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; }
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); } }
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; }
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); } }
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& ) ) ); }
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; }
//----------------------------------------------------------------------------- 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(); }
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; }
//----------------------------------------------------------------------------- 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; }
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); }
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(); }
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() ); }
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); }
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(); }
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; } }
CEphTable::CEphTable(QWidget *parent, QString name, QStringList header, QList<tableRow_t> row) : QDialog(parent), ui(new Ui::CEphTable) { ui->setupUi(this); m_name = name; setWindowTitle(tr("Ephemerides of ") + name); QStandardItemModel *m = new QStandardItemModel(0, header.count()); for (int i = 0; i < header.count(); i++) { m->setHeaderData(i, Qt::Horizontal, header[i]); } for (int i = 0; i < row.count(); i++) { QList <QStandardItem *> items; for (int j = 0; j < row[i].row.count(); j++) { QStandardItem *itm = new QStandardItem; itm->setText(row[i].row[j]); items.append(itm); } m->appendRow(items); } ui->tableView->setModel(m); }
ActionComboBoxWidget::ActionComboBoxWidget(QWidget *parent) : QComboBox(parent), m_view(new ItemViewWidget(this)), m_filterLineEdit(NULL), m_wasPopupVisible(false) { setEditable(true); setView(m_view); setItemDelegate(new ItemDelegate(this)); m_view->setHeaderHidden(true); lineEdit()->hide(); view()->viewport()->parentWidget()->installEventFilter(this); QStandardItemModel *model = new QStandardItemModel(this); const QVector<ActionDefinition> definitions = ActionsManager::getActionDefinitions(); for (int i = 0; i < definitions.count(); ++i) { QStandardItem *item = new QStandardItem(definitions.at(i).icon, QCoreApplication::translate("actions", (definitions.at(i).description.isEmpty() ? definitions.at(i).text : definitions.at(i).description).toUtf8().constData())); item->setData(definitions.at(i).identifier, Qt::UserRole); item->setToolTip(ActionsManager::getActionName(definitions.at(i).identifier)); item->setFlags(item->flags() | Qt::ItemNeverHasChildren); model->appendRow(item); } setModel(model); setCurrentIndex(-1); }
void GeneratorScriptView::addScripts(const types::ScriptList & scriptlist) { if(model()) { model()->deleteLater(); } QStandardItemModel * model = new QStandardItemModel(); QStringList headerlabels; headerlabels << tr("Name") << tr("Last Edited") << tr("API Level"); model->setHorizontalHeaderLabels(headerlabels); foreach(const Script & script, scriptlist) { QList<QStandardItem*> row; QStandardItem * name = new QStandardItem(script.name); QStandardItem * edited = new QStandardItem(script.lastEdited.toString(global::DateFormat)); QStandardItem * apilevel = new QStandardItem(QString::number(script.apilevel)); name->setData(script.author, RoleAuthor); name->setData(script.description, RoleDescription); name->setData(script.program, RoleProgram); name->setData(script.version, RoleVersion); row << name << edited << apilevel; model->appendRow(row); }
EventEditTest::EventEditTest() { qRegisterMetaType<Akonadi::Collection>(); qRegisterMetaType<KMime::Message::Ptr>(); qRegisterMetaType<KCalCore::Event::Ptr>(); QStandardPaths::setTestModeEnabled(true); QStandardItemModel *model = new QStandardItemModel; for (int id = 42; id < 51; ++id) { Akonadi::Collection collection(id); collection.setRights(Akonadi::Collection::AllRights); collection.setName(QString::number(id)); collection.setContentMimeTypes(QStringList() << KCalCore::Event::eventMimeType()); QStandardItem *item = new QStandardItem(collection.name()); item->setData(QVariant::fromValue(collection), Akonadi::EntityTreeModel::CollectionRole); item->setData(QVariant::fromValue(collection.id()), Akonadi::EntityTreeModel::CollectionIdRole); model->appendRow(item); } MessageViewer::_k_eventEditStubModel = model; // Fake a default-selected collection for shouldHaveDefaultValuesOnCreation test MessageViewer::MessageViewerSettingsBase::self()->setLastEventSelectedFolder(43); }
void MainWidget::setIconWidgetPath(QString path) { QStandardItemModel* fModel = qobject_cast<QStandardItemModel*>(iView->model()); if(!fModel) { fModel = new QStandardItemModel; iView->setModel(fModel); } fModel->clear(); QStringList filter; filter<<QString("*.jpeg")<<QString("*.jpg")<<QString("*.png")<<QString("*.gif")<<QString("*.bmp"); QDirIterator dir_iter(path, filter, QDir::Files | QDir::NoSymLinks, QDirIterator::NoIteratorFlags); if(dir_iter.hasNext()){ while(dir_iter.hasNext()){ dir_iter.next(); QString file = dir_iter.fileInfo().absoluteFilePath(); QImage img(file); if(!img.isNull()){ QPixmap pix = QPixmap::fromImage(img); if(pix.size().width() > 300 || pix.size().height()>300){ pix = pix.scaled(200,200, Qt::KeepAspectRatio); //,Qt::SmoothTransformation) } QStandardItem* item = new QStandardItem(QIcon(pix),file.mid(file.lastIndexOf("/")+1)); item->setData(QVariant(file),Qt::WhatsThisRole); fModel->appendRow(item); } } } }
void tst_QItemDelegate::doubleEditorNegativeInput() { QStandardItemModel model; QStandardItem *item = new QStandardItem; item->setData(10.0, Qt::DisplayRole); model.appendRow(item); QListView view; view.setModel(&model); view.show(); QModelIndex index = model.index(0, 0); view.setCurrentIndex(index); // the editor will only selectAll on the current index view.edit(index); QList<QDoubleSpinBox*> editors = qFindChildren<QDoubleSpinBox *>(view.viewport()); QCOMPARE(editors.count(), 1); QDoubleSpinBox *editor = editors.at(0); QCOMPARE(editor->value(), double(10)); QTest::keyClick(editor, Qt::Key_Minus); QTest::keyClick(editor, Qt::Key_1); QTest::keyClick(editor, Qt::Key_0); QTest::keyClick(editor, Qt::Key_Comma); //support both , and . locales QTest::keyClick(editor, Qt::Key_Period); QTest::keyClick(editor, Qt::Key_0); QTest::keyClick(editor, Qt::Key_Enter); QApplication::processEvents(); QCOMPARE(index.data().toString(), QString("-10")); }
void BAbstractFileType::showAutocompletionMenu(BAbstractCodeEditorDocument *doc, QTextCursor cursor, const QPoint &) { if (cursor.isNull()) return; QCompleter *completer = doc->findChild<QCompleter *>("beqt/completer"); cursor.select(QTextCursor::WordUnderCursor); if (!cursor.hasSelection()) { if (completer) completer->popup()->hide(); return; } QList<AutocompletionItem> list = createAutocompletionItemList(doc, cursor); if (list.isEmpty()) { if (completer) completer->popup()->hide(); return; } QStandardItemModel *model = doc->findChild<QStandardItemModel *>("beqt/completion_model"); if (!model) { model = new QStandardItemModel(doc); model->setObjectName("beqt/completion_model"); model->setColumnCount(1); } model->clear(); foreach (const AutocompletionItem &item, list) { QStandardItem *si = new QStandardItem(item.actionIcon, item.actionText); si->setData(item.actionToolTip, Qt::ToolTipRole); si->setData(item.text, Qt::UserRole); model->appendRow(si); }
PluginManagerWidget::PluginManagerWidget(QWidget *parent) : QWidget(parent) , m_ui(new Ui::PluginManagerWidget) { m_ui->setupUi(this); QStandardItemModel *model = new QStandardItemModel(this); for (const QString& name : PluginLoader::instance().availablePlugins()) { model->appendRow(new QStandardItem(PluginLoader::instance().plugin(name)->icon(), name)); } QSortFilterProxyModel *proxyModel = new QSortFilterProxyModel(this); proxyModel->setSourceModel(model); model->sort(0, Qt::AscendingOrder); m_ui->PluginList->setModel(model); m_ui->PluginList->setItemDelegate(new PluginWidgetDelegate(m_ui->PluginList)); m_ui->PluginList->setSelectionMode(QAbstractItemView::SingleSelection); m_ui->PluginList->setEditTriggers(QAbstractItemView::NoEditTriggers); connect(m_ui->PluginList, SIGNAL(clicked(const QModelIndex&)), this, SLOT(onIndexChanged(const QModelIndex&))); const QModelIndex& index =model->index(0, 0); m_ui->PluginList->selectionModel()->select(index, QItemSelectionModel::Select); onIndexChanged(index); }
void LuaEditor::initeModel() { static bool inite = false; QStandardItemModel *model = kinfo->getModel(); if (!inite) { completer->setModel(model); completer->popup()->setStyleSheet("QToolTip { border: 1px solid #2c2c2c; background-color: #242424; color: white;}"); completer->setMaxVisibleItems(9); completer->setCaseSensitivity(Qt::CaseInsensitive); completer->setWrapAround(false); // add lua keywords into the model QStringList luaKeys; luaKeys << "and" << "break" << "do" << "false" << "for" << "function" << "local" << "nil" << "not" << "then" << "true" << "until" << "else" << "elseif" << "in" << "goto" << "if" << "return" << "or" << "repeat" << "while" << "end" << "engine" << "self" << "owner" << "global" << "messenger"; for (auto it = luaKeys.begin(); it != luaKeys.end(); ++it) { model->appendRow(new QStandardItem(QIcon(":/icons/key16"), (*it))); } inite = true; } }
void QgsVectorLayerLegendWidget::populateLegendTreeView( const QHash<QString, QString> &content ) { QStandardItemModel *model = new QStandardItemModel; model->setColumnCount( 2 ); model->setHorizontalHeaderLabels( QStringList() << tr( "Symbol" ) << tr( "Text" ) ); const QgsLegendSymbolList lst = mLayer->renderer() ? mLayer->renderer()->legendSymbolItems() : QgsLegendSymbolList(); for ( const QgsLegendSymbolItem &symbolItem : lst ) { if ( !symbolItem.symbol() ) continue; QgsRenderContext context; QSize iconSize( 16, 16 ); QIcon icon = QgsSymbolLayerUtils::symbolPreviewPixmap( symbolItem.symbol(), iconSize, 0, &context ); QStandardItem *item1 = new QStandardItem( icon, symbolItem.label() ); item1->setEditable( false ); QStandardItem *item2 = new QStandardItem; if ( symbolItem.ruleKey().isEmpty() ) { item1->setEnabled( false ); item2->setEnabled( false ); } else { item1->setData( symbolItem.ruleKey() ); if ( content.contains( symbolItem.ruleKey() ) ) item2->setText( content.value( symbolItem.ruleKey() ) ); } model->appendRow( QList<QStandardItem *>() << item1 << item2 ); } mLegendTreeView->setModel( model ); mLegendTreeView->resizeColumnToContents( 0 ); }
void tst_QItemDelegate::editorKeyPress() { QFETCH(QString, initial); QFETCH(QString, expected); QStandardItemModel model; model.appendRow(new QStandardItem(initial)); QListView view; view.setModel(&model); view.show(); QModelIndex index = model.index(0, 0); view.setCurrentIndex(index); // the editor will only selectAll on the current index view.edit(index); QList<QLineEdit*> lineEditors = qFindChildren<QLineEdit *>(view.viewport()); QCOMPARE(lineEditors.count(), 1); QLineEdit *editor = lineEditors.at(0); QCOMPARE(editor->selectedText(), initial); QTest::keyClicks(editor, expected); QTest::keyClick(editor, Qt::Key_Enter); QApplication::processEvents(); QCOMPARE(index.data().toString(), expected); }
QAbstractItemModel* GetInstalledLangsModel () { QMap<QString, QString> languages = GetInstalledLanguages (); QStandardItemModel *model = new QStandardItemModel (); QStandardItem *systemItem = new QStandardItem (QObject::tr ("System")); systemItem->setData ("system", Qt::UserRole); model->appendRow (systemItem); Q_FOREACH (const QString& language, languages.keys ()) { QStandardItem *item = new QStandardItem (language); item->setData (languages [language], Qt::UserRole); model->appendRow (item); } return model; }
ContentBlockingDialog::ContentBlockingDialog(QWidget *parent) : QDialog(parent), m_ui(new Ui::ContentBlockingDialog) { m_ui->setupUi(this); const QList<ContentBlockingList*> definitions = ContentBlockingManager::getBlockingDefinitions(); QStandardItemModel *model = new QStandardItemModel(this); QStringList labels; labels << tr("Name") << tr("Last update"); model->setHorizontalHeaderLabels(labels); for (int i = 0; i < definitions.count(); ++i) { QList<QStandardItem*> items; items.append(new QStandardItem(definitions.at(i)->getListName())); items[0]->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDragEnabled); items[0]->setData(definitions.at(i)->getConfigListName(), Qt::UserRole); items[0]->setCheckable(true); items[0]->setCheckState(definitions.at(i)->isEnabled() ? Qt::Checked : Qt::Unchecked); items.append(new QStandardItem(Utils::formatDateTime(definitions.at(i)->getLastUpdate()))); items[1]->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDragEnabled); model->appendRow(items); } m_ui->filtersViewWidget->setModel(model); m_ui->filtersViewWidget->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch); m_ui->filtersViewWidget->horizontalHeader()->setVisible(true); m_ui->filtersViewWidget->setItemDelegate(new OptionDelegate(true, this)); connect(m_ui->confirmButtonBox, SIGNAL(accepted()), this, SLOT(save())); connect(m_ui->confirmButtonBox, SIGNAL(rejected()), this, SLOT(close())); }
void tst_QColumnView::dynamicModelChanges() { struct MyItemDelegate : public QItemDelegate { void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const { paintedIndexes += index; QItemDelegate::paint(painter, option, index); } mutable QSet<QModelIndex> paintedIndexes; } delegate;; QStandardItemModel model; ColumnView view; view.setModel(&model); view.setItemDelegate(&delegate); view.show(); QStandardItem *item = new QStandardItem(QLatin1String("item")); model.appendRow(item); QTest::qWait(200); //let the time for painting to occur QCOMPARE(delegate.paintedIndexes.count(), 1); QCOMPARE(*delegate.paintedIndexes.begin(), model.index(0,0)); }
void tst_QItemDelegate::task257859_finalizeEdit() { QStandardItemModel model; model.appendRow(new QStandardItem()); QListView view; view.setModel(&model); view.show(); QApplication::setActiveWindow(&view); view.setFocus(); QTest::qWait(30); QModelIndex index = model.index(0, 0); view.edit(index); QTest::qWait(30); QList<QLineEdit *> lineEditors = qFindChildren<QLineEdit *>(view.viewport()); QCOMPARE(lineEditors.count(), 1); QPointer<QWidget> editor = lineEditors.at(0); QCOMPARE(editor->hasFocus(), true); QDialog dialog; QTimer::singleShot(500, &dialog, SLOT(close())); dialog.exec(); QTRY_VERIFY(!editor); }