diff options
Diffstat (limited to 'src/widgets/dialogs/qsidebar.cpp')
-rw-r--r-- | src/widgets/dialogs/qsidebar.cpp | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/src/widgets/dialogs/qsidebar.cpp b/src/widgets/dialogs/qsidebar.cpp index 6fbcce801d..f883705cc3 100644 --- a/src/widgets/dialogs/qsidebar.cpp +++ b/src/widgets/dialogs/qsidebar.cpp @@ -60,6 +60,8 @@ void QSideBarDelegate::initStyleOption(QStyleOptionViewItem *option, } /*! + \internal + \class QUrlModel QUrlModel lets you have indexes from a QFileSystemModel to a list. When QFileSystemModel changes them QUrlModel will automatically update. @@ -274,7 +276,9 @@ void QUrlModel::addUrls(const QList<QUrl> &list, int row, bool move) QList<QUrl> QUrlModel::urls() const { QList<QUrl> list; - for (int i = 0; i < rowCount(); ++i) + const int numRows = rowCount(); + list.reserve(numRows); + for (int i = 0; i < numRows; ++i) list.append(data(index(i, 0), UrlRole).toUrl()); return list; } @@ -334,10 +338,12 @@ void QUrlModel::dataChanged(const QModelIndex &topLeft, const QModelIndex &botto void QUrlModel::layoutChanged() { QStringList paths; - for (int i = 0; i < watching.count(); ++i) + const int numPaths = watching.count(); + paths.reserve(numPaths); + for (int i = 0; i < numPaths; ++i) paths.append(watching.at(i).second); watching.clear(); - for (int i = 0; i < paths.count(); ++i) { + for (int i = 0; i < numPaths; ++i) { QString path = paths.at(i); QModelIndex newIndex = fileSystemModel->index(path); watching.append(QPair<QModelIndex, QString>(newIndex, path)); @@ -453,12 +459,14 @@ void QSidebar::removeEntry() { QList<QModelIndex> idxs = selectionModel()->selectedIndexes(); QList<QPersistentModelIndex> indexes; - for (int i = 0; i < idxs.count(); i++) + const int numIndexes = idxs.count(); + for (int i = 0; i < numIndexes; i++) indexes.append(idxs.at(i)); - for (int i = 0; i < indexes.count(); ++i) + for (int i = 0; i < numIndexes; ++i) { if (!indexes.at(i).data(QUrlModel::UrlRole).toUrl().path().isEmpty()) model()->removeRow(indexes.at(i).row()); + } } /*! |