X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=pv%2Fprop%2Fint.cpp;h=c1b2d22a6be97b4692d8254c2185e1cd076c72ea;hb=fe94bf8255145410d1673880932d59573c829b0e;hp=7fd4aeeffa2af3ceeb536a29f1365e5427f4484a;hpb=efdec55aec1a137460fa362a381ed1904182bfed;p=pulseview.git
diff --git a/pv/prop/int.cpp b/pv/prop/int.cpp
index 7fd4aeef..c1b2d22a 100644
--- a/pv/prop/int.cpp
+++ b/pv/prop/int.cpp
@@ -17,11 +17,14 @@
* along with this program; if not, see .
*/
-#include
-#include
+#include
+#include
+#include
#include
+#include
+
#include "int.hpp"
using boost::optional;
@@ -32,13 +35,12 @@ using std::pair;
namespace pv {
namespace prop {
-Int::Int(QString name,
- QString suffix,
- optional< pair > range,
- Getter getter,
- Setter setter) :
- Property(name, getter, setter),
+Int::Int(QString name, QString desc, QString suffix,
+ optional< pair > range, Getter getter, Setter setter,
+ QString special_value_text) :
+ Property(name, desc, getter, setter),
suffix_(suffix),
+ special_value_text_(special_value_text),
range_(range),
spin_box_(nullptr)
{
@@ -46,7 +48,7 @@ Int::Int(QString name,
QWidget* Int::get_widget(QWidget *parent, bool auto_commit)
{
- int64_t int_val = 0, range_min = 0;
+ int64_t range_min = 0;
uint64_t range_max = 0;
if (spin_box_)
@@ -55,7 +57,12 @@ QWidget* Int::get_widget(QWidget *parent, bool auto_commit)
if (!getter_)
return nullptr;
- value_ = getter_();
+ try {
+ value_ = getter_();
+ } catch (const sigrok::Error &e) {
+ qWarning() << tr("Querying config key %1 resulted in %2").arg(name_, e.what());
+ return nullptr;
+ }
GVariant *value = value_.gobj();
if (!value)
@@ -63,37 +70,31 @@ QWidget* Int::get_widget(QWidget *parent, bool auto_commit)
spin_box_ = new QSpinBox(parent);
spin_box_->setSuffix(suffix_);
+ spin_box_->setSpecialValueText(special_value_text_);
const GVariantType *const type = g_variant_get_type(value);
assert(type);
if (g_variant_type_equal(type, G_VARIANT_TYPE_BYTE)) {
- int_val = g_variant_get_byte(value);
range_min = 0, range_max = UINT8_MAX;
} else if (g_variant_type_equal(type, G_VARIANT_TYPE_INT16)) {
- int_val = g_variant_get_int16(value);
range_min = INT16_MIN, range_max = INT16_MAX;
} else if (g_variant_type_equal(type, G_VARIANT_TYPE_UINT16)) {
- int_val = g_variant_get_uint16(value);
range_min = 0, range_max = UINT16_MAX;
} else if (g_variant_type_equal(type, G_VARIANT_TYPE_INT32)) {
- int_val = g_variant_get_int32(value);
range_min = INT32_MIN, range_max = INT32_MAX;
} else if (g_variant_type_equal(type, G_VARIANT_TYPE_UINT32)) {
- int_val = g_variant_get_uint32(value);
range_min = 0, range_max = UINT32_MAX;
} else if (g_variant_type_equal(type, G_VARIANT_TYPE_INT64)) {
- int_val = g_variant_get_int64(value);
range_min = INT64_MIN, range_max = INT64_MAX;
} else if (g_variant_type_equal(type, G_VARIANT_TYPE_UINT64)) {
- int_val = g_variant_get_uint64(value);
range_min = 0, range_max = UINT64_MAX;
} else {
// Unexpected value type.
- assert(0);
+ assert(false);
}
- // @todo Sigrok supports 64-bit quantities, but Qt does not have a
+ // @todo sigrok supports 64-bit quantities, but Qt does not have a
// standard widget to allow the values to be modified over the full
// 64-bit range on 32-bit machines. To solve the issue we need a
// custom widget.
@@ -106,7 +107,7 @@ QWidget* Int::get_widget(QWidget *parent, bool auto_commit)
else
spin_box_->setRange((int)range_min, (int)range_max);
- spin_box_->setValue((int)int_val);
+ update_widget();
if (auto_commit)
connect(spin_box_, SIGNAL(valueChanged(int)),
@@ -115,6 +116,48 @@ QWidget* Int::get_widget(QWidget *parent, bool auto_commit)
return spin_box_;
}
+void Int::update_widget()
+{
+ if (!spin_box_)
+ return;
+
+ try {
+ value_ = getter_();
+ } catch (const sigrok::Error &e) {
+ qWarning() << tr("Querying config key %1 resulted in %2").arg(name_, e.what());
+ return;
+ }
+
+ GVariant *value = value_.gobj();
+ assert(value);
+
+ const GVariantType *const type = g_variant_get_type(value);
+ assert(type);
+
+ int64_t int_val = 0;
+
+ if (g_variant_type_equal(type, G_VARIANT_TYPE_BYTE)) {
+ int_val = g_variant_get_byte(value);
+ } else if (g_variant_type_equal(type, G_VARIANT_TYPE_INT16)) {
+ int_val = g_variant_get_int16(value);
+ } else if (g_variant_type_equal(type, G_VARIANT_TYPE_UINT16)) {
+ int_val = g_variant_get_uint16(value);
+ } else if (g_variant_type_equal(type, G_VARIANT_TYPE_INT32)) {
+ int_val = g_variant_get_int32(value);
+ } else if (g_variant_type_equal(type, G_VARIANT_TYPE_UINT32)) {
+ int_val = g_variant_get_uint32(value);
+ } else if (g_variant_type_equal(type, G_VARIANT_TYPE_INT64)) {
+ int_val = g_variant_get_int64(value);
+ } else if (g_variant_type_equal(type, G_VARIANT_TYPE_UINT64)) {
+ int_val = g_variant_get_uint64(value);
+ } else {
+ // Unexpected value type.
+ assert(false);
+ }
+
+ spin_box_->setValue((int)int_val);
+}
+
void Int::commit()
{
assert(setter_);
@@ -140,10 +183,9 @@ void Int::commit()
new_value = g_variant_new_int64(spin_box_->value());
else if (g_variant_type_equal(type, G_VARIANT_TYPE_UINT64))
new_value = g_variant_new_uint64(spin_box_->value());
- else
- {
+ else {
// Unexpected value type.
- assert(0);
+ assert(false);
}
assert(new_value);
@@ -158,5 +200,5 @@ void Int::on_value_changed(int)
commit();
}
-} // prop
-} // pv
+} // namespace prop
+} // namespace pv