]> Creatis software - cpPlugins.git/blobdiff - appli/cpPipelineEditor/QNEBlock.cxx
More on graph editor
[cpPlugins.git] / appli / cpPipelineEditor / QNEBlock.cxx
index d1e01094d1bb535845c708d0cfe498c9c4abbc55..071effc1077bf48a23f420f4514a9987938b043d 100644 (file)
@@ -39,15 +39,19 @@ PipelineEditor::QNEBlock::
 QNEBlock( QGraphicsItem* parent, QGraphicsScene* scene )\r
   : Superclass( parent, scene ),\r
     m_HorzMargin( 20 ),\r
-    m_VertMargin( 5 )\r
+    m_VertMargin( 5 ),\r
+    m_NamePort( NULL ),\r
+    m_TypePort( NULL )\r
 {\r
   QPainterPath p;\r
   p.addRoundedRect( -50, -15, 100, 30, 5, 5 );\r
+\r
   this->setPath( p );\r
   this->setPen( QPen( Qt::darkGreen ) );\r
   this->setBrush( Qt::green );\r
   this->setFlag( QGraphicsItem::ItemIsMovable );\r
   this->setFlag( QGraphicsItem::ItemIsSelectable );\r
+\r
   this->m_Width = this->m_HorzMargin;\r
   this->m_Height = this->m_VertMargin;\r
 }\r
@@ -58,135 +62,86 @@ PipelineEditor::QNEBlock::
 {\r
 }\r
 \r
-// -------------------------------------------------------------------------\r
-PipelineEditor::QNEPort* PipelineEditor::QNEBlock::\r
-addPort( const QString& name, bool isOutput, int flags, int ptr )\r
-{\r
-  QNEPort* port = new QNEPort( this );\r
-  port->setName( name );\r
-  port->setIsOutput( isOutput );\r
-  port->setNEBlock( this );\r
-  port->setPortFlags( flags );\r
-  port->setPtr( ptr );\r
-\r
-  QFontMetrics fm( this->scene( )->font( ) );\r
-  int w = fm.width( name );\r
-  int h = fm.height( );\r
-  if( w > this->m_Width - this->m_HorzMargin )\r
-    this->m_Width = w + this->m_HorzMargin;\r
-  this->m_Height += h;\r
-\r
-  QPainterPath p;\r
-  p.addRoundedRect(\r
-    -this->m_Width / 2,\r
-    -this->m_Height / 2,\r
-    this->m_Width,\r
-    this->m_Height, 5, 5\r
-    );\r
-  this->setPath( p );\r
-\r
-  int y = -this->m_Height / 2 + this->m_VertMargin + port->radius( );\r
-  foreach( QGraphicsItem* port_, children( ) )\r
-  {\r
-    if( port_->type( ) != QNEPort::Type )\r
-      continue;\r
-\r
-    QNEPort* port = ( QNEPort* ) port_;\r
-    if( port->isOutput( ) )\r
-      port->setPos( this->m_Width/2 + port->radius( ), y );\r
-    else\r
-      port->setPos( -this->m_Width/2 - port->radius( ), y );\r
-    y += h;\r
-\r
-  } // rof\r
-  return( port );\r
-}\r
-\r
 // -------------------------------------------------------------------------\r
 void PipelineEditor::QNEBlock::\r
-addInputPort( const QString& name )\r
+setNamePort( const QString& txt )\r
 {\r
-  this->addPort( name, false );\r
+  if( this->m_NamePort == NULL )\r
+    this->m_NamePort = new QNENamePort( this );\r
+  this->m_NamePort->setName( txt );\r
+  this->_configPort( this->m_NamePort );\r
 }\r
 \r
 // -------------------------------------------------------------------------\r
 void PipelineEditor::QNEBlock::\r
-addOutputPort( const QString& name )\r
+setTypePort( const QString& txt )\r
 {\r
-  this->addPort( name, true );\r
+  if( this->m_TypePort == NULL )\r
+    this->m_TypePort = new QNETypePort( this );\r
+  this->m_TypePort->setName( txt );\r
+  this->_configPort( this->m_TypePort );\r
 }\r
 \r
 // -------------------------------------------------------------------------\r
 void PipelineEditor::QNEBlock::\r
-addInputPorts( const QStringList& names )\r
+addInputPort( const QString& txt )\r
 {\r
-  foreach( QString n, names )\r
-    this->addInputPort( n );\r
+  QNEInputPort* ip = new QNEInputPort( this );\r
+  ip->setName( txt );\r
+  this->m_InputPorts.push_back( ip );\r
+  this->_configPort( ip );\r
 }\r
 \r
 // -------------------------------------------------------------------------\r
 void PipelineEditor::QNEBlock::\r
-addOutputPorts( const QStringList& names )\r
+addOutputPort( const QString& txt )\r
 {\r
-  foreach( QString n, names )\r
-    this->addOutputPort( n );\r
+  QNEOutputPort* op = new QNEOutputPort( this );\r
+  op->setName( txt );\r
+  this->m_OutputPorts.push_back( op );\r
+  this->_configPort( op );\r
 }\r
 \r
 // -------------------------------------------------------------------------\r
