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


C++ QStandardItemModel::insertRow方法代码示例

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


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

示例1: QDialog

FilterDlgImpl::FilterDlgImpl(QWidget* parent)
    : QDialog(parent)
{
    _setupUi();
	
    m_query->setRootIsDecorated(false);
    m_query->setSelectionMode(QAbstractItemView::NoSelection);
	
	QStandardItemModel *model = new QStandardItemModel(0, 5, this);

	model->setHeaderData(0, Qt::Horizontal, QObject::tr("Column"));
	model->setHeaderData(1, Qt::Horizontal, QObject::tr("Condition1"));
	model->setHeaderData(2, Qt::Horizontal, QObject::tr("Pattern1"));
	model->setHeaderData(3, Qt::Horizontal, QObject::tr("Condition2"));
	model->setHeaderData(4, Qt::Horizontal, QObject::tr("Pattern2"));
	
	model->insertRow(0);
	model->insertRow(1);
	model->insertRow(2);
	model->setData(model->index(0, 0), tr("Date"));
	model->setData(model->index(0, 1), "=");
	model->setData(model->index(1, 0), tr("Count"));
	model->setData(model->index(1, 1), "=");
	model->setData(model->index(2, 0), tr("Description"));
		
    m_query->setModel(model);
		
    setMinimumSize(680,100);
}
开发者ID:Iownnoname,项目名称:qt,代码行数:29,代码来源:filterdlgimpl.cpp

示例2: on_mMoveUpToolButton_clicked

void QgsComposerLegendWidget::on_mMoveUpToolButton_clicked()
{
  if ( !mLegend )
  {
    return;
  }

  QStandardItemModel* itemModel = qobject_cast<QStandardItemModel *>( mItemTreeView->model() );
  if ( !itemModel )
  {
    return;
  }

  QModelIndex currentIndex = mItemTreeView->currentIndex();
  if ( !currentIndex.isValid() )
  {
    return;
  }

  mLegend->beginCommand( "Moved legend item up" );
  //is there an older sibling?
  int row = currentIndex.row();
  QModelIndex olderSibling = currentIndex.sibling( row - 1, 0 );

  if ( !olderSibling.isValid() )
  {
    return;
  }

  QModelIndex parentIndex = currentIndex.parent();
  QList<QStandardItem*> itemToMove;
  QList<QStandardItem*> olderSiblingItem;

  if ( !parentIndex.isValid() ) //move toplevel item
  {
    itemToMove = itemModel->takeRow( row );
    olderSiblingItem = itemModel->takeRow( row - 1 );
    itemModel->insertRow( row - 1, itemToMove );
    itemModel->insertRow( row, olderSiblingItem );

  }
  else //move classification items
  {
    QStandardItem* parentItem = itemModel->itemFromIndex( parentIndex );
    itemToMove = parentItem->takeRow( row );
    olderSiblingItem = parentItem->takeRow( row - 1 );
    parentItem->insertRow( row - 1, itemToMove );
    parentItem->insertRow( row, olderSiblingItem );
  }

  mItemTreeView->setCurrentIndex( itemModel->indexFromItem( itemToMove.at( 0 ) ) );
  mLegend->update();
  mLegend->endCommand();
}
开发者ID:hCivil,项目名称:Quantum-GIS,代码行数:54,代码来源:qgscomposerlegendwidget.cpp

示例3: on_mMoveDownPushButton_clicked

void QgsComposerLegendWidget::on_mMoveDownPushButton_clicked()
{
  QStandardItemModel* itemModel = dynamic_cast<QStandardItemModel*>( mItemTreeView->model() );
  if ( !itemModel )
  {
    return;
  }

  QModelIndex currentIndex = mItemTreeView->currentIndex();
  if ( !currentIndex.isValid() )
  {
    return;
  }

  //is there an older sibling?
  int row = currentIndex.row();
  QModelIndex youngerSibling = currentIndex.sibling( row + 1, 0 );

  if ( !youngerSibling.isValid() )
  {
    return;
  }

  QModelIndex parentIndex = currentIndex.parent();
  QList<QStandardItem*> itemToMove;
  QList<QStandardItem*> youngerSiblingItem;

  if ( !parentIndex.isValid() ) //move toplevel (layer) item
  {
    youngerSiblingItem = itemModel->takeRow( row + 1 );
    itemToMove = itemModel->takeRow( row );
    itemModel->insertRow( row, youngerSiblingItem );
    itemModel->insertRow( row + 1, itemToMove );
  }
  else //move child (classification) item
  {
    QStandardItem* parentItem = itemModel->itemFromIndex( parentIndex );
    youngerSiblingItem = parentItem->takeRow( row + 1 );
    itemToMove = parentItem->takeRow( row );
    parentItem->insertRow( row, youngerSiblingItem );
    parentItem->insertRow( row + 1, itemToMove );
  }

  mItemTreeView->setCurrentIndex( itemModel->indexFromItem( itemToMove.at( 0 ) ) );
  if ( mLegend )
  {
    mLegend->update();
  }
}
开发者ID:HydroCouple,项目名称:FVHMComponent,代码行数:49,代码来源:qgscomposerlegendwidget.cpp

