-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathstockmodel.cpp
executable file
·52 lines (47 loc) · 1.33 KB
/
stockmodel.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
#include "stockmodel.h"
#include <QModelIndex>
#include <QColor>
#include <QBrush>
#include <QFont>
StockModel::StockModel(QObject *parent, int quantitycolumn,
qint64 lowerlimit) :
QSqlQueryModel(parent),
_col(quantitycolumn),
_lowerlimit(lowerlimit)
{
}
qint64 StockModel::lowerlimit() const
{
return _lowerlimit;
}
void StockModel::setLowerlimit(const qint64 &lowerlimit)
{
_lowerlimit = lowerlimit;
}
QVariant StockModel::data(const QModelIndex &index, int role) const
{
if(index.isValid() && index.column()==_col &&
role==Qt::ForegroundRole){
if(index.data().toLongLong() < _lowerlimit){
QColor text;
text.setNamedColor("#ea4335");//google red
return QBrush(text);
}else{
QColor text;
text.setNamedColor("#34a853");//google greeen
return QBrush(text);
}
}
//font
if(index.isValid() && role==Qt::FontRole){
return QFont("times",12,QFont::DemiBold);
}
//other colors of text
if(index.isValid() && index.column()!=_col &&
role==Qt::ForegroundRole){
QColor text;
text.setNamedColor("#4285f4");//google blue
return QBrush(text);
}
return QSqlQueryModel::data(index,role);
}