KGantt

kganttconstraintgraphicsitem.cpp
1 /*
2  * SPDX-FileCopyrightText: 2001-2015 Klaralvdalens Datakonsult AB. All rights reserved.
3  *
4  * This file is part of the KGantt library.
5  *
6  * SPDX-License-Identifier: GPL-2.0-or-later
7  */
8 
9 #include "kganttconstraintgraphicsitem.h"
10 #include "kganttconstraintmodel.h"
11 #include "kganttgraphicsscene.h"
12 #include "kganttitemdelegate.h"
13 #include "kganttsummaryhandlingproxymodel.h"
14 
15 #include <QPainter>
16 #include <QApplication>
17 #include <QDebug>
18 
19 using namespace KGantt;
20 
21 
22 ConstraintGraphicsItem::ConstraintGraphicsItem( const Constraint& c, QGraphicsItem* parent, GraphicsScene* scene )
23  : QGraphicsItem( parent ), m_constraint( c )
24 {
25  if ( scene )
26  scene->addItem( this );
27  setPos( QPointF( 0., 0. ) );
28  setAcceptHoverEvents( false );
29  setAcceptedMouseButtons( Qt::NoButton );
30  setZValue( 10. );
31 }
32 
33 ConstraintGraphicsItem::~ConstraintGraphicsItem()
34 {
35 }
36 
37 int ConstraintGraphicsItem::type() const
38 {
39  return Type;
40 }
41 
42 GraphicsScene* ConstraintGraphicsItem::scene() const
43 {
44  return qobject_cast<GraphicsScene*>( QGraphicsItem::scene() );
45 }
46 
47 Constraint ConstraintGraphicsItem::proxyConstraint() const
48 {
49  return Constraint( scene()->summaryHandlingModel()->mapFromSource( m_constraint.startIndex() ),
50  scene()->summaryHandlingModel()->mapFromSource( m_constraint.endIndex() ),
51  m_constraint.type(), m_constraint.relationType(), m_constraint.dataMap() );
52 }
53 
54 QRectF ConstraintGraphicsItem::boundingRect() const
55 {
56  return scene()->itemDelegate()->constraintBoundingRect( m_start, m_end, m_constraint );
57 }
58 
59 void ConstraintGraphicsItem::paint( QPainter* painter, const QStyleOptionGraphicsItem* option,
60  QWidget* widget )
61 {
62  Q_UNUSED( widget );
63  //qDebug() << "ConstraintGraphicsItem::paint(...), c=" << m_constraint;
64  QStyleOptionGraphicsItem opt = *option;
65  if (widget) {
66  opt.palette = widget->palette();
67  }else {
68  opt.palette = QApplication::palette();
69  }
70  scene()->itemDelegate()->paintConstraintItem( painter, opt, m_start, m_end, m_constraint );
71 }
72 
73 QString ConstraintGraphicsItem::ganttToolTip() const
74 {
75  return m_constraint.data( Qt::ToolTipRole ).toString();
76 }
77 
78 void ConstraintGraphicsItem::setStart( const QPointF& start )
79 {
80  prepareGeometryChange();
81  m_start = start;
82  update();
83 }
84 
85 void ConstraintGraphicsItem::setEnd( const QPointF& end )
86 {
87  prepareGeometryChange();
88  m_end = end;
89  update();
90 }
91 
92 void ConstraintGraphicsItem::updateItem( const QPointF& start,const QPointF& end )
93 {
94  setStart( start );
95  setEnd( end );
96 }
virtual void paintConstraintItem(QPainter *p, const QStyleOptionGraphicsItem &opt, const QPointF &start, const QPointF &end, const Constraint &constraint)
NoButton
QGraphicsScene * scene() const const
A class used to represent a dependency.
QPalette palette()
virtual QRectF constraintBoundingRect(const QPointF &start, const QPointF &end, const Constraint &constraint) const
ToolTipRole
Global namespace.
void update(Part *part, const QByteArray &data, qint64 dataSize)
virtual QModelIndex mapFromSource(const QModelIndex &sourceIndex) const const =0
void addItem(QGraphicsItem *item)
QChar * data()
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Sun Dec 5 2021 22:32:42 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.