Bootstrap

qstandarditem:insertrow

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

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

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

示例1: on_mMoveUpToolButton_clicked

▲ 点赞 6 ▼

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

示例2: on_mMoveDownPushButton_clicked

▲ 点赞 5 ▼

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

示例3: openGItem

▲ 点赞 3 ▼

KoRecentDocumentsPane::KoRecentDocumentsPane(QWidget* parent, const KComponentData &_componentData,
        const QString& header)
        : KoDetailsPane(parent, _componentData, header)
        , d(new KoRecentDocumentsPanePrivate)
{
    setFocusProxy(m_documentList);
    KGuiItem openGItem(i18n("Open This Document"), "document-open");
    m_openButton->setGuiItem(openGItem);
    m_alwaysUseCheckBox->hide();

    model()->setSortRole(0); // Disable sorting

    KConfigGroup config(componentData().config(), "RecentFiles");

    int i = 1;
    QString path;
    KFileItemList fileList;
    QStandardItem* rootItem = model()->invisibleRootItem();

    do {
        path = config.readPathEntry(QString("File%1").arg(i), QString());

        if (!path.isEmpty()) {
            QString name = config.readPathEntry(QString("Name%1").arg(i), QString());

            KUrl url(path);

            if (name.isEmpty())
                name = url.fileName();

            if (!url.isLocalFile() || QFile::exists(url.toLocalFile())) {
                KFileItem fileItem(KFileItem::Unknown, KFileItem::Unknown, url);
                fileList.prepend(fileItem);
                //center all icons in 64x64 area
                QImage icon = fileItem.pixmap(64).toImage();
                icon = icon.convertToFormat(QImage::Format_ARGB32);
                icon = icon.copy((icon.width() - 64) / 2, (icon.height() - 64) / 2, 64, 64);
                KoFileListItem* item = new KoFileListItem(QPixmap::fromImage(icon), name);
                item->setEditable(false);
                item->setData(fileItem.pixmap(128), Qt::UserRole);
                item->setFileItem(fileItem);
                rootItem->insertRow(0, item);
            }
        }

        i++;
    } while (!path.isEmpty() || i <= 10);


    //Select the first file
    QModelIndex firstIndex = model()->indexFromItem(model()->item(0));
    m_documentList->selectionModel()->select(firstIndex, QItemSelectionModel::Select);
    m_documentList->selectionModel()->setCurrentIndex(firstIndex, QItemSelectionModel::Select);

    d->m_previewJob = KIO::filePreview(fileList, QSize(200, 200), 0);

    connect(d->m_previewJob, SIGNAL(result(KJob*)), this, SLOT(previewResult(KJob*)));
    connect(d->m_previewJob, SIGNAL(gotPreview(const KFileItem&, const QPixmap&)),
            this, SLOT(updatePreview(const KFileItem&, const QPixmap&)));
}

开发者ID:KDE,项目名称:koffice,代码行数:60,代码来源:KoRecentDocumentsPane.cpp

示例4: headingItem

▲ 点赞 1 ▼

// Returns a heading item with the given text. Will create and add a new heading under \c parentIndex at \c position if no heading with that text exists yet.  (Use -1 for \c position to append at the bottom.) If \c text is empty, will return the top-level (invisible root) item.
QStandardItem* AMWindowPaneModel::headingItem(const QString& text, QModelIndex parentIndex, int position) {
    if(text.isEmpty())
        return invisibleRootItem();

    QList<QStandardItem*> searchItems = this->findItems(text);
    foreach(QStandardItem* i, searchItems) {
        if(isHeading(i->index()))
            return i;
    }

    // Didn't find it... time to make it:
    QStandardItem* newHeading = new QStandardItem(text);
    newHeading->setFlags(Qt::ItemIsEnabled);	// enabled, but should not be selectable
    // graphics defaults:
    QFont font = QFont("Lucida Grande", 10, QFont::Bold);
    font.setCapitalization(QFont::AllUppercase);
    newHeading->setFont(font);
    newHeading->setData(QBrush(QColor::fromRgb(100, 109, 125)), Qt::ForegroundRole);

    QStandardItem* parent = itemFromIndex(parentIndex);
    if(parent) {
        if(position < 0 || position > parent->rowCount())
            position = parent->rowCount();
        parent->insertRow(position, newHeading);
    }
    else {
        if(position < 0 || position > rowCount())
            position = rowCount();
        insertRow(position, newHeading);
    }

    return newHeading;
}

