Implement viewOptions() logic in QListViewPrivate.

The private method is called in several places in QListViewPrivate,
but before this patch, the implementation in QAbstractItemView was
 called. This meant that the options were not set properly,
resulting, for example, in icons in icon mode being laid out in
list mode (on the left and small).

This is a regression resulting from
8eab9cbce2 and
3578e05b29. Other views are not
affected in a similar way.

Change-Id: I753cb99410e367266753eaf2fa43361b9212ab96
Reviewed-by: Pier Luigi Fiorini <pierluigi.fiorini@gmail.com>
Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
Reviewed-by: Stephen Kelly <stephen.kelly@kdab.com>
This commit is contained in:
Stephen Kelly 2012-09-19 14:59:25 +02:00 committed by The Qt Project
parent 3e9f279290
commit 05aa8c6c12
3 changed files with 31 additions and 6 deletions

View File

@ -900,14 +900,20 @@ void QListView::startDrag(Qt::DropActions supportedActions)
QStyleOptionViewItem QListView::viewOptions() const
{
Q_D(const QListView);
QStyleOptionViewItem option = QAbstractItemView::viewOptions();
if (!d->iconSize.isValid()) { // otherwise it was already set in abstractitemview
int pm = (d->viewMode == ListMode
? style()->pixelMetric(QStyle::PM_ListViewIconSize, 0, this)
: style()->pixelMetric(QStyle::PM_IconViewIconSize, 0, this));
return d->viewOptions();
}
QStyleOptionViewItem QListViewPrivate::viewOptions() const
{
Q_Q(const QListView);
QStyleOptionViewItem option = QAbstractItemViewPrivate::viewOptions();
if (!iconSize.isValid()) { // otherwise it was already set in abstractitemview
int pm = (viewMode == QListView::ListMode
? q->style()->pixelMetric(QStyle::PM_ListViewIconSize, 0, q)
: q->style()->pixelMetric(QStyle::PM_IconViewIconSize, 0, q));
option.decorationSize = QSize(pm, pm);
}
if (d->viewMode == IconMode) {
if (viewMode == QListView::IconMode) {
option.showDecorationSelected = false;
option.decorationPosition = QStyleOptionViewItem::Top;
option.displayAlignment = Qt::AlignCenter;

View File

@ -394,6 +394,8 @@ public:
}
}
QStyleOptionViewItem viewOptions() const;
void scrollElasticBandBy(int dx, int dy);
QItemViewPaintPairs draggablePaintPairs(const QModelIndexList &indexes, QRect *r) const;

View File

@ -141,6 +141,7 @@ private slots:
void spacing_data();
void spacing();
void testScrollToWithHidden();
void testViewOptions();
};
// Testing get/set functions
@ -910,6 +911,10 @@ class PublicListView : public QListView
void setPositionForIndex(const QPoint &pos, const QModelIndex &index) {
QListView::setPositionForIndex(pos, index);
}
QStyleOptionViewItem viewOptions() const {
return QListView::viewOptions();
}
};
class TestDelegate : public QItemDelegate
@ -2308,5 +2313,17 @@ void tst_QListView::testScrollToWithHidden()
QCOMPARE(expectedScrollBarValue, lv.verticalScrollBar()->value());
}
void tst_QListView::testViewOptions()
{
PublicListView view;
QStyleOptionViewItem options = view.viewOptions();
QCOMPARE(options.decorationPosition, QStyleOptionViewItem::Left);
view.setViewMode(QListView::IconMode);
options = view.viewOptions();
QCOMPARE(options.decorationPosition, QStyleOptionViewItem::Top);
}
QTEST_MAIN(tst_QListView)
#include "tst_qlistview.moc"