KGantt

kganttabstractgrid.h
1/*
2 * SPDX-FileCopyrightText: 2001-2015 Klaralvdalens Datakonsult AB. All rights reserved.
3 *
4 * This file is part of the KGantt library.
5 *
6 * SPDX-License-Identifier: GPL-2.0-or-later
7 */
8
9#ifndef KGANTTABSTRACTGRID_H
10#define KGANTTABSTRACTGRID_H
11
12#include "kganttglobal.h"
13#include "kganttconstraint.h"
14
15QT_BEGIN_NAMESPACE
16class QPainter;
17class QRectF;
19class QModelIndex;
20QT_END_NAMESPACE
21
22namespace KGantt {
24 class Span;
25
26
27
28 /*!\class KGantt::AbstractGrid kganttabstractgrid.h KGanttAbstractGrid
29 * \ingroup KGantt
30 * \brief Abstract baseclass for grids. A grid is used to convert between
31 * QModelIndex'es and gantt chart values (qreals) and to paint the
32 * background and header of the view.
33 *
34 * \see KGantt::DateTimeGrid
35 */
36 class KGANTT_EXPORT AbstractGrid : public QObject {
37 Q_OBJECT
38 KGANTT_DECLARE_PRIVATE_BASE_POLYMORPHIC( AbstractGrid )
39 friend class GraphicsScene;
40 public:
41 /*! Constructor. Creates an AbstractGrid with parent \a parent.
42 * The QObject parent is not used for anything internally. */
43 AbstractGrid(QObject* parent = nullptr);
44
45
46 /*! Destructor. Does nothing */
47 ~AbstractGrid() override;
48
49 /*!\returns The QAbstractItemModel used by this grid */
50 QAbstractItemModel* model() const;
51
52 /*!\returns the current root index for this grid */
53 QModelIndex rootIndex() const;
54
55 /*!\fn virtual Span AbstractGrid::mapToChart( const QModelIndex& idx ) const
56 * Implement this to map from the data in the model to the location of
57 * the corresponding item in the view.
58 */
59 virtual Span mapToChart( const QModelIndex& idx ) const = 0;
60
61 /*!\fn virtual bool AbstractGrid::mapFromChart( const Span& span, const QModelIndex& idx, const QList<Constraint>& constraints ) const
62 * Implement this to update the model data based on the location of the item. Check
63 * against the \a constraints list to make sure no hard constraints are violated by
64 * writing back to the model.
65 * \returns true if the update succeeded.
66 */
67 virtual bool mapFromChart( const Span& span, const QModelIndex& idx,
68 const QList<Constraint>& constraints=QList<Constraint>() ) const = 0;
69
70 /*!
71 * Implement this to map from \a value to the corresponding location in the view.
72 * Return a negative value if \a value cannot be mapped.
73 * The default implementation returns -1.0.
74 */
75 virtual qreal mapToChart( const QVariant &value ) const;
76
77 /*!
78 * Implement this to map from \a x to the corresponding location in the view.
79 * Return an invalid value if \a x cannot be mapped.
80 */
81 virtual QVariant mapFromChart( qreal x ) const;
82
83 /*!\returns true if the startpoint is before the endpoint
84 * of the constraint \a c.
85 */
86 bool isSatisfiedConstraint( const Constraint& c ) const;
87
88 /*!\fn virtual void AbstractGrid::paintGrid( QPainter* painter, const QRectF& sceneRect, const QRectF& exposedRect, AbstractRowController* rowController=0, QWidget* widget=0 )
89 *
90 * Implement this to paint the background of the view -- typically
91 * with some grid lines.
92 * \param painter -- the QPainter to paint with.
93 * \param sceneRect -- the total bounding rectangle of the scene.
94 * \param exposedRect -- the rectangle that needs to be painted.
95 * \param rowController -- the row controller used by the view -- may be 0.
96 * \param widget -- the widget used by the view -- may be 0.
97 */
98 virtual void paintGrid( QPainter* painter, const QRectF& sceneRect, const QRectF& exposedRect,
99 AbstractRowController* rowController = nullptr, QWidget* widget = nullptr ) = 0;
100
101
102 /*!\fn virtual void AbstractGrid::paintHeader( QPainter* painter, const QRectF& headerRect, const QRectF& exposedRect, qreal offset, QWidget* widget=0 )
103 *
104 * Implement this to paint the header part of the view.
105 * \param painter -- the QPainter to paint with.
106 * \param headerRect -- the total rectangle occupied by the header.
107 * \param exposedRect -- the rectangle that needs to be painted.
108 * \param offset -- the horizontal scroll offset of the view.
109 * \param widget -- the widget used by the view -- may be 0.
110 */
111 virtual void paintHeader( QPainter* painter, const QRectF& headerRect, const QRectF& exposedRect,
112 qreal offset, QWidget* widget = nullptr ) = 0;
113
114 public Q_SLOTS:
115 /*! Sets the QAbstractItemModel used by this grid implementation.
116 * This is called by the view, you should never need to call this
117 * from client code. */
118 /*internal*/ virtual void setModel( QAbstractItemModel* model );
119
120 /*! Sets the root index used by this grid implementation.
121 * This is called by the view, you should never need to call this
122 * from client code. */
123 /*internal*/ virtual void setRootIndex( const QModelIndex& idx );
124 Q_SIGNALS:
125 void gridChanged();
126
127 protected:
128 /*!
129 \todo document this function
130 */
131 virtual void drawBackground(QPainter* paint, const QRectF& rect);
132
133 /*!
134 \todo document this function
135 */
136 virtual void drawForeground(QPainter* paint, const QRectF& rect);
137 };
138}
139
140#endif /* KGANTTABSTRACTGRID_H */
Abstract baseclass for grids. A grid is used to convert between QModelIndex'es and gantt chart values...
virtual Span mapToChart(const QModelIndex &idx) const =0
virtual void paintGrid(QPainter *painter, const QRectF &sceneRect, const QRectF &exposedRect, AbstractRowController *rowController=nullptr, QWidget *widget=nullptr)=0
virtual void paintHeader(QPainter *painter, const QRectF &headerRect, const QRectF &exposedRect, qreal offset, QWidget *widget=nullptr)=0
virtual bool mapFromChart(const Span &span, const QModelIndex &idx, const QList< Constraint > &constraints=QList< Constraint >()) const =0
Abstract baseclass for row controllers. A row controller is used by the GraphicsView to nagivate the ...
A class used to represent a dependency.
A class representing a start point and a length.
Contains KGantt macros.
Global namespace.
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 22 2024 12:02:41 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.