Fixed bug where deleted group would still show up in the 'add group' combobox

This commit is contained in:
Arjan Schrijver 2013-01-30 10:56:06 +01:00
parent 42a75e545e
commit dbcd1080ea
2 changed files with 13 additions and 7 deletions

View File

@ -44,10 +44,13 @@ class AddGroupForm(QtGui.QDialog, Ui_AddGroupDialog):
QtGui.QDialog.__init__(self, parent)
self.setupUi(self)
def exec_(self, clear=True):
def exec_(self, clear=True, showTopLevelGroup=False):
if clear:
self.nameEdit.clear()
self.nameEdit.setFocus()
if showTopLevelGroup and not self.parentGroupComboBox.topLevelGroupAdded:
self.parentGroupComboBox.insertItem(0, translate('ImagePlugin.MediaItem', '-- Top-level group --'), 0)
self.parentGroupComboBox.topLevelGroupAdded = True
return QtGui.QDialog.exec_(self)
def accept(self):

View File

@ -56,6 +56,7 @@ class ImageMediaItem(MediaManagerItem):
self.manager = plugin.manager
self.choosegroupform = ChooseGroupForm(self)
self.addgroupform = AddGroupForm(self)
self.fillGroupsComboBox(self.choosegroupform.groupComboBox)
self.fillGroupsComboBox(self.addgroupform.parentGroupComboBox)
QtCore.QObject.connect(Receiver.get_receiver(), QtCore.SIGNAL(u'live_theme_changed'), self.liveThemeChanged)
# Allow DnD from the desktop
@ -151,13 +152,16 @@ class ImageMediaItem(MediaManagerItem):
translate('ImagePlugin.MediaItem', 'Remove group'),
translate('ImagePlugin.MediaItem',
'Are you sure you want to remove "%s" and everything in it?') % item_data.group_name,
QtGui.QMessageBox.StandardButtons(QtGui.QMessageBox.Yes | QtGui.QMessageBox.No)) == QtGui.QMessageBox.Yes:
QtGui.QMessageBox.StandardButtons(QtGui.QMessageBox.Yes |
QtGui.QMessageBox.No)) == QtGui.QMessageBox.Yes:
self.recursivelyDeleteGroup(item_data)
self.manager.delete_object(ImageGroups, row_item.data(0, QtCore.Qt.UserRole).id)
if item_data.parent_id is 0:
self.listView.takeTopLevelItem(self.listView.indexOfTopLevelItem(row_item))
else:
row_item.parent().removeChild(row_item)
self.fillGroupsComboBox(self.choosegroupform.groupComboBox)
self.fillGroupsComboBox(self.addgroupform.parentGroupComboBox)
self.main_window.incrementProgressBar()
self.main_window.finishedProgressBar()
Receiver.send_message(u'cursor_normal')
@ -180,14 +184,13 @@ class ImageMediaItem(MediaManagerItem):
groupList[image_group.id] = group
self.addSubGroups(groupList, image_group.id)
def fillGroupsComboBox(self, comboBox, parentGroupId=0, prefix='', showTopLevelGroup=True):
def fillGroupsComboBox(self, comboBox, parentGroupId=0, prefix=''):
"""
Recursively add groups to the combobox in the 'Add group' dialog
"""
if parentGroupId is 0:
comboBox.clear()
if showTopLevelGroup is True:
comboBox.addItem(translate('ImagePlugin.MediaItem', '-- Top-level group --'), 0)
comboBox.topLevelGroupAdded = False
image_groups = self.manager.get_all_objects(ImageGroups, ImageGroups.parent_id == parentGroupId)
image_groups.sort(cmp=locale_compare, key=lambda group_object: group_object.group_name)
for image_group in image_groups:
@ -245,7 +248,6 @@ class ImageMediaItem(MediaManagerItem):
"""
if target_group is None:
# Ask which group the images should be saved in
self.fillGroupsComboBox(self.choosegroupform.groupComboBox, showTopLevelGroup=False)
if self.choosegroupform.exec_():
group_id = self.choosegroupform.groupComboBox.itemData(
self.choosegroupform.groupComboBox.currentIndex(), QtCore.Qt.UserRole)
@ -384,7 +386,7 @@ class ImageMediaItem(MediaManagerItem):
"""
Called to add a new group
"""
if self.addgroupform.exec_():
if self.addgroupform.exec_(showTopLevelGroup=True):
new_group = ImageGroups.populate(parent_id=self.addgroupform.parentGroupComboBox.itemData(
self.addgroupform.parentGroupComboBox.currentIndex(), QtCore.Qt.UserRole),
group_name=self.addgroupform.nameEdit.text())
@ -392,6 +394,7 @@ class ImageMediaItem(MediaManagerItem):
if self.manager.save_object(new_group):
self.loadFullList(self.manager.get_all_objects(ImageFilenames,
order_by_ref=ImageFilenames.filename))
self.fillGroupsComboBox(self.choosegroupform.groupComboBox)
self.fillGroupsComboBox(self.addgroupform.parentGroupComboBox)
else:
critical_error_message_box(