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
19using namespace KGantt;
20
21
22ConstraintGraphicsItem::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
33ConstraintGraphicsItem::~ConstraintGraphicsItem()
34{
35}
36
37int ConstraintGraphicsItem::type() const
38{
39 return Type;
40}
41
42GraphicsScene* ConstraintGraphicsItem::scene() const
43{
44 return qobject_cast<GraphicsScene*>( QGraphicsItem::scene() );
45}
46
47Constraint 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
54QRectF ConstraintGraphicsItem::boundingRect() const
55{
56 return scene()->itemDelegate()->constraintBoundingRect( m_start, m_end, m_constraint );
57}
58
59void 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
73QString ConstraintGraphicsItem::ganttToolTip() const
74{
75 return m_constraint.data( Qt::ToolTipRole ).toString();
76}
77
78void ConstraintGraphicsItem::setStart( const QPointF& start )
79{
81 m_start = start;
82 update();
83}
84
85void ConstraintGraphicsItem::setEnd( const QPointF& end )
86{
88 m_end = end;
89 update();
90}
91
92void ConstraintGraphicsItem::updateItem( const QPointF& start,const QPointF& end )
93{
94 setStart( start );
95 setEnd( end );
96}
A class used to represent a dependency.
QVariant data(int role) const
QModelIndex endIndex() const
RelationType relationType() const
QModelIndex startIndex() const
QMap< int, QVariant > dataMap() const
virtual void paintConstraintItem(QPainter *p, const QStyleOptionGraphicsItem &opt, const QPointF &start, const QPointF &end, const Constraint &constraint)
virtual QRectF constraintBoundingRect(const QPointF &start, const QPointF &end, const Constraint &constraint) const
Q_SCRIPTABLE QString start(QString train="")
Q_SCRIPTABLE Q_NOREPLY void start()
Global namespace.
const QList< QKeySequence > & end()
void prepareGeometryChange()
QGraphicsScene * scene() const const
void update(const QRectF &rect)
void addItem(QGraphicsItem *item)
QPalette palette()
ToolTipRole
NoButton
QString toString() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:02:52 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.