Example #1
0
/**  Copies the current selection in the active table view into the system
 * clipboard.
*/
void MantidMatrix::copySelection() {
  QItemSelectionModel *selModel = activeView()->selectionModel();
  QString s = "";
  QString eol = applicationWindow()->endOfLine();
  if (!selModel->hasSelection()) {
    QModelIndex index = selModel->currentIndex();
    s = text(index.row(), index.column());
  } else {
    QItemSelection sel = selModel->selection();
    QListIterator<QItemSelectionRange> it(sel);
    if (!it.hasNext())
      return;

    QItemSelectionRange cur = it.next();
    int top = cur.top();
    int bottom = cur.bottom();
    int left = cur.left();
    int right = cur.right();
    for (int i = top; i <= bottom; i++) {
      for (int j = left; j < right; j++)
        s += text(i, j) + "\t";
      s += text(i, right) + eol;
    }
  }
  // Copy text into the clipboard
  QApplication::clipboard()->setText(s.trimmed());
}
void MatrixValuesDialog::setMatrix(Matrix* m)
{
    if (!m)
        return;

	matrix = m;
	commands->setText(m->formula());
	commands->setContext(m);

    endCol->setValue(m->numCols());
    endRow->setValue(m->numRows());

    if (m->viewType() == Matrix::TableView){
        QItemSelectionModel *selModel = m->selectionModel();
        if (selModel->hasSelection()){
            QItemSelectionRange selection = selModel->selection().first();
            if (selection.width() > 1 || selection.height() > 1){
                startCol->setValue(selection.left()+1);
                startRow->setValue(selection.top()+1);
                endCol->setValue(selection.right()+1);
                endRow->setValue(selection.bottom()+1);
            }
        }
    }
}
void SelectionModelSynchronizer::syncedSelectionChanged(const QItemSelection &selected, const QItemSelection &deselected) {
  Q_UNUSED(selected);
  Q_UNUSED(deselected);

  if(!_changeSelectionEnabled)
    return;

  QItemSelectionModel *selectionModel = qobject_cast<QItemSelectionModel *>(sender());
  Q_ASSERT(selectionModel);

  QItemSelection mappedSelection = selectionModel->selection();
  QItemSelection currentSelectionMapped = mapSelectionFromSource(currentSelection(), selectionModel);

  QItemSelection checkSelection = currentSelectionMapped;
  checkSelection.merge(mappedSelection, QItemSelectionModel::Deselect);
  if(checkSelection.isEmpty()) {
    // that means the new selection contains the current selection (currentSel - newSel = {})
    checkSelection = mappedSelection;
    checkSelection.merge(currentSelectionMapped, QItemSelectionModel::Deselect);
    if(checkSelection.isEmpty()) {
      // that means the current selection contains the new selection (newSel - currentSel = {})
      // -> currentSel == newSel
      return;
    }
  }
  setCurrentSelection(mapSelectionToSource(mappedSelection, selectionModel));
}
Example #4
0
void Matrix::clearSelection()
{
    if (d_view_type == ImageView)
        return;

	QItemSelectionModel *selModel = d_table_view->selectionModel();
	if (!selModel || !selModel->hasSelection())
		return;

	const QItemSelectionRange sel = selModel->selection()[0];
	int startRow = sel.top();
	int endRow = sel.bottom();
	int startCol = sel.left();
	int endCol = sel.right();
	double *buffer = d_matrix_model->dataCopy(startRow, endRow, startCol, endCol);
	if (buffer){
    	d_undo_stack->push(new MatrixUndoCommand(d_matrix_model, Clear, startRow, endRow, startCol, endCol, buffer, tr("Clear Selection")));
    	emit modifiedWindow(this);
    	modifiedData(this);
	} else if (ignoreUndo()){
		d_matrix_model->clear(startRow, endRow, startCol, endCol);
		emit modifiedWindow(this);
		modifiedData(this);
	}
}
void BookmarkDialog::addAccepted()
{
    QItemSelectionModel *model = ui.treeView->selectionModel();
    const QModelIndexList &list = model->selection().indexes();

    QModelIndex index;
    if (!list.isEmpty())
        index = proxyModel->mapToSource(list.at(0));

    bookmarkManager->addNewBookmark(index, ui.bookmarkEdit->text(), m_url);
    accept();
}
Example #6
0
void DevicesWidget::updateDeviceViewActions()
{
    QItemSelectionModel *devSel = deviceGroupList->selectionModel();

    if (!portGroups_)
       return;

    // For some reason hasSelection() returns true even if selection size is 0
    // so additional check for size introduced
    if (devSel->hasSelection() && (devSel->selection().size() > 0)) {
        // If more than one non-contiguous ranges selected,
        // disable "New" and "Edit"
        if (devSel->selection().size() > 1) {
            actionNewDeviceGroup->setDisabled(true);
            actionEditDeviceGroup->setDisabled(true);
        }
        else {
            actionNewDeviceGroup->setEnabled(true);

            // Enable "Edit" only if the single range has a single row
            if (devSel->selection().at(0).height() > 1)
                actionEditDeviceGroup->setDisabled(true);
            else
                actionEditDeviceGroup->setEnabled(true);
        }

        // Delete is always enabled as long as we have a selection
        actionDeleteDeviceGroup->setEnabled(true);
    }
    else {
        qDebug("No device selection");
        if (portGroups_->isPort(currentPortIndex_))
            actionNewDeviceGroup->setEnabled(true);
        else
            actionNewDeviceGroup->setDisabled(true);
        actionEditDeviceGroup->setDisabled(true);
        actionDeleteDeviceGroup->setDisabled(true);
    }
}
Example #7
0
void DoubleList::on_m_pAddB_clicked()
{
    QItemSelectionModel* pSelMdl (m_pAvailableG->selectionModel());
    QModelIndexList lSel (pSelMdl->selection().indexes());

    set<int> sSelPos; // the rows must be sorted

    for (QModelIndexList::iterator it = lSel.begin(), end = lSel.end(); it != end; ++it)
    {
        int nRow (it->row());
        CB_ASSERT (nRow >= 0);
        sSelPos.insert(nRow);
    }

    add(sSelPos);
}
Example #8
0
void DoubleList::on_m_pDeleteB_clicked()
{
    if (m_listPainter.m_vSel.empty()) { return; }
    QItemSelectionModel* pSelMdl (m_pSelectedG->selectionModel());
    QModelIndexList lSel (pSelMdl->selection().indexes());

    set<int> sSelPos; // the rows must be sorted and the last must be processed first, so removal of elements doesn't change the row number for the remaining ones

    for (QModelIndexList::iterator it = lSel.begin(), end = lSel.end(); it != end; ++it)
    {
        int nRow (it->row());
        CB_ASSERT (nRow >= 0);
        sSelPos.insert(nRow);
    }

    remove(sSelPos);
}
Example #9
0
void FilesModel::fixSelection() // deselects cells that are selected but are on a different row from the "current" cell and selects the file name
{
    // it works OK when getFltHandlers() is empty
    QItemSelectionModel* pSelModel (m_pCommonData->m_pFilesG->selectionModel());
    QModelIndexList lstSel (pSelModel->selection().indexes());
    QModelIndex crt (m_pCommonData->m_pFilesG->selectionModel()->currentIndex());
    int nCrtRow (crt.row());
    int nCrtCol (crt.column());

    if (0 == nCrtCol)
    {
        for (QModelIndexList::iterator it = lstSel.begin(), end = lstSel.end(); it != end; ++it)
        {
            if (0 != it->column())
            {
                pSelModel->select(*it, QItemSelectionModel::Deselect);
            }
        }
    }
    else
    {
        set<int> sSelectableColumns;
        sSelectableColumns.insert(0);
        for (int i = 0, n = cSize(m_pCommonData->getCrtNotes()); i < n; ++i) // ttt2 poor performance
        {
            const Note* pNote (m_pCommonData->getCrtNotes()[i]);
            sSelectableColumns.insert(m_pCommonData->findPos(pNote) + 1);
        }

        for (QModelIndexList::iterator it = lstSel.begin(), end = lstSel.end(); it != end; ++it)
        {
            if ((it->row() != nCrtRow && 0 != it->column()) || 0 == sSelectableColumns.count(it->column()))
            {
                pSelModel->select(*it, QItemSelectionModel::Deselect);
            }
        }

        if (nCrtRow >= 0)
        {
            pSelModel->select(index(nCrtRow, 0), QItemSelectionModel::Select);
        }
    }
}
Example #10
0
/** Called when switching between tabs
*  @param index :: The index of the new active tab
*/
void MantidMatrix::viewChanged(int index) {
  // get the previous view and selection model
  QTableView *prevView = (QTableView *)m_tabs->widget(m_PrevIndex);
  if (prevView) {
    QItemSelectionModel *oldSelModel = prevView->selectionModel();
    QItemSelectionModel *selModel = activeView()->selectionModel();
    // Copy the selection from the previous tab into the newly-activated one
    selModel->select(oldSelModel->selection(), QItemSelectionModel::Select);
    // Clear the selection on the now-hidden tab
    oldSelModel->clearSelection();

    m_PrevIndex = index;
    // get the previous tab scrollbar positions
    int hValue = prevView->horizontalScrollBar()->value();
    int vValue = prevView->verticalScrollBar()->value();
    // to synchronize the views
    // set  the previous view  scrollbar positions to current view
    activeView()->horizontalScrollBar()->setValue(hValue);
    activeView()->verticalScrollBar()->setValue(vValue);
  }
}
void FolderManager::runCommand(const QString &name)
{
  qDebug() << "FolderManager::runCommand()" << name;

  FolderView *sourceView = currentFolderView(m_active_side);
  FolderView *targetView = currentFolderView((m_active_side == LeftSide) ? RightSide : LeftSide);

  if (! sourceView) {
    qDebug() << "no source view";
    return;
  }

  if (name == "parent") {
    QDir dir(sourceView->fileSystemModel()->rootPath());
    dir.cdUp();
    sourceView->navigateToPath(dir.absolutePath());
  }
  else if (name == "select-all") {
    sourceView->selectAll();
  }
  else if (name == "select-none") {
    sourceView->clearSelection();
  }
  else if (name == "invert-selection") {
    QItemSelectionModel *selectionModel  = sourceView->selectionModel();
    selectionModel->select(selectionModel->selection(), QItemSelectionModel::Toggle);

#if 0
    QAbstractItemModel  *model        = sourceView->model();
    QModelIndex          topLeft      = model->index(0, 0);
    QModelIndex          bottomRight  = model->index(model->rowCount(parent)-1,
                                                     model->columnCount(parent)-1);
    QItemSelection selection(topLeft, bottomRight);
    selectionModel->select(selection, QItemSelectionModel::Toggle);
#endif
  }
}
void BookmarkDialog::addNewFolder()
{
    QItemSelectionModel *model = ui.treeView->selectionModel();
    const QModelIndexList &list = model->selection().indexes();

    QModelIndex index;
    if (!list.isEmpty())
        index = list.at(0);

    QModelIndex newFolder =
        bookmarkManager->addNewFolder(proxyModel->mapToSource(index));
    if (newFolder.isValid()) {
        ui.treeView->expand(index);
        const QModelIndex &index = proxyModel->mapFromSource(newFolder);
        model->setCurrentIndex(index, QItemSelectionModel::ClearAndSelect);

        ui.bookmarkFolders->clear();
        ui.bookmarkFolders->addItems(bookmarkManager->bookmarkFolders());

        const QString &name = index.data().toString();
        ui.bookmarkFolders->setCurrentIndex(ui.bookmarkFolders->findText(name));
    }
    ui.treeView->setFocus();
}
Example #13
0
void FilesModel::matchSelToNotes()
{
    QItemSelectionModel* pNotesSelModel (m_pCommonData->m_pNotesG->selectionModel());
    QModelIndexList notesLstSel (pNotesSelModel->selection().indexes());

    set<int> sSel;
    for (QModelIndexList::iterator it = notesLstSel.begin(), end = notesLstSel.end(); it != end; ++it)
    {
//cout << "cell sel at " << it->row() << "x" << it->column() << endl;
        const Note* pNote (m_pCommonData->getCrtNotes()[it->row()]);
        int nPos (m_pCommonData->findPos(pNote));
        sSel.insert(nPos);
    }

    m_pCommonData->m_pFilesG->selectionModel()->clearSelection();

    for (set<int>::const_iterator it = sSel.begin(), end = sSel.end(); it != end; ++it)
    {
        m_pCommonData->m_pFilesG->selectionModel()->select(index(m_pCommonData->getFilesGCrtRow(), *it + 1), QItemSelectionModel::Select);
//cout << "selecting " << m_pCommonData->getFilesGCrtRow() << "x" << *it + 1 << endl;
    }

    m_pCommonData->m_pFilesG->selectionModel()->select(index(m_pCommonData->getFilesGCrtRow(), 0), QItemSelectionModel::Select);
}
Example #14
0
void HistoryForm::onTick01()
{
    if (this->CurrentEdit == nullptr)
        throw new Huggle::NullPointerException("local WikiEdit CurrentEdit", BOOST_CURRENT_FUNCTION);

    if (this->RetrievingEdit && this->RetrievedEdit != nullptr)
    {
        if (this->RetrievedEdit->IsPostProcessed())
        {
            MainWindow::HuggleMain->ProcessEdit(this->RetrievedEdit, false, true);
            this->RetrievingEdit = false;
            this->RetrievedEdit = nullptr;
            this->t1->stop();
            this->MakeSelectedRowBold();
            MainWindow::HuggleMain->wEditBar->RefreshPage();
        }
        return;
    }

    if (this->query == nullptr || !this->query->IsProcessed())
        return;

    if (this->query->IsFailed())
    {
        this->ui->pushButton->setEnabled(true);
        Huggle::Syslog::HuggleLogs->ErrorLog(_l("history-failure"));
        this->query = nullptr;
        this->t1->stop();
        return;
    }
    bool IsLatest = false;
    QList<ApiQueryResultNode*> revision_data = this->query->GetApiQueryResult()->GetNodes("rev");
    int x = 0;
    while (x < revision_data.count())
    {
        ApiQueryResultNode *rv = revision_data.at(x);
        WikiPageHistoryItem *item = new WikiPageHistoryItem(this->query->GetSite());
        if (rv->Attributes.contains("revid"))
        {
            item->RevID = rv->GetAttribute("revid");
        }
        else
        {
            x++;
            continue;
        }
        bool founder = false;
        item->Name = this->CurrentEdit->Page->PageName;
        item->Site = this->CurrentEdit->GetSite();
        if (rv->Attributes.contains("user"))
            item->User = rv->GetAttribute("user");
        if (rv->Attributes.contains("size"))
            item->Size = rv->GetAttribute("size");
        if (rv->Attributes.contains("timestamp"))
            item->Date = rv->GetAttribute("timestamp");
        if (rv->Attributes.contains("comment") && !rv->GetAttribute("comment").isEmpty())
            item->Summary = rv->GetAttribute("comment");
        this->ui->tableWidget->insertRow(x);
        QIcon icon(":/huggle/pictures/Resources/blob-none.png");
        if (this->CurrentEdit->Page->FounderKnown() && WikiUser::CompareUsernames(item->User, this->CurrentEdit->Page->GetFounder()))
            founder = true;
        if (WikiUtil::IsRevert(item->Summary))
        {
            item->Type = EditType_Revert;
            icon = QIcon(":/huggle/pictures/Resources/blob-revert.png");
        }
        else if (WikiUser::IsIPv6(item->User) || WikiUser::IsIPv4(item->User))
        {
            item->Type = EditType_Anon;
            icon = QIcon(":/huggle/pictures/Resources/blob-anon.png");
        }
        else if (this->CurrentEdit->GetSite()->GetProjectConfig()->WhiteList.contains(item->User))
        {
            item->Type = EditType_W;
            icon = QIcon(":/huggle/pictures/Resources/blob-ignored.png");
        }
        WikiUser *wu = WikiUser::RetrieveUser(item->User, item->Site);
        if (wu != nullptr)
        {
            if (wu->IsReported)
            {
                item->Type = EditType_Reported;
                icon = QIcon(":/huggle/pictures/Resources/blob-reported.png");
            }
            else if (wu->GetWarningLevel() > 0)
            {
                switch (wu->GetWarningLevel())
                {
                case 1:
                    item->Type = EditType_1;
                    icon = QIcon(":/huggle/pictures/Resources/blob-warn-1.png");
                    break;
                case 2:
                    item->Type = EditType_2;
                    icon = QIcon(":/huggle/pictures/Resources/blob-warn-2.png");
                    break;
                case 3:
                    item->Type = EditType_3;
                    icon = QIcon(":/huggle/pictures/Resources/blob-warn-3.png");
                    break;
                case 4:
                    item->Type = EditType_4;
                    icon = QIcon(":/huggle/pictures/Resources/blob-warn-4.png");
                    break;
                }
            }
        }
        bool selected = this->CurrentEdit->RevID == item->RevID.toInt();
        if (selected && x == 0)
            IsLatest = true;
        item->IsCurrent = true;
        if (selected)
            this->SelectedRow = x;
        QFont font;
        font.setItalic(founder);
        font.setBold(selected);
        QTableWidgetItem *i = new QTableWidgetItem(icon, "");
        this->ui->tableWidget->setItem(x, 0, i);
        i = new QTableWidgetItem(item->User);
        i->setFont(font);
        this->ui->tableWidget->setItem(x, 1, i);
        i = new QTableWidgetItem(item->Size);
        i->setFont(font);
        this->ui->tableWidget->setItem(x, 2, i);
        i = new QTableWidgetItem(item->Summary);
        i->setFont(font);
        this->ui->tableWidget->setItem(x, 3, i);
        i = new QTableWidgetItem(item->Date);
        i->setFont(font);
        this->ui->tableWidget->setItem(x, 4, i);
        i = new QTableWidgetItem(item->RevID);
        i->setFont(font);
        this->ui->tableWidget->setItem(x, 5, i);
        this->Items.append(item);
        x++;
    }
    this->ui->tableWidget->resizeRowsToContents();
    this->query = nullptr;
    this->t1->stop();
    if (!this->CurrentEdit->NewPage && !Configuration::HuggleConfiguration->ForceNoEditJump && !IsLatest)
    {
        if (Configuration::HuggleConfiguration->UserConfig->LastEdit)
        {
            this->Display(0, Resources::Html_StopFire, true);
            return;
        }
        else
        {
            QPoint pntr(0, this->pos().y());
            if (this->pos().x() > 400)
                pntr.setX(this->pos().x() - 200);
            else
                pntr.setX(this->pos().x() + 100);

            if (hcfg->UserConfig->ShowWarningIfNotOnLastRevision)
                QToolTip::showText(pntr, "<b><big>" + _l("historyform-not-latest-tip") + "</big></b>", this);
        }
    }
    if (hcfg->UserConfig->AutomaticallyGroup)
    {
        // Check if edits made around of this one weren't made by same user
        // in case they were we need to display a range of them
        QString user = this->CurrentEdit->User->Username;
        int RangeStart = this->SelectedRow;
        int RangeEnd = this->SelectedRow;
        int row = this->SelectedRow;
        while (row > 0)
        {
            if (user != this->ui->tableWidget->item(row - 1, 1)->text())
                break;
            row--;
        }
        RangeStart = row;
        row = this->SelectedRow;
        while (row < (this->ui->tableWidget->rowCount() - 1))
        {
            if (user != this->ui->tableWidget->item(row + 1, 1)->text())
                break;
            row++;
        }
        RangeEnd = row;
        if (RangeStart != RangeEnd)
        {
            QItemSelectionModel *selectionModel = this->ui->tableWidget->selectionModel();
            row = RangeStart;
            this->IgnoreSelectionChanges = true;
            this->ui->tableWidget->clearSelection();
            QItemSelection itemSelection = selectionModel->selection();
            while (row <= RangeEnd)
            {
                this->ui->tableWidget->selectRow(row++);
                itemSelection.merge(selectionModel->selection(), QItemSelectionModel::Select);
            }
            selectionModel->clearSelection();
            this->IgnoreSelectionChanges = false;
            selectionModel->select(itemSelection, QItemSelectionModel::Select);
        }
    }
    this->IgnoreSelectionChanges = false;
    MainWindow::HuggleMain->wEditBar->RefreshPage();
}
Example #15
0
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);
	}
}