00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef KDCHARTABSTRACTDIAGRAM_H
00024 #define KDCHARTABSTRACTDIAGRAM_H
00025
00026 #include <QList>
00027 #include <QRectF>
00028 #include <QAbstractItemView>
00029
00030 #include "KDChartGlobal.h"
00031 #include "KDChartMarkerAttributes.h"
00032 #include "KDChartAttributesModel.h"
00033
00034 namespace KDChart {
00035
00036 class AbstractCoordinatePlane;
00037 class AttributesModel;
00038 class DataValueAttributes;
00039 class PaintContext;
00040
00050 class KDCHART_EXPORT AbstractDiagram : public QAbstractItemView
00051 {
00052 Q_OBJECT
00053 Q_DISABLE_COPY( AbstractDiagram )
00054 KDCHART_DECLARE_PRIVATE_BASE_POLYMORPHIC( AbstractDiagram )
00055
00056 friend class AbstractCoordinatePlane;
00057 friend class CartesianCoordinatePlane;
00058 friend class PolarCoordinatePlane;
00059
00060 protected:
00061 explicit inline AbstractDiagram(
00062 Private *p, QWidget* parent, AbstractCoordinatePlane* plane );
00063 explicit AbstractDiagram (
00064 QWidget* parent = 0, AbstractCoordinatePlane* plane = 0 );
00065 public:
00066 virtual ~AbstractDiagram();
00067
00068
00072 bool compare( const AbstractDiagram* other )const;
00073
00074
00089 const QPair<QPointF, QPointF> dataBoundaries() const;
00090
00091
00098 virtual void paint ( PaintContext* paintContext ) = 0;
00099
00106 virtual void resize ( const QSizeF& area ) = 0;
00107
00109 virtual void setModel ( QAbstractItemModel * model );
00110
00112 virtual void setSelectionModel( QItemSelectionModel* selectionModel );
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;
00186 virtual QRegion visualRegion(const QModelIndex &index) const;
00188 virtual void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight);
00190 virtual void doItemsLayout();
00191
00198 AbstractCoordinatePlane* coordinatePlane() const;
00199
00206 virtual void setCoordinatePlane( AbstractCoordinatePlane* plane );
00207
00208
00222 void setHidden( const QModelIndex & index, bool hidden );
00223
00236 void setHidden( int dataset, bool hidden );
00237
00249 void setHidden( bool hidden );
00250
00257 bool isHidden() const;
00258
00266 bool isHidden( int dataset ) const;
00267
00275 bool isHidden( const QModelIndex & index ) const;
00276
00277
00284 void setDataValueAttributes( const QModelIndex & index,
00285 const DataValueAttributes & a );
00286
00292 void setDataValueAttributes( int dataset, const DataValueAttributes & a );
00293
00298 void setDataValueAttributes( const DataValueAttributes & a );
00299
00306 DataValueAttributes dataValueAttributes() const;
00307
00315 DataValueAttributes dataValueAttributes( int dataset ) const;
00316
00325 DataValueAttributes dataValueAttributes( const QModelIndex & index ) const;
00326
00333 void setPen( const QModelIndex& index, const QPen& pen );
00334
00340 void setPen( int dataset, const QPen& pen );
00341
00346 void setPen( const QPen& pen );
00347
00354 QPen pen() const;
00362 QPen pen( int dataset ) const;
00370 QPen pen( const QModelIndex& index ) const;
00371
00378 void setBrush( const QModelIndex& index, const QBrush& brush);
00379
00385 void setBrush( int dataset, const QBrush& brush );
00386
00391 void setBrush( const QBrush& brush);
00392
00399 QBrush brush() const;
00407 QBrush brush( int dataset ) const;
00415 QBrush brush( const QModelIndex& index ) const;
00416
00423 void setUnitPrefix( const QString& prefix, int column, Qt::Orientation orientation );
00429 void setUnitPrefix( const QString& prefix, Qt::Orientation orientation );
00430
00437 void setUnitSuffix( const QString& suffix, int column, Qt::Orientation orientation );
00443 void setUnitSuffix( const QString& suffix, Qt::Orientation orientation );
00444
00453 QString unitPrefix( int column, Qt::Orientation orientation, bool fallback = false ) const;
00459 QString unitPrefix( Qt::Orientation orientation ) const;
00460
00469 QString unitSuffix( int column, Qt::Orientation orientation, bool fallback = false ) const;
00475 QString unitSuffix( Qt::Orientation orientation ) const;
00476
00481 void setAllowOverlappingDataValueTexts( bool allow );
00482
00486 bool allowOverlappingDataValueTexts() const;
00487
00493 void setAntiAliasing( bool enabled );
00494
00499 bool antiAliasing() const;
00500
00507 void useDefaultColors();
00508
00514 void useRainbowColors();
00515
00521 void useSubduedColors();
00522
00527 QStringList itemRowLabels() const;
00528
00533 QStringList datasetLabels() const;
00534
00544 QList<QBrush> datasetBrushes() const;
00545
00555 QList<QPen> datasetPens() const;
00556
00566 QList<MarkerAttributes> datasetMarkers() const;
00567
00568
00579 void setPercentMode( bool percent );
00580
00581
00593 bool percentMode() const;
00594
00595 virtual void paintMarker( QPainter* painter,
00596 const MarkerAttributes& markerAttributes,
00597 const QBrush& brush, const QPen&,
00598 const QPointF& point, const QSizeF& size );
00599
00614 int datasetDimension() const;
00615
00622 void setDatasetDimension( int dimension );
00623
00624 protected:
00625 void setDatasetDimensionInternal( int dimension );
00626
00627 public:
00628 void update() const;
00629
00630 void paintMarker( QPainter* painter, const DataValueAttributes& a,
00631 const QModelIndex& index,
00632 const QPointF& pos );
00633 void paintMarker( QPainter* painter,
00634 const QModelIndex& index,
00635 const QPointF& pos );
00636 void paintDataValueText( QPainter* painter, const QModelIndex& index,
00637 const QPointF& pos, double value );
00638
00639
00643 QModelIndexList indexesAt( const QPoint& point ) const;
00644
00645 protected:
00646 virtual bool checkInvariants( bool justReturnTheStatus=false ) const;
00647 virtual const QPair<QPointF, QPointF> calculateDataBoundaries() const = 0;
00648
00649 protected Q_SLOTS:
00650 void setDataBoundariesDirty() const;
00651
00652 protected:
00660 virtual void paintDataValueTexts( QPainter* painter );
00668 virtual void paintMarkers( QPainter* painter );
00669 void setAttributesModelRootIndex( const QModelIndex& );
00670 QModelIndex attributesModelRootIndex() const;
00671
00679 double valueForCell( int row, int column ) const;
00680
00681 Q_SIGNALS:
00690 void layoutChanged( AbstractDiagram* );
00691
00696 void aboutToBeDestroyed();
00697
00699 void modelsChanged();
00700
00702 void modelDataChanged();
00703
00705 void dataHidden();
00706
00708 void propertiesChanged();
00709
00710 private:
00711 QModelIndex conditionallyMapFromSource( const QModelIndex & sourceIndex ) const;
00712 QString roundValues( double value, const int decimalPos,
00713 const int decimalDigits ) const;
00714
00715 };
00716
00717 typedef QList<AbstractDiagram*> AbstractDiagramList;
00718 typedef QList<const AbstractDiagram*> ConstAbstractDiagramList;
00719
00723 class PrivateAttributesModel : public AttributesModel {
00724 Q_OBJECT
00725 public:
00726 explicit PrivateAttributesModel( QAbstractItemModel* model, QObject * parent = 0 )
00727 : AttributesModel(model,parent) {}
00728 };
00729 }
00730
00731 #endif