Skip to content

Commit

Permalink
Proper disabling of unticked KML files.
Browse files Browse the repository at this point in the history
Fix #1866
  • Loading branch information
joernu76 committed Aug 9, 2023
1 parent ec2df5d commit 62adb63
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
23 changes: 11 additions & 12 deletions mslib/msui/kmloverlay_dockwidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,8 @@ def __init__(self, parent=None, view=None):

def update(self):
for entry in self.dict_files.values():
entry["patch"].update()
if entry["patch"] is not None:
entry["patch"].update()

def save_settings(self):
for entry in self.dict_files.values():
Expand Down Expand Up @@ -375,11 +376,9 @@ def select_color(self):
self.dict_files[filename]["color"] = self.colour.getRgbF()
self.flag2 = 1 # sets flag of 0 to 1 when the color changes
self.listWidget.currentItem().setIcon(self.show_color_icon(filename, self.set_color(filename)))
self.dict_files[filename]["patch"].update(
self.dict_files[filename]["color"], self.dict_files[filename]["linewidth"])
if self.listWidget.currentItem().checkState() == QtCore.Qt.Unchecked:
self.flag2 = 1 # again sets to 1 because itemChanged signal due to set icon had changed it to 0
self.checklistitem(filename)
if self.dict_files[filename]["patch"] is not None:
self.dict_files[filename]["patch"].update(
self.dict_files[filename]["color"], self.dict_files[filename]["linewidth"])

def set_color(self, filename):
"""
Expand All @@ -399,12 +398,10 @@ def select_linewidth(self):
self.flag = 1 # sets flag of 0 to 1 when the linewidth changes
self.listWidget.currentItem().setIcon(self.show_color_icon(filename, self.set_color(filename)))
# removes and updates patches in the map according to new linewidth
self.dict_files[filename]["patch"].remove()
self.dict_files[filename]["patch"].update(
self.dict_files[filename]["color"], self.dict_files[filename]["linewidth"])
if self.listWidget.currentItem().checkState() == QtCore.Qt.Unchecked:
self.flag = 1 # again sets to 1 because itemChanged signal due to set icon had changed it to 0
self.checklistitem(filename)
if self.dict_files[filename]["patch"] is not None:
self.dict_files[filename]["patch"].remove()
self.dict_files[filename]["patch"].update(
self.dict_files[filename]["color"], self.dict_files[filename]["linewidth"])

def set_linewidth(self, filename):
"""
Expand Down Expand Up @@ -525,6 +522,7 @@ def remove_file(self): # removes checked files
self.listWidget.item(index).checkState() == QtCore.Qt.Checked): # if file is checked
if self.dict_files[self.listWidget.item(index).text()]["patch"] is not None:
self.dict_files[self.listWidget.item(index).text()]["patch"].remove() # remove patch object
self.dict_files[self.listWidget.item(index).text()]["patch"] = None # remove patch object
del self.dict_files[self.listWidget.item(index).text()] # del the checked files from dictionary
self.listWidget.takeItem(index) # remove file item from ListWidget
self.remove_file() # recursively since count of for loop changes every iteration due to del of items))
Expand All @@ -542,6 +540,7 @@ def load_file(self):
for entry in self.dict_files.values(): # removes all patches from map, but not from dict_flighttrack
if entry["patch"] is not None: # since newly initialized files will have patch:None
entry["patch"].remove()
entry["patch"] = None

for index in range(self.listWidget.count()):
if hasattr(self.listWidget.item(index), "checkState") and (
Expand Down
2 changes: 1 addition & 1 deletion tests/_test_msui/test_kmloverlay_dockwidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ def test_check_uncheck(self):
assert len([_x for _x in self.window.dict_files.values() if _x["patch"] is not None]) == 1
self.window.listWidget.item(0).setCheckState(QtCore.Qt.Unchecked)
assert self.window.listWidget.item(0).checkState() == QtCore.Qt.Unchecked
assert len([_x for _x in self.window.dict_files.values() if _x["patch"] is not None]) == 1
assert len([_x for _x in self.window.dict_files.values() if _x["patch"] is not None]) == 0
self.window.select_all()
self.window.remove_file()

Expand Down

0 comments on commit 62adb63

Please sign in to comment.