* 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 <http://www.gnu.org/licenses/>.
*/
-#include <assert.h>
+#include <cassert>
#include <QDoubleSpinBox>
namespace prop {
Double::Double(QString name,
+ QString desc,
int decimals,
QString suffix,
optional< pair<double, double> > range,
optional<double> step,
Getter getter,
Setter setter) :
- Property(name, getter, setter),
+ Property(name, desc, getter, setter),
decimals_(decimals),
suffix_(suffix),
range_(range),
if (!variant.gobj())
return nullptr;
- double value = Glib::VariantBase::cast_dynamic<Glib::Variant<double>>(
- variant).get();
-
spin_box_ = new QDoubleSpinBox(parent);
spin_box_->setDecimals(decimals_);
spin_box_->setSuffix(suffix_);
if (step_)
spin_box_->setSingleStep(*step_);
- spin_box_->setValue(value);
+ update_widget();
if (auto_commit)
connect(spin_box_, SIGNAL(valueChanged(double)),
return spin_box_;
}
+void Double::update_widget()
+{
+ if (!spin_box_)
+ return;
+
+ Glib::VariantBase variant = getter_();
+ assert(variant.gobj());
+
+ double value = Glib::VariantBase::cast_dynamic<Glib::Variant<double>>(
+ variant).get();
+ spin_box_->setValue(value);
+}
+
void Double::commit()
{
assert(setter_);
commit();
}
-} // prop
-} // pv
+} // namespace prop
+} // namespace pv