properties_model.cpp
Go to the documentation of this file.
00001 #include <pcl/apps/cloud_composer/properties_model.h>
00002 #include <pcl/apps/cloud_composer/items/cloud_composer_item.h>
00003 
00004 
00005 pcl::cloud_composer::PropertiesModel::PropertiesModel (QObject* parent)
00006   : QStandardItemModel (parent)
00007 {
00008   setHorizontalHeaderItem (0, new QStandardItem ("Name"));
00009   setHorizontalHeaderItem (1, new QStandardItem ("Value"));
00010 
00011   
00012 }
00013 
00014 pcl::cloud_composer::PropertiesModel::PropertiesModel (CloudComposerItem* parent_item, QObject* parent)
00015   : QStandardItemModel (parent)
00016   , parent_item_ (parent_item)
00017 {
00018   setHorizontalHeaderItem (0, new QStandardItem ("Name"));
00019   setHorizontalHeaderItem (1, new QStandardItem ("Value"));
00020   
00021   connect (this, SIGNAL (itemChanged (QStandardItem*)),
00022            this, SLOT (propertyChanged (QStandardItem*)));
00023   
00024 }
00025 
00026 pcl::cloud_composer::PropertiesModel::PropertiesModel (const PropertiesModel& to_copy)
00027   : QStandardItemModel ()
00028 {
00029   for (int i=0; i < to_copy.rowCount (); ++i){
00030     QList <QStandardItem*> new_row;
00031     QStandardItem* parent = to_copy.item(i,0);
00032     QModelIndex parent_index = to_copy.index(i,0);
00033     new_row.append (parent->clone ());
00034     for (int j=0; j < to_copy.columnCount (parent_index); ++j)
00035     {
00036       if (to_copy.item (i,j))      
00037         new_row.append (to_copy.item(i,j)->clone ());
00038     }
00039     appendRow (new_row);
00040   }
00041 }
00042 
00043 pcl::cloud_composer::PropertiesModel::~PropertiesModel ()
00044 {
00045   
00046 }
00047 
00048 void
00049 pcl::cloud_composer::PropertiesModel::addProperty (const QString prop_name, QVariant value,  Qt::ItemFlags flags, QString category)
00050 {
00051   QStandardItem* parent_item = invisibleRootItem ();
00052   if (category.size () > 0)
00053   {
00054     QList<QStandardItem*> items = findItems (category);
00055     if (items.size () == 0)
00056       qWarning () << "No category named "<<prop_name<<" found in "<<parent_item_->text ()<<" adding to root";
00057     else if (items.size () > 1)
00058       qCritical () << "Multiple categories with same name found!! This is not good...";
00059     else
00060       parent_item = items.at (0);
00061   }
00062 
00063   QList <QStandardItem*> new_row;
00064   QStandardItem* new_property = new QStandardItem (prop_name);
00065   new_property->setFlags (Qt::ItemIsSelectable);
00066   new_row.append (new_property);
00067   
00068   QStandardItem* new_value = new QStandardItem ();
00069   new_value->setFlags (flags);
00070   new_value->setData (value, Qt::EditRole);
00071   new_row.append (new_value);
00072  
00073   parent_item->appendRow (new_row);
00074 }
00075 
00076 void
00077 pcl::cloud_composer::PropertiesModel::addCategory (const QString category_name)
00078 {
00079   QStandardItem* new_category = new QStandardItem (category_name);
00080   appendRow (new_category);
00081 }
00082 
00083 QVariant 
00084 pcl::cloud_composer::PropertiesModel::getProperty (const QString prop_name) const
00085 {
00086   //qDebug () << "Searching for property " << prop_name;
00087   QList<QStandardItem*> items = findItems (prop_name, Qt::MatchExactly | Qt::MatchRecursive, 0);
00088   if (items.size () == 0)
00089   {
00090     qWarning () << "No property named "<<prop_name<<" found in "<<parent_item_->text ();
00091     return QVariant ();
00092   }
00093   else if (items.size () > 1)
00094   {
00095     qWarning () << "Multiple properties found with name "<<prop_name<<" in "<<parent_item_->text ();
00096   }
00097  // qDebug () << "Found properties size ="<<items.size ();
00098   
00099   QStandardItem* property = items.value (0);
00100  // qDebug () << "Prop name="<<prop_name<<" row="<<property->row ()<<" col="<<property->column();
00101   int row = property->row ();
00102   QStandardItem* parent_item = property->parent ();
00103   if (parent_item == 0)
00104     parent_item = invisibleRootItem ();
00105   return parent_item->child (row,1)->data (Qt::EditRole);
00106 }
00107 
00108 void
00109 pcl::cloud_composer::PropertiesModel::copyProperties (const PropertiesModel* to_copy)
00110 {
00111   for (int i=0; i < to_copy->rowCount (); ++i){
00112     QList <QStandardItem*> new_row;
00113     QStandardItem* parent = to_copy->item(i,0);
00114     QModelIndex parent_index = to_copy->index(i,0);
00115     qDebug () << "Copying "<<parent->text()<< " cols ="<<to_copy->columnCount ();
00116     new_row.append (parent->clone ());
00117     for (int j=1; j < to_copy->columnCount (); ++j)
00118     {
00119       if (to_copy->item (i,j))      
00120       {
00121         new_row.append (to_copy->item(i,j)->clone ());
00122       }
00123     }
00124     appendRow (new_row);
00125     
00126   }
00127 }
00128 
00129 
00130 void
00131 pcl::cloud_composer::PropertiesModel::propertyChanged (QStandardItem* property_item)
00132 {
00133   //qDebug () << "Property Changed in properties model";
00134   parent_item_->propertyChanged ();
00135   
00136 }


pcl
Author(s): Open Perception
autogenerated on Wed Aug 26 2015 15:31:34