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)  

Table.cpp
Go to the documentation of this file.
1 
13 
31 #include "Table.h"
32 #include "core/column/Column.h"
33 #include "lib/Interval.h"
34 #include "table/TableModel.h"
39 #include "ScriptEdit.h"
40 
41 #include <QMessageBox>
42 #include <QDateTime>
43 #include <QTextStream>
44 #include <QTextCodec>
45 #include <QClipboard>
46 #include <QApplication>
47 #include <QPainter>
48 #include <QEvent>
49 #include <QCloseEvent>
50 #include <QLayout>
51 #include <QPrintDialog>
52 #include <QLocale>
53 #include <QShortcut>
54 #include <QProgressDialog>
55 #include <QFile>
56 #include <QTemporaryFile>
57 #include <vector>
58 #include <iostream>
59 using namespace std;
60 
61 Table::Table(ScriptingEnv *env, const QString &fname,const QString &sep, int ignoredLines, bool renameCols,
62  bool stripSpaces, bool simplifySpaces, bool convertToNumeric, QLocale numericLocale, const QString& label,
63  QWidget* parent, const char* name, Qt::WindowFlags f)
64  : TableView(label, parent, name,f), scripted(env)
65 {
66 
68  filter.set_ignored_lines(ignoredLines);
69  filter.set_separator(sep);
70  filter.set_first_row_names_columns(renameCols);
71  filter.set_trim_whitespace(stripSpaces);
72  filter.set_simplify_whitespace(simplifySpaces);
73  filter.set_convert_to_numeric(convertToNumeric);
74  filter.set_numeric_locale(numericLocale);
75 
76  QFile file(fname);
77  if ( file.open(QIODevice::ReadOnly) )
78  {
79  d_future_table = static_cast<future::Table *>(filter.importAspect(file));
80  if (!d_future_table)
81  d_future_table = new future::Table(0, 0, label);
82  else
83  d_future_table->setName(label);
84  }
85  setWindowLabel(fname);
86  init();
87 }
88 
89 Table::Table(ScriptingEnv *env, int r, int c, const QString& label, QWidget* parent, const char* name, Qt::WindowFlags f)
90  : TableView(label, parent, name,f), scripted(env)
91 {
92  d_future_table = new future::Table(r, c, label);
93  init();
94 }
95 
97 {
98  TableView::setTable(d_future_table);
99 
100  if (d_future_table)
101  {
102  d_future_table->setView(this);
103  birthdate = d_future_table->creationTime().toString(Qt::LocalDate);
104  }
105 
106  ui.gridLayout1->removeWidget(ui.formula_box);
107  delete ui.formula_box;
108  ui.formula_box = new ScriptEdit(scriptEnv, ui.formula_tab);
109  ui.formula_box->setObjectName(QString::fromUtf8("formula_box"));
110  ui.formula_box->setMinimumSize(QSize(60, 10));
111  ui.formula_box->setAcceptRichText(false);
112  ui.formula_box->setLineWrapMode(QTextEdit::WidgetWidth);
113  ui.gridLayout1->addWidget(ui.formula_box, 1, 0, 1, 3);
114 
115 
116  for (int i=0; i<columnCount(); i++)
117  ui.add_reference_combobox->addItem("col(\""+column(i)->name()+"\")");
118 
119  ui.add_function_combobox->addItems(scriptEnv->mathFunctions());
121 
122  connect(ui.add_function_combobox, SIGNAL(currentIndexChanged(int)),
123  this, SLOT(updateFunctionDoc()));
124  connect(ui.set_formula_button, SIGNAL(pressed()),
125  this, SLOT(applyFormula()));
126  connect(ui.add_function_button, SIGNAL(pressed()),
127  this, SLOT(addFunction()));
128  connect(ui.add_reference_button, SIGNAL(pressed()),
129  this, SLOT(addReference()));
130 
131  connect(d_future_table, SIGNAL(columnsAboutToBeRemoved(int, int)), this, SLOT(handleColumnsAboutToBeRemoved(int, int)));
132  connect(d_future_table, SIGNAL(columnsRemoved(int, int)), this, SLOT(handleColumnsRemoved(int, int)));
133  connect(d_future_table, SIGNAL(rowsInserted(int, int)), this, SLOT(handleRowChange()));
134  connect(d_future_table, SIGNAL(rowsRemoved(int, int)), this, SLOT(handleRowChange()));
135  connect(d_future_table, SIGNAL(dataChanged(int, int, int, int)), this, SLOT(handleColumnChange(int, int, int, int)));
136  connect(d_future_table, SIGNAL(columnsReplaced(int, int)), this, SLOT(handleColumnChange(int, int)));
137 
138  connect(d_future_table, SIGNAL(columnsInserted(int, int)), this, SLOT(handleChange()));
139  connect(d_future_table, SIGNAL(columnsReplaced(int, int)), this, SLOT(handleChange()));
140  connect(d_future_table, SIGNAL(columnsRemoved(int, int)), this, SLOT(handleChange()));
141  connect(d_future_table, SIGNAL(rowsInserted(int, int)), this, SLOT(handleChange()));
142  connect(d_future_table, SIGNAL(rowsRemoved(int, int)), this, SLOT(handleChange()));
143  connect(d_future_table, SIGNAL(dataChanged(int, int, int, int)), this, SLOT(handleChange()));
144  connect(d_future_table, SIGNAL(headerDataChanged(Qt::Orientation, int, int)), this, SLOT(handleChange()));
145  connect(d_future_table, SIGNAL(recalculate()), this, SLOT(recalculate()));
146 
147  connect(d_future_table, SIGNAL(aspectDescriptionChanged(const AbstractAspect*)),
148  this, SLOT(handleAspectDescriptionChange(const AbstractAspect *)));
149  connect(d_future_table, SIGNAL(aspectDescriptionAboutToChange(const AbstractAspect*)),
151 }
152 
154 {
155  emit modifiedWindow(this);
156 }
157 
158 void Table::handleColumnChange(int first, int count)
159 {
160  for (int i=first; i<first+count; i++)
161  emit modifiedData(this, colName(i));
162 }
163 
164 void Table::handleColumnChange(int top, int left, int bottom, int right)
165 {
166  Q_UNUSED(top);
167  Q_UNUSED(bottom);
168  handleColumnChange(left, right-left+1);
169 }
170 
171 void Table::handleColumnsAboutToBeRemoved(int first, int count)
172 {
173  for (int i=first; i<first+count; i++)
174  emit aboutToRemoveCol(colName(i));
175 }
176 
177 void Table::handleColumnsRemoved(int first, int count)
178 {
179  for (int i=first; i<first+count; i++)
180  emit removedCol(colName(i));
181 }
182 
184 {
185  for (int i=0; i<numCols(); i++)
186  emit modifiedData(this, colName(i));
187 }
188 
189 void Table::setBackgroundColor(const QColor& col)
190 {
191  QPalette palette;
192  palette.setColor(QPalette::Window, col);
193  d_view_widget->setPalette(palette);
194 }
195 
196 void Table::setTextColor(const QColor& col)
197 {
198  QPalette palette;
199  palette.setColor(QPalette::WindowText, col);
200  d_view_widget->setPalette(palette);
201 }
202 
203 void Table::setTextFont(const QFont& fnt)
204 {
205  d_view_widget->setFont(fnt);
206 }
207 
208 void Table::setHeaderColor(const QColor& col)
209 {
210  QPalette palette;
211  palette.setColor(QPalette::WindowText, col);
212  d_view_widget->horizontalHeader()->setPalette(palette);
213 }
214 
215 void Table::setHeaderFont(const QFont& fnt)
216 {
217  d_view_widget->horizontalHeader()->setFont(fnt);
218 }
219 
220 void Table::exportPDF(const QString& fileName)
221 {
222  print(fileName);
223 }
224 
226 {
227  print(QString());
228 }
229 
230 void Table::print(const QString& fileName)
231 {
232  QPrinter printer;
233  printer.setColorMode (QPrinter::GrayScale);
234 
235  if (!fileName.isEmpty())
236  {
237  printer.setCreator("SciDAVis");
238  printer.setOutputFormat(QPrinter::PdfFormat);
239  printer.setOutputFileName(fileName);
240  }
241  else
242  {
243  QPrintDialog printDialog(&printer);
244  if (printDialog.exec() != QDialog::Accepted)
245  return;
246  }
247 
248  printer.setFullPage( true );
249  QPainter p;
250  if ( !p.begin(&printer ) )
251  return; // paint on printer
252  int dpiy = printer.logicalDpiY();
253  const int margin = (int) ( (1/2.54)*dpiy ); // 1 cm margins
254 
255  QHeaderView *hHeader = d_view_widget->horizontalHeader();
256  QHeaderView *vHeader = d_view_widget->verticalHeader();
257 
258  int rows = numRows();
259  int cols = numCols();
260  int height = margin;
261  int i, vertHeaderWidth = vHeader->width();
262  int right = margin + vertHeaderWidth;
263 
264  // print header
265  p.setFont(hHeader->font());
266  QString header_label = d_view_widget->model()->headerData(0, Qt::Horizontal).toString();
267  QRect br = p.boundingRect(br, Qt::AlignCenter, header_label);
268  p.drawLine(right, height, right, height+br.height());
269  QRect tr(br);
270 
271  for (i=0;i<cols;i++)
272  {
273  int w = columnWidth(i);
274  tr.setTopLeft(QPoint(right,height));
275  tr.setWidth(w);
276  tr.setHeight(br.height());
277  header_label = d_view_widget->model()->headerData(i, Qt::Horizontal).toString();
278  p.drawText(tr, Qt::AlignCenter, header_label);
279  right += w;
280  p.drawLine(right, height, right, height+tr.height());
281 
282  if (right >= printer.width()-2*margin )
283  break;
284  }
285 
286  p.drawLine(margin + vertHeaderWidth, height, right-1, height);//first horizontal line
287  height += tr.height();
288  p.drawLine(margin, height, right-1, height);
289 
290  // print table values
291  for (i=0;i<rows;i++)
292  {
293  right = margin;
294  QString cell_text = d_view_widget->model()->headerData(i, Qt::Vertical).toString()+"\t";
295  tr = p.boundingRect(tr, Qt::AlignCenter, cell_text);
296  p.drawLine(right, height, right, height+tr.height());
297 
298  br.setTopLeft(QPoint(right,height));
299  br.setWidth(vertHeaderWidth);
300  br.setHeight(tr.height());
301  p.drawText(br, Qt::AlignCenter, cell_text);
302  right += vertHeaderWidth;
303  p.drawLine(right, height, right, height+tr.height());
304 
305  for(int j=0;j<cols;j++)
306  {
307  int w = columnWidth (j);
308  cell_text = text(i,j)+"\t";
309  tr = p.boundingRect(tr,Qt::AlignCenter,cell_text);
310  br.setTopLeft(QPoint(right,height));
311  br.setWidth(w);
312  br.setHeight(tr.height());
313  p.drawText(br, Qt::AlignCenter, cell_text);
314  right += w;
315  p.drawLine(right, height, right, height+tr.height());
316 
317  if (right >= printer.width()-2*margin )
318  break;
319  }
320  height += br.height();
321  p.drawLine(margin, height, right-1, height);
322 
323  if (height >= printer.height()-margin )
324  {
325  printer.newPage();
326  height = margin;
327  p.drawLine(margin, height, right, height);
328  }
329  }
330 }
331 
332 int Table::colX(int col)
333 {
334  return d_future_table? d_future_table->colX(col): 0;
335 }
336 
337 int Table::colY(int col)
338 {
339  return d_future_table? d_future_table->colY(col): 0;
340 }
341 
343 {
344  if (d_future_table)
345  d_future_table->setSelectionAs(pd);
346 }
347 
348 int Table::columnWidth(int col)
349 {
350  return d_future_table? d_view_widget->columnWidth(col): 0;
351 }
352 
353 void Table::setColWidths(const QStringList& widths)
354 {
355  for (int i=0;i<widths.count();i++)
356  d_view_widget->setColumnWidth(i, widths[i].toInt());
357 }
358 
359 void Table::setColumnTypes(const QStringList& ctl)
360 {
361 // TODO: obsolete, remove in 0.3.0
362  int n = qMin((int)ctl.count(), numCols());
363  for (int i=0; i<n; i++)
364  {
365  QStringList l = ctl[i].split(";");
366  switch (l[0].toInt())
367  {
368  // old enum: enum ColType{Numeric = 0, Text = 1, Date = 2, Time = 3, Month = 4, Day = 5};
369  case 0:
371  break;
372  case 1:
374  break;
375  case 2:
376  case 3:
377  case 6:
379  break;
380  case 4:
382  break;
383  case 5:
385  break;
386  }
387  }
388 }
389 
391 {
392 // TODO: obsolete, remove in 0.3.0
393  QString s="ColWidth\t";
394  for (int i=0;i<numCols();i++)
395  s+=QString::number(columnWidth(i))+"\t";
396 
397  return s+"\n";
398 }
399 
401 {
402 // TODO: obsolete, remove in 0.3.0
403  QString s="ColType";
404  for (int i=0; i<numCols(); i++)
405  s += "\t"+QString::number(column(i)->columnMode())+";0/6";
406  return s+"\n";
407 }
408 
409 void Table::setCommands(const QStringList& com)
410 {
411  for(int i=0; i<(int)com.size() && i<numCols(); i++)
412  column(i)->setFormula(Interval<int>(0, numRows()-1), com.at(i).trimmed());
413 }
414 
415 void Table::setCommand(int col, const QString& com)
416 {
417  column(col)->setFormula(Interval<int>(0, numRows()-1), com.trimmed());
418 }
419 
420 void Table::setCommands(const QString& com)
421 {
422  QStringList lst = com.split("\t");
423  lst.pop_front();
424  setCommands(lst);
425 }
426 
428 {
429  for (int col=firstSelectedColumn(); col<=lastSelectedColumn(); col++)
430  if (!recalculate(col, true))
431  return false;
432  return true;
433 }
434 
435 bool Table::recalculate(int col, bool only_selected_rows)
436 {
437  QApplication::setOverrideCursor(Qt::WaitCursor);
438  Column *col_ptr=column(col);
439  if (!col_ptr) return false;
440 
441  QList< Interval<int> > formula_intervals = col_ptr->formulaIntervals();
442  if (only_selected_rows) {
443  // remove non-selected rows from list of intervals
444  QList< Interval<int> > deselected = Interval<int>(0,col_ptr->rowCount()-1) - selectedRows().intervals();
445  foreach(Interval<int> i, deselected)
446  Interval<int>::subtractIntervalFromList(&formula_intervals, i);
447  }
448  foreach(Interval<int> interval, formula_intervals)
449  {
450  QString formula = col_ptr->formula(interval.start());
451  if (formula.isEmpty())
452  continue;
453 
454  Script *colscript = scriptEnv->newScript(formula, this, QString("<%1>").arg(colName(col)));
455  connect(colscript, SIGNAL(error(const QString&,const QString&,int)), scriptEnv, SIGNAL(error(const QString&,const QString&,int)));
456  connect(colscript, SIGNAL(print(const QString&)), scriptEnv, SIGNAL(print(const QString&)));
457 
458  if (!colscript->compile()) {
459  delete colscript;
460  QApplication::restoreOverrideCursor();
461  return false;
462  }
463 
464  colscript->setInt(col+1, "j");
465  QVariant ret;
466  int start_row = interval.start();
467  int end_row = interval.end();
468  switch (col_ptr->columnMode()) {
469  case SciDAVis::Numeric:
470  {
471  QVector<qreal> results(end_row-start_row+1);
472  for (int i=start_row; i<=end_row; i++) {
473  colscript->setInt(i+1,"i");
474  ret = colscript->eval();
475  if (!ret.isValid()) {
476  delete colscript;
477  QApplication::restoreOverrideCursor();
478  return false;
479  }
480  if (ret.canConvert(QVariant::Double))
481  results[i-start_row] = ret.toDouble();
482  else
483  results[i-start_row] = NAN;
484  }
485  col_ptr->replaceValues(start_row, results);
486  break;
487  }
488  default:
489  {
490  QStringList results;
491  for (int i=start_row; i<=end_row; i++) {
492  colscript->setInt(i+1,"i");
493  ret = colscript->eval();
494  if (!ret.isValid()) {
495  delete colscript;
496  QApplication::restoreOverrideCursor();
497  return false;
498  }
499  if (ret.type() == QVariant::Double)
500  results << QLocale().toString(ret.toDouble(), 'g', 14);
501  else if(ret.canConvert(QVariant::String))
502  results << ret.toString();
503  else
504  results << QString();
505  }
506  col_ptr->asStringColumn()->replaceTexts(start_row, results);
507  break;
508  }
509  }
510  delete colscript;
511  }
512  QApplication::restoreOverrideCursor();
513  return true;
514 }
515 
517 {
518 // TODO: obsolete, remove for 0.3.0, only needed for template saving
519  QString s="<com>\n";
520  for (int col=0; col<numCols(); col++)
521  if (!column(col)->formula(0).isEmpty())
522  {
523  s += "<col nr=\""+QString::number(col)+"\">\n";
524  s += column(col)->formula(0);
525  s += "\n</col>\n";
526  }
527  s += "</com>\n";
528  return s;
529 }
530 
532 {
533 // TODO: obsolete, remove for 0.3.0, only needed for template saving
534  QString s = "Comments\t";
535  for (int i=0; i<numCols(); i++)
536  {
537  s += column(i)->comment() + "\t";
538  }
539  return s + "\n";
540 }
541 
542 QString Table::saveToString(const QString& geometry)
543 {
544  QString s = "<table>\n";
545  QString xml;
546  if (d_future_table)
547  {
548  QXmlStreamWriter writer(&xml);
549  d_future_table->save(&writer);
550  }
551  s += QString::number(xml.length()) + "\n"; // this is need in case there are newlines in the XML
552  s += xml + "\n";
553  s += geometry + "\n";
554  s +="</table>\n";
555  return s;
556 }
557 
558 void Table::saveToDevice(QIODevice *device, const QString &geometry)
559 {
560  QTextStream stream(device);
561  stream.setCodec(QTextCodec::codecForName("UTF-8"));
562 
563  // write start tag
564  stream << "<table>\n";
565  stream.flush();
566 
567  // On Windows, writing to a QString has been observed to crash for large tables
568  // (apparently due to excessive memory usage).
569  // => use temporary file if possible
570  QTemporaryFile tmp_file;
571  QString tmp_string;
572  if (d_future_table)
573  {
574  QXmlStreamWriter xml(&tmp_string);
575  if (tmp_file.open())
576  xml.setDevice(&tmp_file);
577  d_future_table->save(&xml);
578  }
579 
580  // write number of characters of QXmlStreamWriter's output
581  // this is needed in case there are newlines in the XML
582  int xml_chars = 0;
583  if (tmp_file.isOpen()) {
584  tmp_file.seek(0);
585  QTextStream count(&tmp_file);
586  count.setCodec(QTextCodec::codecForName("UTF-8"));
587  while (!count.atEnd())
588  xml_chars += count.read(1024).length();
589  } else
590  xml_chars = tmp_string.length();
591  stream << xml_chars << "\n";
592  stream.flush();
593 
594  // Copy QXmlStreamWriter's output to device
595  if (tmp_file.isOpen()) {
596  tmp_file.seek(0);
597  qint64 bytes_read;
598  char buffer[1024];
599  while ((bytes_read = tmp_file.read(buffer, 1024)) > 0)
600  device->write(buffer, bytes_read);
601  } else
602  stream << tmp_string;
603  stream << "\n";
604 
605  // write geometry and end tag
606  stream << geometry << "\n";
607  stream << "</table>\n";
608 }
609 
611 {
612 // TODO: obsolete, remove for 0.3.0, only needed for template saving
613  QString s = "header";
614  for (int j=0; j<numCols(); j++)
615  {
616  switch (column(j)->plotDesignation())
617  {
618  case SciDAVis::X:
619  s += "\t" + colLabel(j) + "[X]";
620  break;
621  case SciDAVis::Y:
622  s += "\t" + colLabel(j) + "[Y]";
623  break;
624  case SciDAVis::Z:
625  s += "\t" + colLabel(j) + "[Z]";
626  break;
627  case SciDAVis::xErr:
628  s += "\t" + colLabel(j) + "[xEr]";
629  break;
630  case SciDAVis::yErr:
631  s += "\t" + colLabel(j) + "[yEr]";
632  break;
633  default:
634  s += "\t" + colLabel(j);
635  }
636  }
637  return s += "\n";
638 }
639 
641 {
642  for (int j=0; j<numCols(); j++)
643  {
644  if (column(j)->plotDesignation() == SciDAVis::X)
645  return j;
646  }
647  return -1;
648 }
649 
650 void Table::setColComment(int col, const QString& s)
651 {
652  column(col)->setComment(s);
653 }
654 
655 void Table::setColName(int col, const QString& text)
656 {
657  if (col < 0 || col >= numCols())
658  return;
659 
660  column(col)->setName(text);
661 }
662 
664 {
665 // TODO for 0.3.0: extended selection support, Column * lists
666  QStringList names;
667  for (int i=0; i<numCols(); i++)
668  {
669  if(isColumnSelected(i))
670  names << name() + "_" + column(i)->name();
671  }
672  return names;
673 }
674 
675 QStringList Table::YColumns()
676 {
677 // TODO for 0.3.0: Column * list
678  QStringList names;
679  for (int i=0;i<numCols();i++)
680  {
681  if(column(i)->plotDesignation() == SciDAVis::Y)
682  names << name() + "_" + column(i)->name();
683  }
684  return names;
685 }
686 
688 {
689 // TODO for 0.3.0: Column * list
690  QStringList names;
691  for (int i=0;i<numCols();i++)
692  {
694  names << name() + "_" + column(i)->name();
695  }
696  return names;
697 }
698 
700 {
701 // TODO for 0.3.0: Column * list
702  QStringList names;
703  for (int i=0;i<numCols();i++)
704  {
705  if (isColumnSelected(i) &&
708  names << name() + "_" + column(i)->name();
709  }
710  return names;
711 }
712 
714 {
715 // TODO for 0.3.0: Column * list
716  QStringList names;
717  for (int i=0; i<numCols(); i++)
718  {
720  names << name() + "_" + column(i)->name();
721  }
722 
723  for (int i=0; i<numCols(); i++)
724  {
725  if (isColumnSelected(i) &&
728  names << name() + "_" + column(i)->name();
729  }
730  return names;
731 }
732 
733 QMap<int, QString> Table::selectedYLabels()
734 {
735 // TODO for 0.3.0: Column * list
736  QMap<int, QString> names;
737  for (int i=0;i <numCols(); i++)
738  {
740  names.insert(i, column(i)->name());
741  }
742  return names;
743 }
744 
745 QStringList Table::columnsList()
746 {
747 // TODO for 0.3.0: Column * list
748  QStringList names;
749  for (int i=0; i<numCols(); i++)
750  names << name() +"_" + column(i)->name();
751 
752  return names;
753 }
754 
756 {
757  return selectedRowCount();
758 }
759 
761 {
762  return selectedColumnCount();
763 }
764 
765 QString Table::colName(int col)
766 {//returns the table name + horizontal header text
767  if (col<0 || col >= numCols())
768  return QString();
769 
770  return QString(name() + "_" + column(col)->name());
771 }
772 
773 void Table::insertCols(int start, int count)
774 {
775  if (d_future_table)
776  {
777  if (start < 0)
778  start = 0;
779 
780  QList<Column*> cols;
781  for(int i=0; i<count; i++)
782  cols << new Column(QString::number(i+1), SciDAVis::Numeric);
783  d_future_table->insertColumns(start, cols);
784  }
785 }
786 
788 {
789  if (d_future_table)
790  d_future_table->insertEmptyColumns();
791 }
792 
794 {
795  if (d_future_table)
796  d_future_table->insertEmptyRows();
797 }
798 
800 {
801  if (d_future_table)
802  {
803  d_future_table->addColumn();
804  column(d_future_table->columnCount()-1)->setColumnMode(SciDAVis::Numeric); // in case we ever change the default
805  column(d_future_table->columnCount()-1)->setPlotDesignation(pd);
806  }
807 }
808 
809 void Table::addColumns(int c)
810 {
811  if (d_future_table)
812  {
813  QList<Column*> cols;
814  for(int i=0; i<c; i++)
815  cols << new Column(QString::number(i+1), SciDAVis::Numeric);
816  d_future_table->appendColumns(cols);
817  }
818 }
819 
821 {
822  if (d_future_table)
823  d_future_table->clearSelectedColumns();
824 }
825 
826 void Table::clearCell(int row, int col)
827 {
828  column(col)->setTextAt(row, QString());
829  column(col)->setValueAt(row, 0.0);
830  column(col)->setDateTimeAt(row, QDateTime());
831  column(col)->setInvalid(row, true);
832 }
833 
835 {
836  if (d_future_table)
837  d_future_table->removeSelectedRows();
838 }
839 
841 {
842  if (d_future_table)
843  d_future_table->cutSelection();
844 }
845 
847 {
848  selectAll();
849 }
850 
852 {
853  d_view_widget->clearSelection();
854 }
855 
857 {
858  if (d_future_table)
859  d_future_table->clearSelectedCells();
860 }
861 
863 {
864  if (d_future_table)
865  d_future_table->copySelection();
866 }
867 
869 {
870  if (d_future_table)
871  d_future_table->pasteIntoSelection();
872 }
873 
875 {
876  if (d_future_table)
877  d_future_table->removeSelectedColumns();
878 }
879 
880 void Table::removeCol(const QStringList& list)
881 {
882  if (d_future_table)
883  foreach(QString name, list)
884  d_future_table->removeColumns(colIndex(name), 1);
885 }
886 
888 {
889  return d_future_table? d_future_table->rowCount():0;
890 }
891 
893 {
894  return d_future_table? d_future_table->columnCount():0;
895 }
896 
898 {
899  return d_future_table? d_future_table->rowCount():0;
900 }
901 
903 {
904  return d_future_table? d_future_table->columnCount():0;
905 }
906 
907 double Table::cell(int row, int col)
908 {
909  Column *colPtr = column(col);
910  if (!colPtr) return 0.0;
911  if (!colPtr->isInvalid(row)) {
912  if (colPtr->columnMode() == SciDAVis::Text) {
913  QString yval = colPtr->textAt(row);
914  bool valid_data = true;
915  double dbval = QLocale().toDouble(yval, &valid_data);
916  if (!valid_data)
917  return 0.0;
918  return dbval;
919  }
920  return colPtr->valueAt(row);
921  }
922  else
923  return 0.0;
924 }
925 
926 void Table::setCell(int row, int col, double val)
927 {
928  column(col)->setValueAt(row, val);
929 }
930 
931 QString Table::text(int row, int col)
932 {
933  Column *colPtr = column(col);
934  if (!colPtr) return QString();
935  return colPtr->asStringColumn()->textAt(row);
936 }
937 
938 void Table::setText(int row, int col, const QString & text)
939 {
940  column(col)->asStringColumn()->setTextAt(row, text);
941 }
942 
943 void Table::importV0x0001XXHeader(QStringList header)
944 {
945  if (!d_future_table) return;
946  QStringList col_label = QStringList();
947  QList<SciDAVis::PlotDesignation> col_plot_type = QList<SciDAVis::PlotDesignation>();
948  for (int i=0; i<header.count();i++)
949  {
950  if (header[i].isEmpty())
951  continue;
952 
953  QString s = header[i].replace("_","-");
954  if (s.contains("[X]"))
955  {
956  col_label << s.remove("[X]");
957  col_plot_type << SciDAVis::X;
958  }
959  else if (s.contains("[Y]"))
960  {
961  col_label << s.remove("[Y]");
962  col_plot_type << SciDAVis::Y;
963  }
964  else if (s.contains("[Z]"))
965  {
966  col_label << s.remove("[Z]");
967  col_plot_type << SciDAVis::Z;
968  }
969  else if (s.contains("[xEr]"))
970  {
971  col_label << s.remove("[xEr]");
972  col_plot_type << SciDAVis::xErr;
973  }
974  else if (s.contains("[yEr]"))
975  {
976  col_label << s.remove("[yEr]");
977  col_plot_type << SciDAVis::yErr;
978  }
979  else
980  {
981  col_label << s;
982  col_plot_type << SciDAVis::noDesignation;
983  }
984  }
985  QList<Column*> quarantine;
986  for (int i=0; i<col_label.count() && i<d_future_table->columnCount();i++)
987  quarantine << column(i);
988  int i = 0;
989  foreach(Column * col, quarantine) {
990  d_future_table->removeChild(col, true);
991  // setting column name while col is still part of table triggers renaming
992  // to prevent name clashes
993  col->setName(col_label.at(i));
994  col->setPlotDesignation(col_plot_type.at(i));
995  i++;
996  }
997  d_future_table->appendColumns(quarantine);
998 }
999 
1000 void Table::setHeader(QStringList header)
1001 {
1002  if (!d_future_table) return;
1003  QList<Column*> quarantine;
1004  for (int i=0; i<header.count() && i<d_future_table->columnCount();i++)
1005  quarantine << column(i);
1006  int i = 0;
1007  foreach(Column * col, quarantine) {
1008  d_future_table->removeChild(col, true);
1009  // setting column name while col is still part of table triggers renaming
1010  // to prevent name clashes
1011  col->setName(header.at(i));
1012  i++;
1013  }
1014  d_future_table->appendColumns(quarantine);
1015 }
1016 
1017 int Table::colIndex(const QString& name)
1018 {
1019  return d_future_table? d_future_table->columnIndex(column(name)):0;
1020 }
1021 
1023 {
1024  return d_future_table? d_future_table->columnCount(SciDAVis::X) == 0: true;
1025 }
1026 
1028 {
1029  return d_future_table? d_future_table->columnCount(SciDAVis::Y) == 0: true;
1030 }
1031 
1032 bool Table::exportASCII(const QString& fname, const QString& separator,
1033  bool withLabels, bool exportSelection)
1034 {
1035  QFile file(fname);
1036  if ( !file.open( QIODevice::WriteOnly ) )
1037  {
1038  QApplication::restoreOverrideCursor();
1039  QMessageBox::critical(0, tr("ASCII Export Error"),
1040  tr("Could not write to file: <br><h4>")+fname+tr("</h4><p>Please verify that you have the right to write to this location!"));
1041  return false;
1042  }
1043 
1044  QTextStream out( &file );
1045  int i,j;
1046  int rows = numRows();
1047  int cols = numCols();
1048  int selectedCols = 0;
1049  int topRow = 0, bottomRow = 0;
1050  vector<int> sCols;
1051  if (exportSelection)
1052  {
1053  for (i=0; i<cols; i++)
1054  {
1055  if (isColumnSelected(i))
1056  selectedCols++;
1057  }
1058 
1059  sCols.resize(selectedCols+1);
1060  int temp = 1;
1061  for (i=0; i<cols; i++)
1062  {
1063  if (isColumnSelected(i))
1064  {
1065  sCols[temp] = i;
1066  temp++;
1067  }
1068  }
1069 
1070  topRow = firstSelectedRow();
1071  bottomRow = lastSelectedRow();
1072  }
1073 
1074  if (withLabels)
1075  {
1076  QStringList header = colNames();
1077  QStringList ls = header.filter(QRegExp ("\\D"));
1078  if (exportSelection)
1079  {
1080  for (i=1; i<selectedCols; i++)
1081  {
1082  if (ls.count()>0)
1083  out << header[sCols[i]] + separator;
1084  else
1085  out << "C"+header[sCols[i]] + separator;
1086  }
1087 
1088  if (ls.count()>0)
1089  out << header[sCols[selectedCols]] + "\n";
1090  else
1091  out << "C" + header[sCols[selectedCols]] + "\n";
1092  }
1093  else
1094  {
1095  if (ls.count()>0)
1096  {
1097  for (j=0; j<cols-1; j++)
1098  out << header[j]+separator;
1099  out << header[cols-1]+"\n";
1100  }
1101  else
1102  {
1103  for (j=0; j<cols-1; j++)
1104  out << "C" + header[j] + separator;
1105  out << "C" + header[cols-1] + "\n";
1106  }
1107  }
1108  }// finished writting labels
1109 
1110  QList<Column*> col_ptrs;
1111  if (exportSelection) {
1112  for (j=1; j<=selectedCols; j++)
1113  col_ptrs << column(sCols[j]);
1114  } else {
1115  for (j=0;j<cols;j++)
1116  col_ptrs << column(j);
1117  topRow = 0;
1118  bottomRow = rows-1;
1119  }
1120 
1121  for (i=topRow; i<=bottomRow; i++) {
1122  bool first = true;
1123  foreach(Column *col, col_ptrs) {
1124  if (first)
1125  first = false;
1126  else
1127  out << separator;
1128  out << col->asStringColumn()->textAt(i);
1129  }
1130  out << "\n";
1131  }
1132 
1133  file.close();
1134  return true;
1135 }
1136 
1137 void Table::customEvent(QEvent *e)
1138 {
1139  if (e->type() == SCRIPTING_CHANGE_EVENT)
1141 }
1142 
1143 void Table::closeEvent( QCloseEvent *e )
1144 {
1145  if (askOnClose)
1146  {
1147  switch( QMessageBox::information(this,tr("SciDAVis"),
1148  tr("Do you want to hide or delete") + "<p><b>'" + objectName() + "'</b> ?",
1149  tr("Delete"), tr("Hide"), tr("Cancel"), 0,2))
1150  {
1151  case 0:
1152  e->accept();
1153  if (d_future_table)
1154  d_future_table->remove();
1155  return;
1156 
1157  case 1:
1158  e->ignore();
1159  emit hiddenWindow(this);
1160  break;
1161 
1162  case 2:
1163  e->ignore();
1164  break;
1165  }
1166  }
1167  else
1168  {
1169  e->accept();
1170  if (d_future_table)
1171  d_future_table->remove();
1172  return;
1173  }
1174 }
1175 
1176 
1177 void Table::setNumRows(int rows)
1178 {
1179  if (d_future_table)
1180  d_future_table->setRowCount(rows);
1181 }
1182 
1183 void Table::setNumCols(int cols)
1184 {
1185  if (d_future_table)
1186  d_future_table->setColumnCount(cols);
1187 }
1188 
1190 {
1191  if (!m || !d_future_table)
1192  return;
1193 
1194  d_future_table->copy(m->d_future_table);
1195 }
1196 
1197 QString Table::saveAsTemplate(const QString& geometryInfo)
1198 {
1199  QString s="<table>\t"+QString::number(numRows())+"\t";
1200  s+=QString::number(numCols())+"\n";
1201  s+=geometryInfo;
1202  s+=saveHeader();
1203  s+=saveColumnWidths();
1204  s+=saveCommands();
1205  s+=saveColumnTypes();
1206  s+=saveComments();
1207  s +="</table>\n";
1208  return s;
1209 }
1210 
1211 void Table::restore(const QStringList& list_in)
1212 {
1213 // TODO: obsolete, remove in 0.3.0, only needed for template loading
1214  QStringList temp_list;
1215  QStringList::const_iterator iterator=list_in.begin();
1216 
1217  temp_list= (*iterator++).split("\t");
1218  temp_list.removeFirst();
1219  importV0x0001XXHeader(temp_list);
1220 
1221  setColWidths((*iterator).right((*iterator).length()-9).split("\t", QString::SkipEmptyParts));
1222  iterator++;
1223 
1224  temp_list = (*iterator++).split("\t");
1225  if (temp_list[0] == "com")
1226  {
1227  temp_list.removeFirst();
1228  setCommands(temp_list);
1229  }
1230  else if (temp_list[0] == "<com>")
1231  {
1232  QStringList commands;
1233  for (int col=0; col<numCols(); col++)
1234  commands << "";
1235  for (; iterator != list_in.end() && *iterator != "</com>"; iterator++)
1236  {
1237  int col = (*iterator).mid(9,(*iterator).length()-11).toInt();
1238  QString formula;
1239  for (iterator++; iterator!=list_in.end() && *iterator != "</col>"; iterator++)
1240  formula += *iterator + "\n";
1241  formula.truncate(formula.length()-1);
1242  commands[col] = formula;
1243  }
1244  iterator++;
1245  setCommands(commands);
1246  }
1247 
1248  temp_list = (*iterator++).split("\t");
1249  temp_list.removeFirst();
1250  setColumnTypes(temp_list);
1251 
1252  temp_list = (*iterator++).split("\t");
1253  temp_list.removeFirst();
1254  setColComments(temp_list);
1255 }
1256 
1258 {
1259  if (d_future_table)
1260  d_future_table->clear();
1261 }
1262 
1263 QStringList Table::colNames()
1264 {
1265  QStringList list;
1266  if (d_future_table)
1267  for (int i=0; i<d_future_table->columnCount(); i++)
1268  list << column(i)->name();
1269  return list;
1270 }
1271 
1272 QString Table::colLabel(int col)
1273 {
1274  return column(col)->name();
1275 }
1276 
1278 {
1279  return column(col)->plotDesignation();
1280 }
1281 
1283 {
1284  column(col)->setPlotDesignation(d);
1285 }
1286 
1288 {
1289  QList<int> list;
1290  if (d_future_table)
1291  for (int i=0; i<d_future_table->columnCount(); i++)
1292  list << column(i)->plotDesignation();
1293  return list;
1294 }
1295 
1297 {
1298  QList<int> list;
1299  if (d_future_table)
1300  for (int i=0; i<d_future_table->columnCount(); i++)
1301  list << column(i)->columnMode();
1302  return list;
1303 }
1304 
1305 int Table::columnType(int col)
1306 {
1307  return column(col)->columnMode();
1308 }
1309 
1310 void Table::setColumnTypes(QList<int> ctl)
1311 {
1312  if (!d_future_table) return;
1313  Q_ASSERT(ctl.size() == d_future_table->columnCount());
1314  for (int i=0; i<d_future_table->columnCount(); i++)
1315  {
1316  switch (ctl.at(i))
1317  {
1318  // old enum: enum ColType{Numeric = 0, Text = 1, Date = 2, Time = 3, Month = 4, Day = 5};
1319  case 0:
1321  break;
1322  case 1:
1324  break;
1325  case 2:
1326  case 3:
1327  case 6:
1329  break;
1330  case 4:
1332  break;
1333  case 5:
1335  break;
1336  }
1337  }
1338 }
1339 
1341 {
1342  column(col)->setColumnMode(mode);
1343 }
1344 
1345 QString Table::columnFormat(int col)
1346 {
1347  // TODO: obsolete, remove in 0.3.0
1348  Column * col_ptr = column(col);
1349  if (col_ptr->columnMode() != SciDAVis::DateTime &&
1350  col_ptr->columnMode() != SciDAVis::Month &&
1351  col_ptr->columnMode() != SciDAVis::Day)
1352  return QString();
1353 
1354  DateTime2StringFilter *filter = static_cast<DateTime2StringFilter *>(col_ptr->outputFilter());
1355  return filter->format();
1356 }
1357 
1359 {
1360  return d_view_widget->verticalHeader()->width();
1361 }
1362 
1363 QString Table::colComment(int col)
1364 {
1365  return column(col)->comment();
1366 }
1367 
1368 QStringList Table::colComments()
1369 {
1370  QStringList list;
1371  if (d_future_table)
1372  for (int i=0; i<d_future_table->columnCount(); i++)
1373  list << column(i)->comment();
1374  return list;
1375 }
1376 
1377 void Table::setColComments(const QStringList& list)
1378 {
1379  if (d_future_table)
1380  for (int i=0; i<d_future_table->columnCount(); i++)
1381  column(i)->setComment(list.at(i));
1382 }
1383 
1385 {
1386  return areCommentsShown();
1387 }
1388 
1390 {
1391  if (!d_future_table) return;
1392 
1393  QApplication::setOverrideCursor(Qt::WaitCursor);
1394  d_future_table->beginMacro(tr("%1: apply formula to column").arg(name()));
1395 
1396  QString formula = ui.formula_box->toPlainText();
1397  for (int col=firstSelectedColumn(); col<=lastSelectedColumn(); col++)
1398  {
1399  Column *col_ptr = column(col);
1400  col_ptr->insertRows(col_ptr->rowCount(), rowCount()-col_ptr->rowCount());
1401  col_ptr->setFormula(Interval<int>(0,rowCount()-1), formula);
1402  if (!recalculate(col, false))
1403  break;
1404  }
1405 
1406  d_future_table->endMacro();
1407  QApplication::restoreOverrideCursor();
1408 }
1409 
1411 {
1412  static_cast<ScriptEdit *>(ui.formula_box)->insertFunction(ui.add_function_combobox->currentText());
1413 }
1414 
1416 {
1417  ui.formula_box->insertPlainText(ui.add_reference_combobox->currentText());
1418 }
1419 
1421 {
1422  ui.add_function_combobox->setToolTip(scriptEnv->mathFunctionDoc(ui.add_function_combobox->currentText()));
1423 }
1424 
1426 {
1427  const Column * col = qobject_cast<const Column *>(aspect);
1428  if (col && d_future_table && d_future_table->columnIndex(col) != -1)
1429  {
1430  d_stored_column_labels[col] = aspect->name();
1431  }
1432 }
1433 
1435 {
1436  if (aspect == d_future_table)
1437  {
1438  setObjectName(d_future_table->name());
1439  updateCaption();
1440  return;
1441  }
1442  const Column * col = qobject_cast<const Column *>(aspect);
1443  if (col && d_future_table && d_future_table->columnIndex(col) != -1 && d_stored_column_labels.contains(col))
1444  {
1445  QString old_name = d_stored_column_labels.value(col);
1446  QString new_name = col->name();
1447  emit changedColHeader(name() + "_" + old_name,
1448  name() + "_" + new_name);
1449 
1450  for (int i=0; i<d_future_table->columnCount(); i++)
1451  {
1452  QList< Interval<int> > formula_intervals = column(i)->formulaIntervals();
1453  foreach(Interval<int> interval, formula_intervals)
1454  {
1455  QString formula = column(i)->formula(interval.start());
1456  if (formula.contains("\"" + old_name + "\""))
1457  {
1458  formula.replace("\"" + old_name + "\"", "\"" + new_name + "\"");
1459  column(i)->setFormula(interval, formula);
1460  }
1461  }
1462  }
1463  }
1464 }
1465 
1466 // this function is for backwards compatibility (used by Python),
1467 void Table::importASCII(const QString &fname, const QString &sep, int ignoredLines,
1468  bool renameCols, bool stripSpaces, bool simplifySpaces, bool newTable) {
1469  Q_UNUSED(newTable)
1470 
1471  AsciiTableImportFilter filter;
1472  filter.set_ignored_lines(ignoredLines);
1473  filter.set_separator(sep);
1474  filter.set_first_row_names_columns(renameCols);
1475  filter.set_trim_whitespace(stripSpaces);
1476  filter.set_simplify_whitespace(simplifySpaces);
1477 
1478  QFile file(fname);
1479  if ( file.open(QIODevice::ReadOnly) )
1480  {
1481  future::Table *temp = static_cast<future::Table *>(filter.importAspect(file));
1482  if (!temp) return;
1483  int preexisting_cols = columnCount();
1484  int overwritten_cols = qMin(temp->columnCount(), preexisting_cols);
1485  for (int i=0; i<overwritten_cols; i++) {
1486  column(i)->asStringColumn()->copy(temp->column(i));
1487  if (renameCols)
1488  column(i)->setName(temp->column(i)->name());
1489  }
1490  for (int i=overwritten_cols; i<preexisting_cols; i++)
1491  column(overwritten_cols)->remove();
1493  for (int i=overwritten_cols; i<temp->columnCount(); i++) {
1494  filter->input(0, temp->column(i));
1495  Column *new_col = new Column(temp->column(i)->name(), SciDAVis::Numeric);
1496  new_col->setPlotDesignation(SciDAVis::Y);
1497  new_col->copy(filter->output(0));
1498  d_future_table->addChild(new_col);
1499  }
1500  delete filter;
1501  delete temp;
1502  setWindowLabel(fname);
1503  }
1504 }
1505 
Table::cell
double cell(int row, int col)
Return the value of the cell as a double.
Definition: Table.cpp:907
AsciiTableImportFilter::set_separator
void set_separator(const QString &value)
Definition: AsciiTableImportFilter.h:73
Table::handleChange
void handleChange()
Definition: Table.cpp:153
AbstractFilter::input
bool input(int port, const AbstractColumn *source)
Connect the provided data source to the specified input port.
Definition: AbstractFilter.cpp:31
Table::insertCols
void insertCols(int start, int count)
Definition: Table.cpp:773
Table::deleteSelectedRows
void deleteSelectedRows()
Definition: Table.cpp:834
Table::commentsEnabled
bool commentsEnabled()
Definition: Table.cpp:1384
Table::YColumns
QStringList YColumns()
Definition: Table.cpp:675
Table::cutSelection
void cutSelection()
Selection Operations.
Definition: Table.cpp:840
Table::saveCommands
QString saveCommands()
Definition: Table.cpp:516
Table::column
Column * column(int index) const
Return column number 'index'.
Definition: Table.h:121
Table::text
QString text(int row, int col)
Definition: Table.cpp:931
Table::selectAllTable
void selectAllTable()
Definition: Table.cpp:846
Table::colPlotDesignation
SciDAVis::PlotDesignation colPlotDesignation(int col)
Definition: Table.cpp:1277
Table::exportASCII
bool exportASCII(const QString &fname, const QString &separator, bool withLabels=false, bool exportSelection=false)
Definition: Table.cpp:1032
ScriptingEnv::newScript
virtual Script * newScript(const QString &, QObject *, const QString &)=0
Instantiate the Script subclass matching the ScriptEnv subclass.
Table::columnCount
int columnCount()
Definition: Table.cpp:902
Table::clearCol
void clearCol()
Definition: Table.cpp:820
Column::asStringColumn
ColumnStringIO * asStringColumn() const
Return a wrapper column object used for String I/O.
Definition: Column.h:166
Table::saveToString
virtual QString saveToString(const QString &geometry)
Definition: Table.cpp:542
ScriptEdit
Editor widget with support for evaluating expressions and executing code.
Definition: ScriptEdit.h:50
scripted::scriptEnv
ScriptingEnv * scriptEnv
Definition: Script.h:155
Table::setColumnTypes
void setColumnTypes(QList< int > ctl)
Definition: Table.cpp:1310
SciDAVis::yErr
@ yErr
y errors
Definition: globals.h:61
Table::Table
Table(ScriptingEnv *env, const QString &fname, const QString &sep, int ignoredLines, bool renameCols, bool stripSpaces, bool simplifySpaces, bool convertToNumeric, QLocale numericFormat, const QString &label, QWidget *parent=0, const char *name=0, Qt::WindowFlags f=0)
Definition: Table.cpp:61
Column::outputFilter
AbstractSimpleFilter * outputFilter() const
Return the output filter (for data type -> string conversion)
Definition: Column.cpp:593
TableView::firstSelectedColumn
int firstSelectedColumn(bool full=false)
Return the index of the first selected column.
Definition: TableView.cpp:802
Column.h
Table::recalculate
bool recalculate()
Recalculate selected cells.
Definition: Table.cpp:427
Table::colComment
QString colComment(int col)
Definition: Table.cpp:1363
Table::colLabel
QString colLabel(int col)
Definition: Table.cpp:1272
Table::numSelectedRows
int numSelectedRows()
Definition: Table.cpp:755
Table::drawableColumnSelection
QStringList drawableColumnSelection()
Definition: Table.cpp:713
SciDAVis::xErr
@ xErr
x errors
Definition: globals.h:60
Table::setColName
void setColName(int col, const QString &text)
Definition: Table.cpp:655
SciDAVis::Y
@ Y
y values
Definition: globals.h:58
Table::handleColumnsAboutToBeRemoved
void handleColumnsAboutToBeRemoved(int, int)
Definition: Table.cpp:171
AbstractAspect::setComment
void setComment(const QString &value)
Definition: AbstractAspect.cpp:265
SciDAVis::noDesignation
@ noDesignation
no plot designation
Definition: globals.h:56
Table::saveAsTemplate
QString saveAsTemplate(const QString &geometryInfo)
Definition: Table.cpp:1197
Table::clearSelection
void clearSelection()
Definition: Table.cpp:856
Table::copy
void copy(Table *m)
Definition: Table.cpp:1189
Table::setBackgroundColor
void setBackgroundColor(const QColor &col)
Definition: Table.cpp:189
Table::noYColumn
bool noYColumn()
Definition: Table.cpp:1027
Table::setWindowLabel
virtual void setWindowLabel(const QString &s)
Set the window label.
Definition: Table.h:74
Table::handleColumnChange
void handleColumnChange(int, int)
Definition: Table.cpp:158
ScriptEdit.h
Table::insertCol
void insertCol()
Definition: Table.cpp:787
Table::addFunction
void addFunction()
Definition: Table.cpp:1410
Table::plotDesignations
QList< int > plotDesignations()
Definition: Table.cpp:1287
future::Table
Aspect providing a spreadsheet table with column logic.
Definition: future_Table.h:86
TableView::lastSelectedColumn
int lastSelectedColumn(bool full=false)
Return the index of the last selected column.
Definition: TableView.cpp:816
Table::applyFormula
void applyFormula()
Definition: Table.cpp:1389
AsciiTableImportFilter::importAspect
virtual AbstractAspect * importAspect(QIODevice &input)
Import an object from the specified device and convert it to an Aspect.
Definition: AsciiTableImportFilter.cpp:158
Column
Aspect that manages a column.
Definition: Column.h:59
Double2StringFilter.h
MyWidget::birthdate
QString birthdate
The creation date.
Definition: MyWidget.h:166
Table::setText
void setText(int row, int col, const QString &text)
Definition: Table.cpp:938
DateTime2StringFilter
Conversion filter QDateTime -> QString.
Definition: DateTime2StringFilter.h:41
Table::verticalHeaderWidth
int verticalHeaderWidth()
Definition: Table.cpp:1358
SCRIPTING_CHANGE_EVENT
#define SCRIPTING_CHANGE_EVENT
Definition: customevents.h:40
Table::copySelection
void copySelection()
Definition: Table.cpp:862
TableModel.h
Table::d_future_table
QPointer< future::Table > d_future_table
Definition: Table.h:55
Table::clearCell
void clearCell(int row, int col)
Definition: Table.cpp:826
Table::aboutToRemoveCol
void aboutToRemoveCol(const QString &)
Table::setHeaderColor
void setHeaderColor(const QColor &col)
Definition: Table.cpp:208
DateTime2StringFilter.h
Table::handleRowChange
void handleRowChange()
Definition: Table.cpp:183
Table::removedCol
void removedCol(const QString &)
Column::formulaIntervals
QList< Interval< int > > formulaIntervals() const override
Return the intervals that have associated formulas.
Definition: Column.cpp:633
Table::setColComment
void setColComment(int col, const QString &s)
Definition: Table.cpp:650
Table
MDI window providing a spreadsheet table with column logic.
Definition: Table.h:51
scripted
Interface for maintaining a reference to the current ScriptingEnv.
Definition: Script.h:149
Table::customEvent
void customEvent(QEvent *e)
Definition: Table.cpp:1137
Table::saveToDevice
void saveToDevice(QIODevice *device, const QString &geometry)
Definition: Table.cpp:558
Column::setColumnMode
void setColumnMode(SciDAVis::ColumnMode mode, AbstractFilter *conversion_filter=0) override
Set the column mode.
Definition: Column.cpp:85
Table::setCommands
void setCommands(const QStringList &com)
Set all column formulae.
Definition: Table.cpp:409
Table::setTextFont
void setTextFont(const QFont &fnt)
Definition: Table.cpp:203
Table::firstXCol
int firstXCol()
Definition: Table.cpp:640
Table::saveHeader
QString saveHeader()
Definition: Table.cpp:610
Table::columnWidth
int columnWidth(int col)
Definition: Table.cpp:348
Column::setPlotDesignation
void setPlotDesignation(SciDAVis::PlotDesignation pd)
Set the column plot designation.
Definition: Column.cpp:136
Column::setFormula
void setFormula(Interval< int > i, QString formula)
Set a formula string for an interval of rows.
Definition: Column.cpp:182
Table::addReference
void addReference()
Definition: Table.cpp:1415
Table::setColPlotDesignation
void setColPlotDesignation(int col, SciDAVis::PlotDesignation d)
Definition: Table.cpp:1282
SciDAVis::ColumnMode
ColumnMode
The column mode (defines output and input filter for table columns)
Definition: globals.h:66
Table::setColumnType
void setColumnType(int col, SciDAVis::ColumnMode mode)
Definition: Table.cpp:1340
Table::pasteSelection
void pasteSelection()
Definition: Table.cpp:868
Table::setTextColor
void setTextColor(const QColor &col)
Definition: Table.cpp:196
Column::isInvalid
bool isInvalid(int row) const override
Return whether a certain row contains an invalid value
Definition: Column.cpp:598
TableView
View class for Table.
Definition: TableView.h:89
AsciiTableImportFilter.h
scripted::scriptingChangeEvent
void scriptingChangeEvent(ScriptingChangeEvent *)
Definition: Script.cpp:119
Table::saveComments
QString saveComments()
Definition: Table.cpp:531
Table::setHeaderFont
void setHeaderFont(const QFont &fnt)
Definition: Table.cpp:215
Table::setCommand
void setCommand(int col, const QString &com)
Set formula for column col.
Definition: Table.cpp:415
MyWidget::modifiedWindow
void modifiedWindow(MyWidget *)
Column::rowCount
int rowCount() const override
Return the data vector size.
Definition: Column.cpp:583
Table::columnTypes
QList< int > columnTypes()
Definition: Table.cpp:1296
Table::columnsList
QStringList columnsList()
Definition: Table.cpp:745
Table::clear
void clear()
Definition: Table.cpp:1257
TableView::selectAll
void selectAll()
Definition: TableView.cpp:308
Table::importASCII
void importASCII(const QString &fname, const QString &sep, int ignoredLines, bool renameCols, bool stripSpaces, bool simplifySpaces, bool newTable)
Definition: Table.cpp:1467
TableView::selectedRowCount
int selectedRowCount(bool full=false)
Return how many rows are (at least partly) selected.
Definition: TableView.cpp:782
Table::removeCol
void removeCol()
Definition: Table.cpp:874
Table::name
virtual QString name()
Return the window name.
Definition: Table.h:68
Table::colX
int colX(int col)
Definition: Table.cpp:332
Table::numCols
int numCols()
Definition: Table.cpp:892
Table::rowCount
int rowCount()
Definition: Table.cpp:897
ColumnStringIO::textAt
virtual QString textAt(int row) const
Return the content of row 'row'.
Definition: Column.cpp:644
TableView::selectedColumnCount
int selectedColumnCount(bool full=false)
Return how many columns are selected.
Definition: TableView.cpp:738
Table::noXColumn
bool noXColumn()
Definition: Table.cpp:1022
Table::importV0x0001XXHeader
void importV0x0001XXHeader(QStringList header)
Definition: Table.cpp:943
SciDAVis::Month
@ Month
column contains month names
Definition: globals.h:69
Table::closeEvent
void closeEvent(QCloseEvent *)
Definition: Table.cpp:1143
TableView::isColumnSelected
bool isColumnSelected(int col, bool full=false)
Returns true if column 'col' is selected; otherwise false.
Definition: TableView.cpp:762
ScriptingEnv
An interpreter for evaluating scripting code. Abstract.
Definition: ScriptingEnv.h:53
AbstractSimpleFilter::output
virtual AbstractColumn * output(int port)
Return a pointer to d_output_column on port 0 (don't override unless you really know what you are doi...
Definition: AbstractSimpleFilter.cpp:115
AbstractAspect::name
QString name() const
Definition: AbstractAspect.cpp:229
Column::columnMode
SciDAVis::ColumnMode columnMode() const override
Return the column mode.
Definition: Column.cpp:579
Table::setColWidths
void setColWidths(const QStringList &widths)
Definition: Table.cpp:353
Table::deselect
void deselect()
Definition: Table.cpp:851
Table::setHeader
void setHeader(QStringList header)
Definition: Table.cpp:1000
Table::setNumCols
void setNumCols(int cols)
Definition: Table.cpp:1183
Table::exportPDF
void exportPDF(const QString &fileName)
Definition: Table.cpp:220
Table::colComments
QStringList colComments()
Definition: Table.cpp:1368
Table::saveColumnTypes
QString saveColumnTypes()
Definition: Table.cpp:400
Column::insertRows
void insertRows(int before, int count) override
Insert some empty (or initialized with zero) rows.
Definition: Column.cpp:124
Script
A chunk of scripting code. Abstract.
Definition: Script.h:53
SciDAVis::Text
@ Text
column contains strings
Definition: globals.h:68
Table::selectedYColumns
QStringList selectedYColumns()
Definition: Table.cpp:687
Table::colName
QString colName(int col)
Definition: Table.cpp:765
Column::replaceValues
virtual void replaceValues(int first, const QVector< qreal > &new_values) override
Replace a range of values.
Definition: Column.cpp:234
Table::addCol
void addCol(SciDAVis::PlotDesignation pd=SciDAVis::Y)
Definition: Table.cpp:799
SciDAVis::DateTime
@ DateTime
column contains dates and/or times
Definition: globals.h:71
Column::formula
QString formula(int row) const override
Return the formula associated with row 'row'
Definition: Column.cpp:628
DateTime2StringFilter::format
QString format() const
Return the format string.
Definition: DateTime2StringFilter.h:55
Table::setColComments
void setColComments(const QStringList &lst)
Definition: Table.cpp:1377
Table::selectedErrColumns
QStringList selectedErrColumns()
Definition: Table.cpp:699
Table::d_stored_column_labels
QHash< const AbstractAspect *, QString > d_stored_column_labels
Definition: Table.h:283
Table::selectedColsNumber
int selectedColsNumber()
Definition: Table.cpp:760
Column::plotDesignation
SciDAVis::PlotDesignation plotDesignation() const override
Return the column plot designation.
Definition: Column.cpp:588
ScriptingChangeEvent
notify an object that it should update its scripting environment (see class scripted)
Definition: Script.h:133
TableView::areCommentsShown
bool areCommentsShown() const
Return whether comments are show currently.
Definition: TableView.cpp:345
Table::init
void init()
Definition: Table.cpp:96
String2DoubleFilter.h
AbstractAspect::setName
void setName(const QString &value)
Definition: AbstractAspect.cpp:234
name
char * name()
Definition: exp_saturation.c:45
String2DoubleFilter
Locale-aware conversion filter QString -> double.
Definition: String2DoubleFilter.h:40
AbstractAspect::comment
QString comment() const
Definition: AbstractAspect.cpp:260
Table::selectedColumns
QStringList selectedColumns()
Definition: Table.cpp:663
TableView::firstSelectedRow
int firstSelectedRow(bool full=false)
Return the index of the first selected row.
Definition: TableView.cpp:827
TableView::lastSelectedRow
int lastSelectedRow(bool full=false)
Return the index of the last selected row.
Definition: TableView.cpp:841
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
Table::setPlotDesignation
void setPlotDesignation(SciDAVis::PlotDesignation pd)
Definition: Table.cpp:342
ScriptingEnv::mathFunctionDoc
virtual const QString mathFunctionDoc(const QString &) const
Return a documentation string for the given mathematical function.
Definition: ScriptingEnv.h:74
future::Table::columnCount
int columnCount() const
Return the total number of columns in the table.
Definition: future_Table.cpp:248
Table::columnFormat
QString columnFormat(int col)
Definition: Table.cpp:1345
Table::setCell
void setCell(int row, int col, double val)
Definition: Table.cpp:926
SciDAVis::PlotDesignation
PlotDesignation
Types of plot designations.
Definition: globals.h:55
IntervalAttribute< bool >::intervals
QList< Interval< int > > intervals() const
Definition: IntervalAttribute.h:292
ColumnStringIO::setTextAt
virtual void setTextAt(int row, const QString &value)
Definition: Column.cpp:652
AsciiTableImportFilter
Import an ASCII file as Table.
Definition: AsciiTableImportFilter.h:52
Column::copy
bool copy(const AbstractColumn *other) override
Copy another column of the same type.
Definition: Column.cpp:108
AbstractAspect::remove
virtual void remove()
Remove me from my parent's list of children.
Definition: AbstractAspect.h:250
Table::colNames
QStringList colNames()
Definition: Table.cpp:1263
SciDAVis::Z
@ Z
z values
Definition: globals.h:59
Table::addColumns
void addColumns(int c)
Definition: Table.cpp:809
ColumnStringIO::replaceTexts
virtual void replaceTexts(int start_row, const QStringList &texts)
Set the content of row 'row'.
Definition: Column.cpp:677
Script::eval
virtual QVariant eval()
Evaluate the Code, returning QVariant() on an error / exception.
Definition: Script.cpp:96
future::Table::column
Column * column(int index) const
Return column number 'index'.
Definition: future_Table.cpp:129
Table::modifiedData
void modifiedData(Table *, const QString &)
SciDAVis::X
@ X
x values
Definition: globals.h:57
MyWidget::hiddenWindow
void hiddenWindow(MyWidget *)
Emitted when the window was hidden.
SciDAVis::Day
@ Day
column containts day of week names
Definition: globals.h:70
Table::handleAspectDescriptionAboutToChange
void handleAspectDescriptionAboutToChange(const AbstractAspect *aspect)
Definition: Table.cpp:1425
Table::restore
void restore(const QStringList &lst)
Definition: Table.cpp:1211
Table::colY
int colY(int col)
Definition: Table.cpp:337
Table::print
void print()
Definition: Table.cpp:225
SciDAVis::Numeric
@ Numeric
column contains doubles
Definition: globals.h:67
Table::colIndex
int colIndex(const QString &name)
Definition: Table.cpp:1017
ColumnStringIO::copy
virtual bool copy(const AbstractColumn *other)
Copy another column of the same type.
Definition: Column.cpp:661
MyWidget::askOnClose
bool askOnClose
Toggle on/off: Ask the user "delete, hide, or cancel?" on a close event.
Definition: MyWidget.h:175
Table::selectedYLabels
QMap< int, QString > selectedYLabels()
Definition: Table.cpp:733
Table::columnType
int columnType(int col)
Definition: Table.cpp:1305
Script::setInt
virtual bool setInt(int, const char *)
Definition: Script.h:94
Table::saveColumnWidths
QString saveColumnWidths()
Definition: Table.cpp:390
Table::changedColHeader
void changedColHeader(const QString &, const QString &)
Interval< int >
MyWidget::updateCaption
void updateCaption()
Set caption according to current CaptionPolicy, name and label.
Definition: MyWidget.cpp:52
Column::textAt
QString textAt(int row) const override
Return the content of row 'row'.
Definition: Column.cpp:240
Table::handleColumnsRemoved
void handleColumnsRemoved(int, int)
Definition: Table.cpp:177
Table::setNumRows
void setNumRows(int rows)
Definition: Table.cpp:1177
TableView::selectedRows
IntervalAttribute< bool > selectedRows(bool full=false)
Get the complete set of selected rows.
Definition: TableView.cpp:852
Column::valueAt
double valueAt(int row) const override
Return the double value in row 'row'.
Definition: Column.cpp:260
Column::setTextAt
void setTextAt(int row, const QString &new_value)
Set the content of row 'row'.
Definition: Column.cpp:197
MyWidget::aspect
QString aspect()
Return the window status as a string.
Definition: MyWidget.cpp:106
Table.h
Table::insertRow
void insertRow()
Definition: Table.cpp:793
AbstractAspect
Base class of all persistent objects in a Project.
Definition: AbstractAspect.h:86
Column::setDateTimeAt
void setDateTimeAt(int row, const QDateTime &new_value)
Set the content of row 'row'.
Definition: Column.cpp:218
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
Interval.h
TableView::ui
Ui::ControlTabs ui
UI with options tabs (description, format, formula etc.)
Definition: TableView.h:229
Table::handleAspectDescriptionChange
void handleAspectDescriptionChange(const AbstractAspect *aspect)
Definition: Table.cpp:1434
Column::setValueAt
void setValueAt(int row, double new_value)
Set the content of row 'row'.
Definition: Column.cpp:229
Table::numRows
int numRows()
Definition: Table.cpp:887
Table::updateFunctionDoc
void updateFunctionDoc()
Definition: Table.cpp:1420
TableView::d_view_widget
TableViewWidget * d_view_widget
The table view (first part of the UI)
Definition: TableView.h:231
Column::setInvalid
void setInvalid(Interval< int > i, bool invalid=true)
Set an interval invalid or valid.
Definition: Column.cpp:162