KDChartLegend.h

Go to the documentation of this file.
00001 /* -*- Mode: C++ -*-
00002    KDChart - a multi-platform charting engine
00003    */
00004 
00005 /****************************************************************************
00006  ** Copyright (C) 2005-2007 Klar�vdalens Datakonsult AB.  All rights reserved.
00007  **
00008  ** This file is part of the KD Chart library.
00009  **
00010  ** This file may be distributed and/or modified under the terms of the
00011  ** GNU General Public License version 2 as published by the Free Software
00012  ** Foundation and appearing in the file LICENSE.GPL included in the
00013  ** packaging of this file.
00014  **
00015  ** Licensees holding valid commercial KD Chart licenses may use this file in
00016  ** accordance with the KD Chart Commercial License Agreement provided with
00017  ** the Software.
00018  **
00019  ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00020  ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00021  **
00022  ** See http://www.kdab.net/kdchart for
00023  **   information about KD Chart Commercial License Agreements.
00024  **
00025  ** Contact info@kdab.net if any conditions of this
00026  ** licensing are not clear to you.
00027  **
00028  **********************************************************************/
00029 
00030 #ifndef KDCHARTLEGEND_H
00031 #define KDCHARTLEGEND_H
00032 
00033 #include "KDChartAbstractAreaWidget.h"
00034 #include "KDChartPosition.h"
00035 #include "KDChartMarkerAttributes.h"
00036 
00037 class QTextTable;
00038 
00039 namespace KDChart {
00040 
00041     class AbstractDiagram;
00042     typedef QList<AbstractDiagram*> DiagramList;
00043     typedef QList<const AbstractDiagram*> ConstDiagramList;
00044 
00062 class KDCHART_EXPORT Legend : public AbstractAreaWidget
00063 {
00064     Q_OBJECT
00065 
00066     Q_DISABLE_COPY( Legend )
00067     KDCHART_DECLARE_PRIVATE_DERIVED_QWIDGET( Legend )
00068 
00069 public:
00070     explicit Legend( QWidget* parent = 0 );
00071     explicit Legend( KDChart::AbstractDiagram* diagram, QWidget* parent );
00072     virtual ~Legend();
00073 
00074 
00075     enum LegendStyle { MarkersOnly     = 0,
00076                        LinesOnly       = 1,
00077                        MarkersAndLines = 2 };
00078 
00079 
00080     void setLegendStyle( LegendStyle style );
00081     LegendStyle legendStyle() const;
00082 
00083 
00084     virtual Legend * clone() const;
00085 
00089     bool compare( const Legend* other )const;
00090 
00091     //QSize calcSizeHint() const;
00092     virtual void resizeEvent( QResizeEvent * event ); // TODO: should be protected
00093 
00094     virtual void paint( QPainter* painter );
00095     virtual void setVisible( bool visible );
00096 
00112     void setReferenceArea( const QWidget* area );
00120     const QWidget* referenceArea() const;
00121 
00128     KDChart::AbstractDiagram* diagram() const;
00129 
00136     DiagramList diagrams() const;
00137 
00141     ConstDiagramList constDiagrams() const;
00142 
00149     void addDiagram( KDChart::AbstractDiagram* newDiagram );
00150 
00156     void removeDiagram( KDChart::AbstractDiagram* oldDiagram );
00157 
00163     void removeDiagrams();
00164 
00179     void replaceDiagram( KDChart::AbstractDiagram* newDiagram,
00180                          KDChart::AbstractDiagram* oldDiagram = 0 );
00181 
00186     uint dataSetOffset( KDChart::AbstractDiagram* diagram );
00187 
00196     void setDiagram( KDChart::AbstractDiagram* newDiagram );
00197 
00206     void setPosition( Position position );
00207 
00212     Position position() const;
00213 
00222     void setAlignment( Qt::Alignment );
00223 
00228     Qt::Alignment alignment() const;
00229 
00235     void setTextAlignment( Qt::Alignment );
00236 
00242      Qt::Alignment textAlignment() const;
00243 
00288     void setFloatingPosition( const RelativePosition& relativePosition );
00289 
00294     const RelativePosition floatingPosition() const;
00295 
00296     void setOrientation( Qt::Orientation orientation );
00297     Qt::Orientation orientation() const;
00298 
00299 
00300     void setSortOrder( Qt::SortOrder order );
00301     Qt::SortOrder sortOrder() const;
00302 
00303     void setShowLines( bool legendShowLines );
00304     bool showLines() const;
00305 
00306     void resetTexts();
00307     void setText( uint dataset, const QString& text );
00308     QString text( uint dataset ) const;
00309     const QMap<uint,QString> texts() const;
00310 
00318     void setHiddenDatasets( const QList<uint> hiddenDatasets );
00319     const QList<uint> hiddenDatasets() const;
00320     void setDatasetHidden( uint dataset, bool hidden );
00321     bool datasetIsHidden( uint dataset ) const;
00322 
00323     uint datasetCount() const;
00324 
00325     void setDefaultColors();
00326     void setRainbowColors();
00327     void setSubduedColors( bool ordered = false );
00328 
00329     void setBrushesFromDiagram( KDChart::AbstractDiagram* diagram );
00330 
00336     void setColor( uint dataset, const QColor& color );
00337 
00338     void setBrush( uint dataset, const QBrush& brush );
00339     QBrush brush( uint dataset ) const;
00340     const QMap<uint,QBrush> brushes() const;
00341 
00342     void setPen( uint dataset, const QPen& pen );
00343     QPen pen( uint dataset ) const;
00344     const QMap<uint,QPen> pens() const;
00345 
00351     void setMarkerAttributes( uint dataset, const MarkerAttributes& );
00352     MarkerAttributes markerAttributes( uint dataset ) const;
00353     const QMap<uint, MarkerAttributes> markerAttributes() const;
00354 
00362     void setUseAutomaticMarkerSize( bool useAutomaticMarkerSize );
00363     bool useAutomaticMarkerSize() const;
00364 
00365     void setTextAttributes( const TextAttributes &a );
00366     TextAttributes textAttributes() const;
00367 
00368     void setTitleText( const QString& text );
00369     QString titleText() const;
00370 
00371     void setTitleTextAttributes( const TextAttributes &a );
00372     TextAttributes titleTextAttributes() const;
00373 
00374     // FIXME same as frameSettings()->padding()?
00375     void setSpacing( uint space );
00376     uint spacing() const;
00377 
00378     // called internally by KDChart::Chart, when painting into a custom QPainter
00379     virtual void forceRebuild();
00380 
00381     virtual QSize minimumSizeHint() const;
00382     virtual QSize sizeHint() const;
00383     virtual void needSizeHint();
00384     virtual void resizeLayout( const QSize& size );
00385 
00386 /*public static*/
00387 //    static LegendPosition stringToPosition( QString name, bool* ok=0 );
00388 
00389 Q_SIGNALS:
00390     void destroyedLegend( Legend* );
00392     void propertiesChanged();
00393 
00394 private Q_SLOTS:
00395     void emitPositionChanged();
00396     void resetDiagram( AbstractDiagram* );
00397     void activateTheLayout();
00398     void setNeedRebuild();
00399     void buildLegend();
00400 }; // End of class Legend
00401 
00402 }
00403 
00404 
00405 #endif // KDCHARTLEGEND_H

Generated on Thu Mar 4 23:19:11 2010 for KD Chart 2 by  doxygen 1.5.4