开发者ID:anukat2015,项目名称:acquaman,代码行数:34,代码来源:AMWindowPaneModel.cpp

示例5: AddProgram

▲ 点赞 1 ▼

bool ProgramsModel::AddProgram(int groupNum, QModelIndex &index, int row)
{
    QStandardItem *groupItem = item(groupNum);

    //if the group was disabled re-enable it
    if(groupItem->rowCount()==0) {
        groupItem->setBackground(Qt::transparent);
        groupItem->setToolTip("");
    }

    int progId = myHost->programsModel->GetNextProgId();

    QString name("New prog");

    //create the program item
    QStandardItem *prgItem = new QStandardItem( name );
    prgItem->setData(ProgramNode,NodeType);
    prgItem->setData(progId,ProgramId);
#ifndef QT_NO_DEBUG
    prgItem->setData(progId,Qt::ToolTipRole);
#endif
    prgItem->setDragEnabled(true);
    prgItem->setDropEnabled(false);
    prgItem->setEditable(true);

    if(row==-1)
        row=groupItem->rowCount();
    groupItem->insertRow(row, prgItem);

    index = prgItem->index();

//    ValidateProgChange(index);

    return true;
}

开发者ID:eriser,项目名称:vstboard-1,代码行数:35,代码来源:programsmodel.cpp

示例6: openGItem

▲ 点赞 1 ▼

KoRecentDocumentsPane::KoRecentDocumentsPane(QWidget* parent, const KComponentData &_componentData,
        const QString& header)
        : KoDetailsPane(parent, _componentData, header)
        , d(new KoRecentDocumentsPanePrivate)
{
    setFocusProxy(m_documentList);
    KGuiItem openGItem(i18n("Open This Document"), koIconName("document-open"));
    m_openButton->setGuiItem(openGItem);
    m_alwaysUseCheckBox->hide();

    model()->setSortRole(0); // Disable sorting

    KConfigGroup config(componentData().config(), "RecentFiles");

    int i = 1;
    QString path;
    KFileItemList fileList;
    QStandardItem* rootItem = model()->invisibleRootItem();

    do {
        path = config.readPathEntry(QString("File%1").arg(i), QString());

        if (!path.isEmpty()) {
            QString name = config.readPathEntry(QString("Name%1").arg(i), QString());

            QUrl url(path);

            if (name.isEmpty())
                name = url.fileName();

            if (!url.isLocalFile() || QFile::exists(url.toLocalFile())) {
                KFileItem fileItem(KFileItem::Unknown, KFileItem::Unknown, url);
                fileList.prepend(fileItem);
                const QIcon icon = QIcon::fromTheme(fileItem.iconName());
                KoFileListItem* item = new KoFileListItem(icon, name, fileItem);
                item->setEditable(false);
                rootItem->insertRow(0, item);
            }
        }

        i++;
    } while (!path.isEmpty() || i <= 10);


    //Select the first file
    QModelIndex firstIndex = model()->indexFromItem(model()->item(0));
    m_documentList->selectionModel()->select(firstIndex, QItemSelectionModel::Select);
    m_documentList->selectionModel()->setCurrentIndex(firstIndex, QItemSelectionModel::Select);

    QStringList availablePlugins = KIO::PreviewJob::availablePlugins();
    KIO::PreviewJob *previewJob = KIO::filePreview(fileList, QSize(IconExtent, IconExtent), &availablePlugins);

    d->m_previewJobs.append(previewJob);
    connect(previewJob, SIGNAL(result(KJob*)), SLOT(previewResult(KJob*)));
    connect(previewJob, SIGNAL(gotPreview(KFileItem,QPixmap)),
            SLOT(updateIcon(KFileItem,QPixmap)));
}

开发者ID:TheTypoMaster,项目名称:calligra,代码行数:57,代码来源:KoRecentDocumentsPane.cpp

示例7: updateItemRowOrder

▲ 点赞 1 ▼

/**
  Updates the sibling position of the item, depending on the position in the model.
  */
void NavigatorTreeModel::updateItemRowOrder(const ModelNode &node)
{
    if (!containsNode(node))
        return;

    ItemRow itemRow = itemRowForNode(node);
    int currentRow = itemRow.idItem->row();
    int newRow = currentRow;
    if (node.parentProperty().parentModelNode().isValid())
        newRow = modelNodeChildren(node.parentProperty().parentModelNode()).indexOf(node);
    Q_ASSERT(newRow >= 0);

    if (currentRow != newRow) {
        QStandardItem *parentIdItem = itemRow.idItem->parent();
        QList<QStandardItem*> items = parentIdItem->takeRow(currentRow);
        parentIdItem->insertRow(newRow, items);
    }
}

