Gui: rename methods of SelectionObserver to clarify intention in client code

This commit is contained in:
wmayer
2021-12-07 14:17:07 +01:00
parent ce88fa2052
commit ca5c799ce2
18 changed files with 123 additions and 126 deletions

View File

@@ -424,7 +424,7 @@ void DlgPropertyLink::closeEvent(QCloseEvent *ev) {
}
void DlgPropertyLink::attachObserver() {
if(isConnectionAttached())
if(isSelectionAttached())
return;
Gui::Selection().selStackPush();
@@ -443,7 +443,7 @@ void DlgPropertyLink::attachObserver() {
}
auto view = qobject_cast<Gui::PropertyView*>(parentView.data());
if(view)
view->blockConnection(true);
view->blockSelection(true);
}
void DlgPropertyLink::showEvent(QShowEvent *ev) {
@@ -465,7 +465,7 @@ void DlgPropertyLink::leaveEvent(QEvent *ev) {
}
void DlgPropertyLink::detachObserver() {
if(isConnectionAttached())
if(isSelectionAttached())
detachSelection();
auto view = qobject_cast<Gui::PropertyView*>(parentView.data());
@@ -480,7 +480,7 @@ void DlgPropertyLink::detachObserver() {
savedSelections.clear();
}
if(view)
view->blockConnection(false);
view->blockSelection(false);
parentView = nullptr;
}
@@ -521,13 +521,13 @@ void DlgPropertyLink::onItemSelectionChanged()
// Sync 3d view selection. To give a better visual feedback, we
// only keep the latest selection.
bool blocked = blockConnection(true);
bool blocked = blockSelection(true);
Gui::Selection().clearSelection();
for(auto &sobj : sobjs)
Gui::Selection().addSelection(sobj.getDocumentName().c_str(),
sobj.getObjectName().c_str(),
sobj.getSubName().c_str());
blockConnection(blocked);
blockSelection(blocked);
// Enforce single parent
if(singleParent && currentObj && currentObj!=obj) {

View File

@@ -351,7 +351,7 @@ void PropertyView::onTimer() {
clearPropertyItemSelection();
timer->stop();
if(!this->isConnectionAttached())
if(!this->isSelectionAttached())
return;
if(!Gui::Selection().hasSelection()) {

View File

@@ -85,21 +85,23 @@ bool SelectionGateFilterExternal::allow(App::Document *doc ,App::DocumentObject
//////////////////////////////////////////////////////////////////////////////////////////
SelectionObserver::SelectionObserver(bool attach,int resolve)
:resolve(resolve),blockSelection(false)
SelectionObserver::SelectionObserver(bool attach, int resolve)
: resolve(resolve)
, blockedSelection(false)
{
if(attach)
if (attach)
attachSelection();
}
SelectionObserver::SelectionObserver(const ViewProviderDocumentObject *vp,bool attach,int resolve)
:resolve(resolve),blockSelection(false)
SelectionObserver::SelectionObserver(const ViewProviderDocumentObject *vp,bool attach, int resolve)
: resolve(resolve)
, blockedSelection(false)
{
if(vp && vp->getObject() && vp->getObject()->getDocument()) {
if (vp && vp->getObject() && vp->getObject()->getDocument()) {
filterDocName = vp->getObject()->getDocument()->getName();
filterObjName = vp->getObject()->getNameInDocument();
}
if(attach)
if (attach)
attachSelection();
}
@@ -109,22 +111,19 @@ SelectionObserver::~SelectionObserver()
detachSelection();
}
bool SelectionObserver::blockConnection(bool block)
bool SelectionObserver::blockSelection(bool block)
{
bool ok = blockSelection;
if (block)
blockSelection = true;
else
blockSelection = false;
bool ok = blockedSelection;
blockedSelection = block;
return ok;
}
bool SelectionObserver::isConnectionBlocked() const
bool SelectionObserver::isSelectionBlocked() const
{
return blockSelection;
return blockedSelection;
}
bool SelectionObserver::isConnectionAttached() const
bool SelectionObserver::isSelectionAttached() const
{
return connectSelection.connected();
}
@@ -147,7 +146,7 @@ void SelectionObserver::attachSelection()
void SelectionObserver::_onSelectionChanged(const SelectionChanges& msg) {
try {
if (blockSelection)
if (blockedSelection)
return;
onSelectionChanged(msg);
} catch (Base::Exception &e) {
@@ -164,7 +163,7 @@ void SelectionObserver::detachSelection()
{
if (connectSelection.connected()) {
connectSelection.disconnect();
if(filterDocName.size())
if (filterDocName.size())
Selection().rmvSelectionGate();
}
}

View File

@@ -232,9 +232,9 @@ public:
SelectionObserver(const Gui::ViewProviderDocumentObject *vp, bool attach=true, int resolve=1);
virtual ~SelectionObserver();
bool blockConnection(bool block);
bool isConnectionBlocked() const;
bool isConnectionAttached() const;
bool blockSelection(bool block);
bool isSelectionBlocked() const;
bool isSelectionAttached() const;
/** Attaches to the selection. */
void attachSelection();
@@ -251,7 +251,7 @@ private:
std::string filterDocName;
std::string filterObjName;
int resolve;
bool blockSelection;
bool blockedSelection;
};
/**

View File

@@ -628,9 +628,9 @@ void TreeWidget::checkTopParent(App::DocumentObject*& obj, std::string& subname)
auto it = tree->DocumentMap.find(Application::Instance->getDocument(obj->getDocument()));
if (it != tree->DocumentMap.end()) {
if (tree->statusTimer->isActive()) {
bool locked = tree->blockConnection(true);
bool locked = tree->blockSelection(true);
tree->_updateStatus(false);
tree->blockConnection(locked);
tree->blockSelection(locked);
}
auto parent = it->second->getTopParent(obj, subname);
if (parent)
@@ -1204,7 +1204,7 @@ DocumentItem* TreeWidget::getDocumentItem(const Gui::Document* doc) const {
}
void TreeWidget::selectAllInstances(const ViewProviderDocumentObject& vpd) {
if (!isConnectionAttached())
if (!isSelectionAttached())
return;
if (selectTimer->isActive())
@@ -1233,9 +1233,9 @@ std::vector<TreeWidget::SelInfo> TreeWidget::getSelection(App::Document* doc)
std::vector<SelInfo> ret;
TreeWidget* tree = instance();
if (!tree || !tree->isConnectionAttached()) {
if (!tree || !tree->isSelectionAttached()) {
for (auto pTree : Instances)
if (pTree->isConnectionAttached()) {
if (pTree->isSelectionAttached()) {
tree = pTree;
break;
}
@@ -1286,7 +1286,7 @@ std::vector<TreeWidget::SelInfo> TreeWidget::getSelection(App::Document* doc)
}
void TreeWidget::selectAllLinks(App::DocumentObject* obj) {
if (!isConnectionAttached())
if (!isSelectionAttached())
return;
if (!obj || !obj->getNameInDocument()) {
@@ -2620,14 +2620,14 @@ void TreeWidget::onUpdateStatus(void)
docItem->_ExpandInfo.reset();
}
if (Selection().hasSelection() && !selectTimer->isActive() && !this->isConnectionBlocked()) {
this->blockConnection(true);
if (Selection().hasSelection() && !selectTimer->isActive() && !this->isSelectionBlocked()) {
this->blockSelection(true);
currentDocItem = 0;
for (auto& v : DocumentMap) {
v.second->setSelected(false);
v.second->selectItems();
}
this->blockConnection(false);
this->blockSelection(false);
}
auto activeDocItem = getDocumentItem(Application::Instance->activeDocument());
@@ -2745,7 +2745,7 @@ void TreeWidget::scrollItemToTop()
{
auto doc = Application::Instance->activeDocument();
for (auto tree : Instances) {
if (!tree->isConnectionAttached() || tree->isConnectionBlocked())
if (!tree->isSelectionAttached() || tree->isSelectionBlocked())
continue;
tree->_updateStatus(false);
@@ -2753,13 +2753,13 @@ void TreeWidget::scrollItemToTop()
if (doc && Gui::Selection().hasSelection(doc->getDocument()->getName(), false)) {
auto it = tree->DocumentMap.find(doc);
if (it != tree->DocumentMap.end()) {
bool lock = tree->blockConnection(true);
bool lock = tree->blockSelection(true);
it->second->selectItems(DocumentItem::SR_FORCE_EXPAND);
tree->blockConnection(lock);
tree->blockSelection(lock);
}
}
else {
tree->blockConnection(true);
tree->blockSelection(true);
for (int i = 0; i < tree->rootItem->childCount(); i++) {
auto docItem = dynamic_cast<DocumentItem*>(tree->rootItem->child(i));
if (!docItem)
@@ -2772,7 +2772,7 @@ void TreeWidget::scrollItemToTop()
break;
}
}
tree->blockConnection(false);
tree->blockSelection(false);
}
tree->selectTimer->stop();
tree->_updateStatus(false);
@@ -2781,7 +2781,7 @@ void TreeWidget::scrollItemToTop()
void TreeWidget::expandSelectedItems(TreeItemMode mode)
{
if (!isConnectionAttached())
if (!isSelectionAttached())
return;
for (auto item : selectedItems()) {
@@ -2897,15 +2897,15 @@ void TreeWidget::changeEvent(QEvent* e)
void TreeWidget::onItemSelectionChanged()
{
if (!this->isConnectionAttached()
|| this->isConnectionBlocked()
if (!this->isSelectionAttached()
|| this->isSelectionBlocked()
|| updateBlocked)
return;
_LastSelectedTreeWidget = this;
// block tmp. the connection to avoid to notify us ourself
bool lock = this->blockConnection(true);
bool lock = this->blockSelection(true);
if (selectTimer->isActive())
onSelectTimer();
@@ -2972,7 +2972,7 @@ void TreeWidget::onItemSelectionChanged()
Gui::Selection().selStackPush(true, true);
}
this->blockConnection(lock);
this->blockSelection(lock);
}
static bool isSelectionCheckBoxesEnabled() {
@@ -3020,7 +3020,7 @@ void TreeWidget::onSelectTimer() {
_updateStatus(false);
bool syncSelect = TreeParams::Instance()->SyncSelection();
bool locked = this->blockConnection(true);
bool locked = this->blockSelection(true);
if (Selection().hasSelection()) {
for (auto& v : DocumentMap) {
v.second->setSelected(false);
@@ -3033,7 +3033,7 @@ void TreeWidget::onSelectTimer() {
for (auto& v : DocumentMap)
v.second->clearSelection();
}
this->blockConnection(locked);
this->blockSelection(locked);
selectTimer->stop();
return;
}
@@ -3168,7 +3168,7 @@ TreeDockWidget::~TreeDockWidget()
}
void TreeWidget::selectLinkedObject(App::DocumentObject* linked) {
if (!isConnectionAttached() || isConnectionBlocked())
if (!isSelectionAttached() || isSelectionBlocked())
return;
auto linkedVp = Base::freecad_dynamic_cast<ViewProviderDocumentObject>(
@@ -3469,13 +3469,13 @@ void TreeWidget::_slotDeleteObject(const Gui::ViewProviderDocumentObject& view,
if (obj->getDocument() == doc)
docItem->_ParentMap.erase(obj);
bool lock = blockConnection(true);
bool lock = blockSelection(true);
for (auto cit = items.begin(), citNext = cit; cit != items.end(); cit = citNext) {
++citNext;
(*cit)->myOwner = 0;
delete* cit;
}
blockConnection(lock);
blockSelection(lock);
// Check for any child of the deleted object that is not in the tree, and put it
// under document item.
@@ -3606,9 +3606,9 @@ void DocumentItem::populateItem(DocumentObjectItem* item, bool refresh, bool del
if (item->myData->removeChildrenFromRoot) {
if (childItem->myData->rootItem) {
assert(childItem != childItem->myData->rootItem);
bool lock = getTree()->blockConnection(true);
bool lock = getTree()->blockSelection(true);
delete childItem->myData->rootItem;
getTree()->blockConnection(lock);
getTree()->blockSelection(lock);
}
}
else if (childItem->requiredAtRoot()) {
@@ -3679,9 +3679,9 @@ void DocumentItem::populateItem(DocumentObjectItem* item, bool refresh, bool del
}
}
bool lock = getTree()->blockConnection(true);
bool lock = getTree()->blockSelection(true);
delete ci;
getTree()->blockConnection(lock);
getTree()->blockSelection(lock);
}
if (updated)
getTree()->_updateStatus();
@@ -4517,7 +4517,7 @@ void DocumentItem::selectAllInstances(const ViewProviderDocumentObject& vpd) {
if (ObjectMap.find(pObject) == ObjectMap.end())
return;
bool lock = getTree()->blockConnection(true);
bool lock = getTree()->blockSelection(true);
// We are trying to select all items corresponding to a given view
// provider, i.e. all appearance of the object inside all its parent items
@@ -4542,7 +4542,7 @@ void DocumentItem::selectAllInstances(const ViewProviderDocumentObject& vpd) {
first = item;
END_FOREACH_ITEM;
getTree()->blockConnection(lock);
getTree()->blockSelection(lock);
if (first) {
treeWidget()->scrollToItem(first);
updateSelection();
@@ -4594,9 +4594,9 @@ void DocumentItem::updateItemsVisibility(QTreeWidgetItem* item, bool show) {
}
void DocumentItem::updateSelection() {
bool lock = getTree()->blockConnection(true);
bool lock = getTree()->blockSelection(true);
updateSelection(this, false);
getTree()->blockConnection(lock);
getTree()->blockSelection(lock);
}
// ----------------------------------------------------------------------------