KD Chart 2  [rev.2.8]
KDChartAbstractDiagram.h
Go to the documentation of this file.
1 /****************************************************************************
2 ** Copyright (C) 2001-2021 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 KDCHARTABSTRACTDIAGRAM_H
24 #define KDCHARTABSTRACTDIAGRAM_H
25 
26 #include <QList>
27 #include <QRectF>
28 #include <QAbstractItemView>
29 
30 #include "KDChartGlobal.h"
32 #include "KDChartAttributesModel.h"
33 
34 namespace KDChart {
35 
36  class AbstractCoordinatePlane;
37  class AttributesModel;
38  class DataValueAttributes;
39  class PaintContext;
40 
50  class KDCHART_EXPORT AbstractDiagram : public QAbstractItemView
51  {
52  Q_OBJECT
53  Q_DISABLE_COPY( AbstractDiagram )
55 
58  friend class PolarCoordinatePlane;
59 
60  protected:
61  explicit inline AbstractDiagram(
62  Private *p, QWidget* parent, AbstractCoordinatePlane* plane );
63  explicit AbstractDiagram (
64  QWidget* parent = 0, AbstractCoordinatePlane* plane = 0 );
65  public:
66  ~AbstractDiagram() override;
67 
68 
72  bool compare( const AbstractDiagram* other ) const;
73 
74 
89  const QPair<QPointF, QPointF> dataBoundaries() const;
90 
91  // protected: // FIXME: why should that be private? (Mirko)
98  virtual void paint ( PaintContext* paintContext ) = 0;
99 
106  virtual void resize ( const QSizeF& area ) = 0;
107 
109  void setModel ( QAbstractItemModel * model ) override;
110 
112  void setSelectionModel( QItemSelectionModel* selectionModel ) override;
113 
142  virtual void setAttributesModel( AttributesModel* model );
143 
150  virtual bool usesExternalAttributesModel() const;
151 
162  virtual AttributesModel* attributesModel() const;
163 
166  void setRootIndex ( const QModelIndex& idx ) override;
167 
169  QRect visualRect(const QModelIndex &index) const override;
171  void scrollTo(const QModelIndex &index, ScrollHint hint = EnsureVisible) override;
173  QModelIndex indexAt(const QPoint &point) const override;
175  QModelIndex moveCursor(CursorAction cursorAction, Qt::KeyboardModifiers modifiers) override;
177  int horizontalOffset() const override;
179  int verticalOffset() const override;
181  bool isIndexHidden(const QModelIndex &index) const override;
183  void setSelection(const QRect &rect, QItemSelectionModel::SelectionFlags command) override;
185  QRegion visualRegionForSelection(const QItemSelection &selection) const override;
186  virtual QRegion visualRegion(const QModelIndex &index) const;
188  void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles = QVector<int>()) override;
190  void doItemsLayout() override;
191 
198  AbstractCoordinatePlane* coordinatePlane() const;
199 
206  virtual void setCoordinatePlane( AbstractCoordinatePlane* plane );
207 
208 
222  void setHidden( const QModelIndex & index, bool hidden );
223 
236  void setHidden( int dataset, bool hidden );
237 
249  void setHidden( bool hidden );
250 
257  bool isHidden() const;
258 
266  bool isHidden( int dataset ) const;
267 
275  bool isHidden( const QModelIndex & index ) const;
276 
277 
284  void setDataValueAttributes( const QModelIndex & index,
285  const DataValueAttributes & a );
286 
292  void setDataValueAttributes( int dataset, const DataValueAttributes & a );
293 
298  void setDataValueAttributes( const DataValueAttributes & a );
299 
306  DataValueAttributes dataValueAttributes() const;
307 
315  DataValueAttributes dataValueAttributes( int dataset ) const;
316 
325  DataValueAttributes dataValueAttributes( const QModelIndex & index ) const;
326 
333  void setPen( const QModelIndex& index, const QPen& pen );
334 
340  void setPen( int dataset, const QPen& pen );
341 
346  void setPen( const QPen& pen );
347 
354  QPen pen() const;
362  QPen pen( int dataset ) const;
370  QPen pen( const QModelIndex& index ) const;
371 
378  void setBrush( const QModelIndex& index, const QBrush& brush);
379 
385  void setBrush( int dataset, const QBrush& brush );
386 
391  void setBrush( const QBrush& brush);
392 
399  QBrush brush() const;
407  QBrush brush( int dataset ) const;
415  QBrush brush( const QModelIndex& index ) const;
416 
423  void setUnitPrefix( const QString& prefix, int column, Qt::Orientation orientation );
429  void setUnitPrefix( const QString& prefix, Qt::Orientation orientation );
430 
437  void setUnitSuffix( const QString& suffix, int column, Qt::Orientation orientation );
443  void setUnitSuffix( const QString& suffix, Qt::Orientation orientation );
444 
453  QString unitPrefix( int column, Qt::Orientation orientation, bool fallback = false ) const;
459  QString unitPrefix( Qt::Orientation orientation ) const;
460 
469  QString unitSuffix( int column, Qt::Orientation orientation, bool fallback = false ) const;
475  QString unitSuffix( Qt::Orientation orientation ) const;
476 
481  void setAllowOverlappingDataValueTexts( bool allow );
482 
486  bool allowOverlappingDataValueTexts() const;
487 
493  void setAntiAliasing( bool enabled );
494 
499  bool antiAliasing() const;
500 
507  void useDefaultColors();
508 
514  void useRainbowColors();
515 
521  void useSubduedColors();
522 
527  QStringList itemRowLabels() const;
528 
533  QStringList datasetLabels() const;
534 
544  QList<QBrush> datasetBrushes() const;
545 
555  QList<QPen> datasetPens() const;
556 
566  QList<MarkerAttributes> datasetMarkers() const;
567 
568 
579  void setPercentMode( bool percent );
580 
581 
593  bool percentMode() const;
594 
595  virtual void paintMarker( QPainter* painter,
596  const MarkerAttributes& markerAttributes,
597  const QBrush& brush, const QPen&,
598  const QPointF& point, const QSizeF& size );
599 
614  int datasetDimension() const;
615 
622  void setDatasetDimension( int dimension );
623 
624  protected:
625  void setDatasetDimensionInternal( int dimension );
626 
627  public:
628  void update() const;
629 
630  void paintMarker( QPainter* painter, const DataValueAttributes& a,
631  const QModelIndex& index,
632  const QPointF& pos );
633  void paintMarker( QPainter* painter,
634  const QModelIndex& index,
635  const QPointF& pos );
636  void paintDataValueText( QPainter* painter, const QModelIndex& index,
637  const QPointF& pos, qreal value );
638 
639  // reverse mapping:
643  QModelIndexList indexesAt( const QPoint& point ) const;
644  QModelIndexList indexesIn( const QRect& rect ) const;
645 
646  protected:
647  virtual bool checkInvariants( bool justReturnTheStatus=false ) const;
648  virtual const QPair<QPointF, QPointF> calculateDataBoundaries() const = 0;
649 
650  protected Q_SLOTS:
651  void setDataBoundariesDirty() const;
652 
653  protected:
661  virtual void paintDataValueTexts( QPainter* painter );
669  virtual void paintMarkers( QPainter* painter );
670  void setAttributesModelRootIndex( const QModelIndex& );
671  QModelIndex attributesModelRootIndex() const;
672 
680  qreal valueForCell( int row, int column ) const;
681 
682  Q_SIGNALS:
691  void layoutChanged( AbstractDiagram* );
692 
697  void aboutToBeDestroyed();
698 
700  void modelsChanged();
701 
704  void attributesModelAboutToChange( AttributesModel* newModel, AttributesModel* oldModel );
705 
707  void modelDataChanged();
708 
710  void dataHidden();
711 
713  void propertiesChanged();
714 
716  void boundariesChanged();
718  void viewportCoordinateSystemChanged();
719 
720  private:
721  QModelIndex conditionallyMapFromSource( const QModelIndex & sourceIndex ) const;
722  };
723 
726 
731  Q_OBJECT
732  public:
733  explicit PrivateAttributesModel( QAbstractItemModel* model, QObject * parent = 0 )
734  : AttributesModel(model,parent) {}
735  };
736 }
737 
738 #endif
KDCHART_DECLARE_PRIVATE_BASE_POLYMORPHIC
#define KDCHART_DECLARE_PRIVATE_BASE_POLYMORPHIC(X)
Definition: KDChartGlobal.h:82
QWidget
Class only listed here to document inheritance of some KDChart classes.
KDChart::MarkerAttributes
A set of attributes controlling the appearance of data set markers.
Definition: KDChartMarkerAttributes.h:44
QList
Definition: KDChartPosition.h:36
KDChartAttributesModel.h
KDChart::PrivateAttributesModel::PrivateAttributesModel
PrivateAttributesModel(QAbstractItemModel *model, QObject *parent=0)
Definition: KDChartAbstractDiagram.h:733
KDChart
Definition: KDChartAbstractCartesianDiagram.h:30
KDChart::PolarCoordinatePlane
Polar coordinate plane.
Definition: KDChartPolarCoordinatePlane.h:37
KDChart::PaintContext
Stores information about painting diagrams.
Definition: KDChartPaintContext.h:42
KDChartGlobal.h
KDChartMarkerAttributes.h
QAbstractItemView
Class only listed here to document inheritance of some KDChart classes.
KDChart::AttributesModel
A proxy model used for decorating data with attributes.
Definition: KDChartAttributesModel.h:47
KDChart::AbstractDiagram
AbstractDiagram defines the interface for diagram classes.
Definition: KDChartAbstractDiagram.h:51
QPair
Definition: KDChartWidget.h:35
KDChart::DataValueAttributes
Diagram attributes dealing with data value labels.
Definition: KDChartDataValueAttributes.h:56
KDChart::CartesianCoordinatePlane
Cartesian coordinate plane.
Definition: KDChartCartesianCoordinatePlane.h:40
QObject
QVector
Definition: KDChartWidget.h:34
KDChart::PrivateAttributesModel
Internally used class just adding a special constructor used by AbstractDiagram.
Definition: KDChartAbstractDiagram.h:730
KDChart::AbstractCoordinatePlane
Base class common for all coordinate planes, CartesianCoordinatePlane, PolarCoordinatePlane,...
Definition: KDChartAbstractCoordinatePlane.h:45

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/