Skip to content

Commit 920a2bc

Browse files
committed
Finish int64-display
2 parents c2d4137 + 0b2f82e commit 920a2bc

73 files changed

Lines changed: 1313 additions & 442 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2023 Alexandr Ananev [mail@ananev.org]
3+
Copyright (c) 2024 Alexandr Ananev [mail@ananev.org]
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

omodsim/controls/bytelisttextedit.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,17 +49,17 @@ void ByteListTextEdit::setValue(const QByteArray& value)
4949
{
5050
case DecMode:
5151
{
52-
const auto text = formatByteArray(DataDisplayMode::Decimal, value);
52+
const auto text = formatUInt8Array(DataDisplayMode::Decimal, value);
5353
if(text != toPlainText())
54-
setPlainText(formatByteArray(DataDisplayMode::Decimal, value));
54+
setPlainText(formatUInt8Array(DataDisplayMode::Decimal, value));
5555
}
5656
break;
5757

5858
case HexMode:
5959
{
60-
const auto text = formatByteArray(DataDisplayMode::Hex, value);
60+
const auto text = formatUInt8Array(DataDisplayMode::Hex, value);
6161
if(text != toPlainText())
62-
setPlainText(formatByteArray(DataDisplayMode::Hex, value));
62+
setPlainText(formatUInt8Array(DataDisplayMode::Hex, value));
6363
}
6464
break;
6565
}

omodsim/controls/modbusmessagewidget.cpp

Lines changed: 88 additions & 88 deletions
Large diffs are not rendered by default.

omodsim/controls/numericlineedit.cpp

Lines changed: 115 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <QIntValidator>
44
#include "qhexvalidator.h"
55
#include "quintvalidator.h"
6+
#include "qint64validator.h"
67
#include "numericlineedit.h"
78

