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


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

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


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

示例1: sourceRequestEvent

bool SourcesOnRequestEngine::sourceRequestEvent(const QString &source)
{
    // When this method is called we can assume that:
    //   * the source does not exist yet
    //   * the source name parameter passed in is not an empty string
    //   * we are free to reject creating the source if we wish

    // We're going to reject any sources that start with the letter 'a'
    // to demonstrate how to reject a request in a DataEngine.
    if (source.startsWith('a') || source.startsWith('A')) {
        return false;
    }

    // For every other source, we're going to start an update count for it.
    // Critically, we create a source before returning that has the exact
    // same key as the source string. We MUST NOT create a source of a different
    // name as that will cause unexpected results for the visualization.
    // In such a case the DataEngine will remain happy and Do The Right Thing(tm)
    // but the visualization will not get the source connected to it as it
    // expects. So ALWAYS key the new data by the source string as below:
    setData(source, "Update Count", 0);

    if (!modelForSource(source)) {
        QStandardItemModel *m = new QStandardItemModel;
        m->appendRow(new QStandardItem("Item1, first update"));
        m->appendRow(new QStandardItem("Item2, first update"));
        m->appendRow(new QStandardItem("Item3, first update"));
        setModel(source, m);
    }

    // as we successfully set up the source, return true
    return true;
}
开发者ID:KDE,项目名称:plasma-framework,代码行数:33,代码来源:sourcesOnRequest.cpp

示例2: setDefaultEvent

void CommonEventsDatas::setDefaultEvent(QStandardItemModel* model,
                                        QStringList& namesEvents,
                                        QList<QVector<SystemCreateParameter*>>&
                                        parameters)
{
    QStandardItemModel* modelParameters;
    QList<QStandardItem*> row;
    SystemEvent* ev;
    QStandardItem* item;

    for (int i = 0; i < namesEvents.size(); i++){
        modelParameters = new QStandardItemModel;
        for (int j = 0; j < parameters[i].size(); j++){
            row = parameters[i][j]->getModelRow();
            modelParameters->appendRow(row);
        }
        item = new QStandardItem();
        item->setText(SuperListItem::beginningText);
        modelParameters->appendRow(item);
        ev = new SystemEvent(i+1, namesEvents[i], modelParameters);
        item = new QStandardItem;
        item->setData(QVariant::fromValue(reinterpret_cast<quintptr>(ev)));
        item->setText(ev->toString());
        model->appendRow(item);
    }
}
开发者ID:Wano-k,项目名称:RPG-Paper-Maker,代码行数:26,代码来源:commoneventsdatas.cpp

示例3: updateSourceEvent

bool SourcesOnRequestEngine::updateSourceEvent(const QString &source)
{
    // Whenever a visualization has requested an update, such as when passing
    // an update interval to DataEngine::connectSource, this method will be called.
    // When this method is called we can assume that:
    //     * the source exists
    //     * it hasn't been updated more frequently than the minimum update interval
    //
    // If not data is set in this method, then the update is skipped for the visualiation
    // and that is just fine.
    //
    // We can also set data for other sources here if we wish, but as with
    // sourceRequestEvent this may not be what the visualization expects. Unlike in
    // sourceRequestEvent, however, this will result in expected behavior: visualizations
    // connected to the sources which have setData called for them will be notified
    // of these changes.
    const int updateCount = containerForSource(source)->data().value("Update Count").toInt() + 1;
    setData(source, "Update Count", updateCount);

    QStandardItemModel *m = qobject_cast<QStandardItemModel *>(modelForSource(source));
    if (m) {
        m->clear();
        m->appendRow(new QStandardItem(QString("Item1, update %1").arg(updateCount)));
        m->appendRow(new QStandardItem(QString("Item2, update %1").arg(updateCount)));
        m->appendRow(new QStandardItem(QString("Item3, update %1").arg(updateCount)));
    }

    // Since we updated the source immediately here, we need to return true so the DataEngine
    // knows to continue with the update notification for visualizations.
    return true;
}
开发者ID:KDE,项目名称:plasma-framework,代码行数:31,代码来源:sourcesOnRequest.cpp

