Skip to content

Commit

Permalink
start to add projectdocument to support project level properties
Browse files Browse the repository at this point in the history
  • Loading branch information
dogboydog committed May 13, 2023
1 parent 71bb232 commit 9259743
Show file tree
Hide file tree
Showing 7 changed files with 151 additions and 12 deletions.
3 changes: 2 additions & 1 deletion src/tiled/document.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ class Document : public QObject,
enum DocumentType {
MapDocumentType,
TilesetDocumentType,
WorldDocumentType
WorldDocumentType,
ProjectDocumentType
};

Document(DocumentType type,
Expand Down
11 changes: 10 additions & 1 deletion src/tiled/editableproject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@
*/

#include "editableproject.h"
#include "projectdocument.h"

namespace Tiled {

EditableProject::EditableProject(Project *project, QObject *parent)
: QObject(parent)
: EditableAsset(nullptr, nullptr, parent)
, mProject(project)
{
}
Expand All @@ -49,6 +50,14 @@ QStringList EditableProject::folders() const
return mProject->folders();
}

bool EditableProject::isReadOnly() const
{
return false;
}
QSharedPointer<Document> EditableProject:createDocument()
{
return ProjectDocumentPtr::create(mProject);
}
} // namespace Tiled

#include "moc_editableproject.cpp"
8 changes: 4 additions & 4 deletions src/tiled/editableproject.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@
#pragma once

#include "project.h"

#include "editableasset.h"
#include <QObject>

namespace Tiled {

class EditableProject : public QObject
class EditableProject : public EditableAsset
{
Q_OBJECT

Expand All @@ -38,12 +38,12 @@ class EditableProject : public QObject

public:
EditableProject(Project *project, QObject *parent = nullptr);

bool isReadOnly() const override;
QString extensionsPath() const;
QString automappingRulesFile() const;
QString fileName() const;
QStringList folders() const;

QSharedPointer<Document> createDocument() override;
private:
Project *mProject;
};
Expand Down
2 changes: 2 additions & 0 deletions src/tiled/libtilededitor.qbs
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,8 @@ DynamicLibrary {
"project.h",
"projectdock.cpp",
"projectdock.h",
"projectdocument.cpp",
"projectdocument.h",
"projectmanager.cpp",
"projectmanager.h",
"projectmodel.cpp",
Expand Down
18 changes: 12 additions & 6 deletions src/tiled/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
#include "newtilesetdialog.h"
#include "offsetmapdialog.h"
#include "projectdock.h"
#include "projectdocument.h"
#include "projectmanager.h"
#include "projectpropertiesdialog.h"
#include "propertytypeseditor.h"
Expand Down Expand Up @@ -1487,15 +1488,20 @@ void MainWindow::restoreSession()
void MainWindow::projectProperties()
{
Project &project = ProjectManager::instance()->project();
if (project.fileName().length() == 0){
return;
}
auto projectDocument = new ProjectDocument(&project);
emit projectDocument->editCurrentObject();

if (ProjectPropertiesDialog(project, this).exec() == QDialog::Accepted) {
project.save();
// if (ProjectPropertiesDialog(project, this).exec() == QDialog::Accepted) {
// project.save();

ScriptManager::instance().refreshExtensionsPaths();
mAutomappingManager->refreshRulesFile();
// ScriptManager::instance().refreshExtensionsPaths();
// mAutomappingManager->refreshRulesFile();

FileFormat::setCompatibilityVersion(project.mCompatibilityVersion);
}
// FileFormat::setCompatibilityVersion(project.mCompatibilityVersion);
// }
}

void MainWindow::cut()
Expand Down
73 changes: 73 additions & 0 deletions src/tiled/projectdocument.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* projectdocument.cpp
* Copyright 2022, Chris Boehm AKA dogboydog
* Copyright 2022, Thorbjørn Lindeijer <[email protected]>
*
* 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 "projectdocument.h"

namespace Tiled {

ProjectDocument::ProjectDocument(Project *project)
: Document(ProjectDocumentType, project->fileName())

{
mCurrentObject = project;
mProject = project;
}

QString ProjectDocument::displayName() const
{
return mProject->fileName();
}

bool ProjectDocument::save(const QString &fileName, QString *error = nullptr)
{
return mProject->save();
}
FileFormat *ProjectDocument::writerFormat() const
{
return nullptr;
}

void ProjectDocument::setExportFormat(FileFormat *format)
{
// do nothing
}

FileFormat *ProjectDocument::exportFormat() const
{
return nullptr;
}

QString ProjectDocument::lastExportFileName() const
{
return mProject->fileName();
}

void ProjectDocument::setLastExportFileName(const QString &fileName)
{
// do nothing
}
std::unique_ptr<EditableAsset> ProjectDocument::createEditable()
{
return std::make_unique<EditableProject>(mProject, this);
}

} // namespace Tiled}
48 changes: 48 additions & 0 deletions src/tiled/projectdocument.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* projectdocument.h
* Copyright 2022, Chris Boehm AKA dogboydog
* Copyright 2022, Thorbjørn Lindeijer <[email protected]>
*
* 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/>.
*/

#pragma once

#include "document.h"
#include "project.h"
#include "editableproject.h"
using ProjectDocumentPtr = QSharedPointer<ProjectDocument>;

namespace Tiled {
class ProjectDocument : public Document
{
Q_OBJECT

public:
ProjectDocument(Project *project);
QString displayName() const override;
FileFormat *writerFormat() const override;
bool save(const QString&, QString*) override;
void setExportFormat(FileFormat *format) override;
FileFormat *exportFormat() const override;
QString lastExportFileName() const override;
void setLastExportFileName(const QString &fileName) override;
std::unique_ptr<EditableAsset> createEditable() override;

private:
Project *mProject;
};
} // namespace Tiled

0 comments on commit 9259743

Please sign in to comment.