File indexing completed on 2024-05-19 15:27:23

0001 /*
0002  * Copyright (C) 2001-2015 Klaralvdalens Datakonsult AB.  All rights reserved.
0003  *
0004  * This file is part of the KD Chart library.
0005  *
0006  * This program is free software; you can redistribute it and/or
0007  * modify it under the terms of the GNU General Public License as
0008  * published by the Free Software Foundation; either version 2 of
0009  * the License, or (at your option) any later version.
0010  *
0011  * This program is distributed in the hope that it will be useful,
0012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0014  * GNU General Public License for more details.
0015  *
0016  * You should have received a copy of the GNU General Public License
0017  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
0018  */
0019 
0020 #ifndef KCHARTCHART_P_H
0021 #define KCHARTCHART_P_H
0022 
0023 //
0024 //  W A R N I N G
0025 //  -------------
0026 //
0027 // This file is not part of the KD Chart API.  It exists purely as an
0028 // implementation detail.  This header file may change from version to
0029 // version without notice, or even be removed.
0030 //
0031 // We mean it.
0032 //
0033 
0034 #include <QObject>
0035 #include <QHBoxLayout>
0036 #include <QVBoxLayout>
0037 
0038 #include "KChartChart.h"
0039 #include "KChartAbstractArea.h"
0040 #include "KChartTextArea.h"
0041 #include "KChartFrameAttributes.h"
0042 #include "KChartBackgroundAttributes.h"
0043 #include "KChartLayoutItems.h"
0044 #include "KChartMath_p.h"
0045 
0046 
0047 namespace KChart {
0048 
0049 class AbstractAreaWidget;
0050 class CartesianAxis;
0051 
0052 /*
0053   struct PlaneInfo can't be declared inside Chart::Private, otherwise MSVC.net says:
0054   qhash.h(195) : error C2248: 'KChart::Chart::Private' : cannot access protected class declared in class 'KChart::Chart'
0055   KChartChart_p.h(58) : see declaration of 'KChart::Chart::Private'
0056   KChartChart.h(61) : see declaration of 'KChart::Chart'
0057   KChartChart.cpp(262) : see reference to class template instantiation 'QHash<Key,T>' being compiled, with
0058             Key=KChart::AbstractCoordinatePlane *,
0059             T=KChart::Chart::Private::PlaneInfo
0060 */
0061 /**
0062  * \internal
0063  */
0064 struct PlaneInfo {
0065     PlaneInfo()
0066         : referencePlane( nullptr ),
0067           horizontalOffset( 1 ),
0068           verticalOffset( 1 ),
0069           gridLayout( nullptr ),
0070           topAxesLayout( nullptr ),
0071           bottomAxesLayout( nullptr ),
0072           leftAxesLayout( nullptr ),
0073           rightAxesLayout( nullptr )
0074     {}
0075     AbstractCoordinatePlane *referencePlane;
0076     int horizontalOffset;
0077     int verticalOffset;
0078     QGridLayout* gridLayout;
0079     QVBoxLayout* topAxesLayout;
0080     QVBoxLayout* bottomAxesLayout;
0081     QHBoxLayout* leftAxesLayout;
0082     QHBoxLayout* rightAxesLayout;
0083 };
0084 
0085 struct LayoutGraphNode
0086 {
0087     LayoutGraphNode()
0088         : diagramPlane( nullptr )
0089         , leftSuccesor( nullptr )
0090         , bottomSuccesor( nullptr )
0091         , sharedSuccesor( nullptr )
0092         , gridLayout( nullptr )
0093         , topAxesLayout( false )
0094         , bottomAxesLayout( false )
0095         , leftAxesLayout( false )
0096         , rightAxesLayout( false )
0097         , priority( -1 )
0098     {}
0099     AbstractCoordinatePlane* diagramPlane;
0100     LayoutGraphNode* leftSuccesor;
0101     LayoutGraphNode* bottomSuccesor;
0102     LayoutGraphNode* sharedSuccesor;
0103     QGridLayout* gridLayout;
0104     bool topAxesLayout;
0105     bool bottomAxesLayout;
0106     bool leftAxesLayout;
0107     bool rightAxesLayout;
0108     int priority;
0109     bool operator<( const LayoutGraphNode &other ) const
0110     {
0111         return priority < other.priority;
0112     }
0113 };
0114 
0115 
0116 /**
0117  * \internal
0118  */
0119 class Q_DECL_HIDDEN Chart::Private : public QObject
0120 {
0121     Q_OBJECT
0122     public:
0123         Chart* chart;
0124 
0125         enum AxisType { Abscissa, Ordinate };
0126         bool useNewLayoutSystem;
0127         CoordinatePlaneList coordinatePlanes;
0128         HeaderFooterList headerFooters;
0129         LegendList legends;
0130 
0131         QHBoxLayout* layout;
0132         QVBoxLayout* vLayout;
0133         QBoxLayout*  planesLayout;
0134         QGridLayout* gridPlaneLayout;
0135         QGridLayout* headerLayout;
0136         QGridLayout* footerLayout;
0137         QGridLayout* dataAndLegendLayout;
0138         QSpacerItem* leftOuterSpacer;
0139         QSpacerItem* rightOuterSpacer;
0140         QSpacerItem* topOuterSpacer;
0141         QSpacerItem* bottomOuterSpacer;
0142 
0143         QVBoxLayout* innerHdFtLayouts[2][3][3];
0144 
0145         QVector<KChart::TextArea*> textLayoutItems;
0146         QVector<KChart::AbstractLayoutItem*> planeLayoutItems;
0147         QVector<KChart::Legend*> legendLayoutItems;
0148 
0149         QSize overrideSize;
0150         bool isFloatingLegendsLayoutDirty;
0151         bool isPlanesLayoutDirty;
0152 
0153         // since we do not want to derive Chart from AbstractAreaBase, we store the attributes
0154         // here and call two static painting methods to draw the background and frame.
0155         KChart::FrameAttributes frameAttributes;
0156         KChart::BackgroundAttributes backgroundAttributes;
0157 
0158         // ### wrong names, "leading" means inter-line distance of text. spacing? margin?
0159         int globalLeadingLeft, globalLeadingRight, globalLeadingTop, globalLeadingBottom;
0160 
0161         QList< AbstractCoordinatePlane* > mouseClickedPlanes;
0162 
0163         Qt::LayoutDirection layoutDirection;
0164 
0165         Private( Chart* );
0166 
0167         virtual ~Private();
0168 
0169         void createLayouts();
0170         void updateDirtyLayouts();
0171         void reapplyInternalLayouts(); // TODO: see if this can be merged with updateDirtyLayouts()
0172         void paintAll( QPainter* painter );
0173 
0174         struct AxisInfo {
0175             AxisInfo()
0176                 :plane(nullptr)
0177             {}
0178             AbstractCoordinatePlane *plane;
0179         };
0180         QHash<AbstractCoordinatePlane*, PlaneInfo> buildPlaneLayoutInfos();
0181         QVector< LayoutGraphNode* > buildPlaneLayoutGraph();
0182 
0183     public Q_SLOTS:
0184         void slotLayoutPlanes();
0185         void slotResizePlanes();
0186         void slotLegendPositionChanged( AbstractAreaWidget* legend );
0187         void slotHeaderFooterPositionChanged( HeaderFooter* hf );
0188         void slotUnregisterDestroyedLegend( Legend * legend );
0189         void slotUnregisterDestroyedHeaderFooter( HeaderFooter* headerFooter );
0190         void slotUnregisterDestroyedPlane( AbstractCoordinatePlane* plane );
0191 };
0192 
0193 }
0194 
0195 #endif