diff --git a/qmlplugin/declarativeaxis.cpp b/qmlplugin/declarativeaxis.cpp new file mode 100644 index 0000000..30ba1aa --- /dev/null +++ b/qmlplugin/declarativeaxis.cpp @@ -0,0 +1,69 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ + +#include "declarativeaxis.h" +#include "declarativechart.h" +#include + +QTCOMMERCIALCHART_BEGIN_NAMESPACE + +DeclarativeAxis::DeclarativeAxis(QObject *parent) : + QAxis(parent), + m_role(DeclarativeAxis::RoleX) +{ +} + +void DeclarativeAxis::classBegin() +{ +} + +void DeclarativeAxis::componentComplete() +{ + DeclarativeChart *declarativeChart = qobject_cast(parent()); + if (declarativeChart) { + QChart *chart = qobject_cast(declarativeChart->m_chart); + Q_ASSERT(chart); + QAxis *axis = 0; + if (m_role == RoleX) + axis = chart->axisX(); + else + axis = chart->axisY(); + Q_ASSERT(axis); + // TODO? + //foreach(DeclarativeCategory catecory, categories()); + //axis->categories()->insert(0, "Jun"); +// axis->categories()->insert(1, "Jul"); +// axis->categories()->insert(2, "Aug"); +// axis->categories()->insert(3, "Sep"); +// axis->categories()->insert(4, "Oct"); +// axis->categories()->insert(5, "Nov"); + //axis->categories()->insert(6, "Dec"); + } +} + +void DeclarativeAxis::setRole(AxisRole role) +{ + // TODO: apply the role to possible parent chart + m_role = role; +} + +#include "moc_declarativeaxis.cpp" + +QTCOMMERCIALCHART_END_NAMESPACE diff --git a/qmlplugin/declarativeaxis.h b/qmlplugin/declarativeaxis.h new file mode 100644 index 0000000..3b5391b --- /dev/null +++ b/qmlplugin/declarativeaxis.h @@ -0,0 +1,58 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ + +#ifndef DECLARATIVE_AXIS_H +#define DECLARATIVE_AXIS_H + +#include "qchartglobal.h" +#include +#include + +QTCOMMERCIALCHART_BEGIN_NAMESPACE + +class DeclarativeAxis: public QAxis, public QDeclarativeParserStatus +{ + Q_INTERFACES(QDeclarativeParserStatus) + Q_OBJECT + Q_PROPERTY(AxisRole role READ role WRITE setRole /*NOTIFY roleChanged*/) + Q_ENUMS(AxisRole) + +public: + enum AxisRole { + RoleX = 0, + RoleY + }; + +public: + explicit DeclarativeAxis(QObject *parent = 0); + +public: // from QDeclarativeParserStatus + virtual void classBegin(); + virtual void componentComplete(); + +public: + void setRole(AxisRole role); + AxisRole role() { return m_role; } + AxisRole m_role; +}; + +QTCOMMERCIALCHART_END_NAMESPACE + +#endif // DECLARATIVE_AXIS_H diff --git a/qmlplugin/declarativechart.cpp b/qmlplugin/declarativechart.cpp index 633bb52..c58a8ee 100644 --- a/qmlplugin/declarativechart.cpp +++ b/qmlplugin/declarativechart.cpp @@ -28,7 +28,6 @@ DeclarativeChart::DeclarativeChart(QDeclarativeItem *parent) m_chart(new QChart(this)), m_legend(LegendDisabled) { - m_chart->setAnimationOptions(QChart::SeriesAnimations); setFlag(QGraphicsItem::ItemHasNoContents, false); } diff --git a/qmlplugin/declarativexyseries.cpp b/qmlplugin/declarativexyseries.cpp index 92d5839..09651cd 100644 --- a/qmlplugin/declarativexyseries.cpp +++ b/qmlplugin/declarativexyseries.cpp @@ -50,7 +50,7 @@ void DeclarativeXySeries::componentComplete() } void DeclarativeXySeries::appendPoints(QDeclarativeListProperty *list, - DeclarativeXyPoint *element) + DeclarativeXyPoint *element) { QXYSeries *series = qobject_cast(list->object); if (series) diff --git a/qmlplugin/plugin.cpp b/qmlplugin/plugin.cpp index b5cc853..dc01730 100644 --- a/qmlplugin/plugin.cpp +++ b/qmlplugin/plugin.cpp @@ -22,6 +22,7 @@ #include #include "qchart.h" #include "declarativechart.h" +#include "declarativeaxis.h" #include "declarativexypoint.h" #include "declarativelineseries.h" #include "declarativesplineseries.h" @@ -41,6 +42,7 @@ public: Q_ASSERT(QLatin1String(uri) == QLatin1String("QtCommercial.Chart")); qmlRegisterType(uri, 1, 0, "Chart"); + qmlRegisterType(uri, 1, 0, "Axis"); qmlRegisterType(uri, 1, 0, "XyPoint"); qmlRegisterType(uri, 1, 0, "ScatterSeries"); qmlRegisterType(uri, 1, 0, "LineSeries"); diff --git a/qmlplugin/qmlplugin.pro b/qmlplugin/qmlplugin.pro index ec157c9..20264a5 100644 --- a/qmlplugin/qmlplugin.pro +++ b/qmlplugin/qmlplugin.pro @@ -21,8 +21,9 @@ RCC_DIR = $$CHART_BUILD_DIR/plugin SOURCES += \ plugin.cpp \ declarativechart.cpp \ - declarativexyseries.cpp \ + declarativeaxis.cpp \ declarativexypoint.cpp \ + declarativexyseries.cpp \ declarativelineseries.cpp \ declarativesplineseries.cpp \ declarativeareaseries.cpp \ @@ -31,8 +32,9 @@ SOURCES += \ declarativebarseries.cpp HEADERS += \ declarativechart.h \ - declarativexyseries.h \ + declarativeaxis.h \ declarativexypoint.h \ + declarativexyseries.h \ declarativelineseries.h \ declarativesplineseries.h \ declarativeareaseries.h \ diff --git a/src/axis/chartaxis.cpp b/src/axis/chartaxis.cpp index 282a452..24cd021 100644 --- a/src/axis/chartaxis.cpp +++ b/src/axis/chartaxis.cpp @@ -322,7 +322,7 @@ void ChartAxis::setLayout(QVector &layout) rectItem->setRect(layout[i-1],m_rect.top(),layout[i]-layout[i-1],m_rect.height()); } lineItem = static_cast(axis.at(i+1)); - lineItem->setLine(layout[i],m_rect.bottom(),layout[i],m_rect.bottom()+5); + lineItem->setLine(layout[i],m_rect.bottom(),layout[i],m_rect.bottom()+5); } } @@ -361,7 +361,7 @@ void ChartAxis::setLayout(QVector &layout) rectItem->setRect(m_rect.left(),layout[i],m_rect.width(),layout[i-1]-layout[i]); } lineItem = static_cast(axis.at(i+1)); - lineItem->setLine(m_rect.left()-5,layout[i],m_rect.left(),layout[i]); + lineItem->setLine(m_rect.left()-5,layout[i],m_rect.left(),layout[i]); } } break; diff --git a/src/axis/qaxis.h b/src/axis/qaxis.h index 5135753..213b258 100644 --- a/src/axis/qaxis.h +++ b/src/axis/qaxis.h @@ -33,6 +33,8 @@ class QAxisPrivate; class QTCOMMERCIALCHART_EXPORT QAxis : public QObject { Q_OBJECT + Q_PROPERTY(bool labelsVisible READ labelsVisible WRITE setLabelsVisible) + public: QAxis(QObject *parent =0);