@@ -0,0 +1,96 | |||||
|
1 | #ifndef QBARSERIESPRIVATE_P_H | |||
|
2 | #define QBARSERIESPRIVATE_P_H | |||
|
3 | ||||
|
4 | #include "qbarseries.h" | |||
|
5 | #include <QStringList> | |||
|
6 | #include <QSeries> | |||
|
7 | ||||
|
8 | class QModelIndex; | |||
|
9 | ||||
|
10 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||
|
11 | ||||
|
12 | typedef QStringList QBarCategories; | |||
|
13 | ||||
|
14 | class QBarSeries; | |||
|
15 | class QBarSet; | |||
|
16 | class BarChartModel; | |||
|
17 | class BarCategory; | |||
|
18 | ||||
|
19 | // Container for series | |||
|
20 | class QBarSeriesPrivate : public QObject | |||
|
21 | { | |||
|
22 | Q_OBJECT | |||
|
23 | Q_DECLARE_PUBLIC(QBarSeries) | |||
|
24 | public: | |||
|
25 | QBarSeriesPrivate(QStringList categories, QBarSeries *parent); | |||
|
26 | ||||
|
27 | virtual QSeries::QSeriesType type() const { return QSeries::SeriesTypeBar; } | |||
|
28 | ||||
|
29 | void appendBarSet(QBarSet *set); // Takes ownership of set | |||
|
30 | void removeBarSet(QBarSet *set); // Releases ownership, doesn't delete set | |||
|
31 | void appendBarSets(QList<QBarSet* > sets); | |||
|
32 | void removeBarSets(QList<QBarSet* > sets); | |||
|
33 | void insertBarSet(int i, QBarSet *set); | |||
|
34 | void insertCategory(int i, QString category); | |||
|
35 | void removeCategory(int i); | |||
|
36 | int barsetCount() const; | |||
|
37 | int categoryCount() const; | |||
|
38 | QList<QBarSet*> barSets() const; | |||
|
39 | QBarCategories categories() const; | |||
|
40 | ||||
|
41 | void setLabelsVisible(bool visible = true); | |||
|
42 | ||||
|
43 | bool setModel(QAbstractItemModel *model); | |||
|
44 | void setModelMapping(int categories, int bottomBoundry, int topBoundry, Qt::Orientation orientation = Qt::Vertical); | |||
|
45 | ||||
|
46 | QBarSet* barsetAt(int index); | |||
|
47 | QString categoryName(int category); | |||
|
48 | qreal min(); | |||
|
49 | qreal max(); | |||
|
50 | qreal valueAt(int set, int category); | |||
|
51 | qreal percentageAt(int set, int category); | |||
|
52 | qreal categorySum(int category); | |||
|
53 | qreal absoluteCategorySum(int category); | |||
|
54 | qreal maxCategorySum(); | |||
|
55 | BarChartModel& modelInternal(); | |||
|
56 | ||||
|
57 | static QBarSeriesPrivate &data(QBarSeries *barseries) | |||
|
58 | { | |||
|
59 | Q_ASSERT(barseries); | |||
|
60 | return *barseries->d_ptr; | |||
|
61 | } | |||
|
62 | ||||
|
63 | Q_SIGNALS: | |||
|
64 | void clicked(QBarSet *barset, QString category, Qt::MouseButtons button); // Up to user of api, what to do with these signals | |||
|
65 | void selected(); | |||
|
66 | void updatedBars(); | |||
|
67 | void restructuredBars(); | |||
|
68 | void showToolTip(QPoint pos, QString tip); | |||
|
69 | ||||
|
70 | public Q_SLOTS: | |||
|
71 | void setToolTipEnabled(bool enabled = true); // enables tooltips | |||
|
72 | void barsetClicked(QString category, Qt::MouseButtons button); | |||
|
73 | ||||
|
74 | private Q_SLOTS: | |||
|
75 | // slots for updating bars when data in model changes | |||
|
76 | void modelUpdated(QModelIndex topLeft, QModelIndex bottomRight); | |||
|
77 | void modelDataAdded(QModelIndex parent, int start, int end); | |||
|
78 | void modelDataRemoved(QModelIndex parent, int start, int end); | |||
|
79 | void barsetChanged(); | |||
|
80 | ||||
|
81 | protected: | |||
|
82 | QBarSeries * const q_ptr; | |||
|
83 | ||||
|
84 | BarChartModel *m_internalModel; // TODO: this may change... current "2 models" situation doesn't look good. | |||
|
85 | QAbstractItemModel* m_model; | |||
|
86 | int m_mapCategories; | |||
|
87 | int m_mapBarBottom; | |||
|
88 | int m_mapBarTop; | |||
|
89 | int m_mapFirst; | |||
|
90 | int m_mapCount; | |||
|
91 | Qt::Orientation m_mapOrientation; | |||
|
92 | }; | |||
|
93 | ||||
|
94 | QTCOMMERCIALCHART_END_NAMESPACE | |||
|
95 | ||||
|
96 | #endif // QBARSERIESPRIVATE_P_H |
@@ -0,0 +1,80 | |||||
|
1 | #ifndef QBARSETPRIVATE_P_H | |||
|
2 | #define QBARSETPRIVATE_P_H | |||
|
3 | ||||
|
4 | #include "qbarset.h" | |||
|
5 | ||||
|
6 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||
|
7 | ||||
|
8 | class QBarSetPrivate : public QObject | |||
|
9 | { | |||
|
10 | Q_OBJECT | |||
|
11 | Q_DECLARE_PUBLIC(QBarSet) | |||
|
12 | ||||
|
13 | public: | |||
|
14 | QBarSetPrivate(QString name, QBarSet *parent); | |||
|
15 | ~QBarSetPrivate(); | |||
|
16 | ||||
|
17 | void setName(QString name); | |||
|
18 | QString name() const; | |||
|
19 | QBarSetPrivate& operator << (const qreal &value); // appends new value to set | |||
|
20 | void insertValue(int i, qreal value); | |||
|
21 | void removeValue(int i); | |||
|
22 | int count() const; | |||
|
23 | qreal valueAt(int index) const; | |||
|
24 | void setValue(int index, qreal value); | |||
|
25 | qreal sum() const; | |||
|
26 | ||||
|
27 | void setPen(const QPen &pen); | |||
|
28 | QPen pen() const; | |||
|
29 | ||||
|
30 | void setBrush(const QBrush &brush); | |||
|
31 | QBrush brush() const; | |||
|
32 | ||||
|
33 | void setLabelPen(const QPen &pen); | |||
|
34 | QPen labelPen() const; | |||
|
35 | ||||
|
36 | void setLabelBrush(const QBrush &brush); | |||
|
37 | QBrush labelBrush() const; | |||
|
38 | ||||
|
39 | void setLabelFont(const QFont &font); | |||
|
40 | QFont labelFont() const; | |||
|
41 | ||||
|
42 | void setLabelsVisible(bool visible = true); | |||
|
43 | bool labelsVisible() const; | |||
|
44 | ||||
|
45 | static QBarSetPrivate &pimpl(QBarSet *barset) | |||
|
46 | { | |||
|
47 | Q_ASSERT(barset); | |||
|
48 | return *barset->d_ptr; | |||
|
49 | } | |||
|
50 | ||||
|
51 | Q_SIGNALS: | |||
|
52 | void clicked(QString category, Qt::MouseButtons button); | |||
|
53 | void structureChanged(); | |||
|
54 | void valueChanged(); | |||
|
55 | void hoverEnter(QPoint pos); | |||
|
56 | void hoverLeave(); | |||
|
57 | void showToolTip(QPoint pos, QString tip); | |||
|
58 | void labelsVisibleChanged(bool visible); | |||
|
59 | ||||
|
60 | public Q_SLOTS: | |||
|
61 | void barHoverEnterEvent(QPoint pos); | |||
|
62 | void barHoverLeaveEvent(); | |||
|
63 | ||||
|
64 | public: | |||
|
65 | QBarSet * const q_ptr; | |||
|
66 | ||||
|
67 | QString m_name; | |||
|
68 | QList<qreal> m_values; // TODO: replace with map (category, value) | |||
|
69 | QMap<QString, qreal> m_mappedValues; | |||
|
70 | QPen m_pen; | |||
|
71 | QBrush m_brush; | |||
|
72 | QPen m_labelPen; | |||
|
73 | QBrush m_labelBrush; | |||
|
74 | QFont m_labelFont; | |||
|
75 | bool m_labelsVisible; | |||
|
76 | }; | |||
|
77 | ||||
|
78 | QTCOMMERCIALCHART_END_NAMESPACE | |||
|
79 | ||||
|
80 | #endif // QBARSETPRIVATE_P_H |
@@ -1,117 +1,117 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include <QtGui/QApplication> |
|
21 | #include <QtGui/QApplication> | |
22 | #include <QMainWindow> |
|
22 | #include <QMainWindow> | |
23 | #include <QChartView> |
|
23 | #include <QChartView> | |
24 | #include <QBarSet> |
|
24 | #include <QBarSet> | |
25 | #include <QLegend> |
|
25 | #include <QLegend> | |
26 | #include "drilldownseries.h" |
|
26 | #include "drilldownseries.h" | |
27 | #include "drilldownchart.h" |
|
27 | #include "drilldownchart.h" | |
28 |
|
28 | |||
29 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
29 | QTCOMMERCIALCHART_USE_NAMESPACE | |
30 |
|
30 | |||
31 | int main(int argc, char *argv[]) |
|
31 | int main(int argc, char *argv[]) | |
32 | { |
|
32 | { | |
33 | //! [1] |
|
33 | //! [1] | |
34 | QApplication a(argc, argv); |
|
34 | QApplication a(argc, argv); | |
35 | QMainWindow window; |
|
35 | QMainWindow window; | |
36 | //! [1] |
|
36 | //! [1] | |
37 |
|
37 | |||
38 | //! [2] |
|
38 | //! [2] | |
39 | DrilldownChart* drilldownChart = new DrilldownChart(); |
|
39 | DrilldownChart* drilldownChart = new DrilldownChart(); | |
40 | drilldownChart->setTheme(QChart::ChartThemeBlueIcy); |
|
40 | drilldownChart->setTheme(QChart::ChartThemeBlueIcy); | |
41 | drilldownChart->setAnimationOptions(QChart::SeriesAnimations); |
|
41 | drilldownChart->setAnimationOptions(QChart::SeriesAnimations); | |
42 | //! [2] |
|
42 | //! [2] | |
43 |
|
43 | |||
44 | //! [3] |
|
44 | //! [3] | |
45 | // Define categories |
|
45 | // Define categories | |
46 | QStringList months; |
|
46 | QStringList months; | |
47 | months << "May" << "Jun" << "Jul" << "Aug" << "Sep"; |
|
47 | months << "May" << "Jun" << "Jul" << "Aug" << "Sep"; | |
48 | QStringList weeks; |
|
48 | QStringList weeks; | |
49 | weeks << "week 1" << "week 2" << "week 3" << "week 4"; |
|
49 | weeks << "week 1" << "week 2" << "week 3" << "week 4"; | |
50 | QStringList plants; |
|
50 | QStringList plants; | |
51 | plants << "Habanero" << "Lemon Drop" << "Starfish" << "Aji Amarillo"; |
|
51 | plants << "Habanero" << "Lemon Drop" << "Starfish" << "Aji Amarillo"; | |
52 | //! [3] |
|
52 | //! [3] | |
53 |
|
53 | |||
54 | //! [4] |
|
54 | //! [4] | |
55 | // Create drilldown structure |
|
55 | // Create drilldown structure | |
56 | DrilldownBarSeries* seasonSeries = new DrilldownBarSeries(months, drilldownChart); |
|
56 | DrilldownBarSeries* seasonSeries = new DrilldownBarSeries(months, drilldownChart); | |
57 | seasonSeries->setName("Crop by month - Season"); |
|
57 | seasonSeries->setName("Crop by month - Season"); | |
58 |
|
58 | |||
59 | // Each month in season series has drilldown series for weekly data |
|
59 | // Each month in season series has drilldown series for weekly data | |
60 | foreach (QString month, months) { |
|
60 | foreach (QString month, months) { | |
61 |
|
61 | |||
62 | // Create drilldown series for every week |
|
62 | // Create drilldown series for every week | |
63 | DrilldownBarSeries* weeklySeries = new DrilldownBarSeries(weeks, drilldownChart); |
|
63 | DrilldownBarSeries* weeklySeries = new DrilldownBarSeries(weeks, drilldownChart); | |
64 | seasonSeries->mapDrilldownSeries(month, weeklySeries); |
|
64 | seasonSeries->mapDrilldownSeries(month, weeklySeries); | |
65 |
|
65 | |||
66 | // Drilling down from weekly data brings us back to season data. |
|
66 | // Drilling down from weekly data brings us back to season data. | |
67 | foreach (QString week, weeks) { |
|
67 | foreach (QString week, weeks) { | |
68 | weeklySeries->mapDrilldownSeries(week, seasonSeries); |
|
68 | weeklySeries->mapDrilldownSeries(week, seasonSeries); | |
69 | weeklySeries->setName(QString("Crop by week - " + month)); |
|
69 | weeklySeries->setName(QString("Crop by week - " + month)); | |
70 | } |
|
70 | } | |
71 |
|
71 | |||
72 | // Use right click signal to implement drilldown |
|
72 | // Use right click signal to implement drilldown | |
73 | QObject::connect(weeklySeries, SIGNAL(clicked(QBarSet*,QString,Qt::MouseButtons)), drilldownChart, SLOT(handleClicked(QBarSet*,QString,Qt::MouseButtons))); |
|
73 | QObject::connect(weeklySeries, SIGNAL(clicked(QBarSet*,QString,Qt::MouseButtons)), drilldownChart, SLOT(handleClicked(QBarSet*,QString,Qt::MouseButtons))); | |
74 | } |
|
74 | } | |
75 |
|
75 | |||
76 | // Enable drilldown from season series using right click. |
|
76 | // Enable drilldown from season series using right click. | |
77 | QObject::connect(seasonSeries, SIGNAL(clicked(QBarSet*,QString,Qt::MouseButtons)), drilldownChart, SLOT(handleClicked(QBarSet*,QString,Qt::MouseButtons))); |
|
77 | QObject::connect(seasonSeries, SIGNAL(clicked(QBarSet*,QString,Qt::MouseButtons)), drilldownChart, SLOT(handleClicked(QBarSet*,QString,Qt::MouseButtons))); | |
78 | //! [4] |
|
78 | //! [4] | |
79 |
|
79 | |||
80 | //! [5] |
|
80 | //! [5] | |
81 | // Fill monthly and weekly series with data |
|
81 | // Fill monthly and weekly series with data | |
82 | foreach (QString plant, plants) { |
|
82 | foreach (QString plant, plants) { | |
83 | QBarSet* monthlyCrop = new QBarSet(plant); |
|
83 | QBarSet* monthlyCrop = new QBarSet(plant); | |
84 | foreach (QString month, months) { |
|
84 | foreach (QString month, months) { | |
85 | QBarSet* weeklyCrop = new QBarSet(plant); |
|
85 | QBarSet* weeklyCrop = new QBarSet(plant); | |
86 | foreach (QString week, weeks ) |
|
86 | foreach (QString week, weeks ) | |
87 | *weeklyCrop << (qrand() % 20); |
|
87 | *weeklyCrop << (qrand() % 20); | |
88 | // Get the drilldown series from season series and add crop to it. |
|
88 | // Get the drilldown series from season series and add crop to it. | |
89 | seasonSeries->drilldownSeries(month)->appendBarSet(weeklyCrop); |
|
89 | seasonSeries->drilldownSeries(month)->appendBarSet(weeklyCrop); | |
90 | seasonSeries->drilldownSeries(month)->setToolTipEnabled(true); |
|
90 | seasonSeries->drilldownSeries(month)->setToolTipEnabled(true); | |
91 |
*monthlyCrop << weeklyCrop-> |
|
91 | *monthlyCrop << weeklyCrop->sum(); | |
92 | } |
|
92 | } | |
93 | seasonSeries->appendBarSet(monthlyCrop); |
|
93 | seasonSeries->appendBarSet(monthlyCrop); | |
94 | } |
|
94 | } | |
95 | //! [5] |
|
95 | //! [5] | |
96 |
|
96 | |||
97 | //! [6] |
|
97 | //! [6] | |
98 | // Show season series in initial view |
|
98 | // Show season series in initial view | |
99 | drilldownChart->changeSeries(seasonSeries); |
|
99 | drilldownChart->changeSeries(seasonSeries); | |
100 | drilldownChart->setTitle(seasonSeries->name()); |
|
100 | drilldownChart->setTitle(seasonSeries->name()); | |
101 | //! [6] |
|
101 | //! [6] | |
102 |
|
102 | |||
103 | //! [7] |
|
103 | //! [7] | |
104 | drilldownChart->axisX()->setGridLineVisible(false); |
|
104 | drilldownChart->axisX()->setGridLineVisible(false); | |
105 | drilldownChart->axisY()->setNiceNumbers(true); |
|
105 | drilldownChart->axisY()->setNiceNumbers(true); | |
106 | drilldownChart->legend()->setVisible(true); |
|
106 | drilldownChart->legend()->setVisible(true); | |
107 | drilldownChart->legend()->setAlignment(QLegend::AlignmentBottom); |
|
107 | drilldownChart->legend()->setAlignment(QLegend::AlignmentBottom); | |
108 | //! [7] |
|
108 | //! [7] | |
109 |
|
109 | |||
110 | QChartView *chartView = new QChartView(drilldownChart); |
|
110 | QChartView *chartView = new QChartView(drilldownChart); | |
111 | window.setCentralWidget(chartView); |
|
111 | window.setCentralWidget(chartView); | |
112 | window.resize(400, 300); |
|
112 | window.resize(400, 300); | |
113 | window.show(); |
|
113 | window.show(); | |
114 |
|
114 | |||
115 | return a.exec(); |
|
115 | return a.exec(); | |
116 | } |
|
116 | } | |
117 |
|
117 |
@@ -1,29 +1,31 | |||||
1 | INCLUDEPATH += $$PWD |
|
1 | INCLUDEPATH += $$PWD | |
2 | DEPENDPATH += $$PWD |
|
2 | DEPENDPATH += $$PWD | |
3 |
|
3 | |||
4 | SOURCES += \ |
|
4 | SOURCES += \ | |
5 | $$PWD/bar.cpp \ |
|
5 | $$PWD/bar.cpp \ | |
6 | $$PWD/barchartmodel.cpp \ |
|
6 | $$PWD/barchartmodel.cpp \ | |
7 | $$PWD/barchartitem.cpp \ |
|
7 | $$PWD/barchartitem.cpp \ | |
8 | $$PWD/percentbarchartitem.cpp \ |
|
8 | $$PWD/percentbarchartitem.cpp \ | |
9 | $$PWD/qbarseries.cpp \ |
|
9 | $$PWD/qbarseries.cpp \ | |
10 | $$PWD/qbarset.cpp \ |
|
10 | $$PWD/qbarset.cpp \ | |
11 | $$PWD/qpercentbarseries.cpp \ |
|
11 | $$PWD/qpercentbarseries.cpp \ | |
12 | $$PWD/qstackedbarseries.cpp \ |
|
12 | $$PWD/qstackedbarseries.cpp \ | |
13 | $$PWD/stackedbarchartitem.cpp \ |
|
13 | $$PWD/stackedbarchartitem.cpp \ | |
14 | $$PWD/barlabel.cpp |
|
14 | $$PWD/barlabel.cpp | |
15 |
|
15 | |||
16 | PRIVATE_HEADERS += \ |
|
16 | PRIVATE_HEADERS += \ | |
17 | $$PWD/bar_p.h \ |
|
17 | $$PWD/bar_p.h \ | |
18 | $$PWD/barchartmodel_p.h \ |
|
18 | $$PWD/barchartmodel_p.h \ | |
19 | $$PWD/barchartitem_p.h \ |
|
19 | $$PWD/barchartitem_p.h \ | |
20 | $$PWD/percentbarchartitem_p.h \ |
|
20 | $$PWD/percentbarchartitem_p.h \ | |
21 | $$PWD/stackedbarchartitem_p.h \ |
|
21 | $$PWD/stackedbarchartitem_p.h \ | |
22 | $$PWD/barlabel_p.h |
|
22 | $$PWD/barlabel_p.h \ | |
|
23 | $$PWD/qbarsetprivate_p.h \ | |||
|
24 | $$PWD/qbarseriesprivate_p.h | |||
23 |
|
25 | |||
24 | PUBLIC_HEADERS += \ |
|
26 | PUBLIC_HEADERS += \ | |
25 | $$PWD/qbarseries.h \ |
|
27 | $$PWD/qbarseries.h \ | |
26 | $$PWD/qbarset.h \ |
|
28 | $$PWD/qbarset.h \ | |
27 | $$PWD/qpercentbarseries.h \ |
|
29 | $$PWD/qpercentbarseries.h \ | |
28 | $$PWD/qstackedbarseries.h |
|
30 | $$PWD/qstackedbarseries.h | |
29 |
|
31 |
@@ -1,472 +1,874 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include <QDebug> |
|
21 | #include <QDebug> | |
22 | #include "qbarseries.h" |
|
22 | #include "qbarseries.h" | |
23 | #include "qbarset.h" |
|
23 | #include "qbarset.h" | |
24 | #include "barchartmodel_p.h" |
|
24 | #include "barchartmodel_p.h" | |
|
25 | #include "qbarseriesprivate_p.h" | |||
|
26 | #include "qbarsetprivate_p.h" | |||
25 | #include <QAbstractItemModel> |
|
27 | #include <QAbstractItemModel> | |
26 | #include <QModelIndex> |
|
28 | #include <QModelIndex> | |
27 |
|
29 | |||
28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
29 |
|
31 | |||
|
32 | QBarSeriesPrivate::QBarSeriesPrivate(QBarCategories categories, QBarSeries *parent) : QObject(parent), | |||
|
33 | q_ptr(parent), | |||
|
34 | m_internalModel(new BarChartModel(categories,this)) | |||
|
35 | { | |||
|
36 | m_model = 0; | |||
|
37 | m_mapCategories = -1; | |||
|
38 | m_mapBarBottom = -1; | |||
|
39 | m_mapBarTop = -1; | |||
|
40 | m_mapFirst = 0; | |||
|
41 | m_mapCount = 0; | |||
|
42 | m_mapOrientation = Qt::Vertical; | |||
|
43 | } | |||
|
44 | ||||
|
45 | void QBarSeriesPrivate::appendBarSet(QBarSet *set) | |||
|
46 | { | |||
|
47 | m_internalModel->appendBarSet(set); | |||
|
48 | // connect(set, SIGNAL(clicked(QString,Qt::MouseButtons)), this, SLOT(barsetClicked(QString,Qt::MouseButtons))); | |||
|
49 | // connect(set, SIGNAL(valueChanged()), this, SLOT(barsetChanged())); | |||
|
50 | emit restructuredBars(); | |||
|
51 | } | |||
|
52 | ||||
|
53 | void QBarSeriesPrivate::removeBarSet(QBarSet *set) | |||
|
54 | { | |||
|
55 | // disconnect(set, SIGNAL(clicked(QString,Qt::MouseButtons)), this, SLOT(barsetClicked(QString,Qt::MouseButtons))); | |||
|
56 | m_internalModel->removeBarSet(set); | |||
|
57 | emit restructuredBars(); | |||
|
58 | } | |||
|
59 | void QBarSeriesPrivate::appendBarSets(QList<QBarSet* > sets) | |||
|
60 | { | |||
|
61 | foreach (QBarSet* barset, sets) { | |||
|
62 | m_internalModel->appendBarSet(barset); | |||
|
63 | connect(barset, SIGNAL(clicked(QString,Qt::MouseButtons)), this, SLOT(barsetClicked(QString,Qt::MouseButtons))); | |||
|
64 | connect(barset, SIGNAL(valueChanged()), this, SLOT(barsetChanged())); | |||
|
65 | } | |||
|
66 | emit restructuredBars(); | |||
|
67 | } | |||
|
68 | ||||
|
69 | void QBarSeriesPrivate::removeBarSets(QList<QBarSet* > sets) | |||
|
70 | { | |||
|
71 | foreach (QBarSet* barset, sets) { | |||
|
72 | disconnect(barset, SIGNAL(clicked(QString,Qt::MouseButtons)), this, SLOT(barsetClicked(QString,Qt::MouseButtons))); | |||
|
73 | m_internalModel->removeBarSet(barset); | |||
|
74 | } | |||
|
75 | emit restructuredBars(); | |||
|
76 | } | |||
|
77 | ||||
|
78 | void QBarSeriesPrivate::insertBarSet(int i, QBarSet *set) | |||
|
79 | { | |||
|
80 | m_internalModel->insertBarSet(i, set); | |||
|
81 | // emit barsetChanged(); | |||
|
82 | } | |||
|
83 | ||||
|
84 | void QBarSeriesPrivate::insertCategory(int i, QString category) | |||
|
85 | { | |||
|
86 | m_internalModel->insertCategory(i, category); | |||
|
87 | } | |||
|
88 | ||||
|
89 | void QBarSeriesPrivate::removeCategory(int i) | |||
|
90 | { | |||
|
91 | m_internalModel->removeCategory(i); | |||
|
92 | } | |||
|
93 | ||||
|
94 | int QBarSeriesPrivate::barsetCount() const | |||
|
95 | { | |||
|
96 | // if(m_model) | |||
|
97 | // return m_mapBarTop - m_mapBarBottom; | |||
|
98 | // else | |||
|
99 | return m_internalModel->barsetCount(); | |||
|
100 | } | |||
|
101 | ||||
|
102 | int QBarSeriesPrivate::categoryCount() const | |||
|
103 | { | |||
|
104 | return m_internalModel->categoryCount(); | |||
|
105 | } | |||
|
106 | ||||
|
107 | QList<QBarSet*> QBarSeriesPrivate::barSets() const | |||
|
108 | { | |||
|
109 | return m_internalModel->barSets(); | |||
|
110 | } | |||
|
111 | ||||
|
112 | QBarSet* QBarSeriesPrivate::barsetAt(int index) | |||
|
113 | { | |||
|
114 | return m_internalModel->barsetAt(index); | |||
|
115 | } | |||
|
116 | ||||
|
117 | QString QBarSeriesPrivate::categoryName(int category) | |||
|
118 | { | |||
|
119 | return m_internalModel->categoryName(category); | |||
|
120 | } | |||
|
121 | ||||
|
122 | void QBarSeriesPrivate::setToolTipEnabled(bool enabled) | |||
|
123 | { | |||
|
124 | // TODO: what if we add sets after call to this function? Those sets won't have tooltip enabled. | |||
|
125 | if (enabled) { | |||
|
126 | for (int i=0; i<m_internalModel->barsetCount(); i++) { | |||
|
127 | QBarSet *set = m_internalModel->barsetAt(i); | |||
|
128 | connect(set, SIGNAL(showToolTip(QPoint,QString)), this, SIGNAL(showToolTip(QPoint,QString))); | |||
|
129 | } | |||
|
130 | } else { | |||
|
131 | for (int i=0; i<m_internalModel->barsetCount(); i++) { | |||
|
132 | QBarSet *set = m_internalModel->barsetAt(i); | |||
|
133 | disconnect(set, SIGNAL(showToolTip(QPoint,QString)), this, SIGNAL(showToolTip(QPoint,QString))); | |||
|
134 | } | |||
|
135 | } | |||
|
136 | } | |||
|
137 | ||||
|
138 | void QBarSeriesPrivate::barsetClicked(QString category, Qt::MouseButtons button) | |||
|
139 | { | |||
|
140 | emit clicked(qobject_cast<QBarSet*>(sender()), category, button); | |||
|
141 | } | |||
|
142 | ||||
|
143 | qreal QBarSeriesPrivate::min() | |||
|
144 | { | |||
|
145 | return m_internalModel->min(); | |||
|
146 | } | |||
|
147 | ||||
|
148 | qreal QBarSeriesPrivate::max() | |||
|
149 | { | |||
|
150 | return m_internalModel->max(); | |||
|
151 | } | |||
|
152 | ||||
|
153 | qreal QBarSeriesPrivate::valueAt(int set, int category) | |||
|
154 | { | |||
|
155 | return m_internalModel->valueAt(set, category); | |||
|
156 | } | |||
|
157 | ||||
|
158 | qreal QBarSeriesPrivate::percentageAt(int set, int category) | |||
|
159 | { | |||
|
160 | return m_internalModel->percentageAt(set, category); | |||
|
161 | } | |||
|
162 | ||||
|
163 | qreal QBarSeriesPrivate::categorySum(int category) | |||
|
164 | { | |||
|
165 | return m_internalModel->categorySum(category); | |||
|
166 | } | |||
|
167 | ||||
|
168 | qreal QBarSeriesPrivate::absoluteCategorySum(int category) | |||
|
169 | { | |||
|
170 | return m_internalModel->absoluteCategorySum(category); | |||
|
171 | } | |||
|
172 | ||||
|
173 | qreal QBarSeriesPrivate::maxCategorySum() | |||
|
174 | { | |||
|
175 | return m_internalModel->maxCategorySum(); | |||
|
176 | } | |||
|
177 | ||||
|
178 | BarChartModel& QBarSeriesPrivate::modelInternal() | |||
|
179 | { | |||
|
180 | return *m_internalModel; | |||
|
181 | } | |||
|
182 | ||||
|
183 | bool QBarSeriesPrivate::setModel(QAbstractItemModel *model) | |||
|
184 | { | |||
|
185 | // disconnect signals from old model | |||
|
186 | if(m_model) | |||
|
187 | { | |||
|
188 | disconnect(m_model, 0, this, 0); | |||
|
189 | m_mapCategories = -1; | |||
|
190 | m_mapBarBottom = -1; | |||
|
191 | m_mapBarTop = -1; | |||
|
192 | m_mapFirst = 0; | |||
|
193 | m_mapCount = 0; | |||
|
194 | m_mapOrientation = Qt::Vertical; | |||
|
195 | } | |||
|
196 | ||||
|
197 | // set new model | |||
|
198 | if(model) | |||
|
199 | { | |||
|
200 | m_model = model; | |||
|
201 | return true; | |||
|
202 | } | |||
|
203 | else | |||
|
204 | { | |||
|
205 | m_model = 0; | |||
|
206 | return false; | |||
|
207 | } | |||
|
208 | } | |||
|
209 | ||||
|
210 | void QBarSeriesPrivate::setModelMapping(int categories, int bottomBoundry, int topBoundry, Qt::Orientation orientation) | |||
|
211 | { | |||
|
212 | if (!m_model) | |||
|
213 | return; | |||
|
214 | ||||
|
215 | m_mapCategories = categories; | |||
|
216 | m_mapBarBottom = bottomBoundry; | |||
|
217 | m_mapBarTop = topBoundry; | |||
|
218 | // m_mapFirst = 1; | |||
|
219 | m_mapOrientation = orientation; | |||
|
220 | ||||
|
221 | // connect the signals | |||
|
222 | if (m_mapOrientation == Qt::Vertical) { | |||
|
223 | m_mapCount = m_model->rowCount() - m_mapFirst; | |||
|
224 | connect(m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)), | |||
|
225 | this, SLOT(modelUpdated(QModelIndex, QModelIndex))); | |||
|
226 | connect(m_model,SIGNAL(rowsInserted(QModelIndex, int, int)), | |||
|
227 | this, SLOT(modelDataAdded(QModelIndex,int,int))); | |||
|
228 | connect(m_model, SIGNAL(rowsRemoved(QModelIndex, int, int)), | |||
|
229 | this, SLOT(modelDataRemoved(QModelIndex,int,int))); | |||
|
230 | } else { | |||
|
231 | m_mapCount = m_model->columnCount() - m_mapFirst; | |||
|
232 | connect(m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)), | |||
|
233 | this, SLOT(modelUpdated(QModelIndex, QModelIndex))); | |||
|
234 | connect(m_model,SIGNAL(columnsInserted(QModelIndex, int, int)), | |||
|
235 | this, SLOT(modelDataAdded(QModelIndex,int,int))); | |||
|
236 | connect(m_model, SIGNAL(columnsRemoved(QModelIndex, int, int)), | |||
|
237 | this, SLOT(modelDataRemoved(QModelIndex,int,int))); | |||
|
238 | } | |||
|
239 | ||||
|
240 | // create the initial bars | |||
|
241 | delete m_internalModel; | |||
|
242 | if (m_mapOrientation == Qt::Vertical) { | |||
|
243 | QStringList categories; | |||
|
244 | for (int k = m_mapFirst; k < m_mapFirst + m_mapCount; k++) | |||
|
245 | categories << m_model->data(m_model->index(k, m_mapCategories), Qt::DisplayRole).toString(); | |||
|
246 | m_internalModel = new BarChartModel(categories, this); | |||
|
247 | ||||
|
248 | for (int i = m_mapBarBottom; i <= m_mapBarTop; i++) { | |||
|
249 | QBarSet* barSet = new QBarSet(QString("Column: %1").arg(i + 1)); | |||
|
250 | for(int m = m_mapFirst; m < m_mapFirst + m_mapCount; m++) | |||
|
251 | *barSet << m_model->data(m_model->index(m, i), Qt::DisplayRole).toDouble(); | |||
|
252 | appendBarSet(barSet); | |||
|
253 | } | |||
|
254 | } else { | |||
|
255 | QStringList categories; | |||
|
256 | for (int k = m_mapFirst; k < m_mapFirst + m_mapCount; k++) | |||
|
257 | categories << m_model->data(m_model->index(m_mapCategories, k), Qt::DisplayRole).toString(); | |||
|
258 | m_internalModel = new BarChartModel(categories, this); | |||
|
259 | ||||
|
260 | for (int i = m_mapBarBottom; i <= m_mapBarTop; i++) { | |||
|
261 | QBarSet* barSet = new QBarSet(QString("Row: %1").arg(i + 1)); | |||
|
262 | for(int m = m_mapFirst; m < m_mapFirst + m_mapCount; m++) | |||
|
263 | *barSet << m_model->data(m_model->index(i, m), Qt::DisplayRole).toDouble(); | |||
|
264 | appendBarSet(barSet); | |||
|
265 | } | |||
|
266 | } | |||
|
267 | } | |||
|
268 | ||||
|
269 | void QBarSeriesPrivate::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight) | |||
|
270 | { | |||
|
271 | Q_UNUSED(bottomRight) | |||
|
272 | ||||
|
273 | if (m_mapOrientation == Qt::Vertical) | |||
|
274 | { | |||
|
275 | // model update is relevant to BarSeries if the change was made to the part of the model that was mapped to BarSeries | |||
|
276 | if (topLeft.column() >= m_mapBarBottom && topLeft.column() <= m_mapBarTop && topLeft.row() >= m_mapFirst && topLeft.row() < m_mapFirst + m_mapCount) | |||
|
277 | barsetAt(topLeft.column() - m_mapBarBottom)->setValue(topLeft.row() - m_mapFirst, m_model->data(topLeft, Qt::DisplayRole).toDouble()); | |||
|
278 | } | |||
|
279 | else | |||
|
280 | { | |||
|
281 | // model update is relevant to BarSeries if the change was made to the part of the model that was mapped to BarSeries | |||
|
282 | if (topLeft.row() >= m_mapBarBottom && topLeft.row() <= m_mapBarTop && topLeft.column() >= m_mapFirst && topLeft.column() < m_mapFirst + m_mapCount) | |||
|
283 | barsetAt(topLeft.row() - m_mapBarBottom)->setValue(topLeft.column() - m_mapFirst, m_model->data(topLeft, Qt::DisplayRole).toDouble()); | |||
|
284 | } | |||
|
285 | } | |||
|
286 | ||||
|
287 | void QBarSeriesPrivate::modelDataAdded(QModelIndex /*parent*/, int start, int /*end*/) | |||
|
288 | { | |||
|
289 | if (m_mapOrientation == Qt::Vertical) { | |||
|
290 | insertCategory(start - m_mapFirst, QString("Row: %1").arg(start + 1)); | |||
|
291 | for (int i = 0; i <= m_mapBarTop - m_mapBarBottom; i++) { | |||
|
292 | barsetAt(i)->insertValue(start - m_mapFirst, m_model->data(m_model->index(start, i), Qt::DisplayRole).toDouble()); | |||
|
293 | } | |||
|
294 | } else { | |||
|
295 | insertCategory(start - m_mapFirst, QString("Column: %1").arg(start + 1)); | |||
|
296 | for (int i = 0; i <= m_mapBarTop - m_mapBarBottom; i++) { | |||
|
297 | barsetAt(i)->insertValue(start - m_mapFirst, m_model->data(m_model->index(i, start), Qt::DisplayRole).toDouble()); | |||
|
298 | } | |||
|
299 | } | |||
|
300 | emit restructuredBars(); | |||
|
301 | } | |||
|
302 | ||||
|
303 | void QBarSeriesPrivate::modelDataRemoved(QModelIndex parent, int start, int end) | |||
|
304 | { | |||
|
305 | Q_UNUSED(parent) | |||
|
306 | Q_UNUSED(end) | |||
|
307 | ||||
|
308 | removeCategory(start - m_mapFirst); | |||
|
309 | for (int i = 0; i <= m_mapBarTop - m_mapBarBottom; i++) | |||
|
310 | { | |||
|
311 | barsetAt(i)->removeValue(start - m_mapFirst); | |||
|
312 | } | |||
|
313 | emit restructuredBars(); | |||
|
314 | } | |||
|
315 | ||||
|
316 | void QBarSeriesPrivate::barsetChanged() | |||
|
317 | { | |||
|
318 | emit updatedBars(); | |||
|
319 | } | |||
|
320 | ||||
|
321 | QBarCategories QBarSeriesPrivate::categories() const | |||
|
322 | { | |||
|
323 | QBarCategories categories; | |||
|
324 | int count = m_internalModel->categoryCount(); | |||
|
325 | for (int i=1; i <= count; i++) { | |||
|
326 | categories.insert(i, m_internalModel->categoryName(i - 1)); | |||
|
327 | } | |||
|
328 | return categories; | |||
|
329 | } | |||
|
330 | ||||
|
331 | void QBarSeriesPrivate::setLabelsVisible(bool visible) | |||
|
332 | { | |||
|
333 | foreach (QBarSet* s, barSets()) { | |||
|
334 | s->setLabelsVisible(visible); | |||
|
335 | } | |||
|
336 | } | |||
|
337 | ||||
|
338 | ||||
30 | /*! |
|
339 | /*! | |
31 | \class QBarSeries |
|
340 | \class QBarSeries | |
32 | \brief part of QtCommercial chart API. |
|
341 | \brief part of QtCommercial chart API. | |
33 |
|
342 | |||
34 | QBarSeries represents a series of data shown as bars. One QBarSeries can contain multible |
|
343 | QBarSeries represents a series of data shown as bars. One QBarSeries can contain multible | |
35 | QBarSet data sets. QBarSeries groups the data from sets to categories, which are defined |
|
344 | QBarSet data sets. QBarSeries groups the data from sets to categories, which are defined | |
36 | by QStringList. |
|
345 | by QStringList. | |
37 |
|
346 | |||
38 | \mainclass |
|
347 | \mainclass | |
39 |
|
348 | |||
40 | \sa QBarSet, QStackedBarSeries, QPercentBarSeries |
|
349 | \sa QBarSet, QStackedBarSeries, QPercentBarSeries | |
41 | */ |
|
350 | */ | |
42 |
|
351 | |||
43 | /*! |
|
352 | /*! | |
44 | \fn virtual QSeriesType QBarSeries::type() const |
|
353 | \fn virtual QSeriesType QBarSeries::type() const | |
45 | \brief Returns type of series. |
|
354 | \brief Returns type of series. | |
46 | \sa QSeries, QSeriesType |
|
355 | \sa QSeries, QSeriesType | |
47 | */ |
|
356 | */ | |
48 |
|
357 | |||
49 | /*! |
|
358 | /*! | |
50 | \fn void QBarSeries::showToolTip(QPoint pos, QString tip) |
|
359 | \fn void QBarSeries::showToolTip(QPoint pos, QString tip) | |
51 | \brief \internal \a pos \a tip |
|
360 | \brief \internal \a pos \a tip | |
52 | */ |
|
361 | */ | |
53 |
|
362 | |||
54 | /*! |
|
363 | /*! | |
55 | Constructs empty QBarSeries. Parameter \a categories defines the categories for chart. |
|
364 | Constructs empty QBarSeries. Parameter \a categories defines the categories for chart. | |
56 | QBarSeries is QObject which is a child of a \a parent. |
|
365 | QBarSeries is QObject which is a child of a \a parent. | |
57 | */ |
|
366 | */ | |
58 | QBarSeries::QBarSeries(QBarCategories categories, QObject *parent) : QSeries(parent), |
|
367 | QBarSeries::QBarSeries(QBarCategories categories, QObject *parent) : QSeries(parent), | |
59 |
|
|
368 | d_ptr(new QBarSeriesPrivate(categories, this)) | |
|
369 | // m_internalModel(new BarChartModel(categories, this)) | |||
60 | { |
|
370 | { | |
61 | m_model = 0; |
|
371 | // m_model = 0; | |
62 | m_mapCategories = -1; |
|
372 | // m_mapCategories = -1; | |
63 | m_mapBarBottom = -1; |
|
373 | // m_mapBarBottom = -1; | |
64 | m_mapBarTop = -1; |
|
374 | // m_mapBarTop = -1; | |
65 | m_mapFirst = 0; |
|
375 | // m_mapFirst = 0; | |
66 | m_mapCount = 0; |
|
376 | // m_mapCount = 0; | |
67 | m_mapOrientation = Qt::Vertical; |
|
377 | // m_mapOrientation = Qt::Vertical; | |
68 | } |
|
378 | } | |
69 |
|
379 | |||
70 | /*! |
|
380 | /*! | |
71 | Adds a set of bars to series. Takes ownership of \a set. |
|
381 | Adds a set of bars to series. Takes ownership of \a set. | |
72 | Connects the clicked(QString, Qt::MouseButtons) signal |
|
382 | Connects the clicked(QString, Qt::MouseButtons) signal | |
73 | of \a set to this series |
|
383 | of \a set to this series | |
74 | */ |
|
384 | */ | |
75 | void QBarSeries::appendBarSet(QBarSet *set) |
|
385 | void QBarSeries::appendBarSet(QBarSet *set) | |
76 | { |
|
386 | { | |
|
387 | Q_D(QBarSeries); | |||
|
388 | connect(&QBarSetPrivate::pimpl(set), SIGNAL(clicked(QString,Qt::MouseButtons)), d_ptr, SLOT(barsetClicked(QString,Qt::MouseButtons))); | |||
|
389 | connect(&QBarSetPrivate::pimpl(set), SIGNAL(valueChanged()), d_ptr, SLOT(barsetChanged())); | |||
|
390 | d->appendBarSet(set); | |||
|
391 | /* | |||
77 | m_internalModel->appendBarSet(set); |
|
392 | m_internalModel->appendBarSet(set); | |
78 | connect(set, SIGNAL(clicked(QString,Qt::MouseButtons)), this, SLOT(barsetClicked(QString,Qt::MouseButtons))); |
|
393 | connect(set, SIGNAL(clicked(QString,Qt::MouseButtons)), this, SLOT(barsetClicked(QString,Qt::MouseButtons))); | |
79 | connect(set, SIGNAL(valueChanged()), this, SLOT(barsetChanged())); |
|
394 | connect(set, SIGNAL(valueChanged()), this, SLOT(barsetChanged())); | |
80 | emit restructuredBars(); |
|
395 | emit restructuredBars(); | |
|
396 | */ | |||
81 | } |
|
397 | } | |
82 |
|
398 | |||
83 | /*! |
|
399 | /*! | |
84 | Removes a set of bars from series. Releases ownership of \a set. Doesnt delete \a set. |
|
400 | Removes a set of bars from series. Releases ownership of \a set. Doesnt delete \a set. | |
85 | Disconnects the clicked(QString, Qt::MouseButtons) signal |
|
401 | Disconnects the clicked(QString, Qt::MouseButtons) signal | |
86 | of \a set from this series |
|
402 | of \a set from this series | |
87 | */ |
|
403 | */ | |
88 | void QBarSeries::removeBarSet(QBarSet *set) |
|
404 | void QBarSeries::removeBarSet(QBarSet *set) | |
89 | { |
|
405 | { | |
|
406 | Q_D(QBarSeries); | |||
|
407 | disconnect(&QBarSetPrivate::pimpl(set), SIGNAL(clicked(QString,Qt::MouseButtons)), d_ptr, SLOT(barsetClicked(QString,Qt::MouseButtons))); | |||
|
408 | d->removeBarSet(set); | |||
|
409 | /* | |||
90 | disconnect(set, SIGNAL(clicked(QString,Qt::MouseButtons)), this, SLOT(barsetClicked(QString,Qt::MouseButtons))); |
|
410 | disconnect(set, SIGNAL(clicked(QString,Qt::MouseButtons)), this, SLOT(barsetClicked(QString,Qt::MouseButtons))); | |
91 | m_internalModel->removeBarSet(set); |
|
411 | m_internalModel->removeBarSet(set); | |
92 | emit restructuredBars(); |
|
412 | emit restructuredBars(); | |
|
413 | */ | |||
93 | } |
|
414 | } | |
94 |
|
415 | |||
95 | /*! |
|
416 | /*! | |
96 | Adds a list of barsets to series. Takes ownership of \a sets. |
|
417 | Adds a list of barsets to series. Takes ownership of \a sets. | |
97 | Connects the clicked(QString, Qt::MouseButtons) signals |
|
418 | Connects the clicked(QString, Qt::MouseButtons) signals | |
98 | of \a sets to this series |
|
419 | of \a sets to this series | |
99 | */ |
|
420 | */ | |
100 | void QBarSeries::appendBarSets(QList<QBarSet* > sets) |
|
421 | void QBarSeries::appendBarSets(QList<QBarSet* > sets) | |
101 | { |
|
422 | { | |
|
423 | Q_D(QBarSeries); | |||
|
424 | d->appendBarSets(sets); | |||
|
425 | /* | |||
102 | foreach (QBarSet* barset, sets) { |
|
426 | foreach (QBarSet* barset, sets) { | |
103 | m_internalModel->appendBarSet(barset); |
|
427 | m_internalModel->appendBarSet(barset); | |
104 | connect(barset, SIGNAL(clicked(QString,Qt::MouseButtons)), this, SLOT(barsetClicked(QString,Qt::MouseButtons))); |
|
428 | connect(barset, SIGNAL(clicked(QString,Qt::MouseButtons)), this, SLOT(barsetClicked(QString,Qt::MouseButtons))); | |
105 | connect(barset, SIGNAL(valueChanged()), this, SLOT(barsetChanged())); |
|
429 | connect(barset, SIGNAL(valueChanged()), this, SLOT(barsetChanged())); | |
106 | } |
|
430 | } | |
107 | emit restructuredBars(); |
|
431 | emit restructuredBars(); | |
|
432 | */ | |||
108 | } |
|
433 | } | |
109 |
|
434 | |||
110 | /*! |
|
435 | /*! | |
111 | Removes a list of barsets from series. Releases ownership of \a sets. Doesnt delete \a sets. |
|
436 | Removes a list of barsets from series. Releases ownership of \a sets. Doesnt delete \a sets. | |
112 | Disconnects the clicked(QString, Qt::MouseButtons) signal |
|
437 | Disconnects the clicked(QString, Qt::MouseButtons) signal | |
113 | of \a sets from this series |
|
438 | of \a sets from this series | |
114 | */ |
|
439 | */ | |
115 | void QBarSeries::removeBarSets(QList<QBarSet* > sets) |
|
440 | void QBarSeries::removeBarSets(QList<QBarSet* > sets) | |
116 | { |
|
441 | { | |
|
442 | Q_D(QBarSeries); | |||
|
443 | d->removeBarSets(sets); | |||
|
444 | /* | |||
117 | foreach (QBarSet* barset, sets) { |
|
445 | foreach (QBarSet* barset, sets) { | |
118 | disconnect(barset, SIGNAL(clicked(QString,Qt::MouseButtons)), this, SLOT(barsetClicked(QString,Qt::MouseButtons))); |
|
446 | disconnect(barset, SIGNAL(clicked(QString,Qt::MouseButtons)), this, SLOT(barsetClicked(QString,Qt::MouseButtons))); | |
119 | m_internalModel->removeBarSet(barset); |
|
447 | m_internalModel->removeBarSet(barset); | |
120 | } |
|
448 | } | |
121 | emit restructuredBars(); |
|
449 | emit restructuredBars(); | |
|
450 | */ | |||
122 | } |
|
451 | } | |
123 |
|
452 | |||
124 | /*! |
|
453 | /*! | |
125 | Inserts new \a set on the \a i position. |
|
454 | Inserts new \a set on the \a i position. | |
126 | The barset that is currently at this postion is moved to postion i + 1 |
|
455 | The barset that is currently at this postion is moved to postion i + 1 | |
127 | */ |
|
456 | */ | |
128 | void QBarSeries::insertBarSet(int i, QBarSet *set) |
|
457 | void QBarSeries::insertBarSet(int i, QBarSet *set) | |
129 | { |
|
458 | { | |
|
459 | Q_D(QBarSeries); | |||
|
460 | d->insertBarSet(i,set); | |||
|
461 | /* | |||
130 | m_internalModel->insertBarSet(i, set); |
|
462 | m_internalModel->insertBarSet(i, set); | |
131 | // emit barsetChanged(); |
|
463 | // emit barsetChanged(); | |
|
464 | */ | |||
132 | } |
|
465 | } | |
133 |
|
466 | |||
134 | /*! |
|
467 | /*! | |
135 | Inserts new \a category on the \a i position. |
|
468 | Inserts new \a category on the \a i position. | |
136 | The category that is currently at this postion is moved to postion i + 1 |
|
469 | The category that is currently at this postion is moved to postion i + 1 | |
137 | \sa removeCategory() |
|
470 | \sa removeCategory() | |
138 | */ |
|
471 | */ | |
139 | void QBarSeries::insertCategory(int i, QString category) |
|
472 | void QBarSeries::insertCategory(int i, QString category) | |
140 | { |
|
473 | { | |
141 | m_internalModel->insertCategory(i, category); |
|
474 | Q_D(QBarSeries); | |
|
475 | d->insertCategory(i,category); | |||
|
476 | //m_internalModel->insertCategory(i, category); | |||
142 | } |
|
477 | } | |
143 |
|
478 | |||
144 | /*! |
|
479 | /*! | |
145 | Removes the category specified by \a i |
|
480 | Removes the category specified by \a i | |
146 | \sa insertCategory() |
|
481 | \sa insertCategory() | |
147 | */ |
|
482 | */ | |
148 | void QBarSeries::removeCategory(int i) |
|
483 | void QBarSeries::removeCategory(int i) | |
149 | { |
|
484 | { | |
150 | m_internalModel->removeCategory(i); |
|
485 | Q_D(QBarSeries); | |
|
486 | d->removeCategory(i); | |||
|
487 | //m_internalModel->removeCategory(i); | |||
151 | } |
|
488 | } | |
152 |
|
489 | |||
153 | /*! |
|
490 | /*! | |
154 | Returns number of sets in series. |
|
491 | Returns number of sets in series. | |
155 | */ |
|
492 | */ | |
156 | int QBarSeries::barsetCount() const |
|
493 | int QBarSeries::barsetCount() const | |
157 | { |
|
494 | { | |
|
495 | Q_D(const QBarSeries); | |||
|
496 | return d->barsetCount(); | |||
|
497 | /* | |||
158 | // if(m_model) |
|
498 | // if(m_model) | |
159 | // return m_mapBarTop - m_mapBarBottom; |
|
499 | // return m_mapBarTop - m_mapBarBottom; | |
160 | // else |
|
500 | // else | |
161 | return m_internalModel->barsetCount(); |
|
501 | return m_internalModel->barsetCount(); | |
|
502 | */ | |||
162 | } |
|
503 | } | |
163 |
|
504 | |||
164 | /*! |
|
505 | /*! | |
165 | Returns number of categories in series |
|
506 | Returns number of categories in series | |
166 | */ |
|
507 | */ | |
167 | int QBarSeries::categoryCount() const |
|
508 | int QBarSeries::categoryCount() const | |
168 | { |
|
509 | { | |
169 | return m_internalModel->categoryCount(); |
|
510 | Q_D(const QBarSeries); | |
|
511 | return d->categoryCount(); | |||
|
512 | // return m_internalModel->categoryCount(); | |||
170 | } |
|
513 | } | |
171 |
|
514 | |||
172 | /*! |
|
515 | /*! | |
173 | Returns a list of sets in series. Keeps ownership of sets. |
|
516 | Returns a list of sets in series. Keeps ownership of sets. | |
174 | */ |
|
517 | */ | |
175 | QList<QBarSet*> QBarSeries::barSets() const |
|
518 | QList<QBarSet*> QBarSeries::barSets() const | |
176 | { |
|
519 | { | |
177 | return m_internalModel->barSets(); |
|
520 | Q_D(const QBarSeries); | |
|
521 | return d->barSets(); | |||
|
522 | // return m_internalModel->barSets(); | |||
178 | } |
|
523 | } | |
179 |
|
524 | |||
180 | /*! |
|
525 | /*! | |
181 | \internal \a index |
|
526 | \internal \a index | |
182 | */ |
|
527 | */ | |
183 | QBarSet* QBarSeries::barsetAt(int index) |
|
528 | QBarSet* QBarSeries::barsetAt(int index) | |
184 | { |
|
529 | { | |
185 | return m_internalModel->barsetAt(index); |
|
530 | Q_D(QBarSeries); | |
|
531 | return d->barsetAt(index); | |||
|
532 | // return m_internalModel->barsetAt(index); | |||
186 | } |
|
533 | } | |
187 |
|
534 | |||
188 | /*! |
|
535 | /*! | |
189 | \internal \a category |
|
536 | \internal \a category | |
190 | */ |
|
537 | */ | |
191 | QString QBarSeries::categoryName(int category) |
|
538 | QString QBarSeries::categoryName(int category) | |
192 | { |
|
539 | { | |
193 | return m_internalModel->categoryName(category); |
|
540 | Q_D(QBarSeries); | |
|
541 | return d->categoryName(category); | |||
|
542 | // return m_internalModel->categoryName(category); | |||
194 | } |
|
543 | } | |
195 |
|
544 | |||
196 | /*! |
|
545 | /*! | |
197 | Enables or disables tooltip depending on parameter \a enabled. |
|
546 | Enables or disables tooltip depending on parameter \a enabled. | |
198 | Tooltip shows the name of set, when mouse is hovering on top of bar. |
|
547 | Tooltip shows the name of set, when mouse is hovering on top of bar. | |
199 | Calling without parameter \a enabled, enables the tooltip |
|
548 | Calling without parameter \a enabled, enables the tooltip | |
200 | */ |
|
549 | */ | |
201 | void QBarSeries::setToolTipEnabled(bool enabled) |
|
550 | void QBarSeries::setToolTipEnabled(bool enabled) | |
202 | { |
|
551 | { | |
|
552 | Q_D(QBarSeries); | |||
|
553 | d->setToolTipEnabled(enabled); | |||
|
554 | /* | |||
203 | // TODO: what if we add sets after call to this function? Those sets won't have tooltip enabled. |
|
555 | // TODO: what if we add sets after call to this function? Those sets won't have tooltip enabled. | |
204 | if (enabled) { |
|
556 | if (enabled) { | |
205 | for (int i=0; i<m_internalModel->barsetCount(); i++) { |
|
557 | for (int i=0; i<m_internalModel->barsetCount(); i++) { | |
206 | QBarSet *set = m_internalModel->barsetAt(i); |
|
558 | QBarSet *set = m_internalModel->barsetAt(i); | |
207 | connect(set, SIGNAL(showToolTip(QPoint,QString)), this, SIGNAL(showToolTip(QPoint,QString))); |
|
559 | connect(set, SIGNAL(showToolTip(QPoint,QString)), this, SIGNAL(showToolTip(QPoint,QString))); | |
208 | } |
|
560 | } | |
209 | } else { |
|
561 | } else { | |
210 | for (int i=0; i<m_internalModel->barsetCount(); i++) { |
|
562 | for (int i=0; i<m_internalModel->barsetCount(); i++) { | |
211 | QBarSet *set = m_internalModel->barsetAt(i); |
|
563 | QBarSet *set = m_internalModel->barsetAt(i); | |
212 | disconnect(set, SIGNAL(showToolTip(QPoint,QString)), this, SIGNAL(showToolTip(QPoint,QString))); |
|
564 | disconnect(set, SIGNAL(showToolTip(QPoint,QString)), this, SIGNAL(showToolTip(QPoint,QString))); | |
213 | } |
|
565 | } | |
214 | } |
|
566 | } | |
|
567 | */ | |||
215 | } |
|
568 | } | |
216 |
|
569 | |||
217 |
|
570 | |||
218 | /*! |
|
571 | /*! | |
219 | \internal \a category |
|
572 | \internal \a category | |
220 | */ |
|
573 | */ | |
221 | void QBarSeries::barsetClicked(QString category, Qt::MouseButtons button) |
|
574 | void QBarSeries::barsetClicked(QString category, Qt::MouseButtons button) | |
222 | { |
|
575 | { | |
223 | emit clicked(qobject_cast<QBarSet*>(sender()), category, button); |
|
576 | Q_D(QBarSeries); | |
|
577 | d->barsetClicked(category,button); | |||
|
578 | // emit clicked(qobject_cast<QBarSet*>(sender()), category, button); | |||
224 | } |
|
579 | } | |
225 |
|
580 | |||
226 | /*! |
|
581 | /*! | |
227 | \internal |
|
582 | \internal | |
228 | */ |
|
583 | */ | |
229 | qreal QBarSeries::min() |
|
584 | qreal QBarSeries::min() | |
230 | { |
|
585 | { | |
231 | return m_internalModel->min(); |
|
586 | Q_D(QBarSeries); | |
|
587 | return d->min(); | |||
|
588 | //return m_internalModel->min(); | |||
232 | } |
|
589 | } | |
233 |
|
590 | |||
234 | /*! |
|
591 | /*! | |
235 | \internal |
|
592 | \internal | |
236 | */ |
|
593 | */ | |
237 | qreal QBarSeries::max() |
|
594 | qreal QBarSeries::max() | |
238 | { |
|
595 | { | |
239 | return m_internalModel->max(); |
|
596 | Q_D(QBarSeries); | |
|
597 | return d->max(); | |||
|
598 | // return m_internalModel->max(); | |||
240 | } |
|
599 | } | |
241 |
|
600 | |||
242 | /*! |
|
601 | /*! | |
243 | \internal \a set \a category |
|
602 | \internal \a set \a category | |
244 | */ |
|
603 | */ | |
245 | qreal QBarSeries::valueAt(int set, int category) |
|
604 | qreal QBarSeries::valueAt(int set, int category) | |
246 | { |
|
605 | { | |
247 | return m_internalModel->valueAt(set, category); |
|
606 | Q_D(QBarSeries); | |
|
607 | return d->valueAt(set,category); | |||
|
608 | // return m_internalModel->valueAt(set, category); | |||
248 | } |
|
609 | } | |
249 |
|
610 | |||
250 | /*! |
|
611 | /*! | |
251 | \internal \a set \a category |
|
612 | \internal \a set \a category | |
252 | */ |
|
613 | */ | |
253 | qreal QBarSeries::percentageAt(int set, int category) |
|
614 | qreal QBarSeries::percentageAt(int set, int category) | |
254 | { |
|
615 | { | |
255 | return m_internalModel->percentageAt(set, category); |
|
616 | Q_D(QBarSeries); | |
|
617 | return d->percentageAt(set,category); | |||
|
618 | // return m_internalModel->percentageAt(set, category); | |||
256 | } |
|
619 | } | |
257 |
|
620 | |||
258 | /*! |
|
621 | /*! | |
259 | \internal \a category |
|
622 | \internal \a category | |
260 | */ |
|
623 | */ | |
261 | qreal QBarSeries::categorySum(int category) |
|
624 | qreal QBarSeries::categorySum(int category) | |
262 | { |
|
625 | { | |
263 | return m_internalModel->categorySum(category); |
|
626 | Q_D(QBarSeries); | |
|
627 | return d->categorySum(category); | |||
|
628 | // return m_internalModel->categorySum(category); | |||
264 | } |
|
629 | } | |
265 |
|
630 | |||
266 | /*! |
|
631 | /*! | |
267 | \internal \a category |
|
632 | \internal \a category | |
268 | */ |
|
633 | */ | |
269 | qreal QBarSeries::absoluteCategorySum(int category) |
|
634 | qreal QBarSeries::absoluteCategorySum(int category) | |
270 | { |
|
635 | { | |
271 | return m_internalModel->absoluteCategorySum(category); |
|
636 | Q_D(QBarSeries); | |
|
637 | return d->absoluteCategorySum(category); | |||
|
638 | // return m_internalModel->absoluteCategorySum(category); | |||
272 | } |
|
639 | } | |
273 |
|
640 | |||
274 | /*! |
|
641 | /*! | |
275 | \internal |
|
642 | \internal | |
276 | */ |
|
643 | */ | |
277 | qreal QBarSeries::maxCategorySum() |
|
644 | qreal QBarSeries::maxCategorySum() | |
278 | { |
|
645 | { | |
279 | return m_internalModel->maxCategorySum(); |
|
646 | Q_D(QBarSeries); | |
|
647 | return d->maxCategorySum(); | |||
|
648 | // return m_internalModel->maxCategorySum(); | |||
280 | } |
|
649 | } | |
281 |
|
650 | |||
282 | /*! |
|
651 | /*! | |
283 | \internal |
|
652 | \internal | |
284 | */ |
|
653 | */ | |
285 | BarChartModel& QBarSeries::modelInternal() |
|
654 | BarChartModel& QBarSeries::modelInternal() | |
286 | { |
|
655 | { | |
287 | return *m_internalModel; |
|
656 | Q_D(QBarSeries); | |
|
657 | return d->modelInternal(); | |||
|
658 | // return *m_internalModel; | |||
288 | } |
|
659 | } | |
289 |
|
660 | |||
290 | /*! |
|
661 | /*! | |
291 | \fn bool QBarSeries::setModel(QAbstractItemModel *model) |
|
662 | \fn bool QBarSeries::setModel(QAbstractItemModel *model) | |
292 | Sets the \a model to be used as a data source |
|
663 | Sets the \a model to be used as a data source | |
293 | */ |
|
664 | */ | |
294 | bool QBarSeries::setModel(QAbstractItemModel *model) |
|
665 | bool QBarSeries::setModel(QAbstractItemModel *model) | |
295 | { |
|
666 | { | |
|
667 | Q_D(QBarSeries); | |||
|
668 | return d->setModel(model); | |||
|
669 | /* | |||
296 | // disconnect signals from old model |
|
670 | // disconnect signals from old model | |
297 | if(m_model) |
|
671 | if(m_model) | |
298 | { |
|
672 | { | |
299 | disconnect(m_model, 0, this, 0); |
|
673 | disconnect(m_model, 0, this, 0); | |
300 | m_mapCategories = -1; |
|
674 | m_mapCategories = -1; | |
301 | m_mapBarBottom = -1; |
|
675 | m_mapBarBottom = -1; | |
302 | m_mapBarTop = -1; |
|
676 | m_mapBarTop = -1; | |
303 | m_mapFirst = 0; |
|
677 | m_mapFirst = 0; | |
304 | m_mapCount = 0; |
|
678 | m_mapCount = 0; | |
305 | m_mapOrientation = Qt::Vertical; |
|
679 | m_mapOrientation = Qt::Vertical; | |
306 | } |
|
680 | } | |
307 |
|
|
681 | ||
308 | // set new model |
|
682 | // set new model | |
309 | if(model) |
|
683 | if(model) | |
310 | { |
|
684 | { | |
311 | m_model = model; |
|
685 | m_model = model; | |
312 | return true; |
|
686 | return true; | |
313 | } |
|
687 | } | |
314 | else |
|
688 | else | |
315 | { |
|
689 | { | |
316 | m_model = 0; |
|
690 | m_model = 0; | |
317 | return false; |
|
691 | return false; | |
318 | } |
|
692 | } | |
|
693 | */ | |||
319 | } |
|
694 | } | |
320 |
|
695 | |||
321 | /*! |
|
696 | /*! | |
322 | \fn bool QBarSeries::setModelMapping(int categories, int bottomBoundry, int topBoundry, Qt::Orientation orientation) |
|
697 | \fn bool QBarSeries::setModelMapping(int categories, int bottomBoundry, int topBoundry, Qt::Orientation orientation) | |
323 | Sets column/row specified by \a categories to be used as a list of bar series categories. |
|
698 | Sets column/row specified by \a categories to be used as a list of bar series categories. | |
324 | Parameter \a bottomBoundry indicates the column/row where the first bar set is located in the model. |
|
699 | Parameter \a bottomBoundry indicates the column/row where the first bar set is located in the model. | |
325 | Parameter \a topBoundry indicates the column/row where the last bar set is located in the model. |
|
700 | Parameter \a topBoundry indicates the column/row where the last bar set is located in the model. | |
326 | All the columns/rows inbetween those two values are also used as data for bar sets. |
|
701 | All the columns/rows inbetween those two values are also used as data for bar sets. | |
327 | The \a orientation paramater specifies whether the data is in columns or in rows. |
|
702 | The \a orientation paramater specifies whether the data is in columns or in rows. | |
328 | */ |
|
703 | */ | |
329 | void QBarSeries::setModelMapping(int categories, int bottomBoundry, int topBoundry, Qt::Orientation orientation) |
|
704 | void QBarSeries::setModelMapping(int categories, int bottomBoundary, int topBoundary, Qt::Orientation orientation) | |
330 | { |
|
705 | { | |
|
706 | Q_D(QBarSeries); | |||
|
707 | d->setModelMapping(categories,bottomBoundary,topBoundary,orientation); | |||
|
708 | /* | |||
331 | if (!m_model) |
|
709 | if (!m_model) | |
332 | return; |
|
710 | return; | |
333 |
|
|
711 | ||
334 | m_mapCategories = categories; |
|
712 | m_mapCategories = categories; | |
335 | m_mapBarBottom = bottomBoundry; |
|
713 | m_mapBarBottom = bottomBoundry; | |
336 | m_mapBarTop = topBoundry; |
|
714 | m_mapBarTop = topBoundry; | |
337 |
|
|
715 | // m_mapFirst = 1; | |
338 | m_mapOrientation = orientation; |
|
716 | m_mapOrientation = orientation; | |
339 |
|
|
717 | ||
340 | // connect the signals |
|
718 | // connect the signals | |
341 | if (m_mapOrientation == Qt::Vertical) { |
|
719 | if (m_mapOrientation == Qt::Vertical) { | |
342 | m_mapCount = m_model->rowCount() - m_mapFirst; |
|
720 | m_mapCount = m_model->rowCount() - m_mapFirst; | |
343 | connect(m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)), |
|
721 | connect(m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)), | |
344 | this, SLOT(modelUpdated(QModelIndex, QModelIndex))); |
|
722 | this, SLOT(modelUpdated(QModelIndex, QModelIndex))); | |
345 | connect(m_model,SIGNAL(rowsInserted(QModelIndex, int, int)), |
|
723 | connect(m_model,SIGNAL(rowsInserted(QModelIndex, int, int)), | |
346 | this, SLOT(modelDataAdded(QModelIndex,int,int))); |
|
724 | this, SLOT(modelDataAdded(QModelIndex,int,int))); | |
347 | connect(m_model, SIGNAL(rowsRemoved(QModelIndex, int, int)), |
|
725 | connect(m_model, SIGNAL(rowsRemoved(QModelIndex, int, int)), | |
348 | this, SLOT(modelDataRemoved(QModelIndex,int,int))); |
|
726 | this, SLOT(modelDataRemoved(QModelIndex,int,int))); | |
349 | } else { |
|
727 | } else { | |
350 | m_mapCount = m_model->columnCount() - m_mapFirst; |
|
728 | m_mapCount = m_model->columnCount() - m_mapFirst; | |
351 | connect(m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)), |
|
729 | connect(m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)), | |
352 | this, SLOT(modelUpdated(QModelIndex, QModelIndex))); |
|
730 | this, SLOT(modelUpdated(QModelIndex, QModelIndex))); | |
353 | connect(m_model,SIGNAL(columnsInserted(QModelIndex, int, int)), |
|
731 | connect(m_model,SIGNAL(columnsInserted(QModelIndex, int, int)), | |
354 | this, SLOT(modelDataAdded(QModelIndex,int,int))); |
|
732 | this, SLOT(modelDataAdded(QModelIndex,int,int))); | |
355 | connect(m_model, SIGNAL(columnsRemoved(QModelIndex, int, int)), |
|
733 | connect(m_model, SIGNAL(columnsRemoved(QModelIndex, int, int)), | |
356 | this, SLOT(modelDataRemoved(QModelIndex,int,int))); |
|
734 | this, SLOT(modelDataRemoved(QModelIndex,int,int))); | |
357 | } |
|
735 | } | |
358 |
|
|
736 | ||
359 | // create the initial bars |
|
737 | // create the initial bars | |
360 | delete m_internalModel; |
|
738 | delete m_internalModel; | |
361 | if (m_mapOrientation == Qt::Vertical) { |
|
739 | if (m_mapOrientation == Qt::Vertical) { | |
362 | QStringList categories; |
|
740 | QStringList categories; | |
363 | for (int k = m_mapFirst; k < m_mapFirst + m_mapCount; k++) |
|
741 | for (int k = m_mapFirst; k < m_mapFirst + m_mapCount; k++) | |
364 | categories << m_model->data(m_model->index(k, m_mapCategories), Qt::DisplayRole).toString(); |
|
742 | categories << m_model->data(m_model->index(k, m_mapCategories), Qt::DisplayRole).toString(); | |
365 | m_internalModel = new BarChartModel(categories, this); |
|
743 | m_internalModel = new BarChartModel(categories, this); | |
366 |
|
|
744 | ||
367 | for (int i = m_mapBarBottom; i <= m_mapBarTop; i++) { |
|
745 | for (int i = m_mapBarBottom; i <= m_mapBarTop; i++) { | |
368 | QBarSet* barSet = new QBarSet(QString("Column: %1").arg(i + 1)); |
|
746 | QBarSet* barSet = new QBarSet(QString("Column: %1").arg(i + 1)); | |
369 | for(int m = m_mapFirst; m < m_mapFirst + m_mapCount; m++) |
|
747 | for(int m = m_mapFirst; m < m_mapFirst + m_mapCount; m++) | |
370 | *barSet << m_model->data(m_model->index(m, i), Qt::DisplayRole).toDouble(); |
|
748 | *barSet << m_model->data(m_model->index(m, i), Qt::DisplayRole).toDouble(); | |
371 | appendBarSet(barSet); |
|
749 | appendBarSet(barSet); | |
372 | } |
|
750 | } | |
373 | } else { |
|
751 | } else { | |
374 | QStringList categories; |
|
752 | QStringList categories; | |
375 | for (int k = m_mapFirst; k < m_mapFirst + m_mapCount; k++) |
|
753 | for (int k = m_mapFirst; k < m_mapFirst + m_mapCount; k++) | |
376 | categories << m_model->data(m_model->index(m_mapCategories, k), Qt::DisplayRole).toString(); |
|
754 | categories << m_model->data(m_model->index(m_mapCategories, k), Qt::DisplayRole).toString(); | |
377 | m_internalModel = new BarChartModel(categories, this); |
|
755 | m_internalModel = new BarChartModel(categories, this); | |
378 |
|
|
756 | ||
379 | for (int i = m_mapBarBottom; i <= m_mapBarTop; i++) { |
|
757 | for (int i = m_mapBarBottom; i <= m_mapBarTop; i++) { | |
380 | QBarSet* barSet = new QBarSet(QString("Row: %1").arg(i + 1)); |
|
758 | QBarSet* barSet = new QBarSet(QString("Row: %1").arg(i + 1)); | |
381 | for(int m = m_mapFirst; m < m_mapFirst + m_mapCount; m++) |
|
759 | for(int m = m_mapFirst; m < m_mapFirst + m_mapCount; m++) | |
382 | *barSet << m_model->data(m_model->index(i, m), Qt::DisplayRole).toDouble(); |
|
760 | *barSet << m_model->data(m_model->index(i, m), Qt::DisplayRole).toDouble(); | |
383 | appendBarSet(barSet); |
|
761 | appendBarSet(barSet); | |
384 | } |
|
762 | } | |
385 | } |
|
763 | } | |
|
764 | */ | |||
386 | } |
|
765 | } | |
387 |
|
766 | |||
388 | /*! |
|
767 | /*! | |
389 | \internal |
|
768 | \internal | |
390 | */ |
|
769 | */ | |
391 | void QBarSeries::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight) |
|
770 | void QBarSeries::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight) | |
392 | { |
|
771 | { | |
|
772 | Q_D(QBarSeries); | |||
|
773 | d->modelUpdated(topLeft,bottomRight); | |||
|
774 | /* | |||
393 | Q_UNUSED(bottomRight) |
|
775 | Q_UNUSED(bottomRight) | |
394 |
|
|
776 | ||
395 | if (m_mapOrientation == Qt::Vertical) |
|
777 | if (m_mapOrientation == Qt::Vertical) | |
396 | { |
|
778 | { | |
397 | // model update is relevant to BarSeries if the change was made to the part of the model that was mapped to BarSeries |
|
779 | // model update is relevant to BarSeries if the change was made to the part of the model that was mapped to BarSeries | |
398 | if (topLeft.column() >= m_mapBarBottom && topLeft.column() <= m_mapBarTop && topLeft.row() >= m_mapFirst && topLeft.row() < m_mapFirst + m_mapCount) |
|
780 | if (topLeft.column() >= m_mapBarBottom && topLeft.column() <= m_mapBarTop && topLeft.row() >= m_mapFirst && topLeft.row() < m_mapFirst + m_mapCount) | |
399 | barsetAt(topLeft.column() - m_mapBarBottom)->setValue(topLeft.row() - m_mapFirst, m_model->data(topLeft, Qt::DisplayRole).toDouble()); |
|
781 | barsetAt(topLeft.column() - m_mapBarBottom)->setValue(topLeft.row() - m_mapFirst, m_model->data(topLeft, Qt::DisplayRole).toDouble()); | |
400 | } |
|
782 | } | |
401 | else |
|
783 | else | |
402 | { |
|
784 | { | |
403 | // model update is relevant to BarSeries if the change was made to the part of the model that was mapped to BarSeries |
|
785 | // model update is relevant to BarSeries if the change was made to the part of the model that was mapped to BarSeries | |
404 | if (topLeft.row() >= m_mapBarBottom && topLeft.row() <= m_mapBarTop && topLeft.column() >= m_mapFirst && topLeft.column() < m_mapFirst + m_mapCount) |
|
786 | if (topLeft.row() >= m_mapBarBottom && topLeft.row() <= m_mapBarTop && topLeft.column() >= m_mapFirst && topLeft.column() < m_mapFirst + m_mapCount) | |
405 | barsetAt(topLeft.row() - m_mapBarBottom)->setValue(topLeft.column() - m_mapFirst, m_model->data(topLeft, Qt::DisplayRole).toDouble()); |
|
787 | barsetAt(topLeft.row() - m_mapBarBottom)->setValue(topLeft.column() - m_mapFirst, m_model->data(topLeft, Qt::DisplayRole).toDouble()); | |
406 | } |
|
788 | } | |
|
789 | */ | |||
407 | } |
|
790 | } | |
408 |
|
791 | |||
409 | /*! |
|
792 | /*! | |
410 | \internal |
|
793 | \internal | |
411 | */ |
|
794 | */ | |
412 |
void QBarSeries::modelDataAdded(QModelIndex |
|
795 | void QBarSeries::modelDataAdded(QModelIndex parent, int start, int end) | |
413 | { |
|
796 | { | |
|
797 | Q_D(QBarSeries); | |||
|
798 | d->modelDataAdded(parent,start,end); | |||
|
799 | /* | |||
414 | if (m_mapOrientation == Qt::Vertical) { |
|
800 | if (m_mapOrientation == Qt::Vertical) { | |
415 | insertCategory(start - m_mapFirst, QString("Row: %1").arg(start + 1)); |
|
801 | insertCategory(start - m_mapFirst, QString("Row: %1").arg(start + 1)); | |
416 | for (int i = 0; i <= m_mapBarTop - m_mapBarBottom; i++) { |
|
802 | for (int i = 0; i <= m_mapBarTop - m_mapBarBottom; i++) { | |
417 | barsetAt(i)->insertValue(start - m_mapFirst, m_model->data(m_model->index(start, i), Qt::DisplayRole).toDouble()); |
|
803 | barsetAt(i)->insertValue(start - m_mapFirst, m_model->data(m_model->index(start, i), Qt::DisplayRole).toDouble()); | |
418 | } |
|
804 | } | |
419 | } else { |
|
805 | } else { | |
420 | insertCategory(start - m_mapFirst, QString("Column: %1").arg(start + 1)); |
|
806 | insertCategory(start - m_mapFirst, QString("Column: %1").arg(start + 1)); | |
421 | for (int i = 0; i <= m_mapBarTop - m_mapBarBottom; i++) { |
|
807 | for (int i = 0; i <= m_mapBarTop - m_mapBarBottom; i++) { | |
422 | barsetAt(i)->insertValue(start - m_mapFirst, m_model->data(m_model->index(i, start), Qt::DisplayRole).toDouble()); |
|
808 | barsetAt(i)->insertValue(start - m_mapFirst, m_model->data(m_model->index(i, start), Qt::DisplayRole).toDouble()); | |
423 | } |
|
809 | } | |
424 | } |
|
810 | } | |
425 | emit restructuredBars(); |
|
811 | emit restructuredBars(); | |
|
812 | */ | |||
426 | } |
|
813 | } | |
427 |
|
814 | |||
428 | /*! |
|
815 | /*! | |
429 | \internal |
|
816 | \internal | |
430 | */ |
|
817 | */ | |
431 | void QBarSeries::modelDataRemoved(QModelIndex parent, int start, int end) |
|
818 | void QBarSeries::modelDataRemoved(QModelIndex parent, int start, int end) | |
432 | { |
|
819 | { | |
|
820 | Q_D(QBarSeries); | |||
|
821 | d->modelDataRemoved(parent,start,end); | |||
|
822 | /* | |||
433 | Q_UNUSED(parent) |
|
823 | Q_UNUSED(parent) | |
434 | Q_UNUSED(end) |
|
824 | Q_UNUSED(end) | |
435 |
|
|
825 | ||
436 | removeCategory(start - m_mapFirst); |
|
826 | removeCategory(start - m_mapFirst); | |
437 | for (int i = 0; i <= m_mapBarTop - m_mapBarBottom; i++) |
|
827 | for (int i = 0; i <= m_mapBarTop - m_mapBarBottom; i++) | |
438 | { |
|
828 | { | |
439 | barsetAt(i)->removeValue(start - m_mapFirst); |
|
829 | barsetAt(i)->removeValue(start - m_mapFirst); | |
440 | } |
|
830 | } | |
441 | emit restructuredBars(); |
|
831 | emit restructuredBars(); | |
|
832 | */ | |||
442 | } |
|
833 | } | |
443 |
|
834 | |||
444 | void QBarSeries::barsetChanged() |
|
835 | void QBarSeries::barsetChanged() | |
445 | { |
|
836 | { | |
446 | emit updatedBars(); |
|
837 | Q_D(QBarSeries); | |
|
838 | d->barsetChanged(); | |||
|
839 | // emit updatedBars(); | |||
447 | } |
|
840 | } | |
448 |
|
841 | |||
449 | QBarCategories QBarSeries::categories() const |
|
842 | QBarCategories QBarSeries::categories() const | |
450 | { |
|
843 | { | |
|
844 | Q_D(const QBarSeries); | |||
|
845 | return d->categories(); | |||
|
846 | /* | |||
451 | QBarCategories categories; |
|
847 | QBarCategories categories; | |
452 | int count = m_internalModel->categoryCount(); |
|
848 | int count = m_internalModel->categoryCount(); | |
453 | for (int i=1; i <= count; i++) { |
|
849 | for (int i=1; i <= count; i++) { | |
454 | categories.insert(i, m_internalModel->categoryName(i - 1)); |
|
850 | categories.insert(i, m_internalModel->categoryName(i - 1)); | |
455 | } |
|
851 | } | |
456 | return categories; |
|
852 | return categories; | |
|
853 | */ | |||
457 | } |
|
854 | } | |
458 |
|
855 | |||
459 | /*! |
|
856 | /*! | |
460 | Sets the visibility of labels in series to \a visible |
|
857 | Sets the visibility of labels in series to \a visible | |
461 | */ |
|
858 | */ | |
462 | void QBarSeries::setLabelsVisible(bool visible) |
|
859 | void QBarSeries::setLabelsVisible(bool visible) | |
463 | { |
|
860 | { | |
|
861 | Q_D(QBarSeries); | |||
|
862 | d->setLabelsVisible(visible); | |||
|
863 | /* | |||
464 | foreach (QBarSet* s, barSets()) { |
|
864 | foreach (QBarSet* s, barSets()) { | |
465 | s->setLabelsVisible(visible); |
|
865 | s->setLabelsVisible(visible); | |
466 | } |
|
866 | } | |
|
867 | */ | |||
467 | } |
|
868 | } | |
468 |
|
869 | |||
469 |
|
870 | |||
470 | #include "moc_qbarseries.cpp" |
|
871 | #include "moc_qbarseries.cpp" | |
|
872 | #include "moc_qbarseriesprivate_p.cpp" | |||
471 |
|
873 | |||
472 | QTCOMMERCIALCHART_END_NAMESPACE |
|
874 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,119 +1,126 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #ifndef BARSERIES_H |
|
21 | #ifndef BARSERIES_H | |
22 | #define BARSERIES_H |
|
22 | #define BARSERIES_H | |
23 |
|
23 | |||
24 | #include <qseries.h> |
|
24 | #include <qseries.h> | |
25 | #include <QStringList> |
|
25 | #include <QStringList> | |
26 |
|
26 | |||
27 | class QModelIndex; |
|
27 | class QModelIndex; | |
28 |
|
28 | |||
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
30 |
|
30 | |||
31 | typedef QStringList QBarCategories; |
|
31 | typedef QStringList QBarCategories; | |
32 |
|
32 | |||
33 | class QBarSet; |
|
33 | class QBarSet; | |
34 | class BarChartModel; |
|
34 | class BarChartModel; | |
35 | class BarCategory; |
|
35 | class BarCategory; | |
|
36 | class QBarSeriesPrivate; | |||
36 |
|
37 | |||
37 | // Container for series |
|
38 | // Container for series | |
38 | class QTCOMMERCIALCHART_EXPORT QBarSeries : public QSeries |
|
39 | class QTCOMMERCIALCHART_EXPORT QBarSeries : public QSeries | |
39 | { |
|
40 | { | |
40 | Q_OBJECT |
|
41 | Q_OBJECT | |
41 | public: |
|
42 | public: | |
42 | QBarSeries(QStringList categories, QObject *parent = 0); |
|
43 | QBarSeries(QStringList categories, QObject *parent = 0); | |
43 |
|
44 | |||
44 | virtual QSeriesType type() const { return QSeries::SeriesTypeBar; } |
|
45 | virtual QSeriesType type() const { return QSeries::SeriesTypeBar; } | |
45 |
|
46 | |||
46 | void appendBarSet(QBarSet *set); // Takes ownership of set |
|
47 | void appendBarSet(QBarSet *set); // Takes ownership of set | |
47 | void removeBarSet(QBarSet *set); // Releases ownership, doesn't delete set |
|
48 | void removeBarSet(QBarSet *set); // Releases ownership, doesn't delete set | |
48 | void appendBarSets(QList<QBarSet* > sets); |
|
49 | void appendBarSets(QList<QBarSet* > sets); | |
49 | void removeBarSets(QList<QBarSet* > sets); |
|
50 | void removeBarSets(QList<QBarSet* > sets); | |
50 | void insertBarSet(int i, QBarSet *set); |
|
51 | void insertBarSet(int i, QBarSet *set); | |
51 | void insertCategory(int i, QString category); |
|
52 | void insertCategory(int i, QString category); | |
52 | void removeCategory(int i); |
|
53 | void removeCategory(int i); | |
53 | int barsetCount() const; |
|
54 | int barsetCount() const; | |
54 | int categoryCount() const; |
|
55 | int categoryCount() const; | |
55 | QList<QBarSet*> barSets() const; |
|
56 | QList<QBarSet*> barSets() const; | |
56 | QBarCategories categories() const; |
|
57 | QBarCategories categories() const; | |
57 |
|
58 | |||
58 | void setLabelsVisible(bool visible = true); |
|
59 | void setLabelsVisible(bool visible = true); | |
59 |
|
60 | |||
60 | bool setModel(QAbstractItemModel *model); |
|
61 | bool setModel(QAbstractItemModel *model); | |
61 |
void setModelMapping(int categories, int bottomBoundry, int topBoundry, Qt::Orientation orientation = Qt::Vertical); |
|
62 | void setModelMapping(int categories, int bottomBoundary, int topBoundary, Qt::Orientation orientation = Qt::Vertical); | |
62 |
|
63 | |||
63 | public: |
|
64 | public: | |
64 | // TODO: Functions below this are not part of api and will be moved |
|
65 | // TODO: Functions below this are not part of api and will be moved | |
65 | // to private implementation, when we start using it |
|
66 | // to private implementation, when we start using it | |
66 | // TODO: TO PIMPL ---> |
|
67 | // TODO: TO PIMPL ---> | |
67 | QBarSet* barsetAt(int index); |
|
68 | QBarSet* barsetAt(int index); | |
68 | QString categoryName(int category); |
|
69 | QString categoryName(int category); | |
69 | qreal min(); |
|
70 | qreal min(); | |
70 | qreal max(); |
|
71 | qreal max(); | |
71 | qreal valueAt(int set, int category); |
|
72 | qreal valueAt(int set, int category); | |
72 | qreal percentageAt(int set, int category); |
|
73 | qreal percentageAt(int set, int category); | |
73 | qreal categorySum(int category); |
|
74 | qreal categorySum(int category); | |
74 | qreal absoluteCategorySum(int category); |
|
75 | qreal absoluteCategorySum(int category); | |
75 | qreal maxCategorySum(); |
|
76 | qreal maxCategorySum(); | |
76 | BarChartModel& modelInternal(); |
|
77 | BarChartModel& modelInternal(); | |
77 | // <--- TO PIMPL |
|
78 | // <--- TO PIMPL | |
78 |
|
79 | |||
79 | Q_SIGNALS: |
|
80 | Q_SIGNALS: | |
80 | void clicked(QBarSet *barset, QString category, Qt::MouseButtons button); // Up to user of api, what to do with these signals |
|
81 | void clicked(QBarSet *barset, QString category, Qt::MouseButtons button); // Up to user of api, what to do with these signals | |
81 | void selected(); |
|
82 | void selected(); | |
82 | // |
|
83 | // | |
83 | void updatedBars(); |
|
84 | void updatedBars(); | |
84 | void restructuredBars(); |
|
85 | void restructuredBars(); | |
85 |
|
86 | |||
86 | // TODO: internal signals, these to private implementation. |
|
87 | // TODO: internal signals, these to private implementation. | |
87 | // TODO: TO PIMPL ---> |
|
88 | // TODO: TO PIMPL ---> | |
88 | void showToolTip(QPoint pos, QString tip); |
|
89 | // void showToolTip(QPoint pos, QString tip); | |
89 | // <--- TO PIMPL |
|
90 | // <--- TO PIMPL | |
90 |
|
91 | |||
91 | public Q_SLOTS: |
|
92 | public Q_SLOTS: | |
92 | void setToolTipEnabled(bool enabled = true); // enables tooltips |
|
93 | void setToolTipEnabled(bool enabled = true); // enables tooltips | |
93 |
|
94 | |||
94 | // TODO: TO PIMPL ---> |
|
95 | // TODO: TO PIMPL ---> | |
95 | void barsetClicked(QString category, Qt::MouseButtons button); |
|
96 | void barsetClicked(QString category, Qt::MouseButtons button); | |
96 | // <--- TO PIMPL |
|
97 | // <--- TO PIMPL | |
97 |
|
98 | |||
98 | private Q_SLOTS: |
|
99 | private Q_SLOTS: | |
99 | // slots for updating bars when data in model changes |
|
100 | // slots for updating bars when data in model changes | |
100 | void modelUpdated(QModelIndex topLeft, QModelIndex bottomRight); |
|
101 | void modelUpdated(QModelIndex topLeft, QModelIndex bottomRight); | |
101 | void modelDataAdded(QModelIndex parent, int start, int end); |
|
102 | void modelDataAdded(QModelIndex parent, int start, int end); | |
102 | void modelDataRemoved(QModelIndex parent, int start, int end); |
|
103 | void modelDataRemoved(QModelIndex parent, int start, int end); | |
103 | void barsetChanged(); |
|
104 | void barsetChanged(); | |
104 |
|
105 | |||
105 | protected: |
|
106 | protected: | |
|
107 | QBarSeriesPrivate * const d_ptr; | |||
|
108 | Q_DECLARE_PRIVATE(QBarSeries) | |||
|
109 | Q_DISABLE_COPY(QBarSeries) | |||
|
110 | ||||
|
111 | /* | |||
106 | BarChartModel *m_internalModel; // TODO: this may change... current "2 models" situation doesn't look good. |
|
112 | BarChartModel *m_internalModel; // TODO: this may change... current "2 models" situation doesn't look good. | |
107 |
|
|
113 | ||
108 |
|
|
114 | // QAbstractItemModel* m_model; | |
109 | int m_mapCategories; |
|
115 | int m_mapCategories; | |
110 | int m_mapBarBottom; |
|
116 | int m_mapBarBottom; | |
111 | int m_mapBarTop; |
|
117 | int m_mapBarTop; | |
112 | int m_mapFirst; |
|
118 | int m_mapFirst; | |
113 | int m_mapCount; |
|
119 | int m_mapCount; | |
114 | Qt::Orientation m_mapOrientation; |
|
120 | Qt::Orientation m_mapOrientation; | |
|
121 | */ | |||
115 | }; |
|
122 | }; | |
116 |
|
123 | |||
117 | QTCOMMERCIALCHART_END_NAMESPACE |
|
124 | QTCOMMERCIALCHART_END_NAMESPACE | |
118 |
|
125 | |||
119 | #endif // BARSERIES_H |
|
126 | #endif // BARSERIES_H |
@@ -1,279 +1,467 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "qbarset.h" |
|
21 | #include "qbarset.h" | |
22 | #include <QDebug> |
|
22 | #include "qbarsetprivate_p.h" | |
|
23 | //#include <QDebug> | |||
23 | #include <QToolTip> |
|
24 | #include <QToolTip> | |
24 |
|
25 | |||
25 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
26 |
|
27 | |||
|
28 | ||||
|
29 | QBarSetPrivate::QBarSetPrivate(QString name, QBarSet *parent) : QObject(parent), | |||
|
30 | q_ptr(parent), | |||
|
31 | m_name(name), | |||
|
32 | m_labelsVisible(false) | |||
|
33 | { | |||
|
34 | ||||
|
35 | } | |||
|
36 | ||||
|
37 | QBarSetPrivate::~QBarSetPrivate() | |||
|
38 | { | |||
|
39 | ||||
|
40 | } | |||
|
41 | ||||
|
42 | void QBarSetPrivate::setName(QString name) | |||
|
43 | { | |||
|
44 | m_name = name; | |||
|
45 | } | |||
|
46 | ||||
|
47 | QString QBarSetPrivate::name() const | |||
|
48 | { | |||
|
49 | return m_name; | |||
|
50 | } | |||
|
51 | ||||
|
52 | QBarSetPrivate& QBarSetPrivate::operator << (const qreal &value) | |||
|
53 | { | |||
|
54 | m_values.append(value); | |||
|
55 | emit structureChanged(); | |||
|
56 | return *this; | |||
|
57 | } | |||
|
58 | ||||
|
59 | void QBarSetPrivate::insertValue(int i, qreal value) | |||
|
60 | { | |||
|
61 | m_values.insert(i, value); | |||
|
62 | } | |||
|
63 | ||||
|
64 | void QBarSetPrivate::removeValue(int i) | |||
|
65 | { | |||
|
66 | m_values.removeAt(i); | |||
|
67 | } | |||
|
68 | ||||
|
69 | int QBarSetPrivate::count() const | |||
|
70 | { | |||
|
71 | return m_values.count(); | |||
|
72 | } | |||
|
73 | ||||
|
74 | qreal QBarSetPrivate::valueAt(int index) const | |||
|
75 | { | |||
|
76 | return m_values.at(index); | |||
|
77 | } | |||
|
78 | ||||
|
79 | void QBarSetPrivate::setValue(int index, qreal value) | |||
|
80 | { | |||
|
81 | m_values.replace(index,value); | |||
|
82 | emit valueChanged(); | |||
|
83 | } | |||
|
84 | ||||
|
85 | qreal QBarSetPrivate::sum() const | |||
|
86 | { | |||
|
87 | qreal sum(0); | |||
|
88 | for (int i=0; i < m_values.count(); i++) { | |||
|
89 | sum += m_values.at(i); | |||
|
90 | } | |||
|
91 | return sum; | |||
|
92 | } | |||
|
93 | ||||
|
94 | void QBarSetPrivate::setPen(const QPen &pen) | |||
|
95 | { | |||
|
96 | m_pen = pen; | |||
|
97 | emit valueChanged(); | |||
|
98 | } | |||
|
99 | ||||
|
100 | QPen QBarSetPrivate::pen() const | |||
|
101 | { | |||
|
102 | return m_pen; | |||
|
103 | } | |||
|
104 | ||||
|
105 | void QBarSetPrivate::setBrush(const QBrush &brush) | |||
|
106 | { | |||
|
107 | m_brush = brush; | |||
|
108 | emit valueChanged(); | |||
|
109 | } | |||
|
110 | ||||
|
111 | QBrush QBarSetPrivate::brush() const | |||
|
112 | { | |||
|
113 | return m_brush; | |||
|
114 | } | |||
|
115 | ||||
|
116 | void QBarSetPrivate::setLabelPen(const QPen &pen) | |||
|
117 | { | |||
|
118 | m_labelPen = pen; | |||
|
119 | emit valueChanged(); | |||
|
120 | } | |||
|
121 | ||||
|
122 | QPen QBarSetPrivate::labelPen() const | |||
|
123 | { | |||
|
124 | return m_labelPen; | |||
|
125 | } | |||
|
126 | ||||
|
127 | void QBarSetPrivate::setLabelBrush(const QBrush &brush) | |||
|
128 | { | |||
|
129 | m_labelBrush = brush; | |||
|
130 | emit valueChanged(); | |||
|
131 | } | |||
|
132 | ||||
|
133 | QBrush QBarSetPrivate::labelBrush() const | |||
|
134 | { | |||
|
135 | return m_labelBrush; | |||
|
136 | } | |||
|
137 | ||||
|
138 | void QBarSetPrivate::setLabelFont(const QFont &font) | |||
|
139 | { | |||
|
140 | m_labelFont = font; | |||
|
141 | emit valueChanged(); | |||
|
142 | } | |||
|
143 | ||||
|
144 | QFont QBarSetPrivate::labelFont() const | |||
|
145 | { | |||
|
146 | return m_labelFont; | |||
|
147 | } | |||
|
148 | ||||
|
149 | void QBarSetPrivate::setLabelsVisible(bool visible) | |||
|
150 | { | |||
|
151 | m_labelsVisible = visible; | |||
|
152 | emit labelsVisibleChanged(visible); | |||
|
153 | } | |||
|
154 | ||||
|
155 | bool QBarSetPrivate::labelsVisible() const | |||
|
156 | { | |||
|
157 | return m_labelsVisible; | |||
|
158 | } | |||
|
159 | ||||
|
160 | void QBarSetPrivate::barHoverEnterEvent(QPoint pos) | |||
|
161 | { | |||
|
162 | emit showToolTip(pos, m_name); | |||
|
163 | emit hoverEnter(pos); | |||
|
164 | } | |||
|
165 | ||||
|
166 | void QBarSetPrivate::barHoverLeaveEvent() | |||
|
167 | { | |||
|
168 | // Emit signal to user of charts | |||
|
169 | emit hoverLeave(); | |||
|
170 | } | |||
|
171 | ||||
|
172 | ||||
27 | /*! |
|
173 | /*! | |
28 | \class QBarSet |
|
174 | \class QBarSet | |
29 | \brief part of QtCommercial chart API. |
|
175 | \brief part of QtCommercial chart API. | |
30 |
|
176 | |||
31 | QBarSet represents one set of bars. Set of bars contains one data value for each category. |
|
177 | QBarSet represents one set of bars. Set of bars contains one data value for each category. | |
32 | First value of set is assumed to belong to first category, second to second category and so on. |
|
178 | First value of set is assumed to belong to first category, second to second category and so on. | |
33 | If set has fewer values than there are categories, then the missing values are assumed to be |
|
179 | If set has fewer values than there are categories, then the missing values are assumed to be | |
34 | at the end of set. For missing values in middle of a set, numerical value of zero is used. |
|
180 | at the end of set. For missing values in middle of a set, numerical value of zero is used. | |
35 |
|
181 | |||
36 | \mainclass |
|
182 | \mainclass | |
37 |
|
183 | |||
38 | \sa QBarSeries, QStackedBarSeries, QPercentBarSeries |
|
184 | \sa QBarSeries, QStackedBarSeries, QPercentBarSeries | |
39 | */ |
|
185 | */ | |
40 |
|
186 | |||
41 | /*! |
|
187 | /*! | |
42 | \fn void QBarSet::clicked(QString category, Qt::MouseButtons button) |
|
188 | \fn void QBarSet::clicked(QString category, Qt::MouseButtons button) | |
43 | \brief signals that set has been clicked |
|
189 | \brief signals that set has been clicked | |
44 | Parameter \a category describes on which category was clicked |
|
190 | Parameter \a category describes on which category was clicked | |
45 | Parameter \a button mouse button |
|
191 | Parameter \a button mouse button | |
46 | */ |
|
192 | */ | |
47 |
|
193 | |||
48 | /*! |
|
194 | /*! | |
49 | \fn void QBarSet::hoverEnter(QPoint pos) |
|
195 | \fn void QBarSet::hoverEnter(QPoint pos) | |
50 | \brief signals that mouse has entered over the set at position \a pos. |
|
196 | \brief signals that mouse has entered over the set at position \a pos. | |
51 | */ |
|
197 | */ | |
52 |
|
198 | |||
53 | /*! |
|
199 | /*! | |
54 | \fn void QBarSet::hoverLeave() |
|
200 | \fn void QBarSet::hoverLeave() | |
55 | \brief signals that mouse has left from the set. |
|
201 | \brief signals that mouse has left from the set. | |
56 | */ |
|
202 | */ | |
57 |
|
203 | |||
58 | /*! |
|
204 | /*! | |
59 | \fn void QBarSet::showToolTip(QPoint pos, QString tip) |
|
205 | \fn void QBarSet::showToolTip(QPoint pos, QString tip) | |
60 | \brief \internal \a pos \a tip |
|
206 | \brief \internal \a pos \a tip | |
61 | */ |
|
207 | */ | |
62 |
|
208 | |||
63 |
|
209 | |||
64 | /*! |
|
210 | /*! | |
65 | Constructs QBarSet with a name of \a name and with parent of \a parent |
|
211 | Constructs QBarSet with a name of \a name and with parent of \a parent | |
66 | */ |
|
212 | */ | |
67 | QBarSet::QBarSet(QString name, QObject *parent) |
|
213 | QBarSet::QBarSet(QString name, QObject *parent) | |
68 | : QObject(parent) |
|
214 | : QObject(parent) | |
69 | ,m_name(name) |
|
215 | ,d_ptr(new QBarSetPrivate(name,this)) | |
70 | ,m_labelsVisible(false) |
|
216 | // ,m_name(name) | |
|
217 | // ,m_labelsVisible(false) | |||
71 | { |
|
218 | { | |
72 | } |
|
219 | } | |
73 |
|
220 | |||
74 | /*! |
|
221 | /*! | |
75 | Sets new \a name for set. |
|
222 | Sets new \a name for set. | |
76 | */ |
|
223 | */ | |
77 | void QBarSet::setName(QString name) |
|
224 | void QBarSet::setName(QString name) | |
78 | { |
|
225 | { | |
79 | m_name = name; |
|
226 | Q_D(QBarSet); | |
|
227 | d->setName(name); | |||
80 | } |
|
228 | } | |
81 |
|
229 | |||
82 | /*! |
|
230 | /*! | |
83 | Returns name of the set. |
|
231 | Returns name of the set. | |
84 | */ |
|
232 | */ | |
85 | QString QBarSet::name() const |
|
233 | QString QBarSet::name() const | |
86 | { |
|
234 | { | |
87 | return m_name; |
|
235 | Q_D(const QBarSet); | |
|
236 | return d->name(); | |||
88 | } |
|
237 | } | |
89 |
|
238 | |||
90 | /*! |
|
239 | /*! | |
91 | Appends new value \a value to the end of set. |
|
240 | Appends new value \a value to the end of set. | |
92 | */ |
|
241 | */ | |
93 | QBarSet& QBarSet::operator << (const qreal &value) |
|
242 | QBarSet& QBarSet::operator << (const qreal &value) | |
94 | { |
|
243 | { | |
95 | m_values.append(value); |
|
244 | Q_D(QBarSet); | |
96 | emit structureChanged(); |
|
245 | d->operator <<(value); | |
97 | return *this; |
|
246 | return *this; | |
|
247 | ||||
|
248 | // m_values.append(value); | |||
|
249 | // emit structureChanged(); | |||
|
250 | // return *this; | |||
98 | } |
|
251 | } | |
99 |
|
252 | |||
100 | /*! |
|
253 | /*! | |
101 | Inserts new \a value on the \a i position. |
|
254 | Inserts new \a value on the \a i position. | |
102 | The value that is currently at this postion is moved to postion i + 1 |
|
255 | The value that is currently at this postion is moved to postion i + 1 | |
103 | \sa removeValue() |
|
256 | \sa removeValue() | |
104 | */ |
|
257 | */ | |
105 | void QBarSet::insertValue(int i, qreal value) |
|
258 | void QBarSet::insertValue(int i, qreal value) | |
106 | { |
|
259 | { | |
107 | m_values.insert(i, value); |
|
260 | Q_D(QBarSet); | |
|
261 | d->insertValue(i,value); | |||
|
262 | // m_values.insert(i, value); | |||
108 | } |
|
263 | } | |
109 |
|
264 | |||
110 | /*! |
|
265 | /*! | |
111 | Removes the value specified by \a i |
|
266 | Removes the value specified by \a i | |
112 | \sa insertValue() |
|
267 | \sa insertValue() | |
113 | */ |
|
268 | */ | |
114 | void QBarSet::removeValue(int i) |
|
269 | void QBarSet::removeValue(int i) | |
115 | { |
|
270 | { | |
116 | m_values.removeAt(i); |
|
271 | Q_D(QBarSet); | |
|
272 | d->removeValue(i); | |||
|
273 | // m_values.removeAt(i); | |||
117 | } |
|
274 | } | |
118 |
|
275 | |||
119 | /*! |
|
276 | /*! | |
120 | Returns count of values in set. |
|
277 | Returns count of values in set. | |
121 | */ |
|
278 | */ | |
122 | int QBarSet::count() const |
|
279 | int QBarSet::count() const | |
123 | { |
|
280 | { | |
124 | return m_values.count(); |
|
281 | Q_D(const QBarSet); | |
|
282 | return d->count(); | |||
|
283 | // return m_values.count(); | |||
125 | } |
|
284 | } | |
126 |
|
285 | |||
127 | /*! |
|
286 | /*! | |
128 | Returns value of set indexed by \a index |
|
287 | Returns value of set indexed by \a index | |
129 | */ |
|
288 | */ | |
130 | qreal QBarSet::valueAt(int index) const |
|
289 | qreal QBarSet::valueAt(int index) const | |
131 | { |
|
290 | { | |
132 | return m_values.at(index); |
|
291 | Q_D(const QBarSet); | |
|
292 | return d->valueAt(index); | |||
|
293 | // return m_values.at(index); | |||
133 | } |
|
294 | } | |
134 |
|
295 | |||
135 | /*! |
|
296 | /*! | |
136 | Sets a new value \a value to set, indexed by \a index |
|
297 | Sets a new value \a value to set, indexed by \a index | |
137 | */ |
|
298 | */ | |
138 | void QBarSet::setValue(int index, qreal value) |
|
299 | void QBarSet::setValue(int index, qreal value) | |
139 | { |
|
300 | { | |
140 | m_values.replace(index,value); |
|
301 | Q_D(QBarSet); | |
141 | emit valueChanged(); |
|
302 | d->setValue(index,value); | |
|
303 | // m_values.replace(index,value); | |||
|
304 | // emit valueChanged(); | |||
142 | } |
|
305 | } | |
143 |
|
306 | |||
144 | /*! |
|
307 | /*! | |
145 |
Returns |
|
308 | Returns sum of all values in barset. | |
146 | */ |
|
309 | */ | |
147 |
qreal QBarSet:: |
|
310 | qreal QBarSet::sum() const | |
148 | { |
|
311 | { | |
|
312 | Q_D(const QBarSet); | |||
|
313 | return d->sum(); | |||
|
314 | /* | |||
149 | qreal total(0); |
|
315 | qreal total(0); | |
150 | for (int i=0; i < m_values.count(); i++) { |
|
316 | for (int i=0; i < m_values.count(); i++) { | |
151 | total += m_values.at(i); |
|
317 | total += m_values.at(i); | |
152 | } |
|
318 | } | |
153 | return total; |
|
319 | return total; | |
|
320 | */ | |||
154 | } |
|
321 | } | |
155 |
|
322 | |||
156 | /*! |
|
323 | /*! | |
157 | Sets pen for set. Bars of this set are drawn using \a pen |
|
324 | Sets pen for set. Bars of this set are drawn using \a pen | |
158 | */ |
|
325 | */ | |
159 | void QBarSet::setPen(const QPen &pen) |
|
326 | void QBarSet::setPen(const QPen &pen) | |
160 | { |
|
327 | { | |
161 | m_pen = pen; |
|
328 | Q_D(QBarSet); | |
162 | emit valueChanged(); |
|
329 | d->setPen(pen); | |
|
330 | // m_pen = pen; | |||
|
331 | // emit valueChanged(); | |||
163 | } |
|
332 | } | |
164 |
|
333 | |||
165 | /*! |
|
334 | /*! | |
166 | Returns pen of the set. |
|
335 | Returns pen of the set. | |
167 | */ |
|
336 | */ | |
168 | QPen QBarSet::pen() const |
|
337 | QPen QBarSet::pen() const | |
169 | { |
|
338 | { | |
170 | return m_pen; |
|
339 | Q_D(const QBarSet); | |
|
340 | return d->pen(); | |||
|
341 | // return m_pen; | |||
171 | } |
|
342 | } | |
172 |
|
343 | |||
173 | /*! |
|
344 | /*! | |
174 | Sets brush for the set. Bars of this set are drawn using \a brush |
|
345 | Sets brush for the set. Bars of this set are drawn using \a brush | |
175 | */ |
|
346 | */ | |
176 | void QBarSet::setBrush(const QBrush &brush) |
|
347 | void QBarSet::setBrush(const QBrush &brush) | |
177 | { |
|
348 | { | |
178 | m_brush = brush; |
|
349 | Q_D(QBarSet); | |
179 | emit valueChanged(); |
|
350 | d->setBrush(brush); | |
|
351 | // m_brush = brush; | |||
|
352 | // emit valueChanged(); | |||
180 | } |
|
353 | } | |
181 |
|
354 | |||
182 | /*! |
|
355 | /*! | |
183 | Returns brush of the set. |
|
356 | Returns brush of the set. | |
184 | */ |
|
357 | */ | |
185 | QBrush QBarSet::brush() const |
|
358 | QBrush QBarSet::brush() const | |
186 | { |
|
359 | { | |
187 | return m_brush; |
|
360 | Q_D(const QBarSet); | |
|
361 | return d->brush(); | |||
|
362 | // return m_brush; | |||
188 | } |
|
363 | } | |
189 |
|
364 | |||
190 | /*! |
|
365 | /*! | |
191 | Sets \a pen of the values that are drawn on top of this barset |
|
366 | Sets \a pen of the values that are drawn on top of this barset | |
192 | */ |
|
367 | */ | |
193 | void QBarSet::setLabelPen(const QPen &pen) |
|
368 | void QBarSet::setLabelPen(const QPen &pen) | |
194 | { |
|
369 | { | |
195 | m_labelPen = pen; |
|
370 | Q_D(QBarSet); | |
196 | emit valueChanged(); |
|
371 | d->setLabelPen(pen); | |
|
372 | // m_labelPen = pen; | |||
|
373 | // emit valueChanged(); | |||
197 | } |
|
374 | } | |
198 |
|
375 | |||
199 | /*! |
|
376 | /*! | |
200 | Returns pen of the values that are drawn on top of this barset |
|
377 | Returns pen of the values that are drawn on top of this barset | |
201 | */ |
|
378 | */ | |
202 | QPen QBarSet::labelPen() const |
|
379 | QPen QBarSet::labelPen() const | |
203 | { |
|
380 | { | |
204 | return m_labelPen; |
|
381 | Q_D(const QBarSet); | |
|
382 | return d->labelPen(); | |||
|
383 | // return m_labelPen; | |||
205 | } |
|
384 | } | |
206 |
|
385 | |||
207 | /*! |
|
386 | /*! | |
208 | Sets \a brush of the values that are drawn on top of this barset |
|
387 | Sets \a brush of the values that are drawn on top of this barset | |
209 | */ |
|
388 | */ | |
210 | void QBarSet::setLabelBrush(const QBrush &brush) |
|
389 | void QBarSet::setLabelBrush(const QBrush &brush) | |
211 | { |
|
390 | { | |
212 | m_labelBrush = brush; |
|
391 | Q_D(QBarSet); | |
213 | emit valueChanged(); |
|
392 | d->setLabelBrush(brush); | |
|
393 | // m_labelBrush = brush; | |||
|
394 | // emit valueChanged(); | |||
214 | } |
|
395 | } | |
215 |
|
396 | |||
216 | /*! |
|
397 | /*! | |
217 | Returns brush of the values that are drawn on top of this barset |
|
398 | Returns brush of the values that are drawn on top of this barset | |
218 | */ |
|
399 | */ | |
219 | QBrush QBarSet::labelBrush() const |
|
400 | QBrush QBarSet::labelBrush() const | |
220 | { |
|
401 | { | |
221 | return m_labelBrush; |
|
402 | Q_D(const QBarSet); | |
|
403 | return d->labelBrush(); | |||
|
404 | // return m_labelBrush; | |||
222 | } |
|
405 | } | |
223 |
|
406 | |||
224 | /*! |
|
407 | /*! | |
225 | Sets the \a font for values that are drawn on top of this barset |
|
408 | Sets the \a font for values that are drawn on top of this barset | |
226 | */ |
|
409 | */ | |
227 | void QBarSet::setLabelFont(const QFont &font) |
|
410 | void QBarSet::setLabelFont(const QFont &font) | |
228 | { |
|
411 | { | |
229 | m_labelFont = font; |
|
412 | Q_D(QBarSet); | |
230 | emit valueChanged(); |
|
413 | d->setLabelFont(font); | |
|
414 | // m_labelFont = font; | |||
|
415 | // emit valueChanged(); | |||
231 | } |
|
416 | } | |
232 |
|
417 | |||
233 | /*! |
|
418 | /*! | |
234 | Returns the pen for values that are drawn on top of this set |
|
419 | Returns the pen for values that are drawn on top of this set | |
235 | */ |
|
420 | */ | |
236 | QFont QBarSet::labelFont() const |
|
421 | QFont QBarSet::labelFont() const | |
237 | { |
|
422 | { | |
238 | return m_labelFont; |
|
423 | Q_D(const QBarSet); | |
|
424 | return d->labelFont(); | |||
|
425 | // return m_labelFont; | |||
239 | } |
|
426 | } | |
240 |
|
427 | |||
241 | /*! |
|
428 | /*! | |
242 | Sets visibility of bar labels. If \a visible is true, labels are drawn on top of barsets. |
|
429 | Sets visibility of bar labels. If \a visible is true, labels are drawn on top of barsets. | |
243 | */ |
|
430 | */ | |
244 |
|
431 | |||
245 | void QBarSet::setLabelsVisible(bool visible) |
|
432 | void QBarSet::setLabelsVisible(bool visible) | |
246 | { |
|
433 | { | |
247 | m_labelsVisible = visible; |
|
434 | Q_D(QBarSet); | |
248 |
|
|
435 | d->setLabelsVisible(visible); | |
|
436 | // m_labelsVisible = visible; | |||
|
437 | // emit labelsVisibleChanged(visible); | |||
249 | } |
|
438 | } | |
250 |
|
439 | |||
251 | /*! |
|
440 | /*! | |
252 | Returns the visibility of values |
|
441 | Returns the visibility of values | |
253 | */ |
|
442 | */ | |
254 | bool QBarSet::labelsVisible() const |
|
443 | bool QBarSet::labelsVisible() const | |
255 | { |
|
444 | { | |
256 | return m_labelsVisible; |
|
445 | Q_D(const QBarSet); | |
|
446 | return d->labelsVisible(); | |||
|
447 | // return m_labelsVisible; | |||
257 | } |
|
448 | } | |
258 |
|
449 | |||
259 |
/* |
|
450 | /* | |
260 | \internal \a pos |
|
|||
261 | */ |
|
|||
262 | void QBarSet::barHoverEnterEvent(QPoint pos) |
|
451 | void QBarSet::barHoverEnterEvent(QPoint pos) | |
263 |
|
|
452 | { | |
264 | emit showToolTip(pos, m_name); |
|
453 | emit showToolTip(pos, m_name); | |
265 | emit hoverEnter(pos); |
|
454 | emit hoverEnter(pos); | |
266 |
|
|
455 | } | |
267 |
|
||||
268 | /*! |
|
|||
269 | \internal |
|
|||
270 | */ |
|
456 | */ | |
|
457 | /* | |||
271 | void QBarSet::barHoverLeaveEvent() |
|
458 | void QBarSet::barHoverLeaveEvent() | |
272 |
|
|
459 | { | |
273 | // Emit signal to user of charts |
|
460 | // Emit signal to user of charts | |
274 | emit hoverLeave(); |
|
461 | emit hoverLeave(); | |
275 |
|
|
462 | } | |
276 |
|
463 | */ | ||
277 | #include "moc_qbarset.cpp" |
|
464 | #include "moc_qbarset.cpp" | |
|
465 | #include "moc_qbarsetprivate_p.cpp" | |||
278 |
|
466 | |||
279 | QTCOMMERCIALCHART_END_NAMESPACE |
|
467 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,105 +1,104 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #ifndef QBARSET_H |
|
21 | #ifndef QBARSET_H | |
22 | #define QBARSET_H |
|
22 | #define QBARSET_H | |
23 |
|
23 | |||
24 | #include <qchartglobal.h> |
|
24 | #include <qchartglobal.h> | |
25 | #include <QPen> |
|
25 | #include <QPen> | |
26 | #include <QBrush> |
|
26 | #include <QBrush> | |
27 | #include <QFont> |
|
27 | #include <QFont> | |
28 |
|
28 | |||
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
|
30 | class QBarSetPrivate; | |||
30 |
|
31 | |||
31 | class QTCOMMERCIALCHART_EXPORT QBarSet : public QObject |
|
32 | class QTCOMMERCIALCHART_EXPORT QBarSet : public QObject | |
32 | { |
|
33 | { | |
33 | Q_OBJECT |
|
34 | Q_OBJECT | |
34 | public: |
|
35 | public: | |
35 | QBarSet(QString name, QObject *parent = 0); |
|
36 | QBarSet(QString name, QObject *parent = 0); | |
36 |
|
37 | |||
37 | void setName(QString name); |
|
38 | void setName(QString name); | |
38 | QString name() const; |
|
39 | QString name() const; | |
39 | QBarSet& operator << (const qreal &value); // appends new value to set |
|
40 | QBarSet& operator << (const qreal &value); // appends new value to set | |
40 | void insertValue(int i, qreal value); |
|
41 | void insertValue(int i, qreal value); | |
41 | void removeValue(int i); |
|
42 | void removeValue(int i); | |
42 |
|
||||
43 | // TODO: remove indices eventually. Use as internal? |
|
|||
44 | int count() const; // count of values in set |
|
43 | int count() const; // count of values in set | |
45 |
qreal valueAt(int index) const; |
|
44 | qreal valueAt(int index) const; // for modifying individual values | |
46 | void setValue(int index, qreal value); // setter for individual value |
|
45 | void setValue(int index, qreal value); // setter for individual value | |
47 |
qreal |
|
46 | qreal sum() const; // sum of all values in the set | |
48 |
|
||||
49 | // TODO: |
|
|||
50 | //qreal value(QString category); |
|
|||
51 | //void setValue(QString category, qreal value); |
|
|||
52 |
|
47 | |||
53 | void setPen(const QPen &pen); |
|
48 | void setPen(const QPen &pen); | |
54 | QPen pen() const; |
|
49 | QPen pen() const; | |
55 |
|
50 | |||
56 | void setBrush(const QBrush &brush); |
|
51 | void setBrush(const QBrush &brush); | |
57 | QBrush brush() const; |
|
52 | QBrush brush() const; | |
58 |
|
53 | |||
59 | void setLabelPen(const QPen &pen); |
|
54 | void setLabelPen(const QPen &pen); | |
60 | QPen labelPen() const; |
|
55 | QPen labelPen() const; | |
61 |
|
56 | |||
62 | void setLabelBrush(const QBrush &brush); |
|
57 | void setLabelBrush(const QBrush &brush); | |
63 | QBrush labelBrush() const; |
|
58 | QBrush labelBrush() const; | |
64 |
|
59 | |||
65 | void setLabelFont(const QFont &font); |
|
60 | void setLabelFont(const QFont &font); | |
66 | QFont labelFont() const; |
|
61 | QFont labelFont() const; | |
67 |
|
62 | |||
68 | void setLabelsVisible(bool visible = true); |
|
63 | void setLabelsVisible(bool visible = true); | |
69 | bool labelsVisible() const; |
|
64 | bool labelsVisible() const; | |
70 |
|
65 | |||
71 | Q_SIGNALS: |
|
66 | Q_SIGNALS: | |
72 | void clicked(QString category, Qt::MouseButtons button); // Clicked and hover signals exposed to user |
|
67 | void clicked(QString category, Qt::MouseButtons button); // Clicked and hover signals exposed to user | |
73 |
|
68 | |||
74 | // TODO: TO PIMPL ---> |
|
69 | // TODO: TO PIMPL ---> | |
75 | void structureChanged(); |
|
70 | // void structureChanged(); | |
76 | void valueChanged(); |
|
71 | // void valueChanged(); | |
77 | void hoverEnter(QPoint pos); |
|
72 | // void hoverEnter(QPoint pos); | |
78 | void hoverLeave(); |
|
73 | // void hoverLeave(); | |
79 | void showToolTip(QPoint pos, QString tip); // Private signal |
|
74 | // void showToolTip(QPoint pos, QString tip); // Private signal | |
80 | void labelsVisibleChanged(bool visible); |
|
75 | // void labelsVisibleChanged(bool visible); | |
81 | // <--- TO PIMPL |
|
76 | // <--- TO PIMPL | |
82 |
|
77 | |||
83 | public Q_SLOTS: |
|
78 | public Q_SLOTS: | |
84 | // These are for internal communication |
|
79 | // These are for internal communication | |
85 | // TODO: TO PIMPL ---> |
|
80 | // TODO: TO PIMPL ---> | |
86 | void barHoverEnterEvent(QPoint pos); |
|
81 | // void barHoverEnterEvent(QPoint pos); | |
87 | void barHoverLeaveEvent(); |
|
82 | // void barHoverLeaveEvent(); | |
88 | // <--- TO PIMPL |
|
83 | // <--- TO PIMPL | |
89 |
|
84 | |||
90 | private: |
|
85 | private: | |
91 |
|
86 | QBarSetPrivate * const d_ptr; | ||
|
87 | Q_DECLARE_PRIVATE(QBarSet) | |||
|
88 | Q_DISABLE_COPY(QBarSet) | |||
|
89 | /* | |||
92 | QString m_name; |
|
90 | QString m_name; | |
93 | QList<qreal> m_values; // TODO: replace with map (category, value) |
|
91 | QList<qreal> m_values; // TODO: replace with map (category, value) | |
94 | QMap<QString, qreal> m_mappedValues; |
|
92 | QMap<QString, qreal> m_mappedValues; | |
95 | QPen m_pen; |
|
93 | QPen m_pen; | |
96 | QBrush m_brush; |
|
94 | QBrush m_brush; | |
97 | QPen m_labelPen; |
|
95 | QPen m_labelPen; | |
98 | QBrush m_labelBrush; |
|
96 | QBrush m_labelBrush; | |
99 | QFont m_labelFont; |
|
97 | QFont m_labelFont; | |
100 | bool m_labelsVisible; |
|
98 | bool m_labelsVisible; | |
|
99 | */ | |||
101 | }; |
|
100 | }; | |
102 |
|
101 | |||
103 | QTCOMMERCIALCHART_END_NAMESPACE |
|
102 | QTCOMMERCIALCHART_END_NAMESPACE | |
104 |
|
103 | |||
105 | #endif // QBARSET_H |
|
104 | #endif // QBARSET_H |
General Comments 0
You need to be logged in to leave comments.
Login now