示例4: PopulateGameAssetsTree

void GameObjectSelectAssetDialog::PopulateGameAssetsTree(GameContentType gameContentType)
{
	AEAssert(m_GameAssetManager != nullptr);

	if(m_GameAssetManager == nullptr)
	{
		return;
	}

	QStandardItemModel* standardModel = reinterpret_cast<QStandardItemModel*>(m_StringProxyFilterModel->sourceModel());

	standardModel->removeRows(0, standardModel->rowCount());

	const GameAssetMap& gameAssetMap = m_GameAssetManager->GetGameAssetMap();

	for (auto gameAssetIt : gameAssetMap)
	{
		GameAsset* gameAsset = gameAssetIt.second;

		if(gameAsset->GetGameContentType() == gameContentType)
		{
			standardModel->insertRow(0);
			standardModel->setData(standardModel->index(0, 0), QString::fromStdWString(gameAsset->GetName()), Qt::ItemDataRole::DisplayRole);
			standardModel->setData(standardModel->index(0, 0), gameAsset->GetUniqueAssetID(), AE_QT_ITEM_DATA_ROLE_GAME_ASSET_UNIQUE_ID);
		}
	}
}
开发者ID:dtbinh,项目名称:Arenal-Engine,代码行数:27,代码来源:GameObjectSelectAssetDialog.cpp

示例5: loadScore

void MainWindow::loadScore()
{
    //QMessageBox::information(0, "wer", "wer");
    ui->tableView->reset();

    QStandardItemModel *model = new QStandardItemModel();

    QList< QList<QStandardItem *> > list = user->scoreDetail();

    for (int i = 0; i < list.count(); i++)
    {
        model->insertRow(i, list.at(i));
        qDebug() << list.at(i).at(1)->text();
    }

    model->setHeaderData(0, Qt::Horizontal, QObject::tr("Course Name"));
    model->setHeaderData(1, Qt::Horizontal, QObject::tr("Middleterm Score"));
    model->setHeaderData(2, Qt::Horizontal, QObject::tr("Final Score"));

    for (int i = 0; i < model->rowCount(); i++)
        for (int j = 0; j < model->columnCount(); j++)
            model->item(i,j)->setEditable(false);

    ui->tableView->setModel(model);

    ui->tableView->horizontalHeader()->setResizeMode(0, QHeaderView::Stretch);
    ui->tableView->resizeColumnToContents(1);
    ui->tableView->resizeColumnToContents(2);
//    ui->tableView->setColumnWidth(2, 100);
//    ui->tableView->setColumnWidth(3, 100);
    ui->tableView->verticalHeader()->hide();
    ui->tableView->setSelectionMode(QAbstractItemView::NoSelection);

}
开发者ID:hkd0518,项目名称:StudentMan,代码行数:34,代码来源:mainwindow.cpp

示例6: moveSelectedItem

void Ui_pluginManagerWindow::moveSelectedItem(bool up)
{
	const int sourceRow = ui.pluginTableView->selectionModel()->currentIndex().row();
	const int destRow = (up ? sourceRow - 1 : sourceRow);

	QStandardItemModel *model = (QStandardItemModel*)ui.pluginTableView->model();
	QList<QStandardItem*> sourceItems = model->takeRow(sourceRow);
	QList<QStandardItem*> destItems = model->takeRow(destRow);

	model->insertRow(destRow, sourceItems);
	model->insertRow(sourceRow, destItems);

	ui.pluginTableView->selectRow(up ? destRow : sourceRow + 1);
}
开发者ID:BackupTheBerlios,项目名称:avidemux-svn,代码行数:14,代码来源:Q_pluginManager.cpp

