Go to the documentation of this file.00001 #include <QFileInfo>
00002 #include <ros/console.h>
00003 #include "rqt_mrta/config/application/rqt_mrta_application.h"
00004 #include "utilities/exception.h"
00005 #include "utilities/simple_xml_settings.h"
00006
00007 namespace rqt_mrta
00008 {
00009 namespace config
00010 {
00011 namespace application
00012 {
00013 RqtMrtaApplication::RqtMrtaApplication(QObject* parent)
00014 : AbstractConfig(parent), application_(new Application(this)),
00015 configs_(new Configs(this)), launches_(new Launches(this))
00016 {
00017 reset();
00018 connect(application_, SIGNAL(changed()), this, SIGNAL(changed()));
00019 connect(configs_, SIGNAL(changed()), this, SIGNAL(changed()));
00020 connect(launches_, SIGNAL(changed()), this, SIGNAL(changed()));
00021 }
00022
00023 RqtMrtaApplication::~RqtMrtaApplication()
00024 {
00025 if (application_)
00026 {
00027 delete application_;
00028 application_ = NULL;
00029 }
00030 if (configs_)
00031 {
00032 delete configs_;
00033 configs_ = NULL;
00034 }
00035 if (launches_)
00036 {
00037 delete launches_;
00038 launches_ = NULL;
00039 }
00040 }
00041
00042 QString RqtMrtaApplication::getApplicationPackage() const { return package_; }
00043
00044 QString RqtMrtaApplication::getApplicationPackageUrl() const { return url_; }
00045
00046 Application* RqtMrtaApplication::getApplication() const { return application_; }
00047
00048 Configs* RqtMrtaApplication::getConfigs() const { return configs_; }
00049
00050 Launches *RqtMrtaApplication::getLaunches() const
00051 {
00052 return launches_;
00053 }
00054
00055 void RqtMrtaApplication::setApplicationPackage(const QString& package)
00056 {
00057 if (package != package_)
00058 {
00059 package_ = package;
00060 emit applicationPackageChanged(package);
00061 emit changed();
00062 }
00063 }
00064
00065 void RqtMrtaApplication::setApplicationPackageUrl(const QString& url)
00066 {
00067 if (url != url_)
00068 {
00069 ROS_ERROR_STREAM("[RqtMrtaApplication::setApplicationPackageUrl] url: " << url.toStdString());
00070 url_ = url;
00071 emit applicationPackageUrlChanged(url);
00072 emit changed();
00073 }
00074 }
00075
00076 void RqtMrtaApplication::save() const { save("rqt_mrta.xml"); }
00077
00078 void RqtMrtaApplication::save(const QString& filename) const
00079 {
00080 if (url_.isEmpty() || filename.isEmpty())
00081 {
00082 ROS_ERROR(
00083 "[RqtMrtaApplication] unable to save application rqt_mrta.xml file.");
00084 return;
00085 }
00086 QString url(url_ + "/" + filename);
00087 QSettings settings(url, utilities::SimpleXmlSettings::format);
00088 if (settings.isWritable())
00089 {
00090 settings.clear();
00091 save(settings);
00092 settings.sync();
00093 if (settings.status() != QSettings::NoError)
00094 {
00095 ROS_ERROR("This application configuration file cannot be saved.");
00096 return;
00097 }
00098 ROS_INFO_STREAM("Saved application configuration file ["
00099 << url.toStdString() << "].");
00100 }
00101 }
00102
00103 void RqtMrtaApplication::save(QSettings& settings) const
00104 {
00105 settings.beginGroup("rqt_mrta");
00106
00107 application_->save(settings);
00108 configs_->save(settings);
00109 launches_->save(settings);
00110 settings.endGroup();
00111 }
00112
00113 void RqtMrtaApplication::load(const QString& url)
00114 {
00115 QFileInfo file_info(url);
00116 if (!file_info.isReadable())
00117 {
00118 return;
00119 }
00120 QSettings settings(url, utilities::SimpleXmlSettings::format);
00121 if (settings.status() != QSettings::NoError)
00122 {
00123 ROS_ERROR("This application configuration file cannot be loaded.");
00124 return;
00125 }
00126 load(settings);
00127 ROS_INFO_STREAM("Loaded application configuration file ["
00128 << url.toStdString() << "].");
00129 }
00130
00131 void RqtMrtaApplication::load(QSettings& settings)
00132 {
00133 settings.beginGroup("rqt_mrta");
00134 QString type(settings.value("@format").toString());
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148 application_->load(settings);
00149 configs_->load(settings);
00150 launches_->load(settings);
00151 settings.endGroup();
00152 }
00153
00154 void RqtMrtaApplication::reset()
00155 {
00156 setApplicationPackage("");
00157 setApplicationPackageUrl("");
00158 application_->reset();
00159 configs_->reset();
00160 launches_->reset();
00161 }
00162
00163 void RqtMrtaApplication::write(QDataStream& stream) const
00164 {
00165 application_->write(stream);
00166 configs_->write(stream);
00167 launches_->write(stream);
00168 }
00169
00170 void RqtMrtaApplication::read(QDataStream& stream)
00171 {
00172 application_->read(stream);
00173 configs_->read(stream);
00174 launches_->read(stream);
00175 }
00176
00177 RqtMrtaApplication& RqtMrtaApplication::
00178 operator=(const RqtMrtaApplication& config)
00179 {
00180 setApplicationPackage(config.package_);
00181 setApplicationPackageUrl(config.url_);
00182 *application_ = *config.application_;
00183 *configs_ = *config.configs_;
00184 *launches_ = *config.launches_;
00185 return *this;
00186 }
00187 }
00188 }
00189 }