From 55650dccbb8b9d97228514a7364409e8d5cdde34 Mon Sep 17 00:00:00 2001 From: miladS Date: Mon, 29 Jan 2024 16:42:20 +0330 Subject: [PATCH] Read probes from database --- logic/include/model/DatabaseManager.h | 16 +++++++--- logic/logic.pro | 10 +++--- logic/src/model/DatabaseManager.cpp | 45 +++++++++++++++++++++++++-- test/test.pro | 2 +- ui/ui.pro | 2 +- 5 files changed, 62 insertions(+), 13 deletions(-) diff --git a/logic/include/model/DatabaseManager.h b/logic/include/model/DatabaseManager.h index f321a33..06db604 100644 --- a/logic/include/model/DatabaseManager.h +++ b/logic/include/model/DatabaseManager.h @@ -1,13 +1,19 @@ -#ifndef DatabaseManager_H -#define DatabaseManager_H +#ifndef DATABASEMANAGER_H +#define DATABASEMANAGER_H + +#include +#include class DatabaseManager { private: - char _functionCode; + QSqlDatabase _db; public: - DatabaseManager(char functionCode); + DatabaseManager(const QString& databasePath); + ~DatabaseManager(); + + QList getProbeIds(); }; -#endif //DatabaseManager_H +#endif //DATABASEMANAGER_H diff --git a/logic/logic.pro b/logic/logic.pro index eef9d5b..e7c8368 100644 --- a/logic/logic.pro +++ b/logic/logic.pro @@ -1,6 +1,7 @@ TEMPLATE = lib -QT += mvvmcore network +QT += mvvmcore network sql + # Creating a static library is typically more efficient. You can still create a shared library if you want to CONFIG += c++14 static @@ -9,10 +10,11 @@ TARGET = logic DEFINES += QT_DEPRECATED_WARNINGS SOURCES += $$files(src/*.cpp, true) \ - src/model/DropDown.cpp -HEADERS += $$files(include/*.h, true) \ - include/model/DropDown.h + +HEADERS += $$files(include/*.h, true) \ \ + include/model/FakeHardwareProbesInfo.h + INCLUDEPATH += $$PWD/include/ diff --git a/logic/src/model/DatabaseManager.cpp b/logic/src/model/DatabaseManager.cpp index b3ab640..7202706 100644 --- a/logic/src/model/DatabaseManager.cpp +++ b/logic/src/model/DatabaseManager.cpp @@ -1,6 +1,47 @@ #include "model/DatabaseManager.h" -DatabaseManager::DatabaseManager(char functionCode) +#include +#include +#include + +DatabaseManager::DatabaseManager(const QString& databasePath) +{ + _db = QSqlDatabase::addDatabase("QSQLITE"); + _db.setDatabaseName(databasePath); + + if(!_db.open()) + { + qDebug() << "Error: " << _db.lastError().text(); + } +} + +/*************************************************************************************************/ +DatabaseManager::~DatabaseManager() { - _functionCode = functionCode; + if(_db.isOpen()) + { + _db.close(); + } +} + +/*************************************************************************************************/ +QList DatabaseManager::getProbeIds() +{ + QList globalIds; + + QSqlQuery query; + if(query.exec("SELECT globalId FROM Probe")) + { + while(query.next()) + { + QString globalId = query.value(0).toString(); + globalIds.append(QVariant(globalId)); + } + } + else + { + qDebug() << "Error executing query: " << query.lastError().text(); + } + + return globalIds; } diff --git a/test/test.pro b/test/test.pro index 0ab78d9..96364c5 100644 --- a/test/test.pro +++ b/test/test.pro @@ -1,5 +1,5 @@ QT += testlib -QT -= gui +QT -= gui mvvmcore network sql CONFIG += qt console warn_on depend_includepath testcase CONFIG -= app_bundle diff --git a/ui/ui.pro b/ui/ui.pro index 454f661..28feafa 100644 --- a/ui/ui.pro +++ b/ui/ui.pro @@ -1,6 +1,6 @@ TEMPLATE = app -QT += quick mvvmquick +QT += quick mvvmquick network sql CONFIG += c++14 TARGET = ConsoleEmulator