Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Expand/Collapse API to GroupLayer #4009

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions src/libtiled/grouplayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ class TILEDSHARED_EXPORT GroupLayer : public Layer
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:
void setMap(Map *map) override;
GroupLayer *initializeClone(GroupLayer *clone) const;
Expand All @@ -66,7 +65,6 @@ class TILEDSHARED_EXPORT GroupLayer : public Layer
QList<Layer*> mLayers;
};


inline int GroupLayer::layerCount() const
{
return mLayers.size();
Expand Down
17 changes: 17 additions & 0 deletions src/tiled/editablegrouplayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
#include "addremovetileset.h"
#include "editablemap.h"
#include "scriptmanager.h"
#include "documentmanager.h"
#include "mapeditor.h"
#include "layerdock.h"

#include <QCoreApplication>

Expand Down Expand Up @@ -136,6 +139,20 @@ void EditableGroupLayer::addLayer(EditableLayer *editableLayer)
insertLayerAt(layerCount(), editableLayer);
}

inline bool EditableGroupLayer::isExpanded() const
{
auto documentManager = DocumentManager::instance();
auto mapEditor = static_cast<MapEditor*>(documentManager->editor(Document::MapDocumentType));
return mapEditor->layerDock()->isExpanded(groupLayer());
}

inline void EditableGroupLayer::setExpanded(bool expanded)
{
auto documentManager = DocumentManager::instance();
auto mapEditor = static_cast<MapEditor*>(documentManager->editor(Document::MapDocumentType));
mapEditor->layerDock()->setExpanded(groupLayer(), expanded);
}

} // namespace Tiled

#include "moc_editablegrouplayer.cpp"
5 changes: 4 additions & 1 deletion src/tiled/editablegrouplayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class EditableGroupLayer : public EditableLayer

Q_PROPERTY(int layerCount READ layerCount)
Q_PROPERTY(QList<QObject*> layers READ layers)
Q_PROPERTY(bool expanded READ isExpanded WRITE setExpanded)

public:
Q_INVOKABLE explicit EditableGroupLayer(const QString &name = QString(),
Expand All @@ -49,8 +50,10 @@ class EditableGroupLayer : public EditableLayer
Q_INVOKABLE void insertLayerAt(int index, Tiled::EditableLayer *editableLayer);
Q_INVOKABLE void addLayer(Tiled::EditableLayer *editableLayer);

private:
bool isExpanded() const;
GroupLayer *groupLayer() const;
public slots:
void setExpanded(bool expanded);
};

inline int EditableGroupLayer::layerCount() const
Expand Down
17 changes: 17 additions & 0 deletions src/tiled/editableobjectgroup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
#include "editableasset.h"
#include "map.h"
#include "scriptmanager.h"
#include "documentmanager.h"
#include "mapeditor.h"
#include "objectsdock.h"

#include <QCoreApplication>

Expand Down Expand Up @@ -172,6 +175,20 @@ void EditableObjectGroup::setDrawOrder(DrawOrder drawOrder)
}
}

inline bool EditableObjectGroup::isExpanded() const
{
auto documentManager = DocumentManager::instance();
auto mapEditor = static_cast<MapEditor*>(documentManager->editor(Document::MapDocumentType));
return mapEditor->objectsDock()->isExpanded(objectGroup());
}

inline void EditableObjectGroup::setExpanded(bool expanded)
{
auto documentManager = DocumentManager::instance();
auto mapEditor = static_cast<MapEditor*>(documentManager->editor(Document::MapDocumentType));
mapEditor->objectsDock()->setExpanded(objectGroup(), expanded);
}

} // namespace Tiled

#include "moc_editableobjectgroup.cpp"
3 changes: 3 additions & 0 deletions src/tiled/editableobjectgroup.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class EditableObjectGroup : public EditableLayer
Q_PROPERTY(int objectCount READ objectCount)
Q_PROPERTY(QColor color READ color WRITE setColor)
Q_PROPERTY(DrawOrder drawOrder READ drawOrder WRITE setDrawOrder)
Q_PROPERTY(bool expanded READ isExpanded WRITE setExpanded)

public:
// Synchronized with ObjectGroup::DrawOrder
Expand Down Expand Up @@ -66,9 +67,11 @@ class EditableObjectGroup : public EditableLayer

static EditableObjectGroup *get(EditableAsset *asset, ObjectGroup *objectGroup);

bool isExpanded() const;
public slots:
void setColor(const QColor &color);
void setDrawOrder(DrawOrder drawOrder);
void setExpanded(bool expanded);
};


Expand Down
13 changes: 13 additions & 0 deletions src/tiled/layerdock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include "utils.h"
#include "iconcheckdelegate.h"
#include "changeevents.h"
#include "grouplayer.h"

