qfilesystemmodel.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/widgets/dialogs/qfilesystemmodel.cpp
Source codeSwitch to Preprocessed file
LineSourceCount
1/****************************************************************************-
2**-
3** Copyright (C) 2016 The Qt Company Ltd.-
4** Contact: https://www.qt.io/licensing/-
5**-
6** This file is part of the QtWidgets module of the Qt Toolkit.-
7**-
8** $QT_BEGIN_LICENSE:LGPL$-
9** Commercial License Usage-
10** Licensees holding valid commercial Qt licenses may use this file in-
11** accordance with the commercial license agreement provided with the-
12** Software or, alternatively, in accordance with the terms contained in-
13** a written agreement between you and The Qt Company. For licensing terms-
14** and conditions see https://www.qt.io/terms-conditions. For further-
15** information use the contact form at https://www.qt.io/contact-us.-
16**-
17** GNU Lesser General Public License Usage-
18** Alternatively, this file may be used under the terms of the GNU Lesser-
19** General Public License version 3 as published by the Free Software-
20** Foundation and appearing in the file LICENSE.LGPL3 included in the-
21** packaging of this file. Please review the following information to-
22** ensure the GNU Lesser General Public License version 3 requirements-
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.-
24**-
25** GNU General Public License Usage-
26** Alternatively, this file may be used under the terms of the GNU-
27** General Public License version 2.0 or (at your option) the GNU General-
28** Public license version 3 or any later version approved by the KDE Free-
29** Qt Foundation. The licenses are as published by the Free Software-
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3-
31** included in the packaging of this file. Please review the following-
32** information to ensure the GNU General Public License requirements will-
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and-
34** https://www.gnu.org/licenses/gpl-3.0.html.-
35**-
36** $QT_END_LICENSE$-
37**-
38****************************************************************************/-
39-
40#include "qfilesystemmodel_p.h"-
41#include "qfilesystemmodel.h"-
42#include <qlocale.h>-
43#include <qmimedata.h>-
44#include <qurl.h>-
45#include <qdebug.h>-
46#include <qmessagebox.h>-
47#include <qapplication.h>-
48#include <QtCore/qcollator.h>-
49-
50#include <algorithm>-
51-
52#ifdef Q_OS_WIN-
53# include <QtCore/QVarLengthArray>-
54# include <qt_windows.h>-
55#endif-
56-
57QT_BEGIN_NAMESPACE-
58-
59#ifndef QT_NO_FILESYSTEMMODEL-
60-
61/*!-
62 \enum QFileSystemModel::Roles-
63 \value FileIconRole-
64 \value FilePathRole-
65 \value FileNameRole-
66 \value FilePermissions-
67*/-
68-
69/*!-
70 \class QFileSystemModel-
71 \since 4.4-
72-
73 \brief The QFileSystemModel class provides a data model for the local filesystem.-
74-
75 \ingroup model-view-
76 \inmodule QtWidgets-
77-
78 This class provides access to the local filesystem, providing functions-
79 for renaming and removing files and directories, and for creating new-
80 directories. In the simplest case, it can be used with a suitable display-
81 widget as part of a browser or filter.-
82-
83 QFileSystemModel can be accessed using the standard interface provided by-
84 QAbstractItemModel, but it also provides some convenience functions that are-
85 specific to a directory model.-
86 The fileInfo(), isDir(), fileName() and filePath() functions provide information-
87 about the underlying files and directories related to items in the model.-
88 Directories can be created and removed using mkdir(), rmdir().-
89-
90 \note QFileSystemModel requires an instance of \l QApplication.-
91-
92 \section1 Example Usage-
93-
94 A directory model that displays the contents of a default directory-
95 is usually constructed with a parent object:-
96-
97 \snippet shareddirmodel/main.cpp 2-
98-
99 A tree view can be used to display the contents of the model-
100-
101 \snippet shareddirmodel/main.cpp 4-
102-
103 and the contents of a particular directory can be displayed by-
104 setting the tree view's root index:-
105-
106 \snippet shareddirmodel/main.cpp 7-
107-
108 The view's root index can be used to control how much of a-
109 hierarchical model is displayed. QFileSystemModel provides a convenience-
110 function that returns a suitable model index for a path to a-
111 directory within the model.-
112-
113 \section1 Caching and Performance-
114-
115 QFileSystemModel will not fetch any files or directories until setRootPath()-
116 is called. This will prevent any unnecessary querying on the file system-
117 until that point such as listing the drives on Windows.-
118-
119 Unlike QDirModel, QFileSystemModel uses a separate thread to populate-
120 itself so it will not cause the main thread to hang as the file system-
121 is being queried. Calls to rowCount() will return 0 until the model-
122 populates a directory.-
123-
124 QFileSystemModel keeps a cache with file information. The cache is-
125 automatically kept up to date using the QFileSystemWatcher.-
126-
127 \sa {Model Classes}-
128*/-
129-
130/*!-
131 \fn bool QFileSystemModel::rmdir(const QModelIndex &index)-
132-
133 Removes the directory corresponding to the model item \a index in the-
134 file system model and \b{deletes the corresponding directory from the-
135 file system}, returning true if successful. If the directory cannot be-
136 removed, false is returned.-
137-
138 \warning This function deletes directories from the file system; it does-
139 \b{not} move them to a location where they can be recovered.-
140-
141 \sa remove()-
142*/-
143-
144/*!-
145 \fn QIcon QFileSystemModel::fileName(const QModelIndex &index) const-
146-
147 Returns the file name for the item stored in the model under the given-
148 \a index.-
149*/-
150-
151/*!-
152 \fn QIcon QFileSystemModel::fileIcon(const QModelIndex &index) const-
153-
154 Returns the icon for the item stored in the model under the given-
155 \a index.-
156*/-
157-
158/*!-
159 \fn QFileInfo QFileSystemModel::fileInfo(const QModelIndex &index) const-
160-
161 Returns the QFileInfo for the item stored in the model under the given-
162 \a index.-
163*/-
164QFileInfo QFileSystemModel::fileInfo(const QModelIndex &index) const-
165{-
166 Q_D(const QFileSystemModel);-
167 return d->node(index)->fileInfo();
never executed: return d->node(index)->fileInfo();
0
168}-
169-
170/*!-
171 \fn void QFileSystemModel::rootPathChanged(const QString &newPath);-
172-
173 This signal is emitted whenever the root path has been changed to a \a newPath.-
174*/-
175-
176/*!-
177 \fn void QFileSystemModel::fileRenamed(const QString &path, const QString &oldName, const QString &newName)-
178-
179 This signal is emitted whenever a file with the \a oldName is successfully-
180 renamed to \a newName. The file is located in in the directory \a path.-
181*/-
182-
183/*!-
184 \since 4.7-
185 \fn void QFileSystemModel::directoryLoaded(const QString &path)-
186-
187 This signal is emitted when the gatherer thread has finished to load the \a path.-
188-
189*/-
190-
191/*!-
192 \fn bool QFileSystemModel::remove(const QModelIndex &index)-
193-
194 Removes the model item \a index from the file system model and \b{deletes the-
195 corresponding file from the file system}, returning true if successful. If the-
196 item cannot be removed, false is returned.-
197-
198 \warning This function deletes files from the file system; it does \b{not}-
199 move them to a location where they can be recovered.-
200-
201 \sa rmdir()-
202*/-
203-
204bool QFileSystemModel::remove(const QModelIndex &aindex)-
205{-
206 const QString path = filePath(aindex);-
207 const bool success = QFileInfo(path).isFile() ? QFile::remove(path) : QDir(path).removeRecursively();
QFileInfo(path).isFile()Description
TRUEnever evaluated
FALSEnever evaluated
0
208#ifndef QT_NO_FILESYSTEMWATCHER-
209 if (success) {
successDescription
TRUEnever evaluated
FALSEnever evaluated
0
210 QFileSystemModelPrivate * d = const_cast<QFileSystemModelPrivate*>(d_func());-
211 d->fileInfoGatherer.removePath(path);-
212 }
never executed: end of block
0
213#endif-
214 return success;
never executed: return success;
0
215}-
216-
217/*!-
218 Constructs a file system model with the given \a parent.-
219*/-
220QFileSystemModel::QFileSystemModel(QObject *parent)-
221 : QAbstractItemModel(*new QFileSystemModelPrivate, parent)-
222{-
223 Q_D(QFileSystemModel);-
224 d->init();-
225}
never executed: end of block
0
226-
227/*!-
228 \internal-
229*/-
230QFileSystemModel::QFileSystemModel(QFileSystemModelPrivate &dd, QObject *parent)-
231 : QAbstractItemModel(dd, parent)-
232{-
233 Q_D(QFileSystemModel);-
234 d->init();-
235}
never executed: end of block
0
236-
237/*!-
238 Destroys this file system model.-
239*/-
240QFileSystemModel::~QFileSystemModel()-
241{-
242}-
243-
244/*!-
245 \reimp-
246*/-
247QModelIndex QFileSystemModel::index(int row, int column, const QModelIndex &parent) const-
248{-
249 Q_D(const QFileSystemModel);-
250 if (row < 0 || column < 0 || row >= rowCount(parent) || column >= columnCount(parent))
row < 0Description
TRUEnever evaluated
FALSEnever evaluated
column < 0Description
TRUEnever evaluated
FALSEnever evaluated
row >= rowCount(parent)Description
TRUEnever evaluated
FALSEnever evaluated
column >= columnCount(parent)Description
TRUEnever evaluated
FALSEnever evaluated
0
251 return QModelIndex();
never executed: return QModelIndex();
0
252-
253 // get the parent node-
254 QFileSystemModelPrivate::QFileSystemNode *parentNode = (d->indexValid(parent) ? d->node(parent) :
d->indexValid(parent)Description
TRUEnever evaluated
FALSEnever evaluated
0
255 const_cast<QFileSystemModelPrivate::QFileSystemNode*>(&d->root));-
256 Q_ASSERT(parentNode);-
257-
258 // now get the internal pointer for the index-
259 const QString &childName = parentNode->visibleChildren.at(d->translateVisibleLocation(parentNode, row));-
260 const QFileSystemModelPrivate::QFileSystemNode *indexNode = parentNode->children.value(childName);-
261 Q_ASSERT(indexNode);-
262-
263 return createIndex(row, column, const_cast<QFileSystemModelPrivate::QFileSystemNode*>(indexNode));
never executed: return createIndex(row, column, const_cast<QFileSystemModelPrivate::QFileSystemNode*>(indexNode));
0
264}-
265-
266/*!-
267 \reimp-
268*/-
269QModelIndex QFileSystemModel::sibling(int row, int column, const QModelIndex &idx) const-
270{-
271 if (row == idx.row() && column < QFileSystemModelPrivate::NumColumns) {
row == idx.row()Description
TRUEnever evaluated
FALSEnever evaluated
column < QFile...te::NumColumnsDescription
TRUEnever evaluated
FALSEnever evaluated
0
272 // cheap sibling operation: just adjust the column:-
273 return createIndex(row, column, idx.internalPointer());
never executed: return createIndex(row, column, idx.internalPointer());
0
274 } else {-
275 // for anything else: call the default implementation-
276 // (this could probably be optimized, too):-
277 return QAbstractItemModel::sibling(row, column, idx);
never executed: return QAbstractItemModel::sibling(row, column, idx);
0
278 }-
279}-
280-
281/*!-
282 \overload-
283-
284 Returns the model item index for the given \a path and \a column.-
285*/-
286QModelIndex QFileSystemModel::index(const QString &path, int column) const-
287{-
288 Q_D(const QFileSystemModel);-
289 QFileSystemModelPrivate::QFileSystemNode *node = d->node(path, false);-
290 return d->index(node, column);
never executed: return d->index(node, column);
0
291}-
292-
293/*!-
294 \internal-
295-
296 Return the QFileSystemNode that goes to index.-
297 */-
298QFileSystemModelPrivate::QFileSystemNode *QFileSystemModelPrivate::node(const QModelIndex &index) const-
299{-
300 if (!index.isValid())
!index.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
301 return const_cast<QFileSystemNode*>(&root);
never executed: return const_cast<QFileSystemNode*>(&root);
0
302 QFileSystemModelPrivate::QFileSystemNode *indexNode = static_cast<QFileSystemModelPrivate::QFileSystemNode*>(index.internalPointer());-
303 Q_ASSERT(indexNode);-
304 return indexNode;
never executed: return indexNode;
0
305}-
306-
307#ifdef Q_OS_WIN32-
308static QString qt_GetLongPathName(const QString &strShortPath)-
309{-
310 if (strShortPath.isEmpty()-
311 || strShortPath == QLatin1String(".") || strShortPath == QLatin1String(".."))-
312 return strShortPath;-
313 if (strShortPath.length() == 2 && strShortPath.endsWith(QLatin1Char(':')))-
314 return strShortPath.toUpper();-
315 const QString absPath = QDir(strShortPath).absolutePath();-
316 if (absPath.startsWith(QLatin1String("//"))-
317 || absPath.startsWith(QLatin1String("\\\\"))) // unc-
318 return QDir::fromNativeSeparators(absPath);-
319 if (absPath.startsWith(QLatin1Char('/')))-
320 return QString();-
321 const QString inputString = QLatin1String("\\\\?\\") + QDir::toNativeSeparators(absPath);-
322 QVarLengthArray<TCHAR, MAX_PATH> buffer(MAX_PATH);-
323 DWORD result = ::GetLongPathName((wchar_t*)inputString.utf16(),-
324 buffer.data(),-
325 buffer.size());-
326 if (result > DWORD(buffer.size())) {-
327 buffer.resize(result);-
328 result = ::GetLongPathName((wchar_t*)inputString.utf16(),-
329 buffer.data(),-
330 buffer.size());-
331 }-
332 if (result > 4) {-
333 QString longPath = QString::fromWCharArray(buffer.data() + 4); // ignoring prefix-
334 longPath[0] = longPath.at(0).toUpper(); // capital drive letters-
335 return QDir::fromNativeSeparators(longPath);-
336 } else {-
337 return QDir::fromNativeSeparators(strShortPath);-
338 }-
339}-
340#endif-
341-
342/*!-
343 \internal-
344-
345 Given a path return the matching QFileSystemNode or &root if invalid-
346*/-
347QFileSystemModelPrivate::QFileSystemNode *QFileSystemModelPrivate::node(const QString &path, bool fetch) const-
348{-
349 Q_Q(const QFileSystemModel);-
350 Q_UNUSED(q);-
351 if (path.isEmpty() || path == myComputer() || path.startsWith(QLatin1Char(':')))
path.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
path == myComputer()Description
TRUEnever evaluated
FALSEnever evaluated
path.startsWit...tin1Char(':'))Description
TRUEnever evaluated
FALSEnever evaluated
0
352 return const_cast<QFileSystemModelPrivate::QFileSystemNode*>(&root);
never executed: return const_cast<QFileSystemModelPrivate::QFileSystemNode*>(&root);
0
353-
354 // Construct the nodes up to the new root path if they need to be built-
355 QString absolutePath;-
356#ifdef Q_OS_WIN32-
357 QString longPath = qt_GetLongPathName(path);-
358#else-
359 QString longPath = path;-
360#endif-
361 if (longPath == rootDir.path())
longPath == rootDir.path()Description
TRUEnever evaluated
FALSEnever evaluated
0
362 absolutePath = rootDir.absolutePath();
never executed: absolutePath = rootDir.absolutePath();
0
363 else-
364 absolutePath = QDir(longPath).absolutePath();
never executed: absolutePath = QDir(longPath).absolutePath();
0
365-
366 // ### TODO can we use bool QAbstractFileEngine::caseSensitive() const?-
367 QStringList pathElements = absolutePath.split(QLatin1Char('/'), QString::SkipEmptyParts);-
368 if ((pathElements.isEmpty())
(pathElements.isEmpty())Description
TRUEnever evaluated
FALSEnever evaluated
0
369#if !defined(Q_OS_WIN) || defined(Q_OS_WINCE)-
370 && QDir::fromNativeSeparators(longPath) != QLatin1String("/")
QDir::fromNati...in1String("/")Description
TRUEnever evaluated
FALSEnever evaluated
0
371#endif-
372 )-
373 return const_cast<QFileSystemModelPrivate::QFileSystemNode*>(&root);
never executed: return const_cast<QFileSystemModelPrivate::QFileSystemNode*>(&root);
0
374 QModelIndex index = QModelIndex(); // start with "My Computer"-
375 QString elementPath;-
376 QChar separator = QLatin1Char('/');-
377 QString trailingSeparator;-
378#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE)-
379 if (absolutePath.startsWith(QLatin1String("//"))) { // UNC path-
380 QString host = QLatin1String("\\\\") + pathElements.constFirst();-
381 if (absolutePath == QDir::fromNativeSeparators(host))-
382 absolutePath.append(QLatin1Char('/'));-
383 if (longPath.endsWith(QLatin1Char('/')) && !absolutePath.endsWith(QLatin1Char('/')))-
384 absolutePath.append(QLatin1Char('/'));-
385 if (absolutePath.endsWith(QLatin1Char('/')))-
386 trailingSeparator = QLatin1String("\\");-
387 int r = 0;-
388 QFileSystemModelPrivate::QFileSystemNode *rootNode = const_cast<QFileSystemModelPrivate::QFileSystemNode*>(&root);-
389 if (!root.children.contains(host.toLower())) {-
390 if (pathElements.count() == 1 && !absolutePath.endsWith(QLatin1Char('/')))-
391 return rootNode;-
392 QFileInfo info(host);-
393 if (!info.exists())-
394 return rootNode;-
395 QFileSystemModelPrivate *p = const_cast<QFileSystemModelPrivate*>(this);-
396 p->addNode(rootNode, host,info);-
397 p->addVisibleFiles(rootNode, QStringList(host));-
398 }-
399 r = rootNode->visibleLocation(host);-
400 r = translateVisibleLocation(rootNode, r);-
401 index = q->index(r, 0, QModelIndex());-
402 pathElements.pop_front();-
403 separator = QLatin1Char('\\');-
404 elementPath = host;-
405 elementPath.append(separator);-
406 } else {-
407 if (!pathElements.at(0).contains(QLatin1Char(':'))) {-
408 QString rootPath = QDir(longPath).rootPath();-
409 pathElements.prepend(rootPath);-
410 }-
411 if (pathElements.at(0).endsWith(QLatin1Char('/')))-
412 pathElements[0].chop(1);-
413 }-
414#else-
415 // add the "/" item, since it is a valid path element on Unix-
416 if (absolutePath[0] == QLatin1Char('/'))
absolutePath[0...atin1Char('/')Description
TRUEnever evaluated
FALSEnever evaluated
0
417 pathElements.prepend(QLatin1String("/"));
never executed: pathElements.prepend(QLatin1String("/"));
0
418#endif-
419-
420 QFileSystemModelPrivate::QFileSystemNode *parent = node(index);-
421-
422 for (int i = 0; i < pathElements.count(); ++i) {
i < pathElements.count()Description
TRUEnever evaluated
FALSEnever evaluated
0
423 QString element = pathElements.at(i);-
424 if (i != 0)
i != 0Description
TRUEnever evaluated
FALSEnever evaluated
0
425 elementPath.append(separator);
never executed: elementPath.append(separator);
0
426 elementPath.append(element);-
427 if (i == pathElements.count() - 1)
i == pathElements.count() - 1Description
TRUEnever evaluated
FALSEnever evaluated
0
428 elementPath.append(trailingSeparator);
never executed: elementPath.append(trailingSeparator);
0
429#ifdef Q_OS_WIN-
430 // On Windows, "filename " and "filename" are equivalent and-
431 // "filename . " and "filename" are equivalent-
432 // "filename......." and "filename" are equivalent Task #133928-
433 // whereas "filename .txt" is still "filename .txt"-
434 // If after stripping the characters there is nothing left then we-
435 // just return the parent directory as it is assumed that the path-
436 // is referring to the parent-
437 while (element.endsWith(QLatin1Char('.')) || element.endsWith(QLatin1Char(' ')))-
438 element.chop(1);-
439 // Only filenames that can't possibly exist will be end up being empty-
440 if (element.isEmpty())-
441 return parent;-
442#endif-
443 bool alreadyExisted = parent->children.contains(element);-
444-
445 // we couldn't find the path element, we create a new node since we-
446 // _know_ that the path is valid-
447 if (alreadyExisted) {
alreadyExistedDescription
TRUEnever evaluated
FALSEnever evaluated
0
448 if ((parent->children.count() == 0)
(parent->child....count() == 0)Description
TRUEnever evaluated
FALSEnever evaluated
0
449 || (parent->caseSensitive()
parent->caseSensitive()Description
TRUEnever evaluated
FALSEnever evaluated
0
450 && parent->children.value(element)->fileName != element)
parent->childr...ame != elementDescription
TRUEnever evaluated
FALSEnever evaluated
0
451 || (!parent->caseSensitive()
!parent->caseSensitive()Description
TRUEnever evaluated
FALSEnever evaluated
0
452 && parent->children.value(element)->fileName.toLower() != element.toLower()))
parent->childr...ment.toLower()Description
TRUEnever evaluated
FALSEnever evaluated
0
453 alreadyExisted = false;
never executed: alreadyExisted = false;
0
454 }
never executed: end of block
0
455-
456 QFileSystemModelPrivate::QFileSystemNode *node;-
457 if (!alreadyExisted) {
!alreadyExistedDescription
TRUEnever evaluated
FALSEnever evaluated
0
458 // Someone might call ::index("file://cookie/monster/doesn't/like/veggies"),-
459 // a path that doesn't exists, I.E. don't blindly create directories.-
460 QFileInfo info(elementPath);-
461 if (!info.exists())
!info.exists()Description
TRUEnever evaluated
FALSEnever evaluated
0
462 return const_cast<QFileSystemModelPrivate::QFileSystemNode*>(&root);
never executed: return const_cast<QFileSystemModelPrivate::QFileSystemNode*>(&root);
0
463 QFileSystemModelPrivate *p = const_cast<QFileSystemModelPrivate*>(this);-
464 node = p->addNode(parent, element,info);-
465#ifndef QT_NO_FILESYSTEMWATCHER-
466 node->populate(fileInfoGatherer.getInfo(info));-
467#endif-
468 } else {
never executed: end of block
0
469 node = parent->children.value(element);-
470 }
never executed: end of block
0
471-
472 Q_ASSERT(node);-
473 if (!node->isVisible) {
!node->isVisibleDescription
TRUEnever evaluated
FALSEnever evaluated
0
474 // It has been filtered out-
475 if (alreadyExisted && node->hasInformation() && !fetch)
alreadyExistedDescription
TRUEnever evaluated
FALSEnever evaluated
node->hasInformation()Description
TRUEnever evaluated
FALSEnever evaluated
!fetchDescription
TRUEnever evaluated
FALSEnever evaluated
0
476 return const_cast<QFileSystemModelPrivate::QFileSystemNode*>(&root);
never executed: return const_cast<QFileSystemModelPrivate::QFileSystemNode*>(&root);
0
477-
478 QFileSystemModelPrivate *p = const_cast<QFileSystemModelPrivate*>(this);-
479 p->addVisibleFiles(parent, QStringList(element));-
480 if (!p->bypassFilters.contains(node))
!p->bypassFilt...contains(node)Description
TRUEnever evaluated
FALSEnever evaluated
0
481 p->bypassFilters[node] = 1;
never executed: p->bypassFilters[node] = 1;
0
482 QString dir = q->filePath(this->index(parent));-
483 if (!node->hasInformation() && fetch) {
!node->hasInformation()Description
TRUEnever evaluated
FALSEnever evaluated
fetchDescription
TRUEnever evaluated
FALSEnever evaluated
0
484 Fetching f = { std::move(dir), std::move(element), node };-
485 p->toFetch.append(std::move(f));-
486 p->fetchingTimer.start(0, const_cast<QFileSystemModel*>(q));-
487 }
never executed: end of block
0
488 }
never executed: end of block
0
489 parent = node;-
490 }
never executed: end of block
0
491-
492 return parent;
never executed: return parent;
0
493}-
494-
495/*!-
496 \reimp-
497*/-
498void QFileSystemModel::timerEvent(QTimerEvent *event)-
499{-
500 Q_D(QFileSystemModel);-
501 if (event->timerId() == d->fetchingTimer.timerId()) {
event->timerId...imer.timerId()Description
TRUEnever evaluated
FALSEnever evaluated
0
502 d->fetchingTimer.stop();-
503#ifndef QT_NO_FILESYSTEMWATCHER-
504 for (int i = 0; i < d->toFetch.count(); ++i) {
i < d->toFetch.count()Description
TRUEnever evaluated
FALSEnever evaluated
0
505 const QFileSystemModelPrivate::QFileSystemNode *node = d->toFetch.at(i).node;-
506 if (!node->hasInformation()) {
!node->hasInformation()Description
TRUEnever evaluated
FALSEnever evaluated
0
507 d->fileInfoGatherer.fetchExtendedInformation(d->toFetch.at(i).dir,-
508 QStringList(d->toFetch.at(i).file));-
509 } else {
never executed: end of block
0
510 // qDebug("yah!, you saved a little gerbil soul");-
511 }
never executed: end of block
0
512 }-
513#endif-
514 d->toFetch.clear();-
515 }
never executed: end of block
0
516}
never executed: end of block
0
517-
518/*!-
519 Returns \c true if the model item \a index represents a directory;-
520 otherwise returns \c false.-
521*/-
522bool QFileSystemModel::isDir(const QModelIndex &index) const-
523{-
524 // This function is for public usage only because it could create a file info-
525 Q_D(const QFileSystemModel);-
526 if (!index.isValid())
!index.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
527 return true;
never executed: return true;
0
528 QFileSystemModelPrivate::QFileSystemNode *n = d->node(index);-
529 if (n->hasInformation())
n->hasInformation()Description
TRUEnever evaluated
FALSEnever evaluated
0
530 return n->isDir();
never executed: return n->isDir();
0
531 return fileInfo(index).isDir();
never executed: return fileInfo(index).isDir();
0
532}-
533-
534/*!-
535 Returns the size in bytes of \a index. If the file does not exist, 0 is returned.-
536 */-
537qint64 QFileSystemModel::size(const QModelIndex &index) const-
538{-
539 Q_D(const QFileSystemModel);-
540 if (!index.isValid())
!index.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
541 return 0;
never executed: return 0;
0
542 return d->node(index)->size();
never executed: return d->node(index)->size();
0
543}-
544-
545/*!-
546 Returns the type of file \a index such as "Directory" or "JPEG file".-
547 */-
548QString QFileSystemModel::type(const QModelIndex &index) const-
549{-
550 Q_D(const QFileSystemModel);-
551 if (!index.isValid())
!index.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
552 return QString();
never executed: return QString();
0
553 return d->node(index)->type();
never executed: return d->node(index)->type();
0
554}-
555-
556/*!-
557 Returns the date and time when \a index was last modified.-
558 */-
559QDateTime QFileSystemModel::lastModified(const QModelIndex &index) const-
560{-
561 Q_D(const QFileSystemModel);-
562 if (!index.isValid())
!index.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
563 return QDateTime();
never executed: return QDateTime();
0
564 return d->node(index)->lastModified();
never executed: return d->node(index)->lastModified();
0
565}-
566-
567/*!-
568 \reimp-
569*/-
570QModelIndex QFileSystemModel::parent(const QModelIndex &index) const-
571{-
572 Q_D(const QFileSystemModel);-
573 if (!d->indexValid(index))
!d->indexValid(index)Description
TRUEnever evaluated
FALSEnever evaluated
0
574 return QModelIndex();
never executed: return QModelIndex();
0
575-
576 QFileSystemModelPrivate::QFileSystemNode *indexNode = d->node(index);-
577 Q_ASSERT(indexNode != 0);-
578 QFileSystemModelPrivate::QFileSystemNode *parentNode = indexNode->parent;-
579 if (parentNode == 0 || parentNode == &d->root)
parentNode == 0Description
TRUEnever evaluated
FALSEnever evaluated
parentNode == &d->rootDescription
TRUEnever evaluated
FALSEnever evaluated
0
580 return QModelIndex();
never executed: return QModelIndex();
0
581-
582 // get the parent's row-
583 QFileSystemModelPrivate::QFileSystemNode *grandParentNode = parentNode->parent;-
584 Q_ASSERT(grandParentNode->children.contains(parentNode->fileName));-
585 int visualRow = d->translateVisibleLocation(grandParentNode, grandParentNode->visibleLocation(grandParentNode->children.value(parentNode->fileName)->fileName));-
586 if (visualRow == -1)
visualRow == -1Description
TRUEnever evaluated
FALSEnever evaluated
0
587 return QModelIndex();
never executed: return QModelIndex();
0
588 return createIndex(visualRow, 0, parentNode);
never executed: return createIndex(visualRow, 0, parentNode);
0
589}-
590-
591/*-
592 \internal-
593-
594 return the index for node-
595*/-
596QModelIndex QFileSystemModelPrivate::index(const QFileSystemModelPrivate::QFileSystemNode *node, int column) const-
597{-
598 Q_Q(const QFileSystemModel);-
599 QFileSystemModelPrivate::QFileSystemNode *parentNode = (node ? node->parent : 0);
nodeDescription
TRUEnever evaluated
FALSEnever evaluated
0
600 if (node == &root || !parentNode)
node == &rootDescription
TRUEnever evaluated
FALSEnever evaluated
!parentNodeDescription
TRUEnever evaluated
FALSEnever evaluated
0
601 return QModelIndex();
never executed: return QModelIndex();
0
602-
603 // get the parent's row-
604 Q_ASSERT(node);-
605 if (!node->isVisible)
!node->isVisibleDescription
TRUEnever evaluated
FALSEnever evaluated
0
606 return QModelIndex();
never executed: return QModelIndex();
0
607-
608 int visualRow = translateVisibleLocation(parentNode, parentNode->visibleLocation(node->fileName));-
609 return q->createIndex(visualRow, column, const_cast<QFileSystemNode*>(node));
never executed: return q->createIndex(visualRow, column, const_cast<QFileSystemNode*>(node));
0
610}-
611-
612/*!-
613 \reimp-
614*/-
615bool QFileSystemModel::hasChildren(const QModelIndex &parent) const-
616{-
617 Q_D(const QFileSystemModel);-
618 if (parent.column() > 0)
parent.column() > 0Description
TRUEnever evaluated
FALSEnever evaluated
0
619 return false;
never executed: return false;
0
620-
621 if (!parent.isValid()) // drives
!parent.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
622 return true;
never executed: return true;
0
623-
624 const QFileSystemModelPrivate::QFileSystemNode *indexNode = d->node(parent);-
625 Q_ASSERT(indexNode);-
626 return (indexNode->isDir());
never executed: return (indexNode->isDir());
0
627}-
628-
629/*!-
630 \reimp-
631 */-
632bool QFileSystemModel::canFetchMore(const QModelIndex &parent) const-
633{-
634 Q_D(const QFileSystemModel);-
635 const QFileSystemModelPrivate::QFileSystemNode *indexNode = d->node(parent);-
636 return (!indexNode->populatedChildren);
never executed: return (!indexNode->populatedChildren);
0
637}-
638-
639/*!-
640 \reimp-
641 */-
642void QFileSystemModel::fetchMore(const QModelIndex &parent)-
643{-
644 Q_D(QFileSystemModel);-
645 if (!d->setRootPath)
!d->setRootPathDescription
TRUEnever evaluated
FALSEnever evaluated
0
646 return;
never executed: return;
0
647 QFileSystemModelPrivate::QFileSystemNode *indexNode = d->node(parent);-
648 if (indexNode->populatedChildren)
indexNode->populatedChildrenDescription
TRUEnever evaluated
FALSEnever evaluated
0
649 return;
never executed: return;
0
650 indexNode->populatedChildren = true;-
651#ifndef QT_NO_FILESYSTEMWATCHER-
652 d->fileInfoGatherer.list(filePath(parent));-
653#endif-
654}
never executed: end of block
0
655-
656/*!-
657 \reimp-
658*/-
659int QFileSystemModel::rowCount(const QModelIndex &parent) const-
660{-
661 Q_D(const QFileSystemModel);-
662 if (parent.column() > 0)
parent.column() > 0Description
TRUEnever evaluated
FALSEnever evaluated
0
663 return 0;
never executed: return 0;
0
664-
665 if (!parent.isValid())
!parent.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
666 return d->root.visibleChildren.count();
never executed: return d->root.visibleChildren.count();
0
667-
668 const QFileSystemModelPrivate::QFileSystemNode *parentNode = d->node(parent);-
669 return parentNode->visibleChildren.count();
never executed: return parentNode->visibleChildren.count();
0
670}-
671-
672/*!-
673 \reimp-
674*/-
675int QFileSystemModel::columnCount(const QModelIndex &parent) const-
676{-
677 return (parent.column() > 0) ? 0 : QFileSystemModelPrivate::NumColumns;
never executed: return (parent.column() > 0) ? 0 : QFileSystemModelPrivate::NumColumns;
0
678}-
679-
680/*!-
681 Returns the data stored under the given \a role for the item "My Computer".-
682-
683 \sa Qt::ItemDataRole-
684 */-
685QVariant QFileSystemModel::myComputer(int role) const-
686{-
687#ifndef QT_NO_FILESYSTEMWATCHER-
688 Q_D(const QFileSystemModel);-
689#endif-
690 switch (role) {-
691 case Qt::DisplayRole:
never executed: case Qt::DisplayRole:
0
692 return QFileSystemModelPrivate::myComputer();
never executed: return QFileSystemModelPrivate::myComputer();
0
693#ifndef QT_NO_FILESYSTEMWATCHER-
694 case Qt::DecorationRole:
never executed: case Qt::DecorationRole:
0
695 return d->fileInfoGatherer.iconProvider()->icon(QFileIconProvider::Computer);
never executed: return d->fileInfoGatherer.iconProvider()->icon(QFileIconProvider::Computer);
0
696#endif-
697 }-
698 return QVariant();
never executed: return QVariant();
0
699}-
700-
701/*!-
702 \reimp-
703*/-
704QVariant QFileSystemModel::data(const QModelIndex &index, int role) const-
705{-
706 Q_D(const QFileSystemModel);-
707 if (!index.isValid() || index.model() != this)
!index.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
index.model() != thisDescription
TRUEnever evaluated
FALSEnever evaluated
0
708 return QVariant();
never executed: return QVariant();
0
709-
710 switch (role) {-
711 case Qt::EditRole:
never executed: case Qt::EditRole:
0
712 case Qt::DisplayRole:
never executed: case Qt::DisplayRole:
0
713 switch (index.column()) {-
714 case 0: return d->displayName(index);
never executed: return d->displayName(index);
never executed: case 0:
0
715 case 1: return d->size(index);
never executed: return d->size(index);
never executed: case 1:
0
716 case 2: return d->type(index);
never executed: return d->type(index);
never executed: case 2:
0
717 case 3: return d->time(index);
never executed: return d->time(index);
never executed: case 3:
0
718 default:
never executed: default:
0
719 qWarning("data: invalid display value column %d", index.column());-
720 break;
never executed: break;
0
721 }-
722 break;
never executed: break;
0
723 case FilePathRole:
never executed: case FilePathRole:
0
724 return filePath(index);
never executed: return filePath(index);
0
725 case FileNameRole:
never executed: case FileNameRole:
0
726 return d->name(index);
never executed: return d->name(index);
0
727 case Qt::DecorationRole:
never executed: case Qt::DecorationRole:
0
728 if (index.column() == 0) {
index.column() == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
729 QIcon icon = d->icon(index);-
730#ifndef QT_NO_FILESYSTEMWATCHER-
731 if (icon.isNull()) {
icon.isNull()Description
TRUEnever evaluated
FALSEnever evaluated
0
732 if (d->node(index)->isDir())
d->node(index)->isDir()Description
TRUEnever evaluated
FALSEnever evaluated
0
733 icon = d->fileInfoGatherer.iconProvider()->icon(QFileIconProvider::Folder);
never executed: icon = d->fileInfoGatherer.iconProvider()->icon(QFileIconProvider::Folder);
0
734 else-
735 icon = d->fileInfoGatherer.iconProvider()->icon(QFileIconProvider::File);
never executed: icon = d->fileInfoGatherer.iconProvider()->icon(QFileIconProvider::File);
0
736 }-
737#endif // QT_NO_FILESYSTEMWATCHER-
738 return icon;
never executed: return icon;
0
739 }-
740 break;
never executed: break;
0
741 case Qt::TextAlignmentRole:
never executed: case Qt::TextAlignmentRole:
0
742 if (index.column() == 1)
index.column() == 1Description
TRUEnever evaluated
FALSEnever evaluated
0
743 return Qt::AlignRight;
never executed: return Qt::AlignRight;
0
744 break;
never executed: break;
0
745 case FilePermissions:
never executed: case FilePermissions:
0
746 int p = permissions(index);-
747 return p;
never executed: return p;
0
748 }-
749-
750 return QVariant();
never executed: return QVariant();
0
751}-
752-
753/*!-
754 \internal-
755*/-
756QString QFileSystemModelPrivate::size(const QModelIndex &index) const-
757{-
758 if (!index.isValid())
!index.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
759 return QString();
never executed: return QString();
0
760 const QFileSystemNode *n = node(index);-
761 if (n->isDir()) {
n->isDir()Description
TRUEnever evaluated
FALSEnever evaluated
0
762#ifdef Q_OS_MAC-
763 return QLatin1String("--");-
764#else-
765 return QLatin1String("");
never executed: return QLatin1String("");
0
766#endif-
767 // Windows - ""-
768 // OS X - "--"-
769 // Konqueror - "4 KB"-
770 // Nautilus - "9 items" (the number of children)-
771 }-
772 return size(n->size());
never executed: return size(n->size());
0
773}-
774-
775QString QFileSystemModelPrivate::size(qint64 bytes)-
776{-
777 // According to the Si standard KB is 1000 bytes, KiB is 1024-
778 // but on windows sizes are calculated by dividing by 1024 so we do what they do.-
779 const qint64 kb = 1024;-
780 const qint64 mb = 1024 * kb;-
781 const qint64 gb = 1024 * mb;-
782 const qint64 tb = 1024 * gb;-
783 if (bytes >= tb)
bytes >= tbDescription
TRUEnever evaluated
FALSEnever evaluated
0
784 return QFileSystemModel::tr("%1 TB").arg(QLocale().toString(qreal(bytes) / tb, 'f', 3));
never executed: return QFileSystemModel::tr("%1 TB").arg(QLocale().toString(qreal(bytes) / tb, 'f', 3));
0
785 if (bytes >= gb)
bytes >= gbDescription
TRUEnever evaluated
FALSEnever evaluated
0
786 return QFileSystemModel::tr("%1 GB").arg(QLocale().toString(qreal(bytes) / gb, 'f', 2));
never executed: return QFileSystemModel::tr("%1 GB").arg(QLocale().toString(qreal(bytes) / gb, 'f', 2));
0
787 if (bytes >= mb)
bytes >= mbDescription
TRUEnever evaluated
FALSEnever evaluated
0
788 return QFileSystemModel::tr("%1 MB").arg(QLocale().toString(qreal(bytes) / mb, 'f', 1));
never executed: return QFileSystemModel::tr("%1 MB").arg(QLocale().toString(qreal(bytes) / mb, 'f', 1));
0
789 if (bytes >= kb)
bytes >= kbDescription
TRUEnever evaluated
FALSEnever evaluated
0
790 return QFileSystemModel::tr("%1 KB").arg(QLocale().toString(bytes / kb));
never executed: return QFileSystemModel::tr("%1 KB").arg(QLocale().toString(bytes / kb));
0
791 return QFileSystemModel::tr("%1 bytes").arg(QLocale().toString(bytes));
never executed: return QFileSystemModel::tr("%1 bytes").arg(QLocale().toString(bytes));
0
792}-
793-
794/*!-
795 \internal-
796*/-
797QString QFileSystemModelPrivate::time(const QModelIndex &index) const-
798{-
799 if (!index.isValid())
!index.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
800 return QString();
never executed: return QString();
0
801#ifndef QT_NO_DATESTRING-
802 return node(index)->lastModified().toString(Qt::SystemLocaleDate);
never executed: return node(index)->lastModified().toString(Qt::SystemLocaleDate);
0
803#else-
804 Q_UNUSED(index);-
805 return QString();-
806#endif-
807}-
808-
809/*-
810 \internal-
811*/-
812QString QFileSystemModelPrivate::type(const QModelIndex &index) const-
813{-
814 if (!index.isValid())
!index.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
815 return QString();
never executed: return QString();
0
816 return node(index)->type();
never executed: return node(index)->type();
0
817}-
818-
819/*!-
820 \internal-
821*/-
822QString QFileSystemModelPrivate::name(const QModelIndex &index) const-
823{-
824 if (!index.isValid())
!index.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
825 return QString();
never executed: return QString();
0
826 QFileSystemNode *dirNode = node(index);-
827 if (-
828#ifndef QT_NO_FILESYSTEMWATCHER-
829 fileInfoGatherer.resolveSymlinks() &&
fileInfoGather...olveSymlinks()Description
TRUEnever evaluated
FALSEnever evaluated
0
830#endif-
831 !resolvedSymLinks.isEmpty() && dirNode->isSymLink(/* ignoreNtfsSymLinks = */ true)) {
!resolvedSymLinks.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
dirNode->isSymLink( true)Description
TRUEnever evaluated
FALSEnever evaluated
0
832 QString fullPath = QDir::fromNativeSeparators(filePath(index));-
833 return resolvedSymLinks.value(fullPath, dirNode->fileName);
never executed: return resolvedSymLinks.value(fullPath, dirNode->fileName);
0
834 }-
835 return dirNode->fileName;
never executed: return dirNode->fileName;
0
836}-
837-
838/*!-
839 \internal-
840*/-
841QString QFileSystemModelPrivate::displayName(const QModelIndex &index) const-
842{-
843#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE)-
844 QFileSystemNode *dirNode = node(index);-
845 if (!dirNode->volumeName.isNull())-
846 return dirNode->volumeName + QLatin1String(" (") + name(index) + QLatin1Char(')');-
847#endif-
848 return name(index);
never executed: return name(index);
0
849}-
850-
851/*!-
852 \internal-
853*/-
854QIcon QFileSystemModelPrivate::icon(const QModelIndex &index) const-
855{-
856 if (!index.isValid())
!index.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
857 return QIcon();
never executed: return QIcon();
0
858 return node(index)->icon();
never executed: return node(index)->icon();
0
859}-
860-
861/*!-
862 \reimp-
863*/-
864bool QFileSystemModel::setData(const QModelIndex &idx, const QVariant &value, int role)-
865{-
866 Q_D(QFileSystemModel);-
867 if (!idx.isValid()
!idx.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
868 || idx.column() != 0
idx.column() != 0Description
TRUEnever evaluated
FALSEnever evaluated
0
869 || role != Qt::EditRole
role != Qt::EditRoleDescription
TRUEnever evaluated
FALSEnever evaluated
0
870 || (flags(idx) & Qt::ItemIsEditable) == 0) {
(flags(idx) & ...Editable) == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
871 return false;
never executed: return false;
0
872 }-
873-
874 QString newName = value.toString();-
875 QString oldName = idx.data().toString();-
876 if (newName == idx.data().toString())
newName == idx...a().toString()Description
TRUEnever evaluated
FALSEnever evaluated
0
877 return true;
never executed: return true;
0
878-
879 const QString parentPath = filePath(parent(idx));-
880-
881 if (newName.isEmpty()
newName.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
0
882 || QDir::toNativeSeparators(newName).contains(QDir::separator())
QDir::toNative...::separator())Description
TRUEnever evaluated
FALSEnever evaluated
0
883 || !QDir(parentPath).rename(oldName, newName)) {
!QDir(parentPa...Name, newName)Description
TRUEnever evaluated
FALSEnever evaluated
0
884#ifndef QT_NO_MESSAGEBOX-
885 QMessageBox::information(0, QFileSystemModel::tr("Invalid filename"),-
886 QFileSystemModel::tr("<b>The name \"%1\" can not be used.</b><p>Try using another name, with fewer characters or no punctuations marks.")-
887 .arg(newName),-
888 QMessageBox::Ok);-
889#endif // QT_NO_MESSAGEBOX-
890 return false;
never executed: return false;
0
891 } else {-
892 /*-
893 *After re-naming something we don't want the selection to change*-
894 - can't remove rows and later insert-
895 - can't quickly remove and insert-
896 - index pointer can't change because treeview doesn't use persistant index's-
897-
898 - if this get any more complicated think of changing it to just-
899 use layoutChanged-
900 */-
901-
902 QFileSystemModelPrivate::QFileSystemNode *indexNode = d->node(idx);-
903 QFileSystemModelPrivate::QFileSystemNode *parentNode = indexNode->parent;-
904 int visibleLocation = parentNode->visibleLocation(parentNode->children.value(indexNode->fileName)->fileName);-
905-
906 parentNode->visibleChildren.removeAt(visibleLocation);-
907 QFileSystemModelPrivate::QFileSystemNode * oldValue = parentNode->children.value(oldName);-
908 parentNode->children[newName] = oldValue;-
909 oldValue->fileName = newName;-
910 oldValue->parent = parentNode;-
911#ifndef QT_NO_FILESYSTEMWATCHER-
912 oldValue->populate(d->fileInfoGatherer.getInfo(QFileInfo(parentPath, newName)));-
913#endif-
914 oldValue->isVisible = true;-
915-
916 parentNode->children.remove(oldName);-
917 parentNode->visibleChildren.insert(visibleLocation, newName);-
918-
919 d->delayedSort();-
920 emit fileRenamed(parentPath, oldName, newName);-
921 }
never executed: end of block
0
922 return true;
never executed: return true;
0
923}-
924-
925/*!-
926 \reimp-
927*/-
928QVariant QFileSystemModel::headerData(int section, Qt::Orientation orientation, int role) const-
929{-
930 switch (role) {-
931 case Qt::DecorationRole:
never executed: case Qt::DecorationRole:
0
932 if (section == 0) {
section == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
933 // ### TODO oh man this is ugly and doesn't even work all the way!-
934 // it is still 2 pixels off-
935 QImage pixmap(16, 1, QImage::Format_Mono);-
936 pixmap.fill(0);-
937 pixmap.setAlphaChannel(pixmap.createAlphaMask());-
938 return pixmap;
never executed: return pixmap;
0
939 }-
940 break;
never executed: break;
0
941 case Qt::TextAlignmentRole:
never executed: case Qt::TextAlignmentRole:
0
942 return Qt::AlignLeft;
never executed: return Qt::AlignLeft;
0
943 }-
944-
945 if (orientation != Qt::Horizontal || role != Qt::DisplayRole)
orientation != Qt::HorizontalDescription
TRUEnever evaluated
FALSEnever evaluated
role != Qt::DisplayRoleDescription
TRUEnever evaluated
FALSEnever evaluated
0
946 return QAbstractItemModel::headerData(section, orientation, role);
never executed: return QAbstractItemModel::headerData(section, orientation, role);
0
947-
948 QString returnValue;-
949 switch (section) {-
950 case 0: returnValue = tr("Name");
never executed: case 0:
0
951 break;
never executed: break;
0
952 case 1: returnValue = tr("Size");
never executed: case 1:
0
953 break;
never executed: break;
0
954 case 2: returnValue =
never executed: case 2:
0
955#ifdef Q_OS_MAC-
956 tr("Kind", "Match OS X Finder");-
957#else-
958 tr("Type", "All other platforms");-
959#endif-
960 break;
never executed: break;
0
961 // Windows - Type-
962 // OS X - Kind-
963 // Konqueror - File Type-
964 // Nautilus - Type-
965 case 3: returnValue = tr("Date Modified");
never executed: case 3:
0
966 break;
never executed: break;
0
967 default: return QVariant();
never executed: return QVariant();
never executed: default:
0
968 }-
969 return returnValue;
never executed: return returnValue;
0
970}-
971-
972/*!-
973 \reimp-
974*/-
975Qt::ItemFlags QFileSystemModel::flags(const QModelIndex &index) const-
976{-
977 Q_D(const QFileSystemModel);-
978 Qt::ItemFlags flags = QAbstractItemModel::flags(index);-
979 if (!index.isValid())
!index.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
980 return flags;
never executed: return flags;
0
981-
982 QFileSystemModelPrivate::QFileSystemNode *indexNode = d->node(index);-
983 if (d->nameFilterDisables && !d->passNameFilters(indexNode)) {
d->nameFilterDisablesDescription
TRUEnever evaluated
FALSEnever evaluated
!d->passNameFilters(indexNode)Description
TRUEnever evaluated
FALSEnever evaluated
0
984 flags &= ~Qt::ItemIsEnabled;-
985 // ### TODO you shouldn't be able to set this as the current item, task 119433-
986 return flags;
never executed: return flags;
0
987 }-
988-
989 flags |= Qt::ItemIsDragEnabled;-
990 if (d->readOnly)
d->readOnlyDescription
TRUEnever evaluated
FALSEnever evaluated
0
991 return flags;
never executed: return flags;
0
992 if ((index.column() == 0) && indexNode->permissions() & QFile::WriteUser) {
(index.column() == 0)Description
TRUEnever evaluated
FALSEnever evaluated
indexNode->per...ile::WriteUserDescription
TRUEnever evaluated
FALSEnever evaluated
0
993 flags |= Qt::ItemIsEditable;-
994 if (indexNode->isDir())
indexNode->isDir()Description
TRUEnever evaluated
FALSEnever evaluated
0
995 flags |= Qt::ItemIsDropEnabled;
never executed: flags |= Qt::ItemIsDropEnabled;
0
996 else-
997 flags |= Qt::ItemNeverHasChildren;
never executed: flags |= Qt::ItemNeverHasChildren;
0
998 }-
999 return flags;
never executed: return flags;
0
1000}-
1001-
1002/*!-
1003 \internal-
1004*/-
1005void QFileSystemModelPrivate::_q_performDelayedSort()-
1006{-
1007 Q_Q(QFileSystemModel);-
1008 q->sort(sortColumn, sortOrder);-
1009}
never executed: end of block
0
1010-
1011-
1012/*-
1013 \internal-
1014 Helper functor used by sort()-
1015*/-
1016class QFileSystemModelSorter-
1017{-
1018public:-
1019 inline QFileSystemModelSorter(int column) : sortColumn(column)-
1020 {-
1021 naturalCompare.setNumericMode(true);-
1022 naturalCompare.setCaseSensitivity(Qt::CaseInsensitive);-
1023 }
never executed: end of block
0
1024-
1025 bool compareNodes(const QFileSystemModelPrivate::QFileSystemNode *l,-
1026 const QFileSystemModelPrivate::QFileSystemNode *r) const-
1027 {-
1028 switch (sortColumn) {-
1029 case 0: {
never executed: case 0:
0
1030#ifndef Q_OS_MAC-
1031 // place directories before files-
1032 bool left = l->isDir();-
1033 bool right = r->isDir();-
1034 if (left ^ right)
left ^ rightDescription
TRUEnever evaluated
FALSEnever evaluated
0
1035 return left;
never executed: return left;
0
1036#endif-
1037 return naturalCompare.compare(l->fileName, r->fileName) < 0;
never executed: return naturalCompare.compare(l->fileName, r->fileName) < 0;
0
1038 }-
1039 case 1:
never executed: case 1:
0
1040 {-
1041 // Directories go first-
1042 bool left = l->isDir();-
1043 bool right = r->isDir();-
1044 if (left ^ right)
left ^ rightDescription
TRUEnever evaluated
FALSEnever evaluated
0
1045 return left;
never executed: return left;
0
1046-
1047 qint64 sizeDifference = l->size() - r->size();-
1048 if (sizeDifference == 0)
sizeDifference == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
1049 return naturalCompare.compare(l->fileName, r->fileName) < 0;
never executed: return naturalCompare.compare(l->fileName, r->fileName) < 0;
0
1050-
1051 return sizeDifference < 0;
never executed: return sizeDifference < 0;
0
1052 }-
1053 case 2:
never executed: case 2:
0
1054 {-
1055 int compare = naturalCompare.compare(l->type(), r->type());-
1056 if (compare == 0)
compare == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
1057 return naturalCompare.compare(l->fileName, r->fileName) < 0;
never executed: return naturalCompare.compare(l->fileName, r->fileName) < 0;
0
1058-
1059 return compare < 0;
never executed: return compare < 0;
0
1060 }-
1061 case 3:
never executed: case 3:
0
1062 {-
1063 if (l->lastModified() == r->lastModified())
l->lastModifie...lastModified()Description
TRUEnever evaluated
FALSEnever evaluated
0
1064 return naturalCompare.compare(l->fileName, r->fileName) < 0;
never executed: return naturalCompare.compare(l->fileName, r->fileName) < 0;
0
1065-
1066 return l->lastModified() < r->lastModified();
never executed: return l->lastModified() < r->lastModified();
0
1067 }-
1068 }-
1069 Q_ASSERT(false);-
1070 return false;
never executed: return false;
0
1071 }-
1072-
1073 bool operator()(const QFileSystemModelPrivate::QFileSystemNode *l,-
1074 const QFileSystemModelPrivate::QFileSystemNode *r) const-
1075 {-
1076 return compareNodes(l, r);
never executed: return compareNodes(l, r);
0
1077 }-
1078-
1079-
1080private:-
1081 QCollator naturalCompare;-
1082 int sortColumn;-
1083};-
1084-
1085/*-
1086 \internal-
1087-
1088 Sort all of the children of parent-
1089*/-
1090void QFileSystemModelPrivate::sortChildren(int column, const QModelIndex &parent)-
1091{-
1092 Q_Q(QFileSystemModel);-
1093 QFileSystemModelPrivate::QFileSystemNode *indexNode = node(parent);-
1094 if (indexNode->children.count() == 0)
indexNode->chi...n.count() == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
1095 return;
never executed: return;
0
1096-
1097 QVector<QFileSystemModelPrivate::QFileSystemNode*> values;-
1098 QHash<QString, QFileSystemNode *>::const_iterator iterator;-
1099 for(iterator = indexNode->children.constBegin() ; iterator != indexNode->children.constEnd() ; ++iterator) {
iterator != in...ren.constEnd()Description
TRUEnever evaluated
FALSEnever evaluated
0
1100 if (filtersAcceptsNode(iterator.value())) {
filtersAccepts...rator.value())Description
TRUEnever evaluated
FALSEnever evaluated
0
1101 values.append(iterator.value());-
1102 } else {
never executed: end of block
0
1103 iterator.value()->isVisible = false;-
1104 }
never executed: end of block
0
1105 }-
1106 QFileSystemModelSorter ms(column);-
1107 std::sort(values.begin(), values.end(), ms);-
1108 // First update the new visible list-
1109 indexNode->visibleChildren.clear();-
1110 //No more dirty item we reset our internal dirty index-
1111 indexNode->dirtyChildrenIndex = -1;-
1112 const int numValues = values.count();-
1113 indexNode->visibleChildren.reserve(numValues);-
1114 for (int i = 0; i < numValues; ++i) {
i < numValuesDescription
TRUEnever evaluated
FALSEnever evaluated
0
1115 indexNode->visibleChildren.append(values.at(i)->fileName);-
1116 values.at(i)->isVisible = true;-
1117 }
never executed: end of block
0
1118-
1119 if (!disableRecursiveSort) {
!disableRecursiveSortDescription
TRUEnever evaluated
FALSEnever evaluated
0
1120 for (int i = 0; i < q->rowCount(parent); ++i) {
i < q->rowCount(parent)Description
TRUEnever evaluated
FALSEnever evaluated
0
1121 const QModelIndex childIndex = q->index(i, 0, parent);-
1122 QFileSystemModelPrivate::QFileSystemNode *indexNode = node(childIndex);-
1123 //Only do a recursive sort on visible nodes-
1124 if (indexNode->isVisible)
indexNode->isVisibleDescription
TRUEnever evaluated
FALSEnever evaluated
0
1125 sortChildren(column, childIndex);
never executed: sortChildren(column, childIndex);
0
1126 }
never executed: end of block
0
1127 }
never executed: end of block
0
1128}
never executed: end of block
0
1129-
1130/*!-
1131 \reimp-
1132*/-
1133void QFileSystemModel::sort(int column, Qt::SortOrder order)-
1134{-
1135 Q_D(QFileSystemModel);-
1136 if (d->sortOrder == order && d->sortColumn == column && !d->forceSort)
d->sortOrder == orderDescription
TRUEnever evaluated
FALSEnever evaluated
d->sortColumn == columnDescription
TRUEnever evaluated
FALSEnever evaluated
!d->forceSortDescription
TRUEnever evaluated
FALSEnever evaluated
0
1137 return;
never executed: return;
0
1138-
1139 emit layoutAboutToBeChanged();-
1140 QModelIndexList oldList = persistentIndexList();-
1141 QVector<QPair<QFileSystemModelPrivate::QFileSystemNode*, int> > oldNodes;-
1142 const int nodeCount = oldList.count();-
1143 oldNodes.reserve(nodeCount);-
1144 for (int i = 0; i < nodeCount; ++i) {
i < nodeCountDescription
TRUEnever evaluated
FALSEnever evaluated
0
1145 const QModelIndex &oldNode = oldList.at(i);-
1146 QPair<QFileSystemModelPrivate::QFileSystemNode*, int> pair(d->node(oldNode), oldNode.column());-
1147 oldNodes.append(pair);-
1148 }
never executed: end of block
0
1149-
1150 if (!(d->sortColumn == column && d->sortOrder != order && !d->forceSort)) {
d->sortColumn == columnDescription
TRUEnever evaluated
FALSEnever evaluated
d->sortOrder != orderDescription
TRUEnever evaluated
FALSEnever evaluated
!d->forceSortDescription
TRUEnever evaluated
FALSEnever evaluated
0
1151 //we sort only from where we are, don't need to sort all the model-
1152 d->sortChildren(column, index(rootPath()));-
1153 d->sortColumn = column;-
1154 d->forceSort = false;-
1155 }
never executed: end of block
0
1156 d->sortOrder = order;-
1157-
1158 QModelIndexList newList;-
1159 const int numOldNodes = oldNodes.size();-
1160 newList.reserve(numOldNodes);-
1161 for (int i = 0; i < numOldNodes; ++i) {
i < numOldNodesDescription
TRUEnever evaluated
FALSEnever evaluated
0
1162 const QPair<QFileSystemModelPrivate::QFileSystemNode*, int> &oldNode = oldNodes.at(i);-
1163 newList.append(d->index(oldNode.first, oldNode.second));-
1164 }
never executed: end of block
0
1165 changePersistentIndexList(oldList, newList);-
1166 emit layoutChanged();-
1167}
never executed: end of block
0
1168-
1169/*!-
1170 Returns a list of MIME types that can be used to describe a list of items-
1171 in the model.-
1172*/-
1173QStringList QFileSystemModel::mimeTypes() const-
1174{-
1175 return QStringList(QLatin1String("text/uri-list"));
never executed: return QStringList(QLatin1String("text/uri-list"));
0
1176}-
1177-
1178/*!-
1179 Returns an object that contains a serialized description of the specified-
1180 \a indexes. The format used to describe the items corresponding to the-
1181 indexes is obtained from the mimeTypes() function.-
1182-
1183 If the list of indexes is empty, 0 is returned rather than a serialized-
1184 empty list.-
1185*/-
1186QMimeData *QFileSystemModel::mimeData(const QModelIndexList &indexes) const-
1187{-
1188 QList<QUrl> urls;-
1189 QList<QModelIndex>::const_iterator it = indexes.begin();-
1190 for (; it != indexes.end(); ++it)
it != indexes.end()Description
TRUEnever evaluated
FALSEnever evaluated
0
1191 if ((*it).column() == 0)
(*it).column() == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
1192 urls << QUrl::fromLocalFile(filePath(*it));
never executed: urls << QUrl::fromLocalFile(filePath(*it));
0
1193 QMimeData *data = new QMimeData();-
1194 data->setUrls(urls);-
1195 return data;
never executed: return data;
0
1196}-
1197-
1198/*!-
1199 Handles the \a data supplied by a drag and drop operation that ended with-
1200 the given \a action over the row in the model specified by the \a row and-
1201 \a column and by the \a parent index.-
1202-
1203 \sa supportedDropActions()-
1204*/-
1205bool QFileSystemModel::dropMimeData(const QMimeData *data, Qt::DropAction action,-
1206 int row, int column, const QModelIndex &parent)-
1207{-
1208 Q_UNUSED(row);-
1209 Q_UNUSED(column);-
1210 if (!parent.isValid() || isReadOnly())
!parent.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
isReadOnly()Description
TRUEnever evaluated
FALSEnever evaluated
0
1211 return false;
never executed: return false;
0
1212-
1213 bool success = true;-
1214 QString to = filePath(parent) + QDir::separator();-
1215-
1216 QList<QUrl> urls = data->urls();-
1217 QList<QUrl>::const_iterator it = urls.constBegin();-
1218-
1219 switch (action) {-
1220 case Qt::CopyAction:
never executed: case Qt::CopyAction:
0
1221 for (; it != urls.constEnd(); ++it) {
it != urls.constEnd()Description
TRUEnever evaluated
FALSEnever evaluated
0
1222 QString path = (*it).toLocalFile();-
1223 success = QFile::copy(path, to + QFileInfo(path).fileName()) && success;
QFile::copy(pa...h).fileName())Description
TRUEnever evaluated
FALSEnever evaluated
successDescription
TRUEnever evaluated
FALSEnever evaluated
0
1224 }
never executed: end of block
0
1225 break;
never executed: break;
0
1226 case Qt::LinkAction:
never executed: case Qt::LinkAction:
0
1227 for (; it != urls.constEnd(); ++it) {
it != urls.constEnd()Description
TRUEnever evaluated
FALSEnever evaluated
0
1228 QString path = (*it).toLocalFile();-
1229 success = QFile::link(path, to + QFileInfo(path).fileName()) && success;
QFile::link(pa...h).fileName())Description
TRUEnever evaluated
FALSEnever evaluated
successDescription
TRUEnever evaluated
FALSEnever evaluated
0
1230 }
never executed: end of block
0
1231 break;
never executed: break;
0
1232 case Qt::MoveAction:
never executed: case Qt::MoveAction:
0
1233 for (; it != urls.constEnd(); ++it) {
it != urls.constEnd()Description
TRUEnever evaluated
FALSEnever evaluated
0
1234 QString path = (*it).toLocalFile();-
1235 success = QFile::rename(path, to + QFileInfo(path).fileName()) && success;
QFile::rename(...h).fileName())Description
TRUEnever evaluated
FALSEnever evaluated
successDescription
TRUEnever evaluated
FALSEnever evaluated
0
1236 }
never executed: end of block
0
1237 break;
never executed: break;
0
1238 default:
never executed: default:
0
1239 return false;
never executed: return false;
0
1240 }-
1241-
1242 return success;
never executed: return success;
0
1243}-
1244-
1245/*!-
1246 \reimp-
1247*/-
1248Qt::DropActions QFileSystemModel::supportedDropActions() const-
1249{-
1250 return Qt::CopyAction | Qt::MoveAction | Qt::LinkAction;
never executed: return Qt::CopyAction | Qt::MoveAction | Qt::LinkAction;
0
1251}-
1252-
1253/*!-
1254 Returns the path of the item stored in the model under the-
1255 \a index given.-
1256*/-
1257QString QFileSystemModel::filePath(const QModelIndex &index) const-
1258{-
1259 Q_D(const QFileSystemModel);-
1260 QString fullPath = d->filePath(index);-
1261 QFileSystemModelPrivate::QFileSystemNode *dirNode = d->node(index);-
1262 if (dirNode->isSymLink()
dirNode->isSymLink()Description
TRUEnever evaluated
FALSEnever evaluated
0
1263#ifndef QT_NO_FILESYSTEMWATCHER-
1264 && d->fileInfoGatherer.resolveSymlinks()
d->fileInfoGat...olveSymlinks()Description
TRUEnever evaluated
FALSEnever evaluated
0
1265#endif-
1266 && d->resolvedSymLinks.contains(fullPath)
d->resolvedSym...ains(fullPath)Description
TRUEnever evaluated
FALSEnever evaluated
0
1267 && dirNode->isDir()) {
dirNode->isDir()Description
TRUEnever evaluated
FALSEnever evaluated
0
1268 QFileInfo resolvedInfo(fullPath);-
1269 resolvedInfo = resolvedInfo.canonicalFilePath();-
1270 if (resolvedInfo.exists())
resolvedInfo.exists()Description
TRUEnever evaluated
FALSEnever evaluated
0
1271 return resolvedInfo.filePath();
never executed: return resolvedInfo.filePath();
0
1272 }
never executed: end of block
0
1273 return fullPath;
never executed: return fullPath;
0
1274}-
1275-
1276QString QFileSystemModelPrivate::filePath(const QModelIndex &index) const-
1277{-
1278 Q_Q(const QFileSystemModel);-
1279 Q_UNUSED(q);-
1280 if (!index.isValid())
!index.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
1281 return QString();
never executed: return QString();
0
1282 Q_ASSERT(index.model() == q);-
1283-
1284 QStringList path;-
1285 QModelIndex idx = index;-
1286 while (idx.isValid()) {
idx.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
1287 QFileSystemModelPrivate::QFileSystemNode *dirNode = node(idx);-
1288 if (dirNode)
dirNodeDescription
TRUEnever evaluated
FALSEnever evaluated
0
1289 path.prepend(dirNode->fileName);
never executed: path.prepend(dirNode->fileName);
0
1290 idx = idx.parent();-
1291 }
never executed: end of block
0
1292 QString fullPath = QDir::fromNativeSeparators(path.join(QDir::separator()));-
1293#if !defined(Q_OS_WIN) || defined(Q_OS_WINCE)-
1294 if ((fullPath.length() > 2) && fullPath[0] == QLatin1Char('/') && fullPath[1] == QLatin1Char('/'))
(fullPath.length() > 2)Description
TRUEnever evaluated
FALSEnever evaluated
fullPath[0] ==...atin1Char('/')Description
TRUEnever evaluated
FALSEnever evaluated
fullPath[1] ==...atin1Char('/')Description
TRUEnever evaluated
FALSEnever evaluated
0
1295 fullPath = fullPath.mid(1);
never executed: fullPath = fullPath.mid(1);
0
1296#endif-
1297#if defined(Q_OS_WIN)-
1298 if (fullPath.length() == 2 && fullPath.endsWith(QLatin1Char(':')))-
1299 fullPath.append(QLatin1Char('/'));-
1300#endif-
1301 return fullPath;
never executed: return fullPath;
0
1302}-
1303-
1304/*!-
1305 Create a directory with the \a name in the \a parent model index.-
1306*/-
1307QModelIndex QFileSystemModel::mkdir(const QModelIndex &parent, const QString &name)-
1308{-
1309 Q_D(QFileSystemModel);-
1310 if (!parent.isValid())
!parent.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
1311 return parent;
never executed: return parent;
0
1312-
1313 QDir dir(filePath(parent));-
1314 if (!dir.mkdir(name))
!dir.mkdir(name)Description
TRUEnever evaluated
FALSEnever evaluated
0
1315 return QModelIndex();
never executed: return QModelIndex();
0
1316 QFileSystemModelPrivate::QFileSystemNode *parentNode = d->node(parent);-
1317 d->addNode(parentNode, name, QFileInfo());-
1318 Q_ASSERT(parentNode->children.contains(name));-
1319 QFileSystemModelPrivate::QFileSystemNode *node = parentNode->children[name];-
1320#ifndef QT_NO_FILESYSTEMWATCHER-
1321 node->populate(d->fileInfoGatherer.getInfo(QFileInfo(dir.absolutePath() + QDir::separator() + name)));-
1322#endif-
1323 d->addVisibleFiles(parentNode, QStringList(name));-
1324 return d->index(node);
never executed: return d->index(node);
0
1325}-
1326-
1327/*!-
1328 Returns the complete OR-ed together combination of QFile::Permission for the \a index.-
1329 */-
1330QFile::Permissions QFileSystemModel::permissions(const QModelIndex &index) const-
1331{-
1332 Q_D(const QFileSystemModel);-
1333 return d->node(index)->permissions();
never executed: return d->node(index)->permissions();
0
1334}-
1335-
1336/*!-
1337 Sets the directory that is being watched by the model to \a newPath by-
1338 installing a \l{QFileSystemWatcher}{file system watcher} on it. Any-
1339 changes to files and directories within this directory will be-
1340 reflected in the model.-
1341-
1342 If the path is changed, the rootPathChanged() signal will be emitted.-
1343-
1344 \note This function does not change the structure of the model or-
1345 modify the data available to views. In other words, the "root" of-
1346 the model is \e not changed to include only files and directories-
1347 within the directory specified by \a newPath in the file system.-
1348 */-
1349QModelIndex QFileSystemModel::setRootPath(const QString &newPath)-
1350{-
1351 Q_D(QFileSystemModel);-
1352#ifdef Q_OS_WIN-
1353#ifdef Q_OS_WIN32-
1354 QString longNewPath = qt_GetLongPathName(newPath);-
1355#else-
1356 QString longNewPath = QDir::fromNativeSeparators(newPath);-
1357#endif-
1358#else-
1359 QString longNewPath = newPath;-
1360#endif-
1361 QDir newPathDir(longNewPath);-
1362 //we remove .. and . from the given path if exist-
1363 if (!newPath.isEmpty()) {
!newPath.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
0
1364 longNewPath = QDir::cleanPath(longNewPath);-
1365 newPathDir.setPath(longNewPath);-
1366 }
never executed: end of block
0
1367-
1368 d->setRootPath = true;-
1369-
1370 //user don't ask for the root path ("") but the conversion failed-
1371 if (!newPath.isEmpty() && longNewPath.isEmpty())
!newPath.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
longNewPath.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
0
1372 return d->index(rootPath());
never executed: return d->index(rootPath());
0
1373-
1374 if (d->rootDir.path() == longNewPath)
d->rootDir.pat...== longNewPathDescription
TRUEnever evaluated
FALSEnever evaluated
0
1375 return d->index(rootPath());
never executed: return d->index(rootPath());
0
1376-
1377 bool showDrives = (longNewPath.isEmpty() || longNewPath == d->myComputer());
longNewPath.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
longNewPath == d->myComputer()Description
TRUEnever evaluated
FALSEnever evaluated
0
1378 if (!showDrives && !newPathDir.exists())
!showDrivesDescription
TRUEnever evaluated
FALSEnever evaluated
!newPathDir.exists()Description
TRUEnever evaluated
FALSEnever evaluated
0
1379 return d->index(rootPath());
never executed: return d->index(rootPath());
0
1380-
1381 //We remove the watcher on the previous path-
1382 if (!rootPath().isEmpty() && rootPath() != QLatin1String(".")) {
!rootPath().isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
rootPath() != ...in1String(".")Description
TRUEnever evaluated
FALSEnever evaluated
0
1383 //This remove the watcher for the old rootPath-
1384#ifndef QT_NO_FILESYSTEMWATCHER-
1385 d->fileInfoGatherer.removePath(rootPath());-
1386#endif-
1387 //This line "marks" the node as dirty, so the next fetchMore-
1388 //call on the path will ask the gatherer to install a watcher again-
1389 //But it doesn't re-fetch everything-
1390 d->node(rootPath())->populatedChildren = false;-
1391 }
never executed: end of block
0
1392-
1393 // We have a new valid root path-
1394 d->rootDir = newPathDir;-
1395 QModelIndex newRootIndex;-
1396 if (showDrives) {
showDrivesDescription
TRUEnever evaluated
FALSEnever evaluated
0
1397 // otherwise dir will become '.'-
1398 d->rootDir.setPath(QLatin1String(""));-
1399 } else {
never executed: end of block
0
1400 newRootIndex = d->index(newPathDir.path());-
1401 }
never executed: end of block
0
1402 fetchMore(newRootIndex);-
1403 emit rootPathChanged(longNewPath);-
1404 d->forceSort = true;-
1405 d->delayedSort();-
1406 return newRootIndex;
never executed: return newRootIndex;
0
1407}-
1408-
1409/*!-
1410 The currently set root path-
1411-
1412 \sa rootDirectory()-
1413*/-
1414QString QFileSystemModel::rootPath() const-
1415{-
1416 Q_D(const QFileSystemModel);-
1417 return d->rootDir.path();
never executed: return d->rootDir.path();
0
1418}-
1419-
1420/*!-
1421 The currently set directory-
1422-
1423 \sa rootPath()-
1424*/-
1425QDir QFileSystemModel::rootDirectory() const-
1426{-
1427 Q_D(const QFileSystemModel);-
1428 QDir dir(d->rootDir);-
1429 dir.setNameFilters(nameFilters());-
1430 dir.setFilter(filter());-
1431 return dir;
never executed: return dir;
0
1432}-
1433-
1434/*!-
1435 Sets the \a provider of file icons for the directory model.-
1436*/-
1437void QFileSystemModel::setIconProvider(QFileIconProvider *provider)-
1438{-
1439 Q_D(QFileSystemModel);-
1440#ifndef QT_NO_FILESYSTEMWATCHER-
1441 d->fileInfoGatherer.setIconProvider(provider);-
1442#endif-
1443 d->root.updateIcon(provider, QString());-
1444}
never executed: end of block
0
1445-
1446/*!-
1447 Returns the file icon provider for this directory model.-
1448*/-
1449QFileIconProvider *QFileSystemModel::iconProvider() const-
1450{-
1451#ifndef QT_NO_FILESYSTEMWATCHER-
1452 Q_D(const QFileSystemModel);-
1453 return d->fileInfoGatherer.iconProvider();
never executed: return d->fileInfoGatherer.iconProvider();
0
1454#else-
1455 return 0;-
1456#endif-
1457}-
1458-
1459/*!-
1460 Sets the directory model's filter to that specified by \a filters.-
1461-
1462 Note that the filter you set should always include the QDir::AllDirs enum value,-
1463 otherwise QFileSystemModel won't be able to read the directory structure.-
1464-
1465 \sa QDir::Filters-
1466*/-
1467void QFileSystemModel::setFilter(QDir::Filters filters)-
1468{-
1469 Q_D(QFileSystemModel);-
1470 if (d->filters == filters)
d->filters == filtersDescription
TRUEnever evaluated
FALSEnever evaluated
0
1471 return;
never executed: return;
0
1472 d->filters = filters;-
1473 // CaseSensitivity might have changed-
1474 setNameFilters(nameFilters());-
1475 d->forceSort = true;-
1476 d->delayedSort();-
1477}
never executed: end of block
0
1478-
1479/*!-
1480 Returns the filter specified for the directory model.-
1481-
1482 If a filter has not been set, the default filter is QDir::AllEntries |-
1483 QDir::NoDotAndDotDot | QDir::AllDirs.-
1484-
1485 \sa QDir::Filters-
1486*/-
1487QDir::Filters QFileSystemModel::filter() const-
1488{-
1489 Q_D(const QFileSystemModel);-
1490 return d->filters;
never executed: return d->filters;
0
1491}-
1492-
1493/*!-
1494 \property QFileSystemModel::resolveSymlinks-
1495 \brief Whether the directory model should resolve symbolic links-
1496-
1497 This is only relevant on Windows.-
1498-
1499 By default, this property is \c true.-
1500*/-
1501void QFileSystemModel::setResolveSymlinks(bool enable)-
1502{-
1503#ifndef QT_NO_FILESYSTEMWATCHER-
1504 Q_D(QFileSystemModel);-
1505 d->fileInfoGatherer.setResolveSymlinks(enable);-
1506#else-
1507 Q_UNUSED(enable)-
1508#endif-
1509}
never executed: end of block
0
1510-
1511bool QFileSystemModel::resolveSymlinks() const-
1512{-
1513#ifndef QT_NO_FILESYSTEMWATCHER-
1514 Q_D(const QFileSystemModel);-
1515 return d->fileInfoGatherer.resolveSymlinks();
never executed: return d->fileInfoGatherer.resolveSymlinks();
0
1516#else-
1517 return false;-
1518#endif-
1519}-
1520-
1521/*!-
1522 \property QFileSystemModel::readOnly-
1523 \brief Whether the directory model allows writing to the file system-
1524-
1525 If this property is set to false, the directory model will allow renaming, copying-
1526 and deleting of files and directories.-
1527-
1528 This property is \c true by default-
1529*/-
1530void QFileSystemModel::setReadOnly(bool enable)-
1531{-
1532 Q_D(QFileSystemModel);-
1533 d->readOnly = enable;-
1534}
never executed: end of block
0
1535-
1536bool QFileSystemModel::isReadOnly() const-
1537{-
1538 Q_D(const QFileSystemModel);-
1539 return d->readOnly;
never executed: return d->readOnly;
0
1540}-
1541-
1542/*!-
1543 \property QFileSystemModel::nameFilterDisables-
1544 \brief Whether files that don't pass the name filter are hidden or disabled-
1545-
1546 This property is \c true by default-
1547*/-
1548void QFileSystemModel::setNameFilterDisables(bool enable)-
1549{-
1550 Q_D(QFileSystemModel);-
1551 if (d->nameFilterDisables == enable)
d->nameFilterD...bles == enableDescription
TRUEnever evaluated
FALSEnever evaluated
0
1552 return;
never executed: return;
0
1553 d->nameFilterDisables = enable;-
1554 d->forceSort = true;-
1555 d->delayedSort();-
1556}
never executed: end of block
0
1557-
1558bool QFileSystemModel::nameFilterDisables() const-
1559{-
1560 Q_D(const QFileSystemModel);-
1561 return d->nameFilterDisables;
never executed: return d->nameFilterDisables;
0
1562}-
1563-
1564/*!-
1565 Sets the name \a filters to apply against the existing files.-
1566*/-
1567void QFileSystemModel::setNameFilters(const QStringList &filters)-
1568{-
1569 // Prep the regexp's ahead of time-
1570#ifndef QT_NO_REGEXP-
1571 Q_D(QFileSystemModel);-
1572-
1573 if (!d->bypassFilters.isEmpty()) {
!d->bypassFilters.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
0
1574 // update the bypass filter to only bypass the stuff that must be kept around-
1575 d->bypassFilters.clear();-
1576 // We guarantee that rootPath will stick around-
1577 QPersistentModelIndex root(index(rootPath()));-
1578 const QModelIndexList persistentList = persistentIndexList();-
1579 for (const auto &persistentIndex : persistentList) {-
1580 QFileSystemModelPrivate::QFileSystemNode *node = d->node(persistentIndex);-
1581 while (node) {
nodeDescription
TRUEnever evaluated
FALSEnever evaluated
0
1582 if (d->bypassFilters.contains(node))
d->bypassFilte...contains(node)Description
TRUEnever evaluated
FALSEnever evaluated
0
1583 break;
never executed: break;
0
1584 if (node->isDir())
node->isDir()Description
TRUEnever evaluated
FALSEnever evaluated
0
1585 d->bypassFilters[node] = true;
never executed: d->bypassFilters[node] = true;
0
1586 node = node->parent;-
1587 }
never executed: end of block
0
1588 }
never executed: end of block
0
1589 }
never executed: end of block
0
1590-
1591 d->nameFilters.clear();-
1592 const Qt::CaseSensitivity caseSensitive =-
1593 (filter() & QDir::CaseSensitive) ? Qt::CaseSensitive : Qt::CaseInsensitive;
(filter() & QD...CaseSensitive)Description
TRUEnever evaluated
FALSEnever evaluated
0
1594 for (const auto &filter : filters)-
1595 d->nameFilters << QRegExp(filter, caseSensitive, QRegExp::Wildcard);
never executed: d->nameFilters << QRegExp(filter, caseSensitive, QRegExp::Wildcard);
0
1596 d->forceSort = true;-
1597 d->delayedSort();-
1598#endif-
1599}
never executed: end of block
0
1600-
1601/*!-
1602 Returns a list of filters applied to the names in the model.-
1603*/-
1604QStringList QFileSystemModel::nameFilters() const-
1605{-
1606 Q_D(const QFileSystemModel);-
1607 QStringList filters;-
1608#ifndef QT_NO_REGEXP-
1609 const int numNameFilters = d->nameFilters.size();-
1610 filters.reserve(numNameFilters);-
1611 for (int i = 0; i < numNameFilters; ++i) {
i < numNameFiltersDescription
TRUEnever evaluated
FALSEnever evaluated
0
1612 filters << d->nameFilters.at(i).pattern();-
1613 }
never executed: end of block
0
1614#endif-
1615 return filters;
never executed: return filters;
0
1616}-
1617-
1618/*!-
1619 \reimp-
1620*/-
1621bool QFileSystemModel::event(QEvent *event)-
1622{-
1623#ifndef QT_NO_FILESYSTEMWATCHER-
1624 Q_D(QFileSystemModel);-
1625 if (event->type() == QEvent::LanguageChange) {
event->type() ...LanguageChangeDescription
TRUEnever evaluated
FALSEnever evaluated
0
1626 d->root.retranslateStrings(d->fileInfoGatherer.iconProvider(), QString());-
1627 return true;
never executed: return true;
0
1628 }-
1629#endif-
1630 return QAbstractItemModel::event(event);
never executed: return QAbstractItemModel::event(event);
0
1631}-
1632-
1633bool QFileSystemModel::rmdir(const QModelIndex &aindex)-
1634{-
1635 QString path = filePath(aindex);-
1636 const bool success = QDir().rmdir(path);-
1637#ifndef QT_NO_FILESYSTEMWATCHER-
1638 if (success) {
successDescription
TRUEnever evaluated
FALSEnever evaluated
0
1639 QFileSystemModelPrivate * d = const_cast<QFileSystemModelPrivate*>(d_func());-
1640 d->fileInfoGatherer.removePath(path);-
1641 }
never executed: end of block
0
1642#endif-
1643 return success;
never executed: return success;
0
1644}-
1645-
1646/*!-
1647 \internal-
1648-
1649 Performed quick listing and see if any files have been added or removed,-
1650 then fetch more information on visible files.-
1651 */-
1652void QFileSystemModelPrivate::_q_directoryChanged(const QString &directory, const QStringList &files)-
1653{-
1654 QFileSystemModelPrivate::QFileSystemNode *parentNode = node(directory, false);-
1655 if (parentNode->children.count() == 0)
parentNode->ch...n.count() == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
1656 return;
never executed: return;
0
1657 QStringList toRemove;-
1658 QStringList newFiles = files;-
1659 std::sort(newFiles.begin(), newFiles.end());-
1660 QHash<QString, QFileSystemNode*>::const_iterator i = parentNode->children.constBegin();-
1661 while (i != parentNode->children.constEnd()) {
i != parentNod...ren.constEnd()Description
TRUEnever evaluated
FALSEnever evaluated
0
1662 QStringList::iterator iterator = std::lower_bound(newFiles.begin(), newFiles.end(), i.value()->fileName);-
1663 if ((iterator == newFiles.end()) || (i.value()->fileName < *iterator))
(iterator == newFiles.end())Description
TRUEnever evaluated
FALSEnever evaluated
(i.value()->fi...e < *iterator)Description
TRUEnever evaluated
FALSEnever evaluated
0
1664 toRemove.append(i.value()->fileName);
never executed: toRemove.append(i.value()->fileName);
0
1665-
1666 ++i;-
1667 }
never executed: end of block
0
1668 for (int i = 0 ; i < toRemove.count() ; ++i )
i < toRemove.count()Description
TRUEnever evaluated
FALSEnever evaluated
0
1669 removeNode(parentNode, toRemove[i]);
never executed: removeNode(parentNode, toRemove[i]);
0
1670}
never executed: end of block
0
1671-
1672/*!-
1673 \internal-
1674-
1675 Adds a new file to the children of parentNode-
1676-
1677 *WARNING* this will change the count of children-
1678*/-
1679QFileSystemModelPrivate::QFileSystemNode* QFileSystemModelPrivate::addNode(QFileSystemNode *parentNode, const QString &fileName, const QFileInfo& info)-
1680{-
1681 // In the common case, itemLocation == count() so check there first-
1682 QFileSystemModelPrivate::QFileSystemNode *node = new QFileSystemModelPrivate::QFileSystemNode(fileName, parentNode);-
1683#ifndef QT_NO_FILESYSTEMWATCHER-
1684 node->populate(info);-
1685#else-
1686 Q_UNUSED(info)-
1687#endif-
1688#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) && !defined(Q_OS_WINRT)-
1689 //The parentNode is "" so we are listing the drives-
1690 if (parentNode->fileName.isEmpty()) {-
1691 wchar_t name[MAX_PATH + 1];-
1692 //GetVolumeInformation requires to add trailing backslash-
1693 const QString nodeName = fileName + QLatin1String("\\");-
1694 BOOL success = ::GetVolumeInformation((wchar_t *)(nodeName.utf16()),-
1695 name, MAX_PATH + 1, NULL, 0, NULL, NULL, 0);-
1696 if (success && name[0])-
1697 node->volumeName = QString::fromWCharArray(name);-
1698 }-
1699#endif-
1700 parentNode->children.insert(fileName, node);-
1701 return node;
never executed: return node;
0
1702}-
1703-
1704/*!-
1705 \internal-
1706-
1707 File at parentNode->children(itemLocation) has been removed, remove from the lists-
1708 and emit signals if necessary-
1709-
1710 *WARNING* this will change the count of children and could change visibleChildren-
1711 */-
1712void QFileSystemModelPrivate::removeNode(QFileSystemModelPrivate::QFileSystemNode *parentNode, const QString& name)-
1713{-
1714 Q_Q(QFileSystemModel);-
1715 QModelIndex parent = index(parentNode);-
1716 bool indexHidden = isHiddenByFilter(parentNode, parent);-
1717-
1718 int vLocation = parentNode->visibleLocation(name);-
1719 if (vLocation >= 0 && !indexHidden)
vLocation >= 0Description
TRUEnever evaluated
FALSEnever evaluated
!indexHiddenDescription
TRUEnever evaluated
FALSEnever evaluated
0
1720 q->beginRemoveRows(parent, translateVisibleLocation(parentNode, vLocation),
never executed: q->beginRemoveRows(parent, translateVisibleLocation(parentNode, vLocation), translateVisibleLocation(parentNode, vLocation));
0
1721 translateVisibleLocation(parentNode, vLocation));
never executed: q->beginRemoveRows(parent, translateVisibleLocation(parentNode, vLocation), translateVisibleLocation(parentNode, vLocation));
0
1722 QFileSystemNode * node = parentNode->children.take(name);-
1723 delete node;-
1724 // cleanup sort files after removing rather then re-sorting which is O(n)-
1725 if (vLocation >= 0)
vLocation >= 0Description
TRUEnever evaluated
FALSEnever evaluated
0
1726 parentNode->visibleChildren.removeAt(vLocation);
never executed: parentNode->visibleChildren.removeAt(vLocation);
0
1727 if (vLocation >= 0 && !indexHidden)
vLocation >= 0Description
TRUEnever evaluated
FALSEnever evaluated
!indexHiddenDescription
TRUEnever evaluated
FALSEnever evaluated
0
1728 q->endRemoveRows();
never executed: q->endRemoveRows();
0
1729}
never executed: end of block
0
1730-
1731/*!-
1732 \internal-
1733-
1734 File at parentNode->children(itemLocation) was not visible before, but now should be-
1735 and emit signals if necessary.-
1736-
1737 *WARNING* this will change the visible count-
1738 */-
1739void QFileSystemModelPrivate::addVisibleFiles(QFileSystemNode *parentNode, const QStringList &newFiles)-
1740{-
1741 Q_Q(QFileSystemModel);-
1742 QModelIndex parent = index(parentNode);-
1743 bool indexHidden = isHiddenByFilter(parentNode, parent);-
1744 if (!indexHidden) {
!indexHiddenDescription
TRUEnever evaluated
FALSEnever evaluated
0
1745 q->beginInsertRows(parent, parentNode->visibleChildren.count() , parentNode->visibleChildren.count() + newFiles.count() - 1);-
1746 }
never executed: end of block
0
1747-
1748 if (parentNode->dirtyChildrenIndex == -1)
parentNode->di...renIndex == -1Description
TRUEnever evaluated
FALSEnever evaluated
0
1749 parentNode->dirtyChildrenIndex = parentNode->visibleChildren.count();
never executed: parentNode->dirtyChildrenIndex = parentNode->visibleChildren.count();
0
1750-
1751 for (const auto &newFile : newFiles) {-
1752 parentNode->visibleChildren.append(newFile);-
1753 parentNode->children.value(newFile)->isVisible = true;-
1754 }
never executed: end of block
0
1755 if (!indexHidden)
!indexHiddenDescription
TRUEnever evaluated
FALSEnever evaluated
0
1756 q->endInsertRows();
never executed: q->endInsertRows();
0
1757}
never executed: end of block
0
1758-
1759/*!-
1760 \internal-
1761-
1762 File was visible before, but now should NOT be-
1763-
1764 *WARNING* this will change the visible count-
1765 */-
1766void QFileSystemModelPrivate::removeVisibleFile(QFileSystemNode *parentNode, int vLocation)-
1767{-
1768 Q_Q(QFileSystemModel);-
1769 if (vLocation == -1)
vLocation == -1Description
TRUEnever evaluated
FALSEnever evaluated
0
1770 return;
never executed: return;
0
1771 QModelIndex parent = index(parentNode);-
1772 bool indexHidden = isHiddenByFilter(parentNode, parent);-
1773 if (!indexHidden)
!indexHiddenDescription
TRUEnever evaluated
FALSEnever evaluated
0
1774 q->beginRemoveRows(parent, translateVisibleLocation(parentNode, vLocation),
never executed: q->beginRemoveRows(parent, translateVisibleLocation(parentNode, vLocation), translateVisibleLocation(parentNode, vLocation));
0
1775 translateVisibleLocation(parentNode, vLocation));
never executed: q->beginRemoveRows(parent, translateVisibleLocation(parentNode, vLocation), translateVisibleLocation(parentNode, vLocation));
0
1776 parentNode->children.value(parentNode->visibleChildren.at(vLocation))->isVisible = false;-
1777 parentNode->visibleChildren.removeAt(vLocation);-
1778 if (!indexHidden)
!indexHiddenDescription
TRUEnever evaluated
FALSEnever evaluated
0
1779 q->endRemoveRows();
never executed: q->endRemoveRows();
0
1780}
never executed: end of block
0
1781-
1782/*!-
1783 \internal-
1784-
1785 The thread has received new information about files,-
1786 update and emit dataChanged if it has actually changed.-
1787 */-
1788void QFileSystemModelPrivate::_q_fileSystemChanged(const QString &path, const QVector<QPair<QString, QFileInfo> > &updates)-
1789{-
1790#ifndef QT_NO_FILESYSTEMWATCHER-
1791 Q_Q(QFileSystemModel);-
1792 QVector<QString> rowsToUpdate;-
1793 QStringList newFiles;-
1794 QFileSystemModelPrivate::QFileSystemNode *parentNode = node(path, false);-
1795 QModelIndex parentIndex = index(parentNode);-
1796 for (const auto &update : updates) {-
1797 QString fileName = update.first;-
1798 Q_ASSERT(!fileName.isEmpty());-
1799 QExtendedInformation info = fileInfoGatherer.getInfo(update.second);-
1800 bool previouslyHere = parentNode->children.contains(fileName);-
1801 if (!previouslyHere) {
!previouslyHereDescription
TRUEnever evaluated
FALSEnever evaluated
0
1802 addNode(parentNode, fileName, info.fileInfo());-
1803 }
never executed: end of block
0
1804 QFileSystemModelPrivate::QFileSystemNode * node = parentNode->children.value(fileName);-
1805 bool isCaseSensitive = parentNode->caseSensitive();-
1806 if (isCaseSensitive) {
isCaseSensitiveDescription
TRUEnever evaluated
FALSEnever evaluated
0
1807 if (node->fileName != fileName)
node->fileName != fileNameDescription
TRUEnever evaluated
FALSEnever evaluated
0
1808 continue;
never executed: continue;
0
1809 } else {
never executed: end of block
0
1810 if (QString::compare(node->fileName,fileName,Qt::CaseInsensitive) != 0)
QString::compa...ensitive) != 0Description
TRUEnever evaluated
FALSEnever evaluated
0
1811 continue;
never executed: continue;
0
1812 }
never executed: end of block
0
1813 if (isCaseSensitive) {
isCaseSensitiveDescription
TRUEnever evaluated
FALSEnever evaluated
0
1814 Q_ASSERT(node->fileName == fileName);-
1815 } else {
never executed: end of block
0
1816 node->fileName = fileName;-
1817 }
never executed: end of block
0
1818-
1819 if (*node != info ) {
*node != infoDescription
TRUEnever evaluated
FALSEnever evaluated
0
1820 node->populate(info);-
1821 bypassFilters.remove(node);-
1822 // brand new information.-
1823 if (filtersAcceptsNode(node)) {
filtersAcceptsNode(node)Description
TRUEnever evaluated
FALSEnever evaluated
0
1824 if (!node->isVisible) {
!node->isVisibleDescription
TRUEnever evaluated
FALSEnever evaluated
0
1825 newFiles.append(fileName);-
1826 } else {
never executed: end of block
0
1827 rowsToUpdate.append(fileName);-
1828 }
never executed: end of block
0
1829 } else {-
1830 if (node->isVisible) {
node->isVisibleDescription
TRUEnever evaluated
FALSEnever evaluated
0
1831 int visibleLocation = parentNode->visibleLocation(fileName);-
1832 removeVisibleFile(parentNode, visibleLocation);-
1833 } else {
never executed: end of block
0
1834 // The file is not visible, don't do anything-
1835 }
never executed: end of block
0
1836 }-
1837 }-
1838 }
never executed: end of block
0
1839-
1840 // bundle up all of the changed signals into as few as possible.-
1841 std::sort(rowsToUpdate.begin(), rowsToUpdate.end());-
1842 QString min;-
1843 QString max;-
1844 for (int i = 0; i < rowsToUpdate.count(); ++i) {
i < rowsToUpdate.count()Description
TRUEnever evaluated
FALSEnever evaluated
0
1845 QString value = rowsToUpdate.at(i);-
1846 //##TODO is there a way to bundle signals with QString as the content of the list?-
1847 /*if (min.isEmpty()) {-
1848 min = value;-
1849 if (i != rowsToUpdate.count() - 1)-
1850 continue;-
1851 }-
1852 if (i != rowsToUpdate.count() - 1) {-
1853 if ((value == min + 1 && max.isEmpty()) || value == max + 1) {-
1854 max = value;-
1855 continue;-
1856 }-
1857 }*/-
1858 max = value;-
1859 min = value;-
1860 int visibleMin = parentNode->visibleLocation(min);-
1861 int visibleMax = parentNode->visibleLocation(max);-
1862 if (visibleMin >= 0
visibleMin >= 0Description
TRUEnever evaluated
FALSEnever evaluated
0
1863 && visibleMin < parentNode->visibleChildren.count()
visibleMin < p...ildren.count()Description
TRUEnever evaluated
FALSEnever evaluated
0
1864 && parentNode->visibleChildren.at(visibleMin) == min
parentNode->vi...bleMin) == minDescription
TRUEnever evaluated
FALSEnever evaluated
0
1865 && visibleMax >= 0) {
visibleMax >= 0Description
TRUEnever evaluated
FALSEnever evaluated
0
1866 QModelIndex bottom = q->index(translateVisibleLocation(parentNode, visibleMin), 0, parentIndex);-
1867 QModelIndex top = q->index(translateVisibleLocation(parentNode, visibleMax), 3, parentIndex);-
1868 emit q->dataChanged(bottom, top);-
1869 }
never executed: end of block
0
1870-
1871 /*min = QString();-
1872 max = QString();*/-
1873 }
never executed: end of block
0
1874-
1875 if (newFiles.count() > 0) {
newFiles.count() > 0Description
TRUEnever evaluated
FALSEnever evaluated
0
1876 addVisibleFiles(parentNode, newFiles);-
1877 }
never executed: end of block
0
1878-
1879 if (newFiles.count() > 0 || (sortColumn != 0 && rowsToUpdate.count() > 0)) {
newFiles.count() > 0Description
TRUEnever evaluated
FALSEnever evaluated
sortColumn != 0Description
TRUEnever evaluated
FALSEnever evaluated
rowsToUpdate.count() > 0Description
TRUEnever evaluated
FALSEnever evaluated
0
1880 forceSort = true;-
1881 delayedSort();-
1882 }
never executed: end of block
0
1883#else-
1884 Q_UNUSED(path)-
1885 Q_UNUSED(updates)-
1886#endif // !QT_NO_FILESYSTEMWATCHER-
1887}
never executed: end of block
0
1888-
1889/*!-
1890 \internal-
1891*/-
1892void QFileSystemModelPrivate::_q_resolvedName(const QString &fileName, const QString &resolvedName)-
1893{-
1894 resolvedSymLinks[fileName] = resolvedName;-
1895}
never executed: end of block
0
1896-
1897/*!-
1898 \internal-
1899*/-
1900void QFileSystemModelPrivate::init()-
1901{-
1902 Q_Q(QFileSystemModel);-
1903 qRegisterMetaType<QVector<QPair<QString,QFileInfo> > >();-
1904#ifndef QT_NO_FILESYSTEMWATCHER-
1905 q->connect(&fileInfoGatherer, SIGNAL(newListOfFiles(QString,QStringList)),-
1906 q, SLOT(_q_directoryChanged(QString,QStringList)));-
1907 q->connect(&fileInfoGatherer, SIGNAL(updates(QString,QVector<QPair<QString,QFileInfo> >)),-
1908 q, SLOT(_q_fileSystemChanged(QString,QVector<QPair<QString,QFileInfo> >)));-
1909 q->connect(&fileInfoGatherer, SIGNAL(nameResolved(QString,QString)),-
1910 q, SLOT(_q_resolvedName(QString,QString)));-
1911 q->connect(&fileInfoGatherer, SIGNAL(directoryLoaded(QString)),-
1912 q, SIGNAL(directoryLoaded(QString)));-
1913#endif // !QT_NO_FILESYSTEMWATCHER-
1914 q->connect(&delayedSortTimer, SIGNAL(timeout()), q, SLOT(_q_performDelayedSort()), Qt::QueuedConnection);-
1915-
1916 roleNames.insertMulti(QFileSystemModel::FileIconRole, QByteArrayLiteral("fileIcon")); // == Qt::decoration
never executed: return ba;
0
1917 roleNames.insert(QFileSystemModel::FilePathRole, QByteArrayLiteral("filePath"));
never executed: return ba;
0
1918 roleNames.insert(QFileSystemModel::FileNameRole, QByteArrayLiteral("fileName"));
never executed: return ba;
0
1919 roleNames.insert(QFileSystemModel::FilePermissions, QByteArrayLiteral("filePermissions"));
never executed: return ba;
0
1920}
never executed: end of block
0
1921-
1922/*!-
1923 \internal-
1924-
1925 Returns \c false if node doesn't pass the filters otherwise true-
1926-
1927 QDir::Modified is not supported-
1928 QDir::Drives is not supported-
1929*/-
1930bool QFileSystemModelPrivate::filtersAcceptsNode(const QFileSystemNode *node) const-
1931{-
1932 // always accept drives-
1933 if (node->parent == &root || bypassFilters.contains(node))
node->parent == &rootDescription
TRUEnever evaluated
FALSEnever evaluated
bypassFilters.contains(node)Description
TRUEnever evaluated
FALSEnever evaluated
0
1934 return true;
never executed: return true;
0
1935-
1936 // If we don't know anything yet don't accept it-
1937 if (!node->hasInformation())
!node->hasInformation()Description
TRUEnever evaluated
FALSEnever evaluated
0
1938 return false;
never executed: return false;
0
1939-
1940 const bool filterPermissions = ((filters & QDir::PermissionMask)
(filters & QDi...ermissionMask)Description
TRUEnever evaluated
FALSEnever evaluated
0
1941 && (filters & QDir::PermissionMask) != QDir::PermissionMask);
(filters & QDi...PermissionMaskDescription
TRUEnever evaluated
FALSEnever evaluated
0
1942 const bool hideDirs = !(filters & (QDir::Dirs | QDir::AllDirs));-
1943 const bool hideFiles = !(filters & QDir::Files);-
1944 const bool hideReadable = !(!filterPermissions || (filters & QDir::Readable));
!filterPermissionsDescription
TRUEnever evaluated
FALSEnever evaluated
(filters & QDir::Readable)Description
TRUEnever evaluated
FALSEnever evaluated
0
1945 const bool hideWritable = !(!filterPermissions || (filters & QDir::Writable));
!filterPermissionsDescription
TRUEnever evaluated
FALSEnever evaluated
(filters & QDir::Writable)Description
TRUEnever evaluated
FALSEnever evaluated
0
1946 const bool hideExecutable = !(!filterPermissions || (filters & QDir::Executable));
!filterPermissionsDescription
TRUEnever evaluated
FALSEnever evaluated
(filters & QDir::Executable)Description
TRUEnever evaluated
FALSEnever evaluated
0
1947 const bool hideHidden = !(filters & QDir::Hidden);-
1948 const bool hideSystem = !(filters & QDir::System);-
1949 const bool hideSymlinks = (filters & QDir::NoSymLinks);-
1950 const bool hideDot = (filters & QDir::NoDot);-
1951 const bool hideDotDot = (filters & QDir::NoDotDot);-
1952-
1953 // Note that we match the behavior of entryList and not QFileInfo on this.-
1954 bool isDot = (node->fileName == QLatin1String("."));-
1955 bool isDotDot = (node->fileName == QLatin1String(".."));-
1956 if ( (hideHidden && !(isDot || isDotDot) && node->isHidden())
hideHiddenDescription
TRUEnever evaluated
FALSEnever evaluated
isDotDescription
TRUEnever evaluated
FALSEnever evaluated
isDotDotDescription
TRUEnever evaluated
FALSEnever evaluated
node->isHidden()Description
TRUEnever evaluated
FALSEnever evaluated
0
1957 || (hideSystem && node->isSystem())
hideSystemDescription
TRUEnever evaluated
FALSEnever evaluated
node->isSystem()Description
TRUEnever evaluated
FALSEnever evaluated
0
1958 || (hideDirs && node->isDir())
hideDirsDescription
TRUEnever evaluated
FALSEnever evaluated
node->isDir()Description
TRUEnever evaluated
FALSEnever evaluated
0
1959 || (hideFiles && node->isFile())
hideFilesDescription
TRUEnever evaluated
FALSEnever evaluated
node->isFile()Description
TRUEnever evaluated
FALSEnever evaluated
0
1960 || (hideSymlinks && node->isSymLink())
hideSymlinksDescription
TRUEnever evaluated
FALSEnever evaluated
node->isSymLink()Description
TRUEnever evaluated
FALSEnever evaluated
0
1961 || (hideReadable && node->isReadable())
hideReadableDescription
TRUEnever evaluated
FALSEnever evaluated
node->isReadable()Description
TRUEnever evaluated
FALSEnever evaluated
0
1962 || (hideWritable && node->isWritable())
hideWritableDescription
TRUEnever evaluated
FALSEnever evaluated
node->isWritable()Description
TRUEnever evaluated
FALSEnever evaluated
0
1963 || (hideExecutable && node->isExecutable())
hideExecutableDescription
TRUEnever evaluated
FALSEnever evaluated
node->isExecutable()Description
TRUEnever evaluated
FALSEnever evaluated
0
1964 || (hideDot && isDot)
hideDotDescription
TRUEnever evaluated
FALSEnever evaluated
isDotDescription
TRUEnever evaluated
FALSEnever evaluated
0
1965 || (hideDotDot && isDotDot))
hideDotDotDescription
TRUEnever evaluated
FALSEnever evaluated
isDotDotDescription
TRUEnever evaluated
FALSEnever evaluated
0
1966 return false;
never executed: return false;
0
1967-
1968 return nameFilterDisables || passNameFilters(node);
never executed: return nameFilterDisables || passNameFilters(node);
0
1969}-
1970-
1971/*-
1972 \internal-
1973-
1974 Returns \c true if node passes the name filters and should be visible.-
1975 */-
1976bool QFileSystemModelPrivate::passNameFilters(const QFileSystemNode *node) const-
1977{-
1978#ifndef QT_NO_REGEXP-
1979 if (nameFilters.isEmpty())
nameFilters.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
0
1980 return true;
never executed: return true;
0
1981-
1982 // Check the name regularexpression filters-
1983 if (!(node->isDir() && (filters & QDir::AllDirs))) {
node->isDir()Description
TRUEnever evaluated
FALSEnever evaluated
(filters & QDir::AllDirs)Description
TRUEnever evaluated
FALSEnever evaluated
0
1984 for (const auto &nameFilter : nameFilters) {-
1985 QRegExp copy = nameFilter;-
1986 if (copy.exactMatch(node->fileName))
copy.exactMatc...ode->fileName)Description
TRUEnever evaluated
FALSEnever evaluated
0
1987 return true;
never executed: return true;
0
1988 }
never executed: end of block
0
1989 return false;
never executed: return false;
0
1990 }-
1991#endif-
1992 return true;
never executed: return true;
0
1993}-
1994-
1995QT_END_NAMESPACE-
1996-
1997#include "moc_qfilesystemmodel.cpp"-
1998-
1999#endif // QT_NO_FILESYSTEMMODEL-
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9