]> sigrok.org Git - pulseview.git/blobdiff - pv/prop/double.cpp
Don't use deprecated headers.
[pulseview.git] / pv / prop / double.cpp
index 93b45d327362f93b12595a4249e154bcdac0bb14..eeb13fdd37e8e366011a0da1fafe14fd72cef77f 100644 (file)
  * 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 <http://www.gnu.org/licenses/>.
  */
 
-#include <assert.h>
+#include <cassert>
 
 #include <QDoubleSpinBox>
 
-#include "double.h"
+#include "double.hpp"
 
 using boost::optional;
 using std::pair;
@@ -38,53 +37,54 @@ Double::Double(QString name,
        Getter getter,
        Setter setter) :
        Property(name, getter, setter),
-       _decimals(decimals),
-       _suffix(suffix),
-       _range(range),
-       _step(step),
-       _spin_box(NULL)
-{
-}
-
-Double::~Double()
+       decimals_(decimals),
+       suffix_(suffix),
+       range_(range),
+       step_(step),
+       spin_box_(nullptr)
 {
 }
 
 QWidget* Double::get_widget(QWidget *parent, bool auto_commit)
 {
-       if (_spin_box)
-               return _spin_box;
+       if (spin_box_)
+               return spin_box_;
+
+       if (!getter_)
+               return nullptr;
+
+       Glib::VariantBase variant = getter_();
+       if (!variant.gobj())
+               return nullptr;
 
-       GVariant *const value = _getter ? _getter() : NULL;
-       if (!value)
-               return NULL;
+       double value = Glib::VariantBase::cast_dynamic<Glib::Variant<double>>(
+               variant).get();
 
-       _spin_box = new QDoubleSpinBox(parent);
-       _spin_box->setDecimals(_decimals);
-       _spin_box->setSuffix(_suffix);
-       if (_range)
-               _spin_box->setRange(_range->first, _range->second);
-       if (_step)
-               _spin_box->setSingleStep(*_step);
+       spin_box_ = new QDoubleSpinBox(parent);
+       spin_box_->setDecimals(decimals_);
+       spin_box_->setSuffix(suffix_);
+       if (range_)
+               spin_box_->setRange(range_->first, range_->second);
+       if (step_)
+               spin_box_->setSingleStep(*step_);
 
-       _spin_box->setValue(g_variant_get_double(value));
-       g_variant_unref(value);
+       spin_box_->setValue(value);
 
        if (auto_commit)
-               connect(_spin_box, SIGNAL(valueChanged(double)),
+               connect(spin_box_, SIGNAL(valueChanged(double)),
                        this, SLOT(on_value_changed(double)));
 
-       return _spin_box;
+       return spin_box_;
 }
 
 void Double::commit()
 {
-       assert(_setter);
+       assert(setter_);
 
-       if (!_spin_box)
+       if (!spin_box_)
                return;
 
-       _setter(g_variant_new_double(_spin_box->value()));
+       setter_(Glib::Variant<double>::create(spin_box_->value()));
 }
 
 void Double::on_value_changed(double)