Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 7th, 2012  |  syntax: None  |  size: 1.48 KB  |  hits: 9  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. QSortFilterProxyModel with QStandardItemModel after appendRow are not working
  2. [PERIOD 1]
  3.    [CHILD 1]
  4.    [CHILD 2]
  5.       [SUBCHILD 2.1]
  6.       ...
  7.    [CHILD N]
  8. [PERIOD 2]
  9. ...
  10. [PERIOD N]
  11.        
  12. MainView::MainView( QWidget* parent /* = 0 */ ) : QTreeView( parent )
  13. {
  14.      if( !model_ )
  15.      {
  16.           model_ = new MainModel( this );
  17.      }
  18.  
  19.      if( !proxy_ )
  20.      {
  21.           proxy_ = new MainFilterProxyModel( this );
  22.           proxy_->setDynamicSortFilter( true );
  23.           proxy_->setSourceModel( model_ );
  24.  
  25.           setModel( proxy_ );
  26.      }
  27. }
  28.        
  29. void MainModel::addRow( const DocumentPtr& document, QStandardItem* parentItem )
  30. {
  31.      assert( document );
  32.  
  33.      QList< QStandardItem* > items;
  34.      items << ( new QStandardItem );
  35.      items << ( new QStandardItem );
  36.      items << ( new QStandardItem );
  37.      items << ( new QStandardItem );
  38.      items << ( new QStandardItem );
  39.      items << ( new QStandardItem );
  40.      items << ( new QStandardItem );
  41.  
  42.      updateRow( document, items );
  43.  
  44.      if( !parentItem )
  45.      {
  46.           BOOST_FOREACH( const TimePeriod& period, TimePeriod::all() )
  47.           {
  48.                if( period.contains( QDateTime::fromTime_t( document->creationDate() ) ) )
  49.                {
  50.                     QStandardItem* periodItem = itemByPeriod( period );
  51.                     Q_ASSERT( periodItem );
  52.  
  53.                     periodItem->appendRow( items );
  54.  
  55.                     break;
  56.                }
  57.           }
  58.      }
  59.      else
  60.      {
  61.           parentItem->appendRow( items );
  62.      }
  63. }