本文整理汇总了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 );
}
示例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
}
示例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);
}
}
}
}
示例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();
}
示例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 );
//.........这里部分代码省略.........
示例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 );
}