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 "Graph.h"
00040 #include "MyWidget.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     void activateNextCell();
00051 };
00052 
00059 class Table: public MyWidget, public scripted
00060 {
00061     Q_OBJECT
00062 
00063 public:
00064     enum PlotDesignation{All = -1, None = 0, X = 1, Y = 2, Z = 3, xErr = 4, yErr = 5};
00065     enum ColType{Numeric = 0, Text = 1, Date = 2, Time = 3, Month = 4, Day = 5};
00066 
00067     Table(ScriptingEnv *env, const QString &fname,const QString &sep, int ignoredLines, bool renameCols,
00068          bool stripSpaces, bool simplifySpaces, const QString &label,
00069          QWidget* parent=0, const char* name=0, Qt::WFlags f=0);
00070     Table(ScriptingEnv *env, int r,int c, const QString &label, QWidget* parent=0, const char* name=0, Qt::WFlags f=0);
00071 
00072     Q3TableSelection getSelection();
00073 
00075     void setNumericPrecision(int prec);
00076 
00077 public slots:
00078     MyTable* table(){return d_table;};
00079     void copy(Table *m);
00080     int numRows();
00081     int numCols();
00082     void setNumRows(int rows);
00083     void setNumCols(int cols);
00084     void resizeRows(int);
00085     void resizeCols(int);
00086 
00088     double cell(int row, int col);
00089     void setCell(int row, int col, double val);
00090 
00091     QString text(int row, int col);
00092     QStringList columnsList();
00093     QStringList colNames(){return col_label;}
00094     QString colName(int col);
00095     QString colLabel(int col){return col_label[col];};
00096     int colIndex(const QString& name);
00097 
00098     int colPlotDesignation(int col){return col_plot_type[col];};
00099     void setColPlotDesignation(int col, PlotDesignation d){col_plot_type[col]=d;};
00100     void setPlotDesignation(PlotDesignation pd);
00101     Q3ValueList<int> plotDesignations(){return col_plot_type;};
00102 
00103     void setColName(int col,const QString& text);
00104     void setHeader(QStringList header);
00105     void loadHeader(QStringList header);
00106     void setHeaderColType();
00107     void setText(int row,int col,const QString & text);
00108     void setRandomValues();
00109     void setAscValues();
00110 
00111     void cellEdited(int,int col);
00112     void moveCurrentCell();
00113     void clearCell(int row, int col);
00114     QString saveText();
00115     bool isEmptyRow(int row);
00116     bool isEmptyColumn(int col);
00117     int nonEmptyRows();
00118 
00119     void plotL();
00120     void plotLP();
00121     void plotP();
00122     void plotVB();
00123     void plotHB();
00124     void plotArea();
00125     void plotPie();
00126     void plotVerticalDropLines();
00127     void plotSpline();
00128     void plotVertSteps();
00129     void plotHorSteps();
00130     void plotHistogram();
00131     void plotVectXYXY();
00132     void plotVectXYAM();
00133     void plotBoxDiagram();
00134 
00136 
00137     void plot3DRibbon();
00138     void plot3DScatter();
00139     void plot3DTrajectory();
00140     void plot3DBars();
00141 
00142     bool valid2DPlot();
00143     bool valid3DPlot();
00145 
00146     void print();
00147     void print(const QString& fileName);
00148     void exportPDF(const QString& fileName);
00149 
00151 
00152     bool eventFilter(QObject *object, QEvent *e);
00153     void contextMenuEvent(QContextMenuEvent *e);
00154     void customEvent( QEvent* e);
00156 
00158 
00159     void removeCol();
00160     void removeCol(const QStringList& list);
00161     void clearCol();
00162     void insertCol();
00163     void insertCols(int start, int count);
00164     void addCol(PlotDesignation pd = Y);
00165     void addColumns(int c);
00167 
00169 
00170 
00173     void sortColAsc();
00177     void sortColDesc();
00182     void sortColumn(int col = -1, int order = 0);
00187     void sortTableDialog();
00189     void sort(int type = 0, int order  = 0, const QString& leadCol = QString());
00191     void sortColumns(int type = 0, int order = 0, const QString& leadCol = QString());
00198     void sortColumns(const QStringList& cols, int type = 0, int order = 0, const QString& leadCol = QString());
00203     void sortColumnsDialog();
00205 
00207 
00208     void normalizeCol(int col=-1);
00209     void normalizeSelection();
00210     void normalize();
00212 
00213     QVarLengthArray<double> col(int ycol);
00214     int firstXCol();
00215     bool noXColumn();
00216     bool noYColumn();
00217     int colX(int col);
00218     int colY(int col);
00219 
00220     QStringList getCommands(){return commands;};
00222     void setCommands(const QStringList& com);
00224     void setCommands(const QString& com);
00226     void setCommand(int col, const QString com);
00228     bool calculate(int col, int startRow, int endRow);
00230     bool calculate();
00231 
00233 
00234     void deleteSelectedRows();
00235     void insertRow();
00237 
00239 
00240     void cutSelection();
00241     void copySelection();
00242     void clearSelection();
00243     void pasteSelection();
00244     void selectAllTable();
00245     void deselect();
00246     void clear();
00248 
00249     void init(int rows, int cols);
00250     QStringList selectedColumns();
00251     QStringList selectedYColumns();
00252     QStringList selectedErrColumns();
00253     QStringList selectedYLabels();
00254     QStringList drawableColumnSelection();
00255     QStringList YColumns();
00256     int selectedColsNumber();
00257     void changeColName(const QString& text);
00258     void enumerateRightCols(bool checked);
00259 
00260     void changeColWidth(int width, bool allCols);
00261     void changeColWidth(int width, int col);
00262     int columnWidth(int col);
00263     QStringList columnWidths();
00264     void setColWidths(const QStringList& widths);
00265 
00266     void setSelectedCol(int col){selectedCol = col;};
00267     int selectedColumn(){return selectedCol;};
00268     int firstSelectedColumn();
00269     int numSelectedRows();
00270     bool isRowSelected(int row, bool full=false) { return d_table->isRowSelected(row, full); }
00271     bool isColumnSelected(int col, bool full=false) { return d_table->isColumnSelected(col, full); }
00273     void goToRow(int row);
00274 
00275     void columnNumericFormat(int col, char *f, int *precision);
00276     void columnNumericFormat(int col, int *f, int *precision);
00277     int columnType(int col){return colTypes[col];};
00278 
00279     Q3ValueList<int> columnTypes(){return colTypes;};
00280     void setColumnTypes(Q3ValueList<int> ctl){colTypes = ctl;};
00281     void setColumnTypes(const QStringList& ctl);
00282     void setColumnType(int col, ColType val) { colTypes[col] = val; }
00283 
00284     void saveToMemory();
00285     void freeMemory();
00286 
00287     QString columnFormat(int col){return col_format[col];};
00288     QStringList getColumnsFormat(){return col_format;};
00289     void setColumnsFormat(const QStringList& lst);
00290 
00291     void setTextFormat(int col);
00292     void setColNumericFormat(int f, int prec, int col);
00293     bool setDateFormat(const QString& format, int col);
00294     bool setTimeFormat(const QString& format, int col);
00295     void setMonthFormat(const QString& format, int col);
00296     void setDayFormat(const QString& format, int col);
00297     bool setDateTimeFormat(int f, const QString& format, int col);
00298 
00299     bool exportToASCIIFile(const QString& fname, const QString& separator,
00300                               bool withLabels,bool exportSelection);
00301     void importASCII(const QString &fname, const QString &sep, int ignoredLines,
00302                         bool renameCols, bool stripSpaces, bool simplifySpaces, bool newTable);
00303     void importMultipleASCIIFiles(const QString &fname, const QString &sep, int ignoredLines,
00304                     bool renameCols, bool stripSpaces, bool simplifySpaces, int importFileAs);
00305 
00307 
00308     virtual QString saveToString(const QString& geometry);
00309     QString saveHeader();
00310     QString saveComments();
00311     QString saveCommands();
00312     QString saveColumnWidths();
00313     QString saveColumnTypes();
00314 
00315     void setSpecifications(const QString& s);
00316     QString& getSpecifications();
00317     void restore(QString& spec);
00318     QString& getNewSpecifications();
00319     void setNewSpecifications();
00320 
00324     QString oldCaption();
00325 
00329     QString newCaption();
00331 
00332     void setBackgroundColor(const QColor& col);
00333     void setTextColor(const QColor& col);
00334     void setHeaderColor(const QColor& col);
00335     void setTextFont(const QFont& fnt);
00336     void setHeaderFont(const QFont& fnt);
00337 
00338     int verticalHeaderWidth(){return d_table->verticalHeader()->width();};
00339 
00340     QString colComment(int col){return comments[col];};
00341     void setColComment(int col, const QString& s);
00342     QStringList colComments(){return comments;};
00343     void setColComments(const QStringList& lst){comments = lst;};
00344     void showComments(bool on = true);
00345     bool commentsEnabled(){return d_show_comments;}
00346 
00347     QString saveAsTemplate(const QString& geometryInfo);
00348     void restore(const QStringList& lst);
00349 
00351     void notifyChanges();
00352 
00354     void colWidthModified(int, int, int);
00355 
00356 signals:
00357     void plot3DRibbon(Table *,const QString&);
00358     void plotXYZ(Table *,const QString&, int);
00359     void plotCol(Table *,const QStringList&, int, int, int);
00360     void changedColHeader(const QString&, const QString&);
00361     void removedCol(const QString&);
00362     void modifiedData(Table *, const QString&);
00363     void optionsDialog();
00364     void colValuesDialog();
00365     void resizedTable(QWidget*);
00366     void showContextMenu(bool selection);
00367     void createTable(const QString&,int,int,const QString&);
00368 
00369 protected:
00370     MyTable *d_table;
00371 
00372 private:
00373     bool d_show_comments;
00374     QString specifications, newSpecifications;
00375     QStringList commands, col_format, comments, col_label;
00376     QList<int> colTypes, col_plot_type;
00377     int selectedCol;
00378     double **d_saved_cells;
00379 
00381     void setColumnHeader(int index, const QString& label);
00382 };
00383 
00384 #endif

Generated on Mon Oct 15 06:11:42 2007 for QtiPlot by  doxygen 1.5.3