]> Creatis software - cpPlugins.git/blobdiff - appli/cpPipelineEditor/QNodesEditor.cxx
...
[cpPlugins.git] / appli / cpPipelineEditor / QNodesEditor.cxx
index 6417636e44ff256c6d30cbee0ce3786b5814e228..e026dda9d12f683e1cf9c495dbe9662ace367fd6 100644 (file)
@@ -36,6 +36,7 @@
 #include <QGraphicsSceneMoveEvent>\r
 #include <QGraphicsSceneResizeEvent>\r
 #include <QGraphicsSceneWheelEvent>\r
+#include <QInputDialog>\r
 \r
 #include "QNEPort.h"\r
 #include "QNEConnection.h"\r
@@ -86,7 +87,7 @@ setWorkspace( TWorkspace* ws )
   {\r
     this->_CreateBlock(\r
       dynamic_cast< TFilter* >( vIt->second.GetPointer( ) ),\r
-      QPointF( )\r
+      QPointF( vIt->second->GetViewX( ), vIt->second->GetViewY( ) )\r
       );\r
 \r
   } // rof\r
@@ -161,6 +162,25 @@ createFilter( const std::string& filter, const QPointF& pnt )
     return( "" );\r
 }\r
 \r
+// -------------------------------------------------------------------------\r
+void PipelineEditor::QNodesEditor::\r
+synchronizeBlockPositions( )\r
+{\r
+  auto bIt = this->m_Graph->BeginVertices( );\r
+  auto fIt = this->m_Workspace->GetGraph( )->BeginVertices( );\r
+  while(\r
+    bIt != this->m_Graph->EndVertices( ) &&\r
+    fIt != this->m_Workspace->GetGraph( )->EndVertices( )\r
+    )\r
+  {\r
+    auto pos = bIt->second->scenePos( );\r
+    fIt->second->SetViewCoords( pos.x( ), pos.y( ) );\r
+    bIt++;\r
+    fIt++;\r
+\r
+  } // elihw\r
+}\r
+\r
 // -------------------------------------------------------------------------\r
 void PipelineEditor::QNodesEditor::\r
 install( QGraphicsScene* s )\r
@@ -193,7 +213,7 @@ _CreateBlock( TFilter* f, const QPointF& pnt )
   QNEBlock* b = new QNEBlock( 0, this->m_Scene );\r
   b->setNamePort( f->GetName( ) );\r
   b->setTypePort( f->GetClassName( ) );\r
-  // TODO: b->setScenePos( pnt );\r
+  b->setPos( pnt );\r
 \r
   // Add input ports\r
   std::set< std::string > inputs;\r
@@ -225,6 +245,35 @@ _DoubleClick( QGraphicsSceneMouseEvent* evt, QGraphicsItem* item )
 \r
     if( block != NULL )\r
     {\r
+      QString old_name = block->namePort( )->name( );\r
+      bool ok;\r
+      QString new_name =\r
+        QInputDialog::getText(\r
+          dynamic_cast< QWidget* >( this->parent( ) ),\r
+          "Change filter name",\r
+          "Filter name:",\r
+          QLineEdit::Normal,\r
+          old_name,\r
+          &ok\r
+          );\r
+      if( ok && !new_name.isEmpty( ) && old_name != new_name )\r
+      {\r
+        ok = this->m_Graph->RenameVertex(\r
+          old_name.toStdString( ),\r
+          new_name.toStdString( )\r
+          );\r
+        if( ok )\r
+        {\r
+          block->namePort( )->setName( new_name );\r
+          this->m_Workspace->GetGraph( )->RenameVertex(\r
+            old_name.toStdString( ),\r
+            new_name.toStdString( )\r
+            );\r
+\r
+        } // fi\r
+\r
+      } // fi\r
+\r
       /* TODO\r
          auto ports = block->ports( );\r
          std::string name = "";\r