X-Git-Url: https://sigrok.org/gitweb/?p=pulseview.git;a=blobdiff_plain;f=pv%2Fprop%2Fenum.cpp;h=a6a53764ca040b9366d5f589e1667607a6701ea1;hp=473e3d5f1a3ad36582a3d5c770d4793f607b6124;hb=dbed5609ae31cdfc3e9db10f3ab91b7607c08372;hpb=8dbbc7f0b9ea59d0f0d62225772f8a56eee125f5 diff --git a/pv/prop/enum.cpp b/pv/prop/enum.cpp index 473e3d5f..a6a53764 100644 --- a/pv/prop/enum.cpp +++ b/pv/prop/enum.cpp @@ -14,15 +14,14 @@ * 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 "enum.h" +#include "enum.hpp" using std::pair; using std::vector; @@ -30,16 +29,12 @@ using std::vector; namespace pv { namespace prop { -Enum::Enum(QString name, +Enum::Enum(QString name, QString desc, vector > values, Getter getter, Setter setter) : - Property(name, getter, setter), + Property(name, desc, getter, setter), values_(values), - selector_(NULL) -{ -} - -Enum::~Enum() + selector_(nullptr) { } @@ -49,20 +44,20 @@ QWidget* Enum::get_widget(QWidget *parent, bool auto_commit) return selector_; if (!getter_) - return NULL; + return nullptr; Glib::VariantBase variant = getter_(); if (!variant.gobj()) - return NULL; + return nullptr; selector_ = new QComboBox(parent); for (unsigned int i = 0; i < values_.size(); i++) { const pair &v = values_[i]; selector_->addItem(v.second, qVariantFromValue(v.first)); - if (v.first.equal(variant)) - selector_->setCurrentIndex(i); } + update_widget(); + if (auto_commit) connect(selector_, SIGNAL(currentIndexChanged(int)), this, SLOT(on_current_item_changed(int))); @@ -70,6 +65,21 @@ QWidget* Enum::get_widget(QWidget *parent, bool auto_commit) return selector_; } +void Enum::update_widget() +{ + if (!selector_) + return; + + Glib::VariantBase variant = getter_(); + assert(variant.gobj()); + + for (unsigned int i = 0; i < values_.size(); i++) { + const pair &v = values_[i]; + if (v.first.equal(variant)) + selector_->setCurrentIndex(i); + } +} + void Enum::commit() { assert(setter_); @@ -89,5 +99,5 @@ void Enum::on_current_item_changed(int) commit(); } -} // prop -} // pv +} // namespace prop +} // namespace pv