@@ -1,117 +1,122 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #include "customtablemodel.h" |
|
22 | 22 | #include <QVector> |
|
23 | 23 | #include <QRect> |
|
24 | 24 | #include <QColor> |
|
25 | 25 | |
|
26 | 26 | CustomTableModel::CustomTableModel(QObject *parent) : |
|
27 | 27 | QAbstractTableModel(parent), |
|
28 | 28 | m_columnCount(0), |
|
29 | 29 | m_rowCount(0) |
|
30 | 30 | { |
|
31 | 31 | } |
|
32 | 32 | |
|
33 | 33 | int CustomTableModel::rowCount(const QModelIndex & parent) const |
|
34 | 34 | { |
|
35 | 35 | Q_UNUSED(parent) |
|
36 | 36 | return m_data.count(); |
|
37 | 37 | } |
|
38 | 38 | |
|
39 | 39 | int CustomTableModel::columnCount(const QModelIndex & parent) const |
|
40 | 40 | { |
|
41 | 41 | Q_UNUSED(parent) |
|
42 | 42 | return m_columnCount; |
|
43 | 43 | } |
|
44 | 44 | |
|
45 | 45 | QVariant CustomTableModel::headerData (int section, Qt::Orientation orientation, int role ) const |
|
46 | 46 | { |
|
47 | 47 | if (role != Qt::DisplayRole) |
|
48 | 48 | return QVariant(); |
|
49 | 49 | |
|
50 | 50 | if (orientation == Qt::Horizontal) { |
|
51 | 51 | if (section % 2 == 0) |
|
52 | 52 | return "x"; |
|
53 | 53 | else |
|
54 | 54 | return "y"; |
|
55 | 55 | } else { |
|
56 | 56 | return QString("%1").arg(section + 1); |
|
57 | 57 | } |
|
58 | 58 | } |
|
59 | 59 | |
|
60 | 60 | QVariant CustomTableModel::data(const QModelIndex &index, int role) const |
|
61 | 61 | { |
|
62 | 62 | if (role == Qt::DisplayRole) { |
|
63 | 63 | return m_data[index.row()]->at(index.column()); |
|
64 | 64 | } else if (role == Qt::EditRole) { |
|
65 | 65 | return m_data[index.row()]->at(index.column()); |
|
66 | 66 | } |
|
67 | 67 | return QVariant(); |
|
68 | 68 | } |
|
69 | 69 | |
|
70 | 70 | bool CustomTableModel::setData(const QModelIndex &index, const QVariant &value, int role) |
|
71 | 71 | { |
|
72 | 72 | if (index.isValid() && role == Qt::EditRole) { |
|
73 | 73 | m_data[index.row()]->replace(index.column(), value); |
|
74 | 74 | emit dataChanged(index, index); |
|
75 | 75 | return true; |
|
76 | 76 | } |
|
77 | 77 | return false; |
|
78 | 78 | } |
|
79 | 79 | |
|
80 | QVariant CustomTableModel::at(int row, int column) | |
|
81 | { | |
|
82 | return data(index(row, column)); | |
|
83 | } | |
|
84 | ||
|
80 | 85 | void CustomTableModel::insertColumn(int column, const QModelIndex &parent) |
|
81 | 86 | { |
|
82 | 87 | beginInsertColumns(parent, column, column); |
|
83 | 88 | m_columnCount++; |
|
84 | 89 | endInsertColumns(); |
|
85 | 90 | } |
|
86 | 91 | |
|
87 | 92 | void CustomTableModel::insertRow(int row, const QModelIndex &parent) |
|
88 | 93 | { |
|
89 | 94 | beginInsertRows(parent, row, row); |
|
90 | 95 | QVector<QVariant>* dataVec = new QVector<QVariant>(m_columnCount); |
|
91 | 96 | m_data.insert(row, dataVec); |
|
92 | 97 | endInsertRows(); |
|
93 | 98 | } |
|
94 | 99 | |
|
95 | 100 | bool CustomTableModel::removeRow(int row, const QModelIndex &parent) |
|
96 | 101 | { |
|
97 | 102 | return QAbstractTableModel::removeRow(row, parent); |
|
98 | 103 | } |
|
99 | 104 | |
|
100 | 105 | bool CustomTableModel::removeRows(int row, int count, const QModelIndex &parent) |
|
101 | 106 | { |
|
102 | 107 | beginRemoveRows(parent, row, row + count - 1); |
|
103 | 108 | bool removed(false); |
|
104 | 109 | for (int i(row); i < (row + count); i++) { |
|
105 | 110 | m_data.removeAt(i); |
|
106 | 111 | removed = true; |
|
107 | 112 | } |
|
108 | 113 | endRemoveRows(); |
|
109 | 114 | return removed; |
|
110 | 115 | } |
|
111 | 116 | |
|
112 | 117 | Qt::ItemFlags CustomTableModel::flags ( const QModelIndex & index ) const |
|
113 | 118 | { |
|
114 | 119 | return QAbstractItemModel::flags(index) | Qt::ItemIsEditable; |
|
115 | 120 | } |
|
116 | 121 | |
|
117 | 122 | #include "moc_customtablemodel.cpp" |
@@ -1,52 +1,54 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #ifndef CUSTOMTABLEMODEL_H |
|
22 | 22 | #define CUSTOMTABLEMODEL_H |
|
23 | 23 | |
|
24 | 24 | #include <QAbstractTableModel> |
|
25 | 25 | #include <QHash> |
|
26 | 26 | |
|
27 | 27 | class CustomTableModel : public QAbstractTableModel |
|
28 | 28 | { |
|
29 | 29 | Q_OBJECT |
|
30 |
Q_PROPERTY(int |
|
|
30 | Q_PROPERTY(int rowCount READ rowCount) | |
|
31 | Q_PROPERTY(int columnCount READ columnCount) | |
|
31 | 32 | |
|
32 | 33 | public: |
|
33 | 34 | explicit CustomTableModel(QObject *parent = 0); |
|
34 | 35 | |
|
35 | 36 | int rowCount ( const QModelIndex & parent = QModelIndex() ) const; |
|
36 | 37 | int columnCount ( const QModelIndex & parent = QModelIndex() ) const; |
|
37 | 38 | QVariant headerData (int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const; |
|
38 | 39 | QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; |
|
39 | 40 | bool setData ( const QModelIndex & index, const QVariant & value, int role = Qt::EditRole ); |
|
40 | 41 | Qt::ItemFlags flags ( const QModelIndex & index ) const; |
|
41 | 42 | void insertColumn(int column, const QModelIndex &parent = QModelIndex()); |
|
42 | 43 | void insertRow(int row, const QModelIndex &parent = QModelIndex()); |
|
43 | 44 | Q_INVOKABLE bool removeRows(int row, int count, const QModelIndex & parent = QModelIndex()); |
|
44 | 45 | Q_INVOKABLE bool removeRow (int row, const QModelIndex &parent = QModelIndex()); |
|
46 | Q_INVOKABLE QVariant at(int row, int column); | |
|
45 | 47 | |
|
46 | 48 | private: |
|
47 | 49 | QList<QVector<QVariant> * > m_data; |
|
48 | 50 | int m_columnCount; |
|
49 | 51 | int m_rowCount; |
|
50 | 52 | }; |
|
51 | 53 | |
|
52 | 54 | #endif // CUSTOMTABLEMODEL_H |
@@ -1,134 +1,105 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | import QtQuick 1.0 |
|
22 | 22 | import QtCommercial.Chart 1.0 |
|
23 | 23 | import QmlCustomModel 1.0 |
|
24 | 24 | |
|
25 | 25 | Rectangle { |
|
26 | 26 | width: parent.width |
|
27 | 27 | height: parent.height |
|
28 | 28 | |
|
29 | 29 | ChartView { |
|
30 | 30 | id: chart |
|
31 | title: "Custom model example" | |
|
31 | title: "Top-5 car brand shares in Finland" | |
|
32 | 32 | anchors.fill: parent |
|
33 | 33 | theme: ChartView.ChartThemeLight |
|
34 | 34 | axisX.max: 10 |
|
35 | 35 | axisX.min: 0 |
|
36 | 36 | axisY.max: 20 |
|
37 | 37 | axisY.min: 0 |
|
38 | animationOptions: ChartView.SeriesAnimations | |
|
39 | axisXLabels: [0, "2007", 1, "2008", 2, "2009", 3, "2010", 4, "2011", 5, "2012"] | |
|
38 | 40 | |
|
39 | 41 | // For dynamic data we use a custom data model derived from QAbstractiItemModel |
|
40 | 42 | CustomModel { |
|
41 | 43 | id: customModel |
|
42 | CustomModelElement { values: [0, "Manufacturer", 1, 2] } | |
|
43 |
CustomModelElement { values: [1, "Volkswagen", 1 |
|
|
44 |
CustomModelElement { values: [2, "Toyota", 1 |
|
|
45 |
CustomModelElement { values: [3, "Ford", |
|
|
46 |
CustomModelElement { values: [4, "Skoda", |
|
|
47 |
CustomModelElement { values: [5, "Volvo", |
|
|
44 | CustomModelElement { values: [0, "Manufacturer", 0, 1, 2, 3, 4] } | |
|
45 | CustomModelElement { values: [1, "Volkswagen", 10.3, 12.0, 12.8, 13.0, 13.8] } | |
|
46 | CustomModelElement { values: [2, "Toyota", 13.8, 13.5, 16.2, 13.7, 10.7] } | |
|
47 | CustomModelElement { values: [3, "Ford", 6.4, 7.1, 8.9, 8.2, 8.6] } | |
|
48 | CustomModelElement { values: [4, "Skoda", 4.7, 5.8, 6.9, 8.3, 8.2] } | |
|
49 | CustomModelElement { values: [5, "Volvo", 7.1, 6.7, 6.5, 6.3, 7.0] } | |
|
50 | CustomModelElement { values: [6, "Others", 57.7, 54.9, 48.7, 50.5, 51.7] } | |
|
48 | 51 | } |
|
49 | 52 | |
|
50 |
|
|
|
51 |
name: " |
|
|
52 |
|
|
|
53 | BarSeries { | |
|
54 | name: "Others" | |
|
55 | barMargin: 0 | |
|
56 | HBarModelMapper { | |
|
53 | 57 | model: customModel |
|
54 |
|
|
|
55 |
|
|
|
58 | firstBarSetRow: 6 | |
|
59 | lastBarSetRow: 6 | |
|
56 | 60 | first: 2 |
|
57 | 61 | } |
|
58 | 62 | } |
|
59 | 63 | |
|
60 | 64 | LineSeries { |
|
61 | name: "Toyota" | |
|
65 | id: lineSeries | |
|
66 | name: "Volkswagen" | |
|
62 | 67 | HXYModelMapper { |
|
68 | id: lineSeriesMapper | |
|
63 | 69 | model: customModel |
|
64 | 70 | xRow: 0 |
|
65 |
yRow: |
|
|
71 | yRow: 1 | |
|
66 | 72 | first: 2 |
|
67 | 73 | } |
|
68 | 74 | } |
|
69 | 75 | |
|
70 | 76 | PieSeries { |
|
71 | 77 | id: pieSeries |
|
72 | 78 | size: 0.4 |
|
73 | 79 | horizontalPosition: 0.7 |
|
74 |
verticalPosition: 0. |
|
|
75 | } | |
|
80 | verticalPosition: 0.4 | |
|
81 | onClicked: { | |
|
82 | // Show the selection by exploding the slice | |
|
83 | for (var i = 0; i < pieSeries.count; i++) | |
|
84 | pieSeries.at(i).exploded = false; | |
|
85 | slice.exploded = true; | |
|
76 | 86 | |
|
77 | // VPieModelMapper { | |
|
78 | // series: pieSeries | |
|
79 | // model: customModel | |
|
80 | // labelsColumn: 1 | |
|
81 | // valuesColumn: 2 | |
|
82 |
|
|
|
83 | // } | |
|
84 | HPieModelMapper { | |
|
85 | series: pieSeries | |
|
86 | model: customModel | |
|
87 | labelsRow: 1 | |
|
88 | valuesRow: 2 | |
|
89 | first: 2 | |
|
90 | } | |
|
91 | ||
|
92 | AreaSeries { | |
|
93 | name: "Ford" | |
|
94 | upperSeries: LineSeries { | |
|
95 | HXYModelMapper { | |
|
96 | model: customModel | |
|
97 | xRow: 0 | |
|
98 | yRow: 3 | |
|
99 | first: 2 | |
|
87 | // Update the line series to show the yearly data for this slice | |
|
88 | lineSeries.name = slice.label; | |
|
89 | for (var j = 0; j < customModel.rowCount; j++) { | |
|
90 | if (customModel.at(j, 1) == slice.label) { | |
|
91 | lineSeriesMapper.yRow = j; | |
|
92 | } | |
|
100 | 93 | } |
|
101 | 94 | } |
|
102 | 95 | } |
|
103 | 96 | |
|
104 | GroupedBarSeries { | |
|
105 | name: "Skoda and Volvo" | |
|
106 | HBarModelMapper { | |
|
107 | model: customModel | |
|
108 | firstBarSetRow: 4 | |
|
109 |
|
|
|
110 | first: 2 | |
|
111 | } | |
|
97 | VPieModelMapper { | |
|
98 | series: pieSeries | |
|
99 | model: customModel | |
|
100 | labelsColumn: 1 | |
|
101 | valuesColumn: 2 | |
|
102 | first: 1 | |
|
112 | 103 | } |
|
113 | 104 | } |
|
114 | ||
|
115 | ||
|
116 | // TODO: you could also implement appending to your model, for example: | |
|
117 | // pieSeries.model.append(["Others", 52.0]); | |
|
118 | ||
|
119 | // TODO: show how to use data from a list model in a chart view | |
|
120 | // i.e. copy the data into a custom model | |
|
121 | // ListModel { | |
|
122 | // id: listModel | |
|
123 | // ListElement { | |
|
124 | // label: "Volkswagen" | |
|
125 | // value: 13.5 | |
|
126 | // } | |
|
127 | // ListElement { | |
|
128 | // label: "Toyota" | |
|
129 | // value: 10.9 | |
|
130 | // } | |
|
131 | // // and so on... | |
|
132 | // } | |
|
133 | ||
|
134 | 105 | } |
@@ -1,150 +1,96 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #include "declarativepieseries.h" |
|
22 | 22 | #include "declarativechart.h" |
|
23 | 23 | #include "qchart.h" |
|
24 | 24 | #include <qdeclarativelist.h> |
|
25 | 25 | #include <QVPieModelMapper> |
|
26 | 26 | #include <QHPieModelMapper> |
|
27 | 27 | |
|
28 | 28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
29 | 29 | |
|
30 | DeclarativePieSlice::DeclarativePieSlice(QObject *parent) : | |
|
31 | QPieSlice(parent) | |
|
32 | { | |
|
33 | } | |
|
34 | ||
|
35 | QColor DeclarativePieSlice::color() | |
|
36 | { | |
|
37 | return brush().color(); | |
|
38 | } | |
|
39 | ||
|
40 | void DeclarativePieSlice::setColor(QColor color) | |
|
41 | { | |
|
42 | QBrush b = brush(); | |
|
43 | b.setColor(color); | |
|
44 | setBrush(b); | |
|
45 | } | |
|
46 | ||
|
47 | QColor DeclarativePieSlice::borderColor() | |
|
48 | { | |
|
49 | return pen().color(); | |
|
50 | } | |
|
51 | ||
|
52 | void DeclarativePieSlice::setBorderColor(QColor color) | |
|
53 | { | |
|
54 | QPen p = pen(); | |
|
55 | p.setColor(color); | |
|
56 | setPen(p); | |
|
57 | } | |
|
58 | ||
|
59 | int DeclarativePieSlice::borderWidth() | |
|
60 | { | |
|
61 | return pen().width(); | |
|
62 | } | |
|
63 | ||
|
64 | void DeclarativePieSlice::setBorderWidth(int width) | |
|
65 | { | |
|
66 | QPen p = pen(); | |
|
67 | p.setWidth(width); | |
|
68 | setPen(p); | |
|
69 | } | |
|
70 | ||
|
71 | QColor DeclarativePieSlice::labelColor() | |
|
72 | { | |
|
73 | return labelBrush().color(); | |
|
74 | } | |
|
75 | ||
|
76 | void DeclarativePieSlice::setLabelColor(QColor color) | |
|
77 | { | |
|
78 | // TODO: use brush instead for label color | |
|
79 | QBrush b = labelBrush(); | |
|
80 | b.setColor(color); | |
|
81 | setLabelBrush(b); | |
|
82 | } | |
|
83 | ||
|
84 | 30 | DeclarativePieSeries::DeclarativePieSeries(QObject *parent) : |
|
85 | 31 | QPieSeries(parent) |
|
86 | 32 | { |
|
87 | 33 | } |
|
88 | 34 | |
|
89 | 35 | void DeclarativePieSeries::classBegin() |
|
90 | 36 | { |
|
91 | 37 | } |
|
92 | 38 | |
|
93 | 39 | void DeclarativePieSeries::componentComplete() |
|
94 | 40 | { |
|
95 | 41 | foreach(QObject *child, children()) { |
|
96 |
if (qobject_cast< |
|
|
97 |
QPieSeries::append(qobject_cast< |
|
|
42 | if (qobject_cast<QPieSlice *>(child)) { | |
|
43 | QPieSeries::append(qobject_cast<QPieSlice *>(child)); | |
|
98 | 44 | } else if(qobject_cast<QVPieModelMapper *>(child)) { |
|
99 | 45 | QVPieModelMapper *mapper = qobject_cast<QVPieModelMapper *>(child); |
|
100 | 46 | mapper->setSeries(this); |
|
101 | 47 | } else if(qobject_cast<QHPieModelMapper *>(child)) { |
|
102 | 48 | QHPieModelMapper *mapper = qobject_cast<QHPieModelMapper *>(child); |
|
103 | 49 | mapper->setSeries(this); |
|
104 | 50 | } |
|
105 | 51 | } |
|
106 | 52 | } |
|
107 | 53 | |
|
108 | 54 | QDeclarativeListProperty<QObject> DeclarativePieSeries::seriesChildren() |
|
109 | 55 | { |
|
110 | 56 | return QDeclarativeListProperty<QObject>(this, 0, &DeclarativePieSeries::appendSeriesChildren); |
|
111 | 57 | } |
|
112 | 58 | |
|
113 | 59 | void DeclarativePieSeries::appendSeriesChildren(QDeclarativeListProperty<QObject> * list, QObject *element) |
|
114 | 60 | { |
|
115 | 61 | // Empty implementation; the children are parsed in componentComplete instead |
|
116 | 62 | Q_UNUSED(list); |
|
117 | 63 | Q_UNUSED(element); |
|
118 | 64 | } |
|
119 | 65 | |
|
120 |
|
|
|
66 | QPieSlice *DeclarativePieSeries::at(int index) | |
|
121 | 67 | { |
|
122 | 68 | QList<QPieSlice*> sliceList = slices(); |
|
123 | 69 | if (index < sliceList.count()) |
|
124 |
return |
|
|
70 | return sliceList[index]; | |
|
125 | 71 | |
|
126 | 72 | return 0; |
|
127 | 73 | } |
|
128 | 74 | |
|
129 |
|
|
|
75 | QPieSlice* DeclarativePieSeries::find(QString label) | |
|
130 | 76 | { |
|
131 | 77 | foreach (QPieSlice *slice, slices()) { |
|
132 | 78 | if (slice->label() == label) |
|
133 | return qobject_cast<DeclarativePieSlice *>(slice); | |
|
79 | return slice; | |
|
134 | 80 | } |
|
135 | 81 | return 0; |
|
136 | 82 | } |
|
137 | 83 | |
|
138 |
|
|
|
84 | QPieSlice* DeclarativePieSeries::append(QString label, qreal value) | |
|
139 | 85 | { |
|
140 | 86 | // TODO: parameter order is wrong, switch it: |
|
141 |
|
|
|
87 | QPieSlice *slice = new QPieSlice(this); | |
|
142 | 88 | slice->setLabel(label); |
|
143 | 89 | slice->setValue(value); |
|
144 | 90 | QPieSeries::append(slice); |
|
145 | 91 | return slice; |
|
146 | 92 | } |
|
147 | 93 | |
|
148 | 94 | #include "moc_declarativepieseries.cpp" |
|
149 | 95 | |
|
150 | 96 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,79 +1,59 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #ifndef DECLARATIVEPIESERIES_H |
|
22 | 22 | #define DECLARATIVEPIESERIES_H |
|
23 | 23 | |
|
24 | 24 | #include "qchartglobal.h" |
|
25 | 25 | #include <QPieSlice> |
|
26 | 26 | #include <QPieSeries> |
|
27 | 27 | #include <QDeclarativeParserStatus> |
|
28 | 28 | #include <QDeclarativeListProperty> |
|
29 | 29 | #include <QAbstractItemModel> |
|
30 | 30 | |
|
31 | 31 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
32 | 32 | |
|
33 | 33 | class QChart; |
|
34 | 34 | |
|
35 | class DeclarativePieSlice: public QPieSlice | |
|
36 | { | |
|
37 | Q_OBJECT | |
|
38 | Q_PROPERTY(QColor color READ color WRITE setColor) | |
|
39 | Q_PROPERTY(QColor borderColor READ borderColor WRITE setBorderColor) | |
|
40 | Q_PROPERTY(int borderWidth READ borderWidth WRITE setBorderWidth) | |
|
41 | Q_PROPERTY(QColor labelColor READ labelColor WRITE setLabelColor) | |
|
42 | ||
|
43 | public: | |
|
44 | explicit DeclarativePieSlice(QObject *parent = 0); | |
|
45 | QColor color(); | |
|
46 | void setColor(QColor color); | |
|
47 | QColor borderColor(); | |
|
48 | void setBorderColor(QColor color); | |
|
49 | int borderWidth(); | |
|
50 | void setBorderWidth(int width); | |
|
51 | QColor labelColor(); | |
|
52 | void setLabelColor(QColor color); | |
|
53 | }; | |
|
54 | ||
|
55 | 35 | class DeclarativePieSeries : public QPieSeries, public QDeclarativeParserStatus |
|
56 | 36 | { |
|
57 | 37 | Q_OBJECT |
|
58 | 38 | Q_INTERFACES(QDeclarativeParserStatus) |
|
59 | 39 | Q_PROPERTY(QDeclarativeListProperty<QObject> seriesChildren READ seriesChildren) |
|
60 | 40 | Q_CLASSINFO("DefaultProperty", "seriesChildren") |
|
61 | 41 | |
|
62 | 42 | public: |
|
63 | 43 | explicit DeclarativePieSeries(QObject *parent = 0); |
|
64 | 44 | QDeclarativeListProperty<QObject> seriesChildren(); |
|
65 |
Q_INVOKABLE |
|
|
66 |
Q_INVOKABLE |
|
|
67 |
Q_INVOKABLE |
|
|
45 | Q_INVOKABLE QPieSlice *at(int index); | |
|
46 | Q_INVOKABLE QPieSlice *find(QString label); | |
|
47 | Q_INVOKABLE QPieSlice *append(QString label, qreal value); | |
|
68 | 48 | |
|
69 | 49 | public: |
|
70 | 50 | void classBegin(); |
|
71 | 51 | void componentComplete(); |
|
72 | 52 | |
|
73 | 53 | public Q_SLOTS: |
|
74 | 54 | static void appendSeriesChildren(QDeclarativeListProperty<QObject> *list, QObject *element); |
|
75 | 55 | }; |
|
76 | 56 | |
|
77 | 57 | QTCOMMERCIALCHART_END_NAMESPACE |
|
78 | 58 | |
|
79 | 59 | #endif // DECLARATIVEPIESERIES_H |
@@ -1,101 +1,99 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #include <QtDeclarative/qdeclarativeextensionplugin.h> |
|
22 | 22 | #include <QtDeclarative/qdeclarative.h> |
|
23 | 23 | #include "qchart.h" |
|
24 | 24 | #include "qaxiscategories.h" |
|
25 | 25 | #include "declarativechart.h" |
|
26 | 26 | #include "declarativexypoint.h" |
|
27 | 27 | #include "declarativelineseries.h" |
|
28 | 28 | #include "declarativesplineseries.h" |
|
29 | 29 | #include "declarativeareaseries.h" |
|
30 | 30 | #include "declarativescatterseries.h" |
|
31 | 31 | #include "declarativebarseries.h" |
|
32 | 32 | #include "declarativepieseries.h" |
|
33 | 33 | #include <QVXYModelMapper> |
|
34 | 34 | #include <QHXYModelMapper> |
|
35 | 35 | #include <QHPieModelMapper> |
|
36 | 36 | #include <QVPieModelMapper> |
|
37 | 37 | #include <QHBarModelMapper> |
|
38 | 38 | #include <QVBarModelMapper> |
|
39 | 39 | |
|
40 | 40 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
41 | 41 | |
|
42 | 42 | class ChartQmlPlugin : public QDeclarativeExtensionPlugin |
|
43 | 43 | { |
|
44 | 44 | Q_OBJECT |
|
45 | 45 | public: |
|
46 | 46 | virtual void registerTypes(const char *uri) |
|
47 | 47 | { |
|
48 | 48 | Q_ASSERT(QLatin1String(uri) == QLatin1String("QtCommercial.Chart")); |
|
49 | 49 | |
|
50 | 50 | qmlRegisterType<DeclarativeChart>(uri, 1, 0, "ChartView"); |
|
51 | 51 | qmlRegisterType<DeclarativeXyPoint>(uri, 1, 0, "XyPoint"); |
|
52 | 52 | qmlRegisterType<DeclarativeScatterSeries>(uri, 1, 0, "ScatterSeries"); |
|
53 | 53 | qmlRegisterType<DeclarativeLineSeries>(uri, 1, 0, "LineSeries"); |
|
54 | 54 | qmlRegisterType<DeclarativeSplineSeries>(uri, 1, 0, "SplineSeries"); |
|
55 | 55 | qmlRegisterType<DeclarativeAreaSeries>(uri, 1, 0, "AreaSeries"); |
|
56 | 56 | qmlRegisterType<DeclarativeBarSeries>(uri, 1, 0, "BarSeries"); |
|
57 | 57 | qmlRegisterType<DeclarativeGroupedBarSeries>(uri, 1, 0, "GroupedBarSeries"); |
|
58 | 58 | qmlRegisterType<DeclarativeStackedBarSeries>(uri, 1, 0, "StackedBarSeries"); |
|
59 | 59 | qmlRegisterType<DeclarativePercentBarSeries>(uri, 1, 0, "PercentBarSeries"); |
|
60 | 60 | qmlRegisterType<DeclarativePieSeries>(uri, 1, 0, "PieSeries"); |
|
61 |
qmlRegisterType< |
|
|
61 | qmlRegisterType<QPieSlice>(uri, 1, 0, "PieSlice"); | |
|
62 | 62 | qmlRegisterType<DeclarativeBarSet>(uri, 1, 0, "BarSet"); |
|
63 | 63 | qmlRegisterType<QHXYModelMapper>(uri, 1, 0, "HXYModelMapper"); |
|
64 | 64 | qmlRegisterType<QVXYModelMapper>(uri, 1, 0, "VXYModelMapper"); |
|
65 | 65 | qmlRegisterType<QHPieModelMapper>(uri, 1, 0, "HPieModelMapper"); |
|
66 | 66 | qmlRegisterType<QVPieModelMapper>(uri, 1, 0, "VPieModelMapper"); |
|
67 | 67 | qmlRegisterType<QHBarModelMapper>(uri, 1, 0, "HBarModelMapper"); |
|
68 | 68 | qmlRegisterType<QVBarModelMapper>(uri, 1, 0, "VBarModelMapper"); |
|
69 | 69 | |
|
70 | 70 | qmlRegisterUncreatableType<QScatterSeries>(uri, 1, 0, "QScatterSeries", |
|
71 | 71 | QLatin1String("Trying to create uncreatable: QScatterSeries.")); |
|
72 | 72 | qmlRegisterUncreatableType<QPieSeries>(uri, 1, 0, "QPieSeries", |
|
73 | 73 | QLatin1String("Trying to create uncreatable: QPieSeries.")); |
|
74 | qmlRegisterUncreatableType<QPieSlice>(uri, 1, 0, "QPieSlice", | |
|
75 | QLatin1String("Trying to create uncreatable: QPieSlice.")); | |
|
76 | 74 | qmlRegisterUncreatableType<QAbstractItemModel>(uri, 1, 0, "AbstractItemModel", |
|
77 | 75 | QLatin1String("Trying to create uncreatable: AbstractItemModel.")); |
|
78 | 76 | qmlRegisterUncreatableType<QXYModelMapper>(uri, 1, 0, "XYModelMapper", |
|
79 | 77 | QLatin1String("Trying to create uncreatable: XYModelMapper.")); |
|
80 | 78 | qmlRegisterUncreatableType<QPieModelMapper>(uri, 1, 0, "PieModelMapper", |
|
81 | 79 | QLatin1String("Trying to create uncreatable: PieModelMapper.")); |
|
82 | 80 | qmlRegisterUncreatableType<QBarModelMapper>(uri, 1, 0, "BarModelMapper", |
|
83 | 81 | QLatin1String("Trying to create uncreatable: BarModelMapper.")); |
|
84 | 82 | qmlRegisterUncreatableType<QAbstractSeries>(uri, 1, 0, "AbstractSeries", |
|
85 | 83 | QLatin1String("Trying to create uncreatable: AbstractSeries.")); |
|
86 | 84 | qmlRegisterUncreatableType<QAxis>(uri, 1, 0, "Axis", |
|
87 | 85 | QLatin1String("Trying to create uncreatable: Axis.")); |
|
88 | 86 | qmlRegisterUncreatableType<QPieModelMapper>(uri, 1, 0, "PieModelMapper", |
|
89 | 87 | QLatin1String("Trying to create uncreatable: PieModelMapper.")); |
|
90 | 88 | qmlRegisterUncreatableType<QXYModelMapper>(uri, 1, 0, "XYModelMapper", |
|
91 | 89 | QLatin1String("Trying to create uncreatable: XYModelMapper.")); |
|
92 | 90 | } |
|
93 | 91 | }; |
|
94 | 92 | |
|
95 | 93 | #include "plugin.moc" |
|
96 | 94 | |
|
97 | 95 | QTCOMMERCIALCHART_END_NAMESPACE |
|
98 | 96 | |
|
99 | 97 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
100 | 98 | |
|
101 | 99 | Q_EXPORT_PLUGIN2(qtcommercialchartqml, QT_PREPEND_NAMESPACE(ChartQmlPlugin)) |
@@ -1,547 +1,612 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #include "qpieslice.h" |
|
22 | 22 | #include "qpieslice_p.h" |
|
23 | 23 | |
|
24 | 24 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
25 | 25 | |
|
26 | 26 | /*! |
|
27 | 27 | \class QPieSlice |
|
28 | 28 | \brief Defines a slice in pie series. |
|
29 | 29 | |
|
30 | 30 | This object defines the properties of a single slice in a QPieSeries. |
|
31 | 31 | |
|
32 | 32 | In addition to the obvious value and label properties the user can also control |
|
33 | 33 | the visual appearance of a slice. By modifying the visual appearance also means that |
|
34 | 34 | the user is overriding the default appearance set by the theme. |
|
35 | 35 | |
|
36 | 36 | Note that if the user has customized slices and theme is changed all customizations will be lost. |
|
37 | 37 | |
|
38 | 38 | To enable user interaction with the pie some basic signals are provided about clicking and hovering. |
|
39 | 39 | */ |
|
40 | 40 | |
|
41 | 41 | /*! |
|
42 | 42 | \property QPieSlice::label |
|
43 | 43 | |
|
44 | 44 | Label of the slice. |
|
45 | 45 | |
|
46 | 46 | \sa labelVisible, labelBrush, labelFont, labelArmLengthFactor |
|
47 | 47 | */ |
|
48 | 48 | |
|
49 | 49 | /*! |
|
50 | 50 | \fn void QPieSlice::labelChanged() |
|
51 | 51 | |
|
52 | 52 | This signal emitted when the slice label has been changed. |
|
53 | 53 | |
|
54 | 54 | \sa label |
|
55 | 55 | */ |
|
56 | 56 | |
|
57 | 57 | /*! |
|
58 | 58 | \property QPieSlice::value |
|
59 | 59 | |
|
60 | 60 | Value of the slice. |
|
61 | 61 | |
|
62 | 62 | Note that if users sets a negative value it is converted to a positive value. |
|
63 | 63 | |
|
64 | 64 | \sa percentage(), QPieSeries::sum() |
|
65 | 65 | */ |
|
66 | 66 | |
|
67 | 67 | /*! |
|
68 | 68 | \fn void QPieSlice::valueChanged() |
|
69 | 69 | |
|
70 | 70 | This signal is emitted when the slice value changes. |
|
71 | 71 | |
|
72 | 72 | \sa value |
|
73 | 73 | */ |
|
74 | 74 | |
|
75 | 75 | /*! |
|
76 | 76 | \property QPieSlice::labelVisible |
|
77 | 77 | |
|
78 | 78 | Defienes the visibility of the slice label. |
|
79 | 79 | |
|
80 | 80 | Default is not visible. |
|
81 | 81 | |
|
82 | 82 | \sa label, labelBrush, labelFont, labelArmLengthFactor |
|
83 | 83 | */ |
|
84 | 84 | |
|
85 | 85 | /*! |
|
86 | 86 | \fn void QPieSlice::labelVisibleChanged() |
|
87 | 87 | |
|
88 | 88 | This signal emitted when visibility of the slice label has changed. |
|
89 | 89 | |
|
90 | 90 | \sa labelVisible |
|
91 | 91 | */ |
|
92 | 92 | |
|
93 | 93 | /*! |
|
94 | 94 | \property QPieSlice::exploded |
|
95 | 95 | |
|
96 | 96 | Defines if the slice is exploded from the pie. |
|
97 | 97 | |
|
98 | 98 | \sa explodeDistanceFactor |
|
99 | 99 | */ |
|
100 | 100 | |
|
101 | 101 | /*! |
|
102 | 102 | \fn void QPieSlice::explodedChanged() |
|
103 | 103 | |
|
104 | 104 | This signal is emitted the the slice has been exploded from the pie or is returned back to the pie. |
|
105 | 105 | |
|
106 | 106 | \sa exploded |
|
107 | 107 | */ |
|
108 | 108 | |
|
109 | 109 | /*! |
|
110 | 110 | \property QPieSlice::pen |
|
111 | 111 | |
|
112 | 112 | Pen used to draw the slice border. |
|
113 | 113 | */ |
|
114 | 114 | |
|
115 | 115 | /*! |
|
116 | 116 | \fn void QPieSlice::penChanged() |
|
117 | 117 | |
|
118 | 118 | This signal is emitted when the pen of the slice has changed. |
|
119 | 119 | |
|
120 | 120 | \sa pen |
|
121 | 121 | */ |
|
122 | 122 | |
|
123 | 123 | /*! |
|
124 | 124 | \property QPieSlice::brush |
|
125 | 125 | |
|
126 | 126 | Brush used to draw the slice. |
|
127 | 127 | */ |
|
128 | 128 | |
|
129 | 129 | /*! |
|
130 | 130 | \fn void QPieSlice::brushChanged() |
|
131 | 131 | |
|
132 | 132 | This signal is emitted when the brush of the slice has changed. |
|
133 | 133 | |
|
134 | 134 | \sa brush |
|
135 | 135 | */ |
|
136 | 136 | |
|
137 | 137 | /*! |
|
138 | 138 | \property QPieSlice::labelBrush |
|
139 | 139 | |
|
140 | 140 | Pen used to draw label and label arm of the slice. |
|
141 | 141 | |
|
142 | 142 | \sa label, labelVisible, labelFont, labelArmLengthFactor |
|
143 | 143 | */ |
|
144 | 144 | |
|
145 | 145 | /*! |
|
146 | 146 | \fn void QPieSlice::labelBrushChanged() |
|
147 | 147 | |
|
148 | 148 | This signal is emitted when the label pen of the slice has changed. |
|
149 | 149 | |
|
150 | 150 | \sa labelBrush |
|
151 | 151 | */ |
|
152 | 152 | |
|
153 | 153 | /*! |
|
154 | 154 | \property QPieSlice::labelFont |
|
155 | 155 | |
|
156 | 156 | Font used for drawing label text. |
|
157 | 157 | |
|
158 | 158 | \sa label, labelVisible, labelArmLengthFactor |
|
159 | 159 | */ |
|
160 | 160 | |
|
161 | 161 | /*! |
|
162 | 162 | \fn void QPieSlice::labelFontChanged() |
|
163 | 163 | |
|
164 | 164 | This signal is emitted when the label font of the slice has changed. |
|
165 | 165 | |
|
166 | 166 | \sa labelFont |
|
167 | 167 | */ |
|
168 | 168 | |
|
169 | 169 | /*! |
|
170 | 170 | \property QPieSlice::labelArmLengthFactor |
|
171 | 171 | |
|
172 | 172 | Defines the length of the label arm. |
|
173 | 173 | |
|
174 | 174 | The factor is relative to pie radius. For example: |
|
175 | 175 | 1.0 means the length is the same as the radius. |
|
176 | 176 | 0.5 means the length is half of the radius. |
|
177 | 177 | |
|
178 | 178 | Default value is 0.15 |
|
179 | 179 | |
|
180 | 180 | \sa label, labelVisible, labelBrush, labelFont |
|
181 | 181 | */ |
|
182 | 182 | |
|
183 | 183 | /*! |
|
184 | 184 | \fn void QPieSlice::labelArmLengthFactorChanged() |
|
185 | 185 | |
|
186 | 186 | This signal is emitted when the label arm factor of the slice has changed. |
|
187 | 187 | |
|
188 | 188 | \sa labelArmLengthFactor |
|
189 | 189 | */ |
|
190 | 190 | |
|
191 | 191 | /*! |
|
192 | 192 | \property QPieSlice::explodeDistanceFactor |
|
193 | 193 | |
|
194 | 194 | When the slice is exploded this factor defines how far the slice is exploded away from the pie. |
|
195 | 195 | |
|
196 | 196 | The factor is relative to pie radius. For example: |
|
197 | 197 | 1.0 means the distance is the same as the radius. |
|
198 | 198 | 0.5 means the distance is half of the radius. |
|
199 | 199 | |
|
200 | 200 | Default value is 0.15 |
|
201 | 201 | |
|
202 | 202 | \sa exploded |
|
203 | 203 | */ |
|
204 | 204 | |
|
205 | 205 | /*! |
|
206 | 206 | \fn void QPieSlice::explodeDistanceFactorChanged() |
|
207 | 207 | |
|
208 | 208 | This signal is emitted when the explode distance factor of the slice has changed. |
|
209 | 209 | |
|
210 | 210 | \sa explodeDistanceFactor |
|
211 | 211 | */ |
|
212 | 212 | |
|
213 | 213 | /*! |
|
214 | 214 | \property QPieSlice::percentage |
|
215 | 215 | |
|
216 | 216 | Percentage of the slice compared to the sum of all slices in the series. |
|
217 | 217 | |
|
218 | 218 | The actual value ranges from 0.0 to 1.0. |
|
219 | 219 | |
|
220 | 220 | Updated automatically once the slice is added to the series. |
|
221 | 221 | |
|
222 | 222 | \sa value, QPieSeries::sum |
|
223 | 223 | */ |
|
224 | 224 | |
|
225 | 225 | /*! |
|
226 | 226 | \fn void QPieSlice::percentageChanged() |
|
227 | 227 | |
|
228 | 228 | This signal is emitted when the percentage of the slice has changed. |
|
229 | 229 | |
|
230 | 230 | \sa percentage |
|
231 | 231 | */ |
|
232 | 232 | |
|
233 | 233 | /*! |
|
234 | 234 | \property QPieSlice::startAngle |
|
235 | 235 | |
|
236 | 236 | Defines the starting angle of this slice in the series it belongs to. |
|
237 | 237 | |
|
238 | 238 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. |
|
239 | 239 | |
|
240 | 240 | Updated automatically once the slice is added to the series. |
|
241 | 241 | */ |
|
242 | 242 | |
|
243 | 243 | /*! |
|
244 | 244 | \fn void QPieSlice::startAngleChanged() |
|
245 | 245 | |
|
246 | 246 | This signal is emitted when the starting angle f the slice has changed. |
|
247 | 247 | |
|
248 | 248 | \sa startAngle |
|
249 | 249 | */ |
|
250 | 250 | |
|
251 | 251 | /*! |
|
252 | 252 | \property QPieSlice::angleSpan |
|
253 | 253 | |
|
254 | 254 | Span of the slice in degrees. |
|
255 | 255 | |
|
256 | 256 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. |
|
257 | 257 | |
|
258 | 258 | Updated automatically once the slice is added to the series. |
|
259 | 259 | */ |
|
260 | 260 | |
|
261 | 261 | /*! |
|
262 | 262 | \fn void QPieSlice::angleSpanChanged() |
|
263 | 263 | |
|
264 | 264 | This signal is emitted when the angle span of the slice has changed. |
|
265 | 265 | |
|
266 | 266 | \sa angleSpan |
|
267 | 267 | */ |
|
268 | 268 | |
|
269 | 269 | |
|
270 | 270 | /*! |
|
271 | 271 | \fn void QPieSlice::clicked() |
|
272 | 272 | |
|
273 | 273 | This signal is emitted when user has clicked the slice. |
|
274 | 274 | |
|
275 | 275 | \sa QPieSeries::clicked() |
|
276 | 276 | */ |
|
277 | 277 | |
|
278 | 278 | /*! |
|
279 | 279 | \fn void QPieSlice::hovered(bool state) |
|
280 | 280 | |
|
281 | 281 | This signal is emitted when user has hovered over or away from the slice. |
|
282 | 282 | |
|
283 | 283 | \a state is true when user has hovered over the slice and false when hover has moved away from the slice. |
|
284 | 284 | |
|
285 | 285 | \sa QPieSeries::hovered() |
|
286 | 286 | */ |
|
287 | 287 | |
|
288 | 288 | /*! |
|
289 | 289 | Constructs an empty slice with a \a parent. |
|
290 | 290 | |
|
291 | 291 | \sa QPieSeries::append(), QPieSeries::insert() |
|
292 | 292 | */ |
|
293 | 293 | QPieSlice::QPieSlice(QObject *parent) |
|
294 | 294 | :QObject(parent), |
|
295 | 295 | d_ptr(new QPieSlicePrivate(this)) |
|
296 | 296 | { |
|
297 | 297 | |
|
298 | 298 | } |
|
299 | 299 | |
|
300 | 300 | /*! |
|
301 | 301 | Constructs an empty slice with given \a value, \a label and a \a parent. |
|
302 | 302 | \sa QPieSeries::append(), QPieSeries::insert() |
|
303 | 303 | */ |
|
304 | 304 | QPieSlice::QPieSlice(QString label, qreal value, QObject *parent) |
|
305 | 305 | :QObject(parent), |
|
306 | 306 | d_ptr(new QPieSlicePrivate(this)) |
|
307 | 307 | { |
|
308 | 308 | setValue(value); |
|
309 | 309 | setLabel(label); |
|
310 | 310 | } |
|
311 | 311 | |
|
312 | 312 | /*! |
|
313 | 313 | Destroys the slice. |
|
314 | 314 | User should not delete the slice if it has been added to the series. |
|
315 | 315 | */ |
|
316 | 316 | QPieSlice::~QPieSlice() |
|
317 | 317 | { |
|
318 | 318 | |
|
319 | 319 | } |
|
320 | 320 | |
|
321 | 321 | void QPieSlice::setLabel(QString label) |
|
322 | 322 | { |
|
323 | 323 | if (d_ptr->m_data.m_labelText != label) { |
|
324 | 324 | d_ptr->m_data.m_labelText = label; |
|
325 | 325 | emit labelChanged(); |
|
326 | 326 | } |
|
327 | 327 | } |
|
328 | 328 | |
|
329 | 329 | QString QPieSlice::label() const |
|
330 | 330 | { |
|
331 | 331 | return d_ptr->m_data.m_labelText; |
|
332 | 332 | } |
|
333 | 333 | |
|
334 | 334 | void QPieSlice::setValue(qreal value) |
|
335 | 335 | { |
|
336 | 336 | value = qAbs(value); // negative values not allowed |
|
337 | 337 | if (!qFuzzyIsNull(d_ptr->m_data.m_value - value)) { |
|
338 | 338 | d_ptr->m_data.m_value = value; |
|
339 | 339 | emit valueChanged(); |
|
340 | 340 | } |
|
341 | 341 | } |
|
342 | 342 | |
|
343 | 343 | qreal QPieSlice::value() const |
|
344 | 344 | { |
|
345 | 345 | return d_ptr->m_data.m_value; |
|
346 | 346 | } |
|
347 | 347 | |
|
348 | 348 | void QPieSlice::setLabelVisible(bool visible) |
|
349 | 349 | { |
|
350 | 350 | if (d_ptr->m_data.m_isLabelVisible != visible) { |
|
351 | 351 | d_ptr->m_data.m_isLabelVisible = visible; |
|
352 | 352 | emit labelVisibleChanged(); |
|
353 | 353 | } |
|
354 | 354 | } |
|
355 | 355 | |
|
356 | 356 | bool QPieSlice::isLabelVisible() const |
|
357 | 357 | { |
|
358 | 358 | return d_ptr->m_data.m_isLabelVisible; |
|
359 | 359 | } |
|
360 | 360 | |
|
361 | 361 | void QPieSlice::setExploded(bool exploded) |
|
362 | 362 | { |
|
363 | 363 | if (d_ptr->m_data.m_isExploded != exploded) { |
|
364 | 364 | d_ptr->m_data.m_isExploded = exploded; |
|
365 | 365 | emit explodedChanged(); |
|
366 | 366 | } |
|
367 | 367 | } |
|
368 | 368 | |
|
369 | 369 | bool QPieSlice::isExploded() const |
|
370 | 370 | { |
|
371 | 371 | return d_ptr->m_data.m_isExploded; |
|
372 | 372 | } |
|
373 | 373 | |
|
374 | 374 | void QPieSlice::setPen(const QPen &pen) |
|
375 | 375 | { |
|
376 | 376 | d_ptr->setPen(pen, false); |
|
377 | 377 | } |
|
378 | 378 | |
|
379 | 379 | QPen QPieSlice::pen() const |
|
380 | 380 | { |
|
381 | 381 | return d_ptr->m_data.m_slicePen; |
|
382 | 382 | } |
|
383 | 383 | |
|
384 | 384 | void QPieSlice::setBrush(const QBrush &brush) |
|
385 | 385 | { |
|
386 | 386 | d_ptr->setBrush(brush, false); |
|
387 | 387 | } |
|
388 | 388 | |
|
389 | 389 | QBrush QPieSlice::brush() const |
|
390 | 390 | { |
|
391 | 391 | return d_ptr->m_data.m_sliceBrush; |
|
392 | 392 | } |
|
393 | 393 | |
|
394 | 394 | void QPieSlice::setLabelBrush(const QBrush &brush) |
|
395 | 395 | { |
|
396 | 396 | d_ptr->setLabelBrush(brush, false); |
|
397 | 397 | } |
|
398 | 398 | |
|
399 | 399 | QBrush QPieSlice::labelBrush() const |
|
400 | 400 | { |
|
401 | 401 | return d_ptr->m_data.m_labelBrush; |
|
402 | 402 | } |
|
403 | 403 | |
|
404 | 404 | void QPieSlice::setLabelFont(const QFont &font) |
|
405 | 405 | { |
|
406 | 406 | d_ptr->setLabelFont(font, false); |
|
407 | 407 | } |
|
408 | 408 | |
|
409 | 409 | QFont QPieSlice::labelFont() const |
|
410 | 410 | { |
|
411 | 411 | return d_ptr->m_data.m_labelFont; |
|
412 | 412 | } |
|
413 | 413 | |
|
414 | 414 | void QPieSlice::setLabelArmLengthFactor(qreal factor) |
|
415 | 415 | { |
|
416 | 416 | if (!qFuzzyIsNull(d_ptr->m_data.m_labelArmLengthFactor - factor)) { |
|
417 | 417 | d_ptr->m_data.m_labelArmLengthFactor = factor; |
|
418 | 418 | emit labelArmLengthFactorChanged(); |
|
419 | 419 | } |
|
420 | 420 | } |
|
421 | 421 | |
|
422 | 422 | qreal QPieSlice::labelArmLengthFactor() const |
|
423 | 423 | { |
|
424 | 424 | return d_ptr->m_data.m_labelArmLengthFactor; |
|
425 | 425 | } |
|
426 | 426 | |
|
427 | 427 | void QPieSlice::setExplodeDistanceFactor(qreal factor) |
|
428 | 428 | { |
|
429 | 429 | if (!qFuzzyIsNull(d_ptr->m_data.m_explodeDistanceFactor - factor)) { |
|
430 | 430 | d_ptr->m_data.m_explodeDistanceFactor = factor; |
|
431 | 431 | emit explodeDistanceFactorChanged(); |
|
432 | 432 | } |
|
433 | 433 | } |
|
434 | 434 | |
|
435 | 435 | qreal QPieSlice::explodeDistanceFactor() const |
|
436 | 436 | { |
|
437 | 437 | return d_ptr->m_data.m_explodeDistanceFactor; |
|
438 | 438 | } |
|
439 | 439 | |
|
440 | 440 | qreal QPieSlice::percentage() const |
|
441 | 441 | { |
|
442 | 442 | return d_ptr->m_data.m_percentage; |
|
443 | 443 | } |
|
444 | 444 | |
|
445 | 445 | qreal QPieSlice::startAngle() const |
|
446 | 446 | { |
|
447 | 447 | return d_ptr->m_data.m_startAngle; |
|
448 | 448 | } |
|
449 | 449 | |
|
450 | 450 | qreal QPieSlice::angleSpan() const |
|
451 | 451 | { |
|
452 | 452 | return d_ptr->m_data.m_angleSpan; |
|
453 | 453 | } |
|
454 | 454 | |
|
455 | QColor QPieSlice::color() | |
|
456 | { | |
|
457 | return brush().color(); | |
|
458 | } | |
|
459 | ||
|
460 | void QPieSlice::setColor(QColor color) | |
|
461 | { | |
|
462 | QBrush b = brush(); | |
|
463 | if (color != b.color()) { | |
|
464 | b.setColor(color); | |
|
465 | setBrush(b); | |
|
466 | } | |
|
467 | } | |
|
468 | ||
|
469 | QColor QPieSlice::borderColor() | |
|
470 | { | |
|
471 | return pen().color(); | |
|
472 | } | |
|
473 | ||
|
474 | void QPieSlice::setBorderColor(QColor color) | |
|
475 | { | |
|
476 | QPen p = pen(); | |
|
477 | if (color != p.color()) { | |
|
478 | p.setColor(color); | |
|
479 | setPen(p); | |
|
480 | emit borderColorChanged(); | |
|
481 | } | |
|
482 | } | |
|
483 | ||
|
484 | int QPieSlice::borderWidth() | |
|
485 | { | |
|
486 | return pen().width(); | |
|
487 | } | |
|
488 | ||
|
489 | void QPieSlice::setBorderWidth(int width) | |
|
490 | { | |
|
491 | QPen p = pen(); | |
|
492 | if (width != p.width()) { | |
|
493 | p.setWidth(width); | |
|
494 | setPen(p); | |
|
495 | } | |
|
496 | } | |
|
497 | ||
|
498 | QColor QPieSlice::labelColor() | |
|
499 | { | |
|
500 | return labelBrush().color(); | |
|
501 | } | |
|
502 | ||
|
503 | void QPieSlice::setLabelColor(QColor color) | |
|
504 | { | |
|
505 | QBrush b = labelBrush(); | |
|
506 | if (color != b.color()) { | |
|
507 | b.setColor(color); | |
|
508 | setLabelBrush(b); | |
|
509 | } | |
|
510 | } | |
|
511 | ||
|
455 | 512 | /*! |
|
456 | 513 | Returns the series that this slice belongs to. |
|
457 | 514 | |
|
458 | 515 | \sa QPieSeries::append() |
|
459 | 516 | */ |
|
460 | 517 | QPieSeries *QPieSlice::series() const |
|
461 | 518 | { |
|
462 | 519 | return d_ptr->m_series; |
|
463 | 520 | } |
|
464 | 521 | |
|
465 | 522 | QPieSlicePrivate::QPieSlicePrivate(QPieSlice *parent) |
|
466 | 523 | :QObject(parent), |
|
467 | 524 | q_ptr(parent), |
|
468 | 525 | m_series(0) |
|
469 | 526 | { |
|
470 | 527 | |
|
471 | 528 | } |
|
472 | 529 | |
|
473 | 530 | QPieSlicePrivate::~QPieSlicePrivate() |
|
474 | 531 | { |
|
475 | 532 | |
|
476 | 533 | } |
|
477 | 534 | |
|
478 | 535 | QPieSlicePrivate *QPieSlicePrivate::fromSlice(QPieSlice *slice) |
|
479 | 536 | { |
|
480 | 537 | return slice->d_func(); |
|
481 | 538 | } |
|
482 | 539 | |
|
483 | 540 | void QPieSlicePrivate::setPen(const QPen &pen, bool themed) |
|
484 | 541 | { |
|
485 | 542 | if (m_data.m_slicePen != pen) { |
|
543 | if (m_data.m_slicePen.color() != pen.color()) | |
|
544 | emit q_ptr->borderColorChanged(); | |
|
545 | if (m_data.m_slicePen.width() != pen.width()) | |
|
546 | emit q_ptr->borderWidthChanged(); | |
|
486 | 547 | m_data.m_slicePen = pen; |
|
487 | 548 | m_data.m_slicePen.setThemed(themed); |
|
488 | 549 | emit q_ptr->penChanged(); |
|
489 | 550 | } |
|
490 | 551 | } |
|
491 | 552 | |
|
492 | 553 | void QPieSlicePrivate::setBrush(const QBrush &brush, bool themed) |
|
493 | 554 | { |
|
494 | 555 | if (m_data.m_sliceBrush != brush) { |
|
556 | if (m_data.m_sliceBrush.color() != brush.color()) | |
|
557 | emit q_ptr->colorChanged(); | |
|
495 | 558 | m_data.m_sliceBrush = brush; |
|
496 | 559 | m_data.m_sliceBrush.setThemed(themed); |
|
497 | 560 | emit q_ptr->brushChanged(); |
|
498 | 561 | } |
|
499 | 562 | } |
|
500 | 563 | |
|
501 | 564 | void QPieSlicePrivate::setLabelBrush(const QBrush &brush, bool themed) |
|
502 | 565 | { |
|
503 | 566 | if (m_data.m_labelBrush != brush) { |
|
567 | if (m_data.m_labelBrush.color() != brush.color()) | |
|
568 | emit q_ptr->labelColorChanged(); | |
|
504 | 569 | m_data.m_labelBrush = brush; |
|
505 | 570 | m_data.m_labelBrush.setThemed(themed); |
|
506 | 571 | emit q_ptr->labelBrushChanged(); |
|
507 | 572 | } |
|
508 | 573 | } |
|
509 | 574 | |
|
510 | 575 | void QPieSlicePrivate::setLabelFont(const QFont &font, bool themed) |
|
511 | 576 | { |
|
512 | 577 | if (m_data.m_labelFont != font) { |
|
513 | 578 | m_data.m_labelFont = font; |
|
514 | 579 | m_data.m_labelFont.setThemed(themed); |
|
515 | 580 | emit q_ptr->labelFontChanged(); |
|
516 | 581 | } |
|
517 | 582 | } |
|
518 | 583 | |
|
519 | 584 | void QPieSlicePrivate::setPercentage(qreal percentage) |
|
520 | 585 | { |
|
521 | 586 | if (!qFuzzyIsNull(m_data.m_percentage - percentage)) { |
|
522 | 587 | m_data.m_percentage = percentage; |
|
523 | 588 | emit q_ptr->percentageChanged(); |
|
524 | 589 | } |
|
525 | 590 | } |
|
526 | 591 | |
|
527 | 592 | void QPieSlicePrivate::setStartAngle(qreal angle) |
|
528 | 593 | { |
|
529 | 594 | if (!qFuzzyIsNull(m_data.m_startAngle - angle)) { |
|
530 | 595 | m_data.m_startAngle = angle; |
|
531 | 596 | emit q_ptr->startAngleChanged(); |
|
532 | 597 | } |
|
533 | 598 | } |
|
534 | 599 | |
|
535 | 600 | void QPieSlicePrivate::setAngleSpan(qreal span) |
|
536 | 601 | { |
|
537 | 602 | if (!qFuzzyIsNull(m_data.m_angleSpan - span)) { |
|
538 | 603 | m_data.m_angleSpan = span; |
|
539 | 604 | emit q_ptr->angleSpanChanged(); |
|
540 | 605 | } |
|
541 | 606 | } |
|
542 | 607 | |
|
543 | 608 | QTCOMMERCIALCHART_END_NAMESPACE |
|
544 | 609 | |
|
545 | 610 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
546 | 611 | #include "moc_qpieslice.cpp" |
|
547 | 612 | #include "moc_qpieslice_p.cpp" |
@@ -1,117 +1,134 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #ifndef QPIESLICE_H |
|
22 | 22 | #define QPIESLICE_H |
|
23 | 23 | |
|
24 | 24 | #include <qchartglobal.h> |
|
25 | 25 | #include <QObject> |
|
26 | 26 | #include <QPen> |
|
27 | 27 | #include <QBrush> |
|
28 | 28 | #include <QFont> |
|
29 | 29 | |
|
30 | 30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
31 | 31 | class QPieSlicePrivate; |
|
32 | 32 | class QPieSeries; |
|
33 | 33 | |
|
34 | 34 | class QTCOMMERCIALCHART_EXPORT QPieSlice : public QObject |
|
35 | 35 | { |
|
36 | 36 | Q_OBJECT |
|
37 | 37 | Q_PROPERTY(QString label READ label WRITE setLabel NOTIFY labelChanged) |
|
38 | 38 | Q_PROPERTY(qreal value READ value WRITE setValue NOTIFY valueChanged) |
|
39 | 39 | Q_PROPERTY(bool labelVisible READ isLabelVisible WRITE setLabelVisible NOTIFY labelVisibleChanged) |
|
40 | 40 | Q_PROPERTY(bool exploded READ isExploded WRITE setExploded NOTIFY explodedChanged) |
|
41 | 41 | Q_PROPERTY(QPen pen READ pen WRITE setPen NOTIFY penChanged) |
|
42 | 42 | Q_PROPERTY(QBrush brush READ brush WRITE setBrush NOTIFY brushChanged) |
|
43 | 43 | Q_PROPERTY(QBrush labelBrush READ labelBrush WRITE setLabelBrush NOTIFY labelBrushChanged) |
|
44 | 44 | Q_PROPERTY(QFont labelFont READ labelFont WRITE setLabelFont NOTIFY labelFontChanged) |
|
45 | 45 | Q_PROPERTY(qreal labelArmLengthFactor READ labelArmLengthFactor WRITE setLabelArmLengthFactor) |
|
46 | 46 | Q_PROPERTY(qreal explodeDistanceFactor READ explodeDistanceFactor WRITE setExplodeDistanceFactor) |
|
47 | 47 | Q_PROPERTY(qreal percentage READ percentage NOTIFY percentageChanged) |
|
48 | 48 | Q_PROPERTY(qreal startAngle READ startAngle NOTIFY startAngleChanged) |
|
49 | 49 | Q_PROPERTY(qreal angleSpan READ angleSpan NOTIFY angleSpanChanged) |
|
50 | Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged) | |
|
51 | Q_PROPERTY(QColor borderColor READ borderColor WRITE setBorderColor NOTIFY borderColorChanged) | |
|
52 | Q_PROPERTY(int borderWidth READ borderWidth WRITE setBorderWidth NOTIFY borderWidthChanged) | |
|
53 | Q_PROPERTY(QColor labelColor READ labelColor WRITE setLabelColor NOTIFY labelColorChanged) | |
|
50 | 54 | |
|
51 | 55 | public: |
|
52 | 56 | explicit QPieSlice(QObject *parent = 0); |
|
53 | 57 | QPieSlice(QString label, qreal value, QObject *parent = 0); |
|
54 | 58 | virtual ~QPieSlice(); |
|
55 | 59 | |
|
56 | 60 | void setLabel(QString label); |
|
57 | 61 | QString label() const; |
|
58 | 62 | |
|
59 | 63 | void setValue(qreal value); |
|
60 | 64 | qreal value() const; |
|
61 | 65 | |
|
62 | 66 | void setLabelVisible(bool visible = true); |
|
63 | 67 | bool isLabelVisible() const; |
|
64 | 68 | |
|
65 | 69 | void setExploded(bool exploded = true); |
|
66 | 70 | bool isExploded() const; |
|
67 | 71 | |
|
68 | 72 | void setPen(const QPen &pen); |
|
69 | 73 | QPen pen() const; |
|
70 | 74 | |
|
71 | 75 | void setBrush(const QBrush &brush); |
|
72 | 76 | QBrush brush() const; |
|
73 | 77 | |
|
74 | 78 | void setLabelBrush(const QBrush &brush); |
|
75 | 79 | QBrush labelBrush() const; |
|
76 | 80 | |
|
77 | 81 | void setLabelFont(const QFont &font); |
|
78 | 82 | QFont labelFont() const; |
|
79 | 83 | |
|
80 | 84 | void setLabelArmLengthFactor(qreal factor); |
|
81 | 85 | qreal labelArmLengthFactor() const; |
|
82 | 86 | |
|
83 | 87 | void setExplodeDistanceFactor(qreal factor); |
|
84 | 88 | qreal explodeDistanceFactor() const; |
|
85 | 89 | |
|
86 | 90 | qreal percentage() const; |
|
87 | 91 | qreal startAngle() const; |
|
88 | 92 | qreal angleSpan() const; |
|
89 | 93 | |
|
94 | QColor color(); | |
|
95 | void setColor(QColor color); | |
|
96 | QColor borderColor(); | |
|
97 | void setBorderColor(QColor color); | |
|
98 | int borderWidth(); | |
|
99 | void setBorderWidth(int width); | |
|
100 | QColor labelColor(); | |
|
101 | void setLabelColor(QColor color); | |
|
102 | ||
|
90 | 103 | QPieSeries *series() const; |
|
91 | 104 | |
|
92 | 105 | Q_SIGNALS: |
|
93 | 106 | void labelChanged(); |
|
94 | 107 | void valueChanged(); |
|
95 | 108 | void labelVisibleChanged(); |
|
96 | 109 | void explodedChanged(); |
|
97 | 110 | void penChanged(); |
|
98 | 111 | void brushChanged(); |
|
99 | 112 | void labelBrushChanged(); |
|
100 | 113 | void labelFontChanged(); |
|
101 | 114 | void labelArmLengthFactorChanged(); |
|
102 | 115 | void explodeDistanceFactorChanged(); |
|
103 | 116 | void percentageChanged(); |
|
104 | 117 | void startAngleChanged(); |
|
105 | 118 | void angleSpanChanged(); |
|
119 | void colorChanged(); | |
|
120 | void borderColorChanged(); | |
|
121 | void borderWidthChanged(); | |
|
122 | void labelColorChanged(); | |
|
106 | 123 | void clicked(); |
|
107 | 124 | void hovered(bool state); |
|
108 | 125 | |
|
109 | 126 | private: |
|
110 | 127 | QPieSlicePrivate * const d_ptr; |
|
111 | 128 | Q_DECLARE_PRIVATE(QPieSlice) |
|
112 | 129 | Q_DISABLE_COPY(QPieSlice) |
|
113 | 130 | }; |
|
114 | 131 | |
|
115 | 132 | QTCOMMERCIALCHART_END_NAMESPACE |
|
116 | 133 | |
|
117 | 134 | #endif // QPIESLICE_H |
General Comments 0
You need to be logged in to leave comments.
Login now