void Matrix::deleteSelectedColumns() { QItemSelectionModel *selModel = d_table_view->selectionModel(); if (!selModel || !selModel->hasSelection()) return; int startCol = -1; int count = 0; int cols = numCols(); for (int i=0; i<cols; i++){ if (selModel->isColumnSelected(i, QModelIndex())){ if (startCol < 0) startCol = i; ++count; } } if (startCol < 0 || !count) return; double *buffer = d_matrix_model->dataCopy(0, numRows() - 1, startCol, startCol + count - 1); if (buffer){ d_undo_stack->push(new MatrixDeleteColsCommand(d_matrix_model, startCol, count, buffer, tr("Delete Columns") + " " + QString::number(startCol + 1) + " - " + QString::number(startCol + count))); emit modifiedWindow(this); modifiedData(this); } else if (ignoreUndo()){ d_matrix_model->removeColumns(startCol, count); d_table_view->reset(); emit modifiedWindow(this); modifiedData(this); } }
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 Matrix::importImage(const QString& fn) { QImage image(fn); if (image.isNull()) return; x_start = 0.0; x_end = image.width() - 1.0; y_start = 0.0; y_end = image.height() - 1.0; double *buffer = d_matrix_model->dataCopy(); if (buffer){ d_undo_stack->push(new MatrixSetImageCommand(d_matrix_model, image, d_view_type, 0, numRows() - 1, 0, numCols() - 1, buffer, tr("Import Image") + " \"" + fn + "\"")); emit modifiedWindow(this); modifiedData(this); } else if (ignoreUndo()){ d_matrix_model->setImage(image); setViewType(ImageView, false); displayImage(image); emit modifiedWindow(this); modifiedData(this); } setWindowLabel(fn); }
void Matrix::fft(bool inverse) { double *buffer = d_matrix_model->dataCopy(); if (buffer){ QString commandText = inverse ? tr("Inverse FFT") : tr("Forward FFT"); d_undo_stack->push(new MatrixFftCommand(inverse, d_matrix_model, 0, numRows() - 1, 0, numCols() - 1, buffer, commandText)); emit modifiedWindow(this); modifiedData(this); } else if (ignoreUndo()){ d_matrix_model->fft(inverse); emit modifiedWindow(this); modifiedData(this); } }
bool Matrix::muParserCalculate(int startRow, int endRow, int startCol, int endCol) { double *buffer = d_matrix_model->dataCopy(startRow, endRow, startCol, endCol); if (buffer){ d_undo_stack->push(new MatrixUndoCommand(d_matrix_model, MuParserCalculate, startRow, endRow, startCol, endCol, buffer, tr("Calculate Values"))); emit modifiedWindow(this); modifiedData(this); return true; } else if(ignoreUndo()){ d_matrix_model->muParserCalculate(startRow, endRow, startCol, endCol); emit modifiedWindow(this); modifiedData(this); return true; } return false; }
void Matrix::importImage(const QImage& image) { if (image.isNull()) return; double *buffer = d_matrix_model->dataCopy(); if (buffer){ d_undo_stack->push(new MatrixSetImageCommand(d_matrix_model, image, d_view_type, 0, numRows() - 1, 0, numCols() - 1, buffer, tr("Import Image"))); emit modifiedWindow(this); modifiedData(this); } else if (ignoreUndo()){ d_matrix_model->setImage(image); setViewType(ImageView, false); displayImage(image); emit modifiedWindow(this); modifiedData(this); } }
bool Matrix::calculate(int startRow, int endRow, int startCol, int endCol, bool forceMuParser) { if (QString(scriptEnv->name()) == "muParser" || forceMuParser) return muParserCalculate(startRow, endRow, startCol, endCol); double *buffer = d_matrix_model->dataCopy(startRow, endRow, startCol, endCol); if (buffer){ d_undo_stack->push(new MatrixUndoCommand(d_matrix_model, Calculate, startRow, endRow, startCol, endCol, buffer, tr("Calculate Values"))); emit modifiedWindow(this); modifiedData(this); return true; } else if(ignoreUndo()){ d_matrix_model->calculate(startRow, endRow, startCol, endCol); emit modifiedWindow(this); modifiedData(this); return true; } return false; }
void Matrix::setCoordinates(double xs, double xe, double ys, double ye) { if (x_start == xs && x_end == xe && y_start == ys && y_end == ye) return; x_start = xs; x_end = xe; y_start = ys; y_end = ye; emit modifiedWindow(this); modifiedData(this); }
void TestIsEqual(mitk::VectorProperty<T> &prop) { std::vector<T> data = MakeSimpleList<T>(); prop.SetValue(data); std::vector<T> modifiedData(data); modifiedData.back() = -modifiedData.back(); // change last element typename mitk::VectorProperty<T>::Pointer modifiedProperty = mitk::VectorProperty<T>::New(); modifiedProperty->SetValue(modifiedData); CPPUNIT_ASSERT_ASSERTION_FAIL_MESSAGE("Modified list shall be recognized by IsEqual()", CPPUNIT_ASSERT_EQUAL(*modifiedProperty, prop)); modifiedData.pop_back(); // remove last element modifiedProperty->SetValue(modifiedData); CPPUNIT_ASSERT_ASSERTION_FAIL_MESSAGE("Removed element shall be recognized by IsEqual()", CPPUNIT_ASSERT_EQUAL(*modifiedProperty, prop)); }
void Matrix::insertColumn() { QItemSelectionModel *selModel = d_table_view->selectionModel(); if (!selModel || !selModel->hasSelection()) return; QModelIndex index = selModel->currentIndex(); if (!index.isValid()) return; if (!d_matrix_model->canResize(numRows(), numCols() + 1)) return; d_undo_stack->push(new MatrixInsertColCommand(d_matrix_model, index.column(), tr("Insert Column") + " " + QString::number(index.column() + 1))); d_table_view->reset(); emit modifiedWindow(this); modifiedData(this); }
void Matrix::setDimensions(int rows, int cols) { int r = numRows(); int c = numCols(); if (r == rows && c == cols) return; if(rows*cols > r*c && !d_matrix_model->canResize(rows, cols)) return; double *buffer = d_matrix_model->dataCopy(); if (buffer) d_undo_stack->push(new MatrixSetSizeCommand(d_matrix_model, QSize(r, c), QSize(rows, cols), buffer, tr("Set Dimensions") + " " + QString::number(rows) + "x" + QString::number(cols))); else if(ignoreUndo()){ d_matrix_model->setDimensions(rows, cols); resetView(); } emit modifiedWindow(this); modifiedData(this); }
void TableStatistics::update(Table *t, const QString& colName) { if (t != d_base) return; int j; if (d_type == row) for (unsigned r=0; r < d_targets.size(); r++) { int cols=d_base->tableCols(); int i = d_targets[r]; int m = 0; for (j = 0; j < cols; j++) if (!d_base->text(i, j).isEmpty() && d_base->columnType(j) == Numeric) m++; if (!m) {//clear row statistics for (j = 1; j<9; j++) setText(r, j, QString::null); } if (m > 0) { double *dat = new double[m]; gsl_vector *y = gsl_vector_alloc (m); int aux = 0; for (j = 0; j<cols; j++) { QString text = d_base->text(i,j); if (!text.isEmpty() && d_base->columnType(j) == Numeric) { double val = text.toDouble(); gsl_vector_set (y, aux, val); dat[aux] = val; aux++; } } double mean = gsl_stats_mean (dat, 1, m); double min, max; gsl_vector_minmax (y, &min, &max); setText(r, 1, QString::number(d_base->tableCols())); setText(r, 2, QString::number(mean)); setText(r, 3, QString::number(gsl_stats_sd(dat, 1, m))); setText(r, 4, QString::number(gsl_stats_variance(dat, 1, m))); setText(r, 5, QString::number(mean*m)); setText(r, 6, QString::number(max)); setText(r, 7, QString::number(min)); setText(r, 8, QString::number(m)); gsl_vector_free (y); delete[] dat; } } else if (d_type == column) for (unsigned c=0; c < d_targets.size(); c++) if (colName == QString(d_base->name())+"_"+text(c, 0)) { int i = d_base->colIndex(colName); if (d_base->columnType(i) != Numeric) return; int rows = d_base->tableRows(); int start = -1, m = 0; for (j=0; j<rows; j++) if (!d_base->text(j,i).isEmpty()) { m++; if (start<0) start=j; } if (!m) {//clear col statistics for (j = 1; j<11; j++) setText(c, j, QString::null); return; } if (start<0) return; double *dat = new double[m]; gsl_vector *y = gsl_vector_alloc (m); int aux = 0, min_index = start, max_index = start; double val = d_base->text(start, i).toDouble(); gsl_vector_set (y, 0, val); dat[0] = val; double min = val, max = val; for (j = start + 1; j<rows; j++) { if (!d_base->text(j, i).isEmpty()) { aux++; val = d_base->text(j, i).toDouble(); gsl_vector_set (y, aux, val); dat[aux] = val; if (val < min) { min = val; min_index = j; } if (val > max) { max = val; max_index = j; } } } double mean=gsl_stats_mean (dat, 1, m); setText(c, 1, "[1:"+QString::number(rows)+"]"); setText(c, 2, QString::number(mean)); setText(c, 3, QString::number(gsl_stats_sd(dat, 1, m))); setText(c, 4, QString::number(gsl_stats_variance(dat, 1, m))); setText(c, 5, QString::number(mean*m)); setText(c, 6, QString::number(max_index + 1)); setText(c, 7, QString::number(max)); setText(c, 8, QString::number(min_index + 1)); setText(c, 9, QString::number(min)); setText(c, 10, QString::number(m)); gsl_vector_free (y); delete[] dat; } for (int i=0; i<worksheet->numCols(); i++) emit modifiedData(this, Table::colName(i)); }
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::guessEndOfLine(text)); 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 = applicationWindow()->clipboardLocale(); 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); modifiedData(this); } else if (ignoreUndo()){ d_matrix_model->pasteData(clipboardBuffer, topRow, leftCol, rows, cols); emit modifiedWindow(this); modifiedData(this); } }