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     void clone(DataCurve* c);
00109 
00110     virtual QString saveToString();
00111     void restoreLabels(const QStringList& lst);
00112 
00113     QString xColumnName(){return d_x_column;};
00114     void setXColumnName(const QString& name){d_x_column = name;};
00115 
00116     bool hasLabels(){return !d_labels_list.isEmpty();};
00117     QString labelsColumnName(){return d_labels_column;};
00118     void setLabelsColumnName(const QString& name);
00119 
00120     int labelsAlignment(){return d_labels_align;};
00121     void setLabelsAlignment(int flags);
00122 
00123     int labelsXOffset(){return d_labels_x_offset;};
00124     int labelsYOffset(){return d_labels_y_offset;};
00125     void setLabelsOffset(int x, int y);
00126 
00127     double labelsRotation(){return d_labels_angle;};
00128     void setLabelsRotation(double angle);
00129 
00130     QFont labelsFont(){return d_labels_font;};
00131     void setLabelsFont(const QFont& font);
00132 
00133     QColor labelsColor(){return d_labels_color;};
00134     void setLabelsColor(const QColor& c);
00135 
00136     bool labelsWhiteOut(){return d_white_out_labels;};
00137     void setLabelsWhiteOut(bool whiteOut = true);
00138 
00139     Table* table(){return d_table;};
00140 
00141     int startRow(){return d_start_row;};
00142     int endRow(){return d_end_row;};
00143     void setRowRange(int startRow, int endRow);
00144 
00145     bool isFullRange();
00146     void setFullRange();
00147 
00148     virtual bool updateData(Table *t, const QString& colName);
00149     virtual void loadData();
00150     void enableSpeedMode();
00151 
00153     int tableRow(int point);
00154 
00155     void remove();
00156 
00169     virtual QStringList plotAssociation();
00170     virtual void updateColumnNames(const QString& oldName, const QString& newName, bool updateTableName);
00171 
00173     QList<ErrorBarsCurve *> errorBarsList(){return d_error_bars;};
00175     void addErrorBars(ErrorBarsCurve *c){if (c) d_error_bars << c;};
00177     void removeErrorBars(ErrorBarsCurve *c);
00179     void clearErrorBars();
00181     void clearLabels();
00182 
00183     void setVisible(bool on);
00184 
00185     void setVisibleLabels(bool on = true){d_show_labels = on;};
00186     bool hasVisibleLabels(){return d_show_labels;};
00187     bool selectedLabels(const QPoint& pos);
00188     bool hasSelectedLabels();
00189     void setLabelsSelected(bool on = true);
00190 
00191     void moveLabels(const QPoint& pos);
00192     virtual void updateLabelsPosition();
00193 
00194 protected:
00195         virtual void drawCurve(QPainter *p, int style, const QwtScaleMap &xMap, const QwtScaleMap &yMap, int from, int to) const;
00196 
00197     bool validCurveType();
00198     virtual void loadLabels();
00199 
00201     QList <ErrorBarsCurve *> d_error_bars;
00203     Table *d_table;
00205     /*
00206      *The column name used for Y values is stored in title().text().
00207      */
00208     QString d_x_column;
00209 
00210     int d_start_row;
00211     int d_end_row;
00212 
00214     QString d_labels_column;
00215 
00217     QList <PlotMarker *> d_labels_list;
00219     double d_click_pos_x, d_click_pos_y;
00220 
00221     QColor d_labels_color;
00222     QFont d_labels_font;
00223     double d_labels_angle;
00224     bool d_white_out_labels;
00225     bool d_show_labels;
00226     int d_labels_align, d_labels_x_offset, d_labels_y_offset;
00228     PlotMarker *d_selected_label;
00229     std::vector<DataRange> d_data_ranges;
00230 };
00231 
00232 class PlotMarker: public QwtPlotMarker
00233 {
00234 public:
00235     PlotMarker(int index, double angle);
00236 
00237     int index(){return d_index;};
00238     void setIndex(int i){d_index = i;};
00239 
00240     double angle(){return d_angle;};
00241     void setAngle(double a){d_angle = a;};
00242 
00243     double xLabelOffset(){return d_label_x_offset;};
00244     double yLabelOffset(){return d_label_y_offset;};
00245     void setLabelOffset(double xOffset, double yOffset){d_label_x_offset = xOffset; d_label_y_offset = yOffset;};
00246 
00247 protected:
00249     void draw(QPainter *p, const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRect &r) const;
00250 
00251     int d_index;
00252     double d_angle;
00254     double d_label_x_offset;
00256     double d_label_y_offset;
00257 };
00258 #endif