Skip to content

Commit

Permalink
fixup 8bf312e
Browse files Browse the repository at this point in the history
After the above change, the Project Properties dialog was changing the
current project directly, while the dialog features OK/Cancel buttons and
changes are only expected to be applied when pressing OK.
  • Loading branch information
bjorn committed Nov 15, 2024
1 parent 85ef006 commit efa984d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 15 deletions.
33 changes: 19 additions & 14 deletions src/tiled/projectpropertiesdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,28 +52,26 @@ ProjectPropertiesDialog::ProjectPropertiesDialog(Project &project, QWidget *pare
: QDialog(parent)
, ui(new Ui::ProjectPropertiesDialog)
, mProject(project)
, mPropertiesProjectDocument(new ProjectDocument(std::make_unique<Project>(), this))
, mLocalProjectDocument(new ProjectDocument(std::make_unique<Project>(project), this))
{
ui->setupUi(this);

mPropertiesProjectDocument->project().setProperties(project.properties());

mCompatibilityVersionProperty = new EnumProperty<CompatibilityVersion>(
tr("Compatibility Version"),
[=] {
return mProject.mCompatibilityVersion;
return localProject().mCompatibilityVersion;
},
[=](CompatibilityVersion value) {
mProject.mCompatibilityVersion = value;
localProject().mCompatibilityVersion = value;
});

mExtensionPathProperty = new UrlProperty(
tr("Extensions Directory"),
[=] {
return QUrl::fromLocalFile(mProject.mExtensionsPath);
return QUrl::fromLocalFile(localProject().mExtensionsPath);
},
[=](const QUrl &value) {
mProject.mExtensionsPath = value.toLocalFile();
localProject().mExtensionsPath = value.toLocalFile();
});
mExtensionPathProperty->setIsDirectory(true);

Expand All @@ -83,10 +81,10 @@ ProjectPropertiesDialog::ProjectPropertiesDialog(Project &project, QWidget *pare
mAutomappingRulesFileProperty = new UrlProperty(
tr("Automapping rules"),
[=] {
return QUrl::fromLocalFile(mProject.mAutomappingRulesFile);
return QUrl::fromLocalFile(localProject().mAutomappingRulesFile);
},
[=](const QUrl &value) {
mProject.mAutomappingRulesFile = value.toLocalFile();
localProject().mAutomappingRulesFile = value.toLocalFile();
});
mAutomappingRulesFileProperty->setFilter(helper.filter());

Expand All @@ -109,7 +107,7 @@ ProjectPropertiesDialog::ProjectPropertiesDialog(Project &project, QWidget *pare
const auto margin = Utils::dpiScaled(3);
ui->propertiesWidget->propertiesView()->widget()->setContentsMargins(0, margin, 0, margin);

ui->propertiesWidget->setDocument(mPropertiesProjectDocument);
ui->propertiesWidget->setDocument(mLocalProjectDocument);
}

ProjectPropertiesDialog::~ProjectPropertiesDialog()
Expand All @@ -119,14 +117,21 @@ ProjectPropertiesDialog::~ProjectPropertiesDialog()

void ProjectPropertiesDialog::accept()
{
mProject.setProperties(mPropertiesProjectDocument->project().properties());
mProject.mCompatibilityVersion = static_cast<CompatibilityVersion>(mCompatibilityVersionProperty->value());
mProject.mExtensionsPath = mExtensionPathProperty->value().toLocalFile();
mProject.mAutomappingRulesFile = mAutomappingRulesFileProperty->value().toLocalFile();
auto &project = localProject();

mProject.setProperties(project.properties());
mProject.mCompatibilityVersion = project.mCompatibilityVersion;
mProject.mExtensionsPath = project.mExtensionsPath;
mProject.mAutomappingRulesFile = project.mAutomappingRulesFile;

QDialog::accept();
}

Project &ProjectPropertiesDialog::localProject()
{
return mLocalProjectDocument->project();
}

} // namespace Tiled

#include "moc_projectpropertiesdialog.cpp"
4 changes: 3 additions & 1 deletion src/tiled/projectpropertiesdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,12 @@ class ProjectPropertiesDialog : public QDialog
void accept() override;

private:
Project &localProject();

Ui::ProjectPropertiesDialog *ui;

Project &mProject;
ProjectDocument *mPropertiesProjectDocument;
ProjectDocument *mLocalProjectDocument;
IntProperty *mCompatibilityVersionProperty;
UrlProperty *mExtensionPathProperty;
UrlProperty *mAutomappingRulesFileProperty;
Expand Down

0 comments on commit efa984d

Please sign in to comment.