Przeglądaj źródła

added Db::disconnect()

fiffty-50 4 lat temu
rodzic
commit
8a24e6b01f
3 zmienionych plików z 15 dodań i 4 usunięć
  1. 8 0
      src/database/db.cpp
  2. 6 0
      src/database/db.h
  3. 1 4
      src/gui/widgets/debugwidget.cpp

+ 8 - 0
src/database/db.cpp

@@ -45,6 +45,14 @@ void Db::iconnect()
     }
 }
 
+void Db::idisconnect()
+{
+    auto db = Db::Database();
+    db.close();
+    db.removeDatabase(db.connectionName());
+    DEB("Database connection closed.");
+}
+
 QSqlDatabase Db::iDatabase()
 {
     auto db = QSqlDatabase::database("qt_sql_default_connection");

+ 6 - 0
src/database/db.h

@@ -62,6 +62,11 @@ class Db
          * instantiated with QSqlDatabase::database("qt_sql_default_connection") as required.
          */
         static void             connect(){get().iconnect();}
+        /*!
+         * \brief disconnect Closes and removes the default database connection.
+         */
+        static void             disconnect(){get().idisconnect();}
+
         /*!
          * \brief Can be used to access the database connection.
          * \return a pointer to the default database connection
@@ -140,6 +145,7 @@ class Db
     private:
         Db() {}
         void             iconnect();
+        void             idisconnect();
         QSqlDatabase     iDatabase();
         bool             iexists(QString column, QString table, QString checkColumn,
                                        QString value, Db::matchType match);

+ 1 - 4
src/gui/widgets/debugwidget.cpp

@@ -57,10 +57,7 @@ void DebugWidget::on_resetDatabasePushButton_clicked()
         dl->deleteLater();
     }
     //close database connection
-    auto db = Db::Database();
-    db.close();
-    db.removeDatabase(db.connectionName());
-    DEB("Closing database connection.");
+    Db::disconnect();
 
     // back up old database
     auto oldDatabase = QFile("data/logbook.db");