X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;ds=sidebyside;f=appli%2FcpPipelineEditor%2FQNEBlock.cxx;h=071effc1077bf48a23f420f4514a9987938b043d;hb=f4aeff15ebb41183d4b89f41b29ec26043848722;hp=7ccb166cd3d6e70f29f03aa077eefba29d70cdbe;hpb=2c372f652bce67b347cd91737916504a054604a3;p=cpPlugins.git diff --git a/appli/cpPipelineEditor/QNEBlock.cxx b/appli/cpPipelineEditor/QNEBlock.cxx index 7ccb166..071effc 100644 --- a/appli/cpPipelineEditor/QNEBlock.cxx +++ b/appli/cpPipelineEditor/QNEBlock.cxx @@ -39,15 +39,19 @@ PipelineEditor::QNEBlock:: QNEBlock( QGraphicsItem* parent, QGraphicsScene* scene ) : Superclass( parent, scene ), m_HorzMargin( 20 ), - m_VertMargin( 5 ) + m_VertMargin( 5 ), + m_NamePort( NULL ), + m_TypePort( NULL ) { QPainterPath p; p.addRoundedRect( -50, -15, 100, 30, 5, 5 ); + this->setPath( p ); this->setPen( QPen( Qt::darkGreen ) ); this->setBrush( Qt::green ); this->setFlag( QGraphicsItem::ItemIsMovable ); this->setFlag( QGraphicsItem::ItemIsSelectable ); + this->m_Width = this->m_HorzMargin; this->m_Height = this->m_VertMargin; } @@ -59,134 +63,85 @@ PipelineEditor::QNEBlock:: } // ------------------------------------------------------------------------- -PipelineEditor::QNEPort* PipelineEditor::QNEBlock:: -addPort( const QString& name, bool isOutput, int flags, int ptr ) -{ - QNEPort* port = new QNEPort( this ); - port->setName( name ); - port->setIsOutput( isOutput ); - port->setNEBlock( this ); - port->setPortFlags( flags ); - port->setPtr( ptr ); - - QFontMetrics fm( this->scene( )->font( ) ); - int w = fm.width( name ); - int h = fm.height( ); - if( w > this->m_Width - this->m_HorzMargin ) - this->m_Width = w + this->m_HorzMargin; - this->m_Height += h; - - QPainterPath p; - p.addRoundedRect( - -this->m_Width / 2, - -this->m_Height / 2, - this->m_Width, - this->m_Height, 5, 5 - ); - this->setPath( p ); - - int y = -this->m_Height / 2 + this->m_VertMargin + port->radius( ); - foreach( QGraphicsItem* port_, children( ) ) - { - if( port_->type( ) != QNEPort::Type ) - continue; - - QNEPort* port = ( QNEPort* ) port_; - if( port->isOutput( ) ) - port->setPos( this->m_Width/2 + port->radius( ), y ); - else - port->setPos( -this->m_Width/2 - port->radius( ), y ); - y += h; - - } // rof - return( port ); -} - -// ------------------------------------------------------------------------- -PipelineEditor::QNEPort* PipelineEditor::QNEBlock:: -addInputPort( const QString& name ) +void PipelineEditor::QNEBlock:: +setNamePort( const QString& txt ) { - return( this->addPort( name, false ) ); + if( this->m_NamePort == NULL ) + this->m_NamePort = new QNENamePort( this ); + this->m_NamePort->setName( txt ); + this->_configPort( this->m_NamePort ); } // ------------------------------------------------------------------------- -PipelineEditor::QNEPort* PipelineEditor::QNEBlock:: -addOutputPort( const QString& name ) +void PipelineEditor::QNEBlock:: +setTypePort( const QString& txt ) { - return( this->addPort( name, true ) ); + if( this->m_TypePort == NULL ) + this->m_TypePort = new QNETypePort( this ); + this->m_TypePort->setName( txt ); + this->_configPort( this->m_TypePort ); } // ------------------------------------------------------------------------- void PipelineEditor::QNEBlock:: -addInputPorts( const QStringList& names ) +addInputPort( const QString& txt ) { - foreach( QString n, names ) - this->addInputPort( n ); + QNEInputPort* ip = new QNEInputPort( this ); + ip->setName( txt ); + this->m_InputPorts.push_back( ip ); + this->_configPort( ip ); } // ------------------------------------------------------------------------- void PipelineEditor::QNEBlock:: -addOutputPorts( const QStringList& names ) +addOutputPort( const QString& txt ) { - foreach( QString n, names ) - this->addOutputPort( n ); + QNEOutputPort* op = new QNEOutputPort( this ); + op->setName( txt ); + this->m_OutputPorts.push_back( op ); + this->_configPort( op ); } // ------------------------------------------------------------------------- -void PipelineEditor::QNEBlock:: -save( QDataStream& ds ) +QVector< PipelineEditor::QNEPort* > PipelineEditor::QNEBlock:: +ports( ) { - ds << pos( ); - - int count( 0 ); - - foreach( QGraphicsItem* port_, children( ) ) + QVector< QNEPort* > res; + foreach( QGraphicsItem* i, this->childItems( ) ) { - if( port_->type( ) != QNEPort::Type ) - continue; - count++; - - } // rof - - ds << count; - - foreach( QGraphicsItem* port_, children( ) ) - { - if( port_->type( ) != QNEPort::Type ) - continue; - - QNEPort* port = ( QNEPort* ) port_; - ds << ( quint64 ) port; - ds << port->portName( ); - ds << port->isOutput( ); - ds << port->portFlags( ); + QNEPort* p = dynamic_cast< QNEPort* >( i ); + if( p != NULL ) + res.append( p ); } // rof + return( res ); } // ------------------------------------------------------------------------- -void PipelineEditor::QNEBlock:: -load( QDataStream& ds, QMap& portMap ) +PipelineEditor::QNEBlock* PipelineEditor::QNEBlock:: +clone( ) { - QPointF p; - ds >> p; - this->setPos( p ); - int count; - ds >> count; - for( int i = 0; i < count; i++ ) + QNEBlock* b = new QNEBlock( 0, this->scene( ) ); + foreach( QGraphicsItem* i, this->childItems( ) ) { - QString name; - bool output; - int flags; - quint64 ptr; + QNENamePort* np = dynamic_cast< QNENamePort* >( i ); + if( np != NULL ) + b->setNamePort( np->name( ) ); + + QNETypePort* tp = dynamic_cast< QNETypePort* >( i ); + if( tp != NULL ) + b->setTypePort( tp->name( ) ); - ds >> ptr; - ds >> name; - ds >> output; - ds >> flags; - portMap[ptr] = this->addPort( name, output, flags, ptr ); + QNEInputPort* ip = dynamic_cast< QNEInputPort* >( i ); + if( ip != NULL ) + b->addInputPort( ip->name( ) ); + + QNEOutputPort* op = dynamic_cast< QNEOutputPort* >( i ); + if( op != NULL ) + b->addOutputPort( op->name( ) ); } // rof + return( b ); } // ------------------------------------------------------------------------- @@ -213,48 +168,48 @@ paint( } // ------------------------------------------------------------------------- -PipelineEditor::QNEBlock* PipelineEditor::QNEBlock:: -clone( ) +QVariant PipelineEditor::QNEBlock:: +itemChange( GraphicsItemChange change, const QVariant& value ) { - QNEBlock* b = new QNEBlock( 0, this->scene( ) ); - - foreach( QGraphicsItem* port_, childItems( ) ) - { - if( port_->type( ) == QNEPort::Type ) - { - QNEPort* port = ( QNEPort* ) port_; - b->addPort( - port->portName( ), - port->isOutput( ), - port->portFlags( ), - port->ptr( ) - ); - - } // fi - - } // rof - return( b ); + return( value ); } // ------------------------------------------------------------------------- -QVector< PipelineEditor::QNEPort* > PipelineEditor::QNEBlock:: -ports( ) +void PipelineEditor::QNEBlock:: +_configPort( QNEPort* port ) { - QVector< PipelineEditor::QNEPort* > res; - foreach( QGraphicsItem* port_, childItems( ) ) + port->setBlock( this ); + + QFontMetrics fm( this->scene( )->font( ) ); + int w = fm.width( port->name( ) ); + int h = fm.height( ); + if( w > this->m_Width - this->m_HorzMargin ) + this->m_Width = w + this->m_HorzMargin; + this->m_Height += h; + + QPainterPath pth; + pth.addRoundedRect( + -this->m_Width / 2, + -this->m_Height / 2, + this->m_Width, + this->m_Height, 5, 5 + ); + this->setPath( pth ); + + int y = -this->m_Height / 2 + this->m_VertMargin + port->radius( ); + foreach( QGraphicsItem* i, this->children( ) ) { - if( port_->type( ) == QNEPort::Type ) - res.append( ( QNEPort* ) port_ ); + QNEPort* p = dynamic_cast< QNEPort* >( i ); + if( p == NULL ) + continue; - } // rof - return( res ); -} + if( dynamic_cast< QNEOutputPort* >( p ) != NULL ) + p->setPos( this->m_Width / 2 + port->radius( ), y ); + else + p->setPos( -this->m_Width / 2 - port->radius( ), y ); + y += h; -// ------------------------------------------------------------------------- -QVariant PipelineEditor::QNEBlock:: -itemChange( GraphicsItemChange change, const QVariant& value ) -{ - return( value ); + } // rof } // eof - $RCSfile$