Skip to content

Commit f019143

Browse files
dogboydogbjorn
andauthored
Added World Properties action to World menu (#4190)
Allows editing the custom properties of a world in the UI. Co-authored-by: Thorbjørn Lindeijer <[email protected]>
1 parent 9842ebc commit f019143

11 files changed

+240
-9
lines changed

NEWS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
* Added support for SVG 1.2 / CSS blending modes to layers (#3932)
44
* Added export plugin for Remixed Dungeon (by Mikhael Danilov, #4158)
5+
* Added "World > World Properties" menu action (with dogboydog, #4190)
56
* Scripting: Added API for custom property types (with dogboydog, #3971)
67
* AutoMapping: Don't match rules based on empty input indexes
78
* AutoMapping: Optimized reloading of rule maps and load rule maps on-demand

src/tiled/libtilededitor.qbs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,9 @@ DynamicLibrary {
578578
"worldmanager.h",
579579
"worldmovemaptool.cpp",
580580
"worldmovemaptool.h",
581+
"worldpropertiesdialog.cpp",
582+
"worldpropertiesdialog.h",
583+
"worldpropertiesdialog.ui",
581584
"zoomable.cpp",
582585
"zoomable.h",
583586
]

src/tiled/mainwindow.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
#include "world.h"
7575
#include "worlddocument.h"
7676
#include "worldmanager.h"
77+
#include "worldpropertiesdialog.h"
7778
#include "zoomable.h"
7879

7980
#include <QActionGroup>
@@ -310,6 +311,7 @@ MainWindow::MainWindow(QWidget *parent, Qt::WindowFlags flags)
310311
ActionManager::registerAction(mUi->actionSnapToGrid, "SnapToGrid");
311312
ActionManager::registerAction(mUi->actionSnapToPixels, "SnapToPixels");
312313
ActionManager::registerAction(mUi->actionTilesetProperties, "TilesetProperties");
314+
ActionManager::registerAction(mUi->actionWorldProperties, "WorldProperties");
313315
ActionManager::registerAction(mUi->actionZoomIn, "ZoomIn");
314316
ActionManager::registerAction(mUi->actionZoomNormal, "ZoomNormal");
315317
ActionManager::registerAction(mUi->actionZoomOut, "ZoomOut");
@@ -679,6 +681,13 @@ MainWindow::MainWindow(QWidget *parent, Qt::WindowFlags flags)
679681
connect(mUi->actionTilesetProperties, &QAction::triggered,
680682
this, &MainWindow::editTilesetProperties);
681683

684+
connect(mUi->actionWorldProperties, &QAction::triggered,
685+
this, &MainWindow::editWorldProperties);
686+
687+
mUi->actionWorldProperties->setEnabled(false);
688+
connect(&WorldManager::instance(), &WorldManager::worldsChanged, this, [this] {
689+
mUi->actionWorldProperties->setDisabled(WorldManager::instance().worlds().empty());
690+
});
682691
connect(mUi->actionNewProject, &QAction::triggered, this, &MainWindow::newProject);
683692
connect(mUi->actionCloseProject, &QAction::triggered, this, &MainWindow::closeProject);
684693
connect(mUi->actionAddFolderToProject, &QAction::triggered, mProjectDock, &ProjectDock::addFolderToProject);
@@ -1954,6 +1963,20 @@ void MainWindow::editTilesetProperties()
19541963
emit tilesetDocument->editCurrentObject();
19551964
}
19561965

1966+
void MainWindow::editWorldProperties()
1967+
{
1968+
if (WorldManager::instance().worlds().empty())
1969+
return;
1970+
QSharedPointer<WorldDocument> world;
1971+
Document *currentDocument = DocumentManager::instance()->currentDocument();
1972+
if (currentDocument && currentDocument->type() == Document::MapDocumentType)
1973+
world = WorldManager::instance().worldForMap(currentDocument->fileName());
1974+
if (!world)
1975+
world = WorldManager::instance().worlds().first();
1976+
1977+
WorldPropertiesDialog(world, this).exec();
1978+
}
1979+
19571980
void MainWindow::autoMappingError(bool automatic)
19581981
{
19591982
QString error = mAutomappingManager->errorString();

src/tiled/mainwindow.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,8 @@ class TILED_EDITOR_EXPORT MainWindow : public QMainWindow
168168

169169
void editTilesetProperties();
170170

171+
void editWorldProperties();
172+
171173
void updateWindowTitle();
172174
void updateActions();
173175
void updateZoomable();

src/tiled/mainwindow.ui

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<bool>true</bool>
1515
</property>
1616
<property name="dockOptions">
17-
<set>QMainWindow::AllowNestedDocks|QMainWindow::AllowTabbedDocks|QMainWindow::AnimatedDocks</set>
17+
<set>QMainWindow::DockOption::AllowNestedDocks|QMainWindow::DockOption::AllowTabbedDocks|QMainWindow::DockOption::AnimatedDocks</set>
1818
</property>
1919
<widget class="QWidget" name="centralWidget">
2020
<layout class="QVBoxLayout" name="verticalLayout">
@@ -38,7 +38,7 @@
3838
<x>0</x>
3939
<y>0</y>
4040
<width>553</width>
41-
<height>23</height>
41+
<height>21</height>
4242
</rect>
4343
</property>
4444
<widget class="QMenu" name="menuFile">
@@ -222,6 +222,7 @@
222222
<addaction name="menuUnloadWorld"/>
223223
<addaction name="menuSaveWorld"/>
224224
<addaction name="separator"/>
225+
<addaction name="actionWorldProperties"/>
225226
</widget>
226227
<addaction name="menuFile"/>
227228
<addaction name="menuEdit"/>
@@ -251,7 +252,7 @@
251252
<string>&amp;Quit</string>
252253
</property>
253254
<property name="menuRole">
254-
<enum>QAction::QuitRole</enum>
255+
<enum>QAction::MenuRole::QuitRole</enum>
255256
</property>
256257
</action>
257258
<action name="actionCopy">
@@ -287,15 +288,15 @@
287288
<string>&amp;About Tiled</string>
288289
</property>
289290
<property name="menuRole">
290-
<enum>QAction::AboutRole</enum>
291+
<enum>QAction::MenuRole::AboutRole</enum>
291292
</property>
292293
</action>
293294
<action name="actionAboutQt">
294295
<property name="text">
295296
<string>About Qt</string>
296297
</property>
297298
<property name="menuRole">
298-
<enum>QAction::AboutQtRole</enum>
299+
<enum>QAction::MenuRole::AboutQtRole</enum>
299300
</property>
300301
</action>
301302
<action name="actionResizeMap">
@@ -421,7 +422,7 @@
421422
<string>Pre&amp;ferences...</string>
422423
</property>
423424
<property name="menuRole">
424-
<enum>QAction::PreferencesRole</enum>
425+
<enum>QAction::MenuRole::PreferencesRole</enum>
425426
</property>
426427
</action>
427428
<action name="actionClearRecentFiles">
@@ -807,6 +808,21 @@
807808
<string>Unload All Worlds</string>
808809
</property>
809810
</action>
811+
<action name="actionWorldProperties">
812+
<property name="icon">
813+
<iconset resource="tiled.qrc">
814+
<normaloff>:/images/16/document-properties.png</normaloff>:/images/16/document-properties.png</iconset>
815+
</property>
816+
<property name="text">
817+
<string>World Properties...</string>
818+
</property>
819+
<property name="toolTip">
820+
<string>World Properties</string>
821+
</property>
822+
<property name="menuRole">
823+
<enum>QAction::MenuRole::NoRole</enum>
824+
</property>
825+
</action>
810826
</widget>
811827
<layoutdefault spacing="6" margin="11"/>
812828
<resources>

src/tiled/propertieswidget.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2386,8 +2386,10 @@ void PropertiesWidget::currentObjectChanged(Object *object)
23862386
this);
23872387
break;
23882388
case Object::ProjectType:
2389+
// this type is currently not handled by the Properties dock
2390+
break;
23892391
case Object::WorldType:
2390-
// these types are currently not handled by the Properties dock
2392+
// this type is currently not handled by the Properties dock
23912393
break;
23922394
}
23932395
}

src/tiled/scriptpropertytype.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* scriptpropertytype.cpp
3-
* Copyright 2024, chris <dogboydog@users.noreply.github.com>
3+
* Copyright 2024-2025, dogboydog
44
*
55
* This file is part of Tiled.
66
*

src/tiled/scriptpropertytype.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* scriptpropertytype.h
3-
* Copyright 2024, chris <dogboydog@users.noreply.github.com>
3+
* Copyright 2024-2025, dogboydog
44
*
55
* This file is part of Tiled.
66
*
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* worldpropertiesdialog.cpp
3+
* Copyright 2025, dogboydog
4+
*
5+
* This file is part of Tiled.
6+
*
7+
* This program is free software; you can redistribute it and/or modify it
8+
* under the terms of the GNU General Public License as published by the Free
9+
* Software Foundation; either version 2 of the License, or (at your option)
10+
* any later version.
11+
*
12+
* This program is distributed in the hope that it will be useful, but WITHOUT
13+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15+
* more details.
16+
*
17+
* You should have received a copy of the GNU General Public License along with
18+
* this program. If not, see <http://www.gnu.org/licenses/>.
19+
*/
20+
21+
#include "worldpropertiesdialog.h"
22+
#include "ui_worldpropertiesdialog.h"
23+
24+
#include "propertiesview.h"
25+
26+
#include "utils.h"
27+
28+
namespace Tiled {
29+
30+
WorldPropertiesDialog::WorldPropertiesDialog(WorldDocumentPtr world, QWidget *parent)
31+
: QDialog(parent)
32+
, ui(new Ui::WorldPropertiesDialog)
33+
, mWorldDocument(world)
34+
{
35+
ui->setupUi(this);
36+
37+
// Don't display the "Custom Properties" header
38+
ui->propertiesWidget->customPropertiesGroup()->setName(QString());
39+
40+
// Tweak margins
41+
const auto halfSpacing = Utils::dpiScaled(2);
42+
ui->propertiesWidget->propertiesView()->widget()->setContentsMargins(0, halfSpacing, 0, halfSpacing);
43+
44+
ui->propertiesWidget->setDocument(mWorldDocument.get());
45+
setWindowTitle(tr("%1 - World Properties").arg(world->displayName()));
46+
}
47+
48+
WorldPropertiesDialog::~WorldPropertiesDialog()
49+
{
50+
delete ui;
51+
}
52+
53+
} // namespace Tiled
54+
55+
#include "moc_worldpropertiesdialog.cpp"

src/tiled/worldpropertiesdialog.h

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* worldpropertiesdialog.h
3+
* Copyright 2025, dogboydog
4+
*
5+
* This file is part of Tiled.
6+
*
7+
* This program is free software; you can redistribute it and/or modify it
8+
* under the terms of the GNU General Public License as published by the Free
9+
* Software Foundation; either version 2 of the License, or (at your option)
10+
* any later version.
11+
*
12+
* This program is distributed in the hope that it will be useful, but WITHOUT
13+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15+
* more details.
16+
*
17+
* You should have received a copy of the GNU General Public License along with
18+
* this program. If not, see <http://www.gnu.org/licenses/>.
19+
*/
20+
21+
#pragma once
22+
23+
#include "worlddocument.h"
24+
25+
#include <QDialog>
26+
27+
namespace Ui {
28+
class WorldPropertiesDialog;
29+
}
30+
31+
namespace Tiled {
32+
33+
class WorldPropertiesDialog : public QDialog
34+
{
35+
Q_OBJECT
36+
37+
public:
38+
explicit WorldPropertiesDialog(WorldDocumentPtr world, QWidget *parent = nullptr);
39+
~WorldPropertiesDialog() override;
40+
41+
private:
42+
Ui::WorldPropertiesDialog *ui;
43+
WorldDocumentPtr mWorldDocument;
44+
};
45+
46+
} // namespace Tiled

0 commit comments

Comments
 (0)