-
Notifications
You must be signed in to change notification settings - Fork 0
/
databaseviewer.cpp
57 lines (47 loc) · 1.55 KB
/
databaseviewer.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include "databaseviewer.h"
#include "ui_databaseviewer.h"
#include "qsqltablemodel.h"
#include "qmessagebox.h"
DatabaseViewer::DatabaseViewer(QWidget *parent) :
QDialog(parent),
ui(new Ui::DatabaseViewer)
{
ui->setupUi(this);
ui->cboxDatabase->addItem("Archived routes (rdb)");
ui->cboxDatabase->addItem("Loaded routes (adb)");
ui->cboxDatabase->addItem("Archived maps (mdb)");
connect(ui->btnQuery, SIGNAL(clicked()), this, SLOT(executeQuery()));
}
void DatabaseViewer::executeQuery()
{
QString db, table;
if (ui->cboxDatabase->currentIndex()==0) db = "rdb";
else { if (ui->cboxDatabase->currentIndex()==1) db = "adb";
else db = "mdb";
}
table = ui->edtQuery->text();
{
QSqlTableModel *model = new QSqlTableModel(this,QSqlDatabase::database(db)); //deletes the table after closing the dialog -> prevents the following error: QSqlDatabasePrivate::removeDatabase: connection 'rdb' is still in use, all queries will cease to work.
// model = new QSqlTableModel::QSqlTableModel(0,QSqlDatabase::database(db));
//model->setEditStrategy(QSqlTableModel::OnManualSubmit);
model->setEditStrategy(QSqlTableModel::OnFieldChange);
model->setTable(table);
ui->tblvResult->setModel(model);
model->select();
}
}
DatabaseViewer::~DatabaseViewer()
{
delete ui;
}
void DatabaseViewer::changeEvent(QEvent *e)
{
QDialog::changeEvent(e);
switch (e->type()) {
case QEvent::LanguageChange:
ui->retranslateUi(this);
break;
default:
break;
}
}