From 13ffac597ff0cb4d944bed09a4d1e9b189f2ef14 2012-06-01 16:09:52 From: Tero Ahola Date: 2012-06-01 16:09:52 Subject: [PATCH] Qml ChartView properties; legend to use Qt alignments --- diff --git a/demos/chartthemes/themewidget.cpp b/demos/chartthemes/themewidget.cpp index e0fda98..4afa544 100644 --- a/demos/chartthemes/themewidget.cpp +++ b/demos/chartthemes/themewidget.cpp @@ -167,10 +167,10 @@ QComboBox* ThemeWidget::createLegendBox() const { QComboBox* legendComboBox = new QComboBox(); legendComboBox->addItem("No Legend ", 0); - legendComboBox->addItem("Legend Top", QLegend::AlignmentTop); - legendComboBox->addItem("Legend Bottom", QLegend::AlignmentBottom); - legendComboBox->addItem("Legend Left", QLegend::AlignmentLeft); - legendComboBox->addItem("Legend Right", QLegend::AlignmentRight); + legendComboBox->addItem("Legend Top", Qt::AlignTop); + legendComboBox->addItem("Legend Bottom", Qt::AlignBottom); + legendComboBox->addItem("Legend Left", Qt::AlignLeft); + legendComboBox->addItem("Legend Right", Qt::AlignRight); return legendComboBox; } @@ -361,7 +361,7 @@ void ThemeWidget::updateUI() chartView->chart()->setAnimationOptions(options); } - QLegend::Alignments alignment(m_legendComboBox->itemData(m_legendComboBox->currentIndex()).toInt()); + Qt::Alignment alignment(m_legendComboBox->itemData(m_legendComboBox->currentIndex()).toInt()); if (!alignment) { foreach (QChartView *chartView, m_charts) { diff --git a/examples/barchart/main.cpp b/examples/barchart/main.cpp index b786b76..cdfa1ae 100644 --- a/examples/barchart/main.cpp +++ b/examples/barchart/main.cpp @@ -62,7 +62,7 @@ int main(int argc, char *argv[]) //![4] chart->legend()->setVisible(true); - chart->legend()->setAlignment(QLegend::AlignmentBottom); + chart->legend()->setAlignment(Qt::AlignBottom); chart->axisY()->setNiceNumbersEnabled(true); //![4] diff --git a/examples/groupedbarchart/main.cpp b/examples/groupedbarchart/main.cpp index d6a8965..80a3a93 100644 --- a/examples/groupedbarchart/main.cpp +++ b/examples/groupedbarchart/main.cpp @@ -70,7 +70,7 @@ int main(int argc, char *argv[]) //![5] chart->legend()->setVisible(true); - chart->legend()->setAlignment(QLegend::AlignmentBottom); + chart->legend()->setAlignment(Qt::AlignBottom); chart->axisY()->setNiceNumbersEnabled(true); //![5] diff --git a/examples/legend/mainwidget.cpp b/examples/legend/mainwidget.cpp index 302d019..2f7d25b 100644 --- a/examples/legend/mainwidget.cpp +++ b/examples/legend/mainwidget.cpp @@ -66,7 +66,7 @@ void MainWidget::createSeries() m_chart->setTitle("Legend detach example"); m_chart->legend()->setVisible(true); - m_chart->legend()->setAlignment(QLegend::AlignmentBottom); + m_chart->legend()->setAlignment(Qt::AlignBottom); m_chart->axisY()->setNiceNumbersEnabled(true); m_chartView->setRenderHint(QPainter::Antialiasing); diff --git a/examples/percentbarchart/main.cpp b/examples/percentbarchart/main.cpp index 0a6cdfa..b30d456 100644 --- a/examples/percentbarchart/main.cpp +++ b/examples/percentbarchart/main.cpp @@ -68,7 +68,7 @@ int main(int argc, char *argv[]) //![5] chart->legend()->setVisible(true); - chart->legend()->setAlignment(QLegend::AlignmentBottom); + chart->legend()->setAlignment(Qt::AlignBottom); //![5] //![6] diff --git a/examples/piechartdrilldown/main.cpp b/examples/piechartdrilldown/main.cpp index 1ca2182..cd73752 100644 --- a/examples/piechartdrilldown/main.cpp +++ b/examples/piechartdrilldown/main.cpp @@ -41,7 +41,7 @@ int main(int argc, char *argv[]) chart->setTheme(QChart::ChartThemeLight); chart->setAnimationOptions(QChart::AllAnimations); chart->legend()->setVisible(true); - chart->legend()->setAlignment(QLegend::AlignmentRight); + chart->legend()->setAlignment(Qt::AlignRight); QPieSeries* yearSeries = new QPieSeries(&window); yearSeries->setName("Sales by year - All"); diff --git a/examples/stackedbarchart/main.cpp b/examples/stackedbarchart/main.cpp index 5d97b57..9cd8338 100644 --- a/examples/stackedbarchart/main.cpp +++ b/examples/stackedbarchart/main.cpp @@ -68,7 +68,7 @@ int main(int argc, char *argv[]) //![5] chart->legend()->setVisible(true); - chart->legend()->setAlignment(QLegend::AlignmentBottom); + chart->legend()->setAlignment(Qt::AlignBottom); chart->axisY()->setNiceNumbersEnabled(true); //![5] diff --git a/examples/stackedbarchartdrilldown/main.cpp b/examples/stackedbarchartdrilldown/main.cpp index 2a9f74a..ee81b9d 100644 --- a/examples/stackedbarchartdrilldown/main.cpp +++ b/examples/stackedbarchartdrilldown/main.cpp @@ -104,7 +104,7 @@ int main(int argc, char *argv[]) drilldownChart->axisX()->setGridLineVisible(false); drilldownChart->axisY()->setNiceNumbersEnabled(true); drilldownChart->legend()->setVisible(true); - drilldownChart->legend()->setAlignment(QLegend::AlignmentBottom); + drilldownChart->legend()->setAlignment(Qt::AlignBottom); //! [7] QChartView *chartView = new QChartView(drilldownChart); diff --git a/plugins/declarative/declarativechart.cpp b/plugins/declarative/declarativechart.cpp index 0916f26..2619677 100644 --- a/plugins/declarative/declarativechart.cpp +++ b/plugins/declarative/declarativechart.cpp @@ -31,8 +31,7 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE DeclarativeChart::DeclarativeChart(QDeclarativeItem *parent) : QDeclarativeItem(parent), - m_chart(new QChart(this)), - m_legend(LegendTop) + m_chart(new QChart(this)) { setFlag(QGraphicsItem::ItemHasNoContents, false); // m_chart->axisX()->setNiceNumbersEnabled(false); @@ -88,7 +87,11 @@ void DeclarativeChart::paint(QPainter *painter, const QStyleOptionGraphicsItem * void DeclarativeChart::setTheme(DeclarativeChart::Theme theme) { - m_chart->setTheme((QChart::ChartTheme) theme); + QChart::ChartTheme chartTheme = (QChart::ChartTheme) theme; + if (chartTheme != m_chart->theme()) { + m_chart->setTheme(chartTheme); + themeChanged(); + } } DeclarativeChart::Theme DeclarativeChart::theme() @@ -98,7 +101,11 @@ DeclarativeChart::Theme DeclarativeChart::theme() void DeclarativeChart::setAnimationOptions(DeclarativeChart::Animation animations) { - m_chart->setAnimationOptions((QChart::AnimationOption) animations); + QChart::AnimationOption animationOptions = (QChart::AnimationOption) animations; + if (animationOptions != m_chart->animationOptions()) { + m_chart->setAnimationOptions(animationOptions); + animationOptionsChanged(); + } } DeclarativeChart::Animation DeclarativeChart::animationOptions() @@ -113,40 +120,16 @@ DeclarativeChart::Animation DeclarativeChart::animationOptions() return DeclarativeChart::NoAnimation; } -void DeclarativeChart::setLegend(DeclarativeChart::Legend legend) -{ - if (legend != m_legend) { - m_legend = legend; - switch (m_legend) { - case LegendDisabled: - m_chart->legend()->setVisible(false); - break; - case LegendTop: - m_chart->legend()->setVisible(true); - m_chart->legend()->setAlignment(QLegend::AlignmentTop); - break; - case LegendBottom: - m_chart->legend()->setVisible(true); - m_chart->legend()->setAlignment(QLegend::AlignmentBottom); - break; - case LegendLeft: - m_chart->legend()->setVisible(true); - m_chart->legend()->setAlignment(QLegend::AlignmentLeft); - break; - case LegendRight: - m_chart->legend()->setVisible(true); - m_chart->legend()->setAlignment(QLegend::AlignmentRight); - break; - default: - m_chart->legend()->setVisible(false); - break; - } +void DeclarativeChart::setTitle(QString title) +{ + if (title != m_chart->title()) { + m_chart->setTitle(title); + emit titleChanged(); } } - -DeclarativeChart::Legend DeclarativeChart::legend() +QString DeclarativeChart::title() { - return m_legend; + return m_chart->title(); } QAxis *DeclarativeChart::axisX() @@ -159,6 +142,11 @@ QAxis *DeclarativeChart::axisY() return m_chart->axisY(); } +QLegend *DeclarativeChart::legend() +{ + return m_chart->legend(); +} + QVariantList DeclarativeChart::axisXLabels() { QVariantList labels; @@ -181,6 +169,37 @@ void DeclarativeChart::setAxisXLabels(QVariantList list) value = element; } } + emit axisLabelsChanged(); +} + +void DeclarativeChart::setTitleColor(QColor color) +{ + QBrush b = m_chart->titleBrush(); + if (color != b.color()) { + b.setColor(color); + m_chart->setTitleBrush(b); + emit titleColorChanged(); + } +} + +QColor DeclarativeChart::titleColor() +{ + return m_chart->titleBrush().color(); +} + +void DeclarativeChart::setBackgroundColor(QColor color) +{ + QBrush b = m_chart->backgroundBrush(); + if (color != b.color()) { + b.setColor(color); + m_chart->setBackgroundBrush(b); + emit backgroundColorChanged(); + } +} + +QColor DeclarativeChart::backgroundColor() +{ + return m_chart->backgroundBrush().color(); } int DeclarativeChart::count() diff --git a/plugins/declarative/declarativechart.h b/plugins/declarative/declarativechart.h index 7e1ca18..a02adee 100644 --- a/plugins/declarative/declarativechart.h +++ b/plugins/declarative/declarativechart.h @@ -34,18 +34,19 @@ class DeclarativeChart : public QDeclarativeItem //class DeclarativeChart : public QQuickPaintedItem, public Chart { Q_OBJECT - Q_PROPERTY(Theme theme READ theme WRITE setTheme) - Q_PROPERTY(Animation animationOptions READ animationOptions WRITE setAnimationOptions) - Q_PROPERTY(QString title READ title WRITE setTitle) - Q_PROPERTY(Legend legend READ legend WRITE setLegend) + Q_PROPERTY(Theme theme READ theme WRITE setTheme NOTIFY themeChanged) + Q_PROPERTY(Animation animationOptions READ animationOptions WRITE setAnimationOptions NOTIFY animationOptionsChanged) + Q_PROPERTY(QString title READ title WRITE setTitle NOTIFY titleChanged) Q_PROPERTY(QAxis *axisX READ axisX) Q_PROPERTY(QAxis *axisY READ axisY) + Q_PROPERTY(QLegend *legend READ legend) // TODO: how to define axis labels? This is not very convenient - Q_PROPERTY(QVariantList axisXLabels READ axisXLabels WRITE setAxisXLabels) + Q_PROPERTY(QVariantList axisXLabels READ axisXLabels WRITE setAxisXLabels NOTIFY axisLabelsChanged) Q_PROPERTY(int count READ count) + Q_PROPERTY(QColor titleColor READ titleColor WRITE setTitleColor NOTIFY titleColorChanged) + Q_PROPERTY(QColor backgroundColor READ backgroundColor WRITE setBackgroundColor NOTIFY backgroundColorChanged) Q_ENUMS(Animation) Q_ENUMS(Theme) - Q_ENUMS(Legend) Q_ENUMS(SeriesType) public: @@ -67,14 +68,6 @@ public: AllAnimations = 0x3 }; - enum Legend { - LegendDisabled = 0, - LegendTop, - LegendBottom, - LegendLeft, - LegendRight - }; - enum SeriesType { SeriesTypeLine, SeriesTypeArea, @@ -102,24 +95,34 @@ public: DeclarativeChart::Theme theme(); void setAnimationOptions(DeclarativeChart::Animation animations); DeclarativeChart::Animation animationOptions(); - void setTitle(QString title) {m_chart->setTitle(title);} - QString title() { return m_chart->title();} - void setLegend(DeclarativeChart::Legend legend); - DeclarativeChart::Legend legend(); + void setTitle(QString title); + QString title(); QAxis *axisX(); QAxis *axisY(); + QLegend *legend(); QVariantList axisXLabels(); void setAxisXLabels(QVariantList list); + void setTitleColor(QColor color); + QColor titleColor(); + void setBackgroundColor(QColor color); + QColor backgroundColor(); int count(); Q_INVOKABLE QAbstractSeries *series(int index); Q_INVOKABLE QAbstractSeries *series(QString seriesName); Q_INVOKABLE QAbstractSeries *createSeries(DeclarativeChart::SeriesType type, QString name = ""); +Q_SIGNALS: + void themeChanged(); + void animationOptionsChanged(); + void titleChanged(); + void axisLabelsChanged(); + void titleColorChanged(); + void backgroundColorChanged(); + public: // Extending QChart with DeclarativeChart is not possible because QObject does not support // multi inheritance, so we now have a QChart as a member instead QChart *m_chart; - Legend m_legend; }; QTCOMMERCIALCHART_END_NAMESPACE diff --git a/plugins/declarative/plugin.cpp b/plugins/declarative/plugin.cpp index 4660dd7..4294794 100644 --- a/plugins/declarative/plugin.cpp +++ b/plugins/declarative/plugin.cpp @@ -67,6 +67,8 @@ public: qmlRegisterType(uri, 1, 0, "HBarModelMapper"); qmlRegisterType(uri, 1, 0, "VBarModelMapper"); + qmlRegisterUncreatableType(uri, 1, 0, "Legend", + QLatin1String("Trying to create uncreatable: Legend.")); qmlRegisterUncreatableType(uri, 1, 0, "QScatterSeries", QLatin1String("Trying to create uncreatable: QScatterSeries.")); qmlRegisterUncreatableType(uri, 1, 0, "QPieSeries", diff --git a/src/chartpresenter.cpp b/src/chartpresenter.cpp index 3e3e793..e8b32e7 100644 --- a/src/chartpresenter.cpp +++ b/src/chartpresenter.cpp @@ -323,7 +323,7 @@ void ChartPresenter::updateLayout() // Reserve some space for legend switch (legend->alignment()) { - case QLegend::AlignmentTop: { + case Qt::AlignTop: { int ledgendSize = legend->minHeight(); int topPadding = 2*m_marginTiny + titleSize.height() + ledgendSize + m_marginTiny; m_chartMargins = QRect(QPoint(m_chartMargins.left(),topPadding),QPoint(m_chartMargins.right(),m_chartMargins.bottom())); @@ -331,7 +331,7 @@ void ChartPresenter::updateLayout() titlePadding = m_marginTiny + m_marginTiny; break; } - case QLegend::AlignmentBottom: { + case Qt::AlignBottom: { int ledgendSize = legend->minHeight(); int bottomPadding = m_marginTiny + m_marginSmall + ledgendSize + m_marginTiny + m_minBottomMargin; m_chartMargins = QRect(QPoint(m_chartMargins.left(),m_chartMargins.top()),QPoint(m_chartMargins.right(),bottomPadding)); @@ -339,7 +339,7 @@ void ChartPresenter::updateLayout() titlePadding = m_chartMargins.top()/2; break; } - case QLegend::AlignmentLeft: { + case Qt::AlignLeft: { int ledgendSize = legend->minWidth(); int leftPadding = m_marginTiny + m_marginSmall + ledgendSize + m_marginTiny + m_minLeftMargin; m_chartMargins = QRect(QPoint(leftPadding,m_chartMargins.top()),QPoint(m_chartMargins.right(),m_chartMargins.bottom())); @@ -347,7 +347,7 @@ void ChartPresenter::updateLayout() titlePadding = m_chartMargins.top()/2; break; } - case QLegend::AlignmentRight: { + case Qt::AlignRight: { int ledgendSize = legend->minWidth(); int rightPadding = m_marginTiny + m_marginSmall + ledgendSize + m_marginTiny; m_chartMargins = QRect(QPoint(m_chartMargins.left(),m_chartMargins.top()),QPoint(rightPadding,m_chartMargins.bottom())); diff --git a/src/legend/qlegend.cpp b/src/legend/qlegend.cpp index 576cd95..dd7d462 100644 --- a/src/legend/qlegend.cpp +++ b/src/legend/qlegend.cpp @@ -62,15 +62,9 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE */ /*! - \enum QLegend::Alignment - - This enum describes the possible position for legend inside chart. - - \value AlignmentTop - \value AlignmentBottom - \value AlignmentLeft - \value AlignmentRight - */ + \fn void QLegend::alignmentChanged() + Emitted when the alignment of the legend changes. +*/ /*! \fn qreal QLegend::minWidth() const @@ -168,21 +162,30 @@ QPen QLegend::pen() const } /*! - Sets the \a alignment for legend. Legend tries to paint itself on the defined position in chart. - \sa QLegend::Alignment + \property QLegend::alignment + \brief The alignment of the legend. +*/ + +/*! + Sets the \a alignment for legend. Legend paints on the defined position in chart. The following alignments are + supported: Qt::AlignTop, Qt::AlignBottom, Qt::AlignLeft, Qt::AlignRight. If you set more than one flag the result + is undefined. + + \sa QLegend::Alignment */ -void QLegend::setAlignment(QLegend::Alignments alignment) +void QLegend::setAlignment(Qt::Alignment alignment) { if(d_ptr->m_alignment!=alignment) { d_ptr->m_alignment = alignment; d_ptr->updateLayout(); + alignmentChanged(); } } /*! Returns the preferred layout for legend */ -QLegend::Alignments QLegend::alignment() const +Qt::Alignment QLegend::alignment() const { return d_ptr->m_alignment; } @@ -297,7 +300,7 @@ QLegendPrivate::QLegendPrivate(ChartPresenter* presenter, QChart *chart, QLegend m_presenter(presenter), m_chart(chart), m_markers(new QGraphicsItemGroup(q)), - m_alignment(QLegend::AlignmentTop), + m_alignment(Qt::AlignTop), m_offsetX(0), m_offsetY(0), m_minWidth(0), @@ -320,8 +323,8 @@ void QLegendPrivate::setOffset(qreal x, qreal y) switch(m_alignment) { - case QLegend::AlignmentTop: - case QLegend::AlignmentBottom: { + case Qt::AlignTop: + case Qt::AlignBottom: { if(m_width<=m_rect.width()) return; if (x != m_offsetX) { @@ -330,8 +333,8 @@ void QLegendPrivate::setOffset(qreal x, qreal y) } break; } - case QLegend::AlignmentLeft: - case QLegend::AlignmentRight: { + case Qt::AlignLeft: + case Qt::AlignRight: { if(m_height<=m_rect.height()) return; @@ -357,8 +360,8 @@ void QLegendPrivate::updateLayout() switch(m_alignment) { - case QLegend::AlignmentTop: - case QLegend::AlignmentBottom: { + case Qt::AlignTop: + case Qt::AlignBottom: { QPointF point = m_rect.topLeft(); m_width = 0; foreach (QGraphicsItem *item, items) { @@ -379,8 +382,8 @@ void QLegendPrivate::updateLayout() m_height=m_minHeight; } break; - case QLegend::AlignmentLeft: - case QLegend::AlignmentRight: { + case Qt::AlignLeft: + case Qt::AlignRight: { QPointF point = m_rect.topLeft(); m_height = 0; foreach (QGraphicsItem *item, items) { diff --git a/src/legend/qlegend.h b/src/legend/qlegend.h index a6488d7..94fc366 100644 --- a/src/legend/qlegend.h +++ b/src/legend/qlegend.h @@ -43,17 +43,7 @@ class QLegendPrivate; class QTCOMMERCIALCHART_EXPORT QLegend : public QGraphicsWidget { Q_OBJECT -public: - - // We only support these alignments (for now) - enum Alignment { - AlignmentTop = Qt::AlignTop, - AlignmentBottom = Qt::AlignBottom, - AlignmentLeft = Qt::AlignLeft, - AlignmentRight = Qt::AlignRight - }; - - Q_DECLARE_FLAGS(Alignments, Alignment) + Q_PROPERTY(Qt::Alignment alignment READ alignment WRITE setAlignment NOTIFY alignmentChanged) private: explicit QLegend(QChart *chart); @@ -70,8 +60,8 @@ public: void setPen(const QPen &pen); QPen pen() const; - void setAlignment(QLegend::Alignments alignment); - QLegend::Alignments alignment() const; + void setAlignment(Qt::Alignment alignment); + Qt::Alignment alignment() const; void detachFromChart(); void attachToChart(); @@ -91,6 +81,9 @@ protected: void hideEvent(QHideEvent *event); void showEvent(QShowEvent *event); +Q_SIGNALS: + void alignmentChanged(); + private: QScopedPointer d_ptr; Q_DISABLE_COPY(QLegend); diff --git a/src/legend/qlegend_p.h b/src/legend/qlegend_p.h index 4678b14..4dc6f71 100644 --- a/src/legend/qlegend_p.h +++ b/src/legend/qlegend_p.h @@ -60,7 +60,7 @@ private: ChartPresenter *m_presenter; QChart* m_chart; QGraphicsItemGroup* m_markers; - QLegend::Alignments m_alignment; + Qt::Alignment m_alignment; QBrush m_brush; QPen m_pen; QRectF m_rect; diff --git a/tests/qmlchartproperties/qml/qmlchartproperties/View1.qml b/tests/qmlchartproperties/qml/qmlchartproperties/Chart.qml similarity index 75% rename from tests/qmlchartproperties/qml/qmlchartproperties/View1.qml rename to tests/qmlchartproperties/qml/qmlchartproperties/Chart.qml index 6b878fb..6963ee6 100644 --- a/tests/qmlchartproperties/qml/qmlchartproperties/View1.qml +++ b/tests/qmlchartproperties/qml/qmlchartproperties/Chart.qml @@ -21,33 +21,20 @@ import QtQuick 1.0 import QtCommercial.Chart 1.0 -Rectangle { +ChartView { + id: chartView + title: "chart" anchors.fill: parent + property variant series: chartView - ChartView { - title: "spline series" - anchors.fill: parent - - SplineSeries { - id: daSeries - name: "spline 1" - XyPoint { x: 0; y: 0 } - XyPoint { x: 1.1; y: 2.1 } - XyPoint { x: 1.9; y: 3.3 } - XyPoint { x: 2.1; y: 2.1 } - XyPoint { x: 2.9; y: 4.9 } - XyPoint { x: 3.4; y: 3.0 } - XyPoint { x: 4.1; y: 3.3 } - } - - SplineSeries { - name: "spline 2" - XyPoint { x: 1.1; y: 1.1 } - XyPoint { x: 1.9; y: 2.3 } - XyPoint { x: 2.1; y: 1.1 } - XyPoint { x: 2.9; y: 3.9 } - XyPoint { x: 3.4; y: 2.0 } - XyPoint { x: 4.1; y: 2.3 } - } + LineSeries { + name: "line" + XyPoint { x: 0; y: 0 } + XyPoint { x: 1.1; y: 2.1 } + XyPoint { x: 1.9; y: 3.3 } + XyPoint { x: 2.1; y: 2.1 } + XyPoint { x: 2.9; y: 4.9 } + XyPoint { x: 3.4; y: 3.0 } + XyPoint { x: 4.1; y: 3.3 } } } diff --git a/tests/qmlchartproperties/qml/qmlchartproperties/ChartEditor.qml b/tests/qmlchartproperties/qml/qmlchartproperties/ChartEditor.qml new file mode 100644 index 0000000..11aa3e6 --- /dev/null +++ b/tests/qmlchartproperties/qml/qmlchartproperties/ChartEditor.qml @@ -0,0 +1,94 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc +** All rights reserved. +** For any questions to Digia, please use contact form at http://qt.digia.com +** +** This file is part of the Qt Commercial Charts Add-on. +** +** $QT_BEGIN_LICENSE$ +** Licensees holding valid Qt Commercial licenses may use this file in +** accordance with the Qt Commercial License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. +** +** If you have questions regarding the use of this file, please use +** contact form at http://qt.digia.com +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 1.0 +import QtCommercial.Chart 1.0 + + +Flow { + id: flow + spacing: 5 + flow: Flow.TopToBottom + property variant series // TODO: rename to chart + + Connections { + target: series + onVisibleChanged: console.log("chart.onVisibleChanged: " + series.visible); + onThemeChanged: console.log("chart.onThemeChanged: " + series.theme); + onLegendChanged: console.log("chart.onLegendChanged: " + series.legend); + onAnimationOptionsChanged: console.log("chart.onAnimationOptionsChanged: " + series.animationOptions); + onTitleColorChanged: console.log("chart.onTitleColorChanged: " + series.titleColor); + onBackgroundColorChanged: console.log("chart.onBackgroundColorChanged: " + series.backgroundColor); + } + Connections { + target: series.legend + onAlignmentChanged: console.log("legend.onAlignmentChanged: " + series.legend.alignment); + onVisibleChanged: console.log("legend.onVisibleChanged: " + series.legend.visible); + } + + Button { + text: "visible" + onClicked: series.visible = !series.visible; + } + Button { + text: "theme +" + onClicked: series.theme++; + } + Button { + text: "theme -" + onClicked: series.theme--; + } + Button { + text: "legend top" + onClicked: series.legend.alignment ^= Qt.AlignTop; + } + Button { + text: "legend bottom" + onClicked: series.legend.alignment ^= Qt.AlignBottom; + } + Button { + text: "legend left" + onClicked: series.legend.alignment ^= Qt.AlignLeft; + } + Button { + text: "legend right" + onClicked: series.legend.alignment ^= Qt.AlignRight; + } + Button { + text: "legend visible" + onClicked: series.legend.visible = !series.legend.visible; + } + Button { + text: "animation opt +" + onClicked: series.animationOptions++; + } + Button { + text: "animation opt -" + onClicked: series.animationOptions--; + } + Button { + text: "title color" + onClicked: series.titleColor = main.nextColor(); + } + Button { + text: "background color" + onClicked: series.backgroundColor = main.nextColor(); + } +} diff --git a/tests/qmlchartproperties/qml/qmlchartproperties/main.qml b/tests/qmlchartproperties/qml/qmlchartproperties/main.qml index c419082..9524e64 100644 --- a/tests/qmlchartproperties/qml/qmlchartproperties/main.qml +++ b/tests/qmlchartproperties/qml/qmlchartproperties/main.qml @@ -26,7 +26,7 @@ Rectangle { width: parent.width height: parent.height property int viewNumber: 0 - property int viewCount: 9 + property int viewCount: 10 property variant colors: ["#637D74", "#403D3A", "#8C3B3B", "#AB6937", "#D4A960"] property int colorIndex: 0 @@ -38,30 +38,33 @@ Rectangle { onViewNumberChanged: { if (viewNumber == 0) { + chartLoader.source = "Chart.qml"; + editorLoader.source = "ChartEditor.qml"; + } else if (viewNumber == 1) { chartLoader.source = "PieChart.qml"; editorLoader.source = "PieEditor.qml"; - } else if (viewNumber == 1) { + } else if (viewNumber == 2) { chartLoader.source = "LineChart.qml"; editorLoader.source = "LineEditor.qml"; - } else if (viewNumber == 2) { + } else if (viewNumber == 3) { chartLoader.source = "SplineChart.qml"; editorLoader.source = "LineEditor.qml"; - } else if (viewNumber == 3) { + } else if (viewNumber == 4) { chartLoader.source = "ScatterChart.qml"; editorLoader.source = "ScatterEditor.qml"; - } else if (viewNumber == 4) { + } else if (viewNumber == 5) { chartLoader.source = "AreaChart.qml"; editorLoader.source = "AreaEditor.qml"; - } else if (viewNumber == 5) { + } else if (viewNumber == 6) { chartLoader.source = "BarChart.qml"; editorLoader.source = "BarEditor.qml"; - } else if (viewNumber == 6) { + } else if (viewNumber == 7) { chartLoader.source = "GroupedBarChart.qml"; editorLoader.source = "BarEditor.qml"; - } else if (viewNumber == 7) { + } else if (viewNumber == 8) { chartLoader.source = "StackedBarChart.qml"; editorLoader.source = "BarEditor.qml"; - } else if (viewNumber == 8) { + } else if (viewNumber == 9) { chartLoader.source = "PercentBarChart.qml"; editorLoader.source = "BarEditor.qml"; } else { @@ -80,7 +83,7 @@ Rectangle { id: chartLoader width: main.width - editorLoader.width height: parent.height - source: "PieChart.qml" + source: "Chart.qml" onStatusChanged: { console.log("chartLoader.status: " + status + " " + source); if (status == Loader.Ready && editorLoader.status == Loader.Ready) @@ -92,7 +95,7 @@ Rectangle { id: editorLoader width: 280 height: parent.height - source: "PieEditor.qml" + source: "ChartEditor.qml" onStatusChanged: { console.log("editorLoader.status: " + status + " " + source); if (status == Loader.Ready && chartLoader.status == Loader.Ready) diff --git a/tests/qmlchartproperties/resources.qrc b/tests/qmlchartproperties/resources.qrc index 0452afa..71e5345 100644 --- a/tests/qmlchartproperties/resources.qrc +++ b/tests/qmlchartproperties/resources.qrc @@ -17,5 +17,7 @@ qml/qmlchartproperties/GroupedBarChart.qml qml/qmlchartproperties/StackedBarChart.qml qml/qmlchartproperties/PercentBarChart.qml + qml/qmlchartproperties/Chart.qml + qml/qmlchartproperties/ChartEditor.qml