]> Creatis software - cpPlugins.git/blobdiff - appli/cpPipelineEditor/QNEPort.cxx
...
[cpPlugins.git] / appli / cpPipelineEditor / QNEPort.cxx
index dbf43463be32b9ed1367dc1f0a3dad565c979bf4..6aa653b1a1987f14f1b8efcabd5397e3ae5a8445 100644 (file)
@@ -41,7 +41,7 @@ QNEPort( QGraphicsItem* parent, QGraphicsScene* scene )
   this->m_Label = new QGraphicsTextItem( this );\r
 \r
   QPainterPath p;\r
-  p.addEllipse( \r
+  p.addEllipse(\r
     -this->m_Radius, -this->m_Radius,\r
     2 * this->m_Radius, 2 * this->m_Radius\r
     );\r
@@ -50,27 +50,24 @@ QNEPort( QGraphicsItem* parent, QGraphicsScene* scene )
   this->setPen( QPen( Qt::darkRed ) );\r
   this->setBrush( Qt::red );\r
   this->setFlag( QGraphicsItem::ItemSendsScenePositionChanges );\r
-  this->m_PortFlags = 0;\r
 }\r
 \r
 // -------------------------------------------------------------------------\r
 PipelineEditor::QNEPort::\r
 ~QNEPort( )\r
 {\r
-  foreach( QNEConnection* conn, this->m_Connections )\r
-    delete conn;\r
 }\r
 \r
 // -------------------------------------------------------------------------\r
 void PipelineEditor::QNEPort::\r
-setNEBlock( QNEBlock *b )\r
+setBlock( QNEBlock* b )\r
 {\r
   this->m_Block = b;\r
 }\r
 \r
 // -------------------------------------------------------------------------\r
 void PipelineEditor::QNEPort::\r
