summaryrefslogtreecommitdiffstats
path: root/src/widgets/itemviews/qheaderview.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/widgets/itemviews/qheaderview.cpp')
-rw-r--r--src/widgets/itemviews/qheaderview.cpp128
1 files changed, 79 insertions, 49 deletions
diff --git a/src/widgets/itemviews/qheaderview.cpp b/src/widgets/itemviews/qheaderview.cpp
index 708b9b44ca..5cbf642802 100644
--- a/src/widgets/itemviews/qheaderview.cpp
+++ b/src/widgets/itemviews/qheaderview.cpp
@@ -353,35 +353,35 @@ void QHeaderView::setModel(QAbstractItemModel *model)
Q_D(QHeaderView);
d->layoutChangePersistentSections.clear();
if (d->model && d->model != QAbstractItemModelPrivate::staticEmptyModel()) {
- if (d->orientation == Qt::Horizontal) {
- QObject::disconnect(d->model, SIGNAL(columnsInserted(QModelIndex,int,int)),
- this, SLOT(sectionsInserted(QModelIndex,int,int)));
- QObject::disconnect(d->model, SIGNAL(columnsAboutToBeRemoved(QModelIndex,int,int)),
- this, SLOT(sectionsAboutToBeRemoved(QModelIndex,int,int)));
- QObject::disconnect(d->model, SIGNAL(columnsRemoved(QModelIndex,int,int)),
- this, SLOT(_q_sectionsRemoved(QModelIndex,int,int)));
- QObject::disconnect(d->model, SIGNAL(columnsAboutToBeMoved(QModelIndex,int,int,QModelIndex,int)),
- this, SLOT(_q_sectionsAboutToBeChanged()));
- QObject::disconnect(d->model, SIGNAL(columnsMoved(QModelIndex,int,int,QModelIndex,int)),
- this, SLOT(_q_sectionsChanged()));
- } else {
- QObject::disconnect(d->model, SIGNAL(rowsInserted(QModelIndex,int,int)),
- this, SLOT(sectionsInserted(QModelIndex,int,int)));
- QObject::disconnect(d->model, SIGNAL(rowsAboutToBeRemoved(QModelIndex,int,int)),
- this, SLOT(sectionsAboutToBeRemoved(QModelIndex,int,int)));
- QObject::disconnect(d->model, SIGNAL(rowsRemoved(QModelIndex,int,int)),
- this, SLOT(_q_sectionsRemoved(QModelIndex,int,int)));
- QObject::disconnect(d->model, SIGNAL(rowsAboutToBeMoved(QModelIndex,int,int,QModelIndex,int)),
- this, SLOT(_q_sectionsAboutToBeChanged()));
- QObject::disconnect(d->model, SIGNAL(rowsMoved(QModelIndex,int,int,QModelIndex,int)),
- this, SLOT(_q_sectionsChanged()));
- }
- QObject::disconnect(d->model, SIGNAL(headerDataChanged(Qt::Orientation,int,int)),
- this, SLOT(headerDataChanged(Qt::Orientation,int,int)));
- QObject::disconnect(d->model, SIGNAL(layoutAboutToBeChanged()),
- this, SLOT(_q_sectionsAboutToBeChanged()));
- QObject::disconnect(d->model, SIGNAL(layoutChanged()),
- this, SLOT(_q_sectionsChanged()));
+ if (d->orientation == Qt::Horizontal) {
+ QObject::disconnect(d->model, SIGNAL(columnsInserted(QModelIndex,int,int)),
+ this, SLOT(sectionsInserted(QModelIndex,int,int)));
+ QObject::disconnect(d->model, SIGNAL(columnsAboutToBeRemoved(QModelIndex,int,int)),
+ this, SLOT(sectionsAboutToBeRemoved(QModelIndex,int,int)));
+ QObject::disconnect(d->model, SIGNAL(columnsRemoved(QModelIndex,int,int)),
+ this, SLOT(_q_sectionsRemoved(QModelIndex,int,int)));
+ QObject::disconnect(d->model, SIGNAL(columnsAboutToBeMoved(QModelIndex,int,int,QModelIndex,int)),
+ this, SLOT(_q_sectionsAboutToBeMoved(QModelIndex,int,int,QModelIndex,int)));
+ QObject::disconnect(d->model, SIGNAL(columnsMoved(QModelIndex,int,int,QModelIndex,int)),
+ this, SLOT(_q_sectionsMoved(QModelIndex,int,int,QModelIndex,int)));
+ } else {
+ QObject::disconnect(d->model, SIGNAL(rowsInserted(QModelIndex,int,int)),
+ this, SLOT(sectionsInserted(QModelIndex,int,int)));
+ QObject::disconnect(d->model, SIGNAL(rowsAboutToBeRemoved(QModelIndex,int,int)),
+ this, SLOT(sectionsAboutToBeRemoved(QModelIndex,int,int)));
+ QObject::disconnect(d->model, SIGNAL(rowsRemoved(QModelIndex,int,int)),
+ this, SLOT(_q_sectionsRemoved(QModelIndex,int,int)));
+ QObject::disconnect(d->model, SIGNAL(rowsAboutToBeMoved(QModelIndex,int,int,QModelIndex,int)),
+ this, SLOT(_q_sectionsAboutToBeMoved(QModelIndex,int,int,QModelIndex,int)));
+ QObject::disconnect(d->model, SIGNAL(rowsMoved(QModelIndex,int,int,QModelIndex,int)),
+ this, SLOT(_q_sectionsMoved(QModelIndex,int,int,QModelIndex,int)));
+ }
+ QObject::disconnect(d->model, SIGNAL(headerDataChanged(Qt::Orientation,int,int)),
+ this, SLOT(headerDataChanged(Qt::Orientation,int,int)));
+ QObject::disconnect(d->model, SIGNAL(layoutAboutToBeChanged(QList<QPersistentModelIndex>,QAbstractItemModel::LayoutChangeHint)),
+ this, SLOT(_q_sectionsAboutToBeChanged(QList<QPersistentModelIndex>,QAbstractItemModel::LayoutChangeHint)));
+ QObject::disconnect(d->model, SIGNAL(layoutChanged(QList<QPersistentModelIndex>,QAbstractItemModel::LayoutChangeHint)),
+ this, SLOT(_q_sectionsChanged(QList<QPersistentModelIndex>,QAbstractItemModel::LayoutChangeHint)));
}
if (model && model != QAbstractItemModelPrivate::staticEmptyModel()) {
@@ -393,9 +393,9 @@ void QHeaderView::setModel(QAbstractItemModel *model)
QObject::connect(model, SIGNAL(columnsRemoved(QModelIndex,int,int)),
this, SLOT(_q_sectionsRemoved(QModelIndex,int,int)));
QObject::connect(model, SIGNAL(columnsAboutToBeMoved(QModelIndex,int,int,QModelIndex,int)),
- this, SLOT(_q_sectionsAboutToBeChanged()));
+ this, SLOT(_q_sectionsAboutToBeMoved(QModelIndex,int,int,QModelIndex,int)));
QObject::connect(model, SIGNAL(columnsMoved(QModelIndex,int,int,QModelIndex,int)),
- this, SLOT(_q_sectionsChanged()));
+ this, SLOT(_q_sectionsMoved(QModelIndex,int,int,QModelIndex,int)));
} else {
QObject::connect(model, SIGNAL(rowsInserted(QModelIndex,int,int)),
this, SLOT(sectionsInserted(QModelIndex,int,int)));
@@ -404,16 +404,16 @@ void QHeaderView::setModel(QAbstractItemModel *model)
QObject::connect(model, SIGNAL(rowsRemoved(QModelIndex,int,int)),
this, SLOT(_q_sectionsRemoved(QModelIndex,int,int)));
QObject::connect(model, SIGNAL(rowsAboutToBeMoved(QModelIndex,int,int,QModelIndex,int)),
- this, SLOT(_q_sectionsAboutToBeChanged()));
+ this, SLOT(_q_sectionsAboutToBeMoved(QModelIndex,int,int,QModelIndex,int)));
QObject::connect(model, SIGNAL(rowsMoved(QModelIndex,int,int,QModelIndex,int)),
- this, SLOT(_q_sectionsChanged()));
+ this, SLOT(_q_sectionsMoved(QModelIndex,int,int,QModelIndex,int)));
}
QObject::connect(model, SIGNAL(headerDataChanged(Qt::Orientation,int,int)),
this, SLOT(headerDataChanged(Qt::Orientation,int,int)));
- QObject::connect(model, SIGNAL(layoutAboutToBeChanged()),
- this, SLOT(_q_sectionsAboutToBeChanged()));
- QObject::connect(model, SIGNAL(layoutChanged()),
- this, SLOT(_q_sectionsChanged()));
+ QObject::connect(model, SIGNAL(layoutAboutToBeChanged(QList<QPersistentModelIndex>,QAbstractItemModel::LayoutChangeHint)),
+ this, SLOT(_q_sectionsAboutToBeChanged(QList<QPersistentModelIndex>,QAbstractItemModel::LayoutChangeHint)));
+ QObject::connect(model, SIGNAL(layoutChanged(QList<QPersistentModelIndex>,QAbstractItemModel::LayoutChangeHint)),
+ this, SLOT(_q_sectionsChanged(QList<QPersistentModelIndex>,QAbstractItemModel::LayoutChangeHint)));
}
d->state = QHeaderViewPrivate::NoClear;
@@ -2150,8 +2150,33 @@ void QHeaderViewPrivate::_q_sectionsRemoved(const QModelIndex &parent,
viewport->update();
}
-void QHeaderViewPrivate::_q_sectionsAboutToBeChanged()
+void QHeaderViewPrivate::_q_sectionsAboutToBeMoved(const QModelIndex &sourceParent, int logicalStart, int logicalEnd, const QModelIndex &destinationParent, int logicalDestination)
+{
+ if (sourceParent != root || destinationParent != root)
+ return; // we only handle changes in the root level
+ Q_UNUSED(logicalStart);
+ Q_UNUSED(logicalEnd);
+ Q_UNUSED(logicalDestination);
+ _q_sectionsAboutToBeChanged();
+}
+
+void QHeaderViewPrivate::_q_sectionsMoved(const QModelIndex &sourceParent, int logicalStart, int logicalEnd, const QModelIndex &destinationParent, int logicalDestination)
+{
+ if (sourceParent != root || destinationParent != root)
+ return; // we only handle changes in the root level
+ Q_UNUSED(logicalStart);
+ Q_UNUSED(logicalEnd);
+ Q_UNUSED(logicalDestination);
+ _q_sectionsChanged();
+}
+
+void QHeaderViewPrivate::_q_sectionsAboutToBeChanged(const QList<QPersistentModelIndex> &,
+ QAbstractItemModel::LayoutChangeHint hint)
{
+ if ((hint == QAbstractItemModel::VerticalSortHint && orientation == Qt::Horizontal) ||
+ (hint == QAbstractItemModel::HorizontalSortHint && orientation == Qt::Vertical))
+ return;
+
//if there is no row/column we can't have mapping for columns
//because no QModelIndex in the model would be valid
// ### this is far from being bullet-proof and we would need a real system to
@@ -2190,8 +2215,13 @@ void QHeaderViewPrivate::_q_sectionsAboutToBeChanged()
}
}
-void QHeaderViewPrivate::_q_sectionsChanged()
+void QHeaderViewPrivate::_q_sectionsChanged(const QList<QPersistentModelIndex> &,
+ QAbstractItemModel::LayoutChangeHint hint)
{
+ if ((hint == QAbstractItemModel::VerticalSortHint && orientation == Qt::Horizontal) ||
+ (hint == QAbstractItemModel::HorizontalSortHint && orientation == Qt::Vertical))
+ return;
+
Q_Q(QHeaderView);
viewport->update();
@@ -2282,8 +2312,8 @@ void QHeaderView::initializeSections()
const int oldCount = d->sectionCount();
const int newCount = d->modelSectionCount();
if (newCount <= 0) {
- d->clear();
- emit sectionCountChanged(oldCount, 0);
+ d->clear();
+ emit sectionCountChanged(oldCount, 0);
} else if (newCount != oldCount) {
const int min = qBound(0, oldCount, newCount - 1);
initializeSections(min, newCount - 1);
@@ -3655,14 +3685,14 @@ void QHeaderViewPrivate::removeSectionsFromSectionItems(int start, int end)
void QHeaderViewPrivate::clear()
{
if (state != NoClear) {
- length = 0;
- visualIndices.clear();
- logicalIndices.clear();
- sectionSelected.clear();
- hiddenSectionSize.clear();
- sectionItems.clear();
- lastSectionLogicalIdx = -1;
- invalidateCachedSizeHint();
+ length = 0;
+ visualIndices.clear();
+ logicalIndices.clear();
+ sectionSelected.clear();
+ hiddenSectionSize.clear();
+ sectionItems.clear();
+ lastSectionLogicalIdx = -1;
+ invalidateCachedSizeHint();
}
}