X-Git-Url: https://sigrok.org/gitweb/?p=pulseview.git;a=blobdiff_plain;f=pv%2Fprop%2Fdouble.cpp;h=57512d723ff26b5cd3473432040e975cf914e8bb;hp=d8a7a2920c5b1f0644ea5d8f33606aebf7286b7a;hb=73078ef7c82758194a92c185131df980c7220cbd;hpb=8dbbc7f0b9ea59d0f0d62225772f8a56eee125f5 diff --git a/pv/prop/double.cpp b/pv/prop/double.cpp index d8a7a292..57512d72 100644 --- a/pv/prop/double.cpp +++ b/pv/prop/double.cpp @@ -14,15 +14,14 @@ * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * along with this program; if not, see . */ -#include +#include #include -#include "double.h" +#include "double.hpp" using boost::optional; using std::pair; @@ -31,22 +30,19 @@ namespace pv { namespace prop { Double::Double(QString name, + QString desc, int decimals, QString suffix, optional< pair > range, optional step, Getter getter, Setter setter) : - Property(name, getter, setter), + Property(name, desc, getter, setter), decimals_(decimals), suffix_(suffix), range_(range), step_(step), - spin_box_(NULL) -{ -} - -Double::~Double() + spin_box_(nullptr) { } @@ -56,14 +52,11 @@ QWidget* Double::get_widget(QWidget *parent, bool auto_commit) return spin_box_; if (!getter_) - return NULL; + return nullptr; Glib::VariantBase variant = getter_(); if (!variant.gobj()) - return NULL; - - double value = Glib::VariantBase::cast_dynamic>( - variant).get(); + return nullptr; spin_box_ = new QDoubleSpinBox(parent); spin_box_->setDecimals(decimals_); @@ -73,7 +66,7 @@ QWidget* Double::get_widget(QWidget *parent, bool auto_commit) if (step_) spin_box_->setSingleStep(*step_); - spin_box_->setValue(value); + update_widget(); if (auto_commit) connect(spin_box_, SIGNAL(valueChanged(double)), @@ -82,6 +75,19 @@ QWidget* Double::get_widget(QWidget *parent, bool auto_commit) return spin_box_; } +void Double::update_widget() +{ + if (!spin_box_) + return; + + Glib::VariantBase variant = getter_(); + assert(variant.gobj()); + + double value = Glib::VariantBase::cast_dynamic>( + variant).get(); + spin_box_->setValue(value); +} + void Double::commit() { assert(setter_); @@ -97,5 +103,5 @@ void Double::on_value_changed(double) commit(); } -} // prop -} // pv +} // namespace prop +} // namespace pv