89
///
@@ -14,7 +15,7 @@ NumericLineEdit::NumericLineEdit(QWidget* parent)
1415
,_paddingZeroes(false)
1516
,_paddingZeroWidth(0)
1617
{
17-
setInputMode(DecMode);
18+
setInputMode(Int32Mode);
1819
setValue(0);
1920

2021
connect(this, &QLineEdit::editingFinished, this, &NumericLineEdit::on_editingFinished);
@@ -78,14 +79,14 @@ void NumericLineEdit::setInputMode(InputMode mode)
7879
{
7980
switch(mode)
8081
{
81-
case DecMode:
82+
case Int32Mode:
8283
case HexMode:
8384
_minValue = INT_MIN;
8485
_maxValue = INT_MAX;
8586
break;
8687

87-
case UnsignedMode:
88-
_minValue = 0U;
88+
case UInt32Mode:
89+
_minValue = 0;
8990
_maxValue = UINT_MAX;
9091
break;
9192

@@ -98,6 +99,16 @@ void NumericLineEdit::setInputMode(InputMode mode)
9899
_minValue = -DBL_MAX;
99100
_maxValue = DBL_MAX;
100101
break;
102+
103+
case Int64Mode:
104+
_minValue = QVariant::fromValue(INT64_MIN);
105+
_maxValue = QVariant::fromValue(INT64_MAX);
106+
break;
107+
108+
case UInt64Mode:
109+
_minValue = 0;
110+
_maxValue = QVariant::fromValue(UINT64_MAX);
111+
break;
101112
}
102113
}
103114
emit rangeChanged(_minValue, _maxValue);
@@ -121,7 +132,7 @@ void NumericLineEdit::internalSetValue(QVariant value)
121132
{
122133
switch(_inputMode)
123134
{
124-
case DecMode:
135+
case Int32Mode:
125136
value = qBound(_minValue.toInt(), value.toInt(), _maxValue.toInt());
126137
if(_paddingZeroes)
127138
{
@@ -135,9 +146,9 @@ void NumericLineEdit::internalSetValue(QVariant value)
135146
if(text != QLineEdit::text())
136147
QLineEdit::setText(text);
137148
}
138-
break;
149+
break;
139150

140-
case UnsignedMode:
151+
case UInt32Mode:
141152
value = qBound(_minValue.toUInt(), value.toUInt(), _maxValue.toUInt());
142153
if(_paddingZeroes)
143154
{
@@ -151,7 +162,7 @@ void NumericLineEdit::internalSetValue(QVariant value)
151162
if(text != QLineEdit::text())
152163
QLineEdit::setText(text);
153164
}
154-
break;
165+
break;
155166

156167
case HexMode:
157168
{
@@ -189,6 +200,42 @@ void NumericLineEdit::internalSetValue(QVariant value)
189200
QLineEdit::setText(text);
190201
}
191202
break;
203+
204+
case Int64Mode:
205+
{
206+
value = qBound(_minValue.toLongLong(), value.toLongLong(), _maxValue.toLongLong());
207+
if(_paddingZeroes)
208+
{
209+
const auto text = QStringLiteral("%1").arg(value.toLongLong(), _paddingZeroWidth, 10, QLatin1Char('0'));
210+
if(text != QLineEdit::text())
211+
QLineEdit::setText(text);
212+
}
213+
else
214+
{
215+
const auto text = QString::number(value.toLongLong());
216+
if(text != QLineEdit::text())
217+
QLineEdit::setText(text);
218+
}
219+
}
220+
break;
221+
222+
case UInt64Mode:
223+
{
224+
value = qBound(_minValue.toULongLong(), value.toULongLong(), _maxValue.toULongLong());
225+
if(_paddingZeroes)
226+
{
227+
const auto text = QStringLiteral("%1").arg(value.toULongLong(), _paddingZeroWidth, 10, QLatin1Char('0'));
228+
if(text != QLineEdit::text())
229+
QLineEdit::setText(text);
230+
}
231+
else
232+
{
233+
const auto text = QString::number(value.toULongLong());
234+
if(text != QLineEdit::text())
235+
QLineEdit::setText(text);
236+
}
237+
}
238+
break;
192239
}
193240

194241
if(value != _value)
@@ -205,7 +252,7 @@ void NumericLineEdit::updateValue()
205252
{
206253
switch(_inputMode)
207254
{
208-
case DecMode:
255+
case Int32Mode:
209256
{
210257
bool ok;
211258
const auto value = text().toInt(&ok);
@@ -214,7 +261,7 @@ void NumericLineEdit::updateValue()
214261
}
215262
break;
216263

217-
case UnsignedMode:
264+
case UInt32Mode:
218265
{
219266
bool ok;
220267
const auto value = text().toUInt(&ok);
@@ -249,6 +296,24 @@ void NumericLineEdit::updateValue()
249296
else internalSetValue(_value);
250297
}
251298
break;
299+
300+
case Int64Mode:
301+
{
302+
bool ok;
303+
const auto value = text().toLongLong(&ok);
304+
if(ok) internalSetValue(value);
305+
else internalSetValue(_value);
306+
}
307+
break;
308+
309+
case UInt64Mode:
310+
{
311+
bool ok;
312+
const auto value = text().toULongLong(&ok);
313+
if(ok) internalSetValue(value);
314+
else internalSetValue(_value);
315+
}
316+
break;
252317
}
253318
}
254319

@@ -297,19 +362,19 @@ void NumericLineEdit::on_textChanged(const QString& text)
297362
QVariant value;
298363
switch(_inputMode)
299364
{
300-
case DecMode:
365+
case Int32Mode:
301366
{
302367
bool ok;
303368
const auto valueInt = text.toInt(&ok);
304369
if(ok) value = qBound(_minValue.toInt(), valueInt, _maxValue.toInt());
305370
}
306371
break;
307372

308-
case UnsignedMode:
373+
case UInt32Mode:
309374
{
310375
bool ok;
311-
const auto valueInt = text.toUInt(&ok);
312-
if(ok) value = qBound(_minValue.toUInt(), valueInt, _maxValue.toUInt());
376+
const auto valueUInt = text.toUInt(&ok);
377+
if(ok) value = qBound(_minValue.toUInt(), valueUInt, _maxValue.toUInt());
313378
}
314379
break;
315380

@@ -336,6 +401,22 @@ void NumericLineEdit::on_textChanged(const QString& text)
336401
if(ok) value = qBound(_minValue.toDouble(), valueDouble, _maxValue.toDouble());
337402
}
338403
break;
404+
405+
case Int64Mode:
406+
{
407+
bool ok;
408+
const auto valueLongLong = text.toLongLong(&ok);
409+
if(ok) value = qBound(_minValue.toLongLong(), valueLongLong, _maxValue.toLongLong());
410+
}
411+
break;
412+
413+
case UInt64Mode:
414+
{
415+
bool ok;
416+
const auto valueULongLong = text.toULongLong(&ok);
417+
if(ok) value = qBound(_minValue.toULongLong(), valueULongLong, _maxValue.toULongLong());
418+
}
419+
break;
339420
}
340421

341422
if(value.isValid() && value != _value)
@@ -356,7 +437,7 @@ void NumericLineEdit::on_rangeChanged(const QVariant& bottom, const QVariant& to
356437
setValidator(nullptr);
357438
switch(_inputMode)
358439
{
359-
case DecMode:
440+
case Int32Mode:
360441
{
361442
const int nums = QString::number(top.toInt()).length();
362443
_paddingZeroWidth = qMax(1, nums);
@@ -366,7 +447,7 @@ void NumericLineEdit::on_rangeChanged(const QVariant& bottom, const QVariant& to
366447
}
367448
break;
368449

369-
case UnsignedMode:
450+
case UInt32Mode:
370451
{
371452
const int nums = QString::number(top.toUInt()).length();
372453
_paddingZeroWidth = qMax(1, nums);
@@ -388,6 +469,24 @@ void NumericLineEdit::on_rangeChanged(const QVariant& bottom, const QVariant& to
388469
case DoubleMode:
389470
setMaxLength(INT16_MAX);
390471
setValidator(new QDoubleValidator(bottom.toDouble(), top.toDouble(), 6, this));
472+
break;
473+
474+
case Int64Mode:
475+
{
476+
const int nums = QString::number(top.toLongLong()).length();
477+
_paddingZeroWidth = qMax(1, nums);
478+
setMaxLength(qMax(1, nums));
479+
setValidator(new QInt64Validator(bottom.toLongLong(), top.toLongLong(), this));
480+
}
481+
break;
482+
483+
case UInt64Mode:
484+
{
485+
const int nums = QString::number(top.toULongLong()).length();
486+
_paddingZeroWidth = qMax(1, nums);
487+
setMaxLength(qMax(1, nums));
488+
setValidator(new QUIntValidator(bottom.toULongLong(), top.toULongLong(), this));
489+
}
391490
break;
392491
}
393492
internalSetValue(_value);

omodsim/controls/numericlineedit.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,13 @@ class NumericLineEdit : public QLineEdit
1313
public:
1414
enum InputMode
1515
{
16-
DecMode = 0,
17-
UnsignedMode,
16+
Int32Mode = 0,
17+
UInt32Mode,
1818
HexMode,
1919
FloatMode,
20-
DoubleMode
20+
DoubleMode,
21+
Int64Mode,
22+
UInt64Mode
2123
};
2224

2325
explicit NumericLineEdit(QWidget* parent = nullptr);

0 commit comments

Comments
 (0)