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()): QwtPlotCurve(name), d_type(0), d_plot_style(0), d_x_offset(0.0), d_y_offset(0.0){};
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     QString saveCurveLayout();
00063     void restoreCurveLayout(const QStringList& lst);
00064 
00065 protected:
00066     // Rtti
00067     int d_type;
00068     // The plot style of the curve
00069     int d_plot_style;
00070     double d_x_offset, d_y_offset;
00071 };
00072 
00073 class DataCurve: public PlotCurve
00074 {
00075 public:
00076     DataCurve(Table *t, const QString& xColName, const QString& name, int startRow = 0, int endRow = -1);
00077     void clone(DataCurve* c);
00078 
00079     QString saveToString();
00080 
00081     QString xColumnName(){return d_x_column;};
00082     void setXColumnName(const QString& name){d_x_column = name;};
00083 
00084     bool hasLabels(){return !d_labels_list.isEmpty();};
00085     QString labelsColumnName(){return d_labels_column;};
00086     void setLabelsColumnName(const QString& name);
00087 
00088     int labelsAlignment(){return d_labels_align;};
00089     void setLabelsAlignment(int flags);
00090 
00091     int labelsXOffset(){return d_labels_x_offset;};
00092     int labelsYOffset(){return d_labels_y_offset;};
00093     void setLabelsOffset(int x, int y);
00094 
00095     double labelsRotation(){return d_labels_angle;};
00096     void setLabelsRotation(double angle);
00097 
00098     QFont labelsFont(){return d_labels_font;};
00099     void setLabelsFont(const QFont& font);
00100 
00101     QColor labelsColor(){return d_labels_color;};
00102     void setLabelsColor(const QColor& c);
00103 
00104     bool labelsWhiteOut(){return d_white_out_labels;};
00105     void setLabelsWhiteOut(bool whiteOut = true);
00106 
00107     Table* table(){return d_table;};
00108 
00109     int startRow(){return d_start_row;};
00110     int endRow(){return d_end_row;};
00111     void setRowRange(int startRow, int endRow);
00112 
00113     bool isFullRange();
00114     void setFullRange();
00115 
00116     virtual bool updateData(Table *t, const QString& colName);
00117     virtual void loadData();
00118 
00120     int tableRow(int point);
00121 
00122     void remove();
00123 
00136     virtual QString plotAssociation();
00137     virtual void updateColumnNames(const QString& oldName, const QString& newName, bool updateTableName);
00138 
00140     QList<DataCurve *> errorBarsList(){return d_error_bars;};
00142     void addErrorBars(DataCurve *c){if (c) d_error_bars << c;};
00144     void removeErrorBars(DataCurve *c);
00146     void clearErrorBars();
00148     void clearLabels();
00149 
00150     void setVisible(bool on);
00151 
00152     bool selectedLabels(const QPoint& pos);
00153     bool hasSelectedLabels();
00154     void setLabelsSelected(bool on = true);
00155 
00156     void moveLabels(const QPoint& pos);
00157     void updateLabelsPosition();
00158 
00159 protected:
00160     bool validCurveType();
00161     void loadLabels();
00162 
00164     QList <DataCurve *> d_error_bars;
00166     Table *d_table;
00168     /*
00169      *The column name used for Y values is stored in title().text().
00170      */
00171     QString d_x_column;
00172 
00173     int d_start_row;
00174     int d_end_row;
00175 
00177     QString d_labels_column;
00178 
00180     QList <PlotMarker *> d_labels_list;
00182     double d_click_pos_x, d_click_pos_y;
00183 
00184     QColor d_labels_color;
00185     QFont d_labels_font;
00186     double d_labels_angle;
00187     bool d_white_out_labels;
00188     int d_labels_align, d_labels_x_offset, d_labels_y_offset;
00190     PlotMarker *d_selected_label;
00191 };
00192 
00193 class PlotMarker: public QwtPlotMarker
00194 {
00195 public:
00196     PlotMarker(int index, double angle);
00197 
00198     int index(){return d_index;};
00199     void setIndex(int i){d_index = i;};
00200 
00201     double angle(){return d_angle;};
00202     void setAngle(double a){d_angle = a;};
00203 
00204     //QwtDoubleRect boundingRect() const;
00205 
00206 protected:
00208     void draw(QPainter *p, const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRect &r) const;
00209 
00210     int d_index;
00211     double d_angle;
00212 };
00213 #endif

Generated on Fri Nov 7 03:36:52 2008 for QtiPlot by  doxygen 1.5.6