Go to the documentation of this file.00001 #include "rqt_mrta/config/param_interface.h"
00002 #include "rqt_mrta/config/params.h"
00003 #include "utilities/exception.h"
00004
00005 namespace rqt_mrta
00006 {
00007 namespace config
00008 {
00009 ParamInterface::ParamInterface(const QString& group_name, Params* parent)
00010 : AbstractConfig(parent), group_name_(group_name)
00011 {
00012 }
00013
00014 ParamInterface::~ParamInterface()
00015 {
00016 setParent(NULL);
00017 }
00018
00019 QString ParamInterface::getGroupName() const { return group_name_; }
00020
00021 QString ParamInterface::getName() const { return name_; }
00022
00023 QString ParamInterface::getFullName() const
00024 {
00025 ParamInterface* parent = getParentParam();
00026 return (parent ? parent->getFullName() + "/" : "") + name_;
00027 }
00028
00029 ParamInterface* ParamInterface::getParentParam() const
00030 {
00031 return parent() ? static_cast<ParamInterface*>(parent()) : NULL;
00032 }
00033
00034 void ParamInterface::setName(const QString& name)
00035 {
00036 if (name != name_)
00037 {
00038 QString full_name(getFullName());
00039 name_ = name;
00040 emit nameChanged(full_name, name);
00041 emit changed();
00042 }
00043 }
00044
00045 ParamInterface* ParamInterface::getParam(const QString& full_name) const
00046 {
00047 return NULL;
00048 }
00049
00050 void ParamInterface::addParam(ParamInterface* param)
00051 {
00052 throw utilities::Exception("param tags cannot have another param type tags.");
00053 }
00054
00055 void ParamInterface::removeParam(const QString& param)
00056 {
00057 throw utilities::Exception("param tags do not have another param type tags.");
00058 }
00059
00060 void ParamInterface::clearParams() {}
00061
00062 bool ParamInterface::contains(const QString& name) const { return false; }
00063
00064 size_t ParamInterface::count() const { return 0; }
00065
00066 bool ParamInterface::isEmpty() const { return true; }
00067
00068 QString ParamInterface::validate() const
00069 {
00070 if (name_.isEmpty())
00071 {
00072 return "The ParamInterface name must not be empty.";
00073 }
00074 if (name_.contains(' '))
00075 {
00076 return "The ParamInterface name must not contain <space>.";
00077 }
00078 return "";
00079 }
00080
00081 bool ParamInterface::isParam() const { return false; }
00082
00083 bool ParamInterface::isParams() const { return false; }
00084
00085 bool ParamInterface::isArray() const { return false; }
00086
00087 void ParamInterface::save(QSettings& settings) const
00088 {
00089 settings.setValue("name", name_);
00090 }
00091
00092 void ParamInterface::load(QSettings& settings)
00093 {
00094 setName(settings.value("name").toString());
00095 }
00096
00097 void ParamInterface::reset() {}
00098
00099 void ParamInterface::write(QDataStream& stream) const { stream << name_; }
00100
00101 void ParamInterface::read(QDataStream& stream)
00102 {
00103 QString name;
00104 stream >> name;
00105 setName(name);
00106 }
00107
00108 ParamInterface& ParamInterface::operator=(const ParamInterface& config)
00109 {
00110 setName(config.name_);
00111 return *this;
00112 }
00113
00114 QString ParamInterface::toYaml(const QString& prefix) const
00115 {
00116 return prefix + name_ + ": ";
00117 }
00118
00119 void ParamInterface::paramTypeChanged(const QString& full_name,
00120 const QMetaType::Type& type)
00121 {
00122 emit typeChanged(name_ + "/" + full_name, type);
00123 emit changed();
00124 }
00125
00126 void ParamInterface::paramValueChanged(const QString& full_name,
00127 const QVariant& value)
00128 {
00129 emit valueChanged(name_ + "/" + full_name, value);
00130 emit changed();
00131 }
00132
00133 void ParamInterface::paramDefaultValueChanged(const QString& full_name,
00134 const QVariant& default_value)
00135 {
00136 emit defaultValueChanged(name_ + "/" + full_name, default_value);
00137 emit changed();
00138 }
00139
00140 void ParamInterface::paramToolTipChanged(const QString& full_name,
00141 const QString& tool_tip)
00142 {
00143 emit toolTipChanged(name_ + "/" + full_name, tool_tip);
00144 emit changed();
00145 }
00146 }
00147 }