Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Gui: change tree view select all behavior
Only select all objects of the current document
  • Loading branch information
realthunder authored and wwmayer committed Dec 8, 2019
1 parent 719c11e commit 50f4c01
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 21 deletions.
46 changes: 25 additions & 21 deletions src/Gui/Tree.cpp
Expand Up @@ -569,6 +569,21 @@ const char *TreeWidget::getTreeName() const {
return myName.c_str();
}

// reimpelement to select only objects in the active document
void TreeWidget::selectAll() {
auto gdoc = Application::Instance->getDocument(
App::GetApplication().getActiveDocument());
if(!gdoc)
return;
auto itDoc = DocumentMap.find(gdoc);
if(itDoc == DocumentMap.end())
return;
if(TreeParams::Instance()->RecordSelection())
Gui::Selection().selStackPush();
Gui::Selection().clearSelection();
Gui::Selection().setSelection(gdoc->getDocument()->getName(),gdoc->getDocument()->getObjects());
}

bool TreeWidget::isObjectShowable(App::DocumentObject *obj) {
if(!obj || !obj->getNameInDocument())
return true;
Expand Down Expand Up @@ -2696,29 +2711,18 @@ void TreeWidget::onItemSelectionChanged ()
auto selItems = selectedItems();

// do not allow document item multi-selection
auto itDoc = selItems.end();
auto itObj = selItems.end();
for(auto it=selItems.begin();it!=selItems.end();) {
auto item = *it;
if(item->type() == ObjectType) {
itObj = it;
if(itDoc!=selItems.end()) {
(*itDoc)->setSelected(false);
selItems.erase(itDoc);
itDoc = selItems.end();
}
}else if(item->type() == DocumentType) {
if(itObj!=selItems.end()) {
if(selItems.size()) {
auto firstType = selItems.back()->type();
for(auto it=selItems.begin();it!=selItems.end();) {
auto item = *it;
if((firstType==ObjectType && item->type()!=ObjectType)
|| (firstType==DocumentType && item!=selItems.back()))
{
item->setSelected(false);
it = selItems.erase(it);
continue;
}else if(itDoc!=selItems.end()) {
(*itDoc)->setSelected(false);
selItems.erase(itDoc);
}
itDoc = it;
} else
++it;
}
++it;
}

if(selItems.size()<=1) {
Expand Down Expand Up @@ -4176,7 +4180,7 @@ DocumentObjectItem *DocumentItem::findItem(
void DocumentItem::selectItems(SelectionReason reason) {
const auto &sels = Selection().getSelection(pDocument->getDocument()->getName(),false);

bool sync = reason==SR_SELECT?false:true;
bool sync = (sels.size()>50 || reason==SR_SELECT)?false:true;

for(const auto &sel : sels)
findItemByObject(sync,sel.pObject,sel.SubName,true);
Expand Down
2 changes: 2 additions & 0 deletions src/Gui/Tree.h
Expand Up @@ -108,6 +108,8 @@ class TreeWidget : public QTreeWidget, public SelectionObserver
void markItem(const App::DocumentObject* Obj,bool mark);
void syncView(ViewProviderDocumentObject *vp);

virtual void selectAll() override;

const char *getTreeName() const;

static void updateStatus(bool delay=true);
Expand Down

0 comments on commit 50f4c01

Please sign in to comment.