本文整理汇总了C++中QAbstractItemModel::setData方法的典型用法代码示例。如果您正苦于以下问题:C++ QAbstractItemModel::setData方法的具体用法?C++ QAbstractItemModel::setData怎么用?C++ QAbstractItemModel::setData使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QAbstractItemModel
的用法示例。
在下文中一共展示了QAbstractItemModel::setData方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: insertRow
void MetaEditor::insertRow(QString code, QString contents)
{
QModelIndex index = view->selectionModel()->currentIndex();
QAbstractItemModel *model = view->model();
// force all row insertions to be children of the root item
while(index.parent() != QModelIndex()) {
index = index.parent();
}
if (!model->insertRow(index.row()+1, index.parent()))
return;
updateActions();
QModelIndex child = model->index(index.row()+1, 0, index.parent());
model->setData(child, QVariant(code), Qt::EditRole);
for (int column = 1; column < model->columnCount(index.parent()); ++column) {
QModelIndex nchild = model->index(index.row()+1, column, index.parent());
if (!contents.isEmpty()) {
model->setData(nchild, QVariant(contents), Qt::EditRole);
} else {
model->setData(nchild, QVariant(tr("[Your value here]")), Qt::EditRole);
}
}
// force newly inserted row to be the currently selected item so that any
// follow-on insertChild calls use this as their parent.
view->selectionModel()->setCurrentIndex(child, QItemSelectionModel::ClearAndSelect);
updateActions();
}
示例2: save
/** Submit the current editing class/interactor to the model and submit the model to the database */
void InteractorEditorWidget::save()
{
if (d->m_EditingIndex.isValid()) {
QAbstractItemModel *model = ddiCore()->drugInteractorTableModel();
// Manage ATC
QModelIndex atc = model->index(d->m_EditingIndex.row(), DrugInteractorTableModel::ATCCodeStringList, d->m_EditingIndex.parent());
model->setData(atc, d->_atcCodesStringListModel->stringList().join(";"));
// Manage class children
QModelIndex children = model->index(d->m_EditingIndex.row(), DrugInteractorTableModel::ChildrenUuid, d->m_EditingIndex.parent());
model->setData(children, d->_childrenInteractorsStringListModel->stringList().join(";"));
// Manage PMIDs
QModelIndex pmids = model->index(d->m_EditingIndex.row(), DrugInteractorTableModel::PMIDStringList, d->m_EditingIndex.parent());
model->setData(pmids, d->_pmidStringListModel->stringList().join(";"));
// Submit mapper at the end as the model will be resetted on submit
if (!d->_mapper->submit())
LOG_ERROR("Unable to submit mapper");
}
setEditorsEnabled(false);
d->aSave->setEnabled(false);
d->aRevert->setEnabled(false);
d->_proxyMoleculeModel->invalidate();
d->_proxyMoleculeModel->setFilterFixedString(d->ui->searchLine->text());
updateCounts();
}
示例3: setJoinInfo
void QgsJoinDialog::setJoinInfo( const QgsVectorJoinInfo& joinInfo )
{
mJoinLayerComboBox->setLayer( QgsMapLayerRegistry::instance()->mapLayer( joinInfo.joinLayerId ) );
mJoinFieldComboBox->setField( joinInfo.joinFieldName );
mTargetFieldComboBox->setField( joinInfo.targetFieldName );
mCacheInMemoryCheckBox->setChecked( joinInfo.memoryCache );
if ( joinInfo.prefix.isNull() )
{
mUseCustomPrefix->setChecked( false );
}
else
{
mUseCustomPrefix->setChecked( true );
mCustomPrefix->setText( joinInfo.prefix );
}
QStringList* lst = joinInfo.joinFieldNamesSubset();
mUseJoinFieldsSubset->setChecked( lst && !lst->isEmpty() );
QAbstractItemModel* model = mJoinFieldsSubsetView->model();
if ( model )
{
for ( int i = 0; i < model->rowCount(); ++i )
{
QModelIndex index = model->index( i, 0 );
if ( lst && lst->contains( model->data( index, Qt::DisplayRole ).toString() ) )
{
model->setData( index, Qt::Checked, Qt::CheckStateRole );
}
else
{
model->setData( index, Qt::Unchecked, Qt::CheckStateRole );
}
}
}
}
示例4: setupModel
void LogDetailWidget::setupModel()
{
QAbstractItemModel *model = pieChart->model();
model->setHeaderData(0, Qt::Horizontal, tr("Label"));
model->setHeaderData(1, Qt::Horizontal, tr("Quantity"));
QString colors[] = {"#ff0000", "#00ff00", "#0000ff","#ffff00", "#ff00ff", "#00ffff", "#000000", "#ffffff", "#777777", "#222222", "#aaaaaa"};
int i=0;
for(hash_map<string, double>::iterator it = logMan.process_stat.begin() ; it != logMan.process_stat.end(); it++)
{
string process = it->first;
double duration = it->second;
model->insertRow(i);
model->setData(model->index(i, 0), QString::fromStdString(process));
model->setData(model->index(i, 1), duration);
model->setData(model->index(i, 0, QModelIndex()),
QColor(colors[i]), Qt::DecorationRole);
i++;
}
}
示例5: resizeEvent
/*
void AdjustNames::resizeEvent( QResizeEvent * event )
{
int w = event->size().width();
int h = event->size().height();
BackFrame->resize(event->size());
if( w > 300 && h > 150 )
{
Cancel->setGeometry(w-85,h-36,77,26);
Next->setGeometry(w-168,h-36,77,26);
line->setGeometry(14,h-53,w-21,16);
title->setGeometry(220,21,w-299,18);
instructions->setGeometry(220,h-79,w-229,18);
tableWidget->setGeometry(220, 45, w-229, h-130);
}
}
*/
void AdjustNames::show()
{
QDialog::show();
scenarioName->setText(QString( "Scenario Name: ") + extractor->setup->scenarioName->text());
scenarioDirectory->setText(QString("Scenario Directory: ") + extractor->setup->scenarioDirectory->text());
tableWidget->clearContents();
tableWidget->setRowCount(0);
tableWidget->horizontalHeaderItem(0)->setToolTip("This is the node id used by the EXata/QualNet simulator and GUI");
tableWidget->horizontalHeaderItem(1)->setToolTip("This is the name used by the HLA federate that published the entity");
tableWidget->horizontalHeaderItem(2)->setToolTip("Enter text to change the name that will be used by the EXata/QualNet simulator and GUI");
tableWidget->horizontalHeaderItem(3)->setToolTip("Enter an icon file name or browse to change the icon used by the EXata/QualNet simulator and GUI");
QAbstractItemModel* model = tableWidget->model();
SNT_HLA::NodeSet::iterator it = extractor->ns->begin();
//QFontMetrics fontMetrics = tableWidget->fontMetrics();
//int iconWidth = 0;
while( it != extractor->ns->end() )
{
QApplication::processEvents();
if( extractor == 0 )
break;
if( (*it)->entity )
{
QString name((*it)->getNodeName());
int id = (*it)->NodeId;
QString iconName((*it)->getIconName().c_str());
QIcon icon(iconName);
QFileInfo iconInfo(iconName);
int row = tableWidget->rowCount();
tableWidget->insertRow(row);
QModelIndex index = model->index(row, 1, QModelIndex());
model->setData(index, name);
index = model->index(row, 2, QModelIndex());
model->setData(index, name);
index = model->index(row, 0, QModelIndex());
model->setData(index, id);
tableWidget->item(row, 0)->setFlags(0);
tableWidget->item(row, 1)->setFlags(0);
FileNameWidget* wid = new FileNameWidget("Open Icon File", extractor->exeHome+"/gui/icons", getImageFilter(),tableWidget);
wid->setText(iconName);
wid->setToolTip("Enter an icon file name or browse to change the icon used by the EXata/QualNet simulator and GUI");
tableWidget->setCellWidget(row, 3, wid);
tableWidget->item(row,0)->setToolTip("This is the node id used by the EXata/QualNet simulator and GUI");
tableWidget->item(row,1)->setToolTip("This is the name used by the HLA federate that published the entity");
tableWidget->item(row,2)->setToolTip("Enter text to change the name that will be used by the EXata/QualNet simulator and GUI");
tableWidget->resizeColumnToContents(0);
tableWidget->resizeColumnToContents(1);
tableWidget->resizeColumnToContents(2);
}
//tableWidget->setColumnWidth(3, iconWidth);
it++;
}
}
示例6: cellChanged
void PreferencesDialog::cellChanged(int row, int column) {
if (row == 3) {
// force selection color to be the same for nodes & edges
QAbstractItemModel* model = _ui->graphDefaultsTable->model();
model->setData(model->index(3, column == 1 ? 2 : 1), model->data(model->index(3,column)));
}
}
示例7: setField
void ParamItem::setField(int column, double value) {
QAbstractItemModel* model
= const_cast<QAbstractItemModel*>(currentIndex.model());
model->setData(
model->index(currentIndex.row(), column, QModelIndex()), value);
}
示例8: insertChild
void MainWindow::insertChild()
{
QModelIndex index = view->selectionModel()->currentIndex();
QAbstractItemModel *model = view->model();
if (model->columnCount(index) == 0) {
if (!model->insertColumn(0, index))
return;
}
if (!model->insertRow(0, index))
return;
for (int column = 0; column < model->columnCount(index); ++column) {
QModelIndex child = model->index(0, column, index);
model->setData(child, QVariant("[No data]"), Qt::EditRole);
if (!model->headerData(column, Qt::Horizontal).isValid())
model->setHeaderData(column, Qt::Horizontal, QVariant("[No header]"),
Qt::EditRole);
}
view->selectionModel()->setCurrentIndex(model->index(0, 0, index),
QItemSelectionModel::ClearAndSelect);
updateActions();
}
示例9: main
//! [0]
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
// Unindented for quoting purposes:
//! [1]
QStringList numbers;
numbers << "One" << "Two" << "Three" << "Four" << "Five";
QAbstractItemModel *model = new StringListModel(numbers);
//! [0] //! [1] //! [2] //! [3]
QListView *view = new QListView;
//! [2]
view->setWindowTitle("View onto a string list model");
//! [4]
view->setModel(model);
//! [3] //! [4]
model->insertRows(5, 7, QModelIndex());
for (int row = 5; row < 12; ++row) {
QModelIndex index = model->index(row, 0, QModelIndex());
model->setData(index, QString::number(row+1));
}
//! [5]
view->show();
return app.exec();
}
示例10: testUpdate
void testUpdate()
{
const QgsKeyValueWidgetFactory factory( QStringLiteral( "testKeyValue" ) );
QgsEditorWidgetWrapper* wrapper = factory.create( nullptr, 0, nullptr, nullptr );
QVERIFY( wrapper );
QSignalSpy spy( wrapper, SIGNAL( valueChanged( const QVariant& ) ) );
QgsKeyValueWidget* widget = qobject_cast< QgsKeyValueWidget* >( wrapper->widget() );
QVERIFY( widget );
QVariantMap initial;
initial[QStringLiteral( "1" )] = "one";
initial[QStringLiteral( "2" )] = "two";
wrapper->setValue( initial );
const QVariant value = wrapper->value();
QCOMPARE( int( value.type() ), int( QVariant::Map ) );
QCOMPARE( value.toMap(), initial );
QCOMPARE( spy.count(), 0 );
QAbstractItemModel* model = widget->tableView->model();
model->setData( model->index( 0, 1 ), "hello" );
QCOMPARE( spy.count(), 1 );
QVariantMap expected = initial;
expected[QStringLiteral( "1" )] = "hello";
QVariant eventValue = spy.at( 0 ).at( 0 ).value<QVariant>();
QCOMPARE( int( eventValue.type() ), int( QVariant::Map ) );
QCOMPARE( eventValue.toMap(), expected );
QCOMPARE( wrapper->value().toMap(), expected );
QCOMPARE( spy.count(), 1 );
}
示例11: pageRight
void Desktopwidget::pageRight (const QModelIndex &index)
{
QAbstractItemModel *model = (QAbstractItemModel *)index.model ();
int pagenum = model->data (index, Desktopmodel::Role_pagenum).toInt ();
QVariant v = pagenum + 1;
model->setData (index, v, Desktopmodel::Role_pagenum);
}
示例12: setRoleValueByName
void Element::setRoleValueByName(QString const &roleName, QString const &value)
{
int roleIndex = roleIndexByName(roleName);
if (roleIndex < roles::customPropertiesBeginRole)
return;
QAbstractItemModel *itemModel = const_cast<QAbstractItemModel*>(mDataIndex.model());
itemModel->setData(mDataIndex, value, roleIndex);
}
示例13: comboBox
void tst_QDataWidgetMapper::comboBox()
{
QDataWidgetMapper mapper;
QAbstractItemModel *model = testModel(&mapper);
mapper.setModel(model);
mapper.setSubmitPolicy(QDataWidgetMapper::ManualSubmit);
QComboBox readOnlyBox;
readOnlyBox.setEditable(false);
readOnlyBox.addItem("read only item 0");
readOnlyBox.addItem("read only item 1");
readOnlyBox.addItem("read only item 2");
QComboBox readWriteBox;
readWriteBox.setEditable(true);
readWriteBox.addItem("read write item 0");
readWriteBox.addItem("read write item 1");
readWriteBox.addItem("read write item 2");
// populat the combo boxes with data
mapper.addMapping(&readOnlyBox, 0, "currentIndex");
mapper.addMapping(&readWriteBox, 1, "currentText");
mapper.toFirst();
QCOMPARE(readOnlyBox.currentText(), QString("read only item 0"));
QCOMPARE(readWriteBox.currentText(), QString("read write item 0"));
// set some new values on the boxes
readOnlyBox.setCurrentIndex(1);
readWriteBox.setEditText("read write item y");
mapper.submit();
// make sure the new values are in the model
QCOMPARE(model->data(model->index(0, 0)).toInt(), 1);
QCOMPARE(model->data(model->index(0, 1)).toString(), QString("read write item y"));
// now test updating of the widgets
model->setData(model->index(0, 0), 2, Qt::EditRole);
model->setData(model->index(0, 1), QString("read write item z"), Qt::EditRole);
QCOMPARE(readOnlyBox.currentIndex(), 2);
QEXPECT_FAIL("", "See task 125493 and QTBUG-428", Abort);
QCOMPARE(readWriteBox.currentText(), QString("read write item z"));
}
示例14: setData
bool KConcatenateRowsProxyModel::setData(const QModelIndex &index, const QVariant &value, int role)
{
const QModelIndex sourceIndex = mapToSource(index);
if (!sourceIndex.isValid()) {
return false;
}
QAbstractItemModel *sourceModel = const_cast<QAbstractItemModel *>(sourceIndex.model());
return sourceModel->setData(sourceIndex, value, role);
}
示例15: on_selectNoneButton_clicked
void DlgFilletEdges::on_selectNoneButton_clicked()
{
QAbstractItemModel* model = ui->treeView->model();
for (int i=0; i<model->rowCount(); ++i) {
Qt::CheckState checkState = Qt::Unchecked;
QVariant value(static_cast<int>(checkState));
model->setData(model->index(i,0), value, Qt::CheckStateRole);
}
}