Gui: Small refactor of Tree.cpp selecting docs

Based on review comment, a small refactoring of code that was duplicated
when adding functionality to select documents.  The duplication has been
removed in this commit.
This commit is contained in:
Pieter Hijma
2025-09-12 10:29:07 +02:00
parent 12b7699800
commit 1edacbf508
2 changed files with 25 additions and 20 deletions

View File

@@ -1512,8 +1512,8 @@ void TreeWidget::setupResizableColumn(TreeWidget *tree) {
}
}
std::vector<Document*> TreeWidget::getSelectedDocuments() {
std::vector<Document*> ret;
TreeWidget* TreeWidget::getTreeForSelection()
{
TreeWidget* tree = instance();
if (!tree || !tree->isSelectionAttached()) {
for (auto pTree : Instances)
@@ -1522,13 +1522,28 @@ std::vector<Document*> TreeWidget::getSelectedDocuments() {
break;
}
}
if (!tree)
return ret;
if (!tree) {
return nullptr;
}
if (tree->selectTimer->isActive())
if (tree->selectTimer->isActive()) {
tree->onSelectTimer();
else
}
else {
tree->_updateStatus(false);
}
return tree;
}
std::vector<Document*> TreeWidget::getSelectedDocuments()
{
std::vector<Document*> ret;
TreeWidget* tree = getTreeForSelection();
if (!tree) {
return ret;
}
const auto items = tree->selectedItems();
for (auto ti : items) {
@@ -1548,22 +1563,11 @@ std::vector<Document*> TreeWidget::getSelectedDocuments() {
std::vector<TreeWidget::SelInfo> TreeWidget::getSelection(App::Document* doc)
{
std::vector<SelInfo> ret;
TreeWidget* tree = getTreeForSelection();
TreeWidget* tree = instance();
if (!tree || !tree->isSelectionAttached()) {
for (auto pTree : Instances)
if (pTree->isSelectionAttached()) {
tree = pTree;
break;
}
}
if (!tree)
if (!tree) {
return ret;
if (tree->selectTimer->isActive())
tree->onSelectTimer();
else
tree->_updateStatus(false);
}
const auto items = tree->selectedItems();
for (auto ti : items) {

View File

@@ -228,6 +228,7 @@ private:
bool CheckForDependents();
void addDependentToSelection(App::Document* doc, App::DocumentObject* docObject);
static TreeWidget* getTreeForSelection();
private:
QAction* createGroupAction;