Browse Source

Ensurning compatibiity for older qt versions

Some uses of the auto keyword when creating Objects derived from QObject are not compatible with older compilers, as observed when testing with the oldest still supported LTS release for ubuntu (the oldest target for compatibility). This commit adresses this and changes the syntax used for instantiating QObject-based classes

To ensure the best possible compatibility, QObjects and their subclasses should be instantiated like this:

QMessageBox box(this);

instead of:

auto box = QMessageBox(this);

This method is more widely compatible, more in line with the Qt documentation and closer to the 'standard' of how QObject based classes are instantiated.
Felix 4 years ago
parent
commit
1570830906

+ 1 - 1
src/database/adatabasesetup.cpp

@@ -306,7 +306,7 @@ bool ADataBaseSetup::backupOldData()
     auto date_string = QDateTime::currentDateTime().toString(opl::datetime::DATETIME_BACKUP_FORMAT);
     auto backup_dir = QDir(AStandardPaths::absPathOf(AStandardPaths::DatabaseBackup));
     auto backup_name = database_file.baseName() + "_bak_" + date_string + ".db";
-    auto file = QFile(aDB->databaseFile.absoluteFilePath());
+    QFile file(aDB->databaseFile.absoluteFilePath());
 
     if (!file.rename(backup_dir.absolutePath() + '/' + backup_name)) {
         DEB << "Unable to backup old database.";

+ 3 - 3
src/gui/dialogues/firstrundialog.cpp

@@ -107,7 +107,7 @@ bool FirstRunDialog::finish()
     data.insert(opl::db::PILOTS_PHONE, ui->phoneLineEdit->text());
     data.insert(opl::db::PILOTS_EMAIL, ui->emailLineEdit->text());
 
-    auto db_fail_msg_box = QMessageBox(QMessageBox::Critical, QStringLiteral("Database setup failed"),
+    QMessageBox db_fail_msg_box(QMessageBox::Critical, QStringLiteral("Database setup failed"),
                                        QStringLiteral("Errors have ocurred creating the database."
                                                       "Without a working database The application will not be usable."));
     if (!setupDatabase()) {
@@ -128,7 +128,7 @@ bool FirstRunDialog::finish()
 
 bool FirstRunDialog::setupDatabase()
 {
-    auto confirm = QMessageBox(QMessageBox::Question, QStringLiteral("Create Database"),
+    QMessageBox confirm(QMessageBox::Question, QStringLiteral("Create Database"),
                                QStringLiteral("We are now going to create the database.<br>"  // [G]: Why both <br> and \n ?
                                               "Would you like to download the latest database information?"
                                               "<br>(Recommended, Internet connection required)"),
@@ -155,7 +155,7 @@ bool FirstRunDialog::setupDatabase()
 
 void FirstRunDialog::reject()
 {
-    auto confirm = QMessageBox(QMessageBox::Critical,
+    QMessageBox confirm(QMessageBox::Critical,
                                QStringLiteral("Setup incomplete"),
                                QStringLiteral("Without completing the initial setup"
                                               " you cannot use the application.<br><br>"

+ 7 - 7
src/gui/dialogues/newflightdialog.cpp

@@ -750,7 +750,7 @@ void NewFlightDialog::formFiller()
 bool NewFlightDialog::isLessOrEqualThanBlockTime(const QString time_string)
 {
     if (mandatoryLineEditsGood.count(true) != 7){
-        auto message_box = QMessageBox(this);
+        QMessageBox message_box(this);
         message_box.setText("Unable to determine total block time.\n"
                             "Please fill out Departure and Arrival Time\n"
                             "before manually editing these times.");
@@ -766,7 +766,7 @@ bool NewFlightDialog::isLessOrEqualThanBlockTime(const QString time_string)
     if (extra_time <= block_time) {
         return true;
     } else {
-        auto message_box = QMessageBox(this);
+        QMessageBox message_box(this);
         message_box.setWindowTitle("Error");
         message_box.setText("The flight time you have entered is longer than the total blocktime:<br><center><b>"
                             + block_time.toString(opl::datetime::TIME_DEFAULT_FORMAT)
@@ -791,7 +791,7 @@ void NewFlightDialog::addNewTail(QLineEdit *parent_line_edit)
     if (reply == QMessageBox::Yes) {
         DEB << "Add new aircraft selected";
         // create and open new aircraft dialog
-        auto na = NewTailDialog(ui->acftLineEdit->text(), this);
+        NewTailDialog na(ui->acftLineEdit->text(), this);
         na.exec();
         // update map and list, set line edit
         tailsIdMap  = aDB->getIdMap(ADatabaseTarget::tails);
@@ -823,7 +823,7 @@ void NewFlightDialog::addNewPilot(QLineEdit *parent_line_edit)
     if (reply == QMessageBox::Yes) {
         DEB << "Add new pilot selected";
         // create and open new pilot dialog
-        auto np = NewPilotDialog(this);
+        NewPilotDialog np(this);
         np.exec();
         // update map and list, set line edit
         pilotsIdMap  = aDB->getIdMap(ADatabaseTarget::pilots);
@@ -863,7 +863,7 @@ void NewFlightDialog::on_submitButton_clicked()
         }
         error_message.append("</b></center><br>Please go back and fill in the required data.");
 
-        auto message_box = QMessageBox(this);
+        QMessageBox message_box(this);
         message_box.setText(error_message);
         message_box.exec();
         return;
@@ -875,7 +875,7 @@ void NewFlightDialog::on_submitButton_clicked()
     flightEntry.setData(newData);
     DEB << "Committing...";
     if (!aDB->commit(flightEntry)) {
-        auto message_box = QMessageBox(this);
+        QMessageBox message_box(this);
         message_box.setText("The following error has ocurred:\n\n"
                             + aDB->lastError.text()
                             + "\n\nYour entry has not been saved.");
@@ -1245,7 +1245,7 @@ void NewFlightDialog::on_IfrCheckBox_stateChanged(int)
 void NewFlightDialog::on_manualEditingCheckBox_stateChanged(int arg1)
 {
     if (!(mandatoryLineEditsGood.count(true) == 7) && ui->manualEditingCheckBox->isChecked()) {
-        auto message_box = QMessageBox(this);
+        QMessageBox message_box(this);
         message_box.setText("Before editing times manually, please fill out the required fields in the flight data tab,"
                             " so that total time can be calculated.");
         message_box.exec();

+ 1 - 1
src/gui/dialogues/newpilotdialog.cpp

@@ -153,7 +153,7 @@ void NewPilotDialog::submitForm()
     DEB << "Pilot entry position: " << pilotEntry.getPosition().tableName << pilotEntry.getPosition().rowId;
     DEB << "Pilot entry data: " << pilotEntry.getData();
     if (!aDB->commit(pilotEntry)) {
-        auto message_box = QMessageBox(this);
+        QMessageBox message_box(this);
         message_box.setText("The following error has ocurred:\n\n"
                             + aDB->lastError.text()
                             + "\n\nThe entry has not been saved.");

+ 4 - 4
src/gui/dialogues/newtaildialog.cpp

@@ -210,7 +210,7 @@ void NewTailDialog::submitForm()
 
     entry.setData(new_data);
     if (!aDB->commit(entry)) {
-        auto message_box = QMessageBox(this);
+        QMessageBox message_box(this);
         message_box.setText("The following error has ocurred:\n\n"
                             + aDB->lastError.text()
                             + "\n\nThe entry has not been saved.");
@@ -257,9 +257,9 @@ void NewTailDialog::on_buttonBox_accepted()
 {
     DEB << "Button Box Accepted.";
     if (ui->registrationLineEdit->text().isEmpty()) {
-        auto nope = QMessageBox(this);
-        nope.setText("Registration cannot be empty.");
-        nope.exec();
+        QMessageBox message_box(this);
+        message_box.setText("Registration cannot be empty.");
+        message_box.exec();
         return;
     }
 

+ 2 - 2
src/gui/widgets/aircraftwidget.cpp

@@ -121,7 +121,7 @@ void AircraftWidget::onDeleteUnsuccessful()
     /// the messagebox doesn't grow too tall.
     QList<int> foreign_key_constraints = aDB->getForeignKeyConstraints(selectedTails.first(), ADatabaseTarget::tails);
     QList<AFlightEntry> constrained_flights;
-    for (const auto &row_id : foreign_key_constraints) {
+    for (const auto &row_id : qAsConst(foreign_key_constraints)) {
         constrained_flights.append(aDB->getFlightEntry(row_id));
     }
 
@@ -144,7 +144,7 @@ void AircraftWidget::onDeleteUnsuccessful()
 
 void AircraftWidget::on_newAircraftButton_clicked()
 {
-    auto nt = NewTailDialog(QString(), this);
+    NewTailDialog nt(QString(), this);
     connect(&nt, SIGNAL(accepted()), this, SLOT(acft_editing_finished()));
     connect(&nt, SIGNAL(rejected()), this, SLOT(acft_editing_finished()));
     nt.exec();

+ 1 - 1
src/gui/widgets/pilotswidget.cpp

@@ -151,7 +151,7 @@ void PilotsWidget::on_deletePilotButton_clicked()
 
     } else if (selectedPilots.length() == 1) {
         auto entry = aDB->getPilotEntry(selectedPilots.first());
-        auto message_box = QMessageBox(this);
+        QMessageBox message_box(this);
         QString message = "You are deleting the following pilot:<br><br><b><tt>";
         message.append(entry.name());
         message.append(QStringLiteral("</b></tt><br><br>Are you sure?"));

+ 1 - 1
src/gui/widgets/settingswidget.cpp

@@ -293,7 +293,7 @@ void SettingsWidget::on_acAllowIncompleteComboBox_currentIndexChanged(int index)
 
 void SettingsWidget::on_aboutPushButton_clicked()
 {
-    auto message_box = QMessageBox(this);
+    QMessageBox message_box(this);
     QString SQLITE_VERSION = aDB->sqliteVersion();
     QString text = QMessageBox::tr(