-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTDBClopesList.cpp
49 lines (39 loc) · 983 Bytes
/
TDBClopesList.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
#include "TDBClopesList.h"
TDBClopesList::TDBClopesList (QWidget* parent) : QTreeWidget(parent)
{
setColumnCount(2);
QStringList header_strings;
header_strings << "Marque" << "Prix";
setHeaderLabels(header_strings);
setSelectionMode(QAbstractItemView::SingleSelection);
}
TDBClopesList::~TDBClopesList ()
{
;
}
void TDBClopesList::fill ()
{
TDBDatabase::open();
QSqlQuery query;
query.prepare("SELECT marque, prix FROM clopes ORDER BY marque");
query.exec();
if(query.first())
{
insert_item(query);
}
while(query.next())
{
insert_item(query);
}
TDBDatabase::close();
}
void TDBClopesList::insert_item(QSqlQuery& query)
{
QStringList item;
QSqlRecord record;
record = query.record();
item.clear();
item<<record.value("marque").toString()
<<QString::number(record.value("prix").toInt()/100.0, 'f', 2);
insertTopLevelItem(0,new QTreeWidgetItem(this, item));
}