9#include "kganttgraphicsscene.h"
10#include "kganttgraphicsscene_p.h"
11#include "kganttgraphicsitem.h"
12#include "kganttconstraint.h"
13#include "kganttconstraintgraphicsitem.h"
14#include "kganttitemdelegate.h"
15#include "kganttabstractrowcontroller.h"
16#include "kganttabstractgrid.h"
17#include "kganttdatetimegrid.h"
18#include "kganttsummaryhandlingproxymodel.h"
19#include "kganttgraphicsview.h"
20#include "kganttprintingcontext.h"
22#include <QApplication>
23#include <QGraphicsSceneHelpEvent>
26#include <QTextDocument>
51 dragSource( nullptr ),
53 rowController( nullptr ),
56 drawColumnLabels( true ),
59 selectionModel( nullptr )
64GraphicsScene::Private::~Private()
69void GraphicsScene::Private::clearConstraintItems()
74 item->removeStartConstraint(citem);
75 item->removeEndConstraint(citem);
80 constraintItems.clear();
83void GraphicsScene::Private::resetConstraintItems()
85 clearConstraintItems();
86 if ( constraintModel.isNull() )
return;
89 createConstraintItem( c );
94void GraphicsScene::Private::createConstraintItem(
const Constraint& c )
99 if ( sitem && eitem ) {
101 sitem->addStartConstraint( citem );
102 eitem->addEndConstraint( citem );
103 constraintItems.append( citem );
114 if ( citem ==
nullptr ) {
120 item->removeStartConstraint( citem );
122 item = items.value( summaryHandlingModel->mapFromSource( c.
endIndex() ),
nullptr );
124 item->removeEndConstraint( citem );
126 constraintItems.removeAt(constraintItems.indexOf(citem));
130void GraphicsScene::Private::deleteConstraintItem(
const Constraint& c )
132 deleteConstraintItem( findConstraintItem( c ) );
141 for ( ; it != clst.
end() ; ++it ) {
142 if ( c.compareIndexes((*it)->constraint()) )
145 if ( it != clst.
end() ) {
149 item = items.value( summaryHandlingModel->mapFromSource( c.
endIndex() ),
nullptr );
153 for ( ; it != clst.
end() ; ++it ) {
154 if ( c.compareIndexes( (*it)->constraint() ) )
157 if ( it != clst.
end() ) {
165void GraphicsScene::Private::clearItems()
173 clearConstraintItems();
184const AbstractGrid *GraphicsScene::Private::getGrid()
const
192GraphicsScene::GraphicsScene(
QObject* parent )
198GraphicsScene::~GraphicsScene()
200 qDeleteAll(
items() );
206void GraphicsScene::init()
209 setConstraintModel(
new ConstraintModel(
this ) );
210 connect( d->getGrid(), SIGNAL(gridChanged()),
this, SLOT(slotGridChanged()) );
217void GraphicsScene::setItemDelegate(
ItemDelegate* delegate )
219 if ( !d->itemDelegate.isNull() && d->itemDelegate->parent()==
this )
delete d->itemDelegate;
220 d->itemDelegate = delegate;
226 return d->itemDelegate;
229QAbstractItemModel* GraphicsScene::model()
const
231 assert(!d->summaryHandlingModel.isNull());
232 return d->summaryHandlingModel->sourceModel();
235void GraphicsScene::setModel( QAbstractItemModel* model )
237 assert(!d->summaryHandlingModel.isNull());
238 d->summaryHandlingModel->setSourceModel(model);
239 d->getGrid()->setModel( d->summaryHandlingModel );
240 setSelectionModel(
new QItemSelectionModel( model,
this ) );
243QAbstractProxyModel* GraphicsScene::summaryHandlingModel()
const
245 return d->summaryHandlingModel;
248void GraphicsScene::setSummaryHandlingModel( QAbstractProxyModel* proxyModel )
251 d->summaryHandlingModel = proxyModel;
254void GraphicsScene::setRootIndex(
const QModelIndex& idx )
256 d->getGrid()->setRootIndex( idx );
259QModelIndex GraphicsScene::rootIndex()
const
261 return d->getGrid()->rootIndex();
266 return d->constraintModel;
271 if ( !d->constraintModel.isNull() ) {
272 d->constraintModel->disconnect(
this );
273 d->clearConstraintItems();
275 d->constraintModel = cm;
277 connect( cm, SIGNAL(constraintAdded(KGantt::Constraint)),
278 this, SLOT(slotConstraintAdded(KGantt::Constraint)) );
279 connect( cm, SIGNAL(constraintRemoved(KGantt::Constraint)),
280 this, SLOT(slotConstraintRemoved(KGantt::Constraint)) );
281 d->resetConstraintItems();
284void GraphicsScene::setSelectionModel( QItemSelectionModel* smodel )
286 if (d->selectionModel) {
287 d->selectionModel->disconnect(
this );
289 d->selectionModel = smodel;
291 connect(d->selectionModel, SIGNAL(modelChanged(QAbstractItemModel*)),
292 this, SLOT(selectionModelChanged(QAbstractItemModel*)));
294 this, SLOT(slotSelectionChanged(QItemSelection,QItemSelection)) );
298QItemSelectionModel* GraphicsScene::selectionModel()
const
300 return d->selectionModel;
305 d->rowController = rc;
310 return d->rowController;
316 grid->disconnect(
this );
320 connect( &d->default_grid, SIGNAL(gridChanged()),
this, SLOT(slotGridChanged()) );
328 if ( d->getGrid() ) {
329 d->getGrid()->disconnect(
this );
330 model = d->getGrid()->model();
334 connect( d->getGrid(), SIGNAL(gridChanged()),
this, SLOT(slotGridChanged()) );
335 d->getGrid()->setModel( model );
351void GraphicsScene::setReadOnly(
bool ro )
356bool GraphicsScene::isReadOnly()
const
366QModelIndex GraphicsScene::mainIndex(
const QModelIndex& idx )
372 return QModelIndex();
399 assert(
views().count() == 1);
402 return v->createItem(type);
409void GraphicsScene::Private::recursiveUpdateMultiItem(
const Span& span,
const QModelIndex& idx )
415 item = q->createItem(
static_cast<ItemType
>( itemtype ) );
416 item->setIndex( idx );
417 q->insertItem( idx, item);
419 item->updateItem( span, idx );
422 while ( ( child = summaryHandlingModel->index( cr, 0, idx ) ).isValid() ) {
423 recursiveUpdateMultiItem( span, child );
428void GraphicsScene::updateRow(
const QModelIndex& rowidx )
431 if ( !rowidx.
isValid() )
return;
433 const QAbstractItemModel* model = rowidx.
model();
436 assert( rowController() );
437 assert( model == summaryHandlingModel() );
439 const QModelIndex sidx = summaryHandlingModel()->mapToSource( rowidx );
440 Span rg = rowController()->rowGeometry( sidx );
441 for ( QModelIndex treewalkidx = sidx; treewalkidx.isValid(); treewalkidx = treewalkidx.parent() ) {
442 if ( treewalkidx.data(
ItemTypeRole ).toInt() == TypeMulti
443 && !rowController()->isRowExpanded( treewalkidx )) {
444 rg = rowController()->rowGeometry( treewalkidx );
449 for (
int col = 0; col < summaryHandlingModel()->columnCount( rowidx.
parent() ); ++col ) {
450 const QModelIndex idx = summaryHandlingModel()->index( rowidx.
row(), col, rowidx.
parent() );
451 const QModelIndex sidx = summaryHandlingModel()->mapToSource( idx );
452 const int itemtype = summaryHandlingModel()->data( idx,
ItemTypeRole ).toInt();
453 const bool isExpanded = rowController()->isRowExpanded( sidx );
454 if ( itemtype == TypeNone ) {
458 if ( itemtype == TypeMulti && !isExpanded ) {
459 d->recursiveUpdateMultiItem( rg, idx );
461 if ( summaryHandlingModel()->data( rowidx.
parent(),
ItemTypeRole ).toInt() == TypeMulti && !isExpanded ) {
465 GraphicsItem* item = findItem( idx );
468 item->setIndex( idx );
469 insertItem(idx, item);
471 const Span span = rowController()->rowGeometry( sidx );
472 item->updateItem( span, idx );
478void GraphicsScene::insertItem(
const QPersistentModelIndex& idx,
GraphicsItem* item )
480 if ( !d->constraintModel.isNull() ) {
482 const QModelIndex sidx = summaryHandlingModel()->mapToSource( idx );
483 const QList<Constraint> clst = d->constraintModel->constraintsForIndex( sidx );
484 for (
const Constraint& c : clst ) {
485 QModelIndex other_idx;
488 GraphicsItem* other_item = d->items.value(summaryHandlingModel()->mapFromSource( other_idx ),
nullptr);
489 if ( !other_item )
continue;
490 ConstraintGraphicsItem* citem =
new ConstraintGraphicsItem( c );
491 item->addStartConstraint( citem );
492 other_item->addEndConstraint( citem );
493 d->constraintItems.append( citem );
495 }
else if ( c.
endIndex() == sidx ) {
497 GraphicsItem* other_item = d->items.value(summaryHandlingModel()->mapFromSource( other_idx ),
nullptr);
498 if ( !other_item )
continue;
499 ConstraintGraphicsItem* citem =
new ConstraintGraphicsItem( c );
500 other_item->addStartConstraint( citem );
501 item->addEndConstraint( citem );
502 d->constraintItems.append( citem );
509 d->items.insert( idx, item );
513void GraphicsScene::removeItem(
const QModelIndex& idx )
516 QHash<QPersistentModelIndex,GraphicsItem*>::iterator it = d->items.find( idx );
517 if ( it != d->items.end() ) {
518 GraphicsItem* item = *it;
522 d->items.erase( it );
525 const QList<ConstraintGraphicsItem*> lst1 = item->startConstraints();
526 const QList<ConstraintGraphicsItem*> lst2 = item->endConstraints();
527 const QSet<ConstraintGraphicsItem*> clst = QSet<ConstraintGraphicsItem*>( lst1.
begin(), lst1.
end() ) +
528 QSet<ConstraintGraphicsItem*>( lst2.
begin(), lst2.
end() );
529 for ( ConstraintGraphicsItem* citem : clst ) {
530 d->deleteConstraintItem( citem );
538GraphicsItem* GraphicsScene::findItem(
const QModelIndex& idx )
const
540 if ( !idx.
isValid() )
return nullptr;
541 assert( idx.
model() == summaryHandlingModel() );
542 QHash<QPersistentModelIndex,GraphicsItem*>::const_iterator it = d->items.find( idx );
543 return ( it != d->items.end() )?*it:
nullptr;
546GraphicsItem* GraphicsScene::findItem(
const QPersistentModelIndex& idx )
const
548 if ( !idx.
isValid() )
return nullptr;
549 assert( idx.
model() == summaryHandlingModel() );
550 QHash<QPersistentModelIndex,GraphicsItem*>::const_iterator it = d->items.find( idx );
551 return ( it != d->items.end() )?*it:
nullptr;
554void GraphicsScene::clearItems()
559void GraphicsScene::updateItems()
561 for ( QHash<QPersistentModelIndex,GraphicsItem*>::iterator it = d->items.begin();
562 it != d->items.end(); ++it ) {
563 GraphicsItem*
const item = it.value();
564 const QPersistentModelIndex& idx = it.key();
565 item->updateItem( Span( item->
pos().
y(), item->rect().
height() ), idx );
570void GraphicsScene::deleteSubtree(
const QModelIndex& _idx )
573 if ( !idx.
model() )
return;
576 {
for (
int i = 0; i < colcount; ++i ) {
577 removeItem( summaryHandlingModel()->index(idx.
row(), i,
parent ) );
579 const int rowcount = summaryHandlingModel()->rowCount( _idx );
580 {
for (
int i = 0; i < rowcount; ++i ) {
581 deleteSubtree( summaryHandlingModel()->index( i, summaryHandlingModel()->columnCount(_idx)-1, _idx ) );
588 return d->findConstraintItem( c );
591void GraphicsScene::slotConstraintAdded(
const KGantt::Constraint& c )
593 d->createConstraintItem( c );
596void GraphicsScene::slotConstraintRemoved(
const KGantt::Constraint& c )
598 d->deleteConstraintItem( c );
601void GraphicsScene::slotGridChanged()
608void GraphicsScene::selectionModelChanged(QAbstractItemModel *model)
613void GraphicsScene::slotSelectionChanged(
const QItemSelection &selected,
const QItemSelection &deselected)
615 const auto desel = deselected.
indexes();
616 for (
const QModelIndex &idx : desel) {
617 GraphicsItem *item = findItem(idx.
model() == d->summaryHandlingModel ? idx : d->summaryHandlingModel->mapFromSource(idx));
622 const auto sel = selected.
indexes();
623 for (
const QModelIndex &idx : sel) {
624 GraphicsItem *item = findItem(idx.
model() == d->summaryHandlingModel ? idx : d->summaryHandlingModel->mapFromSource(idx));
632void GraphicsScene::helpEvent( QGraphicsSceneHelpEvent *helpEvent )
635 QGraphicsItem *item =
itemAt( helpEvent->scenePos(), QTransform() );
636 if ( GraphicsItem* gitem = qgraphicsitem_cast<GraphicsItem*>( item ) ) {
638 }
else if ( ConstraintGraphicsItem* citem = qgraphicsitem_cast<ConstraintGraphicsItem*>( item ) ) {
646void GraphicsScene::drawBackground( QPainter* painter,
const QRectF& _rect )
649 QRectF rect( _rect );
650 if ( d->isPrinting && d->drawColumnLabels ) {
651 QRectF headerRect( scn.topLeft()+QPointF( d->labelsWidth, 0 ),
652 QSizeF( scn.width()-d->labelsWidth, d->rowController->headerHeight() ));
654 d->getGrid()->paintHeader( painter, headerRect, rect, 0,
nullptr );
660 QRectF labelsTabRect( scn.topLeft(), QSizeF( d->labelsWidth, headerRect.height() ) );
662 QStyleOptionHeader opt;
663 opt.rect = labelsTabRect.toRect();
664 opt.text = QLatin1String(
"");
669 scn.setTop( headerRect.bottom() );
670 scn.setLeft( headerRect.left() );
671 rect = rect.intersected( scn );
673 d->getGrid()->paintGrid( painter, scn, rect, d->rowController );
675 d->getGrid()->drawBackground(painter, rect);
678void GraphicsScene::drawForeground( QPainter* painter,
const QRectF& rect )
680 d->getGrid()->drawForeground(painter, rect);
683void GraphicsScene::itemEntered(
const QModelIndex& idx )
688void GraphicsScene::itemPressed(
const QModelIndex& idx, QGraphicsSceneMouseEvent *event )
697 d->selectionModel->select(d->summaryHandlingModel->mapToSource(idx), flags);
702void GraphicsScene::itemClicked(
const QModelIndex& idx )
707void GraphicsScene::itemDoubleClicked(
const QModelIndex& idx )
709 Q_EMIT qrealClicked( idx );
714 d->dragSource = item;
719 return d->dragSource;
727 Q_UNUSED( drawRowLabels );
728 Q_UNUSED( drawColumnLabels );
731 const auto resolution = printer->
resolution();
733 doPrint( &painter, pageRect,
sceneRect().left(),
sceneRect().right(), printer, drawRowLabels, drawColumnLabels );
744 Q_UNUSED( drawRowLabels );
745 Q_UNUSED( drawColumnLabels );
748 const auto resolution = printer->
resolution();
750 doPrint( &painter, pageRect,
start, end, printer, drawRowLabels, drawColumnLabels );
757 QRectF targetRect( _targetRect );
758 if ( targetRect.
isNull() ) {
762 doPrint( painter, targetRect,
sceneRect().left(),
sceneRect().right(),
nullptr, drawRowLabels, drawColumnLabels );
767 const QRectF& _targetRect,
bool drawRowLabels,
bool drawColumnLabels )
769 QRectF targetRect( _targetRect );
770 if ( targetRect.
isNull() ) {
774 doPrint( painter, targetRect,
start, end,
nullptr, drawRowLabels, drawColumnLabels );
794 doPrintScene( printer, &painter, targetRect, ctx );
798void GraphicsScene::doPrint(
QPainter* painter,
const QRectF& targetRect,
799 qreal
start, qreal end,
800 QPrinter* printer,
bool drawRowLabels,
bool drawColumnLabels )
810 doPrintScene( printer, painter, targetRect, ctx );
819 d->isPrinting =
true;
821 d->labelsWidth = 0.0;
827 if (
font().pointSizeF() >= 0.0 )
828 sceneFont.setPointSizeF(
font().pointSizeF() );
829 else if (
font().pointSize() >= 0 )
830 sceneFont.setPointSize(
font().pointSize() );
832 sceneFont.setPixelSize(
font().pixelSize() );
836 QGraphicsTextItem dummyTextItem( QLatin1String(
"X") );
837 dummyTextItem.adjustSize();
838 QFontMetrics fm(dummyTextItem.font());
839 sceneFont.setPixelSize( fm.height() );
842 QRectF scnRect( oldScnRect );
843 QRectF sceneHeaderRect;
844 QRectF labelsHeaderRect;
848 qreal headerHeight = 0.0;
850 headerHeight = d->rowController->headerHeight();
853 sceneHeaderRect.
setTop( -headerHeight );
854 sceneHeaderRect.
setHeight( headerHeight );
855 scnRect.setTop(scnRect.top() - headerHeight);
859 QVector<QGraphicsTextItem*> textLabels;
861 qreal textWidth = 0.;
862 qreal charWidth = QFontMetricsF(sceneFont).boundingRect(
QString::fromLatin1(
"X" ) ).width();
863 QModelIndex sidx = summaryHandlingModel()->mapToSource( summaryHandlingModel()->index( 0, 0, rootIndex()) );
865 QModelIndex idx = summaryHandlingModel()->mapFromSource( sidx );
866 const Span rg=rowController()->rowGeometry( sidx );
868 QGraphicsTextItem* item =
new QGraphicsTextItem( txt );
871 item->
setTextWidth( QFontMetricsF(sceneFont).boundingRect( txt ).
width() + charWidth );
872 textWidth = qMax( item->
textWidth(), textWidth );
873 item->
setPos( 0, rg.start() );
874 }
while ( ( sidx = rowController()->indexBelow( sidx ) ).
isValid() );
875 d->labelsWidth = textWidth;
876 scnRect.setLeft( scnRect.left() - textWidth );
877 for( QGraphicsTextItem* item : std::as_const(textLabels) ) {
878 item->
setPos( scnRect.left(), item->
y() );
882 labelsHeaderRect = sceneHeaderRect;
883 labelsHeaderRect.
translate( -textWidth, 0.0 );
884 labelsHeaderRect.
setWidth( textWidth );
886 labelsRect = QRectF( scnRect.left(), context.
top(), textWidth, context.
sceneRect().
height() );
889 scnRect.setRight( context.
right() );
896 qreal sceneWidth = d->labelsWidth + context.
right() - context.
left();
902 qreal scaleFactor = targetRect.
height() / scnRect.height();
906 vertPages = qRound( ( sceneHeight * scaleFactor / targetRect.
height() ) + 0.5 );
907 horPages = qRound( ( sceneWidth * scaleFactor / targetRect.
width() ) + 0.5 );
909 scaleFactor = std::min( scaleFactor, targetRect.
width() / sceneWidth );
911 horPages = qRound( ( sceneWidth * scaleFactor / targetRect.
width() ) + 0.5 );
915 scaleFactor = std::min( scaleFactor, targetRect.
width() / sceneWidth );
922 qreal yPos = labelsRect.
top();
923 for (
int vpage = 0; vpage < vertPages && yPos < context.
bottom(); ++vpage ) {
934 qreal targetLabelsOffset = 0.0;
935 qreal labelsOffsetX = 0.0;
936 while ( labelsOffsetX < labelsHeaderRect.
width() ) {
939 QRectF target = targetRect;
940 target.
setWidth(std::min(target.
width(), (labelsHeaderRect.
width() - labelsOffsetX) * scaleFactor) );
941 if ( vpage == 0 && headerHeight > 0.0 ) {
942 QRectF sourceHeader = labelsHeaderRect;
943 sourceHeader.
translate( labelsOffsetX, 0.0 );
944 QRectF targetHeader = target;
945 targetHeader.
setSize( sourceHeader.
size() * scaleFactor );
946 drawLabelsHeader( painter, sourceHeader, targetHeader );
949 QRectF rect = labelsRect;
955 bool drawColumnLabels = d->drawColumnLabels;
956 d->drawColumnLabels =
false;
958 render( painter, target, rect );
959 d->drawColumnLabels = drawColumnLabels;
960 labelsOffsetX += rect.
width();
971 targetLabelsOffset = target.
width();
979 qreal xPos = context.
left();
981 for ( ; hpage < horPages && xPos < context.
right(); ++hpage ) {
983 QRectF target = targetRect.
adjusted(targetLabelsOffset, 0., 0., 0.);
984 targetLabelsOffset = 0.0;
985 if (!sceneHeaderRect.
isNull() && vpage == 0) {
987 QRectF rect = sceneHeaderRect;
989 QRectF targetHeader = target;
993 render( painter, targetHeader, rect );
1004 bool drawColumnLabels = d->drawColumnLabels;
1005 d->drawColumnLabels =
false;
1007 render( painter, target, rect );
1008 d->drawColumnLabels = drawColumnLabels;
1010 xPos += rect.
width();
1012 if ( printer && xPos < context.
right() ) {
1021 yPos += targetRect.
height() / scaleFactor;
1023 yPos -= headerHeight;
1026 if ( printer && yPos < context.
bottom() ) {
1035 d->isPrinting =
false;
1036 d->drawColumnLabels =
true;
1037 d->labelsWidth = 0.0;
1038 qDeleteAll( textLabels );
1044void GraphicsScene::drawLabelsHeader( QPainter *painter,
const QRectF &sourceRect,
const QRectF &targetRect )
1049 render( painter, targetRect, sourceRect );
1052#include "moc_kganttgraphicsscene.cpp"
1055#ifndef KDAB_NO_UNIT_TESTS
1056#include "unittest/test.h"
1058#include <QGraphicsLineItem>
1060#include <QStandardItemModel>
1062#include "kganttgraphicsview.h"
1064class SceneTestRowController :
public KGantt::AbstractRowController {
1066 static const int ROW_HEIGHT;
1067 QPointer<QAbstractItemModel> m_model;
1070 SceneTestRowController()
1074 void setModel( QAbstractItemModel* model )
1079 int headerHeight()
const override {
return 40; }
1081 bool isRowVisible(
const QModelIndex& )
const override {
return true;}
1082 bool isRowExpanded(
const QModelIndex& )
const override {
return false; }
1083 KGantt::Span rowGeometry(
const QModelIndex& idx )
const override
1085 return KGantt::Span( idx.
row() * ROW_HEIGHT, ROW_HEIGHT );
1087 int maximumItemHeight()
const override {
1088 return ROW_HEIGHT/2;
1090 int totalHeight()
const override {
1091 return m_model->rowCount()* ROW_HEIGHT;
1094 QModelIndex indexAt(
int height )
const override {
1095 return m_model->index( height/ROW_HEIGHT, 0 );
1098 QModelIndex indexBelow(
const QModelIndex& idx )
const override {
1099 if ( !idx.
isValid() )
return QModelIndex();
1102 QModelIndex indexAbove(
const QModelIndex& idx )
const override {
1103 if ( !idx.
isValid() )
return QModelIndex();
1109class TestLineItem :
public QGraphicsLineItem
1112 TestLineItem(
bool *destroyedFlag )
1113 : QGraphicsLineItem( 0, 0, 10, 10 ),
1114 m_destroyedFlag( destroyedFlag )
1117 ~TestLineItem()
override
1118 { *m_destroyedFlag =
true; }
1121 bool *m_destroyedFlag;
1124const int SceneTestRowController::ROW_HEIGHT = 30;
1126KDAB_SCOPED_UNITTEST_SIMPLE( KGantt,
GraphicsView,
"test" ) {
1127 QStandardItemModel model;
1129 QStandardItem* item =
new QStandardItem();
1135 QStandardItem* item2 =
new QStandardItem();
1144 SceneTestRowController rowController;
1145 rowController.setModel( &model );
1147 KGantt::GraphicsView graphicsView;
1153 bool foreignItemDestroyed =
false;
1154 TestLineItem *foreignItem =
new TestLineItem( &foreignItemDestroyed );
1157 assertFalse( foreignItemDestroyed );
1159 assertFalse( foreignItemDestroyed );
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 ...
A class used to represent a dependency.
QModelIndex endIndex() const
QModelIndex startIndex() const
QBrush noInformationBrush() const
void setNoInformationBrush(const QBrush &brush)
static QModelIndex dataIndex(const QModelIndex &idx)
void printDiagram(QPrinter *printer, const PrintingContext &context)
void setGrid(AbstractGrid *grid)
Set the grid to grid.
GraphicsItem * createItem(ItemType type) const
void print(QPrinter *printer, bool drawRowLabels=true, bool drawColumnLabels=true)
AbstractGrid * takeGrid()
AbstractGrid * grid() const
const AbstractGrid * getGrid() const
The GraphicsView class provides a model/view implementation of a gantt chart.
void setModel(QAbstractItemModel *)
void setRowController(KGantt::AbstractRowController *)
Class used to render gantt items in a KGantt::GraphicsView.
The PrintingContext class provides options for printing the gantt chart.
bool drawColumnLabels() const
bool drawRowLabels() const
void setDrawRowLabels(bool state)
void setSceneRect(const QRectF &rect)
void setRight(qreal right)
void setFitting(const Fitting &value)
@ FitSinglePage
Scale diagram to fit on a single page.
@ NoFitting
No scaling, print as many pages as needed.
@ FitPageHeight
Scale diagram height to fit one page.
void setDrawColumnLabels(bool state)
A class representing a start point and a length.
Proxy model that supports summary gantt items.
Q_SCRIPTABLE QString start(QString train="")
void init(KXmlGuiWindow *window, KGameDifficulty *difficulty=nullptr)
@ ItemTypeRole
The item type.
@ StartTimeRole
Start time (or other start value) for a gantt item.
@ EndTimeRole
End time (or other end value) for a gantt item.
bool isValid(QStringView ifopt)
virtual int columnCount(const QModelIndex &parent) const const=0
virtual QModelIndex index(int row, int column, const QModelIndex &parent) const const=0
virtual void setSourceModel(QAbstractItemModel *sourceModel)
QDateTime currentDateTime()
QVariant data(int key) const const
QPointF pos() const const
void setPos(const QPointF &pos)
void setSelected(bool selected)
void addItem(QGraphicsItem *item)
virtual void helpEvent(QGraphicsSceneHelpEvent *helpEvent)
void invalidate(const QRectF &rect, SceneLayers layers)
QGraphicsItem * itemAt(const QPointF &position, const QTransform &deviceTransform) const const
void setItemIndexMethod(ItemIndexMethod method)
QList< QGraphicsItem * > items(Qt::SortOrder order) const const
void render(QPainter *painter, const QRectF &target, const QRectF &source, Qt::AspectRatioMode aspectRatioMode)
QStyle * style() const const
void update(const QRectF &rect)
QList< QGraphicsView * > views() const const
qreal width() const const
void setTextWidth(qreal width)
qreal textWidth() const const
QGraphicsScene * scene() const const
QModelIndexList indexes() const const
QVariant data(int role) const const
bool isValid() const const
const QAbstractItemModel * model() const const
QModelIndex parent() const const
bool blockSignals(bool block)
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
virtual bool event(QEvent *e)
QObject * parent() const const
T qobject_cast(QObject *object)
QPageLayout pageLayout() const const
QMargins marginsPixels(int resolution) const const
QRect paintRectPixels(int resolution) const const
int logicalDpiX() const const
void setClipRect(const QRect &rectangle, Qt::ClipOperation operation)
void setFont(const QFont &font)
bool isValid() const const
const QAbstractItemModel * model() const const
bool fullPage() const const
virtual bool newPage() override
int resolution() const const
void adjust(qreal dx1, qreal dy1, qreal dx2, qreal dy2)
QRectF adjusted(qreal dx1, qreal dy1, qreal dx2, qreal dy2) const const
qreal height() const const
bool isNull() const const
QRectF marginsRemoved(const QMarginsF &margins) const const
qreal right() const const
void setHeight(qreal height)
void setSize(const QSizeF &size)
void setWidth(qreal width)
QSizeF size() const const
void translate(const QPointF &offset)
qreal width() const const
virtual void setData(const QVariant &value, int role)
void appendRow(QStandardItem *item)
QString fromLatin1(QByteArrayView str)
virtual void drawControl(ControlElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget) const const=0
void showText(const QPoint &pos, const QString &text, QWidget *w, const QRect &rect, int msecDisplayTime)
int toInt(bool *ok) const const
QString toString() const const