##// END OF EJS Templates
ChartViewer: added logaxes charts
Marek Rosa -
r2279:344c3d3c2742
parent child
Show More
@@ -0,0 +1,81
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
21 #include "charts.h"
22 #include "qchart.h"
23 #include "qbarseries.h"
24 #include "qbarset.h"
25 #include "qlogvalueaxis.h"
26 #include "qbarcategoryaxis.h"
27
28 class BarCategoryAxisXLogY: public Chart
29 {
30 public:
31 QString name() { return "AxisX"; }
32 QString category() { return QObject::tr("Axis"); }
33 QString subCategory() { return "BarCategoryAxis"; }
34
35 QChart *createChart(const DataTable &table)
36 {
37 QChart *chart = new QChart();
38 chart->setTitle(" BarCateogry X , LogValue Y");
39
40 QString name("Series ");
41 QBarSeries *series = new QBarSeries(chart);
42 QLogValueAxis *logvalueaxis = new QLogValueAxis();
43 logvalueaxis->setBase(2);
44 QBarCategoryAxis *barcategory = new QBarCategoryAxis();
45 for (int i(0); i < table.count(); i++) {
46 QBarSet *set = new QBarSet("Bar set " + QString::number(i));
47 foreach (Data data, table[i])
48 *set << data.first.y();
49 series->append(set);
50 }
51 chart->addSeries(series);
52
53 int count = series->barSets().first()->count();
54
55
56 for (int i = 0; i < count; i++) {
57 barcategory->append("BarSet " + QString::number(i));
58 }
59
60 chart->setAxisY(logvalueaxis, series);
61 chart->setAxisX(barcategory, series);
62
63 return chart;
64 }
65 };
66
67 class BarCategoryAxisXLogYTitle: public BarCategoryAxisXLogY
68 {
69 QString name() { return "AxisX Title"; }
70 QChart *createChart(const DataTable &table)
71 {
72 QChart *chart = BarCategoryAxisXLogY::createChart(table);
73 chart->axisX()->setTitleText("Axis X");
74 chart->axisY()->setTitleText("Axis Y");
75 chart->setTitle(" BarCateogry X , LogValue Y, title");
76 return chart;
77 }
78 };
79
80 DECLARE_CHART(BarCategoryAxisXLogY);
81 DECLARE_CHART(BarCategoryAxisXLogYTitle);
@@ -0,0 +1,81
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
21 #include "charts.h"
22 #include "qchart.h"
23 #include "qhorizontalbarseries.h"
24 #include "qbarset.h"
25 #include "qlogvalueaxis.h"
26 #include "qbarcategoryaxis.h"
27
28 class BarCategoryAxisYLogX: public Chart
29 {
30 public:
31 QString name() { return "AxisY"; }
32 QString category() { return QObject::tr("Axis"); }
33 QString subCategory() { return "BarCategoryAxis"; }
34
35 QChart *createChart(const DataTable &table)
36 {
37 QChart *chart = new QChart();
38 chart->setTitle(" LogValue X , BarCateogry Y");
39
40 QString name("Series ");
41 QHorizontalBarSeries *series = new QHorizontalBarSeries(chart);
42 QLogValueAxis *logvalueaxis = new QLogValueAxis();
43 logvalueaxis->setBase(2);
44 QBarCategoryAxis *barcategory = new QBarCategoryAxis();
45 for (int i(0); i < table.count(); i++) {
46 QBarSet *set = new QBarSet("Bar set " + QString::number(i));
47 foreach (Data data, table[i])
48 *set << data.first.y();
49 series->append(set);
50 }
51 chart->addSeries(series);
52
53 int count = series->barSets().first()->count();
54
55
56 for (int i = 0; i < count; i++) {
57 barcategory->append("BarSet " + QString::number(i));
58 }
59
60 chart->setAxisX(logvalueaxis, series);
61 chart->setAxisY(barcategory, series);
62
63 return chart;
64 }
65 };
66
67 class BarCategoryAxisYLogXTitle: public BarCategoryAxisYLogX
68 {
69 QString name() { return "AxisX Title"; }
70 QChart *createChart(const DataTable &table)
71 {
72 QChart *chart = BarCategoryAxisYLogX::createChart(table);
73 chart->axisX()->setTitleText("Axis X");
74 chart->axisY()->setTitleText("Axis Y");
75 chart->setTitle(" LogValue X , BarCateogry Y, title");
76 return chart;
77 }
78 };
79
80 DECLARE_CHART(BarCategoryAxisYLogX);
81 DECLARE_CHART(BarCategoryAxisYLogXTitle);
@@ -0,0 +1,76
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
21 #include "charts.h"
22 #include "qchart.h"
23 #include "qlineseries.h"
24 #include "qlogvalueaxis.h"
25 #include "qcategoryaxis.h"
26
27 class LogValueAxisX: public Chart
28 {
29 public:
30 QString name() { return "LogValueAxisX"; }
31 QString category() { return QObject::tr("Axis"); }
32 QString subCategory() { return QObject::tr("Log"); }
33
34 QChart *createChart(const DataTable &table)
35 {
36 QChart *chart = new QChart();
37 chart->setTitle("LogValue X , Value Y");
38
39 QString name("Series ");
40 int nameIndex = 0;
41 foreach (DataList list, table) {
42 QLineSeries *series = new QLineSeries(chart);
43 foreach (Data data, list)
44 series->append(data.first);
45 series->setName(name + QString::number(nameIndex));
46 nameIndex++;
47 chart->addSeries(series);
48 }
49
50 chart->createDefaultAxes();
51 QLogValueAxis *axis = new QLogValueAxis();
52 axis->setBase(1.2);
53 foreach (QAbstractSeries *series, chart->series())
54 chart->setAxisX(axis, series);
55
56 return chart;
57 }
58 };
59
60 class LogValueAxisTitleX: public LogValueAxisX
61 {
62 public:
63 QString name() { return "LogValueAxisXTitle"; }
64
65 QChart *createChart(const DataTable &table)
66 {
67 QChart *chart = LogValueAxisX::createChart(table);
68 chart->axisX()->setTitleText("Axis X");
69 chart->axisY()->setTitleText("Axis Y");
70 chart->setTitle("Log Value X , Value Y, title");
71 return chart;
72 }
73 };
74
75 DECLARE_CHART(LogValueAxisX);
76 DECLARE_CHART(LogValueAxisTitleX);
@@ -0,0 +1,76
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
21 #include "charts.h"
22 #include "qchart.h"
23 #include "qlineseries.h"
24 #include "qlogvalueaxis.h"
25 #include "qcategoryaxis.h"
26
27 class LogValueAxisY: public Chart
28 {
29 public:
30 QString name() { return "LogValueAxisY"; }
31 QString category() { return QObject::tr("Axis"); }
32 QString subCategory() { return QObject::tr("Log"); }
33
34 QChart *createChart(const DataTable &table)
35 {
36 QChart *chart = new QChart();
37 chart->setTitle("Value X , LogValue Y");
38
39 QString name("Series ");
40 int nameIndex = 0;
41 foreach (DataList list, table) {
42 QLineSeries *series = new QLineSeries(chart);
43 foreach (Data data, list)
44 series->append(data.first);
45 series->setName(name + QString::number(nameIndex));
46 nameIndex++;
47 chart->addSeries(series);
48 }
49
50 chart->createDefaultAxes();
51 QLogValueAxis *axis = new QLogValueAxis();
52 axis->setBase(2);
53 foreach (QAbstractSeries *series, chart->series())
54 chart->setAxisY(axis, series);
55
56 return chart;
57 }
58 };
59
60 class LogValueAxisTitleY: public LogValueAxisY
61 {
62 public:
63 QString name() { return "LogValueAxisYTitle"; }
64
65 QChart *createChart(const DataTable &table)
66 {
67 QChart *chart = LogValueAxisY::createChart(table);
68 chart->axisX()->setTitleText("Axis X");
69 chart->axisY()->setTitleText("Axis Y");
70 chart->setTitle("Value X , Log Value Y, title");
71 return chart;
72 }
73 };
74
75 DECLARE_CHART(LogValueAxisY);
76 DECLARE_CHART(LogValueAxisTitleY);
@@ -15,9 +15,13 SOURCES += \
15 15 $$PWD/pieseries/piechart.cpp \
16 16 $$PWD/pieseries/donutchart.cpp \
17 17 $$PWD/axis/valueaxis.cpp \
18 $$PWD/axis/logvalueaxisx.cpp \
19 $$PWD/axis/logvalueaxisy.cpp \
18 20 $$PWD/axis/categoryaxis.cpp \
19 21 $$PWD/axis/barcategoryaxisx.cpp \
20 22 $$PWD/axis/barcategoryaxisy.cpp \
23 $$PWD/axis/barcategoryaxisxlogy.cpp \
24 $$PWD/axis/barcategoryaxisylogx.cpp \
21 25 $$PWD/multiaxis/multivalueaxis.cpp \
22 26 $$PWD/multiaxis/multivalueaxis2.cpp \
23 27 $$PWD/multiaxis/multivalueaxis3.cpp \
@@ -66,14 +66,14 QVector<QRectF> BarChartItem::calculateLayout()
66 66 layout.append(rect);
67 67 bar->setPen(barSet->m_pen);
68 68 bar->setBrush(barSet->m_brush);
69 if (qFuzzyCompare(rectHeight, 0))
69 if (qFuzzyIsNull(rectHeight))
70 70 bar->setVisible(false);
71 71 else
72 72 bar->setVisible(barsVisible);
73 73
74 74 QGraphicsSimpleTextItem *label = m_labels.at(itemIndex);
75 75
76 if (!qFuzzyCompare(barSet->value(category), 0))
76 if (!qFuzzyIsNull(barSet->value(category)))
77 77 label->setText(QString::number(barSet->value(category)));
78 78 else
79 79 label->setText(QString(""));
@@ -63,7 +63,7 QVector<QRectF> PercentBarChartItem::calculateLayout()
63 63 Bar *bar = m_bars.at(itemIndex);
64 64 bar->setPen(barSet->m_pen);
65 65 bar->setBrush(barSet->m_brush);
66 if (qFuzzyCompare(rectHeight, 0))
66 if (qFuzzyIsNull(rectHeight))
67 67 bar->setVisible(false);
68 68 else
69 69 bar->setVisible(barsVisible);
@@ -73,7 +73,7 QVector<QRectF> PercentBarChartItem::calculateLayout()
73 73
74 74 QGraphicsSimpleTextItem *label = m_labels.at(itemIndex);
75 75
76 if (!qFuzzyCompare(m_series->d_func()->valueAt(set, category), 0)) {
76 if (!qFuzzyIsNull(m_series->d_func()->valueAt(set, category))) {
77 77 int p = m_series->d_func()->percentageAt(set, category) * 100;
78 78 QString vString(QString::number(p));
79 79 vString.truncate(3);
@@ -61,14 +61,14 QVector<QRectF> StackedBarChartItem::calculateLayout()
61 61 Bar *bar = m_bars.at(itemIndex);
62 62 bar->setPen(barSet->m_pen);
63 63 bar->setBrush(barSet->m_brush);
64 if (qFuzzyCompare(rectHeight, 0))
64 if (qFuzzyIsNull(rectHeight))
65 65 bar->setVisible(false);
66 66 else
67 67 bar->setVisible(barsVisible);
68 68
69 69 QGraphicsSimpleTextItem *label = m_labels.at(itemIndex);
70 70
71 if (!qFuzzyCompare(barSet->value(category), 0))
71 if (!qFuzzyIsNull(barSet->value(category)))
72 72 label->setText(QString::number(barSet->value(category)));
73 73 else
74 74 label->setText(QString(""));
General Comments 0
You need to be logged in to leave comments. Login now