@@ -0,0 +1,6 | |||||
|
1 | !include( ../examples.pri ) { | |||
|
2 | error( "Couldn't find the examples.pri file!" ) | |||
|
3 | } | |||
|
4 | ||||
|
5 | TARGET = horizontalbarchart | |||
|
6 | SOURCES += main.cpp |
@@ -0,0 +1,94 | |||||
|
1 | /**************************************************************************** | |||
|
2 | ** | |||
|
3 | ** Copyright (C) 2012 Digia Plc | |||
|
4 | ** All rights reserved. | |||
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |||
|
6 | ** | |||
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |||
|
8 | ** | |||
|
9 | ** $QT_BEGIN_LICENSE$ | |||
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |||
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |||
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |||
|
13 | ** a written agreement between you and Digia. | |||
|
14 | ** | |||
|
15 | ** If you have questions regarding the use of this file, please use | |||
|
16 | ** contact form at http://qt.digia.com | |||
|
17 | ** $QT_END_LICENSE$ | |||
|
18 | ** | |||
|
19 | ****************************************************************************/ | |||
|
20 | ||||
|
21 | #include <QApplication> | |||
|
22 | #include <QMainWindow> | |||
|
23 | #include <QChartView> | |||
|
24 | #include <QBarSeries> | |||
|
25 | #include <QBarSet> | |||
|
26 | #include <QLegend> | |||
|
27 | #include <QBarCategoriesAxis> | |||
|
28 | #include <QHorizontalBarSeries> | |||
|
29 | ||||
|
30 | QTCOMMERCIALCHART_USE_NAMESPACE | |||
|
31 | ||||
|
32 | int main(int argc, char *argv[]) | |||
|
33 | { | |||
|
34 | QApplication a(argc, argv); | |||
|
35 | ||||
|
36 | //![1] | |||
|
37 | QBarSet *set0 = new QBarSet("Jane"); | |||
|
38 | QBarSet *set1 = new QBarSet("John"); | |||
|
39 | QBarSet *set2 = new QBarSet("Axel"); | |||
|
40 | QBarSet *set3 = new QBarSet("Mary"); | |||
|
41 | QBarSet *set4 = new QBarSet("Samantha"); | |||
|
42 | ||||
|
43 | *set0 << 1 << 2 << 3 << 4 << 5 << 6; | |||
|
44 | *set1 << 5 << 0 << 0 << 4 << 0 << 7; | |||
|
45 | *set2 << 3 << 5 << 8 << 13 << 8 << 5; | |||
|
46 | *set3 << 5 << 6 << 7 << 3 << 4 << 5; | |||
|
47 | *set4 << 9 << 7 << 5 << 3 << 1 << 2; | |||
|
48 | //![1] | |||
|
49 | ||||
|
50 | //![2] | |||
|
51 | QHorizontalBarSeries *series = new QHorizontalBarSeries(); | |||
|
52 | series->append(set0); | |||
|
53 | series->append(set1); | |||
|
54 | series->append(set2); | |||
|
55 | series->append(set3); | |||
|
56 | series->append(set4); | |||
|
57 | ||||
|
58 | //![2] | |||
|
59 | ||||
|
60 | //![3] | |||
|
61 | QChart* chart = new QChart(); | |||
|
62 | chart->addSeries(series); | |||
|
63 | chart->setTitle("Simple horizontal barchart example"); | |||
|
64 | chart->createDefaultAxes(); | |||
|
65 | //![3] | |||
|
66 | ||||
|
67 | //![4] | |||
|
68 | QStringList categories; | |||
|
69 | categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun"; | |||
|
70 | QBarCategoriesAxis* axis = new QBarCategoriesAxis(); | |||
|
71 | axis->append(categories); | |||
|
72 | chart->createDefaultAxes(); | |||
|
73 | chart->setAxisY(axis,series); | |||
|
74 | //![4] | |||
|
75 | ||||
|
76 | //![5] | |||
|
77 | chart->legend()->setVisible(true); | |||
|
78 | chart->legend()->setAlignment(Qt::AlignBottom); | |||
|
79 | //![5] | |||
|
80 | ||||
|
81 | //![6] | |||
|
82 | QChartView* chartView = new QChartView(chart); | |||
|
83 | chartView->setRenderHint(QPainter::Antialiasing); | |||
|
84 | //![6] | |||
|
85 | ||||
|
86 | //![7] | |||
|
87 | QMainWindow window; | |||
|
88 | window.setCentralWidget(chartView); | |||
|
89 | window.resize(400, 300); | |||
|
90 | window.show(); | |||
|
91 | //![7] | |||
|
92 | ||||
|
93 | return a.exec(); | |||
|
94 | } |
@@ -0,0 +1,51 | |||||
|
1 | /**************************************************************************** | |||
|
2 | ** | |||
|
3 | ** Copyright (C) 2012 Digia Plc | |||
|
4 | ** All rights reserved. | |||
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |||
|
6 | ** | |||
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |||
|
8 | ** | |||
|
9 | ** $QT_BEGIN_LICENSE$ | |||
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |||
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |||
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |||
|
13 | ** a written agreement between you and Digia. | |||
|
14 | ** | |||
|
15 | ** If you have questions regarding the use of this file, please use | |||
|
16 | ** contact form at http://qt.digia.com | |||
|
17 | ** $QT_END_LICENSE$ | |||
|
18 | ** | |||
|
19 | ****************************************************************************/ | |||
|
20 | ||||
|
21 | #include "horizontalbaranimation_p.h" | |||
|
22 | #include "abstractbarchartitem_p.h" | |||
|
23 | #include <QTimer> | |||
|
24 | ||||
|
25 | Q_DECLARE_METATYPE(QVector<QRectF>) | |||
|
26 | ||||
|
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||
|
28 | ||||
|
29 | HorizontalBarAnimation::HorizontalBarAnimation(AbstractBarChartItem *item) : | |||
|
30 | AbstractBarAnimation(item) | |||
|
31 | { | |||
|
32 | } | |||
|
33 | ||||
|
34 | HorizontalBarAnimation::~HorizontalBarAnimation() | |||
|
35 | { | |||
|
36 | ||||
|
37 | } | |||
|
38 | ||||
|
39 | ||||
|
40 | QVariant HorizontalBarAnimation::interpolated(const QVariant &from, const QVariant &to, qreal progress) const | |||
|
41 | { | |||
|
42 | // TODO: | |||
|
43 | Q_UNUSED(from); | |||
|
44 | Q_UNUSED(to); | |||
|
45 | Q_UNUSED(progress); | |||
|
46 | return to; | |||
|
47 | } | |||
|
48 | ||||
|
49 | #include "moc_horizontalbaranimation_p.cpp" | |||
|
50 | ||||
|
51 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -0,0 +1,52 | |||||
|
1 | /**************************************************************************** | |||
|
2 | ** | |||
|
3 | ** Copyright (C) 2012 Digia Plc | |||
|
4 | ** All rights reserved. | |||
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |||
|
6 | ** | |||
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |||
|
8 | ** | |||
|
9 | ** $QT_BEGIN_LICENSE$ | |||
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |||
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |||
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |||
|
13 | ** a written agreement between you and Digia. | |||
|
14 | ** | |||
|
15 | ** If you have questions regarding the use of this file, please use | |||
|
16 | ** contact form at http://qt.digia.com | |||
|
17 | ** $QT_END_LICENSE$ | |||
|
18 | ** | |||
|
19 | ****************************************************************************/ | |||
|
20 | ||||
|
21 | // W A R N I N G | |||
|
22 | // ------------- | |||
|
23 | // | |||
|
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an | |||
|
25 | // implementation detail. This header file may change from version to | |||
|
26 | // version without notice, or even be removed. | |||
|
27 | // | |||
|
28 | // We mean it. | |||
|
29 | ||||
|
30 | #ifndef HORIZONTALBARANIMATION_P_H | |||
|
31 | #define HORIZONTALBARANIMATION_P_H | |||
|
32 | ||||
|
33 | #include "abstractbaranimation_p.h" | |||
|
34 | #include "chartanimation_p.h" | |||
|
35 | #include "abstractbarchartitem_p.h" | |||
|
36 | ||||
|
37 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||
|
38 | ||||
|
39 | class HorizontalBarAnimation : public AbstractBarAnimation | |||
|
40 | { | |||
|
41 | Q_OBJECT | |||
|
42 | public: | |||
|
43 | explicit HorizontalBarAnimation(AbstractBarChartItem *item); | |||
|
44 | ~HorizontalBarAnimation(); | |||
|
45 | ||||
|
46 | virtual QVariant interpolated(const QVariant &from, const QVariant &to, qreal progress) const; | |||
|
47 | ||||
|
48 | }; | |||
|
49 | ||||
|
50 | QTCOMMERCIALCHART_END_NAMESPACE | |||
|
51 | ||||
|
52 | #endif // HORIZONTALBARANIMATION_P_H |
@@ -23,4 +23,5 SUBDIRS += \ | |||||
23 | legend \ |
|
23 | legend \ | |
24 | barmodelmapper \ |
|
24 | barmodelmapper \ | |
25 | qmlpiechart \ |
|
25 | qmlpiechart \ | |
26 | lineandbar |
|
26 | lineandbar \ | |
|
27 | horizontalbarchart |
@@ -11,7 +11,8 SOURCES += \ | |||||
11 | $$PWD/baranimation.cpp \ |
|
11 | $$PWD/baranimation.cpp \ | |
12 | $$PWD/stackedbaranimation.cpp \ |
|
12 | $$PWD/stackedbaranimation.cpp \ | |
13 | $$PWD/percentbaranimation.cpp \ |
|
13 | $$PWD/percentbaranimation.cpp \ | |
14 | $$PWD/abstractbaranimation.cpp |
|
14 | $$PWD/abstractbaranimation.cpp \ | |
|
15 | $$PWD/horizontalbaranimation.cpp | |||
15 |
|
16 | |||
16 |
|
17 | |||
17 | PRIVATE_HEADERS += \ |
|
18 | PRIVATE_HEADERS += \ | |
@@ -25,4 +26,5 PRIVATE_HEADERS += \ | |||||
25 | $$PWD/baranimation_p.h \ |
|
26 | $$PWD/baranimation_p.h \ | |
26 | $$PWD/stackedbaranimation_p.h \ |
|
27 | $$PWD/stackedbaranimation_p.h \ | |
27 | $$PWD/percentbaranimation_p.h \ |
|
28 | $$PWD/percentbaranimation_p.h \ | |
28 | $$PWD/abstractbaranimation_p.h |
|
29 | $$PWD/abstractbaranimation_p.h \ | |
|
30 | $$PWD/horizontalbaranimation_p.h |
@@ -56,10 +56,10 QVector<QRectF> BarChartItem::calculateLayout() | |||||
56 | for (int set = 0; set < setCount; set++) { |
|
56 | for (int set = 0; set < setCount; set++) { | |
57 | QBarSetPrivate* barSet = m_series->d_func()->barsetAt(set)->d_ptr.data(); |
|
57 | QBarSetPrivate* barSet = m_series->d_func()->barsetAt(set)->d_ptr.data(); | |
58 |
|
58 | |||
59 |
qreal xPos = (barSet-> |
|
59 | qreal xPos = (barSet->pos(category) - m_domainMinX) * scaleX + m_rect.left(); | |
60 | xPos -= setCount*barWidth/2; |
|
60 | xPos -= setCount*barWidth/2; | |
61 | xPos += set*barWidth; |
|
61 | xPos += set*barWidth; | |
62 |
qreal barHeight = barSet-> |
|
62 | qreal barHeight = barSet->value(category) * scaleY; | |
63 | Bar* bar = m_bars.at(itemIndex); |
|
63 | Bar* bar = m_bars.at(itemIndex); | |
64 |
|
64 | |||
65 | QRectF rect(xPos, yPos - barHeight, barWidth, barHeight); |
|
65 | QRectF rect(xPos, yPos - barHeight, barWidth, barHeight); | |
@@ -74,8 +74,8 QVector<QRectF> BarChartItem::calculateLayout() | |||||
74 |
|
74 | |||
75 | QGraphicsSimpleTextItem* label = m_labels.at(itemIndex); |
|
75 | QGraphicsSimpleTextItem* label = m_labels.at(itemIndex); | |
76 |
|
76 | |||
77 |
if (!qFuzzyIsNull(barSet-> |
|
77 | if (!qFuzzyIsNull(barSet->value(category))) { | |
78 |
label->setText(QString::number(barSet-> |
|
78 | label->setText(QString::number(barSet->value(category))); | |
79 | } else { |
|
79 | } else { | |
80 | label->setText(QString("")); |
|
80 | label->setText(QString("")); | |
81 | } |
|
81 | } |
@@ -1,16 +1,93 | |||||
|
1 | /**************************************************************************** | |||
|
2 | ** | |||
|
3 | ** Copyright (C) 2012 Digia Plc | |||
|
4 | ** All rights reserved. | |||
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |||
|
6 | ** | |||
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |||
|
8 | ** | |||
|
9 | ** $QT_BEGIN_LICENSE$ | |||
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |||
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |||
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |||
|
13 | ** a written agreement between you and Digia. | |||
|
14 | ** | |||
|
15 | ** If you have questions regarding the use of this file, please use | |||
|
16 | ** contact form at http://qt.digia.com | |||
|
17 | ** $QT_END_LICENSE$ | |||
|
18 | ** | |||
|
19 | ****************************************************************************/ | |||
|
20 | ||||
1 | #include "horizontalbarchartitem_p.h" |
|
21 | #include "horizontalbarchartitem_p.h" | |
|
22 | #include "qabstractbarseries_p.h" | |||
|
23 | #include "qbarset_p.h" | |||
|
24 | #include "bar_p.h" | |||
|
25 | #include <QDebug> | |||
2 |
|
26 | |||
3 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
4 |
|
28 | |||
5 |
HorizontalBarChart |
|
29 | HorizontalBarChartItem::HorizontalBarChartItem(QAbstractBarSeries *series, ChartPresenter *presenter) : | |
6 | AbstractBarChartItem(series, presenter) |
|
30 | AbstractBarChartItem(series, presenter) | |
7 | { |
|
31 | { | |
8 | } |
|
32 | } | |
9 |
|
33 | |||
10 |
QVector<QRectF> HorizontalBarChart |
|
34 | QVector<QRectF> HorizontalBarChartItem::calculateLayout() | |
11 | { |
|
35 | { | |
12 | // TODO: |
|
|||
13 | QVector<QRectF> layout; |
|
36 | QVector<QRectF> layout; | |
|
37 | ||||
|
38 | // Use temporary qreals for accuracy | |||
|
39 | qreal categoryCount = m_series->d_func()->categoryCount(); | |||
|
40 | qreal setCount = m_series->count(); | |||
|
41 | bool barsVisible = m_series->isVisible(); | |||
|
42 | ||||
|
43 | // Domain: | |||
|
44 | qreal width = geometry().width(); | |||
|
45 | qreal height = geometry().height(); | |||
|
46 | qreal rangeY = m_domainMaxY - m_domainMinY; | |||
|
47 | qreal rangeX = m_domainMaxX - m_domainMinX; | |||
|
48 | qreal scaleY = (height / rangeY); | |||
|
49 | qreal scaleX = (width / rangeX); | |||
|
50 | qreal barHeight = (scaleY / setCount) * m_series->d_func()->barWidth(); // On horizontal chart barWidth of the barseries means height of the rect. | |||
|
51 | ||||
|
52 | int itemIndex(0); | |||
|
53 | for (int category = 0; category < categoryCount; category++) { | |||
|
54 | qreal xPos = scaleX * m_domainMinX + geometry().left(); | |||
|
55 | for (int set = 0; set < setCount; set++) { | |||
|
56 | QBarSetPrivate* barSet = m_series->d_func()->barsetAt(set)->d_ptr.data(); | |||
|
57 | ||||
|
58 | qreal yPos = m_rect.bottom() -(barSet->pos(category) + m_domainMinY + 1) * scaleY; | |||
|
59 | yPos += setCount*barHeight/2; | |||
|
60 | yPos -= set*barHeight; | |||
|
61 | ||||
|
62 | qreal barWidth = barSet->value(category) * scaleX; | |||
|
63 | Bar* bar = m_bars.at(itemIndex); | |||
|
64 | ||||
|
65 | QRectF rect(xPos, yPos - barHeight, barWidth, barHeight); | |||
|
66 | layout.append(rect); | |||
|
67 | bar->setPen(barSet->m_pen); | |||
|
68 | bar->setBrush(barSet->m_brush); | |||
|
69 | if (qFuzzyIsNull(barHeight)) { | |||
|
70 | bar->setVisible(false); | |||
|
71 | } else { | |||
|
72 | bar->setVisible(barsVisible); | |||
|
73 | } | |||
|
74 | ||||
|
75 | QGraphicsSimpleTextItem* label = m_labels.at(itemIndex); | |||
|
76 | ||||
|
77 | if (!qFuzzyIsNull(barSet->value(category))) { | |||
|
78 | label->setText(QString::number(barSet->value(category))); | |||
|
79 | } else { | |||
|
80 | label->setText(QString("")); | |||
|
81 | } | |||
|
82 | ||||
|
83 | label->setPos(xPos + (rect.width()/2 - label->boundingRect().width()/2) | |||
|
84 | ,yPos - barHeight/2 - label->boundingRect().height()/2); | |||
|
85 | label->setFont(barSet->m_labelFont); | |||
|
86 | label->setBrush(barSet->m_labelBrush); | |||
|
87 | ||||
|
88 | itemIndex++; | |||
|
89 | } | |||
|
90 | } | |||
14 | return layout; |
|
91 | return layout; | |
15 | } |
|
92 | } | |
16 |
|
93 |
@@ -1,3 +1,32 | |||||
|
1 | /**************************************************************************** | |||
|
2 | ** | |||
|
3 | ** Copyright (C) 2012 Digia Plc | |||
|
4 | ** All rights reserved. | |||
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |||
|
6 | ** | |||
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |||
|
8 | ** | |||
|
9 | ** $QT_BEGIN_LICENSE$ | |||
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |||
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |||
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |||
|
13 | ** a written agreement between you and Digia. | |||
|
14 | ** | |||
|
15 | ** If you have questions regarding the use of this file, please use | |||
|
16 | ** contact form at http://qt.digia.com | |||
|
17 | ** $QT_END_LICENSE$ | |||
|
18 | ** | |||
|
19 | ****************************************************************************/ | |||
|
20 | ||||
|
21 | // W A R N I N G | |||
|
22 | // ------------- | |||
|
23 | // | |||
|
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an | |||
|
25 | // implementation detail. This header file may change from version to | |||
|
26 | // version without notice, or even be removed. | |||
|
27 | // | |||
|
28 | // We mean it. | |||
|
29 | ||||
1 | #ifndef HORIZONTALBARCHARTITEM_H |
|
30 | #ifndef HORIZONTALBARCHARTITEM_H | |
2 | #define HORIZONTALBARCHARTITEM_H |
|
31 | #define HORIZONTALBARCHARTITEM_H | |
3 |
|
32 | |||
@@ -7,12 +36,11 | |||||
7 |
|
36 | |||
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
37 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
9 |
|
38 | |||
10 |
|
39 | class HorizontalBarChartItem : public AbstractBarChartItem | ||
11 | class HorizontalBarChartitem : public AbstractBarChartItem |
|
|||
12 | { |
|
40 | { | |
13 | Q_OBJECT |
|
41 | Q_OBJECT | |
14 | public: |
|
42 | public: | |
15 |
HorizontalBarChart |
|
43 | HorizontalBarChartItem(QAbstractBarSeries *series, ChartPresenter *presenter); | |
16 |
|
44 | |||
17 | private: |
|
45 | private: | |
18 | virtual QVector<QRectF> calculateLayout(); |
|
46 | virtual QVector<QRectF> calculateLayout(); |
@@ -58,9 +58,9 QVector<QRectF> PercentBarChartItem::calculateLayout() | |||||
58 | for (int set=0; set < setCount; set++) { |
|
58 | for (int set=0; set < setCount; set++) { | |
59 | QBarSetPrivate* barSet = m_series->d_func()->barsetAt(set)->d_ptr.data(); |
|
59 | QBarSetPrivate* barSet = m_series->d_func()->barsetAt(set)->d_ptr.data(); | |
60 |
|
60 | |||
61 |
qreal xPos = (barSet-> |
|
61 | qreal xPos = (barSet->pos(category) - m_domainMinX) * scaleX + m_rect.left() - barWidth/2; | |
62 |
|
62 | |||
63 |
qreal barHeight = barSet-> |
|
63 | qreal barHeight = barSet->value(category) * percentage * scaleY; | |
64 | Bar* bar = m_bars.at(itemIndex); |
|
64 | Bar* bar = m_bars.at(itemIndex); | |
65 | bar->setPen(barSet->m_pen); |
|
65 | bar->setPen(barSet->m_pen); | |
66 | bar->setBrush(barSet->m_brush); |
|
66 | bar->setBrush(barSet->m_brush); |
@@ -722,12 +722,12 void QAbstractBarSeriesPrivate::initializeAxisY(QAbstractAxis* axis) | |||||
722 |
|
722 | |||
723 | QAbstractAxis::AxisType QAbstractBarSeriesPrivate::defaultAxisXType() const |
|
723 | QAbstractAxis::AxisType QAbstractBarSeriesPrivate::defaultAxisXType() const | |
724 | { |
|
724 | { | |
725 |
return QAbstractAxis::AxisType |
|
725 | return QAbstractAxis::AxisTypeNoAxis; | |
726 | } |
|
726 | } | |
727 |
|
727 | |||
728 | QAbstractAxis::AxisType QAbstractBarSeriesPrivate::defaultAxisYType() const |
|
728 | QAbstractAxis::AxisType QAbstractBarSeriesPrivate::defaultAxisYType() const | |
729 | { |
|
729 | { | |
730 |
return QAbstractAxis::AxisType |
|
730 | return QAbstractAxis::AxisTypeNoAxis; | |
731 | } |
|
731 | } | |
732 |
|
732 | |||
733 | #include "moc_qabstractbarseries.cpp" |
|
733 | #include "moc_qabstractbarseries.cpp" |
@@ -75,6 +75,7 protected: | |||||
75 | friend class PercentBarChartItem; |
|
75 | friend class PercentBarChartItem; | |
76 | friend class StackedBarChartItem; |
|
76 | friend class StackedBarChartItem; | |
77 | friend class BarChartItem; |
|
77 | friend class BarChartItem; | |
|
78 | friend class HorizontalBarChartItem; | |||
78 | }; |
|
79 | }; | |
79 |
|
80 | |||
80 | QTCOMMERCIALCHART_END_NAMESPACE |
|
81 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -113,6 +113,16 Chart* QBarSeriesPrivate::createGraphics(ChartPresenter* presenter) | |||||
113 | return bar; |
|
113 | return bar; | |
114 | } |
|
114 | } | |
115 |
|
115 | |||
|
116 | QAbstractAxis::AxisType QBarSeriesPrivate::defaultAxisXType() const | |||
|
117 | { | |||
|
118 | return QAbstractAxis::AxisTypeCategories; | |||
|
119 | } | |||
|
120 | ||||
|
121 | QAbstractAxis::AxisType QBarSeriesPrivate::defaultAxisYType() const | |||
|
122 | { | |||
|
123 | return QAbstractAxis::AxisTypeValues; | |||
|
124 | } | |||
|
125 | ||||
116 | #include "moc_qbarseries.cpp" |
|
126 | #include "moc_qbarseries.cpp" | |
117 |
|
127 | |||
118 | QTCOMMERCIALCHART_END_NAMESPACE |
|
128 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -21,7 +21,6 | |||||
21 | #ifndef QBARSERIES_H |
|
21 | #ifndef QBARSERIES_H | |
22 | #define QBARSERIES_H |
|
22 | #define QBARSERIES_H | |
23 |
|
23 | |||
24 | #include <QStringList> |
|
|||
25 | #include <qabstractbarseries.h> |
|
24 | #include <qabstractbarseries.h> | |
26 |
|
25 | |||
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
@@ -43,6 +43,9 public: | |||||
43 | Chart* createGraphics(ChartPresenter* presenter); |
|
43 | Chart* createGraphics(ChartPresenter* presenter); | |
44 | void scaleDomain(Domain& domain); |
|
44 | void scaleDomain(Domain& domain); | |
45 |
|
45 | |||
|
46 | QAbstractAxis::AxisType defaultAxisXType() const; | |||
|
47 | QAbstractAxis::AxisType defaultAxisYType() const; | |||
|
48 | ||||
46 | private: |
|
49 | private: | |
47 | Q_DECLARE_PUBLIC(QBarSeries) |
|
50 | Q_DECLARE_PUBLIC(QBarSeries) | |
48 | }; |
|
51 | }; |
@@ -611,15 +611,23 void QBarSetPrivate::replace(const int index, const QPointF value) | |||||
611 | emit updatedBars(); |
|
611 | emit updatedBars(); | |
612 | } |
|
612 | } | |
613 |
|
613 | |||
614 |
|
|
614 | qreal QBarSetPrivate::pos(const int index) | |
615 | { |
|
615 | { | |
616 |
|
|
616 | if (index < 0 || index >= m_values.count()) { | |
617 |
|
|
617 | return 0; | |
618 |
|
|
618 | } | |
619 |
|
619 | |||
620 |
|
|
620 | return m_values.at(index).x(); | |
621 | } |
|
621 | } | |
622 |
|
622 | |||
|
623 | qreal QBarSetPrivate::value(const int index) | |||
|
624 | { | |||
|
625 | if (index < 0 || index >= m_values.count()) { | |||
|
626 | return 0; | |||
|
627 | } | |||
|
628 | ||||
|
629 | return m_values.at(index).y(); | |||
|
630 | } | |||
623 |
|
631 | |||
624 | #include "moc_qbarset.cpp" |
|
632 | #include "moc_qbarset.cpp" | |
625 | #include "moc_qbarset_p.cpp" |
|
633 | #include "moc_qbarset_p.cpp" |
@@ -108,6 +108,7 private: | |||||
108 | friend class StackedBarChartItem; |
|
108 | friend class StackedBarChartItem; | |
109 | friend class PercentBarChartItem; |
|
109 | friend class PercentBarChartItem; | |
110 | friend class BarChartItem; |
|
110 | friend class BarChartItem; | |
|
111 | friend class HorizontalBarChartItem; | |||
111 | }; |
|
112 | }; | |
112 |
|
113 | |||
113 | QTCOMMERCIALCHART_END_NAMESPACE |
|
114 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -57,7 +57,8 public: | |||||
57 | void replace(const int index, const qreal value); |
|
57 | void replace(const int index, const qreal value); | |
58 | void replace(const int index, const QPointF value); |
|
58 | void replace(const int index, const QPointF value); | |
59 |
|
59 | |||
60 |
|
|
60 | qreal pos(const int index); | |
|
61 | qreal value(const int index); | |||
61 |
|
62 | |||
62 | Q_SIGNALS: |
|
63 | Q_SIGNALS: | |
63 | void restructuredBars(); |
|
64 | void restructuredBars(); |
@@ -1,9 +1,16 | |||||
1 | #include "qhorizontalbarseries.h" |
|
1 | #include "qhorizontalbarseries.h" | |
2 | #include "qhorizontalbarseries_p.h" |
|
2 | #include "qhorizontalbarseries_p.h" | |
|
3 | #include "horizontalbarchartitem_p.h" | |||
|
4 | #include "horizontalbaranimation_p.h" | |||
|
5 | ||||
|
6 | #include "chartdataset_p.h" | |||
|
7 | #include "charttheme_p.h" | |||
|
8 | ||||
|
9 | ||||
3 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
10 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
4 |
|
11 | |||
5 | QHorizontalBarSeries::QHorizontalBarSeries(QObject *parent) : |
|
12 | QHorizontalBarSeries::QHorizontalBarSeries(QObject *parent) : | |
6 | QAbstractBarSeries(parent) |
|
13 | QAbstractBarSeries(*new QHorizontalBarSeriesPrivate(this), parent) | |
7 | { |
|
14 | { | |
8 | } |
|
15 | } | |
9 |
|
16 | |||
@@ -24,8 +31,6 QHorizontalBarSeriesPrivate::QHorizontalBarSeriesPrivate(QHorizontalBarSeries *q | |||||
24 | void QHorizontalBarSeriesPrivate::scaleDomain(Domain& domain) |
|
31 | void QHorizontalBarSeriesPrivate::scaleDomain(Domain& domain) | |
25 | { |
|
32 | { | |
26 | // TODO: |
|
33 | // TODO: | |
27 | Q_UNUSED(domain); |
|
|||
28 | /* |
|
|||
29 | qreal minX(domain.minX()); |
|
34 | qreal minX(domain.minX()); | |
30 | qreal minY(domain.minY()); |
|
35 | qreal minY(domain.minY()); | |
31 | qreal maxX(domain.maxX()); |
|
36 | qreal maxX(domain.maxX()); | |
@@ -33,34 +38,39 void QHorizontalBarSeriesPrivate::scaleDomain(Domain& domain) | |||||
33 | int tickXCount(domain.tickXCount()); |
|
38 | int tickXCount(domain.tickXCount()); | |
34 | int tickYCount(domain.tickYCount()); |
|
39 | int tickYCount(domain.tickYCount()); | |
35 |
|
40 | |||
36 |
qreal |
|
41 | qreal y = categoryCount(); | |
37 |
qreal |
|
42 | qreal x = max(); | |
38 |
minX = qMin(minX, |
|
43 | minX = qMin(minX, x); | |
39 |
minY = qMin(minY, |
|
44 | minY = qMin(minY, -0.5); | |
40 |
maxX = qMax(maxX, x |
|
45 | maxX = qMax(maxX, x); | |
41 | maxY = qMax(maxY, y); |
|
46 | maxY = qMax(maxY, y -0.5); | |
42 |
tick |
|
47 | tickYCount = y+1; | |
43 |
|
48 | |||
44 | domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount); |
|
49 | domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount); | |
45 | */ |
|
|||
46 | } |
|
50 | } | |
47 |
|
51 | |||
48 |
|
52 | |||
49 | Chart* QHorizontalBarSeriesPrivate::createGraphics(ChartPresenter* presenter) |
|
53 | Chart* QHorizontalBarSeriesPrivate::createGraphics(ChartPresenter* presenter) | |
50 | { |
|
54 | { | |
51 | // TODO: |
|
|||
52 | Q_UNUSED(presenter); |
|
|||
53 | return 0; |
|
|||
54 | /* |
|
|||
55 | Q_Q(QHorizontalBarSeries); |
|
55 | Q_Q(QHorizontalBarSeries); | |
56 |
|
56 | |||
57 |
|
|
57 | HorizontalBarChartItem* bar = new HorizontalBarChartItem(q,presenter); | |
58 | if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { |
|
58 | if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { | |
59 |
presenter->animator() |
|
59 | bar->setAnimator(presenter->animator()); | |
|
60 | bar->setAnimation(new HorizontalBarAnimation(bar)); | |||
60 | } |
|
61 | } | |
61 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); |
|
62 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); | |
62 | return bar; |
|
63 | return bar; | |
63 | */ |
|
64 | } | |
|
65 | ||||
|
66 | QAbstractAxis::AxisType QHorizontalBarSeriesPrivate::defaultAxisXType() const | |||
|
67 | { | |||
|
68 | return QAbstractAxis::AxisTypeValues; | |||
|
69 | } | |||
|
70 | ||||
|
71 | QAbstractAxis::AxisType QHorizontalBarSeriesPrivate::defaultAxisYType() const | |||
|
72 | { | |||
|
73 | return QAbstractAxis::AxisTypeValues; | |||
64 | } |
|
74 | } | |
65 |
|
75 | |||
66 |
|
76 |
@@ -1,3 +1,23 | |||||
|
1 | /**************************************************************************** | |||
|
2 | ** | |||
|
3 | ** Copyright (C) 2012 Digia Plc | |||
|
4 | ** All rights reserved. | |||
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |||
|
6 | ** | |||
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |||
|
8 | ** | |||
|
9 | ** $QT_BEGIN_LICENSE$ | |||
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |||
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |||
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |||
|
13 | ** a written agreement between you and Digia. | |||
|
14 | ** | |||
|
15 | ** If you have questions regarding the use of this file, please use | |||
|
16 | ** contact form at http://qt.digia.com | |||
|
17 | ** $QT_END_LICENSE$ | |||
|
18 | ** | |||
|
19 | ****************************************************************************/ | |||
|
20 | ||||
1 | #ifndef QHORIZONTALBARSERIES_H |
|
21 | #ifndef QHORIZONTALBARSERIES_H | |
2 | #define QHORIZONTALBARSERIES_H |
|
22 | #define QHORIZONTALBARSERIES_H | |
3 |
|
23 |
@@ -41,6 +41,8 public: | |||||
41 | QHorizontalBarSeriesPrivate(QHorizontalBarSeries* q); |
|
41 | QHorizontalBarSeriesPrivate(QHorizontalBarSeries* q); | |
42 | Chart* createGraphics(ChartPresenter* presenter); |
|
42 | Chart* createGraphics(ChartPresenter* presenter); | |
43 | void scaleDomain(Domain& domain); |
|
43 | void scaleDomain(Domain& domain); | |
|
44 | QAbstractAxis::AxisType defaultAxisXType() const; | |||
|
45 | QAbstractAxis::AxisType defaultAxisYType() const; | |||
44 |
|
46 | |||
45 | private: |
|
47 | private: | |
46 | Q_DECLARE_PUBLIC(QHorizontalBarSeries) |
|
48 | Q_DECLARE_PUBLIC(QHorizontalBarSeries) |
@@ -112,6 +112,16 Chart* QPercentBarSeriesPrivate::createGraphics(ChartPresenter* presenter) | |||||
112 | return bar; |
|
112 | return bar; | |
113 | } |
|
113 | } | |
114 |
|
114 | |||
|
115 | QAbstractAxis::AxisType QPercentBarSeriesPrivate::defaultAxisXType() const | |||
|
116 | { | |||
|
117 | return QAbstractAxis::AxisTypeCategories; | |||
|
118 | } | |||
|
119 | ||||
|
120 | QAbstractAxis::AxisType QPercentBarSeriesPrivate::defaultAxisYType() const | |||
|
121 | { | |||
|
122 | return QAbstractAxis::AxisTypeValues; | |||
|
123 | } | |||
|
124 | ||||
115 | #include "moc_qpercentbarseries.cpp" |
|
125 | #include "moc_qpercentbarseries.cpp" | |
116 |
|
126 | |||
117 | QTCOMMERCIALCHART_END_NAMESPACE |
|
127 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -42,6 +42,9 public: | |||||
42 | QPercentBarSeriesPrivate(QPercentBarSeries* q); |
|
42 | QPercentBarSeriesPrivate(QPercentBarSeries* q); | |
43 | void scaleDomain(Domain& domain); |
|
43 | void scaleDomain(Domain& domain); | |
44 | Chart* createGraphics(ChartPresenter* presenter); |
|
44 | Chart* createGraphics(ChartPresenter* presenter); | |
|
45 | QAbstractAxis::AxisType defaultAxisXType() const; | |||
|
46 | QAbstractAxis::AxisType defaultAxisYType() const; | |||
|
47 | ||||
45 | private: |
|
48 | private: | |
46 | Q_DECLARE_PUBLIC(QPercentBarSeries) |
|
49 | Q_DECLARE_PUBLIC(QPercentBarSeries) | |
47 | }; |
|
50 | }; |
@@ -114,6 +114,16 Chart* QStackedBarSeriesPrivate::createGraphics(ChartPresenter* presenter) | |||||
114 | return bar; |
|
114 | return bar; | |
115 | } |
|
115 | } | |
116 |
|
116 | |||
|
117 | QAbstractAxis::AxisType QStackedBarSeriesPrivate::defaultAxisXType() const | |||
|
118 | { | |||
|
119 | return QAbstractAxis::AxisTypeCategories; | |||
|
120 | } | |||
|
121 | ||||
|
122 | QAbstractAxis::AxisType QStackedBarSeriesPrivate::defaultAxisYType() const | |||
|
123 | { | |||
|
124 | return QAbstractAxis::AxisTypeValues; | |||
|
125 | } | |||
|
126 | ||||
117 |
|
127 | |||
118 | #include "moc_qstackedbarseries.cpp" |
|
128 | #include "moc_qstackedbarseries.cpp" | |
119 |
|
129 |
@@ -42,6 +42,8 public: | |||||
42 | QStackedBarSeriesPrivate(QStackedBarSeries* q); |
|
42 | QStackedBarSeriesPrivate(QStackedBarSeries* q); | |
43 | Chart* createGraphics(ChartPresenter* presenter); |
|
43 | Chart* createGraphics(ChartPresenter* presenter); | |
44 | void scaleDomain(Domain& domain); |
|
44 | void scaleDomain(Domain& domain); | |
|
45 | QAbstractAxis::AxisType defaultAxisXType() const; | |||
|
46 | QAbstractAxis::AxisType defaultAxisYType() const; | |||
45 |
|
47 | |||
46 | private: |
|
48 | private: | |
47 | Q_DECLARE_PUBLIC(QStackedBarSeries) |
|
49 | Q_DECLARE_PUBLIC(QStackedBarSeries) |
@@ -55,9 +55,9 QVector<QRectF> StackedBarChartItem::calculateLayout() | |||||
55 | for (int set=0; set < setCount; set++) { |
|
55 | for (int set=0; set < setCount; set++) { | |
56 | QBarSetPrivate* barSet = m_series->d_func()->barsetAt(set)->d_ptr.data(); |
|
56 | QBarSetPrivate* barSet = m_series->d_func()->barsetAt(set)->d_ptr.data(); | |
57 |
|
57 | |||
58 |
qreal xPos = (barSet-> |
|
58 | qreal xPos = (barSet->pos(category) - m_domainMinX) * scaleX + m_rect.left() - barWidth/2; | |
59 |
|
59 | |||
60 |
qreal barHeight = barSet-> |
|
60 | qreal barHeight = barSet->value(category) * scaleY; | |
61 | Bar* bar = m_bars.at(itemIndex); |
|
61 | Bar* bar = m_bars.at(itemIndex); | |
62 | bar->setPen(barSet->m_pen); |
|
62 | bar->setPen(barSet->m_pen); | |
63 | bar->setBrush(barSet->m_brush); |
|
63 | bar->setBrush(barSet->m_brush); | |
@@ -72,8 +72,8 QVector<QRectF> StackedBarChartItem::calculateLayout() | |||||
72 |
|
72 | |||
73 | QGraphicsSimpleTextItem* label = m_labels.at(itemIndex); |
|
73 | QGraphicsSimpleTextItem* label = m_labels.at(itemIndex); | |
74 |
|
74 | |||
75 |
if (!qFuzzyIsNull(barSet-> |
|
75 | if (!qFuzzyIsNull(barSet->value(category))) { | |
76 |
label->setText(QString::number(barSet-> |
|
76 | label->setText(QString::number(barSet->value(category))); | |
77 | } else { |
|
77 | } else { | |
78 | label->setText(QString("")); |
|
78 | label->setText(QString("")); | |
79 | } |
|
79 | } |
General Comments 0
You need to be logged in to leave comments.
Login now