Finish support for deleting MAPSEC values
This commit is contained in:
parent
d448765d63
commit
06ece16b93
7 changed files with 70 additions and 24 deletions
|
@ -417,6 +417,7 @@ private:
|
||||||
void scrollMetatileSelectorToSelection();
|
void scrollMetatileSelectorToSelection();
|
||||||
MapListToolBar* getCurrentMapListToolBar();
|
MapListToolBar* getCurrentMapListToolBar();
|
||||||
MapTree* getCurrentMapList();
|
MapTree* getCurrentMapList();
|
||||||
|
void refreshLocationsComboBox();
|
||||||
|
|
||||||
QObjectList shortcutableObjects() const;
|
QObjectList shortcutableObjects() const;
|
||||||
void addCustomHeaderValue(QString key, QJsonValue value, bool isNew = false);
|
void addCustomHeaderValue(QString key, QJsonValue value, bool isNew = false);
|
||||||
|
|
|
@ -139,7 +139,8 @@ public:
|
||||||
bool readSpeciesIconPaths();
|
bool readSpeciesIconPaths();
|
||||||
QMap<QString, QString> speciesToIconPath;
|
QMap<QString, QString> speciesToIconPath;
|
||||||
|
|
||||||
void addNewMapsec(QString name);
|
void addNewMapsec(const QString &name);
|
||||||
|
void removeMapsec(const QString &name);
|
||||||
|
|
||||||
bool hasUnsavedChanges();
|
bool hasUnsavedChanges();
|
||||||
bool hasUnsavedDataChanges = false;
|
bool hasUnsavedDataChanges = false;
|
||||||
|
@ -266,6 +267,7 @@ private:
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void fileChanged(QString filepath);
|
void fileChanged(QString filepath);
|
||||||
|
void mapSectionIdNamesChanged();
|
||||||
void mapLoaded(Map *map);
|
void mapLoaded(Map *map);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -65,9 +65,11 @@ public:
|
||||||
~MapListModel() { }
|
~MapListModel() { }
|
||||||
|
|
||||||
virtual QModelIndex indexOf(QString id) const = 0;
|
virtual QModelIndex indexOf(QString id) const = 0;
|
||||||
virtual void removeFolder(int index) = 0;
|
virtual void removeItemAt(const QModelIndex &index);
|
||||||
virtual void removeItem(const QModelIndex &index);
|
|
||||||
virtual QStandardItem *getItem(const QModelIndex &index) const = 0;
|
virtual QStandardItem *getItem(const QModelIndex &index) const = 0;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual void removeItem(QStandardItem *item) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
class MapGroupModel : public MapListModel {
|
class MapGroupModel : public MapListModel {
|
||||||
|
@ -94,13 +96,15 @@ public:
|
||||||
|
|
||||||
QStandardItem *insertGroupItem(QString groupName);
|
QStandardItem *insertGroupItem(QString groupName);
|
||||||
QStandardItem *insertMapItem(QString mapName, QString groupName);
|
QStandardItem *insertMapItem(QString mapName, QString groupName);
|
||||||
virtual void removeFolder(int index) override;
|
|
||||||
|
|
||||||
virtual QStandardItem *getItem(const QModelIndex &index) const override;
|
virtual QStandardItem *getItem(const QModelIndex &index) const override;
|
||||||
virtual QModelIndex indexOf(QString mapName) const override;
|
virtual QModelIndex indexOf(QString mapName) const override;
|
||||||
|
|
||||||
void initialize();
|
void initialize();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual void removeItem(QStandardItem *item) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend class MapTree;
|
friend class MapTree;
|
||||||
void updateProject();
|
void updateProject();
|
||||||
|
@ -137,13 +141,15 @@ public:
|
||||||
|
|
||||||
QStandardItem *insertAreaItem(QString areaName);
|
QStandardItem *insertAreaItem(QString areaName);
|
||||||
QStandardItem *insertMapItem(QString mapName, QString areaName, int groupIndex);
|
QStandardItem *insertMapItem(QString mapName, QString areaName, int groupIndex);
|
||||||
virtual void removeFolder(int index) override;
|
|
||||||
|
|
||||||
virtual QStandardItem *getItem(const QModelIndex &index) const override;
|
virtual QStandardItem *getItem(const QModelIndex &index) const override;
|
||||||
virtual QModelIndex indexOf(QString mapName) const override;
|
virtual QModelIndex indexOf(QString mapName) const override;
|
||||||
|
|
||||||
void initialize();
|
void initialize();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual void removeItem(QStandardItem *item) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Project *project;
|
Project *project;
|
||||||
QStandardItem *root = nullptr;
|
QStandardItem *root = nullptr;
|
||||||
|
@ -176,13 +182,15 @@ public:
|
||||||
|
|
||||||
QStandardItem *insertLayoutItem(QString layoutId);
|
QStandardItem *insertLayoutItem(QString layoutId);
|
||||||
QStandardItem *insertMapItem(QString mapName, QString layoutId);
|
QStandardItem *insertMapItem(QString mapName, QString layoutId);
|
||||||
virtual void removeFolder(int index) override;
|
|
||||||
|
|
||||||
virtual QStandardItem *getItem(const QModelIndex &index) const override;
|
virtual QStandardItem *getItem(const QModelIndex &index) const override;
|
||||||
virtual QModelIndex indexOf(QString layoutName) const override;
|
virtual QModelIndex indexOf(QString layoutName) const override;
|
||||||
|
|
||||||
void initialize();
|
void initialize();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual void removeItem(QStandardItem *item) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Project *project;
|
Project *project;
|
||||||
QStandardItem *root = nullptr;
|
QStandardItem *root = nullptr;
|
||||||
|
|
|
@ -598,8 +598,9 @@ bool MainWindow::openProject(QString dir, bool initial) {
|
||||||
// Create the project
|
// Create the project
|
||||||
auto project = new Project(editor);
|
auto project = new Project(editor);
|
||||||
project->set_root(dir);
|
project->set_root(dir);
|
||||||
QObject::connect(project, &Project::fileChanged, this, &MainWindow::showFileWatcherWarning);
|
connect(project, &Project::fileChanged, this, &MainWindow::showFileWatcherWarning);
|
||||||
QObject::connect(project, &Project::mapLoaded, this, &MainWindow::onMapLoaded);
|
connect(project, &Project::mapLoaded, this, &MainWindow::onMapLoaded);
|
||||||
|
connect(project, &Project::mapSectionIdNamesChanged, this, &MainWindow::refreshLocationsComboBox);
|
||||||
this->editor->setProject(project);
|
this->editor->setProject(project);
|
||||||
|
|
||||||
// Make sure project looks reasonable before attempting to load it
|
// Make sure project looks reasonable before attempting to load it
|
||||||
|
@ -1163,7 +1164,6 @@ bool MainWindow::setProjectUI() {
|
||||||
|
|
||||||
// Block signals to the comboboxes while they are being modified
|
// Block signals to the comboboxes while they are being modified
|
||||||
const QSignalBlocker blocker1(ui->comboBox_Song);
|
const QSignalBlocker blocker1(ui->comboBox_Song);
|
||||||
const QSignalBlocker blocker2(ui->comboBox_Location);
|
|
||||||
const QSignalBlocker blocker3(ui->comboBox_PrimaryTileset);
|
const QSignalBlocker blocker3(ui->comboBox_PrimaryTileset);
|
||||||
const QSignalBlocker blocker4(ui->comboBox_SecondaryTileset);
|
const QSignalBlocker blocker4(ui->comboBox_SecondaryTileset);
|
||||||
const QSignalBlocker blocker5(ui->comboBox_Weather);
|
const QSignalBlocker blocker5(ui->comboBox_Weather);
|
||||||
|
@ -1176,8 +1176,6 @@ bool MainWindow::setProjectUI() {
|
||||||
// Set up project comboboxes
|
// Set up project comboboxes
|
||||||
ui->comboBox_Song->clear();
|
ui->comboBox_Song->clear();
|
||||||
ui->comboBox_Song->addItems(project->songNames);
|
ui->comboBox_Song->addItems(project->songNames);
|
||||||
ui->comboBox_Location->clear();
|
|
||||||
ui->comboBox_Location->addItems(project->mapSectionIdNames);
|
|
||||||
ui->comboBox_PrimaryTileset->clear();
|
ui->comboBox_PrimaryTileset->clear();
|
||||||
ui->comboBox_PrimaryTileset->addItems(project->primaryTilesetLabels);
|
ui->comboBox_PrimaryTileset->addItems(project->primaryTilesetLabels);
|
||||||
ui->comboBox_SecondaryTileset->clear();
|
ui->comboBox_SecondaryTileset->clear();
|
||||||
|
@ -1198,6 +1196,7 @@ bool MainWindow::setProjectUI() {
|
||||||
ui->comboBox_EmergeMap->addItems(project->mapNames);
|
ui->comboBox_EmergeMap->addItems(project->mapNames);
|
||||||
ui->comboBox_EmergeMap->setClearButtonEnabled(true);
|
ui->comboBox_EmergeMap->setClearButtonEnabled(true);
|
||||||
ui->comboBox_EmergeMap->setFocusedScrollingEnabled(false);
|
ui->comboBox_EmergeMap->setFocusedScrollingEnabled(false);
|
||||||
|
refreshLocationsComboBox();
|
||||||
|
|
||||||
// Show/hide parts of the UI that are dependent on the user's project settings
|
// Show/hide parts of the UI that are dependent on the user's project settings
|
||||||
|
|
||||||
|
@ -1247,6 +1246,17 @@ bool MainWindow::setProjectUI() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::refreshLocationsComboBox() {
|
||||||
|
QStringList locations = this->editor->project->mapSectionIdNames;
|
||||||
|
locations.sort();
|
||||||
|
|
||||||
|
const QSignalBlocker b(ui->comboBox_Location);
|
||||||
|
ui->comboBox_Location->clear();
|
||||||
|
ui->comboBox_Location->addItems(locations);
|
||||||
|
if (this->editor->map)
|
||||||
|
ui->comboBox_Location->setCurrentText(this->editor->map->location);
|
||||||
|
}
|
||||||
|
|
||||||
void MainWindow::clearProjectUI() {
|
void MainWindow::clearProjectUI() {
|
||||||
// Block signals to the comboboxes while they are being modified
|
// Block signals to the comboboxes while they are being modified
|
||||||
const QSignalBlocker blocker1(ui->comboBox_Song);
|
const QSignalBlocker blocker1(ui->comboBox_Song);
|
||||||
|
@ -1328,19 +1338,30 @@ void MainWindow::onOpenMapListContextMenu(const QPoint &point) {
|
||||||
QMenu menu(this);
|
QMenu menu(this);
|
||||||
QAction* addToFolderAction = nullptr;
|
QAction* addToFolderAction = nullptr;
|
||||||
QAction* deleteFolderAction = nullptr;
|
QAction* deleteFolderAction = nullptr;
|
||||||
|
QAction* openItemAction = nullptr;
|
||||||
if (itemType == "map_name") {
|
if (itemType == "map_name") {
|
||||||
// Right-clicking on a map.
|
// Right-clicking on a map.
|
||||||
// TODO: Add action to delete map once deleting maps is supported
|
openItemAction = menu.addAction("Open Map");
|
||||||
|
//menu.addSeparator();
|
||||||
|
//connect(menu.addAction("Delete Map"), &QAction::triggered, [this, index] { deleteMapListItem(index); }); // TODO: No support for deleting maps
|
||||||
} else if (itemType == "map_group") {
|
} else if (itemType == "map_group") {
|
||||||
// Right-clicking on a map group folder
|
// Right-clicking on a map group folder
|
||||||
addToFolderAction = menu.addAction("Add New Map to Group");
|
addToFolderAction = menu.addAction("Add New Map to Group");
|
||||||
|
menu.addSeparator();
|
||||||
deleteFolderAction = menu.addAction("Delete Map Group");
|
deleteFolderAction = menu.addAction("Delete Map Group");
|
||||||
} else if (itemType == "map_section") {
|
} else if (itemType == "map_section") {
|
||||||
// Right-clicking on an MAPSEC folder
|
// Right-clicking on an MAPSEC folder
|
||||||
addToFolderAction = menu.addAction("Add New Map to Area");
|
addToFolderAction = menu.addAction("Add New Map to Area");
|
||||||
|
menu.addSeparator();
|
||||||
|
deleteFolderAction = menu.addAction("Delete Area");
|
||||||
|
if (itemName == this->editor->project->getEmptyMapsecName())
|
||||||
|
deleteFolderAction->setEnabled(false); // Disallow deleting the default name
|
||||||
} else if (itemType == "map_layout") {
|
} else if (itemType == "map_layout") {
|
||||||
// Right-clicking on a map layout
|
// Right-clicking on a map layout
|
||||||
|
openItemAction = menu.addAction("Open Layout");
|
||||||
addToFolderAction = menu.addAction("Add New Map with Layout");
|
addToFolderAction = menu.addAction("Add New Map with Layout");
|
||||||
|
//menu.addSeparator();
|
||||||
|
//deleteFolderAction = menu.addAction("Delete Layout"); // TODO: No support for deleting layouts
|
||||||
}
|
}
|
||||||
|
|
||||||
if (addToFolderAction) {
|
if (addToFolderAction) {
|
||||||
|
@ -1351,13 +1372,16 @@ void MainWindow::onOpenMapListContextMenu(const QPoint &point) {
|
||||||
}
|
}
|
||||||
if (deleteFolderAction) {
|
if (deleteFolderAction) {
|
||||||
connect(deleteFolderAction, &QAction::triggered, [sourceModel, index] {
|
connect(deleteFolderAction, &QAction::triggered, [sourceModel, index] {
|
||||||
sourceModel->removeFolder(index.row());
|
sourceModel->removeItemAt(index);
|
||||||
});
|
});
|
||||||
if (selectedItem->hasChildren()){
|
if (selectedItem->hasChildren()){
|
||||||
// TODO: No support for deleting maps, so you may only delete folders if they don't contain any maps.
|
// TODO: No support for deleting maps, so you may only delete folders if they don't contain any maps.
|
||||||
deleteFolderAction->setEnabled(false);
|
deleteFolderAction->setEnabled(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (openItemAction) {
|
||||||
|
connect(openItemAction, &QAction::triggered, [this, index] { openMapListItem(index); });
|
||||||
|
}
|
||||||
|
|
||||||
if (menu.actions().length() != 0)
|
if (menu.actions().length() != 0)
|
||||||
menu.exec(QCursor::pos());
|
menu.exec(QCursor::pos());
|
||||||
|
|
|
@ -2319,7 +2319,7 @@ QString Project::getEmptyMapsecName() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// This function assumes a valid and unique name
|
// This function assumes a valid and unique name
|
||||||
void Project::addNewMapsec(QString name) {
|
void Project::addNewMapsec(const QString &name) {
|
||||||
if (!this->mapSectionIdNames.isEmpty() && this->mapSectionIdNames.last() == getEmptyMapsecName()) {
|
if (!this->mapSectionIdNames.isEmpty() && this->mapSectionIdNames.last() == getEmptyMapsecName()) {
|
||||||
// If the default map section name (MAPSEC_NONE) is last in the list we'll keep it last in the list.
|
// If the default map section name (MAPSEC_NONE) is last in the list we'll keep it last in the list.
|
||||||
this->mapSectionIdNames.insert(this->mapSectionIdNames.length() - 1, name);
|
this->mapSectionIdNames.insert(this->mapSectionIdNames.length() - 1, name);
|
||||||
|
@ -2327,6 +2327,16 @@ void Project::addNewMapsec(QString name) {
|
||||||
this->mapSectionIdNames.append(name);
|
this->mapSectionIdNames.append(name);
|
||||||
}
|
}
|
||||||
this->hasUnsavedDataChanges = true;
|
this->hasUnsavedDataChanges = true;
|
||||||
|
emit mapSectionIdNamesChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Project::removeMapsec(const QString &name) {
|
||||||
|
if (!this->mapSectionIdNames.contains(name) || name == getEmptyMapsecName())
|
||||||
|
return;
|
||||||
|
|
||||||
|
this->mapSectionIdNames.removeOne(name);
|
||||||
|
this->hasUnsavedDataChanges = true;
|
||||||
|
emit mapSectionIdNamesChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read the constants to preserve any "unused" heal locations when writing the file later
|
// Read the constants to preserve any "unused" heal locations when writing the file later
|
||||||
|
|
|
@ -31,14 +31,14 @@ void MapTree::keyPressEvent(QKeyEvent *event) {
|
||||||
persistentIndexes.append(model->mapToSource(index));
|
persistentIndexes.append(model->mapToSource(index));
|
||||||
}
|
}
|
||||||
for (const auto &index : persistentIndexes) {
|
for (const auto &index : persistentIndexes) {
|
||||||
sourceModel->removeItem(index);
|
sourceModel->removeItemAt(index);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
QWidget::keyPressEvent(event);
|
QWidget::keyPressEvent(event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MapListModel::removeItem(const QModelIndex &index) {
|
void MapListModel::removeItemAt(const QModelIndex &index) {
|
||||||
QStandardItem *item = this->getItem(index)->child(index.row(), index.column());
|
QStandardItem *item = this->getItem(index)->child(index.row(), index.column());
|
||||||
if (!item)
|
if (!item)
|
||||||
return;
|
return;
|
||||||
|
@ -49,7 +49,7 @@ void MapListModel::removeItem(const QModelIndex &index) {
|
||||||
} else {
|
} else {
|
||||||
// TODO: Because there's no support for deleting maps we can only delete empty folders
|
// TODO: Because there's no support for deleting maps we can only delete empty folders
|
||||||
if (!item->hasChildren()) {
|
if (!item->hasChildren()) {
|
||||||
this->removeFolder(index.row());
|
this->removeItem(item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -282,8 +282,8 @@ QStandardItem *MapGroupModel::insertGroupItem(QString groupName) {
|
||||||
return group;
|
return group;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MapGroupModel::removeFolder(int index) {
|
void MapGroupModel::removeItem(QStandardItem *item) {
|
||||||
this->removeRow(index);
|
this->removeRow(item->row());
|
||||||
this->updateProject();
|
this->updateProject();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -454,10 +454,9 @@ QStandardItem *MapAreaModel::insertMapItem(QString mapName, QString areaName, in
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Note: Not actually supported in the interface at the moment.
|
void MapAreaModel::removeItem(QStandardItem *item) {
|
||||||
void MapAreaModel::removeFolder(int index) {
|
this->project->removeMapsec(item->data(Qt::UserRole).toString());
|
||||||
this->removeRow(index);
|
this->removeRow(item->row());
|
||||||
this->project->mapSectionIdNames.removeAt(index);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MapAreaModel::initialize() {
|
void MapAreaModel::initialize() {
|
||||||
|
@ -612,7 +611,7 @@ QStandardItem *LayoutTreeModel::insertMapItem(QString mapName, QString layoutId)
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
void LayoutTreeModel::removeFolder(int) {
|
void LayoutTreeModel::removeItem(QStandardItem *) {
|
||||||
// TODO: Deleting layouts not supported
|
// TODO: Deleting layouts not supported
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,8 @@
|
||||||
#include <QSet>
|
#include <QSet>
|
||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
|
|
||||||
|
// TODO: Convert to modal dialog (among other things, this means we wouldn't need to worry about changes to the map list while this is open)
|
||||||
|
|
||||||
struct NewMapPopup::Settings NewMapPopup::settings = {};
|
struct NewMapPopup::Settings NewMapPopup::settings = {};
|
||||||
|
|
||||||
NewMapPopup::NewMapPopup(QWidget *parent, Project *project) :
|
NewMapPopup::NewMapPopup(QWidget *parent, Project *project) :
|
||||||
|
|
Loading…
Reference in a new issue