@@ -0,0 +1,8 | |||||
|
1 | !include( ../examples.pri ) { | |||
|
2 | error( "Couldn't find the examples.pri file!" ) | |||
|
3 | } | |||
|
4 | ||||
|
5 | TARGET = groupedbarchart | |||
|
6 | SOURCES += main.cpp | |||
|
7 | ||||
|
8 | !system_build:mac: QMAKE_POST_LINK += "$$MAC_POST_LINK_PREFIX $$MAC_EXAMPLES_BIN_DIR" |
@@ -0,0 +1,89 | |||||
|
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 <QGroupedBarSeries> | |||
|
25 | #include <QBarSet> | |||
|
26 | #include <QLegend> | |||
|
27 | ||||
|
28 | QTCOMMERCIALCHART_USE_NAMESPACE | |||
|
29 | ||||
|
30 | int main(int argc, char *argv[]) | |||
|
31 | { | |||
|
32 | QApplication a(argc, argv); | |||
|
33 | ||||
|
34 | //![1] | |||
|
35 | QBarCategories categories; | |||
|
36 | categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun"; | |||
|
37 | //![1] | |||
|
38 | ||||
|
39 | //![2] | |||
|
40 | QBarSet *set0 = new QBarSet("Jane"); | |||
|
41 | QBarSet *set1 = new QBarSet("John"); | |||
|
42 | QBarSet *set2 = new QBarSet("Axel"); | |||
|
43 | QBarSet *set3 = new QBarSet("Mary"); | |||
|
44 | QBarSet *set4 = new QBarSet("Samantha"); | |||
|
45 | ||||
|
46 | *set0 << 1 << 2 << 3 << 4 << 5 << 6; | |||
|
47 | *set1 << 5 << 0 << 0 << 4 << 0 << 7; | |||
|
48 | *set2 << 3 << 5 << 8 << 13 << 8 << 5; | |||
|
49 | *set3 << 5 << 6 << 7 << 3 << 4 << 5; | |||
|
50 | *set4 << 9 << 7 << 5 << 3 << 1 << 2; | |||
|
51 | //![2] | |||
|
52 | ||||
|
53 | //![3] | |||
|
54 | QGroupedBarSeries* series = new QGroupedBarSeries(); | |||
|
55 | series->setCategories(categories); | |||
|
56 | series->appendBarSet(set0); | |||
|
57 | series->appendBarSet(set1); | |||
|
58 | series->appendBarSet(set2); | |||
|
59 | series->appendBarSet(set3); | |||
|
60 | series->appendBarSet(set4); | |||
|
61 | ||||
|
62 | //![3] | |||
|
63 | ||||
|
64 | //![4] | |||
|
65 | QChart* chart = new QChart(); | |||
|
66 | chart->addSeries(series); | |||
|
67 | chart->setTitle("Simple grouped barchart example"); | |||
|
68 | //![4] | |||
|
69 | ||||
|
70 | //![5] | |||
|
71 | chart->legend()->setVisible(true); | |||
|
72 | chart->legend()->setAlignment(QLegend::AlignmentBottom); | |||
|
73 | chart->axisY()->setNiceNumbersEnabled(true); | |||
|
74 | //![5] | |||
|
75 | ||||
|
76 | //![6] | |||
|
77 | QChartView* chartView = new QChartView(chart); | |||
|
78 | chartView->setRenderHint(QPainter::Antialiasing); | |||
|
79 | //![6] | |||
|
80 | ||||
|
81 | //![7] | |||
|
82 | QMainWindow window; | |||
|
83 | window.setCentralWidget(chartView); | |||
|
84 | window.resize(400, 300); | |||
|
85 | window.show(); | |||
|
86 | //![7] | |||
|
87 | ||||
|
88 | return a.exec(); | |||
|
89 | } |
@@ -0,0 +1,87 | |||||
|
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 "groupedbarchartitem_p.h" | |||
|
22 | #include "bar_p.h" | |||
|
23 | #include "barlabel_p.h" | |||
|
24 | #include "qbarset_p.h" | |||
|
25 | #include "qbarseries_p.h" | |||
|
26 | #include "qbarset.h" | |||
|
27 | ||||
|
28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||
|
29 | ||||
|
30 | GroupedBarChartItem::GroupedBarChartItem(QBarSeries *series, ChartPresenter *presenter) : | |||
|
31 | BarChartItem(series, presenter) | |||
|
32 | { | |||
|
33 | } | |||
|
34 | ||||
|
35 | QVector<QRectF> GroupedBarChartItem::calculateLayout() | |||
|
36 | { | |||
|
37 | QVector<QRectF> layout; | |||
|
38 | ||||
|
39 | // Use temporary qreals for accurancy | |||
|
40 | qreal categoryCount = m_series->categoryCount(); | |||
|
41 | qreal setCount = m_series->barsetCount(); | |||
|
42 | ||||
|
43 | // Domain: | |||
|
44 | qreal width = geometry().width(); | |||
|
45 | qreal height = geometry().height(); | |||
|
46 | qreal range = m_domainMaxY - m_domainMinY; | |||
|
47 | qreal scale = (height / range); | |||
|
48 | qreal categoryWidth = width / categoryCount; | |||
|
49 | qreal barWidth = categoryWidth / (setCount+1); | |||
|
50 | ||||
|
51 | int itemIndex(0); | |||
|
52 | for (int category = 0; category < categoryCount; category++) { | |||
|
53 | qreal xPos = categoryWidth * category + barWidth / 2 + geometry().topLeft().x(); | |||
|
54 | qreal yPos = height + scale * m_domainMinY + geometry().topLeft().y(); | |||
|
55 | for (int set = 0; set < setCount; set++) { | |||
|
56 | QBarSet* barSet = m_series->d_func()->barsetAt(set); | |||
|
57 | ||||
|
58 | qreal barHeight = barSet->at(category).y() * scale; | |||
|
59 | Bar* bar = m_bars.at(itemIndex); | |||
|
60 | ||||
|
61 | QRectF rect(xPos, yPos - barHeight, barWidth, barHeight); | |||
|
62 | layout.append(rect); | |||
|
63 | bar->setPen(barSet->pen()); | |||
|
64 | bar->setBrush(barSet->brush()); | |||
|
65 | ||||
|
66 | BarLabel* label = m_labels.at(itemIndex); | |||
|
67 | ||||
|
68 | if (!qFuzzyIsNull(barSet->at(category).y())) { | |||
|
69 | label->setText(QString::number(barSet->at(category).y())); | |||
|
70 | } else { | |||
|
71 | label->setText(QString("")); | |||
|
72 | } | |||
|
73 | ||||
|
74 | label->setPos(xPos + (rect.width()/2 - label->boundingRect().width()/2) | |||
|
75 | ,yPos - barHeight/2 - label->boundingRect().height()/2); | |||
|
76 | label->setFont(barSet->labelFont()); | |||
|
77 | ||||
|
78 | itemIndex++; | |||
|
79 | xPos += barWidth; | |||
|
80 | } | |||
|
81 | } | |||
|
82 | return layout; | |||
|
83 | } | |||
|
84 | ||||
|
85 | #include "moc_groupedbarchartitem_p.cpp" | |||
|
86 | ||||
|
87 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -0,0 +1,47 | |||||
|
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 | #ifndef GROUPEDBARCHARTITEM_H | |||
|
22 | #define GROUPEDBARCHARTITEM_H | |||
|
23 | ||||
|
24 | #include "barchartitem_p.h" | |||
|
25 | #include "qstackedbarseries.h" | |||
|
26 | #include <QGraphicsItem> | |||
|
27 | ||||
|
28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||
|
29 | ||||
|
30 | class GroupedBarChartItem : public BarChartItem | |||
|
31 | { | |||
|
32 | Q_OBJECT | |||
|
33 | public: | |||
|
34 | GroupedBarChartItem(QBarSeries *series, ChartPresenter *presenter); | |||
|
35 | ||||
|
36 | private: | |||
|
37 | // From BarChartItem | |||
|
38 | virtual QVector<QRectF> calculateLayout(); | |||
|
39 | ||||
|
40 | private: | |||
|
41 | ||||
|
42 | // Data | |||
|
43 | }; | |||
|
44 | ||||
|
45 | QTCOMMERCIALCHART_END_NAMESPACE | |||
|
46 | ||||
|
47 | #endif // GROUPEDBARCHARTITEM_H |
@@ -0,0 +1,108 | |||||
|
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 "qgroupedbarseries.h" | |||
|
22 | #include "qgroupedbarseries_p.h" | |||
|
23 | #include "groupedbarchartitem_p.h" | |||
|
24 | #include "chartdataset_p.h" | |||
|
25 | #include "charttheme_p.h" | |||
|
26 | #include "chartanimator_p.h" | |||
|
27 | ||||
|
28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||
|
29 | ||||
|
30 | /*! | |||
|
31 | \class QGroupedBarSeries | |||
|
32 | \brief part of QtCommercial chart API. | |||
|
33 | \mainclass | |||
|
34 | ||||
|
35 | QGroupedBarSeries represents a series of data shown as bars. All bars in same category are | |||
|
36 | grouped next to each other. One QGroupedBarSeries can contain multiple QBarSet data sets. | |||
|
37 | QGroupedBarSeries groups the data from sets to categories, which are defined by QStringList. | |||
|
38 | ||||
|
39 | See the \l {GroupedbarChart Example} {grouped bar chart example} to learn how to create a grouped bar chart. | |||
|
40 | \image examples_groupedbarchart.png | |||
|
41 | ||||
|
42 | \sa QBarSet, QPercentBarSeries, QBarSeries, QStackedBarSeries | |||
|
43 | */ | |||
|
44 | ||||
|
45 | /*! | |||
|
46 | \fn virtual QSeriesType QGroupedBarSeries::type() const | |||
|
47 | \brief Returns type of series. | |||
|
48 | \sa QSeriesType | |||
|
49 | */ | |||
|
50 | ||||
|
51 | /*! | |||
|
52 | Constructs empty QGroupedBarSeries. Parameter \a categories defines the categories for chart. | |||
|
53 | QGroupedBarSeries is QObject which is a child of a \a parent. | |||
|
54 | */ | |||
|
55 | QGroupedBarSeries::QGroupedBarSeries(QObject *parent) | |||
|
56 | : QBarSeries(*new QGroupedBarSeriesPrivate(this), parent) | |||
|
57 | { | |||
|
58 | } | |||
|
59 | ||||
|
60 | QAbstractSeries::SeriesType QGroupedBarSeries::type() const | |||
|
61 | { | |||
|
62 | return QAbstractSeries::SeriesTypeGroupedBar; | |||
|
63 | } | |||
|
64 | ||||
|
65 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
|
66 | ||||
|
67 | QGroupedBarSeriesPrivate::QGroupedBarSeriesPrivate(/*QBarCategories categories,*/ QGroupedBarSeries *q) : QBarSeriesPrivate(/*categories,*/q) | |||
|
68 | { | |||
|
69 | ||||
|
70 | } | |||
|
71 | ||||
|
72 | void QGroupedBarSeriesPrivate::scaleDomain(Domain& domain) | |||
|
73 | { | |||
|
74 | qreal minX(domain.minX()); | |||
|
75 | qreal minY(domain.minY()); | |||
|
76 | qreal maxX(domain.maxX()); | |||
|
77 | qreal maxY(domain.maxY()); | |||
|
78 | int tickXCount(domain.tickXCount()); | |||
|
79 | int tickYCount(domain.tickYCount()); | |||
|
80 | ||||
|
81 | qreal x = m_categories.count(); | |||
|
82 | qreal y = maxCategorySum(); | |||
|
83 | minX = qMin(minX, x); | |||
|
84 | minY = qMin(minY, y); | |||
|
85 | maxX = qMax(maxX, x); | |||
|
86 | maxY = qMax(maxY, y); | |||
|
87 | tickXCount = x+1; | |||
|
88 | ||||
|
89 | domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount); | |||
|
90 | } | |||
|
91 | ||||
|
92 | ||||
|
93 | Chart* QGroupedBarSeriesPrivate::createGraphics(ChartPresenter* presenter) | |||
|
94 | { | |||
|
95 | Q_Q(QGroupedBarSeries); | |||
|
96 | ||||
|
97 | GroupedBarChartItem* bar = new GroupedBarChartItem(q,presenter); | |||
|
98 | if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { | |||
|
99 | presenter->animator()->addAnimation(bar); | |||
|
100 | } | |||
|
101 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); | |||
|
102 | return bar; | |||
|
103 | } | |||
|
104 | ||||
|
105 | #include "moc_qgroupedbarseries.cpp" | |||
|
106 | ||||
|
107 | QTCOMMERCIALCHART_END_NAMESPACE | |||
|
108 |
@@ -0,0 +1,45 | |||||
|
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 | #ifndef GROUPEDBARSERIES_H | |||
|
22 | #define GROUPEDBARSERIES_H | |||
|
23 | ||||
|
24 | #include <QStringList> | |||
|
25 | #include <qbarseries.h> | |||
|
26 | ||||
|
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||
|
28 | ||||
|
29 | class QGroupedBarSeriesPrivate; | |||
|
30 | ||||
|
31 | class QTCOMMERCIALCHART_EXPORT QGroupedBarSeries : public QBarSeries | |||
|
32 | { | |||
|
33 | Q_OBJECT | |||
|
34 | public: | |||
|
35 | explicit QGroupedBarSeries(QObject *parent = 0); | |||
|
36 | QAbstractSeries::SeriesType type() const; | |||
|
37 | ||||
|
38 | private: | |||
|
39 | Q_DECLARE_PRIVATE(QGroupedBarSeries) | |||
|
40 | Q_DISABLE_COPY(QGroupedBarSeries) | |||
|
41 | }; | |||
|
42 | ||||
|
43 | QTCOMMERCIALCHART_END_NAMESPACE | |||
|
44 | ||||
|
45 | #endif // GROUPEDBARSERIES_H |
@@ -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 QGROUPEDBARSERIES_P_H | |||
|
31 | #define QGROUPEDBARSERIES_P_H | |||
|
32 | ||||
|
33 | #include "qbarseries_p.h" | |||
|
34 | #include "domain_p.h" | |||
|
35 | ||||
|
36 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||
|
37 | ||||
|
38 | ||||
|
39 | class QGroupedBarSeriesPrivate: public QBarSeriesPrivate | |||
|
40 | { | |||
|
41 | public: | |||
|
42 | QGroupedBarSeriesPrivate(QGroupedBarSeries* q); | |||
|
43 | Chart* createGraphics(ChartPresenter* presenter); | |||
|
44 | void scaleDomain(Domain& domain); | |||
|
45 | ||||
|
46 | private: | |||
|
47 | Q_DECLARE_PUBLIC(QGroupedBarSeries) | |||
|
48 | }; | |||
|
49 | ||||
|
50 | QTCOMMERCIALCHART_END_NAMESPACE | |||
|
51 | ||||
|
52 | #endif // QGROUPEDBARSERIES_P_H |
@@ -1,88 +1,89 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include <QApplication> |
|
21 | #include <QApplication> | |
22 | #include <QMainWindow> |
|
22 | #include <QMainWindow> | |
23 | #include <QChartView> |
|
23 | #include <QChartView> | |
24 | #include <QBarSeries> |
|
24 | #include <QBarSeries> | |
25 | #include <QBarSet> |
|
25 | #include <QBarSet> | |
26 | #include <QLegend> |
|
26 | #include <QLegend> | |
27 |
|
27 | |||
28 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
28 | QTCOMMERCIALCHART_USE_NAMESPACE | |
29 |
|
29 | |||
30 | int main(int argc, char *argv[]) |
|
30 | int main(int argc, char *argv[]) | |
31 | { |
|
31 | { | |
32 | QApplication a(argc, argv); |
|
32 | QApplication a(argc, argv); | |
33 |
|
33 | |||
34 | //![1] |
|
34 | //![1] | |
35 | QBarCategories categories; |
|
35 | QBarCategories categories; | |
36 | categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun"; |
|
36 | categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun"; | |
37 | //![1] |
|
37 | //![1] | |
38 |
|
38 | |||
39 | //![2] |
|
39 | //![2] | |
40 | QBarSet *set0 = new QBarSet("Jane"); |
|
40 | QBarSet *set0 = new QBarSet("Jane"); | |
41 | QBarSet *set1 = new QBarSet("John"); |
|
41 | QBarSet *set1 = new QBarSet("John"); | |
42 | QBarSet *set2 = new QBarSet("Axel"); |
|
42 | QBarSet *set2 = new QBarSet("Axel"); | |
43 | QBarSet *set3 = new QBarSet("Mary"); |
|
43 | QBarSet *set3 = new QBarSet("Mary"); | |
44 | QBarSet *set4 = new QBarSet("Samantha"); |
|
44 | QBarSet *set4 = new QBarSet("Samantha"); | |
45 |
|
45 | |||
46 | *set0 << 1 << 2 << 3 << 4 << 5 << 6; |
|
46 | *set0 << QPointF(0.0, 1) << QPointF(1.0, 2) << QPointF(2.0, 3) << QPointF(3.0, 4) << QPointF(4.0, 5) << QPointF(5.0, 6); | |
47 | *set1 << 5 << 0 << 0 << 4 << 0 << 7; |
|
47 | *set1 << QPointF(0.2, 2) << QPointF(1.2, 3) << QPointF(2.2, 4) << QPointF(3.2, 5) << QPointF(4.2, 6) << QPointF(5.2, 7); | |
48 | *set2 << 3 << 5 << 8 << 13 << 8 << 5; |
|
48 | *set2 << QPointF(0.4, 3) << QPointF(1.4, 4) << QPointF(2.4, 5) << QPointF(3.4, 6) << QPointF(4.4, 7) << QPointF(5.4, 8); | |
49 | *set3 << 5 << 6 << 7 << 3 << 4 << 5; |
|
49 | *set3 << QPointF(0.6, 4) << QPointF(1.6, 5) << QPointF(2.6, 6) << QPointF(3.6, 7) << QPointF(4.6, 8) << QPointF(5.6, 9); | |
50 | *set4 << 9 << 7 << 5 << 3 << 1 << 2; |
|
50 | *set4 << QPointF(0.8, 5) << QPointF(1.8, 6) << QPointF(2.8, 7) << QPointF(3.8, 8) << QPointF(4.8, 9) << QPointF(5.8, 10); | |
51 | //![2] |
|
51 | //![2] | |
52 |
|
52 | |||
53 | //![3] |
|
53 | //![3] | |
54 | QBarSeries* series = new QBarSeries(); |
|
54 | QBarSeries* series = new QBarSeries(); | |
55 | series->setCategories(categories); |
|
55 | series->setCategories(categories); | |
56 | series->appendBarSet(set0); |
|
56 | series->appendBarSet(set0); | |
57 | series->appendBarSet(set1); |
|
57 | series->appendBarSet(set1); | |
58 | series->appendBarSet(set2); |
|
58 | series->appendBarSet(set2); | |
59 | series->appendBarSet(set3); |
|
59 | series->appendBarSet(set3); | |
60 | series->appendBarSet(set4); |
|
60 | series->appendBarSet(set4); | |
|
61 | ||||
61 | //![3] |
|
62 | //![3] | |
62 |
|
63 | |||
63 | //![4] |
|
64 | //![4] | |
64 | QChart* chart = new QChart(); |
|
65 | QChart* chart = new QChart(); | |
65 | chart->addSeries(series); |
|
66 | chart->addSeries(series); | |
66 | chart->setTitle("Simple barchart example"); |
|
67 | chart->setTitle("Simple barchart example"); | |
67 | //![4] |
|
68 | //![4] | |
68 |
|
69 | |||
69 | //![5] |
|
70 | //![5] | |
70 | chart->legend()->setVisible(true); |
|
71 | chart->legend()->setVisible(true); | |
71 | chart->legend()->setAlignment(QLegend::AlignmentBottom); |
|
72 | chart->legend()->setAlignment(QLegend::AlignmentBottom); | |
72 | chart->axisY()->setNiceNumbersEnabled(true); |
|
73 | chart->axisY()->setNiceNumbersEnabled(true); | |
73 | //![5] |
|
74 | //![5] | |
74 |
|
75 | |||
75 | //![6] |
|
76 | //![6] | |
76 | QChartView* chartView = new QChartView(chart); |
|
77 | QChartView* chartView = new QChartView(chart); | |
77 | chartView->setRenderHint(QPainter::Antialiasing); |
|
78 | chartView->setRenderHint(QPainter::Antialiasing); | |
78 | //![6] |
|
79 | //![6] | |
79 |
|
80 | |||
80 | //![7] |
|
81 | //![7] | |
81 | QMainWindow window; |
|
82 | QMainWindow window; | |
82 | window.setCentralWidget(chartView); |
|
83 | window.setCentralWidget(chartView); | |
83 | window.resize(400, 300); |
|
84 | window.resize(400, 300); | |
84 | window.show(); |
|
85 | window.show(); | |
85 | //![7] |
|
86 | //![7] | |
86 |
|
87 | |||
87 | return a.exec(); |
|
88 | return a.exec(); | |
88 | } |
|
89 | } |
@@ -1,22 +1,23 | |||||
1 | CURRENTLY_BUILDING_COMPONENTS = "examples" |
|
1 | CURRENTLY_BUILDING_COMPONENTS = "examples" | |
2 | !include( ../config.pri ) { |
|
2 | !include( ../config.pri ) { | |
3 | error( "Couldn't find the config.pri file!" ) |
|
3 | error( "Couldn't find the config.pri file!" ) | |
4 | } |
|
4 | } | |
5 |
|
5 | |||
6 | TEMPLATE = subdirs |
|
6 | TEMPLATE = subdirs | |
7 | SUBDIRS += \ |
|
7 | SUBDIRS += \ | |
8 | areachart \ |
|
8 | areachart \ | |
9 | barchart \ |
|
9 | barchart \ | |
10 | customchart \ |
|
10 | customchart \ | |
11 | linechart \ |
|
11 | linechart \ | |
12 | percentbarchart \ |
|
12 | percentbarchart \ | |
13 | piechart \ |
|
13 | piechart \ | |
14 | piechartdrilldown \ |
|
14 | piechartdrilldown \ | |
15 | presenterchart \ |
|
15 | presenterchart \ | |
16 | scatterchart \ |
|
16 | scatterchart \ | |
17 | scatterinteractions \ |
|
17 | scatterinteractions \ | |
18 | splinechart \ |
|
18 | splinechart \ | |
19 | stackedbarchart \ |
|
19 | stackedbarchart \ | |
20 | stackedbarchartdrilldown \ |
|
20 | stackedbarchartdrilldown \ | |
21 | zoomlinechart \ |
|
21 | zoomlinechart \ | |
22 |
modeldata |
|
22 | modeldata \ | |
|
23 | groupedbarchart |
@@ -1,31 +1,36 | |||||
1 | INCLUDEPATH += $$PWD |
|
1 | INCLUDEPATH += $$PWD | |
2 | DEPENDPATH += $$PWD |
|
2 | DEPENDPATH += $$PWD | |
3 |
|
3 | |||
4 | SOURCES += \ |
|
4 | SOURCES += \ | |
5 | $$PWD/bar.cpp \ |
|
5 | $$PWD/bar.cpp \ | |
6 | $$PWD/barchartitem.cpp \ |
|
6 | $$PWD/barchartitem.cpp \ | |
7 | $$PWD/percentbarchartitem.cpp \ |
|
7 | $$PWD/percentbarchartitem.cpp \ | |
|
8 | $$PWD/groupedbarchartitem.cpp \ | |||
8 | $$PWD/qbarseries.cpp \ |
|
9 | $$PWD/qbarseries.cpp \ | |
9 | $$PWD/qbarset.cpp \ |
|
10 | $$PWD/qbarset.cpp \ | |
10 | $$PWD/qpercentbarseries.cpp \ |
|
11 | $$PWD/qpercentbarseries.cpp \ | |
11 | $$PWD/qstackedbarseries.cpp \ |
|
12 | $$PWD/qstackedbarseries.cpp \ | |
|
13 | $$PWD/qgroupedbarseries.cpp \ | |||
12 | $$PWD/stackedbarchartitem.cpp \ |
|
14 | $$PWD/stackedbarchartitem.cpp \ | |
13 | $$PWD/barlabel.cpp |
|
15 | $$PWD/barlabel.cpp \ | |
14 |
|
16 | |||
15 | PRIVATE_HEADERS += \ |
|
17 | PRIVATE_HEADERS += \ | |
16 | $$PWD/bar_p.h \ |
|
18 | $$PWD/bar_p.h \ | |
17 | $$PWD/barchartitem_p.h \ |
|
19 | $$PWD/barchartitem_p.h \ | |
18 | $$PWD/percentbarchartitem_p.h \ |
|
20 | $$PWD/percentbarchartitem_p.h \ | |
19 | $$PWD/stackedbarchartitem_p.h \ |
|
21 | $$PWD/stackedbarchartitem_p.h \ | |
|
22 | $$PWD/groupedbarchartitem_p.h \ | |||
20 | $$PWD/barlabel_p.h \ |
|
23 | $$PWD/barlabel_p.h \ | |
21 | $$PWD/qbarset_p.h \ |
|
24 | $$PWD/qbarset_p.h \ | |
22 | $$PWD/qbarseries_p.h \ |
|
25 | $$PWD/qbarseries_p.h \ | |
23 | $$PWD/qstackedbarseries_p.h\ |
|
26 | $$PWD/qstackedbarseries_p.h\ | |
24 | $$PWD/qpercentbarseries_p.h |
|
27 | $$PWD/qpercentbarseries_p.h \ | |
|
28 | $$PWD/qgroupedbarseries_p.h \ | |||
25 |
|
29 | |||
26 | PUBLIC_HEADERS += \ |
|
30 | PUBLIC_HEADERS += \ | |
27 | $$PWD/qbarseries.h \ |
|
31 | $$PWD/qbarseries.h \ | |
28 | $$PWD/qbarset.h \ |
|
32 | $$PWD/qbarset.h \ | |
29 | $$PWD/qpercentbarseries.h \ |
|
33 | $$PWD/qpercentbarseries.h \ | |
30 | $$PWD/qstackedbarseries.h |
|
34 | $$PWD/qstackedbarseries.h \ | |
|
35 | $$PWD/qgroupedbarseries.h | |||
31 |
|
36 |
@@ -1,208 +1,210 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "barchartitem_p.h" |
|
21 | #include "barchartitem_p.h" | |
22 | #include "bar_p.h" |
|
22 | #include "bar_p.h" | |
23 | #include "barlabel_p.h" |
|
23 | #include "barlabel_p.h" | |
24 | #include "qbarset.h" |
|
24 | #include "qbarset.h" | |
25 | #include "qbarset_p.h" |
|
25 | #include "qbarset_p.h" | |
26 | #include "qbarseries.h" |
|
26 | #include "qbarseries.h" | |
27 | #include "qbarseries_p.h" |
|
27 | #include "qbarseries_p.h" | |
28 | #include "qchart.h" |
|
28 | #include "qchart.h" | |
29 | #include "chartpresenter_p.h" |
|
29 | #include "chartpresenter_p.h" | |
30 | #include "chartanimator_p.h" |
|
30 | #include "chartanimator_p.h" | |
31 | #include "chartdataset_p.h" |
|
31 | #include "chartdataset_p.h" | |
32 | #include <QPainter> |
|
32 | #include <QPainter> | |
33 |
|
33 | |||
34 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
34 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
35 |
|
35 | |||
36 | BarChartItem::BarChartItem(QBarSeries *series, ChartPresenter *presenter) : |
|
36 | BarChartItem::BarChartItem(QBarSeries *series, ChartPresenter *presenter) : | |
37 | ChartItem(presenter), |
|
37 | ChartItem(presenter), | |
38 | m_layoutSet(false), |
|
38 | m_layoutSet(false), | |
39 | m_series(series) |
|
39 | m_series(series) | |
40 | { |
|
40 | { | |
41 | setFlag(ItemClipsChildrenToShape); |
|
41 | setFlag(ItemClipsChildrenToShape); | |
42 | connect(series->d_func(), SIGNAL(updatedBars()), this, SLOT(handleLayoutChanged())); |
|
42 | connect(series->d_func(), SIGNAL(updatedBars()), this, SLOT(handleLayoutChanged())); | |
43 | connect(series->d_func(), SIGNAL(restructuredBars()), this, SLOT(handleModelChanged())); |
|
43 | connect(series->d_func(), SIGNAL(restructuredBars()), this, SLOT(handleModelChanged())); | |
44 | setZValue(ChartPresenter::BarSeriesZValue); |
|
44 | setZValue(ChartPresenter::BarSeriesZValue); | |
45 | dataChanged(); |
|
45 | dataChanged(); | |
46 | } |
|
46 | } | |
47 |
|
47 | |||
48 | BarChartItem::~BarChartItem() |
|
48 | BarChartItem::~BarChartItem() | |
49 | { |
|
49 | { | |
50 | } |
|
50 | } | |
51 |
|
51 | |||
52 | void BarChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
52 | void BarChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) | |
53 | { |
|
53 | { | |
54 | Q_UNUSED(painter); |
|
54 | Q_UNUSED(painter); | |
55 | Q_UNUSED(option); |
|
55 | Q_UNUSED(option); | |
56 | Q_UNUSED(widget); |
|
56 | Q_UNUSED(widget); | |
57 | } |
|
57 | } | |
58 |
|
58 | |||
59 | QRectF BarChartItem::boundingRect() const |
|
59 | QRectF BarChartItem::boundingRect() const | |
60 | { |
|
60 | { | |
61 | return m_rect; |
|
61 | return m_rect; | |
62 | } |
|
62 | } | |
63 |
|
63 | |||
64 | void BarChartItem::dataChanged() |
|
64 | void BarChartItem::dataChanged() | |
65 | { |
|
65 | { | |
66 | foreach(QGraphicsItem *item, childItems()) { |
|
66 | foreach(QGraphicsItem *item, childItems()) { | |
67 | delete item; |
|
67 | delete item; | |
68 | } |
|
68 | } | |
69 |
|
69 | |||
70 | m_bars.clear(); |
|
70 | m_bars.clear(); | |
71 | m_labels.clear(); |
|
71 | m_labels.clear(); | |
72 | m_layout.clear(); |
|
72 | m_layout.clear(); | |
73 |
|
73 | |||
74 | // Create new graphic items for bars |
|
74 | // Create new graphic items for bars | |
75 | for (int c = 0; c < m_series->categoryCount(); c++) { |
|
75 | for (int c = 0; c < m_series->categoryCount(); c++) { | |
76 | QString category = m_series->d_func()->categoryName(c); |
|
76 | QString category = m_series->d_func()->categoryName(c); | |
77 | for (int s = 0; s < m_series->barsetCount(); s++) { |
|
77 | for (int s = 0; s < m_series->barsetCount(); s++) { | |
78 | QBarSet *set = m_series->d_func()->barsetAt(s); |
|
78 | QBarSet *set = m_series->d_func()->barsetAt(s); | |
79 | Bar *bar = new Bar(set,category,this); |
|
79 | Bar *bar = new Bar(set,category,this); | |
80 | m_bars.append(bar); |
|
80 | m_bars.append(bar); | |
81 | connect(bar, SIGNAL(clicked(QString)), set, SIGNAL(clicked(QString))); |
|
81 | connect(bar, SIGNAL(clicked(QString)), set, SIGNAL(clicked(QString))); | |
82 | connect(bar, SIGNAL(clicked(QBarSet*,QString)), m_series, SIGNAL(clicked(QBarSet*,QString))); |
|
82 | connect(bar, SIGNAL(clicked(QBarSet*,QString)), m_series, SIGNAL(clicked(QBarSet*,QString))); | |
83 | connect(bar, SIGNAL(hovered(bool)), set, SIGNAL(hovered(bool))); |
|
83 | connect(bar, SIGNAL(hovered(bool)), set, SIGNAL(hovered(bool))); | |
84 | connect(bar, SIGNAL(hovered(QBarSet*,bool)), m_series, SIGNAL(hovered(QBarSet*,bool))); |
|
84 | connect(bar, SIGNAL(hovered(QBarSet*,bool)), m_series, SIGNAL(hovered(QBarSet*,bool))); | |
85 | m_layout.append(QRectF(0, 0, 0, 0)); |
|
85 | m_layout.append(QRectF(0, 0, 0, 0)); | |
86 | } |
|
86 | } | |
87 | } |
|
87 | } | |
88 |
|
88 | |||
89 | // Create labels |
|
89 | // Create labels | |
90 | for (int category = 0; category < m_series->categoryCount(); category++) { |
|
90 | for (int category = 0; category < m_series->categoryCount(); category++) { | |
91 | for (int s = 0; s < m_series->barsetCount(); s++) { |
|
91 | for (int s = 0; s < m_series->barsetCount(); s++) { | |
92 | QBarSet *set = m_series->d_func()->barsetAt(s); |
|
92 | QBarSet *set = m_series->d_func()->barsetAt(s); | |
93 | BarLabel *value = new BarLabel(*set, this); |
|
93 | BarLabel *value = new BarLabel(*set, this); | |
94 | m_labels.append(value); |
|
94 | m_labels.append(value); | |
95 | connect(set->d_ptr.data(),SIGNAL(labelsVisibleChanged(bool)),value,SLOT(labelsVisibleChanged(bool))); |
|
95 | connect(set->d_ptr.data(),SIGNAL(labelsVisibleChanged(bool)),value,SLOT(labelsVisibleChanged(bool))); | |
96 | } |
|
96 | } | |
97 | } |
|
97 | } | |
98 |
|
98 | |||
99 | // TODO: Is this the right place to call it? |
|
99 | // TODO: Is this the right place to call it? | |
100 | // presenter()->chartTheme()->decorate(m_series, presenter()->dataSet()->seriesIndex(m_series)); |
|
100 | // presenter()->chartTheme()->decorate(m_series, presenter()->dataSet()->seriesIndex(m_series)); | |
101 | } |
|
101 | } | |
102 |
|
102 | |||
103 | QVector<QRectF> BarChartItem::calculateLayout() |
|
103 | QVector<QRectF> BarChartItem::calculateLayout() | |
104 | { |
|
104 | { | |
105 | QVector<QRectF> layout; |
|
105 | QVector<QRectF> layout; | |
106 |
|
106 | |||
107 | // Use temporary qreals for accurancy |
|
107 | // Use temporary qreals for accurancy | |
108 | qreal categoryCount = m_series->categoryCount(); |
|
108 | qreal categoryCount = m_series->categoryCount(); | |
109 | qreal setCount = m_series->barsetCount(); |
|
109 | qreal setCount = m_series->barsetCount(); | |
110 |
|
110 | |||
111 | // Domain: |
|
111 | // Domain: | |
112 | qreal width = geometry().width(); |
|
112 | qreal width = geometry().width(); | |
113 | qreal height = geometry().height(); |
|
113 | qreal height = geometry().height(); | |
114 | qreal range = m_domainMaxY - m_domainMinY; |
|
114 | qreal rangeY = m_domainMaxY - m_domainMinY; | |
115 | qreal scale = (height / range); |
|
115 | qreal rangeX = m_domainMaxX - m_domainMinX; | |
|
116 | qreal scaleY = (height / rangeY); | |||
|
117 | qreal scaleX = (width / rangeX); | |||
116 | qreal categoryWidth = width / categoryCount; |
|
118 | qreal categoryWidth = width / categoryCount; | |
117 |
qreal barWidth = categoryWidth |
|
119 | qreal barWidth = categoryWidth - categoryWidth * m_series->d_func()->barMargin(); | |
118 |
|
120 | |||
119 | int itemIndex(0); |
|
121 | int itemIndex(0); | |
120 | for (int category = 0; category < categoryCount; category++) { |
|
122 | for (int category = 0; category < categoryCount; category++) { | |
121 |
qreal |
|
123 | qreal yPos = height + scaleY * m_domainMinY + geometry().topLeft().y(); | |
122 | qreal yPos = height + scale * m_domainMinY + geometry().topLeft().y(); |
|
|||
123 | for (int set = 0; set < setCount; set++) { |
|
124 | for (int set = 0; set < setCount; set++) { | |
124 | QBarSet* barSet = m_series->d_func()->barsetAt(set); |
|
125 | QBarSet* barSet = m_series->d_func()->barsetAt(set); | |
|
126 | qreal xPos = (barSet->at(category).x() - m_domainMinX) * scaleX + m_rect.left() - barWidth/2; | |||
|
127 | qreal barHeight = barSet->at(category).y() * scaleY; | |||
125 |
|
128 | |||
126 | qreal barHeight = barSet->at(category) * scale; |
|
|||
127 | Bar* bar = m_bars.at(itemIndex); |
|
129 | Bar* bar = m_bars.at(itemIndex); | |
128 |
|
||||
129 | QRectF rect(xPos, yPos - barHeight, barWidth, barHeight); |
|
130 | QRectF rect(xPos, yPos - barHeight, barWidth, barHeight); | |
|
131 | ||||
130 | layout.append(rect); |
|
132 | layout.append(rect); | |
131 | bar->setPen(barSet->pen()); |
|
133 | bar->setPen(barSet->pen()); | |
132 | bar->setBrush(barSet->brush()); |
|
134 | bar->setBrush(barSet->brush()); | |
133 |
|
135 | |||
134 | BarLabel* label = m_labels.at(itemIndex); |
|
136 | BarLabel* label = m_labels.at(itemIndex); | |
135 |
|
137 | |||
136 | if (!qFuzzyIsNull(barSet->at(category))) { |
|
138 | if (!qFuzzyIsNull(barSet->at(category).y())) { | |
137 | label->setText(QString::number(barSet->at(category))); |
|
139 | label->setText(QString::number(barSet->at(category).y())); | |
138 | } else { |
|
140 | } else { | |
139 | label->setText(QString("")); |
|
141 | label->setText(QString("")); | |
140 | } |
|
142 | } | |
141 |
|
143 | |||
142 | label->setPos(xPos + (rect.width()/2 - label->boundingRect().width()/2) |
|
144 | label->setPos(xPos + (rect.width()/2 - label->boundingRect().width()/2) | |
143 | ,yPos - barHeight/2 - label->boundingRect().height()/2); |
|
145 | ,yPos - barHeight/2 - label->boundingRect().height()/2); | |
144 | label->setFont(barSet->labelFont()); |
|
146 | label->setFont(barSet->labelFont()); | |
145 |
|
147 | |||
146 | itemIndex++; |
|
148 | itemIndex++; | |
147 | xPos += barWidth; |
|
|||
148 | } |
|
149 | } | |
149 | } |
|
150 | } | |
|
151 | ||||
150 | return layout; |
|
152 | return layout; | |
151 | } |
|
153 | } | |
152 |
|
154 | |||
153 | void BarChartItem::applyLayout(const QVector<QRectF> &layout) |
|
155 | void BarChartItem::applyLayout(const QVector<QRectF> &layout) | |
154 | { |
|
156 | { | |
155 | if (animator()) |
|
157 | if (animator()) | |
156 | animator()->updateLayout(this, m_layout, layout); |
|
158 | animator()->updateLayout(this, m_layout, layout); | |
157 | else |
|
159 | else | |
158 | setLayout(layout); |
|
160 | setLayout(layout); | |
159 | } |
|
161 | } | |
160 |
|
162 | |||
161 | void BarChartItem::setLayout(const QVector<QRectF> &layout) |
|
163 | void BarChartItem::setLayout(const QVector<QRectF> &layout) | |
162 | { |
|
164 | { | |
163 | m_layout = layout; |
|
165 | m_layout = layout; | |
164 |
|
166 | |||
165 | for (int i=0; i < m_bars.count(); i++) |
|
167 | for (int i=0; i < m_bars.count(); i++) | |
166 | m_bars.at(i)->setRect(layout.at(i)); |
|
168 | m_bars.at(i)->setRect(layout.at(i)); | |
167 |
|
169 | |||
168 | update(); |
|
170 | update(); | |
169 | } |
|
171 | } | |
170 | //handlers |
|
172 | //handlers | |
171 |
|
173 | |||
172 | void BarChartItem::handleModelChanged() |
|
174 | void BarChartItem::handleModelChanged() | |
173 | { |
|
175 | { | |
174 | // dataChanged(); |
|
176 | // dataChanged(); | |
175 | presenter()->resetAllElements(); |
|
177 | presenter()->resetAllElements(); | |
176 | } |
|
178 | } | |
177 |
|
179 | |||
178 | void BarChartItem::handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY) |
|
180 | void BarChartItem::handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY) | |
179 | { |
|
181 | { | |
180 | m_domainMinX = minX; |
|
182 | m_domainMinX = minX; | |
181 | m_domainMaxX = maxX; |
|
183 | m_domainMaxX = maxX; | |
182 | m_domainMinY = minY; |
|
184 | m_domainMinY = minY; | |
183 | m_domainMaxY = maxY; |
|
185 | m_domainMaxY = maxY; | |
184 | handleLayoutChanged(); |
|
186 | handleLayoutChanged(); | |
185 | } |
|
187 | } | |
186 |
|
188 | |||
187 | void BarChartItem::handleGeometryChanged(const QRectF &rect) |
|
189 | void BarChartItem::handleGeometryChanged(const QRectF &rect) | |
188 | { |
|
190 | { | |
189 | prepareGeometryChange(); |
|
191 | prepareGeometryChange(); | |
190 | m_rect = rect; |
|
192 | m_rect = rect; | |
191 | handleLayoutChanged(); |
|
193 | handleLayoutChanged(); | |
192 | m_layoutSet = true; |
|
194 | m_layoutSet = true; | |
193 | } |
|
195 | } | |
194 |
|
196 | |||
195 | void BarChartItem::handleLayoutChanged() |
|
197 | void BarChartItem::handleLayoutChanged() | |
196 | { |
|
198 | { | |
197 | if ((m_rect.width() <= 0) || (m_rect.height() <= 0)) { |
|
199 | if ((m_rect.width() <= 0) || (m_rect.height() <= 0)) { | |
198 | // rect size zero. |
|
200 | // rect size zero. | |
199 | return; |
|
201 | return; | |
200 | } |
|
202 | } | |
201 | QVector<QRectF> layout = calculateLayout(); |
|
203 | QVector<QRectF> layout = calculateLayout(); | |
202 | applyLayout(layout); |
|
204 | applyLayout(layout); | |
203 | update(); |
|
205 | update(); | |
204 | } |
|
206 | } | |
205 |
|
207 | |||
206 | #include "moc_barchartitem_p.cpp" |
|
208 | #include "moc_barchartitem_p.cpp" | |
207 |
|
209 | |||
208 | QTCOMMERCIALCHART_END_NAMESPACE |
|
210 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,90 +1,90 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "percentbarchartitem_p.h" |
|
21 | #include "percentbarchartitem_p.h" | |
22 | #include "bar_p.h" |
|
22 | #include "bar_p.h" | |
23 | #include "barlabel_p.h" |
|
23 | #include "barlabel_p.h" | |
24 | #include "qbarseries_p.h" |
|
24 | #include "qbarseries_p.h" | |
25 | #include "qbarset.h" |
|
25 | #include "qbarset.h" | |
26 | #include <QDebug> |
|
26 | #include <QDebug> | |
27 |
|
27 | |||
28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
29 |
|
29 | |||
30 | PercentBarChartItem::PercentBarChartItem(QBarSeries *series, ChartPresenter *presenter) : |
|
30 | PercentBarChartItem::PercentBarChartItem(QBarSeries *series, ChartPresenter *presenter) : | |
31 | BarChartItem(series, presenter) |
|
31 | BarChartItem(series, presenter) | |
32 | { |
|
32 | { | |
33 | } |
|
33 | } | |
34 |
|
34 | |||
35 | QVector<QRectF> PercentBarChartItem::calculateLayout() |
|
35 | QVector<QRectF> PercentBarChartItem::calculateLayout() | |
36 | { |
|
36 | { | |
37 | QVector<QRectF> layout; |
|
37 | QVector<QRectF> layout; | |
38 |
|
38 | |||
39 | // Use temporary qreals for accurancy |
|
39 | // Use temporary qreals for accurancy | |
40 | qreal width = geometry().width(); |
|
40 | qreal width = geometry().width(); | |
41 | qreal height = geometry().height(); |
|
41 | qreal height = geometry().height(); | |
42 |
|
42 | |||
43 | qreal categoryCount = m_series->categoryCount(); |
|
43 | qreal categoryCount = m_series->categoryCount(); | |
44 | qreal barWidth = width / (m_series->categoryCount() * 2); |
|
44 | qreal barWidth = width / (m_series->categoryCount() * 2); | |
45 | qreal xStep = width / categoryCount; |
|
45 | qreal xStep = width / categoryCount; | |
46 | qreal xPos = xStep / 2 - barWidth / 2 + geometry().topLeft().x(); |
|
46 | qreal xPos = xStep / 2 - barWidth / 2 + geometry().topLeft().x(); | |
47 |
|
47 | |||
48 | qreal range = m_domainMaxY - m_domainMinY; |
|
48 | qreal range = m_domainMaxY - m_domainMinY; | |
49 | qreal domainScale = (height / range); |
|
49 | qreal domainScale = (height / range); | |
50 |
|
50 | |||
51 | int itemIndex(0); |
|
51 | int itemIndex(0); | |
52 | for (int category = 0; category < categoryCount; category++) { |
|
52 | for (int category = 0; category < categoryCount; category++) { | |
53 | qreal colSum = m_series->d_func()->categorySum(category); |
|
53 | qreal colSum = m_series->d_func()->categorySum(category); | |
54 | qreal percentage = (100 / colSum); |
|
54 | qreal percentage = (100 / colSum); | |
55 | qreal yPos = height + domainScale * m_domainMinY + geometry().topLeft().y(); |
|
55 | qreal yPos = height + domainScale * m_domainMinY + geometry().topLeft().y(); | |
56 | for (int set=0; set < m_series->barsetCount(); set++) { |
|
56 | for (int set=0; set < m_series->barsetCount(); set++) { | |
57 | QBarSet* barSet = m_series->d_func()->barsetAt(set); |
|
57 | QBarSet* barSet = m_series->d_func()->barsetAt(set); | |
58 | qreal barHeight = barSet->at(category) * percentage * domainScale; |
|
58 | qreal barHeight = barSet->at(category).y() * percentage * domainScale; | |
59 | Bar* bar = m_bars.at(itemIndex); |
|
59 | Bar* bar = m_bars.at(itemIndex); | |
60 | bar->setPen(barSet->pen()); |
|
60 | bar->setPen(barSet->pen()); | |
61 | bar->setBrush(barSet->brush()); |
|
61 | bar->setBrush(barSet->brush()); | |
62 | QRectF rect(xPos, yPos-barHeight, barWidth, barHeight); |
|
62 | QRectF rect(xPos, yPos-barHeight, barWidth, barHeight); | |
63 | layout.append(rect); |
|
63 | layout.append(rect); | |
64 |
|
64 | |||
65 | BarLabel* label = m_labels.at(itemIndex); |
|
65 | BarLabel* label = m_labels.at(itemIndex); | |
66 |
|
66 | |||
67 | if (!qFuzzyIsNull(m_series->d_func()->valueAt(set,category))) { |
|
67 | if (!qFuzzyIsNull(m_series->d_func()->valueAt(set,category))) { | |
68 | int p = m_series->d_func()->percentageAt(set,category) * 100; |
|
68 | int p = m_series->d_func()->percentageAt(set,category) * 100; | |
69 | QString vString(QString::number(p)); |
|
69 | QString vString(QString::number(p)); | |
70 | vString.truncate(3); |
|
70 | vString.truncate(3); | |
71 | vString.append("%"); |
|
71 | vString.append("%"); | |
72 | label->setText(vString); |
|
72 | label->setText(vString); | |
73 | } else { |
|
73 | } else { | |
74 | label->setText(QString("")); |
|
74 | label->setText(QString("")); | |
75 | } |
|
75 | } | |
76 |
|
76 | |||
77 | label->setPos(xPos + (rect.width()/2 - label->boundingRect().width()/2) |
|
77 | label->setPos(xPos + (rect.width()/2 - label->boundingRect().width()/2) | |
78 | ,yPos - barHeight/2 - label->boundingRect().height()/2); |
|
78 | ,yPos - barHeight/2 - label->boundingRect().height()/2); | |
79 | label->setFont(barSet->labelFont()); |
|
79 | label->setFont(barSet->labelFont()); | |
80 | itemIndex++; |
|
80 | itemIndex++; | |
81 | yPos -= barHeight; |
|
81 | yPos -= barHeight; | |
82 | } |
|
82 | } | |
83 | xPos += xStep; |
|
83 | xPos += xStep; | |
84 | } |
|
84 | } | |
85 | return layout; |
|
85 | return layout; | |
86 | } |
|
86 | } | |
87 |
|
87 | |||
88 | #include "moc_percentbarchartitem_p.cpp" |
|
88 | #include "moc_percentbarchartitem_p.cpp" | |
89 |
|
89 | |||
90 | QTCOMMERCIALCHART_END_NAMESPACE |
|
90 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,702 +1,718 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "qbarseries.h" |
|
21 | #include "qbarseries.h" | |
22 | #include "qbarseries_p.h" |
|
22 | #include "qbarseries_p.h" | |
23 | #include "qbarset.h" |
|
23 | #include "qbarset.h" | |
24 | #include "qbarset_p.h" |
|
24 | #include "qbarset_p.h" | |
25 | #include "domain_p.h" |
|
25 | #include "domain_p.h" | |
26 | #include "legendmarker_p.h" |
|
26 | #include "legendmarker_p.h" | |
27 | #include "chartdataset_p.h" |
|
27 | #include "chartdataset_p.h" | |
28 | #include "charttheme_p.h" |
|
28 | #include "charttheme_p.h" | |
29 | #include "chartanimator_p.h" |
|
29 | #include "chartanimator_p.h" | |
30 |
|
30 | |||
31 | #include <QAbstractItemModel> |
|
31 | #include <QAbstractItemModel> | |
32 | #include <QModelIndex> |
|
32 | #include <QModelIndex> | |
33 |
|
33 | |||
34 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
34 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
35 |
|
35 | |||
36 | /*! |
|
36 | /*! | |
37 | \class QBarSeries |
|
37 | \class QBarSeries | |
38 | \brief part of QtCommercial chart API. |
|
38 | \brief part of QtCommercial chart API. | |
39 | \mainclass |
|
39 | \mainclass | |
40 |
|
40 | |||
41 | QBarSeries represents a series of data shown as bars. One QBarSeries can contain multiple |
|
41 | QBarSeries represents a series of data shown as bars. One QBarSeries can contain multiple | |
42 | QBarSet data sets. QBarSeries groups the data from sets to categories, which are defined |
|
42 | QBarSet data sets. QBarSeries groups the data from sets to categories, which are defined | |
43 | by QStringList. |
|
43 | by QStringList. | |
44 |
|
44 | |||
45 | See the \l {BarChart Example} {bar chart example} to learn how to create a simple bar chart. |
|
45 | See the \l {BarChart Example} {bar chart example} to learn how to create a simple bar chart. | |
46 | \image examples_barchart.png |
|
46 | \image examples_barchart.png | |
47 |
|
47 | |||
48 | \sa QBarSet, QStackedBarSeries, QPercentBarSeries |
|
48 | \sa QBarSet, QStackedBarSeries, QPercentBarSeries | |
49 | */ |
|
49 | */ | |
50 |
|
50 | |||
51 | /*! |
|
51 | /*! | |
52 | \fn void QBarSeries::clicked(QBarSet *barset, QString category) |
|
52 | \fn void QBarSeries::clicked(QBarSet *barset, QString category) | |
53 |
|
53 | |||
54 | The signal is emitted if the user clicks with a mouse on top of QBarSet \a barset of category \a category |
|
54 | The signal is emitted if the user clicks with a mouse on top of QBarSet \a barset of category \a category | |
55 | contained by the series. |
|
55 | contained by the series. | |
56 | */ |
|
56 | */ | |
57 |
|
57 | |||
58 | /*! |
|
58 | /*! | |
59 | \fn void QBarSeries::hovered(QBarSet* barset, bool status) |
|
59 | \fn void QBarSeries::hovered(QBarSet* barset, bool status) | |
60 |
|
60 | |||
61 | The signal is emitted if mouse is hovered on top of series. |
|
61 | The signal is emitted if mouse is hovered on top of series. | |
62 | Parameter \a barset is the pointer of barset, where hover happened. |
|
62 | Parameter \a barset is the pointer of barset, where hover happened. | |
63 | Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series. |
|
63 | Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series. | |
64 | */ |
|
64 | */ | |
65 |
|
65 | |||
66 | /*! |
|
66 | /*! | |
67 | Constructs empty QBarSeries. Parameter \a categories defines the categories for chart. |
|
67 | Constructs empty QBarSeries. Parameter \a categories defines the categories for chart. | |
68 | QBarSeries is QObject which is a child of a \a parent. |
|
68 | QBarSeries is QObject which is a child of a \a parent. | |
69 | */ |
|
69 | */ | |
70 | QBarSeries::QBarSeries(/*QBarCategories categories,*/ QObject *parent) : |
|
70 | QBarSeries::QBarSeries(/*QBarCategories categories,*/ QObject *parent) : | |
71 | QAbstractSeries(*new QBarSeriesPrivate(/*categories,*/ this),parent) |
|
71 | QAbstractSeries(*new QBarSeriesPrivate(/*categories,*/ this),parent) | |
72 | { |
|
72 | { | |
73 | } |
|
73 | } | |
74 |
|
74 | |||
75 | /*! |
|
75 | /*! | |
76 | Destructs barseries and owned barsets. |
|
76 | Destructs barseries and owned barsets. | |
77 | */ |
|
77 | */ | |
78 | QBarSeries::~QBarSeries() |
|
78 | QBarSeries::~QBarSeries() | |
79 | { |
|
79 | { | |
80 | // NOTE: d_ptr destroyed by QObject |
|
80 | // NOTE: d_ptr destroyed by QObject | |
81 | } |
|
81 | } | |
82 |
|
82 | |||
83 | /*! |
|
83 | /*! | |
84 | \internal |
|
84 | \internal | |
85 | */ |
|
85 | */ | |
86 | QBarSeries::QBarSeries(QBarSeriesPrivate &d, QObject *parent) : |
|
86 | QBarSeries::QBarSeries(QBarSeriesPrivate &d, QObject *parent) : | |
87 | QAbstractSeries(d,parent) |
|
87 | QAbstractSeries(d,parent) | |
88 | { |
|
88 | { | |
89 | } |
|
89 | } | |
90 |
|
90 | |||
91 | /*! |
|
91 | /*! | |
92 | Returns the type of series. Derived classes override this. |
|
92 | Returns the type of series. Derived classes override this. | |
93 | */ |
|
93 | */ | |
94 | QAbstractSeries::SeriesType QBarSeries::type() const |
|
94 | QAbstractSeries::SeriesType QBarSeries::type() const | |
95 | { |
|
95 | { | |
96 | return QAbstractSeries::SeriesTypeBar; |
|
96 | return QAbstractSeries::SeriesTypeBar; | |
97 | } |
|
97 | } | |
98 |
|
98 | |||
99 | void QBarSeries::setCategories(QBarCategories categories) |
|
99 | void QBarSeries::setCategories(QBarCategories categories) | |
100 | { |
|
100 | { | |
101 | Q_D(QBarSeries); |
|
101 | Q_D(QBarSeries); | |
102 | d->setCategories(categories); |
|
102 | d->setCategories(categories); | |
103 | emit d->categoriesUpdated(); |
|
103 | emit d->categoriesUpdated(); | |
104 | } |
|
104 | } | |
105 |
|
105 | |||
106 | /*! |
|
106 | /*! | |
107 | Adds a set of bars to series. Takes ownership of \a set. |
|
107 | Adds a set of bars to series. Takes ownership of \a set. | |
108 | */ |
|
108 | */ | |
109 | bool QBarSeries::appendBarSet(QBarSet *set) |
|
109 | bool QBarSeries::appendBarSet(QBarSet *set) | |
110 | { |
|
110 | { | |
111 | Q_D(QBarSeries); |
|
111 | Q_D(QBarSeries); | |
112 | if ((d->m_barSets.contains(set)) || (set == 0)) { |
|
112 | if ((d->m_barSets.contains(set)) || (set == 0)) { | |
113 | // Fail if set is already in list or set is null. |
|
113 | // Fail if set is already in list or set is null. | |
114 | return false; |
|
114 | return false; | |
115 | } |
|
115 | } | |
116 | d->m_barSets.append(set); |
|
116 | d->m_barSets.append(set); | |
117 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), d, SLOT(barsetChanged())); |
|
117 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), d, SLOT(barsetChanged())); | |
118 | emit d->restructuredBars(); |
|
118 | emit d->restructuredBars(); | |
119 | return true; |
|
119 | return true; | |
120 | } |
|
120 | } | |
121 |
|
121 | |||
122 | /*! |
|
122 | /*! | |
123 | Removes a set of bars from series. Releases ownership of \a set. Doesn't delete \a set. |
|
123 | Removes a set of bars from series. Releases ownership of \a set. Doesn't delete \a set. | |
124 | */ |
|
124 | */ | |
125 | bool QBarSeries::removeBarSet(QBarSet *set) |
|
125 | bool QBarSeries::removeBarSet(QBarSet *set) | |
126 | { |
|
126 | { | |
127 | Q_D(QBarSeries); |
|
127 | Q_D(QBarSeries); | |
128 | if (!d->m_barSets.contains(set)) { |
|
128 | if (!d->m_barSets.contains(set)) { | |
129 | // Fail if set is not in list |
|
129 | // Fail if set is not in list | |
130 | return false; |
|
130 | return false; | |
131 | } |
|
131 | } | |
132 | d->m_barSets.removeOne(set); |
|
132 | d->m_barSets.removeOne(set); | |
133 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), d, SLOT(barsetChanged())); |
|
133 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), d, SLOT(barsetChanged())); | |
134 | emit d->restructuredBars(); |
|
134 | emit d->restructuredBars(); | |
135 | return true; |
|
135 | return true; | |
136 | } |
|
136 | } | |
137 |
|
137 | |||
138 | /*! |
|
138 | /*! | |
139 | Adds a list of barsets to series. Takes ownership of \a sets. |
|
139 | Adds a list of barsets to series. Takes ownership of \a sets. | |
140 | */ |
|
140 | */ | |
141 | bool QBarSeries::appendBarSets(QList<QBarSet* > sets) |
|
141 | bool QBarSeries::appendBarSets(QList<QBarSet* > sets) | |
142 | { |
|
142 | { | |
143 | Q_D(QBarSeries); |
|
143 | Q_D(QBarSeries); | |
144 | foreach (QBarSet* set, sets) { |
|
144 | foreach (QBarSet* set, sets) { | |
145 | if ((set == 0) || (d->m_barSets.contains(set))) { |
|
145 | if ((set == 0) || (d->m_barSets.contains(set))) { | |
146 | // Fail if any of the sets is null or is already appended. |
|
146 | // Fail if any of the sets is null or is already appended. | |
147 | return false; |
|
147 | return false; | |
148 | } |
|
148 | } | |
149 | if (sets.count(set) != 1) { |
|
149 | if (sets.count(set) != 1) { | |
150 | // Also fail if same set is more than once in given list. |
|
150 | // Also fail if same set is more than once in given list. | |
151 | return false; |
|
151 | return false; | |
152 | } |
|
152 | } | |
153 | } |
|
153 | } | |
154 |
|
154 | |||
155 | foreach (QBarSet* set, sets) { |
|
155 | foreach (QBarSet* set, sets) { | |
156 | d->m_barSets.append(set); |
|
156 | d->m_barSets.append(set); | |
157 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), d, SLOT(barsetChanged())); |
|
157 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), d, SLOT(barsetChanged())); | |
158 | } |
|
158 | } | |
159 | emit d->restructuredBars(); |
|
159 | emit d->restructuredBars(); | |
160 | return true; |
|
160 | return true; | |
161 | } |
|
161 | } | |
162 |
|
162 | |||
163 | /*! |
|
163 | /*! | |
164 | Removes a list of barsets from series. Releases ownership of \a sets. Doesn't delete \a sets. |
|
164 | Removes a list of barsets from series. Releases ownership of \a sets. Doesn't delete \a sets. | |
165 | */ |
|
165 | */ | |
166 | bool QBarSeries::removeBarSets(QList<QBarSet* > sets) |
|
166 | bool QBarSeries::removeBarSets(QList<QBarSet* > sets) | |
167 | { |
|
167 | { | |
168 | Q_D(QBarSeries); |
|
168 | Q_D(QBarSeries); | |
169 |
|
169 | |||
170 | bool setsRemoved = false; |
|
170 | bool setsRemoved = false; | |
171 | foreach (QBarSet* set, sets) { |
|
171 | foreach (QBarSet* set, sets) { | |
172 | if (d->m_barSets.contains(set)) { |
|
172 | if (d->m_barSets.contains(set)) { | |
173 | d->m_barSets.removeOne(set); |
|
173 | d->m_barSets.removeOne(set); | |
174 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), d, SLOT(barsetChanged())); |
|
174 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), d, SLOT(barsetChanged())); | |
175 | setsRemoved = true; |
|
175 | setsRemoved = true; | |
176 | } |
|
176 | } | |
177 | } |
|
177 | } | |
178 |
|
178 | |||
179 | if (setsRemoved) { |
|
179 | if (setsRemoved) { | |
180 | emit d->restructuredBars(); |
|
180 | emit d->restructuredBars(); | |
181 | } |
|
181 | } | |
182 | return setsRemoved; |
|
182 | return setsRemoved; | |
183 | } |
|
183 | } | |
184 |
|
184 | |||
185 | /*! |
|
185 | /*! | |
186 | Returns number of sets in series. |
|
186 | Returns number of sets in series. | |
187 | */ |
|
187 | */ | |
188 | int QBarSeries::barsetCount() const |
|
188 | int QBarSeries::barsetCount() const | |
189 | { |
|
189 | { | |
190 | Q_D(const QBarSeries); |
|
190 | Q_D(const QBarSeries); | |
191 | return d->m_barSets.count(); |
|
191 | return d->m_barSets.count(); | |
192 | } |
|
192 | } | |
193 |
|
193 | |||
194 | /*! |
|
194 | /*! | |
195 | Returns number of categories in series |
|
195 | Returns number of categories in series | |
196 | */ |
|
196 | */ | |
197 | int QBarSeries::categoryCount() const |
|
197 | int QBarSeries::categoryCount() const | |
198 | { |
|
198 | { | |
199 | Q_D(const QBarSeries); |
|
199 | Q_D(const QBarSeries); | |
200 | return d->m_categories.count(); |
|
200 | return d->m_categories.count(); | |
201 | } |
|
201 | } | |
202 |
|
202 | |||
203 | /*! |
|
203 | /*! | |
204 | Returns a list of sets in series. Keeps ownership of sets. |
|
204 | Returns a list of sets in series. Keeps ownership of sets. | |
205 | */ |
|
205 | */ | |
206 | QList<QBarSet*> QBarSeries::barSets() const |
|
206 | QList<QBarSet*> QBarSeries::barSets() const | |
207 | { |
|
207 | { | |
208 | Q_D(const QBarSeries); |
|
208 | Q_D(const QBarSeries); | |
209 | return d->m_barSets; |
|
209 | return d->m_barSets; | |
210 | } |
|
210 | } | |
211 |
|
211 | |||
212 | /*! |
|
212 | /*! | |
213 | \fn bool QBarSeries::setModel(QAbstractItemModel *model) |
|
213 | \fn bool QBarSeries::setModel(QAbstractItemModel *model) | |
214 | Sets the \a model to be used as a data source |
|
214 | Sets the \a model to be used as a data source | |
215 | */ |
|
215 | */ | |
216 | void QBarSeries::setModel(QAbstractItemModel */*model*/) |
|
216 | void QBarSeries::setModel(QAbstractItemModel */*model*/) | |
217 | { |
|
217 | { | |
218 | // Q_D(QBarSeries); |
|
218 | // Q_D(QBarSeries); | |
219 | // d->setModel(model); |
|
219 | // d->setModel(model); | |
220 | } |
|
220 | } | |
221 |
|
221 | |||
222 | /*! |
|
222 | /*! | |
223 | \fn bool QBarSeries::setModelMapping(int categories, int bottomBoundry, int topBoundry, Qt::Orientation orientation) |
|
223 | \fn bool QBarSeries::setModelMapping(int categories, int bottomBoundry, int topBoundry, Qt::Orientation orientation) | |
224 | Sets column/row specified by \a categories to be used as a list of bar series categories. |
|
224 | Sets column/row specified by \a categories to be used as a list of bar series categories. | |
225 | Parameter \a bottomBoundry indicates the column/row where the first bar set is located in the model. |
|
225 | Parameter \a bottomBoundry indicates the column/row where the first bar set is located in the model. | |
226 | Parameter \a topBoundry indicates the column/row where the last bar set is located in the model. |
|
226 | Parameter \a topBoundry indicates the column/row where the last bar set is located in the model. | |
227 | All the columns/rows inbetween those two values are also used as data for bar sets. |
|
227 | All the columns/rows inbetween those two values are also used as data for bar sets. | |
228 | The \a orientation parameter specifies whether the data is in columns or in rows. |
|
228 | The \a orientation parameter specifies whether the data is in columns or in rows. | |
229 | */ |
|
229 | */ | |
230 | //void QBarSeries::setModelMapping(int categories, int bottomBoundary, int topBoundary, Qt::Orientation orientation) |
|
230 | //void QBarSeries::setModelMapping(int categories, int bottomBoundary, int topBoundary, Qt::Orientation orientation) | |
231 | //{ |
|
231 | //{ | |
232 | // Q_D(QBarSeries); |
|
232 | // Q_D(QBarSeries); | |
233 | // d->setModelMapping(categories,bottomBoundary,topBoundary,orientation); |
|
233 | // d->setModelMapping(categories,bottomBoundary,topBoundary,orientation); | |
234 | //} |
|
234 | //} | |
235 |
|
235 | |||
236 | //void QBarSeries::setModelMappingRange(int first, int count) |
|
236 | //void QBarSeries::setModelMappingRange(int first, int count) | |
237 | //{ |
|
237 | //{ | |
238 | // Q_D(QBarSeries); |
|
238 | // Q_D(QBarSeries); | |
239 | // d->setModelMappingRange(first, count); |
|
239 | // d->setModelMappingRange(first, count); | |
240 | //} |
|
240 | //} | |
241 |
|
241 | |||
242 | /*! |
|
242 | /*! | |
243 | Returns the bar categories of the series. |
|
243 | Returns the bar categories of the series. | |
244 | */ |
|
244 | */ | |
245 | QBarCategories QBarSeries::categories() const |
|
245 | QBarCategories QBarSeries::categories() const | |
246 | { |
|
246 | { | |
247 | Q_D(const QBarSeries); |
|
247 | Q_D(const QBarSeries); | |
248 | return d->m_categories; |
|
248 | return d->m_categories; | |
249 | } |
|
249 | } | |
250 |
|
250 | |||
251 | /*! |
|
251 | /*! | |
252 | Sets the visibility of labels in series to \a visible |
|
252 | Sets the visibility of labels in series to \a visible | |
253 | */ |
|
253 | */ | |
254 | void QBarSeries::setLabelsVisible(bool visible) |
|
254 | void QBarSeries::setLabelsVisible(bool visible) | |
255 | { |
|
255 | { | |
256 | foreach (QBarSet* s, barSets()) { |
|
256 | foreach (QBarSet* s, barSets()) { | |
257 | s->setLabelsVisible(visible); |
|
257 | s->setLabelsVisible(visible); | |
258 | } |
|
258 | } | |
259 | } |
|
259 | } | |
260 |
|
260 | |||
261 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
261 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
262 |
|
262 | |||
263 |
QBarSeriesPrivate::QBarSeriesPrivate( |
|
263 | QBarSeriesPrivate::QBarSeriesPrivate(QBarSeries *q) : | |
264 | QAbstractSeriesPrivate(q), |
|
264 | QAbstractSeriesPrivate(q), | |
265 | // m_categories(categories), |
|
265 | m_barMargin(0.05), // Default value is 5% of category width | |
266 | m_mapCategories(-1), |
|
266 | m_mapCategories(-1), | |
267 | m_mapBarBottom(-1), |
|
267 | m_mapBarBottom(-1), | |
268 | m_mapBarTop(-1) |
|
268 | m_mapBarTop(-1) | |
269 | { |
|
269 | { | |
270 | } |
|
270 | } | |
271 |
|
271 | |||
272 | void QBarSeriesPrivate::setCategories(QBarCategories categories) |
|
272 | void QBarSeriesPrivate::setCategories(QBarCategories categories) | |
273 | { |
|
273 | { | |
274 | m_categories = categories; |
|
274 | m_categories = categories; | |
275 | } |
|
275 | } | |
276 |
|
276 | |||
|
277 | void QBarSeriesPrivate::setBarMargin(qreal margin) | |||
|
278 | { | |||
|
279 | if (margin > 1.0) { | |||
|
280 | margin = 1.0; | |||
|
281 | } else if (margin < 0.0) { | |||
|
282 | margin = 0.0; | |||
|
283 | } | |||
|
284 | ||||
|
285 | m_barMargin = margin; | |||
|
286 | emit updatedBars(); | |||
|
287 | } | |||
|
288 | ||||
|
289 | qreal QBarSeriesPrivate::barMargin() | |||
|
290 | { | |||
|
291 | return m_barMargin; | |||
|
292 | } | |||
277 |
|
293 | |||
278 | QBarSet* QBarSeriesPrivate::barsetAt(int index) |
|
294 | QBarSet* QBarSeriesPrivate::barsetAt(int index) | |
279 | { |
|
295 | { | |
280 | return m_barSets.at(index); |
|
296 | return m_barSets.at(index); | |
281 | } |
|
297 | } | |
282 |
|
298 | |||
283 | QString QBarSeriesPrivate::categoryName(int category) |
|
299 | QString QBarSeriesPrivate::categoryName(int category) | |
284 | { |
|
300 | { | |
285 | return m_categories.at(category); |
|
301 | return m_categories.at(category); | |
286 | } |
|
302 | } | |
287 |
|
303 | |||
288 | qreal QBarSeriesPrivate::min() |
|
304 | qreal QBarSeriesPrivate::min() | |
289 | { |
|
305 | { | |
290 | if (m_barSets.count() <= 0) { |
|
306 | if (m_barSets.count() <= 0) { | |
291 | return 0; |
|
307 | return 0; | |
292 | } |
|
308 | } | |
293 | qreal min = INT_MAX; |
|
309 | qreal min = INT_MAX; | |
294 |
|
310 | |||
295 | for (int i = 0; i < m_barSets.count(); i++) { |
|
311 | for (int i = 0; i < m_barSets.count(); i++) { | |
296 | int categoryCount = m_barSets.at(i)->count(); |
|
312 | int categoryCount = m_barSets.at(i)->count(); | |
297 | for (int j = 0; j < categoryCount; j++) { |
|
313 | for (int j = 0; j < categoryCount; j++) { | |
298 | qreal temp = m_barSets.at(i)->at(j); |
|
314 | qreal temp = m_barSets.at(i)->at(j).y(); | |
299 | if (temp < min) |
|
315 | if (temp < min) | |
300 | min = temp; |
|
316 | min = temp; | |
301 | } |
|
317 | } | |
302 | } |
|
318 | } | |
303 | return min; |
|
319 | return min; | |
304 | } |
|
320 | } | |
305 |
|
321 | |||
306 | qreal QBarSeriesPrivate::max() |
|
322 | qreal QBarSeriesPrivate::max() | |
307 | { |
|
323 | { | |
308 | if (m_barSets.count() <= 0) { |
|
324 | if (m_barSets.count() <= 0) { | |
309 | return 0; |
|
325 | return 0; | |
310 | } |
|
326 | } | |
311 | qreal max = INT_MIN; |
|
327 | qreal max = INT_MIN; | |
312 |
|
328 | |||
313 | for (int i = 0; i < m_barSets.count(); i++) { |
|
329 | for (int i = 0; i < m_barSets.count(); i++) { | |
314 | int categoryCount = m_barSets.at(i)->count(); |
|
330 | int categoryCount = m_barSets.at(i)->count(); | |
315 | for (int j = 0; j < categoryCount; j++) { |
|
331 | for (int j = 0; j < categoryCount; j++) { | |
316 | qreal temp = m_barSets.at(i)->at(j); |
|
332 | qreal temp = m_barSets.at(i)->at(j).y(); | |
317 | if (temp > max) |
|
333 | if (temp > max) | |
318 | max = temp; |
|
334 | max = temp; | |
319 | } |
|
335 | } | |
320 | } |
|
336 | } | |
321 |
|
337 | |||
322 | return max; |
|
338 | return max; | |
323 | } |
|
339 | } | |
324 |
|
340 | |||
325 | qreal QBarSeriesPrivate::valueAt(int set, int category) |
|
341 | qreal QBarSeriesPrivate::valueAt(int set, int category) | |
326 | { |
|
342 | { | |
327 | if ((set < 0) || (set >= m_barSets.count())) { |
|
343 | if ((set < 0) || (set >= m_barSets.count())) { | |
328 | // No set, no value. |
|
344 | // No set, no value. | |
329 | return 0; |
|
345 | return 0; | |
330 | } else if ((category < 0) || (category >= m_barSets.at(set)->count())) { |
|
346 | } else if ((category < 0) || (category >= m_barSets.at(set)->count())) { | |
331 | // No category, no value. |
|
347 | // No category, no value. | |
332 | return 0; |
|
348 | return 0; | |
333 | } |
|
349 | } | |
334 |
|
350 | |||
335 | return m_barSets.at(set)->at(category); |
|
351 | return m_barSets.at(set)->at(category).y(); | |
336 | } |
|
352 | } | |
337 |
|
353 | |||
338 | qreal QBarSeriesPrivate::percentageAt(int set, int category) |
|
354 | qreal QBarSeriesPrivate::percentageAt(int set, int category) | |
339 | { |
|
355 | { | |
340 | if ((set < 0) || (set >= m_barSets.count())) { |
|
356 | if ((set < 0) || (set >= m_barSets.count())) { | |
341 | // No set, no value. |
|
357 | // No set, no value. | |
342 | return 0; |
|
358 | return 0; | |
343 | } else if ((category < 0) || (category >= m_barSets.at(set)->count())) { |
|
359 | } else if ((category < 0) || (category >= m_barSets.at(set)->count())) { | |
344 | // No category, no value. |
|
360 | // No category, no value. | |
345 | return 0; |
|
361 | return 0; | |
346 | } |
|
362 | } | |
347 |
|
363 | |||
348 | qreal value = m_barSets.at(set)->at(category); |
|
364 | qreal value = m_barSets.at(set)->at(category).y(); | |
349 | qreal sum = categorySum(category); |
|
365 | qreal sum = categorySum(category); | |
350 | if ( qFuzzyIsNull(sum) ) { |
|
366 | if ( qFuzzyIsNull(sum) ) { | |
351 | return 0; |
|
367 | return 0; | |
352 | } |
|
368 | } | |
353 |
|
369 | |||
354 | return value / sum; |
|
370 | return value / sum; | |
355 | } |
|
371 | } | |
356 |
|
372 | |||
357 | qreal QBarSeriesPrivate::categorySum(int category) |
|
373 | qreal QBarSeriesPrivate::categorySum(int category) | |
358 | { |
|
374 | { | |
359 | qreal sum(0); |
|
375 | qreal sum(0); | |
360 | int count = m_barSets.count(); // Count sets |
|
376 | int count = m_barSets.count(); // Count sets | |
361 | for (int set = 0; set < count; set++) { |
|
377 | for (int set = 0; set < count; set++) { | |
362 | if (category < m_barSets.at(set)->count()) |
|
378 | if (category < m_barSets.at(set)->count()) | |
363 | sum += m_barSets.at(set)->at(category); |
|
379 | sum += m_barSets.at(set)->at(category).y(); | |
364 | } |
|
380 | } | |
365 | return sum; |
|
381 | return sum; | |
366 | } |
|
382 | } | |
367 |
|
383 | |||
368 | qreal QBarSeriesPrivate::absoluteCategorySum(int category) |
|
384 | qreal QBarSeriesPrivate::absoluteCategorySum(int category) | |
369 | { |
|
385 | { | |
370 | qreal sum(0); |
|
386 | qreal sum(0); | |
371 | int count = m_barSets.count(); // Count sets |
|
387 | int count = m_barSets.count(); // Count sets | |
372 | for (int set = 0; set < count; set++) { |
|
388 | for (int set = 0; set < count; set++) { | |
373 | if (category < m_barSets.at(set)->count()) |
|
389 | if (category < m_barSets.at(set)->count()) | |
374 | sum += qAbs(m_barSets.at(set)->at(category)); |
|
390 | sum += qAbs(m_barSets.at(set)->at(category).y()); | |
375 | } |
|
391 | } | |
376 | return sum; |
|
392 | return sum; | |
377 | } |
|
393 | } | |
378 |
|
394 | |||
379 | qreal QBarSeriesPrivate::maxCategorySum() |
|
395 | qreal QBarSeriesPrivate::maxCategorySum() | |
380 | { |
|
396 | { | |
381 | qreal max = INT_MIN; |
|
397 | qreal max = INT_MIN; | |
382 | int count = m_categories.count(); |
|
398 | int count = m_categories.count(); | |
383 | for (int i = 0; i < count; i++) { |
|
399 | for (int i = 0; i < count; i++) { | |
384 | qreal sum = categorySum(i); |
|
400 | qreal sum = categorySum(i); | |
385 | if (sum > max) |
|
401 | if (sum > max) | |
386 | max = sum; |
|
402 | max = sum; | |
387 | } |
|
403 | } | |
388 | return max; |
|
404 | return max; | |
389 | } |
|
405 | } | |
390 |
|
406 | |||
391 | //void QBarSeriesPrivate::setModel(QAbstractItemModel *model) |
|
407 | //void QBarSeriesPrivate::setModel(QAbstractItemModel *model) | |
392 | //{ |
|
408 | //{ | |
393 | // // disconnect signals from old model |
|
409 | // // disconnect signals from old model | |
394 | // if(m_model) |
|
410 | // if(m_model) | |
395 | // { |
|
411 | // { | |
396 | // disconnect(m_model, 0, this, 0); |
|
412 | // disconnect(m_model, 0, this, 0); | |
397 | // m_mapCategories = -1; |
|
413 | // m_mapCategories = -1; | |
398 | // m_mapBarBottom = -1; |
|
414 | // m_mapBarBottom = -1; | |
399 | // m_mapBarTop = -1; |
|
415 | // m_mapBarTop = -1; | |
400 | // m_mapOrientation = Qt::Vertical; |
|
416 | // m_mapOrientation = Qt::Vertical; | |
401 | // } |
|
417 | // } | |
402 |
|
418 | |||
403 | // // set new model |
|
419 | // // set new model | |
404 | // if(model) |
|
420 | // if(model) | |
405 | // { |
|
421 | // { | |
406 | // m_model = model; |
|
422 | // m_model = model; | |
407 | // } |
|
423 | // } | |
408 | // else |
|
424 | // else | |
409 | // { |
|
425 | // { | |
410 | // m_model = 0; |
|
426 | // m_model = 0; | |
411 | // } |
|
427 | // } | |
412 | //} |
|
428 | //} | |
413 |
|
429 | |||
414 | //void QBarSeriesPrivate::setModelMapping(int categories, int bottomBoundry, int topBoundry, Qt::Orientation orientation) |
|
430 | //void QBarSeriesPrivate::setModelMapping(int categories, int bottomBoundry, int topBoundry, Qt::Orientation orientation) | |
415 | //{ |
|
431 | //{ | |
416 | // Q_Q(QBarSeries); |
|
432 | // Q_Q(QBarSeries); | |
417 |
|
433 | |||
418 | // if (m_model == 0) |
|
434 | // if (m_model == 0) | |
419 | // return; |
|
435 | // return; | |
420 |
|
436 | |||
421 | // m_mapCategories = categories; |
|
437 | // m_mapCategories = categories; | |
422 | // m_mapBarBottom = bottomBoundry; |
|
438 | // m_mapBarBottom = bottomBoundry; | |
423 | // m_mapBarTop = topBoundry; |
|
439 | // m_mapBarTop = topBoundry; | |
424 | // m_mapOrientation = orientation; |
|
440 | // m_mapOrientation = orientation; | |
425 |
|
441 | |||
426 | // // connect the signals |
|
442 | // // connect the signals | |
427 | // connect(m_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(modelUpdated(QModelIndex,QModelIndex))); |
|
443 | // connect(m_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(modelUpdated(QModelIndex,QModelIndex))); | |
428 | // if (m_mapOrientation == Qt::Vertical) { |
|
444 | // if (m_mapOrientation == Qt::Vertical) { | |
429 | // connect(m_model,SIGNAL(rowsInserted(QModelIndex,int,int)), this, SLOT(modelDataAdded(QModelIndex,int,int))); |
|
445 | // connect(m_model,SIGNAL(rowsInserted(QModelIndex,int,int)), this, SLOT(modelDataAdded(QModelIndex,int,int))); | |
430 | // connect(m_model,SIGNAL(rowsRemoved(QModelIndex,int,int)), this, SLOT(modelDataRemoved(QModelIndex,int,int))); |
|
446 | // connect(m_model,SIGNAL(rowsRemoved(QModelIndex,int,int)), this, SLOT(modelDataRemoved(QModelIndex,int,int))); | |
431 | // } else { |
|
447 | // } else { | |
432 | // connect(m_model, SIGNAL(columnsInserted(QModelIndex,int,int)), this, SLOT(modelDataAdded(QModelIndex,int,int))); |
|
448 | // connect(m_model, SIGNAL(columnsInserted(QModelIndex,int,int)), this, SLOT(modelDataAdded(QModelIndex,int,int))); | |
433 | // connect(m_model, SIGNAL(columnsRemoved(QModelIndex,int,int)), this, SLOT(modelDataRemoved(QModelIndex,int,int))); |
|
449 | // connect(m_model, SIGNAL(columnsRemoved(QModelIndex,int,int)), this, SLOT(modelDataRemoved(QModelIndex,int,int))); | |
434 | // } |
|
450 | // } | |
435 |
|
451 | |||
436 | // // create the initial bars |
|
452 | // // create the initial bars | |
437 | // m_categories.clear(); |
|
453 | // m_categories.clear(); | |
438 | // if (m_mapOrientation == Qt::Vertical) { |
|
454 | // if (m_mapOrientation == Qt::Vertical) { | |
439 | // int rowCount = 0; |
|
455 | // int rowCount = 0; | |
440 | // if(m_mapCount == -1) |
|
456 | // if(m_mapCount == -1) | |
441 | // rowCount = m_model->rowCount() - m_mapFirst; |
|
457 | // rowCount = m_model->rowCount() - m_mapFirst; | |
442 | // else |
|
458 | // else | |
443 | // rowCount = qMin(m_mapCount, m_model->rowCount() - m_mapFirst); |
|
459 | // rowCount = qMin(m_mapCount, m_model->rowCount() - m_mapFirst); | |
444 | // for (int k = m_mapFirst; k < m_mapFirst + rowCount; k++) { |
|
460 | // for (int k = m_mapFirst; k < m_mapFirst + rowCount; k++) { | |
445 | // m_categories << m_model->data(m_model->index(k, m_mapCategories), Qt::DisplayRole).toString(); |
|
461 | // m_categories << m_model->data(m_model->index(k, m_mapCategories), Qt::DisplayRole).toString(); | |
446 | // } |
|
462 | // } | |
447 |
|
463 | |||
448 | // for (int i = m_mapBarBottom; i <= m_mapBarTop; i++) { |
|
464 | // for (int i = m_mapBarBottom; i <= m_mapBarTop; i++) { | |
449 | // QBarSet* barSet = new QBarSet(m_model->headerData(i, Qt::Horizontal, Qt::DisplayRole).toString()); |
|
465 | // QBarSet* barSet = new QBarSet(m_model->headerData(i, Qt::Horizontal, Qt::DisplayRole).toString()); | |
450 | // for(int m = m_mapFirst; m < m_mapFirst + rowCount; m++) |
|
466 | // for(int m = m_mapFirst; m < m_mapFirst + rowCount; m++) | |
451 | // *barSet << m_model->data(m_model->index(m, i), Qt::DisplayRole).toDouble(); |
|
467 | // *barSet << m_model->data(m_model->index(m, i), Qt::DisplayRole).toDouble(); | |
452 | // q->appendBarSet(barSet); |
|
468 | // q->appendBarSet(barSet); | |
453 | // } |
|
469 | // } | |
454 | // } else { |
|
470 | // } else { | |
455 | // int columnCount = 0; |
|
471 | // int columnCount = 0; | |
456 | // if(m_mapCount == -1) |
|
472 | // if(m_mapCount == -1) | |
457 | // columnCount = m_model->columnCount() - m_mapFirst; |
|
473 | // columnCount = m_model->columnCount() - m_mapFirst; | |
458 | // else |
|
474 | // else | |
459 | // columnCount = qMin(m_mapCount, m_model->columnCount() - m_mapFirst); |
|
475 | // columnCount = qMin(m_mapCount, m_model->columnCount() - m_mapFirst); | |
460 | // for (int k = m_mapFirst; k < m_mapFirst + columnCount; k++) { |
|
476 | // for (int k = m_mapFirst; k < m_mapFirst + columnCount; k++) { | |
461 | // m_categories << m_model->data(m_model->index(m_mapCategories, k), Qt::DisplayRole).toString(); |
|
477 | // m_categories << m_model->data(m_model->index(m_mapCategories, k), Qt::DisplayRole).toString(); | |
462 | // } |
|
478 | // } | |
463 |
|
479 | |||
464 | // for (int i = m_mapBarBottom; i <= m_mapBarTop; i++) { |
|
480 | // for (int i = m_mapBarBottom; i <= m_mapBarTop; i++) { | |
465 | // QBarSet* barSet = new QBarSet(m_model->headerData(i, Qt::Vertical, Qt::DisplayRole).toString()); |
|
481 | // QBarSet* barSet = new QBarSet(m_model->headerData(i, Qt::Vertical, Qt::DisplayRole).toString()); | |
466 | // for(int m = m_mapFirst; m < m_mapFirst + columnCount; m++) |
|
482 | // for(int m = m_mapFirst; m < m_mapFirst + columnCount; m++) | |
467 | // *barSet << m_model->data(m_model->index(i, m), Qt::DisplayRole).toDouble(); |
|
483 | // *barSet << m_model->data(m_model->index(i, m), Qt::DisplayRole).toDouble(); | |
468 | // q->appendBarSet(barSet); |
|
484 | // q->appendBarSet(barSet); | |
469 | // } |
|
485 | // } | |
470 | // } |
|
486 | // } | |
471 | //} |
|
487 | //} | |
472 |
|
488 | |||
473 | //void QBarSeriesPrivate::setModelMappingRange(int first, int count) |
|
489 | //void QBarSeriesPrivate::setModelMappingRange(int first, int count) | |
474 | //{ |
|
490 | //{ | |
475 | // m_mapFirst = first; |
|
491 | // m_mapFirst = first; | |
476 | // m_mapCount = count; |
|
492 | // m_mapCount = count; | |
477 | //} |
|
493 | //} | |
478 |
|
494 | |||
479 | //void QBarSeriesPrivate::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight) |
|
495 | //void QBarSeriesPrivate::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight) | |
480 | //{ |
|
496 | //{ | |
481 | // for (int row = topLeft.row(); row <= bottomRight.row(); row++) { |
|
497 | // for (int row = topLeft.row(); row <= bottomRight.row(); row++) { | |
482 | // for (int column = topLeft.column(); column <= bottomRight.column(); column++) { |
|
498 | // for (int column = topLeft.column(); column <= bottomRight.column(); column++) { | |
483 | // if (m_mapOrientation == Qt::Vertical) |
|
499 | // if (m_mapOrientation == Qt::Vertical) | |
484 | // { |
|
500 | // { | |
485 | // // model update is relevant to BarSeries if the change was made to the part of the model that was mapped to BarSeries |
|
501 | // // model update is relevant to BarSeries if the change was made to the part of the model that was mapped to BarSeries | |
486 | // if ( row >= m_mapFirst && (m_mapCount == - 1 || row < m_mapFirst + m_mapCount)) { |
|
502 | // if ( row >= m_mapFirst && (m_mapCount == - 1 || row < m_mapFirst + m_mapCount)) { | |
487 | // if (column >= m_mapBarBottom && column <= m_mapBarTop) |
|
503 | // if (column >= m_mapBarBottom && column <= m_mapBarTop) | |
488 | // barsetAt(column - m_mapBarBottom)->replace(row - m_mapFirst, m_model->data(topLeft, Qt::DisplayRole).toDouble()); |
|
504 | // barsetAt(column - m_mapBarBottom)->replace(row - m_mapFirst, m_model->data(topLeft, Qt::DisplayRole).toDouble()); | |
489 | // // if (column == m_mapCategories);// TODO: |
|
505 | // // if (column == m_mapCategories);// TODO: | |
490 | // } |
|
506 | // } | |
491 | // } |
|
507 | // } | |
492 | // else |
|
508 | // else | |
493 | // { |
|
509 | // { | |
494 | // // model update is relevant to BarSeries if the change was made to the part of the model that was mapped to BarSeries |
|
510 | // // model update is relevant to BarSeries if the change was made to the part of the model that was mapped to BarSeries | |
495 | // if (column >= m_mapFirst && (m_mapCount == - 1 || column < m_mapFirst + m_mapCount)) { |
|
511 | // if (column >= m_mapFirst && (m_mapCount == - 1 || column < m_mapFirst + m_mapCount)) { | |
496 | // if (row >= m_mapBarBottom && row <= m_mapBarTop) |
|
512 | // if (row >= m_mapBarBottom && row <= m_mapBarTop) | |
497 | // barsetAt(row - m_mapBarBottom)->replace(column - m_mapFirst, m_model->data(topLeft, Qt::DisplayRole).toDouble()); |
|
513 | // barsetAt(row - m_mapBarBottom)->replace(column - m_mapFirst, m_model->data(topLeft, Qt::DisplayRole).toDouble()); | |
498 | // // if (row == m_mapCategories);// TODO: |
|
514 | // // if (row == m_mapCategories);// TODO: | |
499 | // } |
|
515 | // } | |
500 | // } |
|
516 | // } | |
501 | // } |
|
517 | // } | |
502 | // } |
|
518 | // } | |
503 | //} |
|
519 | //} | |
504 |
|
520 | |||
505 | void QBarSeriesPrivate::modelDataAdded(QModelIndex parent, int start, int end) |
|
521 | void QBarSeriesPrivate::modelDataAdded(QModelIndex parent, int start, int end) | |
506 | { |
|
522 | { | |
507 | Q_UNUSED(parent); |
|
523 | Q_UNUSED(parent); | |
508 | Q_UNUSED(start); |
|
524 | Q_UNUSED(start); | |
509 | Q_UNUSED(end); |
|
525 | Q_UNUSED(end); | |
510 | // initializeDataFromModel(); |
|
526 | // initializeDataFromModel(); | |
511 | // // series uses model as a data sourceupda |
|
527 | // // series uses model as a data sourceupda | |
512 | // int addedCount = end - start + 1; |
|
528 | // int addedCount = end - start + 1; | |
513 | // if (m_mapCount != -1 && start >= m_mapFirst + m_mapCount) { |
|
529 | // if (m_mapCount != -1 && start >= m_mapFirst + m_mapCount) { | |
514 | // return; |
|
530 | // return; | |
515 | // } else { |
|
531 | // } else { | |
516 |
|
532 | |||
517 | // for (int bar = m_mapBarBottom; bar <= m_mapBarTop; bar++) { |
|
533 | // for (int bar = m_mapBarBottom; bar <= m_mapBarTop; bar++) { | |
518 | // QBarSet *barSet = barsetAt(bar - m_mapBarBottom); |
|
534 | // QBarSet *barSet = barsetAt(bar - m_mapBarBottom); | |
519 | // // adding items to unlimited map |
|
535 | // // adding items to unlimited map | |
520 | // if (m_mapCount == -1 && start >= m_mapFirst) { |
|
536 | // if (m_mapCount == -1 && start >= m_mapFirst) { | |
521 | // for (int i = start; i <= end; i++) { |
|
537 | // for (int i = start; i <= end; i++) { | |
522 | // if (bar == m_mapBarBottom) |
|
538 | // if (bar == m_mapBarBottom) | |
523 | // insertCategory(i - m_mapFirst, m_model->data(m_model->index(i, m_mapCategories), Qt::DisplayRole).toString()); |
|
539 | // insertCategory(i - m_mapFirst, m_model->data(m_model->index(i, m_mapCategories), Qt::DisplayRole).toString()); | |
524 | // barSet->insert(i - m_mapFirst, m_model->data(m_model->index(i, bar), Qt::DisplayRole).toDouble()); |
|
540 | // barSet->insert(i - m_mapFirst, m_model->data(m_model->index(i, bar), Qt::DisplayRole).toDouble()); | |
525 | // } |
|
541 | // } | |
526 | // } else if (m_mapCount == - 1 && start < m_mapFirst) { |
|
542 | // } else if (m_mapCount == - 1 && start < m_mapFirst) { | |
527 | // // not all newly added items |
|
543 | // // not all newly added items | |
528 | // for (int i = m_mapFirst; i < m_mapFirst + addedCount; i++) { |
|
544 | // for (int i = m_mapFirst; i < m_mapFirst + addedCount; i++) { | |
529 | // if (bar == m_mapBarBottom) |
|
545 | // if (bar == m_mapBarBottom) | |
530 | // insertCategory(i - m_mapFirst, m_model->data(m_model->index(i, m_mapCategories), Qt::DisplayRole).toString()); |
|
546 | // insertCategory(i - m_mapFirst, m_model->data(m_model->index(i, m_mapCategories), Qt::DisplayRole).toString()); | |
531 | // barSet->insert(i - m_mapFirst, m_model->data(m_model->index(i, bar), Qt::DisplayRole).toDouble()); |
|
547 | // barSet->insert(i - m_mapFirst, m_model->data(m_model->index(i, bar), Qt::DisplayRole).toDouble()); | |
532 | // } |
|
548 | // } | |
533 | // } |
|
549 | // } | |
534 |
|
550 | |||
535 | // // adding items to limited map |
|
551 | // // adding items to limited map | |
536 | // else if (start >= m_mapFirst) { |
|
552 | // else if (start >= m_mapFirst) { | |
537 | // // remove the items that will no longer fit into the map |
|
553 | // // remove the items that will no longer fit into the map | |
538 | // // int toRemove = addedCount - (count - points().size()); |
|
554 | // // int toRemove = addedCount - (count - points().size()); | |
539 | // for (int i = start; i <= end; i++) { |
|
555 | // for (int i = start; i <= end; i++) { | |
540 | // if (bar == m_mapBarBottom) |
|
556 | // if (bar == m_mapBarBottom) | |
541 | // insertCategory(i - m_mapFirst, m_model->data(m_model->index(i, m_mapCategories), Qt::DisplayRole).toString()); |
|
557 | // insertCategory(i - m_mapFirst, m_model->data(m_model->index(i, m_mapCategories), Qt::DisplayRole).toString()); | |
542 | // barSet->insert(i - m_mapFirst, m_model->data(m_model->index(i, bar), Qt::DisplayRole).toDouble()); |
|
558 | // barSet->insert(i - m_mapFirst, m_model->data(m_model->index(i, bar), Qt::DisplayRole).toDouble()); | |
543 | // } |
|
559 | // } | |
544 | // if (m_barSets.size() > m_mapCount) |
|
560 | // if (m_barSets.size() > m_mapCount) | |
545 | // for (int i = m_barSets.size() - 1; i >= m_mapCount; i--) { |
|
561 | // for (int i = m_barSets.size() - 1; i >= m_mapCount; i--) { | |
546 | // if (bar == m_mapBarBottom) |
|
562 | // if (bar == m_mapBarBottom) | |
547 | // removeCategory(i); |
|
563 | // removeCategory(i); | |
548 | // barSet->remove(i); |
|
564 | // barSet->remove(i); | |
549 | // } |
|
565 | // } | |
550 | // } else { |
|
566 | // } else { | |
551 | // // |
|
567 | // // | |
552 | // for (int i = m_mapFirst; i < m_mapFirst + addedCount; i++) { |
|
568 | // for (int i = m_mapFirst; i < m_mapFirst + addedCount; i++) { | |
553 | // if (bar == m_mapBarBottom) |
|
569 | // if (bar == m_mapBarBottom) | |
554 | // insertCategory(i - m_mapFirst, m_model->data(m_model->index(i, m_mapCategories), Qt::DisplayRole).toString()); |
|
570 | // insertCategory(i - m_mapFirst, m_model->data(m_model->index(i, m_mapCategories), Qt::DisplayRole).toString()); | |
555 | // barSet->insert(i - m_mapFirst, m_model->data(m_model->index(i, bar), Qt::DisplayRole).toDouble()); |
|
571 | // barSet->insert(i - m_mapFirst, m_model->data(m_model->index(i, bar), Qt::DisplayRole).toDouble()); | |
556 | // } |
|
572 | // } | |
557 | // if (m_barSets.size() > m_mapCount) |
|
573 | // if (m_barSets.size() > m_mapCount) | |
558 | // for (int i = m_barSets.size() - 1; i >= m_mapCount; i--) { |
|
574 | // for (int i = m_barSets.size() - 1; i >= m_mapCount; i--) { | |
559 | // if (bar == m_mapBarBottom) |
|
575 | // if (bar == m_mapBarBottom) | |
560 | // removeCategory(i); |
|
576 | // removeCategory(i); | |
561 | // barSet->remove(i); |
|
577 | // barSet->remove(i); | |
562 | // } |
|
578 | // } | |
563 | // } |
|
579 | // } | |
564 | // } |
|
580 | // } | |
565 | // emit restructuredBars(); |
|
581 | // emit restructuredBars(); | |
566 | // emit barsetChanged(); |
|
582 | // emit barsetChanged(); | |
567 | // emit categoriesUpdated(); |
|
583 | // emit categoriesUpdated(); | |
568 | // } |
|
584 | // } | |
569 | } |
|
585 | } | |
570 |
|
586 | |||
571 | void QBarSeriesPrivate::modelDataRemoved(QModelIndex parent, int start, int end) |
|
587 | void QBarSeriesPrivate::modelDataRemoved(QModelIndex parent, int start, int end) | |
572 | { |
|
588 | { | |
573 | Q_UNUSED(parent); |
|
589 | Q_UNUSED(parent); | |
574 | Q_UNUSED(start); |
|
590 | Q_UNUSED(start); | |
575 | Q_UNUSED(end); |
|
591 | Q_UNUSED(end); | |
576 | // initializeDataFromModel(); |
|
592 | // initializeDataFromModel(); | |
577 | } |
|
593 | } | |
578 |
|
594 | |||
579 | //void QBarSeriesPrivate::initializeDataFromModel() |
|
595 | //void QBarSeriesPrivate::initializeDataFromModel() | |
580 | //{ |
|
596 | //{ | |
581 | // Q_Q(QBarSeries); |
|
597 | // Q_Q(QBarSeries); | |
582 |
|
598 | |||
583 | // if (m_model == 0) |
|
599 | // if (m_model == 0) | |
584 | // return; |
|
600 | // return; | |
585 |
|
601 | |||
586 | // // connect the signals |
|
602 | // // connect the signals | |
587 | //// connect(m_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(modelUpdated(QModelIndex,QModelIndex))); |
|
603 | //// connect(m_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(modelUpdated(QModelIndex,QModelIndex))); | |
588 | //// if (m_mapOrientation == Qt::Vertical) { |
|
604 | //// if (m_mapOrientation == Qt::Vertical) { | |
589 | //// connect(m_model,SIGNAL(rowsInserted(QModelIndex,int,int)), this, SLOT(modelDataAdded(QModelIndex,int,int))); |
|
605 | //// connect(m_model,SIGNAL(rowsInserted(QModelIndex,int,int)), this, SLOT(modelDataAdded(QModelIndex,int,int))); | |
590 | //// connect(m_model,SIGNAL(rowsRemoved(QModelIndex,int,int)), this, SLOT(modelDataRemoved(QModelIndex,int,int))); |
|
606 | //// connect(m_model,SIGNAL(rowsRemoved(QModelIndex,int,int)), this, SLOT(modelDataRemoved(QModelIndex,int,int))); | |
591 | //// } else { |
|
607 | //// } else { | |
592 | //// connect(m_model, SIGNAL(columnsInserted(QModelIndex,int,int)), this, SLOT(modelDataAdded(QModelIndex,int,int))); |
|
608 | //// connect(m_model, SIGNAL(columnsInserted(QModelIndex,int,int)), this, SLOT(modelDataAdded(QModelIndex,int,int))); | |
593 | //// connect(m_model, SIGNAL(columnsRemoved(QModelIndex,int,int)), this, SLOT(modelDataRemoved(QModelIndex,int,int))); |
|
609 | //// connect(m_model, SIGNAL(columnsRemoved(QModelIndex,int,int)), this, SLOT(modelDataRemoved(QModelIndex,int,int))); | |
594 | //// } |
|
610 | //// } | |
595 |
|
611 | |||
596 | // // create the initial bars |
|
612 | // // create the initial bars | |
597 | // m_categories.clear(); |
|
613 | // m_categories.clear(); | |
598 | // m_barSets.clear(); |
|
614 | // m_barSets.clear(); | |
599 | //// emit restructuredBars(); |
|
615 | //// emit restructuredBars(); | |
600 | // if (m_mapOrientation == Qt::Vertical) { |
|
616 | // if (m_mapOrientation == Qt::Vertical) { | |
601 | // int rowCount = 0; |
|
617 | // int rowCount = 0; | |
602 | // if(m_mapCount == -1) |
|
618 | // if(m_mapCount == -1) | |
603 | // rowCount = m_model->rowCount() - m_mapFirst; |
|
619 | // rowCount = m_model->rowCount() - m_mapFirst; | |
604 | // else |
|
620 | // else | |
605 | // rowCount = qMin(m_mapCount, m_model->rowCount() - m_mapFirst); |
|
621 | // rowCount = qMin(m_mapCount, m_model->rowCount() - m_mapFirst); | |
606 | // for (int k = m_mapFirst; k < m_mapFirst + rowCount; k++) { |
|
622 | // for (int k = m_mapFirst; k < m_mapFirst + rowCount; k++) { | |
607 | // m_categories << m_model->data(m_model->index(k, m_mapCategories), Qt::DisplayRole).toString(); |
|
623 | // m_categories << m_model->data(m_model->index(k, m_mapCategories), Qt::DisplayRole).toString(); | |
608 | // } |
|
624 | // } | |
609 |
|
625 | |||
610 | // for (int i = m_mapBarBottom; i <= m_mapBarTop; i++) { |
|
626 | // for (int i = m_mapBarBottom; i <= m_mapBarTop; i++) { | |
611 | // QBarSet* barSet = new QBarSet(m_model->headerData(i, Qt::Horizontal, Qt::DisplayRole).toString()); |
|
627 | // QBarSet* barSet = new QBarSet(m_model->headerData(i, Qt::Horizontal, Qt::DisplayRole).toString()); | |
612 | // for(int m = m_mapFirst; m < m_mapFirst + rowCount; m++) |
|
628 | // for(int m = m_mapFirst; m < m_mapFirst + rowCount; m++) | |
613 | // *barSet << m_model->data(m_model->index(m, i), Qt::DisplayRole).toDouble(); |
|
629 | // *barSet << m_model->data(m_model->index(m, i), Qt::DisplayRole).toDouble(); | |
614 | // q->appendBarSet(barSet); |
|
630 | // q->appendBarSet(barSet); | |
615 | // } |
|
631 | // } | |
616 | // } else { |
|
632 | // } else { | |
617 | // int columnCount = 0; |
|
633 | // int columnCount = 0; | |
618 | // if(m_mapCount == -1) |
|
634 | // if(m_mapCount == -1) | |
619 | // columnCount = m_model->columnCount() - m_mapFirst; |
|
635 | // columnCount = m_model->columnCount() - m_mapFirst; | |
620 | // else |
|
636 | // else | |
621 | // columnCount = qMin(m_mapCount, m_model->columnCount() - m_mapFirst); |
|
637 | // columnCount = qMin(m_mapCount, m_model->columnCount() - m_mapFirst); | |
622 | // for (int k = m_mapFirst; k < m_mapFirst + columnCount; k++) { |
|
638 | // for (int k = m_mapFirst; k < m_mapFirst + columnCount; k++) { | |
623 | // m_categories << m_model->data(m_model->index(m_mapCategories, k), Qt::DisplayRole).toString(); |
|
639 | // m_categories << m_model->data(m_model->index(m_mapCategories, k), Qt::DisplayRole).toString(); | |
624 | // } |
|
640 | // } | |
625 |
|
641 | |||
626 | // for (int i = m_mapBarBottom; i <= m_mapBarTop; i++) { |
|
642 | // for (int i = m_mapBarBottom; i <= m_mapBarTop; i++) { | |
627 | // QBarSet* barSet = new QBarSet(m_model->headerData(i, Qt::Vertical, Qt::DisplayRole).toString()); |
|
643 | // QBarSet* barSet = new QBarSet(m_model->headerData(i, Qt::Vertical, Qt::DisplayRole).toString()); | |
628 | // for(int m = m_mapFirst; m < m_mapFirst + columnCount; m++) |
|
644 | // for(int m = m_mapFirst; m < m_mapFirst + columnCount; m++) | |
629 | // *barSet << m_model->data(m_model->index(i, m), Qt::DisplayRole).toDouble(); |
|
645 | // *barSet << m_model->data(m_model->index(i, m), Qt::DisplayRole).toDouble(); | |
630 | // q->appendBarSet(barSet); |
|
646 | // q->appendBarSet(barSet); | |
631 | // } |
|
647 | // } | |
632 | // } |
|
648 | // } | |
633 | // emit restructuredBars(); |
|
649 | // emit restructuredBars(); | |
634 | //// emit updatedBars(); |
|
650 | //// emit updatedBars(); | |
635 | //} |
|
651 | //} | |
636 |
|
652 | |||
637 | void QBarSeriesPrivate::insertCategory(int index, const QString category) |
|
653 | void QBarSeriesPrivate::insertCategory(int index, const QString category) | |
638 | { |
|
654 | { | |
639 | m_categories.insert(index, category); |
|
655 | m_categories.insert(index, category); | |
640 | emit categoriesUpdated(); |
|
656 | emit categoriesUpdated(); | |
641 | } |
|
657 | } | |
642 |
|
658 | |||
643 | void QBarSeriesPrivate::removeCategory(int index) |
|
659 | void QBarSeriesPrivate::removeCategory(int index) | |
644 | { |
|
660 | { | |
645 | m_categories.removeAt(index); |
|
661 | m_categories.removeAt(index); | |
646 | emit categoriesUpdated(); |
|
662 | emit categoriesUpdated(); | |
647 | } |
|
663 | } | |
648 |
|
664 | |||
649 | void QBarSeriesPrivate::barsetChanged() |
|
665 | void QBarSeriesPrivate::barsetChanged() | |
650 | { |
|
666 | { | |
651 | emit updatedBars(); |
|
667 | emit updatedBars(); | |
652 | } |
|
668 | } | |
653 |
|
669 | |||
654 | void QBarSeriesPrivate::scaleDomain(Domain& domain) |
|
670 | void QBarSeriesPrivate::scaleDomain(Domain& domain) | |
655 | { |
|
671 | { | |
656 | qreal minX(domain.minX()); |
|
672 | qreal minX(domain.minX()); | |
657 | qreal minY(domain.minY()); |
|
673 | qreal minY(domain.minY()); | |
658 | qreal maxX(domain.maxX()); |
|
674 | qreal maxX(domain.maxX()); | |
659 | qreal maxY(domain.maxY()); |
|
675 | qreal maxY(domain.maxY()); | |
660 | int tickXCount(domain.tickXCount()); |
|
676 | int tickXCount(domain.tickXCount()); | |
661 | int tickYCount(domain.tickYCount()); |
|
677 | int tickYCount(domain.tickYCount()); | |
662 |
|
678 | |||
663 | qreal x = m_categories.count(); |
|
679 | qreal x = m_categories.count(); | |
664 | qreal y = max(); |
|
680 | qreal y = max(); | |
665 | minX = qMin(minX, x); |
|
681 | minX = qMin(minX, x); | |
666 | minY = qMin(minY, y); |
|
682 | minY = qMin(minY, y); | |
667 | maxX = qMax(maxX, x); |
|
683 | maxX = qMax(maxX, x); | |
668 | maxY = qMax(maxY, y); |
|
684 | maxY = qMax(maxY, y); | |
669 | tickXCount = x+1; |
|
685 | tickXCount = x+1; | |
670 |
|
686 | |||
671 | domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount); |
|
687 | domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount); | |
672 | } |
|
688 | } | |
673 |
|
689 | |||
674 | Chart* QBarSeriesPrivate::createGraphics(ChartPresenter* presenter) |
|
690 | Chart* QBarSeriesPrivate::createGraphics(ChartPresenter* presenter) | |
675 | { |
|
691 | { | |
676 | Q_Q(QBarSeries); |
|
692 | Q_Q(QBarSeries); | |
677 |
|
693 | |||
678 | BarChartItem* bar = new BarChartItem(q,presenter); |
|
694 | BarChartItem* bar = new BarChartItem(q,presenter); | |
679 | if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { |
|
695 | if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { | |
680 | presenter->animator()->addAnimation(bar); |
|
696 | presenter->animator()->addAnimation(bar); | |
681 | } |
|
697 | } | |
682 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); |
|
698 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); | |
683 | return bar; |
|
699 | return bar; | |
684 |
|
700 | |||
685 | } |
|
701 | } | |
686 |
|
702 | |||
687 | QList<LegendMarker*> QBarSeriesPrivate::createLegendMarker(QLegend* legend) |
|
703 | QList<LegendMarker*> QBarSeriesPrivate::createLegendMarker(QLegend* legend) | |
688 | { |
|
704 | { | |
689 | Q_Q(QBarSeries); |
|
705 | Q_Q(QBarSeries); | |
690 | QList<LegendMarker*> markers; |
|
706 | QList<LegendMarker*> markers; | |
691 | foreach(QBarSet* set, q->barSets()) { |
|
707 | foreach(QBarSet* set, q->barSets()) { | |
692 | BarLegendMarker* marker = new BarLegendMarker(q,set,legend); |
|
708 | BarLegendMarker* marker = new BarLegendMarker(q,set,legend); | |
693 | markers << marker; |
|
709 | markers << marker; | |
694 | } |
|
710 | } | |
695 |
|
711 | |||
696 | return markers; |
|
712 | return markers; | |
697 | } |
|
713 | } | |
698 |
|
714 | |||
699 | #include "moc_qbarseries.cpp" |
|
715 | #include "moc_qbarseries.cpp" | |
700 | #include "moc_qbarseries_p.cpp" |
|
716 | #include "moc_qbarseries_p.cpp" | |
701 |
|
717 | |||
702 | QTCOMMERCIALCHART_END_NAMESPACE |
|
718 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,82 +1,80 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #ifndef BARSERIES_H |
|
21 | #ifndef BARSERIES_H | |
22 | #define BARSERIES_H |
|
22 | #define BARSERIES_H | |
23 |
|
23 | |||
24 | #include <qabstractseries.h> |
|
24 | #include <qabstractseries.h> | |
25 | #include <QStringList> |
|
25 | #include <QStringList> | |
26 |
|
26 | |||
27 | class QModelIndex; |
|
27 | class QModelIndex; | |
28 |
|
28 | |||
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
30 |
|
30 | |||
31 | typedef QStringList QBarCategories; |
|
31 | typedef QStringList QBarCategories; | |
32 |
|
32 | |||
33 | class QBarSet; |
|
33 | class QBarSet; | |
34 | class BarCategory; |
|
34 | class BarCategory; | |
35 | class QBarSeriesPrivate; |
|
35 | class QBarSeriesPrivate; | |
36 |
|
36 | |||
37 | // Container for series |
|
37 | // Container for series | |
38 | class QTCOMMERCIALCHART_EXPORT QBarSeries : public QAbstractSeries |
|
38 | class QTCOMMERCIALCHART_EXPORT QBarSeries : public QAbstractSeries | |
39 | { |
|
39 | { | |
40 | Q_OBJECT |
|
40 | Q_OBJECT | |
41 | public: |
|
41 | public: | |
42 |
explicit QBarSeries( |
|
42 | explicit QBarSeries(QObject *parent = 0); | |
43 | virtual ~QBarSeries(); |
|
43 | virtual ~QBarSeries(); | |
44 |
|
44 | |||
45 | QAbstractSeries::SeriesType type() const; |
|
45 | QAbstractSeries::SeriesType type() const; | |
46 | void setCategories(QBarCategories categories); |
|
46 | void setCategories(QBarCategories categories); | |
47 |
|
47 | |||
48 | bool appendBarSet(QBarSet *set); // Takes ownership of set |
|
48 | bool appendBarSet(QBarSet *set); // Takes ownership of set | |
49 | bool removeBarSet(QBarSet *set); // Releases ownership, doesn't delete set |
|
49 | bool removeBarSet(QBarSet *set); // Releases ownership, doesn't delete set | |
50 | bool appendBarSets(QList<QBarSet* > sets); |
|
50 | bool appendBarSets(QList<QBarSet* > sets); | |
51 | bool removeBarSets(QList<QBarSet* > sets); |
|
51 | bool removeBarSets(QList<QBarSet* > sets); | |
52 | int barsetCount() const; |
|
52 | int barsetCount() const; | |
53 | int categoryCount() const; |
|
53 | int categoryCount() const; | |
54 | QList<QBarSet*> barSets() const; |
|
54 | QList<QBarSet*> barSets() const; | |
55 | QBarCategories categories() const; |
|
55 | QBarCategories categories() const; | |
56 |
|
56 | |||
57 | void setLabelsVisible(bool visible = true); |
|
57 | void setLabelsVisible(bool visible = true); | |
58 | // TODO: |
|
|||
59 | // void setGroupedDrawing(bool on = true); // By default this is on. Bars are grouped next to each other. If off, bars are drawn at their x-position (propably on top of each other) |
|
|||
60 | // void setBarMargin(int margin); // Margin that is left between bars (if drawn as grouped bars) |
|
|||
61 |
|
58 | |||
62 | void setModel(QAbstractItemModel *model); |
|
59 | void setModel(QAbstractItemModel *model); | |
63 | // void setModelMapping(int categories, int bottomBoundary, int topBoundary, Qt::Orientation orientation = Qt::Vertical); |
|
60 | // void setModelMapping(int categories, int bottomBoundary, int topBoundary, Qt::Orientation orientation = Qt::Vertical); | |
64 | // void setModelMappingRange(int first, int count = -1); |
|
61 | // void setModelMappingRange(int first, int count = -1); | |
65 |
|
62 | |||
66 | protected: |
|
63 | protected: | |
67 | explicit QBarSeries(QBarSeriesPrivate &d,QObject *parent = 0); |
|
64 | explicit QBarSeries(QBarSeriesPrivate &d,QObject *parent = 0); | |
68 |
|
65 | |||
69 | Q_SIGNALS: |
|
66 | Q_SIGNALS: | |
70 | void clicked(QBarSet *barset, QString category); |
|
67 | void clicked(QBarSet *barset, QString category); | |
71 | void hovered(QBarSet* barset, bool status); |
|
68 | void hovered(QBarSet* barset, bool status); | |
72 |
|
69 | |||
73 | protected: |
|
70 | protected: | |
74 | Q_DECLARE_PRIVATE(QBarSeries) |
|
71 | Q_DECLARE_PRIVATE(QBarSeries) | |
75 | friend class BarChartItem; |
|
72 | friend class BarChartItem; | |
76 | friend class PercentBarChartItem; |
|
73 | friend class PercentBarChartItem; | |
77 | friend class StackedBarChartItem; |
|
74 | friend class StackedBarChartItem; | |
|
75 | friend class GroupedBarChartItem; | |||
78 | }; |
|
76 | }; | |
79 |
|
77 | |||
80 | QTCOMMERCIALCHART_END_NAMESPACE |
|
78 | QTCOMMERCIALCHART_END_NAMESPACE | |
81 |
|
79 | |||
82 | #endif // BARSERIES_H |
|
80 | #endif // BARSERIES_H |
@@ -1,69 +1,72 | |||||
1 | #ifndef QBARSERIES_P_H |
|
1 | #ifndef QBARSERIES_P_H | |
2 | #define QBARSERIES_P_H |
|
2 | #define QBARSERIES_P_H | |
3 |
|
3 | |||
4 | #include "qbarseries.h" |
|
4 | #include "qbarseries.h" | |
5 | #include "qabstractseries_p.h" |
|
5 | #include "qabstractseries_p.h" | |
6 | #include <QStringList> |
|
6 | #include <QStringList> | |
7 | #include <QAbstractSeries> |
|
7 | #include <QAbstractSeries> | |
8 |
|
8 | |||
9 | class QModelIndex; |
|
9 | class QModelIndex; | |
10 |
|
10 | |||
11 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
11 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
12 |
|
12 | |||
13 | // Container for series |
|
13 | // Container for series | |
14 | class QBarSeriesPrivate : public QAbstractSeriesPrivate |
|
14 | class QBarSeriesPrivate : public QAbstractSeriesPrivate | |
15 | { |
|
15 | { | |
16 | Q_OBJECT |
|
16 | Q_OBJECT | |
17 | public: |
|
17 | public: | |
18 |
QBarSeriesPrivate( |
|
18 | QBarSeriesPrivate(QBarSeries *parent); | |
19 | void setCategories(QBarCategories categories); |
|
19 | void setCategories(QBarCategories categories); | |
|
20 | void setBarMargin(qreal margin); | |||
|
21 | qreal barMargin(); | |||
20 |
|
22 | |||
21 | void scaleDomain(Domain& domain); |
|
23 | void scaleDomain(Domain& domain); | |
22 | Chart* createGraphics(ChartPresenter* presenter); |
|
24 | Chart* createGraphics(ChartPresenter* presenter); | |
23 | QList<LegendMarker*> createLegendMarker(QLegend* legend); |
|
25 | QList<LegendMarker*> createLegendMarker(QLegend* legend); | |
24 |
|
26 | |||
25 | // void setModel(QAbstractItemModel *model); |
|
27 | // void setModel(QAbstractItemModel *model); | |
26 | // void setModelMapping(int categories, int bottomBoundry, int topBoundry, Qt::Orientation orientation = Qt::Vertical); |
|
28 | // void setModelMapping(int categories, int bottomBoundry, int topBoundry, Qt::Orientation orientation = Qt::Vertical); | |
27 | // void setModelMappingRange(int first, int count = -1); |
|
29 | // void setModelMappingRange(int first, int count = -1); | |
28 |
|
30 | |||
29 | void insertCategory(int index, const QString category); |
|
31 | void insertCategory(int index, const QString category); | |
30 | void removeCategory(int index); |
|
32 | void removeCategory(int index); | |
31 |
|
33 | |||
32 | QBarSet* barsetAt(int index); |
|
34 | QBarSet* barsetAt(int index); | |
33 | QString categoryName(int category); |
|
35 | QString categoryName(int category); | |
34 | qreal min(); |
|
36 | qreal min(); | |
35 | qreal max(); |
|
37 | qreal max(); | |
36 | qreal valueAt(int set, int category); |
|
38 | qreal valueAt(int set, int category); | |
37 | qreal percentageAt(int set, int category); |
|
39 | qreal percentageAt(int set, int category); | |
38 | qreal categorySum(int category); |
|
40 | qreal categorySum(int category); | |
39 | qreal absoluteCategorySum(int category); |
|
41 | qreal absoluteCategorySum(int category); | |
40 | qreal maxCategorySum(); |
|
42 | qreal maxCategorySum(); | |
41 |
|
43 | |||
42 | Q_SIGNALS: |
|
44 | Q_SIGNALS: | |
43 | void clicked(QBarSet *barset, QString category); |
|
45 | void clicked(QBarSet *barset, QString category); | |
44 | void updatedBars(); |
|
46 | void updatedBars(); | |
45 | void restructuredBars(); |
|
47 | void restructuredBars(); | |
46 | void categoriesUpdated(); |
|
48 | void categoriesUpdated(); | |
47 |
|
49 | |||
48 | private Q_SLOTS: |
|
50 | private Q_SLOTS: | |
49 | // slots for updating bars when data in model changes |
|
51 | // slots for updating bars when data in model changes | |
50 | // void modelUpdated(QModelIndex topLeft, QModelIndex bottomRight); |
|
52 | // void modelUpdated(QModelIndex topLeft, QModelIndex bottomRight); | |
51 | void modelDataAdded(QModelIndex parent, int start, int end); |
|
53 | void modelDataAdded(QModelIndex parent, int start, int end); | |
52 | void modelDataRemoved(QModelIndex parent, int start, int end); |
|
54 | void modelDataRemoved(QModelIndex parent, int start, int end); | |
53 | // void initializeDataFromModel(); |
|
55 | // void initializeDataFromModel(); | |
54 | void barsetChanged(); |
|
56 | void barsetChanged(); | |
55 |
|
57 | |||
56 | protected: |
|
58 | protected: | |
57 | QList<QBarSet *> m_barSets; |
|
59 | QList<QBarSet *> m_barSets; | |
58 | QBarCategories m_categories; |
|
60 | QBarCategories m_categories; | |
59 |
|
61 | |||
|
62 | qreal m_barMargin; | |||
60 | int m_mapCategories; |
|
63 | int m_mapCategories; | |
61 | int m_mapBarBottom; |
|
64 | int m_mapBarBottom; | |
62 | int m_mapBarTop; |
|
65 | int m_mapBarTop; | |
63 | private: |
|
66 | private: | |
64 | Q_DECLARE_PUBLIC(QBarSeries) |
|
67 | Q_DECLARE_PUBLIC(QBarSeries) | |
65 | }; |
|
68 | }; | |
66 |
|
69 | |||
67 | QTCOMMERCIALCHART_END_NAMESPACE |
|
70 | QTCOMMERCIALCHART_END_NAMESPACE | |
68 |
|
71 | |||
69 | #endif // QBARSERIESPRIVATE_P_H |
|
72 | #endif // QBARSERIESPRIVATE_P_H |
@@ -1,306 +1,339 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "qbarset.h" |
|
21 | #include "qbarset.h" | |
22 | #include "qbarset_p.h" |
|
22 | #include "qbarset_p.h" | |
23 |
|
23 | |||
24 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
24 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
25 |
|
25 | |||
26 | /*! |
|
26 | /*! | |
27 | \class QBarSet |
|
27 | \class QBarSet | |
28 | \brief part of QtCommercial chart API. |
|
28 | \brief part of QtCommercial chart API. | |
29 |
|
29 | |||
30 | QBarSet represents one set of bars. Set of bars contains one data value for each category. |
|
30 | QBarSet represents one set of bars. Set of bars contains one data value for each category. | |
31 | First value of set is assumed to belong to first category, second to second category and so on. |
|
31 | First value of set is assumed to belong to first category, second to second category and so on. | |
32 | If set has fewer values than there are categories, then the missing values are assumed to be |
|
32 | If set has fewer values than there are categories, then the missing values are assumed to be | |
33 | at the end of set. For missing values in middle of a set, numerical value of zero is used. |
|
33 | at the end of set. For missing values in middle of a set, numerical value of zero is used. | |
34 |
|
34 | |||
35 | \mainclass |
|
35 | \mainclass | |
36 |
|
36 | |||
37 | \sa QBarSeries, QStackedBarSeries, QPercentBarSeries |
|
37 | \sa QBarSeries, QStackedBarSeries, QPercentBarSeries | |
38 | */ |
|
38 | */ | |
39 |
|
39 | |||
40 | /*! |
|
40 | /*! | |
41 | \fn void QBarSet::clicked(QString category) |
|
41 | \fn void QBarSet::clicked(QString category) | |
42 | \brief signals that set has been clicked |
|
42 | \brief signals that set has been clicked | |
43 | Parameter \a category describes on which category was clicked |
|
43 | Parameter \a category describes on which category was clicked | |
44 | */ |
|
44 | */ | |
45 |
|
45 | |||
46 | /*! |
|
46 | /*! | |
47 | \fn void QBarSet::hovered(bool status) |
|
47 | \fn void QBarSet::hovered(bool status) | |
48 | \brief signals that mouse has hovered over the set. If \a status is true, then mouse was entered. If \a status is false, then mouse was left. |
|
48 | \brief signals that mouse has hovered over the set. If \a status is true, then mouse was entered. If \a status is false, then mouse was left. | |
49 |
|
49 | |||
50 | The signal is emitted if mouse is hovered on top of set |
|
50 | The signal is emitted if mouse is hovered on top of set | |
51 | Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series. |
|
51 | Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series. | |
52 | */ |
|
52 | */ | |
53 |
|
53 | |||
54 | /*! |
|
54 | /*! | |
55 | Constructs QBarSet with a name of \a name and with parent of \a parent |
|
55 | Constructs QBarSet with a name of \a name and with parent of \a parent | |
56 | */ |
|
56 | */ | |
57 | QBarSet::QBarSet(const QString name, QObject *parent) |
|
57 | QBarSet::QBarSet(const QString name, QObject *parent) | |
58 | : QObject(parent) |
|
58 | : QObject(parent) | |
59 | ,d_ptr(new QBarSetPrivate(name,this)) |
|
59 | ,d_ptr(new QBarSetPrivate(name,this)) | |
60 | { |
|
60 | { | |
61 | } |
|
61 | } | |
62 |
|
62 | |||
63 | /*! |
|
63 | /*! | |
64 | Destroys the barset |
|
64 | Destroys the barset | |
65 | */ |
|
65 | */ | |
66 | QBarSet::~QBarSet() |
|
66 | QBarSet::~QBarSet() | |
67 | { |
|
67 | { | |
68 | // NOTE: d_ptr destroyed by QObject |
|
68 | // NOTE: d_ptr destroyed by QObject | |
69 | } |
|
69 | } | |
70 |
|
70 | |||
71 | /*! |
|
71 | /*! | |
72 | Sets new \a name for set. |
|
72 | Sets new \a name for set. | |
73 | */ |
|
73 | */ | |
74 | void QBarSet::setName(const QString name) |
|
74 | void QBarSet::setName(const QString name) | |
75 | { |
|
75 | { | |
76 | d_ptr->m_name = name; |
|
76 | d_ptr->m_name = name; | |
77 | } |
|
77 | } | |
78 |
|
78 | |||
79 | /*! |
|
79 | /*! | |
80 | Returns name of the set. |
|
80 | Returns name of the set. | |
81 | */ |
|
81 | */ | |
82 | QString QBarSet::name() const |
|
82 | QString QBarSet::name() const | |
83 | { |
|
83 | { | |
84 | return d_ptr->m_name; |
|
84 | return d_ptr->m_name; | |
85 | } |
|
85 | } | |
86 |
|
86 | |||
|
87 | void QBarSet::append(const QPointF value) | |||
|
88 | { | |||
|
89 | d_ptr->m_values.append(value); | |||
|
90 | emit d_ptr->restructuredBars(); | |||
|
91 | } | |||
|
92 | ||||
|
93 | ||||
|
94 | void QBarSet::append(const QList<QPointF> values) | |||
|
95 | { | |||
|
96 | for (int i=0; i<values.count(); i++) { | |||
|
97 | d_ptr->m_values.append(values.at(i)); | |||
|
98 | } | |||
|
99 | emit d_ptr->restructuredBars(); | |||
|
100 | } | |||
|
101 | ||||
87 | /*! |
|
102 | /*! | |
88 | Appends new value \a value to the end of set. |
|
103 | Appends new value \a value to the end of set. | |
89 | */ |
|
104 | */ | |
90 | void QBarSet::append(const qreal value) |
|
105 | void QBarSet::append(const qreal value) | |
91 | { |
|
106 | { | |
92 |
d_ptr->m_values. |
|
107 | append(QPointF(d_ptr->m_values.count(), value)); | |
|
108 | // d_ptr->m_values.append(value); | |||
|
109 | } | |||
|
110 | ||||
|
111 | ||||
|
112 | void QBarSet::append(const QList<qreal> values) | |||
|
113 | { | |||
|
114 | int index = d_ptr->m_values.count(); | |||
|
115 | for (int i=0; i<values.count(); i++) { | |||
|
116 | d_ptr->m_values.append(QPointF(index,values.at(i))); | |||
|
117 | index++; | |||
|
118 | } | |||
93 | emit d_ptr->restructuredBars(); |
|
119 | emit d_ptr->restructuredBars(); | |
94 | } |
|
120 | } | |
95 |
|
121 | |||
96 | /*! |
|
122 | /*! | |
97 | Appends new value \a value to the end of set. |
|
123 | Appends new value \a value to the end of set. | |
98 | */ |
|
124 | */ | |
99 | QBarSet& QBarSet::operator << (const qreal &value) |
|
125 | QBarSet& QBarSet::operator << (const qreal &value) | |
100 | { |
|
126 | { | |
101 | append(value); |
|
127 | append(value); | |
102 | return *this; |
|
128 | return *this; | |
103 | } |
|
129 | } | |
104 |
|
130 | |||
|
131 | QBarSet& QBarSet::operator << (const QPointF &value) | |||
|
132 | { | |||
|
133 | append(value); | |||
|
134 | return *this; | |||
|
135 | } | |||
|
136 | ||||
105 | /*! |
|
137 | /*! | |
106 | Inserts new \a value on the \a index position. |
|
138 | Inserts new \a value on the \a index position. | |
107 | The value that is currently at this postion is moved to postion index + 1 |
|
139 | The value that is currently at this postion is moved to postion index + 1 | |
108 | \sa remove() |
|
140 | \sa remove() | |
109 | */ |
|
141 | */ | |
110 | void QBarSet::insert(const int index, const qreal value) |
|
142 | void QBarSet::insert(const int index, const qreal value) | |
111 | { |
|
143 | { | |
112 | d_ptr->m_values.insert(index, value); |
|
144 | d_ptr->m_values.insert(index, QPointF(index, value)); | |
113 | // emit d_ptr->updatedBars(); |
|
145 | // emit d_ptr->updatedBars(); | |
114 | } |
|
146 | } | |
115 |
|
147 | |||
116 | /*! |
|
148 | /*! | |
117 | Removes the value specified by \a index |
|
149 | Removes the value specified by \a index | |
118 | \sa insert() |
|
150 | \sa insert() | |
119 | */ |
|
151 | */ | |
120 | void QBarSet::remove(const int index) |
|
152 | void QBarSet::remove(const int index) | |
121 | { |
|
153 | { | |
122 | d_ptr->m_values.removeAt(index); |
|
154 | d_ptr->m_values.removeAt(index); | |
123 | // emit d_ptr->updatedBars(); |
|
155 | // emit d_ptr->updatedBars(); | |
124 | } |
|
156 | } | |
125 |
|
157 | |||
126 | /*! |
|
158 | /*! | |
127 | Sets a new value \a value to set, indexed by \a index |
|
159 | Sets a new value \a value to set, indexed by \a index | |
128 | */ |
|
160 | */ | |
129 | void QBarSet::replace(const int index, const qreal value) |
|
161 | void QBarSet::replace(const int index, const qreal value) | |
130 | { |
|
162 | { | |
131 | d_ptr->m_values.replace(index,value); |
|
163 | d_ptr->m_values.replace(index,QPointF(index,value)); | |
132 | emit d_ptr->updatedBars(); |
|
164 | emit d_ptr->updatedBars(); | |
133 | } |
|
165 | } | |
134 |
|
166 | |||
135 | /*! |
|
167 | /*! | |
136 | Returns value of set indexed by \a index |
|
168 | Returns value of set indexed by \a index. Note that all appended values are stored internally as QPointF | |
137 | */ |
|
169 | */ | |
138 |
|
|
170 | QPointF QBarSet::at(const int index) const | |
139 | { |
|
171 | { | |
140 | if (index < 0 || index >= d_ptr->m_values.count()) |
|
172 | if (index < 0 || index >= d_ptr->m_values.count()) | |
141 | return 0.0; |
|
173 | return 0.0; | |
142 |
|
174 | |||
143 | return d_ptr->m_values.at(index); |
|
175 | return d_ptr->m_values.at(index); | |
144 | } |
|
176 | } | |
145 |
|
177 | |||
146 | /*! |
|
178 | /*! | |
147 | Returns value of set indexed by \a index |
|
179 | Returns value of set indexed by \a index | |
148 | */ |
|
180 | */ | |
149 |
|
|
181 | QPointF QBarSet::operator [](const int index) const | |
150 | { |
|
182 | { | |
151 | return d_ptr->m_values.at(index); |
|
183 | return d_ptr->m_values.at(index); | |
152 | } |
|
184 | } | |
153 |
|
185 | |||
154 | /*! |
|
186 | /*! | |
155 | Returns count of values in set. |
|
187 | Returns count of values in set. | |
156 | */ |
|
188 | */ | |
157 | int QBarSet::count() const |
|
189 | int QBarSet::count() const | |
158 | { |
|
190 | { | |
159 | return d_ptr->m_values.count(); |
|
191 | return d_ptr->m_values.count(); | |
160 | } |
|
192 | } | |
161 |
|
193 | |||
162 | /*! |
|
194 | /*! | |
163 | Returns sum of all values in barset. |
|
195 | Returns sum of all values in barset. | |
164 | */ |
|
196 | */ | |
165 | qreal QBarSet::sum() const |
|
197 | qreal QBarSet::sum() const | |
166 | { |
|
198 | { | |
167 | qreal total(0); |
|
199 | qreal total(0); | |
168 | for (int i=0; i < d_ptr->m_values.count(); i++) { |
|
200 | for (int i=0; i < d_ptr->m_values.count(); i++) { | |
169 | total += d_ptr->m_values.at(i); |
|
201 | //total += d_ptr->m_values.at(i); | |
|
202 | total += d_ptr->m_values.at(i).y(); | |||
170 | } |
|
203 | } | |
171 | return total; |
|
204 | return total; | |
172 | } |
|
205 | } | |
173 |
|
206 | |||
174 | /*! |
|
207 | /*! | |
175 | Sets pen for set. Bars of this set are drawn using \a pen |
|
208 | Sets pen for set. Bars of this set are drawn using \a pen | |
176 | */ |
|
209 | */ | |
177 | void QBarSet::setPen(const QPen &pen) |
|
210 | void QBarSet::setPen(const QPen &pen) | |
178 | { |
|
211 | { | |
179 | if(d_ptr->m_pen!=pen){ |
|
212 | if(d_ptr->m_pen!=pen){ | |
180 | d_ptr->m_pen = pen; |
|
213 | d_ptr->m_pen = pen; | |
181 | emit d_ptr->updatedBars(); |
|
214 | emit d_ptr->updatedBars(); | |
182 | } |
|
215 | } | |
183 | } |
|
216 | } | |
184 |
|
217 | |||
185 | /*! |
|
218 | /*! | |
186 | Returns pen of the set. |
|
219 | Returns pen of the set. | |
187 | */ |
|
220 | */ | |
188 | QPen QBarSet::pen() const |
|
221 | QPen QBarSet::pen() const | |
189 | { |
|
222 | { | |
190 | return d_ptr->m_pen; |
|
223 | return d_ptr->m_pen; | |
191 | } |
|
224 | } | |
192 |
|
225 | |||
193 | /*! |
|
226 | /*! | |
194 | Sets brush for the set. Bars of this set are drawn using \a brush |
|
227 | Sets brush for the set. Bars of this set are drawn using \a brush | |
195 | */ |
|
228 | */ | |
196 | void QBarSet::setBrush(const QBrush &brush) |
|
229 | void QBarSet::setBrush(const QBrush &brush) | |
197 | { |
|
230 | { | |
198 | if(d_ptr->m_brush!=brush){ |
|
231 | if(d_ptr->m_brush!=brush){ | |
199 | d_ptr->m_brush = brush; |
|
232 | d_ptr->m_brush = brush; | |
200 | emit d_ptr->updatedBars(); |
|
233 | emit d_ptr->updatedBars(); | |
201 | } |
|
234 | } | |
202 | } |
|
235 | } | |
203 |
|
236 | |||
204 | /*! |
|
237 | /*! | |
205 | Returns brush of the set. |
|
238 | Returns brush of the set. | |
206 | */ |
|
239 | */ | |
207 | QBrush QBarSet::brush() const |
|
240 | QBrush QBarSet::brush() const | |
208 | { |
|
241 | { | |
209 | return d_ptr->m_brush; |
|
242 | return d_ptr->m_brush; | |
210 | } |
|
243 | } | |
211 |
|
244 | |||
212 | /*! |
|
245 | /*! | |
213 | Sets \a pen of the values that are drawn on top of this barset |
|
246 | Sets \a pen of the values that are drawn on top of this barset | |
214 | */ |
|
247 | */ | |
215 | void QBarSet::setLabelPen(const QPen &pen) |
|
248 | void QBarSet::setLabelPen(const QPen &pen) | |
216 | { |
|
249 | { | |
217 | if(d_ptr->m_labelPen!=pen){ |
|
250 | if(d_ptr->m_labelPen!=pen){ | |
218 | d_ptr->m_labelPen = pen; |
|
251 | d_ptr->m_labelPen = pen; | |
219 | emit d_ptr->updatedBars(); |
|
252 | emit d_ptr->updatedBars(); | |
220 | } |
|
253 | } | |
221 | } |
|
254 | } | |
222 |
|
255 | |||
223 | /*! |
|
256 | /*! | |
224 | Returns pen of the values that are drawn on top of this barset |
|
257 | Returns pen of the values that are drawn on top of this barset | |
225 | */ |
|
258 | */ | |
226 | QPen QBarSet::labelPen() const |
|
259 | QPen QBarSet::labelPen() const | |
227 | { |
|
260 | { | |
228 | return d_ptr->m_labelPen; |
|
261 | return d_ptr->m_labelPen; | |
229 | } |
|
262 | } | |
230 |
|
263 | |||
231 | /*! |
|
264 | /*! | |
232 | Sets \a brush of the values that are drawn on top of this barset |
|
265 | Sets \a brush of the values that are drawn on top of this barset | |
233 | */ |
|
266 | */ | |
234 | void QBarSet::setLabelBrush(const QBrush &brush) |
|
267 | void QBarSet::setLabelBrush(const QBrush &brush) | |
235 | { |
|
268 | { | |
236 | if(d_ptr->m_labelBrush!=brush){ |
|
269 | if(d_ptr->m_labelBrush!=brush){ | |
237 | d_ptr->m_labelBrush = brush; |
|
270 | d_ptr->m_labelBrush = brush; | |
238 | emit d_ptr->updatedBars(); |
|
271 | emit d_ptr->updatedBars(); | |
239 | } |
|
272 | } | |
240 | } |
|
273 | } | |
241 |
|
274 | |||
242 | /*! |
|
275 | /*! | |
243 | Returns brush of the values that are drawn on top of this barset |
|
276 | Returns brush of the values that are drawn on top of this barset | |
244 | */ |
|
277 | */ | |
245 | QBrush QBarSet::labelBrush() const |
|
278 | QBrush QBarSet::labelBrush() const | |
246 | { |
|
279 | { | |
247 | return d_ptr->m_labelBrush; |
|
280 | return d_ptr->m_labelBrush; | |
248 | } |
|
281 | } | |
249 |
|
282 | |||
250 | /*! |
|
283 | /*! | |
251 | Sets the \a font for values that are drawn on top of this barset |
|
284 | Sets the \a font for values that are drawn on top of this barset | |
252 | */ |
|
285 | */ | |
253 | void QBarSet::setLabelFont(const QFont &font) |
|
286 | void QBarSet::setLabelFont(const QFont &font) | |
254 | { |
|
287 | { | |
255 | if(d_ptr->m_labelFont!=font) { |
|
288 | if(d_ptr->m_labelFont!=font) { | |
256 | d_ptr->m_labelFont = font; |
|
289 | d_ptr->m_labelFont = font; | |
257 | emit d_ptr->updatedBars(); |
|
290 | emit d_ptr->updatedBars(); | |
258 | } |
|
291 | } | |
259 |
|
292 | |||
260 | } |
|
293 | } | |
261 |
|
294 | |||
262 | /*! |
|
295 | /*! | |
263 | Returns the pen for values that are drawn on top of this set |
|
296 | Returns the pen for values that are drawn on top of this set | |
264 | */ |
|
297 | */ | |
265 | QFont QBarSet::labelFont() const |
|
298 | QFont QBarSet::labelFont() const | |
266 | { |
|
299 | { | |
267 | return d_ptr->m_labelFont; |
|
300 | return d_ptr->m_labelFont; | |
268 | } |
|
301 | } | |
269 |
|
302 | |||
270 | /*! |
|
303 | /*! | |
271 | Sets visibility of bar labels. If \a visible is true, labels are drawn on top of barsets. |
|
304 | Sets visibility of bar labels. If \a visible is true, labels are drawn on top of barsets. | |
272 | */ |
|
305 | */ | |
273 |
|
306 | |||
274 | void QBarSet::setLabelsVisible(bool visible) |
|
307 | void QBarSet::setLabelsVisible(bool visible) | |
275 | { |
|
308 | { | |
276 | if(d_ptr->m_labelsVisible!=visible) { |
|
309 | if(d_ptr->m_labelsVisible!=visible) { | |
277 | d_ptr->m_labelsVisible = visible; |
|
310 | d_ptr->m_labelsVisible = visible; | |
278 | emit d_ptr->labelsVisibleChanged(visible); |
|
311 | emit d_ptr->labelsVisibleChanged(visible); | |
279 | } |
|
312 | } | |
280 | } |
|
313 | } | |
281 |
|
314 | |||
282 | /*! |
|
315 | /*! | |
283 | Returns the visibility of values |
|
316 | Returns the visibility of values | |
284 | */ |
|
317 | */ | |
285 | bool QBarSet::labelsVisible() const |
|
318 | bool QBarSet::labelsVisible() const | |
286 | { |
|
319 | { | |
287 | return d_ptr->m_labelsVisible; |
|
320 | return d_ptr->m_labelsVisible; | |
288 | } |
|
321 | } | |
289 |
|
322 | |||
290 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
323 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
291 |
|
324 | |||
292 | QBarSetPrivate::QBarSetPrivate(const QString name, QBarSet *parent) : QObject(parent), |
|
325 | QBarSetPrivate::QBarSetPrivate(const QString name, QBarSet *parent) : QObject(parent), | |
293 | q_ptr(parent), |
|
326 | q_ptr(parent), | |
294 | m_name(name), |
|
327 | m_name(name), | |
295 | m_labelsVisible(false) |
|
328 | m_labelsVisible(false) | |
296 | { |
|
329 | { | |
297 | } |
|
330 | } | |
298 |
|
331 | |||
299 | QBarSetPrivate::~QBarSetPrivate() |
|
332 | QBarSetPrivate::~QBarSetPrivate() | |
300 | { |
|
333 | { | |
301 | } |
|
334 | } | |
302 |
|
335 | |||
303 | #include "moc_qbarset.cpp" |
|
336 | #include "moc_qbarset.cpp" | |
304 | #include "moc_qbarset_p.cpp" |
|
337 | #include "moc_qbarset_p.cpp" | |
305 |
|
338 | |||
306 | QTCOMMERCIALCHART_END_NAMESPACE |
|
339 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,97 +1,93 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #ifndef QBARSET_H |
|
21 | #ifndef QBARSET_H | |
22 | #define QBARSET_H |
|
22 | #define QBARSET_H | |
23 |
|
23 | |||
24 | #include <qchartglobal.h> |
|
24 | #include <qchartglobal.h> | |
25 | #include <QPen> |
|
25 | #include <QPen> | |
26 | #include <QBrush> |
|
26 | #include <QBrush> | |
27 | #include <QFont> |
|
27 | #include <QFont> | |
28 |
|
28 | |||
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
30 | class QBarSetPrivate; |
|
30 | class QBarSetPrivate; | |
31 |
|
31 | |||
32 | class QTCOMMERCIALCHART_EXPORT QBarSet : public QObject |
|
32 | class QTCOMMERCIALCHART_EXPORT QBarSet : public QObject | |
33 | { |
|
33 | { | |
34 | Q_OBJECT |
|
34 | Q_OBJECT | |
35 | Q_PROPERTY(QString name READ name WRITE setName) |
|
35 | Q_PROPERTY(QString name READ name WRITE setName) | |
36 |
|
36 | |||
37 | public: |
|
37 | public: | |
38 | explicit QBarSet(const QString name, QObject *parent = 0); |
|
38 | explicit QBarSet(const QString name, QObject *parent = 0); | |
39 | virtual ~QBarSet(); |
|
39 | virtual ~QBarSet(); | |
40 |
|
40 | |||
41 | void setName(const QString name); |
|
41 | void setName(const QString name); | |
42 | QString name() const; |
|
42 | QString name() const; | |
43 |
|
43 | |||
44 | // TODO: |
|
44 | void append(const QPointF value); // Appends bar with x-value | |
45 |
|
|
45 | void append(const QList<QPointF> values); // Same with list | |
46 | // void append(const QList<QPointF> value); // Same with list |
|
|||
47 | void append(const qreal value); // TODO: change so, that count becomes x-value |
|
46 | void append(const qreal value); // TODO: change so, that count becomes x-value | |
|
47 | void append(const QList<qreal> values); // Append list of values. Using index as x-value | |||
48 |
|
48 | |||
49 | // TODO: |
|
49 | QBarSet& operator << (const qreal &value); // TODO: change implementations so, that count becomes x-value | |
50 | // void append(const QList<qreal> values); // Append list of values. Using index as x-value |
|
50 | QBarSet& operator << (const QPointF &value); // Appends bar with x-value | |
51 |
|
||||
52 | QBarSet& operator << (const qreal &value); // TODO: change implementations so, that count becomes x-value |
|
|||
53 | // TODO: |
|
|||
54 | // QBarSet& operator << (const QPointF &value); // Appends bar with x-value |
|
|||
55 |
|
51 | |||
56 | void insert(const int index, const qreal value); // TODO: internal reindexing (what happens, if there are points with real x values?) |
|
52 | void insert(const int index, const qreal value); // TODO: internal reindexing (what happens, if there are points with real x values?) | |
57 | void remove(const int index); // TODO: internal reindexing (what happens, if there are points with real x values?) |
|
53 | void remove(const int index); // TODO: internal reindexing (what happens, if there are points with real x values?) | |
58 | void replace(const int index, const qreal value); |
|
54 | void replace(const int index, const qreal value); | |
59 |
|
|
55 | QPointF at(const int index) const; | |
60 |
|
|
56 | QPointF operator [] (const int index) const; | |
61 | int count() const; |
|
57 | int count() const; | |
62 | qreal sum() const; |
|
58 | qreal sum() const; | |
63 |
|
59 | |||
64 | void setPen(const QPen &pen); |
|
60 | void setPen(const QPen &pen); | |
65 | QPen pen() const; |
|
61 | QPen pen() const; | |
66 |
|
62 | |||
67 | void setBrush(const QBrush &brush); |
|
63 | void setBrush(const QBrush &brush); | |
68 | QBrush brush() const; |
|
64 | QBrush brush() const; | |
69 |
|
65 | |||
70 | void setLabelPen(const QPen &pen); |
|
66 | void setLabelPen(const QPen &pen); | |
71 | QPen labelPen() const; |
|
67 | QPen labelPen() const; | |
72 |
|
68 | |||
73 | void setLabelBrush(const QBrush &brush); |
|
69 | void setLabelBrush(const QBrush &brush); | |
74 | QBrush labelBrush() const; |
|
70 | QBrush labelBrush() const; | |
75 |
|
71 | |||
76 | void setLabelFont(const QFont &font); |
|
72 | void setLabelFont(const QFont &font); | |
77 | QFont labelFont() const; |
|
73 | QFont labelFont() const; | |
78 |
|
74 | |||
79 | void setLabelsVisible(bool visible = true); |
|
75 | void setLabelsVisible(bool visible = true); | |
80 | bool labelsVisible() const; |
|
76 | bool labelsVisible() const; | |
81 |
|
77 | |||
82 | Q_SIGNALS: |
|
78 | Q_SIGNALS: | |
83 | void clicked(QString category); |
|
79 | void clicked(QString category); | |
84 | void hovered(bool status); |
|
80 | void hovered(bool status); | |
85 |
|
81 | |||
86 | private: |
|
82 | private: | |
87 | QScopedPointer<QBarSetPrivate> d_ptr; |
|
83 | QScopedPointer<QBarSetPrivate> d_ptr; | |
88 | Q_DISABLE_COPY(QBarSet) |
|
84 | Q_DISABLE_COPY(QBarSet) | |
89 | friend class QBarSeries; |
|
85 | friend class QBarSeries; | |
90 | friend class BarLegendMarker; |
|
86 | friend class BarLegendMarker; | |
91 | friend class BarChartItem; |
|
87 | friend class BarChartItem; | |
92 | friend class QBarSeriesPrivate; |
|
88 | friend class QBarSeriesPrivate; | |
93 | }; |
|
89 | }; | |
94 |
|
90 | |||
95 | QTCOMMERCIALCHART_END_NAMESPACE |
|
91 | QTCOMMERCIALCHART_END_NAMESPACE | |
96 |
|
92 | |||
97 | #endif // QBARSET_H |
|
93 | #endif // QBARSET_H |
@@ -1,40 +1,39 | |||||
1 | #ifndef QBARSET_P_H |
|
1 | #ifndef QBARSET_P_H | |
2 | #define QBARSET_P_H |
|
2 | #define QBARSET_P_H | |
3 |
|
3 | |||
4 | #include "qbarset.h" |
|
4 | #include "qbarset.h" | |
5 | #include <QMap> |
|
5 | #include <QMap> | |
6 |
|
6 | |||
7 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
7 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
8 |
|
8 | |||
9 | class QBarSetPrivate : public QObject |
|
9 | class QBarSetPrivate : public QObject | |
10 | { |
|
10 | { | |
11 | Q_OBJECT |
|
11 | Q_OBJECT | |
12 |
|
12 | |||
13 | public: |
|
13 | public: | |
14 | QBarSetPrivate(const QString name, QBarSet *parent); |
|
14 | QBarSetPrivate(const QString name, QBarSet *parent); | |
15 | ~QBarSetPrivate(); |
|
15 | ~QBarSetPrivate(); | |
16 |
|
16 | |||
17 | Q_SIGNALS: |
|
17 | Q_SIGNALS: | |
18 | void clicked(QString category); |
|
18 | void clicked(QString category); | |
19 | void restructuredBars(); |
|
19 | void restructuredBars(); | |
20 | void updatedBars(); |
|
20 | void updatedBars(); | |
21 | void labelsVisibleChanged(bool visible); |
|
21 | void labelsVisibleChanged(bool visible); | |
22 |
|
22 | |||
23 | public: |
|
23 | public: | |
24 | QBarSet * const q_ptr; |
|
24 | QBarSet * const q_ptr; | |
25 | QString m_name; |
|
25 | QString m_name; | |
26 | QList<qreal> m_values; // TODO: replace with map (category, value) |
|
26 | QList<QPointF> m_values; | |
27 | QMap<QString, qreal> m_mappedValues; |
|
|||
28 | QPen m_pen; |
|
27 | QPen m_pen; | |
29 | QBrush m_brush; |
|
28 | QBrush m_brush; | |
30 | QPen m_labelPen; |
|
29 | QPen m_labelPen; | |
31 | QBrush m_labelBrush; |
|
30 | QBrush m_labelBrush; | |
32 | QFont m_labelFont; |
|
31 | QFont m_labelFont; | |
33 | bool m_labelsVisible; |
|
32 | bool m_labelsVisible; | |
34 |
|
33 | |||
35 | friend class QBarSet; |
|
34 | friend class QBarSet; | |
36 | }; |
|
35 | }; | |
37 |
|
36 | |||
38 | QTCOMMERCIALCHART_END_NAMESPACE |
|
37 | QTCOMMERCIALCHART_END_NAMESPACE | |
39 |
|
38 | |||
40 | #endif // QBARSETPRIVATE_P_H |
|
39 | #endif // QBARSETPRIVATE_P_H |
@@ -1,85 +1,85 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "stackedbarchartitem_p.h" |
|
21 | #include "stackedbarchartitem_p.h" | |
22 | #include "bar_p.h" |
|
22 | #include "bar_p.h" | |
23 | #include "barlabel_p.h" |
|
23 | #include "barlabel_p.h" | |
24 | #include "qbarset_p.h" |
|
24 | #include "qbarset_p.h" | |
25 | #include "qbarseries_p.h" |
|
25 | #include "qbarseries_p.h" | |
26 | #include "qbarset.h" |
|
26 | #include "qbarset.h" | |
27 |
|
27 | |||
28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
29 |
|
29 | |||
30 | StackedBarChartItem::StackedBarChartItem(QBarSeries *series, ChartPresenter *presenter) : |
|
30 | StackedBarChartItem::StackedBarChartItem(QBarSeries *series, ChartPresenter *presenter) : | |
31 | BarChartItem(series, presenter) |
|
31 | BarChartItem(series, presenter) | |
32 | { |
|
32 | { | |
33 | } |
|
33 | } | |
34 |
|
34 | |||
35 | QVector<QRectF> StackedBarChartItem::calculateLayout() |
|
35 | QVector<QRectF> StackedBarChartItem::calculateLayout() | |
36 | { |
|
36 | { | |
37 | QVector<QRectF> layout; |
|
37 | QVector<QRectF> layout; | |
38 | // Use temporary qreals for accurancy |
|
38 | // Use temporary qreals for accurancy | |
39 |
|
39 | |||
40 | // Domain: |
|
40 | // Domain: | |
41 | qreal range = m_domainMaxY - m_domainMinY; |
|
41 | qreal range = m_domainMaxY - m_domainMinY; | |
42 | qreal height = geometry().height(); |
|
42 | qreal height = geometry().height(); | |
43 | qreal width = geometry().width(); |
|
43 | qreal width = geometry().width(); | |
44 | qreal scale = (height / range); |
|
44 | qreal scale = (height / range); | |
45 | qreal categotyCount = m_series->categoryCount(); |
|
45 | qreal categotyCount = m_series->categoryCount(); | |
46 | qreal barWidth = width / (categotyCount * 2); |
|
46 | qreal barWidth = width / (categotyCount * 2); | |
47 | qreal xStep = width / categotyCount; |
|
47 | qreal xStep = width / categotyCount; | |
48 | qreal xPos = xStep / 2 - barWidth / 2 + geometry().topLeft().x(); |
|
48 | qreal xPos = xStep / 2 - barWidth / 2 + geometry().topLeft().x(); | |
49 |
|
49 | |||
50 | int itemIndex(0); |
|
50 | int itemIndex(0); | |
51 | for (int category = 0; category < categotyCount; category++) { |
|
51 | for (int category = 0; category < categotyCount; category++) { | |
52 | qreal yPos = height + scale * m_domainMinY + geometry().topLeft().y(); |
|
52 | qreal yPos = height + scale * m_domainMinY + geometry().topLeft().y(); | |
53 | for (int set=0; set < m_series->barsetCount(); set++) { |
|
53 | for (int set=0; set < m_series->barsetCount(); set++) { | |
54 | QBarSet* barSet = m_series->d_func()->barsetAt(set); |
|
54 | QBarSet* barSet = m_series->d_func()->barsetAt(set); | |
55 |
|
55 | |||
56 | qreal barHeight = barSet->at(category) * scale; |
|
56 | qreal barHeight = barSet->at(category).y() * scale; | |
57 | Bar* bar = m_bars.at(itemIndex); |
|
57 | Bar* bar = m_bars.at(itemIndex); | |
58 | bar->setPen(barSet->pen()); |
|
58 | bar->setPen(barSet->pen()); | |
59 | bar->setBrush(barSet->brush()); |
|
59 | bar->setBrush(barSet->brush()); | |
60 | QRectF rect(xPos, yPos-barHeight, barWidth, barHeight); |
|
60 | QRectF rect(xPos, yPos-barHeight, barWidth, barHeight); | |
61 | layout.append(rect); |
|
61 | layout.append(rect); | |
62 |
|
62 | |||
63 | BarLabel* label = m_labels.at(itemIndex); |
|
63 | BarLabel* label = m_labels.at(itemIndex); | |
64 |
|
64 | |||
65 | if (!qFuzzyIsNull(barSet->at(category))) { |
|
65 | if (!qFuzzyIsNull(barSet->at(category).y())) { | |
66 | label->setText(QString::number(barSet->at(category))); |
|
66 | label->setText(QString::number(barSet->at(category).y())); | |
67 | } else { |
|
67 | } else { | |
68 | label->setText(QString("")); |
|
68 | label->setText(QString("")); | |
69 | } |
|
69 | } | |
70 |
|
70 | |||
71 | label->setPos(xPos + (rect.width()/2 - label->boundingRect().width()/2) |
|
71 | label->setPos(xPos + (rect.width()/2 - label->boundingRect().width()/2) | |
72 | ,yPos - barHeight/2 - label->boundingRect().height()/2); |
|
72 | ,yPos - barHeight/2 - label->boundingRect().height()/2); | |
73 | label->setFont(barSet->labelFont()); |
|
73 | label->setFont(barSet->labelFont()); | |
74 | itemIndex++; |
|
74 | itemIndex++; | |
75 | yPos -= barHeight; |
|
75 | yPos -= barHeight; | |
76 | } |
|
76 | } | |
77 | xPos += xStep; |
|
77 | xPos += xStep; | |
78 | } |
|
78 | } | |
79 |
|
79 | |||
80 | return layout; |
|
80 | return layout; | |
81 | } |
|
81 | } | |
82 |
|
82 | |||
83 | #include "moc_stackedbarchartitem_p.cpp" |
|
83 | #include "moc_stackedbarchartitem_p.cpp" | |
84 |
|
84 | |||
85 | QTCOMMERCIALCHART_END_NAMESPACE |
|
85 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,290 +1,290 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "chartdataset_p.h" |
|
21 | #include "chartdataset_p.h" | |
22 | #include "qaxis.h" |
|
22 | #include "qaxis.h" | |
23 | #include "qaxis_p.h" |
|
23 | #include "qaxis_p.h" | |
24 | #include "qabstractseries_p.h" |
|
24 | #include "qabstractseries_p.h" | |
25 | #include "qbarseries.h" |
|
25 | #include "qbarseries.h" | |
26 | #include "qstackedbarseries.h" |
|
26 | #include "qstackedbarseries.h" | |
27 | #include "qpercentbarseries.h" |
|
27 | #include "qpercentbarseries.h" | |
28 | #include "qpieseries.h" |
|
28 | #include "qpieseries.h" | |
29 |
|
29 | |||
30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
31 |
|
31 | |||
32 | ChartDataSet::ChartDataSet(QObject *parent):QObject(parent), |
|
32 | ChartDataSet::ChartDataSet(QObject *parent):QObject(parent), | |
33 | m_axisX(new QAxis(this)), |
|
33 | m_axisX(new QAxis(this)), | |
34 | m_axisY(new QAxis(this)), |
|
34 | m_axisY(new QAxis(this)), | |
35 | m_domainIndex(0), |
|
35 | m_domainIndex(0), | |
36 | m_axisXInitialized(false), |
|
36 | m_axisXInitialized(false), | |
37 | m_axisYInitialized(false) |
|
37 | m_axisYInitialized(false) | |
38 | { |
|
38 | { | |
39 | //create main domain |
|
39 | //create main domain | |
40 | Domain* domain = new Domain(m_axisY); |
|
40 | Domain* domain = new Domain(m_axisY); | |
41 | m_axisDomainMap.insert(m_axisY,domain); |
|
41 | m_axisDomainMap.insert(m_axisY,domain); | |
42 | QObject::connect(m_axisY->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisYChanged(qreal,qreal,int,bool))); |
|
42 | QObject::connect(m_axisY->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisYChanged(qreal,qreal,int,bool))); | |
43 | QObject::connect(m_axisX->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisXChanged(qreal,qreal,int,bool))); |
|
43 | QObject::connect(m_axisX->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisXChanged(qreal,qreal,int,bool))); | |
44 | QObject::connect(domain,SIGNAL(rangeYChanged(qreal,qreal,int)),m_axisY->d_ptr.data(),SLOT(handleAxisRangeChanged(qreal,qreal,int))); |
|
44 | QObject::connect(domain,SIGNAL(rangeYChanged(qreal,qreal,int)),m_axisY->d_ptr.data(),SLOT(handleAxisRangeChanged(qreal,qreal,int))); | |
45 | QObject::connect(domain,SIGNAL(rangeXChanged(qreal,qreal,int)),m_axisX->d_ptr.data(),SLOT(handleAxisRangeChanged(qreal,qreal,int))); |
|
45 | QObject::connect(domain,SIGNAL(rangeXChanged(qreal,qreal,int)),m_axisX->d_ptr.data(),SLOT(handleAxisRangeChanged(qreal,qreal,int))); | |
46 | } |
|
46 | } | |
47 |
|
47 | |||
48 | ChartDataSet::~ChartDataSet() |
|
48 | ChartDataSet::~ChartDataSet() | |
49 | { |
|
49 | { | |
50 | removeAllSeries(); |
|
50 | removeAllSeries(); | |
51 | } |
|
51 | } | |
52 |
|
52 | |||
53 | void ChartDataSet::addSeries(QAbstractSeries* series, QAxis *axisY) |
|
53 | void ChartDataSet::addSeries(QAbstractSeries* series, QAxis *axisY) | |
54 | { |
|
54 | { | |
55 | if(axisY==0) axisY = m_axisY; |
|
55 | if(axisY==0) axisY = m_axisY; | |
56 |
|
56 | |||
57 | QAxis* axis = m_seriesAxisMap.value(series); |
|
57 | QAxis* axis = m_seriesAxisMap.value(series); | |
58 |
|
58 | |||
59 | if(axis) { |
|
59 | if(axis) { | |
60 | qWarning() << "Can not add series. Series already on the chart"; |
|
60 | qWarning() << "Can not add series. Series already on the chart"; | |
61 | return; |
|
61 | return; | |
62 | } |
|
62 | } | |
63 |
|
63 | |||
64 | series->setParent(this); // take ownership |
|
64 | series->setParent(this); // take ownership | |
65 | axisY->setParent(this); // take ownership |
|
65 | axisY->setParent(this); // take ownership | |
66 |
|
66 | |||
67 | Domain* domain = m_axisDomainMap.value(axisY); |
|
67 | Domain* domain = m_axisDomainMap.value(axisY); | |
68 |
|
68 | |||
69 | if(!domain) { |
|
69 | if(!domain) { | |
70 | domain = new Domain(axisY); |
|
70 | domain = new Domain(axisY); | |
71 | QObject::connect(axisY->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisYChanged(qreal,qreal,int,bool))); |
|
71 | QObject::connect(axisY->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisYChanged(qreal,qreal,int,bool))); | |
72 | QObject::connect(axisX()->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisXChanged(qreal,qreal,int))); |
|
72 | QObject::connect(axisX()->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisXChanged(qreal,qreal,int))); | |
73 | QObject::connect(domain,SIGNAL(rangeYChanged(qreal,qreal,int)),axisY->d_ptr.data(),SLOT(handleAxisRangeChanged(qreal,qreal,int))); |
|
73 | QObject::connect(domain,SIGNAL(rangeYChanged(qreal,qreal,int)),axisY->d_ptr.data(),SLOT(handleAxisRangeChanged(qreal,qreal,int))); | |
74 | //initialize |
|
74 | //initialize | |
75 | m_axisDomainMap.insert(axisY,domain); |
|
75 | m_axisDomainMap.insert(axisY,domain); | |
76 | emit axisAdded(axisY,domain); |
|
76 | emit axisAdded(axisY,domain); | |
77 | } |
|
77 | } | |
78 |
|
78 | |||
79 | if(!m_axisXInitialized){ |
|
79 | if(!m_axisXInitialized){ | |
80 | m_axisXInitialized=true; |
|
80 | m_axisXInitialized=true; | |
81 | emit axisAdded(m_axisX,domain); |
|
81 | emit axisAdded(m_axisX,domain); | |
82 | } |
|
82 | } | |
83 |
|
83 | |||
84 | if(!m_axisYInitialized && axisY==m_axisY){ |
|
84 | if(!m_axisYInitialized && axisY==m_axisY){ | |
85 | m_axisYInitialized=true; |
|
85 | m_axisYInitialized=true; | |
86 | emit axisAdded(m_axisY,domain); |
|
86 | emit axisAdded(m_axisY,domain); | |
87 | } |
|
87 | } | |
88 |
|
88 | |||
89 | series->d_ptr->scaleDomain(*domain); |
|
89 | series->d_ptr->scaleDomain(*domain); | |
90 |
|
90 | |||
91 | if(series->type() == QAbstractSeries::SeriesTypeBar |
|
91 | if(series->type() == QAbstractSeries::SeriesTypeGroupedBar | |
92 | || series->type() == QAbstractSeries::SeriesTypeStackedBar |
|
92 | || series->type() == QAbstractSeries::SeriesTypeStackedBar | |
93 | || series->type() == QAbstractSeries::SeriesTypePercentBar) { |
|
93 | || series->type() == QAbstractSeries::SeriesTypePercentBar) { | |
94 | QBarSeries* barSeries = static_cast<QBarSeries*>(series); |
|
94 | QBarSeries* barSeries = static_cast<QBarSeries*>(series); | |
95 | setupCategories(barSeries); |
|
95 | setupCategories(barSeries); | |
96 | } |
|
96 | } | |
97 |
|
97 | |||
98 | if (series->type()== QAbstractSeries::SeriesTypePie && m_seriesAxisMap.count() == 0) { |
|
98 | if (series->type()== QAbstractSeries::SeriesTypePie && m_seriesAxisMap.count() == 0) { | |
99 | axisX()->hide(); |
|
99 | axisX()->hide(); | |
100 | this->axisY()->hide(); |
|
100 | this->axisY()->hide(); | |
101 | } |
|
101 | } | |
102 |
|
102 | |||
103 | m_seriesAxisMap.insert(series,axisY); |
|
103 | m_seriesAxisMap.insert(series,axisY); | |
104 |
|
104 | |||
105 | QMapIterator<int, QAbstractSeries*> i(m_indexSeriesMap); |
|
105 | QMapIterator<int, QAbstractSeries*> i(m_indexSeriesMap); | |
106 |
|
106 | |||
107 | int key=0; |
|
107 | int key=0; | |
108 | while (i.hasNext()) { |
|
108 | while (i.hasNext()) { | |
109 | i.next(); |
|
109 | i.next(); | |
110 | if(i.key()!=key) { |
|
110 | if(i.key()!=key) { | |
111 | break; |
|
111 | break; | |
112 | } |
|
112 | } | |
113 | key++; |
|
113 | key++; | |
114 | } |
|
114 | } | |
115 |
|
115 | |||
116 | m_indexSeriesMap.insert(key,series); |
|
116 | m_indexSeriesMap.insert(key,series); | |
117 |
|
117 | |||
118 | series->d_ptr->m_dataset=this; |
|
118 | series->d_ptr->m_dataset=this; | |
119 |
|
119 | |||
120 | emit seriesAdded(series,domain); |
|
120 | emit seriesAdded(series,domain); | |
121 |
|
121 | |||
122 | } |
|
122 | } | |
123 |
|
123 | |||
124 | QAxis* ChartDataSet::removeSeries(QAbstractSeries* series) |
|
124 | QAxis* ChartDataSet::removeSeries(QAbstractSeries* series) | |
125 | { |
|
125 | { | |
126 | QAxis* axis = m_seriesAxisMap.value(series); |
|
126 | QAxis* axis = m_seriesAxisMap.value(series); | |
127 |
|
127 | |||
128 | if(!axis){ |
|
128 | if(!axis){ | |
129 | qWarning()<<"Can not remove series. Series not found on the chart."; |
|
129 | qWarning()<<"Can not remove series. Series not found on the chart."; | |
130 | return 0; |
|
130 | return 0; | |
131 | } |
|
131 | } | |
132 |
|
132 | |||
133 | emit seriesRemoved(series); |
|
133 | emit seriesRemoved(series); | |
134 |
|
134 | |||
135 | m_seriesAxisMap.remove(series); |
|
135 | m_seriesAxisMap.remove(series); | |
136 | int key = seriesIndex(series); |
|
136 | int key = seriesIndex(series); | |
137 | Q_ASSERT(key!=-1); |
|
137 | Q_ASSERT(key!=-1); | |
138 |
|
138 | |||
139 | m_indexSeriesMap.remove(key); |
|
139 | m_indexSeriesMap.remove(key); | |
140 | series->setParent(0); |
|
140 | series->setParent(0); | |
141 | series->d_ptr->m_dataset=0; |
|
141 | series->d_ptr->m_dataset=0; | |
142 |
|
142 | |||
143 | QList<QAxis*> axes = m_seriesAxisMap.values(); |
|
143 | QList<QAxis*> axes = m_seriesAxisMap.values(); | |
144 |
|
144 | |||
145 | int i = axes.indexOf(axis); |
|
145 | int i = axes.indexOf(axis); | |
146 |
|
146 | |||
147 | if(i==-1){ |
|
147 | if(i==-1){ | |
148 | Domain* domain = m_axisDomainMap.take(axis); |
|
148 | Domain* domain = m_axisDomainMap.take(axis); | |
149 | emit axisRemoved(axis); |
|
149 | emit axisRemoved(axis); | |
150 | if(axis!=m_axisY){ |
|
150 | if(axis!=m_axisY){ | |
151 | axis->setParent(0); |
|
151 | axis->setParent(0); | |
152 | delete domain; |
|
152 | delete domain; | |
153 | }else{ |
|
153 | }else{ | |
154 | m_axisYInitialized=false; |
|
154 | m_axisYInitialized=false; | |
155 | m_axisDomainMap.insert(m_axisY,domain); |
|
155 | m_axisDomainMap.insert(m_axisY,domain); | |
156 | } |
|
156 | } | |
157 | } |
|
157 | } | |
158 |
|
158 | |||
159 | if(m_seriesAxisMap.values().size()==0) |
|
159 | if(m_seriesAxisMap.values().size()==0) | |
160 | { |
|
160 | { | |
161 | m_axisXInitialized=false; |
|
161 | m_axisXInitialized=false; | |
162 | emit axisRemoved(axisX()); |
|
162 | emit axisRemoved(axisX()); | |
163 | } |
|
163 | } | |
164 |
|
164 | |||
165 | return axis; |
|
165 | return axis; | |
166 | } |
|
166 | } | |
167 |
|
167 | |||
168 | void ChartDataSet::removeAllSeries() |
|
168 | void ChartDataSet::removeAllSeries() | |
169 | { |
|
169 | { | |
170 | QList<QAbstractSeries*> series = m_seriesAxisMap.keys(); |
|
170 | QList<QAbstractSeries*> series = m_seriesAxisMap.keys(); | |
171 | QList<QAxis*> axes; |
|
171 | QList<QAxis*> axes; | |
172 | foreach(QAbstractSeries *s , series) { |
|
172 | foreach(QAbstractSeries *s , series) { | |
173 | QAxis* axis = removeSeries(s); |
|
173 | QAxis* axis = removeSeries(s); | |
174 | if(axis==axisY()) continue; |
|
174 | if(axis==axisY()) continue; | |
175 | int i = axes.indexOf(axis); |
|
175 | int i = axes.indexOf(axis); | |
176 | if(i==-1){ |
|
176 | if(i==-1){ | |
177 | axes<<axis; |
|
177 | axes<<axis; | |
178 | } |
|
178 | } | |
179 | } |
|
179 | } | |
180 |
|
180 | |||
181 | Q_ASSERT(m_seriesAxisMap.count()==0); |
|
181 | Q_ASSERT(m_seriesAxisMap.count()==0); | |
182 | Q_ASSERT(m_axisDomainMap.count()==1); |
|
182 | Q_ASSERT(m_axisDomainMap.count()==1); | |
183 |
|
183 | |||
184 | qDeleteAll(series); |
|
184 | qDeleteAll(series); | |
185 | qDeleteAll(axes); |
|
185 | qDeleteAll(axes); | |
186 | } |
|
186 | } | |
187 |
|
187 | |||
188 | void ChartDataSet::setupCategories(QBarSeries* series) |
|
188 | void ChartDataSet::setupCategories(QBarSeries* series) | |
189 | { |
|
189 | { | |
190 | QAxisCategories* categories = axisX()->categories(); |
|
190 | QAxisCategories* categories = axisX()->categories(); | |
191 | categories->clear(); |
|
191 | categories->clear(); | |
192 | categories->insert(series->categories()); |
|
192 | categories->insert(series->categories()); | |
193 | } |
|
193 | } | |
194 |
|
194 | |||
195 | void ChartDataSet::zoomInDomain(const QRectF& rect, const QSizeF& size) |
|
195 | void ChartDataSet::zoomInDomain(const QRectF& rect, const QSizeF& size) | |
196 | { |
|
196 | { | |
197 | QMapIterator<QAxis*, Domain*> i(m_axisDomainMap); |
|
197 | QMapIterator<QAxis*, Domain*> i(m_axisDomainMap); | |
198 | //main domain has to be the last one; |
|
198 | //main domain has to be the last one; | |
199 | Domain *domain = m_axisDomainMap.value(axisY()); |
|
199 | Domain *domain = m_axisDomainMap.value(axisY()); | |
200 | Q_ASSERT(domain); |
|
200 | Q_ASSERT(domain); | |
201 | while (i.hasNext()) { |
|
201 | while (i.hasNext()) { | |
202 | i.next(); |
|
202 | i.next(); | |
203 | if(i.value()==domain) continue; |
|
203 | if(i.value()==domain) continue; | |
204 | i.value()->zoomIn(rect,size); |
|
204 | i.value()->zoomIn(rect,size); | |
205 | } |
|
205 | } | |
206 | domain->zoomIn(rect,size); |
|
206 | domain->zoomIn(rect,size); | |
207 | } |
|
207 | } | |
208 |
|
208 | |||
209 | void ChartDataSet::zoomOutDomain(const QRectF& rect, const QSizeF& size) |
|
209 | void ChartDataSet::zoomOutDomain(const QRectF& rect, const QSizeF& size) | |
210 | { |
|
210 | { | |
211 | QMapIterator<QAxis*, Domain*> i(m_axisDomainMap); |
|
211 | QMapIterator<QAxis*, Domain*> i(m_axisDomainMap); | |
212 | //main domain has to be the last one; |
|
212 | //main domain has to be the last one; | |
213 | Domain *domain = m_axisDomainMap.value(axisY()); |
|
213 | Domain *domain = m_axisDomainMap.value(axisY()); | |
214 | Q_ASSERT(domain); |
|
214 | Q_ASSERT(domain); | |
215 | while (i.hasNext()) { |
|
215 | while (i.hasNext()) { | |
216 | i.next(); |
|
216 | i.next(); | |
217 | if(i.value()==domain) continue; |
|
217 | if(i.value()==domain) continue; | |
218 | i.value()->zoomOut(rect,size); |
|
218 | i.value()->zoomOut(rect,size); | |
219 | } |
|
219 | } | |
220 | domain->zoomOut(rect,size); |
|
220 | domain->zoomOut(rect,size); | |
221 | } |
|
221 | } | |
222 |
|
222 | |||
223 | int ChartDataSet::seriesCount(QAbstractSeries::SeriesType type) |
|
223 | int ChartDataSet::seriesCount(QAbstractSeries::SeriesType type) | |
224 | { |
|
224 | { | |
225 | int count=0; |
|
225 | int count=0; | |
226 | QMapIterator<QAbstractSeries*, QAxis*> i(m_seriesAxisMap); |
|
226 | QMapIterator<QAbstractSeries*, QAxis*> i(m_seriesAxisMap); | |
227 | while (i.hasNext()) { |
|
227 | while (i.hasNext()) { | |
228 | i.next(); |
|
228 | i.next(); | |
229 | if(i.key()->type()==type) count++; |
|
229 | if(i.key()->type()==type) count++; | |
230 | } |
|
230 | } | |
231 | return count; |
|
231 | return count; | |
232 | } |
|
232 | } | |
233 |
|
233 | |||
234 | int ChartDataSet::seriesIndex(QAbstractSeries *series) |
|
234 | int ChartDataSet::seriesIndex(QAbstractSeries *series) | |
235 | { |
|
235 | { | |
236 | QMapIterator<int, QAbstractSeries*> i(m_indexSeriesMap); |
|
236 | QMapIterator<int, QAbstractSeries*> i(m_indexSeriesMap); | |
237 | while (i.hasNext()) { |
|
237 | while (i.hasNext()) { | |
238 | i.next(); |
|
238 | i.next(); | |
239 | if (i.value() == series) |
|
239 | if (i.value() == series) | |
240 | return i.key(); |
|
240 | return i.key(); | |
241 | } |
|
241 | } | |
242 | return -1; |
|
242 | return -1; | |
243 | } |
|
243 | } | |
244 |
|
244 | |||
245 | QAxis* ChartDataSet::axisY(QAbstractSeries *series) const |
|
245 | QAxis* ChartDataSet::axisY(QAbstractSeries *series) const | |
246 | { |
|
246 | { | |
247 | if(series == 0) return m_axisY; |
|
247 | if(series == 0) return m_axisY; | |
248 | return m_seriesAxisMap.value(series); |
|
248 | return m_seriesAxisMap.value(series); | |
249 | } |
|
249 | } | |
250 |
|
250 | |||
251 | Domain* ChartDataSet::domain(QAbstractSeries *series) const |
|
251 | Domain* ChartDataSet::domain(QAbstractSeries *series) const | |
252 | { |
|
252 | { | |
253 | QAxis* axis = m_seriesAxisMap.value(series); |
|
253 | QAxis* axis = m_seriesAxisMap.value(series); | |
254 | if(axis){ |
|
254 | if(axis){ | |
255 | return m_axisDomainMap.value(axis); |
|
255 | return m_axisDomainMap.value(axis); | |
256 | }else |
|
256 | }else | |
257 | return 0; |
|
257 | return 0; | |
258 | } |
|
258 | } | |
259 |
|
259 | |||
260 | Domain* ChartDataSet::domain(QAxis* axis) const |
|
260 | Domain* ChartDataSet::domain(QAxis* axis) const | |
261 | { |
|
261 | { | |
262 | if(!axis || axis==axisX()) { |
|
262 | if(!axis || axis==axisX()) { | |
263 | return m_axisDomainMap.value(axisY()); |
|
263 | return m_axisDomainMap.value(axisY()); | |
264 | } |
|
264 | } | |
265 | else { |
|
265 | else { | |
266 | return m_axisDomainMap.value(axis); |
|
266 | return m_axisDomainMap.value(axis); | |
267 | } |
|
267 | } | |
268 | } |
|
268 | } | |
269 |
|
269 | |||
270 | void ChartDataSet::scrollDomain(int dx,int dy,const QSizeF& size) |
|
270 | void ChartDataSet::scrollDomain(int dx,int dy,const QSizeF& size) | |
271 | { |
|
271 | { | |
272 | QMapIterator<QAxis*, Domain*> i( m_axisDomainMap); |
|
272 | QMapIterator<QAxis*, Domain*> i( m_axisDomainMap); | |
273 | //main domain has to be the last one; |
|
273 | //main domain has to be the last one; | |
274 | Domain *domain = m_axisDomainMap.value(axisY()); |
|
274 | Domain *domain = m_axisDomainMap.value(axisY()); | |
275 | while (i.hasNext()) { |
|
275 | while (i.hasNext()) { | |
276 | i.next(); |
|
276 | i.next(); | |
277 | if(i.value()==domain) continue; |
|
277 | if(i.value()==domain) continue; | |
278 | i.value()->move(dx,dy,size); |
|
278 | i.value()->move(dx,dy,size); | |
279 | } |
|
279 | } | |
280 | domain->move(dx,dy,size); |
|
280 | domain->move(dx,dy,size); | |
281 | } |
|
281 | } | |
282 |
|
282 | |||
283 | QList<QAbstractSeries*> ChartDataSet::series() const |
|
283 | QList<QAbstractSeries*> ChartDataSet::series() const | |
284 | { |
|
284 | { | |
285 | return m_seriesAxisMap.keys(); |
|
285 | return m_seriesAxisMap.keys(); | |
286 | } |
|
286 | } | |
287 |
|
287 | |||
288 | #include "moc_chartdataset_p.cpp" |
|
288 | #include "moc_chartdataset_p.cpp" | |
289 |
|
289 | |||
290 | QTCOMMERCIALCHART_END_NAMESPACE |
|
290 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,75 +1,76 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #ifndef QABSTRACTSERIES_H |
|
21 | #ifndef QABSTRACTSERIES_H | |
22 | #define QABSTRACTSERIES_H |
|
22 | #define QABSTRACTSERIES_H | |
23 |
|
23 | |||
24 | #include <qchartglobal.h> |
|
24 | #include <qchartglobal.h> | |
25 | #include <QObject> |
|
25 | #include <QObject> | |
26 | #include <QPen> |
|
26 | #include <QPen> | |
27 |
|
27 | |||
28 | class QAbstractItemModel; |
|
28 | class QAbstractItemModel; | |
29 |
|
29 | |||
30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
31 |
|
31 | |||
32 | class QAbstractSeriesPrivate; |
|
32 | class QAbstractSeriesPrivate; | |
33 | class QChart; |
|
33 | class QChart; | |
34 | //class QModelMapper; |
|
34 | //class QModelMapper; | |
35 |
|
35 | |||
36 | class QTCOMMERCIALCHART_EXPORT QAbstractSeries : public QObject |
|
36 | class QTCOMMERCIALCHART_EXPORT QAbstractSeries : public QObject | |
37 | { |
|
37 | { | |
38 | Q_OBJECT |
|
38 | Q_OBJECT | |
39 | Q_PROPERTY(QString name READ name WRITE setName) |
|
39 | Q_PROPERTY(QString name READ name WRITE setName) | |
40 | Q_ENUMS(SeriesType) |
|
40 | Q_ENUMS(SeriesType) | |
41 |
|
41 | |||
42 | public: |
|
42 | public: | |
43 | enum SeriesType { |
|
43 | enum SeriesType { | |
44 | SeriesTypeLine, |
|
44 | SeriesTypeLine, | |
45 | SeriesTypeArea, |
|
45 | SeriesTypeArea, | |
46 | SeriesTypeBar, |
|
46 | SeriesTypeBar, | |
47 | SeriesTypeStackedBar, |
|
47 | SeriesTypeStackedBar, | |
48 | SeriesTypePercentBar, |
|
48 | SeriesTypePercentBar, | |
|
49 | SeriesTypeGroupedBar, | |||
49 | SeriesTypePie, |
|
50 | SeriesTypePie, | |
50 | SeriesTypeScatter, |
|
51 | SeriesTypeScatter, | |
51 | SeriesTypeSpline |
|
52 | SeriesTypeSpline | |
52 | }; |
|
53 | }; | |
53 |
|
54 | |||
54 | protected: |
|
55 | protected: | |
55 | QAbstractSeries(QAbstractSeriesPrivate &d, QObject *parent = 0); |
|
56 | QAbstractSeries(QAbstractSeriesPrivate &d, QObject *parent = 0); | |
56 |
|
57 | |||
57 | public: |
|
58 | public: | |
58 | ~QAbstractSeries(); |
|
59 | ~QAbstractSeries(); | |
59 | virtual SeriesType type() const = 0; |
|
60 | virtual SeriesType type() const = 0; | |
60 | virtual void setModel(QAbstractItemModel *model) = 0; |
|
61 | virtual void setModel(QAbstractItemModel *model) = 0; | |
61 | QAbstractItemModel* model() const; |
|
62 | QAbstractItemModel* model() const; | |
62 | void setName(const QString& name); |
|
63 | void setName(const QString& name); | |
63 | QString name() const; |
|
64 | QString name() const; | |
64 | QChart* chart() const; |
|
65 | QChart* chart() const; | |
65 |
|
66 | |||
66 | protected: |
|
67 | protected: | |
67 | QScopedPointer<QAbstractSeriesPrivate> d_ptr; |
|
68 | QScopedPointer<QAbstractSeriesPrivate> d_ptr; | |
68 | friend class ChartDataSet; |
|
69 | friend class ChartDataSet; | |
69 | friend class ChartPresenter; |
|
70 | friend class ChartPresenter; | |
70 | friend class QLegendPrivate; |
|
71 | friend class QLegendPrivate; | |
71 | }; |
|
72 | }; | |
72 |
|
73 | |||
73 | QTCOMMERCIALCHART_END_NAMESPACE |
|
74 | QTCOMMERCIALCHART_END_NAMESPACE | |
74 |
|
75 | |||
75 | #endif |
|
76 | #endif |
@@ -1,436 +1,436 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include <QtTest/QtTest> |
|
21 | #include <QtTest/QtTest> | |
22 | #include <qbarset.h> |
|
22 | #include <qbarset.h> | |
23 |
|
23 | |||
24 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
24 | QTCOMMERCIALCHART_USE_NAMESPACE | |
25 |
|
25 | |||
26 | class tst_QBarSet : public QObject |
|
26 | class tst_QBarSet : public QObject | |
27 | { |
|
27 | { | |
28 | Q_OBJECT |
|
28 | Q_OBJECT | |
29 |
|
29 | |||
30 | public slots: |
|
30 | public slots: | |
31 | void initTestCase(); |
|
31 | void initTestCase(); | |
32 | void cleanupTestCase(); |
|
32 | void cleanupTestCase(); | |
33 | void init(); |
|
33 | void init(); | |
34 | void cleanup(); |
|
34 | void cleanup(); | |
35 |
|
35 | |||
36 | private slots: |
|
36 | private slots: | |
37 | void qbarset_data(); |
|
37 | void qbarset_data(); | |
38 | void qbarset(); |
|
38 | void qbarset(); | |
39 | void name_data(); |
|
39 | void name_data(); | |
40 | void name(); |
|
40 | void name(); | |
41 | void append_data(); |
|
41 | void append_data(); | |
42 | void append(); |
|
42 | void append(); | |
43 | void appendOperator_data(); |
|
43 | void appendOperator_data(); | |
44 | void appendOperator(); |
|
44 | void appendOperator(); | |
45 | void insert_data(); |
|
45 | void insert_data(); | |
46 | void insert(); |
|
46 | void insert(); | |
47 | void remove_data(); |
|
47 | void remove_data(); | |
48 | void remove(); |
|
48 | void remove(); | |
49 | void replace_data(); |
|
49 | void replace_data(); | |
50 | void replace(); |
|
50 | void replace(); | |
51 | void at_data(); |
|
51 | void at_data(); | |
52 | void at(); |
|
52 | void at(); | |
53 | void atOperator_data(); |
|
53 | void atOperator_data(); | |
54 | void atOperator(); |
|
54 | void atOperator(); | |
55 | void count_data(); |
|
55 | void count_data(); | |
56 | void count(); |
|
56 | void count(); | |
57 | void sum_data(); |
|
57 | void sum_data(); | |
58 | void sum(); |
|
58 | void sum(); | |
59 | void setPen_data(); |
|
59 | void setPen_data(); | |
60 | void setPen(); |
|
60 | void setPen(); | |
61 | void setBrush_data(); |
|
61 | void setBrush_data(); | |
62 | void setBrush(); |
|
62 | void setBrush(); | |
63 | void setLabelPen_data(); |
|
63 | void setLabelPen_data(); | |
64 | void setLabelPen(); |
|
64 | void setLabelPen(); | |
65 | void setLabelBrush_data(); |
|
65 | void setLabelBrush_data(); | |
66 | void setLabelBrush(); |
|
66 | void setLabelBrush(); | |
67 | void setLabelFont_data(); |
|
67 | void setLabelFont_data(); | |
68 | void setLabelFont(); |
|
68 | void setLabelFont(); | |
69 |
|
69 | |||
70 | private: |
|
70 | private: | |
71 | QBarSet* m_barset; |
|
71 | QBarSet* m_barset; | |
72 | }; |
|
72 | }; | |
73 |
|
73 | |||
74 | void tst_QBarSet::initTestCase() |
|
74 | void tst_QBarSet::initTestCase() | |
75 | { |
|
75 | { | |
76 | } |
|
76 | } | |
77 |
|
77 | |||
78 | void tst_QBarSet::cleanupTestCase() |
|
78 | void tst_QBarSet::cleanupTestCase() | |
79 | { |
|
79 | { | |
80 | } |
|
80 | } | |
81 |
|
81 | |||
82 | void tst_QBarSet::init() |
|
82 | void tst_QBarSet::init() | |
83 | { |
|
83 | { | |
84 | m_barset = new QBarSet(QString("Name")); |
|
84 | m_barset = new QBarSet(QString("Name")); | |
85 | } |
|
85 | } | |
86 |
|
86 | |||
87 | void tst_QBarSet::cleanup() |
|
87 | void tst_QBarSet::cleanup() | |
88 | { |
|
88 | { | |
89 | delete m_barset; |
|
89 | delete m_barset; | |
90 | m_barset = 0; |
|
90 | m_barset = 0; | |
91 | } |
|
91 | } | |
92 |
|
92 | |||
93 | void tst_QBarSet::qbarset_data() |
|
93 | void tst_QBarSet::qbarset_data() | |
94 | { |
|
94 | { | |
95 | } |
|
95 | } | |
96 |
|
96 | |||
97 | void tst_QBarSet::qbarset() |
|
97 | void tst_QBarSet::qbarset() | |
98 | { |
|
98 | { | |
99 | QBarSet barset(QString("Name")); |
|
99 | QBarSet barset(QString("Name")); | |
100 | QCOMPARE(barset.name(), QString("Name")); |
|
100 | QCOMPARE(barset.name(), QString("Name")); | |
101 | QCOMPARE(barset.count(), 0); |
|
101 | QCOMPARE(barset.count(), 0); | |
102 | QVERIFY(qFuzzyIsNull(barset.sum())); |
|
102 | QVERIFY(qFuzzyIsNull(barset.sum())); | |
103 | } |
|
103 | } | |
104 |
|
104 | |||
105 | void tst_QBarSet::name_data() |
|
105 | void tst_QBarSet::name_data() | |
106 | { |
|
106 | { | |
107 | QTest::addColumn<QString> ("name"); |
|
107 | QTest::addColumn<QString> ("name"); | |
108 | QTest::addColumn<QString> ("result"); |
|
108 | QTest::addColumn<QString> ("result"); | |
109 | QTest::newRow("name0") << QString("name0") << QString("name0"); |
|
109 | QTest::newRow("name0") << QString("name0") << QString("name0"); | |
110 | QTest::newRow("name1") << QString("name1") << QString("name1"); |
|
110 | QTest::newRow("name1") << QString("name1") << QString("name1"); | |
111 | } |
|
111 | } | |
112 |
|
112 | |||
113 | void tst_QBarSet::name() |
|
113 | void tst_QBarSet::name() | |
114 | { |
|
114 | { | |
115 | QFETCH(QString, name); |
|
115 | QFETCH(QString, name); | |
116 | QFETCH(QString, result); |
|
116 | QFETCH(QString, result); | |
117 |
|
117 | |||
118 | m_barset->setName(name); |
|
118 | m_barset->setName(name); | |
119 | QCOMPARE(m_barset->name(), result); |
|
119 | QCOMPARE(m_barset->name(), result); | |
120 | } |
|
120 | } | |
121 |
|
121 | |||
122 | void tst_QBarSet::append_data() |
|
122 | void tst_QBarSet::append_data() | |
123 | { |
|
123 | { | |
124 | QTest::addColumn<int> ("count"); |
|
124 | QTest::addColumn<int> ("count"); | |
125 | QTest::newRow("0") << 0; |
|
125 | QTest::newRow("0") << 0; | |
126 | QTest::newRow("5") << 5; |
|
126 | QTest::newRow("5") << 5; | |
127 | QTest::newRow("100") << 100; |
|
127 | QTest::newRow("100") << 100; | |
128 | QTest::newRow("1000") << 1000; |
|
128 | QTest::newRow("1000") << 1000; | |
129 | } |
|
129 | } | |
130 |
|
130 | |||
131 | void tst_QBarSet::append() |
|
131 | void tst_QBarSet::append() | |
132 | { |
|
132 | { | |
133 | QFETCH(int, count); |
|
133 | QFETCH(int, count); | |
134 |
|
134 | |||
135 | QCOMPARE(m_barset->count(), 0); |
|
135 | QCOMPARE(m_barset->count(), 0); | |
136 | QVERIFY(qFuzzyIsNull(m_barset->sum())); |
|
136 | QVERIFY(qFuzzyIsNull(m_barset->sum())); | |
137 |
|
137 | |||
138 | qreal sum(0.0); |
|
138 | qreal sum(0.0); | |
139 | qreal value(0.0); |
|
139 | qreal value(0.0); | |
140 |
|
140 | |||
141 | for (int i=0; i<count; i++) { |
|
141 | for (int i=0; i<count; i++) { | |
142 | m_barset->append(value); |
|
142 | m_barset->append(value); | |
143 | QCOMPARE(m_barset->at(i), value); |
|
143 | QCOMPARE(m_barset->at(i).y(), value); | |
144 | sum += value; |
|
144 | sum += value; | |
145 | value += 1.0; |
|
145 | value += 1.0; | |
146 | } |
|
146 | } | |
147 |
|
147 | |||
148 | QCOMPARE(m_barset->count(), count); |
|
148 | QCOMPARE(m_barset->count(), count); | |
149 | QVERIFY(qFuzzyCompare(m_barset->sum(), sum)); |
|
149 | QVERIFY(qFuzzyCompare(m_barset->sum(), sum)); | |
150 | } |
|
150 | } | |
151 |
|
151 | |||
152 | void tst_QBarSet::appendOperator_data() |
|
152 | void tst_QBarSet::appendOperator_data() | |
153 | { |
|
153 | { | |
154 | append_data(); |
|
154 | append_data(); | |
155 | } |
|
155 | } | |
156 |
|
156 | |||
157 | void tst_QBarSet::appendOperator() |
|
157 | void tst_QBarSet::appendOperator() | |
158 | { |
|
158 | { | |
159 | QFETCH(int, count); |
|
159 | QFETCH(int, count); | |
160 |
|
160 | |||
161 | QCOMPARE(m_barset->count(), 0); |
|
161 | QCOMPARE(m_barset->count(), 0); | |
162 | QVERIFY(qFuzzyIsNull(m_barset->sum())); |
|
162 | QVERIFY(qFuzzyIsNull(m_barset->sum())); | |
163 |
|
163 | |||
164 | qreal sum(0.0); |
|
164 | qreal sum(0.0); | |
165 | qreal value(0.0); |
|
165 | qreal value(0.0); | |
166 |
|
166 | |||
167 | for (int i=0; i<count; i++) { |
|
167 | for (int i=0; i<count; i++) { | |
168 | *m_barset << value; |
|
168 | *m_barset << value; | |
169 | QCOMPARE(m_barset->at(i), value); |
|
169 | QCOMPARE(m_barset->at(i).y(), value); | |
170 | sum += value; |
|
170 | sum += value; | |
171 | value += 1.0; |
|
171 | value += 1.0; | |
172 | } |
|
172 | } | |
173 |
|
173 | |||
174 | QCOMPARE(m_barset->count(), count); |
|
174 | QCOMPARE(m_barset->count(), count); | |
175 | QVERIFY(qFuzzyCompare(m_barset->sum(), sum)); |
|
175 | QVERIFY(qFuzzyCompare(m_barset->sum(), sum)); | |
176 | } |
|
176 | } | |
177 |
|
177 | |||
178 | void tst_QBarSet::insert_data() |
|
178 | void tst_QBarSet::insert_data() | |
179 | { |
|
179 | { | |
180 | } |
|
180 | } | |
181 |
|
181 | |||
182 | void tst_QBarSet::insert() |
|
182 | void tst_QBarSet::insert() | |
183 | { |
|
183 | { | |
184 | QCOMPARE(m_barset->count(), 0); |
|
184 | QCOMPARE(m_barset->count(), 0); | |
185 | QVERIFY(qFuzzyIsNull(m_barset->sum())); |
|
185 | QVERIFY(qFuzzyIsNull(m_barset->sum())); | |
186 |
|
186 | |||
187 | m_barset->insert(0, 1.0); // 1.0 |
|
187 | m_barset->insert(0, 1.0); // 1.0 | |
188 | QCOMPARE(m_barset->at(0), 1.0); |
|
188 | QCOMPARE(m_barset->at(0).y(), 1.0); | |
189 | QCOMPARE(m_barset->count(), 1); |
|
189 | QCOMPARE(m_barset->count(), 1); | |
190 | QVERIFY(qFuzzyCompare(m_barset->sum(), 1.0)); |
|
190 | QVERIFY(qFuzzyCompare(m_barset->sum(), 1.0)); | |
191 |
|
191 | |||
192 | m_barset->insert(0, 2.0); // 2.0 1.0 |
|
192 | m_barset->insert(0, 2.0); // 2.0 1.0 | |
193 | QCOMPARE(m_barset->at(0), 2.0); |
|
193 | QCOMPARE(m_barset->at(0).y(), 2.0); | |
194 | QCOMPARE(m_barset->at(1), 1.0); |
|
194 | QCOMPARE(m_barset->at(1).y(), 1.0); | |
195 | QCOMPARE(m_barset->count(), 2); |
|
195 | QCOMPARE(m_barset->count(), 2); | |
196 | QVERIFY(qFuzzyCompare(m_barset->sum(), 3.0)); |
|
196 | QVERIFY(qFuzzyCompare(m_barset->sum(), 3.0)); | |
197 |
|
197 | |||
198 | m_barset->insert(1, 3.0); // 2.0 3.0 1.0 |
|
198 | m_barset->insert(1, 3.0); // 2.0 3.0 1.0 | |
199 | QCOMPARE(m_barset->at(1), 3.0); |
|
199 | QCOMPARE(m_barset->at(1).y(), 3.0); | |
200 | QCOMPARE(m_barset->at(0), 2.0); |
|
200 | QCOMPARE(m_barset->at(0).y(), 2.0); | |
201 | QCOMPARE(m_barset->at(2), 1.0); |
|
201 | QCOMPARE(m_barset->at(2).y(), 1.0); | |
202 | QCOMPARE(m_barset->count(), 3); |
|
202 | QCOMPARE(m_barset->count(), 3); | |
203 | QVERIFY(qFuzzyCompare(m_barset->sum(), 6.0)); |
|
203 | QVERIFY(qFuzzyCompare(m_barset->sum(), 6.0)); | |
204 | } |
|
204 | } | |
205 |
|
205 | |||
206 | void tst_QBarSet::remove_data() |
|
206 | void tst_QBarSet::remove_data() | |
207 | { |
|
207 | { | |
208 | } |
|
208 | } | |
209 |
|
209 | |||
210 | void tst_QBarSet::remove() |
|
210 | void tst_QBarSet::remove() | |
211 | { |
|
211 | { | |
212 | QCOMPARE(m_barset->count(), 0); |
|
212 | QCOMPARE(m_barset->count(), 0); | |
213 | QVERIFY(qFuzzyIsNull(m_barset->sum())); |
|
213 | QVERIFY(qFuzzyIsNull(m_barset->sum())); | |
214 |
|
214 | |||
215 | m_barset->append(1.0); |
|
215 | m_barset->append(1.0); | |
216 | m_barset->append(2.0); |
|
216 | m_barset->append(2.0); | |
217 | m_barset->append(3.0); |
|
217 | m_barset->append(3.0); | |
218 | m_barset->append(4.0); |
|
218 | m_barset->append(4.0); | |
219 |
|
219 | |||
220 | QCOMPARE(m_barset->count(), 4); |
|
220 | QCOMPARE(m_barset->count(), 4); | |
221 | QCOMPARE(m_barset->sum(), 10.0); |
|
221 | QCOMPARE(m_barset->sum(), 10.0); | |
222 |
|
222 | |||
223 | m_barset->remove(2); // 1.0 2.0 4.0 |
|
223 | m_barset->remove(2); // 1.0 2.0 4.0 | |
224 | QCOMPARE(m_barset->at(0), 1.0); |
|
224 | QCOMPARE(m_barset->at(0).y(), 1.0); | |
225 | QCOMPARE(m_barset->at(1), 2.0); |
|
225 | QCOMPARE(m_barset->at(1).y(), 2.0); | |
226 | QCOMPARE(m_barset->at(2), 4.0); |
|
226 | QCOMPARE(m_barset->at(2).y(), 4.0); | |
227 | QCOMPARE(m_barset->count(), 3); |
|
227 | QCOMPARE(m_barset->count(), 3); | |
228 | QCOMPARE(m_barset->sum(), 7.0); |
|
228 | QCOMPARE(m_barset->sum(), 7.0); | |
229 |
|
229 | |||
230 | m_barset->remove(0); // 2.0 4.0 |
|
230 | m_barset->remove(0); // 2.0 4.0 | |
231 | QCOMPARE(m_barset->at(0), 2.0); |
|
231 | QCOMPARE(m_barset->at(0).y(), 2.0); | |
232 | QCOMPARE(m_barset->at(1), 4.0); |
|
232 | QCOMPARE(m_barset->at(1).y(), 4.0); | |
233 | QCOMPARE(m_barset->count(), 2); |
|
233 | QCOMPARE(m_barset->count(), 2); | |
234 | QCOMPARE(m_barset->sum(), 6.0); |
|
234 | QCOMPARE(m_barset->sum(), 6.0); | |
235 | } |
|
235 | } | |
236 |
|
236 | |||
237 | void tst_QBarSet::replace_data() |
|
237 | void tst_QBarSet::replace_data() | |
238 | { |
|
238 | { | |
239 |
|
239 | |||
240 | } |
|
240 | } | |
241 |
|
241 | |||
242 | void tst_QBarSet::replace() |
|
242 | void tst_QBarSet::replace() | |
243 | { |
|
243 | { | |
244 | QCOMPARE(m_barset->count(), 0); |
|
244 | QCOMPARE(m_barset->count(), 0); | |
245 | QVERIFY(qFuzzyIsNull(m_barset->sum())); |
|
245 | QVERIFY(qFuzzyIsNull(m_barset->sum())); | |
246 |
|
246 | |||
247 | m_barset->append(1.0); |
|
247 | m_barset->append(1.0); | |
248 | m_barset->append(2.0); |
|
248 | m_barset->append(2.0); | |
249 | m_barset->append(3.0); |
|
249 | m_barset->append(3.0); | |
250 | m_barset->append(4.0); |
|
250 | m_barset->append(4.0); | |
251 |
|
251 | |||
252 | QCOMPARE(m_barset->count(), 4); |
|
252 | QCOMPARE(m_barset->count(), 4); | |
253 | QCOMPARE(m_barset->sum(), 10.0); |
|
253 | QCOMPARE(m_barset->sum(), 10.0); | |
254 |
|
254 | |||
255 | m_barset->replace(0, 5.0); // 5.0 2.0 3.0 4.0 |
|
255 | m_barset->replace(0, 5.0); // 5.0 2.0 3.0 4.0 | |
256 | QCOMPARE(m_barset->count(), 4); |
|
256 | QCOMPARE(m_barset->count(), 4); | |
257 | QCOMPARE(m_barset->sum(), 14.0); |
|
257 | QCOMPARE(m_barset->sum(), 14.0); | |
258 | QCOMPARE(m_barset->at(0), 5.0); |
|
258 | QCOMPARE(m_barset->at(0).y(), 5.0); | |
259 |
|
259 | |||
260 | m_barset->replace(3, 6.0); |
|
260 | m_barset->replace(3, 6.0); | |
261 | QCOMPARE(m_barset->count(), 4); // 5.0 2.0 3.0 6.0 |
|
261 | QCOMPARE(m_barset->count(), 4); // 5.0 2.0 3.0 6.0 | |
262 | QCOMPARE(m_barset->sum(), 16.0); |
|
262 | QCOMPARE(m_barset->sum(), 16.0); | |
263 | QCOMPARE(m_barset->at(0), 5.0); |
|
263 | QCOMPARE(m_barset->at(0).y(), 5.0); | |
264 | QCOMPARE(m_barset->at(1), 2.0); |
|
264 | QCOMPARE(m_barset->at(1).y(), 2.0); | |
265 | QCOMPARE(m_barset->at(2), 3.0); |
|
265 | QCOMPARE(m_barset->at(2).y(), 3.0); | |
266 | QCOMPARE(m_barset->at(3), 6.0); |
|
266 | QCOMPARE(m_barset->at(3).y(), 6.0); | |
267 | } |
|
267 | } | |
268 |
|
268 | |||
269 | void tst_QBarSet::at_data() |
|
269 | void tst_QBarSet::at_data() | |
270 | { |
|
270 | { | |
271 |
|
271 | |||
272 | } |
|
272 | } | |
273 |
|
273 | |||
274 | void tst_QBarSet::at() |
|
274 | void tst_QBarSet::at() | |
275 | { |
|
275 | { | |
276 | QCOMPARE(m_barset->count(), 0); |
|
276 | QCOMPARE(m_barset->count(), 0); | |
277 | QVERIFY(qFuzzyIsNull(m_barset->sum())); |
|
277 | QVERIFY(qFuzzyIsNull(m_barset->sum())); | |
278 |
|
278 | |||
279 | m_barset->append(1.0); |
|
279 | m_barset->append(1.0); | |
280 | m_barset->append(2.0); |
|
280 | m_barset->append(2.0); | |
281 | m_barset->append(3.0); |
|
281 | m_barset->append(3.0); | |
282 | m_barset->append(4.0); |
|
282 | m_barset->append(4.0); | |
283 |
|
283 | |||
284 | QCOMPARE(m_barset->at(0), 1.0); |
|
284 | QCOMPARE(m_barset->at(0).y(), 1.0); | |
285 | QCOMPARE(m_barset->at(1), 2.0); |
|
285 | QCOMPARE(m_barset->at(1).y(), 2.0); | |
286 | QCOMPARE(m_barset->at(2), 3.0); |
|
286 | QCOMPARE(m_barset->at(2).y(), 3.0); | |
287 | QCOMPARE(m_barset->at(3), 4.0); |
|
287 | QCOMPARE(m_barset->at(3).y(), 4.0); | |
288 | } |
|
288 | } | |
289 |
|
289 | |||
290 | void tst_QBarSet::atOperator_data() |
|
290 | void tst_QBarSet::atOperator_data() | |
291 | { |
|
291 | { | |
292 |
|
292 | |||
293 | } |
|
293 | } | |
294 |
|
294 | |||
295 | void tst_QBarSet::atOperator() |
|
295 | void tst_QBarSet::atOperator() | |
296 | { |
|
296 | { | |
297 | QCOMPARE(m_barset->count(), 0); |
|
297 | QCOMPARE(m_barset->count(), 0); | |
298 | QVERIFY(qFuzzyIsNull(m_barset->sum())); |
|
298 | QVERIFY(qFuzzyIsNull(m_barset->sum())); | |
299 |
|
299 | |||
300 | m_barset->append(1.0); |
|
300 | m_barset->append(1.0); | |
301 | m_barset->append(2.0); |
|
301 | m_barset->append(2.0); | |
302 | m_barset->append(3.0); |
|
302 | m_barset->append(3.0); | |
303 | m_barset->append(4.0); |
|
303 | m_barset->append(4.0); | |
304 |
|
304 | |||
305 | QCOMPARE(m_barset->operator [](0), 1.0); |
|
305 | QCOMPARE(m_barset->operator [](0).y(), 1.0); | |
306 | QCOMPARE(m_barset->operator [](1), 2.0); |
|
306 | QCOMPARE(m_barset->operator [](1).y(), 2.0); | |
307 | QCOMPARE(m_barset->operator [](2), 3.0); |
|
307 | QCOMPARE(m_barset->operator [](2).y(), 3.0); | |
308 | QCOMPARE(m_barset->operator [](3), 4.0); |
|
308 | QCOMPARE(m_barset->operator [](3).y(), 4.0); | |
309 | } |
|
309 | } | |
310 |
|
310 | |||
311 | void tst_QBarSet::count_data() |
|
311 | void tst_QBarSet::count_data() | |
312 | { |
|
312 | { | |
313 |
|
313 | |||
314 | } |
|
314 | } | |
315 |
|
315 | |||
316 | void tst_QBarSet::count() |
|
316 | void tst_QBarSet::count() | |
317 | { |
|
317 | { | |
318 | QCOMPARE(m_barset->count(), 0); |
|
318 | QCOMPARE(m_barset->count(), 0); | |
319 | QVERIFY(qFuzzyIsNull(m_barset->sum())); |
|
319 | QVERIFY(qFuzzyIsNull(m_barset->sum())); | |
320 |
|
320 | |||
321 | m_barset->append(1.0); |
|
321 | m_barset->append(1.0); | |
322 | QCOMPARE(m_barset->count(),1); |
|
322 | QCOMPARE(m_barset->count(),1); | |
323 | m_barset->append(2.0); |
|
323 | m_barset->append(2.0); | |
324 | QCOMPARE(m_barset->count(),2); |
|
324 | QCOMPARE(m_barset->count(),2); | |
325 | m_barset->append(3.0); |
|
325 | m_barset->append(3.0); | |
326 | QCOMPARE(m_barset->count(),3); |
|
326 | QCOMPARE(m_barset->count(),3); | |
327 | m_barset->append(4.0); |
|
327 | m_barset->append(4.0); | |
328 | QCOMPARE(m_barset->count(),4); |
|
328 | QCOMPARE(m_barset->count(),4); | |
329 | } |
|
329 | } | |
330 |
|
330 | |||
331 | void tst_QBarSet::sum_data() |
|
331 | void tst_QBarSet::sum_data() | |
332 | { |
|
332 | { | |
333 |
|
333 | |||
334 | } |
|
334 | } | |
335 |
|
335 | |||
336 | void tst_QBarSet::sum() |
|
336 | void tst_QBarSet::sum() | |
337 | { |
|
337 | { | |
338 | QCOMPARE(m_barset->count(), 0); |
|
338 | QCOMPARE(m_barset->count(), 0); | |
339 | QVERIFY(qFuzzyIsNull(m_barset->sum())); |
|
339 | QVERIFY(qFuzzyIsNull(m_barset->sum())); | |
340 |
|
340 | |||
341 | m_barset->append(1.0); |
|
341 | m_barset->append(1.0); | |
342 | QVERIFY(qFuzzyCompare(m_barset->sum(),1.0)); |
|
342 | QVERIFY(qFuzzyCompare(m_barset->sum(),1.0)); | |
343 | m_barset->append(2.0); |
|
343 | m_barset->append(2.0); | |
344 | QVERIFY(qFuzzyCompare(m_barset->sum(),3.0)); |
|
344 | QVERIFY(qFuzzyCompare(m_barset->sum(),3.0)); | |
345 | m_barset->append(3.0); |
|
345 | m_barset->append(3.0); | |
346 | QVERIFY(qFuzzyCompare(m_barset->sum(),6.0)); |
|
346 | QVERIFY(qFuzzyCompare(m_barset->sum(),6.0)); | |
347 | m_barset->append(4.0); |
|
347 | m_barset->append(4.0); | |
348 | QVERIFY(qFuzzyCompare(m_barset->sum(),10.0)); |
|
348 | QVERIFY(qFuzzyCompare(m_barset->sum(),10.0)); | |
349 | } |
|
349 | } | |
350 |
|
350 | |||
351 | void tst_QBarSet::setPen_data() |
|
351 | void tst_QBarSet::setPen_data() | |
352 | { |
|
352 | { | |
353 |
|
353 | |||
354 | } |
|
354 | } | |
355 |
|
355 | |||
356 | void tst_QBarSet::setPen() |
|
356 | void tst_QBarSet::setPen() | |
357 | { |
|
357 | { | |
358 | QVERIFY(m_barset->pen() == QPen()); |
|
358 | QVERIFY(m_barset->pen() == QPen()); | |
359 |
|
359 | |||
360 | QPen pen; |
|
360 | QPen pen; | |
361 | pen.setColor(QColor(128,128,128,128)); |
|
361 | pen.setColor(QColor(128,128,128,128)); | |
362 | m_barset->setPen(pen); |
|
362 | m_barset->setPen(pen); | |
363 |
|
363 | |||
364 | QVERIFY(m_barset->pen() == pen); |
|
364 | QVERIFY(m_barset->pen() == pen); | |
365 | } |
|
365 | } | |
366 |
|
366 | |||
367 | void tst_QBarSet::setBrush_data() |
|
367 | void tst_QBarSet::setBrush_data() | |
368 | { |
|
368 | { | |
369 |
|
369 | |||
370 | } |
|
370 | } | |
371 |
|
371 | |||
372 | void tst_QBarSet::setBrush() |
|
372 | void tst_QBarSet::setBrush() | |
373 | { |
|
373 | { | |
374 | QVERIFY(m_barset->brush() == QBrush()); |
|
374 | QVERIFY(m_barset->brush() == QBrush()); | |
375 |
|
375 | |||
376 | QBrush brush; |
|
376 | QBrush brush; | |
377 | brush.setColor(QColor(128,128,128,128)); |
|
377 | brush.setColor(QColor(128,128,128,128)); | |
378 | m_barset->setBrush(brush); |
|
378 | m_barset->setBrush(brush); | |
379 |
|
379 | |||
380 | QVERIFY(m_barset->brush() == brush); |
|
380 | QVERIFY(m_barset->brush() == brush); | |
381 | } |
|
381 | } | |
382 |
|
382 | |||
383 | void tst_QBarSet::setLabelPen_data() |
|
383 | void tst_QBarSet::setLabelPen_data() | |
384 | { |
|
384 | { | |
385 |
|
385 | |||
386 | } |
|
386 | } | |
387 |
|
387 | |||
388 | void tst_QBarSet::setLabelPen() |
|
388 | void tst_QBarSet::setLabelPen() | |
389 | { |
|
389 | { | |
390 | QVERIFY(m_barset->labelPen() == QPen()); |
|
390 | QVERIFY(m_barset->labelPen() == QPen()); | |
391 |
|
391 | |||
392 | QPen pen; |
|
392 | QPen pen; | |
393 | pen.setColor(QColor(128,128,128,128)); |
|
393 | pen.setColor(QColor(128,128,128,128)); | |
394 | m_barset->setLabelPen(pen); |
|
394 | m_barset->setLabelPen(pen); | |
395 |
|
395 | |||
396 | QVERIFY(m_barset->labelPen() == pen); |
|
396 | QVERIFY(m_barset->labelPen() == pen); | |
397 | } |
|
397 | } | |
398 |
|
398 | |||
399 | void tst_QBarSet::setLabelBrush_data() |
|
399 | void tst_QBarSet::setLabelBrush_data() | |
400 | { |
|
400 | { | |
401 |
|
401 | |||
402 | } |
|
402 | } | |
403 |
|
403 | |||
404 | void tst_QBarSet::setLabelBrush() |
|
404 | void tst_QBarSet::setLabelBrush() | |
405 | { |
|
405 | { | |
406 | QVERIFY(m_barset->labelBrush() == QBrush()); |
|
406 | QVERIFY(m_barset->labelBrush() == QBrush()); | |
407 |
|
407 | |||
408 | QBrush brush; |
|
408 | QBrush brush; | |
409 | brush.setColor(QColor(128,128,128,128)); |
|
409 | brush.setColor(QColor(128,128,128,128)); | |
410 | m_barset->setLabelBrush(brush); |
|
410 | m_barset->setLabelBrush(brush); | |
411 |
|
411 | |||
412 | QVERIFY(m_barset->labelBrush() == brush); |
|
412 | QVERIFY(m_barset->labelBrush() == brush); | |
413 | } |
|
413 | } | |
414 |
|
414 | |||
415 | void tst_QBarSet::setLabelFont_data() |
|
415 | void tst_QBarSet::setLabelFont_data() | |
416 | { |
|
416 | { | |
417 |
|
417 | |||
418 | } |
|
418 | } | |
419 |
|
419 | |||
420 | void tst_QBarSet::setLabelFont() |
|
420 | void tst_QBarSet::setLabelFont() | |
421 | { |
|
421 | { | |
422 | QVERIFY(m_barset->labelFont() == QFont()); |
|
422 | QVERIFY(m_barset->labelFont() == QFont()); | |
423 |
|
423 | |||
424 | QFont font; |
|
424 | QFont font; | |
425 | font.setBold(true); |
|
425 | font.setBold(true); | |
426 | font.setItalic(true); |
|
426 | font.setItalic(true); | |
427 | m_barset->setLabelFont(font); |
|
427 | m_barset->setLabelFont(font); | |
428 |
|
428 | |||
429 | QVERIFY(m_barset->labelFont() == font); |
|
429 | QVERIFY(m_barset->labelFont() == font); | |
430 | } |
|
430 | } | |
431 |
|
431 | |||
432 |
|
432 | |||
433 | QTEST_MAIN(tst_QBarSet) |
|
433 | QTEST_MAIN(tst_QBarSet) | |
434 |
|
434 | |||
435 | #include "tst_qbarset.moc" |
|
435 | #include "tst_qbarset.moc" | |
436 |
|
436 |
General Comments 0
You need to be logged in to leave comments.
Login now