Browse Source

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

fiffty-50 4 years ago
parent
commit
508b5f2da6
4 changed files with 4 additions and 47 deletions
  1. 0 43
      src/classes/aircraft.cpp
  2. 0 1
      src/classes/aircraft.h
  3. 2 2
      src/gui/dialogues/newtail.cpp
  4. 2 1
      src/gui/dialogues/newtail.h

+ 0 - 43
src/classes/aircraft.cpp

@@ -64,49 +64,6 @@ 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";

+ 0 - 1
src/classes/aircraft.h

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

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

@@ -112,7 +112,7 @@ void NewTail::setupValidators()
  * information contained in an aircraft object.
  * \param db - entry retreived from database
  */
-void NewTail::formFiller(Aircraft entry)
+void NewTail::formFiller(Entry entry)
 {
     DEB("Filling Form for a/c" << entry);
     //fill Line Edits
@@ -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), true));
+        formFiller(Entry("aircraft",idMap.value(arg1)));
         ui->searchLineEdit->setStyleSheet("border: 1px solid green");
     } else {
         //for example, editing finished without selecting a result from Qcompleter

+ 2 - 1
src/gui/dialogues/newtail.h

@@ -28,6 +28,7 @@
 #include "src/classes/aircraft.h"
 #include "src/classes/strictrxvalidator.h"
 #include "src/classes/calc.h"
+#include "src/database/entry.h"
 
 namespace Ui {
 class NewTail;
@@ -84,7 +85,7 @@ private:
 
     void setupValidators();
 
-    void formFiller(Aircraft);
+    void formFiller(Entry);
 
     bool verify();
 };