示例4: buildList

void VegetationWidget::buildList()
{
	QStringList extList;
	extList << ".png" << ".tga" << ".osgb";
	std::string plantDir = g_SystemContext._workContextDir;
	plantDir.append(CONTEXT_DIR);
	plantDir.append("/Plant/");
	QString grassDir = chineseTextUTF8ToQString(plantDir + "Grass");
	QStringList returnList;
	findAllFilesByExt(grassDir, extList, returnList);
	QStandardItemModel* grassModel = qobject_cast<QStandardItemModel*>(_grassListView->model());
	grassModel->clear();
	for (int i = 0; i < returnList.size(); ++i)
	{
		QFileInfo fileInfo = returnList.at(i);
		QStandardItem* newItem = new QStandardItem(fileInfo.fileName());
		setupIcon(newItem, "grass");
		newItem->setCheckable(true);
		grassModel->appendRow(newItem);
	}
	QString treeDir = chineseTextUTF8ToQString(plantDir + "Tree");
	returnList.clear();
	findAllFilesByExt(treeDir, extList, returnList);
	QStandardItemModel* treeModel = qobject_cast<QStandardItemModel*>(_treeListView->model());
	treeModel->clear();
	for (int i = 0; i < returnList.size(); ++i)
	{
		QFileInfo fileInfo = returnList.at(i);
		QStandardItem* newItem = new QStandardItem(fileInfo.fileName());
		setupIcon(newItem, "tree");
		newItem->setCheckable(true);
		treeModel->appendRow(newItem);
	}
}
开发者ID:FreeDegree,项目名称:Zhang,代码行数:34,代码来源:PlantBrushDockWidget.cpp

示例5: QDialog

QgsStyleV2GroupSelectionDialog::QgsStyleV2GroupSelectionDialog( QgsStyleV2 *style, QWidget *parent ) :
    QDialog( parent )
    , mStyle( style )
{
  setupUi( this );

  QStandardItemModel* model = new QStandardItemModel( groupTree );
  groupTree->setModel( model );

  QStandardItem *allSymbols = new QStandardItem( tr( "All Symbols" ) );
  allSymbols->setData( "all", Qt::UserRole + 2 );
  allSymbols->setEditable( false );
  setBold( allSymbols );
  model->appendRow( allSymbols );

  QStandardItem *group = new QStandardItem( "" ); //require empty name to get first order groups
  group->setData( "groupsheader", Qt::UserRole + 2 );
  group->setEditable( false );
  group->setFlags( group->flags() & ~Qt::ItemIsSelectable );
  buildGroupTree( group );
  group->setText( tr( "Groups" ) );//set title later
  QStandardItem *ungrouped = new QStandardItem( tr( "Ungrouped" ) );
  ungrouped->setData( 0 );
  ungrouped->setData( "group", Qt::UserRole + 2 );
  setBold( ungrouped );
  setBold( group );
  group->appendRow( ungrouped );
  model->appendRow( group );

  QStandardItem *tag = new QStandardItem( tr( "Smart Groups" ) );
  tag->setData( "smartgroupsheader" , Qt::UserRole + 2 );
  tag->setEditable( false );
  tag->setFlags( group->flags() & ~Qt::ItemIsSelectable );
  setBold( tag );
  QgsSymbolGroupMap sgMap = mStyle->smartgroupsListMap();
  QgsSymbolGroupMap::const_iterator i = sgMap.constBegin();
  while ( i != sgMap.constEnd() )
  {
    QStandardItem *item = new QStandardItem( i.value() );
    item->setEditable( false );
    item->setData( i.key() );
    item->setData( "smartgroup" , Qt::UserRole + 2 );
    tag->appendRow( item );
    ++i;
  }
  model->appendRow( tag );

  // expand things in the group tree
  int rows = model->rowCount( model->indexFromItem( model->invisibleRootItem() ) );
  for ( int i = 0; i < rows; i++ )
  {
    groupTree->setExpanded( model->indexFromItem( model->item( i ) ), true );
  }
  connect( groupTree->selectionModel(), SIGNAL( selectionChanged( const QItemSelection&, const QItemSelection& ) ), this, SLOT( groupTreeSelectionChanged( const QItemSelection&, const QItemSelection& ) ) );
}
开发者ID:ar-jan,项目名称:QGIS,代码行数:55,代码来源:qgsstylev2groupselectiondialog.cpp

