summaryrefslogtreecommitdiffstats
path: root/src/widgets/itemviews/qdirmodel.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/widgets/itemviews/qdirmodel.cpp')
-rw-r--r--src/widgets/itemviews/qdirmodel.cpp78
1 files changed, 44 insertions, 34 deletions
diff --git a/src/widgets/itemviews/qdirmodel.cpp b/src/widgets/itemviews/qdirmodel.cpp
index ac23e22ef7..dfb1d7619e 100644
--- a/src/widgets/itemviews/qdirmodel.cpp
+++ b/src/widgets/itemviews/qdirmodel.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$
**
@@ -34,7 +40,6 @@
#include "qdirmodel.h"
#ifndef QT_NO_DIRMODEL
-#include <qstack.h>
#include <qfile.h>
#include <qfilesystemmodel.h>
#include <qurl.h>
@@ -49,6 +54,9 @@
#include <private/qabstractitemmodel_p.h>
#include <qdebug.h>
+#include <stack>
+#include <vector>
+
/*!
\enum QDirModel::Roles
\value FileIconRole
@@ -128,11 +136,12 @@ public:
QPersistentModelIndexData *data;
QPersistentModelIndex index;
};
- QList<SavedPersistent> savedPersistent;
+ QVector<SavedPersistent> savedPersistent;
QPersistentModelIndex toBeRefreshed;
bool shouldStat; // use the "carefull not to stat directories" mode
};
+Q_DECLARE_TYPEINFO(QDirModelPrivate::SavedPersistent, Q_MOVABLE_TYPE);
void qt_setDirModelShouldNotStat(QDirModelPrivate *modelPrivate)
{
@@ -163,14 +172,15 @@ void QDirModelPrivate::clear(QDirNode *parent) const
void QDirModelPrivate::invalidate()
{
- QStack<const QDirNode*> nodes;
+ std::stack<const QDirNode*, std::vector<const QDirNode*> > nodes;
nodes.push(&root);
while (!nodes.empty()) {
- const QDirNode *current = nodes.pop();
+ const QDirNode *current = nodes.top();
+ nodes.pop();
current->stat = false;
- const QVector<QDirNode> children = current->children;
- for (int i = 0; i < children.count(); ++i)
- nodes.push(&children.at(i));
+ const QVector<QDirNode> &children = current->children;
+ for (const auto &child : children)
+ nodes.push(&child);
}
}
@@ -1022,7 +1032,7 @@ bool QDirModel::rmdir(const QModelIndex &index)
return false;
QDirModelPrivate::QDirNode *n = d_func()->node(index);
- if (!n->info.isDir()) {
+ if (Q_UNLIKELY(!n->info.isDir())) {
qWarning("rmdir: the node is not a directory");
return false;
}
@@ -1172,7 +1182,7 @@ QDirModelPrivate::QDirNode *QDirModelPrivate::node(int row, QDirNode *parent) co
if (isDir && !p->populated)
populate(p); // will also resolve symlinks
- if (row >= p->children.count()) {
+ if (Q_UNLIKELY(row >= p->children.count())) {
qWarning("node: the row does not exist");
return 0;
}
@@ -1228,14 +1238,16 @@ void QDirModelPrivate::savePersistentIndexes()
{
Q_Q(QDirModel);
savedPersistent.clear();
+ savedPersistent.reserve(persistent.indexes.size());
foreach (QPersistentModelIndexData *data, persistent.indexes) {
- SavedPersistent saved;
QModelIndex index = data->index;
- saved.path = q->filePath(index);
- saved.column = index.column();
- saved.data = data;
- saved.index = index;
- savedPersistent.append(saved);
+ SavedPersistent saved = {
+ q->filePath(index),
+ index.column(),
+ data,
+ index,
+ };
+ savedPersistent.push_back(std::move(saved));
}
}
@@ -1244,11 +1256,9 @@ void QDirModelPrivate::restorePersistentIndexes()
Q_Q(QDirModel);
bool allow = allowAppendChild;
allowAppendChild = false;
- for (int i = 0; i < savedPersistent.count(); ++i) {
- QPersistentModelIndexData *data = savedPersistent.at(i).data;
- QString path = savedPersistent.at(i).path;
- int column = savedPersistent.at(i).column;
- QModelIndex idx = q->index(path, column);
+ for (const SavedPersistent &sp : qAsConst(savedPersistent)) {
+ QPersistentModelIndexData *data = sp.data;
+ QModelIndex idx = q->index(sp.path, sp.column);
if (idx != data->index || data->model == 0) {
//data->model may be equal to 0 if the model is getting destroyed
persistent.indexes.remove(data->index);