Skip to content

Commit

Permalink
Gui: fix property view flickering
Browse files Browse the repository at this point in the history
  • Loading branch information
realthunder authored and wwmayer committed Sep 10, 2019
1 parent 74d7842 commit 69d124a
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 10 deletions.
37 changes: 32 additions & 5 deletions src/Gui/PropertyView.cpp
Expand Up @@ -136,6 +136,12 @@ PropertyView::PropertyView(QWidget *parent)
this->connectDelDocument =
Application::Instance->signalDeleteDocument.connect(
boost::bind(&PropertyView::slotDeleteDocument, this, _1));
this->connectDelViewObject =
Application::Instance->signalDeletedObject.connect(
boost::bind(&PropertyView::slotDeletedViewObject, this, _1));
this->connectDelObject =
App::GetApplication().signalDeletedObject.connect(
boost::bind(&PropertyView::slotDeletedObject, this, _1));
}

PropertyView::~PropertyView()
Expand All @@ -149,6 +155,8 @@ PropertyView::~PropertyView()
this->connectRedoDocument.disconnect();
this->connectActiveDoc.disconnect();
this->connectDelDocument.disconnect();
this->connectDelObject.disconnect();
this->connectDelViewObject.disconnect();
}

static bool _ShowAll;
Expand Down Expand Up @@ -253,6 +261,25 @@ void PropertyView::slotDeleteDocument(const Gui::Document &doc) {
propertyEditorView->buildUp();
propertyEditorData->buildUp();
clearPropertyItemSelection();
timer->start(50);
}
}

void PropertyView::slotDeletedViewObject(const Gui::ViewProvider &vp) {
if(propertyEditorView->propOwners.count(&vp)) {
propertyEditorView->buildUp();
propertyEditorData->buildUp();
clearPropertyItemSelection();
timer->start(50);
}
}

void PropertyView::slotDeletedObject(const App::DocumentObject &obj) {
if(propertyEditorData->propOwners.count(&obj)) {
propertyEditorView->buildUp();
propertyEditorData->buildUp();
clearPropertyItemSelection();
timer->start(50);
}
}

Expand Down Expand Up @@ -297,10 +324,7 @@ void PropertyView::onSelectionChanged(const SelectionChanges& msg)
return;

// clear the properties.
propertyEditorData->buildUp();
propertyEditorView->buildUp();
clearPropertyItemSelection();
timer->start(100);
timer->start(50);
}

void PropertyView::onTimer() {
Expand All @@ -310,6 +334,9 @@ void PropertyView::onTimer() {
clearPropertyItemSelection();
timer->stop();

if(!this->isConnectionAttached())
return;

if(!Gui::Selection().hasSelection()) {
auto gdoc = TreeWidget::selectedDocument();
if(!gdoc || !gdoc->getDocument())
Expand Down Expand Up @@ -477,7 +504,7 @@ void PropertyView::onTimer() {
for(auto &v : dataPropsMap)
dataProps.emplace_back(v.first,std::move(v.second));

propertyEditorData->buildUp(std::move(dataProps));
propertyEditorData->buildUp(std::move(dataProps),true);

for (it = propViewMap.begin(); it != propViewMap.end(); ++it) {
if (it->propList.size() == sels.size())
Expand Down
4 changes: 4 additions & 0 deletions src/Gui/PropertyView.h
Expand Up @@ -89,6 +89,8 @@ public Q_SLOTS:
void slotRollback();
void slotActiveDocument(const Gui::Document&);
void slotDeleteDocument(const Gui::Document&);
void slotDeletedViewObject(const Gui::ViewProvider&);
void slotDeletedObject(const App::DocumentObject&);

void checkEnable(const char *doc = 0);

Expand All @@ -105,6 +107,8 @@ public Q_SLOTS:
Connection connectRedoDocument;
Connection connectActiveDoc;
Connection connectDelDocument;
Connection connectDelObject;
Connection connectDelViewObject;
QTabWidget* tabs;
QTimer* timer;
};
Expand Down
13 changes: 10 additions & 3 deletions src/Gui/propertyeditor/PropertyEditor.cpp
Expand Up @@ -306,7 +306,7 @@ void PropertyEditor::drawBranches(QPainter *painter, const QRect &rect, const QM
//painter->setPen(savedPen);
}

void PropertyEditor::buildUp(PropertyModel::PropertyList &&props)
void PropertyEditor::buildUp(PropertyModel::PropertyList &&props, bool checkDocument)
{
if (committing) {
Base::Console().Warning("While committing the data to the property the selection has changed.\n");
Expand All @@ -327,8 +327,15 @@ void PropertyEditor::buildUp(PropertyModel::PropertyList &&props)
propList = std::move(props);
propOwners.clear();
for(auto &v : propList) {
for(auto prop : v.second)
propOwners.insert(prop->getContainer());
for(auto prop : v.second) {
auto container = prop->getContainer();
if(!container)
continue;
// Include document to get proper handling in PropertyView::slotDeleteDocument()
if(checkDocument && container->isDerivedFrom(App::DocumentObject::getClassTypeId()))
propOwners.insert(static_cast<App::DocumentObject*>(container)->getDocument());
propOwners.insert(container);
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/Gui/propertyeditor/PropertyEditor.h
Expand Up @@ -72,7 +72,7 @@ class PropertyEditor : public QTreeView
~PropertyEditor();

/** Builds up the list view with the properties. */
void buildUp(PropertyModel::PropertyList &&props = PropertyModel::PropertyList());
void buildUp(PropertyModel::PropertyList &&props = PropertyModel::PropertyList(), bool checkDocument=false);
void updateProperty(const App::Property&);
void updateEditorMode(const App::Property&);
bool appendProperty(const App::Property&);
Expand Down Expand Up @@ -113,7 +113,7 @@ protected Q_SLOTS:
PropertyModel* propertyModel;
QStringList selectedProperty;
PropertyModel::PropertyList propList;
std::unordered_set<App::PropertyContainer*> propOwners;
std::unordered_set<const App::PropertyContainer*> propOwners;
bool autoupdate;
bool committing;
bool delaybuild;
Expand Down

0 comments on commit 69d124a

Please sign in to comment.