title: pyqt treeview index error removing last row
body: <p>I have a 2 column treeView with a simple heirarchy depth of 2; root > parent > child.  I have a removeRows call in my treeView subclass that gets evaluated when the delete key is pressed.  This seems to work fine when I delete any row but the last one.</p>
  
  <p>I receive an <code>IndexError: list index out of range</code>, that seems to be coming from the node class <code>child</code> method.  This seems to occur when the <code>self.beginRemoveRows</code> method is called in the model's <code>removeRows</code>.  Strangely, the order of operations appears to be reversed, or threading is somehow causing a refresh to occur before the model knows about it's recent update.</p>
  
  <p>With these code snippets I was hoping someone could provide a possible explanation or some ideas of what to try next to debug this.</p>
  
  <p>from the <strong>QTreeView</strong> subclass,</p>
  
  <pre><code>def keyPressEvent(self, event):
      if event.key() == Qt.Key_Delete:
          index = self.currentIndex()
          self.model().removeRow(index.row())
      else:
          # call base class keyPressEvent
          QTreeView.keyPressEvent(self, event)  
  </code></pre>
  
  <p>from the <strong>QAbstractItemModel</strong> subclass,</p>
  
  <pre><code>def index(self, row, column, parent=QModelIndex()):
      parent_node = self.getNode(parent)
      child_item = parent_node.child(row)
      if child_item:
          return self.createIndex(row, column, child_item)
      else:
          return QModelIndex()
  
  def getNode(self, index):
      if index.isValid():
          node = index.internalPointer()
          if node:
              return node
      return self._root
  
  def removeRows(self, position, rows, parent=QModelIndex()):
  
      parent_node = self.getNode(parent)
      self.beginRemoveRows(parent, position, position + rows - 1)
      parent_node.removeChild(position)
      self.endRemoveRows()
      return True
  </code></pre>
  
  <p>from the <strong>node class</strong>,</p>
  
  <pre><code>def child(self, row):
      return self._children[row]
  
  def removeChild(self, position):
  
      if position &lt; 0 or position &gt;= len(self._children):
          return False
  
      child = self._children.pop(position)
      child._parent = None
  
      return True
  </code></pre>