X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=appli%2FcpPipelineEditor%2FQNEPort.cxx;h=6aa653b1a1987f14f1b8efcabd5397e3ae5a8445;hb=f8c546490b7168b5c75d877bf66d27f83aa9412c;hp=7c140bbb0c56552833a47760f98a3c206c8efa20;hpb=ef8b6e12859181d3faa8019ce7319c539c0f86ec;p=cpPlugins.git diff --git a/appli/cpPipelineEditor/QNEPort.cxx b/appli/cpPipelineEditor/QNEPort.cxx index 7c140bb..6aa653b 100644 --- a/appli/cpPipelineEditor/QNEPort.cxx +++ b/appli/cpPipelineEditor/QNEPort.cxx @@ -25,13 +25,12 @@ */ #include "QNEPort.h" +#include "QNEConnection.h" #include #include #include -#include "QNEConnection.h" - // ------------------------------------------------------------------------- PipelineEditor::QNEPort:: QNEPort( QGraphicsItem* parent, QGraphicsScene* scene ) @@ -42,7 +41,7 @@ QNEPort( QGraphicsItem* parent, QGraphicsScene* scene ) this->m_Label = new QGraphicsTextItem( this ); QPainterPath p; - p.addEllipse( + p.addEllipse( -this->m_Radius, -this->m_Radius, 2 * this->m_Radius, 2 * this->m_Radius ); @@ -51,27 +50,24 @@ QNEPort( QGraphicsItem* parent, QGraphicsScene* scene ) this->setPen( QPen( Qt::darkRed ) ); this->setBrush( Qt::red ); this->setFlag( QGraphicsItem::ItemSendsScenePositionChanges ); - this->m_PortFlags = 0; } // ------------------------------------------------------------------------- PipelineEditor::QNEPort:: ~QNEPort( ) { - foreach( QNEConnection* conn, this->m_Connections ) - delete conn; } // ------------------------------------------------------------------------- void PipelineEditor::QNEPort:: -setNEBlock( QNEBlock *b ) +setBlock( QNEBlock* b ) { this->m_Block = b; } // ------------------------------------------------------------------------- void PipelineEditor::QNEPort:: -setName( const QString &n ) +setName( const QString& n ) { this->m_Name = n; this->m_Label->setPlainText( n ); @@ -79,100 +75,184 @@ setName( const QString &n ) // ------------------------------------------------------------------------- void PipelineEditor::QNEPort:: -setIsOutput( bool o ) +setPtr( quint64 p ) { - this->m_IsOutput = o; + this->m_Ptr = p; +} - QFontMetrics fm( this->scene( )->font( ) ); - QRect r = fm.boundingRect( this->m_Name ); +// ------------------------------------------------------------------------- +PipelineEditor::QNENamePort:: +QNENamePort( QGraphicsItem* parent, QGraphicsScene* scene ) + : Superclass( parent, scene ) +{ +} - int rm = this->m_Radius + this->m_Margin; - int h = -this->m_Label->boundingRect( ).height( ) / 2; - if( this->m_IsOutput ) - this->m_Label->setPos( - -rm - this->m_Label->boundingRect( ).width( ), h - ); - else - this->m_Label->setPos( rm, h ); +// ------------------------------------------------------------------------- +PipelineEditor::QNENamePort:: +~QNENamePort( ) +{ } // ------------------------------------------------------------------------- -int PipelineEditor::QNEPort:: -radius( ) +void PipelineEditor::QNENamePort:: +setName( const QString& n ) { - return( this->m_Radius ); + this->Superclass::setName( n ); + + QFont font( this->scene( )->font( ) ); + font.setBold( true ); + this->m_Label->setFont( font ); + this->setPath( QPainterPath( ) ); } // ------------------------------------------------------------------------- -bool PipelineEditor::QNEPort:: -isOutput( ) +bool PipelineEditor::QNENamePort:: +isConnected( QNEPort* other ) { - return( this->m_IsOutput ); + return( false ); } // ------------------------------------------------------------------------- -QVector< PipelineEditor::QNEConnection* >& PipelineEditor::QNEPort:: -connections( ) +PipelineEditor::QNETypePort:: +QNETypePort( QGraphicsItem* parent, QGraphicsScene* scene ) + : Superclass( parent, scene ) { - return( this->m_Connections ); } // ------------------------------------------------------------------------- -void PipelineEditor::QNEPort:: -setPortFlags( int f ) +PipelineEditor::QNETypePort:: +~QNETypePort( ) { - this->m_PortFlags = f; +} - if( this->m_PortFlags & Self::TypePort ) - { - QFont font( this->scene( )->font( ) ); - font.setItalic( true ); - this->m_Label->setFont( font ); - this->setPath( QPainterPath( ) ); - } - else if( this->m_PortFlags & Self::NamePort ) +// ------------------------------------------------------------------------- +void PipelineEditor::QNETypePort:: +setName( const QString& n ) +{ + this->Superclass::setName( n ); + + QFont font( this->scene( )->font( ) ); + font.setItalic( true ); + this->m_Label->setFont( font ); + this->setPath( QPainterPath( ) ); +} + +// ------------------------------------------------------------------------- +bool PipelineEditor::QNETypePort:: +isConnected( QNEPort* other ) +{ + return( false ); +} + +// ------------------------------------------------------------------------- +PipelineEditor::QNEInputPort:: +QNEInputPort( QGraphicsItem* parent, QGraphicsScene* scene ) + : Superclass( parent, scene ), + m_Connection( NULL ) +{ +} + +// ------------------------------------------------------------------------- +PipelineEditor::QNEInputPort:: +~QNEInputPort( ) +{ + if( this->m_Connection != NULL ) + delete this->m_Connection; +} + +// ------------------------------------------------------------------------- +void PipelineEditor::QNEInputPort:: +setName( const QString& n ) +{ + this->Superclass::setName( n ); + + QFontMetrics fm( this->scene( )->font( ) ); + QRect r = fm.boundingRect( this->m_Name ); + int rm = this->m_Radius + this->m_Margin; + int h = -this->m_Label->boundingRect( ).height( ) / 2; + this->m_Label->setPos( rm, h ); +} + +// ------------------------------------------------------------------------- +bool PipelineEditor::QNEInputPort:: +isConnected( QNEPort* other ) +{ + if( this->m_Connection != NULL ) + return( + this->m_Connection->port1( ) == other && + this->m_Connection->port2( ) == this + ); + else + return( false ); +} + +// ------------------------------------------------------------------------- +void PipelineEditor::QNEInputPort:: +setConnection( QNEConnection* c ) +{ + this->m_Connection = c; +} + +// ------------------------------------------------------------------------- +QVariant PipelineEditor::QNEInputPort:: +itemChange( GraphicsItemChange change, const QVariant& value ) +{ + if( change == ItemScenePositionHasChanged ) { - QFont font( this->scene( )->font( ) ); - font.setBold( true ); - this->m_Label->setFont( font ); - this->setPath( QPainterPath( ) ); + if( this->m_Connection != NULL ) + { + this->m_Connection->updatePosFromPorts( ); + this->m_Connection->updatePath( ); + + } // fi } // fi + return( value ); } // ------------------------------------------------------------------------- -PipelineEditor::QNEBlock* PipelineEditor::QNEPort:: -block( ) const +PipelineEditor::QNEOutputPort:: +QNEOutputPort( QGraphicsItem* parent, QGraphicsScene* scene ) + : Superclass( parent, scene ) { - return( this->m_Block ); } // ------------------------------------------------------------------------- -quint64 PipelineEditor::QNEPort:: -ptr( ) +PipelineEditor::QNEOutputPort:: +~QNEOutputPort( ) { - return( this->m_Ptr ); + foreach( QNEConnection* conn, this->m_Connections ) + delete conn; } // ------------------------------------------------------------------------- -void PipelineEditor::QNEPort:: -setPtr( quint64 p ) +void PipelineEditor::QNEOutputPort:: +setName( const QString& n ) { - this->m_Ptr = p; + this->Superclass::setName( n ); + + QFontMetrics fm( this->scene( )->font( ) ); + QRect r = fm.boundingRect( this->m_Name ); + int rm = this->m_Radius + this->m_Margin; + int h = -this->m_Label->boundingRect( ).height( ) / 2; + this->m_Label->setPos( + -rm - this->m_Label->boundingRect( ).width( ), h + ); } // ------------------------------------------------------------------------- -bool PipelineEditor::QNEPort:: +bool PipelineEditor::QNEOutputPort:: isConnected( QNEPort* other ) { - foreach( QNEConnection* conn, this->m_Connections ) - if( conn->port1( ) == other || conn->port2( ) == other ) - return( true ); - return( false ); + auto i = this->m_Connections.begin( ); + bool conn = false; + for( ; i != this->m_Connections.end( ) && !conn; ++i ) + conn |= ( ( *i )->port1( ) == this && ( *i )->port2( ) == other ); + return( conn ); } // ------------------------------------------------------------------------- -QVariant PipelineEditor::QNEPort:: +QVariant PipelineEditor::QNEOutputPort:: itemChange( GraphicsItemChange change, const QVariant& value ) { if( change == ItemScenePositionHasChanged )