forked from GLDsuh-a/qt-1
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstalledappmodel.cpp
More file actions
101 lines (88 loc) · 2.49 KB
/
installedappmodel.cpp
File metadata and controls
101 lines (88 loc) · 2.49 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#include "installedappmodel.h"
#include <QDebug>
InstalledAppModel::InstalledAppModel(QObject *parent)
: QAbstractTableModel(parent)
, m_rowCount(20)
{
// m_name = QString::fromLocal8Bit("ÌìµØÅùö¨ÓÎÏÀ");
m_checked = false;
m_selectionModel = new QItemSelectionModel(this);
// connect(m_selectionModel, SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
// this, SLOT(handleSelectionChanged(QItemSelection, QItemSelection)));
for (int i = 0; i < 20; ++i)
{
beginInsertRows(QModelIndex(), 0, 0);
m_name << QString::number(i);
endInsertRows();
}
}
void InstalledAppModel::remove()
{
qDebug() << "installed app model remove" << endl;
beginRemoveRows(QModelIndex(), 0, 0);
m_name.pop_front();
endRemoveRows();
}
QVariant InstalledAppModel::data(const QModelIndex &index, int role) const
{
if (!index.isValid())
{
return QVariant();
}
switch (role)
{
case AppName:
return m_name[index.row()];
case AppIcon:
return QString("app.png");
case Qt::CheckStateRole:
return m_selectionModel->isSelected(index);
}
return QVariant();
}
bool InstalledAppModel::setData(const QModelIndex &index, const QVariant &value, int role)
{
if (!index.isValid())
{
return false;
}
switch (index.column())
{
case 0:
if (role == Qt::CheckStateRole)
{
m_checked = value.toBool();
}
break;
}
emit dataChanged(this->index(0, 0), this->index(rowCount(QModelIndex())-1, columnCount(QModelIndex())-1));
return true;
}
int InstalledAppModel::rowCount(const QModelIndex &parent) const
{
return m_name.count();
}
int InstalledAppModel::columnCount(const QModelIndex &parent) const
{
return 4;
}
void InstalledAppModel::changeName()
{
//m_name = "my name";
emit dataChanged(index(0, 1), index(3, 1));
}
void InstalledAppModel::changeChecked()
{
m_checked = !m_checked;
emit dataChanged(this->index(0, 0), this->index(3, 0));
}
void InstalledAppModel::setSelectionModel(QItemSelectionModel *model)
{
m_selectionModel = model;
connect(m_selectionModel, SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
this, SLOT(handleSelectionChanged(QItemSelection, QItemSelection)));
}
void InstalledAppModel::handleSelectionChanged(QItemSelection select, QItemSelection deselect)
{
emit dataChanged(this->index(0, 0), this->index(rowCount(QModelIndex())-1, columnCount(QModelIndex())-1));
}