Go to the documentation of this file.00001 #include "rqt_mrta/config/application/robot.h"
00002 #include "rqt_mrta/config/application/tasks.h"
00003
00004 namespace rqt_mrta
00005 {
00006 namespace config
00007 {
00008 namespace application
00009 {
00010 Robot::Robot(QObject* parent)
00011 : AbstractConfig(parent), tasks_(new Tasks(this))
00012 {
00013 connect(tasks_, SIGNAL(changed()), this, SIGNAL(changed()));
00014 connect(tasks_, SIGNAL(taskIdChanged(size_t, const QString&)), this,
00015 SLOT(taskChanged(size_t, const QString&)));
00016 connect(tasks_, SIGNAL(added(size_t)), this, SLOT(taskAdded(size_t)));
00017 connect(tasks_, SIGNAL(removed(const QString&)), this,
00018 SLOT(taskRemoved(const QString&)));
00019 connect(tasks_, SIGNAL(cleared()), this, SLOT(tasksCleared()));
00020 }
00021
00022 Robot::~Robot()
00023 {
00024 if (tasks_)
00025 {
00026 delete tasks_;
00027 tasks_ = NULL;
00028 }
00029 }
00030
00031 QString Robot::getId() const { return id_; }
00032
00033 Tasks* Robot::getTasks() const { return tasks_; }
00034
00035 void Robot::setId(const QString& id)
00036 {
00037 if (id != id_)
00038 {
00039 id_ = id;
00040 emit idChanged(id);
00041 emit changed();
00042 }
00043 }
00044
00045 void Robot::save(QSettings& settings) const
00046 {
00047 settings.setValue("id", id_);
00048 tasks_->save(settings);
00049 }
00050
00051 void Robot::load(QSettings& settings)
00052 {
00053 setId(settings.value("id").toString());
00054 tasks_->load(settings);
00055 }
00056
00057 void Robot::reset()
00058 {
00059 setId("");
00060 tasks_->reset();
00061 }
00062
00063 void Robot::write(QDataStream& stream) const
00064 {
00065 stream << id_;
00066 tasks_->write(stream);
00067 }
00068
00069 void Robot::read(QDataStream& stream)
00070 {
00071 QString id;
00072 stream >> id;
00073 setId(id);
00074 tasks_->read(stream);
00075 }
00076
00077 Robot& Robot::operator=(const Robot& config)
00078 {
00079 setId(config.id_);
00080 *tasks_ = *config.tasks_;
00081 return *this;
00082 }
00083
00084 QString Robot::validate() const
00085 {
00086 if (id_.isEmpty())
00087 {
00088 return "The robot id must not be empty.";
00089 }
00090 if (id_.contains(' '))
00091 {
00092 return "The robot id must not contain <space>.";
00093 }
00094 return tasks_->validate();
00095 }
00096
00097 void Robot::taskChanged(size_t task_index, const QString& task_id)
00098 {
00099 emit taskIdChanged(task_index, task_id);
00100 }
00101
00102 void Robot::taskAdded(size_t task_index) { emit added(task_index); }
00103
00104 void Robot::taskRemoved(const QString& task_id) { emit removed(task_id); }
00105
00106 void Robot::tasksCleared() { emit cleared(); }
00107 }
00108 }
00109 }