Fix bug #1642684 by removing the blank item and clearing the text box instead.

Add this to your merge proposal:
--------------------------------
lp:~raoul-snyman/openlp/bug-1642684 (revision 2710)
[SUCCESS] https://ci.openlp.io/job/Branch-01-Pull/1869/
[SUCCESS] https://ci.openlp.io/job/Branch-02-Functional-Tests/1780/
[SUCCESS] https://ci.openlp.io/job/Branch-03-Interface-Tests/1718/
[SUCCESS] https://ci.openlp.io/job/Branch-04a-Windows_Functional_Tests/1458/
[SUCCESS] https://ci.openlp.io/...

bzr-revno: 2710
This commit is contained in:
Raoul Snyman 2016-12-15 20:28:36 +02:00
commit 280d35e1be
2 changed files with 40 additions and 10 deletions

View File

@ -118,13 +118,13 @@ class EditSongForm(QtWidgets.QDialog, Ui_EditSongDialog, RegistryProperties):
objects = self.manager.get_all_objects(cls) objects = self.manager.get_all_objects(cls)
objects.sort(key=get_key) objects.sort(key=get_key)
combo.clear() combo.clear()
combo.addItem('')
for obj in objects: for obj in objects:
row = combo.count() row = combo.count()
combo.addItem(obj.name) combo.addItem(obj.name)
cache.append(obj.name) cache.append(obj.name)
combo.setItemData(row, obj.id) combo.setItemData(row, obj.id)
set_case_insensitive_completer(cache, combo) set_case_insensitive_completer(cache, combo)
combo.setEditText('')
def _add_author_to_list(self, author, author_type): def _add_author_to_list(self, author, author_type):
""" """
@ -360,7 +360,6 @@ class EditSongForm(QtWidgets.QDialog, Ui_EditSongDialog, RegistryProperties):
authors = self.manager.get_all_objects(Author) authors = self.manager.get_all_objects(Author)
authors.sort(key=get_author_key) authors.sort(key=get_author_key)
self.authors_combo_box.clear() self.authors_combo_box.clear()
self.authors_combo_box.addItem('')
self.authors = [] self.authors = []
for author in authors: for author in authors:
row = self.authors_combo_box.count() row = self.authors_combo_box.count()
@ -368,6 +367,7 @@ class EditSongForm(QtWidgets.QDialog, Ui_EditSongDialog, RegistryProperties):
self.authors_combo_box.setItemData(row, author.id) self.authors_combo_box.setItemData(row, author.id)
self.authors.append(author.display_name) self.authors.append(author.display_name)
set_case_insensitive_completer(self.authors, self.authors_combo_box) set_case_insensitive_completer(self.authors, self.authors_combo_box)
self.authors_combo_box.setEditText('')
# Types # Types
self.author_types_combo_box.clear() self.author_types_combo_box.clear()
@ -398,11 +398,11 @@ class EditSongForm(QtWidgets.QDialog, Ui_EditSongDialog, RegistryProperties):
return get_natural_key(theme) return get_natural_key(theme)
self.theme_combo_box.clear() self.theme_combo_box.clear()
self.theme_combo_box.addItem('')
self.themes = theme_list self.themes = theme_list
self.themes.sort(key=get_theme_key) self.themes.sort(key=get_theme_key)
self.theme_combo_box.addItems(theme_list) self.theme_combo_box.addItems(theme_list)
set_case_insensitive_completer(self.themes, self.theme_combo_box) set_case_insensitive_completer(self.themes, self.theme_combo_box)
self.theme_combo_box.setEditText('')
def load_media_files(self): def load_media_files(self):
""" """
@ -442,7 +442,6 @@ class EditSongForm(QtWidgets.QDialog, Ui_EditSongDialog, RegistryProperties):
self.load_songbooks() self.load_songbooks()
self.load_media_files() self.load_media_files()
self.theme_combo_box.setEditText('') self.theme_combo_box.setEditText('')
self.theme_combo_box.setCurrentIndex(0)
# it's a new song to preview is not possible # it's a new song to preview is not possible
self.preview_button.setVisible(False) self.preview_button.setVisible(False)
@ -591,7 +590,7 @@ class EditSongForm(QtWidgets.QDialog, Ui_EditSongDialog, RegistryProperties):
self.manager.save_object(author) self.manager.save_object(author)
self._add_author_to_list(author, author_type) self._add_author_to_list(author, author_type)
self.load_authors() self.load_authors()
self.authors_combo_box.setCurrentIndex(0) self.authors_combo_box.setEditText('')
else: else:
return return
elif item > 0: elif item > 0:
@ -602,7 +601,7 @@ class EditSongForm(QtWidgets.QDialog, Ui_EditSongDialog, RegistryProperties):
message=translate('SongsPlugin.EditSongForm', 'This author is already in the list.')) message=translate('SongsPlugin.EditSongForm', 'This author is already in the list.'))
else: else:
self._add_author_to_list(author, author_type) self._add_author_to_list(author, author_type)
self.authors_combo_box.setCurrentIndex(0) self.authors_combo_box.setEditText('')
else: else:
QtWidgets.QMessageBox.warning( QtWidgets.QMessageBox.warning(
self, UiStrings().NISs, self, UiStrings().NISs,
@ -666,7 +665,7 @@ class EditSongForm(QtWidgets.QDialog, Ui_EditSongDialog, RegistryProperties):
topic_item.setData(QtCore.Qt.UserRole, topic.id) topic_item.setData(QtCore.Qt.UserRole, topic.id)
self.topics_list_view.addItem(topic_item) self.topics_list_view.addItem(topic_item)
self.load_topics() self.load_topics()
self.topics_combo_box.setCurrentIndex(0) self.topics_combo_box.setEditText('')
else: else:
return return
elif item > 0: elif item > 0:
@ -679,7 +678,7 @@ class EditSongForm(QtWidgets.QDialog, Ui_EditSongDialog, RegistryProperties):
topic_item = QtWidgets.QListWidgetItem(str(topic.name)) topic_item = QtWidgets.QListWidgetItem(str(topic.name))
topic_item.setData(QtCore.Qt.UserRole, topic.id) topic_item.setData(QtCore.Qt.UserRole, topic.id)
self.topics_list_view.addItem(topic_item) self.topics_list_view.addItem(topic_item)
self.topics_combo_box.setCurrentIndex(0) self.topics_combo_box.setEditText('')
else: else:
QtWidgets.QMessageBox.warning( QtWidgets.QMessageBox.warning(
self, UiStrings().NISs, self, UiStrings().NISs,
@ -709,7 +708,7 @@ class EditSongForm(QtWidgets.QDialog, Ui_EditSongDialog, RegistryProperties):
self.manager.save_object(songbook) self.manager.save_object(songbook)
self.add_songbook_entry_to_list(songbook.id, songbook.name, self.songbook_entry_edit.text()) self.add_songbook_entry_to_list(songbook.id, songbook.name, self.songbook_entry_edit.text())
self.load_songbooks() self.load_songbooks()
self.songbooks_combo_box.setCurrentIndex(0) self.songbooks_combo_box.setEditText('')
self.songbook_entry_edit.clear() self.songbook_entry_edit.clear()
else: else:
return return
@ -721,7 +720,7 @@ class EditSongForm(QtWidgets.QDialog, Ui_EditSongDialog, RegistryProperties):
message=translate('SongsPlugin.EditSongForm', 'This Songbook is already in the list.')) message=translate('SongsPlugin.EditSongForm', 'This Songbook is already in the list.'))
else: else:
self.add_songbook_entry_to_list(songbook.id, songbook.name, self.songbook_entry_edit.text()) self.add_songbook_entry_to_list(songbook.id, songbook.name, self.songbook_entry_edit.text())
self.songbooks_combo_box.setCurrentIndex(0) self.songbooks_combo_box.setEditText('')
self.songbook_entry_edit.clear() self.songbook_entry_edit.clear()
else: else:
QtWidgets.QMessageBox.warning( QtWidgets.QMessageBox.warning(

View File

@ -76,3 +76,34 @@ class TestEditSongForm(TestCase, TestMixin):
# THEN they should be valid # THEN they should be valid
self.assertTrue(valid, "The tags list should be valid") self.assertTrue(valid, "The tags list should be valid")
@patch('openlp.plugins.songs.forms.editsongform.set_case_insensitive_completer')
def test_load_objects(self, mocked_set_case_insensitive_completer):
"""
Test the _load_objects() method
"""
# GIVEN: A song edit form and some mocked stuff
mocked_class = MagicMock()
mocked_class.name = 'Author'
mocked_combo = MagicMock()
mocked_combo.count.return_value = 0
mocked_cache = MagicMock()
mocked_object = MagicMock()
mocked_object.name = 'Charles'
mocked_object.id = 1
mocked_manager = MagicMock()
mocked_manager.get_all_objects.return_value = [mocked_object]
self.edit_song_form.manager = mocked_manager
# WHEN: _load_objects() is called
self.edit_song_form._load_objects(mocked_class, mocked_combo, mocked_cache)
# THEN: All the correct methods should have been called
self.edit_song_form.manager.get_all_objects.assert_called_once_with(mocked_class)
mocked_combo.clear.assert_called_once_with()
mocked_combo.count.assert_called_once_with()
mocked_combo.addItem.assert_called_once_with('Charles')
mocked_cache.append.assert_called_once_with('Charles')
mocked_combo.setItemData.assert_called_once_with(0, 1)
mocked_set_case_insensitive_completer.assert_called_once_with(mocked_cache, mocked_combo)
mocked_combo.setEditText.assert_called_once_with('')