diff --git a/src/corelib/itemmodels/qitemselectionmodel.cpp b/src/corelib/itemmodels/qitemselectionmodel.cpp
index 883aa5b..ed720d9 100644
--- a/src/corelib/itemmodels/qitemselectionmodel.cpp
+++ b/src/corelib/itemmodels/qitemselectionmodel.cpp
@@ -306,6 +306,7 @@ template<typename ModelIndexContainer>
 static void indexesFromRange(const QItemSelectionRange &range, ModelIndexContainer &result)
 {
     if (range.isValid() && range.model()) {
+        qDebug() << __FUNCTION__ << "range=" << range;
         const QModelIndex topLeft = range.topLeft();
         const int bottom = range.bottom();
         const int right = range.right();
@@ -319,6 +320,7 @@ static void indexesFromRange(const QItemSelectionRange &range, ModelIndexContain
             }
         }
     }
+    qDebug() << __FUNCTION__ << "result=" << result.size();
 }
 
 /*!
@@ -473,9 +475,11 @@ QModelIndexList QItemSelection::indexes() const
 static QVector<QPersistentModelIndex> qSelectionPersistentindexes(const QItemSelection &sel)
 {
     QVector<QPersistentModelIndex> result;
+    qDebug() << __FUNCTION__ << "sel=" << sel.size();
     QList<QItemSelectionRange>::const_iterator it = sel.constBegin();
     for (; it != sel.constEnd(); ++it)
         indexesFromRange(*it, result);
+    qDebug() << __FUNCTION__ << "returns=" << result.size();
     return result;
 }
 
@@ -499,6 +503,8 @@ static QVector<QPair<QPersistentModelIndex, uint> > qSelectionPersistentRowLengt
 */
 void QItemSelection::merge(const QItemSelection &other, QItemSelectionModel::SelectionFlags command)
 {
+    if (0)
+        qDebug() << __FUNCTION__ << size() << "other=" << other.size() << "command=" << command;
     if (other.isEmpty() ||
           !(command & QItemSelectionModel::Select ||
           command & QItemSelectionModel::Deselect ||
@@ -556,6 +562,7 @@ void QItemSelection::merge(const QItemSelection &other, QItemSelectionModel::Sel
 void QItemSelection::split(const QItemSelectionRange &range,
                            const QItemSelectionRange &other, QItemSelection *result)
 {
+    qDebug() << __FUNCTION__;
     if (range.parent() != other.parent() || range.model() != other.model())
         return;
 
@@ -638,6 +645,7 @@ void QItemSelectionModelPrivate::initModel(QAbstractItemModel *model)
 QItemSelection QItemSelectionModelPrivate::expandSelection(const QItemSelection &selection,
                                                            QItemSelectionModel::SelectionFlags command) const
 {
+    qDebug() << __FUNCTION__;
     if (selection.isEmpty() && !((command & QItemSelectionModel::Rows) ||
                                  (command & QItemSelectionModel::Columns)))
         return selection;
@@ -673,6 +681,7 @@ void QItemSelectionModelPrivate::_q_rowsAboutToBeRemoved(const QModelIndex &pare
                                                          int start, int end)
 {
     Q_Q(QItemSelectionModel);
+    qDebug() << __FUNCTION__;
     finalize();
 
     // update current index
@@ -744,6 +753,7 @@ void QItemSelectionModelPrivate::_q_columnsAboutToBeRemoved(const QModelIndex &p
                                                             int start, int end)
 {
     Q_Q(QItemSelectionModel);
+    qDebug() << __FUNCTION__;
 
     // update current index
     if (currentIndex.isValid() && parent == currentIndex.parent()
@@ -776,6 +786,7 @@ void QItemSelectionModelPrivate::_q_columnsAboutToBeRemoved(const QModelIndex &p
 void QItemSelectionModelPrivate::_q_columnsAboutToBeInserted(const QModelIndex &parent,
                                                              int start, int end)
 {
+    qDebug() << __FUNCTION__;
     Q_UNUSED(end);
     finalize();
     QList<QItemSelectionRange> split;
@@ -805,6 +816,8 @@ void QItemSelectionModelPrivate::_q_columnsAboutToBeInserted(const QModelIndex &
 void QItemSelectionModelPrivate::_q_rowsAboutToBeInserted(const QModelIndex &parent,
                                                           int start, int end)
 {
+    if (0)
+        qDebug() << __FUNCTION__ << parent << start << end;
     Q_UNUSED(end);
     finalize();
     QList<QItemSelectionRange> split;
@@ -824,6 +837,11 @@ void QItemSelectionModelPrivate::_q_rowsAboutToBeInserted(const QModelIndex &par
         }
     }
     ranges += split;
+    if (0)
+    qDebug() << __FUNCTION__
+             << "SpliT" << split.size()
+             << "Ranges" << ranges.size()
+             << "currentSelection=" << currentSelection.size();
 }
 
 /*!
@@ -835,6 +853,7 @@ void QItemSelectionModelPrivate::_q_rowsAboutToBeInserted(const QModelIndex &par
 */
 void QItemSelectionModelPrivate::_q_layoutAboutToBeChanged(const QList<QPersistentModelIndex> &, QAbstractItemModel::LayoutChangeHint hint)
 {
+    qDebug() << __FUNCTION__ << "hint=" << hint;
     savedPersistentIndexes.clear();
     savedPersistentCurrentIndexes.clear();
     savedPersistentRowLengths.clear();
@@ -867,9 +886,14 @@ void QItemSelectionModelPrivate::_q_layoutAboutToBeChanged(const QList<QPersiste
         // An algorithm which contains the same assumption is used to process layoutChanged.
         savedPersistentRowLengths = qSelectionPersistentRowLengths(ranges);
         savedPersistentCurrentRowLengths = qSelectionPersistentRowLengths(currentSelection);
+        qDebug() << __FUNCTION__ << "VerticalSortHint";
+
     } else {
         savedPersistentIndexes = qSelectionPersistentindexes(ranges);
         savedPersistentCurrentIndexes = qSelectionPersistentindexes(currentSelection);
+        qDebug() << __FUNCTION__ << "No VerticalSortHint"
+                 << "savedPersistentIndexes="<<savedPersistentIndexes.size()
+                 << "savedPersistentCurrentIndexes="<<savedPersistentCurrentIndexes.size();
     }
 }
 /*!
@@ -877,6 +901,7 @@ void QItemSelectionModelPrivate::_q_layoutAboutToBeChanged(const QList<QPersiste
 */
 static QItemSelection mergeRowLengths(const QVector<QPair<QPersistentModelIndex, uint> > &rowLengths)
 {
+    qDebug() << __FUNCTION__;
     if (rowLengths.isEmpty())
       return QItemSelection();
 
@@ -916,6 +941,11 @@ static QItemSelection mergeRowLengths(const QVector<QPair<QPersistentModelIndex,
 */
 static QItemSelection mergeIndexes(const QVector<QPersistentModelIndex> &indexes)
 {
+    qDebug() << __FUNCTION__ << '>' << "indexes=" << indexes.size() ;
+    for (int i = 0; i < indexes.size(); ++i)
+        qDebug() << "IDX r=" << indexes.at(i).row() << "c="
+                 << indexes.at(i).column() << "p=" << indexes.at(i).parent();
+
     QItemSelection colSpans;
     // merge columns
     int i = 0;
@@ -973,6 +1003,8 @@ static QItemSelection mergeIndexes(const QVector<QPersistentModelIndex> &indexes
         }
         rowSpans.append(QItemSelectionRange(tl, br));
     }
+    qDebug() << __FUNCTION__ << "returns rowSPans=" << rowSpans.size()
+             << "colSpans=" << colSpans.size();
     return rowSpans;
 }
 
@@ -983,6 +1015,7 @@ static QItemSelection mergeIndexes(const QVector<QPersistentModelIndex> &indexes
 */
 void QItemSelectionModelPrivate::_q_layoutChanged(const QList<QPersistentModelIndex> &, QAbstractItemModel::LayoutChangeHint hint)
 {
+    qDebug() << __FUNCTION__ << hint;
     // special case for when all indexes are selected
     if (tableSelected && tableColCount == model->columnCount(tableParent)
         && tableRowCount == model->rowCount(tableParent)) {
@@ -1013,9 +1046,10 @@ void QItemSelectionModelPrivate::_q_layoutChanged(const QList<QPersistentModelIn
         // sort the "new" selection, as preparation for merging
         std::stable_sort(savedPersistentIndexes.begin(), savedPersistentIndexes.end());
         std::stable_sort(savedPersistentCurrentIndexes.begin(), savedPersistentCurrentIndexes.end());
-
         // update the selection by merging the individual indexes
+        qDebug()<< __FUNCTION__ << "mergeIndexes(savedPersistentIndexes)";
         ranges = mergeIndexes(savedPersistentIndexes);
+        qDebug()<< __FUNCTION__ << "mergeIndexes(savedPersistentCurrentIndexes)";
         currentSelection = mergeIndexes(savedPersistentCurrentIndexes);
 
         // release the persistent indexes
@@ -1434,8 +1468,11 @@ bool QItemSelectionModel::isRowSelected(int row, const QModelIndex &parent) cons
     on all items in the same column and that unselectable items are
     ignored.
 */
+
+
 bool QItemSelectionModel::isColumnSelected(int column, const QModelIndex &parent) const
 {
+    qDebug() << __FUNCTION__ << '>' << "col=" << column << parent;
     Q_D(const QItemSelectionModel);
     if (parent.isValid() && d->model != parent.model())
         return false;
@@ -1467,22 +1504,35 @@ bool QItemSelectionModel::isColumnSelected(int column, const QModelIndex &parent
     // add ranges and currentSelection and check through them all
     QList<QItemSelectionRange>::const_iterator it;
     QList<QItemSelectionRange> joined = d->ranges;
+    qDebug() << __FUNCTION__ <<"currentSelection=" << d->currentSelection.count()
+             << "ranges=" << d->ranges.size();
     if (d->currentSelection.count())
         joined += d->currentSelection;
+    if (joined.size() > 1000)
+        qDebug() << __FUNCTION__ <<"LOADS OF SELS";
+//    qDebug() << __FUNCTION__ <<"joined" << joined;
     int rowCount = d->model->rowCount(parent);
     for (int row = 0; row < rowCount; ++row) {
-         for (it = joined.constBegin(); it != joined.constEnd(); ++it) {
+         for (it = joined.constBegin(); it != joined.constEnd(); ++it) {             
              if ((*it).contains(row, column, parent)) {
                  Qt::ItemFlags flags = d->model->index(row, column, parent).flags();
                  if ((flags & Qt::ItemIsSelectable) && (flags & Qt::ItemIsEnabled)) {
                      row = qMax(row, (*it).bottom());
+                     qDebug() << __FUNCTION__ << "joined advanced to" << row;
                      break;
+                 } else {
+                     qDebug() << __FUNCTION__ << "row=" << row << "joined mismatch";
                  }
+             } else {
+                 qDebug() << __FUNCTION__ << "row=" << row << "joined contains mismatch";
              }
          }
-         if (it == joined.constEnd())
+         if (it == joined.constEnd()) {
+             qDebug() << __FUNCTION__ << '<' << "bail out false at " << row ;
              return false;
+         }
     }
+    qDebug() << __FUNCTION__ << '<' << "END" << (rowCount > 0);
     return rowCount > 0; // no rows means no selected items
 }
 
@@ -1676,6 +1726,7 @@ const QAbstractItemModel *QItemSelectionModel::model() const
 void QItemSelectionModel::emitSelectionChanged(const QItemSelection &newSelection,
                                                const QItemSelection &oldSelection)
 {
+    qDebug()<< __FUNCTION__ << newSelection.size() << oldSelection.size();
     // if both selections are empty or equal we return
     if ((oldSelection.isEmpty() && newSelection.isEmpty()) ||
         oldSelection == newSelection)
