KD Chart 2 [rev.2.4]
|
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 00128 virtual QSize minimumSizeHint() const; 00130 virtual QSizePolicy sizePolicy() const; 00131 00135 bool isRubberBandZoomingEnabled() const; 00136 00140 void setRubberBandZoomingEnabled( bool enable ); 00141 00146 virtual double zoomFactorX() const { return 1.0; } 00147 00152 virtual double zoomFactorY() const { return 1.0; } 00153 00158 virtual void setZoomFactors( double factorX, double factorY ) { Q_UNUSED( factorX ); Q_UNUSED( factorY ); } 00159 00165 virtual void setZoomFactorX( double factor ) { Q_UNUSED( factor ); } 00166 00172 virtual void setZoomFactorY( double factor ) { Q_UNUSED( factor ); } 00173 00178 virtual QPointF zoomCenter() const { return QPointF(0.0, 0.0); } 00179 00185 virtual void setZoomCenter( const QPointF& center ) { Q_UNUSED( center ); } 00186 00198 void setGlobalGridAttributes( const GridAttributes & ); 00199 00205 GridAttributes globalGridAttributes() const; 00206 00225 DataDimensionsList gridDimensionsList(); 00226 00234 void setReferenceCoordinatePlane( AbstractCoordinatePlane * plane ); 00235 00251 AbstractCoordinatePlane * referenceCoordinatePlane() const; 00252 00253 virtual AbstractCoordinatePlane* sharedAxisMasterPlane( QPainter* p = 0 ); 00254 00255 00257 virtual bool isEmpty() const; 00259 virtual Qt::Orientations expandingDirections() const; 00261 virtual QSize maximumSize() const; 00263 virtual QSize minimumSize() const; 00265 virtual QSize sizeHint() const; 00272 virtual void setGeometry( const QRect& r ); 00274 virtual QRect geometry() const; 00275 00276 virtual void mousePressEvent( QMouseEvent* event ); 00277 virtual void mouseDoubleClickEvent( QMouseEvent* event ); 00278 virtual void mouseMoveEvent( QMouseEvent* event ); 00279 virtual void mouseReleaseEvent( QMouseEvent* event ); 00280 00284 void setParent( Chart* parent ); 00285 Chart* parent(); 00286 const Chart* parent() const; 00287 00293 #if QT_VERSION < 0x040400 || defined(Q_COMPILER_MANGLES_RETURN_TYPE) 00294 const bool isVisiblePoint( const QPointF& point ) const; 00295 #else 00296 bool isVisiblePoint( const QPointF& point ) const; 00297 #endif 00298 00299 public Q_SLOTS: 00303 void update(); 00307 void relayout(); 00311 void layoutPlanes(); 00315 void setGridNeedsRecalculate(); 00316 00317 Q_SIGNALS: 00319 void destroyedCoordinatePlane( AbstractCoordinatePlane* ); 00320 00322 void needUpdate(); 00323 00325 void needRelayout(); 00326 00328 void needLayoutPlanes(); 00329 00331 void propertiesChanged(); 00332 00338 void geometryChanged( QRect, QRect ); 00339 00340 private: 00341 Q_SIGNALS: 00342 // Emitted from inside the setGeometry() 00343 // This is connected via QueuedConnection to the geometryChanged() Signal 00344 // that users can connect to safely then. 00345 void internal_geometryChanged( QRect, QRect ); 00347 void viewportCoordinateSystemChanged(); 00348 00349 protected: 00350 virtual DataDimensionsList getDataDimensionsList() const = 0; 00351 00352 //KDCHART_DECLARE_PRIVATE_DERIVED( AbstractCoordinatePlane ) 00353 }; 00354 00371 class DataDimension{ 00372 public: 00373 DataDimension() 00374 : start( 1.0 ) 00375 , end( 10.0 ) 00376 , isCalculated( false ) 00377 , calcMode( AbstractCoordinatePlane::Linear ) 00378 , sequence( KDChartEnums::GranularitySequence_10_20 ) 00379 , stepWidth( 1.0 ) 00380 , subStepWidth( 0.0 ) 00381 {} 00382 DataDimension( qreal start_, 00383 qreal end_, 00384 bool isCalculated_, 00385 AbstractCoordinatePlane::AxesCalcMode calcMode_, 00386 KDChartEnums::GranularitySequence sequence_, 00387 qreal stepWidth_=0.0, 00388 qreal subStepWidth_=0.0 ) 00389 : start( start_ ) 00390 , end( end_ ) 00391 , isCalculated( isCalculated_ ) 00392 , calcMode( calcMode_ ) 00393 , sequence( sequence_ ) 00394 , stepWidth( stepWidth_ ) 00395 , subStepWidth( subStepWidth_ ) 00396 {} 00404 qreal distance() const 00405 { 00406 return end-start; 00407 } 00408 00409 bool operator==( const DataDimension& r ) const 00410 { 00411 return 00412 (start == r.start) && 00413 (end == r.end) && 00414 (sequence == r.sequence) && 00415 (isCalculated == r.isCalculated) && 00416 (calcMode == r.calcMode) && 00417 (stepWidth == r.stepWidth) && 00418 (subStepWidth == r.subStepWidth); 00419 } 00420 00421 bool operator!=( const DataDimension& other ) const 00422 { return !operator==( other ); } 00423 00424 00425 qreal start; 00426 qreal end; 00427 bool isCalculated; 00428 AbstractCoordinatePlane::AxesCalcMode calcMode; 00429 KDChartEnums::GranularitySequence sequence; 00430 qreal stepWidth; 00431 qreal subStepWidth; 00432 }; 00433 00434 #if !defined(QT_NO_DEBUG_STREAM) 00435 QDebug operator<<( QDebug stream, const DataDimension& r ); 00436 #endif 00437 00438 } 00439 #endif