X-Git-Url: http://git.code-monkey.de/?a=blobdiff_plain;f=pv%2Fprop%2Fdouble.cpp;h=f39ae844fc97ce34b4519d4a67546a867e8cdb74;hb=0adee2d93430b5fb879388e66f3bd44fd11b3b22;hp=c5ab1db4e28b5a83b98f33f030fc0124b4bef727;hpb=4c60462b00cc329e61daedd1c2e66724077bd412;p=pulseview.git
diff --git a/pv/prop/double.cpp b/pv/prop/double.cpp
index c5ab1db..f39ae84 100644
--- a/pv/prop/double.cpp
+++ b/pv/prop/double.cpp
@@ -14,14 +14,16 @@
* 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
+#include
+
#include "double.hpp"
using boost::optional;
@@ -31,13 +33,14 @@ 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),
@@ -46,10 +49,6 @@ Double::Double(QString name,
{
}
-Double::~Double()
-{
-}
-
QWidget* Double::get_widget(QWidget *parent, bool auto_commit)
{
if (spin_box_)
@@ -58,12 +57,14 @@ QWidget* Double::get_widget(QWidget *parent, bool auto_commit)
if (!getter_)
return nullptr;
- Glib::VariantBase variant = getter_();
- if (!variant.gobj())
+ try {
+ Glib::VariantBase variant = getter_();
+ if (!variant.gobj())
+ return nullptr;
+ } catch (const sigrok::Error &e) {
+ qWarning() << tr("Querying config key %1 resulted in %2").arg(name_, e.what());
return nullptr;
-
- double value = Glib::VariantBase::cast_dynamic>(
- variant).get();
+ }
spin_box_ = new QDoubleSpinBox(parent);
spin_box_->setDecimals(decimals_);
@@ -73,7 +74,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 +83,27 @@ QWidget* Double::get_widget(QWidget *parent, bool auto_commit)
return spin_box_;
}
+void Double::update_widget()
+{
+ if (!spin_box_)
+ return;
+
+ Glib::VariantBase variant;
+
+ try {
+ variant = getter_();
+ } catch (const sigrok::Error &e) {
+ qWarning() << tr("Querying config key %1 resulted in %2").arg(name_, e.what());
+ return;
+ }
+
+ assert(variant.gobj());
+
+ double value = Glib::VariantBase::cast_dynamic>(
+ variant).get();
+ spin_box_->setValue(value);
+}
+
void Double::commit()
{
assert(setter_);
@@ -97,5 +119,5 @@ void Double::on_value_changed(double)
commit();
}
-} // prop
-} // pv
+} // namespace prop
+} // namespace pv