Table.h

Go to the documentation of this file.
00001 /***************************************************************************
00002     File                 : Table.h
00003     Project              : QtiPlot
00004     --------------------------------------------------------------------
00005     Copyright            : (C) 2006 by Ion Vasilief,
00006                            Tilman Hoener zu Siederdissen,
00007                            Knut Franke
00008     Email (use @ for *)  : ion_vasilief*yahoo.fr, thzs*gmx.net
00009     Description          : Table worksheet class
00010 
00011  ***************************************************************************/
00012 
00013 /***************************************************************************
00014  *                                                                         *
00015  *  This program is free software; you can redistribute it and/or modify   *
00016  *  it under the terms of the GNU General Public License as published by   *
00017  *  the Free Software Foundation; either version 2 of the License, or      *
00018  *  (at your option) any later version.                                    *
00019  *                                                                         *
00020  *  This program is distributed in the hope that it will be useful,        *
00021  *  but WITHOUT ANY WARRANTY; without even the implied warranty of         *
00022  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          *
00023  *  GNU General Public License for more details.                           *
00024  *                                                                         *
00025  *   You should have received a copy of the GNU General Public License     *
00026  *   along with this program; if not, write to the Free Software           *
00027  *   Foundation, Inc., 51 Franklin Street, Fifth Floor,                    *
00028  *   Boston, MA  02110-1301  USA                                           *
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 
00083 public slots:
00084     MyTable* table(){return d_table;};
00085     void copy(Table *m);
00086     int numRows();
00087     int numCols();
00088     void setNumRows(int rows);
00089     void setNumCols(int cols);
00090     void resizeRows(int);
00091     void resizeCols(int);
00092 
00094     double cell(int row, int col);
00095     void setCell(int row, int col, double val);
00096 
00097     QString text(int row, int col);
00098     QStringList columnsList();
00099     QStringList colNames(){return col_label;}
00100     QString colName(int col);
00101     void setColName(int col, const QString& text, bool enumerateRight = false);
00102     QString colLabel(int col){return col_label[col];};
00103     int colIndex(const QString& name);
00104 
00105     int colPlotDesignation(int col){return col_plot_type[col];};
00106     void setColPlotDesignation(int col, PlotDesignation pd);
00107     void setPlotDesignation(PlotDesignation pd, bool rightColumns = false);
00108     Q3ValueList<int> plotDesignations(){return col_plot_type;};
00109 
00110     void setHeader(QStringList header);
00111     void loadHeader(QStringList header);
00112     void setHeaderColType();
00113     void setText(int row,int col,const QString & text);
00114     void setRandomValues();
00115     void setAscValues();
00116 
00117     void cellEdited(int,int col);
00118     void moveCurrentCell();
00119     void clearCell(int row, int col);
00120     QString saveText();
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 QString saveToString(const QString& geometry, bool = false);
00301     QString saveHeader();
00302     QString saveComments();
00303     QString saveCommands();
00304     QString saveColumnWidths();
00305     QString saveColumnTypes();
00306     QString saveReadOnlyInfo();
00307     QString saveHiddenColumnsInfo();
00308 
00309     void setSpecifications(const QString& s);
00310     QString& getSpecifications();
00311     void restore(QString& spec);
00312     QString& getNewSpecifications();
00313     void setNewSpecifications();
00314 
00318     QString oldCaption();
00319 
00323     QString newCaption();
00325 
00326     void setBackgroundColor(const QColor& col);
00327     void setTextColor(const QColor& col);
00328     void setHeaderColor(const QColor& col);
00329     void setTextFont(const QFont& fnt);
00330     void setHeaderFont(const QFont& fnt);
00331 
00332     int verticalHeaderWidth(){return d_table->verticalHeader()->width();};
00333 
00334     QString colComment(int col){return comments[col];};
00335     void setColComment(int col, const QString& s);
00336     QStringList colComments(){return comments;};
00337     void setColComments(const QStringList& lst){comments = lst;};
00338     void showComments(bool on = true);
00339     bool commentsEnabled(){return d_show_comments;}
00340 
00341     QString saveAsTemplate(const QString& geometryInfo);
00342     void restore(const QStringList& lst);
00343 
00345     void notifyChanges();
00346 
00348     void colWidthModified(int, int, int);
00349 
00350 signals:
00351     void changedColHeader(const QString&, const QString&);
00352     void removedCol(const QString&);
00353     void modifiedData(Table *, const QString&);
00354     void optionsDialog();
00355     void colValuesDialog();
00356     void resizedTable(QWidget*);
00357     void showContextMenu(bool selection);
00358     void createTable(const QString&,int,int,const QString&);
00359 
00360 protected:
00361     MyTable *d_table;
00362 
00363 private:
00364     void clearCol();
00365 
00366     bool d_show_comments;
00367     QString specifications, newSpecifications;
00368     QStringList commands, col_format, comments, col_label;
00369     QList<int> colTypes, col_plot_type;
00370     int selectedCol;
00371     int d_numeric_precision;
00372     double **d_saved_cells;
00373 
00375     void setColumnHeader(int index, const QString& label);
00376 };
00377 
00378 #endif

Generated on Sun Jun 15 21:32:19 2008 for QtiPlot by  doxygen 1.5.6