示例7: main

int main(int argc, char** argv) {
  QApplication app(argc, argv);

#if GUI
  checkScansDirectoryExists();

  MainWindow window;
  window.show();
#endif

#if PIE
  QStandardItemModel* model = new QStandardItemModel(0, 2);
  model->setHeaderData(0, Qt::Horizontal, "Label");
  model->setHeaderData(1, Qt::Horizontal, "Quantity");

  QDir scanDirectory("/home/valentin/Images/Scans");
  QStringList mangasList = scanDirectory.entryList(QDir::Dirs | QDir::NoDotAndDotDot);

  int row = 0;
  for (const QString& manga: mangasList) {
    model->insertRow(row, QModelIndex());

    QDir mangaDirectory(scanDirectory.path()+"/"+manga);
    QString nbChapters = QString::number(mangaDirectory.entryList(QDir::Dirs | QDir::NoDotAndDotDot).size());

    int r = (16*(row+1))%256;
    int g = (32*(row+1))%256;
    int b = (64*(row+1))%256;

    model->setData(model->index(row, 0, QModelIndex()), manga);
    model->setData(model->index(row, 1, QModelIndex()), nbChapters);
    model->setData(model->index(row, 0, QModelIndex()), QColor(r, g, b), Qt::DecorationRole);

    row++;
  }

  PieView* view = new PieView;
  //QTableView* view = new QTableView;
  view->setModel(model);

  //QHeaderView* headerView = view->horizontalHeader();
  //headerView->setStretchLastSection(true);

  view->show();
#endif

  return app.exec();
}
开发者ID:vmichele,项目名称:MangaReaderForLinux,代码行数:48,代码来源:main.cpp

示例8: addMessage

void CMessageDock::addMessage(const QUuid& uuid, int lineNo, CategoryType category, const QString& description)
{
	QString iconPath, categoryName;
	switch(category)
	{
	case InfomationCategory:
		iconPath     = ":/images/tango/small/dialog-information.png";
		categoryName = tr("Information");
		m_countOfInfomationMessages++;
		break;
	case WarningCategory:
		iconPath     = ":/images/icons/small/software-update-urgent-yellow.png";
		categoryName = tr("Warning");
		m_countOfWarningMessages++;
		break;
	case ErrorCategory:
		iconPath     = ":/images/tango/small/dialog-error.png";
		categoryName = tr("Error");
		m_countOfErrorMessages++;
		break;
	default:
		break;
	}

	QStandardItemModel* model
		= static_cast<QStandardItemModel*>(
			static_cast<QSortFilterProxyModel*>(m_listWidget->model())->sourceModel()) ;
	int row = model->rowCount();
	model->insertRow(row);
	if( !iconPath.isEmpty() ) {
		model->setData(model->index(row, CategoryColumn   ), QIcon(iconPath), Qt::DecorationRole);
		model->setData(model->index(row, CategoryColumn   ), categoryName);
	}
	model->setData(model->index(row, RefIndexColumn   ), m_messages.size(), Qt::UserRole + 1);
	model->setData(model->index(row, DescriptionColumn), description);
	model->setData(model->index(row, FileNameColumn   ), theFile->fileName(uuid));
	model->setData(model->index(row, LineNoColumn     ), 0 < lineNo ? QString("%1").arg(lineNo) : "");
	model->setData(model->index(row, LineNoColumn     ), Qt::AlignRight, Qt::TextAlignmentRole);

	MessageInfoType info;
	info.description= description;
	info.category	= category;
	info.uuid		= uuid;
	info.lineNo		= lineNo;
	m_messages.push_back(info);

	updateMessagesCount();
}
开发者ID:sharkpp,项目名称:hspide,代码行数:48,代码来源:messagedock.cpp

示例9: testItemAddBeginning

    void testItemAddBeginning() {
        QStandardItemModel smallerModel;

        PaginateModel pm;
        new ModelTest(&pm, &pm);
        pm.setSourceModel(&smallerModel);
        pm.setPageSize(5);
        QCOMPARE(pm.pageCount(), 1);
        QCOMPARE(pm.rowCount(), 0);
        smallerModel.insertRow(0, new QStandardItem(QStringLiteral("just one")));
        QCOMPARE(pm.pageCount(), 1);
        QCOMPARE(pm.rowCount(), 1);
        smallerModel.removeRow(0);
        QCOMPARE(pm.pageCount(), 1);
        QCOMPARE(pm.rowCount(), 0);
    }
