9#include "doubleoption.h"
11#include <QVarLengthArray>
13#include <ksanecore_debug.h>
15static const double FIXED_MAX = 32767.9999;
16static const double FIXED_MIN = -32768.0;
17static const double MIN_FIXED_STEP = 0.0001;
18static const double FIXED_PRECISION = 1.0 / 65536;
23DoubleOption::DoubleOption(
const SANE_Handle handle,
const int index)
24 : BaseOption(handle, index)
26 m_optionType = Option::TypeDouble;
29void DoubleOption::readOption()
33 double step = MIN_FIXED_STEP;
34 if (m_optDesc->constraint_type == SANE_CONSTRAINT_RANGE) {
35 step = SANE_UNFIX(m_optDesc->constraint.range->quant);
36 if (step < MIN_FIXED_STEP) {
37 step = MIN_FIXED_STEP;
45void DoubleOption::readValue()
47 if (state() == Option::StateHidden) {
55 status = sane_control_option(m_handle, m_index, SANE_ACTION_GET_VALUE, data.data(), &res);
56 if (
status != SANE_STATUS_GOOD) {
60 double newValue = SANE_UNFIX(toSANE_Word(data.data()));
61 if (abs(newValue - m_value) >= FIXED_PRECISION) {
63 Q_EMIT valueChanged(m_value);
67bool DoubleOption::setValue(
const QVariant &value)
69 if (state() == Option::StateHidden) {
73 double newValue = value.
toDouble(&ok);
74 if (ok && abs(newValue - m_value) >= m_minChange) {
75 unsigned char data[4];
79 fixed = SANE_FIX(newValue);
80 fromSANE_Word(data, fixed);
82 Q_EMIT valueChanged(m_value);
87QVariant DoubleOption::minimumValue()
const
90 if (m_optDesc->constraint_type == SANE_CONSTRAINT_RANGE) {
91 value = SANE_UNFIX(m_optDesc->constraint.range->min);
98QVariant DoubleOption::maximumValue()
const
101 if (m_optDesc->constraint_type == SANE_CONSTRAINT_RANGE) {
102 value = SANE_UNFIX(m_optDesc->constraint.range->max);
109QVariant DoubleOption::stepValue()
const
112 if (m_optDesc->constraint_type == SANE_CONSTRAINT_RANGE) {
113 value = SANE_UNFIX(m_optDesc->constraint.range->quant);
120 value = MIN_FIXED_STEP;
127 if (state() == Option::StateHidden) {
133QString DoubleOption::valueAsString()
const
135 if (state() == Option::StateHidden) {
143#include "moc_doubleoption.cpp"
Q_SCRIPTABLE CaptureState status()
QString number(double n, char format, int precision)
QTextStream & fixed(QTextStream &stream)
double toDouble(bool *ok) const const