Commit 790dac48 authored by Volker Krause's avatar Volker Krause
Browse files

Refactor duplicated chart theming code

parent 4ac8b4b7
......@@ -43,6 +43,7 @@ set(analyzer_srcs
analytics/aggregator.cpp
analytics/analyticsview.cpp
analytics/categoryaggregator.cpp
analytics/chartutil.cpp
analytics/numericaggregator.cpp
analytics/ratiosetaggregator.cpp
analytics/totalaggregator.cpp
......
......@@ -16,6 +16,7 @@
*/
#include "categoryaggregator.h"
#include "chartutil.h"
#include <model/categoryaggregationmodel.h>
#include <model/extrarowsproxymodel.h>
......@@ -31,8 +32,6 @@
#include <QtCharts/QValueAxis>
#include <QtCharts/QVXYModelMapper>
#include <QApplication>
using namespace UserFeedback::Analyzer;
using namespace QtCharts;
......@@ -73,7 +72,7 @@ QtCharts::QChart* CategoryAggregator::timelineChart()
return m_timelineChart.get();
m_timelineChart.reset(new QChart);
m_timelineChart->setTheme(qApp->palette().color(QPalette::Window).lightnessF() < 0.25 ? QChart::ChartThemeDark : QChart::ChartThemeLight);
ChartUtil::applyTheme(m_timelineChart.get());
auto xAxis = new QDateTimeAxis(m_timelineChart.get());
xAxis->setFormat(QStringLiteral("yyyy-MM-dd")); // TODO, follow aggregation mode
auto yAxis = new QValueAxis(m_timelineChart.get());
......@@ -118,7 +117,7 @@ QtCharts::QChart* CategoryAggregator::singlularChart()
return m_singlularChart.get();
m_singlularChart.reset(new QChart);
m_singlularChart->setTheme(qApp->palette().color(QPalette::Window).lightnessF() < 0.25 ? QChart::ChartThemeDark : QChart::ChartThemeLight);
ChartUtil::applyTheme(m_singlularChart.get());
auto series = new QPieSeries(m_singlularChart.get());
auto mapper = new QHPieModelMapper(m_singlularChart.get());
......
/*
Copyright (C) 2017 Volker Krause <vkrause@kde.org>
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "chartutil.h"
#include <QtCharts/QChart>
#include <QApplication>
using namespace UserFeedback::Analyzer;
using namespace QtCharts;
void ChartUtil::applyTheme(QtCharts::QChart *chart)
{
chart->setTheme(qApp->palette().color(QPalette::Window).lightnessF() < 0.25 ? QChart::ChartThemeDark : QChart::ChartThemeLight);
}
/*
Copyright (C) 2017 Volker Krause <vkrause@kde.org>
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef USERFEEDBACK_ANALYZER_CHARTUTIL_H
#define USERFEEDBACK_ANALYZER_CHARTUTIL_H
namespace QtCharts {
class QChart;
}
namespace UserFeedback {
namespace Analyzer {
namespace ChartUtil
{
void applyTheme(QtCharts::QChart *chart);
}
}}
#endif // USERFEEDBACK_ANALYZER_CHARTUTIL_H
......@@ -16,6 +16,7 @@
*/
#include "numericaggregator.h"
#include "chartutil.h"
#include <model/numericaggregationmodel.h>
#include <model/timeaggregationmodel.h>
......@@ -26,9 +27,6 @@
#include <QtCharts/QHBoxPlotModelMapper>
#include <QtCharts/QValueAxis>
#include <QApplication>
#include <QDateTime>
using namespace UserFeedback::Analyzer;
using namespace QtCharts;
......@@ -69,7 +67,7 @@ QtCharts::QChart* NumericAggregator::timelineChart()
return m_timelineChart.get();
m_timelineChart.reset(new QChart);
m_timelineChart->setTheme(qApp->palette().color(QPalette::Window).lightnessF() < 0.25 ? QChart::ChartThemeDark : QChart::ChartThemeLight);
ChartUtil::applyTheme(m_timelineChart.get());
auto xAxis = new QBarCategoryAxis(m_timelineChart.get());
auto yAxis = new QValueAxis(m_timelineChart.get());
m_timelineChart->addAxis(xAxis, Qt::AlignBottom);
......
......@@ -16,6 +16,7 @@
*/
#include "ratiosetaggregator.h"
#include "chartutil.h"
#include <model/ratiosetaggregationmodel.h>
......@@ -26,8 +27,6 @@
#include <QtCharts/QValueAxis>
#include <QtCharts/QVXYModelMapper>
#include <QApplication>
using namespace UserFeedback::Analyzer;
using namespace QtCharts;
......@@ -68,7 +67,7 @@ QtCharts::QChart* RatioSetAggregator::timelineChart()
return m_timelineChart.get();
m_timelineChart.reset(new QChart);
m_timelineChart->setTheme(qApp->palette().color(QPalette::Window).lightnessF() < 0.25 ? QChart::ChartThemeDark : QChart::ChartThemeLight);
ChartUtil::applyTheme(m_timelineChart.get());
auto xAxis = new QDateTimeAxis(m_timelineChart.get());
xAxis->setFormat(QStringLiteral("yyyy-MM-dd")); // TODO, follow aggregation mode
auto yAxis = new QValueAxis(m_timelineChart.get());
......
......@@ -16,6 +16,7 @@
*/
#include "totalaggregator.h"
#include "chartutil.h"
#include <QtCharts/QChart>
#include <QtCharts/QDateTimeAxis>
......@@ -23,7 +24,6 @@
#include <QtCharts/QValueAxis>
#include <QtCharts/QVXYModelMapper>
#include <QApplication>
#include <QAbstractItemModel>
#include <numeric>
......@@ -59,7 +59,7 @@ QtCharts::QChart* TotalAggregator::timelineChart()
}, Qt::UniqueConnection);
m_timelineChart.reset(new QChart);
m_timelineChart->setTheme(qApp->palette().color(QPalette::Window).lightnessF() < 0.25 ? QChart::ChartThemeDark : QChart::ChartThemeLight);
ChartUtil::applyTheme(m_timelineChart.get());
auto xAxis = new QDateTimeAxis(m_timelineChart.get());
xAxis->setFormat(QStringLiteral("yyyy-MM-dd")); // TODO, follow aggregation mode
auto yAxis = new QValueAxis(m_timelineChart.get());
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment