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 
00142         virtual void setAttributesModel( AttributesModel* model );
00143 
00150         virtual bool usesExternalAttributesModel()const;
00151 
00162         virtual AttributesModel* attributesModel() const;
00163 
00166         virtual void setRootIndex ( const QModelIndex& idx );
00167 
00169         virtual QRect visualRect(const QModelIndex &index) const;
00171         virtual void scrollTo(const QModelIndex &index, ScrollHint hint = EnsureVisible);
00173         virtual QModelIndex indexAt(const QPoint &point) const;
00175         virtual QModelIndex moveCursor(CursorAction cursorAction, Qt::KeyboardModifiers modifiers);
00177         virtual int horizontalOffset() const;
00179         virtual int verticalOffset() const;
00181         virtual bool isIndexHidden(const QModelIndex &index) const;
00183         virtual void setSelection(const QRect &rect, QItemSelectionModel::SelectionFlags command);
00185         virtual QRegion visualRegionForSelection(const QItemSelection &selection) const;
00187         virtual void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight);
00189         virtual void doItemsLayout();
00190 
00197         AbstractCoordinatePlane* coordinatePlane() const;
00198 
00205         virtual void setCoordinatePlane( AbstractCoordinatePlane* plane );
00206 
00207 
00220         void setHidden( const QModelIndex & index, bool hidden );
00221 
00234         void setHidden( int column, bool hidden );
00235 
00247         void setHidden( bool hidden );
00248 
00255         bool isHidden() const;
00256 
00264         bool isHidden( int column ) const;
00265 
00273         bool isHidden( const QModelIndex & index ) const;
00274 
00275 
00281         void setDataValueAttributes( const QModelIndex & index,
00282                                      const DataValueAttributes & a );
00283 
00289         void setDataValueAttributes( int dataset, const DataValueAttributes & a );
00290 
00295         void setDataValueAttributes( const DataValueAttributes & a );
00296 
00303         DataValueAttributes dataValueAttributes() const;
00304 
00312         DataValueAttributes dataValueAttributes( int column ) const;
00313 
00321         DataValueAttributes dataValueAttributes( const QModelIndex & index ) const;
00322 
00328         void setPen( const QModelIndex& index, const QPen& pen );
00329 
00335         void setPen( int dataset, const QPen& pen );
00336 
00341         void setPen( const QPen& pen );
00342 
00349         QPen pen() const;
00357         QPen pen( int dataset ) const;
00364         QPen pen( const QModelIndex& index ) const;
00365 
00371         void setBrush( const QModelIndex& index, const QBrush& brush);
00372 
00378         void setBrush( int dataset, const QBrush& brush );
00379 
00384         void setBrush( const QBrush& brush);
00385 
00392         QBrush brush() const;
00400         QBrush brush( int dataset ) const;
00407         QBrush brush( const QModelIndex& index ) const;
00408 
00409         /*
00410          * Set the unit prefix to be used on axes for one specific column.
00411          * @param prefix The prefix to be used.
00412          * @param column The column which should be set.
00413          * @param orientation The orientation of the axis to use.
00414          */
00415         void setUnitPrefix( const QString& prefix, int column, Qt::Orientation orientation );
00416         /*
00417          * Set the unit prefix to be used on axes for all columns.
00418          * @param prefix The prefix to be used.
00419          * @param orientation The orientation of the axis to use.
00420          */
00421         void setUnitPrefix( const QString& prefix, Qt::Orientation orientation );
00422 
00423         /*
00424          * Set the unit prefix to be used on axes for one specific column.
00425          * @param suffix The suffix to be used.
00426          * @param column The column which should be set.
00427          * @param orientation The orientation of the axis to use.
00428          */
00429         void setUnitSuffix( const QString& suffix, int column, Qt::Orientation orientation );
00430         /*
00431          * Set the unit prefix to be used on axes for all columns.
00432          * @param suffix The suffix to be used.
00433          * @param orientation The orientation of the axis to use.
00434          */
00435          void setUnitSuffix( const QString& suffix, Qt::Orientation orientation );
00436 
00437         /*
00438          * Retrieves the axis unit prefix for a specific column.
00439          * @param column The column whose prefix should be retrieved.
00440          * @param orientation The orientation of the axis.
00441          * @param fallback If true, the prefix for all columns is returned, when 
00442          *                 none is set for the selected column.
00443          * @return The axis unit prefix.
00444          */
00445         QString unitPrefix( int column, Qt::Orientation orientation, bool fallback = false ) const;
00446         /*
00447          * Retrieves the axis unit prefix.
00448          * @param orientation The orientation of the axis.
00449          * @return The axis unit prefix.
00450          */
00451         QString unitPrefix( Qt::Orientation orientation ) const;
00452 
00453         /*
00454          * Retrieves the axis unit suffix for a specific column.
00455          * @param column The column whose prefix should be retrieved.
00456          * @param orientation The orientation of the axis.
00457          * @param fallback If true, the suffix for all columns is returned, when 
00458          *                 none is set for the selected column.
00459          * @return The axis unit suffix.
00460          */
00461         QString unitSuffix( int column, Qt::Orientation orientation, bool fallback = false ) const;
00462         /*
00463          * Retrieves the axis unit suffix.
00464          * @param orientation The orientation of the axis.
00465          * @return The axis unit suffix.
00466          */
00467         QString unitSuffix( Qt::Orientation orientation ) const;
00468 
00473         void setAllowOverlappingDataValueTexts( bool allow );
00474 
00478         bool allowOverlappingDataValueTexts() const;
00479 
00485         void setAntiAliasing( bool enabled );
00486 
00491         bool antiAliasing() const;
00492 
00499         void useDefaultColors();
00500 
00506         void useRainbowColors();
00507 
00513         void useSubduedColors();
00514 
00519         QStringList itemRowLabels() const;
00520 
00525         QStringList datasetLabels() const;
00526 
00536         QList<QBrush> datasetBrushes() const;
00537 
00547         QList<QPen> datasetPens() const;
00548 
00558         QList<MarkerAttributes> datasetMarkers() const;
00559 
00560 
00561         // configure the ordinate in percent mode - values 0 to 100
00562         void setPercentMode( bool percent );
00563         bool percentMode() const;
00564 
00565         virtual void paintMarker( QPainter* painter,
00566                                   const MarkerAttributes& markerAttributes,
00567                                   const QBrush& brush, const QPen&,
00568                                   const QPointF& point, const QSizeF& size );
00569 
00584         int datasetDimension() const;
00585 
00591         void setDatasetDimension( int dimension );
00592 
00593         void update() const;
00594 
00595         void paintMarker( QPainter* painter, const QModelIndex& index,
00596                           const QPointF& pos );
00597         void paintDataValueText( QPainter* painter, const QModelIndex& index,
00598                                  const QPointF& pos, double value );
00599 
00600         // reverse mapping:
00604         QModelIndexList indexesAt( const QPoint& point ) const;
00605 
00606     protected:
00607         virtual bool checkInvariants( bool justReturnTheStatus=false ) const;
00608         virtual const QPair<QPointF, QPointF> calculateDataBoundaries() const = 0;
00609         void setDataBoundariesDirty() const;
00610         virtual void paintDataValueTexts( QPainter* painter );
00611         virtual void paintMarkers( QPainter* painter );
00612         void setAttributesModelRootIndex( const QModelIndex& );
00613         QModelIndex attributesModelRootIndex() const;
00614         QModelIndex columnToIndex( int column ) const;
00622         double valueForCell( int row, int column ) const;
00623 
00624     Q_SIGNALS:
00633         void layoutChanged( AbstractDiagram* );
00634 
00636         void modelsChanged();
00637 
00639         void dataHidden();
00640 
00642         void propertiesChanged();
00643 
00644     private:
00645         QString roundValues( double value, const int decimalPos,
00646                               const int decimalDigits ) const;
00647 
00648     };
00649 
00650     typedef QList<AbstractDiagram*> AbstractDiagramList;
00651     typedef QList<const AbstractDiagram*> ConstAbstractDiagramList;
00652 
00656     class PrivateAttributesModel : public AttributesModel {
00657         Q_OBJECT
00658     public:
00659         explicit PrivateAttributesModel( QAbstractItemModel* model, QObject * parent = 0 )
00660             : AttributesModel(model,parent) {}
00661     };
00662 }
00663 
00664 #endif

Generated on Mon Sep 17 16:16:49 2007 for KD Chart 2 by  doxygen 1.5.1