mirror of
https://github.com/huderlem/porymap.git
synced 2026-09-09 17:35:37 -05:00
Fix empty metatile labels being disallowed
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user