Skip to content

Commit

Permalink
Fix 617: Reload project following sync of updated .qgz file on windows (
Browse files Browse the repository at this point in the history
#632)

The qgis project was not reloading after a sync on windows when there was only change to the .qgz file

This happened because  QgsProject.instance().fileName() &QgsProject.instance().absolutePath()returned unix-style path even on windows. This behavior mismatch with the return of e.g os.path.join in python.

This PR fix the is by adding an extra os.path.normpath

Fix #617
  • Loading branch information
ValentinBuira authored Oct 11, 2024
1 parent 4e57258 commit ef0b250
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 11 deletions.
1 change: 0 additions & 1 deletion Mergin/create_project_wizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
check_mergin_subdirs,
create_basic_qgis_project,
find_packable_layers,
find_qgis_files,
package_layer,
PackagingError,
save_current_project,
Expand Down
6 changes: 0 additions & 6 deletions Mergin/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -715,12 +715,6 @@ def sync_project(self):
return
self.project_manager.project_status(self.path)

def _reload_project(self):
"""This will forcefully reload the QGIS project because the project (or its data) may have changed"""
qgis_files = find_qgis_files(self.path)
if QgsProject.instance().fileName() in qgis_files:
iface.addProject(QgsProject.instance().fileName())

def remove_local_project(self):
if not self.path:
return
Expand Down
7 changes: 4 additions & 3 deletions Mergin/projects_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ def unsaved_changes_check(project_dir):
"""
Check if current project is the same as actually operated Mergin project and has some unsaved changes.
"""
if QgsProject.instance().fileName() in find_qgis_files(project_dir):
qgis_proj_filename = os.path.normpath(QgsProject.instance().fileName())
if qgis_proj_filename in find_qgis_files(project_dir):
check_result = unsaved_project_check()
return False if check_result == UnsavedChangesStrategy.HasUnsavedChanges else True
return True # not a Mergin project
Expand Down Expand Up @@ -255,7 +256,7 @@ def reset_local_changes(self, project_dir: str, files_to_reset=None):
if not self.check_project_server(project_dir):
return

current_project_filename = QgsProject.instance().fileName()
current_project_filename = os.path.normpath(QgsProject.instance().fileName())
current_project_path = os.path.normpath(QgsProject.instance().absolutePath())
if current_project_path == os.path.normpath(project_dir):
QgsProject.instance().clear()
Expand Down Expand Up @@ -356,7 +357,7 @@ def sync_project(self, project_dir, project_name=None):
dlg.push_start(self.mc, project_dir, project_name)
dlg.exec_() # blocks until success, failure or cancellation

qgis_proj_filename = QgsProject.instance().fileName()
qgis_proj_filename = os.path.normpath(QgsProject.instance().fileName())
qgis_proj_basename = os.path.basename(qgis_proj_filename)
qgis_proj_changed = False
for updated in pull_changes["updated"]:
Expand Down
2 changes: 1 addition & 1 deletion Mergin/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1026,7 +1026,7 @@ def mergin_project_local_path(project_name=None):
proj_path = None
return proj_path

qgis_project_path = QgsProject.instance().absolutePath()
qgis_project_path = os.path.normpath(QgsProject.instance().absolutePath())
if not qgis_project_path:
return None

Expand Down

0 comments on commit ef0b250

Please sign in to comment.