KChart

KChartAbstractDiagram.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 KCHARTABSTRACTDIAGRAM_H
21 #define KCHARTABSTRACTDIAGRAM_H
22 
23 #include <QList>
24 #include <QRectF>
25 #include <QAbstractItemView>
26 
27 #include "KChartGlobal.h"
28 #include "KChartMarkerAttributes.h"
29 #include "KChartAttributesModel.h"
30 
31 namespace KChart {
32 
33  class AbstractCoordinatePlane;
34  class AttributesModel;
35  class DataValueAttributes;
36  class PaintContext;
37 
47  class KCHART_EXPORT AbstractDiagram : public QAbstractItemView
48  {
49  Q_OBJECT
50  Q_DISABLE_COPY( AbstractDiagram )
51  KCHART_DECLARE_PRIVATE_BASE_POLYMORPHIC( AbstractDiagram )
52 
53  friend class AbstractCoordinatePlane;
54  friend class CartesianCoordinatePlane;
55  friend class PolarCoordinatePlane;
56 
57  protected:
58  explicit inline AbstractDiagram(
59  Private *p, QWidget* parent, AbstractCoordinatePlane* plane );
60  explicit AbstractDiagram (
61  QWidget* parent = nullptr, AbstractCoordinatePlane* plane = nullptr );
62  public:
63  virtual ~AbstractDiagram();
64 
65 
69  bool compare( const AbstractDiagram* other ) const;
70 
71 
86  const QPair<QPointF, QPointF> dataBoundaries() const;
87 
88  // protected: // FIXME: why should that be private? (Mirko)
95  virtual void paint ( PaintContext* paintContext ) = 0;
96 
103  virtual void resize ( const QSizeF& area );
104 
106  void setModel ( QAbstractItemModel * model ) override;
107 
109  void setSelectionModel( QItemSelectionModel* selectionModel ) override;
110 
139  virtual void setAttributesModel( AttributesModel* model );
140 
147  virtual bool usesExternalAttributesModel() const;
148 
159  virtual AttributesModel* attributesModel() const;
160 
163  void setRootIndex ( const QModelIndex& idx ) override;
164 
166  QRect visualRect(const QModelIndex &index) const override;
168  void scrollTo(const QModelIndex &index, ScrollHint hint = EnsureVisible) override;
170  QModelIndex indexAt(const QPoint &point) const override;
172  QModelIndex moveCursor(CursorAction cursorAction, Qt::KeyboardModifiers modifiers) override;
174  int horizontalOffset() const override;
176  int verticalOffset() const override;
178  bool isIndexHidden(const QModelIndex &index) const override;
180  void setSelection(const QRect &rect, QItemSelectionModel::SelectionFlags command) override;
182  QRegion visualRegionForSelection(const QItemSelection &selection) const override;
183  virtual QRegion visualRegion(const QModelIndex &index) const;
185  void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles = QVector<int>()) override;
187  void doItemsLayout() override;
188 
195  AbstractCoordinatePlane* coordinatePlane() const;
196 
202  virtual void setCoordinatePlane( AbstractCoordinatePlane* plane );
203 
204 
218  void setHidden( const QModelIndex & index, bool hidden );
219 
232  void setHidden( int dataset, bool hidden );
233 
245  void setHidden( bool hidden );
246 
253  bool isHidden() const;
254 
262  bool isHidden( int dataset ) const;
263 
271  bool isHidden( const QModelIndex & index ) const;
272 
273 
280  void setDataValueAttributes( const QModelIndex & index,
281  const DataValueAttributes & a );
282 
288  void setDataValueAttributes( int dataset, const DataValueAttributes & a );
289 
294  void setDataValueAttributes( const DataValueAttributes & a );
295 
302  DataValueAttributes dataValueAttributes() const;
303 
311  DataValueAttributes dataValueAttributes( int dataset ) const;
312 
321  DataValueAttributes dataValueAttributes( const QModelIndex & index ) const;
322 
329  void setPen( const QModelIndex& index, const QPen& pen );
330 
336  void setPen( int dataset, const QPen& pen );
337 
342  void setPen( const QPen& pen );
343 
350  QPen pen() const;
358  QPen pen( int dataset ) const;
366  QPen pen( const QModelIndex& index ) const;
367 
374  void setBrush( const QModelIndex& index, const QBrush& brush);
375 
381  void setBrush( int dataset, const QBrush& brush );
382 
387  void setBrush( const QBrush& brush);
388 
395  QBrush brush() const;
403  QBrush brush( int dataset ) const;
411  QBrush brush( const QModelIndex& index ) const;
412 
419  void setUnitPrefix( const QString& prefix, int column, Qt::Orientation orientation );
425  void setUnitPrefix( const QString& prefix, Qt::Orientation orientation );
426 
433  void setUnitSuffix( const QString& suffix, int column, Qt::Orientation orientation );
439  void setUnitSuffix( const QString& suffix, Qt::Orientation orientation );
440 
449  QString unitPrefix( int column, Qt::Orientation orientation, bool fallback = false ) const;
455  QString unitPrefix( Qt::Orientation orientation ) const;
456 
465  QString unitSuffix( int column, Qt::Orientation orientation, bool fallback = false ) const;
471  QString unitSuffix( Qt::Orientation orientation ) const;
472 
477  void setAllowOverlappingDataValueTexts( bool allow );
478 
482  bool allowOverlappingDataValueTexts() const;
483 
489  void setAntiAliasing( bool enabled );
490 
495  bool antiAliasing() const;
496 
503  void useDefaultColors();
504 
510  void useRainbowColors();
511 
517  void useSubduedColors();
518 
523  QStringList itemRowLabels() const;
524 
529  QStringList datasetLabels() const;
530 
540  QList<QBrush> datasetBrushes() const;
541 
551  QList<QPen> datasetPens() const;
552 
562  QList<MarkerAttributes> datasetMarkers() const;
563 
564 
575  void setPercentMode( bool percent );
576 
577 
589  bool percentMode() const;
590 
591  virtual void paintMarker( QPainter* painter,
592  const MarkerAttributes& markerAttributes,
593  const QBrush& brush, const QPen&,
594  const QPointF& point, const QSizeF& size );
595 
610  int datasetDimension() const;
611 
618  void setDatasetDimension( int dimension );
619 
620  protected:
621  void setDatasetDimensionInternal( int dimension );
622 
623  public:
624  void update() const;
625 
626  void paintMarker( QPainter* painter, const DataValueAttributes& a,
627  const QModelIndex& index,
628  const QPointF& pos );
629  void paintMarker( QPainter* painter,
630  const QModelIndex& index,
631  const QPointF& pos );
632  void paintDataValueText( QPainter* painter, const QModelIndex& index,
633  const QPointF& pos, qreal value );
634 
635  // reverse mapping:
639  QModelIndexList indexesAt( const QPoint& point ) const;
640  QModelIndexList indexesIn( const QRect& rect ) const;
641 
642  protected:
643  virtual bool checkInvariants( bool justReturnTheStatus=false ) const;
644  virtual const QPair<QPointF, QPointF> calculateDataBoundaries() const = 0;
645 
646  protected Q_SLOTS:
647  void setDataBoundariesDirty() const;
648 
649  protected:
657  virtual void paintDataValueTexts( QPainter* painter );
665  virtual void paintMarkers( QPainter* painter );
666 
668  void setAttributesModelRootIndex( const QModelIndex& );
669 
672  QModelIndex attributesModelRootIndex() const;
673 
681  qreal valueForCell( int row, int column ) const;
682 
683  Q_SIGNALS:
692  void layoutChanged( AbstractDiagram* );
693 
698  void aboutToBeDestroyed();
699 
701  void modelsChanged();
702 
705  void attributesModelAboutToChange( AttributesModel* newModel, AttributesModel* oldModel );
706 
708  void modelDataChanged();
709 
711  void dataHidden();
712 
714  void propertiesChanged();
715 
717  void boundariesChanged();
719  void viewportCoordinateSystemChanged();
720 
721  private:
722  QModelIndex conditionallyMapFromSource( const QModelIndex & sourceIndex ) const;
723  };
724 
727 
732  Q_OBJECT
733  public:
734  explicit PrivateAttributesModel( QAbstractItemModel* model, QObject * parent = nullptr )
735  : AttributesModel(model,parent) {}
736  };
737 }
738 
739 #endif
Class only listed here to document inheritance of some KChart classes.
typedef KeyboardModifiers
AbstractDiagram defines the interface for diagram classes.
Class only listed here to document inheritance of some KChart classes.
A set of attributes controlling the appearance of data set markers.
Diagram attributes dealing with data value labels.
Stores information about painting diagrams.
Class only listed here to document inheritance of some KChart classes.
Contains KChart macros.
Base class common for all coordinate planes, CartesianCoordinatePlane, PolarCoordinatePlane, TernaryCoordinatePlane.
A proxy model used for decorating data with attributes.
Internally used class just adding a special constructor used by AbstractDiagram.
Orientation
Global namespace.
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Thu Sep 17 2020 22:36:39 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.