@@ -0,0 +1,6 | |||
|
1 | !include( ../examples.pri ) { | |
|
2 | error( "Couldn't find the examples.pri file!" ) | |
|
3 | } | |
|
4 | ||
|
5 | TARGET = horizontalbarchart | |
|
6 | SOURCES += main.cpp |
@@ -0,0 +1,94 | |||
|
1 | /**************************************************************************** | |
|
2 | ** | |
|
3 | ** Copyright (C) 2012 Digia Plc | |
|
4 | ** All rights reserved. | |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
|
6 | ** | |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
|
8 | ** | |
|
9 | ** $QT_BEGIN_LICENSE$ | |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
|
13 | ** a written agreement between you and Digia. | |
|
14 | ** | |
|
15 | ** If you have questions regarding the use of this file, please use | |
|
16 | ** contact form at http://qt.digia.com | |
|
17 | ** $QT_END_LICENSE$ | |
|
18 | ** | |
|
19 | ****************************************************************************/ | |
|
20 | ||
|
21 | #include <QApplication> | |
|
22 | #include <QMainWindow> | |
|
23 | #include <QChartView> | |
|
24 | #include <QBarSeries> | |
|
25 | #include <QBarSet> | |
|
26 | #include <QLegend> | |
|
27 | #include <QBarCategoriesAxis> | |
|
28 | #include <QHorizontalBarSeries> | |
|
29 | ||
|
30 | QTCOMMERCIALCHART_USE_NAMESPACE | |
|
31 | ||
|
32 | int main(int argc, char *argv[]) | |
|
33 | { | |
|
34 | QApplication a(argc, argv); | |
|
35 | ||
|
36 | //![1] | |
|
37 | QBarSet *set0 = new QBarSet("Jane"); | |
|
38 | QBarSet *set1 = new QBarSet("John"); | |
|
39 | QBarSet *set2 = new QBarSet("Axel"); | |
|
40 | QBarSet *set3 = new QBarSet("Mary"); | |
|
41 | QBarSet *set4 = new QBarSet("Samantha"); | |
|
42 | ||
|
43 | *set0 << 1 << 2 << 3 << 4 << 5 << 6; | |
|
44 | *set1 << 5 << 0 << 0 << 4 << 0 << 7; | |
|
45 | *set2 << 3 << 5 << 8 << 13 << 8 << 5; | |
|
46 | *set3 << 5 << 6 << 7 << 3 << 4 << 5; | |
|
47 | *set4 << 9 << 7 << 5 << 3 << 1 << 2; | |
|
48 | //![1] | |
|
49 | ||
|
50 | //![2] | |
|
51 | QHorizontalBarSeries *series = new QHorizontalBarSeries(); | |
|
52 | series->append(set0); | |
|
53 | series->append(set1); | |
|
54 | series->append(set2); | |
|
55 | series->append(set3); | |
|
56 | series->append(set4); | |
|
57 | ||
|
58 | //![2] | |
|
59 | ||
|
60 | //![3] | |
|
61 | QChart* chart = new QChart(); | |
|
62 | chart->addSeries(series); | |
|
63 | chart->setTitle("Simple horizontal barchart example"); | |
|
64 | chart->createDefaultAxes(); | |
|
65 | //![3] | |
|
66 | ||
|
67 | //![4] | |
|
68 | QStringList categories; | |
|
69 | categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun"; | |
|
70 | QBarCategoriesAxis* axis = new QBarCategoriesAxis(); | |
|
71 | axis->append(categories); | |
|
72 | chart->createDefaultAxes(); | |
|
73 | chart->setAxisY(axis,series); | |
|
74 | //![4] | |
|
75 | ||
|
76 | //![5] | |
|
77 | chart->legend()->setVisible(true); | |
|
78 | chart->legend()->setAlignment(Qt::AlignBottom); | |
|
79 | //![5] | |
|
80 | ||
|
81 | //![6] | |
|
82 | QChartView* chartView = new QChartView(chart); | |
|
83 | chartView->setRenderHint(QPainter::Antialiasing); | |
|
84 | //![6] | |
|
85 | ||
|
86 | //![7] | |
|
87 | QMainWindow window; | |
|
88 | window.setCentralWidget(chartView); | |
|
89 | window.resize(400, 300); | |
|
90 | window.show(); | |
|
91 | //![7] | |
|
92 | ||
|
93 | return a.exec(); | |
|
94 | } |
@@ -0,0 +1,51 | |||
|
1 | /**************************************************************************** | |
|
2 | ** | |
|
3 | ** Copyright (C) 2012 Digia Plc | |
|
4 | ** All rights reserved. | |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
|
6 | ** | |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
|
8 | ** | |
|
9 | ** $QT_BEGIN_LICENSE$ | |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
|
13 | ** a written agreement between you and Digia. | |
|
14 | ** | |
|
15 | ** If you have questions regarding the use of this file, please use | |
|
16 | ** contact form at http://qt.digia.com | |
|
17 | ** $QT_END_LICENSE$ | |
|
18 | ** | |
|
19 | ****************************************************************************/ | |
|
20 | ||
|
21 | #include "horizontalbaranimation_p.h" | |
|
22 | #include "abstractbarchartitem_p.h" | |
|
23 | #include <QTimer> | |
|
24 | ||
|
25 | Q_DECLARE_METATYPE(QVector<QRectF>) | |
|
26 | ||
|
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
|
28 | ||
|
29 | HorizontalBarAnimation::HorizontalBarAnimation(AbstractBarChartItem *item) : | |
|
30 | AbstractBarAnimation(item) | |
|
31 | { | |
|
32 | } | |
|
33 | ||
|
34 | HorizontalBarAnimation::~HorizontalBarAnimation() | |
|
35 | { | |
|
36 | ||
|
37 | } | |
|
38 | ||
|
39 | ||
|
40 | QVariant HorizontalBarAnimation::interpolated(const QVariant &from, const QVariant &to, qreal progress) const | |
|
41 | { | |
|
42 | // TODO: | |
|
43 | Q_UNUSED(from); | |
|
44 | Q_UNUSED(to); | |
|
45 | Q_UNUSED(progress); | |
|
46 | return to; | |
|
47 | } | |
|
48 | ||
|
49 | #include "moc_horizontalbaranimation_p.cpp" | |
|
50 | ||
|
51 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -0,0 +1,52 | |||
|
1 | /**************************************************************************** | |
|
2 | ** | |
|
3 | ** Copyright (C) 2012 Digia Plc | |
|
4 | ** All rights reserved. | |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
|
6 | ** | |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
|
8 | ** | |
|
9 | ** $QT_BEGIN_LICENSE$ | |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
|
13 | ** a written agreement between you and Digia. | |
|
14 | ** | |
|
15 | ** If you have questions regarding the use of this file, please use | |
|
16 | ** contact form at http://qt.digia.com | |
|
17 | ** $QT_END_LICENSE$ | |
|
18 | ** | |
|
19 | ****************************************************************************/ | |
|
20 | ||
|
21 | // W A R N I N G | |
|
22 | // ------------- | |
|
23 | // | |
|
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an | |
|
25 | // implementation detail. This header file may change from version to | |
|
26 | // version without notice, or even be removed. | |
|
27 | // | |
|
28 | // We mean it. | |
|
29 | ||
|
30 | #ifndef HORIZONTALBARANIMATION_P_H | |
|
31 | #define HORIZONTALBARANIMATION_P_H | |
|
32 | ||
|
33 | #include "abstractbaranimation_p.h" | |
|
34 | #include "chartanimation_p.h" | |
|
35 | #include "abstractbarchartitem_p.h" | |
|
36 | ||
|
37 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
|
38 | ||
|
39 | class HorizontalBarAnimation : public AbstractBarAnimation | |
|
40 | { | |
|
41 | Q_OBJECT | |
|
42 | public: | |
|
43 | explicit HorizontalBarAnimation(AbstractBarChartItem *item); | |
|
44 | ~HorizontalBarAnimation(); | |
|
45 | ||
|
46 | virtual QVariant interpolated(const QVariant &from, const QVariant &to, qreal progress) const; | |
|
47 | ||
|
48 | }; | |
|
49 | ||
|
50 | QTCOMMERCIALCHART_END_NAMESPACE | |
|
51 | ||
|
52 | #endif // HORIZONTALBARANIMATION_P_H |
@@ -1,26 +1,27 | |||
|
1 | 1 | CURRENTLY_BUILDING_COMPONENTS = "examples" |
|
2 | 2 | !include( ../config.pri ) { |
|
3 | 3 | error( "Couldn't find the config.pri file!" ) |
|
4 | 4 | } |
|
5 | 5 | |
|
6 | 6 | TEMPLATE = subdirs |
|
7 | 7 | SUBDIRS += \ |
|
8 | 8 | areachart \ |
|
9 | 9 | customchart \ |
|
10 | 10 | linechart \ |
|
11 | 11 | percentbarchart \ |
|
12 | 12 | piechart \ |
|
13 | 13 | piechartdrilldown \ |
|
14 | 14 | presenterchart \ |
|
15 | 15 | scatterchart \ |
|
16 | 16 | scatterinteractions \ |
|
17 | 17 | splinechart \ |
|
18 | 18 | stackedbarchart \ |
|
19 | 19 | stackedbarchartdrilldown \ |
|
20 | 20 | zoomlinechart \ |
|
21 | 21 | modeldata \ |
|
22 | 22 | barchart \ |
|
23 | 23 | legend \ |
|
24 | 24 | barmodelmapper \ |
|
25 | 25 | qmlpiechart \ |
|
26 | lineandbar | |
|
26 | lineandbar \ | |
|
27 | horizontalbarchart |
@@ -1,28 +1,30 | |||
|
1 | 1 | INCLUDEPATH += $$PWD |
|
2 | 2 | DEPENDPATH += $$PWD |
|
3 | 3 | |
|
4 | 4 | SOURCES += \ |
|
5 | 5 | $$PWD/axisanimation.cpp \ |
|
6 | 6 | $$PWD/chartanimator.cpp \ |
|
7 | 7 | $$PWD/xyanimation.cpp \ |
|
8 | 8 | $$PWD/pieanimation.cpp \ |
|
9 | 9 | $$PWD/piesliceanimation.cpp \ |
|
10 | 10 | $$PWD/splineanimation.cpp \ |
|
11 | 11 | $$PWD/baranimation.cpp \ |
|
12 | 12 | $$PWD/stackedbaranimation.cpp \ |
|
13 | 13 | $$PWD/percentbaranimation.cpp \ |
|
14 | $$PWD/abstractbaranimation.cpp | |
|
14 | $$PWD/abstractbaranimation.cpp \ | |
|
15 | $$PWD/horizontalbaranimation.cpp | |
|
15 | 16 | |
|
16 | 17 | |
|
17 | 18 | PRIVATE_HEADERS += \ |
|
18 | 19 | $$PWD/axisanimation_p.h \ |
|
19 | 20 | $$PWD/chartanimator_p.h \ |
|
20 | 21 | $$PWD/chartanimation_p.h \ |
|
21 | 22 | $$PWD/xyanimation_p.h \ |
|
22 | 23 | $$PWD/pieanimation_p.h \ |
|
23 | 24 | $$PWD/piesliceanimation_p.h \ |
|
24 | 25 | $$PWD/splineanimation_p.h \ |
|
25 | 26 | $$PWD/baranimation_p.h \ |
|
26 | 27 | $$PWD/stackedbaranimation_p.h \ |
|
27 | 28 | $$PWD/percentbaranimation_p.h \ |
|
28 | $$PWD/abstractbaranimation_p.h | |
|
29 | $$PWD/abstractbaranimation_p.h \ | |
|
30 | $$PWD/horizontalbaranimation_p.h |
@@ -1,96 +1,96 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #include "barchartitem_p.h" |
|
22 | 22 | #include "bar_p.h" |
|
23 | 23 | #include "qbarset_p.h" |
|
24 | 24 | #include "qabstractbarseries_p.h" |
|
25 | 25 | #include "qbarset.h" |
|
26 | 26 | #include "qbarset_p.h" |
|
27 | 27 | |
|
28 | 28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
29 | 29 | |
|
30 | 30 | BarChartItem::BarChartItem(QAbstractBarSeries *series, ChartPresenter *presenter) : |
|
31 | 31 | AbstractBarChartItem(series, presenter) |
|
32 | 32 | { |
|
33 | 33 | } |
|
34 | 34 | |
|
35 | 35 | QVector<QRectF> BarChartItem::calculateLayout() |
|
36 | 36 | { |
|
37 | 37 | QVector<QRectF> layout; |
|
38 | 38 | |
|
39 | 39 | // Use temporary qreals for accuracy |
|
40 | 40 | qreal categoryCount = m_series->d_func()->categoryCount(); |
|
41 | 41 | qreal setCount = m_series->count(); |
|
42 | 42 | bool barsVisible = m_series->isVisible(); |
|
43 | 43 | |
|
44 | 44 | // Domain: |
|
45 | 45 | qreal width = geometry().width(); |
|
46 | 46 | qreal height = geometry().height(); |
|
47 | 47 | qreal rangeY = m_domainMaxY - m_domainMinY; |
|
48 | 48 | qreal rangeX = m_domainMaxX - m_domainMinX; |
|
49 | 49 | qreal scaleY = (height / rangeY); |
|
50 | 50 | qreal scaleX = (width / rangeX); |
|
51 | 51 | qreal barWidth = (scaleX / setCount) * m_series->d_func()->barWidth(); |
|
52 | 52 | |
|
53 | 53 | int itemIndex(0); |
|
54 | 54 | for (int category = 0; category < categoryCount; category++) { |
|
55 | 55 | qreal yPos = height + scaleY * m_domainMinY + geometry().topLeft().y(); |
|
56 | 56 | for (int set = 0; set < setCount; set++) { |
|
57 | 57 | QBarSetPrivate* barSet = m_series->d_func()->barsetAt(set)->d_ptr.data(); |
|
58 | 58 | |
|
59 |
qreal xPos = (barSet-> |
|
|
59 | qreal xPos = (barSet->pos(category) - m_domainMinX) * scaleX + m_rect.left(); | |
|
60 | 60 | xPos -= setCount*barWidth/2; |
|
61 | 61 | xPos += set*barWidth; |
|
62 |
qreal barHeight = barSet-> |
|
|
62 | qreal barHeight = barSet->value(category) * scaleY; | |
|
63 | 63 | Bar* bar = m_bars.at(itemIndex); |
|
64 | 64 | |
|
65 | 65 | QRectF rect(xPos, yPos - barHeight, barWidth, barHeight); |
|
66 | 66 | layout.append(rect); |
|
67 | 67 | bar->setPen(barSet->m_pen); |
|
68 | 68 | bar->setBrush(barSet->m_brush); |
|
69 | 69 | if (qFuzzyIsNull(barHeight)) { |
|
70 | 70 | bar->setVisible(false); |
|
71 | 71 | } else { |
|
72 | 72 | bar->setVisible(barsVisible); |
|
73 | 73 | } |
|
74 | 74 | |
|
75 | 75 | QGraphicsSimpleTextItem* label = m_labels.at(itemIndex); |
|
76 | 76 | |
|
77 |
if (!qFuzzyIsNull(barSet-> |
|
|
78 |
label->setText(QString::number(barSet-> |
|
|
77 | if (!qFuzzyIsNull(barSet->value(category))) { | |
|
78 | label->setText(QString::number(barSet->value(category))); | |
|
79 | 79 | } else { |
|
80 | 80 | label->setText(QString("")); |
|
81 | 81 | } |
|
82 | 82 | |
|
83 | 83 | label->setPos(xPos + (rect.width()/2 - label->boundingRect().width()/2) |
|
84 | 84 | ,yPos - barHeight/2 - label->boundingRect().height()/2); |
|
85 | 85 | label->setFont(barSet->m_labelFont); |
|
86 | 86 | label->setBrush(barSet->m_labelBrush); |
|
87 | 87 | |
|
88 | 88 | itemIndex++; |
|
89 | 89 | } |
|
90 | 90 | } |
|
91 | 91 | return layout; |
|
92 | 92 | } |
|
93 | 93 | |
|
94 | 94 | #include "moc_barchartitem_p.cpp" |
|
95 | 95 | |
|
96 | 96 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,19 +1,96 | |||
|
1 | /**************************************************************************** | |
|
2 | ** | |
|
3 | ** Copyright (C) 2012 Digia Plc | |
|
4 | ** All rights reserved. | |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
|
6 | ** | |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
|
8 | ** | |
|
9 | ** $QT_BEGIN_LICENSE$ | |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
|
13 | ** a written agreement between you and Digia. | |
|
14 | ** | |
|
15 | ** If you have questions regarding the use of this file, please use | |
|
16 | ** contact form at http://qt.digia.com | |
|
17 | ** $QT_END_LICENSE$ | |
|
18 | ** | |
|
19 | ****************************************************************************/ | |
|
20 | ||
|
1 | 21 | #include "horizontalbarchartitem_p.h" |
|
22 | #include "qabstractbarseries_p.h" | |
|
23 | #include "qbarset_p.h" | |
|
24 | #include "bar_p.h" | |
|
25 | #include <QDebug> | |
|
2 | 26 | |
|
3 | 27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
4 | 28 | |
|
5 |
HorizontalBarChart |
|
|
29 | HorizontalBarChartItem::HorizontalBarChartItem(QAbstractBarSeries *series, ChartPresenter *presenter) : | |
|
6 | 30 | AbstractBarChartItem(series, presenter) |
|
7 | 31 | { |
|
8 | 32 | } |
|
9 | 33 | |
|
10 |
QVector<QRectF> HorizontalBarChart |
|
|
34 | QVector<QRectF> HorizontalBarChartItem::calculateLayout() | |
|
11 | 35 | { |
|
12 | // TODO: | |
|
13 | 36 | QVector<QRectF> layout; |
|
37 | ||
|
38 | // Use temporary qreals for accuracy | |
|
39 | qreal categoryCount = m_series->d_func()->categoryCount(); | |
|
40 | qreal setCount = m_series->count(); | |
|
41 | bool barsVisible = m_series->isVisible(); | |
|
42 | ||
|
43 | // Domain: | |
|
44 | qreal width = geometry().width(); | |
|
45 | qreal height = geometry().height(); | |
|
46 | qreal rangeY = m_domainMaxY - m_domainMinY; | |
|
47 | qreal rangeX = m_domainMaxX - m_domainMinX; | |
|
48 | qreal scaleY = (height / rangeY); | |
|
49 | qreal scaleX = (width / rangeX); | |
|
50 | qreal barHeight = (scaleY / setCount) * m_series->d_func()->barWidth(); // On horizontal chart barWidth of the barseries means height of the rect. | |
|
51 | ||
|
52 | int itemIndex(0); | |
|
53 | for (int category = 0; category < categoryCount; category++) { | |
|
54 | qreal xPos = scaleX * m_domainMinX + geometry().left(); | |
|
55 | for (int set = 0; set < setCount; set++) { | |
|
56 | QBarSetPrivate* barSet = m_series->d_func()->barsetAt(set)->d_ptr.data(); | |
|
57 | ||
|
58 | qreal yPos = m_rect.bottom() -(barSet->pos(category) + m_domainMinY + 1) * scaleY; | |
|
59 | yPos += setCount*barHeight/2; | |
|
60 | yPos -= set*barHeight; | |
|
61 | ||
|
62 | qreal barWidth = barSet->value(category) * scaleX; | |
|
63 | Bar* bar = m_bars.at(itemIndex); | |
|
64 | ||
|
65 | QRectF rect(xPos, yPos - barHeight, barWidth, barHeight); | |
|
66 | layout.append(rect); | |
|
67 | bar->setPen(barSet->m_pen); | |
|
68 | bar->setBrush(barSet->m_brush); | |
|
69 | if (qFuzzyIsNull(barHeight)) { | |
|
70 | bar->setVisible(false); | |
|
71 | } else { | |
|
72 | bar->setVisible(barsVisible); | |
|
73 | } | |
|
74 | ||
|
75 | QGraphicsSimpleTextItem* label = m_labels.at(itemIndex); | |
|
76 | ||
|
77 | if (!qFuzzyIsNull(barSet->value(category))) { | |
|
78 | label->setText(QString::number(barSet->value(category))); | |
|
79 | } else { | |
|
80 | label->setText(QString("")); | |
|
81 | } | |
|
82 | ||
|
83 | label->setPos(xPos + (rect.width()/2 - label->boundingRect().width()/2) | |
|
84 | ,yPos - barHeight/2 - label->boundingRect().height()/2); | |
|
85 | label->setFont(barSet->m_labelFont); | |
|
86 | label->setBrush(barSet->m_labelBrush); | |
|
87 | ||
|
88 | itemIndex++; | |
|
89 | } | |
|
90 | } | |
|
14 | 91 | return layout; |
|
15 | 92 | } |
|
16 | 93 | |
|
17 | 94 | #include "moc_horizontalbarchartitem_p.cpp" |
|
18 | 95 | |
|
19 | 96 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,23 +1,51 | |||
|
1 | /**************************************************************************** | |
|
2 | ** | |
|
3 | ** Copyright (C) 2012 Digia Plc | |
|
4 | ** All rights reserved. | |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
|
6 | ** | |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
|
8 | ** | |
|
9 | ** $QT_BEGIN_LICENSE$ | |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
|
13 | ** a written agreement between you and Digia. | |
|
14 | ** | |
|
15 | ** If you have questions regarding the use of this file, please use | |
|
16 | ** contact form at http://qt.digia.com | |
|
17 | ** $QT_END_LICENSE$ | |
|
18 | ** | |
|
19 | ****************************************************************************/ | |
|
20 | ||
|
21 | // W A R N I N G | |
|
22 | // ------------- | |
|
23 | // | |
|
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an | |
|
25 | // implementation detail. This header file may change from version to | |
|
26 | // version without notice, or even be removed. | |
|
27 | // | |
|
28 | // We mean it. | |
|
29 | ||
|
1 | 30 | #ifndef HORIZONTALBARCHARTITEM_H |
|
2 | 31 | #define HORIZONTALBARCHARTITEM_H |
|
3 | 32 | |
|
4 | 33 | #include "abstractbarchartitem_p.h" |
|
5 | 34 | #include "qstackedbarseries.h" |
|
6 | 35 | #include <QGraphicsItem> |
|
7 | 36 | |
|
8 | 37 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
9 | 38 | |
|
10 | ||
|
11 | class HorizontalBarChartitem : public AbstractBarChartItem | |
|
39 | class HorizontalBarChartItem : public AbstractBarChartItem | |
|
12 | 40 | { |
|
13 | 41 | Q_OBJECT |
|
14 | 42 | public: |
|
15 |
HorizontalBarChart |
|
|
43 | HorizontalBarChartItem(QAbstractBarSeries *series, ChartPresenter *presenter); | |
|
16 | 44 | |
|
17 | 45 | private: |
|
18 | 46 | virtual QVector<QRectF> calculateLayout(); |
|
19 | 47 | }; |
|
20 | 48 | |
|
21 | 49 | QTCOMMERCIALCHART_END_NAMESPACE |
|
22 | 50 | |
|
23 | 51 | #endif // HORIZONTALBARCHARTITEM_H |
@@ -1,102 +1,102 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #include "percentbarchartitem_p.h" |
|
22 | 22 | #include "bar_p.h" |
|
23 | 23 | #include "qabstractbarseries_p.h" |
|
24 | 24 | #include "qbarset.h" |
|
25 | 25 | #include "chartanimator_p.h" |
|
26 | 26 | #include "qbarset_p.h" |
|
27 | 27 | |
|
28 | 28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
29 | 29 | |
|
30 | 30 | PercentBarChartItem::PercentBarChartItem(QAbstractBarSeries *series, ChartPresenter *presenter) : |
|
31 | 31 | AbstractBarChartItem(series, presenter) |
|
32 | 32 | { |
|
33 | 33 | } |
|
34 | 34 | |
|
35 | 35 | QVector<QRectF> PercentBarChartItem::calculateLayout() |
|
36 | 36 | { |
|
37 | 37 | QVector<QRectF> layout; |
|
38 | 38 | |
|
39 | 39 | // Use temporary qreals for accuracy |
|
40 | 40 | qreal categoryCount = m_series->d_func()->categoryCount(); |
|
41 | 41 | qreal setCount = m_series->count(); |
|
42 | 42 | bool barsVisible = m_series->isVisible(); |
|
43 | 43 | |
|
44 | 44 | // Domain: |
|
45 | 45 | qreal width = geometry().width(); |
|
46 | 46 | qreal height = geometry().height(); |
|
47 | 47 | qreal rangeY = m_domainMaxY - m_domainMinY; |
|
48 | 48 | qreal rangeX = m_domainMaxX - m_domainMinX; |
|
49 | 49 | qreal scaleY = (height / rangeY); |
|
50 | 50 | qreal scaleX = (width / rangeX); |
|
51 | 51 | qreal barWidth = scaleX * m_series->d_func()->barWidth(); |
|
52 | 52 | |
|
53 | 53 | int itemIndex(0); |
|
54 | 54 | for (int category = 0; category < categoryCount; category++) { |
|
55 | 55 | qreal colSum = m_series->d_func()->categorySum(category); |
|
56 | 56 | qreal percentage = (100 / colSum); |
|
57 | 57 | qreal yPos = height + scaleY * m_domainMinY + geometry().topLeft().y(); |
|
58 | 58 | for (int set=0; set < setCount; set++) { |
|
59 | 59 | QBarSetPrivate* barSet = m_series->d_func()->barsetAt(set)->d_ptr.data(); |
|
60 | 60 | |
|
61 |
qreal xPos = (barSet-> |
|
|
61 | qreal xPos = (barSet->pos(category) - m_domainMinX) * scaleX + m_rect.left() - barWidth/2; | |
|
62 | 62 | |
|
63 |
qreal barHeight = barSet-> |
|
|
63 | qreal barHeight = barSet->value(category) * percentage * scaleY; | |
|
64 | 64 | Bar* bar = m_bars.at(itemIndex); |
|
65 | 65 | bar->setPen(barSet->m_pen); |
|
66 | 66 | bar->setBrush(barSet->m_brush); |
|
67 | 67 | if (qFuzzyIsNull(barHeight)) { |
|
68 | 68 | bar->setVisible(false); |
|
69 | 69 | } else { |
|
70 | 70 | bar->setVisible(barsVisible); |
|
71 | 71 | } |
|
72 | 72 | |
|
73 | 73 | QRectF rect(xPos, yPos-barHeight, barWidth, barHeight); |
|
74 | 74 | layout.append(rect); |
|
75 | 75 | |
|
76 | 76 | QGraphicsSimpleTextItem* label = m_labels.at(itemIndex); |
|
77 | 77 | |
|
78 | 78 | if (!qFuzzyIsNull(m_series->d_func()->valueAt(set,category))) { |
|
79 | 79 | int p = m_series->d_func()->percentageAt(set,category) * 100; |
|
80 | 80 | QString vString(QString::number(p)); |
|
81 | 81 | vString.truncate(3); |
|
82 | 82 | vString.append("%"); |
|
83 | 83 | label->setText(vString); |
|
84 | 84 | } else { |
|
85 | 85 | label->setText(QString("")); |
|
86 | 86 | } |
|
87 | 87 | |
|
88 | 88 | label->setPos(xPos + (rect.width()/2 - label->boundingRect().width()/2) |
|
89 | 89 | ,yPos - barHeight/2 - label->boundingRect().height()/2); |
|
90 | 90 | label->setFont(barSet->m_labelFont); |
|
91 | 91 | label->setBrush(barSet->m_labelBrush); |
|
92 | 92 | |
|
93 | 93 | itemIndex++; |
|
94 | 94 | yPos -= barHeight; |
|
95 | 95 | } |
|
96 | 96 | } |
|
97 | 97 | return layout; |
|
98 | 98 | } |
|
99 | 99 | |
|
100 | 100 | #include "moc_percentbarchartitem_p.cpp" |
|
101 | 101 | |
|
102 | 102 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,737 +1,737 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #include "qabstractbarseries.h" |
|
22 | 22 | #include "qabstractbarseries_p.h" |
|
23 | 23 | #include "qbarset.h" |
|
24 | 24 | #include "qbarset_p.h" |
|
25 | 25 | #include "domain_p.h" |
|
26 | 26 | #include "legendmarker_p.h" |
|
27 | 27 | #include "chartdataset_p.h" |
|
28 | 28 | #include "charttheme_p.h" |
|
29 | 29 | #include "chartanimator_p.h" |
|
30 | 30 | #include "qvaluesaxis.h" |
|
31 | 31 | #include "qbarcategoriesaxis.h" |
|
32 | 32 | |
|
33 | 33 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
34 | 34 | |
|
35 | 35 | /*! |
|
36 | 36 | \class QAbstractBarSeries |
|
37 | 37 | \brief Series for creating a bar chart |
|
38 | 38 | \mainclass |
|
39 | 39 | |
|
40 | 40 | QAbstractBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars to |
|
41 | 41 | the position defined by data. Single bar is defined by QPointF, where x value is the x-coordinate of the bar |
|
42 | 42 | and y-value is the height of the bar. The category names are ignored with this series and x-axis |
|
43 | 43 | shows the x-values. |
|
44 | 44 | |
|
45 | 45 | See the \l {BarChart Example} {bar chart example} to learn how to create a simple bar chart. |
|
46 | 46 | \image examples_barchart.png |
|
47 | 47 | |
|
48 | 48 | \sa QBarSet, QStackedBarSeries, QPercentBarSeries |
|
49 | 49 | */ |
|
50 | 50 | /*! |
|
51 | 51 | \qmlclass AbstractBarSeries QAbstractBarSeries |
|
52 | 52 | \inherits QAbstractSeries |
|
53 | 53 | |
|
54 | 54 | The following QML shows how to create a simple bar chart: |
|
55 | 55 | \snippet ../demos/qmlchart/qml/qmlchart/View6.qml 1 |
|
56 | 56 | |
|
57 | 57 | \beginfloatleft |
|
58 | 58 | \image demos_qmlchart6.png |
|
59 | 59 | \endfloat |
|
60 | 60 | \clearfloat |
|
61 | 61 | */ |
|
62 | 62 | |
|
63 | 63 | /*! |
|
64 | 64 | \property QAbstractBarSeries::barWidth |
|
65 | 65 | The width of the bars of the series. The unit of \a width is the unit of x-axis. The minimum width for bars |
|
66 | 66 | is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen |
|
67 | 67 | is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis. |
|
68 | 68 | Note that with QBarSeries this value means the width of one group of bars instead of just one bar. |
|
69 | 69 | \sa QBarSeries |
|
70 | 70 | */ |
|
71 | 71 | /*! |
|
72 | 72 | \qmlproperty real AbstractBarSeries::barWidth |
|
73 | 73 | The width of the bars of the series. The unit of width is the unit of x-axis. The minimum width for bars |
|
74 | 74 | is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen |
|
75 | 75 | is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis. |
|
76 | 76 | Note that with QBarSeries this value means the width of one group of bars instead of just one bar. |
|
77 | 77 | */ |
|
78 | 78 | |
|
79 | 79 | /*! |
|
80 | 80 | \property QAbstractBarSeries::count |
|
81 | 81 | Holds the number of sets in series. |
|
82 | 82 | */ |
|
83 | 83 | /*! |
|
84 | 84 | \qmlproperty int AbstractBarSeries::count |
|
85 | 85 | Holds the number of sets in series. |
|
86 | 86 | */ |
|
87 | 87 | |
|
88 | 88 | /*! |
|
89 | 89 | \property QAbstractBarSeries::labelsVisible |
|
90 | 90 | Defines the visibility of the labels in series |
|
91 | 91 | */ |
|
92 | 92 | /*! |
|
93 | 93 | \qmlproperty bool AbstractBarSeries::labelsVisible |
|
94 | 94 | Defines the visibility of the labels in series |
|
95 | 95 | */ |
|
96 | 96 | |
|
97 | 97 | /*! |
|
98 | 98 | \fn void QAbstractBarSeries::clicked(int index, QBarSet *barset) |
|
99 | 99 | The signal is emitted if the user clicks with a mouse on top of QBarSet \a barset. |
|
100 | 100 | Clicked bar inside set is indexed by \a index |
|
101 | 101 | */ |
|
102 | 102 | /*! |
|
103 | 103 | \qmlsignal AbstractBarSeries::onClicked(int index, BarSet barset) |
|
104 | 104 | The signal is emitted if the user clicks with a mouse on top of BarSet. |
|
105 | 105 | Clicked bar inside set is indexed by \a index |
|
106 | 106 | */ |
|
107 | 107 | |
|
108 | 108 | /*! |
|
109 | 109 | \fn void QAbstractBarSeries::hovered(bool status, QBarSet* barset) |
|
110 | 110 | |
|
111 | 111 | The signal is emitted if mouse is hovered on top of series. |
|
112 | 112 | Parameter \a barset is the pointer of barset, where hover happened. |
|
113 | 113 | Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series. |
|
114 | 114 | */ |
|
115 | 115 | /*! |
|
116 | 116 | \qmlsignal AbstractBarSeries::onHovered(bool status, BarSet barset) |
|
117 | 117 | |
|
118 | 118 | The signal is emitted if mouse is hovered on top of series. |
|
119 | 119 | Parameter \a barset is the pointer of barset, where hover happened. |
|
120 | 120 | Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series. |
|
121 | 121 | */ |
|
122 | 122 | |
|
123 | 123 | /*! |
|
124 | 124 | \fn void QAbstractBarSeries::countChanged() |
|
125 | 125 | This signal is emitted when barset count has been changed, for example by append or remove. |
|
126 | 126 | */ |
|
127 | 127 | /*! |
|
128 | 128 | \qmlsignal AbstractBarSeries::onCountChanged() |
|
129 | 129 | This signal is emitted when barset count has been changed, for example by append or remove. |
|
130 | 130 | */ |
|
131 | 131 | |
|
132 | 132 | /*! |
|
133 | 133 | \fn void QAbstractBarSeries::labelsVisibleChanged() |
|
134 | 134 | This signal is emitted when labels visibility have changed. |
|
135 | 135 | \sa isLabelsVisible(), setLabelsVisible() |
|
136 | 136 | */ |
|
137 | 137 | |
|
138 | 138 | /*! |
|
139 | 139 | \fn void QAbstractBarSeries::barsetsAdded(QList<QBarSet*> sets) |
|
140 | 140 | This signal is emitted when \a sets have been added to the series. |
|
141 | 141 | \sa append(), insert() |
|
142 | 142 | */ |
|
143 | 143 | /*! |
|
144 | 144 | \qmlsignal AbstractBarSeries::onAdded(BarSet barset) |
|
145 | 145 | Emitted when \a barset has been added to the series. |
|
146 | 146 | */ |
|
147 | 147 | |
|
148 | 148 | /*! |
|
149 | 149 | \fn void QAbstractBarSeries::barsetsRemoved(QList<QBarSet*> sets) |
|
150 | 150 | This signal is emitted when \a sets have been removed from the series. |
|
151 | 151 | \sa remove() |
|
152 | 152 | */ |
|
153 | 153 | /*! |
|
154 | 154 | \qmlsignal AbstractBarSeries::onRemoved(BarSet barset) |
|
155 | 155 | Emitted when \a barset has been removed from the series. |
|
156 | 156 | */ |
|
157 | 157 | |
|
158 | 158 | /*! |
|
159 | 159 | \qmlmethod BarSet AbstractBarSeries::at(int index) |
|
160 | 160 | Returns bar set at \a index. Returns null if the index is not valid. |
|
161 | 161 | */ |
|
162 | 162 | |
|
163 | 163 | /*! |
|
164 | 164 | \qmlmethod BarSet AbstractBarSeries::append(string label, VariantList values) |
|
165 | 165 | Adds a new bar set with \a label and \a values to \a index. Values can be a list of reals or a list of XYPoints. |
|
166 | 166 | For example: |
|
167 | 167 | \code |
|
168 | 168 | myBarSeries.append("set 1", [0, 0.2, 0.2, 0.5, 0.4, 1.5, 0.9]); |
|
169 | 169 | myBarSeries.append("set 2", [Qt.point(0, 1), Qt.point(2, 2.5), Qt.point(3.5, 2.2)]); |
|
170 | 170 | \endcode |
|
171 | 171 | */ |
|
172 | 172 | |
|
173 | 173 | /*! |
|
174 | 174 | \qmlmethod BarSet AbstractBarSeries::insert(int index, string label, VariantList values) |
|
175 | 175 | Inserts a new bar set with \a label and \a values to \a index. Values can be a list of reals or a list of XYPoints. |
|
176 | 176 | If index is zero or smaller, the new barset is prepended. If the index is count or bigger, the new barset is |
|
177 | 177 | appended. |
|
178 | 178 | \sa AbstractBarSeries::append() |
|
179 | 179 | */ |
|
180 | 180 | |
|
181 | 181 | /*! |
|
182 | 182 | \qmlmethod bool AbstractBarSeries::remove(BarSet barset) |
|
183 | 183 | Removes the barset from the series. Returns true if successfull, false otherwise. |
|
184 | 184 | */ |
|
185 | 185 | |
|
186 | 186 | /*! |
|
187 | 187 | \qmlmethod AbstractBarSeries::clear() |
|
188 | 188 | Removes all barsets from the series. |
|
189 | 189 | */ |
|
190 | 190 | |
|
191 | 191 | /*! |
|
192 | 192 | Constructs empty QAbstractBarSeries. |
|
193 | 193 | QAbstractBarSeries is QObject which is a child of a \a parent. |
|
194 | 194 | */ |
|
195 | 195 | QAbstractBarSeries::QAbstractBarSeries(QObject *parent) : |
|
196 | 196 | QAbstractSeries(*new QAbstractBarSeriesPrivate(this),parent) |
|
197 | 197 | { |
|
198 | 198 | } |
|
199 | 199 | |
|
200 | 200 | /*! |
|
201 | 201 | Destructs abstractbarseries and owned barsets. |
|
202 | 202 | */ |
|
203 | 203 | QAbstractBarSeries::~QAbstractBarSeries() |
|
204 | 204 | { |
|
205 | 205 | Q_D(QAbstractBarSeries); |
|
206 | 206 | if(d->m_dataset){ |
|
207 | 207 | d->m_dataset->removeSeries(this); |
|
208 | 208 | } |
|
209 | 209 | } |
|
210 | 210 | |
|
211 | 211 | /*! |
|
212 | 212 | \internal |
|
213 | 213 | */ |
|
214 | 214 | QAbstractBarSeries::QAbstractBarSeries(QAbstractBarSeriesPrivate &d, QObject *parent) : |
|
215 | 215 | QAbstractSeries(d,parent) |
|
216 | 216 | { |
|
217 | 217 | } |
|
218 | 218 | |
|
219 | 219 | /*! |
|
220 | 220 | Sets the width of the bars of the series. The unit of \a width is the unit of x-axis. The minimum width for bars |
|
221 | 221 | is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen |
|
222 | 222 | is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis. |
|
223 | 223 | Note that with \link QBarSeries \endlink this value means the width of one group of bars instead of just one bar. |
|
224 | 224 | */ |
|
225 | 225 | void QAbstractBarSeries::setBarWidth(qreal width) |
|
226 | 226 | { |
|
227 | 227 | Q_D(QAbstractBarSeries); |
|
228 | 228 | d->setBarWidth(width); |
|
229 | 229 | } |
|
230 | 230 | |
|
231 | 231 | /*! |
|
232 | 232 | Returns the width of the bars of the series. |
|
233 | 233 | \sa setBarWidth() |
|
234 | 234 | */ |
|
235 | 235 | qreal QAbstractBarSeries::barWidth() const |
|
236 | 236 | { |
|
237 | 237 | Q_D(const QAbstractBarSeries); |
|
238 | 238 | return d->barWidth(); |
|
239 | 239 | } |
|
240 | 240 | |
|
241 | 241 | /*! |
|
242 | 242 | Adds a set of bars to series. Takes ownership of \a set. If the set is null or is already in series, it won't be appended. |
|
243 | 243 | Returns true, if appending succeeded. |
|
244 | 244 | */ |
|
245 | 245 | bool QAbstractBarSeries::append(QBarSet *set) |
|
246 | 246 | { |
|
247 | 247 | Q_D(QAbstractBarSeries); |
|
248 | 248 | bool success = d->append(set); |
|
249 | 249 | if (success) { |
|
250 | 250 | QList<QBarSet*> sets; |
|
251 | 251 | sets.append(set); |
|
252 | 252 | emit barsetsAdded(sets); |
|
253 | 253 | emit countChanged(); |
|
254 | 254 | } |
|
255 | 255 | return success; |
|
256 | 256 | } |
|
257 | 257 | |
|
258 | 258 | /*! |
|
259 | 259 | Removes a set of bars from series. Releases ownership of \a set. Doesn't delete \a set. |
|
260 | 260 | Returns true, if set was removed. |
|
261 | 261 | */ |
|
262 | 262 | bool QAbstractBarSeries::remove(QBarSet *set) |
|
263 | 263 | { |
|
264 | 264 | Q_D(QAbstractBarSeries); |
|
265 | 265 | bool success = d->remove(set); |
|
266 | 266 | if (success) { |
|
267 | 267 | QList<QBarSet*> sets; |
|
268 | 268 | sets.append(set); |
|
269 | 269 | emit barsetsRemoved(sets); |
|
270 | 270 | emit countChanged(); |
|
271 | 271 | } |
|
272 | 272 | return success; |
|
273 | 273 | } |
|
274 | 274 | |
|
275 | 275 | /*! |
|
276 | 276 | Adds a list of barsets to series. Takes ownership of \a sets. |
|
277 | 277 | Returns true, if all sets were appended succesfully. If any of the sets is null or is already appended to series, |
|
278 | 278 | nothing is appended and function returns false. If any of the sets is in list more than once, nothing is appended |
|
279 | 279 | and function returns false. |
|
280 | 280 | */ |
|
281 | 281 | bool QAbstractBarSeries::append(QList<QBarSet* > sets) |
|
282 | 282 | { |
|
283 | 283 | Q_D(QAbstractBarSeries); |
|
284 | 284 | bool success = d->append(sets); |
|
285 | 285 | if (success) { |
|
286 | 286 | emit barsetsAdded(sets); |
|
287 | 287 | emit countChanged(); |
|
288 | 288 | } |
|
289 | 289 | return success; |
|
290 | 290 | } |
|
291 | 291 | |
|
292 | 292 | /*! |
|
293 | 293 | Insert a set of bars to series at \a index postion. Takes ownership of \a set. If the set is null or is already in series, it won't be appended. |
|
294 | 294 | Returns true, if inserting succeeded. |
|
295 | 295 | |
|
296 | 296 | */ |
|
297 | 297 | bool QAbstractBarSeries::insert(int index, QBarSet *set) |
|
298 | 298 | { |
|
299 | 299 | Q_D(QAbstractBarSeries); |
|
300 | 300 | bool success = d->insert(index, set); |
|
301 | 301 | if (success) { |
|
302 | 302 | QList<QBarSet*> sets; |
|
303 | 303 | sets.append(set); |
|
304 | 304 | emit barsetsAdded(sets); |
|
305 | 305 | emit countChanged(); |
|
306 | 306 | } |
|
307 | 307 | return success; |
|
308 | 308 | } |
|
309 | 309 | |
|
310 | 310 | /*! |
|
311 | 311 | Removes all of the bar sets from the series |
|
312 | 312 | */ |
|
313 | 313 | void QAbstractBarSeries::clear() |
|
314 | 314 | { |
|
315 | 315 | Q_D(QAbstractBarSeries); |
|
316 | 316 | QList<QBarSet *> sets = barSets(); |
|
317 | 317 | bool success = d->remove(sets); |
|
318 | 318 | if (success) { |
|
319 | 319 | emit barsetsRemoved(sets); |
|
320 | 320 | emit countChanged(); |
|
321 | 321 | } |
|
322 | 322 | } |
|
323 | 323 | |
|
324 | 324 | /*! |
|
325 | 325 | Returns number of sets in series. |
|
326 | 326 | */ |
|
327 | 327 | int QAbstractBarSeries::count() const |
|
328 | 328 | { |
|
329 | 329 | Q_D(const QAbstractBarSeries); |
|
330 | 330 | return d->m_barSets.count(); |
|
331 | 331 | } |
|
332 | 332 | |
|
333 | 333 | /*! |
|
334 | 334 | Returns a list of sets in series. Keeps ownership of sets. |
|
335 | 335 | */ |
|
336 | 336 | QList<QBarSet*> QAbstractBarSeries::barSets() const |
|
337 | 337 | { |
|
338 | 338 | Q_D(const QAbstractBarSeries); |
|
339 | 339 | return d->m_barSets; |
|
340 | 340 | } |
|
341 | 341 | |
|
342 | 342 | /*! |
|
343 | 343 | Sets the visibility of labels in series to \a visible |
|
344 | 344 | */ |
|
345 | 345 | void QAbstractBarSeries::setLabelsVisible(bool visible) |
|
346 | 346 | { |
|
347 | 347 | Q_D(QAbstractBarSeries); |
|
348 | 348 | if (d->m_labelsVisible != visible) { |
|
349 | 349 | d->setLabelsVisible(visible); |
|
350 | 350 | emit labelsVisibleChanged(); |
|
351 | 351 | } |
|
352 | 352 | } |
|
353 | 353 | |
|
354 | 354 | /*! |
|
355 | 355 | Returns the visibility of labels |
|
356 | 356 | */ |
|
357 | 357 | bool QAbstractBarSeries::isLabelsVisible() const |
|
358 | 358 | { |
|
359 | 359 | Q_D(const QAbstractBarSeries); |
|
360 | 360 | return d->m_labelsVisible; |
|
361 | 361 | } |
|
362 | 362 | |
|
363 | 363 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
364 | 364 | |
|
365 | 365 | QAbstractBarSeriesPrivate::QAbstractBarSeriesPrivate(QAbstractBarSeries *q) : |
|
366 | 366 | QAbstractSeriesPrivate(q), |
|
367 | 367 | m_barWidth(0.5), // Default value is 50% of category width |
|
368 | 368 | m_labelsVisible(false), |
|
369 | 369 | m_visible(true) |
|
370 | 370 | { |
|
371 | 371 | } |
|
372 | 372 | |
|
373 | 373 | int QAbstractBarSeriesPrivate::categoryCount() const |
|
374 | 374 | { |
|
375 | 375 | // No categories defined. return count of longest set. |
|
376 | 376 | int count = 0; |
|
377 | 377 | for (int i=0; i<m_barSets.count(); i++) { |
|
378 | 378 | if (m_barSets.at(i)->count() > count) { |
|
379 | 379 | count = m_barSets.at(i)->count(); |
|
380 | 380 | } |
|
381 | 381 | } |
|
382 | 382 | |
|
383 | 383 | return count; |
|
384 | 384 | } |
|
385 | 385 | |
|
386 | 386 | void QAbstractBarSeriesPrivate::setBarWidth(qreal width) |
|
387 | 387 | { |
|
388 | 388 | if (width < 0.0) { |
|
389 | 389 | width = 0.0; |
|
390 | 390 | } |
|
391 | 391 | m_barWidth = width; |
|
392 | 392 | emit updatedBars(); |
|
393 | 393 | } |
|
394 | 394 | |
|
395 | 395 | qreal QAbstractBarSeriesPrivate::barWidth() const |
|
396 | 396 | { |
|
397 | 397 | return m_barWidth; |
|
398 | 398 | } |
|
399 | 399 | |
|
400 | 400 | QBarSet* QAbstractBarSeriesPrivate::barsetAt(int index) |
|
401 | 401 | { |
|
402 | 402 | return m_barSets.at(index); |
|
403 | 403 | } |
|
404 | 404 | |
|
405 | 405 | void QAbstractBarSeriesPrivate::setVisible(bool visible) |
|
406 | 406 | { |
|
407 | 407 | m_visible = visible; |
|
408 | 408 | emit updatedBars(); |
|
409 | 409 | } |
|
410 | 410 | |
|
411 | 411 | void QAbstractBarSeriesPrivate::setLabelsVisible(bool visible) |
|
412 | 412 | { |
|
413 | 413 | m_labelsVisible = visible; |
|
414 | 414 | emit labelsVisibleChanged(visible); |
|
415 | 415 | } |
|
416 | 416 | |
|
417 | 417 | qreal QAbstractBarSeriesPrivate::min() |
|
418 | 418 | { |
|
419 | 419 | if (m_barSets.count() <= 0) { |
|
420 | 420 | return 0; |
|
421 | 421 | } |
|
422 | 422 | qreal min = INT_MAX; |
|
423 | 423 | |
|
424 | 424 | for (int i = 0; i < m_barSets.count(); i++) { |
|
425 | 425 | int categoryCount = m_barSets.at(i)->count(); |
|
426 | 426 | for (int j = 0; j < categoryCount; j++) { |
|
427 | 427 | qreal temp = m_barSets.at(i)->at(j); |
|
428 | 428 | if (temp < min) |
|
429 | 429 | min = temp; |
|
430 | 430 | } |
|
431 | 431 | } |
|
432 | 432 | return min; |
|
433 | 433 | } |
|
434 | 434 | |
|
435 | 435 | qreal QAbstractBarSeriesPrivate::max() |
|
436 | 436 | { |
|
437 | 437 | if (m_barSets.count() <= 0) { |
|
438 | 438 | return 0; |
|
439 | 439 | } |
|
440 | 440 | qreal max = INT_MIN; |
|
441 | 441 | |
|
442 | 442 | for (int i = 0; i < m_barSets.count(); i++) { |
|
443 | 443 | int categoryCount = m_barSets.at(i)->count(); |
|
444 | 444 | for (int j = 0; j < categoryCount; j++) { |
|
445 | 445 | qreal temp = m_barSets.at(i)->at(j); |
|
446 | 446 | if (temp > max) |
|
447 | 447 | max = temp; |
|
448 | 448 | } |
|
449 | 449 | } |
|
450 | 450 | |
|
451 | 451 | return max; |
|
452 | 452 | } |
|
453 | 453 | |
|
454 | 454 | qreal QAbstractBarSeriesPrivate::valueAt(int set, int category) |
|
455 | 455 | { |
|
456 | 456 | if ((set < 0) || (set >= m_barSets.count())) { |
|
457 | 457 | // No set, no value. |
|
458 | 458 | return 0; |
|
459 | 459 | } else if ((category < 0) || (category >= m_barSets.at(set)->count())) { |
|
460 | 460 | // No category, no value. |
|
461 | 461 | return 0; |
|
462 | 462 | } |
|
463 | 463 | |
|
464 | 464 | return m_barSets.at(set)->at(category); |
|
465 | 465 | } |
|
466 | 466 | |
|
467 | 467 | qreal QAbstractBarSeriesPrivate::percentageAt(int set, int category) |
|
468 | 468 | { |
|
469 | 469 | if ((set < 0) || (set >= m_barSets.count())) { |
|
470 | 470 | // No set, no value. |
|
471 | 471 | return 0; |
|
472 | 472 | } else if ((category < 0) || (category >= m_barSets.at(set)->count())) { |
|
473 | 473 | // No category, no value. |
|
474 | 474 | return 0; |
|
475 | 475 | } |
|
476 | 476 | |
|
477 | 477 | qreal value = m_barSets.at(set)->at(category); |
|
478 | 478 | qreal sum = categorySum(category); |
|
479 | 479 | if ( qFuzzyIsNull(sum) ) { |
|
480 | 480 | return 0; |
|
481 | 481 | } |
|
482 | 482 | |
|
483 | 483 | return value / sum; |
|
484 | 484 | } |
|
485 | 485 | |
|
486 | 486 | qreal QAbstractBarSeriesPrivate::categorySum(int category) |
|
487 | 487 | { |
|
488 | 488 | qreal sum(0); |
|
489 | 489 | int count = m_barSets.count(); // Count sets |
|
490 | 490 | for (int set = 0; set < count; set++) { |
|
491 | 491 | if (category < m_barSets.at(set)->count()) |
|
492 | 492 | sum += m_barSets.at(set)->at(category); |
|
493 | 493 | } |
|
494 | 494 | return sum; |
|
495 | 495 | } |
|
496 | 496 | |
|
497 | 497 | qreal QAbstractBarSeriesPrivate::absoluteCategorySum(int category) |
|
498 | 498 | { |
|
499 | 499 | qreal sum(0); |
|
500 | 500 | int count = m_barSets.count(); // Count sets |
|
501 | 501 | for (int set = 0; set < count; set++) { |
|
502 | 502 | if (category < m_barSets.at(set)->count()) |
|
503 | 503 | sum += qAbs(m_barSets.at(set)->at(category)); |
|
504 | 504 | } |
|
505 | 505 | return sum; |
|
506 | 506 | } |
|
507 | 507 | |
|
508 | 508 | qreal QAbstractBarSeriesPrivate::maxCategorySum() |
|
509 | 509 | { |
|
510 | 510 | qreal max = INT_MIN; |
|
511 | 511 | int count = categoryCount(); |
|
512 | 512 | for (int i = 0; i < count; i++) { |
|
513 | 513 | qreal sum = categorySum(i); |
|
514 | 514 | if (sum > max) |
|
515 | 515 | max = sum; |
|
516 | 516 | } |
|
517 | 517 | return max; |
|
518 | 518 | } |
|
519 | 519 | |
|
520 | 520 | qreal QAbstractBarSeriesPrivate::minX() |
|
521 | 521 | { |
|
522 | 522 | if (m_barSets.count() <= 0) { |
|
523 | 523 | return 0; |
|
524 | 524 | } |
|
525 | 525 | qreal min = INT_MAX; |
|
526 | 526 | |
|
527 | 527 | for (int i = 0; i < m_barSets.count(); i++) { |
|
528 | 528 | int categoryCount = m_barSets.at(i)->count(); |
|
529 | 529 | for (int j = 0; j < categoryCount; j++) { |
|
530 | 530 | qreal temp = m_barSets.at(i)->d_ptr.data()->m_values.at(j).x(); |
|
531 | 531 | if (temp < min) |
|
532 | 532 | min = temp; |
|
533 | 533 | } |
|
534 | 534 | } |
|
535 | 535 | return min; |
|
536 | 536 | } |
|
537 | 537 | |
|
538 | 538 | qreal QAbstractBarSeriesPrivate::maxX() |
|
539 | 539 | { |
|
540 | 540 | if (m_barSets.count() <= 0) { |
|
541 | 541 | return 0; |
|
542 | 542 | } |
|
543 | 543 | qreal max = INT_MIN; |
|
544 | 544 | |
|
545 | 545 | for (int i = 0; i < m_barSets.count(); i++) { |
|
546 | 546 | int categoryCount = m_barSets.at(i)->count(); |
|
547 | 547 | for (int j = 0; j < categoryCount; j++) { |
|
548 | 548 | qreal temp = m_barSets.at(i)->d_ptr.data()->m_values.at(j).x(); |
|
549 | 549 | if (temp > max) |
|
550 | 550 | max = temp; |
|
551 | 551 | } |
|
552 | 552 | } |
|
553 | 553 | |
|
554 | 554 | return max; |
|
555 | 555 | } |
|
556 | 556 | |
|
557 | 557 | |
|
558 | 558 | void QAbstractBarSeriesPrivate::scaleDomain(Domain& domain) |
|
559 | 559 | { |
|
560 | 560 | qreal minX(domain.minX()); |
|
561 | 561 | qreal minY(domain.minY()); |
|
562 | 562 | qreal maxX(domain.maxX()); |
|
563 | 563 | qreal maxY(domain.maxY()); |
|
564 | 564 | int tickXCount(domain.tickXCount()); |
|
565 | 565 | int tickYCount(domain.tickYCount()); |
|
566 | 566 | |
|
567 | 567 | qreal seriesMinX = this->minX(); |
|
568 | 568 | qreal seriesMaxX = this->maxX(); |
|
569 | 569 | qreal y = max(); |
|
570 | 570 | minX = qMin(minX, seriesMinX - (qreal)0.5); |
|
571 | 571 | minY = qMin(minY, y); |
|
572 | 572 | maxX = qMax(maxX, seriesMaxX + (qreal)0.5); |
|
573 | 573 | maxY = qMax(maxY, y); |
|
574 | 574 | tickXCount = categoryCount()+1; |
|
575 | 575 | |
|
576 | 576 | domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount); |
|
577 | 577 | } |
|
578 | 578 | |
|
579 | 579 | Chart* QAbstractBarSeriesPrivate::createGraphics(ChartPresenter* presenter) |
|
580 | 580 | { |
|
581 | 581 | Q_UNUSED(presenter); |
|
582 | 582 | qWarning() << "QAbstractBarSeriesPrivate::createGraphics called"; |
|
583 | 583 | return 0; |
|
584 | 584 | } |
|
585 | 585 | |
|
586 | 586 | QList<LegendMarker*> QAbstractBarSeriesPrivate::createLegendMarker(QLegend* legend) |
|
587 | 587 | { |
|
588 | 588 | Q_Q(QAbstractBarSeries); |
|
589 | 589 | QList<LegendMarker*> markers; |
|
590 | 590 | foreach(QBarSet* set, q->barSets()) { |
|
591 | 591 | BarLegendMarker* marker = new BarLegendMarker(q,set,legend); |
|
592 | 592 | markers << marker; |
|
593 | 593 | } |
|
594 | 594 | |
|
595 | 595 | return markers; |
|
596 | 596 | } |
|
597 | 597 | |
|
598 | 598 | bool QAbstractBarSeriesPrivate::append(QBarSet *set) |
|
599 | 599 | { |
|
600 | 600 | Q_Q(QAbstractBarSeries); |
|
601 | 601 | if ((m_barSets.contains(set)) || (set == 0)) { |
|
602 | 602 | // Fail if set is already in list or set is null. |
|
603 | 603 | return false; |
|
604 | 604 | } |
|
605 | 605 | m_barSets.append(set); |
|
606 | 606 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); |
|
607 | 607 | QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); |
|
608 | 608 | emit restructuredBars(); // this notifies barchartitem |
|
609 | 609 | if (m_dataset) { |
|
610 | 610 | m_dataset->updateSeries(q); // this notifies legend |
|
611 | 611 | } |
|
612 | 612 | return true; |
|
613 | 613 | } |
|
614 | 614 | |
|
615 | 615 | bool QAbstractBarSeriesPrivate::remove(QBarSet *set) |
|
616 | 616 | { |
|
617 | 617 | Q_Q(QAbstractBarSeries); |
|
618 | 618 | if (!m_barSets.contains(set)) { |
|
619 | 619 | // Fail if set is not in list |
|
620 | 620 | return false; |
|
621 | 621 | } |
|
622 | 622 | m_barSets.removeOne(set); |
|
623 | 623 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); |
|
624 | 624 | QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); |
|
625 | 625 | emit restructuredBars(); // this notifies barchartitem |
|
626 | 626 | if (m_dataset) { |
|
627 | 627 | m_dataset->updateSeries(q); // this notifies legend |
|
628 | 628 | } |
|
629 | 629 | return true; |
|
630 | 630 | } |
|
631 | 631 | |
|
632 | 632 | bool QAbstractBarSeriesPrivate::append(QList<QBarSet* > sets) |
|
633 | 633 | { |
|
634 | 634 | Q_Q(QAbstractBarSeries); |
|
635 | 635 | foreach (QBarSet* set, sets) { |
|
636 | 636 | if ((set == 0) || (m_barSets.contains(set))) { |
|
637 | 637 | // Fail if any of the sets is null or is already appended. |
|
638 | 638 | return false; |
|
639 | 639 | } |
|
640 | 640 | if (sets.count(set) != 1) { |
|
641 | 641 | // Also fail if same set is more than once in given list. |
|
642 | 642 | return false; |
|
643 | 643 | } |
|
644 | 644 | } |
|
645 | 645 | |
|
646 | 646 | foreach (QBarSet* set, sets) { |
|
647 | 647 | m_barSets.append(set); |
|
648 | 648 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); |
|
649 | 649 | QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); |
|
650 | 650 | } |
|
651 | 651 | emit restructuredBars(); // this notifies barchartitem |
|
652 | 652 | if (m_dataset) { |
|
653 | 653 | m_dataset->updateSeries(q); // this notifies legend |
|
654 | 654 | } |
|
655 | 655 | return true; |
|
656 | 656 | } |
|
657 | 657 | |
|
658 | 658 | bool QAbstractBarSeriesPrivate::remove(QList<QBarSet* > sets) |
|
659 | 659 | { |
|
660 | 660 | Q_Q(QAbstractBarSeries); |
|
661 | 661 | if (sets.count() == 0) { |
|
662 | 662 | return false; |
|
663 | 663 | } |
|
664 | 664 | foreach (QBarSet* set, sets) { |
|
665 | 665 | if ((set == 0) || (!m_barSets.contains(set))) { |
|
666 | 666 | // Fail if any of the sets is null or is not in series |
|
667 | 667 | return false; |
|
668 | 668 | } |
|
669 | 669 | if (sets.count(set) != 1) { |
|
670 | 670 | // Also fail if same set is more than once in given list. |
|
671 | 671 | return false; |
|
672 | 672 | } |
|
673 | 673 | } |
|
674 | 674 | |
|
675 | 675 | foreach (QBarSet* set, sets) { |
|
676 | 676 | m_barSets.removeOne(set); |
|
677 | 677 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); |
|
678 | 678 | QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); |
|
679 | 679 | } |
|
680 | 680 | |
|
681 | 681 | emit restructuredBars(); // this notifies barchartitem |
|
682 | 682 | if (m_dataset) { |
|
683 | 683 | m_dataset->updateSeries(q); // this notifies legend |
|
684 | 684 | } |
|
685 | 685 | return true; |
|
686 | 686 | } |
|
687 | 687 | |
|
688 | 688 | bool QAbstractBarSeriesPrivate::insert(int index, QBarSet *set) |
|
689 | 689 | { |
|
690 | 690 | Q_Q(QAbstractBarSeries); |
|
691 | 691 | if ((m_barSets.contains(set)) || (set == 0)) { |
|
692 | 692 | // Fail if set is already in list or set is null. |
|
693 | 693 | return false; |
|
694 | 694 | } |
|
695 | 695 | m_barSets.insert(index, set); |
|
696 | 696 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); |
|
697 | 697 | QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); |
|
698 | 698 | emit restructuredBars(); // this notifies barchartitem |
|
699 | 699 | if (m_dataset) { |
|
700 | 700 | m_dataset->updateSeries(q); // this notifies legend |
|
701 | 701 | } |
|
702 | 702 | return true; |
|
703 | 703 | } |
|
704 | 704 | |
|
705 | 705 | void QAbstractBarSeriesPrivate::initializeAxisX(QAbstractAxis* axis) |
|
706 | 706 | { |
|
707 | 707 | if(axis->type()==QAbstractAxis::AxisTypeCategories) |
|
708 | 708 | { |
|
709 | 709 | QBarCategoriesAxis* cataxis = qobject_cast<QBarCategoriesAxis*>(axis); |
|
710 | 710 | Q_ASSERT(cataxis); |
|
711 | 711 | QStringList categories; |
|
712 | 712 | for (int i(1); i < categoryCount()+1; i++) |
|
713 | 713 | categories << QString::number(i); |
|
714 | 714 | cataxis->append(categories); |
|
715 | 715 | } |
|
716 | 716 | } |
|
717 | 717 | |
|
718 | 718 | void QAbstractBarSeriesPrivate::initializeAxisY(QAbstractAxis* axis) |
|
719 | 719 | { |
|
720 | 720 | Q_UNUSED(axis) |
|
721 | 721 | } |
|
722 | 722 | |
|
723 | 723 | QAbstractAxis::AxisType QAbstractBarSeriesPrivate::defaultAxisXType() const |
|
724 | 724 | { |
|
725 |
return QAbstractAxis::AxisType |
|
|
725 | return QAbstractAxis::AxisTypeNoAxis; | |
|
726 | 726 | } |
|
727 | 727 | |
|
728 | 728 | QAbstractAxis::AxisType QAbstractBarSeriesPrivate::defaultAxisYType() const |
|
729 | 729 | { |
|
730 |
return QAbstractAxis::AxisType |
|
|
730 | return QAbstractAxis::AxisTypeNoAxis; | |
|
731 | 731 | } |
|
732 | 732 | |
|
733 | 733 | #include "moc_qabstractbarseries.cpp" |
|
734 | 734 | #include "moc_qabstractbarseries_p.cpp" |
|
735 | 735 | |
|
736 | 736 | |
|
737 | 737 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,82 +1,83 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #ifndef ABSTRACTBARSERIES_H |
|
22 | 22 | #define ABSTRACTBARSERIES_H |
|
23 | 23 | |
|
24 | 24 | #include <qabstractseries.h> |
|
25 | 25 | #include <QStringList> |
|
26 | 26 | |
|
27 | 27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
28 | 28 | |
|
29 | 29 | class QBarSet; |
|
30 | 30 | class QAbstractBarSeriesPrivate; |
|
31 | 31 | |
|
32 | 32 | // Container for series |
|
33 | 33 | class QTCOMMERCIALCHART_EXPORT QAbstractBarSeries : public QAbstractSeries |
|
34 | 34 | { |
|
35 | 35 | Q_OBJECT |
|
36 | 36 | Q_PROPERTY(qreal barWidth READ barWidth WRITE setBarWidth) |
|
37 | 37 | Q_PROPERTY(int count READ count NOTIFY countChanged) |
|
38 | 38 | Q_PROPERTY(bool labelsVisible READ isLabelsVisible WRITE setLabelsVisible NOTIFY labelsVisibleChanged) |
|
39 | 39 | |
|
40 | 40 | protected: |
|
41 | 41 | explicit QAbstractBarSeries(QObject *parent = 0); |
|
42 | 42 | |
|
43 | 43 | public: |
|
44 | 44 | virtual ~QAbstractBarSeries(); |
|
45 | 45 | |
|
46 | 46 | void setBarWidth(qreal width); |
|
47 | 47 | qreal barWidth() const; |
|
48 | 48 | |
|
49 | 49 | bool append(QBarSet *set); |
|
50 | 50 | bool remove(QBarSet *set); |
|
51 | 51 | bool append(QList<QBarSet* > sets); |
|
52 | 52 | bool insert(int index, QBarSet *set); |
|
53 | 53 | int count() const; |
|
54 | 54 | QList<QBarSet*> barSets() const; |
|
55 | 55 | void clear(); |
|
56 | 56 | |
|
57 | 57 | void setLabelsVisible(bool visible = true); |
|
58 | 58 | bool isLabelsVisible() const; |
|
59 | 59 | |
|
60 | 60 | protected: |
|
61 | 61 | explicit QAbstractBarSeries(QAbstractBarSeriesPrivate &d,QObject *parent = 0); |
|
62 | 62 | |
|
63 | 63 | Q_SIGNALS: |
|
64 | 64 | void clicked(int index, QBarSet *barset); |
|
65 | 65 | void hovered(bool status, QBarSet *barset); |
|
66 | 66 | void countChanged(); |
|
67 | 67 | void labelsVisibleChanged(); |
|
68 | 68 | |
|
69 | 69 | void barsetsAdded(QList<QBarSet*> sets); |
|
70 | 70 | void barsetsRemoved(QList<QBarSet*> sets); |
|
71 | 71 | |
|
72 | 72 | protected: |
|
73 | 73 | Q_DECLARE_PRIVATE(QAbstractBarSeries) |
|
74 | 74 | friend class AbstractBarChartItem; |
|
75 | 75 | friend class PercentBarChartItem; |
|
76 | 76 | friend class StackedBarChartItem; |
|
77 | 77 | friend class BarChartItem; |
|
78 | friend class HorizontalBarChartItem; | |
|
78 | 79 | }; |
|
79 | 80 | |
|
80 | 81 | QTCOMMERCIALCHART_END_NAMESPACE |
|
81 | 82 | |
|
82 | 83 | #endif // ABSTRACTBARSERIES_H |
@@ -1,119 +1,129 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #include "qbarseries.h" |
|
22 | 22 | #include "qbarseries_p.h" |
|
23 | 23 | #include "barchartitem_p.h" |
|
24 | 24 | #include "chartdataset_p.h" |
|
25 | 25 | #include "charttheme_p.h" |
|
26 | 26 | #include "chartanimator_p.h" |
|
27 | 27 | #include "baranimation_p.h" |
|
28 | 28 | #include "qvaluesaxis.h" |
|
29 | 29 | |
|
30 | 30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
31 | 31 | |
|
32 | 32 | /*! |
|
33 | 33 | \class QBarSeries |
|
34 | 34 | \brief Series for creating bar chart |
|
35 | 35 | \mainclass |
|
36 | 36 | |
|
37 | 37 | QBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars |
|
38 | 38 | as groups, where bars in same category are grouped next to each other. QBarSeries groups the data |
|
39 | 39 | from sets to categories, which are defined by a QStringList. |
|
40 | 40 | |
|
41 | 41 | See the \l {BarChart Example} {bar chart example} to learn how to create a grouped bar chart. |
|
42 | 42 | \image examples_barchart.png |
|
43 | 43 | |
|
44 | 44 | \sa QBarSet, QPercentBarSeries, QAbstractBarSeries, QStackedBarSeries |
|
45 | 45 | */ |
|
46 | 46 | /*! |
|
47 | 47 | \qmlclass BarSeries QBarSeries |
|
48 | 48 | \inherits AbstractBarSeries |
|
49 | 49 | |
|
50 | 50 | The following QML shows how to create a simple grouped bar chart: |
|
51 | 51 | \snippet ../demos/qmlchart/qml/qmlchart/View6.qml 1 |
|
52 | 52 | \beginfloatleft |
|
53 | 53 | \image demos_qmlchart6.png |
|
54 | 54 | \endfloat |
|
55 | 55 | \clearfloat |
|
56 | 56 | */ |
|
57 | 57 | |
|
58 | 58 | /*! |
|
59 | 59 | Constructs empty QBarSeries. |
|
60 | 60 | QBarSeries is QObject which is a child of a \a parent. |
|
61 | 61 | */ |
|
62 | 62 | QBarSeries::QBarSeries(QObject *parent) |
|
63 | 63 | : QAbstractBarSeries(*new QBarSeriesPrivate(this), parent) |
|
64 | 64 | { |
|
65 | 65 | } |
|
66 | 66 | |
|
67 | 67 | /*! |
|
68 | 68 | Returns QChartSeries::SeriesTypeBar. |
|
69 | 69 | */ |
|
70 | 70 | QAbstractSeries::SeriesType QBarSeries::type() const |
|
71 | 71 | { |
|
72 | 72 | return QAbstractSeries::SeriesTypeBar; |
|
73 | 73 | } |
|
74 | 74 | |
|
75 | 75 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
76 | 76 | |
|
77 | 77 | QBarSeriesPrivate::QBarSeriesPrivate(QBarSeries *q) : QAbstractBarSeriesPrivate(q) |
|
78 | 78 | { |
|
79 | 79 | |
|
80 | 80 | } |
|
81 | 81 | |
|
82 | 82 | void QBarSeriesPrivate::scaleDomain(Domain& domain) |
|
83 | 83 | { |
|
84 | 84 | qreal minX(domain.minX()); |
|
85 | 85 | qreal minY(domain.minY()); |
|
86 | 86 | qreal maxX(domain.maxX()); |
|
87 | 87 | qreal maxY(domain.maxY()); |
|
88 | 88 | int tickXCount(domain.tickXCount()); |
|
89 | 89 | int tickYCount(domain.tickYCount()); |
|
90 | 90 | |
|
91 | 91 | qreal x = categoryCount(); |
|
92 | 92 | qreal y = max(); |
|
93 | 93 | minX = qMin(minX, - (qreal)0.5); |
|
94 | 94 | minY = qMin(minY, y); |
|
95 | 95 | maxX = qMax(maxX, x - (qreal)0.5); |
|
96 | 96 | maxY = qMax(maxY, y); |
|
97 | 97 | tickXCount = x+1; |
|
98 | 98 | |
|
99 | 99 | domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount); |
|
100 | 100 | } |
|
101 | 101 | |
|
102 | 102 | |
|
103 | 103 | Chart* QBarSeriesPrivate::createGraphics(ChartPresenter* presenter) |
|
104 | 104 | { |
|
105 | 105 | Q_Q(QBarSeries); |
|
106 | 106 | |
|
107 | 107 | BarChartItem* bar = new BarChartItem(q,presenter); |
|
108 | 108 | if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { |
|
109 | 109 | bar->setAnimator(presenter->animator()); |
|
110 | 110 | bar->setAnimation(new BarAnimation(bar)); |
|
111 | 111 | } |
|
112 | 112 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); |
|
113 | 113 | return bar; |
|
114 | 114 | } |
|
115 | 115 | |
|
116 | QAbstractAxis::AxisType QBarSeriesPrivate::defaultAxisXType() const | |
|
117 | { | |
|
118 | return QAbstractAxis::AxisTypeCategories; | |
|
119 | } | |
|
120 | ||
|
121 | QAbstractAxis::AxisType QBarSeriesPrivate::defaultAxisYType() const | |
|
122 | { | |
|
123 | return QAbstractAxis::AxisTypeValues; | |
|
124 | } | |
|
125 | ||
|
116 | 126 | #include "moc_qbarseries.cpp" |
|
117 | 127 | |
|
118 | 128 | QTCOMMERCIALCHART_END_NAMESPACE |
|
119 | 129 |
@@ -1,45 +1,44 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #ifndef QBARSERIES_H |
|
22 | 22 | #define QBARSERIES_H |
|
23 | 23 | |
|
24 | #include <QStringList> | |
|
25 | 24 | #include <qabstractbarseries.h> |
|
26 | 25 | |
|
27 | 26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
28 | 27 | |
|
29 | 28 | class QBarSeriesPrivate; |
|
30 | 29 | |
|
31 | 30 | class QTCOMMERCIALCHART_EXPORT QBarSeries : public QAbstractBarSeries |
|
32 | 31 | { |
|
33 | 32 | Q_OBJECT |
|
34 | 33 | public: |
|
35 | 34 | explicit QBarSeries(QObject *parent = 0); |
|
36 | 35 | QAbstractSeries::SeriesType type() const; |
|
37 | 36 | |
|
38 | 37 | private: |
|
39 | 38 | Q_DECLARE_PRIVATE(QBarSeries) |
|
40 | 39 | Q_DISABLE_COPY(QBarSeries) |
|
41 | 40 | }; |
|
42 | 41 | |
|
43 | 42 | QTCOMMERCIALCHART_END_NAMESPACE |
|
44 | 43 | |
|
45 | 44 | #endif // QBARSERIES_H |
@@ -1,52 +1,55 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | // W A R N I N G |
|
22 | 22 | // ------------- |
|
23 | 23 | // |
|
24 | 24 | // This file is not part of the QtCommercial Chart API. It exists purely as an |
|
25 | 25 | // implementation detail. This header file may change from version to |
|
26 | 26 | // version without notice, or even be removed. |
|
27 | 27 | // |
|
28 | 28 | // We mean it. |
|
29 | 29 | |
|
30 | 30 | #ifndef QBARSERIES_P_H |
|
31 | 31 | #define QBARSERIES_P_H |
|
32 | 32 | |
|
33 | 33 | #include "qabstractbarseries_p.h" |
|
34 | 34 | #include "domain_p.h" |
|
35 | 35 | |
|
36 | 36 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
37 | 37 | |
|
38 | 38 | |
|
39 | 39 | class QBarSeriesPrivate: public QAbstractBarSeriesPrivate |
|
40 | 40 | { |
|
41 | 41 | public: |
|
42 | 42 | QBarSeriesPrivate(QBarSeries* q); |
|
43 | 43 | Chart* createGraphics(ChartPresenter* presenter); |
|
44 | 44 | void scaleDomain(Domain& domain); |
|
45 | 45 | |
|
46 | QAbstractAxis::AxisType defaultAxisXType() const; | |
|
47 | QAbstractAxis::AxisType defaultAxisYType() const; | |
|
48 | ||
|
46 | 49 | private: |
|
47 | 50 | Q_DECLARE_PUBLIC(QBarSeries) |
|
48 | 51 | }; |
|
49 | 52 | |
|
50 | 53 | QTCOMMERCIALCHART_END_NAMESPACE |
|
51 | 54 | |
|
52 | 55 | #endif // QBARSERIES_P_H |
@@ -1,627 +1,635 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #include "qbarset.h" |
|
22 | 22 | #include "qbarset_p.h" |
|
23 | 23 | |
|
24 | 24 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
25 | 25 | |
|
26 | 26 | /*! |
|
27 | 27 | \class QBarSet |
|
28 | 28 | \brief Building block for different bar charts |
|
29 | 29 | |
|
30 | 30 | QBarSet represents one set of bars. Set of bars contains one data value for each category. |
|
31 | 31 | First value of set is assumed to belong to first category, second to second category and so on. |
|
32 | 32 | If set has fewer values than there are categories, then the missing values are assumed to be |
|
33 | 33 | at the end of set. For missing values in middle of a set, numerical value of zero is used. |
|
34 | 34 | |
|
35 | 35 | \mainclass |
|
36 | 36 | |
|
37 | 37 | \sa QAbstractBarSeries, QBarSeries, QStackedBarSeries, QPercentBarSeries |
|
38 | 38 | */ |
|
39 | 39 | /*! |
|
40 | 40 | \qmlclass BarSet QBarSet |
|
41 | 41 | |
|
42 | 42 | BarSet represents one set of bars. Set of bars contains one data value for each category. |
|
43 | 43 | First value of set is assumed to belong to first category, second to second category and so on. |
|
44 | 44 | If set has fewer values than there are categories, then the missing values are assumed to be |
|
45 | 45 | at the end of set. For missing values in middle of a set, numerical value of zero is used. |
|
46 | 46 | \sa AbstractBarSeries, BarSeries, StackedBarSeries, PercentBarSeries |
|
47 | 47 | */ |
|
48 | 48 | |
|
49 | 49 | /*! |
|
50 | 50 | \property QBarSet::label |
|
51 | 51 | Defines the label of the barSet. |
|
52 | 52 | */ |
|
53 | 53 | /*! |
|
54 | 54 | \qmlproperty string BarSet::label |
|
55 | 55 | Defines the label of the barSet. |
|
56 | 56 | */ |
|
57 | 57 | |
|
58 | 58 | /*! |
|
59 | 59 | \property QBarSet::pen |
|
60 | 60 | \brief Defines the pen used by the barSet. |
|
61 | 61 | */ |
|
62 | 62 | |
|
63 | 63 | /*! |
|
64 | 64 | \property QBarSet::brush |
|
65 | 65 | \brief Defines the brush used by the barSet. |
|
66 | 66 | */ |
|
67 | 67 | |
|
68 | 68 | /*! |
|
69 | 69 | \property QBarSet::labelBrush |
|
70 | 70 | \brief Defines the brush used by the barSet's label. |
|
71 | 71 | */ |
|
72 | 72 | |
|
73 | 73 | /*! |
|
74 | 74 | \property QBarSet::labelFont |
|
75 | 75 | \brief Defines the font used by the barSet's label. |
|
76 | 76 | */ |
|
77 | 77 | |
|
78 | 78 | /*! |
|
79 | 79 | \qmlproperty Font BarSet::labelFont |
|
80 | 80 | Defines the font used by the barSet's label. |
|
81 | 81 | |
|
82 | 82 | See the \l {Font} {QML Font Element} for detailed documentation. |
|
83 | 83 | */ |
|
84 | 84 | |
|
85 | 85 | /*! |
|
86 | 86 | \property QBarSet::color |
|
87 | 87 | The fill (brush) color of the bar set. |
|
88 | 88 | */ |
|
89 | 89 | /*! |
|
90 | 90 | \qmlproperty color BarSet::color |
|
91 | 91 | The fill (brush) color of the bar set. |
|
92 | 92 | */ |
|
93 | 93 | |
|
94 | 94 | /*! |
|
95 | 95 | \property QBarSet::borderColor |
|
96 | 96 | The line (pen) color of the bar set. |
|
97 | 97 | */ |
|
98 | 98 | /*! |
|
99 | 99 | \qmlproperty color BarSet::borderColor |
|
100 | 100 | The line (pen) color of the bar set. |
|
101 | 101 | */ |
|
102 | 102 | |
|
103 | 103 | /*! |
|
104 | 104 | \property QBarSet::labelColor |
|
105 | 105 | The text (label) color of the bar set. |
|
106 | 106 | */ |
|
107 | 107 | /*! |
|
108 | 108 | \qmlproperty color BarSet::labelColor |
|
109 | 109 | The text (label) color of the bar set. |
|
110 | 110 | */ |
|
111 | 111 | |
|
112 | 112 | /*! |
|
113 | 113 | \fn void QBarSet::clicked(int index) |
|
114 | 114 | |
|
115 | 115 | The signal is emitted if the user clicks with a mouse on top of barset. |
|
116 | 116 | Clicked bar inside set is indexed by \a index |
|
117 | 117 | */ |
|
118 | 118 | |
|
119 | 119 | /*! |
|
120 | 120 | \fn void QBarSet::hovered(bool status) |
|
121 | 121 | |
|
122 | 122 | The signal is emitted if mouse is hovered on top of barset. |
|
123 | 123 | Parameter \a status is true, if mouse entered on top of barset, false if mouse left from top of barset. |
|
124 | 124 | */ |
|
125 | 125 | |
|
126 | 126 | |
|
127 | 127 | /*! |
|
128 | 128 | \fn void QBarSet::labelChanged() |
|
129 | 129 | This signal is emitted when the label of the barSet has changed. |
|
130 | 130 | \sa label |
|
131 | 131 | */ |
|
132 | 132 | /*! |
|
133 | 133 | \qmlsignal BarSet::onLabelChanged() |
|
134 | 134 | This signal is emitted when the label of the barSet has changed. |
|
135 | 135 | */ |
|
136 | 136 | |
|
137 | 137 | /*! |
|
138 | 138 | \fn void QBarSet::penChanged() |
|
139 | 139 | This signal is emitted when the pen of the barSet has changed. |
|
140 | 140 | \sa pen |
|
141 | 141 | */ |
|
142 | 142 | |
|
143 | 143 | /*! |
|
144 | 144 | \fn void QBarSet::brushChanged() |
|
145 | 145 | This signal is emitted when the brush of the barSet has changed. |
|
146 | 146 | \sa brush |
|
147 | 147 | */ |
|
148 | 148 | |
|
149 | 149 | /*! |
|
150 | 150 | \fn void QBarSet::labelBrushChanged() |
|
151 | 151 | This signal is emitted when the brush of the barSet's label has changed. |
|
152 | 152 | \sa labelBrush |
|
153 | 153 | */ |
|
154 | 154 | |
|
155 | 155 | /*! |
|
156 | 156 | \fn void QBarSet::labelFontChanged() |
|
157 | 157 | This signal is emitted when the font of the barSet's label has changed. |
|
158 | 158 | \sa labelBrush |
|
159 | 159 | */ |
|
160 | 160 | |
|
161 | 161 | /*! |
|
162 | 162 | \fn void QBarSet::colorChanged(QColor) |
|
163 | 163 | This signal is emitted when the fill (brush) color of the set has changed to \a color. |
|
164 | 164 | */ |
|
165 | 165 | /*! |
|
166 | 166 | \qmlsignal BarSet::onColorChanged(color color) |
|
167 | 167 | This signal is emitted when the fill (brush) color of the set has changed to \a color. |
|
168 | 168 | */ |
|
169 | 169 | |
|
170 | 170 | /*! |
|
171 | 171 | \fn void QBarSet::borderColorChanged(QColor) |
|
172 | 172 | This signal is emitted when the line (pen) color of the set has changed to \a color. |
|
173 | 173 | */ |
|
174 | 174 | /*! |
|
175 | 175 | \qmlsignal BarSet::onBorderColorChanged(color color) |
|
176 | 176 | This signal is emitted when the line (pen) color of the set has changed to \a color. |
|
177 | 177 | */ |
|
178 | 178 | |
|
179 | 179 | /*! |
|
180 | 180 | \fn void QBarSet::labelColorChanged(QColor) |
|
181 | 181 | This signal is emitted when the text (label) color of the set has changed to \a color. |
|
182 | 182 | */ |
|
183 | 183 | /*! |
|
184 | 184 | \qmlsignal BarSet::onLabelColorChanged(color color) |
|
185 | 185 | This signal is emitted when the text (label) color of the set has changed to \a color. |
|
186 | 186 | */ |
|
187 | 187 | |
|
188 | 188 | /*! |
|
189 | 189 | \fn void QBarSet::valuesAdded(int index, int count) |
|
190 | 190 | This signal is emitted when new values have been added to the set. |
|
191 | 191 | Parameter \a index indicates the position of the first inserted value. |
|
192 | 192 | Parameter \a count is the number of iserted values. |
|
193 | 193 | \sa append(), insert() |
|
194 | 194 | */ |
|
195 | 195 | /*! |
|
196 | 196 | \qmlsignal BarSet::onValuesAdded(int index, int count) |
|
197 | 197 | This signal is emitted when new values have been added to the set. |
|
198 | 198 | Parameter \a index indicates the position of the first inserted value. |
|
199 | 199 | Parameter \a count is the number of iserted values. |
|
200 | 200 | */ |
|
201 | 201 | |
|
202 | 202 | /*! |
|
203 | 203 | \fn void QBarSet::valuesRemoved(int index, int count) |
|
204 | 204 | This signal is emitted values have been removed from the set. |
|
205 | 205 | Parameter \a index indicates the position of the first removed value. |
|
206 | 206 | Parameter \a count is the number of removed values. |
|
207 | 207 | \sa remove() |
|
208 | 208 | */ |
|
209 | 209 | /*! |
|
210 | 210 | \qmlsignal BarSet::onValuesRemoved(int index, int count) |
|
211 | 211 | This signal is emitted values have been removed from the set. |
|
212 | 212 | Parameter \a index indicates the position of the first removed value. |
|
213 | 213 | Parameter \a count is the number of removed values. |
|
214 | 214 | */ |
|
215 | 215 | |
|
216 | 216 | /*! |
|
217 | 217 | \fn void QBarSet::valueChanged(int index) |
|
218 | 218 | This signal is emitted values the value in the set has been modified. |
|
219 | 219 | Parameter \a index indicates the position of the modified value. |
|
220 | 220 | \sa at() |
|
221 | 221 | */ |
|
222 | 222 | /*! |
|
223 | 223 | \qmlsignal BarSet::onValueChanged(int index) |
|
224 | 224 | This signal is emitted values the value in the set has been modified. |
|
225 | 225 | Parameter \a index indicates the position of the modified value. |
|
226 | 226 | */ |
|
227 | 227 | |
|
228 | 228 | /*! |
|
229 | 229 | \qmlproperty int BarSet::count |
|
230 | 230 | The count of values on the barset |
|
231 | 231 | */ |
|
232 | 232 | |
|
233 | 233 | /*! |
|
234 | 234 | \qmlproperty QVariantList BarSet::values |
|
235 | 235 | The values of the barset. You can set either a list of reals or a list of points as values. If you set a list of |
|
236 | 236 | reals as values, the values are automatically completed to points by using the index of a value as it's |
|
237 | 237 | x-coordinate. For example: |
|
238 | 238 | \code |
|
239 | 239 | myBarSet1.values = [0, 5, 1, 5]; |
|
240 | 240 | myBarSet2.values = [Qt.point(0, 1), Qt.point(1, 5), Qt.point(2.2, 4.3)]; |
|
241 | 241 | \endcode |
|
242 | 242 | */ |
|
243 | 243 | |
|
244 | 244 | /*! |
|
245 | 245 | Constructs QBarSet with a label of \a label and with parent of \a parent |
|
246 | 246 | */ |
|
247 | 247 | QBarSet::QBarSet(const QString label, QObject *parent) |
|
248 | 248 | : QObject(parent) |
|
249 | 249 | ,d_ptr(new QBarSetPrivate(label,this)) |
|
250 | 250 | { |
|
251 | 251 | } |
|
252 | 252 | |
|
253 | 253 | /*! |
|
254 | 254 | Destroys the barset |
|
255 | 255 | */ |
|
256 | 256 | QBarSet::~QBarSet() |
|
257 | 257 | { |
|
258 | 258 | // NOTE: d_ptr destroyed by QObject |
|
259 | 259 | } |
|
260 | 260 | |
|
261 | 261 | /*! |
|
262 | 262 | Sets new \a label for set. |
|
263 | 263 | */ |
|
264 | 264 | void QBarSet::setLabel(const QString label) |
|
265 | 265 | { |
|
266 | 266 | d_ptr->m_label = label; |
|
267 | 267 | emit labelChanged(); |
|
268 | 268 | } |
|
269 | 269 | |
|
270 | 270 | /*! |
|
271 | 271 | Returns label of the set. |
|
272 | 272 | */ |
|
273 | 273 | QString QBarSet::label() const |
|
274 | 274 | { |
|
275 | 275 | return d_ptr->m_label; |
|
276 | 276 | } |
|
277 | 277 | |
|
278 | 278 | /*! |
|
279 | 279 | Appends new value \a value to the end of set. |
|
280 | 280 | */ |
|
281 | 281 | void QBarSet::append(const qreal value) |
|
282 | 282 | { |
|
283 | 283 | // Convert to QPointF |
|
284 | 284 | int index = d_ptr->m_values.count(); |
|
285 | 285 | d_ptr->append(QPointF(d_ptr->m_values.count(), value)); |
|
286 | 286 | emit valuesAdded(index, 1); |
|
287 | 287 | } |
|
288 | 288 | |
|
289 | 289 | /*! |
|
290 | 290 | Appends a list of reals to set. Works like append with single real value. The \a values in list |
|
291 | 291 | are appended to end of barset |
|
292 | 292 | \sa append() |
|
293 | 293 | */ |
|
294 | 294 | void QBarSet::append(const QList<qreal> &values) |
|
295 | 295 | { |
|
296 | 296 | int index = d_ptr->m_values.count(); |
|
297 | 297 | d_ptr->append(values); |
|
298 | 298 | emit valuesAdded(index, values.count()); |
|
299 | 299 | } |
|
300 | 300 | |
|
301 | 301 | /*! |
|
302 | 302 | Convinience operator. Same as append, with real \a value. |
|
303 | 303 | \sa append() |
|
304 | 304 | */ |
|
305 | 305 | QBarSet& QBarSet::operator << (const qreal &value) |
|
306 | 306 | { |
|
307 | 307 | append(value); |
|
308 | 308 | return *this; |
|
309 | 309 | } |
|
310 | 310 | |
|
311 | 311 | /*! |
|
312 | 312 | Inserts new \a value on the \a index position. |
|
313 | 313 | The value that is currently at this postion is moved to postion index + 1 |
|
314 | 314 | \sa remove() |
|
315 | 315 | */ |
|
316 | 316 | void QBarSet::insert(const int index, const qreal value) |
|
317 | 317 | { |
|
318 | 318 | d_ptr->insert(index, value); |
|
319 | 319 | emit valuesAdded(index,1); |
|
320 | 320 | } |
|
321 | 321 | |
|
322 | 322 | /*! |
|
323 | 323 | Removes \a count number of values from the set starting at \a index. |
|
324 | 324 | \sa insert() |
|
325 | 325 | */ |
|
326 | 326 | void QBarSet::remove(const int index, const int count) |
|
327 | 327 | { |
|
328 | 328 | int removedCount = d_ptr->remove(index,count); |
|
329 | 329 | if (removedCount > 0) { |
|
330 | 330 | emit valuesRemoved(index,removedCount); |
|
331 | 331 | } |
|
332 | 332 | return; |
|
333 | 333 | } |
|
334 | 334 | |
|
335 | 335 | /*! |
|
336 | 336 | Sets a new value \a value to set, indexed by \a index |
|
337 | 337 | */ |
|
338 | 338 | void QBarSet::replace(const int index, const qreal value) |
|
339 | 339 | { |
|
340 | 340 | if (index >= 0 && index < d_ptr->m_values.count()) { |
|
341 | 341 | d_ptr->replace(index,value); |
|
342 | 342 | emit valueChanged(index); |
|
343 | 343 | } |
|
344 | 344 | } |
|
345 | 345 | |
|
346 | 346 | |
|
347 | 347 | /*! |
|
348 | 348 | Returns value of set indexed by \a index. |
|
349 | 349 | If the index is out of bounds 0.0 is returned. |
|
350 | 350 | */ |
|
351 | 351 | qreal QBarSet::at(const int index) const |
|
352 | 352 | { |
|
353 | 353 | if (index < 0 || index >= d_ptr->m_values.count()) { |
|
354 | 354 | return 0; |
|
355 | 355 | } |
|
356 | 356 | |
|
357 | 357 | return d_ptr->m_values.at(index).y(); |
|
358 | 358 | } |
|
359 | 359 | |
|
360 | 360 | /*! |
|
361 | 361 | Returns value of set indexed by \a index. |
|
362 | 362 | If the index is out of bounds 0.0 is returned. |
|
363 | 363 | */ |
|
364 | 364 | qreal QBarSet::operator [](const int index) const |
|
365 | 365 | { |
|
366 | 366 | return at(index); |
|
367 | 367 | } |
|
368 | 368 | |
|
369 | 369 | /*! |
|
370 | 370 | Returns count of values in set. |
|
371 | 371 | */ |
|
372 | 372 | int QBarSet::count() const |
|
373 | 373 | { |
|
374 | 374 | return d_ptr->m_values.count(); |
|
375 | 375 | } |
|
376 | 376 | |
|
377 | 377 | /*! |
|
378 | 378 | Returns sum of all values in barset. |
|
379 | 379 | */ |
|
380 | 380 | qreal QBarSet::sum() const |
|
381 | 381 | { |
|
382 | 382 | qreal total(0); |
|
383 | 383 | for (int i=0; i < d_ptr->m_values.count(); i++) { |
|
384 | 384 | total += d_ptr->m_values.at(i).y(); |
|
385 | 385 | } |
|
386 | 386 | return total; |
|
387 | 387 | } |
|
388 | 388 | |
|
389 | 389 | /*! |
|
390 | 390 | Sets pen for set. Bars of this set are drawn using \a pen |
|
391 | 391 | */ |
|
392 | 392 | void QBarSet::setPen(const QPen &pen) |
|
393 | 393 | { |
|
394 | 394 | if(d_ptr->m_pen!=pen){ |
|
395 | 395 | d_ptr->m_pen = pen; |
|
396 | 396 | emit d_ptr->updatedBars(); |
|
397 | 397 | emit penChanged(); |
|
398 | 398 | } |
|
399 | 399 | } |
|
400 | 400 | |
|
401 | 401 | /*! |
|
402 | 402 | Returns pen of the set. |
|
403 | 403 | */ |
|
404 | 404 | QPen QBarSet::pen() const |
|
405 | 405 | { |
|
406 | 406 | return d_ptr->m_pen; |
|
407 | 407 | } |
|
408 | 408 | |
|
409 | 409 | /*! |
|
410 | 410 | Sets brush for the set. Bars of this set are drawn using \a brush |
|
411 | 411 | */ |
|
412 | 412 | void QBarSet::setBrush(const QBrush &brush) |
|
413 | 413 | { |
|
414 | 414 | if(d_ptr->m_brush!=brush){ |
|
415 | 415 | d_ptr->m_brush = brush; |
|
416 | 416 | emit d_ptr->updatedBars(); |
|
417 | 417 | emit brushChanged(); |
|
418 | 418 | } |
|
419 | 419 | } |
|
420 | 420 | |
|
421 | 421 | /*! |
|
422 | 422 | Returns brush of the set. |
|
423 | 423 | */ |
|
424 | 424 | QBrush QBarSet::brush() const |
|
425 | 425 | { |
|
426 | 426 | return d_ptr->m_brush; |
|
427 | 427 | } |
|
428 | 428 | |
|
429 | 429 | /*! |
|
430 | 430 | Sets \a brush of the values that are drawn on top of this barset |
|
431 | 431 | */ |
|
432 | 432 | void QBarSet::setLabelBrush(const QBrush &brush) |
|
433 | 433 | { |
|
434 | 434 | if(d_ptr->m_labelBrush!=brush){ |
|
435 | 435 | d_ptr->m_labelBrush = brush; |
|
436 | 436 | emit d_ptr->updatedBars(); |
|
437 | 437 | emit labelBrushChanged(); |
|
438 | 438 | } |
|
439 | 439 | } |
|
440 | 440 | |
|
441 | 441 | /*! |
|
442 | 442 | Returns brush of the values that are drawn on top of this barset |
|
443 | 443 | */ |
|
444 | 444 | QBrush QBarSet::labelBrush() const |
|
445 | 445 | { |
|
446 | 446 | return d_ptr->m_labelBrush; |
|
447 | 447 | } |
|
448 | 448 | |
|
449 | 449 | /*! |
|
450 | 450 | Sets the \a font for values that are drawn on top of this barset |
|
451 | 451 | */ |
|
452 | 452 | void QBarSet::setLabelFont(const QFont &font) |
|
453 | 453 | { |
|
454 | 454 | if(d_ptr->m_labelFont!=font) { |
|
455 | 455 | d_ptr->m_labelFont = font; |
|
456 | 456 | emit d_ptr->updatedBars(); |
|
457 | 457 | emit labelFontChanged(); |
|
458 | 458 | } |
|
459 | 459 | |
|
460 | 460 | } |
|
461 | 461 | |
|
462 | 462 | /*! |
|
463 | 463 | Returns the pen for values that are drawn on top of this barset |
|
464 | 464 | */ |
|
465 | 465 | QFont QBarSet::labelFont() const |
|
466 | 466 | { |
|
467 | 467 | return d_ptr->m_labelFont; |
|
468 | 468 | } |
|
469 | 469 | |
|
470 | 470 | /*! |
|
471 | 471 | Returns the color of the brush of barset. |
|
472 | 472 | */ |
|
473 | 473 | QColor QBarSet::color() |
|
474 | 474 | { |
|
475 | 475 | return brush().color(); |
|
476 | 476 | } |
|
477 | 477 | |
|
478 | 478 | /*! |
|
479 | 479 | Sets the \a color of brush for this barset |
|
480 | 480 | */ |
|
481 | 481 | void QBarSet::setColor(QColor color) |
|
482 | 482 | { |
|
483 | 483 | QBrush b = brush(); |
|
484 | 484 | if (b.color() != color) { |
|
485 | 485 | b.setColor(color); |
|
486 | 486 | setBrush(b); |
|
487 | 487 | emit colorChanged(color); |
|
488 | 488 | } |
|
489 | 489 | } |
|
490 | 490 | |
|
491 | 491 | /*! |
|
492 | 492 | Returns the color of pen of this barset |
|
493 | 493 | */ |
|
494 | 494 | QColor QBarSet::borderColor() |
|
495 | 495 | { |
|
496 | 496 | return pen().color(); |
|
497 | 497 | } |
|
498 | 498 | |
|
499 | 499 | /*! |
|
500 | 500 | Sets the color of pen for this barset |
|
501 | 501 | */ |
|
502 | 502 | void QBarSet::setBorderColor(QColor color) |
|
503 | 503 | { |
|
504 | 504 | QPen p = pen(); |
|
505 | 505 | if (p.color() != color) { |
|
506 | 506 | p.setColor(color); |
|
507 | 507 | setPen(p); |
|
508 | 508 | emit borderColorChanged(color); |
|
509 | 509 | } |
|
510 | 510 | } |
|
511 | 511 | |
|
512 | 512 | /*! |
|
513 | 513 | Returns the color of labels of this barset |
|
514 | 514 | */ |
|
515 | 515 | QColor QBarSet::labelColor() |
|
516 | 516 | { |
|
517 | 517 | return labelBrush().color(); |
|
518 | 518 | } |
|
519 | 519 | |
|
520 | 520 | /*! |
|
521 | 521 | Sets the color of labels for this barset |
|
522 | 522 | */ |
|
523 | 523 | void QBarSet::setLabelColor(QColor color) |
|
524 | 524 | { |
|
525 | 525 | QBrush b = labelBrush(); |
|
526 | 526 | if (b.color() != color) { |
|
527 | 527 | b.setColor(color); |
|
528 | 528 | setLabelBrush(b); |
|
529 | 529 | emit labelColorChanged(color); |
|
530 | 530 | } |
|
531 | 531 | } |
|
532 | 532 | |
|
533 | 533 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
534 | 534 | |
|
535 | 535 | QBarSetPrivate::QBarSetPrivate(const QString label, QBarSet *parent) : QObject(parent), |
|
536 | 536 | q_ptr(parent), |
|
537 | 537 | m_label(label) |
|
538 | 538 | { |
|
539 | 539 | } |
|
540 | 540 | |
|
541 | 541 | QBarSetPrivate::~QBarSetPrivate() |
|
542 | 542 | { |
|
543 | 543 | } |
|
544 | 544 | |
|
545 | 545 | void QBarSetPrivate::append(QPointF value) |
|
546 | 546 | { |
|
547 | 547 | m_values.append(value); |
|
548 | 548 | emit restructuredBars(); |
|
549 | 549 | } |
|
550 | 550 | |
|
551 | 551 | void QBarSetPrivate::append(QList<QPointF> values) |
|
552 | 552 | { |
|
553 | 553 | for (int i=0; i<values.count(); i++) { |
|
554 | 554 | m_values.append(values.at(i)); |
|
555 | 555 | } |
|
556 | 556 | emit restructuredBars(); |
|
557 | 557 | } |
|
558 | 558 | |
|
559 | 559 | void QBarSetPrivate::append(QList<qreal> values) |
|
560 | 560 | { |
|
561 | 561 | int index = m_values.count(); |
|
562 | 562 | for (int i=0; i<values.count(); i++) { |
|
563 | 563 | m_values.append(QPointF(index,values.at(i))); |
|
564 | 564 | index++; |
|
565 | 565 | } |
|
566 | 566 | emit restructuredBars(); |
|
567 | 567 | } |
|
568 | 568 | |
|
569 | 569 | void QBarSetPrivate::insert(const int index, const qreal value) |
|
570 | 570 | { |
|
571 | 571 | m_values.insert(index, QPointF(index, value)); |
|
572 | 572 | emit restructuredBars(); |
|
573 | 573 | } |
|
574 | 574 | |
|
575 | 575 | void QBarSetPrivate::insert(const int index, const QPointF value) |
|
576 | 576 | { |
|
577 | 577 | m_values.insert(index, value); |
|
578 | 578 | emit restructuredBars(); |
|
579 | 579 | } |
|
580 | 580 | |
|
581 | 581 | int QBarSetPrivate::remove(const int index, const int count) |
|
582 | 582 | { |
|
583 | 583 | int removeCount = count; |
|
584 | 584 | |
|
585 | 585 | if ((index <0) || (m_values.count() == 0)) { |
|
586 | 586 | // Invalid index or not values in list, remove nothing. |
|
587 | 587 | return 0; |
|
588 | 588 | } else if ((index + count) > m_values.count()) { |
|
589 | 589 | // Trying to remove more items than list has. Limit amount to be removed. |
|
590 | 590 | removeCount = m_values.count() - index; |
|
591 | 591 | } |
|
592 | 592 | |
|
593 | 593 | int c = 0; |
|
594 | 594 | while (c < removeCount) { |
|
595 | 595 | m_values.removeAt(index); |
|
596 | 596 | c++; |
|
597 | 597 | } |
|
598 | 598 | emit restructuredBars(); |
|
599 | 599 | return removeCount; |
|
600 | 600 | } |
|
601 | 601 | |
|
602 | 602 | void QBarSetPrivate::replace(const int index, const qreal value) |
|
603 | 603 | { |
|
604 | 604 | m_values.replace(index,QPointF(index,value)); |
|
605 | 605 | emit updatedBars(); |
|
606 | 606 | } |
|
607 | 607 | |
|
608 | 608 | void QBarSetPrivate::replace(const int index, const QPointF value) |
|
609 | 609 | { |
|
610 | 610 | m_values.replace(index,value); |
|
611 | 611 | emit updatedBars(); |
|
612 | 612 | } |
|
613 | 613 | |
|
614 |
|
|
|
614 | qreal QBarSetPrivate::pos(const int index) | |
|
615 | 615 | { |
|
616 |
|
|
|
617 |
|
|
|
618 |
|
|
|
616 | if (index < 0 || index >= m_values.count()) { | |
|
617 | return 0; | |
|
618 | } | |
|
619 | 619 | |
|
620 |
|
|
|
620 | return m_values.at(index).x(); | |
|
621 | 621 | } |
|
622 | 622 | |
|
623 | qreal QBarSetPrivate::value(const int index) | |
|
624 | { | |
|
625 | if (index < 0 || index >= m_values.count()) { | |
|
626 | return 0; | |
|
627 | } | |
|
628 | ||
|
629 | return m_values.at(index).y(); | |
|
630 | } | |
|
623 | 631 | |
|
624 | 632 | #include "moc_qbarset.cpp" |
|
625 | 633 | #include "moc_qbarset_p.cpp" |
|
626 | 634 | |
|
627 | 635 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,115 +1,116 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #ifndef QBARSET_H |
|
22 | 22 | #define QBARSET_H |
|
23 | 23 | |
|
24 | 24 | #include <qchartglobal.h> |
|
25 | 25 | #include <QPen> |
|
26 | 26 | #include <QBrush> |
|
27 | 27 | #include <QFont> |
|
28 | 28 | |
|
29 | 29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
30 | 30 | class QBarSetPrivate; |
|
31 | 31 | |
|
32 | 32 | class QTCOMMERCIALCHART_EXPORT QBarSet : public QObject |
|
33 | 33 | { |
|
34 | 34 | Q_OBJECT |
|
35 | 35 | Q_PROPERTY(QString label READ label WRITE setLabel NOTIFY labelChanged) |
|
36 | 36 | Q_PROPERTY(QPen pen READ pen WRITE setPen NOTIFY penChanged) |
|
37 | 37 | Q_PROPERTY(QBrush brush READ brush WRITE setBrush NOTIFY brushChanged) |
|
38 | 38 | Q_PROPERTY(QBrush labelBrush READ labelBrush WRITE setLabelBrush NOTIFY labelBrushChanged) |
|
39 | 39 | Q_PROPERTY(QFont labelFont READ labelFont WRITE setLabelFont NOTIFY labelFontChanged) |
|
40 | 40 | Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged) |
|
41 | 41 | Q_PROPERTY(QColor borderColor READ borderColor WRITE setBorderColor NOTIFY borderColorChanged) |
|
42 | 42 | Q_PROPERTY(QColor labelColor READ labelColor WRITE setLabelColor NOTIFY labelColorChanged) |
|
43 | 43 | |
|
44 | 44 | public: |
|
45 | 45 | explicit QBarSet(const QString label, QObject *parent = 0); |
|
46 | 46 | virtual ~QBarSet(); |
|
47 | 47 | |
|
48 | 48 | void setLabel(const QString label); |
|
49 | 49 | QString label() const; |
|
50 | 50 | |
|
51 | 51 | void append(const qreal value); |
|
52 | 52 | void append(const QList<qreal> &values); |
|
53 | 53 | |
|
54 | 54 | QBarSet& operator << (const qreal &value); |
|
55 | 55 | |
|
56 | 56 | void insert(const int index, const qreal value); |
|
57 | 57 | void remove(const int index, const int count = 1); |
|
58 | 58 | void replace(const int index, const qreal value); |
|
59 | 59 | qreal at(const int index) const; |
|
60 | 60 | qreal operator [] (const int index) const; |
|
61 | 61 | int count() const; |
|
62 | 62 | qreal sum() const; |
|
63 | 63 | |
|
64 | 64 | void setPen(const QPen &pen); |
|
65 | 65 | QPen pen() const; |
|
66 | 66 | |
|
67 | 67 | void setBrush(const QBrush &brush); |
|
68 | 68 | QBrush brush() const; |
|
69 | 69 | |
|
70 | 70 | void setLabelBrush(const QBrush &brush); |
|
71 | 71 | QBrush labelBrush() const; |
|
72 | 72 | |
|
73 | 73 | void setLabelFont(const QFont &font); |
|
74 | 74 | QFont labelFont() const; |
|
75 | 75 | |
|
76 | 76 | QColor color(); |
|
77 | 77 | void setColor(QColor color); |
|
78 | 78 | |
|
79 | 79 | QColor borderColor(); |
|
80 | 80 | void setBorderColor(QColor color); |
|
81 | 81 | |
|
82 | 82 | QColor labelColor(); |
|
83 | 83 | void setLabelColor(QColor color); |
|
84 | 84 | |
|
85 | 85 | Q_SIGNALS: |
|
86 | 86 | void clicked(int index); |
|
87 | 87 | void hovered(bool status); |
|
88 | 88 | void penChanged(); |
|
89 | 89 | void brushChanged(); |
|
90 | 90 | void labelChanged(); |
|
91 | 91 | void labelBrushChanged(); |
|
92 | 92 | void labelFontChanged(); |
|
93 | 93 | void colorChanged(QColor color); |
|
94 | 94 | void borderColorChanged(QColor color); |
|
95 | 95 | void labelColorChanged(QColor color); |
|
96 | 96 | |
|
97 | 97 | void valuesAdded(int index, int count); |
|
98 | 98 | void valuesRemoved(int index, int count); |
|
99 | 99 | void valueChanged(int index); |
|
100 | 100 | |
|
101 | 101 | private: |
|
102 | 102 | QScopedPointer<QBarSetPrivate> d_ptr; |
|
103 | 103 | Q_DISABLE_COPY(QBarSet) |
|
104 | 104 | friend class QAbstractBarSeries; |
|
105 | 105 | friend class BarLegendMarker; |
|
106 | 106 | friend class AbstractBarChartItem; |
|
107 | 107 | friend class QAbstractBarSeriesPrivate; |
|
108 | 108 | friend class StackedBarChartItem; |
|
109 | 109 | friend class PercentBarChartItem; |
|
110 | 110 | friend class BarChartItem; |
|
111 | friend class HorizontalBarChartItem; | |
|
111 | 112 | }; |
|
112 | 113 | |
|
113 | 114 | QTCOMMERCIALCHART_END_NAMESPACE |
|
114 | 115 | |
|
115 | 116 | #endif // QBARSET_H |
@@ -1,80 +1,81 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | // W A R N I N G |
|
22 | 22 | // ------------- |
|
23 | 23 | // |
|
24 | 24 | // This file is not part of the QtCommercial Chart API. It exists purely as an |
|
25 | 25 | // implementation detail. This header file may change from version to |
|
26 | 26 | // version without notice, or even be removed. |
|
27 | 27 | // |
|
28 | 28 | // We mean it. |
|
29 | 29 | |
|
30 | 30 | #ifndef QBARSET_P_H |
|
31 | 31 | #define QBARSET_P_H |
|
32 | 32 | |
|
33 | 33 | #include "qbarset.h" |
|
34 | 34 | #include <QMap> |
|
35 | 35 | #include <QPen> |
|
36 | 36 | #include <QBrush> |
|
37 | 37 | #include <QFont> |
|
38 | 38 | |
|
39 | 39 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
40 | 40 | |
|
41 | 41 | class QBarSetPrivate : public QObject |
|
42 | 42 | { |
|
43 | 43 | Q_OBJECT |
|
44 | 44 | |
|
45 | 45 | public: |
|
46 | 46 | QBarSetPrivate(const QString label, QBarSet *parent); |
|
47 | 47 | ~QBarSetPrivate(); |
|
48 | 48 | |
|
49 | 49 | void append(QPointF value); |
|
50 | 50 | void append(QList<QPointF> values); |
|
51 | 51 | void append(QList<qreal> values); |
|
52 | 52 | |
|
53 | 53 | void insert(const int index, const qreal value); |
|
54 | 54 | void insert(const int index, const QPointF value); |
|
55 | 55 | int remove(const int index, const int count); |
|
56 | 56 | |
|
57 | 57 | void replace(const int index, const qreal value); |
|
58 | 58 | void replace(const int index, const QPointF value); |
|
59 | 59 | |
|
60 |
|
|
|
60 | qreal pos(const int index); | |
|
61 | qreal value(const int index); | |
|
61 | 62 | |
|
62 | 63 | Q_SIGNALS: |
|
63 | 64 | void restructuredBars(); |
|
64 | 65 | void updatedBars(); |
|
65 | 66 | |
|
66 | 67 | public: |
|
67 | 68 | QBarSet * const q_ptr; |
|
68 | 69 | QString m_label; |
|
69 | 70 | QList<QPointF> m_values; |
|
70 | 71 | QPen m_pen; |
|
71 | 72 | QBrush m_brush; |
|
72 | 73 | QBrush m_labelBrush; |
|
73 | 74 | QFont m_labelFont; |
|
74 | 75 | |
|
75 | 76 | friend class QBarSet; |
|
76 | 77 | }; |
|
77 | 78 | |
|
78 | 79 | QTCOMMERCIALCHART_END_NAMESPACE |
|
79 | 80 | |
|
80 | 81 | #endif // QBARSETPRIVATE_P_H |
@@ -1,69 +1,79 | |||
|
1 | 1 | #include "qhorizontalbarseries.h" |
|
2 | 2 | #include "qhorizontalbarseries_p.h" |
|
3 | #include "horizontalbarchartitem_p.h" | |
|
4 | #include "horizontalbaranimation_p.h" | |
|
5 | ||
|
6 | #include "chartdataset_p.h" | |
|
7 | #include "charttheme_p.h" | |
|
8 | ||
|
9 | ||
|
3 | 10 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
4 | 11 | |
|
5 | 12 | QHorizontalBarSeries::QHorizontalBarSeries(QObject *parent) : |
|
6 | QAbstractBarSeries(parent) | |
|
13 | QAbstractBarSeries(*new QHorizontalBarSeriesPrivate(this), parent) | |
|
7 | 14 | { |
|
8 | 15 | } |
|
9 | 16 | |
|
10 | 17 | QAbstractSeries::SeriesType QHorizontalBarSeries::type() const |
|
11 | 18 | { |
|
12 | 19 | return QAbstractSeries::SeriesTypeHorizontalBar; |
|
13 | 20 | } |
|
14 | 21 | |
|
15 | 22 | |
|
16 | 23 | |
|
17 | 24 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
18 | 25 | |
|
19 | 26 | QHorizontalBarSeriesPrivate::QHorizontalBarSeriesPrivate(QHorizontalBarSeries *q) : QAbstractBarSeriesPrivate(q) |
|
20 | 27 | { |
|
21 | 28 | |
|
22 | 29 | } |
|
23 | 30 | |
|
24 | 31 | void QHorizontalBarSeriesPrivate::scaleDomain(Domain& domain) |
|
25 | 32 | { |
|
26 | 33 | // TODO: |
|
27 | Q_UNUSED(domain); | |
|
28 | /* | |
|
29 | 34 | qreal minX(domain.minX()); |
|
30 | 35 | qreal minY(domain.minY()); |
|
31 | 36 | qreal maxX(domain.maxX()); |
|
32 | 37 | qreal maxY(domain.maxY()); |
|
33 | 38 | int tickXCount(domain.tickXCount()); |
|
34 | 39 | int tickYCount(domain.tickYCount()); |
|
35 | 40 | |
|
36 |
qreal |
|
|
37 |
qreal |
|
|
38 |
minX = qMin(minX, |
|
|
39 |
minY = qMin(minY, |
|
|
40 |
maxX = qMax(maxX, x |
|
|
41 | maxY = qMax(maxY, y); | |
|
42 |
tick |
|
|
41 | qreal y = categoryCount(); | |
|
42 | qreal x = max(); | |
|
43 | minX = qMin(minX, x); | |
|
44 | minY = qMin(minY, -0.5); | |
|
45 | maxX = qMax(maxX, x); | |
|
46 | maxY = qMax(maxY, y -0.5); | |
|
47 | tickYCount = y+1; | |
|
43 | 48 | |
|
44 | 49 | domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount); |
|
45 | */ | |
|
46 | 50 | } |
|
47 | 51 | |
|
48 | 52 | |
|
49 | 53 | Chart* QHorizontalBarSeriesPrivate::createGraphics(ChartPresenter* presenter) |
|
50 | 54 | { |
|
51 | // TODO: | |
|
52 | Q_UNUSED(presenter); | |
|
53 | return 0; | |
|
54 | /* | |
|
55 | 55 | Q_Q(QHorizontalBarSeries); |
|
56 | 56 | |
|
57 |
|
|
|
57 | HorizontalBarChartItem* bar = new HorizontalBarChartItem(q,presenter); | |
|
58 | 58 | if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { |
|
59 |
presenter->animator() |
|
|
59 | bar->setAnimator(presenter->animator()); | |
|
60 | bar->setAnimation(new HorizontalBarAnimation(bar)); | |
|
60 | 61 | } |
|
61 | 62 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); |
|
62 | 63 | return bar; |
|
63 | */ | |
|
64 | } | |
|
65 | ||
|
66 | QAbstractAxis::AxisType QHorizontalBarSeriesPrivate::defaultAxisXType() const | |
|
67 | { | |
|
68 | return QAbstractAxis::AxisTypeValues; | |
|
69 | } | |
|
70 | ||
|
71 | QAbstractAxis::AxisType QHorizontalBarSeriesPrivate::defaultAxisYType() const | |
|
72 | { | |
|
73 | return QAbstractAxis::AxisTypeValues; | |
|
64 | 74 | } |
|
65 | 75 | |
|
66 | 76 | |
|
67 | 77 | #include "moc_qhorizontalbarseries.cpp" |
|
68 | 78 | |
|
69 | 79 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,24 +1,44 | |||
|
1 | /**************************************************************************** | |
|
2 | ** | |
|
3 | ** Copyright (C) 2012 Digia Plc | |
|
4 | ** All rights reserved. | |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
|
6 | ** | |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
|
8 | ** | |
|
9 | ** $QT_BEGIN_LICENSE$ | |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
|
13 | ** a written agreement between you and Digia. | |
|
14 | ** | |
|
15 | ** If you have questions regarding the use of this file, please use | |
|
16 | ** contact form at http://qt.digia.com | |
|
17 | ** $QT_END_LICENSE$ | |
|
18 | ** | |
|
19 | ****************************************************************************/ | |
|
20 | ||
|
1 | 21 | #ifndef QHORIZONTALBARSERIES_H |
|
2 | 22 | #define QHORIZONTALBARSERIES_H |
|
3 | 23 | |
|
4 | 24 | #include <qabstractbarseries.h> |
|
5 | 25 | |
|
6 | 26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
7 | 27 | |
|
8 | 28 | class QHorizontalBarSeriesPrivate; |
|
9 | 29 | |
|
10 | 30 | class QTCOMMERCIALCHART_EXPORT QHorizontalBarSeries : public QAbstractBarSeries |
|
11 | 31 | { |
|
12 | 32 | Q_OBJECT |
|
13 | 33 | public: |
|
14 | 34 | explicit QHorizontalBarSeries(QObject *parent = 0); |
|
15 | 35 | QAbstractSeries::SeriesType type() const; |
|
16 | 36 | |
|
17 | 37 | private: |
|
18 | 38 | Q_DECLARE_PRIVATE(QHorizontalBarSeries) |
|
19 | 39 | Q_DISABLE_COPY(QHorizontalBarSeries) |
|
20 | 40 | }; |
|
21 | 41 | |
|
22 | 42 | QTCOMMERCIALCHART_END_NAMESPACE |
|
23 | 43 | |
|
24 | 44 | #endif // QHORIZONTALBARSERIES_H |
@@ -1,51 +1,53 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | // W A R N I N G |
|
22 | 22 | // ------------- |
|
23 | 23 | // |
|
24 | 24 | // This file is not part of the QtCommercial Chart API. It exists purely as an |
|
25 | 25 | // implementation detail. This header file may change from version to |
|
26 | 26 | // version without notice, or even be removed. |
|
27 | 27 | // |
|
28 | 28 | // We mean it. |
|
29 | 29 | |
|
30 | 30 | #ifndef QHORIZONTALBARSERIES_P_H |
|
31 | 31 | #define QHORIZONTALBARSERIES_P_H |
|
32 | 32 | |
|
33 | 33 | #include "qabstractbarseries_p.h" |
|
34 | 34 | #include "domain_p.h" |
|
35 | 35 | |
|
36 | 36 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
37 | 37 | |
|
38 | 38 | class QHorizontalBarSeriesPrivate: public QAbstractBarSeriesPrivate |
|
39 | 39 | { |
|
40 | 40 | public: |
|
41 | 41 | QHorizontalBarSeriesPrivate(QHorizontalBarSeries* q); |
|
42 | 42 | Chart* createGraphics(ChartPresenter* presenter); |
|
43 | 43 | void scaleDomain(Domain& domain); |
|
44 | QAbstractAxis::AxisType defaultAxisXType() const; | |
|
45 | QAbstractAxis::AxisType defaultAxisYType() const; | |
|
44 | 46 | |
|
45 | 47 | private: |
|
46 | 48 | Q_DECLARE_PUBLIC(QHorizontalBarSeries) |
|
47 | 49 | }; |
|
48 | 50 | |
|
49 | 51 | QTCOMMERCIALCHART_END_NAMESPACE |
|
50 | 52 | |
|
51 | 53 | #endif // QHORIZONTALBARSERIES_P_H |
@@ -1,118 +1,128 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #include "qpercentbarseries.h" |
|
22 | 22 | #include "qpercentbarseries_p.h" |
|
23 | 23 | #include "percentbarchartitem_p.h" |
|
24 | 24 | #include "chartdataset_p.h" |
|
25 | 25 | #include "charttheme_p.h" |
|
26 | 26 | #include "chartanimator_p.h" |
|
27 | 27 | #include "qvaluesaxis.h" |
|
28 | 28 | #include "percentbaranimation_p.h" |
|
29 | 29 | |
|
30 | 30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
31 | 31 | |
|
32 | 32 | /*! |
|
33 | 33 | \class QPercentBarSeries |
|
34 | 34 | \brief Series for creating percent bar chart |
|
35 | 35 | \mainclass |
|
36 | 36 | |
|
37 | 37 | QPercentBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars |
|
38 | 38 | as stacks, where each bar is shown as percentage of all bars in that category. |
|
39 | 39 | QPercentBarSeries groups the data from sets to categories, which are defined by a QStringList. |
|
40 | 40 | |
|
41 | 41 | See the \l {PercentbarChart Example} {percent bar chart example} to learn how to create a percent bar chart. |
|
42 | 42 | \image examples_percentbarchart.png |
|
43 | 43 | |
|
44 | 44 | \sa QBarSet, QStackedBarSeries, QAbstractBarSeries |
|
45 | 45 | */ |
|
46 | 46 | /*! |
|
47 | 47 | \qmlclass PercentBarSeries QPercentBarSeries |
|
48 | 48 | \inherits QAbstractBarSeries |
|
49 | 49 | |
|
50 | 50 | The following QML shows how to create a simple percent bar chart: |
|
51 | 51 | \snippet ../demos/qmlchart/qml/qmlchart/View8.qml 1 |
|
52 | 52 | \beginfloatleft |
|
53 | 53 | \image demos_qmlchart8.png |
|
54 | 54 | \endfloat |
|
55 | 55 | \clearfloat |
|
56 | 56 | */ |
|
57 | 57 | |
|
58 | 58 | /*! |
|
59 | 59 | Constructs empty QPercentBarSeries. |
|
60 | 60 | QPercentBarSeries is QObject which is a child of a \a parent. |
|
61 | 61 | */ |
|
62 | 62 | QPercentBarSeries::QPercentBarSeries(QObject *parent) |
|
63 | 63 | : QAbstractBarSeries(*new QPercentBarSeriesPrivate(this), parent) |
|
64 | 64 | { |
|
65 | 65 | } |
|
66 | 66 | |
|
67 | 67 | /*! |
|
68 | 68 | Returns QChartSeries::SeriesTypePercentBar. |
|
69 | 69 | */ |
|
70 | 70 | QAbstractSeries::SeriesType QPercentBarSeries::type() const |
|
71 | 71 | { |
|
72 | 72 | return QAbstractSeries::SeriesTypePercentBar; |
|
73 | 73 | } |
|
74 | 74 | |
|
75 | 75 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
76 | 76 | |
|
77 | 77 | QPercentBarSeriesPrivate::QPercentBarSeriesPrivate(QPercentBarSeries *q) : QAbstractBarSeriesPrivate(q) |
|
78 | 78 | { |
|
79 | 79 | |
|
80 | 80 | } |
|
81 | 81 | |
|
82 | 82 | void QPercentBarSeriesPrivate::scaleDomain(Domain& domain) |
|
83 | 83 | { |
|
84 | 84 | qreal minX(domain.minX()); |
|
85 | 85 | qreal minY(domain.minY()); |
|
86 | 86 | qreal maxX(domain.maxX()); |
|
87 | 87 | qreal maxY(domain.maxY()); |
|
88 | 88 | int tickXCount(domain.tickXCount()); |
|
89 | 89 | int tickYCount(domain.tickYCount()); |
|
90 | 90 | |
|
91 | 91 | qreal x = categoryCount(); |
|
92 | 92 | minX = qMin(minX, - (qreal)0.5); |
|
93 | 93 | maxX = qMax(maxX, x - (qreal)0.5); |
|
94 | 94 | minY = 0; |
|
95 | 95 | maxY = 100; |
|
96 | 96 | tickXCount = x+1; |
|
97 | 97 | |
|
98 | 98 | domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount); |
|
99 | 99 | } |
|
100 | 100 | |
|
101 | 101 | |
|
102 | 102 | Chart* QPercentBarSeriesPrivate::createGraphics(ChartPresenter* presenter) |
|
103 | 103 | { |
|
104 | 104 | Q_Q(QPercentBarSeries); |
|
105 | 105 | |
|
106 | 106 | PercentBarChartItem* bar = new PercentBarChartItem(q,presenter); |
|
107 | 107 | if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { |
|
108 | 108 | bar->setAnimator(presenter->animator()); |
|
109 | 109 | bar->setAnimation(new PercentBarAnimation(bar)); |
|
110 | 110 | } |
|
111 | 111 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); |
|
112 | 112 | return bar; |
|
113 | 113 | } |
|
114 | 114 | |
|
115 | QAbstractAxis::AxisType QPercentBarSeriesPrivate::defaultAxisXType() const | |
|
116 | { | |
|
117 | return QAbstractAxis::AxisTypeCategories; | |
|
118 | } | |
|
119 | ||
|
120 | QAbstractAxis::AxisType QPercentBarSeriesPrivate::defaultAxisYType() const | |
|
121 | { | |
|
122 | return QAbstractAxis::AxisTypeValues; | |
|
123 | } | |
|
124 | ||
|
115 | 125 | #include "moc_qpercentbarseries.cpp" |
|
116 | 126 | |
|
117 | 127 | QTCOMMERCIALCHART_END_NAMESPACE |
|
118 | 128 |
@@ -1,51 +1,54 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | // W A R N I N G |
|
22 | 22 | // ------------- |
|
23 | 23 | // |
|
24 | 24 | // This file is not part of the QtCommercial Chart API. It exists purely as an |
|
25 | 25 | // implementation detail. This header file may change from version to |
|
26 | 26 | // version without notice, or even be removed. |
|
27 | 27 | // |
|
28 | 28 | // We mean it. |
|
29 | 29 | |
|
30 | 30 | #ifndef QPERCENTBARSERIES_P_H |
|
31 | 31 | #define QPERCENTBARSERIES_P_H |
|
32 | 32 | |
|
33 | 33 | #include "qabstractbarseries_p.h" |
|
34 | 34 | #include "domain_p.h" |
|
35 | 35 | |
|
36 | 36 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
37 | 37 | |
|
38 | 38 | |
|
39 | 39 | class QPercentBarSeriesPrivate: public QAbstractBarSeriesPrivate |
|
40 | 40 | { |
|
41 | 41 | public: |
|
42 | 42 | QPercentBarSeriesPrivate(QPercentBarSeries* q); |
|
43 | 43 | void scaleDomain(Domain& domain); |
|
44 | 44 | Chart* createGraphics(ChartPresenter* presenter); |
|
45 | QAbstractAxis::AxisType defaultAxisXType() const; | |
|
46 | QAbstractAxis::AxisType defaultAxisYType() const; | |
|
47 | ||
|
45 | 48 | private: |
|
46 | 49 | Q_DECLARE_PUBLIC(QPercentBarSeries) |
|
47 | 50 | }; |
|
48 | 51 | |
|
49 | 52 | QTCOMMERCIALCHART_END_NAMESPACE |
|
50 | 53 | |
|
51 | 54 | #endif |
@@ -1,121 +1,131 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #include "qstackedbarseries.h" |
|
22 | 22 | #include "qstackedbarseries_p.h" |
|
23 | 23 | #include "stackedbarchartitem_p.h" |
|
24 | 24 | #include "chartdataset_p.h" |
|
25 | 25 | #include "charttheme_p.h" |
|
26 | 26 | #include "chartanimator_p.h" |
|
27 | 27 | #include "qvaluesaxis.h" |
|
28 | 28 | #include "stackedbaranimation_p.h" |
|
29 | 29 | |
|
30 | 30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
31 | 31 | |
|
32 | 32 | /*! |
|
33 | 33 | \class QStackedBarSeries |
|
34 | 34 | \brief Series for creating stacked bar chart |
|
35 | 35 | \mainclass |
|
36 | 36 | |
|
37 | 37 | QStackedBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars |
|
38 | 38 | as stacks, where bars in same category are stacked on top of each other. |
|
39 | 39 | QStackedBarSeries groups the data from sets to categories, which are defined by QStringList. |
|
40 | 40 | |
|
41 | 41 | See the \l {StackedbarChart Example} {stacked bar chart example} to learn how to create a stacked bar chart. |
|
42 | 42 | \image examples_stackedbarchart.png |
|
43 | 43 | |
|
44 | 44 | \sa QBarSet, QPercentBarSeries, QAbstractBarSeries |
|
45 | 45 | */ |
|
46 | 46 | |
|
47 | 47 | /*! |
|
48 | 48 | \qmlclass StackedBarSeries QStackedBarSeries |
|
49 | 49 | \inherits AbstractBarSeries |
|
50 | 50 | |
|
51 | 51 | The following QML shows how to create a simple stacked bar chart: |
|
52 | 52 | \snippet ../demos/qmlchart/qml/qmlchart/View7.qml 1 |
|
53 | 53 | \beginfloatleft |
|
54 | 54 | \image demos_qmlchart7.png |
|
55 | 55 | \endfloat |
|
56 | 56 | \clearfloat |
|
57 | 57 | */ |
|
58 | 58 | |
|
59 | 59 | /*! |
|
60 | 60 | Constructs empty QStackedBarSeries. |
|
61 | 61 | QStackedBarSeries is QObject which is a child of a \a parent. |
|
62 | 62 | */ |
|
63 | 63 | QStackedBarSeries::QStackedBarSeries(QObject *parent) |
|
64 | 64 | : QAbstractBarSeries(*new QStackedBarSeriesPrivate(this), parent) |
|
65 | 65 | { |
|
66 | 66 | } |
|
67 | 67 | |
|
68 | 68 | /*! |
|
69 | 69 | Returns QChartSeries::SeriesTypeStackedBar. |
|
70 | 70 | */ |
|
71 | 71 | QAbstractSeries::SeriesType QStackedBarSeries::type() const |
|
72 | 72 | { |
|
73 | 73 | return QAbstractSeries::SeriesTypeStackedBar; |
|
74 | 74 | } |
|
75 | 75 | |
|
76 | 76 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
77 | 77 | |
|
78 | 78 | QStackedBarSeriesPrivate::QStackedBarSeriesPrivate(QStackedBarSeries *q) : QAbstractBarSeriesPrivate(q) |
|
79 | 79 | { |
|
80 | 80 | |
|
81 | 81 | } |
|
82 | 82 | |
|
83 | 83 | void QStackedBarSeriesPrivate::scaleDomain(Domain& domain) |
|
84 | 84 | { |
|
85 | 85 | qreal minX(domain.minX()); |
|
86 | 86 | qreal minY(domain.minY()); |
|
87 | 87 | qreal maxX(domain.maxX()); |
|
88 | 88 | qreal maxY(domain.maxY()); |
|
89 | 89 | int tickXCount(domain.tickXCount()); |
|
90 | 90 | int tickYCount(domain.tickYCount()); |
|
91 | 91 | |
|
92 | 92 | qreal x = categoryCount(); |
|
93 | 93 | qreal y = maxCategorySum(); |
|
94 | 94 | minX = qMin(minX, - (qreal)0.5); |
|
95 | 95 | minY = qMin(minY, y); |
|
96 | 96 | maxX = qMax(maxX, x - (qreal)0.5); |
|
97 | 97 | maxY = qMax(maxY, y); |
|
98 | 98 | tickXCount = x+1; |
|
99 | 99 | |
|
100 | 100 | domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount); |
|
101 | 101 | } |
|
102 | 102 | |
|
103 | 103 | |
|
104 | 104 | Chart* QStackedBarSeriesPrivate::createGraphics(ChartPresenter* presenter) |
|
105 | 105 | { |
|
106 | 106 | Q_Q(QStackedBarSeries); |
|
107 | 107 | |
|
108 | 108 | StackedBarChartItem* bar = new StackedBarChartItem(q,presenter); |
|
109 | 109 | if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { |
|
110 | 110 | bar->setAnimator(presenter->animator()); |
|
111 | 111 | bar->setAnimation(new StackedBarAnimation(bar)); |
|
112 | 112 | } |
|
113 | 113 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); |
|
114 | 114 | return bar; |
|
115 | 115 | } |
|
116 | 116 | |
|
117 | QAbstractAxis::AxisType QStackedBarSeriesPrivate::defaultAxisXType() const | |
|
118 | { | |
|
119 | return QAbstractAxis::AxisTypeCategories; | |
|
120 | } | |
|
121 | ||
|
122 | QAbstractAxis::AxisType QStackedBarSeriesPrivate::defaultAxisYType() const | |
|
123 | { | |
|
124 | return QAbstractAxis::AxisTypeValues; | |
|
125 | } | |
|
126 | ||
|
117 | 127 | |
|
118 | 128 | #include "moc_qstackedbarseries.cpp" |
|
119 | 129 | |
|
120 | 130 | QTCOMMERCIALCHART_END_NAMESPACE |
|
121 | 131 |
@@ -1,52 +1,54 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | // W A R N I N G |
|
22 | 22 | // ------------- |
|
23 | 23 | // |
|
24 | 24 | // This file is not part of the QtCommercial Chart API. It exists purely as an |
|
25 | 25 | // implementation detail. This header file may change from version to |
|
26 | 26 | // version without notice, or even be removed. |
|
27 | 27 | // |
|
28 | 28 | // We mean it. |
|
29 | 29 | |
|
30 | 30 | #ifndef QSTACKEDBARSERIES_P_H |
|
31 | 31 | #define QSTACKEDBARSERIES_P_H |
|
32 | 32 | |
|
33 | 33 | #include "qabstractbarseries_p.h" |
|
34 | 34 | #include "domain_p.h" |
|
35 | 35 | |
|
36 | 36 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
37 | 37 | |
|
38 | 38 | |
|
39 | 39 | class QStackedBarSeriesPrivate: public QAbstractBarSeriesPrivate |
|
40 | 40 | { |
|
41 | 41 | public: |
|
42 | 42 | QStackedBarSeriesPrivate(QStackedBarSeries* q); |
|
43 | 43 | Chart* createGraphics(ChartPresenter* presenter); |
|
44 | 44 | void scaleDomain(Domain& domain); |
|
45 | QAbstractAxis::AxisType defaultAxisXType() const; | |
|
46 | QAbstractAxis::AxisType defaultAxisYType() const; | |
|
45 | 47 | |
|
46 | 48 | private: |
|
47 | 49 | Q_DECLARE_PUBLIC(QStackedBarSeries) |
|
48 | 50 | }; |
|
49 | 51 | |
|
50 | 52 | QTCOMMERCIALCHART_END_NAMESPACE |
|
51 | 53 | |
|
52 | 54 | #endif |
@@ -1,95 +1,95 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #include "stackedbarchartitem_p.h" |
|
22 | 22 | #include "bar_p.h" |
|
23 | 23 | #include "qbarset_p.h" |
|
24 | 24 | #include "qabstractbarseries_p.h" |
|
25 | 25 | #include "qbarset.h" |
|
26 | 26 | #include "chartanimator_p.h" |
|
27 | 27 | |
|
28 | 28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
29 | 29 | |
|
30 | 30 | StackedBarChartItem::StackedBarChartItem(QAbstractBarSeries *series, ChartPresenter *presenter) : |
|
31 | 31 | AbstractBarChartItem(series, presenter) |
|
32 | 32 | { |
|
33 | 33 | } |
|
34 | 34 | |
|
35 | 35 | QVector<QRectF> StackedBarChartItem::calculateLayout() |
|
36 | 36 | { |
|
37 | 37 | QVector<QRectF> layout; |
|
38 | 38 | // Use temporary qreals for accuracy |
|
39 | 39 | qreal categoryCount = m_series->d_func()->categoryCount(); |
|
40 | 40 | qreal setCount = m_series->count(); |
|
41 | 41 | bool barsVisible = m_series->isVisible(); |
|
42 | 42 | |
|
43 | 43 | // Domain: |
|
44 | 44 | qreal width = geometry().width(); |
|
45 | 45 | qreal height = geometry().height(); |
|
46 | 46 | qreal rangeY = m_domainMaxY - m_domainMinY; |
|
47 | 47 | qreal rangeX = m_domainMaxX - m_domainMinX; |
|
48 | 48 | qreal scaleY = (height / rangeY); |
|
49 | 49 | qreal scaleX = (width / rangeX); |
|
50 | 50 | qreal barWidth = scaleX * m_series->d_func()->barWidth(); |
|
51 | 51 | |
|
52 | 52 | int itemIndex(0); |
|
53 | 53 | for (int category = 0; category < categoryCount; category++) { |
|
54 | 54 | qreal yPos = height + rangeY * m_domainMinY + geometry().topLeft().y(); |
|
55 | 55 | for (int set=0; set < setCount; set++) { |
|
56 | 56 | QBarSetPrivate* barSet = m_series->d_func()->barsetAt(set)->d_ptr.data(); |
|
57 | 57 | |
|
58 |
qreal xPos = (barSet-> |
|
|
58 | qreal xPos = (barSet->pos(category) - m_domainMinX) * scaleX + m_rect.left() - barWidth/2; | |
|
59 | 59 | |
|
60 |
qreal barHeight = barSet-> |
|
|
60 | qreal barHeight = barSet->value(category) * scaleY; | |
|
61 | 61 | Bar* bar = m_bars.at(itemIndex); |
|
62 | 62 | bar->setPen(barSet->m_pen); |
|
63 | 63 | bar->setBrush(barSet->m_brush); |
|
64 | 64 | if (qFuzzyIsNull(barHeight)) { |
|
65 | 65 | bar->setVisible(false); |
|
66 | 66 | } else { |
|
67 | 67 | bar->setVisible(barsVisible); |
|
68 | 68 | } |
|
69 | 69 | |
|
70 | 70 | QRectF rect(xPos, yPos-barHeight, barWidth, barHeight); |
|
71 | 71 | layout.append(rect); |
|
72 | 72 | |
|
73 | 73 | QGraphicsSimpleTextItem* label = m_labels.at(itemIndex); |
|
74 | 74 | |
|
75 |
if (!qFuzzyIsNull(barSet-> |
|
|
76 |
label->setText(QString::number(barSet-> |
|
|
75 | if (!qFuzzyIsNull(barSet->value(category))) { | |
|
76 | label->setText(QString::number(barSet->value(category))); | |
|
77 | 77 | } else { |
|
78 | 78 | label->setText(QString("")); |
|
79 | 79 | } |
|
80 | 80 | |
|
81 | 81 | label->setPos(xPos + (rect.width()/2 - label->boundingRect().width()/2) |
|
82 | 82 | ,yPos - barHeight/2 - label->boundingRect().height()/2); |
|
83 | 83 | label->setFont(barSet->m_labelFont); |
|
84 | 84 | label->setBrush(barSet->m_labelBrush); |
|
85 | 85 | itemIndex++; |
|
86 | 86 | yPos -= barHeight; |
|
87 | 87 | } |
|
88 | 88 | } |
|
89 | 89 | |
|
90 | 90 | return layout; |
|
91 | 91 | } |
|
92 | 92 | |
|
93 | 93 | #include "moc_stackedbarchartitem_p.cpp" |
|
94 | 94 | |
|
95 | 95 | QTCOMMERCIALCHART_END_NAMESPACE |
General Comments 0
You need to be logged in to leave comments.
Login now