QTreeView/TableView: explicitly mark sortByColumn(int) as deprecated
QTreeView/TableView::sortByColumn(int) was deprecated a long time ago but never got removed. Therefore mark it with QT_DEPRECATED_SINCE(5, 13) so we can remove it with Qt6. Also sync the handling of the sort order changes in QTableView with the one from QTreeView. Change-Id: I0371d9a9c21116edaa9125835827f1a200075d36 Reviewed-by: Luca Beldi <v.ronin@yahoo.it> Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>bb10
parent
d84a7a8128
commit
d0f909f8db
|
|
@ -902,6 +902,15 @@ void QTableViewPrivate::_q_updateSpanRemovedColumns(const QModelIndex &parent, i
|
|||
spans.updateRemovedColumns(start, end);
|
||||
}
|
||||
|
||||
/*!
|
||||
\internal
|
||||
Sort the model when the header sort indicator changed
|
||||
*/
|
||||
void QTableViewPrivate::_q_sortIndicatorChanged(int column, Qt::SortOrder order)
|
||||
{
|
||||
model->sort(column, order);
|
||||
}
|
||||
|
||||
/*!
|
||||
\internal
|
||||
Draws a table cell.
|
||||
|
|
@ -2573,25 +2582,27 @@ void QTableView::setColumnHidden(int column, bool hide)
|
|||
void QTableView::setSortingEnabled(bool enable)
|
||||
{
|
||||
Q_D(QTableView);
|
||||
d->sortingEnabled = enable;
|
||||
horizontalHeader()->setSortIndicatorShown(enable);
|
||||
if (enable) {
|
||||
disconnect(d->horizontalHeader, SIGNAL(sectionEntered(int)),
|
||||
this, SLOT(_q_selectColumn(int)));
|
||||
disconnect(horizontalHeader(), SIGNAL(sectionPressed(int)),
|
||||
this, SLOT(selectColumn(int)));
|
||||
connect(horizontalHeader(), SIGNAL(sortIndicatorChanged(int,Qt::SortOrder)),
|
||||
this, SLOT(sortByColumn(int)), Qt::UniqueConnection);
|
||||
//sortByColumn has to be called before we connect or set the sortingEnabled flag
|
||||
// because otherwise it will not call sort on the model.
|
||||
sortByColumn(horizontalHeader()->sortIndicatorSection(),
|
||||
horizontalHeader()->sortIndicatorOrder());
|
||||
connect(horizontalHeader(), SIGNAL(sortIndicatorChanged(int,Qt::SortOrder)),
|
||||
this, SLOT(_q_sortIndicatorChanged(int,Qt::SortOrder)), Qt::UniqueConnection);
|
||||
} else {
|
||||
connect(d->horizontalHeader, SIGNAL(sectionEntered(int)),
|
||||
this, SLOT(_q_selectColumn(int)), Qt::UniqueConnection);
|
||||
connect(horizontalHeader(), SIGNAL(sectionPressed(int)),
|
||||
this, SLOT(selectColumn(int)), Qt::UniqueConnection);
|
||||
disconnect(horizontalHeader(), SIGNAL(sortIndicatorChanged(int,Qt::SortOrder)),
|
||||
this, SLOT(sortByColumn(int)));
|
||||
this, SLOT(_q_sortIndicatorChanged(int,Qt::SortOrder)));
|
||||
}
|
||||
d->sortingEnabled = enable;
|
||||
}
|
||||
|
||||
bool QTableView::isSortingEnabled() const
|
||||
|
|
@ -3120,19 +3131,21 @@ void QTableView::resizeColumnsToContents()
|
|||
d->horizontalHeader->resizeSections(QHeaderView::ResizeToContents);
|
||||
}
|
||||
|
||||
#if QT_DEPRECATED_SINCE(5, 13)
|
||||
/*!
|
||||
\obsolete
|
||||
\overload
|
||||
|
||||
This function is deprecated. Use
|
||||
sortByColumn(int column, Qt::SortOrder order) instead.
|
||||
Sorts the model by the values in the given \a column.
|
||||
*/
|
||||
void QTableView::sortByColumn(int column)
|
||||
{
|
||||
Q_D(QTableView);
|
||||
if (column == -1)
|
||||
return;
|
||||
d->model->sort(column, d->horizontalHeader->sortIndicatorOrder());
|
||||
sortByColumn(column, d->horizontalHeader->sortIndicatorOrder());
|
||||
}
|
||||
#endif
|
||||
|
||||
/*!
|
||||
\since 4.2
|
||||
|
|
@ -3144,8 +3157,14 @@ void QTableView::sortByColumn(int column)
|
|||
void QTableView::sortByColumn(int column, Qt::SortOrder order)
|
||||
{
|
||||
Q_D(QTableView);
|
||||
if (column < 0)
|
||||
return;
|
||||
// If sorting is enabled it will emit a signal connected to
|
||||
// _q_sortIndicatorChanged, which then actually sorts
|
||||
d->horizontalHeader->setSortIndicator(column, order);
|
||||
sortByColumn(column);
|
||||
// If sorting is not enabled, force to sort now
|
||||
if (!d->sortingEnabled)
|
||||
d->model->sort(column, order);
|
||||
}
|
||||
|
||||
/*!
|
||||
|
|
|
|||
|
|
@ -118,7 +118,6 @@ public:
|
|||
int columnSpan(int row, int column) const;
|
||||
void clearSpans();
|
||||
|
||||
void sortByColumn(int column, Qt::SortOrder order);
|
||||
|
||||
public Q_SLOTS:
|
||||
void selectRow(int row);
|
||||
|
|
@ -131,7 +130,11 @@ public Q_SLOTS:
|
|||
void resizeRowsToContents();
|
||||
void resizeColumnToContents(int column);
|
||||
void resizeColumnsToContents();
|
||||
#if QT_DEPRECATED_SINCE(5, 13)
|
||||
QT_DEPRECATED_X ("Use QTableView::sortByColumn(int column, Qt::SortOrder order) instead")
|
||||
void sortByColumn(int column);
|
||||
#endif
|
||||
void sortByColumn(int column, Qt::SortOrder order);
|
||||
void setShowGrid(bool show);
|
||||
|
||||
protected Q_SLOTS:
|
||||
|
|
@ -188,6 +191,7 @@ private:
|
|||
Q_PRIVATE_SLOT(d_func(), void _q_updateSpanInsertedColumns(QModelIndex,int,int))
|
||||
Q_PRIVATE_SLOT(d_func(), void _q_updateSpanRemovedRows(QModelIndex,int,int))
|
||||
Q_PRIVATE_SLOT(d_func(), void _q_updateSpanRemovedColumns(QModelIndex,int,int))
|
||||
Q_PRIVATE_SLOT(d_func(), void _q_sortIndicatorChanged(int column, Qt::SortOrder order))
|
||||
};
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
|
|
|||
|
|
@ -257,6 +257,7 @@ public:
|
|||
void _q_updateSpanInsertedColumns(const QModelIndex &parent, int start, int end);
|
||||
void _q_updateSpanRemovedRows(const QModelIndex &parent, int start, int end);
|
||||
void _q_updateSpanRemovedColumns(const QModelIndex &parent, int start, int end);
|
||||
void _q_sortIndicatorChanged(int column, Qt::SortOrder order);
|
||||
};
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
|
|
|||
|
|
@ -2598,10 +2598,13 @@ void QTreeView::resizeColumnToContents(int column)
|
|||
d->header->resizeSection(column, qMax(contents, header));
|
||||
}
|
||||
|
||||
#if QT_DEPRECATED_SINCE(5, 13)
|
||||
/*!
|
||||
\obsolete
|
||||
\overload
|
||||
|
||||
This function is deprecated. Use
|
||||
sortByColumn(int column, Qt::SortOrder order) instead.
|
||||
Sorts the model by the values in the given \a column.
|
||||
*/
|
||||
void QTreeView::sortByColumn(int column)
|
||||
|
|
@ -2609,6 +2612,7 @@ void QTreeView::sortByColumn(int column)
|
|||
Q_D(QTreeView);
|
||||
sortByColumn(column, d->header->sortIndicatorOrder());
|
||||
}
|
||||
#endif
|
||||
|
||||
/*!
|
||||
\since 4.2
|
||||
|
|
@ -2624,10 +2628,12 @@ void QTreeView::sortByColumn(int column)
|
|||
void QTreeView::sortByColumn(int column, Qt::SortOrder order)
|
||||
{
|
||||
Q_D(QTreeView);
|
||||
|
||||
//If sorting is enabled will emit a signal connected to _q_sortIndicatorChanged, which then actually sorts
|
||||
if (column < 0)
|
||||
return;
|
||||
// If sorting is enabled it will emit a signal connected to
|
||||
// _q_sortIndicatorChanged, which then actually sorts
|
||||
d->header->setSortIndicator(column, order);
|
||||
//If sorting is not enabled, force to sort now.
|
||||
// If sorting is not enabled, force to sort now
|
||||
if (!d->sortingEnabled)
|
||||
d->model->sort(column, order);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -143,7 +143,6 @@ public:
|
|||
void doItemsLayout() override;
|
||||
void reset() override;
|
||||
|
||||
void sortByColumn(int column, Qt::SortOrder order);
|
||||
|
||||
void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles = QVector<int>()) override;
|
||||
void selectAll() override;
|
||||
|
|
@ -158,7 +157,11 @@ public Q_SLOTS:
|
|||
void expand(const QModelIndex &index);
|
||||
void collapse(const QModelIndex &index);
|
||||
void resizeColumnToContents(int column);
|
||||
#if QT_DEPRECATED_SINCE(5, 13)
|
||||
QT_DEPRECATED_X ("Use QTreeeView::sortByColumn(int column, Qt::SortOrder order) instead")
|
||||
void sortByColumn(int column);
|
||||
#endif
|
||||
void sortByColumn(int column, Qt::SortOrder order);
|
||||
void expandAll();
|
||||
void expandRecursively(const QModelIndex &index, int depth = -1);
|
||||
void collapseAll();
|
||||
|
|
|
|||
|
|
@ -81,7 +81,7 @@ void tst_QAbstractItemModelTester::treeWidgetModel()
|
|||
new QTreeWidgetItem(parent, QStringList("child"));
|
||||
widget.setItemHidden(parent, true);
|
||||
|
||||
widget.sortByColumn(0);
|
||||
widget.sortByColumn(0, Qt::AscendingOrder);
|
||||
}
|
||||
|
||||
void tst_QAbstractItemModelTester::standardItemModel()
|
||||
|
|
|
|||
|
|
@ -2792,7 +2792,7 @@ void tst_QTreeView::sortByColumn()
|
|||
|
||||
view.setSortingEnabled(sortingEnabled);
|
||||
view.setModel(&model);
|
||||
view.sortByColumn(1);
|
||||
view.sortByColumn(1, Qt::DescendingOrder);
|
||||
QCOMPARE(view.header()->sortIndicatorSection(), 1);
|
||||
QCOMPARE(view.model()->data(view.model()->index(0,1)).toString(), QString::fromLatin1("h"));
|
||||
QCOMPARE(view.model()->data(view.model()->index(1,1)).toString(), QString::fromLatin1("g"));
|
||||
|
|
@ -3102,7 +3102,7 @@ void tst_QTreeView::evilModel()
|
|||
view.resizeColumnToContents(1);
|
||||
model.change();
|
||||
|
||||
view.sortByColumn(1);
|
||||
view.sortByColumn(1, Qt::DescendingOrder);
|
||||
model.change();
|
||||
|
||||
view.selectAll();
|
||||
|
|
@ -3946,7 +3946,7 @@ void tst_QTreeView::task254234_proxySort()
|
|||
model.setItem(2,1,new QStandardItem("h"));
|
||||
model.setItem(3,1,new QStandardItem("f"));
|
||||
|
||||
view.sortByColumn(1);
|
||||
view.sortByColumn(1, Qt::DescendingOrder);
|
||||
view.setSortingEnabled(true);
|
||||
|
||||
QSortFilterProxyModel proxy;
|
||||
|
|
|
|||
Loading…
Reference in New Issue