forked from Sepanta/console-emulator
19 changed files with 398 additions and 184 deletions
@ -1,13 +1,20 @@ |
|||||
#ifndef DatabaseManager_H |
#ifndef DATABASEMANAGER_H |
||||
#define DatabaseManager_H |
#define DATABASEMANAGER_H |
||||
|
|
||||
|
#include <QSqlDatabase> |
||||
|
#include <QDebug> |
||||
|
|
||||
class DatabaseManager |
class DatabaseManager |
||||
{ |
{ |
||||
private: |
private: |
||||
char _functionCode; |
QSqlDatabase _db; |
||||
|
|
||||
public: |
public: |
||||
DatabaseManager(char functionCode); |
DatabaseManager(const QString& databasePath); |
||||
|
~DatabaseManager(); |
||||
|
|
||||
|
QList<QVariant> getProbeIds(); |
||||
|
QList<QVariant> getProbeNames(); |
||||
}; |
}; |
||||
|
|
||||
#endif //DatabaseManager_H
|
#endif //DATABASEMANAGER_H
|
||||
|
@ -1,6 +1,69 @@ |
|||||
#include "model/DatabaseManager.h" |
#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() |
||||
{ |
{ |
||||
_functionCode = functionCode; |
QList<QVariant> 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; |
||||
|
} |
||||
|
|
||||
|
/*************************************************************************************************/ |
||||
|
QList<QVariant> DatabaseManager::getProbeNames() |
||||
|
{ |
||||
|
QList<QVariant> names; |
||||
|
|
||||
|
QSqlQuery query; |
||||
|
if(query.exec("SELECT name FROM Probe")) |
||||
|
{ |
||||
|
while(query.next()) |
||||
|
{ |
||||
|
QString name = query.value(0).toString(); |
||||
|
names.append(QVariant(name)); |
||||
|
} |
||||
|
} |
||||
|
else |
||||
|
{ |
||||
|
qDebug() << "Error executing query: " << query.lastError().text(); |
||||
|
} |
||||
|
|
||||
|
return names; |
||||
} |
} |
||||
|
@ -0,0 +1,46 @@ |
|||||
|
import QtQuick 2.0 |
||||
|
import QtQuick.Layouts 1.13 |
||||
|
import QtQuick.Controls 2.12 |
||||
|
import de.skycoder42.QtMvvm.Core 1.0 |
||||
|
import de.skycoder42.QtMvvm.Quick 1.0 |
||||
|
import com.example.consoleemulator 1.0 |
||||
|
|
||||
|
import "qrc:/emulator/elements" |
||||
|
import "qrc:/emulator/components" |
||||
|
import "qrc:/const" |
||||
|
import "qrc:/qtmvvm/views" |
||||
|
|
||||
|
Item { |
||||
|
id: root |
||||
|
implicitWidth: width |
||||
|
implicitHeight: 25 |
||||
|
property var isDisable: false |
||||
|
property var viewModelProperty |
||||
|
property var isProbeEnableProperty |
||||
|
property alias model: idComobBox.model |
||||
|
ComboBox { |
||||
|
id: idComobBox |
||||
|
visible: isDisable |
||||
|
model: probeList |
||||
|
width: parent.width |
||||
|
implicitWidth: width |
||||
|
implicitHeight: parent.height |
||||
|
MvvmBinding { |
||||
|
viewModel: mainView.viewModel |
||||
|
viewProperty: "currentIndex" |
||||
|
viewModelProperty: root.viewModelProperty |
||||
|
} |
||||
|
} |
||||
|
Text { |
||||
|
visible: !isDisable |
||||
|
text: idComobBox.currentText |
||||
|
anchors.fill: parent |
||||
|
horizontalAlignment: Text.AlignHCenter |
||||
|
} |
||||
|
|
||||
|
MvvmBinding { |
||||
|
viewModel: mainView.viewModel |
||||
|
viewProperty: "isDisable" |
||||
|
viewModelProperty: isProbeEnableProperty |
||||
|
} |
||||
|
} |
Loading…
Reference in new issue