86
86
connect(model, SIGNAL(dataChanged(QModelIndex,QModelIndex)),
87
87
this, SLOT(sourceDataChanged(QModelIndex,QModelIndex)));
89
connect(model, SIGNAL(rowsAboutToBeInserted(QModelIndex, int,int)),
89
connect(model, SIGNAL(rowsAboutToBeInserted(QModelIndex,int,int)),
90
90
this, SLOT(sourceRowsAboutToBeInserted(QModelIndex,int,int)) );
91
connect(model, SIGNAL(rowsInserted(QModelIndex, int,int)),
91
connect(model, SIGNAL(rowsInserted(QModelIndex,int,int)),
92
92
this, SLOT(sourceRowsInserted(QModelIndex,int,int)) );
93
connect(model, SIGNAL(rowsAboutToBeRemoved(QModelIndex, int,int)),
93
connect(model, SIGNAL(rowsAboutToBeRemoved(QModelIndex,int,int)),
94
94
this, SLOT(sourceRowsAboutToBeRemoved(QModelIndex,int,int)) );
95
connect(model, SIGNAL(rowsRemoved(QModelIndex, int,int)),
95
connect(model, SIGNAL(rowsRemoved(QModelIndex,int,int)),
96
96
this, SLOT(sourceRowsRemoved(QModelIndex,int,int)) );
98
connect(model, SIGNAL(rowsMoved(QModelIndex,int,int,QModelIndex,int)),
99
this, SLOT(sourceRowsMoved(QModelIndex,int,int,QModelIndex,int)));
98
101
connect(model, SIGNAL(modelAboutToBeReset()),
99
102
this, SIGNAL(modelAboutToBeReset()));
100
103
connect(model, SIGNAL(modelReset()),
114
117
emit dataChanged(mapFromSource(from), mapFromSource(to));
120
void PagedProxyModel::sourceRowsMoved(const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destinationParent, int destinationRow)
122
const int pageStart = (m_currentPage*m_pageSize);
123
int newStart = qMin(m_pageSize, qMax(0, sourceStart - pageStart));
124
int newEnd = qMin(m_pageSize, newStart + (sourceEnd - sourceStart));
125
int newDestinationRow = qMin(m_pageSize, qMax(0, destinationRow - pageStart));
127
emit beginMoveRows(sourceParent, newStart, newEnd, destinationParent, newDestinationRow);
117
131
void PagedProxyModel::sourceRowsAboutToBeInserted( const QModelIndex & parentIdx, int start, int end )
119
beginInsertRows(parentIdx, start, end );
133
const int pageStart = (m_currentPage*m_pageSize);
134
const int pageEnd = (m_currentPage*m_pageSize + m_pageSize);
136
//insert in pages bigger than us, not interested
137
if (start > pageEnd) {
141
//FIXME: proper indexes should be calculated
145
int newStart = qMin(m_pageSize, qMax(0, start - pageStart));
146
int newEnd = qMin(m_pageSize, newStart + (end - start));
148
m_oldRowCount = rowCount();
149
//insert only the ones that are beyond the count
150
if (newEnd > m_oldRowCount) {
151
beginInsertRows(parentIdx, rowCount() - newEnd, newEnd );
123
156
void PagedProxyModel::sourceRowsInserted( const QModelIndex& parentIdx, int start, int end )
125
158
Q_UNUSED( parentIdx );
160
const int pageStart = (m_currentPage*m_pageSize);
161
const int pageEnd = (m_currentPage*m_pageSize + m_pageSize);
163
if (start > pageEnd) {
167
//FIXME: proper mapped indexes should be calculated
171
if (rowCount() > m_oldRowCount) {
174
int newStart = qMin(m_pageSize, qMax(0, start - pageStart));
175
int newEnd = qMin(m_pageSize, newStart + (end - start));
177
if (newStart <= m_oldRowCount) {
178
emit dataChanged(PagedProxyModel::index(newStart, 0),
179
PagedProxyModel::index(qMin(newEnd, m_oldRowCount), 0));
132
184
void PagedProxyModel::sourceRowsAboutToBeRemoved( const QModelIndex & parentIdx, int start, int end )
134
beginRemoveRows(parentIdx, start, end );
186
const int pageStart = (m_currentPage*m_pageSize);
187
const int pageEnd = (m_currentPage*m_pageSize + m_pageSize);
189
if (start > pageEnd) {
193
//FIXME: proper mapped indexes should be calculated
197
int newStart = qMin(m_pageSize, qMax(0, start - pageStart));
198
int newEnd = qMin(m_pageSize, qMax(0, end - pageStart));
200
m_oldRowCount = rowCount();
201
//insert only the ones that are beyond the count
202
if (newEnd < m_oldRowCount) {
203
beginRemoveRows(parentIdx, newStart, newEnd );
138
208
void PagedProxyModel::sourceRowsRemoved( const QModelIndex& parentIdx, int start, int end )
140
210
Q_UNUSED( parentIdx );
212
const int pageStart = (m_currentPage*m_pageSize);
213
const int pageEnd = (m_currentPage*m_pageSize + m_pageSize);
215
if (start > pageEnd) {
219
//FIXME: proper mapped indexes should be calculated
223
if (rowCount() < m_oldRowCount) {
226
int newStart = qMin(m_pageSize, qMax(0, start - pageStart));
227
int newEnd = qMin(m_pageSize, newStart + (end - start));
229
if (sourceModel()->rowCount() - pageStart > rowCount()) {
230
emit dataChanged(PagedProxyModel::index(newStart, 0),
231
PagedProxyModel::index(qMin((sourceModel()->rowCount() - pageStart), qMin(newEnd, m_oldRowCount)), 0));
146
235
int PagedProxyModel::rowCount(const QModelIndex &parent) const