widgets.cpp
Go to the documentation of this file.
00001 #include <QStringList>
00002 #include "rqt_mrta/config/architecture/widgets.h"
00003 
00004 namespace rqt_mrta
00005 {
00006 namespace config
00007 {
00008 namespace architecture
00009 {
00010 Widgets::Widgets(QObject* parent) : AbstractConfig(parent) {}
00011 
00012 Widgets::~Widgets()
00013 {
00014   for (size_t index(0); index < widgets_.count(); index++)
00015   {
00016     if (widgets_[index])
00017     {
00018       delete widgets_[index];
00019       widgets_[index] = NULL;
00020     }
00021   }
00022   widgets_.clear();
00023 }
00024 
00025 size_t Widgets::count() const { return widgets_.count(); }
00026 
00027 Widget* Widgets::getWidget(size_t index) const
00028 {
00029   return index < widgets_.count() ? widgets_[index] : NULL;
00030 }
00031 
00032 Widget* Widgets::addWidget()
00033 {
00034   Widget* widget = new Widget(this);
00035   widgets_.append(widget);
00036   connect(widget, SIGNAL(changed()), this, SLOT(widgetChanged()));
00037   connect(widget, SIGNAL(pluginNameChanged(const QString&)), this,
00038           SLOT(widgetPluginNameChanged(const QString&)));
00039   connect(widget, SIGNAL(destroyed()), this, SLOT(widgetDestroyed()));
00040   emit added(widgets_.count() - 1);
00041   emit changed();
00042   return widget;
00043 }
00044 
00045 void Widgets::clearWidgets()
00046 {
00047   if (!widgets_.isEmpty())
00048   {
00049     for (size_t i(0); i < widgets_.count(); ++i)
00050     {
00051       if (widgets_[i])
00052       {
00053         delete widgets_[i];
00054         widgets_[i] = NULL;
00055       }
00056     }
00057     widgets_.clear();
00058     emit cleared();
00059     emit changed();
00060   }
00061 }
00062 
00063 void Widgets::save(QSettings& settings) const
00064 {
00065   settings.beginGroup("widgets");
00066   for (size_t index(0); index < widgets_.count(); ++index)
00067   {
00068     settings.beginGroup("widget_" + QString::number(index));
00069     widgets_[index]->save(settings);
00070     settings.endGroup();
00071   }
00072   settings.endGroup();
00073 }
00074 
00075 void Widgets::load(QSettings& settings)
00076 {
00077   settings.beginGroup("widgets");
00078   QStringList groups(settings.childGroups());
00079   size_t index(0);
00080   clearWidgets();
00081   for (QStringList::iterator it = groups.begin(); it != groups.end(); ++it)
00082   {
00083     Widget* widget = addWidget();
00084     settings.beginGroup(*it);
00085     widget->load(settings);
00086     settings.endGroup();
00087     ++index;
00088   }
00089   settings.endGroup();
00090 }
00091 
00092 void Widgets::reset() { clearWidgets(); }
00093 
00094 void Widgets::write(QDataStream& stream) const
00095 {
00096   for (size_t index(0); index < widgets_.count(); ++index)
00097   {
00098     widgets_[index]->write(stream);
00099   }
00100 }
00101 
00102 void Widgets::read(QDataStream& stream)
00103 {
00104   for (size_t index(0); index < widgets_.count(); ++index)
00105   {
00106     widgets_[index]->read(stream);
00107   }
00108 }
00109 
00110 Widgets& Widgets::operator=(const Widgets& config)
00111 {
00112   while (widgets_.count() < config.widgets_.count())
00113   {
00114     addWidget();
00115   }
00116   while (widgets_.count() > config.widgets_.count())
00117   {
00118     removeWidget(widgets_.count() - 1);
00119   }
00120   for (size_t index(0); index < widgets_.count(); ++index)
00121   {
00122     *widgets_[index] = *config.widgets_[index];
00123   }
00124   return *this;
00125 }
00126 
00127 void Widgets::widgetChanged()
00128 {
00129   for (size_t index(0); index < widgets_.count(); ++index)
00130   {
00131     if (widgets_[index] == sender())
00132     {
00133       emit widgetChanged(index);
00134       break;
00135     }
00136   }
00137   emit changed();
00138 }
00139 
00140 void Widgets::widgetPluginNameChanged(const QString& plugin_name)
00141 {
00142   Widget* widget = static_cast<Widget*>(sender());
00143   int index(widgets_.indexOf(widget));
00144   if (index != -1)
00145   {
00146     emit widgetPluginNameChanged(index, plugin_name);
00147     emit changed();
00148   }
00149 }
00150 
00151 void Widgets::widgetDestroyed()
00152 {
00153   int index(widgets_.indexOf(static_cast<Widget*>(sender())));
00154   if (index >= 0)
00155   {
00156     widgets_.remove(index);
00157     emit removed(index);
00158     emit changed();
00159   }
00160 }
00161 }
00162 }
00163 }


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