Skip to content

Commit 576ac1f

Browse files
committed
Apply changes to map objects to all selected objects
Also made the changes to layer offset and object flipping more specific, only changing the actually changing axis for all selected layers or objects respectively. The same still needs to be done for changing object position or size.
1 parent 10f72d3 commit 576ac1f

File tree

1 file changed

+58
-13
lines changed

1 file changed

+58
-13
lines changed

src/tiled/propertieswidget.cpp

+58-13
Original file line numberDiff line numberDiff line change
@@ -1207,11 +1207,25 @@ class LayerProperties : public ObjectProperties
12071207
tr("Offset"),
12081208
[this] { return layer()->offset(); },
12091209
[this](const QPointF &value) {
1210-
// todo: consider whether we can apply only the changed axis to the selected layers
1211-
// this is what PropertyBrowser::applyLayerValue used to do
1210+
const auto oldValue = layer()->offset();
1211+
const bool changedX = oldValue.x() != value.x();
1212+
const bool changedY = oldValue.y() != value.y();
1213+
1214+
QVector<QPointF> offsets;
1215+
for (const Layer *layer : mapDocument()->selectedLayers())
1216+
offsets.append(layer->offset());
1217+
1218+
if (changedX) {
1219+
for (QPointF &offset : offsets)
1220+
offset.setX(value.x());
1221+
} else if (changedY) {
1222+
for (QPointF &offset : offsets)
1223+
offset.setY(value.y());
1224+
}
1225+
12121226
push(new SetLayerOffset(mapDocument(),
12131227
mapDocument()->selectedLayers(),
1214-
value));
1228+
offsets));
12151229
});
12161230

12171231
mParallaxFactorProperty = new PointFProperty(
@@ -1771,20 +1785,29 @@ class MapObjectProperties : public ObjectProperties
17711785
return mapObject()->cell().flags();
17721786
},
17731787
[this](const int &value) {
1774-
const int flippingFlags = value;
1775-
1776-
MapObjectCell mapObjectCell;
1777-
mapObjectCell.object = mapObject();
1778-
mapObjectCell.cell = mapObject()->cell();
1779-
mapObjectCell.cell.setFlippedHorizontally(flippingFlags & 1);
1780-
mapObjectCell.cell.setFlippedVertically(flippingFlags & 2);
1788+
const int oldValue = mapObject()->cell().flags();
1789+
const bool changedHorizontally = (oldValue & 1) != (value & 1);
1790+
const bool changedVertically = (oldValue & 2) != (value & 2);
1791+
1792+
QVector<MapObjectCell> objectChanges;
1793+
1794+
for (MapObject *object : mapDocument()->selectedObjects()) {
1795+
MapObjectCell mapObjectCell;
1796+
mapObjectCell.object = object;
1797+
mapObjectCell.cell = object->cell();
1798+
if (changedHorizontally)
1799+
mapObjectCell.cell.setFlippedHorizontally(value & 1);
1800+
if (changedVertically)
1801+
mapObjectCell.cell.setFlippedVertically(value & 2);
1802+
objectChanges.append(mapObjectCell);
1803+
}
17811804

1782-
auto command = new ChangeMapObjectCells(mDocument, { mapObjectCell });
1805+
auto command = new ChangeMapObjectCells(mDocument, objectChanges);
17831806

17841807
command->setText(QCoreApplication::translate("Undo Commands",
17851808
"Flip %n Object(s)",
17861809
nullptr,
1787-
mapDocument()->selectedObjects().size()));
1810+
objectChanges.size()));
17881811
push(command);
17891812
});
17901813

@@ -1938,7 +1961,29 @@ class MapObjectProperties : public ObjectProperties
19381961

19391962
void changeMapObject(MapObject::Property property, const QVariant &value)
19401963
{
1941-
push(new ChangeMapObject(mapDocument(), mapObject(), property, value));
1964+
// todo: when changing object position or size, only change the
1965+
// selected objects in the respective axis or dimension
1966+
QUndoCommand *command = new ChangeMapObject(mapDocument(), mapObject(),
1967+
property, value);
1968+
1969+
if (mapDocument()->selectedObjects().size() == 1) {
1970+
push(command);
1971+
return;
1972+
}
1973+
1974+
auto undoStack = mDocument->undoStack();
1975+
undoStack->beginMacro(command->text());
1976+
undoStack->push(command);
1977+
1978+
for (MapObject *obj : mapDocument()->selectedObjects()) {
1979+
if (obj != mapObject()) {
1980+
QUndoCommand *cmd = new ChangeMapObject(mapDocument(), obj,
1981+
property, value);
1982+
undoStack->push(cmd);
1983+
}
1984+
}
1985+
1986+
mDocument->undoStack()->endMacro();
19421987
}
19431988

19441989
GroupProperty *mObjectProperties;

0 commit comments

Comments
 (0)