KD Chart 2  [rev.2.7]
KDChartAbstractDiagram.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 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 #if QT_VERSION < 0x050000
189  virtual void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight);
190 #else
191  void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles = QVector<int>()) override;
192 #endif
193 
194  void doItemsLayout() override;
195 
202  AbstractCoordinatePlane* coordinatePlane() const;
203 
210  virtual void setCoordinatePlane( AbstractCoordinatePlane* plane );
211 
212 
226  void setHidden( const QModelIndex & index, bool hidden );
227 
240  void setHidden( int dataset, bool hidden );
241 
253  void setHidden( bool hidden );
254 
261  bool isHidden() const;
262 
270  bool isHidden( int dataset ) const;
271 
279  bool isHidden( const QModelIndex & index ) const;
280 
281 
288  void setDataValueAttributes( const QModelIndex & index,
289  const DataValueAttributes & a );
290 
296  void setDataValueAttributes( int dataset, const DataValueAttributes & a );
297 
302  void setDataValueAttributes( const DataValueAttributes & a );
303 
310  DataValueAttributes dataValueAttributes() const;
311 
319  DataValueAttributes dataValueAttributes( int dataset ) const;
320 
329  DataValueAttributes dataValueAttributes( const QModelIndex & index ) const;
330 
337  void setPen( const QModelIndex& index, const QPen& pen );
338 
344  void setPen( int dataset, const QPen& pen );
345 
350  void setPen( const QPen& pen );
351 
358  QPen pen() const;
366  QPen pen( int dataset ) const;
374  QPen pen( const QModelIndex& index ) const;
375 
382  void setBrush( const QModelIndex& index, const QBrush& brush);
383 
389  void setBrush( int dataset, const QBrush& brush );
390 
395  void setBrush( const QBrush& brush);
396 
403  QBrush brush() const;
411  QBrush brush( int dataset ) const;
419  QBrush brush( const QModelIndex& index ) const;
420 
427  void setUnitPrefix( const QString& prefix, int column, Qt::Orientation orientation );
433  void setUnitPrefix( const QString& prefix, Qt::Orientation orientation );
434 
441  void setUnitSuffix( const QString& suffix, int column, Qt::Orientation orientation );
447  void setUnitSuffix( const QString& suffix, Qt::Orientation orientation );
448 
457  QString unitPrefix( int column, Qt::Orientation orientation, bool fallback = false ) const;
463  QString unitPrefix( Qt::Orientation orientation ) const;
464 
473  QString unitSuffix( int column, Qt::Orientation orientation, bool fallback = false ) const;
479  QString unitSuffix( Qt::Orientation orientation ) const;
480 
485  void setAllowOverlappingDataValueTexts( bool allow );
486 
490  bool allowOverlappingDataValueTexts() const;
491 
497  void setAntiAliasing( bool enabled );
498 
503  bool antiAliasing() const;
504 
511  void useDefaultColors();
512 
518  void useRainbowColors();
519 
525  void useSubduedColors();
526 
531  QStringList itemRowLabels() const;
532 
537  QStringList datasetLabels() const;
538 
548  QList<QBrush> datasetBrushes() const;
549 
559  QList<QPen> datasetPens() const;
560 
570  QList<MarkerAttributes> datasetMarkers() const;
571 
572 
583  void setPercentMode( bool percent );
584 
585 
597  bool percentMode() const;
598 
599  virtual void paintMarker( QPainter* painter,
600  const MarkerAttributes& markerAttributes,
601  const QBrush& brush, const QPen&,
602  const QPointF& point, const QSizeF& size );
603 
618  int datasetDimension() const;
619 
626  void setDatasetDimension( int dimension );
627 
628  protected:
629  void setDatasetDimensionInternal( int dimension );
630 
631  public:
632  void update() const;
633 
634  void paintMarker( QPainter* painter, const DataValueAttributes& a,
635  const QModelIndex& index,
636  const QPointF& pos );
637  void paintMarker( QPainter* painter,
638  const QModelIndex& index,
639  const QPointF& pos );
640  void paintDataValueText( QPainter* painter, const QModelIndex& index,
641  const QPointF& pos, qreal value );
642 
643  // reverse mapping:
647  QModelIndexList indexesAt( const QPoint& point ) const;
648  QModelIndexList indexesIn( const QRect& rect ) const;
649 
650  protected:
651  virtual bool checkInvariants( bool justReturnTheStatus=false ) const;
652  virtual const QPair<QPointF, QPointF> calculateDataBoundaries() const = 0;
653 
654  protected Q_SLOTS:
655  void setDataBoundariesDirty() const;
656 
657  protected:
665  virtual void paintDataValueTexts( QPainter* painter );
673  virtual void paintMarkers( QPainter* painter );
674  void setAttributesModelRootIndex( const QModelIndex& );
675  QModelIndex attributesModelRootIndex() const;
676 
684  qreal valueForCell( int row, int column ) const;
685 
686  Q_SIGNALS:
695  void layoutChanged( AbstractDiagram* );
696 
701  void aboutToBeDestroyed();
702 
704  void modelsChanged();
705 
708  void attributesModelAboutToChange( AttributesModel* newModel, AttributesModel* oldModel );
709 
711  void modelDataChanged();
712 
714  void dataHidden();
715 
717  void propertiesChanged();
718 
720  void boundariesChanged();
722  void viewportCoordinateSystemChanged();
723 
724  private:
725  QModelIndex conditionallyMapFromSource( const QModelIndex & sourceIndex ) const;
726  };
727 
730 
735  Q_OBJECT
736  public:
737  explicit PrivateAttributesModel( QAbstractItemModel* model, QObject * parent = 0 )
738  : AttributesModel(model,parent) {}
739  };
740 }
741 
742 #endif
Base class common for all coordinate planes, CartesianCoordinatePlane, PolarCoordinatePlane, TernaryCoordinatePlane.
Diagram attributes dealing with data value labels.
#define KDCHART_DECLARE_PRIVATE_BASE_POLYMORPHIC(X)
Definition: KDChartGlobal.h:82
PrivateAttributesModel(QAbstractItemModel *model, QObject *parent=0)
QList< AbstractDiagram * > AbstractDiagramList
AbstractDiagram defines the interface for diagram classes.
Class only listed here to document inheritance of some KDChart classes.
A proxy model used for decorating data with attributes.
QList< const AbstractDiagram * > ConstAbstractDiagramList
Stores information about painting diagrams.
A set of attributes controlling the appearance of data set markers.
Class only listed here to document inheritance of some KDChart classes.
Class only listed here to document inheritance of some KDChart classes.
Internally used class just adding a special constructor used by AbstractDiagram.

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/