QtiPlot 0.9.7.3

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 
00040 class PlotCurve: public QwtPlotCurve
00041 {
00042 
00043 public:
00044     PlotCurve(const QString& name = QString());
00045 
00047     int type(){return d_type;};
00048     void setType(int t){d_type = t;};
00049 
00053     int plotStyle(){return d_plot_style;};
00054     void setPlotStyle(int s){d_plot_style = s;};
00055 
00056     double xOffset(){return d_x_offset;};
00057     void setXOffset(double dx){d_x_offset = dx;};
00058 
00059     double yOffset(){return d_y_offset;};
00060     void setYOffset(double dy){d_y_offset = dy;};
00061 
00062     bool sideLinesEnabled(){return d_side_lines;};
00063     void enableSideLines(bool on){d_side_lines = on;};
00064 
00065     QString saveCurveLayout();
00066     void restoreCurveLayout(const QStringList& lst);
00067 
00069     void setSkipSymbolsCount(int count);
00071     int skipSymbolsCount(){return d_skip_symbols;};
00072 
00073 protected:
00074     virtual void drawCurve(QPainter *p, int style, const QwtScaleMap &xMap, const QwtScaleMap &yMap, int from, int to) const;
00075     void drawSideLines(QPainter *p, const QwtScaleMap &xMap, const QwtScaleMap &yMap, int from, int to) const;
00076 
00077     virtual void drawSymbols(QPainter *p, const QwtSymbol &,
00078         const QwtScaleMap &xMap, const QwtScaleMap &yMap, int from, int to) const;
00079 
00080     void drawSticks(QPainter *p,
00081         const QwtScaleMap &xMap, const QwtScaleMap &yMap, int from, int to) const;
00082 
00083     QwtDoubleRect boundingRect() const;
00084 
00085     // Rtti
00086     int d_type;
00087     // The plot style of the curve
00088     int d_plot_style;
00089     double d_x_offset, d_y_offset;
00090     bool d_side_lines;
00091     int d_skip_symbols;
00092 };
00093 
00094 class DataCurve: public PlotCurve
00095 {
00096 
00097 public:
00098 
00099     struct DataRange
00100     {
00101             unsigned int from;
00102             unsigned int to;
00103     };
00104 
00105     DataCurve(Table *t, const QString& xColName, const QString& name, int startRow = 0, int endRow = -1);
00106     void clone(DataCurve* c);
00107 
00108     virtual QString saveToString();
00109     void restoreLabels(const QStringList& lst);
00110 
00111     QString xColumnName(){return d_x_column;};
00112     void setXColumnName(const QString& name){d_x_column = name;};
00113 
00114     bool hasLabels(){return !d_labels_list.isEmpty();};
00115     QString labelsColumnName(){return d_labels_column;};
00116     void setLabelsColumnName(const QString& name);
00117 
00118     int labelsAlignment(){return d_labels_align;};
00119     void setLabelsAlignment(int flags);
00120 
00121     int labelsXOffset(){return d_labels_x_offset;};
00122     int labelsYOffset(){return d_labels_y_offset;};
00123     void setLabelsOffset(int x, int y);
00124 
00125     double labelsRotation(){return d_labels_angle;};
00126     void setLabelsRotation(double angle);
00127 
00128     QFont labelsFont(){return d_labels_font;};
00129     void setLabelsFont(const QFont& font);
00130 
00131     QColor labelsColor(){return d_labels_color;};
00132     void setLabelsColor(const QColor& c);
00133 
00134     bool labelsWhiteOut(){return d_white_out_labels;};
00135     void setLabelsWhiteOut(bool whiteOut = true);
00136 
00137     Table* table(){return d_table;};
00138 
00139     int startRow(){return d_start_row;};
00140     int endRow(){return d_end_row;};
00141     void setRowRange(int startRow, int endRow);
00142 
00143     bool isFullRange();
00144     void setFullRange();
00145 
00146     virtual bool updateData(Table *t, const QString& colName);
00147     virtual void loadData();
00148     void enableSpeedMode();
00149 
00151     int tableRow(int point);
00152 
00153     void remove();
00154 
00167     virtual QString plotAssociation();
00168     virtual void updateColumnNames(const QString& oldName, const QString& newName, bool updateTableName);
00169 
00171     QList<DataCurve *> errorBarsList(){return d_error_bars;};
00173     void addErrorBars(DataCurve *c){if (c) d_error_bars << c;};
00175     void removeErrorBars(DataCurve *c);
00177     void clearErrorBars();
00179     void clearLabels();
00180 
00181     void setVisible(bool on);
00182 
00183     bool selectedLabels(const QPoint& pos);
00184     bool hasSelectedLabels();
00185     void setLabelsSelected(bool on = true);
00186 
00187     void moveLabels(const QPoint& pos);
00188     void updateLabelsPosition();
00189 
00190 protected:
00191         virtual void drawCurve(QPainter *p, int style, const QwtScaleMap &xMap, const QwtScaleMap &yMap, int from, int to) const;
00192 
00193     bool validCurveType();
00194     void loadLabels();
00195 
00197     QList <DataCurve *> d_error_bars;
00199     Table *d_table;
00201     /*
00202      *The column name used for Y values is stored in title().text().
00203      */
00204     QString d_x_column;
00205 
00206     int d_start_row;
00207     int d_end_row;
00208 
00210     QString d_labels_column;
00211 
00213     QList <PlotMarker *> d_labels_list;
00215     double d_click_pos_x, d_click_pos_y;
00216 
00217     QColor d_labels_color;
00218     QFont d_labels_font;
00219     double d_labels_angle;
00220     bool d_white_out_labels;
00221     int d_labels_align, d_labels_x_offset, d_labels_y_offset;
00223     PlotMarker *d_selected_label;
00224     std::vector<DataRange> d_data_ranges;
00225 };
00226 
00227 class PlotMarker: public QwtPlotMarker
00228 {
00229 public:
00230     PlotMarker(int index, double angle);
00231 
00232     int index(){return d_index;};
00233     void setIndex(int i){d_index = i;};
00234 
00235     double angle(){return d_angle;};
00236     void setAngle(double a){d_angle = a;};
00237 
00238     double xLabelOffset(){return d_label_x_offset;};
00239     double yLabelOffset(){return d_label_y_offset;};
00240     void setLabelOffset(double xOffset, double yOffset){d_label_x_offset = xOffset; d_label_y_offset = yOffset;};
00241 
00242 protected:
00244     void draw(QPainter *p, const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRect &r) const;
00245 
00246     int d_index;
00247     double d_angle;
00249     double d_label_x_offset;
00251     double d_label_y_offset;
00252 };
00253 #endif