55 : m_value(std::move(value))
73 operator T()
const {
return value(); };
76 [[nodiscard]] T convertToValue(
const QString &text)
const;
77 [[nodiscard]] QString convertToString(
const T &value)
const;
79 QString stringValue()
const;
81 void setValue(
const QString &text);
82 void setValue(
const T &value);
86 QWidget *m_widget =
nullptr;
108 if (
auto lineEdit = qobject_cast<QLineEdit *>(m_widget))
109 lineEdit->setValidator(validator);
110 else if (
auto comboBox = qobject_cast<QComboBox *>(m_widget))
111 comboBox->setValidator(validator);
113 validator->deleteLater();
126 if constexpr (std::is_same_v<std::decay_t<T>,
short>)
127 return text.toShort();
128 if constexpr (std::is_same_v<std::decay_t<T>,
int>)
130 if constexpr (std::is_same_v<std::decay_t<T>,
long>)
131 return text.toLong();
132 if constexpr (std::is_same_v<std::decay_t<T>,
long long>)
133 return text.toLongLong();
134 if constexpr (std::is_same_v<std::decay_t<T>,
unsigned int>)
135 return text.toUInt();
136 if constexpr (std::is_integral_v<T>)
138 if constexpr (std::is_same_v<std::decay_t<T>,
float>)
139 return text.toFloat();
140 if constexpr (std::is_same_v<std::decay_t<T>,
double>)
141 return text.toDouble();
150 if constexpr (std::is_integral_v<T> || std::is_floating_point_v<T>)
151 return QString::number(value);
161 if (
auto lineEdit = qobject_cast<QLineEdit *>(m_widget))
162 return lineEdit->text();
163 if (
auto comboBox = qobject_cast<QComboBox *>(m_widget))
164 return comboBox->currentText();
165 if (
auto label = qobject_cast<QLabel *>(m_widget))
166 return label->text();
175 return convertToValue(stringValue());
182 if (
auto lineEdit = qobject_cast<QLineEdit *>(m_widget))
183 lineEdit->setText(text);
184 else if (
auto comboBox = qobject_cast<QComboBox *>(m_widget))
185 comboBox->setCurrentText(text);
186 else if (
auto label = qobject_cast<QLabel *>(m_widget))
187 label->setText(text);
196 setValue(convertToString(value));
The KNumber< T > class is used to replace DDX_Text data exchange for numeric types.
Definition knumber.h:48
KNumber(T value)
Definition knumber.h:54
void setWidget(QWidget *label)
Definition knumber.h:96
void setValidator(QValidator *validator)
Definition knumber.h:104
T Type
Definition knumber.h:50
KNumber< T > & operator=(const T &value)
Definition knumber.h:117
QWidget * widget() const
Definition knumber.h:90
T value_type
Definition knumber.h:51
#define KDWINUTILS_BEGIN_NAMESPACE
Definition kdwinutils_global.h:27
#define KDWINUTILS_END_NAMESPACE
Definition kdwinutils_global.h:28