summaryrefslogtreecommitdiffstats
path: root/src/widgets/itemviews/qtreewidget.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/widgets/itemviews/qtreewidget.cpp')
-rw-r--r--src/widgets/itemviews/qtreewidget.cpp97
1 files changed, 57 insertions, 40 deletions
diff --git a/src/widgets/itemviews/qtreewidget.cpp b/src/widgets/itemviews/qtreewidget.cpp
index e0f6a3d5d1..31d60c06d7 100644
--- a/src/widgets/itemviews/qtreewidget.cpp
+++ b/src/widgets/itemviews/qtreewidget.cpp
@@ -1,31 +1,37 @@
/****************************************************************************
**
-** Copyright (C) 2015 The Qt Company Ltd.
-** Contact: http://www.qt.io/licensing/
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtWidgets module of the Qt Toolkit.
**
-** $QT_BEGIN_LICENSE:LGPL21$
+** $QT_BEGIN_LICENSE:LGPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see http://www.qt.io/terms-conditions. For further
-** information use the contact form at http://www.qt.io/contact-us.
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 or version 3 as published by the Free
-** Software Foundation and appearing in the file LICENSE.LGPLv21 and
-** LICENSE.LGPLv3 included in the packaging of this file. Please review the
-** following information to ensure the GNU Lesser General Public License
-** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
-** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
**
-** As a special exception, The Qt Company gives you certain additional
-** rights. These rights are described in The Qt Company LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
@@ -726,9 +732,9 @@ QMimeData *QTreeModel::internalMimeData() const
QMimeData *QTreeModel::mimeData(const QModelIndexList &indexes) const
{
QList<QTreeWidgetItem*> items;
- for (int i = 0; i < indexes.count(); ++i) {
- if (indexes.at(i).column() == 0) // only one item per row
- items << item(indexes.at(i));
+ for (const auto &index : indexes) {
+ if (index.column() == 0) // only one item per row
+ items << item(index);
}
// cachedIndexes is a little hack to avoid copying from QModelIndexList to
@@ -1736,7 +1742,7 @@ void QTreeWidgetItem::setData(int column, int role, const QVariant &value)
default:
if (column < values.count()) {
bool found = false;
- QVector<QWidgetItemData> column_values = values.at(column);
+ const QVector<QWidgetItemData> column_values = values.at(column);
for (int i = 0; i < column_values.count(); ++i) {
if (column_values.at(i).role == role) {
if (column_values.at(i).value == value)
@@ -1786,9 +1792,10 @@ QVariant QTreeWidgetItem::data(int column, int role) const
default:
if (column >= 0 && column < values.size()) {
const QVector<QWidgetItemData> &column_values = values.at(column);
- for (int i = 0; i < column_values.count(); ++i)
- if (column_values.at(i).role == role)
- return column_values.at(i).value;
+ for (const auto &column_value : column_values) {
+ if (column_value.role == role)
+ return column_value.value;
+ }
}
}
return QVariant();
@@ -2137,8 +2144,8 @@ QVariant QTreeWidgetItem::childrenCheckState(int column) const
return QVariant();
bool checkedChildren = false;
bool uncheckedChildren = false;
- for (int i = 0; i < children.count(); ++i) {
- QVariant value = children.at(i)->data(column, Qt::CheckStateRole);
+ for (const auto *child : children) {
+ QVariant value = child->data(column, Qt::CheckStateRole);
if (!value.isValid())
return QVariant();
@@ -3019,13 +3026,13 @@ void QTreeWidget::setItemSelected(const QTreeWidgetItem *item, bool select)
QList<QTreeWidgetItem*> QTreeWidget::selectedItems() const
{
Q_D(const QTreeWidget);
- QModelIndexList indexes = selectionModel()->selectedIndexes();
+ const QModelIndexList indexes = selectionModel()->selectedIndexes();
QList<QTreeWidgetItem*> items;
items.reserve(indexes.count());
QSet<QTreeWidgetItem *> seen;
seen.reserve(indexes.count());
- for (int i = 0; i < indexes.count(); ++i) {
- QTreeWidgetItem *item = d->item(indexes.at(i));
+ for (const auto &index : indexes) {
+ QTreeWidgetItem *item = d->item(index);
if (isItemHidden(item) || seen.contains(item))
continue;
seen.insert(item);
@@ -3279,16 +3286,15 @@ QMimeData *QTreeWidget::mimeData(const QList<QTreeWidgetItem*> items) const
Q_D(const QTreeWidget);
if (d->treeModel()->cachedIndexes.isEmpty()) {
QList<QModelIndex> indexes;
- for (int i = 0; i < items.count(); ++i) {
- QTreeWidgetItem *item = items.at(i);
- if (!item) {
+ for (const auto *item : items) {
+ if (Q_UNLIKELY(!item)) {
qWarning("QTreeWidget::mimeData: Null-item passed");
return 0;
}
for (int c = 0; c < item->values.count(); ++c) {
const QModelIndex index = indexFromItem(item, c);
- if (!index.isValid()) {
+ if (Q_UNLIKELY(!index.isValid())) {
qWarning() << "QTreeWidget::mimeData: No index associated with item :" << item;
return 0;
}
@@ -3341,18 +3347,29 @@ QList<QTreeWidgetItem*> QTreeWidget::items(const QMimeData *data) const
}
/*!
- Returns the QModelIndex assocated with the given \a item in the given \a column.
+ Returns the QModelIndex associated with the given \a item in the given \a column.
+
+ \note In Qt versions prior to 5.7, this function took a non-\c{const} \a item.
\sa itemFromIndex(), topLevelItem()
*/
-QModelIndex QTreeWidget::indexFromItem(QTreeWidgetItem *item, int column) const
+QModelIndex QTreeWidget::indexFromItem(const QTreeWidgetItem *item, int column) const
{
Q_D(const QTreeWidget);
return d->index(item, column);
}
/*!
- Returns a pointer to the QTreeWidgetItem assocated with the given \a index.
+ \overload
+ \internal
+*/
+QModelIndex QTreeWidget::indexFromItem(QTreeWidgetItem *item, int column) const
+{
+ return indexFromItem(const_cast<const QTreeWidgetItem *>(item), column);
+}
+
+/*!
+ Returns a pointer to the QTreeWidgetItem associated with the given \a index.
\sa indexFromItem()
*/
@@ -3372,12 +3389,12 @@ void QTreeWidget::dropEvent(QDropEvent *event) {
int col = -1;
int row = -1;
if (d->dropOn(event, &row, &col, &topIndex)) {
- QList<QModelIndex> idxs = selectedIndexes();
+ const QList<QModelIndex> idxs = selectedIndexes();
QList<QPersistentModelIndex> indexes;
const int indexesCount = idxs.count();
indexes.reserve(indexesCount);
- for (int i = 0; i < indexesCount; i++)
- indexes.append(idxs.at(i));
+ for (const auto &idx : idxs)
+ indexes.append(idx);
if (indexes.contains(topIndex))
return;
@@ -3387,12 +3404,12 @@ void QTreeWidget::dropEvent(QDropEvent *event) {
// Remove the items
QList<QTreeWidgetItem *> taken;
- for (int i = 0; i < indexes.count(); ++i) {
- QTreeWidgetItem *parent = itemFromIndex(indexes.at(i));
+ for (const auto &index : indexes) {
+ QTreeWidgetItem *parent = itemFromIndex(index);
if (!parent || !parent->parent()) {
- taken.append(takeTopLevelItem(indexes.at(i).row()));
+ taken.append(takeTopLevelItem(index.row()));
} else {
- taken.append(parent->parent()->takeChild(indexes.at(i).row()));
+ taken.append(parent->parent()->takeChild(index.row()));
}
}