diff options
author | Titta Heikkala <titta.heikkala@digia.com> | 2014-07-01 07:10:00 +0300 |
---|---|---|
committer | Titta Heikkala <titta.heikkala@theqtcompany.com> | 2014-10-14 13:04:52 +0300 |
commit | c544258484ff4fd5d2b88402fbaa5d154b89a3a2 (patch) | |
tree | 7659625abb566dec55d3783ed820b928542d9b2b /examples | |
parent | 76339f714f088645e911cee65bdb66055fe029aa (diff) |
Qt Charts project file structure change
Charts repository structure is changed to follow the structure of a
Qt Add-On module. The task includes following changes:
- All macros and definitions named 'commercial' have been renamed.
- Compile errors related to QString and qSort usage have been fixed.
- Old demos are moved under examples. The QML examples now support only
Qt Quick 2.0, the support for Qt Quick 1 is removed.
- The QML examples with multiple views are updated so that they are
usable also with touch devices.
- Unnecessary version checks are removed from examples.
- The build stamp has been removed as it was only meant for Charts
development purposes and it's no longer needed. Also development
build related debug prints are removed as __DATE__ can't be used
for all OS thus it doesn't make much sense.
- Documentation structure has been updated based on the new module
structure. The raw HTML files have been removed. Demos are
combined to examples.
- Unnecessary .qdocinc files are no longer needed. The content is
moved to the corresponding .cpp files.
- The Charts widget designer plugin is updated according to the module
change.
- The test cases updated according to the project structure change.
Tests are added also for version 2.0.
- cmake modules generation is not needed with Qt 5.4 and Qt Charts
so it's disabled.
- The new module name and version are updated to the plugin.qmltypes
file.
Task-number: QTRD-2844, QTRD-3217, QTRD-3218, QTRD-3277, QTRD-3228,
QTRD-2526, QTRD-3233, QTRD-3222
Change-Id: Ib7fb26057cde710ffaf6bc780c8bf52a16f45160
Reviewed-by: Miikka Heikkinen <miikka.heikkinen@theqtcompany.com>
Diffstat (limited to 'examples')
221 files changed, 6433 insertions, 712 deletions
diff --git a/examples/areachart/areachart.pro b/examples/charts/areachart/areachart.pro index e8e1a074..e8e1a074 100644 --- a/examples/areachart/areachart.pro +++ b/examples/charts/areachart/areachart.pro diff --git a/examples/areachart/main.cpp b/examples/charts/areachart/main.cpp index e860ea18..6f2a1cac 100644 --- a/examples/areachart/main.cpp +++ b/examples/charts/areachart/main.cpp @@ -20,11 +20,11 @@ #include <QApplication> #include <QMainWindow> -#include <QChartView> -#include <QLineSeries> -#include <QAreaSeries> +#include <QtCharts/QChartView> +#include <QtCharts/QLineSeries> +#include <QtCharts/QAreaSeries> -QTCOMMERCIALCHART_USE_NAMESPACE +QT_CHARTS_USE_NAMESPACE int main(int argc, char *argv[]) { diff --git a/examples/charts/audio/audio.pro b/examples/charts/audio/audio.pro new file mode 100644 index 00000000..6a3b6917 --- /dev/null +++ b/examples/charts/audio/audio.pro @@ -0,0 +1,15 @@ +!include( ../examples.pri ) { + error( "Couldn't find the examples.pri file!" ) +} + +QT += multimedia + +TARGET = audio +TEMPLATE = app + +SOURCES += main.cpp\ + widget.cpp \ + xyseriesiodevice.cpp + +HEADERS += widget.h \ + xyseriesiodevice.h diff --git a/examples/charts/audio/main.cpp b/examples/charts/audio/main.cpp new file mode 100644 index 00000000..dd9069df --- /dev/null +++ b/examples/charts/audio/main.cpp @@ -0,0 +1,31 @@ +/**************************************************************************** +** +** Copyright (C) 2014 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 Enterprise Charts Add-on. +** +** $QT_BEGIN_LICENSE$ +** Licensees holding valid Qt Enterprise licenses may use this file in +** accordance with the Qt Enterprise 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 <QApplication> +#include "widget.h" + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + Widget w; + w.show(); + + return a.exec(); +} diff --git a/examples/charts/audio/widget.cpp b/examples/charts/audio/widget.cpp new file mode 100644 index 00000000..6cd5d442 --- /dev/null +++ b/examples/charts/audio/widget.cpp @@ -0,0 +1,82 @@ +/**************************************************************************** +** +** Copyright (C) 2014 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 Enterprise Charts Add-on. +** +** $QT_BEGIN_LICENSE$ +** Licensees holding valid Qt Enterprise licenses may use this file in +** accordance with the Qt Enterprise 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 "widget.h" +#include <QAudioDeviceInfo> +#include <QAudioInput> +#include <QChartView> +#include <QLineSeries> +#include <QChart> +#include <QVBoxLayout> +#include <QValueAxis> +#include "xyseriesiodevice.h" + +QT_CHARTS_USE_NAMESPACE + +Widget::Widget(QWidget *parent) + : QWidget(parent), + m_device(0), + m_chart(0), + m_series(0), + m_audioInput(0) +{ + m_chart = new QChart; + QChartView *chartView = new QChartView(m_chart); + chartView->setMinimumSize(800, 600); + m_series = new QLineSeries; + m_chart->addSeries(m_series); + QValueAxis *axisX = new QValueAxis; + axisX->setRange(0, 2000); + axisX->setLabelFormat("%g"); + axisX->setTitleText("Samples"); + QValueAxis *axisY = new QValueAxis; + axisY->setRange(-1, 1); + axisY->setTitleText("Audio level"); + m_chart->setAxisX(axisX, m_series); + m_chart->setAxisY(axisY, m_series); + m_chart->legend()->hide(); + m_chart->setTitle("Data from the microphone"); + + QVBoxLayout *mainLayout = new QVBoxLayout; + mainLayout->addWidget(chartView); + setLayout(mainLayout); + + QAudioFormat formatAudio; + formatAudio.setSampleRate(8000); + formatAudio.setChannelCount(1); + formatAudio.setSampleSize(8); + formatAudio.setCodec("audio/pcm"); + formatAudio.setByteOrder(QAudioFormat::LittleEndian); + formatAudio.setSampleType(QAudioFormat::UnSignedInt); + + QAudioDeviceInfo inputDevices = QAudioDeviceInfo::defaultInputDevice(); + m_audioInput = new QAudioInput(inputDevices,formatAudio, this); + + m_device = new XYSeriesIODevice(m_series, this); + m_device->open(QIODevice::WriteOnly); + + m_audioInput->start(m_device); +} + +Widget::~Widget() +{ + m_audioInput->stop(); + m_device->close(); +} diff --git a/examples/charts/audio/widget.h b/examples/charts/audio/widget.h new file mode 100644 index 00000000..6f745069 --- /dev/null +++ b/examples/charts/audio/widget.h @@ -0,0 +1,52 @@ +/**************************************************************************** +** +** Copyright (C) 2014 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 Enterprise Charts Add-on. +** +** $QT_BEGIN_LICENSE$ +** Licensees holding valid Qt Enterprise licenses may use this file in +** accordance with the Qt Enterprise 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 WIDGET_H +#define WIDGET_H + +#include <QWidget> +#include <QChartGlobal> + +QT_CHARTS_BEGIN_NAMESPACE +class QLineSeries; +class QChart; +QT_CHARTS_END_NAMESPACE + +QT_CHARTS_USE_NAMESPACE + +class XYSeriesIODevice; +class QAudioInput; + +class Widget : public QWidget +{ + Q_OBJECT + +public: + Widget(QWidget *parent = 0); + ~Widget(); + +private: + XYSeriesIODevice *m_device; + QChart *m_chart; + QLineSeries *m_series; + QAudioInput *m_audioInput; +}; + +#endif // WIDGET_H diff --git a/examples/charts/audio/xyseriesiodevice.cpp b/examples/charts/audio/xyseriesiodevice.cpp new file mode 100644 index 00000000..5440771f --- /dev/null +++ b/examples/charts/audio/xyseriesiodevice.cpp @@ -0,0 +1,57 @@ +/**************************************************************************** +** +** Copyright (C) 2014 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 Enterprise Charts Add-on. +** +** $QT_BEGIN_LICENSE$ +** Licensees holding valid Qt Enterprise licenses may use this file in +** accordance with the Qt Enterprise 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 "xyseriesiodevice.h" +#include <QXYSeries> + +XYSeriesIODevice::XYSeriesIODevice(QXYSeries * series, QObject *parent) : + QIODevice(parent), + m_series(series) +{ +} + +qint64 XYSeriesIODevice::readData(char * data, qint64 maxSize) +{ + Q_UNUSED(data) + Q_UNUSED(maxSize) + return -1; +} + +qint64 XYSeriesIODevice::writeData(const char * data, qint64 maxSize) +{ + qint64 range = 2000; + QList<QPointF> oldPoints = m_series->points(); + QList<QPointF> points; + int resolution = 4; + + if (oldPoints.count() < range) { + points = m_series->points(); + } else { + for (int i = maxSize/resolution; i < oldPoints.count(); i++) + points.append(QPointF(i - maxSize/resolution, oldPoints.at(i).y())); + } + + qint64 size = points.count(); + for (int k = 0; k < maxSize/resolution; k++) + points.append(QPointF(k + size, ((quint8)data[resolution * k] - 128)/128.0)); + + m_series->replace(points); + return maxSize; +} diff --git a/examples/charts/audio/xyseriesiodevice.h b/examples/charts/audio/xyseriesiodevice.h new file mode 100644 index 00000000..6e504b08 --- /dev/null +++ b/examples/charts/audio/xyseriesiodevice.h @@ -0,0 +1,47 @@ +/**************************************************************************** +** +** Copyright (C) 2014 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 Enterprise Charts Add-on. +** +** $QT_BEGIN_LICENSE$ +** Licensees holding valid Qt Enterprise licenses may use this file in +** accordance with the Qt Enterprise 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 XYSERIESIODEVICE_H +#define XYSERIESIODEVICE_H + +#include <QIODevice> +#include <QChartGlobal> + +QT_CHARTS_BEGIN_NAMESPACE +class QXYSeries; +QT_CHARTS_END_NAMESPACE + +QT_CHARTS_USE_NAMESPACE + +class XYSeriesIODevice : public QIODevice +{ + Q_OBJECT +public: + explicit XYSeriesIODevice(QXYSeries * series, QObject *parent = 0); + +protected: + qint64 readData(char * data, qint64 maxSize); + qint64 writeData(const char * data, qint64 maxSize); + +private: + QXYSeries *m_series; +}; + +#endif // XYSERIESIODEVICE_H diff --git a/examples/barchart/barchart.pro b/examples/charts/barchart/barchart.pro index 14db3c88..14db3c88 100644 --- a/examples/barchart/barchart.pro +++ b/examples/charts/barchart/barchart.pro diff --git a/examples/barchart/main.cpp b/examples/charts/barchart/main.cpp index 001ae2b3..a0e3cd89 100644 --- a/examples/barchart/main.cpp +++ b/examples/charts/barchart/main.cpp @@ -26,7 +26,7 @@ #include <QLegend> #include <QBarCategoryAxis> -QTCOMMERCIALCHART_USE_NAMESPACE +QT_CHARTS_USE_NAMESPACE int main(int argc, char *argv[]) { diff --git a/examples/barmodelmapper/barmodelmapper.pro b/examples/charts/barmodelmapper/barmodelmapper.pro index 91b8f367..91b8f367 100644 --- a/examples/barmodelmapper/barmodelmapper.pro +++ b/examples/charts/barmodelmapper/barmodelmapper.pro diff --git a/examples/barmodelmapper/customtablemodel.cpp b/examples/charts/barmodelmapper/customtablemodel.cpp index 3ec58384..3ec58384 100644 --- a/examples/barmodelmapper/customtablemodel.cpp +++ b/examples/charts/barmodelmapper/customtablemodel.cpp diff --git a/examples/barmodelmapper/customtablemodel.h b/examples/charts/barmodelmapper/customtablemodel.h index 755f4c7d..755f4c7d 100644 --- a/examples/barmodelmapper/customtablemodel.h +++ b/examples/charts/barmodelmapper/customtablemodel.h diff --git a/examples/barmodelmapper/main.cpp b/examples/charts/barmodelmapper/main.cpp index bf0b384b..bf0b384b 100644 --- a/examples/barmodelmapper/main.cpp +++ b/examples/charts/barmodelmapper/main.cpp diff --git a/examples/barmodelmapper/tablewidget.cpp b/examples/charts/barmodelmapper/tablewidget.cpp index f31bfff9..81e881e9 100644 --- a/examples/barmodelmapper/tablewidget.cpp +++ b/examples/charts/barmodelmapper/tablewidget.cpp @@ -32,7 +32,7 @@ #include <QHeaderView> #include <QBarCategoryAxis> -QTCOMMERCIALCHART_USE_NAMESPACE +QT_CHARTS_USE_NAMESPACE TableWidget::TableWidget(QWidget *parent) : QWidget(parent) @@ -48,13 +48,8 @@ TableWidget::TableWidget(QWidget *parent) QTableView *tableView = new QTableView; tableView->setModel(model); tableView->setMinimumWidth(300); -#if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)) tableView->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch); tableView->verticalHeader()->setSectionResizeMode(QHeaderView::Stretch); -#else - tableView->horizontalHeader()->setResizeMode(QHeaderView::Stretch); - tableView->verticalHeader()->setResizeMode(QHeaderView::Stretch); -#endif //! [2] //! [3] diff --git a/examples/barmodelmapper/tablewidget.h b/examples/charts/barmodelmapper/tablewidget.h index 3846cc11..3846cc11 100644 --- a/examples/barmodelmapper/tablewidget.h +++ b/examples/charts/barmodelmapper/tablewidget.h diff --git a/examples/boxplotchart/acme_data.txt b/examples/charts/boxplotchart/acme_data.txt index 9511418d..9511418d 100644 --- a/examples/boxplotchart/acme_data.txt +++ b/examples/charts/boxplotchart/acme_data.txt diff --git a/examples/boxplotchart/boxdatareader.cpp b/examples/charts/boxplotchart/boxdatareader.cpp index ba2d8b3a..ba2d8b3a 100644 --- a/examples/boxplotchart/boxdatareader.cpp +++ b/examples/charts/boxplotchart/boxdatareader.cpp diff --git a/examples/boxplotchart/boxdatareader.h b/examples/charts/boxplotchart/boxdatareader.h index 8f1e9c51..5dbddc14 100644 --- a/examples/boxplotchart/boxdatareader.h +++ b/examples/charts/boxplotchart/boxdatareader.h @@ -24,7 +24,7 @@ #include <QTextStream> #include <QBoxSet> -QTCOMMERCIALCHART_USE_NAMESPACE +QT_CHARTS_USE_NAMESPACE class BoxDataReader : public QTextStream { diff --git a/examples/boxplotchart/boxplotchart.pro b/examples/charts/boxplotchart/boxplotchart.pro index c2483511..c2483511 100644 --- a/examples/boxplotchart/boxplotchart.pro +++ b/examples/charts/boxplotchart/boxplotchart.pro diff --git a/examples/boxplotchart/boxplotdata.qrc b/examples/charts/boxplotchart/boxplotdata.qrc index fe6d52b5..fe6d52b5 100644 --- a/examples/boxplotchart/boxplotdata.qrc +++ b/examples/charts/boxplotchart/boxplotdata.qrc diff --git a/examples/boxplotchart/boxwhisk_data.txt b/examples/charts/boxplotchart/boxwhisk_data.txt index f1d49cf0..f1d49cf0 100644 --- a/examples/boxplotchart/boxwhisk_data.txt +++ b/examples/charts/boxplotchart/boxwhisk_data.txt diff --git a/examples/boxplotchart/main.cpp b/examples/charts/boxplotchart/main.cpp index 78ce7a54..802217e1 100644 --- a/examples/boxplotchart/main.cpp +++ b/examples/charts/boxplotchart/main.cpp @@ -29,7 +29,7 @@ #include "boxdatareader.h" -QTCOMMERCIALCHART_USE_NAMESPACE +QT_CHARTS_USE_NAMESPACE int main(int argc, char *argv[]) { diff --git a/examples/charts/callout/callout.cpp b/examples/charts/callout/callout.cpp new file mode 100644 index 00000000..2491368f --- /dev/null +++ b/examples/charts/callout/callout.cpp @@ -0,0 +1,119 @@ +/**************************************************************************** +** +** Copyright (C) 2014 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 Enterprise Charts Add-on. +** +** $QT_BEGIN_LICENSE$ +** Licensees holding valid Qt Enterprise licenses may use this file in +** accordance with the Qt Enterprise 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 "callout.h" +#include <QPainter> +#include <QFontMetrics> +#include <QGraphicsSceneMouseEvent> +#include <QMouseEvent> + +Callout::Callout(QGraphicsItem * parent): + QGraphicsItem(parent) +{ +} + +QRectF Callout::boundingRect() const +{ + QPointF anchor = mapFromParent(m_anchor); + QRectF rect; + rect.setLeft(qMin(m_rect.left(), anchor.x())); + rect.setRight(qMax(m_rect.right(), anchor.x())); + rect.setTop(qMin(m_rect.top(), anchor.y())); + rect.setBottom(qMax(m_rect.bottom(), anchor.y())); + return rect; +} + +void Callout::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) +{ + Q_UNUSED(option) + Q_UNUSED(widget) + QPainterPath path; + path.addRoundedRect(m_rect, 5, 5); + + QPointF anchor = mapFromParent(m_anchor); + if (!m_rect.contains(anchor)) { + QPointF point1, point2; + + // establish the position of the anchor point in relation to m_rect + bool above = anchor.y() <= m_rect.top(); + bool aboveCenter = anchor.y() > m_rect.top() && anchor.y() <= m_rect.center().y(); + bool belowCenter = anchor.y() > m_rect.center().y() && anchor.y() <= m_rect.bottom(); + bool below = anchor.y() > m_rect.bottom(); + + bool onLeft = anchor.x() <= m_rect.left(); + bool leftOfCenter = anchor.x() > m_rect.left() && anchor.x() <= m_rect.center().x(); + bool rightOfCenter = anchor.x() > m_rect.center().x() && anchor.x() <= m_rect.right(); + bool onRight = anchor.x() > m_rect.right(); + + // get the nearest m_rect corner. + qreal x = (onRight + rightOfCenter) * m_rect.width(); + qreal y = (below + belowCenter) * m_rect.height(); + bool cornerCase = (above && onLeft) || (above && onRight) || (below && onLeft) || (below && onRight); + bool vertical = qAbs(anchor.x() - x) > qAbs(anchor.y() - y); + + qreal x1 = x + leftOfCenter * 10 - rightOfCenter * 20 + cornerCase * !vertical * (onLeft * 10 - onRight * 20); + qreal y1 = y + aboveCenter * 10 - belowCenter * 20 + cornerCase * vertical * (above * 10 - below * 20);; + point1.setX(x1); + point1.setY(y1); + + qreal x2 = x + leftOfCenter * 20 - rightOfCenter * 10 + cornerCase * !vertical * (onLeft * 20 - onRight * 10);; + qreal y2 = y + aboveCenter * 20 - belowCenter * 10 + cornerCase * vertical * (above * 20 - below * 10);; + point2.setX(x2); + point2.setY(y2); + + path.moveTo(point1); + path.lineTo(mapFromParent(m_anchor)); + path.lineTo(point2); + path = path.simplified(); + } + painter->setBrush(QColor(255, 255, 255)); + painter->drawPath(path); + painter->drawText(m_textRect, m_text); +} + +void Callout::mousePressEvent(QGraphicsSceneMouseEvent *event) +{ + event->setAccepted(true); +} + +void Callout::mouseMoveEvent(QGraphicsSceneMouseEvent *event) +{ + if (event->buttons() & Qt::LeftButton){ + setPos(mapToParent(event->pos() - event->buttonDownPos(Qt::LeftButton))); + event->setAccepted(true); + } else { + event->setAccepted(false); + } +} + +void Callout::setText(const QString &text) +{ + m_text = text; + QFontMetrics metrics(m_font); + m_textRect = metrics.boundingRect(QRect(0, 0, 150, 150), Qt::AlignLeft, m_text); + m_textRect.translate(5, 5); + prepareGeometryChange(); + m_rect = m_textRect.adjusted(-5, -5, 5, 5); +} + +void Callout::setAnchor(QPointF point) +{ + m_anchor = point; +} diff --git a/examples/charts/callout/callout.h b/examples/charts/callout/callout.h new file mode 100644 index 00000000..23fc8484 --- /dev/null +++ b/examples/charts/callout/callout.h @@ -0,0 +1,52 @@ +/**************************************************************************** +** +** Copyright (C) 2014 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 Enterprise Charts Add-on. +** +** $QT_BEGIN_LICENSE$ +** Licensees holding valid Qt Enterprise licenses may use this file in +** accordance with the Qt Enterprise 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 CALLOUT_H +#define CALLOUT_H + +#include <QGraphicsItem> +#include <QFont> + +class QGraphicsSceneMouseEvent; + +class Callout : public QGraphicsItem +{ +public: + Callout(QGraphicsItem * parent = 0); + + void setText(const QString &text); + void setAnchor(QPointF point); + + QRectF boundingRect() const; + void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,QWidget *widget); + +protected: + void mousePressEvent(QGraphicsSceneMouseEvent *event); + void mouseMoveEvent(QGraphicsSceneMouseEvent *event); + +private: + QString m_text; + QRectF m_textRect; + QRectF m_rect; + QPointF m_anchor; + QFont m_font; +}; + +#endif // CALLOUT_H diff --git a/examples/charts/callout/callout.pro b/examples/charts/callout/callout.pro new file mode 100644 index 00000000..b0da66d6 --- /dev/null +++ b/examples/charts/callout/callout.pro @@ -0,0 +1,15 @@ +!include( ../examples.pri ) { + error( "Couldn't find the examples.pri file!" ) +} + +TARGET = callout +TEMPLATE = app + +SOURCES += \ + main.cpp\ + callout.cpp \ + view.cpp + +HEADERS += \ + callout.h \ + view.h diff --git a/examples/charts/callout/main.cpp b/examples/charts/callout/main.cpp new file mode 100644 index 00000000..a6dfc2e9 --- /dev/null +++ b/examples/charts/callout/main.cpp @@ -0,0 +1,31 @@ +/**************************************************************************** +** +** Copyright (C) 2014 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 Enterprise Charts Add-on. +** +** $QT_BEGIN_LICENSE$ +** Licensees holding valid Qt Enterprise licenses may use this file in +** accordance with the Qt Enterprise 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 <QApplication> +#include "view.h" + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + View w; + w.show(); + + return a.exec(); +} diff --git a/examples/charts/callout/view.cpp b/examples/charts/callout/view.cpp new file mode 100644 index 00000000..a7c43863 --- /dev/null +++ b/examples/charts/callout/view.cpp @@ -0,0 +1,123 @@ +/**************************************************************************** + ** + ** Copyright (C) 2014 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 Enterprise Charts Add-on. + ** + ** $QT_BEGIN_LICENSE$ + ** Licensees holding valid Qt Enterprise licenses may use this file in + ** accordance with the Qt Enterprise 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 "view.h" +#include <QResizeEvent> +#include <QGraphicsScene> +#include <QChart> +#include <QLineSeries> +#include <QSplineSeries> +#include <QGraphicsTextItem> +#include "callout.h" +#include <QMouseEvent> + +View::View(QWidget *parent) + : QGraphicsView(new QGraphicsScene, parent), + m_coordX(0), + m_coordY(0), + m_chart(0), + m_tooltip(0) +{ + setDragMode(QGraphicsView::NoDrag); + setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + + // chart + m_chart = new QChart; + m_chart->setMinimumSize(640, 480); + m_chart->setTitle("Hover the line to show callout. Click the line to make it stay"); + m_chart->legend()->hide(); + QLineSeries *series = new QLineSeries; + series->append(1, 3); + series->append(4, 5); + series->append(5, 4.5); + series->append(7, 1); + series->append(11, 2); + m_chart->addSeries(series); + + QSplineSeries *series2 = new QSplineSeries; + series2->append(1.6, 1.4); + series2->append(2.4, 3.5); + series2->append(3.7, 2.5); + series2->append(7, 4); + series2->append(10, 2); + m_chart->addSeries(series2); + + m_chart->createDefaultAxes(); + m_chart->setAcceptHoverEvents(true); + + setRenderHint(QPainter::Antialiasing); + scene()->addItem(m_chart); + + m_coordX = new QGraphicsSimpleTextItem(m_chart); + m_coordX->setPos(m_chart->size().width()/2 - 50, m_chart->size().height()); + m_coordX->setText("X: "); + m_coordY = new QGraphicsSimpleTextItem(m_chart); + m_coordY->setPos(m_chart->size().width()/2 + 50, m_chart->size().height()); + m_coordY->setText("Y: "); + + connect(series, SIGNAL(clicked(QPointF)), this, SLOT(keepCallout())); + connect(series, SIGNAL(hovered(QPointF, bool)), this, SLOT(tooltip(QPointF,bool))); + + connect(series2, SIGNAL(clicked(QPointF)), this, SLOT(keepCallout())); + connect(series2, SIGNAL(hovered(QPointF, bool)), this, SLOT(tooltip(QPointF,bool))); + + this->setMouseTracking(true); +} + +void View::resizeEvent(QResizeEvent *event) +{ + if (scene()) { + scene()->setSceneRect(QRect(QPoint(0, 0), event->size())); + m_chart->resize(event->size()); + m_coordX->setPos(m_chart->size().width()/2 - 50, m_chart->size().height() - 20); + m_coordY->setPos(m_chart->size().width()/2 + 50, m_chart->size().height() - 20); + } + QGraphicsView::resizeEvent(event); +} + +void View::mouseMoveEvent(QMouseEvent *event) +{ + m_coordX->setText(QString("X: %1").arg(m_chart->mapToValue(event->pos()).x())); + m_coordY->setText(QString("Y: %1").arg(m_chart->mapToValue(event->pos()).y())); + QGraphicsView::mouseMoveEvent(event); +} + +void View::keepCallout() +{ + m_tooltip = new Callout(m_chart); +} + +void View::tooltip(QPointF point, bool state) +{ + if (m_tooltip == 0) + m_tooltip = new Callout(m_chart); + + if (state) { + m_tooltip->setText(QString("X: %1 \nY: %2 ").arg(point.x()).arg(point.y())); + QXYSeries *series = qobject_cast<QXYSeries *>(sender()); + m_tooltip->setAnchor(m_chart->mapToPosition(point, series)); + m_tooltip->setPos(m_chart->mapToPosition(point, series) + QPoint(10, -50)); + m_tooltip->setZValue(11); + m_tooltip->show(); + } else { + m_tooltip->hide(); + } +} diff --git a/examples/charts/callout/view.h b/examples/charts/callout/view.h new file mode 100644 index 00000000..3a322382 --- /dev/null +++ b/examples/charts/callout/view.h @@ -0,0 +1,59 @@ +/**************************************************************************** +** +** Copyright (C) 2014 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 Enterprise Charts Add-on. +** +** $QT_BEGIN_LICENSE$ +** Licensees holding valid Qt Enterprise licenses may use this file in +** accordance with the Qt Enterprise 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 VIEW_H +#define VIEW_H +#include <QGraphicsView> +#include <QChartGlobal> + +QT_CHARTS_BEGIN_NAMESPACE +class QChart; +QT_CHARTS_END_NAMESPACE + +class QGraphicsScene; +class QResizeEvent; +class Callout; +class QMouseEvent; + +QT_CHARTS_USE_NAMESPACE + +class View: public QGraphicsView +{ + Q_OBJECT + +public: + View(QWidget *parent = 0); + +protected: + void resizeEvent(QResizeEvent *event); + void mouseMoveEvent(QMouseEvent *event); + +public slots: + void keepCallout(); + void tooltip(QPointF point, bool state); + +private: + QGraphicsSimpleTextItem *m_coordX; + QGraphicsSimpleTextItem *m_coordY; + QChart *m_chart; + Callout *m_tooltip; +}; + +#endif diff --git a/examples/charts/chartinteractions/chart.cpp b/examples/charts/chartinteractions/chart.cpp new file mode 100644 index 00000000..8aa2a443 --- /dev/null +++ b/examples/charts/chartinteractions/chart.cpp @@ -0,0 +1,101 @@ +/**************************************************************************** +** +** Copyright (C) 2014 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 Enterprise Charts Add-on. +** +** $QT_BEGIN_LICENSE$ +** Licensees holding valid Qt Enterprise licenses may use this file in +** accordance with the Qt Enterprise 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 "chart.h" +#include <QValueAxis> +#include <QAbstractAxis> +#include <qmath.h> + +Chart::Chart(QGraphicsItem *parent, Qt::WindowFlags wFlags, QLineSeries *series) + : QChart(QChart::ChartTypeCartesian, parent, wFlags), m_series(series) +{ + m_clicked = false; +} + +Chart::~Chart() +{ +} + +void Chart::clickPoint(const QPointF &point) +{ + // Find the closes data point + m_movingPoint = QPoint(); + m_clicked = false; + foreach (QPointF p, m_series->points()) { + if (distance(p, point) < distance(m_movingPoint, point)) { + m_movingPoint = p; + m_clicked = true; + } + } +} + +qreal Chart::distance(const QPointF &p1, const QPointF &p2) +{ + return qSqrt((p1.x() - p2.x()) * (p1.x() - p2.x()) + + (p1.y() - p2.y()) * (p1.y() - p2.y())); +} + +void Chart::setPointClicked(bool clicked) +{ + m_clicked = clicked; +} + +void Chart::handlePointMove(const QPoint &point) +{ + if (m_clicked) { + //Map the point clicked from the ChartView + //to the area occupied by the chart. + QPoint mappedPoint = point; + mappedPoint.setX(point.x() - this->plotArea().x()); + mappedPoint.setY(point.y() - this->plotArea().y()); + + //Get the x- and y axis to be able to convert the mapped + //coordinate point to the charts scale. + QAbstractAxis *axisx = this->axisX(); + QValueAxis *haxis = 0; + if (axisx->type() == QAbstractAxis::AxisTypeValue) + haxis = qobject_cast<QValueAxis *>(axisx); + + QAbstractAxis *axisy = this->axisY(); + QValueAxis *vaxis = 0; + if (axisy->type() == QAbstractAxis::AxisTypeValue) + vaxis = qobject_cast<QValueAxis *>(axisy); + + if (haxis && vaxis) { + //Calculate the "unit" between points on the x + //y axis. + double xUnit = this->plotArea().width() / haxis->max(); + double yUnit = this->plotArea().height() / vaxis->max(); + + //Convert the mappedPoint to the actual chart scale. + double x = mappedPoint.x() / xUnit; + double y = vaxis->max() - mappedPoint.y() / yUnit; + + //Replace the old point with the new one. + m_series->replace(m_movingPoint, QPointF(x, y)); + + //Update the m_movingPoint so we are able to + //do the replace also during mousemoveEvent. + m_movingPoint.setX(x); + m_movingPoint.setY(y); + } + } +} + diff --git a/examples/charts/chartinteractions/chart.h b/examples/charts/chartinteractions/chart.h new file mode 100644 index 00000000..9a10387b --- /dev/null +++ b/examples/charts/chartinteractions/chart.h @@ -0,0 +1,53 @@ +/**************************************************************************** +** +** Copyright (C) 2014 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 Enterprise Charts Add-on. +** +** $QT_BEGIN_LICENSE$ +** Licensees holding valid Qt Enterprise licenses may use this file in +** accordance with the Qt Enterprise 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 CHART_H +#define CHART_H + +#include <QChart> +#include <QLineSeries> + +QT_CHARTS_USE_NAMESPACE + +class Chart : public QChart +{ + Q_OBJECT +public: + explicit Chart(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0, QLineSeries *series = 0); + ~Chart(); + +public slots: + void clickPoint(const QPointF &point); + +public: + void handlePointMove(const QPoint &point); + void setPointClicked(bool clicked); + +private: + qreal distance(const QPointF &p1, const QPointF &p2); + QLineSeries *m_series; + QPointF m_movingPoint; + + //Boolean value to determine if an actual point in the + //series is clicked. + bool m_clicked; +}; + +#endif // CHART_H diff --git a/examples/charts/chartinteractions/chartinteractions.pro b/examples/charts/chartinteractions/chartinteractions.pro new file mode 100644 index 00000000..8cf4c36c --- /dev/null +++ b/examples/charts/chartinteractions/chartinteractions.pro @@ -0,0 +1,11 @@ +!include( ../examples.pri ) { + error( "Couldn't find the examples.pri file!" ) +} + +QT += core gui + +TARGET = chartinteractions +TEMPLATE = app + +HEADERS += chart.h chartview.h +SOURCES += main.cpp chart.cpp chartview.cpp diff --git a/examples/charts/chartinteractions/chartview.cpp b/examples/charts/chartinteractions/chartview.cpp new file mode 100644 index 00000000..95fae6cd --- /dev/null +++ b/examples/charts/chartinteractions/chartview.cpp @@ -0,0 +1,50 @@ +/**************************************************************************** +** +** Copyright (C) 2014 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 Enterprise Charts Add-on. +** +** $QT_BEGIN_LICENSE$ +** Licensees holding valid Qt Enterprise licenses may use this file in +** accordance with the Qt Enterprise 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 "chartview.h" +#include <QMouseEvent> +#include "chart.h" + +ChartView::ChartView(Chart *chart, QWidget *parent) : + QChartView(chart, parent) +{ + m_chart = chart; +} + +void ChartView::mousePressEvent(QMouseEvent *event) +{ + m_mousePos = event->pos(); + QChartView::mousePressEvent(event); +} + +void ChartView::mouseMoveEvent(QMouseEvent *event) +{ + m_chart->handlePointMove(event->pos()); + QChartView::mouseMoveEvent(event); +} + +void ChartView::mouseReleaseEvent(QMouseEvent *event) +{ + if (event->pos() != m_mousePos) { + m_chart->handlePointMove(event->pos()); + m_chart->setPointClicked(false); + } + QChartView::mouseReleaseEvent(event); +} diff --git a/examples/charts/chartinteractions/chartview.h b/examples/charts/chartinteractions/chartview.h new file mode 100644 index 00000000..931feee0 --- /dev/null +++ b/examples/charts/chartinteractions/chartview.h @@ -0,0 +1,45 @@ +/**************************************************************************** +** +** Copyright (C) 2014 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 Enterprise Charts Add-on. +** +** $QT_BEGIN_LICENSE$ +** Licensees holding valid Qt Enterprise licenses may use this file in +** accordance with the Qt Enterprise 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 CHARTVIEW_H +#define CHARTVIEW_H + +#include <QChartView> + +class Chart; + +QT_CHARTS_USE_NAMESPACE + +class ChartView : public QChartView +{ +public: + ChartView(Chart *chart, QWidget *parent = 0); + +protected: + void mousePressEvent(QMouseEvent *event); + void mouseMoveEvent(QMouseEvent *event); + void mouseReleaseEvent(QMouseEvent *event); + +private: + Chart *m_chart; + QPoint m_mousePos; +}; + +#endif diff --git a/examples/charts/chartinteractions/main.cpp b/examples/charts/chartinteractions/main.cpp new file mode 100644 index 00000000..67cfb800 --- /dev/null +++ b/examples/charts/chartinteractions/main.cpp @@ -0,0 +1,74 @@ +/**************************************************************************** +** +** Copyright (C) 2014 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 Enterprise Charts Add-on. +** +** $QT_BEGIN_LICENSE$ +** Licensees holding valid Qt Enterprise licenses may use this file in +** accordance with the Qt Enterprise 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 <QApplication> +#include <QMainWindow> +#include <QLineSeries> + +#include <QValueAxis> + +#include "chart.h" +#include "chartview.h" + +QT_CHARTS_USE_NAMESPACE + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + + QLineSeries *series = new QLineSeries(); + + series->append(0, 6); + series->append(1, 3); + series->append(2, 4); + series->append(3, 8); + series->append(7, 13); + series->append(10, 5); + *series << QPointF(11, 1) << QPointF(13, 3) << QPointF(17, 6) << QPointF(18, 3) << QPointF(20, 2); + + Chart *chart = new Chart(0, 0, series); + chart->legend()->hide(); + chart->addSeries(series); + QPen p = series->pen(); + p.setWidth(5); + series->setPen(p); + chart->createDefaultAxes(); + chart->setTitle("Drag'n drop to move data points"); + + QValueAxis *axisX = new QValueAxis(); + chart->setAxisX(axisX, series); + axisX->setRange(0, 20); + + QValueAxis *axisY = new QValueAxis(); + chart->setAxisY(axisY, series); + axisY->setRange(0, 13); + + QObject::connect(series, SIGNAL(clicked(QPointF)), chart, SLOT(clickPoint(QPointF))); + + ChartView *chartView = new ChartView(chart); + chartView->setRenderHint(QPainter::Antialiasing); + + QMainWindow window; + window.setCentralWidget(chartView); + window.resize(400, 300); + window.show(); + + return a.exec(); +} diff --git a/examples/charts/charts.pro b/examples/charts/charts.pro new file mode 100644 index 00000000..e9d3e0e8 --- /dev/null +++ b/examples/charts/charts.pro @@ -0,0 +1,60 @@ +TEMPLATE = subdirs +SUBDIRS += areachart \ + customchart \ + linechart \ + percentbarchart \ + piechart \ + piechartdrilldown \ + scatterchart \ + scatterinteractions \ + splinechart \ + stackedbarchart \ + stackedbarchartdrilldown \ + zoomlinechart \ + modeldata \ + barchart \ + boxplotchart \ + legend \ + barmodelmapper \ + lineandbar \ + horizontalbarchart \ + horizontalstackedbarchart \ + horizontalpercentbarchart \ + donutbreakdown \ + temperaturerecords \ + donutchart \ + multiaxis \ + legendmarkers \ + logvalueaxis \ + polarchart \ + piechartcustomization \ + dynamicspline \ + nesteddonuts \ + chartinteractions \ + callout \ + chartthemes + +qtHaveModule(quick) { + SUBDIRS += qmlboxplot \ + qmlpiechart \ + qmlweather \ + qmlf1legends \ + qmlcustomizations \ + qmlaxes \ + qmlcustomlegend \ + qmlpolarchart \ + qmlchart \ + qmloscilloscope +} + +contains(QT_CONFIG, multimedia) { + SUBDIRS += audio +} else { + message("QtMultimedia library not available. Some examples are disabled") +} + +!linux-arm*: { +SUBDIRS += \ + datetimeaxis +} + diff --git a/examples/charts/chartthemes/chartthemes.pro b/examples/charts/chartthemes/chartthemes.pro new file mode 100644 index 00000000..2a414557 --- /dev/null +++ b/examples/charts/chartthemes/chartthemes.pro @@ -0,0 +1,7 @@ +!include( ../examples.pri ) { + error( "Couldn't find the examples.pri file!" ) +} + +TARGET = chartthemes +SOURCES = main.cpp themewidget.cpp +HEADERS = themewidget.h diff --git a/examples/charts/chartthemes/main.cpp b/examples/charts/chartthemes/main.cpp new file mode 100644 index 00000000..5bc1af84 --- /dev/null +++ b/examples/charts/chartthemes/main.cpp @@ -0,0 +1,35 @@ +/**************************************************************************** +** +** Copyright (C) 2014 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 Enterprise Charts Add-on. +** +** $QT_BEGIN_LICENSE$ +** Licensees holding valid Qt Enterprise licenses may use this file in +** accordance with the Qt Enterprise 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 "themewidget.h" +#include <QApplication> +#include <QMainWindow> + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + QMainWindow window; + ThemeWidget *widget = new ThemeWidget(); + window.setCentralWidget(widget); + window.resize(900, 600); + window.show(); + return a.exec(); +} + diff --git a/examples/charts/chartthemes/themewidget.cpp b/examples/charts/chartthemes/themewidget.cpp new file mode 100644 index 00000000..d1b0051b --- /dev/null +++ b/examples/charts/chartthemes/themewidget.cpp @@ -0,0 +1,372 @@ +/**************************************************************************** +** +** Copyright (C) 2014 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 Enterprise Charts Add-on. +** +** $QT_BEGIN_LICENSE$ +** Licensees holding valid Qt Enterprise licenses may use this file in +** accordance with the Qt Enterprise 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 "themewidget.h" + +#include <QChartView> +#include <QPieSeries> +#include <QPieSlice> +#include <QAbstractBarSeries> +#include <QPercentBarSeries> +#include <QStackedBarSeries> +#include <QBarSeries> +#include <QBarSet> +#include <QLineSeries> +#include <QSplineSeries> +#include <QScatterSeries> +#include <QAreaSeries> +#include <QLegend> +#include <QGridLayout> +#include <QFormLayout> +#include <QComboBox> +#include <QSpinBox> +#include <QCheckBox> +#include <QGroupBox> +#include <QLabel> +#include <QTime> +#include <QBarCategoryAxis> + +ThemeWidget::ThemeWidget(QWidget *parent) : + QWidget(parent), + m_listCount(3), + m_valueMax(10), + m_valueCount(7), + m_dataTable(generateRandomData(m_listCount, m_valueMax, m_valueCount)), + m_themeComboBox(createThemeBox()), + m_antialiasCheckBox(new QCheckBox("Anti-aliasing")), + m_animatedComboBox(createAnimationBox()), + m_legendComboBox(createLegendBox()) +{ + connectSignals(); + // create layout + QGridLayout *baseLayout = new QGridLayout(); + QHBoxLayout *settingsLayout = new QHBoxLayout(); + settingsLayout->addWidget(new QLabel("Theme:")); + settingsLayout->addWidget(m_themeComboBox); + settingsLayout->addWidget(new QLabel("Animation:")); + settingsLayout->addWidget(m_animatedComboBox); + settingsLayout->addWidget(new QLabel("Legend:")); + settingsLayout->addWidget(m_legendComboBox); + settingsLayout->addWidget(m_antialiasCheckBox); + settingsLayout->addStretch(); + baseLayout->addLayout(settingsLayout, 0, 0, 1, 3); + + //create charts + + QChartView *chartView; + + chartView = new QChartView(createAreaChart()); + baseLayout->addWidget(chartView, 1, 0); + m_charts << chartView; + + chartView = new QChartView(createBarChart(m_valueCount)); + baseLayout->addWidget(chartView, 1, 1); + m_charts << chartView; + + chartView = new QChartView(createLineChart()); + baseLayout->addWidget(chartView, 1, 2); + m_charts << chartView; + + chartView = new QChartView(createPieChart()); + chartView->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored); // funny things happen if the pie slice labels no not fit the screen... + baseLayout->addWidget(chartView, 2, 0); + m_charts << chartView; + + chartView = new QChartView(createSplineChart()); + baseLayout->addWidget(chartView, 2, 1); + m_charts << chartView; + + chartView = new QChartView(createScatterChart()); + baseLayout->addWidget(chartView, 2, 2); + m_charts << chartView; + + setLayout(baseLayout); + + // Set defaults + m_antialiasCheckBox->setChecked(true); + updateUI(); +} + +ThemeWidget::~ThemeWidget() +{ +} + +void ThemeWidget::connectSignals() +{ + connect(m_themeComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI())); + connect(m_antialiasCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI())); + connect(m_animatedComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI())); + connect(m_legendComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI())); +} + +DataTable ThemeWidget::generateRandomData(int listCount, int valueMax, int valueCount) const +{ + DataTable dataTable; + + // set seed for random stuff + qsrand(QTime(0, 0, 0).secsTo(QTime::currentTime())); + + // generate random data + for (int i(0); i < listCount; i++) { + DataList dataList; + qreal yValue(0); + for (int j(0); j < valueCount; j++) { + yValue = yValue + (qreal)(qrand() % valueMax) / (qreal) valueCount; + QPointF value((j + (qreal) rand() / (qreal) RAND_MAX) * ((qreal) m_valueMax / (qreal) valueCount), + yValue); + QString label = "Slice " + QString::number(i) + ":" + QString::number(j); + dataList << Data(value, label); + } + dataTable << dataList; + } + + return dataTable; +} + +QComboBox *ThemeWidget::createThemeBox() const +{ + // settings layout + QComboBox *themeComboBox = new QComboBox(); + themeComboBox->addItem("Light", QChart::ChartThemeLight); + themeComboBox->addItem("Blue Cerulean", QChart::ChartThemeBlueCerulean); + themeComboBox->addItem("Dark", QChart::ChartThemeDark); + themeComboBox->addItem("Brown Sand", QChart::ChartThemeBrownSand); + themeComboBox->addItem("Blue NCS", QChart::ChartThemeBlueNcs); + themeComboBox->addItem("High Contrast", QChart::ChartThemeHighContrast); + themeComboBox->addItem("Blue Icy", QChart::ChartThemeBlueIcy); + themeComboBox->addItem("Qt", QChart::ChartThemeQt); + return themeComboBox; +} + +QComboBox *ThemeWidget::createAnimationBox() const +{ + // settings layout + QComboBox *animationComboBox = new QComboBox(); + animationComboBox->addItem("No Animations", QChart::NoAnimation); + animationComboBox->addItem("GridAxis Animations", QChart::GridAxisAnimations); + animationComboBox->addItem("Series Animations", QChart::SeriesAnimations); + animationComboBox->addItem("All Animations", QChart::AllAnimations); + return animationComboBox; +} + +QComboBox *ThemeWidget::createLegendBox() const +{ + QComboBox *legendComboBox = new QComboBox(); + legendComboBox->addItem("No Legend ", 0); + 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; +} + +QChart *ThemeWidget::createAreaChart() const +{ + QChart *chart = new QChart(); + chart->setTitle("Area chart"); + + // The lower series initialized to zero values + QLineSeries *lowerSeries = 0; + QString name("Series "); + int nameIndex = 0; + for (int i(0); i < m_dataTable.count(); i++) { + QLineSeries *upperSeries = new QLineSeries(chart); + for (int j(0); j < m_dataTable[i].count(); j++) { + Data data = m_dataTable[i].at(j); + if (lowerSeries) { + const QList<QPointF>& points = lowerSeries->points(); + upperSeries->append(QPointF(j, points[i].y() + data.first.y())); + } else { + upperSeries->append(QPointF(j, data.first.y())); + } + } + QAreaSeries *area = new QAreaSeries(upperSeries, lowerSeries); + area->setName(name + QString::number(nameIndex)); + nameIndex++; + chart->addSeries(area); + chart->createDefaultAxes(); + lowerSeries = upperSeries; + } + + return chart; +} + +QChart *ThemeWidget::createBarChart(int valueCount) const +{ + Q_UNUSED(valueCount); + QChart *chart = new QChart(); + chart->setTitle("Bar chart"); + + QStackedBarSeries *series = new QStackedBarSeries(chart); + for (int i(0); i < m_dataTable.count(); i++) { + QBarSet *set = new QBarSet("Bar set " + QString::number(i)); + foreach (Data data, m_dataTable[i]) + *set << data.first.y(); + series->append(set); + } + chart->addSeries(series); + chart->createDefaultAxes(); + + return chart; +} + +QChart *ThemeWidget::createLineChart() const +{ + QChart *chart = new QChart(); + chart->setTitle("Line chart"); + + QString name("Series "); + int nameIndex = 0; + foreach (DataList list, m_dataTable) { + QLineSeries *series = new QLineSeries(chart); + foreach (Data data, list) + series->append(data.first); + series->setName(name + QString::number(nameIndex)); + nameIndex++; + chart->addSeries(series); + } + chart->createDefaultAxes(); + + return chart; +} + +QChart *ThemeWidget::createPieChart() const +{ + QChart *chart = new QChart(); + chart->setTitle("Pie chart"); + + qreal pieSize = 1.0 / m_dataTable.count(); + for (int i = 0; i < m_dataTable.count(); i++) { + QPieSeries *series = new QPieSeries(chart); + foreach (Data data, m_dataTable[i]) { + QPieSlice *slice = series->append(data.second, data.first.y()); + if (data == m_dataTable[i].first()) { + slice->setLabelVisible(); + slice->setExploded(); + } + } + qreal hPos = (pieSize / 2) + (i / (qreal) m_dataTable.count()); + series->setPieSize(pieSize); + series->setHorizontalPosition(hPos); + series->setVerticalPosition(0.5); + chart->addSeries(series); + } + + return chart; +} + +QChart *ThemeWidget::createSplineChart() const +{ + // spine chart + QChart *chart = new QChart(); + chart->setTitle("Spline chart"); + QString name("Series "); + int nameIndex = 0; + foreach (DataList list, m_dataTable) { + QSplineSeries *series = new QSplineSeries(chart); + foreach (Data data, list) + series->append(data.first); + series->setName(name + QString::number(nameIndex)); + nameIndex++; + chart->addSeries(series); + } + chart->createDefaultAxes(); + return chart; +} + +QChart *ThemeWidget::createScatterChart() const +{ + // scatter chart + QChart *chart = new QChart(); + chart->setTitle("Scatter chart"); + QString name("Series "); + int nameIndex = 0; + foreach (DataList list, m_dataTable) { + QScatterSeries *series = new QScatterSeries(chart); + foreach (Data data, list) + series->append(data.first); + series->setName(name + QString::number(nameIndex)); + nameIndex++; + chart->addSeries(series); + } + chart->createDefaultAxes(); + return chart; +} + +void ThemeWidget::updateUI() +{ + QChart::ChartTheme theme = (QChart::ChartTheme) m_themeComboBox->itemData(m_themeComboBox->currentIndex()).toInt(); + + if (m_charts.at(0)->chart()->theme() != theme) { + foreach (QChartView *chartView, m_charts) + chartView->chart()->setTheme(theme); + + QPalette pal = window()->palette(); + if (theme == QChart::ChartThemeLight) { + pal.setColor(QPalette::Window, QRgb(0xf0f0f0)); + pal.setColor(QPalette::WindowText, QRgb(0x404044)); + } else if (theme == QChart::ChartThemeDark) { + pal.setColor(QPalette::Window, QRgb(0x121218)); + pal.setColor(QPalette::WindowText, QRgb(0xd6d6d6)); + } else if (theme == QChart::ChartThemeBlueCerulean) { + pal.setColor(QPalette::Window, QRgb(0x40434a)); + pal.setColor(QPalette::WindowText, QRgb(0xd6d6d6)); + } else if (theme == QChart::ChartThemeBrownSand) { + pal.setColor(QPalette::Window, QRgb(0x9e8965)); + pal.setColor(QPalette::WindowText, QRgb(0x404044)); + } else if (theme == QChart::ChartThemeBlueNcs) { + pal.setColor(QPalette::Window, QRgb(0x018bba)); + pal.setColor(QPalette::WindowText, QRgb(0x404044)); + } else if (theme == QChart::ChartThemeHighContrast) { + pal.setColor(QPalette::Window, QRgb(0xffab03)); + pal.setColor(QPalette::WindowText, QRgb(0x181818)); + } else if (theme == QChart::ChartThemeBlueIcy) { + pal.setColor(QPalette::Window, QRgb(0xcee7f0)); + pal.setColor(QPalette::WindowText, QRgb(0x404044)); + } else { + pal.setColor(QPalette::Window, QRgb(0xf0f0f0)); + pal.setColor(QPalette::WindowText, QRgb(0x404044)); + } + window()->setPalette(pal); + } + + bool checked = m_antialiasCheckBox->isChecked(); + foreach (QChartView *chart, m_charts) + chart->setRenderHint(QPainter::Antialiasing, checked); + + QChart::AnimationOptions options(m_animatedComboBox->itemData(m_animatedComboBox->currentIndex()).toInt()); + if (m_charts.at(0)->chart()->animationOptions() != options) { + foreach (QChartView *chartView, m_charts) + chartView->chart()->setAnimationOptions(options); + } + + Qt::Alignment alignment(m_legendComboBox->itemData(m_legendComboBox->currentIndex()).toInt()); + + if (!alignment) { + foreach (QChartView *chartView, m_charts) + chartView->chart()->legend()->hide(); + } else { + foreach (QChartView *chartView, m_charts) { + chartView->chart()->legend()->setAlignment(alignment); + chartView->chart()->legend()->show(); + } + } +} + diff --git a/examples/charts/chartthemes/themewidget.h b/examples/charts/chartthemes/themewidget.h new file mode 100644 index 00000000..d1a4d997 --- /dev/null +++ b/examples/charts/chartthemes/themewidget.h @@ -0,0 +1,77 @@ +/**************************************************************************** +** +** Copyright (C) 2014 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 Enterprise Charts Add-on. +** +** $QT_BEGIN_LICENSE$ +** Licensees holding valid Qt Enterprise licenses may use this file in +** accordance with the Qt Enterprise 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 THEMEWIDGET_H +#define THEMEWIDGET_H + +#include <QWidget> +#include <QChartGlobal> + +class QComboBox; +class QCheckBox; + +QT_CHARTS_BEGIN_NAMESPACE +class QChartView; +class QChart; +QT_CHARTS_END_NAMESPACE + +typedef QPair<QPointF, QString> Data; +typedef QList<Data> DataList; +typedef QList<DataList> DataTable; + +QT_CHARTS_USE_NAMESPACE + +class ThemeWidget: public QWidget +{ + Q_OBJECT +public: + explicit ThemeWidget(QWidget *parent = 0); + ~ThemeWidget(); + +private Q_SLOTS: + void updateUI(); + +private: + DataTable generateRandomData(int listCount, int valueMax, int valueCount) const; + QComboBox *createThemeBox() const; + QComboBox *createAnimationBox() const; + QComboBox *createLegendBox() const; + void connectSignals(); + QChart *createAreaChart() const; + QChart *createBarChart(int valueCount) const; + QChart *createPieChart() const; + QChart *createLineChart() const; + QChart *createSplineChart() const; + QChart *createScatterChart() const; + +private: + int m_listCount; + int m_valueMax; + int m_valueCount; + QList<QChartView *> m_charts; + DataTable m_dataTable; + + QComboBox *m_themeComboBox; + QCheckBox *m_antialiasCheckBox; + QComboBox *m_animatedComboBox; + QComboBox *m_legendComboBox; +}; + +#endif /* THEMEWIDGET_H */ diff --git a/examples/customchart/customchart.pro b/examples/charts/customchart/customchart.pro index 5f3f7382..5f3f7382 100644 --- a/examples/customchart/customchart.pro +++ b/examples/charts/customchart/customchart.pro diff --git a/examples/customchart/main.cpp b/examples/charts/customchart/main.cpp index 8cd02711..8a35dfb1 100644 --- a/examples/customchart/main.cpp +++ b/examples/charts/customchart/main.cpp @@ -24,7 +24,7 @@ #include <QLineSeries> #include <QCategoryAxis> -QTCOMMERCIALCHART_USE_NAMESPACE +QT_CHARTS_USE_NAMESPACE int main(int argc, char *argv[]) { diff --git a/examples/datetimeaxis/datetimeaxis.pro b/examples/charts/datetimeaxis/datetimeaxis.pro index 0ec9d715..0ec9d715 100644 --- a/examples/datetimeaxis/datetimeaxis.pro +++ b/examples/charts/datetimeaxis/datetimeaxis.pro diff --git a/examples/datetimeaxis/main.cpp b/examples/charts/datetimeaxis/main.cpp index 1427276b..988b74f2 100644 --- a/examples/datetimeaxis/main.cpp +++ b/examples/charts/datetimeaxis/main.cpp @@ -29,7 +29,7 @@ #include <QDebug> #include <QValueAxis> -QTCOMMERCIALCHART_USE_NAMESPACE +QT_CHARTS_USE_NAMESPACE int main(int argc, char *argv[]) { diff --git a/examples/datetimeaxis/sun_spots.txt b/examples/charts/datetimeaxis/sun_spots.txt index 91ef5982..91ef5982 100644 --- a/examples/datetimeaxis/sun_spots.txt +++ b/examples/charts/datetimeaxis/sun_spots.txt diff --git a/examples/datetimeaxis/sundata.qrc b/examples/charts/datetimeaxis/sundata.qrc index 318be590..318be590 100644 --- a/examples/datetimeaxis/sundata.qrc +++ b/examples/charts/datetimeaxis/sundata.qrc diff --git a/examples/donutbreakdown/donutbreakdown.pro b/examples/charts/donutbreakdown/donutbreakdown.pro index fecef7b8..fecef7b8 100644 --- a/examples/donutbreakdown/donutbreakdown.pro +++ b/examples/charts/donutbreakdown/donutbreakdown.pro diff --git a/examples/donutbreakdown/donutbreakdownchart.cpp b/examples/charts/donutbreakdown/donutbreakdownchart.cpp index 4886aa0a..5272f105 100644 --- a/examples/donutbreakdown/donutbreakdownchart.cpp +++ b/examples/charts/donutbreakdown/donutbreakdownchart.cpp @@ -22,7 +22,7 @@ #include <QPieSlice> #include <QPieLegendMarker> -QTCOMMERCIALCHART_USE_NAMESPACE +QT_CHARTS_USE_NAMESPACE //![1] DonutBreakdownChart::DonutBreakdownChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) diff --git a/examples/donutbreakdown/donutbreakdownchart.h b/examples/charts/donutbreakdown/donutbreakdownchart.h index ecf75d80..71b3ecf4 100644 --- a/examples/donutbreakdown/donutbreakdownchart.h +++ b/examples/charts/donutbreakdown/donutbreakdownchart.h @@ -23,7 +23,7 @@ #include <QChart> #include <QPieSeries> -QTCOMMERCIALCHART_USE_NAMESPACE +QT_CHARTS_USE_NAMESPACE class DonutBreakdownChart : public QChart { diff --git a/examples/donutbreakdown/main.cpp b/examples/charts/donutbreakdown/main.cpp index bb19f4ee..fb3925b6 100644 --- a/examples/donutbreakdown/main.cpp +++ b/examples/charts/donutbreakdown/main.cpp @@ -23,7 +23,7 @@ #include <QChartView> #include "donutbreakdownchart.h" -QTCOMMERCIALCHART_USE_NAMESPACE +QT_CHARTS_USE_NAMESPACE int main(int argc, char *argv[]) { diff --git a/examples/donutbreakdown/mainslice.cpp b/examples/charts/donutbreakdown/mainslice.cpp index b907df19..0ac83b3c 100644 --- a/examples/donutbreakdown/mainslice.cpp +++ b/examples/charts/donutbreakdown/mainslice.cpp @@ -20,7 +20,7 @@ #include "mainslice.h" -QTCOMMERCIALCHART_USE_NAMESPACE +QT_CHARTS_USE_NAMESPACE //![1] MainSlice::MainSlice(QPieSeries *breakdownSeries, QObject *parent) diff --git a/examples/donutbreakdown/mainslice.h b/examples/charts/donutbreakdown/mainslice.h index 3d99e570..6c6d63c2 100644 --- a/examples/donutbreakdown/mainslice.h +++ b/examples/charts/donutbreakdown/mainslice.h @@ -24,7 +24,7 @@ #include <QPieSlice> #include <QPieSeries> -QTCOMMERCIALCHART_USE_NAMESPACE +QT_CHARTS_USE_NAMESPACE class MainSlice : public QPieSlice { diff --git a/examples/donutchart/donutchart.pro b/examples/charts/donutchart/donutchart.pro index 72d4ea4d..72d4ea4d 100644 --- a/examples/donutchart/donutchart.pro +++ b/examples/charts/donutchart/donutchart.pro diff --git a/examples/donutchart/main.cpp b/examples/charts/donutchart/main.cpp index b47839c8..78b2a7c3 100644 --- a/examples/donutchart/main.cpp +++ b/examples/charts/donutchart/main.cpp @@ -24,7 +24,7 @@ #include <QPieSeries> #include <QPieSlice> #include <QDebug> -QTCOMMERCIALCHART_USE_NAMESPACE +QT_CHARTS_USE_NAMESPACE int main(int argc, char *argv[]) { diff --git a/examples/charts/dynamicspline/chart.cpp b/examples/charts/dynamicspline/chart.cpp new file mode 100644 index 00000000..4c7bc355 --- /dev/null +++ b/examples/charts/dynamicspline/chart.cpp @@ -0,0 +1,72 @@ +/**************************************************************************** +** +** Copyright (C) 2014 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 Enterprise Charts Add-on. +** +** $QT_BEGIN_LICENSE$ +** Licensees holding valid Qt Enterprise licenses may use this file in +** accordance with the Qt Enterprise 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 "chart.h" +#include <QAbstractAxis> +#include <QSplineSeries> +#include <QValueAxis> +#include <QTime> +#include <QDebug> + +Chart::Chart(QGraphicsItem *parent, Qt::WindowFlags wFlags): + QChart(QChart::ChartTypeCartesian, parent, wFlags), + m_series(0), + m_axis(new QValueAxis), + m_step(0), + m_x(5), + m_y(1) +{ + qsrand((uint) QTime::currentTime().msec()); + + QObject::connect(&m_timer, SIGNAL(timeout()), this, SLOT(handleTimeout())); + m_timer.setInterval(1000); + + m_series = new QSplineSeries(this); + QPen green(Qt::red); + green.setWidth(3); + m_series->setPen(green); + m_series->append(m_x, m_y); + + addSeries(m_series); + createDefaultAxes(); + setAxisX(m_axis, m_series); + m_axis->setTickCount(5); + axisX()->setRange(0, 10); + axisY()->setRange(-5, 10); + + m_timer.start(); +} + +Chart::~Chart() +{ + +} + +void Chart::handleTimeout() +{ + qreal x = plotArea().width() / m_axis->tickCount(); + qreal y = (m_axis->max() - m_axis->min()) / m_axis->tickCount(); + m_x += y; + m_y = qrand() % 5 - 2.5; + m_series->append(m_x, m_y); + scroll(x, 0); + if (m_x == 100) + m_timer.stop(); +} diff --git a/examples/charts/dynamicspline/chart.h b/examples/charts/dynamicspline/chart.h new file mode 100644 index 00000000..b6d5eb1c --- /dev/null +++ b/examples/charts/dynamicspline/chart.h @@ -0,0 +1,56 @@ +/**************************************************************************** +** +** Copyright (C) 2014 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 Enterprise Charts Add-on. +** +** $QT_BEGIN_LICENSE$ +** Licensees holding valid Qt Enterprise licenses may use this file in +** accordance with the Qt Enterprise 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 CHART_H +#define CHART_H + +#include <QChart> +#include <QTimer> + +QT_CHARTS_BEGIN_NAMESPACE +class QSplineSeries; +class QValueAxis; +QT_CHARTS_END_NAMESPACE + +QT_CHARTS_USE_NAMESPACE + +//![1] +class Chart: public QChart +{ + Q_OBJECT +public: + Chart(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0); + virtual ~Chart(); + +public slots: + void handleTimeout(); + +private: + QTimer m_timer; + QSplineSeries *m_series; + QStringList m_titles; + QValueAxis *m_axis; + qreal m_step; + qreal m_x; + qreal m_y; +}; +//![1] + +#endif /* CHART_H */ diff --git a/examples/charts/dynamicspline/dynamicspline.pro b/examples/charts/dynamicspline/dynamicspline.pro new file mode 100644 index 00000000..feb26895 --- /dev/null +++ b/examples/charts/dynamicspline/dynamicspline.pro @@ -0,0 +1,7 @@ +!include( ../examples.pri ) { + error( "Couldn't find the examples.pri file!" ) +} + +TARGET = dynamicspline +HEADERS += chart.h +SOURCES += main.cpp chart.cpp diff --git a/examples/charts/dynamicspline/main.cpp b/examples/charts/dynamicspline/main.cpp new file mode 100644 index 00000000..00f18c2f --- /dev/null +++ b/examples/charts/dynamicspline/main.cpp @@ -0,0 +1,42 @@ +/**************************************************************************** +** +** Copyright (C) 2014 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 Enterprise Charts Add-on. +** +** $QT_BEGIN_LICENSE$ +** Licensees holding valid Qt Enterprise licenses may use this file in +** accordance with the Qt Enterprise 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 "chart.h" +#include <QChartView> +#include <QApplication> +#include <QMainWindow> + +QT_CHARTS_USE_NAMESPACE + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + QMainWindow window; + Chart *chart = new Chart; + chart->setTitle("Dynamic spline chart"); + chart->legend()->hide(); + chart->setAnimationOptions(QChart::AllAnimations); + QChartView chartView(chart); + chartView.setRenderHint(QPainter::Antialiasing); + window.setCentralWidget(&chartView); + window.resize(400, 300); + window.show(); + return a.exec(); +} diff --git a/examples/charts/examples.pri b/examples/charts/examples.pri new file mode 100644 index 00000000..7b2eaaa7 --- /dev/null +++ b/examples/charts/examples.pri @@ -0,0 +1,17 @@ + +INCLUDEPATH += ../../../include + +LIBS += -L$$OUT_PWD/../../../lib + +TEMPLATE = app + +QT += charts +QT += core gui widgets + +contains(TARGET, qml.*) { + QT += qml quick +} + +target.path = $$[QT_INSTALL_EXAMPLES]/charts/$$TARGET +INSTALLS += target + diff --git a/examples/horizontalbarchart/horizontalbarchart.pro b/examples/charts/horizontalbarchart/horizontalbarchart.pro index 61ec088e..61ec088e 100644 --- a/examples/horizontalbarchart/horizontalbarchart.pro +++ b/examples/charts/horizontalbarchart/horizontalbarchart.pro diff --git a/examples/horizontalbarchart/main.cpp b/examples/charts/horizontalbarchart/main.cpp index 206f8a12..725aa127 100644 --- a/examples/horizontalbarchart/main.cpp +++ b/examples/charts/horizontalbarchart/main.cpp @@ -28,7 +28,7 @@ #include <QValueAxis> #include <QHorizontalBarSeries> -QTCOMMERCIALCHART_USE_NAMESPACE +QT_CHARTS_USE_NAMESPACE int main(int argc, char *argv[]) { diff --git a/examples/horizontalpercentbarchart/horizontalpercentbarchart.pro b/examples/charts/horizontalpercentbarchart/horizontalpercentbarchart.pro index d6168695..d6168695 100644 --- a/examples/horizontalpercentbarchart/horizontalpercentbarchart.pro +++ b/examples/charts/horizontalpercentbarchart/horizontalpercentbarchart.pro diff --git a/examples/horizontalpercentbarchart/main.cpp b/examples/charts/horizontalpercentbarchart/main.cpp index 29def46e..d8adab49 100644 --- a/examples/horizontalpercentbarchart/main.cpp +++ b/examples/charts/horizontalpercentbarchart/main.cpp @@ -27,7 +27,7 @@ #include <QBarCategoryAxis> #include <QHorizontalPercentBarSeries> -QTCOMMERCIALCHART_USE_NAMESPACE +QT_CHARTS_USE_NAMESPACE int main(int argc, char *argv[]) { diff --git a/examples/horizontalstackedbarchart/horizontalstackedbarchart.pro b/examples/charts/horizontalstackedbarchart/horizontalstackedbarchart.pro index 5c08d212..5c08d212 100644 --- a/examples/horizontalstackedbarchart/horizontalstackedbarchart.pro +++ b/examples/charts/horizontalstackedbarchart/horizontalstackedbarchart.pro diff --git a/examples/horizontalstackedbarchart/main.cpp b/examples/charts/horizontalstackedbarchart/main.cpp index 8ce6c372..13df0cdf 100644 --- a/examples/horizontalstackedbarchart/main.cpp +++ b/examples/charts/horizontalstackedbarchart/main.cpp @@ -27,7 +27,7 @@ #include <QBarCategoryAxis> #include <QHorizontalStackedBarSeries> -QTCOMMERCIALCHART_USE_NAMESPACE +QT_CHARTS_USE_NAMESPACE int main(int argc, char *argv[]) { diff --git a/examples/legend/legend.pro b/examples/charts/legend/legend.pro index 5e22fb2a..5e22fb2a 100644 --- a/examples/legend/legend.pro +++ b/examples/charts/legend/legend.pro diff --git a/examples/legend/main.cpp b/examples/charts/legend/main.cpp index 2fac3cd3..64d3903b 100644 --- a/examples/legend/main.cpp +++ b/examples/charts/legend/main.cpp @@ -23,7 +23,7 @@ #include <QApplication> #include <QMainWindow> -QTCOMMERCIALCHART_USE_NAMESPACE +QT_CHARTS_USE_NAMESPACE int main(int argc, char *argv[]) { diff --git a/examples/legend/mainwidget.cpp b/examples/charts/legend/mainwidget.cpp index 8cf3fe53..32bc2ae9 100644 --- a/examples/legend/mainwidget.cpp +++ b/examples/charts/legend/mainwidget.cpp @@ -29,7 +29,7 @@ #include <QLegend> #include <QFormLayout> -QTCOMMERCIALCHART_USE_NAMESPACE +QT_CHARTS_USE_NAMESPACE MainWidget::MainWidget(QWidget *parent) : QWidget(parent) diff --git a/examples/legend/mainwidget.h b/examples/charts/legend/mainwidget.h index 99c98e0c..3a24d674 100644 --- a/examples/legend/mainwidget.h +++ b/examples/charts/legend/mainwidget.h @@ -32,7 +32,7 @@ #include <QGroupBox> #include <QBarSeries> -QTCOMMERCIALCHART_USE_NAMESPACE +QT_CHARTS_USE_NAMESPACE class MainWidget : public QWidget { diff --git a/examples/legendmarkers/legendmarkers.pro b/examples/charts/legendmarkers/legendmarkers.pro index f79bdba4..f79bdba4 100644 --- a/examples/legendmarkers/legendmarkers.pro +++ b/examples/charts/legendmarkers/legendmarkers.pro diff --git a/examples/legendmarkers/main.cpp b/examples/charts/legendmarkers/main.cpp index f627e496..f627e496 100644 --- a/examples/legendmarkers/main.cpp +++ b/examples/charts/legendmarkers/main.cpp diff --git a/examples/legendmarkers/mainwidget.cpp b/examples/charts/legendmarkers/mainwidget.cpp index 2a20f882..f71e7a61 100644 --- a/examples/legendmarkers/mainwidget.cpp +++ b/examples/charts/legendmarkers/mainwidget.cpp @@ -31,7 +31,7 @@ #include <QXYLegendMarker> #include <qmath.h> -QTCOMMERCIALCHART_USE_NAMESPACE +QT_CHARTS_USE_NAMESPACE MainWidget::MainWidget(QWidget *parent) : QWidget(parent) diff --git a/examples/legendmarkers/mainwidget.h b/examples/charts/legendmarkers/mainwidget.h index 3c01f7b3..350808a2 100644 --- a/examples/legendmarkers/mainwidget.h +++ b/examples/charts/legendmarkers/mainwidget.h @@ -32,7 +32,7 @@ #include <QGroupBox> #include <QLineSeries> -QTCOMMERCIALCHART_USE_NAMESPACE +QT_CHARTS_USE_NAMESPACE class MainWidget : public QWidget { diff --git a/examples/lineandbar/lineandbar.pro b/examples/charts/lineandbar/lineandbar.pro index dd94abd5..dd94abd5 100644 --- a/examples/lineandbar/lineandbar.pro +++ b/examples/charts/lineandbar/lineandbar.pro diff --git a/examples/lineandbar/main.cpp b/examples/charts/lineandbar/main.cpp index f4b46e91..264d5829 100644 --- a/examples/lineandbar/main.cpp +++ b/examples/charts/lineandbar/main.cpp @@ -28,7 +28,7 @@ #include <QBarCategoryAxis> #include <QValueAxis> -QTCOMMERCIALCHART_USE_NAMESPACE +QT_CHARTS_USE_NAMESPACE int main(int argc, char *argv[]) { diff --git a/examples/linechart/linechart.pro b/examples/charts/linechart/linechart.pro index d3eb640a..d3eb640a 100644 --- a/examples/linechart/linechart.pro +++ b/examples/charts/linechart/linechart.pro diff --git a/examples/linechart/main.cpp b/examples/charts/linechart/main.cpp index d47d69f7..c0040e51 100644 --- a/examples/linechart/main.cpp +++ b/examples/charts/linechart/main.cpp @@ -23,7 +23,7 @@ #include <QChartView> #include <QLineSeries> -QTCOMMERCIALCHART_USE_NAMESPACE +QT_CHARTS_USE_NAMESPACE int main(int argc, char *argv[]) { diff --git a/examples/logvalueaxis/logvalueaxis.pro b/examples/charts/logvalueaxis/logvalueaxis.pro index ede43079..ede43079 100644 --- a/examples/logvalueaxis/logvalueaxis.pro +++ b/examples/charts/logvalueaxis/logvalueaxis.pro diff --git a/examples/logvalueaxis/main.cpp b/examples/charts/logvalueaxis/main.cpp index e1f09f09..73591ae3 100644 --- a/examples/logvalueaxis/main.cpp +++ b/examples/charts/logvalueaxis/main.cpp @@ -25,7 +25,7 @@ #include <QValueAxis> #include <QLogValueAxis> -QTCOMMERCIALCHART_USE_NAMESPACE +QT_CHARTS_USE_NAMESPACE int main(int argc, char *argv[]) { diff --git a/examples/modeldata/customtablemodel.cpp b/examples/charts/modeldata/customtablemodel.cpp index 2bec3c98..2bec3c98 100644 --- a/examples/modeldata/customtablemodel.cpp +++ b/examples/charts/modeldata/customtablemodel.cpp diff --git a/examples/modeldata/customtablemodel.h b/examples/charts/modeldata/customtablemodel.h index 755f4c7d..755f4c7d 100644 --- a/examples/modeldata/customtablemodel.h +++ b/examples/charts/modeldata/customtablemodel.h diff --git a/examples/modeldata/main.cpp b/examples/charts/modeldata/main.cpp index bf0b384b..bf0b384b 100644 --- a/examples/modeldata/main.cpp +++ b/examples/charts/modeldata/main.cpp diff --git a/examples/modeldata/modeldata.pro b/examples/charts/modeldata/modeldata.pro index 7c302bd9..7c302bd9 100644 --- a/examples/modeldata/modeldata.pro +++ b/examples/charts/modeldata/modeldata.pro diff --git a/examples/modeldata/tablewidget.cpp b/examples/charts/modeldata/tablewidget.cpp index abfa7bf5..5d50dd70 100644 --- a/examples/modeldata/tablewidget.cpp +++ b/examples/charts/modeldata/tablewidget.cpp @@ -28,7 +28,7 @@ #include <QVXYModelMapper> #include <QHeaderView> -QTCOMMERCIALCHART_USE_NAMESPACE +QT_CHARTS_USE_NAMESPACE TableWidget::TableWidget(QWidget *parent) : QWidget(parent) @@ -43,13 +43,8 @@ TableWidget::TableWidget(QWidget *parent) // create table view and add model to it QTableView *tableView = new QTableView; tableView->setModel(model); -#if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)) tableView->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch); tableView->verticalHeader()->setSectionResizeMode(QHeaderView::Stretch); -#else - tableView->horizontalHeader()->setResizeMode(QHeaderView::Stretch); - tableView->verticalHeader()->setResizeMode(QHeaderView::Stretch); -#endif //! [2] //! [3] diff --git a/examples/modeldata/tablewidget.h b/examples/charts/modeldata/tablewidget.h index 3846cc11..3846cc11 100644 --- a/examples/modeldata/tablewidget.h +++ b/examples/charts/modeldata/tablewidget.h diff --git a/examples/multiaxis/main.cpp b/examples/charts/multiaxis/main.cpp index 37c905d8..b6b53e88 100644 --- a/examples/multiaxis/main.cpp +++ b/examples/charts/multiaxis/main.cpp @@ -26,14 +26,14 @@ #include <QValueAxis> #include <QCategoryAxis> -QTCOMMERCIALCHART_USE_NAMESPACE +QT_CHARTS_USE_NAMESPACE int main(int argc, char *argv[]) { QApplication a(argc, argv); //![1] - QChart *chart = new QChart(); + QChart *chart = new QChart(); chart->legend()->hide(); chart->setTitle("Multiaxis chart example"); //![1] diff --git a/examples/multiaxis/multiaxis.pro b/examples/charts/multiaxis/multiaxis.pro index 33de57cb..33de57cb 100644 --- a/examples/multiaxis/multiaxis.pro +++ b/examples/charts/multiaxis/multiaxis.pro diff --git a/examples/charts/nesteddonuts/main.cpp b/examples/charts/nesteddonuts/main.cpp new file mode 100644 index 00000000..0b833a83 --- /dev/null +++ b/examples/charts/nesteddonuts/main.cpp @@ -0,0 +1,29 @@ +/**************************************************************************** +** +** Copyright (C) 2014 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 Enterprise Charts Add-on. +** +** $QT_BEGIN_LICENSE$ +** Licensees holding valid Qt Enterprise licenses may use this file in +** accordance with the Qt Enterprise 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 <QApplication> +#include "widget.h" + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + Widget w; + w.show(); + return a.exec(); +} diff --git a/examples/charts/nesteddonuts/nesteddonuts.pro b/examples/charts/nesteddonuts/nesteddonuts.pro new file mode 100644 index 00000000..fadab0cd --- /dev/null +++ b/examples/charts/nesteddonuts/nesteddonuts.pro @@ -0,0 +1,8 @@ +!include( ../examples.pri ) { + error( "Couldn't find the examples.pri file!" ) +} + +TARGET = nesteddonuts +SOURCES += main.cpp\ + widget.cpp +HEADERS += widget.h diff --git a/examples/charts/nesteddonuts/widget.cpp b/examples/charts/nesteddonuts/widget.cpp new file mode 100644 index 00000000..e11c4c7c --- /dev/null +++ b/examples/charts/nesteddonuts/widget.cpp @@ -0,0 +1,128 @@ +/**************************************************************************** +** +** Copyright (C) 2014 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 Enterprise Charts Add-on. +** +** $QT_BEGIN_LICENSE$ +** Licensees holding valid Qt Enterprise licenses may use this file in +** accordance with the Qt Enterprise 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 "widget.h" +#include <QChartView> +#include <QChart> +#include <QLegend> +#include <QPieSeries> +#include <QPieSlice> +#include <QTime> +#include <QGridLayout> +#include <QTimer> + +QT_CHARTS_USE_NAMESPACE + +Widget::Widget(QWidget *parent) + : QWidget(parent) +{ + setMinimumSize(800, 600); + qsrand(QTime(0, 0, 0).secsTo(QTime::currentTime())); + + //! [1] + QChartView *chartView = new QChartView; + chartView->setRenderHint(QPainter::Antialiasing); + QChart *chart = chartView->chart(); + chart->legend()->setVisible(false); + chart->setTitle("Nested donuts demo"); + chart->setAnimationOptions(QChart::AllAnimations); + //! [1] + + //! [2] + qreal minSize = 0.1; + qreal maxSize = 0.9; + int donutCount = 5; + //! [2] + + //! [3] + for (int i = 0; i < donutCount; i++) { + QPieSeries *donut = new QPieSeries; + int sliceCount = 3 + qrand() % 3; + for (int j = 0; j < sliceCount; j++) { + qreal value = 100 + qrand() % 100; + QPieSlice *slice = new QPieSlice(QString("%1").arg(value), value); + slice->setLabelVisible(true); + slice->setLabelColor(Qt::white); + slice->setLabelPosition(QPieSlice::LabelInsideTangential); + connect(slice, SIGNAL(hovered(bool)), this, SLOT(explodeSlice(bool))); + donut->append(slice); + donut->setHoleSize(minSize + i * (maxSize - minSize) / donutCount); + donut->setPieSize(minSize + (i + 1) * (maxSize - minSize) / donutCount); + } + m_donuts.append(donut); + chartView->chart()->addSeries(donut); + } + //! [3] + + // create main layout + //! [4] + QGridLayout *mainLayout = new QGridLayout; + mainLayout->addWidget(chartView, 1, 1); + setLayout(mainLayout); + //! [4] + + //! [5] + updateTimer = new QTimer(this); + connect(updateTimer, SIGNAL(timeout()), this, SLOT(updateRotation())); + updateTimer->start(1250); + //! [5] +} + +Widget::~Widget() +{ + +} + +//! [6] +void Widget::updateRotation() +{ + for (int i = 0; i < m_donuts.count(); i++) { + QPieSeries *donut = m_donuts.at(i); + qreal phaseShift = -50 + qrand() % 100; + donut->setPieStartAngle(donut->pieStartAngle() + phaseShift); + donut->setPieEndAngle(donut->pieEndAngle() + phaseShift); + } +} +//! [6] + +//! [7] +void Widget::explodeSlice(bool exploded) +{ + QPieSlice *slice = qobject_cast<QPieSlice *>(sender()); + if (exploded) { + updateTimer->stop(); + qreal sliceStartAngle = slice->startAngle(); + qreal sliceEndAngle = slice->startAngle() + slice->angleSpan(); + + QPieSeries *donut = slice->series(); + qreal seriesIndex = m_donuts.indexOf(donut); + for (int i = seriesIndex + 1; i < m_donuts.count(); i++) { + m_donuts.at(i)->setPieStartAngle(sliceEndAngle); + m_donuts.at(i)->setPieEndAngle(360 + sliceStartAngle); + } + } else { + for (int i = 0; i < m_donuts.count(); i++) { + m_donuts.at(i)->setPieStartAngle(0); + m_donuts.at(i)->setPieEndAngle(360); + } + updateTimer->start(); + } + slice->setExploded(exploded); +} +//! [7] diff --git a/examples/charts/nesteddonuts/widget.h b/examples/charts/nesteddonuts/widget.h new file mode 100644 index 00000000..6d2b749c --- /dev/null +++ b/examples/charts/nesteddonuts/widget.h @@ -0,0 +1,47 @@ +/**************************************************************************** +** +** Copyright (C) 2014 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 Enterprise Charts Add-on. +** +** $QT_BEGIN_LICENSE$ +** Licensees holding valid Qt Enterprise licenses may use this file in +** accordance with the Qt Enterprise 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 WIDGET_H +#define WIDGET_H + +#include <QWidget> +#include <QPieSeries> + +class QTimer; + +QT_CHARTS_USE_NAMESPACE + +class Widget : public QWidget +{ + Q_OBJECT + +public: + Widget(QWidget *parent = 0); + ~Widget(); + +public slots: + void updateRotation(); + void explodeSlice(bool exploded); + +private: + QList<QPieSeries *> m_donuts; + QTimer *updateTimer; +}; + +#endif // WIDGET_H diff --git a/examples/percentbarchart/main.cpp b/examples/charts/percentbarchart/main.cpp index 649b29ba..15a68206 100644 --- a/examples/percentbarchart/main.cpp +++ b/examples/charts/percentbarchart/main.cpp @@ -26,7 +26,7 @@ #include <QLegend> #include <QBarCategoryAxis> -QTCOMMERCIALCHART_USE_NAMESPACE +QT_CHARTS_USE_NAMESPACE int main(int argc, char *argv[]) { diff --git a/examples/percentbarchart/percentbarchart.pro b/examples/charts/percentbarchart/percentbarchart.pro index 983159d1..983159d1 100644 --- a/examples/percentbarchart/percentbarchart.pro +++ b/examples/charts/percentbarchart/percentbarchart.pro diff --git a/examples/piechart/main.cpp b/examples/charts/piechart/main.cpp index 79a088e0..5e7b4ef1 100644 --- a/examples/piechart/main.cpp +++ b/examples/charts/piechart/main.cpp @@ -24,7 +24,7 @@ #include <QPieSeries> #include <QPieSlice> -QTCOMMERCIALCHART_USE_NAMESPACE +QT_CHARTS_USE_NAMESPACE int main(int argc, char *argv[]) { diff --git a/examples/piechart/piechart.pro b/examples/charts/piechart/piechart.pro index 7bd48514..7bd48514 100644 --- a/examples/piechart/piechart.pro +++ b/examples/charts/piechart/piechart.pro diff --git a/examples/charts/piechartcustomization/brushtool.cpp b/examples/charts/piechartcustomization/brushtool.cpp new file mode 100644 index 00000000..08dff95a --- /dev/null +++ b/examples/charts/piechartcustomization/brushtool.cpp @@ -0,0 +1,100 @@ +/**************************************************************************** +** +** Copyright (C) 2014 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 Enterprise Charts Add-on. +** +** $QT_BEGIN_LICENSE$ +** Licensees holding valid Qt Enterprise licenses may use this file in +** accordance with the Qt Enterprise 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 "brushtool.h" +#include <QPushButton> +#include <QFormLayout> +#include <QComboBox> +#include <QColorDialog> + +BrushTool::BrushTool(QString title, QWidget *parent) + : QWidget(parent) +{ + setWindowTitle(title); + setWindowFlags(Qt::Tool); + + m_colorButton = new QPushButton(); + m_styleCombo = new QComboBox(); + m_styleCombo->addItem("Nobrush", (int) Qt::NoBrush); + m_styleCombo->addItem("Solidpattern", (int) Qt::SolidPattern); + m_styleCombo->addItem("Dense1pattern", (int) Qt::Dense1Pattern); + m_styleCombo->addItem("Dense2attern", (int) Qt::Dense2Pattern); + m_styleCombo->addItem("Dense3Pattern", (int) Qt::Dense3Pattern); + m_styleCombo->addItem("Dense4Pattern", (int) Qt::Dense4Pattern); + m_styleCombo->addItem("Dense5Pattern", (int) Qt::Dense5Pattern); + m_styleCombo->addItem("Dense6Pattern", (int) Qt::Dense6Pattern); + m_styleCombo->addItem("Dense7Pattern", (int) Qt::Dense7Pattern); + m_styleCombo->addItem("HorPattern", (int) Qt::HorPattern); + m_styleCombo->addItem("VerPattern", (int) Qt::VerPattern); + m_styleCombo->addItem("CrossPattern", (int) Qt::CrossPattern); + m_styleCombo->addItem("BDiagPattern", (int) Qt::BDiagPattern); + m_styleCombo->addItem("FDiagPattern", (int) Qt::FDiagPattern); + m_styleCombo->addItem("DiagCrossPattern", (int) Qt::DiagCrossPattern); + + QFormLayout *layout = new QFormLayout(); + layout->addRow("Color", m_colorButton); + layout->addRow("Style", m_styleCombo); + setLayout(layout); + + connect(m_colorButton, SIGNAL(clicked()), this, SLOT(showColorDialog())); + connect(m_styleCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(updateStyle())); +} + +void BrushTool::setBrush(QBrush brush) +{ + m_brush = brush; + m_colorButton->setText(m_brush.color().name()); + m_styleCombo->setCurrentIndex(m_brush.style()); // index matches the enum +} + +QBrush BrushTool::brush() const +{ + return m_brush; +} + +QString BrushTool::name() +{ + return name(m_brush); +} + +QString BrushTool::name(const QBrush &brush) +{ + return brush.color().name(); +} + +void BrushTool::showColorDialog() +{ + QColorDialog dialog(m_brush.color()); + dialog.show(); + dialog.exec(); + m_brush.setColor(dialog.selectedColor()); + m_colorButton->setText(m_brush.color().name()); + emit changed(); +} + +void BrushTool::updateStyle() +{ + Qt::BrushStyle style = (Qt::BrushStyle) m_styleCombo->itemData(m_styleCombo->currentIndex()).toInt(); + if (m_brush.style() != style) { + m_brush.setStyle(style); + emit changed(); + } +} + +#include "moc_brushtool.cpp" diff --git a/examples/charts/piechartcustomization/brushtool.h b/examples/charts/piechartcustomization/brushtool.h new file mode 100644 index 00000000..f6e31b72 --- /dev/null +++ b/examples/charts/piechartcustomization/brushtool.h @@ -0,0 +1,53 @@ +/**************************************************************************** +** +** Copyright (C) 2014 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 Enterprise Charts Add-on. +** +** $QT_BEGIN_LICENSE$ +** Licensees holding valid Qt Enterprise licenses may use this file in +** accordance with the Qt Enterprise 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 BRUSHTOOL_H +#define BRUSHTOOL_H + +#include <QWidget> +#include <QBrush> + +class QPushButton; +class QComboBox; + +class BrushTool : public QWidget +{ + Q_OBJECT + +public: + explicit BrushTool(QString title, QWidget *parent = 0); + void setBrush(QBrush brush); + QBrush brush() const; + QString name(); + static QString name(const QBrush &brush); + +Q_SIGNALS: + void changed(); + +public Q_SLOTS: + void showColorDialog(); + void updateStyle(); + +private: + QBrush m_brush; + QPushButton *m_colorButton; + QComboBox *m_styleCombo; +}; + +#endif // BRUSHTOOL_H diff --git a/examples/charts/piechartcustomization/customslice.cpp b/examples/charts/piechartcustomization/customslice.cpp new file mode 100644 index 00000000..bbcd1492 --- /dev/null +++ b/examples/charts/piechartcustomization/customslice.cpp @@ -0,0 +1,48 @@ +/**************************************************************************** +** +** Copyright (C) 2014 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 Enterprise Charts Add-on. +** +** $QT_BEGIN_LICENSE$ +** Licensees holding valid Qt Enterprise licenses may use this file in +** accordance with the Qt Enterprise 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 "customslice.h" + +QT_CHARTS_USE_NAMESPACE + +CustomSlice::CustomSlice(QString label, qreal value) + : QPieSlice(label, value) +{ + connect(this, SIGNAL(hovered(bool)), this, SLOT(showHighlight(bool))); +} + +QBrush CustomSlice::originalBrush() +{ + return m_originalBrush; +} + +void CustomSlice::showHighlight(bool show) +{ + if (show) { + QBrush brush = this->brush(); + m_originalBrush = brush; + brush.setColor(brush.color().lighter()); + setBrush(brush); + } else { + setBrush(m_originalBrush); + } +} + +#include "moc_customslice.cpp" diff --git a/examples/charts/piechartcustomization/customslice.h b/examples/charts/piechartcustomization/customslice.h new file mode 100644 index 00000000..4c8e81fa --- /dev/null +++ b/examples/charts/piechartcustomization/customslice.h @@ -0,0 +1,44 @@ +/**************************************************************************** +** +** Copyright (C) 2014 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 Enterprise Charts Add-on. +** +** $QT_BEGIN_LICENSE$ +** Licensees holding valid Qt Enterprise licenses may use this file in +** accordance with the Qt Enterprise 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 CUSTOMSLICE_H +#define CUSTOMSLICE_H + +#include <QPieSlice> + +QT_CHARTS_USE_NAMESPACE + +class CustomSlice : public QPieSlice +{ + Q_OBJECT + +public: + CustomSlice(QString label, qreal value); + +public: + QBrush originalBrush(); + +public Q_SLOTS: + void showHighlight(bool show); + +private: + QBrush m_originalBrush; +}; + +#endif // CUSTOMSLICE_H diff --git a/examples/charts/piechartcustomization/main.cpp b/examples/charts/piechartcustomization/main.cpp new file mode 100644 index 00000000..f35fd0fc --- /dev/null +++ b/examples/charts/piechartcustomization/main.cpp @@ -0,0 +1,34 @@ +/**************************************************************************** +** +** Copyright (C) 2014 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 Enterprise Charts Add-on. +** +** $QT_BEGIN_LICENSE$ +** Licensees holding valid Qt Enterprise licenses may use this file in +** accordance with the Qt Enterprise 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 "mainwidget.h" +#include <QApplication> +#include <QMainWindow> + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + QMainWindow window; + MainWidget widget; + window.setCentralWidget(&widget); + window.resize(900, 600); + window.show(); + return a.exec(); +} diff --git a/examples/charts/piechartcustomization/mainwidget.cpp b/examples/charts/piechartcustomization/mainwidget.cpp new file mode 100644 index 00000000..fb0ed05d --- /dev/null +++ b/examples/charts/piechartcustomization/mainwidget.cpp @@ -0,0 +1,360 @@ +/**************************************************************************** +** +** Copyright (C) 2014 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 Enterprise Charts Add-on. +** +** $QT_BEGIN_LICENSE$ +** Licensees holding valid Qt Enterprise licenses may use this file in +** accordance with the Qt Enterprise 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 "mainwidget.h" +#include "customslice.h" +#include "pentool.h" +#include "brushtool.h" +#include <QPushButton> +#include <QComboBox> +#include <QCheckBox> +#include <QLineEdit> +#include <QGroupBox> +#include <QDoubleSpinBox> +#include <QFormLayout> +#include <QFontDialog> +#include <QChartView> +#include <QPieSeries> + +QT_CHARTS_USE_NAMESPACE + +MainWidget::MainWidget(QWidget *parent) + : QWidget(parent), + m_slice(0) +{ + // create chart + QChart *chart = new QChart; + chart->setTitle("Piechart customization"); + chart->setAnimationOptions(QChart::AllAnimations); + + // create series + m_series = new QPieSeries(); + *m_series << new CustomSlice("Slice 1", 10.0); + *m_series << new CustomSlice("Slice 2", 20.0); + *m_series << new CustomSlice("Slice 3", 30.0); + *m_series << new CustomSlice("Slice 4", 40.0); + *m_series << new CustomSlice("Slice 5", 50.0); + m_series->setLabelsVisible(); + chart->addSeries(m_series); + + connect(m_series, SIGNAL(clicked(QPieSlice*)), this, SLOT(handleSliceClicked(QPieSlice*))); + + // chart settings + m_themeComboBox = new QComboBox(); + m_themeComboBox->addItem("Light", QChart::ChartThemeLight); + m_themeComboBox->addItem("BlueCerulean", QChart::ChartThemeBlueCerulean); + m_themeComboBox->addItem("Dark", QChart::ChartThemeDark); + m_themeComboBox->addItem("BrownSand", QChart::ChartThemeBrownSand); + m_themeComboBox->addItem("BlueNcs", QChart::ChartThemeBlueNcs); + m_themeComboBox->addItem("High Contrast", QChart::ChartThemeHighContrast); + m_themeComboBox->addItem("Blue Icy", QChart::ChartThemeBlueIcy); + m_themeComboBox->addItem("Qt", QChart::ChartThemeQt); + + m_aaCheckBox = new QCheckBox(); + m_animationsCheckBox = new QCheckBox(); + m_animationsCheckBox->setCheckState(Qt::Checked); + + m_legendCheckBox = new QCheckBox(); + + QFormLayout *chartSettingsLayout = new QFormLayout(); + chartSettingsLayout->addRow("Theme", m_themeComboBox); + chartSettingsLayout->addRow("Antialiasing", m_aaCheckBox); + chartSettingsLayout->addRow("Animations", m_animationsCheckBox); + chartSettingsLayout->addRow("Legend", m_legendCheckBox); + QGroupBox *chartSettings = new QGroupBox("Chart"); + chartSettings->setLayout(chartSettingsLayout); + + connect(m_themeComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateChartSettings())); + connect(m_aaCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateChartSettings())); + connect(m_animationsCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateChartSettings())); + connect(m_legendCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateChartSettings())); + + // series settings + m_hPosition = new QDoubleSpinBox(); + m_hPosition->setMinimum(0.0); + m_hPosition->setMaximum(1.0); + m_hPosition->setSingleStep(0.1); + m_hPosition->setValue(m_series->horizontalPosition()); + + m_vPosition = new QDoubleSpinBox(); + m_vPosition->setMinimum(0.0); + m_vPosition->setMaximum(1.0); + m_vPosition->setSingleStep(0.1); + m_vPosition->setValue(m_series->verticalPosition()); + + m_sizeFactor = new QDoubleSpinBox(); + m_sizeFactor->setMinimum(0.0); + m_sizeFactor->setMaximum(1.0); + m_sizeFactor->setSingleStep(0.1); + m_sizeFactor->setValue(m_series->pieSize()); + + m_startAngle = new QDoubleSpinBox(); + m_startAngle->setMinimum(-720); + m_startAngle->setMaximum(720); + m_startAngle->setValue(m_series->pieStartAngle()); + m_startAngle->setSingleStep(1); + + m_endAngle = new QDoubleSpinBox(); + m_endAngle->setMinimum(-720); + m_endAngle->setMaximum(720); + m_endAngle->setValue(m_series->pieEndAngle()); + m_endAngle->setSingleStep(1); + + m_holeSize = new QDoubleSpinBox(); + m_holeSize->setMinimum(0.0); + m_holeSize->setMaximum(1.0); + m_holeSize->setSingleStep(0.1); + m_holeSize->setValue(m_series->holeSize()); + + QPushButton *appendSlice = new QPushButton("Append slice"); + QPushButton *insertSlice = new QPushButton("Insert slice"); + QPushButton *removeSlice = new QPushButton("Remove selected slice"); + + QFormLayout *seriesSettingsLayout = new QFormLayout(); + seriesSettingsLayout->addRow("Horizontal position", m_hPosition); + seriesSettingsLayout->addRow("Vertical position", m_vPosition); + seriesSettingsLayout->addRow("Size factor", m_sizeFactor); + seriesSettingsLayout->addRow("Start angle", m_startAngle); + seriesSettingsLayout->addRow("End angle", m_endAngle); + seriesSettingsLayout->addRow("Hole size", m_holeSize); + seriesSettingsLayout->addRow(appendSlice); + seriesSettingsLayout->addRow(insertSlice); + seriesSettingsLayout->addRow(removeSlice); + QGroupBox *seriesSettings = new QGroupBox("Series"); + seriesSettings->setLayout(seriesSettingsLayout); + + connect(m_vPosition, SIGNAL(valueChanged(double)), this, SLOT(updateSerieSettings())); + connect(m_hPosition, SIGNAL(valueChanged(double)), this, SLOT(updateSerieSettings())); + connect(m_sizeFactor, SIGNAL(valueChanged(double)), this, SLOT(updateSerieSettings())); + connect(m_startAngle, SIGNAL(valueChanged(double)), this, SLOT(updateSerieSettings())); + connect(m_endAngle, SIGNAL(valueChanged(double)), this, SLOT(updateSerieSettings())); + connect(m_holeSize, SIGNAL(valueChanged(double)), this, SLOT(updateSerieSettings())); + connect(appendSlice, SIGNAL(clicked()), this, SLOT(appendSlice())); + connect(insertSlice, SIGNAL(clicked()), this, SLOT(insertSlice())); + connect(removeSlice, SIGNAL(clicked()), this, SLOT(removeSlice())); + + // slice settings + m_sliceName = new QLineEdit("<click a slice>"); + m_sliceName->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum); + m_sliceValue = new QDoubleSpinBox(); + m_sliceValue->setMaximum(1000); + m_sliceLabelVisible = new QCheckBox(); + m_sliceLabelArmFactor = new QDoubleSpinBox(); + m_sliceLabelArmFactor->setSingleStep(0.01); + m_sliceExploded = new QCheckBox(); + m_sliceExplodedFactor = new QDoubleSpinBox(); + m_sliceExplodedFactor->setSingleStep(0.01); + m_pen = new QPushButton(); + m_penTool = new PenTool("Slice pen", this); + m_brush = new QPushButton(); + m_brushTool = new BrushTool("Slice brush", this); + m_font = new QPushButton(); + m_labelBrush = new QPushButton(); + m_labelBrushTool = new BrushTool("Label brush", this); + m_labelPosition = new QComboBox(this); + m_labelPosition->addItem("Outside", QPieSlice::LabelOutside); + m_labelPosition->addItem("Inside horizontal", QPieSlice::LabelInsideHorizontal); + m_labelPosition->addItem("Inside tangential", QPieSlice::LabelInsideTangential); + m_labelPosition->addItem("Inside normal", QPieSlice::LabelInsideNormal); + + QFormLayout *sliceSettingsLayout = new QFormLayout(); + sliceSettingsLayout->addRow("Label", m_sliceName); + sliceSettingsLayout->addRow("Value", m_sliceValue); + sliceSettingsLayout->addRow("Pen", m_pen); + sliceSettingsLayout->addRow("Brush", m_brush); + sliceSettingsLayout->addRow("Label visible", m_sliceLabelVisible); + sliceSettingsLayout->addRow("Label font", m_font); + sliceSettingsLayout->addRow("Label brush", m_labelBrush); + sliceSettingsLayout->addRow("Label position", m_labelPosition); + sliceSettingsLayout->addRow("Label arm length", m_sliceLabelArmFactor); + sliceSettingsLayout->addRow("Exploded", m_sliceExploded); + sliceSettingsLayout->addRow("Explode distance", m_sliceExplodedFactor); + QGroupBox *sliceSettings = new QGroupBox("Selected slice"); + sliceSettings->setLayout(sliceSettingsLayout); + + connect(m_sliceName, SIGNAL(textChanged(QString)), this, SLOT(updateSliceSettings())); + connect(m_sliceValue, SIGNAL(valueChanged(double)), this, SLOT(updateSliceSettings())); + connect(m_pen, SIGNAL(clicked()), m_penTool, SLOT(show())); + connect(m_penTool, SIGNAL(changed()), this, SLOT(updateSliceSettings())); + connect(m_brush, SIGNAL(clicked()), m_brushTool, SLOT(show())); + connect(m_brushTool, SIGNAL(changed()), this, SLOT(updateSliceSettings())); + connect(m_font, SIGNAL(clicked()), this, SLOT(showFontDialog())); + connect(m_labelBrush, SIGNAL(clicked()), m_labelBrushTool, SLOT(show())); + connect(m_labelBrushTool, SIGNAL(changed()), this, SLOT(updateSliceSettings())); + connect(m_sliceLabelVisible, SIGNAL(toggled(bool)), this, SLOT(updateSliceSettings())); + connect(m_sliceLabelVisible, SIGNAL(toggled(bool)), this, SLOT(updateSliceSettings())); + connect(m_sliceLabelArmFactor, SIGNAL(valueChanged(double)), this, SLOT(updateSliceSettings())); + connect(m_sliceExploded, SIGNAL(toggled(bool)), this, SLOT(updateSliceSettings())); + connect(m_sliceExplodedFactor, SIGNAL(valueChanged(double)), this, SLOT(updateSliceSettings())); + connect(m_labelPosition, SIGNAL(currentIndexChanged(int)), this, SLOT(updateSliceSettings())); + + // create chart view + m_chartView = new QChartView(chart); + + // create main layout + QVBoxLayout *settingsLayout = new QVBoxLayout(); + settingsLayout->addWidget(chartSettings); + settingsLayout->addWidget(seriesSettings); + settingsLayout->addWidget(sliceSettings); + settingsLayout->addStretch(); + + QGridLayout *baseLayout = new QGridLayout(); + baseLayout->addLayout(settingsLayout, 0, 0); + baseLayout->addWidget(m_chartView, 0, 1); + setLayout(baseLayout); + + updateSerieSettings(); + updateChartSettings(); +} + + +void MainWidget::updateChartSettings() +{ + QChart::ChartTheme theme = (QChart::ChartTheme) m_themeComboBox->itemData(m_themeComboBox->currentIndex()).toInt(); + m_chartView->chart()->setTheme(theme); + m_chartView->setRenderHint(QPainter::Antialiasing, m_aaCheckBox->isChecked()); + + if (m_animationsCheckBox->checkState() == Qt::Checked) + m_chartView->chart()->setAnimationOptions(QChart::AllAnimations); + else + m_chartView->chart()->setAnimationOptions(QChart::NoAnimation); + + if (m_legendCheckBox->checkState() == Qt::Checked) + m_chartView->chart()->legend()->show(); + else + m_chartView->chart()->legend()->hide(); +} + +void MainWidget::updateSerieSettings() +{ + m_series->setHorizontalPosition(m_hPosition->value()); + m_series->setVerticalPosition(m_vPosition->value()); + m_series->setPieSize(m_sizeFactor->value()); + m_holeSize->setMaximum(m_sizeFactor->value()); + m_series->setPieStartAngle(m_startAngle->value()); + m_series->setPieEndAngle(m_endAngle->value()); + m_series->setHoleSize(m_holeSize->value()); +} + +void MainWidget::updateSliceSettings() +{ + if (!m_slice) + return; + + m_slice->setLabel(m_sliceName->text()); + + m_slice->setValue(m_sliceValue->value()); + + m_slice->setPen(m_penTool->pen()); + m_slice->setBrush(m_brushTool->brush()); + + m_slice->setLabelBrush(m_labelBrushTool->brush()); + m_slice->setLabelVisible(m_sliceLabelVisible->isChecked()); + m_slice->setLabelArmLengthFactor(m_sliceLabelArmFactor->value()); + m_slice->setLabelPosition((QPieSlice::LabelPosition)m_labelPosition->currentIndex()); // assumes that index is in sync with the enum + + m_slice->setExploded(m_sliceExploded->isChecked()); + m_slice->setExplodeDistanceFactor(m_sliceExplodedFactor->value()); +} + +void MainWidget::handleSliceClicked(QPieSlice *slice) +{ + m_slice = static_cast<CustomSlice *>(slice); + + // name + m_sliceName->blockSignals(true); + m_sliceName->setText(slice->label()); + m_sliceName->blockSignals(false); + + // value + m_sliceValue->blockSignals(true); + m_sliceValue->setValue(slice->value()); + m_sliceValue->blockSignals(false); + + // pen + m_pen->setText(PenTool::name(m_slice->pen())); + m_penTool->setPen(m_slice->pen()); + + // brush + m_brush->setText(m_slice->originalBrush().color().name()); + m_brushTool->setBrush(m_slice->originalBrush()); + + // label + m_labelBrush->setText(BrushTool::name(m_slice->labelBrush())); + m_labelBrushTool->setBrush(m_slice->labelBrush()); + m_font->setText(slice->labelFont().toString()); + m_sliceLabelVisible->blockSignals(true); + m_sliceLabelVisible->setChecked(slice->isLabelVisible()); + m_sliceLabelVisible->blockSignals(false); + m_sliceLabelArmFactor->blockSignals(true); + m_sliceLabelArmFactor->setValue(slice->labelArmLengthFactor()); + m_sliceLabelArmFactor->blockSignals(false); + m_labelPosition->blockSignals(true); + m_labelPosition->setCurrentIndex(slice->labelPosition()); // assumes that index is in sync with the enum + m_labelPosition->blockSignals(false); + + // exploded + m_sliceExploded->blockSignals(true); + m_sliceExploded->setChecked(slice->isExploded()); + m_sliceExploded->blockSignals(false); + m_sliceExplodedFactor->blockSignals(true); + m_sliceExplodedFactor->setValue(slice->explodeDistanceFactor()); + m_sliceExplodedFactor->blockSignals(false); +} + +void MainWidget::showFontDialog() +{ + if (!m_slice) + return; + + QFontDialog dialog(m_slice->labelFont()); + dialog.show(); + dialog.exec(); + + m_slice->setLabelFont(dialog.currentFont()); + m_font->setText(dialog.currentFont().toString()); +} + +void MainWidget::appendSlice() +{ + *m_series << new CustomSlice("Slice " + QString::number(m_series->count() + 1), 10.0); +} + +void MainWidget::insertSlice() +{ + if (!m_slice) + return; + + int i = m_series->slices().indexOf(m_slice); + + m_series->insert(i, new CustomSlice("Slice " + QString::number(m_series->count() + 1), 10.0)); +} + +void MainWidget::removeSlice() +{ + if (!m_slice) + return; + + m_sliceName->setText("<click a slice>"); + + m_series->remove(m_slice); + m_slice = 0; +} + +#include "moc_mainwidget.cpp" diff --git a/examples/charts/piechartcustomization/mainwidget.h b/examples/charts/piechartcustomization/mainwidget.h new file mode 100644 index 00000000..e9d3ada1 --- /dev/null +++ b/examples/charts/piechartcustomization/mainwidget.h @@ -0,0 +1,93 @@ +/**************************************************************************** +** +** Copyright (C) 2014 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 Enterprise Charts Add-on. +** +** $QT_BEGIN_LICENSE$ +** Licensees holding valid Qt Enterprise licenses may use this file in +** accordance with the Qt Enterprise 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 MAINWIDGET_H +#define MAINWIDGET_H + +#include <QWidget> +#include <QChartGlobal> + +class QLineEdit; +class QPushButton; +class QCheckBox; +class QComboBox; +class QDoubleSpinBox; +class PenTool; +class BrushTool; +class CustomSlice; + +QT_CHARTS_BEGIN_NAMESPACE +class QChartView; +class QPieSeries; +class QPieSlice; +QT_CHARTS_END_NAMESPACE + +QT_CHARTS_USE_NAMESPACE + +class MainWidget : public QWidget +{ + Q_OBJECT + +public: + explicit MainWidget(QWidget *parent = 0); + +public Q_SLOTS: + void updateChartSettings(); + void updateSerieSettings(); + void updateSliceSettings(); + void handleSliceClicked(QPieSlice *slice); + void showFontDialog(); + void appendSlice(); + void insertSlice(); + void removeSlice(); + +private: + QComboBox *m_themeComboBox; + QCheckBox *m_aaCheckBox; + QCheckBox *m_animationsCheckBox; + QCheckBox *m_legendCheckBox; + + QChartView *m_chartView; + QPieSeries *m_series; + CustomSlice *m_slice; + + QDoubleSpinBox *m_hPosition; + QDoubleSpinBox *m_vPosition; + QDoubleSpinBox *m_sizeFactor; + QDoubleSpinBox *m_startAngle; + QDoubleSpinBox *m_endAngle; + QDoubleSpinBox *m_holeSize; + + QLineEdit *m_sliceName; + QDoubleSpinBox *m_sliceValue; + QCheckBox *m_sliceLabelVisible; + QDoubleSpinBox *m_sliceLabelArmFactor; + QCheckBox *m_sliceExploded; + QDoubleSpinBox *m_sliceExplodedFactor; + QPushButton *m_brush; + BrushTool *m_brushTool; + QPushButton *m_pen; + PenTool *m_penTool; + QPushButton *m_font; + QPushButton *m_labelBrush; + QComboBox *m_labelPosition; + BrushTool *m_labelBrushTool; +}; + +#endif // MAINWIDGET_H diff --git a/examples/charts/piechartcustomization/pentool.cpp b/examples/charts/piechartcustomization/pentool.cpp new file mode 100644 index 00000000..104231ee --- /dev/null +++ b/examples/charts/piechartcustomization/pentool.cpp @@ -0,0 +1,141 @@ +/**************************************************************************** +** +** Copyright (C) 2014 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 Enterprise Charts Add-on. +** +** $QT_BEGIN_LICENSE$ +** Licensees holding valid Qt Enterprise licenses may use this file in +** accordance with the Qt Enterprise 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 "pentool.h" +#include <QPushButton> +#include <QDoubleSpinBox> +#include <QComboBox> +#include <QFormLayout> +#include <QColorDialog> + +PenTool::PenTool(QString title, QWidget *parent) + : QWidget(parent) +{ + setWindowTitle(title); + setWindowFlags(Qt::Tool); + + m_colorButton = new QPushButton(); + + m_widthSpinBox = new QDoubleSpinBox(); + + m_styleCombo = new QComboBox(); + m_styleCombo->addItem("NoPen"); + m_styleCombo->addItem("SolidLine"); + m_styleCombo->addItem("DashLine"); + m_styleCombo->addItem("DotLine"); + m_styleCombo->addItem("DashDotLine"); + m_styleCombo->addItem("DashDotDotLine"); + + m_capStyleCombo = new QComboBox(); + m_capStyleCombo->addItem("FlatCap", Qt::FlatCap); + m_capStyleCombo->addItem("SquareCap", Qt::SquareCap); + m_capStyleCombo->addItem("RoundCap", Qt::RoundCap); + + m_joinStyleCombo = new QComboBox(); + m_joinStyleCombo->addItem("MiterJoin", Qt::MiterJoin); + m_joinStyleCombo->addItem("BevelJoin", Qt::BevelJoin); + m_joinStyleCombo->addItem("RoundJoin", Qt::RoundJoin); + m_joinStyleCombo->addItem("SvgMiterJoin", Qt::SvgMiterJoin); + + QFormLayout *layout = new QFormLayout(); + layout->addRow("Color", m_colorButton); + layout->addRow("Width", m_widthSpinBox); + layout->addRow("Style", m_styleCombo); + layout->addRow("Cap style", m_capStyleCombo); + layout->addRow("Join style", m_joinStyleCombo); + setLayout(layout); + + connect(m_colorButton, SIGNAL(clicked()), this, SLOT(showColorDialog())); + connect(m_widthSpinBox, SIGNAL(valueChanged(double)), this, SLOT(updateWidth(double))); + connect(m_styleCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(updateStyle(int))); + connect(m_capStyleCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(updateCapStyle(int))); + connect(m_joinStyleCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(updateJoinStyle(int))); +} + +void PenTool::setPen(const QPen &pen) +{ + m_pen = pen; + m_colorButton->setText(m_pen.color().name()); + m_widthSpinBox->setValue(m_pen.widthF()); + m_styleCombo->setCurrentIndex(m_pen.style()); // index matches the enum + m_capStyleCombo->setCurrentIndex(m_capStyleCombo->findData(m_pen.capStyle())); + m_joinStyleCombo->setCurrentIndex(m_joinStyleCombo->findData(m_pen.joinStyle())); +} + +QPen PenTool::pen() const +{ + return m_pen; +} + +QString PenTool::name() +{ + return name(m_pen); +} + +QString PenTool::name(const QPen &pen) +{ + return pen.color().name() + ":" + QString::number(pen.widthF()); +} + +void PenTool::showColorDialog() +{ + QColorDialog dialog(m_pen.color()); + dialog.show(); + dialog.exec(); + m_pen.setColor(dialog.selectedColor()); + m_colorButton->setText(m_pen.color().name()); + emit changed(); +} + +void PenTool::updateWidth(double width) +{ + if (!qFuzzyCompare((qreal) width, m_pen.widthF())) { + m_pen.setWidthF(width); + emit changed(); + } +} + +void PenTool::updateStyle(int style) +{ + if (m_pen.style() != style) { + m_pen.setStyle((Qt::PenStyle) style); + emit changed(); + } +} + +void PenTool::updateCapStyle(int index) +{ + Qt::PenCapStyle capStyle = (Qt::PenCapStyle) m_capStyleCombo->itemData(index).toInt(); + if (m_pen.capStyle() != capStyle) { + m_pen.setCapStyle(capStyle); + emit changed(); + } +} + +void PenTool::updateJoinStyle(int index) +{ + Qt::PenJoinStyle joinStyle = (Qt::PenJoinStyle) m_joinStyleCombo->itemData(index).toInt(); + if (m_pen.joinStyle() != joinStyle) { + m_pen.setJoinStyle(joinStyle); + emit changed(); + } +} + +#include "moc_pentool.cpp" diff --git a/examples/charts/piechartcustomization/pentool.h b/examples/charts/piechartcustomization/pentool.h new file mode 100644 index 00000000..66e7ab10 --- /dev/null +++ b/examples/charts/piechartcustomization/pentool.h @@ -0,0 +1,60 @@ +/**************************************************************************** +** +** Copyright (C) 2014 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 Enterprise Charts Add-on. +** +** $QT_BEGIN_LICENSE$ +** Licensees holding valid Qt Enterprise licenses may use this file in +** accordance with the Qt Enterprise 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 PENTOOL_H +#define PENTOOL_H + +#include <QWidget> +#include <QPen> + +class QPushButton; +class QDoubleSpinBox; +class QComboBox; + +class PenTool : public QWidget +{ + Q_OBJECT + +public: + explicit PenTool(QString title, QWidget *parent = 0); + void setPen(const QPen &pen); + QPen pen() const; + QString name(); + static QString name(const QPen &pen); + +Q_SIGNALS: + void changed(); + +public Q_SLOTS: + void showColorDialog(); + void updateWidth(double width); + void updateStyle(int style); + void updateCapStyle(int index); + void updateJoinStyle(int index); + +private: + QPen m_pen; + QPushButton *m_colorButton; + QDoubleSpinBox *m_widthSpinBox; + QComboBox *m_styleCombo; + QComboBox *m_capStyleCombo; + QComboBox *m_joinStyleCombo; +}; + +#endif // PENTOOL_H diff --git a/examples/charts/piechartcustomization/piechartcustomization.pro b/examples/charts/piechartcustomization/piechartcustomization.pro new file mode 100644 index 00000000..722744de --- /dev/null +++ b/examples/charts/piechartcustomization/piechartcustomization.pro @@ -0,0 +1,16 @@ +!include( ../examples.pri ) { + error( "Couldn't find the examples.pri file!" ) +} + +TARGET = piechartcustomization +SOURCES += main.cpp \ + pentool.cpp \ + brushtool.cpp \ + customslice.cpp \ + mainwidget.cpp + +HEADERS += \ + pentool.h \ + brushtool.h \ + customslice.h \ + mainwidget.h diff --git a/examples/piechartdrilldown/drilldownchart.cpp b/examples/charts/piechartdrilldown/drilldownchart.cpp index 71cd1a06..b326472c 100644 --- a/examples/piechartdrilldown/drilldownchart.cpp +++ b/examples/charts/piechartdrilldown/drilldownchart.cpp @@ -20,7 +20,7 @@ #include "drilldownchart.h" #include "drilldownslice.h" -QTCOMMERCIALCHART_USE_NAMESPACE +QT_CHARTS_USE_NAMESPACE DrilldownChart::DrilldownChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) : QChart(QChart::ChartTypeCartesian, parent, wFlags), diff --git a/examples/piechartdrilldown/drilldownchart.h b/examples/charts/piechartdrilldown/drilldownchart.h index 7e14083f..554b6651 100644 --- a/examples/piechartdrilldown/drilldownchart.h +++ b/examples/charts/piechartdrilldown/drilldownchart.h @@ -22,12 +22,12 @@ #include <QChart> -QTCOMMERCIALCHART_BEGIN_NAMESPACE +QT_CHARTS_BEGIN_NAMESPACE class QAbstractSeries; class QPieSlice; -QTCOMMERCIALCHART_END_NAMESPACE +QT_CHARTS_END_NAMESPACE -QTCOMMERCIALCHART_USE_NAMESPACE +QT_CHARTS_USE_NAMESPACE class DrilldownChart : public QChart { diff --git a/examples/piechartdrilldown/drilldownslice.cpp b/examples/charts/piechartdrilldown/drilldownslice.cpp index a2f8a6cc..c04d7fe7 100644 --- a/examples/piechartdrilldown/drilldownslice.cpp +++ b/examples/charts/piechartdrilldown/drilldownslice.cpp @@ -20,7 +20,7 @@ #include "drilldownslice.h" -QTCOMMERCIALCHART_USE_NAMESPACE +QT_CHARTS_USE_NAMESPACE DrilldownSlice::DrilldownSlice(qreal value, QString prefix, QAbstractSeries *drilldownSeries) : m_drilldownSeries(drilldownSeries), diff --git a/examples/piechartdrilldown/drilldownslice.h b/examples/charts/piechartdrilldown/drilldownslice.h index ce9aae55..9743e852 100644 --- a/examples/piechartdrilldown/drilldownslice.h +++ b/examples/charts/piechartdrilldown/drilldownslice.h @@ -22,11 +22,11 @@ #include <QPieSlice> -QTCOMMERCIALCHART_BEGIN_NAMESPACE +QT_CHARTS_BEGIN_NAMESPACE class QAbstractSeries; -QTCOMMERCIALCHART_END_NAMESPACE +QT_CHARTS_END_NAMESPACE -QTCOMMERCIALCHART_USE_NAMESPACE +QT_CHARTS_USE_NAMESPACE class DrilldownSlice : public QPieSlice { diff --git a/examples/piechartdrilldown/main.cpp b/examples/charts/piechartdrilldown/main.cpp index 2fee9b87..a32587ff 100644 --- a/examples/piechartdrilldown/main.cpp +++ b/examples/charts/piechartdrilldown/main.cpp @@ -27,7 +27,7 @@ #include <QLegend> #include <QPieSeries> -QTCOMMERCIALCHART_USE_NAMESPACE +QT_CHARTS_USE_NAMESPACE int main(int argc, char *argv[]) { diff --git a/examples/piechartdrilldown/piechartdrilldown.pro b/examples/charts/piechartdrilldown/piechartdrilldown.pro index 0f9626c9..0f9626c9 100644 --- a/examples/piechartdrilldown/piechartdrilldown.pro +++ b/examples/charts/piechartdrilldown/piechartdrilldown.pro diff --git a/examples/polarchart/chartview.cpp b/examples/charts/polarchart/chartview.cpp index 311a2ab4..038ce709 100644 --- a/examples/polarchart/chartview.cpp +++ b/examples/charts/polarchart/chartview.cpp @@ -24,7 +24,7 @@ #include <QAbstractAxis> #include <QValueAxis> -QTCOMMERCIALCHART_USE_NAMESPACE +QT_CHARTS_USE_NAMESPACE ChartView::ChartView(QWidget *parent) : QChartView(parent) diff --git a/examples/polarchart/chartview.h b/examples/charts/polarchart/chartview.h index d968358b..9f59b469 100644 --- a/examples/polarchart/chartview.h +++ b/examples/charts/polarchart/chartview.h @@ -24,7 +24,7 @@ #include <QChartView> #include <QPolarChart> -QTCOMMERCIALCHART_USE_NAMESPACE +QT_CHARTS_USE_NAMESPACE class ChartView : public QChartView { diff --git a/examples/polarchart/main.cpp b/examples/charts/polarchart/main.cpp index f4516ac4..cc959519 100644 --- a/examples/polarchart/main.cpp +++ b/examples/charts/polarchart/main.cpp @@ -29,7 +29,7 @@ #include <QPolarChart> #include <QDebug> -QTCOMMERCIALCHART_USE_NAMESPACE +QT_CHARTS_USE_NAMESPACE int main(int argc, char *argv[]) { diff --git a/examples/polarchart/polarchart.pro b/examples/charts/polarchart/polarchart.pro index 8759c1ce..8759c1ce 100644 --- a/examples/polarchart/polarchart.pro +++ b/examples/charts/polarchart/polarchart.pro diff --git a/examples/charts/qmlaxes/main.cpp b/examples/charts/qmlaxes/main.cpp new file mode 100644 index 00000000..bb0957e8 --- /dev/null +++ b/examples/charts/qmlaxes/main.cpp @@ -0,0 +1,50 @@ +/**************************************************************************** +** +** Copyright (C) 2014 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 Enterprise Charts Add-on. +** +** $QT_BEGIN_LICENSE$ +** Licensees holding valid Qt Enterprise licenses may use this file in +** accordance with the Qt Enterprise 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 <QApplication> +#include <QtCore/QDir> +#include <QtQuick/QQuickView> +#include <QtQml/QQmlEngine> + +int main(int argc, char *argv[]) +{ + // Qt Charts uses Qt Graphics View Framework for drawing, therefore QApplication must be used. + QApplication app(argc, argv); + + QQuickView viewer; + + // The following are needed to make examples run without having to install the module + // in desktop environments. +#ifdef Q_OS_WIN + QString extraImportPath(QStringLiteral("%1/../../../../%2")); +#else + QString extraImportPath(QStringLiteral("%1/../../../%2")); +#endif + viewer.engine()->addImportPath(extraImportPath.arg(QGuiApplication::applicationDirPath(), + QString::fromLatin1("qml"))); + QObject::connect(viewer.engine(), &QQmlEngine::quit, &viewer, &QWindow::close); + + viewer.setTitle(QStringLiteral("QML Axes")); + viewer.setSource(QUrl("qrc:/qml/qmlaxes/main.qml")); + viewer.setResizeMode(QQuickView::SizeRootObjectToView); + viewer.show(); + + return app.exec(); +} diff --git a/examples/charts/qmlaxes/qml/qmlaxes/View1.qml b/examples/charts/qmlaxes/qml/qmlaxes/View1.qml new file mode 100644 index 00000000..4c09e269 --- /dev/null +++ b/examples/charts/qmlaxes/qml/qmlaxes/View1.qml @@ -0,0 +1,68 @@ +/**************************************************************************** +** +** Copyright (C) 2014 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 Enterprise Charts Add-on. +** +** $QT_BEGIN_LICENSE$ +** Licensees holding valid Qt Enterprise licenses may use this file in +** accordance with the Qt Enterprise 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 2.0 +import QtCharts 2.0 + +Rectangle { + anchors.fill: parent + + //![1] + ChartView { + title: "Two Series, Common Axes" + anchors.fill: parent + legend.visible: false + antialiasing: true + + ValueAxis { + id: axisX + min: 0 + max: 10 + tickCount: 5 + } + + ValueAxis { + id: axisY + min: -0.5 + max: 1.5 + } + + LineSeries { + id: series1 + axisX: axisX + axisY: axisY + } + + ScatterSeries { + id: series2 + axisX: axisX + axisY: axisY + } + } + + // Add data dynamically to the series + Component.onCompleted: { + for (var i = 0; i <= 10; i++) { + series1.append(i, Math.random()); + series2.append(i, Math.random()); + } + } + //![1] +} diff --git a/examples/charts/qmlaxes/qml/qmlaxes/View2.qml b/examples/charts/qmlaxes/qml/qmlaxes/View2.qml new file mode 100644 index 00000000..4672c19f --- /dev/null +++ b/examples/charts/qmlaxes/qml/qmlaxes/View2.qml @@ -0,0 +1,60 @@ +/**************************************************************************** +** +** Copyright (C) 2014 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 Enterprise Charts Add-on. +** +** $QT_BEGIN_LICENSE$ +** Licensees holding valid Qt Enterprise licenses may use this file in +** accordance with the Qt Enterprise 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 2.0 +import QtCharts 2.0 + +Rectangle { + anchors.fill: parent + + //![1] + ChartView { + title: "Accurate Historical Data" + anchors.fill: parent + legend.visible: false + antialiasing: true + + LineSeries { + axisX: DateTimeAxis { + format: "yyyy MMM" + tickCount: 5 + } + axisY: ValueAxis { + min: 0 + max: 150 + } + + // Please note that month in JavaScript months are zero based, so 2 means March + XYPoint { x: toMsecsSinceEpoch(new Date(1950, 2, 15)); y: 5 } + XYPoint { x: toMsecsSinceEpoch(new Date(1970, 0, 1)); y: 50 } + XYPoint { x: toMsecsSinceEpoch(new Date(1987, 12, 31)); y: 102 } + XYPoint { x: toMsecsSinceEpoch(new Date(1998, 7, 1)); y: 100 } + XYPoint { x: toMsecsSinceEpoch(new Date(2012, 8, 2)); y: 110 } + } + } + + // DateTimeAxis is based on QDateTimes so we must convert our JavaScript dates to + // milliseconds since epoch to make them match the DateTimeAxis values + function toMsecsSinceEpoch(date) { + var msecs = date.getTime(); + return msecs; + } + //![1] +} diff --git a/examples/charts/qmlaxes/qml/qmlaxes/View3.qml b/examples/charts/qmlaxes/qml/qmlaxes/View3.qml new file mode 100644 index 00000000..711833c6 --- /dev/null +++ b/examples/charts/qmlaxes/qml/qmlaxes/View3.qml @@ -0,0 +1,68 @@ +/**************************************************************************** +** +** Copyright (C) 2014 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 Enterprise Charts Add-on. +** +** $QT_BEGIN_LICENSE$ +** Licensees holding valid Qt Enterprise licenses may use this file in +** accordance with the Qt Enterprise 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 2.0 +import QtCharts 2.0 + +Rectangle { + anchors.fill: parent + + //![1] + ChartView { + title: "Numerical Data for Dummies" + anchors.fill: parent + legend.visible: false + antialiasing: true + + LineSeries { + axisY: CategoryAxis { + min: 0 + max: 30 + CategoryRange { + label: "critical" + endValue: 2 + } + CategoryRange { + label: "low" + endValue: 4 + } + CategoryRange { + label: "normal" + endValue: 7 + } + CategoryRange { + label: "high" + endValue: 15 + } + CategoryRange { + label: "extremely high" + endValue: 30 + } + } + + XYPoint { x: 0; y: 4.3 } + XYPoint { x: 1; y: 4.1 } + XYPoint { x: 2; y: 4.7 } + XYPoint { x: 3; y: 3.9 } + XYPoint { x: 4; y: 5.2 } + } + } + //![1] +} diff --git a/examples/charts/qmlaxes/qml/qmlaxes/main.qml b/examples/charts/qmlaxes/qml/qmlaxes/main.qml new file mode 100644 index 00000000..cc75dca3 --- /dev/null +++ b/examples/charts/qmlaxes/qml/qmlaxes/main.qml @@ -0,0 +1,80 @@ +/**************************************************************************** +** +** Copyright (C) 2014 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 Enterprise Charts Add-on. +** +** $QT_BEGIN_LICENSE$ +** Licensees holding valid Qt Enterprise licenses may use this file in +** accordance with the Qt Enterprise 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 2.0 + +Rectangle { + width: 440 + height: 330 + property bool sourceLoaded: false + + ListView { + id: root + focus: true + anchors.fill: parent + snapMode: ListView.SnapOneItem + highlightRangeMode: ListView.StrictlyEnforceRange + highlightMoveDuration: 250 + orientation: ListView.Horizontal + boundsBehavior: Flickable.StopAtBounds + + onCurrentIndexChanged: { + if (infoText.opacity > 0.0) { + if (sourceLoaded) + infoText.opacity = 0.0; + else if (currentIndex != 0) + currentIndex = 0; + } + } + + model: ListModel { + ListElement {component: "View1.qml"} + ListElement {component: "View2.qml"} + ListElement {component: "View3.qml"} + } + + delegate: Loader { + width: root.width + height: root.height + + source: component + asynchronous: true + + onLoaded: sourceLoaded = true + } + } + + Rectangle { + id: infoText + anchors.centerIn: parent + width: parent.width + height: 40 + color: "black" + Text { + color: "white" + anchors.centerIn: parent + text: "You can navigate between views using swipe or arrow keys" + } + + Behavior on opacity { + NumberAnimation { duration: 400 } + } + } +} diff --git a/examples/charts/qmlaxes/qmlaxes.pro b/examples/charts/qmlaxes/qmlaxes.pro new file mode 100644 index 00000000..50b4c012 --- /dev/null +++ b/examples/charts/qmlaxes/qmlaxes.pro @@ -0,0 +1,7 @@ +!include( ../examples.pri ) { + error( "Couldn't find the examples.pri file!" ) +} + +RESOURCES += resources.qrc +SOURCES += main.cpp +OTHER_FILES += qml/qmlaxes/* diff --git a/examples/charts/qmlaxes/resources.qrc b/examples/charts/qmlaxes/resources.qrc new file mode 100644 index 00000000..c30b2f2c --- /dev/null +++ b/examples/charts/qmlaxes/resources.qrc @@ -0,0 +1,8 @@ +<RCC> + <qresource prefix="/"> + <file>qml/qmlaxes/main.qml</file> + <file>qml/qmlaxes/View1.qml</file> + <file>qml/qmlaxes/View2.qml</file> + <file>qml/qmlaxes/View3.qml</file> + </qresource> +</RCC> diff --git a/examples/charts/qmlboxplot/main.cpp b/examples/charts/qmlboxplot/main.cpp new file mode 100644 index 00000000..709bd5d2 --- /dev/null +++ b/examples/charts/qmlboxplot/main.cpp @@ -0,0 +1,50 @@ +/**************************************************************************** +** +** Copyright (C) 2014 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 Enterprise Charts Add-on. +** +** $QT_BEGIN_LICENSE$ +** Licensees holding valid Qt Enterprise licenses may use this file in +** accordance with the Qt Enterprise 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 <QApplication> +#include <QDir> +#include <QtQuick/QQuickView> +#include <QtQml/QQmlEngine> + +int main(int argc, char *argv[]) +{ + // Qt Charts uses Qt Graphics View Framework for drawing, therefore QApplication must be used. + QApplication app(argc, argv); + + QQuickView viewer; + + // The following are needed to make examples run without having to install the module + // in desktop environments. +#ifdef Q_OS_WIN + QString extraImportPath(QStringLiteral("%1/../../../../%2")); +#else + QString extraImportPath(QStringLiteral("%1/../../../%2")); +#endif + viewer.engine()->addImportPath(extraImportPath.arg(QGuiApplication::applicationDirPath(), + QString::fromLatin1("qml"))); + QObject::connect(viewer.engine(), &QQmlEngine::quit, &viewer, &QWindow::close); + + viewer.setTitle(QStringLiteral("QML Box Plot")); + viewer.setSource(QUrl("qrc:/qml/qmlboxplot/main.qml")); + viewer.setResizeMode(QQuickView::SizeRootObjectToView); + viewer.show(); + + return app.exec(); +} diff --git a/examples/qmlboxplot/qml/qmlboxplot/main.qml b/examples/charts/qmlboxplot/qml/qmlboxplot/main.qml index 11d927a6..bb71b5df 100644 --- a/examples/qmlboxplot/qml/qmlboxplot/main.qml +++ b/examples/charts/qmlboxplot/qml/qmlboxplot/main.qml @@ -18,8 +18,8 @@ ** ****************************************************************************/ -import QtQuick 1.0 -import QtCommercial.Chart 1.3 +import QtQuick 2.0 +import QtCharts 2.0 ChartView { title: "Box Plot series" @@ -27,6 +27,7 @@ ChartView { height: 300 theme: ChartView.ChartThemeBrownSand legend.alignment: Qt.AlignBottom + antialiasing: true BoxPlotSeries { id: plotSeries diff --git a/examples/qmlboxplot/qmlboxplot.pro b/examples/charts/qmlboxplot/qmlboxplot.pro index 194aef38..237f05f1 100644 --- a/examples/qmlboxplot/qmlboxplot.pro +++ b/examples/charts/qmlboxplot/qmlboxplot.pro @@ -5,7 +5,5 @@ RESOURCES += resources.qrc SOURCES += main.cpp -include(qmlapplicationviewer/qmlapplicationviewer.pri) - OTHER_FILES += \ qml/qmlboxplot/main.qml diff --git a/examples/qmlboxplot/resources.qrc b/examples/charts/qmlboxplot/resources.qrc index 49a98f16..49a98f16 100644 --- a/examples/qmlboxplot/resources.qrc +++ b/examples/charts/qmlboxplot/resources.qrc diff --git a/examples/charts/qmlchart/main.cpp b/examples/charts/qmlchart/main.cpp new file mode 100644 index 00000000..16327b97 --- /dev/null +++ b/examples/charts/qmlchart/main.cpp @@ -0,0 +1,50 @@ +/**************************************************************************** +** +** Copyright (C) 2014 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 Enterprise Charts Add-on. +** +** $QT_BEGIN_LICENSE$ +** Licensees holding valid Qt Enterprise licenses may use this file in +** accordance with the Qt Enterprise 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 <QtWidgets/QApplication> +#include <QtQuick/QQuickView> +#include <QtCore/QDir> +#include <QtQml/QQmlEngine> + +int main(int argc, char *argv[]) +{ + // Qt Charts uses Qt Graphics View Framework for drawing, therefore QApplication must be used. + QApplication app(argc, argv); + + QQuickView viewer; + // The following are needed to make examples run without having to install the module + // in desktop environments. +#ifdef Q_OS_WIN + QString extraImportPath(QStringLiteral("%1/../../../../%2")); +#else + QString extraImportPath(QStringLiteral("%1/../../../%2")); +#endif + viewer.engine()->addImportPath(extraImportPath.arg(QGuiApplication::applicationDirPath(), + QString::fromLatin1("qml"))); + QObject::connect(viewer.engine(), &QQmlEngine::quit, &viewer, &QWindow::close); + + viewer.setTitle(QStringLiteral("QML Chart")); + + viewer.setSource(QUrl("qrc:/qml/qmlchart/main.qml")); + viewer.setResizeMode(QQuickView::SizeRootObjectToView); + viewer.show(); + + return app.exec(); +} diff --git a/examples/charts/qmlchart/qml/qmlchart/View1.qml b/examples/charts/qmlchart/qml/qmlchart/View1.qml new file mode 100644 index 00000000..20590780 --- /dev/null +++ b/examples/charts/qmlchart/qml/qmlchart/View1.qml @@ -0,0 +1,54 @@ +/**************************************************************************** +** +** Copyright (C) 2014 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 Enterprise Charts Add-on. +** +** $QT_BEGIN_LICENSE$ +** Licensees holding valid Qt Enterprise licenses may use this file in +** accordance with the Qt Enterprise 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$ +** +****************************************************************************/ + +//![2] +import QtQuick 2.0 +//![2] +import QtCharts 2.0 + +Rectangle { + anchors.fill: parent + property variant othersSlice: 0 + + //![1] + ChartView { + id: chart + title: "Top-5 car brand shares in Finland" + anchors.fill: parent + legend.alignment: Qt.AlignBottom + antialiasing: true + + PieSeries { + id: pieSeries + PieSlice { label: "Volkswagen"; value: 13.5 } + PieSlice { label: "Toyota"; value: 10.9 } + PieSlice { label: "Ford"; value: 8.6 } + PieSlice { label: "Skoda"; value: 8.2 } + PieSlice { label: "Volvo"; value: 6.8 } + } + } + + Component.onCompleted: { + // You can also manipulate slices dynamically + othersSlice = pieSeries.append("Others", 52.0); + pieSeries.find("Volkswagen").exploded = true; + } + //![1] +} diff --git a/examples/charts/qmlchart/qml/qmlchart/View10.qml b/examples/charts/qmlchart/qml/qmlchart/View10.qml new file mode 100644 index 00000000..a3e3442b --- /dev/null +++ b/examples/charts/qmlchart/qml/qmlchart/View10.qml @@ -0,0 +1,42 @@ +/**************************************************************************** +** +** Copyright (C) 2014 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 Enterprise Charts Add-on. +** +** $QT_BEGIN_LICENSE$ +** Licensees holding valid Qt Enterprise licenses may use this file in +** accordance with the Qt Enterprise 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 2.0 +import QtCharts 2.0 + +Rectangle { + anchors.fill: parent + + //![1] + ChartView { + title: "Horizontal Stacked Bar series" + anchors.fill: parent + legend.alignment: Qt.AlignBottom + antialiasing: true + + HorizontalStackedBarSeries { + axisY: BarCategoryAxis { categories: ["2007", "2008", "2009", "2010", "2011", "2012" ] } + BarSet { label: "Bob"; values: [2, 2, 3, 4, 5, 6] } + BarSet { label: "Susan"; values: [5, 1, 2, 4, 1, 7] } + BarSet { label: "James"; values: [3, 5, 8, 13, 5, 8] } + } + } + //![1] +} diff --git a/examples/charts/qmlchart/qml/qmlchart/View11.qml b/examples/charts/qmlchart/qml/qmlchart/View11.qml new file mode 100644 index 00000000..68aaf907 --- /dev/null +++ b/examples/charts/qmlchart/qml/qmlchart/View11.qml @@ -0,0 +1,43 @@ +/**************************************************************************** +** +** Copyright (C) 2014 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 Enterprise Charts Add-on. +** +** $QT_BEGIN_LICENSE$ +** Licensees holding valid Qt Enterprise licenses may use this file in +** accordance with the Qt Enterprise 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 2.0 +import QtCharts 2.0 + +Rectangle { + anchors.fill: parent + + //![1] + ChartView { + title: "Horizontal Percent Bar series" + anchors.fill: parent + legend.alignment: Qt.AlignBottom + antialiasing: true + + HorizontalPercentBarSeries { + axisY: BarCategoryAxis { categories: ["2007", "2008", "2009", "2010", "2011", "2012" ] } + BarSet { label: "Bob"; values: [2, 2, 3, 4, 5, 6] } + BarSet { label: "Susan"; values: [5, 1, 2, 4, 1, 7] } + BarSet { label: "James"; values: [3, 5, 8, 13, 5, 8] } + } + } + //![1] +} + diff --git a/examples/charts/qmlchart/qml/qmlchart/View12.qml b/examples/charts/qmlchart/qml/qmlchart/View12.qml new file mode 100644 index 00000000..04be8f00 --- /dev/null +++ b/examples/charts/qmlchart/qml/qmlchart/View12.qml @@ -0,0 +1,77 @@ +/**************************************************************************** +** +** Copyright (C) 2014 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 Enterprise Charts Add-on. +** +** $QT_BEGIN_LICENSE$ +** Licensees holding valid Qt Enterprise licenses may use this file in +** accordance with the Qt Enterprise 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 2.0 +import QtCharts 2.0 + +Rectangle { + anchors.fill: parent + + //![1] + ChartView { + id: chart + title: "Production costs" + anchors.fill: parent + legend.visible: false + antialiasing: true + + PieSeries { + id: pieOuter + size: 0.96 + holeSize: 0.7 + PieSlice { id: slice; label: "Alpha"; value: 19511; color: "#8AB846"; borderColor: "#163430" } + PieSlice { label: "Epsilon"; value: 11105; color: "#C0EEFF"; borderColor: "#3B391C" } + PieSlice { label: "Psi"; value: 9352; color: "#DF8939"; borderColor: "#13060C" } + } + + PieSeries { + size: 0.7 + id: pieInner + holeSize: 0.25 + + PieSlice { label: "Materials"; value: 10334; color: "#8AB846"; borderColor: "#163430" } + PieSlice { label: "Employee"; value: 3066; color: "#AAE356"; borderColor: "#163430" } + PieSlice { label: "Logistics"; value: 6111; color: "#99CC4E"; borderColor: "#163430" } + + PieSlice { label: "Materials"; value: 7371; color: "#C0EEFF"; borderColor: "#3B391C" } + PieSlice { label: "Employee"; value: 2443; color: "#C9FAFF"; borderColor: "#3B391C" } + PieSlice { label: "Logistics"; value: 1291; color: "#B0FAFF"; borderColor: "#3B391C" } + + PieSlice { label: "Materials"; value: 4022; color: "#DF8939"; borderColor: "#13060C" } + PieSlice { label: "Employee"; value: 3998; color: "#FC9D42"; borderColor: "#13060C" } + PieSlice { label: "Logistics"; value: 1332; color: "#F2963F"; borderColor: "#13060C" } + } + } + + Component.onCompleted: { + // Set the common slice properties dynamically for convenience + for (var i = 0; i < pieOuter.count; i++) { + pieOuter.at(i).labelPosition = PieSlice.LabelOutside; + pieOuter.at(i).labelVisible = true; + pieOuter.at(i).borderWidth = 3; + } + for (var i = 0; i < pieInner.count; i++) { + pieInner.at(i).labelPosition = PieSlice.LabelInsideNormal; + pieInner.at(i).labelVisible = true; + pieInner.at(i).borderWidth = 2; + } + } + //![1] +} diff --git a/examples/charts/qmlchart/qml/qmlchart/View2.qml b/examples/charts/qmlchart/qml/qmlchart/View2.qml new file mode 100644 index 00000000..be0ae18d --- /dev/null +++ b/examples/charts/qmlchart/qml/qmlchart/View2.qml @@ -0,0 +1,45 @@ +/**************************************************************************** +** +** Copyright (C) 2014 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 Enterprise Charts Add-on. +** +** $QT_BEGIN_LICENSE$ +** Licensees holding valid Qt Enterprise licenses may use this file in +** accordance with the Qt Enterprise 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 2.0 +import QtCharts 2.0 + +Rectangle { + anchors.fill: parent + + //![1] + ChartView { + title: "Line" + anchors.fill: parent + antialiasing: true + + LineSeries { + name: "LineSeries" + 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 } + } + } + //![1] +} diff --git a/examples/charts/qmlchart/qml/qmlchart/View3.qml b/examples/charts/qmlchart/qml/qmlchart/View3.qml new file mode 100644 index 00000000..e7680bea --- /dev/null +++ b/examples/charts/qmlchart/qml/qmlchart/View3.qml @@ -0,0 +1,45 @@ +/**************************************************************************** +** +** Copyright (C) 2014 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 Enterprise Charts Add-on. +** +** $QT_BEGIN_LICENSE$ +** Licensees holding valid Qt Enterprise licenses may use this file in +** accordance with the Qt Enterprise 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 2.0 +import QtCharts 2.0 + +Rectangle { + anchors.fill: parent + + //![1] + ChartView { + title: "Spline" + anchors.fill: parent + antialiasing: true + + SplineSeries { + name: "SplineSeries" + XYPoint { x: 0; y: 0.0 } + XYPoint { x: 1.1; y: 3.2 } + XYPoint { x: 1.9; y: 2.4 } + XYPoint { x: 2.1; y: 2.1 } + XYPoint { x: 2.9; y: 2.6 } + XYPoint { x: 3.4; y: 2.3 } + XYPoint { x: 4.1; y: 3.1 } + } + } + //![1] +} diff --git a/examples/charts/qmlchart/qml/qmlchart/View4.qml b/examples/charts/qmlchart/qml/qmlchart/View4.qml new file mode 100644 index 00000000..5ba5dc15 --- /dev/null +++ b/examples/charts/qmlchart/qml/qmlchart/View4.qml @@ -0,0 +1,108 @@ +/**************************************************************************** +** +** Copyright (C) 2014 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 Enterprise Charts Add-on. +** +** $QT_BEGIN_LICENSE$ +** Licensees holding valid Qt Enterprise licenses may use this file in +** accordance with the Qt Enterprise 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 2.0 +import QtCharts 2.0 + +Rectangle { + anchors.fill: parent + + //![1] + ChartView { + title: "NHL All-Star Team Players" + anchors.fill: parent + antialiasing: true + + ValueAxis { + id: valueAxis + min: 2000 + max: 2011 + tickCount: 12 + labelFormat: "%.0f" + } + + AreaSeries { + name: "Russian" + color: "#FFD52B1E" + borderColor: "#FF0039A5" + borderWidth: 3 + axisX: valueAxis + upperSeries: LineSeries { + XYPoint { x: 2000; y: 1 } + XYPoint { x: 2001; y: 1 } + XYPoint { x: 2002; y: 1 } + XYPoint { x: 2003; y: 1 } + XYPoint { x: 2004; y: 1 } + XYPoint { x: 2005; y: 0 } + XYPoint { x: 2006; y: 1 } + XYPoint { x: 2007; y: 1 } + XYPoint { x: 2008; y: 4 } + XYPoint { x: 2009; y: 3 } + XYPoint { x: 2010; y: 2 } + XYPoint { x: 2011; y: 1 } + } + } + //![1] + + AreaSeries { + name: "Swedish" + color: "#AF005292" + borderColor: "#AFFDCA00" + borderWidth: 3 + axisX: valueAxis + upperSeries: LineSeries { + XYPoint { x: 2000; y: 1 } + XYPoint { x: 2001; y: 1 } + XYPoint { x: 2002; y: 3 } + XYPoint { x: 2003; y: 3 } + XYPoint { x: 2004; y: 2 } + XYPoint { x: 2005; y: 0 } + XYPoint { x: 2006; y: 2 } + XYPoint { x: 2007; y: 1 } + XYPoint { x: 2008; y: 2 } + XYPoint { x: 2009; y: 1 } + XYPoint { x: 2010; y: 3 } + XYPoint { x: 2011; y: 3 } + } + } + + AreaSeries { + name: "Finnish" + color: "#00357F" + borderColor: "#FEFEFE" + borderWidth: 3 + axisX: valueAxis + upperSeries: LineSeries { + XYPoint { x: 2000; y: 0 } + XYPoint { x: 2001; y: 0 } + XYPoint { x: 2002; y: 0 } + XYPoint { x: 2003; y: 0 } + XYPoint { x: 2004; y: 0 } + XYPoint { x: 2005; y: 0 } + XYPoint { x: 2006; y: 1 } + XYPoint { x: 2007; y: 0 } + XYPoint { x: 2008; y: 0 } + XYPoint { x: 2009; y: 0 } + XYPoint { x: 2010; y: 0 } + XYPoint { x: 2011; y: 1 } + } + } + } +} diff --git a/examples/charts/qmlchart/qml/qmlchart/View5.qml b/examples/charts/qmlchart/qml/qmlchart/View5.qml new file mode 100644 index 00000000..7cce1d77 --- /dev/null +++ b/examples/charts/qmlchart/qml/qmlchart/View5.qml @@ -0,0 +1,56 @@ +/**************************************************************************** +** +** Copyright (C) 2014 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 Enterprise Charts Add-on. +** +** $QT_BEGIN_LICENSE$ +** Licensees holding valid Qt Enterprise licenses may use this file in +** accordance with the Qt Enterprise 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 2.0 +import QtCharts 2.0 + +Rectangle { + anchors.fill: parent + + //![1] + ChartView { + title: "Scatters" + anchors.fill: parent + antialiasing: true + + ScatterSeries { + id: scatter1 + name: "Scatter1" + XYPoint { x: 1.5; y: 1.5 } + XYPoint { x: 1.5; y: 1.6 } + XYPoint { x: 1.57; y: 1.55 } + XYPoint { x: 1.8; y: 1.8 } + XYPoint { x: 1.9; y: 1.6 } + XYPoint { x: 2.1; y: 1.3 } + XYPoint { x: 2.5; y: 2.1 } + } + + ScatterSeries { + name: "Scatter2" + //![1] + XYPoint { x: 2.0; y: 2.0 } + XYPoint { x: 2.0; y: 2.1 } + XYPoint { x: 2.07; y: 2.05 } + XYPoint { x: 2.2; y: 2.9 } + XYPoint { x: 2.4; y: 2.7 } + XYPoint { x: 2.67; y: 2.65 } + } + } +} diff --git a/examples/charts/qmlchart/qml/qmlchart/View6.qml b/examples/charts/qmlchart/qml/qmlchart/View6.qml new file mode 100644 index 00000000..78d3a834 --- /dev/null +++ b/examples/charts/qmlchart/qml/qmlchart/View6.qml @@ -0,0 +1,43 @@ +/**************************************************************************** +** +** Copyright (C) 2014 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 Enterprise Charts Add-on. +** +** $QT_BEGIN_LICENSE$ +** Licensees holding valid Qt Enterprise licenses may use this file in +** accordance with the Qt Enterprise 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 2.0 +import QtCharts 2.0 + +Rectangle { + anchors.fill: parent + + //![1] + ChartView { + title: "Bar series" + anchors.fill: parent + legend.alignment: Qt.AlignBottom + antialiasing: true + + BarSeries { + id: mySeries + axisX: BarCategoryAxis { categories: ["2007", "2008", "2009", "2010", "2011", "2012" ] } + BarSet { label: "Bob"; values: [2, 2, 3, 4, 5, 6] } + BarSet { label: "Susan"; values: [5, 1, 2, 4, 1, 7] } + BarSet { label: "James"; values: [3, 5, 8, 13, 5, 8] } + } + } + //![1] +} diff --git a/examples/charts/qmlchart/qml/qmlchart/View7.qml b/examples/charts/qmlchart/qml/qmlchart/View7.qml new file mode 100644 index 00000000..4980e70b --- /dev/null +++ b/examples/charts/qmlchart/qml/qmlchart/View7.qml @@ -0,0 +1,43 @@ +/**************************************************************************** +** +** Copyright (C) 2014 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 Enterprise Charts Add-on. +** +** $QT_BEGIN_LICENSE$ +** Licensees holding valid Qt Enterprise licenses may use this file in +** accordance with the Qt Enterprise 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 2.0 +import QtCharts 2.0 + +Rectangle { + anchors.fill: parent + + //![1] + ChartView { + title: "Stacked Bar series" + anchors.fill: parent + legend.alignment: Qt.AlignBottom + antialiasing: true + + StackedBarSeries { + id: mySeries + axisX: BarCategoryAxis { categories: ["2007", "2008", "2009", "2010", "2011", "2012" ] } + BarSet { label: "Bob"; values: [2, 2, 3, 4, 5, 6] } + BarSet { label: "Susan"; values: [5, 1, 2, 4, 1, 7] } + BarSet { label: "James"; values: [3, 5, 8, 13, 5, 8] } + } + } + //![1] +} diff --git a/examples/charts/qmlchart/qml/qmlchart/View8.qml b/examples/charts/qmlchart/qml/qmlchart/View8.qml new file mode 100644 index 00000000..bba51cc9 --- /dev/null +++ b/examples/charts/qmlchart/qml/qmlchart/View8.qml @@ -0,0 +1,42 @@ +/**************************************************************************** +** +** Copyright (C) 2014 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 Enterprise Charts Add-on. +** +** $QT_BEGIN_LICENSE$ +** Licensees holding valid Qt Enterprise licenses may use this file in +** accordance with the Qt Enterprise 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 2.0 +import QtCharts 2.0 + +Rectangle { + anchors.fill: parent + + //![1] + ChartView { + title: "Percent Bar series" + anchors.fill: parent + legend.alignment: Qt.AlignBottom + antialiasing: true + + PercentBarSeries { + axisX: BarCategoryAxis { categories: ["2007", "2008", "2009", "2010", "2011", "2012" ] } + BarSet { label: "Bob"; values: [2, 2, 3, 4, 5, 6] } + BarSet { label: "Susan"; values: [5, 1, 2, 4, 1, 7] } + BarSet { label: "James"; values: [3, 5, 8, 13, 5, 8] } + } + } + //![1] +} diff --git a/examples/charts/qmlchart/qml/qmlchart/View9.qml b/examples/charts/qmlchart/qml/qmlchart/View9.qml new file mode 100644 index 00000000..fe0f0a55 --- /dev/null +++ b/examples/charts/qmlchart/qml/qmlchart/View9.qml @@ -0,0 +1,43 @@ +/**************************************************************************** +** +** Copyright (C) 2014 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 Enterprise Charts Add-on. +** +** $QT_BEGIN_LICENSE$ +** Licensees holding valid Qt Enterprise licenses may use this file in +** accordance with the Qt Enterprise 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 2.0 +import QtCharts 2.0 + +Rectangle { + anchors.fill: parent + + //![1] + ChartView { + title: "Horizontal Bar series" + anchors.fill: parent + legend.alignment: Qt.AlignBottom + antialiasing: true + + HorizontalBarSeries { + axisY: BarCategoryAxis { categories: ["2007", "2008", "2009", "2010", "2011", "2012" ] } + BarSet { label: "Bob"; values: [2, 2, 3, 4, 5, 6] } + BarSet { label: "Susan"; values: [5, 1, 2, 4, 1, 7] } + BarSet { label: "James"; values: [3, 5, 8, 13, 5, 8] } + } + } + //![1] +} + diff --git a/examples/charts/qmlchart/qml/qmlchart/main.qml b/examples/charts/qmlchart/qml/qmlchart/main.qml new file mode 100644 index 00000000..0a384636 --- /dev/null +++ b/examples/charts/qmlchart/qml/qmlchart/main.qml @@ -0,0 +1,91 @@ +/**************************************************************************** +** +** Copyright (C) 2014 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 Enterprise Charts Add-on. +** +** $QT_BEGIN_LICENSE$ +** Licensees holding valid Qt Enterprise licenses may use this file in +** accordance with the Qt Enterprise 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$ +** +****************************************************************************/ + +//![1] +import QtQuick 2.0 +//![1] + +Rectangle { + width: 600 + height: 400 + property bool sourceLoaded: false + + ListView { + id: root + focus: true + anchors.fill: parent + snapMode: ListView.SnapOneItem + highlightRangeMode: ListView.StrictlyEnforceRange + highlightMoveDuration: 250 + orientation: ListView.Horizontal + boundsBehavior: Flickable.StopAtBounds + + onCurrentIndexChanged: { + if (infoText.opacity > 0.0) { + if (sourceLoaded) + infoText.opacity = 0.0; + else if (currentIndex != 0) + currentIndex = 0; + } + } + + model: ListModel { + ListElement {component: "View1.qml"} + ListElement {component: "View2.qml"} + ListElement {component: "View3.qml"} + ListElement {component: "View4.qml"} + ListElement {component: "View5.qml"} + ListElement {component: "View6.qml"} + ListElement {component: "View7.qml"} + ListElement {component: "View8.qml"} + ListElement {component: "View9.qml"} + ListElement {component: "View10.qml"} + ListElement {component: "View11.qml"} + ListElement {component: "View12.qml"} + } + + delegate: Loader { + width: root.width + height: root.height + + source: component + asynchronous: true + + onLoaded: sourceLoaded = true + } + } + + Rectangle { + id: infoText + anchors.centerIn: parent + width: parent.width + height: 40 + color: "black" + Text { + color: "white" + anchors.centerIn: parent + text: "You can navigate between views using swipe or arrow keys" + } + + Behavior on opacity { + NumberAnimation { duration: 400 } + } + } +} diff --git a/examples/charts/qmlchart/qmlchart.pro b/examples/charts/qmlchart/qmlchart.pro new file mode 100644 index 00000000..82426424 --- /dev/null +++ b/examples/charts/qmlchart/qmlchart.pro @@ -0,0 +1,7 @@ +!include( ../examples.pri ) { + error( "Couldn't find the examples.pri file!" ) +} + +RESOURCES += resources.qrc +SOURCES += main.cpp +OTHER_FILES += qml/qmlchart/* diff --git a/examples/charts/qmlchart/resources.qrc b/examples/charts/qmlchart/resources.qrc new file mode 100644 index 00000000..7b14dace --- /dev/null +++ b/examples/charts/qmlchart/resources.qrc @@ -0,0 +1,17 @@ +<RCC> + <qresource prefix="/"> + <file>qml/qmlchart/main.qml</file> + <file>qml/qmlchart/View1.qml</file> + <file>qml/qmlchart/View2.qml</file> + <file>qml/qmlchart/View3.qml</file> + <file>qml/qmlchart/View4.qml</file> + <file>qml/qmlchart/View5.qml</file> + <file>qml/qmlchart/View6.qml</file> + <file>qml/qmlchart/View7.qml</file> + <file>qml/qmlchart/View8.qml</file> + <file>qml/qmlchart/View9.qml</file> + <file>qml/qmlchart/View10.qml</file> + <file>qml/qmlchart/View11.qml</file> + <file>qml/qmlchart/View12.qml</file> + </qresource> +</RCC> diff --git a/examples/charts/qmlcustomizations/main.cpp b/examples/charts/qmlcustomizations/main.cpp new file mode 100644 index 00000000..e36fd058 --- /dev/null +++ b/examples/charts/qmlcustomizations/main.cpp @@ -0,0 +1,49 @@ +/**************************************************************************** +** +** Copyright (C) 2014 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 Enterprise Charts Add-on. +** +** $QT_BEGIN_LICENSE$ +** Licensees holding valid Qt Enterprise licenses may use this file in +** accordance with the Qt Enterprise 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 <QtWidgets/QApplication> +#include <QtQuick/QQuickView> +#include <QtCore/QDir> +#include <QtQml/QQmlEngine> + +int main(int argc, char *argv[]) +{ + // Qt Charts uses Qt Graphics View Framework for drawing, therefore QApplication must be used. + QApplication app(argc, argv); + + QQuickView viewer; + // The following are needed to make examples run without having to install the module + // in desktop environments. +#ifdef Q_OS_WIN + QString extraImportPath(QStringLiteral("%1/../../../../%2")); +#else + QString extraImportPath(QStringLiteral("%1/../../../%2")); +#endif + viewer.engine()->addImportPath(extraImportPath.arg(QGuiApplication::applicationDirPath(), + QString::fromLatin1("qml"))); + QObject::connect(viewer.engine(), &QQmlEngine::quit, &viewer, &QWindow::close); + + viewer.setTitle(QStringLiteral("QML Customizations")); + viewer.setSource(QUrl("qrc:/qml/qmlcustomizations/main.qml")); + viewer.setResizeMode(QQuickView::SizeRootObjectToView); + viewer.show(); + + return app.exec(); +} diff --git a/examples/charts/qmlcustomizations/qml/qmlcustomizations/main.qml b/examples/charts/qmlcustomizations/qml/qmlcustomizations/main.qml new file mode 100644 index 00000000..8000caf7 --- /dev/null +++ b/examples/charts/qmlcustomizations/qml/qmlcustomizations/main.qml @@ -0,0 +1,102 @@ +/**************************************************************************** +** +** Copyright (C) 2014 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 Enterprise Charts Add-on. +** +** $QT_BEGIN_LICENSE$ +** Licensees holding valid Qt Enterprise licenses may use this file in +** accordance with the Qt Enterprise 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 2.0 +import QtCharts 2.0 + +Rectangle { + width: 400 + height: 300 + property int __activeIndex: 1 + property real __intervalCoefficient: 0 + + //![1] + ChartView { + id: chartView + anchors.fill: parent + title: "Wheel of fortune" + legend.visible: false + antialiasing: true + + PieSeries { + id: wheelOfFortune + horizontalPosition: 0.3 + } + + SplineSeries { + id: splineSeries + } + + ScatterSeries { + id: scatterSeries + } + } + //![1] + + //![2] + Component.onCompleted: { + __intervalCoefficient = Math.random() + 0.1; + + for (var i = 0; i < 20; i++) + wheelOfFortune.append("", 1); + + var interval = 1; + for (var j = 0; interval < 800; j++) { + interval = __intervalCoefficient * j * j; + splineSeries.append(j, interval); + } + chartView.axisX(scatterSeries).max = j; + chartView.axisY(scatterSeries).max = 1000; + } + //![2] + + Timer { + triggeredOnStart: true + running: true + repeat: true + interval: 100 + onTriggered: { + var index = __activeIndex % wheelOfFortune.count; + if (interval < 700) { + //![3] + wheelOfFortune.at(index).exploded = false; + __activeIndex++; + index = __activeIndex % wheelOfFortune.count; + wheelOfFortune.at(index).exploded = true; + //![3] + interval = splineSeries.at(__activeIndex).y; + //![4] + scatterSeries.clear(); + scatterSeries.append(__activeIndex, interval); + scatterSeries.color = Qt.tint(scatterSeries.color, "#05FF0000"); + scatterSeries.markerSize += 0.5; + //![4] + } else { + //![5] + // Switch the colors of the slice and the border + wheelOfFortune.at(index).borderWidth = 2; + var borderColor = wheelOfFortune.at(index).borderColor; + wheelOfFortune.at(index).borderColor = wheelOfFortune.at(index).color; + wheelOfFortune.at(index).color = borderColor; + //![5] + } + } + } +} diff --git a/examples/charts/qmlcustomizations/qmlcustomizations.pro b/examples/charts/qmlcustomizations/qmlcustomizations.pro new file mode 100644 index 00000000..ae2d4e5b --- /dev/null +++ b/examples/charts/qmlcustomizations/qmlcustomizations.pro @@ -0,0 +1,7 @@ +!include( ../examples.pri ) { + error( "Couldn't find the examples.pri file!" ) +} + +RESOURCES += resources.qrc +SOURCES += main.cpp +OTHER_FILES += qml/qmlcustomizations/* diff --git a/examples/charts/qmlcustomizations/resources.qrc b/examples/charts/qmlcustomizations/resources.qrc new file mode 100644 index 00000000..35dd1b54 --- /dev/null +++ b/examples/charts/qmlcustomizations/resources.qrc @@ -0,0 +1,5 @@ +<RCC> + <qresource prefix="/"> + <file>qml/qmlcustomizations/main.qml</file> + </qresource> +</RCC> diff --git a/examples/charts/qmlcustomlegend/main.cpp b/examples/charts/qmlcustomlegend/main.cpp new file mode 100644 index 00000000..82cda036 --- /dev/null +++ b/examples/charts/qmlcustomlegend/main.cpp @@ -0,0 +1,49 @@ +/**************************************************************************** +** +** Copyright (C) 2014 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 Enterprise Charts Add-on. +** +** $QT_BEGIN_LICENSE$ +** Licensees holding valid Qt Enterprise licenses may use this file in +** accordance with the Qt Enterprise 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 <QtWidgets/QApplication> +#include <QtQuick/QQuickView> +#include <QtCore/QDir> +#include <QtQml/QQmlEngine> + +int main(int argc, char *argv[]) +{ + // Qt Charts uses Qt Graphics View Framework for drawing, therefore QApplication must be used. + QApplication app(argc, argv); + + QQuickView viewer; + // The following are needed to make examples run without having to install the module + // in desktop environments. +#ifdef Q_OS_WIN + QString extraImportPath(QStringLiteral("%1/../../../../%2")); +#else + QString extraImportPath(QStringLiteral("%1/../../../%2")); +#endif + viewer.engine()->addImportPath(extraImportPath.arg(QGuiApplication::applicationDirPath(), + QString::fromLatin1("qml"))); + QObject::connect(viewer.engine(), &QQmlEngine::quit, &viewer, &QWindow::close); + + viewer.setTitle(QStringLiteral("QML Custom Legend")); + viewer.setSource(QUrl("qrc:/qml/qmlcustomlegend/main.qml")); + viewer.setResizeMode(QQuickView::SizeRootObjectToView); + viewer.show(); + + return app.exec(); +} diff --git a/examples/charts/qmlcustomlegend/qml/qmlcustomlegend/AnimatedAreaSeries.qml b/examples/charts/qmlcustomlegend/qml/qmlcustomlegend/AnimatedAreaSeries.qml new file mode 100644 index 00000000..0af6b5c3 --- /dev/null +++ b/examples/charts/qmlcustomlegend/qml/qmlcustomlegend/AnimatedAreaSeries.qml @@ -0,0 +1,30 @@ +/**************************************************************************** +** +** Copyright (C) 2014 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 Enterprise Charts Add-on. +** +** $QT_BEGIN_LICENSE$ +** Licensees holding valid Qt Enterprise licenses may use this file in +** accordance with the Qt Enterprise 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 2.0 +import QtCharts 2.0 + +AreaSeries { + id: series + + Behavior on opacity { + NumberAnimation { duration: 250 } + } +} diff --git a/examples/charts/qmlcustomlegend/qml/qmlcustomlegend/ChartViewHighlighted.qml b/examples/charts/qmlcustomlegend/qml/qmlcustomlegend/ChartViewHighlighted.qml new file mode 100644 index 00000000..7ca033b2 --- /dev/null +++ b/examples/charts/qmlcustomlegend/qml/qmlcustomlegend/ChartViewHighlighted.qml @@ -0,0 +1,77 @@ +/**************************************************************************** +** +** Copyright (C) 2014 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 Enterprise Charts Add-on. +** +** $QT_BEGIN_LICENSE$ +** Licensees holding valid Qt Enterprise licenses may use this file in +** accordance with the Qt Enterprise 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 2.0 +import QtCharts 2.0 + +//![1] +ChartView { + id: chartViewHighlighted + title: "" + property variant selectedSeries + signal clicked + legend.visible: false + margins.top: 10 + margins.bottom: 0 + antialiasing: true + + LineSeries { + id: lineSeries + + axisX: ValueAxis { + min: 2006 + max: 2012 + labelFormat: "%.0f" + tickCount: 7 + } + axisY: ValueAxis { + id: axisY + titleText: "EUR" + min: 0 + max: 40000 + niceNumbersEnabled: true + labelFormat: "%.0f" + tickCount: 5 + } + } +//![1] + + MouseArea { + anchors.fill: parent + onClicked: { + chartViewHighlighted.clicked(); + } + } + + onSelectedSeriesChanged: { + lineSeries.clear(); + lineSeries.color = selectedSeries.color; + var maxVal = 0.0; + for (var i = 0; i < selectedSeries.upperSeries.count; i++ ) { + var y = selectedSeries.upperSeries.at(i).y - selectedSeries.lowerSeries.at(i).y; + lineSeries.append(selectedSeries.upperSeries.at(i).x, y); + if (maxVal < y) + maxVal = y; + } + chartViewHighlighted.title = selectedSeries.name; + axisY.max = maxVal; + } +} + diff --git a/examples/charts/qmlcustomlegend/qml/qmlcustomlegend/ChartViewSelector.qml b/examples/charts/qmlcustomlegend/qml/qmlcustomlegend/ChartViewSelector.qml new file mode 100644 index 00000000..86714a01 --- /dev/null +++ b/examples/charts/qmlcustomlegend/qml/qmlcustomlegend/ChartViewSelector.qml @@ -0,0 +1,100 @@ +/**************************************************************************** +** +** Copyright (C) 2014 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 Enterprise Charts Add-on. +** +** $QT_BEGIN_LICENSE$ +** Licensees holding valid Qt Enterprise licenses may use this file in +** accordance with the Qt Enterprise 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 2.0 +import QtCharts 2.0 + +Rectangle { + id: chartViewSelector + width: parent.width + height: parent.height + signal seriesAdded(string seriesName, color seriesColor) + + function highlightSeries(seriesName) { + if (seriesName == "") { + if (state != "") + state = ""; + + for (var i = 0; i < chartViewStacked.count; i++) + chartViewStacked.series(i).opacity = 1.0; + } else { + var targetOpacity = 0.1; + for (var j = 0; j < chartViewStacked.count; j++) { + if (chartViewStacked.series(j).name != seriesName) + chartViewStacked.series(j).opacity = 0.25; + else if (state == "highlight") + chartViewSelected.selectedSeries = chartViewStacked.series(j); + } + } + } + + function selectSeries(seriesName) { + for (var i = 0; i < chartViewStacked.count; i++) { + if (chartViewStacked.series(i).name == seriesName) { + chartViewSelected.selectedSeries = chartViewStacked.series(i); + if (chartViewSelector.state == "") + chartViewSelector.state = "highlighted"; + else + chartViewSelector.state = ""; + } + } + } + + ChartViewStacked { + id: chartViewStacked + anchors.left: parent.left + anchors.leftMargin: 0 + width: parent.width + height: parent.height + onSeriesAdded: chartViewSelector.seriesAdded(series.name, series.color); + } + + ChartViewHighlighted { + id: chartViewSelected + anchors.left: chartViewStacked.right + width: parent.width + height: parent.height + + opacity: 0.0 + onClicked: { + chartViewSelector.state = ""; + } + } + + states: State { + name: "highlighted" + PropertyChanges { + target: chartViewSelected + opacity: 1.0 + } + PropertyChanges { + target: chartViewStacked + anchors.leftMargin: -chartViewStacked.width + opacity: 0.0 + } + } + + transitions: Transition { + PropertyAnimation { + properties: "width, height, opacity, anchors.leftMargin" + duration: 400 + } + } +} diff --git a/examples/charts/qmlcustomlegend/qml/qmlcustomlegend/ChartViewStacked.qml b/examples/charts/qmlcustomlegend/qml/qmlcustomlegend/ChartViewStacked.qml new file mode 100644 index 00000000..ade88c04 --- /dev/null +++ b/examples/charts/qmlcustomlegend/qml/qmlcustomlegend/ChartViewStacked.qml @@ -0,0 +1,117 @@ +/**************************************************************************** +** +** Copyright (C) 2014 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 Enterprise Charts Add-on. +** +** $QT_BEGIN_LICENSE$ +** Licensees holding valid Qt Enterprise licenses may use this file in +** accordance with the Qt Enterprise 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 2.0 +import QtCharts 2.0 + +ChartView { + id: chartView + title: "Government Taxes" + legend.visible: false + signal entered(string seriesName) + signal exited(string seriesName) + margins.top: 10 + margins.bottom: 0 + antialiasing: true + + ValueAxis { + id: axisX + min: 2006 + max: 2012 + tickCount: 7 + labelFormat: "%.0f" + } + + ValueAxis { + id: axisY + titleText: "EUR" + min: 0 + max: 90000 + tickCount: 10 + labelFormat: "%.0f" + } + + AnimatedAreaSeries { + id: stateSeries + name: "state" + axisX: axisX + axisY: axisY + borderWidth: 0 + upperSeries: LineSeries { + id: stateUpper + XYPoint { x: 2006; y: 33119 } + XYPoint { x: 2007; y: 37941 } + XYPoint { x: 2008; y: 40122 } + XYPoint { x: 2009; y: 38991 } + XYPoint { x: 2010; y: 34055 } + XYPoint { x: 2011; y: 34555 } + XYPoint { x: 2012; y: 38991 } + } + lowerSeries: LineSeries { + XYPoint { x: 2006; y: 0 } + XYPoint { x: 2007; y: 0 } + XYPoint { x: 2008; y: 0 } + XYPoint { x: 2009; y: 0 } + XYPoint { x: 2010; y: 0 } + XYPoint { x: 2011; y: 0 } + XYPoint { x: 2012; y: 0 } + } + } + + //![1] + AnimatedAreaSeries { + id: municipalSeries + name: "municipal" + axisX: axisX + axisY: axisY + borderWidth: 0 + upperSeries: LineSeries { + id: municipalUpper + XYPoint { x: 2006; y: 33119 + 13443 } + XYPoint { x: 2007; y: 37941 + 15311 } + XYPoint { x: 2008; y: 40122 + 16552 } + XYPoint { x: 2009; y: 38991 + 17904 } + XYPoint { x: 2010; y: 34055 + 17599 } + XYPoint { x: 2011; y: 34555 + 19002 } + XYPoint { x: 2012; y: 38991 + 19177 } + } + lowerSeries: stateUpper + } + //![1] + + AnimatedAreaSeries { + id: socialSeries + name: "social sec." + axisX: axisX + axisY: axisY + borderWidth: 0 + upperSeries: LineSeries { + id: socialUpper + XYPoint { x: 2006; y: 33119 + 13443 + 18855 } + XYPoint { x: 2007; y: 37941 + 15311 + 20238 } + XYPoint { x: 2008; y: 40122 + 16552 + 21347 } + XYPoint { x: 2009; y: 38991 + 17904 + 22376 } + XYPoint { x: 2010; y: 34055 + 17599 + 22076 } + XYPoint { x: 2011; y: 34555 + 19002 + 22631 } + XYPoint { x: 2012; y: 38991 + 19177 + 23686 } + } + lowerSeries: municipalUpper + } +} diff --git a/examples/charts/qmlcustomlegend/qml/qmlcustomlegend/CustomLegend.qml b/examples/charts/qmlcustomlegend/qml/qmlcustomlegend/CustomLegend.qml new file mode 100644 index 00000000..d146f83c --- /dev/null +++ b/examples/charts/qmlcustomlegend/qml/qmlcustomlegend/CustomLegend.qml @@ -0,0 +1,136 @@ +/**************************************************************************** +** +** Copyright (C) 2014 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 Enterprise Charts Add-on. +** +** $QT_BEGIN_LICENSE$ +** Licensees holding valid Qt Enterprise licenses may use this file in +** accordance with the Qt Enterprise 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 2.0 +import QtCharts 2.0 + +Rectangle { + id: legend + color: "lightgray" + + property int seriesCount: 0 + property variant seriesNames: [] + property variant seriesColors: [] + signal entered(string seriesName) + signal exited(string seriesName) + signal selected(string seriesName) + + function addSeries(seriesName, color) { + var names = seriesNames; + names[seriesCount] = seriesName; + seriesNames = names; + + var colors = seriesColors; + colors[seriesCount] = color; + seriesColors = colors; + + seriesCount++; + } + + Gradient { + id: buttonGradient + GradientStop { position: 0.0; color: "#F0F0F0" } + GradientStop { position: 1.0; color: "#A0A0A0" } + } + + Gradient { + id: buttonGradientHovered + GradientStop { position: 0.0; color: "#FFFFFF" } + GradientStop { position: 1.0; color: "#B0B0B0" } + } + + //![2] + Component { + id: legendDelegate + Rectangle { + id: rect + //![2] + property string name: seriesNames[index] + property color markerColor: seriesColors[index] + gradient: buttonGradient + border.color: "#A0A0A0" + border.width: 1 + radius: 4 + + implicitWidth: label.implicitWidth + marker.implicitWidth + 30 + implicitHeight: label.implicitHeight + marker.implicitHeight + 10 + + Row { + id: row + spacing: 5 + anchors.verticalCenter: parent.verticalCenter + anchors.left: parent.left + anchors.leftMargin: 5 + Rectangle { + id: marker + anchors.verticalCenter: parent.verticalCenter + color: markerColor + opacity: 0.3 + radius: 4 + width: 12 + height: 10 + } + Text { + id: label + anchors.verticalCenter: parent.verticalCenter + anchors.verticalCenterOffset: -1 + text: name + } + } + + //![3] + MouseArea { + id: mouseArea + anchors.fill: parent + hoverEnabled: true + onEntered: { + rect.gradient = buttonGradientHovered; + legend.entered(label.text); + } + onExited: { + rect.gradient = buttonGradient; + legend.exited(label.text); + marker.opacity = 0.3; + marker.height = 10; + } + onClicked: { + legend.selected(label.text); + marker.opacity = 1.0; + marker.height = 12; + } + } + //![3] + } + } + + //![1] + Row { + id: legendRow + anchors.centerIn: parent + spacing: 10 + + Repeater { + id: legendRepeater + model: seriesCount + delegate: legendDelegate + } + } + //![1] +} diff --git a/examples/charts/qmlcustomlegend/qml/qmlcustomlegend/main.qml b/examples/charts/qmlcustomlegend/qml/qmlcustomlegend/main.qml new file mode 100644 index 00000000..815d5331 --- /dev/null +++ b/examples/charts/qmlcustomlegend/qml/qmlcustomlegend/main.qml @@ -0,0 +1,66 @@ +/**************************************************************************** +** +** Copyright (C) 2014 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 Enterprise Charts Add-on. +** +** $QT_BEGIN_LICENSE$ +** Licensees holding valid Qt Enterprise licenses may use this file in +** accordance with the Qt Enterprise 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 2.0 +import QtCharts 2.0 + +Rectangle { + id: main + width: 400 + height: 320 + + Column { + id: column + anchors.fill: parent + anchors.bottomMargin: 10 + spacing: 0 + + ChartViewSelector { + id: chartViewSelector + width: parent.width + height: parent.height - customLegend.height - anchors.bottomMargin + onSeriesAdded: customLegend.addSeries(seriesName, seriesColor); + } + + CustomLegend { + id: customLegend + width: parent.width + height: 50 + anchors.horizontalCenter: parent.horizontalCenter + onEntered: chartViewSelector.highlightSeries(seriesName); + onExited: chartViewSelector.highlightSeries(""); + onSelected: chartViewSelector.selectSeries(seriesName); + } + } + + states: State { + name: "highlighted" + PropertyChanges { + target: chartViewHighlighted + width: column.width + height: (column.height - column.anchors.margins * 2 - customLegend.height) + } + PropertyChanges { + target: chartViewStacked + width: 1 + height: 1 + } + } +} diff --git a/examples/charts/qmlcustomlegend/qmlcustomlegend.pro b/examples/charts/qmlcustomlegend/qmlcustomlegend.pro new file mode 100644 index 00000000..d42afded --- /dev/null +++ b/examples/charts/qmlcustomlegend/qmlcustomlegend.pro @@ -0,0 +1,7 @@ +!include( ../examples.pri ) { + error( "Couldn't find the examples.pri file!" ) +} + +RESOURCES += resources.qrc +SOURCES += main.cpp +OTHER_FILES += qml/qmlcustomlegend/* diff --git a/examples/charts/qmlcustomlegend/resources.qrc b/examples/charts/qmlcustomlegend/resources.qrc new file mode 100644 index 00000000..bd49690b --- /dev/null +++ b/examples/charts/qmlcustomlegend/resources.qrc @@ -0,0 +1,10 @@ +<RCC> + <qresource prefix="/"> + <file>qml/qmlcustomlegend/main.qml</file> + <file>qml/qmlcustomlegend/CustomLegend.qml</file> + <file>qml/qmlcustomlegend/ChartViewStacked.qml</file> + <file>qml/qmlcustomlegend/ChartViewHighlighted.qml</file> + <file>qml/qmlcustomlegend/ChartViewSelector.qml</file> + <file>qml/qmlcustomlegend/AnimatedAreaSeries.qml</file> + </qresource> +</RCC> diff --git a/examples/charts/qmlf1legends/main.cpp b/examples/charts/qmlf1legends/main.cpp new file mode 100644 index 00000000..df79b769 --- /dev/null +++ b/examples/charts/qmlf1legends/main.cpp @@ -0,0 +1,49 @@ +/**************************************************************************** +** +** Copyright (C) 2014 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 Enterprise Charts Add-on. +** +** $QT_BEGIN_LICENSE$ +** Licensees holding valid Qt Enterprise licenses may use this file in +** accordance with the Qt Enterprise 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 <QtWidgets/QApplication> +#include <QtQuick/QQuickView> +#include <QtCore/QDir> +#include <QtQml/QQmlEngine> + +int main(int argc, char *argv[]) +{ + // Qt Charts uses Qt Graphics View Framework for drawing, therefore QApplication must be used. + QApplication app(argc, argv); + + QQuickView viewer; + // The following are needed to make examples run without having to install the module + // in desktop environments. +#ifdef Q_OS_WIN + QString extraImportPath(QStringLiteral("%1/../../../../%2")); +#else + QString extraImportPath(QStringLiteral("%1/../../../%2")); +#endif + viewer.engine()->addImportPath(extraImportPath.arg(QGuiApplication::applicationDirPath(), + QString::fromLatin1("qml"))); + QObject::connect(viewer.engine(), &QQmlEngine::quit, &viewer, &QWindow::close); + + viewer.setTitle(QStringLiteral("QML F1 Legends")); + viewer.setSource(QUrl("qrc:/qml/qmlf1legends/main.qml")); + viewer.setResizeMode(QQuickView::SizeRootObjectToView); + viewer.show(); + + return app.exec(); +} diff --git a/examples/charts/qmlf1legends/qml/qmlf1legends/SpeedsXml.qml b/examples/charts/qmlf1legends/qml/qmlf1legends/SpeedsXml.qml new file mode 100644 index 00000000..00d45a17 --- /dev/null +++ b/examples/charts/qmlf1legends/qml/qmlf1legends/SpeedsXml.qml @@ -0,0 +1,95 @@ +/**************************************************************************** +** +** Copyright (C) 2014 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 Enterprise Charts Add-on. +** +** $QT_BEGIN_LICENSE$ +** Licensees holding valid Qt Enterprise licenses may use this file in +** accordance with the Qt Enterprise 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.XmlListModel 2.0 + +//![1] +XmlListModel { + // Hard-coded test data + xml: "<results><row><speedTrap>0</speedTrap><driver>Fittipaldi</driver><speed>104.12</speed></row>" + +"<row><speedTrap>0</speedTrap><driver>Stewart</driver><speed>106.12</speed></row>" + +"<row><speedTrap>0</speedTrap><driver>Hunt</driver><speed>106.12</speed></row>" +//![1] + +"<row><speedTrap>1</speedTrap><driver>Fittipaldi</driver><speed>115.12</speed></row>" + +"<row><speedTrap>1</speedTrap><driver>Stewart</driver><speed>114.12</speed></row>" + +"<row><speedTrap>1</speedTrap><driver>Hunt</driver><speed>115.12</speed></row>" + +"<row><speedTrap>2</speedTrap><driver>Hunt</driver><speed>165.23</speed></row>" + +"<row><speedTrap>2</speedTrap><driver>Fittipaldi</driver><speed>175.23</speed></row>" + +"<row><speedTrap>2</speedTrap><driver>Stewart</driver><speed>168.23</speed></row>" + +"<row><speedTrap>3</speedTrap><driver>Hunt</driver><speed>104.87</speed></row>" + +"<row><speedTrap>3</speedTrap><driver>Fittipaldi</driver><speed>104.43</speed></row>" + +"<row><speedTrap>3</speedTrap><driver>Stewart</driver><speed>94.83</speed></row>" + +"<row><speedTrap>4</speedTrap><driver>Hunt</driver><speed>107.87</speed></row>" + +"<row><speedTrap>4</speedTrap><driver>Fittipaldi</driver><speed>111.84</speed></row>" + +"<row><speedTrap>4</speedTrap><driver>Stewart</driver><speed>106.84</speed></row>" + +"<row><speedTrap>5</speedTrap><driver>Hunt</driver><speed>94.87</speed></row>" + +"<row><speedTrap>5</speedTrap><driver>Stewart</driver><speed>92.37</speed></row>" + +"<row><speedTrap>5</speedTrap><driver>Fittipaldi</driver><speed>99.37</speed></row>" + +"<row><speedTrap>6</speedTrap><driver>Hunt</driver><speed>52.87</speed></row>" + +"<row><speedTrap>6</speedTrap><driver>Fittipaldi</driver><speed>42.87</speed></row>" + +"<row><speedTrap>6</speedTrap><driver>Stewart</driver><speed>55.87</speed></row>" + +"<row><speedTrap>7</speedTrap><driver>Hunt</driver><speed>77.87</speed></row>" + +"<row><speedTrap>7</speedTrap><driver>Fittipaldi</driver><speed>72.87</speed></row>" + +"<row><speedTrap>7</speedTrap><driver>Stewart</driver><speed>87.87</speed></row>" + +"<row><speedTrap>8</speedTrap><driver>Hunt</driver><speed>94.17</speed></row>" + +"<row><speedTrap>8</speedTrap><driver>Fittipaldi</driver><speed>98.17</speed></row>" + +"<row><speedTrap>8</speedTrap><driver>Stewart</driver><speed>84.17</speed></row>" + +"<row><speedTrap>9</speedTrap><driver>Hunt</driver><speed>91.87</speed></row>" + +"<row><speedTrap>9</speedTrap><driver>Fittipaldi</driver><speed>71.87</speed></row>" + +"<row><speedTrap>9</speedTrap><driver>Stewart</driver><speed>81.87</speed></row>" + +"<row><speedTrap>10</speedTrap><driver>Hunt</driver><speed>104.87</speed></row>" + +"<row><speedTrap>10</speedTrap><driver>Fittipaldi</driver><speed>115.87</speed></row>" + +"<row><speedTrap>10</speedTrap><driver>Stewart</driver><speed>119.87</speed></row>" + +"<row><speedTrap>11</speedTrap><driver>Hunt</driver><speed>162.87</speed></row>" + +"<row><speedTrap>11</speedTrap><driver>Fittipaldi</driver><speed>155.84</speed></row>" + +"<row><speedTrap>11</speedTrap><driver>Stewart</driver><speed>152.84</speed></row>" + +"<row><speedTrap>12</speedTrap><driver>Hunt</driver><speed>181.87</speed></row>" + +"<row><speedTrap>12</speedTrap><driver>Fittipaldi</driver><speed>161.85</speed></row>" + +"<row><speedTrap>12</speedTrap><driver>Stewart</driver><speed>167.85</speed></row>" + +"<row><speedTrap>13</speedTrap><driver>Hunt</driver><speed>155.87</speed></row>" + +"<row><speedTrap>13</speedTrap><driver>Fittipaldi</driver><speed>154.87</speed></row>" + +"<row><speedTrap>13</speedTrap><driver>Stewart</driver><speed>164.87</speed></row>" + +"<row><speedTrap>14</speedTrap><driver>Hunt</driver><speed>197.57</speed></row>" + +"<row><speedTrap>14</speedTrap><driver>Fittipaldi</driver><speed>187.54</speed></row>" + +"<row><speedTrap>14</speedTrap><driver>Stewart</driver><speed>180.54</speed></row>" + +"<row><speedTrap>15</speedTrap><driver>Fittipaldi</driver><speed>216.87</speed></row>" + +"<row><speedTrap>15</speedTrap><driver>Hunt</driver><speed>207.87</speed></row>" + +"<row><speedTrap>15</speedTrap><driver>Stewart</driver><speed>197.87</speed></row>" + +"<row><speedTrap>16</speedTrap><driver>Hunt</driver><speed>82.87</speed></row>" + +"<row><speedTrap>16</speedTrap><driver>Fittipaldi</driver><speed>79.37</speed></row>" + +"<row><speedTrap>16</speedTrap><driver>Stewart</driver><speed>85.37</speed></row>" + +"<row><speedTrap>17</speedTrap><driver>Hunt</driver><speed>153.87</speed></row>" + +"<row><speedTrap>17</speedTrap><driver>Fittipaldi</driver><speed>143.87</speed></row>" + +"<row><speedTrap>17</speedTrap><driver>Stewart</driver><speed>133.87</speed></row>" + +"<row><speedTrap>18</speedTrap><driver>Hunt</driver><speed>89.87</speed></row>" + +"<row><speedTrap>18</speedTrap><driver>Fittipaldi</driver><speed>95.85</speed></row>" + +"<row><speedTrap>18</speedTrap><driver>Stewart</driver><speed>98.85</speed></row>" + +"<row><speedTrap>19</speedTrap><driver>Hunt</driver><speed>169.87</speed></row>" + +"<row><speedTrap>19</speedTrap><driver>Stewart</driver><speed>167.87</speed></row>" + +"<row><speedTrap>19</speedTrap><driver>Fittipaldi</driver><speed>154.87</speed></row>" + +"</results>" +//![2] + query: "/results/row" + + XmlRole { name: "speedTrap"; query: "speedTrap/string()" } + XmlRole { name: "driver"; query: "driver/string()" } + XmlRole { name: "speed"; query: "speed/string()" } +} +//![2] diff --git a/examples/charts/qmlf1legends/qml/qmlf1legends/main.qml b/examples/charts/qmlf1legends/qml/qmlf1legends/main.qml new file mode 100644 index 00000000..9aaec276 --- /dev/null +++ b/examples/charts/qmlf1legends/qml/qmlf1legends/main.qml @@ -0,0 +1,95 @@ +/**************************************************************************** +** +** Copyright (C) 2014 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 Enterprise Charts Add-on. +** +** $QT_BEGIN_LICENSE$ +** Licensees holding valid Qt Enterprise licenses may use this file in +** accordance with the Qt Enterprise 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 2.0 +import QtCharts 2.0 +import QtQuick.XmlListModel 2.0 + +Rectangle { + width: 400 + height: 300 + property int currentIndex: -1 + + //![1] + ChartView { + id: chartView + title: "Driver Speeds, lap 1" + anchors.fill: parent + legend.alignment: Qt.AlignTop + animationOptions: ChartView.SeriesAnimations + antialiasing: true + } + //![1] + + //![2] + // An example XmlListModel containing F1 legend drivers' speeds at speed traps + SpeedsXml { + id: speedsXml + onStatusChanged: { + if (status == XmlListModel.Ready) { + timer.start(); + } + } + } + //![2] + + //![3] + // A timer to mimic refreshing the data dynamically + Timer { + id: timer + interval: 700 + repeat: true + triggeredOnStart: true + running: false + onTriggered: { + currentIndex++; + if (currentIndex < speedsXml.count) { + // Check if there is a series for the data already (we are using driver name to identify series) + var lineSeries = chartView.series(speedsXml.get(currentIndex).driver); + if (!lineSeries) { + lineSeries = chartView.createSeries(ChartView.SeriesTypeLine, speedsXml.get(currentIndex).driver); + chartView.axisY().min = 0; + chartView.axisY().max = 250; + chartView.axisY().tickCount = 6; + chartView.axisY().titleText = "speed (kph)"; + chartView.axisX().titleText = "speed trap"; + chartView.axisX().labelFormat = "%.0f"; + } + lineSeries.append(speedsXml.get(currentIndex).speedTrap, speedsXml.get(currentIndex).speed); + + if (speedsXml.get(currentIndex).speedTrap > 3) { + chartView.axisX().max = Number(speedsXml.get(currentIndex).speedTrap) + 1; + chartView.axisX().min = chartView.axisX().max - 5; + } else { + chartView.axisX().max = 5; + chartView.axisX().min = 0; + } + chartView.axisX().tickCount = chartView.axisX().max - chartView.axisX().min + 1; + } else { + // No more data, change x-axis range to show all the data + timer.stop(); + chartView.animationOptions = ChartView.AllAnimations; + chartView.axisX().min = 0; + chartView.axisX().max = speedsXml.get(currentIndex - 1).speedTrap; + } + } + } + //![3] +} diff --git a/examples/charts/qmlf1legends/qmlf1legends.pro b/examples/charts/qmlf1legends/qmlf1legends.pro new file mode 100644 index 00000000..fc8c04f4 --- /dev/null +++ b/examples/charts/qmlf1legends/qmlf1legends.pro @@ -0,0 +1,7 @@ +!include( ../examples.pri ) { + error( "Couldn't find the examples.pri file!" ) +} + +RESOURCES += resources.qrc +SOURCES += main.cpp +OTHER_FILES += qml/qmlf1legends/* diff --git a/examples/charts/qmlf1legends/resources.qrc b/examples/charts/qmlf1legends/resources.qrc new file mode 100644 index 00000000..2a89c915 --- /dev/null +++ b/examples/charts/qmlf1legends/resources.qrc @@ -0,0 +1,6 @@ +<RCC> + <qresource prefix="/"> + <file>qml/qmlf1legends/main.qml</file> + <file>qml/qmlf1legends/SpeedsXml.qml</file> + </qresource> +</RCC> diff --git a/examples/charts/qmloscilloscope/datasource.cpp b/examples/charts/qmloscilloscope/datasource.cpp new file mode 100644 index 00000000..ff651110 --- /dev/null +++ b/examples/charts/qmloscilloscope/datasource.cpp @@ -0,0 +1,91 @@ +/**************************************************************************** +** +** Copyright (C) 2014 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 Enterprise Charts Add-on. +** +** $QT_BEGIN_LICENSE$ +** Licensees holding valid Qt Enterprise licenses may use this file in +** accordance with the Qt Enterprise 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 "datasource.h" +#include <QXYSeries> +#include <QAreaSeries> +#include <QtQuick/QQuickView> +#include <QtQuick/QQuickItem> +#include <QDebug> +#include <qmath.h> + +QT_CHARTS_USE_NAMESPACE + +Q_DECLARE_METATYPE(QAbstractSeries *) +Q_DECLARE_METATYPE(QAbstractAxis *) + +DataSource::DataSource(QQuickView *appViewer, QObject *parent) : + QObject(parent), + m_appViewer(appViewer), + m_index(-1) +{ + qRegisterMetaType<QAbstractSeries*>(); + qRegisterMetaType<QAbstractAxis*>(); + + generateData(0, 5, 1024); +} + +void DataSource::update(QAbstractSeries *series) +{ + if (series) { + QXYSeries *xySeries = static_cast<QXYSeries *>(series); + m_index++; + if (m_index > m_data.count() - 1) + m_index = 0; + + QList<QPointF> points = m_data.at(m_index); + // Use replace instead of clear + append, it's optimized for performance + xySeries->replace(points); + } +} + +void DataSource::generateData(int type, int rowCount, int colCount) +{ + // Remove previous data + foreach (QList<QPointF> row, m_data) + row.clear(); + m_data.clear(); + + // Append the new data depending on the type + for (int i(0); i < rowCount; i++) { + QList<QPointF> points; + for (int j(0); j < colCount; j++) { + qreal x(0); + qreal y(0); + switch (type) { + case 0: + // data with sin + random component + y = qSin(3.14159265358979 / 50 * j) + 0.5 + (qreal) rand() / (qreal) RAND_MAX; + x = j; + break; + case 1: + // linear data + x = j; + y = (qreal) i / 10; + break; + default: + // unknown, do nothing + break; + } + points.append(QPointF(x, y)); + } + m_data.append(points); + } +} diff --git a/examples/charts/qmloscilloscope/datasource.h b/examples/charts/qmloscilloscope/datasource.h new file mode 100644 index 00000000..8cb8daa7 --- /dev/null +++ b/examples/charts/qmloscilloscope/datasource.h @@ -0,0 +1,49 @@ +/**************************************************************************** +** +** Copyright (C) 2014 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 Enterprise Charts Add-on. +** +** $QT_BEGIN_LICENSE$ +** Licensees holding valid Qt Enterprise licenses may use this file in +** accordance with the Qt Enterprise 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 DATASOURCE_H +#define DATASOURCE_H + +#include <QObject> +#include <QAbstractSeries> + +class QQuickView; + +QT_CHARTS_USE_NAMESPACE + +class DataSource : public QObject +{ + Q_OBJECT +public: + explicit DataSource(QQuickView *appViewer, QObject *parent = 0); + +signals: + +public slots: + void generateData(int type, int rowCount, int colCount); + void update(QAbstractSeries *series); + +private: + QQuickView *m_appViewer; + QList<QList<QPointF> > m_data; + int m_index; +}; + +#endif // DATASOURCE_H diff --git a/examples/charts/qmloscilloscope/main.cpp b/examples/charts/qmloscilloscope/main.cpp new file mode 100644 index 00000000..cb68260f --- /dev/null +++ b/examples/charts/qmloscilloscope/main.cpp @@ -0,0 +1,56 @@ +/**************************************************************************** +** +** Copyright (C) 2014 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 Enterprise Charts Add-on. +** +** $QT_BEGIN_LICENSE$ +** Licensees holding valid Qt Enterprise licenses may use this file in +** accordance with the Qt Enterprise 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 <QtWidgets/QApplication> +#include <QtQml/QQmlContext> +#include <QtQuick/QQuickView> +#include <QtQml/QQmlEngine> +#include <QtCore/QDir> +#include "datasource.h" + +int main(int argc, char *argv[]) +{ + // Qt Charts uses Qt Graphics View Framework for drawing, therefore QApplication must be used. + QApplication app(argc, argv); + + QQuickView viewer; + + // The following are needed to make examples run without having to install the module + // in desktop environments. +#ifdef Q_OS_WIN + QString extraImportPath(QStringLiteral("%1/../../../../%2")); +#else + QString extraImportPath(QStringLiteral("%1/../../../%2")); +#endif + viewer.engine()->addImportPath(extraImportPath.arg(QGuiApplication::applicationDirPath(), + QString::fromLatin1("qml"))); + QObject::connect(viewer.engine(), &QQmlEngine::quit, &viewer, &QWindow::close); + + viewer.setTitle(QStringLiteral("QML Oscilloscope")); + + DataSource dataSource(&viewer); + viewer.rootContext()->setContextProperty("dataSource", &dataSource); + + viewer.setSource(QUrl("qrc:/qml/qmloscilloscope/main.qml")); + viewer.setResizeMode(QQuickView::SizeRootObjectToView); + viewer.show(); + + return app.exec(); +} diff --git a/examples/charts/qmloscilloscope/qml/qmloscilloscope/ControlPanel.qml b/examples/charts/qmloscilloscope/qml/qmloscilloscope/ControlPanel.qml new file mode 100644 index 00000000..72b9b5df --- /dev/null +++ b/examples/charts/qmloscilloscope/qml/qmloscilloscope/ControlPanel.qml @@ -0,0 +1,88 @@ +/**************************************************************************** +** +** Copyright (C) 2014 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 Enterprise Charts Add-on. +** +** $QT_BEGIN_LICENSE$ +** Licensees holding valid Qt Enterprise licenses may use this file in +** accordance with the Qt Enterprise 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 2.0 +import QtQuick.Layouts 1.0 + +ColumnLayout { + spacing: 8 + Layout.fillHeight: true + signal animationsEnabled(bool enabled) + signal seriesTypeChanged(string type) + signal refreshRateChanged(variant rate); + signal signalSourceChanged(string source, int signalCount, int sampleCount); + signal antialiasingEnabled(bool enabled) + + Text { + text: "Scope" + font.pointSize: 18 + color: "white" + } + + MultiButton { + text: "Graph: " + items: ["line", "spline", "scatter"] + currentSelection: 0 + onSelectionChanged: seriesTypeChanged(items[currentSelection]); + } + + MultiButton { + id: signalSourceButton + text: "Source: " + items: ["sin", "linear"] + currentSelection: 0 + onSelectionChanged: signalSourceChanged( + selection, + 5, + sampleCountButton.items[sampleCountButton.currentSelection]); + } + + MultiButton { + id: sampleCountButton + text: "Samples: " + items: [6, 128, 1024, 10000] + currentSelection: 2 + onSelectionChanged: signalSourceChanged( + signalSourceButton.items[signalSourceButton.currentSelection], + 5, + selection); + } + + MultiButton { + text: "Refresh rate: " + items: [1, 24, 60, 100] + currentSelection: 2 + onSelectionChanged: refreshRateChanged(items[currentSelection]); + } + + MultiButton { + text: "Animations: " + items: ["OFF", "ON"] + currentSelection: 0 + onSelectionChanged: animationsEnabled(currentSelection == 1); + } + + MultiButton { + text: "Antialias: " + items: ["OFF", "ON"] + currentSelection: 0 + onSelectionChanged: antialiasingEnabled(currentSelection == 1); + } +} diff --git a/examples/charts/qmloscilloscope/qml/qmloscilloscope/MultiButton.qml b/examples/charts/qmloscilloscope/qml/qmloscilloscope/MultiButton.qml new file mode 100644 index 00000000..8f6e1e1e --- /dev/null +++ b/examples/charts/qmloscilloscope/qml/qmloscilloscope/MultiButton.qml @@ -0,0 +1,60 @@ +/**************************************************************************** +** +** Copyright (C) 2014 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 Enterprise Charts Add-on. +** +** $QT_BEGIN_LICENSE$ +** Licensees holding valid Qt Enterprise licenses may use this file in +** accordance with the Qt Enterprise 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 2.0 +import QtQuick.Controls 1.0 +import QtQuick.Controls.Styles 1.0 + +Item { + id: button + + property string text: "Option: " + property variant items: ["first"] + property int currentSelection: 0 + signal selectionChanged(variant selection) + + signal clicked + + implicitWidth: buttonText.implicitWidth + 5 + implicitHeight: buttonText.implicitHeight + 10 + + Button { + id: buttonText + width: parent.width + height: parent.height + + style: ButtonStyle { + label: Component { + Text { + text: button.text + button.items[currentSelection] + clip: true + wrapMode: Text.WordWrap + verticalAlignment: Text.AlignVCenter + horizontalAlignment: Text.AlignHCenter + anchors.fill: parent + } + } + } + onClicked: { + currentSelection = (currentSelection + 1) % items.length; + selectionChanged(button.items[currentSelection]); + } + } +} diff --git a/examples/charts/qmloscilloscope/qml/qmloscilloscope/ScopeView.qml b/examples/charts/qmloscilloscope/qml/qmloscilloscope/ScopeView.qml new file mode 100644 index 00000000..d27bf0aa --- /dev/null +++ b/examples/charts/qmloscilloscope/qml/qmloscilloscope/ScopeView.qml @@ -0,0 +1,115 @@ +/**************************************************************************** +** +** Copyright (C) 2014 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 Enterprise Charts Add-on. +** +** $QT_BEGIN_LICENSE$ +** Licensees holding valid Qt Enterprise licenses may use this file in +** accordance with the Qt Enterprise 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 2.0 +import QtCharts 2.0 + +//![1] +ChartView { + id: chartView + animationOptions: ChartView.NoAnimation + theme: ChartView.ChartThemeDark + + ValueAxis { + id: axisY1 + min: -1 + max: 4 + } + + ValueAxis { + id: axisY2 + min: -10 + max: 5 + } + + ValueAxis { + id: axisX + min: 0 + max: 1000 + } + + LineSeries { + id: lineSeries1 + name: "signal 1" + axisX: axisX + axisY: axisY1 + } + LineSeries { + id: lineSeries2 + name: "signal 2" + axisX: axisX + axisYRight: axisY2 + } +//![1] + + //![2] + Timer { + id: refreshTimer + interval: 1 / 60 * 1000 // 60 Hz + running: true + repeat: true + onTriggered: { + dataSource.update(chartView.series(0)); + dataSource.update(chartView.series(1)); + } + } + //![2] + + //![3] + function changeSeriesType(type) { + chartView.removeAllSeries(); + + // Create two new series of the correct type. Axis x is the same for both of the series, + // but the series have their own y-axes to make it possible to control the y-offset + // of the "signal sources". + if (type == "line") { + chartView.createSeries(ChartView.SeriesTypeLine, "signal 1", axisX, axisY1); + chartView.createSeries(ChartView.SeriesTypeLine, "signal 2", axisX, axisY2); + } else if (type == "spline") { + chartView.createSeries(ChartView.SeriesTypeSpline, "signal 1", axisX, axisY1); + chartView.createSeries(ChartView.SeriesTypeSpline, "signal 2", axisX, axisY2); + } else { + var series1 = chartView.createSeries(ChartView.SeriesTypeScatter, "signal 1", axisX, axisY1); + series1.markerSize = 3; + series1.borderColor = "transparent"; + var series2 = chartView.createSeries(ChartView.SeriesTypeScatter, "signal 2", axisX, axisY2); + series2.markerSize = 3; + series2.borderColor = "transparent"; + } + } + + function createAxis(min, max) { + // The following creates a ValueAxis object that can be then set as a x or y axis for a series + return Qt.createQmlObject("import QtQuick 2.0; import QtCharts 2.0; ValueAxis { min: " + + min + "; max: " + max + " }", chartView); + } + //![3] + + function setAnimations(enabled) { + if (enabled) + chartView.animationOptions = ChartView.SeriesAnimations; + else + chartView.animationOptions = ChartView.NoAnimation; + } + + function changeRefreshRate(rate) { + refreshTimer.interval = 1 / Number(rate) * 1000; + } +} diff --git a/examples/charts/qmloscilloscope/qml/qmloscilloscope/main.qml b/examples/charts/qmloscilloscope/qml/qmloscilloscope/main.qml new file mode 100644 index 00000000..c88dfab3 --- /dev/null +++ b/examples/charts/qmloscilloscope/qml/qmloscilloscope/main.qml @@ -0,0 +1,61 @@ +/**************************************************************************** +** +** Copyright (C) 2014 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 Enterprise Charts Add-on. +** +** $QT_BEGIN_LICENSE$ +** Licensees holding valid Qt Enterprise licenses may use this file in +** accordance with the Qt Enterprise 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 2.0 + +//![1] +Rectangle { + id: main + width: 400 + height: 300 + color: "#404040" + + ControlPanel { + id: controlPanel + anchors.top: parent.top + anchors.topMargin: 10 + anchors.bottom: parent.bottom + anchors.left: parent.left + anchors.leftMargin: 10 +//![1] + + onSignalSourceChanged: { + if (source == "sin") + dataSource.generateData(0, signalCount, sampleCount); + else + dataSource.generateData(1, signalCount, sampleCount); + } + onAnimationsEnabled: scopeView.setAnimations(enabled); + onSeriesTypeChanged: scopeView.changeSeriesType(type); + onRefreshRateChanged: scopeView.changeRefreshRate(rate); + onAntialiasingEnabled: scopeView.antialiasing = enabled; + } + +//![2] + ScopeView { + id: scopeView + anchors.top: parent.top + anchors.bottom: parent.bottom + anchors.right: parent.right + anchors.left: controlPanel.right + height: main.height + } +//![2] +} diff --git a/examples/charts/qmloscilloscope/qmloscilloscope.pro b/examples/charts/qmloscilloscope/qmloscilloscope.pro new file mode 100644 index 00000000..a66fabcd --- /dev/null +++ b/examples/charts/qmloscilloscope/qmloscilloscope.pro @@ -0,0 +1,11 @@ +!include( ../examples.pri ) { + error( "Couldn't find the examples.pri file!" ) +} + +RESOURCES += resources.qrc +SOURCES += main.cpp \ + datasource.cpp +OTHER_FILES += qml/qmloscilloscope/* + +HEADERS += \ + datasource.h diff --git a/examples/charts/qmloscilloscope/resources.qrc b/examples/charts/qmloscilloscope/resources.qrc new file mode 100644 index 00000000..e2aadae8 --- /dev/null +++ b/examples/charts/qmloscilloscope/resources.qrc @@ -0,0 +1,8 @@ +<RCC> + <qresource prefix="/"> + <file>qml/qmloscilloscope/main.qml</file> + <file>qml/qmloscilloscope/ControlPanel.qml</file> + <file>qml/qmloscilloscope/ScopeView.qml</file> + <file>qml/qmloscilloscope/MultiButton.qml</file> + </qresource> +</RCC> diff --git a/examples/charts/qmlpiechart/main.cpp b/examples/charts/qmlpiechart/main.cpp new file mode 100644 index 00000000..5162b540 --- /dev/null +++ b/examples/charts/qmlpiechart/main.cpp @@ -0,0 +1,49 @@ +/**************************************************************************** +** +** Copyright (C) 2014 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 Enterprise Charts Add-on. +** +** $QT_BEGIN_LICENSE$ +** Licensees holding valid Qt Enterprise licenses may use this file in +** accordance with the Qt Enterprise 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 <QtWidgets/QApplication> +#include <QtQuick/QQuickView> +#include <QtCore/QDir> +#include <QtQml/QQmlEngine> + +int main(int argc, char *argv[]) +{ + // Qt Charts uses Qt Graphics View Framework for drawing, therefore QApplication must be used. + QApplication app(argc, argv); + + QQuickView viewer; + // The following are needed to make examples run without having to install the module + // in desktop environments. +#ifdef Q_OS_WIN + QString extraImportPath(QStringLiteral("%1/../../../../%2")); +#else + QString extraImportPath(QStringLiteral("%1/../../../%2")); +#endif + viewer.engine()->addImportPath(extraImportPath.arg(QGuiApplication::applicationDirPath(), + QString::fromLatin1("qml"))); + QObject::connect(viewer.engine(), &QQmlEngine::quit, &viewer, &QWindow::close); + + viewer.setTitle(QStringLiteral("QML Pie Chart")); + viewer.setSource(QUrl("qrc:/qml/qmlpiechart/main.qml")); + viewer.setResizeMode(QQuickView::SizeRootObjectToView); + viewer.show(); + + return app.exec(); +} diff --git a/examples/qmlpiechart/qml/qmlpiechart/main.qml b/examples/charts/qmlpiechart/qml/qmlpiechart/main.qml index 77f4472e..b836539b 100644 --- a/examples/qmlpiechart/qml/qmlpiechart/main.qml +++ b/examples/charts/qmlpiechart/qml/qmlpiechart/main.qml @@ -19,13 +19,14 @@ ****************************************************************************/ //![1] -import QtQuick 1.0 -import QtCommercial.Chart 1.1 +import QtQuick 2.0 +import QtCharts 2.0 ChartView { width: 400 height: 300 theme: ChartView.ChartThemeBrownSand + antialiasing: true //![1] //![2] diff --git a/examples/qmlpiechart/qmlpiechart.pro b/examples/charts/qmlpiechart/qmlpiechart.pro index b771d8dd..926f9c2d 100644 --- a/examples/qmlpiechart/qmlpiechart.pro +++ b/examples/charts/qmlpiechart/qmlpiechart.pro @@ -5,5 +5,3 @@ RESOURCES += resources.qrc SOURCES += main.cpp OTHER_FILES += qml/qmlpiechart/* - -include(qmlapplicationviewer/qmlapplicationviewer.pri) diff --git a/examples/qmlpiechart/qmlpiechart.svg b/examples/charts/qmlpiechart/qmlpiechart.svg index 566acfad..566acfad 100644 --- a/examples/qmlpiechart/qmlpiechart.svg +++ b/examples/charts/qmlpiechart/qmlpiechart.svg diff --git a/examples/qmlpiechart/resources.qrc b/examples/charts/qmlpiechart/resources.qrc index 2501bcc8..2501bcc8 100644 --- a/examples/qmlpiechart/resources.qrc +++ b/examples/charts/qmlpiechart/resources.qrc diff --git a/examples/charts/qmlpolarchart/main.cpp b/examples/charts/qmlpolarchart/main.cpp new file mode 100644 index 00000000..a850da1f --- /dev/null +++ b/examples/charts/qmlpolarchart/main.cpp @@ -0,0 +1,49 @@ +/**************************************************************************** +** +** Copyright (C) 2014 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 Enterprise Charts Add-on. +** +** $QT_BEGIN_LICENSE$ +** Licensees holding valid Qt Enterprise licenses may use this file in +** accordance with the Qt Enterprise 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 <QtWidgets/QApplication> +#include <QtQuick/QQuickView> +#include <QtCore/QDir> +#include <QtQml/QQmlEngine> + +int main(int argc, char *argv[]) +{ + // Qt Charts uses Qt Graphics View Framework for drawing, therefore QApplication must be used. + QApplication app(argc, argv); + + QQuickView viewer; + // The following are needed to make examples run without having to install the module + // in desktop environments. +#ifdef Q_OS_WIN + QString extraImportPath(QStringLiteral("%1/../../../../%2")); +#else + QString extraImportPath(QStringLiteral("%1/../../../%2")); +#endif + viewer.engine()->addImportPath(extraImportPath.arg(QGuiApplication::applicationDirPath(), + QString::fromLatin1("qml"))); + QObject::connect(viewer.engine(), &QQmlEngine::quit, &viewer, &QWindow::close); + + viewer.setTitle(QStringLiteral("QML Polar Chart")); + viewer.setSource(QUrl("qrc:/qml/qmlpolarchart/main.qml")); + viewer.setResizeMode(QQuickView::SizeRootObjectToView); + viewer.show(); + + return app.exec(); +} diff --git a/examples/charts/qmlpolarchart/qml/qmlpolarchart/View1.qml b/examples/charts/qmlpolarchart/qml/qmlpolarchart/View1.qml new file mode 100644 index 00000000..b6c921fa --- /dev/null +++ b/examples/charts/qmlpolarchart/qml/qmlpolarchart/View1.qml @@ -0,0 +1,69 @@ +/**************************************************************************** +** +** Copyright (C) 2014 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 Enterprise Charts Add-on. +** +** $QT_BEGIN_LICENSE$ +** Licensees holding valid Qt Enterprise licenses may use this file in +** accordance with the Qt Enterprise 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 2.0 +import QtCharts 2.0 + +Rectangle { + anchors.fill: parent + //![1] + PolarChartView { + title: "Two Series, Common Axes" + anchors.fill: parent + legend.visible: false + antialiasing: true + + ValueAxis { + id: axisAngular + min: 0 + max: 20 + tickCount: 9 + } + + ValueAxis { + id: axisRadial + min: -0.5 + max: 1.5 + } + + SplineSeries { + id: series1 + axisAngular: axisAngular + axisRadial: axisRadial + pointsVisible: true + } + + ScatterSeries { + id: series2 + axisAngular: axisAngular + axisRadial: axisRadial + markerSize: 10 + } + } + + // Add data dynamically to the series + Component.onCompleted: { + for (var i = 0; i <= 20; i++) { + series1.append(i, Math.random()); + series2.append(i, Math.random()); + } + } + //![1] +} diff --git a/examples/charts/qmlpolarchart/qml/qmlpolarchart/View2.qml b/examples/charts/qmlpolarchart/qml/qmlpolarchart/View2.qml new file mode 100644 index 00000000..9df1f66b --- /dev/null +++ b/examples/charts/qmlpolarchart/qml/qmlpolarchart/View2.qml @@ -0,0 +1,90 @@ +/**************************************************************************** +** +** Copyright (C) 2014 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 Enterprise Charts Add-on. +** +** $QT_BEGIN_LICENSE$ +** Licensees holding valid Qt Enterprise licenses may use this file in +** accordance with the Qt Enterprise 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 2.0 +import QtCharts 2.0 + +Rectangle { + anchors.fill: parent + + //![1] + PolarChartView { + title: "Historical Area Series" + anchors.fill: parent + legend.visible: false + antialiasing: true + + DateTimeAxis { + id: axis1 + format: "yyyy MMM" + tickCount: 13 + } + ValueAxis { + id: axis2 + } + LineSeries { + id: lowerLine + axisAngular: axis1 + axisRadial: axis2 + + // Please note that month in JavaScript months are zero based, so 2 means March + XYPoint { x: toMsecsSinceEpoch(new Date(1950, 0, 1)); y: 15 } + XYPoint { x: toMsecsSinceEpoch(new Date(1962, 4, 1)); y: 35 } + XYPoint { x: toMsecsSinceEpoch(new Date(1970, 0, 1)); y: 50 } + XYPoint { x: toMsecsSinceEpoch(new Date(1978, 2, 1)); y: 75 } + XYPoint { x: toMsecsSinceEpoch(new Date(1987, 11, 1)); y: 102 } + XYPoint { x: toMsecsSinceEpoch(new Date(1992, 1, 1)); y: 132 } + XYPoint { x: toMsecsSinceEpoch(new Date(1998, 7, 1)); y: 100 } + XYPoint { x: toMsecsSinceEpoch(new Date(2002, 4, 1)); y: 120 } + XYPoint { x: toMsecsSinceEpoch(new Date(2012, 8, 1)); y: 140 } + XYPoint { x: toMsecsSinceEpoch(new Date(2013, 5, 1)); y: 150 } + } + LineSeries { + id: upperLine + axisAngular: axis1 + axisRadial: axis2 + + // Please note that month in JavaScript months are zero based, so 2 means March + XYPoint { x: toMsecsSinceEpoch(new Date(1950, 0, 1)); y: 30 } + XYPoint { x: toMsecsSinceEpoch(new Date(1962, 4, 1)); y: 55 } + XYPoint { x: toMsecsSinceEpoch(new Date(1970, 0, 1)); y: 80 } + XYPoint { x: toMsecsSinceEpoch(new Date(1978, 2, 1)); y: 105 } + XYPoint { x: toMsecsSinceEpoch(new Date(1987, 11, 1)); y: 125 } + XYPoint { x: toMsecsSinceEpoch(new Date(1992, 1, 1)); y: 160 } + XYPoint { x: toMsecsSinceEpoch(new Date(1998, 7, 1)); y: 140 } + XYPoint { x: toMsecsSinceEpoch(new Date(2002, 4, 1)); y: 140 } + XYPoint { x: toMsecsSinceEpoch(new Date(2012, 8, 1)); y: 170 } + XYPoint { x: toMsecsSinceEpoch(new Date(2013, 5, 1)); y: 200 } + } + AreaSeries { + axisAngular: axis1 + axisRadial: axis2 + lowerSeries: lowerLine + upperSeries: upperLine + } + } + // DateTimeAxis is based on QDateTimes so we must convert our JavaScript dates to + // milliseconds since epoch to make them match the DateTimeAxis values + function toMsecsSinceEpoch(date) { + var msecs = date.getTime(); + return msecs; + } + //![1] +} diff --git a/examples/charts/qmlpolarchart/qml/qmlpolarchart/View3.qml b/examples/charts/qmlpolarchart/qml/qmlpolarchart/View3.qml new file mode 100644 index 00000000..0a5304b4 --- /dev/null +++ b/examples/charts/qmlpolarchart/qml/qmlpolarchart/View3.qml @@ -0,0 +1,77 @@ +/**************************************************************************** +** +** Copyright (C) 2014 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 Enterprise Charts Add-on. +** +** $QT_BEGIN_LICENSE$ +** Licensees holding valid Qt Enterprise licenses may use this file in +** accordance with the Qt Enterprise 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 2.0 +import QtCharts 2.0 + +Rectangle { + anchors.fill: parent + + //![1] + PolarChartView { + title: "Numerical Data for Dummies" + anchors.fill: parent + legend.visible: false + antialiasing: true + + LineSeries { + axisRadial: CategoryAxis { + min: 0 + max: 30 + CategoryRange { + label: "critical" + endValue: 2 + } + CategoryRange { + label: "low" + endValue: 7 + } + CategoryRange { + label: "normal" + endValue: 12 + } + CategoryRange { + label: "high" + endValue: 18 + } + CategoryRange { + label: "extremely high" + endValue: 30 + } + } + + axisAngular: ValueAxis { + tickCount: 13 + } + + XYPoint { x: 0; y: 4.3 } + XYPoint { x: 1; y: 4.1 } + XYPoint { x: 2; y: 4.7 } + XYPoint { x: 3; y: 3.9 } + XYPoint { x: 4; y: 5.2 } + XYPoint { x: 5; y: 5.3 } + XYPoint { x: 6; y: 6.1 } + XYPoint { x: 7; y: 7.7 } + XYPoint { x: 8; y: 12.9 } + XYPoint { x: 9; y: 19.2 } + } + } + //![1] +} diff --git a/examples/charts/qmlpolarchart/qml/qmlpolarchart/main.qml b/examples/charts/qmlpolarchart/qml/qmlpolarchart/main.qml new file mode 100644 index 00000000..ce5a4ed4 --- /dev/null +++ b/examples/charts/qmlpolarchart/qml/qmlpolarchart/main.qml @@ -0,0 +1,80 @@ +/**************************************************************************** +** +** Copyright (C) 2014 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 Enterprise Charts Add-on. +** +** $QT_BEGIN_LICENSE$ +** Licensees holding valid Qt Enterprise licenses may use this file in +** accordance with the Qt Enterprise 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 2.0 + +Rectangle { + width: 800 + height: 600 + property bool sourceLoaded: false + + ListView { + id: root + focus: true + anchors.fill: parent + snapMode: ListView.SnapOneItem + highlightRangeMode: ListView.StrictlyEnforceRange + highlightMoveDuration: 250 + orientation: ListView.Horizontal + boundsBehavior: Flickable.StopAtBounds + + onCurrentIndexChanged: { + if (infoText.opacity > 0.0) { + if (sourceLoaded) + infoText.opacity = 0.0; + else if (currentIndex != 0) + currentIndex = 0; + } + } + + model: ListModel { + ListElement {component: "View1.qml"} + ListElement {component: "View2.qml"} + ListElement {component: "View3.qml"} + } + + delegate: Loader { + width: root.width + height: root.height + + source: component + asynchronous: true + + onLoaded: sourceLoaded = true + } + } + + Rectangle { + id: infoText + anchors.centerIn: parent + width: parent.width + height: 40 + color: "black" + Text { + color: "white" + anchors.centerIn: parent + text: "You can navigate between views using swipe or arrow keys" + } + + Behavior on opacity { + NumberAnimation { duration: 400 } + } + } +} diff --git a/examples/charts/qmlpolarchart/qmlpolarchart.pro b/examples/charts/qmlpolarchart/qmlpolarchart.pro new file mode 100644 index 00000000..aa3341a5 --- /dev/null +++ b/examples/charts/qmlpolarchart/qmlpolarchart.pro @@ -0,0 +1,7 @@ +!include( ../examples.pri ) { + error( "Couldn't find the examples.pri file!" ) +} + +RESOURCES += resources.qrc +SOURCES += main.cpp +OTHER_FILES += qml/qmlpolarchart/* diff --git a/examples/charts/qmlpolarchart/resources.qrc b/examples/charts/qmlpolarchart/resources.qrc new file mode 100644 index 00000000..a4a975ed --- /dev/null +++ b/examples/charts/qmlpolarchart/resources.qrc @@ -0,0 +1,8 @@ +<RCC> + <qresource prefix="/"> + <file>qml/qmlpolarchart/main.qml</file> + <file>qml/qmlpolarchart/View1.qml</file> + <file>qml/qmlpolarchart/View2.qml</file> + <file>qml/qmlpolarchart/View3.qml</file> + </qresource> +</RCC> diff --git a/examples/charts/qmlweather/main.cpp b/examples/charts/qmlweather/main.cpp new file mode 100644 index 00000000..9bdd28d1 --- /dev/null +++ b/examples/charts/qmlweather/main.cpp @@ -0,0 +1,59 @@ +/**************************************************************************** +** +** Copyright (C) 2014 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 Enterprise Charts Add-on. +** +** $QT_BEGIN_LICENSE$ +** Licensees holding valid Qt Enterprise licenses may use this file in +** accordance with the Qt Enterprise 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 <QtWidgets/QApplication> +#include <QtQuick/QQuickView> +#include <QDebug> +#include <QtCore/QDir> +#include <QtQml/QQmlContext> +#include <QtQml/QQmlEngine> + +int main(int argc, char *argv[]) +{ + // Qt Charts uses Qt Graphics View Framework for drawing, therefore QApplication must be used. + QApplication app(argc, argv); + + QQuickView viewer; + // The following are needed to make examples run without having to install the module + // in desktop environments. +#ifdef Q_OS_WIN + QString extraImportPath(QStringLiteral("%1/../../../../%2")); +#else + QString extraImportPath(QStringLiteral("%1/../../../%2")); +#endif + viewer.engine()->addImportPath(extraImportPath.arg(QGuiApplication::applicationDirPath(), + QString::fromLatin1("qml"))); + QObject::connect(viewer.engine(), &QQmlEngine::quit, &viewer, &QWindow::close); + + QString appKey; + if (argc > 1) { + appKey = argv[1]; + qDebug() << "App key for worldweatheronline.com:" << appKey; + } else { + qWarning() << "No app key for worldweatheronline.com given. Using static test data instead of live data."; + } + viewer.setTitle(QStringLiteral("QML Weather")); + viewer.rootContext()->setContextProperty("weatherAppKey", appKey); + viewer.setSource(QUrl("qrc:/qml/qmlweather/main.qml")); + viewer.setResizeMode(QQuickView::SizeRootObjectToView); + viewer.show(); + + return app.exec(); +} diff --git a/examples/charts/qmlweather/qml/qmlweather/main.qml b/examples/charts/qmlweather/qml/qmlweather/main.qml new file mode 100644 index 00000000..23d3ee23 --- /dev/null +++ b/examples/charts/qmlweather/qml/qmlweather/main.qml @@ -0,0 +1,201 @@ +/**************************************************************************** +** +** Copyright (C) 2014 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 Enterprise Charts Add-on. +** +** $QT_BEGIN_LICENSE$ +** Licensees holding valid Qt Enterprise licenses may use this file in +** accordance with the Qt Enterprise 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 2.0 +import QtCharts 2.0 + +Rectangle { + width: 500 + height: 400 + gradient: Gradient { + GradientStop { position: 0.0; color: "lightblue" } + GradientStop { position: 1.0; color: "white" } + } + + //![1] + ChartView { + id: chartView + title: "Weather forecast" + //![1] + anchors.top: parent.top + anchors.bottom: weatherImageRow.top + anchors.left: parent.left + anchors.right: parent.right + legend.alignment: Qt.AlignTop + antialiasing: true + + //![2] + BarCategoryAxis { + id: barCategoriesAxis + titleText: "Date" + } + + ValueAxis{ + id: valueAxisY2 + min: 0 + max: 10 + titleText: "Rainfall [mm]" + } + + ValueAxis { + id: valueAxisX + // Hide the value axis; it is only used to map the line series to bar categories axis + visible: false + min: 0 + max: 5 + } + + ValueAxis{ + id: valueAxisY + min: 0 + max: 15 + titleText: "Temperature [°C]" + } + + LineSeries { + id: maxTempSeries + axisX: valueAxisX + axisY: valueAxisY + name: "Max. temperature" + } + + LineSeries { + id: minTempSeries + axisX: valueAxisX + axisY: valueAxisY + name: "Min. temperature" + } + + BarSeries { + id: myBarSeries + axisX: barCategoriesAxis + axisYRight: valueAxisY2 + BarSet { + id: rainfallSet + label: "Rainfall" + } + } + //![2] + } + + // A timer to refresh the forecast every 5 minutes + Timer { + interval: 300000 + repeat: true + triggeredOnStart: true + running: true + onTriggered: { + if (weatherAppKey != "") { + //![3] + // Make HTTP GET request and parse the result + var xhr = new XMLHttpRequest; + xhr.open("GET", + "http://free.worldweatheronline.com/feed/weather.ashx?q=Jyv%c3%a4skyl%c3%a4,Finland&format=json&num_of_days=5&key=" + + weatherAppKey); + xhr.onreadystatechange = function() { + if (xhr.readyState == XMLHttpRequest.DONE) { + var a = JSON.parse(xhr.responseText); + parseWeatherData(a); + } + } + xhr.send(); + //![3] + } else { + // No app key for worldweatheronline.com given by the user -> use dummy static data + var responseText = "{ \"data\": { \"current_condition\": [ {\"cloudcover\": \"10\", \"humidity\": \"61\", \"observation_time\": \"06:26 AM\", \"precipMM\": \"0.0\", \"pressure\": \"1022\", \"temp_C\": \"6\", \"temp_F\": \"43\", \"visibility\": \"10\", \"weatherCode\": \"113\", \"weatherDesc\": [ {\"value\": \"Sunny\" } ], \"weatherIconUrl\": [ {\"value\": \"http:\/\/www.worldweatheronline.com\/images\/wsymbols01_png_64\/wsymbol_0001_sunny.png\" } ], \"winddir16Point\": \"SE\", \"winddirDegree\": \"140\", \"windspeedKmph\": \"7\", \"windspeedMiles\": \"4\" } ], \"request\": [ {\"query\": \"Jyvaskyla, Finland\", \"type\": \"City\" } ], \"weather\": [ {\"date\": \"2012-05-09\", \"precipMM\": \"0.4\", \"tempMaxC\": \"14\", \"tempMaxF\": \"57\", \"tempMinC\": \"7\", \"tempMinF\": \"45\", \"weatherCode\": \"116\", \"weatherDesc\": [ {\"value\": \"Partly Cloudy\" } ], \"weatherIconUrl\": [ {\"value\": \"http:\/\/www.worldweatheronline.com\/images\/wsymbols01_png_64\/wsymbol_0002_sunny_intervals.png\" } ], \"winddir16Point\": \"S\", \"winddirDegree\": \"179\", \"winddirection\": \"S\", \"windspeedKmph\": \"20\", \"windspeedMiles\": \"12\" }, {\"date\": \"2012-05-10\", \"precipMM\": \"2.4\", \"tempMaxC\": \"13\", \"tempMaxF\": \"55\", \"tempMinC\": \"8\", \"tempMinF\": \"46\", \"weatherCode\": \"266\", \"weatherDesc\": [ {\"value\": \"Light drizzle\" } ], \"weatherIconUrl\": [ {\"value\": \"http:\/\/www.worldweatheronline.com\/images\/wsymbols01_png_64\/wsymbol_0017_cloudy_with_light_rain.png\" } ], \"winddir16Point\": \"SW\", \"winddirDegree\": \"219\", \"winddirection\": \"SW\", \"windspeedKmph\": \"21\", \"windspeedMiles\": \"13\" }, {\"date\": \"2012-05-11\", \"precipMM\": \"11.1\", \"tempMaxC\": \"15\", \"tempMaxF\": \"59\", \"tempMinC\": \"7\", \"tempMinF\": \"44\", \"weatherCode\": \"266\", \"weatherDesc\": [ {\"value\": \"Light drizzle\" } ], \"weatherIconUrl\": [ {\"value\": \"http:\/\/www.worldweatheronline.com\/images\/wsymbols01_png_64\/wsymbol_0017_cloudy_with_light_rain.png\" } ], \"winddir16Point\": \"SSW\", \"winddirDegree\": \"200\", \"winddirection\": \"SSW\", \"windspeedKmph\": \"20\", \"windspeedMiles\": \"12\" }, {\"date\": \"2012-05-12\", \"precipMM\": \"2.8\", \"tempMaxC\": \"7\", \"tempMaxF\": \"44\", \"tempMinC\": \"2\", \"tempMinF\": \"35\", \"weatherCode\": \"317\", \"weatherDesc\": [ {\"value\": \"Light sleet\" } ], \"weatherIconUrl\": [ {\"value\": \"http:\/\/www.worldweatheronline.com\/images\/wsymbols01_png_64\/wsymbol_0021_cloudy_with_sleet.png\" } ], \"winddir16Point\": \"NW\", \"winddirDegree\": \"311\", \"winddirection\": \"NW\", \"windspeedKmph\": \"24\", \"windspeedMiles\": \"15\" }, {\"date\": \"2012-05-13\", \"precipMM\": \"0.4\", \"tempMaxC\": \"6\", \"tempMaxF\": \"42\", \"tempMinC\": \"2\", \"tempMinF\": \"35\", \"weatherCode\": \"116\", \"weatherDesc\": [ {\"value\": \"Partly Cloudy\" } ], \"weatherIconUrl\": [ {\"value\": \"http:\/\/www.worldweatheronline.com\/images\/wsymbols01_png_64\/wsymbol_0002_sunny_intervals.png\" } ], \"winddir16Point\": \"WNW\", \"winddirDegree\": \"281\", \"winddirection\": \"WNW\", \"windspeedKmph\": \"21\", \"windspeedMiles\": \"13\" } ] }}"; + var a = JSON.parse(responseText); + parseWeatherData(a); + } + } + } + + Row { + id: weatherImageRow + anchors.bottom: poweredByText.top + anchors.bottomMargin: 10 + anchors.left: parent.left + anchors.leftMargin: 25 + anchors.right: parent.right + anchors.rightMargin: 25 + + ListModel { + id: weatherImageModel + } + + Repeater { + id: repeater + model: weatherImageModel + delegate: Image { + source: imageSource + width: weatherImageRow.width / weatherImageModel.count + height: width + fillMode: Image.PreserveAspectCrop + } + } + } + + Text { + id: poweredByText + anchors.bottom: parent.bottom + anchors.bottomMargin: 10 + anchors.left: parent.left + anchors.leftMargin: 25 + text: "Powered by World Weather Online" + } + + function parseWeatherData(weatherData) { + // Clear previous values + maxTempSeries.clear(); + minTempSeries.clear(); + weatherImageModel.clear(); + + //![4] + // Loop through the parsed JSON + for (var i in weatherData.data.weather) { + var weatherObj = weatherData.data.weather[i]; + //![4] + + //![5] + // Store temperature values, rainfall and weather icon. + // The temperature values begin from 0.5 instead of 0.0 to make the start from the + // middle of the rainfall bars. This makes the temperature lines visually better + // synchronized with the rainfall bars. + maxTempSeries.append(Number(i) + 0.5, weatherObj.tempMaxC); + minTempSeries.append(Number(i) + 0.5, weatherObj.tempMinC); + rainfallSet.append(i, weatherObj.precipMM); + weatherImageModel.append({"imageSource":weatherObj.weatherIconUrl[0].value}); + //![5] + + // Update scale of the chart + valueAxisY.max = Math.max(chartView.axisY().max,weatherObj.tempMaxC); + valueAxisX.min = 0; + valueAxisX.max = Number(i) + 1; + + // Set the x-axis labels to the dates of the forecast + var xLabels = barCategoriesAxis.categories; + xLabels[Number(i)] = weatherObj.date.substring(5, 10); + barCategoriesAxis.categories = xLabels; + barCategoriesAxis.visible = true; + barCategoriesAxis.min = 0; + barCategoriesAxis.max = xLabels.length - 1; + } + } + +} diff --git a/examples/charts/qmlweather/qmlweather.pro b/examples/charts/qmlweather/qmlweather.pro new file mode 100644 index 00000000..5e0d8df4 --- /dev/null +++ b/examples/charts/qmlweather/qmlweather.pro @@ -0,0 +1,7 @@ +!include( ../examples.pri ) { + error( "Couldn't find the examples.pri file!" ) +} + +RESOURCES += resources.qrc +SOURCES += main.cpp +OTHER_FILES += qml/qmlweather/* diff --git a/examples/charts/qmlweather/resources.qrc b/examples/charts/qmlweather/resources.qrc new file mode 100644 index 00000000..7205906f --- /dev/null +++ b/examples/charts/qmlweather/resources.qrc @@ -0,0 +1,5 @@ +<RCC> + <qresource prefix="/"> + <file>qml/qmlweather/main.qml</file> + </qresource> +</RCC> diff --git a/examples/scatterchart/chartview.cpp b/examples/charts/scatterchart/chartview.cpp index 345be195..345be195 100644 --- a/examples/scatterchart/chartview.cpp +++ b/examples/charts/scatterchart/chartview.cpp diff --git a/examples/scatterchart/chartview.h b/examples/charts/scatterchart/chartview.h index 699100ff..c2c03038 100644 --- a/examples/scatterchart/chartview.h +++ b/examples/charts/scatterchart/chartview.h @@ -23,7 +23,7 @@ #include <QChartView> -QTCOMMERCIALCHART_USE_NAMESPACE +QT_CHARTS_USE_NAMESPACE class ChartView : public QChartView { diff --git a/examples/scatterchart/main.cpp b/examples/charts/scatterchart/main.cpp index 43d5e4c6..e1a76ed2 100644 --- a/examples/scatterchart/main.cpp +++ b/examples/charts/scatterchart/main.cpp @@ -22,7 +22,7 @@ #include <QMainWindow> #include "chartview.h" -QTCOMMERCIALCHART_USE_NAMESPACE +QT_CHARTS_USE_NAMESPACE int main(int argc, char *argv[]) { diff --git a/examples/scatterchart/scatterchart.pro b/examples/charts/scatterchart/scatterchart.pro index 8170d6f4..8170d6f4 100644 --- a/examples/scatterchart/scatterchart.pro +++ b/examples/charts/scatterchart/scatterchart.pro diff --git a/examples/scatterinteractions/chartview.cpp b/examples/charts/scatterinteractions/chartview.cpp index e7ccd5c4..7e55c4e0 100644 --- a/examples/scatterinteractions/chartview.cpp +++ b/examples/charts/scatterinteractions/chartview.cpp @@ -22,7 +22,7 @@ #include <qmath.h> #include <QDebug> -QTCOMMERCIALCHART_USE_NAMESPACE +QT_CHARTS_USE_NAMESPACE ChartView::ChartView(QWidget *parent) : QChartView(new QChart(), parent), diff --git a/examples/scatterinteractions/chartview.h b/examples/charts/scatterinteractions/chartview.h index d84ec6f5..da280051 100644 --- a/examples/scatterinteractions/chartview.h +++ b/examples/charts/scatterinteractions/chartview.h @@ -25,7 +25,7 @@ #include <QChartView> #include <QScatterSeries> -QTCOMMERCIALCHART_USE_NAMESPACE +QT_CHARTS_USE_NAMESPACE class ChartView : public QChartView { diff --git a/examples/scatterinteractions/main.cpp b/examples/charts/scatterinteractions/main.cpp index fb5dd8fc..fb5dd8fc 100644 --- a/examples/scatterinteractions/main.cpp +++ b/examples/charts/scatterinteractions/main.cpp diff --git a/examples/scatterinteractions/scatterinteractions.pro b/examples/charts/scatterinteractions/scatterinteractions.pro index 596fe020..596fe020 100644 --- a/examples/scatterinteractions/scatterinteractions.pro +++ b/examples/charts/scatterinteractions/scatterinteractions.pro diff --git a/examples/splinechart/main.cpp b/examples/charts/splinechart/main.cpp index bb4c28d6..e6a40dd0 100644 --- a/examples/splinechart/main.cpp +++ b/examples/charts/splinechart/main.cpp @@ -23,7 +23,7 @@ #include <QChartView> #include <QSplineSeries> -QTCOMMERCIALCHART_USE_NAMESPACE +QT_CHARTS_USE_NAMESPACE int main(int argc, char *argv[]) { diff --git a/examples/splinechart/splinechart.pro b/examples/charts/splinechart/splinechart.pro index b2624f53..b2624f53 100644 --- a/examples/splinechart/splinechart.pro +++ b/examples/charts/splinechart/splinechart.pro diff --git a/examples/stackedbarchart/main.cpp b/examples/charts/stackedbarchart/main.cpp index 3e83c39b..c94b18de 100644 --- a/examples/stackedbarchart/main.cpp +++ b/examples/charts/stackedbarchart/main.cpp @@ -26,7 +26,7 @@ #include <QLegend> #include <QBarCategoryAxis> -QTCOMMERCIALCHART_USE_NAMESPACE +QT_CHARTS_USE_NAMESPACE int main(int argc, char *argv[]) { diff --git a/examples/stackedbarchart/stackedbarchart.pro b/examples/charts/stackedbarchart/stackedbarchart.pro index f6a77b6a..f6a77b6a 100644 --- a/examples/stackedbarchart/stackedbarchart.pro +++ b/examples/charts/stackedbarchart/stackedbarchart.pro diff --git a/examples/stackedbarchartdrilldown/drilldownchart.cpp b/examples/charts/stackedbarchartdrilldown/drilldownchart.cpp index 1dd3df57..1acfa172 100644 --- a/examples/stackedbarchartdrilldown/drilldownchart.cpp +++ b/examples/charts/stackedbarchartdrilldown/drilldownchart.cpp @@ -21,7 +21,7 @@ #include "drilldownchart.h" #include <QBarCategoryAxis> -QTCOMMERCIALCHART_USE_NAMESPACE +QT_CHARTS_USE_NAMESPACE DrilldownChart::DrilldownChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) : QChart(QChart::ChartTypeCartesian, parent, wFlags), diff --git a/examples/stackedbarchartdrilldown/drilldownchart.h b/examples/charts/stackedbarchartdrilldown/drilldownchart.h index 1eb7ead0..c75216f7 100644 --- a/examples/stackedbarchartdrilldown/drilldownchart.h +++ b/examples/charts/stackedbarchartdrilldown/drilldownchart.h @@ -24,7 +24,7 @@ #include <QChart> #include "drilldownseries.h" -QTCOMMERCIALCHART_USE_NAMESPACE +QT_CHARTS_USE_NAMESPACE //! [1] class DrilldownChart : public QChart diff --git a/examples/stackedbarchartdrilldown/drilldownseries.cpp b/examples/charts/stackedbarchartdrilldown/drilldownseries.cpp index 2f3c2fb3..87d70b5a 100644 --- a/examples/stackedbarchartdrilldown/drilldownseries.cpp +++ b/examples/charts/stackedbarchartdrilldown/drilldownseries.cpp @@ -20,7 +20,7 @@ #include "drilldownseries.h" -QTCOMMERCIALCHART_USE_NAMESPACE +QT_CHARTS_USE_NAMESPACE DrilldownBarSeries::DrilldownBarSeries(QStringList categories, QObject *parent) : QStackedBarSeries(parent) diff --git a/examples/stackedbarchartdrilldown/drilldownseries.h b/examples/charts/stackedbarchartdrilldown/drilldownseries.h index a9c86ad5..5a340839 100644 --- a/examples/stackedbarchartdrilldown/drilldownseries.h +++ b/examples/charts/stackedbarchartdrilldown/drilldownseries.h @@ -24,7 +24,7 @@ #include <QStackedBarSeries> #include <QMap> -QTCOMMERCIALCHART_USE_NAMESPACE +QT_CHARTS_USE_NAMESPACE //! [1] class DrilldownBarSeries : public QStackedBarSeries diff --git a/examples/stackedbarchartdrilldown/main.cpp b/examples/charts/stackedbarchartdrilldown/main.cpp index 2673ab32..6a46520d 100644 --- a/examples/stackedbarchartdrilldown/main.cpp +++ b/examples/charts/stackedbarchartdrilldown/main.cpp @@ -26,7 +26,7 @@ #include "drilldownseries.h" #include "drilldownchart.h" -QTCOMMERCIALCHART_USE_NAMESPACE +QT_CHARTS_USE_NAMESPACE int main(int argc, char *argv[]) { diff --git a/examples/stackedbarchartdrilldown/stackedbarchartdrilldown.pro b/examples/charts/stackedbarchartdrilldown/stackedbarchartdrilldown.pro index c10066f4..c10066f4 100644 --- a/examples/stackedbarchartdrilldown/stackedbarchartdrilldown.pro +++ b/examples/charts/stackedbarchartdrilldown/stackedbarchartdrilldown.pro diff --git a/examples/temperaturerecords/main.cpp b/examples/charts/temperaturerecords/main.cpp index 97ddfde5..24caec8e 100644 --- a/examples/temperaturerecords/main.cpp +++ b/examples/charts/temperaturerecords/main.cpp @@ -27,7 +27,7 @@ #include <QBarCategoryAxis> #include <QStackedBarSeries> -QTCOMMERCIALCHART_USE_NAMESPACE +QT_CHARTS_USE_NAMESPACE int main(int argc, char *argv[]) { diff --git a/examples/temperaturerecords/temperaturerecords.pro b/examples/charts/temperaturerecords/temperaturerecords.pro index e2eb6be3..e2eb6be3 100644 --- a/examples/temperaturerecords/temperaturerecords.pro +++ b/examples/charts/temperaturerecords/temperaturerecords.pro diff --git a/examples/zoomlinechart/chart.cpp b/examples/charts/zoomlinechart/chart.cpp index 890c6c03..890c6c03 100644 --- a/examples/zoomlinechart/chart.cpp +++ b/examples/charts/zoomlinechart/chart.cpp diff --git a/examples/zoomlinechart/chart.h b/examples/charts/zoomlinechart/chart.h index 4dea7c79..a0ebb223 100644 --- a/examples/zoomlinechart/chart.h +++ b/examples/charts/zoomlinechart/chart.h @@ -25,7 +25,7 @@ class QGestureEvent; -QTCOMMERCIALCHART_USE_NAMESPACE +QT_CHARTS_USE_NAMESPACE //![1] class Chart : public QChart diff --git a/examples/zoomlinechart/chartview.cpp b/examples/charts/zoomlinechart/chartview.cpp index 64369c62..64369c62 100644 --- a/examples/zoomlinechart/chartview.cpp +++ b/examples/charts/zoomlinechart/chartview.cpp diff --git a/examples/zoomlinechart/chartview.h b/examples/charts/zoomlinechart/chartview.h index 911a4de4..3ad7c85e 100644 --- a/examples/zoomlinechart/chartview.h +++ b/examples/charts/zoomlinechart/chartview.h @@ -24,7 +24,7 @@ #include <QChartView> #include <QRubberBand> -QTCOMMERCIALCHART_USE_NAMESPACE +QT_CHARTS_USE_NAMESPACE //![1] class ChartView : public QChartView diff --git a/examples/zoomlinechart/main.cpp b/examples/charts/zoomlinechart/main.cpp index 5569c0c9..7dd5865a 100644 --- a/examples/zoomlinechart/main.cpp +++ b/examples/charts/zoomlinechart/main.cpp @@ -26,7 +26,7 @@ #include <QLineSeries> #include <QValueAxis> -QTCOMMERCIALCHART_USE_NAMESPACE +QT_CHARTS_USE_NAMESPACE int main(int argc, char *argv[]) { diff --git a/examples/zoomlinechart/zoomlinechart.pro b/examples/charts/zoomlinechart/zoomlinechart.pro index c98161b2..c98161b2 100644 --- a/examples/zoomlinechart/zoomlinechart.pro +++ b/examples/charts/zoomlinechart/zoomlinechart.pro diff --git a/examples/examples.pri b/examples/examples.pri deleted file mode 100644 index ea89d8b8..00000000 --- a/examples/examples.pri +++ /dev/null @@ -1,33 +0,0 @@ -!include( ../config.pri ) { - error( "Couldn't find the config.pri file!" ) -} - -DESTDIR = $$CHART_BUILD_BIN_DIR -!ios { -OBJECTS_DIR = $$CHART_BUILD_DIR/examples/$$TARGET -MOC_DIR = $$CHART_BUILD_DIR/examples/$$TARGET -UI_DIR = $$CHART_BUILD_DIR/examples/$$TARGET -RCC_DIR = $$CHART_BUILD_DIR/examples/$$TARGET -} -TEMPLATE = app -QT += core gui -greaterThan(QT_MAJOR_VERSION, 4): QT += widgets - -# staticlib config causes problems when building executables -staticlib: CONFIG-=staticlib - -android { - # Workaround to fix android deployment, which seems to always look for target in - # OUT_PWD instead of DESTDIR. - COPY_PARAMETERS = "$$CHART_BUILD_BIN_DIR/lib$${TARGET}.so $$OUT_PWD/lib$${TARGET}.so" - contains(QMAKE_HOST.os, Windows): COPY_PARAMETERS = $$replace(COPY_PARAMETERS, "/","\\") - QMAKE_POST_LINK += $$QMAKE_COPY $$COPY_PARAMETERS - - contains(TARGET, qml.*) { - charts_qmldir.files = $$CHART_BUILD_QML_PLUGIN_DIR/qmldir - charts_qmldir.path = /assets/imports/QtCommercial/Chart - charts_qmlplugin.files = $$CHART_BUILD_QML_PLUGIN_DIR/libqtcommercialchartqml.so - charts_qmlplugin.path = /libs/$$ANDROID_TARGET_ARCH - INSTALLS += charts_qmldir charts_qmlplugin - } -} diff --git a/examples/examples.pro b/examples/examples.pro index 9985e63b..fadcde2f 100644 --- a/examples/examples.pro +++ b/examples/examples.pro @@ -1,45 +1,2 @@ -CURRENTLY_BUILDING_COMPONENTS = "examples" -!include( ../config.pri ) { - error( "Couldn't find the config.pri file!" ) -} - TEMPLATE = subdirs -SUBDIRS += \ - areachart \ - customchart \ - linechart \ - percentbarchart \ - piechart \ - piechartdrilldown \ - scatterchart \ - scatterinteractions \ - splinechart \ - stackedbarchart \ - stackedbarchartdrilldown \ - zoomlinechart \ - modeldata \ - barchart \ - boxplotchart \ - legend \ - barmodelmapper \ - lineandbar \ - horizontalbarchart \ - horizontalstackedbarchart \ - horizontalpercentbarchart \ - donutbreakdown \ - temperaturerecords \ - donutchart \ - multiaxis \ - legendmarkers \ - logvalueaxis \ - polarchart - -!contains(QT_VERSION, ^5\\..*\\..*$)|qtHaveModule(declarative) { - SUBDIRS += qmlboxplot \ - qmlpiechart -} - -!linux-arm*: { -SUBDIRS += \ - datetimeaxis -} +SUBDIRS += charts diff --git a/examples/qmlboxplot/main.cpp b/examples/qmlboxplot/main.cpp deleted file mode 100644 index 0ba758b4..00000000 --- a/examples/qmlboxplot/main.cpp +++ /dev/null @@ -1,43 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 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 Enterprise Charts Add-on. -** -** $QT_BEGIN_LICENSE$ -** Licensees holding valid Qt Enterprise licenses may use this file in -** accordance with the Qt Enterprise 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 <QApplication> -#include <QtDeclarative/QDeclarativeEngine> -#include <QDir> -#include "qmlapplicationviewer.h" - -Q_DECL_EXPORT int main(int argc, char *argv[]) -{ - QScopedPointer<QApplication> app(createApplication(argc, argv)); - QScopedPointer<QmlApplicationViewer> viewer(QmlApplicationViewer::create()); -#ifdef Q_OS_ANDROID - viewer->addImportPath(QString::fromLatin1("assets:/imports")); - viewer->engine()->addPluginPath(QString::fromLatin1("%1/../%2").arg(QDir::homePath(), QString::fromLatin1("lib"))); -#else - viewer->addImportPath(QString::fromLatin1("%1/%2").arg(QCoreApplication::applicationDirPath(), QString::fromLatin1("imports"))); -#endif - - // // viewer->setOrientation(QmlApplicationViewer::ScreenOrientationAuto); - viewer->setSource(QUrl("qrc:/qml/qmlboxplot/main.qml")); - viewer->setRenderHint(QPainter::Antialiasing, true); - viewer->showExpanded(); - - return app->exec(); -} diff --git a/examples/qmlboxplot/qmlapplicationviewer/qmlapplicationviewer.cpp b/examples/qmlboxplot/qmlapplicationviewer/qmlapplicationviewer.cpp deleted file mode 100644 index cb227056..00000000 --- a/examples/qmlboxplot/qmlapplicationviewer/qmlapplicationviewer.cpp +++ /dev/null @@ -1,177 +0,0 @@ -// checksum 0xaa72 version 0x90018 -/* - This file was generated by the Qt Quick Application wizard of Qt Creator. - QmlApplicationViewer is a convenience class containing mobile device specific - code such as screen orientation handling. Also QML paths and debugging are - handled here. - It is recommended not to modify this file, since newer versions of Qt Creator - may offer an updated version of it. -*/ - -#include "qmlapplicationviewer.h" - -#include <QDir> -#include <QFileInfo> -#include <QApplication> -#include <QDeclarativeComponent> -#include <QDeclarativeEngine> -#include <QDeclarativeContext> - -#include <qplatformdefs.h> // MEEGO_EDITION_HARMATTAN - -#ifdef HARMATTAN_BOOSTER -#include <MDeclarativeCache> -#endif - -#if defined(QMLJSDEBUGGER) && QT_VERSION < 0x040800 - -#include <qt_private/qdeclarativedebughelper_p.h> - -#if !defined(NO_JSDEBUGGER) -#include <jsdebuggeragent.h> -#endif -#if !defined(NO_QMLOBSERVER) -#include <qdeclarativeviewobserver.h> -#endif - -// Enable debugging before any QDeclarativeEngine is created -struct QmlJsDebuggingEnabler -{ - QmlJsDebuggingEnabler() - { - QDeclarativeDebugHelper::enableDebugging(); - } -}; - -// Execute code in constructor before first QDeclarativeEngine is instantiated -static QmlJsDebuggingEnabler enableDebuggingHelper; - -#endif // QMLJSDEBUGGER - -class QmlApplicationViewerPrivate -{ - QString mainQmlFile; - friend class QmlApplicationViewer; - static QString adjustPath(const QString &path); -}; - -QString QmlApplicationViewerPrivate::adjustPath(const QString &path) -{ -#ifdef Q_OS_MAC - if (!QDir::isAbsolutePath(path)) - return QString::fromLatin1("%1/../Resources/%2") - .arg(QCoreApplication::applicationDirPath(), path); -#elif defined(Q_OS_BLACKBERRY) - if (!QDir::isAbsolutePath(path)) - return QString::fromLatin1("app/native/%1").arg(path); -#elif !defined(Q_OS_ANDROID) - QString pathInInstallDir = - QString::fromLatin1("%1/../%2").arg(QCoreApplication::applicationDirPath(), path); - if (QFileInfo(pathInInstallDir).exists()) - return pathInInstallDir; - pathInInstallDir = - QString::fromLatin1("%1/%2").arg(QCoreApplication::applicationDirPath(), path); - if (QFileInfo(pathInInstallDir).exists()) - return pathInInstallDir; -#endif - return path; -} - -QmlApplicationViewer::QmlApplicationViewer(QWidget *parent) - : QDeclarativeView(parent) - , d(new QmlApplicationViewerPrivate()) -{ - connect(engine(), SIGNAL(quit()), SLOT(close())); - setResizeMode(QDeclarativeView::SizeRootObjectToView); - - // Qt versions prior to 4.8.0 don't have QML/JS debugging services built in -#if defined(QMLJSDEBUGGER) && QT_VERSION < 0x040800 -#if !defined(NO_JSDEBUGGER) - new QmlJSDebugger::JSDebuggerAgent(engine()); -#endif -#if !defined(NO_QMLOBSERVER) - new QmlJSDebugger::QDeclarativeViewObserver(this, this); -#endif -#endif -} - -QmlApplicationViewer::~QmlApplicationViewer() -{ - delete d; -} - -QmlApplicationViewer *QmlApplicationViewer::create() -{ - return new QmlApplicationViewer(); -} - -void QmlApplicationViewer::setMainQmlFile(const QString &file) -{ - d->mainQmlFile = QmlApplicationViewerPrivate::adjustPath(file); -#ifdef Q_OS_ANDROID - setSource(QUrl(QLatin1String("assets:/")+d->mainQmlFile)); -#else - setSource(QUrl::fromLocalFile(d->mainQmlFile)); -#endif -} - -void QmlApplicationViewer::addImportPath(const QString &path) -{ - engine()->addImportPath(QmlApplicationViewerPrivate::adjustPath(path)); -} - -void QmlApplicationViewer::setOrientation(ScreenOrientation orientation) -{ -#if QT_VERSION < 0x050000 - Qt::WidgetAttribute attribute; - switch (orientation) { -#if QT_VERSION < 0x040702 - // Qt < 4.7.2 does not yet have the Qt::WA_*Orientation attributes - case ScreenOrientationLockPortrait: - attribute = static_cast<Qt::WidgetAttribute>(128); - break; - case ScreenOrientationLockLandscape: - attribute = static_cast<Qt::WidgetAttribute>(129); - break; - default: - case ScreenOrientationAuto: - attribute = static_cast<Qt::WidgetAttribute>(130); - break; -#else // QT_VERSION < 0x040702 - case ScreenOrientationLockPortrait: - attribute = Qt::WA_LockPortraitOrientation; - break; - case ScreenOrientationLockLandscape: - attribute = Qt::WA_LockLandscapeOrientation; - break; - default: - case ScreenOrientationAuto: - attribute = Qt::WA_AutoOrientation; - break; -#endif // QT_VERSION < 0x040702 - }; - setAttribute(attribute, true); -#else // QT_VERSION < 0x050000 - Q_UNUSED(orientation) -#endif // QT_VERSION < 0x050000 -} - -void QmlApplicationViewer::showExpanded() -{ -#if defined(MEEGO_EDITION_HARMATTAN) || defined(Q_WS_SIMULATOR) - showFullScreen(); -#elif defined(Q_WS_MAEMO_5) || defined(Q_OS_QNX) - showMaximized(); -#else - show(); -#endif -} - -QApplication *createApplication(int &argc, char **argv) -{ -#ifdef HARMATTAN_BOOSTER - return MDeclarativeCache::qApplication(argc, argv); -#else - return new QApplication(argc, argv); -#endif -} diff --git a/examples/qmlboxplot/qmlapplicationviewer/qmlapplicationviewer.h b/examples/qmlboxplot/qmlapplicationviewer/qmlapplicationviewer.h deleted file mode 100644 index adcb232f..00000000 --- a/examples/qmlboxplot/qmlapplicationviewer/qmlapplicationviewer.h +++ /dev/null @@ -1,46 +0,0 @@ -// checksum 0xc67a version 0x90018 -/* - This file was generated by the Qt Quick Application wizard of Qt Creator. - QmlApplicationViewer is a convenience class containing mobile device specific - code such as screen orientation handling. Also QML paths and debugging are - handled here. - It is recommended not to modify this file, since newer versions of Qt Creator - may offer an updated version of it. -*/ - -#ifndef QMLAPPLICATIONVIEWER_H -#define QMLAPPLICATIONVIEWER_H - -#include <QDeclarativeView> - -class QmlApplicationViewer : public QDeclarativeView -{ - Q_OBJECT - -public: - enum ScreenOrientation { - ScreenOrientationLockPortrait, - ScreenOrientationLockLandscape, - ScreenOrientationAuto - }; - - explicit QmlApplicationViewer(QWidget *parent = 0); - virtual ~QmlApplicationViewer(); - - static QmlApplicationViewer *create(); - - void setMainQmlFile(const QString &file); - void addImportPath(const QString &path); - - // Note that this will only have an effect on Fremantle. - void setOrientation(ScreenOrientation orientation); - - void showExpanded(); - -private: - class QmlApplicationViewerPrivate *d; -}; - -QApplication *createApplication(int &argc, char **argv); - -#endif // QMLAPPLICATIONVIEWER_H diff --git a/examples/qmlboxplot/qmlapplicationviewer/qmlapplicationviewer.pri b/examples/qmlboxplot/qmlapplicationviewer/qmlapplicationviewer.pri deleted file mode 100644 index 567c6dc6..00000000 --- a/examples/qmlboxplot/qmlapplicationviewer/qmlapplicationviewer.pri +++ /dev/null @@ -1,13 +0,0 @@ -QT += declarative - -SOURCES += $$PWD/qmlapplicationviewer.cpp -HEADERS += $$PWD/qmlapplicationviewer.h -INCLUDEPATH += $$PWD - -# Include JS debugger library if QMLJSDEBUGGER_PATH is set -!isEmpty(QMLJSDEBUGGER_PATH) { - include($$QMLJSDEBUGGER_PATH/qmljsdebugger-lib.pri) -} else { - DEFINES -= QMLJSDEBUGGER -} - diff --git a/examples/qmlpiechart/main.cpp b/examples/qmlpiechart/main.cpp deleted file mode 100644 index b12a10b2..00000000 --- a/examples/qmlpiechart/main.cpp +++ /dev/null @@ -1,43 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 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 Enterprise Charts Add-on. -** -** $QT_BEGIN_LICENSE$ -** Licensees holding valid Qt Enterprise licenses may use this file in -** accordance with the Qt Enterprise 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 <QApplication> -#include <QtDeclarative/QDeclarativeEngine> -#include <QDir> -#include "qmlapplicationviewer.h" - -Q_DECL_EXPORT int main(int argc, char *argv[]) -{ - QScopedPointer<QApplication> app(createApplication(argc, argv)); - QScopedPointer<QmlApplicationViewer> viewer(QmlApplicationViewer::create()); -#ifdef Q_OS_ANDROID - viewer->addImportPath(QString::fromLatin1("assets:/imports")); - viewer->engine()->addPluginPath(QString::fromLatin1("%1/../%2").arg(QDir::homePath(), QString::fromLatin1("lib"))); -#else - viewer->addImportPath(QString::fromLatin1("%1/%2").arg(QCoreApplication::applicationDirPath(), QString::fromLatin1("imports"))); -#endif - - // // viewer->setOrientation(QmlApplicationViewer::ScreenOrientationAuto); - viewer->setSource(QUrl("qrc:/qml/qmlpiechart/main.qml")); - viewer->setRenderHint(QPainter::Antialiasing, true); - viewer->showExpanded(); - - return app->exec(); -} diff --git a/examples/qmlpiechart/qmlapplicationviewer/qmlapplicationviewer.cpp b/examples/qmlpiechart/qmlapplicationviewer/qmlapplicationviewer.cpp deleted file mode 100644 index cb227056..00000000 --- a/examples/qmlpiechart/qmlapplicationviewer/qmlapplicationviewer.cpp +++ /dev/null @@ -1,177 +0,0 @@ -// checksum 0xaa72 version 0x90018 -/* - This file was generated by the Qt Quick Application wizard of Qt Creator. - QmlApplicationViewer is a convenience class containing mobile device specific - code such as screen orientation handling. Also QML paths and debugging are - handled here. - It is recommended not to modify this file, since newer versions of Qt Creator - may offer an updated version of it. -*/ - -#include "qmlapplicationviewer.h" - -#include <QDir> -#include <QFileInfo> -#include <QApplication> -#include <QDeclarativeComponent> -#include <QDeclarativeEngine> -#include <QDeclarativeContext> - -#include <qplatformdefs.h> // MEEGO_EDITION_HARMATTAN - -#ifdef HARMATTAN_BOOSTER -#include <MDeclarativeCache> -#endif - -#if defined(QMLJSDEBUGGER) && QT_VERSION < 0x040800 - -#include <qt_private/qdeclarativedebughelper_p.h> - -#if !defined(NO_JSDEBUGGER) -#include <jsdebuggeragent.h> -#endif -#if !defined(NO_QMLOBSERVER) -#include <qdeclarativeviewobserver.h> -#endif - -// Enable debugging before any QDeclarativeEngine is created -struct QmlJsDebuggingEnabler -{ - QmlJsDebuggingEnabler() - { - QDeclarativeDebugHelper::enableDebugging(); - } -}; - -// Execute code in constructor before first QDeclarativeEngine is instantiated -static QmlJsDebuggingEnabler enableDebuggingHelper; - -#endif // QMLJSDEBUGGER - -class QmlApplicationViewerPrivate -{ - QString mainQmlFile; - friend class QmlApplicationViewer; - static QString adjustPath(const QString &path); -}; - -QString QmlApplicationViewerPrivate::adjustPath(const QString &path) -{ -#ifdef Q_OS_MAC - if (!QDir::isAbsolutePath(path)) - return QString::fromLatin1("%1/../Resources/%2") - .arg(QCoreApplication::applicationDirPath(), path); -#elif defined(Q_OS_BLACKBERRY) - if (!QDir::isAbsolutePath(path)) - return QString::fromLatin1("app/native/%1").arg(path); -#elif !defined(Q_OS_ANDROID) - QString pathInInstallDir = - QString::fromLatin1("%1/../%2").arg(QCoreApplication::applicationDirPath(), path); - if (QFileInfo(pathInInstallDir).exists()) - return pathInInstallDir; - pathInInstallDir = - QString::fromLatin1("%1/%2").arg(QCoreApplication::applicationDirPath(), path); - if (QFileInfo(pathInInstallDir).exists()) - return pathInInstallDir; -#endif - return path; -} - -QmlApplicationViewer::QmlApplicationViewer(QWidget *parent) - : QDeclarativeView(parent) - , d(new QmlApplicationViewerPrivate()) -{ - connect(engine(), SIGNAL(quit()), SLOT(close())); - setResizeMode(QDeclarativeView::SizeRootObjectToView); - - // Qt versions prior to 4.8.0 don't have QML/JS debugging services built in -#if defined(QMLJSDEBUGGER) && QT_VERSION < 0x040800 -#if !defined(NO_JSDEBUGGER) - new QmlJSDebugger::JSDebuggerAgent(engine()); -#endif -#if !defined(NO_QMLOBSERVER) - new QmlJSDebugger::QDeclarativeViewObserver(this, this); -#endif -#endif -} - -QmlApplicationViewer::~QmlApplicationViewer() -{ - delete d; -} - -QmlApplicationViewer *QmlApplicationViewer::create() -{ - return new QmlApplicationViewer(); -} - -void QmlApplicationViewer::setMainQmlFile(const QString &file) -{ - d->mainQmlFile = QmlApplicationViewerPrivate::adjustPath(file); -#ifdef Q_OS_ANDROID - setSource(QUrl(QLatin1String("assets:/")+d->mainQmlFile)); -#else - setSource(QUrl::fromLocalFile(d->mainQmlFile)); -#endif -} - -void QmlApplicationViewer::addImportPath(const QString &path) -{ - engine()->addImportPath(QmlApplicationViewerPrivate::adjustPath(path)); -} - -void QmlApplicationViewer::setOrientation(ScreenOrientation orientation) -{ -#if QT_VERSION < 0x050000 - Qt::WidgetAttribute attribute; - switch (orientation) { -#if QT_VERSION < 0x040702 - // Qt < 4.7.2 does not yet have the Qt::WA_*Orientation attributes - case ScreenOrientationLockPortrait: - attribute = static_cast<Qt::WidgetAttribute>(128); - break; - case ScreenOrientationLockLandscape: - attribute = static_cast<Qt::WidgetAttribute>(129); - break; - default: - case ScreenOrientationAuto: - attribute = static_cast<Qt::WidgetAttribute>(130); - break; -#else // QT_VERSION < 0x040702 - case ScreenOrientationLockPortrait: - attribute = Qt::WA_LockPortraitOrientation; - break; - case ScreenOrientationLockLandscape: - attribute = Qt::WA_LockLandscapeOrientation; - break; - default: - case ScreenOrientationAuto: - attribute = Qt::WA_AutoOrientation; - break; -#endif // QT_VERSION < 0x040702 - }; - setAttribute(attribute, true); -#else // QT_VERSION < 0x050000 - Q_UNUSED(orientation) -#endif // QT_VERSION < 0x050000 -} - -void QmlApplicationViewer::showExpanded() -{ -#if defined(MEEGO_EDITION_HARMATTAN) || defined(Q_WS_SIMULATOR) - showFullScreen(); -#elif defined(Q_WS_MAEMO_5) || defined(Q_OS_QNX) - showMaximized(); -#else - show(); -#endif -} - -QApplication *createApplication(int &argc, char **argv) -{ -#ifdef HARMATTAN_BOOSTER - return MDeclarativeCache::qApplication(argc, argv); -#else - return new QApplication(argc, argv); -#endif -} diff --git a/examples/qmlpiechart/qmlapplicationviewer/qmlapplicationviewer.h b/examples/qmlpiechart/qmlapplicationviewer/qmlapplicationviewer.h deleted file mode 100644 index adcb232f..00000000 --- a/examples/qmlpiechart/qmlapplicationviewer/qmlapplicationviewer.h +++ /dev/null @@ -1,46 +0,0 @@ -// checksum 0xc67a version 0x90018 -/* - This file was generated by the Qt Quick Application wizard of Qt Creator. - QmlApplicationViewer is a convenience class containing mobile device specific - code such as screen orientation handling. Also QML paths and debugging are - handled here. - It is recommended not to modify this file, since newer versions of Qt Creator - may offer an updated version of it. -*/ - -#ifndef QMLAPPLICATIONVIEWER_H -#define QMLAPPLICATIONVIEWER_H - -#include <QDeclarativeView> - -class QmlApplicationViewer : public QDeclarativeView -{ - Q_OBJECT - -public: - enum ScreenOrientation { - ScreenOrientationLockPortrait, - ScreenOrientationLockLandscape, - ScreenOrientationAuto - }; - - explicit QmlApplicationViewer(QWidget *parent = 0); - virtual ~QmlApplicationViewer(); - - static QmlApplicationViewer *create(); - - void setMainQmlFile(const QString &file); - void addImportPath(const QString &path); - - // Note that this will only have an effect on Fremantle. - void setOrientation(ScreenOrientation orientation); - - void showExpanded(); - -private: - class QmlApplicationViewerPrivate *d; -}; - -QApplication *createApplication(int &argc, char **argv); - -#endif // QMLAPPLICATIONVIEWER_H diff --git a/examples/qmlpiechart/qmlapplicationviewer/qmlapplicationviewer.pri b/examples/qmlpiechart/qmlapplicationviewer/qmlapplicationviewer.pri deleted file mode 100644 index 567c6dc6..00000000 --- a/examples/qmlpiechart/qmlapplicationviewer/qmlapplicationviewer.pri +++ /dev/null @@ -1,13 +0,0 @@ -QT += declarative - -SOURCES += $$PWD/qmlapplicationviewer.cpp -HEADERS += $$PWD/qmlapplicationviewer.h -INCLUDEPATH += $$PWD - -# Include JS debugger library if QMLJSDEBUGGER_PATH is set -!isEmpty(QMLJSDEBUGGER_PATH) { - include($$QMLJSDEBUGGER_PATH/qmljsdebugger-lib.pri) -} else { - DEFINES -= QMLJSDEBUGGER -} - |