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 private:
00051     void activateNextCell();
00052 };
00053 
00060 class Table: public MyWidget, 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 
00068     Table(ScriptingEnv *env, const QString &fname,const QString &sep, int ignoredLines, bool renameCols,
00069          bool stripSpaces, bool simplifySpaces, bool importComments, const QString& commentString, bool readOnly,
00070          const QString &label, QWidget* parent=0, const QString& name = QString(), Qt::WFlags f=0);
00071     Table(ScriptingEnv *env, int r,int c, const QString &label, QWidget* parent=0, const QString& name = QString(), Qt::WFlags f=0);
00072 
00073     Q3TableSelection getSelection();
00074 
00076     void setNumericPrecision(int prec);
00078     void updateDecimalSeparators();
00080     void updateDecimalSeparators(const QLocale& oldSeparators);
00081     void resetHeader();
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 contextMenuEvent(QContextMenuEvent *e);
00133     void customEvent( QEvent* e);
00135 
00137 
00138     void removeCol();
00139     void removeCol(const QStringList& list);
00140     void clearCol();
00141     void insertCol();
00142     void insertCols(int start, int count);
00143     void addCol(PlotDesignation pd = Y);
00144     void addColumns(int c, bool readOnly = false);
00145     void moveColumn(int, int, int);
00146     void swapColumns(int, int);
00147     void moveColumnBy(int cols);
00149 
00151 
00152 
00155     void sortColAsc();
00159     void sortColDesc();
00164     void sortColumn(int col = -1, int order = 0);
00169     void sortTableDialog();
00171     void sort(int type = 0, int order  = 0, const QString& leadCol = QString());
00173     void sortColumns(int type = 0, int order = 0, const QString& leadCol = QString());
00180     void sortColumns(const QStringList& cols, int type = 0, int order = 0, const QString& leadCol = QString());
00185     void sortColumnsDialog();
00187 
00189 
00190     void normalizeCol(int col=-1);
00191     void normalizeSelection();
00192     void normalize();
00194 
00195     QVarLengthArray<double> col(int ycol);
00196     int firstXCol();
00197     bool noXColumn();
00198     bool noYColumn();
00199     int colX(int col);
00200     int colY(int col);
00201 
00202     QStringList getCommands(){return commands;};
00204     void setCommands(const QStringList& com);
00206     void setCommands(const QString& com);
00208     void setCommand(int col, const QString& com);
00210     bool calculate(int col, int startRow, int endRow);
00212     bool calculate();
00213 
00215 
00216     void deleteSelectedRows();
00217     void deleteRows(int startRow, int endRow);
00218     void insertRow();
00220 
00222 
00223     void cutSelection();
00224     void copySelection();
00225     void clearSelection();
00226     void pasteSelection();
00227     void selectAllTable();
00228     void deselect();
00229     void clear();
00231 
00232     void init(int rows, int cols);
00233     QStringList selectedColumns();
00234     QStringList selectedYColumns();
00235     QStringList selectedErrColumns();
00236     QStringList selectedYLabels();
00237     QStringList drawableColumnSelection();
00238     QStringList YColumns();
00239     int selectedColsNumber();
00240 
00241     void changeColWidth(int width, bool allCols);
00242     void changeColWidth(int width, int col);
00243     int columnWidth(int col);
00244     QStringList columnWidths();
00245     void setColWidths(const QStringList& widths);
00246 
00247     void setSelectedCol(int col){selectedCol = col;};
00248     int selectedColumn(){return selectedCol;};
00249     int firstSelectedColumn();
00250     int numSelectedRows();
00251     bool isRowSelected(int row, bool full=false) { return d_table->isRowSelected(row, full); }
00252     bool isColumnSelected(int col, bool full=false) { return d_table->isColumnSelected(col, full); }
00254     void goToRow(int row);
00255 
00256     void columnNumericFormat(int col, char *f, int *precision);
00257     void columnNumericFormat(int col, int *f, int *precision);
00258     int columnType(int col){return colTypes[col];};
00259 
00260     Q3ValueList<int> columnTypes(){return colTypes;};
00261     void setColumnTypes(Q3ValueList<int> ctl){colTypes = ctl;};
00262     void setColumnTypes(const QStringList& ctl);
00263     void setColumnType(int col, ColType val) { colTypes[col] = val; }
00264 
00265     void saveToMemory(double **cells){d_saved_cells = cells;};
00266     void saveToMemory();
00267     void freeMemory();
00268 
00269     bool isReadOnlyColumn(int col);
00270     void setReadOnlyColumn(int col, bool on = true);
00271 
00272     QString columnFormat(int col){return col_format[col];};
00273     QStringList getColumnsFormat(){return col_format;};
00274     void setColumnsFormat(const QStringList& lst);
00275 
00276     void setTextFormat(int col);
00277     void setColNumericFormat(int f, int prec, int col, bool updateCells = true);
00278     bool setDateFormat(const QString& format, int col, bool updateCells = true);
00279     bool setTimeFormat(const QString& format, int col, bool updateCells = true);
00280     void setMonthFormat(const QString& format, int col, bool updateCells = true);
00281     void setDayFormat(const QString& format, int col, bool updateCells = true);
00282 
00283     bool exportASCII(const QString& fname, const QString& separator, bool withLabels = false,
00284                      bool exportComments = false, bool exportSelection = false);
00285     void importASCII(const QString &fname, const QString &sep, int ignoredLines, bool renameCols,
00286                     bool stripSpaces, bool simplifySpaces, bool importComments, bool newTable,
00287                     const QString& commentString, bool readOnly = false);
00288     void importMultipleASCIIFiles(const QString &fname, const QString &sep, int ignoredLines,
00289                     bool renameCols, bool stripSpaces, bool simplifySpaces, bool importComments,
00290                     const QString &commentString, bool readOnly, int importFileAs);
00291 
00293 
00294     virtual QString saveToString(const QString& geometry, bool = false);
00295     QString saveHeader();
00296     QString saveComments();
00297     QString saveCommands();
00298     QString saveColumnWidths();
00299     QString saveColumnTypes();
00300     QString saveReadOnlyInfo();
00301 
00302     void setSpecifications(const QString& s);
00303     QString& getSpecifications();
00304     void restore(QString& spec);
00305     QString& getNewSpecifications();
00306     void setNewSpecifications();
00307 
00311     QString oldCaption();
00312 
00316     QString newCaption();
00318 
00319     void setBackgroundColor(const QColor& col);
00320     void setTextColor(const QColor& col);
00321     void setHeaderColor(const QColor& col);
00322     void setTextFont(const QFont& fnt);
00323     void setHeaderFont(const QFont& fnt);
00324 
00325     int verticalHeaderWidth(){return d_table->verticalHeader()->width();};
00326 
00327     QString colComment(int col){return comments[col];};
00328     void setColComment(int col, const QString& s);
00329     QStringList colComments(){return comments;};
00330     void setColComments(const QStringList& lst){comments = lst;};
00331     void showComments(bool on = true);
00332     bool commentsEnabled(){return d_show_comments;}
00333 
00334     QString saveAsTemplate(const QString& geometryInfo);
00335     void restore(const QStringList& lst);
00336 
00338     void notifyChanges();
00339 
00341     void colWidthModified(int, int, int);
00342 
00343 signals:
00344     void changedColHeader(const QString&, const QString&);
00345     void removedCol(const QString&);
00346     void modifiedData(Table *, const QString&);
00347     void optionsDialog();
00348     void colValuesDialog();
00349     void resizedTable(QWidget*);
00350     void showContextMenu(bool selection);
00351     void createTable(const QString&,int,int,const QString&);
00352 
00353 protected:
00354     MyTable *d_table;
00355 
00356 private:
00357     bool d_show_comments;
00358     QString specifications, newSpecifications;
00359     QStringList commands, col_format, comments, col_label;
00360     QList<int> colTypes, col_plot_type;
00361     QList<bool> d_read_only;
00362     int selectedCol;
00363     int d_numeric_precision;
00364     double **d_saved_cells;
00365 
00367     void setColumnHeader(int index, const QString& label);
00368 };
00369 
00370 #endif

Generated on Thu Feb 7 13:59:27 2008 for QtiPlot by  doxygen 1.5.4