← Back to team overview

openlp-core team mailing list archive

[Merge] lp:~trb143/openlp/bug-791598 into lp:openlp

 

Tim Bentley has proposed merging lp:~trb143/openlp/bug-791598 into lp:openlp.

Requested reviews:
  OpenLP Core (openlp-core)
Related bugs:
  Bug #791598 in OpenLP: "Copying a theme moves to the last media item in the service"
  https://bugs.launchpad.net/openlp/+bug/791598

For more details, see:
https://code.launchpad.net/~trb143/openlp/bug-791598/+merge/63470

Small Performance improvement
Persist the Selected item over a rebuild of the UI.
-- 
https://code.launchpad.net/~trb143/openlp/bug-791598/+merge/63470
Your team OpenLP Core is requested to review the proposed merge of lp:~trb143/openlp/bug-791598 into lp:openlp.
=== modified file 'openlp/core/ui/servicemanager.py'
--- openlp/core/ui/servicemanager.py	2011-05-27 10:17:59 +0000
+++ openlp/core/ui/servicemanager.py	2011-06-04 18:18:28 +0000
@@ -959,6 +959,7 @@
             treewidgetitem.setToolTip(0, serviceitem.notes)
             treewidgetitem.setData(0, QtCore.Qt.UserRole,
                 QtCore.QVariant(item[u'order']))
+            treewidgetitem.setSelected(item[u'selected'])
             # Add the children to their parent treewidgetitem.
             for count, frame in enumerate(serviceitem.get_frames()):
                 child = QtGui.QTreeWidgetItem(treewidgetitem)
@@ -1030,16 +1031,34 @@
         # force reset of renderer as theme data has changed
         self.mainwindow.renderer.themedata = None
         if self.serviceItems:
+            for item in self.serviceItems:
+                item[u'selected'] = False
+            serviceIterator = QtGui.QTreeWidgetItemIterator(
+                self.serviceManagerList)
+            while serviceIterator.value():
+                if serviceIterator.value().isSelected():
+                    selectedItem = serviceIterator.value()
+                serviceIterator += 1
+            if selectedItem is not None:
+                if selectedItem.parent() is None:
+                    pos = selectedItem.data(0, QtCore.Qt.UserRole).toInt()[0]
+                else:
+                    pos = selectedItem.parent().data(0, QtCore.Qt.UserRole). \
+                        toInt()[0]
+                self.serviceItems[pos - 1][u'selected'] = True
             tempServiceItems = self.serviceItems
             self.serviceManagerList.clear()
             self.serviceItems = []
             self.isNew = True
             for item in tempServiceItems:
                 self.addServiceItem(
-                    item[u'service_item'], False, expand=item[u'expanded'])
+                    item[u'service_item'], False, expand=item[u'expanded'],
+                    repaint=False, selected=item[u'selected'])
             # Set to False as items may have changed rendering
             # does not impact the saved song so True may also be valid
             self.setModified()
+            # Repaint it once only at the end
+            self.repaintServiceList(-1, -1)
         Receiver.send_message(u'cursor_normal')
 
     def serviceItemUpdate(self, message):
@@ -1069,7 +1088,7 @@
         self.setModified()
 
     def addServiceItem(self, item, rebuild=False, expand=None, replace=False,
-        repaint=True):
+        repaint=True, selected=False):
         """
         Add a Service item to the list
 
@@ -1097,17 +1116,17 @@
                     for inditem in item:
                         self.serviceItems.append({u'service_item': inditem,
                             u'order': len(self.serviceItems) + 1,
-                            u'expanded': expand})
+                            u'expanded': expand, u'selected': selected})
                 else:
                     self.serviceItems.append({u'service_item': item,
                         u'order': len(self.serviceItems) + 1,
-                        u'expanded': expand})
+                        u'expanded': expand, u'selected': selected})
                 if repaint:
                     self.repaintServiceList(len(self.serviceItems) - 1, -1)
             else:
                 self.serviceItems.insert(self.dropPosition,
                     {u'service_item': item, u'order': self.dropPosition,
-                    u'expanded': expand})
+                    u'expanded': expand, u'selected': selected})
                 self.repaintServiceList(self.dropPosition, -1)
             # if rebuilding list make sure live is fixed.
             if rebuild:


Follow ups