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