KD Chart 2 [rev.2.4]
|
00001 /**************************************************************************** 00002 ** Copyright (C) 2001-2012 Klaralvdalens Datakonsult AB. All rights reserved. 00003 ** 00004 ** This file is part of the KD Chart library. 00005 ** 00006 ** Licensees holding valid commercial KD Chart licenses may use this file in 00007 ** accordance with the KD Chart Commercial License Agreement provided with 00008 ** the Software. 00009 ** 00010 ** 00011 ** This file may be distributed and/or modified under the terms of the 00012 ** GNU General Public License version 2 and version 3 as published by the 00013 ** Free Software Foundation and appearing in the file LICENSE.GPL.txt included. 00014 ** 00015 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 00016 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 00017 ** 00018 ** Contact info@kdab.com if any conditions of this licensing are not 00019 ** clear to you. 00020 ** 00021 **********************************************************************/ 00022 00023 #include "kdganttconstraintgraphicsitem.h" 00024 #include "kdganttconstraintmodel.h" 00025 #include "kdganttgraphicsscene.h" 00026 #include "kdganttitemdelegate.h" 00027 #include "kdganttsummaryhandlingproxymodel.h" 00028 00029 #include <QPainter> 00030 #include <QDebug> 00031 00032 using namespace KDGantt; 00033 00038 ConstraintGraphicsItem::ConstraintGraphicsItem( const Constraint& c, QGraphicsItem* parent, GraphicsScene* scene ) 00039 : QGraphicsItem( parent, scene ), m_constraint( c ) 00040 { 00041 setPos( QPointF( 0., 0. ) ); 00042 setAcceptsHoverEvents( false ); 00043 setAcceptedMouseButtons( Qt::NoButton ); 00044 setZValue( 10. ); 00045 } 00046 00047 ConstraintGraphicsItem::~ConstraintGraphicsItem() 00048 { 00049 } 00050 00051 int ConstraintGraphicsItem::type() const 00052 { 00053 return Type; 00054 } 00055 00056 GraphicsScene* ConstraintGraphicsItem::scene() const 00057 { 00058 return qobject_cast<GraphicsScene*>( QGraphicsItem::scene() ); 00059 } 00060 00061 Constraint ConstraintGraphicsItem::proxyConstraint() const 00062 { 00063 return Constraint( scene()->summaryHandlingModel()->mapFromSource( m_constraint.startIndex() ), 00064 scene()->summaryHandlingModel()->mapFromSource( m_constraint.endIndex() ), 00065 m_constraint.type(), m_constraint.relationType(), m_constraint.dataMap() ); 00066 } 00067 00068 QRectF ConstraintGraphicsItem::boundingRect() const 00069 { 00070 return scene()->itemDelegate()->constraintBoundingRect( m_start, m_end, m_constraint ); 00071 } 00072 00073 void ConstraintGraphicsItem::paint( QPainter* painter, const QStyleOptionGraphicsItem* option, 00074 QWidget* widget ) 00075 { 00076 Q_UNUSED( widget ); 00077 //qDebug() << "ConstraintGraphicsItem::paint(...), c=" << m_constraint; 00078 scene()->itemDelegate()->paintConstraintItem( painter, *option, m_start, m_end, m_constraint ); 00079 } 00080 00081 QString ConstraintGraphicsItem::ganttToolTip() const 00082 { 00083 return m_constraint.data( Qt::ToolTipRole ).toString(); 00084 } 00085 00086 void ConstraintGraphicsItem::setStart( const QPointF& start ) 00087 { 00088 prepareGeometryChange(); 00089 m_start = start; 00090 update(); 00091 } 00092 00093 void ConstraintGraphicsItem::setEnd( const QPointF& end ) 00094 { 00095 prepareGeometryChange(); 00096 m_end = end; 00097 update(); 00098 } 00099 00100 void ConstraintGraphicsItem::updateItem( const QPointF& start,const QPointF& end ) 00101 { 00102 setStart( start ); 00103 setEnd( end ); 00104 }