Line | Source Code | Coverage |
---|
1 | | - |
2 | | - |
3 | | - |
4 | | - |
5 | class QDirModelPrivate : public QAbstractItemModelPrivate | - |
6 | { | - |
7 | inline QDirModel* q_func() { return static_cast<QDirModel *>(q_ptr); } inline const QDirModel* q_func() const { return static_cast<const QDirModel *>(q_ptr); } friend class QDirModel; | - |
8 | | - |
9 | public: | - |
10 | struct QDirNode | - |
11 | { | - |
12 | QDirNode() : parent(0), populated(false), stat(false) {} executed: } Execution Count:10490 | 10490 |
13 | ~QDirNode() { children.clear(); } executed: } Execution Count:10522 | 10522 |
14 | QDirNode *parent; | - |
15 | QFileInfo info; | - |
16 | QIcon icon; | - |
17 | mutable QVector<QDirNode> children; | - |
18 | mutable bool populated; | - |
19 | mutable bool stat; | - |
20 | }; | - |
21 | | - |
22 | QDirModelPrivate() | - |
23 | : resolveSymlinks(true), | - |
24 | readOnly(true), | - |
25 | lazyChildCount(false), | - |
26 | allowAppendChild(true), | - |
27 | iconProvider(&defaultProvider), | - |
28 | shouldStat(true) | - |
29 | { } executed: } Execution Count:82 | 82 |
30 | | - |
31 | void init(); | - |
32 | QDirNode *node(int row, QDirNode *parent) const; | - |
33 | QVector<QDirNode> children(QDirNode *parent, bool stat) const; | - |
34 | | - |
35 | void _q_refresh(); | - |
36 | | - |
37 | void savePersistentIndexes(); | - |
38 | void restorePersistentIndexes(); | - |
39 | | - |
40 | QFileInfoList entryInfoList(const QString &path) const; | - |
41 | QStringList entryList(const QString &path) const; | - |
42 | | - |
43 | QString name(const QModelIndex &index) const; | - |
44 | QString size(const QModelIndex &index) const; | - |
45 | QString type(const QModelIndex &index) const; | - |
46 | QString time(const QModelIndex &index) const; | - |
47 | | - |
48 | void appendChild(QDirModelPrivate::QDirNode *parent, const QString &path) const; | - |
49 | static QFileInfo resolvedInfo(QFileInfo info); | - |
50 | | - |
51 | inline QDirNode *node(const QModelIndex &index) const; | - |
52 | inline void populate(QDirNode *parent) const; | - |
53 | inline void clear(QDirNode *parent) const; | - |
54 | | - |
55 | void invalidate(); | - |
56 | | - |
57 | mutable QDirNode root; | - |
58 | bool resolveSymlinks; | - |
59 | bool readOnly; | - |
60 | bool lazyChildCount; | - |
61 | bool allowAppendChild; | - |
62 | | - |
63 | QDir::Filters filters; | - |
64 | QDir::SortFlags sort; | - |
65 | QStringList nameFilters; | - |
66 | | - |
67 | QFileIconProvider *iconProvider; | - |
68 | QFileIconProvider defaultProvider; | - |
69 | | - |
70 | struct SavedPersistent { | - |
71 | QString path; | - |
72 | int column; | - |
73 | QPersistentModelIndexData *data; | - |
74 | QPersistentModelIndex index; | - |
75 | }; | - |
76 | QList<SavedPersistent> savedPersistent; | - |
77 | QPersistentModelIndex toBeRefreshed; | - |
78 | | - |
79 | bool shouldStat; | - |
80 | }; | - |
81 | | - |
82 | void qt_setDirModelShouldNotStat(QDirModelPrivate *modelPrivate) | - |
83 | { | - |
84 | modelPrivate->shouldStat = false; | - |
85 | } | 0 |
86 | | - |
87 | QDirModelPrivate::QDirNode *QDirModelPrivate::node(const QModelIndex &index) const | - |
88 | { | - |
89 | QDirModelPrivate::QDirNode *n = | - |
90 | static_cast<QDirModelPrivate::QDirNode*>(index.internalPointer()); | - |
91 | qt_noop(); | - |
92 | return n; executed: return n; Execution Count:31153 | 31153 |
93 | } | - |
94 | | - |
95 | void QDirModelPrivate::populate(QDirNode *parent) const | - |
96 | { | - |
97 | qt_noop(); | - |
98 | parent->children = children(parent, parent->stat); | - |
99 | parent->populated = true; | - |
100 | } executed: } Execution Count:599 | 599 |
101 | | - |
102 | void QDirModelPrivate::clear(QDirNode *parent) const | - |
103 | { | - |
104 | qt_noop(); | - |
105 | parent->children.clear(); | - |
106 | parent->populated = false; | - |
107 | } executed: } Execution Count:108 | 108 |
108 | | - |
109 | void QDirModelPrivate::invalidate() | - |
110 | { | - |
111 | QStack<const QDirNode*> nodes; | - |
112 | nodes.push(&root); | - |
113 | while (!nodes.empty()) { never evaluated: !nodes.empty() | 0 |
114 | const QDirNode *current = nodes.pop(); | - |
115 | current->stat = false; | - |
116 | const QVector<QDirNode> children = current->children; | - |
117 | for (int i = 0; i < children.count(); ++i) never evaluated: i < children.count() | 0 |
118 | nodes.push(&children.at(i)); never executed: nodes.push(&children.at(i)); | 0 |
119 | } | 0 |
120 | } | 0 |
121 | QDirModel::QDirModel(const QStringList &nameFilters, | - |
122 | QDir::Filters filters, | - |
123 | QDir::SortFlags sort, | - |
124 | QObject *parent) | - |
125 | : QAbstractItemModel(*new QDirModelPrivate, parent) | - |
126 | { | - |
127 | QDirModelPrivate * const d = d_func(); | - |
128 | | - |
129 | d->nameFilters = nameFilters.isEmpty() ? QStringList(QLatin1String("*")) : nameFilters; never evaluated: nameFilters.isEmpty() | 0 |
130 | d->filters = filters; | - |
131 | d->sort = sort; | - |
132 | d->root.parent = 0; | - |
133 | d->root.info = QFileInfo(); | - |
134 | d->clear(&d->root); | - |
135 | } | 0 |
136 | | - |
137 | | - |
138 | | - |
139 | | - |
140 | | - |
141 | QDirModel::QDirModel(QObject *parent) | - |
142 | : QAbstractItemModel(*new QDirModelPrivate, parent) | - |
143 | { | - |
144 | QDirModelPrivate * const d = d_func(); | - |
145 | d->init(); | - |
146 | } executed: } Execution Count:82 | 82 |
147 | | - |
148 | | - |
149 | | - |
150 | | - |
151 | QDirModel::QDirModel(QDirModelPrivate &dd, QObject *parent) | - |
152 | : QAbstractItemModel(dd, parent) | - |
153 | { | - |
154 | QDirModelPrivate * const d = d_func(); | - |
155 | d->init(); | - |
156 | } | 0 |
157 | | - |
158 | | - |
159 | | - |
160 | | - |
161 | | - |
162 | QDirModel::~QDirModel() | - |
163 | { | - |
164 | | - |
165 | } | - |
166 | | - |
167 | | - |
168 | | - |
169 | | - |
170 | | - |
171 | | - |
172 | | - |
173 | QModelIndex QDirModel::index(int row, int column, const QModelIndex &parent) const | - |
174 | { | - |
175 | const QDirModelPrivate * const d = d_func(); | - |
176 | | - |
177 | if (column < 0 || column >= columnCount(parent) || row < 0 || parent.column() > 0) evaluated: column < 0 yes Evaluation Count:4 | yes Evaluation Count:16799 |
evaluated: column >= columnCount(parent) yes Evaluation Count:1 | yes Evaluation Count:16798 |
evaluated: row < 0 yes Evaluation Count:1 | yes Evaluation Count:16797 |
partially evaluated: parent.column() > 0 no Evaluation Count:0 | yes Evaluation Count:16797 |
| 0-16799 |
178 | return QModelIndex(); executed: return QModelIndex(); Execution Count:6 | 6 |
179 | | - |
180 | QDirModelPrivate::QDirNode *p = (d->indexValid(parent) ? d->node(parent) : &d->root); evaluated: d->indexValid(parent) yes Evaluation Count:16730 | yes Evaluation Count:67 |
| 67-16730 |
181 | qt_noop(); | - |
182 | if (!p->populated) evaluated: !p->populated yes Evaluation Count:25 | yes Evaluation Count:16772 |
| 25-16772 |
183 | d->populate(p); executed: d->populate(p); Execution Count:25 | 25 |
184 | if (row >= p->children.count()) partially evaluated: row >= p->children.count() no Evaluation Count:0 | yes Evaluation Count:16797 |
| 0-16797 |
185 | return QModelIndex(); never executed: return QModelIndex(); | 0 |
186 | | - |
187 | QDirModelPrivate::QDirNode *n = d->node(row, d->indexValid(parent) ? p : 0); | - |
188 | qt_noop(); | - |
189 | | - |
190 | return createIndex(row, column, n); executed: return createIndex(row, column, n); Execution Count:16797 | 16797 |
191 | } | - |
192 | | - |
193 | | - |
194 | | - |
195 | | - |
196 | | - |
197 | QModelIndex QDirModel::parent(const QModelIndex &child) const | - |
198 | { | - |
199 | const QDirModelPrivate * const d = d_func(); | - |
200 | | - |
201 | if (!d->indexValid(child)) evaluated: !d->indexValid(child) yes Evaluation Count:4 | yes Evaluation Count:7347 |
| 4-7347 |
202 | return QModelIndex(); executed: return QModelIndex(); Execution Count:4 | 4 |
203 | QDirModelPrivate::QDirNode *node = d->node(child); | - |
204 | QDirModelPrivate::QDirNode *par = (node ? node->parent : 0); partially evaluated: node yes Evaluation Count:7347 | no Evaluation Count:0 |
| 0-7347 |
205 | if (par == 0) evaluated: par == 0 yes Evaluation Count:47 | yes Evaluation Count:7300 |
| 47-7300 |
206 | return QModelIndex(); executed: return QModelIndex(); Execution Count:47 | 47 |
207 | | - |
208 | | - |
209 | const QVector<QDirModelPrivate::QDirNode> children = | - |
210 | par->parent ? par->parent->children : d->root.children; evaluated: par->parent yes Evaluation Count:7001 | yes Evaluation Count:299 |
| 299-7001 |
211 | qt_noop(); | - |
212 | int row = (par - &(children.at(0))); | - |
213 | qt_noop(); | - |
214 | | - |
215 | return createIndex(row, 0, par); executed: return createIndex(row, 0, par); Execution Count:7300 | 7300 |
216 | } | - |
217 | | - |
218 | | - |
219 | | - |
220 | | - |
221 | | - |
222 | | - |
223 | int QDirModel::rowCount(const QModelIndex &parent) const | - |
224 | { | - |
225 | const QDirModelPrivate * const d = d_func(); | - |
226 | if (parent.column() > 0) evaluated: parent.column() > 0 yes Evaluation Count:1 | yes Evaluation Count:3193 |
| 1-3193 |
227 | return 0; executed: return 0; Execution Count:1 | 1 |
228 | | - |
229 | if (!parent.isValid()) { evaluated: !parent.isValid() yes Evaluation Count:30 | yes Evaluation Count:3163 |
| 30-3163 |
230 | if (!d->root.populated) evaluated: !d->root.populated yes Evaluation Count:7 | yes Evaluation Count:23 |
| 7-23 |
231 | d->populate(&d->root); executed: d->populate(&d->root); Execution Count:7 | 7 |
232 | return d->root.children.count(); executed: return d->root.children.count(); Execution Count:30 | 30 |
233 | } | - |
234 | if (parent.model() != this) partially evaluated: parent.model() != this no Evaluation Count:0 | yes Evaluation Count:3163 |
| 0-3163 |
235 | return 0; never executed: return 0; | 0 |
236 | QDirModelPrivate::QDirNode *p = d->node(parent); | - |
237 | if (p->info.isDir() && !p->populated) partially evaluated: p->info.isDir() yes Evaluation Count:3163 | no Evaluation Count:0 |
evaluated: !p->populated yes Evaluation Count:170 | yes Evaluation Count:2993 |
| 0-3163 |
238 | d->populate(p); executed: d->populate(p); Execution Count:170 | 170 |
239 | return p->children.count(); executed: return p->children.count(); Execution Count:3163 | 3163 |
240 | } | - |
241 | | - |
242 | | - |
243 | | - |
244 | | - |
245 | | - |
246 | | - |
247 | int QDirModel::columnCount(const QModelIndex &parent) const | - |
248 | { | - |
249 | if (parent.column() > 0) partially evaluated: parent.column() > 0 no Evaluation Count:0 | yes Evaluation Count:19796 |
| 0-19796 |
250 | return 0; never executed: return 0; | 0 |
251 | return 4; executed: return 4; Execution Count:19796 | 19796 |
252 | } | - |
253 | | - |
254 | | - |
255 | | - |
256 | | - |
257 | QVariant QDirModel::data(const QModelIndex &index, int role) const | - |
258 | { | - |
259 | const QDirModelPrivate * const d = d_func(); | - |
260 | if (!d->indexValid(index)) evaluated: !d->indexValid(index) yes Evaluation Count:258 | yes Evaluation Count:3117 |
| 258-3117 |
261 | return QVariant(); executed: return QVariant(); Execution Count:258 | 258 |
262 | | - |
263 | if (role == Qt::DisplayRole || role == Qt::EditRole) { evaluated: role == Qt::DisplayRole yes Evaluation Count:2458 | yes Evaluation Count:659 |
evaluated: role == Qt::EditRole yes Evaluation Count:164 | yes Evaluation Count:495 |
| 164-2458 |
264 | switch (index.column()) { | - |
265 | case 0: return d->name(index); executed: return d->name(index); Execution Count:807 | 807 |
266 | case 1: return d->size(index); executed: return d->size(index); Execution Count:607 | 607 |
267 | case 2: return d->type(index); executed: return d->type(index); Execution Count:604 | 604 |
268 | case 3: return d->time(index); executed: return d->time(index); Execution Count:604 | 604 |
269 | default: | - |
270 | QMessageLogger("itemviews/qdirmodel.cpp", 376, __PRETTY_FUNCTION__).warning("data: invalid display value column %d", index.column()); | - |
271 | return QVariant(); never executed: return QVariant(); | 0 |
272 | } | - |
273 | } | 0 |
274 | | - |
275 | if (index.column() == 0) { evaluated: index.column() == 0 yes Evaluation Count:161 | yes Evaluation Count:334 |
| 161-334 |
276 | if (role == FileIconRole) evaluated: role == FileIconRole yes Evaluation Count:22 | yes Evaluation Count:139 |
| 22-139 |
277 | return fileIcon(index); executed: return fileIcon(index); Execution Count:22 | 22 |
278 | if (role == FilePathRole) partially evaluated: role == FilePathRole no Evaluation Count:0 | yes Evaluation Count:139 |
| 0-139 |
279 | return filePath(index); never executed: return filePath(index); | 0 |
280 | if (role == FileNameRole) partially evaluated: role == FileNameRole no Evaluation Count:0 | yes Evaluation Count:139 |
| 0-139 |
281 | return fileName(index); never executed: return fileName(index); | 0 |
282 | } executed: } Execution Count:139 | 139 |
283 | | - |
284 | if (index.column() == 1 && Qt::TextAlignmentRole == role) { evaluated: index.column() == 1 yes Evaluation Count:124 | yes Evaluation Count:349 |
evaluated: Qt::TextAlignmentRole == role yes Evaluation Count:18 | yes Evaluation Count:106 |
| 18-349 |
285 | return Qt::AlignRight; executed: return Qt::AlignRight; Execution Count:18 | 18 |
286 | } | - |
287 | return QVariant(); executed: return QVariant(); Execution Count:455 | 455 |
288 | } | - |
289 | bool QDirModel::setData(const QModelIndex &index, const QVariant &value, int role) | - |
290 | { | - |
291 | QDirModelPrivate * const d = d_func(); | - |
292 | if (!d->indexValid(index) || index.column() != 0 partially evaluated: !d->indexValid(index) yes Evaluation Count:3 | no Evaluation Count:0 |
never evaluated: index.column() != 0 | 0-3 |
293 | || (flags(index) & Qt::ItemIsEditable) == 0 || role != Qt::EditRole) never evaluated: (flags(index) & Qt::ItemIsEditable) == 0 never evaluated: role != Qt::EditRole | 0 |
294 | return false; executed: return false; Execution Count:3 | 3 |
295 | | - |
296 | QDirModelPrivate::QDirNode *node = d->node(index); | - |
297 | QDir dir = node->info.dir(); | - |
298 | QString name = value.toString(); | - |
299 | if (dir.rename(node->info.fileName(), name)) { never evaluated: dir.rename(node->info.fileName(), name) | 0 |
300 | node->info = QFileInfo(dir, name); | - |
301 | QModelIndex sibling = index.sibling(index.row(), 3); | - |
302 | dataChanged(index, sibling); | - |
303 | | - |
304 | d->toBeRefreshed = index.parent(); | - |
305 | QMetaObject::invokeMethod(this, "_q_refresh", Qt::QueuedConnection); | - |
306 | | - |
307 | return true; never executed: return true; | 0 |
308 | } | - |
309 | | - |
310 | return false; never executed: return false; | 0 |
311 | } | - |
312 | | - |
313 | | - |
314 | | - |
315 | | - |
316 | | - |
317 | | - |
318 | QVariant QDirModel::headerData(int section, Qt::Orientation orientation, int role) const | - |
319 | { | - |
320 | if (orientation == Qt::Horizontal) { partially evaluated: orientation == Qt::Horizontal yes Evaluation Count:85 | no Evaluation Count:0 |
| 0-85 |
321 | if (role != Qt::DisplayRole) evaluated: role != Qt::DisplayRole yes Evaluation Count:66 | yes Evaluation Count:19 |
| 19-66 |
322 | return QVariant(); executed: return QVariant(); Execution Count:66 | 66 |
323 | switch (section) { | - |
324 | case 0: return tr("Name"); executed: return tr("Name"); Execution Count:11 | 11 |
325 | case 1: return tr("Size"); executed: return tr("Size"); Execution Count:6 | 6 |
326 | case 2: return | 1 |
327 | | 1 |
328 | | 1 |
329 | | 1 |
330 | tr("Type", "All other platforms"); executed: return tr("Type", "All other platforms"); Execution Count:1 | 1 |
331 | | - |
332 | | - |
333 | | - |
334 | | - |
335 | | - |
336 | case 3: return tr("Date Modified"); executed: return tr("Date Modified"); Execution Count:1 | 1 |
337 | default: return QVariant(); never executed: return QVariant(); | 0 |
338 | } | - |
339 | } | 0 |
340 | return QAbstractItemModel::headerData(section, orientation, role); never executed: return QAbstractItemModel::headerData(section, orientation, role); | 0 |
341 | } | - |
342 | | - |
343 | | - |
344 | | - |
345 | | - |
346 | | - |
347 | | - |
348 | bool QDirModel::hasChildren(const QModelIndex &parent) const | - |
349 | { | - |
350 | const QDirModelPrivate * const d = d_func(); | - |
351 | if (parent.column() > 0) evaluated: parent.column() > 0 yes Evaluation Count:1767 | yes Evaluation Count:633 |
| 633-1767 |
352 | return false; executed: return false; Execution Count:1767 | 1767 |
353 | | - |
354 | if (!parent.isValid()) evaluated: !parent.isValid() yes Evaluation Count:7 | yes Evaluation Count:626 |
| 7-626 |
355 | return true; executed: return true; Execution Count:7 | 7 |
356 | QDirModelPrivate::QDirNode *p = d->node(parent); | - |
357 | qt_noop(); | - |
358 | | - |
359 | if (d->lazyChildCount) partially evaluated: d->lazyChildCount no Evaluation Count:0 | yes Evaluation Count:626 |
| 0-626 |
360 | return p->info.isDir(); never executed: return p->info.isDir(); | 0 |
361 | return p->info.isDir() && rowCount(parent) > 0; executed: return p->info.isDir() && rowCount(parent) > 0; Execution Count:626 | 626 |
362 | } | - |
363 | | - |
364 | | - |
365 | | - |
366 | | - |
367 | | - |
368 | | - |
369 | Qt::ItemFlags QDirModel::flags(const QModelIndex &index) const | - |
370 | { | - |
371 | const QDirModelPrivate * const d = d_func(); | - |
372 | Qt::ItemFlags flags = QAbstractItemModel::flags(index); | - |
373 | if (!d->indexValid(index)) evaluated: !d->indexValid(index) yes Evaluation Count:1 | yes Evaluation Count:21 |
| 1-21 |
374 | return flags; executed: return flags; Execution Count:1 | 1 |
375 | flags |= Qt::ItemIsDragEnabled; | - |
376 | if (d->readOnly) partially evaluated: d->readOnly yes Evaluation Count:21 | no Evaluation Count:0 |
| 0-21 |
377 | return flags; executed: return flags; Execution Count:21 | 21 |
378 | QDirModelPrivate::QDirNode *node = d->node(index); | - |
379 | if ((index.column() == 0) && node->info.isWritable()) { never evaluated: (index.column() == 0) never evaluated: node->info.isWritable() | 0 |
380 | flags |= Qt::ItemIsEditable; | - |
381 | if (fileInfo(index).isDir()) never evaluated: fileInfo(index).isDir() | 0 |
382 | flags |= Qt::ItemIsDropEnabled; never executed: flags |= Qt::ItemIsDropEnabled; | 0 |
383 | } | 0 |
384 | return flags; never executed: return flags; | 0 |
385 | } | - |
386 | | - |
387 | | - |
388 | | - |
389 | | - |
390 | | - |
391 | | - |
392 | void QDirModel::sort(int column, Qt::SortOrder order) | - |
393 | { | - |
394 | QDir::SortFlags sort = QDir::DirsFirst | QDir::IgnoreCase; | - |
395 | if (order == Qt::DescendingOrder) evaluated: order == Qt::DescendingOrder yes Evaluation Count:1 | yes Evaluation Count:12 |
| 1-12 |
396 | sort |= QDir::Reversed; executed: sort |= QDir::Reversed; Execution Count:1 | 1 |
397 | | - |
398 | switch (column) { | - |
399 | case 0: | - |
400 | sort |= QDir::Name; | - |
401 | break; executed: break; Execution Count:2 | 2 |
402 | case 1: | - |
403 | sort |= QDir::Size; | - |
404 | break; executed: break; Execution Count:1 | 1 |
405 | case 2: | - |
406 | sort |= QDir::Type; | - |
407 | break; executed: break; Execution Count:1 | 1 |
408 | case 3: | - |
409 | sort |= QDir::Time; | - |
410 | break; executed: break; Execution Count:1 | 1 |
411 | default: | - |
412 | break; executed: break; Execution Count:8 | 8 |
413 | } | - |
414 | | - |
415 | setSorting(sort); | - |
416 | } executed: } Execution Count:13 | 13 |
417 | | - |
418 | | - |
419 | | - |
420 | | - |
421 | | - |
422 | | - |
423 | QStringList QDirModel::mimeTypes() const | - |
424 | { | - |
425 | return QStringList(QLatin1String("text/uri-list")); executed: return QStringList(QLatin1String("text/uri-list")); Execution Count:1 | 1 |
426 | } | - |
427 | QMimeData *QDirModel::mimeData(const QModelIndexList &indexes) const | - |
428 | { | - |
429 | QList<QUrl> urls; | - |
430 | QList<QModelIndex>::const_iterator it = indexes.begin(); | - |
431 | for (; it != indexes.end(); ++it) never evaluated: it != indexes.end() | 0 |
432 | if ((*it).column() == 0) never evaluated: (*it).column() == 0 | 0 |
433 | urls << QUrl::fromLocalFile(filePath(*it)); never executed: urls << QUrl::fromLocalFile(filePath(*it)); | 0 |
434 | QMimeData *data = new QMimeData(); | - |
435 | data->setUrls(urls); | - |
436 | return data; never executed: return data; | 0 |
437 | } | - |
438 | bool QDirModel::dropMimeData(const QMimeData *data, Qt::DropAction action, | - |
439 | int , int , const QModelIndex &parent) | - |
440 | { | - |
441 | QDirModelPrivate * const d = d_func(); | - |
442 | if (!d->indexValid(parent) || isReadOnly()) never evaluated: !d->indexValid(parent) never evaluated: isReadOnly() | 0 |
443 | return false; never executed: return false; | 0 |
444 | | - |
445 | bool success = true; | - |
446 | QString to = filePath(parent) + QDir::separator(); | - |
447 | QModelIndex _parent = parent; | - |
448 | | - |
449 | QList<QUrl> urls = data->urls(); | - |
450 | QList<QUrl>::const_iterator it = urls.constBegin(); | - |
451 | | - |
452 | switch (action) { | - |
453 | case Qt::CopyAction: | - |
454 | for (; it != urls.constEnd(); ++it) { never evaluated: it != urls.constEnd() | 0 |
455 | QString path = (*it).toLocalFile(); | - |
456 | success = QFile::copy(path, to + QFileInfo(path).fileName()) && success; never evaluated: QFile::copy(path, to + QFileInfo(path).fileName()) | 0 |
457 | } | 0 |
458 | break; | 0 |
459 | case Qt::LinkAction: | - |
460 | for (; it != urls.constEnd(); ++it) { never evaluated: it != urls.constEnd() | 0 |
461 | QString path = (*it).toLocalFile(); | - |
462 | success = QFile::link(path, to + QFileInfo(path).fileName()) && success; never evaluated: QFile::link(path, to + QFileInfo(path).fileName()) | 0 |
463 | } | 0 |
464 | break; | 0 |
465 | case Qt::MoveAction: | - |
466 | for (; it != urls.constEnd(); ++it) { never evaluated: it != urls.constEnd() | 0 |
467 | QString path = (*it).toLocalFile(); | - |
468 | if (QFile::copy(path, to + QFileInfo(path).fileName()) never evaluated: QFile::copy(path, to + QFileInfo(path).fileName()) | 0 |
469 | && QFile::remove(path)) { never evaluated: QFile::remove(path) | 0 |
470 | QModelIndex idx=index(QFileInfo(path).path()); | - |
471 | if (idx.isValid()) { never evaluated: idx.isValid() | 0 |
472 | refresh(idx); | - |
473 | | - |
474 | _parent = index(to); | - |
475 | } | 0 |
476 | } else { | 0 |
477 | success = false; | - |
478 | } | 0 |
479 | } | - |
480 | break; | 0 |
481 | default: | - |
482 | return false; never executed: return false; | 0 |
483 | } | - |
484 | | - |
485 | if (success) | 0 |
486 | refresh(_parent); never executed: refresh(_parent); | 0 |
487 | | - |
488 | return success; never executed: return success; | 0 |
489 | } | - |
490 | | - |
491 | | - |
492 | | - |
493 | | - |
494 | | - |
495 | | - |
496 | | - |
497 | Qt::DropActions QDirModel::supportedDropActions() const | - |
498 | { | - |
499 | return Qt::CopyAction | Qt::MoveAction; executed: return Qt::CopyAction | Qt::MoveAction; Execution Count:1 | 1 |
500 | } | - |
501 | | - |
502 | | - |
503 | | - |
504 | | - |
505 | | - |
506 | | - |
507 | void QDirModel::setIconProvider(QFileIconProvider *provider) | - |
508 | { | - |
509 | QDirModelPrivate * const d = d_func(); | - |
510 | d->iconProvider = provider; | - |
511 | } executed: } Execution Count:2 | 2 |
512 | | - |
513 | | - |
514 | | - |
515 | | - |
516 | | - |
517 | QFileIconProvider *QDirModel::iconProvider() const | - |
518 | { | - |
519 | const QDirModelPrivate * const d = d_func(); | - |
520 | return d->iconProvider; executed: return d->iconProvider; Execution Count:2 | 2 |
521 | } | - |
522 | | - |
523 | | - |
524 | | - |
525 | | - |
526 | | - |
527 | void QDirModel::setNameFilters(const QStringList &filters) | - |
528 | { | - |
529 | QDirModelPrivate * const d = d_func(); | - |
530 | d->nameFilters = filters; | - |
531 | layoutAboutToBeChanged(); | - |
532 | if (d->shouldStat) partially evaluated: d->shouldStat yes Evaluation Count:1 | no Evaluation Count:0 |
| 0-1 |
533 | refresh(QModelIndex()); executed: refresh(QModelIndex()); Execution Count:1 | 1 |
534 | else | - |
535 | d->invalidate(); never executed: d->invalidate(); | 0 |
536 | layoutChanged(); | - |
537 | } executed: } Execution Count:1 | 1 |
538 | | - |
539 | | - |
540 | | - |
541 | | - |
542 | | - |
543 | QStringList QDirModel::nameFilters() const | - |
544 | { | - |
545 | const QDirModelPrivate * const d = d_func(); | - |
546 | return d->nameFilters; never executed: return d->nameFilters; | 0 |
547 | } | - |
548 | void QDirModel::setFilter(QDir::Filters filters) | - |
549 | { | - |
550 | QDirModelPrivate * const d = d_func(); | - |
551 | d->filters = filters; | - |
552 | layoutAboutToBeChanged(); | - |
553 | if (d->shouldStat) partially evaluated: d->shouldStat yes Evaluation Count:3 | no Evaluation Count:0 |
| 0-3 |
554 | refresh(QModelIndex()); executed: refresh(QModelIndex()); Execution Count:3 | 3 |
555 | else | - |
556 | d->invalidate(); never executed: d->invalidate(); | 0 |
557 | layoutChanged(); | - |
558 | } executed: } Execution Count:3 | 3 |
559 | | - |
560 | | - |
561 | | - |
562 | | - |
563 | | - |
564 | | - |
565 | | - |
566 | QDir::Filters QDirModel::filter() const | - |
567 | { | - |
568 | const QDirModelPrivate * const d = d_func(); | - |
569 | return d->filters; executed: return d->filters; Execution Count:2 | 2 |
570 | } | - |
571 | | - |
572 | | - |
573 | | - |
574 | | - |
575 | | - |
576 | | - |
577 | | - |
578 | void QDirModel::setSorting(QDir::SortFlags sort) | - |
579 | { | - |
580 | QDirModelPrivate * const d = d_func(); | - |
581 | d->sort = sort; | - |
582 | layoutAboutToBeChanged(); | - |
583 | if (d->shouldStat) partially evaluated: d->shouldStat yes Evaluation Count:13 | no Evaluation Count:0 |
| 0-13 |
584 | refresh(QModelIndex()); executed: refresh(QModelIndex()); Execution Count:13 | 13 |
585 | else | - |
586 | d->invalidate(); never executed: d->invalidate(); | 0 |
587 | layoutChanged(); | - |
588 | } executed: } Execution Count:13 | 13 |
589 | | - |
590 | | - |
591 | | - |
592 | | - |
593 | | - |
594 | | - |
595 | | - |
596 | QDir::SortFlags QDirModel::sorting() const | - |
597 | { | - |
598 | const QDirModelPrivate * const d = d_func(); | - |
599 | return d->sort; never executed: return d->sort; | 0 |
600 | } | - |
601 | void QDirModel::setResolveSymlinks(bool enable) | - |
602 | { | - |
603 | QDirModelPrivate * const d = d_func(); | - |
604 | d->resolveSymlinks = enable; | - |
605 | } executed: } Execution Count:4 | 4 |
606 | | - |
607 | bool QDirModel::resolveSymlinks() const | - |
608 | { | - |
609 | const QDirModelPrivate * const d = d_func(); | - |
610 | return d->resolveSymlinks; executed: return d->resolveSymlinks; Execution Count:2 | 2 |
611 | } | - |
612 | void QDirModel::setReadOnly(bool enable) | - |
613 | { | - |
614 | QDirModelPrivate * const d = d_func(); | - |
615 | d->readOnly = enable; | - |
616 | } executed: } Execution Count:65 | 65 |
617 | | - |
618 | bool QDirModel::isReadOnly() const | - |
619 | { | - |
620 | const QDirModelPrivate * const d = d_func(); | - |
621 | return d->readOnly; executed: return d->readOnly; Execution Count:16 | 16 |
622 | } | - |
623 | void QDirModel::setLazyChildCount(bool enable) | - |
624 | { | - |
625 | QDirModelPrivate * const d = d_func(); | - |
626 | d->lazyChildCount = enable; | - |
627 | } executed: } Execution Count:2 | 2 |
628 | | - |
629 | bool QDirModel::lazyChildCount() const | - |
630 | { | - |
631 | const QDirModelPrivate * const d = d_func(); | - |
632 | return d->lazyChildCount; executed: return d->lazyChildCount; Execution Count:2 | 2 |
633 | } | - |
634 | void QDirModel::refresh(const QModelIndex &parent) | - |
635 | { | - |
636 | QDirModelPrivate * const d = d_func(); | - |
637 | | - |
638 | QDirModelPrivate::QDirNode *n = d->indexValid(parent) ? d->node(parent) : &(d->root); evaluated: d->indexValid(parent) yes Evaluation Count:13 | yes Evaluation Count:17 |
| 13-17 |
639 | | - |
640 | int rows = n->children.count(); | - |
641 | if (rows == 0) { evaluated: rows == 0 yes Evaluation Count:4 | yes Evaluation Count:26 |
| 4-26 |
642 | layoutAboutToBeChanged(); | - |
643 | n->stat = true; | - |
644 | n->populated = false; | - |
645 | layoutChanged(); | - |
646 | return; executed: return; Execution Count:4 | 4 |
647 | } | - |
648 | | - |
649 | layoutAboutToBeChanged(); | - |
650 | d->savePersistentIndexes(); | - |
651 | d->rowsAboutToBeRemoved(parent, 0, rows - 1); | - |
652 | n->stat = true; | - |
653 | d->clear(n); | - |
654 | d->rowsRemoved(parent, 0, rows - 1); | - |
655 | d->restorePersistentIndexes(); | - |
656 | layoutChanged(); | - |
657 | } executed: } Execution Count:26 | 26 |
658 | | - |
659 | | - |
660 | | - |
661 | | - |
662 | | - |
663 | | - |
664 | | - |
665 | QModelIndex QDirModel::index(const QString &path, int column) const | - |
666 | { | - |
667 | const QDirModelPrivate * const d = d_func(); | - |
668 | | - |
669 | if (path.isEmpty() || path == QCoreApplication::translate("QFileDialog", "My Computer")) evaluated: path.isEmpty() yes Evaluation Count:1 | yes Evaluation Count:57 |
partially evaluated: path == QCoreApplication::translate("QFileDialog", "My Computer") no Evaluation Count:0 | yes Evaluation Count:57 |
| 0-57 |
670 | return QModelIndex(); executed: return QModelIndex(); Execution Count:1 | 1 |
671 | | - |
672 | QString absolutePath = QDir(path).absolutePath(); | - |
673 | QStringList pathElements = absolutePath.split(QLatin1Char('/'), QString::SkipEmptyParts); | - |
674 | if ((pathElements.isEmpty() || !QFileInfo(path).exists()) partially evaluated: pathElements.isEmpty() no Evaluation Count:0 | yes Evaluation Count:57 |
evaluated: !QFileInfo(path).exists() yes Evaluation Count:4 | yes Evaluation Count:53 |
| 0-57 |
675 | | - |
676 | && path != QLatin1String("/") partially evaluated: path != QLatin1String("/") yes Evaluation Count:4 | no Evaluation Count:0 |
| 0-4 |
677 | | - |
678 | ) | - |
679 | return QModelIndex(); executed: return QModelIndex(); Execution Count:4 | 4 |
680 | | - |
681 | QModelIndex idx; | - |
682 | if (!d->root.populated) evaluated: !d->root.populated yes Evaluation Count:33 | yes Evaluation Count:20 |
| 20-33 |
683 | d->populate(&d->root); executed: d->populate(&d->root); Execution Count:33 | 33 |
684 | pathElements.prepend(QLatin1String("/")); | - |
685 | | - |
686 | | - |
687 | for (int i = 0; i < pathElements.count(); ++i) { evaluated: i < pathElements.count() yes Evaluation Count:635 | yes Evaluation Count:52 |
| 52-635 |
688 | qt_noop(); | - |
689 | QString element = pathElements.at(i); | - |
690 | QDirModelPrivate::QDirNode *parent = (idx.isValid() ? d->node(idx) : &d->root); evaluated: idx.isValid() yes Evaluation Count:582 | yes Evaluation Count:53 |
| 53-582 |
691 | | - |
692 | qt_noop(); | - |
693 | if (!parent->populated) evaluated: !parent->populated yes Evaluation Count:364 | yes Evaluation Count:271 |
| 271-364 |
694 | d->populate(parent); executed: d->populate(parent); Execution Count:364 | 364 |
695 | | - |
696 | | - |
697 | int row = -1; | - |
698 | for (int j = parent->children.count() - 1; j >= 0; --j) { evaluated: j >= 0 yes Evaluation Count:5091 | yes Evaluation Count:13 |
| 13-5091 |
699 | const QFileInfo& fi = parent->children.at(j).info; | - |
700 | QString childFileName; | - |
701 | childFileName = idx.isValid() ? fi.fileName() : fi.absoluteFilePath(); evaluated: idx.isValid() yes Evaluation Count:5038 | yes Evaluation Count:53 |
| 53-5038 |
702 | | - |
703 | | - |
704 | | - |
705 | if (childFileName == element) { evaluated: childFileName == element yes Evaluation Count:622 | yes Evaluation Count:4469 |
| 622-4469 |
706 | if (i == pathElements.count() - 1) evaluated: i == pathElements.count() - 1 yes Evaluation Count:50 | yes Evaluation Count:572 |
| 50-572 |
707 | parent->children[j].stat = true; executed: parent->children[j].stat = true; Execution Count:50 | 50 |
708 | row = j; | - |
709 | break; executed: break; Execution Count:622 | 622 |
710 | } | - |
711 | } executed: } Execution Count:4469 | 4469 |
712 | | - |
713 | | - |
714 | if (row == -1) { evaluated: row == -1 yes Evaluation Count:13 | yes Evaluation Count:622 |
| 13-622 |
715 | | - |
716 | | - |
717 | | - |
718 | | - |
719 | | - |
720 | | - |
721 | | - |
722 | QString newPath = parent->info.absoluteFilePath() + QLatin1Char('/') + element; | - |
723 | | - |
724 | if (!d->allowAppendChild || !QFileInfo(newPath).isDir()) partially evaluated: !d->allowAppendChild no Evaluation Count:0 | yes Evaluation Count:13 |
evaluated: !QFileInfo(newPath).isDir() yes Evaluation Count:1 | yes Evaluation Count:12 |
| 0-13 |
725 | return QModelIndex(); executed: return QModelIndex(); Execution Count:1 | 1 |
726 | d->appendChild(parent, newPath); | - |
727 | row = parent->children.count() - 1; | - |
728 | if (i == pathElements.count() - 1) evaluated: i == pathElements.count() - 1 yes Evaluation Count:2 | yes Evaluation Count:10 |
| 2-10 |
729 | parent->children[row].stat = true; executed: parent->children[row].stat = true; Execution Count:2 | 2 |
730 | const_cast<QDirModel*>(this)->layoutChanged(); | - |
731 | } executed: } Execution Count:12 | 12 |
732 | | - |
733 | qt_noop(); | - |
734 | idx = createIndex(row, 0, static_cast<void*>(&parent->children[row])); | - |
735 | qt_noop(); | - |
736 | } executed: } Execution Count:634 | 634 |
737 | | - |
738 | if (column != 0) evaluated: column != 0 yes Evaluation Count:3 | yes Evaluation Count:49 |
| 3-49 |
739 | return idx.sibling(idx.row(), column); executed: return idx.sibling(idx.row(), column); Execution Count:3 | 3 |
740 | return idx; executed: return idx; Execution Count:49 | 49 |
741 | } | - |
742 | | - |
743 | | - |
744 | | - |
745 | | - |
746 | | - |
747 | | - |
748 | bool QDirModel::isDir(const QModelIndex &index) const | - |
749 | { | - |
750 | const QDirModelPrivate * const d = d_func(); | - |
751 | qt_noop(); | - |
752 | QDirModelPrivate::QDirNode *node = d->node(index); | - |
753 | return node->info.isDir(); never executed: return node->info.isDir(); | 0 |
754 | } | - |
755 | | - |
756 | | - |
757 | | - |
758 | | - |
759 | | - |
760 | QModelIndex QDirModel::mkdir(const QModelIndex &parent, const QString &name) | - |
761 | { | - |
762 | QDirModelPrivate * const d = d_func(); | - |
763 | if (!d->indexValid(parent) || isReadOnly()) partially evaluated: !d->indexValid(parent) no Evaluation Count:0 | yes Evaluation Count:7 |
partially evaluated: isReadOnly() no Evaluation Count:0 | yes Evaluation Count:7 |
| 0-7 |
764 | return QModelIndex(); never executed: return QModelIndex(); | 0 |
765 | | - |
766 | QDirModelPrivate::QDirNode *p = d->node(parent); | - |
767 | QString path = p->info.absoluteFilePath(); | - |
768 | | - |
769 | | - |
770 | | - |
771 | QDir newDir(name); | - |
772 | QDir dir(path); | - |
773 | if (newDir.isRelative()) partially evaluated: newDir.isRelative() yes Evaluation Count:7 | no Evaluation Count:0 |
| 0-7 |
774 | newDir = QDir(path + QLatin1Char('/') + name); executed: newDir = QDir(path + QLatin1Char('/') + name); Execution Count:7 | 7 |
775 | QString childName = newDir.dirName(); | - |
776 | newDir.cdUp(); | - |
777 | | - |
778 | if (newDir.absolutePath() != dir.absolutePath() || !dir.mkdir(name)) evaluated: newDir.absolutePath() != dir.absolutePath() yes Evaluation Count:2 | yes Evaluation Count:5 |
evaluated: !dir.mkdir(name) yes Evaluation Count:1 | yes Evaluation Count:4 |
| 1-5 |
779 | return QModelIndex(); executed: return QModelIndex(); Execution Count:3 | 3 |
780 | | - |
781 | refresh(parent); | - |
782 | | - |
783 | QStringList entryList = d->entryList(path); | - |
784 | int r = entryList.indexOf(childName); | - |
785 | QModelIndex i = index(r, 0, parent); | - |
786 | | - |
787 | return i; executed: return i; Execution Count:4 | 4 |
788 | } | - |
789 | bool QDirModel::rmdir(const QModelIndex &index) | - |
790 | { | - |
791 | QDirModelPrivate * const d = d_func(); | - |
792 | if (!d->indexValid(index) || isReadOnly()) evaluated: !d->indexValid(index) yes Evaluation Count:3 | yes Evaluation Count:4 |
partially evaluated: isReadOnly() no Evaluation Count:0 | yes Evaluation Count:4 |
| 0-4 |
793 | return false; executed: return false; Execution Count:3 | 3 |
794 | | - |
795 | QDirModelPrivate::QDirNode *n = d_func()->node(index); | - |
796 | if (!n->info.isDir()) { partially evaluated: !n->info.isDir() no Evaluation Count:0 | yes Evaluation Count:4 |
| 0-4 |
797 | QMessageLogger("itemviews/qdirmodel.cpp", 1035, __PRETTY_FUNCTION__).warning("rmdir: the node is not a directory"); | - |
798 | return false; never executed: return false; | 0 |
799 | } | - |
800 | | - |
801 | QModelIndex par = parent(index); | - |
802 | QDirModelPrivate::QDirNode *p = d_func()->node(par); | - |
803 | QDir dir = p->info.dir(); | - |
804 | QString path = n->info.absoluteFilePath(); | - |
805 | if (!dir.rmdir(path)) partially evaluated: !dir.rmdir(path) no Evaluation Count:0 | yes Evaluation Count:4 |
| 0-4 |
806 | return false; never executed: return false; | 0 |
807 | | - |
808 | refresh(par); | - |
809 | | - |
810 | return true; executed: return true; Execution Count:4 | 4 |
811 | } | - |
812 | bool QDirModel::remove(const QModelIndex &index) | - |
813 | { | - |
814 | QDirModelPrivate * const d = d_func(); | - |
815 | if (!d->indexValid(index) || isReadOnly()) partially evaluated: !d->indexValid(index) no Evaluation Count:0 | yes Evaluation Count:5 |
partially evaluated: isReadOnly() no Evaluation Count:0 | yes Evaluation Count:5 |
| 0-5 |
816 | return false; never executed: return false; | 0 |
817 | | - |
818 | QDirModelPrivate::QDirNode *n = d_func()->node(index); | - |
819 | if (n->info.isDir()) partially evaluated: n->info.isDir() no Evaluation Count:0 | yes Evaluation Count:5 |
| 0-5 |
820 | return false; never executed: return false; | 0 |
821 | | - |
822 | QModelIndex par = parent(index); | - |
823 | QDirModelPrivate::QDirNode *p = d_func()->node(par); | - |
824 | QDir dir = p->info.dir(); | - |
825 | QString path = n->info.absoluteFilePath(); | - |
826 | if (!dir.remove(path)) partially evaluated: !dir.remove(path) no Evaluation Count:0 | yes Evaluation Count:5 |
| 0-5 |
827 | return false; never executed: return false; | 0 |
828 | | - |
829 | refresh(par); | - |
830 | | - |
831 | return true; executed: return true; Execution Count:5 | 5 |
832 | } | - |
833 | | - |
834 | | - |
835 | | - |
836 | | - |
837 | | - |
838 | | - |
839 | | - |
840 | QString QDirModel::filePath(const QModelIndex &index) const | - |
841 | { | - |
842 | const QDirModelPrivate * const d = d_func(); | - |
843 | if (d->indexValid(index)) { partially evaluated: d->indexValid(index) yes Evaluation Count:23 | no Evaluation Count:0 |
| 0-23 |
844 | QFileInfo fi = fileInfo(index); | - |
845 | if (d->resolveSymlinks && fi.isSymLink()) evaluated: d->resolveSymlinks yes Evaluation Count:22 | yes Evaluation Count:1 |
evaluated: fi.isSymLink() yes Evaluation Count:1 | yes Evaluation Count:21 |
| 1-22 |
846 | fi = d->resolvedInfo(fi); executed: fi = d->resolvedInfo(fi); Execution Count:1 | 1 |
847 | return QDir::cleanPath(fi.absoluteFilePath()); executed: return QDir::cleanPath(fi.absoluteFilePath()); Execution Count:23 | 23 |
848 | } | - |
849 | return QString(); never executed: return QString(); | 0 |
850 | } | - |
851 | | - |
852 | | - |
853 | | - |
854 | | - |
855 | | - |
856 | | - |
857 | | - |
858 | QString QDirModel::fileName(const QModelIndex &index) const | - |
859 | { | - |
860 | const QDirModelPrivate * const d = d_func(); | - |
861 | if (!d->indexValid(index)) partially evaluated: !d->indexValid(index) yes Evaluation Count:1 | no Evaluation Count:0 |
| 0-1 |
862 | return QString(); executed: return QString(); Execution Count:1 | 1 |
863 | QFileInfo info = fileInfo(index); | - |
864 | if (info.isRoot()) never evaluated: info.isRoot() | 0 |
865 | return info.absoluteFilePath(); never executed: return info.absoluteFilePath(); | 0 |
866 | if (d->resolveSymlinks && info.isSymLink()) never evaluated: d->resolveSymlinks never evaluated: info.isSymLink() | 0 |
867 | info = d->resolvedInfo(info); never executed: info = d->resolvedInfo(info); | 0 |
868 | return info.fileName(); never executed: return info.fileName(); | 0 |
869 | } | - |
870 | | - |
871 | | - |
872 | | - |
873 | | - |
874 | | - |
875 | | - |
876 | QIcon QDirModel::fileIcon(const QModelIndex &index) const | - |
877 | { | - |
878 | const QDirModelPrivate * const d = d_func(); | - |
879 | if (!d->indexValid(index)) partially evaluated: !d->indexValid(index) no Evaluation Count:0 | yes Evaluation Count:22 |
| 0-22 |
880 | return d->iconProvider->icon(QFileIconProvider::Computer); never executed: return d->iconProvider->icon(QFileIconProvider::Computer); | 0 |
881 | QDirModelPrivate::QDirNode *node = d->node(index); | - |
882 | if (node->icon.isNull()) evaluated: node->icon.isNull() yes Evaluation Count:16 | yes Evaluation Count:6 |
| 6-16 |
883 | node->icon = d->iconProvider->icon(node->info); executed: node->icon = d->iconProvider->icon(node->info); Execution Count:16 | 16 |
884 | return node->icon; executed: return node->icon; Execution Count:22 | 22 |
885 | } | - |
886 | QFileInfo QDirModel::fileInfo(const QModelIndex &index) const | - |
887 | { | - |
888 | const QDirModelPrivate * const d = d_func(); | - |
889 | qt_noop(); | - |
890 | | - |
891 | QDirModelPrivate::QDirNode *node = d->node(index); | - |
892 | return node->info; executed: return node->info; Execution Count:23 | 23 |
893 | } | - |
894 | void QDirModelPrivate::init() | - |
895 | { | - |
896 | filters = QDir::AllEntries | QDir::NoDotAndDotDot; | - |
897 | sort = QDir::Name; | - |
898 | nameFilters << QLatin1String("*"); | - |
899 | root.parent = 0; | - |
900 | root.info = QFileInfo(); | - |
901 | clear(&root); | - |
902 | roleNames.insertMulti(QDirModel::FileIconRole, QByteArray("fileIcon", sizeof("fileIcon") - 1)); | - |
903 | roleNames.insert(QDirModel::FilePathRole, QByteArray("filePath", sizeof("filePath") - 1)); | - |
904 | roleNames.insert(QDirModel::FileNameRole, QByteArray("fileName", sizeof("fileName") - 1)); | - |
905 | } executed: } Execution Count:82 | 82 |
906 | | - |
907 | QDirModelPrivate::QDirNode *QDirModelPrivate::node(int row, QDirNode *parent) const | - |
908 | { | - |
909 | if (row < 0) partially evaluated: row < 0 no Evaluation Count:0 | yes Evaluation Count:16797 |
| 0-16797 |
910 | return 0; never executed: return 0; | 0 |
911 | | - |
912 | bool isDir = !parent || parent->info.isDir(); evaluated: !parent yes Evaluation Count:67 | yes Evaluation Count:16730 |
partially evaluated: parent->info.isDir() yes Evaluation Count:16730 | no Evaluation Count:0 |
| 0-16730 |
913 | QDirNode *p = (parent ? parent : &root); evaluated: parent yes Evaluation Count:16730 | yes Evaluation Count:67 |
| 67-16730 |
914 | if (isDir && !p->populated) partially evaluated: isDir yes Evaluation Count:16797 | no Evaluation Count:0 |
partially evaluated: !p->populated no Evaluation Count:0 | yes Evaluation Count:16797 |
| 0-16797 |
915 | populate(p); never executed: populate(p); | 0 |
916 | | - |
917 | if (row >= p->children.count()) { partially evaluated: row >= p->children.count() no Evaluation Count:0 | yes Evaluation Count:16797 |
| 0-16797 |
918 | QMessageLogger("itemviews/qdirmodel.cpp", 1190, __PRETTY_FUNCTION__).warning("node: the row does not exist"); | - |
919 | return 0; never executed: return 0; | 0 |
920 | } | - |
921 | | - |
922 | return const_cast<QDirNode*>(&p->children.at(row)); executed: return const_cast<QDirNode*>(&p->children.at(row)); Execution Count:16797 | 16797 |
923 | } | - |
924 | | - |
925 | QVector<QDirModelPrivate::QDirNode> QDirModelPrivate::children(QDirNode *parent, bool stat) const | - |
926 | { | - |
927 | qt_noop(); | - |
928 | QFileInfoList infoList; | - |
929 | if (parent == &root) { evaluated: parent == &root yes Evaluation Count:43 | yes Evaluation Count:556 |
| 43-556 |
930 | parent = 0; | - |
931 | infoList = QDir::drives(); | - |
932 | } else if (parent->info.isDir()) { executed: } Execution Count:43 partially evaluated: parent->info.isDir() yes Evaluation Count:556 | no Evaluation Count:0 |
| 0-556 |
933 | | - |
934 | if (parent->info.isSymLink() && resolveSymlinks) { evaluated: parent->info.isSymLink() yes Evaluation Count:2 | yes Evaluation Count:554 |
partially evaluated: resolveSymlinks yes Evaluation Count:2 | no Evaluation Count:0 |
| 0-554 |
935 | QString link = parent->info.symLinkTarget(); | - |
936 | if (link.size() > 1 && link.at(link.size() - 1) == QDir::separator()) partially evaluated: link.size() > 1 yes Evaluation Count:2 | no Evaluation Count:0 |
partially evaluated: link.at(link.size() - 1) == QDir::separator() no Evaluation Count:0 | yes Evaluation Count:2 |
| 0-2 |
937 | link.chop(1); never executed: link.chop(1); | 0 |
938 | if (stat) partially evaluated: stat yes Evaluation Count:2 | no Evaluation Count:0 |
| 0-2 |
939 | infoList = entryInfoList(link); executed: infoList = entryInfoList(link); Execution Count:2 | 2 |
940 | else | - |
941 | infoList = QDir(link).entryInfoList(nameFilters, QDir::AllEntries | QDir::System); never executed: infoList = QDir(link).entryInfoList(nameFilters, QDir::AllEntries | QDir::System); | 0 |
942 | } else { | - |
943 | if (stat) partially evaluated: stat yes Evaluation Count:554 | no Evaluation Count:0 |
| 0-554 |
944 | infoList = entryInfoList(parent->info.absoluteFilePath()); executed: infoList = entryInfoList(parent->info.absoluteFilePath()); Execution Count:554 | 554 |
945 | else | - |
946 | infoList = QDir(parent->info.absoluteFilePath()).entryInfoList(nameFilters, QDir::AllEntries | QDir::System); never executed: infoList = QDir(parent->info.absoluteFilePath()).entryInfoList(nameFilters, QDir::AllEntries | QDir::System); | 0 |
947 | } | - |
948 | } | - |
949 | | - |
950 | QVector<QDirNode> nodes(infoList.count()); | - |
951 | for (int i = 0; i < infoList.count(); ++i) { evaluated: i < infoList.count() yes Evaluation Count:10396 | yes Evaluation Count:599 |
| 599-10396 |
952 | QDirNode &node = nodes[i]; | - |
953 | node.parent = parent; | - |
954 | node.info = infoList.at(i); | - |
955 | node.populated = false; | - |
956 | node.stat = shouldStat; | - |
957 | } executed: } Execution Count:10396 | 10396 |
958 | | - |
959 | return nodes; executed: return nodes; Execution Count:599 | 599 |
960 | } | - |
961 | | - |
962 | void QDirModelPrivate::_q_refresh() | - |
963 | { | - |
964 | QDirModel * const q = q_func(); | - |
965 | q->refresh(toBeRefreshed); | - |
966 | toBeRefreshed = QModelIndex(); | - |
967 | } | 0 |
968 | | - |
969 | void QDirModelPrivate::savePersistentIndexes() | - |
970 | { | - |
971 | QDirModel * const q = q_func(); | - |
972 | savedPersistent.clear(); | - |
973 | for (QForeachContainer<__typeof__(persistent.indexes)> _container_(persistent.indexes); !_container_.brk && _container_.i != _container_.e; __extension__ ({ ++_container_.brk; ++_container_.i; })) for (QPersistentModelIndexData *data = *_container_.i;; __extension__ ({--_container_.brk; break;})) { | - |
974 | SavedPersistent saved; | - |
975 | QModelIndex index = data->index; | - |
976 | saved.path = q->filePath(index); | - |
977 | saved.column = index.column(); | - |
978 | saved.data = data; | - |
979 | saved.index = index; | - |
980 | savedPersistent.append(saved); | - |
981 | } executed: } Execution Count:21 | 21 |
982 | } executed: } Execution Count:38 | 38 |
983 | | - |
984 | void QDirModelPrivate::restorePersistentIndexes() | - |
985 | { | - |
986 | QDirModel * const q = q_func(); | - |
987 | bool allow = allowAppendChild; | - |
988 | allowAppendChild = false; | - |
989 | for (int i = 0; i < savedPersistent.count(); ++i) { evaluated: i < savedPersistent.count() yes Evaluation Count:21 | yes Evaluation Count:38 |
| 21-38 |
990 | QPersistentModelIndexData *data = savedPersistent.at(i).data; | - |
991 | QString path = savedPersistent.at(i).path; | - |
992 | int column = savedPersistent.at(i).column; | - |
993 | QModelIndex idx = q->index(path, column); | - |
994 | if (idx != data->index || data->model == 0) { evaluated: idx != data->index yes Evaluation Count:17 | yes Evaluation Count:4 |
evaluated: data->model == 0 yes Evaluation Count:2 | yes Evaluation Count:2 |
| 2-17 |
995 | | - |
996 | persistent.indexes.remove(data->index); | - |
997 | data->index = idx; | - |
998 | data->model = q; | - |
999 | if (idx.isValid()) evaluated: idx.isValid() yes Evaluation Count:17 | yes Evaluation Count:2 |
| 2-17 |
1000 | persistent.indexes.insert(idx, data); executed: persistent.indexes.insert(idx, data); Execution Count:17 | 17 |
1001 | } executed: } Execution Count:19 | 19 |
1002 | } executed: } Execution Count:21 | 21 |
1003 | savedPersistent.clear(); | - |
1004 | allowAppendChild = allow; | - |
1005 | } executed: } Execution Count:38 | 38 |
1006 | | - |
1007 | QFileInfoList QDirModelPrivate::entryInfoList(const QString &path) const | - |
1008 | { | - |
1009 | const QDir dir(path); | - |
1010 | return dir.entryInfoList(nameFilters, filters, sort); executed: return dir.entryInfoList(nameFilters, filters, sort); Execution Count:556 | 556 |
1011 | } | - |
1012 | | - |
1013 | QStringList QDirModelPrivate::entryList(const QString &path) const | - |
1014 | { | - |
1015 | const QDir dir(path); | - |
1016 | return dir.entryList(nameFilters, filters, sort); executed: return dir.entryList(nameFilters, filters, sort); Execution Count:4 | 4 |
1017 | } | - |
1018 | | - |
1019 | QString QDirModelPrivate::name(const QModelIndex &index) const | - |
1020 | { | - |
1021 | const QDirNode *n = node(index); | - |
1022 | const QFileInfo info = n->info; | - |
1023 | if (info.isRoot()) { evaluated: info.isRoot() yes Evaluation Count:20 | yes Evaluation Count:787 |
| 20-787 |
1024 | QString name = info.absoluteFilePath(); | - |
1025 | | - |
1026 | | - |
1027 | | - |
1028 | | - |
1029 | | - |
1030 | | - |
1031 | return name; executed: return name; Execution Count:20 | 20 |
1032 | } | - |
1033 | return info.fileName(); executed: return info.fileName(); Execution Count:787 | 787 |
1034 | } | - |
1035 | | - |
1036 | QString QDirModelPrivate::size(const QModelIndex &index) const | - |
1037 | { | - |
1038 | const QDirNode *n = node(index); | - |
1039 | if (n->info.isDir()) { evaluated: n->info.isDir() yes Evaluation Count:155 | yes Evaluation Count:452 |
| 155-452 |
1040 | | - |
1041 | | - |
1042 | | - |
1043 | return QLatin1String(""); executed: return QLatin1String(""); Execution Count:155 | 155 |
1044 | | - |
1045 | | - |
1046 | | - |
1047 | | - |
1048 | | - |
1049 | } | - |
1050 | | - |
1051 | | - |
1052 | | - |
1053 | const quint64 kb = 1024; | - |
1054 | const quint64 mb = 1024 * kb; | - |
1055 | const quint64 gb = 1024 * mb; | - |
1056 | const quint64 tb = 1024 * gb; | - |
1057 | quint64 bytes = n->info.size(); | - |
1058 | if (bytes >= tb) evaluated: bytes >= tb yes Evaluation Count:1 | yes Evaluation Count:451 |
| 1-451 |
1059 | return QFileSystemModel::tr("%1 TB").arg(QLocale().toString(qreal(bytes) / tb, 'f', 3)); executed: return QFileSystemModel::tr("%1 TB").arg(QLocale().toString(qreal(bytes) / tb, 'f', 3)); Execution Count:1 | 1 |
1060 | if (bytes >= gb) partially evaluated: bytes >= gb no Evaluation Count:0 | yes Evaluation Count:451 |
| 0-451 |
1061 | 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 |
1062 | if (bytes >= mb) evaluated: bytes >= mb yes Evaluation Count:9 | yes Evaluation Count:442 |
| 9-442 |
1063 | return QFileSystemModel::tr("%1 MB").arg(QLocale().toString(qreal(bytes) / mb, 'f', 1)); executed: return QFileSystemModel::tr("%1 MB").arg(QLocale().toString(qreal(bytes) / mb, 'f', 1)); Execution Count:9 | 9 |
1064 | if (bytes >= kb) evaluated: bytes >= kb yes Evaluation Count:341 | yes Evaluation Count:101 |
| 101-341 |
1065 | return QFileSystemModel::tr("%1 KB").arg(QLocale().toString(bytes / kb)); executed: return QFileSystemModel::tr("%1 KB").arg(QLocale().toString(bytes / kb)); Execution Count:341 | 341 |
1066 | return QFileSystemModel::tr("%1 byte(s)").arg(QLocale().toString(bytes)); executed: return QFileSystemModel::tr("%1 byte(s)").arg(QLocale().toString(bytes)); Execution Count:101 | 101 |
1067 | } | - |
1068 | | - |
1069 | QString QDirModelPrivate::type(const QModelIndex &index) const | - |
1070 | { | - |
1071 | return iconProvider->type(node(index)->info); executed: return iconProvider->type(node(index)->info); Execution Count:604 | 604 |
1072 | } | - |
1073 | | - |
1074 | QString QDirModelPrivate::time(const QModelIndex &index) const | - |
1075 | { | - |
1076 | | - |
1077 | return node(index)->info.lastModified().toString(Qt::LocalDate); executed: return node(index)->info.lastModified().toString(Qt::LocalDate); Execution Count:604 | 604 |
1078 | | - |
1079 | | - |
1080 | | - |
1081 | | - |
1082 | } | - |
1083 | | - |
1084 | void QDirModelPrivate::appendChild(QDirModelPrivate::QDirNode *parent, const QString &path) const | - |
1085 | { | - |
1086 | QDirModelPrivate::QDirNode node; | - |
1087 | node.populated = false; | - |
1088 | node.stat = shouldStat; | - |
1089 | node.parent = (parent == &root ? 0 : parent); partially evaluated: parent == &root no Evaluation Count:0 | yes Evaluation Count:12 |
| 0-12 |
1090 | node.info = QFileInfo(path); | - |
1091 | node.info.setCaching(true); | - |
1092 | | - |
1093 | | - |
1094 | | - |
1095 | QDirModelPrivate *that = const_cast<QDirModelPrivate *>(this); | - |
1096 | that->savePersistentIndexes(); | - |
1097 | parent->children.append(node); | - |
1098 | for (int i = 0; i < parent->children.count(); ++i) { evaluated: i < parent->children.count() yes Evaluation Count:20 | yes Evaluation Count:12 |
| 12-20 |
1099 | QDirNode *childNode = &parent->children[i]; | - |
1100 | for (int j = 0; j < childNode->children.count(); ++j) partially evaluated: j < childNode->children.count() no Evaluation Count:0 | yes Evaluation Count:20 |
| 0-20 |
1101 | childNode->children[j].parent = childNode; never executed: childNode->children[j].parent = childNode; | 0 |
1102 | } executed: } Execution Count:20 | 20 |
1103 | that->restorePersistentIndexes(); | - |
1104 | } executed: } Execution Count:12 | 12 |
1105 | | - |
1106 | QFileInfo QDirModelPrivate::resolvedInfo(QFileInfo info) | - |
1107 | { | - |
1108 | | - |
1109 | | - |
1110 | | - |
1111 | | - |
1112 | QStringList paths; | - |
1113 | do { | - |
1114 | QFileInfo link(info.symLinkTarget()); | - |
1115 | if (link.isRelative()) partially evaluated: link.isRelative() no Evaluation Count:0 | yes Evaluation Count:1 |
| 0-1 |
1116 | info.setFile(info.absolutePath(), link.filePath()); never executed: info.setFile(info.absolutePath(), link.filePath()); | 0 |
1117 | else | - |
1118 | info = link; executed: info = link; Execution Count:1 | 1 |
1119 | if (paths.contains(info.absoluteFilePath())) partially evaluated: paths.contains(info.absoluteFilePath()) no Evaluation Count:0 | yes Evaluation Count:1 |
| 0-1 |
1120 | return QFileInfo(); never executed: return QFileInfo(); | 0 |
1121 | paths.append(info.absoluteFilePath()); | - |
1122 | } while (info.isSymLink()); executed: } Execution Count:1 partially evaluated: info.isSymLink() no Evaluation Count:0 | yes Evaluation Count:1 |
| 0-1 |
1123 | return info; executed: return info; Execution Count:1 | 1 |
1124 | | - |
1125 | } | - |
1126 | | - |
1127 | | - |
1128 | | - |
1129 | | - |
| | |