QHeaderView - renaming functions in Qt5

This patch renames the functions in Qt5 according to the
notes. It also renames resizeMode to be consistent.

The old functions are both marked with both QT_DEPRECATED
and '### Qt 6 - remove'

All usage of the function within the qtbase are also
changed to use the new functions.

Change-Id: I9e05fa41d232e9ca43b945fcc949987017f3aedd
Reviewed-by: Stephen Kelly <stephen.kelly@kdab.com>
This commit is contained in:
Thorbjørn Lund Martsum 2012-03-03 06:05:54 +01:00 committed by Qt by Nokia
parent 7220d7f365
commit b64426248d
9 changed files with 164 additions and 79 deletions

16
dist/changes-5.0.0 vendored
View File

@ -352,6 +352,22 @@ QtWidgets
the proper Qt API: due to the version bump, QStyle will try to use the additional
QStyleOption members, which are left default-initialized.
* QHeaderView - The following functions have been obsoleted.
* void setMovable(bool movable) - use void setSectionsMovable(bool movable) instead.
* bool isMovable() const - use bool sectionsMovable() const instead.
* void setClickable(bool clickable) - use void setSectionsClickable(bool clickable) instead.
* bool isClickable() const - use bool sectionsClickable() instead.
* void setResizeMode(int logicalindex, ResizeMode mode) -
use setSectionResizeMode(logicalindex, mode) instead.
* ResizeMode resizeMode(int logicalindex) const -
use sectionResizeMode(int logicalindex) instead.
QtNetwork
---------
* QHostAddress::isLoopback() API added. Returns true if the address is

View File