开发者ID:KDE,项目名称:discover,代码行数:16,代码来源:PaginateModelTest.cpp

示例10: openProject

void MainWindow::openProject()
{
  const QString sfm_data_fileName = QFileDialog::getOpenFileName(this, tr("Choose a sfm_data project file"),
    QString::null, tr("sfm_data (*.json *.xml *.bin)"));
  if (sfm_data_fileName.isEmpty())
    return;

  m_sfm_data_filename = sfm_data_fileName.toStdString();

  if (m_doc.loadData(sfm_data_fileName.toStdString()))
  {
    //Add image names in the QT tree view
    {
      QStandardItemModel * model = new QStandardItemModel(0,1, this);
      model->setHeaderData(0, Qt::Horizontal, QObject::tr("Views"));
      m_treeView_Images->setModel(model);

      for (Views::const_reverse_iterator iterV = m_doc._sfm_data.GetViews().rbegin();
        iterV != m_doc._sfm_data.GetViews().rend();
        ++iterV)
      {
        const View * view = iterV->second.get();
        if (m_doc._sfm_data.IsPoseAndIntrinsicDefined(view))
        {
          std::ostringstream os;
          os << view->id_view << " " << view->s_Img_path;
          model->insertRow(0);
          model->setData(model->index(0, 0), QString::fromStdString(os.str()));
        }
      }
    }
  }
  else
  {
    QMessageBox msgBox;
    msgBox.setText("Cannot open the provided sfm_data file.");
    msgBox.exec();
  }
}
开发者ID:DirSch,项目名称:openMVG,代码行数:39,代码来源:mainLayout.cpp

示例11: loadElective

void MainWindow::loadElective()
{
    //QMessageBox::information(0, "User", "Elective");
    ui->tableView->reset();

    QStandardItemModel *model = new QStandardItemModel();
    //MyStandardItemModel *model = new MyStandardItemModel();
    MyItemDelegate *delegate = new MyItemDelegate();

    connect(model, SIGNAL(itemChanged(QStandardItem*)), this, SLOT(saveElectiveChange(QStandardItem*)));

    QList< QList<QStandardItem *> > list = user->electiveDetail();

    for (int i = 0; i < list.count(); i++)
    {
        model->insertRow(i, list.at(i));
        qDebug() << list.at(i).at(1)->text();
    }

    model->setHeaderData(0, Qt::Horizontal, QObject::tr("Status"));
    model->setHeaderData(1, Qt::Horizontal, QObject::tr("Course ID"));
    model->setHeaderData(2, Qt::Horizontal, QObject::tr("Course Name"));
    model->setHeaderData(3, Qt::Horizontal, QObject::tr("Teacher ID"));
    model->setHeaderData(4, Qt::Horizontal, QObject::tr("Teacher Name"));
    model->setHeaderData(5, Qt::Horizontal, QObject::tr("Course Addr."));

    ui->tableView->setModel(model);
    //ui->tableView->setItemDelegate(delegate);

    for (int i = 0; i < model->columnCount(); i++)
        ui->tableView->horizontalHeader()->setResizeMode(i, QHeaderView::Stretch);
    //ui->tableView->horizontalHeader()->setResizeMode(0, QHeaderView::Stretch);
    ui->tableView->resizeColumnToContents(1);
    ui->tableView->resizeColumnToContents(2);
//    ui->tableView->setColumnWidth(2, 100);
//    ui->tableView->setColumnWidth(3, 100);
    ui->tableView->verticalHeader()->hide();
    ui->tableView->setSelectionMode(QAbstractItemView::NoSelection);
}
开发者ID:hkd0518,项目名称:StudentMan,代码行数:39,代码来源:mainwindow.cpp

示例12: driveClicked

