8#include "integeroption.h"
10#include <QVarLengthArray>
12static const int KSW_INT_MAX = 2147483647;
13static const int KSW_INT_MIN = -2147483647 - 1;
18IntegerOption::IntegerOption(
const SANE_Handle handle,
const int index)
19 : BaseOption(handle, index)
21 m_optionType = Option::TypeInteger;
24void IntegerOption::readValue()
26 if (state() == Option::StateHidden) {
34 status = sane_control_option(m_handle, m_index, SANE_ACTION_GET_VALUE, data.data(), &res);
35 if (
status != SANE_STATUS_GOOD) {
39 int newValue = toSANE_Word(data.data());
40 if (newValue != m_iVal) {
42 Q_EMIT valueChanged(m_iVal);
46QVariant IntegerOption::minimumValue()
const
49 if (m_optDesc->constraint_type == SANE_CONSTRAINT_RANGE) {
50 value =
static_cast<int>(m_optDesc->constraint.range->min);
57QVariant IntegerOption::maximumValue()
const
60 if (m_optDesc->constraint_type == SANE_CONSTRAINT_RANGE) {
61 value =
static_cast<int>(m_optDesc->constraint.range->max);
68QVariant IntegerOption::stepValue()
const
71 if (m_optDesc->constraint_type == SANE_CONSTRAINT_RANGE) {
72 value =
static_cast<int>(m_optDesc->constraint.range->quant);
86 if (state() == Option::StateHidden) {
93QString IntegerOption::valueAsString()
const
95 if (state() == Option::StateHidden) {
101bool IntegerOption::setValue(
const QVariant &val)
104 int newValue = val.
toInt(&ok);
105 if (ok && newValue != m_iVal) {
106 unsigned char data[4];
108 fromSANE_Word(data, newValue);
110 Q_EMIT valueChanged(m_iVal);
117#include "moc_integeroption.cpp"
Q_SCRIPTABLE CaptureState status()
QString number(double n, char format, int precision)
int toInt(bool *ok) const const