KGantt

kganttgraphicsscene.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 KGANTTGRAPHICSSCENE_H
10#define KGANTTGRAPHICSSCENE_H
11
12#include <QDateTime>
13#include <QList>
14#include <QGraphicsScene>
15#include <QModelIndex>
16
17#include "kganttglobal.h"
18
19QT_BEGIN_NAMESPACE
22class QItemSelection;
23class QPrinter;
25
26
27/*!\class KGantt::GraphicsScene
28 * \internal
29 */
31QT_END_NAMESPACE
32
33namespace KGantt {
34 class AbstractGrid;
35 class AbstractRowController;
36 class GraphicsItem;
37 class Constraint;
38 class ConstraintModel;
39 class ConstraintGraphicsItem;
40 class ItemDelegate;
41 class PrintingContext;
42
43 class KGANTT_EXPORT GraphicsScene : public QGraphicsScene {
44 Q_OBJECT
45 KGANTT_DECLARE_PRIVATE_BASE_POLYMORPHIC( GraphicsScene )
46 public:
47 explicit GraphicsScene( QObject* parent = nullptr );
48 ~GraphicsScene() override;
49
50 //qreal dateTimeToSceneX( const QDateTime& dt ) const;
51 //QDateTime sceneXtoDateTime( qreal x ) const;
52
53 static QModelIndex mainIndex( const QModelIndex& idx );
54
55 /*! Returns the index pointing to the last column
56 * in the same row as idx. This can be thought of
57 * as in "inverse" of mainIndex()
58 */
59 static QModelIndex dataIndex( const QModelIndex& idx );
60
61 QAbstractItemModel* model() const;
62 QAbstractProxyModel* summaryHandlingModel() const;
63 QModelIndex rootIndex() const;
64 ConstraintModel* constraintModel() const;
65 QItemSelectionModel* selectionModel() const;
66
67 void insertItem( const QPersistentModelIndex&, GraphicsItem* );
68 void removeItem( const QModelIndex& );
70 GraphicsItem* findItem( const QModelIndex& ) const;
71 GraphicsItem* findItem( const QPersistentModelIndex& ) const;
72
73 void updateItems();
74 void clearItems();
75 void deleteSubtree( const QModelIndex& );
76
77 ConstraintGraphicsItem* findConstraintItem( const Constraint& ) const;
78 QList<ConstraintGraphicsItem*> findConstraintItems( const QModelIndex& idx ) const;
79
80 void setItemDelegate( ItemDelegate* );
81 ItemDelegate* itemDelegate() const;
82
83 void setRowController( AbstractRowController* rc );
84 AbstractRowController* rowController() const;
85
86 /**
87 * Set the grid to @p grid.
88 * The current grid (if set) is deleted.
89 * If @p grid is nullptr, the scene reverts to use the default_grid
90 */
91 void setGrid( AbstractGrid* grid );
92 /**
93 * @return the grid set with setGrid().
94 * Note: Returns nullptr if no grid has been set.
95 */
96 AbstractGrid* grid() const;
97 /**
98 * @return the current grid.
99 */
100 const AbstractGrid *getGrid() const;
101 /**
102 * @return the grid set with setGrid()
103 * Note: Returns nullptr if no grid has been set.
104 * The scene reverts to use the default_grid.
105 */
106 AbstractGrid *takeGrid();
107
108 bool isReadOnly() const;
109
110 void updateRow( const QModelIndex& idx );
111
112 /*! Creates a new item of type type.
113 */
114 GraphicsItem* createItem( ItemType type ) const;
115
116 /* used by GraphicsItem */
117 void itemEntered( const QModelIndex& );
118 void itemPressed( const QModelIndex& idx, QGraphicsSceneMouseEvent *event );
119 void itemClicked( const QModelIndex& );
120 void itemDoubleClicked( const QModelIndex& );
121 void setDragSource( GraphicsItem* item );
122 GraphicsItem* dragSource() const;
123
124 /* Printing */
125
126 /*! Print the Gantt chart using \a printer. If \a drawRowLabels
127 * is true (the default), each row will have it's label printed
128 * on the left side. If \a drawColumnLabels is true (the
129 * default), each column will have it's label printed at the
130 * top side.
131 *
132 * This version of print() will print multiple pages.
133 */
134 void print( QPrinter* printer, bool drawRowLabels = true, bool drawColumnLabels = true );
135
136 /*! Print part of the Gantt chart from \a start to \a end using \a printer.
137 * If \a drawRowLabels is true (the default), each row will have it's
138 * label printed on the left side. If \a drawColumnLabels is true (the
139 * default), each column will have it's label printed at the
140 * top side.
141 *
142 * This version of print() will print multiple pages.
143 *
144 * To print a certain range of a chart with a DateTimeGrid, use
145 * qreal DateTimeGrid::mapFromDateTime( const QDateTime& dt) const
146 * to figure out the values for \a start and \a end.
147 */
148 void print( QPrinter* printer, qreal start, qreal end, bool drawRowLabels = true, bool drawColumnLabels = true );
149
150 /*! Render the GanttView inside the rectangle \a target using the painter \a painter.
151 * If \a drawRowLabels is true (the default), each row will have it's
152 * label printed on the left side. If \a drawColumnLabels is true (the
153 * default), each column will have it's label printed at the
154 * top side.
155 */
156 void print( QPainter* painter, const QRectF& target = QRectF(), bool drawRowLabels=true, bool drawColumnLabels = true );
157
158 /*! Render the GanttView inside the rectangle \a target using the painter \a painter.
159 * If \a drawRowLabels is true (the default), each row will have it's
160 * label printed on the left side. If \a drawColumnLabels is true (the
161 * default), each column will have it's label printed at the
162 * top side.
163 *
164 * To print a certain range of a chart with a DateTimeGrid, use
165 * qreal DateTimeGrid::mapFromDateTime( const QDateTime& dt) const
166 * to figure out the values for \a start and \a end.
167 */
168 void print( QPainter* painter, qreal start, qreal end, const QRectF& target = QRectF(), bool drawRowLabels=true, bool drawColumnLabels = true );
169
170 /*! Print the Gantt chart on the \a printer in accordance with the PrintingContext \a context
171 *
172 * \see PrintingContext
173 *
174 * \since 2.8.0
175 */
176 void printDiagram( QPrinter *printer, const PrintingContext &context );
177
178 Q_SIGNALS:
179 void gridChanged();
180
181 void clicked( const QModelIndex & index );
182 void qrealClicked( const QModelIndex & index );
183 void entered( const QModelIndex & index );
184 void pressed( const QModelIndex & index );
185
186 protected:
187 /*reimp*/ void helpEvent( QGraphicsSceneHelpEvent *helpEvent ) override;
188 /*reimp*/ void drawBackground( QPainter* painter, const QRectF& rect ) override;
189 /*reimp*/ void drawForeground( QPainter* painter, const QRectF& rect ) override;
190
191 public Q_SLOTS:
192 void setModel( QAbstractItemModel* );
193 void setSummaryHandlingModel( QAbstractProxyModel* );
194 void setConstraintModel( KGantt::ConstraintModel* );
195 void setRootIndex( const QModelIndex& idx );
196 void setSelectionModel( QItemSelectionModel* selectionmodel );
197 void setReadOnly( bool );
198
199 private Q_SLOTS:
200 /* slots for ConstraintModel */
201 void slotConstraintAdded( const KGantt::Constraint& );
202 void slotConstraintRemoved( const KGantt::Constraint& );
203 void slotGridChanged();
204 void slotSelectionChanged(const QItemSelection &selected, const QItemSelection &deselected);
205 void selectionModelChanged(QAbstractItemModel *);
206
207 private:
208 /*\internal
209 */
210 void doPrint( QPainter* painter, const QRectF& targetRect,
211 qreal start, qreal end,
212 QPrinter* printer, bool drawRowLabels, bool drawColumnLabels );
213
214 void doPrintScene( QPrinter *printer, QPainter *painter, const QRectF& targetRect, const PrintingContext &context );
215
216 void drawLabelsHeader( QPainter *painter, const QRectF &sourceRect, const QRectF &targetRect );
217 };
218}
219
220#endif /* KGANTTGRAPHICSSCENE_H */
Abstract baseclass for grids. A grid is used to convert between QModelIndex'es and gantt chart values...
Abstract baseclass for row controllers. A row controller is used by the GraphicsView to nagivate the ...
A class used to represent a dependency.
Class used to render gantt items in a KGantt::GraphicsView.
The PrintingContext class provides options for printing the gantt chart.
Q_SCRIPTABLE Q_NOREPLY void start()
Contains KGantt macros.
Global namespace.
void removeItem(QGraphicsItem *item)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:02:52 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.