[TD]fix scene and tree selection sync
This commit is contained in:
@@ -727,6 +727,17 @@ bool DrawGuiUtil::findObjectInSelection(const std::vector<Gui::SelectionObject>&
|
||||
return false;
|
||||
}
|
||||
|
||||
std::vector<std::string> DrawGuiUtil::getSubsForSelectedObject(const std::vector<Gui::SelectionObject>& selection,
|
||||
App::DocumentObject* selectedObj)
|
||||
{
|
||||
for (auto& selObj : selection) {
|
||||
if (selectedObj == selObj.getObject()) {
|
||||
return selObj.getSubNames();
|
||||
}
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
bool DrawGuiUtil::isStyleSheetDark(std::string curStyleSheet)
|
||||
{
|
||||
if (curStyleSheet.find("dark") != std::string::npos ||
|
||||
|
||||
@@ -91,6 +91,8 @@ class TechDrawGuiExport DrawGuiUtil {
|
||||
|
||||
static bool findObjectInSelection(const std::vector<Gui::SelectionObject>& selection,
|
||||
const App::DocumentObject& targetObject);
|
||||
static std::vector<std::string> getSubsForSelectedObject(const std::vector<Gui::SelectionObject>& selection,
|
||||
App::DocumentObject* selectedObj);
|
||||
};
|
||||
|
||||
} //end namespace TechDrawGui
|
||||
|
||||
@@ -62,6 +62,7 @@
|
||||
#include "ViewProviderDrawingView.h"
|
||||
#include "ViewProviderPage.h"
|
||||
#include "ZVALUE.h"
|
||||
#include "DrawGuiUtil.h"
|
||||
|
||||
|
||||
using namespace TechDrawGui;
|
||||
@@ -194,10 +195,8 @@ QVariant QGIView::itemChange(GraphicsItemChange change, const QVariant &value)
|
||||
if (change == ItemSelectedHasChanged && scene()) {
|
||||
if(isSelected()) {
|
||||
m_colCurrent = getSelectColor();
|
||||
// m_selectState = 2;
|
||||
} else {
|
||||
m_colCurrent = PreferencesGui::getAccessibleQColor(PreferencesGui::normalQColor());
|
||||
// m_selectState = 0;
|
||||
}
|
||||
drawBorder();
|
||||
}
|
||||
@@ -290,7 +289,6 @@ void QGIView::snapPosition(QPointF& mPos)
|
||||
|
||||
void QGIView::mousePressEvent(QGraphicsSceneMouseEvent * event)
|
||||
{
|
||||
// Base::Console().Message("QGIV::mousePressEvent() - %s\n", getViewName());
|
||||
Qt::KeyboardModifiers originalModifiers = event->modifiers();
|
||||
if (event->button()&Qt::LeftButton) {
|
||||
m_multiselectActivated = false;
|
||||
@@ -298,10 +296,8 @@ void QGIView::mousePressEvent(QGraphicsSceneMouseEvent * event)
|
||||
|
||||
if (event->button() == Qt::LeftButton && PreferencesGui::multiSelection()) {
|
||||
std::vector<Gui::SelectionObject> selection = Gui::Selection().getSelectionEx();
|
||||
if (selection.size() == 1
|
||||
&& selection.front().getObject() == getViewObject()
|
||||
&& selection.front().hasSubNames()) {
|
||||
|
||||
if (!DrawGuiUtil::getSubsForSelectedObject(selection, getViewObject()).empty()) {
|
||||
// we have already selected geometry for this view
|
||||
m_multiselectActivated = true;
|
||||
event->setModifiers(originalModifiers | Qt::ControlModifier);
|
||||
}
|
||||
@@ -319,7 +315,6 @@ void QGIView::mouseMoveEvent(QGraphicsSceneMouseEvent * event)
|
||||
|
||||
void QGIView::mouseReleaseEvent(QGraphicsSceneMouseEvent * event)
|
||||
{
|
||||
// Base::Console().Message("QGIV::mouseReleaseEvent() - %s\n", getViewName());
|
||||
Qt::KeyboardModifiers originalModifiers = event->modifiers();
|
||||
if ((event->button()&Qt::LeftButton) && m_multiselectActivated) {
|
||||
if (PreferencesGui::multiSelection()) {
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
#ifndef _PreComp_
|
||||
#include <QDomDocument>
|
||||
#include <QFile>
|
||||
#include <QGraphicsSceneEvent>
|
||||
#include <QPainter>
|
||||
#include <QSvgGenerator>
|
||||
#include <QTemporaryFile>
|
||||
@@ -81,6 +82,7 @@
|
||||
#include "ViewProviderDrawingView.h"
|
||||
#include "ViewProviderPage.h"
|
||||
#include "ZVALUE.h"
|
||||
#include "PreferencesGui.h"
|
||||
|
||||
|
||||
// used SVG namespaces
|
||||
@@ -104,6 +106,53 @@ QGSPage::QGSPage(ViewProviderPage* vpPage, QWidget* parent)
|
||||
// setItemIndexMethod(QGraphicsScene::NoIndex); //sometimes faster
|
||||
}
|
||||
|
||||
|
||||
void QGSPage::mousePressEvent(QGraphicsSceneMouseEvent * event)
|
||||
{
|
||||
constexpr int QGITemplateType{QGraphicsItem::UserType + 150};
|
||||
constexpr int QGIDrawingTemplateType{QGraphicsItem::UserType + 151};
|
||||
constexpr int QGISVGTemplateType{QGraphicsItem::UserType + 153};
|
||||
// type 13 is the itemUnderMouse on a page outside of any views. It is not
|
||||
// the template or background or foreground. QGraphicsItem type = 13 is not
|
||||
// documented and not found in QGraphicsItem.h.
|
||||
constexpr int MysteryType{13};
|
||||
|
||||
Qt::KeyboardModifiers originalModifiers = event->modifiers();
|
||||
auto itemUnderMouse = itemAt(event->scenePos().x(), event->scenePos().y(), QTransform());
|
||||
|
||||
if (!itemUnderMouse ||
|
||||
itemUnderMouse->type() == QGITemplateType ||
|
||||
itemUnderMouse->type() == QGIDrawingTemplateType ||
|
||||
itemUnderMouse->type() == QGISVGTemplateType ||
|
||||
itemUnderMouse->type() == MysteryType) {
|
||||
// click without item clears selection
|
||||
for (auto& item : selectedItems()) {
|
||||
item->setSelected(false);
|
||||
}
|
||||
QGraphicsScene::mousePressEvent(event);
|
||||
return;
|
||||
}
|
||||
|
||||
if (event->button() == Qt::LeftButton && PreferencesGui::multiSelection()) {
|
||||
event->setModifiers(originalModifiers | Qt::ControlModifier);
|
||||
}
|
||||
|
||||
QGraphicsScene::mousePressEvent(event);
|
||||
}
|
||||
|
||||
void QGSPage::mouseReleaseEvent(QGraphicsSceneMouseEvent * event)
|
||||
{
|
||||
Qt::KeyboardModifiers originalModifiers = event->modifiers();
|
||||
if ((event->button() == Qt::LeftButton) && PreferencesGui::multiSelection()) {
|
||||
event->setModifiers(originalModifiers | Qt::ControlModifier);
|
||||
}
|
||||
|
||||
QGraphicsScene::mouseReleaseEvent(event);
|
||||
|
||||
event->setModifiers(originalModifiers);
|
||||
}
|
||||
|
||||
|
||||
void QGSPage::addChildrenToPage()
|
||||
{
|
||||
// Base::Console().Message("QGSP::addChildrenToPage()\n");
|
||||
|
||||
@@ -149,6 +149,9 @@ public:
|
||||
|
||||
|
||||
protected:
|
||||
void mousePressEvent(QGraphicsSceneMouseEvent *event) override;
|
||||
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override;
|
||||
|
||||
QColor getBackgroundColor();
|
||||
bool orphanExists(const char* viewName, const std::vector<App::DocumentObject*>& list);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user