KGantt

kganttgraphicsview.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 KGANTTGRAPHICSVIEW_H
10#define KGANTTGRAPHICSVIEW_H
11
12#include <QGraphicsView>
13
14#include "kganttglobal.h"
15
16QT_BEGIN_NAMESPACE
17class QPrinter;
18class QModelIndex;
23
24namespace KGantt {
25 class AbstractRowController;
26 class AbstractGrid;
27 class GraphicsItem;
28 class ConstraintModel;
29 class ItemDelegate;
30 class PrintingContext;
31
32 /*!\class KGantt::GraphicsView kganttgraphicsview.h KGanttGraphicsView
33 * \ingroup KGantt
34 * \brief The GraphicsView class provides a model/view implementation of a gantt chart.
35 */
36 class KGANTT_EXPORT GraphicsView : public QGraphicsView {
37 Q_OBJECT
38 KGANTT_DECLARE_PRIVATE_BASE_POLYMORPHIC(GraphicsView)
39
40 Q_PROPERTY( bool readOnly READ isReadOnly WRITE setReadOnly )
41
42 Q_PRIVATE_SLOT( d, void slotGridChanged() )
43 Q_PRIVATE_SLOT( d, void slotHorizontalScrollValueChanged( int ) )
44
45
46 Q_PRIVATE_SLOT( d, void slotHeaderContextMenuRequested( const QPoint& ) )
47 /* slots for QAbstractItemModel signals */
48 Q_PRIVATE_SLOT( d, void slotColumnsInserted( const QModelIndex& parent, int start, int end ) )
49 Q_PRIVATE_SLOT( d, void slotColumnsRemoved( const QModelIndex& parent, int start, int end ) )
50 Q_PRIVATE_SLOT( d, void slotDataChanged( const QModelIndex& topLeft, const QModelIndex& bottomRight ) )
51 Q_PRIVATE_SLOT( d, void slotLayoutChanged() )
52 Q_PRIVATE_SLOT( d, void slotModelReset() )
53 Q_PRIVATE_SLOT( d, void slotRowsInserted( const QModelIndex& parent, int start, int end ) )
54 Q_PRIVATE_SLOT( d, void slotRowsAboutToBeRemoved( const QModelIndex& parent, int start, int end ) )
55 Q_PRIVATE_SLOT( d, void slotRowsRemoved( const QModelIndex& parent, int start, int end ) )
56
57 Q_PRIVATE_SLOT( d, void slotItemClicked( const QModelIndex& idx ) )
58 Q_PRIVATE_SLOT( d, void slotItemDoubleClicked( const QModelIndex& idx ) )
59 public:
60 /*! Constructor. Creates a new KGantt::GraphicsView with parent
61 * \a parent.
62 */
63 explicit GraphicsView( QWidget* parent = nullptr );
64
65
66 /*! Destroys this view. */
67 ~GraphicsView() override;
68
69 /*! \returns the current model displayed by this view
70 *
71 * Note: The returned model is not the model set with \a setModel()
72 *
73 * \see GraphicsView::setModel
74 */
75 QAbstractItemModel* model() const;
76
77 /*! \returns the KGantt::SummaryHandlingProxyModel used by this view.
78 */
79 QAbstractProxyModel* summaryHandlingModel() const;
80
81 /*! \returns the KGantt::ConstraintModel displayed by this view.
82 */
83 ConstraintModel* constraintModel() const;
84
85 /*! \returns the rootindex for this view.
86 */
87 QModelIndex rootIndex() const;
88
89 /*! \returns the QItemSelectionModel used by this view
90 */
91 QItemSelectionModel* selectionModel() const;
92
93
94 /*! \returns the AbstractRowController
95 * for this view. \see setRowController
96 */
97 AbstractRowController* rowController() const;
98
99 /*! \returns the AbstractGrid used by this view.
100 */
101 AbstractGrid* grid() const;
102
103 /*! \returns the AbstractGrid used by this view.
104 */
105 AbstractGrid* takeGrid();
106
107 /*! \returns the ItemDelegate used by this view to render items
108 */
109 ItemDelegate* itemDelegate() const;
110
111 /*!\returns true if the view is in read-only mode
112 */
113 bool isReadOnly() const;
114
115 /*! Sets the context menu policy for the header. The default value
116 * Qt::DefaultContextMenu results in a standard context menu on the header
117 * that allows the user to set the scale and zoom.
118 *
119 * Setting this to Qt::CustomContextMenu will cause the signal
120 * headerContextMenuRequested(const QPoint& pt) to be emitted instead.
121 *
122 * \see QWidget::setContextMenuPolicy( Qt::ContextMenuPolicy )
123 */
124 void setHeaderContextMenuPolicy( Qt::ContextMenuPolicy );
125
126 /*! \returns the context menu policy for the header
127 */
128 Qt::ContextMenuPolicy headerContextMenuPolicy() const;
129
130 /*!\returns The QModelIndex for the item located at
131 * position \a pos in the view or an invalid index
132 * if no item was present at that position.
133 *
134 * This is useful for for example contextmenus.
135 */
136 QModelIndex indexAt( const QPoint& pos ) const;
137
138 /*! Adds a constraint from \a from to \a to. \a modifiers are the
139 * keyboard modifiers pressed by the user when the action is invoked.
140 *
141 * Override this to control how constraints are added. The default
142 * implementation adds a soft constraint unless the Shift key is pressed,
143 * in that case it adds a hard constraint. If a constraint is already
144 * present, it is removed and nothing is added.
145 */
146 virtual void addConstraint( const QModelIndex& from,
147 const QModelIndex& to,
148 Qt::KeyboardModifiers modifiers );
149
150
151 /*! \internal */
152 void updateRow( const QModelIndex& );
153
154 /*! \internal
155 * Resets the state of the view.
156 */
157 void updateScene();
158
159#if 0
160 TODO: For 3.0
161
162
163 /*! Creates a new GraphicsItem
164 * Re-iplement to create your own flavour of GraphicsItem
165 */
166 virtual GraphicsItem* createItem( ItemType type ) const;
167#endif
168
169 public Q_SLOTS:
170 /*! \internal
171 * Adjusts the bounding rectangle of the scene.
172 */
173 void updateSceneRect();
174
175 public:
176 /*! \internal */
177 void deleteSubtree( const QModelIndex& );
178
179 /*! Print the Gantt chart using \a printer. If \a drawRowLabels
180 * is true (the default), each row will have it's label printed
181 * on the left side. If \a drawColumnLabels is true (the
182 * default), each column will have it's label printed at the
183 * top side.
184 *
185 * This version of print() will print multiple pages.
186 */
187 void print( QPrinter* printer, bool drawRowLabels = true, bool drawColumnLabels = true );
188
189 /*! Print part of the Gantt chart from \a start to \a end using \a printer.
190 * If \a drawRowLabels is true (the default), each row will have it's
191 * label printed on the left side. If \a drawColumnLabels is true (the
192 * default), each column will have it's label printed at the
193 * top side.
194 *
195 * This version of print() will print multiple pages.
196 *
197 * To print a certain range of a chart with a DateTimeGrid, use
198 * qreal DateTimeGrid::mapFromDateTime( const QDateTime& dt) const
199 * to figure out the values for \a start and \a end.
200 */
201 void print( QPrinter* printer, qreal start, qreal end, bool drawRowLabels = true, bool drawColumnLabels = true );
202
203 /*! Render the GanttView inside the rectangle \a target using the painter \a painter.
204 * If \a drawRowLabels is true (the default), each row will have it's
205 * label printed on the left side. If \a drawColumnLabels is true (the
206 * default), each column will have it's label printed at the
207 * top side.
208 */
209 void print( QPainter* painter, const QRectF& target = QRectF(), bool drawRowLabels = true, bool drawColumnLabels = true );
210
211 /*! Render the GanttView inside the rectangle \a target using the painter \a painter.
212 * If \a drawRowLabels is true (the default), each row will have it's
213 * label printed on the left side. If \a drawColumnLabels is true (the
214 * default), each column will have it's label printed at the
215 * top side.
216 *
217 * To print a certain range of a chart with a DateTimeGrid, use
218 * qreal DateTimeGrid::mapFromDateTime( const QDateTime& dt) const
219 * to figure out the values for \a start and \a end.
220 */
221 void print( QPainter* painter, qreal start, qreal end,
222 const QRectF& target = QRectF(), bool drawRowLabels = true, bool drawColumnLabels = true );
223
224 /*! Print the Gantt chart on the \a printer in accordance with the PrintingContext \a context
225 *
226 * \see PrintingContext
227 *
228 * \since 2.8.0
229 */
230 void printDiagram( QPrinter *printer, const PrintingContext &context );
231
232 public Q_SLOTS:
233 /*! Sets the model to be displayed in this view to
234 * \a model. The view does not take ownership of the model.
235 *
236 * To make a model work well with GraphicsView it must
237 * have a certain layout. Whether the model is flat or has a
238 * treestrucure is not important, as long as an
239 * AbstractRowController is provided that can navigate the
240 * model.
241 *
242 * GraphicsView operates per row in the model. The data is always
243 * taken from the _last_ item in the row. The ItemRoles used are
244 * Qt::DisplayRole and the roles defined in KGantt::ItemDataRole.
245 *
246 * Note: This model is not returned by \a model()
247 *
248 * \see GraphicsView::model
249 */
250 void setModel( QAbstractItemModel* );
251 void setSummaryHandlingModel( QAbstractProxyModel* model );
252
253 /*! Sets the constraintmodel displayed by this view.
254 * \see KGantt::ConstraintModel.
255 */
256 void setConstraintModel( KGantt::ConstraintModel* );
257
258 /*! Sets the root index of the model displayed by this view.
259 * Similar to QAbstractItemView::setRootIndex, default is QModelIndex().
260 */
261 void setRootIndex( const QModelIndex& );
262
263 /*! Sets the QItemSelectionModel used by this view to manage
264 * selections. Similar to QAbstractItemView::setSelectionModel
265 */
266 void setSelectionModel( QItemSelectionModel* );
267
268 /*! Sets the AbstractRowController used by this view. The
269 * AbstractRowController deals with the height and position
270 * of each row and with which parts of the model are
271 * displayed. \see AbstractRowController
272 */
273 void setRowController( KGantt::AbstractRowController* );
274
275 /*! Sets the AbstractGrid for this view. The grid is an
276 * object that controls how QModelIndexes are mapped
277 * to and from the view and how the background and header
278 * is rendered. \see AbstractGrid and DateTimeGrid.
279 */
280 void setGrid( KGantt::AbstractGrid* );
281
282 /*! Sets the KGantt::ItemDelegate used for rendering items on this
283 * view. \see ItemDelegate and QAbstractItemDelegate.
284 */
285 void setItemDelegate( KGantt::ItemDelegate* delegate );
286
287 /*! Sets the view to read-only mode if \a to is true. The default is
288 * read/write if the model permits it.
289 */
290 void setReadOnly( bool );
291
292 Q_SIGNALS:
293 /*! \fn void GraphicsView::activated( const QModelIndex & index ) */
294 void activated( const QModelIndex & index );
295
296 /*! \fn void GraphicsView::clicked( const QModelIndex & index ); */
297 void clicked( const QModelIndex & index );
298
299 /*! \fn void GraphicsView::qrealClicked( const QModelIndex & index ); */
300 void qrealClicked( const QModelIndex & index );
301
302 /*! \fn void GraphicsView::entered( const QModelIndex & index ); */
303 void entered( const QModelIndex & index );
304
305 /*! \fn void GraphicsView::pressed( const QModelIndex & index ); */
306 void pressed( const QModelIndex & index );
307
308 /*! \fn void GraphicsView::headerContextMenuRequested( const QPoint& pt )
309 * This signal is emitted when the header has contextMenuPolicy Qt::CustomContextMenu
310 * and the widget wants to show a context menu for the header. Unlike in
311 * QWidget::customContextMenuRequested() signal, \a pt is here in global coordinates.
312 */
314
315 protected:
316 /*! \internal */
317 void clearItems();
318 /*reimp*/void resizeEvent( QResizeEvent* ) override;
319 private:
320 friend class View;
321 };
322}
323
324#endif /* KGANTTGRAPHICSVIEW_H */
325
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 ...
The GraphicsView class provides a model/view implementation of a gantt chart.
void headerContextMenuRequested(const QPoint &pt)
Class used to render gantt items in a KGantt::GraphicsView.
The PrintingContext class provides options for printing the gantt chart.
This widget that consists of a QTreeView and a GraphicsView.
Definition kganttview.h:44
Q_SCRIPTABLE Q_NOREPLY void start()
Contains KGantt macros.
Global namespace.
T qobject_cast(QObject *object)
ContextMenuPolicy
typedef KeyboardModifiers
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:14:21 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.