##// END OF EJS Templates
QIntervalsAxis working somewhat
Marek Rosa -
r1701:49d19bd1233e
parent child
Show More
@@ -0,0 +1,122
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
21 #include "chartintervalsaxisx_p.h"
22 #include "qabstractaxis.h"
23 #include "chartpresenter_p.h"
24 #include "chartanimator_p.h"
25 #include <QGraphicsLayout>
26 #include <QDebug>
27 #include <QFontMetrics>
28 #include <cmath>
29 #include <QIntervalsAxis>
30
31 static int label_padding = 5;
32
33 QTCOMMERCIALCHART_BEGIN_NAMESPACE
34
35 ChartIntervalAxisX::ChartIntervalAxisX(QAbstractAxis *axis,ChartPresenter *presenter) : ChartAxis(axis,presenter)
36 {
37 }
38
39 ChartIntervalAxisX::~ChartIntervalAxisX()
40 {
41 }
42
43 QVector<qreal> ChartIntervalAxisX::calculateLayout() const
44 {
45 QIntervalsAxis *axis = qobject_cast<QIntervalsAxis *>(m_chartAxis);
46 int tickCount = axis->intervalsLabels().count() + 1;
47 QVector<qreal> points;
48 points.resize(tickCount);
49
50 qreal scale = m_rect.width() / axis->max();
51 for (int i = 0; i < tickCount; ++i)
52 if (i < tickCount - 1) {
53 int x = axis->intervalMin(axis->intervalsLabels().at(i)) * scale + m_rect.left();
54 points[i] = x;
55 } else {
56 int x = axis->intervalMax(axis->intervalsLabels().at(i - 1)) * scale + m_rect.left();
57 points[i] = x;
58 }
59
60 return points;
61 }
62
63 void ChartIntervalAxisX::updateGeometry()
64 {
65 const QVector<qreal>& layout = ChartAxis::layout();
66
67 m_minWidth = 0;
68 m_minHeight = 0;
69
70 if(layout.isEmpty()) return;
71
72 QIntervalsAxis *intervalAxis = qobject_cast<QIntervalsAxis *>(m_chartAxis);
73
74 QStringList ticksList = intervalAxis->intervalsLabels();
75
76 // createNumberLabels(ticksList,m_min,m_max,layout.size());
77
78 QList<QGraphicsItem *> lines = m_grid->childItems();
79 QList<QGraphicsItem *> labels = m_labels->childItems();
80 QList<QGraphicsItem *> shades = m_shades->childItems();
81 QList<QGraphicsItem *> axis = m_axis->childItems();
82
83 // Q_ASSERT(labels.size() == ticksList.size());
84 // Q_ASSERT(layout.size() == ticksList.size());
85
86 QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(axis.at(0));
87 lineItem->setLine(m_rect.left(), m_rect.bottom(), m_rect.right(), m_rect.bottom());
88
89 // qreal width = 0;
90 for (int i = 0; i < layout.size(); ++i) {
91 QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(lines.at(i));
92 lineItem->setLine(layout[i], m_rect.top(), layout[i], m_rect.bottom());
93 QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i));
94 if (i < ticksList.count()) {
95 labelItem->setText(ticksList.at(i));
96 }
97 const QRectF& rect = labelItem->boundingRect();
98 QPointF center = rect.center();
99 labelItem->setTransformOriginPoint(center.x(), center.y());
100 if (i < ticksList.count())
101 labelItem->setPos(layout[i] + (layout[i + 1] - layout[i]) / 2 - center.x(), m_rect.bottom() + label_padding);
102 else
103 labelItem->setPos(layout[i] - center.x(), m_rect.bottom() + label_padding);
104
105 if(labelItem->pos().x() > m_rect.width() + m_rect.left() - rect.width() / 2){
106 labelItem->setVisible(false);
107 lineItem->setVisible(false);
108 }
109
110 m_minWidth += rect.width();
111 m_minHeight = qMax(rect.height(), m_minHeight);
112
113 if ((i + 1) % 2 && i > 1) {
114 QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i / 2 - 1));
115 rectItem->setRect(layout[i - 1],m_rect.top(),layout[i]-layout[i - 1],m_rect.height());
116 }
117 lineItem = static_cast<QGraphicsLineItem*>(axis.at(i+1));
118 lineItem->setLine(layout[i],m_rect.bottom(),layout[i], m_rect.bottom() + 5);
119 }
120 }
121
122 QTCOMMERCIALCHART_END_NAMESPACE
@@ -0,0 +1,59
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
21 // W A R N I N G
22 // -------------
23 //
24 // This file is not part of the QtCommercial Chart API. It exists purely as an
25 // implementation detail. This header file may change from version to
26 // version without notice, or even be removed.
27 //
28 // We mean it.
29
30 #ifndef CHARTINTERVALAXISX_H
31 #define CHARTINTERVALAXISX_H
32
33 #include "chartaxis_p.h"
34
35 QTCOMMERCIALCHART_BEGIN_NAMESPACE
36
37 class QAbstractAxis;
38 class ChartPresenter;
39
40 class ChartIntervalAxisX : public ChartAxis
41 {
42 public:
43 ChartIntervalAxisX(QAbstractAxis *axis, ChartPresenter *presenter);
44 ~ChartIntervalAxisX();
45
46 AxisType axisType() const { return X_AXIS;}
47
48 protected:
49 QVector<qreal> calculateLayout() const;
50 void updateGeometry();
51
52 private:
53 void createLabels(QStringList &labels,qreal min, qreal max,int ticks) const;
54
55 };
56
57 QTCOMMERCIALCHART_END_NAMESPACE
58
59 #endif /* CHARTINTERVALAXISX_H */
@@ -0,0 +1,131
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
21 #include "chartintervalsaxisy_p.h"
22 #include "qabstractaxis.h"
23 #include "chartpresenter_p.h"
24 #include "chartanimator_p.h"
25 #include <QGraphicsLayout>
26 #include <QDebug>
27 #include <QFontMetrics>
28 #include <cmath>
29 #include <QIntervalsAxis>
30
31 static int label_padding = 5;
32
33 QTCOMMERCIALCHART_BEGIN_NAMESPACE
34
35 ChartIntervalAxisY::ChartIntervalAxisY(QAbstractAxis *axis,ChartPresenter *presenter) : ChartAxis(axis,presenter)
36 {
37 }
38
39 ChartIntervalAxisY::~ChartIntervalAxisY()
40 {
41 }
42
43 QVector<qreal> ChartIntervalAxisY::calculateLayout() const
44 {
45 QIntervalsAxis *axis = qobject_cast<QIntervalsAxis *>(m_chartAxis);
46 int tickCount = axis->intervalsLabels().count() + 1;
47 QVector<qreal> points;
48 points.resize(tickCount);
49
50 qreal scale = m_rect.height() / axis->max();
51 for (int i = 0; i < tickCount; ++i)
52 if (i < tickCount - 1) {
53 int y = -axis->intervalMin(axis->intervalsLabels().at(i)) * scale + m_rect.bottom();
54 points[i] = y;
55 } else {
56 int y = -axis->intervalMax(axis->intervalsLabels().at(i - 1)) * scale + m_rect.bottom();
57 points[i] = y;
58 }
59
60 return points;
61 }
62
63 void ChartIntervalAxisY::updateGeometry()
64 {
65 const QVector<qreal> &layout = ChartAxis::layout();
66 m_minWidth = 0;
67 m_minHeight = 0;
68
69 if(layout.isEmpty()) return;
70
71 QIntervalsAxis *intervalAxis = qobject_cast<QIntervalsAxis *>(m_chartAxis);
72
73 QStringList ticksList = intervalAxis->intervalsLabels();
74
75 QList<QGraphicsItem *> lines = m_grid->childItems();
76 QList<QGraphicsItem *> labels = m_labels->childItems();
77 QList<QGraphicsItem *> shades = m_shades->childItems();
78 QList<QGraphicsItem *> axis = m_axis->childItems();
79
80 // Q_ASSERT(labels.size() == ticksList.size());
81 // Q_ASSERT(layout.size() == ticksList.size());
82
83 qreal height = 2*m_rect.bottom();
84
85 QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(axis.at(0));
86 lineItem->setLine(m_rect.left() , m_rect.top(), m_rect.left(), m_rect.bottom());
87
88 for (int i = 0; i < layout.size(); ++i) {
89 QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(lines.at(i));
90 lineItem->setLine(m_rect.left() , layout[i], m_rect.right(), layout[i]);
91 QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i));
92
93 if (i < ticksList.count()) {
94 labelItem->setText(ticksList.at(i));
95 }
96 const QRectF& rect = labelItem->boundingRect();
97
98 QPointF center = rect.center();
99 labelItem->setTransformOriginPoint(center.x(), center.y());
100
101 if (i < ticksList.count())
102 labelItem->setPos(m_rect.left() - rect.width() - label_padding , layout[i] + (layout[i + 1] - layout[i]) / 2 - center.y());
103 // labelItem->setPos(layout[i] + (layout[i + 1] - layout[i]) / 2 - center.x(), m_rect.bottom() + label_padding);
104 else
105 labelItem->setPos(m_rect.left() - rect.width() - label_padding , layout[i]-center.y());
106
107 // labelItem->setPos(m_rect.left() - rect.width() - label_padding , layout[i]-center.y());
108
109 if(labelItem->pos().y()+rect.height()>height) {
110 labelItem->setVisible(false);
111 lineItem->setVisible(false);
112 }
113 else {
114 labelItem->setVisible(true);
115 lineItem->setVisible(true);
116 height=labelItem->pos().y();
117 }
118
119 m_minWidth=qMax(rect.width()+label_padding,m_minWidth);
120 m_minHeight+=rect.height();
121
122 if ((i+1)%2 && i>1) {
123 QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i/2-1));
124 rectItem->setRect(m_rect.left(),layout[i],m_rect.width(),layout[i-1]-layout[i]);
125 }
126 lineItem = static_cast<QGraphicsLineItem*>(axis.at(i+1));
127 lineItem->setLine(m_rect.left()-5,layout[i],m_rect.left(),layout[i]);
128 }
129 }
130
131 QTCOMMERCIALCHART_END_NAMESPACE
@@ -0,0 +1,55
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
21 // W A R N I N G
22 // -------------
23 //
24 // This file is not part of the QtCommercial Chart API. It exists purely as an
25 // implementation detail. This header file may change from version to
26 // version without notice, or even be removed.
27 //
28 // We mean it.
29
30 #ifndef CHARTINTERVALAXISY_H
31 #define CHARTINTERVALAXISY_H
32
33 #include "chartaxis_p.h"
34
35 QTCOMMERCIALCHART_BEGIN_NAMESPACE
36
37 class QAbstractAxis;
38 class ChartPresenter;
39
40 class ChartIntervalAxisY : public ChartAxis
41 {
42 public:
43 ChartIntervalAxisY(QAbstractAxis *axis, ChartPresenter *presenter);
44 ~ChartIntervalAxisY();
45
46 AxisType axisType() const { return Y_AXIS;}
47
48 protected:
49 QVector<qreal> calculateLayout() const;
50 void updateGeometry();
51 };
52
53 QTCOMMERCIALCHART_END_NAMESPACE
54
55 #endif /* CHARTINTERVALAXISY_H */
@@ -1,5 +1,6
1 include(valuesaxis/valuesaxis.pri)
1 include(valuesaxis/valuesaxis.pri)
2 include(categoriesaxis/categoriesaxis.pri)
2 include(categoriesaxis/categoriesaxis.pri)
3 include(intervalsaxis/intervalsaxis.pri)
3
4
4 INCLUDEPATH += $$PWD
5 INCLUDEPATH += $$PWD
5 DEPENDPATH += $$PWD
6 DEPENDPATH += $$PWD
@@ -2,11 +2,14 INCLUDEPATH += $$PWD
2 DEPENDPATH += $$PWD
2 DEPENDPATH += $$PWD
3
3
4 SOURCES += \
4 SOURCES += \
5 $$PWD/chartintervalsaxisx.cpp \
6 $$PWD/chartintervalsaxisy.cpp \
5 $$PWD/qintervalsaxis.cpp
7 $$PWD/qintervalsaxis.cpp
6
8
7
8 PRIVATE_HEADERS += \
9 PRIVATE_HEADERS += \
9 $$PWD/qintervalaxis_p.h
10 $$PWD/chartintervalsaxisx_p.h \
11 $$PWD/chartintervalsaxisy_p.h \
12 $$PWD/qintervalsaxis_p.h
10
13
11 PUBLIC_HEADERS += \
14 PUBLIC_HEADERS += \
12 $$PWD/qintervalaxis.h
15 $$PWD/qintervalsaxis.h
@@ -18,25 +18,25
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "qintervalaxis.h"
21 #include "qintervalsaxis.h"
22 #include "qintervalaxis_p.h"
22 #include "qintervalsaxis_p.h"
23 #include "chartcategoriesaxisx_p.h"
23 #include "chartintervalsaxisx_p.h"
24 #include "chartcategoriesaxisy_p.h"
24 #include "chartintervalsaxisy_p.h"
25 #include <qmath.h>
25 #include <qmath.h>
26 #include <QDebug>
26 #include <QDebug>
27
27
28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29 /*!
29 /*!
30 \internal
30 \internal
31 \class QIntervalAxis
31 \class QIntervalsAxis
32 \brief The QIntervalAxis class is used for manipulating chart's axis.
32 \brief The QIntervalsAxis class is used for manipulating chart's axis.
33 \mainclass
33 \mainclass
34
34
35 Axis can be setup to show axis line with tick marks, grid lines and shades.
35 Axis can be setup to show axis line with tick marks, grid lines and shades.
36 */
36 */
37
37
38 /*!
38 /*!
39 \qmlclass Axis QIntervalAxis
39 \qmlclass Axis QIntervalsAxis
40 \brief The Axis element is used for manipulating chart's axes.
40 \brief The Axis element is used for manipulating chart's axes.
41
41
42 Axis can be setup to show axis line with tick marks, grid lines and shades.
42 Axis can be setup to show axis line with tick marks, grid lines and shades.
@@ -50,22 +50,22 QTCOMMERCIALCHART_BEGIN_NAMESPACE
50 /*!
50 /*!
51 Constructs an axis object which is a child of \a parent.
51 Constructs an axis object which is a child of \a parent.
52 */
52 */
53 QIntervalAxis::QIntervalAxis(QObject *parent):
53 QIntervalsAxis::QIntervalsAxis(QObject *parent):
54 QValuesAxis(*new QIntervalAxisPrivate(this),parent)
54 QValuesAxis(*new QIntervalsAxisPrivate(this),parent)
55 {
55 {
56 }
56 }
57
57
58 /*!
58 /*!
59 Destroys the object
59 Destroys the object
60 */
60 */
61 QIntervalAxis::~QIntervalAxis()
61 QIntervalsAxis::~QIntervalsAxis()
62 {
62 {
63 }
63 }
64
64
65 /*!
65 /*!
66 \internal
66 \internal
67 */
67 */
68 QIntervalAxis::QIntervalAxis(QIntervalAxisPrivate &d,QObject *parent):QValuesAxis(d,parent)
68 QIntervalsAxis::QIntervalsAxis(QIntervalsAxisPrivate &d,QObject *parent):QValuesAxis(d,parent)
69 {
69 {
70
70
71 }
71 }
@@ -73,106 +73,118 QIntervalAxis::QIntervalAxis(QIntervalAxisPrivate &d,QObject *parent):QValuesAxi
73 /*!
73 /*!
74 Appends \a category to axis
74 Appends \a category to axis
75 */
75 */
76 void QIntervalAxis::append(const QString& category, qreal x)
76 void QIntervalsAxis::append(const QString& intervalLabel, qreal interval)
77 {
77 {
78 Q_D(QIntervalAxis);
78 Q_D(QIntervalsAxis);
79 if (!d->m_categories.contains(category))
79 if (!d->m_intervals.contains(intervalLabel))
80 {
80 {
81 if(d->m_categories.isEmpty()){
81 if(d->m_intervals.isEmpty()){
82 Range range(d->m_categoryMinimum,x);
82 Range range(d->m_categoryMinimum,interval);
83 d->m_categoriesMap.insert(category,range);
83 d->m_intervalsMap.insert(intervalLabel, range);
84 d->m_categories.append(category);
84 d->m_intervals.append(intervalLabel);
85 }else{
85 }else{
86 Range range = d->m_categoriesMap.value(d->m_categories.last());
86 Range range = d->m_intervalsMap.value(d->m_intervals.last());
87 d->m_categoriesMap.insert(category,Range(range.first,x));
87 d->m_intervalsMap.insert(intervalLabel, Range(range.second,interval));
88 d->m_categories.append(category);
88 d->m_intervals.append(intervalLabel);
89 }
89 }
90 setRange(d->m_min,x);
90 setRange(d->m_min,interval);
91 }
91 }
92 }
92 }
93
93
94 void QIntervalAxis::setFisrtCategoryMinimum(qreal x)
94 void QIntervalsAxis::setFisrtIntervalMinimum(qreal min)
95 {
95 {
96 Q_D(QIntervalAxis);
96 Q_D(QIntervalsAxis);
97 if(d->m_categories.isEmpty()){
97 if(d->m_intervals.isEmpty()){
98 d->m_categoryMinimum=x;
98 d->m_categoryMinimum = min;
99 }else{
99 }else{
100 Range range = d->m_categoriesMap.value(d->m_categories.first());
100 Range range = d->m_intervalsMap.value(d->m_intervals.first());
101 d->m_categoriesMap.insert(d->m_categories.first(),Range(x,range.second));
101 d->m_intervalsMap.insert(d->m_intervals.first(), Range(min, range.second));
102 setRange(x,d->m_min);
102 setRange(min, d->m_min);
103 }
103 }
104 }
104 }
105
105
106 qreal QIntervalsAxis::intervalMin(const QString& intervalLabel) const
107 {
108 Q_D(const QIntervalsAxis);
109 return d->m_intervalsMap.value(intervalLabel).first;
110 }
111
112 qreal QIntervalsAxis::intervalMax(const QString& intervalLabel) const
113 {
114 Q_D(const QIntervalsAxis);
115 return d->m_intervalsMap.value(intervalLabel).second;
116 }
117
106 /*!
118 /*!
107 Removes \a category from axis
119 Removes \a category from axis
108 */
120 */
109 void QIntervalAxis::remove(const QString &category)
121 void QIntervalsAxis::remove(const QString &intervalLabel)
110 {
122 {
111 Q_UNUSED(category);
123 Q_UNUSED(intervalLabel);
112 //TODO
124 //TODO
113 }
125 }
114
126
115 QStringList QIntervalAxis::categories()
127 QStringList QIntervalsAxis::intervalsLabels()
116 {
128 {
117 Q_D(QIntervalAxis);
129 Q_D(QIntervalsAxis);
118 return d->m_categories;
130 return d->m_intervals;
119 }
131 }
120
132
121 /*!
133 /*!
122 Returns number of categories.
134 Returns number of categories.
123 */
135 */
124 int QIntervalAxis::count() const
136 int QIntervalsAxis::count() const
125 {
137 {
126 Q_D(const QIntervalAxis);
138 Q_D(const QIntervalsAxis);
127 return d->m_categories.count();
139 return d->m_intervals.count();
128 }
140 }
129
141
130 /*!
142 /*!
131 Returns the type of the axis
143 Returns the type of the axis
132 */
144 */
133 QAbstractAxis::AxisType QIntervalAxis::type() const
145 QAbstractAxis::AxisType QIntervalsAxis::type() const
134 {
146 {
135 return AxisTypeCategories;
147 return AxisTypeCategories;
136 }
148 }
137
149
138 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
150 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
139
151
140 QIntervalAxisPrivate::QIntervalAxisPrivate(QIntervalAxis* q):
152 QIntervalsAxisPrivate::QIntervalsAxisPrivate(QIntervalsAxis* q):
141 QValuesAxisPrivate(q),
153 QValuesAxisPrivate(q),
142 m_categoryMinimum(0)
154 m_categoryMinimum(0)
143 {
155 {
144
156
145 }
157 }
146
158
147 QIntervalAxisPrivate::~QIntervalAxisPrivate()
159 QIntervalsAxisPrivate::~QIntervalsAxisPrivate()
148 {
160 {
149
161
150 }
162 }
151
163
152 int QIntervalAxisPrivate::ticksCount() const
164 int QIntervalsAxisPrivate::ticksCount() const
153 {
165 {
154 return m_categories.count()+1;
166 return m_intervals.count() + 1;
155 }
167 }
156
168
157 void QIntervalAxisPrivate::handleAxisRangeChanged(qreal min, qreal max,int count)
169 void QIntervalsAxisPrivate::handleAxisRangeChanged(qreal min, qreal max,int count)
158 {
170 {
171 Q_UNUSED(count);
159 m_min = min;
172 m_min = min;
160 m_max = max;
173 m_max = max;
161 m_ticksCount = count;
174 // m_ticksCount = count;
162 }
175 }
163
176
164 ChartAxis* QIntervalAxisPrivate::createGraphics(ChartPresenter* presenter)
177 ChartAxis* QIntervalsAxisPrivate::createGraphics(ChartPresenter* presenter)
165 {
178 {
166 Q_UNUSED(presenter);
179 Q_Q(QIntervalsAxis);
167 // Q_Q( QCategoriesAxis);
168 if(m_orientation == Qt::Vertical){
180 if(m_orientation == Qt::Vertical){
169 return 0;
181 return new ChartIntervalAxisY(q,presenter);
170 }else{
182 }else{
171 return 0;
183 return new ChartIntervalAxisX(q,presenter);
172 }
184 }
173 }
185 }
174
186
175 #include "moc_qintervalaxis.cpp"
187 #include "moc_qintervalsaxis.cpp"
176 #include "moc_qintervalaxis_p.cpp"
188 #include "moc_qintervalsaxis_p.cpp"
177
189
178 QTCOMMERCIALCHART_END_NAMESPACE
190 QTCOMMERCIALCHART_END_NAMESPACE
@@ -26,37 +26,37
26
26
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28
28
29 class QIntervalAxisPrivate;
29 class QIntervalsAxisPrivate;
30
30
31 class QTCOMMERCIALCHART_EXPORT QIntervalAxis : public QValuesAxis
31 class QTCOMMERCIALCHART_EXPORT QIntervalsAxis : public QValuesAxis
32 {
32 {
33 Q_OBJECT
33 Q_OBJECT
34
34
35 public:
35 public:
36 explicit QIntervalAxis(QObject *parent = 0);
36 explicit QIntervalsAxis(QObject *parent = 0);
37 ~QIntervalAxis();
37 ~QIntervalsAxis();
38
38
39 protected:
39 protected:
40 QIntervalAxis(QIntervalAxisPrivate &d,QObject *parent = 0);
40 QIntervalsAxis(QIntervalsAxisPrivate &d,QObject *parent = 0);
41
41
42 public:
42 public:
43 AxisType type() const;
43 AxisType type() const;
44
44
45 void append(const QString& category, qreal interval = 1);
45 void append(const QString& label, qreal interval = 1);
46 void remove(const QString& category);
46 void remove(const QString& label);
47
47
48 void setFisrtCategoryMinimum(qreal x);
48 void setFisrtIntervalMinimum(qreal min);
49
49
50 qreal categoryMin(const QString& category) const;
50 qreal intervalMin(const QString& intervalLabel) const;
51 qreal categoryMax(const QString& category) const;
51 qreal intervalMax(const QString& intervalLabel) const;
52
52
53 QStringList categories();
53 QStringList intervalsLabels();
54 int count() const;
54 int count() const;
55
55
56
56
57 private:
57 private:
58 Q_DECLARE_PRIVATE(QIntervalAxis)
58 Q_DECLARE_PRIVATE(QIntervalsAxis)
59 Q_DISABLE_COPY(QIntervalAxis)
59 Q_DISABLE_COPY(QIntervalsAxis)
60 };
60 };
61
61
62 QTCOMMERCIALCHART_END_NAMESPACE
62 QTCOMMERCIALCHART_END_NAMESPACE
@@ -27,24 +27,23
27 //
27 //
28 // We mean it.
28 // We mean it.
29
29
30 #ifndef QINTERVALAXIS_P_H
30 #ifndef QIntervalsAxis_P_H
31 #define QINTERVALAXIS_P_H
31 #define QIntervalsAxis_P_H
32
32
33 #include "qintervalaxis.h"
33 #include "qintervalsaxis.h"
34 #include "qvaluesaxis_p.h"
34 #include "qvaluesaxis_p.h"
35
35
36 QTCOMMERCIALCHART_BEGIN_NAMESPACE
36 QTCOMMERCIALCHART_BEGIN_NAMESPACE
37
37
38
39 typedef QPair<qreal, qreal> Range;
38 typedef QPair<qreal, qreal> Range;
40
39
41 class QIntervalAxisPrivate : public QValuesAxisPrivate
40 class QIntervalsAxisPrivate : public QValuesAxisPrivate
42 {
41 {
43 Q_OBJECT
42 Q_OBJECT
44
43
45 public:
44 public:
46 QIntervalAxisPrivate(QIntervalAxis *q);
45 QIntervalsAxisPrivate(QIntervalsAxis *q);
47 ~QIntervalAxisPrivate();
46 ~QIntervalsAxisPrivate();
48
47
49
48
50 public:
49 public:
@@ -58,12 +57,12 public Q_SLOTS:
58 void handleAxisRangeChanged(qreal min, qreal max,int count);
57 void handleAxisRangeChanged(qreal min, qreal max,int count);
59
58
60 private:
59 private:
61 QMap<QString , Range> m_categoriesMap;
60 QMap<QString , Range> m_intervalsMap;
62 QStringList m_categories;
61 QStringList m_intervals;
63 qreal m_categoryMinimum;
62 qreal m_categoryMinimum;
64
63
65 private:
64 private:
66 Q_DECLARE_PUBLIC(QIntervalAxis)
65 Q_DECLARE_PUBLIC(QIntervalsAxis)
67 };
66 };
68
67
69 QTCOMMERCIALCHART_END_NAMESPACE
68 QTCOMMERCIALCHART_END_NAMESPACE
@@ -59,7 +59,7 private:
59 void looseNiceNumbers(qreal &min, qreal &max, int &ticksCount) const;
59 void looseNiceNumbers(qreal &min, qreal &max, int &ticksCount) const;
60 qreal niceNumber(qreal x,bool ceiling) const;
60 qreal niceNumber(qreal x,bool ceiling) const;
61
61
62 private:
62 protected:
63 qreal m_min;
63 qreal m_min;
64 qreal m_max;
64 qreal m_max;
65 int m_tickCount;
65 int m_tickCount;
General Comments 0
You need to be logged in to leave comments. Login now