summaryrefslogtreecommitdiffstats
path: root/src/gui/itemviews
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui/itemviews')
-rw-r--r--src/gui/itemviews/qabstractitemview.cpp26
-rw-r--r--src/gui/itemviews/qabstractitemview_p.h1
-rw-r--r--src/gui/itemviews/qheaderview.cpp31
-rw-r--r--src/gui/itemviews/qheaderview_p.h3
-rw-r--r--src/gui/itemviews/qitemselectionmodel.cpp20
-rw-r--r--src/gui/itemviews/qlistview.cpp7
-rw-r--r--src/gui/itemviews/qsortfilterproxymodel.cpp9
7 files changed, 66 insertions, 31 deletions
diff --git a/src/gui/itemviews/qabstractitemview.cpp b/src/gui/itemviews/qabstractitemview.cpp
index 55b3a03..83e05b4 100644
--- a/src/gui/itemviews/qabstractitemview.cpp
+++ b/src/gui/itemviews/qabstractitemview.cpp
@@ -88,6 +88,7 @@ QAbstractItemViewPrivate::QAbstractItemViewPrivate()
autoScroll(true),
autoScrollMargin(16),
autoScrollCount(0),
+ shouldScrollToCurrentOnShow(false),
alternatingColors(false),
textElideMode(Qt::ElideRight),
verticalScrollMode(QAbstractItemView::ScrollPerItem),
@@ -1380,8 +1381,9 @@ bool QAbstractItemView::event(QEvent *event)
d->executePostedLayout(); //make sure we set the layout properly
break;
case QEvent::Show:
- {
- d->executePostedLayout(); //make sure we set the layout properly
+ d->executePostedLayout(); //make sure we set the layout properly
+ if (d->shouldScrollToCurrentOnShow) {
+ d->shouldScrollToCurrentOnShow = false;
const QModelIndex current = currentIndex();
if (current.isValid() && (d->state == QAbstractItemView::EditingState || d->autoScroll))
scrollTo(current);
@@ -3163,14 +3165,18 @@ void QAbstractItemView::currentChanged(const QModelIndex &current, const QModelI
d->updateDirtyRegion();
}
}
- if (isVisible() && current.isValid() && !d->autoScrollTimer.isActive()) {
- if (d->autoScroll)
- scrollTo(current);
- d->setDirtyRegion(visualRect(current));
- d->updateDirtyRegion();
- edit(current, CurrentChanged, 0);
- if (current.row() == (d->model->rowCount(d->root) - 1))
- d->_q_fetchMore();
+ if (current.isValid() && !d->autoScrollTimer.isActive()) {
+ if (isVisible()) {
+ if (d->autoScroll)
+ scrollTo(current);
+ d->setDirtyRegion(visualRect(current));
+ d->updateDirtyRegion();
+ edit(current, CurrentChanged, 0);
+ if (current.row() == (d->model->rowCount(d->root) - 1))
+ d->_q_fetchMore();
+ } else {
+ d->shouldScrollToCurrentOnShow = d->autoScroll;
+ }
}
}
diff --git a/src/gui/itemviews/qabstractitemview_p.h b/src/gui/itemviews/qabstractitemview_p.h
index 37fe4a2..16bd1ab 100644
--- a/src/gui/itemviews/qabstractitemview_p.h
+++ b/src/gui/itemviews/qabstractitemview_p.h
@@ -359,6 +359,7 @@ public:
QBasicTimer autoScrollTimer;
int autoScrollMargin;
int autoScrollCount;
+ bool shouldScrollToCurrentOnShow; //used to know if we should scroll to current on show event
bool alternatingColors;
diff --git a/src/gui/itemviews/qheaderview.cpp b/src/gui/itemviews/qheaderview.cpp
index 5bd82d4..dc63b25 100644
--- a/src/gui/itemviews/qheaderview.cpp
+++ b/src/gui/itemviews/qheaderview.cpp
@@ -1388,8 +1388,7 @@ int QHeaderView::defaultSectionSize() const
void QHeaderView::setDefaultSectionSize(int size)
{
Q_D(QHeaderView);
- d->defaultSectionSize = size;
- d->forceInitializing = true;
+ d->setDefaultSectionSize(size);
}
/*!
@@ -1894,9 +1893,6 @@ void QHeaderView::initializeSections()
//make sure we update the hidden sections
if (newCount < oldCount)
d->updateHiddenSections(0, newCount-1);
- } else if (d->forceInitializing) {
- initializeSections(0, newCount - 1);
- d->forceInitializing = false;
}
}
@@ -1952,7 +1948,7 @@ void QHeaderView::initializeSections(int start, int end)
if (!d->sectionHidden.isEmpty())
d->sectionHidden.resize(d->sectionCount);
- if (d->sectionCount > oldCount || d->forceInitializing)
+ if (d->sectionCount > oldCount)
d->createSectionSpan(start, end, (end - start + 1) * d->defaultSectionSize, d->globalResizeMode);
//Q_ASSERT(d->headerLength() == d->length);
@@ -3364,6 +3360,29 @@ void QHeaderViewPrivate::cascadingResize(int visual, int newSize)
viewport->update();
}
+void QHeaderViewPrivate::setDefaultSectionSize(int size)
+{
+ Q_Q(QHeaderView);
+ defaultSectionSize = size;
+ int currentVisualIndex = 0;
+ for (int i = 0; i < sectionSpans.count(); ++i) {
+ QHeaderViewPrivate::SectionSpan &span = sectionSpans[i];
+ if (span.size > 0) {
+ //we resize it if it is not hidden (ie size > 0)
+ const int newSize = span.count * size;
+ if (newSize != span.size) {
+ length += newSize - span.size; //the whole length is changed
+ const int oldSectionSize = span.sectionSize();
+ span.size = span.count * size;
+ for (int i = currentVisualIndex; i < currentVisualIndex + span.count; ++i) {
+ emit q->sectionResized(logicalIndex(i), oldSectionSize, size);
+ }
+ }
+ }
+ currentVisualIndex += span.count;
+ }
+}
+
void QHeaderViewPrivate::resizeSectionSpan(int visualIndex, int oldSize, int newSize)
{
Q_Q(QHeaderView);
diff --git a/src/gui/itemviews/qheaderview_p.h b/src/gui/itemviews/qheaderview_p.h
index fbba69a..2889f08 100644
--- a/src/gui/itemviews/qheaderview_p.h
+++ b/src/gui/itemviews/qheaderview_p.h
@@ -90,7 +90,6 @@ public:
highlightSelected(false),
stretchLastSection(false),
cascadingResizing(false),
- forceInitializing(false),
stretchSections(0),
contentsSections(0),
minimumSectionSize(-1),
@@ -275,7 +274,6 @@ public:
bool highlightSelected;
bool stretchLastSection;
bool cascadingResizing;
- bool forceInitializing;
int stretchSections;
int contentsSections;
int defaultSectionSize;
@@ -310,6 +308,7 @@ public:
void createSectionSpan(int start, int end, int size, QHeaderView::ResizeMode mode);
void removeSectionsFromSpans(int start, int end);
void resizeSectionSpan(int visualIndex, int oldSize, int newSize);
+ void setDefaultSectionSize(int size);
inline int headerSectionCount() const { // for debugging
int count = 0;
diff --git a/src/gui/itemviews/qitemselectionmodel.cpp b/src/gui/itemviews/qitemselectionmodel.cpp
index 1a3ae2d..8baefdf 100644
--- a/src/gui/itemviews/qitemselectionmodel.cpp
+++ b/src/gui/itemviews/qitemselectionmodel.cpp
@@ -1313,11 +1313,11 @@ bool QItemSelectionModel::rowIntersectsSelection(int row, const QModelIndex &par
int left = sel.at(i).left();
int right = sel.at(i).right();
if (top <= row && bottom >= row) {
- Qt::ItemFlags leftFlags = d->model->index(row, left, parent).flags();
- Qt::ItemFlags rightFlags = d->model->index(row, right, parent).flags();
- if ((leftFlags & Qt::ItemIsSelectable) && (leftFlags & Qt::ItemIsEnabled)
- && (rightFlags & Qt::ItemIsSelectable) && (rightFlags & Qt::ItemIsEnabled))
- return true;
+ for (int j = left; j <= right; j++) {
+ const Qt::ItemFlags flags = d->model->index(row, j, parent).flags();
+ if ((flags & Qt::ItemIsSelectable) && (flags & Qt::ItemIsEnabled))
+ return true;
+ }
}
}
@@ -1342,11 +1342,11 @@ bool QItemSelectionModel::columnIntersectsSelection(int column, const QModelInde
int top = sel.at(i).top();
int bottom = sel.at(i).bottom();
if (left <= column && right >= column) {
- Qt::ItemFlags topFlags = d->model->index(top, column, parent).flags();
- Qt::ItemFlags bottomFlags = d->model->index(bottom, column, parent).flags();
- if ((topFlags & Qt::ItemIsSelectable) && (topFlags & Qt::ItemIsEnabled)
- && (bottomFlags & Qt::ItemIsSelectable) && (bottomFlags & Qt::ItemIsEnabled))
- return true;
+ for (int j = top; j <= bottom; j++) {
+ const Qt::ItemFlags flags = d->model->index(j, column, parent).flags();
+ if ((flags & Qt::ItemIsSelectable) && (flags & Qt::ItemIsEnabled))
+ return true;
+ }
}
}
diff --git a/src/gui/itemviews/qlistview.cpp b/src/gui/itemviews/qlistview.cpp
index 07f0a38..48f53a0 100644
--- a/src/gui/itemviews/qlistview.cpp
+++ b/src/gui/itemviews/qlistview.cpp
@@ -1997,14 +1997,15 @@ bool QListViewPrivate::doItemsLayout(int delta)
int first = batchStartRow();
int last = qMin(first + delta - 1, max);
- if (max < 0 || last < first)
- return true; // nothing to do
-
if (first == 0) {
layoutChildren(); // make sure the viewport has the right size
prepareItemsLayout();
}
+ if (max < 0 || last < first) {
+ return true; // nothing to do
+ }
+
QListViewLayoutInfo info;
info.bounds = layoutBounds;
info.grid = gridSize();
diff --git a/src/gui/itemviews/qsortfilterproxymodel.cpp b/src/gui/itemviews/qsortfilterproxymodel.cpp
index 91431c4..43feda8 100644
--- a/src/gui/itemviews/qsortfilterproxymodel.cpp
+++ b/src/gui/itemviews/qsortfilterproxymodel.cpp
@@ -144,6 +144,7 @@ public:
const QModelIndex &proxy_index) const
{
Q_ASSERT(proxy_index.isValid());
+ Q_ASSERT(proxy_index.model() == q_func());
const void *p = proxy_index.internalPointer();
Q_ASSERT(p);
QMap<QModelIndex, Mapping *>::const_iterator it =
@@ -311,6 +312,10 @@ QModelIndex QSortFilterProxyModelPrivate::proxy_to_source(const QModelIndex &pro
{
if (!proxy_index.isValid())
return QModelIndex(); // for now; we may want to be able to set a root index later
+ if (proxy_index.model() != q_func()) {
+ qWarning() << "QSortFilterProxyModel: index from wrong model passed to mapToSource";
+ return QModelIndex();
+ }
IndexMap::const_iterator it = index_to_iterator(proxy_index);
Mapping *m = it.value();
if ((proxy_index.row() >= m->source_rows.size()) || (proxy_index.column() >= m->source_columns.size()))
@@ -324,6 +329,10 @@ QModelIndex QSortFilterProxyModelPrivate::source_to_proxy(const QModelIndex &sou
{
if (!source_index.isValid())
return QModelIndex(); // for now; we may want to be able to set a root index later
+ if (source_index.model() != model) {
+ qWarning() << "QSortFilterProxyModel: index from wrong model passed to mapFromSource";
+ return QModelIndex();
+ }
QModelIndex source_parent = source_index.parent();
IndexMap::const_iterator it = create_mapping(source_parent);
Mapping *m = it.value();