/*
 *  Implementation of manual recursive filtering for Qt < 5
 *
*/
 
bool MySortFilterProxyModel
::filterAcceptsRow( int sourceRow, 
const QModelIndex & sourceParent 
) const {
#if QT_VERSION < 0x050000
 
      // Qt is less than 5, so manually perform recursion
 
      // Default QSortFilterProxyModel behavior for an empty regexp
      if ( filterRegExp().isEmpty() )
         return true;
 
      QModelIndex index0 
= sourceModel
()->index
( sourceRow, 
0, sourceParent 
);
  
      // If column0 at the current level matches, return true
      if ( sourceModel()->data( index0, Qt::DisplayRole ).toString().contains( filterRegExp() ) )
        return true;
 
      // The current level doesn't match but if it has children, recurse to look at them
      else if ( sourceModel()->hasChildren( index0 ) )
      {
         bool bResult = false;
         int nRows = sourceModel()->rowCount( index0 );
 
         // Look at each child row.  If any one of them matches (bResult == true) then the loop will exit
         for ( int nRow = 0; nRow < nRows && !bResult; ++nRow )
         {
               bResult = filterAcceptsRow( nRow, index0 );
         }
 
         // Return whatever the loop result was.  If any child matches, this is true, otherwise it is false.
         return bResult;
      }
 
      // Otherwise, nothing at this level or below it matches, so the whole subtree is ignored.
      return false;
 
#else
      // Qt version is > 4, so use default implementation
 
#endif
}
        /*
 *  Implementation of manual recursive filtering for Qt < 5
 *
*/
bool MySortFilterProxyModel::filterAcceptsRow( int sourceRow, const QModelIndex & sourceParent ) const
{
#if QT_VERSION < 0x050000
      // Qt is less than 5, so manually perform recursion
      // Default QSortFilterProxyModel behavior for an empty regexp
      if ( filterRegExp().isEmpty() )
         return true;
      QModelIndex index0 = sourceModel()->index( sourceRow, 0, sourceParent );
 
      // If column0 at the current level matches, return true
      if ( sourceModel()->data( index0, Qt::DisplayRole ).toString().contains( filterRegExp() ) )
        return true;
      // The current level doesn't match but if it has children, recurse to look at them
      else if ( sourceModel()->hasChildren( index0 ) )
      {
         bool bResult = false;
         int nRows = sourceModel()->rowCount( index0 );
         // Look at each child row.  If any one of them matches (bResult == true) then the loop will exit
         for ( int nRow = 0; nRow < nRows && !bResult; ++nRow )
         {
               bResult = filterAcceptsRow( nRow, index0 );
         }
         // Return whatever the loop result was.  If any child matches, this is true, otherwise it is false.
         return bResult;
      }
      // Otherwise, nothing at this level or below it matches, so the whole subtree is ignored.
      return false;
#else
      // Qt version is > 4, so use default implementation
      return QSortFilterProxyModel::filterAcceptsRow( sourceRow, sourceParent );
#endif
}
To copy to clipboard, switch view to plain text mode 
  
				
Bookmarks