]> Creatis software - cpPlugins.git/blob - appli/PipelineEditor/PluginsNavigator.cxx
Moved to version 1.0
[cpPlugins.git] / appli / PipelineEditor / PluginsNavigator.cxx
1 // =========================================================================
2 // @author Leonardo Florez-Valencia (florez-l@javeriana.edu.co)
3 // =========================================================================
4
5 #include "PluginsNavigator.h"
6 #include <boost/tokenizer.hpp>
7
8 // -------------------------------------------------------------------------
9 PluginsNavigator::
10 PluginsNavigator( QWidget* parent )
11   : Superclass( parent )
12 {
13   this->m_PlgMgr.Configure( );
14
15   this->setDragEnabled( true );
16   this->setDragDropMode( QAbstractItemView::DragOnly );
17   this->setAlternatingRowColors( true );
18   this->Update( );
19 }
20
21 // -------------------------------------------------------------------------
22 PluginsNavigator::
23 ~PluginsNavigator( )
24 {
25 }
26
27 // -------------------------------------------------------------------------
28 void PluginsNavigator::
29 Update( )
30 {
31   this->_Clear( );
32   this->_Update( );
33 }
34
35 // -------------------------------------------------------------------------
36 void PluginsNavigator::
37 _Clear( )
38 {
39   this->clear( );
40   this->setColumnCount( 1 );
41   QString header_txt = "Plugins";
42   if( QTreeWidgetItem* header = this->headerItem( ) )
43     header->setText( 0, header_txt );
44   else
45     this->setHeaderLabel( header_txt );
46 }
47
48 // -------------------------------------------------------------------------
49 void PluginsNavigator::
50 _Update( )
51 {
52   typedef boost::char_separator< char > _TSep;
53   typedef boost::tokenizer< _TSep > _TTok;
54   typedef cpPlugins::Interface::Manager::TPlugins _TPlugins;
55   typedef _TPlugins::value_type _TPlg;
56
57   for( const _TPlg& plg: this->m_PlgMgr.GetPlugins( ) )
58   {
59     _TSep sep{ ":" };
60     _TTok tokens{ plg.first, sep };
61     QTreeWidgetItem* cat = NULL;
62     for( const std::string& t: tokens )
63     {
64       QList< QTreeWidgetItem* > cat_items;
65
66       /* TODO
67          if( cat != NULL )
68          cat_items =
69          cat->findItems( t.c_str( ), Qt::MatchExactly | Qt::MatchRecursive );
70          else
71       */
72       cat_items =
73         this->findItems( t.c_str( ), Qt::MatchExactly | Qt::MatchRecursive );
74       if( cat_items.size( ) == 0 )
75       {
76         bool prev = ( cat == NULL );
77         cat = new QTreeWidgetItem( cat, QStringList( t.c_str( ) ) );
78         if( prev )
79           this->addTopLevelItem( cat );
80       }
81       else
82         cat = cat_items[ 0 ];
83     } // rof
84   } // rof
85   this->expandAll( );
86 }
87
88 // eof - $RCSfile$