void ProgressPanel::getSelectedTaskInternal(const QItemSelection& selected, std::list<ProgressTaskInfoPtr>& selection) const { std::set<int> rows; QModelIndexList selectedIndex = selected.indexes(); for (int i = 0; i < selectedIndex.size(); ++i) { rows.insert(selectedIndex[i].row()); } for (std::set<int>::iterator it = rows.begin(); it!=rows.end(); ++it) { if ((*it) >= 0 && (*it) < (int)_imp->tasksOrdered.size()) { selection.push_back(_imp->tasksOrdered[*it]); } } }
void KMyMoneyAccountTreeView::selectionChanged(const QItemSelection &selected, const QItemSelection &deselected) { QTreeView::selectionChanged(selected, deselected); if (!selected.empty()) { QModelIndexList indexes = selected.front().indexes(); if (!indexes.empty()) { QVariant data = model()->data(model()->index(indexes.front().row(), AccountsModel::Account, indexes.front().parent()), AccountsModel::AccountRole); if (data.isValid()) { if (data.canConvert<MyMoneyAccount>()) { emit selectObject(data.value<MyMoneyAccount>()); } if (data.canConvert<MyMoneyInstitution>()) { emit selectObject(data.value<MyMoneyInstitution>()); } // an object was successfully selected return; } } } // since no object was selected reset the object selection emit selectObject(MyMoneyAccount()); emit selectObject(MyMoneyInstitution()); }
void QgsNodeEditor::updateNodeSelection( const QItemSelection& selected, const QItemSelection& ) { if ( mUpdatingTableSelection ) return; mUpdatingNodeSelection = true; mSelectedFeature->deselectAllVertexes(); Q_FOREACH ( const QModelIndex& index, mTableView->selectionModel()->selectedRows() ) { int nodeIdx = index.row(); mSelectedFeature->selectVertex( nodeIdx ); } //ensure that newly selected node is visible in canvas if ( !selected.indexes().isEmpty() ) { int newRow = selected.indexes().first().row(); zoomToNode( newRow ); } mUpdatingNodeSelection = false; }
void StarredFilesListView::updateActions() { StarredFileItem *item = NULL; QItemSelection selected = selectionModel()->selection(); QModelIndexList indexes = selected.indexes(); if (indexes.size() != 0) { const QModelIndex& index = indexes.at(0); QStandardItem *it = ((StarredFilesListModel *)model())->itemFromIndex(index); item = (StarredFileItem *)it; } if (!item) { // No item is selected open_file_action_->setEnabled(false); view_file_on_web_action_->setEnabled(false); return; } const StarredItem& file = item->file(); open_file_action_->setData(QVariant::fromValue(file)); view_file_on_web_action_->setData(QVariant::fromValue(file)); }
void QueueManagerWidget::moveUpClicked() { QModelIndexList sel = view->selectionModel()->selectedRows(); QList<int> rows; foreach (const QModelIndex& idx, sel) rows.append(idx.row()); if (rows.isEmpty() || rows.front() == 0) return; model->moveUp(rows.front(), rows.count()); QItemSelection nsel; int cols = model->columnCount(QModelIndex()); QModelIndex top_left = model->index(rows.front() - 1, 0); QModelIndex bottom_right = model->index(rows.back() - 1, cols - 1); nsel.select(top_left, bottom_right); view->selectionModel()->select(nsel, QItemSelectionModel::Select); if (!indexVisible(top_left)) view->scrollTo(top_left, QAbstractItemView::PositionAtCenter); updateButtons(); }
void availableRoomsWindow::selectionChanged(const QItemSelection& selected, const QItemSelection&) { QList<QModelIndex> indexes = selected.indexes(); if(indexes.size() == 0) return; widgetMapper->setCurrentIndex( indexes.at(0).row() ); bookingDlg->getWidgetMapper()->setCurrentIndex( indexes.at(0).row() ); updateMaxGuestNumber(); updateBookButton(); updateRoomPrice(); }
void TableView::selectionChanged(const QItemSelection &selected, const QItemSelection &deselected) { QTableView::selectionChanged(selected,deselected); //on change la couleur des éléments selectionnés QModelIndexList list = selected.indexes(); QModelIndexList::Iterator it = list.begin(); for (int i=0;it!=list.end();it++,i++) { elementBase * elem = getSourceModel()->getElement((*it).row()); elem->invertColor(); } // on restaure la couleur original des éléments désélectionnés list = deselected.indexes(); it = list.begin(); for (int i=0;it!=list.end();it++,i++) { elementBase * elem = getSourceModel()->getElement((*it).row()); elem->invertColor(); } }
void HistoryDialog::selectionChanged(QItemSelection selected, QItemSelection deselected) { Q_UNUSED(deselected); if (selected.indexes().count() == 0){ return; } QModelIndex index = selected.indexes().at(0); QString screenshot; if (index.column() == 0) { screenshot = index.data().toString(); } else { screenshot = ui->tableView->model()->index(index.row(), 0).data().toString(); } mSelectedScreenshot = screenshot; ui->uploadButton->setEnabled(QFile::exists(screenshot)); }
void views::treeView::performDrag() { QModelIndexList list=selectedIndexes(); QList<QUrl> urls=getUrls(list); if(urls.isEmpty() ) { return ; } QMimeData *mimeData = new QMimeData; mimeData->setUrls(urls); QDrag *drag = new QDrag(this); drag->setMimeData(mimeData); drag->setPixmap(QPixmap(decor->tagIcon(-1).pixmap(48,48)) ); drag->exec(Qt::CopyAction|Qt::MoveAction); if(reorderL.size() == 0) { return ; } QItemSelection sel; std::set<int>::const_iterator it=reorderL.begin(); for(;it!=reorderL.end();it++) { QItemSelection s; s.select(model ()->index (*it, 0),model ()->index (*it, model()->columnCount()-1)); sel.merge(s,QItemSelectionModel::SelectCurrent); } // selectionModel()->select (sel,QItemSelectionModel::Select ); reorderL.clear(); }
void PlaylistView::moveItems(int steps) { PlaylistModel *playlistModel = dynamic_cast<PlaylistModel *>(this->model()); if (playlistModel == nullptr) { return; } QItemSelection indexList = this->selectionModel()->selection(); std::sort(indexList.begin(), indexList.end(), steps > 0 ? sortQItemSelectionDesc : sortQItemSelectionAsc); for (QItemSelection::const_iterator i = indexList.cbegin(); i != indexList.cend(); ++i) { int top = i->top(); int btm = i->bottom(); int count = abs(top - btm); int srcRow = min(top, btm); int destRow = srcRow + steps; QModelIndex newIdx = steps > 0 ? playlistModel->index(destRow + count, 0) : playlistModel->index(srcRow - 1, 0); QModelIndex oldIdx = steps > 0 ? playlistModel->index(srcRow, 0) : playlistModel->index(srcRow + count, 0); if (newIdx.isValid()) { this->selectionModel()->select(newIdx, QItemSelectionModel::SelectionFlag::Select | QItemSelectionModel::SelectionFlag::Rows); this->selectionModel()->select(oldIdx, QItemSelectionModel::SelectionFlag::Deselect | QItemSelectionModel::SelectionFlag::Rows); playlistModel->moveRows(playlistModel->index(0, 0), srcRow, count, playlistModel->index(playlistModel->rowCount(QModelIndex()) - 1, playlistModel->columnCount(QModelIndex()) - 1), destRow); } } }
QList<Dataset> DatasetItemModel::getDatasets(const QItemSelection &selection) { // get unique row indexes from the user selection QSet<int> rows; for (const auto &index : selection.indexes()) { rows.insert(index.row()); } // get the datasets corresponding to the selection and return them QList<Dataset> datasetList; for (const auto &row : rows) { const Dataset &item = m_datasets_reference.at(row); datasetList.push_back(item); } return datasetList; }
bool TableView::setSelectedRows(QList<int> rows) { QItemSelectionModel * selection = selectionModel(); selection->clear(); TableModel * currentModel = static_cast<TableModel *>(model()); QItemSelection totalSelection; for(int i = 0; i < rows.size(); i++) { if(!currentModel->isValidRow(rows[i])) { continue; } QModelIndex index = model()->index(rows[i], 0); QItemSelection currentSelection(index, index); totalSelection.merge(currentSelection, QItemSelectionModel::SelectCurrent); } selection->select(totalSelection, QItemSelectionModel::ClearAndSelect); setSelectionModel(selection); return true; }
void CourseEditUI::tableViewSelectionChanged( const QItemSelection & selected, const QItemSelection & deselected ) { if(selected.count() > 0) { QModelIndexList selectedList = selected.at(0).indexes(); if(selectedList.count() > 0) { QString question = selectedList.value(0).data().toString(); QString answer = selectedList.value(1).data().toString(); txtQuestion->setText(question); txtAnswer->setText(answer); for(Items::const_iterator it = _items.begin(); it != _items.end(); ++it) { if(it->get()->GetQuestion() == question.toStdString() && it->get()->GetAnswer() == answer.toStdString()) { _currentItem = *it; return; } } _currentItem = ItemPtr(); } } }
void MshView::selectionChanged( const QItemSelection &selected, const QItemSelection &deselected ) { Q_UNUSED(deselected); if (!selected.isEmpty()) { emit removeSelectedMeshComponent(); const QModelIndex idx = *(selected.indexes().begin()); const TreeItem* tree_item = static_cast<TreeModel*>(this->model())->getItem(idx); const MshItem* list_item = dynamic_cast<const MshItem*>(tree_item); if (list_item) { emit enableSaveButton(true); emit enableRemoveButton(true); emit meshSelected(*list_item->getMesh()); } else { emit enableSaveButton(false); emit enableRemoveButton(false); emit elementSelected(dynamic_cast<const MshItem*>(tree_item->parentItem())->vtkSource(), static_cast<unsigned>(tree_item->row()), true); } } }
/** * This function work with both TreeModel and FilterModel selections. * It is assumed that only a single item is selected. */ void FixDpiDialog::updateDpiFromSelection(QItemSelection const& selection) { if (selection.isEmpty()) { resetDpiForm(); dpiCombo->setEnabled(false); xDpi->setEnabled(false); yDpi->setEnabled(false); // applyBtn is managed elsewhere. return; } dpiCombo->setEnabled(true); xDpi->setEnabled(true); yDpi->setEnabled(true); // FilterModel may replace AGGREGATE_METADATA_ROLE with AGGREGATE_NOT_OK_METADATA_ROLE. QVariant const data(selection.front().topLeft().data(AGGREGATE_METADATA_ROLE)); if (data.isValid()) { setDpiForm(data.value<ImageMetadata>()); } else { resetDpiForm(); } }
void MainWindow::drawPath(QItemSelection item){ QCPCurve *curve = qobject_cast<QCPCurve*>(ui->citiesPlot->plottable(0)); curve->clearData(); curve->setLineStyle(QCPCurve::lsLine); ui->citiesPlot->replot(); QModelIndex index = item.indexes().first(); Tour tour = qvariant_cast<Tour>(ui->listView->model()->data(index, Qt::UserRole)); for(int i=0; i<tour.tourSize(); i++){ int x = tour.getCity(i).getX(); int y = tour.getCity(i).getY(); curve->addData(x, y); } curve->addData(tour.getCity(0).getX(), tour.getCity(0).getY()); ui->citiesPlot->replot(); }
void BrokenLinksWidget::selectionChanged(const QItemSelection &selected) { mLocateButton->setEnabled(!selected.isEmpty()); bool isTileset = qobject_cast<TilesetDocument*>(mBrokenLinksModel->document()) != nullptr; if (!selected.isEmpty()) { const auto firstIndex = selected.first().topLeft(); const BrokenLink &link = mBrokenLinksModel->brokenLink(firstIndex.row()); switch (link.type) { case Tiled::Internal::MapTilesetReference: mLocateButton->setText(tr("Locate File...")); break; case Tiled::Internal::TilesetTileImageSource: case Tiled::Internal::TilesetImageSource: if (isTileset) mLocateButton->setText(tr("Locate File...")); else mLocateButton->setText(tr("Open Tileset...")); break; } } }
void LayerList::selectionChanged(const QItemSelection &selected) { bool on = selected.count() > 0; if(on) { QModelIndex cs = currentSelection(); dataChanged(cs,cs); _selected = cs.data().value<net::LayerListItem>().id; } else { _selected = 0; } updateLockedControls(); emit layerSelected(_selected); }
void AttachmentModel::removeSelectedAttachments(QItemSelection const &selection) { if (selection.isEmpty()) return; std::vector<int> rowsToRemove; for (auto &range : selection) for (auto &index : range.indexes()) rowsToRemove.push_back(index.row()); brng::sort(rowsToRemove, std::greater<int>()); for (auto row : rowsToRemove | badap::uniqued) removeRow(row); }
void CGroupListView::selectionChanged(const QItemSelection &selected, const QItemSelection &deselected) { QModelIndexList deselectedItems(deselected.indexes()); QAbstractItemView::selectionChanged(selected, deselected); QModelIndexList selectedItems(selectedIndexes()); if(0==selectedItems.count() && 1==deselectedItems.count()) selectionModel()->select(deselectedItems.last(), QItemSelectionModel::Select); else emit itemSelected(selectedItems.count() ? selectedItems.last() : QModelIndex()); }
void CxReader::feedChanged(QItemSelection selected, QItemSelection deselected) { FeedEntryListModel * old = feedEntryListModel; QString id = this->feedListModel->data(selected.indexes().at(0), FeedListModel::ID).toString(); this->feedEntryListModel = new FeedEntryListModel(this->config, id, this); this->ui->feedEntryList->setModel(this->feedEntryListModel); connect(this->ui->feedEntryList->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)), SLOT(feedEntryChanged(QItemSelection, QItemSelection))); if(this->ui->unreadOnly->isChecked()) this->feedEntryListModel->showOnlyUnread(true); if(old != NULL) delete old; }
/** * @brief Converts a selection of this model to a selection in the source model. * * Reimplemented from QSortFilterProxyModel to peacefully handle items that do * not exist in the source model. * * @param proxy_selection A selection in this model. * @return The corresponding source selection. */ QItemSelection QuestFilesModel::mapSelectionToSource(const QItemSelection& proxy_selection) const { QItemSelection source_selection; const QModelIndexList& indexes = proxy_selection.indexes(); Q_FOREACH (const QModelIndex& index, indexes) { const QModelIndex& source_index = mapToSource(index); if (!index.isValid()) { // Selected item that does not exist in the source model. continue; } source_selection.append(QItemSelectionRange(source_index)); } return source_selection; }
void QmitkPointListView::OnListViewSelectionChanged(const QItemSelection &selected, const QItemSelection & /*deselected*/) { if (m_SelfCall) return; mitk::PointSet *pointSet = const_cast<mitk::PointSet *>(m_PointListModel->GetPointSet()); if (pointSet == nullptr) return; // (take care that this widget doesn't react to self-induced changes by setting m_SelfCall) m_SelfCall = true; // update selection of all points in pointset: select the one(s) that are selected in the view, deselect all others QModelIndexList selectedIndexes = selected.indexes(); for (mitk::PointSet::PointsContainer::Iterator it = pointSet->GetPointSet(m_PointListModel->GetTimeStep())->GetPoints()->Begin(); it != pointSet->GetPointSet(m_PointListModel->GetTimeStep())->GetPoints()->End(); ++it) { QModelIndex index; if (m_PointListModel->GetModelIndexForPointID(it->Index(), index)) { if (selectedIndexes.indexOf(index) != -1) // index is found in the selected indices list { pointSet->SetSelectInfo(it->Index(), true, m_PointListModel->GetTimeStep()); mitk::Point3D p = pointSet->GetPoint(it->Index(), m_PointListModel->GetTimeStep()); for (auto snc : m_Sncs) snc->SelectSliceByPoint(p); } else { pointSet->SetSelectInfo(it->Index(), false, m_PointListModel->GetTimeStep()); } } } m_SelfCall = false; emit SignalPointSelectionChanged(); mitk::RenderingManager::GetInstance()->RequestUpdateAll(); }
void ErrorReportDialog::onShowFileContent(const QItemSelection& newSelection, const QItemSelection & oldSelection) { ARX_UNUSED(oldSelection); const QModelIndexList selectedIndexes = newSelection.indexes(); if(selectedIndexes.empty()) return; const QModelIndex selectedIndex = selectedIndexes.at(0); if(!selectedIndex.isValid()) return; fs::path fileName = m_errorReport.GetAttachedFiles()[selectedIndex.row()].path; QString ext = fileName.ext().c_str(); if(ext == ".txt" || ext == ".log" || ext == ".ini" || ext == ".xml") { QFile textFile(fileName.string().c_str()); textFile.open(QIODevice::ReadOnly | QIODevice::Text); QByteArray data; data = textFile.readAll(); ui->fileViewText->setText(QString::fromUtf8(data)); ui->stackedFileViews->setCurrentIndex(0); } else if(ext == ".jpg" || ext == ".jpeg" || ext == ".bmp" || ext == ".png" || ext == ".gif") { m_fileViewImage.load(fileName.string().c_str()); ui->stackedFileViews->setCurrentIndex(1); } else { QFile binaryFile(fileName.string().c_str()); binaryFile.open(QIODevice::ReadOnly); if(binaryFile.size() > 20 * 1024 * 1024) { ui->stackedFileViews->setCurrentIndex(3); return; } QByteArray data; data = binaryFile.readAll(); m_fileViewHex.setData(data); ui->stackedFileViews->setCurrentIndex(2); } }
void AttachmentModel::removeSelectedAttachments(QItemSelection const &selection) { if (selection.isEmpty()) return; auto rowsToRemove = QSet<int>{}; for (auto &range : selection) for (auto &index : range.indexes()) rowsToRemove << index.row(); auto sortedRowsToRemove = rowsToRemove.toList(); std::sort(sortedRowsToRemove.begin(), sortedRowsToRemove.end(), std::greater<int>()); for (auto row : sortedRowsToRemove) removeRow(row); }
/*! * This is called when usb selection is changed in the view (selection model). */ void UsbUiSettingModel::handleSelectionChange(const QItemSelection &selected, const QItemSelection &deselected ) { Q_UNUSED( deselected ); myDebug() << ">>> UsbUiSettingModel::handleSelectionChange"; QModelIndexList items = selected.indexes(); if (!items.isEmpty()) { myDebug() << " UsbUiSettingModel::handleSelectionChange item exists"; QModelIndex index = items[0]; int newPersonalityId = mPersonalityIds.at(index.row()); if ( newPersonalityId != mCurrentMode ) { myDebug() << " UsbUiSettingModel::handleSelectionChange setting personality"; mModelActive->SetUsbPersonality(newPersonalityId); } } myDebug() << "<<< UsbUiSettingModel::handleSelectionChange return"; }
void QmitkLevelWindowPresetDefinitionDialog::ListViewSelectionChanged(const QItemSelection& selected, const QItemSelection& /*deselected*/) { QModelIndexList indexes(selected.indexes()); if (indexes.empty()) { presetnameLineEdit->setText(""); levelSpinBox->setValue(0); windowSpinBox->setValue(0); } else { PresetTableModel::Entry entry(m_TableModel->getPreset(indexes.first())); presetnameLineEdit->setText(QString(entry.name.c_str())); levelSpinBox->setValue((int)entry.level); windowSpinBox->setValue((int)entry.window); } }
QmitkDataNodeSelection::QmitkDataNodeSelection( const QItemSelection& sel) : mitk::DataNodeSelection(), berry::QtItemSelection(sel) { QModelIndexList indexes = sel.indexes(); for (QModelIndexList::const_iterator index = indexes.constBegin(); index != indexes.constEnd(); ++index) { QVariant data = index->data(QmitkDataNodeRole); mitk::DataNode::Pointer node = data.value<mitk::DataNode::Pointer> (); if (node.IsNotNull()) { berry::Object::Pointer obj(new mitk::DataNodeObject(node)); mitk::DataNodeSelection::m_Selection->push_back(obj); } } }
void LogChangeWidget::selectionChanged(const QItemSelection &selected, const QItemSelection &deselected) { Utils::TreeView::selectionChanged(selected, deselected); if (!m_hasCustomDelegate) return; const QModelIndexList previousIndexes = deselected.indexes(); if (previousIndexes.isEmpty()) return; const QModelIndex current = currentIndex(); int row = current.row(); int previousRow = previousIndexes.first().row(); if (row < previousRow) qSwap(row, previousRow); for (int r = previousRow; r <= row; ++r) { update(current.sibling(r, 0)); update(current.sibling(r, 1)); } }
void ActivePlaylistView::handleSelectionChange( const QItemSelection& selected, const QItemSelection& /*deselected*/) { if(selected.indexes().size() == 0){ connect( dataStore, SIGNAL(activePlaylistModified()), model, SLOT(refresh())); } else{ disconnect( dataStore, SIGNAL(activePlaylistModified()), model, SLOT(refresh())); } }