Skip to content

Commit

Permalink
Tweak validation behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
Admiral-Fish committed Dec 21, 2019
1 parent aaaf746 commit 55dc6a6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
21 changes: 16 additions & 5 deletions Forms/Controls/TextBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
TextBox::TextBox(QWidget *parent)
: QLineEdit(parent)
{
connect(this, &TextBox::textChanged, this, &TextBox::onTextChanged);
connect(this, &TextBox::editingFinished, this, &TextBox::onEditFinished);
setup = false;
}
Expand Down Expand Up @@ -91,12 +92,24 @@ u32 TextBox::getUInt()
return this->text().toUInt(nullptr, base);
}

void TextBox::onEditFinished()
void TextBox::onTextChanged(QString string)
{
if (setup)
{
QString string = this->text().toUpper();
string = string.toUpper();
string.remove(filter);

int position = this->cursorPosition();
this->setText(string);
this->setCursorPosition(position);
}
}

void TextBox::onEditFinished()
{
if (setup)
{
QString string = this->text();
u64 temp = string.toULongLong(nullptr, base);

if (temp > maxValue)
Expand All @@ -108,8 +121,6 @@ void TextBox::onEditFinished()
string = QString::number(minValue, base);
}

int position = cursorPosition();
setText(string);
setCursorPosition(position);
this->setText(string);
}
}
3 changes: 2 additions & 1 deletion Forms/Controls/TextBox.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,13 @@ class TextBox : public QLineEdit

private:
bool setup;
u64 maxValue = 0;
u64 maxValue;
u64 minValue;
int base;
QRegExp filter;

private slots:
void onTextChanged(QString string);
void onEditFinished();
};

Expand Down

0 comments on commit 55dc6a6

Please sign in to comment.