File indexing completed on 2024-05-12 04:20:39
0001 /* 0002 * SPDX-FileCopyrightText: 2001-2015 Klaralvdalens Datakonsult AB. All rights reserved. 0003 * 0004 * This file is part of the KGantt library. 0005 * 0006 * SPDX-License-Identifier: GPL-2.0-or-later 0007 */ 0008 0009 #ifndef KGANTTABSTRACTGRID_H 0010 #define KGANTTABSTRACTGRID_H 0011 0012 #include "kganttglobal.h" 0013 #include "kganttconstraint.h" 0014 0015 QT_BEGIN_NAMESPACE 0016 class QPainter; 0017 class QRectF; 0018 class QAbstractItemModel; 0019 class QModelIndex; 0020 QT_END_NAMESPACE 0021 0022 namespace KGantt { 0023 class AbstractRowController; 0024 class Span; 0025 0026 0027 0028 /*!\class KGantt::AbstractGrid kganttabstractgrid.h KGanttAbstractGrid 0029 * \ingroup KGantt 0030 * \brief Abstract baseclass for grids. A grid is used to convert between 0031 * QModelIndex'es and gantt chart values (qreals) and to paint the 0032 * background and header of the view. 0033 * 0034 * \see KGantt::DateTimeGrid 0035 */ 0036 class KGANTT_EXPORT AbstractGrid : public QObject { 0037 Q_OBJECT 0038 KGANTT_DECLARE_PRIVATE_BASE_POLYMORPHIC( AbstractGrid ) 0039 friend class GraphicsScene; 0040 public: 0041 /*! Constructor. Creates an AbstractGrid with parent \a parent. 0042 * The QObject parent is not used for anything internally. */ 0043 AbstractGrid(QObject* parent = nullptr); 0044 0045 0046 /*! Destructor. Does nothing */ 0047 ~AbstractGrid() override; 0048 0049 /*!\returns The QAbstractItemModel used by this grid */ 0050 QAbstractItemModel* model() const; 0051 0052 /*!\returns the current root index for this grid */ 0053 QModelIndex rootIndex() const; 0054 0055 /*!\fn virtual Span AbstractGrid::mapToChart( const QModelIndex& idx ) const 0056 * Implement this to map from the data in the model to the location of 0057 * the corresponding item in the view. 0058 */ 0059 virtual Span mapToChart( const QModelIndex& idx ) const = 0; 0060 0061 /*!\fn virtual bool AbstractGrid::mapFromChart( const Span& span, const QModelIndex& idx, const QList<Constraint>& constraints ) const 0062 * Implement this to update the model data based on the location of the item. Check 0063 * against the \a constraints list to make sure no hard constraints are violated by 0064 * writing back to the model. 0065 * \returns true if the update succeeded. 0066 */ 0067 virtual bool mapFromChart( const Span& span, const QModelIndex& idx, 0068 const QList<Constraint>& constraints=QList<Constraint>() ) const = 0; 0069 0070 /*! 0071 * Implement this to map from \a value to the corresponding location in the view. 0072 * Return a negative value if \a value cannot be mapped. 0073 * The default implementation returns -1.0. 0074 */ 0075 virtual qreal mapToChart( const QVariant &value ) const; 0076 0077 /*! 0078 * Implement this to map from \a x to the corresponding location in the view. 0079 * Return an invalid value if \a x cannot be mapped. 0080 */ 0081 virtual QVariant mapFromChart( qreal x ) const; 0082 0083 /*!\returns true if the startpoint is before the endpoint 0084 * of the constraint \a c. 0085 */ 0086 bool isSatisfiedConstraint( const Constraint& c ) const; 0087 0088 /*!\fn virtual void AbstractGrid::paintGrid( QPainter* painter, const QRectF& sceneRect, const QRectF& exposedRect, AbstractRowController* rowController=0, QWidget* widget=0 ) 0089 * 0090 * Implement this to paint the background of the view -- typically 0091 * with some grid lines. 0092 * \param painter -- the QPainter to paint with. 0093 * \param sceneRect -- the total bounding rectangle of the scene. 0094 * \param exposedRect -- the rectangle that needs to be painted. 0095 * \param rowController -- the row controller used by the view -- may be 0. 0096 * \param widget -- the widget used by the view -- may be 0. 0097 */ 0098 virtual void paintGrid( QPainter* painter, const QRectF& sceneRect, const QRectF& exposedRect, 0099 AbstractRowController* rowController = nullptr, QWidget* widget = nullptr ) = 0; 0100 0101 0102 /*!\fn virtual void AbstractGrid::paintHeader( QPainter* painter, const QRectF& headerRect, const QRectF& exposedRect, qreal offset, QWidget* widget=0 ) 0103 * 0104 * Implement this to paint the header part of the view. 0105 * \param painter -- the QPainter to paint with. 0106 * \param headerRect -- the total rectangle occupied by the header. 0107 * \param exposedRect -- the rectangle that needs to be painted. 0108 * \param offset -- the horizontal scroll offset of the view. 0109 * \param widget -- the widget used by the view -- may be 0. 0110 */ 0111 virtual void paintHeader( QPainter* painter, const QRectF& headerRect, const QRectF& exposedRect, 0112 qreal offset, QWidget* widget = nullptr ) = 0; 0113 0114 public Q_SLOTS: 0115 /*! Sets the QAbstractItemModel used by this grid implementation. 0116 * This is called by the view, you should never need to call this 0117 * from client code. */ 0118 /*internal*/ virtual void setModel( QAbstractItemModel* model ); 0119 0120 /*! Sets the root index used by this grid implementation. 0121 * This is called by the view, you should never need to call this 0122 * from client code. */ 0123 /*internal*/ virtual void setRootIndex( const QModelIndex& idx ); 0124 Q_SIGNALS: 0125 void gridChanged(); 0126 0127 protected: 0128 /*! 0129 \todo document this function 0130 */ 0131 virtual void drawBackground(QPainter* paint, const QRectF& rect); 0132 0133 /*! 0134 \todo document this function 0135 */ 0136 virtual void drawForeground(QPainter* paint, const QRectF& rect); 0137 }; 0138 } 0139 0140 #endif /* KGANTTABSTRACTGRID_H */