Go to the documentation of this file.00001 #include <QStringList>
00002 #include "rqt_mrta/config/includes.h"
00003 #include "rqt_mrta/config/include.h"
00004
00005 namespace rqt_mrta
00006 {
00007 namespace config
00008 {
00009 Includes::Includes(QObject* parent) : AbstractConfig(parent) {}
00010
00011 Includes::~Includes()
00012 {
00013 for (size_t index(0); index < includes_.count(); index++)
00014 {
00015 if (includes_[index])
00016 {
00017 delete includes_[index];
00018 includes_[index] = NULL;
00019 }
00020 }
00021 includes_.clear();
00022 }
00023
00024 Include* Includes::getInclude(size_t index) const
00025 {
00026 return index < includes_.count() ? includes_[index] : NULL;
00027 }
00028
00029 Include* Includes::addInclude()
00030 {
00031 Include* include = new Include(this);
00032 includes_.append(include);
00033 connect(include, SIGNAL(changed()), this, SIGNAL(changed()));
00034 connect(include, SIGNAL(fileChanged(const QString)), this,
00035 SLOT(includeFileChanged(const QString&)));
00036 connect(include, SIGNAL(destroyed()), this, SLOT(includeDestroyed()));
00037 emit added(includes_.count() - 1);
00038 emit changed();
00039 return include;
00040 }
00041
00042 void Includes::removeInclude(Include* include)
00043 {
00044 removeInclude(includes_.indexOf(include));
00045 }
00046
00047 void Includes::removeInclude(size_t index)
00048 {
00049 if (index >= 0 && index < includes_.count())
00050 {
00051 QString file(includes_[index]->getFile());
00052 includes_.remove(index);
00053 emit removed(file);
00054 emit changed();
00055 }
00056 }
00057
00058 void Includes::clearIncludes()
00059 {
00060 if (!includes_.isEmpty())
00061 {
00062 for (size_t index(0); index < includes_.count(); index++)
00063 {
00064 if (includes_[index])
00065 {
00066 delete includes_[index];
00067 includes_[index] = NULL;
00068 }
00069 }
00070 includes_.clear();
00071 emit cleared();
00072 emit changed();
00073 }
00074 }
00075
00076 bool Includes::contains(const QString& file) const
00077 {
00078 for (size_t index(0); index < includes_.count(); index++)
00079 {
00080 if (includes_[index]->getFile() == file)
00081 {
00082 return true;
00083 }
00084 }
00085 return false;
00086 }
00087
00088 size_t Includes::count() const { return includes_.count(); }
00089
00090 bool Includes::isEmpty() const { return includes_.isEmpty(); }
00091
00092 QString Includes::validate() const
00093 {
00094 QString validation;
00095 for (size_t index(0); index < includes_.count(); index++)
00096 {
00097 validation = includes_[index]->validate();
00098 if (!validation.isEmpty())
00099 {
00100 break;
00101 }
00102 }
00103 return validation;
00104 }
00105
00106 QString Includes::toLaunch(const QString &prefix) const
00107 {
00108 QString launch;
00109 for (size_t index(0); index < includes_.count(); index++)
00110 {
00111 launch += includes_[index]->toLaunch(prefix + "\t");
00112 }
00113 return launch;
00114 }
00115
00116 void Includes::save(QSettings& settings) const
00117 {
00118 settings.beginGroup("includes");
00119 for (size_t index(0); index < includes_.count(); index++)
00120 {
00121 settings.beginGroup("include_" + QString::number(index));
00122 includes_[index]->save(settings);
00123 settings.endGroup();
00124 }
00125 settings.endGroup();
00126 }
00127
00128 void Includes::load(QSettings& settings)
00129 {
00130 settings.beginGroup("includes");
00131 QStringList groups(settings.childGroups());
00132 size_t index(0);
00133 for (QStringList::iterator it(groups.begin()); it != groups.end(); it++)
00134 {
00135 Include* include =
00136 index < includes_.count() ? include = includes_[index] : addInclude();
00137 settings.beginGroup(*it);
00138 include->load(settings);
00139 settings.endGroup();
00140 ++index;
00141 }
00142 settings.endGroup();
00143 while (index < includes_.count())
00144 {
00145 removeInclude(index);
00146 }
00147 }
00148
00149 void Includes::reset() { clearIncludes(); }
00150
00151 void Includes::write(QDataStream& stream) const
00152 {
00153 for (size_t index(0); index < includes_.count(); index++)
00154 {
00155 includes_[index]->write(stream);
00156 }
00157 }
00158
00159 void Includes::read(QDataStream& stream)
00160 {
00161 for (size_t index(0); index < includes_.count(); index++)
00162 {
00163 includes_[index]->read(stream);
00164 }
00165 }
00166
00167 Includes& Includes::operator=(const Includes& config)
00168 {
00169 while (includes_.count() < config.includes_.count())
00170 {
00171 addInclude();
00172 }
00173 while (includes_.count() > config.includes_.count())
00174 {
00175 removeInclude(includes_.count() - 1);
00176 }
00177 for (size_t index(0); index < includes_.count(); ++index)
00178 {
00179 *includes_[index] = *config.includes_[index];
00180 }
00181 return *this;
00182 }
00183
00184 void Includes::includeFileChanged(const QString& file)
00185 {
00186 int index(includes_.indexOf(static_cast<Include*>(sender())));
00187 if (index != -1)
00188 {
00189 emit includeFileChanged(index, file);
00190 emit changed();
00191 }
00192 }
00193
00194 void Includes::includeDestroyed()
00195 {
00196 Include* include = static_cast<Include*>(sender());
00197 int index(includes_.indexOf(include));
00198 if (index >= 0)
00199 {
00200 QString file(include->getFile());
00201 includes_.remove(index);
00202 emit removed(file);
00203 emit changed();
00204 }
00205 }
00206 }
00207 }