示例6: populateStyles

bool QgsStyleExportImportDialog::populateStyles( QgsStyle *style )
{
  // load symbols and color ramps from file
  if ( mDialogMode == Import )
  {
    // NOTE mTempStyle is style here
    if ( !style->importXml( mFileName ) )
    {
      QMessageBox::warning( this, tr( "Import error" ),
                            tr( "An error occurred during import:\n%1" ).arg( style->errorString() ) );
      return false;
    }
  }

  QStandardItemModel *model = qobject_cast<QStandardItemModel *>( listItems->model() );
  model->clear();

  // populate symbols
  QStringList styleNames = style->symbolNames();
  QString name;

  for ( int i = 0; i < styleNames.count(); ++i )
  {
    name = styleNames[i];
    QStringList tags = style->tagsOfSymbol( QgsStyle::SymbolEntity, name );
    QgsSymbol *symbol = style->symbol( name );
    QStandardItem *item = new QStandardItem( name );
    QIcon icon = QgsSymbolLayerUtils::symbolPreviewIcon( symbol, listItems->iconSize(), 15 );
    item->setIcon( icon );
    item->setToolTip( QString( "<b>%1</b><br><i>%2</i>" ).arg( name, tags.count() > 0 ? tags.join( ", " ) : tr( "Not tagged" ) ) );
    // Set font to 10points to show reasonable text
    QFont itemFont = item->font();
    itemFont.setPointSize( 10 );
    item->setFont( itemFont );
    model->appendRow( item );
    delete symbol;
  }

  // and color ramps
  styleNames = style->colorRampNames();

  for ( int i = 0; i < styleNames.count(); ++i )
  {
    name = styleNames[i];
    std::unique_ptr< QgsColorRamp > ramp( style->colorRamp( name ) );

    QStandardItem *item = new QStandardItem( name );
    QIcon icon = QgsSymbolLayerUtils::colorRampPreviewIcon( ramp.get(), listItems->iconSize(), 15 );
    item->setIcon( icon );
    model->appendRow( item );
  }
  return true;
}
开发者ID:exlimit,项目名称:QGIS,代码行数:53,代码来源:qgsstyleexportimportdialog.cpp

示例7: ctkCheckableHeaderViewTest2

