item_inspector.cpp
Go to the documentation of this file.
00001 #include <pcl/apps/cloud_composer/qt.h>
00002 #include <pcl/apps/cloud_composer/item_inspector.h>
00003 #include <pcl/apps/cloud_composer/items/cloud_composer_item.h>
00004 
00005 
00006 pcl::cloud_composer::ItemInspector::ItemInspector (QWidget* parent)
00007   : QTabWidget(parent)
00008 {
00009   current_item_properties_model_ = 0;
00010   current_project_model_ = 0;
00011   current_selection_model_ = 0;
00012   
00013   parameter_view_ = new QTreeView ();
00014   addTab (parameter_view_, "Parameters");
00015 
00016   
00017 }
00018 
00019 pcl::cloud_composer::ItemInspector::~ItemInspector ()
00020 {
00021   
00022 }
00023 
00024 void
00025 pcl::cloud_composer::ItemInspector::setModel (ProjectModel* new_model)
00026 {
00027   // DISABLED: JUST KEEP TREES ALWAYS EXPANDED
00028    //If we have a model loaded, save its tree state 
00029   //if (current_item_properties_model_)
00030   //  storeTreeState ();
00031   QItemSelectionModel* new_selection_model = new_model->getSelectionModel ();
00032   current_project_model_ = new_model;
00033   
00034   if (current_selection_model_)
00035   {
00036     disconnect (current_selection_model_, SIGNAL (currentChanged (const QModelIndex, const QModelIndex)),
00037                 this, SLOT (selectionChanged (const QModelIndex, const QModelIndex)));
00038     removeTabs ();
00039     
00040   }
00041   current_selection_model_ = new_selection_model;
00042   connect (current_selection_model_, SIGNAL (currentChanged (const QModelIndex, const QModelIndex)),
00043            this, SLOT (selectionChanged (const QModelIndex,const QModelIndex)));
00044   
00045   updateView ();
00046   
00047 }
00048 
00049 void
00050 pcl::cloud_composer::ItemInspector::selectionChanged (const QModelIndex &current, const QModelIndex &)
00051 {
00052   //If we have a model loaded, save its tree state 
00053  // if (current_item_properties_model_)
00054  //   storeTreeState ();
00055   if (current_project_model_)
00056     updateView ();
00057   
00058 }
00059 
00060 void
00061 pcl::cloud_composer::ItemInspector::storeTreeState ()
00062 {
00063   QList <QPersistentModelIndex> expanded_list;
00064   int row_count = current_item_properties_model_->rowCount ();
00065   for (int i = 0; i < row_count ; ++i)
00066   {
00067     QModelIndex index = current_item_properties_model_->index (i, 0);
00068     if (parameter_view_->isExpanded (index))
00069     {
00070       expanded_list <<  QPersistentModelIndex (index);
00071     }
00072   }
00073   // save list
00074   item_treestate_map_.insert (current_item_properties_model_, expanded_list);
00075 }
00076 
00077 void
00078 pcl::cloud_composer::ItemInspector::restoreTreeState ()
00079 {
00080   if (item_treestate_map_.contains (current_item_properties_model_))
00081   {
00082     parameter_view_->setUpdatesEnabled (false);
00083     
00084     foreach (QPersistentModelIndex item_index, item_treestate_map_.value (current_item_properties_model_)) 
00085     {
00086       if (item_index.isValid ())
00087        parameter_view_->setExpanded (item_index, true);
00088     }
00089     parameter_view_->setUpdatesEnabled (true);
00090   }
00091   
00092 }
00093 
00094 void 
00095 pcl::cloud_composer::ItemInspector::itemChanged (QStandardItem *)
00096 {
00097 
00098   
00099 }
00100 
00101 void
00102 pcl::cloud_composer::ItemInspector::removeTabs ()
00103 {
00104   clear ();
00105   addTab (parameter_view_, "Parameters");
00106 }
00107 
00108 void
00109 pcl::cloud_composer::ItemInspector::updateView ()
00110 {
00111 
00112   current_item_properties_model_ = 0;
00113   QModelIndex current_item = current_selection_model_->currentIndex ();
00114   const QStandardItemModel* model = 0;
00115   CloudComposerItem* cloud_item = 0;
00116   if (current_item.isValid ())
00117     model = dynamic_cast<const QStandardItemModel*> (current_item.model ());
00118         
00119   if (model)
00120   {
00121     cloud_item = dynamic_cast<CloudComposerItem*> (model->itemFromIndex (current_item));
00122     if (cloud_item)
00123     {
00124       current_item_properties_model_ = cloud_item->data (ItemDataRole::PROPERTIES).value <PropertiesModel*> ();
00125       //Display any additional graphical data if this item has any
00126       QMap <QString, QWidget*> tabs = cloud_item->getInspectorTabs ();
00127       foreach (QString tab_name, tabs.keys ())
00128       {
00129         addTab (tabs.value (tab_name), tab_name);
00130         tabs.value (tab_name)->show ();
00131       }
00132     }
00133   }
00134       
00135   
00136   parameter_view_->setModel (current_item_properties_model_);
00137   parameter_view_->resizeColumnToContents (0);
00138   // restoreTreeState ();
00139   parameter_view_->expandAll ();
00140 }


pcl
Author(s): Open Perception
autogenerated on Wed Aug 26 2015 15:25:03