diff --git a/demos/chartviewer/charts/charts.pri b/demos/chartviewer/charts/charts.pri index f2d564e..d73bc74 100644 --- a/demos/chartviewer/charts/charts.pri +++ b/demos/chartviewer/charts/charts.pri @@ -1,13 +1,14 @@ -INCLUDEPATH += $$PWD +INCLUDEPATH += $$PWD DEPENDPATH += $$PWD - -SOURCES+= \ - linechart.cpp \ - scatterchart.cpp \ - splinechart.cpp \ - piechart.cpp \ - verticalstackedbarchart.cpp \ - horizontalstackedbarchart.cpp \ - verticalbarchart.cpp \ - horizontalbarchart.cpp \ - areachart.cpp \ No newline at end of file +SOURCES += linechart.cpp \ + scatterchart.cpp \ + splinechart.cpp \ + verticalstackedbarchart.cpp \ + horizontalstackedbarchart.cpp \ + verticalbarchart.cpp \ + horizontalbarchart.cpp \ + horizontalpercentbarchart.cpp \ + verticalpercentbarchart.cpp \ + areachart.cpp \ + piechart.cpp \ + donutchart.cpp diff --git a/demos/chartviewer/charts/donutchart.cpp b/demos/chartviewer/charts/donutchart.cpp new file mode 100644 index 0000000..8402b2f --- /dev/null +++ b/demos/chartviewer/charts/donutchart.cpp @@ -0,0 +1,57 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc +** All rights reserved. +** For any questions to Digia, please use contact form at http://qt.digia.com +** +** This file is part of the Qt Commercial Charts Add-on. +** +** $QT_BEGIN_LICENSE$ +** Licensees holding valid Qt Commercial licenses may use this file in +** accordance with the Qt Commercial License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. +** +** If you have questions regarding the use of this file, please use +** contact form at http://qt.digia.com +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "charts.h" +#include "qchart.h" +#include "qpieseries.h" + +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/demos/chartviewer/charts/horizontalpercentbarchart.cpp b/demos/chartviewer/charts/horizontalpercentbarchart.cpp new file mode 100644 index 0000000..ce1223a --- /dev/null +++ b/demos/chartviewer/charts/horizontalpercentbarchart.cpp @@ -0,0 +1,55 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc +** All rights reserved. +** For any questions to Digia, please use contact form at http://qt.digia.com +** +** This file is part of the Qt Commercial Charts Add-on. +** +** $QT_BEGIN_LICENSE$ +** Licensees holding valid Qt Commercial licenses may use this file in +** accordance with the Qt Commercial License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. +** +** If you have questions regarding the use of this file, please use +** contact form at http://qt.digia.com +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "charts.h" +#include "qchart.h" +#include "qhorizontalpercentbarseries.h" +#include "qbarset.h" + +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/demos/chartviewer/charts/verticalpercentbarchart.cpp b/demos/chartviewer/charts/verticalpercentbarchart.cpp new file mode 100644 index 0000000..5adeb38 --- /dev/null +++ b/demos/chartviewer/charts/verticalpercentbarchart.cpp @@ -0,0 +1,55 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc +** All rights reserved. +** For any questions to Digia, please use contact form at http://qt.digia.com +** +** This file is part of the Qt Commercial Charts Add-on. +** +** $QT_BEGIN_LICENSE$ +** Licensees holding valid Qt Commercial licenses may use this file in +** accordance with the Qt Commercial License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. +** +** If you have questions regarding the use of this file, please use +** contact form at http://qt.digia.com +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "charts.h" +#include "qchart.h" +#include "qpercentbarseries.h" +#include "qbarset.h" + +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("Stacked 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/demos/chartviewer/window.cpp b/demos/chartviewer/window.cpp index 976c645..031b566 100644 --- a/demos/chartviewer/window.cpp +++ b/demos/chartviewer/window.cpp @@ -296,6 +296,8 @@ void Window::checkTemplate() if (m_template == index || index == 0) return; + m_template = index; + QString category = m_templateComboBox->itemData(index).toString(); Charts::ChartList list = Charts::chartList();