KD Chart 2
[rev.2.5]
|
00001 /**************************************************************************** 00002 ** Copyright (C) 2001-2012 Klaralvdalens Datakonsult AB. All rights reserved. 00003 ** 00004 ** This file is part of the KD Chart library. 00005 ** 00006 ** Licensees holding valid commercial KD Chart licenses may use this file in 00007 ** accordance with the KD Chart Commercial License Agreement provided with 00008 ** the Software. 00009 ** 00010 ** 00011 ** This file may be distributed and/or modified under the terms of the 00012 ** GNU General Public License version 2 and version 3 as published by the 00013 ** Free Software Foundation and appearing in the file LICENSE.GPL.txt included. 00014 ** 00015 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 00016 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 00017 ** 00018 ** Contact info@kdab.com if any conditions of this licensing are not 00019 ** clear to you. 00020 ** 00021 **********************************************************************/ 00022 00023 #ifndef KDCHARTABSTRACTCOORDINATEPLANE_H 00024 #define KDCHARTABSTRACTCOORDINATEPLANE_H 00025 00026 #include <QObject> 00027 #include <QList> 00028 00029 #include "KDChartAbstractArea.h" 00030 #include "KDChartAbstractDiagram.h" 00031 #include "KDChartEnums.h" 00032 00033 namespace KDChart { 00034 00035 class Chart; 00036 class GridAttributes; 00037 class DataDimension; 00038 00039 typedef QList<DataDimension> DataDimensionsList; 00040 00044 class KDCHART_EXPORT AbstractCoordinatePlane : public AbstractArea 00045 { 00046 Q_OBJECT 00047 00048 Q_DISABLE_COPY( AbstractCoordinatePlane ) 00049 KDCHART_DECLARE_PRIVATE_DERIVED_PARENT( AbstractCoordinatePlane, Chart* ) 00050 00051 friend class AbstractGrid; 00052 00053 public: 00054 enum AxesCalcMode { Linear, Logarithmic }; 00055 00056 protected: 00057 explicit AbstractCoordinatePlane ( Chart* parent = 0 ); 00058 00059 public: 00060 virtual ~AbstractCoordinatePlane(); 00061 00068 virtual void addDiagram ( AbstractDiagram* diagram ); 00069 00087 virtual void replaceDiagram ( AbstractDiagram* diagram, AbstractDiagram* oldDiagram = 0 ); 00088 00097 virtual void takeDiagram( AbstractDiagram* diagram ); 00098 00102 AbstractDiagram* diagram(); 00103 00107 AbstractDiagramList diagrams(); 00108 00112 ConstAbstractDiagramList diagrams() const; 00113 00117 virtual void layoutDiagrams() = 0; 00118 00125 virtual const QPointF translate ( const QPointF& diagramPoint ) const = 0; 00126 00130 bool isRubberBandZoomingEnabled() const; 00131 00135 void setRubberBandZoomingEnabled( bool enable ); 00136 00141 virtual qreal zoomFactorX() const { return 1.0; } 00142 00147 virtual qreal zoomFactorY() const { return 1.0; } 00148 00153 virtual void setZoomFactors( qreal factorX, qreal factorY ) { Q_UNUSED( factorX ); Q_UNUSED( factorY ); } 00154 00160 virtual void setZoomFactorX( qreal factor ) { Q_UNUSED( factor ); } 00161 00167 virtual void setZoomFactorY( qreal factor ) { Q_UNUSED( factor ); } 00168 00173 virtual QPointF zoomCenter() const { return QPointF(0.0, 0.0); } 00174 00180 virtual void setZoomCenter( const QPointF& center ) { Q_UNUSED( center ); } 00181 00193 void setGlobalGridAttributes( const GridAttributes & ); 00194 00200 GridAttributes globalGridAttributes() const; 00201 00220 DataDimensionsList gridDimensionsList(); 00221 00229 void setReferenceCoordinatePlane( AbstractCoordinatePlane * plane ); 00230 00246 AbstractCoordinatePlane * referenceCoordinatePlane() const; 00247 00252 bool isCornerSpacersEnabled() const; 00253 00257 void setCornerSpacersEnabled( bool enable ); 00258 00259 virtual AbstractCoordinatePlane* sharedAxisMasterPlane( QPainter* p = 0 ); // KDChart 3: const method? 00260 00261 00263 virtual bool isEmpty() const; 00265 virtual Qt::Orientations expandingDirections() const; 00267 virtual QSize maximumSize() const; 00269 virtual QSize minimumSize() const; 00271 virtual QSize sizeHint() const; 00278 virtual void setGeometry( const QRect& r ); 00280 virtual QRect geometry() const; 00281 00282 virtual void mousePressEvent( QMouseEvent* event ); 00283 virtual void mouseDoubleClickEvent( QMouseEvent* event ); 00284 virtual void mouseMoveEvent( QMouseEvent* event ); 00285 virtual void mouseReleaseEvent( QMouseEvent* event ); 00286 00290 void setParent( Chart* parent ); 00291 Chart* parent(); 00292 const Chart* parent() const; 00293 00299 #if QT_VERSION < 0x040400 || defined(Q_COMPILER_MANGLES_RETURN_TYPE) 00300 const bool isVisiblePoint( const QPointF& point ) const; 00301 #else 00302 bool isVisiblePoint( const QPointF& point ) const; 00303 #endif 00304 00305 public Q_SLOTS: 00309 void update(); 00313 void relayout(); 00317 void layoutPlanes(); 00321 void setGridNeedsRecalculate(); 00322 00323 Q_SIGNALS: 00325 void destroyedCoordinatePlane( AbstractCoordinatePlane* ); 00326 00328 void needUpdate(); 00329 00331 void needRelayout(); 00332 00334 void needLayoutPlanes(); 00335 00337 void propertiesChanged(); 00338 00339 void boundariesChanged(); 00340 00346 void geometryChanged( QRect, QRect ); 00347 00348 private: 00349 Q_SIGNALS: 00350 // Emitted from inside the setGeometry() 00351 // This is connected via QueuedConnection to the geometryChanged() Signal 00352 // that users can connect to safely then. 00353 void internal_geometryChanged( QRect, QRect ); 00355 void viewportCoordinateSystemChanged(); 00356 00357 protected: 00358 virtual DataDimensionsList getDataDimensionsList() const = 0; 00359 00360 //KDCHART_DECLARE_PRIVATE_DERIVED( AbstractCoordinatePlane ) 00361 }; 00362 00379 class DataDimension{ 00380 public: 00381 DataDimension() 00382 : start( 1.0 ) 00383 , end( 10.0 ) 00384 , isCalculated( false ) 00385 , calcMode( AbstractCoordinatePlane::Linear ) 00386 , sequence( KDChartEnums::GranularitySequence_10_20 ) 00387 , stepWidth( 1.0 ) 00388 , subStepWidth( 0.0 ) 00389 {} 00390 DataDimension( qreal start_, 00391 qreal end_, 00392 bool isCalculated_, 00393 AbstractCoordinatePlane::AxesCalcMode calcMode_, 00394 KDChartEnums::GranularitySequence sequence_, 00395 qreal stepWidth_=0.0, 00396 qreal subStepWidth_=0.0 ) 00397 : start( start_ ) 00398 , end( end_ ) 00399 , isCalculated( isCalculated_ ) 00400 , calcMode( calcMode_ ) 00401 , sequence( sequence_ ) 00402 , stepWidth( stepWidth_ ) 00403 , subStepWidth( subStepWidth_ ) 00404 {} 00412 qreal distance() const 00413 { 00414 return end-start; 00415 } 00416 00417 bool operator==( const DataDimension& r ) const 00418 { 00419 return 00420 (start == r.start) && 00421 (end == r.end) && 00422 (sequence == r.sequence) && 00423 (isCalculated == r.isCalculated) && 00424 (calcMode == r.calcMode) && 00425 (stepWidth == r.stepWidth) && 00426 (subStepWidth == r.subStepWidth); 00427 } 00428 00429 bool operator!=( const DataDimension& other ) const 00430 { return !operator==( other ); } 00431 00432 00433 qreal start; 00434 qreal end; 00435 bool isCalculated; 00436 AbstractCoordinatePlane::AxesCalcMode calcMode; 00437 KDChartEnums::GranularitySequence sequence; 00438 qreal stepWidth; 00439 qreal subStepWidth; 00440 }; 00441 00442 #if !defined(QT_NO_DEBUG_STREAM) 00443 QDebug operator<<( QDebug stream, const DataDimension& r ); 00444 #endif 00445 00446 } 00447 #endif