KD Chart 2  [rev.2.5.1]
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Macros Pages
kdganttconstraintgraphicsitem.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 ** Copyright (C) 2001-2013 Klaralvdalens Datakonsult AB. All rights reserved.
3 **
4 ** This file is part of the KD Chart library.
5 **
6 ** Licensees holding valid commercial KD Chart licenses may use this file in
7 ** accordance with the KD Chart Commercial License Agreement provided with
8 ** the Software.
9 **
10 **
11 ** This file may be distributed and/or modified under the terms of the
12 ** GNU General Public License version 2 and version 3 as published by the
13 ** Free Software Foundation and appearing in the file LICENSE.GPL.txt included.
14 **
15 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
16 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
17 **
18 ** Contact info@kdab.com if any conditions of this licensing are not
19 ** clear to you.
20 **
21 **********************************************************************/
22 
24 #include "kdganttconstraintmodel.h"
25 #include "kdganttgraphicsscene.h"
26 #include "kdganttitemdelegate.h"
28 
29 #include <QPainter>
30 #include <QDebug>
31 
32 using namespace KDGantt;
33 
37 #if QT_VERSION < 0x050000
39  : QGraphicsItem( parent, scene ), m_constraint( c )
40 {
41  setPos( QPointF( 0., 0. ) );
42  setAcceptsHoverEvents( false );
43  setAcceptedMouseButtons( Qt::NoButton );
44  setZValue( 10. );
45 }
46 #else
48  : QGraphicsItem( parent ), m_constraint( c )
49 {
50  if ( scene )
51  scene->addItem( this );
52  setPos( QPointF( 0., 0. ) );
53  setAcceptHoverEvents( false );
54  setAcceptedMouseButtons( Qt::NoButton );
55  setZValue( 10. );
56 }
57 #endif
58 
60 {
61 }
62 
64 {
65  return Type;
66 }
67 
69 {
70  return qobject_cast<GraphicsScene*>( QGraphicsItem::scene() );
71 }
72 
74 {
75  return Constraint( scene()->summaryHandlingModel()->mapFromSource( m_constraint.startIndex() ),
76  scene()->summaryHandlingModel()->mapFromSource( m_constraint.endIndex() ),
77  m_constraint.type(), m_constraint.relationType(), m_constraint.dataMap() );
78 }
79 
81 {
82  return scene()->itemDelegate()->constraintBoundingRect( m_start, m_end, m_constraint );
83 }
84 
85 void ConstraintGraphicsItem::paint( QPainter* painter, const QStyleOptionGraphicsItem* option,
86  QWidget* widget )
87 {
88  Q_UNUSED( widget );
89  //qDebug() << "ConstraintGraphicsItem::paint(...), c=" << m_constraint;
90  scene()->itemDelegate()->paintConstraintItem( painter, *option, m_start, m_end, m_constraint );
91 }
92 
94 {
95  return m_constraint.data( Qt::ToolTipRole ).toString();
96 }
97 
98 void ConstraintGraphicsItem::setStart( const QPointF& start )
99 {
100  prepareGeometryChange();
101  m_start = start;
102  update();
103 }
104 
105 void ConstraintGraphicsItem::setEnd( const QPointF& end )
106 {
107  prepareGeometryChange();
108  m_end = end;
109  update();
110 }
111 
112 void ConstraintGraphicsItem::updateItem( const QPointF& start,const QPointF& end )
113 {
114  setStart( start );
115  setEnd( end );
116 }

Klarälvdalens Datakonsult AB (KDAB)
Qt-related services and products
http://www.kdab.com/
http://www.kdab.com/products/kd-chart/