-void PipelineEditor::QNEBlock::\r
-save( QDataStream& ds )\r
+QVector< PipelineEditor::QNEPort* > PipelineEditor::QNEBlock::\r
+ports( )\r
 {\r
-  ds << pos( );\r
-\r
-  int count( 0 );\r
-\r
-  foreach( QGraphicsItem* port_, children( ) )\r
+  QVector< QNEPort* > res;\r
+  foreach( QGraphicsItem* i, this->childItems( ) )\r
   {\r
-    if( port_->type( ) != QNEPort::Type )\r
-      continue;\r
-    count++;\r
-\r
-  } // rof\r
-\r
-  ds << count;\r
-\r
-  foreach( QGraphicsItem* port_, children( ) )\r
-  {\r
-    if( port_->type( ) != QNEPort::Type )\r
-      continue;\r
-\r
-    QNEPort* port = ( QNEPort* ) port_;\r
-    ds << ( quint64 ) port;\r
-    ds << port->portName( );\r
-    ds << port->isOutput( );\r
-    ds << port->portFlags( );\r
+    QNEPort* p = dynamic_cast< QNEPort* >( i );\r
+    if( p != NULL )\r
+      res.append( p );\r
 \r
   } // rof\r
+  return( res );\r
 }\r
 \r
 // -------------------------------------------------------------------------\r
-void PipelineEditor::QNEBlock::\r
-load( QDataStream& ds, QMap<quint64, QNEPort*>& portMap )\r
+PipelineEditor::QNEBlock* PipelineEditor::QNEBlock::\r
+clone( )\r
 {\r
-  QPointF p;\r
-  ds >> p;\r
-  this->setPos( p );\r
-  int count;\r
-  ds >> count;\r
-  for( int i = 0; i < count; i++ )\r
+  QNEBlock* b = new QNEBlock( 0, this->scene( ) );\r
+  foreach( QGraphicsItem* i, this->childItems( ) )\r
   {\r
-    QString name;\r
-    bool output;\r
-    int flags;\r
-    quint64 ptr;\r
+    QNENamePort* np = dynamic_cast< QNENamePort* >( i );\r
+    if( np != NULL )\r
+      b->setNamePort( np->name( ) );\r
+\r
+    QNETypePort* tp = dynamic_cast< QNETypePort* >( i );\r
+    if( tp != NULL )\r
+      b->setTypePort( tp->name( ) );\r
+\r
+    QNEInputPort* ip = dynamic_cast< QNEInputPort* >( i );\r
+    if( ip != NULL )\r
+      b->addInputPort( ip->name( ) );\r
 \r
-    ds >> ptr;\r
-    ds >> name;\r
-    ds >> output;\r
-    ds >> flags;\r
-    portMap[ptr] = this->addPort( name, output, flags, ptr );\r
+    QNEOutputPort* op = dynamic_cast< QNEOutputPort* >( i );\r
+    if( op != NULL )\r
+      b->addOutputPort( op->name( ) );\r
 \r
   } // rof\r
+  return( b );\r
 }\r
 \r
 // -------------------------------------------------------------------------\r
@@ -213,48 +168,48 @@ paint(
 }\r
 \r
 // -------------------------------------------------------------------------\r
-PipelineEditor::QNEBlock* PipelineEditor::QNEBlock::\r
-clone( )\r
+QVariant PipelineEditor::QNEBlock::\r
+itemChange( GraphicsItemChange change, const QVariant& value )\r
 {\r
-  QNEBlock* b = new QNEBlock( 0, this->scene( ) );\r
-\r
-  foreach( QGraphicsItem* port_, childItems( ) )\r
-  {\r
-    if( port_->type( ) == QNEPort::Type )\r
-    {\r
-      QNEPort* port = ( QNEPort* ) port_;\r
-      b->addPort(\r
-        port->portName( ),\r
-        port->isOutput( ),\r
-        port->portFlags( ),\r
-        port->ptr( )\r
-        );\r
-\r
-    } // fi\r
-\r
-  } // rof\r
-  return( b );\r
+  return( value );\r
 }\r
 \r
 // -------------------------------------------------------------------------\r
-QVector< PipelineEditor::QNEPort* > PipelineEditor::QNEBlock::\r
-ports( )\r
+void PipelineEditor::QNEBlock::\r
+_configPort( QNEPort* port )\r
 {\r
-  QVector< PipelineEditor::QNEPort* > res;\r
-  foreach( QGraphicsItem* port_, childItems( ) )\r
+  port->setBlock( this );\r
+\r
+  QFontMetrics fm( this->scene( )->font( ) );\r
+  int w = fm.width( port->name( ) );\r
+  int h = fm.height( );\r
+  if( w > this->m_Width - this->m_HorzMargin )\r
+    this->m_Width = w + this->m_HorzMargin;\r
+  this->m_Height += h;\r
+\r
+  QPainterPath pth;\r
+  pth.addRoundedRect(\r
+    -this->m_Width / 2,\r
+    -this->m_Height / 2,\r
+    this->m_Width,\r
+    this->m_Height, 5, 5\r
+    );\r
+  this->setPath( pth );\r
+\r
+  int y = -this->m_Height / 2 + this->m_VertMargin + port->radius( );\r
+  foreach( QGraphicsItem* i, this->children( ) )\r
   {\r
-    if( port_->type( ) == QNEPort::Type )\r
-      res.append( ( QNEPort* ) port_ );\r
+    QNEPort* p = dynamic_cast< QNEPort* >( i );\r
+    if( p == NULL )\r
+      continue;\r
 \r
-  } // rof\r
-  return( res );\r
-}\r
+    if( dynamic_cast< QNEOutputPort* >( p ) != NULL )\r
+      p->setPos( this->m_Width / 2 + port->radius( ), y );\r
+    else\r
+      p->setPos( -this->m_Width / 2 - port->radius( ), y );\r
+    y += h;\r
 \r
-// -------------------------------------------------------------------------\r
-QVariant PipelineEditor::QNEBlock::\r
-itemChange( GraphicsItemChange change, const QVariant& value )\r
-{\r
-  return( value );\r
+  } // rof\r
 }\r
 \r
 // eof - $RCSfile$\r