@ -120,9 +120,9 @@ QDataStream &operator>>(QDataStream &in, QHeaderViewPrivate::SectionSpan &span)
\section1 Moving Header Sections
A header can be fixed in place, or made movable with setMovable(). It can
be made clickable with setClickable(), and has resizing behavior in
accordance with setResizeMode().
A header can be fixed in place, or made movable with setSectionsMovable(). It can
be made clickable with setSectionsClickable(), and has resizing behavior in
accordance with setResizeMode() and setSectionResizeMode()
\note Double-clicking on a header to resize a section only applies for
visible rows.
@ -185,7 +185,7 @@ QDataStream &operator>>(QDataStream &in, QHeaderViewPrivate::SectionSpan &span)
The following values are obsolete:
\value Custom Use Fixed instead.
\sa setResizeMode() stretchLastSection minimumSectionSize
\sa setResizeMode() setSectionResizeMode() stretchLastSection minimumSectionSize
*/
/*!
@ -216,7 +216,7 @@ QDataStream &operator>>(QDataStream &in, QHeaderViewPrivate::SectionSpan &span)
This signal is emitted when a section is pressed. The section's logical
index is specified by \a logicalIndex.
\sa setClickable()
\sa setSectionsClickable()
*/
/*!
@ -227,7 +227,7 @@ QDataStream &operator>>(QDataStream &in, QHeaderViewPrivate::SectionSpan &span)
Note that the sectionPressed signal will also be emitted.
\sa setClickable(), sectionPressed()
\sa setSectionsClickable(), sectionPressed()
*/
/*!
@ -238,7 +238,7 @@ QDataStream &operator>>(QDataStream &in, QHeaderViewPrivate::SectionSpan &span)
mouse button is pressed. The section's logical index is specified by
\a logicalIndex.
\sa setClickable(), sectionPressed()
\sa setSectionsClickable(), sectionPressed()
*/
/*!
@ -247,7 +247,7 @@ QDataStream &operator>>(QDataStream &in, QHeaderViewPrivate::SectionSpan &span)
This signal is emitted when a section is double-clicked. The section's
logical index is specified by \a logicalIndex.
\sa setClickable()
\sa setSectionsClickable()
*/
/*!
@ -266,7 +266,7 @@ QDataStream &operator>>(QDataStream &in, QHeaderViewPrivate::SectionSpan &span)
This signal is emitted when a section is double-clicked. The section's
logical index is specified by \a logicalIndex.
\sa setClickable()
\sa setSectionsClickable()
*/
/*!
@ -1085,62 +1085,98 @@ int QHeaderView::logicalIndex(int visualIndex) const
}
/*!
If \a movable is true, the header may be moved by the user; otherwise it
If \a sectionsMovable is true, the header may be moved by the user; otherwise it
is fixed in place.
\sa isMovable(), sectionMoved()
\sa sectionsMovable(), sectionMoved()
*/
// ### Qt 5: change to setSectionsMovable()
void QHeaderView::setMovable(bool movable)
void QHeaderView::setSectionsMovable(bool movable)
{
Q_D(QHeaderView);
d->movableSections = movable;
}
// ### Qt 6 - remove this obsolete function
/*!
\obsolete
\fn void QHeaderView::setMovable(bool movable)
Use setSectionsMovable instead.
\sa setSectionsMovable()
*/
/*!
Returns true if the header can be moved by the user; otherwise returns
false.
\sa setMovable()
\sa setSectionsMovable()
*/
// ### Qt 5: change to sectionsMovable()
bool QHeaderView::isMovable() const
bool QHeaderView::sectionsMovable() const
{
Q_D(const QHeaderView);
return d->movableSections;
}
// ### Qt 6 - remove this obsolete function
/*!
\obsolete
\fn bool QHeaderView::isMovable(bool movable)
Use sectionsMovable instead.
\sa sectionsMovable()
*/
/*!
If \a clickable is true, the header will respond to single clicks.
\sa isClickable(), sectionClicked(), sectionPressed(),
\sa sectionsClickable(), sectionClicked(), sectionPressed(),
setSortIndicatorShown()
*/
// ### Qt 5: change to setSectionsClickable()
void QHeaderView::setClickable(bool clickable)
void QHeaderView::setSectionsClickable(bool clickable)
{
Q_D(QHeaderView);
d->clickableSections = clickable;
}
// ### Qt 6 - remove this obsolete function
/*!
\obsolete
\fn void QHeaderView::setClickable(bool clickable)
Use setSectionsClickable instead.
\sa setSectionsClickable()
*/
/*!
Returns true if the header is clickable; otherwise returns false. A
clickable header could be set up to allow the user to change the
representation of the data in the view related to the header.
\sa setClickable()
\sa setSectionsClickable()
*/
// ### Qt 5: change to sectionsClickable()
bool QHeaderView::isClickable() const
bool QHeaderView::sectionsClickable() const
{
Q_D(const QHeaderView);
return d->clickableSections;
}
// ### Qt 6 - remove this obsolete function
/*!
\obsolete
\fn bool QHeaderView::isClickable() const
Use sectionsClickable instead.
\sa sectionsClickable()
*/
void QHeaderView::setHighlightSections(bool highlight)
{
Q_D(QHeaderView);
@ -1172,8 +1208,6 @@ void QHeaderView::setResizeMode(ResizeMode mode)
}
/*!
\overload
Sets the constraints on how the section specified by \a logicalIndex in
the header can be resized to those described by the given \a mode. The logical
index should exist at the time this function is called.
@ -1185,8 +1219,7 @@ void QHeaderView::setResizeMode(ResizeMode mode)
\sa setStretchLastSection()
*/
// ### Qt 5: change to setSectionResizeMode()
void QHeaderView::setResizeMode(int logicalIndex, ResizeMode mode)
void QHeaderView::setSectionResizeMode(int logicalIndex, ResizeMode mode)
{
Q_D(QHeaderView);
int visual = visualIndex(logicalIndex);
@ -1208,6 +1241,17 @@ void QHeaderView::setResizeMode(int logicalIndex, ResizeMode mode)
d->doDelayedResizeSections(); // section sizes may change as a result of the new mode
}
// ### Qt 6 - remove this obsolete function
/*!
\overload
\obsolete
\fn void QHeaderView::setResizeMode(int logicalIndex, ResizeMode mode)
Use setSectionResizeMode instead.
\sa setSectionResizeMode()
*/
/*!
Returns the resize mode that applies to the section specified by the given
\a logicalIndex.
@ -1215,7 +1259,7 @@ void QHeaderView::setResizeMode(int logicalIndex, ResizeMode mode)
\sa setResizeMode()
*/
QHeaderView::ResizeMode QHeaderView::resizeMode(int logicalIndex) const
QHeaderView::ResizeMode QHeaderView::sectionResizeMode(int logicalIndex) const
{
Q_D(const QHeaderView);
int visual = visualIndex(logicalIndex);
@ -1224,6 +1268,16 @@ QHeaderView::ResizeMode QHeaderView::resizeMode(int logicalIndex) const
return d->headerSectionResizeMode(visual);
}
// ### Qt 6 - remove this obsolete function
/*!
\obsolete
\fn QHeaderView::ResizeMode QHeaderView::resizeMode(int logicalIndex) const
Use sectionResizeMode instead.
\sa sectionResizeMode()
*/
/*!
\since 4.1
@ -1246,7 +1300,7 @@ int QHeaderView::stretchSectionCount() const
By default, this property is false.
\sa setClickable()
\sa setSectionsClickable()
*/
void QHeaderView::setSortIndicatorShown(bool show)
@ -1299,8 +1353,8 @@ void QHeaderView::setSortIndicator(int logicalIndex, Qt::SortOrder order)
}
if (old != logicalIndex
&& ((logicalIndex >= 0 && resizeMode(logicalIndex) == ResizeToContents)
|| old >= d->sectionCount() || (old >= 0 && resizeMode(old) == ResizeToContents))) {
&& ((logicalIndex >= 0 && sectionResizeMode(logicalIndex) == ResizeToContents)
|| old >= d->sectionCount() || (old >= 0 && sectionResizeMode(old) == ResizeToContents))) {
resizeSections();
d->viewport->update();
} else {
@ -2207,7 +2261,7 @@ void QHeaderView::mousePressEvent(QMouseEvent *e)
updateSection(d->pressed);
d->state = QHeaderViewPrivate::SelectSections;
}
} else if (resizeMode(handle) == Interactive) {
} else if (sectionResizeMode(handle) == Interactive) {
d->originalSize = sectionSize(handle);
d->state = QHeaderViewPrivate::ResizeSection;
d->section = handle;
@ -2289,7 +2343,7 @@ void QHeaderView::mouseMoveEvent(QMouseEvent *e)
#ifndef QT_NO_CURSOR
int handle = d->sectionHandleAt(pos);
bool hasCursor = testAttribute(Qt::WA_SetCursor);
if (handle != -1 && (resizeMode(handle) == Interactive)) {
if (handle != -1 && (sectionResizeMode(handle) == Interactive)) {
if (!hasCursor)
setCursor(d->orientation == Qt::Horizontal ? Qt::SplitHCursor : Qt::SplitVCursor);
} else if (hasCursor) {
@ -2360,7 +2414,7 @@ void QHeaderView::mouseDoubleClickEvent(QMouseEvent *e)
Q_D(QHeaderView);
int pos = d->orientation == Qt::Horizontal ? e->x() : e->y();
int handle = d->sectionHandleAt(pos);
if (handle > -1 && resizeMode(handle) == Interactive) {
if (handle > -1 && sectionResizeMode(handle) == Interactive) {
emit sectionHandleDoubleClicked(handle);
#ifndef QT_NO_CURSOR
Qt::CursorShape splitCursor = (d->orientation == Qt::Horizontal)
@ -2368,7 +2422,7 @@ void QHeaderView::mouseDoubleClickEvent(QMouseEvent *e)
if (cursor().shape() == splitCursor) {
// signal handlers may have changed the section size
handle = d->sectionHandleAt(pos);
if (!(handle > -1 && resizeMode(handle) == Interactive))
if (!(handle > -1 && sectionResizeMode(handle) == Interactive))
setCursor(Qt::ArrowCursor);
}
#endif
@ -2673,7 +2727,7 @@ void QHeaderView::dataChanged(const QModelIndex &topLeft, const QModelIndex &bot
int first = orientation() == Qt::Horizontal ? topLeft.column() : topLeft.row();
int last = orientation() == Qt::Horizontal ? bottomRight.column() : bottomRight.row();
for (int i = first; i <= last && !resizeRequired; ++i)
resizeRequired = (resizeMode(i) == ResizeToContents);
resizeRequired = (sectionResizeMode(i) == ResizeToContents);
if (resizeRequired)
d->doDelayedResizeSections();
}

View File

@ -114,18 +114,33 @@ public:
int visualIndex(int logicalIndex) const;
int logicalIndex(int visualIndex) const;
void setMovable(bool movable);
bool isMovable() const;
void setSectionsMovable(bool movable);
bool sectionsMovable() const;
#if QT_DEPRECATED_SINCE(5, 0)
inline QT_DEPRECATED void setMovable(bool movable) { setSectionsMovable(movable); }
inline QT_DEPRECATED bool isMovable() const { return sectionsMovable(); }
#endif
void setClickable(bool clickable);
bool isClickable() const;
void setSectionsClickable(bool clickable);
bool sectionsClickable() const;
#if QT_DEPRECATED_SINCE(5, 0)
inline QT_DEPRECATED void setClickable(bool clickable) { setSectionsClickable(clickable); }
inline QT_DEPRECATED bool isClickable() const { return sectionsClickable(); }
#endif
void setHighlightSections(bool highlight);
bool highlightSections() const;
void setResizeMode(ResizeMode mode);
void setResizeMode(int logicalIndex, ResizeMode mode);
ResizeMode resizeMode(int logicalIndex) const;
ResizeMode sectionResizeMode(int logicalIndex) const;
void setSectionResizeMode(int logicalIndex, ResizeMode mode);
#if QT_DEPRECATED_SINCE(5, 0)
inline QT_DEPRECATED void setResizeMode(int logicalindex, ResizeMode mode)
{ setSectionResizeMode(logicalindex, mode); }
inline QT_DEPRECATED ResizeMode resizeMode(int logicalindex) const
{ return sectionResizeMode(logicalindex); }
#endif
int stretchSectionCount() const;
void setSortIndicatorShown(bool show);

View File

@ -616,12 +616,12 @@ void QTableViewPrivate::init()
q->setEditTriggers(editTriggers|QAbstractItemView::AnyKeyPressed);
QHeaderView *vertical = new QHeaderView(Qt::Vertical, q);
vertical->setClickable(true);
vertical->setSectionsClickable(true);
vertical->setHighlightSections(true);
q->setVerticalHeader(vertical);
QHeaderView *horizontal = new QHeaderView(Qt::Horizontal, q);
horizontal->setClickable(true);
horizontal->setSectionsClickable(true);
horizontal->setHighlightSections(true);
q->setHorizontalHeader(horizontal);

View File

@ -848,7 +848,7 @@ void QTreeView::setSortingEnabled(bool enable)
{
Q_D(QTreeView);
header()->setSortIndicatorShown(enable);
header()->setClickable(enable);
header()->setSectionsClickable(enable);
if (enable) {
//sortByColumn has to be called before we connect or set the sortingEnabled flag
// because otherwise it will not call sort on the model.
@ -2886,7 +2886,7 @@ void QTreeViewPrivate::initialize()
q->setAttribute(Qt::WA_MacShowFocusRect);
QHeaderView *header = new QHeaderView(Qt::Horizontal, q);
header->setMovable(true);
header->setSectionsMovable(true);
header->setStretchLastSection(true);
header->setDefaultAlignment(Qt::AlignLeft|Qt::AlignVCenter);
q->setHeader(header);

View File

@ -2535,7 +2535,7 @@ QTreeWidget::QTreeWidget(QWidget *parent)
this, SLOT(_q_sort()));
connect(selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
this, SLOT(_q_selectionChanged(QItemSelection,QItemSelection)));
header()->setClickable(false);
header()->setSectionsClickable(false);
}
/*!

View File

@ -2068,9 +2068,9 @@ QCalendarWidget::QCalendarWidget(QWidget *parent)
d->m_view->setSelectionBehavior(QAbstractItemView::SelectItems);
d->m_view->setSelectionMode(QAbstractItemView::SingleSelection);
d->m_view->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
d->m_view->horizontalHeader()->setClickable(false);
d->m_view->horizontalHeader()->setSectionsClickable(false);
d->m_view->verticalHeader()->setResizeMode(QHeaderView::Stretch);
d->m_view->verticalHeader()->setClickable(false);
d->m_view->verticalHeader()->setSectionsClickable(false);
d->m_selection = d->m_view->selectionModel();
d->createNavigationBar(this);
d->m_view->setFrameStyle(QFrame::NoFrame);

View File

@ -847,7 +847,7 @@ void tst_QFileSystemModel::sort()
tree->resize(800, 800);
QTest::qWait(500);
tree->header()->setSortIndicator(1,Qt::DescendingOrder);
tree->header()->setResizeMode(0, QHeaderView::ResizeToContents);
tree->header()->setSectionResizeMode(0, QHeaderView::ResizeToContents);
QStringList dirsToOpen;
do
{

View File

@ -502,20 +502,20 @@ void tst_QHeaderView::removeCols()
void tst_QHeaderView::movable()
{
QCOMPARE(view->isMovable(), false);
view->setMovable(false);
QCOMPARE(view->isMovable(), false);
view->setMovable(true);
QCOMPARE(view->isMovable(), true);
QCOMPARE(view->sectionsMovable(), false);
view->setSectionsMovable(false);
QCOMPARE(view->sectionsMovable(), false);
view->setSectionsMovable(true);
QCOMPARE(view->sectionsMovable(), true);
}
void tst_QHeaderView::clickable()
{
QCOMPARE(view->isClickable(), false);
view->setClickable(false);
QCOMPARE(view->isClickable(), false);
view->setClickable(true);
QCOMPARE(view->isClickable(), true);
QCOMPARE(view->sectionsClickable(), false);
view->setSectionsClickable(false);
QCOMPARE(view->sectionsClickable(), false);
view->setSectionsClickable(true);
QCOMPARE(view->sectionsClickable(), true);
}
void tst_QHeaderView::hidden()
@ -1108,7 +1108,7 @@ void tst_QHeaderView::resizeWithResizeModes()
view->setStretchLastSection(false);
for (int i = 0; i < sections.count(); ++i) {
view->resizeSection(i, sections.at(i));
view->setResizeMode(i, (QHeaderView::ResizeMode)modes.at(i));
view->setSectionResizeMode(i, (QHeaderView::ResizeMode)modes.at(i));
}
topLevel->show();
view->resize(size, size);
@ -1150,27 +1150,27 @@ void tst_QHeaderView::resizeMode()
// resizeMode must not be called with an invalid index
int last = view->count() - 1;
view->setResizeMode(QHeaderView::Interactive);
QCOMPARE(view->resizeMode(last), QHeaderView::Interactive);
QCOMPARE(view->resizeMode(1), QHeaderView::Interactive);
QCOMPARE(view->sectionResizeMode(last), QHeaderView::Interactive);
QCOMPARE(view->sectionResizeMode(1), QHeaderView::Interactive);
view->setResizeMode(QHeaderView::Stretch);
QCOMPARE(view->resizeMode(last), QHeaderView::Stretch);
QCOMPARE(view->resizeMode(1), QHeaderView::Stretch);
QCOMPARE(view->sectionResizeMode(last), QHeaderView::Stretch);
QCOMPARE(view->sectionResizeMode(1), QHeaderView::Stretch);
view->setResizeMode(QHeaderView::Custom);
QCOMPARE(view->resizeMode(last), QHeaderView::Custom);
QCOMPARE(view->resizeMode(1), QHeaderView::Custom);
QCOMPARE(view->sectionResizeMode(last), QHeaderView::Custom);
QCOMPARE(view->sectionResizeMode(1), QHeaderView::Custom);
// test when sections have been moved
view->setStretchLastSection(false);
for (int i=0; i < (view->count() - 1); ++i)
view->setResizeMode(i, QHeaderView::Interactive);
view->setSectionResizeMode(i, QHeaderView::Interactive);
int logicalIndex = view->count() / 2;
view->setResizeMode(logicalIndex, QHeaderView::Stretch);
view->setSectionResizeMode(logicalIndex, QHeaderView::Stretch);
view->moveSection(view->visualIndex(logicalIndex), 0);
for (int i=0; i < (view->count() - 1); ++i) {
if (i == logicalIndex)
QCOMPARE(view->resizeMode(i), QHeaderView::Stretch);
QCOMPARE(view->sectionResizeMode(i), QHeaderView::Stretch);
else
QCOMPARE(view->resizeMode(i), QHeaderView::Interactive);
QCOMPARE(view->sectionResizeMode(i), QHeaderView::Interactive);
}
}
@ -1209,12 +1209,12 @@ void tst_QHeaderView::resizeSection()
view->resize(400, 400);
topLevel->show();
view->setMovable(true);
view->setSectionsMovable(true);
view->setStretchLastSection(false);
for (int i = 0; i < logical.count(); ++i)
if (logical.at(i) > -1 && logical.at(i) < view->count()) // for now
view->setResizeMode(logical.at(i), (QHeaderView::ResizeMode)mode.at(i));
view->setSectionResizeMode(logical.at(i), (QHeaderView::ResizeMode)mode.at(i));
for (int j = 0; j < logical.count(); ++j)
view->resizeSection(logical.at(j), initial);
@ -1447,7 +1447,7 @@ void tst_QHeaderView::stretchSectionCount()
view->setStretchLastSection(true);
QCOMPARE(view->stretchSectionCount(), 0);
view->setResizeMode(0, QHeaderView::Stretch);
view->setSectionResizeMode(0, QHeaderView::Stretch);
QCOMPARE(view->stretchSectionCount(), 1);
}
@ -1693,7 +1693,7 @@ void tst_QHeaderView::globalResizeMode()
h.setResizeMode((QHeaderView::ResizeMode)mode);
m.insertRow(insert);
for (int i = 0; i < h.count(); ++i)
QCOMPARE(h.resizeMode(i), (QHeaderView::ResizeMode)mode);
QCOMPARE(h.sectionResizeMode(i), (QHeaderView::ResizeMode)mode);
}
@ -1725,7 +1725,7 @@ void tst_QHeaderView::sectionPressedSignal()
h.setModel(&m);
h.show();
h.setClickable(clickable);
h.setSectionsClickable(clickable);
QSignalSpy spy(&h, SIGNAL(sectionPressed(int)));
@ -1745,7 +1745,7 @@ void tst_QHeaderView::sectionClickedSignal()
h.setModel(&m);
h.show();
h.setClickable(clickable);
h.setSectionsClickable(clickable);
h.setSortIndicatorShown(true);
QSignalSpy spy(&h, SIGNAL(sectionClicked(int)));
@ -1869,7 +1869,7 @@ void tst_QHeaderView::preserveHiddenSectionWidth()
view.resizeSection(0, 100);
view.resizeSection(1, 10);
view.resizeSection(2, 50);
view.setResizeMode(3, QHeaderView::Stretch);
view.setSectionResizeMode(3, QHeaderView::Stretch);
view.show();
view.hideSection(2);
@ -2066,7 +2066,7 @@ void tst_QHeaderView::QTBUG7833_sectionClicked()
tv.setSortingEnabled(true);
tv.horizontalHeader()->setSortIndicatorShown(true);
tv.horizontalHeader()->setClickable(true);
tv.horizontalHeader()->setSectionsClickable(true);
tv.horizontalHeader()->setStretchLastSection(true);
tv.horizontalHeader()->setResizeMode(QHeaderView::Interactive);
@ -2126,7 +2126,7 @@ void tst_QHeaderView::QTBUG12268_hiddenMovedSectionSorting()
for (int j = 0; j< model->columnCount(); ++j)
model->setData(model->index(i,j), QString("item [%1,%2]").arg(i).arg(j));
view.setModel(model);
view.horizontalHeader()->setMovable(true);
view.horizontalHeader()->setSectionsMovable(true);
view.setSortingEnabled(true);
view.sortByColumn(1, Qt::AscendingOrder);
view.horizontalHeader()->moveSection(0,2);