Skip to content

Commit

Permalink
Property: improve auto transaction on property change
Browse files Browse the repository at this point in the history
* Deselect property item in property view on selection change.
* Special handling for label change because of potential label base
subname references.
  • Loading branch information
realthunder committed Jan 12, 2018
1 parent 52fe7ee commit 6738a16
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 12 deletions.
13 changes: 7 additions & 6 deletions src/App/Document.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<DocumentObject*>(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) {
Expand Down
20 changes: 19 additions & 1 deletion src/App/PropertyStandard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1348,8 +1348,12 @@ void PropertyString::setValue(const char* newLabel)
std::vector<std::pair<PropertyXLink*,std::string> > linkChange;
std::string label;
auto obj = dynamic_cast<DocumentObject*>(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;
Expand Down Expand Up @@ -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();
Expand All @@ -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)
Expand Down
19 changes: 14 additions & 5 deletions src/Gui/PropertyView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ void PropertyView::hideEvent(QHideEvent *ev) {
// clear the properties before hiding.
propertyEditorData->buildUp(props);
propertyEditorView->buildUp(props);
clearPropertyItemSelection();
QWidget::hideEvent(ev);
}

Expand All @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -230,6 +237,8 @@ void PropertyView::onSelectionChanged(const SelectionChanges& msg)
msg.Type != SelectionChanges::ClrSelection)
return;

clearPropertyItemSelection();

std::set<App::DocumentObject *> objSet;

// group the properties by <name,id>
Expand Down
1 change: 1 addition & 0 deletions src/Gui/PropertyView.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 6738a16

Please sign in to comment.