QTreeWidget: mark is/setFirstItemColumnSpanned() as deprecated

Deprecate the QTreeWidget functions is/setFirstItemColumnSpanned() to
stay in sync with the other deprecated functions
(selected/expanded/hidden) so they can get removed in Qt6.
Also add a small unit test for them.

Change-Id: Ie1cb5d7163c2d56d653c21e841ccaf7d38569787
Reviewed-by: Samuel Gaist <samuel.gaist@idiap.ch>
Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
This commit is contained in:
Christian Ehrlicher 2018-11-02 21:48:52 +01:00
parent f56ca2c4f6
commit e56c79dc9d
3 changed files with 56 additions and 20 deletions

View File

@ -1127,6 +1127,14 @@ bool QTreeWidgetItem::isExpanded() const
\sa isFirstColumnSpanned()
*/
void QTreeWidgetItem::setFirstColumnSpanned(bool span)
{
const QTreeModel *model = treeModel();
if (!model || this == model->headerItem)
return; // We can't set the header items to spanning
const QModelIndex index = model->index(this, 0);
view->setFirstColumnSpanned(index.row(), index.parent(), span);
}
/*!
\fn bool QTreeWidgetItem::isFirstColumnSpanned() const
@ -1136,6 +1144,14 @@ bool QTreeWidgetItem::isExpanded() const
\sa setFirstColumnSpanned()
*/
bool QTreeWidgetItem::isFirstColumnSpanned() const
{
const QTreeModel *model = treeModel();
if (!model || this == model->headerItem)
return false;
const QModelIndex index = model->index(this, 0);
return view->isFirstColumnSpanned(index.row(), index.parent());
}
/*!
\fn QString QTreeWidgetItem::text(int column) const
@ -3230,7 +3246,6 @@ void QTreeWidget::setItemExpanded(const QTreeWidgetItem *item, bool expand)
if (item && item->treeWidget() == this)
const_cast<QTreeWidgetItem*>(item)->setExpanded(expand);
}
#endif
/*!
\since 4.3
@ -3239,14 +3254,14 @@ void QTreeWidget::setItemExpanded(const QTreeWidgetItem *item, bool expand)
otherwise returns \c false.
\sa setFirstItemColumnSpanned()
\obsolete
This function is deprecated. Use \l{QTreeWidgetItem::isFirstColumnSpanned()} instead.
*/
bool QTreeWidget::isFirstItemColumnSpanned(const QTreeWidgetItem *item) const
{
Q_D(const QTreeWidget);
if (item == d->treeModel()->headerItem)
return false; // We can't set the header items to spanning
const QModelIndex index = d->index(item);
return isFirstColumnSpanned(index.row(), index.parent());
return ((item && item->treeWidget() == this) ? item->isFirstColumnSpanned() : false);
}
/*!
@ -3256,15 +3271,17 @@ bool QTreeWidget::isFirstItemColumnSpanned(const QTreeWidgetItem *item) const
otherwise the item will show one section per column.
\sa isFirstItemColumnSpanned()
\obsolete
This function is deprecated. Use \l{QTreeWidgetItem::setFirstColumnSpanned()} instead.
*/
void QTreeWidget::setFirstItemColumnSpanned(const QTreeWidgetItem *item, bool span)
{
Q_D(QTreeWidget);
if (item == d->treeModel()->headerItem)
return; // We can't set header items to spanning
const QModelIndex index = d->index(item);
setFirstColumnSpanned(index.row(), index.parent(), span);
if (item && item->treeWidget() == this)
const_cast<QTreeWidgetItem*>(item)->setFirstColumnSpanned(span);
}
#endif
/*!
\since 4.3

View File

@ -88,8 +88,8 @@ public:
void setExpanded(bool expand);
bool isExpanded() const;
inline void setFirstColumnSpanned(bool span);
inline bool isFirstColumnSpanned() const;
void setFirstColumnSpanned(bool span);
bool isFirstColumnSpanned() const;
inline void setDisabled(bool disabled);
inline bool isDisabled() const;
@ -335,10 +335,12 @@ public:
bool isItemExpanded(const QTreeWidgetItem *item) const;
QT_DEPRECATED_X ("Use QTreeWidgetItem::setExpanded() instead")
void setItemExpanded(const QTreeWidgetItem *item, bool expand);
#endif
QT_DEPRECATED_X ("Use QTreeWidgetItem::isFirstColumnSpanned() instead")
bool isFirstItemColumnSpanned(const QTreeWidgetItem *item) const;
QT_DEPRECATED_X ("Use QTreeWidgetItem::setFirstColumnSpanned() instead")
void setFirstItemColumnSpanned(const QTreeWidgetItem *item, bool span);
#endif
QTreeWidgetItem *itemAbove(const QTreeWidgetItem *item) const;
QTreeWidgetItem *itemBelow(const QTreeWidgetItem *item) const;
@ -423,12 +425,6 @@ inline QTreeWidgetItem *QTreeWidget::itemAt(int ax, int ay) const
inline void QTreeWidget::setHeaderLabel(const QString &alabel)
{ setHeaderLabels(QStringList(alabel)); }
inline void QTreeWidgetItem::setFirstColumnSpanned(bool aspan)
{ if (view) view->setFirstItemColumnSpanned(this, aspan); }
inline bool QTreeWidgetItem::isFirstColumnSpanned() const
{ return (view ? view->isFirstItemColumnSpanned(this) : false); }
inline void QTreeWidgetItem::setDisabled(bool disabled)
{ setFlags(disabled ? (flags() & ~Qt::ItemIsEnabled) : flags() | Qt::ItemIsEnabled); }

View File

@ -140,6 +140,7 @@ private slots:
void expandAndCallapse();
void itemData();
void setDisabled();
void setSpanned();
void removeSelectedItem();
void removeCurrentItem();
void removeCurrentItem_task186451();
@ -2818,6 +2819,28 @@ void tst_QTreeWidget::setDisabled()
QCOMPARE(takenChildren.items[1]->isDisabled(), false);
}
void tst_QTreeWidget::setSpanned()
{
QTreeWidget w;
QTreeWidgetItem *i1 = new QTreeWidgetItem();
QScopedPointer<QTreeWidgetItem> i2(new QTreeWidgetItem());
QTreeWidgetItem *top = new QTreeWidgetItem(&w);
top->addChild(i1);
top->setFirstColumnSpanned(true);
QCOMPARE(top->isFirstColumnSpanned(), true);
QCOMPARE(i1->isFirstColumnSpanned(), false);
QCOMPARE(i2->isFirstColumnSpanned(), false);
top->setFirstColumnSpanned(false);
i1->setFirstColumnSpanned(true);
i2->setFirstColumnSpanned(true);
QCOMPARE(top->isFirstColumnSpanned(), false);
QCOMPARE(i1->isFirstColumnSpanned(), true);
QCOMPARE(i2->isFirstColumnSpanned(), false);
}
void tst_QTreeWidget::removeSelectedItem()
{
const QScopedPointer <QTreeWidget> w(new QTreeWidget);