]> sigrok.org Git - pulseview.git/blame - pv/prop/string.cpp
Replaced boost::shared_ptr with std::shared_ptr
[pulseview.git] / pv / prop / string.cpp
CommitLineData
7112a458
JH
1/*
2 * This file is part of the PulseView project.
3 *
4 * Copyright (C) 2013 Joel Holdsworth <joel@airwebreathe.org.uk>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21#include <assert.h>
22
4e5a4405 23#include <QLineEdit>
7112a458
JH
24#include <QSpinBox>
25
26#include "string.h"
27
7112a458
JH
28namespace pv {
29namespace prop {
30
31String::String(QString name,
32 Getter getter,
33 Setter setter) :
34 Property(name, getter, setter),
35 _line_edit(NULL)
36{
37}
38
b1fe148e 39QWidget* String::get_widget(QWidget *parent, bool auto_commit)
7112a458
JH
40{
41 if (_line_edit)
42 return _line_edit;
43
7112a458 44 GVariant *const value = _getter ? _getter() : NULL;
c542721b
JH
45 if (!value)
46 return NULL;
47
48 _line_edit = new QLineEdit(parent);
49 _line_edit->setText(QString::fromUtf8(
50 g_variant_get_string(value, NULL)));
51 g_variant_unref(value);
7112a458 52
b1fe148e
JH
53 if (auto_commit)
54 connect(_line_edit, SIGNAL(textEdited(const QString&)),
55 this, SLOT(on_text_edited(const QString&)));
56
7112a458
JH
57 return _line_edit;
58}
59
60void String::commit()
61{
62 assert(_setter);
63
64 if (!_line_edit)
65 return;
66
67 QByteArray ba = _line_edit->text().toLocal8Bit();
68 _setter(g_variant_new_string(ba.data()));
69}
70
b1fe148e
JH
71void String::on_text_edited(const QString&)
72{
73 commit();
74}
75
7112a458
JH
76} // prop
77} // pv