00001 #include "rqt_mrta/config/param.h" 00002 #include "rqt_mrta/config/params.h" 00003 #include "rqt_mrta/param_item.h" 00004 00005 namespace rqt_mrta 00006 { 00007 00008 ParamItem::ParamItem(config::Param* param, ParamItem* parent) 00009 : parent_(parent), param_(param) 00010 { 00011 } 00012 00013 ParamItem::ParamItem(config::Params* params, ParamItem* parent) 00014 : parent_(parent), param_(params) 00015 { 00016 for (size_t index(0); index < params->count(); index++) 00017 { 00018 config::ParamInterface* param = params->getChild(index); 00019 ParamItem* item = 00020 param->isEmpty() 00021 ? new ParamItem(static_cast<config::Param*>(param), this) 00022 : new ParamItem(static_cast<config::Params*>(param), this); 00023 appendChild(item); 00024 } 00025 } 00026 00027 ParamItem::~ParamItem() 00028 { 00029 param_ = NULL; 00030 parent_ = NULL; 00031 for (QList<ParamItem*>::iterator it(children_.begin()); it != children_.end(); 00032 ++it) 00033 { 00034 if (*it) 00035 { 00036 delete *it; 00037 *it = NULL; 00038 } 00039 } 00040 children_.clear(); 00041 } 00042 00043 config::ParamInterface* ParamItem::getParam() const { return param_; } 00044 00045 ParamItem* ParamItem::getParent() const { return parent_; } 00046 00047 size_t ParamItem::getNumChildren() const { return children_.count(); } 00048 00049 ParamItem* ParamItem::getChild(size_t row) const 00050 { 00051 return children_.value(row); 00052 } 00053 00054 ParamItem* ParamItem::getChild(const QString& full_name) const 00055 { 00056 for (QList<ParamItem*>::const_iterator it(children_.begin()); 00057 it != children_.end(); ++it) 00058 { 00059 ParamItem* item = *it; 00060 if (item->getFullName() == full_name) 00061 { 00062 return item; 00063 } 00064 } 00065 return NULL; 00066 } 00067 00068 bool ParamItem::isLeaf() const { return children_.isEmpty(); } 00069 00070 int ParamItem::getRow() const 00071 { 00072 return parent_ ? parent_->children_.indexOf(const_cast<ParamItem*>(this)) 00073 : -1; 00074 } 00075 00076 size_t ParamItem::getNumColumns() const { return 2; } 00077 00078 QString ParamItem::getFullName() const { return param_->getFullName(); } 00079 00080 void ParamItem::appendChild(ParamItem* child) { children_.append(child); } 00081 }