|
1 | NO CONTENT: new file 100644, binary diff hidden |
@@ -0,0 +1,45 | |||
|
1 | /*! | |
|
2 | \example examples/populationpyramid | |
|
3 | \title Population pyramid example | |
|
4 | \subtitle | |
|
5 | ||
|
6 | The example shows how to create a bar chart with bars extending in opposite directions. For example purposes we use population data found from wikipedia. | |
|
7 | ||
|
8 | \image examples_populationpyramid.png | |
|
9 | ||
|
10 | First we create two barsets and append the data to them. To make another barset grow to left, the values are negated. | |
|
11 | ||
|
12 | \snippet ../examples/populationpyramid/main.cpp 1 | |
|
13 | ||
|
14 | We create the series and append the barsets to it. The series takes ownership of the barsets. We want the bars to be at same position on the y-axis, so we turn the | |
|
15 | overlap drawing on. We also set the bar width to be 50% of the category width. | |
|
16 | ||
|
17 | \snippet ../examples/populationpyramid/main.cpp 2 | |
|
18 | ||
|
19 | Here we create the chart object and add the series to it. We set the title for chart with setTitle and then turn on animations of the series by calling | |
|
20 | setAnimationOptions(QChart::SeriesAnimations) | |
|
21 | ||
|
22 | \snippet ../examples/populationpyramid/main.cpp 3 | |
|
23 | ||
|
24 | To have categories displayed on axis, we need to create a QBarCategoryAxis for that. Here we create a category axis with list of categories and | |
|
25 | set it to be the y-axis of the chart. The chart takes ownership of axis. For x-axis we use default axis, which is created and scaled to series data | |
|
26 | by calling createDefaultAxes of the chart. Note that the call for createDefaultAxes must be before we set the category axis. Otherwise the default axis will | |
|
27 | override the category axis. | |
|
28 | We also set the range for x-axis, since in this case it gives nicer result than autoscaling. | |
|
29 | ||
|
30 | \snippet ../examples/populationpyramid/main.cpp 4 | |
|
31 | ||
|
32 | We also want to show the legend. To do that, we get the legend pointer from chart and set it to visible. We also place the legend to bottom of the chart by setting it's alignment | |
|
33 | to Qt::AlignBottom. | |
|
34 | ||
|
35 | \snippet ../examples/populationpyramid/main.cpp 5 | |
|
36 | ||
|
37 | Finally we add the chart onto a view. We also turn on the antialiasing for the chartView. | |
|
38 | ||
|
39 | \snippet ../examples/populationpyramid/main.cpp 6 | |
|
40 | ||
|
41 | Chart is ready to be shown. We set the chart to be central widget of the window. | |
|
42 | We also set the size for the chart window and show it. | |
|
43 | ||
|
44 | \snippet ../examples/populationpyramid/main.cpp 7 | |
|
45 | */ No newline at end of file |
@@ -1,45 +1,46 | |||
|
1 | 1 | /*! |
|
2 | 2 | \page examples.html |
|
3 | 3 | \title Examples |
|
4 | 4 | \keyword Examples |
|
5 | 5 | |
|
6 | 6 | \raw HTML |
|
7 | 7 | <table cellpadding="2" cellspacing="1" border="0" width="100%" class="indextable"> |
|
8 | 8 | <tr> |
|
9 | 9 | <th class="titleheader" width="33%"> |
|
10 | 10 | List of examples |
|
11 | 11 | </th> |
|
12 | 12 | </tr> |
|
13 | 13 | <tr> |
|
14 | 14 | <td valign="top"> |
|
15 | 15 | <ul> |
|
16 | 16 | <li><a href="examples-areachart.html">Area chart</a></li> |
|
17 | 17 | <li><a href="examples-barchart.html">Bar chart</a></li> |
|
18 | 18 | <li><a href="examples-customchart.html">Custom chart</a></li> |
|
19 | 19 | <li><a href="examples-horizontalbarchart.html">Horizontal bar chart</a></li> |
|
20 | 20 | <li><a href="examples-horizontalstackedbarchart.html">Horizontal stacked bar chart</a></li> |
|
21 | 21 | <li><a href="examples-horizontalpercentbarchart.html">Horizontal percent bar chart</a></li> |
|
22 | 22 | <li><a href="examples-legend.html">Legend</a></li> |
|
23 | 23 | <li><a href="examples-linechart.html">Line chart</a></li> |
|
24 | 24 | <li><a href="examples-lineandbar.html">Line and barchart</a></li> |
|
25 | 25 | <li><a href="examples-modeldata.html">Model data</a></li> |
|
26 | 26 | <li><a href="examples-barmodelmapper.html">Bar chart from model</a></li> |
|
27 | 27 | <li><a href="examples-percentbarchart.html">Percent bar chart</a></li> |
|
28 | <li><a href="examples-populationpyramid.html">Population pyramid</a></li> | |
|
28 | 29 | <li><a href="examples-piechart.html">Pie chart</a></li> |
|
29 | 30 | <li><a href="examples-donutchart.html">Donut chart</a></li> |
|
30 | 31 | <li><a href="examples-piechartdrilldown.html">Pie chart drilldown</a></li> |
|
31 | 32 | <li><a href="examples-donut.html">Nested donuts chart</a></li> |
|
32 | 33 | <li><a href="examples-donutbreakdown.html">Donut chart drilldown</a></li> |
|
33 | 34 | <li><a href="examples-presenterchart.html">Presenter chart</a></li> |
|
34 | 35 | <li><a href="examples-scatterchart.html">Scatter chart</a></li> |
|
35 | 36 | <li><a href="examples-scatterinteractions.html">Scatter interactions</a></li> |
|
36 | 37 | <li><a href="examples-splinechart.html">Spline chart</a></li> |
|
37 | 38 | <li><a href="examples-stackedbarchart.html">Stacked bar chart</a></li> |
|
38 | 39 | <li><a href="examples-stackedbarchartdrilldown.html">Stacked bar chart drilldown</a></li> |
|
39 | 40 | <li><a href="examples-zoomlinechart.html">Zoom line</a></li> |
|
40 | 41 | </ul> |
|
41 | 42 | </td> |
|
42 | 43 | </tr> |
|
43 | 44 | </table> |
|
44 | 45 | \endraw |
|
45 | 46 | */ |
@@ -1,94 +1,94 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #include <QApplication> |
|
22 | 22 | #include <QMainWindow> |
|
23 | 23 | #include <QChartView> |
|
24 | 24 | #include <QBarSeries> |
|
25 | 25 | #include <QBarSet> |
|
26 | 26 | #include <QLegend> |
|
27 | 27 | #include <QBarCategoryAxis> |
|
28 | 28 | #include <QHorizontalBarSeries> |
|
29 | 29 | |
|
30 | 30 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
31 | 31 | |
|
32 | 32 | int main(int argc, char *argv[]) |
|
33 | 33 | { |
|
34 | 34 | QApplication a(argc, argv); |
|
35 | 35 | |
|
36 | 36 | //![1] |
|
37 | 37 | QBarSet *male = new QBarSet("Male"); |
|
38 | 38 | QBarSet *female = new QBarSet("Female"); |
|
39 | 39 | |
|
40 | // From wikipedia | |
|
40 | // Not really negative population. Negated values are used to grow bar to left. | |
|
41 | 41 | *male << -145596 << -149894 << -167327 << -164118 << -170710 << -169408 << -158395 << -176975 << -191803 << -191198 << -196815 |
|
42 | 42 | << -207826 << -145517 << -113204 << -90986 << -70909 << -40013 << -15887 << -5769; |
|
43 | 43 | |
|
44 | 44 | *female << 139353 << 143522 << 161212 << 156824 << 163226 << 161766 << 150595 << 170779 << 185979 << 187897 << 196158 |
|
45 | 45 | << 209062 << 152460 << 129230 << 114778 << 109611 << 83845 << 44605 << 22328; |
|
46 | 46 | |
|
47 | 47 | //![1] |
|
48 | 48 | |
|
49 | 49 | //![2] |
|
50 | 50 | QHorizontalBarSeries *series = new QHorizontalBarSeries(); |
|
51 | 51 | series->append(male); |
|
52 | 52 | series->append(female); |
|
53 | 53 | series->setBarWidth(0.5); |
|
54 |
series->set |
|
|
54 | series->setOverlap(true); | |
|
55 | 55 | //![2] |
|
56 | 56 | |
|
57 | 57 | //![3] |
|
58 | 58 | QChart* chart = new QChart(); |
|
59 | 59 | chart->addSeries(series); |
|
60 | 60 | chart->setTitle("Population of Finland in 2005 by age group"); |
|
61 | chart->createDefaultAxes(); | |
|
62 | 61 | chart->setAnimationOptions(QChart::SeriesAnimations); |
|
63 | 62 | //![3] |
|
64 | 63 | |
|
65 | 64 | //![4] |
|
66 | 65 | QStringList categories; |
|
67 | 66 | categories << "0-4" << "5-9" << "10-14" << "15-19" << "20-24" << "25-29" << "30-34" << "35-39" << "40-44" << "45-49" |
|
68 | 67 | << "50-54" << "55-59" << "60-64" << "65-69" << "70-74" << "75-79" << "80-84" << "85-89" << "90-"; |
|
69 | 68 | |
|
70 | 69 | QBarCategoryAxis* axis = new QBarCategoryAxis(); |
|
71 | 70 | axis->append(categories); |
|
71 | chart->createDefaultAxes(); | |
|
72 | 72 | chart->setAxisY(axis,series); |
|
73 | 73 | chart->axisX(series)->setRange(-210000,210000); |
|
74 | 74 | //![4] |
|
75 | 75 | |
|
76 | 76 | //![5] |
|
77 | 77 | chart->legend()->setVisible(true); |
|
78 | 78 | chart->legend()->setAlignment(Qt::AlignBottom); |
|
79 | 79 | //![5] |
|
80 | 80 | |
|
81 | 81 | //![6] |
|
82 | 82 | QChartView* chartView = new QChartView(chart); |
|
83 | 83 | chartView->setRenderHint(QPainter::Antialiasing); |
|
84 | 84 | //![6] |
|
85 | 85 | |
|
86 | 86 | //![7] |
|
87 | 87 | QMainWindow window; |
|
88 | 88 | window.setCentralWidget(chartView); |
|
89 |
window.resize(400, |
|
|
89 | window.resize(400, 600); | |
|
90 | 90 | window.show(); |
|
91 | 91 | //![7] |
|
92 | 92 | |
|
93 | 93 | return a.exec(); |
|
94 | 94 | } |
@@ -1,106 +1,106 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #include "horizontalbarchartitem_p.h" |
|
22 | 22 | #include "qabstractbarseries_p.h" |
|
23 | 23 | #include "qbarset_p.h" |
|
24 | 24 | #include "bar_p.h" |
|
25 | 25 | |
|
26 | 26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
27 | 27 | |
|
28 | 28 | HorizontalBarChartItem::HorizontalBarChartItem(QAbstractBarSeries *series, ChartPresenter *presenter) : |
|
29 | 29 | AbstractBarChartItem(series, presenter) |
|
30 | 30 | { |
|
31 | 31 | } |
|
32 | 32 | |
|
33 | 33 | QVector<QRectF> HorizontalBarChartItem::calculateLayout() |
|
34 | 34 | { |
|
35 | 35 | QVector<QRectF> layout; |
|
36 | 36 | |
|
37 | 37 | // Use temporary qreals for accuracy |
|
38 | 38 | qreal categoryCount = m_series->d_func()->categoryCount(); |
|
39 | 39 | qreal setCount = m_series->count(); |
|
40 | 40 | bool barsVisible = m_series->isVisible(); |
|
41 | 41 | |
|
42 | 42 | // Domain: |
|
43 | 43 | qreal width = geometry().width(); |
|
44 | 44 | qreal height = geometry().height(); |
|
45 | 45 | qreal rangeY = m_domainMaxY - m_domainMinY; |
|
46 | 46 | qreal rangeX = m_domainMaxX - m_domainMinX; |
|
47 | 47 | qreal scaleY = (height / rangeY); |
|
48 | 48 | qreal scaleX = (width / rangeX); |
|
49 | 49 | qreal barHeight; |
|
50 | 50 | |
|
51 | 51 | // On horizontal chart barWidth of the barseries means height of the rect. |
|
52 |
if (m_series->d_func()->m_ |
|
|
53 | barHeight = (scaleY / setCount) * m_series->d_func()->barWidth(); | |
|
54 | } else { | |
|
52 | if (m_series->d_func()->m_overlap) { | |
|
55 | 53 | barHeight = scaleY * m_series->d_func()->barWidth(); |
|
54 | } else { | |
|
55 | barHeight = (scaleY / setCount) * m_series->d_func()->barWidth(); | |
|
56 | 56 | } |
|
57 | 57 | |
|
58 | 58 | int itemIndex(0); |
|
59 | 59 | for (int category = 0; category < categoryCount; category++) { |
|
60 | 60 | qreal xPos = -scaleX * m_domainMinX + geometry().left(); |
|
61 | 61 | for (int set = 0; set < setCount; set++) { |
|
62 | 62 | QBarSetPrivate* barSet = m_series->d_func()->barsetAt(set)->d_ptr.data(); |
|
63 | 63 | |
|
64 | 64 | qreal yPos = m_rect.bottom() + (m_domainMinY - barSet->pos(category)) * scaleY; |
|
65 |
if (m_series->d_func()->m_ |
|
|
65 | if (m_series->d_func()->m_overlap) { | |
|
66 | yPos += barHeight/2; | |
|
67 | } else { | |
|
66 | 68 | yPos += setCount*barHeight/2; |
|
67 | 69 | yPos -= set*barHeight; |
|
68 | } else { | |
|
69 | yPos += barHeight/2; | |
|
70 | 70 | } |
|
71 | 71 | |
|
72 | 72 | qreal barWidth = barSet->value(category) * scaleX; |
|
73 | 73 | Bar* bar = m_bars.at(itemIndex); |
|
74 | 74 | |
|
75 | 75 | QRectF rect(xPos, yPos - barHeight, barWidth, barHeight); |
|
76 | 76 | layout.append(rect); |
|
77 | 77 | bar->setPen(barSet->m_pen); |
|
78 | 78 | bar->setBrush(barSet->m_brush); |
|
79 | 79 | if (qFuzzyIsNull(barHeight)) { |
|
80 | 80 | bar->setVisible(false); |
|
81 | 81 | } else { |
|
82 | 82 | bar->setVisible(barsVisible); |
|
83 | 83 | } |
|
84 | 84 | |
|
85 | 85 | QGraphicsSimpleTextItem* label = m_labels.at(itemIndex); |
|
86 | 86 | |
|
87 | 87 | if (!qFuzzyIsNull(barSet->value(category))) { |
|
88 | 88 | label->setText(QString::number(barSet->value(category))); |
|
89 | 89 | } else { |
|
90 | 90 | label->setText(QString("")); |
|
91 | 91 | } |
|
92 | 92 | |
|
93 | 93 | label->setPos(xPos + (rect.width()/2 - label->boundingRect().width()/2) |
|
94 | 94 | ,yPos - barHeight/2 - label->boundingRect().height()/2); |
|
95 | 95 | label->setFont(barSet->m_labelFont); |
|
96 | 96 | label->setBrush(barSet->m_labelBrush); |
|
97 | 97 | |
|
98 | 98 | itemIndex++; |
|
99 | 99 | } |
|
100 | 100 | } |
|
101 | 101 | return layout; |
|
102 | 102 | } |
|
103 | 103 | |
|
104 | 104 | #include "moc_horizontalbarchartitem_p.cpp" |
|
105 | 105 | |
|
106 | 106 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,834 +1,835 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #include "qabstractbarseries.h" |
|
22 | 22 | #include "qabstractbarseries_p.h" |
|
23 | 23 | #include "qbarset.h" |
|
24 | 24 | #include "qbarset_p.h" |
|
25 | 25 | #include "domain_p.h" |
|
26 | 26 | #include "legendmarker_p.h" |
|
27 | 27 | #include "chartdataset_p.h" |
|
28 | 28 | #include "charttheme_p.h" |
|
29 | 29 | #include "qvalueaxis.h" |
|
30 | 30 | #include "qbarcategoryaxis.h" |
|
31 | 31 | |
|
32 | 32 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
33 | 33 | |
|
34 | 34 | /*! |
|
35 | 35 | \class QAbstractBarSeries |
|
36 | 36 | \brief Series for creating a bar chart |
|
37 | 37 | \mainclass |
|
38 | 38 | |
|
39 | 39 | QAbstractBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars to |
|
40 | 40 | the position defined by data. Single bar is defined by QPointF, where x value is the x-coordinate of the bar |
|
41 | 41 | and y-value is the height of the bar. The category names are ignored with this series and x-axis |
|
42 | 42 | shows the x-values. |
|
43 | 43 | |
|
44 | 44 | See the \l {BarChart Example} {bar chart example} to learn how to create a simple bar chart. |
|
45 | 45 | \image examples_barchart.png |
|
46 | 46 | |
|
47 | 47 | \sa QBarSet, QStackedBarSeries, QPercentBarSeries |
|
48 | 48 | */ |
|
49 | 49 | /*! |
|
50 | 50 | \qmlclass AbstractBarSeries QAbstractBarSeries |
|
51 | 51 | \inherits QAbstractSeries |
|
52 | 52 | |
|
53 | 53 | The following QML shows how to create a simple bar chart: |
|
54 | 54 | \snippet ../demos/qmlchart/qml/qmlchart/View6.qml 1 |
|
55 | 55 | |
|
56 | 56 | \beginfloatleft |
|
57 | 57 | \image demos_qmlchart6.png |
|
58 | 58 | \endfloat |
|
59 | 59 | \clearfloat |
|
60 | 60 | */ |
|
61 | 61 | |
|
62 | 62 | /*! |
|
63 | 63 | \property QAbstractBarSeries::barWidth |
|
64 | 64 | The width of the bars of the series. The unit of \a width is the unit of x-axis. The minimum width for bars |
|
65 | 65 | is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen |
|
66 | 66 | is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis. |
|
67 | 67 | Note that with QBarSeries this value means the width of one group of bars instead of just one bar. |
|
68 | 68 | \sa QBarSeries |
|
69 | 69 | */ |
|
70 | 70 | /*! |
|
71 | 71 | \qmlproperty real AbstractBarSeries::barWidth |
|
72 | 72 | The width of the bars of the series. The unit of width is the unit of x-axis. The minimum width for bars |
|
73 | 73 | is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen |
|
74 | 74 | is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis. |
|
75 | 75 | Note that with QBarSeries this value means the width of one group of bars instead of just one bar. |
|
76 | 76 | */ |
|
77 | 77 | |
|
78 | 78 | /*! |
|
79 | 79 | \property QAbstractBarSeries::count |
|
80 | 80 | Holds the number of sets in series. |
|
81 | 81 | */ |
|
82 | 82 | /*! |
|
83 | 83 | \qmlproperty int AbstractBarSeries::count |
|
84 | 84 | Holds the number of sets in series. |
|
85 | 85 | */ |
|
86 | 86 | |
|
87 | 87 | /*! |
|
88 | 88 | \property QAbstractBarSeries::labelsVisible |
|
89 | 89 | Defines the visibility of the labels in series |
|
90 | 90 | */ |
|
91 | 91 | /*! |
|
92 | 92 | \qmlproperty bool AbstractBarSeries::labelsVisible |
|
93 | 93 | Defines the visibility of the labels in series |
|
94 | 94 | */ |
|
95 | 95 | |
|
96 | 96 | /*! |
|
97 | 97 | \fn void QAbstractBarSeries::clicked(int index, QBarSet *barset) |
|
98 | 98 | The signal is emitted if the user clicks with a mouse on top of QBarSet \a barset. |
|
99 | 99 | Clicked bar inside set is indexed by \a index |
|
100 | 100 | */ |
|
101 | 101 | /*! |
|
102 | 102 | \qmlsignal AbstractBarSeries::onClicked(int index, BarSet barset) |
|
103 | 103 | The signal is emitted if the user clicks with a mouse on top of BarSet. |
|
104 | 104 | Clicked bar inside set is indexed by \a index |
|
105 | 105 | */ |
|
106 | 106 | |
|
107 | 107 | /*! |
|
108 | 108 | \fn void QAbstractBarSeries::hovered(bool status, QBarSet* barset) |
|
109 | 109 | |
|
110 | 110 | The signal is emitted if mouse is hovered on top of series. |
|
111 | 111 | Parameter \a barset is the pointer of barset, where hover happened. |
|
112 | 112 | Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series. |
|
113 | 113 | */ |
|
114 | 114 | /*! |
|
115 | 115 | \qmlsignal AbstractBarSeries::onHovered(bool status, BarSet barset) |
|
116 | 116 | |
|
117 | 117 | The signal is emitted if mouse is hovered on top of series. |
|
118 | 118 | Parameter \a barset is the pointer of barset, where hover happened. |
|
119 | 119 | Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series. |
|
120 | 120 | */ |
|
121 | 121 | |
|
122 | 122 | /*! |
|
123 | 123 | \fn void QAbstractBarSeries::countChanged() |
|
124 | 124 | This signal is emitted when barset count has been changed, for example by append or remove. |
|
125 | 125 | */ |
|
126 | 126 | /*! |
|
127 | 127 | \qmlsignal AbstractBarSeries::onCountChanged() |
|
128 | 128 | This signal is emitted when barset count has been changed, for example by append or remove. |
|
129 | 129 | */ |
|
130 | 130 | |
|
131 | 131 | /*! |
|
132 | 132 | \fn void QAbstractBarSeries::labelsVisibleChanged() |
|
133 | 133 | This signal is emitted when labels visibility have changed. |
|
134 | 134 | \sa isLabelsVisible(), setLabelsVisible() |
|
135 | 135 | */ |
|
136 | 136 | |
|
137 | 137 | /*! |
|
138 | 138 | \fn void QAbstractBarSeries::barsetsAdded(QList<QBarSet*> sets) |
|
139 | 139 | This signal is emitted when \a sets have been added to the series. |
|
140 | 140 | \sa append(), insert() |
|
141 | 141 | */ |
|
142 | 142 | /*! |
|
143 | 143 | \qmlsignal AbstractBarSeries::onAdded(BarSet barset) |
|
144 | 144 | Emitted when \a barset has been added to the series. |
|
145 | 145 | */ |
|
146 | 146 | |
|
147 | 147 | /*! |
|
148 | 148 | \fn void QAbstractBarSeries::barsetsRemoved(QList<QBarSet*> sets) |
|
149 | 149 | This signal is emitted when \a sets have been removed from the series. |
|
150 | 150 | \sa remove() |
|
151 | 151 | */ |
|
152 | 152 | /*! |
|
153 | 153 | \qmlsignal AbstractBarSeries::onRemoved(BarSet barset) |
|
154 | 154 | Emitted when \a barset has been removed from the series. |
|
155 | 155 | */ |
|
156 | 156 | |
|
157 | 157 | /*! |
|
158 | 158 | \qmlmethod BarSet AbstractBarSeries::at(int index) |
|
159 | 159 | Returns bar set at \a index. Returns null if the index is not valid. |
|
160 | 160 | */ |
|
161 | 161 | |
|
162 | 162 | /*! |
|
163 | 163 | \qmlmethod BarSet AbstractBarSeries::append(string label, VariantList values) |
|
164 | 164 | Adds a new bar set with \a label and \a values to \a index. Values can be a list of reals or a list of XYPoints. |
|
165 | 165 | For example: |
|
166 | 166 | \code |
|
167 | 167 | myBarSeries.append("set 1", [0, 0.2, 0.2, 0.5, 0.4, 1.5, 0.9]); |
|
168 | 168 | myBarSeries.append("set 2", [Qt.point(0, 1), Qt.point(2, 2.5), Qt.point(3.5, 2.2)]); |
|
169 | 169 | \endcode |
|
170 | 170 | */ |
|
171 | 171 | |
|
172 | 172 | /*! |
|
173 | 173 | \qmlmethod BarSet AbstractBarSeries::insert(int index, string label, VariantList values) |
|
174 | 174 | Inserts a new bar set with \a label and \a values to \a index. Values can be a list of reals or a list of XYPoints. |
|
175 | 175 | If index is zero or smaller, the new barset is prepended. If the index is count or bigger, the new barset is |
|
176 | 176 | appended. |
|
177 | 177 | \sa AbstractBarSeries::append() |
|
178 | 178 | */ |
|
179 | 179 | |
|
180 | 180 | /*! |
|
181 | 181 | \qmlmethod bool AbstractBarSeries::remove(BarSet barset) |
|
182 | 182 | Removes the barset from the series. Returns true if successfull, false otherwise. |
|
183 | 183 | */ |
|
184 | 184 | |
|
185 | 185 | /*! |
|
186 | 186 | \qmlmethod AbstractBarSeries::clear() |
|
187 | 187 | Removes all barsets from the series. |
|
188 | 188 | */ |
|
189 | 189 | |
|
190 | 190 | /*! |
|
191 | 191 | This is depreciated constructor. |
|
192 | 192 | \a parent |
|
193 | 193 | */ |
|
194 | 194 | QAbstractBarSeries::QAbstractBarSeries(QObject *parent) : |
|
195 | 195 | QAbstractSeries(*(QAbstractBarSeriesPrivate*)(0),parent) |
|
196 | 196 | { |
|
197 | 197 | } |
|
198 | 198 | |
|
199 | 199 | /*! |
|
200 | 200 | Destructs abstractbarseries and owned barsets. |
|
201 | 201 | */ |
|
202 | 202 | QAbstractBarSeries::~QAbstractBarSeries() |
|
203 | 203 | { |
|
204 | 204 | |
|
205 | 205 | } |
|
206 | 206 | |
|
207 | 207 | /*! |
|
208 | 208 | \internal |
|
209 | 209 | */ |
|
210 | 210 | QAbstractBarSeries::QAbstractBarSeries(QAbstractBarSeriesPrivate &d, QObject *parent) : |
|
211 | 211 | QAbstractSeries(d,parent) |
|
212 | 212 | { |
|
213 | 213 | } |
|
214 | 214 | |
|
215 | 215 | /*! |
|
216 | 216 | Sets the width of the bars of the series. The unit of \a width is the unit of x-axis. The minimum width for bars |
|
217 | 217 | is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen |
|
218 | 218 | is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis. |
|
219 | 219 | Note that with \link QBarSeries \endlink this value means the width of one group of bars instead of just one bar. |
|
220 | 220 | */ |
|
221 | 221 | void QAbstractBarSeries::setBarWidth(qreal width) |
|
222 | 222 | { |
|
223 | 223 | Q_D(QAbstractBarSeries); |
|
224 | 224 | d->setBarWidth(width); |
|
225 | 225 | } |
|
226 | 226 | |
|
227 | 227 | /*! |
|
228 | 228 | Returns the width of the bars of the series. |
|
229 | 229 | \sa setBarWidth() |
|
230 | 230 | */ |
|
231 | 231 | qreal QAbstractBarSeries::barWidth() const |
|
232 | 232 | { |
|
233 | 233 | Q_D(const QAbstractBarSeries); |
|
234 | 234 | return d->barWidth(); |
|
235 | 235 | } |
|
236 | 236 | |
|
237 | 237 | /*! |
|
238 | 238 | Adds a set of bars to series. Takes ownership of \a set. If the set is null or is already in series, it won't be appended. |
|
239 | 239 | Returns true, if appending succeeded. |
|
240 | 240 | */ |
|
241 | 241 | bool QAbstractBarSeries::append(QBarSet *set) |
|
242 | 242 | { |
|
243 | 243 | Q_D(QAbstractBarSeries); |
|
244 | 244 | bool success = d->append(set); |
|
245 | 245 | if (success) { |
|
246 | 246 | QList<QBarSet*> sets; |
|
247 | 247 | sets.append(set); |
|
248 | 248 | set->setParent(this); |
|
249 | 249 | emit barsetsAdded(sets); |
|
250 | 250 | emit countChanged(); |
|
251 | 251 | } |
|
252 | 252 | return success; |
|
253 | 253 | } |
|
254 | 254 | |
|
255 | 255 | /*! |
|
256 | 256 | Removes barset from series. Releases ownership of \a set. Deletes the set, if remove |
|
257 | 257 | was successful. |
|
258 | 258 | Returns true, if set was removed. |
|
259 | 259 | */ |
|
260 | 260 | bool QAbstractBarSeries::remove(QBarSet *set) |
|
261 | 261 | { |
|
262 | 262 | Q_D(QAbstractBarSeries); |
|
263 | 263 | bool success = d->remove(set); |
|
264 | 264 | if (success) { |
|
265 | 265 | QList<QBarSet*> sets; |
|
266 | 266 | sets.append(set); |
|
267 | 267 | set->setParent(0); |
|
268 | 268 | emit barsetsRemoved(sets); |
|
269 | 269 | emit countChanged(); |
|
270 | 270 | delete set; |
|
271 | 271 | set = 0; |
|
272 | 272 | } |
|
273 | 273 | return success; |
|
274 | 274 | } |
|
275 | 275 | |
|
276 | 276 | /*! |
|
277 | 277 | Takes a single \a set from the series. Does not delete the barset object. |
|
278 | 278 | |
|
279 | 279 | NOTE: The series remains as the barset's parent object. You must set the |
|
280 | 280 | parent object to take full ownership. |
|
281 | 281 | |
|
282 | 282 | Returns true if take was successfull. |
|
283 | 283 | */ |
|
284 | 284 | bool QAbstractBarSeries::take(QBarSet *set) |
|
285 | 285 | { |
|
286 | 286 | Q_D(QAbstractBarSeries); |
|
287 | 287 | bool success = d->remove(set); |
|
288 | 288 | if (success) { |
|
289 | 289 | QList<QBarSet*> sets; |
|
290 | 290 | sets.append(set); |
|
291 | 291 | emit barsetsRemoved(sets); |
|
292 | 292 | emit countChanged(); |
|
293 | 293 | } |
|
294 | 294 | return success; |
|
295 | 295 | } |
|
296 | 296 | |
|
297 | 297 | /*! |
|
298 | 298 | Adds a list of barsets to series. Takes ownership of \a sets. |
|
299 | 299 | Returns true, if all sets were appended succesfully. If any of the sets is null or is already appended to series, |
|
300 | 300 | nothing is appended and function returns false. If any of the sets is in list more than once, nothing is appended |
|
301 | 301 | and function returns false. |
|
302 | 302 | */ |
|
303 | 303 | bool QAbstractBarSeries::append(QList<QBarSet* > sets) |
|
304 | 304 | { |
|
305 | 305 | Q_D(QAbstractBarSeries); |
|
306 | 306 | bool success = d->append(sets); |
|
307 | 307 | if (success) { |
|
308 | 308 | emit barsetsAdded(sets); |
|
309 | 309 | emit countChanged(); |
|
310 | 310 | } |
|
311 | 311 | return success; |
|
312 | 312 | } |
|
313 | 313 | |
|
314 | 314 | /*! |
|
315 | 315 | Insert a set of bars to series at \a index postion. Takes ownership of \a set. If the set is null or is already in series, it won't be appended. |
|
316 | 316 | Returns true, if inserting succeeded. |
|
317 | 317 | |
|
318 | 318 | */ |
|
319 | 319 | bool QAbstractBarSeries::insert(int index, QBarSet *set) |
|
320 | 320 | { |
|
321 | 321 | Q_D(QAbstractBarSeries); |
|
322 | 322 | bool success = d->insert(index, set); |
|
323 | 323 | if (success) { |
|
324 | 324 | QList<QBarSet*> sets; |
|
325 | 325 | sets.append(set); |
|
326 | 326 | emit barsetsAdded(sets); |
|
327 | 327 | emit countChanged(); |
|
328 | 328 | } |
|
329 | 329 | return success; |
|
330 | 330 | } |
|
331 | 331 | |
|
332 | 332 | /*! |
|
333 | 333 | Removes all barsets from the series. Deletes removed sets. |
|
334 | 334 | */ |
|
335 | 335 | void QAbstractBarSeries::clear() |
|
336 | 336 | { |
|
337 | 337 | Q_D(QAbstractBarSeries); |
|
338 | 338 | QList<QBarSet *> sets = barSets(); |
|
339 | 339 | bool success = d->remove(sets); |
|
340 | 340 | if (success) { |
|
341 | 341 | emit barsetsRemoved(sets); |
|
342 | 342 | emit countChanged(); |
|
343 | 343 | foreach (QBarSet* set, sets) { |
|
344 | 344 | delete set; |
|
345 | 345 | } |
|
346 | 346 | } |
|
347 | 347 | } |
|
348 | 348 | |
|
349 | 349 | /*! |
|
350 | 350 | Returns number of sets in series. |
|
351 | 351 | */ |
|
352 | 352 | int QAbstractBarSeries::count() const |
|
353 | 353 | { |
|
354 | 354 | Q_D(const QAbstractBarSeries); |
|
355 | 355 | return d->m_barSets.count(); |
|
356 | 356 | } |
|
357 | 357 | |
|
358 | 358 | /*! |
|
359 | 359 | Returns a list of sets in series. Keeps ownership of sets. |
|
360 | 360 | */ |
|
361 | 361 | QList<QBarSet*> QAbstractBarSeries::barSets() const |
|
362 | 362 | { |
|
363 | 363 | Q_D(const QAbstractBarSeries); |
|
364 | 364 | return d->m_barSets; |
|
365 | 365 | } |
|
366 | 366 | |
|
367 | 367 | /*! |
|
368 | 368 | Sets the visibility of labels in series to \a visible |
|
369 | 369 | */ |
|
370 | 370 | void QAbstractBarSeries::setLabelsVisible(bool visible) |
|
371 | 371 | { |
|
372 | 372 | Q_D(QAbstractBarSeries); |
|
373 | 373 | if (d->m_labelsVisible != visible) { |
|
374 | 374 | d->setLabelsVisible(visible); |
|
375 | 375 | emit labelsVisibleChanged(); |
|
376 | 376 | } |
|
377 | 377 | } |
|
378 | 378 | |
|
379 | 379 | /*! |
|
380 | 380 | Returns the visibility of labels |
|
381 | 381 | */ |
|
382 | 382 | bool QAbstractBarSeries::isLabelsVisible() const |
|
383 | 383 | { |
|
384 | 384 | Q_D(const QAbstractBarSeries); |
|
385 | 385 | return d->m_labelsVisible; |
|
386 | 386 | } |
|
387 | 387 | |
|
388 | 388 | /*! |
|
389 |
Sets the |
|
|
389 | Sets the overlap drawing mode for bars. If \a overlap is true, then the bars | |
|
390 | 390 | are drawn at same position inside group. Can be used for example to draw negative bars |
|
391 | at same position on axis than positive bars. | |
|
391 | at same position on axis than positive bars. By default overlap is false and bars are drawn | |
|
392 | next to each other. Note that this setting doesn't affect stacked and percent bar series. | |
|
392 | 393 | */ |
|
393 |
void QAbstractBarSeries::set |
|
|
394 | void QAbstractBarSeries::setOverlap(bool overlap) | |
|
394 | 395 | { |
|
395 | 396 | Q_D(QAbstractBarSeries); |
|
396 | d->setGrouping(grouping); | |
|
397 | d->setOverlap(overlap); | |
|
397 | 398 | } |
|
398 | 399 | |
|
399 | 400 | |
|
400 | 401 | |
|
401 | 402 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
402 | 403 | |
|
403 | 404 | QAbstractBarSeriesPrivate::QAbstractBarSeriesPrivate(QAbstractBarSeries *q) : |
|
404 | 405 | QAbstractSeriesPrivate(q), |
|
405 | 406 | m_barWidth(0.5), // Default value is 50% of category width |
|
406 | 407 | m_labelsVisible(false), |
|
407 | 408 | m_visible(true), |
|
408 | m_grouping(true) | |
|
409 | m_overlap(false) | |
|
409 | 410 | { |
|
410 | 411 | } |
|
411 | 412 | |
|
412 | 413 | int QAbstractBarSeriesPrivate::categoryCount() const |
|
413 | 414 | { |
|
414 | 415 | // No categories defined. return count of longest set. |
|
415 | 416 | int count = 0; |
|
416 | 417 | for (int i=0; i<m_barSets.count(); i++) { |
|
417 | 418 | if (m_barSets.at(i)->count() > count) { |
|
418 | 419 | count = m_barSets.at(i)->count(); |
|
419 | 420 | } |
|
420 | 421 | } |
|
421 | 422 | |
|
422 | 423 | return count; |
|
423 | 424 | } |
|
424 | 425 | |
|
425 | 426 | void QAbstractBarSeriesPrivate::setBarWidth(qreal width) |
|
426 | 427 | { |
|
427 | 428 | if (width < 0.0) { |
|
428 | 429 | width = 0.0; |
|
429 | 430 | } |
|
430 | 431 | m_barWidth = width; |
|
431 | 432 | emit updatedBars(); |
|
432 | 433 | } |
|
433 | 434 | |
|
434 | 435 | qreal QAbstractBarSeriesPrivate::barWidth() const |
|
435 | 436 | { |
|
436 | 437 | return m_barWidth; |
|
437 | 438 | } |
|
438 | 439 | |
|
439 | 440 | QBarSet* QAbstractBarSeriesPrivate::barsetAt(int index) |
|
440 | 441 | { |
|
441 | 442 | return m_barSets.at(index); |
|
442 | 443 | } |
|
443 | 444 | |
|
444 | 445 | void QAbstractBarSeriesPrivate::setVisible(bool visible) |
|
445 | 446 | { |
|
446 | 447 | m_visible = visible; |
|
447 | 448 | emit updatedBars(); |
|
448 | 449 | } |
|
449 | 450 | |
|
450 | 451 | void QAbstractBarSeriesPrivate::setLabelsVisible(bool visible) |
|
451 | 452 | { |
|
452 | 453 | m_labelsVisible = visible; |
|
453 | 454 | emit labelsVisibleChanged(visible); |
|
454 | 455 | } |
|
455 | 456 | |
|
456 |
void QAbstractBarSeriesPrivate::set |
|
|
457 | void QAbstractBarSeriesPrivate::setOverlap(bool overlap) | |
|
457 | 458 | { |
|
458 |
if (m_ |
|
|
459 |
m_ |
|
|
459 | if (m_overlap != overlap) { | |
|
460 | m_overlap = overlap; | |
|
460 | 461 | emit updatedBars(); |
|
461 | 462 | } |
|
462 | 463 | } |
|
463 | 464 | |
|
464 | 465 | qreal QAbstractBarSeriesPrivate::min() |
|
465 | 466 | { |
|
466 | 467 | if (m_barSets.count() <= 0) { |
|
467 | 468 | return 0; |
|
468 | 469 | } |
|
469 | 470 | qreal min = INT_MAX; |
|
470 | 471 | |
|
471 | 472 | for (int i = 0; i < m_barSets.count(); i++) { |
|
472 | 473 | int categoryCount = m_barSets.at(i)->count(); |
|
473 | 474 | for (int j = 0; j < categoryCount; j++) { |
|
474 | 475 | qreal temp = m_barSets.at(i)->at(j); |
|
475 | 476 | if (temp < min) |
|
476 | 477 | min = temp; |
|
477 | 478 | } |
|
478 | 479 | } |
|
479 | 480 | return min; |
|
480 | 481 | } |
|
481 | 482 | |
|
482 | 483 | qreal QAbstractBarSeriesPrivate::max() |
|
483 | 484 | { |
|
484 | 485 | if (m_barSets.count() <= 0) { |
|
485 | 486 | return 0; |
|
486 | 487 | } |
|
487 | 488 | qreal max = INT_MIN; |
|
488 | 489 | |
|
489 | 490 | for (int i = 0; i < m_barSets.count(); i++) { |
|
490 | 491 | int categoryCount = m_barSets.at(i)->count(); |
|
491 | 492 | for (int j = 0; j < categoryCount; j++) { |
|
492 | 493 | qreal temp = m_barSets.at(i)->at(j); |
|
493 | 494 | if (temp > max) |
|
494 | 495 | max = temp; |
|
495 | 496 | } |
|
496 | 497 | } |
|
497 | 498 | |
|
498 | 499 | return max; |
|
499 | 500 | } |
|
500 | 501 | |
|
501 | 502 | qreal QAbstractBarSeriesPrivate::valueAt(int set, int category) |
|
502 | 503 | { |
|
503 | 504 | if ((set < 0) || (set >= m_barSets.count())) { |
|
504 | 505 | // No set, no value. |
|
505 | 506 | return 0; |
|
506 | 507 | } else if ((category < 0) || (category >= m_barSets.at(set)->count())) { |
|
507 | 508 | // No category, no value. |
|
508 | 509 | return 0; |
|
509 | 510 | } |
|
510 | 511 | |
|
511 | 512 | return m_barSets.at(set)->at(category); |
|
512 | 513 | } |
|
513 | 514 | |
|
514 | 515 | qreal QAbstractBarSeriesPrivate::percentageAt(int set, int category) |
|
515 | 516 | { |
|
516 | 517 | if ((set < 0) || (set >= m_barSets.count())) { |
|
517 | 518 | // No set, no value. |
|
518 | 519 | return 0; |
|
519 | 520 | } else if ((category < 0) || (category >= m_barSets.at(set)->count())) { |
|
520 | 521 | // No category, no value. |
|
521 | 522 | return 0; |
|
522 | 523 | } |
|
523 | 524 | |
|
524 | 525 | qreal value = m_barSets.at(set)->at(category); |
|
525 | 526 | qreal sum = categorySum(category); |
|
526 | 527 | if ( qFuzzyIsNull(sum) ) { |
|
527 | 528 | return 0; |
|
528 | 529 | } |
|
529 | 530 | |
|
530 | 531 | return value / sum; |
|
531 | 532 | } |
|
532 | 533 | |
|
533 | 534 | qreal QAbstractBarSeriesPrivate::categorySum(int category) |
|
534 | 535 | { |
|
535 | 536 | qreal sum(0); |
|
536 | 537 | int count = m_barSets.count(); // Count sets |
|
537 | 538 | for (int set = 0; set < count; set++) { |
|
538 | 539 | if (category < m_barSets.at(set)->count()) |
|
539 | 540 | sum += m_barSets.at(set)->at(category); |
|
540 | 541 | } |
|
541 | 542 | return sum; |
|
542 | 543 | } |
|
543 | 544 | |
|
544 | 545 | qreal QAbstractBarSeriesPrivate::absoluteCategorySum(int category) |
|
545 | 546 | { |
|
546 | 547 | qreal sum(0); |
|
547 | 548 | int count = m_barSets.count(); // Count sets |
|
548 | 549 | for (int set = 0; set < count; set++) { |
|
549 | 550 | if (category < m_barSets.at(set)->count()) |
|
550 | 551 | sum += qAbs(m_barSets.at(set)->at(category)); |
|
551 | 552 | } |
|
552 | 553 | return sum; |
|
553 | 554 | } |
|
554 | 555 | |
|
555 | 556 | qreal QAbstractBarSeriesPrivate::maxCategorySum() |
|
556 | 557 | { |
|
557 | 558 | qreal max = INT_MIN; |
|
558 | 559 | int count = categoryCount(); |
|
559 | 560 | for (int i = 0; i < count; i++) { |
|
560 | 561 | qreal sum = categorySum(i); |
|
561 | 562 | if (sum > max) |
|
562 | 563 | max = sum; |
|
563 | 564 | } |
|
564 | 565 | return max; |
|
565 | 566 | } |
|
566 | 567 | |
|
567 | 568 | qreal QAbstractBarSeriesPrivate::minX() |
|
568 | 569 | { |
|
569 | 570 | if (m_barSets.count() <= 0) { |
|
570 | 571 | return 0; |
|
571 | 572 | } |
|
572 | 573 | qreal min = INT_MAX; |
|
573 | 574 | |
|
574 | 575 | for (int i = 0; i < m_barSets.count(); i++) { |
|
575 | 576 | int categoryCount = m_barSets.at(i)->count(); |
|
576 | 577 | for (int j = 0; j < categoryCount; j++) { |
|
577 | 578 | qreal temp = m_barSets.at(i)->d_ptr.data()->m_values.at(j).x(); |
|
578 | 579 | if (temp < min) |
|
579 | 580 | min = temp; |
|
580 | 581 | } |
|
581 | 582 | } |
|
582 | 583 | return min; |
|
583 | 584 | } |
|
584 | 585 | |
|
585 | 586 | qreal QAbstractBarSeriesPrivate::maxX() |
|
586 | 587 | { |
|
587 | 588 | if (m_barSets.count() <= 0) { |
|
588 | 589 | return 0; |
|
589 | 590 | } |
|
590 | 591 | qreal max = INT_MIN; |
|
591 | 592 | |
|
592 | 593 | for (int i = 0; i < m_barSets.count(); i++) { |
|
593 | 594 | int categoryCount = m_barSets.at(i)->count(); |
|
594 | 595 | for (int j = 0; j < categoryCount; j++) { |
|
595 | 596 | qreal temp = m_barSets.at(i)->d_ptr.data()->m_values.at(j).x(); |
|
596 | 597 | if (temp > max) |
|
597 | 598 | max = temp; |
|
598 | 599 | } |
|
599 | 600 | } |
|
600 | 601 | |
|
601 | 602 | return max; |
|
602 | 603 | } |
|
603 | 604 | |
|
604 | 605 | |
|
605 | 606 | void QAbstractBarSeriesPrivate::scaleDomain(Domain& domain) |
|
606 | 607 | { |
|
607 | 608 | qreal minX(domain.minX()); |
|
608 | 609 | qreal minY(domain.minY()); |
|
609 | 610 | qreal maxX(domain.maxX()); |
|
610 | 611 | qreal maxY(domain.maxY()); |
|
611 | 612 | |
|
612 | 613 | qreal seriesMinX = this->minX(); |
|
613 | 614 | qreal seriesMaxX = this->maxX(); |
|
614 | 615 | qreal y = max(); |
|
615 | 616 | minX = qMin(minX, seriesMinX - (qreal)0.5); |
|
616 | 617 | minY = qMin(minY, y); |
|
617 | 618 | maxX = qMax(maxX, seriesMaxX + (qreal)0.5); |
|
618 | 619 | maxY = qMax(maxY, y); |
|
619 | 620 | |
|
620 | 621 | domain.setRange(minX,maxX,minY,maxY); |
|
621 | 622 | } |
|
622 | 623 | |
|
623 | 624 | ChartElement* QAbstractBarSeriesPrivate::createGraphics(ChartPresenter* presenter) |
|
624 | 625 | { |
|
625 | 626 | Q_UNUSED(presenter); |
|
626 | 627 | qWarning() << "QAbstractBarSeriesPrivate::createGraphics called"; |
|
627 | 628 | return 0; |
|
628 | 629 | } |
|
629 | 630 | |
|
630 | 631 | QList<LegendMarker*> QAbstractBarSeriesPrivate::createLegendMarker(QLegend* legend) |
|
631 | 632 | { |
|
632 | 633 | Q_Q(QAbstractBarSeries); |
|
633 | 634 | QList<LegendMarker*> markers; |
|
634 | 635 | foreach(QBarSet* set, q->barSets()) { |
|
635 | 636 | BarLegendMarker* marker = new BarLegendMarker(q,set,legend); |
|
636 | 637 | markers << marker; |
|
637 | 638 | } |
|
638 | 639 | |
|
639 | 640 | return markers; |
|
640 | 641 | } |
|
641 | 642 | |
|
642 | 643 | bool QAbstractBarSeriesPrivate::append(QBarSet *set) |
|
643 | 644 | { |
|
644 | 645 | Q_Q(QAbstractBarSeries); |
|
645 | 646 | if ((m_barSets.contains(set)) || (set == 0)) { |
|
646 | 647 | // Fail if set is already in list or set is null. |
|
647 | 648 | return false; |
|
648 | 649 | } |
|
649 | 650 | m_barSets.append(set); |
|
650 | 651 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); |
|
651 | 652 | QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); |
|
652 | 653 | emit restructuredBars(); // this notifies barchartitem |
|
653 | 654 | if (m_dataset) { |
|
654 | 655 | m_dataset->updateSeries(q); // this notifies legend |
|
655 | 656 | } |
|
656 | 657 | return true; |
|
657 | 658 | } |
|
658 | 659 | |
|
659 | 660 | bool QAbstractBarSeriesPrivate::remove(QBarSet *set) |
|
660 | 661 | { |
|
661 | 662 | Q_Q(QAbstractBarSeries); |
|
662 | 663 | if (!m_barSets.contains(set)) { |
|
663 | 664 | // Fail if set is not in list |
|
664 | 665 | return false; |
|
665 | 666 | } |
|
666 | 667 | m_barSets.removeOne(set); |
|
667 | 668 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); |
|
668 | 669 | QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); |
|
669 | 670 | emit restructuredBars(); // this notifies barchartitem |
|
670 | 671 | if (m_dataset) { |
|
671 | 672 | m_dataset->updateSeries(q); // this notifies legend |
|
672 | 673 | } |
|
673 | 674 | return true; |
|
674 | 675 | } |
|
675 | 676 | |
|
676 | 677 | bool QAbstractBarSeriesPrivate::append(QList<QBarSet* > sets) |
|
677 | 678 | { |
|
678 | 679 | Q_Q(QAbstractBarSeries); |
|
679 | 680 | foreach (QBarSet* set, sets) { |
|
680 | 681 | if ((set == 0) || (m_barSets.contains(set))) { |
|
681 | 682 | // Fail if any of the sets is null or is already appended. |
|
682 | 683 | return false; |
|
683 | 684 | } |
|
684 | 685 | if (sets.count(set) != 1) { |
|
685 | 686 | // Also fail if same set is more than once in given list. |
|
686 | 687 | return false; |
|
687 | 688 | } |
|
688 | 689 | } |
|
689 | 690 | |
|
690 | 691 | foreach (QBarSet* set, sets) { |
|
691 | 692 | m_barSets.append(set); |
|
692 | 693 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); |
|
693 | 694 | QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); |
|
694 | 695 | } |
|
695 | 696 | emit restructuredBars(); // this notifies barchartitem |
|
696 | 697 | if (m_dataset) { |
|
697 | 698 | m_dataset->updateSeries(q); // this notifies legend |
|
698 | 699 | } |
|
699 | 700 | return true; |
|
700 | 701 | } |
|
701 | 702 | |
|
702 | 703 | bool QAbstractBarSeriesPrivate::remove(QList<QBarSet* > sets) |
|
703 | 704 | { |
|
704 | 705 | Q_Q(QAbstractBarSeries); |
|
705 | 706 | if (sets.count() == 0) { |
|
706 | 707 | return false; |
|
707 | 708 | } |
|
708 | 709 | foreach (QBarSet* set, sets) { |
|
709 | 710 | if ((set == 0) || (!m_barSets.contains(set))) { |
|
710 | 711 | // Fail if any of the sets is null or is not in series |
|
711 | 712 | return false; |
|
712 | 713 | } |
|
713 | 714 | if (sets.count(set) != 1) { |
|
714 | 715 | // Also fail if same set is more than once in given list. |
|
715 | 716 | return false; |
|
716 | 717 | } |
|
717 | 718 | } |
|
718 | 719 | |
|
719 | 720 | foreach (QBarSet* set, sets) { |
|
720 | 721 | m_barSets.removeOne(set); |
|
721 | 722 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); |
|
722 | 723 | QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); |
|
723 | 724 | } |
|
724 | 725 | |
|
725 | 726 | emit restructuredBars(); // this notifies barchartitem |
|
726 | 727 | if (m_dataset) { |
|
727 | 728 | m_dataset->updateSeries(q); // this notifies legend |
|
728 | 729 | } |
|
729 | 730 | return true; |
|
730 | 731 | } |
|
731 | 732 | |
|
732 | 733 | bool QAbstractBarSeriesPrivate::insert(int index, QBarSet *set) |
|
733 | 734 | { |
|
734 | 735 | Q_Q(QAbstractBarSeries); |
|
735 | 736 | if ((m_barSets.contains(set)) || (set == 0)) { |
|
736 | 737 | // Fail if set is already in list or set is null. |
|
737 | 738 | return false; |
|
738 | 739 | } |
|
739 | 740 | m_barSets.insert(index, set); |
|
740 | 741 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); |
|
741 | 742 | QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); |
|
742 | 743 | emit restructuredBars(); // this notifies barchartitem |
|
743 | 744 | if (m_dataset) { |
|
744 | 745 | m_dataset->updateSeries(q); // this notifies legend |
|
745 | 746 | } |
|
746 | 747 | return true; |
|
747 | 748 | } |
|
748 | 749 | |
|
749 | 750 | void QAbstractBarSeriesPrivate::initializeAxis(QAbstractAxis* axis) |
|
750 | 751 | { |
|
751 | 752 | Q_Q(QAbstractBarSeries); |
|
752 | 753 | |
|
753 | 754 | if(axis->type()==QAbstractAxis::AxisTypeBarCategory) { |
|
754 | 755 | |
|
755 | 756 | switch(q->type()) { |
|
756 | 757 | |
|
757 | 758 | case QAbstractSeries::SeriesTypeHorizontalBar: |
|
758 | 759 | case QAbstractSeries::SeriesTypeHorizontalPercentBar: |
|
759 | 760 | case QAbstractSeries::SeriesTypeHorizontalStackedBar: { |
|
760 | 761 | |
|
761 | 762 | if(axis->orientation()==Qt::Vertical) |
|
762 | 763 | { |
|
763 | 764 | populateCategories(qobject_cast<QBarCategoryAxis*>(axis)); |
|
764 | 765 | } |
|
765 | 766 | break; |
|
766 | 767 | } |
|
767 | 768 | case QAbstractSeries::SeriesTypeBar: |
|
768 | 769 | case QAbstractSeries::SeriesTypePercentBar: |
|
769 | 770 | case QAbstractSeries::SeriesTypeStackedBar: { |
|
770 | 771 | |
|
771 | 772 | if(axis->orientation()==Qt::Horizontal) |
|
772 | 773 | { |
|
773 | 774 | populateCategories(qobject_cast<QBarCategoryAxis*>(axis)); |
|
774 | 775 | } |
|
775 | 776 | break; |
|
776 | 777 | } |
|
777 | 778 | default: |
|
778 | 779 | qWarning()<<"Unexpected series type"; |
|
779 | 780 | break; |
|
780 | 781 | |
|
781 | 782 | } |
|
782 | 783 | } |
|
783 | 784 | } |
|
784 | 785 | |
|
785 | 786 | QAbstractAxis::AxisType QAbstractBarSeriesPrivate::defaultAxisType(Qt::Orientation orientation) const |
|
786 | 787 | { |
|
787 | 788 | Q_Q(const QAbstractBarSeries); |
|
788 | 789 | |
|
789 | 790 | switch(q->type()) { |
|
790 | 791 | |
|
791 | 792 | case QAbstractSeries::SeriesTypeHorizontalBar: |
|
792 | 793 | case QAbstractSeries::SeriesTypeHorizontalPercentBar: |
|
793 | 794 | case QAbstractSeries::SeriesTypeHorizontalStackedBar: { |
|
794 | 795 | |
|
795 | 796 | if(orientation==Qt::Vertical) |
|
796 | 797 | { |
|
797 | 798 | return QAbstractAxis::AxisTypeBarCategory; |
|
798 | 799 | } |
|
799 | 800 | break; |
|
800 | 801 | } |
|
801 | 802 | case QAbstractSeries::SeriesTypeBar: |
|
802 | 803 | case QAbstractSeries::SeriesTypePercentBar: |
|
803 | 804 | case QAbstractSeries::SeriesTypeStackedBar: { |
|
804 | 805 | |
|
805 | 806 | if(orientation==Qt::Horizontal) |
|
806 | 807 | { |
|
807 | 808 | return QAbstractAxis::AxisTypeBarCategory; |
|
808 | 809 | } |
|
809 | 810 | break; |
|
810 | 811 | } |
|
811 | 812 | default: |
|
812 | 813 | qWarning()<<"Unexpected series type"; |
|
813 | 814 | break; |
|
814 | 815 | |
|
815 | 816 | } |
|
816 | 817 | return QAbstractAxis::AxisTypeValue; |
|
817 | 818 | |
|
818 | 819 | } |
|
819 | 820 | |
|
820 | 821 | void QAbstractBarSeriesPrivate::populateCategories(QBarCategoryAxis* axis) |
|
821 | 822 | { |
|
822 | 823 | QStringList categories; |
|
823 | 824 | if(axis->categories().isEmpty()) { |
|
824 | 825 | for (int i(1); i < categoryCount()+1; i++) |
|
825 | 826 | categories << QString::number(i); |
|
826 | 827 | axis->append(categories); |
|
827 | 828 | } |
|
828 | 829 | } |
|
829 | 830 | |
|
830 | 831 | #include "moc_qabstractbarseries.cpp" |
|
831 | 832 | #include "moc_qabstractbarseries_p.cpp" |
|
832 | 833 | |
|
833 | 834 | |
|
834 | 835 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,89 +1,89 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #ifndef ABSTRACTBARSERIES_H |
|
22 | 22 | #define ABSTRACTBARSERIES_H |
|
23 | 23 | |
|
24 | 24 | #include <qabstractseries.h> |
|
25 | 25 | #include <QStringList> |
|
26 | 26 | |
|
27 | 27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
28 | 28 | |
|
29 | 29 | class QBarSet; |
|
30 | 30 | class QAbstractBarSeriesPrivate; |
|
31 | 31 | |
|
32 | 32 | // Container for series |
|
33 | 33 | class QTCOMMERCIALCHART_EXPORT QAbstractBarSeries : public QAbstractSeries |
|
34 | 34 | { |
|
35 | 35 | Q_OBJECT |
|
36 | 36 | Q_PROPERTY(qreal barWidth READ barWidth WRITE setBarWidth) |
|
37 | 37 | Q_PROPERTY(int count READ count NOTIFY countChanged) |
|
38 | 38 | Q_PROPERTY(bool labelsVisible READ isLabelsVisible WRITE setLabelsVisible NOTIFY labelsVisibleChanged) |
|
39 | 39 | |
|
40 | 40 | protected: |
|
41 | 41 | //TODO DEPRECIATED |
|
42 | 42 | explicit QAbstractBarSeries(QObject *parent = 0); |
|
43 | 43 | |
|
44 | 44 | public: |
|
45 | 45 | virtual ~QAbstractBarSeries(); |
|
46 | 46 | |
|
47 | 47 | void setBarWidth(qreal width); |
|
48 | 48 | qreal barWidth() const; |
|
49 | 49 | |
|
50 | 50 | bool append(QBarSet *set); |
|
51 | 51 | bool remove(QBarSet *set); |
|
52 | 52 | bool take(QBarSet *set); |
|
53 | 53 | bool append(QList<QBarSet* > sets); |
|
54 | 54 | bool insert(int index, QBarSet *set); |
|
55 | 55 | int count() const; |
|
56 | 56 | QList<QBarSet*> barSets() const; |
|
57 | 57 | void clear(); |
|
58 | 58 | |
|
59 | 59 | void setLabelsVisible(bool visible = true); |
|
60 | 60 | bool isLabelsVisible() const; |
|
61 | 61 | |
|
62 |
void set |
|
|
62 | void setOverlap(bool overlap = true); | |
|
63 | 63 | |
|
64 | 64 | protected: |
|
65 | 65 | explicit QAbstractBarSeries(QAbstractBarSeriesPrivate &d,QObject *parent = 0); |
|
66 | 66 | |
|
67 | 67 | Q_SIGNALS: |
|
68 | 68 | void clicked(int index, QBarSet *barset); |
|
69 | 69 | void hovered(bool status, QBarSet *barset); |
|
70 | 70 | void countChanged(); |
|
71 | 71 | void labelsVisibleChanged(); |
|
72 | 72 | |
|
73 | 73 | void barsetsAdded(QList<QBarSet*> sets); |
|
74 | 74 | void barsetsRemoved(QList<QBarSet*> sets); |
|
75 | 75 | |
|
76 | 76 | protected: |
|
77 | 77 | Q_DECLARE_PRIVATE(QAbstractBarSeries) |
|
78 | 78 | friend class AbstractBarChartItem; |
|
79 | 79 | friend class PercentBarChartItem; |
|
80 | 80 | friend class StackedBarChartItem; |
|
81 | 81 | friend class BarChartItem; |
|
82 | 82 | friend class HorizontalBarChartItem; |
|
83 | 83 | friend class HorizontalStackedBarChartItem; |
|
84 | 84 | friend class HorizontalPercentBarChartItem; |
|
85 | 85 | }; |
|
86 | 86 | |
|
87 | 87 | QTCOMMERCIALCHART_END_NAMESPACE |
|
88 | 88 | |
|
89 | 89 | #endif // ABSTRACTBARSERIES_H |
@@ -1,105 +1,105 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | // W A R N I N G |
|
22 | 22 | // ------------- |
|
23 | 23 | // |
|
24 | 24 | // This file is not part of the QtCommercial Chart API. It exists purely as an |
|
25 | 25 | // implementation detail. This header file may change from version to |
|
26 | 26 | // version without notice, or even be removed. |
|
27 | 27 | // |
|
28 | 28 | // We mean it. |
|
29 | 29 | |
|
30 | 30 | #ifndef QABSTRACTBARSERIES_P_H |
|
31 | 31 | #define QABSTRACTBARSERIES_P_H |
|
32 | 32 | |
|
33 | 33 | #include "qabstractbarseries.h" |
|
34 | 34 | #include "qabstractseries_p.h" |
|
35 | 35 | #include <QStringList> |
|
36 | 36 | #include <QAbstractSeries> |
|
37 | 37 | |
|
38 | 38 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
39 | 39 | |
|
40 | 40 | class QBarModelMapper; |
|
41 | 41 | class QBarCategoryAxis; |
|
42 | 42 | |
|
43 | 43 | class QAbstractBarSeriesPrivate : public QAbstractSeriesPrivate |
|
44 | 44 | { |
|
45 | 45 | Q_OBJECT |
|
46 | 46 | public: |
|
47 | 47 | QAbstractBarSeriesPrivate(QAbstractBarSeries *parent); |
|
48 | 48 | int categoryCount() const; |
|
49 | 49 | |
|
50 | 50 | void setBarWidth(qreal width); |
|
51 | 51 | qreal barWidth() const; |
|
52 | 52 | |
|
53 | 53 | void setVisible(bool visible); |
|
54 | 54 | void setLabelsVisible(bool visible); |
|
55 |
void set |
|
|
55 | void setOverlap(bool overlap); | |
|
56 | 56 | |
|
57 | 57 | void scaleDomain(Domain& domain); |
|
58 | 58 | ChartElement* createGraphics(ChartPresenter* presenter); |
|
59 | 59 | QList<LegendMarker*> createLegendMarker(QLegend* legend); |
|
60 | 60 | |
|
61 | 61 | void initializeAxis(QAbstractAxis* axis); |
|
62 | 62 | virtual QAbstractAxis::AxisType defaultAxisType(Qt::Orientation orientation) const; |
|
63 | 63 | |
|
64 | 64 | bool append(QBarSet *set); |
|
65 | 65 | bool remove(QBarSet *set); |
|
66 | 66 | bool append(QList<QBarSet* > sets); |
|
67 | 67 | bool remove(QList<QBarSet* > sets); |
|
68 | 68 | bool insert(int index, QBarSet *set); |
|
69 | 69 | |
|
70 | 70 | QBarSet* barsetAt(int index); |
|
71 | 71 | qreal min(); |
|
72 | 72 | qreal max(); |
|
73 | 73 | qreal valueAt(int set, int category); |
|
74 | 74 | qreal percentageAt(int set, int category); |
|
75 | 75 | qreal categorySum(int category); |
|
76 | 76 | qreal absoluteCategorySum(int category); |
|
77 | 77 | qreal maxCategorySum(); |
|
78 | 78 | qreal minX(); |
|
79 | 79 | qreal maxX(); |
|
80 | 80 | |
|
81 | 81 | Q_SIGNALS: |
|
82 | 82 | void clicked(int index, QBarSet *barset); |
|
83 | 83 | void updatedBars(); |
|
84 | 84 | void restructuredBars(); |
|
85 | 85 | void labelsVisibleChanged(bool visible); |
|
86 | 86 | |
|
87 | 87 | private: |
|
88 | 88 | void populateCategories(QBarCategoryAxis* axis); |
|
89 | 89 | |
|
90 | 90 | protected: |
|
91 | 91 | QList<QBarSet *> m_barSets; |
|
92 | 92 | qreal m_barWidth; |
|
93 | 93 | bool m_labelsVisible; |
|
94 | 94 | bool m_visible; |
|
95 |
bool m_ |
|
|
95 | bool m_overlap; | |
|
96 | 96 | |
|
97 | 97 | private: |
|
98 | 98 | Q_DECLARE_PUBLIC(QAbstractBarSeries) |
|
99 | 99 | friend class HorizontalBarChartItem; |
|
100 | 100 | friend class BarChartItem; |
|
101 | 101 | }; |
|
102 | 102 | |
|
103 | 103 | QTCOMMERCIALCHART_END_NAMESPACE |
|
104 | 104 | |
|
105 | 105 | #endif // QABSTRACTBARSERIES_P_H |
@@ -1,109 +1,109 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #include "barchartitem_p.h" |
|
22 | 22 | #include "bar_p.h" |
|
23 | 23 | #include "qbarset_p.h" |
|
24 | 24 | #include "qabstractbarseries_p.h" |
|
25 | 25 | #include "qbarset.h" |
|
26 | 26 | #include "qbarset_p.h" |
|
27 | 27 | |
|
28 | 28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
29 | 29 | |
|
30 | 30 | BarChartItem::BarChartItem(QAbstractBarSeries *series, ChartPresenter *presenter) : |
|
31 | 31 | AbstractBarChartItem(series, presenter) |
|
32 | 32 | { |
|
33 | 33 | } |
|
34 | 34 | |
|
35 | 35 | QVector<QRectF> BarChartItem::calculateLayout() |
|
36 | 36 | { |
|
37 | 37 | QVector<QRectF> layout; |
|
38 | 38 | |
|
39 | 39 | // Use temporary qreals for accuracy |
|
40 | 40 | qreal categoryCount = m_series->d_func()->categoryCount(); |
|
41 | 41 | qreal setCount = m_series->count(); |
|
42 | 42 | bool barsVisible = m_series->isVisible(); |
|
43 | 43 | |
|
44 | 44 | // Domain: |
|
45 | 45 | qreal width = geometry().width(); |
|
46 | 46 | qreal height = geometry().height(); |
|
47 | 47 | qreal rangeY = m_domainMaxY - m_domainMinY; |
|
48 | 48 | qreal rangeX = m_domainMaxX - m_domainMinX; |
|
49 | 49 | qreal scaleY = (height / rangeY); |
|
50 | 50 | qreal scaleX = (width / rangeX); |
|
51 | 51 | qreal barWidth; |
|
52 | 52 | |
|
53 |
if (m_series->d_func()->m_ |
|
|
54 | barWidth = (scaleX / setCount) * m_series->d_func()->barWidth(); | |
|
55 | } else { | |
|
53 | if (m_series->d_func()->m_overlap) { | |
|
56 | 54 | barWidth = scaleX * m_series->d_func()->barWidth(); |
|
55 | } else { | |
|
56 | barWidth = (scaleX / setCount) * m_series->d_func()->barWidth(); | |
|
57 | 57 | } |
|
58 | 58 | |
|
59 | 59 | int itemIndex(0); |
|
60 | 60 | for (int category = 0; category < categoryCount; category++) { |
|
61 | 61 | qreal yPos = height + scaleY * m_domainMinY + geometry().topLeft().y(); |
|
62 | 62 | for (int set = 0; set < setCount; set++) { |
|
63 | 63 | QBarSetPrivate* barSet = m_series->d_func()->barsetAt(set)->d_ptr.data(); |
|
64 | 64 | |
|
65 | 65 | qreal xPos; |
|
66 | 66 | |
|
67 |
if (m_series->d_func()->m_ |
|
|
67 | if (m_series->d_func()->m_overlap) { | |
|
68 | xPos = (barSet->pos(category) - m_domainMinX) * scaleX + m_rect.left() - barWidth/2; | |
|
69 | } else { | |
|
68 | 70 | xPos = (barSet->pos(category) - m_domainMinX) * scaleX + m_rect.left(); |
|
69 | 71 | xPos -= setCount*barWidth/2; |
|
70 | 72 | xPos += set*barWidth; |
|
71 | } else { | |
|
72 | xPos = (barSet->pos(category) - m_domainMinX) * scaleX + m_rect.left() - barWidth/2; | |
|
73 | 73 | } |
|
74 | 74 | |
|
75 | 75 | qreal barHeight = barSet->value(category) * scaleY; |
|
76 | 76 | Bar* bar = m_bars.at(itemIndex); |
|
77 | 77 | |
|
78 | 78 | QRectF rect(xPos, yPos - barHeight, barWidth, barHeight); |
|
79 | 79 | layout.append(rect); |
|
80 | 80 | bar->setPen(barSet->m_pen); |
|
81 | 81 | bar->setBrush(barSet->m_brush); |
|
82 | 82 | if (qFuzzyIsNull(barHeight)) { |
|
83 | 83 | bar->setVisible(false); |
|
84 | 84 | } else { |
|
85 | 85 | bar->setVisible(barsVisible); |
|
86 | 86 | } |
|
87 | 87 | |
|
88 | 88 | QGraphicsSimpleTextItem* label = m_labels.at(itemIndex); |
|
89 | 89 | |
|
90 | 90 | if (!qFuzzyIsNull(barSet->value(category))) { |
|
91 | 91 | label->setText(QString::number(barSet->value(category))); |
|
92 | 92 | } else { |
|
93 | 93 | label->setText(QString("")); |
|
94 | 94 | } |
|
95 | 95 | |
|
96 | 96 | label->setPos(xPos + (rect.width()/2 - label->boundingRect().width()/2) |
|
97 | 97 | ,yPos - barHeight/2 - label->boundingRect().height()/2); |
|
98 | 98 | label->setFont(barSet->m_labelFont); |
|
99 | 99 | label->setBrush(barSet->m_labelBrush); |
|
100 | 100 | |
|
101 | 101 | itemIndex++; |
|
102 | 102 | } |
|
103 | 103 | } |
|
104 | 104 | return layout; |
|
105 | 105 | } |
|
106 | 106 | |
|
107 | 107 | #include "moc_barchartitem_p.cpp" |
|
108 | 108 | |
|
109 | 109 | QTCOMMERCIALCHART_END_NAMESPACE |
General Comments 0
You need to be logged in to leave comments.
Login now