1- #include < QKeyEvent>
21#include < float.h>
2+ #include < QKeyEvent>
33#include < QIntValidator>
4+ #include " ansiutils.h"
45#include " qhexvalidator.h"
56#include " quintvalidator.h"
67#include " qint64validator.h"
@@ -79,11 +80,12 @@ void NumericLineEdit::setInputMode(InputMode mode)
7980 switch (mode)
8081 {
8182 case HexMode:
83+ case AnsiMode:
8284 _minValue = (ushort)0 ;
8385 _maxValue = USHRT_MAX;
8486 break ;
8587
86- case Int32Mode:
88+ case Int32Mode:
8789 _minValue = INT_MIN;
8890 _maxValue = INT_MAX;
8991 break ;
@@ -118,6 +120,23 @@ void NumericLineEdit::setInputMode(InputMode mode)
118120 emit rangeChanged (_minValue, _maxValue);
119121}
120122
123+ // /
124+ // / \brief NumericLineEdit::codepage
125+ // /
126+ QString NumericLineEdit::codepage () const
127+ {
128+ return _codepage;
129+ }
130+
131+ // /
132+ // / \brief NumericLineEdit::setCodepage
133+ // / \param name
134+ // /
135+ void NumericLineEdit::setCodepage (const QString& name)
136+ {
137+ _codepage = name;
138+ }
139+
121140// /
122141// / \brief NumericLineEdit::setText
123142// / \param text
@@ -150,7 +169,7 @@ void NumericLineEdit::internalSetValue(QVariant value)
150169 if (text != QLineEdit::text ())
151170 QLineEdit::setText (text);
152171 }
153- break ;
172+ break ;
154173
155174 case UInt32Mode:
156175 value = qBound (_minValue.toUInt (), value.toUInt (), _maxValue.toUInt ());
@@ -166,7 +185,7 @@ void NumericLineEdit::internalSetValue(QVariant value)
166185 if (text != QLineEdit::text ())
167186 QLineEdit::setText (text);
168187 }
169- break ;
188+ break ;
170189
171190 case HexMode:
172191 {
@@ -187,6 +206,15 @@ void NumericLineEdit::internalSetValue(QVariant value)
187206 }
188207 break ;
189208
209+ case AnsiMode:
210+ {
211+ value = qBound (_minValue.toInt () > 0 ? _minValue.toUInt () : 0 , value.toUInt (), _maxValue.toUInt ());
212+ const auto text = printableAnsi (uint16ToAnsi (value.value <quint16>()), _codepage);
213+ if (text != QLineEdit::text ())
214+ QLineEdit::setText (text);
215+ }
216+ break ;
217+
190218 case FloatMode:
191219 {
192220 value = qBound (_minValue.toFloat (), value.toFloat (), _maxValue.toFloat ());
@@ -283,6 +311,15 @@ void NumericLineEdit::updateValue()
283311 }
284312 break ;
285313
314+ case AnsiMode:
315+ {
316+ auto codec = QTextCodec::codecForName (_codepage.toUtf8 ());
317+ if (codec == nullptr ) codec = QTextCodec::codecForLocale ();
318+ const auto value = uint16FromAnsi (codec->fromUnicode (text ()));
319+ internalSetValue (value);
320+ }
321+ break ;
322+
286323 case FloatMode:
287324 {
288325 bool ok;
@@ -390,6 +427,13 @@ void NumericLineEdit::on_textChanged(const QString& text)
390427 }
391428 break ;
392429
430+ case AnsiMode:
431+ {
432+ const uint valueUInt = uint16FromAnsi (text.toLocal8Bit ());
433+ value = qBound (_minValue.toUInt (), valueUInt, _maxValue.toUInt ());
434+ }
435+ break ;
436+
393437 case FloatMode:
394438 {
395439 bool ok;
@@ -469,11 +513,15 @@ void NumericLineEdit::on_rangeChanged(const QVariant& bottom, const QVariant& to
469513 }
470514 break ;
471515
516+ case AnsiMode:
517+ setMaxLength (2 );
518+ break ;
519+
472520 case FloatMode:
473521 case DoubleMode:
474522 setMaxLength (INT16_MAX);
475523 setValidator (new QDoubleValidator (bottom.toDouble (), top.toDouble (), 6 , this ));
476- break ;
524+ break ;
477525
478526 case Int64Mode:
479527 {
0 commit comments