[TD]fix fail to clear frame on selection change

This commit is contained in:
wandererfan
2025-11-05 16:17:35 -05:00
committed by Chris Hennes
parent 92690acc85
commit 2e32a93ba7
3 changed files with 23 additions and 18 deletions

View File

@@ -168,7 +168,6 @@ void QGIView::alignTo(QGraphicsItem*item, const QString &alignment)
QVariant QGIView::itemChange(GraphicsItemChange change, const QVariant &value)
{
// Base::Console().message("QGIV::itemChange(%d)\n", change);
if(change == ItemPositionChange && scene()) {
QPointF newPos = value.toPointF(); //position within parent!
TechDraw::DrawView* viewObj = getViewObject();
@@ -196,13 +195,10 @@ QVariant QGIView::itemChange(GraphicsItemChange change, const QVariant &value)
return newPos;
}
// wf: why scene()? because if our selected state has changed because we have been removed from
// the scene, we don't do anything except wait to be deleted.
if (change == ItemSelectedHasChanged && scene()) {
std::vector<Gui::SelectionObject> currentSelection = Gui::Selection().getSelectionEx();
bool isViewObjectSelected = Gui::Selection().isSelected(getViewObject());
bool hasSelectedSubElements =
!DrawGuiUtil::getSubsForSelectedObject(currentSelection, getViewObject()).empty();
if (isViewObjectSelected || hasSelectedSubElements) {
if (isSelected() || hasSelectedChildren(this)) {
m_colCurrent = getSelectColor();
m_border->show();
m_label->show();
@@ -220,7 +216,6 @@ QVariant QGIView::itemChange(GraphicsItemChange change, const QVariant &value)
}
}
drawBorder();
update();
}
return QGraphicsItemGroup::itemChange(change, value);
@@ -537,7 +532,6 @@ void QGIView::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
m_lock->setVisible(getViewObject()->isLocked() && getViewObject()->showLock());
drawBorder();
update();
}
@@ -560,13 +554,11 @@ void QGIView::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
}
drawBorder();
update();
}
//sets position in /Gui(graphics), not /App
void QGIView::setPosition(qreal xPos, qreal yPos)
{
// Base::Console().message("QGIV::setPosition(%.3f, %.3f) (gui)\n", x, y);
double newX = xPos;
double newY = -yPos;
double oldX = pos().x();
@@ -595,8 +587,6 @@ QGIViewClip* QGIView::getClipGroup()
void QGIView::updateView(bool forceUpdate)
{
// Base::Console().message("QGIV::updateView() - %s\n", getViewObject()->getNameInDocument());
//allow/prevent dragging
if (getViewObject()->isLocked()) {
setFlag(QGraphicsItem::ItemIsMovable, false);
@@ -678,7 +668,6 @@ void QGIView::toggleCache(bool state)
void QGIView::draw()
{
// Base::Console().message("QGIV::draw()\n");
double xFeat, yFeat;
if (getViewObject()) {
xFeat = Rez::guiX(getViewObject()->X.getValue());
@@ -742,10 +731,10 @@ void QGIView::layoutDecorations(const QRectF& contentArea,
void QGIView::drawBorder()
{
// Base::Console().message("QGIV::drawBorder() - %s\n", getViewName());
auto feat = getViewObject();
if (!feat)
if (!feat) {
return;
}
prepareCaption();
@@ -1060,6 +1049,20 @@ void QGIView::makeMark(double xPos, double yPos, QColor color)
vItem->setZValue(ZVALUE::VERTEX);
}
//! true if parent has any children which are selected
bool QGIView::hasSelectedChildren(QGIView* parent)
{
QList<QGraphicsItem*> children = parent->childItems();
auto itMatch = std::find_if(children.begin(), children.end(),
[&](QGraphicsItem* child) {
return child->isSelected();
});
return itMatch != children.end();
}
void QGIView::makeMark(Base::Vector3d pos, QColor color)
{
makeMark(pos.x, pos.y, color);
@@ -1070,6 +1073,7 @@ void QGIView::makeMark(QPointF pos, QColor color)
makeMark(pos.x(), pos.y(), color);
}
//! Retrieves objects of type T with given indexes
template <typename T>
std::vector<T> QGIView::getObjects(std::vector<int> indexes)

View File

@@ -174,6 +174,8 @@ public:
bool pseudoEventFilter(QGraphicsItem *watched, QEvent *event) { return sceneEventFilter(watched, event); }
static bool hasSelectedChildren(QGIView* parent);
protected:
QGIView* getQGIVByName(std::string name) const;

View File

@@ -116,7 +116,7 @@ QVariant QGIViewPart::itemChange(GraphicsItemChange change, const QVariant& valu
}
return QGIView::itemChange(change, value);
}
// we are selected
// we are selected, don't change anything?
}
else if (change == ItemSceneChange && scene()) {
// This means we are finished?
@@ -140,7 +140,6 @@ QVariant QGIViewPart::itemChange(GraphicsItemChange change, const QVariant& valu
child->hide();
}
}
update();
}
});
}