Browse Source

Merge remote-tracking branch 'origin/develop-removing-obsolete-code' into develop-removing-obsolete-code

George 4 years ago
parent
commit
836a517d18

+ 10 - 7
main.cpp

@@ -28,13 +28,16 @@
 #include <QFileInfo>
 #include <QStandardPaths>
 
+#define APPNAME "openPilotLog"
+#define ORGNAME APPNAME
+#define ORGDOMAIN "https://github.com/fiffty-50/openpilotlog"
 
 int main(int argc, char *argv[])
 {
     QApplication openPilotLog(argc, argv);
-    QCoreApplication::setOrganizationName("openPilotLog");
-    QCoreApplication::setOrganizationDomain("https://github.com/fiffty-50/openpilotlog");
-    QCoreApplication::setApplicationName("openPilotLog");
+    QCoreApplication::setOrganizationName(ORGNAME);
+    QCoreApplication::setOrganizationDomain(ORGDOMAIN);
+    QCoreApplication::setApplicationName(APPNAME);
 
     AStandardPaths::setup();
     AStandardPaths::scan_paths();
@@ -47,10 +50,10 @@ int main(int argc, char *argv[])
 
     aDB()->connect();
 
-    if (!ASettings::read("setup/setup_complete").toBool()) {
-        FirstRunDialog dialog;
-        dialog.exec();
-    }
+//    if (!ASettings::read("setup/setup_complete").toBool()) {
+//        FirstRunDialog dialog;
+//        dialog.exec();
+//    }
 
     //Theming
     int selectedtheme = ASettings::getSettings().value("main/theme").toInt();

+ 0 - 1
src/classes/asettings.h

@@ -24,7 +24,6 @@
  * \brief The Settings class is a thin wrapper for the QSettings class,
  * simplifying reading and writing of settings.
  */
-
 class ASettings
 {
 private:

+ 15 - 15
src/database/adatabase.cpp

@@ -159,11 +159,11 @@ bool ADatabase::removeMany(QList<DataPosition> data_position_list)
             lastError = ADatabaseError("Database entry not found.");
             errorCount++;
         }
-        QString statement = "DELETE FROM " + data_position.first +
+        QString statement = "DELETE FROM " + data_position.tableName +
                 " WHERE ROWID=?";
 
         query.prepare(statement);
-        query.addBindValue(data_position.second);
+        query.addBindValue(data_position.rowId);
         query.exec();
 
         if (!(query.lastError().type() == QSqlError::NoError))
@@ -191,7 +191,7 @@ bool ADatabase::removeMany(QList<DataPosition> data_position_list)
 
 bool ADatabase::exists(AEntry entry)
 {
-    if(entry.getPosition().second == 0)
+    if(entry.getPosition().rowId == 0)
         return false;
 
     //Check database for row id
@@ -221,15 +221,15 @@ bool ADatabase::exists(AEntry entry)
 
 bool ADatabase::exists(DataPosition data_position)
 {
-    if(data_position.second == 0)
+    if(data_position.rowId == 0)
         return false;
 
     //Check database for row id
-    QString statement = "SELECT COUNT(*) FROM " + data_position.first +
+    QString statement = "SELECT COUNT(*) FROM " + data_position.tableName +
             " WHERE ROWID=?";
     QSqlQuery query;
     query.prepare(statement);
-    query.addBindValue(data_position.second);
+    query.addBindValue(data_position.rowId);
     query.setForwardOnly(true);
     query.exec();
     //this returns either 1 or 0 since row ids are unique
@@ -242,7 +242,7 @@ bool ADatabase::exists(DataPosition data_position)
     if (rowId) {
         return true;
     } else {
-        DEB "No entry exists at DataPosition: " << data_position;
+        DEB "No entry exists at DataPosition: " << data_position.tableName << data_position.rowId;
         lastError = ADatabaseError("Database entry not found.");
         return false;
     }
@@ -334,17 +334,17 @@ bool ADatabase::insert(AEntry new_entry)
 RowData ADatabase::getEntryData(DataPosition data_position)
 {
     // check table exists
-    if (!tableNames.contains(data_position.first)) {
-        DEB data_position.first << " not a table in the database. Unable to retreive Entry data.";
+    if (!tableNames.contains(data_position.tableName)) {
+        DEB data_position.tableName << " not a table in the database. Unable to retreive Entry data.";
         return RowData();
     }
 
     //Check Database for rowId
-    QString statement = "SELECT COUNT(*) FROM " + data_position.first
+    QString statement = "SELECT COUNT(*) FROM " + data_position.tableName
                       + " WHERE ROWID=?";
     QSqlQuery check_query;
     check_query.prepare(statement);
-    check_query.addBindValue(data_position.second);
+    check_query.addBindValue(data_position.rowId);
     check_query.setForwardOnly(true);
     check_query.exec();
 
@@ -357,18 +357,18 @@ RowData ADatabase::getEntryData(DataPosition data_position)
 
     check_query.next();
     if (check_query.value(0).toInt() == 0) {
-        DEB "No Entry found for row id: " << data_position.second;
+        DEB "No Entry found for row id: " << data_position.rowId;
         lastError = ADatabaseError("Database entry not found.");
         return RowData();
     }
 
     // Retreive TableData
-    statement = "SELECT * FROM " + data_position.first
+    statement = "SELECT * FROM " + data_position.tableName
               + " WHERE ROWID=?";
 
     QSqlQuery select_query;
     select_query.prepare(statement);
-    select_query.addBindValue(data_position.second);
+    select_query.addBindValue(data_position.rowId);
     select_query.setForwardOnly(true);
     select_query.exec();
 
@@ -382,7 +382,7 @@ RowData ADatabase::getEntryData(DataPosition data_position)
     select_query.next();
     RowData entry_data;
 
-    for (const auto &column : tableColumns.value(data_position.first)) {
+    for (const auto &column : tableColumns.value(data_position.tableName)) {
         entry_data.insert(column, select_query.value(column));
     }
     return entry_data;

+ 16 - 1
src/database/declarations.h

@@ -30,7 +30,7 @@ using TableColumns = QMap<TableName, ColumnNames>;
 // [F]: Good idea! Implementing something similar to first and second methods
 // of QPair would be useful to carry over, or some other way of quickly and
 // unambiguously accessing the elements.
-struct DataPosition : QPair<TableName, RowId> {
+/*struct DataPosition : QPair<TableName, RowId> {
     TableName tableName;
     RowId rowId;
     DataPosition()
@@ -40,6 +40,21 @@ struct DataPosition : QPair<TableName, RowId> {
         : QPair<TableName, RowId>::QPair(table_name, row_id),
           tableName(first), rowId(second)
     {}
+    DataPosition(const DataPosition& other) = default;
+    DataPosition& operator=(const DataPosition& other) = default;
+};*/
+
+//[F]: How about something like this?
+struct DataPosition {
+    TableName tableName;
+    RowId rowId;
+    DataPosition()
+        : tableName(TableName())
+    {};
+    DataPosition(TableName table_name, RowId row_id)
+        : tableName(table_name), rowId(row_id)
+    {};
+
     DataPosition(const DataPosition& other) = default;
     DataPosition& operator=(const DataPosition& other) = default;
 };

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

@@ -82,7 +82,7 @@ NewPilotDialog::NewPilotDialog(int rowId, QWidget *parent) :
     setup();
 
     pilotEntry = aDB()->getPilotEntry(rowId);
-    DEB "Pilot Entry position: " << pilotEntry.getPosition();
+    DEB "Pilot Entry position: " << pilotEntry.getPosition().tableName << pilotEntry.getPosition().rowId;
     formFiller();
     ui->lastnameLineEdit->setFocus();
 }
@@ -150,7 +150,7 @@ void NewPilotDialog::submitForm()
     }
 
     pilotEntry.setData(new_data);
-    DEB "Pilot entry position: " << pilotEntry.getPosition();
+    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);

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

@@ -113,7 +113,7 @@ void NewTailDialog::setupValidators()
  */
 void NewTailDialog::fillForm(AEntry entry, bool is_template)
 {
-    DEB "Filling Form for a/c" << entry.getPosition();
+    DEB "Filling Form for a/c" << entry.getPosition().tableName << entry.getPosition().rowId;
     //fill Line Edits
     auto line_edits = this->findChildren<QLineEdit *>();
 
@@ -216,8 +216,8 @@ void NewTailDialog::submitForm()
         message_box.exec();
         return;
     } else {
-        if (entry.getPosition().second != 0)
-            ACalc::updateAutoTimes(entry.getPosition().second);
+        if (entry.getPosition().rowId != 0)
+            ACalc::updateAutoTimes(entry.getPosition().rowId);
         QDialog::accept();
     }
 }