From 6738a16e1fe4edf4c52f6f7f70ee39cba21a2a9c Mon Sep 17 00:00:00 2001 From: "Zheng, Lei" Date: Fri, 12 Jan 2018 10:52:45 +0800 Subject: [PATCH] Property: improve auto transaction on property change * Deselect property item in property view on selection change. * Special handling for label change because of potential label base subname references. --- src/App/Document.cpp | 13 +++++++------ src/App/PropertyStandard.cpp | 20 +++++++++++++++++++- src/Gui/PropertyView.cpp | 19 ++++++++++++++----- src/Gui/PropertyView.h | 1 + 4 files changed, 41 insertions(+), 12 deletions(-) diff --git a/src/App/Document.cpp b/src/App/Document.cpp index ce9dfc2eb8c2..4e2acee4d04f 100644 --- a/src/App/Document.cpp +++ b/src/App/Document.cpp @@ -1018,13 +1018,14 @@ void Document::_checkTransaction(DocumentObject* pcDelObj, const Property *What, if(name && tid>0) { bool ignore = false; if(What) { - if(What->testStatus(Property::Output)) + auto parent = What->getContainer(); + auto obj = dynamic_cast(parent); + if(!obj) + ignore = true; + else if(What!=&obj->Label && + (What->testStatus(Property::Output) || + (parent->getPropertyType(What) & Prop_Output))) ignore = true; - else { - auto parent = What->getContainer(); - if(parent && (parent->getPropertyType(What) & Prop_Output)) - ignore = true; - } } if(FC_LOG_INSTANCE.isEnabled(FC_LOGLEVEL_LOG)) { if(What) { diff --git a/src/App/PropertyStandard.cpp b/src/App/PropertyStandard.cpp index c0ba57051309..1c3d7c409669 100644 --- a/src/App/PropertyStandard.cpp +++ b/src/App/PropertyStandard.cpp @@ -1348,8 +1348,12 @@ void PropertyString::setValue(const char* newLabel) std::vector > linkChange; std::string label; auto obj = dynamic_cast(getContainer()); + bool commit = false; - if(obj && obj->getNameInDocument() && this==&obj->Label) { + if(!GetApplication().isRestoring() && + obj && obj->getNameInDocument() && this==&obj->Label && + !obj->getDocument()->isPerformingTransaction()) + { // allow object to control label change static ParameterGrp::handle _hPGrp; @@ -1397,6 +1401,17 @@ void PropertyString::setValue(const char* newLabel) obj->onBeforeChangeLabel(label); newLabel = label.c_str(); linkChange = PropertyXLink::updateLabel(obj,newLabel); + + if(linkChange.size() && + !obj->getDocument()->hasPendingTransaction() && + !GetApplication().getActiveTransaction()) + { + commit = true; + std::ostringstream str; + str << "Change " << obj->getNameInDocument() << ".Label"; + GetApplication().setActiveTransaction(str.str().c_str()); + } + } aboutToSetValue(); @@ -1405,6 +1420,9 @@ void PropertyString::setValue(const char* newLabel) for(auto change : linkChange) change.first->setSubName(change.second.c_str()); + + if(commit) + GetApplication().closeActiveTransaction(); } void PropertyString::setValue(const std::string &sString) diff --git a/src/Gui/PropertyView.cpp b/src/Gui/PropertyView.cpp index 0120013af462..7e4be92cc2e0 100644 --- a/src/Gui/PropertyView.cpp +++ b/src/Gui/PropertyView.cpp @@ -136,6 +136,7 @@ void PropertyView::hideEvent(QHideEvent *ev) { // clear the properties before hiding. propertyEditorData->buildUp(props); propertyEditorView->buildUp(props); + clearPropertyItemSelection(); QWidget::hideEvent(ev); } @@ -144,6 +145,16 @@ void PropertyView::showEvent(QShowEvent *ev) { QWidget::showEvent(ev); } +void PropertyView::clearPropertyItemSelection() { + if(App::GetApplication().autoTransaction()) { + QModelIndex index; + propertyEditorData->clearSelection(); + propertyEditorData->setCurrentIndex(index); + propertyEditorView->clearSelection(); + propertyEditorView->setCurrentIndex(index); + } +} + void PropertyView::slotRollback() { // If auto transaction (BaseApp->Preferences->Document->AutoTransaction) is // enabled, PropertyItemDelegate will setup application active transaction @@ -152,11 +163,7 @@ void PropertyView::slotRollback() { // the current active transaction will be closed by design, which cause // further editing to be not recorded. Hence, we force unselect any property // item on undo/redo - QModelIndex index; - propertyEditorData->clearSelection(); - propertyEditorData->setCurrentIndex(index); - propertyEditorView->clearSelection(); - propertyEditorView->setCurrentIndex(index); + clearPropertyItemSelection(); } void PropertyView::slotChangePropertyData(const App::DocumentObject&, const App::Property& prop) @@ -230,6 +237,8 @@ void PropertyView::onSelectionChanged(const SelectionChanges& msg) msg.Type != SelectionChanges::ClrSelection) return; + clearPropertyItemSelection(); + std::set objSet; // group the properties by diff --git a/src/Gui/PropertyView.h b/src/Gui/PropertyView.h index 2fc1ae5147a0..0db6db8ab2ab 100644 --- a/src/Gui/PropertyView.h +++ b/src/Gui/PropertyView.h @@ -64,6 +64,7 @@ class PropertyView : public QWidget, public Gui::SelectionObserver Gui::PropertyEditor::PropertyEditor* propertyEditorView; Gui::PropertyEditor::PropertyEditor* propertyEditorData; + void clearPropertyItemSelection(); public Q_SLOTS: /// Stores a preference for the last tab selected