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