KSaneCore

option.h
1/*
2 * SPDX-FileCopyrightText: 2021 Alexander Stippich <a.stippich@gmx.net>
3 *
4 * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
5 */
6
7#ifndef KSANE_COREOPTION_H
8#define KSANE_COREOPTION_H
9
10#include <memory>
11
12// Qt includes
13
14#include "ksanecore_export.h"
15#include <QObject>
16#include <QString>
17#include <QVariant>
18
19namespace KSaneCore
20{
21
22class OptionPrivate;
23
24/**
25 * A wrapper class providing access to the internal KSaneBaseOption
26 * to access all options provided by KSANECore/SANE
27 */
28class KSANECORE_EXPORT Option : public QObject
29{
30 Q_OBJECT
31
32public:
33 /** This enumeration describes the type of the option. */
34 enum OptionType { TypeDetectFail, TypeBool, TypeInteger, TypeDouble, TypeValueList, TypeString, TypeGamma, TypeAction };
35
36 Q_ENUM(OptionType)
37
38 /** This enumeration describes the unit of the value of the option,
39 * if any. */
40 enum OptionUnit { UnitNone, UnitPixel, UnitBit, UnitMilliMeter, UnitDPI, UnitPercent, UnitMicroSecond, UnitSecond };
41
42 Q_ENUM(OptionUnit)
43
44 /** This enumeration describes the current statue of the value of
45 * the option, indicating if this option should be displayed or not. */
46 enum OptionState { StateHidden, StateDisabled, StateActive };
47
48 Q_ENUM(OptionState)
49
50 explicit Option(QObject *parent = nullptr);
51 ~Option() override;
52
53 /** This function returns the internal name of the option
54 * @return the internal name */
55 QString name() const;
56
57 /** This function returns the translated title of the option
58 * @return the title */
59 QString title() const;
60
61 /** This function returns a more verbose, translated description
62 * of the option.
63 * @return the description */
64 QString description() const;
65
66 /** This function the type of the option as determined by KSANECore.
67 * Each type provides a different implementation for different
68 * variable types, e.g. integer, float or string.
69 * @return the type of option the of value OptionType */
70 OptionType type() const;
71
72 /** This function returns the state of the option indicating
73 * if the function is disabled or should be hidden.
74 * @return the state of option the of value OptionState */
75 OptionState state() const;
76
77 /** This function returns the currently active value for the option.
78 * @return the current value */
79 QVariant value() const;
80
81 /** This function returns the minimum value for the option.
82 * Returns an empty QVariant if this value is not applicable
83 * for the option type.
84 * @return the minimum value */
85 QVariant minimumValue() const;
86
87 /** This function returns the maximum value for the option.
88 * Returns an empty QVariant if this value is not applicable
89 * for the option type.
90 * @return the maximum value */
91 QVariant maximumValue() const;
92
93 /** This function returns the step value for the option.
94 * Returns an empty QVariant if this value is not applicable
95 * for the option type.
96 * @return the step value */
97 QVariant stepValue() const;
98
99 /** This function returns the list of possible values if the option
100 * is of type OptionType::TypeValueList. The list may contain
101 * formatted or translated values.
102 * @return a list with all possible values */
103 QVariantList valueList() const;
104
105 /** This function returns the list of possible values if the option
106 * is of type OptionType::TypeValueList. The list contains the raw
107 * internal values without any formatting or translation.
108 * @return a list with all possible internal values */
109 QVariantList internalValueList() const;
110
111 /** This function returns an enum specifying whether the values
112 * of the option have a unit, e.g. mm, px, etc.
113 * @return unit of value CoreOptionUnit */
114 OptionUnit valueUnit() const;
115
116 /** This function returns the size of the values of the option
117 * of type CoreOptionType::TypeValueList.
118 * If the size is greater than one, value() and setValue()
119 * return and expect a QVariantList with an accordingly number
120 * of elements. If the option is a CoreOptionType::TypeString,
121 * the size represents the number of characters in the string.
122 * @return the number of elements */
123 int valueSize() const;
124
125 /** This function temporarily stores the current value
126 * in a member variable. */
127 bool storeCurrentData();
128
129 /** This function restores the previously saved value
130 * and makes it the current value. */
131 bool restoreSavedData();
132
133Q_SIGNALS:
134 /** This signal is emitted when the option is reloaded, which may
135 * happen if the value of other options has changed. */
137
138 /** This signal is emitted when the current value is updated,
139 * either when a user sets a new value or by a reload by the backend. */
140 void valueChanged(const QVariant &value);
141
142public Q_SLOTS:
143
144 /** This slot allows to change the current value of the option.
145 * @param value the new value of option inside a QVariant.
146 * In case the variant cannot be cast to a value suitable for
147 * the specific option, the value is discarded. */
148 bool setValue(const QVariant &value);
149
150protected:
151 std::unique_ptr<KSaneCore::OptionPrivate> d;
152};
153
154} // namespace KSaneCore
155
156#endif // KSANE_COREOPTION_H
A wrapper class providing access to the internal KSaneBaseOption to access all options provided by KS...
Definition option.h:29
void valueChanged(const QVariant &value)
This signal is emitted when the current value is updated, either when a user sets a new value or by a...
void optionReloaded()
This signal is emitted when the option is reloaded, which may happen if the value of other options ha...
OptionType
This enumeration describes the type of the option.
Definition option.h:34
OptionState
This enumeration describes the current statue of the value of the option, indicating if this option s...
Definition option.h:46
OptionUnit
This enumeration describes the unit of the value of the option, if any.
Definition option.h:40
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 16:56:33 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.