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 KDCHARTLEGEND_H 00024 #define KDCHARTLEGEND_H 00025 00026 #include "KDChartAbstractAreaWidget.h" 00027 #include "KDChartPosition.h" 00028 #include "KDChartMarkerAttributes.h" 00029 00030 class QTextTable; 00031 00032 namespace KDChart { 00033 00034 class AbstractDiagram; 00035 typedef QList<AbstractDiagram*> DiagramList; 00036 typedef QList<const AbstractDiagram*> ConstDiagramList; 00037 00055 class KDCHART_EXPORT Legend : public AbstractAreaWidget 00056 { 00057 Q_OBJECT 00058 00059 Q_DISABLE_COPY( Legend ) 00060 KDCHART_DECLARE_PRIVATE_DERIVED_QWIDGET( Legend ) 00061 00062 public: 00063 explicit Legend( QWidget* parent = 0 ); 00064 explicit Legend( KDChart::AbstractDiagram* diagram, QWidget* parent ); 00065 virtual ~Legend(); 00066 00067 00068 enum LegendStyle { MarkersOnly = 0, 00069 LinesOnly = 1, 00070 MarkersAndLines = 2 }; 00071 00072 00073 void setLegendStyle( LegendStyle style ); 00074 LegendStyle legendStyle() const; 00075 00076 00077 virtual Legend * clone() const; 00078 00082 bool compare( const Legend* other ) const; 00083 00084 virtual void resizeEvent( QResizeEvent * event ); // TODO: should be protected 00085 00086 virtual void paint( QPainter* painter ); 00087 virtual void setVisible( bool visible ); 00088 00104 void setReferenceArea( const QWidget* area ); 00112 const QWidget* referenceArea() const; 00113 00120 KDChart::AbstractDiagram* diagram() const; 00121 00128 DiagramList diagrams() const; 00129 00133 ConstDiagramList constDiagrams() const; 00134 00141 void addDiagram( KDChart::AbstractDiagram* newDiagram ); 00142 00148 void removeDiagram( KDChart::AbstractDiagram* oldDiagram ); 00149 00155 void removeDiagrams(); 00156 00171 void replaceDiagram( KDChart::AbstractDiagram* newDiagram, 00172 KDChart::AbstractDiagram* oldDiagram = 0 ); 00173 00178 uint dataSetOffset( KDChart::AbstractDiagram* diagram ); 00179 00188 void setDiagram( KDChart::AbstractDiagram* newDiagram ); 00189 00198 void setPosition( Position position ); 00199 00204 Position position() const; 00205 00214 void setAlignment( Qt::Alignment ); 00215 00220 Qt::Alignment alignment() const; 00221 00227 void setTextAlignment( Qt::Alignment ); 00228 00234 Qt::Alignment textAlignment() const; 00235 00242 void setLegendSymbolAlignment(Qt::Alignment); 00243 00250 Qt::Alignment legendSymbolAlignment() const; 00251 00296 void setFloatingPosition( const RelativePosition& relativePosition ); 00297 00302 const RelativePosition floatingPosition() const; 00303 00304 void setOrientation( Qt::Orientation orientation ); 00305 Qt::Orientation orientation() const; 00306 00307 00308 void setSortOrder( Qt::SortOrder order ); 00309 Qt::SortOrder sortOrder() const; 00310 00311 void setShowLines( bool legendShowLines ); 00312 bool showLines() const; 00313 00314 void resetTexts(); 00315 void setText( uint dataset, const QString& text ); 00316 QString text( uint dataset ) const; 00317 const QMap<uint,QString> texts() const; 00318 00326 void setHiddenDatasets( const QList<uint> hiddenDatasets ); 00327 const QList<uint> hiddenDatasets() const; 00328 void setDatasetHidden( uint dataset, bool hidden ); 00329 bool datasetIsHidden( uint dataset ) const; 00330 00331 uint datasetCount() const; 00332 00333 void setDefaultColors(); 00334 void setRainbowColors(); 00335 void setSubduedColors( bool ordered = false ); 00336 00337 void setBrushesFromDiagram( KDChart::AbstractDiagram* diagram ); 00338 00344 void setColor( uint dataset, const QColor& color ); 00345 00346 void setBrush( uint dataset, const QBrush& brush ); 00347 QBrush brush( uint dataset ) const; 00348 const QMap<uint,QBrush> brushes() const; 00349 00350 void setPen( uint dataset, const QPen& pen ); 00351 QPen pen( uint dataset ) const; 00352 const QMap<uint,QPen> pens() const; 00353 00359 void setMarkerAttributes( uint dataset, const MarkerAttributes& ); 00360 MarkerAttributes markerAttributes( uint dataset ) const; 00361 const QMap<uint, MarkerAttributes> markerAttributes() const; 00362 00370 void setUseAutomaticMarkerSize( bool useAutomaticMarkerSize ); 00371 bool useAutomaticMarkerSize() const; 00372 00373 void setTextAttributes( const TextAttributes &a ); 00374 TextAttributes textAttributes() const; 00375 00376 void setTitleText( const QString& text ); 00377 QString titleText() const; 00378 00379 void setTitleTextAttributes( const TextAttributes &a ); 00380 TextAttributes titleTextAttributes() const; 00381 00382 void setSpacing( uint space ); 00383 uint spacing() const; 00384 00385 // called internally by KDChart::Chart, when painting into a custom QPainter 00386 virtual void forceRebuild(); 00387 00388 virtual QSize minimumSizeHint() const; 00389 virtual QSize sizeHint() const; 00390 virtual void needSizeHint(); 00391 virtual void resizeLayout( const QSize& size ); 00392 00393 Q_SIGNALS: 00394 void destroyedLegend( Legend* ); 00396 void propertiesChanged(); 00397 00398 private Q_SLOTS: 00399 void emitPositionChanged(); 00400 void resetDiagram( AbstractDiagram* ); 00401 void activateTheLayout(); 00402 void setNeedRebuild(); 00403 void buildLegend(); 00404 }; // End of class Legend 00405 00406 } 00407 00408 00409 #endif // KDCHARTLEGEND_H