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

Delay loading of tile stamps until after initializing the session #4044

Open
wants to merge 1 commit 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
6 changes: 6 additions & 0 deletions src/tiled/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
#include "tilesetdocument.h"
#include "tileseteditor.h"
#include "tilesetmanager.h"
#include "tilestampmanager.h"
#include "tmxmapformat.h"
#include "utils.h"
#include "world.h"
Expand Down Expand Up @@ -1017,6 +1018,11 @@ void MainWindow::initializeSession()
// adding the project's extension path.
ScriptManager::instance().ensureInitialized();

// Load tile stamps (delayed so that potential custom types and file
// formats can be supported by stamps - which isn't perfect since there
// will still be issues when the project isn't open on startup)
TileStampManager::instance()->loadStamps();

if (projectLoaded || Preferences::instance()->restoreSessionOnStartup())
restoreSession();
}
Expand Down
5 changes: 5 additions & 0 deletions src/tiled/projectmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ ProjectManager::ProjectManager(QObject *parent)
ourInstance = this;
}

ProjectManager::~ProjectManager()
{
ourInstance = nullptr;
}

/**
* Replaces the current project with the given \a project.
*/
Expand Down
1 change: 1 addition & 0 deletions src/tiled/projectmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class TILED_EDITOR_EXPORT ProjectManager : public QObject

public:
explicit ProjectManager(QObject *parent = nullptr);
~ProjectManager() override;

static ProjectManager *instance();

Expand Down
13 changes: 7 additions & 6 deletions src/tiled/tilestampmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@
#include "preferences.h"
#include "savefile.h"
#include "stampbrush.h"
#include "tilelayer.h"
#include "tileselectiontool.h"
#include "tileset.h"
#include "tilesetmanager.h"
#include "tilestampmodel.h"
#include "toolmanager.h"
#include "utils.h"
Expand All @@ -46,6 +42,8 @@

using namespace Tiled;

TileStampManager *TileStampManager::ourInstance;

TileStampManager::TileStampManager(const ToolManager &toolManager,
QObject *parent)
: QObject(parent)
Expand All @@ -54,6 +52,9 @@ TileStampManager::TileStampManager(const ToolManager &toolManager,
, mTileStampModel(new TileStampModel(this))
, mToolManager(toolManager)
{
Q_ASSERT(!ourInstance);
ourInstance = this;

mRegisteredCb = stampsDirectory.onChange([this] { stampsDirectoryChanged(); });

connect(mTileStampModel, &TileStampModel::stampAdded,
Expand All @@ -64,15 +65,15 @@ TileStampManager::TileStampManager(const ToolManager &toolManager,
this, &TileStampManager::saveStamp);
connect(mTileStampModel, &TileStampModel::stampRemoved,
this, &TileStampManager::deleteStamp);

loadStamps();
}

TileStampManager::~TileStampManager()
{
// needs to be over here where the TileStamp type is complete

stampsDirectory.unregister(mRegisteredCb);

ourInstance = nullptr;
}

static TileStamp stampFromContext(AbstractTool *selectedTool)
Expand Down
13 changes: 11 additions & 2 deletions src/tiled/tilestampmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,16 @@ class TileStampManager : public QObject
TileStampManager(const ToolManager &toolManager, QObject *parent = nullptr);
~TileStampManager() override;

static TileStampManager *instance();

static QList<Qt::Key> quickStampKeys();

TileStampModel *tileStampModel() const;

SessionOption<QString> stampsDirectory;

void loadStamps();

public slots:
TileStamp createStamp();
void addVariation(const TileStamp &targetStamp);
Expand All @@ -76,8 +80,6 @@ public slots:
void eraseQuickStamp(int index);
void setQuickStamp(int index, TileStamp stamp);

void loadStamps();

private:
void stampAdded(TileStamp stamp);
void stampRenamed(TileStamp stamp);
Expand All @@ -93,9 +95,16 @@ public slots:
Session::CallbackIterator mRegisteredCb;

const ToolManager &mToolManager;

static TileStampManager *ourInstance;
};


inline TileStampManager *TileStampManager::instance()
{
return ourInstance;
}

/**
* Returns the keys used for quickly accessible tile stamps.
* Note: To store a tile layer <Ctrl> is added. The given keys will work
Expand Down