@@ -0,0 +1,94 | |||
|
1 | /**************************************************************************** | |
|
2 | ** | |
|
3 | ** Copyright (C) 2012 Digia Plc | |
|
4 | ** All rights reserved. | |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
|
6 | ** | |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
|
8 | ** | |
|
9 | ** $QT_BEGIN_LICENSE$ | |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
|
13 | ** a written agreement between you and Digia. | |
|
14 | ** | |
|
15 | ** If you have questions regarding the use of this file, please use | |
|
16 | ** contact form at http://qt.digia.com | |
|
17 | ** $QT_END_LICENSE$ | |
|
18 | ** | |
|
19 | ****************************************************************************/ | |
|
20 | ||
|
21 | import QtQuick 1.0 | |
|
22 | import QtCommercial.Chart 1.0 | |
|
23 | ||
|
24 | ||
|
25 | Flow { | |
|
26 | id: flow | |
|
27 | spacing: 5 | |
|
28 | flow: Flow.TopToBottom | |
|
29 | property variant series // TODO: rename to chart | |
|
30 | ||
|
31 | Connections { | |
|
32 | target: series | |
|
33 | onVisibleChanged: console.log("chart.onVisibleChanged: " + series.visible); | |
|
34 | onThemeChanged: console.log("chart.onThemeChanged: " + series.theme); | |
|
35 | onLegendChanged: console.log("chart.onLegendChanged: " + series.legend); | |
|
36 | onAnimationOptionsChanged: console.log("chart.onAnimationOptionsChanged: " + series.animationOptions); | |
|
37 | onTitleColorChanged: console.log("chart.onTitleColorChanged: " + series.titleColor); | |
|
38 | onBackgroundColorChanged: console.log("chart.onBackgroundColorChanged: " + series.backgroundColor); | |
|
39 | } | |
|
40 | Connections { | |
|
41 | target: series.legend | |
|
42 | onAlignmentChanged: console.log("legend.onAlignmentChanged: " + series.legend.alignment); | |
|
43 | onVisibleChanged: console.log("legend.onVisibleChanged: " + series.legend.visible); | |
|
44 | } | |
|
45 | ||
|
46 | Button { | |
|
47 | text: "visible" | |
|
48 | onClicked: series.visible = !series.visible; | |
|
49 | } | |
|
50 | Button { | |
|
51 | text: "theme +" | |
|
52 | onClicked: series.theme++; | |
|
53 | } | |
|
54 | Button { | |
|
55 | text: "theme -" | |
|
56 | onClicked: series.theme--; | |
|
57 | } | |
|
58 | Button { | |
|
59 | text: "legend top" | |
|
60 | onClicked: series.legend.alignment ^= Qt.AlignTop; | |
|
61 | } | |
|
62 | Button { | |
|
63 | text: "legend bottom" | |
|
64 | onClicked: series.legend.alignment ^= Qt.AlignBottom; | |
|
65 | } | |
|
66 | Button { | |
|
67 | text: "legend left" | |
|
68 | onClicked: series.legend.alignment ^= Qt.AlignLeft; | |
|
69 | } | |
|
70 | Button { | |
|
71 | text: "legend right" | |
|
72 | onClicked: series.legend.alignment ^= Qt.AlignRight; | |
|
73 | } | |
|
74 | Button { | |
|
75 | text: "legend visible" | |
|
76 | onClicked: series.legend.visible = !series.legend.visible; | |
|
77 | } | |
|
78 | Button { | |
|
79 | text: "animation opt +" | |
|
80 | onClicked: series.animationOptions++; | |
|
81 | } | |
|
82 | Button { | |
|
83 | text: "animation opt -" | |
|
84 | onClicked: series.animationOptions--; | |
|
85 | } | |
|
86 | Button { | |
|
87 | text: "title color" | |
|
88 | onClicked: series.titleColor = main.nextColor(); | |
|
89 | } | |
|
90 | Button { | |
|
91 | text: "background color" | |
|
92 | onClicked: series.backgroundColor = main.nextColor(); | |
|
93 | } | |
|
94 | } |
@@ -167,10 +167,10 QComboBox* ThemeWidget::createLegendBox() const | |||
|
167 | 167 | { |
|
168 | 168 | QComboBox* legendComboBox = new QComboBox(); |
|
169 | 169 | legendComboBox->addItem("No Legend ", 0); |
|
170 |
legendComboBox->addItem("Legend Top", Q |
|
|
171 |
legendComboBox->addItem("Legend Bottom", Q |
|
|
172 |
legendComboBox->addItem("Legend Left", Q |
|
|
173 |
legendComboBox->addItem("Legend Right", Q |
|
|
170 | legendComboBox->addItem("Legend Top", Qt::AlignTop); | |
|
171 | legendComboBox->addItem("Legend Bottom", Qt::AlignBottom); | |
|
172 | legendComboBox->addItem("Legend Left", Qt::AlignLeft); | |
|
173 | legendComboBox->addItem("Legend Right", Qt::AlignRight); | |
|
174 | 174 | return legendComboBox; |
|
175 | 175 | } |
|
176 | 176 | |
@@ -361,7 +361,7 void ThemeWidget::updateUI() | |||
|
361 | 361 | chartView->chart()->setAnimationOptions(options); |
|
362 | 362 | } |
|
363 | 363 | |
|
364 |
Q |
|
|
364 | Qt::Alignment alignment(m_legendComboBox->itemData(m_legendComboBox->currentIndex()).toInt()); | |
|
365 | 365 | |
|
366 | 366 | if (!alignment) { |
|
367 | 367 | foreach (QChartView *chartView, m_charts) { |
@@ -62,7 +62,7 int main(int argc, char *argv[]) | |||
|
62 | 62 | |
|
63 | 63 | //![4] |
|
64 | 64 | chart->legend()->setVisible(true); |
|
65 |
chart->legend()->setAlignment(Q |
|
|
65 | chart->legend()->setAlignment(Qt::AlignBottom); | |
|
66 | 66 | chart->axisY()->setNiceNumbersEnabled(true); |
|
67 | 67 | //![4] |
|
68 | 68 |
@@ -70,7 +70,7 int main(int argc, char *argv[]) | |||
|
70 | 70 | |
|
71 | 71 | //![5] |
|
72 | 72 | chart->legend()->setVisible(true); |
|
73 |
chart->legend()->setAlignment(Q |
|
|
73 | chart->legend()->setAlignment(Qt::AlignBottom); | |
|
74 | 74 | chart->axisY()->setNiceNumbersEnabled(true); |
|
75 | 75 | //![5] |
|
76 | 76 |
@@ -66,7 +66,7 void MainWidget::createSeries() | |||
|
66 | 66 | m_chart->setTitle("Legend detach example"); |
|
67 | 67 | |
|
68 | 68 | m_chart->legend()->setVisible(true); |
|
69 |
m_chart->legend()->setAlignment(Q |
|
|
69 | m_chart->legend()->setAlignment(Qt::AlignBottom); | |
|
70 | 70 | m_chart->axisY()->setNiceNumbersEnabled(true); |
|
71 | 71 | |
|
72 | 72 | m_chartView->setRenderHint(QPainter::Antialiasing); |
@@ -68,7 +68,7 int main(int argc, char *argv[]) | |||
|
68 | 68 | |
|
69 | 69 | //![5] |
|
70 | 70 | chart->legend()->setVisible(true); |
|
71 |
chart->legend()->setAlignment(Q |
|
|
71 | chart->legend()->setAlignment(Qt::AlignBottom); | |
|
72 | 72 | //![5] |
|
73 | 73 | |
|
74 | 74 | //![6] |
@@ -41,7 +41,7 int main(int argc, char *argv[]) | |||
|
41 | 41 | chart->setTheme(QChart::ChartThemeLight); |
|
42 | 42 | chart->setAnimationOptions(QChart::AllAnimations); |
|
43 | 43 | chart->legend()->setVisible(true); |
|
44 |
chart->legend()->setAlignment(Q |
|
|
44 | chart->legend()->setAlignment(Qt::AlignRight); | |
|
45 | 45 | |
|
46 | 46 | QPieSeries* yearSeries = new QPieSeries(&window); |
|
47 | 47 | yearSeries->setName("Sales by year - All"); |
@@ -68,7 +68,7 int main(int argc, char *argv[]) | |||
|
68 | 68 | |
|
69 | 69 | //![5] |
|
70 | 70 | chart->legend()->setVisible(true); |
|
71 |
chart->legend()->setAlignment(Q |
|
|
71 | chart->legend()->setAlignment(Qt::AlignBottom); | |
|
72 | 72 | chart->axisY()->setNiceNumbersEnabled(true); |
|
73 | 73 | //![5] |
|
74 | 74 |
@@ -104,7 +104,7 int main(int argc, char *argv[]) | |||
|
104 | 104 | drilldownChart->axisX()->setGridLineVisible(false); |
|
105 | 105 | drilldownChart->axisY()->setNiceNumbersEnabled(true); |
|
106 | 106 | drilldownChart->legend()->setVisible(true); |
|
107 |
drilldownChart->legend()->setAlignment(Q |
|
|
107 | drilldownChart->legend()->setAlignment(Qt::AlignBottom); | |
|
108 | 108 | //! [7] |
|
109 | 109 | |
|
110 | 110 | QChartView *chartView = new QChartView(drilldownChart); |
@@ -31,8 +31,7 QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||
|
31 | 31 | |
|
32 | 32 | DeclarativeChart::DeclarativeChart(QDeclarativeItem *parent) |
|
33 | 33 | : QDeclarativeItem(parent), |
|
34 |
m_chart(new QChart(this)) |
|
|
35 | m_legend(LegendTop) | |
|
34 | m_chart(new QChart(this)) | |
|
36 | 35 | { |
|
37 | 36 | setFlag(QGraphicsItem::ItemHasNoContents, false); |
|
38 | 37 | // m_chart->axisX()->setNiceNumbersEnabled(false); |
@@ -88,7 +87,11 void DeclarativeChart::paint(QPainter *painter, const QStyleOptionGraphicsItem * | |||
|
88 | 87 | |
|
89 | 88 | void DeclarativeChart::setTheme(DeclarativeChart::Theme theme) |
|
90 | 89 | { |
|
91 |
|
|
|
90 | QChart::ChartTheme chartTheme = (QChart::ChartTheme) theme; | |
|
91 | if (chartTheme != m_chart->theme()) { | |
|
92 | m_chart->setTheme(chartTheme); | |
|
93 | themeChanged(); | |
|
94 | } | |
|
92 | 95 | } |
|
93 | 96 | |
|
94 | 97 | DeclarativeChart::Theme DeclarativeChart::theme() |
@@ -98,7 +101,11 DeclarativeChart::Theme DeclarativeChart::theme() | |||
|
98 | 101 | |
|
99 | 102 | void DeclarativeChart::setAnimationOptions(DeclarativeChart::Animation animations) |
|
100 | 103 | { |
|
101 |
|
|
|
104 | QChart::AnimationOption animationOptions = (QChart::AnimationOption) animations; | |
|
105 | if (animationOptions != m_chart->animationOptions()) { | |
|
106 | m_chart->setAnimationOptions(animationOptions); | |
|
107 | animationOptionsChanged(); | |
|
108 | } | |
|
102 | 109 | } |
|
103 | 110 | |
|
104 | 111 | DeclarativeChart::Animation DeclarativeChart::animationOptions() |
@@ -113,40 +120,16 DeclarativeChart::Animation DeclarativeChart::animationOptions() | |||
|
113 | 120 | return DeclarativeChart::NoAnimation; |
|
114 | 121 | } |
|
115 | 122 | |
|
116 |
void DeclarativeChart::set |
|
|
117 | { | |
|
118 |
if (le |
|
|
119 | m_legend = legend; | |
|
120 |
|
|
|
121 | case LegendDisabled: | |
|
122 | m_chart->legend()->setVisible(false); | |
|
123 | break; | |
|
124 | case LegendTop: | |
|
125 | m_chart->legend()->setVisible(true); | |
|
126 | m_chart->legend()->setAlignment(QLegend::AlignmentTop); | |
|
127 | break; | |
|
128 | case LegendBottom: | |
|
129 | m_chart->legend()->setVisible(true); | |
|
130 | m_chart->legend()->setAlignment(QLegend::AlignmentBottom); | |
|
131 | break; | |
|
132 | case LegendLeft: | |
|
133 | m_chart->legend()->setVisible(true); | |
|
134 | m_chart->legend()->setAlignment(QLegend::AlignmentLeft); | |
|
135 | break; | |
|
136 | case LegendRight: | |
|
137 | m_chart->legend()->setVisible(true); | |
|
138 | m_chart->legend()->setAlignment(QLegend::AlignmentRight); | |
|
139 | break; | |
|
140 | default: | |
|
141 | m_chart->legend()->setVisible(false); | |
|
142 | break; | |
|
143 | } | |
|
123 | void DeclarativeChart::setTitle(QString title) | |
|
124 | { | |
|
125 | if (title != m_chart->title()) { | |
|
126 | m_chart->setTitle(title); | |
|
127 | emit titleChanged(); | |
|
144 | 128 | } |
|
145 | 129 | } |
|
146 | ||
|
147 | DeclarativeChart::Legend DeclarativeChart::legend() | |
|
130 | QString DeclarativeChart::title() | |
|
148 | 131 | { |
|
149 |
return m_ |
|
|
132 | return m_chart->title(); | |
|
150 | 133 | } |
|
151 | 134 | |
|
152 | 135 | QAxis *DeclarativeChart::axisX() |
@@ -159,6 +142,11 QAxis *DeclarativeChart::axisY() | |||
|
159 | 142 | return m_chart->axisY(); |
|
160 | 143 | } |
|
161 | 144 | |
|
145 | QLegend *DeclarativeChart::legend() | |
|
146 | { | |
|
147 | return m_chart->legend(); | |
|
148 | } | |
|
149 | ||
|
162 | 150 | QVariantList DeclarativeChart::axisXLabels() |
|
163 | 151 | { |
|
164 | 152 | QVariantList labels; |
@@ -181,6 +169,37 void DeclarativeChart::setAxisXLabels(QVariantList list) | |||
|
181 | 169 | value = element; |
|
182 | 170 | } |
|
183 | 171 | } |
|
172 | emit axisLabelsChanged(); | |
|
173 | } | |
|
174 | ||
|
175 | void DeclarativeChart::setTitleColor(QColor color) | |
|
176 | { | |
|
177 | QBrush b = m_chart->titleBrush(); | |
|
178 | if (color != b.color()) { | |
|
179 | b.setColor(color); | |
|
180 | m_chart->setTitleBrush(b); | |
|
181 | emit titleColorChanged(); | |
|
182 | } | |
|
183 | } | |
|
184 | ||
|
185 | QColor DeclarativeChart::titleColor() | |
|
186 | { | |
|
187 | return m_chart->titleBrush().color(); | |
|
188 | } | |
|
189 | ||
|
190 | void DeclarativeChart::setBackgroundColor(QColor color) | |
|
191 | { | |
|
192 | QBrush b = m_chart->backgroundBrush(); | |
|
193 | if (color != b.color()) { | |
|
194 | b.setColor(color); | |
|
195 | m_chart->setBackgroundBrush(b); | |
|
196 | emit backgroundColorChanged(); | |
|
197 | } | |
|
198 | } | |
|
199 | ||
|
200 | QColor DeclarativeChart::backgroundColor() | |
|
201 | { | |
|
202 | return m_chart->backgroundBrush().color(); | |
|
184 | 203 | } |
|
185 | 204 | |
|
186 | 205 | int DeclarativeChart::count() |
@@ -34,18 +34,19 class DeclarativeChart : public QDeclarativeItem | |||
|
34 | 34 | //class DeclarativeChart : public QQuickPaintedItem, public Chart |
|
35 | 35 | { |
|
36 | 36 | Q_OBJECT |
|
37 | Q_PROPERTY(Theme theme READ theme WRITE setTheme) | |
|
38 | Q_PROPERTY(Animation animationOptions READ animationOptions WRITE setAnimationOptions) | |
|
39 | Q_PROPERTY(QString title READ title WRITE setTitle) | |
|
40 | Q_PROPERTY(Legend legend READ legend WRITE setLegend) | |
|
37 | Q_PROPERTY(Theme theme READ theme WRITE setTheme NOTIFY themeChanged) | |
|
38 | Q_PROPERTY(Animation animationOptions READ animationOptions WRITE setAnimationOptions NOTIFY animationOptionsChanged) | |
|
39 | Q_PROPERTY(QString title READ title WRITE setTitle NOTIFY titleChanged) | |
|
41 | 40 | Q_PROPERTY(QAxis *axisX READ axisX) |
|
42 | 41 | Q_PROPERTY(QAxis *axisY READ axisY) |
|
42 | Q_PROPERTY(QLegend *legend READ legend) | |
|
43 | 43 | // TODO: how to define axis labels? This is not very convenient |
|
44 | Q_PROPERTY(QVariantList axisXLabels READ axisXLabels WRITE setAxisXLabels) | |
|
44 | Q_PROPERTY(QVariantList axisXLabels READ axisXLabels WRITE setAxisXLabels NOTIFY axisLabelsChanged) | |
|
45 | 45 | Q_PROPERTY(int count READ count) |
|
46 | Q_PROPERTY(QColor titleColor READ titleColor WRITE setTitleColor NOTIFY titleColorChanged) | |
|
47 | Q_PROPERTY(QColor backgroundColor READ backgroundColor WRITE setBackgroundColor NOTIFY backgroundColorChanged) | |
|
46 | 48 | Q_ENUMS(Animation) |
|
47 | 49 | Q_ENUMS(Theme) |
|
48 | Q_ENUMS(Legend) | |
|
49 | 50 | Q_ENUMS(SeriesType) |
|
50 | 51 | |
|
51 | 52 | public: |
@@ -67,14 +68,6 public: | |||
|
67 | 68 | AllAnimations = 0x3 |
|
68 | 69 | }; |
|
69 | 70 | |
|
70 | enum Legend { | |
|
71 | LegendDisabled = 0, | |
|
72 | LegendTop, | |
|
73 | LegendBottom, | |
|
74 | LegendLeft, | |
|
75 | LegendRight | |
|
76 | }; | |
|
77 | ||
|
78 | 71 | enum SeriesType { |
|
79 | 72 | SeriesTypeLine, |
|
80 | 73 | SeriesTypeArea, |
@@ -102,24 +95,34 public: | |||
|
102 | 95 | DeclarativeChart::Theme theme(); |
|
103 | 96 | void setAnimationOptions(DeclarativeChart::Animation animations); |
|
104 | 97 | DeclarativeChart::Animation animationOptions(); |
|
105 |
void setTitle(QString title) |
|
|
106 | QString title() { return m_chart->title();} | |
|
107 | void setLegend(DeclarativeChart::Legend legend); | |
|
108 | DeclarativeChart::Legend legend(); | |
|
98 | void setTitle(QString title); | |
|
99 | QString title(); | |
|
109 | 100 | QAxis *axisX(); |
|
110 | 101 | QAxis *axisY(); |
|
102 | QLegend *legend(); | |
|
111 | 103 | QVariantList axisXLabels(); |
|
112 | 104 | void setAxisXLabels(QVariantList list); |
|
105 | void setTitleColor(QColor color); | |
|
106 | QColor titleColor(); | |
|
107 | void setBackgroundColor(QColor color); | |
|
108 | QColor backgroundColor(); | |
|
113 | 109 | int count(); |
|
114 | 110 | Q_INVOKABLE QAbstractSeries *series(int index); |
|
115 | 111 | Q_INVOKABLE QAbstractSeries *series(QString seriesName); |
|
116 | 112 | Q_INVOKABLE QAbstractSeries *createSeries(DeclarativeChart::SeriesType type, QString name = ""); |
|
117 | 113 | |
|
114 | Q_SIGNALS: | |
|
115 | void themeChanged(); | |
|
116 | void animationOptionsChanged(); | |
|
117 | void titleChanged(); | |
|
118 | void axisLabelsChanged(); | |
|
119 | void titleColorChanged(); | |
|
120 | void backgroundColorChanged(); | |
|
121 | ||
|
118 | 122 | public: |
|
119 | 123 | // Extending QChart with DeclarativeChart is not possible because QObject does not support |
|
120 | 124 | // multi inheritance, so we now have a QChart as a member instead |
|
121 | 125 | QChart *m_chart; |
|
122 | Legend m_legend; | |
|
123 | 126 | }; |
|
124 | 127 | |
|
125 | 128 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -67,6 +67,8 public: | |||
|
67 | 67 | qmlRegisterType<QHBarModelMapper>(uri, 1, 0, "HBarModelMapper"); |
|
68 | 68 | qmlRegisterType<QVBarModelMapper>(uri, 1, 0, "VBarModelMapper"); |
|
69 | 69 | |
|
70 | qmlRegisterUncreatableType<QLegend>(uri, 1, 0, "Legend", | |
|
71 | QLatin1String("Trying to create uncreatable: Legend.")); | |
|
70 | 72 | qmlRegisterUncreatableType<QScatterSeries>(uri, 1, 0, "QScatterSeries", |
|
71 | 73 | QLatin1String("Trying to create uncreatable: QScatterSeries.")); |
|
72 | 74 | qmlRegisterUncreatableType<QPieSeries>(uri, 1, 0, "QPieSeries", |
@@ -323,7 +323,7 void ChartPresenter::updateLayout() | |||
|
323 | 323 | // Reserve some space for legend |
|
324 | 324 | switch (legend->alignment()) { |
|
325 | 325 | |
|
326 |
case Q |
|
|
326 | case Qt::AlignTop: { | |
|
327 | 327 | int ledgendSize = legend->minHeight(); |
|
328 | 328 | int topPadding = 2*m_marginTiny + titleSize.height() + ledgendSize + m_marginTiny; |
|
329 | 329 | m_chartMargins = QRect(QPoint(m_chartMargins.left(),topPadding),QPoint(m_chartMargins.right(),m_chartMargins.bottom())); |
@@ -331,7 +331,7 void ChartPresenter::updateLayout() | |||
|
331 | 331 | titlePadding = m_marginTiny + m_marginTiny; |
|
332 | 332 | break; |
|
333 | 333 | } |
|
334 |
case Q |
|
|
334 | case Qt::AlignBottom: { | |
|
335 | 335 | int ledgendSize = legend->minHeight(); |
|
336 | 336 | int bottomPadding = m_marginTiny + m_marginSmall + ledgendSize + m_marginTiny + m_minBottomMargin; |
|
337 | 337 | m_chartMargins = QRect(QPoint(m_chartMargins.left(),m_chartMargins.top()),QPoint(m_chartMargins.right(),bottomPadding)); |
@@ -339,7 +339,7 void ChartPresenter::updateLayout() | |||
|
339 | 339 | titlePadding = m_chartMargins.top()/2; |
|
340 | 340 | break; |
|
341 | 341 | } |
|
342 |
case Q |
|
|
342 | case Qt::AlignLeft: { | |
|
343 | 343 | int ledgendSize = legend->minWidth(); |
|
344 | 344 | int leftPadding = m_marginTiny + m_marginSmall + ledgendSize + m_marginTiny + m_minLeftMargin; |
|
345 | 345 | m_chartMargins = QRect(QPoint(leftPadding,m_chartMargins.top()),QPoint(m_chartMargins.right(),m_chartMargins.bottom())); |
@@ -347,7 +347,7 void ChartPresenter::updateLayout() | |||
|
347 | 347 | titlePadding = m_chartMargins.top()/2; |
|
348 | 348 | break; |
|
349 | 349 | } |
|
350 |
case Q |
|
|
350 | case Qt::AlignRight: { | |
|
351 | 351 | int ledgendSize = legend->minWidth(); |
|
352 | 352 | int rightPadding = m_marginTiny + m_marginSmall + ledgendSize + m_marginTiny; |
|
353 | 353 | m_chartMargins = QRect(QPoint(m_chartMargins.left(),m_chartMargins.top()),QPoint(rightPadding,m_chartMargins.bottom())); |
@@ -62,15 +62,9 QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||
|
62 | 62 | */ |
|
63 | 63 | |
|
64 | 64 | /*! |
|
65 |
|
|
|
66 | ||
|
67 | This enum describes the possible position for legend inside chart. | |
|
68 | ||
|
69 | \value AlignmentTop | |
|
70 | \value AlignmentBottom | |
|
71 | \value AlignmentLeft | |
|
72 | \value AlignmentRight | |
|
73 | */ | |
|
65 | \fn void QLegend::alignmentChanged() | |
|
66 | Emitted when the alignment of the legend changes. | |
|
67 | */ | |
|
74 | 68 | |
|
75 | 69 | /*! |
|
76 | 70 | \fn qreal QLegend::minWidth() const |
@@ -168,21 +162,30 QPen QLegend::pen() const | |||
|
168 | 162 | } |
|
169 | 163 | |
|
170 | 164 | /*! |
|
171 | Sets the \a alignment for legend. Legend tries to paint itself on the defined position in chart. | |
|
172 | \sa QLegend::Alignment | |
|
165 | \property QLegend::alignment | |
|
166 | \brief The alignment of the legend. | |
|
167 | */ | |
|
168 | ||
|
169 | /*! | |
|
170 | Sets the \a alignment for legend. Legend paints on the defined position in chart. The following alignments are | |
|
171 | supported: Qt::AlignTop, Qt::AlignBottom, Qt::AlignLeft, Qt::AlignRight. If you set more than one flag the result | |
|
172 | is undefined. | |
|
173 | ||
|
174 | \sa QLegend::Alignment | |
|
173 | 175 | */ |
|
174 |
void QLegend::setAlignment(Q |
|
|
176 | void QLegend::setAlignment(Qt::Alignment alignment) | |
|
175 | 177 | { |
|
176 | 178 | if(d_ptr->m_alignment!=alignment) { |
|
177 | 179 | d_ptr->m_alignment = alignment; |
|
178 | 180 | d_ptr->updateLayout(); |
|
181 | alignmentChanged(); | |
|
179 | 182 | } |
|
180 | 183 | } |
|
181 | 184 | |
|
182 | 185 | /*! |
|
183 | 186 | Returns the preferred layout for legend |
|
184 | 187 | */ |
|
185 |
Q |
|
|
188 | Qt::Alignment QLegend::alignment() const | |
|
186 | 189 | { |
|
187 | 190 | return d_ptr->m_alignment; |
|
188 | 191 | } |
@@ -297,7 +300,7 QLegendPrivate::QLegendPrivate(ChartPresenter* presenter, QChart *chart, QLegend | |||
|
297 | 300 | m_presenter(presenter), |
|
298 | 301 | m_chart(chart), |
|
299 | 302 | m_markers(new QGraphicsItemGroup(q)), |
|
300 |
m_alignment(Q |
|
|
303 | m_alignment(Qt::AlignTop), | |
|
301 | 304 | m_offsetX(0), |
|
302 | 305 | m_offsetY(0), |
|
303 | 306 | m_minWidth(0), |
@@ -320,8 +323,8 void QLegendPrivate::setOffset(qreal x, qreal y) | |||
|
320 | 323 | |
|
321 | 324 | switch(m_alignment) { |
|
322 | 325 | |
|
323 |
case Q |
|
|
324 |
case Q |
|
|
326 | case Qt::AlignTop: | |
|
327 | case Qt::AlignBottom: { | |
|
325 | 328 | if(m_width<=m_rect.width()) return; |
|
326 | 329 | |
|
327 | 330 | if (x != m_offsetX) { |
@@ -330,8 +333,8 void QLegendPrivate::setOffset(qreal x, qreal y) | |||
|
330 | 333 | } |
|
331 | 334 | break; |
|
332 | 335 | } |
|
333 |
case Q |
|
|
334 |
case Q |
|
|
336 | case Qt::AlignLeft: | |
|
337 | case Qt::AlignRight: { | |
|
335 | 338 | |
|
336 | 339 | if(m_height<=m_rect.height()) return; |
|
337 | 340 | |
@@ -357,8 +360,8 void QLegendPrivate::updateLayout() | |||
|
357 | 360 | |
|
358 | 361 | switch(m_alignment) { |
|
359 | 362 | |
|
360 |
case Q |
|
|
361 |
case Q |
|
|
363 | case Qt::AlignTop: | |
|
364 | case Qt::AlignBottom: { | |
|
362 | 365 | QPointF point = m_rect.topLeft(); |
|
363 | 366 | m_width = 0; |
|
364 | 367 | foreach (QGraphicsItem *item, items) { |
@@ -379,8 +382,8 void QLegendPrivate::updateLayout() | |||
|
379 | 382 | m_height=m_minHeight; |
|
380 | 383 | } |
|
381 | 384 | break; |
|
382 |
case Q |
|
|
383 |
case Q |
|
|
385 | case Qt::AlignLeft: | |
|
386 | case Qt::AlignRight: { | |
|
384 | 387 | QPointF point = m_rect.topLeft(); |
|
385 | 388 | m_height = 0; |
|
386 | 389 | foreach (QGraphicsItem *item, items) { |
@@ -43,17 +43,7 class QLegendPrivate; | |||
|
43 | 43 | class QTCOMMERCIALCHART_EXPORT QLegend : public QGraphicsWidget |
|
44 | 44 | { |
|
45 | 45 | Q_OBJECT |
|
46 | public: | |
|
47 | ||
|
48 | // We only support these alignments (for now) | |
|
49 | enum Alignment { | |
|
50 | AlignmentTop = Qt::AlignTop, | |
|
51 | AlignmentBottom = Qt::AlignBottom, | |
|
52 | AlignmentLeft = Qt::AlignLeft, | |
|
53 | AlignmentRight = Qt::AlignRight | |
|
54 | }; | |
|
55 | ||
|
56 | Q_DECLARE_FLAGS(Alignments, Alignment) | |
|
46 | Q_PROPERTY(Qt::Alignment alignment READ alignment WRITE setAlignment NOTIFY alignmentChanged) | |
|
57 | 47 | |
|
58 | 48 | private: |
|
59 | 49 | explicit QLegend(QChart *chart); |
@@ -70,8 +60,8 public: | |||
|
70 | 60 | void setPen(const QPen &pen); |
|
71 | 61 | QPen pen() const; |
|
72 | 62 | |
|
73 |
void setAlignment(Q |
|
|
74 |
Q |
|
|
63 | void setAlignment(Qt::Alignment alignment); | |
|
64 | Qt::Alignment alignment() const; | |
|
75 | 65 | |
|
76 | 66 | void detachFromChart(); |
|
77 | 67 | void attachToChart(); |
@@ -91,6 +81,9 protected: | |||
|
91 | 81 | void hideEvent(QHideEvent *event); |
|
92 | 82 | void showEvent(QShowEvent *event); |
|
93 | 83 | |
|
84 | Q_SIGNALS: | |
|
85 | void alignmentChanged(); | |
|
86 | ||
|
94 | 87 | private: |
|
95 | 88 | QScopedPointer<QLegendPrivate> d_ptr; |
|
96 | 89 | Q_DISABLE_COPY(QLegend); |
@@ -60,7 +60,7 private: | |||
|
60 | 60 | ChartPresenter *m_presenter; |
|
61 | 61 | QChart* m_chart; |
|
62 | 62 | QGraphicsItemGroup* m_markers; |
|
63 |
Q |
|
|
63 | Qt::Alignment m_alignment; | |
|
64 | 64 | QBrush m_brush; |
|
65 | 65 | QPen m_pen; |
|
66 | 66 | QRectF m_rect; |
@@ -21,33 +21,20 | |||
|
21 | 21 | import QtQuick 1.0 |
|
22 | 22 | import QtCommercial.Chart 1.0 |
|
23 | 23 | |
|
24 | Rectangle { | |
|
24 | ChartView { | |
|
25 | id: chartView | |
|
26 | title: "chart" | |
|
25 | 27 | anchors.fill: parent |
|
28 | property variant series: chartView | |
|
26 | 29 | |
|
27 | ChartView { | |
|
28 |
|
|
|
29 | anchors.fill: parent | |
|
30 | ||
|
31 | SplineSeries { | |
|
32 | id: daSeries | |
|
33 | name: "spline 1" | |
|
34 |
|
|
|
35 |
|
|
|
36 | XyPoint { x: 1.9; y: 3.3 } | |
|
37 | XyPoint { x: 2.1; y: 2.1 } | |
|
38 | XyPoint { x: 2.9; y: 4.9 } | |
|
39 | XyPoint { x: 3.4; y: 3.0 } | |
|
40 | XyPoint { x: 4.1; y: 3.3 } | |
|
41 | } | |
|
42 | ||
|
43 | SplineSeries { | |
|
44 | name: "spline 2" | |
|
45 | XyPoint { x: 1.1; y: 1.1 } | |
|
46 | XyPoint { x: 1.9; y: 2.3 } | |
|
47 | XyPoint { x: 2.1; y: 1.1 } | |
|
48 | XyPoint { x: 2.9; y: 3.9 } | |
|
49 | XyPoint { x: 3.4; y: 2.0 } | |
|
50 | XyPoint { x: 4.1; y: 2.3 } | |
|
51 | } | |
|
30 | LineSeries { | |
|
31 | name: "line" | |
|
32 | XyPoint { x: 0; y: 0 } | |
|
33 | XyPoint { x: 1.1; y: 2.1 } | |
|
34 | XyPoint { x: 1.9; y: 3.3 } | |
|
35 | XyPoint { x: 2.1; y: 2.1 } | |
|
36 | XyPoint { x: 2.9; y: 4.9 } | |
|
37 | XyPoint { x: 3.4; y: 3.0 } | |
|
38 | XyPoint { x: 4.1; y: 3.3 } | |
|
52 | 39 | } |
|
53 | 40 | } |
@@ -26,7 +26,7 Rectangle { | |||
|
26 | 26 | width: parent.width |
|
27 | 27 | height: parent.height |
|
28 | 28 | property int viewNumber: 0 |
|
29 |
property int viewCount: |
|
|
29 | property int viewCount: 10 | |
|
30 | 30 | property variant colors: ["#637D74", "#403D3A", "#8C3B3B", "#AB6937", "#D4A960"] |
|
31 | 31 | property int colorIndex: 0 |
|
32 | 32 | |
@@ -38,30 +38,33 Rectangle { | |||
|
38 | 38 | |
|
39 | 39 | onViewNumberChanged: { |
|
40 | 40 | if (viewNumber == 0) { |
|
41 | chartLoader.source = "Chart.qml"; | |
|
42 | editorLoader.source = "ChartEditor.qml"; | |
|
43 | } else if (viewNumber == 1) { | |
|
41 | 44 | chartLoader.source = "PieChart.qml"; |
|
42 | 45 | editorLoader.source = "PieEditor.qml"; |
|
43 |
} else if (viewNumber == |
|
|
46 | } else if (viewNumber == 2) { | |
|
44 | 47 | chartLoader.source = "LineChart.qml"; |
|
45 | 48 | editorLoader.source = "LineEditor.qml"; |
|
46 |
} else if (viewNumber == |
|
|
49 | } else if (viewNumber == 3) { | |
|
47 | 50 | chartLoader.source = "SplineChart.qml"; |
|
48 | 51 | editorLoader.source = "LineEditor.qml"; |
|
49 |
} else if (viewNumber == |
|
|
52 | } else if (viewNumber == 4) { | |
|
50 | 53 | chartLoader.source = "ScatterChart.qml"; |
|
51 | 54 | editorLoader.source = "ScatterEditor.qml"; |
|
52 |
} else if (viewNumber == |
|
|
55 | } else if (viewNumber == 5) { | |
|
53 | 56 | chartLoader.source = "AreaChart.qml"; |
|
54 | 57 | editorLoader.source = "AreaEditor.qml"; |
|
55 |
} else if (viewNumber == |
|
|
58 | } else if (viewNumber == 6) { | |
|
56 | 59 | chartLoader.source = "BarChart.qml"; |
|
57 | 60 | editorLoader.source = "BarEditor.qml"; |
|
58 |
} else if (viewNumber == |
|
|
61 | } else if (viewNumber == 7) { | |
|
59 | 62 | chartLoader.source = "GroupedBarChart.qml"; |
|
60 | 63 | editorLoader.source = "BarEditor.qml"; |
|
61 |
} else if (viewNumber == |
|
|
64 | } else if (viewNumber == 8) { | |
|
62 | 65 | chartLoader.source = "StackedBarChart.qml"; |
|
63 | 66 | editorLoader.source = "BarEditor.qml"; |
|
64 |
} else if (viewNumber == |
|
|
67 | } else if (viewNumber == 9) { | |
|
65 | 68 | chartLoader.source = "PercentBarChart.qml"; |
|
66 | 69 | editorLoader.source = "BarEditor.qml"; |
|
67 | 70 | } else { |
@@ -80,7 +83,7 Rectangle { | |||
|
80 | 83 | id: chartLoader |
|
81 | 84 | width: main.width - editorLoader.width |
|
82 | 85 | height: parent.height |
|
83 |
source: " |
|
|
86 | source: "Chart.qml" | |
|
84 | 87 | onStatusChanged: { |
|
85 | 88 | console.log("chartLoader.status: " + status + " " + source); |
|
86 | 89 | if (status == Loader.Ready && editorLoader.status == Loader.Ready) |
@@ -92,7 +95,7 Rectangle { | |||
|
92 | 95 | id: editorLoader |
|
93 | 96 | width: 280 |
|
94 | 97 | height: parent.height |
|
95 |
source: " |
|
|
98 | source: "ChartEditor.qml" | |
|
96 | 99 | onStatusChanged: { |
|
97 | 100 | console.log("editorLoader.status: " + status + " " + source); |
|
98 | 101 | if (status == Loader.Ready && chartLoader.status == Loader.Ready) |
@@ -17,5 +17,7 | |||
|
17 | 17 | <file>qml/qmlchartproperties/GroupedBarChart.qml</file> |
|
18 | 18 | <file>qml/qmlchartproperties/StackedBarChart.qml</file> |
|
19 | 19 | <file>qml/qmlchartproperties/PercentBarChart.qml</file> |
|
20 | <file>qml/qmlchartproperties/Chart.qml</file> | |
|
21 | <file>qml/qmlchartproperties/ChartEditor.qml</file> | |
|
20 | 22 | </qresource> |
|
21 | 23 | </RCC> |
General Comments 0
You need to be logged in to leave comments.
Login now