当前位置: 首页>>代码示例>>C++>>正文


C++ QSortFilterProxyModel::rowCount方法代码示例

本文整理汇总了C++中QSortFilterProxyModel::rowCount方法的典型用法代码示例。如果您正苦于以下问题:C++ QSortFilterProxyModel::rowCount方法的具体用法?C++ QSortFilterProxyModel::rowCount怎么用?C++ QSortFilterProxyModel::rowCount使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在QSortFilterProxyModel的用法示例。


在下文中一共展示了QSortFilterProxyModel::rowCount方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: testChangeWithProxyModel

void TestProjectModel::testChangeWithProxyModel()
{
    QSortFilterProxyModel* proxy = new QSortFilterProxyModel( this );
    proxy->setSourceModel( model );
    ProjectFolderItem* root = new ProjectFolderItem( nullptr, Path(QUrl::fromLocalFile(QStringLiteral("/folder1"))) );
    root->appendRow( new ProjectFileItem( nullptr, Path(QUrl::fromLocalFile(QStringLiteral("/folder1/file1"))) ) );
    model->appendRow( root );

    QCOMPARE( model->rowCount(), 1 );
    QCOMPARE( proxy->rowCount(), 1 );

    model->removeRow( 0 );

    QCOMPARE( model->rowCount(), 0 );
    QCOMPARE( proxy->rowCount(), 0 );
}
开发者ID:KDE,项目名称:kdevplatform,代码行数:16,代码来源:test_projectmodel.cpp

示例2: setDefaultEngine

void FilterOptions::setDefaultEngine(int index)
{
  QSortFilterProxyModel* proxy = qobject_cast<QSortFilterProxyModel*>(m_dlg.cmbDefaultEngine->model());
  if (index == -1)
    index = proxy->rowCount()-1;//"None" is the last

  const QModelIndex modelIndex = proxy->mapFromSource(proxy->sourceModel()->index(index,0));
  m_dlg.cmbDefaultEngine->setCurrentIndex(modelIndex.row());
  m_dlg.cmbDefaultEngine->view()->setCurrentIndex(modelIndex);  //TODO: remove this when Qt bug is fixed
}
开发者ID:emmanuel099,项目名称:kio,代码行数:10,代码来源:ikwsopts.cpp

示例3: selectRow

void ModelDescriptorListWidget::selectRow(int row)
{
    QModelIndex rootIndex = this->rootIndex();
    if(rootIndex.isValid()) {
        QItemSelectionModel *selectionModel = this->selectionModel();
        QSortFilterProxyModel *proxyModel = this->proxyModel();
        if(row < proxyModel->rowCount(rootIndex)) {
            selectionModel->clear();
            QModelIndex index = proxyModel->index(row, 0, rootIndex);
            if(index.isValid()) {
                selectionModel->setCurrentIndex(index, QItemSelectionModel::SelectCurrent);
            }
        }
    }
}
开发者ID:OpenSpeedShop,项目名称:gui,代码行数:15,代码来源:ModelDescriptorListWidget.cpp

示例4: setExperimentType

void ModelDescriptorListWidget::setExperimentType(const QString &experimentType)
{
    //NOTE: QAbstractItemModel::match() seems to search children, we only want root level items searched!
    QSortFilterProxyModel *proxyModel = qobject_cast<QSortFilterProxyModel *>(QTreeView::model());

    if(!experimentType.isEmpty()) {
        for(int row=0; row < proxyModel->rowCount(QModelIndex()); row++) {
            QModelIndex index = proxyModel->index(row, 0, QModelIndex());
            if(!index.data(Qt::DisplayRole).toString().compare(experimentType, Qt::CaseInsensitive)) {
                setRootIndex(index);
                setRootIsDecorated(false);
                return;
            }
        }
    }

    setRootIndex(QModelIndex());
    setRootIsDecorated(true);
    expandAll();
}
开发者ID:OpenSpeedShop,项目名称:gui,代码行数:20,代码来源:ModelDescriptorListWidget.cpp

示例5: testInsertRemoveGrandChildren

