Simplify saving the map list tab
This commit is contained in:
parent
a18b2c960b
commit
3bd5ddbf2f
6 changed files with 31 additions and 79 deletions
|
@ -22,12 +22,6 @@ static const QVersionNumber porymapVersion = QVersionNumber::fromString(PORYMAP_
|
||||||
|
|
||||||
#define CONFIG_BACKWARDS_COMPATABILITY
|
#define CONFIG_BACKWARDS_COMPATABILITY
|
||||||
|
|
||||||
enum MapSortOrder {
|
|
||||||
SortByGroup = 0,
|
|
||||||
SortByArea = 1,
|
|
||||||
SortByLayout = 2,
|
|
||||||
};
|
|
||||||
|
|
||||||
class KeyValueConfigBase
|
class KeyValueConfigBase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -56,7 +50,7 @@ public:
|
||||||
this->recentProjects.clear();
|
this->recentProjects.clear();
|
||||||
this->projectManuallyClosed = false;
|
this->projectManuallyClosed = false;
|
||||||
this->reopenOnLaunch = true;
|
this->reopenOnLaunch = true;
|
||||||
this->mapSortOrder = MapSortOrder::SortByGroup;
|
this->mapListTab = 0;
|
||||||
this->prettyCursors = true;
|
this->prettyCursors = true;
|
||||||
this->mirrorConnectingMaps = true;
|
this->mirrorConnectingMaps = true;
|
||||||
this->showDiveEmergeMaps = false;
|
this->showDiveEmergeMaps = false;
|
||||||
|
@ -107,7 +101,7 @@ public:
|
||||||
|
|
||||||
bool reopenOnLaunch;
|
bool reopenOnLaunch;
|
||||||
bool projectManuallyClosed;
|
bool projectManuallyClosed;
|
||||||
MapSortOrder mapSortOrder;
|
int mapListTab;
|
||||||
bool prettyCursors;
|
bool prettyCursors;
|
||||||
bool mirrorConnectingMaps;
|
bool mirrorConnectingMaps;
|
||||||
bool showDiveEmergeMaps;
|
bool showDiveEmergeMaps;
|
||||||
|
|
|
@ -242,11 +242,7 @@ private slots:
|
||||||
void on_toolButton_Move_clicked();
|
void on_toolButton_Move_clicked();
|
||||||
void on_toolButton_Shift_clicked();
|
void on_toolButton_Shift_clicked();
|
||||||
|
|
||||||
void on_mapListContainer_currentChanged(int index);
|
|
||||||
void onOpenMapListContextMenu(const QPoint &point);
|
void onOpenMapListContextMenu(const QPoint &point);
|
||||||
void onAddNewMapToGroupClick(QAction* triggeredAction);
|
|
||||||
void onAddNewMapToAreaClick(QAction* triggeredAction);
|
|
||||||
void onAddNewMapToLayoutClick(QAction* triggeredAction);
|
|
||||||
void currentMetatilesSelectionChanged();
|
void currentMetatilesSelectionChanged();
|
||||||
|
|
||||||
void on_action_Export_Map_Image_triggered();
|
void on_action_Export_Map_Image_triggered();
|
||||||
|
@ -393,6 +389,7 @@ private:
|
||||||
void mapListRemoveArea();
|
void mapListRemoveArea();
|
||||||
void mapListRemoveLayout();
|
void mapListRemoveLayout();
|
||||||
void openMapListItem(const QModelIndex &index);
|
void openMapListItem(const QModelIndex &index);
|
||||||
|
void saveMapListTab(int index);
|
||||||
|
|
||||||
void displayMapProperties();
|
void displayMapProperties();
|
||||||
void checkToolButtons();
|
void checkToolButtons();
|
||||||
|
|
|
@ -24,7 +24,7 @@ public:
|
||||||
QString layoutId;
|
QString layoutId;
|
||||||
void init();
|
void init();
|
||||||
void initUi();
|
void initUi();
|
||||||
void init(MapSortOrder type, QVariant data);
|
void init(int tabIndex, QVariant data);
|
||||||
void init(Layout *);
|
void init(Layout *);
|
||||||
static void setDefaultSettings(Project *project);
|
static void setDefaultSettings(Project *project);
|
||||||
|
|
||||||
|
|
|
@ -278,12 +278,6 @@ uint32_t KeyValueConfigBase::getConfigUint32(QString key, QString value, uint32_
|
||||||
return qMin(max, qMax(min, result));
|
return qMin(max, qMax(min, result));
|
||||||
}
|
}
|
||||||
|
|
||||||
const QMap<QString, MapSortOrder> mapSortOrderMap = {
|
|
||||||
{"group", MapSortOrder::SortByGroup},
|
|
||||||
{"layout", MapSortOrder::SortByLayout},
|
|
||||||
{"area", MapSortOrder::SortByArea},
|
|
||||||
};
|
|
||||||
|
|
||||||
PorymapConfig porymapConfig;
|
PorymapConfig porymapConfig;
|
||||||
|
|
||||||
QString PorymapConfig::getConfigFilepath() {
|
QString PorymapConfig::getConfigFilepath() {
|
||||||
|
@ -308,14 +302,8 @@ void PorymapConfig::parseConfigKeyValue(QString key, QString value) {
|
||||||
this->reopenOnLaunch = getConfigBool(key, value);
|
this->reopenOnLaunch = getConfigBool(key, value);
|
||||||
} else if (key == "pretty_cursors") {
|
} else if (key == "pretty_cursors") {
|
||||||
this->prettyCursors = getConfigBool(key, value);
|
this->prettyCursors = getConfigBool(key, value);
|
||||||
} else if (key == "map_sort_order") {
|
} else if (key == "map_list_tab") {
|
||||||
QString sortOrder = value.toLower();
|
this->mapListTab = getConfigInteger(key, value, 0, 2, 0);
|
||||||
if (mapSortOrderMap.contains(sortOrder)) {
|
|
||||||
this->mapSortOrder = mapSortOrderMap.value(sortOrder);
|
|
||||||
} else {
|
|
||||||
this->mapSortOrder = MapSortOrder::SortByGroup;
|
|
||||||
logWarn(QString("Invalid config value for map_sort_order: '%1'. Must be 'group', 'area', or 'layout'.").arg(value));
|
|
||||||
}
|
|
||||||
} else if (key == "main_window_geometry") {
|
} else if (key == "main_window_geometry") {
|
||||||
this->mainWindowGeometry = bytesFromString(value);
|
this->mainWindowGeometry = bytesFromString(value);
|
||||||
} else if (key == "main_window_state") {
|
} else if (key == "main_window_state") {
|
||||||
|
@ -432,7 +420,7 @@ QMap<QString, QString> PorymapConfig::getKeyValueMap() {
|
||||||
map.insert("project_manually_closed", this->projectManuallyClosed ? "1" : "0");
|
map.insert("project_manually_closed", this->projectManuallyClosed ? "1" : "0");
|
||||||
map.insert("reopen_on_launch", this->reopenOnLaunch ? "1" : "0");
|
map.insert("reopen_on_launch", this->reopenOnLaunch ? "1" : "0");
|
||||||
map.insert("pretty_cursors", this->prettyCursors ? "1" : "0");
|
map.insert("pretty_cursors", this->prettyCursors ? "1" : "0");
|
||||||
map.insert("map_sort_order", mapSortOrderMap.key(this->mapSortOrder));
|
map.insert("map_list_tab", QString::number(this->mapListTab));
|
||||||
map.insert("main_window_geometry", stringFromByteArray(this->mainWindowGeometry));
|
map.insert("main_window_geometry", stringFromByteArray(this->mainWindowGeometry));
|
||||||
map.insert("main_window_state", stringFromByteArray(this->mainWindowState));
|
map.insert("main_window_state", stringFromByteArray(this->mainWindowState));
|
||||||
map.insert("map_splitter_state", stringFromByteArray(this->mapSplitterState));
|
map.insert("map_splitter_state", stringFromByteArray(this->mapSplitterState));
|
||||||
|
|
|
@ -371,7 +371,7 @@ void MainWindow::initMiscHeapObjects() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::initMapList() {
|
void MainWindow::initMapList() {
|
||||||
ui->mapListContainer->setCurrentIndex(static_cast<int>(porymapConfig.mapSortOrder));
|
ui->mapListContainer->setCurrentIndex(porymapConfig.mapListTab);
|
||||||
|
|
||||||
WheelFilter *wheelFilter = new WheelFilter(this);
|
WheelFilter *wheelFilter = new WheelFilter(this);
|
||||||
ui->mainTabBar->installEventFilter(wheelFilter);
|
ui->mainTabBar->installEventFilter(wheelFilter);
|
||||||
|
@ -430,6 +430,8 @@ void MainWindow::initMapList() {
|
||||||
connect(ui->mapListToolBar_Groups, &MapListToolBar::addFolderClicked, this, &MainWindow::mapListAddGroup);
|
connect(ui->mapListToolBar_Groups, &MapListToolBar::addFolderClicked, this, &MainWindow::mapListAddGroup);
|
||||||
connect(ui->mapListToolBar_Areas, &MapListToolBar::addFolderClicked, this, &MainWindow::mapListAddArea);
|
connect(ui->mapListToolBar_Areas, &MapListToolBar::addFolderClicked, this, &MainWindow::mapListAddArea);
|
||||||
connect(ui->mapListToolBar_Layouts, &MapListToolBar::addFolderClicked, this, &MainWindow::mapListAddLayout);
|
connect(ui->mapListToolBar_Layouts, &MapListToolBar::addFolderClicked, this, &MainWindow::mapListAddLayout);
|
||||||
|
|
||||||
|
connect(ui->mapListContainer, &QTabWidget::currentChanged, this, &MainWindow::saveMapListTab);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::updateWindowTitle() {
|
void MainWindow::updateWindowTitle() {
|
||||||
|
@ -1209,7 +1211,6 @@ bool MainWindow::setProjectUI() {
|
||||||
ui->spinBox_SelectedCollision->setMaximum(Block::getMaxCollision());
|
ui->spinBox_SelectedCollision->setMaximum(Block::getMaxCollision());
|
||||||
|
|
||||||
// map models
|
// map models
|
||||||
// !TODO: delete these on close
|
|
||||||
this->mapGroupModel = new MapGroupModel(editor->project);
|
this->mapGroupModel = new MapGroupModel(editor->project);
|
||||||
this->groupListProxyModel = new FilterChildrenProxyModel();
|
this->groupListProxyModel = new FilterChildrenProxyModel();
|
||||||
groupListProxyModel->setSourceModel(this->mapGroupModel);
|
groupListProxyModel->setSourceModel(this->mapGroupModel);
|
||||||
|
@ -1308,32 +1309,30 @@ void MainWindow::onOpenMapListContextMenu(const QPoint &point) {
|
||||||
int dataRole;
|
int dataRole;
|
||||||
FilterChildrenProxyModel *proxy;
|
FilterChildrenProxyModel *proxy;
|
||||||
QTreeView *list;
|
QTreeView *list;
|
||||||
void (MainWindow::*addFunction)(QAction *);
|
|
||||||
QString actionText;
|
QString actionText;
|
||||||
|
|
||||||
switch (porymapConfig.mapSortOrder) {
|
int currentTab = ui->mapListContainer->currentIndex();
|
||||||
case MapSortOrder::SortByGroup:
|
|
||||||
|
switch (currentTab) {
|
||||||
|
case MapListTab::Groups:
|
||||||
model = this->mapGroupModel;
|
model = this->mapGroupModel;
|
||||||
dataRole = MapListUserRoles::GroupRole;
|
dataRole = MapListUserRoles::GroupRole;
|
||||||
proxy = this->groupListProxyModel;
|
proxy = this->groupListProxyModel;
|
||||||
list = this->ui->mapList;
|
list = this->ui->mapList;
|
||||||
addFunction = &MainWindow::onAddNewMapToGroupClick;
|
|
||||||
actionText = "Add New Map to Group";
|
actionText = "Add New Map to Group";
|
||||||
break;
|
break;
|
||||||
case MapSortOrder::SortByArea:
|
case MapListTab::Areas:
|
||||||
model = this->mapAreaModel;
|
model = this->mapAreaModel;
|
||||||
dataRole = Qt::UserRole;
|
dataRole = Qt::UserRole;
|
||||||
proxy = this->areaListProxyModel;
|
proxy = this->areaListProxyModel;
|
||||||
list = this->ui->areaList;
|
list = this->ui->areaList;
|
||||||
addFunction = &MainWindow::onAddNewMapToAreaClick;
|
|
||||||
actionText = "Add New Map to Area";
|
actionText = "Add New Map to Area";
|
||||||
break;
|
break;
|
||||||
case MapSortOrder::SortByLayout:
|
case MapListTab::Layouts:
|
||||||
model = this->layoutTreeModel;
|
model = this->layoutTreeModel;
|
||||||
dataRole = Qt::UserRole;
|
dataRole = Qt::UserRole;
|
||||||
proxy = this->layoutListProxyModel;
|
proxy = this->layoutListProxyModel;
|
||||||
list = this->ui->layoutList;
|
list = this->ui->layoutList;
|
||||||
addFunction = &MainWindow::onAddNewMapToLayoutClick;
|
|
||||||
actionText = "Add New Map with Layout";
|
actionText = "Add New Map with Layout";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -1358,7 +1357,14 @@ void MainWindow::onOpenMapListContextMenu(const QPoint &point) {
|
||||||
QMenu menu(this);
|
QMenu menu(this);
|
||||||
QActionGroup actions(&menu);
|
QActionGroup actions(&menu);
|
||||||
actions.addAction(menu.addAction(actionText))->setData(itemData);
|
actions.addAction(menu.addAction(actionText))->setData(itemData);
|
||||||
(this->*addFunction)(menu.exec(QCursor::pos()));
|
|
||||||
|
auto triggeredAction = menu.exec(QCursor::pos());
|
||||||
|
if (!triggeredAction)
|
||||||
|
return;
|
||||||
|
|
||||||
|
// At the moment all the actions do the same thing (add new map/layout).
|
||||||
|
openNewMapPopupWindow();
|
||||||
|
this->newMapPrompt->init(currentTab, triggeredAction->data());
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::mapListAddGroup() {
|
void MainWindow::mapListAddGroup() {
|
||||||
|
@ -1598,28 +1604,6 @@ void MainWindow::mapListRemoveLayout() {
|
||||||
// TODO: consider this in the future
|
// TODO: consider this in the future
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void MainWindow::onAddNewMapToGroupClick(QAction* triggeredAction) {
|
|
||||||
if (!triggeredAction) return;
|
|
||||||
|
|
||||||
openNewMapPopupWindow();
|
|
||||||
this->newMapPrompt->init(MapSortOrder::SortByGroup, triggeredAction->data());
|
|
||||||
}
|
|
||||||
|
|
||||||
void MainWindow::onAddNewMapToAreaClick(QAction* triggeredAction) {
|
|
||||||
if (!triggeredAction) return;
|
|
||||||
|
|
||||||
openNewMapPopupWindow();
|
|
||||||
this->newMapPrompt->init(MapSortOrder::SortByArea, triggeredAction->data());
|
|
||||||
}
|
|
||||||
|
|
||||||
void MainWindow::onAddNewMapToLayoutClick(QAction* triggeredAction) {
|
|
||||||
if (!triggeredAction) return;
|
|
||||||
|
|
||||||
openNewMapPopupWindow();
|
|
||||||
this->newMapPrompt->init(MapSortOrder::SortByLayout, triggeredAction->data());
|
|
||||||
}
|
|
||||||
|
|
||||||
void MainWindow::onNewMapCreated() {
|
void MainWindow::onNewMapCreated() {
|
||||||
QString newMapName = this->newMapPrompt->map->name;
|
QString newMapName = this->newMapPrompt->map->name;
|
||||||
int newMapGroup = this->newMapPrompt->group;
|
int newMapGroup = this->newMapPrompt->group;
|
||||||
|
@ -1862,19 +1846,8 @@ void MainWindow::currentMetatilesSelectionChanged() {
|
||||||
scrollMetatileSelectorToSelection();
|
scrollMetatileSelectorToSelection();
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Redundant. Remove
|
void MainWindow::saveMapListTab(int index) {
|
||||||
void MainWindow::on_mapListContainer_currentChanged(int index) {
|
porymapConfig.mapListTab = index;
|
||||||
switch (index) {
|
|
||||||
case MapListTab::Groups:
|
|
||||||
porymapConfig.mapSortOrder = MapSortOrder::SortByGroup;
|
|
||||||
break;
|
|
||||||
case MapListTab::Areas:
|
|
||||||
porymapConfig.mapSortOrder = MapSortOrder::SortByArea;
|
|
||||||
break;
|
|
||||||
case MapListTab::Layouts:
|
|
||||||
porymapConfig.mapSortOrder = MapSortOrder::SortByLayout;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::openMapListItem(const QModelIndex &index) {
|
void MainWindow::openMapListItem(const QModelIndex &index) {
|
||||||
|
|
|
@ -102,17 +102,17 @@ void NewMapPopup::init() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Creating new map by right-clicking in the map list
|
// Creating new map by right-clicking in the map list
|
||||||
void NewMapPopup::init(MapSortOrder type, QVariant data) {
|
void NewMapPopup::init(int tabIndex, QVariant data) {
|
||||||
initUi();
|
initUi();
|
||||||
switch (type)
|
switch (tabIndex)
|
||||||
{
|
{
|
||||||
case MapSortOrder::SortByGroup:
|
case MapListTab::Groups:
|
||||||
settings.group = project->groupNames.at(data.toInt());
|
settings.group = project->groupNames.at(data.toInt());
|
||||||
break;
|
break;
|
||||||
case MapSortOrder::SortByArea:
|
case MapListTab::Areas:
|
||||||
settings.location = data.toString();
|
settings.location = data.toString();
|
||||||
break;
|
break;
|
||||||
case MapSortOrder::SortByLayout:
|
case MapListTab::Layouts:
|
||||||
this->ui->checkBox_UseExistingLayout->setCheckState(Qt::Checked);
|
this->ui->checkBox_UseExistingLayout->setCheckState(Qt::Checked);
|
||||||
useLayout(data.toString());
|
useLayout(data.toString());
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in a new issue