PlotCurve.h
Go to the documentation of this file.
/***************************************************************************
File : PlotCurve.h
Project : QtiPlot
--------------------------------------------------------------------
Copyright : (C) 2007 by Ion Vasilief
Email (use @ for *) : ion_vasilief*yahoo.fr
Description : AbstractPlotCurve and DataCurve classes
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the Free Software *
* Foundation, Inc., 51 Franklin Street, Fifth Floor, *
* Boston, MA 02110-1301 USA *
* *
***************************************************************************/
#ifndef PLOTCURVE_H
#define PLOTCURVE_H
#include <qwt_plot_curve.h>
#include <qwt_plot_marker.h>
#include <Table.h>
class PlotMarker;
class Table;
class ErrorBarsCurve;
class PlotCurve: public QwtPlotCurve
{
public:
PlotCurve(const QString& name = QString());
int type(){return d_type;};
void setType(int t){d_type = t;};
int plotStyle(){return d_plot_style;};
void setPlotStyle(int s){d_plot_style = s;};
double xOffset(){return d_x_offset;};
void setXOffset(double dx){d_x_offset = dx;};
double yOffset(){return d_y_offset;};
void setYOffset(double dy){d_y_offset = dy;};
bool sideLinesEnabled(){return d_side_lines;};
void enableSideLines(bool on){d_side_lines = on;};
QString saveCurveSymbolImage();
QString saveCurveLayout();
void restoreCurveLayout(const QStringList& lst);
void setSkipSymbolsCount(int count);
int skipSymbolsCount(){return d_skip_symbols;};
protected:
virtual void drawCurve(QPainter *p, int style, const QwtScaleMap &xMap, const QwtScaleMap &yMap, int from, int to) const;
void drawSideLines(QPainter *p, const QwtScaleMap &xMap, const QwtScaleMap &yMap, int from, int to) const;
virtual void drawSymbols(QPainter *p, const QwtSymbol &,
const QwtScaleMap &xMap, const QwtScaleMap &yMap, int from, int to) const;
void drawSticks(QPainter *p,
const QwtScaleMap &xMap, const QwtScaleMap &yMap, int from, int to) const;
QwtDoubleRect boundingRect() const;
// Rtti
int d_type;
// The plot style of the curve
int d_plot_style;
double d_x_offset, d_y_offset;
bool d_side_lines;
int d_skip_symbols;
};
class DataCurve: public PlotCurve
{
public:
struct DataRange
{
unsigned int from;
unsigned int to;
};
DataCurve(Table *t, const QString& xColName, const QString& name, int startRow = 0, int endRow = -1);
DataCurve(Table *xt, const QString& xColName, Table *yt, const QString& name, int startRow = 0, int endRow = -1);
void clone(DataCurve* c);
virtual QString saveToString();
void restoreLabels(const QStringList& lst);
QString xColumnName(){return d_x_column;};
void setXColumnName(const QString& name){d_x_column = name;};
bool hasLabels(){return !d_labels_list.isEmpty();};
QString labelsColumnName(){return d_labels_column;};
void setLabelsColumnName(const QString& name);
int labelsAlignment(){return d_labels_align;};
void setLabelsAlignment(int flags);
int labelsXOffset(){return d_labels_x_offset;};
int labelsYOffset(){return d_labels_y_offset;};
void setLabelsOffset(int x, int y);
double labelsRotation(){return d_labels_angle;};
void setLabelsRotation(double angle);
QFont labelsFont(){return d_labels_font;};
void setLabelsFont(const QFont& font);
QColor labelsColor(){return d_labels_color;};
void setLabelsColor(const QColor& c);
bool labelsWhiteOut(){return d_white_out_labels;};
void setLabelsWhiteOut(bool whiteOut = true);
Table* table(){return d_table;};
Table* xTable(){return d_x_table;};
void setDataSource(Table *yt, int ycol = 1, Table *xt = NULL, int xcol = 0);
int startRow(){return d_start_row;};
int endRow(){return d_end_row;};
void setRowRange(int startRow, int endRow);
bool isFullRange();
void setFullRange();
virtual bool updateData(Table *t, const QString& colName);
virtual void loadData();
void enableSpeedMode();
int tableRow(int point);
void remove();
virtual QStringList plotAssociation();
virtual void updateColumnNames(const QString& oldName, const QString& newName, bool updateTableName);
QList<ErrorBarsCurve *> errorBarsList(){return d_error_bars;};
void addErrorBars(ErrorBarsCurve *c){if (c) d_error_bars << c;};
void removeErrorBars(ErrorBarsCurve *c);
void clearErrorBars();
void clearLabels();
void setVisible(bool on);
void setVisibleLabels(bool on = true){d_show_labels = on;};
bool hasVisibleLabels(){return d_show_labels;};
bool selectedLabels(const QPoint& pos);
bool hasSelectedLabels();
void setLabelsSelected(bool on = true);
void moveLabels(const QPoint& pos);
virtual void updateLabelsPosition();
protected:
virtual void drawCurve(QPainter *p, int style, const QwtScaleMap &xMap, const QwtScaleMap &yMap, int from, int to) const;
bool validCurveType();
virtual void loadLabels();
QList <ErrorBarsCurve *> d_error_bars;
Table *d_table;
Table *d_x_table;
/*
*The column name used for Y values is stored in title().text().
*/
QString d_x_column;
int d_start_row;
int d_end_row;
QString d_labels_column;
QList <PlotMarker *> d_labels_list;
double d_click_pos_x, d_click_pos_y;
QColor d_labels_color;
QFont d_labels_font;
double d_labels_angle;
bool d_white_out_labels;
bool d_show_labels;
int d_labels_align, d_labels_x_offset, d_labels_y_offset;
PlotMarker *d_selected_label;
std::vector<DataRange> d_data_ranges;
};
class PlotMarker: public QwtPlotMarker
{
public:
PlotMarker(int index, double angle);
int index(){return d_index;};
void setIndex(int i){d_index = i;};
double angle(){return d_angle;};
void setAngle(double a){d_angle = a;};
double xLabelOffset(){return d_label_x_offset;};
double yLabelOffset(){return d_label_y_offset;};
void setLabelOffset(double xOffset, double yOffset){d_label_x_offset = xOffset; d_label_y_offset = yOffset;};
protected:
void draw(QPainter *p, const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRect &r) const;
int d_index;
double d_angle;
double d_label_x_offset;
double d_label_y_offset;
};
#endif
PlotCurve::saveCurveLayout
QString saveCurveLayout()
Definition: PlotCurve.cpp:121
DataCurve::d_data_ranges
std::vector< DataRange > d_data_ranges
Definition: PlotCurve.h:234
DataCurve::setLabelsSelected
void setLabelsSelected(bool on=true)
Definition: PlotCurve.cpp:1146
DataCurve::xColumnName
QString xColumnName()
Definition: PlotCurve.h:114
PlotMarker::PlotMarker
PlotMarker(int index, double angle)
Definition: PlotCurve.cpp:1208
DataCurve::labelsAlignment
int labelsAlignment()
Definition: PlotCurve.h:121
PlotCurve::d_plot_style
int d_plot_style
Definition: PlotCurve.h:90
DataCurve::DataCurve
DataCurve(Table *t, const QString &xColName, const QString &name, int startRow=0, int endRow=-1)
Definition: PlotCurve.cpp:385
DataCurve::tableRow
int tableRow(int point)
Returns the row index in the data source table corresponding to the data point index.
Definition: PlotCurve.cpp:718
DataCurve::setLabelsColor
void setLabelsColor(const QColor &c)
Definition: PlotCurve.cpp:890
DataCurve::updateLabelsPosition
virtual void updateLabelsPosition()
Definition: PlotCurve.cpp:919
DataCurve::d_labels_x_offset
int d_labels_x_offset
Definition: PlotCurve.h:231
DataCurve::hasSelectedLabels
bool hasSelectedLabels()
Definition: PlotCurve.cpp:1131
DataCurve::labelsFont
QFont labelsFont()
Definition: PlotCurve.h:131
PlotCurve::d_x_offset
double d_x_offset
Definition: PlotCurve.h:91
PlotCurve::PlotCurve
PlotCurve(const QString &name=QString())
Definition: PlotCurve.cpp:51
PlotCurve::drawCurve
virtual void drawCurve(QPainter *p, int style, const QwtScaleMap &xMap, const QwtScaleMap &yMap, int from, int to) const
Definition: PlotCurve.cpp:272
DataCurve::d_labels_color
QColor d_labels_color
Definition: PlotCurve.h:226
PlotCurve::setXOffset
void setXOffset(double dx)
Definition: PlotCurve.h:58
DataCurve::d_start_row
int d_start_row
Definition: PlotCurve.h:215
DataCurve::setDataSource
void setDataSource(Table *yt, int ycol=1, Table *xt=NULL, int xcol=0)
Definition: PlotCurve.cpp:510
DataCurve::d_labels_list
QList< PlotMarker * > d_labels_list
List of the text labels associated to this curve.
Definition: PlotCurve.h:222
ErrorBarsCurve
Error bars curve.
Definition: ErrorBarsCurve.h:36
DataCurve::clearLabels
void clearLabels()
Clears the list of attached text labels.
Definition: PlotCurve.cpp:858
PlotMarker::setAngle
void setAngle(double a)
Definition: PlotCurve.h:246
PlotCurve::d_type
int d_type
Definition: PlotCurve.h:88
DataCurve::validCurveType
bool validCurveType()
Definition: PlotCurve.cpp:1172
PlotMarker::d_index
int d_index
Definition: PlotCurve.h:256
DataCurve::DataRange
Definition: PlotCurve.h:101
DataCurve::d_click_pos_y
double d_click_pos_y
Definition: PlotCurve.h:224
DataCurve::setLabelsRotation
void setLabelsRotation(double angle)
Definition: PlotCurve.cpp:965
PlotMarker::d_label_y_offset
double d_label_y_offset
y coordinate offset
Definition: PlotCurve.h:261
PlotCurve::d_side_lines
bool d_side_lines
Definition: PlotCurve.h:92
DataCurve::d_table
Table * d_table
The data source table.
Definition: PlotCurve.h:206
PlotMarker::setLabelOffset
void setLabelOffset(double xOffset, double yOffset)
Definition: PlotCurve.h:250
DataCurve::labelsRotation
double labelsRotation()
Definition: PlotCurve.h:128
DataCurve::setLabelsColumnName
void setLabelsColumnName(const QString &name)
Definition: PlotCurve.cpp:781
DataCurve::saveToString
virtual QString saveToString()
Definition: PlotCurve.cpp:1019
DataCurve::endRow
int endRow()
Definition: PlotCurve.h:145
PlotCurve::drawSideLines
void drawSideLines(QPainter *p, const QwtScaleMap &xMap, const QwtScaleMap &yMap, int from, int to) const
Definition: PlotCurve.cpp:358
DataCurve::clearErrorBars
void clearErrorBars()
Clears the list of attached error bars.
Definition: PlotCurve.cpp:691
DataCurve::d_labels_font
QFont d_labels_font
Definition: PlotCurve.h:227
DataCurve::setVisibleLabels
void setVisibleLabels(bool on=true)
Definition: PlotCurve.h:188
DataCurve::updateColumnNames
virtual void updateColumnNames(const QString &oldName, const QString &newName, bool updateTableName)
Definition: PlotCurve.cpp:474
PlotCurve::saveCurveSymbolImage
QString saveCurveSymbolImage()
Definition: PlotCurve.cpp:99
DataCurve::d_labels_column
QString d_labels_column
The name of the column used for text labels.
Definition: PlotCurve.h:219
DataCurve::isFullRange
bool isFullRange()
Definition: PlotCurve.cpp:454
DataCurve::d_selected_label
PlotMarker * d_selected_label
Keeps track of the plot marker on which the user clicked when selecting the labels.
Definition: PlotCurve.h:233
DataCurve::loadLabels
virtual void loadLabels()
Definition: PlotCurve.cpp:793
DataCurve::d_white_out_labels
bool d_white_out_labels
Definition: PlotCurve.h:229
DataCurve::d_x_column
QString d_x_column
The name of the column used for abscissae values.
Definition: PlotCurve.h:213
DataCurve::setVisible
void setVisible(bool on)
Definition: PlotCurve.cpp:709
DataCurve::restoreLabels
void restoreLabels(const QStringList &lst)
Definition: PlotCurve.cpp:1053
PlotCurve::drawSymbols
virtual void drawSymbols(QPainter *p, const QwtSymbol &, const QwtScaleMap &xMap, const QwtScaleMap &yMap, int from, int to) const
Draw symbols.
Definition: PlotCurve.cpp:332
PlotMarker::setIndex
void setIndex(int i)
Definition: PlotCurve.h:243
PlotCurve::sideLinesEnabled
bool sideLinesEnabled()
Definition: PlotCurve.h:63
DataCurve::d_show_labels
bool d_show_labels
Definition: PlotCurve.h:230
DataCurve::hasVisibleLabels
bool hasVisibleLabels()
Definition: PlotCurve.h:189
DataCurve::xTable
Table * xTable()
Definition: PlotCurve.h:141
DataCurve::setFullRange
void setFullRange()
Definition: PlotCurve.cpp:443
DataCurve::hasLabels
bool hasLabels()
Definition: PlotCurve.h:117
DataCurve::table
Table * table()
Definition: PlotCurve.h:140
DataCurve::drawCurve
virtual void drawCurve(QPainter *p, int style, const QwtScaleMap &xMap, const QwtScaleMap &yMap, int from, int to) const
Definition: PlotCurve.cpp:537
DataCurve::labelsYOffset
int labelsYOffset()
Definition: PlotCurve.h:125
PlotMarker::index
int index()
Definition: PlotCurve.h:242
DataCurve::d_click_pos_x
double d_click_pos_x
Keep track of the coordinates of the point where the user clicked when selecting the labels...
Definition: PlotCurve.h:224
PlotCurve::plotStyle
int plotStyle()
The plot style of the curve.
Definition: PlotCurve.h:54
DataCurve::setRowRange
void setRowRange(int startRow, int endRow)
Definition: PlotCurve.cpp:429
DataCurve::d_labels_align
int d_labels_align
Definition: PlotCurve.h:231
DataCurve
Definition: PlotCurve.h:96
DataCurve::setLabelsAlignment
void setLabelsAlignment(int flags)
Definition: PlotCurve.cpp:907
PlotCurve::yOffset
double yOffset()
Definition: PlotCurve.h:60
PlotCurve::d_skip_symbols
int d_skip_symbols
Definition: PlotCurve.h:93
DataCurve::setXColumnName
void setXColumnName(const QString &name)
Definition: PlotCurve.h:115
DataCurve::addErrorBars
void addErrorBars(ErrorBarsCurve *c)
Adds a single error bars curve to the list of attached error bars.
Definition: PlotCurve.h:178
PlotMarker
Definition: PlotCurve.h:237
PlotMarker::draw
void draw(QPainter *p, const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRect &r) const
Does the actual drawing; see QwtPlotItem::draw.
Definition: PlotCurve.cpp:1215
PlotMarker::d_angle
double d_angle
Definition: PlotCurve.h:257
DataCurve::selectedLabels
bool selectedLabels(const QPoint &pos)
Definition: PlotCurve.cpp:1102
PlotCurve::drawSticks
void drawSticks(QPainter *p, const QwtScaleMap &xMap, const QwtScaleMap &yMap, int from, int to) const
Definition: PlotCurve.cpp:290
DataCurve::setLabelsFont
void setLabelsFont(const QFont &font)
Definition: PlotCurve.cpp:872
DataCurve::labelsXOffset
int labelsXOffset()
Definition: PlotCurve.h:124
PlotMarker::xLabelOffset
double xLabelOffset()
Definition: PlotCurve.h:248
DataCurve::startRow
int startRow()
Definition: PlotCurve.h:144
DataCurve::errorBarsList
QList< ErrorBarsCurve * > errorBarsList()
The list of attached error bars.
Definition: PlotCurve.h:176
PlotCurve::enableSideLines
void enableSideLines(bool on)
Definition: PlotCurve.h:64
DataCurve::removeErrorBars
void removeErrorBars(ErrorBarsCurve *c)
Remove a single error bars curve from the list of attached error bars.
Definition: PlotCurve.cpp:681
PlotMarker::yLabelOffset
double yLabelOffset()
Definition: PlotCurve.h:249
PlotMarker::angle
double angle()
Definition: PlotCurve.h:245
DataCurve::d_x_table
Table * d_x_table
The data source table in case X and Y datasets are from different tables.
Definition: PlotCurve.h:208
DataCurve::enableSpeedMode
void enableSpeedMode()
Definition: PlotCurve.cpp:523
PlotCurve::setType
void setType(int t)
Definition: PlotCurve.h:49
DataCurve::setLabelsOffset
void setLabelsOffset(int x, int y)
Definition: PlotCurve.cpp:952
Table.h
PlotCurve::setPlotStyle
void setPlotStyle(int s)
Definition: PlotCurve.h:55
PlotCurve
Abstract 2D plot curve class.
Definition: PlotCurve.h:41
PlotCurve::setYOffset
void setYOffset(double dy)
Definition: PlotCurve.h:61
DataCurve::d_end_row
int d_end_row
Definition: PlotCurve.h:216
PlotCurve::skipSymbolsCount
int skipSymbolsCount()
Returns the number of symbols not to be drawn.
Definition: PlotCurve.h:73
DataCurve::d_labels_y_offset
int d_labels_y_offset
Definition: PlotCurve.h:231
PlotCurve::setSkipSymbolsCount
void setSkipSymbolsCount(int count)
Set the number of symbols not to be drawn: usefull for large data sets.
Definition: PlotCurve.cpp:313
Table
MDI window providing a spreadsheet table with column logic.
Definition: Table.h:57
DataCurve::d_labels_angle
double d_labels_angle
Definition: PlotCurve.h:228
PlotCurve::restoreCurveLayout
void restoreCurveLayout(const QStringList &lst)
Definition: PlotCurve.cpp:183
PlotMarker::d_label_x_offset
double d_label_x_offset
x coordinate offset
Definition: PlotCurve.h:259
PlotCurve::boundingRect
QwtDoubleRect boundingRect() const
Definition: PlotCurve.cpp:64
PlotCurve::xOffset
double xOffset()
Definition: PlotCurve.h:57
PlotCurve::type
int type()
Sort of rtti()
Definition: PlotCurve.h:48
PlotCurve::d_y_offset
double d_y_offset
Definition: PlotCurve.h:91
DataCurve::labelsColumnName
QString labelsColumnName()
Definition: PlotCurve.h:118
DataCurve::d_error_bars
QList< ErrorBarsCurve * > d_error_bars
List of the error bar curves associated to this curve.
Definition: PlotCurve.h:204
DataCurve::DataRange::to
unsigned int to
Definition: PlotCurve.h:104
DataCurve::clone
void clone(DataCurve *c)
Definition: PlotCurve.cpp:999
DataCurve::setLabelsWhiteOut
void setLabelsWhiteOut(bool whiteOut=true)
Definition: PlotCurve.cpp:979
DataCurve::moveLabels
void moveLabels(const QPoint &pos)
Definition: PlotCurve.cpp:1182
DataCurve::labelsWhiteOut
bool labelsWhiteOut()
Definition: PlotCurve.h:137
DataCurve::labelsColor
QColor labelsColor()
Definition: PlotCurve.h:134
DataCurve::loadData
virtual void loadData()
Definition: PlotCurve.cpp:553
DataCurve::DataRange::from
unsigned int from
Definition: PlotCurve.h:103
DataCurve::updateData
virtual bool updateData(Table *t, const QString &colName)
Definition: PlotCurve.cpp:498
DataCurve::plotAssociation
virtual QStringList plotAssociation()
A list of data sources for this curve.
Definition: PlotCurve.cpp:462