Sfoglia il codice sorgente

fixed bug in aircraft class where the wrong table was referenced for templates

fiffty-50 4 anni fa
parent
commit
71f8caa0fe

+ 5 - 5
openPilotLog.pro.user

@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <!DOCTYPE QtCreatorProject>
-<!-- Written by QtCreator 4.13.2, 2020-11-19T09:18:31. -->
+<!-- Written by QtCreator 4.13.2, 2020-11-19T10:28:36. -->
 <qtcreator>
  <data>
   <variable>EnvironmentId</variable>
@@ -323,19 +323,19 @@
     <valuelist type="QVariantList" key="CustomOutputParsers"/>
     <value type="int" key="PE.EnvironmentAspect.Base">2</value>
     <valuelist type="QVariantList" key="PE.EnvironmentAspect.Changes"/>
-    <value type="QString" key="ProjectExplorer.CustomExecutableRunConfiguration.Executable"></value>
-    <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.CustomExecutableRunConfiguration</value>
-    <value type="QString" key="ProjectExplorer.RunConfiguration.BuildKey"></value>
+    <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.Qt4RunConfiguration:/home/felix/git/openpilotlog/openPilotLog.pro</value>
+    <value type="QString" key="ProjectExplorer.RunConfiguration.BuildKey">/home/felix/git/openpilotlog/openPilotLog.pro</value>
     <value type="QString" key="RunConfiguration.Arguments"></value>
     <value type="bool" key="RunConfiguration.Arguments.multi">false</value>
     <value type="QString" key="RunConfiguration.OverrideDebuggerStartup"></value>
     <value type="bool" key="RunConfiguration.UseCppDebugger">false</value>
     <value type="bool" key="RunConfiguration.UseCppDebuggerAuto">true</value>
+    <value type="bool" key="RunConfiguration.UseLibrarySearchPath">true</value>
     <value type="bool" key="RunConfiguration.UseMultiProcess">false</value>
     <value type="bool" key="RunConfiguration.UseQmlDebugger">false</value>
     <value type="bool" key="RunConfiguration.UseQmlDebuggerAuto">true</value>
     <value type="QString" key="RunConfiguration.WorkingDirectory"></value>
-    <value type="QString" key="RunConfiguration.WorkingDirectory.default"></value>
+    <value type="QString" key="RunConfiguration.WorkingDirectory.default">/home/felix/git/build-openPilotLog-Desktop-Debug</value>
    </valuemap>
    <value type="int" key="ProjectExplorer.Target.RunConfigurationCount">1</value>
   </valuemap>

+ 43 - 0
src/classes/aircraft.cpp

@@ -64,6 +64,49 @@ Aircraft::Aircraft(int tail_id)
     }
 }
 
+Aircraft::Aircraft(int acft_id, bool isTemplate)
+{
+    if(isTemplate){
+        //retreive database layout
+        const auto dbContent = DbInfo();
+        auto table = QLatin1String("aircraft");
+
+        //Check database for row id
+        QString statement = "SELECT COUNT(*) FROM " + table + " WHERE _rowid_=" + QString::number(acft_id);
+        QSqlQuery q(statement);
+        q.next();
+        int rows = q.value(0).toInt();
+        if (rows == 0) {
+            DEB("No Entry found for row id: " << acft_id );
+            position.second = 0;
+        } else {
+            DEB("Retreiving data for row id: " << acft_id);
+            QString statement = "SELECT * FROM " + table + " WHERE _rowid_=" + QString::number(acft_id);
+
+            QSqlQuery q(statement);
+            q.exec();
+            q.next();
+            for (int i = 0; i < dbContent.format.value(table).length(); i++) {
+                data.insert(dbContent.format.value(table)[i], q.value(i).toString());
+            }
+
+            error = q.lastError().text();
+            if (error.length() > 2) {
+                DEB("Error: " << q.lastError().text());
+                position.second = 0;
+                position.first = "invalid";
+            } else {
+                position.second = acft_id;
+                position.first = "aircraft";
+            }
+        }
+    } else {
+        DEB("This constructor is for use with templates only. To create an object from the tails table use"
+            "the tail_id only in the constructor.");
+    }
+
+}
+
 Aircraft::Aircraft(QMap<QString, QString> newData)
 {
     QString table = "tails";

+ 2 - 1
src/classes/aircraft.h

@@ -29,7 +29,8 @@ class Aircraft : public Entry
 //    using Entry::Entry;
 public:
     Aircraft();
-    Aircraft(int acft_id);
+    Aircraft(int tail_id);
+    Aircraft(int acft_id, bool isTemplate);
     Aircraft(QMap<QString, QString> newData);
 };
 

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

@@ -247,7 +247,7 @@ void NewTail::on_searchLineEdit_textChanged(const QString &arg1)
 
         DEB("Template Selected. aircraft_id is: " << idMap.value(arg1));
         //call autofiller for dialog
-        formFiller(Aircraft(idMap.value(arg1)));
+        formFiller(Aircraft(idMap.value(arg1), true));
         ui->searchLineEdit->setStyleSheet("border: 1px solid green");
     } else {
         //for example, editing finished without selecting a result from Qcompleter