Browse Source

Read probes from database

pull/1/head
miladS 1 year ago
parent
commit
55650dccbb
  1. 16
      logic/include/model/DatabaseManager.h
  2. 10
      logic/logic.pro
  3. 45
      logic/src/model/DatabaseManager.cpp
  4. 2
      test/test.pro
  5. 2
      ui/ui.pro

16
logic/include/model/DatabaseManager.h

@ -1,13 +1,19 @@
#ifndef DatabaseManager_H
#define DatabaseManager_H
#ifndef DATABASEMANAGER_H
#define DATABASEMANAGER_H
#include <QSqlDatabase>
#include <QDebug>
class DatabaseManager
{
private:
char _functionCode;
QSqlDatabase _db;
public:
DatabaseManager(char functionCode);
DatabaseManager(const QString& databasePath);
~DatabaseManager();
QList<QVariant> getProbeIds();
};
#endif //DatabaseManager_H
#endif //DATABASEMANAGER_H

10
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/

45
logic/src/model/DatabaseManager.cpp

@ -1,6 +1,47 @@
#include "model/DatabaseManager.h"
DatabaseManager::DatabaseManager(char functionCode)
#include <QDebug>
#include <QSqlQuery>
#include <QSqlError>
DatabaseManager::DatabaseManager(const QString& databasePath)
{
_db = QSqlDatabase::addDatabase("QSQLITE");
_db.setDatabaseName(databasePath);
if(!_db.open())
{
qDebug() << "Error: " << _db.lastError().text();
}
}
/*************************************************************************************************/
DatabaseManager::~DatabaseManager()
{
if(_db.isOpen())
{
_db.close();
}
}
/*************************************************************************************************/
QList<QVariant> DatabaseManager::getProbeIds()
{
QList<QVariant> globalIds;
QSqlQuery query;
if(query.exec("SELECT globalId FROM Probe"))
{
while(query.next())
{
_functionCode = functionCode;
QString globalId = query.value(0).toString();
globalIds.append(QVariant(globalId));
}
}
else
{
qDebug() << "Error executing query: " << query.lastError().text();
}
return globalIds;
}

2
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

2
ui/ui.pro

@ -1,6 +1,6 @@
TEMPLATE = app
QT += quick mvvmquick
QT += quick mvvmquick network sql
CONFIG += c++14
TARGET = ConsoleEmulator

Loading…
Cancel
Save