KGantt

kganttview.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 KGANTTVIEW_H
10#define KGANTTVIEW_H
11
12#include <QWidget>
13#include <QModelIndex>
14#include "kganttglobal.h"
15#include "kganttprintingcontext.h"
16
17QT_BEGIN_NAMESPACE
22class QPrinter;
23class QSplitter;
25
26namespace KGantt {
27 class ItemDelegate;
28 class Constraint;
29 class ConstraintModel;
30 class AbstractGrid;
31 class GraphicsView;
32 class AbstractRowController;
33
34
35 /*!\class KGantt::View kganttview.h KGanttView
36 * \ingroup KGantt
37 * \brief This widget that consists of a QTreeView and a GraphicsView
38 *
39 * This is the easy to use, complete gantt chart widget. It
40 * consists of a QTreeView on the left and a KGantt::GraphicsView
41 * on the right separated by a QSplitter. The two views share the same
42 * model.
43 */
44 class KGANTT_EXPORT View : public QWidget {
45 Q_OBJECT
46 KGANTT_DECLARE_PRIVATE_BASE_POLYMORPHIC_QWIDGET(View)
47 Q_PRIVATE_SLOT( d, void slotCollapsed(const QModelIndex&) )
48 Q_PRIVATE_SLOT( d, void slotExpanded(const QModelIndex&) )
49 Q_PRIVATE_SLOT( d, void slotVerticalScrollValueChanged( int ) )
50 Q_PRIVATE_SLOT( d, void slotLeftWidgetVerticalRangeChanged( int, int ) )
51 Q_PRIVATE_SLOT( d, void slotGfxViewVerticalRangeChanged( int, int ) )
52
53 public:
54 /*! Constructor. Creates a View with parent \a parent,
55 * a DateTimeGrid as default grid implementation and no model etc.
56 */
57 explicit View(QWidget* parent = nullptr);
58 ~View() override;
59
60 /*! \returns the current model displayed by this view
61 */
62 QAbstractItemModel* model() const;
63
64 /*! \returns the QItemSelectionModel used by this view
65 */
66 QItemSelectionModel* selectionModel() const;
67
68 /*! \returns the ItemDelegate used by this view to render items
69 */
70 ItemDelegate* itemDelegate() const;
71
72 /*! \returns the KGantt::ConstraintModel displayed by this view.
73 */
74 ConstraintModel* constraintModel() const;
75
76 /*! \returns the AbstractGrid used by this view.
77 */
78 AbstractGrid* grid() const;
79
80 /*! \returns the rootindex for this view.
81 */
82 QModelIndex rootIndex() const;
83
84 /*!\returns The QModelIndex for the item located at
85 * position \a pos in the view or an invalid index
86 * if no item was present at that position.
87 *
88 * \see GraphicsView::indexAt
89 */
90 QModelIndex indexAt( const QPoint& pos ) const;
91
92
93
94 /*! Replaces the left widget with a custom QAbstractItemView.
95 *
96 * \param aiv The view to be used to the left, instead of the default tree view
97 * \sa setRowController()
98 */
99 void setLeftView( QAbstractItemView* );
100
101 /*!
102 * \returns a pointer to the QAbstractItemView in the left
103 * part of the widget.
104 * */
105 const QAbstractItemView* leftView() const;
106
107 /*!
108 * \overload const QAbstractItemView* KGantt::View::leftView() const
109 */
110 QAbstractItemView* leftView();
111
112
113
114 /*!
115 * \overload const QSplitter* KGantt::View::splitter() const
116 */
117 const QSplitter* splitter() const;
118 /*!
119 * \returns a pointer to the QSplitter that manages the left view and graphicsView
120 */
121 QSplitter* splitter();
122
123 /*! Sets \a ctrl to be the rowcontroller used by this View.
124 * The default rowcontroller is owned by KGantt::View and is
125 * suitable for the default treeview in the left part of the view.
126 * You probably only want to change this if you replace the treeview.
127 */
128 void setRowController( AbstractRowController* );
129
130
131 /*! \returns a pointer to the current rowcontroller.
132 * \see AbstractRowController
133 */
134 AbstractRowController* rowController();
135 /*! \overload AbstractRowController* KGantt::View::rowController()
136 */
137 const AbstractRowController* rowController() const;
138
139 /*! Set the GraphicsView to be used for this View. It only makes sense to call this
140 * if you need to subclass GraphicsView.
141 *
142 * NOTE: _Only_ call this right after creating the View, before setting a model or any other
143 * attributes.
144 */
145 void setGraphicsView( GraphicsView* );
146
147 /*!
148 * \overload const GraphicsView* KGantt::View::graphicsView() const
149 */
150 const GraphicsView* graphicsView() const;
151
152 /*!
153 * \returns a pointer to the GraphicsView
154 */
155 GraphicsView* graphicsView();
156 const QAbstractProxyModel* ganttProxyModel() const;
157 QAbstractProxyModel* ganttProxyModel();
158
159 void ensureVisible(const QModelIndex& index);
160
161 /*! Print the Gantt chart using \a printer. If \a drawRowLabels
162 * is true (the default), each row will have it's label printed
163 * on the left side. If \a drawColumnLabels is true (the
164 * default), each column will have it's label printed at the
165 * top side.
166 *
167 * This version of print() will print multiple pages.
168 */
169 void print( QPrinter* printer, bool drawRowLabels=true, bool drawColumnLabels=true );
170
171 /*! Print part of the Gantt chart from \a start to \a end using \a printer.
172 * If \a drawRowLabels is true (the default), each row will have it's
173 * label printed on the left side. If \a drawColumnLabels is true (the
174 * default), each column will have it's label printed at the
175 * top side.
176 *
177 * This version of print() will print multiple pages.
178 *
179 * To print a certain range of a chart with a DateTimeGrid, use
180 * qreal DateTimeGrid::mapFromDateTime( const QDateTime& dt) const
181 * to figure out the values for \a start and \a end.
182 */
183 void print( QPrinter* printer, qreal start, qreal end, bool drawRowLabels=true, bool drawColumnLabels=true );
184
185 /*! Render the GanttView inside the rectangle \a target using the painter \a painter.
186 * If \a drawRowLabels is true (the default), each row will have it's
187 * label printed on the left side. If \a drawColumnLabels is true (the
188 * default), each column will have it's label printed at the
189 * top side.
190 */
191 void print( QPainter* painter, const QRectF& target = QRectF(), bool drawRowLabels=true, bool drawColumnLabels=true);
192
193 /*! Render the GanttView inside the rectangle \a target using the painter \a painter.
194 * If \a drawRowLabels is true (the default), each row will have it's
195 * label printed on the left side. If \a drawColumnLabels is true (the
196 * default), each column will have it's label printed at the
197 * top side.
198 *
199 * To print a certain range of a chart with a DateTimeGrid, use
200 * qreal DateTimeGrid::mapFromDateTime( const QDateTime& dt) const
201 * to figure out the values for \a start and \a end.
202 */
203 void print( QPainter* painter, qreal start, qreal end,
204 const QRectF& target = QRectF(), bool drawRowLabels=true, bool drawColumnLabels=true);
205
206 /*! Print the Gantt chart on the \a printer in accordance with the PrintingContext \a context
207 *
208 * \see PrintingContext
209 *
210 * \since 2.8.0
211 */
212 void printDiagram( QPrinter *printer, const PrintingContext &context = PrintingContext() );
213
214 public Q_SLOTS:
215 /*! Sets the QAbstractItemModel to be displayed in this view
216 * to \a model.
217 *
218 * \see GraphicsView::setModel
219 */
220 void setModel(QAbstractItemModel* model);
221
222 /*! Sets the root index of the model displayed by this view.
223 * Similar to QAbstractItemView::setRootIndex, default is QModelIndex().
224 */
225 void setRootIndex( const QModelIndex& idx );
226
227 /*! Sets the QItemSelectionModel used by this view to manage
228 * selections. Similar to QAbstractItemView::setSelectionModel
229 */
230 void setSelectionModel( QItemSelectionModel* smodel );
231
232 /*! Sets the KGantt::ItemDelegate used for rendering items on this
233 * view. \see ItemDelegate and QAbstractItemDelegate.
234 */
235 void setItemDelegate( KGantt::ItemDelegate* );
236
237 /*! Sets the constraintmodel displayed by this view.
238 * \see KGantt::ConstraintModel.
239 */
240 void setConstraintModel( KGantt::ConstraintModel* );
241
242 /*! Sets the AbstractGrid for this view. The grid is an
243 * object that controls how QModelIndexes are mapped
244 * to and from the view and how the background and header
245 * is rendered. \see AbstractGrid and DateTimeGrid.
246 */
247 void setGrid( KGantt::AbstractGrid* );
248 void expandAll( QModelIndex index = QModelIndex() );
249 void collapseAll( QModelIndex index = QModelIndex() );
250
251 protected:
252 /*reimp*/ void resizeEvent(QResizeEvent*) override;
253 };
254}
255
256#endif /* KGANTTVIEW_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 ...
The GraphicsView class provides a model/view implementation of a gantt chart.
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)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Jun 14 2024 11:59:32 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.