Table.h
Go to the documentation of this file.
/***************************************************************************
File : Table.h
Project : QtiPlot
--------------------------------------------------------------------
Copyright : (C) 2006 by Ion Vasilief, Knut Franke
Email (use @ for *) : ion_vasilief*yahoo.fr
Description : Table worksheet class
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the Free Software *
* Foundation, Inc., 51 Franklin Street, Fifth Floor, *
* Boston, MA 02110-1301 USA *
* *
***************************************************************************/
#ifndef TABLE_H
#define TABLE_H
#include <q3table.h>
#include <q3header.h>
#include <QVarLengthArray>
#include <QLocale>
#include <MdiSubWindow.h>
#include <ScriptingEnv.h>
#include <Script.h>
class MyTable : public Q3Table
{
public:
MyTable(QWidget * parent = 0, const char * name = 0);
MyTable(int numRows, int numCols, QWidget * parent = 0, const char * name = 0);
private:
void activateNextCell();
};
class Table: public MdiSubWindow, public scripted
{
Q_OBJECT
public:
enum PlotDesignation{All = -1, None = 0, X = 1, Y = 2, Z = 3, xErr = 4, yErr = 5, Label = 6};
enum ColType{Numeric = 0, Text = 1, Date = 2, Time = 3, Month = 4, Day = 5};
enum NumericFormat{Default = 0, Decimal = 1, Scientific = 2};
enum ImportMode {
NewColumns,
NewRows,
Overwrite
};
Table(ScriptingEnv *env, int r,int c, const QString &label, ApplicationWindow* parent, const QString& name = QString(), Qt::WFlags f=0);
Q3TableSelection getSelection();
void setNumericPrecision(int prec);
void updateDecimalSeparators(const QLocale& oldSeparators);
void setAutoUpdateValues(bool on = true);
virtual QString sizeToString();
double avg(int col, int startRow = 0, int endRow = -1);
double sum(int col, int startRow = 0, int endRow = -1);
double minColumnValue(int col, int startRow = 0, int endRow = -1);
double maxColumnValue(int col, int startRow = 0, int endRow = -1);
Table* extractData(const QString& name, const QString& condition, int startRow = 0, int endRow = -1);
static QDateTime dateTime(double val);
static double fromDateTime(const QDateTime& dt);
static double fromTime(const QTime& t);
public slots:
MyTable* table(){return d_table;};
void copy(Table *m, bool values = true);
int numRows();
int numCols();
void setNumRows(int rows);
void setNumCols(int cols);
void resizeRows(int);
void resizeCols(int);
double cell(int row, int col);
void setCell(int row, int col, double val);
QString text(int row, int col);
QStringList columnsList();
QStringList colNames(){return col_label;}
QString colName(int col);
void setColName(int col, const QString& text, bool enumerateRight = false, bool warn = true);
QString colLabel(int col);
int colIndex(const QString& name);
int colPlotDesignation(int col){return col_plot_type[col];};
void setColPlotDesignation(int col, PlotDesignation pd);
void setPlotDesignation(PlotDesignation pd, bool rightColumns = false);
QList<int> plotDesignations(){return col_plot_type;};
void setHeader(QStringList header);
void loadHeader(QStringList header);
void setHeaderColType();
void setText(int row,int col,const QString & text);
void setRandomValues();
void setRandomValues(int col, int startRow = 0, int endRow = -1);
void setNormalRandomValues();
void setNormalRandomValues(int col, int startRow = 0, int endRow = -1, double sigma = 1.0);
void setAscValues();
void cellEdited(int,int col);
void moveCurrentCell();
void clearCell(int row, int col);
bool isEmptyRow(int row);
bool isEmptyColumn(int col);
int nonEmptyRows();
void print();
void print(QPrinter *);
void print(const QString& fileName);
void exportPDF(const QString& fileName);
bool eventFilter(QObject *object, QEvent *e);
void customEvent( QEvent* e);
void removeCol();
void removeCol(const QStringList& list);
void insertCol();
virtual void insertCols(int start, int count);
virtual void addCol(PlotDesignation pd = Y);
void addColumns(int c);
virtual void moveColumn(int, int, int);
void swapColumns(int, int);
void moveColumnBy(int cols);
void hideSelectedColumns();
void showAllColumns();
void hideColumn(int col, bool = true);
bool isColumnHidden(int col){return d_table->isColumnHidden(col);};
void sortColAsc();
void sortColDesc();
void sortColumn(int col = -1, int order = 0);
void sortTableDialog();
void sort(int type = 0, int order = 0, const QString& leadCol = QString());
void sortColumns(int type = 0, int order = 0, const QString& leadCol = QString());
void sortColumns(const QStringList& cols, int type = 0, int order = 0, const QString& leadCol = QString());
void sortColumnsDialog();
void normalizeCol(int col=-1);
void normalizeSelection();
void normalize();
QVarLengthArray<double> col(int ycol);
void columnRange(int c, double *min, double *max);
int firstXCol();
bool noXColumn();
bool noYColumn();
int colX(int col);
int colY(int col, int xCol = -1, const QStringList& lst = QStringList());
QStringList getCommands(){return commands;};
void clearCommands();
void setCommands(const QStringList& com);
void setCommands(const QString& com);
void setCommand(int col, const QString& com);
bool calculate(int col, int startRow, int endRow, bool forceMuParser = false, bool notifyChanges = true);
bool muParserCalculate(int col, int startRow, int endRow, bool notifyChanges = true);
bool calculate();
void updateValues(Table*, const QString& columnName);
void deleteSelectedRows();
void deleteRows(int startRow, int endRow);
void insertRow();
void moveRow(bool up = true);
void cutSelection();
void copySelection();
void clearSelection();
void pasteSelection();
void selectAllTable();
void deselect();
void clear();
void init(int rows, int cols);
QStringList writableSelectedColumns();
QStringList selectedColumns();
QStringList selectedYColumns();
QStringList selectedErrColumns();
QStringList selectedYLabels();
QStringList drawableColumnSelection();
QStringList YColumns();
int selectedColsNumber();
void setColumnWidth(int width, bool allCols);
void setColumnWidth(int col, int width);
int columnWidth(int col);
QStringList columnWidths();
void setColWidths(const QStringList& widths);
void adjustColumnsWidth(bool selection = true);
void setSelectedCol(int col){selectedCol = col;};
int selectedColumn(){return selectedCol;};
int firstSelectedColumn();
int numSelectedRows();
bool isRowSelected(int row, bool full=false) { return d_table->isRowSelected(row, full); }
bool isColumnSelected(int col, bool full=false) { return d_table->isColumnSelected(col, full); }
void goToRow(int row);
void goToColumn(int col);
void columnNumericFormat(int col, char *f, int *precision);
void columnNumericFormat(int col, int *f, int *precision);
int columnType(int col){return colTypes[col];};
QList<int> columnTypes(){return colTypes;};
void setColumnTypes(QList<int> ctl){colTypes = ctl;};
void setColumnTypes(const QStringList& ctl);
void setColumnType(int col, ColType val) { colTypes[col] = val; }
void saveToMemory(double **cells){d_saved_cells = cells;};
void saveToMemory();
void freeMemory();
bool isReadOnlyColumn(int col);
void setReadOnlyColumn(int col, bool on = true);
QString columnFormat(int col){return col_format[col];};
QStringList getColumnsFormat(){return col_format;};
void setColumnsFormat(const QStringList& lst);
void setTextFormat(int col);
void setColNumericFormat(int col);
void setColNumericFormat(int f, int prec, int col, bool updateCells = true);
bool setDateFormat(const QString& format, int col, bool updateCells = true);
bool setTimeFormat(const QString& format, int col, bool updateCells = true);
void setMonthFormat(const QString& format, int col, bool updateCells = true);
void setDayFormat(const QString& format, int col, bool updateCells = true);
bool exportExcel(const QString& fname, bool withLabels, bool exportComments, bool exportSelection);
bool exportOdsSpreadsheet(const QString& fname, bool withLabels, bool exportComments, bool exportSelection);
bool exportODF(const QString& fname, bool withLabels, bool exportComments, bool exportSelection);
bool exportASCII(const QString& fname, const QString& separator, bool withLabels = false,
bool exportComments = false, bool exportSelection = false);
void importASCII(const QString &fname, const QString &sep = "\t", int ignoredLines = 0, bool renameCols = false,
bool stripSpaces = false, bool simplifySpaces = false, bool importComments = false,
const QString& commentString = "", bool readOnly = false,
ImportMode importAs = Overwrite, const QLocale& importLocale = QLocale(), int endLine = 0, int maxRows = -1,
const QList<int>& newColTypes = QList<int>(), const QStringList& colFormats = QStringList());
virtual void save(const QString &fn, const QString& geometry, bool = false);
void restore(const QStringList& lst);
QString saveHeader();
QString saveComments();
QString saveCommands();
QString saveColumnWidths();
QString saveColumnTypes();
QString saveReadOnlyInfo();
QString saveHiddenColumnsInfo();
void setBackgroundColor(const QColor& col);
void setTextColor(const QColor& col);
void setHeaderColor(const QColor& col);
void setTextFont(const QFont& fnt);
void setHeaderFont(const QFont& fnt);
int verticalHeaderWidth(){return d_table->verticalHeader()->width();};
QString comment(int col);
void setColComment(int col, const QString& s);
QStringList colComments(){return comments;};
void setColComments(const QStringList& lst){comments = lst;};
void showComments(bool on = true);
bool commentsEnabled(){return d_show_comments;}
void notifyChanges();
void notifyChanges(const QString& colName);
void colWidthModified(int, int, int);
signals:
void changedColHeader(const QString&, const QString&);
void removedCol(const QString&);
void addedCol(const QString&);
void removedCol(int);
void colIndexChanged(int, int);
void modifiedData(Table *, const QString&);
void optionsDialog();
void colValuesDialog();
void resizedTable(QWidget*);
void showContextMenu(bool selection);
protected:
MyTable *d_table;
private:
void clearCol();
bool d_show_comments;
QStringList commands, col_format, comments, col_label;
QList<int> colTypes, col_plot_type;
int selectedCol;
int d_numeric_precision;
double **d_saved_cells;
void setColumnHeader(int index, const QString& label);
};
#endif
Table::selectedCol
int selectedCol
Definition: Table.h:377
Table::isColumnHidden
bool isColumnHidden(int col)
Definition: Table.h:160
Table::plotDesignations
QList< int > plotDesignations()
Definition: Table.h:116
MyTable::activateNextCell
void activateNextCell()
Definition: Table.cpp:4003
Table::getCommands
QStringList getCommands()
Definition: Table.h:217
Table::columnTypes
QList< int > columnTypes()
Definition: Table.h:286
Table::isColumnSelected
bool isColumnSelected(int col, bool full=false)
Definition: Table.h:276
Table::setColumnType
void setColumnType(int col, ColType val)
Definition: Table.h:289
MyTable
Definition: Table.h:41
Table::ImportMode
ImportMode
Definition: Table.h:65
ScriptingEnv
An interpreter for evaluating scripting code. Abstract.
Definition: ScriptingEnv.h:50
Table::NewRows
add file as new rows to this table
Definition: Table.h:67
ScriptingEnv.h
Table::verticalHeaderWidth
int verticalHeaderWidth()
Definition: Table.h:340
Table::selectedColumn
int selectedColumn()
Definition: Table.h:272
Table::colTypes
QList< int > colTypes
Definition: Table.h:376
Table::colPlotDesignation
int colPlotDesignation(int col)
Definition: Table.h:113
Script.h
Table::NewColumns
add file as new columns to this table
Definition: Table.h:66
min
#define min(a, b)
Definition: ShapiroWilkTest.cpp:36
Table::d_table
MyTable * d_table
Definition: Table.h:369
ApplicationWindow
QtiPlot&#39;s main window.
Definition: ApplicationWindow.h:133
Table::colComments
QStringList colComments()
Definition: Table.h:344
Table::getColumnsFormat
QStringList getColumnsFormat()
Definition: Table.h:299
Table::d_show_comments
bool d_show_comments
Definition: Table.h:374
Table::ColType
ColType
Definition: Table.h:63
Table::columnFormat
QString columnFormat(int col)
Definition: Table.h:298
Table::setColComments
void setColComments(const QStringList &lst)
Definition: Table.h:345
Table::setSelectedCol
void setSelectedCol(int col)
Definition: Table.h:271
Table::d_saved_cells
double ** d_saved_cells
Definition: Table.h:379
Table::table
MyTable * table()
Definition: Table.h:92
Table::columnType
int columnType(int col)
Definition: Table.h:284
Table::comments
QStringList comments
Definition: Table.h:375
Table::colNames
QStringList colNames()
Definition: Table.h:107
Table::saveToMemory
void saveToMemory(double **cells)
Definition: Table.h:291
MdiSubWindow
Base class of all MDI client windows.
Definition: MdiSubWindow.h:51
scripted
Interface for maintaining a reference to the current ScriptingEnv.
Definition: Script.h:152
MyTable::MyTable
MyTable(QWidget *parent=0, const char *name=0)
Definition: Table.cpp:3995
Table::d_numeric_precision
int d_numeric_precision
Definition: Table.h:378
Table::PlotDesignation
PlotDesignation
Definition: Table.h:62
Table::NumericFormat
NumericFormat
Definition: Table.h:64
Table
MDI window providing a spreadsheet table with column logic.
Definition: Table.h:57
MdiSubWindow.h
Table::setColumnTypes
void setColumnTypes(QList< int > ctl)
Definition: Table.h:287
Table::isRowSelected
bool isRowSelected(int row, bool full=false)
Definition: Table.h:275
Table::commentsEnabled
bool commentsEnabled()
Definition: Table.h:347