Gui: clean-up Selection API

Replace the int of the 'resolve' argument of several functions with a proper enum class.
* This avoids the inconsistencies in client code where often true/false is passed when an int is expected
* This avoids the use of magic numbers like 0, 1, 2 or the undocumented 3
This commit is contained in:
wmayer
2022-04-09 17:03:43 +02:00
parent 2d266a75cd
commit 0b2c73cf32
24 changed files with 365 additions and 274 deletions

View File

@@ -429,9 +429,13 @@ QWidget* TreeWidgetEditDelegate::createEditor(
// ---------------------------------------------------------------------------
TreeWidget::TreeWidget(const char* name, QWidget* parent)
: QTreeWidget(parent), SelectionObserver(true, 0), contextItem(nullptr)
, searchObject(nullptr), searchDoc(nullptr), searchContextDoc(nullptr)
, editingItem(nullptr), currentDocItem(nullptr)
: QTreeWidget(parent), SelectionObserver(true, ResolveMode::NoResolve)
, contextItem(nullptr)
, searchObject(nullptr)
, searchDoc(nullptr)
, searchContextDoc(nullptr)
, editingItem(nullptr)
, currentDocItem(nullptr)
, myName(name)
{
Instances.insert(this);
@@ -1060,7 +1064,7 @@ void TreeWidget::onFinishEditing()
DocumentObjectItem* objitem = static_cast<DocumentObjectItem*>
(this->contextItem);
App::DocumentObject* obj = objitem->object()->getObject();
if (!obj)
if (!obj)
return;
Gui::Document* doc = Gui::Application::Instance->getDocument(obj->getDocument());
doc->commitCommand();
@@ -1239,7 +1243,7 @@ std::vector<TreeWidget::SelInfo> TreeWidget::getSelection(App::Document* doc)
break;
}
}
if (!tree)
if (!tree)
return ret;
if (tree->selectTimer->isActive())
@@ -1440,14 +1444,14 @@ void TreeWidget::keyPressEvent(QKeyEvent* event)
void TreeWidget::mouseDoubleClickEvent(QMouseEvent* event)
{
QTreeWidgetItem* item = itemAt(event->pos());
if (!item)
if (!item)
return;
try {
if (item->type() == TreeWidget::DocumentType) {
//QTreeWidget::mouseDoubleClickEvent(event);
Gui::Document* doc = static_cast<DocumentItem*>(item)->document();
if (!doc)
if (!doc)
return;
if (doc->getDocument()->testStatus(App::Document::PartialDoc)) {
contextItem = item;
@@ -2752,7 +2756,7 @@ void TreeWidget::scrollItemToTop()
tree->_updateStatus(false);
if (doc && Gui::Selection().hasSelection(doc->getDocument()->getName(), false)) {
if (doc && Gui::Selection().hasSelection(doc->getDocument()->getName(), ResolveMode::NoResolve)) {
auto it = tree->DocumentMap.find(doc);
if (it != tree->DocumentMap.end()) {
bool lock = tree->blockSelection(true);
@@ -2871,7 +2875,7 @@ void TreeWidget::syncView(ViewProviderDocumentObject* vp)
void TreeWidget::onShowHidden()
{
if (!this->contextItem)
if (!this->contextItem)
return;
DocumentItem* docItem = nullptr;
if (this->contextItem->type() == DocumentType)
@@ -4149,7 +4153,7 @@ void DocumentItem::updateSelection(QTreeWidgetItem* ti, bool unselect) {
}
}
if (unselect)
if (unselect)
return;
for (int i = 0, count = ti->childCount(); i < count; ++i)
updateSelection(ti->child(i));
@@ -4419,7 +4423,7 @@ DocumentObjectItem* DocumentItem::findItem(
}
void DocumentItem::selectItems(SelectionReason reason) {
const auto& sels = Selection().getSelection(pDocument->getDocument()->getName(), false);
const auto& sels = Selection().getSelection(pDocument->getDocument()->getName(), ResolveMode::NoResolve);
bool sync = (sels.size() > 50 || reason == SR_SELECT) ? false : true;
@@ -4475,7 +4479,7 @@ void DocumentItem::selectItems(SelectionReason reason) {
void DocumentItem::populateParents(const ViewProvider* vp, ViewParentMap& parentMap) {
auto it = parentMap.find(vp);
if (it == parentMap.end())
if (it == parentMap.end())
return;
for (auto parent : it->second) {
auto it = ObjectMap.find(parent->getObject());