00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #ifndef TABLE_H
00032 #define TABLE_H
00033
00034 #include <q3table.h>
00035 #include <q3header.h>
00036 #include <Q3ValueList>
00037 #include <QVarLengthArray>
00038
00039 #include "plot2D/Graph.h"
00040 #include "MdiSubWindow.h"
00041 #include "ScriptingEnv.h"
00042 #include "Script.h"
00043
00044 class MyTable : public Q3Table
00045 {
00046 public:
00047 MyTable(QWidget * parent = 0, const char * name = 0);
00048 MyTable(int numRows, int numCols, QWidget * parent = 0, const char * name = 0);
00049
00050 private:
00051 void activateNextCell();
00052 };
00053
00060 class Table: public MdiSubWindow, public scripted
00061 {
00062 Q_OBJECT
00063
00064 public:
00065 enum PlotDesignation{All = -1, None = 0, X = 1, Y = 2, Z = 3, xErr = 4, yErr = 5, Label = 6};
00066 enum ColType{Numeric = 0, Text = 1, Date = 2, Time = 3, Month = 4, Day = 5};
00067 enum ImportMode {
00068 NewColumns,
00069 NewRows,
00070 Overwrite
00071 };
00072
00073 Table(ScriptingEnv *env, int r,int c, const QString &label, ApplicationWindow* parent, const QString& name = QString(), Qt::WFlags f=0);
00074
00075 Q3TableSelection getSelection();
00076
00078 void setNumericPrecision(int prec);
00080 void updateDecimalSeparators(const QLocale& oldSeparators);
00081 void setAutoUpdateValues(bool on = true);
00082 virtual QString sizeToString();
00083
00084 public slots:
00085 MyTable* table(){return d_table;};
00086 void copy(Table *m);
00087 int numRows();
00088 int numCols();
00089 void setNumRows(int rows);
00090 void setNumCols(int cols);
00091 void resizeRows(int);
00092 void resizeCols(int);
00093
00095 double cell(int row, int col);
00096 void setCell(int row, int col, double val);
00097
00098 QString text(int row, int col);
00099 QStringList columnsList();
00100 QStringList colNames(){return col_label;}
00101 QString colName(int col);
00102 void setColName(int col, const QString& text, bool enumerateRight = false);
00103 QString colLabel(int col){return col_label[col];};
00104 int colIndex(const QString& name);
00105
00106 int colPlotDesignation(int col){return col_plot_type[col];};
00107 void setColPlotDesignation(int col, PlotDesignation pd);
00108 void setPlotDesignation(PlotDesignation pd, bool rightColumns = false);
00109 Q3ValueList<int> plotDesignations(){return col_plot_type;};
00110
00111 void setHeader(QStringList header);
00112 void loadHeader(QStringList header);
00113 void setHeaderColType();
00114 void setText(int row,int col,const QString & text);
00115 void setRandomValues();
00116 void setAscValues();
00117
00118 void cellEdited(int,int col);
00119 void moveCurrentCell();
00120 void clearCell(int row, int col);
00121 bool isEmptyRow(int row);
00122 bool isEmptyColumn(int col);
00123 int nonEmptyRows();
00124
00125 void print();
00126 void print(const QString& fileName);
00127 void exportPDF(const QString& fileName);
00128
00130
00131 bool eventFilter(QObject *object, QEvent *e);
00132 void customEvent( QEvent* e);
00134
00136
00137 void removeCol();
00138 void removeCol(const QStringList& list);
00139 void insertCol();
00140 void insertCols(int start, int count);
00141 void addCol(PlotDesignation pd = Y);
00142 void addColumns(int c);
00143 void moveColumn(int, int, int);
00144 void swapColumns(int, int);
00145 void moveColumnBy(int cols);
00146 void hideSelectedColumns();
00147 void showAllColumns();
00148 void hideColumn(int col, bool = true);
00149 bool isColumnHidden(int col){return d_table->isColumnHidden(col);};
00151
00153
00154
00157 void sortColAsc();
00161 void sortColDesc();
00166 void sortColumn(int col = -1, int order = 0);
00171 void sortTableDialog();
00173 void sort(int type = 0, int order = 0, const QString& leadCol = QString());
00175 void sortColumns(int type = 0, int order = 0, const QString& leadCol = QString());
00182 void sortColumns(const QStringList& cols, int type = 0, int order = 0, const QString& leadCol = QString());
00187 void sortColumnsDialog();
00189
00191
00192 void normalizeCol(int col=-1);
00193 void normalizeSelection();
00194 void normalize();
00196
00197 QVarLengthArray<double> col(int ycol);
00198 int firstXCol();
00199 bool noXColumn();
00200 bool noYColumn();
00201 int colX(int col);
00202 int colY(int col);
00203
00204 QStringList getCommands(){return commands;};
00206 void setCommands(const QStringList& com);
00208 void setCommands(const QString& com);
00210 void setCommand(int col, const QString& com);
00212 bool calculate(int col, int startRow, int endRow, bool forceMuParser = true, bool notifyChanges = true);
00214 bool muParserCalculate(int col, int startRow, int endRow, bool notifyChanges = true);
00216 bool calculate();
00218 void updateValues(Table*, const QString& columnName);
00219
00221
00222 void deleteSelectedRows();
00223 void deleteRows(int startRow, int endRow);
00224 void insertRow();
00226
00228
00229 void cutSelection();
00230 void copySelection();
00231 void clearSelection();
00232 void pasteSelection();
00233 void selectAllTable();
00234 void deselect();
00235 void clear();
00237
00238 void init(int rows, int cols);
00239 QStringList selectedColumns();
00240 QStringList selectedYColumns();
00241 QStringList selectedErrColumns();
00242 QStringList selectedYLabels();
00243 QStringList drawableColumnSelection();
00244 QStringList YColumns();
00245 int selectedColsNumber();
00246
00247 void setColumnWidth(int width, bool allCols);
00248 void setColumnWidth(int col, int width);
00249 int columnWidth(int col);
00250 QStringList columnWidths();
00251 void setColWidths(const QStringList& widths);
00252
00253 void setSelectedCol(int col){selectedCol = col;};
00254 int selectedColumn(){return selectedCol;};
00255 int firstSelectedColumn();
00256 int numSelectedRows();
00257 bool isRowSelected(int row, bool full=false) { return d_table->isRowSelected(row, full); }
00258 bool isColumnSelected(int col, bool full=false) { return d_table->isColumnSelected(col, full); }
00260 void goToRow(int row);
00262 void goToColumn(int col);
00263
00264 void columnNumericFormat(int col, char *f, int *precision);
00265 void columnNumericFormat(int col, int *f, int *precision);
00266 int columnType(int col){return colTypes[col];};
00267
00268 Q3ValueList<int> columnTypes(){return colTypes;};
00269 void setColumnTypes(Q3ValueList<int> ctl){colTypes = ctl;};
00270 void setColumnTypes(const QStringList& ctl);
00271 void setColumnType(int col, ColType val) { colTypes[col] = val; }
00272
00273 void saveToMemory(double **cells){d_saved_cells = cells;};
00274 void saveToMemory();
00275 void freeMemory();
00276
00277 bool isReadOnlyColumn(int col);
00278 void setReadOnlyColumn(int col, bool on = true);
00279
00280 QString columnFormat(int col){return col_format[col];};
00281 QStringList getColumnsFormat(){return col_format;};
00282 void setColumnsFormat(const QStringList& lst);
00283
00284 void setTextFormat(int col);
00285 void setColNumericFormat(int f, int prec, int col, bool updateCells = true);
00286 bool setDateFormat(const QString& format, int col, bool updateCells = true);
00287 bool setTimeFormat(const QString& format, int col, bool updateCells = true);
00288 void setMonthFormat(const QString& format, int col, bool updateCells = true);
00289 void setDayFormat(const QString& format, int col, bool updateCells = true);
00290
00291 bool exportASCII(const QString& fname, const QString& separator, bool withLabels = false,
00292 bool exportComments = false, bool exportSelection = false);
00293 void importASCII(const QString &fname, const QString &sep, int ignoredLines, bool renameCols,
00294 bool stripSpaces, bool simplifySpaces, bool importComments,
00295 const QString& commentString, bool readOnly = false,
00296 ImportMode importAs = Overwrite, int endLine = 0, int maxRows = -1);
00297
00299
00300 virtual void save(const QString &fn, const QString& geometry, bool = false);
00301 void restore(const QStringList& lst);
00302
00303 QString saveHeader();
00304 QString saveComments();
00305 QString saveCommands();
00306 QString saveColumnWidths();
00307 QString saveColumnTypes();
00308 QString saveReadOnlyInfo();
00309 QString saveHiddenColumnsInfo();
00310
00311 void setBackgroundColor(const QColor& col);
00312 void setTextColor(const QColor& col);
00313 void setHeaderColor(const QColor& col);
00314 void setTextFont(const QFont& fnt);
00315 void setHeaderFont(const QFont& fnt);
00316
00317 int verticalHeaderWidth(){return d_table->verticalHeader()->width();};
00318
00319 QString comment(int col);
00320 void setColComment(int col, const QString& s);
00321 QStringList colComments(){return comments;};
00322 void setColComments(const QStringList& lst){comments = lst;};
00323 void showComments(bool on = true);
00324 bool commentsEnabled(){return d_show_comments;}
00325
00327 void notifyChanges();
00328
00330 void colWidthModified(int, int, int);
00331
00332 signals:
00333 void changedColHeader(const QString&, const QString&);
00334 void removedCol(const QString&);
00335 void modifiedData(Table *, const QString&);
00336 void optionsDialog();
00337 void colValuesDialog();
00338 void resizedTable(QWidget*);
00339 void showContextMenu(bool selection);
00340 void createTable(const QString&,int,int,const QString&);
00341
00342 protected:
00343 MyTable *d_table;
00344
00345 private:
00346 void clearCol();
00347
00348 bool d_show_comments;
00349 QStringList commands, col_format, comments, col_label;
00350 QList<int> colTypes, col_plot_type;
00351 int selectedCol;
00352 int d_numeric_precision;
00353 double **d_saved_cells;
00354
00356 void setColumnHeader(int index, const QString& label);
00357 };
00358
00359 #endif