hgcacheproxymodel/src/hgcacheproxymodel.cpp
branchGCC_SURGE
changeset 10 c348b9772569
parent 8 15f034b8a3b5
child 17 a10844a9914d
equal deleted inserted replaced
4:463f1934e292 10:c348b9772569
    11 *
    11 *
    12 * Contributors:
    12 * Contributors:
    13 *
    13 *
    14 * Description:
    14 * Description:
    15 *
    15 *
    16 *  Version     : %version: 7 %
    16 *  Version     : %version: 11 %
    17 */
    17 */
    18 #include <QList>
    18 #include <QList>
    19 #include <QAbstractItemModel>
    19 #include <QAbstractItemModel>
    20 
    20 
    21 #include <hgwidgets/hgcacheproxymodel.h>
    21 #include <hgwidgets/hgcacheproxymodel.h>
   249 }
   249 }
   250 
   250 
   251 void HgCacheProxyModel::sort(int column, Qt::SortOrder order)
   251 void HgCacheProxyModel::sort(int column, Qt::SortOrder order)
   252 {
   252 {
   253     mSupressBM = true;
   253     mSupressBM = true;
   254     cleanupForBMReset();
   254     sourceModelAboutToBeReset();
   255     mSortFilterProxyModel->sort(column, order);
   255     mSortFilterProxyModel->sort(column, order);
   256     resetBM();
   256     sourceModelReset();  
   257 }
   257 }
   258 
   258 
   259 QModelIndex HgCacheProxyModel::buddy(const QModelIndex &index) const
   259 QModelIndex HgCacheProxyModel::buddy(const QModelIndex &index) const
   260 {
   260 {
   261     return mSortFilterProxyModel->buddy(mapToSource(index));
   261     return mSortFilterProxyModel->buddy(mapToSource(index));
   280 
   280 
   281 void HgCacheProxyModel::setSortCaseSensitivity(Qt::CaseSensitivity cs)
   281 void HgCacheProxyModel::setSortCaseSensitivity(Qt::CaseSensitivity cs)
   282 {
   282 {
   283     if (sortCaseSensitivity() != cs){
   283     if (sortCaseSensitivity() != cs){
   284         mSupressBM = true;
   284         mSupressBM = true;
   285         cleanupForBMReset();
   285         sourceModelAboutToBeReset();
   286         mSortFilterProxyModel->setSortCaseSensitivity(cs);
   286         mSortFilterProxyModel->setSortCaseSensitivity(cs);
   287         resetBM();    
   287         sourceModelReset();  
   288     }
   288     }
   289 }
   289 }
   290 
   290 
   291 bool HgCacheProxyModel::isSortLocaleAware() const
   291 bool HgCacheProxyModel::isSortLocaleAware() const
   292 {
   292 {
   295 
   295 
   296 void HgCacheProxyModel::setSortLocaleAware(bool on)
   296 void HgCacheProxyModel::setSortLocaleAware(bool on)
   297 {
   297 {
   298     if (isSortLocaleAware() != on){
   298     if (isSortLocaleAware() != on){
   299         mSupressBM = true;    
   299         mSupressBM = true;    
   300         cleanupForBMReset();
   300         sourceModelAboutToBeReset();
   301         mSortFilterProxyModel->setSortLocaleAware(on);
   301         mSortFilterProxyModel->setSortLocaleAware(on);
   302         resetBM();    
   302         sourceModelReset();  
   303     }
   303     }
   304 }
   304 }
   305 
   305 
   306 int HgCacheProxyModel::sortColumn() const
   306 int HgCacheProxyModel::sortColumn() const
   307 {
   307 {
   320 
   320 
   321 void HgCacheProxyModel::setDynamicSortFilter(bool enable)
   321 void HgCacheProxyModel::setDynamicSortFilter(bool enable)
   322 {
   322 {
   323     if (dynamicSortFilter() != enable){
   323     if (dynamicSortFilter() != enable){
   324         mSupressBM = true;   
   324         mSupressBM = true;   
   325         cleanupForBMReset();
   325         sourceModelAboutToBeReset();
   326         mSortFilterProxyModel->setDynamicSortFilter(enable);
   326         mSortFilterProxyModel->setDynamicSortFilter(enable);
   327         resetBM();
   327         sourceModelReset();  
   328     }
   328     }
   329 }
   329 }
   330 
   330 
   331 int HgCacheProxyModel::sortRole() const
   331 int HgCacheProxyModel::sortRole() const
   332 {
   332 {
   335 
   335 
   336 void HgCacheProxyModel::setSortRole(int role)
   336 void HgCacheProxyModel::setSortRole(int role)
   337 {
   337 {
   338     if (sortRole() != role){
   338     if (sortRole() != role){
   339         mSupressBM = true;
   339         mSupressBM = true;
   340         cleanupForBMReset();
   340         sourceModelAboutToBeReset();
   341         mSortFilterProxyModel->setSortRole(role);
   341         mSortFilterProxyModel->setSortRole(role);
   342         resetBM();    
   342         sourceModelReset();    
   343     }
   343     }
   344 }
   344 }
   345 
   345 
   346 QRegExp HgCacheProxyModel::filterRegExp() const
   346 QRegExp HgCacheProxyModel::filterRegExp() const
   347 {
   347 {
   350 
   350 
   351 void HgCacheProxyModel::setFilterRegExp(const QRegExp &regExp)
   351 void HgCacheProxyModel::setFilterRegExp(const QRegExp &regExp)
   352 {
   352 {
   353     if (filterRegExp() != regExp){
   353     if (filterRegExp() != regExp){
   354         mSupressBM = true;
   354         mSupressBM = true;
   355         cleanupForBMReset();
   355         sourceModelAboutToBeReset();
   356         mSortFilterProxyModel->setFilterRegExp(regExp);
   356         mSortFilterProxyModel->setFilterRegExp(regExp);
   357         resetBM();    
   357         sourceModelReset();    
   358     }
   358     }
   359 }
   359 }
   360 
   360 
   361 int HgCacheProxyModel::filterKeyColumn() const
   361 int HgCacheProxyModel::filterKeyColumn() const
   362 {
   362 {
   365 
   365 
   366 void HgCacheProxyModel::setFilterKeyColumn(int column)
   366 void HgCacheProxyModel::setFilterKeyColumn(int column)
   367 {
   367 {
   368     if (filterKeyColumn() != column){   
   368     if (filterKeyColumn() != column){   
   369         mSupressBM = true;
   369         mSupressBM = true;
   370         cleanupForBMReset();
   370         sourceModelAboutToBeReset();
   371         mSortFilterProxyModel->setFilterKeyColumn(column);
   371         mSortFilterProxyModel->setFilterKeyColumn(column);
   372         resetBM();    
   372         sourceModelReset();    
   373     }
   373     }
   374 }
   374 }
   375 
   375 
   376 Qt::CaseSensitivity HgCacheProxyModel::filterCaseSensitivity() const
   376 Qt::CaseSensitivity HgCacheProxyModel::filterCaseSensitivity() const
   377 {
   377 {
   380 
   380 
   381 void HgCacheProxyModel::setFilterCaseSensitivity(Qt::CaseSensitivity cs)
   381 void HgCacheProxyModel::setFilterCaseSensitivity(Qt::CaseSensitivity cs)
   382 {
   382 {
   383     if ( filterCaseSensitivity() != cs){   
   383     if ( filterCaseSensitivity() != cs){   
   384         mSupressBM = true;
   384         mSupressBM = true;
   385         cleanupForBMReset();
   385         sourceModelAboutToBeReset();
   386         mSortFilterProxyModel->setFilterCaseSensitivity(cs);
   386         mSortFilterProxyModel->setFilterCaseSensitivity(cs);
   387         resetBM();    
   387         sourceModelReset();    
   388     }
   388     }
   389 }
   389 }
   390 
   390 
   391 int HgCacheProxyModel::filterRole() const
   391 int HgCacheProxyModel::filterRole() const
   392 {
   392 {
   395 
   395 
   396 void HgCacheProxyModel::setFilterRole(int role)
   396 void HgCacheProxyModel::setFilterRole(int role)
   397 {
   397 {
   398     if ( filterRole() != role ){   
   398     if ( filterRole() != role ){   
   399         mSupressBM = true;
   399         mSupressBM = true;
   400         cleanupForBMReset();
   400         sourceModelAboutToBeReset();
   401         mSortFilterProxyModel->setFilterRole(role);
   401         mSortFilterProxyModel->setFilterRole(role);
   402         resetBM();
   402         sourceModelReset();    
   403     }
   403     }
   404 }
   404 }
   405 
   405 
   406 bool HgCacheProxyModel::submit()
   406 bool HgCacheProxyModel::submit()
   407 {
   407 {
   450             idx = mapToDataProviderIndex(i);
   450             idx = mapToDataProviderIndex(i);
   451             if ( idx >=0)
   451             if ( idx >=0)
   452                 list.append(idx);
   452                 list.append(idx);
   453         }
   453         }
   454     }
   454     }
   455     if (mDataProviderModel)
   455     if (mDataProviderModel && list.count()>0)
   456         mDataProviderModel->request(list, mSupressBM);
   456         mDataProviderModel->request(list, mSupressBM);
   457     TX_EXIT    
   457     TX_EXIT    
   458 }
   458 }
   459 
   459 
   460 int HgCacheProxyModel::count()const
   460 int HgCacheProxyModel::count()const
   478 }
   478 }
   479 
   479 
   480 int HgCacheProxyModel::mapFromDataProviderIndex(int myIndex) const
   480 int HgCacheProxyModel::mapFromDataProviderIndex(int myIndex) const
   481 {
   481 {
   482     return mSortFilterProxyModel->mapFromSource( mDataProviderModel->index(myIndex, 0) ).row();
   482     return mSortFilterProxyModel->mapFromSource( mDataProviderModel->index(myIndex, 0) ).row();
   483 }
       
   484 
       
   485 void HgCacheProxyModel::cleanupForBMReset()
       
   486 {
       
   487     releaseAll();
       
   488 }
       
   489 
       
   490 void HgCacheProxyModel::resetBM()
       
   491 {
       
   492     if (mBufferManager){
       
   493         mCurrentPos = 0;
       
   494         mBufferManager->resetBuffer( mCurrentPos, count() );
       
   495     }
       
   496     mSupressBM = false;
       
   497 }
   483 }
   498 
   484 
   499 void HgCacheProxyModel::releaseAll()
   485 void HgCacheProxyModel::releaseAll()
   500 {
   486 {
   501     if ( mDataProviderModel ){
   487     if ( mDataProviderModel ){
   577 {
   563 {
   578     TX_ENTRY_ARGS(QString("from:%1 to:%2").arg( topLeft.row() ).arg( bottomRight.row() ) );
   564     TX_ENTRY_ARGS(QString("from:%1 to:%2").arg( topLeft.row() ).arg( bottomRight.row() ) );
   579     QModelIndex begin = index( topLeft.row(), topLeft.column() );
   565     QModelIndex begin = index( topLeft.row(), topLeft.column() );
   580     QModelIndex end = index( bottomRight.row(), bottomRight.column() );
   566     QModelIndex end = index( bottomRight.row(), bottomRight.column() );
   581     
   567     
   582     if (begin.isValid() && end.isValid() && !mSupressBM)
   568     if (begin.isValid() && end.isValid() && !mSupressBM){
   583         emit dataChanged(begin, end);
   569         emit dataChanged(begin, end);
       
   570     }
   584     TX_EXIT
   571     TX_EXIT
   585 }
   572 }
   586 
   573 
   587 void HgCacheProxyModel::sourceHeaderDataChanged( Qt::Orientation orientation, int first, int last )
   574 void HgCacheProxyModel::sourceHeaderDataChanged( Qt::Orientation orientation, int first, int last )
   588 {
   575 {
   593 
   580 
   594 void HgCacheProxyModel::sourceLayoutAboutToBeChanged()
   581 void HgCacheProxyModel::sourceLayoutAboutToBeChanged()
   595 {
   582 {
   596     TX_ENTRY
   583     TX_ENTRY
   597     emit layoutAboutToBeChanged();
   584     emit layoutAboutToBeChanged();
       
   585     TX_EXIT
       
   586 }
       
   587 
       
   588 void HgCacheProxyModel::sourceLayoutChanged()
       
   589 {
       
   590     TX_ENTRY
       
   591     emit layoutChanged();
       
   592     TX_EXIT    
       
   593 }
       
   594 
       
   595 void HgCacheProxyModel::sourceModelAboutToBeReset()
       
   596 {
       
   597     TX_ENTRY
       
   598     beginResetModel();
   598     mSupressBM = true;
   599     mSupressBM = true;
   599     releaseAll();
   600     releaseAll();
   600     TX_EXIT
   601     TX_EXIT
   601 }
   602 }
   602 
   603 
   603 void HgCacheProxyModel::sourceLayoutChanged()
   604 void HgCacheProxyModel::sourceModelReset()
   604 {
   605 {
   605     TX_ENTRY
   606     TX_ENTRY
   606     mSupressBM = true;
   607     mSupressBM = true;
   607     if (mBufferManager){
   608     if (mBufferManager){
   608         mCurrentPos = 0;
   609         mCurrentPos = 0;
   609         mBufferManager->resetBuffer( mCurrentPos, count() );
   610         mBufferManager->resetBuffer( mCurrentPos, count() );
   610     }
   611     }
   611     mSupressBM = false;
   612     mSupressBM = false;
   612     emit layoutChanged();
       
   613     TX_EXIT    
       
   614 }
       
   615 
       
   616 void HgCacheProxyModel::sourceModelAboutToBeReset()
       
   617 {
       
   618     TX_ENTRY
       
   619     beginResetModel();
       
   620     mSupressBM = true;
       
   621     releaseAll();
       
   622     TX_EXIT
       
   623 }
       
   624 
       
   625 void HgCacheProxyModel::sourceModelReset()
       
   626 {
       
   627     TX_ENTRY
       
   628     mSupressBM = true;
       
   629     if (mBufferManager){
       
   630         mCurrentPos = 0;
       
   631         mBufferManager->resetBuffer( mCurrentPos, count() );
       
   632     }
       
   633     mSupressBM = false;
       
   634     endResetModel();
   613     endResetModel();
   635     TX_EXIT
   614     TX_EXIT
   636 }
   615 }
   637 
   616 
   638 void HgCacheProxyModel::sourceRowsAboutToBeInserted( const QModelIndex & parent, int start, int end )
   617 void HgCacheProxyModel::sourceRowsAboutToBeInserted( const QModelIndex & parent, int start, int end )
   639 {
   618 {
   640     TX_ENTRY
   619     TX_ENTRY
   641     if (mBufferManager && !mSupressBM){
   620     if (mBufferManager && !mSupressBM){
   642         beginInsertRows(parent, start, end);
   621         beginInsertRows(parent, start, end);
   643 //        mBufferManager->aboutToInsertItems(start, end);    
   622         for ( int i=start; i <=end; i++){
       
   623             mBufferManager->aboutToInsertItem(i);
       
   624         }        
   644     }
   625     }
   645     TX_EXIT
   626     TX_EXIT
   646 }
   627 }
   647 
   628 
   648 void HgCacheProxyModel::sourceRowsAboutToBeMoved( const QModelIndex & sourceParent, int sourceStart, 
   629 void HgCacheProxyModel::sourceRowsAboutToBeMoved( const QModelIndex & sourceParent, int sourceStart, 
   656 void HgCacheProxyModel::sourceRowsAboutToBeRemoved( const QModelIndex & parent, int start, int end )
   637 void HgCacheProxyModel::sourceRowsAboutToBeRemoved( const QModelIndex & parent, int start, int end )
   657 {
   638 {
   658     TX_ENTRY
   639     TX_ENTRY
   659     if (mBufferManager && !mSupressBM){
   640     if (mBufferManager && !mSupressBM){
   660         beginRemoveRows(parent, start, end);
   641         beginRemoveRows(parent, start, end);
   661 //        mBufferManager->aboutToRemoveItems(start, end);    
   642         for ( int i=start; i <=end; i++){
       
   643             mBufferManager->aboutToRemoveItem(i);
       
   644         }
   662     }
   645     }
   663     TX_EXIT
   646     TX_EXIT
   664 }
   647 }
   665 
   648 
   666 void HgCacheProxyModel::sourceRowsInserted( const QModelIndex & parent, int start, int end )
   649 void HgCacheProxyModel::sourceRowsInserted( const QModelIndex & parent, int start, int end )
   667 {
   650 {
   668     TX_ENTRY
   651     TX_ENTRY
   669     Q_UNUSED(parent);
   652     Q_UNUSED(parent);
   670     Q_UNUSED(end);
   653     Q_UNUSED(end);
   671     if (mBufferManager && !mSupressBM){
   654     if (mBufferManager && !mSupressBM){
   672         mBufferManager->itemCountChanged(start, false, count());
   655         for ( int i=start; i <=end; i++){
       
   656             mBufferManager->insertedItem(i);
       
   657         }
   673         endInsertRows();
   658         endInsertRows();
   674     }
   659     }
   675     TX_EXIT    
   660     TX_EXIT    
   676 }
   661 }
   677 
   662 
   692 {
   677 {
   693     TX_ENTRY
   678     TX_ENTRY
   694     Q_UNUSED(parent);
   679     Q_UNUSED(parent);
   695     Q_UNUSED(end);
   680     Q_UNUSED(end);
   696     if (mBufferManager && !mSupressBM){
   681     if (mBufferManager && !mSupressBM){
   697         mBufferManager->itemCountChanged(start, true, count());
   682         for ( int i=start; i <=end; i++){
       
   683             mBufferManager->removedItem(i);
       
   684         }
   698         endRemoveRows();
   685         endRemoveRows();
   699     }
   686     }
   700     TX_EXIT
   687     TX_EXIT
   701 }
   688 }
   702 
   689 
   711         end = begin;
   698         end = begin;
   712     } else {
   699     } else {
   713         end = index(mapFromDataProviderIndex(to),0);
   700         end = index(mapFromDataProviderIndex(to),0);
   714     }
   701     }
   715     
   702     
   716     if (begin.isValid() && end.isValid() && !mSupressBM)
   703     if (begin.isValid() && end.isValid() && !mSupressBM){
   717         emit dataChanged(begin, end );
   704         emit dataChanged(begin, end );
       
   705     }
   718 }
   706 }
   719 
   707 
   720 //eof
   708 //eof