]> Creatis software - cpPlugins.git/blobdiff - libs/cpPipelineEditor/Canvas.cxx
...
[cpPlugins.git] / libs / cpPipelineEditor / Canvas.cxx
index 27312460d8b060d6a9d15e9fc8ae632db8add566..0015421e15ed281a6c328aa050e61970e857dbc0 100644 (file)
@@ -2,7 +2,17 @@
 // @author Leonardo Florez-Valencia (florez-l@javeriana.edu.co)
 // -------------------------------------------------------------------------
 
+
+#include <iostream>
+
+
+
+
+
 #include <cpPipelineEditor/Canvas.h>
+#include <cpPipelineEditor/FilterBlock.h>
+#include <cpPipelineEditor/FunctorBlock.h>
+#include <cpPipelineEditor/WidgetBlock.h>
 
 #include <QDragEnterEvent>
 #include <QTreeWidget>
@@ -24,6 +34,23 @@ cpPipelineEditor::Canvas::
 {
 }
 
+// -------------------------------------------------------------------------
+cpPipelineEditor::Block* cpPipelineEditor::Canvas::
+createBlock( const std::string& name )
+{
+  QString str = name.c_str( );
+  QStringList tokens = str.split( "@" );
+  std::string block_type = tokens.back( ).toStdString( );
+  Block* new_block = NULL;
+  if( block_type == "Filters" )
+    new_block = new FilterBlock( NULL, this->m_Scene );
+  else if( block_type == "Functors" )
+    new_block = new FunctorBlock( NULL, this->m_Scene );
+  else if( block_type == "Widgets" )
+    new_block = new WidgetBlock( NULL, this->m_Scene );
+  return( new_block );
+}
+
 // -------------------------------------------------------------------------
 void cpPipelineEditor::Canvas::
 dragEnterEvent( QDragEnterEvent* event )
@@ -60,21 +87,20 @@ dropEvent( QDropEvent* event )
 
   // Process dropped data
   QList< QTreeWidgetItem* > items = tree->selectedItems( );
-  for(
-    QList< QTreeWidgetItem* >::const_iterator iIt = items.begin( );
-    iIt != items.end( );
-    ++iIt
-    )
+  for( QTreeWidgetItem* item : items )
   {
-    /* TODO
-       auto parent = ( *iIt )->parent( );
-       if( parent != NULL )
-       this->addFilter(
-       parent->text( 0 ).toStdString( ),
-       ( *iIt )->text( 0 ).toStdString( ),
-       p
-       );
-    */
+    std::string name = "";
+    QTreeWidgetItem* p = item;
+    while( p != NULL )
+    {
+      name += p->text( 0 ).toStdString( ) + "@";
+      p = p->parent( );
+
+    } // elihw
+    name.resize( name.size( ) - 1 );
+
+    // Create block
+    Block* b = this->createBlock( name );
 
   } // rof
 }