ScaleDraw.h
Go to the documentation of this file.
/***************************************************************************
File : ScaleDraw.h
Project : QtiPlot
--------------------------------------------------------------------
Copyright : (C) 2006-2007 by Ion Vasilief
Email (use @ for *) : ion_vasilief*yahoo.fr
Description : Extension to QwtScaleDraw
***************************************************************************/
/***************************************************************************
* *
* 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 SCALES_H
#define SCALES_H
#include <QDateTime>
#include <QStringList>
#include <QLocale>
#include <qwt_scale_draw.h>
class Graph;
class ScaleDraw: public QwtScaleDraw
{
public:
enum TicksStyle{None = 0, Out = 1, Both = 2, In = 3};
enum ScaleType{Numeric = 0, Text = 1, Day = 2, Month = 3, Time = 4, Date = 5, ColHeader = 6};
enum NumericFormat{Automatic, Decimal, Scientific, Superscripts, Engineering, SuperscriptsGER};
enum NameFormat{ShortName, LongName, Initial};
enum ShowTicksPolicy{ShowAll = 0, HideBegin = 1, HideEnd = 2, HideBeginEnd = 3};
ScaleDraw(Graph *plot, ScaleDraw *sd);
ScaleDraw(Graph *plot, const QString& formula = QString::null);
ScaleDraw(Graph *plot, const QStringList& labels, const QString& format, ScaleType type = Text);
Graph *plot(){return d_plot;};
QString formatString(){return d_format_info;}
QString formula() {return d_formula;};
void setFormula(const QString& formula) {d_formula = formula;};
double transformValue(double value) const;
virtual QwtText label(double value) const;
QString labelString(double value) const;
int labelNumericPrecision()const {return d_prec;};
void setNumericPrecision(int prec){d_prec = prec;};
int majorTicksStyle()const {return d_majTicks;};
void setMajorTicksStyle(TicksStyle type){d_majTicks = type;};
int minorTicksStyle()const {return d_minTicks;};
void setMinorTicksStyle(TicksStyle type){d_minTicks = type;};
ShowTicksPolicy showTicksPolicy(){return d_show_ticks_policy;};
void setShowTicksPolicy(const ShowTicksPolicy& policy){d_show_ticks_policy = policy;};
void setSelected(bool select = true){d_selected = select;};
int axis() const;
ScaleType scaleType(){return d_type;};
void setScaleType(ScaleType type){d_type = type;};
void labelFormat(char &f, int &prec) const;
NumericFormat labelNumericFormat(){return d_numeric_format;};
void setNumericFormat(NumericFormat format);
void setDayFormat(NameFormat format);
void setMonthFormat(NameFormat format);
void setTimeFormat(const QString& format);
void setDateFormat(const QString& format);
QStringList labelsList(){return d_text_labels;};
void setLabelsList(const QStringList& list){d_text_labels = list;};
NameFormat nameFormat(){return d_name_format;};
QString prefix(){return d_prefix;};
void setPrefix(const QString& s){d_prefix = s;};
QString suffix(){return d_suffix;};
void setSuffix(const QString& s){d_suffix = s;};
protected:
virtual void draw (QPainter *, const QPalette &) const;
virtual void drawLabel(QPainter *painter, double value) const;
virtual void drawTick(QPainter *p, double value, int len) const;
void drawInwardTick(QPainter *painter, double value, int len) const;
virtual void drawBackbone(QPainter *painter) const;
void drawBreak(QPainter *) const;
private:
Graph *d_plot;
ScaleType d_type;
NumericFormat d_numeric_format;
char d_fmt;
int d_prec;
QString d_formula;
int d_majTicks;
int d_minTicks;
bool d_selected;
NameFormat d_name_format;
/* - the date/time format used to calculate labels for Date/Time scales
* - the Column/Table name in the case of Text/ColHeader scales
*/
QString d_format_info;
QStringList d_text_labels;
ShowTicksPolicy d_show_ticks_policy;
QString d_prefix, d_suffix;
};
#endif
ScaleDraw::setDayFormat
void setDayFormat(NameFormat format)
Definition: ScaleDraw.cpp:818
ScaleDraw::d_fmt
char d_fmt
Numerical format specification.
Definition: ScaleDraw.h:121
ScaleDraw::transformValue
double transformValue(double value) const
Definition: ScaleDraw.cpp:411
ScaleDraw::setMajorTicksStyle
void setMajorTicksStyle(TicksStyle type)
Definition: ScaleDraw.h:70
ScaleDraw
Extension to QwtScaleDraw.
Definition: ScaleDraw.h:41
ScaleDraw::d_suffix
QString d_suffix
Definition: ScaleDraw.h:143
ScaleDraw::TicksStyle
TicksStyle
Definition: ScaleDraw.h:44
ScaleDraw::minorTicksStyle
int minorTicksStyle() const
Definition: ScaleDraw.h:72
Graph
A 2D-plotting widget.
Definition: Graph.h:123
ScaleDraw::Time
Definition: ScaleDraw.h:45
ScaleDraw::Both
Definition: ScaleDraw.h:44
ScaleDraw::suffix
QString suffix()
Definition: ScaleDraw.h:102
ScaleDraw::labelsList
QStringList labelsList()
Definition: ScaleDraw.h:95
ScaleDraw::setPrefix
void setPrefix(const QString &s)
Definition: ScaleDraw.h:101
ScaleDraw::In
Definition: ScaleDraw.h:44
ScaleDraw::drawInwardTick
void drawInwardTick(QPainter *painter, double value, int len) const
Definition: ScaleDraw.cpp:557
ScaleDraw::Decimal
Definition: ScaleDraw.h:46
ScaleDraw::Text
Definition: ScaleDraw.h:45
ScaleDraw::labelNumericPrecision
int labelNumericPrecision() const
Definition: ScaleDraw.h:66
ScaleDraw::Scientific
Definition: ScaleDraw.h:46
ScaleDraw::formula
QString formula()
Definition: ScaleDraw.h:59
ScaleDraw::setScaleType
void setScaleType(ScaleType type)
Definition: ScaleDraw.h:83
ScaleDraw::d_formula
QString d_formula
A mathematical expression used to calculate the label values.
Definition: ScaleDraw.h:125
ScaleDraw::HideBegin
Definition: ScaleDraw.h:48
ScaleDraw::d_plot
Graph * d_plot
Pointer to the parent plot.
Definition: ScaleDraw.h:115
ScaleDraw::setNumericFormat
void setNumericFormat(NumericFormat format)
Definition: ScaleDraw.cpp:433
ScaleDraw::showTicksPolicy
ShowTicksPolicy showTicksPolicy()
Definition: ScaleDraw.h:75
ScaleDraw::setFormula
void setFormula(const QString &formula)
Definition: ScaleDraw.h:60
ScaleDraw::d_text_labels
QStringList d_text_labels
Stores the labels for Txt scales.
Definition: ScaleDraw.h:140
ScaleDraw::Engineering
Definition: ScaleDraw.h:46
ScaleDraw::NameFormat
NameFormat
Definition: ScaleDraw.h:47
ScaleDraw::Month
Definition: ScaleDraw.h:45
ScaleDraw::d_show_ticks_policy
ShowTicksPolicy d_show_ticks_policy
Definition: ScaleDraw.h:142
ScaleDraw::drawTick
virtual void drawTick(QPainter *p, double value, int len) const
Definition: ScaleDraw.cpp:500
ScaleDraw::ScaleDraw
ScaleDraw(Graph *plot, ScaleDraw *sd)
Constructs a new scale draw which is a clone of sd.
Definition: ScaleDraw.cpp:85
ScaleDraw::d_prefix
QString d_prefix
Definition: ScaleDraw.h:143
ScaleDraw::HideEnd
Definition: ScaleDraw.h:48
ScaleDraw::setMinorTicksStyle
void setMinorTicksStyle(TicksStyle type)
Definition: ScaleDraw.h:73
ScaleDraw::Out
Definition: ScaleDraw.h:44
ScaleDraw::d_type
ScaleType d_type
Stores the scale type (numeric, text, etc...). See: enum NumericFormat.
Definition: ScaleDraw.h:117
ScaleDraw::label
virtual QwtText label(double value) const
Definition: ScaleDraw.cpp:107
ScaleDraw::d_majTicks
int d_majTicks
Max ticks style.
Definition: ScaleDraw.h:127
ScaleDraw::setSelected
void setSelected(bool select=true)
Definition: ScaleDraw.h:78
ScaleDraw::drawBreak
void drawBreak(QPainter *) const
Definition: ScaleDraw.cpp:681
ScaleDraw::labelNumericFormat
NumericFormat labelNumericFormat()
Definition: ScaleDraw.h:87
ScaleDraw::ShowAll
Definition: ScaleDraw.h:48
ScaleDraw::labelString
QString labelString(double value) const
Definition: ScaleDraw.cpp:122
ScaleDraw::prefix
QString prefix()
Definition: ScaleDraw.h:100
ScaleDraw::SuperscriptsGER
Definition: ScaleDraw.h:46
ScaleDraw::setSuffix
void setSuffix(const QString &s)
Definition: ScaleDraw.h:103
ScaleDraw::d_name_format
NameFormat d_name_format
Stores the scale name format for Day and Month scales.
Definition: ScaleDraw.h:133
ScaleDraw::nameFormat
NameFormat nameFormat()
Definition: ScaleDraw.h:98
ScaleDraw::draw
virtual void draw(QPainter *, const QPalette &) const
Definition: ScaleDraw.cpp:643
ScaleDraw::d_selected
bool d_selected
Flag telling if the scale labels are selected (a blue frame is drawn around each labels if true) ...
Definition: ScaleDraw.h:131
ScaleDraw::Superscripts
Definition: ScaleDraw.h:46
ScaleDraw::Automatic
Definition: ScaleDraw.h:46
ScaleDraw::scaleType
ScaleType scaleType()
Definition: ScaleDraw.h:82
ScaleDraw::d_prec
int d_prec
Numerical precision.
Definition: ScaleDraw.h:123
ScaleDraw::Day
Definition: ScaleDraw.h:45
ScaleDraw::Numeric
Definition: ScaleDraw.h:45
ScaleDraw::setNumericPrecision
void setNumericPrecision(int prec)
Definition: ScaleDraw.h:67
ScaleDraw::None
Definition: ScaleDraw.h:44
ScaleDraw::Initial
Definition: ScaleDraw.h:47
ScaleDraw::setShowTicksPolicy
void setShowTicksPolicy(const ShowTicksPolicy &policy)
Definition: ScaleDraw.h:76
ScaleDraw::Date
Definition: ScaleDraw.h:45
ScaleDraw::setMonthFormat
void setMonthFormat(NameFormat format)
Definition: ScaleDraw.cpp:824
ScaleDraw::drawBackbone
virtual void drawBackbone(QPainter *painter) const
Definition: ScaleDraw.cpp:737
ScaleDraw::LongName
Definition: ScaleDraw.h:47
ScaleDraw::majorTicksStyle
int majorTicksStyle() const
Definition: ScaleDraw.h:69
ScaleDraw::setLabelsList
void setLabelsList(const QStringList &list)
Definition: ScaleDraw.h:96
ScaleDraw::HideBeginEnd
Definition: ScaleDraw.h:48
ScaleDraw::axis
int axis() const
Definition: ScaleDraw.cpp:480
ScaleDraw::drawLabel
virtual void drawLabel(QPainter *painter, double value) const
Definition: ScaleDraw.cpp:348
ScaleDraw::ColHeader
Definition: ScaleDraw.h:45
ScaleDraw::ScaleType
ScaleType
Definition: ScaleDraw.h:45
ScaleDraw::labelFormat
void labelFormat(char &f, int &prec) const
Return the number format for the major scale labels.
Definition: ScaleDraw.cpp:474
ScaleDraw::d_minTicks
int d_minTicks
Min ticks style.
Definition: ScaleDraw.h:129
ScaleDraw::d_format_info
QString d_format_info
Stores extra format information:
Definition: ScaleDraw.h:138
ScaleDraw::NumericFormat
NumericFormat
Definition: ScaleDraw.h:46
ScaleDraw::ShowTicksPolicy
ShowTicksPolicy
Definition: ScaleDraw.h:48
ScaleDraw::d_numeric_format
NumericFormat d_numeric_format
Stores the scale numeric format: Automatic, Decimal, Scientific, Superscripts.
Definition: ScaleDraw.h:119
ScaleDraw::setTimeFormat
void setTimeFormat(const QString &format)
Definition: ScaleDraw.cpp:830
ScaleDraw::ShortName
Definition: ScaleDraw.h:47
ScaleDraw::formatString
QString formatString()
Definition: ScaleDraw.h:57
ScaleDraw::plot
Graph * plot()
Definition: ScaleDraw.h:55
ScaleDraw::setDateFormat
void setDateFormat(const QString &format)
Definition: ScaleDraw.cpp:836