X-Git-Url: https://sigrok.org/gitweb/?p=pulseview.git;a=blobdiff_plain;f=pv%2Fprop%2Fint.cpp;h=3f29951b3d997b7b5b8a299fd34c3a0bf0d6db40;hp=fd3bfe4708e6a0cb95832e81643421945de5a5eb;hb=b571a8e7e0dc3e3b6daa58f27050e76466f006dd;hpb=c6246dc56ed01d7e99aa65ab88b8c191300b1ebd diff --git a/pv/prop/int.cpp b/pv/prop/int.cpp index fd3bfe47..3f29951b 100644 --- a/pv/prop/int.cpp +++ b/pv/prop/int.cpp @@ -14,15 +14,17 @@ * 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 +#include + #include "int.hpp" using boost::optional; @@ -34,11 +36,12 @@ namespace pv { namespace prop { Int::Int(QString name, + QString desc, QString suffix, optional< pair > range, Getter getter, Setter setter) : - Property(name, getter, setter), + Property(name, desc, getter, setter), suffix_(suffix), range_(range), spin_box_(nullptr) @@ -47,7 +50,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_) @@ -56,7 +59,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) @@ -69,32 +77,25 @@ QWidget* Int::get_widget(QWidget *parent, bool auto_commit) 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. @@ -107,7 +108,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)), @@ -116,6 +117,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_); @@ -141,10 +184,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); @@ -159,5 +201,5 @@ void Int::on_value_changed(int) commit(); } -} // prop -} // pv +} // namespace prop +} // namespace pv