From c819a8926959ecadfe2e588e28918ed6fb90ce5d Mon Sep 17 00:00:00 2001 From: Giuseppe D'Angelo Date: Fri, 8 Nov 2013 13:53:26 +0100 Subject: [PATCH] Document the BC break of viewportSizeHint() in itemviews Since users were not supposed to use this feature at all, just live with the BC break, but document it. In order to prevent possible problems in the future, introduce dummy overrides in QAbstractItemView and QListView as well. Also, fix the visibility of the overrides (it's protected, not public). Task-number: QTBUG-34667 Change-Id: Ib4554ae5e1e7d3ce4ea8e8703e1fea9e2231edb0 Reviewed-by: Marc Mutz --- dist/changes-5.2.0 | 8 ++++++-- src/widgets/itemviews/qabstractitemview.cpp | 9 +++++++++ src/widgets/itemviews/qabstractitemview.h | 2 ++ src/widgets/itemviews/qlistview.cpp | 10 ++++++++++ src/widgets/itemviews/qlistview.h | 2 ++ src/widgets/itemviews/qtableview.h | 4 ++-- src/widgets/itemviews/qtreeview.h | 4 ++-- src/widgets/widgets/qscrollarea.h | 3 ++- 8 files changed, 35 insertions(+), 7 deletions(-) diff --git a/dist/changes-5.2.0 b/dist/changes-5.2.0 index ae0d785aab5..b0446fbbaf5 100644 --- a/dist/changes-5.2.0 +++ b/dist/changes-5.2.0 @@ -34,8 +34,12 @@ QtWidgets --------- - QAbstractScrollArea now has a SizeAdjustPolicy. If it is set to AdjustToContents - it will make use of the new protected viewportSizeHint() (binary compatible since it - was reserved in Qt5). This function returns a suggested size based on contents. + it will make use of the protected viewportSizeHint() virtual function. This + function returns a suggested size based on contents. Note that although the + viewportSizeHint() virtual function was reserved in 5.0, user code was not + supposed to be overriding it (as the function was private and undocumented). + Code that was overriding viewportSizeHint() needs to be recompiled against 5.2 + for this feature to work correctly. - QTreeView now has setTreePosition to allow the treestructure to show data from other columns than logicalindex zero. diff --git a/src/widgets/itemviews/qabstractitemview.cpp b/src/widgets/itemviews/qabstractitemview.cpp index fd704e479b2..7edad74f54c 100644 --- a/src/widgets/itemviews/qabstractitemview.cpp +++ b/src/widgets/itemviews/qabstractitemview.cpp @@ -1390,6 +1390,15 @@ bool QAbstractItemView::showDropIndicator() const return d->showDropIndicator; } +/*! + \since 5.2 + \reimp +*/ +QSize QAbstractItemView::viewportSizeHint() const +{ + return QAbstractScrollArea::viewportSizeHint(); +} + /*! \property QAbstractItemView::dragEnabled \brief whether the view supports dragging of its own items diff --git a/src/widgets/itemviews/qabstractitemview.h b/src/widgets/itemviews/qabstractitemview.h index 96428515aeb..4f9cd7b1c64 100644 --- a/src/widgets/itemviews/qabstractitemview.h +++ b/src/widgets/itemviews/qabstractitemview.h @@ -346,6 +346,8 @@ protected: DropIndicatorPosition dropIndicatorPosition() const; #endif + QSize viewportSizeHint() const Q_DECL_OVERRIDE; + private: Q_DECLARE_PRIVATE(QAbstractItemView) Q_DISABLE_COPY(QAbstractItemView) diff --git a/src/widgets/itemviews/qlistview.cpp b/src/widgets/itemviews/qlistview.cpp index 616a832b888..0cca52daa2a 100644 --- a/src/widgets/itemviews/qlistview.cpp +++ b/src/widgets/itemviews/qlistview.cpp @@ -3200,6 +3200,16 @@ int QListView::visualIndex(const QModelIndex &index) const return visualIndex; } + +/*! + \since 5.2 + \reimp +*/ +QSize QListView::viewportSizeHint() const +{ + return QAbstractItemView::viewportSizeHint(); +} + QT_END_NAMESPACE #endif // QT_NO_LISTVIEW diff --git a/src/widgets/itemviews/qlistview.h b/src/widgets/itemviews/qlistview.h index e4ae2d03fdd..a973dfb2219 100644 --- a/src/widgets/itemviews/qlistview.h +++ b/src/widgets/itemviews/qlistview.h @@ -180,6 +180,8 @@ protected: void selectionChanged(const QItemSelection &selected, const QItemSelection &deselected); void currentChanged(const QModelIndex ¤t, const QModelIndex &previous); + QSize viewportSizeHint() const Q_DECL_OVERRIDE; + private: int visualIndex(const QModelIndex &index) const; diff --git a/src/widgets/itemviews/qtableview.h b/src/widgets/itemviews/qtableview.h index db956480d6a..387d24c6084 100644 --- a/src/widgets/itemviews/qtableview.h +++ b/src/widgets/itemviews/qtableview.h @@ -118,8 +118,6 @@ public: void sortByColumn(int column, Qt::SortOrder order); - QSize viewportSizeHint() const; - public Q_SLOTS: void selectRow(int row); void selectColumn(int column); @@ -161,6 +159,8 @@ protected: void updateGeometries(); + QSize viewportSizeHint() const Q_DECL_OVERRIDE; + int sizeHintForRow(int row) const; int sizeHintForColumn(int column) const; diff --git a/src/widgets/itemviews/qtreeview.h b/src/widgets/itemviews/qtreeview.h index d9c6cd92691..429b9d3add3 100644 --- a/src/widgets/itemviews/qtreeview.h +++ b/src/widgets/itemviews/qtreeview.h @@ -147,8 +147,6 @@ public: void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector &roles = QVector()); void selectAll(); - QSize viewportSizeHint() const; - Q_SIGNALS: void expanded(const QModelIndex &index); void collapsed(const QModelIndex &index); @@ -208,6 +206,8 @@ protected: void updateGeometries(); + QSize viewportSizeHint() const Q_DECL_OVERRIDE; + int sizeHintForColumn(int column) const; int indexRowSizeHint(const QModelIndex &index) const; int rowHeight(const QModelIndex &index) const; diff --git a/src/widgets/widgets/qscrollarea.h b/src/widgets/widgets/qscrollarea.h index 70af5fbbd79..db1083f122b 100644 --- a/src/widgets/widgets/qscrollarea.h +++ b/src/widgets/widgets/qscrollarea.h @@ -69,7 +69,6 @@ public: void setWidgetResizable(bool resizable); QSize sizeHint() const; - QSize viewportSizeHint() const; bool focusNextPrevChild(bool next); @@ -86,6 +85,8 @@ protected: void resizeEvent(QResizeEvent *); void scrollContentsBy(int dx, int dy); + QSize viewportSizeHint() const Q_DECL_OVERRIDE; + private: Q_DECLARE_PRIVATE(QScrollArea) Q_DISABLE_COPY(QScrollArea)