void FlatProxyModelTester::testInsertRemoveGrandChildren()
{
    QSortFilterProxyModel sf;
    FlatProxyModel fm;
    QStandardItemModel sm;

    sf.setSourceModel( &fm );
    fm.setSourceModel( &sm );

    sm.setHeaderData( 0, Qt::Horizontal, "Column 0" );
    QCOMPARE( sm.rowCount(), 0 );

    QStandardItem *pitem = new QStandardItem( "Parent" );
    sm.insertRow( 0, pitem );
    QCOMPARE( sm.rowCount(), 1 );
    QCOMPARE( fm.rowCount(), 1 );
    QCOMPARE( sf.rowCount(), 1 );
    QCOMPARE( sm.index( 0, 0 ).data(), sf.index( 0, 0 ).data() );
    QCOMPARE( sf.index( 0, 0 ).data(), QVariant( "Parent" ) );

    QModelIndex grandparent = sm.index( 0, 0 );
    QVERIFY( grandparent.isValid() );

    QStandardItem *gitem = new QStandardItem( "First child" );
    pitem->insertRow( 0, gitem );
    QCOMPARE( sm.rowCount( grandparent ), 1 );
    QCOMPARE( fm.rowCount(), 2 );
    QCOMPARE( sf.rowCount(), 2 );
    QCOMPARE( sm.index( 0, 0, grandparent ).data(), sf.index( 1, 0 ).data() );
    QCOMPARE( sf.index( 1, 0 ).data(), QVariant( "First child" ) );

    QModelIndex parent = sm.index( 0, 0, grandparent );
    QVERIFY( parent.isValid() );

    QStandardItem *item = new QStandardItem( "First grandchild" );
    gitem->insertRow( 0, item );
    QCOMPARE( sm.rowCount( parent ), 1 );
    QCOMPARE( fm.rowCount(), 3 );
    QCOMPARE( sf.rowCount(), 3 );
    QCOMPARE( sm.index( 0, 0, parent ).data(), sf.index( 2, 0 ).data() );
    QCOMPARE( sf.index( 2, 0 ).data(), QVariant( "First grandchild" ) );

    item = new QStandardItem( "Second grandchild" );
    gitem->insertRow( 1, item );
    QCOMPARE( sm.rowCount( parent ), 2 );
    QCOMPARE( fm.rowCount(), 4 );
    QCOMPARE( sf.rowCount(), 4 );
    QCOMPARE( sm.index( 0, 0, parent ).data(), sf.index( 2, 0 ).data() );
    QCOMPARE( sm.index( 1, 0, parent ).data(), sf.index( 3, 0 ).data() );
    QCOMPARE( sf.index( 2, 0 ).data(), QVariant( "First grandchild" ) );
    QCOMPARE( sf.index( 3, 0 ).data(), QVariant( "Second grandchild" ) );

    item = new QStandardItem( "In between" );
    gitem->insertRow( 1, item );
    QCOMPARE( sm.rowCount( parent ), 3 );
    QCOMPARE( fm.rowCount(), 5 );
    QCOMPARE( sf.rowCount(), 5 );
    QCOMPARE( sm.index( 0, 0, parent ).data(), sf.index( 2, 0 ).data() );
    QCOMPARE( sm.index( 1, 0, parent ).data(), sf.index( 3, 0 ).data() );
    QCOMPARE( sm.index( 2, 0, parent ).data(), sf.index( 4, 0 ).data() );
    QCOMPARE( sf.index( 2, 0 ).data(), QVariant( "First grandchild" ) );
    QCOMPARE( sf.index( 3, 0 ).data(), QVariant( "In between" ) );
    QCOMPARE( sf.index( 4, 0 ).data(), QVariant( "Second grandchild" ) );

    item = new QStandardItem( "Before first" );
    gitem->insertRow( 0, item );
    QCOMPARE( sm.rowCount( parent ), 4 );
    QCOMPARE( fm.rowCount(), 6 );
    QCOMPARE( sf.rowCount(), 6 );
    QCOMPARE( sm.index( 0, 0, parent ).data(), sf.index( 2, 0 ).data() );
    QCOMPARE( sm.index( 1, 0, parent ).data(), sf.index( 3, 0 ).data() );
    QCOMPARE( sm.index( 2, 0, parent ).data(), sf.index( 4, 0 ).data() );
    QCOMPARE( sm.index( 3, 0, parent ).data(), sf.index( 5, 0 ).data() );
    QCOMPARE( sf.index( 2, 0 ).data(), QVariant( "Before first" ) );
    QCOMPARE( sf.index( 3, 0 ).data(), QVariant( "First grandchild" ) );
    QCOMPARE( sf.index( 4, 0 ).data(), QVariant( "In between" ) );
    QCOMPARE( sf.index( 5, 0 ).data(), QVariant( "Second grandchild" ) );

    sm.removeRow( 0, parent );
    QCOMPARE( sm.rowCount( parent ), 3 );
    QCOMPARE( fm.rowCount(), 5 );
    QCOMPARE( sf.rowCount(), 5 );
    QCOMPARE( sm.index( 0, 0, parent ).data(), sf.index( 2, 0 ).data() );
    QCOMPARE( sm.index( 1, 0, parent ).data(), sf.index( 3, 0 ).data() );
    QCOMPARE( sm.index( 2, 0, parent ).data(), sf.index( 4, 0 ).data() );
    QCOMPARE( sf.index( 2, 0 ).data(), QVariant( "First grandchild" ) );
    QCOMPARE( sf.index( 3, 0 ).data(), QVariant( "In between" ) );
    QCOMPARE( sf.index( 4, 0 ).data(), QVariant( "Second grandchild" ) );

    sm.removeRow( 1, parent );
    QCOMPARE( sm.rowCount( parent ), 2 );
    QCOMPARE( fm.rowCount(), 4 );
    QCOMPARE( sf.rowCount(), 4 );
    QCOMPARE( sm.index( 0, 0, parent ).data(), sf.index( 2, 0 ).data() );
    QCOMPARE( sm.index( 1, 0, parent ).data(), sf.index( 3, 0 ).data() );
    QCOMPARE( sf.index( 2, 0 ).data(), QVariant( "First grandchild" ) );
    QCOMPARE( sf.index( 3, 0 ).data(), QVariant( "Second grandchild" ) );

    sm.removeRow( 1, parent );
    QCOMPARE( sm.rowCount( parent ), 1 );
//.........这里部分代码省略.........
开发者ID:abhishekmurthy,项目名称:Calligra,代码行数:101,代码来源:FlatProxyModelTester.cpp

示例6: testInsertRemoveTop

void FlatProxyModelTester::testInsertRemoveTop()
{
    QSortFilterProxyModel sf;
    FlatProxyModel fm;
    QStandardItemModel sm;

    sf.setSourceModel( &fm );
    fm.setSourceModel( &sm );

    sm.setHeaderData( 0, Qt::Horizontal, "Column 0" );
    QCOMPARE( sm.rowCount(), 0 );

    // insert
    sm.insertRow( 0, new QStandardItem( "First" ) );
    QCOMPARE( sm.rowCount(), 1 );
    QCOMPARE( fm.rowCount(), 1 );
    QCOMPARE( sf.rowCount(), 1 );
    QCOMPARE( sm.index( 0, 0 ).data(), sf.index( 0, 0 ).data() );
    QCOMPARE( sf.index( 0, 0 ).data(), QVariant( "First" ) );

    sm.insertRow( 1, new QStandardItem( "Second" ) );
    QCOMPARE( sm.rowCount(), 2 );
    QCOMPARE( fm.rowCount(), 2 );
    QCOMPARE( sf.rowCount(), 2 );
    QCOMPARE( sm.index( 0, 0 ).data(), sf.index( 0, 0 ).data() );
    QCOMPARE( sm.index( 1, 0 ).data(), sf.index( 1, 0 ).data() );
    QCOMPARE( sf.index( 0, 0 ).data(), QVariant( "First" ) );
    QCOMPARE( sf.index( 1, 0 ).data(), QVariant( "Second" ) );

    sm.insertRow( 1, new QStandardItem( "In between" ) );
    QCOMPARE( sm.rowCount(), 3 );
    QCOMPARE( fm.rowCount(), 3 );
    QCOMPARE( sf.rowCount(), 3 );
    QCOMPARE( sm.index( 0, 0 ).data(), sf.index( 0, 0 ).data() );
    QCOMPARE( sm.index( 1, 0 ).data(), sf.index( 1, 0 ).data() );
    QCOMPARE( sm.index( 2, 0 ).data(), sf.index( 2, 0 ).data() );
    QCOMPARE( sf.index( 0, 0 ).data(), QVariant( "First" ) );
    QCOMPARE( sf.index( 1, 0 ).data(), QVariant( "In between" ) );
    QCOMPARE( sf.index( 2, 0 ).data(), QVariant( "Second" ) );

    sm.insertRow( 0, new QStandardItem( "Before first" ) );
    QCOMPARE( sm.rowCount(), 4 );
    QCOMPARE( fm.rowCount(), 4 );
    QCOMPARE( sf.rowCount(), 4 );
    QCOMPARE( sm.index( 0, 0 ).data(), sf.index( 0, 0 ).data() );
    QCOMPARE( sm.index( 1, 0 ).data(), sf.index( 1, 0 ).data() );
    QCOMPARE( sm.index( 2, 0 ).data(), sf.index( 2, 0 ).data() );
    QCOMPARE( sm.index( 3, 0 ).data(), sf.index( 3, 0 ).data() );
    QCOMPARE( sf.index( 0, 0 ).data(), QVariant( "Before first" ) );
    QCOMPARE( sf.index( 1, 0 ).data(), QVariant( "First" ) );
    QCOMPARE( sf.index( 2, 0 ).data(), QVariant( "In between" ) );
    QCOMPARE( sf.index( 3, 0 ).data(), QVariant( "Second" ) );

    // remove
    sm.removeRow( 0 );
    QCOMPARE( sm.rowCount(), 3 );
    QCOMPARE( fm.rowCount(), 3 );
    QCOMPARE( sf.rowCount(), 3 );
    QCOMPARE( sm.index( 0, 0 ).data(), sf.index( 0, 0 ).data() );
    QCOMPARE( sm.index( 1, 0 ).data(), sf.index( 1, 0 ).data() );
    QCOMPARE( sm.index( 2, 0 ).data(), sf.index( 2, 0 ).data() );
    QCOMPARE( sf.index( 0, 0 ).data(), QVariant( "First" ) );
    QCOMPARE( sf.index( 1, 0 ).data(), QVariant( "In between" ) );
    QCOMPARE( sf.index( 2, 0 ).data(), QVariant( "Second" ) );

    sm.removeRow( 1 );
    QCOMPARE( sm.rowCount(), 2 );
    QCOMPARE( fm.rowCount(), 2 );
    QCOMPARE( sf.rowCount(), 2 );
    QCOMPARE( sm.index( 0, 0 ).data(), sf.index( 0, 0 ).data() );
    QCOMPARE( sm.index( 1, 0 ).data(), sf.index( 1, 0 ).data() );
    QCOMPARE( sf.index( 0, 0 ).data(), QVariant( "First" ) );
    QCOMPARE( sf.index( 1, 0 ).data(), QVariant( "Second" ) );

    sm.removeRow( 1 );
    QCOMPARE( sm.rowCount(), 1 );
    QCOMPARE( fm.rowCount(), 1 );
    QCOMPARE( sf.rowCount(), 1 );
    QCOMPARE( sm.index( 0, 0 ).data(), sf.index( 0, 0 ).data() );
    QCOMPARE( sf.index( 0, 0 ).data(), QVariant( "First" ) );

    sm.removeRow( 0 );
    QCOMPARE( sm.rowCount(), 0 );
    QCOMPARE( fm.rowCount(), 0 );
    QCOMPARE( sf.rowCount(), 0 );
}
开发者ID:abhishekmurthy,项目名称:Calligra,代码行数:86,代码来源:FlatProxyModelTester.cpp


注:本文中的QSortFilterProxyModel::rowCount方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。