-setName( const QString &n )\r
+setName( const QStringn )\r
 {\r
   this->m_Name = n;\r
   this->m_Label->setPlainText( n );\r
@@ -78,100 +75,184 @@ setName( const QString &n )
 \r
 // -------------------------------------------------------------------------\r
 void PipelineEditor::QNEPort::\r
-setIsOutput( bool o )\r
+setPtr( quint64 p )\r
 {\r
-  this->m_IsOutput = o;\r
+  this->m_Ptr = p;\r
+}\r
 \r
-  QFontMetrics fm( this->scene( )->font( ) );\r
-  QRect r = fm.boundingRect( this->m_Name );\r
+// -------------------------------------------------------------------------\r
+PipelineEditor::QNENamePort::\r
+QNENamePort( QGraphicsItem* parent, QGraphicsScene* scene )\r
+  : Superclass( parent, scene )\r
+{\r
+}\r
 \r
-  int rm = this->m_Radius + this->m_Margin;\r
-  int h = -this->m_Label->boundingRect( ).height( ) / 2;\r
-  if( this->m_IsOutput )\r
-    this->m_Label->setPos(\r
-      -rm - this->m_Label->boundingRect( ).width( ), h\r
-      );\r
-  else\r
-    this->m_Label->setPos( rm, h );\r
+// -------------------------------------------------------------------------\r
+PipelineEditor::QNENamePort::\r
+~QNENamePort( )\r
+{\r
 }\r
 \r
 // -------------------------------------------------------------------------\r
-int PipelineEditor::QNEPort::\r
-radius( )\r
+void PipelineEditor::QNENamePort::\r
+setName( const QString& n )\r
 {\r
-  return( this->m_Radius );\r
+  this->Superclass::setName( n );\r
+\r
+  QFont font( this->scene( )->font( ) );\r
+  font.setBold( true );\r
+  this->m_Label->setFont( font );\r
+  this->setPath( QPainterPath( ) );\r
 }\r
 \r
 // -------------------------------------------------------------------------\r
-bool PipelineEditor::QNEPort::\r
-isOutput( )\r
+bool PipelineEditor::QNENamePort::\r
+isConnected( QNEPort* other )\r
 {\r
-  return( this->m_IsOutput );\r
+  return( false );\r
 }\r
 \r
 // -------------------------------------------------------------------------\r
-QVector< PipelineEditor::QNEConnection* >& PipelineEditor::QNEPort::\r
-connections( )\r
+PipelineEditor::QNETypePort::\r
+QNETypePort( QGraphicsItem* parent, QGraphicsScene* scene )\r
+  : Superclass( parent, scene )\r
 {\r
-  return( this->m_Connections );\r
 }\r
 \r
 // -------------------------------------------------------------------------\r
-void PipelineEditor::QNEPort::\r
-setPortFlags( int f )\r
+PipelineEditor::QNETypePort::\r
+~QNETypePort( )\r
 {\r
-  this->m_PortFlags = f;\r
+}\r
 \r
-  if( this->m_PortFlags & Self::TypePort )\r
-  {\r
-    QFont font( this->scene( )->font( ) );\r
-    font.setItalic( true );\r
-    this->m_Label->setFont( font );\r
-    this->setPath( QPainterPath( ) );\r
-  }\r
-  else if( this->m_PortFlags & Self::NamePort )\r
+// -------------------------------------------------------------------------\r
+void PipelineEditor::QNETypePort::\r
+setName( const QString& n )\r
+{\r
+  this->Superclass::setName( n );\r
+\r
+  QFont font( this->scene( )->font( ) );\r
+  font.setItalic( true );\r
+  this->m_Label->setFont( font );\r
+  this->setPath( QPainterPath( ) );\r
+}\r
+\r
+// -------------------------------------------------------------------------\r
+bool PipelineEditor::QNETypePort::\r
+isConnected( QNEPort* other )\r
+{\r
+  return( false );\r
+}\r
+\r
+// -------------------------------------------------------------------------\r
+PipelineEditor::QNEInputPort::\r
+QNEInputPort( QGraphicsItem* parent, QGraphicsScene* scene )\r
+  : Superclass( parent, scene ),\r
+    m_Connection( NULL )\r
+{\r
+}\r
+\r
+// -------------------------------------------------------------------------\r
+PipelineEditor::QNEInputPort::\r
+~QNEInputPort( )\r
+{\r
+  if( this->m_Connection != NULL )\r
+    delete this->m_Connection;\r
+}\r
+\r
+// -------------------------------------------------------------------------\r
+void PipelineEditor::QNEInputPort::\r
+setName( const QString& n )\r
+{\r
+  this->Superclass::setName( n );\r
+\r
+  QFontMetrics fm( this->scene( )->font( ) );\r
+  QRect r = fm.boundingRect( this->m_Name );\r
+  int rm = this->m_Radius + this->m_Margin;\r
+  int h = -this->m_Label->boundingRect( ).height( ) / 2;\r
+  this->m_Label->setPos( rm, h );\r
+}\r
+\r
+// -------------------------------------------------------------------------\r
+bool PipelineEditor::QNEInputPort::\r
+isConnected( QNEPort* other )\r
+{\r
+  if( this->m_Connection != NULL )\r
+    return(\r
+      this->m_Connection->port1( ) == other &&\r
+      this->m_Connection->port2( ) == this\r
+      );\r
+  else\r
+    return( false );\r
+}\r
+\r
+// -------------------------------------------------------------------------\r
+void PipelineEditor::QNEInputPort::\r
+setConnection( QNEConnection* c )\r
+{\r
+  this->m_Connection = c;\r
+}\r
+\r
+// -------------------------------------------------------------------------\r
+QVariant PipelineEditor::QNEInputPort::\r
+itemChange( GraphicsItemChange change, const QVariant& value )\r
+{\r
+  if( change == ItemScenePositionHasChanged )\r
   {\r
-    QFont font( this->scene( )->font( ) );\r
-    font.setBold( true );\r
-    this->m_Label->setFont( font );\r
-    this->setPath( QPainterPath( ) );\r
+    if( this->m_Connection != NULL )\r
+    {\r
+      this->m_Connection->updatePosFromPorts( );\r
+      this->m_Connection->updatePath( );\r
+\r
+    } // fi\r
 \r
   } // fi\r
+  return( value );\r
 }\r
 \r
 // -------------------------------------------------------------------------\r
-PipelineEditor::QNEBlock* PipelineEditor::QNEPort::\r
-block( ) const\r
+PipelineEditor::QNEOutputPort::\r
+QNEOutputPort( QGraphicsItem* parent, QGraphicsScene* scene )\r
+  : Superclass( parent, scene )\r
 {\r
-  return( this->m_Block );\r
 }\r
 \r
 // -------------------------------------------------------------------------\r
-quint64 PipelineEditor::QNEPort::\r
-ptr( )\r
+PipelineEditor::QNEOutputPort::\r
+~QNEOutputPort( )\r
 {\r
-  return( this->m_Ptr );\r
+  foreach( QNEConnection* conn, this->m_Connections )\r
+    delete conn;\r
 }\r
 \r
 // -------------------------------------------------------------------------\r
-void PipelineEditor::QNEPort::\r
-setPtr( quint64 p )\r
+void PipelineEditor::QNEOutputPort::\r
+setName( const QString& n )\r
 {\r
-  this->m_Ptr = p;\r
+  this->Superclass::setName( n );\r
+\r
+  QFontMetrics fm( this->scene( )->font( ) );\r
+  QRect r = fm.boundingRect( this->m_Name );\r
+  int rm = this->m_Radius + this->m_Margin;\r
+  int h = -this->m_Label->boundingRect( ).height( ) / 2;\r
+  this->m_Label->setPos(\r
+    -rm - this->m_Label->boundingRect( ).width( ), h\r
+    );\r
 }\r
 \r
 // -------------------------------------------------------------------------\r
-bool PipelineEditor::QNEPort::\r
+bool PipelineEditor::QNEOutputPort::\r
 isConnected( QNEPort* other )\r
 {\r
-  foreach( QNEConnection* conn, this->m_Connections )\r
-    if( conn->port1( ) == other || conn->port2( ) == other )\r
-      return( true );\r
-  return( false );\r
+  auto i = this->m_Connections.begin( );\r
+  bool conn = false;\r
+  for( ; i != this->m_Connections.end( ) && !conn; ++i )\r
+    conn |= ( ( *i )->port1( ) == this && ( *i )->port2( ) == other );\r
+  return( conn );\r
 }\r
 \r
 // -------------------------------------------------------------------------\r
-QVariant PipelineEditor::QNEPort::\r
+QVariant PipelineEditor::QNEOutputPort::\r
 itemChange( GraphicsItemChange change, const QVariant& value )\r
 {\r
   if( change == ItemScenePositionHasChanged )\r