-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathqtablemodel.cpp
More file actions
85 lines (82 loc) · 2.35 KB
/
qtablemodel.cpp
File metadata and controls
85 lines (82 loc) · 2.35 KB
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
#include "qtablemodel.h"
#include <QVariant>
QTableModel::QTableModel(int cCount,int rCount, QList<QString> hNames, QList<QString> hhNames)
{
_columnCount = cCount;
_rowCount = rCount;
_headerNames = hNames;
_horizontalHeaderNames = hhNames;
//QList<QString> v;
//values.push_back(v);
}
int QTableModel::rowCount(const QModelIndex &parent) const
{
return _rowCount;
}
int QTableModel::columnCount(const QModelIndex &parent) const
{
return _columnCount;
}
bool QTableModel::removeRows()
{
beginRemoveRows(QModelIndex(),0,_rowCount-1);
endRemoveRows();
return true;
}
bool QTableModel::removeColumns()
{
beginRemoveColumns(QModelIndex(),0,_columnCount-1);
endRemoveColumns();
return true;
}
bool QTableModel::setDat(const QList<QString> &value)
{
//values.clear();
values.push_back(value);
QModelIndex startIndex=createIndex(0, 0);
QModelIndex stopIndex=createIndex(_columnCount, _rowCount);
emit dataChanged(startIndex, stopIndex);
}
bool QTableModel::setData(const QModelIndex &index, const QVariant &value, int role)
{
if(role==Qt::EditRole)
{
values[index.row()][index.column()]= value.toString();
}
}
Qt::ItemFlags QTableModel::flags(const QModelIndex &index) const
{
if(!index.isValid())
{
return Qt::NoItemFlags;
}
return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable;
}
QVariant QTableModel::data(const QModelIndex &index, int role) const
{
if (role == Qt::DisplayRole) {
if(index.column()<=_columnCount)
{
QString answer = values[index.row()].at(index.column());
// QString answer = "test";
return QVariant(answer);
}
}
return QVariant();
}
bool QTableModel::setHeaderData ( int section, Qt::Orientation orientation, const QVariant & value, int role ) const
{
}
QVariant QTableModel::headerData( int section, Qt::Orientation orientation, int role) const
{
if (role == Qt::DisplayRole && orientation == Qt::Horizontal) {
QString answer = _headerNames.at(section);
return QVariant(answer);
}
if (role == Qt::DisplayRole && orientation == Qt::Vertical) {
QString answer =_horizontalHeaderNames.at(section);
answer = answer.remove(0,answer.lastIndexOf('/')+1);
return QVariant(answer);
}
return QVariant();
}