KChart

KChartLegend.h
1 /*
2  * Copyright (C) 2001-2015 Klaralvdalens Datakonsult AB. All rights reserved.
3  *
4  * This file is part of the KD Chart library.
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License as
8  * published by the Free Software Foundation; either version 2 of
9  * the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see <https://www.gnu.org/licenses/>.
18  */
19 
20 #ifndef KCHARTLEGEND_H
21 #define KCHARTLEGEND_H
22 
23 #include "KChartAbstractAreaWidget.h"
24 #include "KChartPosition.h"
25 #include "KChartMarkerAttributes.h"
26 
27 class QTextTable;
28 
29 namespace KChart {
30 
31 class AbstractDiagram;
32 typedef QList<AbstractDiagram*> DiagramList;
33 typedef QList<const AbstractDiagram*> ConstDiagramList;
34 
52 class KCHART_EXPORT Legend : public AbstractAreaWidget
53 {
54  Q_OBJECT
55 
56  Q_DISABLE_COPY( Legend )
57  KCHART_DECLARE_PRIVATE_DERIVED_QWIDGET( Legend )
58 
59 public:
60  explicit Legend( QWidget* parent = nullptr );
61  explicit Legend( KChart::AbstractDiagram* diagram, QWidget* parent = nullptr );
62  virtual ~Legend();
63 
64 
65  enum LegendStyle { MarkersOnly = 0,
66  LinesOnly = 1,
67  MarkersAndLines = 2 };
68 
69 
70  void setLegendStyle( LegendStyle style );
71  LegendStyle legendStyle() const;
72 
73 
74 
78  virtual Legend * clone() const;
79 
83  bool compare( const Legend* other ) const;
84 
85  void resizeEvent( QResizeEvent * event ) override; // TODO: should be protected
86 
87  virtual void paint( QPainter* painter ) override;
88  void paint( QPainter* painter, const QRect &rect);
89  void setVisible( bool visible ) override;
90 
106  void setReferenceArea( const QWidget* area );
114  const QWidget* referenceArea() const;
115 
122  KChart::AbstractDiagram* diagram() const;
123 
130  DiagramList diagrams() const;
131 
135  ConstDiagramList constDiagrams() const;
136 
143  void addDiagram( KChart::AbstractDiagram* newDiagram );
144 
150  void removeDiagram( KChart::AbstractDiagram* oldDiagram );
151 
157  void removeDiagrams();
158 
173  void replaceDiagram( KChart::AbstractDiagram* newDiagram,
174  KChart::AbstractDiagram* oldDiagram = nullptr );
175 
180  uint dataSetOffset( KChart::AbstractDiagram* diagram );
181 
190  void setDiagram( KChart::AbstractDiagram* newDiagram );
191 
200  void setPosition( Position position );
201 
206  Position position() const;
207 
216  void setAlignment( Qt::Alignment );
217 
222  Qt::Alignment alignment() const;
223 
229  void setTextAlignment( Qt::Alignment );
230 
236  Qt::Alignment textAlignment() const;
237 
244  void setLegendSymbolAlignment(Qt::Alignment);
245 
252  Qt::Alignment legendSymbolAlignment() const;
253 
298  void setFloatingPosition( const RelativePosition& relativePosition );
299 
304  const RelativePosition floatingPosition() const;
305 
306  void setOrientation( Qt::Orientation orientation );
307  Qt::Orientation orientation() const;
308 
309 
310  void setSortOrder( Qt::SortOrder order );
311  Qt::SortOrder sortOrder() const;
312 
313  void setShowLines( bool legendShowLines );
314  bool showLines() const;
315 
316 
322  void resetTexts();
323  void setText( uint dataset, const QString& text );
324  QString text( uint dataset ) const;
325  const QMap<uint,QString> texts() const;
326 
334  void setHiddenDatasets( const QList<uint> hiddenDatasets );
335  const QList<uint> hiddenDatasets() const;
336  void setDatasetHidden( uint dataset, bool hidden );
337  bool datasetIsHidden( uint dataset ) const;
338 
339  uint datasetCount() const;
340 
341  void setDefaultColors();
342  void setRainbowColors();
343  void setSubduedColors( bool ordered = false );
344 
345  void setBrushesFromDiagram( KChart::AbstractDiagram* diagram );
346 
352  void setColor( uint dataset, const QColor& color );
353 
354  void setBrush( uint dataset, const QBrush& brush );
355  QBrush brush( uint dataset ) const;
356  const QMap<uint,QBrush> brushes() const;
357 
358  void setPen( uint dataset, const QPen& pen );
359  QPen pen( uint dataset ) const;
360  const QMap<uint,QPen> pens() const;
361 
367  void setMarkerAttributes( uint dataset, const MarkerAttributes& );
368  MarkerAttributes markerAttributes( uint dataset ) const;
369  const QMap<uint, MarkerAttributes> markerAttributes() const;
370 
378  void setUseAutomaticMarkerSize( bool useAutomaticMarkerSize );
379  bool useAutomaticMarkerSize() const;
380 
381  void setTextAttributes( const TextAttributes &a );
382  TextAttributes textAttributes() const;
383 
384  void setTitleText( const QString& text );
385  QString titleText() const;
386 
387  void setTitleTextAttributes( const TextAttributes &a );
388  TextAttributes titleTextAttributes() const;
389 
390  void setSpacing( uint space );
391  uint spacing() const;
392 
393  // called internally by KChart::Chart, when painting into a custom QPainter
394  void forceRebuild() override;
395 
396  QSize minimumSizeHint() const override;
397  QSize sizeHint() const override;
398  bool hasHeightForWidth() const override;
399  int heightForWidth( int width ) const override;
400  void needSizeHint() override;
401  void resizeLayout( const QSize& size ) override;
402 
403 Q_SIGNALS:
404  void destroyedLegend( Legend* );
406  void propertiesChanged();
407 
408 private Q_SLOTS:
409  void emitPositionChanged();
410  void resetDiagram( AbstractDiagram* );
411  void activateTheLayout();
412  void setNeedRebuild();
413  void buildLegend();
414 }; // End of class Legend
415 
416 }
417 
418 
419 #endif // KCHARTLEGEND_H
Defines relative position information: reference area, position in this area (reference position)...
Class only listed here to document inheritance of some KChart classes.
Legend defines the interface for the legend drawing class.
Definition: KChartLegend.h:52
AbstractDiagram defines the interface for diagram classes.
A set of attributes controlling the appearance of data set markers.
Defines a position, using compass terminology.
typedef Alignment
SortOrder
A set of text attributes.
An area in the chart with a background, a frame, etc.
Orientation
Global namespace.
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Tue Sep 22 2020 22:36:46 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.