本文整理汇总了C++中QAbstractItemModel::index方法的典型用法代码示例。如果您正苦于以下问题:C++ QAbstractItemModel::index方法的具体用法?C++ QAbstractItemModel::index怎么用?C++ QAbstractItemModel::index使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QAbstractItemModel
的用法示例。
在下文中一共展示了QAbstractItemModel::index方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: onCompleterIndexActivated
/*!
* When user selects a zip or a city this private slot is activated. It causes the line edit
* to be populated with the selected values.
*/
void ZipCountryCompleters::onCompleterIndexActivated(const QModelIndex &index)
{
if (!m_ZipModel || !m_CityModel)
return;
QAbstractItemModel *model = const_cast<QAbstractItemModel*>(index.model());
const QString &zip = model->index(index.row(), ZipCountryModel::Zip).data().toString();
const QString &city = model->index(index.row(), ZipCountryModel::City).data().toString();
const QString &province = model->index(index.row(), ZipCountryModel::Province).data().toString();
// Disconnect editors
m_zipEdit->blockSignals(true);
m_cityEdit->blockSignals(true);
m_provinceCombo->blockSignals(true);
if (m_zipEdit) {
m_zipEdit->clearFocus();
m_zipEdit->setText(zip.toUpper());
}
if (m_cityEdit) {
m_cityEdit->clearFocus();
m_cityEdit->setText(city.toUpper());
}
if (m_provinceCombo) {
m_provinceCombo->clearFocus();
m_provinceCombo->setCurrentIndex(m_provinceCombo->findText(province));
}
// Reconnect editors
m_zipEdit->blockSignals(false);
m_cityEdit->blockSignals(false);
m_provinceCombo->blockSignals(false);
checkData();
}
示例2: writeSettings
void PreferencesDialog::writeSettings() {
TulipSettings::instance().setProxyEnabled(_ui->proxyCheck->isChecked());
switch(_ui->proxyType->currentIndex()) {
case 0:
TulipSettings::instance().setProxyType(QNetworkProxy::Socks5Proxy);
break;
case 1:
TulipSettings::instance().setProxyType(QNetworkProxy::HttpProxy);
break;
case 2:
TulipSettings::instance().setProxyType(QNetworkProxy::HttpCachingProxy);
break;
case 3:
TulipSettings::instance().setProxyType(QNetworkProxy::FtpCachingProxy);
break;
default:
break;
}
TulipSettings::instance().setProxyHost(_ui->proxyAddr->text());
TulipSettings::instance().setProxyPort(_ui->proxyPort->value());
TulipSettings::instance().setUseProxyAuthentification(_ui->proxyAuthCheck->isChecked());
TulipSettings::instance().setProxyUsername(_ui->proxyUser->text());
TulipSettings::instance().setProxyPassword(_ui->proxyPassword->text());
QAbstractItemModel* model = _ui->graphDefaultsTable->model();
TulipSettings::instance().setDefaultColor(tlp::NODE,model->data(model->index(0,1)).value<tlp::Color>());
TulipSettings::instance().setDefaultColor(tlp::EDGE,model->data(model->index(0,2)).value<tlp::Color>());
TulipSettings::instance().setDefaultSize(tlp::NODE,model->data(model->index(1,1)).value<tlp::Size>());
TulipSettings::instance().setDefaultSize(tlp::EDGE,model->data(model->index(1,2)).value<tlp::Size>());
TulipSettings::instance().setDefaultShape(tlp::NODE,model->data(model->index(2,1)).value<NodeShape::NodeShapes>());
TulipSettings::instance().setDefaultShape(tlp::EDGE,(int)(model->data(model->index(2,2)).value<EdgeShape::EdgeShapes>()));
TulipSettings::instance().setDefaultSelectionColor(model->data(model->index(3,1)).value<tlp::Color>());
TulipSettings::instance().setDefaultSelectionColor(model->data(model->index(3,2)).value<tlp::Color>());
TulipSettings::instance().applyProxySettings();
TulipSettings::instance().setDisplayDefaultViews(_ui->displayDefaultViews->isChecked());
TulipSettings::instance().setAutomaticMapMetric(_ui->colorMappingCheck->isChecked());
TulipSettings::instance().setAutomaticRatio(_ui->aspectRatioCheck->isChecked());
TulipSettings::instance().setViewOrtho(_ui->viewOrthoCheck->isChecked());
TulipSettings::instance().setResultPropertyStored(_ui->resultPropertyStoredCheck->isChecked());
TulipSettings::instance().setRunningTimeComputed(_ui->runningTimeComputedCheck->isChecked());
if (_ui->randomSeedCheck->isChecked()) {
bool ok = true;
unsigned int seed = _ui->randomSeedEdit->text().toUInt(&ok);
tlp::setSeedOfRandomSequence(seed);
}
else
tlp::setSeedOfRandomSequence();
TulipSettings::instance().setSeedOfRandomSequence(tlp::getSeedOfRandomSequence());
}
示例3: 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++;
}
}
示例4: 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();
}
示例5: onCustomMenuRequested
void LogDetailWidget::onCustomMenuRequested(const QPoint &pos)
{
QModelIndex index = ui.aaView->currentIndex();
if(index.row() <0) return;
QAbstractItemModel* model = ui.aaView->model();
QMenu *menu=new QMenu(this);
QString timestamp = model->data(model->index(index.row(), 0), Qt::DisplayRole).toString();
QString compName = model->data(model->index(index.row(), 2), Qt::DisplayRole).toString();
QString type = model->data(model->index(index.row(), 4), Qt::DisplayRole).toString();
QString value = model->data(model->index(index.row(), 5), Qt::DisplayRole).toString();
int i;
if((i=compName.indexOf(".java"))>=0 && type == "edit" && value != "")
{
QAction *editHistory = new QAction("See Edit History", this);
menu->addAction(editHistory);
connect(editHistory, SIGNAL(triggered()), this, SLOT(showEditHistory()));
}
QAction *showact = new QAction("Show Screenshot", this);
menu->addAction(showact);
menu->popup(ui.aaView->viewport()->mapToGlobal(pos));
connect(showact, SIGNAL(triggered()), this, SLOT(showScreenshot()));
}
示例6: prevIndex
QModelIndex TreeViewFind::prevIndex(const QModelIndex &idx, bool *wrapped) const
{
if (wrapped)
*wrapped = false;
QAbstractItemModel *model = d->m_view->model();
// if same parent has earlier columns, just move there
if (idx.column() > 0)
return model->index(idx.row(), idx.column() - 1, idx.parent());
QModelIndex current = idx;
bool checkForChildren = true;
if (current.isValid()) {
int row = current.row();
if (row > 0) {
current = model->index(row - 1, 0, current.parent());
} else {
current = current.parent();
checkForChildren = !current.isValid();
if (checkForChildren && wrapped) {
// we start from the end
*wrapped = true;
}
}
}
if (checkForChildren) {
// traverse down the hierarchy
while (int rc = model->rowCount(current)) {
current = model->index(rc - 1, 0, current);
}
}
// set to last column
current = model->index(current.row(), model->columnCount(current.parent()) - 1, current.parent());
return current;
}
示例7: 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();
}
示例8: 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)));
}
}
示例9: accept
void EditSolutionDialog::accept()
{
QVariant bw = ui->bw->property("wine");
QModelIndexList l = mWineModel->match(mWineModel->index(0, 0), Qt::DisplayRole, bw, -1, Qt::MatchFixedString);
bw = l.first().data(PackageModel::IdRole);
QVariant aw = ui->aw->property("wine");
l = mWineModel->match(mWineModel->index(0, 0), Qt::DisplayRole, aw, -1, Qt::MatchFixedString);
aw = l.first().data(PackageModel::IdRole);
SolutionModel::IntList bp;
QAbstractItemModel *bpm = ui->bp->model();
for (int i = 0, count = bpm->rowCount(); i < count; ++i)
bp.append(bpm->index(i, 0).data(PackageModel::IdRole).toInt());
SolutionModel::IntList ap;
QAbstractItemModel *apm = ui->ap->model();
for (int i = 0, count = apm->rowCount(); i < count; ++i)
ap.append(apm->index(i, 0).data(PackageModel::IdRole).toInt());
QModelIndex index = mModel->index(mRow, 0);
QMap<int, QVariant> data;
data.insert(SolutionModel::BWRole, bw);
data.insert(SolutionModel::AWRole, aw);
data.insert(SolutionModel::BPRole, QVariant::fromValue(bp));
data.insert(SolutionModel::APRole, QVariant::fromValue(ap));
QSortFilterProxyModel *sm = static_cast<QSortFilterProxyModel *>(mModel);
sm->sourceModel()->setItemData(sm->mapToSource(index), data);
QDialog::accept();
}
示例10: _q_recomputeCompleterPopupSize
//-----------------------------------------------------------------------------
void ctkPathLineEditPrivate::_q_recomputeCompleterPopupSize()
{
QSize lineEditSize = this->LineEdit->size();
QAbstractItemView* view = this->LineEdit->completer()->popup();
const QFontMetrics& fm = view->fontMetrics();
int iconWidth = 0;
int textWidth = 0;
QStyleOptionFrame option;
int frameWidth = view->style()->pixelMetric(QStyle::PM_DefaultFrameWidth, &option, view);
int frame = 2 * frameWidth
+ view->contentsMargins().left()
+ view->contentsMargins().right();
QAbstractItemModel* model = this->LineEdit->completer()->completionModel();
for (int i = 0; i < model->rowCount(); ++i)
{
QVariant icon = model->data(model->index(i, 0), Qt::DecorationRole);
if (icon.isValid() && icon.canConvert<QIcon>())
{
iconWidth = qMax(iconWidth, icon.value<QIcon>().availableSizes().front().width() + 4);
}
textWidth = qMax(textWidth, fm.boundingRect(model->data(model->index(i, 0)).toString()).width());
}
view->setMinimumWidth(qMax(frame + iconWidth + textWidth, lineEditSize.width()));
}
示例11: 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();
}
示例12: setData
void tst_QDataWidgetMapper::setData()
{
QDataWidgetMapper mapper;
QAbstractItemModel *model = testModel(&mapper);
mapper.setModel(model);
QLineEdit edit1;
QLineEdit edit2;
QLineEdit edit3;
mapper.addMapping(&edit1, 0);
mapper.addMapping(&edit2, 1);
mapper.addMapping(&edit3, 0, "text");
mapper.toFirst();
QCOMPARE(edit1.text(), QString("item 0 0"));
QCOMPARE(edit2.text(), QString("item 0 1"));
QCOMPARE(edit3.text(), QString("item 0 0"));
edit1.setText("new text");
mapper.submit();
QCOMPARE(model->data(model->index(0, 0)).toString(), QString("new text"));
edit3.setText("more text");
mapper.submit();
QCOMPARE(model->data(model->index(0, 0)).toString(), QString("more text"));
}
示例13: 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++;
}
}
示例14:
void CSVRender::Object::apply (CSMWorld::CommandMacro& commands)
{
const CSMWorld::RefCollection& collection = mData.getReferences();
QAbstractItemModel *model = mData.getTableModel (CSMWorld::UniversalId::Type_References);
int recordIndex = collection.getIndex (mReferenceId);
if (mOverrideFlags & Override_Position)
{
for (int i=0; i<3; ++i)
{
int column = collection.findColumnIndex (static_cast<CSMWorld::Columns::ColumnId> (
CSMWorld::Columns::ColumnId_PositionXPos+i));
commands.push (new CSMWorld::ModifyCommand (*model,
model->index (recordIndex, column), mPositionOverride.pos[i]));
}
int column = collection.findColumnIndex (static_cast<CSMWorld::Columns::ColumnId> (
CSMWorld::Columns::ColumnId_Cell));
if (CSMWorld::CellCoordinates::isExteriorCell(collection.getRecord (recordIndex).get().mCell))
{
std::pair<int, int> cellIndex = collection.getRecord (recordIndex).get().getCellIndex();
/// \todo figure out worldspace (not important until multiple worldspaces are supported)
std::string cellId = CSMWorld::CellCoordinates (cellIndex).getId ("");
commands.push (new CSMWorld::ModifyCommand (*model,
model->index (recordIndex, column), QString::fromUtf8 (cellId.c_str())));
}
}
if (mOverrideFlags & Override_Rotation)
{
for (int i=0; i<3; ++i)
{
int column = collection.findColumnIndex (static_cast<CSMWorld::Columns::ColumnId> (
CSMWorld::Columns::ColumnId_PositionXRot+i));
commands.push (new CSMWorld::ModifyCommand (*model,
model->index (recordIndex, column), mPositionOverride.rot[i]));
}
}
if (mOverrideFlags & Override_Scale)
{
int column = collection.findColumnIndex (CSMWorld::Columns::ColumnId_Scale);
commands.push (new CSMWorld::ModifyCommand (*model,
model->index (recordIndex, column), mScaleOverride));
}
mOverrideFlags = 0;
}
示例15: itemSelected
//! [9] //! [10]
void AddressView::itemSelected(const QModelIndex &index)
{
if (!index.isValid())
return;
QAbstractItemModel *model = treeView->model();
iFirstName->setText(model->data(model->index(index.row(), 0)).toString());
iLastName->setText(model->data(model->index(index.row(), 1)).toString());
iAddress->setText(model->data(model->index(index.row(), 2)).toString());
iEMail->setText(model->data(model->index(index.row(), 3)).toString());
}