hgcacheproxymodel/src/hgcacheproxymodel.cpp
changeset 3 c863538fcbb6
parent 2 49c70dcc3f17
child 6 1cdcc61142d2
equal deleted inserted replaced
2:49c70dcc3f17 3:c863538fcbb6
    11 *
    11 *
    12 * Contributors:
    12 * Contributors:
    13 *
    13 *
    14 * Description:
    14 * Description:
    15 *
    15 *
    16 *  Version     : %version: 7 %
    16 *  Version     : %version: 10 %
    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 {
   638 void HgCacheProxyModel::sourceRowsAboutToBeInserted( const QModelIndex & parent, int start, int end )
   625 void HgCacheProxyModel::sourceRowsAboutToBeInserted( const QModelIndex & parent, int start, int end )
   639 {
   626 {
   640     TX_ENTRY
   627     TX_ENTRY
   641     if (mBufferManager && !mSupressBM){
   628     if (mBufferManager && !mSupressBM){
   642         beginInsertRows(parent, start, end);
   629         beginInsertRows(parent, start, end);
   643 //        mBufferManager->aboutToInsertItems(start, end);    
   630         for ( int i=start; i <=end; i++){
       
   631             mBufferManager->aboutToInsertItem(i);
       
   632         }        
   644     }
   633     }
   645     TX_EXIT
   634     TX_EXIT
   646 }
   635 }
   647 
   636 
   648 void HgCacheProxyModel::sourceRowsAboutToBeMoved( const QModelIndex & sourceParent, int sourceStart, 
   637 void HgCacheProxyModel::sourceRowsAboutToBeMoved( const QModelIndex & sourceParent, int sourceStart, 
   656 void HgCacheProxyModel::sourceRowsAboutToBeRemoved( const QModelIndex & parent, int start, int end )
   645 void HgCacheProxyModel::sourceRowsAboutToBeRemoved( const QModelIndex & parent, int start, int end )
   657 {
   646 {
   658     TX_ENTRY
   647     TX_ENTRY
   659     if (mBufferManager && !mSupressBM){
   648     if (mBufferManager && !mSupressBM){
   660         beginRemoveRows(parent, start, end);
   649         beginRemoveRows(parent, start, end);
   661 //        mBufferManager->aboutToRemoveItems(start, end);    
   650         for ( int i=start; i <=end; i++){
       
   651             mBufferManager->aboutToRemoveItem(i);
       
   652         }
   662     }
   653     }
   663     TX_EXIT
   654     TX_EXIT
   664 }
   655 }
   665 
   656 
   666 void HgCacheProxyModel::sourceRowsInserted( const QModelIndex & parent, int start, int end )
   657 void HgCacheProxyModel::sourceRowsInserted( const QModelIndex & parent, int start, int end )
   667 {
   658 {
   668     TX_ENTRY
   659     TX_ENTRY
   669     Q_UNUSED(parent);
   660     Q_UNUSED(parent);
   670     Q_UNUSED(end);
   661     Q_UNUSED(end);
   671     if (mBufferManager && !mSupressBM){
   662     if (mBufferManager && !mSupressBM){
   672         mBufferManager->itemCountChanged(start, false, count());
   663         for ( int i=start; i <=end; i++){
       
   664             mBufferManager->insertedItem(i);
       
   665         }
   673         endInsertRows();
   666         endInsertRows();
   674     }
   667     }
   675     TX_EXIT    
   668     TX_EXIT    
   676 }
   669 }
   677 
   670 
   692 {
   685 {
   693     TX_ENTRY
   686     TX_ENTRY
   694     Q_UNUSED(parent);
   687     Q_UNUSED(parent);
   695     Q_UNUSED(end);
   688     Q_UNUSED(end);
   696     if (mBufferManager && !mSupressBM){
   689     if (mBufferManager && !mSupressBM){
   697         mBufferManager->itemCountChanged(start, true, count());
   690         for ( int i=start; i <=end; i++){
       
   691             mBufferManager->removedItem(i);
       
   692         }
   698         endRemoveRows();
   693         endRemoveRows();
   699     }
   694     }
   700     TX_EXIT
   695     TX_EXIT
   701 }
   696 }
   702 
   697 
   711         end = begin;
   706         end = begin;
   712     } else {
   707     } else {
   713         end = index(mapFromDataProviderIndex(to),0);
   708         end = index(mapFromDataProviderIndex(to),0);
   714     }
   709     }
   715     
   710     
   716     if (begin.isValid() && end.isValid() && !mSupressBM)
   711     if (begin.isValid() && end.isValid() && !mSupressBM){
   717         emit dataChanged(begin, end );
   712         emit dataChanged(begin, end );
       
   713     }
   718 }
   714 }
   719 
   715 
   720 //eof
   716 //eof