forked from zhengtianzuo/QtQuickExamples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQmlTableView.cpp
More file actions
73 lines (64 loc) · 1.57 KB
/
QmlTableView.cpp
File metadata and controls
73 lines (64 loc) · 1.57 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
/*!
*@file QmlTableView.h
*@brief QmlTableView
*@version 1.0
*@section LICENSE Copyright (C) 2003-2103 CamelSoft Corporation
*@author zhengtianzuo
*/
#include "QmlTableView.h"
#include <QDebug>
QmlTableViewModel::QmlTableViewModel() : QAbstractTableModel(0)
{
}
int QmlTableViewModel::rowCount(const QModelIndex &parent) const
{
Q_UNUSED(parent)
return m_aryData.size();
}
int QmlTableViewModel::columnCount(const QModelIndex &parent) const
{
Q_UNUSED(parent)
return 3;
}
QVariant QmlTableViewModel::data(const QModelIndex &index, int role) const
{
return m_aryData[index.row()][role];
}
QHash<int, QByteArray> QmlTableViewModel::roleNames() const
{
QHash<int, QByteArray> roles;
roles[OneRole] = "1";
roles[TwoRole] = "2";
roles[ThreeRole] = "3";
return roles;
}
void QmlTableViewModel::Add(QString one, QString two, QString three)
{
beginInsertRows(QModelIndex(), m_aryData.size(), m_aryData.size());
QVector<QString> list;
list.push_back(one);
list.push_back(two);
list.push_back(three);
m_aryData.push_back(list);
endInsertRows();
}
void QmlTableViewModel::Set(int row, int column, QString text)
{
if (row == -1){return;}
if (column == -1){return;}
beginResetModel();
m_aryData[row][column] = text;
endResetModel();
}
void QmlTableViewModel::Del()
{
if (m_aryData.size() <= 0) return;
beginRemoveRows(QModelIndex(), m_aryData.size() - 1, m_aryData.size() - 1);
m_aryData.removeLast();
endRemoveRows();
}
void QmlTableViewModel::Refresh()
{
beginResetModel();
endResetModel();
}