18
18
#include <debug_p.h>
20
20
QSortFilterProxyModelQML::QSortFilterProxyModelQML(QObject *parent) :
21
QSortFilterProxyModel(parent)
21
QSortFilterProxyModel(parent), m_limit(-1)
23
connect(this, SIGNAL(modelReset()), SIGNAL(countChanged()));
24
connect(this, SIGNAL(rowsInserted(QModelIndex,int,int)), SIGNAL(countChanged()));
25
connect(this, SIGNAL(rowsRemoved(QModelIndex,int,int)), SIGNAL(countChanged()));
25
28
void QSortFilterProxyModelQML::setRoleNames(const QHash<int,QByteArray> &roleNames)
64
67
setRoleNames(itemModel->roleNames());
66
69
setSourceModel(itemModel);
71
connect(itemModel, SIGNAL(modelReset()), SIGNAL(totalCountChanged()));
72
connect(itemModel, SIGNAL(rowsInserted(QModelIndex,int,int)), SIGNAL(totalCountChanged()));
73
connect(itemModel, SIGNAL(rowsRemoved(QModelIndex,int,int)), SIGNAL(totalCountChanged()));
74
Q_EMIT totalCountChanged();
75
Q_EMIT countChanged();
97
QSortFilterProxyModelQML::totalCount() const
99
if (sourceModel() != NULL) {
100
return sourceModel()->rowCount();
88
107
QSortFilterProxyModelQML::count()
90
109
return rowCount();
113
QSortFilterProxyModelQML::rowCount(const QModelIndex &parent) const
115
int count = QSortFilterProxyModel::rowCount(parent);
117
return qMin(count, m_limit);
124
QSortFilterProxyModelQML::limit() const
130
QSortFilterProxyModelQML::setLimit(int limit)
132
if (limit != m_limit) {
133
int count = QSortFilterProxyModel::rowCount();
136
bool inserted = false;
137
bool removed = false;
141
start = qMin(count, limit);
145
} else if (limit == -1) {
146
if (m_limit < count) {
147
start = qMin(count, m_limit);
151
} else if (m_limit >= count && limit >= count) {
153
} else if (m_limit >= count && limit < count) {
154
start = qMin(count, limit);
157
} else if (m_limit < count && limit >= count) {
158
start = qMin(count, m_limit);
161
} else if (m_limit < count && limit < count) {
162
if (m_limit < limit) {
163
start = qMin(count, m_limit);
164
end = qMin(count, limit)-1;
167
start = qMin(count, limit);
168
end = qMin(count, m_limit)-1;
174
beginInsertRows(QModelIndex(), start, end);
177
beginRemoveRows(QModelIndex(), start, end);
188
Q_EMIT limitChanged();