From 344c3d3c27422964497364905aa2af61cf96ff14 2012-11-26 12:58:47 From: Marek Rosa Date: 2012-11-26 12:58:47 Subject: [PATCH] ChartViewer: added logaxes charts --- diff --git a/demos/chartviewer/charts/axis/barcategoryaxisxlogy.cpp b/demos/chartviewer/charts/axis/barcategoryaxisxlogy.cpp new file mode 100644 index 0000000..bd65654 --- /dev/null +++ b/demos/chartviewer/charts/axis/barcategoryaxisxlogy.cpp @@ -0,0 +1,81 @@ +/**************************************************************************** +** +** 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 "qbarseries.h" +#include "qbarset.h" +#include "qlogvalueaxis.h" +#include "qbarcategoryaxis.h" + +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/demos/chartviewer/charts/axis/barcategoryaxisylogx.cpp b/demos/chartviewer/charts/axis/barcategoryaxisylogx.cpp new file mode 100644 index 0000000..3b76b46 --- /dev/null +++ b/demos/chartviewer/charts/axis/barcategoryaxisylogx.cpp @@ -0,0 +1,81 @@ +/**************************************************************************** +** +** 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 "qhorizontalbarseries.h" +#include "qbarset.h" +#include "qlogvalueaxis.h" +#include "qbarcategoryaxis.h" + +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/demos/chartviewer/charts/axis/logvalueaxisx.cpp b/demos/chartviewer/charts/axis/logvalueaxisx.cpp new file mode 100644 index 0000000..ec59df8 --- /dev/null +++ b/demos/chartviewer/charts/axis/logvalueaxisx.cpp @@ -0,0 +1,76 @@ +/**************************************************************************** +** +** 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 "qlineseries.h" +#include "qlogvalueaxis.h" +#include "qcategoryaxis.h" + +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/demos/chartviewer/charts/axis/logvalueaxisy.cpp b/demos/chartviewer/charts/axis/logvalueaxisy.cpp new file mode 100644 index 0000000..a434488 --- /dev/null +++ b/demos/chartviewer/charts/axis/logvalueaxisy.cpp @@ -0,0 +1,76 @@ +/**************************************************************************** +** +** 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 "qlineseries.h" +#include "qlogvalueaxis.h" +#include "qcategoryaxis.h" + +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/demos/chartviewer/charts/charts.pri b/demos/chartviewer/charts/charts.pri index 88d455c..13321ef 100644 --- a/demos/chartviewer/charts/charts.pri +++ b/demos/chartviewer/charts/charts.pri @@ -15,9 +15,13 @@ SOURCES += \ $$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 \ diff --git a/src/barchart/vertical/bar/barchartitem.cpp b/src/barchart/vertical/bar/barchartitem.cpp index 2029d32..1ef0259 100644 --- a/src/barchart/vertical/bar/barchartitem.cpp +++ b/src/barchart/vertical/bar/barchartitem.cpp @@ -66,14 +66,14 @@ QVector BarChartItem::calculateLayout() layout.append(rect); bar->setPen(barSet->m_pen); bar->setBrush(barSet->m_brush); - if (qFuzzyCompare(rectHeight, 0)) + if (qFuzzyIsNull(rectHeight)) bar->setVisible(false); else bar->setVisible(barsVisible); QGraphicsSimpleTextItem *label = m_labels.at(itemIndex); - if (!qFuzzyCompare(barSet->value(category), 0)) + if (!qFuzzyIsNull(barSet->value(category))) label->setText(QString::number(barSet->value(category))); else label->setText(QString("")); diff --git a/src/barchart/vertical/percent/percentbarchartitem.cpp b/src/barchart/vertical/percent/percentbarchartitem.cpp index 5d98b90..5690928 100644 --- a/src/barchart/vertical/percent/percentbarchartitem.cpp +++ b/src/barchart/vertical/percent/percentbarchartitem.cpp @@ -63,7 +63,7 @@ QVector PercentBarChartItem::calculateLayout() Bar *bar = m_bars.at(itemIndex); bar->setPen(barSet->m_pen); bar->setBrush(barSet->m_brush); - if (qFuzzyCompare(rectHeight, 0)) + if (qFuzzyIsNull(rectHeight)) bar->setVisible(false); else bar->setVisible(barsVisible); @@ -73,7 +73,7 @@ QVector PercentBarChartItem::calculateLayout() QGraphicsSimpleTextItem *label = m_labels.at(itemIndex); - if (!qFuzzyCompare(m_series->d_func()->valueAt(set, category), 0)) { + if (!qFuzzyIsNull(m_series->d_func()->valueAt(set, category))) { int p = m_series->d_func()->percentageAt(set, category) * 100; QString vString(QString::number(p)); vString.truncate(3); diff --git a/src/barchart/vertical/stacked/stackedbarchartitem.cpp b/src/barchart/vertical/stacked/stackedbarchartitem.cpp index 73244cf..ccc6f6f 100644 --- a/src/barchart/vertical/stacked/stackedbarchartitem.cpp +++ b/src/barchart/vertical/stacked/stackedbarchartitem.cpp @@ -61,14 +61,14 @@ QVector StackedBarChartItem::calculateLayout() Bar *bar = m_bars.at(itemIndex); bar->setPen(barSet->m_pen); bar->setBrush(barSet->m_brush); - if (qFuzzyCompare(rectHeight, 0)) + if (qFuzzyIsNull(rectHeight)) bar->setVisible(false); else bar->setVisible(barsVisible); QGraphicsSimpleTextItem *label = m_labels.at(itemIndex); - if (!qFuzzyCompare(barSet->value(category), 0)) + if (!qFuzzyIsNull(barSet->value(category))) label->setText(QString::number(barSet->value(category))); else label->setText(QString(""));