# 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-2006 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
    00190     void setDiagram( KDChart::AbstractDiagram* newDiagram );
    00191
    00200     void setPosition( Position position );
    00201
    00206     Position position() const;
    00207
    00216     void setAlignment( Qt::Alignment );
    00217
    00222     Qt::Alignment alignment() const;
    00223
    00268     void setFloatingPosition( const RelativePosition& relativePosition );
    00269
    00274     const RelativePosition floatingPosition() const;
    00275
    00276     void setOrientation( Qt::Orientation orientation );
    00277     Qt::Orientation orientation() const;
    00278
    00279     void setShowLines( bool legendShowLines );
    00280     bool showLines() const;
    00281
    00282     void resetTexts();
    00283     void setText( uint dataset, const QString& text );
    00284     QString text( uint dataset ) const;
    00285     const QMap<uint,QString> texts() const;
    00286
    00287     uint datasetCount() const;
    00288
    00289     void setDefaultColors();
    00290     void setRainbowColors();
    00291     void setSubduedColors( bool ordered = false );
    00292
    00293     void setBrushesFromDiagram( KDChart::AbstractDiagram* diagram );
    00294
    00300     void setColor( uint dataset, const QColor& color );
    00301
    00302     void setBrush( uint dataset, const QBrush& brush );
    00303     QBrush brush( uint dataset ) const;
    00304     const QMap<uint,QBrush> brushes() const;
    00305
    00306     void setPen( uint dataset, const QPen& pen );
    00307     QPen pen( uint dataset ) const;
    00308     const QMap<uint,QPen> pens() const;
    00309
    00315     void setMarkerAttributes( uint dataset, const MarkerAttributes& );
    00316     MarkerAttributes markerAttributes( uint dataset ) const;
    00317     const QMap<uint, MarkerAttributes> markerAttributes() const;
    00318
    00326     void setUseAutomaticMarkerSize( bool useAutomaticMarkerSize );
    00327     bool useAutomaticMarkerSize() const;
    00328
    00329     void setTextAttributes( const TextAttributes &a );
    00330     TextAttributes textAttributes() const;
    00331
    00332     void setTitleText( const QString& text );
    00333     QString titleText() const;
    00334
    00335     void setTitleTextAttributes( const TextAttributes &a );
    00336     TextAttributes titleTextAttributes() const;
    00337
    00338     // FIXME same as frameSettings()->padding()?
    00339     void setSpacing( uint space );
    00340     uint spacing() const;
    00341
    00342     // called internally by KDChart::Chart, when painting into a custom QPainter
    00343     virtual void forceRebuild();
    00344
    00345     virtual QSize minimumSizeHint() const;
    00346     virtual QSize sizeHint() const;
    00347     virtual void needSizeHint();
    00348     virtual void resizeLayout( const QSize& size );
    00349
    00350 /*public static*/
    00351 //    static LegendPosition stringToPosition( QString name, bool* ok=0 );
    00352
    00353 Q_SIGNALS:
    00354     void destroyedLegend( Legend* );
    00356     void propertiesChanged();
    00357
    00358 private Q_SLOTS:
    00359     void emitPositionChanged();
    00360     void resetDiagram( AbstractDiagram* );
    00361     void activateTheLayout();
    00362     void setNeedRebuild();
    00363     void buildLegend();
    00364 }; // End of class Legend
    00365
    00366 }
    00367
    00368
    00369 #endif // KDCHARTLEGEND_H