title: Insert and remove items from a QAbstractListModel
body: <p>I am trying to create a QAbstractListView for use with a QComboBox which maintains a sorted list of the items it contains. I've included some sample code below that illustrates my problem. When I update the items in the list, the currentIndex of the combo box does not update to reflect the changes to the model. I've tried using the rowsAboutToBeInserted and rowsInserted signals, but I can't see any effect (maybe I'm doing it wrong?).</p>
  
  <p>My actual use case is a little more complex, but the example should be enough. The items being sorted aren't just strings, and take a little more effort to sort and have a ItemDataRole different to their DisplayRole.</p>
  
  <p>The itemsAdded and itemsRemoved are my own functions, which will be connected to signals from another list which I'm trying to proxy.</p>
  
  <p>To trigger the problem, press the 'Insert "c"' button. The string is inserted into the list correctly, but the selection moves from 'e' to 'd' (i.e. the selection index does not change).</p>
  
  <p><img src="https://i.stack.imgur.com/Z59Mg.png" alt="example code"></p>
  
  <pre><code>#!/usr/bin/env python
  # -*- coding: utf-8 -*-
  
  from PyQt4 import QtCore, QtGui
  
  class Model(QtCore.QAbstractListModel):
      def __init__(self, *args, **kwargs):
          QtCore.QAbstractListModel.__init__(self, *args, **kwargs)
          self.items = []
  
      def rowCount(self, parent=QtCore.QModelIndex()):
          return len(self.items)
  
      def data(self, index, role=QtCore.Qt.DisplayRole):
          if index.isValid() is True:
              if role == QtCore.Qt.DisplayRole:
                  return QtCore.QVariant(self.items[index.row()])
              elif role == QtCore.Qt.ItemDataRole:
                  return QtCore.QVariant(self.items[index.row()])
          return QtCore.QVariant()
  
      def itemsAdded(self, items):
          # insert items into their sorted position
          items = sorted(items)
          row = 0
          while row &lt; len(self.items) and len(items) &gt; 0:
              if items[0] &lt; self.items[row]:
                  self.items[row:row] = [items.pop(0)]
                  row += 1
              row += 1
          # add remaining items to end of list
          if len(items) &gt; 0:
              self.items.extend(items)
  
      def itemsRemoved(self, items):
          # remove items from list
          for item in items:
              for row in range(0, len(self.items)):
                  if self.items[row] == item:
                      self.items.pop(row)
                      break
  
  def main():
      app = QtGui.QApplication([])
      w = QtGui.QWidget()
      w.resize(300,300)
      layout = QtGui.QVBoxLayout()
  
      model = Model()
      model.itemsAdded(['a','b','d','e'])
  
      combobox = QtGui.QComboBox()
      combobox.setModel(model)
      combobox.setCurrentIndex(3)
      layout.addWidget(combobox)
  
      def insertC(self):
          model.itemsAdded('c')
  
      button = QtGui.QPushButton('Insert "c"')
      button.clicked.connect(insertC)
      layout.addWidget(button)
  
      w.setLayout(layout)
      w.show()
      app.exec_()
  
  if __name__ == '__main__':
      main()
  </code></pre>