QtiPlot  0.9.8.2
PlotCurve.h
Go to the documentation of this file.
1 /***************************************************************************
2  File : PlotCurve.h
3  Project : QtiPlot
4  --------------------------------------------------------------------
5  Copyright : (C) 2007 by Ion Vasilief
6  Email (use @ for *) : ion_vasilief*yahoo.fr
7  Description : AbstractPlotCurve and DataCurve classes
8 
9  ***************************************************************************/
10 
11 /***************************************************************************
12  * *
13  * This program is free software; you can redistribute it and/or modify *
14  * it under the terms of the GNU General Public License as published by *
15  * the Free Software Foundation; either version 2 of the License, or *
16  * (at your option) any later version. *
17  * *
18  * This program is distributed in the hope that it will be useful, *
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
21  * GNU General Public License for more details. *
22  * *
23  * You should have received a copy of the GNU General Public License *
24  * along with this program; if not, write to the Free Software *
25  * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
26  * Boston, MA 02110-1301 USA *
27  * *
28  ***************************************************************************/
29 #ifndef PLOTCURVE_H
30 #define PLOTCURVE_H
31 
32 #include <qwt_plot_curve.h>
33 #include <qwt_plot_marker.h>
34 #include <Table.h>
35 
36 class PlotMarker;
37 class Table;
38 class ErrorBarsCurve;
39 
41 class PlotCurve: public QwtPlotCurve
42 {
43 
44 public:
45  PlotCurve(const QString& name = QString());
46 
48  int type(){return d_type;};
49  void setType(int t){d_type = t;};
50 
54  int plotStyle(){return d_plot_style;};
55  void setPlotStyle(int s){d_plot_style = s;};
56 
57  double xOffset(){return d_x_offset;};
58  void setXOffset(double dx){d_x_offset = dx;};
59 
60  double yOffset(){return d_y_offset;};
61  void setYOffset(double dy){d_y_offset = dy;};
62 
63  bool sideLinesEnabled(){return d_side_lines;};
64  void enableSideLines(bool on){d_side_lines = on;};
65 
66  QString saveCurveSymbolImage();
67  QString saveCurveLayout();
68  void restoreCurveLayout(const QStringList& lst);
69 
71  void setSkipSymbolsCount(int count);
74 
75 protected:
76  virtual void drawCurve(QPainter *p, int style, const QwtScaleMap &xMap, const QwtScaleMap &yMap, int from, int to) const;
77  void drawSideLines(QPainter *p, const QwtScaleMap &xMap, const QwtScaleMap &yMap, int from, int to) const;
78 
79  virtual void drawSymbols(QPainter *p, const QwtSymbol &,
80  const QwtScaleMap &xMap, const QwtScaleMap &yMap, int from, int to) const;
81 
82  void drawSticks(QPainter *p,
83  const QwtScaleMap &xMap, const QwtScaleMap &yMap, int from, int to) const;
84 
85  QwtDoubleRect boundingRect() const;
86 
87  // Rtti
88  int d_type;
89  // The plot style of the curve
94 };
95 
96 class DataCurve: public PlotCurve
97 {
98 
99 public:
100 
101  struct DataRange
102  {
103  unsigned int from;
104  unsigned int to;
105  };
106 
107  DataCurve(Table *t, const QString& xColName, const QString& name, int startRow = 0, int endRow = -1);
108  DataCurve(Table *xt, const QString& xColName, Table *yt, const QString& name, int startRow = 0, int endRow = -1);
109  void clone(DataCurve* c);
110 
111  virtual QString saveToString();
112  void restoreLabels(const QStringList& lst);
113 
114  QString xColumnName(){return d_x_column;};
115  void setXColumnName(const QString& name){d_x_column = name;};
116 
117  bool hasLabels(){return !d_labels_list.isEmpty();};
118  QString labelsColumnName(){return d_labels_column;};
119  void setLabelsColumnName(const QString& name);
120 
121  int labelsAlignment(){return d_labels_align;};
122  void setLabelsAlignment(int flags);
123 
124  int labelsXOffset(){return d_labels_x_offset;};
125  int labelsYOffset(){return d_labels_y_offset;};
126  void setLabelsOffset(int x, int y);
127 
128  double labelsRotation(){return d_labels_angle;};
129  void setLabelsRotation(double angle);
130 
131  QFont labelsFont(){return d_labels_font;};
132  void setLabelsFont(const QFont& font);
133 
134  QColor labelsColor(){return d_labels_color;};
135  void setLabelsColor(const QColor& c);
136 
137  bool labelsWhiteOut(){return d_white_out_labels;};
138  void setLabelsWhiteOut(bool whiteOut = true);
139 
140  Table* table(){return d_table;};
141  Table* xTable(){return d_x_table;};
142  void setDataSource(Table *yt, int ycol = 1, Table *xt = NULL, int xcol = 0);
143 
144  int startRow(){return d_start_row;};
145  int endRow(){return d_end_row;};
146  void setRowRange(int startRow, int endRow);
147 
148  bool isFullRange();
149  void setFullRange();
150 
151  virtual bool updateData(Table *t, const QString& colName);
152  virtual void loadData();
153  void enableSpeedMode();
154 
156  int tableRow(int point);
157 
158  void remove();
159 
172  virtual QStringList plotAssociation();
173  virtual void updateColumnNames(const QString& oldName, const QString& newName, bool updateTableName);
174 
176  QList<ErrorBarsCurve *> errorBarsList(){return d_error_bars;};
178  void addErrorBars(ErrorBarsCurve *c){if (c) d_error_bars << c;};
180  void removeErrorBars(ErrorBarsCurve *c);
182  void clearErrorBars();
184  void clearLabels();
185 
186  void setVisible(bool on);
187 
188  void setVisibleLabels(bool on = true){d_show_labels = on;};
189  bool hasVisibleLabels(){return d_show_labels;};
190  bool selectedLabels(const QPoint& pos);
191  bool hasSelectedLabels();
192  void setLabelsSelected(bool on = true);
193 
194  void moveLabels(const QPoint& pos);
195  virtual void updateLabelsPosition();
196 
197 protected:
198  virtual void drawCurve(QPainter *p, int style, const QwtScaleMap &xMap, const QwtScaleMap &yMap, int from, int to) const;
199 
200  bool validCurveType();
201  virtual void loadLabels();
202 
204  QList <ErrorBarsCurve *> d_error_bars;
210  /*
211  *The column name used for Y values is stored in title().text().
212  */
213  QString d_x_column;
214 
217 
220 
222  QList <PlotMarker *> d_labels_list;
224  double d_click_pos_x, d_click_pos_y;
225 
231  int d_labels_align, d_labels_x_offset, d_labels_y_offset;
234  std::vector<DataRange> d_data_ranges;
235 };
236 
237 class PlotMarker: public QwtPlotMarker
238 {
239 public:
240  PlotMarker(int index, double angle);
241 
242  int index(){return d_index;};
243  void setIndex(int i){d_index = i;};
244 
245  double angle(){return d_angle;};
246  void setAngle(double a){d_angle = a;};
247 
248  double xLabelOffset(){return d_label_x_offset;};
249  double yLabelOffset(){return d_label_y_offset;};
250  void setLabelOffset(double xOffset, double yOffset){d_label_x_offset = xOffset; d_label_y_offset = yOffset;};
251 
252 protected:
254  void draw(QPainter *p, const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRect &r) const;
255 
256  int d_index;
257  double d_angle;
262 };
263 #endif
QString saveCurveLayout()
Definition: PlotCurve.cpp:121
std::vector< DataRange > d_data_ranges
Definition: PlotCurve.h:234
QString xColumnName()
Definition: PlotCurve.h:114
int labelsAlignment()
Definition: PlotCurve.h:121
int d_plot_style
Definition: PlotCurve.h:90
QFont labelsFont()
Definition: PlotCurve.h:131
double d_x_offset
Definition: PlotCurve.h:91
PlotCurve(const QString &name=QString())
Definition: PlotCurve.cpp:51
QColor d_labels_color
Definition: PlotCurve.h:226
void setXOffset(double dx)
Definition: PlotCurve.h:58
int d_start_row
Definition: PlotCurve.h:215
QList< PlotMarker * > d_labels_list
List of the text labels associated to this curve.
Definition: PlotCurve.h:222
Error bars curve.
Definition: ErrorBarsCurve.h:36
void setAngle(double a)
Definition: PlotCurve.h:246
int d_type
Definition: PlotCurve.h:88
int d_index
Definition: PlotCurve.h:256
Definition: PlotCurve.h:101
double d_click_pos_y
Definition: PlotCurve.h:224
double d_label_y_offset
y coordinate offset
Definition: PlotCurve.h:261
bool d_side_lines
Definition: PlotCurve.h:92
Table * d_table
The data source table.
Definition: PlotCurve.h:206
void setLabelOffset(double xOffset, double yOffset)
Definition: PlotCurve.h:250
double labelsRotation()
Definition: PlotCurve.h:128
int endRow()
Definition: PlotCurve.h:145
QFont d_labels_font
Definition: PlotCurve.h:227
void setVisibleLabels(bool on=true)
Definition: PlotCurve.h:188
QString saveCurveSymbolImage()
Definition: PlotCurve.cpp:99
QString d_labels_column
The name of the column used for text labels.
Definition: PlotCurve.h:219
PlotMarker * d_selected_label
Keeps track of the plot marker on which the user clicked when selecting the labels.
Definition: PlotCurve.h:233
bool d_white_out_labels
Definition: PlotCurve.h:229
QString d_x_column
The name of the column used for abscissae values.
Definition: PlotCurve.h:213
void drawSticks(QPainter *p, const QwtScaleMap &xMap, const QwtScaleMap &yMap, int from, int to) const
Definition: PlotCurve.cpp:290
void setIndex(int i)
Definition: PlotCurve.h:243
bool sideLinesEnabled()
Definition: PlotCurve.h:63
bool d_show_labels
Definition: PlotCurve.h:230
bool hasVisibleLabels()
Definition: PlotCurve.h:189
Table * xTable()
Definition: PlotCurve.h:141
bool hasLabels()
Definition: PlotCurve.h:117
Table * table()
Definition: PlotCurve.h:140
int labelsYOffset()
Definition: PlotCurve.h:125
int index()
Definition: PlotCurve.h:242
int plotStyle()
The plot style of the curve.
Definition: PlotCurve.h:54
Definition: PlotCurve.h:96
double yOffset()
Definition: PlotCurve.h:60
int d_skip_symbols
Definition: PlotCurve.h:93
QwtDoubleRect boundingRect() const
Definition: PlotCurve.cpp:64
void setXColumnName(const QString &name)
Definition: PlotCurve.h:115
void addErrorBars(ErrorBarsCurve *c)
Adds a single error bars curve to the list of attached error bars.
Definition: PlotCurve.h:178
Definition: PlotCurve.h:237
double d_angle
Definition: PlotCurve.h:257
int labelsXOffset()
Definition: PlotCurve.h:124
double xLabelOffset()
Definition: PlotCurve.h:248
int startRow()
Definition: PlotCurve.h:144
QList< ErrorBarsCurve * > errorBarsList()
The list of attached error bars.
Definition: PlotCurve.h:176
void enableSideLines(bool on)
Definition: PlotCurve.h:64
double yLabelOffset()
Definition: PlotCurve.h:249
virtual void drawCurve(QPainter *p, int style, const QwtScaleMap &xMap, const QwtScaleMap &yMap, int from, int to) const
Definition: PlotCurve.cpp:272
double angle()
Definition: PlotCurve.h:245
Table * d_x_table
The data source table in case X and Y datasets are from different tables.
Definition: PlotCurve.h:208
void setType(int t)
Definition: PlotCurve.h:49
void setPlotStyle(int s)
Definition: PlotCurve.h:55
Abstract 2D plot curve class.
Definition: PlotCurve.h:41
void setYOffset(double dy)
Definition: PlotCurve.h:61
int d_end_row
Definition: PlotCurve.h:216
int skipSymbolsCount()
Returns the number of symbols not to be drawn.
Definition: PlotCurve.h:73
int d_labels_y_offset
Definition: PlotCurve.h:231
void setSkipSymbolsCount(int count)
Set the number of symbols not to be drawn: usefull for large data sets.
Definition: PlotCurve.cpp:313
virtual void drawSymbols(QPainter *p, const QwtSymbol &, const QwtScaleMap &xMap, const QwtScaleMap &yMap, int from, int to) const
Draw symbols.
Definition: PlotCurve.cpp:332
MDI window providing a spreadsheet table with column logic.
Definition: Table.h:57
double d_labels_angle
Definition: PlotCurve.h:228
void restoreCurveLayout(const QStringList &lst)
Definition: PlotCurve.cpp:183
double d_label_x_offset
x coordinate offset
Definition: PlotCurve.h:259
double xOffset()
Definition: PlotCurve.h:57
int type()
Sort of rtti()
Definition: PlotCurve.h:48
double d_y_offset
Definition: PlotCurve.h:91
QString labelsColumnName()
Definition: PlotCurve.h:118
QList< ErrorBarsCurve * > d_error_bars
List of the error bar curves associated to this curve.
Definition: PlotCurve.h:204
unsigned int to
Definition: PlotCurve.h:104
void drawSideLines(QPainter *p, const QwtScaleMap &xMap, const QwtScaleMap &yMap, int from, int to) const
Definition: PlotCurve.cpp:358
bool labelsWhiteOut()
Definition: PlotCurve.h:137
QColor labelsColor()
Definition: PlotCurve.h:134
unsigned int from
Definition: PlotCurve.h:103