kdganttgraphicsscene.h

Go to the documentation of this file.
00001 /****************************************************************************
00002 ** Copyright (C) 2001-2010 Klaralvdalens Datakonsult AB.  All rights reserved.
00003 **
00004 ** This file is part of the KD Chart library.
00005 **
00006 ** Licensees holding valid commercial KD Chart licenses may use this file in
00007 ** accordance with the KD Chart Commercial License Agreement provided with
00008 ** the Software.
00009 **
00010 **
00011 ** This file may be distributed and/or modified under the terms of the
00012 ** GNU General Public License version 2 and version 3 as published by the
00013 ** Free Software Foundation and appearing in the file LICENSE.GPL included.
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 ** Contact info@kdab.com if any conditions of this licensing are not
00019 ** clear to you.
00020 **
00021 **********************************************************************/
00022 
00023 #ifndef KDGANTTGRAPHICSSCENE_H
00024 #define KDGANTTGRAPHICSSCENE_H
00025 
00026 #include <QDateTime>
00027 #include <QList>
00028 #include <QGraphicsScene>
00029 #include <QModelIndex>
00030 
00031 #include "kdganttglobal.h"
00032 
00033 class QAbstractProxyModel;
00034 class QItemSelectionModel;
00035 class QPrinter;
00036 
00037 namespace KDGantt {
00038     class AbstractGrid;
00039     class AbstractRowController;
00040     class GraphicsItem;
00041     class Constraint;
00042     class ConstraintModel;
00043     class ConstraintGraphicsItem;
00044     class ItemDelegate;
00045 
00046     class KDCHART_EXPORT GraphicsScene : public QGraphicsScene {
00047         Q_OBJECT
00048         KDGANTT_DECLARE_PRIVATE_BASE_POLYMORPHIC( GraphicsScene )
00049     public:
00050         explicit GraphicsScene( QObject* parent=0 );
00051         virtual ~GraphicsScene();
00052 
00053         //qreal dateTimeToSceneX( const QDateTime& dt ) const;
00054         //QDateTime sceneXtoDateTime( qreal x ) const;
00055 
00056         static QModelIndex mainIndex( const QModelIndex& idx );
00057         static QModelIndex dataIndex( const QModelIndex& idx );
00058 
00059         QAbstractItemModel* model() const;
00060         QAbstractProxyModel* summaryHandlingModel() const;
00061         QModelIndex rootIndex() const;
00062         ConstraintModel* constraintModel() const;
00063         QItemSelectionModel* selectionModel() const;
00064 
00065         void insertItem( const QPersistentModelIndex&, GraphicsItem* );
00066         void removeItem( const QModelIndex& );
00067         using QGraphicsScene::removeItem;
00068         GraphicsItem* findItem( const QModelIndex& ) const;
00069         GraphicsItem* findItem( const QPersistentModelIndex& ) const;
00070 
00071         void updateItems();
00072         void clearItems();
00073         void deleteSubtree( const QModelIndex& );
00074 
00075         ConstraintGraphicsItem* findConstraintItem( const Constraint& ) const;
00076         QList<ConstraintGraphicsItem*> findConstraintItems( const QModelIndex& idx ) const;
00077         void clearConstraintItems();
00078 
00079         void setItemDelegate( ItemDelegate* );
00080         ItemDelegate* itemDelegate() const;
00081 
00082         void setRowController( AbstractRowController* rc );
00083         AbstractRowController* rowController() const;
00084 
00085         void setGrid( AbstractGrid* grid );
00086         AbstractGrid* grid() const;
00087 
00088         bool isReadOnly() const;
00089 
00090         void updateRow( const QModelIndex& idx );
00091         GraphicsItem* createItem( ItemType type ) const;
00092 
00093         /* used by GraphicsItem */
00094         void itemEntered( const QModelIndex& );
00095         void itemPressed( const QModelIndex& );
00096         void itemClicked( const QModelIndex& );
00097         void itemDoubleClicked( const QModelIndex& );
00098         void setDragSource( GraphicsItem* item );
00099         GraphicsItem* dragSource() const;
00100 
00101         /* Printing */
00102         void print( QPrinter* printer, bool drawRowLabels = true );
00103         void print( QPrinter* printer, qreal start, qreal end, bool drawRowLabels = true );
00104         void print( QPainter* painter, const QRectF& target = QRectF(), bool drawRowLabels=true );
00105         void print( QPainter* painter, qreal start, qreal end, const QRectF& target = QRectF(), bool drawRowLabels=true );
00106 
00107     Q_SIGNALS:
00108         void gridChanged();
00109 
00110         void clicked( const QModelIndex & index );
00111         void doubleClicked( const QModelIndex & index );
00112         void entered( const QModelIndex & index );
00113         void pressed( const QModelIndex & index );
00114 
00115     protected:
00116         /*reimp*/ void helpEvent( QGraphicsSceneHelpEvent *helpEvent );
00117         /*reimp*/ void drawBackground( QPainter* painter, const QRectF& rect );
00118         /*reimp*/ void drawForeground( QPainter* painter, const QRectF& rect );
00119 
00120     public Q_SLOTS:
00121         void setModel( QAbstractItemModel* );
00122         void setSummaryHandlingModel( QAbstractProxyModel* );
00123         void setConstraintModel( ConstraintModel* );
00124         void setRootIndex( const QModelIndex& idx );
00125         void setSelectionModel( QItemSelectionModel* selectionmodel );
00126         void setReadOnly( bool );
00127 
00128     private Q_SLOTS:
00129         /* slots for ConstraintModel */
00130         void slotConstraintAdded( const KDGantt::Constraint& );
00131         void slotConstraintRemoved( const KDGantt::Constraint& );
00132         void slotGridChanged();
00133     private:
00134         void doPrint( QPainter* painter, const QRectF& targetRect,
00135                       qreal start, qreal end,
00136                       QPrinter* printer, bool drawRowLabels );
00137     };
00138 }
00139 
00140 #endif /* KDGANTTGRAPHICSSCENE_H */