void MainWindow::addToCartOutbound() { QModelIndexList selection = ui->tvOutboundFlights->selectionModel()->selectedRows(); if (selection.count() != 1) { return; } QJsonObject selectedFlight = mOutboundFlights->jsonData(selection.first()); QString airlineName = selectedFlight["name"].toString(); QList<QJsonObject> inbound = mInboundFlights->jsonData(); QList<QJsonObject> inboundCleaned; for (QList<QJsonObject>::const_iterator it = inbound.cbegin(); it != inbound.cend(); ++it) { if (it->value("name") == airlineName) { inboundCleaned.append(*it); } } mInboundFlights->setData(inboundCleaned); mUser.addToCart(selectedFlight); updateShoppingCart(); }
Checksum Verifier::availableChecksum(Verifier::ChecksumStrength strength) const { Checksum pair; //check if there is at least one entry QModelIndex index = d->model->index(0, 0); if (!index.isValid()) { return pair; } const QStringList available = supportedVerficationTypes(); const QStringList supported = d->orderChecksumTypes(strength); for (int i = 0; i < supported.count(); ++i) { QModelIndexList indexList = d->model->match(index, Qt::DisplayRole, supported.at(i)); if (!indexList.isEmpty() && available.contains(supported.at(i))) { QModelIndex match = d->model->index(indexList.first().row(), VerificationModel::Checksum); pair.first = supported.at(i); pair.second = match.data().toString(); break; } } return pair; }
QModelIndex getCalGroupDialog::selectedIndex() const { QModelIndexList list = selectionModel()->selectedIndexes(); if (!list.isEmpty()) return list.first(); else return QModelIndex(); }
void KLinkItemSelectionModelTest::testToggle() { // Select last index in subModel QModelIndex subIndex = m_subModel->index(m_subModel->rowCount() - 1, 0); m_subSelectionModel->select(subIndex, QItemSelectionModel::Toggle); // Check selections QModelIndexList subList = m_subSelectionModel->selectedIndexes(); QCOMPARE(subList.count(), 1); QCOMPARE(subList.first(), subIndex); QModelIndexList mainList = m_mainSelectionModel->selectedIndexes(); QModelIndex mainIndex = m_mainModel->index(m_mainModel->rowCount() - 1, 0); QCOMPARE(mainList.count(), 1); QCOMPARE(mainList.first(), mainIndex); }
void StatusWindow::setupDescriptionSelect(const QString &description) { StatusWindowDescriptionProxyModel *proxyModel = new StatusWindowDescriptionProxyModel(this); proxyModel->setSourceModel(m_descriptionManager->model()); DescriptionSelect->setModel(proxyModel); DescriptionSelect->setEnabled(false); ClearDescriptionsHistoryButton->setEnabled(false); Q_ASSERT(Container->subStatusContainers().count() > 0); if (m_descriptionManager->model()->rowCount() > 0) { DescriptionSelect->setEnabled(true); ClearDescriptionsHistoryButton->setEnabled(true); QModelIndexList matching = m_descriptionManager->model()->match( m_descriptionManager->model()->index(0, 0), DescriptionRole, QVariant(description), 1, Qt::MatchFixedString | Qt::MatchCaseSensitive); if (matching.count() > 0) DescriptionSelect->setCurrentIndex(matching.first().row()); else DescriptionSelect->setCurrentIndex(-1); } }
Item FakeAkonadiServerCommand::getItemByDisplayName(const QString& displayName) const { QModelIndexList list = m_model->match( m_model->index( 0, 0 ), Qt::DisplayRole, displayName, 1, Qt::MatchRecursive ); if ( list.isEmpty() ) return Item(); return list.first().data( EntityTreeModel::ItemRole ).value<Item>(); }
void StreamsBrowsePage::edit() { QModelIndexList selected = view->selectedIndexes(false); // Dont need sorted selection here... if (1!=selected.size()) { return; } QModelIndex index=proxy.mapToSource(selected.first()); StreamsModel::Item *item=static_cast<StreamsModel::Item *>(index.internalPointer()); if (item->isCategory() || !item->parent || !item->parent->isFavourites()) { return; } QString name=item->name; QString url=item->url; StreamDialog dlg(this); dlg.setEdit(name, url); if (QDialog::Accepted==dlg.exec()) { QString newName=dlg.name(); QString newUrl=dlg.url(); QString existingNameForUrl=newUrl!=url ? StreamsModel::self()->favouritesNameForUrl(newUrl) : QString(); if (!existingNameForUrl.isEmpty()) { MessageBox::error(this, tr("Stream '%1' already exists!").arg(existingNameForUrl)); } else if (newName!=name && StreamsModel::self()->nameExistsInFavourites(newName)) { MessageBox::error(this, tr("A stream named '%1' already exists!").arg(newName)); } else { StreamsModel::self()->updateFavouriteStream(newUrl, newName, index); } } }
void TimeWidget::copy() { QApplication::clipboard()->clear(); QItemSelectionModel* selected = table->selectionModel(); QModelIndexList indices = selected->selectedIndexes(); if(indices.size() < 1) return; qSort(indices); QModelIndex previous = indices.first(); indices.removeFirst(); QString selected_text; QModelIndex current; Q_FOREACH(current, indices) { QVariant data = table->model()->data(previous); QString text = data.toString(); selected_text.append(text); // Add last character for this element based on row or element change if(current.row() != previous.row()) selected_text.append(QLatin1Char('\n')); else selected_text.append(";"); previous = current; }
/* * This SLOT is called whenever user clicks a url inside output's textBrowser */ void MainWindow::outputTextBrowserAnchorClicked(const QUrl &link) { if (link.toString().contains("goto:")) { QString pkgName = link.toString().mid(5); QModelIndex columnIndex = m_packageModel->index(0, PackageModel::ctn_PACKAGE_NAME_COLUMN, QModelIndex()); QModelIndexList foundItems = m_packageModel->match(columnIndex, Qt::DisplayRole, pkgName, -1, Qt::MatchExactly); QModelIndex proxyIndex; if (foundItems.count() == 1) { proxyIndex = foundItems.first(); if(proxyIndex.isValid()) { ui->tvPackages->scrollTo(proxyIndex, QAbstractItemView::PositionAtCenter); ui->tvPackages->setCurrentIndex(proxyIndex); _changeTabWidgetPropertiesIndex(ctn_TABINDEX_INFORMATION); } } if (foundItems.count() == 0 || !proxyIndex.isValid()) { refreshTabInfo(pkgName); disconnect(ui->twProperties, SIGNAL(currentChanged(int)), this, SLOT(changedTabIndex())); _ensureTabVisible(ctn_TABINDEX_INFORMATION); connect(ui->twProperties, SIGNAL(currentChanged(int)), this, SLOT(changedTabIndex())); }
DeviceProcessItem DeviceProcessesDialogPrivate::selectedProcess() const { const QModelIndexList indexes = procView->selectionModel()->selectedIndexes(); if (indexes.empty() || !processList) return DeviceProcessItem(); return processList->at(proxyModel.mapToSource(indexes.first()).row()); }
void WSInfoDelegate::setModelData(QWidget* editor, QAbstractItemModel* model, const QModelIndex& thisindex) const { WeightModel *mymodel = qobject_cast<WeightModel *>(currCombo.model); WSInfoModel *wsim = WSInfoModel::instance(); QModelIndexList matches = wsim->match(wsim->index(0,0), Qt::DisplayRole, currCombo.activeText); int row; if (matches.isEmpty()) { // we need to add this puppy wsim->insertRows(wsim->rowCount(), 1); wsim->setData(wsim->index(wsim->rowCount() - 1, 0), currCombo.activeText); row = wsim->rowCount() - 1; } else { row = matches.first().row(); } int grams = wsim->data(wsim->index(row, WSInfoModel::GR)).toInt(); QVariant v = QString(currCombo.activeText); // don't set if it's the same as it was before setting. if (mymodel->data(thisindex, WeightModel::TYPE).toString() == currCombo.activeText){ return; } mymodel->setData(IDX(WeightModel::TYPE), v, Qt::EditRole); mymodel->passInData(IDX(WeightModel::WEIGHT), grams); qDebug() << "Fixme, every weigth is 0.0 grams. see:" << grams; }
void TankInfoDelegate::setModelData(QWidget* editor, QAbstractItemModel* model, const QModelIndex& thisindex) const { CylindersModel *mymodel = qobject_cast<CylindersModel *>(currCombo.model); TankInfoModel *tanks = TankInfoModel::instance(); QModelIndexList matches = tanks->match(tanks->index(0,0), Qt::DisplayRole, currCombo.activeText); int row; if (matches.isEmpty()) { // we need to add this tanks->insertRows(tanks->rowCount(), 1); tanks->setData(tanks->index(tanks->rowCount() -1, 0), currCombo.activeText); row = tanks->rowCount() - 1; } else { row = matches.first().row(); } int tankSize = tanks->data(tanks->index(row, TankInfoModel::ML)).toInt(); int tankPressure = tanks->data(tanks->index(row, TankInfoModel::BAR)).toInt(); // don't f**k the other data, jimmy. if ( mymodel->data(thisindex, CylindersModel::TYPE).toString() == currCombo.activeText){ return; } mymodel->setData(IDX(CylindersModel::TYPE), currCombo.activeText, Qt::EditRole); mymodel->passInData(IDX(CylindersModel::WORKINGPRESS), tankPressure); mymodel->passInData(IDX(CylindersModel::SIZE), tankSize); }
void KJotsLinkDialog::setLinkUrl(const QString &linkUrl) { Akonadi::Item item = Akonadi::Item::fromUrl(KUrl(linkUrl)); Akonadi::Collection collection = Akonadi::Collection::fromUrl(KUrl(linkUrl)); if (!item.isValid() && !collection.isValid()) { linkUrlLineEdit->setText(linkUrl); linkUrlLineEditRadioButton->setChecked(true); return; } QModelIndex idx; if (collection.isValid()) { idx = Akonadi::EntityTreeModel::modelIndexForCollection( m_descendantsProxyModel, collection ); } else if (item.isValid()) { const QModelIndexList list = Akonadi::EntityTreeModel::modelIndexesForItem( m_descendantsProxyModel, item ); if (list.isEmpty()) return; idx = list.first(); } if (!idx.isValid()) return; hrefComboRadioButton->setChecked(true); hrefCombo->view()->setCurrentIndex( idx ); hrefCombo->setCurrentIndex( idx.row() ); }
void DirectusFileExplorer::RenameSelectedItem() { QModelIndexList selectionList = this->selectedIndexes(); QModelIndex selectedItem = selectionList.first(); // TODO: Implement actual renaming on the item }
TemplateSelectionPage::TemplateSelectionPage(TemplateClassAssistant* parent, Qt::WindowFlags f) : QWidget(parent, f) , d(new TemplateSelectionPagePrivate(this)) { d->assistant = parent; d->ui = new Ui::TemplateSelection; d->ui->setupUi(this); d->model = new TemplatesModel(QStringLiteral("kdevfiletemplates"), this); d->model->refresh(); d->ui->view->setLevels(3); d->ui->view->setHeaderLabels(QStringList() << i18n("Language") << i18n("Framework") << i18n("Template")); d->ui->view->setModel(d->model); connect(d->ui->view, &MultiLevelListView::currentIndexChanged, this, [&] (const QModelIndex& index) { d->currentTemplateChanged(index); }); QModelIndex templateIndex = d->model->index(0, 0); while (templateIndex.child(0, 0).isValid()) { templateIndex = templateIndex.child(0, 0); } KSharedConfigPtr config; if (IProject* project = ICore::self()->projectController()->findProjectForUrl(d->assistant->baseUrl())) { config = project->projectConfiguration(); } else { config = ICore::self()->activeSession()->config(); } KConfigGroup group(config, FileTemplatesGroup); QString lastTemplate = group.readEntry(LastUsedTemplateEntry); QModelIndexList indexes = d->model->match(d->model->index(0, 0), TemplatesModel::DescriptionFileRole, lastTemplate, 1, Qt::MatchRecursive); if (!indexes.isEmpty()) { templateIndex = indexes.first(); } d->ui->view->setCurrentIndex(templateIndex); QPushButton* getMoreButton = new QPushButton(i18n("Get More Templates..."), d->ui->view); getMoreButton->setIcon(QIcon::fromTheme(QStringLiteral("get-hot-new-stuff"))); connect (getMoreButton, &QPushButton::clicked, this, [&] { d->getMoreClicked(); }); d->ui->view->addWidget(0, getMoreButton); QPushButton* loadButton = new QPushButton(QIcon::fromTheme(QStringLiteral("application-x-archive")), i18n("Load Template From File"), d->ui->view); connect (loadButton, &QPushButton::clicked, this, [&] { d->loadFileClicked(); }); d->ui->view->addWidget(0, loadButton); d->ui->view->setContentsMargins(0, 0, 0, 0); }
/*! \brief Similar to QComboBox::findData() but searches recursively in the tree model (instead of * just root items) */ QModelIndex TreeComboBox::treeFindData(const QVariant &data, int role, Qt::MatchFlags flags) const { if (this->model() == NULL) return QModelIndex(); const QModelIndex startId = this->model()->index(0, this->modelColumn(), QModelIndex()); const QModelIndexList matchIds = this->model()->match(startId, role, data, 1, flags); return !matchIds.isEmpty() ? matchIds.first() : QModelIndex(); }
void K3b::DataDirTreeView::slotSelectionChanged( const QItemSelection& selected, const QItemSelection& ) { QModelIndexList indexes = selected.indexes(); if ( !indexes.isEmpty() ) { K3b::DirItem* dir = d->model->itemForIndex( indexes.first() )->getDirItem(); emit dirSelected( dir ); } }
Item EventSelectorDialog::selectedItem() { const QModelIndexList list = m_view->selectionModel()->selectedRows(); if (list.size() != 1) { return Item(); } return list.first().data(MixedTreeModel::ItemRole).value<Item>(); }
Song LibraryPage::coverRequest() const { QModelIndexList selected = view->selectedIndexes(false); // Dont need sorted selection here... if (1==selected.count()) { QList<Song> songs=MpdLibraryModel::self()->songs(QModelIndexList() << selected.first(), false); if (!songs.isEmpty()) { Song s=songs.at(0); if (SqlLibraryModel::T_Artist==static_cast<SqlLibraryModel::Item *>(selected.first().internalPointer())->getType() && !s.useComposer()) { s.setArtistImageRequest(); } return s; } } return Song(); }
bool EditTagDialog::DoesValueVary(const QModelIndexList& sel, const QString& id) const { QVariant value = data_[sel.first().row()].current_value(id); for (int i = 1; i < sel.count(); ++i) { if (value != data_[sel[i].row()].current_value(id)) return true; } return false; }
void ModuleDockWidget::moduleChanged(const int moduleID) { const QModelIndexList list = m_proxyModel->match(m_moduleManager->m_moduleModel->invisibleRootItem()->index(), Qt::UserRole + 1, QString::number(moduleID)); if(list.size() == 1) { m_proxyModel->setData(m_proxyModel->mapFromSource(list.first()), m_settings->getModuleSettings(moduleID)->name(false), Qt::DisplayRole); } }
void HKPropertyDialog::deleteKeyTriggered() { QModelIndexList indexes = tb_keys->selectionModel()->selection().indexes(); if (!indexes.isEmpty()) { int index = indexes.first().row(); values.remove(index); updateKeysTableTriggered(); } }
void WebBrowser::removeBookmark() { const QModelIndexList list = m_bookmarkModel->match(m_bookmarkModel->index(0,0), BookmarkItem::UrlRole, m_url.prettyUrl()); if (!list.isEmpty()) { removeBookmark(list.first()); } }
void QxtCountryComboBoxPrivate::setCurrentCountry(QLocale::Country country) { // column 3 is QLocale::Country QModelIndex start = qxt_p().model()->index(0, 3); QModelIndexList result = qxt_p().model()->match(start, Qt::DisplayRole, country, 1, Qt::MatchExactly); if (!result.isEmpty()) qxt_p().setCurrentIndex(result.first().row()); }
QModelIndex QmlProfilerStatisticsMainView::selectedModelIndex() const { QModelIndexList sel = selectedIndexes(); if (sel.isEmpty()) return QModelIndex(); else return sel.first(); }
void FileSystemTab::scrollToSelection() { const QModelIndexList selectedIndexes(m_view->selectionModel()->selectedIndexes()); if(!selectedIndexes.isEmpty()) { m_view->scrollTo(selectedIndexes.first(), QAbstractItemView::PositionAtTop); } }
Calendar *CalendarTreeView::selectedCalendar() const { QModelIndexList lst = selectionModel()->selectedRows(); if ( lst.count() == 1 ) { return model()->calendar( lst.first() ); } return 0; }
Account *AccountTreeView::selectedAccount() const { QModelIndexList lst = selectionModel()->selectedRows(); if ( lst.count() == 1 ) { return model()->account( lst.first() ); } return 0; }
void ConnectPage::instanceSelected() { const QModelIndexList rows = ui->instanceView->selectionModel()->selectedRows(); if (rows.size() != 1) return; ui->host->setText(rows.first().data(NetworkDiscoveryModel::UrlStringRole).toString()); }
void GeneralDataGUI::removeUnitMeasure(){ if( m_d->project ){ QModelIndexList listRows = m_d->ui->unitMeasureView->selectionModel()->selectedRows(); if( listRows.size() > 0 ){ m_d->project->unitMeasureModel()->removeUnitMeasure( listRows.first().row(), listRows.size()); } } }