@@ -0,0 +1,50 | |||
|
1 | #include "declarativebarseries.h" | |
|
2 | #include "declarativechart.h" | |
|
3 | #include "qchart.h" | |
|
4 | #include "qbarseries.h" | |
|
5 | #include "qbarset.h" | |
|
6 | ||
|
7 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
|
8 | ||
|
9 | DeclarativeBarSeries::DeclarativeBarSeries(QDeclarativeItem *parent) : | |
|
10 | QDeclarativeItem(parent) | |
|
11 | { | |
|
12 | setFlag(QGraphicsItem::ItemHasNoContents, false); | |
|
13 | connect(this, SIGNAL(parentChanged()), | |
|
14 | this, SLOT(setParentForSeries())); | |
|
15 | } | |
|
16 | ||
|
17 | void DeclarativeBarSeries::setParentForSeries() | |
|
18 | { | |
|
19 | if (!m_series) { | |
|
20 | DeclarativeChart *declarativeChart = qobject_cast<DeclarativeChart *>(parent()); | |
|
21 | ||
|
22 | if (declarativeChart) { | |
|
23 | QChart *chart = qobject_cast<QChart *>(declarativeChart->m_chart); | |
|
24 | Q_ASSERT(chart); | |
|
25 | ||
|
26 | QStringList categories; | |
|
27 | categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun"; | |
|
28 | m_series = new QBarSeries(categories); | |
|
29 | ||
|
30 | // TODO: use data from model | |
|
31 | QBarSet *set0 = new QBarSet("Bub"); | |
|
32 | QBarSet *set1 = new QBarSet("Bob"); | |
|
33 | QBarSet *set2 = new QBarSet("Guybrush"); | |
|
34 | ||
|
35 | *set0 << 1 << 2 << 3 << 4 << 5 << 6; | |
|
36 | *set1 << 5 << 0 << 0 << 4 << 0 << 7; | |
|
37 | *set2 << 3 << 5 << 8 << 13 << 8 << 5; | |
|
38 | ||
|
39 | m_series->addBarSet(set0); | |
|
40 | m_series->addBarSet(set1); | |
|
41 | m_series->addBarSet(set2); | |
|
42 | ||
|
43 | chart->addSeries(m_series); | |
|
44 | } | |
|
45 | } | |
|
46 | } | |
|
47 | ||
|
48 | #include "moc_declarativebarseries.cpp" | |
|
49 | ||
|
50 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -0,0 +1,34 | |||
|
1 | #ifndef DECLARATIVEBARSERIES_H | |
|
2 | #define DECLARATIVEBARSERIES_H | |
|
3 | ||
|
4 | #include "qchartglobal.h" | |
|
5 | #include "scatterelement.h" // TODO: rename header | |
|
6 | #include <QDeclarativeItem> | |
|
7 | ||
|
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
|
9 | ||
|
10 | class QChart; | |
|
11 | class QBarSeries; | |
|
12 | ||
|
13 | class DeclarativeBarSeries : public QDeclarativeItem | |
|
14 | { | |
|
15 | Q_OBJECT | |
|
16 | ||
|
17 | public: | |
|
18 | explicit DeclarativeBarSeries(QDeclarativeItem *parent = 0); | |
|
19 | ||
|
20 | signals: | |
|
21 | ||
|
22 | public slots: | |
|
23 | ||
|
24 | private slots: | |
|
25 | void setParentForSeries(); | |
|
26 | ||
|
27 | private: | |
|
28 | QChart *m_chart; | |
|
29 | QBarSeries *m_series; | |
|
30 | }; | |
|
31 | ||
|
32 | QTCOMMERCIALCHART_END_NAMESPACE | |
|
33 | ||
|
34 | #endif // DECLARATIVEBARSERIES_H |
@@ -1,4 +1,5 | |||
|
1 | 1 | #include "declarativechart.h" |
|
2 | #include <QPainter>s | |
|
2 | 3 | |
|
3 | 4 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
4 | 5 | |
@@ -16,6 +17,8 DeclarativeChart::ChartTheme DeclarativeChart::theme() | |||
|
16 | 17 | |
|
17 | 18 | void DeclarativeChart::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) |
|
18 | 19 | { |
|
20 | Q_UNUSED(oldGeometry) | |
|
21 | ||
|
19 | 22 | if (newGeometry.isValid()) { |
|
20 | 23 | if (newGeometry.width() > 0 && newGeometry.height() > 0) { |
|
21 | 24 | m_chart->resize(newGeometry.width(), newGeometry.height()); |
@@ -23,6 +26,15 void DeclarativeChart::geometryChanged(const QRectF &newGeometry, const QRectF & | |||
|
23 | 26 | } |
|
24 | 27 | } |
|
25 | 28 | |
|
29 | void DeclarativeChart::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) | |
|
30 | { | |
|
31 | Q_UNUSED(option) | |
|
32 | Q_UNUSED(widget) | |
|
33 | ||
|
34 | // TODO: optimized? | |
|
35 | painter->setRenderHint(QPainter::Antialiasing, true); | |
|
36 | } | |
|
37 | ||
|
26 | 38 | #include "moc_declarativechart.cpp" |
|
27 | 39 | |
|
28 | 40 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -22,12 +22,14 public: | |||
|
22 | 22 | ThemeIcy, |
|
23 | 23 | ThemeGrayscale, |
|
24 | 24 | ThemeScientific, |
|
25 | ThemeUnnamed1 | |
|
25 | ThemeBlueCerulean, | |
|
26 | ThemeLight | |
|
26 | 27 | }; |
|
27 | 28 | DeclarativeChart(QDeclarativeItem *parent = 0); |
|
28 | 29 | |
|
29 | 30 | public: // From QDeclarativeItem/QGraphicsItem |
|
30 | 31 | void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry); |
|
32 | void paint (QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); | |
|
31 | 33 | |
|
32 | 34 | public: |
|
33 | 35 | void setTheme(ChartTheme theme) {m_chart->setChartTheme((QChart::ChartTheme) theme);} |
@@ -4,6 +4,7 | |||
|
4 | 4 | #include "scatterelement.h" |
|
5 | 5 | #include "declarativescatterseries.h" |
|
6 | 6 | #include "declarativelineseries.h" |
|
7 | #include "declarativebarseries.h" | |
|
7 | 8 | #include "declarativepieseries.h" |
|
8 | 9 | |
|
9 | 10 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
@@ -19,6 +20,7 public: | |||
|
19 | 20 | qmlRegisterType<DeclarativeChart>(uri, 1, 0, "Chart"); |
|
20 | 21 | qmlRegisterType<DeclarativeScatterSeries>(uri, 1, 0, "ScatterSeries"); |
|
21 | 22 | qmlRegisterType<DeclarativeLineSeries>(uri, 1, 0, "LineSeries"); |
|
23 | qmlRegisterType<DeclarativeBarSeries>(uri, 1, 0, "BarSeries"); | |
|
22 | 24 | qmlRegisterType<DeclarativePieSeries>(uri, 1, 0, "PieSeries"); |
|
23 | 25 | qmlRegisterType<QPieSlice>(uri, 1, 0, "ChartPieElement"); |
|
24 | 26 | // TODO: rename ScatterElement class to something like "PointElement" |
@@ -27,13 +27,15 SOURCES += \ | |||
|
27 | 27 | declarativescatterseries.cpp \ |
|
28 | 28 | scatterelement.cpp \ |
|
29 | 29 | declarativepieseries.cpp \ |
|
30 | declarativelineseries.cpp | |
|
30 | declarativelineseries.cpp \ | |
|
31 | declarativebarseries.cpp | |
|
31 | 32 | HEADERS += \ |
|
32 | 33 | declarativechart.h \ |
|
33 | 34 | declarativescatterseries.h \ |
|
34 | 35 | scatterelement.h \ |
|
35 | 36 | declarativepieseries.h \ |
|
36 | declarativelineseries.h | |
|
37 | declarativelineseries.h \ | |
|
38 | declarativebarseries.h | |
|
37 | 39 | |
|
38 | 40 | TARGETPATH = QtCommercial/Chart |
|
39 | 41 | target.path = $$[QT_INSTALL_IMPORTS]/$$TARGETPATH |
@@ -20,44 +20,35 Rectangle { | |||
|
20 | 20 | // } |
|
21 | 21 | |
|
22 | 22 | Component.onCompleted: { |
|
23 | // console.log("Component.onCompleted: " + ChartPointElement.x); | |
|
24 | // console.log("Component.onCompleted: " + ChartPointElement.y); | |
|
25 | // console.log("Component.onCompleted: " + ChartPointElement.dataX); | |
|
26 | // console.log("Component.onCompleted: " + ChartPointElement.dataY); | |
|
27 | //console.log("Component.onCompleted: " + chartModel.get(0).x); | |
|
28 | //console.log("Component.onCompleted: " + chartModel.ChartPointElements); | |
|
29 | // console.log("Component.onCompleted: " + elementt.dataX); | |
|
30 | 23 | // console.log("Component.onCompleted: " + chartModel.get(0).dataX); |
|
31 | //ChartPointElement { x: 0.3; y: 0.3 } | |
|
32 | 24 | } |
|
33 | 25 | |
|
26 | // ChartModel { | |
|
27 | // id: dynamicData | |
|
28 | // } | |
|
29 | ||
|
34 | 30 | Chart { |
|
35 | 31 | id: chart1 |
|
36 | 32 | anchors.top: parent.top |
|
37 | 33 | anchors.left: parent.left |
|
38 | 34 | anchors.right: parent.right |
|
39 | 35 | height: parent.height / 2 |
|
40 |
theme: Chart.Theme |
|
|
36 | theme: Chart.ThemeBlueCerulean | |
|
41 | 37 | |
|
42 |
|
|
|
43 | data: [ | |
|
44 | // TODO: "NnElement" matches the naming convention of for example ListModel... | |
|
45 | // But PieSlice would match the naming of QtCommercial Charts C++ api | |
|
46 | ChartPieElement { label: "Volkswagen"; value: 13.5 }, | |
|
47 | ChartPieElement { label: "Toyota"; value: 10.9 }, | |
|
48 | ChartPieElement { label: "Ford"; value: 8.6 }, | |
|
49 | ChartPieElement { label: "Skoda"; value: 8.2 }, | |
|
50 | ChartPieElement { label: "Volvo"; value: 6.8 }, | |
|
51 | ChartPieElement { label: "Others"; value: 52.0 } | |
|
52 | ] | |
|
38 | BarSeries { | |
|
53 | 39 | } |
|
54 | 40 | |
|
55 | // Series { | |
|
56 | // seriesType: Series.SeriesTypeLine | |
|
57 | // } | |
|
58 | // TODO: | |
|
59 | // Series { | |
|
60 | // seriesType: Series.SeriesTypeBar | |
|
41 | // PieSeries { | |
|
42 | // data: [ | |
|
43 | // // TODO: "NnElement" matches the naming convention of for example ListModel... | |
|
44 | // // But PieSlice would match the naming of QtCommercial Charts C++ api | |
|
45 | // ChartPieElement { label: "Volkswagen"; value: 13.5 }, | |
|
46 | // ChartPieElement { label: "Toyota"; value: 10.9 }, | |
|
47 | // ChartPieElement { label: "Ford"; value: 8.6 }, | |
|
48 | // ChartPieElement { label: "Skoda"; value: 8.2 }, | |
|
49 | // ChartPieElement { label: "Volvo"; value: 6.8 }, | |
|
50 | // ChartPieElement { label: "Others"; value: 52.0 } | |
|
51 | // ] | |
|
61 | 52 | // } |
|
62 | 53 | } |
|
63 | 54 | |
@@ -101,7 +92,6 Rectangle { | |||
|
101 | 92 | ] |
|
102 | 93 | } |
|
103 | 94 | ScatterSeries { |
|
104 | id: scatter4 | |
|
105 | 95 | data: [ |
|
106 | 96 | ChartPointElement { x: 2.6; y: 2.6 }, |
|
107 | 97 | ChartPointElement { x: 2.6; y: 2.7 }, |
General Comments 0
You need to be logged in to leave comments.
Login now