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 
00039 class PlotCurve: public QwtPlotCurve
00040 {
00041 
00042 public:
00043     PlotCurve(const QString& name = QString()): QwtPlotCurve(name), d_type(0), d_x_offset(0.0), d_y_offset(0.0){};
00044 
00045     int type(){return d_type;};
00046     void setType(int t){d_type = t;};
00047 
00048     double xOffset(){return d_x_offset;};
00049     void setXOffset(double dx){d_x_offset = dx;};
00050 
00051     double yOffset(){return d_y_offset;};
00052     void setYOffset(double dy){d_y_offset = dy;};
00053 
00054     QwtDoubleRect boundingRect() const;
00055 
00056 protected:
00057     int d_type;
00058     double d_x_offset, d_y_offset;
00059 };
00060 
00061 class DataCurve: public PlotCurve
00062 {
00063 public:
00064     DataCurve(Table *t, const QString& xColName, const QString& name, int startRow = 0, int endRow = -1);
00065     void clone(DataCurve* c);
00066 
00067     QString saveToString();
00068 
00069     QString xColumnName(){return d_x_column;};
00070     void setXColumnName(const QString& name){d_x_column = name;};
00071 
00072     bool hasLabels(){return !d_labels_list.isEmpty();};
00073     QString labelsColumnName(){return d_labels_column;};
00074     void setLabelsColumnName(const QString& name);
00075 
00076     int labelsAlignment(){return d_labels_align;};
00077     void setLabelsAlignment(int flags);
00078 
00079     int labelsXOffset(){return d_labels_x_offset;};
00080     int labelsYOffset(){return d_labels_y_offset;};
00081     void setLabelsOffset(int x, int y);
00082 
00083     double labelsRotation(){return d_labels_angle;};
00084     void setLabelsRotation(double angle);
00085 
00086     QFont labelsFont(){return d_labels_font;};
00087     void setLabelsFont(const QFont& font);
00088 
00089     QColor labelsColor(){return d_labels_color;};
00090     void setLabelsColor(const QColor& c);
00091 
00092     bool labelsWhiteOut(){return d_white_out_labels;};
00093     void setLabelsWhiteOut(bool whiteOut = true);
00094 
00095     Table* table(){return d_table;};
00096 
00097     int startRow(){return d_start_row;};
00098     int endRow(){return d_end_row;};
00099     void setRowRange(int startRow, int endRow);
00100 
00101     bool isFullRange();
00102     void setFullRange();
00103 
00104     virtual bool updateData(Table *t, const QString& colName);
00105     virtual void loadData();
00106 
00108     int tableRow(int point);
00109 
00110     void remove();
00111 
00124     virtual QString plotAssociation();
00125     virtual void updateColumnNames(const QString& oldName, const QString& newName, bool updateTableName);
00126 
00128     QList<DataCurve *> errorBarsList(){return d_error_bars;};
00130     void addErrorBars(DataCurve *c){if (c) d_error_bars << c;};
00132     void removeErrorBars(DataCurve *c);
00134     void clearErrorBars();
00136     void clearLabels();
00137 
00138     void setVisible(bool on);
00139 
00140     bool selectedLabels(const QPoint& pos);
00141     bool hasSelectedLabels();
00142     void setLabelsSelected(bool on = true);
00143 
00144     void moveLabels(const QPoint& pos);
00145     void updateLabelsPosition();
00146 
00147 protected:
00148     bool validCurveType();
00149     void loadLabels();
00150 
00152     QList <DataCurve *> d_error_bars;
00154     Table *d_table;
00156     /*
00157      *The column name used for Y values is stored in title().text().
00158      */
00159     QString d_x_column;
00160 
00161     int d_start_row;
00162     int d_end_row;
00163 
00165     QString d_labels_column;
00166 
00168     QList <PlotMarker *> d_labels_list;
00170     PlotMarker *d_selected_label;
00172     double d_click_pos_x, d_click_pos_y;
00173 
00174     QColor d_labels_color;
00175     QFont d_labels_font;
00176     double d_labels_angle;
00177     bool d_white_out_labels;
00178     int d_labels_align, d_labels_x_offset, d_labels_y_offset;
00179 };
00180 
00181 class PlotMarker: public QwtPlotMarker
00182 {
00183 public:
00184     PlotMarker(int index, double angle);
00185 
00186     int index(){return d_index;};
00187     void setIndex(int i){d_index = i;};
00188 
00189     double angle(){return d_angle;};
00190     void setAngle(double a){d_angle = a;};
00191 
00192     //QwtDoubleRect boundingRect() const;
00193 
00194 protected:
00196     void draw(QPainter *p, const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRect &r) const;
00197 
00198     int d_index;
00199     double d_angle;
00200 };
00201 #endif

Generated on Thu Feb 7 13:59:27 2008 for QtiPlot by  doxygen 1.5.4