开发者ID:TheProjecter,项目名称:project-qtcreator,代码行数:21,代码来源:navigatortreemodel.cpp

示例8: config

▲ 点赞 1 ▼

KoRecentDocumentsPane::KoRecentDocumentsPane(QWidget* parent, const QString& header)
        : KoDetailsPane(parent, header)
        , d(new KoRecentDocumentsPanePrivate)
{
    setFocusProxy(m_documentList);
    m_openButton->setText(i18n("Open This Document"));
    m_openButton->setIcon(koIcon("document-open"));

    m_alwaysUseCheckBox->hide();

    model()->setSortRole(0); // Disable sorting

    // load list of recent files from config
    KConfigGroup config(KSharedConfig::openConfig(), "RecentFiles");

    QString fileKey;
    QString fileValue;
    QUrl url;
    QString nameValue;
    KFileItemList fileList;
    QStandardItem* rootItem = model()->invisibleRootItem();

    for (int i = 1; i <= MAX_RECENTFILES_ENTRIES; ++i) {
        fileValue = config.readPathEntry(QString("File%1").arg(i), QString());

        // ignore empty entries
        if (fileValue.isEmpty()) {
            continue;
        }

        url = QUrl::fromUserInput(fileValue);

        // ignore entries for files known to no longer exist
        if (url.isLocalFile() && !QFile::exists(url.toLocalFile())) {
            continue;
        }
        // ignore duplicated entries
        if (!fileList.findByUrl(url).isNull()) {
            continue;
        }

        nameValue = config.readPathEntry(QString("Name%1").arg(i), QString());
        // handle name entries with empty strings
        if (nameValue.isEmpty()) {
            nameValue = url.fileName();
        }

        KFileItem fileItem(url);
        fileList.prepend(fileItem);
        const QIcon icon = QIcon::fromTheme(fileItem.iconName());
        KoFileListItem* item = new KoFileListItem(icon, nameValue, fileItem);
        item->setEditable(false);
        rootItem->insertRow(0, item);
    }


    //Select the first file
    QModelIndex firstIndex = model()->indexFromItem(model()->item(0));
    m_documentList->selectionModel()->select(firstIndex, QItemSelectionModel::Select);
    m_documentList->selectionModel()->setCurrentIndex(firstIndex, QItemSelectionModel::Select);

    QStringList availablePlugins = KIO::PreviewJob::availablePlugins();
    KIO::PreviewJob *previewJob = KIO::filePreview(fileList, QSize(IconExtent, IconExtent), &availablePlugins);

    d->m_previewJobs.append(previewJob);
    connect(previewJob, SIGNAL(result(KJob*)), SLOT(previewResult(KJob*)));
    connect(previewJob, SIGNAL(gotPreview(KFileItem,QPixmap)),
            SLOT(updateIcon(KFileItem,QPixmap)));
}

开发者ID:KDE,项目名称:calligra,代码行数:69,代码来源:KoRecentDocumentsPane.cpp

示例9: testInsertRemoveGrandChildren

▲ 点赞 1 ▼

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

示例10: test

▲ 点赞 1 ▼

