~ubuntu-branches/ubuntu/raring/plasma-mobile/raring-proposed

« back to all changes in this revision

Viewing changes to components/mobilecomponents/pagedproxymodel.cpp

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2012-07-17 12:04:43 UTC
  • mfrom: (1.1.6)
  • Revision ID: package-import@ubuntu.com-20120717120443-q3ig9u2fnltx67yg
Tags: 2.0+git2012071701-0ubuntu1
* New upstream snapshot
* Remove build-dep on kde-runtime-dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
86
86
    connect(model, SIGNAL(dataChanged(QModelIndex,QModelIndex)),
87
87
            this, SLOT(sourceDataChanged(QModelIndex,QModelIndex)));
88
88
 
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)) );
97
97
 
 
98
    connect(model, SIGNAL(rowsMoved(QModelIndex,int,int,QModelIndex,int)),
 
99
            this, SLOT(sourceRowsMoved(QModelIndex,int,int,QModelIndex,int)));
 
100
 
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));
115
118
}
116
119
 
 
120
void PagedProxyModel::sourceRowsMoved(const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destinationParent, int destinationRow)
 
121
{
 
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));
 
126
 
 
127
    emit beginMoveRows(sourceParent, newStart, newEnd, destinationParent, newDestinationRow);
 
128
    endMoveRows();
 
129
}
 
130
 
117
131
void PagedProxyModel::sourceRowsAboutToBeInserted( const QModelIndex & parentIdx, int start, int end )
118
132
{
119
 
    beginInsertRows(parentIdx, start, end );
 
133
    const int pageStart = (m_currentPage*m_pageSize);
 
134
    const int pageEnd = (m_currentPage*m_pageSize + m_pageSize);
 
135
 
 
136
    //insert in pages bigger than us, not interested
 
137
    if (start > pageEnd) {
 
138
        return;
 
139
    }
 
140
 
 
141
    //FIXME: proper indexes should be calculated
 
142
    beginResetModel();
 
143
    return;
 
144
 
 
145
    int newStart = qMin(m_pageSize, qMax(0, start - pageStart));
 
146
    int newEnd = qMin(m_pageSize, newStart + (end - start));
 
147
 
 
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 );
 
152
    }
120
153
}
121
154
 
122
155
 
123
156
void PagedProxyModel::sourceRowsInserted( const QModelIndex& parentIdx, int start, int end )
124
157
{
125
158
    Q_UNUSED( parentIdx );
126
 
    Q_UNUSED( start );
127
 
    Q_UNUSED( end );
128
 
    endInsertRows();
 
159
 
 
160
    const int pageStart = (m_currentPage*m_pageSize);
 
161
    const int pageEnd = (m_currentPage*m_pageSize + m_pageSize);
 
162
 
 
163
    if (start > pageEnd) {
 
164
        return;
 
165
    }
 
166
 
 
167
    //FIXME: proper mapped indexes should be calculated
 
168
    endResetModel();
 
169
    return;
 
170
 
 
171
    if (rowCount() > m_oldRowCount) {
 
172
        endInsertRows();
 
173
    }
 
174
    int newStart = qMin(m_pageSize, qMax(0, start - pageStart));
 
175
    int newEnd = qMin(m_pageSize, newStart + (end - start));
 
176
 
 
177
    if (newStart <= m_oldRowCount) {
 
178
        emit dataChanged(PagedProxyModel::index(newStart, 0),
 
179
                         PagedProxyModel::index(qMin(newEnd, m_oldRowCount), 0));
 
180
    }
129
181
}
130
182
 
131
183
 
132
184
void PagedProxyModel::sourceRowsAboutToBeRemoved( const QModelIndex & parentIdx, int start, int end )
133
185
{
134
 
    beginRemoveRows(parentIdx, start, end );
 
186
    const int pageStart = (m_currentPage*m_pageSize);
 
187
    const int pageEnd = (m_currentPage*m_pageSize + m_pageSize);
 
188
 
 
189
    if (start > pageEnd) {
 
190
        return;
 
191
    }
 
192
 
 
193
    //FIXME: proper mapped indexes should be calculated
 
194
    beginResetModel();
 
195
    return;
 
196
 
 
197
    int newStart = qMin(m_pageSize, qMax(0, start - pageStart));
 
198
    int newEnd = qMin(m_pageSize, qMax(0, end - pageStart));
 
199
 
 
200
    m_oldRowCount = rowCount();
 
201
    //insert only the ones that are beyond the count
 
202
    if (newEnd < m_oldRowCount) {
 
203
        beginRemoveRows(parentIdx, newStart, newEnd );
 
204
    }
135
205
}
136
206
 
137
207
 
138
208
void PagedProxyModel::sourceRowsRemoved( const QModelIndex& parentIdx, int start, int end )
139
209
{
140
210
    Q_UNUSED( parentIdx );
141
 
    Q_UNUSED( start );
142
 
    Q_UNUSED( end );
143
 
    endRemoveRows();
 
211
 
 
212
    const int pageStart = (m_currentPage*m_pageSize);
 
213
    const int pageEnd = (m_currentPage*m_pageSize + m_pageSize);
 
214
 
 
215
    if (start > pageEnd) {
 
216
        return;
 
217
    }
 
218
 
 
219
    //FIXME: proper mapped indexes should be calculated
 
220
    endResetModel();
 
221
    return;
 
222
 
 
223
    if (rowCount() < m_oldRowCount) {
 
224
        endRemoveRows();
 
225
    }
 
226
    int newStart = qMin(m_pageSize, qMax(0, start - pageStart));
 
227
    int newEnd = qMin(m_pageSize, newStart + (end - start));
 
228
 
 
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));
 
232
    }
144
233
}
145
234
 
146
235
int PagedProxyModel::rowCount(const QModelIndex &parent) const
172
261
 
173
262
QModelIndex PagedProxyModel::parent(const QModelIndex &index) const
174
263
{
 
264
    Q_UNUSED(index)
175
265
    return QModelIndex();
176
266
}
177
267