launch.cpp
Go to the documentation of this file.
00001 #include <QFileInfo>
00002 #include "rqt_mrta/config/launch.h"
00003 #include "rqt_mrta/config/includes.h"
00004 #include "utilities/exception.h"
00005 
00006 namespace rqt_mrta
00007 {
00008 namespace config
00009 {
00010 Launch::Launch(QObject* parent)
00011     : AbstractConfig(parent), includes_(new Includes(this))
00012 {
00013   reset();
00014   connect(includes_, SIGNAL(changed()), this, SIGNAL(changed()));
00015 }
00016 
00017 Launch::~Launch()
00018 {
00019   if (includes_)
00020   {
00021     delete includes_;
00022     includes_ = NULL;
00023   }
00024 }
00025 
00026 QString Launch::getId() const { return id_; }
00027 
00028 Includes* Launch::getIncludes() const { return includes_; }
00029 
00030 QMap<QString, QString> Launch::getMap() const { return map_; }
00031 
00032 void Launch::setId(const QString& id)
00033 {
00034   if (id != id_)
00035   {
00036     id_ = id;
00037     emit idChanged(id);
00038     emit changed();
00039   }
00040 }
00041 
00042 void Launch::add(const QString& key, const QString& value)
00043 {
00044   map_[(!key.startsWith('@') ? "@" : "") + key + (!key.endsWith('@') ? "@" : "")] = value;
00045 }
00046 
00047 QString Launch::validate() const
00048 {
00049   if (id_.contains(' '))
00050   {
00051     return "The launch file id must not have <space>.";
00052   }
00053   return includes_->validate();
00054 }
00055 
00056 void Launch::save(QSettings& settings) const
00057 {
00058   settings.setValue("id", id_);
00059   includes_->save(settings);
00060 }
00061 
00062 void Launch::load(QSettings& settings)
00063 {
00064   setId(settings.value("id").toString());
00065   includes_->load(settings);
00066 }
00067 
00068 void Launch::reset()
00069 {
00070   setId("");
00071   includes_->reset();
00072 }
00073 
00074 void Launch::write(QDataStream& stream) const
00075 {
00076   stream << id_;
00077   includes_->write(stream);
00078 }
00079 
00080 void Launch::read(QDataStream& stream)
00081 {
00082   QString id;
00083   stream >> id;
00084   setId(id);
00085   includes_->read(stream);
00086 }
00087 
00088 Launch& Launch::operator=(const Launch& config)
00089 {
00090   setId(config.id_);
00091   *includes_ = *config.includes_;
00092   return *this;
00093 }
00094 
00095 void Launch::saveAsLaunch(const QString& url) const
00096 {
00097   QFile file(url + ".launch");
00098   if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
00099   {
00100     ROS_ERROR_STREAM("Unable to open the " << url.toStdString()
00101                                            << ".launch file.");
00102     return;
00103   }
00104   file.write(toLaunch().toStdString().c_str());
00105   file.close();
00106   ROS_INFO_STREAM("Created the " << url.toStdString() << ".launch file.");
00107 }
00108 
00109 QString Launch::toLaunch() const
00110 {
00111   QString launch;
00112   launch += "<?xml version=\"1.0\"?>\n";
00113   launch += "<launch>\n";
00114   launch += includes_->toLaunch();
00115   launch += "</launch>\n";
00116   for (const_iterator it(map_.constBegin()); it != map_.constEnd(); it++)
00117   {
00118     launch.replace(it.key(), it.value());
00119   }
00120   return launch;
00121 }
00122 }
00123 }


rqt_mrta
Author(s): Adriano Henrique Rossette Leite
autogenerated on Thu Jun 6 2019 18:50:52