//-----------------------------------------------------------------------------
int ctkCheckableHeaderViewTest2(int argc, char * argv [] )
{
  QApplication app(argc, argv);

  QStringList headers;
  headers << "Title 1" << "Title 2" << "Title 3";
  QStandardItemModel model;
  model.setHorizontalHeaderLabels(headers);
  QList<QStandardItem*> row0;
  row0 << new QStandardItem << new QStandardItem << new QStandardItem;
  row0[0]->setText("not user checkable");
  model.appendRow(row0);
  QList<QStandardItem*> row1;
  row1 << new QStandardItem << new QStandardItem << new QStandardItem;
  row1[0]->setCheckable(true);
  row1[0]->setText("checkable1");
  model.appendRow(row1);
  QList<QStandardItem*> row2;
  row2 << new QStandardItem << new QStandardItem << new QStandardItem;
  row2[0]->setCheckable(true);
  row2[0]->setText("checkable2");
  model.appendRow(row2);

  QTreeView view;
  view.setModel(&model);

  model.setHeaderData(0, Qt::Horizontal, Qt::Checked, Qt::CheckStateRole);

  QHeaderView* previousHeaderView = view.header();
  bool oldClickable = previousHeaderView->isClickable();

  ctkCheckableHeaderView* headerView = new ctkCheckableHeaderView(Qt::Horizontal, &view);  
  headerView->setClickable(oldClickable);
  headerView->setMovable(previousHeaderView->isMovable());
  headerView->setHighlightSections(previousHeaderView->highlightSections());
  headerView->checkableModelHelper()->setPropagateDepth(-1);
  headerView->checkableModelHelper()->setForceCheckability(true);

  // sets the model to the headerview
  view.setHeader(headerView);
  headers << "4";
  model.setHorizontalHeaderLabels(headers);
  view.show();

  if (argc < 2 || QString(argv[1]) != "-I" )
    {
    QTimer::singleShot(500, &app, SLOT(quit()));
    }
  
  return app.exec();
}
开发者ID:Koki-Shimizu,项目名称:CTK,代码行数:52,代码来源:ctkCheckableHeaderViewTest2.cpp

示例8: save

bool CodeEditor::save()
{
    QFile file(windowFilePath());
    if(!file.open(QIODevice::WriteOnly| QIODevice::Truncate) )
        return false;

    const QString text = edit->toPlainText();
    file.write(text.toLocal8Bit());
    file.close();

    CppObjList objList;
    CppReader reader(text);
    objList << reader;

    objList.readDescription(text);
    if(!objList.isEmpty())
    {
        QFileInfo info(windowFilePath());

        if( Editor1::source().contains(info.fileName()))
        {
            QStandardItemModel *objModel = Editor1::source().value(info.fileName());
            objModel->clear();
            foreach (QStandardItem *it, objList)
                objModel->appendRow( it);
            objModel->setHorizontalHeaderLabels(QStringList(info.fileName()));

            model->clear();
            select(model->invisibleRootItem(),objModel->invisibleRootItem());
            view->expandAll();
            view->resizeColumnToContents(0);
        }
        else
        {
            QStandardItemModel *objModel = new QStandardItemModel;
            foreach (QStandardItem *it, objList)
                objModel->appendRow( it);
            objModel->setHorizontalHeaderLabels(QStringList(info.fileName()));
            Editor1::source().insert(info.fileName(),objModel);

            model->clear();

            select(model->invisibleRootItem(),objModel->invisibleRootItem());
            view->expandAll();
            view->resizeColumnToContents(0);
        }
    }

    edit->document()->setModified(false);
    return true;
}
开发者ID:sefloware,项目名称:GBR,代码行数:51,代码来源:stcodeeditor.cpp

示例9: ctkModelTesterTest1

//-----------------------------------------------------------------------------
int ctkModelTesterTest1(int argc, char * argv [] )
{
  QCoreApplication app(argc, argv);

  QAbstractItemModelHelper * item = new QAbstractItemModelHelper;
  QObject * object = new QObject; 

  ctkModelTester ctkTester( item, object );

  delete item;

  try
    {
    // as we can infer that QStandardItemModel is correct,
    // ctkModelTester shall not fail for any of the actions on the model.
    // Please note here that takeRow() doesn't delete the items so we end up
    // with mem leaks.
    QStandardItemModel model;
    ctkModelTester treeModelTester(&model);
    QList<QStandardItem*> items;
    items << new QStandardItem("col1") << new QStandardItem("col2");
    model.appendRow(items);
    QList<QStandardItem*> items2  = model.takeRow(0);
    if (items2 != items)
      {
      std::cerr << "Error" << std::endl;
      return EXIT_FAILURE;
      }
    items2.clear();
    model.appendRow(items);
    for (int i = 0; i < 10; ++i)
      {
      model.appendRow(QList<QStandardItem*>() << new QStandardItem("col1") << new QStandardItem("col2"));
      }
    model.takeRow(0);
    model.takeRow(model.rowCount() / 2 );
    model.takeRow(model.rowCount() - 1);
    items2 << new QStandardItem("col1") << new QStandardItem("col2");
    items2[0]->appendRow(QList<QStandardItem*>() << new QStandardItem("subcol1") << new QStandardItem("subcol2"));
    items2[0]->appendRow(QList<QStandardItem*>() << new QStandardItem("subcol1") << new QStandardItem("subcol2"));
    model.setData(model.index(0,0), QString("foo"));
    model.sort(0);
    }
  catch (const char* error)
    {
    std::cerr << error << std::endl;
    return EXIT_FAILURE;
    }

  return EXIT_SUCCESS;
}
开发者ID:phfr83,项目名称:CTK,代码行数:52,代码来源:ctkModelTesterTest1.cpp

