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;
|
||||
|
||||
bool isProgrammaticEventTabChange;
|
||||
bool projectHasUnsavedChanges;
|
||||
bool newMapDefaultsSet = false;
|
||||
|
||||
MapSortOrder mapSortOrder;
|
||||
|
@ -366,7 +365,7 @@ private:
|
|||
QStandardItem* createMapItem(QString mapName, int groupNum, int inGroupNum);
|
||||
void refreshRecentProjectsMenu();
|
||||
|
||||
void drawMapListIcons(QAbstractItemModel *model);
|
||||
void updateMapListIcon(const QString &mapName);
|
||||
void updateMapList();
|
||||
|
||||
void displayMapProperties();
|
||||
|
|
|
@ -981,7 +981,6 @@ void Editor::updateDiveEmergeVisibility() {
|
|||
}
|
||||
}
|
||||
|
||||
// TODO: Fold into PixmapItem
|
||||
QPoint Editor::calculateConnectionPosition(MapConnection *connection, const QPixmap &pixmap) {
|
||||
const QString direction = connection->direction();
|
||||
int offset = connection->offset();
|
||||
|
|
|
@ -421,9 +421,7 @@ void MainWindow::markMapEdited(Map* map) {
|
|||
return;
|
||||
map->hasUnsavedDataChanges = true;
|
||||
|
||||
// TODO: Only update the necessary list icon
|
||||
updateMapList();
|
||||
|
||||
updateMapListIcon(map->name);
|
||||
if (editor && editor->map == map)
|
||||
showWindowTitle();
|
||||
}
|
||||
|
@ -807,8 +805,10 @@ bool MainWindow::setMap(QString map_name, bool scrollTreeView) {
|
|||
|
||||
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;
|
||||
updateMapList();
|
||||
updateMapListIcon(userConfig.recentMap);
|
||||
|
||||
Scripting::cb_MapOpened(map_name);
|
||||
prefab.updatePrefabUi(editor->map);
|
||||
|
@ -1535,38 +1535,39 @@ void MainWindow::on_mapList_activated(const QModelIndex &index)
|
|||
userSetMap(data.toString());
|
||||
}
|
||||
|
||||
void MainWindow::drawMapListIcons(QAbstractItemModel *model) {
|
||||
projectHasUnsavedChanges = false;
|
||||
QList<QModelIndex> list;
|
||||
list.append(QModelIndex());
|
||||
while (list.length()) {
|
||||
QModelIndex parent = list.takeFirst();
|
||||
for (int i = 0; i < model->rowCount(parent); i++) {
|
||||
QModelIndex index = model->index(i, 0, parent);
|
||||
if (model->hasChildren(index)) {
|
||||
list.append(index);
|
||||
}
|
||||
QVariant data = index.data(Qt::UserRole);
|
||||
if (!data.isNull()) {
|
||||
QString map_name = data.toString();
|
||||
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::updateMapListIcon(const QString &mapName) {
|
||||
if (!editor->project || !editor->project->mapCache.contains(mapName))
|
||||
return;
|
||||
|
||||
QStandardItem *item = mapListModel->itemFromIndex(mapListIndexes.value(mapName));
|
||||
if (!item)
|
||||
return;
|
||||
|
||||
if (editor->map && editor->map->name == mapName) {
|
||||
item->setIcon(*mapOpenedIcon);
|
||||
} else if (editor->project->mapCache.value(mapName)->hasUnsavedChanges()) {
|
||||
item->setIcon(*mapEditedIcon);
|
||||
} else {
|
||||
item->setIcon(*mapIcon);
|
||||
}
|
||||
}
|
||||
|
||||
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() {
|
||||
|
@ -1575,6 +1576,13 @@ void MainWindow::on_action_Save_Project_triggered() {
|
|||
showWindowTitle();
|
||||
}
|
||||
|
||||
void MainWindow::on_action_Save_triggered() {
|
||||
editor->save();
|
||||
if (editor->map)
|
||||
updateMapListIcon(editor->map->name);
|
||||
showWindowTitle();
|
||||
}
|
||||
|
||||
void MainWindow::duplicate() {
|
||||
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)
|
||||
{
|
||||
int oldIndex = ui->mapViewTab->currentIndex();
|
||||
|
@ -3128,7 +3130,16 @@ bool MainWindow::closeProject() {
|
|||
if (!isProjectOpen())
|
||||
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(
|
||||
this, "porymap", "The project has been modified, save changes?",
|
||||
QMessageBox::No | QMessageBox::Yes | QMessageBox::Cancel, QMessageBox::Yes);
|
||||
|
|
Loading…
Reference in a new issue