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)  

future_Matrix.cpp
Go to the documentation of this file.
1 
13 
31 #include "matrix/future_Matrix.h"
32 #include "Matrix.h"
33 #include "core/future_Folder.h"
34 #include "matrixcommands.h"
35 #include "lib/ActionManager.h"
36 #include "lib/XmlStreamReader.h"
37 
38 #include <QtCore>
39 #include <QtGui>
40 #include <QtDebug>
41 #include <QMenu>
42 #include <QInputDialog>
43 #include <QFileDialog>
44 #include <QProgressDialog>
45 
46 #include <stdlib.h>
47 #include <math.h>
48 #include <stdio.h>
49 
50 #include <gsl/gsl_linalg.h>
51 #include <gsl/gsl_math.h>
52 
53 namespace future{
54 
55 #define WAIT_CURSOR QApplication::setOverrideCursor(QCursor(Qt::WaitCursor))
56 #define RESET_CURSOR QApplication::restoreOverrideCursor()
57 
60 
61 #ifndef LEGACY_CODE_0_2_x
62 Matrix::Matrix(AbstractScriptingEngine *engine, int rows, int cols, const QString& name)
63  : AbstractPart(name), d_plot_menu(0), scripted(engine)
64 #else
65 Matrix::Matrix(void *, int rows, int cols, const QString& name)
66  : AbstractPart(name), d_plot_menu(0)
67 #endif
68 {
69  d_matrix_private = new Private(this);
70  // set initial number of rows and columns
71  appendColumns(cols);
72  appendRows(rows);
73 
74  d_view = NULL;
75  createActions();
77 }
78 
79 #ifndef LEGACY_CODE_0_2_x
81  : AbstractPart("temp"), scripted(0)
82 #else
83 Matrix::Matrix()
84  : AbstractPart("temp")
85 #endif
86 {
87  d_view = NULL;
88  createActions();
89 }
90 
92 {
93  // delete d_view.data();
94 }
95 
96 void Matrix::setView(MatrixView * view)
97 {
98  d_view = view;
100  connect(d_view, SIGNAL(controlTabBarStatusChanged(bool)), this, SLOT(adjustTabBarAction(bool)));
101  adjustTabBarAction(true);
102 }
103 
104 QWidget *Matrix::view()
105 {
106 #ifndef LEGACY_CODE_0_2_x
107  if (!d_view)
108  {
109  d_view = new MatrixView(this);
111  connect(d_view, SIGNAL(controlTabBarStatusChanged(bool)), this, SLOT(adjustTabBarAction(bool)));
112  adjustTabBarAction(true);
113  }
114 #else
115  Q_ASSERT(d_view != NULL);
116 #endif
117  return d_view;
118 }
119 
120 void Matrix::insertColumns(int before, int count)
121 {
122  if( count < 1 || before < 0 || before > columnCount()) return;
123  WAIT_CURSOR;
124  beginMacro(QObject::tr("%1: insert %2 column(s)").arg(name()).arg(count));
125  exec(new MatrixInsertColumnsCmd(d_matrix_private, before, count));
126  endMacro();
127  RESET_CURSOR;
128 }
129 
130 void Matrix::removeColumns(int first, int count)
131 {
132  if( count < 1 || first < 0 || first+count > columnCount()) return;
133  WAIT_CURSOR;
134  beginMacro(QObject::tr("%1: remove %2 column(s)").arg(name()).arg(count));
135  exec(new MatrixRemoveColumnsCmd(d_matrix_private, first, count));
136  endMacro();
137  RESET_CURSOR;
138 }
139 
140 void Matrix::removeRows(int first, int count)
141 {
142  if( count < 1 || first < 0 || first+count > rowCount()) return;
143  WAIT_CURSOR;
144  beginMacro(QObject::tr("%1: remove %2 row(s)").arg(name()).arg(count));
145  exec(new MatrixRemoveRowsCmd(d_matrix_private, first, count));
146  endMacro();
147  RESET_CURSOR;
148 }
149 
150 void Matrix::insertRows(int before, int count)
151 {
152  if( count < 1 || before < 0 || before > rowCount()) return;
153  WAIT_CURSOR;
154  beginMacro(QObject::tr("%1: insert %2 row(s)").arg(name()).arg(count));
155  exec(new MatrixInsertRowsCmd(d_matrix_private, before, count));
156  endMacro();
157  RESET_CURSOR;
158 }
159 
160 void Matrix::setDimensions(int rows, int cols)
161 {
162  if( (rows < 0) || (cols < 0 ) || (rows == rowCount() && cols == columnCount()) ) return;
163  WAIT_CURSOR;
164  beginMacro(QObject::tr("%1: set matrix size to %2x%3").arg(name()).arg(rows).arg(cols));
165  int col_diff = cols - columnCount();
166  int row_diff = rows - rowCount();
167  if(col_diff > 0)
169  else if(col_diff < 0)
170  exec(new MatrixRemoveColumnsCmd(d_matrix_private, columnCount()+col_diff, -col_diff));
171  if(row_diff > 0)
173  else if(row_diff < 0)
174  exec(new MatrixRemoveRowsCmd(d_matrix_private, rowCount()+row_diff, -row_diff));
175  endMacro();
176  RESET_CURSOR;
177 }
178 
180 {
181  return d_matrix_private->columnCount();
182 }
183 
184 int Matrix::rowCount() const
185 {
186  return d_matrix_private->rowCount();
187 }
188 
190 {
191  WAIT_CURSOR;
192  beginMacro(QObject::tr("%1: clear").arg(name()));
194  endMacro();
195  RESET_CURSOR;
196 }
197 
198 double Matrix::cell(int row, int col) const
199 {
200  if(row < 0 || row >= rowCount() ||
201  col < 0 || col >= columnCount()) return 0.0;
202  return d_matrix_private->cell(row, col);
203 }
204 
206 {
207  if (!d_view) return;
208  int first = d_view->firstSelectedRow();
209  if( first < 0 ) return;
210 
211  WAIT_CURSOR;
212  beginMacro(tr("%1: cut selected cell(s)").arg(name()));
213  copySelection();
215  endMacro();
216  RESET_CURSOR;
217 }
218 
220 {
221  if (!d_view) return;
222  int first_col = d_view->firstSelectedColumn(false);
223  if(first_col == -1) return;
224  int last_col = d_view->lastSelectedColumn(false);
225  if(last_col == -2) return;
226  int first_row = d_view->firstSelectedRow(false);
227  if(first_row == -1) return;
228  int last_row = d_view->lastSelectedRow(false);
229  if(last_row == -2) return;
230  int cols = last_col - first_col +1;
231  int rows = last_row - first_row +1;
232 
233  WAIT_CURSOR;
234  QString output_str;
235 
236  for(int r=0; r<rows; r++)
237  {
238  for(int c=0; c<cols; c++)
239  {
240  if(d_view->isCellSelected(first_row + r, first_col + c))
241  output_str += QLocale().toString(cell(first_row + r, first_col + c),
242  d_matrix_private->numericFormat(), 16); // copy with max. precision
243  if(c < cols-1)
244  output_str += "\t";
245  }
246  if(r < rows-1)
247  output_str += "\n";
248  }
249  QApplication::clipboard()->setText(output_str);
250  RESET_CURSOR;
251 }
252 
254 {
255  if (!d_view) return;
256  if(columnCount() < 1 || rowCount() < 1) return;
257 
258  WAIT_CURSOR;
259  beginMacro(tr("%1: paste from clipboard").arg(name()));
260 
261  int first_col = d_view->firstSelectedColumn(false);
262  int last_col = d_view->lastSelectedColumn(false);
263  int first_row = d_view->firstSelectedRow(false);
264  int last_row = d_view->lastSelectedRow(false);
265  int input_row_count = 0;
266  int input_col_count = 0;
267  int rows, cols;
268 
269  const QClipboard *clipboard = QApplication::clipboard();
270  const QMimeData *mimeData = clipboard->mimeData();;
271  if(mimeData->hasText())
272  {
273  QString input_str = QString(clipboard->text());
274  QList< QStringList > cell_texts;
275  QStringList input_rows(input_str.split(QRegExp("\\n|\\r\\n|\\r")));
276  input_row_count = input_rows.count();
277  input_col_count = 0;
278  for(int i=0; i<input_row_count; i++)
279  {
280  cell_texts.append(input_rows.at(i).split("\t"));
281  if(cell_texts.at(i).count() > input_col_count) input_col_count = cell_texts.at(i).count();
282  }
283 
284  if( (first_col == -1 || first_row == -1) ||
285  (last_row == first_row && last_col == first_col) )
286  // if the is no selection or only one cell selected, the
287  // selection will be expanded to the needed size from the current cell
288  {
289  int current_row, current_col;
290  d_view->getCurrentCell(&current_row, &current_col);
291  if(current_row == -1) current_row = 0;
292  if(current_col == -1) current_col = 0;
293  d_view->setCellSelected(current_row, current_col);
294  first_col = current_col;
295  first_row = current_row;
296  last_row = first_row + input_row_count -1;
297  last_col = first_col + input_col_count -1;
298  // resize the matrix if necessary
299  if(last_col >= columnCount())
300  appendColumns(last_col+1-columnCount());
301  if(last_row >= rowCount())
302  appendRows(last_row+1-rowCount());
303  // select the rectangle to be pasted in
304  d_view->setCellsSelected(first_row, first_col, last_row, last_col);
305  }
306 
307  rows = last_row - first_row + 1;
308  cols = last_col - first_col + 1;
309  for(int r=0; r<rows && r<input_row_count; r++)
310  {
311  for(int c=0; c<cols && c<input_col_count; c++)
312  {
313  if(d_view->isCellSelected(first_row + r, first_col + c) && (c < cell_texts.at(r).count()) )
314  {
315  setCell(first_row + r, first_col + c, cell_texts.at(r).at(c).toDouble());
316  }
317  }
318  }
319  }
320  endMacro();
321  RESET_CURSOR;
322 }
323 
325 {
326  if (!d_view) return;
327  int first = d_view->firstSelectedColumn();
328  int last = d_view->lastSelectedColumn();
329  if( first < 0 ) return;
330  int count, current = first;
331 
332  WAIT_CURSOR;
333  beginMacro(QObject::tr("%1: insert empty column(s)").arg(name()));
334  while( current <= last )
335  {
336  current = first+1;
337  while( current <= last && d_view->isColumnSelected(current) ) current++;
338  count = current-first;
339  insertColumns(first, count);
340  current += count;
341  last += count;
342  while( current <= last && !d_view->isColumnSelected(current) ) current++;
343  first = current;
344  }
345  endMacro();
346  RESET_CURSOR;
347 }
348 
350 {
351  if (!d_view) return;
352  int first = d_view->firstSelectedColumn();
353  int last = d_view->lastSelectedColumn();
354  if( first < 0 ) return;
355 
356  WAIT_CURSOR;
357  beginMacro(QObject::tr("%1: remove selected column(s)").arg(name()));
358  for(int i=last; i>=first; i--)
359  if(d_view->isColumnSelected(i, false)) removeColumns(i, 1);
360  endMacro();
361  RESET_CURSOR;
362 }
363 
365 {
366  if (!d_view) return;
367  WAIT_CURSOR;
368  beginMacro(QObject::tr("%1: clear selected column(s)").arg(name()));
369  for(int i=0; i<columnCount(); i++)
370  if(d_view->isColumnSelected(i, false))
372  endMacro();
373  RESET_CURSOR;
374 }
375 
377 {
378  if (!d_view) return;
379  int first = d_view->firstSelectedRow();
380  int last = d_view->lastSelectedRow();
381  int count, current = first;
382 
383  if( first < 0 ) return;
384 
385  WAIT_CURSOR;
386  beginMacro(QObject::tr("%1: insert empty rows(s)").arg(name()));
387  while( current <= last )
388  {
389  current = first+1;
390  while( current <= last && d_view->isRowSelected(current) ) current++;
391  count = current-first;
392  insertRows(first, count);
393  current += count;
394  last += count;
395  while( current <= last && !d_view->isRowSelected(current) ) current++;
396  first = current;
397  }
398  endMacro();
399  RESET_CURSOR;
400 }
401 
403 {
404  if (!d_view) return;
405  int first = d_view->firstSelectedRow();
406  int last = d_view->lastSelectedRow();
407  if( first < 0 ) return;
408 
409  WAIT_CURSOR;
410  beginMacro(QObject::tr("%1: remove selected rows(s)").arg(name()));
411  for(int i=last; i>=first; i--)
412  if(d_view->isRowSelected(i, false)) removeRows(i, 1);
413  endMacro();
414  RESET_CURSOR;
415 }
416 
418 {
419  if (!d_view) return;
420  int first = d_view->firstSelectedRow();
421  int last = d_view->lastSelectedRow();
422  if( first < 0 ) return;
423 
424  WAIT_CURSOR;
425  beginMacro(QObject::tr("%1: clear selected rows(s)").arg(name()));
426  for(int i=first; i<=last; i++)
427  {
428  if(d_view->isRowSelected(i))
429  for(int j=0; j<columnCount(); j++)
431  }
432  endMacro();
433  RESET_CURSOR;
434 }
435 
437 {
438  if (!d_view) return;
439  int first_row = d_view->firstSelectedRow();
440  int last_row = d_view->lastSelectedRow();
441  if( first_row < 0 ) return;
442  int first_col = d_view->firstSelectedColumn();
443  int last_col = d_view->lastSelectedColumn();
444  if( first_col < 0 ) return;
445 
446  WAIT_CURSOR;
447  beginMacro(tr("%1: clear selected cell(s)").arg(name()));
448  for(int i=first_row; i<=last_row; i++)
449  for(int j=first_col; j<=last_col; j++)
450  if(d_view->isCellSelected(i, j))
452  endMacro();
453  RESET_CURSOR;
454 }
455 
457 {
458  QMenu *menu = AbstractPart::createContextMenu();
459  Q_ASSERT(menu);
460  menu->addSeparator();
461 
462  menu->addAction(action_duplicate);
463  // TODO menu->addAction( ....
464 
465  return menu;
466 }
467 
468 QMenu * Matrix::createSelectionMenu(QMenu * append_to)
469 {
470  QMenu * menu = append_to;
471  if(!menu)
472  menu = new QMenu();
473 
474  menu->addAction(action_cut_selection);
475  menu->addAction(action_copy_selection);
476  menu->addAction(action_paste_into_selection);
477  menu->addAction(action_clear_selection);
478 
479  return menu;
480 }
481 
482 
483 QMenu * Matrix::createColumnMenu(QMenu * append_to)
484 {
485  QMenu * menu = append_to;
486  if(!menu)
487  menu = new QMenu();
488 
489  menu->addAction(action_insert_columns);
490  menu->addAction(action_remove_columns);
491  menu->addAction(action_clear_columns);
492  menu->addSeparator();
493  menu->addAction(action_edit_coordinates);
494 
495  return menu;
496 }
497 
498 QMenu * Matrix::createMatrixMenu(QMenu * append_to)
499 {
500  QMenu * menu = append_to;
501  if(!menu)
502  menu = new QMenu();
503 
504  menu->addAction(action_toggle_tabbar);
505  menu->addSeparator();
506  menu->addAction(action_select_all);
507  menu->addAction(action_clear_matrix);
508  menu->addSeparator();
509  menu->addAction(action_set_formula);
510  menu->addAction(action_recalculate);
511  menu->addSeparator();
512  menu->addAction(action_edit_format);
513  menu->addSeparator();
514  menu->addAction(action_go_to_cell);
515 
516  return menu;
517 }
518 
519 QMenu * Matrix::createRowMenu(QMenu * append_to)
520 {
521  QMenu * menu = append_to;
522  if(!menu)
523  menu = new QMenu();
524 
525  menu->addAction(action_insert_rows);
526  menu->addAction(action_remove_rows);
527  menu->addAction(action_clear_rows);
528  menu->addSeparator();
529  menu->addAction(action_edit_coordinates);
530 
531  return menu;
532 }
533 
534 
536 {
537  QIcon * icon_temp;
538 
539  // selection related actions
540  action_cut_selection = new QAction(QIcon(QPixmap(":/cut.xpm")), tr("Cu&t"), this);
541  actionManager()->addAction(action_cut_selection, "cut_selection");
542 
543  action_copy_selection = new QAction(QIcon(QPixmap(":/copy.xpm")), tr("&Copy"), this);
544  actionManager()->addAction(action_copy_selection, "copy_selection");
545 
546  action_paste_into_selection = new QAction(QIcon(QPixmap(":/paste.xpm")), tr("Past&e"), this);
547  actionManager()->addAction(action_paste_into_selection, "paste_into_selection");
548 
549  icon_temp = new QIcon();
550  icon_temp->addPixmap(QPixmap(":/16x16/clear.png"));
551  icon_temp->addPixmap(QPixmap(":/32x32/clear.png"));
552  action_clear_selection = new QAction(*icon_temp, tr("Clea&r","clear selection"), this);
553  actionManager()->addAction(action_clear_selection, "clear_selection");
554  delete icon_temp;
555 
556  // matrix related actions
557  icon_temp = new QIcon();
558  icon_temp->addPixmap(QPixmap(":/16x16/fx.png"));
559  icon_temp->addPixmap(QPixmap(":/32x32/fx.png"));
560  action_set_formula = new QAction(*icon_temp, tr("Assign &Formula"), this);
561  action_set_formula->setShortcut(tr("Alt+Q"));
562  actionManager()->addAction(action_set_formula, "set_formula");
563  delete icon_temp;
564 
565  icon_temp = new QIcon();
566  icon_temp->addPixmap(QPixmap(":/16x16/recalculate.png"));
567  icon_temp->addPixmap(QPixmap(":/32x32/recalculate.png"));
568  action_recalculate = new QAction(*icon_temp, tr("Recalculate"), this);
569  action_recalculate->setShortcut(tr("Ctrl+Return"));
570  actionManager()->addAction(action_recalculate, "recalculate");
571  delete icon_temp;
572 
573  icon_temp = new QIcon();
574  icon_temp->addPixmap(QPixmap(":/16x16/table_options.png"));
575  icon_temp->addPixmap(QPixmap(":/32x32/table_options.png"));
576  action_toggle_tabbar = new QAction(*icon_temp, QString("Show/Hide Controls"), this); // show/hide control tabs
577  action_toggle_tabbar->setShortcut(tr("F12"));
578  actionManager()->addAction(action_toggle_tabbar, "toggle_tabbar");
579  delete icon_temp;
580 
581  icon_temp = new QIcon();
582  icon_temp->addPixmap(QPixmap(":/16x16/select_all.png"));
583  icon_temp->addPixmap(QPixmap(":/32x32/select_all.png"));
584  action_select_all = new QAction(*icon_temp, tr("Select All"), this);
585  actionManager()->addAction(action_select_all, "select_all");
586  delete icon_temp;
587 
588  icon_temp = new QIcon();
589  icon_temp->addPixmap(QPixmap(":/16x16/clear_table.png"));
590  icon_temp->addPixmap(QPixmap(":/32x32/clear_table.png"));
591  action_clear_matrix = new QAction(*icon_temp, tr("Clear Matrix"), this);
592  actionManager()->addAction(action_clear_matrix, "clear_matrix");
593  delete icon_temp;
594 
595  icon_temp = new QIcon();
596  icon_temp->addPixmap(QPixmap(":/16x16/go_to_cell.png"));
597  icon_temp->addPixmap(QPixmap(":/32x32/go_to_cell.png"));
598  action_go_to_cell = new QAction(*icon_temp, tr("&Go to Cell"), this);
599  action_go_to_cell->setShortcut(tr("Ctrl+Alt+G"));
600  actionManager()->addAction(action_go_to_cell, "go_to_cell");
601  delete icon_temp;
602 
603  action_transpose = new QAction(tr("&Transpose"), this);
604  actionManager()->addAction(action_transpose, "transpose");
605 
606  action_mirror_horizontally = new QAction(tr("Mirror &Horizontally"), this);
607  actionManager()->addAction(action_mirror_horizontally, "mirror_horizontally");
608 
609  action_mirror_vertically = new QAction(tr("Mirror &Vertically"), this);
610  actionManager()->addAction(action_mirror_vertically, "mirror_vertically");
611 
612  action_import_image = new QAction(tr("&Import Image", "import image as matrix"), this);
613  actionManager()->addAction(action_import_image, "import_image");
614 
615  action_duplicate = new QAction(QIcon(QPixmap(":/duplicate.xpm")), tr("&Duplicate", "duplicate matrix"), this);
616  actionManager()->addAction(action_duplicate, "duplicate");
617 
618  action_dimensions_dialog = new QAction(QIcon(QPixmap(":/resize.xpm")), tr("&Dimensions", "matrix size"), this);
619  actionManager()->addAction(action_dimensions_dialog, "dimensions_dialog");
620 
621  action_edit_coordinates = new QAction(tr("Set &Coordinates"), this);
622  actionManager()->addAction(action_edit_coordinates, "edit_coordinates");
623 
624  action_edit_format = new QAction(tr("Set Display &Format"), this);
625  actionManager()->addAction(action_edit_format, "edit_format");
626 
627  // column related actions
628  icon_temp = new QIcon();
629  icon_temp->addPixmap(QPixmap(":/16x16/insert_column.png"));
630  icon_temp->addPixmap(QPixmap(":/32x32/insert_column.png"));
631  action_insert_columns = new QAction(*icon_temp, tr("&Insert Empty Columns"), this);
632  actionManager()->addAction(action_insert_columns, "insert_columns");
633  delete icon_temp;
634 
635  icon_temp = new QIcon();
636  icon_temp->addPixmap(QPixmap(":/16x16/remove_column.png"));
637  icon_temp->addPixmap(QPixmap(":/32x32/remove_column.png"));
638  action_remove_columns = new QAction(*icon_temp, tr("Remo&ve Columns"), this);
639  actionManager()->addAction(action_remove_columns, "remove_columns");
640  delete icon_temp;
641 
642  icon_temp = new QIcon();
643  icon_temp->addPixmap(QPixmap(":/16x16/clear_column.png"));
644  icon_temp->addPixmap(QPixmap(":/32x32/clear_column.png"));
645  action_clear_columns = new QAction(*icon_temp, tr("Clea&r Columns"), this);
646  actionManager()->addAction(action_clear_columns, "clear_columns");
647  delete icon_temp;
648 
649  icon_temp = new QIcon();
650  icon_temp->addPixmap(QPixmap(":/16x16/add_columns.png"));
651  icon_temp->addPixmap(QPixmap(":/32x32/add_columns.png"));
652  action_add_columns = new QAction(*icon_temp, tr("&Add Columns"), this);
653  actionManager()->addAction(action_add_columns, "add_columns");
654  delete icon_temp;
655 
656  // row related actions
657  icon_temp = new QIcon();
658  icon_temp->addPixmap(QPixmap(":/16x16/insert_row.png"));
659  icon_temp->addPixmap(QPixmap(":/32x32/insert_row.png"));
660  action_insert_rows = new QAction(*icon_temp ,tr("&Insert Empty Rows"), this);;
661  actionManager()->addAction(action_insert_rows, "insert_rows");
662  delete icon_temp;
663 
664  icon_temp = new QIcon();
665  icon_temp->addPixmap(QPixmap(":/16x16/remove_row.png"));
666  icon_temp->addPixmap(QPixmap(":/32x32/remove_row.png"));
667  action_remove_rows = new QAction(*icon_temp, tr("Remo&ve Rows"), this);;
668  actionManager()->addAction(action_remove_rows, "remove_rows");
669  delete icon_temp;
670 
671  icon_temp = new QIcon();
672  icon_temp->addPixmap(QPixmap(":/16x16/clear_row.png"));
673  icon_temp->addPixmap(QPixmap(":/32x32/clear_row.png"));
674  action_clear_rows = new QAction(*icon_temp, tr("Clea&r Rows"), this);;
675  actionManager()->addAction(action_clear_rows, "clear_rows");
676  delete icon_temp;
677 
678  icon_temp = new QIcon();
679  icon_temp->addPixmap(QPixmap(":/16x16/add_rows.png"));
680  icon_temp->addPixmap(QPixmap(":/32x32/add_rows.png"));
681  action_add_rows = new QAction(*icon_temp, tr("&Add Rows"), this);;
682  actionManager()->addAction(action_add_rows, "add_rows");
683  delete icon_temp;
684 }
685 
687 {
688  connect(action_cut_selection, SIGNAL(triggered()), this, SLOT(cutSelection()));
689  connect(action_copy_selection, SIGNAL(triggered()), this, SLOT(copySelection()));
690  connect(action_paste_into_selection, SIGNAL(triggered()), this, SLOT(pasteIntoSelection()));
691  connect(action_set_formula, SIGNAL(triggered()), this, SLOT(editFormula()));
692  connect(action_edit_coordinates, SIGNAL(triggered()), this, SLOT(editCoordinates()));
693  connect(action_edit_format, SIGNAL(triggered()), this, SLOT(editFormat()));
694  connect(action_clear_selection, SIGNAL(triggered()), this, SLOT(clearSelectedCells()));
695 #ifdef LEGACY_CODE_0_2_x
696  connect(action_recalculate, SIGNAL(triggered()), this, SLOT(recalculateSelectedCells()));
697 #endif
698  connect(action_select_all, SIGNAL(triggered()), this, SLOT(selectAll()));
699  connect(action_clear_matrix, SIGNAL(triggered()), this, SLOT(clear()));
700  connect(action_transpose, SIGNAL(triggered()), this, SLOT(transpose()));
701  connect(action_mirror_horizontally, SIGNAL(triggered()), this, SLOT(mirrorHorizontally()));
702  connect(action_mirror_vertically, SIGNAL(triggered()), this, SLOT(mirrorVertically()));
703  connect(action_go_to_cell, SIGNAL(triggered()), this, SLOT(goToCell()));
704  connect(action_dimensions_dialog, SIGNAL(triggered()), this, SLOT(dimensionsDialog()));
705  connect(action_import_image, SIGNAL(triggered()), this, SLOT(importImageDialog()));
706  connect(action_duplicate, SIGNAL(triggered()), this, SLOT(duplicate()));
707  connect(action_insert_columns, SIGNAL(triggered()), this, SLOT(insertEmptyColumns()));
708  connect(action_remove_columns, SIGNAL(triggered()), this, SLOT(removeSelectedColumns()));
709  connect(action_clear_columns, SIGNAL(triggered()), this, SLOT(clearSelectedColumns()));
710  connect(action_insert_rows, SIGNAL(triggered()), this, SLOT(insertEmptyRows()));
711  connect(action_remove_rows, SIGNAL(triggered()), this, SLOT(removeSelectedRows()));
712  connect(action_clear_rows, SIGNAL(triggered()), this, SLOT(clearSelectedRows()));
713  connect(action_add_columns, SIGNAL(triggered()), this, SLOT(addColumns()));
714  connect(action_add_rows, SIGNAL(triggered()), this, SLOT(addRows()));
715 }
716 
718 {
719  connect(action_toggle_tabbar, SIGNAL(triggered()), d_view, SLOT(toggleControlTabBar()));
720 
721  d_view->addAction(action_cut_selection);
722  d_view->addAction(action_copy_selection);
724  d_view->addAction(action_set_formula);
725  d_view->addAction(action_edit_coordinates);
726  d_view->addAction(action_edit_format);
727  d_view->addAction(action_clear_selection);
728  d_view->addAction(action_recalculate);
729  d_view->addAction(action_toggle_tabbar);
730  d_view->addAction(action_select_all);
731  d_view->addAction(action_clear_matrix);
732  d_view->addAction(action_transpose);
734  d_view->addAction(action_mirror_vertically);
735  d_view->addAction(action_go_to_cell);
736  d_view->addAction(action_dimensions_dialog);
737  d_view->addAction(action_import_image);
738 #ifndef LEGACY_CODE_0_2_x
739  d_view->addAction(action_duplicate);
740 #endif
741  d_view->addAction(action_insert_columns);
742  d_view->addAction(action_remove_columns);
743  d_view->addAction(action_clear_columns);
744  d_view->addAction(action_insert_rows);
745  d_view->addAction(action_remove_rows);
746  d_view->addAction(action_clear_rows);
747  d_view->addAction(action_add_columns);
748  d_view->addAction(action_add_rows);
749 }
750 
752 {
753  action_cut_selection->setText(tr("Cu&t"));
754  action_copy_selection->setText(tr("&Copy"));
755  action_paste_into_selection->setText(tr("Past&e"));
756  action_clear_selection->setText(tr("Clea&r","clear selection"));
757  action_set_formula->setText(tr("Assign &Formula"));
758  action_recalculate->setText(tr("Recalculate"));
759  action_select_all->setText(tr("Select All"));
760  action_clear_matrix->setText(tr("Clear Matrix"));
761  action_go_to_cell->setText(tr("&Go to Cell"));
762  action_transpose->setText(tr("&Transpose"));
763  action_mirror_horizontally->setText(tr("Mirror &Horizontally"));
764  action_mirror_vertically->setText(tr("Mirror &Vertically"));
765  action_import_image->setText(tr("&Import Image", "import image as matrix"));
766 #ifndef LEGACY_CODE_0_2_x
767  action_duplicate->setText(tr("&Duplicate", "duplicate matrix"));
768 #endif
769  action_dimensions_dialog->setText(tr("&Dimensions", "matrix size"));
770  action_edit_coordinates->setText(tr("Set &Coordinates"));
771  action_edit_format->setText(tr("Set Display &Format"));
772  action_insert_columns->setText(tr("&Insert Empty Columns"));
773  action_remove_columns->setText(tr("Remo&ve Columns"));
774  action_clear_columns->setText(tr("Clea&r Columns"));
775  action_add_columns->setText(tr("&Add Columns"));
776  action_insert_rows->setText(tr("&Insert Empty Rows"));
777  action_remove_rows->setText(tr("Remo&ve Rows"));
778  action_clear_rows->setText(tr("Clea&r Rows"));
779  action_add_rows->setText(tr("&Add Rows"));
780 }
781 
782 bool Matrix::fillProjectMenu(QMenu * menu)
783 {
784  menu->setTitle(tr("&Matrix"));
785 
786  menu->addAction(action_toggle_tabbar);
787  menu->addSeparator();
788  menu->addAction(action_edit_coordinates);
789  menu->addAction(action_dimensions_dialog);
790  menu->addAction(action_edit_format);
791  menu->addSeparator();
792  menu->addAction(action_set_formula);
793  menu->addAction(action_recalculate);
794  menu->addSeparator();
795  menu->addAction(action_clear_matrix);
796  menu->addAction(action_transpose);
797  menu->addAction(action_mirror_horizontally);
798  menu->addAction(action_mirror_vertically);
799  menu->addSeparator();
800 #ifndef LEGACY_CODE_0_2_x
801  menu->addAction(action_duplicate);
802 #endif
803  menu->addAction(action_import_image);
804  menu->addSeparator();
805  menu->addAction(action_go_to_cell);
806  if (action_clear_matrix->text() != tr("Clear Matrix"))
807  {
809  adjustTabBarAction(d_view->isControlTabBarVisible());
810  }
811 
812  return true;
813 
814  // TODO:
815  // Convert to Table
816  // Export
817 }
818 
819 void Matrix::showMatrixViewContextMenu(const QPoint& pos)
820 {
821  if (!d_view) return;
822  QMenu context_menu;
823 
824  createSelectionMenu(&context_menu);
825  context_menu.addSeparator();
826  createMatrixMenu(&context_menu);
827  context_menu.addSeparator();
828 
829  context_menu.exec(pos);
830 }
831 
833 {
834  QMenu context_menu;
835 
836  createColumnMenu(&context_menu);
837 
838  context_menu.exec(pos);
839 }
840 
842 {
843  QMenu context_menu;
844 
845  createRowMenu(&context_menu);
846 
847  context_menu.exec(pos);
848 }
849 
851 {
852  if (!d_view) return;
853  bool ok;
854 
855  int col = QInputDialog::getInt(0, tr("Go to Cell"), tr("Enter column"),
856  1, 1, columnCount(), 1, &ok);
857  if ( !ok ) return;
858 
859  int row = QInputDialog::getInt(0, tr("Go to Cell"), tr("Enter row"),
860  1, 1, rowCount(), 1, &ok);
861  if ( !ok ) return;
862 
863  d_view->goToCell(row-1, col-1);
864 }
865 
866 void Matrix::copy(Matrix * other)
867 {
868  WAIT_CURSOR;
869  beginMacro(QObject::tr("%1: copy %2").arg(name()).arg(other->name()));
870  int rows = other->rowCount();
871  int columns = other->columnCount();
872  setDimensions(rows, columns);
873  for (int i=0; i<rows; i++)
874  setRowHeight(i, other->rowHeight(i));
875  for (int i=0; i<columns; i++)
876  setColumnWidth(i, other->columnWidth(i));
878  for (int i=0; i<columns; i++)
879  setColumnCells(i, 0, rows-1, other->columnCells(i, 0, rows-1));
880  setCoordinates(other->xStart(), other->xEnd(), other->yStart(), other->yEnd());
883  setFormula(other->formula());
885  emit dataChanged(0, 0, rows-1, columns-1);
886  if (d_view) d_view->rereadSectionSizes();
887  endMacro();
888  RESET_CURSOR;
889 }
890 
891 void Matrix::setPlotMenu(QMenu * menu)
892 {
893  d_plot_menu = menu;
894 }
895 
896 QIcon Matrix::icon() const
897 {
898  QIcon ico;
899  ico.addPixmap(QPixmap(":/16x16/matrix.png"));
900  ico.addPixmap(QPixmap(":/24x24/matrix.png"));
901  ico.addPixmap(QPixmap(":/32x32/matrix.png"));
902  return ico;
903 }
904 
905 QString Matrix::text(int row, int col)
906 {
907  return QLocale().toString(cell(row,col), d_matrix_private->numericFormat(), d_matrix_private->displayedDigits());
908 }
909 
911 {
912  if (!d_view) return;
913  d_view->selectAll();
914 }
915 
916 void Matrix::setCell(int row, int col, double value)
917 {
918  if(row < 0 || row >= rowCount()) return;
919  if(col < 0 || col >= columnCount()) return;
920  exec(new MatrixSetCellValueCmd(d_matrix_private, row, col, value));
921 }
922 
923 void Matrix::setCells(const QVector<qreal> & data)
924 {
926 }
927 
929 {
930  bool ok;
931 
932  int cols = QInputDialog::getInt(0, tr("Set Matrix Dimensions"), tr("Enter number of columns"),
933  columnCount(), 1, 1e9, 1, &ok);
934  if ( !ok ) return;
935 
936  int rows = QInputDialog::getInt(0, tr("Set Matrix Dimensions"), tr("Enter number of rows"),
937  rowCount(), 1, 1e9, 1, &ok);
938  if ( !ok ) return;
939 
940  setDimensions(rows, cols);
941 }
942 
944 {
945  QList<QByteArray> formats = QImageReader::supportedImageFormats();
946  QString filter = tr("Images") + " (";
947  for (int i=0; i<formats.count(); i++)
948  filter += " *."+formats.at(i)+" ";
949  filter += ");;";
950  for (int i=0; i<formats.count(); i++)
951  filter += " *."+formats.at(i)+" (*." + formats.at(i) +");;";
952 
953  QString images_path = global("images_path").toString();
954  QString file_name = QFileDialog::getOpenFileName(0, tr("Import image from file"), images_path, filter);
955  if ( !file_name.isEmpty() )
956  {
957  QFileInfo file_info(file_name);
958  images_path = file_info.canonicalPath();
959  setGlobal("images_path", images_path);
960  QImage image(file_name);
961  Matrix * matrix = NULL;
962  if (!image.isNull())
963  matrix = Matrix::fromImage(image);
964  if (matrix)
965  {
966  copy(matrix);
967  delete matrix;
968  }
969  else
970  QMessageBox::information(0, tr("Error importing image"), tr("Import of image '%1' failed").arg(file_name));
971  }
972 }
973 
975 {
976 #ifndef LEGACY_CODE_0_2_x
977  Matrix * matrix = new Matrix(0, rowCount(), columnCount(), name());
978  matrix->copy(this);
979  if (folder())
980  folder()->addChild(matrix);
981 #endif
982 }
983 
985 {
986  if (!d_view) return;
987  d_view->showControlFormatTab();
988 }
989 
991 {
992  if (!d_view) return;
993  d_view->showControlCoordinatesTab();
994 }
995 
997 {
998  if (!d_view) return;
999  d_view->showControlFormulaTab();
1000 }
1001 
1003 {
1004  if (!d_view) return;
1005  WAIT_CURSOR;
1006  int count = d_view->selectedRowCount(false);
1007  beginMacro(QObject::tr("%1: add %2 rows(s)").arg(name()).arg(count));
1009  endMacro();
1010  RESET_CURSOR;
1011 }
1012 
1014 {
1015  if (!d_view) return;
1016  WAIT_CURSOR;
1017  int count = d_view->selectedRowCount(false);
1018  beginMacro(QObject::tr("%1: add %2 column(s)").arg(name()).arg(count));
1020  endMacro();
1021  RESET_CURSOR;
1022 }
1023 
1024 void Matrix::setXStart(double x)
1025 {
1026  WAIT_CURSOR;
1028  RESET_CURSOR;
1029 }
1030 
1031 void Matrix::setXEnd(double x)
1032 {
1033  WAIT_CURSOR;
1035  RESET_CURSOR;
1036 }
1037 
1038 void Matrix::setYStart(double y)
1039 {
1040  WAIT_CURSOR;
1042  RESET_CURSOR;
1043 }
1044 
1045 void Matrix::setYEnd(double y)
1046 {
1047  WAIT_CURSOR;
1049  RESET_CURSOR;
1050 }
1051 
1052 void Matrix::setCoordinates(double x1, double x2, double y1, double y2)
1053 {
1054  WAIT_CURSOR;
1055  exec(new MatrixSetCoordinatesCmd(d_matrix_private, x1, x2, y1, y2));
1056  RESET_CURSOR;
1057 }
1058 
1059 void Matrix::setNumericFormat(char format)
1060 {
1061  if (format == numericFormat()) return;
1062  WAIT_CURSOR;
1064  RESET_CURSOR;
1065 }
1066 
1068 {
1069  if (digits == displayedDigits()) return;
1070  WAIT_CURSOR;
1072  RESET_CURSOR;
1073 }
1074 
1075 double Matrix::xStart() const
1076 {
1077  return d_matrix_private->xStart();
1078 }
1079 
1080 double Matrix::yStart() const
1081 {
1082  return d_matrix_private->yStart();
1083 }
1084 
1085 double Matrix::xEnd() const
1086 {
1087  return d_matrix_private->xEnd();
1088 }
1089 
1090 double Matrix::yEnd() const
1091 {
1092  return d_matrix_private->yEnd();
1093 }
1094 
1095 QString Matrix::formula() const
1096 {
1097  return d_matrix_private->formula();
1098 }
1099 
1100 void Matrix::setFormula(const QString & formula)
1101 {
1102  WAIT_CURSOR;
1104  RESET_CURSOR;
1105 }
1106 
1108 {
1109  return d_matrix_private->numericFormat();
1110 }
1111 
1113 {
1114  return d_matrix_private->displayedDigits();
1115 }
1116 
1117 void Matrix::save(QXmlStreamWriter * writer) const
1118 {
1119  int cols = columnCount();
1120  int rows = rowCount();
1121  writer->writeStartElement("matrix");
1122  writeBasicAttributes(writer);
1123  writer->writeAttribute("columns", QString::number(cols));
1124  writer->writeAttribute("rows", QString::number(rows));
1125  writeCommentElement(writer);
1126  writer->writeStartElement("formula");
1127  writer->writeCharacters(formula());
1128  writer->writeEndElement();
1129  writer->writeStartElement("display");
1130  writer->writeAttribute("numeric_format", QString(QChar(numericFormat())));
1131  writer->writeAttribute("displayed_digits", QString::number(displayedDigits()));
1132  writer->writeEndElement();
1133  writer->writeStartElement("coordinates");
1134  writer->writeAttribute("x_start", QString::number(xStart()));
1135  writer->writeAttribute("x_end", QString::number(xEnd()));
1136  writer->writeAttribute("y_start", QString::number(yStart()));
1137  writer->writeAttribute("y_end", QString::number(yEnd()));
1138  writer->writeEndElement();
1139 
1140  for (int col=0; col<cols; col++)
1141  for (int row=0; row<rows; row++)
1142  {
1143  writer->writeStartElement("cell");
1144  writer->writeAttribute("row", QString::number(row));
1145  writer->writeAttribute("column", QString::number(col));
1146  writer->writeCharacters(QString::number(cell(row, col), 'e', 16));
1147  writer->writeEndElement();
1148  }
1149  for (int col=0; col<cols; col++)
1150  {
1151  writer->writeStartElement("column_width");
1152  writer->writeAttribute("column", QString::number(col));
1153  writer->writeCharacters(QString::number(columnWidth(col)));
1154  writer->writeEndElement();
1155  }
1156  for (int row=0; row<rows; row++)
1157  {
1158  writer->writeStartElement("row_height");
1159  writer->writeAttribute("row", QString::number(row));
1160  writer->writeCharacters(QString::number(rowHeight(row)));
1161  writer->writeEndElement();
1162  }
1163  writer->writeEndElement(); // "matrix"
1164 }
1165 
1166 
1168 {
1169  if(reader->isStartElement() && reader->name() == "matrix")
1170  {
1171  setDimensions(0, 0);
1172  setComment("");
1173  setFormula("");
1174  setNumericFormat('f');
1175  setDisplayedDigits(6);
1176  setCoordinates(0.0, 1.0, 0.0, 1.0);
1177 
1178  if (!readBasicAttributes(reader)) return false;
1179 
1180  // read dimensions
1181  bool ok1, ok2;
1182  int rows, cols;
1183  rows = reader->readAttributeInt("rows", &ok1);
1184  cols = reader->readAttributeInt("columns", &ok2);
1185  if(!ok1 || !ok2)
1186  {
1187  reader->raiseError(tr("invalid row or column count"));
1188  return false;
1189  }
1191  setDimensions(rows, cols);
1192 
1193  // read child elements
1194  while (!reader->atEnd())
1195  {
1196  reader->readNext();
1197 
1198  if (reader->isEndElement()) break;
1199 
1200  if (reader->isStartElement())
1201  {
1202  bool ret_val = true;
1203  if (reader->name() == "comment")
1204  ret_val = readCommentElement(reader);
1205  else if(reader->name() == "formula")
1206  ret_val = readFormulaElement(reader);
1207  else if(reader->name() == "display")
1208  ret_val = readDisplayElement(reader);
1209  else if(reader->name() == "coordinates")
1210  ret_val = readCoordinatesElement(reader);
1211  else if(reader->name() == "cell")
1212  ret_val = readCellElement(reader);
1213  else if(reader->name() == "row_height")
1214  ret_val = readRowHeightElement(reader);
1215  else if(reader->name() == "column_width")
1216  ret_val = readColumnWidthElement(reader);
1217  else // unknown element
1218  {
1219  reader->raiseWarning(tr("unknown element '%1'").arg(reader->name().toString()));
1220  if (!reader->skipToEndElement()) return false;
1221  }
1222  if(!ret_val) return false;
1223  }
1224  }
1226  }
1227  else // no matrix element
1228  reader->raiseError(tr("no matrix element found"));
1229 
1230  return !reader->hasError();
1231 }
1232 
1234 {
1235  Q_ASSERT(reader->isStartElement() && reader->name() == "display");
1236  QXmlStreamAttributes attribs = reader->attributes();
1237 
1238  QString str = attribs.value(reader->namespaceUri().toString(), "numeric_format").toString();
1239  if(str.isEmpty() || str.length() != 1)
1240  {
1241  reader->raiseError(tr("invalid or missing numeric format"));
1242  return false;
1243  }
1244  setNumericFormat(str.at(0).toLatin1());
1245 
1246  bool ok;
1247  int digits = reader->readAttributeInt("displayed_digits", &ok);
1248  if(!ok)
1249  {
1250  reader->raiseError(tr("invalid or missing number of displayed digits"));
1251  return false;
1252  }
1253  setDisplayedDigits(digits);
1254  if (!reader->skipToEndElement()) return false;
1255 
1256  return true;
1257 }
1258 
1260 {
1261  Q_ASSERT(reader->isStartElement() && reader->name() == "coordinates");
1262 
1263  bool ok;
1264  int val;
1265 
1266  val = reader->readAttributeInt("x_start", &ok);
1267  if(!ok)
1268  {
1269  reader->raiseError(tr("invalid x start value"));
1270  return false;
1271  }
1272  setXStart(val);
1273 
1274  val = reader->readAttributeInt("x_end", &ok);
1275  if(!ok)
1276  {
1277  reader->raiseError(tr("invalid x end value"));
1278  return false;
1279  }
1280  setXEnd(val);
1281 
1282  val = reader->readAttributeInt("y_start", &ok);
1283  if(!ok)
1284  {
1285  reader->raiseError(tr("invalid y start value"));
1286  return false;
1287  }
1288  setYStart(val);
1289 
1290  val = reader->readAttributeInt("y_end", &ok);
1291  if(!ok)
1292  {
1293  reader->raiseError(tr("invalid y end value"));
1294  return false;
1295  }
1296  setYEnd(val);
1297  if (!reader->skipToEndElement()) return false;
1298 
1299  return true;
1300 }
1301 
1303 {
1304  Q_ASSERT(reader->isStartElement() && reader->name() == "formula");
1305  setFormula(reader->readElementText());
1306  return true;
1307 }
1308 
1310 {
1311  Q_ASSERT(reader->isStartElement() && reader->name() == "row_height");
1312  bool ok;
1313  int row = reader->readAttributeInt("row", &ok);
1314  if(!ok)
1315  {
1316  reader->raiseError(tr("invalid or missing row index"));
1317  return false;
1318  }
1319  QString str = reader->readElementText();
1320  int value = str.toInt(&ok);
1321  if(!ok)
1322  {
1323  reader->raiseError(tr("invalid row height"));
1324  return false;
1325  }
1326  if (d_view)
1327  d_view->setRowHeight(row, value);
1328  else
1329  setRowHeight(row, value);
1330  return true;
1331 }
1332 
1334 {
1335  Q_ASSERT(reader->isStartElement() && reader->name() == "column_width");
1336  bool ok;
1337  int col = reader->readAttributeInt("column", &ok);
1338  if(!ok)
1339  {
1340  reader->raiseError(tr("invalid or missing column index"));
1341  return false;
1342  }
1343  QString str = reader->readElementText();
1344  int value = str.toInt(&ok);
1345  if(!ok)
1346  {
1347  reader->raiseError(tr("invalid column width"));
1348  return false;
1349  }
1350  if (d_view)
1351  d_view->setColumnWidth(col, value);
1352  else
1353  setColumnWidth(col, value);
1354  return true;
1355 }
1356 
1358 {
1359  Q_ASSERT(reader->isStartElement() && reader->name() == "cell");
1360 
1361  QString str;
1362  int row, col;
1363  bool ok;
1364 
1365  QXmlStreamAttributes attribs = reader->attributes();
1366  row = reader->readAttributeInt("row", &ok);
1367  if(!ok)
1368  {
1369  reader->raiseError(tr("invalid or missing row index"));
1370  return false;
1371  }
1372  col = reader->readAttributeInt("column", &ok);
1373  if(!ok)
1374  {
1375  reader->raiseError(tr("invalid or missing column index"));
1376  return false;
1377  }
1378 
1379  str = reader->readElementText();
1380  double value = str.toDouble(&ok);
1381  if(!ok)
1382  {
1383  reader->raiseError(tr("invalid cell value"));
1384  return false;
1385  }
1386  setCell(row, col, value);
1387 
1388  return true;
1389 }
1390 
1391 void Matrix::setRowHeight(int row, int height)
1392 {
1393  d_matrix_private->setRowHeight(row, height);
1394 }
1395 
1396 void Matrix::setColumnWidth(int col, int width)
1397 {
1398  d_matrix_private->setColumnWidth(col, width);
1399 }
1400 
1401 int Matrix::rowHeight(int row) const
1402 {
1403  return d_matrix_private->rowHeight(row);
1404 }
1405 
1406 int Matrix::columnWidth(int col) const
1407 {
1408  return d_matrix_private->columnWidth(col);
1409 }
1410 
1411 void Matrix::adjustTabBarAction(bool visible)
1412 {
1413  if(visible)
1414  action_toggle_tabbar->setText(tr("Hide Controls"));
1415  else
1416  action_toggle_tabbar->setText(tr("Show Controls"));
1417 }
1418 
1419 QVector<qreal> Matrix::columnCells(int col, int first_row, int last_row)
1420 {
1421  return d_matrix_private->columnCells(col, first_row, last_row);
1422 }
1423 
1424 void Matrix::setColumnCells(int col, int first_row, int last_row, const QVector<qreal> & values)
1425 {
1426  WAIT_CURSOR;
1427  exec(new MatrixSetColumnCellsCmd(d_matrix_private, col, first_row, last_row, values));
1428  RESET_CURSOR;
1429 }
1430 
1431 QVector<qreal> Matrix::rowCells(int row, int first_column, int last_column)
1432 {
1433  return d_matrix_private->rowCells(row, first_column, last_column);
1434 }
1435 
1436 void Matrix::setRowCells(int row, int first_column, int last_column, const QVector<qreal> & values)
1437 {
1438  WAIT_CURSOR;
1439  exec(new MatrixSetRowCellsCmd(d_matrix_private, row, first_column, last_column, values));
1440  RESET_CURSOR;
1441 }
1442 
1444 {
1445  WAIT_CURSOR;
1447  RESET_CURSOR;
1448 }
1449 
1451 {
1452  WAIT_CURSOR;
1454  RESET_CURSOR;
1455 }
1456 
1458 {
1459  WAIT_CURSOR;
1461  RESET_CURSOR;
1462 }
1463 
1464 void Matrix::recalculateSelectedCells()
1465 {
1466  if (!d_view) return;
1467 #ifdef LEGACY_CODE_0_2_x
1468  WAIT_CURSOR;
1469  beginMacro(tr("%1: apply formula to selection").arg(name()));
1470  emit recalculate();
1471  endMacro();
1472  RESET_CURSOR;
1473 #endif
1474 }
1475 
1476 
1477 /* ========================= static methods ======================= */
1479 
1481 {
1482  if (!action_manager)
1484 
1485  return action_manager;
1486 }
1487 
1489 {
1490  if (!action_manager)
1491  action_manager = new ActionManager();
1492 
1493  action_manager->setTitle(tr("Matrix"));
1494  volatile Matrix * action_creator = new Matrix(); // initialize the action texts
1495  delete action_creator;
1496 }
1497 
1498 Matrix * Matrix::fromImage(const QImage & image)
1499 {
1500  int cols = image.width();
1501  int rows = image.height();
1502 
1503  QProgressDialog progress;
1504  progress.setRange(0, cols);
1505  progress.setWindowTitle(tr("SciDAVis") + " - " + tr("Import image..."));
1506  progress.raise();
1507 
1508  Matrix * matrix = new Matrix(0, rows, cols, tr("Matrix %1").arg(1));
1509 
1510  QVector<qreal> values;
1511  values.resize(rows);
1512 
1513  for (int i=0; i<cols; i++)
1514  {
1515  for (int j=0; j<rows; j++)
1516  values[j] = qGray(image.pixel(i, rows - 1 - j));
1517 
1518  matrix->setColumnCells(i, 0, rows-1, values);
1519 
1520  if (i%5 == 4)
1521  {
1522  progress.setValue(i);
1523  QApplication::processEvents();
1524  }
1525 
1526  if (progress.wasCanceled())
1527  break;
1528  }
1529 
1530  if (progress.wasCanceled())
1531  {
1532  delete matrix;
1533  return NULL;
1534  }
1535  return matrix;
1536 }
1537 
1538 /* ========================== Matrix::Private ====================== */
1539 
1541  : d_owner(owner), d_column_count(0), d_row_count(0)
1542 {
1543  d_block_change_signals = false;
1544  d_numeric_format = 'f';
1545  d_displayed_digits = 6;
1546  d_x_start = 0.0;
1547  d_x_end = 1.0;
1548  d_y_start = 0.0;
1549  d_y_end = 1.0;
1550 }
1551 
1552 void Matrix::Private::insertColumns(int before, int count)
1553 {
1554  Q_ASSERT(before >= 0);
1555  Q_ASSERT(before <= d_column_count);
1556 
1557  emit d_owner->columnsAboutToBeInserted(before, count);
1558  for(int i=0; i<count; i++)
1559  {
1560  d_data.insert(before+i, QVector<qreal>(d_row_count));
1561  d_column_widths.insert(before+i, Matrix::defaultColumnWidth());
1562  }
1563 
1564  d_column_count += count;
1565  emit d_owner->columnsInserted(before, count);
1566 }
1567 
1568 void Matrix::Private::removeColumns(int first, int count)
1569 {
1570  emit d_owner->columnsAboutToBeRemoved(first, count);
1571  Q_ASSERT(first >= 0);
1572  Q_ASSERT(first+count <= d_column_count);
1573  d_data.remove(first, count);
1574  for (int i=0; i<count; i++)
1575  d_column_widths.removeAt(first);
1576  d_column_count -= count;
1577  emit d_owner->columnsRemoved(first, count);
1578 }
1579 
1580 void Matrix::Private::insertRows(int before, int count)
1581 {
1582  emit d_owner->rowsAboutToBeInserted(before, count);
1583  Q_ASSERT(before >= 0);
1584  Q_ASSERT(before <= d_row_count);
1585  for(int col=0; col<d_column_count; col++)
1586  for(int i=0; i<count; i++)
1587  d_data[col].insert(before+i, 0.0);
1588  for(int i=0; i<count; i++)
1589  d_row_heights.insert(before+i, Matrix::defaultRowHeight());
1590 
1591  d_row_count += count;
1592  emit d_owner->rowsInserted(before, count);
1593 }
1594 
1595 void Matrix::Private::removeRows(int first, int count)
1596 {
1597  emit d_owner->rowsAboutToBeRemoved(first, count);
1598  Q_ASSERT(first >= 0);
1599  Q_ASSERT(first+count <= d_row_count);
1600  for(int col=0; col<d_column_count; col++)
1601  d_data[col].remove(first, count);
1602  for (int i=0; i<count; i++)
1603  d_row_heights.removeAt(first);
1604 
1605  d_row_count -= count;
1606  emit d_owner->rowsRemoved(first, count);
1607 }
1608 
1609 double Matrix::Private::cell(int row, int col) const
1610 {
1611  Q_ASSERT(row >= 0 && row < d_row_count);
1612  Q_ASSERT(col >= 0 && col < d_column_count);
1613  return d_data.at(col).at(row);
1614 }
1615 
1616 void Matrix::Private::setCell(int row, int col, double value)
1617 {
1618  Q_ASSERT(row >= 0 && row < d_row_count);
1619  Q_ASSERT(col >= 0 && col < d_column_count);
1620  d_data[col][row] = value;
1621  if (!d_block_change_signals)
1622  emit d_owner->dataChanged(row, col, row, col);
1623 }
1624 
1625 void Matrix::Private::setCells(const QVector<qreal>& data)
1626 {
1627  if (rowCount()*columnCount() != data.size()) return;
1628  int k=0;
1629  for (int i=0; i<columnCount(); i++) {
1630  for (int j=0; j<rowCount(); j++) {
1631  d_data[i][j]=data[k++];
1632  }
1633  }
1634 }
1635 
1636 QVector<qreal> Matrix::Private::columnCells(int col, int first_row, int last_row)
1637 {
1638  Q_ASSERT(first_row >= 0 && first_row < d_row_count);
1639  Q_ASSERT(last_row >= 0 && last_row < d_row_count);
1640 
1641  if(first_row == 0 && last_row == d_row_count-1)
1642  return d_data.at(col);
1643 
1644  QVector<qreal> result;
1645  for(int i=first_row; i<=last_row; i++)
1646  result.append(d_data.at(col).at(i));
1647  return result;
1648 }
1649 
1650 void Matrix::Private::setColumnCells(int col, int first_row, int last_row, const QVector<qreal> & values)
1651 {
1652  Q_ASSERT(first_row >= 0 && first_row < d_row_count);
1653  Q_ASSERT(last_row >= 0 && last_row < d_row_count);
1654  Q_ASSERT(values.count() > last_row - first_row);
1655 
1656  if(first_row == 0 && last_row == d_row_count-1)
1657  {
1658  d_data[col] = values;
1659  d_data[col].resize(d_row_count); // values may be larger
1660  if (!d_block_change_signals)
1661  emit d_owner->dataChanged(first_row, col, last_row, col);
1662  return;
1663  }
1664 
1665  for(int i=first_row; i<=last_row; i++)
1666  d_data[col][i] = values.at(i-first_row);
1667  if (!d_block_change_signals)
1668  emit d_owner->dataChanged(first_row, col, last_row, col);
1669 }
1670 
1671 QVector<qreal> Matrix::Private::rowCells(int row, int first_column, int last_column)
1672 {
1673  Q_ASSERT(first_column >= 0 && first_column < d_column_count);
1674  Q_ASSERT(last_column >= 0 && last_column < d_column_count);
1675 
1676  QVector<qreal> result;
1677  for(int i=first_column; i<=last_column; i++)
1678  result.append(d_data.at(i).at(row));
1679  return result;
1680 }
1681 
1682 void Matrix::Private::setRowCells(int row, int first_column, int last_column, const QVector<qreal> & values)
1683 {
1684  Q_ASSERT(first_column >= 0 && first_column < d_column_count);
1685  Q_ASSERT(last_column >= 0 && last_column < d_column_count);
1686  Q_ASSERT(values.count() > last_column - first_column);
1687 
1688  for(int i=first_column; i<=last_column; i++)
1689  d_data[i][row] = values.at(i-first_column);
1690  if (!d_block_change_signals)
1691  emit d_owner->dataChanged(row, first_column, row, last_column);
1692 }
1693 
1695 {
1696  d_data[col].fill(0.0);
1697  if (!d_block_change_signals)
1698  emit d_owner->dataChanged(0, col, d_row_count-1, col);
1699 }
1700 
1702 {
1703  return d_x_start;
1704 }
1705 
1707 {
1708  return d_y_start;
1709 }
1710 
1712 {
1713  return d_x_end;
1714 }
1715 
1717 {
1718  return d_y_end;
1719 }
1720 
1722 {
1723  d_x_start = x;
1724  emit d_owner->coordinatesChanged();
1725 }
1726 
1728 {
1729  d_x_end = x;
1730  emit d_owner->coordinatesChanged();
1731 }
1732 
1734 {
1735  d_y_start = y;
1736  emit d_owner->coordinatesChanged();
1737 }
1738 
1740 {
1741  d_y_end = y;
1742  emit d_owner->coordinatesChanged();
1743 }
1744 
1746 {
1747  return d_formula;
1748 }
1749 
1751 {
1752  d_formula = formula;
1753  emit d_owner->formulaChanged();
1754 }
1755 
1756 } // namespace
future::Matrix::Private::clearColumn
void clearColumn(int col)
Fill column with zeroes.
Definition: future_Matrix.cpp:1694
future::Matrix::yEnd
double yEnd() const
Definition: future_Matrix.cpp:1090
future::Matrix::action_clear_columns
QAction * action_clear_columns
Definition: future_Matrix.h:339
future::Matrix::columnCount
int columnCount() const
Return the total number of columns.
Definition: future_Matrix.cpp:179
future::Matrix::action_transpose
QAction * action_transpose
Definition: future_Matrix.h:331
future::Matrix::addColumns
void addColumns()
Append as many columns as are selected.
Definition: future_Matrix.cpp:1013
MatrixInsertRowsCmd
Insert rows.
Definition: matrixcommands.h:67
future::Matrix::editCoordinates
void editCoordinates()
Definition: future_Matrix.cpp:990
future::Matrix::Private::setXEnd
void setXEnd(double x)
Definition: future_Matrix.cpp:1727
future::Matrix::goToCell
void goToCell()
Definition: future_Matrix.cpp:850
future
Definition: AbstractAspect.h:43
future::Matrix::save
virtual void save(QXmlStreamWriter *) const
Save as XML.
Definition: future_Matrix.cpp:1117
AbstractAspect::writeCommentElement
void writeCommentElement(QXmlStreamWriter *writer) const
Save the comment to XML.
Definition: AbstractAspect.cpp:52
future::Matrix::Private::insertColumns
void insertColumns(int before, int count)
Insert columns before column number 'before'.
Definition: future_Matrix.cpp:1552
MatrixView
View class for Matrix.
Definition: MatrixView.h:83
future::Matrix::Private::setColumnWidth
void setColumnWidth(int col, int width)
Definition: future_Matrix.h:437
future::Matrix::clearSelectedRows
void clearSelectedRows()
Definition: future_Matrix.cpp:417
future::Matrix::transpose
void transpose()
Definition: future_Matrix.cpp:1443
future::Matrix::xStart
double xStart() const
Definition: future_Matrix.cpp:1075
future::Matrix::Private::d_block_change_signals
bool d_block_change_signals
Definition: future_Matrix.h:480
future::Matrix::duplicate
void duplicate()
Duplicate the matrix inside its folder.
Definition: future_Matrix.cpp:974
matrixcommands.h
future::Matrix::action_insert_columns
QAction * action_insert_columns
Definition: future_Matrix.h:337
future_Folder.h
future::Matrix::Private::rowHeight
int rowHeight(int row) const
Definition: future_Matrix.h:438
future::Matrix::Private::columnCount
int columnCount() const
Return the number of columns in the table.
Definition: future_Matrix.h:402
future::Matrix::Private::setRowCells
void setRowCells(int row, int first_column, int last_column, const QVector< qreal > &values)
Set the values in the given cells from a double vector.
Definition: future_Matrix.cpp:1682
future::Matrix::Private::xStart
double xStart() const
Definition: future_Matrix.cpp:1701
future::Matrix::readFormulaElement
bool readFormulaElement(XmlStreamReader *reader)
Read XML formula element.
Definition: future_Matrix.cpp:1302
AbstractAspect::exec
void exec(QUndoCommand *command)
Execute the given command, pushing it on the undoStack() if available.
Definition: AbstractAspect.cpp:203
XmlStreamReader::raiseError
void raiseError(const QString &message=QString())
Definition: XmlStreamReader.cpp:80
future::Matrix::appendColumns
void appendColumns(int count)
Definition: future_Matrix.h:131
AbstractAspect::global
static QVariant global(const QString &key)
Retrieve a global setting.
Definition: AbstractAspect.cpp:360
future::Matrix::default_column_width
static int default_column_width
Definition: future_Matrix.h:216
data
Definition: exp_saturation.c:37
XmlStreamReader::readAttributeInt
int readAttributeInt(const QString &name, bool *ok)
Read an XML attribute and convert it to int.
Definition: XmlStreamReader.cpp:110
str
#define str(x)
Definition: PythonScripting.cpp:41
future::Matrix::setCells
void setCells(const QVector< qreal > &data)
Set the value of all cells.
Definition: future_Matrix.cpp:923
XmlStreamReader
XML stream parser that supports errors as well as warnings.
Definition: XmlStreamReader.h:42
future::Matrix::action_toggle_tabbar
QAction * action_toggle_tabbar
Definition: future_Matrix.h:320
MatrixInsertColumnsCmd
Insert columns.
Definition: matrixcommands.h:41
AbstractAspect::setComment
void setComment(const QString &value)
Definition: AbstractAspect.cpp:265
future::Matrix::setNumericFormat
void setNumericFormat(char format)
Definition: future_Matrix.cpp:1059
future::Matrix::action_recalculate
QAction * action_recalculate
Definition: future_Matrix.h:328
MatrixSetRowCellsCmd
Set cell values for (a part of) a row at once.
Definition: matrixcommands.h:354
future::Matrix::Private::setYEnd
void setYEnd(double y)
Definition: future_Matrix.cpp:1739
future::Matrix::showMatrixViewContextMenu
void showMatrixViewContextMenu(const QPoint &pos)
Show a context menu for the selected cells.
Definition: future_Matrix.cpp:819
future::Matrix::setColumnCells
void setColumnCells(int col, int first_row, int last_row, const QVector< qreal > &values)
Set the values in the given cells from a double vector.
Definition: future_Matrix.cpp:1424
Matrix.h
future::Matrix::displayedDigits
int displayedDigits() const
Definition: future_Matrix.cpp:1112
future::Matrix::readCoordinatesElement
bool readCoordinatesElement(XmlStreamReader *reader)
Read XML coodinates element.
Definition: future_Matrix.cpp:1259
future::Matrix::Private::d_y_start
double d_y_start
Y value corresponding to row 1.
Definition: future_Matrix.h:478
future::Matrix::Private::rowCount
int rowCount() const
Return the number of rows in the table.
Definition: future_Matrix.h:404
future::Matrix::action_cut_selection
QAction * action_cut_selection
Definition: future_Matrix.h:313
future::Matrix::Private::setYStart
void setYStart(double y)
Definition: future_Matrix.cpp:1733
future::Matrix::Private::setXStart
void setXStart(double x)
Definition: future_Matrix.cpp:1721
future::Matrix::removeRows
void removeRows(int first, int count)
Definition: future_Matrix.cpp:140
future::Matrix::rowCells
QVector< qreal > rowCells(int row, int first_column, int last_column)
Return the values in the given cells as double vector.
Definition: future_Matrix.cpp:1431
future::Matrix::createRowMenu
QMenu * createRowMenu(QMenu *append_to=0)
Create a menu with row related operations.
Definition: future_Matrix.cpp:519
future::Matrix::copy
virtual void copy()
Copy current selection.
Definition: AbstractPart.h:79
future::Matrix::action_duplicate
QAction * action_duplicate
Definition: future_Matrix.h:330
future::Matrix::createActions
void createActions()
Definition: future_Matrix.cpp:535
future::Matrix::Private::yEnd
double yEnd() const
Definition: future_Matrix.cpp:1716
future::Matrix::action_insert_rows
QAction * action_insert_rows
Definition: future_Matrix.h:344
future::Matrix::pasteIntoSelection
void pasteIntoSelection()
Definition: future_Matrix.cpp:253
future::Matrix::action_edit_format
QAction * action_edit_format
Definition: future_Matrix.h:325
future::Matrix::action_edit_coordinates
QAction * action_edit_coordinates
Definition: future_Matrix.h:326
future::Matrix::action_clear_selection
QAction * action_clear_selection
Definition: future_Matrix.h:316
future::Matrix::Private::setRowHeight
void setRowHeight(int row, int height)
Definition: future_Matrix.h:436
future::Matrix::Private::d_x_start
double d_x_start
X value corresponding to column 1.
Definition: future_Matrix.h:476
future::Matrix::action_manager
static ActionManager * action_manager
Definition: future_Matrix.h:212
scripted
Interface for maintaining a reference to the current ScriptingEnv.
Definition: Script.h:149
future::Matrix::action_clear_rows
QAction * action_clear_rows
Definition: future_Matrix.h:346
future::Matrix::setRowCells
void setRowCells(int row, int first_column, int last_column, const QVector< qreal > &values)
Set the values in the given cells from a double vector.
Definition: future_Matrix.cpp:1436
future::Matrix::Matrix
Matrix()
Private ctor for initActionManager() only.
Definition: future_Matrix.cpp:80
future::Matrix::defaultColumnWidth
static int defaultColumnWidth()
Definition: future_Matrix.h:206
future::Matrix::Private::d_numeric_format
char d_numeric_format
Format code for displaying numbers.
Definition: future_Matrix.h:473
future::Matrix::fillProjectMenu
virtual bool fillProjectMenu(QMenu *menu)
Fill the part specific menu for the main window including setting the title.
Definition: future_Matrix.cpp:782
future::Matrix::selectAll
void selectAll()
Definition: future_Matrix.cpp:910
future::Matrix::Private::setFormula
void setFormula(const QString &formula)
Definition: future_Matrix.cpp:1750
future::Matrix::d_plot_menu
QMenu * d_plot_menu
Definition: future_Matrix.h:309
future::Matrix::connectActions
void connectActions()
Definition: future_Matrix.cpp:686
WAIT_CURSOR
#define WAIT_CURSOR
Definition: future_Matrix.cpp:55
future::Matrix::default_row_height
static int default_row_height
Definition: future_Matrix.h:217
future::Matrix::setXEnd
void setXEnd(double x)
Definition: future_Matrix.cpp:1031
future::Matrix::setYStart
void setYStart(double y)
Definition: future_Matrix.cpp:1038
future_Matrix.h
XmlStreamReader::skipToEndElement
bool skipToEndElement()
Go to the end element tag of the current element.
Definition: XmlStreamReader.cpp:121
future::Matrix::adjustTabBarAction
void adjustTabBarAction(bool visible)
Definition: future_Matrix.cpp:1411
future::Matrix::xEnd
double xEnd() const
Definition: future_Matrix.cpp:1085
future::Matrix::setColumnWidth
void setColumnWidth(int col, int width)
This method should only be called by the view.
Definition: future_Matrix.cpp:1396
MatrixSetFormulaCmd
Set matrix formula.
Definition: matrixcommands.h:301
future::Matrix::action_clear_matrix
QAction * action_clear_matrix
Definition: future_Matrix.h:322
future::Matrix::showMatrixViewColumnContextMenu
void showMatrixViewColumnContextMenu(const QPoint &pos)
Show a context menu for the selected columns.
Definition: future_Matrix.cpp:832
future::Matrix
Aspect providing a spreadsheet to manage MxN matrix data.
Definition: future_Matrix.h:60
future::Matrix::action_remove_rows
QAction * action_remove_rows
Definition: future_Matrix.h:345
future::Matrix::action_copy_selection
QAction * action_copy_selection
Definition: future_Matrix.h:314
AbstractAspect::endMacro
void endMacro()
End the undo stack macro.
Definition: AbstractAspect.cpp:222
MatrixClearCmd
Clear matrix.
Definition: matrixcommands.h:149
future::Matrix::createSelectionMenu
QMenu * createSelectionMenu(QMenu *append_to=0)
Create a menu with selection related operations.
Definition: future_Matrix.cpp:468
future::Matrix::action_add_rows
QAction * action_add_rows
Definition: future_Matrix.h:347
AbstractAspect::beginMacro
void beginMacro(const QString &text)
Begin an undo stack macro (series of commands)
Definition: AbstractAspect.cpp:215
future::Matrix::icon
virtual QIcon icon() const
Return an icon to be used for decorating my views.
Definition: future_Matrix.cpp:896
future::Matrix::view
virtual QWidget * view()
Construct a primary view on me.
Definition: future_Matrix.cpp:104
future::Matrix::setRowHeight
void setRowHeight(int row, int height)
This method should only be called by the view.
Definition: future_Matrix.cpp:1391
future::Matrix::setPlotMenu
void setPlotMenu(QMenu *menu)
Set a plot menu.
Definition: future_Matrix.cpp:891
future::Matrix::insertColumns
void insertColumns(int before, int count)
Definition: future_Matrix.cpp:120
future::Matrix::setCoordinates
void setCoordinates(double x1, double x2, double y1, double y2)
Definition: future_Matrix.cpp:1052
future::Matrix::editFormat
void editFormat()
Definition: future_Matrix.cpp:984
future::Matrix::Private::blockChangeSignals
void blockChangeSignals(bool block)
Enable/disable the emission of dataChanged signals.
Definition: future_Matrix.h:453
future::Matrix::rowCount
int rowCount() const
Return the total number of rows.
Definition: future_Matrix.cpp:184
future::Matrix::readRowHeightElement
bool readRowHeightElement(XmlStreamReader *reader)
Definition: future_Matrix.cpp:1309
future::Matrix::Private::cell
double cell(int row, int col) const
Return the value in the given cell.
Definition: future_Matrix.cpp:1609
future::Matrix::action_mirror_horizontally
QAction * action_mirror_horizontally
Definition: future_Matrix.h:333
future::Matrix::action_paste_into_selection
QAction * action_paste_into_selection
Definition: future_Matrix.h:315
future::Matrix::Private::insertRows
void insertRows(int before, int count)
Insert rows before row number 'before'.
Definition: future_Matrix.cpp:1580
future::Matrix::fromImage
static Matrix * fromImage(const QImage &image)
Definition: future_Matrix.cpp:1498
MatrixMirrorHorizontallyCmd
Mirror the matrix horizontally.
Definition: matrixcommands.h:408
future::Matrix::d_matrix_private
Private * d_matrix_private
Definition: future_Matrix.h:351
future::Matrix::action_import_image
QAction * action_import_image
Definition: future_Matrix.h:329
future::Matrix::columnWidth
int columnWidth(int col) const
Definition: future_Matrix.cpp:1406
AbstractAspect::name
QString name() const
Definition: AbstractAspect.cpp:229
future::Matrix::d_view
QPointer< MatrixView > d_view
Definition: future_Matrix.h:350
AbstractAspect::readBasicAttributes
bool readBasicAttributes(XmlStreamReader *reader)
Load name, creation time and caption spec from XML.
Definition: AbstractAspect.cpp:77
future::Matrix::Private::xEnd
double xEnd() const
Definition: future_Matrix.cpp:1711
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
future::Matrix::yStart
double yStart() const
Definition: future_Matrix.cpp:1080
future::Matrix::addRows
void addRows()
Append as many rows as are selected.
Definition: future_Matrix.cpp:1002
future::Matrix::Private::rowCells
QVector< qreal > rowCells(int row, int first_column, int last_column)
Return the values in the given cells as double vector.
Definition: future_Matrix.cpp:1671
future::Matrix::Private::numericFormat
char numericFormat() const
Definition: future_Matrix.h:420
future::Matrix::appendRows
void appendRows(int count)
Definition: future_Matrix.h:134
future::Matrix::dataChanged
void dataChanged(int top, int left, int bottom, int right)
future::Matrix::Private::formula
QString formula() const
Definition: future_Matrix.cpp:1745
XmlStreamReader.h
future::Matrix::load
virtual bool load(XmlStreamReader *)
Load from XML.
Definition: future_Matrix.cpp:1167
future::Matrix::Private::Private
Private(Matrix *owner)
Definition: future_Matrix.cpp:1540
MatrixSetFormatCmd
Set numeric format.
Definition: matrixcommands.h:259
MatrixTransposeCmd
Transpose the matrix.
Definition: matrixcommands.h:386
future::Matrix::Private::setCell
void setCell(int row, int col, double value)
Set the value in the given cell.
Definition: future_Matrix.cpp:1616
future::Matrix::clear
void clear()
Clear the whole matrix (i.e. set all cells to 0.0)
Definition: future_Matrix.cpp:189
future::Matrix::formula
QString formula() const
Definition: future_Matrix.cpp:1095
ActionManager.h
AbstractAspect::writeBasicAttributes
void writeBasicAttributes(QXmlStreamWriter *writer) const
Save name, creation time and caption spec to XML.
Definition: AbstractAspect.cpp:70
AbstractAspect::folder
future::Folder * folder()
Return the folder the Aspect is contained in or 0 if not.
Definition: AbstractAspect.cpp:316
future::Matrix::Private::removeColumns
void removeColumns(int first, int count)
Remove Columns.
Definition: future_Matrix.cpp:1568
future::Matrix::Private::d_x_end
double d_x_end
X value corresponding to the last column.
Definition: future_Matrix.h:477
MatrixSetCoordinatesCmd
Set matrix coordinates.
Definition: matrixcommands.h:229
future::Matrix::mirrorHorizontally
void mirrorHorizontally()
Definition: future_Matrix.cpp:1450
future::Matrix::insertEmptyColumns
void insertEmptyColumns()
Insert columns depending on the selection.
Definition: future_Matrix.cpp:324
future::Matrix::Private::setCells
void setCells(const QVector< qreal > &data)
Set the value of all cells.
Definition: future_Matrix.cpp:1625
RESET_CURSOR
#define RESET_CURSOR
Definition: future_Matrix.cpp:56
future::Matrix::Private
friend class Private
Definition: future_Matrix.h:64
future::Matrix::createContextMenu
virtual QMenu * createContextMenu() const
Return a new context menu.
Definition: future_Matrix.cpp:456
name
char * name()
Definition: exp_saturation.c:45
MatrixMirrorVerticallyCmd
Mirror the matrix vertically.
Definition: matrixcommands.h:430
MatrixSetDigitsCmd
Set displayed digits.
Definition: matrixcommands.h:280
future::Matrix::cutSelection
void cutSelection()
Definition: future_Matrix.cpp:205
future::Matrix::editFormula
void editFormula()
Definition: future_Matrix.cpp:996
future::Matrix::action_go_to_cell
QAction * action_go_to_cell
Definition: future_Matrix.h:323
future::Matrix::~Matrix
~Matrix()
Definition: future_Matrix.cpp:91
future::Matrix::initActionManager
static void initActionManager()
Definition: future_Matrix.cpp:1488
future::Matrix::Private::d_displayed_digits
int d_displayed_digits
Number of significant digits.
Definition: future_Matrix.h:475
future::Matrix::setDisplayedDigits
void setDisplayedDigits(int digits)
Definition: future_Matrix.cpp:1067
AbstractAspect::addChild
void addChild(AbstractAspect *child)
Add the given Aspect to my list of children.
Definition: AbstractAspect.cpp:114
MatrixRemoveColumnsCmd
Remove columns.
Definition: matrixcommands.h:93
MatrixSetColumnCellsCmd
Set cell values for (a part of) a column at once.
Definition: matrixcommands.h:322
future::Matrix::action_mirror_vertically
QAction * action_mirror_vertically
Definition: future_Matrix.h:332
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
MatrixSetCellValueCmd
Set cell value.
Definition: matrixcommands.h:199
ActionManager
Manages QActions and their shortcuts.
Definition: ActionManager.h:84
AbstractPart::createContextMenu
virtual QMenu * createContextMenu() const
Return AbstractAspect::createContextMenu() plus operations on the primary view.
Definition: AbstractPart.cpp:42
AbstractAspect::setGlobal
static void setGlobal(const QString &key, const QVariant &value)
Update a global setting.
Definition: AbstractAspect.cpp:370
future::Matrix::clearSelectedCells
void clearSelectedCells()
Definition: future_Matrix.cpp:436
MatrixRemoveRowsCmd
Remove rows.
Definition: matrixcommands.h:121
future::Matrix::importImageDialog
void importImageDialog()
Definition: future_Matrix.cpp:943
future::Matrix::Private::displayedDigits
int displayedDigits() const
Definition: future_Matrix.h:422
future::Matrix::numericFormat
char numericFormat() const
Definition: future_Matrix.cpp:1107
future::Matrix::action_set_formula
QAction * action_set_formula
Definition: future_Matrix.h:327
MatrixClearColumnCmd
Clear matrix column.
Definition: matrixcommands.h:173
future::Matrix::readDisplayElement
bool readDisplayElement(XmlStreamReader *reader)
Read XML display element.
Definition: future_Matrix.cpp:1233
future::Matrix::dimensionsDialog
void dimensionsDialog()
Definition: future_Matrix.cpp:928
future::Matrix::readCellElement
bool readCellElement(XmlStreamReader *reader)
Read XML cell element.
Definition: future_Matrix.cpp:1357
future::Matrix::createColumnMenu
QMenu * createColumnMenu(QMenu *append_to=0)
Create a menu with column related operations.
Definition: future_Matrix.cpp:483
XmlStreamReader::raiseWarning
void raiseWarning(const QString &message=QString())
Definition: XmlStreamReader.cpp:86
future::Matrix::actionManager
static ActionManager * actionManager()
Definition: future_Matrix.cpp:1480
future::Matrix::copySelection
void copySelection()
Definition: future_Matrix.cpp:219
future::Matrix::clearSelectedColumns
void clearSelectedColumns()
Definition: future_Matrix.cpp:364
future::Matrix::addActionsToView
void addActionsToView()
Definition: future_Matrix.cpp:717
future::Matrix::action_remove_columns
QAction * action_remove_columns
Definition: future_Matrix.h:338
future::Matrix::text
QString text(int row, int col)
Return the text displayed in the given cell.
Definition: future_Matrix.cpp:905
future::Matrix::Private::columnWidth
int columnWidth(int col) const
Definition: future_Matrix.h:439
future::Matrix::removeSelectedColumns
void removeSelectedColumns()
Definition: future_Matrix.cpp:349
future::Matrix::removeSelectedRows
void removeSelectedRows()
Definition: future_Matrix.cpp:402
future::Matrix::action_add_columns
QAction * action_add_columns
Definition: future_Matrix.h:340
future::Matrix::translateActionsStrings
void translateActionsStrings()
Definition: future_Matrix.cpp:751
future::Matrix::showMatrixViewRowContextMenu
void showMatrixViewRowContextMenu(const QPoint &pos)
Show a context menu for the selected rows.
Definition: future_Matrix.cpp:841
future::Matrix::createMatrixMenu
QMenu * createMatrixMenu(QMenu *append_to=0)
Create a menu with table related operations.
Definition: future_Matrix.cpp:498
future::Matrix::action_select_all
QAction * action_select_all
Definition: future_Matrix.h:321
future::Matrix::defaultRowHeight
static int defaultRowHeight()
Definition: future_Matrix.h:207
future::Matrix::Private::d_y_end
double d_y_end
Y value corresponding to the last row.
Definition: future_Matrix.h:479
future::Matrix::setYEnd
void setYEnd(double y)
Definition: future_Matrix.cpp:1045
future::Matrix::removeColumns
void removeColumns(int first, int count)
Definition: future_Matrix.cpp:130
future::Matrix::Private::columnCells
QVector< qreal > columnCells(int col, int first_row, int last_row)
Return the values in the given cells as double vector.
Definition: future_Matrix.cpp:1636
future::Matrix::rowHeight
int rowHeight(int row) const
Definition: future_Matrix.cpp:1401
future::Matrix::Private::removeRows
void removeRows(int first, int count)
Remove Columns.
Definition: future_Matrix.cpp:1595
future::Matrix::setDimensions
void setDimensions(int rows, int cols)
Set the number of rows and columns.
Definition: future_Matrix.cpp:160
future::Matrix::cell
double cell(int row, int col) const
Return the value in the given cell.
Definition: future_Matrix.cpp:198
future::Matrix::readColumnWidthElement
bool readColumnWidthElement(XmlStreamReader *reader)
Definition: future_Matrix.cpp:1333
AbstractAspect::readCommentElement
bool readCommentElement(XmlStreamReader *reader)
Load comment from an XML element.
Definition: AbstractAspect.cpp:61
future::Matrix::copy
void copy(Matrix *other)
Definition: future_Matrix.cpp:866
future::Matrix::Private::yStart
double yStart() const
Definition: future_Matrix.cpp:1706
future::Matrix::action_dimensions_dialog
QAction * action_dimensions_dialog
Definition: future_Matrix.h:324
ActionManager::addAction
void addAction(QAction *action, const QString &internal_name)
Definition: ActionManager.cpp:44
future::Matrix::mirrorVertically
void mirrorVertically()
Definition: future_Matrix.cpp:1457
future::Matrix::Private::setColumnCells
void setColumnCells(int col, int first_row, int last_row, const QVector< qreal > &values)
Set the values in the given cells from a double vector.
Definition: future_Matrix.cpp:1650
future::Matrix::columnCells
QVector< qreal > columnCells(int col, int first_row, int last_row)
Return the values in the given cells as double vector.
Definition: future_Matrix.cpp:1419
future::Matrix::setXStart
void setXStart(double x)
Definition: future_Matrix.cpp:1024
future::Matrix::insertRows
void insertRows(int before, int count)
Definition: future_Matrix.cpp:150
AbstractPart
Base class of Aspects with MDI windows as views.
Definition: AbstractPart.h:44