Skip to content

File GridNode.hpp

File List > grid > GridNode.hpp

Go to the documentation of this file

//
// SPDX-FileCopyrightText: 2026 Michal Grabarczyk
// SPDX-License-Identifier: GPL-3.0-only WITH Universal-FOSS-exception-1.0
//
// This file is also available under a separate commercial license.
// See COMMERCIAL-LICENSING.md for contact information.
//
#pragma once

#include <QColor>
#include <QRectF>
#include <QSGNode>
#include <QVector>

#include <functional>

namespace QAccelPlot {

class Axis;
class Grid;

class GridNode : public QSGNode {
public:
    explicit GridNode();

    void update(const Grid* grid, const Axis* xAxis, const Axis* yAxis, const QRectF& plotRect);

private:
    // Groups the orientation-specific inputs so the shared loop logic in
    // collectAxisGridLines() can handle both vertical and horizontal grid lines.
    struct GridLineCollectionParams {
        const Axis* axis;
        bool gridLinesVisible;
        bool subGridLinesVisible;
        // makeRect(dataValue, halfLineWidth) -> the QRectF to add for that grid line
        std::function<QRectF(qreal dataValue, qreal halfWidth)> makeRect;
    };

    void collectGridLines(QVector<QRectF>& mainRects, QVector<QRectF>& subRects, const Grid* grid, const Axis* xAxis, const Axis* yAxis) const;
    void collectAxisGridLines(QVector<QRectF>& mainRects, QVector<QRectF>& subRects, const Grid* grid, const GridLineCollectionParams& p) const;

    QRectF plotRect_;
    QSGGeometryNode* subGridNode_;
    QSGGeometryNode* mainGridNode_;
};

} // namespace QAccelPlot