X-Git-Url: http://git.code-monkey.de/?a=blobdiff_plain;f=pv%2Fprop%2Fenum.cpp;h=d5d571a9ec487396b921cdae5b45855bb7bbabde;hb=20f59e957e70250cfb876ac7a1743134d6b83339;hp=71cd431548da771ff5e3a9289480f62c5d5b71d2;hpb=1e5faac3a34145620fedf7344c442d9e0a4e2296;p=pulseview.git
diff --git a/pv/prop/enum.cpp b/pv/prop/enum.cpp
index 71cd431..d5d571a 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,60 +29,54 @@ using std::vector;
namespace pv {
namespace prop {
-Enum::Enum(QString name,
- vector > values,
+Enum::Enum(QString name, QString desc,
+ vector > values,
Getter getter, Setter setter) :
- Property(name, getter, setter),
- _values(values),
- _selector(NULL)
+ Property(name, desc, getter, setter),
+ values_(values),
+ selector_(nullptr)
{
}
-Enum::~Enum()
-{
- for (vector< pair >::const_iterator i =
- _values.begin(); i != _values.end(); i++)
- g_variant_unref((*i).first);
-}
-
QWidget* Enum::get_widget(QWidget *parent, bool auto_commit)
{
- if (_selector)
- return _selector;
-
- GVariant *const value = _getter ? _getter() : NULL;
- if (!value)
- return NULL;
-
- _selector = new QComboBox(parent);
- for (unsigned int i = 0; i < _values.size(); i++) {
- const pair &v = _values[i];
- _selector->addItem(v.second, qVariantFromValue((void*)v.first));
- if (value && g_variant_equal(v.first, value))
- _selector->setCurrentIndex(i);
+ if (selector_)
+ return selector_;
+
+ if (!getter_)
+ return nullptr;
+
+ Glib::VariantBase variant = getter_();
+ if (!variant.gobj())
+ 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);
}
- g_variant_unref(value);
-
if (auto_commit)
- connect(_selector, SIGNAL(currentIndexChanged(int)),
+ connect(selector_, SIGNAL(currentIndexChanged(int)),
this, SLOT(on_current_item_changed(int)));
- return _selector;
+ return selector_;
}
void Enum::commit()
{
- assert(_setter);
+ assert(setter_);
- if (!_selector)
+ if (!selector_)
return;
- const int index = _selector->currentIndex();
+ const int index = selector_->currentIndex();
if (index < 0)
return;
- _setter((GVariant*)_selector->itemData(index).value());
+ setter_(selector_->itemData(index).value());
}
void Enum::on_current_item_changed(int)
@@ -91,5 +84,5 @@ void Enum::on_current_item_changed(int)
commit();
}
-} // prop
-} // pv
+} // namespace prop
+} // namespace pv