|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 * Version : %version: 2 % |
|
17 */ |
|
18 #include <QList> |
|
19 #include <QAbstractItemModel> |
|
20 |
|
21 #include <hgwidgets/hgcacheproxymodel.h> |
|
22 #include <hgwidgets/hgdataprovidermodel.h> |
|
23 #include "hgbuffermanager.h" |
|
24 #include "hglogger.h" |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 Q_DECL_EXPORT HgCacheProxyModel::HgCacheProxyModel(QObject *parent): |
|
31 QAbstractItemModel(parent), |
|
32 mBufferManager(0), |
|
33 mSortFilterProxyModel(new QSortFilterProxyModel(this)), |
|
34 mDataProviderModel(0), |
|
35 mResetNeeded(false), |
|
36 mSupressBM(false), |
|
37 mSortParameterChanged(true), |
|
38 mFilterParameterChanged(true) |
|
39 { |
|
40 connect(mSortFilterProxyModel, SIGNAL(columnsAboutToBeInserted(QModelIndex,int,int)), |
|
41 this, SIGNAL(columnsAboutToBeInserted(QModelIndex,int,int))); |
|
42 |
|
43 connect(mSortFilterProxyModel, SIGNAL(columnsAboutToBeMoved(QModelIndex, int, int, QModelIndex, int)), |
|
44 this, SIGNAL(columnsAboutToBeMoved(QModelIndex, int, int, QModelIndex, int))); |
|
45 |
|
46 connect(mSortFilterProxyModel, SIGNAL(columnsAboutToBeRemoved(QModelIndex,int,int)), |
|
47 this, SIGNAL(columnsAboutToBeRemoved(QModelIndex,int,int))); |
|
48 |
|
49 connect(mSortFilterProxyModel, SIGNAL(columnsInserted(QModelIndex,int,int)), |
|
50 this, SIGNAL(columnsInserted(QModelIndex,int,int))); |
|
51 |
|
52 connect(mSortFilterProxyModel, SIGNAL(columnsMoved(QModelIndex, int, int, QModelIndex, int)), |
|
53 this, SIGNAL(columnsMoved(QModelIndex, int, int, QModelIndex, int))); |
|
54 |
|
55 connect(mSortFilterProxyModel, SIGNAL(columnsRemoved(QModelIndex,int,int)), |
|
56 this, SIGNAL(columnsRemoved(QModelIndex,int,int))); |
|
57 |
|
58 connect(mSortFilterProxyModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)), |
|
59 this, SLOT(dataUpdated(QModelIndex,QModelIndex))); |
|
60 |
|
61 connect(mSortFilterProxyModel, SIGNAL(headerDataChanged(Qt::Orientation,int,int)), |
|
62 this, SIGNAL(headerDataChanged(Qt::Orientation,int,int))); |
|
63 |
|
64 connect(mSortFilterProxyModel, SIGNAL(layoutAboutToBeChanged()), |
|
65 this, SIGNAL(layoutAboutToBeChanged())); |
|
66 |
|
67 connect(mSortFilterProxyModel, SIGNAL(layoutChanged()), |
|
68 this, SIGNAL(layoutChanged())); |
|
69 |
|
70 connect(mSortFilterProxyModel, SIGNAL(modelAboutToBeReset()), |
|
71 this, SLOT(sourceAboutToBeReset())); |
|
72 |
|
73 connect(mSortFilterProxyModel, SIGNAL(modelReset()), |
|
74 this, SLOT(sourceReset())); |
|
75 |
|
76 connect(mSortFilterProxyModel, SIGNAL(rowsAboutToBeInserted(QModelIndex,int,int)), |
|
77 this, SIGNAL(rowsAboutToBeInserted(QModelIndex,int,int))); |
|
78 |
|
79 connect(mSortFilterProxyModel, SIGNAL(rowsAboutToBeMoved(QModelIndex, int, int, QModelIndex, int)), |
|
80 this, SIGNAL(rowsAboutToBeMoved(QModelIndex, int, int, QModelIndex, int))); |
|
81 |
|
82 connect(mSortFilterProxyModel, SIGNAL(rowsAboutToBeRemoved(QModelIndex,int,int)), |
|
83 this, SIGNAL(rowsAboutToBeRemoved(QModelIndex,int,int))); |
|
84 |
|
85 connect(mSortFilterProxyModel, SIGNAL(rowsInserted(QModelIndex,int,int)), |
|
86 this, SIGNAL(rowsInserted(QModelIndex,int,int))); |
|
87 |
|
88 connect(mSortFilterProxyModel, SIGNAL(rowsInserted(QModelIndex,int,int)), |
|
89 this, SLOT(sourceRowsInserted(QModelIndex,int,int))); |
|
90 |
|
91 connect(mSortFilterProxyModel, SIGNAL(rowsMoved(QModelIndex, int, int, QModelIndex, int)), |
|
92 this, SIGNAL(rowsMoved(QModelIndex, int, int, QModelIndex, int))); |
|
93 |
|
94 connect(mSortFilterProxyModel, SIGNAL(rowsRemoved(QModelIndex,int,int)), |
|
95 this, SIGNAL(rowsRemoved(QModelIndex,int,int))); |
|
96 |
|
97 connect(mSortFilterProxyModel, SIGNAL(rowsRemoved(QModelIndex,int,int)), |
|
98 this, SLOT(sourceRowsRemoved(QModelIndex,int,int))); |
|
99 } |
|
100 |
|
101 Q_DECL_EXPORT HgCacheProxyModel::~HgCacheProxyModel() |
|
102 { |
|
103 delete mBufferManager; |
|
104 } |
|
105 |
|
106 Q_DECL_EXPORT void HgCacheProxyModel::setDataProvider(HgDataProviderModel *dataProvider, int cacheSize, int cacheTreshold) |
|
107 { |
|
108 TX_ENTRY |
|
109 mDataProviderModel = dataProvider; |
|
110 mSortFilterProxyModel->setSourceModel(mDataProviderModel); |
|
111 if (mDataProviderModel){ |
|
112 mDataProviderModel->registerObserver(this); |
|
113 mDataProviderModel->resizeQPixmapPool(cacheSize); |
|
114 |
|
115 delete mBufferManager; |
|
116 mBufferManager = NULL; |
|
117 mBufferManager = new HgBufferManager(this, cacheSize, cacheTreshold, 0, count() ); |
|
118 } |
|
119 TX_EXIT |
|
120 } |
|
121 |
|
122 Q_DECL_EXPORT HgDataProviderModel* HgCacheProxyModel::DataProvider() |
|
123 { |
|
124 return mDataProviderModel; |
|
125 } |
|
126 |
|
127 Q_DECL_EXPORT void HgCacheProxyModel::resizeCache(int newSize, int newTreshold) |
|
128 { |
|
129 TX_ENTRY |
|
130 if (mDataProviderModel) |
|
131 mDataProviderModel->resizeQPixmapPool(newSize); |
|
132 if (mBufferManager) |
|
133 mBufferManager->resizeCache( newSize, newTreshold ); |
|
134 TX_EXIT |
|
135 } |
|
136 |
|
137 Q_DECL_EXPORT QModelIndex HgCacheProxyModel::index(int row, int column, const QModelIndex &parent) const |
|
138 { |
|
139 Q_UNUSED(parent); |
|
140 if ( row >= rowCount() ){ |
|
141 row = -1; |
|
142 } |
|
143 if ( column >= columnCount() ){ |
|
144 column = -1; |
|
145 } |
|
146 |
|
147 return QAbstractItemModel::createIndex(row, column); |
|
148 } |
|
149 |
|
150 Q_DECL_EXPORT QModelIndex HgCacheProxyModel::parent(const QModelIndex &child) const |
|
151 { |
|
152 return mSortFilterProxyModel->parent(mapToSource(child)); |
|
153 } |
|
154 |
|
155 Q_DECL_EXPORT int HgCacheProxyModel::rowCount(const QModelIndex &parent) const |
|
156 { |
|
157 return mSortFilterProxyModel->rowCount(mapToSource(parent)); |
|
158 } |
|
159 |
|
160 Q_DECL_EXPORT int HgCacheProxyModel::columnCount(const QModelIndex &parent) const |
|
161 { |
|
162 return mSortFilterProxyModel->columnCount(mapToSource(parent)); |
|
163 } |
|
164 |
|
165 Q_DECL_EXPORT bool HgCacheProxyModel::hasChildren(const QModelIndex &parent) const |
|
166 { |
|
167 return mSortFilterProxyModel->hasChildren(mapToSource(parent)); |
|
168 } |
|
169 |
|
170 Q_DECL_EXPORT QVariant HgCacheProxyModel::data(const QModelIndex &index, int role) const |
|
171 { |
|
172 setBufferPosition(index.row()); |
|
173 QVariant res = mSortFilterProxyModel->data(mapToSource(index), role); |
|
174 return res; |
|
175 } |
|
176 |
|
177 Q_DECL_EXPORT bool HgCacheProxyModel::setData(const QModelIndex &index, const QVariant &value, int role) |
|
178 { |
|
179 return mSortFilterProxyModel->setData(mapToSource(index), value, role); |
|
180 } |
|
181 |
|
182 Q_DECL_EXPORT QVariant HgCacheProxyModel::headerData(int section, Qt::Orientation orientation, int role) const |
|
183 { |
|
184 return mSortFilterProxyModel->headerData(section, orientation, role); |
|
185 } |
|
186 |
|
187 Q_DECL_EXPORT bool HgCacheProxyModel::setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role) |
|
188 { |
|
189 return mSortFilterProxyModel->setHeaderData(section, orientation, value, role); |
|
190 } |
|
191 |
|
192 Q_DECL_EXPORT QMap<int, QVariant> HgCacheProxyModel::itemData(const QModelIndex &index) const |
|
193 { |
|
194 setBufferPosition(index.row()); |
|
195 return mSortFilterProxyModel->itemData(mapToSource(index)); |
|
196 } |
|
197 |
|
198 Q_DECL_EXPORT bool HgCacheProxyModel::setItemData(const QModelIndex &index, const QMap<int, QVariant> &roles) |
|
199 { |
|
200 return mSortFilterProxyModel->setItemData(mapToSource(index), roles); |
|
201 } |
|
202 |
|
203 Q_DECL_EXPORT QStringList HgCacheProxyModel::mimeTypes() const |
|
204 { |
|
205 return mSortFilterProxyModel->mimeTypes(); |
|
206 } |
|
207 |
|
208 Q_DECL_EXPORT QMimeData *HgCacheProxyModel::mimeData(const QModelIndexList &indexes) const |
|
209 { |
|
210 QModelIndexList list; |
|
211 for ( int i=0; i < indexes.count(); i++){ |
|
212 list.append(mapToSource(indexes[i])); |
|
213 } |
|
214 return mSortFilterProxyModel->mimeData(list); |
|
215 } |
|
216 |
|
217 Q_DECL_EXPORT bool HgCacheProxyModel::dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) |
|
218 { |
|
219 return mSortFilterProxyModel->dropMimeData(data, action, row, column, mapToSource(parent)); |
|
220 } |
|
221 |
|
222 Q_DECL_EXPORT Qt::DropActions HgCacheProxyModel::supportedDropActions() const |
|
223 { |
|
224 return mSortFilterProxyModel->supportedDropActions(); |
|
225 } |
|
226 |
|
227 Q_DECL_EXPORT bool HgCacheProxyModel::insertRows(int row, int count, const QModelIndex &parent) |
|
228 { |
|
229 return mSortFilterProxyModel->insertRows(row, count, mapToSource(parent)); |
|
230 } |
|
231 |
|
232 Q_DECL_EXPORT bool HgCacheProxyModel::insertColumns(int column, int count, const QModelIndex &parent) |
|
233 { |
|
234 return mSortFilterProxyModel->insertColumns(column, count, mapToSource(parent)); |
|
235 } |
|
236 |
|
237 Q_DECL_EXPORT bool HgCacheProxyModel::removeRows(int row, int count, const QModelIndex &parent) |
|
238 { |
|
239 return mSortFilterProxyModel->removeRows(row, count, mapToSource(parent)); |
|
240 } |
|
241 |
|
242 Q_DECL_EXPORT bool HgCacheProxyModel::removeColumns(int column, int count, const QModelIndex &parent) |
|
243 { |
|
244 return mSortFilterProxyModel->removeColumns(column, count, mapToSource(parent)); |
|
245 } |
|
246 |
|
247 Q_DECL_EXPORT void HgCacheProxyModel::fetchMore(const QModelIndex &parent) |
|
248 { |
|
249 mSortFilterProxyModel->fetchMore(mapToSource(parent)); |
|
250 } |
|
251 |
|
252 Q_DECL_EXPORT bool HgCacheProxyModel::canFetchMore(const QModelIndex &parent) const |
|
253 { |
|
254 return mSortFilterProxyModel->canFetchMore(mapToSource(parent)); |
|
255 } |
|
256 |
|
257 Q_DECL_EXPORT Qt::ItemFlags HgCacheProxyModel::flags(const QModelIndex &index) const |
|
258 { |
|
259 return mSortFilterProxyModel->flags(mapToSource(index)); |
|
260 } |
|
261 |
|
262 Q_DECL_EXPORT void HgCacheProxyModel::sort(int column, Qt::SortOrder order) |
|
263 { |
|
264 if ( mSortParameterChanged || (sortColumn() != column) || (sortOrder() != order) ){ |
|
265 mSortParameterChanged = false; |
|
266 mResetNeeded = true; |
|
267 cleanupForBMResetIfNeeded(); |
|
268 mSortFilterProxyModel->sort(column, order); |
|
269 resetBMIfNeeded(); |
|
270 } |
|
271 } |
|
272 |
|
273 Q_DECL_EXPORT QModelIndex HgCacheProxyModel::buddy(const QModelIndex &index) const |
|
274 { |
|
275 return mSortFilterProxyModel->buddy(mapToSource(index)); |
|
276 } |
|
277 |
|
278 Q_DECL_EXPORT QModelIndexList HgCacheProxyModel::match(const QModelIndex &start, int role, |
|
279 const QVariant &value, int hits, |
|
280 Qt::MatchFlags flags) const |
|
281 { |
|
282 return mSortFilterProxyModel->match(mapToSource(start), role, value, hits, flags); |
|
283 } |
|
284 |
|
285 Q_DECL_EXPORT QSize HgCacheProxyModel::span(const QModelIndex &index) const |
|
286 { |
|
287 return mSortFilterProxyModel->span(mapToSource(index)); |
|
288 } |
|
289 |
|
290 Q_DECL_EXPORT Qt::CaseSensitivity HgCacheProxyModel::sortCaseSensitivity() const |
|
291 { |
|
292 return mSortFilterProxyModel->sortCaseSensitivity(); |
|
293 } |
|
294 |
|
295 Q_DECL_EXPORT void HgCacheProxyModel::setSortCaseSensitivity(Qt::CaseSensitivity cs) |
|
296 { |
|
297 if (sortCaseSensitivity() != cs){ |
|
298 mSortParameterChanged = true; |
|
299 cleanupForBMResetIfNeeded(); |
|
300 mSortFilterProxyModel->setSortCaseSensitivity(cs); |
|
301 resetBMIfNeeded(); |
|
302 } |
|
303 } |
|
304 |
|
305 Q_DECL_EXPORT bool HgCacheProxyModel::isSortLocaleAware() const |
|
306 { |
|
307 return mSortFilterProxyModel->isSortLocaleAware(); |
|
308 } |
|
309 |
|
310 Q_DECL_EXPORT void HgCacheProxyModel::setSortLocaleAware(bool on) |
|
311 { |
|
312 if (isSortLocaleAware() != on){ |
|
313 mSortParameterChanged = true; |
|
314 cleanupForBMResetIfNeeded(); |
|
315 mSortFilterProxyModel->setSortLocaleAware(on); |
|
316 resetBMIfNeeded(); |
|
317 } |
|
318 } |
|
319 |
|
320 Q_DECL_EXPORT int HgCacheProxyModel::sortColumn() const |
|
321 { |
|
322 return mSortFilterProxyModel->sortColumn(); |
|
323 } |
|
324 |
|
325 Q_DECL_EXPORT Qt::SortOrder HgCacheProxyModel::sortOrder() const |
|
326 { |
|
327 return mSortFilterProxyModel->sortOrder(); |
|
328 } |
|
329 |
|
330 Q_DECL_EXPORT bool HgCacheProxyModel::dynamicSortFilter() const |
|
331 { |
|
332 return mSortFilterProxyModel->dynamicSortFilter(); |
|
333 } |
|
334 |
|
335 Q_DECL_EXPORT void HgCacheProxyModel::setDynamicSortFilter(bool enable) |
|
336 { |
|
337 if (dynamicSortFilter() != enable){ |
|
338 mSortParameterChanged = true; |
|
339 mFilterParameterChanged = true; |
|
340 cleanupForBMResetIfNeeded(); |
|
341 mSortFilterProxyModel->setDynamicSortFilter(enable); |
|
342 resetBMIfNeeded(); |
|
343 } |
|
344 } |
|
345 |
|
346 Q_DECL_EXPORT int HgCacheProxyModel::sortRole() const |
|
347 { |
|
348 return mSortFilterProxyModel->sortRole(); |
|
349 } |
|
350 |
|
351 Q_DECL_EXPORT void HgCacheProxyModel::setSortRole(int role) |
|
352 { |
|
353 if (sortRole() != role){ |
|
354 mSortParameterChanged = true; |
|
355 cleanupForBMResetIfNeeded(); |
|
356 mSortFilterProxyModel->setSortRole(role); |
|
357 resetBMIfNeeded(); |
|
358 } |
|
359 } |
|
360 |
|
361 //Q_DECL_EXPORT QRegExp HgCacheProxyModel::filterRegExp() const |
|
362 //{ |
|
363 // return mSortFilterProxyModel->filterRegExp(); |
|
364 //} |
|
365 // |
|
366 //Q_DECL_EXPORT void HgCacheProxyModel::setFilterRegExp(const QRegExp ®Exp) |
|
367 //{ |
|
368 // if (filterRegExp() != regExp){ |
|
369 // mFilterParameterChanged = true; |
|
370 // cleanupForBMResetIfNeeded(); |
|
371 // mSortFilterProxyModel->setFilterRegExp(regExp); |
|
372 // resetBMIfNeeded(); |
|
373 // } |
|
374 //} |
|
375 // |
|
376 //Q_DECL_EXPORT int HgCacheProxyModel::filterKeyColumn() const |
|
377 //{ |
|
378 // return mSortFilterProxyModel->filterKeyColumn(); |
|
379 //} |
|
380 // |
|
381 //Q_DECL_EXPORT void HgCacheProxyModel::setFilterKeyColumn(int column) |
|
382 //{ |
|
383 // if (filterKeyColumn() != column){ |
|
384 // mFilterParameterChanged = true; |
|
385 // cleanupForBMResetIfNeeded(); |
|
386 // mSortFilterProxyModel->setFilterKeyColumn(column); |
|
387 // resetBMIfNeeded(); |
|
388 // } |
|
389 //} |
|
390 // |
|
391 //Q_DECL_EXPORT Qt::CaseSensitivity HgCacheProxyModel::filterCaseSensitivity() const |
|
392 //{ |
|
393 // return mSortFilterProxyModel->filterCaseSensitivity(); |
|
394 //} |
|
395 // |
|
396 //Q_DECL_EXPORT void HgCacheProxyModel::setFilterCaseSensitivity(Qt::CaseSensitivity cs) |
|
397 //{ |
|
398 // if ( filterCaseSensitivity() != cs){ |
|
399 // mFilterParameterChanged = true; |
|
400 // cleanupForBMResetIfNeeded(); |
|
401 // mSortFilterProxyModel->setFilterCaseSensitivity(cs); |
|
402 // resetBMIfNeeded(); |
|
403 // } |
|
404 //} |
|
405 // |
|
406 //Q_DECL_EXPORT int HgCacheProxyModel::filterRole() const |
|
407 //{ |
|
408 // return mSortFilterProxyModel->filterRole(); |
|
409 //} |
|
410 // |
|
411 //Q_DECL_EXPORT void HgCacheProxyModel::setFilterRole(int role) |
|
412 //{ |
|
413 // if ( mFilterParameterChanged || (filterRole() != role)){ |
|
414 // mFilterParameterChanged = false; |
|
415 // mResetNeeded = true; |
|
416 // cleanupForBMResetIfNeeded(); |
|
417 // mSortFilterProxyModel->setFilterRole(role); |
|
418 // resetBMIfNeeded(); |
|
419 // } |
|
420 //} |
|
421 |
|
422 Q_DECL_EXPORT bool HgCacheProxyModel::submit() |
|
423 { |
|
424 return mSortFilterProxyModel->submit(); |
|
425 } |
|
426 |
|
427 Q_DECL_EXPORT void HgCacheProxyModel::revert() |
|
428 { |
|
429 mSortFilterProxyModel->revert(); |
|
430 } |
|
431 |
|
432 Q_DECL_EXPORT void HgCacheProxyModel::release(int start, int end) |
|
433 { |
|
434 TX_ENTRY_ARGS( QString("%0-%1").arg(start).arg(end)); |
|
435 QList<int> list; |
|
436 int idx = 0; |
|
437 if ( start > end){ |
|
438 idx = end; |
|
439 end = start; |
|
440 start = idx; |
|
441 idx = 0; |
|
442 } |
|
443 for ( int i=start; i <=end; i++){ |
|
444 idx = mapToDataProviderIndex(i); |
|
445 if ( idx >=0) |
|
446 list.append(idx); |
|
447 } |
|
448 if (mDataProviderModel) |
|
449 mDataProviderModel->release(list, true); |
|
450 TX_EXIT |
|
451 } |
|
452 |
|
453 Q_DECL_EXPORT void HgCacheProxyModel::request(int start, int end, HgRequestOrder order) |
|
454 { |
|
455 TX_ENTRY_ARGS( QString("%0-%1").arg(start).arg(end)); |
|
456 QList<int> list; |
|
457 int idx; |
|
458 if (order == HgRequestOrderAscending){ |
|
459 for ( int i=start; i <=end; i++){ |
|
460 idx = mapToDataProviderIndex(i); |
|
461 if ( idx >=0) |
|
462 list.append(idx); |
|
463 } |
|
464 } else { |
|
465 for ( int i=end; i >=start; i--){ |
|
466 idx = mapToDataProviderIndex(i); |
|
467 if ( idx >=0) |
|
468 list.append(idx); |
|
469 } |
|
470 } |
|
471 if (mDataProviderModel) |
|
472 mDataProviderModel->request(list, mSupressBM); |
|
473 TX_EXIT |
|
474 } |
|
475 |
|
476 int HgCacheProxyModel::count()const |
|
477 { |
|
478 return rowCount(index(0, 0, QModelIndex())); |
|
479 } |
|
480 |
|
481 QModelIndex HgCacheProxyModel::mapToSource(const QModelIndex &index) const |
|
482 { |
|
483 return mapToSource(index.row(), index.column()); |
|
484 } |
|
485 |
|
486 QModelIndex HgCacheProxyModel::mapToSource(int row, int col) const |
|
487 { |
|
488 return mSortFilterProxyModel->index(row, col); |
|
489 } |
|
490 |
|
491 int HgCacheProxyModel::mapToDataProviderIndex(int myIndex) const |
|
492 { |
|
493 return mSortFilterProxyModel->mapToSource( mapToSource(myIndex, 0)).row(); |
|
494 } |
|
495 |
|
496 int HgCacheProxyModel::mapFromDataProviderIndex(int myIndex) const |
|
497 { |
|
498 return mSortFilterProxyModel->mapFromSource( mDataProviderModel->index(myIndex, 0) ).row(); |
|
499 } |
|
500 |
|
501 void HgCacheProxyModel::cleanupForBMResetIfNeeded() |
|
502 { |
|
503 if (mResetNeeded || mSortFilterProxyModel->dynamicSortFilter()==true){ |
|
504 TX_LOG |
|
505 mSupressBM = true; |
|
506 mResetNeeded = true; |
|
507 beginResetModel(); |
|
508 releaseAll(); |
|
509 } |
|
510 } |
|
511 |
|
512 void HgCacheProxyModel::resetBMIfNeeded() |
|
513 { |
|
514 if ( mResetNeeded ){ |
|
515 if (mBufferManager) |
|
516 mBufferManager->resetBuffer( mCurrentPos, count() ); |
|
517 mSupressBM = false; |
|
518 mResetNeeded = false; |
|
519 endResetModel(); |
|
520 } |
|
521 mResetNeeded = false; |
|
522 } |
|
523 |
|
524 void HgCacheProxyModel::releaseAll() |
|
525 { |
|
526 if ( mDataProviderModel ){ |
|
527 QList<int> list; |
|
528 for ( int i=0; i<mDataProviderModel->rowCount(); i++){ |
|
529 list.append(i); |
|
530 } |
|
531 mDataProviderModel->release(list, true); //will quietly replace all icons with default ones, |
|
532 } |
|
533 } |
|
534 |
|
535 void HgCacheProxyModel::setBufferPosition(int pos) const |
|
536 { |
|
537 if (!mSupressBM && mBufferManager){ |
|
538 TX_LOG_ARGS(QString("idx:%1 ").arg(pos) ); |
|
539 if (mCurrentPos!=pos){ |
|
540 mCurrentPos = pos; |
|
541 mBufferManager->setPosition(mCurrentPos); |
|
542 } |
|
543 } |
|
544 } |
|
545 |
|
546 void HgCacheProxyModel::sourceReset() |
|
547 { |
|
548 mSupressBM = true; |
|
549 mResetNeeded = true; |
|
550 releaseAll(); |
|
551 if (mBufferManager) |
|
552 mBufferManager->resetBuffer( 0, count() ); |
|
553 mSupressBM = false; |
|
554 mResetNeeded = false; |
|
555 endResetModel(); |
|
556 } |
|
557 |
|
558 void HgCacheProxyModel::sourceAboutToBeReset() |
|
559 { |
|
560 mSupressBM = true; |
|
561 mResetNeeded = true; |
|
562 beginResetModel(); |
|
563 } |
|
564 |
|
565 void HgCacheProxyModel::sourceRowsInserted(const QModelIndex &source_parent, int start, int end) |
|
566 { |
|
567 Q_UNUSED(source_parent); |
|
568 Q_UNUSED(end); |
|
569 if (mBufferManager) |
|
570 mBufferManager->itemCountChanged(start, false, count()); |
|
571 } |
|
572 |
|
573 void HgCacheProxyModel::sourceRowsRemoved(const QModelIndex &source_parent, int start, int end) |
|
574 { |
|
575 Q_UNUSED(source_parent); |
|
576 Q_UNUSED(end); |
|
577 if (mBufferManager) |
|
578 mBufferManager->itemCountChanged(start, true, count()); |
|
579 } |
|
580 |
|
581 void HgCacheProxyModel::dataUpdated(QModelIndex from, QModelIndex to) |
|
582 { |
|
583 dataUpdated(from.row(), to.row()); |
|
584 } |
|
585 |
|
586 Q_DECL_EXPORT void HgCacheProxyModel::dataUpdated(int from, int to) |
|
587 { |
|
588 TX_LOG_ARGS(QString("from:%1 to:%2").arg(from).arg(to)); |
|
589 emit dataChanged(index(mapFromDataProviderIndex(from),0), index ( mapFromDataProviderIndex(to),0) ); |
|
590 } |
|
591 //eof |