void FMPanel::driveClicked( const QModelIndex &index )
{
    const QStandardItemModel* model = qobject_cast<const QStandardItemModel*>( index.model() );
    if( model == NULL )
        return;
    QStandardItem* item = model->itemFromIndex(index);
#ifdef Q_WS_MAC
    QString path( item->whatsThis() );
#else
    QString path( item->text() );
#endif
    QDir dir( path );
    currentFile.clear();
    if( dir.entryInfoList().count()!=0 )
    {
        lastClick = QTime::currentTime ();
        currentDir.clear();
        currentDir.append( path );
        dirList->setRootPath( currentDir );
        setPathEditText( currentDir );
        driveJustLoaded = true;
        noDrive = false;
    }
    else
    {
        //TODO: check this out on win
        QStandardItemModel* model = new QStandardItemModel( 1, 1 );
        QStandardItem* empty = new QStandardItem("No drive available.");
        currentDir.clear();
        model->insertRow( 0, empty );
        dirList->setModel( model );
        setPathEditText( "No drive available." );
        noDrive = true;
        mainW->stopAnimation();
    }
    tab->setCurrentIndex(1);
    return;
}
开发者ID:davenmccalla,项目名称:qefem,代码行数:38,代码来源:fmpanel.cpp

示例13: processResults

/** Process results sent back from various search engines (local, remote). */
void SearchDialog::processResults(Request type, const QStandardItemList &results)
{
	QListView *listToProcess = nullptr;
	switch (type) {
	case Artist:
		listToProcess = _artists;
		break;
	case Album:
		listToProcess = _albums;
		break;
	case Track:
		listToProcess = _tracks;
		break;
	}
	QStandardItemModel *m = qobject_cast<QStandardItemModel*>(listToProcess->model());
	for (int i = 0; i < results.size(); i++) {
		m->insertRow(0, results.at(i));
	}
	m->sort(0);
	listToProcess->setFixedHeight(listToProcess->model()->rowCount() * listToProcess->sizeHintForRow(0));
	qDebug() << "number of items" << listToProcess->model()->rowCount();
	qDebug() << "size h f r 1" << _artists->sizeHintForRow(0) << _albums->sizeHintForRow(0) << _tracks->sizeHintForRow(0);
	qDebug() << "size h f r 2" << iconArtists->height() << iconAlbums->height() << iconTracks->height();
	int ar = qMax(_artists->model()->rowCount() * _artists->sizeHintForRow(0), iconArtists->height());
	int al = qMax(_albums->model()->rowCount() * _albums->sizeHintForRow(0), iconAlbums->height());
	int tr = qMax(_tracks->model()->rowCount() * _tracks->sizeHintForRow(0), iconTracks->height());
	artistLayoutWidget->setFixedHeight(ar);
	albumLayoutWidget->setFixedHeight(al);
	trackLayoutWidget->setFixedHeight(tr);
	qDebug() << "ar al tr" << ar << al << tr;

	int h = ar + al + tr;
	//int h = 300;
	h += labelSearchMore->height() + aggregated->height() + 3;
	int minW = qMax(iconArtists->width() + _artists->sizeHintForColumn(0), 400);
	this->resize(minW, h);
}
开发者ID:MBach,项目名称:Miam-Player,代码行数:38,代码来源:searchdialog.cpp

示例14: showLinks

void KGetLinkView::showLinks( const QList<QString>& links )
{
    QStandardItemModel *model = new QStandardItemModel(0, 5, this);

    model->setHeaderData(0, Qt::Horizontal, i18n("Auxiliary header"));
    model->setHeaderData(1, Qt::Horizontal, i18n("File Name"));
    model->setHeaderData(2, Qt::Horizontal, i18n("Description"));
    model->setHeaderData(3, Qt::Horizontal, i18nc("list header: type of file", "File Type"));
    model->setHeaderData(4, Qt::Horizontal, i18n("Location (URL)"));

    foreach (const QString &linkitem, links)
    {
        KUrl url(linkitem);
        QString file = url.fileName();
        if (file.isEmpty())
        {
            file = QString(url.host());
        }

        KMimeType::Ptr mt = KMimeType::findByUrl(linkitem, 0, true, true);

        QList<QStandardItem*> items;

        QStandardItem *item = new QStandardItem(file);
        item->setIcon(KIcon(mt->iconName()));
        item->setCheckable(true);
        item->setData(QVariant(url.fileName()), Qt::DisplayRole);
        item->setData(QVariant(mt->name()), Qt::UserRole); // used for filtering DownloadFilterType

        items << new QStandardItem(QString::number(model->rowCount()));
        items << item;
        items << new QStandardItem();
        items << new QStandardItem(mt->comment());
        items << new QStandardItem(url.prettyUrl());

        model->insertRow(model->rowCount(), items);
    }
开发者ID:mfuchs,项目名称:kget-gsoc,代码行数:37,代码来源:kget_linkview.cpp

示例15: 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


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