KD Chart 2  [rev.2.7]
KDChartLegend.h
Go to the documentation of this file.
1 /****************************************************************************
2 ** Copyright (C) 2001-2020 Klaralvdalens Datakonsult AB. All rights reserved.
3 **
4 ** This file is part of the KD Chart library.
5 **
6 ** Licensees holding valid commercial KD Chart licenses may use this file in
7 ** accordance with the KD Chart Commercial License Agreement provided with
8 ** the Software.
9 **
10 **
11 ** This file may be distributed and/or modified under the terms of the
12 ** GNU General Public License version 2 and version 3 as published by the
13 ** Free Software Foundation and appearing in the file LICENSE.GPL.txt included.
14 **
15 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
16 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
17 **
18 ** Contact info@kdab.com if any conditions of this licensing are not
19 ** clear to you.
20 **
21 **********************************************************************/
22 
23 #ifndef KDCHARTLEGEND_H
24 #define KDCHARTLEGEND_H
25 
27 #include "KDChartPosition.h"
29 
30 class QTextTable;
31 
32 namespace KDChart {
33 
37 
55 class KDCHART_EXPORT Legend : public AbstractAreaWidget
56 {
57  Q_OBJECT
58 
59  Q_DISABLE_COPY( Legend )
61 
62 public:
63  explicit Legend( QWidget* parent = 0 );
64  explicit Legend( KDChart::AbstractDiagram* diagram, QWidget* parent = 0 );
65  ~Legend() override;
66 
67 
68  enum LegendStyle { MarkersOnly = 0,
69  LinesOnly = 1,
70  MarkersAndLines = 2 };
71 
72 
73  void setLegendStyle( LegendStyle style );
74  LegendStyle legendStyle() const;
75 
76 
77  virtual Legend * clone() const;
78 
82  bool compare( const Legend* other ) const;
83 
84  void resizeEvent( QResizeEvent * event ) override; // TODO: should be protected
85 
86  void paint( QPainter* painter ) override;
87  void setVisible( bool visible ) override;
88 
104  void setReferenceArea( const QWidget* area );
112  const QWidget* referenceArea() const;
113 
120  KDChart::AbstractDiagram* diagram() const;
121 
128  DiagramList diagrams() const;
129 
133  ConstDiagramList constDiagrams() const;
134 
141  void addDiagram( KDChart::AbstractDiagram* newDiagram );
142 
148  void removeDiagram( KDChart::AbstractDiagram* oldDiagram );
149 
155  void removeDiagrams();
156 
171  void replaceDiagram( KDChart::AbstractDiagram* newDiagram,
172  KDChart::AbstractDiagram* oldDiagram = 0 );
173 
178  uint dataSetOffset( KDChart::AbstractDiagram* diagram );
179 
188  void setDiagram( KDChart::AbstractDiagram* newDiagram );
189 
198  void setPosition( Position position );
199 
204  Position position() const;
205 
214  void setAlignment( Qt::Alignment );
215 
220  Qt::Alignment alignment() const;
221 
227  void setTextAlignment( Qt::Alignment );
228 
234  Qt::Alignment textAlignment() const;
235 
242  void setLegendSymbolAlignment(Qt::Alignment);
243 
250  Qt::Alignment legendSymbolAlignment() const;
251 
296  void setFloatingPosition( const RelativePosition& relativePosition );
297 
302  const RelativePosition floatingPosition() const;
303 
304  void setOrientation( Qt::Orientation orientation );
305  Qt::Orientation orientation() const;
306 
307 
308  void setSortOrder( Qt::SortOrder order );
309  Qt::SortOrder sortOrder() const;
310 
311  void setShowLines( bool legendShowLines );
312  bool showLines() const;
313 
314  void resetTexts();
315  void setText( uint dataset, const QString& text );
316  QString text( uint dataset ) const;
317  const QMap<uint,QString> texts() const;
318 
326  void setHiddenDatasets( const QList<uint> hiddenDatasets );
327  const QList<uint> hiddenDatasets() const;
328  void setDatasetHidden( uint dataset, bool hidden );
329  bool datasetIsHidden( uint dataset ) const;
330 
331  uint datasetCount() const;
332 
333  void setDefaultColors();
334  void setRainbowColors();
335  void setSubduedColors( bool ordered = false );
336 
337  void setBrushesFromDiagram( KDChart::AbstractDiagram* diagram );
338 
344  void setColor( uint dataset, const QColor& color );
345 
346  void setBrush( uint dataset, const QBrush& brush );
347  QBrush brush( uint dataset ) const;
348  const QMap<uint,QBrush> brushes() const;
349 
350  void setPen( uint dataset, const QPen& pen );
351  QPen pen( uint dataset ) const;
352  const QMap<uint,QPen> pens() const;
353 
359  void setMarkerAttributes( uint dataset, const MarkerAttributes& );
360  MarkerAttributes markerAttributes( uint dataset ) const;
361  const QMap<uint, MarkerAttributes> markerAttributes() const;
362 
370  void setUseAutomaticMarkerSize( bool useAutomaticMarkerSize );
371  bool useAutomaticMarkerSize() const;
372 
373  void setTextAttributes( const TextAttributes &a );
374  TextAttributes textAttributes() const;
375 
376  void setTitleText( const QString& text );
377  QString titleText() const;
378 
379  void setTitleTextAttributes( const TextAttributes &a );
380  TextAttributes titleTextAttributes() const;
381 
382  void setSpacing( uint space );
383  uint spacing() const;
384 
385  // called internally by KDChart::Chart, when painting into a custom QPainter
386  void forceRebuild() override;
387 
388  QSize minimumSizeHint() const override;
389  QSize sizeHint() const override;
390  bool hasHeightForWidth() const; //override;
391  int heightForWidth( int width ) const override;
392  void needSizeHint() override;
393  void resizeLayout( const QSize& size ) override;
394 
395 Q_SIGNALS:
396  void destroyedLegend( Legend* );
398  void propertiesChanged();
399 
400 private Q_SLOTS:
401  void emitPositionChanged();
402  void resetDiagram( AbstractDiagram* );
403  void activateTheLayout();
404  void setNeedRebuild();
405  void buildLegend();
406 }; // End of class Legend
407 
408 }
409 
410 
411 #endif // KDCHARTLEGEND_H
AbstractDiagram defines the interface for diagram classes.
An area in the chart with a background, a frame, etc.
Legend defines the interface for the legend drawing class.
Definition: KDChartLegend.h:55
QList< AbstractDiagram * > DiagramList
Definition: KDChartLegend.h:34
A set of attributes controlling the appearance of data set markers.
#define KDCHART_DECLARE_PRIVATE_DERIVED_QWIDGET(X)
Definition: KDChartGlobal.h:68
Defines relative position information: reference area, position in this area (reference position)...
Defines a position, using compass terminology.
Class only listed here to document inheritance of some KDChart classes.
QList< const AbstractDiagram * > ConstDiagramList
Definition: KDChartLegend.h:36
A set of text attributes.

Klarälvdalens Datakonsult AB (KDAB)
"The Qt, C++ and OpenGL Experts"
https://www.kdab.com/

https://www.kdab.com/development-resources/qt-tools/kd-chart/