Fix empty metatile labels being disallowed

This commit is contained in:
GriffinR
2025-03-03 13:28:20 -05:00
parent 7efc3e3421
commit d37864fa82
4 changed files with 16 additions and 4 deletions

View File

@@ -52,8 +52,11 @@ public:
: PrefixValidator(prefix, re_identifier, parent) {};
~IdentifierValidator() {};
void setAllowEmpty(bool allowEmpty);
private:
static const QRegularExpression re_identifier;
static const QRegularExpression re_identifierOrEmpty;
};
class UppercaseValidator : public QValidator {

View File

@@ -182,9 +182,11 @@ bool Tileset::setMetatileLabel(int metatileId, QString label, Tileset *primaryTi
if (!tileset)
return false;
IdentifierValidator validator;
if (!validator.isValid(label))
return false;
if (!label.isEmpty()) {
IdentifierValidator validator;
if (!validator.isValid(label))
return false;
}
tileset->metatileLabels[metatileId] = label;
return true;

View File

@@ -2,7 +2,11 @@
// Identifiers must only contain word characters, and cannot start with a digit.
const QRegularExpression IdentifierValidator::re_identifier = QRegularExpression("[A-Za-z_]+[\\w]*");
const QRegularExpression IdentifierValidator::re_identifierOrEmpty = QRegularExpression("(^$|[A-Za-z_]+[\\w]*)");
void IdentifierValidator::setAllowEmpty(bool allowEmpty) {
this->setRegularExpression(allowEmpty ? re_identifierOrEmpty : re_identifier);
}
bool PrefixValidator::missingPrefix(const QString &input) const {
return !m_prefix.isEmpty() && !input.startsWith(m_prefix);

View File

@@ -34,7 +34,10 @@ TilesetEditor::TilesetEditor(Project *project, Layout *layout, QWidget *parent)
ui->actionShow_Tileset_Divider->setChecked(porymapConfig.showTilesetEditorDivider);
ui->spinBox_paletteSelector->setMinimum(0);
ui->spinBox_paletteSelector->setMaximum(Project::getNumPalettesTotal() - 1);
ui->lineEdit_metatileLabel->setValidator(new IdentifierValidator(this));
auto validator = new IdentifierValidator(this);
validator->setAllowEmpty(true);
ui->lineEdit_metatileLabel->setValidator(validator);
ActiveWindowFilter *filter = new ActiveWindowFilter(this);
connect(filter, &ActiveWindowFilter::activated, this, &TilesetEditor::onWindowActivated);