]> sigrok.org Git - pulseview.git/commitdiff
Added auto-commit support to properties
authorJoel Holdsworth <redacted>
Sat, 12 Oct 2013 11:17:10 +0000 (12:17 +0100)
committerJoel Holdsworth <redacted>
Sun, 13 Oct 2013 11:39:43 +0000 (12:39 +0100)
12 files changed:
CMakeLists.txt
pv/prop/bool.cpp
pv/prop/bool.h
pv/prop/double.cpp
pv/prop/double.h
pv/prop/enum.cpp
pv/prop/enum.h
pv/prop/int.cpp
pv/prop/int.h
pv/prop/property.h
pv/prop/string.cpp
pv/prop/string.h

index 43208aae80f1f51fdc38b3b2c4d8e77b6a451371..2ea44dba08084bf4d3bcc15f385f3d5ea7c1f873 100644 (file)
@@ -159,6 +159,12 @@ set(pulseview_HEADERS
        pv/dialogs/connect.h
        pv/popups/deviceoptions.h
        pv/popups/probes.h
+       pv/prop/bool.h
+       pv/prop/double.h
+       pv/prop/enum.h
+       pv/prop/int.h
+       pv/prop/property.h
+       pv/prop/string.h
        pv/toolbars/samplingbar.h
        pv/view/cursor.h
        pv/view/decodesignal.h
index ad9a13e7c0e05bc710fc7d385b6ad7e6b22a04be..179208a5e1c927b74de3469b3aca4a8d3634d453 100644 (file)
@@ -40,7 +40,7 @@ Bool::~Bool()
 {
 }
 
-QWidget* Bool::get_widget(QWidget *parent)
+QWidget* Bool::get_widget(QWidget *parent, bool auto_commit)
 {
        if (_check_box)
                return _check_box;
@@ -55,6 +55,10 @@ QWidget* Bool::get_widget(QWidget *parent)
                g_variant_unref(value);
        }
 
+       if (auto_commit)
+               connect(_check_box, SIGNAL(stateChanged(int)),
+                       this, SLOT(on_state_changed(int)));
+
        return _check_box;
 }
 
@@ -74,5 +78,10 @@ void Bool::commit()
                _check_box->checkState() == Qt::Checked));
 }
 
+void Bool::on_state_changed(int)
+{
+       commit();
+}
+
 } // prop
 } // pv
index 22fc95cc8c2827305491bacd6f21e6602f0a6b27..0d8e205e87a682976b417e3b796fc7ca0e16eb9f 100644 (file)
@@ -30,16 +30,21 @@ namespace prop {
 
 class Bool : public Property
 {
+       Q_OBJECT;
+
 public:
        Bool(QString name, Getter getter, Setter setter);
 
        virtual ~Bool();
 
-       QWidget* get_widget(QWidget *parent);
+       QWidget* get_widget(QWidget *parent, bool auto_commit);
        bool labeled_widget() const;
 
        void commit();
 
+private slots:
+       void on_state_changed(int);
+
 private:
        QCheckBox *_check_box;
 };
index 39e205ee691f2910dd7899ac958ae5d9c69bde3f..188286ae1c4ff08a22687c0ac11704c69920ff23 100644 (file)
@@ -50,7 +50,7 @@ Double::~Double()
 {
 }
 
-QWidget* Double::get_widget(QWidget *parent)
+QWidget* Double::get_widget(QWidget *parent, bool auto_commit)
 {
        if (_spin_box)
                return _spin_box;
@@ -70,6 +70,10 @@ QWidget* Double::get_widget(QWidget *parent)
                g_variant_unref(value);
        }
 
+       if (auto_commit)
+               connect(_spin_box, SIGNAL(valueChanged(double)),
+                       this, SLOT(on_value_changed(double)));
+
        return _spin_box;
 }
 
@@ -83,5 +87,10 @@ void Double::commit()
        _setter(g_variant_new_double(_spin_box->value()));
 }
 
+void Double::on_value_changed(double)
+{
+       commit();
+}
+
 } // prop
 } // pv
index 5edb392419cf302a940b49d0e643ca3c15bd60ad..ba4c5958945c76a8653a119ab16f4faa5eac791f 100644 (file)
@@ -34,6 +34,8 @@ namespace prop {
 
 class Double : public Property
 {
+       Q_OBJECT
+
 public:
        Double(QString name, int decimals, QString suffix,
                boost::optional< std::pair<double, double> > range,
@@ -43,10 +45,13 @@ public:
 
        virtual ~Double();
 
-       QWidget* get_widget(QWidget *parent);
+       QWidget* get_widget(QWidget *parent, bool auto_commit);
 
        void commit();
 
+private slots:
+       void on_value_changed(double);
+
 private:
        const int _decimals;
        const QString _suffix;
index 2249b570851fd183aeb943cb857923584902608a..412a31b0827854d01d103d5f110325b7717faaad 100644 (file)
@@ -45,7 +45,7 @@ Enum::~Enum()
                g_variant_unref(_values[i].first);
 }
 
-QWidget* Enum::get_widget(QWidget *parent)
+QWidget* Enum::get_widget(QWidget *parent, bool auto_commit)
 {
        if (_selector)
                return _selector;
@@ -62,6 +62,10 @@ QWidget* Enum::get_widget(QWidget *parent)
 
        g_variant_unref(value);
 
+       if (auto_commit)
+               connect(_selector, SIGNAL(currentIndexChanged(int)),
+                       this, SLOT(on_current_item_changed(int)));
+
        return _selector;
 }
 
@@ -79,5 +83,10 @@ void Enum::commit()
        _setter((GVariant*)_selector->itemData(index).value<void*>());
 }
 
+void Enum::on_current_item_changed(int)
+{
+       commit();
+}
+
 } // prop
 } // pv
