Skip to content

Commit

Permalink
Replace mask with validator
Browse files Browse the repository at this point in the history
  • Loading branch information
sithlord48 committed Aug 10, 2022
1 parent c731e55 commit 4f3fbd8
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 10 deletions.
15 changes: 15 additions & 0 deletions demos/ff7tkWidgetGallery/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,13 @@ MainWindow::MainWindow(QWidget *parent): QMainWindow(parent), ui(new Ui::MainWin
auto itemlistLayout = new QVBoxLayout ();
itemlistLayout->addWidget(itemlistView);
ui->itemListView_Box->setLayout(itemlistLayout);

hexLineEdit = new HexLineEdit(this);
auto hexLineEditLayout = new QVBoxLayout();
hexLineEditLayout->addWidget(hexLineEdit);
ui->hexLineEdit_Box->setLayout(hexLineEditLayout);
ui->sb_hexEditLine_maxlen->setValue(hexLineEdit->maxLength());

}

MainWindow::~MainWindow()
Expand Down Expand Up @@ -112,6 +119,7 @@ void MainWindow::on_combo_widget_currentIndexChanged(int index)
case 10: ui->locListBox->setVisible(1); break;
case 11: ui->ChocoboManagerBox->setVisible(1); break;
case 12: ui->AchievementEditor_Box->setVisible(1); break;
case 13: ui->hexLineEdit_group->setVisible(1); break;
}
this->adjustSize();
}
Expand Down Expand Up @@ -246,6 +254,7 @@ void MainWindow::hideAllBoxes(void)
ui->locListBox->setVisible(0);
ui->ChocoboManagerBox->setVisible(0);
ui->AchievementEditor_Box->setVisible(0);
ui->hexLineEdit_group->setVisible(0);
}

void MainWindow::on_btn_loadAchievement_clicked()
Expand Down Expand Up @@ -286,3 +295,9 @@ void MainWindow::on_sb_itemListViewMaxQty_editingFinished()
{
itemlistView->setMaximumItemQty(ui->sb_itemListViewMaxQty->value());
}

void MainWindow::on_sb_hexEditLine_maxlen_valueChanged(double arg1)
{
hexLineEdit->setMaxLength(arg1 * 2);
}

4 changes: 4 additions & 0 deletions demos/ff7tkWidgetGallery/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <ChocoboManager.h>
#include <AchievementEditor.h>
#include <ItemListView.h>
#include <HexLineEdit.h>
#include <Lgp.h>

namespace Ui
Expand Down Expand Up @@ -67,6 +68,8 @@ private slots:
void on_cb_itemSelectionDeleageEditable_toggled(bool checked);
void on_sb_itemListViewMaxQty_editingFinished();

void on_sb_hexEditLine_maxlen_valueChanged(double arg1);

private:

Ui::MainWindow *ui = nullptr;
Expand All @@ -81,4 +84,5 @@ private slots:
ChocoboManager *chocoboManager = nullptr;
AchievementEditor *achievementEditor = nullptr;
ItemListView *itemlistView = nullptr;
HexLineEdit *hexLineEdit = nullptr;
};
49 changes: 47 additions & 2 deletions demos/ff7tkWidgetGallery/mainwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>175</width>
<height>32</height>
<width>117</width>
<height>31</height>
</rect>
</property>
<property name="sizePolicy">
Expand Down Expand Up @@ -88,6 +88,11 @@
<string>AchievementEditor</string>
</property>
</item>
<item>
<property name="text">
<string>HexLineEdit</string>
</property>
</item>
</widget>
</item>
<item>
Expand Down Expand Up @@ -580,6 +585,46 @@
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="hexLineEdit_group">
<property name="title">
<string>HexLineEdit</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_11">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_5">
<item>
<widget class="QLabel" name="label_3">
<property name="text">
<string>MaxLength</string>
</property>
</widget>
</item>
<item>
<widget class="QDoubleSpinBox" name="sb_hexEditLine_maxlen">
<property name="decimals">
<number>0</number>
</property>
<property name="maximum">
<double>20000000000000000426408380189087937446025157425359298935486676992.000000000000000</double>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QFrame" name="hexLineEdit_Box">
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
</widget>
Expand Down
10 changes: 3 additions & 7 deletions src/widgets/common/HexLineEdit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,18 @@
/****************************************************************************/
/****************************************************************************/
#include <HexLineEdit.h>
#include <QRegularExpressionValidator>

HexLineEdit::HexLineEdit(QWidget *parent)
: QLineEdit(parent)
, _noEmit(false)
{
setValidator(new QRegularExpressionValidator(QRegularExpression(_hexRegEx), this));
connect(this, &HexLineEdit::textEdited, this, &HexLineEdit::emitDataEdited);
}

HexLineEdit::HexLineEdit(const QByteArray &contents, QWidget *parent)
: QLineEdit(parent)
, _noEmit(false)
: HexLineEdit(parent)
{
setData(contents);
}
Expand All @@ -39,7 +40,6 @@ void HexLineEdit::setData(const QByteArray &contents)
{
_noEmit = true;
setMaxLength(contents.size() * 2);
setInputMask(QString(contents.size() * 2, 'H'));
_noEmit = false;
setText(QString::fromLatin1(contents.toHex()));
Q_EMIT dataChanged(contents);
Expand Down Expand Up @@ -67,7 +67,3 @@ void HexLineEdit::setMaxLength(int maxLength)
QLineEdit::setMaxLength(maxLength);
}

void HexLineEdit::setInputMask(const QString &inputMask)
{
QLineEdit::setInputMask(inputMask);
}
3 changes: 2 additions & 1 deletion src/widgets/common/HexLineEdit.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,17 @@ class FF7TKQTWIDGETS_EXPORT HexLineEdit : public QLineEdit
explicit HexLineEdit(QWidget *parent = nullptr);
explicit HexLineEdit(const QByteArray &contents, QWidget *parent = nullptr);
QByteArray data() const;
void setMaxLength(int maxLength);
public slots:
void setData(const QByteArray &contents);
signals:
void dataChanged(const QByteArray &data);
void dataEdited(const QByteArray &data);
private:
QString text() const;
void setMaxLength(int maxLength);
void setInputMask(const QString &inputMask);
bool _noEmit;
QString _hexRegEx = QStringLiteral("([A-F]|[0-9]|[a-f])*");
private slots:
void emitDataEdited();
void setText(const QString &);
Expand Down

0 comments on commit 4f3fbd8

Please sign in to comment.