void Desktopwidget::dirSelected (const QModelIndex &index, bool allow_undo) { QString path = _model->data (index, QDirModel::FilePathRole).toString (); QModelIndex root = _model->findRoot (index); QString root_path = _model->data (root, QDirModel::FilePathRole).toString (); // printf ("dirSelected %s, %s\n", path.latin1 (), _contents->getDirPath ().latin1 ()); // clear the page preview _page->slotReset (); // if we have are actually changing directory, do so if (path != _contents->getDirPath ()) { _path = path; _contents->changeDir (path, root_path, allow_undo); } /* otherwise just clear the current selection. This avoid confusion with keyboard shortcuts which might operate in the directory view and item view */ else { QItemSelectionModel *sel = _view->selectionModel (); sel->clear (); } }
// this slot handles auto-selection of items. void FolderView::onAutoSelectionTimeout() { if(QApplication::mouseButtons() != Qt::NoButton) return; Qt::KeyboardModifiers mods = QApplication::keyboardModifiers(); QPoint pos = view->viewport()->mapFromGlobal(QCursor::pos()); // convert to viewport coordinates QModelIndex index = view->indexAt(pos); // find out the hovered item QItemSelectionModel::SelectionFlags flags = (mode == DetailedListMode ? QItemSelectionModel::Rows : QItemSelectionModel::NoUpdate); QItemSelectionModel* selModel = view->selectionModel(); if(mods & Qt::ControlModifier) { // Ctrl key is pressed if(selModel->isSelected(index) && index != lastAutoSelectionIndex_) { // unselect a previously selected item selModel->select(index, flags|QItemSelectionModel::Deselect); lastAutoSelectionIndex_ = QModelIndex(); } else { // select an unselected item selModel->select(index, flags|QItemSelectionModel::Select); lastAutoSelectionIndex_ = index; } selModel->setCurrentIndex(index, QItemSelectionModel::NoUpdate); // move the cursor } else if(mods & Qt::ShiftModifier) { // Shift key is pressed // select all items between current index and the hovered index. QModelIndex current = selModel->currentIndex(); if(selModel->hasSelection() && current.isValid()) { selModel->clear(); // clear old selection selModel->setCurrentIndex(current, QItemSelectionModel::NoUpdate); int begin = current.row(); int end = index.row(); if(begin > end) qSwap(begin, end); for(int row = begin; row <= end; ++row) { QModelIndex sel = model_->index(row, 0); selModel->select(sel, flags|QItemSelectionModel::Select); } } else { // no items are selected, select the hovered item. if(index.isValid()) { selModel->select(index, flags|QItemSelectionModel::SelectCurrent); selModel->setCurrentIndex(index, QItemSelectionModel::NoUpdate); } } lastAutoSelectionIndex_ = index; } else if(mods == Qt::NoModifier) { // no modifier keys are pressed. if(index.isValid()) { // select the hovered item view->clearSelection(); selModel->select(index, flags|QItemSelectionModel::SelectCurrent); selModel->setCurrentIndex(index, QItemSelectionModel::NoUpdate); } lastAutoSelectionIndex_ = index; } autoSelectionTimer_->deleteLater(); autoSelectionTimer_ = nullptr; }
void ccDBRoot::selectEntity(ccHObject* obj) { bool ctrlPushed = (QApplication::keyboardModifiers () & Qt::ControlModifier); QItemSelectionModel* selectionModel = m_dbTreeWidget->selectionModel(); assert(selectionModel); //valid object? then we will try to select (or toggle) it if (obj) { QModelIndex selectedIndex = index(obj); if (selectedIndex.isValid()) { //if CTRL is pushed if (ctrlPushed) { //default case: toggle current item selection state if (!obj->isSelected()) { QModelIndexList selectedIndexes = selectionModel->selectedIndexes(); if (!selectedIndexes.empty()) { //special case: labels can only be merged with labels! if (obj->isA(CC_2D_LABEL) != static_cast<ccHObject*>(selectedIndexes[0].internalPointer())->isA(CC_2D_LABEL)) { ccLog::Warning("[Selection] Labels and other entities can't be mixed! (release the CTRL key to start a new selection)"); return; } } } selectionModel->select(selectedIndex,QItemSelectionModel::Toggle); } else { if (selectionModel->isSelected(selectedIndex)) //nothing to do return; selectionModel->select(selectedIndex,QItemSelectionModel::ClearAndSelect); } //hack: auto-scroll to selected element if (obj->isSelected() && !ctrlPushed) m_dbTreeWidget->scrollTo(selectedIndex); } } //otherwise we clear current selection (if CTRL is not pushed) else if (!ctrlPushed) { selectionModel->clear(); } }
void ModelDescriptorListWidget::selectRow(int row) { QModelIndex rootIndex = this->rootIndex(); if(rootIndex.isValid()) { QItemSelectionModel *selectionModel = this->selectionModel(); QSortFilterProxyModel *proxyModel = this->proxyModel(); if(row < proxyModel->rowCount(rootIndex)) { selectionModel->clear(); QModelIndex index = proxyModel->index(row, 0, rootIndex); if(index.isValid()) { selectionModel->setCurrentIndex(index, QItemSelectionModel::SelectCurrent); } } } }
void ModelDescriptorListWidget::selectRow(const QUuid &uid) { QItemSelectionModel *selectionModel = this->selectionModel(); if(selectionModel) { selectionModel->clear(); QModelIndex selectedIndex = findIndex(uid); if(selectedIndex.isValid()) { QModelIndex selectedIndexParent = selectedIndex.parent(); if(selectedIndexParent.isValid()) { expand(selectedIndexParent); } selectionModel->setCurrentIndex(selectedIndex, QItemSelectionModel::SelectCurrent); } } }
void UniqueNotesModel::selectTopLeft() { QItemSelectionModel* pSelModel (m_pCommonData->m_pUniqueNotesG->selectionModel()); pSelModel->clear(); emit layoutChanged(); if (m_pCommonData->getUniqueNotes().getFltCount() > 0) { //pSelModel->select(index(0, 0), QItemSelectionModel::Current); //pSelModel->select(index(0, 0), QItemSelectionModel::Select); //m_pCommonData->printFilesCrt(); m_pCommonData->m_pUniqueNotesG->setCurrentIndex(index(0, 0)); //m_pCommonData->printFilesCrt(); } }
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; }
// makes current and selects the specified row and emits a change signal regardless of the element that was selected before; makes current the default invalid index (-1,-1) if the table is empty; void FilesModel::selectRow(int nRow, const vector<int>& vnSel /* = std::vector<int>()*/) { QItemSelectionModel* pSelModel (m_pCommonData->m_pFilesG->selectionModel()); //m_pCommonData->printFilesCrt(); { NonblockingGuard g (m_pCommonData->m_bChangeGuard); if (!g) { return; } pSelModel->clear(); // 2008.07.08: this doesn't work quite as expected: it does trigger SelectionChanged, but it changes the current item after emitting the signal, so whoever catches it, doesn't know what the current item is (it's probably in the second param of CurrentChanged, but that doesn't help SelectionChanged, which has QItemSelection params, which don't seem to offer any way to get at the "current" index) } //m_pCommonData->printFilesCrt(); emit layoutChanged(); m_nPrevCurrentRow = -2; // to make sure that onFilesGSelChanged() updates the notes and streams regardless of whether there are any files in m_pFilesG or not if (!m_pCommonData->getViewHandlers().empty()) { //pSelModel->select(index(0, 0), QItemSelectionModel::Current); //pSelModel->select(index(0, 0), QItemSelectionModel::Select); //m_pCommonData->printFilesCrt(); m_pCommonData->m_pFilesG->setCurrentIndex(index(nRow, 0)); // this sometimes calls onFilesGSelChanged(), but not always; //m_pCommonData->printFilesCrt(); } if (-2 == m_nPrevCurrentRow) { onFilesGSelChanged(); } for (int i = 0, n = cSize(vnSel); i < n; ++i) { pSelModel->select(pSelModel->model()->index(vnSel[i], 0), QItemSelectionModel::Select); } }
void FileRenamerDlgImpl::reloadTable() { { bool bVa (false); bool bErr (false); // it's error if any file lacks ID3V2 const deque<const Mp3Handler*>& vpHndl (m_pHndlrListModel->getHandlerList()); if (vpHndl.empty()) { accept(); return; } int n (cSize(vpHndl)); CB_ASSERT (n > 0); string strArtist ("\1"); for (int i = 0; i < n; ++i) { const Mp3Handler* pHndl (vpHndl[i]); const Id3V2StreamBase* pId3V2 (pHndl->getId3V2Stream()); if (0 == pId3V2) { bErr = true; } else { if ("\1" == strArtist) { strArtist = pId3V2->getArtist(); } else { if (strArtist != pId3V2->getArtist()) { bVa = true; } } } } if (bErr) { m_eState = "\1" == strArtist ? ERR : bVa ? VARIOUS_ERR : SINGLE_ERR; } else { m_eState = bVa ? VARIOUS : SINGLE; } } selectPattern(); m_pHndlrListModel->emitLayoutChanged(); const Mp3Handler* p (m_pHndlrListModel->getHandlerList().at(0)); // !!! it was supposed to close the window if nothing remained if (!m_bUseCurrentView) { m_pCrtDirTagEdtE->setText(toNativeSeparators(convStr(p->getDir()))); } //m_pCrtDirTagEdtE->hide(); //setWindowTitle("MP3 Diags - " + convStr(p->getDir()) + " - File renamer"); QItemSelectionModel* pSelModel (m_pCurrentAlbumG->selectionModel()); pSelModel->clear(); pSelModel->setCurrentIndex(m_pHndlrListModel->index(0, 0), QItemSelectionModel::SelectCurrent); resizeUi(); }
void KWQTableView::nextCell() { QItemSelectionModel * selModel = selectionModel(); QModelIndexList indexes = selModel->selectedIndexes(); QModelIndex currentIndex = selModel->currentIndex(); int currentRow = currentIndex.row(); int currentColumn = currentIndex.column(); int newRow = currentRow; int newColumn = currentColumn; if (indexes.count() == 1) //one cell selected { switch(Prefs::enterMove()) { case 0: //down if (currentRow == (model()->rowCount() - 1)) { model()->insertRows(model()->rowCount(), 1, QModelIndex()); newRow++; } else newRow++; break; case 1: //right if (currentRow == (model()->rowCount() - 1) && currentColumn == 1) { model()->insertRows(model()->rowCount(), 1, QModelIndex()); newRow++; newColumn = 0; } else { if (currentColumn == 0) newColumn++; else { newRow++; newColumn--; } } break; case 2: //no move //do nothing break; } QModelIndex newIndex = model()->index(newRow, newColumn); selModel->clear(); selModel->setCurrentIndex(newIndex, QItemSelectionModel::SelectCurrent); } else if (indexes.count() > 1) //a larger selection, move within it { QModelIndex topLeft = indexes.first(); QModelIndex bottomRight = indexes.last(); int tr = topLeft.row(); int lc = topLeft.column(); int br = bottomRight.row(); int rc = bottomRight.column(); switch(Prefs::enterMove()) { case 0: if (currentRow == br) { newRow = tr; if (currentColumn < rc) newColumn = rc; else newColumn = lc; } else if (currentRow < br) newRow++; break; case 1: if (currentColumn == rc) { newColumn = lc; if (currentRow < br) newRow++; else newRow = tr; } else newColumn++; break; case 2: //do nothing break; } QModelIndex newIndex = model()->index(newRow, newColumn); selModel->setCurrentIndex(newIndex, QItemSelectionModel::Current); } if (newColumn != currentColumn) updateKeyboardLayout(); }
void ccDBRoot::deleteSelectedEntities() { QItemSelectionModel* qism = m_dbTreeWidget->selectionModel(); QModelIndexList selectedIndexes = qism->selectedIndexes(); if (selectedIndexes.size() < 1) return; unsigned selCount = (unsigned)selectedIndexes.size(); hidePropertiesView(); //specific case: shared labels ccHObject::Container allLabels; bool hasSharedLabels = false; std::set<ccHObject*> cloudsToBeDeleted; //will only be used if 'hasSharedLabels' is true if (m_treeRoot->filterChildren(allLabels,true,CC_2D_LABEL) != 0) { for (unsigned i=0; i<allLabels.size(); ++i) { cc2DLabel* label = static_cast<cc2DLabel*>(allLabels[i]); //shared labels are labels shared by at least 2 different clouds if (label->size() > 1 && label->getPoint(0).cloud != label->getPoint(1).cloud || label->size() > 2 && label->getPoint(1).cloud != label->getPoint(2).cloud) { hasSharedLabels = true; break; } } } //we remove all objects that are children of other deleted ones! //(otherwise we may delete the parent before the child!) std::vector<ccHObject*> toBeDeleted; for (unsigned i=0;i<selCount;++i) { ccHObject* obj = static_cast<ccHObject*>(selectedIndexes[i].internalPointer()); //we don't take care of parentless objects (i.e. the tree root) if (!obj->getParent() || obj->isLocked()) { ccConsole::Warning(QString("Object '%1' can't be deleted this way (locked)").arg(obj->getName())); continue; } //we don't take objects that are siblings of others bool isSiblingOfAnotherOne = false; for (unsigned j=0;j<selCount;++j) { if (i != j) { ccHObject* otherObj = static_cast<ccHObject*>(selectedIndexes[j].internalPointer()); if (otherObj->isAncestorOf(obj)) { isSiblingOfAnotherOne = true; break; } } } if (!isSiblingOfAnotherOne) { //last check: mesh vertices if (obj->isKindOf(CC_POINT_CLOUD) && obj->getParent()->isKindOf(CC_MESH)) if (ccHObjectCaster::ToGenericMesh(obj->getParent())->getAssociatedCloud() == obj) { ccConsole::Warning("Mesh vertices can't be deleted without their parent mesh!"); continue; } toBeDeleted.push_back(obj); if (hasSharedLabels) { //we must keep a parallel list for clouds only if (obj->isA(CC_POINT_CLOUD)) { cloudsToBeDeleted.insert(obj); } else { ccHObject::Container subClouds; if (obj->filterChildren(subClouds,true,CC_POINT_CLOUD) != 0) for (size_t i=0; i<subClouds.size(); ++i) cloudsToBeDeleted.insert(subClouds[i]); } } } } qism->clear(); //check now that we don't delete clouds on which some labels are dependent if (hasSharedLabels) { size_t labelCount = allLabels.size(); for (size_t i=0;i<labelCount;++i) { cc2DLabel* label = static_cast<cc2DLabel*>(allLabels[i]); if (label->size() > 1) //there's no issue with 1-point labels! { for (unsigned j=1;j<label->size();++j) //1st cloud is always the parent! if (label->getPoint(j).cloud && label->getPoint(j).cloud != label->getPoint(0).cloud && cloudsToBeDeleted.find(label->getPoint(j).cloud) != cloudsToBeDeleted.end()) { ccLog::Warning(QString("Label '%1' has been deleted as it is dependent on '%2'").arg(label->getName()).arg(label->getPoint(j).cloud->getName())); label->clear(); toBeDeleted.push_back(label); } } } } while (!toBeDeleted.empty()) { ccHObject* anObject = toBeDeleted.back(); assert(anObject); toBeDeleted.pop_back(); anObject->prepareDisplayForRefresh_recursive(); if (anObject->isKindOf(CC_MESH)) { //specific case: the object is a mesh and its parent is its vertices! //(can happen if a Delaunay mesh is computed directly in CC) if (anObject->getParent() && anObject->getParent() == ccHObjectCaster::ToGenericMesh(anObject)->getAssociatedCloud()) anObject->getParent()->setVisible(true); } ccHObject* parent = anObject->getParent(); int childPos = parent->getChildIndex(anObject); assert(childPos>=0); beginRemoveRows(index(anObject).parent(),childPos,childPos); parent->removeChild(childPos); endRemoveRows(); } updatePropertiesView(); MainWindow::RefreshAllGLWindow(); }
void ccDBRoot::deleteSelectedEntities() { QItemSelectionModel* qism = m_dbTreeWidget->selectionModel(); QModelIndexList selectedIndexes = qism->selectedIndexes(); if (selectedIndexes.size() < 1) return; unsigned selCount = (unsigned)selectedIndexes.size(); hidePropertiesView(); //we remove all objects that are children of other deleted ones! //(otherwise we may delete the parent before the child!) std::vector<ccHObject*> toBeDeleted; for (unsigned i=0;i<selCount;++i) { ccHObject* obj = static_cast<ccHObject*>(selectedIndexes[i].internalPointer()); //we don't take care of parentless objects (i.e. the tree root) if (!obj->getParent() || obj->isLocked()) { ccConsole::Warning(QString("Object '%1' can't be deleted this way (locked)").arg(obj->getName())); continue; } //we don't take objects that are siblings of others bool isSiblingOfAnotherOne = false; for (unsigned j=0;j<selCount;++j) { if (i != j) { ccHObject* otherObj = static_cast<ccHObject*>(selectedIndexes[j].internalPointer()); if (otherObj->isAncestorOf(obj)) { isSiblingOfAnotherOne = true; break; } } } if (!isSiblingOfAnotherOne) { //last check: mesh vertices if (obj->isKindOf(CC_POINT_CLOUD) && obj->getParent()->isKindOf(CC_MESH)) if (static_cast<ccGenericMesh*>(obj->getParent())->getAssociatedCloud() == obj) { ccConsole::Warning("Mesh vertices can't be deleted without their parent mesh!"); continue; } toBeDeleted.push_back(obj); } } qism->clear(); while (!toBeDeleted.empty()) { ccHObject* anObject = toBeDeleted.back(); assert(anObject); toBeDeleted.pop_back(); anObject->prepareDisplayForRefresh_recursive(); //DGM FIXME: what a burden... we should find something simpler (shared pointers?) //specific case: if the entity is a cloud, we must look for 2-points //or 3-points labels that may have a dependence to it if (anObject->isKindOf(CC_POINT_CLOUD)) { ccHObject::Container allLabels; if (m_treeRoot->filterChildren(allLabels,true,CC_2D_LABEL) != 0) { unsigned labelCount = allLabels.size(); for (unsigned i=0;i<allLabels.size();++i) { cc2DLabel* label = static_cast<cc2DLabel*>(allLabels[i]); for (unsigned j=1;j<label->size();++j) //the first point is always the parent cloud! if (label->getPoint(j).cloud == anObject) { ccLog::Warning(QString("Label '%1' has been deleted as it is dependent on '%2'").arg(label->getName()).arg(anObject->getName())); label->clear(); toBeDeleted.push_back(label); } } } } ccHObject* parent = anObject->getParent(); int childPos = parent->getChildIndex(anObject); assert(childPos>=0); beginRemoveRows(index(anObject).parent(),childPos,childPos); parent->removeChild(childPos); endRemoveRows(); } updatePropertiesView(); MainWindow::RefreshAllGLWindow(); }