Project Documentation Manager BRIGADOON-0002
Project Documentation Manager
Loading...
Searching...
No Matches
programversion.cpp
Go to the documentation of this file.
1#include "programversion.h"
2#include <QDateTime>
3#include <QSqlQuery>
5#include "projectdocmanager.h"
6
8
9ProgramVersion::ProgramVersion(Ui::MainWindow* UI_Window)
10{
11 ui = UI_Window;
12
14
15 QObject::connect( ui->MajorVersion, QOverload<int>::of(&QSpinBox::valueChanged), [=](quint16 i){ SetMajorVersion(i); });
16 QObject::connect( ui->MinorVersion, QOverload<int>::of(&QSpinBox::valueChanged), [=](quint16 i){ SetMinorVersion(i); });
17 QObject::connect( ui->Revision, QOverload<int>::of(&QSpinBox::valueChanged), [=](quint16 i){ SetRevision(i); });
18 QObject::connect( ui->OverrideStepControl, SIGNAL(stateChanged(int)), this, SLOT(SetStepOverride(int)));
19 QObject::connect( ui->MajorVersion, SIGNAL(valueChanged(int)), this, SLOT(UpdateMajorVersion(int)));
20 QObject::connect( ui->MinorVersion, SIGNAL(valueChanged(int)), this, SLOT(UpdateMinorVersion(int)));
21 QObject::connect( ui->Revision, SIGNAL(valueChanged(int)), this, SLOT(UpdateRevision(int)));
22 QObject::connect(ui->UpdateVersion, SIGNAL(pressed()), this, SLOT(SaveVersion()));
23 QObject::connect(ui->ProjectStatusDate, SIGNAL(dateTimeChanged(QDateTime)), this, SLOT(ReadProjectDateTime(QDateTime)));
24}
25
27{
28 if ( ui->OverrideStepControl->isChecked() )
29 {
30 ui->MajorVersion->setMinimum( 0 );
31 ui->MajorVersion->setMaximum( 999 );
32 ui->MajorVersion->setValue(Value);
33 }
34 else
35 {
36 ui->MajorVersion->setMinimum( Value );
37 ui->MajorVersion->setMaximum( Value + 1 );
39 }
41}
42
44{
45 if ( ui->OverrideStepControl->isChecked() )
46 {
47 ui->MinorVersion->setMinimum( 0 );
48 ui->MinorVersion->setMaximum( 999 );
49 ui->MinorVersion->setValue(Value);
50 }
51 else
52 {
53 ui->MinorVersion->setMinimum( Value);
54 ui->MinorVersion->setMaximum( Value + 1 );
55 PresetRevision( 0 );
56 }
58}
59
60void ProgramVersion::SetRevision( quint16 Value )
61{
62 if ( ui->OverrideStepControl->isChecked() )
63 {
64 ui->Revision->setMinimum( 0);
65 ui->Revision->setMaximum( 999 );
66 ui->Revision->setValue(Value);
67 }
68 else
69 {
70 ui->Revision->setMinimum( Value );
71 ui->Revision->setMaximum( Value + 1 );
72 }
74}
75
77{
78 ui->MajorVersion->setMinimum( 0 );
79 ui->MajorVersion->setMaximum( 999 );
80 ui->MajorVersion->setValue( Value );
81 SetMajorVersion( Value );
82}
83
85{
86 ui->MinorVersion->setMinimum( 0 );
87 ui->MinorVersion->setMaximum( 999 );
88 ui->MinorVersion->setValue( Value );
89 SetMinorVersion( Value );
90}
91
92void ProgramVersion::PresetRevision( quint16 Value )
93{
94 ui->Revision->setMinimum( 0 );
95 ui->Revision->setMaximum( 999 );
96 ui->Revision->setValue( Value );
97 SetRevision( Value );
98}
99
101{
102 QString message = "Operator set Version Step Override to ";
103 if ( State == Qt::Checked )
104 {
105 ui->MajorVersion->setMinimum( 0 );
106 ui->MajorVersion->setMaximum( 999 );
107
108 ui->MinorVersion->setMinimum( 0 );
109 ui->MinorVersion->setMaximum( 999 );
110
111 ui->Revision->setMinimum( 0 );
112 ui->Revision->setMaximum( 999 );
113
114 LogAdd(LOG_DEBUG, MODE_OPERATOR, message + "ON.");
115 }
116 else
117 {
118 ui->MajorVersion->setMinimum( ui->MajorVersion->value() );
119 ui->MajorVersion->setMaximum( ui->MajorVersion->value() + 1 );
120
121 ui->MinorVersion->setMinimum( ui->MinorVersion->value() );
122 ui->MinorVersion->setMaximum( ui->MinorVersion->value() + 1 );
123
124 ui->Revision->setMinimum( ui->Revision->value() );
125 ui->Revision->setMaximum( ui->Revision->value() + 1 );
126
127 LogAdd(LOG_DEBUG, MODE_OPERATOR, message + "OFF.");
129 }
130}
131
133{
134 ui->OverrideStepControl->setChecked(Enable);
135}
136
138{
140 version_info = ProjectId->VersionInfo;
144 QString version_timestamp = ProjectId->VersionInfo.VersionDate.toLocalTime().toString(timestamp_format_string);
145 ui->VersionDate->setText(version_timestamp);
147}
148
150{
152 result.ProjectNumber = ProjectId;
153 result.VersionInfo.MajorVersion = ui->MajorVersion->value();
154 result.VersionInfo.MinorVersion = ui->MinorVersion->value();
155 result.VersionInfo.Revision = ui->Revision->value();
157 result.VersionInfo.VersionDate = QDateTime::fromString(ui->VersionDate->text(), timestamp_format_string );
158 result.VersionInfo.VersionString = ui->VersionDescription->toPlainText();
159 return( result );
160}
161
163{
164 QString now = QDateTime::currentDateTime().toString(timestamp_format_string);
165 ui->VersionDate->setText(now);
166 if (!ui->OverrideStepControl->isChecked()) LogProgramVersion(WriteVersion(project_index));
167 ui->VersionDescription->clear();
168}
169
170void ProgramVersion::LogAdd(LOGGING_SEVERITY Severity, LOGGING_MODE Mode, QString Message)
171{
172 REMOTE_LOG_ENTRY log_entry;
173 log_entry.Severity = Severity;
174 log_entry.Mode = Mode;
175 log_entry.Message = Message;
176 emit SendLogEntry(log_entry);
177}
178
180{
181 QString version_timestamp_string = VersionInstance.VersionInfo.VersionDate.toString(timestamp_format_string);
182 QString message_template = "Program Version is %1, dated %2";
183 QString log_message = message_template.arg(VersionInstance.VersionInfo.FullVersionString, version_timestamp_string);
184 LogAdd(LOG_DEBUG, MODE_OPERATOR, log_message);
185}
186
188{
189 SetOverrideEnable(true);
192 SetRevision(0);
194 ui->VersionDescription->clear();
195 ui->ExecutableDirectory->clear();
196 ui->FullHistory->clear();
197 SetOverrideEnable(false);
198}
199
200void ProgramVersion::ReadVersionText(uint ProjectIndex, VERSION_INFO VersionInstance)
201{
202 QString p1 = QString::number(ProjectIndex);
203 QString p2 = QString::number(VersionInstance.MajorVersion);
204 QString p3 = QString::number(VersionInstance.MinorVersion);
205 QString p4 = QString::number(VersionInstance.Revision);
206 QString query_template = QString("select description, version_timestamp from proj_version_info where project_id = %1 and major_version = %2 and minor_version = %3 and revision = %4 ");
207 QString query_string = query_template.arg(p1, p2, p3,p4);
208 QSqlQuery version_text_query(query_string);
209
210 while (version_text_query.next())
211 {
212 QString version_string = version_text_query.value(0).toString();
213 ui->VersionDescription->setText(version_string);
214 QDateTime version_datetime = version_text_query.value(1).toDateTime();
215 ui->VersionDate->setText(version_datetime.toLocalTime().toString());
216 }
217
218 ReadFullHistory(ProjectIndex);
219}
220
222{
223 bool new_version = false;
224
225 // Get the Version Data
227 QString p1 = QString::number(project_index);
228 QString p2 = QString::number(ui->MajorVersion->value());
229 QString p3 = QString::number(ui->MinorVersion->value());
230 QString p4 = QString::number(ui->Revision->value());
231 QString p5 = ui->VersionDescription->toPlainText();
232 QString p6 = ui->ProjectStatus->currentText();
233 QDateTime p7 = QDateTime::currentDateTime();
234 ui->VersionDate->setText(p7.toString());
235 // First Check if the Version Exists Already
236 QString query_string = QString("select project_id from proj_version_info where project_id = %1 and major_version = %2 and minor_version = %3 and revision = %4").arg(p1, p2, p3, p4);
237 QSqlQuery does_version_exist(query_string);
238
239 // If the Version Exists Update the Version's Description.
240 if (does_version_exist.next())
241 {
242 query_string = QString("update proj_version_info set description = '%1', version_status = '%5' where project_id = %2 and major_version = %3 and minor_version = %4 and revision = %5").arg(p5, p1, p2, p3, p4);
243 QSqlQuery update_version_description(query_string);
244 if (!update_version_description.exec()) LogAdd(LOG_ERROR, MODE_DATABASE, QString("ERROR - Unable to update Version %1.%2.%3").arg(p2, p3, p4, p5));
245 else LogAdd(LOG_DEBUG, MODE_DATABASE, QString("Update Version %1.%2.%3, Descrip: %p4, Status Level: %p5").arg(p1, p2, p3, p4, p5));
246 }
247
248 // No, It Doesn't, so make New Entry.
249 else
250 {
251 // First Update the Project's Version so that it Database Constraints aren't violated
252 query_string = QString("update project set major_version = %1, minor_version = %2, revision = %3 where project_index = %4").arg(p2, p3, p4, p1);
253 QSqlQuery update_version_query;
254 bool result = update_version_query.exec(query_string);
255 if (!result)
256 {
257 LogAdd(LOG_ERROR, MODE_DATABASE, "ERROR - Unable to update Project Version during Version Update");
258 }
259 else
260 {
261 query_string =
262 QString("INSERT INTO proj_version_info(project_id, major_version, minor_version, revision, description, version_status, version_timestamp) VALUES (%1, %2, %3, %4, '%5', '%6', '%7')").arg(p1, p2, p3, p4, p5, p6, p7.toString(DATETIME_DATABASE_FORMAT));
263 QSqlQuery insert_version_query;
264 result = insert_version_query.exec(query_string);
265 if (!result) LogAdd(LOG_ERROR, MODE_DATABASE, "ERROR - Unable to insert Version Description!");
266 else
267 {
268 LogAdd(LOG_DEBUG, MODE_DATABASE, QString("Inserted Version %1.%2.%3 Description").arg(p2, p3, p4));
269 new_version = true;
270 }
271 }
272 }
274
275 // If This is a New Version, Check if it should be committed to Git
276 if (new_version) emit SendVersionInfo(version);
277}
278
280{
282 emit SendMajorVersion(MajorVersion);
283}
284
286{
288 emit SendMinorVersion(MinorVersion);
289}
290
292{
294 emit SendRevision(Revision);
295}
296
297void ProgramVersion::ReadProjectDateTime(QDateTime ProjectDateTime)
298{
299 emit SendProjectDateTime(ProjectDateTime.toString(timestamp_format_string));
300}
301
302QString ProgramVersion::FormatVersion(int MajorVersion, int MinorVersion, int Revision)
303{
304 return(QString::number(MajorVersion).rightJustified(2, '0') + "." +
305 QString::number(MinorVersion).rightJustified(2, '0') + "." +
306 QString::number(Revision).rightJustified(2, '0')
307 );
308}
309
310QString ProgramVersion::ReadFullHistory(int ProjectIndex)
311{
312 QString full_history;
313 QString query_string = QString("select major_version, minor_version, revision, description, version_status from proj_version_info where project_id = %1 order by major_version desc, minor_version desc, revision desc")
314 .arg(QString::number(ProjectIndex));
315 QSqlQuery version_text_query(query_string);
316
317 while (version_text_query.next())
318 {
319 full_history += QString("<P><B>Version ") + FormatVersion(version_text_query.value(0).toInt(), version_text_query.value(1).toInt(), version_text_query.value(2).toInt()) + ": <I>";
320 full_history += version_text_query.value(4).toString() + " </I></B>";
321 full_history += version_text_query.value(3).toString() + "</P>";
322 }
323 ui->FullHistory->setText(full_history);
324
325 return(full_history);
326}
void SetOverrideEnable(bool Enable)
Enable/Disable the Override.
Ui::MainWindow * ui
void SetMajorVersion(quint16 Value)
Sets the Project's Major Version to Value.
void SendMajorVersion(int MajorVersion)
Send the Major Version.
void PresetRevision(quint16 Value)
Preset the Revision to a Value.
void SendRevision(int Revision)
Send the Revision.
void DoClear(void)
Reset the Version Information.
REMOTE_VERSION_ENTRY WriteVersion(uint ProjectId)
Read the Version Information into Structure.
QString FormatVersion(int MajorVersion, int MinorVersion, int Revision)
Format the numeric version (major, minor, revision) as text.
void SendLogEntry(REMOTE_LOG_ENTRY LogEntry)
Send Log Entry to the Log \LogEntry Structure holding Log information.
void LogAdd(LOGGING_SEVERITY Severity, LOGGING_MODE Mode, QString Message)
void SendVersionInfo(REMOTE_VERSION_ENTRY VersionEntry)
Send the Version information by the Signal-Slot Method.
void SetMinorVersion(quint16 Value)
Sets the Project's Minor Version to Value.
void ReadProjectInfo(PROJECT_INFORMATION *ProjectId)
Read The Project Information.
ProgramVersion(Ui::MainWindow *UI_Window)
Program Version Class Constructor.
void SaveVersion(void)
Save the Project's Version.
QString ReadFullHistory(int ProjectIndex)
Read the entire history of the Project as a string.
QString timestamp_format_string
DateTime Format String.
void UpdateRevision(int Revision)
Set the Revision to the Value Supplied.
void SendMinorVersion(int MinorVersion)
Send the Minor Version.
void SendProjectDateTime(QString ProjectDateTime)
Send the Current DateTime as the Version DateTime.
uint project_index
Project Index Number.
void LogProgramVersion(REMOTE_VERSION_ENTRY VersionInstance)
Convert the Program Version to Log Message and Send It.
void PresetMinorVersion(quint16 Value)
Preset the Minor Version to a Value.
void SetRevision(quint16 Value)
Sets the Project's Revision to Value.
void SetVersionDate(void)
Set the Version Date.
void UpdateMajorVersion(int MajorVersion)
Set the Major Version to the Value Supplied.
void UpdateMinorVersion(int MinorVersion)
Set the Minor Version to the Value Supplied.
VERSION_INFO version_info
Structure holding Version Information.
void ReadVersionText(uint ProjectIndex, VERSION_INFO Version)
Read the Version Text for the Project's Version.
void SetStepOverride(int State)
Set the Status of Version Step Override.
void PresetMajorVersion(quint16 Value)
Preset the Major Version to a Value.
void ReadProjectDateTime(QDateTime ProjectDateTime)
Read the Project DateTime.
Project Document Control Class.
Common Structure Defintitions.
#define DATETIME_DATABASE_FORMAT
text format of the DateTime used by the Database.
#define DATETIME_DISPLAY_FORMAT
DateTime formatting for the program displays.
LOGGING_SEVERITY
Log Severity allow the selection of logging events based on Severity.
Definition logger.h:48
@ LOG_ERROR
Definition logger.h:52
@ LOG_DEBUG
Definition logger.h:56
LOGGING_MODE
Log Severity allow the selection of logging events based on the mode.
Definition logger.h:21
@ MODE_OPERATOR
Definition logger.h:34
@ MODE_DATABASE
Definition logger.h:35
ProjectDocManager * project_doc_manager
Program Version Class.
Project Information Passed Between Functions.
PROJECT_DESCRIPTION ProjectDesc
Definition logger.h:60
LOGGING_MODE Mode
Definition logger.h:61
QString Message
Definition logger.h:63
LOGGING_SEVERITY Severity
Definition logger.h:62
Version Structure used between functions.
VERSION_INFO VersionInfo
uint ProjectNumber
Information about the Project's Version.