From d7de7fe9427df19497b336dd4a5eca61055bd437 Mon Sep 17 00:00:00 2001 From: Joel Klinghed Date: Mon, 24 Jul 2017 20:58:16 +0200 Subject: Add description to GuiForm fields And improve GTK implementation of GuiForm to use GtkGrid instead of GtkBox --- src/gui_qt.cc | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) (limited to 'src/gui_qt.cc') diff --git a/src/gui_qt.cc b/src/gui_qt.cc index cc2ad0d..596ddda 100644 --- a/src/gui_qt.cc +++ b/src/gui_qt.cc @@ -839,13 +839,15 @@ public: } void add_string(std::string const& id, std::string const& label, - std::string const& value) override { - values_.emplace_back(new StringValue(id, label, value)); + std::string const& value, + std::string const& description) override { + values_.emplace_back(new StringValue(id, label, description, value)); } void add_number(std::string const& id, std::string const& label, - uint64_t value) override { - values_.emplace_back(new NumberValue(id, label, value)); + uint64_t value, + std::string const& description) override { + values_.emplace_back(new NumberValue(id, label, description, value)); } std::string get_string(std::string const& id) const override { @@ -904,10 +906,13 @@ protected: Type const type_; std::string const id_; std::string const label_; + std::string const description_; QLineEdit* edit_; - Value(Type type, std::string const& id, std::string const& label) - : type_(type), id_(id), label_(label), edit_(nullptr) { + Value(Type type, std::string const& id, std::string const& label, + std::string const& description) + : type_(type), id_(id), label_(label), description_(description), + edit_(nullptr) { } }; @@ -915,8 +920,9 @@ protected: std::string value_; StringValue(std::string const& id, std::string const& label, + std::string const& description, std::string const& value) - : Value(STRING, id, label), value_(value) { + : Value(STRING, id, label, description), value_(value) { } }; @@ -924,8 +930,9 @@ protected: uint64_t value_; NumberValue(std::string const& id, std::string const& label, + std::string const& description, uint64_t value) - : Value(NUMBER, id, label), value_(value) { + : Value(NUMBER, id, label, description), value_(value) { } }; @@ -972,6 +979,13 @@ protected: layout->addWidget(label, row, 0); layout->addWidget(edit, row, 1); ++row; + if (!value->description_.empty()) { + auto desc = new QLabel( + QString::fromStdString("" + value->description_ + "")); + desc->setAlignment(Qt::AlignTrailing); + desc->setWordWrap(true); + layout->addWidget(desc, row++, 0, 1, 2); + } } error_ = new QLabel(); layout->addWidget(error_, row++, 0, 1, 2); -- cgit v1.2.3-70-g09d2