Browse Source

Updated Debugwidget

Updated Debugwidget to use new DB API.

Added option to choose branch for updating database from Github.
Felix Turo 4 years ago
parent
commit
520612c5fe
3 changed files with 37 additions and 17 deletions
  1. 2 2
      mainwindow.cpp
  2. 18 15
      src/gui/widgets/debugwidget.cpp
  3. 17 0
      src/gui/widgets/debugwidget.ui

+ 2 - 2
mainwindow.cpp

@@ -76,7 +76,7 @@ MainWindow::MainWindow(QWidget *parent)
     /// [F] I understand how it is annoying to not have the database
     /// working when something has changed. Hopefully this check
     /// helps to avoid that in the future!
-    const int DATABASE_REVISION_NUMBER = 13;
+    const int DATABASE_REVISION_NUMBER = 14;
     QSqlQuery query;
     query.prepare("SELECT COUNT (*) FROM changelog");
     query.exec();
@@ -84,7 +84,7 @@ MainWindow::MainWindow(QWidget *parent)
     if (query.value(0).toInt() != DATABASE_REVISION_NUMBER) {
         DEB("##########################################");
         DEB("Your database is out of date.");
-        DEB("Curren Revision: " << DATABASE_REVISION_NUMBER);
+        DEB("Current Revision:  " << DATABASE_REVISION_NUMBER);
         DEB("You have revision: " << query.value(0).toInt());
         DEB("Use of DebugWidget to udpate recommended.");
         DEB("##########################################");

+ 18 - 15
src/gui/widgets/debugwidget.cpp

@@ -1,7 +1,7 @@
 #include "debugwidget.h"
 #include "ui_debugwidget.h"
 
-
+using namespace experimental;
 
 DebugWidget::DebugWidget(QWidget *parent) :
     QWidget(parent),
@@ -13,7 +13,6 @@ DebugWidget::DebugWidget(QWidget *parent) :
             ui->tableComboBox->addItem(table);
         }
     }
-
 }
 
 DebugWidget::~DebugWidget()
@@ -47,7 +46,9 @@ void DebugWidget::on_resetDatabasePushButton_clicked()
         dir.mkpath(".");
     // download latest csv
     QStringList templateTables = {"aircraft", "airports", "changelog"};
-    const auto& linkStub = "https://raw.githubusercontent.com/fiffty-50/openpilotlog/develop/assets/database/templates/";
+    QString linkStub = "https://raw.githubusercontent.com/fiffty-50/openpilotlog/";
+    linkStub.append(ui->branchLineEdit->text());
+    linkStub.append("/assets/database/templates/");
     for (const auto& table : templateTables) {
         QEventLoop loop;
         ADownload* dl = new ADownload;
@@ -59,7 +60,7 @@ void DebugWidget::on_resetDatabasePushButton_clicked()
         dl->deleteLater();
     }
     //close database connection
-    Db::disconnect();
+    aDB()->disconnect();
 
     // back up old database
     auto oldDatabase = QFile("data/logbook.db");
@@ -71,7 +72,7 @@ void DebugWidget::on_resetDatabasePushButton_clicked()
         }
     }
     // re-connct and create new database
-    Db::connect();
+    aDB()->connect();
 
     if (ADataBaseSetup::createDatabase()) {
         mb.setText("Database has been successfully reset.\n\nRestarting application.");
@@ -99,7 +100,10 @@ void DebugWidget::on_fillUserDataPushButton_clicked()
         dir.mkpath(".");
     // download latest csv
     QStringList userTables = {"pilots", "tails", "flights"};
-    const auto& linkStub = "https://raw.githubusercontent.com/fiffty-50/openpilotlog/develop/assets/database/templates/sample_";
+    QString linkStub = "https://raw.githubusercontent.com/fiffty-50/openpilotlog/";
+    linkStub.append(ui->branchLineEdit->text());
+    linkStub.append("/assets/database/templates/sample_");
+
     for (const auto& table : userTables) {
         QEventLoop loop;
         ADownload* dl = new ADownload;
@@ -110,19 +114,18 @@ void DebugWidget::on_fillUserDataPushButton_clicked()
         loop.exec(); // event loop waits for download done signal before allowing loop to continue
         dl->deleteLater();
     }
-    QVector<bool> allGood;
+    QBitArray allGood;
+    allGood.resize(userTables.size());
+
     for (const auto& table : userTables) {
         auto data = aReadCsv("data/templates/sample_" + table + ".csv");
-        allGood.append(ADataBaseSetup::commitData(data, table));
+        allGood.setBit(userTables.indexOf(table), ADataBaseSetup::commitData(data, table));
     }
 
-    for (const auto& item : allGood) {
-        if (!item) {
-            mb.setText("Errors have ocurred. Check console for details.");
-            mb.exec();
-            return;
-        }
-
+    if (allGood.count(true) != userTables.size()) {
+        mb.setText("Errors have ocurred. Check console for details.");
+        mb.exec();
+        return;
     }
 
     mb.setText("User tables successfully populated.\n\nRestarting app.");

+ 17 - 0
src/gui/widgets/debugwidget.ui

@@ -145,6 +145,23 @@
        <item row="5" column="3">
         <widget class="QLineEdit" name="debug2LineEdit"/>
        </item>
+       <item row="0" column="1">
+        <widget class="QLabel" name="branchLabel">
+         <property name="text">
+          <string>branch:</string>
+         </property>
+        </widget>
+       </item>
+       <item row="0" column="2">
+        <widget class="QLineEdit" name="branchLineEdit">
+         <property name="text">
+          <string>develop</string>
+         </property>
+         <property name="placeholderText">
+          <string>develop</string>
+         </property>
+        </widget>
+       </item>
       </layout>
      </widget>
     </widget>