Commit c4d0d33d authored by Volker Krause's avatar Volker Krause
Browse files

Add UI infrastructure for singluar charts

parent 34a0761f
......@@ -53,6 +53,7 @@ AnalyticsView::AnalyticsView(QWidget* parent) :
ui->aggregatedDataView->setModel(m_aggregatedDataModel);
m_timeAggregationModel->setSourceModel(m_dataModel);
connect(m_timeAggregationModel, &QAbstractItemModel::modelReset, this, &AnalyticsView::updateTimeSliderRange);
ui->actionAggregateYear->setData(TimeAggregationModel::AggregateYear);
ui->actionAggregateMonth->setData(TimeAggregationModel::AggregateMonth);
......@@ -108,7 +109,10 @@ AnalyticsView::AnalyticsView(QWidget* parent) :
AnalyticsView::~AnalyticsView()
{
disconnect(ui->chartView->chart(), &QObject::destroyed, this, &AnalyticsView::updateChart);
if (ui->singularChartView->chart())
disconnect(ui->singularChartView->chart(), &QObject::destroyed, this, &AnalyticsView::updateChart);
if (ui->timelineChartView->chart())
disconnect(ui->timelineChartView->chart(), &QObject::destroyed, this, &AnalyticsView::updateChart);
QSettings settings;
settings.beginGroup(QStringLiteral("Analytics"));
......@@ -173,17 +177,27 @@ void AnalyticsView::updateChart()
if (!aggr)
return;
if (ui->chartView->chart())
disconnect(ui->chartView->chart(), &QObject::destroyed, this, &AnalyticsView::updateChart);
if (ui->singularChartView->chart())
disconnect(ui->singularChartView->chart(), &QObject::destroyed, this, &AnalyticsView::updateChart);
if (ui->timelineChartView->chart())
disconnect(ui->timelineChartView->chart(), &QObject::destroyed, this, &AnalyticsView::updateChart);
if (ui->actionTimelineChart->isChecked()) {
ui->chartView->setChart(aggr->timelineChart());
ui->timelineChartView->setChart(aggr->timelineChart());
connect(ui->timelineChartView->chart(), &QObject::destroyed, this, &AnalyticsView::updateChart);
ui->chartStack->setCurrentWidget(ui->timelinePage);
} else if (ui->actionSingularChart->isChecked()) {
ui->chartView->setChart(aggr->singlularChart());
ui->singularChartView->setChart(aggr->singlularChart());
connect(ui->singularChartView->chart(), &QObject::destroyed, this, &AnalyticsView::updateChart);
ui->chartStack->setCurrentWidget(ui->singularPage);
}
}
if (ui->chartView->chart())
connect(ui->chartView->chart(), &QObject::destroyed, this, &AnalyticsView::updateChart);
void AnalyticsView::updateTimeSliderRange()
{
qDebug() << m_timeAggregationModel->rowCount() << ui->timeSlider->maximum() << ui->timeSlider->minimum();
if (m_timeAggregationModel->rowCount() > 0)
ui->timeSlider->setRange(0, m_timeAggregationModel->rowCount() - 1);
}
Aggregator* AnalyticsView::createAggregator(const Aggregation& aggr) const
......
......@@ -57,6 +57,7 @@ signals:
private:
void chartSelected();
void updateChart();
void updateTimeSliderRange();
Aggregator* createAggregator(const Aggregation &aggr) const;
......
......@@ -51,10 +51,59 @@
</layout>
</item>
<item>
<widget class="QtCharts::QChartView" name="chartView">
<property name="renderHints">
<set>QPainter::Antialiasing|QPainter::TextAntialiasing</set>
<widget class="QStackedWidget" name="chartStack">
<property name="currentIndex">
<number>0</number>
</property>
<widget class="QWidget" name="timelinePage">
<layout class="QVBoxLayout" name="verticalLayout_2">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QtCharts::QChartView" name="timelineChartView">
<property name="renderHints">
<set>QPainter::Antialiasing|QPainter::TextAntialiasing</set>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="singularPage">
<layout class="QVBoxLayout" name="verticalLayout_3">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QtCharts::QChartView" name="singularChartView"/>
</item>
<item>
<widget class="QSlider" name="timeSlider">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
</item>
</layout>
......
......@@ -38,7 +38,7 @@ Aggregator::ChartModes CategoryAggregator::chartModes() const
{
Aggregator::ChartModes modes = None;
if (aggregation().elements().size() == 1)
modes |= Timeline;
modes |= Timeline | Singular;
return modes;
}
......@@ -103,3 +103,16 @@ QtCharts::QChart* CategoryAggregator::timelineChart()
return m_timelineChart.get();
}
QtCharts::QChart* CategoryAggregator::singlularChart()
{
if (m_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);
// TODO
return m_singlularChart.get();
}
......@@ -37,10 +37,12 @@ public:
QString displayName() const override;
QAbstractItemModel* timeAggregationModel() override;
QtCharts::QChart* timelineChart() override;
QtCharts::QChart* singlularChart() override;
private:
std::unique_ptr<CategoryAggregationModel> m_model;
std::unique_ptr<QtCharts::QChart> m_timelineChart;
std::unique_ptr<QtCharts::QChart> m_singlularChart;
};
}}
......
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