示例10: QDialog

BrewWindow::BrewWindow(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::BrewWindow)
{
    ui->setupUi(this);
    QStandardItemModel* model = new QStandardItemModel();

    QStandardItem* item1 = new QStandardItem("Maltose Rest 55°");
    model->appendRow(item1);
    QStandardItem* item2 = new QStandardItem("Protein Rest °");
    model->appendRow(item2);

    ui->listView->setModel(model);
}
开发者ID:ipa,项目名称:GuerrillaBrew,代码行数:14,代码来源:brewwindow.cpp

示例11: main

int main(int argc, char *argv[])
{
    QApplication app(argc, argv);
    QStandardItemModel model;
    model.appendRow(new QStandardItem("Norway"));
    model.appendRow(new QStandardItem("Netherlands"));
    model.appendRow(new QStandardItem("New Zealand"));
    model.appendRow(new QStandardItem("Namibia"));
    model.appendRow(new QStandardItem("Nicaragua"));
    model.appendRow(new QStandardItem("North Korea"));
    model.appendRow(new QStandardItem("Northern Cyprus "));
    model.appendRow(new QStandardItem("Sweden"));
    model.appendRow(new QStandardItem("Denmark"));

    QStringList strings;
    strings << "Norway" << "Sweden" << "Denmark";

    QQmlApplicationEngine engine;
    engine.rootContext()->setContextProperty("standardmodel", &model);
    engine.rootContext()->setContextProperty("stringmodel", strings);
    engine.load(QUrl("main.qml"));
    QObject *topLevel = engine.rootObjects().value(0);

    QQuickWindow *window = qobject_cast<QQuickWindow *>(topLevel);
    if ( !window ) {
        qWarning("Error: Your root item has to be a Window.");
        return -1;
    }
    window->show();
    return app.exec();
}
开发者ID:SchleunigerAG,项目名称:WinEC7_Qt5.3.1_Fixes,代码行数:31,代码来源:main.cpp

示例12: populateSymbols

void QgsStyleManagerDialog::populateSymbols( const QStringList& symbolNames, bool check )
{
  QStandardItemModel* model = qobject_cast<QStandardItemModel*>( listItems->model() );
  model->clear();

  int type = currentItemType();

  for ( int i = 0; i < symbolNames.count(); ++i )
  {
    QString name = symbolNames[i];
    QgsSymbol* symbol = mStyle->symbol( name );
    if ( symbol && symbol->type() == type )
    {
      QStandardItem* item = new QStandardItem( name );
      QIcon icon = QgsSymbolLayerUtils::symbolPreviewIcon( symbol, listItems->iconSize() );
      item->setIcon( icon );
      item->setData( name ); // used to find out original name when user edited the name
      item->setCheckable( check );
      item->setToolTip( name );
      // add to model
      model->appendRow( item );
    }
    delete symbol;
  }
  selectedSymbolsChanged( QItemSelection(), QItemSelection() );
  symbolSelected( listItems->currentIndex() );
}
开发者ID:3liz,项目名称:Quantum-GIS,代码行数:27,代码来源:qgsstylemanagerdialog.cpp

