X-Git-Url: http://git.code-monkey.de/?a=blobdiff_plain;f=pv%2Fprop%2Fstring.cpp;h=d93d78eddf72589190cee89a2f0a082c76a9204b;hb=119c5c232ef47e92ef6a5cc9f8b7c4c31dc2f387;hp=511fe6c4352de19356c36604b5d1479e8ab46319;hpb=e8d009288de28cb194bc7964f96677c2baf900c9;p=pulseview.git
diff --git a/pv/prop/string.cpp b/pv/prop/string.cpp
index 511fe6c..d93d78e 100644
--- a/pv/prop/string.cpp
+++ b/pv/prop/string.cpp
@@ -14,16 +14,15 @@
* 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;
@@ -33,47 +32,60 @@ 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 NULL;
+ if (!getter_)
+ return nullptr;
- Glib::VariantBase variant = _getter();
+ Glib::VariantBase variant = getter_();
if (!variant.gobj())
- return NULL;
+ return nullptr;
- string value = Glib::VariantBase::cast_dynamic>(
- variant).get();
+ line_edit_ = new QLineEdit(parent);
- _line_edit = new QLineEdit(parent);
- _line_edit->setText(QString::fromStdString(value));
+ update_widget();
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::update_widget()
+{
+ if (!line_edit_)
+ return;
+
+ Glib::VariantBase variant = getter_();
+ assert(variant.gobj());
+
+ string value = Glib::VariantBase::cast_dynamic>(
+ variant).get();
+
+ line_edit_->setText(QString::fromStdString(value));
}
void String::commit()
{
- assert(_setter);
+ assert(setter_);
- if (!_line_edit)
+ if (!line_edit_)
return;
- QByteArray ba = _line_edit->text().toLocal8Bit();
- _setter(Glib::Variant::create(ba.data()));
+ QByteArray ba = line_edit_->text().toLocal8Bit();
+ setter_(Glib::Variant::create(ba.data()));
}
void String::on_text_edited(const QString&)
@@ -81,5 +93,5 @@ void String::on_text_edited(const QString&)
commit();
}
-} // prop
-} // pv
+} // namespace prop
+} // namespace pv