continued with QVariant

This commit is contained in:
Andreas Preikschat 2012-05-19 11:13:32 +02:00
parent b07fab7ff0
commit b124481ea2
14 changed files with 67 additions and 98 deletions

View File

@ -28,6 +28,7 @@
import sip
sip.setapi(u'QString', 2)
sip.setapi(u'QVariant', 2)
from openlp.core import main

View File

@ -64,23 +64,6 @@ class ServiceItemAction(object):
Next = 3
class MissingTypeConversion(Exception):
"""
A exception class which is used when a setting is not converted.
"""
def __init__(self, msg):
"""
Constructor
"""
self.msg = msg
def __str__(self):
"""
Returns a string representation.
"""
return repr(self.msg)
class Settings(QtCore.QSettings):
"""
This class customises the ``QSettings`` class. You must use this class
@ -109,25 +92,17 @@ class Settings(QtCore.QSettings):
**Note**, this method only converts a few types and might need to be
extended if a certain type is missing!
"""
setting = super(Settings, self).value(key, defaultValue)
# FIXME
if key == u'recent files':
return []
setting = super(Settings, self).value(key, defaultValue)
# Convert the setting to the correct type.
if isinstance(defaultValue, bool):
return setting.toBool()
if isinstance(defaultValue, QtCore.QByteArray):
return setting.toByteArray()
return bool(setting)
# Enumerations are also taken care of.
if isinstance(defaultValue, int):
return setting.toInt()[0]
if isinstance(defaultValue, basestring):
return setting.toString()
if isinstance(defaultValue, list):
return setting.toStringList()
if isinstance(defaultValue, QtCore.QPoint):
return setting.toPoint()
if isinstance(defaultValue, (datetime.date, QtCore.QDate)):
return setting.toDate()
print u'No!', type(defaultValue)
raise MissingTypeConversion(u'Setting could not be converted')
return int(setting)
return setting
def translate(context, text, comment=None,

View File

@ -622,11 +622,11 @@ class MediaManagerItem(QtGui.QWidget):
item = self.listView.currentItem()
if item is None:
return False
item_id = (item.data(QtCore.Qt.UserRole)).toInt()[0]
item_id = item.data(QtCore.Qt.UserRole)
else:
item_id = remoteItem
else:
item_id = (item.data(QtCore.Qt.UserRole)).toInt()[0]
item_id = item.data(QtCore.Qt.UserRole)
return item_id
def saveAutoSelectId(self):
@ -637,7 +637,7 @@ class MediaManagerItem(QtGui.QWidget):
if self.autoSelectId == -1:
item = self.listView.currentItem()
if item:
self.autoSelectId = item.data(QtCore.Qt.UserRole).toInt()[0]
self.autoSelectId = item.data(QtCore.Qt.UserRole)
def search(self, string, showError=True):
"""

View File

@ -121,7 +121,7 @@ class SearchEdit(QtGui.QLineEdit):
"""
menu = self.menuButton.menu()
for action in menu.actions():
if identifier == action.data().toInt()[0]:
if identifier == action.data():
# setPlaceholderText has been implemented in Qt 4.7 and in at
# least PyQt 4.9 (I am not sure, if it was implemented in
# PyQt 4.8).
@ -209,7 +209,7 @@ class SearchEdit(QtGui.QLineEdit):
for action in self.menuButton.menu().actions():
action.setChecked(False)
self.menuButton.setDefaultAction(sender)
self._currentSearchType = sender.data().toInt()[0]
self._currentSearchType = sender.data()
# setPlaceholderText has been implemented in Qt 4.7 and in at least
# PyQt 4.9 (I am not sure, if it was implemented in PyQt 4.8).
try:

View File

@ -407,9 +407,9 @@ class WebkitPlayer(MediaPlayer):
controller = display.controller
if controller.media_info.is_flash:
currentTime = display.frame.evaluateJavaScript( \
u'show_flash("currentTime");').toInt()[0]
u'show_flash("currentTime");')
length = display.frame.evaluateJavaScript( \
u'show_flash("length");').toInt()[0]
u'show_flash("length");')
else:
if display.frame.evaluateJavaScript( \
u'show_video("isEnded");').toString() == 'true':

