File indexing completed on 2025-01-26 03:34:04

0001 /*
0002     File                 : BarPlotPrivate.h
0003     Project              : LabPlot
0004     Description          : Bar Plot - private implementation
0005     --------------------------------------------------------------------
0006     SPDX-FileCopyrightText: 2022 Alexander Semke <alexander.semke@web.de>
0007 
0008     SPDX-License-Identifier: GPL-2.0-or-later
0009 */
0010 
0011 #ifndef BARPLOTPRIVATE_H
0012 #define BARPLOTPRIVATE_H
0013 
0014 #include "backend/worksheet/plots/cartesian/BarPlot.h"
0015 #include "backend/worksheet/plots/cartesian/PlotPrivate.h"
0016 #include <QPen>
0017 
0018 class Background;
0019 class Line;
0020 class CartesianCoordinateSystem;
0021 class Value;
0022 class KConfigGroup;
0023 
0024 typedef QVector<QPointF> Points;
0025 
0026 class BarPlotPrivate : public PlotPrivate {
0027 public:
0028     explicit BarPlotPrivate(BarPlot*);
0029 
0030     void retransform() override;
0031     void recalc();
0032     virtual void recalcShapeAndBoundingRect() override;
0033     void updateValues();
0034     void updatePixmap();
0035 
0036     Background* addBackground(const KConfigGroup&);
0037     Line* addBorderLine(const KConfigGroup&);
0038     void addValue(const KConfigGroup&);
0039 
0040     BarPlot* const q;
0041 
0042     // General
0043     const AbstractColumn* xColumn{nullptr};
0044     QString xColumnPath;
0045     QVector<const AbstractColumn*> dataColumns;
0046     QVector<QString> dataColumnPaths;
0047     BarPlot::Type type{BarPlot::Type::Grouped};
0048     BarPlot::Orientation orientation{BarPlot::Orientation::Vertical};
0049     double widthFactor{1.0};
0050     qreal opacity{1.0};
0051 
0052     double xMin{0.};
0053     double xMax{1.};
0054     double yMin{0.};
0055     double yMax{1.};
0056 
0057     // bar properties
0058     QVector<Background*> backgrounds;
0059     QVector<Line*> borderLines;
0060 
0061     // values
0062     Value* value{nullptr};
0063 
0064 private:
0065     void paint(QPainter*, const QStyleOptionGraphicsItem*, QWidget* widget = nullptr) override;
0066 
0067     void recalc(int);
0068     void verticalBarPlot(int);
0069     void horizontalBarPlot(int);
0070     void updateFillingRect(int columnIndex, int valueIndex, const QVector<QLineF>&);
0071 
0072     void draw(QPainter*);
0073 
0074     QVector<QPointF> m_valuesPoints;
0075     QVector<QPointF> m_valuesPointsLogical;
0076     QVector<QString> m_valuesStrings;
0077     QPainterPath m_valuesPath;
0078 
0079     QVector<QVector<QVector<QLineF>>> m_barLines; // QVector<QLineF> contains four lines that are clipped on the plot rectangle
0080     QVector<QVector<QPolygonF>> m_fillPolygons; // polygons used for the filling (clipped versions of the boxes)
0081     QVector<double> m_stackedBarPositiveOffsets; // offsets for the y-positions for stacked bar plots, positive direction
0082     QVector<double> m_stackedBarNegativeOffsets; // offsets for the y-positions for stacked bar plots, negative direction
0083     QVector<double> m_stackedBar100PercentValues; // total sum of values in a stacked bar group defining the 100% value
0084     double m_widthScaleFactor{1.0};
0085     double m_groupWidth{1.0}; // width of a bar group
0086     double m_groupGap{0.0}; // gap around a group of bars
0087 };
0088 
0089 #endif