QString rosterListView::selectedBareJid() { if(selectedIndexes().size() > 0) return selectedIndexes().at(0).data(rosterItem::BareJid).toString(); else return ""; }
void BedCorrelationItemView::slotCustomContextMenuRequested(const QPoint& p) { QMenu* m = new QMenu(this); QAction* reloadA = new QAction(tr("Reload"), this); QAction* createA = new QAction(tr("Create BedCorrelation..."), this); QAction* editA = new QAction(tr("Edit..."), this); QAction* deleteA = new QAction(tr("Delete"), this); connect(reloadA, SIGNAL(activated()), this, SLOT(slotReload())); connect(createA, SIGNAL(activated()), this, SLOT(slotCreate())); connect(editA, SIGNAL(activated()), this, SLOT(slotEdit())); connect(deleteA, SIGNAL(activated()), this, SLOT(slotDelete())); m->addAction(createA); if (selectedIndexes().count() == 1) { m->insertSeparator(editA); m->addAction(editA); } if (selectedIndexes().count() > 0) { m->insertSeparator(deleteA); m->addAction(deleteA); } m->addAction(reloadA); m->exec(mapToGlobal(p)); }
void PlaylistView::mousePressEvent(QMouseEvent* event) { if (!(editTriggers() & QAbstractItemView::SelectedClicked)) { QTreeView::mousePressEvent(event); return; } QModelIndex index = indexAt(event->pos()); if (event->button() == Qt::LeftButton && index.isValid() && index.data(Playlist::Role_CanSetRating).toBool()) { // Calculate which star was clicked double new_rating = RatingPainter::RatingForPos(event->pos(), visualRect(index)); if (selectedIndexes().contains(index)) { // Update all the selected items QModelIndexList src_index_list; for (const QModelIndex& index : selectedIndexes()) { if (index.data(Playlist::Role_CanSetRating).toBool()) { QModelIndex src_index = playlist_->proxy()->mapToSource(index); src_index_list << src_index; } } playlist_->RateSongs(src_index_list, new_rating); } else { // Update only this item playlist_->RateSong(playlist_->proxy()->mapToSource(index), new_rating); } } else { QTreeView::mousePressEvent(event); } inhibit_autoscroll_ = true; inhibit_autoscroll_timer_->start(); }
void ProcessListView::displaySelected(QModelIndex _index) { for (int i = 0; i < selectedIndexes().size(); i += model->getHeaderSize()) qDebug() << "ProcessListView: List Indexes: " << selectedIndexes().at(i).row(); qDebug() << "ProcessListView: finished? " << model->getProcess(_index.row())->isFinished(); qDebug() << "ProcessListView: Current Index: " << _index.row(); }
void ExtendedTableWidget::keyPressEvent(QKeyEvent* event) { // Call a custom copy method when Ctrl-C is pressed if(event->matches(QKeySequence::Copy)) { copy(false); return; } else if(event->matches(QKeySequence::Paste)) { // Call a custom paste method when Ctrl-V is pressed paste(); } else if(event->modifiers().testFlag(Qt::ControlModifier) && event->modifiers().testFlag(Qt::ShiftModifier) && (event->key() == Qt::Key_C)) { // Call copy with headers when Ctrl-Shift-C is pressed copy(true); } else if(event->key() == Qt::Key_Tab && hasFocus() && selectedIndexes().count() == 1 && selectedIndexes().at(0).row() == model()->rowCount()-1 && selectedIndexes().at(0).column() == model()->columnCount()-1) { // If the Tab key was pressed while the focus was on the last cell of the last row insert a new row automatically model()->insertRow(model()->rowCount()); } else if ((event->key() == Qt::Key_Delete) || (event->key() == Qt::Key_Backspace)) { // Check if entire rows are selected. We call the selectedRows() method here not only for simplicity reasons but also because it distinguishes between // "an entire row is selected" and "all cells of a row are selected", the former is e.g. the case when the row number is clicked, the latter when all cells // are selected manually. This is an important distinction (especially when a table has only one column!) to match the users' expectations. Also never // delete records when the backspace key was pressed. if(event->key() == Qt::Key_Delete && selectionModel()->selectedRows().size()) { // At least on entire row is selected. Because we don't allow completely arbitrary selections (at least at the moment) but only block selections, // this means that only entire entire rows are selected. If an entire row is (or multiple entire rows are) selected, we delete that record instead // of deleting only the cell contents. emit selectedRowsToBeDeleted(); } else { // No entire row is selected. So just set the selected cells to null or empty string depending on the modifier keys if(event->modifiers().testFlag(Qt::AltModifier)) { // When pressing Alt+Delete set the value to NULL for(const QModelIndex& index : selectedIndexes()) model()->setData(index, QVariant()); } else { // When pressing Delete only set the value to empty string for(const QModelIndex& index : selectedIndexes()) model()->setData(index, ""); } } } else if(event->modifiers().testFlag(Qt::ControlModifier) && (event->key() == Qt::Key_PageUp || event->key() == Qt::Key_PageDown)) { // When pressing Ctrl + Page up/down send a signal indicating the user wants to change the current table emit switchTable(event->key() == Qt::Key_PageDown); return; } // This prevents the current selection from being changed when pressing tab to move to the next filter. Note that this is in an 'if' condition, // not in an 'else if' because this way, when the tab key was pressed and the focus was on the last cell, a new row is inserted and then the tab // key press is processed a second time to move the cursor as well if((event->key() != Qt::Key_Tab && event->key() != Qt::Key_Backtab) || hasFocus()) QTableView::keyPressEvent(event); }
void GroupListView::DeleteItem() { ProgramsModel *progModel = qobject_cast<ProgramsModel*>(model()); if(!progModel) return; if(!selectedIndexes().isEmpty()) progModel->UserRemoveRows(selectedIndexes(),rootIndex()); else if(currentIndex().isValid()) progModel->UserRemoveRows(QModelIndexList()<<currentIndex(),rootIndex()); }
void GroupListView::Copy() { QMimeData *mime=0; if(!selectedIndexes().isEmpty()) mime = model()->mimeData( selectedIndexes() ); else if(currentIndex().isValid()) mime = model()->mimeData( QModelIndexList() << currentIndex() ); if(!mime) return; QApplication::clipboard()->setMimeData( mime ); }
void FileSystemTreeView::keyPressEvent(QKeyEvent *event) { switch (event->key()) { // Move up in the filesystem case Qt::Key_Backspace: { QString path = _fileSystemModel->filePath(_theIndex); QFileInfo fileInfo(path); if (fileInfo.isDir()) { QDir d(path); if (d.cdUp()) { emit folderChanged(d.absolutePath()); } } break; } // Change directory if selected one is a directory, otherwise, send track to playlist case Qt::Key_Return: case Qt::Key_Enter: { if (selectedIndexes().size() == 1) { QString path = _fileSystemModel->filePath(selectedIndexes().first()); QFileInfo fileInfo(path); if (fileInfo.isDir()) { emit folderChanged(fileInfo.absoluteFilePath()); } else if (FileHelper::suffixes().contains(fileInfo.suffix())) { this->convertIndex(selectedIndexes().first()); } } else { for (QModelIndex index : selectedIndexes()) { this->convertIndex(index); } } break; } case Qt::Key_Space: { if (selectedIndexes().isEmpty()) { this->selectionModel()->select(_fileSystemModel->index(0, 0, _theIndex), QItemSelectionModel::Select); } break; } case Qt::Key_Left: case Qt::Key_Right: case Qt::Key_Up: case Qt::Key_Down: TreeView::keyPressEvent(event); break; default: event->isAccepted(); this->scrollAndHighlight((QChar)event->key()); } }
//----------------------------------------------------------------------------- // Function: PortMapsTreeView::keyPressEvent() //----------------------------------------------------------------------------- void PortMapsTreeView::keyPressEvent(QKeyEvent* event) { // When delete is pressed, attempt to delete the selected mapping. if (event->key() == Qt::Key_Delete) { if (!selectedIndexes().isEmpty()) { emit removeItem(selectedIndexes().first()); } } else { QTreeView::keyPressEvent(event); } }
/** Alerts the user if there's too many tracks to add. */ QMessageBox::StandardButton TreeView::beforeSending(const QString &target, QList<QUrl> *tracks) { // Quick count tracks before anything else int count = this->countAll(selectedIndexes()); QMessageBox::StandardButton ret = Miam::showWarning(target, count); if (ret == QMessageBox::Ok) { // Gather all items (pure virtual call, this function must be reimplemented in subclasses: custom tree, file system, etc.) for (QModelIndex index : selectedIndexes()) { this->findAll(index, tracks); } } return ret; }
void MainWindow::selectNextNote(bool directionDown) { int toAdd = 1; // standard - select next note below if (!directionDown) toAdd = -1; auto selectionModel = ui_->listResult->selectionModel(); if (!selectionModel->selectedIndexes().isEmpty()) { auto newIndex = ui_->listResult->model()->index( selectionModel->selectedIndexes().first().row() + toAdd, 0 ); if (newIndex.isValid()) { selectionModel->select(newIndex, QItemSelectionModel::ClearAndSelect); } } }
QModelIndex ColorGridView::moveCursor(QAbstractItemView::CursorAction action, Qt::KeyboardModifiers) { //FIXME: keyboard navigation not work well QModelIndexList list = selectedIndexes(); if( !list.isEmpty() ){ QModelIndex index = list.at(0); int row = index.row(); int column = index.column(); int rMax = model()->rowCount()-1; int cMax = model()->columnCount()-1; switch(action){ case QAbstractItemView::MoveUp: row==0?:row--; break; case QAbstractItemView::MoveDown: row==rMax?:row++; break; case QAbstractItemView::MoveLeft: column==0?:column--; break; case QAbstractItemView::MoveRight: column==cMax?:column++; break; default: break; } return model()->index(row,column); }else{
void ListView::startDrag(Qt::DropActions supportedActions) { QModelIndexList indexes = selectedIndexes(); if (indexes.count() > 0) { QMimeData *data = model()->mimeData(indexes); if (!data) { return; } QDrag *drag = new QDrag(this); drag->setMimeData(data); QPixmap pix; if (1==indexes.count()) { QVariant var=model()->data(indexes.first(), ItemView::Role_Image); QImage img=var.value<QImage>(); if (img.isNull()) { pix=var.value<QPixmap>(); } else { pix=QPixmap::fromImage(img); } } if (pix.isNull()) { drag->setPixmap(Icons::self()->albumIcon.pixmap(64, 64)); } else { drag->setPixmap(pix.width()<64 ? pix : pix.scaled(QSize(64, 64), Qt::KeepAspectRatio, Qt::SmoothTransformation)); } drag->start(supportedActions); } }
/*! Returns the list of selecetd breakpoints. */ BreakpointTreeItem* BreakpointsTreeView::getSelectedBreakpointTreeItem() { const QModelIndexList modelIndexes = selectedIndexes(); foreach (QModelIndex modelIndex, modelIndexes) { return static_cast<BreakpointTreeItem*>(modelIndex.internalPointer()); } return 0; }
void CGroupListView::dropEvent(QDropEvent *event) { emit info(QString()); drawHighlighter(QModelIndex()); if(event->mimeData()->hasFormat(KFI_FONT_DRAG_MIME)) { event->acceptProposedAction(); QSet<QString> families; QByteArray encodedData(event->mimeData()->data(KFI_FONT_DRAG_MIME)); QDataStream ds(&encodedData, QIODevice::ReadOnly); QModelIndex from(selectedIndexes().last()), to(indexAt(event->pos())); ds >> families; // Are we mvoeing/copying, removing a font from the current group? if(to.isValid() && from.isValid()) { if( ((static_cast<CGroupListItem *>(from.internalPointer()))->isSystem() && (static_cast<CGroupListItem *>(to.internalPointer()))->isPersonal()) || ((static_cast<CGroupListItem *>(from.internalPointer()))->isPersonal() && (static_cast<CGroupListItem *>(to.internalPointer()))->isSystem())) QTimer::singleShot(0, this, SLOT(emitMoveFonts())); else if((static_cast<CGroupListItem *>(from.internalPointer()))->isCustom() && !(static_cast<CGroupListItem *>(to.internalPointer()))->isCustom()) emit removeFamilies(from, families); else emit addFamilies(to, families); } if(isUnclassified()) emit unclassifiedChanged(); }
//source: http://stackoverflow.com/questions/3135737/copying-part-of-qtableview void MyTableWidget::keyPressEvent(QKeyEvent* event) { // If Ctrl-C typed // Or use event->matches(QKeySequence::Copy) if (event->key() == Qt::Key_C && (event->modifiers() & Qt::ControlModifier)) { QModelIndexList cells = selectedIndexes(); qSort(cells); // Necessary, otherwise they are in column order QString text; int currentRow = 0; // To determine when to insert newlines foreach (const QModelIndex& cell, cells) { if (text.length() == 0) { // First item } else if (cell.row() != currentRow) { // New row text += '\n'; } else { // Next cell text += '\t'; } currentRow = cell.row(); text += cell.data().toString(); } QApplication::clipboard()->setText(text); }
void ItemLibraryTreeView::activateItem( const QModelIndex & /*index*/) { QMimeData *mimeData = model()->mimeData(selectedIndexes()); if (!mimeData) return; QString name; QFileSystemModel *fileSystemModel = qobject_cast<QFileSystemModel*>(model()); Q_ASSERT(fileSystemModel); QFileInfo fileInfo = fileSystemModel->fileInfo(selectedIndexes().front()); QPixmap pixmap(fileInfo.absoluteFilePath()); if (!pixmap.isNull()) { name = "image^" + fileInfo.absoluteFilePath(); emit itemActivated(name); } }
// --- void VSWSCReleasesDataListTree::keyReleaseEvent (QKeyEvent* evnt) { QModelIndexList selected = selectedIndexes (); QModelIndexList::iterator i = selected.begin (); if (i == selected.end ()) { QTreeView::keyReleaseEvent (evnt); // None has been selected, then it is sent to the parent... return; } // When a button is released, // then depending on the button one or other thing is done... QModelIndex index = *i; VSWSCReleasesDataListModel::Item* item = static_cast <VSWSCReleasesDataListModel::Item*> (index.internalPointer ()); evnt -> accept(); // But in any case, the event is just treated... if (item -> type () == 2) // Button works just for releases... { // What ever the key selected is... // The information has to be highlighted QTreeView::keyReleaseEvent (evnt); // Default treatement... emit (releaseSelectedSignal (item -> parent () -> value (), item -> value ())); // ...the data in the right side has to change... } }
QList<int>* listview_t::get_selectedIndexes() {//descending QList<int>* result = new QList<int>; QVector<int> temp; QModelIndexList list = selectedIndexes(); QModelIndexList::const_iterator it; for (it = list.constBegin(); it != list.constEnd(); it++) temp.push_back(it->row()); if (!temp.empty()) { for (int j = 0; j < temp.size() - 1; j++) { for (int i = 0; i < temp.size() - j - 1; i++) if (temp[i] > temp[i+1]) { int tmp = temp[i]; temp[i] = temp[i+1]; temp[i+1] = tmp; } result->push_back(temp[temp.size() - j - 1]); } result->push_back(temp[0]); } return result; }
void GameList::slotContextMenu(const QPoint& pos) { QModelIndex cell = indexAt(pos); QModelIndexList selection = selectedIndexes(); // Make sure the right click occured on a cell! if(cell.isValid() && selection.contains(cell)) { QMenu menu(tr("Game list"), this); menu.addAction(tr("Copy games..."), this, SLOT(slotCopyGame())); menu.addAction(tr("Filter twins"), this, SLOT(slotFindDuplicate())); QMenu* mergeMenu = menu.addMenu(tr("Merge into current game")); mergeMenu->addAction(tr("All Games"), this, SLOT(slotMergeAllGames())); mergeMenu->addAction(tr("Filter"), this, SLOT(slotMergeFilter())); mergeMenu->addAction(tr("Selected games"), this, SLOT(slotMergeGame())); menu.addSeparator(); QAction* deleteAction = menu.addAction(tr("Delete game"), this, SLOT(slotDeleteGame())); deleteAction->setCheckable(true); deleteAction->setEnabled(!m_model->filter()->database()->isReadOnly()); menu.addSeparator(); menu.addAction(tr("Hide game"), this, SLOT(slotHideGame())); QModelIndex index = GetSourceIndex(cell); int n = m_model->filter()->indexToGame(index.row()); deleteAction->setChecked(m_model->filter()->database()->deleted(n)); menu.exec(mapToGlobal(pos)); } }
vtkIdType * SpreadsheetTable::selectedRowIndices(int &nvals) const { vtkIdType *ids = 0; nvals = 0; QModelIndexList sel(selectedIndexes()); nvals = model()->columnCount(); if(nvals > 0) { int row = 0; ids = new vtkIdType[nvals]; for(QModelIndexList::iterator it = sel.begin(); it != sel.end(); ++it) { row = it->row(); break; } for(int col = 0; col < nvals; ++col) ids[col] = (vtkIdType)model()->index(row, col).internalId(); } return ids; }
int AnimationView::getCurrentFrame() const { QModelIndexList selected = selectedIndexes(); if (selected.size() == 1) return selected.at(0).row(); return -1; }
JID QtTreeWidget::selectedJID() const { QModelIndexList list = selectedIndexes(); if (list.size() != 1) { return JID(); } return jidFromIndex(list[0]); }
void BedCorrelationItemView::slotDelete() { QModelIndexList selected = selectedIndexes(); if (selected.isEmpty()) { return; } QStringList names; for (QModelIndexList::iterator it = selected.begin(); it != selected.end(); it++) { BedCorrelationItem* itm = (BedCorrelationItem*) ((BedCorrelationItemModel*) model())->itemFromIndex(*it); if (itm) { names << tr("Name: %1, ID: %2") .arg(itm->getBedCorrelation()->getName()) .arg(itm->getBedCorrelation()->getId()); } } if (QMessageBox::Yes == QMessageBox::warning(this, tr("Really Delete?"), tr("Really delete this BedCorrelations?\n%1") .arg(names.join(", ")), QMessageBox::Yes | QMessageBox::No)) { emit deleteRequest(selected); } }
void PortListView::performDrag() { QModelIndexList indexes = selectedIndexes(); QString mimeText; foreach (QModelIndex index, indexes) { // if the index is not valid if (!index.isValid()) continue; // add the port name of the indexed item to mime data mimeText += index.model()->data(index, Qt::DisplayRole).toString(); mimeText += ";"; } // set the mime data QMimeData* mimeData = new QMimeData(); mimeData->setText(mimeText); QDrag* drag = new QDrag(this); drag->setMimeData(mimeData); if (drag->exec(Qt::MoveAction) == Qt::MoveAction) { // inform the model that the dragged items could be removed emit removeItems(indexes); } }
int XTreeView::currentIndex() { QModelIndexList idx = selectedIndexes(); if(idx.isEmpty()) return -1; return idx.at(0).row(); }
void PackageView::selectionChanged(const QItemSelection &selected, const QItemSelection &deselected) { QTreeView::selectionChanged(selected, deselected); if (!selectedIndexes().size()) { emit selectionEmpty(); return; } if (!selected.indexes().isEmpty()) { emit currentPackageChanged(selected.indexes().first()); if(selectedIndexes().count()/NUM_COLUMNS > 1) { emit selectionMulti(); } } }
void RosterTreeView::sendMessage() { QModelIndexList list = selectedIndexes(); if(list.count()) { if(RosterSortProxy *proxy = dynamic_cast<RosterSortProxy*>(model())) { QList<KittySDK::IContact*> contacts; KittySDK::IContact *me = 0; foreach(QModelIndex in, list) { QModelIndex index = proxy->mapToSource(in); if(index.data(RosterItem::TypeRole) == RosterItem::Contact) { if(RosterContact *cnt = static_cast<RosterContact*>(index.internalPointer())) { //for 1st one we set the account used if(in == list.first()) { me = cnt->contact()->account()->me(); contacts << cnt->contact(); //only add for the same account } else if(me == cnt->contact()->account()->me()) { contacts << cnt->contact(); } } } } if(contacts.count()) { Core::inst()->mainWindow()->hideFilterEdit(); Core::inst()->chatManager()->startChat(me, contacts); } }
void ScriptTableView::startDrag(Qt::DropActions supportedActions) { QModelIndexList indexes = selectedIndexes(); for(int i = indexes.count() - 1 ; i >= 0; --i) { const QModelIndex &index = indexes.at(i); if(!(index.flags() & Qt::ItemIsDragEnabled)) indexes.removeAt(i); } if(indexes.count() == 0) return; QMimeData *data = model()->mimeData(indexes); if(!data) return; QRect rect; QDrag *drag = new QDrag(this); drag->setMimeData(data); Qt::DropAction finalDefaultDropAction = Qt::IgnoreAction; if(defaultDropAction() != Qt::IgnoreAction && (supportedActions & defaultDropAction())) finalDefaultDropAction = defaultDropAction(); else if(supportedActions & Qt::CopyAction && dragDropMode() != QAbstractItemView::InternalMove) finalDefaultDropAction = Qt::CopyAction; drag->exec(supportedActions, finalDefaultDropAction); }
// this is reimplemented from QAbstractItemView::startDrag() void ScreenSetupView::startDrag(Qt::DropActions) { QModelIndexList indexes = selectedIndexes(); if (indexes.count() != 1) return; QMimeData* pData = model()->mimeData(indexes); if (pData == NULL) return; QPixmap pixmap = *model()->screen(indexes[0]).pixmap(); QDrag* pDrag = new QDrag(this); pDrag->setPixmap(pixmap); pDrag->setMimeData(pData); pDrag->setHotSpot(QPoint(pixmap.width() / 2, pixmap.height() / 2)); if (pDrag->exec(Qt::MoveAction, Qt::MoveAction) == Qt::MoveAction) { selectionModel()->clear(); // make sure to only delete the drag source if screens weren't swapped // see ScreenSetupModel::dropMimeData if (!model()->screen(indexes[0]).swapped()) model()->screen(indexes[0]) = Screen(); else model()->screen(indexes[0]).setSwapped(false); } }