-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUI.h
152 lines (130 loc) · 2.86 KB
/
UI.h
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#pragma once
#include "Service.h"
#include <qwidget.h>
#include <qtablewidget.h>
#include <QAbstractTableModel>
#include <qpushbutton.h>
#include <qpainter.h>
class MyTableModel : public QAbstractTableModel {
vector<melodie> v;
public:
MyTableModel(vector<melodie> m) : v(m) {
}
int rowCount(const QModelIndex& parent = QModelIndex()) const override {
return v.size();
}
int columnCount(const QModelIndex& parent = QModelIndex()) const override {
return 5;
}
QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override {
if (role == Qt::DisplayRole) {
melodie p = v[index.row()];
if (index.column() == 0) {
return QString::number(p.id);
}
else if (index.column() == 1) {
return QString::fromStdString(p.titlu);
}
else if (index.column() == 2) {
return QString::fromStdString(p.artist);
}
else if (index.column() == 3) {
return QString::number(p.rank);
}
else {
int nr = 0;
for (auto& x : v)
if (x.rank == v[index.row()].rank && x.id != v[index.row()].id)
nr++;
return QString::number(nr);
}
}
return QVariant{};
}
/*bool setData(const QModelIndex& index, const QVariant& value,int role)
{
if (role == Qt::EditRole)
{
int row = index.row();
int column = index.column();
}
return true;
}
Qt::ItemFlags flags(const QModelIndex& index) const override {
return Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled;
}*/
void setMelodii(vector<melodie> m)
{
this->v = m;
QModelIndex bottomRight1 = createIndex(0, 0);
QModelIndex topLeft1 = createIndex(rowCount(), columnCount());
emit dataChanged(bottomRight1, topLeft1);
emit layoutChanged();
}
};
//class Widget_Jos : public QWidget {
//
// service& srv;
//
//public:
//
// Widget_Jos(service& srv1) : srv(srv1){}
//
// void update()
// {
// this->repaint();
// }
//
// void paintEvent(QPaintEvent* ev) override
// {
// QPainter p(this);
// int v[11];
//
// for (auto& x : srv.get_list())
// v[x.rank]++;
//
// int s = -20;
// for (int i = 0; i <= 10; i++)
// {
// s += 40;
// p.fillRect(s, 0, 20, 60, Qt::red);
// }
// }
//};
class GUI : public QWidget {
service& srv;
QTableView* tblV = new QTableView;
MyTableModel* model;
QSlider* slider;
QPushButton* UPDATE = new QPushButton("UPDATE");
QLineEdit* nume;
QPushButton* DELETE = new QPushButton("DELETE");
//Widget_Jos* jos = new Widget_Jos(srv);
public:
GUI(service& srv1) : srv(srv1)
{
model = new MyTableModel(srv.get_list());
tblV->setModel(model);
build_UI();
connect_signals();
}
void build_UI();
void connect_signals();
void update()
{
this->repaint();
}
void paintEvent(QPaintEvent* ev) override
{
QPainter p(this);
int v[11] = {0};
for (auto& x : srv.get_list())
v[x.rank]++;
int s = -20;
for (int i = 0; i <= 10; i++)
{
s += 40;
p.fillRect(s, 350, 20, v[i] * 50, Qt::red);
}
}
};