void CleanDialog::setFileList(const QString &workingDirectory, const QStringList &l) { d->m_workingDirectory = workingDirectory; d->ui.groupBox->setTitle(tr("Repository: %1"). arg(QDir::toNativeSeparators(workingDirectory))); if (const int oldRowCount = d->m_filesModel->rowCount()) d->m_filesModel->removeRows(0, oldRowCount); QStyle *style = QApplication::style(); const QIcon folderIcon = style->standardIcon(QStyle::SP_DirIcon); const QIcon fileIcon = style->standardIcon(QStyle::SP_FileIcon); const QString diffSuffix = QLatin1String(".diff"); const QString patchSuffix = QLatin1String(".patch"); const QString proUserSuffix = QLatin1String(".pro.user"); const QString qmlProUserSuffix = QLatin1String(".qmlproject.user"); const QChar slash = QLatin1Char('/'); // Do not initially check patches or 'pro.user' files for deletion. foreach(const QString &fileName, l) { const QFileInfo fi(workingDirectory + slash + fileName); const bool isDir = fi.isDir(); QStandardItem *nameItem = new QStandardItem(QDir::toNativeSeparators(fileName)); nameItem->setFlags(Qt::ItemIsUserCheckable|Qt::ItemIsEnabled); nameItem->setIcon(isDir ? folderIcon : fileIcon); const bool saveFile = !isDir && (fileName.endsWith(diffSuffix) || fileName.endsWith(patchSuffix) || fileName.endsWith(proUserSuffix) || fileName.endsWith(qmlProUserSuffix)); nameItem->setCheckable(true); nameItem->setCheckState(saveFile ? Qt::Unchecked : Qt::Checked); nameItem->setData(QVariant(fi.absoluteFilePath()), fileNameRole); nameItem->setData(QVariant(isDir), isDirectoryRole); // Tooltip with size information if (fi.isFile()) { const QString lastModified = fi.lastModified().toString(Qt::DefaultLocaleShortDate); nameItem->setToolTip(tr("%1 bytes, last modified %2") .arg(fi.size()).arg(lastModified)); } d->m_filesModel->appendRow(nameItem); } for (int c = 0; c < d->m_filesModel->columnCount(); c++) d->ui.filesTreeView->resizeColumnToContents(c); }
bool LogChangeWidget::populateLog(const QString &repository, const QString &commit, LogFlags flags) { const QString currentCommit = this->commit(); int selected = currentCommit.isEmpty() ? 0 : -1; if (const int rowCount = m_model->rowCount()) m_model->removeRows(0, rowCount); // Retrieve log using a custom format "Sha1:Subject [(refs)]" GitClient *client = GitPlugin::instance()->gitClient(); QStringList arguments; arguments << QLatin1String("--max-count=1000") << QLatin1String("--format=%h:%s %d"); arguments << (commit.isEmpty() ? QLatin1String("HEAD") : commit); if (!(flags & IncludeRemotes)) arguments << QLatin1String("--not") << QLatin1String("--remotes"); QString output; if (!client->synchronousLog(repository, arguments, &output, 0, VcsBasePlugin::NoOutput)) return false; foreach (const QString &line, output.split(QLatin1Char('\n'))) { const int colonPos = line.indexOf(QLatin1Char(':')); if (colonPos != -1) { QList<QStandardItem *> row; for (int c = 0; c < ColumnCount; ++c) { QStandardItem *item = new QStandardItem; item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable); if (line.endsWith(QLatin1Char(')'))) { QFont font = item->font(); font.setBold(true); item->setFont(font); } row.push_back(item); } const QString sha1 = line.left(colonPos); row[Sha1Column]->setText(sha1); row[SubjectColumn]->setText(line.right(line.size() - colonPos - 1)); m_model->appendRow(row); if (selected == -1 && currentCommit == sha1) selected = m_model->rowCount() - 1; } } setCurrentIndex(m_model->index(selected, 0)); return true; }
void SpellCheckWidget::copyUserDict() { // Get the current dictionary. if (!ui.userDictList->selectionModel()->hasSelection()) { return; } int row = ui.userDictList->selectionModel()->selectedIndexes().first().row(); QStandardItem *item = m_Model.item(row, 1); if (!item) { return; } // Get the current words, before creating so list doesn't change QStringList words; for (int i = 0; i < ui.userWordList->count(); ++i) { QString word = ui.userWordList->item(i)->text(); words.append(word); } // Create a new dictionary QStringList current_dicts; for (int row = 0; row < m_Model.rowCount(); ++row) { QStandardItem *item = m_Model.itemFromIndex(m_Model.index(row, 1)); current_dicts.append(item->text()); } QString dict_name = item->text(); while (current_dicts.contains(dict_name)) { dict_name += "_copy"; } if (!createUserDict(dict_name)) { return; } // Add the words to the dictionary foreach(QString word, words) { QListWidgetItem *item = new QListWidgetItem(word, ui.userWordList); item->setFlags(item->flags() | Qt::ItemIsEditable); ui.userWordList->addItem(item); }
void tst_QItemDelegate::editorEvent() { QFETCH(QRect, rect); QFETCH(QString, text); QFETCH(int, checkState); QFETCH(int, flags); QFETCH(bool, inCheck); QFETCH(int, type); QFETCH(int, button); QFETCH(bool, edited); QFETCH(int, expectedCheckState); QStandardItemModel model(1, 1); QModelIndex index = model.index(0, 0); QVERIFY(index.isValid()); QStandardItem *item = model.itemFromIndex(index); item->setText(text); item->setCheckState((Qt::CheckState)checkState); item->setFlags((Qt::ItemFlags)flags); QStyleOptionViewItem option; option.rect = rect; option.state |= QStyle::State_Enabled; const int checkMargin = qApp->style()->pixelMetric(QStyle::PM_FocusFrameHMargin, 0, 0) + 1; QPoint pos = inCheck ? qApp->style()->subElementRect(QStyle::SE_ViewItemCheckIndicator, &option, 0).center() + QPoint(checkMargin, 0) : QPoint(200,200); QEvent *event = new QMouseEvent((QEvent::Type)type, pos, (Qt::MouseButton)button, (Qt::MouseButton)button, Qt::NoModifier); TestItemDelegate delegate; bool wasEdited = delegate.editorEvent(event, &model, option, index); delete event; QApplication::processEvents(); QCOMPARE(wasEdited, edited); QCOMPARE(index.data(Qt::CheckStateRole).toInt(), expectedCheckState); }
bool PdmlHandler::startElement(const QString & /* namespaceURI */, const QString & /* localName */, const QString &qName, const QXmlAttributes &attributes) { qDebug("%s (%s)", __FUNCTION__, qName.toAscii().constData()); if (qName == "pdml") { packetCount = 0; } else if (qName == "packet") { currentItem = _model->item(packetCount, 0); } else if ((qName == "proto") || (qName == "field")) { QStandardItem *item; if (attributes.value("hide") == "yes") { skip = true; } else { QString val; val = attributes.value("showname"); if (val.isEmpty()) val = attributes.value("show"); if (!val.isEmpty()) { item = new QStandardItem(val); item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled); currentItem->appendRow(item); currentItem = item; //qDebug("ITEM(%p) --> %s", item, attributes.value("showname").toAscii().constData()); } else skip = true; } } return true; }
void ClassesDatas::read(const QJsonObject &json){ // Clear SuperListItem::deleteModel(m_model, false); // Read QJsonArray jsonList = json["classes"].toArray(); QStandardItem* item; SystemClass* sysClass; for (int i = 0; i < jsonList.size(); i++){ item = new QStandardItem; sysClass= new SystemClass; sysClass->read(jsonList[i].toObject()); item->setData(QVariant::fromValue( reinterpret_cast<quintptr>(sysClass))); item->setFlags(item->flags() ^ (Qt::ItemIsDropEnabled)); item->setText(sysClass->toString()); m_model->appendRow(item); } }
void MainWindow::setProjectsInMenu() { QStandardItem* parent = projectsModel->invisibleRootItem(); ProjectFactory* pf = &(ProjectFactory::getInstance()); for (Iterator<Project> it = pf->getIterator(); !(it.isDone()); it.next()) { QStandardItem* temp = new QStandardItem(it.current().getId()); // gonna need to manage those items, and delete them at the end of the process temp->setFlags(temp->flags() & ~Qt::ItemIsEditable); parent->appendRow(temp); //parent = temp; for(Iterator<Task> it2 = it.current().getIterator(); !(it2.isDone()); it2.next()) { QStandardItem* temp2 = new QStandardItem(it2.current().getId()); temp2->setFlags(temp2->flags() & ~Qt::ItemIsEditable); temp->appendRow(temp2); if (it2.current().getTaskType()==COMPOSITE) { for (Iterator<Task> it3 = dynamic_cast<CompositeTask&>(it2.current()).getIterator(); !(it3.isDone()); it3.next()) { injectSubTaskInModel(temp2,it3.current()); } } } } }
void ParserTreeItem::convertTo(QStandardItem *item) const { if (!item) return; QMap<SymbolInformation, ParserTreeItem::Ptr> map; // convert to map - to sort it CitSymbolInformations curHash = d->symbolInformations.constBegin(); CitSymbolInformations endHash = d->symbolInformations.constEnd(); while (curHash != endHash) { map.insert(curHash.key(), curHash.value()); ++curHash; } typedef QMap<SymbolInformation, ParserTreeItem::Ptr>::const_iterator MapCitSymbolInformations; // add to item MapCitSymbolInformations cur = map.constBegin(); MapCitSymbolInformations end = map.constEnd(); while (cur != end) { const SymbolInformation &inf = cur.key(); ParserTreeItem::Ptr ptr = cur.value(); QStandardItem *add = new QStandardItem(); Utils::setSymbolInformationToItem(inf, add); if (!ptr.isNull()) { // icon add->setIcon(ptr->icon()); // draggable if (!ptr->symbolLocations().isEmpty()) add->setFlags(add->flags() | Qt::ItemIsDragEnabled); // locations add->setData(Utils::locationsToRole(ptr->symbolLocations()), Constants::SymbolLocationsRole); } item->appendRow(add); ++cur; } }
void QgsDbTableModel::addTableEntry( QString type, QString schemaName, QString tableName, QString geometryColName, QString sql ) { //is there already a root item with the given scheme Name? QStandardItem* schemaItem; QList<QStandardItem*> schemaItems = findItems( schemaName, Qt::MatchExactly, 0 ); //there is already an item for this schema if ( schemaItems.size() > 0 ) { schemaItem = schemaItems.at( 0 ); } else //create a new toplevel item for this schema { schemaItem = new QStandardItem( schemaName ); schemaItem->setFlags( Qt::ItemIsEnabled ); invisibleRootItem()->setChild( invisibleRootItem()->rowCount(), schemaItem ); } //path to icon for specified type QString typeName; QGis::WkbType wkbType = qgisTypeFromDbType( type ); QIcon iconFile = iconForType( wkbType ); QList<QStandardItem*> childItemList; QStandardItem* schemaNameItem = new QStandardItem( schemaName ); schemaNameItem->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable ); QStandardItem* typeItem = new QStandardItem( QIcon( iconFile ), type ); typeItem->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable ); QStandardItem* tableItem = new QStandardItem( tableName ); tableItem->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable ); QStandardItem* geomItem = new QStandardItem( geometryColName ); geomItem->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable ); QStandardItem* sqlItem = new QStandardItem( sql ); sqlItem->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable ); childItemList.push_back( schemaNameItem ); childItemList.push_back( tableItem ); childItemList.push_back( typeItem ); childItemList.push_back( geomItem ); childItemList.push_back( sqlItem ); schemaItem->appendRow( childItemList ); ++mTableCount; }
void MSCalibrationForm::setCalibrateMethod( const adcontrols::MSCalibrateMethod& method ) { QStandardItemModel& model = *pModel_; ui->spinPolynomials->setValue( method.polynomialDegree() ); ui->spinMassTolerance->setValue( method.massToleranceDa() ); ui->spinMinimumRA->setValue( method.minimumRAPercent() ); ui->spinLowMass->setValue( method.lowMass() ); ui->spinHighMass->setValue( method.highMass() ); const adcontrols::MSReferences& references = method.references(); int nRows = static_cast<int>( references.size() ); if ( nRows < model.rowCount() ) model.removeRows( 0, model.rowCount() ); // make sure all clear model.setRowCount( nRows + 1 ); // be sure last empty line int row = 0; for ( auto& ref: references ) { std::wstring formula = ref.display_formula(); model.setData( model.index( row, c_formula ), qtwrapper::qstring::copy( formula ) ); model.setData( model.index( row, c_exact_mass ), ref.exact_mass() ); model.setData( model.index( row, c_enable ), ref.enable() ); QStandardItem * chk = model.itemFromIndex( model.index( row, c_enable ) ); if ( chk ) { chk->setFlags( Qt::ItemIsUserCheckable | Qt::ItemIsEnabled ); chk->setEditable( true ); model.setData( model.index( row, c_enable ), ref.enable() ? Qt::Checked : Qt::Unchecked, Qt::CheckStateRole ); } model.setData( model.index( row, c_description ), qtwrapper::qstring::copy( ref.description() ) ); model.setData( model.index( row, c_charge ), ref.charge_count() ); ++row; } }
static void PopulateDataContainerComboBox(AbstractFilter* filter, FilterParameter* filterParameter, QComboBox* dcCombo, DataContainerArrayProxy& dcaProxy) { FilterParameterType* fp = dynamic_cast<FilterParameterType*>(filterParameter); assert(fp != NULL); DataContainerArray::Pointer dca = filter->getDataContainerArray(); // Populate the DataContainerArray Combo Box with all the DataContainers QList<DataContainerProxy> dcList = dcaProxy.dataContainers.values(); QListIterator<DataContainerProxy> iter(dcList); dcCombo->clear(); QVector<unsigned int> defVec = fp->getDefaultGeometryTypes(); while(iter.hasNext() ) { DataContainerProxy dcProxy = iter.next(); DataContainer::Pointer dc = dca->getDataContainer(dcProxy.name); IGeometry::Pointer geom = IGeometry::NullPointer(); uint32_t geomType = 999; if (NULL != dc.get()) { geom = dc->getGeometry(); } if (NULL != geom.get()) { geomType = geom->getGeometryType(); } dcCombo->addItem(dcProxy.name); if (defVec.isEmpty() == false) { if (defVec.contains(geomType) == false) { QStandardItemModel* model = qobject_cast<QStandardItemModel*>(dcCombo->model()); if (NULL != model) { QStandardItem* item = model->item(dcCombo->findText(dcProxy.name)); if (NULL != item) { item->setFlags(item->flags() & ~Qt::ItemIsEnabled); } } } } } }
void StatusDatas::setDefault() { int i, length; SystemStatus *status; QStandardItem *item; QString names[] = { "KO" }; int iconsID[] = { -1 }; length = (sizeof(names)/sizeof(*names)); for (i = 0; i < length; i++) { status = new SystemStatus(i + 1, new LangsTranslation(names[i]), iconsID[i]); item = new QStandardItem; item->setData(QVariant::fromValue(reinterpret_cast<quintptr>(status))); item->setFlags(item->flags() ^ (Qt::ItemIsDropEnabled)); item->setText(status->toString()); m_model->appendRow(item); } }
QList<QStandardItem*> DkFileAssociationsPreference::getItems(const QString& filter, bool browse, bool reg) { QList<QStandardItem* > items; QStandardItem* item = new QStandardItem(filter); item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled); items.append(item); item = new QStandardItem(""); //item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsUserCheckable); item->setCheckable(true); item->setCheckState(browse ? Qt::Checked : Qt::Unchecked); items.append(item); item = new QStandardItem(""); //item->setFlags(Qt::Qt::ItemIsSelectable | Qt::ItemIsUserCheckable); item->setCheckable(true); item->setCheckState(reg ? Qt::Checked : Qt::Unchecked); #ifndef Q_OS_WIN // registering is windows only item->setEnabled(false); #endif items.append(item); return items; }
void QgsGraduatedSymbolRendererV2Widget::populateRanges() { QStandardItemModel* m = qobject_cast<QStandardItemModel*>( viewGraduated->model() ); m->clear(); mRowSelected = -1; QStringList labels; labels << tr( "Symbol" ) << tr( "Range" ) << tr( "Label" ); m->setHorizontalHeaderLabels( labels ); QSize iconSize( 16, 16 ); int i, count = mRenderer->ranges().count(); for ( i = 0; i < count; i++ ) { const QgsRendererRangeV2& range = mRenderer->ranges()[i]; QString rangeStr = QString::number( range.lowerValue(), 'f', 4 ) + " - " + QString::number( range.upperValue(), 'f', 4 ); QIcon icon = QgsSymbolLayerV2Utils::symbolPreviewIcon( range.symbol(), iconSize ); QStandardItem* item = new QStandardItem( icon, "" ); //item->setData(k); // set attribute value as user role item->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEnabled ); QStandardItem* item2 = new QStandardItem( rangeStr ); item2->setEditable( 0 ); QList<QStandardItem *> list; list << item << item2 << new QStandardItem( range.label() ); m->appendRow( list ); } // make sure that the "range" column has visible context viewGraduated->resizeColumnToContents( 0 ); }
void CookiesContentsWidget::addCookie(const QNetworkCookie &cookie) { const QString domain = (cookie.domain().startsWith('.') ? cookie.domain().mid(1) : cookie.domain()); QStandardItem *domainItem = findDomain(domain); if (domainItem) { for (int i = 0; i < domainItem->rowCount(); ++i) { if (domainItem->child(i, 0)->text() == cookie.name() && domainItem->child(i, 0)->data(Qt::UserRole).toString() == cookie.path()) { return; } } } else { domainItem = new QStandardItem(HistoryManager::getIcon(QUrl(QStringLiteral("http://%1/").arg(domain))), domain); domainItem->setToolTip(domain); m_model->appendRow(domainItem); if (sender()) { m_model->sort(0); } } QStandardItem *cookieItem = new QStandardItem(QString(cookie.name())); cookieItem->setData(cookie.path(), Qt::UserRole); cookieItem->setData(cookie.domain(), (Qt::UserRole + 1)); cookieItem->setToolTip(cookie.name()); cookieItem->setFlags(cookieItem->flags() | Qt::ItemNeverHasChildren); domainItem->appendRow(cookieItem); domainItem->setText(QStringLiteral("%1 (%2)").arg(domain).arg(domainItem->rowCount())); }
void tst_QItemDelegate::QTBUG4435_keepSelectionOnCheck() { QStandardItemModel model(3, 1); for (int i = 0; i < 3; ++i) { QStandardItem *item = new QStandardItem(QLatin1String("Item ") + QString::number(i)); item->setCheckable(true); item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsUserCheckable | Qt::ItemIsEnabled); model.setItem(i, item); } QTableView view; view.setModel(&model); view.setItemDelegate(new TestItemDelegate); view.show(); view.selectAll(); QTest::qWaitForWindowShown(&view); QStyleOptionViewItem option; option.rect = view.visualRect(model.index(0, 0)); const int checkMargin = qApp->style()->pixelMetric(QStyle::PM_FocusFrameHMargin, 0, 0) + 1; QPoint pos = qApp->style()->subElementRect(QStyle::SE_ViewItemCheckIndicator, &option, 0).center() + QPoint(checkMargin, 0); QTest::mouseClick(view.viewport(), Qt::LeftButton, Qt::ControlModifier, pos); QTRY_VERIFY(view.selectionModel()->isColumnSelected(0, QModelIndex())); QCOMPARE(model.item(0)->checkState(), Qt::Checked); }
void TagsDialog::on_edit_tag(const QModelIndex &index) { if(!index.isValid()) return; EditTagsDialog d(this); QString old_text =model_.item(index.row(), 1)->text(); d.set_text(old_text); if(d.exec() == QInputDialog::Accepted) { QString new_text = d.get_text(); if(old_text == new_text) return; if(new_text.isEmpty()) { QMessageBox::critical(&d, "Name", "This name already exists in database"); return; } for(int i=0; i<model_.rowCount(); ++i) { if(new_text == model_.item(i, 1)->text() && old_text != new_text) { QMessageBox::critical(&d, "Name", "This name already exists in database"); return; } } QStandardItem* newitem = new QStandardItem(d.get_text()); newitem->setFlags(newitem->flags() & ~Qt::ItemIsEditable); model_.setItem(index.row(), 1, newitem); } }
void MSCalibrationForm::handle_value_changed( const QModelIndex& index ) { QStandardItemModel& model = *pModel_; int row = index.row(); if ( index.column() == c_formula ) { adcontrols::MSReference ref; std::wstring text = model.index( row, c_formula ).data( Qt::EditRole ).toString().toStdWString(); if ( parse_formula( text, ref ) ) { model.setData( model.index( row, c_formula ), qtwrapper::qstring::copy( ref.formula() ) ); model.setData( model.index( row, c_exact_mass ), ref.exact_mass() ); model.setData( model.index( row, c_enable ), ref.enable() ); QStandardItem * chk = model.itemFromIndex( model.index( row, c_enable ) ); if ( chk ) { chk->setFlags( Qt::ItemIsUserCheckable | Qt::ItemIsEnabled ); chk->setEditable( true ); model.setData( model.index( row, c_enable ), ref.enable() ? Qt::Checked : Qt::Unchecked, Qt::CheckStateRole ); } model.setData( model.index( row, c_charge ), ref.charge_count() ); } } if ( row == model.rowCount() - 1 ) model.insertRow( row + 1); }
void TableViewModel::addNodeIntoModel( int rowNumber, QString type, QString text ) { // 將簡寫轉為單字 if (type == LETTER_ATTRIBUTE) type = TYPE_ATTRIBUTE; else if (type == LETTER_ENTITY) type = TYPE_ENTITY; else if (type == LETTER_RELATIONSHIP) type = TYPE_RELATIONSHIP; else type = TYPE_CONNECTOR; QStandardItem *typeItem = new QStandardItem(type); QStandardItem *textItem = new QStandardItem(text); // 設定type那欄不可點選、編輯 typeItem->setFlags(typeItem->flags() & ~Qt::ItemIsEditable & ~Qt::ItemIsSelectable); // 新增row QList<QStandardItem*> rowContent; rowContent << typeItem << textItem; //appendRow(row); insertRow(rowNumber, rowContent); }
void InterceptWidget::updateColumns() { QStringList columnList = model->getColumnNames(); QStandardItemModel *columnModel = new(std::nothrow) QStandardItemModel(columnList.size(), 1); if (columnModel == NULL ) { qFatal("Cannot allocate memory for QStandardItemModel X{"); return; } for (int i = 0; i < columnList.size(); ++i) { QStandardItem* item = NULL; item = new(std::nothrow) QStandardItem(columnList.at(i)); if (item != NULL) { item->setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled); item->setData( (packetsTable->isColumnHidden(i) ? Qt::Unchecked : Qt::Checked), Qt::CheckStateRole); columnModel->setItem(i, 0, item); } else { qFatal("Cannot allocate memory for QStandardItem 2 X{"); } } connect(columnModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)), SLOT(onColumnChanged(QModelIndex,QModelIndex))); ui->columnListWidget->setModel(columnModel); }
void SelectSiteDialog::initializeTable() { model = new QStandardItemModel(importedSites.size(), 1, this); QStandardItem *item; QStringList verticalHeader; int row = 0; foreach(QSharedPointer<Site> site, importedSites) { verticalHeader.append(QString::number(row + 1)); item = new QStandardItem(site.data()->siteDetails.Csc); item->setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled); item->setData(QVariant(QString::number(site.data()->siteDetails.SwpId)), DataType::SWP_ID); item->setCheckable(true); item->setTextAlignment(Qt::AlignJustify); item->setCheckState(Qt::Unchecked); item->setBackground(QColor(Qt::white)); item->setForeground(QColor(Qt::black)); model->setItem(row, 0, item); row++; }
QStandardItem *CSceneExplorer::createItem(int id, const ENodeType type, const QString &label) { QIcon *icon = 0; QStandardItem *item = 0; if(type == ENT_PROP_MODEL) { icon = &m_propIcon; } else if(type == ENT_PROP_POWERUP) { icon = &m_powerupIcon; } else if(type == ENT_PROP_PARTICLE) { icon = &m_particleIcon; } else if(type == ENT_LIGHT) { icon = &m_lightIcon; } else if(type == ENT_LOGIC_CAMERA) { icon = &m_cameraIcon; } else if(type == ENT_LOGIC_TRIGGER) { icon = &m_logicIcon; } else if(type == ENT_LOGIC_VECTOR) { icon = &m_logicIcon; } else if(type == ENT_LOGIC_CONSTRAINT) { icon = &m_logicIcon; } else if(type == ENT_MAP) { icon = &m_mapIcon; } if(icon) { item = new QStandardItem(*icon, label); item->setData(QVariant(id), Qt::UserRole + 1); item->setFlags(item->flags() & ~Qt::ItemIsEditable); } return item; }
/** Creates a StandardItemModel with the queried drugs. Items userData are DrugID. */ QStandardItemModel *DrugInteractionQuery::toStandardModel() const { if (!m_StandardModel) { m_StandardModel = new QStandardItemModel; } // for all drugs QFont bold; bold.setBold(true); QVector<IDrug *> insertedDrugs; for(int i=0; i < m_Drugs.count(); ++i) { IDrug *drug = m_Drugs.at(i); if (insertedDrugs.contains(drug)) continue; insertedDrugs.append(drug); // add a root item QStandardItem *root = new QStandardItem(drug->brandName()); root->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable); root->setData(drug->drugId()); m_StandardModel->appendRow(root); // TODO: foreach component of the drug, append total daily dose } return m_StandardModel; }
void addChildrentofile(QStandardItem *parent) { // QStandardItem *logsitem = new QStandardItem("Logs"); logsitem->setFlags(logsitem->flags() ^ Qt::ItemIsEditable); parent->appendRow(logsitem ); //add lognames and count QStandardItem *rangeitem = new QStandardItem("RANGE(100)"); rangeitem->setFlags((rangeitem->flags()|Qt::ItemIsUserCheckable) ^ Qt::ItemIsEditable); rangeitem->setCheckState(Qt::Checked); logsitem->appendRow(rangeitem); QStandardItem *bestpositem = new QStandardItem("BESTPOS(50)"); bestpositem->setFlags((bestpositem->flags()|Qt::ItemIsUserCheckable) ^ Qt::ItemIsEditable); bestpositem->setCheckState(Qt::Checked); logsitem->appendRow(bestpositem); QStandardItem *constellationsitem = new QStandardItem("Constellations"); constellationsitem->setFlags(constellationsitem->flags() ^ Qt::ItemIsEditable); parent->appendRow(constellationsitem ); QStandardItem *signalsitem = new QStandardItem("Signals"); signalsitem->setFlags(signalsitem->flags() ^ Qt::ItemIsEditable); parent->appendRow(signalsitem); QStandardItem *prnsitem = new QStandardItem("Prns"); prnsitem->setFlags(prnsitem->flags() ^ Qt::ItemIsEditable); parent->appendRow(prnsitem); QStandardItem *timeitem = new QStandardItem("Time"); timeitem->setFlags(timeitem->flags() ^ Qt::ItemIsEditable); parent->appendRow(timeitem); }
static QStandardItem *createEditableItem(const QString &text) { QStandardItem *rc = new QStandardItem(text); rc->setFlags(Qt::ItemIsEnabled|Qt::ItemIsEditable|Qt::ItemIsSelectable); return rc; }
void QgsOracleTableModel::addTableEntry( const QgsOracleLayerProperty &layerProperty ) { QgsDebugMsg( layerProperty.toString() ); if ( layerProperty.isView && layerProperty.pkCols.isEmpty() ) { QgsDebugMsg( "View without pk skipped." ); return; } // is there already a root item with the given scheme Name? QStandardItem *ownerItem = 0; for ( int i = 0; i < layerProperty.size(); i++ ) { QGis::WkbType wkbType = layerProperty.types[ i ]; int srid = layerProperty.srids[ i ]; QString tip; if ( wkbType == QGis::WKBUnknown ) { tip = tr( "Specify a geometry type" ); } else if ( wkbType != QGis::WKBNoGeometry && srid == 0 ) { tip = tr( "Enter a SRID" ); } if ( tip.isEmpty() && layerProperty.isView ) { tip = tr( "Select a primary key" ); } QStandardItem *ownerNameItem = new QStandardItem( layerProperty.ownerName ); QStandardItem *typeItem = new QStandardItem( iconForWkbType( wkbType ), wkbType == QGis::WKBUnknown ? tr( "Select..." ) : QgsOracleConn::displayStringForWkbType( wkbType ) ); typeItem->setData( wkbType == QGis::WKBUnknown, Qt::UserRole + 1 ); typeItem->setData( wkbType, Qt::UserRole + 2 ); if ( wkbType == QGis::WKBUnknown ) typeItem->setFlags( typeItem->flags() | Qt::ItemIsEditable ); QStandardItem *tableItem = new QStandardItem( layerProperty.tableName ); QStandardItem *geomItem = new QStandardItem( layerProperty.geometryColName ); QStandardItem *sridItem = new QStandardItem( wkbType != QGis::WKBNoGeometry ? QString::number( srid ) : "" ); sridItem->setEditable( wkbType != QGis::WKBNoGeometry && srid == 0 ); if ( sridItem->isEditable() ) { sridItem->setText( tr( "Enter..." ) ); sridItem->setFlags( sridItem->flags() | Qt::ItemIsEditable ); } QStandardItem *pkItem = new QStandardItem( "" ); if ( layerProperty.isView ) { pkItem->setText( tr( "Select..." ) ); pkItem->setFlags( pkItem->flags() | Qt::ItemIsEditable ); } else pkItem->setFlags( pkItem->flags() & ~Qt::ItemIsEditable ); pkItem->setData( layerProperty.isView, Qt::UserRole + 1 ); pkItem->setData( false, Qt::UserRole + 2 ); // not selected QStandardItem *selItem = new QStandardItem( "" ); selItem->setFlags( selItem->flags() | Qt::ItemIsUserCheckable ); selItem->setCheckState( Qt::Checked ); selItem->setToolTip( tr( "Disable 'Fast Access to Features at ID' capability to force keeping the attribute table in memory (e.g. in case of expensive views)." ) ); QStandardItem* sqlItem = new QStandardItem( layerProperty.sql ); QList<QStandardItem*> childItemList; childItemList << ownerNameItem; childItemList << tableItem; childItemList << typeItem; childItemList << geomItem; childItemList << sridItem; childItemList << pkItem; childItemList << selItem; childItemList << sqlItem; foreach ( QStandardItem *item, childItemList ) { if ( tip.isEmpty() ) { item->setFlags( item->flags() | Qt::ItemIsSelectable | Qt::ItemIsEnabled ); item->setToolTip( "" ); } else { item->setFlags( item->flags() & ~Qt::ItemIsSelectable ); if ( item == ownerNameItem || item == tableItem || item == geomItem ) { item->setFlags( item->flags() & ~Qt::ItemIsEnabled ); item->setToolTip( tip ); } } } if ( !ownerItem ) { QList<QStandardItem*> ownerItems = findItems( layerProperty.ownerName, Qt::MatchExactly, dbtmOwner ); // there is already an item for this schema if ( ownerItems.size() > 0 ) { ownerItem = ownerItems.at( dbtmOwner ); } else { // create a new toplevel item for this schema ownerItem = new QStandardItem( layerProperty.ownerName ); ownerItem->setFlags( Qt::ItemIsEnabled ); invisibleRootItem()->setChild( invisibleRootItem()->rowCount(), ownerItem ); } } ownerItem->appendRow( childItemList ); ++mTableCount; } }
void MainWindow::buildTree(QDomNode doc, QStandardItemModel* model, QStandardItem *item, QList<int> *nbChildren, int childNumber, QList<int> *currentChild, int currentLevel) { //check if doc is not empty if(!doc.isNull()) { QStandardItem *itemUpdated = item; int nbAttributes = 0; nbAttributesMax(doc, &nbAttributes); //append root to model if(currentLevel == -1) { QList<QStandardItem*> list; list.append(item); for(int i = 0; i < nbAttributes; i++) { QStandardItem *newItem = new QStandardItem(""); newItem->setFlags(newItem->flags() & ~Qt::ItemIsEditable); list.append(newItem); } model->appendRow(list); } //append everything but root to model else { if(!doc.isComment()) { //get the parent to the node we want to add to the model QList<QStandardItem*> list; for(int i = 0; i < currentLevel; i++) { itemUpdated = itemUpdated->child(currentChild->at(i)); } addColumnModel(model, doc); getTagAttributes(&list, doc); //append the list itemUpdated->appendRow(list); } else { for(int i = 0; i < currentLevel; i++) { itemUpdated = itemUpdated->child(currentChild->at(i)); } QStandardItem *newItem = new QStandardItem("(Comment) " + doc.nodeValue()); newItem->setFlags(newItem->flags() & ~Qt::ItemIsEditable); itemUpdated->appendRow(newItem); } } //if the node has at least one child get all the children and add them to the model if(!doc.childNodes().isEmpty() && (doc.firstChild().toElement().tagName() != "" || doc.firstChild().isComment())) { //get the children QDomNodeList nodeList = doc.childNodes(); //update the level and store the number of children currentLevel++; (*nbChildren)[currentLevel] = nodeList.length(); //for each child add the child and its children to the model for(int i = 0; i < (*nbChildren)[currentLevel]; i++) { (*currentChild)[currentLevel] = i; buildTree(nodeList.at(i), model, item, nbChildren, i, currentChild, currentLevel); } } //if the current node doesn't have any children the previous level need to be updated else { //the level which must be updated is the first one which is not equal to the //number of children of its level (if we start by the last level scanned) int ii = 1; if(currentLevel >= 1 && childNumber == (*nbChildren)[currentLevel] - 1) { while((*currentChild)[currentLevel-ii] == (*nbChildren)[currentLevel-ii] && ii <= currentLevel) { ii++; } //if currentLevel-ii is < 0, it means that all the children of the previous levels have been scanned if(ii <= currentLevel) { (*currentChild)[currentLevel-ii] += 1; } } } } }
// -------------------------------------------------------------------------- void voDelimitedTextPreviewModel::updatePreview() { Q_D(voDelimitedTextPreviewModel); if (d->SampleCacheFile.fileName().isEmpty()) { //qWarning() << QObject::tr("ERROR: updatePreview: SampleCacheFile filename not set"); return; } // Setup vtkDelimitedTextReader vtkNew<vtkDelimitedTextReader> previewReader; d->configureReader(previewReader.GetPointer()); // Read in file to table previewReader->Update(); vtkSmartPointer<vtkTable> table = previewReader->GetOutput(); if (d->Transpose) { // Assumes there is a header column ... which we have no setting to specify for anyway voUtils::transposeTable(table); } // Build model (self) this->clear(); // Clear original data table while (d->OriginalDataTable->GetNumberOfColumns() > 0) { d->OriginalDataTable->RemoveColumn(d->OriginalDataTable->GetNumberOfColumns() - 1); // columns should be named } // Update metadata preview and set DataTable QColor headerBackgroundColor = QPalette().color(QPalette::Window); QColor ofInterestBackgroundColor = QPalette().color(QPalette::Mid); for (vtkIdType cid = 0; cid < table->GetNumberOfColumns(); ++cid) { vtkStringArray * column = vtkStringArray::SafeDownCast(table->GetColumn(cid)); Q_ASSERT(column); vtkSmartPointer<vtkStringArray> dataColumn; if (cid >= d->NumberOfRowMetaDataTypes) { dataColumn = vtkSmartPointer<vtkStringArray>::New(); dataColumn->SetName(QString::number(cid - d->NumberOfRowMetaDataTypes + 1).toLatin1()); dataColumn->SetNumberOfValues(column->GetNumberOfValues() - d->NumberOfColumnMetaDataTypes); } for (int rid = 0; rid < column->GetNumberOfValues(); ++rid) { QString value = QString(column->GetValue(rid)); QStandardItem* currentItem = 0; if (rid == d->ColumnMetaDataTypeOfInterest || cid == d->RowMetaDataTypeOfInterest) { this->setItem(rid, cid, (currentItem = new QStandardItem(value))); currentItem->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable); currentItem->setData(ofInterestBackgroundColor, Qt::BackgroundRole); } else if (rid < d->NumberOfColumnMetaDataTypes || cid < d->NumberOfRowMetaDataTypes) { this->setItem(rid, cid, (currentItem = new QStandardItem(value))); currentItem->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable); currentItem->setData(headerBackgroundColor, Qt::BackgroundRole); } else { dataColumn->SetValue(rid - d->NumberOfColumnMetaDataTypes, value.toLatin1()); } } if (cid >= d->NumberOfRowMetaDataTypes) { d->OriginalDataTable->AddColumn(dataColumn.GetPointer()); } } // TODO: Add missing value identification/rectification step vtkNew<vtkStringToNumeric> numericToStringFilter; numericToStringFilter->SetInputData(d->OriginalDataTable.GetPointer()); numericToStringFilter->Update(); vtkTable * numericDataTable = vtkTable::SafeDownCast(numericToStringFilter->GetOutput()); Q_ASSERT(numericDataTable); d->OriginalDataTable = numericDataTable; // Remove data table observer, copy data, and re-add observer d->DataTable->RemoveObserver(d->UpdateDataPreviewCallbackCommand); this->resetDataTable(); d->DataTable->AddObserver(vtkCommand::ModifiedEvent, d->UpdateDataPreviewCallbackCommand); d->updateDataPreview(); }
void QgsPgTableModel::addTableEntry( const QgsPostgresLayerProperty &layerProperty ) { QgsDebugMsg( layerProperty.toString() ); // is there already a root item with the given scheme Name? QStandardItem *schemaItem = nullptr; for ( int i = 0; i < layerProperty.size(); i++ ) { QgsWkbTypes::Type wkbType = layerProperty.types[ i ]; int srid = layerProperty.srids[ i ]; if ( wkbType == QgsWkbTypes::Unknown && layerProperty.geometryColName.isEmpty() ) { wkbType = QgsWkbTypes::NoGeometry; } QString tip; if ( wkbType == QgsWkbTypes::Unknown ) { tip = tr( "Specify a geometry type in the '%1' column" ).arg( tr( "Data Type" ) ); } else if ( wkbType != QgsWkbTypes::NoGeometry && srid == INT_MIN ) { tip = tr( "Enter a SRID into the '%1' column" ).arg( tr( "SRID" ) ); } else if ( !layerProperty.pkCols.isEmpty() ) { tip = tr( "Select columns in the '%1' column that uniquely identify features of this layer" ).arg( tr( "Feature id" ) ); } QStandardItem *schemaNameItem = new QStandardItem( layerProperty.schemaName ); QStandardItem *typeItem = new QStandardItem( iconForWkbType( wkbType ), wkbType == QgsWkbTypes::Unknown ? tr( "Select..." ) : QgsPostgresConn::displayStringForWkbType( wkbType ) ); typeItem->setData( wkbType == QgsWkbTypes::Unknown, Qt::UserRole + 1 ); typeItem->setData( wkbType, Qt::UserRole + 2 ); if ( wkbType == QgsWkbTypes::Unknown ) typeItem->setFlags( typeItem->flags() | Qt::ItemIsEditable ); QStandardItem *geomTypeItem = new QStandardItem( QgsPostgresConn::displayStringForGeomType( layerProperty.geometryColType ) ); QStandardItem *tableItem = new QStandardItem( layerProperty.tableName ); QStandardItem *commentItem = new QStandardItem( layerProperty.tableComment ); QStandardItem *geomItem = new QStandardItem( layerProperty.geometryColName ); QStandardItem *sridItem = new QStandardItem( wkbType != QgsWkbTypes::NoGeometry ? QString::number( srid ) : QLatin1String( "" ) ); sridItem->setEditable( wkbType != QgsWkbTypes::NoGeometry && srid == INT_MIN ); if ( sridItem->isEditable() ) { sridItem->setText( tr( "Enter..." ) ); sridItem->setFlags( sridItem->flags() | Qt::ItemIsEditable ); } QStandardItem *pkItem = new QStandardItem( QLatin1String( "" ) ); if ( !layerProperty.pkCols.isEmpty() ) { pkItem->setText( tr( "Select..." ) ); pkItem->setFlags( pkItem->flags() | Qt::ItemIsEditable ); } else pkItem->setFlags( pkItem->flags() & ~Qt::ItemIsEditable ); pkItem->setData( layerProperty.pkCols, Qt::UserRole + 1 ); pkItem->setData( "", Qt::UserRole + 2 ); QStandardItem *selItem = new QStandardItem( QLatin1String( "" ) ); selItem->setFlags( selItem->flags() | Qt::ItemIsUserCheckable ); selItem->setCheckState( Qt::Checked ); selItem->setToolTip( tr( "Disable 'Fast Access to Features at ID' capability to force keeping the attribute table in memory (e.g. in case of expensive views)." ) ); QStandardItem *sqlItem = new QStandardItem( layerProperty.sql ); QList<QStandardItem *> childItemList; childItemList << schemaNameItem; childItemList << tableItem; childItemList << commentItem; childItemList << geomItem; childItemList << geomTypeItem; childItemList << typeItem; childItemList << sridItem; childItemList << pkItem; childItemList << selItem; childItemList << sqlItem; Q_FOREACH ( QStandardItem *item, childItemList ) { if ( tip.isEmpty() ) { item->setFlags( item->flags() | Qt::ItemIsSelectable ); item->setToolTip( QLatin1String( "" ) ); } else { item->setFlags( item->flags() & ~Qt::ItemIsSelectable ); if ( item == schemaNameItem ) item->setData( QgsApplication::getThemeIcon( QStringLiteral( "/mIconWarning.svg" ) ), Qt::DecorationRole ); if ( item == schemaNameItem || item == tableItem || item == geomItem ) { item->setToolTip( tip ); } } } if ( !schemaItem ) { QList<QStandardItem *> schemaItems = findItems( layerProperty.schemaName, Qt::MatchExactly, DbtmSchema ); // there is already an item for this schema if ( !schemaItems.isEmpty() ) { schemaItem = schemaItems.at( DbtmSchema ); } else { // create a new toplevel item for this schema schemaItem = new QStandardItem( layerProperty.schemaName ); schemaItem->setFlags( Qt::ItemIsEnabled ); invisibleRootItem()->setChild( invisibleRootItem()->rowCount(), schemaItem ); } } schemaItem->appendRow( childItemList ); ++mTableCount; } }
bool QgsPgTableModel::setData( const QModelIndex &idx, const QVariant &value, int role ) { if ( !QStandardItemModel::setData( idx, value, role ) ) return false; if ( idx.column() == DbtmType || idx.column() == DbtmSrid || idx.column() == DbtmPkCol ) { QgsWkbTypes::Type wkbType = ( QgsWkbTypes::Type ) idx.sibling( idx.row(), DbtmType ).data( Qt::UserRole + 2 ).toInt(); QString tip; if ( wkbType == QgsWkbTypes::Unknown ) { tip = tr( "Specify a geometry type in the '%1' column" ).arg( tr( "Data Type" ) ); } else if ( wkbType != QgsWkbTypes::NoGeometry ) { bool ok; int srid = idx.sibling( idx.row(), DbtmSrid ).data().toInt( &ok ); if ( !ok || srid == INT_MIN ) tip = tr( "Enter a SRID into the '%1' column" ).arg( tr( "SRID" ) ); } QStringList pkCols = idx.sibling( idx.row(), DbtmPkCol ).data( Qt::UserRole + 1 ).toStringList(); if ( tip.isEmpty() && !pkCols.isEmpty() ) { QSet<QString> s0( idx.sibling( idx.row(), DbtmPkCol ).data( Qt::UserRole + 2 ).toStringList().toSet() ); QSet<QString> s1( pkCols.toSet() ); if ( s0.intersect( s1 ).isEmpty() ) tip = tr( "Select columns in the '%1' column that uniquely identify features of this layer" ).arg( tr( "Feature id" ) ); } for ( int i = 0; i < DbtmColumns; i++ ) { QStandardItem *item = itemFromIndex( idx.sibling( idx.row(), i ) ); if ( tip.isEmpty() ) { if ( i == DbtmSchema ) { item->setData( QVariant(), Qt::DecorationRole ); } item->setFlags( item->flags() | Qt::ItemIsSelectable ); item->setToolTip( QLatin1String( "" ) ); } else { item->setFlags( item->flags() & ~Qt::ItemIsSelectable ); if ( i == DbtmSchema ) item->setData( QgsApplication::getThemeIcon( QStringLiteral( "/mIconWarning.svg" ) ), Qt::DecorationRole ); if ( i == DbtmSchema || i == DbtmTable || i == DbtmGeomCol ) { item->setFlags( item->flags() ); item->setToolTip( tip ); } } } } return true; }