scidavis  2.3.0
About: SciDAVis is a free application for Scientific Data Analysis and Visualization (a fork off of QtiPlot).
  Fossies Dox: scidavis-2.3.0.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

Matrix.cpp
Go to the documentation of this file.
1 
13 
31 #include "Matrix.h"
33 #include "ScriptEdit.h"
34 
35 #include <QtGlobal>
36 #include <QTextStream>
37 #include <QList>
38 #include <QEvent>
39 #include <QContextMenuEvent>
40 #include <QVBoxLayout>
41 #include <QMouseEvent>
42 #include <QHeaderView>
43 #include <QDateTime>
44 #include <QApplication>
45 #include <QMessageBox>
46 #include <QVarLengthArray>
47 #include <QClipboard>
48 #include <QShortcut>
49 #include <QPrinter>
50 #include <QPrintDialog>
51 #include <QPainter>
52 #include <QLocale>
53 #include <QXmlStreamWriter>
54 #include <QtDebug>
55 
56 #include <stdlib.h>
57 #include <math.h>
58 #include <stdio.h>
59 
60 #include <gsl/gsl_linalg.h>
61 #include <gsl/gsl_math.h>
62 
63 Matrix::Matrix(ScriptingEnv *env, int r, int c, const QString& label, QWidget* parent, const char* name, Qt::WindowFlags f)
64  : MatrixView(label, parent, name, f), scripted(env)
65 {
66  d_future_matrix = new future::Matrix(0, r, c, label);
67  init(r, c);
68 }
69 
70 Matrix::Matrix(future::Matrix *future_matrix, ScriptingEnv *env, int r, int c, const QString& label, QWidget* parent, const char* name, Qt::WindowFlags f)
71  : MatrixView(label, parent, name, f), scripted(env)
72 {
73  d_future_matrix = future_matrix;
74  init(r, c);
75 }
76 
77 void Matrix::init(int, int)
78 {
79  MatrixView::setMatrix(d_future_matrix);
80  d_future_matrix->setView(this);
83  d_future_matrix->setCoordinates(1.0, 10.0, 1.0, 10.0);
84  dMatrix = 0;
85 
86  birthdate = d_future_matrix->creationTime().toString(Qt::LocalDate);
87 
88  // this is not very nice but works for the moment
89  ui.gridLayout2->removeWidget(ui.formula_box);
90  delete ui.formula_box;
91  ui.formula_box = new ScriptEdit(scriptEnv, ui.formula_tab);
92  ui.formula_box->setObjectName(QString::fromUtf8("formula_box"));
93  ui.formula_box->setMinimumSize(QSize(60, 10));
94  ui.formula_box->setAcceptRichText(false);
95  ui.formula_box->setLineWrapMode(QTextEdit::WidgetWidth);
96  ui.gridLayout2->addWidget(ui.formula_box, 1, 0, 1, 3);
97 
98  ui.add_cell_combobox->addItem("cell(i, j)");
99  ui.add_function_combobox->addItems(scriptEnv->mathFunctions());
101 
102  connect(ui.add_function_combobox, SIGNAL(currentIndexChanged(int)),
103  this, SLOT(updateFunctionDoc()));
104  connect(ui.button_set_formula, SIGNAL(pressed()),
105  this, SLOT(applyFormula()));
106  connect(ui.add_function_button, SIGNAL(pressed()),
107  this, SLOT(addFunction()));
108  connect(ui.add_cell_button, SIGNAL(pressed()),
109  this, SLOT(addCell()));
110 
111  connect(d_future_matrix, SIGNAL(columnsInserted(int, int)), this, SLOT(handleChange()));
112  connect(d_future_matrix, SIGNAL(columnsRemoved(int, int)), this, SLOT(handleChange()));
113  connect(d_future_matrix, SIGNAL(rowsInserted(int, int)), this, SLOT(handleChange()));
114  connect(d_future_matrix, SIGNAL(rowsRemoved(int, int)), this, SLOT(handleChange()));
115  connect(d_future_matrix, SIGNAL(dataChanged(int, int, int, int)), this, SLOT(handleChange()));
116  connect(d_future_matrix, SIGNAL(coordinatesChanged()), this, SLOT(handleChange()));
117  connect(d_future_matrix, SIGNAL(formulaChanged()), this, SLOT(handleChange()));
118  connect(d_future_matrix, SIGNAL(formatChanged()), this, SLOT(handleChange()));
119  connect(d_future_matrix, SIGNAL(recalculate()), this, SLOT(recalculate()));
120 
121  connect(d_future_matrix, SIGNAL(aspectDescriptionChanged(const AbstractAspect*)),
122  this, SLOT(handleAspectDescriptionChange(const AbstractAspect *)));
123 }
124 
126 {
127 }
128 
130 {
131  emit modifiedWindow(this);
132 }
133 
134 double Matrix::cell(int row, int col)
135 {
136  if(dMatrix)
137  return dMatrix[row][col];
138  else
139  return d_future_matrix->cell(row, col);
140 }
141 
142 void Matrix::setCell(int row, int col, double value)
143 {
144  d_future_matrix->setCell(row, col, value);
145 }
146 
147 void Matrix::setCells(const QVector<qreal> & data)
148 {
150 }
151 
152 QString Matrix::text(int row, int col)
153 {
154  return d_future_matrix->text(row, col);
155 }
156 
157 void Matrix::setText(int row, int col, const QString & new_text )
158 {
159  bool ok = true;
160  QLocale locale;
161  double res = locale.toDouble(new_text, &ok);
162  if (ok)
163  d_future_matrix->setCell(row, col, res);
164  else
165  {
166  Script *script = scriptEnv->newScript(new_text, this, QString("<%1_%2_%3>").arg(name()).arg(row).arg(col));
167  connect(script, SIGNAL(error(const QString&,const QString&,int)), scriptEnv, SIGNAL(error(const QString&,const QString&,int)));
168 
169  script->setInt(row+1, "row");
170  script->setInt(row+1, "i");
171  script->setInt(col+1, "col");
172  script->setInt(col+1, "j");
173 
174  QVariant ret = script->eval();
175  setCell(row, col, ret.toDouble());
176  }
177 }
178 
179 void Matrix::setCoordinates(double xs, double xe, double ys, double ye)
180 {
181  d_future_matrix->setCoordinates(xs, xe, ys, ye);
182 }
183 
184 QString Matrix::saveToString(const QString &geometry)
185 {
186  QString s = "<matrix>\n";
187  QString xml;
188  QXmlStreamWriter writer(&xml);
189  d_future_matrix->save(&writer);
190  s += QString::number(xml.length()) + "\n"; // this is need in case there are newlines in the XML
191  s += xml + "\n";
192  s += geometry + "\n";
193  s +="</matrix>\n";
194  return s;
195 
196 #if 0
197  QString s = "<matrix>\n";
198  s += QString(name()) + "\t";
199  s += QString::number(numRows())+"\t";
200  s += QString::number(numCols())+"\t";
201  s += birthDate() + "\n";
202  s += info;
203  s += "ColWidth\t" + QString::number(columnWidth(0))+"\n";
204  s += "<formula>\n" + formula() + "\n</formula>\n";
205  s += "TextFormat\t" + QString(d_future_matrix->numericFormat()) + "\t" + QString::number(d_future_matrix->displayedDigits()) + "\n";
206  s += "WindowLabel\t" + windowLabel() + "\t" + QString::number(captionPolicy()) + "\n";
207  s += "Coordinates\t" + QString::number(xStart(),'g',15) + "\t" +QString::number(xEnd(),'g',15) + "\t";
208  s += QString::number(yStart(),'g',15) + "\t" + QString::number(yEnd(),'g',15) + "\n";
209  s += saveText();
210  s +="</matrix>\n";
211  return s;
212 #endif
213 }
214 
215 QString Matrix::saveAsTemplate(const QString &info)
216 {
217  QString s= "<matrix>\t";
218  s+= QString::number(numRows())+"\t";
219  s+= QString::number(numCols())+"\n";
220  s+= info;
221  s+= "ColWidth\t" + QString::number(columnWidth(0))+"\n";
222  s+= "<formula>\n" + formula() + "\n</formula>\n";
223  s+= "TextFormat\t" + QString(d_future_matrix->numericFormat()) + "\t" + QString::number(d_future_matrix->displayedDigits()) + "\n";
224  s+= "Coordinates\t" + QString::number(xStart(),'g',15) + "\t" +QString::number(xEnd(),'g',15) + "\t";
225  s+= QString::number(yStart(),'g',15) + "\t" + QString::number(yEnd(),'g',15) + "\n";
226  s +="</matrix>\n";
227  return s;
228 }
229 
231 {
232  QString out_text = "<data>\n";
233  int cols = d_future_matrix->columnCount();
234  for(int i=0; i<d_future_matrix->rowCount(); i++)
235  {
236  out_text += QString::number(i)+"\t";
237  for (int j=0; j<cols-1; j++)
238  out_text += QString::number(cell(i,j), 'e', 16)+"\t";
239 
240  out_text += QString::number(cell(i,cols-1), 'e', 16)+"\n";
241  }
242  return out_text + "</data>\n";
243 }
244 
245 void Matrix::setFormula(const QString &s)
246 {
248 }
249 
251 {
252  return d_future_matrix->formula();
253 }
254 
255 void Matrix::setNumericFormat(const QChar& f, int prec)
256 {
258  return;
259 
260  d_future_matrix->setNumericFormat(f.toLatin1());
262 
263  emit modifiedWindow(this);
264 }
265 
266 void Matrix::setTextFormat(const QChar &format, int precision)
267 {
268  d_future_matrix->setNumericFormat(format.toLatin1());
270 }
271 
272 void Matrix::setColumnsWidth(int width)
273 {
274  for(int i=0; i<d_future_matrix->columnCount(); i++)
275  setColumnWidth(i, width);
276 }
277 
278 void Matrix::setDimensions(int rows, int cols)
279 {
280  d_future_matrix->setDimensions(rows, cols);
281 }
282 
284 {
285  return d_future_matrix->rowCount();
286 }
287 
288 void Matrix::setNumRows(int rows)
289 {
291 }
292 
294 {
295  return d_future_matrix->columnCount();
296 }
297 
298 void Matrix::setNumCols(int cols)
299 {
301 }
302 
304 {
305  int rows = numRows();
306  int cols = numCols();
307 
308  if (rows != cols){
309  QMessageBox::critical(0,tr("Error"),
310  tr("Calculation failed, the matrix is not square!"));
311  return GSL_POSINF;
312  }
313 
314  QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
315 
316  gsl_matrix *A = gsl_matrix_alloc(rows, cols);
317  int i;
318  for(i=0; i<rows; i++)
319  for(int j=0; j<cols; j++)
320  gsl_matrix_set(A, i, j, cell(i, j));
321 
322  gsl_permutation * p = gsl_permutation_alloc(rows);
323  gsl_linalg_LU_decomp(A, p, &i);
324 
325  double det = gsl_linalg_LU_det(A, i);
326 
327  gsl_matrix_free(A);
328  gsl_permutation_free(p);
329 
330  QApplication::restoreOverrideCursor();
331  return det;
332 }
333 
335 {
336  int rows = numRows();
337  int cols = numCols();
338 
339  if (rows != cols){
340  QMessageBox::critical(0,tr("Error"),
341  tr("Inversion failed, the matrix is not square!"));
342  return;
343  }
344 
345  QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
346 
347  gsl_matrix *A = gsl_matrix_alloc(rows, cols);
348  int i;
349  for(i=0; i<rows; i++){
350  for(int j=0; j<cols; j++)
351  gsl_matrix_set(A, i, j, cell(i, j));
352  }
353 
354  gsl_permutation * p = gsl_permutation_alloc(cols);
355  gsl_linalg_LU_decomp(A, p, &i);
356 
357  gsl_matrix *inverse = gsl_matrix_alloc(rows, cols);
358  gsl_linalg_LU_invert(A, p, inverse);
359 
360  gsl_matrix_free(A);
361  gsl_permutation_free(p);
362 
363  this->blockSignals(true);
364  for(i=0; i<rows; i++){
365  for(int j=0; j<cols; j++)
366  setCell(i, j, gsl_matrix_get(inverse, i, j));
367  }
368  this->blockSignals(false);
369 
370  gsl_matrix_free(inverse);
371  QApplication::restoreOverrideCursor();
372  emit modifiedWindow(this);
373 }
374 
376 {
378 }
379 
381 {
382  int rows = numRows();
383  int cols = numCols();
384  dMatrix = allocateMatrixData(rows, cols);
385  for (int i=0; i<rows; i++)
386  for (int j=0; j<cols; j++)
387  dMatrix[i][j] = d_future_matrix->cell(i, j);
388 }
389 
391 {
393  dMatrix = 0;
394 }
395 
397 {
398  QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
399  Script *script = scriptEnv->newScript(formula(), this, QString("<%1>").arg(name()));
400  connect(script, SIGNAL(error(const QString&,const QString&,int)), scriptEnv, SIGNAL(error(const QString&,const QString&,int)));
401  connect(script, SIGNAL(print(const QString&)), scriptEnv, SIGNAL(print(const QString&)));
402  if (!script->compile())
403  {
404  QApplication::restoreOverrideCursor();
405  return false;
406  }
407 
408  this->blockSignals(true);
409 
410  int startRow = firstSelectedRow(false);
411  int endRow = lastSelectedRow(false);
412  int startCol = firstSelectedColumn(false);
413  int endCol = lastSelectedColumn(false);
414 
415  QVariant ret;
417  double dx = fabs(xEnd()-xStart())/(double)(numRows()-1);
418  double dy = fabs(yEnd()-yStart())/(double)(numCols()-1);
419  for(int row = startRow; row <= endRow; row++)
420  for(int col = startCol; col <= endCol; col++)
421  {
422  if (!isCellSelected(row, col)) continue;
423  script->setInt(row+1, "i");
424  script->setInt(row+1, "row");
425  script->setDouble(yStart()+row*dy, "y");
426  script->setInt(col+1, "j");
427  script->setInt(col+1, "col");
428  script->setDouble(xStart()+col*dx, "x");
429  ret = script->eval();
430  if (!ret.isValid()) {
432  blockSignals(false);
433  emit modifiedWindow(this);
434  QApplication::restoreOverrideCursor();
435  return false;
436  }
437  setCell(row, col, ret.toDouble());
438  }
440 
441  blockSignals(false);
442  emit modifiedWindow(this);
443  QApplication::restoreOverrideCursor();
444  return true;
445 }
446 
448 {
450 }
451 
453 {
455 }
456 
458 {
459  copySelection();
460  clearSelection();
461 }
462 
464 {
465  for(int i=0; i<numRows(); i++)
466  {
467  if (this->isRowSelected (i, true))
468  return true;
469  }
470  return false;
471 }
472 
474 {
476 }
477 
479 {
481 }
482 
484 {
485  for(int i=0; i<numCols(); i++)
486  {
487  if (this->isColumnSelected (i, true))
488  return true;
489  }
490  return false;
491 }
492 
494 {
496 }
497 
499 {
500  int r=0;
501  for(int i=0; i<numRows(); i++)
502  if (this->isRowSelected(i, true))
503  r++;
504  return r;
505 }
506 
508 {
509  int c=0;
510  for(int i=0; i<numCols(); i++)
511  if (this->isColumnSelected(i, true))
512  c++;
513  return c;
514 }
515 
517 {
519 }
520 
522 {
524 }
525 
526 void Matrix::customEvent(QEvent *e)
527 {
528  if (e->type() == SCRIPTING_CHANGE_EVENT)
530 }
531 
532 void Matrix::closeEvent( QCloseEvent *e )
533 {
534  if (askOnClose)
535  {
536  switch( QMessageBox::information(this,tr("SciDAVis"),
537  tr("Do you want to hide or delete") + "<p><b>'" + objectName() + "'</b> ?",
538  tr("Delete"), tr("Hide"), tr("Cancel"), 0,2))
539  {
540  case 0:
541  e->accept();
543  return;
544 
545  case 1:
546  e->ignore();
547  emit hiddenWindow(this);
548  break;
549 
550  case 2:
551  e->ignore();
552  break;
553  }
554  }
555  else
556  {
557  e->accept();
559  return;
560  }
561 }
562 
563 void Matrix::exportPDF(const QString& fileName)
564 {
565  print(fileName);
566 }
567 
569 {
570  print(QString());
571 }
572 
573 void Matrix::print(const QString& fileName)
574 {
575  QPrinter printer;
576  printer.setColorMode(QPrinter::GrayScale);
577 
578  if (!fileName.isEmpty())
579  {
580  printer.setCreator("SciDAVis");
581  printer.setOutputFormat(QPrinter::PdfFormat);
582  printer.setOutputFileName(fileName);
583  }
584  else
585  {
586  QPrintDialog printDialog(&printer);
587  if (printDialog.exec() != QDialog::Accepted)
588  return;
589  }
590 
591  printer.setFullPage( true );
592  QPainter p;
593  if ( !p.begin(&printer) )
594  return; // paint on printer
595  int dpiy = printer.logicalDpiY();
596  const int margin = (int) ( (1/2.54)*dpiy ); // 1 cm margins
597 
598  QHeaderView *vHeader = d_view_widget->verticalHeader();
599 
600  int rows = numRows();
601  int cols = numCols();
602  int height = margin;
603  int i, vertHeaderWidth = vHeader->width();
604  int right = margin + vertHeaderWidth;
605 
606  // print header
607  p.setFont(QFont());
608  QString header_label = d_view_widget->model()->headerData(0, Qt::Horizontal).toString();
609  QRect br = p.boundingRect(br, Qt::AlignCenter, header_label);
610  p.drawLine(right, height, right, height+br.height());
611  QRect tr(br);
612 
613  for(i=0;i<cols;i++)
614  {
615  int w = columnWidth(i);
616  tr.setTopLeft(QPoint(right,height));
617  tr.setWidth(w);
618  tr.setHeight(br.height());
619  header_label = d_view_widget->model()->headerData(i, Qt::Horizontal).toString();
620  p.drawText(tr, Qt::AlignCenter, header_label);
621  right += w;
622  p.drawLine(right, height, right, height+tr.height());
623 
624  if (right >= printer.width()-2*margin )
625  break;
626  }
627 
628  p.drawLine(margin + vertHeaderWidth, height, right-1, height);//first horizontal line
629  height += tr.height();
630  p.drawLine(margin, height, right-1, height);
631 
632  // print table values
633  for(i=0;i<rows;i++)
634  {
635  right = margin;
636  QString cell_text = d_view_widget->model()->headerData(i, Qt::Vertical).toString()+"\t";
637  tr = p.boundingRect(tr, Qt::AlignCenter, cell_text);
638  p.drawLine(right, height, right, height+tr.height());
639 
640  br.setTopLeft(QPoint(right,height));
641  br.setWidth(vertHeaderWidth);
642  br.setHeight(tr.height());
643  p.drawText(br,Qt::AlignCenter,cell_text);
644  right += vertHeaderWidth;
645  p.drawLine(right, height, right, height+tr.height());
646 
647  for(int j=0;j<cols;j++)
648  {
649  int w = columnWidth (j);
650  cell_text = text(i,j)+"\t";
651  tr = p.boundingRect(tr,Qt::AlignCenter,cell_text);
652  br.setTopLeft(QPoint(right,height));
653  br.setWidth(w);
654  br.setHeight(tr.height());
655  p.drawText(br, Qt::AlignCenter, cell_text);
656  right += w;
657  p.drawLine(right, height, right, height+tr.height());
658 
659  if (right >= printer.width()-2*margin )
660  break;
661  }
662  height += br.height();
663  p.drawLine(margin, height, right-1, height);
664 
665  if (height >= printer.height()-margin )
666  {
667  printer.newPage();
668  height = margin;
669  p.drawLine(margin, height, right, height);
670  }
671  }
672 }
673 
674 void Matrix::range(double *min, double *max)
675 {
676  double d_min = cell(0, 0);
677  double d_max = d_min;
678 
679  for(int i=0; i<numRows(); i++)
680  {
681  for(int j=0; j<numCols(); j++)
682  {
683  double aux = cell(i, j);
684  if (aux <= d_min)
685  d_min = aux;
686 
687  if (aux >= d_max)
688  d_max = aux;
689  }
690  }
691 
692  *min = d_min;
693  *max = d_max;
694 }
695 
696 double** Matrix::allocateMatrixData(int rows, int columns)
697 {
698  double** data = new double* [rows];
699  for ( int i = 0; i < rows; ++i)
700  data[i] = new double [columns];
701 
702  return data;
703 }
704 
705 void Matrix::freeMatrixData(double **data, int rows)
706 {
707  for ( int i = 0; i < rows; i++)
708  delete [] data[i];
709 
710  delete [] data;
711 }
712 
714 {
715  this->update();
716 }
717 
719 {
720  if (!m)
721  return;
722 
724 }
725 
726 Matrix * Matrix::fromImage(const QImage & image, ScriptingEnv *env)
727 {
729  if (!fm) return NULL;
730  return new Matrix(fm, env, image.height(), image.width(), tr("Matrix %1").arg(1));
731 }
732 
734 {
735  QApplication::setOverrideCursor(Qt::WaitCursor);
736  d_future_matrix->beginMacro(tr("%1: apply formula to selection").arg(name()));
737 
738  setFormula(ui.formula_box->toPlainText());
739  recalculate();
740 
742  QApplication::restoreOverrideCursor();
743 }
744 
746 {
747  static_cast<ScriptEdit *>(ui.formula_box)->insertFunction(ui.add_function_combobox->currentText());
748 }
749 
751 {
752  ui.formula_box->insertPlainText(ui.add_cell_combobox->currentText());
753 }
754 
756 {
757  ui.add_function_combobox->setToolTip(scriptEnv->mathFunctionDoc(ui.add_function_combobox->currentText()));
758 }
759 
761 {
762  if (aspect != d_future_matrix) return;
763  setObjectName(d_future_matrix->name());
764  updateCaption();
765 }
766 
767 
768 
Matrix
Matrix worksheet class.
Definition: Matrix.h:52
Matrix::cutSelection
void cutSelection()
Standard cut operation.
Definition: Matrix.cpp:457
Matrix::dMatrix
double ** dMatrix
Stores the matrix data only before the user opens the matrix dialog in order to avoid data loses duri...
Definition: Matrix.h:306
future::Matrix::columnCount
int columnCount() const
Return the total number of columns.
Definition: future_Matrix.cpp:179
Matrix::yStart
double yStart()
Return the Y value corresponding to row 1.
Definition: Matrix.h:267
future::Matrix::save
virtual void save(QXmlStreamWriter *) const
Save as XML.
Definition: future_Matrix.cpp:1117
MatrixView
View class for Matrix.
Definition: MatrixView.h:83
future::Matrix::transpose
void transpose()
Definition: future_Matrix.cpp:1443
Matrix::formula
QString formula()
Return the matrix formula.
Definition: Matrix.cpp:250
ScriptingEnv::newScript
virtual Script * newScript(const QString &, QObject *, const QString &)=0
Instantiate the Script subclass matching the ScriptEnv subclass.
Matrix::xEnd
double xEnd()
Return the X value corresponding to the last column.
Definition: Matrix.h:265
Matrix::applyFormula
void applyFormula()
Definition: Matrix.cpp:733
ScriptEdit
Editor widget with support for evaluating expressions and executing code.
Definition: ScriptEdit.h:50
scripted::scriptEnv
ScriptingEnv * scriptEnv
Definition: Script.h:155
MatrixView::firstSelectedRow
int firstSelectedRow(bool full=false)
Return the index of the first selected row.
Definition: MatrixView.cpp:320
MatrixView::columnWidth
int columnWidth(int col) const
Definition: MatrixView.cpp:537
MatrixView::setColumnWidth
void setColumnWidth(int col, int width)
Definition: MatrixView.cpp:525
Matrix::recalculate
bool recalculate()
Calculate matrix values using the formula for all selected cells.
Definition: Matrix.cpp:396
Matrix::allocateMatrixData
static double ** allocateMatrixData(int rows, int columns)
Allocate memory for a matrix buffer.
Definition: Matrix.cpp:696
Matrix::birthDate
virtual QString birthDate()
Return the creation date.
Definition: Matrix.h:288
Matrix::numSelectedRows
int numSelectedRows()
Return the number of selected rows.
Definition: Matrix.cpp:498
data
Definition: exp_saturation.c:37
MatrixView::lastSelectedColumn
int lastSelectedColumn(bool full=false)
Return the index of the last selected column.
Definition: MatrixView.cpp:309
future::Matrix::setCells
void setCells(const QVector< qreal > &data)
Set the value of all cells.
Definition: future_Matrix.cpp:923
Matrix::fromImage
static Matrix * fromImage(const QImage &image, ScriptingEnv *env)
Definition: Matrix.cpp:726
Matrix::deleteSelectedColumns
void deleteSelectedColumns()
Delte the selected columns.
Definition: Matrix.cpp:493
Script::setDouble
virtual bool setDouble(double, const char *)
Definition: Script.h:95
future::Matrix::setNumericFormat
void setNumericFormat(char format)
Definition: future_Matrix.cpp:1059
Matrix::xStart
double xStart()
Return the X value corresponding to column 1.
Definition: Matrix.h:263
Matrix::setTextFormat
void setTextFormat(const QChar &format, int precision)
Set the number format for the cells.
Definition: Matrix.cpp:266
Matrix::columnsSelected
bool columnsSelected()
Return whether any columns are fully selected.
Definition: Matrix.cpp:483
ScriptEdit.h
MatrixView::isRowSelected
bool isRowSelected(int row, bool full=false)
Returns true if row 'row' is selected; otherwise false.
Definition: MatrixView.cpp:287
Matrix.h
future::Matrix::displayedDigits
int displayedDigits() const
Definition: future_Matrix.cpp:1112
Matrix::setText
void setText(int row, int col, const QString &new_text)
Set the content of the cell as a string.
Definition: Matrix.cpp:157
MyWidget::captionPolicy
virtual CaptionPolicy captionPolicy()
Return the caption policy.
Definition: MyWidget.h:86
Matrix::closeEvent
void closeEvent(QCloseEvent *)
Definition: Matrix.cpp:532
AbstractAspect::creationTime
QDateTime creationTime() const
Definition: AbstractAspect.cpp:288
MyWidget::birthdate
QString birthdate
The creation date.
Definition: MyWidget.h:166
Matrix::print
void print()
Print the Matrix.
Definition: Matrix.cpp:568
Matrix::saveCellsToMemory
void saveCellsToMemory()
Temporally save the cell values to memory.
Definition: Matrix.cpp:380
Matrix::setFormula
void setFormula(const QString &s)
Set the matrix forumla.
Definition: Matrix.cpp:245
SCRIPTING_CHANGE_EVENT
#define SCRIPTING_CHANGE_EVENT
Definition: customevents.h:40
future::Matrix::pasteIntoSelection
void pasteIntoSelection()
Definition: future_Matrix.cpp:253
Matrix::setNumericFormat
void setNumericFormat(const QChar &f, int prec)
Set the number format for the cells.
Definition: Matrix.cpp:255
MatrixView::d_view_widget
MatrixViewWidget * d_view_widget
The matrix view (first part of the UI)
Definition: MatrixView.h:203
scripted
Interface for maintaining a reference to the current ScriptingEnv.
Definition: Script.h:149
Matrix::setCoordinates
void setCoordinates(double xs, double xe, double ys, double ye)
Set the X and Y coordinate intervals.
Definition: Matrix.cpp:179
Matrix::setCells
void setCells(const QVector< qreal > &)
Set the value of all cells.
Definition: Matrix.cpp:147
Matrix::customEvent
void customEvent(QEvent *e)
Custom event handler.
Definition: Matrix.cpp:526
Matrix::name
virtual QString name()
Return the window name.
Definition: Matrix.h:59
Matrix::~Matrix
~Matrix()
Definition: Matrix.cpp:125
Matrix::setDimensions
void setDimensions(int rows, int cols)
Set the Matrix size.
Definition: Matrix.cpp:278
scripted::scriptingChangeEvent
void scriptingChangeEvent(ScriptingChangeEvent *)
Definition: Script.cpp:119
MatrixView::isCellSelected
bool isCellSelected(int row, int col)
Return whether a cell is selected.
Definition: MatrixView.cpp:345
future::Matrix
Aspect providing a spreadsheet to manage MxN matrix data.
Definition: future_Matrix.h:60
MyWidget::modifiedWindow
void modifiedWindow(MyWidget *)
AbstractAspect::endMacro
void endMacro()
End the undo stack macro.
Definition: AbstractAspect.cpp:222
Matrix::saveToString
QString saveToString(const QString &info)
Return a string to save the matrix in a project file (<matrix> section)
Definition: Matrix.cpp:184
AbstractAspect::beginMacro
void beginMacro(const QString &text)
Begin an undo stack macro (series of commands)
Definition: AbstractAspect.cpp:215
Matrix::updateFunctionDoc
void updateFunctionDoc()
Definition: Matrix.cpp:755
Matrix::rowsSelected
bool rowsSelected()
Return whether any rows are fully selected.
Definition: Matrix.cpp:463
MatrixView::isColumnSelected
bool isColumnSelected(int col, bool full=false)
Returns true if column 'col' is selected; otherwise false.
Definition: MatrixView.cpp:267
future::Matrix::setCoordinates
void setCoordinates(double x1, double x2, double y1, double y2)
Definition: future_Matrix.cpp:1052
Matrix::numCols
int numCols()
Return the number of columns.
Definition: Matrix.cpp:293
Matrix::invert
void invert()
Invert the matrix.
Definition: Matrix.cpp:334
MatrixView::firstSelectedColumn
int firstSelectedColumn(bool full=false)
Return the index of the first selected column.
Definition: MatrixView.cpp:295
future::Matrix::rowCount
int rowCount() const
Return the total number of rows.
Definition: future_Matrix.cpp:184
Matrix::addFunction
void addFunction()
Definition: Matrix.cpp:745
future::Matrix::fromImage
static Matrix * fromImage(const QImage &image)
Definition: future_Matrix.cpp:1498
Matrix::insertColumn
void insertColumn()
Insert a column before the current cell.
Definition: Matrix.cpp:478
ScriptingEnv
An interpreter for evaluating scripting code. Abstract.
Definition: ScriptingEnv.h:53
Matrix::handleAspectDescriptionChange
void handleAspectDescriptionChange(const AbstractAspect *aspect)
Definition: Matrix.cpp:760
Matrix::d_future_matrix
future::Matrix * d_future_matrix
Definition: Matrix.h:56
AbstractAspect::name
QString name() const
Definition: AbstractAspect.cpp:229
Matrix::saveAsTemplate
QString saveAsTemplate(const QString &info)
Format the matrix format in a string to save it in a template file.
Definition: Matrix.cpp:215
future::Matrix::insertEmptyRows
void insertEmptyRows()
Insert rows depending on the selection.
Definition: future_Matrix.cpp:376
future::Matrix::setFormula
void setFormula(const QString &formula)
Definition: future_Matrix.cpp:1100
Matrix::setCell
void setCell(int row, int col, double value)
Set the value of the cell.
Definition: Matrix.cpp:142
MatrixView::ui
Ui::MatrixControlTabs ui
Definition: MatrixView.h:201
Matrix::saveText
QString saveText()
Return a string conaining the data of the matrix (<data> section)
Definition: Matrix.cpp:230
Matrix::insertRow
void insertRow()
Insert a row before the current cell.
Definition: Matrix.cpp:516
Script
A chunk of scripting code. Abstract.
Definition: Script.h:53
future::Matrix::formula
QString formula() const
Definition: future_Matrix.cpp:1095
Matrix::forgetSavedCells
void forgetSavedCells()
Definition: Matrix.cpp:390
Matrix::setNumCols
void setNumCols(int cols)
Definition: Matrix.cpp:298
Matrix::copy
void copy(Matrix *m)
Definition: Matrix.cpp:718
Matrix::pasteSelection
void pasteSelection()
Standard paste operation.
Definition: Matrix.cpp:521
future::Matrix::insertEmptyColumns
void insertEmptyColumns()
Insert columns depending on the selection.
Definition: future_Matrix.cpp:324
ScriptingChangeEvent
notify an object that it should update its scripting environment (see class scripted)
Definition: Script.h:133
name
char * name()
Definition: exp_saturation.c:45
Matrix::updateDecimalSeparators
void updateDecimalSeparators()
Definition: Matrix.cpp:713
Matrix::handleChange
void handleChange()
Definition: Matrix.cpp:129
Matrix::range
void range(double *min, double *max)
Min and max values of the matrix.
Definition: Matrix.cpp:674
Matrix::Matrix
Matrix(ScriptingEnv *env, int r, int c, const QString &label, QWidget *parent=0, const char *name=0, Qt::WindowFlags f=0)
Constructor.
Definition: Matrix.cpp:63
Matrix::copySelection
void copySelection()
Standard copy operation.
Definition: Matrix.cpp:452
future::Matrix::setDisplayedDigits
void setDisplayedDigits(int digits)
Definition: future_Matrix.cpp:1067
Matrix::setColumnsWidth
void setColumnsWidth(int width)
Set the width of all columns (obsolete, only for OPJ import)
Definition: Matrix.cpp:272
MatrixView::lastSelectedRow
int lastSelectedRow(bool full=false)
Return the index of the last selected row.
Definition: MatrixView.cpp:334
ScriptingEnv::mathFunctions
virtual const QStringList mathFunctions() const
Return a list of supported mathematical functions. These should be imported into the global namespace...
Definition: ScriptingEnv.h:72
ScriptingEnv::mathFunctionDoc
virtual const QString mathFunctionDoc(const QString &) const
Return a documentation string for the given mathematical function.
Definition: ScriptingEnv.h:74
Matrix::text
QString text(int row, int col)
Return the content of the cell as a string.
Definition: Matrix.cpp:152
MatrixView.h
future::Matrix::setCell
void setCell(int row, int col, double value)
Set the value of the cell.
Definition: future_Matrix.cpp:916
AbstractAspect::remove
virtual void remove()
Remove me from my parent's list of children.
Definition: AbstractAspect.h:250
Matrix::determinant
double determinant()
Calculate the determinant of the matrix.
Definition: Matrix.cpp:303
future::Matrix::clearSelectedCells
void clearSelectedCells()
Definition: future_Matrix.cpp:436
Matrix::clearSelection
void clearSelection()
Clear cells.
Definition: Matrix.cpp:447
Matrix::exportPDF
void exportPDF(const QString &fileName)
Definition: Matrix.cpp:563
Script::eval
virtual QVariant eval()
Evaluate the Code, returning QVariant() on an error / exception.
Definition: Script.cpp:96
Matrix::yEnd
double yEnd()
Return the Y value corresponding to the last row.
Definition: Matrix.h:269
future::Matrix::numericFormat
char numericFormat() const
Definition: future_Matrix.cpp:1107
Matrix::addCell
void addCell()
Definition: Matrix.cpp:750
MyWidget::hiddenWindow
void hiddenWindow(MyWidget *)
Emitted when the window was hidden.
Matrix::deleteSelectedRows
void deleteSelectedRows()
Delete the selected rows.
Definition: Matrix.cpp:473
Matrix::windowLabel
virtual QString windowLabel()
Return the window label.
Definition: Matrix.h:63
MyWidget::askOnClose
bool askOnClose
Toggle on/off: Ask the user "delete, hide, or cancel?" on a close event.
Definition: MyWidget.h:175
MatrixView::init
void init()
Initialization.
Definition: MatrixView.cpp:84
future::Matrix::copySelection
void copySelection()
Definition: future_Matrix.cpp:219
Script::setInt
virtual bool setInt(int, const char *)
Definition: Script.h:94
future::Matrix::text
QString text(int row, int col)
Return the text displayed in the given cell.
Definition: future_Matrix.cpp:905
future::Matrix::removeSelectedColumns
void removeSelectedColumns()
Definition: future_Matrix.cpp:349
future::Matrix::removeSelectedRows
void removeSelectedRows()
Definition: future_Matrix.cpp:402
MyWidget::updateCaption
void updateCaption()
Set caption according to current CaptionPolicy, name and label.
Definition: MyWidget.cpp:52
Matrix::numRows
int numRows()
Return the number of rows.
Definition: Matrix.cpp:283
future::Matrix::setDimensions
void setDimensions(int rows, int cols)
Set the number of rows and columns.
Definition: future_Matrix.cpp:160
MyWidget::aspect
QString aspect()
Return the window status as a string.
Definition: MyWidget.cpp:106
future::Matrix::cell
double cell(int row, int col) const
Return the value in the given cell.
Definition: future_Matrix.cpp:198
Matrix::precision
int precision()
Return the number precision digits.
Definition: Matrix.h:175
Matrix::freeMatrixData
static void freeMatrixData(double **data, int rows)
Free memory used for a matrix buffer.
Definition: Matrix.cpp:705
Matrix::cell
double cell(int row, int col)
Return the value of the cell as a double.
Definition: Matrix.cpp:134
AbstractAspect
Base class of all persistent objects in a Project.
Definition: AbstractAspect.h:86
future::Matrix::copy
void copy(Matrix *other)
Definition: future_Matrix.cpp:866
Script::compile
virtual bool compile(bool for_eval=true)
Compile the Code. Return true if the implementation doesn't support compilation.
Definition: Script.cpp:90
Matrix::transpose
void transpose()
Transpose the matrix.
Definition: Matrix.cpp:375
Matrix::numSelectedColumns
int numSelectedColumns()
Return the number of selected columns.
Definition: Matrix.cpp:507
Matrix::setNumRows
void setNumRows(int rows)
Definition: Matrix.cpp:288