Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
A GroupLayer is a new kind of layer that can contain other layers. It is meant for organizing layers in folders in case you are working with maps that have a large amount of layers. The visibility, opacity and later also locked status of the group layer will affect all child layers. Also the Layers view will allow collapsing group layers. This change is only the start. The addition of group layers is expected to affect a large amount of code.
- Loading branch information
Showing
28 changed files
with
464 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
/* | ||
* grouplayer.cpp | ||
* Copyright 2017, Thorbjørn Lindeijer <bjorn@lindeijer.nl> | ||
* | ||
* This file is part of Tiled. | ||
* | ||
* This program is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU General Public License as published by the Free | ||
* Software Foundation; either version 2 of the License, or (at your option) | ||
* any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
* more details. | ||
* | ||
* You should have received a copy of the GNU General Public License along with | ||
* this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#include "grouplayer.h" | ||
|
||
#include "map.h" | ||
|
||
namespace Tiled { | ||
|
||
GroupLayer::GroupLayer(const QString &name, int x, int y): | ||
Layer(GroupLayerType, name, x, y) | ||
{ | ||
} | ||
|
||
GroupLayer::~GroupLayer() | ||
{ | ||
qDeleteAll(mLayers); | ||
} | ||
|
||
void GroupLayer::addLayer(Layer *layer) | ||
{ | ||
adoptLayer(layer); | ||
mLayers.append(layer); | ||
} | ||
|
||
void GroupLayer::insertLayer(int index, Layer *layer) | ||
{ | ||
adoptLayer(layer); | ||
mLayers.insert(index, layer); | ||
} | ||
|
||
void GroupLayer::adoptLayer(Layer *layer) | ||
{ | ||
layer->setMap(map()); | ||
|
||
if (map()) | ||
if (ObjectGroup *group = layer->asObjectGroup()) | ||
map()->initializeObjectIds(*group); | ||
} | ||
|
||
Layer *GroupLayer::takeLayerAt(int index) | ||
{ | ||
Layer *layer = mLayers.takeAt(index); | ||
layer->setMap(nullptr); | ||
return layer; | ||
} | ||
|
||
void GroupLayer::setMap(Map *map) | ||
{ | ||
// todo: What about initializing object IDs? | ||
Layer::setMap(map); | ||
for (Layer *layer : mLayers) | ||
layer->setMap(map); | ||
} | ||
|
||
bool GroupLayer::isEmpty() const | ||
{ | ||
return mLayers.isEmpty(); | ||
} | ||
|
||
QSet<SharedTileset> GroupLayer::usedTilesets() const | ||
{ | ||
QSet<SharedTileset> tilesets; | ||
|
||
for (const Layer *layer : mLayers) | ||
tilesets |= layer->usedTilesets(); | ||
|
||
return tilesets; | ||
} | ||
|
||
bool GroupLayer::referencesTileset(const Tileset *tileset) const | ||
{ | ||
for (const Layer *layer : mLayers) | ||
if (layer->referencesTileset(tileset)) | ||
return true; | ||
|
||
return false; | ||
} | ||
|
||
void GroupLayer::replaceReferencesToTileset(Tileset *oldTileset, Tileset *newTileset) | ||
{ | ||
const auto &children = mLayers; | ||
for (Layer *layer : children) | ||
layer->replaceReferencesToTileset(oldTileset, newTileset); | ||
} | ||
|
||
bool GroupLayer::canMergeWith(Layer *) const | ||
{ | ||
// Merging group layers would be possible, but duplicating all child layers | ||
// is not the right approach. | ||
// todo: implement special case of reparenting child layers | ||
return false; | ||
} | ||
|
||
Layer *GroupLayer::mergedWith(Layer *) const | ||
{ | ||
return nullptr; | ||
} | ||
|
||
Layer *GroupLayer::clone() const | ||
{ | ||
return initializeClone(new GroupLayer(mName, mX, mY)); | ||
} | ||
|
||
GroupLayer *GroupLayer::initializeClone(GroupLayer *clone) const | ||
{ | ||
Layer::initializeClone(clone); | ||
for (const Layer *layer : mLayers) | ||
clone->addLayer(layer->clone()); | ||
return clone; | ||
} | ||
|
||
} // namespace Tiled |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* | ||
* grouplayer.h | ||
* Copyright 2017, Thorbjørn Lindeijer <bjorn@lindeijer.nl> | ||
* | ||
* This file is part of Tiled. | ||
* | ||
* This program is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU General Public License as published by the Free | ||
* Software Foundation; either version 2 of the License, or (at your option) | ||
* any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
* more details. | ||
* | ||
* You should have received a copy of the GNU General Public License along with | ||
* this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#ifndef GROUPLAYER_H | ||
#define GROUPLAYER_H | ||
|
||
#include "layer.h" | ||
|
||
#include <QList> | ||
|
||
namespace Tiled { | ||
|
||
class TILEDSHARED_EXPORT GroupLayer : public Layer | ||
{ | ||
public: | ||
GroupLayer(const QString &name, int x, int y); | ||
~GroupLayer(); | ||
|
||
int layerCount() const; | ||
Layer *layerAt(int index) const; | ||
const QList<Layer*> &layers() const { return mLayers; } | ||
|
||
void addLayer(Layer *layer); | ||
void insertLayer(int index, Layer *layer); | ||
Layer *takeLayerAt(int index); | ||
|
||
void setMap(Map *map) override; | ||
bool isEmpty() const override; | ||
QSet<SharedTileset> usedTilesets() const override; | ||
bool referencesTileset(const Tileset *tileset) const override; | ||
void replaceReferencesToTileset(Tileset *oldTileset, Tileset *newTileset) override; | ||
bool canMergeWith(Layer *other) const override; | ||
Layer *mergedWith(Layer *other) const override; | ||
Layer *clone() const override; | ||
|
||
// Enable easy iteration over children with range-based for | ||
QList<Layer*>::iterator begin() { return mLayers.begin(); } | ||
QList<Layer*>::iterator end() { return mLayers.end(); } | ||
QList<Layer*>::const_iterator begin() const { return mLayers.begin(); } | ||
QList<Layer*>::const_iterator end() const { return mLayers.end(); } | ||
|
||
protected: | ||
GroupLayer *initializeClone(GroupLayer *clone) const; | ||
|
||
private: | ||
void adoptLayer(Layer *layer); | ||
|
||
QList<Layer*> mLayers; | ||
}; | ||
|
||
|
||
inline int GroupLayer::layerCount() const | ||
{ | ||
return mLayers.size(); | ||
} | ||
|
||
inline Layer *GroupLayer::layerAt(int index) const | ||
{ | ||
return mLayers.at(index); | ||
} | ||
|
||
} // namespace Tiled | ||
|
||
#endif // GROUPLAYER_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.