mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
statistics: collect colors in a StatsTheme class
To enable rudimentary theming, collect all colors in a new theme class. The class has to be passed down to the various items. In general the items save a reference to the them in the constructor. Alternatively, they might also just query the StatsView everytime they need to access a color. For now, it's hard the say what is preferred: a reference per item or a function call per invokation? Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
56e02dbcc0
commit
b5aac29cea
25 changed files with 272 additions and 166 deletions
|
@ -35,6 +35,7 @@ static const double selectionLassoWidth = 2.0; // Border between title and char
|
|||
|
||||
StatsView::StatsView(QQuickItem *parent) : QQuickItem(parent),
|
||||
backgroundDirty(true),
|
||||
currentTheme(statsThemes[0]),
|
||||
highlightedSeries(nullptr),
|
||||
xAxis(nullptr),
|
||||
yAxis(nullptr),
|
||||
|
@ -99,7 +100,7 @@ void StatsView::mousePressEvent(QMouseEvent *event)
|
|||
if (selectionRect)
|
||||
deleteChartItem(selectionRect); // Ooops. Already a selection in place.
|
||||
dragStartMouse = pos;
|
||||
selectionRect = createChartItem<ChartRectLineItem>(ChartZValue::Selection, selectionLassoColor, selectionLassoWidth);
|
||||
selectionRect = createChartItem<ChartRectLineItem>(ChartZValue::Selection, currentTheme->selectionLassoColor, selectionLassoWidth);
|
||||
selectionModifier = modifier;
|
||||
oldSelection = modifier.ctrl ? getDiveSelection() : std::vector<dive *>();
|
||||
grabMouse();
|
||||
|
@ -143,7 +144,7 @@ RootNode::RootNode(StatsView &view) : view(view)
|
|||
// also be done on the widget level, but would have to be done
|
||||
// separately for desktop and mobile, so do it here.
|
||||
backgroundNode.reset(view.w()->createRectangleNode());
|
||||
backgroundNode->setColor(backgroundColor);
|
||||
backgroundNode->setColor(view.getCurrentTheme().backgroundColor);
|
||||
appendChildNode(backgroundNode.get());
|
||||
|
||||
for (auto &zNode: zNodes) {
|
||||
|
@ -184,7 +185,7 @@ QSGNode *StatsView::updatePaintNode(QSGNode *oldNode, QQuickItem::UpdatePaintNod
|
|||
}
|
||||
|
||||
for (ChartItem *item = dirtyItems.first; item; item = item->next) {
|
||||
item->render();
|
||||
item->render(*currentTheme);
|
||||
item->dirty = false;
|
||||
}
|
||||
dirtyItems.splice(cleanItems);
|
||||
|
@ -299,6 +300,18 @@ QQuickWindow *StatsView::w() const
|
|||
return window();
|
||||
}
|
||||
|
||||
void StatsView::setTheme(int idx)
|
||||
{
|
||||
idx = std::clamp(idx, 0, (int)statsThemes.size() - 1);
|
||||
currentTheme = statsThemes[idx];
|
||||
rootNode->backgroundNode->setColor(currentTheme->backgroundColor);
|
||||
}
|
||||
|
||||
const StatsTheme &StatsView::getCurrentTheme() const
|
||||
{
|
||||
return *currentTheme;
|
||||
}
|
||||
|
||||
QSizeF StatsView::size() const
|
||||
{
|
||||
return boundingRect().size();
|
||||
|
@ -459,7 +472,7 @@ void StatsView::setTitle(const QString &s)
|
|||
return;
|
||||
}
|
||||
title = createChartItem<ChartTextItem>(ChartZValue::Legend, titleFont, s);
|
||||
title->setColor(darkLabelColor);
|
||||
title->setColor(currentTheme->darkLabelColor);
|
||||
}
|
||||
|
||||
void StatsView::updateTitlePos()
|
||||
|
@ -1128,10 +1141,10 @@ void StatsView::plotHistogramCountChart(const std::vector<dive *> &dives,
|
|||
if (categoryVariable->type() == StatsVariable::Type::Numeric) {
|
||||
double mean = categoryVariable->mean(dives);
|
||||
if (!std::isnan(mean))
|
||||
meanMarker = createChartItem<HistogramMarker>(mean, isHorizontal, meanMarkerColor, xAxis, yAxis);
|
||||
meanMarker = createChartItem<HistogramMarker>(mean, isHorizontal, currentTheme->meanMarkerColor, xAxis, yAxis);
|
||||
double median = categoryVariable->quartiles(dives).q2;
|
||||
if (!std::isnan(median))
|
||||
medianMarker = createChartItem<HistogramMarker>(median, isHorizontal, medianMarkerColor, xAxis, yAxis);
|
||||
medianMarker = createChartItem<HistogramMarker>(median, isHorizontal, currentTheme->medianMarkerColor, xAxis, yAxis);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue