Commit 6eecf4e5 authored by Alexander Stippich's avatar Alexander Stippich
Browse files

change options API

parent 12cc1a34
......@@ -692,7 +692,7 @@ void KSaneWidget::getOptVals(QMap <QString, QString> &opts)
for (int i = 0; i < d->m_optList.size(); i++) {
option = d->m_optList.at(i);
tmp = option->getValueAsString();
tmp = option->valueAsString();
if (!tmp.isEmpty()) {
opts[option->name()] = tmp;
}
......@@ -704,7 +704,7 @@ bool KSaneWidget::getOptVal(const QString &optname, QString &value)
KSaneOption *option;
if ((option = d->getOption(optname)) != nullptr) {
value = option->getValueAsString();
value = option->valueAsString();
return !value.isEmpty();
}
return false;
......@@ -763,9 +763,9 @@ int KSaneWidget::setOptVals(const QMap <QString, QString> &opts)
(d->m_optGamB)) {
// check if the current gamma values are identical. if they are identical,
// uncheck the "Separate color intensity tables" checkbox
QVariant redGamma = d->m_optGamR->getValue();
QVariant greenGamma = d->m_optGamG->getValue();
QVariant blueGamma = d->m_optGamB->getValue();
QVariant redGamma = d->m_optGamR->value();
QVariant greenGamma = d->m_optGamG->value();
QVariant blueGamma = d->m_optGamB->value();
if ((redGamma == greenGamma) && (greenGamma == blueGamma)) {
d->m_splitGamChB->setChecked(false);
......@@ -798,9 +798,9 @@ bool KSaneWidget::setOptVal(const QString &option, const QString &value)
(opt == d->m_optGamB))) {
// check if the current gamma values are identical. if they are identical,
// uncheck the "Separate color intensity tables" checkbox
QVariant redGamma = d->m_optGamR->getValue();
QVariant greenGamma = d->m_optGamG->getValue();
QVariant blueGamma = d->m_optGamB->getValue();
QVariant redGamma = d->m_optGamR->value();
QVariant greenGamma = d->m_optGamG->value();
QVariant blueGamma = d->m_optGamB->value();
if ((redGamma == greenGamma) && (greenGamma == blueGamma)) {
d->m_splitGamChB->setChecked(false);
// set the values to the common gamma widget
......@@ -842,7 +842,7 @@ void KSaneWidget::enableAutoSelect(bool enable)
float KSaneWidget::currentDPI()
{
if (d->m_optRes) {
QVariant value = d->m_optRes->getValue();
QVariant value = d->m_optRes->value();
if (!value.isNull()) {
return value.toFloat();
}
......@@ -854,16 +854,16 @@ float KSaneWidget::scanAreaWidth()
{
float result = 0.0;
if (d->m_optBrX) {
if (d->m_optBrX->getUnit() == KSaneOption::UnitPixel) {
result = d->m_optBrX->getMaxValue().toFloat();
if (d->m_optBrX->valueUnit() == KSaneOption::UnitPixel) {
result = d->m_optBrX->maximumValue().toFloat();
float dpi = currentDPI();
if (dpi < 1) {
qCDebug(KSANE_LOG) << "Broken DPI value";
dpi = 1.0;
}
result = result / dpi / 25.4;
} else if (d->m_optBrX->getUnit() == KSaneOption::UnitMilliMeter) {
result = d->m_optBrX->getMaxValue().toFloat();
} else if (d->m_optBrX->valueUnit() == KSaneOption::UnitMilliMeter) {
result = d->m_optBrX->maximumValue().toFloat();
}
}
return result;
......@@ -873,16 +873,16 @@ float KSaneWidget::scanAreaHeight()
{
float result = 0.0;
if (d->m_optBrY) {
if (d->m_optBrY->getUnit() == KSaneOption::UnitPixel) {
result = d->m_optBrY->getMaxValue().toFloat();
if (d->m_optBrY->valueUnit() == KSaneOption::UnitPixel) {
result = d->m_optBrY->maximumValue().toFloat();
float dpi = currentDPI();
if (dpi < 1) {
qCDebug(KSANE_LOG) << "Broken DPI value";
dpi = 1.0;
}
result = result / dpi / 25.4;
} else if (d->m_optBrY->getUnit() == KSaneOption::UnitMilliMeter) {
result = d->m_optBrY->getMaxValue().toFloat();
} else if (d->m_optBrY->valueUnit() == KSaneOption::UnitMilliMeter) {
result = d->m_optBrY->maximumValue().toFloat();
}
}
return result;
......
......@@ -226,7 +226,7 @@ float KSaneWidgetPrivate::ratioToScanAreaX(float ratio)
if (!m_optBrX) {
return 0.0;
}
float max = m_optBrX->getMaxValue().toFloat();
float max = m_optBrX->maximumValue().toFloat();
return max * ratio;
}
......@@ -236,7 +236,7 @@ float KSaneWidgetPrivate::ratioToScanAreaY(float ratio)
if (!m_optBrY) {
return 0.0;
}
float max = m_optBrY->getMaxValue().toFloat();
float max = m_optBrY->maximumValue().toFloat();
return max * ratio;
}
......@@ -246,7 +246,7 @@ float KSaneWidgetPrivate::scanAreaToRatioX(float scanArea)
if (!m_optBrX) {
return 0.0;
}
float max = m_optBrX->getMaxValue().toFloat();
float max = m_optBrX->maximumValue().toFloat();
if (scanArea > max) {
return 1.0;
......@@ -264,7 +264,7 @@ float KSaneWidgetPrivate::scanAreaToRatioY(float scanArea)
if (!m_optBrY) {
return 0.0;
}
float max = m_optBrY->getMaxValue().toFloat();
float max = m_optBrY->maximumValue().toFloat();
if (scanArea > max) {
return 1.0;
......@@ -295,12 +295,12 @@ float KSaneWidgetPrivate::ratioToDispUnitX(float ratio)
float result = ratioToScanAreaX(ratio);
if (m_optBrX->getUnit() == KSaneOption::UnitMilliMeter) {
if (m_optBrX->valueUnit() == KSaneOption::UnitMilliMeter) {
return mmToDispUnit(result);
}
else if (m_optBrX->getUnit() == KSaneOption::UnitPixel && m_optRes) {
else if (m_optBrX->valueUnit() == KSaneOption::UnitPixel && m_optRes) {
// get current DPI
float dpi = m_optRes->getValue().toFloat();
float dpi = m_optRes->value().toFloat();
if (dpi > 1) {
result = result / (dpi / 25.4);
return mmToDispUnit(result);
......@@ -318,12 +318,12 @@ float KSaneWidgetPrivate::ratioToDispUnitY(float ratio)
float result = ratioToScanAreaY(ratio);
if (m_optBrY->getUnit() == KSaneOption::UnitMilliMeter) {
if (m_optBrY->valueUnit() == KSaneOption::UnitMilliMeter) {
return mmToDispUnit(result);
}
else if (m_optBrY->getUnit() == KSaneOption::UnitPixel && m_optRes) {
else if (m_optBrY->valueUnit() == KSaneOption::UnitPixel && m_optRes) {
// get current DPI
float dpi = m_optRes->getValue().toFloat();
float dpi = m_optRes->value().toFloat();
if (dpi > 1) {
result = result / (dpi / 25.4);
return mmToDispUnit(result);
......@@ -842,7 +842,7 @@ void KSaneWidgetPrivate::setBRX(const QVariant &x)
return;
}
QVariant tlx = m_optTlX->getValue();
QVariant tlx = m_optTlX->value();
if (!tlx.isNull()) {
float tlxRatio = scanAreaToRatioX(tlx.toFloat());
m_scanareaWidth->setValue(ratioToDispUnitX(ratio) - ratioToDispUnitX(tlxRatio));
......@@ -864,7 +864,7 @@ void KSaneWidgetPrivate::setBRY(const QVariant &y)
if (!m_optTlY) {
return;
}
QVariant tly = m_optTlY->getValue();
QVariant tly = m_optTlY->value();
if (!tly.isNull()) {
float tlyRatio = scanAreaToRatioY(tly.toFloat());
m_scanareaHeight->setValue(ratioToDispUnitY(ratio) - ratioToDispUnitY(tlyRatio));
......@@ -880,10 +880,10 @@ void KSaneWidgetPrivate::updatePreviewSize()
// check if an update is necessary
if (m_optBrX != nullptr) {
max_x = m_optBrX->getMaxValue().toFloat();
max_x = m_optBrX->maximumValue().toFloat();
}
if (m_optBrY != nullptr) {
max_y = m_optBrY->getMaxValue().toFloat();
max_y = m_optBrY->maximumValue().toFloat();
}
if ((max_x == m_previewWidth) && (max_y == m_previewHeight)) {
//qCDebug(KSANE_LOG) << "no preview size change";
......@@ -979,8 +979,8 @@ void KSaneWidgetPrivate::startPreviewScan()
if ((m_optTlX != nullptr) && (m_optTlY != nullptr) &&
(m_optBrX != nullptr) && (m_optBrY != nullptr)) {
// get maximums
max_x = m_optBrX->getMaxValue().toFloat();
max_y = m_optBrY->getMaxValue().toFloat();
max_x = m_optBrX->maximumValue().toFloat();
max_y = m_optBrY->maximumValue().toFloat();
// select the whole area
m_optTlX->setValue(0);
m_optTlY->setValue(0);
......@@ -1001,7 +1001,7 @@ void KSaneWidgetPrivate::startPreviewScan()
} else {
// set the resolution to getMinValue and increase if necessary
SANE_Parameters params;
dpi = m_optRes->getMinValue().toFloat();
dpi = m_optRes->minimumValue().toFloat();
do {
m_optRes->setValue(dpi);
if ((m_optResY != nullptr) && (m_optRes->name() == QStringLiteral(SANE_NAME_SCAN_X_RESOLUTION))) {
......@@ -1025,7 +1025,7 @@ void KSaneWidgetPrivate::startPreviewScan()
if (params.pixels_per_line == 0) {
// This is a security measure for broken backends
dpi = m_optRes->getMinValue().toFloat();
dpi = m_optRes->minimumValue().toFloat();
m_optRes->setValue(dpi);
qCDebug(KSANE_LOG) << "Setting minimum DPI value for a broken back-end";
}
......@@ -1053,7 +1053,7 @@ void KSaneWidgetPrivate::startPreviewScan()
m_progressBar->setValue(0);
m_isPreview = true;
m_previewThread->setPreviewInverted(m_optInvert->getValue().toBool());
m_previewThread->setPreviewInverted(m_optInvert->value().toBool());
m_previewThread->start();
m_updProgressTmr.start();
}
......@@ -1142,7 +1142,7 @@ void KSaneWidgetPrivate::startFinalScan()
setBusy(true);
m_updProgressTmr.start();
m_scanThread->setImageInverted(m_optInvert->getValue().toBool());
m_scanThread->setImageInverted(m_optInvert->value().toBool());
m_scanThread->start();
}
......@@ -1152,7 +1152,7 @@ bool KSaneWidgetPrivate::scanSourceADF()
return false;
}
QString source = m_optSource->getValue().toString();
QString source = m_optSource->value().toString();
return source.contains(QStringLiteral("Automatic Document Feeder")) ||
source.contains(QStringLiteral("ADF")) ||
......@@ -1199,7 +1199,7 @@ void KSaneWidgetPrivate::oneFinalScanDone()
// Check if we have a "wait for button" batch scanning
if (m_optWaitForBtn) {
qCDebug(KSANE_LOG) << m_optWaitForBtn->name();
QString wait = m_optWaitForBtn->getValue().toString();
QString wait = m_optWaitForBtn->value().toString();
qCDebug(KSANE_LOG) << "wait ==" << wait;
if (wait == QStringLiteral("true")) {
......@@ -1319,8 +1319,8 @@ void KSaneWidgetPrivate::checkInvert()
return;
}
QString source = m_optSource->getValue().toString();
QString filmtype = m_optFilmType->getValue().toString();
QString source = m_optSource->value().toString();
QString filmtype = m_optFilmType->value().toString();
if ((source.contains(i18nc("This is compared to the option string returned by sane",
"Transparency"), Qt::CaseInsensitive)) &&
......@@ -1398,12 +1398,12 @@ void KSaneWidgetPrivate::updateScanSelection()
{
QVariant maxX;
if (m_optBrX) {
maxX = m_optBrX->getMaxValue();
maxX = m_optBrX->maximumValue();
}
QVariant maxY;
if (m_optBrY) {
maxY = m_optBrY->getMaxValue();
maxY = m_optBrY->maximumValue();
}
float x1 = m_scanareaX->value();
......
......@@ -63,7 +63,7 @@ void KSaneBoolOption::readValue()
}
}
QVariant KSaneBoolOption::getValue() const
QVariant KSaneBoolOption::value() const
{
if (state() == StateHidden) {
return QVariant();
......@@ -71,7 +71,7 @@ QVariant KSaneBoolOption::getValue() const
return m_checked;
}
QString KSaneBoolOption::getValueAsString() const
QString KSaneBoolOption::valueAsString() const
{
if (state() == StateHidden) {
return QString();
......
......@@ -23,8 +23,8 @@ public:
void readValue() override;
QVariant getValue() const override;
QString getValueAsString() const override;
QVariant value() const override;
QString valueAsString() const override;
public Q_SLOTS:
bool setValue(const QVariant &value) override;
......
......@@ -83,7 +83,7 @@ bool KSaneDoubleOption::setValue(const QVariant &value)
return ok;
}
QVariant KSaneDoubleOption::getMinValue() const
QVariant KSaneDoubleOption::minimumValue() const
{
QVariant value;
if (m_optDesc->constraint_type == SANE_CONSTRAINT_RANGE) {
......@@ -94,7 +94,7 @@ QVariant KSaneDoubleOption::getMinValue() const
return value;
}
QVariant KSaneDoubleOption::getMaxValue() const
QVariant KSaneDoubleOption::maximumValue() const
{
QVariant value;
if (m_optDesc->constraint_type == SANE_CONSTRAINT_RANGE) {
......@@ -105,7 +105,7 @@ QVariant KSaneDoubleOption::getMaxValue() const
return value;
}
QVariant KSaneDoubleOption::getStepValue() const
QVariant KSaneDoubleOption::stepValue() const
{
QVariant value;
if (m_optDesc->constraint_type == SANE_CONSTRAINT_RANGE) {
......@@ -116,7 +116,7 @@ QVariant KSaneDoubleOption::getStepValue() const
return value;
}
QVariant KSaneDoubleOption::getValue() const
QVariant KSaneDoubleOption::value() const
{
if (state() == StateHidden) {
return QVariant();
......@@ -124,7 +124,7 @@ QVariant KSaneDoubleOption::getValue() const
return QVariant(m_value);
}
QString KSaneDoubleOption::getValueAsString() const
QString KSaneDoubleOption::valueAsString() const
{
if (state() == StateHidden) {
return QString();
......
......@@ -25,11 +25,11 @@ public:
void readValue() override;
void readOption() override;
QVariant getMinValue() const override;
QVariant getMaxValue() const override;
QVariant getStepValue() const override;
QVariant getValue() const override;
QString getValueAsString() const override;
QVariant minimumValue() const override;
QVariant maximumValue() const override;
QVariant stepValue() const override;
QVariant value() const override;
QString valueAsString() const override;
public Q_SLOTS:
bool setValue(const QVariant &value) override;
......
......@@ -95,7 +95,7 @@ void KSaneGammaOption::readValue()
// not easy nor fast.. ergo not done
}
QVariant KSaneGammaOption::getValue() const
QVariant KSaneGammaOption::value() const
{
if (state() == StateHidden) {
return QVariant();
......@@ -103,7 +103,12 @@ QVariant KSaneGammaOption::getValue() const
return QVariantList{ m_brightness, m_contrast, m_gamma };
}
QVariant KSaneGammaOption::getMaxValue() const
int KSaneGammaOption::valueSize() const
{
return 3;
}
QVariant KSaneGammaOption::maximumValue() const
{
QVariant value;
if (m_optDesc) {
......@@ -113,7 +118,7 @@ QVariant KSaneGammaOption::getMaxValue() const
return value;
}
QString KSaneGammaOption::getValueAsString() const
QString KSaneGammaOption::valueAsString() const
{
if (state() == StateHidden) {
return QString();
......
......@@ -24,9 +24,10 @@ public:
void readValue() override;
void readOption() override;
QVariant getMaxValue() const override;
QVariant getValue() const override;
QString getValueAsString() const override;
QVariant maximumValue() const override;
QVariant value() const override;
int valueSize() const override;
QString valueAsString() const override;
public Q_SLOTS:
bool setValue(const QVariant & value) override;
......
......@@ -45,7 +45,7 @@ void KSaneIntegerOption::readValue()
}
}
QVariant KSaneIntegerOption::getMinValue() const
QVariant KSaneIntegerOption::minimumValue() const
{
QVariant value;
if (m_optDesc->constraint_type == SANE_CONSTRAINT_RANGE) {
......@@ -56,7 +56,7 @@ QVariant KSaneIntegerOption::getMinValue() const
return value;
}
QVariant KSaneIntegerOption::getMaxValue() const
QVariant KSaneIntegerOption::maximumValue() const
{
QVariant value;
if (m_optDesc->constraint_type == SANE_CONSTRAINT_RANGE) {
......@@ -67,7 +67,7 @@ QVariant KSaneIntegerOption::getMaxValue() const
return value;
}
QVariant KSaneIntegerOption::getStepValue() const
QVariant KSaneIntegerOption::stepValue() const
{
QVariant value;
if (m_optDesc->constraint_type == SANE_CONSTRAINT_RANGE) {
......@@ -78,7 +78,7 @@ QVariant KSaneIntegerOption::getStepValue() const
return value;
}
QVariant KSaneIntegerOption::getValue() const
QVariant KSaneIntegerOption::value() const
{
QVariant value;
if (state() == StateHidden) {
......@@ -88,7 +88,7 @@ QVariant KSaneIntegerOption::getValue() const
return value;
}
QString KSaneIntegerOption::getValueAsString() const
QString KSaneIntegerOption::valueAsString() const
{
if (state() == StateHidden) {
return QString();
......
......@@ -23,11 +23,11 @@ public:
void readValue() override;
QVariant getMinValue() const override;
QVariant getMaxValue() const override;
QVariant getStepValue() const override;
QVariant getValue() const override;
QString getValueAsString() const override;
QVariant minimumValue() const override;
QVariant maximumValue() const override;
QVariant stepValue() const override;
QVariant value() const override;
QString valueAsString() const override;
public Q_SLOTS:
bool setValue(const QVariant &value) override;
......
......@@ -31,12 +31,12 @@ bool KSaneInvertOption::setValue(const QVariant &value)
}
}
QVariant KSaneInvertOption::getValue() const
QVariant KSaneInvertOption::value() const
{
return m_checked;
}
QString KSaneInvertOption::getValueAsString() const
QString KSaneInvertOption::valueAsString() const
{
if (m_checked) {
return QStringLiteral("true");
......
......@@ -23,8 +23,8 @@ class KSaneInvertOption : public KSaneOption
public:
KSaneInvertOption();
QVariant getValue() const override;
QString getValueAsString() const override;
QVariant value() const override;
QString valueAsString() const override;
KSaneOptionState state() const override;
QString name() const override;
......
......@@ -59,7 +59,7 @@ void KSaneListOption::readValue()
}
}
QVariantList KSaneListOption::getEntryList() const
QVariantList KSaneListOption::valueList() const
{
int i;
QVariantList list;
......@@ -101,7 +101,7 @@ bool KSaneListOption::setValue(const QVariant &value)
return success;
}
QVariant KSaneListOption::getMinValue() const
QVariant KSaneListOption::minimumValue() const
{
QVariant value;
if (state() == StateHidden) {
......@@ -131,7 +131,7 @@ QVariant KSaneListOption::getMinValue() const
return value;
}
QVariant KSaneListOption::getValue() const
QVariant KSaneListOption::value() const
{
if (state() == StateHidden) {
return QVariant();
......@@ -183,7 +183,7 @@ bool KSaneListOption::setValue(float value)
return false;
}
QString KSaneListOption::getValueAsString() const
QString KSaneListOption::valueAsString() const
{
if (state() == StateHidden) {
return QString();
......
......@@ -25,10 +25,10 @@ public:
void readValue() override;
QVariant getMinValue() const override;
QVariant getValue() const override;
QString getValueAsString() const override;
QVariantList getEntryList() const override;
QVariant minimumValue() const override;
QVariant value() const override;
QString valueAsString() const override;
QVariantList valueList() const override;
public Q_SLOTS:
bool setValue(const QVariant &value) override;
......
......@@ -168,37 +168,32 @@ void KSaneOption::fromSANE_Word(unsigned char *data, SANE_Word from)
#endif
}
QVariant KSaneOption::getMinValue() const
QVariant KSaneOption::value() const
{
return QVariant();
}
QVariant KSaneOption::getMaxValue() const
QVariant KSaneOption::minimumValue() const
{
return QVariant();
}
QVariant KSaneOption::getStepValue() const
QVariant KSaneOption::maximumValue() const
{
return QVariant();
}
QVariantList KSaneOption::getEntryList() const
{
return QVariantList();
}
QVariant KSaneOption::getValue() const
QVariant KSaneOption::stepValue() const
{
return QVariant();
}
QString KSaneOption::getValueAsString() const
QVariantList KSaneOption::valueList() const
{
return QString();
return QVariantList();
}
KSaneOption::KSaneOptionUnit KSaneOption::getUnit() const
KSaneOption::KSaneOptionUnit KSaneOption::valueUnit() const
{
if (m_optDesc != nullptr) {
switch (m_optDesc->unit) {
......@@ -215,6 +210,19 @@ KSaneOption::KSaneOptionUnit KSaneOption::getUnit() const
}
}
int KSaneOption::valueSize() const
{
if (m_optDesc != nullptr) {
return m_optDesc->size / sizeof(SANE_Word);
}
return 0;
}
QString KSaneOption::valueAsString() const
{
return QString();
}
bool KSaneOption::setValue(const QVariant &)
{
return false;
......