12#include "kdganttview_p.h"
18#include <QAbstractItemModel>
19#include <QGraphicsItem>
20#include <QGraphicsRectItem>
31#include "../evaldialog/evaldialog.h"
40 explicit HeaderView(
QWidget *parent =
nullptr)
56 , m_controller(this, proxy)
58 setHeader(
new HeaderView);
61KDGanttTreeView::~KDGanttTreeView()
67 for (
int i = 0; i < model()->rowCount(index); i++) {
69 if (model()->hasChildren(indexAt))
71 if (isExpanded(indexAt))
79 for (
int i = 0; i < model()->rowCount(index); i++) {
81 if (model()->hasChildren(indexAt))
83 if (!isExpanded(indexAt))
89View::Private::Private(
View *v)
92 , rowController(nullptr)
99View::Private::~Private()
104void View::Private::init()
106 auto *tw =
new KDGanttTreeView(&ganttProxyModel, &splitter);
111 q->setRowController(tw->rowController());
118 layout->setContentsMargins(0, 0, 0, 0);
119 layout->addWidget(&splitter);
120 q->setLayout(layout);
122 constraintProxy.setProxyModel(&ganttProxyModel);
123 constraintProxy.setDestinationModel(&mappedConstraintModel);
127void View::Private::setupGraphicsView()
129 gfxview->setParent(&splitter);
132 gfxview->setSelectionModel(leftWidget->selectionModel());
133 gfxview->setConstraintModel(&mappedConstraintModel);
134 q->setLeftView(leftWidget);
135 q->setRowController(rowController);
139void View::Private::updateScene()
141 gfxview->clearItems();
145 if (
auto *tw = qobject_cast<QTreeView *>(leftWidget)) {
146 QModelIndex idx = ganttProxyModel.mapFromSource(model->index(0, 0, leftWidget->rootIndex()));
148 gfxview->updateRow(idx);
149 }
while ((idx = tw->indexBelow(idx)) !=
QModelIndex() && gfxview->rowController()->isRowVisible(idx));
150 gfxview->updateSceneRect();
152 const QModelIndex rootidx = ganttProxyModel.mapFromSource(leftWidget->rootIndex());
153 for (
int r = 0; r < ganttProxyModel.rowCount(rootidx); ++r) {
154 gfxview->updateRow(ganttProxyModel.index(r, 0, rootidx));
159void View::Private::slotCollapsed(
const QModelIndex &_idx)
161 auto *tw = qobject_cast<QTreeView *>(leftWidget);
165 bool blocked = gfxview->blockSignals(
true);
169 const QModelIndex pidx = ganttProxyModel.mapFromSource(idx);
170 bool isMulti =
false;
171 for (
QModelIndex treewalkidx = pidx; treewalkidx.
isValid(); treewalkidx = treewalkidx.parent()) {
173 && !gfxview->rowController()->isRowExpanded(treewalkidx)) {
180 for (
int i = 0; i < model->
rowCount(idx); ++i) {
181 gfxview->deleteSubtree(ganttProxyModel.index(i, 0, pidx));
184 gfxview->updateRow(pidx);
187 while ((idx = tw->indexBelow(idx)) !=
QModelIndex() && gfxview->rowController()->isRowVisible(ganttProxyModel.mapFromSource(idx))) {
188 const QModelIndex proxyidx(ganttProxyModel.mapFromSource(idx));
189 gfxview->updateRow(proxyidx);
191 gfxview->blockSignals(blocked);
192 gfxview->updateSceneRect();
195void View::Private::slotExpanded(
const QModelIndex &_idx)
197 QModelIndex idx(ganttProxyModel.mapFromSource(_idx));
200 gfxview->updateRow(idx);
201 }
while ((idx = gfxview->rowController()->indexBelow(idx)) !=
QModelIndex()
202 && gfxview->rowController()->isRowVisible(idx));
203 gfxview->updateSceneRect();
206void View::Private::slotVerticalScrollValueChanged(
int val)
209 qDebug() <<
"View::Private::slotVerticalScrollValueChanged("<<val<<
")="
210 << val/gfxview->verticalScrollBar()->singleStep();
212 leftWidget->verticalScrollBar()->setValue(val / gfxview->verticalScrollBar()->singleStep());
215void View::Private::slotLeftWidgetVerticalRangeChanged(
int min,
int max)
218 gfxview->verticalScrollBar()->setRange(min, max);
219 gfxview->updateSceneRect();
222void View::Private::slotGfxViewVerticalRangeChanged(
int min,
int max)
225 if (!leftWidget.isNull() && !gfxview.isNull()) {
226 int leftMin = leftWidget->verticalScrollBar()->minimum();
227 int leftMax = leftWidget->verticalScrollBar()->maximum();
228 bool blocked = gfxview->verticalScrollBar()->blockSignals(
true);
229 gfxview->verticalScrollBar()->setRange(qMax(min, leftMin), qMax(max, leftMax));
230 gfxview->verticalScrollBar()->blockSignals(blocked);
249 , _d(new Private(this))
252 EvalDialog::checkEvalLicense(
"KD Gantt");
272 if (
aiv ==
d->leftWidget)
274 if (!
d->leftWidget.isNull()) {
275 d->leftWidget->disconnect(
this);
276 d->leftWidget->hide();
277 d->leftWidget->verticalScrollBar()->disconnect(
d->gfxview->verticalScrollBar());
278 d->gfxview->verticalScrollBar()->disconnect(
d->leftWidget->verticalScrollBar());
282 d->splitter.insertWidget(0,
d->leftWidget);
291 connect(
d->gfxview->verticalScrollBar(),
SIGNAL(valueChanged(
int)),
292 d->leftWidget->verticalScrollBar(),
SLOT(setValue(
int)));
293 connect(
d->leftWidget->verticalScrollBar(),
SIGNAL(valueChanged(
int)),
294 d->gfxview->verticalScrollBar(),
SLOT(setValue(
int)));
295 connect(
d->leftWidget->verticalScrollBar(),
SIGNAL(rangeChanged(
int,
int)),
297 connect(
d->gfxview->verticalScrollBar(),
SIGNAL(rangeChanged(
int,
int)),
308 if (
ctrl ==
d->rowController &&
d->gfxview->rowController() ==
ctrl)
310 d->rowController =
ctrl;
311 d->gfxview->setRowController(
d->rowController);
319 return d->rowController;
326 return d->rowController;
335 return d->leftWidget;
343 return d->leftWidget;
354 if (
gv !=
d->gfxview) {
357 d->setupGraphicsView();
410 d->ganttProxyModel.setSourceModel(
model);
411 d->gfxview->setModel(&
d->ganttProxyModel);
437 d->gfxview->setGrid(
grid);
443 tw->expandAll(index);
449 tw->collapseAll(index);
456 return d->gfxview->grid();
472 d->gfxview->setRootIndex(
idx);
479 return d->gfxview->itemDelegate();
496 d->constraintProxy.setSourceModel(
cm);
497 d->gfxview->setConstraintModel(&
d->mappedConstraintModel);
504 return d->constraintProxy.sourceModel();
509 return &(
d->ganttProxyModel);
514 return &(
d->ganttProxyModel);
545 return d->gfxview->indexAt(
pos);
586 d->gfxview->print(painter,
604 d->gfxview->print(painter,
611#include "moc_kdganttview.cpp"
615#ifndef KDAB_NO_UNIT_TESTS
616#include "unittest/test.h"
619#include <QApplication>
Abstract baseclass for grids.
Abstract baseclass for row controllers.
The ConstraintModel keeps track of the interdependencies between gantt items in a View.
The GraphicsView class provides a model/view implementation of a gantt chart.
void print(QPrinter *printer, bool drawRowLabels=true, bool drawColumnLabels=true)
Print the Gantt chart using printer.
void setGrid(AbstractGrid *)
Sets the AbstractGrid for this view.
Class used to render gantt items in a KDGantt::GraphicsView.
Proxy model that supports summary gantt items.
This widget that consists of a QTreeView and a GraphicsView.
void ensureVisible(const QModelIndex &index)
void expandAll(QModelIndex index=QModelIndex())
QModelIndex indexAt(const QPoint &pos) const
View(QWidget *parent=nullptr)
Constructor.
void setLeftView(QAbstractItemView *)
Replaces the left widget with a custom QAbstractItemView.
void setConstraintModel(ConstraintModel *)
Sets the constraintmodel displayed by this view.
void setGrid(AbstractGrid *)
Sets the AbstractGrid for this view.
void setRootIndex(const QModelIndex &idx)
Sets the root index of the model displayed by this view.
void setItemDelegate(ItemDelegate *)
Sets the KDGantt::ItemDelegate used for rendering items on this view.
void setRowController(AbstractRowController *)
Sets ctrl to be the rowcontroller used by this View.
void setSelectionModel(QItemSelectionModel *smodel)
Sets the QItemSelectionModel used by this view to manage selections.
void setGraphicsView(GraphicsView *)
Set the GraphicsView to be used for this View.
const QSplitter * splitter() const
void setModel(QAbstractItemModel *model)
Sets the QAbstractItemModel to be displayed in this view to model.
QItemSelectionModel * selectionModel() const
const QAbstractProxyModel * ganttProxyModel() const
const QAbstractItemView * leftView() const
ItemDelegate * itemDelegate() const
ConstraintModel * constraintModel() const
const GraphicsView * graphicsView() const
AbstractRowController * rowController()
void resizeEvent(QResizeEvent *) override
void print(QPrinter *printer, bool drawRowLabels=true, bool drawColumnLabels=true)
Print the Gantt chart using printer.
AbstractGrid * grid() const
QAbstractItemModel * model() const
QModelIndex rootIndex() const
void collapseAll(QModelIndex index=QModelIndex())
KDAB_SCOPED_UNITTEST_SIMPLE(KDGantt, Constraint, "test")
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 QRectF &rect, int xmargin, int ymargin)
QGraphicsScene * scene() const const
bool isValid() const const
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
T qobject_cast(QObject *object)
QImage toImage() const const