View File

@ -737,9 +737,9 @@ class ServiceManager(QtGui.QWidget):
if item is None:
return
if item.parent():
pos = item.parent().data(0, QtCore.Qt.UserRole).toInt()[0]
pos = item.parent().data(0, QtCore.Qt.UserRole)
else:
pos = item.data(0, QtCore.Qt.UserRole).toInt()[0]
pos = item.data(0, QtCore.Qt.UserRole)
serviceItem = self.serviceItems[pos - 1]
self.editAction.setVisible(False)
self.maintainAction.setVisible(False)
@ -841,7 +841,7 @@ class ServiceManager(QtGui.QWidget):
while serviceIterator.value():
if serviceIterator.value() == selected:
if message == u'last slide' and prevItemLastSlide:
pos = prevItem.data(0, QtCore.Qt.UserRole).toInt()[0]
pos = prevItem.data(0, QtCore.Qt.UserRole)
check_expanded = self.serviceItems[pos - 1][u'expanded']
self.serviceManagerList.setCurrentItem(prevItemLastSlide)
if not check_expanded:
@ -908,7 +908,7 @@ class ServiceManager(QtGui.QWidget):
Record if an item is collapsed. Used when repainting the list to get the
correct state.
"""
pos = item.data(0, QtCore.Qt.UserRole).toInt()[0]
pos = item.data(0, QtCore.Qt.UserRole)
self.serviceItems[pos - 1][u'expanded'] = False
def onExpandAll(self):
@ -924,7 +924,7 @@ class ServiceManager(QtGui.QWidget):
Record if an item is collapsed. Used when repainting the list to get the
correct state.
"""
pos = item.data(0, QtCore.Qt.UserRole).toInt()[0]
pos = item.data(0, QtCore.Qt.UserRole)
self.serviceItems[pos - 1][u'expanded'] = True
def onServiceTop(self):
@ -1133,10 +1133,9 @@ class ServiceManager(QtGui.QWidget):
serviceIterator += 1
if selectedItem is not None:
if selectedItem.parent() is None:
pos = selectedItem.data(0, QtCore.Qt.UserRole).toInt()[0]
pos = selectedItem.data(0, QtCore.Qt.UserRole)
else:
pos = selectedItem.parent().data(0, QtCore.Qt.UserRole). \
toInt()[0]
pos = selectedItem.parent().data(0, QtCore.Qt.UserRole)
self.serviceItems[pos - 1][u'selected'] = True
tempServiceItems = self.serviceItems
self.serviceManagerList.clear()
@ -1321,10 +1320,10 @@ class ServiceManager(QtGui.QWidget):
for item in items:
parentitem = item.parent()
if parentitem is None:
serviceItem = item.data(0, QtCore.Qt.UserRole).toInt()[0]
serviceItem = item.data(0, QtCore.Qt.UserRole)
else:
serviceItem = parentitem.data(0, QtCore.Qt.UserRole).toInt()[0]
serviceItemChild = item.data(0, QtCore.Qt.UserRole).toInt()[0]
serviceItem = parentitem.data(0, QtCore.Qt.UserRole)
serviceItemChild = item.data(0, QtCore.Qt.UserRole)
# Adjust for zero based arrays.
serviceItem -= 1
# Only process the first item on the list for this method.
@ -1441,9 +1440,9 @@ class ServiceManager(QtGui.QWidget):
def _getParentItemData(self, item):
parentitem = item.parent()
if parentitem is None:
return item.data(0, QtCore.Qt.UserRole).toInt()[0]
return item.data(0, QtCore.Qt.UserRole)
else:
return parentitem.data(0, QtCore.Qt.UserRole).toInt()[0]
return parentitem.data(0, QtCore.Qt.UserRole)
def printServiceOrder(self):
"""

View File

@ -551,40 +551,34 @@ class ThemeForm(QtGui.QWizard, Ui_ThemeWizard):
log.debug(u'updateTheme')
# main page
self.theme.font_main_name = self.mainFontComboBox.currentFont().family()
self.theme.font_main_size = self.field(u'mainSizeSpinBox').toInt()[0]
self.theme.font_main_line_adjustment = \
self.field(u'lineSpacingSpinBox').toInt()[0]
self.theme.font_main_outline_size = \
self.field(u'outlineSizeSpinBox').toInt()[0]
self.theme.font_main_shadow_size = \
self.field(u'shadowSizeSpinBox').toInt()[0]
self.theme.font_main_size = self.field(u'mainSizeSpinBox')
self.theme.font_main_line_adjustment = self.field(u'lineSpacingSpinBox')
self.theme.font_main_outline_size = self.field(u'outlineSizeSpinBox')
self.theme.font_main_shadow_size = self.field(u'shadowSizeSpinBox')
self.theme.font_main_bold = self.field(u'mainBoldCheckBox').toBool()
# FIXME ?
self.theme.font_main_italics = \
self.field(u'mainItalicsCheckBox').toBool()
# footer page
self.theme.font_footer_name = \
self.footerFontComboBox.currentFont().family()
self.theme.font_footer_size = \
self.field(u'footerSizeSpinBox').toInt()[0]
self.theme.font_footer_size = self.field(u'footerSizeSpinBox')
# position page
self.theme.font_main_x = self.field(u'mainPositionX').toInt()[0]
self.theme.font_main_y = self.field(u'mainPositionY').toInt()[0]
self.theme.font_main_height = \
self.field(u'mainPositionHeight').toInt()[0]
self.theme.font_main_width = self.field(u'mainPositionWidth').toInt()[0]
self.theme.font_footer_x = self.field(u'footerPositionX').toInt()[0]
self.theme.font_footer_y = self.field(u'footerPositionY').toInt()[0]
self.theme.font_footer_height = \
self.field(u'footerPositionHeight').toInt()[0]
self.theme.font_footer_width = \
self.field(u'footerPositionWidth').toInt()[0]
self.theme.font_main_x = self.field(u'mainPositionX')
self.theme.font_main_y = self.field(u'mainPositionY')
self.theme.font_main_height = self.field(u'mainPositionHeight')
self.theme.font_main_width = self.field(u'mainPositionWidth')
#print self.field(u'footerPositionX')
self.theme.font_footer_x = self.field(u'footerPositionX')
self.theme.font_footer_y = self.field(u'footerPositionY')
self.theme.font_footer_height = self.field(u'footerPositionHeight')
self.theme.font_footer_width = self.field(u'footerPositionWidth')
# position page
self.theme.display_horizontal_align = \
self.horizontalComboBox.currentIndex()
self.theme.display_vertical_align = \
self.verticalComboBox.currentIndex()
self.theme.display_slide_transition = \
self.field(u'slideTransition').toBool()
self.theme.display_vertical_align = self.verticalComboBox.currentIndex()
# TODO Check
self.theme.display_slide_transition = self.field(u'slideTransition').toBool()
def accept(self):
"""

