mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
stats: remove theme-access from QtQuick root node
To make the QtQuick code more general, remove the access to the StatsTheme, which only makes sense for the statistics module. Store the background color in a separate variable, since that will be needed by any potential users of the code. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
1a3bc9bf71
commit
845ac82b57
2 changed files with 13 additions and 5 deletions
|
@ -37,6 +37,7 @@ static const double selectionLassoWidth = 2.0; // Border between title and char
|
|||
StatsView::StatsView(QQuickItem *parent) : QQuickItem(parent),
|
||||
backgroundDirty(true),
|
||||
currentTheme(&getStatsTheme(false)),
|
||||
backgroundColor(currentTheme->backgroundColor),
|
||||
highlightedSeries(nullptr),
|
||||
xAxis(nullptr),
|
||||
yAxis(nullptr),
|
||||
|
@ -128,7 +129,7 @@ using ZNode = HideableQSGNode<QSGNode>;
|
|||
class RootNode : public QSGNode
|
||||
{
|
||||
public:
|
||||
RootNode(StatsView &view);
|
||||
RootNode(StatsView &view, QColor backgroundColor);
|
||||
~RootNode();
|
||||
StatsView &view;
|
||||
std::unique_ptr<QSGRectangleNode> backgroundNode; // solid background
|
||||
|
@ -136,13 +137,12 @@ public:
|
|||
std::array<std::unique_ptr<ZNode>, (size_t)ChartZValue::Count> zNodes;
|
||||
};
|
||||
|
||||
RootNode::RootNode(StatsView &view) : view(view)
|
||||
RootNode::RootNode(StatsView &view, QColor backgroundColor) : view(view)
|
||||
{
|
||||
// Add a background rectangle with a solid color. This could
|
||||
// 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(view.getCurrentTheme().backgroundColor);
|
||||
appendChildNode(backgroundNode.get());
|
||||
|
||||
for (auto &zNode: zNodes) {
|
||||
|
@ -172,7 +172,7 @@ QSGNode *StatsView::updatePaintNode(QSGNode *oldNode, QQuickItem::UpdatePaintNod
|
|||
// This is just a copy of what is found in Qt's documentation.
|
||||
RootNode *n = static_cast<RootNode *>(oldNode);
|
||||
if (!n)
|
||||
n = rootNode = new RootNode(*this);
|
||||
n = rootNode = new RootNode(*this, backgroundColor);
|
||||
|
||||
// Delete all chart items that are marked for deletion.
|
||||
freeDeletedChartItems();
|
||||
|
@ -298,10 +298,16 @@ QQuickWindow *StatsView::w() const
|
|||
return window();
|
||||
}
|
||||
|
||||
void StatsView::setBackgroundColor(QColor color)
|
||||
{
|
||||
backgroundColor = color;
|
||||
rootNode->backgroundNode->setColor(color);
|
||||
}
|
||||
|
||||
void StatsView::setTheme(bool dark)
|
||||
{
|
||||
currentTheme = &getStatsTheme(dark);
|
||||
rootNode->backgroundNode->setColor(currentTheme->backgroundColor);
|
||||
setBackgroundColor(currentTheme->backgroundColor);
|
||||
}
|
||||
|
||||
const StatsTheme &StatsView::getCurrentTheme() const
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue