KDChartAbstractDiagram.h

Go to the documentation of this file.
00001 /****************************************************************************
00002  ** Copyright (C) 2007 Klaralvdalens Datakonsult AB.  All rights reserved.
00003  **
00004  ** This file is part of the KD Chart library.
00005  **
00006  ** This file may be distributed and/or modified under the terms of the
00007  ** GNU General Public License version 2 as published by the Free Software
00008  ** Foundation and appearing in the file LICENSE.GPL included in the
00009  ** packaging of this file.
00010  **
00011  ** Licensees holding valid commercial KD Chart licenses may use this file in
00012  ** accordance with the KD Chart Commercial License Agreement provided with
00013  ** the Software.
00014  **
00015  ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00016  ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00017  **
00018  ** See http://www.kdab.net/kdchart for
00019  **   information about KDChart Commercial License Agreements.
00020  **
00021  ** Contact info@kdab.net if any conditions of this
00022  ** licensing are not clear to you.
00023  **
00024  **********************************************************************/
00025 
00026 #ifndef KDCHARTABSTRACTDIAGRAM_H
00027 #define KDCHARTABSTRACTDIAGRAM_H
00028 
00029 #include <QList>
00030 #include <QRectF>
00031 #include <QAbstractItemView>
00032 
00033 #include "KDChartGlobal.h"
00034 #include "KDChartMarkerAttributes.h"
00035 #include "KDChartAttributesModel.h"
00036 
00037 namespace KDChart {
00038 
00039     class AbstractCoordinatePlane;
00040     class AttributesModel;
00041     class DataValueAttributes;
00042     class PaintContext;
00043 
00053     class KDCHART_EXPORT AbstractDiagram : public QAbstractItemView
00054     {
00055         Q_OBJECT
00056         Q_DISABLE_COPY( AbstractDiagram )
00057         KDCHART_DECLARE_PRIVATE_BASE_POLYMORPHIC( AbstractDiagram )
00058 
00059     friend class AbstractCoordinatePlane;
00060     friend class CartesianCoordinatePlane;
00061     friend class PolarCoordinatePlane;
00062 
00063     protected:
00064         explicit inline AbstractDiagram(
00065             Private *p, QWidget* parent, AbstractCoordinatePlane* plane );
00066         explicit AbstractDiagram (
00067             QWidget* parent = 0, AbstractCoordinatePlane* plane = 0 );
00068     public:
00069         virtual ~AbstractDiagram();
00070 
00071 
00075         bool compare( const AbstractDiagram* other )const;
00076 
00077 
00092         const QPair<QPointF, QPointF> dataBoundaries() const;
00093 
00094         // protected: // FIXME: why should that be private? (Mirko)
00101         virtual void paint ( PaintContext* paintContext ) = 0;
00102 
00109         virtual void resize ( const QSizeF& area ) = 0;
00110 
00112         virtual void setModel ( QAbstractItemModel * model );
00113 
00115         virtual void setSelectionModel( QItemSelectionModel* selectionModel );
00116 
00145         virtual void setAttributesModel( AttributesModel* model );
00146 
00153         virtual bool usesExternalAttributesModel()const;
00154 
00165         virtual AttributesModel* attributesModel() const;
00166 
00169         virtual void setRootIndex ( const QModelIndex& idx );
00170 
00172         virtual QRect visualRect(const QModelIndex &index) const;
00174         virtual void scrollTo(const QModelIndex &index, ScrollHint hint = EnsureVisible);
00176         virtual QModelIndex indexAt(const QPoint &point) const;
00178         virtual QModelIndex moveCursor(CursorAction cursorAction, Qt::KeyboardModifiers modifiers);
00180         virtual int horizontalOffset() const;
00182         virtual int verticalOffset() const;
00184         virtual bool isIndexHidden(const QModelIndex &index) const;
00186         virtual void setSelection(const QRect &rect, QItemSelectionModel::SelectionFlags command);
00188         virtual QRegion visualRegionForSelection(const QItemSelection &selection) const;
00189         virtual QRegion visualRegion(const QModelIndex &index) const;
00191         virtual void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight);
00193         virtual void doItemsLayout();
00194 
00201         AbstractCoordinatePlane* coordinatePlane() const;
00202 
00209         virtual void setCoordinatePlane( AbstractCoordinatePlane* plane );
00210 
00211 
00225         void setHidden( const QModelIndex & index, bool hidden );
00226 
00239         void setHidden( int dataset, bool hidden );
00240 
00252         void setHidden( bool hidden );
00253 
00260         bool isHidden() const;
00261 
00269         bool isHidden( int dataset ) const;
00270 
00278         bool isHidden( const QModelIndex & index ) const;
00279 
00280 
00287         void setDataValueAttributes( const QModelIndex & index,
00288                                      const DataValueAttributes & a );
00289 
00295         void setDataValueAttributes( int dataset, const DataValueAttributes & a );
00296 
00301         void setDataValueAttributes( const DataValueAttributes & a );
00302 
00309         DataValueAttributes dataValueAttributes() const;
00310 
00318         DataValueAttributes dataValueAttributes( int dataset ) const;
00319 
00328         DataValueAttributes dataValueAttributes( const QModelIndex & index ) const;
00329 
00336         void setPen( const QModelIndex& index, const QPen& pen );
00337 
00343         void setPen( int dataset, const QPen& pen );
00344 
00349         void setPen( const QPen& pen );
00350 
00357         QPen pen() const;
00365         QPen pen( int dataset ) const;
00373         QPen pen( const QModelIndex& index ) const;
00374 
00381         void setBrush( const QModelIndex& index, const QBrush& brush);
00382 
00388         void setBrush( int dataset, const QBrush& brush );
00389 
00394         void setBrush( const QBrush& brush);
00395 
00402         QBrush brush() const;
00410         QBrush brush( int dataset ) const;
00418         QBrush brush( const QModelIndex& index ) const;
00419 
00426         void setUnitPrefix( const QString& prefix, int column, Qt::Orientation orientation );
00432         void setUnitPrefix( const QString& prefix, Qt::Orientation orientation );
00433 
00440         void setUnitSuffix( const QString& suffix, int column, Qt::Orientation orientation );
00446          void setUnitSuffix( const QString& suffix, Qt::Orientation orientation );
00447 
00456         QString unitPrefix( int column, Qt::Orientation orientation, bool fallback = false ) const;
00462         QString unitPrefix( Qt::Orientation orientation ) const;
00463 
00472         QString unitSuffix( int column, Qt::Orientation orientation, bool fallback = false ) const;
00478         QString unitSuffix( Qt::Orientation orientation ) const;
00479 
00484         void setAllowOverlappingDataValueTexts( bool allow );
00485 
00489         bool allowOverlappingDataValueTexts() const;
00490 
00496         void setAntiAliasing( bool enabled );
00497 
00502         bool antiAliasing() const;
00503 
00510         void useDefaultColors();
00511 
00517         void useRainbowColors();
00518 
00524         void useSubduedColors();
00525 
00530         QStringList itemRowLabels() const;
00531 
00536         QStringList datasetLabels() const;
00537 
00547         QList<QBrush> datasetBrushes() const;
00548 
00558         QList<QPen> datasetPens() const;
00559 
00569         QList<MarkerAttributes> datasetMarkers() const;
00570 
00571 
00572         // configure the ordinate in percent mode - values 0 to 100
00573         void setPercentMode( bool percent );
00574         bool percentMode() const;
00575 
00576         virtual void paintMarker( QPainter* painter,
00577                                   const MarkerAttributes& markerAttributes,
00578                                   const QBrush& brush, const QPen&,
00579                                   const QPointF& point, const QSizeF& size );
00580 
00595         int datasetDimension() const;
00596 
00603         void setDatasetDimension( int dimension );
00604 
00605     protected:
00606         void setDatasetDimensionInternal( int dimension );
00607 
00608     public:
00609         void update() const;
00610 
00611         void paintMarker( QPainter* painter, const DataValueAttributes& a,
00612                           const QModelIndex& index,
00613                           const QPointF& pos );
00614         void paintMarker( QPainter* painter,
00615                           const QModelIndex& index,
00616                           const QPointF& pos );
00617         void paintDataValueText( QPainter* painter, const QModelIndex& index,
00618                                  const QPointF& pos, double value );
00619 
00620         // reverse mapping:
00624         QModelIndexList indexesAt( const QPoint& point ) const;
00625 
00626     protected:
00627         virtual bool checkInvariants( bool justReturnTheStatus=false ) const;
00628         virtual const QPair<QPointF, QPointF> calculateDataBoundaries() const = 0;
00629 
00630     protected Q_SLOTS:
00631         void setDataBoundariesDirty() const;
00632 
00633     protected:
00641         virtual void paintDataValueTexts( QPainter* painter );
00649         virtual void paintMarkers( QPainter* painter );
00650         void setAttributesModelRootIndex( const QModelIndex& );
00651         QModelIndex attributesModelRootIndex() const;
00652 
00660         double valueForCell( int row, int column ) const;
00661 
00662     Q_SIGNALS:
00671         void layoutChanged( AbstractDiagram* );
00672 
00674         void modelsChanged();
00675 
00677         void dataHidden();
00678 
00680         void propertiesChanged();
00681 
00682     private:
00683         QModelIndex conditionallyMapFromSource( const QModelIndex & sourceIndex ) const;
00684         QString roundValues( double value, const int decimalPos,
00685                               const int decimalDigits ) const;
00686 
00687     };
00688 
00689     typedef QList<AbstractDiagram*> AbstractDiagramList;
00690     typedef QList<const AbstractDiagram*> ConstAbstractDiagramList;
00691 
00695     class PrivateAttributesModel : public AttributesModel {
00696         Q_OBJECT
00697     public:
00698         explicit PrivateAttributesModel( QAbstractItemModel* model, QObject * parent = 0 )
00699             : AttributesModel(model,parent) {}
00700     };
00701 }
00702 
00703 #endif

Generated on Thu Mar 4 23:19:09 2010 for KD Chart 2 by  doxygen 1.5.4