index 402798c08aed26a2c5b5a8c088704528b6eb5bb2..a7e6ed8d53f58bdcf8f5418ad7e695b1677e72e3 100644 (file)
@@ -33,16 +33,21 @@ namespace prop {
 
 class Enum : public Property
 {
+       Q_OBJECT;
+
 public:
        Enum(QString name, std::vector<std::pair<GVariant*, QString> > values,
                Getter getter, Setter setter);
 
        virtual ~Enum();
 
-       QWidget* get_widget(QWidget *parent);
+       QWidget* get_widget(QWidget *parent, bool auto_commit);
 
        void commit();
 
+private slots:
+       void on_current_item_changed(int);
+
 private:
        const std::vector< std::pair<GVariant*, QString> > _values;
 
index 98936292f1e5319460b791c3ae286a96756648f8..6a2cb7d0300b06345cbfa2422e07068812c5d13c 100644 (file)
@@ -46,7 +46,7 @@ Int::~Int()
 {
 }
 
-QWidget* Int::get_widget(QWidget *parent)
+QWidget* Int::get_widget(QWidget *parent, bool auto_commit)
 {
        if (_spin_box)
                return _spin_box;
@@ -64,6 +64,10 @@ QWidget* Int::get_widget(QWidget *parent)
                g_variant_unref(value);
        }
 
+       if (auto_commit)
+               connect(_spin_box, SIGNAL(valueChanged(int)),
+                       this, SLOT(on_value_changed(int)));
+
        return _spin_box;
 }
 
@@ -77,5 +81,10 @@ void Int::commit()
        _setter(g_variant_new_int64(_spin_box->value()));
 }
 
+void Int::on_value_changed(int)
+{
+       commit();
+}
+
 } // prop
 } // pv
index 279bedc1c5bb758f2703cdfabc9aae2fe3e34cc4..f4c7387983409749354839538356b8bfc11e9c2d 100644 (file)
@@ -34,6 +34,8 @@ namespace prop {
 
 class Int : public Property
 {
+       Q_OBJECT;
+
 public:
        Int(QString name, QString suffix,
                boost::optional< std::pair<int64_t, int64_t> > range,
@@ -41,10 +43,13 @@ public:
 
        virtual ~Int();
 
-       QWidget* get_widget(QWidget *parent);
+       QWidget* get_widget(QWidget *parent, bool auto_commit);
 
        void commit();
 
+private slots:
+       void on_value_changed(int);
+
 private:
        const QString _suffix;
        const boost::optional< std::pair<int64_t, int64_t> > _range;
index 31b90330d5e68a69cd63f01c220b5abdbdb30f2d..22e211b1936905146d5d80118a2756dc5859b7da 100644 (file)
@@ -33,8 +33,10 @@ class QWidget;
 namespace pv {
 namespace prop {
 
-class Property
+class Property : public QObject
 {
+       Q_OBJECT;
+
 public:
        typedef boost::function<GVariant* ()> Getter;
        typedef boost::function<void (GVariant*)> Setter;
@@ -45,7 +47,8 @@ protected:
 public:
        const QString& name() const;
 
-       virtual QWidget* get_widget(QWidget *parent) = 0;
+       virtual QWidget* get_widget(QWidget *parent,
+               bool auto_commit = false) = 0;
        virtual bool labeled_widget() const;
 
        virtual void commit() = 0;
index b9de789b90298042104bd0b60b2ea94e8bd45668..b8f3351cf8fb2acbc160a7bcd41bfb529443ddd3 100644 (file)
@@ -38,7 +38,7 @@ String::String(QString name,
 {
 }
 
-QWidget* String::get_widget(QWidget *parent)
+QWidget* String::get_widget(QWidget *parent, bool auto_commit)
 {
        if (_line_edit)
                return _line_edit;
@@ -52,6 +52,10 @@ QWidget* String::get_widget(QWidget *parent)
                g_variant_unref(value);
        }
 
+       if (auto_commit)
+               connect(_line_edit, SIGNAL(textEdited(const QString&)),
+                       this, SLOT(on_text_edited(const QString&)));
+
        return _line_edit;
 }
 
@@ -66,5 +70,10 @@ void String::commit()
        _setter(g_variant_new_string(ba.data()));
 }
 
+void String::on_text_edited(const QString&)
+{
+       commit();
+}
+
 } // prop
 } // pv
index bd95d9b91b3f28aa905ccf0731051969cb1a1049..d54635fe75bcbc3368a887e89b7518147bb5cfd9 100644 (file)
@@ -30,13 +30,18 @@ namespace prop {
 
 class String : public Property
 {
+       Q_OBJECT;
+
 public:
        String(QString name, Getter getter, Setter setter);
 
-       QWidget* get_widget(QWidget *parent);
+       QWidget* get_widget(QWidget *parent, bool auto_commit);
 
        void commit();
 
+private slots:
+       void on_text_edited(const QString&);
+
 private:
        QLineEdit *_line_edit;
 };