diff options
Diffstat (limited to 'tests/manual')
143 files changed, 14172 insertions, 0 deletions
diff --git a/tests/manual/boxplottester/boxplottester.pro b/tests/manual/boxplottester/boxplottester.pro new file mode 100644 index 00000000..1a8681fe --- /dev/null +++ b/tests/manual/boxplottester/boxplottester.pro @@ -0,0 +1,18 @@ +!include( ../../tests.pri ) { + error( "Couldn't find the test.pri file!" ) +} + +TEMPLATE = app + +QT += charts +QT += core gui widgets + +SOURCES += main.cpp \ + mainwidget.cpp \ + customtablemodel.cpp \ + pentool.cpp + +HEADERS += \ + mainwidget.h \ + customtablemodel.h \ + pentool.h diff --git a/tests/manual/boxplottester/customtablemodel.cpp b/tests/manual/boxplottester/customtablemodel.cpp new file mode 100644 index 00000000..8724dd56 --- /dev/null +++ b/tests/manual/boxplottester/customtablemodel.cpp @@ -0,0 +1,147 @@ +/**************************************************************************** +** +** 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 "customtablemodel.h" +#include <QtCore/QVector> +#include <QtCore/QTime> +#include <QtCore/QRect> +#include <QtGui/QColor> + +const QString categories[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Nov", "Dec"}; + +CustomTableModel::CustomTableModel(QObject *parent) : + QAbstractTableModel(parent) +{ + m_columnCount = 6; + m_rowCount = 5; + QVector<qreal>* dataVec_Jan = new QVector<qreal>(m_rowCount); + dataVec_Jan->insert(0, 3.0); + dataVec_Jan->insert(1, 4.0); + dataVec_Jan->insert(2, 4.4); + dataVec_Jan->insert(3, 6.0); + dataVec_Jan->insert(4, 7.0); + m_data.append(dataVec_Jan); + + QVector<qreal>* dataVec_Feb = new QVector<qreal>(m_rowCount); + dataVec_Feb->insert(0, 5.0); + dataVec_Feb->insert(1, 6.0); + dataVec_Feb->insert(2, 7.5); + dataVec_Feb->insert(3, 8.0); + dataVec_Feb->insert(4, 12.0); + m_data.append(dataVec_Feb); + + QVector<qreal>* dataVec_Mar = new QVector<qreal>(m_rowCount); + dataVec_Mar->insert(0, 3.0); + dataVec_Mar->insert(1, 4.0); + dataVec_Mar->insert(2, 5.7); + dataVec_Mar->insert(3, 8.0); + dataVec_Mar->insert(4, 9.0); + m_data.append(dataVec_Mar); + + QVector<qreal>* dataVec_Apr = new QVector<qreal>(m_rowCount); + dataVec_Apr->insert(0, 5.0); + dataVec_Apr->insert(1, 6.0); + dataVec_Apr->insert(2, 6.8); + dataVec_Apr->insert(3, 7.0); + dataVec_Apr->insert(4, 8.0); + m_data.append(dataVec_Apr); + + QVector<qreal>* dataVec_May = new QVector<qreal>(m_rowCount); + dataVec_May->insert(0, 4.0); + dataVec_May->insert(1, 5.0); + dataVec_May->insert(2, 5.2); + dataVec_May->insert(3, 6.0); + dataVec_May->insert(4, 7.0); + m_data.append(dataVec_May); + + QVector<qreal>* dataVec_Jun = new QVector<qreal>(m_rowCount); + dataVec_Jun->insert(0, 4.0); + dataVec_Jun->insert(1, 7.0); + dataVec_Jun->insert(2, 8.2); + dataVec_Jun->insert(3, 9.0); + dataVec_Jun->insert(4, 10.0); + m_data.append(dataVec_Jun); +} + +CustomTableModel::~CustomTableModel() +{ + qDeleteAll(m_data); +} + +int CustomTableModel::rowCount(const QModelIndex &parent) const +{ + Q_UNUSED(parent) + return m_rowCount; +} + +int CustomTableModel::columnCount(const QModelIndex &parent) const +{ + Q_UNUSED(parent) + return m_data.count(); +} + +QVariant CustomTableModel::headerData(int section, Qt::Orientation orientation, int role) const +{ + if (role != Qt::DisplayRole) + return QVariant(); + + if (orientation == Qt::Horizontal) + return categories[section]; + else + return QString("%1").arg(section + 1); +} + +QVariant CustomTableModel::data(const QModelIndex &index, int role) const +{ + if (role == Qt::DisplayRole) { + return m_data[index.column()]->at(index.row()); + } else if (role == Qt::EditRole) { + return m_data[index.column()]->at(index.row()); + } else if (role == Qt::BackgroundRole) { + QRect rect; + foreach (rect, m_mapping) + if (rect.contains(index.column(), index.row())) + return QColor(m_mapping.key(rect)); + + // cell not mapped return white color + return QColor(Qt::white); + } + return QVariant(); +} + +bool CustomTableModel::setData(const QModelIndex &index, const QVariant &value, int role) +{ + if (index.isValid() && role == Qt::EditRole) { + m_data[index.column()]->replace(index.row(), value.toDouble()); + emit dataChanged(index, index); + return true; + } + return false; +} + +Qt::ItemFlags CustomTableModel::flags(const QModelIndex &index) const +{ + return QAbstractItemModel::flags(index) | Qt::ItemIsEditable; +} + +void CustomTableModel::addMapping(QString color, QRect area) +{ + m_mapping.insertMulti(color, area); +} diff --git a/tests/manual/boxplottester/customtablemodel.h b/tests/manual/boxplottester/customtablemodel.h new file mode 100644 index 00000000..0f1fb9df --- /dev/null +++ b/tests/manual/boxplottester/customtablemodel.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 CUSTOMTABLEMODEL_H +#define CUSTOMTABLEMODEL_H + +#include <QtCore/QAbstractTableModel> +#include <QtCore/QHash> +#include <QtCore/QRect> + +class CustomTableModel : public QAbstractTableModel +{ + Q_OBJECT +public: + explicit CustomTableModel(QObject *parent = 0); + virtual ~CustomTableModel(); + + int rowCount(const QModelIndex &parent = QModelIndex()) const; + int columnCount(const QModelIndex &parent = QModelIndex()) const; + QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const; + QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; + bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole); + Qt::ItemFlags flags(const QModelIndex &index) const; + + void addMapping(QString color, QRect area); + void clearMapping() { m_mapping.clear(); } + +private: + QList<QVector<qreal> *> m_data; + QHash<QString, QRect> m_mapping; + int m_columnCount; + int m_rowCount; +}; + +#endif // CUSTOMTABLEMODEL_H diff --git a/tests/manual/boxplottester/main.cpp b/tests/manual/boxplottester/main.cpp new file mode 100644 index 00000000..6d136669 --- /dev/null +++ b/tests/manual/boxplottester/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 <QtCore/QtGlobal> +#include <QtWidgets/QApplication> +#include "mainwidget.h" + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + + MainWidget w; + w.resize(1000,600); + w.show(); + + return a.exec(); +} diff --git a/tests/manual/boxplottester/mainwidget.cpp b/tests/manual/boxplottester/mainwidget.cpp new file mode 100644 index 00000000..784512d3 --- /dev/null +++ b/tests/manual/boxplottester/mainwidget.cpp @@ -0,0 +1,482 @@ +/**************************************************************************** +** +** 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 "customtablemodel.h" +#include "pentool.h" +#include <QtCharts/QVBoxPlotModelMapper> +#include <QtWidgets/QTableView> +#include <QtWidgets/QHeaderView> +#include <QtCharts/QChartView> +#include <QtCharts/QBoxPlotSeries> +#include <QtCharts/QBoxSet> +#include <QtCharts/QLegend> +#include <QtCharts/QBarCategoryAxis> +#include <QtGui/QBrush> +#include <QtGui/QColor> +#include <QtWidgets/QPushButton> +#include <QtWidgets/QComboBox> +#include <QtWidgets/QSpinBox> +#include <QtWidgets/QCheckBox> +#include <QtWidgets/QGridLayout> +#include <QtWidgets/QHBoxLayout> +#include <QtWidgets/QLabel> +#include <QtWidgets/QSpacerItem> +#include <QtWidgets/QMessageBox> +#include <cmath> +#include <QtCore/QDebug> +#include <QtGui/QStandardItemModel> +#include <QtCharts/QBarCategoryAxis> +#include <QtCharts/QLogValueAxis> + +QT_CHARTS_USE_NAMESPACE + +static const QString allCategories[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}; +static const int maxCategories = 12; + +MainWidget::MainWidget(QWidget *parent) : + QWidget(parent), + m_chart(0), + m_axis(0), + m_rowPos(0), + m_seriesCount(0) +{ + m_chart = new QChart(); + + m_penTool = new PenTool("Whiskers pen", this); + + // Grid layout for the controls for configuring the chart widget + QGridLayout *grid = new QGridLayout(); + + // Create add a series button + QPushButton *addSeriesButton = new QPushButton("Add a series"); + connect(addSeriesButton, SIGNAL(clicked()), this, SLOT(addSeries())); + grid->addWidget(addSeriesButton, m_rowPos++, 1); + + // Create remove a series button + QPushButton *removeSeriesButton = new QPushButton("Remove a series"); + connect(removeSeriesButton, SIGNAL(clicked()), this, SLOT(removeSeries())); + grid->addWidget(removeSeriesButton, m_rowPos++, 1); + + // Create add a single box button + QPushButton *addBoxButton = new QPushButton("Add a box"); + connect(addBoxButton, SIGNAL(clicked()), this, SLOT(addBox())); + grid->addWidget(addBoxButton, m_rowPos++, 1); + + // Create insert a box button + QPushButton *insertBoxButton = new QPushButton("Insert a box"); + connect(insertBoxButton, SIGNAL(clicked()), this, SLOT(insertBox())); + grid->addWidget(insertBoxButton, m_rowPos++, 1); + + // Create add a single box button + QPushButton *removeBoxButton = new QPushButton("Remove a box"); + connect(removeBoxButton, SIGNAL(clicked()), this, SLOT(removeBox())); + grid->addWidget(removeBoxButton, m_rowPos++, 1); + + // Create clear button + QPushButton *clearButton = new QPushButton("Clear"); + connect(clearButton, SIGNAL(clicked()), this, SLOT(clear())); + grid->addWidget(clearButton, m_rowPos++, 1); + + // Create clear button + QPushButton *clearBoxButton = new QPushButton("ClearBox"); + connect(clearBoxButton, SIGNAL(clicked()), this, SLOT(clearBox())); + grid->addWidget(clearBoxButton, m_rowPos++, 1); + + // Create set brush button + QPushButton *setBrushButton = new QPushButton("Set brush"); + connect(setBrushButton, SIGNAL(clicked()), this, SLOT(setBrush())); + grid->addWidget(setBrushButton, m_rowPos++, 1); + + // Create set whiskers pen button + QPushButton *setWhiskersButton = new QPushButton("Whiskers pen"); + connect(setWhiskersButton, SIGNAL(clicked()), m_penTool, SLOT(show())); + connect(m_penTool, SIGNAL(changed()), this, SLOT(changePen())); + grid->addWidget(setWhiskersButton, m_rowPos++, 1); + + // Box width setting + m_boxWidthSB = new QDoubleSpinBox(); + m_boxWidthSB->setMinimum(-1.0); + m_boxWidthSB->setMaximum(2.0); + m_boxWidthSB->setSingleStep(0.1); + m_boxWidthSB->setValue(0.5); + grid->addWidget(new QLabel("Box width:"), m_rowPos, 0); + grid->addWidget(m_boxWidthSB, m_rowPos++, 1); + connect(m_boxWidthSB, SIGNAL(valueChanged(double)), this, SLOT(setBoxWidth(double))); + + initThemeCombo(grid); + initCheckboxes(grid); + + QTableView *tableView = new QTableView; + m_model = new CustomTableModel(tableView); + tableView->setModel(m_model); + tableView->setMaximumWidth(200); + grid->addWidget(tableView, m_rowPos++, 0, 3, 2, Qt::AlignLeft); + tableView->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch); + tableView->verticalHeader()->setSectionResizeMode(QHeaderView::Stretch); + + // add row with empty label to make all the other rows static + grid->addWidget(new QLabel(""), grid->rowCount(), 0); + grid->setRowStretch(grid->rowCount() - 1, 1); + + // Create chart view with the chart + m_chartView = new QChartView(m_chart, this); + + // As a default antialiasing is off + m_chartView->setRenderHint(QPainter::Antialiasing, false); + + // Another grid layout as a main layout + QGridLayout *mainLayout = new QGridLayout(); + mainLayout->addLayout(grid, 0, 0); + mainLayout->addWidget(m_chartView, 0, 1, 3, 1); + setLayout(mainLayout); + + legendToggled(false); + animationToggled(false); +} + +// Combo box for selecting theme +void MainWidget::initThemeCombo(QGridLayout *grid) +{ + QComboBox *chartTheme = new QComboBox(); + chartTheme->addItem("Default"); + chartTheme->addItem("Light"); + chartTheme->addItem("Blue Cerulean"); + chartTheme->addItem("Dark"); + chartTheme->addItem("Brown Sand"); + chartTheme->addItem("Blue NCS"); + chartTheme->addItem("High Contrast"); + chartTheme->addItem("Blue Icy"); + chartTheme->addItem("Qt"); + connect(chartTheme, SIGNAL(currentIndexChanged(int)), + this, SLOT(changeChartTheme(int))); + grid->addWidget(new QLabel("Chart theme:"), m_rowPos, 0); + grid->addWidget(chartTheme, m_rowPos++, 1); +} + +// Different check boxes for customizing chart +void MainWidget::initCheckboxes(QGridLayout *grid) +{ + QCheckBox *animationCheckBox = new QCheckBox("Animation"); + connect(animationCheckBox, SIGNAL(toggled(bool)), this, SLOT(animationToggled(bool))); + animationCheckBox->setChecked(false); + grid->addWidget(animationCheckBox, m_rowPos++, 0); + + QCheckBox *legendCheckBox = new QCheckBox("Legend"); + connect(legendCheckBox, SIGNAL(toggled(bool)), this, SLOT(legendToggled(bool))); + legendCheckBox->setChecked(false); + grid->addWidget(legendCheckBox, m_rowPos++, 0); + + QCheckBox *titleCheckBox = new QCheckBox("Title"); + connect(titleCheckBox, SIGNAL(toggled(bool)), this, SLOT(titleToggled(bool))); + titleCheckBox->setChecked(false); + grid->addWidget(titleCheckBox, m_rowPos++, 0); + + QCheckBox *antialiasingCheckBox = new QCheckBox("Antialiasing"); + connect(antialiasingCheckBox, SIGNAL(toggled(bool)), this, SLOT(antialiasingToggled(bool))); + antialiasingCheckBox->setChecked(false); + grid->addWidget(antialiasingCheckBox, m_rowPos++, 0); + + QCheckBox *modelMapperCheckBox = new QCheckBox("Use model mapper"); + connect(modelMapperCheckBox, SIGNAL(toggled(bool)), this, SLOT(modelMapperToggled(bool))); + modelMapperCheckBox->setChecked(false); + grid->addWidget(modelMapperCheckBox, m_rowPos++, 0); + + m_boxOutlined = new QCheckBox("Box outlined"); + connect(m_boxOutlined, SIGNAL(toggled(bool)), this, SLOT(boxOutlineToggled(bool))); + m_boxOutlined->setChecked(true); + grid->addWidget(m_boxOutlined, m_rowPos++, 0); +} + +void MainWidget::updateAxis(int categoryCount) +{ + if (!m_axis) { + m_chart->createDefaultAxes(); + m_axis = new QBarCategoryAxis(); + } + QStringList categories; + for (int i = 0; i < categoryCount; i++) + categories << allCategories[i]; + m_axis->setCategories(categories); +} + +void MainWidget::addSeries() +{ + qDebug() << "BoxPlotTester::MainWidget::addSeries()"; + + if (m_seriesCount > 9) + return; + + // Initial data + QBoxSet *set0 = new QBoxSet(); + QBoxSet *set1 = new QBoxSet(); + QBoxSet *set2 = new QBoxSet(); + QBoxSet *set3 = new QBoxSet(); + QBoxSet *set4 = new QBoxSet(); + QBoxSet *set5 = new QBoxSet(); + + // low bot med top upp + *set0 << -1 << 2 << 4 << 13 << 15; + *set1 << 5 << 6 << 7.5 << 8 << 12; + *set2 << 3 << 5 << 5.7 << 8 << 9; + *set3 << 5 << 6 << 6.8 << 7 << 8; + *set4 << 4 << 5 << 5.2 << 6 << 7; + *set5 << 4 << 7 << 8.2 << 9 << 10; + + m_series[m_seriesCount] = new QBoxPlotSeries(); + m_series[m_seriesCount]->append(set0); + m_series[m_seriesCount]->append(set1); + m_series[m_seriesCount]->append(set2); + m_series[m_seriesCount]->append(set3); + m_series[m_seriesCount]->append(set4); + m_series[m_seriesCount]->append(set5); + m_series[m_seriesCount]->setName("Box & Whiskers"); + + connect(m_series[m_seriesCount], SIGNAL(clicked(QBoxSet*)), this, SLOT(boxClicked(QBoxSet*))); + connect(m_series[m_seriesCount], SIGNAL(hovered(bool, QBoxSet*)), this, SLOT(boxHovered(bool, QBoxSet*))); + connect(set1, SIGNAL(clicked()), this, SLOT(singleBoxClicked())); + connect(set2, SIGNAL(hovered(bool)), this, SLOT(singleBoxHovered(bool))); + + m_series[m_seriesCount]->setBoxOutlineVisible(m_boxOutlined->checkState()); + m_series[m_seriesCount]->setBoxWidth(m_boxWidthSB->value()); + + m_chart->addSeries(m_series[m_seriesCount]); + + updateAxis(m_series[0]->count()); + m_chart->setAxisX(m_axis, m_series[m_seriesCount]); + + m_seriesCount++; +} + +void MainWidget::removeSeries() +{ + qDebug() << "BoxPlotTester::MainWidget::removeSeries()"; + + if (m_seriesCount > 0) { + m_seriesCount--; + m_chart->removeSeries(m_series[m_seriesCount]); + delete m_series[m_seriesCount]; + m_series[m_seriesCount] = 0; + } else { + qDebug() << "Create a series first"; + } +} + +void MainWidget::addBox() +{ + qDebug() << "BoxPlotTester::MainWidget::addBox()"; + + if (m_seriesCount > 0 && m_series[0]->count() < maxCategories) { + QBoxSet *newSet = new QBoxSet(); + newSet->setValue(QBoxSet::LowerExtreme, 5.0); + newSet->setValue(QBoxSet::LowerQuartile, 6.0); + newSet->setValue(QBoxSet::Median, 6.8); + newSet->setValue(QBoxSet::UpperQuartile, 7.0); + newSet->setValue(QBoxSet::UpperExtreme, 8.0); + + updateAxis(m_series[0]->count() + 1); + + m_series[0]->append(newSet); + } +} + +void MainWidget::insertBox() +{ + qDebug() << "BoxPlotTester::MainWidget::insertBox()"; + + if (m_seriesCount > 0 && m_series[0]->count() < maxCategories) { + updateAxis(m_series[0]->count() + 1); + for (int i = 0; i < m_seriesCount; i++) { + QBoxSet *newSet = new QBoxSet(); + *newSet << 2 << 6 << 6.8 << 7 << 10; + m_series[i]->insert(1, newSet); + } + } +} + +void MainWidget::removeBox() +{ + qDebug() << "BoxPlotTester::MainWidget::removeBox"; + + if (m_seriesCount > 0) { + for (int i = 0; i < m_seriesCount; i++) { + qDebug() << "m_series[i]->count() = " << m_series[i]->count(); + if (m_series[i]->count()) { + QList<QBoxSet *> sets = m_series[i]->boxSets(); + m_series[i]->remove(sets.at(m_series[i]->count() - 1)); + } + } + + updateAxis(m_series[0]->count()); + } else { + qDebug() << "Create a series first"; + } +} + +void MainWidget::clear() +{ + qDebug() << "BoxPlotTester::MainWidget::clear"; + + if (m_seriesCount > 0) + m_series[0]->clear(); + else + qDebug() << "Create a series first"; +} + +void MainWidget::clearBox() +{ + qDebug() << "BoxPlotTester::MainWidget::clearBox"; + + if (m_seriesCount > 0) { + QList<QBoxSet *> sets = m_series[0]->boxSets(); + if (sets.count() > 1) + sets.at(1)->clear(); + else + qDebug() << "Create a series with at least two items first"; + } else { + qDebug() << "Create a series first"; + } +} + +void MainWidget::setBrush() +{ + qDebug() << "BoxPlotTester::MainWidget::setBrush"; + + if (m_seriesCount > 0) { + QList<QBoxSet *> sets = m_series[0]->boxSets(); + if (sets.count() > 1) + sets.at(1)->setBrush(QBrush(QColor(Qt::yellow))); + else + qDebug() << "Create a series with at least two items first"; + } else { + qDebug() << "Create a series first"; + } +} + +void MainWidget::animationToggled(bool enabled) +{ + qDebug() << "BoxPlotTester::Animation toggled to " << enabled; + if (enabled) + m_chart->setAnimationOptions(QChart::SeriesAnimations); + else + m_chart->setAnimationOptions(QChart::NoAnimation); +} + +void MainWidget::legendToggled(bool enabled) +{ + qDebug() << "BoxPlotTester::Legend toggled to " << enabled; + m_chart->legend()->setVisible(enabled); + if (enabled) + m_chart->legend()->setAlignment(Qt::AlignBottom); +} + +void MainWidget::titleToggled(bool enabled) +{ + qDebug() << "BoxPlotTester::Title toggled to " << enabled; + if (enabled) + m_chart->setTitle("Simple boxplotchart example"); + else + m_chart->setTitle(""); +} + +void MainWidget::antialiasingToggled(bool enabled) +{ + qDebug() << "BoxPlotTester::antialiasingToggled toggled to " << enabled; + m_chartView->setRenderHint(QPainter::Antialiasing, enabled); +} + +void MainWidget::boxOutlineToggled(bool visible) +{ + qDebug() << "BoxPlotTester::boxOutlineToggled toggled to " << visible; + for (int i = 0; i < m_seriesCount; i++) + m_series[i]->setBoxOutlineVisible(visible); +} + +void MainWidget::modelMapperToggled(bool enabled) +{ + if (enabled) { + m_series[m_seriesCount] = new QBoxPlotSeries(); + + int first = 0; + int count = 5; + QVBoxPlotModelMapper *mapper = new QVBoxPlotModelMapper(this); + mapper->setFirstBoxSetColumn(0); + mapper->setLastBoxSetColumn(5); + mapper->setFirstRow(first); + mapper->setRowCount(count); + mapper->setSeries(m_series[m_seriesCount]); + mapper->setModel(m_model); + m_chart->addSeries(m_series[m_seriesCount]); + + m_seriesCount++; + } else { + removeSeries(); + } +} + +void MainWidget::changeChartTheme(int themeIndex) +{ + qDebug() << "BoxPlotTester::changeChartTheme: " << themeIndex; + if (themeIndex == 0) + m_chart->setTheme(QChart::ChartThemeLight); + else + m_chart->setTheme((QChart::ChartTheme) (themeIndex - 1)); +} + +void MainWidget::boxClicked(QBoxSet *set) +{ + qDebug() << "boxClicked, median = " << set->at(QBoxSet::Median); +} + +void MainWidget::boxHovered(bool state, QBoxSet *set) +{ + if (state) + qDebug() << "box median " << set->at(QBoxSet::Median) << " hover started"; + else + qDebug() << "box median " << set->at(QBoxSet::Median) << " hover ended"; +} + +void MainWidget::singleBoxClicked() +{ + qDebug() << "singleBoxClicked"; +} + +void MainWidget::singleBoxHovered(bool state) +{ + if (state) + qDebug() << "single box hover started"; + else + qDebug() << "single box hover ended"; +} + +void MainWidget::changePen() +{ + qDebug() << "changePen() = " << m_penTool->pen(); + for (int i = 0; i < m_seriesCount; i++) + m_series[i]->setPen(m_penTool->pen()); +} + +void MainWidget::setBoxWidth(double width) +{ + qDebug() << "setBoxWidth to " << width; + + for (int i = 0; i < m_seriesCount; i++) + m_series[i]->setBoxWidth(qreal(width)); +} diff --git a/tests/manual/boxplottester/mainwidget.h b/tests/manual/boxplottester/mainwidget.h new file mode 100644 index 00000000..cbb2cd38 --- /dev/null +++ b/tests/manual/boxplottester/mainwidget.h @@ -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$ +** +****************************************************************************/ + +#ifndef MAINWIDGET_H +#define MAINWIDGET_H + +#include <QtCharts/QChartGlobal> +#include <QtCharts/QChart> +#include <QtCharts/QChartView> +#include <QtWidgets/QWidget> +#include <QtCharts/QBoxPlotSeries> +#include <QtCharts/QBarCategoryAxis> +#include <QtCharts/QBoxSet> +#include <QtWidgets/QCheckBox> +#include <QtWidgets/QDoubleSpinBox> + +class QGridLayout; +class CustomTableModel; +class PenTool; + +QT_CHARTS_USE_NAMESPACE + +class MainWidget : public QWidget +{ + Q_OBJECT +public: + explicit MainWidget(QWidget *parent = 0); + +signals: + +private: + void initThemeCombo(QGridLayout *grid); + void initCheckboxes(QGridLayout *grid); + void updateAxis(int categoryCount); + +private slots: + void addSeries(); + void removeSeries(); + void addBox(); + void insertBox(); + void removeBox(); + void clear(); + void clearBox(); + void setBrush(); + void animationToggled(bool enabled); + void legendToggled(bool enabled); + void titleToggled(bool enabled); + void modelMapperToggled(bool enabled); + void changeChartTheme(int themeIndex); + void boxClicked(QBoxSet *set); + void boxHovered(bool state, QBoxSet *set); + void singleBoxClicked(); + void singleBoxHovered(bool state); + void changePen(); + void antialiasingToggled(bool); + void boxOutlineToggled(bool); + void setBoxWidth(double width); + +private: + QChart *m_chart; + QChartView *m_chartView; + QGridLayout *m_scatterLayout; + QBarCategoryAxis *m_axis; + CustomTableModel *m_model; + PenTool *m_penTool; + int m_rowPos; + int m_seriesCount; + QBoxPlotSeries *m_series[10]; + QCheckBox *m_boxOutlined; + QDoubleSpinBox *m_boxWidthSB; +}; + +#endif // MAINWIDGET_H diff --git a/tests/manual/boxplottester/pentool.cpp b/tests/manual/boxplottester/pentool.cpp new file mode 100644 index 00000000..b827039f --- /dev/null +++ b/tests/manual/boxplottester/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 <QtWidgets/QPushButton> +#include <QtWidgets/QDoubleSpinBox> +#include <QtWidgets/QComboBox> +#include <QtWidgets/QFormLayout> +#include <QtWidgets/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/tests/manual/boxplottester/pentool.h b/tests/manual/boxplottester/pentool.h new file mode 100644 index 00000000..13b4064d --- /dev/null +++ b/tests/manual/boxplottester/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 <QtWidgets/QWidget> +#include <QtGui/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/tests/manual/chartdesigner/brushwidget.cpp b/tests/manual/chartdesigner/brushwidget.cpp new file mode 100644 index 00000000..6e615001 --- /dev/null +++ b/tests/manual/chartdesigner/brushwidget.cpp @@ -0,0 +1,33 @@ +/**************************************************************************** +** +** 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 "brushwidget.h" + +BrushWidget::BrushWidget(QWidget *parent):QWidget(parent) +{ + + +} + +BrushWidget::~BrushWidget() +{ + +} + diff --git a/tests/manual/chartdesigner/brushwidget.h b/tests/manual/chartdesigner/brushwidget.h new file mode 100644 index 00000000..7f570cb5 --- /dev/null +++ b/tests/manual/chartdesigner/brushwidget.h @@ -0,0 +1,39 @@ +/**************************************************************************** +** +** 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 BRUSHWIDGET_H +#define BRUSHWIDGET_H + +#include <QtWidgets/QWidget> + +class BrushWidget: public QWidget +{ +public: + explicit BrushWidget(QWidget *parent = 0); + ~BrushWidget(); + + QBrush brush() const { return m_brush; } + void setBrush(const QBrush &brush); + +private: + QBrush m_brush; +}; + +#endif /* BRUSHWIDGET_H */ diff --git a/tests/manual/chartdesigner/chartdesigner.pro b/tests/manual/chartdesigner/chartdesigner.pro new file mode 100644 index 00000000..0594b37f --- /dev/null +++ b/tests/manual/chartdesigner/chartdesigner.pro @@ -0,0 +1,24 @@ +!include( ../tests.pri ) { + error( "Couldn't find the test.pri file!" ) +} + +TEMPLATE = app +QT += core gui + +SOURCES += \ + brushwidget.cpp \ + main.cpp \ + mainwindow.cpp \ + objectinspectorwidget.cpp \ + penwidget.cpp \ + engine.cpp + + +HEADERS += \ + brushwidget.h \ + mainwindow.h \ + objectinspectorwidget.h \ + penwidget.h \ + engine.h + +!system_build:mac: QMAKE_POST_LINK += "$$MAC_POST_LINK_PREFIX $$MAC_TESTS_BIN_DIR" diff --git a/tests/manual/chartdesigner/engine.cpp b/tests/manual/chartdesigner/engine.cpp new file mode 100644 index 00000000..b7ea9e93 --- /dev/null +++ b/tests/manual/chartdesigner/engine.cpp @@ -0,0 +1,343 @@ +/**************************************************************************** + ** + ** 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 "engine.h" +#include <QtCore/QItemSelectionModel> +#include <QtGui/QStandardItemModel> +#include <QtCharts/QVXYModelMapper> +#include <QtCharts/QHBarModelMapper> +#include <QtCharts/QVPieModelMapper> +#include <QtCharts/QLineSeries> +#include <QtCharts/QSplineSeries> +#include <QtCharts/QScatterSeries> +#include <QtCharts/QBarSeries> +#include <QtCharts/QPercentBarSeries> +#include <QtCharts/QStackedBarSeries> +#include <QtCharts/QAreaSeries> +#include <QtCharts/QPieSeries> +#include <QtCharts/QChart> +#include <QtCharts/QBarSet> + + +const qint32 MAGIC_NUMBER = 0x66666666; + +Engine::Engine(QObject* parent) : + QObject(parent), m_count(10), m_chart(new QChart()), m_model(0), m_selection(0) +{ + createModels(); +} + +Engine::~Engine() +{ + delete m_chart; + delete m_selection; + delete m_model; +} + +void Engine::createModels() +{ + m_model = new QStandardItemModel(m_count, m_count); + m_model->setHorizontalHeaderLabels( + QStringList() << "A" << "B" << "C" << "D" << "E" << "F" << "G" << "H" << "I" << "J"); + m_model->setVerticalHeaderLabels( + QStringList() << "1" << "2" << "3" << "4" << "5" << "6" << "7" << "8" << "9" << "10"); + m_selection = new QItemSelectionModel(m_model); + +} + +QList<QAbstractSeries*> Engine::addSeries(QAbstractSeries::SeriesType type) +{ + const QModelIndexList& list = m_selection->selectedIndexes(); + + QMap<int, QModelIndex> columns; + + foreach (const QModelIndex& index, list) { + columns.insertMulti(index.column(), index); + } + + QList<int> keys = columns.uniqueKeys(); + + QModelIndexList rows = columns.values(keys.first()); + + int minRow = m_count + 1; + int maxRow = -1; + + foreach (const QModelIndex& index, rows) { + minRow = qMin(index.row(), minRow); + maxRow = qMax(index.row(), maxRow); + } + + QList<QAbstractSeries*> result; + QColor color; + + switch (type) { + + case QAbstractSeries::SeriesTypeLine: + { + for (int i = 1; i < keys.count(); ++i) { + QLineSeries *line = new QLineSeries(); + setupXYSeries(line, keys, i, minRow, maxRow); + result << line; + } + break; + } + case QAbstractSeries::SeriesTypeSpline: + { + for (int i = 1; i < keys.count(); ++i) { + QSplineSeries *line = new QSplineSeries(); + setupXYSeries(line, keys, i, minRow, maxRow); + result << line; + } + break; + } + case QAbstractSeries::SeriesTypeScatter: + { + for (int i = 1; i < keys.count(); ++i) { + QScatterSeries *line = new QScatterSeries(); + setupXYSeries(line, keys, i, minRow, maxRow); + result << line; + } + break; + } + case QAbstractSeries::SeriesTypeBar: + { + QBarSeries *bar = new QBarSeries(); + setupBarSeries(bar,keys,minRow,maxRow); + result << bar; + break; + } + case QAbstractSeries::SeriesTypePercentBar: + { + QPercentBarSeries *bar = new QPercentBarSeries(); + setupBarSeries(bar,keys,minRow,maxRow); + result << bar; + break; + } + case QAbstractSeries::SeriesTypeStackedBar: + { + QStackedBarSeries *bar = new QStackedBarSeries(); + setupBarSeries(bar,keys,minRow,maxRow); + result << bar; + break; + } + case QAbstractSeries::SeriesTypePie: + { + + QPieSeries *pie = new QPieSeries(); + setupPieSeries(pie,keys,minRow,maxRow); + result << pie; + break; + } + case QAbstractSeries::SeriesTypeArea: + { + QAreaSeries *area = new QAreaSeries( new QLineSeries(), new QLineSeries()); + setupAreaSeries(area,keys,minRow,maxRow); + result << area; + break; + } + } + + m_chart->createDefaultAxes(); + return result; +} + +void Engine::removeSeries(QAbstractSeries* series) +{ + m_chart->removeSeries(series); + + foreach (const QModelIndex& index, m_seriesModelIndex.value(series)) { + m_model->setData(index, QColor(Qt::white), Qt::BackgroundRole); + } +} + +void Engine::clearModels() +{ + delete m_selection; + m_selection = 0; + delete m_model; + m_model = 0; + createModels(); +} + +bool Engine::save(const QString &filename) const +{ + if (filename.isEmpty()) + return false; + + QFile file(filename); + + if (!file.open(QIODevice::WriteOnly)) { + return false; + } + + QDataStream out(&file); + out << MAGIC_NUMBER; + out.setVersion(QDataStream::Qt_4_8); + out << m_model->rowCount(); + out << m_model->columnCount(); + + for (int row = 0; row < m_model->rowCount(); ++row) { + for (int column = 0; column < m_model->columnCount(); ++column) { + QStandardItem *item = m_model->item(row, column); + if (item) { + out << row; + out << column; + out << item->data(Qt::EditRole).toString(); + } + } + } + return true; +} + +bool Engine::load(const QString &filename) +{ + clearModels(); + + if (filename.isEmpty()) + return false; + + QFile file(filename); + + if (!file.open(QIODevice::ReadOnly)) { + return false; + } + + QDataStream in(&file); + + qint32 magicNumber; + in >> magicNumber; + + if (magicNumber != MAGIC_NUMBER) + return false; + + in.setVersion(QDataStream::Qt_4_8); + + int rowCount; + in >> rowCount; + + int columnCount; + in >> columnCount; + + while (!in.atEnd()) { + int row; + int column; + QString value; + in >> row >> column >> value; + QStandardItem *item = new QStandardItem(); + bool ok; + double result = value.toDouble(&ok); + if(ok) + item->setData(result, Qt::EditRole); + else + item->setData(value, Qt::EditRole); + m_model->setItem(row, column, item); + } + + return true; +} + +void Engine::setupXYSeries(QXYSeries *xyseries, const QList<int>& columns, int column, int minRow, int maxRow) +{ + QVXYModelMapper* mapper = new QVXYModelMapper(xyseries); + mapper->setSeries(xyseries); + mapper->setModel(m_model); + mapper->setXColumn(columns.first()); + mapper->setYColumn(columns.at(column)); + mapper->setFirstRow(minRow); + mapper->setRowCount(maxRow - minRow + 1); + m_chart->addSeries(xyseries); + xyseries->setName(QString("Series %1").arg(m_chart->series().count())); + QObject::connect(xyseries,SIGNAL(clicked(QPointF)),this,SIGNAL(selected())); + const QModelIndexList& list = m_selection->selectedIndexes(); + QModelIndexList result; + foreach (const QModelIndex& index, list) { + if (index.column() ==columns.at(column)){ + m_model->setData(index, xyseries->pen().color(), Qt::BackgroundRole); + result << index; + } + } + m_seriesModelIndex.insert(xyseries,result); +} + +void Engine::setupBarSeries(QAbstractBarSeries *bar, const QList<int>& columns, int minRow, int maxRow) +{ + QHBarModelMapper* mapper = new QHBarModelMapper(bar); + mapper->setSeries(bar); + mapper->setModel(m_model); + mapper->setFirstColumn(minRow); + mapper->setColumnCount(maxRow - minRow + 1); + mapper->setFirstBarSetRow(columns.at(1)); + mapper->setLastBarSetRow(columns.last()); + m_chart->addSeries(bar); + bar->setName(QString("Series %1").arg(m_chart->series().count())); + + const QModelIndexList& list = m_selection->selectedIndexes(); + foreach (const QModelIndex& index, list) { + if (index.column() >= columns.at(1) && index.column()<= columns.last()) { + //m_model->setData(index, bar->barSets().at(index.column())->brush().color(), Qt::BackgroundRole); + } + } +} + +void Engine::setupPieSeries(QPieSeries *pie, const QList<int>& columns, int minRow, int maxRow) +{ + QVPieModelMapper* mapper = new QVPieModelMapper(pie); + mapper->setSeries(pie); + mapper->setModel(m_model); + mapper->setValuesColumn(columns.at(1)); + mapper->setLabelsColumn(columns.first()); + mapper->setFirstRow(minRow); + mapper->setRowCount(maxRow - minRow + 1); + m_chart->addSeries(pie); + pie->setName(QString("Series %1").arg(m_chart->series().count())); + + const QModelIndexList& list = m_selection->selectedIndexes(); + foreach (const QModelIndex& index, list) { + // m_model->setData(index, bar->barSets()pen().color(), Qt::BackgroundRole); + } +} + +void Engine::setupAreaSeries(QAreaSeries *series, const QList<int>& columns, int minRow, int maxRow) +{ + QVXYModelMapper* umapper = new QVXYModelMapper(series); + umapper->setSeries(series->upperSeries()); + umapper->setModel(m_model); + umapper->setXColumn(columns.first()); + umapper->setYColumn(columns.at(1)); + umapper->setFirstRow(minRow); + umapper->setRowCount(maxRow - minRow + 1); + + QVXYModelMapper* lmapper = new QVXYModelMapper(series); + lmapper->setSeries(series->lowerSeries()); + lmapper->setModel(m_model); + lmapper->setXColumn(columns.first()); + lmapper->setYColumn(columns.at(2)); + lmapper->setFirstRow(minRow); + lmapper->setRowCount(maxRow - minRow + 1); + + m_chart->addSeries(series); + series->setName(QString("Series %1").arg(m_chart->series().count())); + + const QModelIndexList& list = m_selection->selectedIndexes(); + foreach (const QModelIndex& index, list) { + //if (index.column() ==columns.at(column)) + // m_model->setData(index, xyseries->pen().color(), Qt::BackgroundRole); + } +} diff --git a/tests/manual/chartdesigner/engine.h b/tests/manual/chartdesigner/engine.h new file mode 100644 index 00000000..eef15dcf --- /dev/null +++ b/tests/manual/chartdesigner/engine.h @@ -0,0 +1,76 @@ +/**************************************************************************** + ** + ** 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 ENGINE_H +#define ENGINE_H + +#include <QtCore/QObject> +#include <QtCharts/QAbstractSeries> +#include <QtCore/QModelIndex> + +class QStandardItemModel; +class QItemSelectionModel; + + +QT_CHARTS_BEGIN_NAMESPACE +class QChart; +class QXYSeries; +class QAbstractBarSeries; +class QPieSeries; +class QAreaSeries; +QT_CHARTS_END_NAMESPACE + +QT_CHARTS_USE_NAMESPACE + +class Engine : public QObject +{ + Q_OBJECT +public: + explicit Engine(QObject *parent = 0); + ~Engine(); + + int modelCount() { return m_count; } + QStandardItemModel *model() const { return m_model; } + QItemSelectionModel *selectionModel() const { return m_selection; } + QChart* chart() const { return m_chart; } + void clearModels(); + QList<QAbstractSeries*> addSeries(QAbstractSeries::SeriesType type); + void removeSeries(QAbstractSeries* series); + bool save(const QString &filename) const; + bool load(const QString &filename); +signals: + void selected(); + +private: + void createModels(); + void setupXYSeries(QXYSeries *xyseries, const QList<int>& columns, int column, int minRow, int maxRow); + void setupBarSeries(QAbstractBarSeries *series, const QList<int>& columns, int minRow, int maxRow); + void setupPieSeries(QPieSeries *pie, const QList<int>& columns, int minRow, int maxRow); + void setupAreaSeries(QAreaSeries *series, const QList<int>& columns, int minRow, int maxRow); + +private: + int m_count; + QChart *m_chart; + QStandardItemModel *m_model; + QItemSelectionModel *m_selection; + QMap<QAbstractSeries*, QList<QModelIndex> > m_seriesModelIndex; +}; + +#endif /* ENGINE_H */ diff --git a/tests/manual/chartdesigner/main.cpp b/tests/manual/chartdesigner/main.cpp new file mode 100644 index 00000000..6b47caf5 --- /dev/null +++ b/tests/manual/chartdesigner/main.cpp @@ -0,0 +1,32 @@ +/**************************************************************************** +** +** 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 "mainwindow.h" +#include <QtWidgets/QApplication> + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + + MainWindow window; + window.resize(1000,600); + window.show(); + return a.exec(); +} diff --git a/tests/manual/chartdesigner/mainwindow.cpp b/tests/manual/chartdesigner/mainwindow.cpp new file mode 100644 index 00000000..70588459 --- /dev/null +++ b/tests/manual/chartdesigner/mainwindow.cpp @@ -0,0 +1,423 @@ +/**************************************************************************** + ** + ** 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 "mainwindow.h" +#include "objectinspectorwidget.h" +#include "penwidget.h" +#include "brushwidget.h" +#include "engine.h" +#include <QtCore/QSettings> +#include <QtCharts/QChartView> +#include <QtWidgets/QDockWidget> +#include <QtWidgets/QMenuBar> +#include <QtWidgets/QTableWidget> +#include <QtWidgets/QSplitter> +#include <QtCore/QMetaEnum> +#include <QtGui/QStandardItemModel> +#include <QtWidgets/QHeaderView> +#include <QtCore/QDebug> +#include <QtWidgets/QMessageBox> + +static const QString FILENAME_SETTING("filename"); +static const QString GEOMETRY_SETTING("geometry"); + +MainWindow::MainWindow() : + m_engine(new Engine(this)), + m_view(new QChartView(m_engine->chart())), + m_scene(m_view->scene()), + m_table(new QTableView()), + m_addSeriesMenu(0), + m_seriesMenu(0), + m_chartMenu(0), + m_themeMenu(0), + m_animationMenu(0), + m_zoomMenu(0), + m_removeAllAction(0), + m_legendAction(0), + m_antialiasingAction(0) +{ + createMenus(); + createDockWidgets(); + createTable(); + createLayout(); + + QSettings settings; + restoreGeometry(settings.value(GEOMETRY_SETTING).toByteArray()); + m_filename = settings.value(FILENAME_SETTING).toString(); + if (m_filename.isEmpty()) + m_filename = "untitled"; + + setWindowTitle(m_filename); + updateUI(); +} + +MainWindow::~MainWindow() +{ + delete m_engine; +} + +void MainWindow::createMenus() +{ + QMenu *file = menuBar()->addMenu(tr("File")); + QMenu *edit = menuBar()->addMenu(tr("Edit")); + m_seriesMenu = menuBar()->addMenu(tr("Series")); + m_chartMenu = menuBar()->addMenu(tr("Chart")); + + m_addSeriesMenu = new QMenu(tr("Add series")); + m_themeMenu = new QMenu(tr("Apply theme")); + m_animationMenu = new QMenu(tr("Animations")); + m_zoomMenu = new QMenu(tr("Zoom")); + + file->addAction(tr("New"), this, SLOT(handleNewAction())); + file->addAction(tr("Load"), this, SLOT(handleLoadAction())); + file->addAction(tr("Save"), this, SLOT(handleSaveAction())); + file->addAction(tr("Save As"), this, SLOT(handleSaveAsAction())); + + //seriesMenu + m_seriesMenu->addMenu(m_addSeriesMenu); + m_removeAllAction = new QAction(tr("Remove all series"), this); + QObject::connect(m_removeAllAction, SIGNAL(triggered()), this, SLOT(handleRemoveAllSeriesAction())); + m_seriesMenu->addAction(m_removeAllAction); + m_seriesMenu->addSeparator(); + + //seriesMenu /addSeriesMenu + { + int index = QAbstractSeries::staticMetaObject.indexOfEnumerator("SeriesType"); + QMetaEnum metaEnum = QAbstractSeries::staticMetaObject.enumerator(index); + + int count = metaEnum.keyCount(); + + for (int i = 0; i < count; ++i) { + QAction* action = new QAction(metaEnum.key(i), this); + action->setData(metaEnum.value(i)); + m_addSeriesMenu->addAction(action); + QObject::connect(action, SIGNAL(triggered()), this, SLOT(handleAddSeriesMenu())); + } + } + + //chartMenu / themeMenu + { + m_chartMenu->addMenu(m_themeMenu); + int index = QChart::staticMetaObject.indexOfEnumerator("ChartTheme"); + QMetaEnum metaEnum = QChart::staticMetaObject.enumerator(index); + + int count = metaEnum.keyCount(); + + for (int i = 0; i < count; ++i) { + QAction* action = new QAction(metaEnum.key(i), this); + action->setData(metaEnum.value(i)); + action->setCheckable(true); + m_themeMenu->addAction(action); + QObject::connect(action, SIGNAL(triggered()), this, SLOT(handleThemeMenu())); + } + } + + //chartMenu / animationMenu + { + m_chartMenu->addMenu(m_animationMenu); + int index = QChart::staticMetaObject.indexOfEnumerator("AnimationOption"); + QMetaEnum metaEnum = QChart::staticMetaObject.enumerator(index); + + int count = metaEnum.keyCount(); + + for (int i = 0; i < count; ++i) { + QAction* action = new QAction(metaEnum.key(i), this); + action->setData(metaEnum.value(i)); + action->setCheckable(true); + m_animationMenu->addAction(action); + QObject::connect(action, SIGNAL(triggered()), this, SLOT(handleAnimationMenu())); + } + } + + //chartMenu / zoomMenu + { + m_chartMenu->addMenu(m_zoomMenu); + int index = QChartView::staticMetaObject.indexOfEnumerator("RubberBand"); + QMetaEnum metaEnum = QChartView::staticMetaObject.enumerator(index); + + int count = metaEnum.keyCount(); + + for (int i = 0; i < count; ++i) { + QAction* action = new QAction(metaEnum.key(i), this); + action->setData(metaEnum.value(i)); + action->setCheckable(true); + m_zoomMenu->addAction(action); + QObject::connect(action, SIGNAL(triggered()), this, SLOT(handleZoomMenu())); + } + } + + //chartMenu / legend + m_legendAction = new QAction(tr("Legend"), this); + m_legendAction->setCheckable(true); + m_chartMenu->addAction(m_legendAction); + QObject::connect(m_legendAction, SIGNAL(triggered()), this, SLOT(handleLegendAction())); + + //chartMenu / Anti-aliasing + m_antialiasingAction = new QAction(tr("Anti-aliasing"), this); + m_antialiasingAction->setCheckable(true); + m_chartMenu->addAction(m_antialiasingAction); + QObject::connect(m_antialiasingAction, SIGNAL(triggered()), this, SLOT(handleAntialiasingAction())); + +} + +void MainWindow::createDockWidgets() +{ + m_brushWidget = new BrushWidget(); + QDockWidget *brushDockWidget = new QDockWidget(tr("Brush"), this); + brushDockWidget->setFeatures(QDockWidget::DockWidgetMovable | QDockWidget::DockWidgetFloatable); + brushDockWidget->setWidget(m_brushWidget); + addDockWidget(Qt::RightDockWidgetArea, brushDockWidget); + + m_penWidget = new PenWidget(); + QDockWidget *penDockWidget = new QDockWidget(tr("Pen"), this); + penDockWidget->setFeatures(QDockWidget::DockWidgetMovable | QDockWidget::DockWidgetFloatable); + penDockWidget->setWidget(m_penWidget); + addDockWidget(Qt::RightDockWidgetArea, penDockWidget); + + m_inspectorWidget = new InspectorWidget(); + QDockWidget *inspectorDockWidget = new QDockWidget(tr("Object Inspector"), this); + inspectorDockWidget->setFeatures( + QDockWidget::DockWidgetMovable | QDockWidget::DockWidgetFloatable); + inspectorDockWidget->setWidget(m_inspectorWidget); + addDockWidget(Qt::RightDockWidgetArea, inspectorDockWidget); + + setDockOptions(QMainWindow::AnimatedDocks); +} + +void MainWindow::createLayout() +{ + m_table->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch); + + int rowHeight = m_table->rowHeight(0); + int tableHeight = (m_engine->modelCount() * rowHeight) + m_table->horizontalHeader()->height() + 2 * m_table->frameWidth(); + + m_table->setMinimumHeight(tableHeight); + m_table->setMaximumHeight(tableHeight); + + QSplitter *splitter = new QSplitter(this); + splitter->setOrientation(Qt::Vertical); + splitter->addWidget(m_table); + splitter->addWidget(m_view); + setCentralWidget(splitter); + m_view->hide(); +} + +void MainWindow::createTable() +{ + m_table->setModel(m_engine->model()); + m_table->setSelectionModel(m_engine->selectionModel()); + QObject::connect(m_table->selectionModel(),SIGNAL(selectionChanged(QItemSelection,QItemSelection)), this,SLOT(updateUI())); +} + +void MainWindow::updateUI() +{ + + QItemSelectionModel* selection = m_table->selectionModel(); + const QModelIndexList& list = selection->selectedIndexes(); + + QMap<int, QModelIndex> columns; + + foreach (const QModelIndex& index, list) { + columns.insertMulti(index.column(), index); + } + + QList<int> keys = columns.uniqueKeys(); + + bool seriesEnabled = false; + + foreach (QAction* action, m_addSeriesMenu->actions()) { + switch (action->data().toInt()) { + case QAbstractSeries::SeriesTypeLine: + case QAbstractSeries::SeriesTypeSpline: + case QAbstractSeries::SeriesTypeScatter: + action->setEnabled(list.count() > 0 && keys.count() >= 2); + seriesEnabled |= action->isEnabled(); + break; + case QAbstractSeries::SeriesTypeBar: + case QAbstractSeries::SeriesTypePercentBar: + case QAbstractSeries::SeriesTypeStackedBar: + action->setEnabled(list.count() > 0 && keys.count() >= 2); + seriesEnabled |= action->isEnabled(); + break; + case QAbstractSeries::SeriesTypePie: + action->setEnabled(list.count() > 0 && keys.count() == 2); + seriesEnabled |= action->isEnabled(); + break; + case QAbstractSeries::SeriesTypeArea: + action->setEnabled(list.count() > 0 && keys.count() == 3); + seriesEnabled |= action->isEnabled(); + break; + } + } + + m_chartMenu->setEnabled(m_engine->chart()->series().count() > 0); + m_seriesMenu->setEnabled(seriesEnabled || m_engine->chart()->series().count() > 0); + m_removeAllAction->setEnabled(m_engine->chart()->series().count() > 0); + + int theme = m_engine->chart()->theme(); + foreach (QAction* action, m_themeMenu->actions()) { + action->setChecked(action->data().toInt() == theme); + } + + int animation = m_engine->chart()->animationOptions(); + foreach (QAction* action, m_animationMenu->actions()) { + action->setChecked(action->data().toInt() == animation); + } + + int zoom = m_view->rubberBand(); + foreach (QAction* action, m_zoomMenu->actions()) { + action->setChecked(action->data().toInt() == zoom); + } + + m_legendAction->setChecked(m_engine->chart()->legend()->isVisible()); + m_antialiasingAction->setChecked(m_view->renderHints().testFlag(QPainter::Antialiasing)); + + foreach (QAction *action, m_seriesMenu->actions()) { + //TODO: visibility handling + //if (m_series.value(action->text())) + // ; + //action->setChecked(false); + } +} + +void MainWindow::closeEvent(QCloseEvent *event) +{ + QSettings settings; + settings.setValue(GEOMETRY_SETTING, saveGeometry()); + settings.setValue(FILENAME_SETTING, m_filename); + QMainWindow::closeEvent(event); +} + +//handlers + +void MainWindow::handleNewAction() +{ + m_engine->chart()->removeAllSeries(); + m_view->hide(); + m_engine->clearModels(); + createTable(); + m_filename = "untitled"; + setWindowTitle(m_filename); + updateUI(); +} + +void MainWindow::handleAddSeriesMenu() +{ + m_view->show(); + QAction* action = qobject_cast<QAction*>(sender()); + QList<QAbstractSeries*> series = m_engine->addSeries(QAbstractSeries::SeriesType(action->data().toInt())); + + foreach (QAbstractSeries* s , series) + { + QAction *newAction = new QAction(s->name(),this); + //newAction->setCheckable(true); + m_series.insert(s->name(),s); + m_seriesMenu->addAction(newAction); + } + + updateUI(); +} + +void MainWindow::handleRemoveAllSeriesAction() +{ + + foreach (QAction* action, m_seriesMenu->actions()){ + if(m_series.contains(action->text())){ + m_seriesMenu->removeAction(action); + m_engine->removeSeries(m_series.value(action->text())); + delete action; + } + } + + m_series.clear(); + + m_view->hide(); + updateUI(); +} + +void MainWindow::handleThemeMenu() +{ + QAction* action = qobject_cast<QAction*>(sender()); + m_engine->chart()->setTheme(QChart::ChartTheme(action->data().toInt())); + updateUI(); +} + +void MainWindow::handleAnimationMenu() +{ + QAction* action = qobject_cast<QAction*>(sender()); + m_engine->chart()->setAnimationOptions(QChart::AnimationOption(action->data().toInt())); + updateUI(); +} + +void MainWindow::handleZoomMenu() +{ + QAction* action = qobject_cast<QAction*>(sender()); + m_view->setRubberBand(QChartView::RubberBand(action->data().toInt())); + updateUI(); +} + +void MainWindow::handleAntialiasingAction() +{ + QAction* action = qobject_cast<QAction*>(sender()); + if (action->isChecked()) { + m_view->setRenderHint(QPainter::Antialiasing, true); + } + else { + m_view->setRenderHint(QPainter::Antialiasing, false); + } +} + +void MainWindow::handleLegendAction() +{ + QAction* action = qobject_cast<QAction*>(sender()); + if (action->isChecked()) { + m_engine->chart()->legend()->setVisible(true); + } + else { + m_engine->chart()->legend()->setVisible(false); + } +} + +void MainWindow::handleSaveAction() +{ + if(!m_engine->save(m_filename)) { + + QScopedPointer<QMessageBox> messageBox(new QMessageBox(this)); + messageBox->setIcon(QMessageBox::Warning); + messageBox->setWindowModality(Qt::WindowModal); + messageBox->setWindowTitle(QString(tr("Error"))); + messageBox->setText(tr("Could not write to ") + m_filename); + messageBox->exec(); + } +} + +void MainWindow::handleLoadAction() +{ + if(!m_engine->load(m_filename)) { + + QScopedPointer<QMessageBox> messageBox(new QMessageBox(this)); + messageBox->setIcon(QMessageBox::Warning); + messageBox->setWindowModality(Qt::WindowModal); + messageBox->setWindowTitle(QString(tr("Error"))); + messageBox->setText(tr("Could not open ") + m_filename); + messageBox->exec(); + + }else createTable(); +} diff --git a/tests/manual/chartdesigner/mainwindow.h b/tests/manual/chartdesigner/mainwindow.h new file mode 100644 index 00000000..d5ce5418 --- /dev/null +++ b/tests/manual/chartdesigner/mainwindow.h @@ -0,0 +1,97 @@ +/**************************************************************************** +** +** 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 MAINWINDOW_H +#define MAINWINDOW_H + +#include <QtWidgets/QMainWindow> +#include <QtCharts/QChartGlobal> +#include <QtCore/QMap> + + +QT_CHARTS_BEGIN_NAMESPACE +class QChartView; +class QAbstractSeries; +QT_CHARTS_END_NAMESPACE + +class QGraphicsScene; +class InspectorWidget; +class BrushWidget; +class PenWidget; +class QTableView; +class Engine; + +QT_CHARTS_USE_NAMESPACE + +class MainWindow : public QMainWindow +{ + Q_OBJECT +public: + MainWindow(); + ~MainWindow(); + +private slots: + void handleNewAction(); + void handleAddSeriesMenu(); + void handleRemoveAllSeriesAction(); + void updateUI(); + void handleThemeMenu(); + void handleAnimationMenu(); + void handleZoomMenu(); + void handleAntialiasingAction(); + void handleLegendAction(); + void handleSaveAction(); + void handleLoadAction(); + +protected: + void closeEvent(QCloseEvent *event); + +private: + void createMenus(); + void createDockWidgets(); + void createModel(); + void createLayout(); + void createTable(); + +private: + Engine *m_engine; + QChartView *m_view; + QGraphicsScene *m_scene; + QTableView *m_table; + InspectorWidget *m_inspectorWidget; + PenWidget *m_penWidget; + BrushWidget *m_brushWidget; + QMenu *m_addSeriesMenu; + QMenu *m_seriesMenu; + QMenu *m_chartMenu; + QMenu *m_themeMenu; + QMenu *m_animationMenu; + QMenu *m_zoomMenu; + + QAction *m_removeAllAction; + QAction *m_legendAction; + QAction *m_antialiasingAction; + QString m_filename; + + QMap<QString,QAbstractSeries*> m_series; + +}; + +#endif /* MAINWINDOW_H */ diff --git a/tests/manual/chartdesigner/objectinspectorwidget.cpp b/tests/manual/chartdesigner/objectinspectorwidget.cpp new file mode 100644 index 00000000..64a89854 --- /dev/null +++ b/tests/manual/chartdesigner/objectinspectorwidget.cpp @@ -0,0 +1,51 @@ +/**************************************************************************** +** +** 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 "objectinspectorwidget.h" +#include <QtGui/QIcon> +#include <QtGui/QPainter> +#include <QtGui/QPixmapCache> + +InspectorWidget::InspectorWidget() +{ + +} + +InspectorWidget::~InspectorWidget() +{ + +} + +QIcon InspectorWidget::getColorIcon(const QColor& color,const QSize &size) const +{ + + QString key = QString("COLOR_ICON=%1:%2x%3").arg(color.name()).arg(size.width()).arg(size.height()); + + QPixmap pixmap(size); + + if (!QPixmapCache::find(key, &pixmap)) { + pixmap.fill(Qt::white); + QPainter painter(&pixmap); + painter.fillRect(2, 2, 46, 46, color); + QPixmapCache::insert(key, pixmap); + } + + return QIcon(pixmap); +} diff --git a/tests/manual/chartdesigner/objectinspectorwidget.h b/tests/manual/chartdesigner/objectinspectorwidget.h new file mode 100644 index 00000000..ba9deed4 --- /dev/null +++ b/tests/manual/chartdesigner/objectinspectorwidget.h @@ -0,0 +1,37 @@ +/**************************************************************************** +** +** 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 INSPECTORWIDGET_H +#define INSPECTORWIDGET_H + +#include <QtWidgets/QWidget> + +class InspectorWidget : public QWidget +{ +public: + InspectorWidget(); + ~InspectorWidget(); + +private: + QIcon getColorIcon(const QColor& color,const QSize &size) const; + +}; + +#endif diff --git a/tests/manual/chartdesigner/penwidget.cpp b/tests/manual/chartdesigner/penwidget.cpp new file mode 100644 index 00000000..e2b22f64 --- /dev/null +++ b/tests/manual/chartdesigner/penwidget.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 "penwidget.h" +#include <QtWidgets/QFormLayout> +#include <QtWidgets/QComboBox> +#include <QtWidgets/QSpinBox> + +PenWidget::PenWidget(QWidget *parent):QWidget(parent), +m_colorComboBox(0), +m_lineStyleComboBox(0), +m_widthSpinBox(0) +{ + createContent(); + createLayout(); + setFixedSize(minimumSizeHint()); +} + +PenWidget::~PenWidget() +{ + +} + +void PenWidget::createContent() +{ + m_colorComboBox = new QComboBox(this); + m_lineStyleComboBox = new QComboBox(this); + m_widthSpinBox = new QSpinBox(this); +} + +void PenWidget::createLayout() +{ + QFormLayout *layout = new QFormLayout(); + layout->addRow(tr("Color"), m_colorComboBox); + layout->addRow(tr("Style"), m_lineStyleComboBox); + layout->addRow(tr("Width"), m_widthSpinBox); + setLayout(layout); +} + diff --git a/tests/manual/chartdesigner/penwidget.h b/tests/manual/chartdesigner/penwidget.h new file mode 100644 index 00000000..fe9998c0 --- /dev/null +++ b/tests/manual/chartdesigner/penwidget.h @@ -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$ +** +****************************************************************************/ + +#ifndef PENWIDGET_H +#define PENWIDGET_H + +#include <QtWidgets/QWidget> +#include <QtWidgets/QPen> + +class QComboBox; +class QSpinBox; + +class PenWidget : public QWidget +{ +public: + explicit PenWidget(QWidget* parent = 0); + ~PenWidget(); + + QPen pen() const { return m_pen; } +private: + void createContent(); + void createLayout(); + +private: + QPen m_pen; + QComboBox *m_colorComboBox; + QComboBox *m_lineStyleComboBox; + QSpinBox *m_widthSpinBox; +}; + +#endif /* PENWIDGET_H */ diff --git a/tests/manual/chartviewer/charts.h b/tests/manual/chartviewer/charts.h new file mode 100644 index 00000000..2d59a885 --- /dev/null +++ b/tests/manual/chartviewer/charts.h @@ -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$ +** +****************************************************************************/ + + +#ifndef CHARTS_H +#define CHARTS_H +#include "model.h" +#include <QtCore/QList> +#include <QtCore/QString> +#include <QtCore/QSharedPointer> +#include <QtCharts/QChartGlobal> + +QT_CHARTS_BEGIN_NAMESPACE +class QChart; +QT_CHARTS_END_NAMESPACE + +QT_CHARTS_USE_NAMESPACE + +class Chart +{ +public: + virtual ~Chart() {}; + virtual QChart *createChart(const DataTable &table) = 0; + virtual QString name() = 0; + virtual QString category() = 0; + virtual QString subCategory() = 0; + +}; + +namespace Charts +{ + + typedef QList<Chart *> ChartList; + + inline ChartList &chartList() + { + static ChartList list; + return list; + } + + inline bool findChart(Chart *chart) + { + ChartList &list = chartList(); + if (list.contains(chart)) + return true; + + foreach (Chart *item, list) { + if (item->name() == chart->name() && item->category() == chart->category() && item->subCategory() == chart->subCategory()) + return true; + } + return false; + } + + inline void addChart(Chart *chart) + { + ChartList &list = chartList(); + if (!findChart(chart)) + list.append(chart); + } +} + +template <class T> +class ChartWrapper +{ +public: + QSharedPointer<T> chart; + ChartWrapper() : chart(new T) { Charts::addChart(chart.data()); } +}; + +#define DECLARE_CHART(chartType) static ChartWrapper<chartType> chartType; +#define DECLARE_CHART_TEMPLATE(chartType,chartName) static ChartWrapper<chartType> chartName; + +#endif diff --git a/tests/manual/chartviewer/charts/axis/barcategoryaxisx.cpp b/tests/manual/chartviewer/charts/axis/barcategoryaxisx.cpp new file mode 100644 index 00000000..250576bb --- /dev/null +++ b/tests/manual/chartviewer/charts/axis/barcategoryaxisx.cpp @@ -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$ +** +****************************************************************************/ + +#include "charts.h" +#include <QtCharts/QChart> +#include <QtCharts/QBarSeries> +#include <QtCharts/QBarSet> +#include <QtCharts/QValueAxis> +#include <QtCharts/QBarCategoryAxis> + +class BarCategoryAxisX: public Chart +{ +public: + QString name() { return "AxisX"; } + QString category() { return QObject::tr("Axis"); } + QString subCategory() { return "BarCategoryAxis"; } + + QChart *createChart(const DataTable &table) + { + QChart *chart = new QChart(); + chart->setTitle(" BarCateogry X , Value Y"); + + QString name("Series "); + QBarSeries *series = new QBarSeries(chart); + QValueAxis *valueaxis = new QValueAxis(); + QBarCategoryAxis *barcategory = new QBarCategoryAxis(); + for (int i(0); i < table.count(); i++) { + QBarSet *set = new QBarSet("Bar set " + QString::number(i)); + foreach (Data data, table[i]) + *set << data.first.y(); + series->append(set); + } + chart->addSeries(series); + + int count = series->barSets().first()->count(); + + + for (int i = 0; i < count; i++) { + barcategory->append("BarSet " + QString::number(i)); + } + + chart->setAxisY(valueaxis, series); + chart->setAxisX(barcategory, series); + + return chart; + } +}; + +class BarCategoryAxisXTitle: public BarCategoryAxisX +{ + QString name() { return "AxisX Title"; } + QChart *createChart(const DataTable &table) + { + QChart *chart = BarCategoryAxisX::createChart(table); + chart->axisX()->setTitleText("Axis X"); + chart->axisY()->setTitleText("Axis Y"); + chart->setTitle(" BarCateogry X , Value Y, title"); + return chart; + } +}; + +DECLARE_CHART(BarCategoryAxisX); +DECLARE_CHART(BarCategoryAxisXTitle); diff --git a/tests/manual/chartviewer/charts/axis/barcategoryaxisxlogy.cpp b/tests/manual/chartviewer/charts/axis/barcategoryaxisxlogy.cpp new file mode 100644 index 00000000..516d0f49 --- /dev/null +++ b/tests/manual/chartviewer/charts/axis/barcategoryaxisxlogy.cpp @@ -0,0 +1,81 @@ +/**************************************************************************** +** +** 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 "charts.h" +#include <QtCharts/QChart> +#include <QtCharts/QBarSeries> +#include <QtCharts/QBarSet> +#include <QtCharts/QLogValueAxis> +#include <QtCharts/QBarCategoryAxis> + +class BarCategoryAxisXLogY: public Chart +{ +public: + QString name() { return "AxisX"; } + QString category() { return QObject::tr("Axis"); } + QString subCategory() { return "BarCategoryAxis"; } + + QChart *createChart(const DataTable &table) + { + QChart *chart = new QChart(); + chart->setTitle(" BarCateogry X , LogValue Y"); + + QString name("Series "); + QBarSeries *series = new QBarSeries(chart); + QLogValueAxis *logvalueaxis = new QLogValueAxis(); + logvalueaxis->setBase(2); + QBarCategoryAxis *barcategory = new QBarCategoryAxis(); + for (int i(0); i < table.count(); i++) { + QBarSet *set = new QBarSet("Bar set " + QString::number(i)); + foreach (Data data, table[i]) + *set << data.first.y(); + series->append(set); + } + chart->addSeries(series); + + int count = series->barSets().first()->count(); + + + for (int i = 0; i < count; i++) { + barcategory->append("BarSet " + QString::number(i)); + } + + chart->setAxisY(logvalueaxis, series); + chart->setAxisX(barcategory, series); + + return chart; + } +}; + +class BarCategoryAxisXLogYTitle: public BarCategoryAxisXLogY +{ + QString name() { return "AxisX Title"; } + QChart *createChart(const DataTable &table) + { + QChart *chart = BarCategoryAxisXLogY::createChart(table); + chart->axisX()->setTitleText("Axis X"); + chart->axisY()->setTitleText("Axis Y"); + chart->setTitle(" BarCateogry X , LogValue Y, title"); + return chart; + } +}; + +DECLARE_CHART(BarCategoryAxisXLogY); +DECLARE_CHART(BarCategoryAxisXLogYTitle); diff --git a/tests/manual/chartviewer/charts/axis/barcategoryaxisy.cpp b/tests/manual/chartviewer/charts/axis/barcategoryaxisy.cpp new file mode 100644 index 00000000..d20442b2 --- /dev/null +++ b/tests/manual/chartviewer/charts/axis/barcategoryaxisy.cpp @@ -0,0 +1,84 @@ +/**************************************************************************** +** +** 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 "charts.h" +#include <QtCharts/QChart> +#include <QtCharts/QHorizontalBarSeries> +#include <QtCharts/QBarSet> +#include <QtCharts/QValueAxis> +#include <QtCharts/QBarCategoryAxis> + +class BarCategoryAxisY: public Chart +{ +public: + QString name() { return "AxisY"; } + QString category() { return QObject::tr("Axis"); } + QString subCategory() { return "BarCategoryAxis"; } + + QChart *createChart(const DataTable &table) + { + QChart *chart = new QChart(); + chart->setTitle(" BarCateogry Y , Value X"); + + QString name("Series "); + QHorizontalBarSeries *series = new QHorizontalBarSeries(chart); + QValueAxis *valueaxis = new QValueAxis(); + QBarCategoryAxis *barcategory = new QBarCategoryAxis(); + for (int i(0); i < table.count(); i++) { + QBarSet *set = new QBarSet("Bar set " + QString::number(i)); + foreach(Data data, table[i]) + *set << data.first.y(); + series->append(set); + } + chart->addSeries(series); + + int count = series->barSets().first()->count(); + + for (int i = 0; i < count; i++) { + barcategory->append("BarSet " + QString::number(i)); + } + + chart->setAxisX(valueaxis, series); + chart->setAxisY(barcategory, series); + + return chart; + } +}; + +class BarCategoryAxisYTitle: public BarCategoryAxisY +{ +public: + QString name() + { + return "AxisY Title"; + } + + QChart *createChart(const DataTable &table) + { + QChart *chart = BarCategoryAxisY::createChart(table); + chart->axisX()->setTitleText("Axis X"); + chart->axisY()->setTitleText("Axis Y"); + chart->setTitle(" BarCateogry Y , Value X, title"); + return chart; + } +}; + +DECLARE_CHART(BarCategoryAxisY); +DECLARE_CHART(BarCategoryAxisYTitle); diff --git a/tests/manual/chartviewer/charts/axis/barcategoryaxisylogx.cpp b/tests/manual/chartviewer/charts/axis/barcategoryaxisylogx.cpp new file mode 100644 index 00000000..f38cf931 --- /dev/null +++ b/tests/manual/chartviewer/charts/axis/barcategoryaxisylogx.cpp @@ -0,0 +1,81 @@ +/**************************************************************************** +** +** 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 "charts.h" +#include <QtCharts/QChart> +#include <QtCharts/QHorizontalBarSeries> +#include <QtCharts/QBarSet> +#include <QtCharts/QLogValueAxis> +#include <QtCharts/QBarCategoryAxis> + +class BarCategoryAxisYLogX: public Chart +{ +public: + QString name() { return "AxisY"; } + QString category() { return QObject::tr("Axis"); } + QString subCategory() { return "BarCategoryAxis"; } + + QChart *createChart(const DataTable &table) + { + QChart *chart = new QChart(); + chart->setTitle(" LogValue X , BarCateogry Y"); + + QString name("Series "); + QHorizontalBarSeries *series = new QHorizontalBarSeries(chart); + QLogValueAxis *logvalueaxis = new QLogValueAxis(); + logvalueaxis->setBase(2); + QBarCategoryAxis *barcategory = new QBarCategoryAxis(); + for (int i(0); i < table.count(); i++) { + QBarSet *set = new QBarSet("Bar set " + QString::number(i)); + foreach (Data data, table[i]) + *set << data.first.y(); + series->append(set); + } + chart->addSeries(series); + + int count = series->barSets().first()->count(); + + + for (int i = 0; i < count; i++) { + barcategory->append("BarSet " + QString::number(i)); + } + + chart->setAxisX(logvalueaxis, series); + chart->setAxisY(barcategory, series); + + return chart; + } +}; + +class BarCategoryAxisYLogXTitle: public BarCategoryAxisYLogX +{ + QString name() { return "AxisX Title"; } + QChart *createChart(const DataTable &table) + { + QChart *chart = BarCategoryAxisYLogX::createChart(table); + chart->axisX()->setTitleText("Axis X"); + chart->axisY()->setTitleText("Axis Y"); + chart->setTitle(" LogValue X , BarCateogry Y, title"); + return chart; + } +}; + +DECLARE_CHART(BarCategoryAxisYLogX); +DECLARE_CHART(BarCategoryAxisYLogXTitle); diff --git a/tests/manual/chartviewer/charts/axis/categoryaxis.cpp b/tests/manual/chartviewer/charts/axis/categoryaxis.cpp new file mode 100644 index 00000000..dc025f6d --- /dev/null +++ b/tests/manual/chartviewer/charts/axis/categoryaxis.cpp @@ -0,0 +1,83 @@ +/**************************************************************************** +** +** 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 "charts.h" +#include <QtCharts/QChart> +#include <QtCharts/QLineSeries> +#include <QtCharts/QCategoryAxis> + +class CategoryLineChart: public Chart +{ +public: + QString name() { return QObject::tr("CategoryAxis"); } + QString category() { return QObject::tr("Axis"); } + QString subCategory() { return QString::null; } + + QChart *createChart(const DataTable &table) + { + QChart *chart = new QChart(); + chart->setTitle("Category X , Category Y "); + + QString name("Series "); + int nameIndex = 0; + foreach (DataList list, table) { + QLineSeries *series = new QLineSeries(chart); + foreach (Data data, list) + series->append(data.first); + series->setName(name + QString::number(nameIndex)); + nameIndex++; + chart->addSeries(series); + } + + QCategoryAxis *axisX = new QCategoryAxis; + axisX->append("low", 5); + axisX->append("avg.", 12); + axisX->append("high", 19); + axisX->setRange(0, 20); + chart->setAxisX(axisX, chart->series().at(0)); + + QCategoryAxis *axisY = new QCategoryAxis; + axisY->append("cheap", 5); + axisY->append("fair", 12); + axisY->append("pricy", 20); + axisY->setRange(0, 20); + chart->setAxisY(axisY, chart->series().at(0)); + + return chart; + } +}; + +class CategoryLineChartTitle: public CategoryLineChart +{ +public: + QString name() { return QObject::tr("CategoryAxis, Title"); } + + QChart *createChart(const DataTable &table) + { + QChart *chart = CategoryLineChart::createChart(table); + chart->axisX()->setTitleText("Axis X"); + chart->axisY()->setTitleText("Axis Y"); + chart->setTitle("Category X , Category Y,title "); + return chart; + } +}; + +DECLARE_CHART(CategoryLineChart) +DECLARE_CHART(CategoryLineChartTitle) diff --git a/tests/manual/chartviewer/charts/axis/datetimeaxisx.cpp b/tests/manual/chartviewer/charts/axis/datetimeaxisx.cpp new file mode 100644 index 00000000..99154bbc --- /dev/null +++ b/tests/manual/chartviewer/charts/axis/datetimeaxisx.cpp @@ -0,0 +1,81 @@ +/**************************************************************************** +** +** 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 "charts.h" +#include <QtCharts/QChart> +#include <QtCharts/QLineSeries> +#include <QtCharts/QValueAxis> +#include <QtCharts/QDateTimeAxis> + +class DateTimeAxisX: public Chart +{ +public: + QString name() { return "AxisX"; } + QString category() { return QObject::tr("Axis"); } + QString subCategory() { return "DateTimeAxis"; } + + QChart *createChart(const DataTable &table) + { + QChart *chart = new QChart(); + chart->setTitle("DateTime X , Value Y"); + QValueAxis *valueaxis = new QValueAxis(); + QDateTimeAxis *datetimeaxis = new QDateTimeAxis(); + datetimeaxis->setTickCount(10); + datetimeaxis->setFormat("yyyy"); + + qreal day = 1000l * 60l * 60l * 24l; + + QString name("Series "); + int nameIndex = 0; + foreach (DataList list, table) { + QLineSeries *series = new QLineSeries(chart); + foreach (Data data, list) { + QPointF point = data.first; + series->append(day * 365l * 30l + point.x() * day * 365l, point.y()); + } + series->setName(name + QString::number(nameIndex)); + nameIndex++; + chart->addSeries(series); + chart->setAxisX(datetimeaxis, series); + chart->setAxisY(valueaxis, series); + } + + return chart; + } +}; + +class DateTimeAxisXTitle: public DateTimeAxisX +{ +public: + QString name() { return "AxisX Title"; } + + QChart *createChart(const DataTable &table) + { + QChart *chart = DateTimeAxisX::createChart(table); + chart->axisX()->setTitleText("Axis X"); + chart->axisY()->setTitleText("Axis Y"); + chart->setTitle("DateTime X , Value Y, Title"); + return chart; + } +}; + + +DECLARE_CHART(DateTimeAxisX); +DECLARE_CHART(DateTimeAxisXTitle); diff --git a/tests/manual/chartviewer/charts/axis/datetimeaxisy.cpp b/tests/manual/chartviewer/charts/axis/datetimeaxisy.cpp new file mode 100644 index 00000000..0234eb6a --- /dev/null +++ b/tests/manual/chartviewer/charts/axis/datetimeaxisy.cpp @@ -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$ +** +****************************************************************************/ + +#include "charts.h" +#include <QtCharts/QChart> +#include <QtCharts/QLineSeries> +#include <QtCharts/QValueAxis> +#include <QtCharts/QDateTimeAxis> + +class DateTimeAxisY: public Chart +{ +public: + QString name() { return "AxisY"; } + QString category() { return QObject::tr("Axis"); } + QString subCategory() { return "DateTimeAxis"; } + + QChart *createChart(const DataTable &table) + { + QChart *chart = new QChart(); + chart->setTitle("Value X , DateTime Y"); + QValueAxis *valueaxis = new QValueAxis(); + QDateTimeAxis *datetimeaxis = new QDateTimeAxis(); + datetimeaxis->setTickCount(10); + datetimeaxis->setFormat("yyyy"); + + qreal day = 1000l * 60l * 60l * 24l; + + QString name("Series "); + int nameIndex = 0; + foreach (DataList list, table) { + QLineSeries *series = new QLineSeries(chart); + foreach (Data data, list) { + QPointF point = data.first; + series->append(point.x(), day * 365l * 30l + point.y() * day * 365l); + } + series->setName(name + QString::number(nameIndex)); + nameIndex++; + chart->addSeries(series); + chart->setAxisY(datetimeaxis, series); + chart->setAxisX(valueaxis, series); + } + + return chart; + } +}; + +class DateTimeAxisYTitle: public DateTimeAxisY +{ +public: + QString name() { return "AxisY Title"; } + + QChart *createChart(const DataTable &table) + { + QChart *chart = DateTimeAxisY::createChart(table); + chart->axisX()->setTitleText("Axis X"); + chart->axisY()->setTitleText("Axis Y"); + chart->setTitle("Value X , DateTime Y, Title"); + return chart; + } +}; + +DECLARE_CHART(DateTimeAxisY); +DECLARE_CHART(DateTimeAxisYTitle); diff --git a/tests/manual/chartviewer/charts/axis/logvalueaxisx.cpp b/tests/manual/chartviewer/charts/axis/logvalueaxisx.cpp new file mode 100644 index 00000000..d60a1f18 --- /dev/null +++ b/tests/manual/chartviewer/charts/axis/logvalueaxisx.cpp @@ -0,0 +1,76 @@ +/**************************************************************************** +** +** 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 "charts.h" +#include <QtCharts/QChart> +#include <QtCharts/QLineSeries> +#include <QtCharts/QLogValueAxis> +#include <QtCharts/QCategoryAxis> + +class LogValueAxisX: public Chart +{ +public: + QString name() { return "LogValueAxisX"; } + QString category() { return QObject::tr("Axis"); } + QString subCategory() { return QObject::tr("Log"); } + + QChart *createChart(const DataTable &table) + { + QChart *chart = new QChart(); + chart->setTitle("LogValue X , Value Y"); + + QString name("Series "); + int nameIndex = 0; + foreach (DataList list, table) { + 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(); + QLogValueAxis *axis = new QLogValueAxis(); + axis->setBase(1.2); + foreach (QAbstractSeries *series, chart->series()) + chart->setAxisX(axis, series); + + return chart; + } +}; + +class LogValueAxisTitleX: public LogValueAxisX +{ +public: + QString name() { return "LogValueAxisXTitle"; } + + QChart *createChart(const DataTable &table) + { + QChart *chart = LogValueAxisX::createChart(table); + chart->axisX()->setTitleText("Axis X"); + chart->axisY()->setTitleText("Axis Y"); + chart->setTitle("Log Value X , Value Y, title"); + return chart; + } +}; + +DECLARE_CHART(LogValueAxisX); +DECLARE_CHART(LogValueAxisTitleX); diff --git a/tests/manual/chartviewer/charts/axis/logvalueaxisy.cpp b/tests/manual/chartviewer/charts/axis/logvalueaxisy.cpp new file mode 100644 index 00000000..cc631515 --- /dev/null +++ b/tests/manual/chartviewer/charts/axis/logvalueaxisy.cpp @@ -0,0 +1,76 @@ +/**************************************************************************** +** +** 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 "charts.h" +#include <QtCharts/QChart> +#include <QtCharts/QLineSeries> +#include <QtCharts/QLogValueAxis> +#include <QtCharts/QCategoryAxis> + +class LogValueAxisY: public Chart +{ +public: + QString name() { return "LogValueAxisY"; } + QString category() { return QObject::tr("Axis"); } + QString subCategory() { return QObject::tr("Log"); } + + QChart *createChart(const DataTable &table) + { + QChart *chart = new QChart(); + chart->setTitle("Value X , LogValue Y"); + + QString name("Series "); + int nameIndex = 0; + foreach (DataList list, table) { + 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(); + QLogValueAxis *axis = new QLogValueAxis(); + axis->setBase(2); + foreach (QAbstractSeries *series, chart->series()) + chart->setAxisY(axis, series); + + return chart; + } +}; + +class LogValueAxisTitleY: public LogValueAxisY +{ +public: + QString name() { return "LogValueAxisYTitle"; } + + QChart *createChart(const DataTable &table) + { + QChart *chart = LogValueAxisY::createChart(table); + chart->axisX()->setTitleText("Axis X"); + chart->axisY()->setTitleText("Axis Y"); + chart->setTitle("Value X , Log Value Y, title"); + return chart; + } +}; + +DECLARE_CHART(LogValueAxisY); +DECLARE_CHART(LogValueAxisTitleY); diff --git a/tests/manual/chartviewer/charts/axis/valueaxis.cpp b/tests/manual/chartviewer/charts/axis/valueaxis.cpp new file mode 100644 index 00000000..9bbfb0c9 --- /dev/null +++ b/tests/manual/chartviewer/charts/axis/valueaxis.cpp @@ -0,0 +1,75 @@ +/**************************************************************************** +** +** 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 "charts.h" +#include <QtCharts/QChart> +#include <QtCharts/QLineSeries> +#include <QtCharts/QValueAxis> +#include <QtCharts/QCategoryAxis> + +class ValueAxis: public Chart +{ +public: + QString name() { return "ValueAxis"; } + QString category() { return QObject::tr("Axis"); } + QString subCategory() { return QString::null; } + + QChart *createChart(const DataTable &table) + { + QChart *chart = new QChart(); + chart->setTitle("Value X , Value Y"); + + QString name("Series "); + int nameIndex = 0; + foreach (DataList list, table) { + 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(); + QValueAxis *axis = new QValueAxis(); + foreach (QAbstractSeries *series, chart->series()) + chart->setAxisX(axis, series); + + return chart; + } +}; + +class ValueAxisTitle: public ValueAxis +{ +public: + QString name() { return "ValueAxis Title"; } + + QChart *createChart(const DataTable &table) + { + QChart *chart = ValueAxis::createChart(table); + chart->axisX()->setTitleText("Axis X"); + chart->axisY()->setTitleText("Axis Y"); + chart->setTitle("Value X , Value Y, title"); + return chart; + } +}; + +DECLARE_CHART(ValueAxis); +DECLARE_CHART(ValueAxisTitle); diff --git a/tests/manual/chartviewer/charts/barseries/horizontalbarchart.cpp b/tests/manual/chartviewer/charts/barseries/horizontalbarchart.cpp new file mode 100644 index 00000000..3cc1887e --- /dev/null +++ b/tests/manual/chartviewer/charts/barseries/horizontalbarchart.cpp @@ -0,0 +1,51 @@ +/**************************************************************************** +** +** 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 "charts.h" +#include <QtCharts/QChart> +#include <QtCharts/QHorizontalBarSeries> +#include <QtCharts/QBarSet> + +class HorizontalBarChart: public Chart +{ +public: + QString name() { return QObject::tr("HorizontalBarChart"); } + QString category() { return QObject::tr("BarSeries"); } + QString subCategory() { return QObject::tr("Horizontal"); } + + QChart *createChart(const DataTable &table) + { + QChart *chart = new QChart(); + chart->setTitle("Horizontal bar chart"); + QHorizontalBarSeries *series = new QHorizontalBarSeries(chart); + for (int i(0); i < table.count(); i++) { + QBarSet *set = new QBarSet("Bar set " + QString::number(i)); + foreach (Data data, table[i]) + *set << data.first.y(); + series->append(set); + } + chart->addSeries(series); + chart->createDefaultAxes(); + return chart; + } +}; + +DECLARE_CHART(HorizontalBarChart) + diff --git a/tests/manual/chartviewer/charts/barseries/horizontalpercentbarchart.cpp b/tests/manual/chartviewer/charts/barseries/horizontalpercentbarchart.cpp new file mode 100644 index 00000000..71cd14f0 --- /dev/null +++ b/tests/manual/chartviewer/charts/barseries/horizontalpercentbarchart.cpp @@ -0,0 +1,51 @@ +/**************************************************************************** +** +** 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 "charts.h" +#include <QtCharts/QChart> +#include <QtCharts/QHorizontalPercentBarSeries> +#include <QtCharts/QBarSet> + +class HorizontalPercentBarChart: public Chart +{ +public: + QString name() { return QObject::tr("HorizontalPercentBarChart"); } + QString category() { return QObject::tr("BarSeries"); } + QString subCategory() { return QObject::tr("Horizontal"); } + + QChart *createChart(const DataTable &table) + { + QChart *chart = new QChart(); + chart->setTitle("Horizontal percent chart"); + QHorizontalPercentBarSeries *series = new QHorizontalPercentBarSeries(chart); + for (int i(0); i < table.count(); i++) { + QBarSet *set = new QBarSet("Bar set " + QString::number(i)); + foreach (Data data, table[i]) + *set << data.first.y(); + series->append(set); + } + chart->addSeries(series); + chart->createDefaultAxes(); + return chart; + } +}; + +DECLARE_CHART(HorizontalPercentBarChart) + diff --git a/tests/manual/chartviewer/charts/barseries/horizontalstackedbarchart.cpp b/tests/manual/chartviewer/charts/barseries/horizontalstackedbarchart.cpp new file mode 100644 index 00000000..7dab6791 --- /dev/null +++ b/tests/manual/chartviewer/charts/barseries/horizontalstackedbarchart.cpp @@ -0,0 +1,51 @@ +/**************************************************************************** +** +** 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 "charts.h" +#include <QtCharts/QChart> +#include <QtCharts/QHorizontalStackedBarSeries> +#include <QtCharts/QBarSet> + +class HorizontalStackedBarChart: public Chart +{ +public: + QString name() { return QObject::tr("HorizontalStackedBarChart"); } + QString category() { return QObject::tr("BarSeries"); } + QString subCategory() { return QObject::tr("Horizontal"); } + + QChart *createChart(const DataTable &table) + { + QChart *chart = new QChart(); + chart->setTitle("Horizontal stacked chart"); + QHorizontalStackedBarSeries *series = new QHorizontalStackedBarSeries(chart); + for (int i(0); i < table.count(); i++) { + QBarSet *set = new QBarSet("Bar set " + QString::number(i)); + foreach (Data data, table[i]) + *set << data.first.y(); + series->append(set); + } + chart->addSeries(series); + chart->createDefaultAxes(); + return chart; + } +}; + +DECLARE_CHART(HorizontalStackedBarChart) + diff --git a/tests/manual/chartviewer/charts/barseries/verticalbarchart.cpp b/tests/manual/chartviewer/charts/barseries/verticalbarchart.cpp new file mode 100644 index 00000000..d7dbbaa0 --- /dev/null +++ b/tests/manual/chartviewer/charts/barseries/verticalbarchart.cpp @@ -0,0 +1,51 @@ +/**************************************************************************** +** +** 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 "charts.h" +#include <QtCharts/QChart> +#include <QtCharts/QBarSeries> +#include <QtCharts/QBarSet> + +class VerticalBarChart: public Chart +{ +public: + QString name() { return QObject::tr("VerticalBarChart"); } + QString category() { return QObject::tr("BarSeries"); } + QString subCategory() { return QObject::tr("Vertical"); } + + QChart *createChart(const DataTable &table) + { + QChart *chart = new QChart(); + chart->setTitle("Vertical bar chart"); + QBarSeries *series = new QBarSeries(chart); + for (int i(0); i < table.count(); i++) { + QBarSet *set = new QBarSet("Bar set " + QString::number(i)); + foreach (Data data, table[i]) + *set << data.first.y(); + series->append(set); + } + chart->addSeries(series); + chart->createDefaultAxes(); + return chart; + } +}; + +DECLARE_CHART(VerticalBarChart) + diff --git a/tests/manual/chartviewer/charts/barseries/verticalpercentbarchart.cpp b/tests/manual/chartviewer/charts/barseries/verticalpercentbarchart.cpp new file mode 100644 index 00000000..e219ebc0 --- /dev/null +++ b/tests/manual/chartviewer/charts/barseries/verticalpercentbarchart.cpp @@ -0,0 +1,51 @@ +/**************************************************************************** +** +** 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 "charts.h" +#include <QtCharts/QChart> +#include <QtCharts/QPercentBarSeries> +#include <QtCharts/QBarSet> + +class VerticalPercentBarChart: public Chart +{ +public: + QString name() { return QObject::tr("VerticalPercentBarChart"); } + QString category() { return QObject::tr("BarSeries"); } + QString subCategory() { return QObject::tr("Vertical"); } + + QChart *createChart(const DataTable &table) + { + QChart *chart = new QChart(); + chart->setTitle("Percent bar chart"); + QPercentBarSeries *series = new QPercentBarSeries(chart); + for (int i(0); i < table.count(); i++) { + QBarSet *set = new QBarSet("Bar set " + QString::number(i)); + foreach (Data data, table[i]) + *set << data.first.y(); + series->append(set); + } + chart->addSeries(series); + chart->createDefaultAxes(); + return chart; + } +}; + +DECLARE_CHART(VerticalPercentBarChart) + diff --git a/tests/manual/chartviewer/charts/barseries/verticalstackedbarchart.cpp b/tests/manual/chartviewer/charts/barseries/verticalstackedbarchart.cpp new file mode 100644 index 00000000..84986acc --- /dev/null +++ b/tests/manual/chartviewer/charts/barseries/verticalstackedbarchart.cpp @@ -0,0 +1,51 @@ +/**************************************************************************** +** +** 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 "charts.h" +#include <QtCharts/QChart> +#include <QtCharts/QStackedBarSeries> +#include <QtCharts/QBarSet> + +class VerticalStackedBarChart: public Chart +{ +public: + QString name() { return QObject::tr("VerticalStackedBarChart"); } + QString category() { return QObject::tr("BarSeries"); } + QString subCategory() { return QObject::tr("Vertical"); } + + QChart *createChart(const DataTable &table) + { + QChart *chart = new QChart(); + chart->setTitle("Stacked bar chart"); + QStackedBarSeries *series = new QStackedBarSeries(chart); + for (int i(0); i < table.count(); i++) { + QBarSet *set = new QBarSet("Bar set " + QString::number(i)); + foreach (Data data, table[i]) + *set << data.first.y(); + series->append(set); + } + chart->addSeries(series); + chart->createDefaultAxes(); + return chart; + } +}; + +DECLARE_CHART(VerticalStackedBarChart) + diff --git a/tests/manual/chartviewer/charts/charts.pri b/tests/manual/chartviewer/charts/charts.pri new file mode 100644 index 00000000..5bef427f --- /dev/null +++ b/tests/manual/chartviewer/charts/charts.pri @@ -0,0 +1,51 @@ +INCLUDEPATH += $$PWD +DEPENDPATH += $$PWD +SOURCES += \ + $$PWD/font/font.cpp \ + $$PWD/xyseries/linechart.cpp \ + $$PWD/xyseries/scatterchart.cpp \ + $$PWD/xyseries/splinechart.cpp \ + $$PWD/xyseries/areachart.cpp \ + $$PWD/barseries/verticalstackedbarchart.cpp \ + $$PWD/barseries/horizontalstackedbarchart.cpp \ + $$PWD/barseries/verticalbarchart.cpp \ + $$PWD/barseries/horizontalbarchart.cpp \ + $$PWD/barseries/horizontalpercentbarchart.cpp \ + $$PWD/barseries/verticalpercentbarchart.cpp \ + $$PWD/pieseries/piechart.cpp \ + $$PWD/pieseries/donutchart.cpp \ + $$PWD/axis/valueaxis.cpp \ + $$PWD/axis/logvalueaxisx.cpp \ + $$PWD/axis/logvalueaxisy.cpp \ + $$PWD/axis/categoryaxis.cpp \ + $$PWD/axis/barcategoryaxisx.cpp \ + $$PWD/axis/barcategoryaxisy.cpp \ + $$PWD/axis/barcategoryaxisxlogy.cpp \ + $$PWD/axis/barcategoryaxisylogx.cpp \ + $$PWD/multiaxis/multivalueaxis.cpp \ + $$PWD/multiaxis/multivalueaxis2.cpp \ + $$PWD/multiaxis/multivalueaxis3.cpp \ + $$PWD/multiaxis/multivalueaxis4.cpp \ + $$PWD/multiaxis/multivaluebaraxis.cpp \ + $$PWD/size/sizecharts.cpp \ + $$PWD/domain/barlogy.cpp \ + $$PWD/domain/barlogx.cpp \ + $$PWD/domain/barstackedlogy.cpp \ + $$PWD/domain/barstackedlogx.cpp \ + $$PWD/domain/barpercentlogy.cpp \ + $$PWD/domain/barpercentlogx.cpp \ + $$PWD/domain/linelogxlogy.cpp \ + $$PWD/domain/linelogxy.cpp \ + $$PWD/domain/linexlogy.cpp \ + $$PWD/domain/splinelogxlogy.cpp \ + $$PWD/domain/splinelogxy.cpp \ + $$PWD/domain/splinexlogy.cpp \ + $$PWD/domain/scatterlogxlogy.cpp \ + $$PWD/domain/scatterlogxy.cpp \ + $$PWD/domain/scatterxlogy.cpp + +!linux-arm*: { +SOURCES += \ + $$PWD/axis/datetimeaxisx.cpp \ + $$PWD/axis/datetimeaxisy.cpp +} diff --git a/tests/manual/chartviewer/charts/domain/barlogx.cpp b/tests/manual/chartviewer/charts/domain/barlogx.cpp new file mode 100644 index 00000000..32a36755 --- /dev/null +++ b/tests/manual/chartviewer/charts/domain/barlogx.cpp @@ -0,0 +1,67 @@ +/**************************************************************************** +** +** 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 "charts.h" +#include <QtCharts/QChart> +#include <QtCharts/QHorizontalBarSeries> +#include <QtCharts/QBarSet> +#include <QtCharts/QLogValueAxis> +#include <QtCharts/QBarCategoryAxis> + +class BarLogX: public Chart +{ +public: + QString name() { return "Horizontal Bar"; } + QString category() { return QObject::tr("Domain"); } + QString subCategory() { return "Horizontal Log"; } + + QChart *createChart(const DataTable &table) + { + QChart *chart = new QChart(); + chart->setTitle("Bar: Log X, BarCateogry Y"); + + QString name("Series "); + QHorizontalBarSeries *series = new QHorizontalBarSeries(chart); + QLogValueAxis *logvalueaxis = new QLogValueAxis(); + logvalueaxis->setBase(2); + QBarCategoryAxis *barcategory = new QBarCategoryAxis(); + for (int i(0); i < table.count(); i++) { + QBarSet *set = new QBarSet("Bar set " + QString::number(i)); + foreach (Data data, table[i]) + *set << data.first.y(); + series->append(set); + } + chart->addSeries(series); + + int count = series->barSets().first()->count(); + + + for (int i = 0; i < count; i++) { + barcategory->append("BarSet " + QString::number(i)); + } + + chart->setAxisX(logvalueaxis, series); + chart->setAxisY(barcategory, series); + + return chart; + } +}; + +DECLARE_CHART(BarLogX); diff --git a/tests/manual/chartviewer/charts/domain/barlogy.cpp b/tests/manual/chartviewer/charts/domain/barlogy.cpp new file mode 100644 index 00000000..e8c36acd --- /dev/null +++ b/tests/manual/chartviewer/charts/domain/barlogy.cpp @@ -0,0 +1,67 @@ +/**************************************************************************** +** +** 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 "charts.h" +#include <QtCharts/QChart> +#include <QtCharts/QBarSeries> +#include <QtCharts/QBarSet> +#include <QtCharts/QLogValueAxis> +#include <QtCharts/QBarCategoryAxis> + +class BarLogY: public Chart +{ +public: + QString name() { return "Bar"; } + QString category() { return QObject::tr("Domain"); } + QString subCategory() { return "Vertical Log"; } + + QChart *createChart(const DataTable &table) + { + QChart *chart = new QChart(); + chart->setTitle("Bar: BarCateogry X, Log Y"); + + QString name("Series "); + QBarSeries *series = new QBarSeries(chart); + QLogValueAxis *logvalueaxis = new QLogValueAxis(); + logvalueaxis->setBase(2); + QBarCategoryAxis *barcategory = new QBarCategoryAxis(); + for (int i(0); i < table.count(); i++) { + QBarSet *set = new QBarSet("Bar set " + QString::number(i)); + foreach (Data data, table[i]) + *set << data.first.y(); + series->append(set); + } + chart->addSeries(series); + + int count = series->barSets().first()->count(); + + + for (int i = 0; i < count; i++) { + barcategory->append("BarSet " + QString::number(i)); + } + + chart->setAxisY(logvalueaxis, series); + chart->setAxisX(barcategory, series); + + return chart; + } +}; + +DECLARE_CHART(BarLogY); diff --git a/tests/manual/chartviewer/charts/domain/barpercentlogx.cpp b/tests/manual/chartviewer/charts/domain/barpercentlogx.cpp new file mode 100644 index 00000000..ce61c5cc --- /dev/null +++ b/tests/manual/chartviewer/charts/domain/barpercentlogx.cpp @@ -0,0 +1,67 @@ +/**************************************************************************** +** +** 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 "charts.h" +#include <QtCharts/QChart> +#include <QtCharts/QHorizontalPercentBarSeries> +#include <QtCharts/QBarSet> +#include <QtCharts/QLogValueAxis> +#include <QtCharts/QBarCategoryAxis> + +class BarPercentLogX: public Chart +{ +public: + QString name() { return "Horizontal PercentBar"; } + QString category() { return QObject::tr("Domain"); } + QString subCategory() { return "Horizontal Log"; } + + QChart *createChart(const DataTable &table) + { + QChart *chart = new QChart(); + chart->setTitle("PercentBar: Log X, BarCateogry Y"); + + QString name("Series "); + QHorizontalPercentBarSeries *series = new QHorizontalPercentBarSeries(chart); + QLogValueAxis *logvalueaxis = new QLogValueAxis(); + logvalueaxis->setBase(2); + QBarCategoryAxis *barcategory = new QBarCategoryAxis(); + for (int i(0); i < table.count(); i++) { + QBarSet *set = new QBarSet("Bar set " + QString::number(i)); + foreach (Data data, table[i]) + *set << data.first.y(); + series->append(set); + } + chart->addSeries(series); + + int count = series->barSets().first()->count(); + + + for (int i = 0; i < count; i++) { + barcategory->append("BarSet " + QString::number(i)); + } + + chart->setAxisX(logvalueaxis, series); + chart->setAxisY(barcategory, series); + + return chart; + } +}; + +DECLARE_CHART(BarPercentLogX); diff --git a/tests/manual/chartviewer/charts/domain/barpercentlogy.cpp b/tests/manual/chartviewer/charts/domain/barpercentlogy.cpp new file mode 100644 index 00000000..cf10e76c --- /dev/null +++ b/tests/manual/chartviewer/charts/domain/barpercentlogy.cpp @@ -0,0 +1,67 @@ +/**************************************************************************** +** +** 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 "charts.h" +#include <QtCharts/QChart> +#include <QtCharts/QPercentBarSeries> +#include <QtCharts/QBarSet> +#include <QtCharts/QLogValueAxis> +#include <QtCharts/QBarCategoryAxis> + +class BarPercentLogY: public Chart +{ +public: + QString name() { return "PercentBar"; } + QString category() { return QObject::tr("Domain"); } + QString subCategory() { return "Vertical Log"; } + + QChart *createChart(const DataTable &table) + { + QChart *chart = new QChart(); + chart->setTitle("PercentBar: BarCateogry X, Log Y"); + + QString name("Series "); + QPercentBarSeries *series = new QPercentBarSeries(chart); + QLogValueAxis *logvalueaxis = new QLogValueAxis(); + logvalueaxis->setBase(2); + QBarCategoryAxis *barcategory = new QBarCategoryAxis(); + for (int i(0); i < table.count(); i++) { + QBarSet *set = new QBarSet("Bar set " + QString::number(i)); + foreach (Data data, table[i]) + *set << data.first.y(); + series->append(set); + } + chart->addSeries(series); + + int count = series->barSets().first()->count(); + + + for (int i = 0; i < count; i++) { + barcategory->append("BarSet " + QString::number(i)); + } + + chart->setAxisY(logvalueaxis, series); + chart->setAxisX(barcategory, series); + + return chart; + } +}; + +DECLARE_CHART(BarPercentLogY); diff --git a/tests/manual/chartviewer/charts/domain/barstackedlogx.cpp b/tests/manual/chartviewer/charts/domain/barstackedlogx.cpp new file mode 100644 index 00000000..e10445f1 --- /dev/null +++ b/tests/manual/chartviewer/charts/domain/barstackedlogx.cpp @@ -0,0 +1,67 @@ +/**************************************************************************** +** +** 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 "charts.h" +#include <QtCharts/QChart> +#include <QtCharts/QHorizontalStackedBarSeries> +#include <QtCharts/QBarSet> +#include <QtCharts/QLogValueAxis> +#include <QtCharts/QBarCategoryAxis> + +class BarStackedLogX: public Chart +{ +public: + QString name() { return "Horizontal StackedBar"; } + QString category() { return QObject::tr("Domain"); } + QString subCategory() { return "Horizontal Log"; } + + QChart *createChart(const DataTable &table) + { + QChart *chart = new QChart(); + chart->setTitle("StackedBar: Log X, BarCateogry Y"); + + QString name("Series "); + QHorizontalStackedBarSeries *series = new QHorizontalStackedBarSeries(chart); + QLogValueAxis *logvalueaxis = new QLogValueAxis(); + logvalueaxis->setBase(2); + QBarCategoryAxis *barcategory = new QBarCategoryAxis(); + for (int i(0); i < table.count(); i++) { + QBarSet *set = new QBarSet("Bar set " + QString::number(i)); + foreach (Data data, table[i]) + *set << data.first.y(); + series->append(set); + } + chart->addSeries(series); + + int count = series->barSets().first()->count(); + + + for (int i = 0; i < count; i++) { + barcategory->append("BarSet " + QString::number(i)); + } + + chart->setAxisX(logvalueaxis, series); + chart->setAxisY(barcategory, series); + + return chart; + } +}; + +DECLARE_CHART(BarStackedLogX); diff --git a/tests/manual/chartviewer/charts/domain/barstackedlogy.cpp b/tests/manual/chartviewer/charts/domain/barstackedlogy.cpp new file mode 100644 index 00000000..114252d9 --- /dev/null +++ b/tests/manual/chartviewer/charts/domain/barstackedlogy.cpp @@ -0,0 +1,67 @@ +/**************************************************************************** +** +** 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 "charts.h" +#include <QtCharts/QChart> +#include <QtCharts/QStackedBarSeries> +#include <QtCharts/QBarSet> +#include <QtCharts/QLogValueAxis> +#include <QtCharts/QBarCategoryAxis> + +class BarStackedLogY: public Chart +{ +public: + QString name() { return "StackedBar"; } + QString category() { return QObject::tr("Domain"); } + QString subCategory() { return "Vertical Log"; } + + QChart *createChart(const DataTable &table) + { + QChart *chart = new QChart(); + chart->setTitle("StackedBar: BarCateogry X, Log Y"); + + QString name("Series "); + QStackedBarSeries *series = new QStackedBarSeries(chart); + QLogValueAxis *logvalueaxis = new QLogValueAxis(); + logvalueaxis->setBase(2); + QBarCategoryAxis *barcategory = new QBarCategoryAxis(); + for (int i(0); i < table.count(); i++) { + QBarSet *set = new QBarSet("Bar set " + QString::number(i)); + foreach (Data data, table[i]) + *set << data.first.y(); + series->append(set); + } + chart->addSeries(series); + + int count = series->barSets().first()->count(); + + + for (int i = 0; i < count; i++) { + barcategory->append("BarSet " + QString::number(i)); + } + + chart->setAxisY(logvalueaxis, series); + chart->setAxisX(barcategory, series); + + return chart; + } +}; + +DECLARE_CHART(BarStackedLogY); diff --git a/tests/manual/chartviewer/charts/domain/linelogxlogy.cpp b/tests/manual/chartviewer/charts/domain/linelogxlogy.cpp new file mode 100644 index 00000000..dea1ef04 --- /dev/null +++ b/tests/manual/chartviewer/charts/domain/linelogxlogy.cpp @@ -0,0 +1,62 @@ +/**************************************************************************** +** +** 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 "charts.h" +#include <QtCharts/QChart> +#include <QtCharts/QLineSeries> +#include <QtCharts/QLogValueAxis> + +class LineLogXLogY: public Chart +{ +public: + QString name() { return "Line LogX LogY"; } + QString category() { return QObject::tr("Domain"); } + QString subCategory() { return QObject::tr("Both Log"); } + + QChart *createChart(const DataTable &table) + { + QChart *chart = new QChart(); + chart->setTitle("Line: Log X, Log Y"); + + QString name("Series "); + int nameIndex = 0; + foreach (DataList list, table) { + QLineSeries *series = new QLineSeries(chart); + foreach (Data data, list) + series->append(data.first); + series->setName(name + QString::number(nameIndex)); + nameIndex++; + chart->addSeries(series); + } + + QLogValueAxis *axisX= new QLogValueAxis(); + axisX->setBase(2); + QLogValueAxis *axisY= new QLogValueAxis(); + axisY->setBase(2); + foreach (QAbstractSeries *series, chart->series()) { + chart->setAxisX(axisX, series); + chart->setAxisY(axisY, series); + } + + return chart; + } +}; + +DECLARE_CHART(LineLogXLogY); diff --git a/tests/manual/chartviewer/charts/domain/linelogxy.cpp b/tests/manual/chartviewer/charts/domain/linelogxy.cpp new file mode 100644 index 00000000..ca0d7cf1 --- /dev/null +++ b/tests/manual/chartviewer/charts/domain/linelogxy.cpp @@ -0,0 +1,62 @@ +/**************************************************************************** +** +** 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 "charts.h" +#include <QtCharts/QChart> +#include <QtCharts/QLineSeries> +#include <QtCharts/QLogValueAxis> +#include <QtCharts/QValueAxis> + +class LineLogXY: public Chart +{ +public: + QString name() { return "Line LogX Y"; } + QString category() { return QObject::tr("Domain"); } + QString subCategory() { return QObject::tr("Both Log"); } + + QChart *createChart(const DataTable &table) + { + QChart *chart = new QChart(); + chart->setTitle("Line: Log X, Y"); + + QString name("Series "); + int nameIndex = 0; + foreach (DataList list, table) { + QLineSeries *series = new QLineSeries(chart); + foreach (Data data, list) + series->append(data.first); + series->setName(name + QString::number(nameIndex)); + nameIndex++; + chart->addSeries(series); + } + + QLogValueAxis *axisX= new QLogValueAxis(); + axisX->setBase(2); + QValueAxis *axisY= new QValueAxis(); + foreach (QAbstractSeries *series, chart->series()) { + chart->setAxisX(axisX, series); + chart->setAxisY(axisY, series); + } + + return chart; + } +}; + +DECLARE_CHART(LineLogXY); diff --git a/tests/manual/chartviewer/charts/domain/linexlogy.cpp b/tests/manual/chartviewer/charts/domain/linexlogy.cpp new file mode 100644 index 00000000..16ec254d --- /dev/null +++ b/tests/manual/chartviewer/charts/domain/linexlogy.cpp @@ -0,0 +1,62 @@ +/**************************************************************************** +** +** 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 "charts.h" +#include <QtCharts/QChart> +#include <QtCharts/QLineSeries> +#include <QtCharts/QLogValueAxis> +#include <QtCharts/QValueAxis> + +class LineXLogY: public Chart +{ +public: + QString name() { return "Line X LogY"; } + QString category() { return QObject::tr("Domain"); } + QString subCategory() { return QObject::tr("Both Log"); } + + QChart *createChart(const DataTable &table) + { + QChart *chart = new QChart(); + chart->setTitle("Line: X, Log Y"); + + QString name("Series "); + int nameIndex = 0; + foreach (DataList list, table) { + QLineSeries *series = new QLineSeries(chart); + foreach (Data data, list) + series->append(data.first); + series->setName(name + QString::number(nameIndex)); + nameIndex++; + chart->addSeries(series); + } + + QValueAxis *axisX= new QValueAxis(); + QLogValueAxis *axisY= new QLogValueAxis(); + axisY->setBase(2); + foreach (QAbstractSeries *series, chart->series()) { + chart->setAxisX(axisX, series); + chart->setAxisY(axisY, series); + } + + return chart; + } +}; + +DECLARE_CHART(LineXLogY); diff --git a/tests/manual/chartviewer/charts/domain/scatterlogxlogy.cpp b/tests/manual/chartviewer/charts/domain/scatterlogxlogy.cpp new file mode 100644 index 00000000..c87def5c --- /dev/null +++ b/tests/manual/chartviewer/charts/domain/scatterlogxlogy.cpp @@ -0,0 +1,62 @@ +/**************************************************************************** +** +** 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 "charts.h" +#include <QtCharts/QChart> +#include <QtCharts/QScatterSeries> +#include <QtCharts/QLogValueAxis> + +class ScatterLogXLogY: public Chart +{ +public: + QString name() { return "Scatter LogX LogY"; } + QString category() { return QObject::tr("Domain"); } + QString subCategory() { return QObject::tr("Both Log"); } + + QChart *createChart(const DataTable &table) + { + QChart *chart = new QChart(); + chart->setTitle("Scatter: Log X, Log Y"); + + QString name("Series "); + int nameIndex = 0; + foreach (DataList list, table) { + QScatterSeries *series = new QScatterSeries(chart); + foreach (Data data, list) + series->append(data.first); + series->setName(name + QString::number(nameIndex)); + nameIndex++; + chart->addSeries(series); + } + + QLogValueAxis *axisX= new QLogValueAxis(); + axisX->setBase(2); + QLogValueAxis *axisY= new QLogValueAxis(); + axisY->setBase(2); + foreach (QAbstractSeries *series, chart->series()) { + chart->setAxisX(axisX, series); + chart->setAxisY(axisY, series); + } + + return chart; + } +}; + +DECLARE_CHART(ScatterLogXLogY); diff --git a/tests/manual/chartviewer/charts/domain/scatterlogxy.cpp b/tests/manual/chartviewer/charts/domain/scatterlogxy.cpp new file mode 100644 index 00000000..d7603616 --- /dev/null +++ b/tests/manual/chartviewer/charts/domain/scatterlogxy.cpp @@ -0,0 +1,62 @@ +/**************************************************************************** +** +** 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 "charts.h" +#include <QtCharts/QChart> +#include <QtCharts/QScatterSeries> +#include <QtCharts/QLogValueAxis> +#include <QtCharts/QValueAxis> + +class ScatterLogXY: public Chart +{ +public: + QString name() { return "Scatter LogX Y"; } + QString category() { return QObject::tr("Domain"); } + QString subCategory() { return QObject::tr("Both Log"); } + + QChart *createChart(const DataTable &table) + { + QChart *chart = new QChart(); + chart->setTitle("Scatter: Log X, Y"); + + QString name("Series "); + int nameIndex = 0; + foreach (DataList list, table) { + QScatterSeries *series = new QScatterSeries(chart); + foreach (Data data, list) + series->append(data.first); + series->setName(name + QString::number(nameIndex)); + nameIndex++; + chart->addSeries(series); + } + + QLogValueAxis *axisX= new QLogValueAxis(); + axisX->setBase(2); + QValueAxis *axisY= new QValueAxis(); + foreach (QAbstractSeries *series, chart->series()) { + chart->setAxisX(axisX, series); + chart->setAxisY(axisY, series); + } + + return chart; + } +}; + +DECLARE_CHART(ScatterLogXY); diff --git a/tests/manual/chartviewer/charts/domain/scatterxlogy.cpp b/tests/manual/chartviewer/charts/domain/scatterxlogy.cpp new file mode 100644 index 00000000..bc09bf66 --- /dev/null +++ b/tests/manual/chartviewer/charts/domain/scatterxlogy.cpp @@ -0,0 +1,62 @@ +/**************************************************************************** +** +** 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 "charts.h" +#include <QtCharts/QChart> +#include <QtCharts/QScatterSeries> +#include <QtCharts/QLogValueAxis> +#include <QtCharts/QValueAxis> + +class ScatterXLogY: public Chart +{ +public: + QString name() { return "Scatter X LogY"; } + QString category() { return QObject::tr("Domain"); } + QString subCategory() { return QObject::tr("Both Log"); } + + QChart *createChart(const DataTable &table) + { + QChart *chart = new QChart(); + chart->setTitle("Scatter: X, Log Y"); + + QString name("Series "); + int nameIndex = 0; + foreach (DataList list, table) { + QScatterSeries *series = new QScatterSeries(chart); + foreach (Data data, list) + series->append(data.first); + series->setName(name + QString::number(nameIndex)); + nameIndex++; + chart->addSeries(series); + } + + QValueAxis *axisX= new QValueAxis(); + QLogValueAxis *axisY= new QLogValueAxis(); + axisY->setBase(2); + foreach (QAbstractSeries *series, chart->series()) { + chart->setAxisX(axisX, series); + chart->setAxisY(axisY, series); + } + + return chart; + } +}; + +DECLARE_CHART(ScatterXLogY); diff --git a/tests/manual/chartviewer/charts/domain/splinelogxlogy.cpp b/tests/manual/chartviewer/charts/domain/splinelogxlogy.cpp new file mode 100644 index 00000000..b87a4bb7 --- /dev/null +++ b/tests/manual/chartviewer/charts/domain/splinelogxlogy.cpp @@ -0,0 +1,62 @@ +/**************************************************************************** +** +** 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 "charts.h" +#include <QtCharts/QChart> +#include <QtCharts/QSplineSeries> +#include <QtCharts/QLogValueAxis> + +class SplineLogXLogY: public Chart +{ +public: + QString name() { return "Spline LogX LogY"; } + QString category() { return QObject::tr("Domain"); } + QString subCategory() { return QObject::tr("Both Log"); } + + QChart *createChart(const DataTable &table) + { + QChart *chart = new QChart(); + chart->setTitle("Spline: Log X, Log Y"); + + QString name("Series "); + int nameIndex = 0; + foreach (DataList list, table) { + QSplineSeries *series = new QSplineSeries(chart); + foreach (Data data, list) + series->append(data.first); + series->setName(name + QString::number(nameIndex)); + nameIndex++; + chart->addSeries(series); + } + + QLogValueAxis *axisX= new QLogValueAxis(); + axisX->setBase(2); + QLogValueAxis *axisY= new QLogValueAxis(); + axisY->setBase(2); + foreach (QAbstractSeries *series, chart->series()) { + chart->setAxisX(axisX, series); + chart->setAxisY(axisY, series); + } + + return chart; + } +}; + +DECLARE_CHART(SplineLogXLogY); diff --git a/tests/manual/chartviewer/charts/domain/splinelogxy.cpp b/tests/manual/chartviewer/charts/domain/splinelogxy.cpp new file mode 100644 index 00000000..0354aadf --- /dev/null +++ b/tests/manual/chartviewer/charts/domain/splinelogxy.cpp @@ -0,0 +1,62 @@ +/**************************************************************************** +** +** 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 "charts.h" +#include <QtCharts/QChart> +#include <QtCharts/QSplineSeries> +#include <QtCharts/QLogValueAxis> +#include <QtCharts/QValueAxis> + +class SplineLogXY: public Chart +{ +public: + QString name() { return "Spline LogX Y"; } + QString category() { return QObject::tr("Domain"); } + QString subCategory() { return QObject::tr("Both Log"); } + + QChart *createChart(const DataTable &table) + { + QChart *chart = new QChart(); + chart->setTitle("Spline: Log X, Y"); + + QString name("Series "); + int nameIndex = 0; + foreach (DataList list, table) { + QSplineSeries *series = new QSplineSeries(chart); + foreach (Data data, list) + series->append(data.first); + series->setName(name + QString::number(nameIndex)); + nameIndex++; + chart->addSeries(series); + } + + QLogValueAxis *axisX= new QLogValueAxis(); + axisX->setBase(2); + QValueAxis *axisY= new QValueAxis(); + foreach (QAbstractSeries *series, chart->series()) { + chart->setAxisX(axisX, series); + chart->setAxisY(axisY, series); + } + + return chart; + } +}; + +DECLARE_CHART(SplineLogXY); diff --git a/tests/manual/chartviewer/charts/domain/splinexlogy.cpp b/tests/manual/chartviewer/charts/domain/splinexlogy.cpp new file mode 100644 index 00000000..6a6d8210 --- /dev/null +++ b/tests/manual/chartviewer/charts/domain/splinexlogy.cpp @@ -0,0 +1,62 @@ +/**************************************************************************** +** +** 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 "charts.h" +#include <QtCharts/QChart> +#include <QtCharts/QSplineSeries> +#include <QtCharts/QLogValueAxis> +#include <QtCharts/QValueAxis> + +class SplineXLogY: public Chart +{ +public: + QString name() { return "Spline X LogY"; } + QString category() { return QObject::tr("Domain"); } + QString subCategory() { return QObject::tr("Both Log"); } + + QChart *createChart(const DataTable &table) + { + QChart *chart = new QChart(); + chart->setTitle("Spline: X, Log Y"); + + QString name("Series "); + int nameIndex = 0; + foreach (DataList list, table) { + QSplineSeries *series = new QSplineSeries(chart); + foreach (Data data, list) + series->append(data.first); + series->setName(name + QString::number(nameIndex)); + nameIndex++; + chart->addSeries(series); + } + + QValueAxis *axisX= new QValueAxis(); + QLogValueAxis *axisY= new QLogValueAxis(); + axisY->setBase(2); + foreach (QAbstractSeries *series, chart->series()) { + chart->setAxisX(axisX, series); + chart->setAxisY(axisY, series); + } + + return chart; + } +}; + +DECLARE_CHART(SplineXLogY); diff --git a/tests/manual/chartviewer/charts/font/font.cpp b/tests/manual/chartviewer/charts/font/font.cpp new file mode 100644 index 00000000..b544ca94 --- /dev/null +++ b/tests/manual/chartviewer/charts/font/font.cpp @@ -0,0 +1,126 @@ +/**************************************************************************** +** +** 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 "charts.h" +#include <QtCharts/QChart> +#include <QtCharts/QLineSeries> + +class FontChart: public Chart +{ +public: + FontChart(int fontSize): m_fontSize(fontSize) {}; + QString name() { return QObject::tr("Font") + " " + QString::number(m_fontSize); } + QString category() { return QObject::tr("Font"); } + QString subCategory() { return QString::null; } + + QChart *createChart(const DataTable &table) + { + QChart *chart = new QChart(); + chart->setTitle("Font size " + QString::number(m_fontSize)); + QString name("Series "); + int nameIndex = 0; + foreach (DataList list, table) { + 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(); + QFont font; + font.setPixelSize(m_fontSize); + chart->setTitleFont(font); + chart->axisX()->setLabelsFont(font); + chart->axisY()->setLabelsFont(font); + chart->axisX()->setTitleText("Axis X"); + chart->axisY()->setTitleText("Axis Y"); + chart->axisX()->setTitleFont(font); + chart->axisY()->setTitleFont(font); + return chart; + } + +private: + int m_fontSize; +}; + +class FontChart6: public FontChart +{ +public: + FontChart6(): FontChart(6) {}; +}; + +class FontChart8: public FontChart +{ +public: + FontChart8(): FontChart(8) {}; +}; + +class FontChart10: public FontChart +{ +public: + FontChart10(): FontChart(10) {}; +}; + +class FontChart14: public FontChart +{ +public: + FontChart14(): FontChart(14) {}; +}; + +class FontChart18: public FontChart +{ +public: + FontChart18(): FontChart(18) {}; +}; + +class FontChart20: public FontChart +{ +public: + FontChart20(): FontChart(20) {}; +}; + +class FontChart24: public FontChart +{ +public: + FontChart24(): FontChart(24) {}; +}; + +class FontChart28: public FontChart +{ +public: + FontChart28(): FontChart(28) {}; +}; + +class FontChart32: public FontChart +{ +public: + FontChart32(): FontChart(32) {}; +}; + +DECLARE_CHART(FontChart6); +DECLARE_CHART(FontChart8); +DECLARE_CHART(FontChart10); +DECLARE_CHART(FontChart14); +DECLARE_CHART(FontChart18); +DECLARE_CHART(FontChart20); +DECLARE_CHART(FontChart24); +DECLARE_CHART(FontChart28); +DECLARE_CHART(FontChart32); diff --git a/tests/manual/chartviewer/charts/multiaxis/multivalueaxis.cpp b/tests/manual/chartviewer/charts/multiaxis/multivalueaxis.cpp new file mode 100644 index 00000000..960b9c6a --- /dev/null +++ b/tests/manual/chartviewer/charts/multiaxis/multivalueaxis.cpp @@ -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$ +** +****************************************************************************/ + +#include "charts.h" +#include <QtCharts/QChart> +#include <QtCharts/QLineSeries> +#include <QtCharts/QValueAxis> +#include <QtCharts/QCategoryAxis> + +class MultiValueAxis: public Chart +{ +public: + QString name() + { + return "AxisSet 1"; + } + QString category() + { + return QObject::tr("MultiAxis"); + } + QString subCategory() + { + return "MultiValueAxis"; + } + + QChart *createChart(const DataTable &table) + { + QChart *chart = new QChart(); + QValueAxis *axisX; + QValueAxis *axisY; + + chart->setTitle("MultiValueAxis1"); + + QString name("Series"); + int nameIndex = 0; + foreach (DataList list, table) { + QLineSeries *series = new QLineSeries(chart); + foreach (Data data, list) + series->append(data.first); + series->setName(name + QString::number(nameIndex)); + + chart->addSeries(series); + axisX = new QValueAxis(); + axisX->setLinePenColor(series->pen().color()); + axisY = new QValueAxis(); + axisY->setLinePenColor(series->pen().color()); + + chart->addAxis(axisX,nameIndex % 2?Qt::AlignTop:Qt::AlignBottom); + chart->addAxis(axisY,nameIndex % 2?Qt::AlignRight:Qt::AlignLeft); + series->attachAxis(axisX); + series->attachAxis(axisY); + + nameIndex++; + } + + return chart; + } +}; + +DECLARE_CHART(MultiValueAxis); diff --git a/tests/manual/chartviewer/charts/multiaxis/multivalueaxis2.cpp b/tests/manual/chartviewer/charts/multiaxis/multivalueaxis2.cpp new file mode 100644 index 00000000..91e1d7a3 --- /dev/null +++ b/tests/manual/chartviewer/charts/multiaxis/multivalueaxis2.cpp @@ -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$ +** +****************************************************************************/ + +#include "charts.h" +#include <QtCharts/QChart> +#include <QtCharts/QLineSeries> +#include <QtCharts/QValueAxis> +#include <QtCharts/QCategoryAxis> + +class MultiValueAxis2: public Chart +{ +public: + QString name() + { + return "AxisSet 2"; + } + QString category() + { + return QObject::tr("MultiAxis"); + } + QString subCategory() + { + return "MultiValueAxis"; + } + + QChart *createChart(const DataTable &table) + { + QChart *chart = new QChart(); + QValueAxis *axisX; + QValueAxis *axisY; + + chart->setTitle("MultiValueAxis2"); + + QString name("Series"); + int nameIndex = 1; + foreach (DataList list, table) { + QLineSeries *series = new QLineSeries(chart); + foreach (Data data, list) + series->append(data.first); + series->setName(name + QString::number(nameIndex)); + + chart->addSeries(series); + axisX = new QValueAxis(); + axisX->setLinePenColor(series->pen().color()); + + axisY = new QValueAxis(); + axisY->setLinePenColor(series->pen().color()); + + chart->addAxis(axisX, nameIndex % 2?Qt::AlignTop:Qt::AlignBottom); + chart->addAxis(axisY, nameIndex % 2?Qt::AlignRight:Qt::AlignLeft); + series->attachAxis(axisX); + series->attachAxis(axisY); + nameIndex++; + } + + return chart; + } +}; + +DECLARE_CHART(MultiValueAxis2); diff --git a/tests/manual/chartviewer/charts/multiaxis/multivalueaxis3.cpp b/tests/manual/chartviewer/charts/multiaxis/multivalueaxis3.cpp new file mode 100644 index 00000000..3d25169e --- /dev/null +++ b/tests/manual/chartviewer/charts/multiaxis/multivalueaxis3.cpp @@ -0,0 +1,79 @@ +/**************************************************************************** +** +** 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 "charts.h" +#include <QtCharts/QChart> +#include <QtCharts/QLineSeries> +#include <QtCharts/QValueAxis> +#include <QtCharts/QCategoryAxis> + +class MultiValueAxis3: public Chart +{ +public: + QString name() + { + return "AxisSet 3"; + } + QString category() + { + return QObject::tr("MultiAxis"); + } + QString subCategory() + { + return "MultiValueAxis"; + } + + QChart *createChart(const DataTable &table) + { + QChart *chart = new QChart(); + QValueAxis *axisX; + QValueAxis *axisY; + + chart->setTitle("MultiValueAxis3"); + + QString name("Series"); + int nameIndex = 0; + foreach (DataList list, table) { + QLineSeries *series = new QLineSeries(chart); + foreach (Data data, list) + series->append(data.first); + series->setName(name + QString::number(nameIndex)); + + chart->addSeries(series); + axisX = new QValueAxis(); + axisX->setLinePenColor(series->pen().color()); + axisX->setTitleText("ValueAxis for series" + QString::number(nameIndex)); + + axisY = new QValueAxis(); + axisY->setLinePenColor(series->pen().color()); + axisY->setTitleText("ValueAxis for series" + QString::number(nameIndex)); + + chart->addAxis(axisX, nameIndex % 2?Qt::AlignTop:Qt::AlignBottom); + chart->addAxis(axisY, nameIndex % 2?Qt::AlignRight:Qt::AlignLeft); + series->attachAxis(axisX); + series->attachAxis(axisY); + nameIndex++; + } + + return chart; + } +}; + +DECLARE_CHART(MultiValueAxis3); diff --git a/tests/manual/chartviewer/charts/multiaxis/multivalueaxis4.cpp b/tests/manual/chartviewer/charts/multiaxis/multivalueaxis4.cpp new file mode 100644 index 00000000..5a69ec74 --- /dev/null +++ b/tests/manual/chartviewer/charts/multiaxis/multivalueaxis4.cpp @@ -0,0 +1,78 @@ +/**************************************************************************** +** +** 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 "charts.h" +#include <QtCharts/QChart> +#include <QtCharts/QLineSeries> +#include <QtCharts/QValueAxis> +#include <QtCharts/QCategoryAxis> + +class MultiValueAxis4: public Chart +{ +public: + QString name() + { + return "AxisSet 4"; + } + QString category() + { + return QObject::tr("MultiAxis"); + } + QString subCategory() + { + return "MultiValueAxis"; + } + + QChart *createChart(const DataTable &table) + { + QChart *chart = new QChart(); + QValueAxis *axisX; + QValueAxis *axisY; + + chart->setTitle("MultiValueAxis4"); + + QString name("Series"); + int nameIndex = 1; + foreach (DataList list, table) { + QLineSeries *series = new QLineSeries(chart); + foreach (Data data, list) + series->append(data.first); + series->setName(name + QString::number(nameIndex)); + + chart->addSeries(series); + axisX = new QValueAxis(); + axisX->setLinePenColor(series->pen().color()); + axisX->setTitleText("ValueAxis for series" + QString::number(nameIndex)); + axisY = new QValueAxis(); + axisY->setLinePenColor(series->pen().color()); + axisY->setTitleText("ValueAxis for series" + QString::number(nameIndex)); + + chart->addAxis(axisX, nameIndex % 2?Qt::AlignTop:Qt::AlignBottom); + chart->addAxis(axisY, nameIndex % 2?Qt::AlignRight:Qt::AlignLeft); + series->attachAxis(axisX); + series->attachAxis(axisY); + nameIndex++; + } + + return chart; + } +}; + +DECLARE_CHART(MultiValueAxis4); diff --git a/tests/manual/chartviewer/charts/multiaxis/multivaluebaraxis.cpp b/tests/manual/chartviewer/charts/multiaxis/multivaluebaraxis.cpp new file mode 100644 index 00000000..300a0f4b --- /dev/null +++ b/tests/manual/chartviewer/charts/multiaxis/multivaluebaraxis.cpp @@ -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$ +** +****************************************************************************/ + +#include "charts.h" +#include <QtCharts/QChart> +#include <QtCharts/QLineSeries> +#include <QtCharts/QValueAxis> +#include <QtCharts/QCategoryAxis> +#include <QtCharts/QBarSeries> +#include <QtCharts/QBarSet> +#include <QtCharts/QBarCategoryAxis> + +class MultiValueBarAxis: public Chart +{ +public: + QString name() + { + return "Axis"; + } + QString category() + { + return QObject::tr("MultiAxis"); + } + QString subCategory() + { + return "MultiBarAxis"; + } + + QChart *createChart(const DataTable &table) + { + QChart *chart = new QChart(); + QValueAxis *axisX; + QValueAxis *axisY; + QBarSeries *series = new QBarSeries(); + QBarCategoryAxis *barcategory = new QBarCategoryAxis(); + + chart->setTitle("MultiBarAxis"); + + QString name("Series"); + int nameIndex = 1; + for (int i(0); i < 2; i++) { + QLineSeries *series = new QLineSeries(chart); + foreach (Data data, table.at(i)) + series->append(data.first); + series->setName(name + QString::number(nameIndex)); + + chart->addSeries(series); + axisX = new QValueAxis(); + axisX->setLinePenColor(series->pen().color()); + axisX->setTitleText("ValueAxis for series" + QString::number(nameIndex)); + + axisY = new QValueAxis(); + axisY->setLinePenColor(series->pen().color()); + axisY->setTitleText("ValueAxis for series" + QString::number(nameIndex)); + + chart->addAxis(axisX, nameIndex % 2?Qt::AlignTop:Qt::AlignBottom); + chart->addAxis(axisY, nameIndex % 2?Qt::AlignRight:Qt::AlignLeft); + series->attachAxis(axisX); + series->attachAxis(axisY); + nameIndex++; + } + + QBarSet *set = new QBarSet("Bar set "); + foreach (Data data, table.at(2)) + *set << data.first.y(); + + int count = set->count(); + for (int i = 0; i < count; i++) { + barcategory->append("BarSet " + QString::number(i)); + } + series->append(set); + chart->addSeries(series); + + barcategory->setLinePen(set->brush().color()); + barcategory->setGridLinePen(set->brush().color()); + barcategory->setTitleText("BarCategoryAxis Title"); + + chart->setAxisX(barcategory, series); + + return chart; + } +}; + + +DECLARE_CHART(MultiValueBarAxis); diff --git a/tests/manual/chartviewer/charts/pieseries/donutchart.cpp b/tests/manual/chartviewer/charts/pieseries/donutchart.cpp new file mode 100644 index 00000000..50026ecf --- /dev/null +++ b/tests/manual/chartviewer/charts/pieseries/donutchart.cpp @@ -0,0 +1,55 @@ +/**************************************************************************** +** +** 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 "charts.h" +#include <QtCharts/QChart> +#include <QtCharts/QPieSeries> + +class DonutChart: public Chart +{ +public: + QString name() { return QObject::tr("DonutChart"); } + QString category() { return QObject::tr("PieSeries"); } + QString subCategory() { return QString::null; } + + QChart *createChart(const DataTable &table) + { + QChart *chart = new QChart(); + chart->setTitle("Donut chart"); + for (int i = 0, j = table.count(); i < table.count(); i++, j--) { + QPieSeries *series = new QPieSeries(chart); + foreach (Data data, table[i]) { + QPieSlice *slice = series->append(data.second, data.first.y()); + if (data == table[i].first()) + slice->setLabelVisible(); + } + series->setPieSize(j / (qreal) table.count()); + if (j > 1) + series->setHoleSize((j - 1) / (qreal) table.count() + 0.1); + series->setHorizontalPosition(0.5); + series->setVerticalPosition(0.5); + chart->addSeries(series); + } + return chart; + } +}; + +DECLARE_CHART(DonutChart) + diff --git a/tests/manual/chartviewer/charts/pieseries/piechart.cpp b/tests/manual/chartviewer/charts/pieseries/piechart.cpp new file mode 100644 index 00000000..f88e4657 --- /dev/null +++ b/tests/manual/chartviewer/charts/pieseries/piechart.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 "charts.h" +#include <QtCharts/QChart> +#include <QtCharts/QPieSeries> + +class PieChart: public Chart +{ +public: + QString name() { return QObject::tr("PieChart"); } + QString category() { return QObject::tr("PieSeries"); } + QString subCategory() { return QString::null; } + + QChart *createChart(const DataTable &table) + { + QChart *chart = new QChart(); + chart->setTitle("Pie chart"); + qreal pieSize = 1.0 / table.count(); + for (int i = 0; i < table.count(); i++) { + QPieSeries *series = new QPieSeries(chart); + foreach (Data data, table[i]) { + QPieSlice *slice = series->append(data.second, data.first.y()); + if (data == table[i].first()) { + slice->setLabelVisible(); + slice->setExploded(); + } + } + qreal hPos = (pieSize / 2) + (i / (qreal) table.count()); + series->setPieSize(pieSize); + series->setHorizontalPosition(hPos); + series->setVerticalPosition(0.5); + chart->addSeries(series); + } + return chart; + } +}; + +DECLARE_CHART(PieChart) + diff --git a/tests/manual/chartviewer/charts/size/sizecharts.cpp b/tests/manual/chartviewer/charts/size/sizecharts.cpp new file mode 100644 index 00000000..6be59159 --- /dev/null +++ b/tests/manual/chartviewer/charts/size/sizecharts.cpp @@ -0,0 +1,140 @@ +/**************************************************************************** +** +** 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 "charts.h" +#include <QtCharts/QChart> +#include <QtCharts/QLineSeries> +#include <QtCharts/QValueAxis> + +class SizeChart: public Chart +{ +public: + QString name() { return QObject::tr("PlotArea"); } + QString category() { return QObject::tr("Size"); } + QString subCategory() { return QString::null; } + + QChart *createChart(const DataTable &table) + { + + QChart *chart = new QChart(); + QString name("Series"); + int nameIndex = 0; + foreach (DataList list, table) { + QLineSeries *series = new QLineSeries(chart); + foreach (Data data, list) + series->append(data.first); + series->setName(name + QString::number(nameIndex)); + nameIndex++; + chart->addSeries(series); + } + chart->setContentsMargins(0,0,0,0); + chart->setMargins(QMargins(0,0,0,0)); + return chart; + } +}; + +class SizeChart2: public SizeChart +{ +public: + QString name() { return QObject::tr("PA + T"); } + + QChart *createChart(const DataTable &table) + { + QChart *chart = SizeChart::createChart(table); + chart->setTitle(name()); + return chart; + } +}; + +class SizeChart3: public SizeChart2 +{ +public: + QString name() { return QObject::tr("PA+T+CM10"); } + + QChart *createChart(const DataTable &table) + { + QChart *chart = SizeChart2::createChart(table); + chart->setContentsMargins(10,10,10,10); + + return chart; + } +}; + +class SizeChart4: public SizeChart3 +{ +public: + QString name() { return QObject::tr("PA+T+CM10+M25"); } + + QChart *createChart(const DataTable &table) + { + QChart *chart = SizeChart3::createChart(table); + chart->setMargins(QMargins(30,30,30,30)); + return chart; + } +}; + +class SizeChart5: public SizeChart4 +{ +public: + QString name() { return QObject::tr("PA+T+CM10+M25+AX"); } + + QChart *createChart(const DataTable &table) + { + QChart *chart = SizeChart4::createChart(table); + chart->createDefaultAxes(); + chart->axisY()->hide(); + return chart; + } +}; + +class SizeChart6: public SizeChart4 +{ +public: + QString name() { return QObject::tr("PA+T+CM10+M25+AY"); } + + QChart *createChart(const DataTable &table) + { + QChart *chart = SizeChart4::createChart(table); + chart->createDefaultAxes(); + chart->axisX()->hide(); + return chart; + } +}; + +class SizeChart7: public SizeChart4 +{ +public: + QString name() { return QObject::tr("PA+T+CM10+M25+AX+AY"); } + + QChart *createChart(const DataTable &table) + { + QChart *chart = SizeChart4::createChart(table); + chart->createDefaultAxes(); + return chart; + } +}; + +DECLARE_CHART(SizeChart) +DECLARE_CHART(SizeChart2) +DECLARE_CHART(SizeChart3) +DECLARE_CHART(SizeChart4) +DECLARE_CHART(SizeChart5) +DECLARE_CHART(SizeChart6) +DECLARE_CHART(SizeChart7) diff --git a/tests/manual/chartviewer/charts/xyseries/areachart.cpp b/tests/manual/chartviewer/charts/xyseries/areachart.cpp new file mode 100644 index 00000000..dc869c3b --- /dev/null +++ b/tests/manual/chartviewer/charts/xyseries/areachart.cpp @@ -0,0 +1,65 @@ +/**************************************************************************** +** +** 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 "charts.h" +#include <QtCharts/QChart> +#include <QtCharts/QAreaSeries> +#include <QtCharts/QLineSeries> + +class AreaChart: public Chart +{ +public: + QString name() { return QObject::tr("AreaChart"); } + QString category() { return QObject::tr("XYSeries"); } + QString subCategory() { return QString::null; } + + QChart *createChart(const DataTable &table) + { + 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 < table.count(); i++) { + QLineSeries *upperSeries = new QLineSeries(chart); + for (int j(0); j < table[i].count(); j++) { + Data data = table[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; + } +}; + +DECLARE_CHART(AreaChart) + diff --git a/tests/manual/chartviewer/charts/xyseries/linechart.cpp b/tests/manual/chartviewer/charts/xyseries/linechart.cpp new file mode 100644 index 00000000..4ef39e4c --- /dev/null +++ b/tests/manual/chartviewer/charts/xyseries/linechart.cpp @@ -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$ +** +****************************************************************************/ + +#include "charts.h" +#include <QtCharts/QChart> +#include <QtCharts/QLineSeries> + +class LineChart: public Chart +{ +public: + QString name() { return QObject::tr("LineChart"); } + QString category() { return QObject::tr("XYSeries"); } + QString subCategory() { return QString::null; } + + QChart *createChart(const DataTable &table) + { + QChart *chart = new QChart(); + chart->setTitle("Line chart"); + QString name("Series "); + int nameIndex = 0; + foreach (DataList list, table) { + 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; + } +}; + +DECLARE_CHART(LineChart) + diff --git a/tests/manual/chartviewer/charts/xyseries/scatterchart.cpp b/tests/manual/chartviewer/charts/xyseries/scatterchart.cpp new file mode 100644 index 00000000..d49e7f49 --- /dev/null +++ b/tests/manual/chartviewer/charts/xyseries/scatterchart.cpp @@ -0,0 +1,51 @@ +/**************************************************************************** +** +** 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 "charts.h" +#include <QtCharts/QChart> +#include <QtCharts/QScatterSeries> + +class ScatterChart: public Chart +{ +public: + QString name() { return QObject::tr("ScatterChart"); } + QString category() { return QObject::tr("XYSeries"); } + QString subCategory() { return QString::null; } + + QChart *createChart(const DataTable &table) + { + QChart *chart = new QChart(); + chart->setTitle("Scatter chart"); + QString name("Series "); + int nameIndex = 0; + foreach (DataList list, table) { + 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; + } +}; + +DECLARE_CHART(ScatterChart) diff --git a/tests/manual/chartviewer/charts/xyseries/splinechart.cpp b/tests/manual/chartviewer/charts/xyseries/splinechart.cpp new file mode 100644 index 00000000..38ffe340 --- /dev/null +++ b/tests/manual/chartviewer/charts/xyseries/splinechart.cpp @@ -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$ +** +****************************************************************************/ + +#include "charts.h" +#include <QtCharts/QChart> +#include <QtCharts/QSplineSeries> + +class SplineChart: public Chart +{ +public: + QString name() { return QObject::tr("SplineChart"); } + QString category() { return QObject::tr("XYSeries"); } + QString subCategory() { return QString::null; } + + QChart *createChart(const DataTable &table) + { + QChart *chart = new QChart(); + chart->setTitle("Spline chart"); + QString name("Series "); + int nameIndex = 0; + foreach (DataList list, table) { + 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; + } +}; + +DECLARE_CHART(SplineChart) + diff --git a/tests/manual/chartviewer/chartviewer.pro b/tests/manual/chartviewer/chartviewer.pro new file mode 100644 index 00000000..693c1eab --- /dev/null +++ b/tests/manual/chartviewer/chartviewer.pro @@ -0,0 +1,10 @@ +!include( ../../tests.pri ) { + error( "Couldn't find the test.pri file!" ) +} +include(charts/charts.pri) +TARGET = chartviewer +QT += opengl +INCLUDEPATH += . +SOURCES += main.cpp window.cpp view.cpp grid.cpp +HEADERS += window.h view.h charts.h model.h grid.h + diff --git a/tests/manual/chartviewer/grid.cpp b/tests/manual/chartviewer/grid.cpp new file mode 100644 index 00000000..f1619ab0 --- /dev/null +++ b/tests/manual/chartviewer/grid.cpp @@ -0,0 +1,301 @@ +/**************************************************************************** +** +** 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 "grid.h" +#include "charts.h" +#include <QtCharts/QChart> +#include <QtWidgets/QGraphicsGridLayout> +#include <QtWidgets/QGraphicsSceneMouseEvent> +#include <QtCore/QDebug> + +Grid::Grid(int size, QGraphicsItem *parent) + : QGraphicsWidget(parent), + m_listCount(3), + m_valueMax(10), + m_valueCount(7), + m_size(size), + m_dataTable(Model::generateRandomData(m_listCount, m_valueMax, m_valueCount)), + m_state(NoState), + m_currentState(NoState), + m_rubberBand(new QGraphicsRectItem()), + m_gridLayout(new QGraphicsGridLayout()) +{ + setLayout(m_gridLayout); + m_rubberBand->setParentItem(this); + m_rubberBand->setVisible(false); + m_rubberBand->setZValue(2); +} + +Grid::~Grid() +{ + +} + +void Grid::createCharts(const QString &category) +{ + clear(); + + QChart *qchart(0); + Charts::ChartList list = Charts::chartList(); + + if (category.isEmpty()) { + for (int i = 0; i < m_size * m_size; ++i) { + QChart *chart = new QChart(); + chart->setTitle(QObject::tr("Empty")); + m_gridLayout->addItem(chart, i / m_size, i % m_size); + m_chartHash[chart] = i; + m_chartHashRev[i] = chart; + } + } else { + int j = 0; + for (int i = 0; i < list.size(); ++i) { + Chart *chart = list.at(i); + if (chart->category() == category && j < m_size * m_size) { + qchart = list.at(i)->createChart(m_dataTable); + m_gridLayout->addItem(qchart, j / m_size, j % m_size); + m_chartHash[qchart] = j; + m_chartHashRev[j] = qchart; + j++; + } + } + for (; j < m_size * m_size; ++j) { + qchart = new QChart(); + qchart->setTitle(QObject::tr("Empty")); + m_gridLayout->addItem(qchart, j / m_size, j % m_size); + m_chartHash[qchart] = j; + m_chartHashRev[j] = qchart; + } + } + m_gridLayout->activate(); +} + +void Grid::createCharts(const QString &category, const QString &subcategory, const QString &name) +{ + clear(); + + QChart *qchart(0); + Charts::ChartList list = Charts::chartList(); + Chart *chart; + + //find chart + for (int i = 0; i < list.size(); ++i) { + + chart = list.at(i); + if (chart->category() == category && + chart->subCategory() == subcategory && + chart->name() == name) { + break; + } + chart = 0; + } + + //create charts + for (int j = 0; j < m_size * m_size; ++j) { + + if(!chart){ + qchart = new QChart(); + }else{ + qchart = chart->createChart(m_dataTable); + } + qchart->setTitle(QObject::tr("Empty")); + m_gridLayout->addItem(qchart, j / m_size, j % m_size); + m_chartHash[qchart] = j; + m_chartHashRev[j] = qchart; + } + + m_gridLayout->activate(); +} + +void Grid::clear() +{ + int count = m_gridLayout->count(); + for (int i = 0; i < count; ++i) + m_gridLayout->removeAt(0); + + qDeleteAll(m_chartHash.keys()); + m_chartHash.clear(); + m_chartHashRev.clear(); +} + +QList<QChart *> Grid::charts() +{ + return m_chartHash.keys(); +} + +void Grid::setState(State state) +{ + m_state = state; +} + +void Grid::setSize(int size) +{ + if (m_size != size) { + + //remove old; + int count = m_gridLayout->count(); + for (int i = 0; i < count; ++i) { + m_gridLayout->removeAt(0); + } + + + QChart* qchart = 0; + int j = 0; + + for (; j < size * size; ++j) { + + qchart = m_chartHashRev[j]; + + if (!qchart){ + qchart = new QChart(); + qchart->setTitle(QObject::tr("Empty")); + } + + m_chartHash[qchart] = j; + m_chartHashRev[j] = qchart; + m_gridLayout->addItem(qchart, j / size, j % size); + } + + //delete rest + while (j < m_size * m_size) { + QChart* qchart = m_chartHashRev.take(j); + delete(qchart); + m_chartHash.remove(qchart); + j++; + } + + m_size = size; + } +} + +void Grid::setRubberPen(const QPen &pen) +{ + m_rubberBand->setPen(pen); +} + +void Grid::replaceChart(QChart *oldChart, Chart *newChart) +{ + int index = m_chartHash[oldChart]; + //not in 4.7.2 m_baseLayout->removeItem(qchart); + for (int i = 0; i < m_gridLayout->count(); ++i) { + if (m_gridLayout->itemAt(i) == oldChart) { + m_gridLayout->removeAt(i); + break; + } + } + m_chartHash.remove(oldChart); + m_chartHashRev.remove(index); + QChart *chart = newChart->createChart(m_dataTable); + m_gridLayout->addItem(chart, index / m_size, index % m_size); + m_chartHash[chart] = index; + m_chartHashRev[index] = chart; + delete oldChart; +} + +void Grid::mousePressEvent(QGraphicsSceneMouseEvent *event) +{ + if (event->button() == Qt::LeftButton) { + + m_origin = event->pos(); + m_currentState = NoState; + + foreach (QChart *chart, charts()) { + QRectF geometryRect = chart->geometry(); + QRectF plotArea = chart->plotArea(); + plotArea.translate(geometryRect.topLeft()); + if (plotArea.contains(m_origin)) { + m_currentState = m_state; + if (m_currentState == NoState) emit chartSelected(chart); + break; + } + } + if (m_currentState == ZoomState) { + m_rubberBand->setRect(QRectF(m_origin, QSize())); + m_rubberBand->setVisible(true); + } + + event->accept(); + } + + if (event->button() == Qt::RightButton) { + m_origin = event->pos(); + m_currentState = m_state; + } +} + +void Grid::mouseMoveEvent(QGraphicsSceneMouseEvent *event) +{ + if (m_currentState != NoState) { + + foreach (QChart *chart, charts()) { + QRectF geometryRect = chart->geometry(); + QRectF plotArea = chart->plotArea(); + plotArea.translate(geometryRect.topLeft()); + if (plotArea.contains(m_origin)) { + if (m_currentState == ScrollState) { + QPointF delta = m_origin - event->pos(); + chart->scroll(delta.x(), -delta.y()); + } + if (m_currentState == ZoomState && plotArea.contains(event->pos())) + m_rubberBand->setRect(QRectF(m_origin, event->pos()).normalized()); + break; + } + } + if (m_currentState == ScrollState) + m_origin = event->pos(); + event->accept(); + } +} + +void Grid::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) +{ + if (event->button() == Qt::LeftButton) { + if (m_currentState == ZoomState) { + m_rubberBand->setVisible(false); + + foreach (QChart *chart, charts()) { + QRectF geometryRect = chart->geometry(); + QRectF plotArea = chart->plotArea(); + plotArea.translate(geometryRect.topLeft()); + if (plotArea.contains(m_origin)) { + QRectF rect = m_rubberBand->rect(); + rect.translate(-geometryRect.topLeft()); + chart->zoomIn(rect); + break; + } + } + } + m_currentState = NoState; + event->accept(); + } + + if (event->button() == Qt::RightButton) { + if (m_currentState == ZoomState) { + foreach (QChart *chart, charts()) { + QRectF geometryRect = chart->geometry(); + QRectF plotArea = chart->plotArea(); + plotArea.translate(geometryRect.topLeft()); + if (plotArea.contains(m_origin)) { + chart->zoomOut(); + break; + } + } + } + } +} diff --git a/tests/manual/chartviewer/grid.h b/tests/manual/chartviewer/grid.h new file mode 100644 index 00000000..a519503d --- /dev/null +++ b/tests/manual/chartviewer/grid.h @@ -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$ +** +****************************************************************************/ + +#ifndef GRID_H_ +#define GRID_H_ + +#include "model.h" +#include <QtWidgets/QGraphicsWidget> +#include <QtCharts/QChartGlobal> + +class QGraphicsGridLayout; +class Chart; + +QT_CHARTS_BEGIN_NAMESPACE +class QChart; +QT_CHARTS_END_NAMESPACE + +QT_CHARTS_USE_NAMESPACE + +class Grid : public QGraphicsWidget +{ + Q_OBJECT +public: + enum State { NoState = 0, ZoomState, ScrollState}; + + Grid(int size, QGraphicsItem *parent = 0); + ~Grid(); + + QList<QChart *> charts(); + void createCharts(const QString &category = QString()); + void createCharts(const QString &category, const QString &subcategory, const QString &name); + void replaceChart(QChart *oldChart, Chart *newChart); + void setState(State state); + State state() const { return m_state; }; + void setRubberPen(const QPen &pen); + void setSize(int size); + int size() const {return m_size;} + +Q_SIGNALS: + void chartSelected(QChart *chart); + +protected: + void mousePressEvent(QGraphicsSceneMouseEvent *event); + void mouseMoveEvent(QGraphicsSceneMouseEvent *event); + void mouseReleaseEvent(QGraphicsSceneMouseEvent *event); + +private: + void clear(); + +private: + int m_listCount; + int m_valueMax; + int m_valueCount; + int m_size; + DataTable m_dataTable; + QHash<QChart *, int> m_chartHash; + QHash<int, QChart *> m_chartHashRev; + State m_state; + State m_currentState; + QPointF m_origin; + QGraphicsRectItem *m_rubberBand; + QGraphicsGridLayout *m_gridLayout; +}; + +#endif /* GRID_H_ */ diff --git a/tests/manual/chartviewer/main.cpp b/tests/manual/chartviewer/main.cpp new file mode 100644 index 00000000..6a267632 --- /dev/null +++ b/tests/manual/chartviewer/main.cpp @@ -0,0 +1,85 @@ +/**************************************************************************** +** +** 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 "window.h" +#include <QtWidgets/QApplication> +#include <QtWidgets/QMainWindow> +#include <iostream> + +QVariantHash parseArgs(QStringList args) +{ + QVariantHash parameters; + + while (!args.isEmpty()) { + + QString param = args.takeFirst(); + if (param.startsWith("--")) { + param.remove(0, 2); + + if (args.isEmpty() || args.first().startsWith("--")) { + parameters[param] = true; + } else { + QString value = args.takeFirst(); + if (value == "true" || value == "on" || value == "enabled") { + parameters[param] = true; + } else if (value == "false" || value == "off" || value == "disable") { + parameters[param] = false; + } else { + if (value.endsWith('"')) + value.chop(1); + if (value.startsWith('"')) + value.remove(0, 1); + parameters[param] = value; + } + } + } + } + + return parameters; +} + +void printHelp() +{ + std::cout << "chartviewer <options> "<< std::endl; + std::cout << " --view <1/2/3/4> - set size of charts' grid" << std::endl; + std::cout << " --chart <categoryName::subCategory::chartName> - set template to be show " << std::endl; + std::cout << " --opengl <enabled/disbaled> - set opengl mode" << std::endl; + std::cout << " --theme <name> - set theme" << std::endl; + std::cout << " --legend <alignment> - set legend alignment" << std::endl; + std::cout << " --help - prints this help" << std::endl; + std::cout << "Examples: " << std::endl; + std::cout << " chartviewer --view 4 --chart Axis" << std::endl; + std::cout << " chartviewer --view 1 --chart Axis::BarCategoryAxis::Axis " << std::endl; +} + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + QVariantHash parameters = parseArgs(QApplication::arguments()); + if(parameters.contains("help")) + { + printHelp(); + return 0; + } + Window window(parameters); + window.show(); + return a.exec(); +} + diff --git a/tests/manual/chartviewer/model.h b/tests/manual/chartviewer/model.h new file mode 100644 index 00000000..0400a631 --- /dev/null +++ b/tests/manual/chartviewer/model.h @@ -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$ +** +****************************************************************************/ + +#ifndef MODEL_H +#define MODEL_H + +#include <QtCore/QList> +#include <QtCore/QPair> +#include <QtCore/QPointF> +#include <QtCore/QTime> +#include <stdlib.h> + +typedef QPair<QPointF, QString> Data; +typedef QList<Data> DataList; +typedef QList<DataList> DataTable; + + +class Model +{ +private: + Model() {} + +public: + static DataTable generateRandomData(int listCount, int valueMax, int valueCount) + { + 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.1); + for (int j(0); j < valueCount; j++) { + yValue = yValue + (qreal)(qrand() % valueMax) / (qreal) valueCount; + QPointF value( + (j + (qreal) qrand() / (qreal) RAND_MAX) + * ((qreal) valueMax / (qreal) valueCount), yValue); + QString label = "Slice " + QString::number(i) + ":" + QString::number(j); + dataList << Data(value, label); + } + dataTable << dataList; + } + return dataTable; + } +}; + +#endif diff --git a/tests/manual/chartviewer/view.cpp b/tests/manual/chartviewer/view.cpp new file mode 100644 index 00000000..67ef7918 --- /dev/null +++ b/tests/manual/chartviewer/view.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 "view.h" +#include <QtWidgets/QGraphicsWidget> +#include <QtGui/QResizeEvent> +#include <QtCore/QDebug> + +View::View(QGraphicsScene *scene, QGraphicsWidget *form , QWidget *parent) + : QGraphicsView(scene, parent), + m_form(form) +{ + setDragMode(QGraphicsView::NoDrag); + setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); +} + +void View::resizeEvent(QResizeEvent *event) +{ + if (scene()) + scene()->setSceneRect(QRect(QPoint(0, 0), event->size())); + if (m_form) + m_form->resize(QSizeF(event->size())); + QGraphicsView::resizeEvent(event); +} + +void View::mouseMoveEvent(QMouseEvent *event) +{ + //BugFix somehow view always eats the mouse move event; + QGraphicsView::mouseMoveEvent(event); + event->setAccepted(false); +} + +void View::mouseReleaseEvent(QMouseEvent *event) +{ + QGraphicsView::mouseReleaseEvent(event); + //BugFix somehow view always eats the mouse release event; + event->setAccepted(false); +} diff --git a/tests/manual/chartviewer/view.h b/tests/manual/chartviewer/view.h new file mode 100644 index 00000000..c9c80860 --- /dev/null +++ b/tests/manual/chartviewer/view.h @@ -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$ +** +****************************************************************************/ + +#ifndef VIEW_H +#define VIEW_H +#include <QtWidgets/QGraphicsView> + +class QGraphicsScene; +class QResizeEvent; + +class View: public QGraphicsView +{ +public: + View(QGraphicsScene *scene, QGraphicsWidget *form , QWidget *parent = 0); + +protected: + void resizeEvent(QResizeEvent *event); + void mouseMoveEvent(QMouseEvent *event); + void mouseReleaseEvent(QMouseEvent *event); + +private: + QGraphicsWidget *m_form; +}; + +#endif diff --git a/tests/manual/chartviewer/window.cpp b/tests/manual/chartviewer/window.cpp new file mode 100644 index 00000000..d535adf6 --- /dev/null +++ b/tests/manual/chartviewer/window.cpp @@ -0,0 +1,506 @@ +/**************************************************************************** + ** + ** 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 "window.h" +#include "view.h" +#include "grid.h" +#include "charts.h" +#include <QtCharts/QChartView> +#include <QtCharts/QAreaSeries> +#include <QtCharts/QLegend> +#include <QtWidgets/QGridLayout> +#include <QtWidgets/QFormLayout> +#include <QtWidgets/QComboBox> +#include <QtWidgets/QSpinBox> +#include <QtWidgets/QCheckBox> +#include <QtWidgets/QGroupBox> +#include <QtWidgets/QLabel> +#include <QtWidgets/QGraphicsScene> +#include <QtWidgets/QGraphicsLinearLayout> +#include <QtWidgets/QGraphicsProxyWidget> +#include <QtOpenGL/QGLWidget> +#include <QtWidgets/QApplication> +#include <QtCore/QDebug> +#include <QtWidgets/QMenu> +#include <QtWidgets/QPushButton> + +Window::Window(const QVariantHash ¶meters, QWidget *parent) + : QMainWindow(parent), + m_scene(new QGraphicsScene(this)), + m_view(0), + m_form(0), + m_themeComboBox(0), + m_antialiasCheckBox(0), + m_animatedComboBox(0), + m_legendComboBox(0), + m_templateComboBox(0), + m_viewComboBox(0), + m_openGLCheckBox(0), + m_zoomCheckBox(0), + m_scrollCheckBox(0), + m_baseLayout(new QGraphicsLinearLayout()), + m_menu(createMenu()), + m_template(0), + m_grid(new Grid(-1)) +{ + createProxyWidgets(); + // create layout + QGraphicsLinearLayout *settingsLayout = new QGraphicsLinearLayout(); + + settingsLayout->setOrientation(Qt::Vertical); + settingsLayout->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum); + settingsLayout->addItem(m_widgetHash["openGLCheckBox"]); + settingsLayout->addItem(m_widgetHash["antialiasCheckBox"]); + settingsLayout->addItem(m_widgetHash["viewLabel"]); + settingsLayout->addItem(m_widgetHash["viewComboBox"]); + settingsLayout->addItem(m_widgetHash["themeLabel"]); + settingsLayout->addItem(m_widgetHash["themeComboBox"]); + settingsLayout->addItem(m_widgetHash["animationsLabel"]); + settingsLayout->addItem(m_widgetHash["animatedComboBox"]); + settingsLayout->addItem(m_widgetHash["legendLabel"]); + settingsLayout->addItem(m_widgetHash["legendComboBox"]); + settingsLayout->addItem(m_widgetHash["templateLabel"]); + settingsLayout->addItem(m_widgetHash["templateComboBox"]); + settingsLayout->addItem(m_widgetHash["scrollCheckBox"]); + settingsLayout->addItem(m_widgetHash["zoomCheckBox"]); + settingsLayout->addStretch(); + + m_baseLayout->setOrientation(Qt::Horizontal); + m_baseLayout->addItem(m_grid); + m_baseLayout->addItem(settingsLayout); + + m_form = new QGraphicsWidget(); + m_form->setLayout(m_baseLayout); + m_scene->addItem(m_form); + + m_view = new View(m_scene, m_form); + m_view->setMinimumSize(m_form->minimumSize().toSize()); + + // Set defaults + m_antialiasCheckBox->setChecked(true); + initializeFromParamaters(parameters); + updateUI(); + if(!m_category.isEmpty() && !m_subcategory.isEmpty() && !m_name.isEmpty()) + m_grid->createCharts(m_category,m_subcategory,m_name); + + + handleGeometryChanged(); + setCentralWidget(m_view); + + connectSignals(); +} + +Window::~Window() +{ +} + +void Window::connectSignals() +{ + QObject::connect(m_form, SIGNAL(geometryChanged()), this , SLOT(handleGeometryChanged())); + QObject::connect(m_viewComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI())); + QObject::connect(m_themeComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI())); + QObject::connect(m_antialiasCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI())); + QObject::connect(m_openGLCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI())); + QObject::connect(m_zoomCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI())); + QObject::connect(m_scrollCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI())); + QObject::connect(m_animatedComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI())); + QObject::connect(m_legendComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI())); + QObject::connect(m_templateComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI())); + QObject::connect(m_grid, SIGNAL(chartSelected(QChart*)), this, SLOT(handleChartSelected(QChart*))); +} + +void Window::createProxyWidgets() +{ + m_themeComboBox = createThemeBox(); + m_viewComboBox = createViewBox(); + m_antialiasCheckBox = new QCheckBox(tr("Anti-aliasing")); + m_animatedComboBox = createAnimationBox(); + m_legendComboBox = createLegendBox(); + m_openGLCheckBox = new QCheckBox(tr("OpenGL")); + m_zoomCheckBox = new QCheckBox(tr("Zoom")); + m_scrollCheckBox = new QCheckBox(tr("Scroll")); + m_templateComboBox = createTempleteBox(); + m_widgetHash["viewLabel"] = m_scene->addWidget(new QLabel("View")); + m_widgetHash["viewComboBox"] = m_scene->addWidget(m_viewComboBox); + m_widgetHash["themeComboBox"] = m_scene->addWidget(m_themeComboBox); + m_widgetHash["antialiasCheckBox"] = m_scene->addWidget(m_antialiasCheckBox); + m_widgetHash["animatedComboBox"] = m_scene->addWidget(m_animatedComboBox); + m_widgetHash["legendComboBox"] = m_scene->addWidget(m_legendComboBox); + m_widgetHash["openGLCheckBox"] = m_scene->addWidget(m_openGLCheckBox); + m_widgetHash["themeLabel"] = m_scene->addWidget(new QLabel("Theme")); + m_widgetHash["animationsLabel"] = m_scene->addWidget(new QLabel("Animations")); + m_widgetHash["legendLabel"] = m_scene->addWidget(new QLabel("Legend")); + m_widgetHash["templateLabel"] = m_scene->addWidget(new QLabel("Chart template")); + m_widgetHash["templateComboBox"] = m_scene->addWidget(m_templateComboBox); + m_widgetHash["zoomCheckBox"] = m_scene->addWidget(m_zoomCheckBox); + m_widgetHash["scrollCheckBox"] = m_scene->addWidget(m_scrollCheckBox); +} + +QComboBox *Window::createThemeBox() +{ + QComboBox *themeComboBox = new ComboBox(this); + 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 *Window::createViewBox() +{ + QComboBox *viewComboBox = new ComboBox(this); + viewComboBox->addItem("1 chart", 1); + viewComboBox->addItem("4 charts", 2); + viewComboBox->addItem("9 charts", 3); + viewComboBox->addItem("16 charts", 4); + return viewComboBox; +} + +QComboBox *Window::createAnimationBox() +{ + QComboBox *animationComboBox = new ComboBox(this); + 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 *Window::createLegendBox() +{ + QComboBox *legendComboBox = new ComboBox(this); + 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; +} + +QComboBox *Window::createTempleteBox() +{ + QComboBox *templateComboBox = new ComboBox(this); + templateComboBox->addItem("No Template", 0); + + Charts::ChartList list = Charts::chartList(); + QMultiMap<QString, Chart *> categoryMap; + + foreach (Chart *chart, list) + categoryMap.insertMulti(chart->category(), chart); + + foreach (const QString &category, categoryMap.uniqueKeys()) + templateComboBox->addItem(category, category); + + return templateComboBox; +} + +void Window::initializeFromParamaters(const QVariantHash ¶meters) +{ + if (parameters.contains("view")) { + int t = parameters["view"].toInt(); + for (int i = 0; i < m_viewComboBox->count(); ++i) { + if (m_viewComboBox->itemData(i).toInt() == t) { + m_viewComboBox->setCurrentIndex(i); + break; + } + } + } + + if (parameters.contains("chart")) { + QString t = parameters["chart"].toString(); + + QRegExp rx("([a-zA-Z0-9_]*)::([a-zA-Z0-9_]*)::([a-zA-Z0-9_]*)"); + int pos = rx.indexIn(t); + + if (pos > -1) { + m_category = rx.cap(1); + m_subcategory = rx.cap(2); + m_name = rx.cap(3); + m_templateComboBox->setCurrentIndex(0); + } + else { + for (int i = 0; i < m_templateComboBox->count(); ++i) { + if (m_templateComboBox->itemText(i) == t) { + m_templateComboBox->setCurrentIndex(i); + break; + } + } + } + } + if (parameters.contains("opengl")) { + bool checked = parameters["opengl"].toBool(); + m_openGLCheckBox->setChecked(checked); + } + if (parameters.contains("theme")) { + QString t = parameters["theme"].toString(); + for (int i = 0; i < m_themeComboBox->count(); ++i) { + if (m_themeComboBox->itemText(i) == t) { + m_themeComboBox->setCurrentIndex(i); + break; + } + } + } + if (parameters.contains("animation")) { + QString t = parameters["animation"].toString(); + for (int i = 0; i < m_animatedComboBox->count(); ++i) { + if (m_animatedComboBox->itemText(i) == t) { + m_animatedComboBox->setCurrentIndex(i); + break; + } + } + } + if (parameters.contains("legend")) { + QString t = parameters["legend"].toString(); + for (int i = 0; i < m_legendComboBox->count(); ++i) { + if (m_legendComboBox->itemText(i) == t) { + m_legendComboBox->setCurrentIndex(i); + break; + } + } + } +} + +void Window::updateUI() +{ + checkView(); + checkTemplate(); + checkOpenGL(); + checkTheme(); + checkAnimationOptions(); + checkLegend(); + checkState(); +} + +void Window::checkView() +{ + int count(m_viewComboBox->itemData(m_viewComboBox->currentIndex()).toInt()); + if(m_grid->size()!=count){ + m_grid->setSize(count); + m_template = 0; + } +} + +void Window::checkLegend() +{ + Qt::Alignment alignment(m_legendComboBox->itemData(m_legendComboBox->currentIndex()).toInt()); + + if (!alignment) { + foreach (QChart *chart, m_grid->charts()) + chart->legend()->hide(); + } else { + foreach (QChart *chart, m_grid->charts()) { + chart->legend()->setAlignment(alignment); + chart->legend()->show(); + } + } +} + +void Window::checkOpenGL() +{ + bool opengl = m_openGLCheckBox->isChecked(); + bool isOpengl = qobject_cast<QGLWidget *>(m_view->viewport()); + if ((isOpengl && !opengl) || (!isOpengl && opengl)) { + m_view->deleteLater(); + m_view = new View(m_scene, m_form); + m_view->setViewport(!opengl ? new QWidget() : new QGLWidget()); + setCentralWidget(m_view); + } + + bool antialias = m_antialiasCheckBox->isChecked(); + + if (opengl) + m_view->setRenderHint(QPainter::HighQualityAntialiasing, antialias); + else + m_view->setRenderHint(QPainter::Antialiasing, antialias); +} + +void Window::checkAnimationOptions() +{ + QChart::AnimationOptions options( + m_animatedComboBox->itemData(m_animatedComboBox->currentIndex()).toInt()); + + QList<QChart *> charts = m_grid->charts(); + + if (!charts.isEmpty() && charts.at(0)->animationOptions() != options) { + foreach (QChart *chart, charts) + chart->setAnimationOptions(options); + } +} + +void Window::checkState() +{ + bool scroll = m_scrollCheckBox->isChecked(); + + + if (m_grid->state() != Grid::ScrollState && scroll) { + m_grid->setState(Grid::ScrollState); + m_zoomCheckBox->setChecked(false); + } else if (!scroll && m_grid->state() == Grid::ScrollState) { + m_grid->setState(Grid::NoState); + } + + bool zoom = m_zoomCheckBox->isChecked(); + + if (m_grid->state() != Grid::ZoomState && zoom) { + m_grid->setState(Grid::ZoomState); + m_scrollCheckBox->setChecked(false); + } else if (!zoom && m_grid->state() == Grid::ZoomState) { + m_grid->setState(Grid::NoState); + } +} + +void Window::checkTemplate() +{ + int index = m_templateComboBox->currentIndex(); + if (m_template == index || index == 0) + return; + + m_template = index; + QString category = m_templateComboBox->itemData(index).toString(); + m_grid->createCharts(category); +} + +void Window::checkTheme() +{ + QChart::ChartTheme theme = (QChart::ChartTheme) m_themeComboBox->itemData( + m_themeComboBox->currentIndex()).toInt(); + + foreach (QChart *chart, m_grid->charts()) + 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 if (theme == QChart::ChartThemeQt) { + pal.setColor(QPalette::Window, QRgb(0xf0f0f0)); + pal.setColor(QPalette::WindowText, QRgb(0x404044)); + } else { + pal.setColor(QPalette::Window, QRgb(0xf0f0f0)); + pal.setColor(QPalette::WindowText, QRgb(0x404044)); + } + foreach (QGraphicsProxyWidget *widget, m_widgetHash) + widget->setPalette(pal); + m_view->setBackgroundBrush(pal.color((QPalette::Window))); + m_grid->setRubberPen(pal.color((QPalette::WindowText))); +} + +void Window::comboBoxFocused(QComboBox *combobox) +{ + foreach (QGraphicsProxyWidget *widget , m_widgetHash) { + if (widget->widget() == combobox) + widget->setZValue(2.0); + else + widget->setZValue(0.0); + } +} + +void Window::handleChartSelected(QChart *qchart) +{ + if (m_templateComboBox->currentIndex() != 0) + return; + + QAction *chosen = m_menu->exec(QCursor::pos()); + + if (chosen) { + Chart *chart = (Chart *) chosen->data().value<void *>(); + m_grid->replaceChart(qchart, chart); + updateUI(); + } +} + +QMenu *Window::createMenu() +{ + Charts::ChartList list = Charts::chartList(); + QMultiMap<QString, Chart *> categoryMap; + + QMenu *result = new QMenu(this); + + foreach (Chart *chart, list) + categoryMap.insertMulti(chart->category(), chart); + + foreach (const QString &category, categoryMap.uniqueKeys()) { + QMenu *menu(0); + QMultiMap<QString, Chart *> subCategoryMap; + if (category.isEmpty()) { + menu = result; + } else { + menu = new QMenu(category, this); + result->addMenu(menu); + } + + foreach (Chart *chart, categoryMap.values(category)) + subCategoryMap.insert(chart->subCategory(), chart); + + foreach (const QString &subCategory, subCategoryMap.uniqueKeys()) { + QMenu *subMenu(0); + if (subCategory.isEmpty()) { + subMenu = menu; + } else { + subMenu = new QMenu(subCategory, this); + menu->addMenu(subMenu); + } + + foreach (Chart *chart, subCategoryMap.values(subCategory)) { + createMenuAction(subMenu, QIcon(), chart->name(), + qVariantFromValue((void *) chart)); + } + } + } + return result; +} + +QAction *Window::createMenuAction(QMenu *menu, const QIcon &icon, const QString &text, + const QVariant &data) +{ + QAction *action = menu->addAction(icon, text); + action->setCheckable(false); + action->setData(data); + return action; +} + +void Window::handleGeometryChanged() +{ + QSizeF size = m_baseLayout->sizeHint(Qt::MinimumSize); + m_view->scene()->setSceneRect(0, 0, this->width(), this->height()); + m_view->setMinimumSize(size.toSize()); +} diff --git a/tests/manual/chartviewer/window.h b/tests/manual/chartviewer/window.h new file mode 100644 index 00000000..94d954ee --- /dev/null +++ b/tests/manual/chartviewer/window.h @@ -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$ +** +****************************************************************************/ + +#ifndef WINDOW_H +#define WINDOW_H +#include <QtWidgets/QMainWindow> +#include <QtCharts/QChartGlobal> +#include <QtCore/QHash> +#include <QtWidgets/QComboBox> + +class QCheckBox; +class QGraphicsRectItem; +class QGraphicsScene; +class QGraphicsWidget; +class View; +class QGraphicsLinearLayout; +class Chart; +class Grid; +class QPushButton; + +QT_CHARTS_BEGIN_NAMESPACE +class QChart; +QT_CHARTS_END_NAMESPACE + +QT_CHARTS_USE_NAMESPACE + + +class Window: public QMainWindow +{ + Q_OBJECT +public: + explicit Window(const QVariantHash ¶meters, QWidget *parent = 0); + ~Window(); + +private Q_SLOTS: + void updateUI(); + void handleGeometryChanged(); + void handleChartSelected(QChart *chart); +private: + QComboBox *createViewBox(); + QComboBox *createThemeBox(); + QComboBox *createAnimationBox(); + QComboBox *createLegendBox(); + QComboBox *createTempleteBox(); + void connectSignals(); + void createProxyWidgets(); + void comboBoxFocused(QComboBox *combox); + inline void checkAnimationOptions(); + inline void checkView(); + inline void checkLegend(); + inline void checkOpenGL(); + inline void checkTheme(); + inline void checkState(); + inline void checkTemplate(); + QMenu *createMenu(); + QAction *createMenuAction(QMenu *menu, const QIcon &icon, const QString &text, const QVariant &data); + void initializeFromParamaters(const QVariantHash ¶meters); + +private: + QGraphicsScene *m_scene; + View *m_view; + QHash<QString, QGraphicsProxyWidget *> m_widgetHash; + + QGraphicsWidget *m_form; + QComboBox *m_themeComboBox; + QCheckBox *m_antialiasCheckBox; + QComboBox *m_animatedComboBox; + QComboBox *m_legendComboBox; + QComboBox *m_templateComboBox; + QComboBox *m_viewComboBox; + QCheckBox *m_openGLCheckBox; + QCheckBox *m_zoomCheckBox; + QCheckBox *m_scrollCheckBox; + QGraphicsLinearLayout *m_baseLayout; + QMenu *m_menu; + int m_template; + Grid *m_grid; + QString m_category; + QString m_subcategory; + QString m_name; + + friend class ComboBox; +}; + +class ComboBox: public QComboBox +{ +public: + ComboBox(Window *window, QWidget *parent = 0): QComboBox(parent), m_window(window) + {} + +protected: + void focusInEvent(QFocusEvent *e) { + QComboBox::focusInEvent(e); + m_window->comboBoxFocused(this); + } +private: + Window *m_window; +}; + +#endif diff --git a/tests/manual/chartwidgettest/chartwidgettest.pro b/tests/manual/chartwidgettest/chartwidgettest.pro new file mode 100644 index 00000000..3f4cdbb0 --- /dev/null +++ b/tests/manual/chartwidgettest/chartwidgettest.pro @@ -0,0 +1,15 @@ +!include( ../../tests.pri ) { + error( "Couldn't find the test.pri file!" ) +} + +TEMPLATE = app + +QT += core gui opengl widgets + +SOURCES += main.cpp \ + mainwidget.cpp \ + dataseriedialog.cpp + +HEADERS += \ + mainwidget.h \ + dataseriedialog.h diff --git a/tests/manual/chartwidgettest/dataseriedialog.cpp b/tests/manual/chartwidgettest/dataseriedialog.cpp new file mode 100644 index 00000000..41ca56d9 --- /dev/null +++ b/tests/manual/chartwidgettest/dataseriedialog.cpp @@ -0,0 +1,189 @@ +/**************************************************************************** +** +** 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 "dataseriedialog.h" +#include <QtWidgets/QDialogButtonBox> +#include <QtWidgets/QGridLayout> +#include <QtWidgets/QCheckBox> +#include <QtWidgets/QPushButton> +#include <QtWidgets/QGroupBox> +#include <QtWidgets/QRadioButton> +#include <QtWidgets/QLabel> +#include <QtCore/QDebug> + +DataSerieDialog::DataSerieDialog(QWidget *parent) : + QDialog(parent) +{ + QDialogButtonBox *addSeriesBox = new QDialogButtonBox(Qt::Horizontal); + QPushButton *b = addSeriesBox->addButton(QDialogButtonBox::Ok); + connect(b, SIGNAL(clicked()), this, SLOT(accept())); + b = addSeriesBox->addButton(QDialogButtonBox::Cancel); + connect(b, SIGNAL(clicked()), this, SLOT(reject())); + + QGridLayout *grid = new QGridLayout(); + + m_seriesTypeSelector = seriesTypeSelector(); + m_columnCountSelector = columnCountSelector(); + m_rowCountSelector = rowCountSelector(); + m_dataCharacteristicsSelector = dataCharacteristicsSelector(); + + grid->addWidget(m_seriesTypeSelector, 0, 0); + grid->addWidget(m_columnCountSelector, 0, 1); + grid->addWidget(m_rowCountSelector, 1, 1); + grid->addWidget(m_dataCharacteristicsSelector, 1, 0); + m_labelsSelector = new QCheckBox("Labels defined"); + m_labelsSelector->setChecked(true); + grid->addWidget(m_labelsSelector, 2, 0); + grid->addWidget(addSeriesBox, 3, 1); + + setLayout(grid); +} + +QGroupBox *DataSerieDialog::seriesTypeSelector() +{ + QVBoxLayout *layout = new QVBoxLayout(); + + QRadioButton *line = new QRadioButton("Line"); + line->setChecked(true); + layout->addWidget(line); + layout->addWidget(new QRadioButton("Area")); + layout->addWidget(new QRadioButton("Pie")); + layout->addWidget(new QRadioButton("Bar")); + layout->addWidget(new QRadioButton("Stacked bar")); + layout->addWidget(new QRadioButton("Percent bar")); + layout->addWidget(new QRadioButton("Scatter")); + layout->addWidget(new QRadioButton("Spline")); + + QGroupBox *groupBox = new QGroupBox("Series type"); + groupBox->setLayout(layout); + selectRadio(groupBox, 0); + + return groupBox; +} + +QGroupBox *DataSerieDialog::columnCountSelector() +{ + QVBoxLayout *layout = new QVBoxLayout(); + + QRadioButton *radio = new QRadioButton("1"); + radio->setChecked(true); + layout->addWidget(radio); + layout->addWidget(new QRadioButton("2")); + layout->addWidget(new QRadioButton("3")); + layout->addWidget(new QRadioButton("4")); + layout->addWidget(new QRadioButton("5")); + layout->addWidget(new QRadioButton("8")); + layout->addWidget(new QRadioButton("10")); + layout->addWidget(new QRadioButton("100")); + + QGroupBox *groupBox = new QGroupBox("Column count"); + groupBox->setLayout(layout); + selectRadio(groupBox, 0); + + return groupBox; +} + +QGroupBox *DataSerieDialog::rowCountSelector() +{ + QVBoxLayout *layout = new QVBoxLayout(); + + layout->addWidget(new QRadioButton("1")); + QRadioButton *radio = new QRadioButton("10"); + radio->setChecked(true); + layout->addWidget(radio); + layout->addWidget(new QRadioButton("50")); + layout->addWidget(new QRadioButton("100")); + layout->addWidget(new QRadioButton("1000")); + layout->addWidget(new QRadioButton("10000")); + layout->addWidget(new QRadioButton("100000")); + layout->addWidget(new QRadioButton("1000000")); + + QGroupBox *groupBox = new QGroupBox("Row count"); + groupBox->setLayout(layout); + selectRadio(groupBox, 0); + + return groupBox; +} + +QGroupBox *DataSerieDialog::dataCharacteristicsSelector() +{ + QVBoxLayout *layout = new QVBoxLayout(); + + layout->addWidget(new QRadioButton("Linear")); + layout->addWidget(new QRadioButton("Constant")); + layout->addWidget(new QRadioButton("Random")); + layout->addWidget(new QRadioButton("Sin")); + layout->addWidget(new QRadioButton("Sin + random")); + + QGroupBox *groupBox = new QGroupBox("Data Characteristics"); + groupBox->setLayout(layout); + selectRadio(groupBox, 0); + + return groupBox; +} + +void DataSerieDialog::accept() +{ + accepted(radioSelection(m_seriesTypeSelector), + radioSelection(m_columnCountSelector).toInt(), + radioSelection(m_rowCountSelector).toInt(), + radioSelection(m_dataCharacteristicsSelector), + m_labelsSelector->isChecked()); + QDialog::accept(); +} + +void DataSerieDialog::selectRadio(QGroupBox *groupBox, int defaultSelection) +{ + QVBoxLayout *layout = qobject_cast<QVBoxLayout *>(groupBox->layout()); + Q_ASSERT(layout); + Q_ASSERT(layout->count()); + + QLayoutItem *item = 0; + if (defaultSelection == -1) { + item = layout->itemAt(0); + } else if (layout->count() > defaultSelection) { + item = layout->itemAt(defaultSelection); + } + Q_ASSERT(item); + QRadioButton *radio = qobject_cast<QRadioButton *>(item->widget()); + Q_ASSERT(radio); + radio->setChecked(true); +} + +QString DataSerieDialog::radioSelection(QGroupBox *groupBox) +{ + QString selection; + QVBoxLayout *layout = qobject_cast<QVBoxLayout *>(groupBox->layout()); + Q_ASSERT(layout); + + for (int i(0); i < layout->count(); i++) { + QLayoutItem *item = layout->itemAt(i); + Q_ASSERT(item); + QRadioButton *radio = qobject_cast<QRadioButton *>(item->widget()); + Q_ASSERT(radio); + if (radio->isChecked()) { + selection = radio->text(); + break; + } + } + + qDebug() << "radioSelection: " << selection; + return selection; +} diff --git a/tests/manual/chartwidgettest/dataseriedialog.h b/tests/manual/chartwidgettest/dataseriedialog.h new file mode 100644 index 00000000..5c0ee483 --- /dev/null +++ b/tests/manual/chartwidgettest/dataseriedialog.h @@ -0,0 +1,55 @@ +/**************************************************************************** +** +** 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 DATASERIEDIALOG_H +#define DATASERIEDIALOG_H + +#include <QtWidgets/QDialog> + +class QGroupBox; +class QCheckBox; + +class DataSerieDialog : public QDialog +{ + Q_OBJECT +public: + explicit DataSerieDialog(QWidget *parent = 0); + +signals: + void accepted(QString series, int columnCount, int rowCount, QString dataCharacteristics, bool labelsDefined); + +public slots: + void accept(); + +private: + QGroupBox *seriesTypeSelector(); + QGroupBox *columnCountSelector(); + QGroupBox *rowCountSelector(); + QGroupBox *dataCharacteristicsSelector(); + void selectRadio(QGroupBox *groupBox, int defaultSelection); + QString radioSelection(QGroupBox *groupBox); + QGroupBox *m_seriesTypeSelector; + QGroupBox *m_columnCountSelector; + QGroupBox *m_rowCountSelector; + QCheckBox *m_labelsSelector; + QGroupBox *m_dataCharacteristicsSelector; +}; + +#endif // DATASERIEDIALOG_H diff --git a/tests/manual/chartwidgettest/main.cpp b/tests/manual/chartwidgettest/main.cpp new file mode 100644 index 00000000..6d136669 --- /dev/null +++ b/tests/manual/chartwidgettest/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 <QtCore/QtGlobal> +#include <QtWidgets/QApplication> +#include "mainwidget.h" + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + + MainWidget w; + w.resize(1000,600); + w.show(); + + return a.exec(); +} diff --git a/tests/manual/chartwidgettest/mainwidget.cpp b/tests/manual/chartwidgettest/mainwidget.cpp new file mode 100644 index 00000000..97b1e792 --- /dev/null +++ b/tests/manual/chartwidgettest/mainwidget.cpp @@ -0,0 +1,380 @@ +/**************************************************************************** +** +** 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 "dataseriedialog.h" +#include <QtCharts/QChartView> +#include <QtCharts/QPieSeries> +#include <QtCharts/QScatterSeries> +#include <QtCharts/QLineSeries> +#include <QtCharts/QAreaSeries> +#include <QtCharts/QSplineSeries> +#include <QtCharts/QBarSet> +#include <QtCharts/QBarSeries> +#include <QtCharts/QStackedBarSeries> +#include <QtCharts/QPercentBarSeries> +#include <QtWidgets/QPushButton> +#include <QtWidgets/QComboBox> +#include <QtWidgets/QSpinBox> +#include <QtWidgets/QCheckBox> +#include <QtWidgets/QGridLayout> +#include <QtWidgets/QHBoxLayout> +#include <QtWidgets/QLabel> +#include <QtWidgets/QSpacerItem> +#include <QtWidgets/QMessageBox> +#include <cmath> +#include <QtCore/QDebug> +#include <QtGui/QStandardItemModel> +#include <QtCharts/QBarCategoryAxis> +#include <QtOpenGL/QGLWidget> + +QT_CHARTS_USE_NAMESPACE + +MainWidget::MainWidget(QWidget *parent) : + QWidget(parent), + m_addSerieDialog(0), + m_chart(0) +{ + m_chart = new QChart(); + + // Grid layout for the controls for configuring the chart widget + QGridLayout *grid = new QGridLayout(); + QPushButton *addSeriesButton = new QPushButton("Add series"); + connect(addSeriesButton, SIGNAL(clicked()), this, SLOT(addSeries())); + grid->addWidget(addSeriesButton, 0, 1); + initBackroundCombo(grid); + initScaleControls(grid); + initThemeCombo(grid); + initCheckboxes(grid); + + // add row with empty label to make all the other rows static + grid->addWidget(new QLabel(""), grid->rowCount(), 0); + grid->setRowStretch(grid->rowCount() - 1, 1); + + // Create chart view with the chart + m_chartView = new QChartView(m_chart, this); + m_chartView->setRubberBand(QChartView::HorizonalRubberBand); + + // Another grid layout as a main layout + QGridLayout *mainLayout = new QGridLayout(); + mainLayout->addLayout(grid, 0, 0); + mainLayout->addWidget(m_chartView, 0, 1, 3, 1); + setLayout(mainLayout); +} + +// Combo box for selecting the chart's background +void MainWidget::initBackroundCombo(QGridLayout *grid) +{ + QComboBox *backgroundCombo = new QComboBox(this); + backgroundCombo->addItem("Color"); + backgroundCombo->addItem("Gradient"); + backgroundCombo->addItem("Image"); + connect(backgroundCombo, SIGNAL(currentIndexChanged(int)), + this, SLOT(backgroundChanged(int))); + + grid->addWidget(new QLabel("Background:"), grid->rowCount(), 0); + grid->addWidget(backgroundCombo, grid->rowCount() - 1, 1); +} + +// Scale related controls (auto-scale vs. manual min-max values) +void MainWidget::initScaleControls(QGridLayout *grid) +{ + m_autoScaleCheck = new QCheckBox("Automatic scaling"); + connect(m_autoScaleCheck, SIGNAL(stateChanged(int)), this, SLOT(autoScaleChanged(int))); + // Allow setting also non-sense values (like -2147483648 and 2147483647) + m_xMinSpin = new QSpinBox(); + m_xMinSpin->setMinimum(INT_MIN); + m_xMinSpin->setMaximum(INT_MAX); + m_xMinSpin->setValue(0); + connect(m_xMinSpin, SIGNAL(valueChanged(int)), this, SLOT(xMinChanged(int))); + m_xMaxSpin = new QSpinBox(); + m_xMaxSpin->setMinimum(INT_MIN); + m_xMaxSpin->setMaximum(INT_MAX); + m_xMaxSpin->setValue(10); + connect(m_xMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(xMaxChanged(int))); + m_yMinSpin = new QSpinBox(); + m_yMinSpin->setMinimum(INT_MIN); + m_yMinSpin->setMaximum(INT_MAX); + m_yMinSpin->setValue(0); + connect(m_yMinSpin, SIGNAL(valueChanged(int)), this, SLOT(yMinChanged(int))); + m_yMaxSpin = new QSpinBox(); + m_yMaxSpin->setMinimum(INT_MIN); + m_yMaxSpin->setMaximum(INT_MAX); + m_yMaxSpin->setValue(10); + connect(m_yMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(yMaxChanged(int))); + + grid->addWidget(m_autoScaleCheck, grid->rowCount(), 0); + grid->addWidget(new QLabel("x min:"), grid->rowCount(), 0); + grid->addWidget(m_xMinSpin, grid->rowCount() - 1, 1); + grid->addWidget(new QLabel("x max:"), grid->rowCount(), 0); + grid->addWidget(m_xMaxSpin, grid->rowCount() - 1, 1); + grid->addWidget(new QLabel("y min:"), grid->rowCount(), 0); + grid->addWidget(m_yMinSpin, grid->rowCount() - 1, 1); + grid->addWidget(new QLabel("y max:"), grid->rowCount(), 0); + grid->addWidget(m_yMaxSpin, grid->rowCount() - 1, 1); + + m_autoScaleCheck->setChecked(true); +} + +// Combo box for selecting theme +void MainWidget::initThemeCombo(QGridLayout *grid) +{ + QComboBox *chartTheme = new QComboBox(); + chartTheme->addItem("Default"); + chartTheme->addItem("Light"); + chartTheme->addItem("Blue Cerulean"); + chartTheme->addItem("Dark"); + chartTheme->addItem("Brown Sand"); + chartTheme->addItem("Blue NCS"); + chartTheme->addItem("High Contrast"); + chartTheme->addItem("Blue Icy"); + chartTheme->addItem("Qt"); + connect(chartTheme, SIGNAL(currentIndexChanged(int)), + this, SLOT(changeChartTheme(int))); + grid->addWidget(new QLabel("Chart theme:"), 8, 0); + grid->addWidget(chartTheme, 8, 1); +} + +// Different check boxes for customizing chart +void MainWidget::initCheckboxes(QGridLayout *grid) +{ + // TODO: setZoomEnabled slot has been removed from QChartView -> Re-implement zoom on/off + QCheckBox *zoomCheckBox = new QCheckBox("Drag'n drop Zoom"); +// connect(zoomCheckBox, SIGNAL(toggled(bool)), m_chartView, SLOT(setZoomEnabled(bool))); + zoomCheckBox->setChecked(true); + grid->addWidget(zoomCheckBox, grid->rowCount(), 0); + + QCheckBox *aliasCheckBox = new QCheckBox("Anti-alias"); + connect(aliasCheckBox, SIGNAL(toggled(bool)), this, SLOT(antiAliasToggled(bool))); + aliasCheckBox->setChecked(false); + grid->addWidget(aliasCheckBox, grid->rowCount(), 0); + + QCheckBox *openGLCheckBox = new QCheckBox("Use QGLWidget"); + connect(openGLCheckBox, SIGNAL(toggled(bool)), this, SLOT(openGLToggled(bool))); + openGLCheckBox->setChecked(false); + grid->addWidget(openGLCheckBox, grid->rowCount(), 0); +} + +void MainWidget::antiAliasToggled(bool enabled) +{ + m_chartView->setRenderHint(QPainter::Antialiasing, enabled); +} + +void MainWidget::openGLToggled(bool enabled) +{ + if (enabled) { + QGLFormat f = QGLFormat::defaultFormat(); + f.setSampleBuffers(true); + f.setSamples(4); + QGLFormat::setDefaultFormat(f); + QGLWidget *g = new QGLWidget(); + m_chartView->setViewport(g); + } else { + m_chartView->setViewport(0); + } +} + +void MainWidget::addSeries() +{ + if (!m_addSerieDialog) { + m_addSerieDialog = new DataSerieDialog(this); + connect(m_addSerieDialog, SIGNAL(accepted(QString,int,int,QString,bool)), + this, SLOT(addSeries(QString,int,int,QString,bool))); + } + m_addSerieDialog->exec(); +} + +QList<RealList> MainWidget::generateTestData(int columnCount, int rowCount, QString dataCharacteristics) +{ + QList<RealList> testData; + for (int j(0); j < columnCount; j++) { + QList <qreal> newColumn; + for (int i(0); i < rowCount; i++) { + if (dataCharacteristics == "Sin") { + newColumn.append(abs(sin(3.14159265358979 / 50 * i) * 100)); + } else if (dataCharacteristics == "Sin + random") { + newColumn.append(abs(sin(3.14159265358979 / 50 * i) * 100) + (rand() % 5)); + } else if (dataCharacteristics == "Random") { + newColumn.append(rand() % 10 + (qreal) rand() / (qreal) RAND_MAX); + } else if (dataCharacteristics == "Linear") { + //newColumn.append(i * (j + 1.0)); + // TODO: temporary hack to make pie work; prevent zero values: + newColumn.append(i * (j + 1.0) + 0.1); + } else { // "constant" + newColumn.append((j + 1.0)); + } + } + testData.append(newColumn); + } + return testData; +} + +QStringList MainWidget::generateLabels(int count) +{ + QStringList result; + for (int i(0); i < count; i++) + result.append("label" + QString::number(i)); + return result; +} + +void MainWidget::addSeries(QString seriesName, int columnCount, int rowCount, QString dataCharacteristics, bool labelsEnabled) +{ + qDebug() << "addSeries: " << seriesName + << " columnCount: " << columnCount + << " rowCount: " << rowCount + << " dataCharacteristics: " << dataCharacteristics + << " labels enabled: " << labelsEnabled; + m_defaultSeriesName = seriesName; + + QList<RealList> data = generateTestData(columnCount, rowCount, dataCharacteristics); + + // Line series and scatter series use similar data + if (seriesName == "Line") { + for (int j(0); j < data.count(); j ++) { + QList<qreal> column = data.at(j); + QLineSeries *series = new QLineSeries(); + series->setName("line" + QString::number(j)); + for (int i(0); i < column.count(); i++) + series->append(i, column.at(i)); + m_chart->addSeries(series); + } + } else if (seriesName == "Area") { + // TODO: lower series for the area? + for (int j(0); j < data.count(); j ++) { + QList<qreal> column = data.at(j); + QLineSeries *lineSeries = new QLineSeries(); + for (int i(0); i < column.count(); i++) + lineSeries->append(i, column.at(i)); + QAreaSeries *areaSeries = new QAreaSeries(lineSeries); + areaSeries->setName("area" + QString::number(j)); + m_chart->addSeries(areaSeries); + } + } else if (seriesName == "Scatter") { + for (int j(0); j < data.count(); j++) { + QList<qreal> column = data.at(j); + QScatterSeries *series = new QScatterSeries(); + series->setName("scatter" + QString::number(j)); + for (int i(0); i < column.count(); i++) + series->append(i, column.at(i)); + m_chart->addSeries(series); + } + } else if (seriesName == "Pie") { + QStringList labels = generateLabels(rowCount); + for (int j(0); j < data.count(); j++) { + QPieSeries *series = new QPieSeries(); + QList<qreal> column = data.at(j); + for (int i(0); i < column.count(); i++) + series->append(labels.at(i), column.at(i)); + m_chart->addSeries(series); + } + } else if (seriesName == "Bar" + || seriesName == "Stacked bar" + || seriesName == "Percent bar") { + QStringList category; + QStringList labels = generateLabels(rowCount); + foreach (QString label, labels) + category << label; + QAbstractBarSeries* series = 0; + if (seriesName == "Bar") { + series = new QBarSeries(this); + QBarCategoryAxis* axis = new QBarCategoryAxis(); + axis->append(category); + m_chart->setAxisX(axis,series); + } else if (seriesName == "Stacked bar") { + series = new QStackedBarSeries(this); + QBarCategoryAxis* axis = new QBarCategoryAxis(); + axis->append(category); + m_chart->setAxisX(axis,series); + } else { + series = new QPercentBarSeries(this); + QBarCategoryAxis* axis = new QBarCategoryAxis(); + axis->append(category); + m_chart->setAxisX(axis,series); + } + + for (int j(0); j < data.count(); j++) { + QList<qreal> column = data.at(j); + QBarSet *set = new QBarSet("set" + QString::number(j)); + for (int i(0); i < column.count(); i++) + *set << column.at(i); + series->append(set); + } + + m_chart->addSeries(series); + } else if (seriesName == "Spline") { + for (int j(0); j < data.count(); j ++) { + QList<qreal> column = data.at(j); + QSplineSeries *series = new QSplineSeries(); + series->setName("spline" + QString::number(j)); + for (int i(0); i < column.count(); i++) + series->append(i, column.at(i)); + m_chart->addSeries(series); + } + } + m_chart->createDefaultAxes(); +} + +void MainWidget::backgroundChanged(int itemIndex) +{ + qDebug() << "backgroundChanged: " << itemIndex; +} + +void MainWidget::autoScaleChanged(int value) +{ + if (value) { + // TODO: enable auto scaling + } else { + // TODO: set scaling manually (and disable auto scaling) + } + + m_xMinSpin->setEnabled(!value); + m_xMaxSpin->setEnabled(!value); + m_yMinSpin->setEnabled(!value); + m_yMaxSpin->setEnabled(!value); +} + +void MainWidget::xMinChanged(int value) +{ + qDebug() << "xMinChanged: " << value; +} + +void MainWidget::xMaxChanged(int value) +{ + qDebug() << "xMaxChanged: " << value; +} + +void MainWidget::yMinChanged(int value) +{ + qDebug() << "yMinChanged: " << value; +} + +void MainWidget::yMaxChanged(int value) +{ + qDebug() << "yMaxChanged: " << value; +} + +void MainWidget::changeChartTheme(int themeIndex) +{ + qDebug() << "changeChartTheme: " << themeIndex; + if (themeIndex == 0) + m_chart->setTheme(QChart::ChartThemeLight); + else + m_chart->setTheme((QChart::ChartTheme) (themeIndex - 1)); +} diff --git a/tests/manual/chartwidgettest/mainwidget.h b/tests/manual/chartwidgettest/mainwidget.h new file mode 100644 index 00000000..82a710bb --- /dev/null +++ b/tests/manual/chartwidgettest/mainwidget.h @@ -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$ +** +****************************************************************************/ + +#ifndef MAINWIDGET_H +#define MAINWIDGET_H + +#include <QtCharts/QChartGlobal> +#include <QtCharts/QChart> +#include <QtCharts/QChartView> +#include <QtWidgets/QWidget> + +class QSpinBox; +class QCheckBox; +class QGridLayout; + +QT_CHARTS_USE_NAMESPACE + +#define RealList QList<qreal> +class DataSerieDialog; + +class MainWidget : public QWidget +{ + Q_OBJECT +public: + explicit MainWidget(QWidget *parent = 0); + +signals: + +private: + void initBackroundCombo(QGridLayout *grid); + void initScaleControls(QGridLayout *grid); + void initThemeCombo(QGridLayout *grid); + void initCheckboxes(QGridLayout *grid); + +private slots: + void addSeries(); + void addSeries(QString series, int columnCount, int rowCount, QString dataCharacteristics, bool labelsEnabled); + void backgroundChanged(int itemIndex); + void autoScaleChanged(int value); + void xMinChanged(int value); + void xMaxChanged(int value); + void yMinChanged(int value); + void yMaxChanged(int value); + void antiAliasToggled(bool enabled); + void openGLToggled(bool enabled); + void changeChartTheme(int themeIndex); + QList<RealList> generateTestData(int columnCount, int rowCount, QString dataCharacteristics); + QStringList generateLabels(int count); + +private: + DataSerieDialog *m_addSerieDialog; + QChart *m_chart; + QChartView *m_chartView; + QCheckBox *m_autoScaleCheck; + QSpinBox *m_xMinSpin; + QSpinBox *m_xMaxSpin; + QSpinBox *m_yMinSpin; + QSpinBox *m_yMaxSpin; + QString m_defaultSeriesName; + QGridLayout *m_scatterLayout; +}; + +#endif // MAINWIDGET_H diff --git a/tests/manual/manual.pro b/tests/manual/manual.pro new file mode 100644 index 00000000..5f2b85b1 --- /dev/null +++ b/tests/manual/manual.pro @@ -0,0 +1,18 @@ +TEMPLATE = subdirs +SUBDIRS += \ + presenterchart \ + polarcharttest \ + boxplottester + +contains(QT_CONFIG, opengl) { + SUBDIRS += chartwidgettest \ + wavechart \ + chartviewer +} else { + message("OpenGL not available. Some test apps are disabled") +} + +qtHaveModule(quick) { + SUBDIRS += qmlchartproperties \ + qmlchartaxis +} diff --git a/tests/manual/polarcharttest/chartview.cpp b/tests/manual/polarcharttest/chartview.cpp new file mode 100644 index 00000000..37a25f8f --- /dev/null +++ b/tests/manual/polarcharttest/chartview.cpp @@ -0,0 +1,58 @@ +/**************************************************************************** +** +** 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 <QtGui/QMouseEvent> +#include <QtCore/QDebug> +#include <QtCharts/QAbstractAxis> + +QT_CHARTS_USE_NAMESPACE + +ChartView::ChartView(QWidget *parent) : + QChartView(parent) +{ +} + +void ChartView::keyPressEvent(QKeyEvent *event) +{ + switch (event->key()) { + case Qt::Key_Plus: + chart()->zoomIn(); + break; + case Qt::Key_Minus: + chart()->zoomOut(); + break; + case Qt::Key_Left: + chart()->scroll(-1.0, 0); + break; + case Qt::Key_Right: + chart()->scroll(1.0, 0); + break; + case Qt::Key_Up: + chart()->scroll(0, 1.0); + break; + case Qt::Key_Down: + chart()->scroll(0, -1.0); + break; + default: + QGraphicsView::keyPressEvent(event); + break; + } +} diff --git a/tests/manual/polarcharttest/chartview.h b/tests/manual/polarcharttest/chartview.h new file mode 100644 index 00000000..fb8b4ff9 --- /dev/null +++ b/tests/manual/polarcharttest/chartview.h @@ -0,0 +1,38 @@ +/**************************************************************************** +** +** 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 <QtCharts/QChartView> +#include <QtCharts/QPolarChart> + +QT_CHARTS_USE_NAMESPACE + +class ChartView : public QChartView +{ +public: + ChartView(QWidget *parent = 0); + +protected: + void keyPressEvent(QKeyEvent *event); +}; + +#endif diff --git a/tests/manual/polarcharttest/main.cpp b/tests/manual/polarcharttest/main.cpp new file mode 100644 index 00000000..28203655 --- /dev/null +++ b/tests/manual/polarcharttest/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 "mainwindow.h" +#include <QtWidgets/QApplication> + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + MainWindow w; + w.show(); + + return a.exec(); +} diff --git a/tests/manual/polarcharttest/mainwindow.cpp b/tests/manual/polarcharttest/mainwindow.cpp new file mode 100644 index 00000000..79c8918f --- /dev/null +++ b/tests/manual/polarcharttest/mainwindow.cpp @@ -0,0 +1,1199 @@ +/**************************************************************************** +** +** 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 "mainwindow.h" +#include "chartview.h" +#include <QtCharts/QScatterSeries> +#include <QtCharts/QLineSeries> +#include <QtCharts/QSplineSeries> +#include <QtCharts/QAreaSeries> +#include <QtCharts/QBarSeries> +#include <QtCharts/QBarSet> +#include <QtCharts/QValueAxis> +#include <QtCharts/QLogValueAxis> +#include <QtCharts/QDateTimeAxis> +#include <QtCharts/QCategoryAxis> +#include <QtCharts/QPolarChart> +#include <QtCore/QDebug> +#include <QtCore/QtMath> +#include <QtCore/QDateTime> + +QT_CHARTS_USE_NAMESPACE +#include "ui_mainwindow.h" + +MainWindow::MainWindow(QWidget *parent) : + QMainWindow(parent), + ui(new Ui::MainWindow), + m_angularTickCount(9), + m_radialTickCount(11), + m_labelsAngle(0), + m_angularMin(0.0), + m_angularMax(40000.0), + m_radialMin(0.0), + m_radialMax(30000.0), + m_angularShadesVisible(false), + m_radialShadesVisible(false), + m_labelsVisible(true), + m_titleVisible(true), + m_gridVisible(true), + m_arrowVisible(true), + m_angularShadesBrush(new QBrush(Qt::NoBrush)), + m_radialShadesBrush(new QBrush(Qt::NoBrush)), + m_labelBrush(new QBrush(Qt::black)), + m_titleBrush(new QBrush(Qt::black)), + m_backgroundBrush(new QBrush(Qt::white)), + m_plotAreaBackgroundBrush(new QBrush(Qt::NoBrush)), + m_angularShadesPen(new QPen(Qt::NoPen)), + m_radialShadesPen(new QPen(Qt::NoPen)), + m_labelPen(new QPen(Qt::NoPen)), + m_titlePen(new QPen(Qt::NoPen)), + m_gridPen(new QPen(QRgb(0x010101))), // Note: Pure black is default color, so it gets overridden by + m_arrowPen(new QPen(QRgb(0x010101))), // default theme if set to that initially. This is an example of workaround. + m_backgroundPen(new QPen(Qt::NoPen)), + m_plotAreaBackgroundPen(new QPen(Qt::NoPen)), + m_labelFormat(QString("%.2f")), + m_animationOptions(QChart::NoAnimation), + m_angularTitle(QString("Angular Title")), + m_radialTitle(QString("Radial Title")), + m_base(2.0), + m_dateFormat(QString("mm-ss-zzz")), + m_chart(0), + m_angularAxis(0), + m_radialAxis(0), + m_angularAxisMode(AxisModeNone), + m_radialAxisMode(AxisModeNone), + m_moreCategories(false), + m_series1(0), + m_series2(0), + m_series3(0), + m_series4(0), + m_series5(0), + m_series6(0), + m_series7(0) +{ + ui->setupUi(this); + + ui->angularTicksSpin->setValue(m_angularTickCount); + ui->radialTicksSpin->setValue(m_radialTickCount); + ui->anglesSpin->setValue(m_labelsAngle); + ui->radialMinSpin->setValue(m_radialMin); + ui->radialMaxSpin->setValue(m_radialMax); + ui->angularMinSpin->setValue(m_angularMin); + ui->angularMaxSpin->setValue(m_angularMax); + ui->angularShadesComboBox->setCurrentIndex(0); + ui->radialShadesComboBox->setCurrentIndex(0); + ui->labelFormatEdit->setText(m_labelFormat); + ui->dateFormatEdit->setText(m_dateFormat); + ui->moreCategoriesCheckBox->setChecked(m_moreCategories); + + ui->series1checkBox->setChecked(true); + ui->series2checkBox->setChecked(true); + ui->series3checkBox->setChecked(true); + ui->series4checkBox->setChecked(true); + ui->series5checkBox->setChecked(true); + ui->series6checkBox->setChecked(true); + ui->series7checkBox->setChecked(true); + + m_currentLabelFont.setFamily(ui->labelFontComboBox->currentFont().family()); + m_currentLabelFont.setPixelSize(15); + m_currentTitleFont.setFamily(ui->titleFontComboBox->currentFont().family()); + m_currentTitleFont.setPixelSize(30); + + ui->labelFontSizeSpin->setValue(m_currentLabelFont.pixelSize()); + ui->titleFontSizeSpin->setValue(m_currentTitleFont.pixelSize()); + + ui->logBaseSpin->setValue(m_base); + + initXYValueChart(); + setAngularAxis(AxisModeValue); + setRadialAxis(AxisModeValue); + + ui->angularAxisComboBox->setCurrentIndex(int(m_angularAxisMode)); + ui->radialAxisComboBox->setCurrentIndex(int(m_radialAxisMode)); + + connect(ui->angularTicksSpin, SIGNAL(valueChanged(int)), this, SLOT(angularTicksChanged(int))); + connect(ui->radialTicksSpin, SIGNAL(valueChanged(int)), this, SLOT(radialTicksChanged(int))); + connect(ui->anglesSpin, SIGNAL(valueChanged(int)), this, SLOT(anglesChanged(int))); + connect(ui->radialMinSpin, SIGNAL(valueChanged(double)), this, SLOT(radialMinChanged(double))); + connect(ui->radialMaxSpin, SIGNAL(valueChanged(double)), this, SLOT(radialMaxChanged(double))); + connect(ui->angularMinSpin, SIGNAL(valueChanged(double)), this, SLOT(angularMinChanged(double))); + connect(ui->angularMaxSpin, SIGNAL(valueChanged(double)), this, SLOT(angularMaxChanged(double))); + connect(ui->angularShadesComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(angularShadesIndexChanged(int))); + connect(ui->radialShadesComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(radialShadesIndexChanged(int))); + connect(ui->animationsComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(animationIndexChanged(int))); + connect(ui->labelFormatEdit, SIGNAL(textEdited(QString)), this, SLOT(labelFormatEdited(QString))); + connect(ui->labelFontComboBox, SIGNAL(currentFontChanged(QFont)), this, SLOT(labelFontChanged(QFont))); + connect(ui->labelFontSizeSpin, SIGNAL(valueChanged(int)), this, SLOT(labelFontSizeChanged(int))); + connect(ui->labelComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(labelsIndexChanged(int))); + connect(ui->titleFontComboBox, SIGNAL(currentFontChanged(QFont)), this, SLOT(titleFontChanged(QFont))); + connect(ui->titleFontSizeSpin, SIGNAL(valueChanged(int)), this, SLOT(titleFontSizeChanged(int))); + connect(ui->titleComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(titleIndexChanged(int))); + connect(ui->gridComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(gridIndexChanged(int))); + connect(ui->arrowComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(arrowIndexChanged(int))); + connect(ui->logBaseSpin, SIGNAL(valueChanged(double)), this, SLOT(logBaseChanged(double))); + connect(ui->angularAxisComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(angularAxisIndexChanged(int))); + connect(ui->radialAxisComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(radialAxisIndexChanged(int))); + connect(ui->niceNumbersCheckBox, SIGNAL(clicked()), this, SLOT(niceNumbersChecked())); + connect(ui->dateFormatEdit, SIGNAL(textEdited(QString)), this, SLOT(dateFormatEdited(QString))); + connect(ui->moreCategoriesCheckBox, SIGNAL(clicked()), this, SLOT(moreCategoriesChecked())); + connect(ui->series1checkBox, SIGNAL(clicked()), this, SLOT(series1CheckBoxChecked())); + connect(ui->series2checkBox, SIGNAL(clicked()), this, SLOT(series2CheckBoxChecked())); + connect(ui->series3checkBox, SIGNAL(clicked()), this, SLOT(series3CheckBoxChecked())); + connect(ui->series4checkBox, SIGNAL(clicked()), this, SLOT(series4CheckBoxChecked())); + connect(ui->series5checkBox, SIGNAL(clicked()), this, SLOT(series5CheckBoxChecked())); + connect(ui->series6checkBox, SIGNAL(clicked()), this, SLOT(series6CheckBoxChecked())); + connect(ui->series7checkBox, SIGNAL(clicked()), this, SLOT(series7CheckBoxChecked())); + connect(ui->themeComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(themeIndexChanged(int))); + connect(ui->backgroundComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(backgroundIndexChanged(int))); + connect(ui->plotAreaComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(plotAreaIndexChanged(int))); + + ui->chartView->setChart(m_chart); + ui->chartView->setRenderHint(QPainter::Antialiasing); +} + +MainWindow::~MainWindow() +{ + delete ui; + delete m_angularShadesBrush; + delete m_radialShadesBrush; + delete m_angularShadesPen; + delete m_radialShadesPen; +} + +void MainWindow::initXYValueChart() +{ + qreal seriesAngularMin = 1; + qreal seriesAngularMax = 46000; + qreal seriesRadialMin = 1; + qreal seriesRadialMax = 23500; + qreal radialDimension = seriesRadialMax - seriesRadialMin; + qreal angularDimension = seriesAngularMax - seriesAngularMin; + + // Scatter series, points outside min-max ranges should not be drawn + m_series1 = new QScatterSeries(); + m_series1->setName("scatter"); + qreal scatterCount = 10; + qreal scatterAngularStep = angularDimension / scatterCount; + qreal scatterRadialStep = radialDimension / scatterCount; + for (qreal i = 0.0; i < scatterCount; i++) { + m_series1->append((i * scatterAngularStep) + seriesAngularMin, (i * scatterRadialStep) + seriesRadialMin); + //qDebug() << m_series1->points().last(); + } + m_series1->setMarkerSize(10); + *m_series1 << QPointF(50, 50) << QPointF(150, 150) << QPointF(250, 250) << QPointF(350, 350) << QPointF(450, 450); + *m_series1 << QPointF(1050, 0.50) << QPointF(1150, 0.25) << QPointF(1250, 0.12) << QPointF(1350, 0.075) << QPointF(1450, 0.036); + *m_series1 << QPointF(0.50, 2000) << QPointF(0.25, 3500) << QPointF(0.12, 5000) << QPointF(0.075, 6500) << QPointF(0.036, 8000); + + // Line series, points outside min-max ranges should not be drawn, + // but lines should be properly interpolated at chart edges + m_series2 = new QLineSeries(); + m_series2->setName("line 1"); + qreal lineCount = 100; + qreal lineAngularStep = angularDimension / lineCount; + qreal lineRadialStep = radialDimension / lineCount; + for (qreal i = 0.0; i < lineCount; i++) { + m_series2->append((i * lineAngularStep) + seriesAngularMin, (i * lineRadialStep) + seriesRadialMin); + //qDebug() << m_series2->points().last(); + } + QPen series2Pen = QPen(Qt::blue, 10); + //series2Pen.setStyle(Qt::DashDotDotLine); + m_series2->setPen(series2Pen); + + m_series3 = new QLineSeries(); + m_series3->setName("Area upper"); + lineCount = 87; + lineAngularStep = angularDimension / lineCount; + lineRadialStep = radialDimension / lineCount; + for (qreal i = 1.0; i <= lineCount; i++) { + m_series3->append((i * lineAngularStep) + seriesAngularMin, (i * lineRadialStep) + seriesRadialMin + 200.0); + //qDebug() << m_series3->points().last(); + } + + m_series4 = new QLineSeries(); + m_series4->setName("Area lower"); + lineCount = 89; + lineAngularStep = angularDimension / lineCount; + lineRadialStep = radialDimension / lineCount; + for (qreal i = 1.0; i <= lineCount; i++) { + m_series4->append((i * lineAngularStep) + seriesAngularMin + 100.0, (i * lineRadialStep) + seriesRadialMin + i * 300.0); + //qDebug() << m_series4->points().last(); + } + + m_series5 = new QAreaSeries(); + m_series5->setName("area"); + m_series5->setUpperSeries(m_series3); + m_series5->setLowerSeries(m_series4); + m_series5->setOpacity(0.5); + + m_series6 = new QSplineSeries(); + m_series6->setName("spline"); + qreal ad = angularDimension / 20; + qreal rd = radialDimension / 10; + m_series6->append(seriesAngularMin, seriesRadialMin + rd * 2); + m_series6->append(seriesAngularMin + ad, seriesRadialMin + rd * 5); + m_series6->append(seriesAngularMin + ad * 2, seriesRadialMin + rd * 4); + m_series6->append(seriesAngularMin + ad * 3, seriesRadialMin + rd * 9); + m_series6->append(seriesAngularMin + ad * 4, seriesRadialMin + rd * 11); + m_series6->append(seriesAngularMin + ad * 5, seriesRadialMin + rd * 12); + m_series6->append(seriesAngularMin + ad * 6, seriesRadialMin + rd * 9); + m_series6->append(seriesAngularMin + ad * 7, seriesRadialMin + rd * 11); + m_series6->append(seriesAngularMin + ad * 8, seriesRadialMin + rd * 12); + m_series6->append(seriesAngularMin + ad * 9, seriesRadialMin + rd * 6); + m_series6->append(seriesAngularMin + ad * 10, seriesRadialMin + rd * 4); + m_series6->append(seriesAngularMin + ad * 10, seriesRadialMin + rd * 8); + m_series6->append(seriesAngularMin + ad * 11, seriesRadialMin + rd * 9); + m_series6->append(seriesAngularMin + ad * 12, seriesRadialMin + rd * 11); + m_series6->append(seriesAngularMin + ad * 13, seriesRadialMin + rd * 12); + m_series6->append(seriesAngularMin + ad * 14, seriesRadialMin + rd * 6); + m_series6->append(seriesAngularMin + ad * 15, seriesRadialMin + rd * 3); + m_series6->append(seriesAngularMin + ad * 16, seriesRadialMin + rd * 2); + m_series6->append(seriesAngularMin + ad * 17, seriesRadialMin + rd * 6); + m_series6->append(seriesAngularMin + ad * 18, seriesRadialMin + rd * 6); + m_series6->append(seriesAngularMin + ad * 19, seriesRadialMin + rd * 6); + m_series6->append(seriesAngularMin + ad * 20, seriesRadialMin + rd * 6); + m_series6->append(seriesAngularMin + ad * 19, seriesRadialMin + rd * 2); + m_series6->append(seriesAngularMin + ad * 18, seriesRadialMin + rd * 9); + m_series6->append(seriesAngularMin + ad * 17, seriesRadialMin + rd * 7); + m_series6->append(seriesAngularMin + ad * 16, seriesRadialMin + rd * 3); + m_series6->append(seriesAngularMin + ad * 15, seriesRadialMin + rd * 1); + m_series6->append(seriesAngularMin + ad * 14, seriesRadialMin + rd * 7); + m_series6->append(seriesAngularMin + ad * 13, seriesRadialMin + rd * 5); + m_series6->append(seriesAngularMin + ad * 12, seriesRadialMin + rd * 9); + m_series6->append(seriesAngularMin + ad * 11, seriesRadialMin + rd * 1); + m_series6->append(seriesAngularMin + ad * 10, seriesRadialMin + rd * 4); + m_series6->append(seriesAngularMin + ad * 9, seriesRadialMin + rd * 1); + m_series6->append(seriesAngularMin + ad * 8, seriesRadialMin + rd * 2); + m_series6->append(seriesAngularMin + ad * 7, seriesRadialMin + rd * 4); + m_series6->append(seriesAngularMin + ad * 6, seriesRadialMin + rd * 8); + m_series6->append(seriesAngularMin + ad * 5, seriesRadialMin + rd * 12); + m_series6->append(seriesAngularMin + ad * 4, seriesRadialMin + rd * 9); + m_series6->append(seriesAngularMin + ad * 3, seriesRadialMin + rd * 8); + m_series6->append(seriesAngularMin + ad * 2, seriesRadialMin + rd * 7); + m_series6->append(seriesAngularMin + ad, seriesRadialMin + rd * 4); + m_series6->append(seriesAngularMin, seriesRadialMin + rd * 10); + + m_series6->setPointsVisible(true); + QPen series6Pen = QPen(Qt::red, 10); + //series6Pen.setStyle(Qt::DashDotDotLine); + m_series6->setPen(series6Pen); + + // m_series7 shows points at category intersections + m_series7 = new QScatterSeries(); + m_series7->setName("Category check"); + m_series7->setMarkerSize(7); + m_series7->setBrush(QColor(Qt::red)); + m_series7->setMarkerShape(QScatterSeries::MarkerShapeRectangle); + *m_series7 << QPointF(1000, 1000) + << QPointF(1000, 2000) + << QPointF(1000, 4000) + << QPointF(1000, 9000) + << QPointF(1000, 14000) + << QPointF(1000, 16500) + << QPointF(1000, 19000) + + << QPointF(4000, 1000) + << QPointF(4000, 2000) + << QPointF(4000, 4000) + << QPointF(4000, 9000) + << QPointF(4000, 14000) + << QPointF(4000, 16500) + << QPointF(4000, 19000) + + << QPointF(7000, 1000) + << QPointF(7000, 2000) + << QPointF(7000, 4000) + << QPointF(7000, 9000) + << QPointF(7000, 14000) + << QPointF(7000, 16500) + << QPointF(7000, 19000) + + << QPointF(12000, 1000) + << QPointF(12000, 2000) + << QPointF(12000, 4000) + << QPointF(12000, 9000) + << QPointF(12000, 14000) + << QPointF(12000, 16500) + << QPointF(12000, 19000) + + << QPointF(17000, 1000) + << QPointF(17000, 2000) + << QPointF(17000, 4000) + << QPointF(17000, 9000) + << QPointF(17000, 14000) + << QPointF(17000, 16500) + << QPointF(17000, 19000) + + << QPointF(22000, 1000) + << QPointF(22000, 2000) + << QPointF(22000, 4000) + << QPointF(22000, 9000) + << QPointF(22000, 14000) + << QPointF(22000, 16500) + << QPointF(22000, 19000) + + << QPointF(28000, 1000) + << QPointF(28000, 2000) + << QPointF(28000, 4000) + << QPointF(28000, 9000) + << QPointF(28000, 14000) + << QPointF(28000, 16500) + << QPointF(28000, 19000); + + m_chart = new QPolarChart(); + + m_chart->addSeries(m_series1); + m_chart->addSeries(m_series2); + m_chart->addSeries(m_series3); + m_chart->addSeries(m_series4); + m_chart->addSeries(m_series5); + m_chart->addSeries(m_series6); + m_chart->addSeries(m_series7); + + connect(m_series1, SIGNAL(clicked(QPointF)), this, SLOT(seriesClicked(QPointF))); + connect(m_series2, SIGNAL(clicked(QPointF)), this, SLOT(seriesClicked(QPointF))); + connect(m_series3, SIGNAL(clicked(QPointF)), this, SLOT(seriesClicked(QPointF))); + connect(m_series4, SIGNAL(clicked(QPointF)), this, SLOT(seriesClicked(QPointF))); + connect(m_series5, SIGNAL(clicked(QPointF)), this, SLOT(seriesClicked(QPointF))); + connect(m_series6, SIGNAL(clicked(QPointF)), this, SLOT(seriesClicked(QPointF))); + connect(m_series7, SIGNAL(clicked(QPointF)), this, SLOT(seriesClicked(QPointF))); + connect(m_series1, SIGNAL(hovered(QPointF, bool)), this, SLOT(seriesHovered(QPointF, bool))); + connect(m_series2, SIGNAL(hovered(QPointF, bool)), this, SLOT(seriesHovered(QPointF, bool))); + connect(m_series3, SIGNAL(hovered(QPointF, bool)), this, SLOT(seriesHovered(QPointF, bool))); + connect(m_series4, SIGNAL(hovered(QPointF, bool)), this, SLOT(seriesHovered(QPointF, bool))); + connect(m_series5, SIGNAL(hovered(QPointF, bool)), this, SLOT(seriesHovered(QPointF, bool))); + connect(m_series6, SIGNAL(hovered(QPointF, bool)), this, SLOT(seriesHovered(QPointF, bool))); + connect(m_series7, SIGNAL(hovered(QPointF, bool)), this, SLOT(seriesHovered(QPointF, bool))); + + m_chart->setTitle("Use arrow keys to scroll and +/- to zoom"); + m_chart->setAnimationOptions(m_animationOptions); + //m_chart->legend()->setVisible(false); + m_chart->setAcceptHoverEvents(true); + m_chart->setBackgroundBrush(*m_backgroundBrush); + m_chart->setBackgroundPen(*m_backgroundPen); + m_chart->setPlotAreaBackgroundBrush(*m_plotAreaBackgroundBrush); + m_chart->setPlotAreaBackgroundPen(*m_plotAreaBackgroundPen); +} + +void MainWindow::setAngularAxis(MainWindow::AxisMode mode) +{ + if (m_angularAxis) { + m_chart->removeAxis(m_angularAxis); + delete m_angularAxis; + m_angularAxis = 0; + } + + m_angularAxisMode = mode; + + switch (m_angularAxisMode) { + case AxisModeNone: + return; + case AxisModeValue: + m_angularAxis = new QValueAxis(); + static_cast<QValueAxis *>(m_angularAxis)->setTickCount(m_angularTickCount); + static_cast<QValueAxis *>(m_angularAxis)->setLabelFormat(m_labelFormat); + break; + case AxisModeLogValue: + m_angularAxis = new QLogValueAxis(); + static_cast<QLogValueAxis *>(m_angularAxis)->setBase(m_base); + static_cast<QLogValueAxis *>(m_angularAxis)->setLabelFormat(m_labelFormat); + break; + case AxisModeDateTime: + m_angularAxis = new QDateTimeAxis(); + static_cast<QDateTimeAxis *>(m_angularAxis)->setTickCount(m_angularTickCount); + static_cast<QDateTimeAxis *>(m_angularAxis)->setFormat(m_dateFormat); + break; + case AxisModeCategory: + m_angularAxis = new QCategoryAxis(); + applyCategories(); + break; + default: + qWarning() << "Unsupported AxisMode"; + break; + } + + m_angularAxis->setLabelsAngle(m_labelsAngle); + m_angularAxis->setLabelsFont(m_currentLabelFont); + m_angularAxis->setLabelsBrush(*m_labelBrush); + m_angularAxis->setLabelsPen(*m_labelPen); + m_angularAxis->setLabelsVisible(m_labelsVisible); + m_angularAxis->setShadesBrush(*m_angularShadesBrush); + m_angularAxis->setShadesPen(*m_angularShadesPen); + m_angularAxis->setShadesVisible(m_angularShadesVisible); + m_angularAxis->setTitleFont(m_currentTitleFont); + m_angularAxis->setTitleBrush(*m_titleBrush); + m_angularAxis->setTitlePen(*m_titlePen); + m_angularAxis->setTitleVisible(m_titleVisible); + m_angularAxis->setTitleText(m_angularTitle); + m_angularAxis->setGridLinePen(*m_gridPen); + m_angularAxis->setGridLineVisible(m_gridVisible); + m_angularAxis->setLinePen(*m_arrowPen); + m_angularAxis->setLineVisible(m_arrowVisible); + + m_chart->addAxis(m_angularAxis, QPolarChart::PolarOrientationAngular); + + m_series1->attachAxis(m_angularAxis); + m_series2->attachAxis(m_angularAxis); + m_series3->attachAxis(m_angularAxis); + m_series4->attachAxis(m_angularAxis); + m_series5->attachAxis(m_angularAxis); + m_series6->attachAxis(m_angularAxis); + m_series7->attachAxis(m_angularAxis); + + applyRanges(); + + //connect(m_angularAxis, SIGNAL(rangeChanged(qreal, qreal)), this, SLOT(angularRangeChanged(qreal, qreal))); +} + +void MainWindow::setRadialAxis(MainWindow::AxisMode mode) +{ + if (m_radialAxis) { + m_chart->removeAxis(m_radialAxis); + delete m_radialAxis; + m_radialAxis = 0; + } + + m_radialAxisMode = mode; + + switch (m_radialAxisMode) { + case AxisModeNone: + return; + case AxisModeValue: + m_radialAxis = new QValueAxis(); + static_cast<QValueAxis *>(m_radialAxis)->setTickCount(m_radialTickCount); + static_cast<QValueAxis *>(m_radialAxis)->setLabelFormat(m_labelFormat); + break; + case AxisModeLogValue: + m_radialAxis = new QLogValueAxis(); + static_cast<QLogValueAxis *>(m_radialAxis)->setBase(m_base); + static_cast<QLogValueAxis *>(m_radialAxis)->setLabelFormat(m_labelFormat); + break; + case AxisModeDateTime: + m_radialAxis = new QDateTimeAxis(); + static_cast<QDateTimeAxis *>(m_radialAxis)->setTickCount(m_radialTickCount); + static_cast<QDateTimeAxis *>(m_radialAxis)->setFormat(m_dateFormat); + break; + case AxisModeCategory: + m_radialAxis = new QCategoryAxis(); + applyCategories(); + break; + default: + qWarning() << "Unsupported AxisMode"; + break; + } + + m_radialAxis->setLabelsAngle(m_labelsAngle); + m_radialAxis->setLabelsFont(m_currentLabelFont); + m_radialAxis->setLabelsBrush(*m_labelBrush); + m_radialAxis->setLabelsPen(*m_labelPen); + m_radialAxis->setLabelsVisible(m_labelsVisible); + m_radialAxis->setShadesBrush(*m_radialShadesBrush); + m_radialAxis->setShadesPen(*m_radialShadesPen); + m_radialAxis->setShadesVisible(m_radialShadesVisible); + m_radialAxis->setTitleFont(m_currentTitleFont); + m_radialAxis->setTitleBrush(*m_titleBrush); + m_radialAxis->setTitlePen(*m_titlePen); + m_radialAxis->setTitleVisible(m_titleVisible); + m_radialAxis->setTitleText(m_radialTitle); + m_radialAxis->setGridLinePen(*m_gridPen); + m_radialAxis->setGridLineVisible(m_gridVisible); + m_radialAxis->setLinePen(*m_arrowPen); + m_radialAxis->setLineVisible(m_arrowVisible); + + m_chart->addAxis(m_radialAxis, QPolarChart::PolarOrientationRadial); + + m_series1->attachAxis(m_radialAxis); + m_series2->attachAxis(m_radialAxis); + m_series3->attachAxis(m_radialAxis); + m_series4->attachAxis(m_radialAxis); + m_series5->attachAxis(m_radialAxis); + m_series6->attachAxis(m_radialAxis); + m_series7->attachAxis(m_radialAxis); + + applyRanges(); + + series1CheckBoxChecked(); + series2CheckBoxChecked(); + series3CheckBoxChecked(); + series4CheckBoxChecked(); + series5CheckBoxChecked(); + series6CheckBoxChecked(); + series7CheckBoxChecked(); + + //connect(m_radialAxis, SIGNAL(rangeChanged(qreal, qreal)), this, SLOT(radialRangeChanged(qreal, qreal))); +} + +void MainWindow::applyRanges() +{ + if (ui->niceNumbersCheckBox->isChecked()) { + if (m_angularAxisMode == AxisModeValue) { + static_cast<QValueAxis *>(m_angularAxis)->applyNiceNumbers(); + m_angularMin = static_cast<QValueAxis *>(m_angularAxis)->min(); + m_angularMax = static_cast<QValueAxis *>(m_angularAxis)->max(); + m_angularTickCount = static_cast<QValueAxis *>(m_angularAxis)->tickCount(); + } + if (m_radialAxisMode == AxisModeValue) { + static_cast<QValueAxis *>(m_radialAxis)->applyNiceNumbers(); + m_radialMin = static_cast<QValueAxis *>(m_radialAxis)->min(); + m_radialMax = static_cast<QValueAxis *>(m_radialAxis)->max(); + m_radialTickCount = static_cast<QValueAxis *>(m_radialAxis)->tickCount(); + } + } + + if (m_angularAxis) + m_angularAxis->setRange(m_angularMin, m_angularMax); + if (m_radialAxis) + m_radialAxis->setRange(m_radialMin, m_radialMax); +} + +void MainWindow::angularTicksChanged(int value) +{ + m_angularTickCount = value; + if (m_angularAxisMode == AxisModeValue) + static_cast<QValueAxis *>(m_angularAxis)->setTickCount(m_angularTickCount); + else if (m_angularAxisMode == AxisModeDateTime) + static_cast<QDateTimeAxis *>(m_angularAxis)->setTickCount(m_angularTickCount); +} + +void MainWindow::radialTicksChanged(int value) +{ + m_radialTickCount = value; + if (m_radialAxisMode == AxisModeValue) + static_cast<QValueAxis *>(m_radialAxis)->setTickCount(m_radialTickCount); + else if (m_radialAxisMode == AxisModeDateTime) + static_cast<QDateTimeAxis *>(m_radialAxis)->setTickCount(m_radialTickCount); +} + +void MainWindow::anglesChanged(int value) +{ + m_labelsAngle = value; + m_radialAxis->setLabelsAngle(m_labelsAngle); + m_angularAxis->setLabelsAngle(m_labelsAngle); +} + +void MainWindow::angularMinChanged(double value) +{ + m_angularMin = value; + if (m_angularAxisMode != AxisModeDateTime) { + m_angularAxis->setMin(m_angularMin); + } else { + QDateTime dateTime; + dateTime.setMSecsSinceEpoch(qint64(m_angularMin)); + m_angularAxis->setMin(dateTime); + } +} + +void MainWindow::angularMaxChanged(double value) +{ + m_angularMax = value; + if (m_angularAxisMode != AxisModeDateTime) { + m_angularAxis->setMax(m_angularMax); + } else { + QDateTime dateTime; + dateTime.setMSecsSinceEpoch(qint64(m_angularMax)); + m_angularAxis->setMax(dateTime); + } +} + +void MainWindow::radialMinChanged(double value) +{ + m_radialMin = value; + if (m_radialAxisMode != AxisModeDateTime) { + m_radialAxis->setMin(m_radialMin); + } else { + QDateTime dateTime; + dateTime.setMSecsSinceEpoch(qint64(m_radialMin)); + m_radialAxis->setMin(dateTime); + } +} + +void MainWindow::radialMaxChanged(double value) +{ + m_radialMax = value; + if (m_radialAxisMode != AxisModeDateTime) { + m_radialAxis->setMax(m_radialMax); + } else { + QDateTime dateTime; + dateTime.setMSecsSinceEpoch(qint64(m_radialMax)); + m_radialAxis->setMax(dateTime); + } +} + +void MainWindow::angularShadesIndexChanged(int index) +{ + delete m_angularShadesBrush; + delete m_angularShadesPen; + + switch (index) { + case 0: + m_angularShadesBrush = new QBrush(Qt::NoBrush); + m_angularShadesPen = new QPen(Qt::NoPen); + m_angularShadesVisible = false; + break; + case 1: + m_angularShadesBrush = new QBrush(Qt::lightGray); + m_angularShadesPen = new QPen(Qt::NoPen); + m_angularShadesVisible = true; + break; + case 2: + m_angularShadesBrush = new QBrush(Qt::yellow); + m_angularShadesPen = new QPen(Qt::DotLine); + m_angularShadesPen->setWidth(2); + m_angularShadesVisible = true; + break; + default: + break; + } + + m_angularAxis->setShadesBrush(*m_angularShadesBrush); + m_angularAxis->setShadesPen(*m_angularShadesPen); + m_angularAxis->setShadesVisible(m_angularShadesVisible); +} + +void MainWindow::radialShadesIndexChanged(int index) +{ + delete m_radialShadesBrush; + delete m_radialShadesPen; + + switch (index) { + case 0: + m_radialShadesBrush = new QBrush(Qt::NoBrush); + m_radialShadesPen = new QPen(Qt::NoPen); + m_radialShadesVisible = false; + break; + case 1: + m_radialShadesBrush = new QBrush(Qt::green); + m_radialShadesPen = new QPen(Qt::NoPen); + m_radialShadesVisible = true; + break; + case 2: + m_radialShadesBrush = new QBrush(Qt::blue); + m_radialShadesPen = new QPen(Qt::DotLine); + m_radialShadesPen->setWidth(2); + m_radialShadesVisible = true; + break; + default: + break; + } + + m_radialAxis->setShadesBrush(*m_radialShadesBrush); + m_radialAxis->setShadesPen(*m_radialShadesPen); + m_radialAxis->setShadesVisible(m_radialShadesVisible); +} + +void MainWindow::labelFormatEdited(const QString &text) +{ + m_labelFormat = text; + if (m_angularAxisMode == AxisModeValue) + static_cast<QValueAxis *>(m_angularAxis)->setLabelFormat(m_labelFormat); + else if (m_angularAxisMode == AxisModeLogValue) + static_cast<QLogValueAxis *>(m_angularAxis)->setLabelFormat(m_labelFormat); + + if (m_radialAxisMode == AxisModeValue) + static_cast<QValueAxis *>(m_radialAxis)->setLabelFormat(m_labelFormat); + else if (m_radialAxisMode == AxisModeLogValue) + static_cast<QLogValueAxis *>(m_radialAxis)->setLabelFormat(m_labelFormat); +} + +void MainWindow::labelFontChanged(const QFont &font) +{ + m_currentLabelFont = font; + m_currentLabelFont.setPixelSize(ui->labelFontSizeSpin->value()); + m_angularAxis->setLabelsFont(m_currentLabelFont); + m_radialAxis->setLabelsFont(m_currentLabelFont); +} + +void MainWindow::labelFontSizeChanged(int value) +{ + m_currentLabelFont = ui->labelFontComboBox->currentFont(); + m_currentLabelFont.setPixelSize(value); + m_angularAxis->setLabelsFont(m_currentLabelFont); + m_radialAxis->setLabelsFont(m_currentLabelFont); +} + +void MainWindow::animationIndexChanged(int index) +{ + switch (index) { + case 0: + m_animationOptions = QChart::NoAnimation; + break; + case 1: + m_animationOptions = QChart::SeriesAnimations; + break; + case 2: + m_animationOptions = QChart::GridAxisAnimations; + break; + case 3: + m_animationOptions = QChart::AllAnimations; + break; + default: + break; + } + + m_chart->setAnimationOptions(m_animationOptions); +} + +void MainWindow::labelsIndexChanged(int index) +{ + delete m_labelBrush; + delete m_labelPen; + + switch (index) { + case 0: + m_labelBrush = new QBrush(Qt::NoBrush); + m_labelPen = new QPen(Qt::NoPen); + m_labelsVisible = false; + break; + case 1: + m_labelBrush = new QBrush(Qt::black); + m_labelPen = new QPen(Qt::NoPen); + m_labelsVisible = true; + break; + case 2: + m_labelBrush = new QBrush(Qt::white); + m_labelPen = new QPen(Qt::blue); + m_labelsVisible = true; + break; + default: + break; + } + + m_radialAxis->setLabelsBrush(*m_labelBrush); + m_radialAxis->setLabelsPen(*m_labelPen); + m_radialAxis->setLabelsVisible(m_labelsVisible); + m_angularAxis->setLabelsBrush(*m_labelBrush); + m_angularAxis->setLabelsPen(*m_labelPen); + m_angularAxis->setLabelsVisible(m_labelsVisible); +} + +void MainWindow::titleIndexChanged(int index) +{ + delete m_titleBrush; + delete m_titlePen; + + switch (index) { + case 0: + m_titleBrush = new QBrush(Qt::NoBrush); + m_titlePen = new QPen(Qt::NoPen); + m_titleVisible = false; + m_angularTitle = QString(); + m_radialTitle = QString(); + break; + case 1: + m_titleBrush = new QBrush(Qt::NoBrush); + m_titlePen = new QPen(Qt::NoPen); + m_titleVisible = true; + m_angularTitle = QString(); + m_radialTitle = QString(); + break; + case 2: + m_titleBrush = new QBrush(Qt::NoBrush); + m_titlePen = new QPen(Qt::NoPen); + m_titleVisible = false; + m_angularTitle = QString("Invisible Ang. Title!"); + m_radialTitle = QString("Invisible Rad. Title!"); + break; + case 3: + m_titleBrush = new QBrush(Qt::black); + m_titlePen = new QPen(Qt::NoPen); + m_titleVisible = true; + m_angularTitle = QString("Angular Title"); + m_radialTitle = QString("Radial Title"); + break; + case 4: + m_titleBrush = new QBrush(Qt::white); + m_titlePen = new QPen(Qt::blue); + m_titleVisible = true; + m_angularTitle = QString("Angular Blue Title"); + m_radialTitle = QString("Radial Blue Title"); + break; + default: + break; + } + + m_radialAxis->setTitleBrush(*m_titleBrush); + m_radialAxis->setTitlePen(*m_titlePen); + m_radialAxis->setTitleVisible(m_titleVisible); + m_radialAxis->setTitleText(m_radialTitle); + m_angularAxis->setTitleBrush(*m_titleBrush); + m_angularAxis->setTitlePen(*m_titlePen); + m_angularAxis->setTitleVisible(m_titleVisible); + m_angularAxis->setTitleText(m_angularTitle); +} + +void MainWindow::titleFontChanged(const QFont &font) +{ + m_currentTitleFont = font; + m_currentTitleFont.setPixelSize(ui->titleFontSizeSpin->value()); + m_angularAxis->setTitleFont(m_currentTitleFont); + m_radialAxis->setTitleFont(m_currentTitleFont); +} + +void MainWindow::titleFontSizeChanged(int value) +{ + m_currentTitleFont = ui->titleFontComboBox->currentFont(); + m_currentTitleFont.setPixelSize(value); + m_angularAxis->setTitleFont(m_currentTitleFont); + m_radialAxis->setTitleFont(m_currentTitleFont); +} + +void MainWindow::gridIndexChanged(int index) +{ + delete m_gridPen; + + switch (index) { + case 0: + m_gridPen = new QPen(Qt::NoPen); + m_gridVisible = false; + break; + case 1: + m_gridPen = new QPen(Qt::black); + m_gridVisible = true; + break; + case 2: + m_gridPen = new QPen(Qt::red); + m_gridPen->setStyle(Qt::DashDotLine); + m_gridPen->setWidth(3); + m_gridVisible = true; + break; + default: + break; + } + + m_angularAxis->setGridLinePen(*m_gridPen); + m_angularAxis->setGridLineVisible(m_gridVisible); + m_radialAxis->setGridLinePen(*m_gridPen); + m_radialAxis->setGridLineVisible(m_gridVisible); +} + +void MainWindow::arrowIndexChanged(int index) +{ + delete m_arrowPen; + + switch (index) { + case 0: + m_arrowPen = new QPen(Qt::NoPen); + m_arrowVisible = false; + break; + case 1: + m_arrowPen = new QPen(Qt::black); + m_arrowVisible = true; + break; + case 2: + m_arrowPen = new QPen(Qt::red); + m_arrowPen->setStyle(Qt::DashDotLine); + m_arrowPen->setWidth(3); + m_arrowVisible = true; + break; + default: + break; + } + + m_angularAxis->setLinePen(*m_arrowPen); + m_angularAxis->setLineVisible(m_arrowVisible); + m_radialAxis->setLinePen(*m_arrowPen); + m_radialAxis->setLineVisible(m_arrowVisible); +} + +void MainWindow::angularRangeChanged(qreal min, qreal max) +{ + if (!qFuzzyCompare(qreal(ui->angularMinSpin->value()), min)) + ui->angularMinSpin->setValue(min); + if (!qFuzzyCompare(qreal(ui->angularMaxSpin->value()), max)) + ui->angularMaxSpin->setValue(max); +} + +void MainWindow::radialRangeChanged(qreal min, qreal max) +{ + if (!qFuzzyCompare(qreal(ui->radialMinSpin->value()), min)) + ui->radialMinSpin->setValue(min); + if (!qFuzzyCompare(qreal(ui->radialMaxSpin->value()), max)) + ui->radialMaxSpin->setValue(max); +} + +void MainWindow::angularAxisIndexChanged(int index) +{ + switch (index) { + case 0: + setAngularAxis(AxisModeNone); + break; + case 1: + setAngularAxis(AxisModeValue); + break; + case 2: + setAngularAxis(AxisModeLogValue); + break; + case 3: + setAngularAxis(AxisModeDateTime); + break; + case 4: + setAngularAxis(AxisModeCategory); + break; + default: + qWarning("Invalid Index!"); + } +} + +void MainWindow::radialAxisIndexChanged(int index) +{ + switch (index) { + case 0: + setRadialAxis(AxisModeNone); + break; + case 1: + setRadialAxis(AxisModeValue); + break; + case 2: + setRadialAxis(AxisModeLogValue); + break; + case 3: + setRadialAxis(AxisModeDateTime); + break; + case 4: + setRadialAxis(AxisModeCategory); + break; + default: + qWarning("Invalid Index!"); + } +} + +void MainWindow::logBaseChanged(double value) +{ + m_base = value; + if (m_angularAxisMode == AxisModeLogValue) + static_cast<QLogValueAxis *>(m_angularAxis)->setBase(m_base); + if (m_radialAxisMode == AxisModeLogValue) + static_cast<QLogValueAxis *>(m_radialAxis)->setBase(m_base); +} + +void MainWindow::niceNumbersChecked() +{ + if (ui->niceNumbersCheckBox->isChecked()) + applyRanges(); +} + +void MainWindow::dateFormatEdited(const QString &text) +{ + m_dateFormat = text; + if (m_angularAxisMode == AxisModeDateTime) + static_cast<QDateTimeAxis *>(m_angularAxis)->setFormat(m_dateFormat); + if (m_radialAxisMode == AxisModeDateTime) + static_cast<QDateTimeAxis *>(m_radialAxis)->setFormat(m_dateFormat); +} + +void MainWindow::moreCategoriesChecked() +{ + applyCategories(); + m_moreCategories = ui->moreCategoriesCheckBox->isChecked(); +} + +void MainWindow::series1CheckBoxChecked() +{ + if (ui->series1checkBox->isChecked()) + m_series1->setVisible(true); + else + m_series1->setVisible(false); +} + +void MainWindow::series2CheckBoxChecked() +{ + if (ui->series2checkBox->isChecked()) + m_series2->setVisible(true); + else + m_series2->setVisible(false); +} + +void MainWindow::series3CheckBoxChecked() +{ + if (ui->series3checkBox->isChecked()) + m_series3->setVisible(true); + else + m_series3->setVisible(false); +} + +void MainWindow::series4CheckBoxChecked() +{ + if (ui->series4checkBox->isChecked()) + m_series4->setVisible(true); + else + m_series4->setVisible(false); +} + +void MainWindow::series5CheckBoxChecked() +{ + if (ui->series5checkBox->isChecked()) + m_series5->setVisible(true); + else + m_series5->setVisible(false); +} + +void MainWindow::series6CheckBoxChecked() +{ + if (ui->series6checkBox->isChecked()) + m_series6->setVisible(true); + else + m_series6->setVisible(false); +} + +void MainWindow::series7CheckBoxChecked() +{ + if (ui->series7checkBox->isChecked()) + m_series7->setVisible(true); + else + m_series7->setVisible(false); +} + +void MainWindow::themeIndexChanged(int index) +{ + m_chart->setTheme(QChart::ChartTheme(index)); +} + +void MainWindow::seriesHovered(QPointF point, bool state) +{ + QAbstractSeries *series = qobject_cast<QAbstractSeries *>(sender()); + if (series) { + if (state) { + QString str("'%3' - %1 x %2"); + ui->hoverLabel->setText(str.arg(point.x()).arg(point.y()).arg(series->name())); + } else { + ui->hoverLabel->setText("No hover"); + } + } else { + qDebug() << "seriesHovered - invalid sender!"; + } +} + +void MainWindow::seriesClicked(const QPointF &point) +{ + QAbstractSeries *series = qobject_cast<QAbstractSeries *>(sender()); + if (series) { + QString str("'%3' clicked at: %1 x %2"); + m_angularTitle = str.arg(point.x()).arg(point.y()).arg(series->name()); + m_angularAxis->setTitleText(m_angularTitle); + } else { + qDebug() << "seriesClicked - invalid sender!"; + } +} + +void MainWindow::backgroundIndexChanged(int index) +{ + delete m_backgroundBrush; + delete m_backgroundPen; + + switch (index) { + case 0: + m_backgroundBrush = new QBrush(Qt::white); + m_backgroundPen = new QPen(Qt::NoPen); + break; + case 1: + m_backgroundBrush = new QBrush(Qt::blue); + m_backgroundPen = new QPen(Qt::NoPen); + break; + case 2: + m_backgroundBrush = new QBrush(Qt::yellow); + m_backgroundPen = new QPen(Qt::black, 2); + break; + default: + break; + } + m_chart->setBackgroundBrush(*m_backgroundBrush); + m_chart->setBackgroundPen(*m_backgroundPen); +} + +void MainWindow::plotAreaIndexChanged(int index) +{ + delete m_plotAreaBackgroundBrush; + delete m_plotAreaBackgroundPen; + + switch (index) { + case 0: + m_plotAreaBackgroundBrush = new QBrush(Qt::green); + m_plotAreaBackgroundPen = new QPen(Qt::green); + m_chart->setPlotAreaBackgroundVisible(false); + break; + case 1: + m_plotAreaBackgroundBrush = new QBrush(Qt::magenta); + m_plotAreaBackgroundPen = new QPen(Qt::NoPen); + m_chart->setPlotAreaBackgroundVisible(true); + break; + case 2: + m_plotAreaBackgroundBrush = new QBrush(Qt::lightGray); + m_plotAreaBackgroundPen = new QPen(Qt::red, 6); + m_chart->setPlotAreaBackgroundVisible(true); + break; + default: + break; + } + m_chart->setPlotAreaBackgroundBrush(*m_plotAreaBackgroundBrush); + m_chart->setPlotAreaBackgroundPen(*m_plotAreaBackgroundPen); +} + +void MainWindow::applyCategories() +{ + // Basic layout is three categories, extended has five + if (m_angularAxisMode == AxisModeCategory) { + QCategoryAxis *angCatAxis = static_cast<QCategoryAxis *>(m_angularAxis); + if (angCatAxis->count() == 0) { + angCatAxis->setStartValue(4000); + angCatAxis->append("Category A", 7000); + angCatAxis->append("Category B", 12000); + angCatAxis->append("Category C", 17000); + } + if (angCatAxis->count() == 3 && ui->moreCategoriesCheckBox->isChecked()) { + angCatAxis->setStartValue(1000); + angCatAxis->replaceLabel("Category A", "Cat A"); + angCatAxis->replaceLabel("Category B", "Cat B"); + angCatAxis->replaceLabel("Category C", "Cat C"); + angCatAxis->append("Cat D", 22000); + angCatAxis->append("Cat E", 28000); + } else if (angCatAxis->count() == 5 && !ui->moreCategoriesCheckBox->isChecked()) { + angCatAxis->setStartValue(4000); + angCatAxis->replaceLabel("Cat A", "Category A"); + angCatAxis->replaceLabel("Cat B", "Category B"); + angCatAxis->replaceLabel("Cat C", "Category C"); + angCatAxis->remove("Cat D"); + angCatAxis->remove("Cat E"); + } + } + + if (m_radialAxisMode == AxisModeCategory) { + QCategoryAxis *radCatAxis = static_cast<QCategoryAxis *>(m_radialAxis); + if (radCatAxis->count() == 0) { + radCatAxis->setStartValue(2000); + radCatAxis->append("Category 1", 4000); + radCatAxis->append("Category 2", 9000); + radCatAxis->append("Category 3", 14000); + } + if (radCatAxis->count() == 3 && ui->moreCategoriesCheckBox->isChecked()) { + radCatAxis->setStartValue(1000); + radCatAxis->replaceLabel("Category 1", "Cat 1"); + radCatAxis->replaceLabel("Category 2", "Cat 2"); + radCatAxis->replaceLabel("Category 3", "Cat 3"); + radCatAxis->append("Cat 4", 16500); + radCatAxis->append("Cat 5", 19000); + } else if (radCatAxis->count() == 5 && !ui->moreCategoriesCheckBox->isChecked()) { + radCatAxis->setStartValue(2000); + radCatAxis->replaceLabel("Cat 1", "Category 1"); + radCatAxis->replaceLabel("Cat 2", "Category 2"); + radCatAxis->replaceLabel("Cat 3", "Category 3"); + radCatAxis->remove("Cat 4"); + radCatAxis->remove("Cat 5"); + } + } +} diff --git a/tests/manual/polarcharttest/mainwindow.h b/tests/manual/polarcharttest/mainwindow.h new file mode 100644 index 00000000..2257ef04 --- /dev/null +++ b/tests/manual/polarcharttest/mainwindow.h @@ -0,0 +1,161 @@ +/**************************************************************************** +** +** 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 MAINWINDOW_H +#define MAINWINDOW_H + +#include <QtCharts/QPolarChart> +#include <QtWidgets/QMainWindow> +#include <QtGui/QFont> +#include <QtCharts/QChart> +#include <QtCharts/QScatterSeries> +#include <QtCharts/QLineSeries> +#include <QtCharts/QSplineSeries> +#include <QtCharts/QAreaSeries> + +namespace Ui { +class MainWindow; +} + +QT_CHARTS_USE_NAMESPACE + +class QBrush; +class QPen; + +class MainWindow : public QMainWindow +{ + Q_OBJECT + +public: + explicit MainWindow(QWidget *parent = 0); + ~MainWindow(); + +public slots: + void angularTicksChanged(int value); + void radialTicksChanged(int value); + void anglesChanged(int value); + void angularMinChanged(double value); + void angularMaxChanged(double value); + void radialMinChanged(double value); + void radialMaxChanged(double value); + void angularShadesIndexChanged(int index); + void radialShadesIndexChanged(int index); + void labelFormatEdited(const QString &text); + void labelFontChanged(const QFont &font); + void labelFontSizeChanged(int value); + void animationIndexChanged(int index); + void labelsIndexChanged(int index); + void titleIndexChanged(int index); + void titleFontChanged(const QFont &font); + void titleFontSizeChanged(int value); + void gridIndexChanged(int index); + void arrowIndexChanged(int index); + void angularRangeChanged(qreal min, qreal max); + void radialRangeChanged(qreal min, qreal max); + void angularAxisIndexChanged(int index); + void radialAxisIndexChanged(int index); + void logBaseChanged(double value); + void niceNumbersChecked(); + void dateFormatEdited(const QString &text); + void moreCategoriesChecked(); + void series1CheckBoxChecked(); + void series2CheckBoxChecked(); + void series3CheckBoxChecked(); + void series4CheckBoxChecked(); + void series5CheckBoxChecked(); + void series6CheckBoxChecked(); + void series7CheckBoxChecked(); + void themeIndexChanged(int index); + void seriesHovered(QPointF point, bool state); + void seriesClicked(const QPointF &point); + void backgroundIndexChanged(int index); + void plotAreaIndexChanged(int index); + +private: + enum AxisMode { + AxisModeNone, + AxisModeValue, + AxisModeLogValue, + AxisModeDateTime, + AxisModeCategory + }; + + void initXYValueChart(); + void setAngularAxis(AxisMode mode); + void setRadialAxis(AxisMode mode); + + void applyRanges(); + void applyCategories(); + + Ui::MainWindow *ui; + + int m_angularTickCount; + int m_radialTickCount; + qreal m_labelsAngle; + qreal m_angularMin; + qreal m_angularMax; + qreal m_radialMin; + qreal m_radialMax; + bool m_angularShadesVisible; + bool m_radialShadesVisible; + bool m_labelsVisible; + bool m_titleVisible; + bool m_gridVisible; + bool m_arrowVisible; + QBrush *m_angularShadesBrush; + QBrush *m_radialShadesBrush; + QBrush *m_labelBrush; + QBrush *m_titleBrush; + QBrush *m_backgroundBrush; + QBrush *m_plotAreaBackgroundBrush; + QPen *m_angularShadesPen; + QPen *m_radialShadesPen; + QPen *m_labelPen; + QPen *m_titlePen; + QPen *m_gridPen; + QPen *m_arrowPen; + QPen *m_backgroundPen; + QPen *m_plotAreaBackgroundPen; + QString m_labelFormat; + QFont m_currentLabelFont; + QFont m_currentTitleFont; + QChart::AnimationOptions m_animationOptions; + QString m_angularTitle; + QString m_radialTitle; + qreal m_base; + QString m_dateFormat; + + QPolarChart *m_chart; + QAbstractAxis *m_angularAxis; + QAbstractAxis *m_radialAxis; + AxisMode m_angularAxisMode; + AxisMode m_radialAxisMode; + bool m_moreCategories; + + QScatterSeries *m_series1; + QLineSeries *m_series2; + QLineSeries *m_series3; + QLineSeries *m_series4; + QAreaSeries *m_series5; + QSplineSeries *m_series6; + QScatterSeries *m_series7; +}; + +#endif // MAINWINDOW_H diff --git a/tests/manual/polarcharttest/mainwindow.ui b/tests/manual/polarcharttest/mainwindow.ui new file mode 100644 index 00000000..cc4b1994 --- /dev/null +++ b/tests/manual/polarcharttest/mainwindow.ui @@ -0,0 +1,1002 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>MainWindow</class> + <widget class="QMainWindow" name="MainWindow"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>1193</width> + <height>956</height> + </rect> + </property> + <property name="windowTitle"> + <string>MainWindow</string> + </property> + <widget class="QWidget" name="centralWidget"> + <layout class="QHBoxLayout" name="horizontalLayout"> + <item> + <widget class="ChartView" name="chartView"/> + </item> + <item> + <widget class="QGroupBox" name="settingsBox"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Minimum" vsizetype="Minimum"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="minimumSize"> + <size> + <width>200</width> + <height>0</height> + </size> + </property> + <property name="title"> + <string>Settings</string> + </property> + <widget class="QSpinBox" name="radialTicksSpin"> + <property name="geometry"> + <rect> + <x>110</x> + <y>90</y> + <width>71</width> + <height>22</height> + </rect> + </property> + </widget> + <widget class="QLabel" name="label"> + <property name="geometry"> + <rect> + <x>10</x> + <y>90</y> + <width>101</width> + <height>16</height> + </rect> + </property> + <property name="text"> + <string>Radial Tick count</string> + </property> + </widget> + <widget class="QLabel" name="label_2"> + <property name="geometry"> + <rect> + <x>10</x> + <y>120</y> + <width>101</width> + <height>16</height> + </rect> + </property> + <property name="text"> + <string>Angular Tick count</string> + </property> + </widget> + <widget class="QSpinBox" name="angularTicksSpin"> + <property name="geometry"> + <rect> + <x>110</x> + <y>120</y> + <width>71</width> + <height>22</height> + </rect> + </property> + </widget> + <widget class="QSpinBox" name="anglesSpin"> + <property name="geometry"> + <rect> + <x>110</x> + <y>150</y> + <width>71</width> + <height>22</height> + </rect> + </property> + <property name="minimum"> + <number>-9999</number> + </property> + <property name="maximum"> + <number>9999</number> + </property> + <property name="singleStep"> + <number>5</number> + </property> + </widget> + <widget class="QLabel" name="label_3"> + <property name="geometry"> + <rect> + <x>10</x> + <y>150</y> + <width>101</width> + <height>16</height> + </rect> + </property> + <property name="text"> + <string>Label angles</string> + </property> + </widget> + <widget class="QLabel" name="label_4"> + <property name="geometry"> + <rect> + <x>10</x> + <y>180</y> + <width>101</width> + <height>16</height> + </rect> + </property> + <property name="text"> + <string>Angular min</string> + </property> + </widget> + <widget class="QLabel" name="label_5"> + <property name="geometry"> + <rect> + <x>10</x> + <y>210</y> + <width>101</width> + <height>16</height> + </rect> + </property> + <property name="text"> + <string>Angular max</string> + </property> + </widget> + <widget class="QDoubleSpinBox" name="angularMinSpin"> + <property name="geometry"> + <rect> + <x>90</x> + <y>180</y> + <width>91</width> + <height>22</height> + </rect> + </property> + <property name="decimals"> + <number>5</number> + </property> + <property name="minimum"> + <double>-999999999.000000000000000</double> + </property> + <property name="maximum"> + <double>999999999.000000000000000</double> + </property> + <property name="singleStep"> + <double>10.000000000000000</double> + </property> + </widget> + <widget class="QDoubleSpinBox" name="angularMaxSpin"> + <property name="geometry"> + <rect> + <x>90</x> + <y>210</y> + <width>91</width> + <height>22</height> + </rect> + </property> + <property name="decimals"> + <number>5</number> + </property> + <property name="minimum"> + <double>-999999999.000000000000000</double> + </property> + <property name="maximum"> + <double>999999999.000000000000000</double> + </property> + <property name="singleStep"> + <double>10.000000000000000</double> + </property> + </widget> + <widget class="QDoubleSpinBox" name="radialMaxSpin"> + <property name="geometry"> + <rect> + <x>90</x> + <y>270</y> + <width>91</width> + <height>22</height> + </rect> + </property> + <property name="decimals"> + <number>5</number> + </property> + <property name="minimum"> + <double>-999999999.000000000000000</double> + </property> + <property name="maximum"> + <double>999999999.000000000000000</double> + </property> + <property name="singleStep"> + <double>10.000000000000000</double> + </property> + </widget> + <widget class="QDoubleSpinBox" name="radialMinSpin"> + <property name="geometry"> + <rect> + <x>90</x> + <y>240</y> + <width>91</width> + <height>22</height> + </rect> + </property> + <property name="decimals"> + <number>5</number> + </property> + <property name="minimum"> + <double>-999999999.000000000000000</double> + </property> + <property name="maximum"> + <double>999999999.000000000000000</double> + </property> + <property name="singleStep"> + <double>10.000000000000000</double> + </property> + </widget> + <widget class="QLabel" name="label_11"> + <property name="geometry"> + <rect> + <x>10</x> + <y>270</y> + <width>101</width> + <height>16</height> + </rect> + </property> + <property name="text"> + <string>Radial max</string> + </property> + </widget> + <widget class="QLabel" name="label_12"> + <property name="geometry"> + <rect> + <x>10</x> + <y>240</y> + <width>101</width> + <height>16</height> + </rect> + </property> + <property name="text"> + <string>Radial min</string> + </property> + </widget> + <widget class="QComboBox" name="angularShadesComboBox"> + <property name="geometry"> + <rect> + <x>10</x> + <y>300</y> + <width>171</width> + <height>22</height> + </rect> + </property> + <item> + <property name="text"> + <string>No angular shades</string> + </property> + </item> + <item> + <property name="text"> + <string>Gray angular shades</string> + </property> + </item> + <item> + <property name="text"> + <string>Yellow ang. shades + custom pen</string> + </property> + </item> + </widget> + <widget class="QComboBox" name="radialShadesComboBox"> + <property name="geometry"> + <rect> + <x>10</x> + <y>330</y> + <width>171</width> + <height>22</height> + </rect> + </property> + <item> + <property name="text"> + <string>No radial shades</string> + </property> + </item> + <item> + <property name="text"> + <string>Green radial shades</string> + </property> + </item> + <item> + <property name="text"> + <string>Blue rad. shades + custom pen</string> + </property> + </item> + </widget> + <widget class="QLabel" name="label_13"> + <property name="geometry"> + <rect> + <x>10</x> + <y>360</y> + <width>101</width> + <height>16</height> + </rect> + </property> + <property name="text"> + <string>Label format</string> + </property> + </widget> + <widget class="QLineEdit" name="labelFormatEdit"> + <property name="geometry"> + <rect> + <x>100</x> + <y>360</y> + <width>81</width> + <height>20</height> + </rect> + </property> + </widget> + <widget class="QLabel" name="label_14"> + <property name="geometry"> + <rect> + <x>10</x> + <y>390</y> + <width>101</width> + <height>16</height> + </rect> + </property> + <property name="text"> + <string>Label font size</string> + </property> + </widget> + <widget class="QFontComboBox" name="labelFontComboBox"> + <property name="geometry"> + <rect> + <x>10</x> + <y>420</y> + <width>171</width> + <height>22</height> + </rect> + </property> + </widget> + <widget class="QSpinBox" name="labelFontSizeSpin"> + <property name="geometry"> + <rect> + <x>100</x> + <y>390</y> + <width>81</width> + <height>22</height> + </rect> + </property> + <property name="minimum"> + <number>-100000</number> + </property> + <property name="maximum"> + <number>100000</number> + </property> + </widget> + <widget class="QComboBox" name="animationsComboBox"> + <property name="geometry"> + <rect> + <x>10</x> + <y>480</y> + <width>171</width> + <height>22</height> + </rect> + </property> + <item> + <property name="text"> + <string>No animations</string> + </property> + </item> + <item> + <property name="text"> + <string>Series animation</string> + </property> + </item> + <item> + <property name="text"> + <string>Grid animation</string> + </property> + </item> + <item> + <property name="text"> + <string>All animations</string> + </property> + </item> + </widget> + <widget class="QComboBox" name="labelComboBox"> + <property name="geometry"> + <rect> + <x>10</x> + <y>450</y> + <width>171</width> + <height>22</height> + </rect> + </property> + <property name="currentIndex"> + <number>1</number> + </property> + <item> + <property name="text"> + <string>No labels</string> + </property> + </item> + <item> + <property name="text"> + <string>Black label</string> + </property> + </item> + <item> + <property name="text"> + <string>White label + blue pen</string> + </property> + </item> + </widget> + <widget class="QSpinBox" name="titleFontSizeSpin"> + <property name="geometry"> + <rect> + <x>100</x> + <y>510</y> + <width>81</width> + <height>22</height> + </rect> + </property> + <property name="minimum"> + <number>-100000</number> + </property> + <property name="maximum"> + <number>100000</number> + </property> + </widget> + <widget class="QComboBox" name="titleComboBox"> + <property name="geometry"> + <rect> + <x>10</x> + <y>570</y> + <width>171</width> + <height>22</height> + </rect> + </property> + <property name="sizePolicy"> + <sizepolicy hsizetype="Fixed" vsizetype="Fixed"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="currentIndex"> + <number>3</number> + </property> + <item> + <property name="text"> + <string>Invisible empty title</string> + </property> + </item> + <item> + <property name="text"> + <string>Visible empty title</string> + </property> + </item> + <item> + <property name="text"> + <string>Invisible title</string> + </property> + </item> + <item> + <property name="text"> + <string>Black title</string> + </property> + </item> + <item> + <property name="text"> + <string>White title + blue pen</string> + </property> + </item> + </widget> + <widget class="QFontComboBox" name="titleFontComboBox"> + <property name="geometry"> + <rect> + <x>10</x> + <y>540</y> + <width>171</width> + <height>22</height> + </rect> + </property> + </widget> + <widget class="QLabel" name="label_15"> + <property name="geometry"> + <rect> + <x>10</x> + <y>510</y> + <width>101</width> + <height>16</height> + </rect> + </property> + <property name="text"> + <string>Title font size</string> + </property> + </widget> + <widget class="QComboBox" name="gridComboBox"> + <property name="geometry"> + <rect> + <x>10</x> + <y>600</y> + <width>171</width> + <height>22</height> + </rect> + </property> + <property name="sizePolicy"> + <sizepolicy hsizetype="Fixed" vsizetype="Fixed"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="currentIndex"> + <number>1</number> + </property> + <item> + <property name="text"> + <string>Invisible grid</string> + </property> + </item> + <item> + <property name="text"> + <string>Black grid</string> + </property> + </item> + <item> + <property name="text"> + <string>Custom grid pen</string> + </property> + </item> + </widget> + <widget class="QComboBox" name="arrowComboBox"> + <property name="geometry"> + <rect> + <x>10</x> + <y>630</y> + <width>171</width> + <height>22</height> + </rect> + </property> + <property name="sizePolicy"> + <sizepolicy hsizetype="Fixed" vsizetype="Fixed"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="currentIndex"> + <number>1</number> + </property> + <item> + <property name="text"> + <string>Invisible arrow</string> + </property> + </item> + <item> + <property name="text"> + <string>Black arrow</string> + </property> + </item> + <item> + <property name="text"> + <string>Custom arrow pen</string> + </property> + </item> + </widget> + <widget class="QComboBox" name="angularAxisComboBox"> + <property name="geometry"> + <rect> + <x>10</x> + <y>20</y> + <width>171</width> + <height>22</height> + </rect> + </property> + <property name="currentIndex"> + <number>1</number> + </property> + <item> + <property name="text"> + <string>No Angular Axis</string> + </property> + </item> + <item> + <property name="text"> + <string>Angular Value Axis</string> + </property> + </item> + <item> + <property name="text"> + <string>Angular Log Axis</string> + </property> + </item> + <item> + <property name="text"> + <string>Angular DateTime Axis</string> + </property> + </item> + <item> + <property name="text"> + <string>Angular Category Axis</string> + </property> + </item> + </widget> + <widget class="QComboBox" name="radialAxisComboBox"> + <property name="geometry"> + <rect> + <x>10</x> + <y>50</y> + <width>171</width> + <height>22</height> + </rect> + </property> + <property name="currentIndex"> + <number>1</number> + </property> + <item> + <property name="text"> + <string>No Radial Axis</string> + </property> + </item> + <item> + <property name="text"> + <string>Radial Value Axis</string> + </property> + </item> + <item> + <property name="text"> + <string>Radial Log Axis</string> + </property> + </item> + <item> + <property name="text"> + <string>Radial DateTime Axis</string> + </property> + </item> + <item> + <property name="text"> + <string>Radial Category Axis</string> + </property> + </item> + </widget> + <widget class="QLabel" name="label_16"> + <property name="geometry"> + <rect> + <x>10</x> + <y>660</y> + <width>101</width> + <height>16</height> + </rect> + </property> + <property name="text"> + <string>Log Base</string> + </property> + </widget> + <widget class="QDoubleSpinBox" name="logBaseSpin"> + <property name="geometry"> + <rect> + <x>90</x> + <y>660</y> + <width>91</width> + <height>22</height> + </rect> + </property> + <property name="decimals"> + <number>5</number> + </property> + <property name="minimum"> + <double>-999999999.000000000000000</double> + </property> + <property name="maximum"> + <double>999999999.000000000000000</double> + </property> + <property name="value"> + <double>8.000000000000000</double> + </property> + </widget> + <widget class="QCheckBox" name="niceNumbersCheckBox"> + <property name="geometry"> + <rect> + <x>10</x> + <y>690</y> + <width>91</width> + <height>16</height> + </rect> + </property> + <property name="text"> + <string>Nice Numbers</string> + </property> + </widget> + <widget class="QLineEdit" name="dateFormatEdit"> + <property name="geometry"> + <rect> + <x>100</x> + <y>710</y> + <width>81</width> + <height>20</height> + </rect> + </property> + </widget> + <widget class="QLabel" name="label_17"> + <property name="geometry"> + <rect> + <x>10</x> + <y>710</y> + <width>101</width> + <height>16</height> + </rect> + </property> + <property name="text"> + <string>DateTime format</string> + </property> + </widget> + <widget class="QCheckBox" name="moreCategoriesCheckBox"> + <property name="geometry"> + <rect> + <x>100</x> + <y>690</y> + <width>141</width> + <height>16</height> + </rect> + </property> + <property name="text"> + <string>More Categories</string> + </property> + </widget> + <widget class="QCheckBox" name="series1checkBox"> + <property name="geometry"> + <rect> + <x>10</x> + <y>730</y> + <width>31</width> + <height>16</height> + </rect> + </property> + <property name="text"> + <string>1</string> + </property> + </widget> + <widget class="QCheckBox" name="series2checkBox"> + <property name="geometry"> + <rect> + <x>40</x> + <y>730</y> + <width>31</width> + <height>16</height> + </rect> + </property> + <property name="text"> + <string>2</string> + </property> + </widget> + <widget class="QCheckBox" name="series3checkBox"> + <property name="geometry"> + <rect> + <x>70</x> + <y>730</y> + <width>31</width> + <height>16</height> + </rect> + </property> + <property name="text"> + <string>3</string> + </property> + </widget> + <widget class="QCheckBox" name="series4checkBox"> + <property name="geometry"> + <rect> + <x>10</x> + <y>750</y> + <width>31</width> + <height>16</height> + </rect> + </property> + <property name="text"> + <string>4</string> + </property> + </widget> + <widget class="QCheckBox" name="series5checkBox"> + <property name="geometry"> + <rect> + <x>40</x> + <y>750</y> + <width>31</width> + <height>16</height> + </rect> + </property> + <property name="text"> + <string>5</string> + </property> + </widget> + <widget class="QCheckBox" name="series6checkBox"> + <property name="geometry"> + <rect> + <x>70</x> + <y>750</y> + <width>31</width> + <height>16</height> + </rect> + </property> + <property name="text"> + <string>6</string> + </property> + </widget> + <widget class="QCheckBox" name="series7checkBox"> + <property name="geometry"> + <rect> + <x>100</x> + <y>740</y> + <width>31</width> + <height>16</height> + </rect> + </property> + <property name="text"> + <string>7</string> + </property> + </widget> + <widget class="QComboBox" name="themeComboBox"> + <property name="geometry"> + <rect> + <x>10</x> + <y>770</y> + <width>171</width> + <height>22</height> + </rect> + </property> + <property name="sizePolicy"> + <sizepolicy hsizetype="Fixed" vsizetype="Fixed"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="currentIndex"> + <number>0</number> + </property> + <item> + <property name="text"> + <string>Theme: Light</string> + </property> + </item> + <item> + <property name="text"> + <string>Theme: Blue Cerulean</string> + </property> + </item> + <item> + <property name="text"> + <string>Theme: Dark</string> + </property> + </item> + <item> + <property name="text"> + <string>Theme: Brown Sand</string> + </property> + </item> + <item> + <property name="text"> + <string>Theme: Blue Ncs</string> + </property> + </item> + <item> + <property name="text"> + <string>Theme: High Contrast</string> + </property> + </item> + <item> + <property name="text"> + <string>Theme: Blue Icy</string> + </property> + </item> + <item> + <property name="text"> + <string>Theme: Qt</string> + </property> + </item> + </widget> + <widget class="QLabel" name="hoverLabel"> + <property name="geometry"> + <rect> + <x>10</x> + <y>800</y> + <width>171</width> + <height>16</height> + </rect> + </property> + <property name="text"> + <string>Hover coordinates here!</string> + </property> + </widget> + <widget class="QComboBox" name="backgroundComboBox"> + <property name="geometry"> + <rect> + <x>10</x> + <y>820</y> + <width>171</width> + <height>22</height> + </rect> + </property> + <property name="sizePolicy"> + <sizepolicy hsizetype="Fixed" vsizetype="Fixed"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="currentIndex"> + <number>0</number> + </property> + <item> + <property name="text"> + <string>Background: White</string> + </property> + </item> + <item> + <property name="text"> + <string>Background: Blue</string> + </property> + </item> + <item> + <property name="text"> + <string>Background: Yellow + Black Border</string> + </property> + </item> + </widget> + <widget class="QComboBox" name="plotAreaComboBox"> + <property name="geometry"> + <rect> + <x>10</x> + <y>850</y> + <width>171</width> + <height>22</height> + </rect> + </property> + <property name="sizePolicy"> + <sizepolicy hsizetype="Fixed" vsizetype="Fixed"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="currentIndex"> + <number>0</number> + </property> + <item> + <property name="text"> + <string>PlotArea: Transparent</string> + </property> + </item> + <item> + <property name="text"> + <string>PlotArea: Magenta</string> + </property> + </item> + <item> + <property name="text"> + <string>PlotArea: Gray + Red Border</string> + </property> + </item> + </widget> + </widget> + </item> + </layout> + </widget> + <widget class="QMenuBar" name="menuBar"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>1193</width> + <height>21</height> + </rect> + </property> + </widget> + <widget class="QToolBar" name="mainToolBar"> + <attribute name="toolBarArea"> + <enum>TopToolBarArea</enum> + </attribute> + <attribute name="toolBarBreak"> + <bool>false</bool> + </attribute> + </widget> + <widget class="QStatusBar" name="statusBar"/> + </widget> + <layoutdefault spacing="6" margin="11"/> + <customwidgets> + <customwidget> + <class>ChartView</class> + <extends>QGraphicsView</extends> + <header>chartview.h</header> + </customwidget> + </customwidgets> + <resources/> + <connections/> +</ui> diff --git a/tests/manual/polarcharttest/polarcharttest.pro b/tests/manual/polarcharttest/polarcharttest.pro new file mode 100644 index 00000000..a8409769 --- /dev/null +++ b/tests/manual/polarcharttest/polarcharttest.pro @@ -0,0 +1,19 @@ +!include( ../../tests.pri ) { + error( "Couldn't find the test.pri file!" ) +} + +QT += core gui widgets + +TARGET = polarcharttest +TEMPLATE = app +INCLUDEPATH += . + + +SOURCES += main.cpp \ + mainwindow.cpp \ + chartview.cpp + +HEADERS += mainwindow.h \ + chartview.h + +FORMS += mainwindow.ui diff --git a/tests/manual/presenterchart/chartview.cpp b/tests/manual/presenterchart/chartview.cpp new file mode 100644 index 00000000..be01933c --- /dev/null +++ b/tests/manual/presenterchart/chartview.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 "chartview.h" +#include <QtCharts/QLineSeries> +#include <QtCharts/QScatterSeries> +#include <QtCharts/QSplineSeries> +#include <QtCharts/QAreaSeries> +#include <QtCore/QTime> + +ChartView::ChartView(QChart *chart, QWidget *parent) + : QChartView(chart, parent), + m_index(-1), + m_chart(chart) +{ + m_chart->setTitle("Charts presenter"); + m_chart->setDropShadowEnabled(false); + QObject::connect(&m_timer, SIGNAL(timeout()), this, SLOT(handleTimeout())); + m_timer.setInterval(3000); + + //![1] + QLineSeries *series0 = new QLineSeries(); + series0->setName("line"); + + QScatterSeries *series1 = new QScatterSeries(); + series1->setName("scatter"); + + QSplineSeries *series2 = new QSplineSeries(); + series2->setName("spline"); + + QAreaSeries *series3 = new QAreaSeries(series0); + series3->setName("area"); + //![1] + + //![2] + int numPoints = 10; + + for (int x = 0; x <= numPoints; ++x) { + qreal y = qrand() % 100; + series0->append(x, y); + series1->append(x, y); + series2->append(x, y); + } + //![2] + + //![3] + m_series << series0; + m_titles << m_chart->title() + ": LineChart"; + m_series << series1; + m_titles << m_chart->title() + ": ScatterChart"; + m_series << series2; + m_titles << m_chart->title() + ": SplineChart"; + m_series << series3; + m_titles << m_chart->title() + ": AreaChart"; + //![3] + + m_timer.start(); + handleTimeout(); +} + +ChartView::~ChartView() +{ + if (m_series.size() == 0) + return; + m_chart->removeSeries(m_series.at(m_index)); + m_series.removeLast(); //remove QAreaSeries instance since they will be deleted when QLineSeries instance is gone + qDeleteAll(m_series); +} + +//![4] +void ChartView::handleTimeout() +{ + if (m_series.size() == 0) + return; + if (m_index >= 0) + m_chart->removeSeries(m_series.at(m_index)); + m_index++; + m_index = m_index % m_series.size(); + m_chart->addSeries(m_series.at(m_index)); + m_chart->setTitle(m_titles.at(m_index)); + m_chart->createDefaultAxes(); +} +//![4] diff --git a/tests/manual/presenterchart/chartview.h b/tests/manual/presenterchart/chartview.h new file mode 100644 index 00000000..99d8c65a --- /dev/null +++ b/tests/manual/presenterchart/chartview.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 CHARTVIEW_H +#define CHARTVIEW_H + +#include <QtCharts/QChartView> +#include <QtCore/QTimer> + +QT_CHARTS_USE_NAMESPACE + +//![1] +class ChartView: public QChartView +{ + Q_OBJECT +public: + ChartView(QChart *chart, QWidget *parent = 0); + virtual ~ChartView(); + +public slots: + void handleTimeout(); + +private: + QTimer m_timer; + QList<QAbstractSeries *> m_series; + QStringList m_titles; + int m_index; + QChart *m_chart; +}; +//![1] + +#endif /* CHARTVIEW_H */ diff --git a/tests/manual/presenterchart/main.cpp b/tests/manual/presenterchart/main.cpp new file mode 100644 index 00000000..22a45025 --- /dev/null +++ b/tests/manual/presenterchart/main.cpp @@ -0,0 +1,37 @@ +/**************************************************************************** +** +** 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 <QtWidgets/QApplication> +#include <QtWidgets/QMainWindow> + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + QMainWindow window; + QChart *chart = new QChart(); + ChartView chartView(chart, &window); + chartView.setRenderHint(QPainter::Antialiasing); + chart->setAnimationOptions(QChart::SeriesAnimations); + window.setCentralWidget(&chartView); + window.resize(400, 300); + window.show(); + return a.exec(); +} diff --git a/tests/manual/presenterchart/presenterchart.pro b/tests/manual/presenterchart/presenterchart.pro new file mode 100644 index 00000000..0269c6e7 --- /dev/null +++ b/tests/manual/presenterchart/presenterchart.pro @@ -0,0 +1,9 @@ +!include( ../../tests.pri ) { + error( "Couldn't find the test.pri file!" ) +} + +TARGET = presenterchart +HEADERS += chartview.h +SOURCES += main.cpp chartview.cpp + +QT += widgets diff --git a/tests/manual/qmlchartaxis/main.cpp b/tests/manual/qmlchartaxis/main.cpp new file mode 100644 index 00000000..5c5923c7 --- /dev/null +++ b/tests/manual/qmlchartaxis/main.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 <QtWidgets/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.setSource(QUrl("qrc:/qml/qmlchartaxis/main.qml")); + viewer.show(); + + return app.exec(); +} diff --git a/tests/manual/qmlchartaxis/qml/qmlchartaxis/Button.qml b/tests/manual/qmlchartaxis/qml/qmlchartaxis/Button.qml new file mode 100644 index 00000000..61df081d --- /dev/null +++ b/tests/manual/qmlchartaxis/qml/qmlchartaxis/Button.qml @@ -0,0 +1,70 @@ +/**************************************************************************** +** +** 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 { + id: button + height: 25 + width: 140 + color: unpressedColor + radius: 5 + property color unpressedColor: "#afafaf" + + property string text: "button" + signal clicked + + Text { + id: buttonText + anchors.centerIn: parent + text: button.text + } + + MouseArea { + anchors.fill: parent + onClicked: { + button.clicked(); + } + onPressedChanged: { + if (pressed) { + button.color = "#efefef"; + } else { + button.color = unpressedColor; + } + } + onPressAndHold: { + repeatTimer.start(); + } + onReleased: { + repeatTimer.stop(); + } + } + + Timer { + id: repeatTimer + interval: 140 + repeat: true + triggeredOnStart: false + running: false + onTriggered: { + button.clicked(); + } + } +} diff --git a/tests/manual/qmlchartaxis/qml/qmlchartaxis/ChartAxes.qml b/tests/manual/qmlchartaxis/qml/qmlchartaxis/ChartAxes.qml new file mode 100644 index 00000000..69250a39 --- /dev/null +++ b/tests/manual/qmlchartaxis/qml/qmlchartaxis/ChartAxes.qml @@ -0,0 +1,75 @@ +/**************************************************************************** +** +** 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: "chart axes" + + // TODO: Do we need a property for orientation or properties "axisX" and "axisY" on ChartView + // to make an axis the default axis for all series with no other axes defined...? +// ValueAxis { +// orientation: ValueAxis.AxisX +// min: 0 +// max: 10 +// } +// axisX: ValueAxis { +// min: 0 +// max: 10 +// } + // ...Now that we don't have this implementation, the following axes won't have any affect: + ValueAxis { + min: 0 + max: 10 + } + ValueAxis { + min: 0 + max: 5 + } + + LineSeries { + name: "line series" + XYPoint { x: 0; y: 0 } + XYPoint { x: 1; y: 1 } + XYPoint { x: 2; y: 2 } + XYPoint { x: 3; y: 3 } + XYPoint { x: 4; y: 4 } + } + + ScatterSeries { + name: "scatter series" + XYPoint { x: 0; y: 0 } + XYPoint { x: 0.5; y: 1 } + XYPoint { x: 1; y: 2 } + XYPoint { x: 1.5; y: 3 } + XYPoint { x: 2; y: 4 } + XYPoint { x: 1; y: 1 } + XYPoint { x: 2; y: 2 } + XYPoint { x: 3; y: 3 } + XYPoint { x: 4; y: 4 } + } + +// Component.onCompleted: { +// // You can also set the axes dynamically +// chartView.setAxisX(axisX, scatter); +// } +} diff --git a/tests/manual/qmlchartaxis/qml/qmlchartaxis/ChartAxesRevert.qml b/tests/manual/qmlchartaxis/qml/qmlchartaxis/ChartAxesRevert.qml new file mode 100644 index 00000000..524e3314 --- /dev/null +++ b/tests/manual/qmlchartaxis/qml/qmlchartaxis/ChartAxesRevert.qml @@ -0,0 +1,58 @@ +/**************************************************************************** +** +** 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: "chart axes reverted" + + ValueAxis { + min: 0 + max: 10 + } + ValueAxis { + min: 0 + max: 5 + } + + ScatterSeries { + name: "scatter series" + XYPoint { x: 0; y: 0 } + XYPoint { x: 0.5; y: 1 } + XYPoint { x: 1; y: 2 } + XYPoint { x: 1.5; y: 3 } + XYPoint { x: 2; y: 4 } + XYPoint { x: 1; y: 1 } + XYPoint { x: 2; y: 2 } + XYPoint { x: 3; y: 3 } + XYPoint { x: 4; y: 4 } + } + + LineSeries { + name: "line series" + XYPoint { x: 0; y: 0 } + XYPoint { x: 1; y: 1 } + XYPoint { x: 2; y: 2 } + XYPoint { x: 3; y: 3 } + XYPoint { x: 4; y: 4 } + } +} diff --git a/tests/manual/qmlchartaxis/qml/qmlchartaxis/ConfiguringDynamically.qml b/tests/manual/qmlchartaxis/qml/qmlchartaxis/ConfiguringDynamically.qml new file mode 100644 index 00000000..9e24b47b --- /dev/null +++ b/tests/manual/qmlchartaxis/qml/qmlchartaxis/ConfiguringDynamically.qml @@ -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$ +** +****************************************************************************/ + +import QtQuick 2.0 +import QtCharts 2.0 + +ChartView { + title: "configuring dynamically" + id: chartView + property int index: 0 + + Timer { + interval: 1000 + repeat: true + running: true + onTriggered: { + switch (index) { + case 0: + lineSeries.axisX.max = 6; + lineSeries.axisY.max = 6; + break; + case 1: + scatterSeries.axisX.max = 10; + scatterSeries.axisY.max = 10; + break; + default: + chartView.axisX().max = 4; + chartView.axisY().max = 4; + } + index = (index + 1) % 3; + } + } + + LineSeries { + id: lineSeries + name: "line series" + XYPoint { x: 0; y: 0 } + XYPoint { x: 1; y: 1 } + XYPoint { x: 2; y: 2 } + XYPoint { x: 3; y: 3 } + XYPoint { x: 4; y: 4 } + } + + ScatterSeries { + id: scatterSeries + name: "scatter series" + XYPoint { x: 0; y: 0 } + XYPoint { x: 0.5; y: 1 } + XYPoint { x: 1; y: 2 } + XYPoint { x: 1.5; y: 3 } + XYPoint { x: 2; y: 4 } + XYPoint { x: 1; y: 1 } + XYPoint { x: 2; y: 2 } + XYPoint { x: 3; y: 3 } + XYPoint { x: 4; y: 4 } + } +} diff --git a/tests/manual/qmlchartaxis/qml/qmlchartaxis/CreatingDynamically.qml b/tests/manual/qmlchartaxis/qml/qmlchartaxis/CreatingDynamically.qml new file mode 100644 index 00000000..209ef372 --- /dev/null +++ b/tests/manual/qmlchartaxis/qml/qmlchartaxis/CreatingDynamically.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 + +ChartView { + id: chartView + title: "creating dyn. new series" + property int index: 0 + + Timer { + interval: 1000 + repeat: true + running: true + onTriggered: { + switch (index) { + case 0: + var count = chartView.count; + var line = chartView.createSeries(ChartView.SeriesTypeLine, "line"); + line.append(0, 0); + line.append(1, 1); + line.append(2, 2); + line.append(3, 3); + line.append(4, 4); + break; + case 1: + chartView.axisX().min = 0; + chartView.axisX().max = 4.5; + chartView.axisY().min = 0; + chartView.axisY().max = 4.5; + break; + case 2: + var scatter = chartView.createSeries(ChartView.SeriesTypeScatter, "scatter"); + scatter.append(0, 0); + scatter.append(0.5, 1); + scatter.append(1, 2); + scatter.append(1.5, 3); + scatter.append(2, 4); + scatter.append(1, 1); + scatter.append(2, 2); + scatter.append(3, 3); + scatter.append(4, 4); + break; + default: + chartView.removeAllSeries(); + } + index = (index + 1) % 4; + } + } +} diff --git a/tests/manual/qmlchartaxis/qml/qmlchartaxis/DefaultAndUserDefined.qml b/tests/manual/qmlchartaxis/qml/qmlchartaxis/DefaultAndUserDefined.qml new file mode 100644 index 00000000..2cab44fd --- /dev/null +++ b/tests/manual/qmlchartaxis/qml/qmlchartaxis/DefaultAndUserDefined.qml @@ -0,0 +1,71 @@ +/**************************************************************************** +** +** 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 { + title: "default + user defined" + + ValueAxis { + id: axisX + min: 0 + max: 6 + } + + ValueAxis { + id: axisY + min: 0 + max: 6 + } + + LineSeries { + name: "line series 1" + XYPoint { x: 0; y: 0 } + XYPoint { x: 1; y: 1 } + XYPoint { x: 2; y: 2 } + XYPoint { x: 3; y: 3 } + XYPoint { x: 4; y: 4 } + } + + ScatterSeries { + name: "scatter series" + axisX: axisX + axisY: axisY + XYPoint { x: 0; y: 0 } + XYPoint { x: 0.5; y: 1 } + XYPoint { x: 1; y: 2 } + XYPoint { x: 1.5; y: 3 } + XYPoint { x: 2; y: 4 } + XYPoint { x: 1; y: 1 } + XYPoint { x: 2; y: 2 } + XYPoint { x: 3; y: 3 } + XYPoint { x: 4; y: 4 } + } + + LineSeries { + name: "line series 2" + XYPoint { x: 0; y: 0 } + XYPoint { x: 0.5; y: 1 } + XYPoint { x: 1; y: 2 } + XYPoint { x: 1.5; y: 3 } + XYPoint { x: 2; y: 4 } + } +} diff --git a/tests/manual/qmlchartaxis/qml/qmlchartaxis/DefaultAxes.qml b/tests/manual/qmlchartaxis/qml/qmlchartaxis/DefaultAxes.qml new file mode 100644 index 00000000..f06dd7cf --- /dev/null +++ b/tests/manual/qmlchartaxis/qml/qmlchartaxis/DefaultAxes.qml @@ -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$ +** +****************************************************************************/ + +import QtQuick 2.0 +import QtCharts 2.0 + +ChartView { + id: chartView + title: "default axes" + + LineSeries { + name: "line series" + XYPoint { x: 0; y: 0 } + XYPoint { x: 1; y: 1 } + XYPoint { x: 2; y: 2 } + XYPoint { x: 3; y: 3 } + XYPoint { x: 4; y: 4 } + } + + ScatterSeries { + name: "scatter series" + XYPoint { x: 0; y: 0 } + XYPoint { x: 0.5; y: 1 } + XYPoint { x: 1; y: 2 } + XYPoint { x: 1.5; y: 3 } + XYPoint { x: 2; y: 4 } + XYPoint { x: 1; y: 1 } + XYPoint { x: 2; y: 2 } + XYPoint { x: 3; y: 3 } + XYPoint { x: 4; y: 4 } + } +} diff --git a/tests/manual/qmlchartaxis/qml/qmlchartaxis/DefaultAxesRevert.qml b/tests/manual/qmlchartaxis/qml/qmlchartaxis/DefaultAxesRevert.qml new file mode 100644 index 00000000..67685082 --- /dev/null +++ b/tests/manual/qmlchartaxis/qml/qmlchartaxis/DefaultAxesRevert.qml @@ -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$ +** +****************************************************************************/ + +import QtQuick 2.0 +import QtCharts 2.0 + +ChartView { + id: chartView + title: "default axes" + + ScatterSeries { + name: "scatter series" + XYPoint { x: 0; y: 0 } + XYPoint { x: 0.5; y: 1 } + XYPoint { x: 1; y: 2 } + XYPoint { x: 1.5; y: 3 } + XYPoint { x: 2; y: 4 } + XYPoint { x: 1; y: 1 } + XYPoint { x: 2; y: 2 } + XYPoint { x: 3; y: 3 } + XYPoint { x: 4; y: 4 } + } + + LineSeries { + name: "line series" + XYPoint { x: 0; y: 0 } + XYPoint { x: 1; y: 1 } + XYPoint { x: 2; y: 2 } + XYPoint { x: 3; y: 3 } + XYPoint { x: 4; y: 4 } + } +} diff --git a/tests/manual/qmlchartaxis/qml/qmlchartaxis/Legacy.qml b/tests/manual/qmlchartaxis/qml/qmlchartaxis/Legacy.qml new file mode 100644 index 00000000..caafabb7 --- /dev/null +++ b/tests/manual/qmlchartaxis/qml/qmlchartaxis/Legacy.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 + +ChartView { + id: chartView + title: "Deprecated code" + property int index: 0 + + Component.onCompleted: { + // Calling createDefaultAxes in onCompleted is now deprecated. It needs to be tested, + // though, because some application may still use it + chartView.createDefaultAxes(); + } + + LineSeries { + name: "line series" + XYPoint { x: 0; y: 0 } + XYPoint { x: 1; y: 1 } + XYPoint { x: 2; y: 2 } + XYPoint { x: 3; y: 3 } + XYPoint { x: 4; y: 4 } + } + + ScatterSeries { + name: "scatter series" + XYPoint { x: 0; y: 0 } + XYPoint { x: 0.5; y: 1 } + XYPoint { x: 1; y: 2 } + XYPoint { x: 1.5; y: 3 } + XYPoint { x: 2; y: 4 } + XYPoint { x: 1; y: 1 } + XYPoint { x: 2; y: 2 } + XYPoint { x: 3; y: 3 } + XYPoint { x: 4; y: 4 } + } +} diff --git a/tests/manual/qmlchartaxis/qml/qmlchartaxis/SeriesSpecificDynamic.qml b/tests/manual/qmlchartaxis/qml/qmlchartaxis/SeriesSpecificDynamic.qml new file mode 100644 index 00000000..c9ac5d92 --- /dev/null +++ b/tests/manual/qmlchartaxis/qml/qmlchartaxis/SeriesSpecificDynamic.qml @@ -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$ +** +****************************************************************************/ + +import QtQuick 2.0 +import QtCharts 2.0 + +ChartView { + title: "series specific dynamic axes" + id: chartView + property int index: 0 + + Timer { + interval: 1000 + repeat: true + running: true + onTriggered: { + switch (index) { + case 0: + lineAxisX.max = 6; + lineAxisY.max = 6; + scatterAxisX.max = 10; + scatterAxisY.max = 10; + break; + case 1: + lineAxisX.max = 10; + lineAxisY.max = 10; + scatterAxisX.max = 6; + scatterAxisY.max = 6; + break; + default: + chartView.axisX().max = 4; + chartView.axisY().max = 4; + } + index = (index + 1) % 3; + } + } + + LineSeries { + id: lineSeries + name: "line series" + axisX: ValueAxis { id: lineAxisX } + axisY: ValueAxis { id: lineAxisY } + XYPoint { x: 0; y: 0 } + XYPoint { x: 1; y: 1 } + XYPoint { x: 2; y: 2 } + XYPoint { x: 3; y: 3 } + XYPoint { x: 4; y: 4 } + } + + ScatterSeries { + id: scatterSeries + name: "scatter series" + axisX: ValueAxis { id: scatterAxisX } + axisY: ValueAxis { id: scatterAxisY } + XYPoint { x: 0; y: 0 } + XYPoint { x: 0.5; y: 1 } + XYPoint { x: 1; y: 2 } + XYPoint { x: 1.5; y: 3 } + XYPoint { x: 2; y: 4 } + XYPoint { x: 1; y: 1 } + XYPoint { x: 2; y: 2 } + XYPoint { x: 3; y: 3 } + XYPoint { x: 4; y: 4 } + } +} diff --git a/tests/manual/qmlchartaxis/qml/qmlchartaxis/SwitchingDynamically.qml b/tests/manual/qmlchartaxis/qml/qmlchartaxis/SwitchingDynamically.qml new file mode 100644 index 00000000..db11c9ee --- /dev/null +++ b/tests/manual/qmlchartaxis/qml/qmlchartaxis/SwitchingDynamically.qml @@ -0,0 +1,71 @@ +/**************************************************************************** +** +** 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: "switching axes dynamically" + + Timer { + interval: 1000 + repeat: true + running: true + onTriggered: { + //console.log("current axisX: " + lineSeries.axisX + " 1: " + valueAxis1 + " 2: " +valueAxis2); + + // Note: an axis is destroyed if it is not used anymore + if (lineSeries.axisX == valueAxis1) + lineSeries.axisX = valueAxis2; + else if (lineSeries.axisX == valueAxis2) + lineSeries.axisX = valueAxis3; + } + } + + ValueAxis { + id: valueAxis1 + min: 0 + max: 5 + } + + ValueAxis { + id: valueAxis2 + min: 1 + max: 6 + } + + ValueAxis { + id: valueAxis3 + min: 2 + max: 7 + } + + LineSeries { + id: lineSeries + name: "line series" + axisX: valueAxis1 + XYPoint { x: 0; y: 0 } + XYPoint { x: 1; y: 1 } + XYPoint { x: 2; y: 2 } + XYPoint { x: 3; y: 3 } + XYPoint { x: 4; y: 4 } + } +} diff --git a/tests/manual/qmlchartaxis/qml/qmlchartaxis/UserDefined.qml b/tests/manual/qmlchartaxis/qml/qmlchartaxis/UserDefined.qml new file mode 100644 index 00000000..f87c18cb --- /dev/null +++ b/tests/manual/qmlchartaxis/qml/qmlchartaxis/UserDefined.qml @@ -0,0 +1,64 @@ +/**************************************************************************** +** +** 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 { + title: "user defined" + + ValueAxis { + id: axisX + min: 0 + max: 6 + } + + ValueAxis { + id: axisY + min: 0 + max: 6 + } + + LineSeries { + name: "line series" + axisX: axisX + axisY: axisY + XYPoint { x: 0; y: 0 } + XYPoint { x: 1; y: 1 } + XYPoint { x: 2; y: 2 } + XYPoint { x: 3; y: 3 } + XYPoint { x: 4; y: 4 } + } + + ScatterSeries { + name: "scatter series" + axisX: axisX + axisY: axisY + XYPoint { x: 0; y: 0 } + XYPoint { x: 0.5; y: 1 } + XYPoint { x: 1; y: 2 } + XYPoint { x: 1.5; y: 3 } + XYPoint { x: 2; y: 4 } + XYPoint { x: 1; y: 1 } + XYPoint { x: 2; y: 2 } + XYPoint { x: 3; y: 3 } + XYPoint { x: 4; y: 4 } + } +} diff --git a/tests/manual/qmlchartaxis/qml/qmlchartaxis/UserDefinedRevert.qml b/tests/manual/qmlchartaxis/qml/qmlchartaxis/UserDefinedRevert.qml new file mode 100644 index 00000000..ea625c22 --- /dev/null +++ b/tests/manual/qmlchartaxis/qml/qmlchartaxis/UserDefinedRevert.qml @@ -0,0 +1,64 @@ +/**************************************************************************** +** +** 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 { + title: "user defined reverted" + + ValueAxis { + id: axisX + min: 0 + max: 6 + } + + ValueAxis { + id: axisY + min: 0 + max: 6 + } + + ScatterSeries { + name: "scatter series" + axisX: axisX + axisY: axisY + XYPoint { x: 0; y: 0 } + XYPoint { x: 0.5; y: 1 } + XYPoint { x: 1; y: 2 } + XYPoint { x: 1.5; y: 3 } + XYPoint { x: 2; y: 4 } + XYPoint { x: 1; y: 1 } + XYPoint { x: 2; y: 2 } + XYPoint { x: 3; y: 3 } + XYPoint { x: 4; y: 4 } + } + + LineSeries { + name: "line series" + axisX: axisX + axisY: axisY + XYPoint { x: 0; y: 0 } + XYPoint { x: 1; y: 1 } + XYPoint { x: 2; y: 2 } + XYPoint { x: 3; y: 3 } + XYPoint { x: 4; y: 4 } + } +} diff --git a/tests/manual/qmlchartaxis/qml/qmlchartaxis/main.qml b/tests/manual/qmlchartaxis/qml/qmlchartaxis/main.qml new file mode 100644 index 00000000..f973bf7a --- /dev/null +++ b/tests/manual/qmlchartaxis/qml/qmlchartaxis/main.qml @@ -0,0 +1,96 @@ +/**************************************************************************** +** +** 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 { + id: main + width: 500 + height: 400 + property string viewName: "DefaultAxes" + + Row { + anchors.fill: parent + anchors.topMargin: 10 + + Loader { + id: chartLoader + width: parent.width - buttonColumn.width + height: parent.height + source: viewName + ".qml" + } + + Column { + id: buttonColumn + width: 150 + height: parent.height + spacing: 5 + + Button { + text: "Default axes" + onClicked: viewName = "DefaultAxes"; + } + Button { + text: "Default axes reverted" + onClicked: viewName = "DefaultAxesRevert"; + } + Button { + text: "User defined" + onClicked: viewName = "UserDefined"; + } + Button { + text: "User defined reverted" + onClicked: viewName = "UserDefinedRevert"; + } + Button { + text: "Chart axes" + onClicked: viewName = "ChartAxes"; + } + Button { + text: "Chart axes reverted" + onClicked: viewName = "ChartAxesRevert"; + } + Button { + text: "Configuring dynamically" + onClicked: viewName = "ConfiguringDynamically"; + } + Button { + text: "Series specific dynamic" + onClicked: viewName = "SeriesSpecificDynamic"; + } + Button { + text: "Creating dynamically" + onClicked: viewName = "CreatingDynamically"; + } + Button { + text: "Switching dynamically" + onClicked: viewName = "SwitchingDynamically"; + } + Button { + text: "Default + User defined" + onClicked: viewName = "DefaultAndUserDefined"; + } + Button { + text: "Legacy" + onClicked: viewName = "Legacy"; + } + } + } +} diff --git a/tests/manual/qmlchartaxis/qmlchartaxis.pro b/tests/manual/qmlchartaxis/qmlchartaxis.pro new file mode 100644 index 00000000..aaf2a7a0 --- /dev/null +++ b/tests/manual/qmlchartaxis/qmlchartaxis.pro @@ -0,0 +1,8 @@ +!include( ../../tests.pri ) { + error( "Couldn't find the test.pri file!" ) +} + +RESOURCES += resources.qrc +SOURCES += main.cpp +OTHER_FILES += qml/qmlchartaxis/* + diff --git a/tests/manual/qmlchartaxis/resources.qrc b/tests/manual/qmlchartaxis/resources.qrc new file mode 100644 index 00000000..2f9f4b67 --- /dev/null +++ b/tests/manual/qmlchartaxis/resources.qrc @@ -0,0 +1,18 @@ +<RCC> + <qresource prefix="/"> + <file>qml/qmlchartaxis/main.qml</file> + <file>qml/qmlchartaxis/Button.qml</file> + <file>qml/qmlchartaxis/DefaultAxes.qml</file> + <file>qml/qmlchartaxis/DefaultAxesRevert.qml</file> + <file>qml/qmlchartaxis/UserDefined.qml</file> + <file>qml/qmlchartaxis/UserDefinedRevert.qml</file> + <file>qml/qmlchartaxis/ChartAxes.qml</file> + <file>qml/qmlchartaxis/ChartAxesRevert.qml</file> + <file>qml/qmlchartaxis/ConfiguringDynamically.qml</file> + <file>qml/qmlchartaxis/SeriesSpecificDynamic.qml</file> + <file>qml/qmlchartaxis/CreatingDynamically.qml</file> + <file>qml/qmlchartaxis/SwitchingDynamically.qml</file> + <file>qml/qmlchartaxis/DefaultAndUserDefined.qml</file> + <file>qml/qmlchartaxis/Legacy.qml</file> + </qresource> +</RCC> diff --git a/tests/manual/qmlchartproperties/main.cpp b/tests/manual/qmlchartproperties/main.cpp new file mode 100644 index 00000000..752724be --- /dev/null +++ b/tests/manual/qmlchartproperties/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 <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.setSource(QUrl("qrc:/qml/qmlchartproperties/main.qml")); + viewer.setResizeMode(QQuickView::SizeRootObjectToView); + viewer.show(); + + return app.exec(); +} diff --git a/tests/manual/qmlchartproperties/qml/qmlchartproperties/AreaChart.qml b/tests/manual/qmlchartproperties/qml/qmlchartproperties/AreaChart.qml new file mode 100644 index 00000000..069e17de --- /dev/null +++ b/tests/manual/qmlchartproperties/qml/qmlchartproperties/AreaChart.qml @@ -0,0 +1,111 @@ +/**************************************************************************** +** +** 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 { + title: "area series" + anchors.fill: parent + animationOptions: ChartView.SeriesAnimations + + property variant series: areaSeries + + AreaSeries { + id: areaSeries + name: "area 1" + + upperSeries: LineSeries { + XYPoint { x: 0; y: 1 } + XYPoint { x: 1; y: 1 } + XYPoint { x: 2; y: 3 } + XYPoint { x: 3; y: 3 } + XYPoint { x: 4; y: 2 } + XYPoint { x: 5; y: 0 } + XYPoint { x: 6; y: 2 } + XYPoint { x: 7; y: 1 } + XYPoint { x: 8; y: 2 } + XYPoint { x: 9; y: 1 } + XYPoint { x: 10; y: 3 } + XYPoint { x: 11; y: 3 } + } + lowerSeries: LineSeries { + XYPoint { x: 0; y: 0 } + XYPoint { x: 1; y: 0 } + XYPoint { x: 2; y: 0 } + XYPoint { x: 3; y: 0 } + XYPoint { x: 4; y: 0 } + XYPoint { x: 5; y: 0 } + XYPoint { x: 6; y: 0 } + XYPoint { x: 7; y: 0 } + XYPoint { x: 8; y: 0 } + XYPoint { x: 9; y: 0 } + XYPoint { x: 10; y: 0 } + XYPoint { x: 11; y: 0 } + } + + pointLabelsFormat: "@xPoint, @yPoint"; + + onNameChanged: console.log(name + ".onNameChanged: " + name); + onVisibleChanged: console.log(name + ".onVisibleChanged: " + visible); + onOpacityChanged: console.log(name + ".onOpacityChanged: " + opacity); + onClicked: console.log(name + ".onClicked: " + point.x + ", " + point.y); + onSelected: console.log(name + ".onSelected"); + onColorChanged: console.log(name + ".onColorChanged: " + color); + onBorderColorChanged: console.log(name + ".onBorderColorChanged: " + borderColor); + onBorderWidthChanged: console.log(name + ".onBorderChanged: " + borderWidth); +// onCountChanged: console.log(name + ".onCountChanged: " + count); + onHovered: console.log("lineSeries.onHovered:" + point.x + "," + point.y + " " + state); + onPointLabelsVisibilityChanged: console.log(name + ".onPointLabelsVisibilityChanged: " + + visible); + onPointLabelsFormatChanged: console.log(name + ".onPointLabelsFormatChanged: " + + format); + onPointLabelsFontChanged: console.log(name + ".onPointLabelsFontChanged: " + + font.family); + onPointLabelsColorChanged: console.log(name + ".onPointLabelsColorChanged: " + + color); + } + + AreaSeries { + name: "area 2" + + upperSeries: LineSeries { + XYPoint { x: 0; y: 0.5 } + XYPoint { x: 1; y: 1.5 } + XYPoint { x: 2; y: 0.3 } + XYPoint { x: 3; y: 1.5 } + XYPoint { x: 4; y: 0.1 } + XYPoint { x: 5; y: 0.3 } + XYPoint { x: 6; y: 1.2 } + XYPoint { x: 7; y: 1.3 } + XYPoint { x: 8; y: 0.2 } + XYPoint { x: 9; y: 0.1 } + XYPoint { x: 10; y: 3.2 } + XYPoint { x: 11; y: 4.6 } + } + + onNameChanged: console.log(name + ".onNameChanged: " + name); + onVisibleChanged: console.log(name + ".onVisibleChanged: " + visible); + onClicked: console.log(name + ".onClicked: " + point.x + ", " + point.y); + onSelected: console.log(name + ".onSelected"); + onColorChanged: console.log(name + ".onColorChanged: " + color); + onBorderColorChanged: console.log(name + ".onBorderColorChanged: " + borderColor); + } +} diff --git a/tests/manual/qmlchartproperties/qml/qmlchartproperties/AreaEditor.qml b/tests/manual/qmlchartproperties/qml/qmlchartproperties/AreaEditor.qml new file mode 100644 index 00000000..168dc957 --- /dev/null +++ b/tests/manual/qmlchartproperties/qml/qmlchartproperties/AreaEditor.qml @@ -0,0 +1,111 @@ +/**************************************************************************** +** +** 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 + +Flow { + id: flow + spacing: 5 + flow: Flow.TopToBottom + property variant series + + Button { + text: "visible" + onClicked: series.visible = !series.visible; + } + Button { + text: "opacity +" + onClicked: series.opacity += 0.1; + } + Button { + text: "opacity -" + onClicked: series.opacity -= 0.1; + } + Button { + text: "color" + onClicked: series.color = main.nextColor(); + } + Button { + text: "borderColor" + onClicked: series.borderColor = main.nextColor(); + } + Button { + text: series != undefined ? "borderWidth + (" + series.borderWidth + ")" : "" + onClicked: series.borderWidth += 0.5; + } + Button { + text: series != undefined ? "borderWidth - (" + series.borderWidth + ")" : "" + onClicked: series.borderWidth -= 0.5; + } + Button { + text: "point labels visible" + onClicked: series.pointLabelsVisible = !series.pointLabelsVisible; + } + Button { + text: "point labels format" + onClicked: { + if (series.pointLabelsFormat === "@xPoint, @yPoint") + series.pointLabelsFormat = "(@xPoint)" + else + series.pointLabelsFormat = "@xPoint, @yPoint" + } + } + Button { + text: "point labels font" + onClicked: { + if (series.pointLabelsFont.family === "Times") + series.pointLabelsFont.family = "Courier"; + else + series.pointLabelsFont.family = "Times"; + } + } + Button { + text: "point labels color" + onClicked: series.pointLabelsColor = main.nextColor(); + } + Button { + id: upperButton + text: "upper series" + unpressedColor: "#79bd8f" + onClicked: { + lineEditor.visible = true; + color = "#00a388"; + lowerButton.color = "#79bd8f"; + lineEditor.series = series.upperSeries; + } + } + Button { + id: lowerButton + text: "lower series" + unpressedColor: "#79bd8f" + onClicked: { + lineEditor.visible = true; + color = "#00a388"; + upperButton.color = "#79bd8f"; + lineEditor.series = series.lowerSeries; + } + } + LineEditor { + id: lineEditor + visible: false + } + + onSeriesChanged: lineEditor.series = series.upperSeries; +} diff --git a/tests/manual/qmlchartproperties/qml/qmlchartproperties/BarChart.qml b/tests/manual/qmlchartproperties/qml/qmlchartproperties/BarChart.qml new file mode 100644 index 00000000..ad088646 --- /dev/null +++ b/tests/manual/qmlchartproperties/qml/qmlchartproperties/BarChart.qml @@ -0,0 +1,76 @@ +/**************************************************************************** +** +** 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 { + title: "Bar series" + anchors.fill: parent + theme: ChartView.ChartThemeLight + legend.alignment: Qt.AlignBottom + animationOptions: ChartView.SeriesAnimations + + property variant series: mySeries + + + BarSeries { + id: mySeries + name: "bar" + labelsFormat: "@value"; + axisX: BarCategoryAxis { categories: ["2007", "2008", "2009", "2010", "2011", "2012" ] } + BarSet { label: "Bob"; values: [2, 2, 3, 4, 5, 6] + onClicked: console.log("barset.onClicked: " + index); + onHovered: console.log("barset.onHovered: " + status + " " + index); + onPenChanged: console.log("barset.onPenChanged: " + pen); + onBrushChanged: console.log("barset.onBrushChanged: " + brush); + onLabelChanged: console.log("barset.onLabelChanged: " + label); + onLabelBrushChanged: console.log("barset.onLabelBrushChanged: " + labelBrush); + onLabelFontChanged: console.log("barset.onLabelFontChanged: " + labelFont); + onColorChanged: console.log("barset.onColorChanged: " + color); + onBorderColorChanged: console.log("barset.onBorderColorChanged: " + color); + onLabelColorChanged: console.log("barset.onLabelColorChanged: " + color); + onCountChanged: console.log("barset.onCountChanged: " + count); + onValuesAdded: console.log("barset.onValuesAdded: " + index + ", " + count); + onValuesRemoved: console.log("barset.onValuesRemoved: " + index + ", " + count); + onValueChanged: console.log("barset.onValuesChanged: " + index); + } + BarSet { label: "Susan"; values: [5, 1, 2, 4, 1, 7] } + BarSet { label: "James"; values: [3, 5, 8, 13, 5, 8] } + + onNameChanged: console.log("barSeries.onNameChanged: " + series.name); + onVisibleChanged: console.log("barSeries.onVisibleChanged: " + series.visible); + onOpacityChanged: console.log("barSeries.onOpacityChanged: " + opacity); + onClicked: console.log("barSeries.onClicked: " + barset + " " + index); + onHovered: console.log("barSeries.onHovered: " + barset + " " + status + + " " + index); + onLabelsVisibleChanged: console.log("barSeries.onLabelsVisibleChanged: " + series.labelsVisible); + onCountChanged: console.log("barSeries.onCountChanged: " + count); + onLabelsFormatChanged: console.log("barSeries.onLabelsFormatChanged: " + format); + onLabelsPositionChanged: console.log("barSeries.onLabelsPositionChanged: " + series.labelsPosition); + + function changeLabelsPosition() { + if (labelsPosition === BarSeries.LabelsCenter) + labelsPosition = BarSeries.LabelsInsideEnd; + else + labelsPosition = BarSeries.LabelsCenter; + } + } +} diff --git a/tests/manual/qmlchartproperties/qml/qmlchartproperties/BarEditor.qml b/tests/manual/qmlchartproperties/qml/qmlchartproperties/BarEditor.qml new file mode 100644 index 00000000..cdd847a5 --- /dev/null +++ b/tests/manual/qmlchartproperties/qml/qmlchartproperties/BarEditor.qml @@ -0,0 +1,199 @@ +/**************************************************************************** +** +** 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 + +Row { + anchors.fill: parent + spacing: 5 + property variant series + + // buttons for selecting the edited object: series, barset or label + Flow { + spacing: 5 + flow: Flow.TopToBottom + Button { + id: seriesButton + text: "series" + unpressedColor: "#79bd8f" + onClicked: { + seriesFlow.visible = true; + setFlow.visible = false; + labelsFlow.visible = false; + color = "#00a388"; + setButton.color = "#79bd8f"; + labelButton.color = "#79bd8f"; + } + } + Button { + id: setButton + text: "BarSet" + unpressedColor: "#79bd8f" + onClicked: { + seriesFlow.visible = false; + setFlow.visible = true; + labelsFlow.visible = false; + color = "#00a388"; + seriesButton.color = "#79bd8f"; + labelButton.color = "#79bd8f"; + } + } + Button { + id: labelButton + text: "label" + unpressedColor: "#79bd8f" + onClicked: { + seriesFlow.visible = false; + setFlow.visible = false; + labelsFlow.visible = true; + color = "#00a388"; + seriesButton.color = "#79bd8f"; + setButton.color = "#79bd8f"; + } + } + } + + // Buttons for editing series + Flow { + id: seriesFlow + spacing: 5 + flow: Flow.TopToBottom + visible: false + + Button { + text: "visible" + onClicked: series.visible = !series.visible; + } + Button { + text: "opacity +" + onClicked: series.opacity += 0.1; + } + Button { + text: "opacity -" + onClicked: series.opacity -= 0.1; + } + Button { + text: "bar width +" + onClicked: series.barWidth += 0.1; + } + Button { + text: "bar width -" + onClicked: series.barWidth -= 0.1; + } + } + + // Buttons for editing sets + Flow { + id: setFlow + spacing: 5 + flow: Flow.TopToBottom + visible: false + + Button { + text: "append set" + onClicked: { + var count = series.count; + series.append("set" + count, [0, 0.1 * count, 0.2 * count, 0.3 * count, 0.4 * count, 0.5 * count, 0.6 * count]); + } + } + Button { + text: "insert set" + onClicked: { + var count = series.count; + series.insert(count - 1, "set" + count, [0, 0.1 * count, 0.2 * count, 0.3 * count, 0.4 * count, 0.5 * count, 0.6 * count]); + } + } + Button { + text: "remove set" + onClicked: series.remove(series.at(series.count - 1)); + } + Button { + text: "clear sets" + onClicked: series.clear(); + } + + Button { + text: "set 1 append" + onClicked: series.at(0).append(series.at(0).count + 1); + } + Button { + text: "set 1 replace" + onClicked: series.at(0).replace(series.at(0).count - 1, series.at(0).at(series.at(0).count - 1) + 1.5); + } + Button { + text: "set 1 remove" + onClicked: series.at(0).remove(series.at(0).count - 1); + } + + Button { + text: "set 1 color" + onClicked: series.at(0).color = main.nextColor(); + } + Button { + text: "set 1 border color" + onClicked: series.at(0).borderColor = main.nextColor(); + } + Button { + text: "set 1 borderWidth +" + onClicked: series.at(0).borderWidth += 0.5; + } + Button { + text: "set 1 borderWidth -" + onClicked: series.at(0).borderWidth -= 0.5; + } + } + + + Flow { + id: labelsFlow + spacing: 5 + flow: Flow.TopToBottom + visible: false + + Button { + text: "labels visible" + onClicked: series.labelsVisible = !series.labelsVisible; + } + Button { + text: "labels format" + onClicked: { + if (series.labelsFormat === "@value") + series.labelsFormat = "@value%" + else + series.labelsFormat = "@value" + } + } + Button { + text: "labels position" + onClicked: series.changeLabelsPosition(); + } + Button { + text: "set 1 label color" + onClicked: series.at(0).labelColor = main.nextColor(); + } + FontEditor { + id: fontEditor + fontDescription: "label" + function editedFont() { + return series.at(0).labelFont; + } + } + } +} diff --git a/tests/manual/qmlchartproperties/qml/qmlchartproperties/Button.qml b/tests/manual/qmlchartproperties/qml/qmlchartproperties/Button.qml new file mode 100644 index 00000000..61df081d --- /dev/null +++ b/tests/manual/qmlchartproperties/qml/qmlchartproperties/Button.qml @@ -0,0 +1,70 @@ +/**************************************************************************** +** +** 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 { + id: button + height: 25 + width: 140 + color: unpressedColor + radius: 5 + property color unpressedColor: "#afafaf" + + property string text: "button" + signal clicked + + Text { + id: buttonText + anchors.centerIn: parent + text: button.text + } + + MouseArea { + anchors.fill: parent + onClicked: { + button.clicked(); + } + onPressedChanged: { + if (pressed) { + button.color = "#efefef"; + } else { + button.color = unpressedColor; + } + } + onPressAndHold: { + repeatTimer.start(); + } + onReleased: { + repeatTimer.stop(); + } + } + + Timer { + id: repeatTimer + interval: 140 + repeat: true + triggeredOnStart: false + running: false + onTriggered: { + button.clicked(); + } + } +} diff --git a/tests/manual/qmlchartproperties/qml/qmlchartproperties/Chart.qml b/tests/manual/qmlchartproperties/qml/qmlchartproperties/Chart.qml new file mode 100644 index 00000000..3f30ea44 --- /dev/null +++ b/tests/manual/qmlchartproperties/qml/qmlchartproperties/Chart.qml @@ -0,0 +1,110 @@ +/**************************************************************************** +** +** 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: "Chart Title" + anchors.fill: parent + property variant chart: chartView + + LineSeries { + name: "line" + XYPoint { x: 0; y: 0 } + XYPoint { x: 1.1; y: 2.1 } + XYPoint { x: 1.9; y: 3.3 } + XYPoint { x: 2.1; y: 2.1 } + XYPoint { x: 2.9; y: 4.9 } + XYPoint { x: 3.4; y: 3.0 } + XYPoint { x: 4.1; y: 3.3 } + } + + onVisibleChanged: console.log("chart.onVisibleChanged: " + visible); + onTitleColorChanged: console.log("chart.onTitleColorChanged: " + color); + onBackgroundColorChanged: console.log("chart.onBackgroundColorChanged: " + chart.backgroundColor); + onDropShadowEnabledChanged: console.log("chart.onDropShadowEnabledChanged: " + enabled); + onBackgroundRoundnessChanged: console.log("chart.onBackgroundRoundnessChanged: " + diameter); + onSeriesAdded: console.log("chart.onSeriesAdded: " + series.name); + onSeriesRemoved: console.log("chart.onSeriesRemoved: " + series.name); + onPlotAreaColorChanged: console.log("chart.plotAreaColorChanged: " + chart.plotAreaColor); + + legend.onVisibleChanged: console.log("legend.onVisibleChanged: " + chart.legend.visible); + legend.onBackgroundVisibleChanged: console.log("legend.onBackgroundVisibleChanged: " + visible); + legend.onColorChanged: console.log("legend.onColorChanged: " + color); + legend.onBorderColorChanged: console.log("legend.onBorderColorChanged: " + color); + legend.onLabelColorChanged: console.log("legend.onLabelColorChanged: " + color); + legend.onReverseMarkersChanged: console.log("legend.onReverseMarkersChanged: " + + chart.legend.reverseMarkers) + margins.onTopChanged: console.log("chart.margins.onTopChanged: " + top ); + margins.onBottomChanged: console.log("chart.margins.onBottomChanged: " + bottom); + margins.onLeftChanged: console.log("chart.margins.onLeftChanged: " + left); + margins.onRightChanged: console.log("chart.margins.onRightChanged: " + right); + onPlotAreaChanged: { + console.log("chart.onPlotAreaChanged, width: " + chartView.plotArea.width + + " height: " + chartView.plotArea.height + + " y: " + chartView.plotArea.y + + " x: " + chartView.plotArea.x); + marginVisualizer.opacity = 1.0; + } + + ValueAxis{ + onColorChanged: console.log("axisX.onColorChanged: " + color); + onLabelsVisibleChanged: console.log("axisX.onLabelsVisibleChanged: " + visible); + onLabelsColorChanged: console.log("axisX.onLabelsColorChanged: " + color); + onVisibleChanged: console.log("axisX.onVisibleChanged: " + visible); + onGridVisibleChanged: console.log("axisX.onGridVisibleChanged: " + visible); + onShadesVisibleChanged: console.log("axisX.onShadesVisibleChanged: " + visible); + onShadesColorChanged: console.log("axisX.onShadesColorChanged: " + color); + onShadesBorderColorChanged: console.log("axisX.onShadesBorderColorChanged: " + color); + onMinChanged: console.log("axisX.onMinChanged: " + min); + onMaxChanged: console.log("axisX.onMaxChanged: " + max); + } + + ValueAxis{ + onColorChanged: console.log("axisY.onColorChanged: " + color); + onLabelsVisibleChanged: console.log("axisY.onLabelsVisibleChanged: " + visible); + onLabelsColorChanged: console.log("axisY.onLabelsColorChanged: " + color); + onVisibleChanged: console.log("axisY.onVisibleChanged: " + visible); + onGridVisibleChanged: console.log("axisY.onGridVisibleChanged: " + visible); + onShadesVisibleChanged: console.log("axisY.onShadesVisibleChanged: " + visible); + onShadesColorChanged: console.log("axisY.onShadesColorChanged: " + color); + onShadesBorderColorChanged: console.log("axisY.onShadesBorderColorChanged: " + color); + onMinChanged: console.log("axisY.onMinChanged: " + min); + onMaxChanged: console.log("axisY.onMaxChanged: " + max); + } + + Rectangle { + id: marginVisualizer + color: "transparent" + border.color: "red" + anchors.fill: parent + anchors.topMargin: chartView.minimumMargins.top + anchors.bottomMargin: chartView.minimumMargins.bottom + anchors.leftMargin: chartView.minimumMargins.left + anchors.rightMargin: chartView.minimumMargins.right + opacity: 0.0 + onOpacityChanged: if (opacity > 0.9) opacity = 0.0; + Behavior on opacity { + NumberAnimation { duration: 800 } + } + } +} diff --git a/tests/manual/qmlchartproperties/qml/qmlchartproperties/ChartEditor.qml b/tests/manual/qmlchartproperties/qml/qmlchartproperties/ChartEditor.qml new file mode 100644 index 00000000..87139f35 --- /dev/null +++ b/tests/manual/qmlchartproperties/qml/qmlchartproperties/ChartEditor.qml @@ -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$ +** +****************************************************************************/ + +import QtQuick 2.0 + +Item { + id: chartEditor + property variant chart + onChartChanged: { + if (loader.item != undefined) + loader.item.chart = chart; + } + + function selectButton(button) { + chartButton.color = "#79bd8f"; + titleButton.color = "#79bd8f"; + legendButton.color = "#79bd8f"; + axisXButton.color = "#79bd8f"; + axisYButton.color = "#79bd8f"; + seriesButton.color = "#79bd8f"; + button.color = "#00a388"; + } + + Flow { + id: selectorFlow + anchors.top: parent.top + height: 90 + anchors.left: parent.left + anchors.right: parent.right + spacing: 5 + flow: Flow.TopToBottom + + Button { + id: chartButton + text: "Chart properties" + unpressedColor: "#79bd8f" + onClicked: { + selectButton(chartButton); + loader.source = "ChartEditorProperties.qml"; + loader.item.chart = chart; + } + } + Button { + id: titleButton + text: "Title properties" + unpressedColor: "#79bd8f" + onClicked: { + selectButton(titleButton); + loader.source = "ChartEditorTitle.qml"; + loader.item.chart = chart; + } + } + Button { + id: legendButton + text: "Legend properties" + unpressedColor: "#79bd8f" + onClicked: { + selectButton(legendButton); + loader.source = "ChartEditorLegend.qml"; + loader.item.chartLegend = chart.legend; + } + } + Button { + id: axisXButton + text: "Axis X properties" + unpressedColor: "#79bd8f" + onClicked: { + selectButton(axisXButton); + loader.source = "ChartEditorAxis.qml"; + loader.item.axis = chart.axisX(); + } + } + Button { + id: axisYButton + text: "Axis Y properties" + unpressedColor: "#79bd8f" + onClicked: { + selectButton(axisYButton); + loader.source = "ChartEditorAxis.qml"; + loader.item.axis = chart.axisY(); + } + } + Button { + id: seriesButton + text: "Series" + unpressedColor: "#79bd8f" + onClicked: { + selectButton(seriesButton); + loader.source = "ChartEditorSeries.qml"; + loader.item.chart = chart; + } + } + } + + Loader { + id: loader + anchors.top: selectorFlow.bottom + anchors.bottom: parent.bottom + anchors.left: parent.left + anchors.right: parent.right + } +} diff --git a/tests/manual/qmlchartproperties/qml/qmlchartproperties/ChartEditorAxis.qml b/tests/manual/qmlchartproperties/qml/qmlchartproperties/ChartEditorAxis.qml new file mode 100644 index 00000000..0c6d8dce --- /dev/null +++ b/tests/manual/qmlchartproperties/qml/qmlchartproperties/ChartEditorAxis.qml @@ -0,0 +1,131 @@ +/**************************************************************************** +** +** 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 + +Row { + anchors.fill: parent + spacing: 5 + property variant axis + + Flow { + spacing: 5 + flow: Flow.TopToBottom + height: parent.height + + Button { + text: "axis visible" + onClicked: axis.visible = !axis.visible; + } + Button { + text: "axis line visible" + onClicked: axis.lineVisible = !axis.lineVisible; + } + Button { + text: "axis color" + onClicked: axis.color = main.nextColor(); + } + Button { + text: "axis labels visible" + onClicked: axis.labelsVisible = !axis.labelsVisible; + } + Button { + text: "axis labels angle +" + onClicked: axis.labelsAngle += 5; + } + Button { + text: "axis labels angle -" + onClicked: axis.labelsAngle -= 5; + } + Button { + text: "axis labels color" + onClicked: axis.labelsColor = main.nextColor(); + } + Button { + text: "axis grid visible" + onClicked: axis.gridVisible = !axis.gridVisible; + } + Button { + text: "axis shades visible" + onClicked: axis.shadesVisible = !axis.shadesVisible; + } + Button { + text: "axis shades color" + onClicked: axis.shadesColor = main.nextColor(); + } + Button { + text: "axis shades bcolor" + onClicked: axis.shadesBorderColor = main.nextColor(); + } + Button { + text: "axis title text" + onClicked: axis.titleText = axis.titleText + "X"; + } + Button { + text: "axis title visible" + onClicked: axis.titleVisible = !axis.titleVisible; + } + Button { + text: "axis max +" + onClicked: axis.max += 0.1; + } + Button { + text: "axis max -" + onClicked: axis.max -= 0.1; + } + Button { + text: "axis min +" + onClicked: axis.min += 0.1; + } + Button { + text: "axis min -" + onClicked: axis.min -= 0.1; + } + Button { + text: "axis tick count +" + onClicked: axis.tickCount++; + } + Button { + text: "axis tick count -" + + onClicked: axis.tickCount--; + } + Button { + text: "axis nice nmb" + onClicked: axis.niceNumbersEnabled = !axis.niceNumbersEnabled; + } + + FontEditor { + id: fontEditor + fontDescription: "axis" + function editedFont() { + return axis.labelsFont; + } + } + + FontEditor { + id: titleFontEditor + fontDescription: "title" + function editedFont() { + return axis.titleFont; + } + } + } +} diff --git a/tests/manual/qmlchartproperties/qml/qmlchartproperties/ChartEditorLegend.qml b/tests/manual/qmlchartproperties/qml/qmlchartproperties/ChartEditorLegend.qml new file mode 100644 index 00000000..24ffd9ef --- /dev/null +++ b/tests/manual/qmlchartproperties/qml/qmlchartproperties/ChartEditorLegend.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 + +Row { + anchors.fill: parent + spacing: 5 + property variant chartLegend + + Flow { + spacing: 5 + flow: Flow.TopToBottom + + Button { + text: "legend visible" + onClicked: chartLegend.visible = !chartLegend.visible; + } + Button { + text: "legend bckgrd visible" + onClicked: chartLegend.backgroundVisible = !chartLegend.backgroundVisible; + } + Button { + text: "legend color" + onClicked: chartLegend.color = main.nextColor(); + } + Button { + text: "legend border color" + onClicked: chartLegend.borderColor = main.nextColor(); + } + Button { + text: "legend label color" + onClicked: chartLegend.labelColor = main.nextColor(); + } + Button { + text: "legend top" + onClicked: chartLegend.alignment = Qt.AlignTop; + } + Button { + text: "legend bottom" + onClicked: chartLegend.alignment = Qt.AlignBottom; + } + Button { + text: "legend left" + onClicked: chartLegend.alignment = Qt.AlignLeft; + } + Button { + text: "legend right" + onClicked: chartLegend.alignment = Qt.AlignRight; + } + Button { + text: "legend use reverse order" + onClicked: chartLegend.reverseMarkers = !chartLegend.reverseMarkers; + } + } + + FontEditor { + fontDescription: "legend" + function editedFont() { + return chartLegend.font; + } + } +} diff --git a/tests/manual/qmlchartproperties/qml/qmlchartproperties/ChartEditorProperties.qml b/tests/manual/qmlchartproperties/qml/qmlchartproperties/ChartEditorProperties.qml new file mode 100644 index 00000000..d172e4d8 --- /dev/null +++ b/tests/manual/qmlchartproperties/qml/qmlchartproperties/ChartEditorProperties.qml @@ -0,0 +1,124 @@ +/**************************************************************************** +** +** 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 + +Flow { + anchors.fill: parent + property variant chart + flow: Flow.TopToBottom + spacing: 5 + Button { + text: "visible" + onClicked: chart.visible = !chart.visible; + } + Button { + text: "theme +" + onClicked: chart.theme++; + } + Button { + text: "theme -" + onClicked: chart.theme--; + } + Button { + text: "animation opt +" + onClicked: chart.animationOptions++; + } + Button { + text: "animation opt -" + onClicked: chart.animationOptions--; + } + Button { + text: "background color" + onClicked: chart.backgroundColor = main.nextColor(); + } + Button { + text: "plot area color" + onClicked: chart.plotAreaColor = main.nextColor(); + } + Button { + text: "drop shadow enabled" + onClicked: chart.dropShadowEnabled = !chart.dropShadowEnabled; + } + Button { + text: "roundness" + onClicked: chart.backgroundRoundness++; + } + Button { + text: "zoom +" + onClicked: chart.zoom(2); + } + Button { + text: "zoom -" + onClicked: chart.zoom(0.5); + } + Button { + text: "scroll left" + onClicked: chart.scrollLeft(10); + } + Button { + text: "scroll right" + onClicked: chart.scrollRight(10); + } + Button { + text: "scroll up" + onClicked: chart.scrollUp(10); + } + Button { + text: "scroll down" + onClicked: chart.scrollDown(10); + } + Button { + text: "title color" + onClicked: chart.titleColor = main.nextColor(); + } + Button { + text: "top margin +" + onClicked: chart.margins.top += 5; + } + Button { + text: "top margin -" + onClicked: chart.margins.top -= 5; + } + Button { + text: "bottom margin +" + onClicked: chart.margins.bottom += 5; + } + Button { + text: "bottom margin -" + onClicked: chart.margins.bottom -= 5; + } + Button { + text: "left margin +" + onClicked: chart.margins.left += 5; + } + Button { + text: "left margin -" + onClicked: chart.margins.left -= 5; + } + Button { + text: "right margin +" + onClicked: chart.margins.right += 5; + } + Button { + text: "right margin -" + onClicked: chart.margins.right -= 5; + } +} diff --git a/tests/manual/qmlchartproperties/qml/qmlchartproperties/ChartEditorSeries.qml b/tests/manual/qmlchartproperties/qml/qmlchartproperties/ChartEditorSeries.qml new file mode 100644 index 00000000..e7efc222 --- /dev/null +++ b/tests/manual/qmlchartproperties/qml/qmlchartproperties/ChartEditorSeries.qml @@ -0,0 +1,64 @@ +/**************************************************************************** +** +** 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 + +Flow { + anchors.fill: parent + property variant chart + flow: Flow.TopToBottom + spacing: 5 + + Button { + text: "add line" + onClicked: addXYSeries(ChartView.SeriesTypeLine, "line"); + } + Button { + text: "add spline" + onClicked: addXYSeries(ChartView.SeriesTypeSpline, "spline"); + } + Button { + text: "add scatter" + onClicked: addXYSeries(ChartView.SeriesTypeScatter, "scatter"); + } + Button { + text: "remove last" + onClicked: { + if (chart.count > 0) + chart.removeSeries(chart.series(chart.count - 1)); + else + chart.removeSeries(0); + } + } + Button { + text: "remove all" + onClicked: chart.removeAllSeries(); + } + + function addXYSeries(type, name) { + var series = chart.createSeries(type, name + " " + chart.count); + for (var i = chart.axisX().min; i < chart.axisX().max; i++) { + var y = Math.random() * (chart.axisY().max - chart.axisY().min) + chart.axisY().min; + var x = Math.random() + i; + series.append(x, y); + } + } +} diff --git a/tests/manual/qmlchartproperties/qml/qmlchartproperties/ChartEditorTitle.qml b/tests/manual/qmlchartproperties/qml/qmlchartproperties/ChartEditorTitle.qml new file mode 100644 index 00000000..61b4365f --- /dev/null +++ b/tests/manual/qmlchartproperties/qml/qmlchartproperties/ChartEditorTitle.qml @@ -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$ +** +****************************************************************************/ + +import QtQuick 2.0 + +Flow { + property variant chart + anchors.fill: parent + flow: Flow.TopToBottom + spacing: 5 + + FontEditor { + fontDescription: "title" + function editedFont() { + return chart.titleFont; + } + } +} diff --git a/tests/manual/qmlchartproperties/qml/qmlchartproperties/FontEditor.qml b/tests/manual/qmlchartproperties/qml/qmlchartproperties/FontEditor.qml new file mode 100644 index 00000000..3531597f --- /dev/null +++ b/tests/manual/qmlchartproperties/qml/qmlchartproperties/FontEditor.qml @@ -0,0 +1,92 @@ +/**************************************************************************** +** +** 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 + +Flow { + flow: Flow.TopToBottom + spacing: 5 + property string fontDescription: "" + + Button { + text: fontDescription + " bold" + onClicked: editedFont().bold = !editedFont().bold; + } + Button { + text: fontDescription + " capitalization" + onClicked: editedFont().capitalization++; + } + Button { + text: fontDescription + " font family" + onClicked: editedFont().family = "courier"; + } + Button { + text: fontDescription + " font italic" + onClicked: editedFont().italic = !editedFont().italic; + } + Button { + text: fontDescription + " letterSpacing +" + onClicked: editedFont().letterSpacing++; + } + Button { + text: fontDescription + " letterSpacing -" + onClicked: editedFont().letterSpacing--; + } + Button { + text: fontDescription + " pixelSize +" + onClicked: editedFont().pixelSize++; + } + Button { + text: fontDescription + " pixelSize -" + onClicked: editedFont().pixelSize--; + } + Button { + text: fontDescription + " pointSize +" + onClicked: editedFont().pointSize++; + } + Button { + text: fontDescription + " pointSize -" + onClicked: editedFont().pointSize--; + } + Button { + text: fontDescription + " strikeout" + onClicked: editedFont().strikeout = !editedFont().strikeout; + } + Button { + text: fontDescription + " underline" + onClicked: editedFont().underline = !editedFont().underline; + } + Button { + text: fontDescription + " weight +" + onClicked: editedFont().weight++; + } + Button { + text: fontDescription + " weight -" + onClicked: editedFont().weight--; + } + Button { + text: fontDescription + " wordSpacing +" + onClicked: editedFont().wordSpacing++; + } + Button { + text: fontDescription + " wordSpacing -" + onClicked: editedFont().wordSpacing--; + } +} diff --git a/tests/manual/qmlchartproperties/qml/qmlchartproperties/HorizontalBarChart.qml b/tests/manual/qmlchartproperties/qml/qmlchartproperties/HorizontalBarChart.qml new file mode 100644 index 00000000..aedb26cb --- /dev/null +++ b/tests/manual/qmlchartproperties/qml/qmlchartproperties/HorizontalBarChart.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 + +ChartView { + title: "Bar series" + anchors.fill: parent + theme: ChartView.ChartThemeLight + legend.alignment: Qt.AlignBottom + animationOptions: ChartView.SeriesAnimations + + property variant series: mySeries + + HorizontalBarSeries { + id: mySeries + name: "bar" + labelsFormat: "@value"; + axisY: BarCategoryAxis { categories: ["2007", "2008", "2009", "2010", "2011", "2012" ] } + BarSet { label: "Bob"; values: [2, 2, 3, 4, 5, 6] + onClicked: console.log("barset.onClicked: " + index); + onHovered: console.log("barset.onHovered: " + status + " " + index); + onPenChanged: console.log("barset.onPenChanged: " + pen); + onBrushChanged: console.log("barset.onBrushChanged: " + brush); + onLabelChanged: console.log("barset.onLabelChanged: " + label); + onLabelBrushChanged: console.log("barset.onLabelBrushChanged: " + labelBrush); + onLabelFontChanged: console.log("barset.onLabelFontChanged: " + labelFont); + onColorChanged: console.log("barset.onColorChanged: " + color); + onBorderColorChanged: console.log("barset.onBorderColorChanged: " + color); + onLabelColorChanged: console.log("barset.onLabelColorChanged: " + color); + onCountChanged: console.log("barset.onCountChanged: " + count); + onValuesAdded: console.log("barset.onValuesAdded: " + index + ", " + count); + onValuesRemoved: console.log("barset.onValuesRemoved: " + index + ", " + count); + onValueChanged: console.log("barset.onValuesChanged: " + index); + } + BarSet { label: "Susan"; values: [5, 1, 2, 4, 1, 7] } + BarSet { label: "James"; values: [3, 5, 8, 13, 5, 8] } + + onNameChanged: console.log("horizontalBarSeries.onNameChanged: " + series.name); + onVisibleChanged: console.log("horizontalBarSeries.onVisibleChanged: " + series.visible); + onOpacityChanged: console.log("horizontalBarSeries.onOpacityChanged: " + opacity); + onClicked: console.log("horizontalBarSeries.onClicked: " + barset + " " + index); + onHovered: console.log("horizontalBarSeries.onHovered: " + barset + " " + + status + " " + index); + onLabelsVisibleChanged: console.log("horizontalBarSeries.onLabelsVisibleChanged: " + series.labelsVisible); + onCountChanged: console.log("horizontalBarSeries.onCountChanged: " + count); + onLabelsFormatChanged: console.log("horizontalBarSeries.onLabelsFormatChanged: " + + format); + onLabelsPositionChanged: console.log("horizontalBarSeries.onLabelsPositionChanged: " + + series.labelsPosition); + + function changeLabelsPosition() { + if (labelsPosition === BarSeries.LabelsCenter) + labelsPosition = BarSeries.LabelsInsideEnd; + else + labelsPosition = BarSeries.LabelsCenter; + } + } +} diff --git a/tests/manual/qmlchartproperties/qml/qmlchartproperties/HorizontalPercentBarChart.qml b/tests/manual/qmlchartproperties/qml/qmlchartproperties/HorizontalPercentBarChart.qml new file mode 100644 index 00000000..c0d1b443 --- /dev/null +++ b/tests/manual/qmlchartproperties/qml/qmlchartproperties/HorizontalPercentBarChart.qml @@ -0,0 +1,79 @@ +/**************************************************************************** +** +** 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 { + title: "Percent bar series" + anchors.fill: parent + theme: ChartView.ChartThemeLight + legend.alignment: Qt.AlignBottom + animationOptions: ChartView.SeriesAnimations + + property variant series: mySeries + + HorizontalPercentBarSeries { + id: mySeries + name: "bar" + labelsFormat: "@value"; + axisY: BarCategoryAxis { categories: ["2007", "2008", "2009", "2010", "2011", "2012" ] } + BarSet { label: "Bob"; values: [2, 2, 3, 4, 5, 6] + onClicked: console.log("barset.onClicked: " + index); + onHovered: console.log("barset.onHovered: " + status + " " + index); + onPenChanged: console.log("barset.onPenChanged: " + pen); + onBrushChanged: console.log("barset.onBrushChanged: " + brush); + onLabelChanged: console.log("barset.onLabelChanged: " + label); + onLabelBrushChanged: console.log("barset.onLabelBrushChanged: " + labelBrush); + onLabelFontChanged: console.log("barset.onLabelFontChanged: " + labelFont); + onColorChanged: console.log("barset.onColorChanged: " + color); + onBorderColorChanged: console.log("barset.onBorderColorChanged: " + color); + onLabelColorChanged: console.log("barset.onLabelColorChanged: " + color); + onCountChanged: console.log("barset.onCountChanged: " + count); + onValuesAdded: console.log("barset.onValuesAdded: " + index + ", " + count); + onValuesRemoved: console.log("barset.onValuesRemoved: " + index + ", " + count); + onValueChanged: console.log("barset.onValuesChanged: " + index); + } + BarSet { label: "Susan"; values: [5, 1, 2, 4, 1, 7] } + BarSet { label: "James"; values: [3, 5, 8, 13, 5, 8] } + + onNameChanged: console.log("horizontalPercentBarSeries.onNameChanged: " + series.name); + onVisibleChanged: console.log("horizontalPercentBarSeries.onVisibleChanged: " + series.visible); + onOpacityChanged: console.log("horizontalPercentBarSeries.onOpacityChanged: " + opacity); + onClicked: console.log("horizontalPercentBarSeries.onClicked: " + barset + " " + index); + onHovered: console.log("horizontalPercentBarSeries.onHovered: " + barset + + " " + status + " " + index); + onLabelsVisibleChanged: console.log("horizontalPercentBarSeries.onLabelsVisibleChanged: " + series.labelsVisible); + onCountChanged: console.log("horizontalPercentBarSeries.onCountChanged: " + count); + onLabelsFormatChanged: console.log( + "horizontalPercentBarSeries.onLabelsFormatChanged: " + + format); + onLabelsPositionChanged: console.log( + "horizontalPercentBarSeries.onLabelsPositionChanged: " + + series.labelsPosition); + + function changeLabelsPosition() { + if (labelsPosition === BarSeries.LabelsCenter) + labelsPosition = BarSeries.LabelsInsideEnd; + else + labelsPosition = BarSeries.LabelsCenter; + } + } +} diff --git a/tests/manual/qmlchartproperties/qml/qmlchartproperties/HorizontalStackedBarChart.qml b/tests/manual/qmlchartproperties/qml/qmlchartproperties/HorizontalStackedBarChart.qml new file mode 100644 index 00000000..3b94e89d --- /dev/null +++ b/tests/manual/qmlchartproperties/qml/qmlchartproperties/HorizontalStackedBarChart.qml @@ -0,0 +1,79 @@ +/**************************************************************************** +** +** 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 { + title: "Stacked bar series" + anchors.fill: parent + theme: ChartView.ChartThemeLight + legend.alignment: Qt.AlignBottom + animationOptions: ChartView.SeriesAnimations + + property variant series: mySeries + + HorizontalStackedBarSeries { + id: mySeries + name: "bar" + labelsFormat: "@value"; + axisY: BarCategoryAxis { categories: ["2007", "2008", "2009", "2010", "2011", "2012" ] } + BarSet { label: "Bob"; values: [2, 2, 3, 4, 5, 6] + onClicked: console.log("barset.onClicked: " + index); + onHovered: console.log("barset.onHovered: " + status + " " + index); + onPenChanged: console.log("barset.onPenChanged: " + pen); + onBrushChanged: console.log("barset.onBrushChanged: " + brush); + onLabelChanged: console.log("barset.onLabelChanged: " + label); + onLabelBrushChanged: console.log("barset.onLabelBrushChanged: " + labelBrush); + onLabelFontChanged: console.log("barset.onLabelFontChanged: " + labelFont); + onColorChanged: console.log("barset.onColorChanged: " + color); + onBorderColorChanged: console.log("barset.onBorderColorChanged: " + color); + onLabelColorChanged: console.log("barset.onLabelColorChanged: " + color); + onCountChanged: console.log("barset.onCountChanged: " + count); + onValuesAdded: console.log("barset.onValuesAdded: " + index + ", " + count); + onValuesRemoved: console.log("barset.onValuesRemoved: " + index + ", " + count); + onValueChanged: console.log("barset.onValuesChanged: " + index); + } + BarSet { label: "Susan"; values: [5, 1, 2, 4, 1, 7] } + BarSet { label: "James"; values: [3, 5, 8, 13, 5, 8] } + + onNameChanged: console.log("horizontalStackedBarSeries.onNameChanged: " + series.name); + onVisibleChanged: console.log("horizontalStackedBarSeries.onVisibleChanged: " + series.visible); + onOpacityChanged: console.log("horizontalStackedBarSeries.onOpacityChanged: " + opacity); + onClicked: console.log("horizontalStackedBarSeries.onClicked: " + barset + " " + index); + onHovered: console.log("horizontalStackedBarSeries.onHovered: " + barset + + " " + status + " " + index); + onLabelsVisibleChanged: console.log("horizontalStackedBarSeries.onLabelsVisibleChanged: " + series.labelsVisible); + onCountChanged: console.log("horizontalStackedBarSeries.onCountChanged: " + count); + onLabelsFormatChanged: console.log( + "horizontalStackedBarSeries.onLabelsFormatChanged: " + + format); + onLabelsPositionChanged: console.log( + "horizontalStackedBarSeries.onLabelsPositionChanged: " + + series.labelsPosition); + + function changeLabelsPosition() { + if (labelsPosition === BarSeries.LabelsCenter) + labelsPosition = BarSeries.LabelsInsideEnd; + else + labelsPosition = BarSeries.LabelsCenter; + } + } +} diff --git a/tests/manual/qmlchartproperties/qml/qmlchartproperties/LineChart.qml b/tests/manual/qmlchartproperties/qml/qmlchartproperties/LineChart.qml new file mode 100644 index 00000000..de3134a8 --- /dev/null +++ b/tests/manual/qmlchartproperties/qml/qmlchartproperties/LineChart.qml @@ -0,0 +1,78 @@ +/**************************************************************************** +** +** 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 { + property variant series: lineSeries + + title: "line series" + anchors.fill: parent + animationOptions: ChartView.SeriesAnimations + + LineSeries { + id: lineSeries + name: "line 1" + XYPoint { x: 0; y: 0 } + XYPoint { x: 1.1; y: 2.1 } + XYPoint { x: 1.9; y: 3.3 } + XYPoint { x: 2.1; y: 2.1 } + XYPoint { x: 2.9; y: 4.9 } + XYPoint { x: 3.4; y: 3.0 } + XYPoint { x: 4.1; y: 3.3 } + + pointLabelsFormat: "@xPoint, @yPoint"; + + onNameChanged: console.log("lineSeries.onNameChanged: " + name); + onVisibleChanged: console.log("lineSeries.onVisibleChanged: " + visible); + onOpacityChanged: console.log(name + ".onOpacityChanged: " + opacity); + onClicked: console.log(name + ".onClicked: " + point.x + ", " + point.y); + onPointReplaced: console.log("lineSeries.onPointReplaced: " + index); + onPointRemoved: console.log("lineSeries.onPointRemoved: " + index); + onPointAdded: console.log("lineSeries.onPointAdded: " + series.at(index).x + ", " + series.at(index).y); + onColorChanged: console.log("lineSeries.onColorChanged: " + color); + onWidthChanged: console.log("lineSeries.onWidthChanged: " + width); + onStyleChanged: console.log("lineSeries.onStyleChanged: " + style); + onCapStyleChanged: console.log("lineSeries.onCapStyleChanged: " + capStyle); + onCountChanged: console.log("lineSeries.onCountChanged: " + count); + onHovered: console.log("lineSeries.onHovered:" + point.x + "," + point.y + " " + state); + onPointLabelsVisibilityChanged: console.log("lineSeries.onPointLabelsVisibilityChanged: " + + visible); + onPointLabelsFormatChanged: console.log("lineSeries.onPointLabelsFormatChanged: " + + format); + onPointLabelsFontChanged: console.log("lineSeries.onPointLabelsFontChanged: " + + font.family); + onPointLabelsColorChanged: console.log("lineSeries.onPointLabelsColorChanged: " + + color); + } + + LineSeries { + name: "line 2" + XYPoint { x: 1.1; y: 1.1 } + XYPoint { x: 1.9; y: 2.3 } + XYPoint { x: 2.1; y: 1.1 } + XYPoint { x: 2.9; y: 3.9 } + XYPoint { x: 3.4; y: 2.0 } + XYPoint { x: 4.1; y: 2.3 } + onClicked: console.log(name + ".onClicked: " + point.x + ", " + point.y); + onHovered: console.log(name + ".onHovered: " + point.x + ", " + point.y); + } +} diff --git a/tests/manual/qmlchartproperties/qml/qmlchartproperties/LineEditor.qml b/tests/manual/qmlchartproperties/qml/qmlchartproperties/LineEditor.qml new file mode 100644 index 00000000..7960b4a1 --- /dev/null +++ b/tests/manual/qmlchartproperties/qml/qmlchartproperties/LineEditor.qml @@ -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$ +** +****************************************************************************/ + +import QtQuick 2.0 + + +Flow { + id: flow + spacing: 5 + flow: Flow.TopToBottom + property variant series + + Button { + text: "visible" + onClicked: series.visible = !series.visible; + } + Button { + text: "opacity +" + onClicked: series.opacity += 0.1; + } + Button { + text: "opacity -" + onClicked: series.opacity -= 0.1; + } + Button { + text: "color" + onClicked: series.color = main.nextColor(); + } + Button { + text: series != undefined ? "width + (" + series.width + ")" : "" + onClicked: series.width += 0.5; + } + Button { + text: series != undefined ? "width - (" + series.width + ")" : "" + onClicked: series.width -= 0.5; + } + Button { + text: series != undefined ? "style + (" + series.style + ")" : "" + onClicked: series.style++; + } + Button { + text: series != undefined ? "style - (" + series.style + ")" : "" + onClicked: series.style--; + } + Button { + text: series != undefined ? "cap style + (" + series.capStyle + ")" : "" + onClicked: series.capStyle++; + } + Button { + text: series != undefined ? "cap style - (" +series.capStyle + ")" : "" + onClicked: series.capStyle--; + } + Button { + text: "points visible" + onClicked: series.pointsVisible = !series.pointsVisible; + } + Button { + text: "point labels visible" + onClicked: series.pointLabelsVisible = !series.pointLabelsVisible; + } + Button { + text: "point labels format" + onClicked: { + if (series.pointLabelsFormat === "@xPoint, @yPoint") + series.pointLabelsFormat = "(@xPoint)" + else + series.pointLabelsFormat = "@xPoint, @yPoint" + } + } + Button { + text: "point labels font" + onClicked: { + if (series.pointLabelsFont.family === "Times") + series.pointLabelsFont.family = "Courier"; + else + series.pointLabelsFont.family = "Times"; + } + } + Button { + text: "point labels color" + onClicked: series.pointLabelsColor = main.nextColor(); + } + Button { + text: "append point" + onClicked: series.append(series.count - 1, series.count - 1); + } + Button { + text: "replace point" + onClicked: { + var xyPoint = series.at(series.count - 1); + series.replace(series.count - 1, xyPoint.x, xyPoint.y + 0.1); + } + } + Button { + text: "remove point" + onClicked: series.remove(series.count - 1); + } + Button { + text: "insert point" + onClicked: series.insert(series.count - 2, series.count - 2, series.count - 2); + } + Button { + text: "clear" + onClicked: series.clear(); + } +} diff --git a/tests/manual/qmlchartproperties/qml/qmlchartproperties/PercentBarChart.qml b/tests/manual/qmlchartproperties/qml/qmlchartproperties/PercentBarChart.qml new file mode 100644 index 00000000..74c9b88f --- /dev/null +++ b/tests/manual/qmlchartproperties/qml/qmlchartproperties/PercentBarChart.qml @@ -0,0 +1,78 @@ +/**************************************************************************** +** +** 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 { + title: "Percent bar series" + anchors.fill: parent + theme: ChartView.ChartThemeLight + legend.alignment: Qt.AlignBottom + animationOptions: ChartView.SeriesAnimations + + property variant series: mySeries + + PercentBarSeries { + id: mySeries + name: "bar" + labelsFormat: "@value"; + axisX: BarCategoryAxis { categories: ["2007", "2008", "2009", "2010", "2011", "2012" ] } + + BarSet { label: "Bob"; values: [2, 2, 3, 4, 5, 6] + onClicked: console.log("barset.onClicked: " + index); + onHovered: console.log("barset.onHovered: " + status + " " + index); + onPenChanged: console.log("barset.onPenChanged: " + pen); + onBrushChanged: console.log("barset.onBrushChanged: " + brush); + onLabelChanged: console.log("barset.onLabelChanged: " + label); + onLabelBrushChanged: console.log("barset.onLabelBrushChanged: " + labelBrush); + onLabelFontChanged: console.log("barset.onLabelFontChanged: " + labelFont); + onColorChanged: console.log("barset.onColorChanged: " + color); + onBorderColorChanged: console.log("barset.onBorderColorChanged: " + color); + onLabelColorChanged: console.log("barset.onLabelColorChanged: " + color); + onCountChanged: console.log("barset.onCountChanged: " + count); + onValuesAdded: console.log("barset.onValuesAdded: " + index + ", " + count); + onValuesRemoved: console.log("barset.onValuesRemoved: " + index + ", " + count); + onValueChanged: console.log("barset.onValuesChanged: " + index); + } + BarSet { label: "Susan"; values: [5, 1, 2, 4, 1, 7] } + BarSet { label: "James"; values: [3, 5, 8, 13, 5, 8] } + + onNameChanged: console.log("percentBarSeries.onNameChanged: " + series.name); + onVisibleChanged: console.log("percentBarSeries.onVisibleChanged: " + series.visible); + onOpacityChanged: console.log("percentBarSeries.onOpacityChanged: " + opacity); + onClicked: console.log("percentBarSeries.onClicked: " + barset + " " + index); + onHovered: console.log("percentBarSeries.onHovered: " + barset + + " " + status + " " + index); + onLabelsVisibleChanged: console.log("percentBarSeries.onLabelsVisibleChanged: " + series.labelsVisible); + onCountChanged: console.log("percentBarSeries.onCountChanged: " + count); + onLabelsFormatChanged: console.log("percentBarSeries.onLabelsFormatChanged: " + + format); + onLabelsPositionChanged: console.log("percentBarSeries.onLabelsPositionChanged: " + + series.labelsPosition); + + function changeLabelsPosition() { + if (labelsPosition === BarSeries.LabelsCenter) + labelsPosition = BarSeries.LabelsInsideEnd; + else + labelsPosition = BarSeries.LabelsCenter; + } + } +} diff --git a/tests/manual/qmlchartproperties/qml/qmlchartproperties/PieChart.qml b/tests/manual/qmlchartproperties/qml/qmlchartproperties/PieChart.qml new file mode 100644 index 00000000..37a321ae --- /dev/null +++ b/tests/manual/qmlchartproperties/qml/qmlchartproperties/PieChart.qml @@ -0,0 +1,67 @@ +/**************************************************************************** +** +** 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: chart + title: "pie series" + animationOptions: ChartView.SeriesAnimations + + property variant series: pieSeries + + PieSeries { + id: pieSeries + name: "pie" + PieSlice { label: "slice1"; value: 11; + onValueChanged: console.log("slice.onValueChanged: " + value); + onLabelVisibleChanged: console.log("slice.onLabelVisibleChanged: " + labelVisible); + onPenChanged: console.log("slice.onPenChanged: " + pen); + onBorderColorChanged: console.log("slice.onBorderColorChanged: " + borderColor); + onBorderWidthChanged: console.log("slice.onBorderWidthChanged: " + borderWidth); + onBrushChanged: console.log("slice.onBrushChanged: " + brush); + onColorChanged: console.log("slice.onColorChanged: " + color); + onLabelColorChanged: console.log("slice.onLabelColorChanged: " + labelColor); + onLabelBrushChanged: console.log("slice.onLabelBrushChanged: " + labelBrush); + onLabelFontChanged: console.log("slice.onLabelFontChanged: " + labelFont); + onPercentageChanged: console.log("slice.onPercentageChanged: " + percentage); + onStartAngleChanged: console.log("slice.onStartAngleChanged: " + startAngle); + onAngleSpanChanged: console.log("slice.onAngleSpanChanged: " + angleSpan); + onClicked: console.log("slice.onClicked: " + label); + onHovered: console.log("slice.onHovered: " + state); + } + PieSlice { label: "slice2"; value: 22 } + PieSlice { label: "slice3"; value: 33 } + PieSlice { label: "slice4"; value: 44 } + + onNameChanged: console.log("pieSeries.onNameChanged: " + name); + onVisibleChanged: console.log("pieSeries.onVisibleChanged: " + series.visible); + onOpacityChanged: console.log("pieSeries.onOpacityChanged: " + opacity); + onClicked: console.log("pieSeries.onClicked: " + slice.label); + onHovered: console.log("pieSeries.onHovered: " + slice.label); + onAdded: console.log("pieSeries.onAdded: " + slices); + onSliceAdded: console.log("pieSeries.onSliceAdded: " + slice.label); + onRemoved: console.log("pieSeries.onRemoved: " + slices); + onSliceRemoved: console.log("pieSeries.onSliceRemoved: " + slice.label); + onCountChanged: console.log("pieSeries.onCountChanged: " + count); + onSumChanged: console.log("pieSeries.onSumChanged: " + sum); + } +} diff --git a/tests/manual/qmlchartproperties/qml/qmlchartproperties/PieEditor.qml b/tests/manual/qmlchartproperties/qml/qmlchartproperties/PieEditor.qml new file mode 100644 index 00000000..91eb0343 --- /dev/null +++ b/tests/manual/qmlchartproperties/qml/qmlchartproperties/PieEditor.qml @@ -0,0 +1,228 @@ +/**************************************************************************** +** +** 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 + +Row { + anchors.fill: parent + spacing: 5 + property variant series + property int sliceIndex: 0 + + // buttons for selecting the edited object: series, slice or label + Flow { + spacing: 5 + flow: Flow.TopToBottom + Button { + id: seriesButton + text: "series" + unpressedColor: "#79bd8f" + onClicked: { + seriesFlow.visible = true; + slicesFlow.visible = false; + labelsFlow.visible = false; + color = "#00a388"; + sliceButton.color = "#79bd8f"; + labelButton.color = "#79bd8f"; + } + } + Button { + id: sliceButton + text: "slice" + unpressedColor: "#79bd8f" + onClicked: { + seriesFlow.visible = false; + slicesFlow.visible = true; + labelsFlow.visible = false; + color = "#00a388"; + seriesButton.color = "#79bd8f"; + labelButton.color = "#79bd8f"; + } + } + Button { + id: labelButton + text: "label" + unpressedColor: "#79bd8f" + onClicked: { + seriesFlow.visible = false; + slicesFlow.visible = false; + labelsFlow.visible = true; + color = "#00a388"; + seriesButton.color = "#79bd8f"; + sliceButton.color = "#79bd8f"; + } + } + } + + // Buttons for editing series + Flow { + id: seriesFlow + spacing: 5 + flow: Flow.TopToBottom + visible: false + Button { + text: "visible" + onClicked: series.visible = !series.visible; + } + Button { + text: "series opacity +" + onClicked: series.opacity += 0.1; + } + Button { + text: "series opacity -" + onClicked: series.opacity -= 0.1; + } + Button { + text: "series hpos +" + onClicked: series.horizontalPosition += 0.1; + } + Button { + text: "series hpos -" + onClicked: series.horizontalPosition -= 0.1; + } + Button { + text: "series vpos +" + onClicked: series.verticalPosition += 0.1; + } + Button { + text: "series vpos -" + onClicked: series.verticalPosition -= 0.1; + } + Button { + text: "series size +" + onClicked: series.size += 0.1; + } + Button { + text: "series size -" + onClicked: series.size -= 0.1; + } + Button { + text: "series start angle +" + onClicked: series.startAngle += 1.1; + } + Button { + text: "series start angle -" + onClicked: series.startAngle -= 1.1; + } + Button { + text: "series end angle +" + onClicked: series.endAngle += 1.1; + } + Button { + text: "series end angle -" + onClicked: series.endAngle -= 1.1; + } + } + + // Buttons for editing slices + Flow { + id: slicesFlow + spacing: 5 + flow: Flow.TopToBottom + visible: false + + Button { + text: "append slice" + onClicked: series.append("slice" + (series.count + 1), 3.0); + } + Button { + text: "remove slice" + onClicked: series.remove(series.at(series.count - 1)); + } + Button { + text: "slice color" + onClicked: series.at(sliceIndex).color = main.nextColor(); + } + Button { + text: "slice border color" + onClicked: series.at(sliceIndex).borderColor = main.nextColor(); + } + Button { + text: "slice border width +" + onClicked: series.at(sliceIndex).borderWidth++; + } + Button { + text: "slice border width -" + onClicked: series.at(sliceIndex).borderWidth--; + } + Button { + text: "slice exploded" + onClicked: series.at(sliceIndex).exploded = !series.at(sliceIndex).exploded; + } + Button { + text: "slice explode dist +" + onClicked: series.at(sliceIndex).explodeDistanceFactor += 0.1; + } + Button { + text: "slice explode dist -" + onClicked: series.at(sliceIndex).explodeDistanceFactor -= 0.1; + } + } + + // Buttons for editing labels + Flow { + id: labelsFlow + spacing: 5 + flow: Flow.TopToBottom + visible: false + + Button { + text: "label visible" + onClicked: series.at(sliceIndex).labelVisible = !series.at(sliceIndex).labelVisible; + } + Button { + text: "LabelInsideNormal" + onClicked: series.at(sliceIndex).labelPosition = PieSlice.LabelInsideNormal; + } + Button { + text: "LabelInsideHorizontal" + onClicked: series.at(sliceIndex).labelPosition = PieSlice.LabelInsideHorizontal; + } + Button { + text: "LabelInsideTangential" + onClicked: series.at(sliceIndex).labelPosition = PieSlice.LabelInsideTangential; + } + Button { + text: "LabelOutside" + onClicked: series.at(sliceIndex).labelPosition = PieSlice.LabelOutside; + } + Button { + text: "label arm len +" + onClicked: series.at(sliceIndex).labelArmLengthFactor += 0.1; + } + Button { + text: "label arm len -" + onClicked: series.at(sliceIndex).labelArmLengthFactor -= 0.1; + } + Button { + text: "slice label color" + onClicked: series.at(sliceIndex).labelColor = main.nextColor(); + } + + FontEditor { + id: fontEditor + fontDescription: "label" + function editedFont() { + return series.at(sliceIndex).labelFont; + } + } + } +} diff --git a/tests/manual/qmlchartproperties/qml/qmlchartproperties/ScatterChart.qml b/tests/manual/qmlchartproperties/qml/qmlchartproperties/ScatterChart.qml new file mode 100644 index 00000000..d531ac32 --- /dev/null +++ b/tests/manual/qmlchartproperties/qml/qmlchartproperties/ScatterChart.qml @@ -0,0 +1,75 @@ +/**************************************************************************** +** +** 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 { + title: "scatter series" + property variant series: scatterSeries + animationOptions: ChartView.SeriesAnimations + + ScatterSeries { + id: scatterSeries + name: "scatter 1" + 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 } + + pointLabelsFormat: "@xPoint, @yPoint"; + + onNameChanged: console.log("scatterSeries.onNameChanged: " + name); + onVisibleChanged: console.log("scatterSeries.onVisibleChanged: " + visible); + onOpacityChanged: console.log(name + ".onOpacityChanged: " + opacity); + onClicked: console.log(name + ".onClicked: " + point.x + ", " + point.y); + onHovered: console.log(name + ".onHovered: " + point.x + ", " + point.y); + onPointReplaced: console.log("scatterSeries.onPointReplaced: " + index); + onPointRemoved: console.log("scatterSeries.onPointRemoved: " + index); + onPointAdded: console.log("scatterSeries.onPointAdded: " + series.at(index).x + ", " + series.at(index).y); + onColorChanged: console.log("scatterSeries.onColorChanged: " + color); + onBorderColorChanged: console.log("scatterSeries.onBorderColorChanged: " + borderColor); + onBorderWidthChanged: console.log("scatterSeries.onBorderChanged: " + borderWidth); + onCountChanged: console.log("scatterSeries.onCountChanged: " + count); + onPointLabelsVisibilityChanged: console.log("lineSeries.onPointLabelsVisibilityChanged: " + + visible); + onPointLabelsFormatChanged: console.log("lineSeries.onPointLabelsFormatChanged: " + + format); + onPointLabelsFontChanged: console.log("lineSeries.onPointLabelsFontChanged: " + + font.family); + onPointLabelsColorChanged: console.log("lineSeries.onPointLabelsColorChanged: " + + color); + } + + ScatterSeries { + name: "scatter2" + 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 } + onClicked: console.log(name + ".onClicked: " + point.x + ", " + point.y); + onHovered: console.log(name + ".onHovered: " + point.x + ", " + point.y); + } +} diff --git a/tests/manual/qmlchartproperties/qml/qmlchartproperties/ScatterEditor.qml b/tests/manual/qmlchartproperties/qml/qmlchartproperties/ScatterEditor.qml new file mode 100644 index 00000000..23afdb75 --- /dev/null +++ b/tests/manual/qmlchartproperties/qml/qmlchartproperties/ScatterEditor.qml @@ -0,0 +1,118 @@ +/**************************************************************************** +** +** 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 + +Flow { + id: flow + spacing: 5 + flow: Flow.TopToBottom + property variant series + + Button { + text: "visible" + onClicked: series.visible = !series.visible; + } + Button { + text: "opacity +" + onClicked: series.opacity += 0.1; + } + Button { + text: "opacity -" + onClicked: series.opacity -= 0.1; + } + Button { + text: "color" + onClicked: series.color = main.nextColor(); + } + Button { + text: "borderColor" + onClicked: series.borderColor = main.nextColor(); + } + Button { + text: series != undefined ? "borderWidth + (" + series.borderWidth + ")" : "" + onClicked: series.borderWidth += 0.5; + } + Button { + text: series != undefined ? "borderWidth - (" + series.borderWidth + ")" : "" + onClicked: series.borderWidth -= 0.5; + } + Button { + text: "markerSize +" + onClicked: series.markerSize += 1.0; + } + Button { + text: "markerSize -" + onClicked: series.markerSize -= 1.0; + } + Button { + text: "markerShape" + onClicked: series.markerShape = ((series.markerShape + 1) % 2); + } + Button { + text: "point labels visible" + onClicked: series.pointLabelsVisible = !series.pointLabelsVisible; + } + Button { + text: "point labels format" + onClicked: { + if (series.pointLabelsFormat === "@xPoint, @yPoint") + series.pointLabelsFormat = "(@xPoint)" + else + series.pointLabelsFormat = "@xPoint, @yPoint" + } + } + Button { + text: "point labels font" + onClicked: { + if (series.pointLabelsFont.family === "Times") + series.pointLabelsFont.family = "Courier"; + else + series.pointLabelsFont.family = "Times"; + } + } + Button { + text: "point labels color" + onClicked: series.pointLabelsColor = main.nextColor(); + } + Button { + text: "append point" + onClicked: series.append(series.count - 1, series.count - 1); + } + Button { + text: "replace point" + onClicked: { + var xyPoint = series.at(series.count - 1); + series.replace(series.count - 1, xyPoint.x, xyPoint.y + 0.1); + } + } + Button { + text: "remove point" + onClicked: series.remove(series.count - 1); + } + Button { + text: "insert point" + onClicked: series.insert(series.count - 2, series.count - 2, series.count - 2); + } + Button { + text: "clear" + onClicked: series.clear(); + } +} diff --git a/tests/manual/qmlchartproperties/qml/qmlchartproperties/SplineChart.qml b/tests/manual/qmlchartproperties/qml/qmlchartproperties/SplineChart.qml new file mode 100644 index 00000000..3a182d19 --- /dev/null +++ b/tests/manual/qmlchartproperties/qml/qmlchartproperties/SplineChart.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 + +ChartView { + title: "spline series" + anchors.fill: parent + property variant series: splineSeries + animationOptions: ChartView.SeriesAnimations + + SplineSeries { + id: splineSeries + name: "spline 1" + XYPoint { x: 0; y: 0 } + XYPoint { x: 1.1; y: 2.1 } + XYPoint { x: 1.9; y: 3.3 } + XYPoint { x: 2.1; y: 2.1 } + XYPoint { x: 2.9; y: 4.9 } + XYPoint { x: 3.4; y: 3.0 } + XYPoint { x: 4.1; y: 3.3 } + + pointLabelsFormat: "@xPoint, @yPoint"; + + onNameChanged: console.log("splineSeries.onNameChanged: " + name); + onVisibleChanged: console.log("splineSeries.onVisibleChanged: " + visible); + onOpacityChanged: console.log(name + ".onOpacityChanged: " + opacity); + onClicked: console.log(name + ".onClicked: " + point.x + ", " + point.y); + onHovered: console.log(name + ".onHovered: " + point.x + ", " + point.y); + onPointReplaced: console.log("splineSeries.onPointReplaced: " + index); + onPointRemoved: console.log("splineSeries.onPointRemoved: " + index); + onPointAdded: console.log("splineSeries.onPointAdded: " + series.at(index).x + ", " + series.at(index).y); + onColorChanged: console.log("splineSeries.onColorChanged: " + color); + onWidthChanged: console.log("splineSeries.onWidthChanged: " + width); + onStyleChanged: console.log("splineSeries.onStyleChanged: " + style); + onCapStyleChanged: console.log("splineSeries.onCapStyleChanged: " + capStyle); + onCountChanged: console.log("splineSeries.onCountChanged: " + count); + onPointLabelsVisibilityChanged: console.log("splineSeries.onPointLabelsVisibilityChanged: " + + visible); + onPointLabelsFormatChanged: console.log("splineSeries.onPointLabelsFormatChanged: " + + format); + onPointLabelsFontChanged: console.log("splineSeries.onPointLabelsFontChanged: " + + font.family); + onPointLabelsColorChanged: console.log("splineSeries.onPointLabelsColorChanged: " + + color); + } + + SplineSeries { + name: "spline 2" + XYPoint { x: 1.1; y: 1.1 } + XYPoint { x: 1.9; y: 2.3 } + XYPoint { x: 2.1; y: 1.1 } + XYPoint { x: 2.9; y: 3.9 } + XYPoint { x: 3.4; y: 2.0 } + XYPoint { x: 4.1; y: 2.3 } + onClicked: console.log(name + ".onClicked: " + point.x + ", " + point.y); + onHovered: console.log(name + ".onHovered: " + point.x + ", " + point.y); + } +} diff --git a/tests/manual/qmlchartproperties/qml/qmlchartproperties/StackedBarChart.qml b/tests/manual/qmlchartproperties/qml/qmlchartproperties/StackedBarChart.qml new file mode 100644 index 00000000..a59f0e12 --- /dev/null +++ b/tests/manual/qmlchartproperties/qml/qmlchartproperties/StackedBarChart.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 + +ChartView { + title: "Stacked bar series" + anchors.fill: parent + theme: ChartView.ChartThemeLight + legend.alignment: Qt.AlignBottom + animationOptions: ChartView.SeriesAnimations + + property variant series: mySeries + + StackedBarSeries { + id: mySeries + name: "bar" + labelsFormat: "@value"; + axisX: BarCategoryAxis { categories: ["2007", "2008", "2009", "2010", "2011", "2012" ] } + BarSet { label: "Bob"; values: [2, 2, 3, 4, 5, 6] + onClicked: console.log("barset.onClicked: " + index); + onHovered: console.log("barset.onHovered: " + status + " " + index); + onPenChanged: console.log("barset.onPenChanged: " + pen); + onBrushChanged: console.log("barset.onBrushChanged: " + brush); + onLabelChanged: console.log("barset.onLabelChanged: " + label); + onLabelBrushChanged: console.log("barset.onLabelBrushChanged: " + labelBrush); + onLabelFontChanged: console.log("barset.onLabelFontChanged: " + labelFont); + onColorChanged: console.log("barset.onColorChanged: " + color); + onBorderColorChanged: console.log("barset.onBorderColorChanged: " + color); + onLabelColorChanged: console.log("barset.onLabelColorChanged: " + color); + onCountChanged: console.log("barset.onCountChanged: " + count); + onValuesAdded: console.log("barset.onValuesAdded: " + index + ", " + count); + onValuesRemoved: console.log("barset.onValuesRemoved: " + index + ", " + count); + onValueChanged: console.log("barset.onValuesChanged: " + index); + } + BarSet { label: "Susan"; values: [5, 1, 2, 4, 1, 7] } + BarSet { label: "James"; values: [3, 5, 8, 13, 5, 8] } + + onNameChanged: console.log("stackedBarSeries.onNameChanged: " + series.name); + onVisibleChanged: console.log("stackedBarSeries.onVisibleChanged: " + series.visible); + onOpacityChanged: console.log("stackedBarSeries.onOpacityChanged: " + opacity); + onClicked: console.log("stackedBarSeries.onClicked: " + barset + " " + index); + onHovered: console.log("stackedBarSeries.onHovered: " + barset + + " " + status + " " + index); + onLabelsVisibleChanged: console.log("stackedBarSeries.onLabelsVisibleChanged: " + series.labelsVisible); + onCountChanged: console.log("stackedBarSeries.onCountChanged: " + count); + onLabelsFormatChanged: console.log("stackedBarSeries.onLabelsFormatChanged: " + + format); + onLabelsPositionChanged: console.log("stackedBarSeries.onLabelsPositionChanged: " + + series.labelsPosition); + + function changeLabelsPosition() { + if (labelsPosition === BarSeries.LabelsCenter) + labelsPosition = BarSeries.LabelsInsideEnd; + else + labelsPosition = BarSeries.LabelsCenter; + } + } +} diff --git a/tests/manual/qmlchartproperties/qml/qmlchartproperties/main.qml b/tests/manual/qmlchartproperties/qml/qmlchartproperties/main.qml new file mode 100644 index 00000000..8265e1ae --- /dev/null +++ b/tests/manual/qmlchartproperties/qml/qmlchartproperties/main.qml @@ -0,0 +1,179 @@ +/**************************************************************************** +** +** 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 { + id: main + width: 800 + height: 600 + property int viewCount: 9 + property variant colors: ["#637D74", "#403D3A", "#8C3B3B", "#AB6937", "#D4A960"] + property int colorIndex: 0 + property int buttonWidth: 42 + + function nextColor() { + colorIndex++; + return colors[colorIndex % colors.length]; + } + + Row { + anchors.top: parent.top + anchors.bottom: buttonRow.top + anchors.bottomMargin: 10 + anchors.left: parent.left + anchors.right: parent.right + + Loader { + id: chartLoader + width: main.width - editorLoader.width + height: parent.height + source: "Chart.qml" + onStatusChanged: { + if (status == Loader.Ready && editorLoader.status == Loader.Ready && chartLoader.item) { + if (source.toString().search("/Chart.qml") > 0) + editorLoader.item.chart = chartLoader.item.chart; + else + editorLoader.item.series = chartLoader.item.series; + } + } + } + + Loader { + id: editorLoader + width: 280 + height: parent.height + source: "ChartEditor.qml" + onStatusChanged: { + if (status == Loader.Ready && chartLoader.status == Loader.Ready && chartLoader.item) { + if (source.toString().search("/ChartEditor.qml") > 0) + editorLoader.item.chart = chartLoader.item.chart; + else + editorLoader.item.series = chartLoader.item.series; + } + } + } + } + + Row { + id: buttonRow + height: 40 + anchors.bottom: parent.bottom + anchors.horizontalCenter: parent.horizontalCenter + spacing: 10 + + Button { + text: "chart" + width: buttonWidth + onClicked: { + chartLoader.source = "Chart.qml"; + editorLoader.source = "ChartEditor.qml"; + } + } + Button { + text: "pie" + width: buttonWidth + onClicked: { + chartLoader.source = "PieChart.qml"; + editorLoader.source = "PieEditor.qml"; + } + } + Button { + text: "line" + width: buttonWidth + onClicked: { + chartLoader.source = "LineChart.qml"; + editorLoader.source = "LineEditor.qml"; + } + } + Button { + text: "spline" + width: buttonWidth + onClicked: { + chartLoader.source = "SplineChart.qml"; + editorLoader.source = "LineEditor.qml"; + } + } + Button { + text: "scatter" + width: buttonWidth + onClicked: { + chartLoader.source = "ScatterChart.qml"; + editorLoader.source = "ScatterEditor.qml"; + } + } + Button { + text: "area" + width: buttonWidth + onClicked: { + chartLoader.source = "AreaChart.qml"; + editorLoader.source = "AreaEditor.qml"; + } + } + Button { + text: "bar" + width: buttonWidth + onClicked: { + chartLoader.source = "BarChart.qml"; + editorLoader.source = "BarEditor.qml"; + } + } + Button { + text: "sbar" + width: buttonWidth + onClicked: { + chartLoader.source = "StackedBarChart.qml"; + editorLoader.source = "BarEditor.qml"; + } + } + Button { + text: "pbar" + width: buttonWidth + onClicked: { + chartLoader.source = "PercentBarChart.qml"; + editorLoader.source = "BarEditor.qml"; + } + } + Button { + text: "hbar" + width: buttonWidth + onClicked: { + chartLoader.source = "HorizontalBarChart.qml"; + editorLoader.source = "BarEditor.qml"; + } + } + Button { + text: "hsbar" + width: buttonWidth + onClicked: { + chartLoader.source = "HorizontalStackedBarChart.qml"; + editorLoader.source = "BarEditor.qml"; + } + } + Button { + text: "hpbar" + width: buttonWidth + onClicked: { + chartLoader.source = "HorizontalPercentBarChart.qml"; + editorLoader.source = "BarEditor.qml"; + } + } + } +} diff --git a/tests/manual/qmlchartproperties/qmlchartproperties.pro b/tests/manual/qmlchartproperties/qmlchartproperties.pro new file mode 100644 index 00000000..78c19300 --- /dev/null +++ b/tests/manual/qmlchartproperties/qmlchartproperties.pro @@ -0,0 +1,8 @@ +!include( ../../tests.pri ) { + error( "Couldn't find the test.pri file!" ) +} + +RESOURCES += resources.qrc +SOURCES += main.cpp +OTHER_FILES += qml/qmlchartproperties/* + diff --git a/tests/manual/qmlchartproperties/resources.qrc b/tests/manual/qmlchartproperties/resources.qrc new file mode 100644 index 00000000..e93f369e --- /dev/null +++ b/tests/manual/qmlchartproperties/resources.qrc @@ -0,0 +1,30 @@ +<RCC> + <qresource prefix="/"> + <file>qml/qmlchartproperties/main.qml</file> + <file>qml/qmlchartproperties/Button.qml</file> + <file>qml/qmlchartproperties/PieChart.qml</file> + <file>qml/qmlchartproperties/PieEditor.qml</file> + <file>qml/qmlchartproperties/LineChart.qml</file> + <file>qml/qmlchartproperties/LineEditor.qml</file> + <file>qml/qmlchartproperties/SplineChart.qml</file> + <file>qml/qmlchartproperties/ScatterChart.qml</file> + <file>qml/qmlchartproperties/AreaChart.qml</file> + <file>qml/qmlchartproperties/BarChart.qml</file> + <file>qml/qmlchartproperties/BarEditor.qml</file> + <file>qml/qmlchartproperties/ScatterEditor.qml</file> + <file>qml/qmlchartproperties/AreaEditor.qml</file> + <file>qml/qmlchartproperties/StackedBarChart.qml</file> + <file>qml/qmlchartproperties/PercentBarChart.qml</file> + <file>qml/qmlchartproperties/Chart.qml</file> + <file>qml/qmlchartproperties/ChartEditor.qml</file> + <file>qml/qmlchartproperties/FontEditor.qml</file> + <file>qml/qmlchartproperties/HorizontalBarChart.qml</file> + <file>qml/qmlchartproperties/HorizontalPercentBarChart.qml</file> + <file>qml/qmlchartproperties/HorizontalStackedBarChart.qml</file> + <file>qml/qmlchartproperties/ChartEditorAxis.qml</file> + <file>qml/qmlchartproperties/ChartEditorLegend.qml</file> + <file>qml/qmlchartproperties/ChartEditorProperties.qml</file> + <file>qml/qmlchartproperties/ChartEditorTitle.qml</file> + <file>qml/qmlchartproperties/ChartEditorSeries.qml</file> + </qresource> +</RCC> diff --git a/tests/manual/wavechart/main.cpp b/tests/manual/wavechart/main.cpp new file mode 100644 index 00000000..58423319 --- /dev/null +++ b/tests/manual/wavechart/main.cpp @@ -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$ +** +****************************************************************************/ + +#include "wavechart.h" +#include <QtWidgets/QApplication> +#include <QtWidgets/QMainWindow> +#include <QtOpenGL/QGLWidget> + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + + QMainWindow window; + QChart *chart = new QChart(); + WaveChart *waveChart = new WaveChart(chart,&window); + + waveChart->setViewport( new QGLWidget() ); + waveChart->setRenderHint(QPainter::Antialiasing); + chart->setAnimationOptions(QChart::AllAnimations); + chart->setTitle("This is wave generator."); + + window.setCentralWidget(waveChart); + window.resize(400, 300); + window.show(); + + return a.exec(); +} diff --git a/tests/manual/wavechart/wavechart.cpp b/tests/manual/wavechart/wavechart.cpp new file mode 100644 index 00000000..dc05d073 --- /dev/null +++ b/tests/manual/wavechart/wavechart.cpp @@ -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$ +** +****************************************************************************/ + +#include "wavechart.h" +#include <cmath> + +QT_CHARTS_USE_NAMESPACE + +#define PI 3.14159265358979 +static const int numPoints =100; + +WaveChart::WaveChart(QChart* chart, QWidget* parent) : + QChartView(chart, parent), + m_series(new QLineSeries()), + m_wave(0), + m_step(2 * PI / numPoints) +{ + QPen blue(Qt::blue); + blue.setWidth(3); + m_series->setPen(blue); + + chart->legend()->setVisible(false); + + QTime now = QTime::currentTime(); + qsrand((uint) now.msec()); + + int fluctuate = 100; + + for (qreal x = 0; x <= 2 * PI; x += m_step) { + m_series->append(x, fabs(sin(x) * fluctuate)); + } + + chart->addSeries(m_series); + chart->createDefaultAxes(); + + QObject::connect(&m_timer, SIGNAL(timeout()), this, SLOT(update())); + m_timer.setInterval(5000); + m_timer.start(); +} + +void WaveChart::update() +{ + + int fluctuate; + const QList<QPointF>& points = m_series->points(); + for (qreal i = 0, x = 0; x <= 2 * PI; x += m_step, i++) { + fluctuate = qrand() % 100; + m_series->replace(x,points[i].y(),x,fabs(sin(x) * fluctuate)); + + } + +} diff --git a/tests/manual/wavechart/wavechart.h b/tests/manual/wavechart/wavechart.h new file mode 100644 index 00000000..95978861 --- /dev/null +++ b/tests/manual/wavechart/wavechart.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 WAVECHART_H +#define WAVECHART_H + +#include <QtCore/QTimer> +#include <QtCore/QTime> +#include <QtCore/QObject> +#include <QtCharts/QLineSeries> +#include <QtCharts/QChartView> + +QT_CHARTS_USE_NAMESPACE + +class WaveChart: public QChartView +{ + Q_OBJECT + +public: + WaveChart(QChart* chart, QWidget* parent); + +private slots: + void update(); + +private: + QLineSeries* m_series; + int m_wave; + qreal m_step; + QTimer m_timer; +}; + +#endif diff --git a/tests/manual/wavechart/wavechart.pro b/tests/manual/wavechart/wavechart.pro new file mode 100644 index 00000000..0da16ed4 --- /dev/null +++ b/tests/manual/wavechart/wavechart.pro @@ -0,0 +1,8 @@ +!include( ../../tests.pri ) { + error( "Couldn't find the test.pri file!" ) +} + +QT+=opengl +TARGET = wavechart +SOURCES += main.cpp wavechart.cpp +HEADERS += wavechart.h |