@@ -0,0 +1,144 | |||||
|
1 | /**************************************************************************** | |||
|
2 | ** | |||
|
3 | ** Copyright (C) 2013 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 "customtablemodel.h" | |||
|
22 | #include <QVector> | |||
|
23 | #include <QTime> | |||
|
24 | #include <QRect> | |||
|
25 | #include <QColor> | |||
|
26 | ||||
|
27 | const QString categories[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Nov", "Dec"}; | |||
|
28 | ||||
|
29 | CustomTableModel::CustomTableModel(QObject *parent) : | |||
|
30 | QAbstractTableModel(parent) | |||
|
31 | { | |||
|
32 | // qsrand(QTime(0, 0, 0).secsTo(QTime::currentTime())); | |||
|
33 | ||||
|
34 | m_columnCount = 6; | |||
|
35 | m_rowCount = 5; | |||
|
36 | QVector<qreal>* dataVec_Jan = new QVector<qreal>(m_rowCount); | |||
|
37 | dataVec_Jan->insert(0, 3.0); | |||
|
38 | dataVec_Jan->insert(1, 4.0); | |||
|
39 | dataVec_Jan->insert(2, 4.4); | |||
|
40 | dataVec_Jan->insert(3, 6.0); | |||
|
41 | dataVec_Jan->insert(4, 7.0); | |||
|
42 | m_data.append(dataVec_Jan); | |||
|
43 | ||||
|
44 | QVector<qreal>* dataVec_Feb = new QVector<qreal>(m_rowCount); | |||
|
45 | dataVec_Feb->insert(0, 5.0); | |||
|
46 | dataVec_Feb->insert(1, 6.0); | |||
|
47 | dataVec_Feb->insert(2, 7.5); | |||
|
48 | dataVec_Feb->insert(3, 8.0); | |||
|
49 | dataVec_Feb->insert(4, 12.0); | |||
|
50 | m_data.append(dataVec_Feb); | |||
|
51 | ||||
|
52 | QVector<qreal>* dataVec_Mar = new QVector<qreal>(m_rowCount); | |||
|
53 | dataVec_Mar->insert(0, 3.0); | |||
|
54 | dataVec_Mar->insert(1, 4.0); | |||
|
55 | dataVec_Mar->insert(2, 5.7); | |||
|
56 | dataVec_Mar->insert(3, 8.0); | |||
|
57 | dataVec_Mar->insert(4, 9.0); | |||
|
58 | m_data.append(dataVec_Mar); | |||
|
59 | ||||
|
60 | QVector<qreal>* dataVec_Apr = new QVector<qreal>(m_rowCount); | |||
|
61 | dataVec_Apr->insert(0, 5.0); | |||
|
62 | dataVec_Apr->insert(1, 6.0); | |||
|
63 | dataVec_Apr->insert(2, 6.8); | |||
|
64 | dataVec_Apr->insert(3, 7.0); | |||
|
65 | dataVec_Apr->insert(4, 8.0); | |||
|
66 | m_data.append(dataVec_Apr); | |||
|
67 | ||||
|
68 | QVector<qreal>* dataVec_May = new QVector<qreal>(m_rowCount); | |||
|
69 | dataVec_May->insert(0, 4.0); | |||
|
70 | dataVec_May->insert(1, 5.0); | |||
|
71 | dataVec_May->insert(2, 5.2); | |||
|
72 | dataVec_May->insert(3, 6.0); | |||
|
73 | dataVec_May->insert(4, 7.0); | |||
|
74 | m_data.append(dataVec_May); | |||
|
75 | ||||
|
76 | QVector<qreal>* dataVec_Jun = new QVector<qreal>(m_rowCount); | |||
|
77 | dataVec_Jun->insert(0, 4.0); | |||
|
78 | dataVec_Jun->insert(1, 7.0); | |||
|
79 | dataVec_Jun->insert(2, 8.2); | |||
|
80 | dataVec_Jun->insert(3, 9.0); | |||
|
81 | dataVec_Jun->insert(4, 10.0); | |||
|
82 | m_data.append(dataVec_Jun); | |||
|
83 | } | |||
|
84 | ||||
|
85 | int CustomTableModel::rowCount(const QModelIndex &parent) const | |||
|
86 | { | |||
|
87 | Q_UNUSED(parent) | |||
|
88 | return m_rowCount; | |||
|
89 | } | |||
|
90 | ||||
|
91 | int CustomTableModel::columnCount(const QModelIndex &parent) const | |||
|
92 | { | |||
|
93 | Q_UNUSED(parent) | |||
|
94 | return m_data.count(); | |||
|
95 | } | |||
|
96 | ||||
|
97 | QVariant CustomTableModel::headerData(int section, Qt::Orientation orientation, int role) const | |||
|
98 | { | |||
|
99 | if (role != Qt::DisplayRole) | |||
|
100 | return QVariant(); | |||
|
101 | ||||
|
102 | if (orientation == Qt::Horizontal) | |||
|
103 | return categories[section]; | |||
|
104 | else | |||
|
105 | return QString("%1").arg(section + 1); | |||
|
106 | } | |||
|
107 | ||||
|
108 | QVariant CustomTableModel::data(const QModelIndex &index, int role) const | |||
|
109 | { | |||
|
110 | if (role == Qt::DisplayRole) { | |||
|
111 | return m_data[index.column()]->at(index.row()); | |||
|
112 | } else if (role == Qt::EditRole) { | |||
|
113 | return m_data[index.column()]->at(index.row()); | |||
|
114 | } else if (role == Qt::BackgroundRole) { | |||
|
115 | QRect rect; | |||
|
116 | foreach (rect, m_mapping) | |||
|
117 | if (rect.contains(index.column(), index.row())) | |||
|
118 | return QColor(m_mapping.key(rect)); | |||
|
119 | ||||
|
120 | // cell not mapped return white color | |||
|
121 | return QColor(Qt::white); | |||
|
122 | } | |||
|
123 | return QVariant(); | |||
|
124 | } | |||
|
125 | ||||
|
126 | bool CustomTableModel::setData(const QModelIndex &index, const QVariant &value, int role) | |||
|
127 | { | |||
|
128 | if (index.isValid() && role == Qt::EditRole) { | |||
|
129 | m_data[index.column()]->replace(index.row(), value.toDouble()); | |||
|
130 | emit dataChanged(index, index); | |||
|
131 | return true; | |||
|
132 | } | |||
|
133 | return false; | |||
|
134 | } | |||
|
135 | ||||
|
136 | Qt::ItemFlags CustomTableModel::flags(const QModelIndex &index) const | |||
|
137 | { | |||
|
138 | return QAbstractItemModel::flags(index) | Qt::ItemIsEditable; | |||
|
139 | } | |||
|
140 | ||||
|
141 | void CustomTableModel::addMapping(QString color, QRect area) | |||
|
142 | { | |||
|
143 | m_mapping.insertMulti(color, area); | |||
|
144 | } |
@@ -0,0 +1,51 | |||||
|
1 | /**************************************************************************** | |||
|
2 | ** | |||
|
3 | ** Copyright (C) 2013 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 | #ifndef CUSTOMTABLEMODEL_H | |||
|
22 | #define CUSTOMTABLEMODEL_H | |||
|
23 | ||||
|
24 | #include <QAbstractTableModel> | |||
|
25 | #include <QHash> | |||
|
26 | #include <QRect> | |||
|
27 | ||||
|
28 | class CustomTableModel : public QAbstractTableModel | |||
|
29 | { | |||
|
30 | Q_OBJECT | |||
|
31 | public: | |||
|
32 | explicit CustomTableModel(QObject *parent = 0); | |||
|
33 | ||||
|
34 | int rowCount(const QModelIndex &parent = QModelIndex()) const; | |||
|
35 | int columnCount(const QModelIndex &parent = QModelIndex()) const; | |||
|
36 | QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const; | |||
|
37 | QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; | |||
|
38 | bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole); | |||
|
39 | Qt::ItemFlags flags(const QModelIndex &index) const; | |||
|
40 | ||||
|
41 | void addMapping(QString color, QRect area); | |||
|
42 | void clearMapping() { m_mapping.clear(); } | |||
|
43 | ||||
|
44 | private: | |||
|
45 | QList<QVector<qreal> * > m_data; | |||
|
46 | QHash<QString, QRect> m_mapping; | |||
|
47 | int m_columnCount; | |||
|
48 | int m_rowCount; | |||
|
49 | }; | |||
|
50 | ||||
|
51 | #endif // CUSTOMTABLEMODEL_H |
@@ -1,61 +1,79 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2013 Digia Plc |
|
3 | ** Copyright (C) 2013 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 "boxplotanimation_p.h" |
|
21 | #include "boxplotanimation_p.h" | |
22 | #include "boxplotchartitem_p.h" |
|
22 | #include "boxplotchartitem_p.h" | |
23 | #include "boxwhiskersdata_p.h" |
|
23 | #include "boxwhiskersdata_p.h" | |
24 | #include "boxwhiskersanimation_p.h" |
|
24 | #include "boxwhiskersanimation_p.h" | |
25 | #include <QDebug> |
|
25 | #include <QDebug> | |
26 |
|
26 | |||
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
28 |
|
28 | |||
29 | BoxPlotAnimation::BoxPlotAnimation(BoxPlotChartItem *item) |
|
29 | BoxPlotAnimation::BoxPlotAnimation(BoxPlotChartItem *item) | |
30 | : m_item(item) |
|
30 | : m_item(item) | |
31 | { |
|
31 | { | |
32 | } |
|
32 | } | |
33 |
|
33 | |||
34 | BoxPlotAnimation::~BoxPlotAnimation() |
|
34 | BoxPlotAnimation::~BoxPlotAnimation() | |
35 | { |
|
35 | { | |
36 | } |
|
36 | } | |
37 |
|
37 | |||
38 | void BoxPlotAnimation::addBox(BoxWhiskers *box) |
|
38 | void BoxPlotAnimation::addBox(BoxWhiskers *box) | |
39 | { |
|
39 | { | |
40 | BoxWhiskersAnimation *animation = m_animations.value(box); |
|
40 | BoxWhiskersAnimation *animation = m_animations.value(box); | |
41 | if (!animation) { |
|
41 | if (!animation) { | |
42 | animation = new BoxWhiskersAnimation(box); |
|
42 | animation = new BoxWhiskersAnimation(box); | |
43 | m_animations.insert(box, animation); |
|
43 | m_animations.insert(box, animation); | |
44 | BoxWhiskersData start; |
|
44 | BoxWhiskersData start; | |
45 | start.m_median = box->m_data.m_median; |
|
45 | start.m_median = box->m_data.m_median; | |
46 | animation->setup(start, box->m_data); |
|
46 | animation->setup(start, box->m_data); | |
47 | } else { |
|
47 | } else { | |
48 | animation->stop(); |
|
48 | animation->stop(); | |
49 | animation->setEndData(box->m_data); |
|
49 | animation->setEndData(box->m_data); | |
50 | } |
|
50 | } | |
51 | } |
|
51 | } | |
52 |
|
52 | |||
53 | ChartAnimation *BoxPlotAnimation::boxAnimation(BoxWhiskers *box) |
|
53 | ChartAnimation *BoxPlotAnimation::boxAnimation(BoxWhiskers *box) | |
54 | { |
|
54 | { | |
55 | // TODO: Check for missing animation |
|
55 | // TODO: Check for missing animation | |
56 |
|
|
56 | BoxWhiskersAnimation *animation = m_animations.value(box); | |
|
57 | animation->m_moveMedianLine = false; | |||
|
58 | ||||
|
59 | return animation; | |||
|
60 | } | |||
|
61 | ||||
|
62 | ChartAnimation *BoxPlotAnimation::boxChangeAnimation(BoxWhiskers *box) | |||
|
63 | { | |||
|
64 | BoxWhiskersAnimation *animation = m_animations.value(box); | |||
|
65 | animation->m_moveMedianLine = true; | |||
|
66 | animation->setEndData(box->m_data); | |||
|
67 | ||||
|
68 | return animation; | |||
|
69 | } | |||
|
70 | ||||
|
71 | void BoxPlotAnimation::setAnimationStart(BoxWhiskers *box) | |||
|
72 | { | |||
|
73 | BoxWhiskersAnimation *animation = m_animations.value(box); | |||
|
74 | animation->setStartData(box->m_data); | |||
57 | } |
|
75 | } | |
58 |
|
76 | |||
59 | //#include "moc_boxplotanimation_p.cpp" |
|
77 | //#include "moc_boxplotanimation_p.cpp" | |
60 |
|
78 | |||
61 | QTCOMMERCIALCHART_END_NAMESPACE |
|
79 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,59 +1,62 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2013 Digia Plc |
|
3 | ** Copyright (C) 2013 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 BOXPLOTANIMATION_P_H |
|
30 | #ifndef BOXPLOTANIMATION_P_H | |
31 | #define BOXPLOTANIMATION_P_H |
|
31 | #define BOXPLOTANIMATION_P_H | |
32 |
|
32 | |||
33 | #include "chartanimation_p.h" |
|
33 | #include "chartanimation_p.h" | |
34 | #include "boxwhiskers_p.h" |
|
34 | #include "boxwhiskers_p.h" | |
35 | #include "boxwhiskersdata_p.h" |
|
35 | #include "boxwhiskersdata_p.h" | |
36 | #include "boxwhiskersanimation_p.h" |
|
36 | #include "boxwhiskersanimation_p.h" | |
37 |
|
37 | |||
38 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
38 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
39 |
|
39 | |||
40 | class BoxPlotChartItem; |
|
40 | class BoxPlotChartItem; | |
41 |
|
41 | |||
42 | class BoxPlotAnimation /*: public ChartAnimation*/ |
|
42 | class BoxPlotAnimation /*: public ChartAnimation*/ | |
43 | { |
|
43 | { | |
44 | //Q_OBJECT |
|
44 | //Q_OBJECT | |
45 | public: |
|
45 | public: | |
46 | BoxPlotAnimation(BoxPlotChartItem *item); |
|
46 | BoxPlotAnimation(BoxPlotChartItem *item); | |
47 | ~BoxPlotAnimation(); |
|
47 | ~BoxPlotAnimation(); | |
48 |
|
48 | |||
49 | void addBox(BoxWhiskers *box); |
|
49 | void addBox(BoxWhiskers *box); | |
50 | ChartAnimation *boxAnimation(BoxWhiskers *box); |
|
50 | ChartAnimation *boxAnimation(BoxWhiskers *box); | |
|
51 | ChartAnimation *boxChangeAnimation(BoxWhiskers *box); | |||
|
52 | ||||
|
53 | void setAnimationStart(BoxWhiskers *box); | |||
51 |
|
54 | |||
52 | protected: |
|
55 | protected: | |
53 | BoxPlotChartItem *m_item; |
|
56 | BoxPlotChartItem *m_item; | |
54 | QHash<BoxWhiskers *, BoxWhiskersAnimation *> m_animations; |
|
57 | QHash<BoxWhiskers *, BoxWhiskersAnimation *> m_animations; | |
55 | }; |
|
58 | }; | |
56 |
|
59 | |||
57 | QTCOMMERCIALCHART_END_NAMESPACE |
|
60 | QTCOMMERCIALCHART_END_NAMESPACE | |
58 |
|
61 | |||
59 | #endif // BOXPLOTANIMATION_P_H |
|
62 | #endif // BOXPLOTANIMATION_P_H |
@@ -1,113 +1,115 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2013 Digia Plc |
|
3 | ** Copyright (C) 2013 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 "boxwhiskersanimation_p.h" |
|
21 | #include "boxwhiskersanimation_p.h" | |
22 | #include "boxplotanimation_p.h" |
|
22 | #include "boxplotanimation_p.h" | |
23 | #include "boxplotchartitem_p.h" |
|
23 | #include "boxplotchartitem_p.h" | |
24 | #include "boxwhiskersdata_p.h" |
|
24 | #include "boxwhiskersdata_p.h" | |
25 | #include <QDebug> |
|
25 | #include <QDebug> | |
26 |
|
26 | |||
27 | Q_DECLARE_METATYPE(QVector<QRectF>) |
|
27 | Q_DECLARE_METATYPE(QVector<QRectF>) | |
28 | Q_DECLARE_METATYPE(QTCOMMERCIALCHART_NAMESPACE::BoxWhiskersData) |
|
28 | Q_DECLARE_METATYPE(QTCOMMERCIALCHART_NAMESPACE::BoxWhiskersData) | |
29 | Q_DECLARE_METATYPE(qreal) |
|
29 | Q_DECLARE_METATYPE(qreal) | |
30 |
|
30 | |||
31 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
31 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
32 |
|
32 | |||
33 | BoxWhiskersAnimation::BoxWhiskersAnimation(BoxPlotChartItem *item) |
|
|||
34 | : ChartAnimation(item), |
|
|||
35 | m_item(item) |
|
|||
36 | { |
|
|||
37 | setDuration(ChartAnimationDuration); |
|
|||
38 | setEasingCurve(QEasingCurve::OutQuart); |
|
|||
39 | } |
|
|||
40 |
|
||||
41 | BoxWhiskersAnimation::BoxWhiskersAnimation(BoxWhiskers *box) |
|
33 | BoxWhiskersAnimation::BoxWhiskersAnimation(BoxWhiskers *box) | |
42 | : ChartAnimation(box), |
|
34 | : ChartAnimation(box), | |
43 | m_box(box) |
|
35 | m_box(box) | |
44 | { |
|
36 | { | |
45 | setDuration(ChartAnimationDuration); |
|
37 | setDuration(ChartAnimationDuration); | |
46 | setEasingCurve(QEasingCurve::OutQuart); |
|
38 | setEasingCurve(QEasingCurve::OutQuart); | |
47 | } |
|
39 | } | |
48 |
|
40 | |||
49 | BoxWhiskersAnimation::~BoxWhiskersAnimation() |
|
41 | BoxWhiskersAnimation::~BoxWhiskersAnimation() | |
50 | { |
|
42 | { | |
51 | } |
|
43 | } | |
52 |
|
44 | |||
53 | QVariant BoxWhiskersAnimation::interpolated(const QVariant &from, const QVariant &to, qreal progress) const |
|
45 | QVariant BoxWhiskersAnimation::interpolated(const QVariant &from, const QVariant &to, qreal progress) const | |
54 | { |
|
46 | { | |
55 | BoxWhiskersData startData = qvariant_cast<BoxWhiskersData>(from); |
|
47 | BoxWhiskersData startData = qvariant_cast<BoxWhiskersData>(from); | |
56 | BoxWhiskersData endData = qvariant_cast<BoxWhiskersData>(to); |
|
48 | BoxWhiskersData endData = qvariant_cast<BoxWhiskersData>(to); | |
57 | BoxWhiskersData result; |
|
49 | BoxWhiskersData result; | |
58 |
|
50 | |||
59 | if (endData.m_index == 1) { |
|
51 | if (endData.m_index == 1) { | |
60 | //qDebug() << "endData.m_lowerExtreme = " << endData.m_lowerExtreme; |
|
52 | //qDebug() << "endData.m_lowerExtreme = " << endData.m_lowerExtreme; | |
61 | //qDebug() << "endData.m_median = " << endData.m_median; |
|
53 | //qDebug() << "endData.m_median = " << endData.m_median; | |
62 | } |
|
54 | } | |
63 |
|
55 | |||
64 | result.m_lowerExtreme = endData.m_median + progress * (endData.m_lowerExtreme - endData.m_median); |
|
56 | if (m_moveMedianLine) { | |
65 |
result.m_lower |
|
57 | result.m_lowerExtreme = startData.m_lowerExtreme + progress * (endData.m_lowerExtreme - startData.m_lowerExtreme); | |
66 | result.m_median = endData.m_median; |
|
58 | result.m_lowerQuartile = startData.m_lowerQuartile + progress * (endData.m_lowerQuartile - startData.m_lowerQuartile); | |
67 |
result.m_ |
|
59 | result.m_median = startData.m_median + progress * (endData.m_median - startData.m_median); | |
68 |
result.m_upper |
|
60 | result.m_upperQuartile = startData.m_upperQuartile + progress * (endData.m_upperQuartile - startData.m_upperQuartile); | |
|
61 | result.m_upperExtreme = startData.m_upperExtreme + progress * (endData.m_upperExtreme - startData.m_upperExtreme); | |||
|
62 | } else { | |||
|
63 | result.m_lowerExtreme = endData.m_median + progress * (endData.m_lowerExtreme - endData.m_median); | |||
|
64 | result.m_lowerQuartile = endData.m_median + progress * (endData.m_lowerQuartile - endData.m_median); | |||
|
65 | result.m_median = endData.m_median; | |||
|
66 | result.m_upperQuartile = endData.m_median + progress * (endData.m_upperQuartile - endData.m_median); | |||
|
67 | result.m_upperExtreme = endData.m_median + progress * (endData.m_upperExtreme - endData.m_median); | |||
|
68 | } | |||
69 | result.m_index = endData.m_index; |
|
69 | result.m_index = endData.m_index; | |
70 | result.m_boxItems = endData.m_boxItems; |
|
70 | result.m_boxItems = endData.m_boxItems; | |
71 |
|
71 | |||
72 | // result.m_lowerExtreme = endData.m_lowerExtreme; |
|
|||
73 | // result.m_lowerQuartile = endData.m_lowerQuartile; |
|
|||
74 | // result.m_median = endData.m_median; |
|
|||
75 | // result.m_upperQuartile = endData.m_upperQuartile; |
|
|||
76 | // result.m_upperExtreme = endData.m_upperExtreme; |
|
|||
77 | // result.m_index = endData.m_index; |
|
|||
78 | // result.m_boxItems = endData.m_boxItems; |
|
|||
79 |
|
72 | |||
80 | result.m_maxX = endData.m_maxX; |
|
73 | result.m_maxX = endData.m_maxX; | |
81 | result.m_minX = endData.m_minX; |
|
74 | result.m_minX = endData.m_minX; | |
82 | result.m_maxY = endData.m_maxY; |
|
75 | result.m_maxY = endData.m_maxY; | |
83 | result.m_minY = endData.m_minY; |
|
76 | result.m_minY = endData.m_minY; | |
84 | result.m_seriesIndex = endData.m_seriesIndex; |
|
77 | result.m_seriesIndex = endData.m_seriesIndex; | |
85 | result.m_seriesCount = endData.m_seriesCount; |
|
78 | result.m_seriesCount = endData.m_seriesCount; | |
86 |
|
79 | |||
87 | return qVariantFromValue(result); |
|
80 | return qVariantFromValue(result); | |
88 | } |
|
81 | } | |
89 |
|
82 | |||
90 | void BoxWhiskersAnimation::updateCurrentValue(const QVariant &value) |
|
83 | void BoxWhiskersAnimation::updateCurrentValue(const QVariant &value) | |
91 | { |
|
84 | { | |
92 | BoxWhiskersData data = qvariant_cast<BoxWhiskersData>(value); |
|
85 | BoxWhiskersData data = qvariant_cast<BoxWhiskersData>(value); | |
93 | m_box->setLayout(data); |
|
86 | m_box->setLayout(data); | |
94 | } |
|
87 | } | |
95 |
|
88 | |||
96 | void BoxWhiskersAnimation::setup(const BoxWhiskersData &startData, const BoxWhiskersData &endData) |
|
89 | void BoxWhiskersAnimation::setup(const BoxWhiskersData &startData, const BoxWhiskersData &endData) | |
97 | { |
|
90 | { | |
98 | setKeyValueAt(0.0, qVariantFromValue(startData)); |
|
91 | setKeyValueAt(0.0, qVariantFromValue(startData)); | |
99 | setKeyValueAt(1.0, qVariantFromValue(endData)); |
|
92 | setKeyValueAt(1.0, qVariantFromValue(endData)); | |
100 | } |
|
93 | } | |
101 |
|
94 | |||
102 | void BoxWhiskersAnimation::setEndData(const BoxWhiskersData &endData) |
|
95 | void BoxWhiskersAnimation::setEndData(const BoxWhiskersData &endData) | |
103 | { |
|
96 | { | |
104 | if (state() != QAbstractAnimation::Stopped) |
|
97 | if (state() != QAbstractAnimation::Stopped) | |
105 | stop(); |
|
98 | stop(); | |
106 |
|
99 | |||
107 | setEndValue(qVariantFromValue(endData)); |
|
100 | setEndValue(qVariantFromValue(endData)); | |
108 | } |
|
101 | } | |
109 |
|
102 | |||
|
103 | void BoxWhiskersAnimation::setStartData(const BoxWhiskersData &endData) | |||
|
104 | { | |||
|
105 | if (state() != QAbstractAnimation::Stopped) | |||
|
106 | stop(); | |||
|
107 | ||||
|
108 | setStartValue(qVariantFromValue(endData)); | |||
|
109 | } | |||
|
110 | ||||
|
111 | ||||
110 | #include "moc_boxwhiskersanimation_p.cpp" |
|
112 | #include "moc_boxwhiskersanimation_p.cpp" | |
111 |
|
113 | |||
112 | QTCOMMERCIALCHART_END_NAMESPACE |
|
114 | QTCOMMERCIALCHART_END_NAMESPACE | |
113 |
|
115 |
@@ -1,65 +1,69 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2013 Digia Plc |
|
3 | ** Copyright (C) 2013 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 BOXWHISKERSANIMATION_P_H |
|
30 | #ifndef BOXWHISKERSANIMATION_P_H | |
31 | #define BOXWHISKERSANIMATION_P_H |
|
31 | #define BOXWHISKERSANIMATION_P_H | |
32 |
|
32 | |||
33 | #include "chartanimation_p.h" |
|
33 | #include "chartanimation_p.h" | |
34 | #include "boxwhiskers_p.h" |
|
34 | #include "boxwhiskers_p.h" | |
35 | #include "boxwhiskersdata_p.h" |
|
35 | #include "boxwhiskersdata_p.h" | |
36 |
|
36 | |||
37 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
37 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
38 |
|
38 | |||
39 | class BoxPlotChartItem; |
|
39 | class BoxPlotChartItem; | |
40 |
|
40 | |||
41 | class BoxWhiskersAnimation : public ChartAnimation |
|
41 | class BoxWhiskersAnimation : public ChartAnimation | |
42 | { |
|
42 | { | |
43 | Q_OBJECT |
|
43 | Q_OBJECT | |
44 |
|
44 | |||
45 | public: |
|
45 | public: | |
46 | BoxWhiskersAnimation(BoxPlotChartItem *item); |
|
|||
47 | BoxWhiskersAnimation(BoxWhiskers *box); |
|
46 | BoxWhiskersAnimation(BoxWhiskers *box); | |
48 | ~BoxWhiskersAnimation(); |
|
47 | ~BoxWhiskersAnimation(); | |
49 |
|
48 | |||
50 | public: // from QVariantAnimation |
|
49 | public: // from QVariantAnimation | |
51 | virtual QVariant interpolated(const QVariant &from, const QVariant &to, qreal progress) const; |
|
50 | virtual QVariant interpolated(const QVariant &from, const QVariant &to, qreal progress) const; | |
52 | virtual void updateCurrentValue(const QVariant &value); |
|
51 | virtual void updateCurrentValue(const QVariant &value); | |
53 |
|
52 | |||
54 | void setup(const BoxWhiskersData &startData, const BoxWhiskersData &endData); |
|
53 | void setup(const BoxWhiskersData &startData, const BoxWhiskersData &endData); | |
55 | void setEndData(const BoxWhiskersData &endData); |
|
54 | void setEndData(const BoxWhiskersData &endData); | |
|
55 | void setStartData(const BoxWhiskersData &endData); | |||
|
56 | ||||
|
57 | void moveMedianLine(bool move); | |||
56 |
|
58 | |||
57 | protected: |
|
59 | protected: | |
|
60 | friend class BoxPlotAnimation; | |||
58 | BoxPlotChartItem *m_item; |
|
61 | BoxPlotChartItem *m_item; | |
59 | BoxWhiskers *m_box; |
|
62 | BoxWhiskers *m_box; | |
60 | BoxWhiskersData *m_boxData; |
|
63 | BoxWhiskersData *m_boxData; | |
|
64 | bool m_moveMedianLine; | |||
61 | }; |
|
65 | }; | |
62 |
|
66 | |||
63 | QTCOMMERCIALCHART_END_NAMESPACE |
|
67 | QTCOMMERCIALCHART_END_NAMESPACE | |
64 |
|
68 | |||
65 | #endif // BOXWHISKERSANIMATION_P_H |
|
69 | #endif // BOXWHISKERSANIMATION_P_H |
@@ -1,196 +1,198 | |||||
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 "boxplotchartitem_p.h" |
|
21 | #include "boxplotchartitem_p.h" | |
22 | #include "qboxplotseries_p.h" |
|
22 | #include "qboxplotseries_p.h" | |
23 | #include "bar_p.h" |
|
23 | #include "bar_p.h" | |
24 | #include "qbarset_p.h" |
|
24 | #include "qbarset_p.h" | |
25 | #include "qabstractbarseries_p.h" |
|
25 | #include "qabstractbarseries_p.h" | |
26 | #include "qbarset.h" |
|
26 | #include "qbarset.h" | |
27 | #include "boxwhiskers_p.h" |
|
27 | #include "boxwhiskers_p.h" | |
28 | #include <QPainter> |
|
28 | #include <QPainter> | |
29 |
|
29 | |||
30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
31 |
|
31 | |||
32 | BoxPlotChartItem::BoxPlotChartItem(QBoxPlotSeries *series, QGraphicsItem* item) : |
|
32 | BoxPlotChartItem::BoxPlotChartItem(QBoxPlotSeries *series, QGraphicsItem* item) : | |
33 | ChartItem(series->d_func(), item), |
|
33 | ChartItem(series->d_func(), item), | |
34 | m_series(series), |
|
34 | m_series(series), | |
35 | m_animation(0), |
|
35 | m_animation(0), | |
36 | m_animate(0) |
|
36 | m_animate(0) | |
37 | { |
|
37 | { | |
38 | connect(series->d_func(), SIGNAL(restructuredBars()), this, SLOT(handleDataStructureChanged())); |
|
38 | connect(series->d_func(), SIGNAL(restructuredBars()), this, SLOT(handleDataStructureChanged())); | |
39 | connect(series->d_func(), SIGNAL(updatedLayout()), this, SLOT(handleLayoutChanged())); |
|
39 | connect(series->d_func(), SIGNAL(updatedLayout()), this, SLOT(handleLayoutChanged())); | |
40 | connect(series->d_func(), SIGNAL(updatedBars()), this, SLOT(handleUpdatedBars())); |
|
40 | connect(series->d_func(), SIGNAL(updatedBars()), this, SLOT(handleUpdatedBars())); | |
41 | connect(series->d_func(), SIGNAL(updated()), this, SLOT(handleUpdatedBars())); |
|
41 | connect(series->d_func(), SIGNAL(updated()), this, SLOT(handleUpdatedBars())); | |
42 | // QBoxPlotSeriesPrivate calls handleDataStructureChanged(), don't do it here |
|
42 | // QBoxPlotSeriesPrivate calls handleDataStructureChanged(), don't do it here | |
43 | setZValue(ChartPresenter::BoxPlotSeriesZValue); |
|
43 | setZValue(ChartPresenter::BoxPlotSeriesZValue); | |
44 |
|
44 | |||
45 | m_barSets = m_series->barSets(); |
|
45 | m_barSets = m_series->barSets(); | |
46 | } |
|
46 | } | |
47 |
|
47 | |||
48 | BoxPlotChartItem::~BoxPlotChartItem() |
|
48 | BoxPlotChartItem::~BoxPlotChartItem() | |
49 | { |
|
49 | { | |
50 | qDebug() << "BoxPlotChartItem::~BoxPlotChartItem() " << m_seriesIndex; |
|
50 | qDebug() << "BoxPlotChartItem::~BoxPlotChartItem() " << m_seriesIndex; | |
51 | } |
|
51 | } | |
52 |
|
52 | |||
53 | void BoxPlotChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
53 | void BoxPlotChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) | |
54 | { |
|
54 | { | |
55 | Q_UNUSED(painter); |
|
55 | Q_UNUSED(painter); | |
56 | Q_UNUSED(option); |
|
56 | Q_UNUSED(option); | |
57 | Q_UNUSED(widget); |
|
57 | Q_UNUSED(widget); | |
58 |
|
58 | |||
59 | //painter->setClipRect(QRectF(QPointF(0,0),domain()->size())); |
|
59 | //painter->setClipRect(QRectF(QPointF(0,0),domain()->size())); | |
60 |
|
60 | |||
61 | //qDebug() << "ALERT EMPTY: BoxPlotChartItem::paint"; |
|
61 | //qDebug() << "ALERT EMPTY: BoxPlotChartItem::paint"; | |
62 | } |
|
62 | } | |
63 |
|
63 | |||
64 | void BoxPlotChartItem::setAnimation(BoxPlotAnimation *animation) |
|
64 | void BoxPlotChartItem::setAnimation(BoxPlotAnimation *animation) | |
65 | { |
|
65 | { | |
66 | //qDebug() << "BoxPlotChartItem::setAnimation :" << animation; |
|
66 | //qDebug() << "BoxPlotChartItem::setAnimation :" << animation; | |
67 |
|
67 | |||
68 | m_animation = animation; |
|
68 | m_animation = animation; | |
69 | if (m_animation) { |
|
69 | if (m_animation) { | |
70 | foreach (BoxWhiskers *item, m_boxTable.values()) { |
|
70 | foreach (BoxWhiskers *item, m_boxTable.values()) { | |
71 | m_animation->addBox(item); |
|
71 | m_animation->addBox(item); | |
72 | } |
|
72 | } | |
73 | handleDomainUpdated(); |
|
73 | handleDomainUpdated(); | |
74 | } |
|
74 | } | |
75 | } |
|
75 | } | |
76 |
|
76 | |||
77 | void BoxPlotChartItem::handleDataStructureChanged() |
|
77 | void BoxPlotChartItem::handleDataStructureChanged() | |
78 | { |
|
78 | { | |
79 | //qDebug() << "BoxPlotChartItem::handleDataStructureChanged()"; |
|
79 | //qDebug() << "BoxPlotChartItem::handleDataStructureChanged()"; | |
80 | int setCount = m_series->count(); |
|
80 | int setCount = m_series->count(); | |
81 |
|
81 | |||
82 | for (int s = 0; s < setCount; s++) { |
|
82 | for (int s = 0; s < setCount; s++) { | |
83 | QBarSet *set = m_series->d_func()->barsetAt(s); |
|
83 | QBarSet *set = m_series->d_func()->barsetAt(s); | |
84 |
|
84 | |||
85 | BoxWhiskers *boxWhiskersItem = m_boxTable.value(set); |
|
85 | BoxWhiskers *boxWhiskersItem = m_boxTable.value(set); | |
86 | if (boxWhiskersItem == 0) { |
|
86 | if (boxWhiskersItem == 0) { | |
87 | // Item is not yet created, make a box and add it to hash table |
|
87 | // Item is not yet created, make a box and add it to hash table | |
88 | boxWhiskersItem = new BoxWhiskers(domain(), this); |
|
88 | boxWhiskersItem = new BoxWhiskers(domain(), this); | |
89 | m_boxTable.insert(set, boxWhiskersItem); |
|
89 | m_boxTable.insert(set, boxWhiskersItem); | |
90 |
|
90 | |||
91 | boxWhiskersItem->setBrush(m_series->brush()); |
|
91 | boxWhiskersItem->setBrush(m_series->brush()); | |
92 | boxWhiskersItem->setPen(m_series->pen()); |
|
92 | boxWhiskersItem->setPen(m_series->pen()); | |
93 | } |
|
93 | } | |
94 | updateBoxGeometry(boxWhiskersItem, s); |
|
94 | updateBoxGeometry(boxWhiskersItem, s); | |
95 |
|
95 | |||
96 | boxWhiskersItem->updateGeometry(); |
|
96 | boxWhiskersItem->updateGeometry(); | |
97 |
|
97 | |||
98 | if (m_animation) |
|
98 | if (m_animation) | |
99 | m_animation->addBox(boxWhiskersItem); |
|
99 | m_animation->addBox(boxWhiskersItem); | |
100 | } |
|
100 | } | |
101 |
|
101 | |||
102 | // |
|
102 | // | |
103 | handleDomainUpdated(); |
|
103 | handleDomainUpdated(); | |
104 | } |
|
104 | } | |
105 |
|
105 | |||
106 | void BoxPlotChartItem::handleUpdatedBars() |
|
106 | void BoxPlotChartItem::handleUpdatedBars() | |
107 | { |
|
107 | { | |
108 | //qDebug() << "BoxPlotChartItem::handleUpdatedBars()"; |
|
108 | //qDebug() << "BoxPlotChartItem::handleUpdatedBars()"; | |
109 |
|
109 | |||
110 | foreach (BoxWhiskers *item, m_boxTable.values()) { |
|
110 | foreach (BoxWhiskers *item, m_boxTable.values()) { | |
111 | item->setBrush(m_series->brush()); |
|
111 | item->setBrush(m_series->brush()); | |
112 | item->setPen(m_series->pen()); |
|
112 | item->setPen(m_series->pen()); | |
113 | } |
|
113 | } | |
114 | } |
|
114 | } | |
115 |
|
115 | |||
116 | void BoxPlotChartItem::handleDomainUpdated() |
|
116 | void BoxPlotChartItem::handleDomainUpdated() | |
117 | { |
|
117 | { | |
118 | //qDebug() << "BoxPlotChartItem::handleDomainUpdated() domain()->size() = " << domain()->size(); |
|
118 | //qDebug() << "BoxPlotChartItem::handleDomainUpdated() domain()->size() = " << domain()->size(); | |
119 |
|
119 | |||
120 | if ((domain()->size().width() <= 0) || (domain()->size().height() <= 0)) |
|
120 | if ((domain()->size().width() <= 0) || (domain()->size().height() <= 0)) | |
121 | return; |
|
121 | return; | |
122 |
|
122 | |||
123 | // Set my bounding rect to same as domain size |
|
123 | // Set my bounding rect to same as domain size | |
124 | m_boundingRect.setRect(0.0, 0.0, domain()->size().width(), domain()->size().height()); |
|
124 | m_boundingRect.setRect(0.0, 0.0, domain()->size().width(), domain()->size().height()); | |
125 |
|
125 | |||
126 | foreach (BoxWhiskers *item, m_boxTable.values()) { |
|
126 | foreach (BoxWhiskers *item, m_boxTable.values()) { | |
127 | // Update the domain size for each BoxWhisker item |
|
127 | // Update the domain size for each BoxWhisker item | |
128 | item->setDomainSize(domain()->size()); |
|
128 | item->setDomainSize(domain()->size()); | |
129 |
|
129 | |||
130 | // If the animation is set, start the animation for each BoxWhisker item |
|
130 | // If the animation is set, start the animation for each BoxWhisker item | |
131 | if (m_animation) { |
|
131 | if (m_animation) { | |
132 | presenter()->startAnimation(m_animation->boxAnimation(item)); |
|
132 | presenter()->startAnimation(m_animation->boxAnimation(item)); | |
133 | } |
|
133 | } | |
134 | } |
|
134 | } | |
135 | } |
|
135 | } | |
136 |
|
136 | |||
137 | void BoxPlotChartItem::handleLayoutChanged() |
|
137 | void BoxPlotChartItem::handleLayoutChanged() | |
138 | { |
|
138 | { | |
139 | //qDebug() << "BoxPlotChartItem::handleLayoutChanged() domain()->size() = " << domain()->size(); |
|
139 | foreach (BoxWhiskers *item, m_boxTable.values()) { | |
140 | //foreach (BoxWhiskers *boxWhiskersItem, m_boxes) |
|
140 | if (m_animation) | |
141 | // boxWhiskersItem->updateGeometry(); |
|
141 | m_animation->setAnimationStart(item); | |
142 | } |
|
|||
143 |
|
142 | |||
144 | void BoxPlotChartItem::handleSeriesRemove(QAbstractSeries *series) |
|
143 | bool dirty = updateBoxGeometry(item, item->m_data.m_index); | |
145 | { |
|
144 | if (dirty && m_animation) | |
146 | qDebug() << "BoxPlotChartItem::handleSeriesRemove " << m_seriesIndex; |
|
145 | presenter()->startAnimation(m_animation->boxChangeAnimation(item)); | |
147 | QBoxPlotSeries *removedSeries = static_cast<QBoxPlotSeries *>(series); |
|
146 | else | |
148 | if (m_series == removedSeries) { |
|
147 | item->updateGeometry(); | |
149 | return; |
|
|||
150 | } |
|
148 | } | |
151 |
|
||||
152 | m_seriesCount = m_seriesCount - 1; |
|
|||
153 |
|
||||
154 | handleDataStructureChanged(); |
|
|||
155 | } |
|
149 | } | |
156 |
|
150 | |||
157 | QRectF BoxPlotChartItem::boundingRect() const |
|
151 | QRectF BoxPlotChartItem::boundingRect() const | |
158 | { |
|
152 | { | |
159 | return m_boundingRect; |
|
153 | return m_boundingRect; | |
160 | } |
|
154 | } | |
161 |
|
155 | |||
162 | void BoxPlotChartItem::initializeLayout() |
|
156 | void BoxPlotChartItem::initializeLayout() | |
163 | { |
|
157 | { | |
164 | qDebug() << "ALERT EMPTY: BoxPlotChartItem::initializeLayout"; |
|
158 | qDebug() << "ALERT EMPTY: BoxPlotChartItem::initializeLayout"; | |
165 | } |
|
159 | } | |
166 |
|
160 | |||
167 | QVector<QRectF> BoxPlotChartItem::calculateLayout() |
|
161 | QVector<QRectF> BoxPlotChartItem::calculateLayout() | |
168 | { |
|
162 | { | |
169 | return QVector<QRectF>(); |
|
163 | return QVector<QRectF>(); | |
170 | } |
|
164 | } | |
171 |
|
165 | |||
172 |
|
|
166 | bool BoxPlotChartItem::updateBoxGeometry(BoxWhiskers *box, int index) | |
173 | { |
|
167 | { | |
|
168 | bool changed = false; | |||
|
169 | ||||
174 | QBarSet *set = m_series->d_func()->barsetAt(index); |
|
170 | QBarSet *set = m_series->d_func()->barsetAt(index); | |
175 | //QBarSet *set = m_barSets.at(index); |
|
|||
176 | BoxWhiskersData &data = box->m_data; |
|
171 | BoxWhiskersData &data = box->m_data; | |
|
172 | ||||
|
173 | if ((data.m_lowerExtreme != set->at(0)) || (data.m_lowerQuartile != set->at(1)) || | |||
|
174 | (data.m_median != set->at(2)) || (data.m_upperQuartile != set->at(3)) || (data.m_upperExtreme != set->at(4))) | |||
|
175 | changed = true; | |||
|
176 | ||||
177 | data.m_lowerExtreme = set->at(0); |
|
177 | data.m_lowerExtreme = set->at(0); | |
178 | data.m_lowerQuartile = set->at(1); |
|
178 | data.m_lowerQuartile = set->at(1); | |
179 | data.m_median = set->at(2); |
|
179 | data.m_median = set->at(2); | |
180 | data.m_upperQuartile = set->at(3); |
|
180 | data.m_upperQuartile = set->at(3); | |
181 | data.m_upperExtreme = set->at(4); |
|
181 | data.m_upperExtreme = set->at(4); | |
182 | data.m_index = index; |
|
182 | data.m_index = index; | |
183 | data.m_boxItems = m_series->count(); |
|
183 | data.m_boxItems = m_series->count(); | |
184 |
|
184 | |||
185 | data.m_maxX = domain()->maxX(); |
|
185 | data.m_maxX = domain()->maxX(); | |
186 | data.m_minX = domain()->minX(); |
|
186 | data.m_minX = domain()->minX(); | |
187 | data.m_maxY = domain()->maxY(); |
|
187 | data.m_maxY = domain()->maxY(); | |
188 | data.m_minY = domain()->minY(); |
|
188 | data.m_minY = domain()->minY(); | |
189 |
|
189 | |||
190 | data.m_seriesIndex = m_seriesIndex; |
|
190 | data.m_seriesIndex = m_seriesIndex; | |
191 | data.m_seriesCount = m_seriesCount; |
|
191 | data.m_seriesCount = m_seriesCount; | |
|
192 | ||||
|
193 | return changed; | |||
192 | } |
|
194 | } | |
193 |
|
195 | |||
194 | #include "moc_boxplotchartitem_p.cpp" |
|
196 | #include "moc_boxplotchartitem_p.cpp" | |
195 |
|
197 | |||
196 | QTCOMMERCIALCHART_END_NAMESPACE |
|
198 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,87 +1,86 | |||||
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 |
|
30 | |||
31 | #ifndef BOXPLOTCHARTITEM_H |
|
31 | #ifndef BOXPLOTCHARTITEM_H | |
32 | #define BOXPLOTCHARTITEM_H |
|
32 | #define BOXPLOTCHARTITEM_H | |
33 |
|
33 | |||
34 | #include "boxwhiskers_p.h" |
|
34 | #include "boxwhiskers_p.h" | |
35 | #include "qboxplotseries.h" |
|
35 | #include "qboxplotseries.h" | |
36 | #include "chartitem_p.h" |
|
36 | #include "chartitem_p.h" | |
37 | #include "boxplotanimation_p.h" |
|
37 | #include "boxplotanimation_p.h" | |
38 | #include <QGraphicsItem> |
|
38 | #include <QGraphicsItem> | |
39 |
|
39 | |||
40 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
40 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
41 |
|
41 | |||
42 | class BoxPlotSeriesPrivate; |
|
42 | class BoxPlotSeriesPrivate; | |
43 |
|
43 | |||
44 | class BoxPlotChartItem : public ChartItem |
|
44 | class BoxPlotChartItem : public ChartItem | |
45 | { |
|
45 | { | |
46 | Q_OBJECT |
|
46 | Q_OBJECT | |
47 | public: |
|
47 | public: | |
48 | BoxPlotChartItem(QBoxPlotSeries *series, QGraphicsItem* item =0); |
|
48 | BoxPlotChartItem(QBoxPlotSeries *series, QGraphicsItem* item =0); | |
49 | ~BoxPlotChartItem(); |
|
49 | ~BoxPlotChartItem(); | |
50 |
|
50 | |||
51 | void setAnimation(BoxPlotAnimation *animation); |
|
51 | void setAnimation(BoxPlotAnimation *animation); | |
52 |
|
52 | |||
53 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); |
|
53 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); | |
54 | QRectF boundingRect() const; |
|
54 | QRectF boundingRect() const; | |
55 |
|
55 | |||
56 | public Q_SLOTS: |
|
56 | public Q_SLOTS: | |
57 | void handleDataStructureChanged(); |
|
57 | void handleDataStructureChanged(); | |
58 | void handleDomainUpdated(); |
|
58 | void handleDomainUpdated(); | |
59 | void handleLayoutChanged(); |
|
59 | void handleLayoutChanged(); | |
60 | void handleUpdatedBars(); |
|
60 | void handleUpdatedBars(); | |
61 | void handleSeriesRemove(QAbstractSeries *series); |
|
|||
62 |
|
61 | |||
63 | private: |
|
62 | private: | |
64 | virtual QVector<QRectF> calculateLayout(); |
|
63 | virtual QVector<QRectF> calculateLayout(); | |
65 | void initializeLayout(); |
|
64 | void initializeLayout(); | |
66 |
|
|
65 | bool updateBoxGeometry(BoxWhiskers *box, int index); | |
67 |
|
66 | |||
68 | protected: |
|
67 | protected: | |
69 | friend class QBoxPlotSeriesPrivate; |
|
68 | friend class QBoxPlotSeriesPrivate; | |
70 | QBoxPlotSeries *m_series; // Not owned. |
|
69 | QBoxPlotSeries *m_series; // Not owned. | |
71 | QList<BoxWhiskers *> m_boxes; |
|
70 | QList<BoxWhiskers *> m_boxes; | |
72 | QHash<QBarSet *, BoxWhiskers *> m_boxTable; |
|
71 | QHash<QBarSet *, BoxWhiskers *> m_boxTable; | |
73 | QList<QBarSet *> m_barSets; |
|
72 | QList<QBarSet *> m_barSets; | |
74 | int m_seriesIndex; |
|
73 | int m_seriesIndex; | |
75 | int m_seriesCount; |
|
74 | int m_seriesCount; | |
76 |
|
75 | |||
77 | BoxPlotAnimation *m_animation; |
|
76 | BoxPlotAnimation *m_animation; | |
78 | bool m_animate; |
|
77 | bool m_animate; | |
79 |
|
78 | |||
80 | QRectF m_boundingRect; |
|
79 | QRectF m_boundingRect; | |
81 |
|
80 | |||
82 | //QList<BoxPlotAnimation *> m_animations; |
|
81 | //QList<BoxPlotAnimation *> m_animations; | |
83 | }; |
|
82 | }; | |
84 |
|
83 | |||
85 | QTCOMMERCIALCHART_END_NAMESPACE |
|
84 | QTCOMMERCIALCHART_END_NAMESPACE | |
86 |
|
85 | |||
87 | #endif // BOXPLOTCHARTITEM_H |
|
86 | #endif // BOXPLOTCHARTITEM_H |
@@ -1,16 +1,18 | |||||
1 | !include( ../tests.pri ) { |
|
1 | !include( ../tests.pri ) { | |
2 | error( "Couldn't find the test.pri file!" ) |
|
2 | error( "Couldn't find the test.pri file!" ) | |
3 | } |
|
3 | } | |
4 |
|
4 | |||
5 | TEMPLATE = app |
|
5 | TEMPLATE = app | |
6 |
|
6 | |||
7 | QT += core gui opengl |
|
7 | QT += core gui opengl | |
8 | contains(QT_MAJOR_VERSION, 5) { |
|
8 | contains(QT_MAJOR_VERSION, 5) { | |
9 | QT += widgets |
|
9 | QT += widgets | |
10 | } |
|
10 | } | |
11 |
|
11 | |||
12 | SOURCES += main.cpp \ |
|
12 | SOURCES += main.cpp \ | |
13 | mainwidget.cpp |
|
13 | mainwidget.cpp \ | |
|
14 | customtablemodel.cpp | |||
14 |
|
15 | |||
15 | HEADERS += \ |
|
16 | HEADERS += \ | |
16 | mainwidget.h |
|
17 | mainwidget.h \ | |
|
18 | customtablemodel.h |
@@ -1,239 +1,283 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2013 Digia Plc |
|
3 | ** Copyright (C) 2013 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 "mainwidget.h" |
|
21 | #include "mainwidget.h" | |
|
22 | #include "customtablemodel.h" | |||
|
23 | #include <QVBarModelMapper> | |||
|
24 | #include <QTableView> | |||
|
25 | #include <QHeaderView> | |||
22 | #include <QChartView> |
|
26 | #include <QChartView> | |
23 | #include <QBoxPlotSeries> |
|
27 | #include <QBoxPlotSeries> | |
24 | #include <QBarSet> |
|
28 | #include <QBarSet> | |
25 | #include <QLegend> |
|
29 | #include <QLegend> | |
26 | #include <QBarCategoryAxis> |
|
30 | #include <QBarCategoryAxis> | |
27 | #include <QBrush> |
|
31 | #include <QBrush> | |
28 | #include <QColor> |
|
32 | #include <QColor> | |
29 | #include <QPushButton> |
|
33 | #include <QPushButton> | |
30 | #include <QComboBox> |
|
34 | #include <QComboBox> | |
31 | #include <QSpinBox> |
|
35 | #include <QSpinBox> | |
32 | #include <QCheckBox> |
|
36 | #include <QCheckBox> | |
33 | #include <QGridLayout> |
|
37 | #include <QGridLayout> | |
34 | #include <QHBoxLayout> |
|
38 | #include <QHBoxLayout> | |
35 | #include <QLabel> |
|
39 | #include <QLabel> | |
36 | #include <QSpacerItem> |
|
40 | #include <QSpacerItem> | |
37 | #include <QMessageBox> |
|
41 | #include <QMessageBox> | |
38 | #include <cmath> |
|
42 | #include <cmath> | |
39 | #include <QDebug> |
|
43 | #include <QDebug> | |
40 | #include <QStandardItemModel> |
|
44 | #include <QStandardItemModel> | |
41 | #include <QBarCategoryAxis> |
|
45 | #include <QBarCategoryAxis> | |
42 |
|
46 | |||
43 |
|
47 | |||
44 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
48 | QTCOMMERCIALCHART_USE_NAMESPACE | |
45 |
|
49 | |||
46 | QString addCategories[] = {"Jul", "Aug", "Sep", "Nov", "Dec"}; |
|
50 | QString addCategories[] = {"Jul", "Aug", "Sep", "Nov", "Dec"}; | |
47 |
|
51 | |||
48 | MainWidget::MainWidget(QWidget *parent) : |
|
52 | MainWidget::MainWidget(QWidget *parent) : | |
49 | QWidget(parent), |
|
53 | QWidget(parent), | |
50 | m_chart(0), |
|
54 | m_chart(0), | |
51 | rowPos(0), |
|
55 | rowPos(0), | |
52 | nSeries(0), |
|
56 | nSeries(0), | |
53 | nNewBoxes(0) |
|
57 | nNewBoxes(0) | |
54 | { |
|
58 | { | |
55 | m_chart = new QChart(); |
|
59 | m_chart = new QChart(); | |
56 |
|
60 | |||
57 | // Grid layout for the controls for configuring the chart widget |
|
61 | // Grid layout for the controls for configuring the chart widget | |
58 | QGridLayout *grid = new QGridLayout(); |
|
62 | QGridLayout *grid = new QGridLayout(); | |
59 |
|
63 | |||
60 | // Create add a series button |
|
64 | // Create add a series button | |
61 | QPushButton *addSeriesButton = new QPushButton("Add a series"); |
|
65 | QPushButton *addSeriesButton = new QPushButton("Add a series"); | |
62 | connect(addSeriesButton, SIGNAL(clicked()), this, SLOT(addSeries())); |
|
66 | connect(addSeriesButton, SIGNAL(clicked()), this, SLOT(addSeries())); | |
63 | grid->addWidget(addSeriesButton, rowPos++, 1); |
|
67 | grid->addWidget(addSeriesButton, rowPos++, 1); | |
64 |
|
68 | |||
65 | // Create remove a series button |
|
69 | // Create remove a series button | |
66 | QPushButton *removeSeriesButton = new QPushButton("Remove a series"); |
|
70 | QPushButton *removeSeriesButton = new QPushButton("Remove a series"); | |
67 | connect(removeSeriesButton, SIGNAL(clicked()), this, SLOT(removeSeries())); |
|
71 | connect(removeSeriesButton, SIGNAL(clicked()), this, SLOT(removeSeries())); | |
68 | grid->addWidget(removeSeriesButton, rowPos++, 1); |
|
72 | grid->addWidget(removeSeriesButton, rowPos++, 1); | |
69 |
|
73 | |||
70 |
|
74 | |||
71 | // Create add a single box button |
|
75 | // Create add a single box button | |
72 | QPushButton *addBoxButton = new QPushButton("Add a box"); |
|
76 | QPushButton *addBoxButton = new QPushButton("Add a box"); | |
73 | connect(addBoxButton, SIGNAL(clicked()), this, SLOT(addBox())); |
|
77 | connect(addBoxButton, SIGNAL(clicked()), this, SLOT(addBox())); | |
74 | grid->addWidget(addBoxButton, rowPos++, 1); |
|
78 | grid->addWidget(addBoxButton, rowPos++, 1); | |
75 |
|
79 | |||
76 | initThemeCombo(grid); |
|
80 | initThemeCombo(grid); | |
77 | initCheckboxes(grid); |
|
81 | initCheckboxes(grid); | |
78 |
|
82 | |||
|
83 | m_model = new CustomTableModel; | |||
|
84 | QTableView *tableView = new QTableView; | |||
|
85 | tableView->setModel(m_model); | |||
|
86 | tableView->setMaximumWidth(200); | |||
|
87 | grid->addWidget(tableView, rowPos++, 0, 3, 2, Qt::AlignLeft); | |||
|
88 | #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)) | |||
|
89 | tableView->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch); | |||
|
90 | tableView->verticalHeader()->setSectionResizeMode(QHeaderView::Stretch); | |||
|
91 | #else | |||
|
92 | tableView->horizontalHeader()->setResizeMode(QHeaderView::Stretch); | |||
|
93 | tableView->verticalHeader()->setResizeMode(QHeaderView::Stretch); | |||
|
94 | #endif | |||
|
95 | ||||
79 | // add row with empty label to make all the other rows static |
|
96 | // add row with empty label to make all the other rows static | |
80 | grid->addWidget(new QLabel(""), grid->rowCount(), 0); |
|
97 | grid->addWidget(new QLabel(""), grid->rowCount(), 0); | |
81 | grid->setRowStretch(grid->rowCount() - 1, 1); |
|
98 | grid->setRowStretch(grid->rowCount() - 1, 1); | |
82 |
|
99 | |||
83 | // Create chart view with the chart |
|
100 | // Create chart view with the chart | |
84 | m_chartView = new QChartView(m_chart, this); |
|
101 | m_chartView = new QChartView(m_chart, this); | |
85 | //m_chartView->setRubberBand(QChartView::HorizonalRubberBand); |
|
102 | //m_chartView->setRubberBand(QChartView::HorizonalRubberBand); | |
86 |
|
103 | |||
87 | // Another grid layout as a main layout |
|
104 | // Another grid layout as a main layout | |
88 | QGridLayout *mainLayout = new QGridLayout(); |
|
105 | QGridLayout *mainLayout = new QGridLayout(); | |
89 | mainLayout->addLayout(grid, 0, 0); |
|
106 | mainLayout->addLayout(grid, 0, 0); | |
90 | mainLayout->addWidget(m_chartView, 0, 1, 3, 1); |
|
107 | mainLayout->addWidget(m_chartView, 0, 1, 3, 1); | |
91 | setLayout(mainLayout); |
|
108 | setLayout(mainLayout); | |
92 |
|
109 | |||
93 | legendToggled(false); |
|
110 | legendToggled(false); | |
94 | animationToggled(false); |
|
111 | animationToggled(false); | |
95 | } |
|
112 | } | |
96 |
|
113 | |||
97 | // Combo box for selecting theme |
|
114 | // Combo box for selecting theme | |
98 | void MainWidget::initThemeCombo(QGridLayout *grid) |
|
115 | void MainWidget::initThemeCombo(QGridLayout *grid) | |
99 | { |
|
116 | { | |
100 | QComboBox *chartTheme = new QComboBox(); |
|
117 | QComboBox *chartTheme = new QComboBox(); | |
101 | chartTheme->addItem("Default"); |
|
118 | chartTheme->addItem("Default"); | |
102 | chartTheme->addItem("Light"); |
|
119 | chartTheme->addItem("Light"); | |
103 | chartTheme->addItem("Blue Cerulean"); |
|
120 | chartTheme->addItem("Blue Cerulean"); | |
104 | chartTheme->addItem("Dark"); |
|
121 | chartTheme->addItem("Dark"); | |
105 | chartTheme->addItem("Brown Sand"); |
|
122 | chartTheme->addItem("Brown Sand"); | |
106 | chartTheme->addItem("Blue NCS"); |
|
123 | chartTheme->addItem("Blue NCS"); | |
107 | chartTheme->addItem("High Contrast"); |
|
124 | chartTheme->addItem("High Contrast"); | |
108 | chartTheme->addItem("Blue Icy"); |
|
125 | chartTheme->addItem("Blue Icy"); | |
109 | connect(chartTheme, SIGNAL(currentIndexChanged(int)), |
|
126 | connect(chartTheme, SIGNAL(currentIndexChanged(int)), | |
110 | this, SLOT(changeChartTheme(int))); |
|
127 | this, SLOT(changeChartTheme(int))); | |
111 | grid->addWidget(new QLabel("Chart theme:"), rowPos, 0); |
|
128 | grid->addWidget(new QLabel("Chart theme:"), rowPos, 0); | |
112 | grid->addWidget(chartTheme, rowPos++, 1); |
|
129 | grid->addWidget(chartTheme, rowPos++, 1); | |
113 | } |
|
130 | } | |
114 |
|
131 | |||
115 | // Different check boxes for customizing chart |
|
132 | // Different check boxes for customizing chart | |
116 | void MainWidget::initCheckboxes(QGridLayout *grid) |
|
133 | void MainWidget::initCheckboxes(QGridLayout *grid) | |
117 | { |
|
134 | { | |
118 | QCheckBox *animationCheckBox = new QCheckBox("Animation"); |
|
135 | QCheckBox *animationCheckBox = new QCheckBox("Animation"); | |
119 | connect(animationCheckBox, SIGNAL(toggled(bool)), this, SLOT(animationToggled(bool))); |
|
136 | connect(animationCheckBox, SIGNAL(toggled(bool)), this, SLOT(animationToggled(bool))); | |
120 | animationCheckBox->setChecked(false); |
|
137 | animationCheckBox->setChecked(false); | |
121 | grid->addWidget(animationCheckBox, rowPos++, 0); |
|
138 | grid->addWidget(animationCheckBox, rowPos++, 0); | |
122 |
|
139 | |||
123 | QCheckBox *legendCheckBox = new QCheckBox("Legend"); |
|
140 | QCheckBox *legendCheckBox = new QCheckBox("Legend"); | |
124 | connect(legendCheckBox, SIGNAL(toggled(bool)), this, SLOT(legendToggled(bool))); |
|
141 | connect(legendCheckBox, SIGNAL(toggled(bool)), this, SLOT(legendToggled(bool))); | |
125 | legendCheckBox->setChecked(false); |
|
142 | legendCheckBox->setChecked(false); | |
126 | grid->addWidget(legendCheckBox, rowPos++, 0); |
|
143 | grid->addWidget(legendCheckBox, rowPos++, 0); | |
127 |
|
144 | |||
128 | QCheckBox *titleCheckBox = new QCheckBox("Title"); |
|
145 | QCheckBox *titleCheckBox = new QCheckBox("Title"); | |
129 | connect(titleCheckBox, SIGNAL(toggled(bool)), this, SLOT(titleToggled(bool))); |
|
146 | connect(titleCheckBox, SIGNAL(toggled(bool)), this, SLOT(titleToggled(bool))); | |
130 | titleCheckBox->setChecked(false); |
|
147 | titleCheckBox->setChecked(false); | |
131 | grid->addWidget(titleCheckBox, rowPos++, 0); |
|
148 | grid->addWidget(titleCheckBox, rowPos++, 0); | |
|
149 | ||||
|
150 | QCheckBox *modelMapperCheckBox = new QCheckBox("Use model mapper"); | |||
|
151 | connect(modelMapperCheckBox, SIGNAL(toggled(bool)), this, SLOT(modelMapperToggled(bool))); | |||
|
152 | modelMapperCheckBox->setChecked(false); | |||
|
153 | grid->addWidget(modelMapperCheckBox, rowPos++, 0); | |||
|
154 | ||||
132 | } |
|
155 | } | |
133 |
|
156 | |||
134 | void MainWidget::addSeries() |
|
157 | void MainWidget::addSeries() | |
135 | { |
|
158 | { | |
136 | qDebug() << "BoxPlotTester::MainWidget::addSeries()"; |
|
159 | qDebug() << "BoxPlotTester::MainWidget::addSeries()"; | |
137 |
|
160 | |||
138 | if (nSeries > 9) |
|
161 | if (nSeries > 9) | |
139 | return; |
|
162 | return; | |
140 |
|
163 | |||
141 | // Initial data |
|
164 | // Initial data | |
142 | //![1] |
|
165 | //![1] | |
143 | QBarSet *set0 = new QBarSet("Jan"); |
|
166 | QBarSet *set0 = new QBarSet("Jan"); | |
144 | QBarSet *set1 = new QBarSet("Feb"); |
|
167 | QBarSet *set1 = new QBarSet("Feb"); | |
145 | QBarSet *set2 = new QBarSet("Mar"); |
|
168 | QBarSet *set2 = new QBarSet("Mar"); | |
146 | QBarSet *set3 = new QBarSet("Apr"); |
|
169 | QBarSet *set3 = new QBarSet("Apr"); | |
147 | QBarSet *set4 = new QBarSet("May"); |
|
170 | QBarSet *set4 = new QBarSet("May"); | |
148 | QBarSet *set5 = new QBarSet("Jun"); |
|
171 | QBarSet *set5 = new QBarSet("Jun"); | |
149 |
|
172 | |||
150 | // low bot med top upp |
|
173 | // low bot med top upp | |
151 | *set0 << 3 << 4 << 4.4 << 6 << 7; |
|
174 | *set0 << 3 << 4 << 4.4 << 6 << 7; | |
152 | *set1 << 5 << 6 << 7.5 << 8 << 12; |
|
175 | *set1 << 5 << 6 << 7.5 << 8 << 12; | |
153 | *set2 << 3 << 5 << 5.7 << 8 << 9; |
|
176 | *set2 << 3 << 5 << 5.7 << 8 << 9; | |
154 | *set3 << 5 << 6 << 6.8 << 7 << 8; |
|
177 | *set3 << 5 << 6 << 6.8 << 7 << 8; | |
155 | *set4 << 4 << 5 << 5.2 << 6 << 7; |
|
178 | *set4 << 4 << 5 << 5.2 << 6 << 7; | |
156 | *set5 << 4 << 7 << 8.2 << 9 << 10; |
|
179 | *set5 << 4 << 7 << 8.2 << 9 << 10; | |
157 |
|
180 | |||
158 | m_series[nSeries] = new QBoxPlotSeries(); |
|
181 | m_series[nSeries] = new QBoxPlotSeries(); | |
159 | m_series[nSeries]->append(set0); |
|
182 | m_series[nSeries]->append(set0); | |
160 | m_series[nSeries]->append(set1); |
|
183 | m_series[nSeries]->append(set1); | |
161 | m_series[nSeries]->append(set2); |
|
184 | m_series[nSeries]->append(set2); | |
162 | m_series[nSeries]->append(set3); |
|
185 | m_series[nSeries]->append(set3); | |
163 | m_series[nSeries]->append(set4); |
|
186 | m_series[nSeries]->append(set4); | |
164 | m_series[nSeries]->append(set5); |
|
187 | m_series[nSeries]->append(set5); | |
165 | m_series[nSeries]->type(); |
|
188 | m_series[nSeries]->type(); | |
166 | m_series[nSeries]->setName("Box & Whiskers"); |
|
189 | m_series[nSeries]->setName("Box & Whiskers"); | |
167 |
|
190 | |||
168 | m_chart->addSeries(m_series[nSeries]); |
|
191 | m_chart->addSeries(m_series[nSeries]); | |
169 |
|
192 | |||
170 | if (nSeries == 0) { |
|
193 | if (nSeries == 0) { | |
171 | QStringList categories; |
|
194 | QStringList categories; | |
172 | categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun"; |
|
195 | categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun"; | |
173 | m_axis = new QBarCategoryAxis(); |
|
196 | m_axis = new QBarCategoryAxis(); | |
174 | m_axis->append(categories); |
|
197 | m_axis->append(categories); | |
175 | m_chart->createDefaultAxes(); |
|
198 | m_chart->createDefaultAxes(); | |
176 | m_chart->setAxisX(m_axis, m_series[nSeries]); |
|
199 | m_chart->setAxisX(m_axis, m_series[nSeries]); | |
177 | } |
|
200 | } | |
178 |
|
201 | |||
179 | nSeries++; |
|
202 | nSeries++; | |
180 | } |
|
203 | } | |
181 |
|
204 | |||
182 | void MainWidget::removeSeries() |
|
205 | void MainWidget::removeSeries() | |
183 | { |
|
206 | { | |
184 | if (nSeries > 0) { |
|
207 | if (nSeries > 0) { | |
185 | nSeries--; |
|
208 | nSeries--; | |
186 | m_chart->removeSeries(m_series[nSeries]); |
|
209 | m_chart->removeSeries(m_series[nSeries]); | |
187 | delete m_series[nSeries]; |
|
210 | delete m_series[nSeries]; | |
188 | } |
|
211 | } | |
189 | } |
|
212 | } | |
190 |
|
213 | |||
191 | void MainWidget::addBox() |
|
214 | void MainWidget::addBox() | |
192 | { |
|
215 | { | |
193 | qDebug() << "BoxPlotTester::MainWidget::addBox()"; |
|
216 | qDebug() << "BoxPlotTester::MainWidget::addBox()"; | |
194 |
|
217 | |||
195 | QBarSet *newSet = new QBarSet("New"); |
|
218 | QBarSet *newSet = new QBarSet("New"); | |
196 | *newSet << 5 << 6 << 6.8 << 7 << 8; |
|
219 | *newSet << 5 << 6 << 6.8 << 7 << 8; | |
197 |
|
220 | |||
198 | m_series[0]->append(newSet); |
|
221 | m_series[0]->append(newSet); | |
199 |
|
222 | |||
200 | m_axis->append(addCategories[nNewBoxes]); |
|
223 | m_axis->append(addCategories[nNewBoxes]); | |
201 |
|
224 | |||
202 | nNewBoxes++; |
|
225 | nNewBoxes++; | |
203 | } |
|
226 | } | |
204 |
|
227 | |||
205 | void MainWidget::animationToggled(bool enabled) |
|
228 | void MainWidget::animationToggled(bool enabled) | |
206 | { |
|
229 | { | |
207 | qDebug() << "BoxPlotTester::Animation toggled to " << enabled; |
|
230 | qDebug() << "BoxPlotTester::Animation toggled to " << enabled; | |
208 | if (enabled) |
|
231 | if (enabled) | |
209 | m_chart->setAnimationOptions(QChart::SeriesAnimations); |
|
232 | m_chart->setAnimationOptions(QChart::SeriesAnimations); | |
210 | else |
|
233 | else | |
211 | m_chart->setAnimationOptions(QChart::NoAnimation); |
|
234 | m_chart->setAnimationOptions(QChart::NoAnimation); | |
212 | } |
|
235 | } | |
213 |
|
236 | |||
214 | void MainWidget::legendToggled(bool enabled) |
|
237 | void MainWidget::legendToggled(bool enabled) | |
215 | { |
|
238 | { | |
216 | qDebug() << "BoxPlotTester::Legend toggled to " << enabled; |
|
239 | qDebug() << "BoxPlotTester::Legend toggled to " << enabled; | |
217 | m_chart->legend()->setVisible(enabled); |
|
240 | m_chart->legend()->setVisible(enabled); | |
218 | if (enabled) |
|
241 | if (enabled) | |
219 | m_chart->legend()->setAlignment(Qt::AlignBottom); |
|
242 | m_chart->legend()->setAlignment(Qt::AlignBottom); | |
220 | } |
|
243 | } | |
221 |
|
244 | |||
222 | void MainWidget::titleToggled(bool enabled) |
|
245 | void MainWidget::titleToggled(bool enabled) | |
223 | { |
|
246 | { | |
224 | qDebug() << "BoxPlotTester::Title toggled to " << enabled; |
|
247 | qDebug() << "BoxPlotTester::Title toggled to " << enabled; | |
225 | if (enabled) |
|
248 | if (enabled) | |
226 | m_chart->setTitle("Simple boxplotchart example"); |
|
249 | m_chart->setTitle("Simple boxplotchart example"); | |
227 | else |
|
250 | else | |
228 | m_chart->setTitle(""); |
|
251 | m_chart->setTitle(""); | |
229 | } |
|
252 | } | |
230 |
|
253 | |||
|
254 | void MainWidget::modelMapperToggled(bool enabled) | |||
|
255 | { | |||
|
256 | if (enabled) { | |||
|
257 | m_series[nSeries] = new QBoxPlotSeries(); | |||
|
258 | ||||
|
259 | int first = 0; | |||
|
260 | int count = 5; | |||
|
261 | QVBarModelMapper *mapper = new QVBarModelMapper(this); | |||
|
262 | mapper->setFirstBarSetColumn(0); | |||
|
263 | mapper->setLastBarSetColumn(5); | |||
|
264 | mapper->setFirstRow(first); | |||
|
265 | mapper->setRowCount(count); | |||
|
266 | mapper->setSeries(m_series[nSeries]); | |||
|
267 | mapper->setModel(m_model); | |||
|
268 | m_chart->addSeries(m_series[nSeries]); | |||
|
269 | ||||
|
270 | nSeries++; | |||
|
271 | } else { | |||
|
272 | removeSeries(); | |||
|
273 | } | |||
|
274 | } | |||
231 |
|
275 | |||
232 | void MainWidget::changeChartTheme(int themeIndex) |
|
276 | void MainWidget::changeChartTheme(int themeIndex) | |
233 | { |
|
277 | { | |
234 | qDebug() << "BoxPlotTester::changeChartTheme: " << themeIndex; |
|
278 | qDebug() << "BoxPlotTester::changeChartTheme: " << themeIndex; | |
235 | if (themeIndex == 0) |
|
279 | if (themeIndex == 0) | |
236 | m_chart->setTheme(QChart::ChartThemeLight); |
|
280 | m_chart->setTheme(QChart::ChartThemeLight); | |
237 | else |
|
281 | else | |
238 | m_chart->setTheme((QChart::ChartTheme) (themeIndex - 1)); |
|
282 | m_chart->setTheme((QChart::ChartTheme) (themeIndex - 1)); | |
239 | } |
|
283 | } |
@@ -1,67 +1,70 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2013 Digia Plc |
|
3 | ** Copyright (C) 2013 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 MAINWIDGET_H |
|
21 | #ifndef MAINWIDGET_H | |
22 | #define MAINWIDGET_H |
|
22 | #define MAINWIDGET_H | |
23 |
|
23 | |||
24 | #include "qchartglobal.h" |
|
24 | #include "qchartglobal.h" | |
25 | #include "qchart.h" |
|
25 | #include "qchart.h" | |
26 | #include "qchartview.h" |
|
26 | #include "qchartview.h" | |
|
27 | #include "customtablemodel.h" | |||
27 | #include <QWidget> |
|
28 | #include <QWidget> | |
28 | #include <QBoxPlotSeries> |
|
29 | #include <QBoxPlotSeries> | |
29 | #include <QBarCategoryAxis> |
|
30 | #include <QBarCategoryAxis> | |
30 |
|
31 | |||
31 | class QGridLayout; |
|
32 | class QGridLayout; | |
32 |
|
33 | |||
33 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
34 | QTCOMMERCIALCHART_USE_NAMESPACE | |
34 |
|
35 | |||
35 | class MainWidget : public QWidget |
|
36 | class MainWidget : public QWidget | |
36 | { |
|
37 | { | |
37 | Q_OBJECT |
|
38 | Q_OBJECT | |
38 | public: |
|
39 | public: | |
39 | explicit MainWidget(QWidget *parent = 0); |
|
40 | explicit MainWidget(QWidget *parent = 0); | |
40 |
|
41 | |||
41 | signals: |
|
42 | signals: | |
42 |
|
43 | |||
43 | private: |
|
44 | private: | |
44 | void initThemeCombo(QGridLayout *grid); |
|
45 | void initThemeCombo(QGridLayout *grid); | |
45 | void initCheckboxes(QGridLayout *grid); |
|
46 | void initCheckboxes(QGridLayout *grid); | |
46 |
|
47 | |||
47 | private slots: |
|
48 | private slots: | |
48 | void addSeries(); |
|
49 | void addSeries(); | |
49 | void removeSeries(); |
|
50 | void removeSeries(); | |
50 | void addBox(); |
|
51 | void addBox(); | |
51 | void animationToggled(bool enabled); |
|
52 | void animationToggled(bool enabled); | |
52 | void legendToggled(bool enabled); |
|
53 | void legendToggled(bool enabled); | |
53 | void titleToggled(bool enabled); |
|
54 | void titleToggled(bool enabled); | |
|
55 | void modelMapperToggled(bool enabled); | |||
54 | void changeChartTheme(int themeIndex); |
|
56 | void changeChartTheme(int themeIndex); | |
55 |
|
57 | |||
56 | private: |
|
58 | private: | |
57 | QChart *m_chart; |
|
59 | QChart *m_chart; | |
58 | QChartView *m_chartView; |
|
60 | QChartView *m_chartView; | |
59 | QGridLayout *m_scatterLayout; |
|
61 | QGridLayout *m_scatterLayout; | |
60 | QBarCategoryAxis *m_axis; |
|
62 | QBarCategoryAxis *m_axis; | |
|
63 | CustomTableModel *m_model; | |||
61 | int rowPos; |
|
64 | int rowPos; | |
62 | int nSeries; |
|
65 | int nSeries; | |
63 | int nNewBoxes; |
|
66 | int nNewBoxes; | |
64 | QBoxPlotSeries *m_series[10]; |
|
67 | QBoxPlotSeries *m_series[10]; | |
65 | }; |
|
68 | }; | |
66 |
|
69 | |||
67 | #endif // MAINWIDGET_H |
|
70 | #endif // MAINWIDGET_H |
General Comments 0
You need to be logged in to leave comments.
Login now