X-Git-Url: http://git.code-monkey.de/?a=blobdiff_plain;f=pv%2Fprop%2Fstring.cpp;h=96a83422e0a3e2a026336845ac20c72c876e7d35;hb=ca1d6d5f466272ac7e906b589e2804b12568fa96;hp=7fcc656958b9fed74d6f91c89f29e2ebe58d429e;hpb=c542721b53c7560e6b170a5596bf815571690fc4;p=pulseview.git
diff --git a/pv/prop/string.cpp b/pv/prop/string.cpp
index 7fcc656..96a8342 100644
--- a/pv/prop/string.cpp
+++ b/pv/prop/string.cpp
@@ -14,58 +14,66 @@
* 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 "string.h"
+#include "string.hpp"
+
+using std::string;
+
+using Glib::ustring;
namespace pv {
namespace prop {
String::String(QString name,
+ QString desc,
Getter getter,
Setter setter) :
- Property(name, getter, setter),
- _line_edit(NULL)
+ Property(name, desc, getter, setter),
+ line_edit_(nullptr)
{
}
QWidget* String::get_widget(QWidget *parent, bool auto_commit)
{
- if (_line_edit)
- return _line_edit;
+ if (line_edit_)
+ return line_edit_;
+
+ if (!getter_)
+ return nullptr;
+
+ Glib::VariantBase variant = getter_();
+ if (!variant.gobj())
+ return nullptr;
- GVariant *const value = _getter ? _getter() : NULL;
- if (!value)
- return NULL;
+ string value = Glib::VariantBase::cast_dynamic>(
+ variant).get();
- _line_edit = new QLineEdit(parent);
- _line_edit->setText(QString::fromUtf8(
- g_variant_get_string(value, NULL)));
- g_variant_unref(value);
+ line_edit_ = new QLineEdit(parent);
+ line_edit_->setText(QString::fromStdString(value));
if (auto_commit)
- connect(_line_edit, SIGNAL(textEdited(const QString&)),
+ connect(line_edit_, SIGNAL(textEdited(const QString&)),
this, SLOT(on_text_edited(const QString&)));
- return _line_edit;
+ return line_edit_;
}
void String::commit()
{
- assert(_setter);
+ assert(setter_);
- if (!_line_edit)
+ if (!line_edit_)
return;
- QByteArray ba = _line_edit->text().toLocal8Bit();
- _setter(g_variant_new_string(ba.data()));
+ QByteArray ba = line_edit_->text().toLocal8Bit();
+ setter_(Glib::Variant::create(ba.data()));
}
void String::on_text_edited(const QString&)
@@ -73,5 +81,5 @@ void String::on_text_edited(const QString&)
commit();
}
-} // prop
-} // pv
+} // namespace prop
+} // namespace pv