]> sigrok.org Git - pulseview.git/blobdiff - pv/prop/binding/binding.cpp
Added support for auto-apply in Binding
[pulseview.git] / pv / prop / binding / binding.cpp
index 9455ad5905258d00bb4c1c7518610754490ab291..afdd7030a2a694b889cfe799fcc29cb2edd8c1a2 100644 (file)
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
  */
 
-#include <QFormLayout>
-#include <QWidget>
-
 #include <boost/foreach.hpp>
 
-#include "binding.h"
+#include <QFormLayout>
 
 #include <pv/prop/property.h>
 
+#include "binding.h"
+
 using namespace boost;
 
 namespace pv {
 namespace prop {
 namespace binding {
 
-Binding::Binding() :
-       _form(NULL)
+const std::vector< boost::shared_ptr<Property> >& Binding::properties()
 {
+       return _properties;
 }
 
-QWidget* Binding::get_form(QWidget *parent)
+void Binding::commit()
 {
-       if(_form)
-               return _form;
-
-       _form = new QWidget(parent);
-       QFormLayout *const layout = new QFormLayout(_form);
-       _form->setLayout(layout);
-
-       BOOST_FOREACH(shared_ptr<Property> p, _properties)
-       {
+       BOOST_FOREACH(shared_ptr<pv::prop::Property> p, _properties) {
                assert(p);
-               layout->addRow(p->name(), p->get_widget(_form));
+               p->commit();
        }
-
-       return _form;
 }
 
-void Binding::commit()
+void Binding::add_properties_to_form(QFormLayout *layout,
+       bool auto_commit) const
 {
-       BOOST_FOREACH(shared_ptr<Property> p, _properties)
+       assert(layout);
+
+       BOOST_FOREACH(shared_ptr<pv::prop::Property> p, _properties)
        {
                assert(p);
-               p->commit();
+               const QString label = p->labeled_widget() ? QString() : p->name();
+               layout->addRow(label, p->get_widget(layout->parentWidget(),
+                       auto_commit));
        }
 }
 
+QWidget* Binding::get_property_form(QWidget *parent,
+       bool auto_commit) const
+{
+       QWidget *const form = new QWidget(parent);
+       QFormLayout *const layout = new QFormLayout(form);
+       form->setLayout(layout);
+       add_properties_to_form(layout, auto_commit);
+       return form;
+}
+
 } // binding
 } // prop
 } // pv