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, Knut Franke
00006     Email (use @ for *)  : ion_vasilief*yahoo.fr
00007     Description          : Table worksheet class
00008 
00009  ***************************************************************************/
00010 
00011 /***************************************************************************
00012  *                                                                         *
00013  *  This program is free software; you can redistribute it and/or modify   *
00014  *  it under the terms of the GNU General Public License as published by   *
00015  *  the Free Software Foundation; either version 2 of the License, or      *
00016  *  (at your option) any later version.                                    *
00017  *                                                                         *
00018  *  This program is distributed in the hope that it will be useful,        *
00019  *  but WITHOUT ANY WARRANTY; without even the implied warranty of         *
00020  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          *
00021  *  GNU General Public License for more details.                           *
00022  *                                                                         *
00023  *   You should have received a copy of the GNU General Public License     *
00024  *   along with this program; if not, write to the Free Software           *
00025  *   Foundation, Inc., 51 Franklin Street, Fifth Floor,                    *
00026  *   Boston, MA  02110-1301  USA                                           *
00027  *                                                                         *
00028  ***************************************************************************/
00029 #ifndef TABLE_H
00030 #define TABLE_H
00031 
00032 #include <q3table.h>
00033 #include <q3header.h>
00034 #include <Q3ValueList>
00035 #include <QVarLengthArray>
00036 
00037 #include <MdiSubWindow.h>
00038 #include <ScriptingEnv.h>
00039 #include <Script.h>
00040 
00041 class MyTable : public Q3Table
00042 {
00043 public:
00044     MyTable(QWidget * parent = 0, const char * name = 0);
00045     MyTable(int numRows, int numCols, QWidget * parent = 0, const char * name = 0);
00046 
00047 private:
00048     void activateNextCell();
00049 };
00050 
00057 class Table: public MdiSubWindow, public scripted
00058 {
00059     Q_OBJECT
00060 
00061 public:
00062     enum PlotDesignation{All = -1, None = 0, X = 1, Y = 2, Z = 3, xErr = 4, yErr = 5, Label = 6};
00063     enum ColType{Numeric = 0, Text = 1, Date = 2, Time = 3, Month = 4, Day = 5};
00064     enum NumericFormat{Default = 0, Decimal = 1, Scientific = 2};
00065     enum ImportMode {
00066         NewColumns, 
00067         NewRows, 
00068         Overwrite 
00069     };
00070 
00071     Table(ScriptingEnv *env, int r,int c, const QString &label, ApplicationWindow* parent, const QString& name = QString(), Qt::WFlags f=0);
00072 
00073     Q3TableSelection getSelection();
00074 
00076     void setNumericPrecision(int prec);
00078     void updateDecimalSeparators(const QLocale& oldSeparators);
00079     void setAutoUpdateValues(bool on = true);
00080     virtual QString sizeToString();
00081 
00082 public slots:
00083     MyTable* table(){return d_table;};
00084     void copy(Table *m);
00085     int numRows();
00086     int numCols();
00087     void setNumRows(int rows);
00088     void setNumCols(int cols);
00089     void resizeRows(int);
00090     void resizeCols(int);
00091 
00093     double cell(int row, int col);
00094     void setCell(int row, int col, double val);
00095 
00096     QString text(int row, int col);
00097     QStringList columnsList();
00098     QStringList colNames(){return col_label;}
00099     QString colName(int col);
00100     void setColName(int col, const QString& text, bool enumerateRight = false);
00101     QString colLabel(int col){return col_label[col];};
00102     int colIndex(const QString& name);
00103 
00104     int colPlotDesignation(int col){return col_plot_type[col];};
00105     void setColPlotDesignation(int col, PlotDesignation pd);
00106     void setPlotDesignation(PlotDesignation pd, bool rightColumns = false);
00107     Q3ValueList<int> plotDesignations(){return col_plot_type;};
00108 
00109     void setHeader(QStringList header);
00110     void loadHeader(QStringList header);
00111     void setHeaderColType();
00112     void setText(int row,int col,const QString & text);
00113     void setRandomValues();
00114     void setAscValues();
00115 
00116     void cellEdited(int,int col);
00117     void moveCurrentCell();
00118     void clearCell(int row, int col);
00119     bool isEmptyRow(int row);
00120     bool isEmptyColumn(int col);
00121     int nonEmptyRows();
00122 
00123     void print();
00124     void print(QPrinter *);
00125     void print(const QString& fileName);
00126     void exportPDF(const QString& fileName);
00127 
00129 
00130     bool eventFilter(QObject *object, QEvent *e);
00131     void customEvent( QEvent* e);
00133 
00135 
00136     void removeCol();
00137     void removeCol(const QStringList& list);
00138     void insertCol();
00139     void insertCols(int start, int count);
00140     void addCol(PlotDesignation pd = Y);
00141     void addColumns(int c);
00142     void moveColumn(int, int, int);
00143     void swapColumns(int, int);
00144     void moveColumnBy(int cols);
00145     void hideSelectedColumns();
00146     void showAllColumns();
00147     void hideColumn(int col, bool = true);
00148     bool isColumnHidden(int col){return d_table->isColumnHidden(col);};
00150 
00152 
00153 
00156     void sortColAsc();
00160     void sortColDesc();
00165     void sortColumn(int col = -1, int order = 0);
00170     void sortTableDialog();
00172     void sort(int type = 0, int order  = 0, const QString& leadCol = QString());
00174     void sortColumns(int type = 0, int order = 0, const QString& leadCol = QString());
00181     void sortColumns(const QStringList& cols, int type = 0, int order = 0, const QString& leadCol = QString());
00186     void sortColumnsDialog();
00188 
00190 
00191     void normalizeCol(int col=-1);
00192     void normalizeSelection();
00193     void normalize();
00195 
00196     QVarLengthArray<double> col(int ycol);
00197     void columnRange(int c, double *min, double *max);
00198 
00199     int firstXCol();
00200     bool noXColumn();
00201     bool noYColumn();
00202     int colX(int col);
00203     int colY(int col);
00204 
00205     QStringList getCommands(){return commands;};
00207     void clearCommands();
00209     void setCommands(const QStringList& com);
00211     void setCommands(const QString& com);
00213     void setCommand(int col, const QString& com);
00215     bool calculate(int col, int startRow, int endRow, bool forceMuParser = false, bool notifyChanges = true);
00217     bool muParserCalculate(int col, int startRow, int endRow, bool notifyChanges = true);
00219     bool calculate();
00221     void updateValues(Table*, const QString& columnName);
00222 
00224 
00225     void deleteSelectedRows();
00226     void deleteRows(int startRow, int endRow);
00227     void insertRow();
00228     void moveRow(bool up = true);
00230 
00232 
00233     void cutSelection();
00234     void copySelection();
00235     void clearSelection();
00236     void pasteSelection();
00237     void selectAllTable();
00238     void deselect();
00239     void clear();
00241 
00242     void init(int rows, int cols);
00243     QStringList selectedColumns();
00244     QStringList selectedYColumns();
00245     QStringList selectedErrColumns();
00246     QStringList selectedYLabels();
00247     QStringList drawableColumnSelection();
00248     QStringList YColumns();
00249     int selectedColsNumber();
00250 
00251     void setColumnWidth(int width, bool allCols);
00252     void setColumnWidth(int col, int width);
00253     int columnWidth(int col);
00254     QStringList columnWidths();
00255     void setColWidths(const QStringList& widths);
00256     void adjustColumnsWidth();
00257 
00258     void setSelectedCol(int col){selectedCol = col;};
00259     int selectedColumn(){return selectedCol;};
00260     int firstSelectedColumn();
00261     int numSelectedRows();
00262     bool isRowSelected(int row, bool full=false) { return d_table->isRowSelected(row, full); }
00263     bool isColumnSelected(int col, bool full=false) { return d_table->isColumnSelected(col, full); }
00265     void goToRow(int row);
00267     void goToColumn(int col);
00268 
00269     void columnNumericFormat(int col, char *f, int *precision);
00270     void columnNumericFormat(int col, int *f, int *precision);
00271     int columnType(int col){return colTypes[col];};
00272 
00273     Q3ValueList<int> columnTypes(){return colTypes;};
00274     void setColumnTypes(Q3ValueList<int> ctl){colTypes = ctl;};
00275     void setColumnTypes(const QStringList& ctl);
00276     void setColumnType(int col, ColType val) { colTypes[col] = val; }
00277 
00278     void saveToMemory(double **cells){d_saved_cells = cells;};
00279     void saveToMemory();
00280     void freeMemory();
00281 
00282     bool isReadOnlyColumn(int col);
00283     void setReadOnlyColumn(int col, bool on = true);
00284 
00285     QString columnFormat(int col){return col_format[col];};
00286     QStringList getColumnsFormat(){return col_format;};
00287     void setColumnsFormat(const QStringList& lst);
00288 
00289     void setTextFormat(int col);
00290     void setColNumericFormat(int f, int prec, int col, bool updateCells = true);
00291     bool setDateFormat(const QString& format, int col, bool updateCells = true);
00292     bool setTimeFormat(const QString& format, int col, bool updateCells = true);
00293     void setMonthFormat(const QString& format, int col, bool updateCells = true);
00294     void setDayFormat(const QString& format, int col, bool updateCells = true);
00295 
00296     bool exportODF(const QString& fname, bool withLabels, bool exportComments, bool exportSelection);
00297     bool exportASCII(const QString& fname, const QString& separator, bool withLabels = false,
00298                      bool exportComments = false, bool exportSelection = false);
00299     void importASCII(const QString &fname, const QString &sep, int ignoredLines, bool renameCols,
00300                     bool stripSpaces, bool simplifySpaces, bool importComments,
00301                     const QString& commentString, bool readOnly = false,
00302                     ImportMode importAs = Overwrite, int endLine = 0, int maxRows = -1);
00303 
00305 
00306     virtual void save(const QString &fn, const QString& geometry, bool = false);
00307     void restore(const QStringList& lst);
00308 
00309     QString saveHeader();
00310     QString saveComments();
00311     QString saveCommands();
00312     QString saveColumnWidths();
00313     QString saveColumnTypes();
00314     QString saveReadOnlyInfo();
00315     QString saveHiddenColumnsInfo();
00316 
00317     void setBackgroundColor(const QColor& col);
00318     void setTextColor(const QColor& col);
00319     void setHeaderColor(const QColor& col);
00320     void setTextFont(const QFont& fnt);
00321     void setHeaderFont(const QFont& fnt);
00322 
00323     int verticalHeaderWidth(){return d_table->verticalHeader()->width();};
00324 
00325     QString comment(int col);
00326     void setColComment(int col, const QString& s);
00327     QStringList colComments(){return comments;};
00328     void setColComments(const QStringList& lst){comments = lst;};
00329     void showComments(bool on = true);
00330     bool commentsEnabled(){return d_show_comments;}
00331 
00333     void notifyChanges();
00334 
00336     void colWidthModified(int, int, int);
00337 
00338 signals:
00339     void changedColHeader(const QString&, const QString&);
00340     void removedCol(const QString&);
00341     void modifiedData(Table *, const QString&);
00342     void optionsDialog();
00343     void colValuesDialog();
00344     void resizedTable(QWidget*);
00345     void showContextMenu(bool selection);
00346     void createTable(const QString&,int,int,const QString&);
00347 
00348 protected:
00349     MyTable *d_table;
00350 
00351 private:
00352     void clearCol();
00353 
00354     bool d_show_comments;
00355     QStringList commands, col_format, comments, col_label;
00356     QList<int> colTypes, col_plot_type;
00357     int selectedCol;
00358     int d_numeric_precision;
00359     double **d_saved_cells;
00360 
00362     void setColumnHeader(int index, const QString& label);
00363 };
00364 
00365 #endif

Generated by  doxygen 1.6.2