Core: set properties of frozen object read-only

This commit is contained in:
Florian Foinant-Willig
2025-09-23 22:42:14 +02:00
parent d1ca523ca7
commit d15d9948bc
2 changed files with 33 additions and 0 deletions

View File

@@ -228,6 +228,19 @@ void DocumentObject::touch(bool noRecompute)
void DocumentObject::freeze()
{
StatusBits.set(ObjectStatus::Freeze);
// store read-only property names
this->readOnlyProperties.clear();
std::vector<std::pair<const char*, Property*>> list;
static_cast<App::PropertyContainer*>(this)->getPropertyNamedList(list);
for (auto pair: list){
if (pair.second->isReadOnly()){
this->readOnlyProperties.push_back(pair.first);
} else {
pair.second->setReadOnly(true);
}
}
// use the signalTouchedObject to refresh the Gui
if (_pDoc) {
_pDoc->signalTouchedObject(*this);
@@ -241,6 +254,17 @@ void DocumentObject::freeze()
void DocumentObject::unfreeze(bool noRecompute)
{
StatusBits.reset(ObjectStatus::Freeze);
// reset read-only property status
std::vector<std::pair<const char*, Property*>> list;
static_cast<App::PropertyContainer*>(this)->getPropertyNamedList(list);
for (auto pair: list){
if (! std::count(readOnlyProperties.begin(), readOnlyProperties.end(), pair.first)){
pair.second->setReadOnly(false);
}
}
touch(noRecompute);
}
@@ -840,6 +864,10 @@ DocumentObject::onProposedLabelChange(std::string& newLabel)
void DocumentObject::onEarlyChange(const Property* prop)
{
if (isFreezed() && prop != &Visibility) {
return;
}
if (GetApplication().isClosingAll()) {
return;
}

View File

@@ -110,6 +110,11 @@ class AppExport DocumentObject: public App::TransactionalObject
{
PROPERTY_HEADER_WITH_OVERRIDE(App::DocumentObject);
private:
// store read-only property names at freeze
// in order to retablish correct status at unfreeze
std::vector<const char*> readOnlyProperties;
public:
PropertyString Label;
PropertyString Label2;