File indexing completed on 2024-05-12 15:54:29
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 KGANTTVIEW_H 0021 #define KGANTTVIEW_H 0022 0023 #include <QWidget> 0024 #include <QModelIndex> 0025 #include "kganttglobal.h" 0026 #include "kganttprintingcontext.h" 0027 0028 QT_BEGIN_NAMESPACE 0029 class QAbstractItemModel; 0030 class QAbstractProxyModel; 0031 class QAbstractItemView; 0032 class QItemSelectionModel; 0033 class QPrinter; 0034 class QSplitter; 0035 QT_END_NAMESPACE 0036 0037 namespace KGantt { 0038 class ItemDelegate; 0039 class Constraint; 0040 class ConstraintModel; 0041 class AbstractGrid; 0042 class GraphicsView; 0043 class AbstractRowController; 0044 0045 0046 /*!\class KGantt::View kganttview.h KGanttView 0047 * \ingroup KGantt 0048 * \brief This widget that consists of a QTreeView and a GraphicsView 0049 * 0050 * This is the easy to use, complete gantt chart widget. It 0051 * consists of a QTreeView on the left and a KGantt::GraphicsView 0052 * on the right separated by a QSplitter. The two views share the same 0053 * model. 0054 */ 0055 class KGANTT_EXPORT View : public QWidget { 0056 Q_OBJECT 0057 KGANTT_DECLARE_PRIVATE_BASE_POLYMORPHIC_QWIDGET(View) 0058 Q_PRIVATE_SLOT( d, void slotCollapsed(const QModelIndex&) ) 0059 Q_PRIVATE_SLOT( d, void slotExpanded(const QModelIndex&) ) 0060 Q_PRIVATE_SLOT( d, void slotVerticalScrollValueChanged( int ) ) 0061 Q_PRIVATE_SLOT( d, void slotLeftWidgetVerticalRangeChanged( int, int ) ) 0062 Q_PRIVATE_SLOT( d, void slotGfxViewVerticalRangeChanged( int, int ) ) 0063 0064 public: 0065 /*! Constructor. Creates a View with parent \a parent, 0066 * a DateTimeGrid as default grid implementaion and no model etc. 0067 */ 0068 explicit View(QWidget* parent = nullptr); 0069 virtual ~View(); 0070 0071 /*! \returns the current model displayed by this view 0072 */ 0073 QAbstractItemModel* model() const; 0074 0075 /*! \returns the QItemSelectionModel used by this view 0076 */ 0077 QItemSelectionModel* selectionModel() const; 0078 0079 /*! \returns the ItemDelegate used by this view to render items 0080 */ 0081 ItemDelegate* itemDelegate() const; 0082 0083 /*! \returns the KGantt::ConstraintModel displayed by this view. 0084 */ 0085 ConstraintModel* constraintModel() const; 0086 0087 /*! \returns the AbstractGrid used by this view. 0088 */ 0089 AbstractGrid* grid() const; 0090 0091 /*! \returns the rootindex for this view. 0092 */ 0093 QModelIndex rootIndex() const; 0094 0095 /*!\returns The QModelIndex for the item located at 0096 * position \a pos in the view or an invalid index 0097 * if no item was present at that position. 0098 * 0099 * \see GraphicsView::indexAt 0100 */ 0101 QModelIndex indexAt( const QPoint& pos ) const; 0102 0103 0104 0105 /*! Replaces the left widget with a custom QAbstractItemView. 0106 * 0107 * \param aiv The view to be used to the left, instead of the default tree view 0108 * \sa setRowController() 0109 */ 0110 void setLeftView( QAbstractItemView* ); 0111 0112 /*! 0113 * \returns a pointer to the QAbstractItemView in the left 0114 * part of the widget. 0115 * */ 0116 const QAbstractItemView* leftView() const; 0117 0118 /*! 0119 * \overload const QAbstractItemView* KGantt::View::leftView() const 0120 */ 0121 QAbstractItemView* leftView(); 0122 0123 0124 0125 /*! 0126 * \overload const QSplitter* KGantt::View::splitter() const 0127 */ 0128 const QSplitter* splitter() const; 0129 /*! 0130 * \returns a pointer to the QSplitter that manages the left view and graphicsView 0131 */ 0132 QSplitter* splitter(); 0133 0134 /*! Sets \a ctrl to be the rowcontroller used by this View. 0135 * The default rowcontroller is owned by KGantt::View and is 0136 * suitable for the default treeview in the left part of the view. 0137 * You probably only want to change this if you replace the treeview. 0138 */ 0139 void setRowController( AbstractRowController* ); 0140 0141 0142 /*! \returns a pointer to the current rowcontroller. 0143 * \see AbstractRowController 0144 */ 0145 AbstractRowController* rowController(); 0146 /*! \overload AbstractRowController* KGantt::View::rowController() 0147 */ 0148 const AbstractRowController* rowController() const; 0149 0150 /*! Set the GraphicsView to be used for this View. It only makes sense to call this 0151 * if you need to subclass GraphicsView. 0152 * 0153 * NOTE: _Only_ call this right after creating the View, before setting a model or any other 0154 * attributes. 0155 */ 0156 void setGraphicsView( GraphicsView* ); 0157 0158 /*! 0159 * \overload const GraphicsView* KGantt::View::graphicsView() const 0160 */ 0161 const GraphicsView* graphicsView() const; 0162 0163 /*! 0164 * \returns a pointer to the GraphicsView 0165 */ 0166 GraphicsView* graphicsView(); 0167 const QAbstractProxyModel* ganttProxyModel() const; 0168 QAbstractProxyModel* ganttProxyModel(); 0169 0170 void ensureVisible(const QModelIndex& index); 0171 0172 /*! Print the Gantt chart using \a printer. If \a drawRowLabels 0173 * is true (the default), each row will have it's label printed 0174 * on the left side. If \a drawColumnLabels is true (the 0175 * default), each column will have it's label printed at the 0176 * top side. 0177 * 0178 * This version of print() will print multiple pages. 0179 */ 0180 void print( QPrinter* printer, bool drawRowLabels=true, bool drawColumnLabels=true ); 0181 0182 /*! Print part of the Gantt chart from \a start to \a end using \a printer. 0183 * If \a drawRowLabels is true (the default), each row will have it's 0184 * label printed on the left side. If \a drawColumnLabels is true (the 0185 * default), each column will have it's label printed at the 0186 * top side. 0187 * 0188 * This version of print() will print multiple pages. 0189 * 0190 * To print a certain range of a chart with a DateTimeGrid, use 0191 * qreal DateTimeGrid::mapFromDateTime( const QDateTime& dt) const 0192 * to figure out the values for \a start and \a end. 0193 */ 0194 void print( QPrinter* printer, qreal start, qreal end, bool drawRowLabels=true, bool drawColumnLabels=true ); 0195 0196 /*! Render the GanttView inside the rectangle \a target using the painter \a painter. 0197 * If \a drawRowLabels is true (the default), each row will have it's 0198 * label printed on the left side. If \a drawColumnLabels is true (the 0199 * default), each column will have it's label printed at the 0200 * top side. 0201 */ 0202 void print( QPainter* painter, const QRectF& target = QRectF(), bool drawRowLabels=true, bool drawColumnLabels=true); 0203 0204 /*! Render the GanttView inside the rectangle \a target using the painter \a painter. 0205 * If \a drawRowLabels is true (the default), each row will have it's 0206 * label printed on the left side. If \a drawColumnLabels is true (the 0207 * default), each column will have it's label printed at the 0208 * top side. 0209 * 0210 * To print a certain range of a chart with a DateTimeGrid, use 0211 * qreal DateTimeGrid::mapFromDateTime( const QDateTime& dt) const 0212 * to figure out the values for \a start and \a end. 0213 */ 0214 void print( QPainter* painter, qreal start, qreal end, 0215 const QRectF& target = QRectF(), bool drawRowLabels=true, bool drawColumnLabels=true); 0216 0217 /*! Print the Gantt chart on the \a printer in accordance with the PrintingContext \a context 0218 * 0219 * \see PrintingContext 0220 * 0221 * \since 2.8.0 0222 */ 0223 void printDiagram( QPrinter *printer, const PrintingContext &context = PrintingContext() ); 0224 0225 public Q_SLOTS: 0226 /*! Sets the QAbstractItemModel to be displayed in this view 0227 * to \a model. 0228 * 0229 * \see GraphicsView::setModel 0230 */ 0231 void setModel(QAbstractItemModel* model); 0232 0233 /*! Sets the root index of the model displayed by this view. 0234 * Similar to QAbstractItemView::setRootIndex, default is QModelIndex(). 0235 */ 0236 void setRootIndex( const QModelIndex& idx ); 0237 0238 /*! Sets the QItemSelectionModel used by this view to manage 0239 * selections. Similar to QAbstractItemView::setSelectionModel 0240 */ 0241 void setSelectionModel( QItemSelectionModel* smodel ); 0242 0243 /*! Sets the KGantt::ItemDelegate used for rendering items on this 0244 * view. \see ItemDelegate and QAbstractItemDelegate. 0245 */ 0246 void setItemDelegate( ItemDelegate* ); 0247 0248 /*! Sets the constraintmodel displayed by this view. 0249 * \see KGantt::ConstraintModel. 0250 */ 0251 void setConstraintModel( ConstraintModel* ); 0252 0253 /*! Sets the AbstractGrid for this view. The grid is an 0254 * object that controls how QModelIndexes are mapped 0255 * to and from the view and how the background and header 0256 * is rendered. \see AbstractGrid and DateTimeGrid. 0257 */ 0258 void setGrid( AbstractGrid* ); 0259 void expandAll( QModelIndex index = QModelIndex() ); 0260 void collapseAll( QModelIndex index = QModelIndex() ); 0261 0262 protected: 0263 /*reimp*/ void resizeEvent(QResizeEvent*) override; 0264 }; 0265 } 0266 0267 #endif /* KGANTTVIEW_H */