31 #include <QAbstractItemModel>
32 #include <QHeaderView>
33 #include <QVBoxLayout>
34 #include <QGraphicsItem>
35 #include <QGraphicsRectItem>
37 #include <QPaintEvent>
44 #include "../evaldialog/evaldialog.h"
47 using namespace KDGantt;
50 class HeaderView :
public QHeaderView {
52 explicit HeaderView(
QWidget* parent=0 ) : QHeaderView( Qt::Horizontal, parent ) {
55 QSize sizeHint()
const { QSize s = QHeaderView::sizeHint(); s.rheight() *= 2;
return s; }
61 m_controller( this, proxy )
63 setHeader(
new HeaderView );
87 tw->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
88 tw->setVerticalScrollMode( QAbstractItemView::ScrollPerPixel );
93 gfxview.setAlignment(Qt::AlignTop|Qt::AlignLeft);
96 tw->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
97 gfxview.setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
99 QVBoxLayout* layout =
new QVBoxLayout(q);
100 layout->setMargin(0);
102 q->setLayout(layout);
105 constraintProxy.setDestinationModel( &mappedConstraintModel );
106 gfxview.setSelectionModel( leftWidget->selectionModel() );
107 gfxview.setConstraintModel( &mappedConstraintModel );
112 gfxview.clearItems();
115 if(
QTreeView* tw = qobject_cast<QTreeView*>(leftWidget)) {
116 QModelIndex idx =
ganttProxyModel.mapFromSource(
model->index( 0, 0, leftWidget->rootIndex() ) );
118 gfxview.updateRow( idx );
119 }
while ( ( idx = tw->indexBelow( idx ) ) != QModelIndex() &&
120 gfxview.rowController()->isRowVisible(idx) );
121 gfxview.updateSceneRect();
123 const QModelIndex rootidx =
ganttProxyModel.mapFromSource( leftWidget->rootIndex() );
135 bool blocked = gfxview.blockSignals(
true );
137 QModelIndex idx( _idx );
138 const QAbstractItemModel*
model = leftWidget->model();
140 bool isMulti =
false;
141 for( QModelIndex treewalkidx = pidx; treewalkidx.isValid(); treewalkidx = treewalkidx.parent() ) {
143 && !gfxview.rowController()->isRowExpanded( treewalkidx ) ) {
150 for (
int i = 0; i < model->rowCount( idx ); ++i ) {
154 gfxview.updateRow(pidx);
157 while ( ( idx=tw->indexBelow( idx ) ) != QModelIndex() &&
158 gfxview.rowController()->isRowVisible(
ganttProxyModel.mapFromSource(idx) ) ) {
160 gfxview.updateRow(proxyidx);
162 gfxview.blockSignals( blocked );
163 gfxview.updateSceneRect();
171 gfxview.updateRow(idx);
172 }
while( ( idx=gfxview.rowController()->indexBelow( idx ) ) != QModelIndex()
173 && gfxview.rowController()->isRowVisible( idx ) );
174 gfxview.updateSceneRect();
180 qDebug() <<
"View::Private::slotVerticalScrollValueChanged("<<val<<
")="
181 << val/gfxview.verticalScrollBar()->singleStep();
183 leftWidget->verticalScrollBar()->setValue( val/gfxview.verticalScrollBar()->singleStep() );
189 gfxview.verticalScrollBar()->setRange( min, max );
190 gfxview.updateSceneRect();
196 int leftMin = leftWidget->verticalScrollBar()->minimum();
197 int leftMax = leftWidget->verticalScrollBar()->maximum();
198 bool blocked = gfxview.verticalScrollBar()->blockSignals(
true );
199 gfxview.verticalScrollBar()->setRange( qMax( min, leftMin ), qMax( max, leftMax ) );
200 gfxview.verticalScrollBar()->blockSignals( blocked );
220 #if defined KDAB_EVAL
221 EvalDialog::checkEvalLicense(
"KD Gantt" );
241 if ( aiv==
d->leftWidget )
return;
242 if ( !
d->leftWidget.isNull() ) {
243 d->leftWidget->disconnect(
this );
244 d->leftWidget->hide();
245 d->leftWidget->verticalScrollBar()->disconnect(
d->gfxview.verticalScrollBar() );
246 d->gfxview.verticalScrollBar()->disconnect(
d->leftWidget->verticalScrollBar() );
250 d->splitter.insertWidget( 0,
d->leftWidget );
252 if( qobject_cast<QTreeView*>(
d->leftWidget) ) {
253 connect(
d->leftWidget, SIGNAL(collapsed(QModelIndex)),
254 this, SLOT(slotCollapsed(QModelIndex)) );
255 connect(
d->leftWidget, SIGNAL(expanded(QModelIndex)),
256 this, SLOT(slotExpanded(QModelIndex)) );
259 connect(
d->gfxview.verticalScrollBar(), SIGNAL(valueChanged(
int)),
260 d->leftWidget->verticalScrollBar(), SLOT(setValue(
int)) );
261 connect(
d->leftWidget->verticalScrollBar(), SIGNAL(valueChanged(
int)),
262 d->gfxview.verticalScrollBar(), SLOT(setValue(
int)) );
263 connect(
d->leftWidget->verticalScrollBar(), SIGNAL(rangeChanged(
int,
int)),
264 this, SLOT(slotLeftWidgetVerticalRangeChanged(
int,
int)) );
265 connect(
d->gfxview.verticalScrollBar(), SIGNAL(rangeChanged(
int,
int)),
266 this, SLOT(slotGfxViewVerticalRangeChanged(
int,
int)) );
276 if ( ctrl ==
d->rowController )
return;
277 d->rowController = ctrl;
278 d->gfxview.setRowController(
d->rowController );
286 return d->rowController;
293 return d->rowController;
302 return d->leftWidget;
310 return d->leftWidget;
361 d->ganttProxyModel.setSourceModel( model );
362 d->gfxview.setModel( &
d->ganttProxyModel );
369 return leftView()->selectionModel();
377 leftView()->setSelectionModel( smodel );
378 d->gfxview.setSelectionModel(
new QItemSelectionModel( &(
d->ganttProxyModel ),
this ) );
388 d->gfxview.setGrid( grid );
395 return d->gfxview.grid();
411 d->gfxview.setRootIndex( idx );
418 return d->gfxview.itemDelegate();
426 leftView()->setItemDelegate( delegate );
427 d->gfxview.setItemDelegate( delegate );
435 d->constraintProxy.setSourceModel( cm );
436 d->gfxview.setConstraintModel( &
d->mappedConstraintModel );
443 return d->constraintProxy.sourceModel();
448 return &(
d->ganttProxyModel );
453 return &(
d->ganttProxyModel );
458 QWidget::resizeEvent(ev);
469 return d->gfxview.indexAt( pos );
493 void View::print( QPrinter* printer, qreal start, qreal end,
bool drawRowLabels )
502 void View::print( QPainter* painter,
const QRectF& target,
bool drawRowLabels)
504 d->gfxview.print( painter,
517 void View::print( QPainter* painter, qreal start, qreal end,
const QRectF& target,
bool drawRowLabels)
519 d->gfxview.print( painter,
526 #include "moc_kdganttview.cpp"
528 #ifndef KDAB_NO_UNIT_TESTS
529 #include "unittest/test.h"
532 #include <QApplication>
538 std::ostream&
operator<<( std::ostream& os,
const QImage& img )
540 os <<
"QImage[ size=("<<img.width()<<
", "<<img.height()<<
")]";
547 #if 0 // GUI tests do not work well on the server
548 QTimer::singleShot( 1000, qApp, SLOT(quit()) );
552 QPixmap screenshot1 = QPixmap::grabWidget( &view );
558 QTimer::singleShot( 1000, qApp, SLOT(quit()) );
561 QPixmap screenshot2 = QPixmap::grabWidget( &view );
563 assertEqual( screenshot1.toImage(), screenshot2.toImage() );
569 QTimer::singleShot( 1000, qApp, SLOT(quit()) );
void setSelectionModel(QItemSelectionModel *smodel)
QAbstractItemModel * model() const
QItemSelectionModel * selectionModel() const
QModelIndex rootIndex() const
void print(QPrinter *printer, bool drawRowLabels=true)
Class used to render gantt items in a KDGantt::GraphicsView.
void setLeftView(QAbstractItemView *)
This widget that consists of a QTreeView and a GraphicsView.
The GraphicsView class provides a model/view implementation of a gantt chart.
void print(QPrinter *printer, bool drawRowLabels=true)
void setGrid(AbstractGrid *)
QDebug operator<<(QDebug dbg, const Constraint &c)
const QAbstractItemView * leftView() const
AbstractGrid * grid() const
ConstraintModel * constraintModel() const
void setRootIndex(const QModelIndex &idx)
Abstract baseclass for grids. A grid is used to convert between QModelIndex'es and gantt chart values...
const GraphicsView * graphicsView() const
void slotVerticalScrollValueChanged(int)
void setModel(QAbstractItemModel *model)
void setRowController(AbstractRowController *)
void setItemDelegate(ItemDelegate *)
QModelIndex indexAt(const QPoint &pos) const
void slotGfxViewVerticalRangeChanged(int, int)
KDGanttTreeView(QAbstractProxyModel *proxy, QWidget *parent=0)
KDAB_SCOPED_UNITTEST_SIMPLE(KDGantt, View,"test")
void slotLeftWidgetVerticalRangeChanged(int, int)
virtual ~KDGanttTreeView()
AbstractRowController * rowController()
void resizeEvent(QResizeEvent *)
void slotCollapsed(const QModelIndex &)
Abstract baseclass for row controllers. A row controller is used by the GraphicsView to nagivate the ...
const QSplitter * splitter() const
void setConstraintModel(ConstraintModel *)
const QAbstractProxyModel * ganttProxyModel() const
void slotExpanded(const QModelIndex &)
ItemDelegate * itemDelegate() const
AbstractRowController * rowController()