示例13: subclassing

void tst_QStandardItem::subclassing()
{
    qMetaTypeId<QStandardItem*>();

    CustomItem *item = new CustomItem;
    QCOMPARE(item->type(), int(QStandardItem::UserType + 1));

    item->setText(QString::fromLatin1("foo"));
    QCOMPARE(item->text(), QString::fromLatin1("foo"));

    item->emitDataChanged(); // does nothing

    QStandardItemModel model;
    model.appendRow(item);

    QSignalSpy itemChangedSpy(&model, SIGNAL(itemChanged(QStandardItem*)));
    item->emitDataChanged();
    QCOMPARE(itemChangedSpy.count(), 1);
    QCOMPARE(itemChangedSpy.at(0).count(), 1);
    QCOMPARE(qvariant_cast<QStandardItem*>(itemChangedSpy.at(0).at(0)), (QStandardItem*)item);

    CustomItem *child0 = new CustomItem("cc");
    CustomItem *child1 = new CustomItem("bbb");
    CustomItem *child2 = new CustomItem("a");
    item->appendRow(child0);
    item->appendRow(child1);
    item->appendRow(child2);
    item->sortChildren(0);
    QCOMPARE(item->child(0), (QStandardItem*)child2);
    QCOMPARE(item->child(1), (QStandardItem*)child0);
    QCOMPARE(item->child(2), (QStandardItem*)child1);
}
开发者ID:maxxant,项目名称:qt,代码行数:32,代码来源:tst_qstandarditem.cpp

示例14: dropEvent

void BookmarkList::dropEvent(QDropEvent *event)
{
	const QMimeData* data = event->mimeData();
	if(data->hasUrls())
	{
		//TODO: Add insert to the dropped row, except row 0
		QStandardItemModel* mod = (QStandardItemModel*)model();
		QString path = data->urls()[0].path(); 
		QFileInfo f(path);
		if(mod)
		{
			QList<QStandardItem*> items = mod->findItems(f.fileName());
			if(f.isDir() && items.isEmpty())
			{
				QStandardItem *it = new QStandardItem();
				it->setText(f.fileName());
				it->setData(path);
#if QT_VERSION >= 0x040600
				// Todo: Use a "favorites folder" icon instead
				it->setIcon(*globalIcon);
#else
				it->setIcon(QIcon(":/images/icons/clip-folder-bookmark.png"));
#endif	
				it->setDropEnabled(true);
				mod->appendRow(it);
				emit bookmarkAdded();
			}
		}
	}
	event->acceptProposedAction();
}
开发者ID:ViktorNova,项目名称:los,代码行数:31,代码来源:BookmarkList.cpp

示例15: p

void QgsSymbolV2SelectorDialog::populateSymbolView()
{
  QSize previewSize = viewSymbols->iconSize();
  QPixmap p( previewSize );
  QPainter painter;

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

  QStringList names = mStyle->symbolNames();
  for ( int i = 0; i < names.count(); i++ )
  {
    QgsSymbolV2* s = mStyle->symbol( names[i] );
    if ( s->type() != mSymbol->type() )
    {
      delete s;
      continue;
    }
    QStandardItem* item = new QStandardItem( names[i] );
    item->setData( names[i], Qt::UserRole ); //so we can show a label when it is clicked
    item->setText( "" ); //set the text to nothing and show in label when clicked rather
    item->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable );
    // create preview icon
    QIcon icon = QgsSymbolLayerV2Utils::symbolPreviewIcon( s, previewSize );
    item->setIcon( icon );
    // add to model
    model->appendRow( item );
    delete s;
  }
}
开发者ID:CzendaZdenda,项目名称:qgis,代码行数:34,代码来源:qgssymbolv2selectordialog.cpp


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