KD Chart 2: KDChart::Legend class Reference

Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

# KDChart::Legend Class Reference

`#include <KDChartLegend.h>`

Inheritance diagram for KDChart::Legend:

[legend]
Collaboration diagram for KDChart::Legend:
[legend]
List of all members.

## Detailed Description

Legend defines the interface for the legend drawing class.

Legend is the class for drawing legends for all kinds of diagrams ("chart types").

Legend is drawn on chart level, not per diagram, but you can have more than one legend per chart, using KDChart::Chart::addLegend().

Note:
  Legend is different from all other classes ofd KD Chart, since it can be displayed outside of the Chart's area. If you want to, you can embedd the legend into your own widget, or into another part of a bigger grid, into which you might have inserted the Chart.

On the other hand, please note that you MUST call Chart::addLegend to get your legend positioned into the correct place of your chart - if you want to have the legend shown inside of the chart (that's probably true for most cases).

Definition at line 62 of file KDChartLegend.h.

## Public Types
enum | LegendStyle { MarkersOnly = 0, LinesOnly = 1, MarkersAndLines = 2 }
## Public Member Functions
void | activateTheLayout ()
void | addDiagram (KDChart::AbstractDiagram *newDiagram)
| Add the given diagram to the legend.
Qt::Alignment | alignment () const
| Returns the alignment of a non-floating legend.
void | alignToReferencePoint (const RelativePosition &position)
BackgroundAttributes | backgroundAttributes () const
QBrush | brush (uint dataset) const
const QMap< uint, QBrush > | brushes () const
void | buildLegend ()
virtual Legend * | clone () const
bool | compare (const AbstractAreaBase *other) const
| Returns true if both areas have the same settings.
bool | compare (const Legend *other) const
| Returns true if both axes have the same settings.
ConstDiagramList | constDiagrams () const
uint | datasetCount () const
KDChart::AbstractDiagram * | diagram () const
| The first diagram of the legend or 0 if there was none added to the legend.
DiagramList | diagrams () const
| The list of all diagrams associated with the legend.
const RelativePosition | floatingPosition () const
| Returns the position of a floating legend.
virtual void | forceRebuild ()
| Call this to trigger an unconditional re-building of the widget's internals.
FrameAttributes | frameAttributes () const
void | getFrameLeadings (int &left, int &top, int &right, int &bottom) const
| Legend (KDChart::AbstractDiagram *diagram, QWidget *parent)
| Legend (QWidget *parent=0)
LegendStyle | legendStyle () const
const QMap< uint, MarkerAttributes > | markerAttributes () const
MarkerAttributes | markerAttributes (uint dataset) const
virtual QSize | minimumSizeHint () const
virtual void | needSizeHint ()
| Call this to trigger an conditional re-building of the widget's internals.
Qt::Orientation | orientation () const
virtual void | paint (QPainter *painter)
| Overwrite this to paint the inner contents of your widget.
void | paintAll (QPainter &painter)
| Call paintAll, if you want the background and the frame to be drawn before the normal paint() is invoked automatically.
virtual void | paintBackground (QPainter &painter, const QRect &rectangle)
virtual void | paintEvent (QPaintEvent *event)
| Draws the background and frame, then calls paint().
virtual void | paintFrame (QPainter &painter, const QRect &rectangle)
virtual void | paintIntoRect (QPainter &painter, const QRect &rect)
| Draws the background and frame, then calls paint().
QPen | pen (uint dataset) const
const QMap< uint, QPen > | pens () const
Position | position () const
| Returns the position of a non-floating legend.
void | propertiesChanged ()
| Emitted upon change of a property of the Legend or any of its components.
const QWidget * | referenceArea () const
| Returns the reference area, that is used for font size of title text, and for font size of the item texts, IF automatic area detection is set.
void | removeDiagram (KDChart::AbstractDiagram *oldDiagram)
| Removes the diagram from the legend's list of diagrams.
void | removeDiagrams ()
| Removes all of the diagram from the legend's list of diagrams.
void | replaceDiagram (KDChart::AbstractDiagram *newDiagram, KDChart::AbstractDiagram *oldDiagram=0)
| Replaces the old diagram, or appends the new diagram, it there is none yet.
void | resetDiagram (AbstractDiagram *)
void | resetTexts ()
| Removes all legend texts that might have been set by setText.
virtual void | resizeEvent (QResizeEvent *event)
virtual void | resizeLayout (const QSize &size)
void | setAlignment (Qt::Alignment)
| Specify the alignment of a non-floating legend.
void | setBackgroundAttributes (const BackgroundAttributes &a)
void | setBrush (uint dataset, const QBrush &brush)
void | setBrushesFromDiagram (KDChart::AbstractDiagram *diagram)
void | setColor (uint dataset, const QColor &color)
| Note: there is no color() getter method, since setColor just sets a QBrush with the respective color, so the brush() getter method is sufficient.
void | setDefaultColors ()
void | setDiagram (KDChart::AbstractDiagram *newDiagram)
| A convenience method doing the same as replaceDiagram( newDiagram, 0 );.
void | setFloatingPosition (const RelativePosition &relativePosition)
| Specify the position and alignment of a floating legend.
void | setFrameAttributes (const FrameAttributes &a)
void | setLegendStyle (LegendStyle style)
void | setMarkerAttributes (uint dataset, const MarkerAttributes &)
| Note that any sizes specified via setMarkerAttributes are ignored, unless you disable the automatic size calculation, by saying setUseAutomaticMarkerSize( false ).
void | setNeedRebuild ()
void | setOrientation (Qt::Orientation orientation)
void | setPen (uint dataset, const QPen &pen)
void | setPosition (Position position)
| Specify the position of a non-floating legend.
void | setRainbowColors ()
void | setReferenceArea (const QWidget *area)
| Specifies the reference area for font size of title text, and for font size of the item texts, IF automatic area detection is set.
void | setShowLines (bool legendShowLines)
void | setSpacing (uint space)
void | setSubduedColors (bool ordered=false)
void | setText (uint dataset, const QString &text)
void | setTextAttributes (const TextAttributes &a)
void | setTitleText (const QString &text)
void | setTitleTextAttributes (const TextAttributes &a)
void | setUseAutomaticMarkerSize (bool useAutomaticMarkerSize)
| This option is on by default, it means that Marker sizes in the Legend will be the same as the font height used for their respective label texts.
virtual void | setVisible (bool visible)
bool | showLines () const
virtual QSize | sizeHint () const
uint | spacing () const
QString | text (uint dataset) const
TextAttributes | textAttributes () const
const QMap< uint, QString > | texts () const
QString | titleText () const
TextAttributes | titleTextAttributes () const
bool | useAutomaticMarkerSize () const
virtual | ~Legend ()
## Static Public Member Functions
void | paintBackgroundAttributes (QPainter &painter, const QRect &rectangle, const KDChart::BackgroundAttributes &attributes)
void | paintFrameAttributes (QPainter &painter, const QRect &rectangle, const KDChart::FrameAttributes &attributes)
## Public Attributes
Q_SIGNALS | __pad0__: void destroyedLegend( Legend* )
private | Q_SLOTS: void emitPositionChanged()
## Protected Member Functions
virtual QRect | areaGeometry () const
QRect | innerRect () const
virtual void | positionHasChanged ()

## Member Enumeration Documentation

enum KDChart::Legend::LegendStyle

  | Enumeration values:
  MarkersOnly |
  LinesOnly |
  MarkersAndLines |
Definition at line 75 of file KDChartLegend.h. Referenced by buildLegend().
    00075                      { MarkersOnly     = 0,
    00076                        LinesOnly       = 1,
    00077                        MarkersAndLines = 2 };

## Constructor & Destructor Documentation

Legend::Legend | ( | QWidget * | parent = 0 | ) | `[explicit]`

| Definition at line 85 of file KDChartLegend.cpp. References d. Referenced by clone().
    00085                                 :
    00086     AbstractAreaWidget( new Private(), parent )
    00087 {
    00088     d->referenceArea = parent;
    00089     init();
    00090 }

Legend::Legend | ( | KDChart::AbstractDiagram * | diagram,
|  | QWidget * | parent
| ) | `[explicit]`

| Definition at line 92 of file KDChartLegend.cpp. References d, and setDiagram().
    00092                                                                  :
    00093     AbstractAreaWidget( new Private(), parent )
    00094 {
    00095     d->referenceArea = parent;
    00096     init();
    00097     setDiagram( diagram );
    00098 }

Legend::~Legend | ( |  | ) | `[virtual]`

| Definition at line 100 of file KDChartLegend.cpp.
    00101 {
    00102     emit destroyedLegend( this );
    00103 }

## Member Function Documentation

void Legend::activateTheLayout | ( |  | ) |

| Definition at line 182 of file KDChartLegend.cpp. References d. Referenced by buildLegend(), and resizeLayout().
    00183 {
    00184     if( d->layout && d->layout->parent() )
    00185         d->layout->activate();
    00186 }

void Legend::addDiagram | ( | KDChart::AbstractDiagram * | newDiagram | ) |

  | Add the given diagram to the legend. Parameters:
  newDiagram | The diagram to add.
See also: diagram, diagrams, removeDiagram, removeDiagrams, replaceDiagram, setDiagram Definition at line 334 of file KDChartLegend.cpp. References d, resetDiagram(), and setNeedRebuild(). Referenced by replaceDiagram().
    00335 {
    00336     if ( newDiagram )
    00337     {
    00338         DiagramObserver* observer = new DiagramObserver( newDiagram, this );
    00339
    00340         DiagramObserver* oldObs = d->findObserverForDiagram( newDiagram );
    00341         if( oldObs ){
    00342             delete oldObs;
    00343             d->observers[ d->observers.indexOf( oldObs ) ] = observer;
    00344         }else{
    00345             d->observers.append( observer );
    00346         }
    00347         connect( observer, SIGNAL( diagramDestroyed(AbstractDiagram*) ),
    00348                         SLOT( resetDiagram(AbstractDiagram*) ));
    00349         connect( observer, SIGNAL( diagramDataChanged(AbstractDiagram*) ),
    00350                  SLOT( setNeedRebuild() ));
    00351         connect( observer, SIGNAL( diagramDataHidden(AbstractDiagram*) ),
    00352                  SLOT( setNeedRebuild() ));
    00353         connect( observer, SIGNAL( diagramAttributesChanged(AbstractDiagram*) ),
    00354                         SLOT( setNeedRebuild() ));
    00355         setNeedRebuild();
    00356     }
    00357 }

Qt::Alignment Legend::alignment | ( |  | ) | const

| Returns the alignment of a non-floating legend. See also: setAlignment Definition at line 443 of file KDChartLegend.cpp. References d. Referenced by clone().
    00444 {
    00445     return d->alignment;
    00446 }

void AbstractAreaBase::alignToReferencePoint | ( | const RelativePosition & | position | ) | `[inherited]`

| Definition at line 90 of file KDChartAbstractAreaBase.cpp.
    00091 {
    00092     Q_UNUSED( position );
    00093     // PENDING(kalle) FIXME
    00094     qWarning( "Sorry, not implemented: void AbstractAreaBase::alignToReferencePoint( const RelativePosition& position )" );
    00095 }

QRect AbstractAreaWidget::areaGeometry | ( |  | ) | const`[protected, virtual, inherited]`

| Implements KDChart::AbstractAreaBase. Definition at line 186 of file KDChartAbstractAreaWidget.cpp.
    00187 {
    00188     return geometry();
    00189 }

BackgroundAttributes AbstractAreaBase::backgroundAttributes | ( |  | ) | const`[inherited]`

| Definition at line 112 of file KDChartAbstractAreaBase.cpp. References d. Referenced by updateCommonBrush().
    00113 {
    00114     return d->backgroundAttributes;
    00115 }

QBrush Legend::brush | ( | uint | dataset | ) | const

| Definition at line 549 of file KDChartLegend.cpp. References d. Referenced by buildLegend(), and setRainbowColors().
    00550 {
    00551     if( d->brushes.find( dataset ) != d->brushes.end() )
    00552         return d->brushes[ dataset ];
    00553     else
    00554         return d->modelBrushes[ dataset ];
    00555 }

const QMap< uint, QBrush > Legend::brushes | ( |  | ) | const

| Definition at line 557 of file KDChartLegend.cpp. References d.
    00558 {
    00559     return d->brushes;
    00560 }

void Legend::buildLegend | ( |  | ) |

| Definition at line 770 of file KDChartLegend.cpp. References activateTheLayout(), brush(), KDChart::TextAttributes::calculatedFontSize(), d, KDChart::AbstractDiagram::datasetBrushes(), KDChart::AbstractDiagram::datasetLabels(), KDChart::AbstractDiagram::datasetMarkers(), KDChart::AbstractDiagram::datasetPens(), diagram(), KDChart::AbstractDiagram::isHidden(), KDChart::TextAttributes::isVisible(), legendStyle(), LegendStyle, LinesOnly, markerAttributes(), MarkersAndLines, MarkersOnly, orientation(), pen(), propertiesChanged(), referenceArea(), KDChart::AbstractLayoutItem::setParentWidget(), showLines(), spacing(), text(), textAttributes(), titleText(), titleTextAttributes(), and useAutomaticMarkerSize(). Referenced by forceRebuild(), needSizeHint(), and setNeedRebuild().
    00771 {
    00772     /*
    00773     if( !d->needRebuild ) {
    00774 #ifdef DEBUG_LEGEND_PAINT
    00775         qDebug() << "leaving Legend::buildLegend() with NO action (was already build)";
    00776 #endif
    00777         // Note: We do *not* need to send positionChanged here,
    00778         //       because we send it in the resizeEvent, so layouting
    00779         //       is done at the right time.
    00780         return;
    00781     }
    00782 #ifdef DEBUG_LEGEND_PAINT
    00783     qDebug() << "entering Legend::buildLegend() **********************************";
    00784 #endif
    00785     d->needRebuild = false;
    00786     */
    00787
    00788     Q_FOREACH( QLayoutItem* layoutItem, d->layoutItems ) {
    00789         d->layout->removeItem( layoutItem );
    00790     }
    00791     qDeleteAll( d->layoutItems );
    00792     d->layoutItems.clear();
    00793
    00794     if( orientation() == Qt::Vertical ) {
    00795         d->layout->setColumnStretch( 4, 1 );
    00796     } else {
    00797         d->layout->setColumnStretch( 4, 0 );
    00798     }
    00799
    00800     d->modelLabels.clear();
    00801     d->modelBrushes.clear();
    00802     d->modelPens.clear();
    00803     d->modelMarkers.clear();
    00804     // retrieve the diagrams' settings for all non-hidden datasets
    00805     for (int i = 0; i < d->observers.size(); ++i){
    00806         const AbstractDiagram* diagram = d->observers.at(i)->diagram();
    00807         if( diagram ){
    00808             //qDebug() << "accessing" << diagram;
    00809             const QStringList             diagramLabels(  diagram->datasetLabels()  );
    00810             const QList<QBrush>           diagramBrushes( diagram->datasetBrushes() );
    00811             const QList<QPen>             diagramPens(    diagram->datasetPens()    );
    00812             const QList<MarkerAttributes> diagramMarkers( diagram->datasetMarkers() );
    00813             for ( int dataset = 0; dataset < diagramLabels.count(); dataset++ ) {
    00814                 // only show the label if the diagrams is NOT having the dataset set to hidden
    00815                 if( ! diagram->isHidden( dataset ) ){
    00816                     d->modelLabels  += diagramLabels[   dataset ];
    00817                     d->modelBrushes += diagramBrushes[  dataset ];
    00818                     d->modelPens    += diagramPens[     dataset ];
    00819                     d->modelMarkers += diagramMarkers[  dataset ];
    00820                 }
    00821             }
    00822         }
    00823     }
    00824
    00825     Q_ASSERT( d->modelLabels.count() == d->modelBrushes.count() );
    00826
    00827     // legend caption
    00828     if( !titleText().isEmpty() && titleTextAttributes().isVisible() ) {
    00829         // PENDING(kalle) Other properties!
    00830         KDChart::TextLayoutItem* titleItem =
    00831             new KDChart::TextLayoutItem( titleText(),
    00832                 titleTextAttributes(),
    00833                 referenceArea(),
    00834                 (orientation() == Qt::Vertical)
    00835                 ? KDChartEnums::MeasureOrientationMinimum
    00836                 : KDChartEnums::MeasureOrientationHorizontal,
    00837                 Qt::AlignCenter );
    00838         titleItem->setParentWidget( this );
    00839
    00840         d->layoutItems << titleItem;
    00841         if( orientation() == Qt::Vertical )
    00842             d->layout->addItem( titleItem, 0, 0, 1, 5, Qt::AlignCenter );
    00843         else
    00844             d->layout->addItem( titleItem, 0, 0, 1, d->modelLabels.count() ? (d->modelLabels.count()*4) : 1, Qt::AlignCenter );
    00845
    00846         // The line between the title and the legend items, if any.
    00847         if( showLines() && d->modelLabels.count() ) {
    00848             KDChart::HorizontalLineLayoutItem* lineItem = new KDChart::HorizontalLineLayoutItem();
    00849             d->layoutItems << lineItem;
    00850             if( orientation() == Qt::Vertical )
    00851                 d->layout->addItem( lineItem, 1, 0, 1, 5, Qt::AlignCenter );
    00852             else
    00853                 d->layout->addItem( lineItem, 1, 0, 1, d->modelLabels.count()*4, Qt::AlignCenter );
    00854         }
    00855     }
    00856
    00857     const KDChartEnums::MeasureOrientation orient =
    00858             (orientation() == Qt::Vertical)
    00859             ? KDChartEnums::MeasureOrientationMinimum
    00860             : KDChartEnums::MeasureOrientationHorizontal;
    00861     const TextAttributes labelAttrs( textAttributes() );
    00862     const qreal fontHeight = labelAttrs.calculatedFontSize( referenceArea(), orient );
    00863     const LegendStyle style = legendStyle();
    00864     //qDebug() << "fontHeight:" << fontHeight;
    00865
    00866     const bool bShowMarkers = (style != LinesOnly);
    00867
    00868     QSizeF maxMarkersSize(1.0, 1.0);
    00869     QVector <MarkerAttributes> markerAttrs( d->modelLabels.count() );
    00870     if( bShowMarkers ){
    00871         for ( int dataset = 0; dataset < d->modelLabels.count(); ++dataset ) {
    00872             markerAttrs[dataset] = markerAttributes( dataset );
    00873             QSizeF siz;
    00874             if( useAutomaticMarkerSize() ||
    00875                 ! markerAttrs[dataset].markerSize().isValid() )
    00876             {
    00877                 siz = QSizeF(fontHeight, fontHeight);
    00878                 markerAttrs[dataset].setMarkerSize( siz );
    00879             }else{
    00880                 siz = markerAttrs[dataset].markerSize();
    00881             }
    00882             maxMarkersSize =
    00883                     QSizeF(qMax(maxMarkersSize.width(),  siz.width()),
    00884                            qMax(maxMarkersSize.height(), siz.height()));
    00885         }
    00886     }
    00887
    00888     // If we show a marker on a line, we paint it after 4 pixels
    00889     // of the line have been painted. This allows to see the line style
    00890     // at the right side of the marker without the line needing to
    00891     // be too long.
    00892     // (having the marker in the middle of the line would require longer lines)
    00893     const int markerOffsOnLine = 8;
    00894
    00895     int maxLineLength = 18;
    00896     {
    00897         bool hasComplexPenStyle = false;
    00898         for ( int dataset = 0; dataset < d->modelLabels.count(); ++dataset ){
    00899             const QPen pn = pen(dataset);
    00900             const Qt::PenStyle ps = pn.style();
    00901             if( ps != Qt::NoPen ){
    00902                 maxLineLength = qMax( pn.width() * 18, maxLineLength );
    00903                 if( ps != Qt::SolidLine )
    00904                     hasComplexPenStyle = true;
    00905             }
    00906         }
    00907         if( hasComplexPenStyle && bShowMarkers )
    00908             maxLineLength =
    00909                     maxLineLength + markerOffsOnLine +
    00910                     static_cast<int>(maxMarkersSize.width());
    00911     }
    00912
    00913     for ( int dataset = 0; dataset < d->modelLabels.count(); ++dataset ) {
    00914         KDChart::AbstractLayoutItem* markerLineItem = 0;
    00915         switch( style ){
    00916             case( MarkersOnly ):
    00917                 markerLineItem = new KDChart::MarkerLayoutItem(
    00918                         diagram(),
    00919                         markerAttrs[dataset],
    00920                         brush( dataset ),
    00921                         pen( dataset ),
    00922                         Qt::AlignLeft );
    00923                 break;
    00924             case( LinesOnly ):
    00925                 markerLineItem = new KDChart::LineLayoutItem(
    00926                         diagram(),
    00927                         maxLineLength,
    00928                         pen( dataset ),
    00929                         Qt::AlignCenter );
    00930                 break;
    00931             case( MarkersAndLines ):
    00932                 markerLineItem = new KDChart::LineWithMarkerLayoutItem(
    00933                         diagram(),
    00934                         maxLineLength,
    00935                         pen( dataset ),
    00936                         markerOffsOnLine,
    00937                         markerAttrs[dataset],
    00938                         brush( dataset ),
    00939                         pen( dataset ),
    00940                         Qt::AlignCenter );
    00941                 break;
    00942             default:
    00943                 Q_ASSERT( false ); // all styles need to be handled
    00944         }
    00945         if( markerLineItem ){
    00946             d->layoutItems << markerLineItem;
    00947             if( orientation() == Qt::Vertical )
    00948                 d->layout->addItem( markerLineItem,
    00949                                     dataset*2+2, // first row is title, second is line
    00950                                     1,
    00951                                     1, 1, Qt::AlignCenter );
    00952             else
    00953                 d->layout->addItem( markerLineItem,
    00954                                     2, // all in row two
    00955                                     dataset*4 );
    00956         }
    00957
    00958         // PENDING(kalle) Other properties!
    00959         KDChart::TextLayoutItem* labelItem =
    00960             new KDChart::TextLayoutItem( text( dataset ),
    00961                 labelAttrs,
    00962                 referenceArea(), orient,
    00963                 Qt::AlignLeft );
    00964         labelItem->setParentWidget( this );
    00965
    00966         d->layoutItems << labelItem;
    00967         if( orientation() == Qt::Vertical )
    00968             d->layout->addItem( labelItem,
    00969                                 dataset*2+2, // first row is title, second is line
    00970                                 3 );
    00971         else
    00972             d->layout->addItem( labelItem,
    00973                                 2, // all in row two
    00974                                 dataset*4+1 );
    00975
    00976         // horizontal lines (only in vertical mode, and not after the last item)
    00977         if( orientation() == Qt::Vertical && showLines() && dataset != d->modelLabels.count()-1 ) {
    00978             KDChart::HorizontalLineLayoutItem* lineItem = new KDChart::HorizontalLineLayoutItem();
    00979             d->layoutItems << lineItem;
    00980             d->layout->addItem( lineItem,
    00981                                 dataset*2+1+2,
    00982                                 0,
    00983                                 1, 5, Qt::AlignCenter );
    00984         }
    00985
    00986         // vertical lines (only in horizontal mode, and not after the last item)
    00987         if( orientation() == Qt::Horizontal && showLines() && dataset != d->modelLabels.count()-1 ) {
    00988             KDChart::VerticalLineLayoutItem* lineItem = new KDChart::VerticalLineLayoutItem();
    00989             d->layoutItems << lineItem;
    00990             d->layout->addItem( lineItem,
    00991                                 2, // all in row two
    00992                                 style == MarkersAndLines ? dataset*4+3 : dataset*4+2 ,
    00993                                 1, 1, Qt::AlignCenter );
    00994         }
    00995
    00996         if( orientation() != Qt::Vertical ) { // Horizontal needs a spacer
    00997             d->layout->addItem( new QSpacerItem( spacing(), 1 ),
    00998                                 2, // all in row two
    00999                                 dataset*4+3 );
    01000         }
    01001     }
    01002
    01003     // vertical line (only in vertical mode)
    01004     if( orientation() == Qt::Vertical && showLines() && d->modelLabels.count() ) {
    01005         KDChart::VerticalLineLayoutItem* lineItem = new KDChart::VerticalLineLayoutItem();
    01006         d->layoutItems << lineItem;
    01007         d->layout->addItem( lineItem, 2, 2, d->modelLabels.count()*2, 1 );
    01008     }
    01009
    01010     // This line is absolutely necessary, otherwise: #2516.
    01011     activateTheLayout();
    01012
    01013     emit propertiesChanged();
    01014     //emit positionChanged( this );
    01015     //emitPositionChanged();
    01016 #ifdef DEBUG_LEGEND_PAINT
    01017     qDebug() << "leaving Legend::buildLegend()";
    01018 #endif
    01019 }

Legend * Legend::clone | ( |  | ) | const`[virtual]`

| Definition at line 201 of file KDChartLegend.cpp. References alignment(), d, KDChart::AbstractAreaBase::frameAttributes(), Legend(), legendStyle(), position(), setAlignment(), KDChart::AbstractAreaBase::setFrameAttributes(), setLegendStyle(), setPosition(), setTextAttributes(), setTitleTextAttributes(), setUseAutomaticMarkerSize(), textAttributes(), titleTextAttributes(), and useAutomaticMarkerSize().
    00202 {
    00203     Legend* legend = new Legend( new Private( *d ), 0 );
    00204     legend->setTextAttributes( textAttributes() );
    00205     legend->setTitleTextAttributes( titleTextAttributes() );
    00206     legend->setFrameAttributes( frameAttributes() );
    00207     legend->setUseAutomaticMarkerSize( useAutomaticMarkerSize() );
    00208     legend->setPosition( position() );
    00209     legend->setAlignment( alignment() );
    00210     legend->setLegendStyle( legendStyle() );
    00211     return legend;
    00212 }

bool AbstractAreaBase::compare | ( | const AbstractAreaBase * | other | ) | const`[inherited]`

| Returns true if both areas have the same settings. Definition at line 75 of file KDChartAbstractAreaBase.cpp.
    00076 {
    00077     if( other == this ) return true;
    00078     if( ! other ){
    00079         //qDebug() << "CartesianAxis::compare() cannot compare to Null pointer";
    00080         return false;
    00081     }
    00082     /*
    00083     qDebug() << "AbstractAreaBase:" << (frameAttributes() == other->frameAttributes())
    00084         << (backgroundAttributes() == other->backgroundAttributes()) << "\n";
    00085     */
    00086     return  (frameAttributes()      == other->frameAttributes()) &&
    00087             (backgroundAttributes() == other->backgroundAttributes());
    00088 }

bool Legend::compare | ( | const Legend * | other | ) | const

| Returns true if both axes have the same settings. Definition at line 215 of file KDChartLegend.cpp.
    00216 {
    00217     if( other == this ) return true;
    00218     if( ! other ){
    00219         //qDebug() << "Legend::compare() cannot compare to Null pointer";
    00220         return false;
    00221     }
    00222     /*
    00223     qDebug() << ( static_cast<const AbstractAreaBase*>(this)->compare( other ) );
    00224     qDebug() << (isVisible()              == other->isVisible());
    00225     qDebug() << (position()               == other->position());
    00226     qDebug() << (alignment()              == other->alignment());
    00227     qDebug() << (floatingPosition()       == other->floatingPosition());
    00228     qDebug() << (orientation()            == other->orientation());
    00229     qDebug() << (showLines()              == other->showLines());
    00230     qDebug() << (texts()                  == other->texts());
    00231     qDebug() << (brushes()                == other->brushes());
    00232     qDebug() << (pens()                   == other->pens());
    00233     qDebug() << (markerAttributes()       == other->markerAttributes());
    00234     qDebug() << (useAutomaticMarkerSize() == other->useAutomaticMarkerSize());
    00235     qDebug() << (textAttributes()         == other->textAttributes());
    00236     qDebug() << (titleText()              == other->titleText());
    00237     qDebug() << (titleTextAttributes()    == other->titleTextAttributes());
    00238     qDebug() << (spacing()                == other->spacing());
    00239     qDebug() << (legendStyle()            == other->legendStyle());
    00240     */
    00241     return  ( static_cast<const AbstractAreaBase*>(this)->compare( other ) ) &&
    00242             (isVisible()              == other->isVisible()) &&
    00243             (position()               == other->position()) &&
    00244             (alignment()              == other->alignment())&&
    00245             (floatingPosition()       == other->floatingPosition()) &&
    00246             (orientation()            == other->orientation())&&
    00247             (showLines()              == other->showLines())&&
    00248             (texts()                  == other->texts())&&
    00249             (brushes()                == other->brushes())&&
    00250             (pens()                   == other->pens())&&
    00251             (markerAttributes()       == other->markerAttributes())&&
    00252             (useAutomaticMarkerSize() == other->useAutomaticMarkerSize()) &&
    00253             (textAttributes()         == other->textAttributes()) &&
    00254             (titleText()              == other->titleText())&&
    00255             (titleTextAttributes()    == other->titleTextAttributes()) &&
    00256             (spacing()                == other->spacing()) &&
    00257             (legendStyle()            == other->legendStyle());
    00258 }

ConstDiagramList Legend::constDiagrams | ( |  | ) | const

| Returns: The list of diagrams associated with this coordinate plane. Definition at line 326 of file KDChartLegend.cpp. References KDChart::ConstDiagramList, and d.
    00327 {
    00328     ConstDiagramList list;
    00329     for (int i = 0; i < d->observers.size(); ++i)
    00330         list << d->observers.at(i)->diagram();
    00331     return list;
    00332 }

uint Legend::datasetCount | ( |  | ) | const

| Definition at line 283 of file KDChartLegend.cpp. References d, KDChart::AbstractDiagram::datasetBrushes(), KDChart::AbstractDiagram::datasetLabels(), and KDChart::DiagramObserver::diagram().
    00284 {
    00285     int modelLabelsCount = 0;
    00286     int modelBrushesCount = 0;
    00287     for (int i = 0; i < d->observers.size(); ++i) {
    00288         DiagramObserver * obs = d->observers.at(i);
    00289         modelLabelsCount  += obs->diagram()->datasetLabels().count();
    00290         modelBrushesCount += obs->diagram()->datasetBrushes().count();
    00291     }
    00292     Q_ASSERT( modelLabelsCount == modelBrushesCount );
    00293     return modelLabelsCount;
    00294 }

AbstractDiagram * Legend::diagram | ( |  | ) | const

| The first diagram of the legend or 0 if there was none added to the legend. Returns: The first diagram of the legend or 0. See also: diagrams, addDiagram, removeDiagram, removeDiagrams, replaceDiagram, setDiagram Definition at line 311 of file KDChartLegend.cpp. References d. Referenced by buildLegend(), and paint().
    00312 {
    00313     if( d->observers.isEmpty() )
    00314         return 0;
    00315     return d->observers.first()->diagram();
    00316 }

DiagramList Legend::diagrams | ( |  | ) | const

| The list of all diagrams associated with the legend. Returns: The list of all diagrams associated with the legend. See also: diagram, addDiagram, removeDiagram, removeDiagrams, replaceDiagram, setDiagram Definition at line 318 of file KDChartLegend.cpp. References d, and KDChart::DiagramList.
    00319 {
    00320     DiagramList list;
    00321     for (int i = 0; i < d->observers.size(); ++i)
    00322         list << d->observers.at(i)->diagram();
    00323     return list;
    00324 }

const RelativePosition Legend::floatingPosition | ( |  | ) | const

| Returns the position of a floating legend. See also: setFloatingPosition Definition at line 457 of file KDChartLegend.cpp. References d. Referenced by KDChart::Chart::reLayoutFloatingLegends().
    00458 {
    00459     return d->relativePosition;
    00460 }

void Legend::forceRebuild | ( |  | ) | `[virtual]`

| Call this to trigger an unconditional re-building of the widget's internals. Reimplemented from KDChart::AbstractAreaWidget. Definition at line 657 of file KDChartLegend.cpp. References buildLegend(). Referenced by resizeEvent().
    00658 {
    00659 #ifdef DEBUG_LEGEND_PAINT
    00660     qDebug() << "entering Legend::forceRebuild()";
    00661 #endif
    00662     //setSpacing(d->layout->spacing());
    00663     buildLegend();
    00664 #ifdef DEBUG_LEGEND_PAINT
    00665     qDebug() << "leaving Legend::forceRebuild()";
    00666 #endif
    00667 }

FrameAttributes AbstractAreaBase::frameAttributes | ( |  | ) | const`[inherited]`

| Definition at line 102 of file KDChartAbstractAreaBase.cpp. References d. Referenced by clone(), and updateCommonBrush().
    00103 {
    00104     return d->frameAttributes;
    00105 }

void AbstractAreaBase::getFrameLeadings | ( | int & | left,
|  | int & | top,
|  | int & | right,
|  | int & | bottom
| ) | const`[inherited]`

| Definition at line 204 of file KDChartAbstractAreaBase.cpp. References d. Referenced by KDChart::AbstractAreaBase::innerRect(), and KDChart::AbstractAreaWidget::paintAll().
    00205 {
    00206     if( d && d->frameAttributes.isVisible() ){
    00207         const int padding = qMax( d->frameAttributes.padding(), 0 );
    00208         left   = padding;
    00209         top    = padding;
    00210         right  = padding;
    00211         bottom = padding;
    00212     }else{
    00213         left   = 0;
    00214         top    = 0;
    00215         right  = 0;
    00216         bottom = 0;
    00217     }
    00218 }

QRect AbstractAreaBase::innerRect | ( |  | ) | const`[protected, inherited]`

| Definition at line 220 of file KDChartAbstractAreaBase.cpp. References KDChart::AbstractAreaBase::areaGeometry(), and KDChart::AbstractAreaBase::getFrameLeadings(). Referenced by KDChart::TextArea::paintAll(), and KDChart::AbstractArea::paintAll().
    00221 {
    00222     int left;
    00223     int top;
    00224     int right;
    00225     int bottom;
    00226     getFrameLeadings( left, top, right, bottom );
    00227     return
    00228         QRect( QPoint(0,0), areaGeometry().size() )
    00229             .adjusted( left, top, -right, -bottom );
    00230 }

Legend::LegendStyle Legend::legendStyle | ( |  | ) | const

| Definition at line 196 of file KDChartLegend.cpp. References d. Referenced by buildLegend(), and clone().
    00197 {
    00198     return d->legendStyle;
    00199 }

const QMap< uint, MarkerAttributes > Legend::markerAttributes | ( |  | ) | const

| Definition at line 615 of file KDChartLegend.cpp. References d. Referenced by buildLegend().
    00616 {
    00617     return d->markerAttributes;
    00618 }

MarkerAttributes Legend::markerAttributes | ( | uint | dataset | ) | const

| Definition at line 606 of file KDChartLegend.cpp. References d.
    00607 {
    00608     if( d->markerAttributes.find( dataset ) != d->markerAttributes.end() )
    00609         return d->markerAttributes[ dataset ];
    00610     else if ( static_cast<uint>( d->modelMarkers.count() ) > dataset )
    00611         return d->modelMarkers[ dataset ];
    00612     return MarkerAttributes();
    00613 }

QSize Legend::minimumSizeHint | ( |  | ) | const`[virtual]`

| Definition at line 143 of file KDChartLegend.cpp. References sizeHint().
    00144 {
    00145     return sizeHint();
    00146 }

void Legend::needSizeHint | ( |  | ) | `[virtual]`

| Call this to trigger an conditional re-building of the widget's internals. e.g. AbstractAreaWidget call this, before calling layout()->setGeometry() Reimplemented from KDChart::AbstractAreaWidget. Definition at line 161 of file KDChartLegend.cpp. References buildLegend().
    00162 {
    00163     // Re-build the Legend's content, if it has not been build yet,
    00164     // or if the Legend's geometry has changed, resp.
    00165     buildLegend();
    00166 }

Qt::Orientation Legend::orientation | ( |  | ) | const

| Definition at line 470 of file KDChartLegend.cpp. References d. Referenced by buildLegend().
    00471 {
    00472     return d->orientation;
    00473 }

void Legend::paint | ( | QPainter * | painter | ) | `[virtual]`

| Overwrite this to paint the inner contents of your widget. Note: When overriding this method, please let your widget draw itself at the top/left corner of the painter. You should call rect() (or width(), height(), resp.) to find the drawable area's size: While the paint() method is being executed the frame of the widget is outside of its rect(), so you can use all of rect() for your custom drawing! See also: paint, paintIntoRect Implements KDChart::AbstractAreaWidget. Definition at line 261 of file KDChartLegend.cpp. References d, diagram(), and KDChart::AbstractLayoutItem::paint().
    00262 {
    00263 #ifdef DEBUG_LEGEND_PAINT
    00264     qDebug() << "entering Legend::paint( QPainter* painter )";
    00265 #endif
    00266     // rule: We do not show a legend, if there is no diagram.
    00267     if( ! diagram() ) return;
    00268
    00269     // re-calculate/adjust the Legend's internal layout and contents, if needed:
    00270     //buildLegend();
    00271
    00272     // PENDING(kalle) Support palette
    00273
    00274     Q_FOREACH( KDChart::AbstractLayoutItem* layoutItem, d->layoutItems ) {
    00275         layoutItem->paint( painter );
    00276     }
    00277 #ifdef DEBUG_LEGEND_PAINT
    00278     qDebug() << "leaving Legend::paint( QPainter* painter )";
    00279 #endif
    00280 }

void AbstractAreaWidget::paintAll | ( | QPainter & | painter | ) | `[inherited]`

| Call paintAll, if you want the background and the frame to be drawn before the normal paint() is invoked automatically. Definition at line 145 of file KDChartAbstractAreaWidget.cpp. References KDChart::AbstractAreaBase::getFrameLeadings(), KDChart::AbstractAreaWidget::paint(), KDChart::AbstractAreaBase::paintBackground(), and KDChart::AbstractAreaBase::paintFrame(). Referenced by KDChart::AbstractAreaWidget::paintEvent(), and KDChart::AbstractAreaWidget::paintIntoRect().
    00146 {
    00147     //qDebug() << "AbstractAreaWidget::paintAll() called";
    00148
    00149     // Paint the background and frame
    00150     paintBackground( painter, QRect(QPoint(0, 0), size() ) );
    00151     paintFrame(      painter, QRect(QPoint(0, 0), size() ) );
    00152
    00153 /*
    00154     we do not call setContentsMargins() now,
    00155     but we call resizeLayout() whenever the size or the frame has changed
    00156
    00157     // adjust the widget's content margins,
    00158     // to be sure all content gets calculated
    00159     // to fit into the inner rectangle
    00160     const QRect oldGeometry( areaGeometry()  );
    00161     const QRect inner( innerRect() );
    00162     //qDebug() << "areaGeometry():" << oldGeometry
    00163     //         << "  contentsRect():" << contentsRect() << "  inner:" << inner;
    00164     if( contentsRect() != inner ){
    00165         //qDebug() << "old contentsRect():" << contentsRect() << "  new innerRect:" << inner;
    00166         setContentsMargins(
    00167             inner.left(),
    00168             inner.top(),
    00169             oldGeometry.width() -inner.width()-1,
    00170             oldGeometry.height()-inner.height()-1 );
    00171         //forceRebuild();
    00172     }
    00173 */
    00174     int left;
    00175     int top;
    00176     int right;
    00177     int bottom;
    00178     getFrameLeadings( left, top, right, bottom );
    00179     const QPoint translation( left, top );
    00180     painter.translate( translation );
    00181     paint( &painter );
    00182     painter.translate( -translation.x(), -translation.y() );
    00183      //qDebug() << "AbstractAreaWidget::paintAll() done.";
    00184 }

void AbstractAreaBase::paintBackground | ( | QPainter & | painter,
|  | const QRect & | rectangle
| ) | `[virtual, inherited]`

| Definition at line 188 of file KDChartAbstractAreaBase.cpp. References d, and KDChart::AbstractAreaBase::paintBackgroundAttributes(). Referenced by KDChart::TextArea::paintAll(), KDChart::AbstractAreaWidget::paintAll(), and KDChart::AbstractArea::paintAll().
    00189 {
    00190     Q_ASSERT_X ( d != 0, "AbstractAreaBase::paintBackground()",
    00191                 "Private class was not initialized!" );
    00192     paintBackgroundAttributes( painter, rect, d->backgroundAttributes );
    00193 }

void AbstractAreaBase::paintBackgroundAttributes | ( | QPainter & | painter,
|  | const QRect & | rectangle,
|  | const KDChart::BackgroundAttributes & | attributes
| ) | `[static, inherited]`

| Definition at line 119 of file KDChartAbstractAreaBase.cpp. References KDChart::BackgroundAttributes::brush(), KDChart::BackgroundAttributes::isVisible(), KDChart::BackgroundAttributes::pixmap(), and KDChart::BackgroundAttributes::pixmapMode(). Referenced by KDChart::AbstractAreaBase::paintBackground().
    00121 {
    00122     if( !attributes.isVisible() ) return;
    00123
    00124     /* first draw the brush (may contain a pixmap)*/
    00125     if( Qt::NoBrush != attributes.brush().style() ) {
    00126         KDChart::PainterSaver painterSaver( &painter );
    00127         painter.setPen( Qt::NoPen );
    00128         const QPointF newTopLeft( painter.deviceMatrix().map( rect.topLeft() ) );
    00129         painter.setBrushOrigin( newTopLeft );
    00130         painter.setBrush( attributes.brush() );
    00131         painter.drawRect( rect.adjusted( 0, 0, -1, -1 ) );
    00132     }
    00133     /* next draw the backPixmap over the brush */
    00134     if( !attributes.pixmap().isNull() &&
    00135         attributes.pixmapMode() != BackgroundAttributes::BackgroundPixmapModeNone ) {
    00136         QPointF ol = rect.topLeft();
    00137         if( BackgroundAttributes::BackgroundPixmapModeCentered == attributes.pixmapMode() )
    00138         {
    00139             ol.setX( rect.center().x() - attributes.pixmap().width() / 2 );
    00140             ol.setY( rect.center().y() - attributes.pixmap().height()/ 2 );
    00141             painter.drawPixmap( ol, attributes.pixmap() );
    00142         } else {
    00143             QMatrix m;
    00144             double zW = (double)rect.width()  / (double)attributes.pixmap().width();
    00145             double zH = (double)rect.height() / (double)attributes.pixmap().height();
    00146             switch( attributes.pixmapMode() ) {
    00147             case BackgroundAttributes::BackgroundPixmapModeScaled:
    00148             {
    00149                 double z;
    00150                 z = qMin( zW, zH );
    00151                 m.scale( z, z );
    00152             }
    00153             break;
    00154             case BackgroundAttributes::BackgroundPixmapModeStretched:
    00155                 m.scale( zW, zH );
    00156                 break;
    00157             default:
    00158                 ; // Cannot happen, previously checked
    00159             }
    00160             QPixmap pm = attributes.pixmap().transformed( m );
    00161             ol.setX( rect.center().x() - pm.width() / 2 );
    00162             ol.setY( rect.center().y() - pm.height()/ 2 );
    00163             painter.drawPixmap( ol, pm );
    00164         }
    00165     }
    00166 }

void AbstractAreaWidget::paintEvent | ( | QPaintEvent * | event | ) | `[virtual, inherited]`

| Draws the background and frame, then calls paint(). In most cases there is no need to overwrite this method in a derived class, but you would overwrite paint() instead. See also: paint Definition at line 99 of file KDChartAbstractAreaWidget.cpp. References d, and KDChart::AbstractAreaWidget::paintAll().
    00100 {
    00101     Q_UNUSED( event );
    00102     QPainter painter( this );
    00103     if( size() != d->currentLayoutSize ){
    00104         d->resizeLayout( this, size() );
    00105     }
    00106     paintAll( painter );
    00107 }

void AbstractAreaBase::paintFrame | ( | QPainter & | painter,
|  | const QRect & | rectangle
| ) | `[virtual, inherited]`

| Definition at line 196 of file KDChartAbstractAreaBase.cpp. References d, and KDChart::AbstractAreaBase::paintFrameAttributes(). Referenced by KDChart::TextArea::paintAll(), KDChart::AbstractAreaWidget::paintAll(), and KDChart::AbstractArea::paintAll().
    00197 {
    00198     Q_ASSERT_X ( d != 0, "AbstractAreaBase::paintFrame()",
    00199                 "Private class was not initialized!" );
    00200     paintFrameAttributes( painter, rect, d->frameAttributes );
    00201 }

void AbstractAreaBase::paintFrameAttributes | ( | QPainter & | painter,
|  | const QRect & | rectangle,
|  | const KDChart::FrameAttributes & | attributes
| ) | `[static, inherited]`

| Definition at line 169 of file KDChartAbstractAreaBase.cpp. References KDChart::FrameAttributes::isVisible(), and KDChart::FrameAttributes::pen(). Referenced by KDChart::AbstractAreaBase::paintFrame().
    00171 {
    00172
    00173     if( !attributes.isVisible() ) return;
    00174
    00175     // Note: We set the brush to NoBrush explicitely here.
    00176     //       Otherwise we might get a filled rectangle, so any
    00177     //       previously drawn background would be overwritten by that area.
    00178
    00179     const QPen   oldPen(   painter.pen() );
    00180     const QBrush oldBrush( painter.brush() );
    00181     painter.setPen(   attributes.pen() );
    00182     painter.setBrush( Qt::NoBrush );
    00183     painter.drawRect( rect.adjusted( 0, 0, -1, -1 ) );
    00184     painter.setBrush( oldBrush );
    00185     painter.setPen(   oldPen );
    00186 }

void AbstractAreaWidget::paintIntoRect | ( | QPainter & | painter,
|  | const QRect & | rect
| ) | `[virtual, inherited]`

| Draws the background and frame, then calls paint(). In most cases there is no need to overwrite this method in a derived class, but you would overwrite paint() instead. Definition at line 109 of file KDChartAbstractAreaWidget.cpp. References d, and KDChart::AbstractAreaWidget::paintAll(). Referenced by KDChart::Chart::paint().
    00110 {
    00111     //qDebug() << "AbstractAreaWidget::paintIntoRect() called rect=" << rect;
    00112
    00113     if( rect.isEmpty() ) return;
    00114
    00115     d->resizeLayout( this, rect.size() );
    00116
    00117     const QPoint translation( rect.topLeft() );
    00118     painter.translate( translation );
    00119     paintAll( painter );
    00120     painter.translate( -translation.x(), -translation.y() );
    00121
    00122 /*
    00123     // make sure, the contents of the widget have been set up,
    00124     // so we get a usefull geometry:
    00125     needSizeHint();
    00126
    00127     const QRect oldGeometry( layout()->geometry() );
    00128     const QRect newGeo( QPoint(0,0), rect.size() );
    00129     const bool mustChangeGeo = layout() && oldGeometry != newGeo;
    00130     if( mustChangeGeo )
    00131         layout()->setGeometry( newGeo );
    00132     painter.translate( rect.left(), rect.top() );
    00133     paintAll( painter );
    00134     painter.translate( -rect.left(), -rect.top() );
    00135     if( mustChangeGeo )
    00136         layout()->setGeometry( oldGeometry );
    00137 */
    00138 }

QPen Legend::pen | ( | uint | dataset | ) | const

| Definition at line 585 of file KDChartLegend.cpp. References d. Referenced by buildLegend().
    00586 {
    00587     if( d->pens.find( dataset ) != d->pens.end() )
    00588         return d->pens[dataset];
    00589     else
    00590         return d->modelPens[ dataset ];
    00591 }

const QMap< uint, QPen > Legend::pens | ( |  | ) | const

| Definition at line 593 of file KDChartLegend.cpp. References d.
    00594 {
    00595     return d->pens;
    00596 }

Position Legend::position | ( |  | ) | const

| Returns the position of a non-floating legend. See also: setPosition Definition at line 432 of file KDChartLegend.cpp. References d. Referenced by clone(), and KDChart::Chart::reLayoutFloatingLegends().
    00433 {
    00434     return d->position;
    00435 }

void AbstractAreaWidget::positionHasChanged | ( |  | ) | `[protected, virtual, inherited]`

| Reimplemented from KDChart::AbstractAreaBase. Definition at line 191 of file KDChartAbstractAreaWidget.cpp.
    00192 {
    00193     emit positionChanged( this );
    00194 }

void KDChart::Legend::propertiesChanged | ( |  | ) |

| Emitted upon change of a property of the Legend or any of its components. Referenced by buildLegend().

const QWidget * Legend::referenceArea | ( |  | ) | const

| Returns the reference area, that is used for font size of title text, and for font size of the item texts, IF automatic area detection is set. See also: setReferenceArea Definition at line 304 of file KDChartLegend.cpp. References d. Referenced by buildLegend().
    00305 {
    00306     //qDebug() << d->referenceArea;
    00307     return (d->referenceArea ? d->referenceArea : static_cast<const QWidget*>(parent()));
    00308 }

void Legend::removeDiagram | ( | KDChart::AbstractDiagram * | oldDiagram | ) |

| Removes the diagram from the legend's list of diagrams. See also: diagram, diagrams, addDiagram, removeDiagrams, replaceDiagram, setDiagram Definition at line 359 of file KDChartLegend.cpp. References d, and setNeedRebuild(). Referenced by removeDiagrams(), replaceDiagram(), and resetDiagram().
    00360 {
    00361     if( oldDiagram ){
    00362         DiagramObserver* oldObs = d->findObserverForDiagram( oldDiagram );
    00363         if( oldObs ){
    00364             //qDebug() << "before delete oldObs;";
    00365             delete oldObs;
    00366             //qDebug() << "after delete oldObs;";
    00367             d->observers.removeAt( d->observers.indexOf( oldObs ) );
    00368             //qDebug() << "after d->observers.removeAt()";
    00369         }
    00370         setNeedRebuild();
    00371     }
    00372 }

void Legend::removeDiagrams | ( |  | ) |

| Removes all of the diagram from the legend's list of diagrams. See also: diagram, diagrams, addDiagram, removeDiagram, replaceDiagram, setDiagram Definition at line 374 of file KDChartLegend.cpp. References d, and removeDiagram().
    00375 {
    00376     for (int i = 0; i < d->observers.size(); ++i)
    00377         removeDiagram( d->observers.at(i)->diagram() );
    00378 }

void Legend::replaceDiagram | ( | KDChart::AbstractDiagram * | newDiagram,
|  | KDChart::AbstractDiagram * | oldDiagram = 0
| ) |

  | Replaces the old diagram, or appends the new diagram, it there is none yet. Parameters:
  newDiagram | The diagram to be used instead of the old one. If this parameter is zero, the first diagram will just be removed.
  oldDiagram | The diagram to be removed by the new one. This diagram will be deleted automatically. If the parameter is omitted, the very first diagram will be replaced. In case, there was no diagram yet, the new diagram will just be added.
See also: diagram, diagrams, addDiagram, removeDiagram, removeDiagrams, setDiagram Definition at line 380 of file KDChartLegend.cpp. References addDiagram(), d, and removeDiagram(). Referenced by setDiagram().
    00382 {
    00383     KDChart::AbstractDiagram* old = oldDiagram;
    00384     if( ! d->observers.isEmpty() && ! old ){
    00385         old = d->observers.first()->diagram();
    00386         if( ! old )
    00387             d->observers.removeFirst(); // first entry had a 0 diagram
    00388     }
    00389     if( old )
    00390         removeDiagram( old );
    00391     if( newDiagram )
    00392         addDiagram( newDiagram );
    00393 }

void Legend::resetDiagram | ( | AbstractDiagram * |  | ) |

| Definition at line 400 of file KDChartLegend.cpp. References removeDiagram(). Referenced by addDiagram().
    00401 {
    00402     //qDebug() << oldDiagram;
    00403     removeDiagram( oldDiagram );
    00404 }

void Legend::resetTexts | ( |  | ) |

| Removes all legend texts that might have been set by setText. This resets the Legend to default behaviour: Texts are created automatically. Definition at line 505 of file KDChartLegend.cpp. References d, and setNeedRebuild().
    00506 {
    00507     if( ! d->texts.count() ) return;
    00508     d->texts.clear();
    00509     setNeedRebuild();
    00510 }

void Legend::resizeEvent | ( | QResizeEvent * | event | ) | `[virtual]`

| Definition at line 760 of file KDChartLegend.cpp. References forceRebuild(), and sizeHint().
    00761 {
    00762 #ifdef DEBUG_LEGEND_PAINT
    00763     qDebug() << "Legend::resizeEvent() called";
    00764 #endif
    00765     forceRebuild();
    00766     sizeHint();
    00767     QTimer::singleShot(0, this, SLOT(emitPositionChanged()));
    00768 }

void Legend::resizeLayout | ( | const QSize & | size | ) | `[virtual]`

| Reimplemented from KDChart::AbstractAreaWidget. Definition at line 168 of file KDChartLegend.cpp. References activateTheLayout(), and d.
    00169 {
    00170 #ifdef DEBUG_LEGEND_PAINT
    00171     qDebug() << "Legend::resizeLayout started";
    00172 #endif
    00173     if( d->layout ){
    00174         d->layout->setGeometry( QRect(QPoint(0,0), size) );
    00175         activateTheLayout();
    00176     }
    00177 #ifdef DEBUG_LEGEND_PAINT
    00178     qDebug() << "Legend::resizeLayout done";
    00179 #endif
    00180 }

void Legend::setAlignment | ( | Qt::Alignment |  | ) |

| Specify the alignment of a non-floating legend. Use setFloatingPosition to set position and alignment if your legend is floating. See also: alignment, setPosition, setFloatingPosition Definition at line 437 of file KDChartLegend.cpp. References d. Referenced by clone().
    00438 {
    00439     d->alignment = alignment;
    00440     emitPositionChanged();
    00441 }

void AbstractAreaBase::setBackgroundAttributes | ( | const BackgroundAttributes & | a | ) | `[inherited]`

| Definition at line 107 of file KDChartAbstractAreaBase.cpp. References d.
    00108 {
    00109     d->backgroundAttributes = a;
    00110 }

void Legend::setBrush | ( | uint | dataset,
|  | const QBrush & | brush
| ) |

| Definition at line 542 of file KDChartLegend.cpp. References d, and setNeedRebuild().
    00543 {
    00544     if( d->brushes[ dataset ] == brush ) return;
    00545     d->brushes[ dataset ] = brush;
    00546     setNeedRebuild();
    00547 }

void Legend::setBrushesFromDiagram | ( | KDChart::AbstractDiagram * | diagram | ) |

| Definition at line 563 of file KDChartLegend.cpp. References d, KDChart::AbstractDiagram::datasetBrushes(), and setNeedRebuild().
    00564 {
    00565     bool bChangesDone = false;
    00566     QList<QBrush> datasetBrushes = diagram->datasetBrushes();
    00567     for( int i = 0; i < datasetBrushes.count(); i++ ){
    00568         if( d->brushes[ i ] != datasetBrushes[ i ] ){
    00569             d->brushes[ i ]  = datasetBrushes[ i ];
    00570             bChangesDone = true;
    00571         }
    00572     }
    00573     if( bChangesDone )
    00574         setNeedRebuild();
    00575 }

void Legend::setColor | ( | uint | dataset,
|  | const QColor & | color
| ) |

| Note: there is no color() getter method, since setColor just sets a QBrush with the respective color, so the brush() getter method is sufficient. Definition at line 535 of file KDChartLegend.cpp. References d, and setNeedRebuild(). Referenced by setDefaultColors(), setRainbowColors(), and setSubduedColors().
    00536 {
    00537     if( d->brushes[ dataset ] == color ) return;
    00538     d->brushes[ dataset ] = color;
    00539     setNeedRebuild();
    00540 }

void Legend::setDefaultColors | ( |  | ) |

| Definition at line 682 of file KDChartLegend.cpp. References setColor().
    00683 {
    00684     setColor(  0, Qt::red );
    00685     setColor(  1, Qt::green );
    00686     setColor(  2, Qt::blue );
    00687     setColor(  3, Qt::cyan );
    00688     setColor(  4, Qt::magenta );
    00689     setColor(  5, Qt::yellow );
    00690     setColor(  6, Qt::darkRed );
    00691     setColor(  7, Qt::darkGreen );
    00692     setColor(  8, Qt::darkBlue );
    00693     setColor(  9, Qt::darkCyan );
    00694     setColor( 10, Qt::darkMagenta );
    00695     setColor( 11, Qt::darkYellow );
    00696 }

void Legend::setDiagram | ( | KDChart::AbstractDiagram * | newDiagram | ) |

| A convenience method doing the same as replaceDiagram( newDiagram, 0 );. Replaces the first diagram by the given diagram. If the legend's list of diagram is empty the given diagram is added to the list. See also: diagram, diagrams, addDiagram, removeDiagram, removeDiagrams, replaceDiagram Definition at line 395 of file KDChartLegend.cpp. References replaceDiagram(). Referenced by KDChart::Widget::addLegend(), Legend(), and KDChart::Widget::replaceLegend().
    00396 {
    00397     replaceDiagram( newDiagram );
    00398 }

void Legend::setFloatingPosition | ( | const RelativePosition & | relativePosition | ) |

| Specify the position and alignment of a floating legend. Use setPosition and setAlignment to set position and alignment if your legend is non-floating. Note: When setFloatingPosition is called, the Legend's position value is set to KDChart::Position::Floating automatically. If your Chart is pointed to by m_chart, your could have the floating legend alligned exactly to the chart's coordinate plane's top-right corner with the following commands:
    KDChart::RelativePosition relativePosition;
    relativePosition.setReferenceArea( m_chart->coordinatePlane() );
    relativePosition.setReferencePosition( Position::NorthEast );
    relativePosition.setAlignment( Qt::AlignTop | Qt::AlignRight );
    relativePosition.setHorizontalPadding(
        KDChart::Measure( -1.0, KDChartEnums::MeasureCalculationModeAbsolute ) );
    relativePosition.setVerticalPadding(
        KDChart::Measure( 0.0, KDChartEnums::MeasureCalculationModeAbsolute ) );
    m_legend->setFloatingPosition( relativePosition );
To have the legend positioned at a fixed point, measured from the QPainter's top left corner, you could use the following code code:
    KDChart::RelativePosition relativePosition;
    relativePosition.setReferencePoints( PositionPoints( QPointF( 0.0, 0.0 ) ) );
    relativePosition.setReferencePosition( Position::NorthWest );
    relativePosition.setAlignment( Qt::AlignTop | Qt::AlignLeft );
    relativePosition.setHorizontalPadding(
        KDChart::Measure( 4.0, KDChartEnums::MeasureCalculationModeAbsolute ) );
    relativePosition.setVerticalPadding(
        KDChart::Measure( 4.0, KDChartEnums::MeasureCalculationModeAbsolute ) );
    m_legend->setFloatingPosition( relativePosition );
Actually that's exactly the code KD Chart is using as default position for any floating legends, so if you just say setPosition( KDChart::Position::Floating ) without calling setFloatingPosition your legend will be positioned at point 4/4. See also: setPosition, setAlignment Definition at line 448 of file KDChartLegend.cpp. References d.
    00449 {
    00450     d->position = Position::Floating;
    00451     if( d->relativePosition != relativePosition ){
    00452         d->relativePosition  = relativePosition;
    00453         emitPositionChanged();
    00454     }
    00455 }

void AbstractAreaBase::setFrameAttributes | ( | const FrameAttributes & | a | ) | `[inherited]`

| Definition at line 97 of file KDChartAbstractAreaBase.cpp. References d. Referenced by clone().
    00098 {
    00099     d->frameAttributes = a;
    00100 }

void Legend::setLegendStyle | ( | LegendStyle | style | ) |

| Definition at line 189 of file KDChartLegend.cpp. References d, and setNeedRebuild(). Referenced by clone().
    00190 {
    00191     if( d->legendStyle == style ) return;
    00192     d->legendStyle = style;
    00193     setNeedRebuild();
    00194 }

void Legend::setMarkerAttributes | ( | uint | dataset,
|  | const MarkerAttributes & |
| ) |

| Note that any sizes specified via setMarkerAttributes are ignored, unless you disable the automatic size calculation, by saying setUseAutomaticMarkerSize( false ). Definition at line 599 of file KDChartLegend.cpp. References d, and setNeedRebuild().
    00600 {
    00601     if( d->markerAttributes[dataset] == markerAttributes ) return;
    00602     d->markerAttributes[ dataset ] = markerAttributes;
    00603     setNeedRebuild();
    00604 }

void Legend::setNeedRebuild | ( |  | ) |

| Definition at line 412 of file KDChartLegend.cpp. References buildLegend(), and sizeHint(). Referenced by addDiagram(), removeDiagram(), resetTexts(), setBrush(), setBrushesFromDiagram(), setColor(), setLegendStyle(), setMarkerAttributes(), setOrientation(), setPen(), setReferenceArea(), setShowLines(), setSpacing(), setText(), setTextAttributes(), setTitleText(), setTitleTextAttributes(), and setUseAutomaticMarkerSize().
    00413 {
    00414     //qDebug() << "setNeedRebuild()";
    00415     buildLegend();
    00416     sizeHint();
    00417 }

void Legend::setOrientation | ( | Qt::Orientation | orientation | ) |

| Definition at line 462 of file KDChartLegend.cpp. References d, and setNeedRebuild().
    00463 {
    00464     if( d->orientation == orientation ) return;
    00465     d->orientation = orientation;
    00466     setNeedRebuild();
    00467     emitPositionChanged();
    00468 }

void Legend::setPen | ( | uint | dataset,
|  | const QPen & | pen
| ) |

| Definition at line 578 of file KDChartLegend.cpp. References d, and setNeedRebuild().
    00579 {
    00580     if( d->pens[dataset] == pen ) return;
    00581     d->pens[dataset] = pen;
    00582     setNeedRebuild();
    00583 }

void Legend::setPosition | ( | Position | position | ) |

| Specify the position of a non-floating legend. Use setFloatingPosition to set position and alignment if your legend is floating. See also: setAlignment, setFloatingPosition Definition at line 419 of file KDChartLegend.cpp. References d. Referenced by KDChart::Widget::addLegend(), and clone().
    00420 {
    00421     d->position = position;
    00422     emitPositionChanged();
    00423 }

void Legend::setRainbowColors | ( |  | ) |

| Definition at line 698 of file KDChartLegend.cpp. References brush(), and setColor().
    00699 {
    00700     setColor(  0, QColor(255,  0,196) );
    00701     setColor(  1, QColor(255,  0, 96) );
    00702     setColor(  2, QColor(255, 128,64) );
    00703     setColor(  3, Qt::yellow );
    00704     setColor(  4, Qt::green );
    00705     setColor(  5, Qt::cyan );
    00706     setColor(  6, QColor( 96, 96,255) );
    00707     setColor(  7, QColor(160,  0,255) );
    00708     for( int i = 8; i < 16; ++i )
    00709         setColor( i, brush( i - 8 ).color().light() );
    00710 }

void Legend::setReferenceArea | ( | const QWidget * | area | ) |

| Specifies the reference area for font size of title text, and for font size of the item texts, IF automatic area detection is set. Note: This parameter is ignored, if the Measure given for setTitleTextAttributes (or setTextAttributes, resp.) is not specifying automatic area detection. If no reference area is specified, but automatic area detection is set, then the size of the legend's parent widget will be used. See also: KDChart::Measure, KDChartEnums::MeasureCalculationMode Definition at line 297 of file KDChartLegend.cpp. References d, and setNeedRebuild(). Referenced by KDChart::Chart::addLegend().
    00298 {
    00299     if( area == d->referenceArea ) return;
    00300     d->referenceArea = area;
    00301     setNeedRebuild();
    00302 }

void Legend::setShowLines | ( | bool | legendShowLines | ) |

| Definition at line 475 of file KDChartLegend.cpp. References d, and setNeedRebuild().
    00476 {
    00477     if( d->showLines == legendShowLines ) return;
    00478     d->showLines = legendShowLines;
    00479     setNeedRebuild();
    00480     emitPositionChanged();
    00481 }

void Legend::setSpacing | ( | uint | space | ) |

| Definition at line 669 of file KDChartLegend.cpp. References d, and setNeedRebuild().
    00670 {
    00671     if( d->spacing == space && d->layout->spacing() == static_cast<int>(space) ) return;
    00672     d->spacing = space;
    00673     d->layout->setSpacing( space );
    00674     setNeedRebuild();
    00675 }

void Legend::setSubduedColors | ( | bool | ordered = false | ) |

| Definition at line 712 of file KDChartLegend.cpp. References setColor().
    00713 {
    00714 static const int NUM_SUBDUEDCOLORS = 18;
    00715 static const QColor SUBDUEDCOLORS[ NUM_SUBDUEDCOLORS ] = {
    00716     QColor( 0xe0,0x7f,0x70 ),
    00717     QColor( 0xe2,0xa5,0x6f ),
    00718     QColor( 0xe0,0xc9,0x70 ),
    00719     QColor( 0xd1,0xe0,0x70 ),
    00720     QColor( 0xac,0xe0,0x70 ),
    00721     QColor( 0x86,0xe0,0x70 ),
    00722     QColor( 0x70,0xe0,0x7f ),
    00723     QColor( 0x70,0xe0,0xa4 ),
    00724     QColor( 0x70,0xe0,0xc9 ),
    00725     QColor( 0x70,0xd1,0xe0 ),
    00726     QColor( 0x70,0xac,0xe0 ),
    00727     QColor( 0x70,0x86,0xe0 ),
    00728     QColor( 0x7f,0x70,0xe0 ),
    00729     QColor( 0xa4,0x70,0xe0 ),
    00730     QColor( 0xc9,0x70,0xe0 ),
    00731     QColor( 0xe0,0x70,0xd1 ),
    00732     QColor( 0xe0,0x70,0xac ),
    00733     QColor( 0xe0,0x70,0x86 ),
    00734 };
    00735     if( ordered )
    00736         for(int i=0; i<NUM_SUBDUEDCOLORS; ++i)
    00737             setColor( i, SUBDUEDCOLORS[i] );
    00738     else{
    00739         setColor( 0, SUBDUEDCOLORS[ 0] );
    00740         setColor( 1, SUBDUEDCOLORS[ 5] );
    00741         setColor( 2, SUBDUEDCOLORS[10] );
    00742         setColor( 3, SUBDUEDCOLORS[15] );
    00743         setColor( 4, SUBDUEDCOLORS[ 2] );
    00744         setColor( 5, SUBDUEDCOLORS[ 7] );
    00745         setColor( 6, SUBDUEDCOLORS[12] );
    00746         setColor( 7, SUBDUEDCOLORS[17] );
    00747         setColor( 8, SUBDUEDCOLORS[ 4] );
    00748         setColor( 9, SUBDUEDCOLORS[ 9] );
    00749         setColor(10, SUBDUEDCOLORS[14] );
    00750         setColor(11, SUBDUEDCOLORS[ 1] );
    00751         setColor(12, SUBDUEDCOLORS[ 6] );
    00752         setColor(13, SUBDUEDCOLORS[11] );
    00753         setColor(14, SUBDUEDCOLORS[16] );
    00754         setColor(15, SUBDUEDCOLORS[ 3] );
    00755         setColor(16, SUBDUEDCOLORS[ 8] );
    00756         setColor(17, SUBDUEDCOLORS[13] );
    00757     }
    00758 }

void Legend::setText | ( | uint | dataset,
|  | const QString & | text
| ) |

| Definition at line 512 of file KDChartLegend.cpp. References d, and setNeedRebuild().
    00513 {
    00514     if( d->texts[ dataset ] == text ) return;
    00515     d->texts[ dataset ] = text;
    00516     setNeedRebuild();
    00517 }

void Legend::setTextAttributes | ( | const TextAttributes & | a | ) |

| Definition at line 621 of file KDChartLegend.cpp. References d, and setNeedRebuild(). Referenced by KDChart::Chart::addLegend(), and clone().
    00622 {
    00623     if( d->textAttributes == a ) return;
    00624     d->textAttributes = a;
    00625     setNeedRebuild();
    00626 }

void Legend::setTitleText | ( | const QString & | text | ) |

| Definition at line 633 of file KDChartLegend.cpp. References d, and setNeedRebuild().
    00634 {
    00635     if( d->titleText == text ) return;
    00636     d->titleText = text;
    00637     setNeedRebuild();
    00638 }

void Legend::setTitleTextAttributes | ( | const TextAttributes & | a | ) |

| Definition at line 645 of file KDChartLegend.cpp. References d, and setNeedRebuild(). Referenced by KDChart::Chart::addLegend(), and clone().
    00646 {
    00647     if( d->titleTextAttributes == a ) return;
    00648     d->titleTextAttributes = a;
    00649     setNeedRebuild();
    00650 }

void Legend::setUseAutomaticMarkerSize | ( | bool | useAutomaticMarkerSize | ) |

| This option is on by default, it means that Marker sizes in the Legend will be the same as the font height used for their respective label texts. Set this to false, if you want to specify the marker sizes via setMarkerAttributes or if you want the Legend to use the same marker sizes as they are used in the Diagrams. Definition at line 488 of file KDChartLegend.cpp. References d, and setNeedRebuild(). Referenced by clone().
    00489 {
    00490     d->useAutomaticMarkerSize = useAutomaticMarkerSize;
    00491     setNeedRebuild();
    00492     emitPositionChanged();
    00493 }

void Legend::setVisible | ( | bool | visible | ) | `[virtual]`

| Definition at line 406 of file KDChartLegend.cpp. Referenced by KDChart::Chart::addLegend().
    00407 {
    00408     QWidget::setVisible( visible );
    00409     emitPositionChanged();
    00410 }

bool Legend::showLines | ( |  | ) | const

| Definition at line 483 of file KDChartLegend.cpp. References d. Referenced by buildLegend().
    00484 {
    00485     return d->showLines;
    00486 }

QSize Legend::sizeHint | ( |  | ) | const`[virtual]`

| Definition at line 150 of file KDChartLegend.cpp. References d. Referenced by minimumSizeHint(), KDChart::Chart::reLayoutFloatingLegends(), resizeEvent(), and setNeedRebuild().
    00151 {
    00152 #ifdef DEBUG_LEGEND_PAINT
    00153     qDebug()  << "Legend::sizeHint() started";
    00154 #endif
    00155     Q_FOREACH( KDChart::AbstractLayoutItem* layoutItem, d->layoutItems ) {
    00156         layoutItem->sizeHint();
    00157     }
    00158     return AbstractAreaWidget::sizeHint();
    00159 }

uint Legend::spacing | ( |  | ) | const

| Definition at line 677 of file KDChartLegend.cpp. References d. Referenced by buildLegend().
    00678 {
    00679     return d->spacing;
    00680 }

QString Legend::text | ( | uint | dataset | ) | const

| Definition at line 519 of file KDChartLegend.cpp. References d. Referenced by buildLegend().
    00520 {
    00521     if( d->texts.find( dataset ) != d->texts.end() ){
    00522         //qDebug() << "Legend::text(" << dataset << ") returning d->texts[" << dataset << "] :" << d->texts[ dataset ];
    00523         return d->texts[ dataset ];
    00524     }else{
    00525         //qDebug() << "Legend::text(" << dataset << ") returning d->modelLabels[" << dataset << "] :" << d->modelLabels[ dataset ];
    00526         return d->modelLabels[ dataset ];
    00527     }
    00528 }

TextAttributes Legend::textAttributes | ( |  | ) | const

| Definition at line 628 of file KDChartLegend.cpp. References d. Referenced by KDChart::Chart::addLegend(), buildLegend(), and clone().
    00629 {
    00630     return d->textAttributes;
    00631 }

const QMap< uint, QString > Legend::texts | ( |  | ) | const

| Definition at line 530 of file KDChartLegend.cpp. References d.
    00531 {
    00532     return d->texts;
    00533 }

QString Legend::titleText | ( |  | ) | const

| Definition at line 640 of file KDChartLegend.cpp. References d. Referenced by buildLegend().
    00641 {
    00642     return d->titleText;
    00643 }

TextAttributes Legend::titleTextAttributes | ( |  | ) | const

| Definition at line 652 of file KDChartLegend.cpp. References d. Referenced by KDChart::Chart::addLegend(), buildLegend(), and clone().
    00653 {
    00654     return d->titleTextAttributes;
    00655 }

bool Legend::useAutomaticMarkerSize | ( |  | ) | const

| Definition at line 495 of file KDChartLegend.cpp. References d. Referenced by buildLegend(), and clone().
    00496 {
    00497     return d->useAutomaticMarkerSize;
    00498 }

## Member Data Documentation

Q_SIGNALS KDChart::Legend::__pad0__

| Reimplemented from KDChart::AbstractAreaWidget. Definition at line 354 of file KDChartLegend.h.

private KDChart::Legend::Q_SLOTS

| Definition at line 359 of file KDChartLegend.h.

The documentation for this class was generated from the following files:

- KDChartLegend.h
- KDChartLegend.cpp