Merge pull request #9 from kvazar-network/validate-key-value-lenght

disable save button on key/value length limit reached #7
This commit is contained in:
d47081 2024-03-30 07:22:36 +02:00 committed by GitHub
commit ce350e7667
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 103 additions and 13 deletions

View File

@ -15,16 +15,33 @@
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout"> <layout class="QVBoxLayout" name="verticalLayout">
<item> <item>
<widget class="QLabel" name="label_1"> <layout class="QGridLayout" name="gridKeyLableLayout">
<property name="text"> <item column="1">
<string>Key</string> <widget class="QLabel" name="keyLable">
</property> <property name="text">
</widget> <string>Key</string>
</property>
<property name="alignment">
<set>Qt::AlignLeft</set>
</property>
</widget>
</item>
<item column="2">
<widget class="QLabel" name="keyCounter">
<property name="text">
<string/>
</property>
<property name="alignment">
<set>Qt::AlignRight</set>
</property>
</widget>
</item>
</layout>
</item> </item>
<item> <item>
<widget class="QLineEdit" name="keyText"> <widget class="QLineEdit" name="keyText">
<property name="toolTip"> <property name="toolTip">
<string>New value</string> <string>New key</string>
</property> </property>
</widget> </widget>
</item> </item>
@ -42,11 +59,28 @@
</spacer> </spacer>
</item> </item>
<item> <item>
<widget class="QLabel" name="label_2"> <layout class="QGridLayout" name="gridValueLableLayout">
<property name="text"> <item column="1">
<string>Value</string> <widget class="QLabel" name="valueLabel">
</property> <property name="text">
</widget> <string>Value</string>
</property>
<property name="alignment">
<set>Qt::AlignLeft</set>
</property>
</widget>
</item>
<item column="2">
<widget class="QLabel" name="valueCounter">
<property name="text">
<string/>
</property>
<property name="alignment">
<set>Qt::AlignRight</set>
</property>
</widget>
</item>
</layout>
</item> </item>
<item> <item>
<widget class="QPlainTextEdit" name="valueText"> <widget class="QPlainTextEdit" name="valueText">

View File

@ -49,12 +49,68 @@ void KevaAddKeyDialog::cancel()
void KevaAddKeyDialog::onKeyChanged(const QString& key) void KevaAddKeyDialog::onKeyChanged(const QString& key)
{ {
bool enabled = key.length() > 0 && ui->valueText->toPlainText().length() > 0; // Calculate current length
int keyTextLength = key.length();
int valueTextLength = ui->valueText->toPlainText().length();
// Update counter value
ui->keyCounter->setText(
QString::number(
keyTextLength
) + "/" + QString::number(
255
)
);
// Update counter palette
QPalette keyCounterPalette = ui->keyCounter->palette();
keyCounterPalette.setColor(
QPalette::WindowText,
keyTextLength > MAX_SCRIPT_ELEMENT_SIZE ? Qt::red : Qt::darkGreen
);
ui->keyCounter->setPalette(
keyCounterPalette
);
// Update button status
bool enabled = keyTextLength > 0 && valueTextLength > 0 &&
keyTextLength <= 255 && valueTextLength < MAX_SCRIPT_ELEMENT_SIZE + 1;
ui->buttonBox->button(QDialogButtonBox::Save)->setEnabled(enabled); ui->buttonBox->button(QDialogButtonBox::Save)->setEnabled(enabled);
} }
void KevaAddKeyDialog::onValueChanged() void KevaAddKeyDialog::onValueChanged()
{ {
bool enabled = ui->valueText->toPlainText().length() > 0 && ui->keyText->text().length() > 0; // Calculate current length
int keyTextLength = ui->keyText->text().length();
int valueTextLength = ui->valueText->toPlainText().length();
// Update counter value
ui->valueCounter->setText(
QString::number(
valueTextLength
) + "/" + QString::number(
MAX_SCRIPT_ELEMENT_SIZE
)
);
// Update counter palette
QPalette valueCounterPalette = ui->valueCounter->palette();
valueCounterPalette.setColor(
QPalette::WindowText,
valueTextLength > MAX_SCRIPT_ELEMENT_SIZE ? Qt::red : Qt::darkGreen
);
ui->valueCounter->setPalette(
valueCounterPalette
);
// Update button status
bool enabled = keyTextLength > 0 && valueTextLength > 0 &&
keyTextLength <= 255 && valueTextLength < MAX_SCRIPT_ELEMENT_SIZE + 1;
ui->buttonBox->button(QDialogButtonBox::Save)->setEnabled(enabled); ui->buttonBox->button(QDialogButtonBox::Save)->setEnabled(enabled);
} }