QtiPlot 0.9.8.2
PlotCurve.h
Go to the documentation of this file.
00001 /***************************************************************************
00002     File                 : PlotCurve.h
00003     Project              : QtiPlot
00004     --------------------------------------------------------------------
00005     Copyright            : (C) 2007 by Ion Vasilief
00006     Email (use @ for *)  : ion_vasilief*yahoo.fr
00007     Description          : AbstractPlotCurve and DataCurve classes
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 PLOTCURVE_H
00030 #define PLOTCURVE_H
00031 
00032 #include <qwt_plot_curve.h>
00033 #include <qwt_plot_marker.h>
00034 #include <Table.h>
00035 
00036 class PlotMarker;
00037 class Table;
00038 class ErrorBarsCurve;
00039 
00041 class PlotCurve: public QwtPlotCurve
00042 {
00043 
00044 public:
00045     PlotCurve(const QString& name = QString());
00046 
00048     int type(){return d_type;};
00049     void setType(int t){d_type = t;};
00050 
00054     int plotStyle(){return d_plot_style;};
00055     void setPlotStyle(int s){d_plot_style = s;};
00056 
00057     double xOffset(){return d_x_offset;};
00058     void setXOffset(double dx){d_x_offset = dx;};
00059 
00060     double yOffset(){return d_y_offset;};
00061     void setYOffset(double dy){d_y_offset = dy;};
00062 
00063     bool sideLinesEnabled(){return d_side_lines;};
00064     void enableSideLines(bool on){d_side_lines = on;};
00065 
00066     QString saveCurveSymbolImage();
00067     QString saveCurveLayout();
00068     void restoreCurveLayout(const QStringList& lst);
00069 
00071     void setSkipSymbolsCount(int count);
00073     int skipSymbolsCount(){return d_skip_symbols;};
00074 
00075 protected:
00076     virtual void drawCurve(QPainter *p, int style, const QwtScaleMap &xMap, const QwtScaleMap &yMap, int from, int to) const;
00077     void drawSideLines(QPainter *p, const QwtScaleMap &xMap, const QwtScaleMap &yMap, int from, int to) const;
00078 
00079     virtual void drawSymbols(QPainter *p, const QwtSymbol &,
00080         const QwtScaleMap &xMap, const QwtScaleMap &yMap, int from, int to) const;
00081 
00082     void drawSticks(QPainter *p,
00083         const QwtScaleMap &xMap, const QwtScaleMap &yMap, int from, int to) const;
00084 
00085     QwtDoubleRect boundingRect() const;
00086 
00087     // Rtti
00088     int d_type;
00089     // The plot style of the curve
00090     int d_plot_style;
00091     double d_x_offset, d_y_offset;
00092     bool d_side_lines;
00093     int d_skip_symbols;
00094 };
00095 
00096 class DataCurve: public PlotCurve
00097 {
00098 
00099 public:
00100 
00101     struct DataRange
00102     {
00103             unsigned int from;
00104             unsigned int to;
00105     };
00106 
00107     DataCurve(Table *t, const QString& xColName, const QString& name, int startRow = 0, int endRow = -1);
00108     DataCurve(Table *xt, const QString& xColName, Table *yt, const QString& name, int startRow = 0, int endRow = -1);
00109     void clone(DataCurve* c);
00110 
00111     virtual QString saveToString();
00112     void restoreLabels(const QStringList& lst);
00113 
00114     QString xColumnName(){return d_x_column;};
00115     void setXColumnName(const QString& name){d_x_column = name;};
00116 
00117     bool hasLabels(){return !d_labels_list.isEmpty();};
00118     QString labelsColumnName(){return d_labels_column;};
00119     void setLabelsColumnName(const QString& name);
00120 
00121     int labelsAlignment(){return d_labels_align;};
00122     void setLabelsAlignment(int flags);
00123 
00124     int labelsXOffset(){return d_labels_x_offset;};
00125     int labelsYOffset(){return d_labels_y_offset;};
00126     void setLabelsOffset(int x, int y);
00127 
00128     double labelsRotation(){return d_labels_angle;};
00129     void setLabelsRotation(double angle);
00130 
00131     QFont labelsFont(){return d_labels_font;};
00132     void setLabelsFont(const QFont& font);
00133 
00134     QColor labelsColor(){return d_labels_color;};
00135     void setLabelsColor(const QColor& c);
00136 
00137     bool labelsWhiteOut(){return d_white_out_labels;};
00138     void setLabelsWhiteOut(bool whiteOut = true);
00139 
00140     Table* table(){return d_table;};
00141     Table* xTable(){return d_x_table;};
00142     void setDataSource(Table *yt, int ycol = 1, Table *xt = NULL, int xcol = 0);
00143 
00144     int startRow(){return d_start_row;};
00145     int endRow(){return d_end_row;};
00146     void setRowRange(int startRow, int endRow);
00147 
00148     bool isFullRange();
00149     void setFullRange();
00150 
00151     virtual bool updateData(Table *t, const QString& colName);
00152     virtual void loadData();
00153     void enableSpeedMode();
00154 
00156     int tableRow(int point);
00157 
00158     void remove();
00159 
00172     virtual QStringList plotAssociation();
00173     virtual void updateColumnNames(const QString& oldName, const QString& newName, bool updateTableName);
00174 
00176     QList<ErrorBarsCurve *> errorBarsList(){return d_error_bars;};
00178     void addErrorBars(ErrorBarsCurve *c){if (c) d_error_bars << c;};
00180     void removeErrorBars(ErrorBarsCurve *c);
00182     void clearErrorBars();
00184     void clearLabels();
00185 
00186     void setVisible(bool on);
00187 
00188     void setVisibleLabels(bool on = true){d_show_labels = on;};
00189     bool hasVisibleLabels(){return d_show_labels;};
00190     bool selectedLabels(const QPoint& pos);
00191     bool hasSelectedLabels();
00192     void setLabelsSelected(bool on = true);
00193 
00194     void moveLabels(const QPoint& pos);
00195     virtual void updateLabelsPosition();
00196 
00197 protected:
00198         virtual void drawCurve(QPainter *p, int style, const QwtScaleMap &xMap, const QwtScaleMap &yMap, int from, int to) const;
00199 
00200     bool validCurveType();
00201     virtual void loadLabels();
00202 
00204     QList <ErrorBarsCurve *> d_error_bars;
00206     Table *d_table;
00208     Table *d_x_table;
00210     /*
00211      *The column name used for Y values is stored in title().text().
00212      */
00213     QString d_x_column;
00214 
00215     int d_start_row;
00216     int d_end_row;
00217 
00219     QString d_labels_column;
00220 
00222     QList <PlotMarker *> d_labels_list;
00224     double d_click_pos_x, d_click_pos_y;
00225 
00226     QColor d_labels_color;
00227     QFont d_labels_font;
00228     double d_labels_angle;
00229     bool d_white_out_labels;
00230     bool d_show_labels;
00231     int d_labels_align, d_labels_x_offset, d_labels_y_offset;
00233     PlotMarker *d_selected_label;
00234     std::vector<DataRange> d_data_ranges;
00235 };
00236 
00237 class PlotMarker: public QwtPlotMarker
00238 {
00239 public:
00240     PlotMarker(int index, double angle);
00241 
00242     int index(){return d_index;};
00243     void setIndex(int i){d_index = i;};
00244 
00245     double angle(){return d_angle;};
00246     void setAngle(double a){d_angle = a;};
00247 
00248     double xLabelOffset(){return d_label_x_offset;};
00249     double yLabelOffset(){return d_label_y_offset;};
00250     void setLabelOffset(double xOffset, double yOffset){d_label_x_offset = xOffset; d_label_y_offset = yOffset;};
00251 
00252 protected:
00254     void draw(QPainter *p, const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRect &r) const;
00255 
00256     int d_index;
00257     double d_angle;
00259     double d_label_x_offset;
00261     double d_label_y_offset;
00262 };
00263 #endif