diff --git a/src/Gui/Dialogs/DlgAddPropertyVarSet.cpp b/src/Gui/Dialogs/DlgAddPropertyVarSet.cpp index 94011897c6..3ef09b990d 100644 --- a/src/Gui/Dialogs/DlgAddPropertyVarSet.cpp +++ b/src/Gui/Dialogs/DlgAddPropertyVarSet.cpp @@ -371,8 +371,7 @@ bool DlgAddPropertyVarSet::isGroupValid() bool DlgAddPropertyVarSet::isTypeValid() { std::string type = ui->comboBoxType->currentText().toStdString(); - - return !Base::Type::fromName(type.c_str()).isBad(); + return Base::Type::fromName(type.c_str()).isDerivedFrom(App::Property::getClassTypeId()); } bool DlgAddPropertyVarSet::areFieldsValid() @@ -380,9 +379,41 @@ bool DlgAddPropertyVarSet::areFieldsValid() return isNameValid() && isGroupValid() && isTypeValid(); } -void DlgAddPropertyVarSet::onTextFieldChanged([[maybe_unused]] const QString& text) +void DlgAddPropertyVarSet::onTextFieldChanged([[maybe_unused]]const QString& text) { setOkEnabled(areFieldsValid()); + showStatusMessage(); +} + +void DlgAddPropertyVarSet::showStatusMessage() +{ + QString error; + QString text = ui->lineEditName->text(); + std::string name = text.toStdString(); + + if (!isGroupValid()) { + error = tr("Invalid group name"); + } + else if (!isTypeValid()) { + error = tr("Invalid type name"); + } + else if (name.empty()) { + error.clear(); + } + else if (name != Base::Tools::getIdentifier(name)) { + error = tr("Invalid property name '%1'").arg(text); + } + else if (propertyExists(name)) { + error = tr("Property '%1' already exists").arg(text); + } + else if (App::ExpressionParser::isTokenAConstant(name)) { + error = tr("'%1' is a constant").arg(text); + } + else if (App::ExpressionParser::isTokenAUnit(name)) { + error = tr("'%1' is a unit").arg(text); + } + + ui->labelError->setText(error); } void DlgAddPropertyVarSet::removeEditor() @@ -409,6 +440,7 @@ void DlgAddPropertyVarSet::onTypeChanged(const QString& text) } setOkEnabled(areFieldsValid()); + showStatusMessage(); } void DlgAddPropertyVarSet::changeEvent(QEvent* e) diff --git a/src/Gui/Dialogs/DlgAddPropertyVarSet.h b/src/Gui/Dialogs/DlgAddPropertyVarSet.h index d0b539ae24..8e19901f3b 100644 --- a/src/Gui/Dialogs/DlgAddPropertyVarSet.h +++ b/src/Gui/Dialogs/DlgAddPropertyVarSet.h @@ -121,6 +121,7 @@ private: bool areFieldsValid(); void onTextFieldChanged(const QString& text); + void showStatusMessage(); void removeEditor(); void onTypeChanged(const QString& text); diff --git a/src/Gui/Dialogs/DlgAddPropertyVarSet.ui b/src/Gui/Dialogs/DlgAddPropertyVarSet.ui index d46bc7ba31..651c8fc452 100644 --- a/src/Gui/Dialogs/DlgAddPropertyVarSet.ui +++ b/src/Gui/Dialogs/DlgAddPropertyVarSet.ui @@ -7,7 +7,7 @@ 0 0 418 - 223 + 234 @@ -70,6 +70,13 @@ + + + + + + + Qt::Horizontal