-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathtablemodel.cpp
91 lines (76 loc) · 2.21 KB
/
tablemodel.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
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
/* OpenBRF -- by marco tarini. Provided under GNU General Public License */
#include "tablemodel.h"
#include <QColor>
#include <QApplication>
#include <QPalette>
#include <QFont>
MyTableModel::MyTableModel(QObject *parent)
: QAbstractListModel(parent)
{
}
void MyTableModel::updateChanges(){
int t=vec.size();
emit(this->dataChanged(createIndex(0,0),createIndex(1,t+100)));
emit(layoutChanged());
}
void MyTableModel::clear()
{
int t=vec.size();
vec.clear();
vecUsed.clear();
this->dataChanged(createIndex(0,0),createIndex(1,t));
}
int MyTableModel::rowCount(const QModelIndex &parent) const
{
Q_UNUSED(parent);
return vec.size();
}
int MyTableModel::columnCount(const QModelIndex &parent) const
{
Q_UNUSED(parent);
return 1;
}
Qt::DropActions MyTableModel::supportedDropActions() const{
return Qt::CopyAction | Qt::MoveAction;
}
QVariant MyTableModel::data(const QModelIndex &index, int role) const
{
static QFont alternate;
static bool firstTime=true;
if (firstTime) {
alternate= QApplication::font();
//alternate.setItalic(!alternate.italic());
alternate.setBold(true);
firstTime = false;
}
int i = index.row();
if (i>=(int)vecUsed.size()) i = vecUsed.size()-1;
if (i<0) {
return QVariant();
}
if (role==Qt::DisplayRole)
return vec[ i ];
if (role==Qt::FontRole){
return (vecUsed[ i ]!=1)?QApplication::font():alternate;
}
if (role==Qt::BackgroundColorRole) return QColor(255,255,255,255);
// //return (index.row()%2==0)?QColor(128,128,128,255):QColor(0,0,0,255);
// return (vecUsed[ index.row() ]!=0)?
// QApplication::palette().color (QPalette::Base):
// QApplication::palette().color (QPalette::AlternateBase);
if (role==Qt::TextColorRole) {
switch(vecUsed[ i ]){
case 1: return QColor(0,0,150,255);
case 0: return QColor(0,0,0,255);//QApplication::palette().color(QPalette::Text);
case -1:return QColor(40,50,40,255);
case -2:return QColor(140,150,140,255);
//return QApplication::palette().color(QPalette::Text);
}
}
return QVariant();
}
QVariant MyTableModel::headerData(int /*section*/, Qt::Orientation /*orientation*/, int /*role*/) const
{
return tr("HEADER");
// return QVariant();
}