Skip to content

Commit

Permalink
Gui: fix tree view selection focus problem
Browse files Browse the repository at this point in the history
  • Loading branch information
realthunder authored and wwmayer committed Aug 17, 2019
1 parent 0a2d8dc commit 20c628f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
23 changes: 12 additions & 11 deletions src/Gui/Tree.cpp
Expand Up @@ -2207,19 +2207,18 @@ void TreeWidget::slotActiveDocument(const Gui::Document& Doc)
}
}

static int _UpdateBlocked;

struct UpdateDisabler {
QWidget &widget;
int &blocked;
bool visible;
bool focus;

// Note! DO NOT block signal here, or else
// QTreeWidgetItem::setChildIndicatorPolicy() does not work
UpdateDisabler(QWidget &w)
:widget(w)
UpdateDisabler(QWidget &w, int &blocked)
:widget(w),blocked(blocked)
{
if(++_UpdateBlocked > 1)
if(++blocked > 1)
return;
focus = widget.hasFocus();
visible = widget.isVisible();
Expand All @@ -2234,7 +2233,7 @@ struct UpdateDisabler {
}
}
~UpdateDisabler() {
if(_UpdateBlocked<=0 || --_UpdateBlocked!=0)
if(blocked<=0 || --blocked!=0)
return;

if(visible) {
Expand Down Expand Up @@ -2267,7 +2266,7 @@ void TreeWidget::onUpdateStatus(void)

FC_LOG("begin update status");

UpdateDisabler disabler(*this);
UpdateDisabler disabler(*this,updateBlocked);

std::vector<App::DocumentObject*> errors;

Expand Down Expand Up @@ -2450,7 +2449,7 @@ void TreeWidget::onItemEntered(QTreeWidgetItem * item)
}

void TreeWidget::leaveEvent(QEvent *) {
if(!_UpdateBlocked && FC_TREEPARAM(PreSelection)) {
if(!updateBlocked && FC_TREEPARAM(PreSelection)) {
preselectTimer->stop();
Selection().rmvPreselect();
}
Expand Down Expand Up @@ -2608,8 +2607,10 @@ void TreeWidget::setupText() {

void TreeWidget::syncView(ViewProviderDocumentObject *vp) {
if(currentDocItem && FC_TREEPARAM(SyncView)) {
bool focus = hasFocus();
currentDocItem->document()->setActiveView(vp);
setFocus();
if(focus)
setFocus();
}
}

Expand Down Expand Up @@ -2644,7 +2645,7 @@ void TreeWidget::onItemSelectionChanged ()
{
if (!this->isConnectionAttached()
|| this->isConnectionBlocked()
|| _UpdateBlocked)
|| updateBlocked)
return;

_LastSelectedTreeWidget = this;
Expand Down Expand Up @@ -3123,7 +3124,7 @@ void TreeWidget::slotDeleteDocument(const Gui::Document& Doc)
NewObjects.erase(Doc.getDocument()->getName());
auto it = DocumentMap.find(&Doc);
if (it != DocumentMap.end()) {
UpdateDisabler disabler(*this);
UpdateDisabler disabler(*this,updateBlocked);
auto docItem = it->second;
for(auto &v : docItem->ObjectMap) {
for(auto item : v.second->items)
Expand Down
1 change: 1 addition & 0 deletions src/Gui/Tree.h
Expand Up @@ -241,6 +241,7 @@ private Q_SLOTS:
static std::set<TreeWidget*> Instances;

std::string myName; // for debugging purpose
int updateBlocked = 0;

friend class DocumentItem;
friend class DocumentObjectItem;
Expand Down

0 comments on commit 20c628f

Please sign in to comment.