-
Notifications
You must be signed in to change notification settings - Fork 0
/
logview.cpp
37 lines (29 loc) · 1.09 KB
/
logview.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
#include "logview.h"
logView::logView(QObject *parent) :
QObject(parent)
{
model = new QSqlTableModel;
initializeModel(model);
QTableView *view1 = createView(model, QObject::tr("Logs view"));
view1->show();
}
QTableView *logView::createView(QSqlQueryModel *model, const QString &title = ""){
QTableView *view = new QTableView;
view->setEditTriggers(QAbstractItemView::NoEditTriggers);
view->setModel(model);
view->setWordWrap(TRUE);
view->setWindowTitle(title);
view->setAutoScroll(true);
view->setWordWrap(true);
view->resize(453, 445);
QHeaderView * header = view->horizontalHeader();
header->stretchLastSection();
return view;
}
void logView::initializeModel(QSqlQueryModel *model){
model->setQuery("SELECT code, name, success, date FROM logs ORDER BY id desc LIMIT 150");
model->setHeaderData(0, Qt::Horizontal, QObject::tr("Code"));
model->setHeaderData(1, Qt::Horizontal, QObject::tr("Name"));
model->setHeaderData(2, Qt::Horizontal, QObject::tr("Succes?"));
model->setHeaderData(3, Qt::Horizontal, QObject::tr("Date"));
}