##// END OF EJS Templates
QCategoryAxis to QIntervalAxis part 1 of 2
Michal Klocek -
r1614:ec094357a3fd
parent child
Show More
@@ -1,149 +1,149
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "qcategoriesaxis.h"
21 #include "qcategoriesaxis.h"
22 #include "qcategoriesaxis_p.h"
22 #include "qcategoriesaxis_p.h"
23 #include "chartcategoriesaxisx_p.h"
23 #include "chartcategoriesaxisx_p.h"
24 #include "chartcategoriesaxisy_p.h"
24 #include "chartcategoriesaxisy_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 QCategoriesAxis::QCategoriesAxis(QObject *parent):
30 QIntervalAxis::QIntervalAxis(QObject *parent):
31 QValuesAxis(*new QCategoriesAxisPrivate(this),parent)
31 QValuesAxis(*new QIntervalAxisPrivate(this),parent)
32 {
32 {
33 }
33 }
34
34
35 QCategoriesAxis::~QCategoriesAxis()
35 QIntervalAxis::~QIntervalAxis()
36 {
36 {
37 }
37 }
38
38
39 QCategoriesAxis::QCategoriesAxis(QCategoriesAxisPrivate &d,QObject *parent):QValuesAxis(d,parent)
39 QIntervalAxis::QIntervalAxis(QIntervalAxisPrivate &d,QObject *parent):QValuesAxis(d,parent)
40 {
40 {
41
41
42 }
42 }
43
43
44 /*!
44 /*!
45 Appends \a categories to axis
45 Appends \a categories to axis
46 */
46 */
47 void QCategoriesAxis::append(const QString& category, qreal x)
47 void QIntervalAxis::append(const QString& category, qreal x)
48 {
48 {
49 Q_D(QCategoriesAxis);
49 Q_D(QIntervalAxis);
50 if (!d->m_categories.contains(category))
50 if (!d->m_categories.contains(category))
51 {
51 {
52 if(d->m_categories.isEmpty()){
52 if(d->m_categories.isEmpty()){
53 Range range(d->m_categoryMinimum,x);
53 Range range(d->m_categoryMinimum,x);
54 d->m_categoriesMap.insert(category,range);
54 d->m_categoriesMap.insert(category,range);
55 d->m_categories.append(category);
55 d->m_categories.append(category);
56 }else{
56 }else{
57 Range range = d->m_categoriesMap.value(d->m_categories.last());
57 Range range = d->m_categoriesMap.value(d->m_categories.last());
58 d->m_categoriesMap.insert(category,Range(range.first,x));
58 d->m_categoriesMap.insert(category,Range(range.first,x));
59 d->m_categories.append(category);
59 d->m_categories.append(category);
60 }
60 }
61 setRange(d->m_min,x);
61 setRange(d->m_min,x);
62 }
62 }
63 }
63 }
64
64
65 void QCategoriesAxis::setFisrtCategoryMinimum(qreal x)
65 void QIntervalAxis::setFisrtCategoryMinimum(qreal x)
66 {
66 {
67 Q_D(QCategoriesAxis);
67 Q_D(QIntervalAxis);
68 if(d->m_categories.isEmpty()){
68 if(d->m_categories.isEmpty()){
69 d->m_categoryMinimum=x;
69 d->m_categoryMinimum=x;
70 }else{
70 }else{
71 Range range = d->m_categoriesMap.value(d->m_categories.first());
71 Range range = d->m_categoriesMap.value(d->m_categories.first());
72 d->m_categoriesMap.insert(d->m_categories.first(),Range(x,range.second));
72 d->m_categoriesMap.insert(d->m_categories.first(),Range(x,range.second));
73 setRange(x,d->m_min);
73 setRange(x,d->m_min);
74 }
74 }
75 }
75 }
76
76
77 /*!
77 /*!
78 Removes \a category from axis
78 Removes \a category from axis
79 */
79 */
80 void QCategoriesAxis::remove(const QString &category)
80 void QIntervalAxis::remove(const QString &category)
81 {
81 {
82 Q_UNUSED(category);
82 Q_UNUSED(category);
83 //TODO
83 //TODO
84 }
84 }
85
85
86 QStringList QCategoriesAxis::categories()
86 QStringList QIntervalAxis::categories()
87 {
87 {
88 Q_D(QCategoriesAxis);
88 Q_D(QIntervalAxis);
89 return d->m_categories;
89 return d->m_categories;
90 }
90 }
91
91
92 /*!
92 /*!
93 Returns number of categories.
93 Returns number of categories.
94 */
94 */
95 int QCategoriesAxis::count() const
95 int QIntervalAxis::count() const
96 {
96 {
97 Q_D(const QCategoriesAxis);
97 Q_D(const QIntervalAxis);
98 return d->m_categories.count();
98 return d->m_categories.count();
99 }
99 }
100
100
101 /*!
101 /*!
102 Returns the type of axis.
102 Returns the type of axis.
103 */
103 */
104 QAbstractAxis::AxisType QCategoriesAxis::type() const
104 QAbstractAxis::AxisType QIntervalAxis::type() const
105 {
105 {
106 return AxisTypeCategories;
106 return AxisTypeCategories;
107 }
107 }
108
108
109 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
109 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
110
110
111 QCategoriesAxisPrivate::QCategoriesAxisPrivate(QCategoriesAxis* q):
111 QIntervalAxisPrivate::QIntervalAxisPrivate(QIntervalAxis* q):
112 QValuesAxisPrivate(q),
112 QValuesAxisPrivate(q),
113 m_categoryMinimum(0)
113 m_categoryMinimum(0)
114 {
114 {
115
115
116 }
116 }
117
117
118 QCategoriesAxisPrivate::~QCategoriesAxisPrivate()
118 QIntervalAxisPrivate::~QIntervalAxisPrivate()
119 {
119 {
120
120
121 }
121 }
122
122
123 int QCategoriesAxisPrivate::ticksCount() const
123 int QIntervalAxisPrivate::ticksCount() const
124 {
124 {
125 return m_categories.count()+1;
125 return m_categories.count()+1;
126 }
126 }
127
127
128 void QCategoriesAxisPrivate::handleAxisRangeChanged(qreal min, qreal max,int count)
128 void QIntervalAxisPrivate::handleAxisRangeChanged(qreal min, qreal max,int count)
129 {
129 {
130 m_min = min;
130 m_min = min;
131 m_max = max;
131 m_max = max;
132 m_ticksCount = count;
132 m_ticksCount = count;
133 }
133 }
134
134
135 ChartAxis* QCategoriesAxisPrivate::createGraphics(ChartPresenter* presenter)
135 ChartAxis* QIntervalAxisPrivate::createGraphics(ChartPresenter* presenter)
136 {
136 {
137 Q_UNUSED(presenter);
137 Q_UNUSED(presenter);
138 // Q_Q( QCategoriesAxis);
138 // Q_Q( QCategoriesAxis);
139 if(m_orientation == Qt::Vertical){
139 if(m_orientation == Qt::Vertical){
140 return 0;
140 return 0;
141 }else{
141 }else{
142 return 0;
142 return 0;
143 }
143 }
144 }
144 }
145
145
146 #include "moc_qcategoriesaxis.cpp"
146 #include "moc_qcategoriesaxis.cpp"
147 #include "moc_qcategoriesaxis_p.cpp"
147 #include "moc_qcategoriesaxis_p.cpp"
148
148
149 QTCOMMERCIALCHART_END_NAMESPACE
149 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,64 +1,64
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #ifndef QCATEGORIESAXIS_H
21 #ifndef QCATEGORIESAXIS_H
22 #define QCATEGORIESAXIS_H
22 #define QCATEGORIESAXIS_H
23
23
24 #include "qabstractaxis.h"
24 #include "qabstractaxis.h"
25 #include "qvaluesaxis.h"
25 #include "qvaluesaxis.h"
26
26
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28
28
29 class QCategoriesAxisPrivate;
29 class QIntervalAxisPrivate;
30
30
31 class QTCOMMERCIALCHART_EXPORT QCategoriesAxis : public QValuesAxis
31 class QTCOMMERCIALCHART_EXPORT QIntervalAxis : public QValuesAxis
32 {
32 {
33 Q_OBJECT
33 Q_OBJECT
34
34
35 public:
35 public:
36 explicit QCategoriesAxis(QObject *parent = 0);
36 explicit QIntervalAxis(QObject *parent = 0);
37 ~QCategoriesAxis();
37 ~QIntervalAxis();
38
38
39 protected:
39 protected:
40 QCategoriesAxis(QCategoriesAxisPrivate &d,QObject *parent = 0);
40 QIntervalAxis(QIntervalAxisPrivate &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& category, qreal interval = 1);
46 void remove(const QString& category);
46 void remove(const QString& category);
47
47
48 void setFisrtCategoryMinimum(qreal x);
48 void setFisrtCategoryMinimum(qreal x);
49
49
50 qreal categoryMin(const QString& category) const;
50 qreal categoryMin(const QString& category) const;
51 qreal categoryMax(const QString& category) const;
51 qreal categoryMax(const QString& category) const;
52
52
53 QStringList categories();
53 QStringList categories();
54 int count() const;
54 int count() const;
55
55
56
56
57 private:
57 private:
58 Q_DECLARE_PRIVATE(QCategoriesAxis)
58 Q_DECLARE_PRIVATE(QIntervalAxis)
59 Q_DISABLE_COPY(QCategoriesAxis)
59 Q_DISABLE_COPY(QIntervalAxis)
60 };
60 };
61
61
62 QTCOMMERCIALCHART_END_NAMESPACE
62 QTCOMMERCIALCHART_END_NAMESPACE
63
63
64 #endif // QCATEGORIESAXIS_H
64 #endif // QCATEGORIESAXIS_H
@@ -1,71 +1,71
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 // W A R N I N G
21 // W A R N I N G
22 // -------------
22 // -------------
23 //
23 //
24 // This file is not part of the QtCommercial Chart API. It exists purely as an
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
25 // implementation detail. This header file may change from version to
26 // version without notice, or even be removed.
26 // version without notice, or even be removed.
27 //
27 //
28 // We mean it.
28 // We mean it.
29
29
30 #ifndef QCATEGORIESAXIS_P_H
30 #ifndef QCATEGORIESAXIS_P_H
31 #define QCATEGORIESAXIS_P_H
31 #define QCATEGORIESAXIS_P_H
32
32
33 #include "qcategoriesaxis.h"
33 #include "qcategoriesaxis.h"
34 #include "qvaluesaxis_p.h"
34 #include "qvaluesaxis_p.h"
35
35
36 QTCOMMERCIALCHART_BEGIN_NAMESPACE
36 QTCOMMERCIALCHART_BEGIN_NAMESPACE
37
37
38
38
39 typedef QPair<qreal, qreal> Range;
39 typedef QPair<qreal, qreal> Range;
40
40
41 class QCategoriesAxisPrivate : public QValuesAxisPrivate
41 class QIntervalAxisPrivate : public QValuesAxisPrivate
42 {
42 {
43 Q_OBJECT
43 Q_OBJECT
44
44
45 public:
45 public:
46 QCategoriesAxisPrivate(QCategoriesAxis *q);
46 QIntervalAxisPrivate(QIntervalAxis *q);
47 ~QCategoriesAxisPrivate();
47 ~QIntervalAxisPrivate();
48
48
49
49
50 public:
50 public:
51 ChartAxis* createGraphics(ChartPresenter* presenter);
51 ChartAxis* createGraphics(ChartPresenter* presenter);
52 int ticksCount() const;
52 int ticksCount() const;
53
53
54 Q_SIGNALS:
54 Q_SIGNALS:
55 void changed(qreal min, qreal max, int tickCount,bool niceNumbers);
55 void changed(qreal min, qreal max, int tickCount,bool niceNumbers);
56
56
57 public Q_SLOTS:
57 public Q_SLOTS:
58 void handleAxisRangeChanged(qreal min, qreal max,int count);
58 void handleAxisRangeChanged(qreal min, qreal max,int count);
59
59
60 private:
60 private:
61 QMap<QString , Range> m_categoriesMap;
61 QMap<QString , Range> m_categoriesMap;
62 QStringList m_categories;
62 QStringList m_categories;
63 qreal m_categoryMinimum;
63 qreal m_categoryMinimum;
64
64
65 private:
65 private:
66 Q_DECLARE_PUBLIC(QCategoriesAxis)
66 Q_DECLARE_PUBLIC(QIntervalAxis)
67 };
67 };
68
68
69 QTCOMMERCIALCHART_END_NAMESPACE
69 QTCOMMERCIALCHART_END_NAMESPACE
70
70
71 #endif // QCATEGORIESAXIS_P_H
71 #endif // QCATEGORIESAXIS_P_H
General Comments 0
You need to be logged in to leave comments. Login now