Skip to content

Commit c2e338e

Browse files
authored
Merge pull request #1179 from IKhonakhbeeva/walls
Fix moving multiple items [AUTOZIP]
2 parents 74eaee9 + 36545d4 commit c2e338e

File tree

6 files changed

+32
-12
lines changed

6 files changed

+32
-12
lines changed

plugins/robots/common/twoDModel/src/engine/items/wallItem.cpp

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ WallItem::WallItem(const QPointF &begin, const QPointF &end)
3535
setFlags(ItemIsSelectable | ItemIsMovable | ItemSendsScenePositionChanges);
3636
setPrivateData();
3737
setAcceptDrops(true);
38+
connect(this, &AbstractItem::mouseInteractionStarted, this, [this](){
39+
mEstimatedPos = pos();
40+
});
3841
}
3942

4043
WallItem *WallItem::clone() const
@@ -191,6 +194,8 @@ void WallItem::recalculateBorders()
191194

192195
void WallItem::resizeItem(QGraphicsSceneMouseEvent *event)
193196
{
197+
mEstimatedPos += event->scenePos() - event->lastScenePos();
198+
194199
if (event->modifiers() & Qt::ShiftModifier && (dragState() == TopLeft || dragState() == BottomRight)) {
195200
AbstractItem::resizeItem(event);
196201
reshapeRectWithShift();
@@ -245,7 +250,7 @@ void WallItem::resizeWithGrid(QGraphicsSceneMouseEvent *event, int indexGrid)
245250
const qreal x = mapFromScene(event->scenePos()).x();
246251
const qreal y = mapFromScene(event->scenePos()).y();
247252

248-
setFlag(QGraphicsItem::ItemIsMovable, dragState() == None);
253+
setFlag(QGraphicsItem::ItemIsMovable, false);
249254

250255
if (dragState() == TopLeft) {
251256
setX1(x);
@@ -256,26 +261,26 @@ void WallItem::resizeWithGrid(QGraphicsSceneMouseEvent *event, int indexGrid)
256261
setY2(y);
257262
reshapeEndWithGrid(indexGrid);
258263
} else {
259-
auto newPos = QPointF(alignedCoordinate(pos().x(), indexGrid),
260-
alignedCoordinate(pos().y(), indexGrid));
261-
setPos(newPos);
262-
update();
264+
setPos(mEstimatedPos);
265+
moveBy(alignedCoordinate(begin().x(), indexGrid) - begin().x()
266+
, alignedCoordinate(begin().y(), indexGrid) - begin().y());
263267
}
264268
}
265269

266270
void WallItem::reshapeEndWithGrid(int indexGrid)
267271
{
268-
setX2(alignedCoordinate(x2(), indexGrid));
269-
setY2(alignedCoordinate(y2(), indexGrid));
272+
setX2(alignedCoordinate(end().x(), indexGrid) - pos().x());
273+
setY2(alignedCoordinate(end().y(), indexGrid) - pos().y());
270274

271275
mCellNumbX2 = x2() / indexGrid;
272276
mCellNumbY2 = y2() / indexGrid;
273277
}
274278

275279
void WallItem::reshapeBeginWithGrid(int indexGrid)
276280
{
277-
setX1(alignedCoordinate(x1(), indexGrid));
278-
setY1(alignedCoordinate(y1(), indexGrid));
281+
setX1(alignedCoordinate(begin().x(), indexGrid) - pos().x());
282+
setY1(alignedCoordinate(begin().y(), indexGrid) - pos().y());
283+
279284
mCellNumbX1 = x1() / indexGrid;
280285
mCellNumbY1 = y1() / indexGrid;
281286
}

plugins/robots/common/twoDModel/src/engine/items/wallItem.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ class WallItem : public graphicsUtils::AbstractItem, public SolidItem
9393

9494
QPainterPath mPath;
9595
int mWallWidth {10};
96+
QPointF mEstimatedPos;
9697
};
9798

9899
}

qrtranslations/fr/plugins/robots/twoDModel_fr.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@
353353
<context>
354354
<name>twoDModel::items::WallItem</name>
355355
<message>
356-
<location filename="../../../../plugins/robots/common/twoDModel/src/engine/items/wallItem.cpp" line="+61"/>
356+
<location filename="../../../../plugins/robots/common/twoDModel/src/engine/items/wallItem.cpp" line="+64"/>
357357
<source>Wall (W)</source>
358358
<translation>Mur (W)</translation>
359359
</message>

qrtranslations/ru/plugins/robots/twoDModel_ru.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,7 @@
629629
<context>
630630
<name>twoDModel::items::WallItem</name>
631631
<message>
632-
<location filename="../../../../plugins/robots/common/twoDModel/src/engine/items/wallItem.cpp" line="+61"/>
632+
<location filename="../../../../plugins/robots/common/twoDModel/src/engine/items/wallItem.cpp" line="+64"/>
633633
<source>Wall (W)</source>
634634
<translation>Стена (W)</translation>
635635
</message>

qrutils/graphicsUtils/abstractItem.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,7 @@ void AbstractItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
596596

597597
void AbstractItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
598598
{
599+
setFlag(QGraphicsItem::ItemIsMovable, mEditable);
599600
QGraphicsItem::mouseReleaseEvent(event);
600601
emit mouseInteractionStopped();
601602
}

qrutils/graphicsUtils/abstractScene.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,25 @@ void AbstractScene::setX2andY2(QGraphicsSceneMouseEvent *event)
8383

8484
void AbstractScene::reshapeItem(QGraphicsSceneMouseEvent *event)
8585
{
86+
setX2andY2(event);
87+
if (!mGraphicsItem) return;
88+
auto oldPos = mGraphicsItem->pos();
8689
reshapeItem(event, mGraphicsItem);
90+
auto delta = mGraphicsItem->pos() - oldPos;
91+
if (mGraphicsItem->isSelected()) {
92+
mGraphicsItem->setPos(oldPos);
93+
}
94+
for (auto selectedItem : selectedItems()) {
95+
if (auto item = dynamic_cast<AbstractItem*>(selectedItem)) {
96+
if (!item->parentItem()) {
97+
item->moveBy(delta.x(), delta.y());
98+
}
99+
}
100+
}
87101
}
88102

89103
void AbstractScene::reshapeItem(QGraphicsSceneMouseEvent *event, graphicsUtils::AbstractItem *item)
90104
{
91-
setX2andY2(event);
92105
if (item && item->editable()) {
93106
if (item->dragState() != graphicsUtils::AbstractItem::None) {
94107
mView->setDragMode(QGraphicsView::NoDrag);

0 commit comments

Comments
 (0)