10#include "kganttview_p.h"
12#include "kganttitemdelegate.h"
13#include "kganttgraphicsitem.h"
14#include "kganttsummaryhandlingproxymodel.h"
16#include <QAbstractItemModel>
19#include <QGraphicsItem>
20#include <QGraphicsRectItem>
29#include "../evaldialog/evaldialog.h"
46 m_controller( this, proxy )
48 setHeader(
new HeaderView );
51KGanttTreeView::~KGanttTreeView()
57 for (
int i = 0; i < model()->rowCount(index); i++) {
59 if (model()->hasChildren(indexAt))
61 if (isExpanded(indexAt))
69 for (
int i = 0; i < model()->rowCount(index); i++) {
71 if (model()->hasChildren(indexAt))
73 if (!isExpanded(indexAt))
79View::Private::Private(
View* v)
82 rowController(nullptr),
89View::Private::~Private()
94void View::Private::init()
96 KGanttTreeView* tw =
new KGanttTreeView( &ganttProxyModel, &splitter );
100 q->setLeftView( tw );
101 q->setRowController( tw->rowController() );
110 q->setLayout(layout);
112 constraintProxy.setProxyModel( &ganttProxyModel );
113 constraintProxy.setDestinationModel( &mappedConstraintModel );
117void View::Private::setupGraphicsView()
119 gfxview->setParent( &splitter );
122 gfxview->setSelectionModel( leftWidget->selectionModel() );
123 gfxview->setConstraintModel( &mappedConstraintModel );
124 q->setLeftView( leftWidget );
125 q->setRowController( rowController );
129void View::Private::updateScene()
131 gfxview->clearItems();
134 if (
QTreeView* tw = qobject_cast<QTreeView*>(leftWidget)) {
135 QModelIndex idx = ganttProxyModel.mapFromSource( model->index( 0, 0, leftWidget->rootIndex() ) );
137 gfxview->updateRow( idx );
138 }
while ( ( idx = tw->indexBelow( idx ) ) !=
QModelIndex() &&
139 gfxview->rowController()->isRowVisible(idx) );
140 gfxview->updateSceneRect();
142 const QModelIndex rootidx = ganttProxyModel.mapFromSource( leftWidget->rootIndex() );
143 for (
int r = 0; r < ganttProxyModel.rowCount(rootidx); ++r ) {
144 gfxview->updateRow( ganttProxyModel.index( r, 0, rootidx ) );
149void View::Private::slotCollapsed(
const QModelIndex& _idx)
151 QTreeView* tw = qobject_cast<QTreeView*>(leftWidget);
154 bool blocked = gfxview->blockSignals(
true );
158 const QModelIndex pidx = ganttProxyModel.mapFromSource(idx);
159 bool isMulti =
false;
160 for (
QModelIndex treewalkidx = pidx; treewalkidx.
isValid(); treewalkidx = treewalkidx.parent() ) {
161 if ( treewalkidx.data(
ItemTypeRole ).toInt() == TypeMulti
162 && !gfxview->rowController()->isRowExpanded( treewalkidx ) ) {
169 for (
int i = 0; i < model->
rowCount( idx ); ++i ) {
170 gfxview->deleteSubtree( ganttProxyModel.index( i, 0, pidx ) );
173 gfxview->updateRow(pidx);
177 gfxview->rowController()->isRowVisible( ganttProxyModel.mapFromSource(idx) ) ) {
178 const QModelIndex proxyidx( ganttProxyModel.mapFromSource( idx ) );
179 gfxview->updateRow(proxyidx);
181 gfxview->blockSignals( blocked );
182 gfxview->updateSceneRect();
185void View::Private::slotExpanded(
const QModelIndex& _idx)
187 QModelIndex idx( ganttProxyModel.mapFromSource( _idx ) );
190 gfxview->updateRow(idx);
191 }
while ( ( idx=gfxview->rowController()->indexBelow( idx ) ) !=
QModelIndex()
192 && gfxview->rowController()->isRowVisible( idx ) );
193 gfxview->updateSceneRect();
196void View::Private::slotVerticalScrollValueChanged(
int val )
199 qDebug() <<
"View::Private::slotVerticalScrollValueChanged("<<val<<
")="
200 << val/gfxview->verticalScrollBar()->singleStep();
202 leftWidget->verticalScrollBar()->setValue( val/gfxview->verticalScrollBar()->singleStep() );
205void View::Private::slotLeftWidgetVerticalRangeChanged(
int min,
int max )
209 if (!gfxview.isNull()) {
210 gfxview->verticalScrollBar()->setRange( min, max );
211 gfxview->updateSceneRect();
215void View::Private::slotGfxViewVerticalRangeChanged(
int min,
int max )
218 if ( !leftWidget.isNull() && !gfxview.isNull() ) {
219 int leftMin = leftWidget->verticalScrollBar()->minimum();
220 int leftMax = leftWidget->verticalScrollBar()->maximum();
221 bool blocked = gfxview->verticalScrollBar()->blockSignals(
true );
222 gfxview->verticalScrollBar()->setRange( qMax( min, leftMin ), qMax( max, leftMax ) );
223 gfxview->verticalScrollBar()->blockSignals( blocked );
232 _d(new Private(this))
235 EvalDialog::checkEvalLicense(
"KD Gantt" );
251 if ( aiv==d->leftWidget )
return;
252 if ( !d->leftWidget.isNull() ) {
253 d->leftWidget->disconnect(
this );
254 d->leftWidget->hide();
255 d->leftWidget->verticalScrollBar()->disconnect( d->gfxview->verticalScrollBar() );
256 d->gfxview->verticalScrollBar()->disconnect( d->leftWidget->verticalScrollBar() );
260 d->splitter.insertWidget( 0, d->leftWidget );
269 connect( d->gfxview->verticalScrollBar(), SIGNAL(valueChanged(
int)),
270 d->leftWidget->verticalScrollBar(), SLOT(setValue(
int)) );
271 connect( d->leftWidget->verticalScrollBar(), SIGNAL(valueChanged(
int)),
272 d->gfxview->verticalScrollBar(), SLOT(setValue(
int)) );
273 connect( d->leftWidget->verticalScrollBar(), SIGNAL(rangeChanged(
int,
int)),
274 this, SLOT(slotLeftWidgetVerticalRangeChanged(
int,
int)) );
275 connect( d->gfxview->verticalScrollBar(), SIGNAL(rangeChanged(
int,
int)),
276 this, SLOT(slotGfxViewVerticalRangeChanged(
int,
int)) );
282 if ( ctrl == d->rowController && d->gfxview->rowController() == ctrl )
return;
283 d->rowController = ctrl;
284 d->gfxview->setRowController( d->rowController );
290 return d->rowController;
296 return d->rowController;
302 return d->leftWidget;
308 return d->leftWidget;
314 if ( gv != d->gfxview ) {
318 d->gfxview->setModel(old->
model());
319 d->setupGraphicsView();
320 d->gfxview->setGrid(
grid );
360 d->ganttProxyModel.setSourceModel(
model );
361 d->gfxview->setModel( &d->ganttProxyModel );
380 d->gfxview->setGrid(
grid );
390 tw->expandAll(index);
401 tw->collapseAll(index);
408 return d->gfxview->grid();
421 d->gfxview->setRootIndex( idx );
427 return d->gfxview->itemDelegate();
434 d->gfxview->setItemDelegate( delegate );
440 d->constraintProxy.setSourceModel( cm );
441 d->gfxview->setConstraintModel( &d->mappedConstraintModel );
447 return d->constraintProxy.sourceModel();
452 return &( d->ganttProxyModel );
457 return &( d->ganttProxyModel );
469 const QModelIndex pidx = d->ganttProxyModel.mapFromSource(index);
483 return d->gfxview->indexAt(
pos );
501 d->gfxview->print( painter,
510 d->gfxview->print( painter,
522#include "moc_kganttview.cpp"
524#ifndef KDAB_NO_UNIT_TESTS
525#include "unittest/test.h"
527#include "kganttlistviewrowcontroller.h"
528#include <QApplication>
533KDAB_SCOPED_UNITTEST_SIMPLE(
KGantt,
View,
"test" ) {
534 View view(
nullptr );
540 QPixmap screenshot1 = QPixmap::grabWidget( &view );
543 view.setLeftView( tv );
549 QPixmap screenshot2 = QPixmap::grabWidget( &view );
554 view.setLeftView(lv);
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.
QAbstractItemModel * model() const
void print(QPrinter *printer, bool drawRowLabels=true, bool drawColumnLabels=true)
void printDiagram(QPrinter *printer, const PrintingContext &context)
AbstractGrid * takeGrid()
Class used to render gantt items in a KGantt::GraphicsView.
The PrintingContext class provides options for printing the gantt chart.
Proxy model that supports summary gantt items.
This widget that consists of a QTreeView and a GraphicsView.
void setItemDelegate(KGantt::ItemDelegate *)
QModelIndex indexAt(const QPoint &pos) const
void setLeftView(QAbstractItemView *)
const GraphicsView * graphicsView() const
void setRootIndex(const QModelIndex &idx)
void setRowController(AbstractRowController *)
void setSelectionModel(QItemSelectionModel *smodel)
void setGraphicsView(GraphicsView *)
void setModel(QAbstractItemModel *model)
QItemSelectionModel * selectionModel() const
const QAbstractItemView * leftView() const
ItemDelegate * itemDelegate() const
ConstraintModel * constraintModel() const
void printDiagram(QPrinter *printer, const PrintingContext &context=PrintingContext())
void print(QPrinter *printer, bool drawRowLabels=true, bool drawColumnLabels=true)
void setGrid(KGantt::AbstractGrid *)
AbstractGrid * grid() const
QAbstractItemModel * model() const
AbstractRowController * rowController()
const QSplitter * splitter() const
void setConstraintModel(KGantt::ConstraintModel *)
QModelIndex rootIndex() const
Q_SCRIPTABLE Q_NOREPLY void start()
@ ItemTypeRole
The item type.
virtual int rowCount(const QModelIndex &parent) const const=0
QAbstractItemModel * model() const const
QModelIndex rootIndex() const const
QItemSelectionModel * selectionModel() const const
void setItemDelegate(QAbstractItemDelegate *delegate)
virtual void setModel(QAbstractItemModel *model)
virtual void setRootIndex(const QModelIndex &index)
virtual void setSelectionModel(QItemSelectionModel *selectionModel)
void ensureVisible(const QGraphicsItem *item, int xmargin, int ymargin)
QGraphicsScene * scene() const const
void setContentsMargins(const QMargins &margins)
bool isValid() const const
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
T qobject_cast(QObject *object)
QImage toImage() const const
QModelIndex indexBelow(const QModelIndex &index) const const