X-Git-Url: http://git.code-monkey.de/?a=blobdiff_plain;f=pv%2Fprop%2Fstring.cpp;h=b82b496eed42175f7361cd792a4ab8196036eee7;hb=152a0b1b4e19dc3d8b816851abc82813d891b363;hp=e7af45973cc92950aef95c8c4ba50d0357b8132b;hpb=4c60462b00cc329e61daedd1c2e66724077bd412;p=pulseview.git diff --git a/pv/prop/string.cpp b/pv/prop/string.cpp index e7af459..b82b496 100644 --- a/pv/prop/string.cpp +++ b/pv/prop/string.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 "string.hpp" using std::string; @@ -33,9 +35,10 @@ namespace pv { namespace prop { String::String(QString name, + QString desc, Getter getter, Setter setter) : - Property(name, getter, setter), + Property(name, desc, getter, setter), line_edit_(nullptr) { } @@ -48,15 +51,18 @@ QWidget* String::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; - - string value = Glib::VariantBase::cast_dynamic>( - variant).get(); + } line_edit_ = new QLineEdit(parent); - line_edit_->setText(QString::fromStdString(value)); + + update_widget(); if (auto_commit) connect(line_edit_, SIGNAL(textEdited(const QString&)), @@ -65,6 +71,28 @@ QWidget* String::get_widget(QWidget *parent, bool auto_commit) return line_edit_; } +void String::update_widget() +{ + if (!line_edit_) + 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()); + + string value = Glib::VariantBase::cast_dynamic>( + variant).get(); + + line_edit_->setText(QString::fromStdString(value)); +} + void String::commit() { assert(setter_); @@ -81,5 +109,5 @@ void String::on_text_edited(const QString&) commit(); } -} // prop -} // pv +} // namespace prop +} // namespace pv