void MainWindow::openModeCreationDialogEdit() { QModelIndexList list = ui.modeListView->selectionModel()->selectedIndexes(); if (list.length() == 0) { QMessageBox::about(this, tr("Error"), tr("No mode chosen!")); return; } QModelIndex index = list.at(0); string name; name = index.data(ModeListItemDelegate::modeNameRole).toString().toStdString(); const Mode& mode = processController.getMode(name); if (modeCrDlg != NULL) { modeCrDlg->reject(); } modeCrDlg = new ModeCreationDialog(mode, this); connect(modeCrDlg, SIGNAL(modeEditAccepted(string&, Mode&)), this, SLOT(editMode(string&, Mode&))); connect(modeCrDlg, SIGNAL(rejected()), this, SLOT(closeModeCreationDialog())); modeCrDlg->exec(); }
void ClipboardModel::sortItems(const QModelIndexList &indexList, CompareItems *compare) { QList< QPair<int, ClipboardItemPtr> > list; QList<int> rows; for (int i = 0; i < indexList.length(); ++i) { int row = indexList[i].row(); if ( row >= m_clipboardList.length() ) return; list.append( qMakePair(row, m_clipboardList[row]) ); rows.append(row); } qSort(rows); qSort( list.begin(), list.end(), compare ); for (int i = 0; i < list.length(); ++i ) { int row1 = list[i].first; int row2 = rows[i]; if (row1 != row2) { m_clipboardList[row2] = list[i].second; QModelIndex ind = index(row2); emit dataChanged(ind, ind); } } }
void ClassifierTrainer::add_selection_to_positives_slot() { QModelIndexList indices = positivesTreeView->selectionModel()->selectedIndexes(); if (indices.length() > 0) { QModelIndex index = indices[0]; QStandardItem *item = positivesModel->item(index.row()); AddSectionDialog *dialog = new AddSectionDialog(item->text(), this); dialog->setModal(true); int response = dialog->exec(); if (response == 1) // accepted { Section s = dialog->section(); int sectionRowCount = item->rowCount() + 1; // save contents to project config file project->load(); if (project->addSectionToPositiveImage(s)) { project->save(); // update ui updatePositivesGroup(); } } } }
void MainWindow::on_edit_clicked() { QItemSelectionModel *select = ui->targetListTable->selectionModel(); QModelIndexList selectedRows = select->selectedRows(); if (select->hasSelection() && selectedRows.length() == 1) { // only 1 item can be selected QList<QModelIndex>::iterator i = selectedRows.begin(); int selectedRow = i->row(); // gets the selected row number // Creates edit window targetEditor = new TargetMaker(this); targetEditor->setModal(true); targetEditor->setWindowTitle("Edit Target"); // Sets default values targetEditor->defaultFileInput = targetList->rows->at(selectedRow)->imageFilePath; targetEditor->defaultNameInput = targetList->rows->at(selectedRow)->name->text(); targetEditor->defaultCoordInput = targetList->rows->at(selectedRow)->coord->text(); targetEditor->defaultDescInput = targetList->rows->at(selectedRow)->desc->text(); targetEditor->setDefaultInputs(); // Opens edit window targetEditor->exec(); if (targetEditor->accepted) { targetList->editRow(selectedRow, targetEditor->getImageFilePath(), targetEditor->getName(), targetEditor->getCoord(), targetEditor->getDesc()); } } }
void MainWindow::selectionChanged(const QItemSelection &/*selected*/, const QItemSelection &/*deselected*/) { QModelIndexList rows = mSelectionModel->selectedRows(); modify_PB->setEnabled(rows.length() == 1); remove_PB->setEnabled(rows.length() != 0); bool enableSwap = (rows.length() == 2); if (enableSwap) { QPair<bool, GeneralActionInfo> info0 = mActions->actionById(mDefaultModel->id(mSortFilterProxyModel->mapToSource(rows[0]))); QPair<bool, GeneralActionInfo> info1 = mActions->actionById(mDefaultModel->id(mSortFilterProxyModel->mapToSource(rows[1]))); enableSwap = (info0.first && info1.first && (info0.second.shortcut == info1.second.shortcut)); } swap_PB->setEnabled(enableSwap); }
//----------------------------------------------------------------------------- void SetupTabMatrix::operationAdd() { QAction *a = qobject_cast<QAction *>(sender()); QVariant var = a->data(); bool ok; int shift = var.toInt(&ok); if (ok) { QItemSelectionModel *selection = this->ui->tableViewOperations->selectionModel(); QModelIndexList list = selection->selectedIndexes(); bool left = shift < 0; shift = qAbs(shift); quint32 mask = 0; for (int i = 0; i < list.length(); i++) { if (list.at(i).row() == 0) { mask |= 0x00000001 << (31 - list.at(i).column()); } } this->mPreset->matrix()->operationAdd(mask, shift, left); } }
QList<int> MainWindow::descendingTableSelection() { QList<int> returnValue; QModelIndexList selectedDownloads = ui->tableView->selectionModel()->selectedRows(); // search for index of download table from indexes of proxy model // this is needed because the removing of rows has to be done in an index descending order for(int i=downloadManager->numberOfDownloads()-1; i>=0; i--) { int idx = sortProxyModel->mapFromSource(downloadTable->index(i, 0)).row(); for(int j=0; j<selectedDownloads.length(); j++) { if(idx == selectedDownloads.at(j).row()) { returnValue.append(i); break; } } } return returnValue; }
void ClassifierTrainer::del_image_from_negatives_slot() { QModelIndexList indices = negativesTreeView->selectionModel()->selectedIndexes(); if (indices.length() > 0) { QModelIndex index = indices[0]; project->load(); QStandardItem *item = negativesModel->itemFromIndex(index); qDebug() << "ABout to delete negative : " << item->text(); project->removeNegativeImage(item->text()); project->save(); updateNegativesGroup(); } }
void HotkeysLibrarySingleshotView::startDrag(QMouseEvent *event) { QModelIndexList indices = this->selectedIndexes(); QByteArray objects; for(int i=0;i<indices.length(); i++) { objects.append(model()->index(indices.at(i).row(), 0).data().toByteArray()); objects.append(" "); } objects.remove(objects.length() - 1, 1); //qDebug() << objects; QMimeData *mimedata = new QMimeData(); mimedata->setData("application/sg-action-singleshot-reference", objects); QDrag *drag = new QDrag(this); drag->setMimeData(mimedata); QPixmap pixmap(this->style()->standardPixmap(QStyle::SP_FileIcon)); drag->setPixmap(pixmap); Qt::DropAction dropAction = drag->exec(Qt::CopyAction); }
bool ClipboardModel::moveItemsWithKeyboard(QModelIndexList indexList, int key, int count) { int from, to; bool res = false; QList<int> list; for ( int i = 0; i < indexList.length(); ++i ) list.append( indexList.at(i).row() ); if ( key == Qt::Key_Down || key == Qt::Key_End ) qSort( list.begin(), list.end(), qGreater<int>() ); else qSort( list.begin(), list.end(), qLess<int>() ); for ( int i = 0, d = 0; i<list.length(); ++i ) { from = list.at(i) + d; switch (key) { case Qt::Key_Down: to = from + count; break; case Qt::Key_Up: to = from - count; break; case Qt::Key_End: to = rowCount()-i-1; break; default: to = 0+i; break; } if ( to < 0 ) --d; else if (to >= rowCount() ) ++d; if ( !move(from, to) ) return false; if (!res) res = to==0 || from==0 || to == rowCount(); } return res; }
void QgsVertexEditor::updateVertexSelection( const QItemSelection &selected, const QItemSelection & ) { if ( mUpdatingTableSelection ) return; mUpdatingVertexSelection = true; mSelectedFeature->deselectAllVertices(); QgsCoordinateTransform t( mLayer->crs(), mCanvas->mapSettings().destinationCrs(), QgsProject::instance() ); std::unique_ptr<QgsRectangle> bbox; QModelIndexList indexList = selected.indexes(); for ( int i = 0; i < indexList.length(); ++i ) { int vertexIdx = indexList.at( i ).row(); mSelectedFeature->selectVertex( vertexIdx ); // create a bounding box of selected vertices QgsPointXY point( mSelectedFeature->vertexMap().at( vertexIdx )->point() ); if ( !bbox ) bbox.reset( new QgsRectangle( point, point ) ); else bbox->combineExtentWith( point ); } //ensure that newly selected vertices are visible in canvas if ( bbox ) { try { QgsRectangle transformedBbox = t.transform( *bbox ); QgsRectangle canvasExtent = mCanvas->mapSettings().extent(); transformedBbox.combineExtentWith( canvasExtent ); mCanvas->setExtent( transformedBbox ); } catch ( QgsCsException &cse ) { QgsMessageLog::logMessage( QObject::tr( "Simplify transform error caught: %1" ).arg( cse.what() ), QObject::tr( "CRS" ) ); } } mUpdatingVertexSelection = false; }
int MainWindow::deleteSelectedMode() { QModelIndexList list = ui.modeListView->selectionModel()->selectedIndexes(); if (list.length() == 0) { QMessageBox::about(this, tr("Error"), tr("No mode chosen!")); return 0; } QModelIndex index = list.at(0); string name; name = index.data(ModeListItemDelegate::modeNameRole).toString().toStdString(); processController.deleteMode(name); this->fillModeModel(); return 0; }
void ClassifierTrainer::del_image_from_positives_slot() { QModelIndexList indices = positivesTreeView->selectionModel()->selectedIndexes(); if (indices.length() > 0) { QModelIndex index = indices[0]; project->load(); QStandardItem *item = positivesModel->itemFromIndex(index); if (!item->parent()) { project->removePositiveImage(item->text()); project->save(); updatePositivesGroup(); } else { // TODO qDebug() << "Not parent. Need to get to parent."; } } }
void LogsDialog::plotLogs() { if (plotLock) return; if (!ui->FieldsTW->selectedItems().length()) { removeAllGraphs(); return; } plotsCollection plots; QModelIndexList selection = ui->logTable->selectionModel()->selectedRows(); int rowCount = selection.length(); bool hasLogSelection; QVarLengthArray<int> selectedRows; if (rowCount) { hasLogSelection = true; foreach (QModelIndex index, selection) { selectedRows.append(index.row()); } qSort(selectedRows.begin(), selectedRows.end()); } else {
//----------------------------------------------------------------------------- void SetupTabMatrix::on_tableViewOperations_customContextMenuRequested(const QPoint &point) { QModelIndex index = this->ui->tableViewOperations->indexAt(point); QItemSelectionModel *selection = this->ui->tableViewOperations->selectionModel(); if (this->mMenu != NULL) { delete this->mMenu; this->mMenu = NULL; } if (index.isValid()) { MatrixPreviewModel::RowType type = this->mMatrixModel->rowType(index.row()); QModelIndexList list = selection->selectedIndexes(); switch (type) { case MatrixPreviewModel::Source: { bool found = false; for (int i = 0; i < list.length() && !found; i++) { if (list.at(i).row() == 0) found = true; } if (found) { this->mMenu = new QMenu(tr("Source"), this); QMenu *left = new QMenu(tr("Add \"Left Shift\""), this->mMenu); QMenu *right = new QMenu(tr("Add \"Right Shift\""), this->mMenu); this->mMenu->addMenu(left); this->mMenu->addMenu(right); for (int i = 0; i < 32; i++) { QAction *action = left->addAction(QString("<< %1").arg(i), this, SLOT(operationAdd())); action->setData(QVariant(-i)); action = right->addAction(QString(">> %1").arg(i), this, SLOT(operationAdd())); action->setData(QVariant(i)); } this->mMenu->exec(this->ui->tableViewOperations->mapToGlobal(point)); } break; } case MatrixPreviewModel::Operation: { this->mMenu = new QMenu(tr("Operation"), this); int operationIndex = index.row() - 1; quint32 mask; int shift; bool left; this->mPreset->matrix()->operation(operationIndex, &mask, &shift, &left); QAction *actionLeft = this->mMenu->addAction(tr("Shift left"), this, SLOT(operationShift())); QAction *actionRight = this->mMenu->addAction(tr("Shift right"), this, SLOT(operationShift())); QAction *actionRemove = this->mMenu->addAction(tr("Remove"), this, SLOT(operationRemove())); Q_UNUSED(actionRemove) quint32 data = operationIndex; actionLeft->setData(QVariant(data | 0x80000000)); actionRight->setData(QVariant(data)); actionRemove->setData(QVariant(data)); if (shift >= 31) { if (left) actionLeft->setEnabled(false); else actionRight->setEnabled(false); } this->mMenu->exec(this->ui->tableViewOperations->mapToGlobal(point)); break; } case MatrixPreviewModel::MaskUsed: case MatrixPreviewModel::MaskAnd: case MatrixPreviewModel::MaskOr: case MatrixPreviewModel::MaskFill: { this->mMenu = new QMenu(tr("Mask"), this); quint32 data = (quint32)type; quint32 bits = 0; for (int i = 0; i < list.length(); i++) { if (list.at(i).row() == index.row()) { bits |= 0x00000001 << (31 - list.at(i).column()); } } // show menu if more than 0 bits was selected if (bits != 0) { QList<QVariant> parameters; parameters.append(QVariant(data)); parameters.append(QVariant(bits)); parameters.append(QVariant(true)); QAction *actionSet = this->mMenu->addAction(tr("Set 1"), this, SLOT(maskReset())); actionSet->setData(parameters); QAction *actionReset = this->mMenu->addAction(tr("Set 0"), this, SLOT(maskReset())); parameters.replace(2, QVariant(false)); actionReset->setData(parameters); } this->mMenu->exec(this->ui->tableViewOperations->mapToGlobal(point)); break; } default: break; } } }
void TagLineEdit::keyPressEvent(QKeyEvent* event) { if (m_model == NULL) return; bool requestComplete = false; bool dontProcess = false; switch (event->key()) { case Qt::Key_Left: case Qt::Key_Right: //Turn off the completer QLineEdit::keyPressEvent(event); lwPopup->hide(); return; case Qt::Key_Up: if (lwPopup->isVisible()) { lwPopup->clearSelection(); if (lwPopup->currentRow() == lwPopup->count() - 1) lwPopup->setCurrentRow(0, QItemSelectionModel::Select); else lwPopup->setCurrentRow(lwPopup->currentRow() + 1); } else QLineEdit::keyPressEvent(event); return; case Qt::Key_Down: if (lwPopup->isVisible()) { lwPopup->clearSelection(); if (lwPopup->currentRow() == 0) lwPopup->setCurrentRow(lwPopup->count() - 1, QItemSelectionModel::Select); else lwPopup->setCurrentRow(lwPopup->currentRow() - 1); } else QLineEdit::keyPressEvent(event); return; case Qt::Key_Space: if (event->modifiers() == Qt::ControlModifier) requestComplete = false; //Show the listwidget else if (lwPopup->isVisible()) requestComplete = true; break; //Note: The following two are not directly received, we pass them from the `event()` function. case Qt::Key_Tab: case Qt::Key_Backtab: if (lwPopup->isVisible()) { requestComplete = true; dontProcess = true; break; } else { event->ignore(); return; } case Qt::Key_Return: case Qt::Key_Enter: if (lwPopup->isVisible()) { requestComplete = true; dontProcess = true; } break; case Qt::Key_Escape: if (lwPopup->isVisible()) lwPopup->hide(); else QLineEdit::keyPressEvent(event); return; } if (!requestComplete) QLineEdit::keyPressEvent(event); QString thisText = this->text(); int pos1 = this->cursorPosition(), pos2 = this->cursorPosition(); //We wrap the `for`s in ifs to avoid increasing/decreasing the positions if // the cursor is already on space. if (pos1 >0 && thisText[pos1-1] != ' ') { for ( ; pos1 > 0; pos1--) { if (thisText[pos1] == ' ') { pos1++; break; } } } if (thisText[pos2] != ' ') { for ( ; pos2 < thisText.length(); pos2++) { if (thisText[pos2] == ' ') { pos2--; break; } } } if (!requestComplete) { QString textpresent = thisText.mid(pos1, pos2 - pos1); if (textpresent.length() == 0) { lwPopup->hide(); return; } QModelIndexList matches = m_model->match(m_model->index(0, m_modelcolumn), Qt::DisplayRole, textpresent, -1, Qt::MatchContains); if (matches.length() == 0) { lwPopup->hide(); return; } lwPopup->clear(); foreach (QModelIndex index, matches) lwPopup->addItem(m_model->data(index).toString()); lwPopup->setCurrentRow(0, QItemSelectionModel::Select); bool hasSelection = this->hasSelectedText(); int originalSelStart = this->selectionStart(); int originalCursorPos = this->cursorPosition(); this->setCursorPosition(pos1); int startOfWordX = this->cursorRect().left(); if (hasSelection) this->setSelection(originalSelStart, originalCursorPos - originalSelStart); else this->setCursorPosition(originalCursorPos); QPoint lwPopupOffset(startOfWordX, this->height()); lwPopup->move(this->parentWidget()->mapToGlobal(this->pos()) + lwPopupOffset); //qDebug() << this->pos() << lwPopup->pos(); lwPopup->resize(80, 120); lwPopup->show(); } else { //Do NOT do NOW: QLineEdit::keyPressEvent(event); //We should only do it for space; after we're done. QString finalText = thisText.mid(0, pos1); finalText += lwPopup->currentIndex().data().toString(); int cursorPos = finalText.length(); finalText += thisText.mid(pos2); this->setText(finalText); this->setCursorPosition(cursorPos); //this->setSelection(cursorPos, 0); lwPopup->hide(); if (dontProcess) event->accept(); if (!dontProcess) { QLineEdit::keyPressEvent(event); } } }
void cutDialog::edit_current_row() { QItemSelectionModel *selectionModel = listWidget->selectionModel(); QModelIndexList selected = selectionModel->selectedIndexes(); int row = listWidget ->currentRow(); QListWidgetItem * item = listWidget ->item(row); if(selected.length() != 1) { QMessageBox message(QMessageBox::Critical, "编辑错误 ", "<p>请选择单条文本内容进行编辑 !</font></strong></p>" ,QMessageBox::Ok ,this,Qt::Tool); this ->activateWindow(); message.exec(); return; } if(row >= 0 && item ->isSelected()) { editDialog = new QDialog(this); cutEdit = new QTextEdit(editDialog); QPushButton *okButton = new QPushButton("确定",editDialog); connect(okButton,SIGNAL(clicked()),this,SLOT(ok_edit_button())); QPushButton *cancelButton = new QPushButton("取消",editDialog); connect(cancelButton,SIGNAL(clicked()),this,SLOT(cancel_edit_button())); QListWidgetItem * item = listWidget ->item(row); int key = item->data(Qt::UserRole).toInt(); QString sqlStr = "select * from info where id = " + QString::number(key); QSqlQuery query; query.exec(sqlStr); while(query.next()) { if(query.value(2).toString() == "文本") { cutEdit ->setPlainText(query.value(3).toString()); } else { QMessageBox message(QMessageBox::Warning, "编辑提示 ", "文件不能编辑 !" ,QMessageBox::Ok ,this,Qt::Tool); this ->activateWindow(); message.exec(); return; } } QHBoxLayout *hboxLayout = new QHBoxLayout; hboxLayout ->addWidget(okButton); hboxLayout ->addStretch(); hboxLayout ->addWidget(cancelButton); QVBoxLayout *vboxLayout = new QVBoxLayout; vboxLayout ->addWidget(cutEdit); vboxLayout ->addLayout(hboxLayout); editDialog ->setLayout(vboxLayout); editDialog ->setWindowTitle("编辑"); //editDialog ->resize(400,500); editDialog ->setFixedSize(400,500); editDialog ->exec(); } else { QMessageBox message(QMessageBox::Critical, "编辑错误 ", "<p>请选择编辑的内容 !</font></strong></p>" ,QMessageBox::Ok ,this,Qt::Tool); this ->activateWindow(); message.exec(); } }
void MainWindow::collapseToTray() { // getting name of the active mode to start session QModelIndexList list = ui.modeListView->selectionModel()->selectedIndexes(); if (list.length() == 0) { QMessageBox::about(this, tr("Error"), tr("No mode chosen!")); return; } QModelIndex index = list.at(0); string name = index.data(ModeListItemDelegate::modeNameRole).toString().toStdString(); // setting current session mode this->processController.setSessionMode(name); // getting time of session stand unsigned long sessionStand; if (ui.checkTillDown->isChecked()) { sessionStand = ULLONG_MAX; // tray icon refresh tooltip trayIcon->setToolTip("Process Control\nMode: " + QString(name.c_str()) + "\nTime left: till shutdown"); } else { sessionStand = ui.timeEdit->time().msec() + ui.timeEdit->time().second() * MS_IN_S + ui.timeEdit->time().minute() * SEC_IN_MIN * MS_IN_S + ui.timeEdit->time().hour() * MIN_IN_HOUR * SEC_IN_MIN * MS_IN_S; //timer for tooltip refreshing connect(refreshTimer, SIGNAL(timeout()), this, SLOT(refreshTrayIconTooltip())); refreshTimer->start(REFRESH_TRAY_STAB); } // message box, TODO: maybe I need separated class for that or smth. QMessageBox msgBox; msgBox.setWindowTitle(tr("Process control")); msgBox.setText(tr("The program will keep running in the " "system tray. Reboot to prematurely terminate program.")); msgBox.setWindowIcon(QIcon(":/MainWindow/Resources/mainTray.ico")); msgBox.setStandardButtons(QMessageBox::Ok); msgBox.exec(); this->hide(); // preparing ... this->processController.start(sessionStand); // starting timer for control stabs - every CONTOL_STAB ms it will run function // for stopping restricted programs and injecting dll with restriction into browsers connect(controlTimer, SIGNAL(timeout()), this, SLOT(controlStab())); controlTimer->start(CONTROL_STAB); // starting end session timer connect(sessionTimer, SIGNAL(timeout()), this, SLOT(endSession())); sessionTimer->setSingleShot(true); sessionTimer->start(sessionStand); startTime->restart(); trayIcon->setVisible(true); trayIcon->show(); }