#include <QApplication>
#include <QBoxLayout>
Expand Down Expand Up @@ -149,6 +150,18 @@ void LayerDock::setMapDocument(MapDocument *mapDocument)
updateOpacitySlider();
}

bool LayerDock::isExpanded(GroupLayer *layer) const {
auto sourceIndex = mMapDocument->layerModel()->index(layer);
auto index = mLayerView->proxyModel()->mapFromSource(sourceIndex);
return mLayerView->isExpanded(index);
}

void LayerDock::setExpanded(GroupLayer *layer, bool expanded) {
auto sourceIndex = mMapDocument->layerModel()->index(layer);
auto index = mLayerView->proxyModel()->mapFromSource(sourceIndex);
mLayerView->setExpanded(index, expanded);
}

void LayerDock::changeEvent(QEvent *e)
{
QDockWidget::changeEvent(e);
Expand Down
8 changes: 8 additions & 0 deletions src/tiled/layerdock.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#pragma once

#include "mapdocument.h"
#include "editablegrouplayer.h"

#include <QDockWidget>
#include <QTreeView>
Expand Down Expand Up @@ -54,6 +55,11 @@ class LayerDock : public QDockWidget
*/
void setMapDocument(MapDocument *mapDocument);

Q_INVOKABLE bool isExpanded(EditableGroupLayer *layer) const { return isExpanded(layer->groupLayer()); };
Q_INVOKABLE void setExpanded(EditableGroupLayer *layer, bool expanded) { setExpanded(layer->groupLayer(), expanded); };
bool isExpanded(GroupLayer *layer) const;
void setExpanded(GroupLayer *layer, bool expanded);

protected:
void changeEvent(QEvent *e) override;

Expand Down Expand Up @@ -90,6 +96,8 @@ class LayerView : public QTreeView

void editLayerModelIndex(const QModelIndex &layerModelIndex);

QAbstractProxyModel *proxyModel() { return mProxyModel; }

protected:
bool event(QEvent *event) override;
void contextMenuEvent(QContextMenuEvent *event) override;
Expand Down
4 changes: 4 additions & 0 deletions src/tiled/mapeditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ class MapEditor final : public Editor
Q_OBJECT

Q_PROPERTY(Tiled::TilesetDock *tilesetsView READ tilesetDock CONSTANT)
Q_PROPERTY(Tiled::LayerDock *layersView READ layerDock CONSTANT)
Q_PROPERTY(Tiled::ObjectsDock *objectsView READ objectsDock CONSTANT)
Q_PROPERTY(Tiled::EditableMap *currentBrush READ currentBrush WRITE setCurrentBrush)
Q_PROPERTY(Tiled::EditableWangSet *currentWangSet READ currentWangSet NOTIFY currentWangSetChanged)
Q_PROPERTY(int currentWangColorIndex READ currentWangColorIndex NOTIFY currentWangColorIndexChanged)
Expand All @@ -83,6 +85,8 @@ class MapEditor final : public Editor
~MapEditor() override;

TilesetDock *tilesetDock() const { return mTilesetDock; }
LayerDock *layerDock() const { return mLayerDock; }
ObjectsDock *objectsDock() const { return mObjectsDock; }
TemplatesDock *templatesDock() const { return mTemplatesDock; }

void saveState() override;
Expand Down
8 changes: 8 additions & 0 deletions src/tiled/objectsdock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,14 @@ void ObjectsDock::setMapDocument(MapDocument *mapDoc)
updateActions();
}

bool ObjectsDock::isExpanded(ObjectGroup *layer) const {
return mObjectsView->isExpanded(mObjectsView->layerViewIndex(layer));
}

void ObjectsDock::setExpanded(ObjectGroup *layer, bool expanded) {
mObjectsView->setExpanded(mObjectsView->layerViewIndex(layer), expanded);
}

void ObjectsDock::changeEvent(QEvent *e)
{
QDockWidget::changeEvent(e);
Expand Down
7 changes: 7 additions & 0 deletions src/tiled/objectsdock.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

#pragma once

#include "editableobjectgroup.h"

#include <QDockWidget>
#include <QMap>

Expand All @@ -41,6 +43,11 @@ class ObjectsDock : public QDockWidget

void setMapDocument(MapDocument *mapDoc);

Q_INVOKABLE bool isExpanded(EditableObjectGroup *layer) const { return isExpanded(layer->objectGroup()); };
Q_INVOKABLE void setExpanded(EditableObjectGroup *layer, bool expanded) { setExpanded(layer->objectGroup(), expanded); };
bool isExpanded(ObjectGroup *layer) const;
void setExpanded(ObjectGroup *layer, bool expanded);

protected:
void changeEvent(QEvent *e) override;

Expand Down
Loading