Skip to content
Permalink
Browse files

Gui: fix tree view selection focus problem

  • Loading branch information...
realthunder authored and wwmayer committed Aug 17, 2019
1 parent 0a2d8dc commit 20c628fc0c45f5ed3a35c6cadbf6dcbd8447670b
Showing with 13 additions and 11 deletions.
  1. +12 −11 src/Gui/Tree.cpp
  2. +1 −0 src/Gui/Tree.h
@@ -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();
@@ -2234,7 +2233,7 @@ struct UpdateDisabler {
}
}
~UpdateDisabler() {
if(_UpdateBlocked<=0 || --_UpdateBlocked!=0)
if(blocked<=0 || --blocked!=0)
return;

if(visible) {
@@ -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;

@@ -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();
}
@@ -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();
}
}

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

_LastSelectedTreeWidget = this;
@@ -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)
@@ -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;

0 comments on commit 20c628f

Please sign in to comment.
You can’t perform that action at this time.