View File

@ -93,7 +93,7 @@ class AlertForm(QtGui.QDialog, Ui_AlertDialog):
"""
item = self.alertListWidget.currentItem()
if item:
item_id = (item.data(QtCore.Qt.UserRole)).toInt()[0]
item_id = item.data(QtCore.Qt.UserRole)
self.manager.delete_object(AlertItem, item_id)
row = self.alertListWidget.row(item)
self.alertListWidget.takeItem(row)
@ -147,7 +147,7 @@ class AlertForm(QtGui.QDialog, Ui_AlertDialog):
bitem = self.alertListWidget.item(item.row())
self.triggerAlert(bitem.text())
self.alertTextEdit.setText(bitem.text())
self.item_id = (bitem.data(QtCore.Qt.UserRole)).toInt()[0]
self.item_id = bitem.data(QtCore.Qt.UserRole)
self.saveButton.setEnabled(False)
def onSingleClick(self):
@ -158,7 +158,7 @@ class AlertForm(QtGui.QDialog, Ui_AlertDialog):
item = self.alertListWidget.selectedIndexes()[0]
bitem = self.alertListWidget.item(item.row())
self.alertTextEdit.setText(bitem.text())
self.item_id = (bitem.data(QtCore.Qt.UserRole)).toInt()[0]
self.item_id = bitem.data(QtCore.Qt.UserRole)
# If the alert does not contain '<>' we clear the ParameterEdit field.
if self.alertTextEdit.text().find(u'<>') == -1:
self.parameterEdit.setText(u'')

View File

@ -432,13 +432,13 @@ class BibleImportForm(OpenLPWizard):
if self.currentPage() == self.welcomePage:
return True
elif self.currentPage() == self.selectPage:
if self.field(u'source_format').toInt()[0] == BibleFormat.OSIS:
if self.field(u'source_format') == BibleFormat.OSIS:
if not self.field(u'osis_location').toString():
critical_error_message_box(UiStrings().NFSs,
WizardStrings.YouSpecifyFile % WizardStrings.OSIS)
self.osisFileEdit.setFocus()
return False
elif self.field(u'source_format').toInt()[0] == BibleFormat.CSV:
elif self.field(u'source_format') == BibleFormat.CSV:
if not self.field(u'csv_booksfile').toString():
critical_error_message_box(UiStrings().NFSs,
translate('BiblesPlugin.ImportWizardForm',
@ -453,19 +453,19 @@ class BibleImportForm(OpenLPWizard):
'verses to import.'))
self.csvVersesEdit.setFocus()
return False
elif self.field(u'source_format').toInt()[0] == \
elif self.field(u'source_format') == \
BibleFormat.OpenSong:
if not self.field(u'opensong_file').toString():
critical_error_message_box(UiStrings().NFSs,
WizardStrings.YouSpecifyFile % WizardStrings.OS)
self.openSongFileEdit.setFocus()
return False
elif self.field(u'source_format').toInt()[0] == \
elif self.field(u'source_format') == \
BibleFormat.WebDownload:
self.versionNameEdit.setText(
self.webTranslationComboBox.currentText())
return True
elif self.field(u'source_format').toInt()[0] == BibleFormat.OpenLP1:
elif self.field(u'source_format') == BibleFormat.OpenLP1:
if not self.field(u'openlp1_location').toString():
critical_error_message_box(UiStrings().NFSs,
WizardStrings.YouSpecifyFile % UiStrings().OLPV1)
@ -643,7 +643,7 @@ class BibleImportForm(OpenLPWizard):
Prepare the UI for the import.
"""
OpenLPWizard.preWizard(self)
bible_type = self.field(u'source_format').toInt()[0]
bible_type = self.field(u'source_format')
if bible_type == BibleFormat.WebDownload:
self.progressLabel.setText(translate(
'BiblesPlugin.ImportWizardForm',
@ -656,7 +656,7 @@ class BibleImportForm(OpenLPWizard):
"""
Perform the actual import.
"""
bible_type = self.field(u'source_format').toInt()[0]
bible_type = self.field(u'source_format')
license_version = self.field(u'license_version').toString()
license_copyright = self.field(u'license_copyright').toString()
license_permissions = self.field(u'license_permissions').toString()
@ -683,7 +683,7 @@ class BibleImportForm(OpenLPWizard):
elif bible_type == BibleFormat.WebDownload:
# Import a bible from the web.
self.progressBar.setMaximum(1)
download_location = self.field(u'web_location').toInt()[0]
download_location = self.field(u'web_location')
bible_version = self.webTranslationComboBox.currentText()
bible = self.web_bible_list[download_location][bible_version]
importer = self.manager.import_bible(

View File

@ -160,7 +160,7 @@ class CustomMediaItem(MediaManagerItem):
"""
if check_item_selected(self.listView, UiStrings().SelectEdit):
item = self.listView.currentItem()
item_id = (item.data(QtCore.Qt.UserRole)).toInt()[0]
item_id = item.data(QtCore.Qt.UserRole)
self.edit_custom_form.loadCustom(item_id, False)
self.edit_custom_form.exec_()
self.autoSelectId = -1
@ -184,7 +184,7 @@ class CustomMediaItem(MediaManagerItem):
return
row_list = [item.row() for item in self.listView.selectedIndexes()]
row_list.sort(reverse=True)
id_list = [(item.data(QtCore.Qt.UserRole)).toInt()[0]
id_list = [(item.data(QtCore.Qt.UserRole))
for item in self.listView.selectedIndexes()]
for id in id_list:
self.plugin.manager.delete_object(CustomSlide, id)

View File

@ -372,7 +372,7 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog):
else:
return
elif item > 0:
item_id = (self.authorsComboBox.itemData(item)).toInt()[0]
item_id = (self.authorsComboBox.itemData(item))
author = self.manager.get_object(Author, item_id)
if self.authorsListView.findItems(unicode(author.display_name),
QtCore.Qt.MatchExactly):
@ -427,7 +427,7 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog):
else:
return
elif item > 0:
item_id = (self.topicsComboBox.itemData(item)).toInt()[0]
item_id = (self.topicsComboBox.itemData(item))
topic = self.manager.get_object(Topic, item_id)
if self.topicsListView.findItems(unicode(topic.name),
QtCore.Qt.MatchExactly):
@ -858,12 +858,12 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog):
self.song.authors = []
for row in xrange(self.authorsListView.count()):
item = self.authorsListView.item(row)
authorId = (item.data(QtCore.Qt.UserRole)).toInt()[0]
authorId = (item.data(QtCore.Qt.UserRole))
self.song.authors.append(self.manager.get_object(Author, authorId))
self.song.topics = []
for row in xrange(self.topicsListView.count()):
item = self.topicsListView.item(row)
topicId = (item.data(QtCore.Qt.UserRole)).toInt()[0]
topicId = (item.data(QtCore.Qt.UserRole))
self.song.topics.append(self.manager.get_object(Topic, topicId))
# Save the song here because we need a valid id for the audio files.
clean_song(self.manager, self.song)

View File

@ -741,7 +741,7 @@ class SongImportForm(OpenLPWizard):
self.finishButton.setVisible(False)
self.cancelButton.setVisible(True)
last_import_type = Settings().value(
u'songs/last import type').toInt()[0]
u'songs/last import type')
if last_import_type < 0 or \
last_import_type >= self.formatComboBox.count():
last_import_type = 0

View File

@ -98,7 +98,7 @@ class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog):
def _getCurrentItemId(self, listWidget):
item = listWidget.currentItem()
if item:
item_id = (item.data(QtCore.Qt.UserRole)).toInt()[0]
item_id = (item.data(QtCore.Qt.UserRole))
return item_id
else:
return -1

View File

@ -381,7 +381,7 @@ class SongMediaItem(MediaManagerItem):
log.debug(u'onEditClick')
if check_item_selected(self.listView, UiStrings().SelectEdit):
self.editItem = self.listView.currentItem()
item_id = (self.editItem.data(QtCore.Qt.UserRole)).toInt()[0]
item_id = self.editItem.data(QtCore.Qt.UserRole)
self.editSongForm.loadSong(item_id, False)
self.editSongForm.exec_()
self.autoSelectId = -1
@ -406,7 +406,7 @@ class SongMediaItem(MediaManagerItem):
Receiver.send_message(u'cursor_busy')
self.plugin.formParent.displayProgressBar(len(items))
for item in items:
item_id = (item.data(QtCore.Qt.UserRole)).toInt()[0]
item_id = item.data(QtCore.Qt.UserRole)
media_files = self.plugin.manager.get_all_objects(MediaFile,
MediaFile.song_id == item_id)
for media_file in media_files:
@ -435,7 +435,7 @@ class SongMediaItem(MediaManagerItem):
log.debug(u'onCloneClick')
if check_item_selected(self.listView, UiStrings().SelectEdit):
self.editItem = self.listView.currentItem()
item_id = (self.editItem.data(QtCore.Qt.UserRole)).toInt()[0]
item_id = self.editItem.data(QtCore.Qt.UserRole)
old_song = self.plugin.manager.get_object(Song, item_id)
song_xml = self.openLyrics.song_to_xml(old_song)
new_song = self.openLyrics.xml_to_song(song_xml)