Browse Source

Merge pull request #58 from fiffty-50/develop-string-rework

QStringBuilder and translation groundwork. Closes #58
Felix Turowsky 4 years ago
parent
commit
d01d7c75ad

+ 3 - 0
CMakeLists.txt

@@ -13,6 +13,9 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
 
 set(QT_MIN_VERSION "5.5.1")
 
+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DQT_USE_QSTRINGBUILDER")
+MESSAGE ("Enabling QStringBuilder")
+
 find_package(QT NAMES Qt6 Qt5 COMPONENTS Widgets REQUIRED)
 find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Widgets Sql Network REQUIRED)
 

+ 13 - 0
docs/wiki/wiki_coding_style.md

@@ -18,6 +18,19 @@ See https://wiki.qt.io/Qt_Coding_Style for general code style guidelines.
 |Type Alias|follow Qt Convention|`using NewType = QMap<QString, int>`|
 
 
+## Strings in openPilotLog
+
+Aim to construct and use strings in the most efficient way. 
+
+- For all user-facing string use [tr()](), so that the app is translatable.
+
+- Use [QStringLiteral](https://doc-snapshots.qt.io/qt6-dev/qstring.html#QStringLiteral) where possible, except when using a function that has a `char *` overload.
+
+- For string comparisons using the `==` operator, use [QLatin1String](https://wiki.qt.io/Using_QString_Effectively)
+
+- For concatenations, openPilotLog uses [QStringBuilder](https://doc-snapshots.qt.io/qt6-dev/qstring.html#more-efficient-string-construction) globally, so the `+` operator can be used.
+- (Debug etc. can be  `char *`, `QString` or anything else)
+
 ## Examples
 
 ```c++

+ 1 - 1
mainwindow.cpp

@@ -98,7 +98,7 @@ MainWindow::~MainWindow()
 void MainWindow::nope()
 {
     QMessageBox message_box(this); //error box
-    message_box.setText("This feature is not yet available!");
+    message_box.setText(tr("This feature is not yet available!"));
     message_box.exec();
 }
 

+ 1 - 1
openPilotLog.pro

@@ -14,7 +14,7 @@ DEFINES += QT_DEPRECATED_WARNINGS
 # In order to do so, uncomment the following line.
 # You can also select to disable deprecated APIs only up to a certain version of Qt.
 DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0
-QMAKE_CXXFLAGS += -Wno-deprecated-copy # see https://bugreports.qt.io/browse/QTBUG-75210
+DEFINES *= QT_USE_QSTRINGBUILDER
 
 # [G]: need to fix this. There must be a src/* command or smth
 SOURCES += \

+ 10 - 10
src/classes/asettings.cpp

@@ -20,19 +20,19 @@
 
 
 QMap<ASettings::Main, QString> ASettings::mainMap = {
-    {Main::Style,      QStringLiteral("style")},
-    {Main::StyleSheet, QStringLiteral("stylesheet")},
+    {Main::Style,                       QStringLiteral("style")},
+    {Main::StyleSheet,                  QStringLiteral("stylesheet")},
 };
 
 QMap<ASettings::LogBook, QString> ASettings::logBookMap = {
-    {LogBook::View, QStringLiteral("view")},
+    {LogBook::View,                     QStringLiteral("view")},
 };
 
 QMap<ASettings::UserData, QString> ASettings::userDataMap = {
-    {UserData::DisplaySelfAs,     QStringLiteral("displayselfas")},
-    {UserData::AcftSortColumn,      QStringLiteral("acSortColumn")},  // [G]: inconsistent naming
-    {UserData::PilSortColumn,     QStringLiteral("pilSortColumn")},
-    {UserData::AcAllowIncomplete, QStringLiteral("acAllowIncomplete")},
+    {UserData::DisplaySelfAs,           QStringLiteral("displayselfas")},
+    {UserData::AcftSortColumn,          QStringLiteral("acSortColumn")},  // [G]: inconsistent naming
+    {UserData::PilSortColumn,           QStringLiteral("pilSortColumn")},
+    {UserData::AcAllowIncomplete,       QStringLiteral("acAllowIncomplete")},
 };
 
 QMap<ASettings::FlightLogging, QString> ASettings::flightLoggingMap = {
@@ -51,12 +51,12 @@ QMap<ASettings::FlightLogging, QString> ASettings::flightLoggingMap = {
 };
 
 QMap<ASettings::Setup, QString> ASettings::setupMap = {
-    {Setup::SetupComplete, QStringLiteral("setupComplete")}
+    {Setup::SetupComplete,              QStringLiteral("setupComplete")}
 };
 
 QMap<ASettings::NewFlight, QString> ASettings::newFlightMap = {
-    {NewFlight::FunctionComboBox, QStringLiteral("FunctionComboBox")},  // inconsistent naming
-    {NewFlight::CalendarCheckBox, QStringLiteral("calendarCheckBox")},
+    {NewFlight::FunctionComboBox,       QStringLiteral("FunctionComboBox")},  // inconsistent naming
+    {NewFlight::CalendarCheckBox,       QStringLiteral("calendarCheckBox")},
 };
 
 void ASettings::setup()

+ 1 - 1
src/classes/atailentry.cpp

@@ -43,7 +43,7 @@ const QString ATailEntry::type()
     if (!tableData.value(Opl::Db::TAILS_MODEL).toString().isEmpty())
         type_string.append(getData().value(Opl::Db::TAILS_MODEL).toString());
     if (!tableData.value(Opl::Db::TAILS_VARIANT).toString().isEmpty())
-        type_string.append('-' + getData().value(Opl::Db::TAILS_VARIANT).toString() + ' ');
+        type_string.append('-' + getData().value(Opl::Db::TAILS_VARIANT).toString());
 
     return type_string;
 }

+ 6 - 2
src/database/adatabase.cpp

@@ -199,13 +199,17 @@ bool ADatabase::removeMany(QList<DataPosition> data_position_list)
             lastError = QString();
             return true;
         } else {
-            lastError = "Transaction unsuccessful (Interrupted). Error count: " + QString::number(errorCount);
+            lastError = ADatabaseError(
+                        "Transaction unsuccessful (Interrupted). Error count: "
+                        + QString::number(errorCount));
             return false;
         }
     } else {
         query.prepare(QStringLiteral("ROLLBACK"));
         query.exec();
-        lastError = "Transaction unsuccessful (no changes have been made). Error count: " + QString::number(errorCount);
+        lastError = ADatabaseError(
+                    "Transaction unsuccessful (no changes have been made). Error count: "
+                    + QString::number(errorCount));
         return false;
     }
 }

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

@@ -56,7 +56,7 @@ void FirstRunDialog::on_previousPushButton_clicked()
         ui->previousPushButton->setEnabled(false);
         break;
     case 2:
-        ui->nextPushButton->setText(QStringLiteral("Next"));
+        ui->nextPushButton->setText(tr("Next"));
         break;
     }
     ui->stackedWidget->setCurrentIndex(current_idx - 1);
@@ -71,15 +71,15 @@ void FirstRunDialog::on_nextPushButton_clicked()
         if(ui->firstnameLineEdit->text().isEmpty()
            || ui->lastnameLineEdit->text().isEmpty())
         {
-            QMessageBox(QMessageBox::Warning, QStringLiteral("Error"),
-                        QStringLiteral("Please enter first and last name")
+            QMessageBox(QMessageBox::Warning, tr("Error"),
+                        tr("Please enter first and last name")
                         ).exec();
             return;
         }
         ui->previousPushButton->setEnabled(true);
         break;
     case 1:
-        ui->nextPushButton->setText(QStringLiteral("Done"));
+        ui->nextPushButton->setText(tr("Done"));
         break;
     case 2:
         if(!finish())
@@ -114,9 +114,9 @@ bool FirstRunDialog::finish()
     data.insert(Opl::Db::PILOTS_PHONE, ui->phoneLineEdit->text());
     data.insert(Opl::Db::PILOTS_EMAIL, ui->emailLineEdit->text());
 
-    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."));
+    QMessageBox db_fail_msg_box(QMessageBox::Critical, tr("Database setup failed"),
+                                tr("Errors have ocurred creating the database."
+                                   "Without a working database The application will not be usable."));
     if (!setupDatabase()) {
         db_fail_msg_box.exec();
         return false;
@@ -135,8 +135,8 @@ bool FirstRunDialog::finish()
 
 bool FirstRunDialog::setupDatabase()
 {
-    QMessageBox confirm(QMessageBox::Question, QStringLiteral("Create Database"),
-                               QStringLiteral("We are now going to create the database.<br>"  // [G]: Why both <br> and \n ?
+    QMessageBox confirm(QMessageBox::Question, tr("Create Database"),
+                               tr("We are now going to create the database.<br>"
                                               "Would you like to download the latest database information?"
                                               "<br>(Recommended, Internet connection required)"),
                                QMessageBox::Yes | QMessageBox::No, this);
@@ -146,7 +146,7 @@ bool FirstRunDialog::setupDatabase()
         useLocalTemplates = false;
         if (!ADataBaseSetup::downloadTemplates()) { // To do: return true only if size of dl != 0
             QMessageBox message_box(this);
-            message_box.setText(QStringLiteral("Downloading latest data has failed.<br><br>Using local data instead."));
+            message_box.setText(tr("Downloading latest data has failed.<br><br>Using local data instead."));
             useLocalTemplates = true; // fall back
         } else {
         useLocalTemplates = true;
@@ -171,8 +171,8 @@ bool FirstRunDialog::setupDatabase()
 void FirstRunDialog::reject()
 {
     QMessageBox confirm(QMessageBox::Critical,
-                               QStringLiteral("Setup incomplete"),
-                               QStringLiteral("Without completing the initial setup"
+                               tr("Setup incomplete"),
+                               tr("Without completing the initial setup"
                                               " you cannot use the application.<br><br>"
                                               "Quit anyway?"),
                                QMessageBox::Yes | QMessageBox::No, this);

+ 52 - 47
src/gui/dialogues/newflightdialog.cpp

@@ -49,10 +49,10 @@ static const auto SELF_RX              = QRegularExpression(
             "self", QRegularExpression::CaseInsensitiveOption);
 
 static const auto MANDATORY_LINE_EDITS_DISPLAY_NAMES = QMap<int, QString> {
-    {0, QStringLiteral("Date of Flight")}, {1, QStringLiteral("Departure Airport")},
-    {2, QStringLiteral("Destination Airport")}, {3, QStringLiteral("Time Off Blocks")},
-    {4, QStringLiteral("Time on Blocks")}, {5, QStringLiteral("PIC Name")},
-    {6, QStringLiteral("Aircraft Registration")}
+    {0, QObject::tr("Date of Flight")},      {1, QObject::tr("Departure Airport")},
+    {2, QObject::tr("Destination Airport")}, {3, QObject::tr("Time Off Blocks")},
+    {4, QObject::tr("Time on Blocks")},      {5, QObject::tr("PIC Name")},
+    {6, QObject::tr("Aircraft Registration")}
 };
 
 
@@ -139,12 +139,12 @@ void NewFlightDialog::setup()
     readSettings();
 
     // Visually mark mandatory fields
-    ui->deptLocLineEdit->setStyleSheet("border: 0.1ex solid #3daee9");
-    ui->destLocLineEdit->setStyleSheet("border: 0.1ex solid #3daee9");
-    ui->tofbTimeLineEdit->setStyleSheet("border: 0.1ex solid #3daee9");
-    ui->tonbTimeLineEdit->setStyleSheet("border: 0.1ex solid #3daee9");
-    ui->picNameLineEdit->setStyleSheet("border: 0.1ex solid #3daee9");
-    ui->acftLineEdit->setStyleSheet("border: 0.1ex solid #3daee9");
+    ui->deptLocLineEdit->setStyleSheet(QStringLiteral("border: 0.1ex solid #3daee9"));
+    ui->destLocLineEdit->setStyleSheet(QStringLiteral("border: 0.1ex solid #3daee9"));
+    ui->tofbTimeLineEdit->setStyleSheet(QStringLiteral("border: 0.1ex solid #3daee9"));
+    ui->tonbTimeLineEdit->setStyleSheet(QStringLiteral("border: 0.1ex solid #3daee9"));
+    ui->picNameLineEdit->setStyleSheet(QStringLiteral("border: 0.1ex solid #3daee9"));
+    ui->acftLineEdit->setStyleSheet(QStringLiteral("border: 0.1ex solid #3daee9"));
 
     ui->doftLineEdit->setText(QDate::currentDate().toString(Qt::ISODate));
     emit ui->doftLineEdit->editingFinished();
@@ -646,10 +646,10 @@ void NewFlightDialog::formFiller()
     }
 
     ui->acftLineEdit->setText(flightEntry.getRegistration());
-    line_edits_names.removeOne("acftLineEdit");
+    line_edits_names.removeOne(QStringLiteral("acftLineEdit"));
 
     for (const auto& data_key : flightEntry.getData().keys()) {
-        auto rx = QRegularExpression(data_key + "LineEdit");//acftLineEdit
+        auto rx = QRegularExpression(data_key + QStringLiteral("LineEdit"));//acftLineEdit
         for(const auto& leName : line_edits_names){
             if(rx.match(leName).hasMatch())  {
                 //DEB << "Loc Match found: " << key << " - " << leName);
@@ -661,7 +661,7 @@ void NewFlightDialog::formFiller()
                 break;
             }
         }
-        rx = QRegularExpression(data_key + "Loc\\w+?");
+        rx = QRegularExpression(data_key + QStringLiteral("Loc\\w+?"));
         for(const auto& leName : line_edits_names){
             if(rx.match(leName).hasMatch())  {
                 //DEB << "Loc Match found: " << key << " - " << leName);
@@ -673,7 +673,7 @@ void NewFlightDialog::formFiller()
                 break;
             }
         }
-        rx = QRegularExpression(data_key + "Time\\w+?");
+        rx = QRegularExpression(data_key + QStringLiteral("Time\\w+?"));
         for(const auto& leName : line_edits_names){
             if(rx.match(leName).hasMatch())  {
                 //DEB << "Time Match found: " << key << " - " << leName);
@@ -687,7 +687,7 @@ void NewFlightDialog::formFiller()
                 break;
             }
         }
-        rx = QRegularExpression(data_key + "Name\\w+?");
+        rx = QRegularExpression(data_key + QStringLiteral("Name\\w+?"));
         for(const auto& leName : line_edits_names){
             if(rx.match(leName).hasMatch())  {
                 auto line_edits = this->findChild<QLineEdit *>(leName);
@@ -705,7 +705,7 @@ void NewFlightDialog::formFiller()
                                               ui->tSICTimeLineEdit, ui->tDUALTimeLineEdit,
                                               ui->tFITimeLineEdit};
     for(const auto& line_edit : function_combo_boxes){
-        if(line_edit->text() != "00:00"){
+        if(line_edit->text() != QStringLiteral("00:00")){
             QString name = line_edit->objectName();
             name.chop(12);
             name.remove(0,1);
@@ -765,9 +765,9 @@ bool NewFlightDialog::isLessOrEqualThanBlockTime(const QString time_string)
 {
     if (mandatoryLineEditsGood.count(true) != 7){
         QMessageBox message_box(this);
-        message_box.setText("Unable to determine total block time.<br>"
-                            "Please fill out all Mandatory Fields<br>"
-                            "before manually editing these times.");
+        message_box.setText(tr("Unable to determine total block time.<br>"
+                               "Please fill out all Mandatory Fields<br>"
+                               "before manually editing these times."));
         message_box.exec();
         return false;
     }
@@ -781,10 +781,10 @@ bool NewFlightDialog::isLessOrEqualThanBlockTime(const QString time_string)
         return true;
     } else {
         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>"
-                            + ATime::toString(block_time, flightTimeFormat)
-                            + "</b></center>");
+        message_box.setWindowTitle(tr("Error"));
+        message_box.setText(tr("The flight time you have entered is longer than the total blocktime:"
+                               "<br><center><b>%1</b></center>"
+                               ).arg(ATime::toString(block_time, flightTimeFormat)));
         message_box.exec();
         return false;
     }
@@ -797,10 +797,11 @@ bool NewFlightDialog::isLessOrEqualThanBlockTime(const QString time_string)
 void NewFlightDialog::addNewTail(QLineEdit *parent_line_edit)
 {
     QMessageBox::StandardButton reply;
-    reply = QMessageBox::question(this, "No Aircraft found",
-                                  "No aircraft with this registration found.<br>"
-                                  "If this is the first time you log a flight with this aircraft, you have to "
-                                  "add the registration to the database first.<br><br>Would you like to add a new aircraft to the database?",
+    reply = QMessageBox::question(this, tr("No Aircraft found"),
+                                  tr("No aircraft with this registration found.<br>"
+                                     "If this is the first time you log a flight with this aircraft, "
+                                     "you have to add the registration to the database first."
+                                     "<br><br>Would you like to add a new aircraft to the database?"),
                                   QMessageBox::Yes|QMessageBox::No);
     if (reply == QMessageBox::Yes) {
         DEB << "Add new aircraft selected";
@@ -828,11 +829,12 @@ void NewFlightDialog::addNewTail(QLineEdit *parent_line_edit)
 void NewFlightDialog::addNewPilot(QLineEdit *parent_line_edit)
 {
     QMessageBox::StandardButton reply;
-    reply = QMessageBox::question(this, "No Pilot found",
-                                  "No pilot found.<br>Please enter the Name as"
-                                  "<br><br><center><b>Lastname, Firstname</b></center><br><br>"
-                                  "If this is the first time you log a flight with this pilot, you have to "
-                                  "add the name to the database first.<br><br>Would you like to add a new pilot to the database?",
+    reply = QMessageBox::question(this, tr("No Pilot found"),
+                                  tr("No pilot found.<br>Please enter the Name as"
+                                     "<br><br><center><b>Lastname, Firstname</b></center><br><br>"
+                                     "If this is the first time you log a flight with this pilot, "
+                                     "you have to add the pilot to the database first."
+                                     "<br><br>Would you like to add a new pilot to the database?"),
                                   QMessageBox::Yes|QMessageBox::No);
     if (reply == QMessageBox::Yes) {
         DEB << "Add new pilot selected";
@@ -867,18 +869,20 @@ void NewFlightDialog::on_submitButton_clicked()
     }
     DEB << "editing finished emitted. good count: " << mandatoryLineEditsGood.count(true);
     if (mandatoryLineEditsGood.count(true) != 7) {
-        QString error_message = "Not all mandatory entries are valid.<br>The following"
-                                " item(s) are empty or missing:<br><br><center><b>";
+        QString missing_items;
         for (int i=0; i < mandatoryLineEditsGood.size(); i++) {
             if (!mandatoryLineEditsGood[i]){
-                error_message.append(MANDATORY_LINE_EDITS_DISPLAY_NAMES.value(i) + "<br>");
-                mandatoryLineEdits[i]->setStyleSheet("border: 1px solid red");
+                missing_items.append(MANDATORY_LINE_EDITS_DISPLAY_NAMES.value(i) + "<br>");
+                mandatoryLineEdits[i]->setStyleSheet(QStringLiteral("border: 1px solid red"));
             }
         }
-        error_message.append("</b></center><br>Please go back and fill in the required data.");
 
         QMessageBox message_box(this);
-        message_box.setText(error_message);
+        message_box.setText(tr("Not all mandatory entries are valid.<br>"
+                               "The following item(s) are empty or missing:"
+                               "<br><br><center><b>%1</b></center><br>"
+                               "Please go back and fill in the required data."
+                               ).arg(missing_items));
         message_box.exec();
         return;
     }
@@ -890,9 +894,10 @@ void NewFlightDialog::on_submitButton_clicked()
     DEB << "Committing...";
     if (!aDB->commit(flightEntry)) {
         QMessageBox message_box(this);
-        message_box.setText("The following error has ocurred:\n\n"
-                            + aDB->lastError.text()
-                            + "\n\nYour entry has not been saved.");
+        message_box.setText(tr("The following error has ocurred:"
+                               "<br><br>%1<br><br>"
+                               "The entry has not been saved."
+                               ).arg(aDB->lastError.text()));
         message_box.setIcon(QMessageBox::Warning);
         message_box.exec();
         return;
@@ -926,7 +931,7 @@ void NewFlightDialog::onGoodInputReceived(QLineEdit *line_edit)
 void NewFlightDialog::onBadInputReceived(QLineEdit *line_edit)
 {
     DEB << line_edit->objectName() << " - Bad input received - " << line_edit->text();
-    line_edit->setStyleSheet("border: 1px solid red");
+    line_edit->setStyleSheet(QStringLiteral("border: 1px solid red"));
 
     DEB << "Mandatory Good: " << mandatoryLineEditsGood.count(true) << " out of "
         << mandatoryLineEditsGood.size() << ". Array: " << mandatoryLineEditsGood;
@@ -1106,7 +1111,7 @@ void NewFlightDialog::onLocationEditingFinished(QLineEdit *line_edit, QLabel *na
     // check result
     if (airport_id == 0) {
         // to do: prompt user how to handle unknown airport
-        name_label->setText("Unknown airport identifier");
+        name_label->setText(tr("Unknown airport identifier"));
         onBadInputReceived(line_edit);
         return;
     }
@@ -1171,7 +1176,7 @@ void NewFlightDialog::on_acftLineEdit_editingFinished()
 
     // to do: promp user to add new
     onBadInputReceived(line_edit);
-    ui->acftTypeLabel->setText("Unknown Registration.");
+    ui->acftTypeLabel->setText(tr("Unknown Registration."));
     addNewTail(line_edit);
 }
 
@@ -1259,8 +1264,8 @@ void NewFlightDialog::on_manualEditingCheckBox_stateChanged(int arg1)
 {
     if (!(mandatoryLineEditsGood.count(true) == 7) && ui->manualEditingCheckBox->isChecked()) {
         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.setText(tr("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();
         ui->manualEditingCheckBox->setChecked(false);
         return;
@@ -1304,7 +1309,7 @@ void NewFlightDialog::on_ApproachComboBox_currentTextChanged(const QString &arg1
 
     if (arg1 == QStringLiteral("OTHER")) {
         QMessageBox message_box(this);
-        message_box.setText(QStringLiteral("You can specify the approach type in the Remarks field."));
+        message_box.setText(tr("You can specify the approach type in the Remarks field."));
         message_box.exec();
     }
 }

+ 13 - 12
src/gui/dialogues/newpilotdialog.cpp

@@ -39,19 +39,19 @@
 
 static const auto NAME_RX = QLatin1String("(\\p{L}+(\\s|'|\\-)?\\s?(\\p{L}+)?\\s?)");
 static const auto FIRSTNAME_VALID = QPair<QString, QRegularExpression> {
-     "firstnameLineEdit", QRegularExpression(NAME_RX + NAME_RX + NAME_RX)};
+     QStringLiteral("firstnameLineEdit"), QRegularExpression(NAME_RX + NAME_RX + NAME_RX)};
 static const auto LASTNAME_VALID = QPair<QString, QRegularExpression> {
-     "lastnameLineEdit", QRegularExpression(NAME_RX + NAME_RX + NAME_RX)};
+     QStringLiteral("lastnameLineEdit"), QRegularExpression(NAME_RX + NAME_RX + NAME_RX)};
 static const auto PHONE_VALID = QPair<QString, QRegularExpression> {
-     "phoneLineEdit", QRegularExpression("^[+]{0,1}[0-9\\-\\s]+")};
+     QStringLiteral("phoneLineEdit"), QRegularExpression("^[+]{0,1}[0-9\\-\\s]+")};
 static const auto EMAIL_VALID = QPair<QString, QRegularExpression> {
-     "emailLineEdit", QRegularExpression(
+     QStringLiteral("emailLineEdit"), QRegularExpression(
                 "\\A[a-z0-9!#$%&'*+/=?^_‘{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_‘{|}~-]+)*@"
                 "(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\z")};
 static const auto COMPANY_VALID = QPair<QString, QRegularExpression> {
-     "companyLineEdit", QRegularExpression("\\w+(\\s|\\-)?(\\w+(\\s|\\-)?)?(\\w+(\\s|\\-)?)?")};
+     QStringLiteral("companyLineEdit"), QRegularExpression("\\w+(\\s|\\-)?(\\w+(\\s|\\-)?)?(\\w+(\\s|\\-)?)?")};
 static const auto EMPLOYEENR_VALID = QPair<QString, QRegularExpression> {
-     "employeeidLineEdit", QRegularExpression("\\w+")};
+     QStringLiteral("employeeidLineEdit"), QRegularExpression("\\w+")};
 
 static const auto LINE_EDIT_VALIDATORS = QVector<QPair<QString, QRegularExpression>> {
         FIRSTNAME_VALID,
@@ -119,7 +119,7 @@ void NewPilotDialog::on_buttonBox_accepted()
 {
     if (ui->lastnameLineEdit->text().isEmpty() || ui->firstnameLineEdit->text().isEmpty()) {
         QMessageBox message_box(this);
-        message_box.setText("Last Name and First Name are required.");
+        message_box.setText(tr("Last Name and First Name are required."));
         message_box.show();
     } else {
         submitForm();
@@ -132,7 +132,7 @@ void NewPilotDialog::formFiller()
     auto line_edits = this->findChildren<QLineEdit *>();
 
     for (const auto &le : line_edits) {
-        auto key = le->objectName().remove("LineEdit");
+        auto key = le->objectName().remove(QStringLiteral("LineEdit"));
         le->setText(pilotEntry.getData().value(key).toString());
     }
 }
@@ -144,7 +144,7 @@ void NewPilotDialog::submitForm()
     RowData new_data;
     auto line_edits = this->findChildren<QLineEdit *>();
     for(auto& le : line_edits) {
-        auto key = le->objectName().remove("LineEdit");
+        auto key = le->objectName().remove(QStringLiteral("LineEdit"));
         auto value = le->text();
         new_data.insert(key, value);
     }
@@ -154,9 +154,10 @@ void NewPilotDialog::submitForm()
     DEB << "Pilot entry data: " << pilotEntry.getData();
     if (!aDB->commit(pilotEntry)) {
         QMessageBox message_box(this);
-        message_box.setText("The following error has ocurred:\n\n"
-                            + aDB->lastError.text()
-                            + "\n\nThe entry has not been saved.");
+        message_box.setText(tr("The following error has ocurred:"
+                               "<br><br>%1<br><br>"
+                               "The entry has not been saved."
+                               ).arg(aDB->lastError.text()));
         message_box.exec();
         return;
     } else {

+ 44 - 40
src/gui/dialogues/newtaildialog.cpp

@@ -21,14 +21,18 @@
 #include "src/oplconstants.h"
 
 static const auto REG_VALID = QPair<QString, QRegularExpression> {
-    "registrationLineEdit", QRegularExpression("\\w+-\\w+")};
+    QStringLiteral("registrationLineEdit"), QRegularExpression("\\w+-\\w+")};
 static const auto MAKE_VALID = QPair<QString, QRegularExpression> {
-    "makeLineEdit", QRegularExpression("[-a-zA-Z\\s]+")};
+    QStringLiteral("makeLineEdit"), QRegularExpression("[-a-zA-Z\\s]+")};
 static const auto MODEL_VALID = QPair<QString, QRegularExpression> {
-    "modelLineEdit", QRegularExpression("[\\s\\w-]+")};
+    QStringLiteral("modelLineEdit"), QRegularExpression("[\\s\\w-]+")};
 static const auto VARIANT_VALID = QPair<QString, QRegularExpression> {
-    "variantLineEdit", QRegularExpression("[\\s\\w-]+")};
-static const auto LINE_EDIT_VALIDATORS = QVector<QPair<QString, QRegularExpression>>({REG_VALID, MAKE_VALID, MODEL_VALID, VARIANT_VALID});
+    QStringLiteral("variantLineEdit"), QRegularExpression("[\\s\\w-]+")};
+static const auto LINE_EDIT_VALIDATORS = QVector<QPair<QString, QRegularExpression>>{
+    REG_VALID,
+    MAKE_VALID,
+    MODEL_VALID,
+    VARIANT_VALID};
 
 
 NewTailDialog::NewTailDialog(QString new_registration, QWidget *parent) :
@@ -42,7 +46,7 @@ NewTailDialog::NewTailDialog(QString new_registration, QWidget *parent) :
     setupValidators();
 
     ui->registrationLineEdit->setText(new_registration);
-    ui->searchLineEdit->setStyleSheet("border: 1px solid blue");
+    ui->searchLineEdit->setStyleSheet(QStringLiteral("border: 1px solid blue"));
     ui->searchLineEdit->setFocus();
 
     entry = ATailEntry();
@@ -124,7 +128,7 @@ void NewTailDialog::fillForm(AEntry entry, bool is_template)
     auto data = entry.getData();
 
     for (const auto &le : line_edits) {
-        auto key = le->objectName().remove("LineEdit");
+        auto key = le->objectName().remove(QStringLiteral("LineEdit"));
         le->setText(data.value(key).toString());
     }
 
@@ -140,13 +144,13 @@ void NewTailDialog::fillForm(AEntry entry, bool is_template)
  */
 bool NewTailDialog::verify()
 {
-    auto recommended_line_edits = this->findChildren<QLineEdit *>("registrationLineEdit");
-    recommended_line_edits.append(this->findChild<QLineEdit *>("makeLineEdit"));
-    recommended_line_edits.append(this->findChild<QLineEdit *>("modelLineEdit"));
+    auto recommended_line_edits = this->findChildren<QLineEdit *>(QStringLiteral("registrationLineEdit"));
+    recommended_line_edits.append(this->findChild<QLineEdit *>(QStringLiteral("makeLineEdit")));
+    recommended_line_edits.append(this->findChild<QLineEdit *>(QStringLiteral("modelLineEdit")));
 
-    auto recommended_combo_boxes = this->findChildren<QComboBox *>("operationComboBox");
-    recommended_combo_boxes.append(this->findChild<QComboBox *>("ppNumberComboBox"));
-    recommended_combo_boxes.append(this->findChild<QComboBox *>("ppTypeComboBox"));
+    auto recommended_combo_boxes = this->findChildren<QComboBox *>(QStringLiteral("operationComboBox"));
+    recommended_combo_boxes.append(this->findChild<QComboBox *>(QStringLiteral("ppNumberComboBox")));
+    recommended_combo_boxes.append(this->findChild<QComboBox *>(QStringLiteral("ppTypeComboBox")));
 
     for (const auto &le : recommended_line_edits) {
         if (le->text() != "") {
@@ -154,7 +158,7 @@ bool NewTailDialog::verify()
             recommended_line_edits.removeOne(le);
             le->setStyleSheet("");
         } else {
-            le->setStyleSheet("border: 1px solid red");
+            le->setStyleSheet(QStringLiteral("border: 1px solid red"));
             DEB << "Not Good: " << le;
         }
     }
@@ -164,7 +168,7 @@ bool NewTailDialog::verify()
             recommended_combo_boxes.removeOne(cb);
             cb->setStyleSheet("");
         } else {
-            cb->setStyleSheet("background: orange");
+            cb->setStyleSheet(QStringLiteral("background: orange"));
             DEB << "Not Good: " << cb;
         }
     }
@@ -186,10 +190,10 @@ void NewTailDialog::submitForm()
     RowData new_data;
     //retreive Line Edits
     auto line_edits = this->findChildren<QLineEdit *>();
-    line_edits.removeOne(this->findChild<QLineEdit *>("searchLineEdit"));
+    line_edits.removeOne(this->findChild<QLineEdit *>(QStringLiteral("searchLineEdit")));
 
     for (const auto &le : line_edits) {
-        auto key = le->objectName().remove("LineEdit");
+        auto key = le->objectName().remove(QStringLiteral("LineEdit"));
         new_data.insert(key, le->text());
     }
 
@@ -211,14 +215,16 @@ void NewTailDialog::submitForm()
     entry.setData(new_data);
     if (!aDB->commit(entry)) {
         QMessageBox message_box(this);
-        message_box.setText("The following error has ocurred:\n\n"
-                            + aDB->lastError.text()
-                            + "\n\nThe entry has not been saved.");
+        message_box.setText(tr("The following error has ocurred:"
+                               "<br><br>%1<br><br>"
+                               "The entry has not been saved."
+                               ).arg(aDB->lastError.text()));
         message_box.exec();
         return;
     } else {
         if (entry.getPosition().rowId != 0)
             ACalc::updateAutoTimes(entry.getPosition().rowId);
+
         QDialog::accept();
     }
 }
@@ -227,30 +233,26 @@ void NewTailDialog::submitForm()
 
 void NewTailDialog::on_operationComboBox_currentIndexChanged(int index)
 {
-    if (index != 0) {
+    if (index != 0)
         ui->operationComboBox->setStyleSheet("");
-    }
 }
 
 void NewTailDialog::on_ppTypeComboBox_currentIndexChanged(int index)
 {
-    if (index != 0) {
+    if (index != 0)
         ui->ppTypeComboBox->setStyleSheet("");
-    }
 }
 
 void NewTailDialog::on_ppNumberComboBox_currentIndexChanged(int index)
 {
-    if (index != 0) {
+    if (index != 0)
         ui->ppNumberComboBox->setStyleSheet("");
-    }
 }
 
 void NewTailDialog::on_weightComboBox_currentIndexChanged(int index)
 {
-    if (index != 0) {
+    if (index != 0)
         ui->weightComboBox->setStyleSheet("");
-    }
 }
 
 void NewTailDialog::on_buttonBox_accepted()
@@ -258,7 +260,7 @@ void NewTailDialog::on_buttonBox_accepted()
     DEB << "Button Box Accepted.";
     if (ui->registrationLineEdit->text().isEmpty()) {
         QMessageBox message_box(this);
-        message_box.setText("Registration cannot be empty.");
+        message_box.setText(tr("Registration cannot be empty."));
         message_box.exec();
         return;
     }
@@ -267,19 +269,22 @@ void NewTailDialog::on_buttonBox_accepted()
         if (!ASettings::read(ASettings::UserData::AcAllowIncomplete).toInt()) {
             QMessageBox message_box(this);
             message_box.setIcon(QMessageBox::Warning);
-            message_box.setText("Some or all recommended fields are empty.\nPlease go back and "
-                         "complete the form.\n\nYou can allow logging incomplete tail entries on the settings page.");
+            message_box.setText(tr("Some or all recommended fields are empty.<br>"
+                                   "Please go back and complete the form.<br><br>"
+                                   "You can allow logging incomplete tail entries "
+                                   "on the settings page."));
             message_box.exec();
             return;
         } else {
             QMessageBox::StandardButton reply;
-            reply = QMessageBox::question(this, "Warning",
-                                          "Some recommended fields are empty.\n\n"
+            reply = QMessageBox::question(this, tr("Warning"),
+                                          tr("Some recommended fields are empty.<br><br>"
                                           "If you do not fill out the aircraft details, "
-                                          "it will be impossible to automatically determine Single/Multi Pilot Times or Single/Multi Engine Time."
-                                          "This will also impact statistics and auto-logging capabilites.\n\n"
-                                          "It is highly recommended to fill in all the details.\n\n"
-                                          "Are you sure you want to proceed?",
+                                          "it will be impossible to automatically determine "
+                                          "Single/Multi Pilot Times or Single/Multi Engine Time."
+                                          "This will also impact statistics and auto-logging capabilites.<br><br>"
+                                          "It is highly recommended to fill in all the details.<br><br>"
+                                          "Are you sure you want to proceed?"),
                                           QMessageBox::Yes | QMessageBox::No);
             if (reply == QMessageBox::Yes) {
                 submitForm();
@@ -292,18 +297,17 @@ void NewTailDialog::on_buttonBox_accepted()
 
 void NewTailDialog::onSearchCompleterActivated()
 {
-    DEB << "Search completer activated!";
     const auto &text = ui->searchLineEdit->text();
     if (aircraftList.contains(text)) {
 
             DEB << "Template Selected. aircraft_id is: " << idMap.value(text);
             //call autofiller for dialog
             fillForm(aDB->getAircraftEntry(idMap.value(text)), true);
-            ui->searchLineEdit->setStyleSheet("border: 1px solid green");
+            ui->searchLineEdit->setStyleSheet(QStringLiteral("border: 1px solid green"));
             ui->searchLabel->setText(text);
         } else {
             //for example, editing finished without selecting a result from Qcompleter
-            ui->searchLineEdit->setStyleSheet("border: 1px solid orange");
+            ui->searchLineEdit->setStyleSheet(QStringLiteral("border: 1px solid orange"));
         }
 }
 

+ 1 - 0
src/gui/dialogues/newtaildialog.h

@@ -22,6 +22,7 @@
 #include <QCompleter>
 #include <QMessageBox>
 #include <QRegularExpression>
+#include <QComboBox>
 
 #include "src/classes/asettings.h"
 #include "src/functions/acalc.h"

+ 45 - 27
src/gui/widgets/aircraftwidget.cpp

@@ -85,12 +85,12 @@ void AircraftWidget::on_deleteButton_clicked()
 {
     if (selectedTails.length() == 0) {
         QMessageBox message_box(this);
-        message_box.setText(QStringLiteral("No Aircraft selected."));
+        message_box.setText(tr("No Aircraft selected."));
         message_box.exec();
 
     } else if (selectedTails.length() > 1) {
         QMessageBox message_box(this);
-        message_box.setText(QStringLiteral("Deleting multiple entries is currently not supported"));
+        message_box.setText(tr("Deleting multiple entries is currently not supported"));
         message_box.exec();
         /// [F] to do: for (const auto& row_id : selectedPilots) { do batchDelete }
         /// I am not sure if enabling this functionality for this widget is a good idea.
@@ -104,42 +104,59 @@ void AircraftWidget::on_deleteButton_clicked()
     } else if (selectedTails.length() == 1) {
         auto entry = aDB->getTailEntry(selectedTails.first());
         QMessageBox message_box(this);
-        QString message = "You are deleting the following aircraft:<br><br><b><tt>";
-        message.append(entry.registration() + QStringLiteral(" - (") + entry.type() + ')');
-        message.append(QStringLiteral("</b></tt><br><br>Are you sure?"));
-        message_box.setText(message);
-        message_box.exec();
-        if(!aDB->remove(entry))
-            onDeleteUnsuccessful();
+        message_box.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
+        message_box.setDefaultButton(QMessageBox::No);
+        message_box.setIcon(QMessageBox::Question);
+        message_box.setWindowTitle(tr("Delete Aircraft"));
+        message_box.setText(tr("You are deleting the following aircraft:<br><br><b><tt>"
+                               "%1 - (%2)</b></tt><br><br>Are you sure?"
+                               ).arg(entry.registration(),
+                                     entry.type()));
+
+        if (message_box.exec() == QMessageBox::Yes) {
+            if(!aDB->remove(entry))
+                onDeleteUnsuccessful();
         }
+    }
+
     model->select();
 }
 
 void AircraftWidget::onDeleteUnsuccessful()
 {
-    /// [F]: To do: Some logic to display a warning if too many entries exists, so that
-    /// the messagebox doesn't grow too tall.
-    QList<int> foreign_key_constraints = aDB->getForeignKeyConstraints(selectedTails.first(), ADatabaseTarget::tails);
+    QList<int> foreign_key_constraints = aDB->getForeignKeyConstraints(selectedTails.first(),
+                                                                       ADatabaseTarget::tails);
     QList<AFlightEntry> constrained_flights;
     for (const auto &row_id : qAsConst(foreign_key_constraints)) {
         constrained_flights.append(aDB->getFlightEntry(row_id));
     }
 
-    QString message = "<br>Unable to delete.<br><br>";
-    if(!constrained_flights.isEmpty()){
-        message.append(QStringLiteral("This is most likely the case because a flight exists with the aircraft "
-                   "you are trying to delete.<br>"
-                   "The following flight(s) with this aircraft have been found:<br><br><br><b><tt>"));
-        for (auto &flight : constrained_flights) {
-            message.append(flight.summary() + QStringLiteral("&nbsp;&nbsp;&nbsp;&nbsp;<br>"));
+    QMessageBox message_box(this);
+    if (constrained_flights.isEmpty()) {
+        message_box.setText(tr("<br>Unable to delete.<br><br>The following error has ocurred: %1"
+                               ).arg(aDB->lastError.text()));
+        message_box.exec();
+        return;
+    } else {
+        QString constrained_flights_string;
+        for (int i=0; i<constrained_flights.length(); i++) {
+            constrained_flights_string.append(constrained_flights[i].summary() + QStringLiteral("&nbsp;&nbsp;&nbsp;&nbsp;<br>"));
+            if (i>10) {
+                constrained_flights_string.append("<br>[...]<br>");
+                break;
+            }
         }
+        message_box.setText(tr("Unable to delete.<br><br>"
+                               "This is most likely the case because a flight exists with the aircraft "
+                               "you are trying to delete.<br><br>"
+                               "%1 flight(s) with this aircraft have been found:<br><br><br><b><tt>"
+                               "%2"
+                               "</b></tt><br><br>You have to change or remove the conflicting flight(s) "
+                               "before removing this aircraft from the database.<br><br>"
+                               ).arg(QString::number(constrained_flights.length()), constrained_flights_string));
+        message_box.setIcon(QMessageBox::Critical);
+        message_box.exec();
     }
-    message.append(QStringLiteral("</b></tt><br><br>You have to change or remove the conflicting flight(s) "
-                                  "before removing this aircraft from the database.<br><br>"));
-    QMessageBox message_box(this);
-    message_box.setText(message);
-    message_box.setIcon(QMessageBox::Critical);
-    message_box.exec();
 }
 
 void AircraftWidget::on_newAircraftButton_clicked()
@@ -155,7 +172,9 @@ void AircraftWidget::on_aircraftSearchLineEdit_textChanged(const QString &arg1)
     if(ui->aircraftSearchComboBox->currentIndex() == 0){
         ui->aircraftSearchLineEdit->setText(arg1.toUpper());
     }
-    model->setFilter(ui->aircraftSearchComboBox->currentText() + " LIKE \"%" + arg1 + "%\"");
+    model->setFilter(ui->aircraftSearchComboBox->currentText()
+                     + QStringLiteral(" LIKE \"%")
+                     + arg1 + QStringLiteral("%\""));
 }
 
 void AircraftWidget::onDisplayModel_dataBaseUpdated()
@@ -167,7 +186,6 @@ void AircraftWidget::onDisplayModel_dataBaseUpdated()
 void AircraftWidget::tableView_selectionChanged()
 {
     if (this->findChild<NewTailDialog*>() != nullptr) {
-        DEB << "Selection changed. Deleting orphaned dialog.";
         delete this->findChild<NewTailDialog*>();
         /// [F] if the user changes the selection without making any changes,
         /// if(selectedTails.length() == 1) spawns a new dialog without the

+ 35 - 33
src/gui/widgets/logbookwidget.cpp

@@ -25,11 +25,11 @@
 #include "src/testing/adebug.h"
 
 const QMap<int, QString> FILTER_MAP = {
-    {0, "Date LIKE \"%"},
-    {1, "Dept LIKE \"%"},
-    {2, "Dest LIKE \"%"},
-    {3, "Registration LIKE \"%"},
-    {4, "\"Name PIC\" LIKE \"%"}
+    {0, QStringLiteral("Date LIKE \"%")},
+    {1, QStringLiteral("Dept LIKE \"%")},
+    {2, QStringLiteral("Dest LIKE \"%")},
+    {3, QStringLiteral("Registration LIKE \"%")},
+    {4, QStringLiteral("\"Name PIC\" LIKE \"%")}
 };
 const auto NON_WORD_CHAR = QRegularExpression("\\W");
 
@@ -86,7 +86,7 @@ void LogbookWidget::setupDefaultView()
 {
     DEB << "Loading Default View...";
     displayModel = new QSqlTableModel(this);
-    displayModel->setTable("viewDefault");
+    displayModel->setTable(QStringLiteral("viewDefault"));
     displayModel->select();
 
     view = ui->tableView;
@@ -119,7 +119,7 @@ void LogbookWidget::setupEasaView()
 {
     DEB << "Loading EASA View...";
     displayModel = new QSqlTableModel;
-    displayModel->setTable("viewEASA");
+    displayModel->setTable(QStringLiteral("viewEASA"));
     displayModel->select();
 
     view = ui->tableView;
@@ -188,10 +188,11 @@ void LogbookWidget::on_editFlightButton_clicked()
         ef->exec();
         displayModel->select();
     } else if (selectedFlights.isEmpty()) {
-        messageBox->setText("No flight selected.\n");
+        messageBox->setText(tr("<br>No flight selected.<br>"));
         messageBox->exec();
     } else {
-        messageBox->setText("More than one flight selected.\n\nEditing multiple entries is not yet supported.");
+        messageBox->setText(tr("<br>More than one flight selected."
+                               "<br><br>Editing multiple entries is not yet supported."));
         messageBox->exec();
     }
 }
@@ -201,68 +202,69 @@ void LogbookWidget::on_deleteFlightPushButton_clicked()
     DEB << "Flights selected: " << selectedFlights.length();
     if (selectedFlights.length() == 0) {
         messageBox->setIcon(QMessageBox::Information);
-        messageBox->setText("No Flight Selected.");
+        messageBox->setText(tr("<br>No flight selected.<br>"));
         messageBox->exec();
         return;
-    } else if (selectedFlights.length() > 0 && selectedFlights.length() < 11) {
+    } else if (selectedFlights.length() > 0 && selectedFlights.length() <= 10) {
         QList<AFlightEntry> flights_list;
 
         for (const auto &flight_id : selectedFlights) {
             flights_list.append(aDB->getFlightEntry(flight_id));
         }
 
-        QString warningMsg = "The following flight(s) will be deleted:<br><br><b><tt>";
+        QString flights_list_string;
 
         for (auto &flight : flights_list) {
-            warningMsg.append(flight.summary());
-            warningMsg.append(QLatin1String("&nbsp;&nbsp;&nbsp;&nbsp;<br>"));
+            flights_list_string.append(flight.summary());
+            flights_list_string.append(QStringLiteral("&nbsp;&nbsp;&nbsp;&nbsp;<br>"));
         }
-        warningMsg.append("</b></tt><br>Deleting Flights is irreversible."
-                          "<br>Do you want to proceed?");
 
         QMessageBox confirm;
         confirm.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
         confirm.setDefaultButton(QMessageBox::No);
         confirm.setIcon(QMessageBox::Question);
         confirm.setWindowTitle("Delete Flight");
-        confirm.setText(warningMsg);
-        int reply = confirm.exec();
-        if (reply == QMessageBox::Yes) {
+        confirm.setText(tr("The following flight(s) will be deleted:<br><br><b><tt>"
+                           "%1<br></b></tt>"
+                           "Deleting flights is irreversible.<br>Do you want to proceed?"
+                           ).arg(flights_list_string));
+        if (confirm.exec() == QMessageBox::Yes) {
             for (auto& flight : flights_list) {
                 DEB << "Deleting flight: " << flight.summary();
                 if(!aDB->remove(flight)) {
-                    messageBox->setText(aDB->lastError.text());
+                    confirm.setText(tr("<br>Unable to delete.<br><br>The following error has ocurred: %1"
+                                       ).arg(aDB->lastError.text()));
                     messageBox->exec();
                     return;
                 }
             }
-            messageBox->setText(QString::number(selectedFlights.length()) + " flights have been deleted successfully.");
+            messageBox->setText(tr("%1 flights have been deleted successfully."
+                                   ).arg(QString::number(selectedFlights.length())));
             messageBox->exec();
             displayModel->select();
         }
     } else if (selectedFlights.length() > 10) {
-        auto warningMsg = "You have selected " + QString::number(selectedFlights.length())
-                + " flights.\n\n Deleting flights is irreversible.\n\n"
-                  "Are you sure you want to proceed?";
         QMessageBox confirm;
         confirm.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
         confirm.setDefaultButton(QMessageBox::No);
         confirm.setIcon(QMessageBox::Warning);
         confirm.setWindowTitle("Delete Flight");
-        confirm.setText(warningMsg);
-        int reply = confirm.exec();
-        if(reply == QMessageBox::Yes) {
+        confirm.setText(tr("You have selected %1 flights.<br><br>"
+                           "Deleting flights is irreversible.<br><br>"
+                           "Are you sure you want to proceed?"
+                           ).arg(QString::number(selectedFlights.length())));
+        if(confirm.exec() == QMessageBox::Yes) {
             QList<DataPosition> selected_flights;
             for (const auto& flight_id : selectedFlights) {
-                selected_flights.append({QLatin1String("flights"), flight_id});
+                selected_flights.append({QStringLiteral("flights"), flight_id});
             }
             if (!aDB->removeMany(selected_flights)) {
-
                 messageBox->setText(aDB->lastError.text()); // [F]: To Do: error info
                 messageBox->exec();
                 return;
             }
-            messageBox->setText(QString::number(selectedFlights.length()) + " flights have been deleted successfully.");
+            messageBox->setText(tr("%1 flights have been deleted successfully."
+                                   ).arg(QString::number(selectedFlights.length())));
             messageBox->exec();
             displayModel->select();
         }
@@ -324,15 +326,15 @@ void LogbookWidget::on_flightSearchLlineEdit_textChanged(const QString &arg1)
 
     if (ui->flightSearchComboBox->currentIndex() < 3) {
         displayModel->setFilter(FILTER_MAP.value(ui->flightSearchComboBox->currentIndex())
-                                + arg1 + "%\"");
+                                + arg1 + QStringLiteral("%\""));
         return;
     } else if (ui->flightSearchComboBox->currentIndex() == 3) { // registration
         displayModel->setFilter(FILTER_MAP.value(ui->flightSearchComboBox->currentIndex())
-                                + arg1 + "%\"");
+                                + arg1 + QStringLiteral("%\""));
         return;
     } else if (ui->flightSearchComboBox->currentIndex() == 4) { // Name Pic
         displayModel->setFilter(FILTER_MAP.value(ui->flightSearchComboBox->currentIndex())
-                                + arg1 + "%\"");
+                                + arg1 + QStringLiteral("%\""));
         return;
     }
 }

+ 42 - 26
src/gui/widgets/pilotswidget.cpp

@@ -40,8 +40,8 @@ void PilotsWidget::setupModelAndView()
     sortColumn = ASettings::read(ASettings::UserData::PilSortColumn).toInt();
 
     model = new QSqlTableModel(this);
-    model->setTable("viewPilots");
-    model->setFilter("ID > 1");//to not allow editing of self, shall be done via settings
+    model->setTable(QStringLiteral("viewPilots"));
+    model->setFilter(QStringLiteral("ID > 1")); // Don't show self
     model->select();
 
     view = ui->pilotsTableView;
@@ -81,7 +81,6 @@ void PilotsWidget::onDisplayModel_dataBaseUpdated()
 void PilotsWidget::tableView_selectionChanged()//const QItemSelection &index, const QItemSelection &
 {
     if (this->findChild<NewPilotDialog*>() != nullptr) {
-        DEB << "Selection changed. Deleting orphaned dialog.";
         delete this->findChild<NewPilotDialog*>();
         /// [F] if the user changes the selection without making any changes,
         /// if(selectedPilots.length() == 1) spawns a new dialog without the
@@ -133,12 +132,12 @@ void PilotsWidget::on_deletePilotButton_clicked()
 {
     if (selectedPilots.length() == 0) {
         QMessageBox message_box(this);
-        message_box.setText("No Pilot selected.");
+        message_box.setText(tr("No Pilot selected."));
         message_box.exec();
 
     } else if (selectedPilots.length() > 1) {
         QMessageBox message_box(this);
-        message_box.setText("Deleting multiple entries is currently not supported");
+        message_box.setText(tr("Deleting multiple entries is currently not supported"));
         message_box.exec();
         /// [F] to do: for (const auto& row_id : selectedPilots) { do batchDelete }
         /// I am not sure if enabling this functionality for this widget is a good idea.
@@ -152,14 +151,18 @@ void PilotsWidget::on_deletePilotButton_clicked()
     } else if (selectedPilots.length() == 1) {
         auto entry = aDB->getPilotEntry(selectedPilots.first());
         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?"));
-        message_box.setText(message);
-        message_box.exec();
-        if(!aDB->remove(entry))
-            onDeleteUnsuccessful();
+        message_box.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
+        message_box.setDefaultButton(QMessageBox::No);
+        message_box.setIcon(QMessageBox::Question);
+        message_box.setWindowTitle(tr("Delete Pilot"));
+
+        message_box.setText(tr("You are deleting the following pilot:<br><br><b><tt>"
+                               "%1</b></tt><br><br>Are you sure?").arg(entry.name()));
+        if (message_box.exec() == QMessageBox::Yes) {
+            if(!aDB->remove(entry))
+                onDeleteUnsuccessful();
         }
+    }
     model->select();
 }
 
@@ -167,27 +170,40 @@ void PilotsWidget::onDeleteUnsuccessful()
 {
     /// [F]: To do: Some logic to display a warning if too many entries exists, so that
     /// the messagebox doesn't grow too tall.
-    QList<int> foreign_key_constraints = aDB->getForeignKeyConstraints(selectedPilots.first(), ADatabaseTarget::pilots);
+    QList<int> foreign_key_constraints = aDB->getForeignKeyConstraints(selectedPilots.first(),
+                                                                       ADatabaseTarget::pilots);
     QList<AFlightEntry> constrained_flights;
     for (const auto &row_id : foreign_key_constraints) {
         constrained_flights.append(aDB->getFlightEntry(row_id));
     }
 
-    QString message = "<br>Unable to delete.<br><br>";
-    if(!constrained_flights.isEmpty()){
-        message.append(QStringLiteral("This is most likely the case because a flight exists with the Pilot "
-                   "you are trying to delete as PIC.<br>"
-                   "The following flight(s) with this pilot have been found:<br><br><br><b><tt>"));
-        for (auto &flight : constrained_flights) {
-            message.append(flight.summary() + QStringLiteral("&nbsp;&nbsp;&nbsp;&nbsp;<br>"));
+    QMessageBox message_box(this);
+    if (constrained_flights.isEmpty()) {
+        message_box.setText(tr("<br>Unable to delete.<br><br>The following error has ocurred:<br>%1"
+                               ).arg(aDB->lastError.text()));
+        message_box.exec();
+        return;
+    } else {
+        QString constrained_flights_string;
+        for (int i=0; i<constrained_flights.length(); i++) {
+            constrained_flights_string.append(constrained_flights[i].summary() + QStringLiteral("&nbsp;&nbsp;&nbsp;&nbsp;<br>"));
+            if (i>10) {
+                constrained_flights_string.append("<br>[...]<br>");
+                break;
+            }
         }
+        message_box.setText(tr("Unable to delete.<br><br>"
+                               "This is most likely the case because a flight exists with the Pilot "
+                               "you are trying to delete as PIC.<br><br>"
+                               "%1 flight(s) with this pilot have been found:<br><br><br><b><tt>"
+                               "%2"
+                               "</b></tt><br><br>You have to change or remove the conflicting flight(s) "
+                               "before removing this pilot from the database.<br><br>"
+                               ).arg(QString::number(constrained_flights.length()),
+                                     constrained_flights_string));
+        message_box.setIcon(QMessageBox::Critical);
+        message_box.exec();
     }
-    message.append(QStringLiteral("</b></tt><br><br>You have to change or remove the conflicting flight(s) "
-                                  "before removing this pilot from the database.<br><br>"));
-    QMessageBox message_box(this);
-    message_box.setText(message);
-    message_box.setIcon(QMessageBox::Critical);
-    message_box.exec();
 }
 
 void PilotsWidget::pilot_editing_finished()

+ 25 - 24
src/gui/widgets/settingswidget.cpp

@@ -27,25 +27,24 @@
 #include <QStyleFactory>
 
 static const auto FIRSTNAME_VALID = QPair<QString, QRegularExpression> {
-    "firstnameLineEdit", QRegularExpression("[a-zA-Z]+")};
+    QStringLiteral("firstnameLineEdit"), QRegularExpression("[a-zA-Z]+")};
 static const auto LASTNAME_VALID = QPair<QString, QRegularExpression> {
-    "lastnameLineEdit", QRegularExpression("\\w+")};
+    QStringLiteral("lastnameLineEdit"), QRegularExpression("\\w+")};
 static const auto PHONE_VALID = QPair<QString, QRegularExpression> {
-    "phoneLineEdit", QRegularExpression("^[+]{0,1}[0-9\\-\\s]+")};
+    QStringLiteral("phoneLineEdit"), QRegularExpression("^[+]{0,1}[0-9\\-\\s]+")};
 static const auto EMAIL_VALID = QPair<QString, QRegularExpression> {
-    "emailLineEdit", QRegularExpression("\\A[a-z0-9!#$%&'*+/=?^_‘{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_‘{|}~-]+)*@"
+    QStringLiteral("emailLineEdit"), QRegularExpression("\\A[a-z0-9!#$%&'*+/=?^_‘{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_‘{|}~-]+)*@"
                                         "(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\z")};
 static const auto COMPANY_VALID = QPair<QString, QRegularExpression> {
-    "companyLineEdit", QRegularExpression("\\w+")};
+    QStringLiteral("companyLineEdit"), QRegularExpression("\\w+")};
 static const auto EMPLOYEENR_VALID = QPair<QString, QRegularExpression> {
-    "employeeidLineEdit", QRegularExpression("\\w+")};
+    QStringLiteral("employeeidLineEdit"), QRegularExpression("\\w+")};
 static const auto PREFIX_VALID = QPair<QString, QRegularExpression> {
-    "prefixLineEdit", QRegularExpression("[a-zA-Z0-9]?[a-zA-Z0-9]?[a-zA-Z0-9]")};
+    QStringLiteral("prefixLineEdit"), QRegularExpression("[a-zA-Z0-9]?[a-zA-Z0-9]?[a-zA-Z0-9]")};
 
-static const auto LINE_EDIT_VALIDATORS = QVector<QPair<QString, QRegularExpression>>({FIRSTNAME_VALID, LASTNAME_VALID,
-                                           PHONE_VALID,     EMAIL_VALID,
-                                           COMPANY_VALID,     EMPLOYEENR_VALID,
-                                           PREFIX_VALID});
+static const auto LINE_EDIT_VALIDATORS = QVector<QPair<QString, QRegularExpression>>{
+    FIRSTNAME_VALID, LASTNAME_VALID, PHONE_VALID, EMAIL_VALID,
+    COMPANY_VALID, EMPLOYEENR_VALID, PREFIX_VALID};
 
 SettingsWidget::SettingsWidget(QWidget *parent) :
     QWidget(parent),
@@ -278,13 +277,13 @@ void SettingsWidget::on_acAllowIncompleteComboBox_currentIndexChanged(int index)
     ASettings::write(ASettings::UserData::AcAllowIncomplete, index);
     if (index) {
         QMessageBox::StandardButton reply;
-        reply = QMessageBox::warning(this, "Warning",
-                                      "Enabling incomplete logging will enable you to add aircraft with incomplete data.\n\n"
+        reply = QMessageBox::warning(this, tr("Warning"),
+                                      tr("Enabling incomplete logging will enable you to add aircraft with incomplete data.<br><br>"
                                       "If you do not fill out the aircraft details, "
                                       "it will be impossible to automatically determine Single/Multi Pilot Times or Single/Multi Engine Time. "
-                                      "This will also impact statistics and auto-logging capabilites as well as jeopardise database integrity.\n\n"
-                                      "It is highly recommended to keep this option off unless you have a specific reason not to.\n\n"
-                                      "Are you sure you want to proceed?",
+                                      "This will also impact statistics and auto-logging capabilites as well as jeopardise database integrity.<br><br>"
+                                      "It is highly recommended to keep this option off unless you have a specific reason not to.<br><br>"
+                                      "Are you sure you want to proceed?"),
                                       QMessageBox::Yes | QMessageBox::No);
         if (reply == QMessageBox::Yes) {
             ASettings::write(ASettings::UserData::AcAllowIncomplete, index);
@@ -307,7 +306,7 @@ void SettingsWidget::on_aboutPushButton_clicked()
 
                        "<h3><center>About openPilotLog</center></h3>"
                        "<br>"
-                       "(c) 2020 Felix Turowsky"
+                       "(c) 2020-2021 Felix Turowsky"
                        "<br>"
                        "<p>This is a collaboratively developed Free and Open Source Application. "
                        "Visit us <a href=\"https://%1/\">here</a> for more information.</p>"
@@ -324,16 +323,18 @@ void SettingsWidget::on_aboutPushButton_clicked()
 
                        "<p>You should have received a copy of the GNU General Public License "
                        "along with this program.  If not, "
-                       "please click <a href=\"https://www.gnu.org/licenses/\">here</a>.</p>"
+                       "please click <a href=\"https://%2\">here</a>.</p>"
 
                        "<br>"
 
-                       "<p>This program uses <a href=\"http://%2/\">Qt</a> version %3 and "
-                       "<a href=\"https://sqlite.org/about.html\">SQLite</a> version %4</p>"
-                   ).arg(QLatin1String("github.com/fiffty-50/openpilotlog"),
-                         QLatin1String("qt.io"),
-                         QLatin1String(QT_VERSION_STR),
-                         QString(SQLITE_VERSION));
+                       "<p>This program uses <a href=\"http://%3/\">Qt</a> version %4 and "
+                       "<a href=\"https://%5/\">SQLite</a> version %6</p>"
+                   ).arg(QStringLiteral("github.com/fiffty-50/openpilotlog"),
+                         QStringLiteral("gnu.org/licenses/"),
+                         QStringLiteral("qt.io"),
+                         QT_VERSION_STR,
+                         QStringLiteral("sqlite.org/about.html"),
+                         SQLITE_VERSION);
     message_box.setText(text);
     message_box.exec();
 }

+ 16 - 7
src/gui/widgets/totalswidget.cpp

@@ -18,6 +18,7 @@
 #include "totalswidget.h"
 #include "ui_totalswidget.h"
 #include "src/testing/adebug.h"
+#include "src/database/adatabase.h"
 
 TotalsWidget::TotalsWidget(QWidget *parent) :
     QWidget(parent),
@@ -26,20 +27,28 @@ TotalsWidget::TotalsWidget(QWidget *parent) :
     ui->setupUi(this);
     auto data = AStat::totals();
     DEB << "Filling Totals Line Edits...";
-    //DEB << "data: " << data;
     for (const auto &field : data) {
         auto line_edit = parent->findChild<QLineEdit *>(field.first + "LineEdit");
         line_edit->setText(field.second);
     }
-    QSettings settings;
-    QString name = settings.value("userdata/firstname").toString();
-    if(!name.isEmpty()) {
-        QString salutation = "Welcome to openPilotLog, " + name + QLatin1Char('!');
-        ui->welcomeLabel->setText(salutation);
-    }
+
+    QString salutation = tr("Welcome to openPilotLog");
+    salutation.append(QStringLiteral(", ") + userName() + QLatin1Char('!'));
+
+    ui->welcomeLabel->setText(salutation);
 }
 
 TotalsWidget::~TotalsWidget()
 {
     delete ui;
 }
+
+const QString TotalsWidget::userName()
+{
+    auto namestring = aDB->getPilotEntry(1).name();
+    auto names = namestring.split(',');
+    if (!names.isEmpty())
+        return names[0];
+
+    return QString();
+}

+ 1 - 0
src/gui/widgets/totalswidget.h

@@ -39,6 +39,7 @@ public:
 
 private:
     Ui::TotalsWidget *ui;
+    const QString userName();
 };
 
 #endif // TOTALSWIDGET_H