void LocalView::slot_refresh_directory_tree() { //qDebug() <<__FUNCTION__<<": "<<__LINE__<<":"<< __FILE__; QItemSelectionModel *ism = this->uiw->treeView->selectionModel(); QModelIndex cidx, idx; if (ism != 0) { if (ism->hasSelection()) { cidx = ism->currentIndex(); idx = ism->model()->index(cidx.row(), 0, cidx.parent()); // QModelIndex origIndex = this->dir_file_model->mapToSource(mil.at(0)); QModelIndex origIndex = this->dir_file_model->mapToSource(idx); } // QModelIndexList mil = ism->selectedIndexes(); // if (mil.count() > 0) { // // model->refresh(mil.at(0)); // QModelIndex origIndex = this->dir_file_model->mapToSource(mil.at(0)); // q_debug()<<mil.at(0)<<origIndex; // // model->refresh(origIndex); // } } this->dir_file_model->refresh(this->uiw->tableView->rootIndex()); }
SettingsDialog::SettingsDialog(Core::Application *app, ListModel *listModel, QWidget *parent) : QDialog(parent), ui(new Ui::SettingsDialog()), m_application(app), m_docsetRegistry(app->docsetRegistry()) { ui->setupUi(this); #ifdef Q_OS_OSX ui->availableDocsetList->setAttribute(Qt::WA_MacShowFocusRect, false); ui->installedDocsetList->setAttribute(Qt::WA_MacShowFocusRect, false); #endif ui->downloadableGroup->hide(); ui->docsetsProgress->hide(); ui->installedDocsetList->setItemDelegate(new DocsetListItemDelegate(this)); ui->installedDocsetList->setModel(listModel); ui->installedDocsetList->setSelectionMode(QAbstractItemView::ExtendedSelection); QItemSelectionModel *selectionModel = ui->installedDocsetList->selectionModel(); connect(selectionModel, &QItemSelectionModel::selectionChanged, [this, selectionModel]() { if (!m_replies.isEmpty()) return; ui->removeDocsetsButton->setEnabled(selectionModel->hasSelection()); for (const QModelIndex &index : selectionModel->selectedIndexes()) { if (index.data(Zeal::ListModel::UpdateAvailableRole).toBool()) { ui->updateSelectedDocsetsButton->setEnabled(true); return; } } ui->updateSelectedDocsetsButton->setEnabled(false); }); connect(ui->updateSelectedDocsetsButton, &QPushButton::clicked, this, &SettingsDialog::updateSelectedDocsets); connect(ui->updateAllDocsetsButton, &QPushButton::clicked, this, &SettingsDialog::updateAllDocsets); connect(ui->removeDocsetsButton, &QPushButton::clicked, this, &SettingsDialog::removeSelectedDocsets); ui->availableDocsetList->setItemDelegate(new ProgressItemDelegate(this)); // Setup signals & slots connect(ui->buttonBox, &QDialogButtonBox::accepted, this, &SettingsDialog::saveSettings); connect(ui->buttonBox, &QDialogButtonBox::rejected, this, &SettingsDialog::loadSettings); connect(ui->buttonBox, &QDialogButtonBox::clicked, this, [this](QAbstractButton *button) { if (button == ui->buttonBox->button(QDialogButtonBox::Apply)) saveSettings(); }); connect(ui->minFontSize, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), this, [](int value) { QWebSettings::globalSettings()->setFontSize(QWebSettings::MinimumFontSize, value); }); connect(ui->addFeedButton, &QPushButton::clicked, this, &SettingsDialog::addDashFeed); connect(ui->refreshButton, &QPushButton::clicked, this, &SettingsDialog::downloadDocsetList); connect(m_application, &Core::Application::extractionCompleted, this, &SettingsDialog::extractionCompleted); connect(m_application, &Core::Application::extractionError, this, &SettingsDialog::extractionError); connect(m_application, &Core::Application::extractionProgress, this, &SettingsDialog::extractionProgress); loadSettings(); }
void Matrix::pasteSelection() { if (d_view_type == ImageView) return; QString text = QApplication::clipboard()->text(); if (text.isEmpty()) return; QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); QStringList linesList = text.split(applicationWindow()->endOfLine(), QString::SkipEmptyParts); int rows = linesList.size(); if (!rows) return; int cols = linesList[0].split("\t").count(); for (int i = 1; i < rows; i++){ int aux = linesList[i].split("\t").count(); if (aux > cols) cols = aux; } int topRow = 0, leftCol = 0; QItemSelectionModel *selModel = d_table_view->selectionModel(); if (selModel->hasSelection()){ QItemSelectionRange sel = selModel->selection()[0]; topRow = sel.top(); leftCol = sel.left(); } int oldRows = numRows(); int bottomRow = topRow + rows - 1; if (bottomRow > oldRows - 1) bottomRow = oldRows - 1; int oldCols = numCols(); int rightCol = leftCol + cols - 1; if (rightCol > oldCols - 1) rightCol = oldCols - 1; double *clipboardBuffer = (double *)malloc(rows*cols*sizeof(double)); if (!clipboardBuffer){ QMessageBox::critical(this, tr("QtiPlot") + " - " + tr("Memory Allocation Error"), tr("Not enough memory, operation aborted!")); QApplication::restoreOverrideCursor(); return; } QLocale locale = this->locale(); //Better use QLocale::system() ?? int cell = 0; for(int i = 0; i < rows; i++){ QStringList cells = linesList[i].split("\t"); int size = cells.count(); for(int j = 0; j<cols; j++){ if (j >= size){ clipboardBuffer[cell++] = GSL_NAN; continue; } bool numeric = true; double value = locale.toDouble(cells[j], &numeric); if (numeric) clipboardBuffer[cell++] = value; else clipboardBuffer[cell++] = GSL_NAN; } } QApplication::restoreOverrideCursor(); double *backupBuffer = d_matrix_model->dataCopy(topRow, bottomRow, leftCol, rightCol); if (backupBuffer){ d_undo_stack->push(new MatrixPasteCommand(d_matrix_model, topRow, bottomRow, leftCol, rightCol, clipboardBuffer, rows, cols, backupBuffer, oldRows, oldCols, tr("Paste"))); emit modifiedWindow(this); } else if (ignoreUndo()){ d_matrix_model->pasteData(clipboardBuffer, topRow, leftCol, rows, cols); emit modifiedWindow(this); } }
void GameDatabaseDialog::gameSelectionChanged(const QModelIndex& current, const QModelIndex& previous) { Q_UNUSED(previous); const PgnGameEntry* entry = m_pgnGameEntryModel->entryAt(current.row()); PgnGame game; PgnDatabase::PgnDatabaseError error; if ((error = m_selectedDatabase->game(entry, &game)) != PgnDatabase::NoError) { if (error == PgnDatabase::DatabaseDoesNotExist) { // Ask the user if the database should be deleted from the // list QMessageBox msgBox(this); QPushButton* removeDbButton = msgBox.addButton(tr("Remove"), QMessageBox::ActionRole); msgBox.addButton(QMessageBox::Cancel); msgBox.setText("PGN database does not exist."); msgBox.setInformativeText(QString("Remove %1 from the list of databases?").arg(m_selectedDatabase->displayName())); msgBox.setDefaultButton(removeDbButton); msgBox.setIcon(QMessageBox::Warning); msgBox.exec(); if (msgBox.clickedButton() == removeDbButton) { QItemSelectionModel* selection = ui->m_databasesListView->selectionModel(); if (selection->hasSelection()) CuteChessApplication::instance()->gameDatabaseManager()->removeDatabase(selection->currentIndex().row()); } } else { // Ask the user to re-import the database QMessageBox msgBox(this); QPushButton* importDbButton = msgBox.addButton(tr("Import"), QMessageBox::ActionRole); msgBox.addButton(QMessageBox::Cancel); if (error == PgnDatabase::DatabaseModified) { msgBox.setText("PGN database has been modified since the last import."); msgBox.setInformativeText("The database must be imported again to read it."); } else { msgBox.setText("Error occured while trying to read the PGN database."); msgBox.setInformativeText("Importing the database again may fix this problem."); } msgBox.setDefaultButton(importDbButton); msgBox.setIcon(QMessageBox::Warning); msgBox.exec(); if (msgBox.clickedButton() == importDbButton) { QItemSelectionModel* selection = ui->m_databasesListView->selectionModel(); if (selection->hasSelection()) CuteChessApplication::instance()->gameDatabaseManager()->importDatabaseAgain(selection->currentIndex().row()); } } } ui->m_whiteLabel->setText(game.tagValue("White")); ui->m_blackLabel->setText(game.tagValue("Black")); ui->m_siteLabel->setText(game.tagValue("Site")); ui->m_eventLabel->setText(game.tagValue("Event")); ui->m_resultLabel->setText(game.tagValue("Result")); m_boardScene->setBoard(game.createBoard()); m_boardScene->populate(); m_moveIndex = 0; m_moves = game.moves(); ui->m_previousMoveButton->setEnabled(false); ui->m_nextMoveButton->setEnabled(!m_moves.isEmpty()); ui->m_skipToFirstMoveButton->setEnabled(false); ui->m_skipToLastMoveButton->setEnabled(!m_moves.isEmpty()); }
void OnlineCenterSearch::updatePushButtons() { QItemSelectionModel *sm = view->selectionModel(); Ui::MainWindow *ui = NavApp::getMainUi(); ui->pushButtonOnlineCenterSearchClearSelection->setEnabled(sm != nullptr && sm->hasSelection()); }
void LocalView::slot_remove() { QItemSelectionModel *ism = this->curr_item_view->selectionModel(); // QModelIndexList mil; QModelIndex cidx, idx; if (ism == 0 || !ism->hasSelection()) { QMessageBox::critical(this, tr("Warning..."), tr("No item selected").leftJustified(50, ' ')); return; } // mil = ism->selectedIndexes(); cidx = ism->currentIndex(); idx = ism->model()->index(cidx.row(), 0, cidx.parent()); QString local_file = this->curr_item_view==this->uiw->treeView ? this->dir_file_model->filePath(idx) : this->model->filePath(idx); QStringList local_files; for (int i = ism->model()->rowCount(cidx.parent())-1; i >= 0; --i) { idx = ism->model()->index(i, 0, cidx.parent()); if (ism->isRowSelected(i, cidx.parent())) { local_file = this->curr_item_view==this->uiw->treeView ? this->dir_file_model->filePath(idx) : this->model->filePath(idx); local_files.prepend(local_file); } } if (QMessageBox::question(this, tr("Question..."), QString("%1\n %2").arg(QString(tr("Are you sure remove it?"))) .arg(local_files.join("\n ")), QMessageBox::Yes|QMessageBox::No) == QMessageBox::Yes) { bool bok; for (int i = ism->model()->rowCount(cidx.parent())-1; i >= 0; --i) { idx = ism->model()->index(i, 0, cidx.parent()); if (ism->isRowSelected(i, cidx.parent())) { idx = ism->model()->index(i, 0, cidx.parent()); if (ism->model() == this->model ? this->model->isDir(idx) : this->model->isDir(idx)) { bok = ism->model() == this->model ? this->model->rmdir(idx) : this->model->rmdir(idx); } else { bok = ism->model() == this->model ? this->model->remove(idx) : this->model->remove(idx); } if (bok) { // this->slot_refresh_directory_tree(); } else { local_file = this->curr_item_view==this->uiw->treeView ? this->dir_file_model->filePath(idx) : this->model->filePath(idx); q_debug()<<"can not remove file/direcotry:"<<i<<local_file; } } } // if (QFile::remove(local_file)) { // this->slot_refresh_directory_tree(); // } else { // q_debug()<<"can not remove file:"<<local_file; // } } }
void LocalView::slot_rmdir() { QString dir_name; QItemSelectionModel *ism = this->curr_item_view->selectionModel(); // QModelIndexList mil; QModelIndex cidx, idx; if (ism == 0 || !ism->hasSelection()) { qDebug()<<"SelectedIndexes count :"<< ism->hasSelection() << " why no item selected????"; QMessageBox::critical(this, tr("Warning..."), tr("No item selected")); return; } // mil = ism->selectedIndexes(); cidx = ism->currentIndex(); idx = ism->model()->index(cidx.row(), 0, cidx.parent()); QModelIndex midx = idx; QModelIndex aim_midx = (this->curr_item_view == this->uiw->treeView) ? this->dir_file_model->mapToSource(midx): midx; //检查所选择的项是不是目录 if (!this->model->isDir(aim_midx)) { QMessageBox::critical(this, tr("Warning..."), tr("The selected item is not a directory.")); return ; } // qDebug()<<QDir(this->model->filePath(aim_midx)).count(); if (QDir(this->model->filePath(aim_midx)).count() > 2) { QMessageBox::critical(this, tr("Warning..."), tr("Selected director not empty.")); return; } QModelIndex tree_midx = this->dir_file_model->mapFromSource(aim_midx); QModelIndex pidx = aim_midx.parent(); int it_row = tree_midx.row(); QModelIndex nidx = tree_midx.parent(); QString next_select_path; if (this->dir_file_model->rowCount(nidx) == 1) { // goto parent next_select_path = this->dir_file_model->filePath(nidx); } else if (it_row == this->dir_file_model->rowCount(nidx)-1) { // goto privious next_select_path = this->dir_file_model->filePath(this->dir_file_model->index(it_row-1, 0, nidx)); } else if (it_row > this->dir_file_model->rowCount(nidx)-1) { // not possible } else if (it_row < this->dir_file_model->rowCount(nidx)-1) { // goto next next_select_path = this->dir_file_model->filePath(this->dir_file_model->index(it_row+1, 0, nidx)); } else { // not possible } Q_ASSERT(!next_select_path.isEmpty()); if (this->model->rmdir(aim_midx)) { if (this->curr_item_view == this->uiw->treeView) { // this->slot_dir_tree_item_clicked(tree_midx.parent()); // A: if has next sible, will select next sible // B: if has priv sible, will select privious sible // C: if no next and no priv, will select parent // ism = this->curr_item_view->selectionModel(); idx = ism->currentIndex(); qDebug()<<idx<<this->dir_file_model->filePath(idx); // set selection and go on ism->clearSelection(); QItemSelection *selection = new QItemSelection(); // ism->select(this->dir_file_model->index(next_select_path), QItemSelectionModel::Select | QItemSelectionModel::Current | QItemSelectionModel::Rows); ism->setCurrentIndex(this->dir_file_model->index(next_select_path), QItemSelectionModel::Select | QItemSelectionModel::Current | QItemSelectionModel::Rows); idx = ism->currentIndex(); qDebug()<<idx<<this->dir_file_model->filePath(idx); this->slot_dir_tree_item_clicked(this->dir_file_model->index(next_select_path)); } } else { QMessageBox::critical(this, tr("Warning..."), tr("Delete directory faild. Maybe the directory is not empty.")); } // if (!QDir().rmdir(this->model->filePath(aim_midx))) { // QMessageBox::critical(this, tr("Warning..."), tr("Delete directory faild. Mayby the directory is not empty.")); // } else { // this->slot_refresh_directory_tree(); // } }
void DataOutputWidget::exportData(QTextStream &stream, const QChar stringsQuoteChar, const QChar numbersQuoteChar, const QString fieldDelimiter, const Options opt) { QItemSelectionModel *selectionModel = m_view->selectionModel(); if (!selectionModel->hasSelection()) return; QString fixedFieldDelimiter = fieldDelimiter; /// FIXME: ugly workaround... fixedFieldDelimiter = fixedFieldDelimiter.replace("\\t", "\t"); fixedFieldDelimiter = fixedFieldDelimiter.replace("\\r", "\r"); fixedFieldDelimiter = fixedFieldDelimiter.replace("\\n", "\n"); QTime t; t.start(); QSet<int> columns; QSet<int> rows; QHash<QPair<int,int>,QString> snapshot; const QModelIndexList selectedIndexes = selectionModel->selectedIndexes(); snapshot.reserve(selectedIndexes.count()); foreach (const QModelIndex& index, selectedIndexes) { const QVariant data = index.data(Qt::UserRole); const int col = index.column(); const int row = index.row(); if (!columns.contains(col)) columns.insert(col); if (!rows.contains(row)) rows.insert(row); if (data.type() < 7) // is numeric or boolean { if (numbersQuoteChar != '\0') snapshot[qMakePair(row,col)] = numbersQuoteChar + data.toString() + numbersQuoteChar; else snapshot[qMakePair(row,col)] = data.toString(); } else { if (stringsQuoteChar != '\0') snapshot[qMakePair(row,col)] = stringsQuoteChar + data.toString() + stringsQuoteChar; else snapshot[qMakePair(row,col)] = data.toString(); } } if (opt.testFlag(ExportColumnNames)) { if (opt.testFlag(ExportLineNumbers)) stream << fixedFieldDelimiter; QSetIterator<int> j(columns); while (j.hasNext()) { const QVariant data = m_model->headerData(j.next(), Qt::Horizontal); if (stringsQuoteChar != '\0') stream << stringsQuoteChar + data.toString() + stringsQuoteChar; else stream << data.toString(); if (j.hasNext()) stream << fixedFieldDelimiter; } stream << "\n"; } foreach(const int row, rows) { if (opt.testFlag(ExportLineNumbers)) stream << row + 1 << fixedFieldDelimiter; QSetIterator<int> j(columns); while (j.hasNext()) { stream << snapshot.value(qMakePair(row,j.next())); if (j.hasNext()) stream << fixedFieldDelimiter; } stream << "\n"; } kDebug() << "Export in" << t.elapsed() << "msecs"; }
void EclipsesBrowserDialog::updateButtonStates() { QItemSelectionModel *s = m_browserWidget->treeView->selectionModel(); m_browserWidget->buttonShow->setEnabled( s->hasSelection() ); }