]> Creatis software - cpPlugins.git/blobdiff - appli/PipelineEditor/PluginsNavigator.cxx
Moved to version 1.0
[cpPlugins.git] / appli / PipelineEditor / PluginsNavigator.cxx
diff --git a/appli/PipelineEditor/PluginsNavigator.cxx b/appli/PipelineEditor/PluginsNavigator.cxx
new file mode 100644 (file)
index 0000000..305d746
--- /dev/null
@@ -0,0 +1,88 @@
+// =========================================================================
+// @author Leonardo Florez-Valencia (florez-l@javeriana.edu.co)
+// =========================================================================
+
+#include "PluginsNavigator.h"
+#include <boost/tokenizer.hpp>
+
+// -------------------------------------------------------------------------
+PluginsNavigator::
+PluginsNavigator( QWidget* parent )
+  : Superclass( parent )
+{
+  this->m_PlgMgr.Configure( );
+
+  this->setDragEnabled( true );
+  this->setDragDropMode( QAbstractItemView::DragOnly );
+  this->setAlternatingRowColors( true );
+  this->Update( );
+}
+
+// -------------------------------------------------------------------------
+PluginsNavigator::
+~PluginsNavigator( )
+{
+}
+
+// -------------------------------------------------------------------------
+void PluginsNavigator::
+Update( )
+{
+  this->_Clear( );
+  this->_Update( );
+}
+
+// -------------------------------------------------------------------------
+void PluginsNavigator::
+_Clear( )
+{
+  this->clear( );
+  this->setColumnCount( 1 );
+  QString header_txt = "Plugins";
+  if( QTreeWidgetItem* header = this->headerItem( ) )
+    header->setText( 0, header_txt );
+  else
+    this->setHeaderLabel( header_txt );
+}
+
+// -------------------------------------------------------------------------
+void PluginsNavigator::
+_Update( )
+{
+  typedef boost::char_separator< char > _TSep;
+  typedef boost::tokenizer< _TSep > _TTok;
+  typedef cpPlugins::Interface::Manager::TPlugins _TPlugins;
+  typedef _TPlugins::value_type _TPlg;
+
+  for( const _TPlg& plg: this->m_PlgMgr.GetPlugins( ) )
+  {
+    _TSep sep{ ":" };
+    _TTok tokens{ plg.first, sep };
+    QTreeWidgetItem* cat = NULL;
+    for( const std::string& t: tokens )
+    {
+      QList< QTreeWidgetItem* > cat_items;
+
+      /* TODO
+         if( cat != NULL )
+         cat_items =
+         cat->findItems( t.c_str( ), Qt::MatchExactly | Qt::MatchRecursive );
+         else
+      */
+      cat_items =
+        this->findItems( t.c_str( ), Qt::MatchExactly | Qt::MatchRecursive );
+      if( cat_items.size( ) == 0 )
+      {
+        bool prev = ( cat == NULL );
+        cat = new QTreeWidgetItem( cat, QStringList( t.c_str( ) ) );
+        if( prev )
+          this->addTopLevelItem( cat );
+      }
+      else
+        cat = cat_items[ 0 ];
+    } // rof
+  } // rof
+  this->expandAll( );
+}
+
+// eof - $RCSfile$