Simplify map list icon updating
This commit is contained in:
parent
4af1c4d463
commit
edb4a67994
3 changed files with 44 additions and 35 deletions
|
@ -340,7 +340,6 @@ private:
|
||||||
QMap<Event::Group, DraggablePixmapItem*> lastSelectedEvent;
|
QMap<Event::Group, DraggablePixmapItem*> lastSelectedEvent;
|
||||||
|
|
||||||
bool isProgrammaticEventTabChange;
|
bool isProgrammaticEventTabChange;
|
||||||
bool projectHasUnsavedChanges;
|
|
||||||
bool newMapDefaultsSet = false;
|
bool newMapDefaultsSet = false;
|
||||||
|
|
||||||
MapSortOrder mapSortOrder;
|
MapSortOrder mapSortOrder;
|
||||||
|
@ -366,7 +365,7 @@ private:
|
||||||
QStandardItem* createMapItem(QString mapName, int groupNum, int inGroupNum);
|
QStandardItem* createMapItem(QString mapName, int groupNum, int inGroupNum);
|
||||||
void refreshRecentProjectsMenu();
|
void refreshRecentProjectsMenu();
|
||||||
|
|
||||||
void drawMapListIcons(QAbstractItemModel *model);
|
void updateMapListIcon(const QString &mapName);
|
||||||
void updateMapList();
|
void updateMapList();
|
||||||
|
|
||||||
void displayMapProperties();
|
void displayMapProperties();
|
||||||
|
|
|
@ -981,7 +981,6 @@ void Editor::updateDiveEmergeVisibility() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Fold into PixmapItem
|
|
||||||
QPoint Editor::calculateConnectionPosition(MapConnection *connection, const QPixmap &pixmap) {
|
QPoint Editor::calculateConnectionPosition(MapConnection *connection, const QPixmap &pixmap) {
|
||||||
const QString direction = connection->direction();
|
const QString direction = connection->direction();
|
||||||
int offset = connection->offset();
|
int offset = connection->offset();
|
||||||
|
|
|
@ -421,9 +421,7 @@ void MainWindow::markMapEdited(Map* map) {
|
||||||
return;
|
return;
|
||||||
map->hasUnsavedDataChanges = true;
|
map->hasUnsavedDataChanges = true;
|
||||||
|
|
||||||
// TODO: Only update the necessary list icon
|
updateMapListIcon(map->name);
|
||||||
updateMapList();
|
|
||||||
|
|
||||||
if (editor && editor->map == map)
|
if (editor && editor->map == map)
|
||||||
showWindowTitle();
|
showWindowTitle();
|
||||||
}
|
}
|
||||||
|
@ -807,8 +805,10 @@ bool MainWindow::setMap(QString map_name, bool scrollTreeView) {
|
||||||
|
|
||||||
connect(editor->map, &Map::mapNeedsRedrawing, this, &MainWindow::onMapNeedsRedrawing);
|
connect(editor->map, &Map::mapNeedsRedrawing, this, &MainWindow::onMapNeedsRedrawing);
|
||||||
|
|
||||||
|
// Swap the "currently-open" icon from the old map to the new map
|
||||||
|
updateMapListIcon(userConfig.recentMap);
|
||||||
userConfig.recentMap = map_name;
|
userConfig.recentMap = map_name;
|
||||||
updateMapList();
|
updateMapListIcon(userConfig.recentMap);
|
||||||
|
|
||||||
Scripting::cb_MapOpened(map_name);
|
Scripting::cb_MapOpened(map_name);
|
||||||
prefab.updatePrefabUi(editor->map);
|
prefab.updatePrefabUi(editor->map);
|
||||||
|
@ -1535,38 +1535,39 @@ void MainWindow::on_mapList_activated(const QModelIndex &index)
|
||||||
userSetMap(data.toString());
|
userSetMap(data.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::drawMapListIcons(QAbstractItemModel *model) {
|
void MainWindow::updateMapListIcon(const QString &mapName) {
|
||||||
projectHasUnsavedChanges = false;
|
if (!editor->project || !editor->project->mapCache.contains(mapName))
|
||||||
QList<QModelIndex> list;
|
return;
|
||||||
list.append(QModelIndex());
|
|
||||||
while (list.length()) {
|
QStandardItem *item = mapListModel->itemFromIndex(mapListIndexes.value(mapName));
|
||||||
QModelIndex parent = list.takeFirst();
|
if (!item)
|
||||||
for (int i = 0; i < model->rowCount(parent); i++) {
|
return;
|
||||||
QModelIndex index = model->index(i, 0, parent);
|
|
||||||
if (model->hasChildren(index)) {
|
if (editor->map && editor->map->name == mapName) {
|
||||||
list.append(index);
|
item->setIcon(*mapOpenedIcon);
|
||||||
}
|
} else if (editor->project->mapCache.value(mapName)->hasUnsavedChanges()) {
|
||||||
QVariant data = index.data(Qt::UserRole);
|
item->setIcon(*mapEditedIcon);
|
||||||
if (!data.isNull()) {
|
} else {
|
||||||
QString map_name = data.toString();
|
item->setIcon(*mapIcon);
|
||||||
if (editor->project && editor->project->mapCache.contains(map_name)) {
|
|
||||||
QStandardItem *map = mapListModel->itemFromIndex(mapListIndexes.value(map_name));
|
|
||||||
map->setIcon(*mapIcon);
|
|
||||||
if (editor->project->mapCache.value(map_name)->hasUnsavedChanges()) {
|
|
||||||
map->setIcon(*mapEditedIcon);
|
|
||||||
projectHasUnsavedChanges = true;
|
|
||||||
}
|
|
||||||
if (editor->map->name == map_name) {
|
|
||||||
map->setIcon(*mapOpenedIcon);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::updateMapList() {
|
void MainWindow::updateMapList() {
|
||||||
drawMapListIcons(mapListModel);
|
QList<QModelIndex> list;
|
||||||
|
list.append(QModelIndex());
|
||||||
|
while (list.length()) {
|
||||||
|
QModelIndex parent = list.takeFirst();
|
||||||
|
for (int i = 0; i < mapListModel->rowCount(parent); i++) {
|
||||||
|
QModelIndex index = mapListModel->index(i, 0, parent);
|
||||||
|
if (mapListModel->hasChildren(index)) {
|
||||||
|
list.append(index);
|
||||||
|
}
|
||||||
|
QVariant data = index.data(Qt::UserRole);
|
||||||
|
if (!data.isNull()) {
|
||||||
|
updateMapListIcon(data.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::on_action_Save_Project_triggered() {
|
void MainWindow::on_action_Save_Project_triggered() {
|
||||||
|
@ -1575,6 +1576,13 @@ void MainWindow::on_action_Save_Project_triggered() {
|
||||||
showWindowTitle();
|
showWindowTitle();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::on_action_Save_triggered() {
|
||||||
|
editor->save();
|
||||||
|
if (editor->map)
|
||||||
|
updateMapListIcon(editor->map->name);
|
||||||
|
showWindowTitle();
|
||||||
|
}
|
||||||
|
|
||||||
void MainWindow::duplicate() {
|
void MainWindow::duplicate() {
|
||||||
editor->duplicateSelectedEvents();
|
editor->duplicateSelectedEvents();
|
||||||
}
|
}
|
||||||
|
@ -1827,12 +1835,6 @@ void MainWindow::paste() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::on_action_Save_triggered() {
|
|
||||||
editor->save();
|
|
||||||
updateMapList();
|
|
||||||
showWindowTitle();
|
|
||||||
}
|
|
||||||
|
|
||||||
void MainWindow::on_mapViewTab_tabBarClicked(int index)
|
void MainWindow::on_mapViewTab_tabBarClicked(int index)
|
||||||
{
|
{
|
||||||
int oldIndex = ui->mapViewTab->currentIndex();
|
int oldIndex = ui->mapViewTab->currentIndex();
|
||||||
|
@ -3128,7 +3130,16 @@ bool MainWindow::closeProject() {
|
||||||
if (!isProjectOpen())
|
if (!isProjectOpen())
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if (projectHasUnsavedChanges || (editor->map && editor->map->hasUnsavedChanges())) {
|
// Check loaded maps for unsaved changes
|
||||||
|
bool unsavedChanges = false;
|
||||||
|
for (auto map : editor->project->mapCache.values()) {
|
||||||
|
if (map && map->hasUnsavedChanges()) {
|
||||||
|
unsavedChanges = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (unsavedChanges) {
|
||||||
QMessageBox::StandardButton result = QMessageBox::question(
|
QMessageBox::StandardButton result = QMessageBox::question(
|
||||||
this, "porymap", "The project has been modified, save changes?",
|
this, "porymap", "The project has been modified, save changes?",
|
||||||
QMessageBox::No | QMessageBox::Yes | QMessageBox::Cancel, QMessageBox::Yes);
|
QMessageBox::No | QMessageBox::Yes | QMessageBox::Cancel, QMessageBox::Yes);
|
||||||
|
|
Loading…
Reference in a new issue