KD Chart 2  [rev.2.5.1]
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Macros Pages
KDChartAbstractDiagram.h
Go to the documentation of this file.
1 /****************************************************************************
2 ** Copyright (C) 2001-2013 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  virtual ~AbstractDiagram();
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  virtual void setModel ( QAbstractItemModel * model );
110 
112  virtual void setSelectionModel( QItemSelectionModel* selectionModel );
113 
142  virtual void setAttributesModel( AttributesModel* model );
143 
150  virtual bool usesExternalAttributesModel() const;
151 
162  virtual AttributesModel* attributesModel() const;
163 
166  virtual void setRootIndex ( const QModelIndex& idx );
167 
169  virtual QRect visualRect(const QModelIndex &index) const;
171  virtual void scrollTo(const QModelIndex &index, ScrollHint hint = EnsureVisible);
173  virtual QModelIndex indexAt(const QPoint &point) const;
175  virtual QModelIndex moveCursor(CursorAction cursorAction, Qt::KeyboardModifiers modifiers);
177  virtual int horizontalOffset() const;
179  virtual int verticalOffset() const;
181  virtual bool isIndexHidden(const QModelIndex &index) const;
183  virtual void setSelection(const QRect &rect, QItemSelectionModel::SelectionFlags command);
185  virtual QRegion visualRegionForSelection(const QItemSelection &selection) const;
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  virtual void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles = QVector<int>());
192 #endif
193 
194  virtual void doItemsLayout();
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 
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

Klarälvdalens Datakonsult AB (KDAB)
Qt-related services and products
http://www.kdab.com/
http://www.kdab.com/products/kd-chart/