void FlatProxyModelTester::test()
{
    qDebug()<<"set 1 row, 1 column";
    m_standardmodel.setColumnCount( 1 );
    m_standardmodel.setRowCount( 1 );

    m_standardmodel.setHorizontalHeaderLabels( QStringList() << "Column 1" );
    m_flatmodel.setSourceModel( &m_standardmodel );
    
    QCOMPARE( m_flatmodel.columnCount(), 2 ); // it adds an extra column
    QCOMPARE( m_flatmodel.rowCount(), 1 );
    QCOMPARE( m_flatmodel.headerData( 0, Qt::Horizontal ), QVariant( "Column 1" ) );
    
    m_standardmodel.setData( m_standardmodel.index( 0, 0 ), "Index 0,0" );

    QModelIndex idx = m_flatmodel.index( 0, 0 );
    QVERIFY( idx.isValid() );
    qDebug()<<"Index 0,0:"<<idx.data();

    QCOMPARE( idx.data(), QVariant( "Index 0,0" ) );
    
    qDebug()<<"1 row, set 2 columns";
    m_standardmodel.setColumnCount( 2 );
    QCOMPARE( m_flatmodel.columnCount(), 3 ); // it adds an extra column
    m_flatmodel.setHeaderData( 1, Qt::Horizontal, "Column 2" );
    QCOMPARE( m_flatmodel.headerData( 1, Qt::Horizontal ), QVariant( "Column 2" ) );
    m_standardmodel.setData( m_standardmodel.index( 0, 1 ), "Index 0,1" );
    idx = m_flatmodel.index( 0, 1 );
    QVERIFY( idx.isValid() );
    qDebug()<<"Index 0,1:"<<idx.data();
    QCOMPARE( idx.data(), QVariant( "Index 0,1" ) );

    qDebug()<<"Set 2 rows, 2 columns";
    m_standardmodel.setRowCount( 2 );
    QCOMPARE( m_flatmodel.rowCount(), 2 );
    m_standardmodel.setData( m_standardmodel.index( 1, 0 ), "Index 1,0" );
    idx = m_flatmodel.index( 1, 0 );
    QVERIFY( idx.isValid() );
    qDebug()<<"Index 1,0:"<<idx.data();
    QCOMPARE( idx.data(), QVariant( "Index 1,0" ) );

    m_standardmodel.setData( m_standardmodel.index( 1, 1 ), "Index 1,1" );
    idx = m_flatmodel.index( 1, 1 );
    QVERIFY( idx.isValid() );
    qDebug()<<"Index 1,1:"<<idx.data();
    QCOMPARE( idx.data(), QVariant( "Index 1,1" ) );
    
    qDebug()<<"Add child on last index, adds a new row 1 in the flat model";

    // NOTE: m_standardmodel.insertRow( 0, m_standardmodel.index( 1, 0 ) );
    // does not work as there will be no columns and thus no valid indexes for this row
    QStandardItem *item = m_standardmodel.itemFromIndex( m_standardmodel.index( 1, 0 ) );
    QList<QStandardItem*> items;
    items << new QStandardItem( "Child last column 1" ) << new QStandardItem( "Child last column 2" );
    item->appendRow( items );
    QCOMPARE( m_flatmodel.rowCount(), 3 );
    idx = m_flatmodel.index( 2, 0 );
    QCOMPARE( idx.data(), QVariant( "Child last column 1" ) );
    idx = m_flatmodel.index( 2, 1 );
    QCOMPARE( idx.data(), QVariant( "Child last column 2" ) );

    qDebug()<<"add child on first index";
    
    item = m_standardmodel.itemFromIndex( m_standardmodel.index( 0, 0 ) );
    items.clear();
    items << new QStandardItem( "Child first column 1" ) << new QStandardItem( "Child first column 2" );
    item->appendRow( items );
    QCOMPARE( m_flatmodel.rowCount(), 4 );
    idx = m_flatmodel.index( 1, 0 );
    QCOMPARE( idx.data(), QVariant( "Child first column 1" ) );
    idx = m_flatmodel.index( 1, 1 );
    QCOMPARE( idx.data(), QVariant( "Child first column 2" ) );

    qDebug()<<"add row (2) on top level between first and last";
    
    item = m_standardmodel.invisibleRootItem();
    items.clear();
    items << new QStandardItem( "New index 1,0" ) << new QStandardItem( "New index 1,1" );
    item->insertRow( 1, items );
    QCOMPARE( m_flatmodel.rowCount(), 5 );
    idx = m_flatmodel.index( 2, 0 );
    QCOMPARE( idx.data(), QVariant( "New index 1,0" ) );
    idx = m_flatmodel.index( 2, 1 );
    QCOMPARE( idx.data(), QVariant( "New index 1,1" ) );

    qDebug()<<"Add child on middle index, adds row 3 to flat model";
    
    item = m_standardmodel.itemFromIndex( m_standardmodel.index( 1, 0 ) );
    items.clear();
    items << new QStandardItem( "Child middle column 1" ) << new QStandardItem( "Child middle column 2" );
    item->appendRow( items );
    QCOMPARE( m_flatmodel.rowCount(), 6 );
    idx = m_flatmodel.index( 3, 0 );
    QCOMPARE( idx.data().toString(), QVariant( "Child middle column 1" ).toString() );
    idx = m_flatmodel.index( 3, 1 );
    QCOMPARE( idx.data(), QVariant( "Child middle column 2" ) );

    qDebug()<<"Add child on middle index's child, adds row 4 to flat model";
    
    QModelIndex parent = m_standardmodel.index( 1, 0 );
//.........这里部分代码省略.........

开发者ID:abhishekmurthy,项目名称:Calligra,代码行数:101,代码来源:FlatProxyModelTester.cpp

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

;