void UserphraseModel::remove(QModelIndexList indexList) { if (indexList.empty()) { qDebug() << "indexList is empty"; return; } qSort(indexList.begin(), indexList.end(), qGreater<QModelIndex>()); // XXX: indexList is in revsrsed order, so first is actual last, and vice // verse. auto first = indexList.last().row(); auto last = indexList.first().row(); emit beginRemoveRows(indexList.first().parent(), first, last); foreach(auto item, indexList) { auto index = item.row(); qDebug() << userphrase_[index].phrase_ << userphrase_[index].bopomofo_; auto ret = chewing_userphrase_remove( ctx_.get(), userphrase_[index].phrase_.toUtf8().constData(), userphrase_[index].bopomofo_.toUtf8().constData()); if (ret > 0) { // FIXME: std::vector::erase is an inefficient operation. userphrase_.erase(userphrase_.begin() + index); } else { qWarning() << "chewing_userphrase_remove() returns" << ret; } // FIXME: Handle chewing_userphrase_remove fails. }
void VcsEventWidgetPrivate::diffRevisions() { QModelIndexList l = m_ui->eventView->selectionModel()->selectedRows(); KDevelop::VcsEvent ev1 = m_logModel->eventForIndex( l.first() ); KDevelop::VcsEvent ev2 = m_logModel->eventForIndex( l.last() ); KDevelop::VcsJob* job = m_iface->diff( m_url, ev1.revision(), ev2.revision() ); VcsDiffWidget* widget = new VcsDiffWidget( job ); widget->setRevisions( ev1.revision(), ev2.revision() ); auto dlg = new QDialog( q ); dlg->setWindowTitle( i18n("Difference between Revisions") ); widget->connect(widget, &VcsDiffWidget::destroyed, dlg, &QDialog::deleteLater); auto mainLayout = new QVBoxLayout(dlg); auto buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok); auto okButton = buttonBox->button(QDialogButtonBox::Ok); okButton->setDefault(true); okButton->setShortcut(Qt::CTRL | Qt::Key_Return); dlg->connect(buttonBox, &QDialogButtonBox::accepted, dlg, &QDialog::accept); dlg->connect(buttonBox, &QDialogButtonBox::rejected, dlg, &QDialog::reject); mainLayout->addWidget(buttonBox); mainLayout->addWidget(widget); dlg->show(); }
void GraphicalUriArray::selectionChanged(const QItemSelection &, const QItemSelection & ) { QModelIndexList selected = m_listView->selectionModel()->selectedRows(); // we enable the "Up" button if exactly one item is selected, but not the first one m_btUp->setEnabled( selected.size() == 1 && selected.first().row() != 0 ); // we enable the "Down" button if exactly one item is selected, but not the last one m_btDown->setEnabled( selected.size() == 1 && selected.last().row() != m_model->rowCount() - 1 ); }
void QueueManager::MoveDown() { QModelIndexList indexes = ui_->list->selectionModel()->selectedRows(); qStableSort(indexes); if (indexes.isEmpty() || indexes.last().row() == current_playlist_->queue()->rowCount() - 1) return; for (int i = indexes.count() - 1; i >= 0; --i) { current_playlist_->queue()->MoveDown(indexes[i].row()); } }
//remove button clicked void AddFile_GUI::on_pushButton_4_clicked() { //get selected rows QModelIndexList indexes = ui->tableView->selectionModel()->selectedRows(); qSort(indexes.begin(), indexes.end()); //remove last index in list while (!indexes.isEmpty()) { model->removeRows(indexes.last().row(), 1); indexes.removeLast(); } }
void ProjectBuildSetWidget::selectionChanged() { QModelIndexList selectedRows = m_ui->itemView->selectionModel()->selectedRows(); kDebug() << "checking selectionmodel:" << selectedRows; m_ui->removeItemButton->setEnabled( !selectedRows.isEmpty() ); m_ui->addItemButton->setEnabled( !m_view->selectedItems().isEmpty() ); bool enableUp = selectedRows.count() > 0 && selectedRows.first().row() != 0; bool enableDown = selectedRows.count() > 0 && selectedRows.last().row() != m_ui->itemView->model()->rowCount() - 1; m_ui->upButton->setEnabled( enableUp ); m_ui->downButton->setEnabled( enableDown ); m_ui->bottomButton->setEnabled( enableDown ); m_ui->topButton->setEnabled( enableUp ); }
/*! \reimp */ void ItemViewFindWidget::find(const QString &ttf, bool skipCurrent, bool backward, bool *found, bool *wrapped) { if (!m_itemView || !m_itemView->model()->hasChildren()) return; QModelIndex idx; if (skipCurrent && m_itemView->selectionModel()->hasSelection()) { QModelIndexList il = m_itemView->selectionModel()->selectedIndexes(); qSort(il.begin(), il.end(), indexLessThan); idx = backward ? il.first() : il.last(); } else { idx = m_itemView->currentIndex(); } *found = true; QModelIndex newIdx = idx; if (!ttf.isEmpty()) { if (newIdx.isValid()) { int column = newIdx.column(); if (skipCurrent) if (QTreeView *tv = qobject_cast<QTreeView *>(m_itemView)) if (tv->allColumnsShowFocus()) column = backward ? 0 : m_itemView->model()->columnCount(newIdx.parent()) - 1; newIdx = findHelper(ttf, skipCurrent, backward, newIdx.parent(), newIdx.row(), column); } if (!newIdx.isValid()) { int row = backward ? m_itemView->model()->rowCount() : 0; int column = backward ? 0 : -1; newIdx = findHelper(ttf, true, backward, m_itemView->rootIndex(), row, column); if (!newIdx.isValid()) { *found = false; newIdx = idx; } else { *wrapped = true; } } } if (!isVisible()) show(); m_itemView->setCurrentIndex(newIdx); }
void TableGroupBox::cellSelected()//const QModelIndex & /* current */, const QModelIndex & /*previous*/) { QModelIndexList selectedRows = m_table->selectionModel()->selectedRows(); if (!selectedRows.isEmpty()) { // Enable the insert button if the entire row is selected m_insertButton->setEnabled(true); // If the last row is set to be fixed, then the remove button is // disabled for the final row. if ( m_lastRowFixed && selectedRows.last().row() == m_table->model()->rowCount() - 1 ) m_removeButton->setEnabled(false); else m_removeButton->setEnabled(true); } else { // Disable the buttons m_insertButton->setEnabled(false); m_removeButton->setEnabled(false); } }
QModelIndexList CartesianDiagramDataCompressor::indexesAt( const CachePosition& position ) const { if ( isValidCachePosition( position ) ) { CachePosition posPrev( position ); if( m_datasetDimension == 2 ){ if(posPrev.second) --posPrev.second; }else{ if(posPrev.first) --posPrev.first; } const QModelIndexList indPrev = mapToModel( posPrev ); const QModelIndexList indCur = mapToModel( position ); QModelIndexList indexes; if( m_datasetDimension == 2 ) { const int iStart = (indPrev.empty() || indPrev==indCur) ? indCur.first().column() : indPrev.first().column() + 1; const int iEnd = indCur.last().column(); for( int i=iStart; i<=iEnd; ++i){ indexes << m_model->index( position.first, i, m_rootIndex ); } } else { const int iStart = (indPrev.empty() || indPrev==indCur) ? indCur.first().row() : indPrev.first().row() + 1; const int iEnd = (indCur.isEmpty()) ? iStart : indCur.first().row(); //qDebug()<<iStart<<iEnd << iEnd-iStart; for( int i=iStart; i<=iEnd; ++i){ indexes << m_model->index( i, position.second, m_rootIndex ); } } return indexes; } else { return QModelIndexList(); } }
void QueryView::copyc() { QItemSelectionModel *s = qview->selectionModel(); QModelIndexList indices = s->selectedIndexes(); if(indices.isEmpty()) { return; } qSort(indices); QModelIndex prev = indices.first(); QModelIndex last = indices.last(); indices.removeFirst(); QModelIndex current; QString selectedText; foreach(current, indices) { QVariant data = qview->model()->data(prev); selectedText.append(data.toString()); if(current.row() != prev.row()) selectedText.append(QLatin1Char('\n')); else selectedText.append(QLatin1Char('\t')); prev = current; }
void RPCConsole::peerLayoutChanged() { if (!clientModel) return; const CNodeCombinedStats *stats = NULL; bool fUnselect = false; bool fReselect = false; if (cachedNodeid == -1) // no node selected yet return; // find the currently selected row int selectedRow; QModelIndexList selectedModelIndex = ui->peerWidget->selectionModel()->selectedIndexes(); if (selectedModelIndex.isEmpty()) selectedRow = -1; else selectedRow = selectedModelIndex.first().row(); // check if our detail node has a row in the table (it may not necessarily // be at selectedRow since its position can change after a layout change) int detailNodeRow = clientModel->getPeerTableModel()->getRowByNodeId(cachedNodeid); if (detailNodeRow < 0) { // detail node dissapeared from table (node disconnected) fUnselect = true; cachedNodeid = -1; ui->detailWidget->hide(); ui->peerHeading->setText(tr("Select a peer to view detailed information.")); } else { if (detailNodeRow != selectedRow) { // detail node moved position fUnselect = true; fReselect = true; } // get fresh stats on the detail node. stats = clientModel->getPeerTableModel()->getNodeStats(detailNodeRow); } if (fUnselect && selectedRow >= 0) { ui->peerWidget->selectionModel()->select(QItemSelection(selectedModelIndex.first(), selectedModelIndex.last()), QItemSelectionModel::Deselect); } if (fReselect) { ui->peerWidget->selectRow(detailNodeRow); } if (stats) updateNodeDetail(stats); }
void RPCConsole::peerLayoutChanged() { const CNodeCombinedStats *stats = NULL; bool fUnselect = false, fReselect = false, fDisconnected = false; if (detailNodeStats.nodestats.nodeid == -1) // no node selected yet return; // find the currently selected row int selectedRow; QModelIndexList selectedModelIndex = ui->peerWidget->selectionModel()->selectedIndexes(); if (selectedModelIndex.isEmpty()) selectedRow = -1; else selectedRow = selectedModelIndex.first().row(); // check if our detail node has a row in the table (it may not necessarily // be at selectedRow since its position can change after a layout change) int detailNodeRow = clientModel->getPeerTableModel()->getRowByNodeId(detailNodeStats.nodestats.nodeid); if (detailNodeRow < 0) { // detail node dissapeared from table (node disconnected) fUnselect = true; fDisconnected = true; detailNodeStats.nodestats.nodeid = 0; } else { if (detailNodeRow != selectedRow) { // detail node moved position fUnselect = true; fReselect = true; } // get fresh stats on the detail node. stats = clientModel->getPeerTableModel()->getNodeStats(detailNodeRow); } if (fUnselect && selectedRow >= 0) { ui->peerWidget->selectionModel()->select(QItemSelection(selectedModelIndex.first(), selectedModelIndex.last()), QItemSelectionModel::Deselect); } if (fReselect) { ui->peerWidget->selectRow(detailNodeRow); } if (stats) updateNodeDetail(stats); if (fDisconnected) { ui->peerHeading->setText(QString(tr("Peer Disconnected"))); ui->detailWidget->setDisabled(true); QDateTime dt = QDateTime::fromTime_t(detailNodeStats.nodestats.nLastSend); if (detailNodeStats.nodestats.nLastSend) ui->peerLastSend->setText(dt.toString("yyyy-MM-dd hh:mm:ss")); dt.setTime_t(detailNodeStats.nodestats.nLastRecv); if (detailNodeStats.nodestats.nLastRecv) ui->peerLastRecv->setText(dt.toString("yyyy-MM-dd hh:mm:ss")); dt.setTime_t(detailNodeStats.nodestats.nTimeConnected); ui->peerConnTime->setText(dt.toString("yyyy-MM-dd hh:mm:ss")); } }
void ExtendedTableWidget::copy() { QModelIndexList indices = selectionModel()->selectedIndexes(); // Abort if there's nothing to copy if (indices.isEmpty()) return; qSort(indices); SqliteTableModel* m = qobject_cast<SqliteTableModel*>(model()); // If a single cell is selected, copy it to clipboard if (indices.size() == 1) { QImage img; QVariant data = m->data(indices.first(), Qt::EditRole); if (img.loadFromData(data.toByteArray())) { // If it's an image qApp->clipboard()->setImage(img); return; } else { qApp->clipboard()->setText(data.toString()); return; } } m_buffer.clear(); // If any of the cells contain binary data - we use inner buffer bool containsBinary = false; foreach (const QModelIndex& index, indices) if (m->isBinary(index)) { containsBinary = true; break; } if (containsBinary) { qApp->clipboard()->clear(); // Copy selected data into inner buffer int columns = indices.last().column() - indices.first().column() + 1; while (!indices.isEmpty()) { QByteArrayList lst; for (int i = 0; i < columns; ++i) { lst << indices.first().data(Qt::EditRole).toByteArray(); indices.pop_front(); } m_buffer.push_back(lst); } return; } QModelIndex first = indices.first(); QString result; int currentRow = 0; foreach(const QModelIndex& index, indices) { if (first == index) { /* first index */ } else if (index.row() != currentRow) result.append("\r\n"); else result.append("\t"); currentRow = index.row(); QVariant data = index.data(Qt::EditRole); // non-NULL data is enquoted, whilst NULL isn't if (!data.isNull()) { QString text = data.toString(); text.replace("\"", "\"\""); result.append(QString("\"%1\"").arg(text)); } } qApp->clipboard()->setText(result); }
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(); }