Kaynağa Gözat

Made sure backups are read sorted, moved checkDbVersion to ADatabase

George 4 yıl önce
ebeveyn
işleme
be23bf8b36

+ 3 - 10
mainwindow.cpp

@@ -73,13 +73,13 @@ MainWindow::MainWindow(QWidget *parent)
 
 
     // check database version (Debug)
-    int db_ver = checkDbVersion();
+    int db_ver = aDB->dbVersion();
     if (db_ver != DATABASE_REVISION) {
-        DEB << "############## WARNING ####################";
+        DEB << "############## WARNING ##############";
         DEB << "Your database is out of date.";
         DEB << "Current Revision:\t" << DATABASE_REVISION;
         DEB << "You have revision:\t" << db_ver;
-        DEB << "############## WARNING ###################";
+        DEB << "############## WARNING ##############";
         QMessageBox message_box(this); //error box
         message_box.setText(tr("Database revision out of date!"));
         message_box.exec();
@@ -180,13 +180,6 @@ void MainWindow::on_actionDebug_triggered()
 
 // Debug
 
-int MainWindow::checkDbVersion()
-{
-    QSqlQuery query("SELECT COUNT(*) FROM changelog");
-    query.next();
-    return query.value(0).toInt();
-}
-
 // not used at the moment
 
 /*void MainWindow::on_actionNewAircraft_triggered()

+ 0 - 2
mainwindow.h

@@ -100,8 +100,6 @@ private:
 
     void connectWidgets();
 
-    int checkDbVersion();
-
 protected:
     /*!
      * \brief Shows the debug widget by pressing <ctrl + t>

+ 8 - 15
src/database/adatabase.cpp

@@ -33,26 +33,23 @@ QString ADatabaseError::text() const
 
 ADatabase* ADatabase::self = nullptr;
 
-/*!
- * \brief Return the names of a given table in the database.
- */
+int ADatabase::dbVersion()
+{
+    QSqlQuery query("SELECT COUNT(*) FROM changelog");
+    query.next();
+    return query.value(0).toInt();
+}
+
 ColumnNames_T ADatabase::getTableColumns(TableName_T table_name) const
 {
     return tableColumns.value(table_name);
 }
 
-/*!
- * \brief Return the names of all tables in the database
- */
 TableNames_T ADatabase::getTableNames() const
 {
     return tableNames;
 }
 
-/*!
- * \brief Updates the member variables tableNames and tableColumns with up-to-date layout information
- * if the database has been altered. This function is normally only required during database setup or maintenance.
- */
 void ADatabase::updateLayout()
 {
     auto db = ADatabase::database();
@@ -73,7 +70,7 @@ void ADatabase::updateLayout()
 ADatabase* ADatabase::instance()
 {
 #ifdef __GNUC__
-    return self ?: self = new ADatabase();
+    return self ?: self = new ADatabase();  // Cheeky business...
 #else
     if(!self)
         self = new ADatabase();
@@ -86,10 +83,6 @@ ADatabase::ADatabase()
                              absoluteFilePath(QStringLiteral("logbook.db"))))
 {}
 
-/*!
- * \brief ADatabase::sqliteVersion returns database sqlite version.
- * \return sqlite version string
- */
 const QString ADatabase::sqliteVersion()
 {
     QSqlQuery query;

+ 18 - 0
src/database/adatabase.h

@@ -102,9 +102,27 @@ public:
     void operator=(const ADatabase&) = delete;
     static ADatabase* instance();
 
+    int dbVersion();
+    /*!
+     * \brief Return the names of all tables in the database
+     */
     TableNames_T getTableNames() const;
+
+    /*!
+     * \brief Return the names of a given table in the database.
+     */
     ColumnNames_T getTableColumns(TableName_T table_name) const;
+
+    /*!
+     * \brief Updates the member variables tableNames and tableColumns with up-to-date layout information
+     * if the database has been altered. This function is normally only required during database setup or maintenance.
+     */
     void updateLayout();
+
+    /*!
+     * \brief ADatabase::sqliteVersion returns database sqlite version.
+     * \return sqlite version string
+     */
     const QString sqliteVersion();
 
     ADatabaseError lastError;

+ 5 - 1
src/gui/widgets/backupwidget.cpp

@@ -79,7 +79,7 @@ void BackupWidget::fillTableWithSampleData()
 {
     // First column in table, would be created by listing the files in backupdir
     QDir backup_dir = QDir(AStandardPaths::directory(AStandardPaths::Backup));
-    QStringList entries = backup_dir.entryList(QStringList{"*.db"});
+    QStringList entries = backup_dir.entryList(QStringList{"*.db"}, QDir::Files, QDir::Time);
     QList<QStandardItem*> filenames;
     QFileIconProvider provider;
 
@@ -89,6 +89,10 @@ void BackupWidget::fillTableWithSampleData()
         filenames.append(item);
     }
 
+    // [G]: works but a bit too hardcoded perhaps? The aviation industry wont change overnight
+    // but still it could be worthwile to at least have the names a bit more encapsulated in the
+    // database so we have them more "centralised" at least.
+
     // Get summary of each db file and populate lists (columns) of data
     QList<QStandardItem *> total_flights, total_tails, total_pilots, max_doft, total_time;
     for (const auto &entry : entries) {