Skip to content

Commit

Permalink
Change current layer depending on selected objects (#1466)
Browse files Browse the repository at this point in the history
Closes #1424
  • Loading branch information
Glavak authored and bjorn committed Mar 6, 2017
1 parent 6db4285 commit cd87cbc
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
19 changes: 18 additions & 1 deletion src/tiled/mapdocument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ void MapDocument::setCurrentLayer(Layer *layer)
mCurrentLayer = layer;
emit currentLayerChanged(mCurrentLayer);

if (mCurrentLayer)
if (mCurrentLayer && currentObject()->typeId() == Object::LayerType)
setCurrentObject(mCurrentLayer);
}

Expand Down Expand Up @@ -659,6 +659,23 @@ void MapDocument::setSelectedObjects(const QList<MapObject *> &selectedObjects)
mSelectedObjects = selectedObjects;
emit selectedObjectsChanged();

ObjectGroup *singleObjectGroup = nullptr;
for (MapObject *object : selectedObjects) {
ObjectGroup *currentObjectGroup = object->objectGroup();

if (!singleObjectGroup) {
singleObjectGroup = currentObjectGroup;
} else if (singleObjectGroup != currentObjectGroup) {
singleObjectGroup = nullptr;
break;
}
}

// Switch the current object layer if only one object layer (and/or its objects)
// are included in the current selection.
if (singleObjectGroup)
setCurrentLayer(singleObjectGroup);

if (selectedObjects.size() == 1)
setCurrentObject(selectedObjects.first());
}
Expand Down
17 changes: 0 additions & 17 deletions src/tiled/objectsdock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -349,32 +349,15 @@ void ObjectsView::selectionChanged(const QItemSelection &selected,
return;

const QModelIndexList selectedProxyRows = selectionModel()->selectedRows();
ObjectGroup *singleObjectGroup = nullptr;
bool multipleObjectGroups = false;

QList<MapObject*> selectedObjects;
for (const QModelIndex &proxyIndex : selectedProxyRows) {
const QModelIndex index = mProxyModel->mapToSource(proxyIndex);

if (ObjectGroup *og = mapObjectModel()->toObjectGroupContext(index)) {
if (!multipleObjectGroups) {
if (!singleObjectGroup) {
singleObjectGroup = og;
} else if (singleObjectGroup != og) {
singleObjectGroup = nullptr;
multipleObjectGroups = true;
}
}
}
if (MapObject *o = mapObjectModel()->toMapObject(index))
selectedObjects.append(o);
}

// Switch the current object layer if only one object layer (and/or its objects)
// are included in the current selection.
if (singleObjectGroup)
mMapDocument->setCurrentLayer(singleObjectGroup);

if (selectedObjects != mMapDocument->selectedObjects()) {
mSynching = true;
if (selectedObjects.count() == 1) {
Expand Down

0 comments on commit cd87cbc

Please sign in to comment.