'Select rows identified by identifiers. identifiers can be a set of ids,
row numbers or QModelIndexes.'

def select_rows(self, identifiers, using_ids=True, change_current=True, scroll=True):

    rows = set([(x.row() if hasattr(x, 'row') else x) for x in identifiers])
    if using_ids:
        rows = set([])
        identifiers = set(identifiers)
        m = self.model()
        for row in xrange(m.rowCount(QModelIndex())):
            if (m.id(row) in identifiers):
                rows.add(row)
    rows = list(sorted(rows))
    if rows:
        row = rows[0]
        if change_current:
            self.set_current_row(row, select=False)
        if scroll:
            self.scroll_to_row(row)
    sm = self.selectionModel()
    sel = QItemSelection()
    m = self.model()
    max_col = (m.columnCount(QModelIndex()) - 1)
    for (k, g) in itertools.groupby(enumerate(rows), (lambda (i, x): (i - x))):
        group = list(map(operator.itemgetter(1), g))
        sel.merge(QItemSelection(m.index(min(group), 0), m.index(max(group), max_col)), sm.Select)
    sm.select(sel, sm.ClearAndSelect)
