| Line | Source | Count |
| 1 | | - |
| 2 | | - |
| 3 | QFileInfo QFileSystemModel::fileInfo(const QModelIndex &index) const | - |
| 4 | { | - |
| 5 | const QFileSystemModelPrivate * const d = d_func(); | - |
| 6 | return d->node(index)->fileInfo(); | - |
| 7 | } | - |
| 8 | bool QFileSystemModel::remove(const QModelIndex &aindex) | - |
| 9 | { | - |
| 10 | const QString path = filePath(aindex); | - |
| 11 | const bool success = QFileInfo(path).isFile() ? QFile::remove(path) : QDir(path).removeRecursively(); | - |
| 12 | | - |
| 13 | if (success) { | - |
| 14 | QFileSystemModelPrivate * d = const_cast<QFileSystemModelPrivate*>(d_func()); | - |
| 15 | d->fileInfoGatherer.removePath(path); | - |
| 16 | } | - |
| 17 | | - |
| 18 | return success; | - |
| 19 | } | - |
| 20 | | - |
| 21 | | - |
| 22 | | - |
| 23 | | - |
| 24 | QFileSystemModel::QFileSystemModel(QObject *parent) | - |
| 25 | : QAbstractItemModel(*new QFileSystemModelPrivate, parent) | - |
| 26 | { | - |
| 27 | QFileSystemModelPrivate * const d = d_func(); | - |
| 28 | d->init(); | - |
| 29 | } | - |
| 30 | | - |
| 31 | | - |
| 32 | | - |
| 33 | | - |
| 34 | QFileSystemModel::QFileSystemModel(QFileSystemModelPrivate &dd, QObject *parent) | - |
| 35 | : QAbstractItemModel(dd, parent) | - |
| 36 | { | - |
| 37 | QFileSystemModelPrivate * const d = d_func(); | - |
| 38 | d->init(); | - |
| 39 | } | - |
| 40 | | - |
| 41 | | - |
| 42 | | - |
| 43 | | - |
| 44 | QFileSystemModel::~QFileSystemModel() | - |
| 45 | { | - |
| 46 | } | - |
| 47 | | - |
| 48 | | - |
| 49 | | - |
| 50 | | - |
| 51 | QModelIndex QFileSystemModel::index(int row, int column, const QModelIndex &parent) const | - |
| 52 | { | - |
| 53 | const QFileSystemModelPrivate * const d = d_func(); | - |
| 54 | if (row < 0 || column < 0 || row >= rowCount(parent) || column >= columnCount(parent)) | - |
| 55 | return QModelIndex(); | - |
| 56 | | - |
| 57 | | - |
| 58 | QFileSystemModelPrivate::QFileSystemNode *parentNode = (d->indexValid(parent) ? d->node(parent) : | - |
| 59 | const_cast<QFileSystemModelPrivate::QFileSystemNode*>(&d->root)); | - |
| 60 | ((!(parentNode)) ? qt_assert("parentNode",__FILE__,250256) : qt_noop()); | - |
| 61 | | - |
| 62 | | - |
| 63 | const QString &childName = parentNode->visibleChildren.at(d->translateVisibleLocation(parentNode, row)); | - |
| 64 | const QFileSystemModelPrivate::QFileSystemNode *indexNode = parentNode->children.value(childName); | - |
| 65 | ((!(indexNode)) ? qt_assert("indexNode",__FILE__,255261) : qt_noop()); | - |
| 66 | | - |
| 67 | return createIndex(row, column, const_cast<QFileSystemModelPrivate::QFileSystemNode*>(indexNode)); | - |
| 68 | } | - |
| 69 | | - |
| 70 | | - |
| 71 | | - |
| 72 | | - |
| 73 | QModelIndex QFileSystemModel::sibling(int row, int column, const QModelIndex &idx) const | - |
| 74 | { | - |
| 75 | if (row == idx.row()| TRUE | never evaluated | | FALSE | never evaluated |
&& column < QFileSystemModelPrivate::NumColumns| TRUE | never evaluated | | FALSE | never evaluated |
) { | 0 |
| 76 | | - |
| 77 | return never executed: return createIndex(row, column, idx.internalPointer()); createIndex(row, column, idx.internalPointer());never executed: return createIndex(row, column, idx.internalPointer()); | 0 |
| 78 | } else { | - |
| 79 | | - |
| 80 | | - |
| 81 | return never executed: return QAbstractItemModel::sibling(row, column, idx); QAbstractItemModel::sibling(row, column, idx);never executed: return QAbstractItemModel::sibling(row, column, idx); | 0 |
| 82 | } | - |
| 83 | } | - |
| 84 | | - |
| 85 | | - |
| 86 | | - |
| 87 | | - |
| 88 | | - |
| 89 | | - |
| 90 | QModelIndex QFileSystemModel::index(const QString &path, int column) const | - |
| 91 | { | - |
| 92 | const QFileSystemModelPrivate * const d = d_func(); | - |
| 93 | QFileSystemModelPrivate::QFileSystemNode *node = d->node(path, false); | - |
| 94 | return d->index(node, column); | - |
| 95 | } | - |
| 96 | | - |
| 97 | | - |
| 98 | | - |
| 99 | | - |
| 100 | | - |
| 101 | | - |
| 102 | QFileSystemModelPrivate::QFileSystemNode *QFileSystemModelPrivate::node(const QModelIndex &index) const | - |
| 103 | { | - |
| 104 | if (!index.isValid()) | - |
| 105 | return const_cast<QFileSystemNode*>(&root); | - |
| 106 | QFileSystemModelPrivate::QFileSystemNode *indexNode = static_cast<QFileSystemModelPrivate::QFileSystemNode*>(index.internalPointer()); | - |
| 107 | ((!(indexNode)) ? qt_assert("indexNode",__FILE__,282303) : qt_noop()); | - |
| 108 | return indexNode; | - |
| 109 | } | - |
| 110 | QFileSystemModelPrivate::QFileSystemNode *QFileSystemModelPrivate::node(const QString &path, bool fetch) const | - |
| 111 | { | - |
| 112 | const QFileSystemModel * const q = q_func(); | - |
| 113 | (void)q;; | - |
| 114 | if (path.isEmpty()| TRUE | never evaluated | | FALSE | never evaluated |
|| path == myComputer()| TRUE | never evaluated | | FALSE | never evaluated |
|| path.startsWith(QLatin1Char(':'))| TRUE | never evaluated | | FALSE | never evaluated |
) | 0 |
| 115 | return never executed: return const_cast<QFileSystemModelPrivate::QFileSystemNode*>(&root); const_cast<QFileSystemModelPrivate::QFileSystemNode*>(&root);never executed: return const_cast<QFileSystemModelPrivate::QFileSystemNode*>(&root); | 0 |
| 116 | | - |
| 117 | | - |
| 118 | QString absolutePath; | - |
| 119 | | - |
| 120 | | - |
| 121 | | - |
| 122 | QString longPath = path; | - |
| 123 | | - |
| 124 | if (longPath == rootDir.path()| TRUE | never evaluated | | FALSE | never evaluated |
) | 0 |
| 125 | absolutePath = rootDir.absolutePath(); never executed: absolutePath = rootDir.absolutePath(); | 0 |
| 126 | else | - |
| 127 | absolutePath = QDir(longPath).absolutePath(); never executed: absolutePath = QDir(longPath).absolutePath(); | 0 |
| 128 | | - |
| 129 | | - |
| 130 | QStringList pathElements = absolutePath.split(QLatin1Char('/'), QString::SkipEmptyParts); | - |
| 131 | if ((| TRUE | never evaluated | | FALSE | never evaluated |
pathElements.isEmpty())| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 132 | | - |
| 133 | && QDir::fromNativeSeparators(longPath) != QLatin1String("/")| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 134 | | - |
| 135 | ) | - |
| 136 | return never executed: return const_cast<QFileSystemModelPrivate::QFileSystemNode*>(&root); const_cast<QFileSystemModelPrivate::QFileSystemNode*>(&root);never executed: return const_cast<QFileSystemModelPrivate::QFileSystemNode*>(&root); | 0 |
| 137 | QModelIndex index = QModelIndex(); | - |
| 138 | QString elementPath; | - |
| 139 | QChar separator = QLatin1Char('/'); | - |
| 140 | QString trailingSeparator; | - |
| 141 | if (absolutePath[0] == QLatin1Char('/')| TRUE | never evaluated | | FALSE | never evaluated |
) | 0 |
| 142 | pathElements.prepend(QLatin1String("/")); never executed: pathElements.prepend(QLatin1String("/")); | 0 |
| 143 | | - |
| 144 | | - |
| 145 | QFileSystemModelPrivate::QFileSystemNode *parent = node(index); | - |
| 146 | | - |
| 147 | for (int i = 0; i < pathElements.count()| TRUE | never evaluated | | FALSE | never evaluated |
; ++i) { | 0 |
| 148 | QString element = pathElements.at(i); | - |
| 149 | if (i != 0| TRUE | never evaluated | | FALSE | never evaluated |
) | 0 |
| 150 | elementPath.append(separator); never executed: elementPath.append(separator); | 0 |
| 151 | elementPath.append(element); | - |
| 152 | if (i == pathElements.count() - 1| TRUE | never evaluated | | FALSE | never evaluated |
) | 0 |
| 153 | elementPath.append(trailingSeparator); never executed: elementPath.append(trailingSeparator); | 0 |
| 154 | bool alreadyExisted = parent->children.contains(element); | - |
| 155 | | - |
| 156 | | - |
| 157 | | - |
| 158 | if (alreadyExisted| TRUE | never evaluated | | FALSE | never evaluated |
) { | 0 |
| 159 | if ((| TRUE | never evaluated | | FALSE | never evaluated |
parent->children.count() == 0)| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 160 | || (parent->caseSensitive()| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 161 | && parent->children.value(element)->fileName != element| TRUE | never evaluated | | FALSE | never evaluated |
) | 0 |
| 162 | || (!parent->caseSensitive()| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 163 | && parent->children.value(element)->fileName.toLower() != element.toLower()| TRUE | never evaluated | | FALSE | never evaluated |
)) | 0 |
| 164 | alreadyExisted = false; never executed: alreadyExisted = false; | 0 |
| 165 | } never executed: end of block | 0 |
| 166 | | - |
| 167 | QFileSystemModelPrivate::QFileSystemNode *node; | - |
| 168 | if (!alreadyExisted| TRUE | never evaluated | | FALSE | never evaluated |
) { | 0 |
| 169 | | - |
| 170 | | - |
| 171 | QFileInfo info(elementPath); | - |
| 172 | if (!info.exists()| TRUE | never evaluated | | FALSE | never evaluated |
) | 0 |
| 173 | return never executed: return const_cast<QFileSystemModelPrivate::QFileSystemNode*>(&root); const_cast<QFileSystemModelPrivate::QFileSystemNode*>(&root);never executed: return const_cast<QFileSystemModelPrivate::QFileSystemNode*>(&root); | 0 |
| 174 | QFileSystemModelPrivate *p = const_cast<QFileSystemModelPrivate*>(this); | - |
| 175 | node = p->addNode(parent, element,info); | - |
| 176 | | - |
| 177 | node->populate(fileInfoGatherer.getInfo(info)); | - |
| 178 | | - |
| 179 | } never executed: end of block else { | 0 |
| 180 | node = parent->children.value(element); | - |
| 181 | } never executed: end of block | 0 |
| 182 | | - |
| 183 | ((!(node)) ? qt_assert("node",__FILE__,451472) : qt_noop()); | - |
| 184 | if (!node->isVisible| TRUE | never evaluated | | FALSE | never evaluated |
) { | 0 |
| 185 | | - |
| 186 | if (alreadyExisted| TRUE | never evaluated | | FALSE | never evaluated |
&& node->hasInformation()| TRUE | never evaluated | | FALSE | never evaluated |
&& !fetch| TRUE | never evaluated | | FALSE | never evaluated |
) | 0 |
| 187 | return never executed: return const_cast<QFileSystemModelPrivate::QFileSystemNode*>(&root); const_cast<QFileSystemModelPrivate::QFileSystemNode*>(&root);never executed: return const_cast<QFileSystemModelPrivate::QFileSystemNode*>(&root); | 0 |
| 188 | | - |
| 189 | QFileSystemModelPrivate *p = const_cast<QFileSystemModelPrivate*>(this); | - |
| 190 | p->addVisibleFiles(parent, QStringList(element)); | - |
| 191 | if (!p->bypassFilters.contains(node)| TRUE | never evaluated | | FALSE | never evaluated |
) | 0 |
| 192 | p->bypassFilters[node] = 1; never executed: p->bypassFilters[node] = 1; | 0 |
| 193 | QString dir = q->filePath(this->index(parent)); | - |
| 194 | if (!node->hasInformation()| TRUE | never evaluated | | FALSE | never evaluated |
&& fetch| TRUE | never evaluated | | FALSE | never evaluated |
) { | 0 |
| 195 | Fetching f;f .dir= { std::move(dir; | - |
| f.file =), std::move(element; | |
| f.node =), node ;}; | |
| 196 | p->toFetch.append(std::move(f);)); | - |
| 197 | p->fetchingTimer.start(0, const_cast<QFileSystemModel*>(q)); | - |
| 198 | } never executed: end of block | 0 |
| 199 | } never executed: end of block | 0 |
| 200 | parent = node; | - |
| 201 | } never executed: end of block | 0 |
| 202 | | - |
| 203 | return never executed: return parent; parent;never executed: return parent; | 0 |
| 204 | } | - |
| 205 | | - |
| 206 | | - |
| 207 | | - |
| 208 | | - |
| 209 | void QFileSystemModel::timerEvent(QTimerEvent *event) | - |
| 210 | { | - |
| 211 | QFileSystemModelPrivate * const d = d_func(); | - |
| 212 | if (event->timerId() == d->fetchingTimer.timerId()) { | - |
| 213 | d->fetchingTimer.stop(); | - |
| 214 | | - |
| 215 | for (int i = 0; i < d->toFetch.count(); ++i) { | - |
| 216 | const QFileSystemModelPrivate::QFileSystemNode *node = d->toFetch.at(i).node; | - |
| 217 | if (!node->hasInformation()) { | - |
| 218 | d->fileInfoGatherer.fetchExtendedInformation(d->toFetch.at(i).dir, | - |
| 219 | QStringList(d->toFetch.at(i).file)); | - |
| 220 | } else { | - |
| 221 | | - |
| 222 | } | - |
| 223 | } | - |
| 224 | | - |
| 225 | d->toFetch.clear(); | - |
| 226 | } | - |
| 227 | } | - |
| 228 | | - |
| 229 | | - |
| 230 | | - |
| 231 | | - |
| 232 | | - |
| 233 | bool QFileSystemModel::isDir(const QModelIndex &index) const | - |
| 234 | { | - |
| 235 | | - |
| 236 | const QFileSystemModelPrivate * const d = d_func(); | - |
| 237 | if (!index.isValid()) | - |
| 238 | return true; | - |
| 239 | QFileSystemModelPrivate::QFileSystemNode *n = d->node(index); | - |
| 240 | if (n->hasInformation()) | - |
| 241 | return n->isDir(); | - |
| 242 | return fileInfo(index).isDir(); | - |
| 243 | } | - |
| 244 | | - |
| 245 | | - |
| 246 | | - |
| 247 | | - |
| 248 | qint64 QFileSystemModel::size(const QModelIndex &index) const | - |
| 249 | { | - |
| 250 | const QFileSystemModelPrivate * const d = d_func(); | - |
| 251 | if (!index.isValid()) | - |
| 252 | return 0; | - |
| 253 | return d->node(index)->size(); | - |
| 254 | } | - |
| 255 | | - |
| 256 | | - |
| 257 | | - |
| 258 | | - |
| 259 | QString QFileSystemModel::type(const QModelIndex &index) const | - |
| 260 | { | - |
| 261 | const QFileSystemModelPrivate * const d = d_func(); | - |
| 262 | if (!index.isValid()) | - |
| 263 | return QString(); | - |
| 264 | return d->node(index)->type(); | - |
| 265 | } | - |
| 266 | | - |
| 267 | | - |
| 268 | | - |
| 269 | | - |
| 270 | QDateTime QFileSystemModel::lastModified(const QModelIndex &index) const | - |
| 271 | { | - |
| 272 | const QFileSystemModelPrivate * const d = d_func(); | - |
| 273 | if (!index.isValid()) | - |
| 274 | return QDateTime(); | - |
| 275 | return d->node(index)->lastModified(); | - |
| 276 | } | - |
| 277 | | - |
| 278 | | - |
| 279 | | - |
| 280 | | - |
| 281 | QModelIndex QFileSystemModel::parent(const QModelIndex &index) const | - |
| 282 | { | - |
| 283 | const QFileSystemModelPrivate * const d = d_func(); | - |
| 284 | if (!d->indexValid(index)) | - |
| 285 | return QModelIndex(); | - |
| 286 | | - |
| 287 | QFileSystemModelPrivate::QFileSystemNode *indexNode = d->node(index); | - |
| 288 | ((!(indexNode != 0)) ? qt_assert("indexNode != 0",__FILE__,559577) : qt_noop()); | - |
| 289 | QFileSystemModelPrivate::QFileSystemNode *parentNode = indexNode->parent; | - |
| 290 | if (parentNode == 0 || parentNode == &d->root) | - |
| 291 | return QModelIndex(); | - |
| 292 | | - |
| 293 | | - |
| 294 | QFileSystemModelPrivate::QFileSystemNode *grandParentNode = parentNode->parent; | - |
| 295 | ((!(grandParentNode->children.contains(parentNode->fileName))) ? qt_assert("grandParentNode->children.contains(parentNode->fileName)",__FILE__,566584) : qt_noop()); | - |
| 296 | int visualRow = d->translateVisibleLocation(grandParentNode, grandParentNode->visibleLocation(grandParentNode->children.value(parentNode->fileName)->fileName)); | - |
| 297 | if (visualRow == -1) | - |
| 298 | return QModelIndex(); | - |
| 299 | return createIndex(visualRow, 0, parentNode); | - |
| 300 | } | - |
| 301 | | - |
| 302 | | - |
| 303 | | - |
| 304 | | - |
| 305 | | - |
| 306 | | - |
| 307 | QModelIndex QFileSystemModelPrivate::index(const QFileSystemModelPrivate::QFileSystemNode *node, int column) const | - |
| 308 | { | - |
| 309 | const QFileSystemModel * const q = q_func(); | - |
| 310 | QFileSystemModelPrivate::QFileSystemNode *parentNode = (node ? node->parent : 0); | - |
| 311 | if (node == &root || !parentNode) | - |
| 312 | return QModelIndex(); | - |
| 313 | | - |
| 314 | | - |
| 315 | ((!(node)) ? qt_assert("node",__FILE__,586604) : qt_noop()); | - |
| 316 | if (!node->isVisible) | - |
| 317 | return QModelIndex(); | - |
| 318 | | - |
| 319 | int visualRow = translateVisibleLocation(parentNode, parentNode->visibleLocation(node->fileName)); | - |
| 320 | return q->createIndex(visualRow, column, const_cast<QFileSystemNode*>(node)); | - |
| 321 | } | - |
| 322 | | - |
| 323 | | - |
| 324 | | - |
| 325 | | - |
| 326 | bool QFileSystemModel::hasChildren(const QModelIndex &parent) const | - |
| 327 | { | - |
| 328 | const QFileSystemModelPrivate * const d = d_func(); | - |
| 329 | if (parent.column() > 0) | - |
| 330 | return false; | - |
| 331 | | - |
| 332 | if (!parent.isValid()) | - |
| 333 | return true; | - |
| 334 | | - |
| 335 | const QFileSystemModelPrivate::QFileSystemNode *indexNode = d->node(parent); | - |
| 336 | ((!(indexNode)) ? qt_assert("indexNode",__FILE__,607625) : qt_noop()); | - |
| 337 | return (indexNode->isDir()); | - |
| 338 | } | - |
| 339 | | - |
| 340 | | - |
| 341 | | - |
| 342 | | - |
| 343 | bool QFileSystemModel::canFetchMore(const QModelIndex &parent) const | - |
| 344 | { | - |
| 345 | const QFileSystemModelPrivate * const d = d_func(); | - |
| 346 | const QFileSystemModelPrivate::QFileSystemNode *indexNode = d->node(parent); | - |
| 347 | return (!indexNode->populatedChildren); | - |
| 348 | } | - |
| 349 | | - |
| 350 | | - |
| 351 | | - |
| 352 | | - |
| 353 | void QFileSystemModel::fetchMore(const QModelIndex &parent) | - |
| 354 | { | - |
| 355 | QFileSystemModelPrivate * const d = d_func(); | - |
| 356 | if (!d->setRootPath) | - |
| 357 | return; | - |
| 358 | QFileSystemModelPrivate::QFileSystemNode *indexNode = d->node(parent); | - |
| 359 | if (indexNode->populatedChildren) | - |
| 360 | return; | - |
| 361 | indexNode->populatedChildren = true; | - |
| 362 | | - |
| 363 | d->fileInfoGatherer.list(filePath(parent)); | - |
| 364 | | - |
| 365 | } | - |
| 366 | | - |
| 367 | | - |
| 368 | | - |
| 369 | | - |
| 370 | int QFileSystemModel::rowCount(const QModelIndex &parent) const | - |
| 371 | { | - |
| 372 | const QFileSystemModelPrivate * const d = d_func(); | - |
| 373 | if (parent.column() > 0) | - |
| 374 | return 0; | - |
| 375 | | - |
| 376 | if (!parent.isValid()) | - |
| 377 | return d->root.visibleChildren.count(); | - |
| 378 | | - |
| 379 | const QFileSystemModelPrivate::QFileSystemNode *parentNode = d->node(parent); | - |
| 380 | return parentNode->visibleChildren.count(); | - |
| 381 | } | - |
| 382 | | - |
| 383 | | - |
| 384 | | - |
| 385 | | - |
| 386 | int QFileSystemModel::columnCount(const QModelIndex &parent) const | - |
| 387 | { | - |
| 388 | return (parent.column() > 0) ? 0 : QFileSystemModelPrivate::NumColumns; | - |
| 389 | } | - |
| 390 | | - |
| 391 | | - |
| 392 | | - |
| 393 | | - |
| 394 | | - |
| 395 | | - |
| 396 | QVariant QFileSystemModel::myComputer(int role) const | - |
| 397 | { | - |
| 398 | | - |
| 399 | const QFileSystemModelPrivate * const d = d_func(); | - |
| 400 | | - |
| 401 | switch (role) { | - |
| 402 | case Qt::DisplayRole: | - |
| 403 | return QFileSystemModelPrivate::myComputer(); | - |
| 404 | | - |
| 405 | case Qt::DecorationRole: | - |
| 406 | return d->fileInfoGatherer.iconProvider()->icon(QFileIconProvider::Computer); | - |
| 407 | | - |
| 408 | } | - |
| 409 | return QVariant(); | - |
| 410 | } | - |
| 411 | | - |
| 412 | | - |
| 413 | | - |
| 414 | | - |
| 415 | QVariant QFileSystemModel::data(const QModelIndex &index, int role) const | - |
| 416 | { | - |
| 417 | const QFileSystemModelPrivate * const d = d_func(); | - |
| 418 | if (!index.isValid() || index.model() != this) | - |
| 419 | return QVariant(); | - |
| 420 | | - |
| 421 | switch (role) { | - |
| 422 | case Qt::EditRole: | - |
| 423 | case Qt::DisplayRole: | - |
| 424 | switch (index.column()) { | - |
| 425 | case 0: return d->displayName(index); | - |
| 426 | case 1: return d->size(index); | - |
| 427 | case 2: return d->type(index); | - |
| 428 | case 3: return d->time(index); | - |
| 429 | default: | - |
| 430 | QMessageLogger(__FILE__, 701719, __PRETTY_FUNCTION__).warning("data: invalid display value column %d", index.column()); | - |
| 431 | break; | - |
| 432 | } | - |
| 433 | break; | - |
| 434 | case FilePathRole: | - |
| 435 | return filePath(index); | - |
| 436 | case FileNameRole: | - |
| 437 | return d->name(index); | - |
| 438 | case Qt::DecorationRole: | - |
| 439 | if (index.column() == 0) { | - |
| 440 | QIcon icon = d->icon(index); | - |
| 441 | | - |
| 442 | if (icon.isNull()) { | - |
| 443 | if (d->node(index)->isDir()) | - |
| 444 | icon = d->fileInfoGatherer.iconProvider()->icon(QFileIconProvider::Folder); | - |
| 445 | else | - |
| 446 | icon = d->fileInfoGatherer.iconProvider()->icon(QFileIconProvider::File); | - |
| 447 | } | - |
| 448 | | - |
| 449 | return icon; | - |
| 450 | } | - |
| 451 | break; | - |
| 452 | case Qt::TextAlignmentRole: | - |
| 453 | if (index.column() == 1) | - |
| 454 | return Qt::AlignRight; | - |
| 455 | break; | - |
| 456 | case FilePermissions: | - |
| 457 | int p = permissions(index); | - |
| 458 | return p; | - |
| 459 | } | - |
| 460 | | - |
| 461 | return QVariant(); | - |
| 462 | } | - |
| 463 | | - |
| 464 | | - |
| 465 | | - |
| 466 | | - |
| 467 | QString QFileSystemModelPrivate::size(const QModelIndex &index) const | - |
| 468 | { | - |
| 469 | if (!index.isValid()) | - |
| 470 | return QString(); | - |
| 471 | const QFileSystemNode *n = node(index); | - |
| 472 | if (n->isDir()) { | - |
| 473 | | - |
| 474 | | - |
| 475 | | - |
| 476 | return QLatin1String(""); | - |
| 477 | | - |
| 478 | | - |
| 479 | | - |
| 480 | | - |
| 481 | | - |
| 482 | } | - |
| 483 | return size(n->size()); | - |
| 484 | } | - |
| 485 | | - |
| 486 | QString QFileSystemModelPrivate::size(qint64 bytes) | - |
| 487 | { | - |
| 488 | | - |
| 489 | | - |
| 490 | const qint64 kb = 1024; | - |
| 491 | const qint64 mb = 1024 * kb; | - |
| 492 | const qint64 gb = 1024 * mb; | - |
| 493 | const qint64 tb = 1024 * gb; | - |
| 494 | if (bytes >= tb) | - |
| 495 | return QFileSystemModel::tr("%1 TB").arg(QLocale().toString(qreal(bytes) / tb, 'f', 3)); | - |
| 496 | if (bytes >= gb) | - |
| 497 | return QFileSystemModel::tr("%1 GB").arg(QLocale().toString(qreal(bytes) / gb, 'f', 2)); | - |
| 498 | if (bytes >= mb) | - |
| 499 | return QFileSystemModel::tr("%1 MB").arg(QLocale().toString(qreal(bytes) / mb, 'f', 1)); | - |
| 500 | if (bytes >= kb) | - |
| 501 | return QFileSystemModel::tr("%1 KB").arg(QLocale().toString(bytes / kb)); | - |
| 502 | return QFileSystemModel::tr("%1 bytes").arg(QLocale().toString(bytes)); | - |
| 503 | } | - |
| 504 | | - |
| 505 | | - |
| 506 | | - |
| 507 | | - |
| 508 | QString QFileSystemModelPrivate::time(const QModelIndex &index) const | - |
| 509 | { | - |
| 510 | if (!index.isValid()) | - |
| 511 | return QString(); | - |
| 512 | | - |
| 513 | return node(index)->lastModified().toString(Qt::SystemLocaleDate); | - |
| 514 | | - |
| 515 | | - |
| 516 | | - |
| 517 | | - |
| 518 | } | - |
| 519 | | - |
| 520 | | - |
| 521 | | - |
| 522 | | - |
| 523 | QString QFileSystemModelPrivate::type(const QModelIndex &index) const | - |
| 524 | { | - |
| 525 | if (!index.isValid()) | - |
| 526 | return QString(); | - |
| 527 | return node(index)->type(); | - |
| 528 | } | - |
| 529 | | - |
| 530 | | - |
| 531 | | - |
| 532 | | - |
| 533 | QString QFileSystemModelPrivate::name(const QModelIndex &index) const | - |
| 534 | { | - |
| 535 | if (!index.isValid()) | - |
| 536 | return QString(); | - |
| 537 | QFileSystemNode *dirNode = node(index); | - |
| 538 | if ( | - |
| 539 | | - |
| 540 | fileInfoGatherer.resolveSymlinks() && | - |
| 541 | | - |
| 542 | !resolvedSymLinks.isEmpty() && dirNode->isSymLink( true)) { | - |
| 543 | QString fullPath = QDir::fromNativeSeparators(filePath(index)); | - |
| 544 | return resolvedSymLinks.value(fullPath, dirNode->fileName); | - |
| 545 | } | - |
| 546 | return dirNode->fileName; | - |
| 547 | } | - |
| 548 | | - |
| 549 | | - |
| 550 | | - |
| 551 | | - |
| 552 | QString QFileSystemModelPrivate::displayName(const QModelIndex &index) const | - |
| 553 | { | - |
| 554 | | - |
| 555 | | - |
| 556 | | - |
| 557 | | - |
| 558 | | - |
| 559 | return name(index); | - |
| 560 | } | - |
| 561 | | - |
| 562 | | - |
| 563 | | - |
| 564 | | - |
| 565 | QIcon QFileSystemModelPrivate::icon(const QModelIndex &index) const | - |
| 566 | { | - |
| 567 | if (!index.isValid()) | - |
| 568 | return QIcon(); | - |
| 569 | return node(index)->icon(); | - |
| 570 | } | - |
| 571 | | - |
| 572 | | - |
| 573 | | - |
| 574 | | - |
| 575 | bool QFileSystemModel::setData(const QModelIndex &idx, const QVariant &value, int role) | - |
| 576 | { | - |
| 577 | QFileSystemModelPrivate * const d = d_func(); | - |
| 578 | if (!idx.isValid() | - |
| 579 | || idx.column() != 0 | - |
| 580 | || role != Qt::EditRole | - |
| 581 | || (flags(idx) & Qt::ItemIsEditable) == 0) { | - |
| 582 | return false; | - |
| 583 | } | - |
| 584 | | - |
| 585 | QString newName = value.toString(); | - |
| 586 | QString oldName = idx.data().toString(); | - |
| 587 | if (newName == idx.data().toString()) | - |
| 588 | return true; | - |
| 589 | | - |
| 590 | const QString parentPath = filePath(parent(idx)); | - |
| 591 | | - |
| 592 | if (newName.isEmpty() | - |
| 593 | || QDir::toNativeSeparators(newName).contains(QDir::separator()) | - |
| 594 | || !QDir(parentPath).rename(oldName, newName)) { | - |
| 595 | | - |
| 596 | QMessageBox::information(0, QFileSystemModel::tr("Invalid filename"), | - |
| 597 | QFileSystemModel::tr("<b>The name \"%1\" can not be used.</b><p>Try using another name, with fewer characters or no punctuations marks.") | - |
| 598 | .arg(newName), | - |
| 599 | QMessageBox::Ok); | - |
| 600 | | - |
| 601 | return false; | - |
| 602 | } else { | - |
| 603 | QFileSystemModelPrivate::QFileSystemNode *indexNode = d->node(idx); | - |
| 604 | QFileSystemModelPrivate::QFileSystemNode *parentNode = indexNode->parent; | - |
| 605 | int visibleLocation = parentNode->visibleLocation(parentNode->children.value(indexNode->fileName)->fileName); | - |
| 606 | | - |
| 607 | parentNode->visibleChildren.removeAt(visibleLocation); | - |
| 608 | QFileSystemModelPrivate::QFileSystemNode * oldValue = parentNode->children.value(oldName); | - |
| 609 | parentNode->children[newName] = oldValue; | - |
| 610 | oldValue->fileName = newName; | - |
| 611 | oldValue->parent = parentNode; | - |
| 612 | | - |
| 613 | oldValue->populate(d->fileInfoGatherer.getInfo(QFileInfo(parentPath, newName))); | - |
| 614 | | - |
| 615 | oldValue->isVisible = true; | - |
| 616 | | - |
| 617 | parentNode->children.remove(oldName); | - |
| 618 | parentNode->visibleChildren.insert(visibleLocation, newName); | - |
| 619 | | - |
| 620 | d->delayedSort(); | - |
| 621 | fileRenamed(parentPath, oldName, newName); | - |
| 622 | } | - |
| 623 | return true; | - |
| 624 | } | - |
| 625 | | - |
| 626 | | - |
| 627 | | - |
| 628 | | - |
| 629 | QVariant QFileSystemModel::headerData(int section, Qt::Orientation orientation, int role) const | - |
| 630 | { | - |
| 631 | switch (role) { | - |
| 632 | case Qt::DecorationRole: | - |
| 633 | if (section == 0) { | - |
| 634 | | - |
| 635 | | - |
| 636 | QImage pixmap(16, 1, QImage::Format_Mono); | - |
| 637 | pixmap.fill(0); | - |
| 638 | pixmap.setAlphaChannel(pixmap.createAlphaMask()); | - |
| 639 | return pixmap; | - |
| 640 | } | - |
| 641 | break; | - |
| 642 | case Qt::TextAlignmentRole: | - |
| 643 | return Qt::AlignLeft; | - |
| 644 | } | - |
| 645 | | - |
| 646 | if (orientation != Qt::Horizontal || role != Qt::DisplayRole) | - |
| 647 | return QAbstractItemModel::headerData(section, orientation, role); | - |
| 648 | | - |
| 649 | QString returnValue; | - |
| 650 | switch (section) { | - |
| 651 | case 0: returnValue = tr("Name"); | - |
| 652 | break; | - |
| 653 | case 1: returnValue = tr("Size"); | - |
| 654 | break; | - |
| 655 | case 2: returnValue = | - |
| 656 | | - |
| 657 | | - |
| 658 | | - |
| 659 | tr("Type", "All other platforms"); | - |
| 660 | | - |
| 661 | break; | - |
| 662 | | - |
| 663 | | - |
| 664 | | - |
| 665 | | - |
| 666 | case 3: returnValue = tr("Date Modified"); | - |
| 667 | break; | - |
| 668 | default: return QVariant(); | - |
| 669 | } | - |
| 670 | return returnValue; | - |
| 671 | } | - |
| 672 | | - |
| 673 | | - |
| 674 | | - |
| 675 | | - |
| 676 | Qt::ItemFlags QFileSystemModel::flags(const QModelIndex &index) const | - |
| 677 | { | - |
| 678 | const QFileSystemModelPrivate * const d = d_func(); | - |
| 679 | Qt::ItemFlags flags = QAbstractItemModel::flags(index); | - |
| 680 | if (!index.isValid()) | - |
| 681 | return flags; | - |
| 682 | | - |
| 683 | QFileSystemModelPrivate::QFileSystemNode *indexNode = d->node(index); | - |
| 684 | if (d->nameFilterDisables && !d->passNameFilters(indexNode)) { | - |
| 685 | flags &= ~Qt::ItemIsEnabled; | - |
| 686 | | - |
| 687 | return flags; | - |
| 688 | } | - |
| 689 | | - |
| 690 | flags |= Qt::ItemIsDragEnabled; | - |
| 691 | if (d->readOnly) | - |
| 692 | return flags; | - |
| 693 | if ((index.column() == 0) && indexNode->permissions() & QFile::WriteUser) { | - |
| 694 | flags |= Qt::ItemIsEditable; | - |
| 695 | if (indexNode->isDir()) | - |
| 696 | flags |= Qt::ItemIsDropEnabled; | - |
| 697 | else | - |
| 698 | flags |= Qt::ItemNeverHasChildren; | - |
| 699 | } | - |
| 700 | return flags; | - |
| 701 | } | - |
| 702 | | - |
| 703 | | - |
| 704 | | - |
| 705 | | - |
| 706 | void QFileSystemModelPrivate::_q_performDelayedSort() | - |
| 707 | { | - |
| 708 | QFileSystemModel * const q = q_func(); | - |
| 709 | q->sort(sortColumn, sortOrder); | - |
| 710 | } | - |
| 711 | | - |
| 712 | | - |
| 713 | | - |
| 714 | | - |
| 715 | | - |
| 716 | | - |
| 717 | class QFileSystemModelSorter | - |
| 718 | { | - |
| 719 | public: | - |
| 720 | inline QFileSystemModelSorter(int column) : sortColumn(column) | - |
| 721 | { | - |
| 722 | naturalCompare.setNumericMode(true); | - |
| 723 | naturalCompare.setCaseSensitivity(Qt::CaseInsensitive); | - |
| 724 | } | - |
| 725 | | - |
| 726 | bool compareNodes(const QFileSystemModelPrivate::QFileSystemNode *l, | - |
| 727 | const QFileSystemModelPrivate::QFileSystemNode *r) const | - |
| 728 | { | - |
| 729 | switch (sortColumn) { | - |
| 730 | case 0: { | - |
| 731 | | - |
| 732 | | - |
| 733 | bool left = l->isDir(); | - |
| 734 | bool right = r->isDir(); | - |
| 735 | if (left ^ right) | - |
| 736 | return left; | - |
| 737 | | - |
| 738 | return naturalCompare.compare(l->fileName, r->fileName) < 0; | - |
| 739 | } | - |
| 740 | case 1: | - |
| 741 | { | - |
| 742 | | - |
| 743 | bool left = l->isDir(); | - |
| 744 | bool right = r->isDir(); | - |
| 745 | if (left ^ right) | - |
| 746 | return left; | - |
| 747 | | - |
| 748 | qint64 sizeDifference = l->size() - r->size(); | - |
| 749 | if (sizeDifference == 0) | - |
| 750 | return naturalCompare.compare(l->fileName, r->fileName) < 0; | - |
| 751 | | - |
| 752 | return sizeDifference < 0; | - |
| 753 | } | - |
| 754 | case 2: | - |
| 755 | { | - |
| 756 | int compare = naturalCompare.compare(l->type(), r->type()); | - |
| 757 | if (compare == 0) | - |
| 758 | return naturalCompare.compare(l->fileName, r->fileName) < 0; | - |
| 759 | | - |
| 760 | return compare < 0; | - |
| 761 | } | - |
| 762 | case 3: | - |
| 763 | { | - |
| 764 | if (l->lastModified() == r->lastModified()) | - |
| 765 | return naturalCompare.compare(l->fileName, r->fileName) < 0; | - |
| 766 | | - |
| 767 | return l->lastModified() < r->lastModified(); | - |
| 768 | } | - |
| 769 | } | - |
| 770 | ((!(false)) ? qt_assert("false",__FILE__,10511069) : qt_noop()); | - |
| 771 | return false; | - |
| 772 | } | - |
| 773 | | - |
| 774 | bool operator()(const QFileSystemModelPrivate::QFileSystemNode *l, | - |
| 775 | const QFileSystemModelPrivate::QFileSystemNode *r) const | - |
| 776 | { | - |
| 777 | return compareNodes(l, r); | - |
| 778 | } | - |
| 779 | | - |
| 780 | | - |
| 781 | private: | - |
| 782 | QCollator naturalCompare; | - |
| 783 | int sortColumn; | - |
| 784 | }; | - |
| 785 | | - |
| 786 | | - |
| 787 | | - |
| 788 | | - |
| 789 | | - |
| 790 | | - |
| 791 | void QFileSystemModelPrivate::sortChildren(int column, const QModelIndex &parent) | - |
| 792 | { | - |
| 793 | QFileSystemModel * const q = q_func(); | - |
| 794 | QFileSystemModelPrivate::QFileSystemNode *indexNode = node(parent); | - |
| 795 | if (indexNode->children.count() == 0) | - |
| 796 | return; | - |
| 797 | | - |
| 798 | QVector<QFileSystemModelPrivate::QFileSystemNode*> values; | - |
| 799 | QHash<QString, QFileSystemNode *>::const_iterator iterator; | - |
| 800 | for(iterator = indexNode->children.constBegin() ; iterator != indexNode->children.constEnd() ; ++iterator) { | - |
| 801 | if (filtersAcceptsNode(iterator.value())) { | - |
| 802 | values.append(iterator.value()); | - |
| 803 | } else { | - |
| 804 | iterator.value()->isVisible = false; | - |
| 805 | } | - |
| 806 | } | - |
| 807 | QFileSystemModelSorter ms(column); | - |
| 808 | std::sort(values.begin(), values.end(), ms); | - |
| 809 | | - |
| 810 | indexNode->visibleChildren.clear(); | - |
| 811 | | - |
| 812 | indexNode->dirtyChildrenIndex = -1; | - |
| 813 | const int numValues = values.count(); | - |
| 814 | indexNode->visibleChildren.reserve(numValues); | - |
| 815 | for (int i = 0; i < numValues; ++i) { | - |
| 816 | indexNode->visibleChildren.append(values.at(i)->fileName); | - |
| 817 | values.at(i)->isVisible = true; | - |
| 818 | } | - |
| 819 | | - |
| 820 | if (!disableRecursiveSort) { | - |
| 821 | for (int i = 0; i < q->rowCount(parent); ++i) { | - |
| 822 | const QModelIndex childIndex = q->index(i, 0, parent); | - |
| 823 | QFileSystemModelPrivate::QFileSystemNode *indexNode = node(childIndex); | - |
| 824 | | - |
| 825 | if (indexNode->isVisible) | - |
| 826 | sortChildren(column, childIndex); | - |
| 827 | } | - |
| 828 | } | - |
| 829 | } | - |
| 830 | | - |
| 831 | | - |
| 832 | | - |
| 833 | | - |
| 834 | void QFileSystemModel::sort(int column, Qt::SortOrder order) | - |
| 835 | { | - |
| 836 | QFileSystemModelPrivate * const d = d_func(); | - |
| 837 | if (d->sortOrder == order && d->sortColumn == column && !d->forceSort) | - |
| 838 | return; | - |
| 839 | | - |
| 840 | layoutAboutToBeChanged(); | - |
| 841 | QModelIndexList oldList = persistentIndexList(); | - |
| 842 | QVector<QPair<QFileSystemModelPrivate::QFileSystemNode*, int> > oldNodes; | - |
| 843 | const int nodeCount = oldList.count(); | - |
| 844 | oldNodes.reserve(nodeCount); | - |
| 845 | for (int i = 0; i < nodeCount; ++i) { | - |
| 846 | const QModelIndex &oldNode = oldList.at(i); | - |
| 847 | QPair<QFileSystemModelPrivate::QFileSystemNode*, int> pair(d->node(oldNode), oldNode.column()); | - |
| 848 | oldNodes.append(pair); | - |
| 849 | } | - |
| 850 | | - |
| 851 | if (!(d->sortColumn == column && d->sortOrder != order && !d->forceSort)) { | - |
| 852 | | - |
| 853 | d->sortChildren(column, index(rootPath())); | - |
| 854 | d->sortColumn = column; | - |
| 855 | d->forceSort = false; | - |
| 856 | } | - |
| 857 | d->sortOrder = order; | - |
| 858 | | - |
| 859 | QModelIndexList newList; | - |
| 860 | const int numOldNodes = oldNodes.size(); | - |
| 861 | newList.reserve(numOldNodes); | - |
| 862 | for (int i = 0; i < numOldNodes; ++i) { | - |
| 863 | const QPair<QFileSystemModelPrivate::QFileSystemNode*, int> &oldNode = oldNodes.at(i); | - |
| 864 | newList.append(d->index(oldNode.first, oldNode.second)); | - |
| 865 | } | - |
| 866 | changePersistentIndexList(oldList, newList); | - |
| 867 | layoutChanged(); | - |
| 868 | } | - |
| 869 | | - |
| 870 | | - |
| 871 | | - |
| 872 | | - |
| 873 | | - |
| 874 | QStringList QFileSystemModel::mimeTypes() const | - |
| 875 | { | - |
| 876 | return QStringList(QLatin1String("text/uri-list")); | - |
| 877 | } | - |
| 878 | QMimeData *QFileSystemModel::mimeData(const QModelIndexList &indexes) const | - |
| 879 | { | - |
| 880 | QList<QUrl> urls; | - |
| 881 | QList<QModelIndex>::const_iterator it = indexes.begin(); | - |
| 882 | for (; it != indexes.end(); ++it) | - |
| 883 | if ((*it).column() == 0) | - |
| 884 | urls << QUrl::fromLocalFile(filePath(*it)); | - |
| 885 | QMimeData *data = new QMimeData(); | - |
| 886 | data->setUrls(urls); | - |
| 887 | return data; | - |
| 888 | } | - |
| 889 | bool QFileSystemModel::dropMimeData(const QMimeData *data, Qt::DropAction action, | - |
| 890 | int row, int column, const QModelIndex &parent) | - |
| 891 | { | - |
| 892 | (void)row;; | - |
| 893 | (void)column;; | - |
| 894 | if (!parent.isValid() || isReadOnly()) | - |
| 895 | return false; | - |
| 896 | | - |
| 897 | bool success = true; | - |
| 898 | QString to = filePath(parent) + QDir::separator(); | - |
| 899 | | - |
| 900 | QList<QUrl> urls = data->urls(); | - |
| 901 | QList<QUrl>::const_iterator it = urls.constBegin(); | - |
| 902 | | - |
| 903 | switch (action) { | - |
| 904 | case Qt::CopyAction: | - |
| 905 | for (; it != urls.constEnd(); ++it) { | - |
| 906 | QString path = (*it).toLocalFile(); | - |
| 907 | success = QFile::copy(path, to + QFileInfo(path).fileName()) && success; | - |
| 908 | } | - |
| 909 | break; | - |
| 910 | case Qt::LinkAction: | - |
| 911 | for (; it != urls.constEnd(); ++it) { | - |
| 912 | QString path = (*it).toLocalFile(); | - |
| 913 | success = QFile::link(path, to + QFileInfo(path).fileName()) && success; | - |
| 914 | } | - |
| 915 | break; | - |
| 916 | case Qt::MoveAction: | - |
| 917 | for (; it != urls.constEnd(); ++it) { | - |
| 918 | QString path = (*it).toLocalFile(); | - |
| 919 | success = QFile::rename(path, to + QFileInfo(path).fileName()) && success; | - |
| 920 | } | - |
| 921 | break; | - |
| 922 | default: | - |
| 923 | return false; | - |
| 924 | } | - |
| 925 | | - |
| 926 | return success; | - |
| 927 | } | - |
| 928 | | - |
| 929 | | - |
| 930 | | - |
| 931 | | - |
| 932 | Qt::DropActions QFileSystemModel::supportedDropActions() const | - |
| 933 | { | - |
| 934 | return Qt::CopyAction | Qt::MoveAction | Qt::LinkAction; | - |
| 935 | } | - |
| 936 | | - |
| 937 | | - |
| 938 | | - |
| 939 | | - |
| 940 | | - |
| 941 | QString QFileSystemModel::filePath(const QModelIndex &index) const | - |
| 942 | { | - |
| 943 | const QFileSystemModelPrivate * const d = d_func(); | - |
| 944 | QString fullPath = d->filePath(index); | - |
| 945 | QFileSystemModelPrivate::QFileSystemNode *dirNode = d->node(index); | - |
| 946 | if (dirNode->isSymLink() | - |
| 947 | | - |
| 948 | && d->fileInfoGatherer.resolveSymlinks() | - |
| 949 | | - |
| 950 | && d->resolvedSymLinks.contains(fullPath) | - |
| 951 | && dirNode->isDir()) { | - |
| 952 | QFileInfo resolvedInfo(fullPath); | - |
| 953 | resolvedInfo = resolvedInfo.canonicalFilePath(); | - |
| 954 | if (resolvedInfo.exists()) | - |
| 955 | return resolvedInfo.filePath(); | - |
| 956 | } | - |
| 957 | return fullPath; | - |
| 958 | } | - |
| 959 | | - |
| 960 | QString QFileSystemModelPrivate::filePath(const QModelIndex &index) const | - |
| 961 | { | - |
| 962 | const QFileSystemModel * const q = q_func(); | - |
| 963 | (void)q;; | - |
| 964 | if (!index.isValid()) | - |
| 965 | return QString(); | - |
| 966 | ((!(index.model() == q)) ? qt_assert("index.model() == q",__FILE__,12641282) : qt_noop()); | - |
| 967 | | - |
| 968 | QStringList path; | - |
| 969 | QModelIndex idx = index; | - |
| 970 | while (idx.isValid()) { | - |
| 971 | QFileSystemModelPrivate::QFileSystemNode *dirNode = node(idx); | - |
| 972 | if (dirNode) | - |
| 973 | path.prepend(dirNode->fileName); | - |
| 974 | idx = idx.parent(); | - |
| 975 | } | - |
| 976 | QString fullPath = QDir::fromNativeSeparators(path.join(QDir::separator())); | - |
| 977 | | - |
| 978 | if ((fullPath.length() > 2) && fullPath[0] == QLatin1Char('/') && fullPath[1] == QLatin1Char('/')) | - |
| 979 | fullPath = fullPath.mid(1); | - |
| 980 | | - |
| 981 | | - |
| 982 | | - |
| 983 | | - |
| 984 | | - |
| 985 | return fullPath; | - |
| 986 | } | - |
| 987 | | - |
| 988 | | - |
| 989 | | - |
| 990 | | - |
| 991 | QModelIndex QFileSystemModel::mkdir(const QModelIndex &parent, const QString &name) | - |
| 992 | { | - |
| 993 | QFileSystemModelPrivate * const d = d_func(); | - |
| 994 | if (!parent.isValid()) | - |
| 995 | return parent; | - |
| 996 | | - |
| 997 | QDir dir(filePath(parent)); | - |
| 998 | if (!dir.mkdir(name)) | - |
| 999 | return QModelIndex(); | - |
| 1000 | QFileSystemModelPrivate::QFileSystemNode *parentNode = d->node(parent); | - |
| 1001 | d->addNode(parentNode, name, QFileInfo()); | - |
| 1002 | ((!(parentNode->children.contains(name))) ? qt_assert("parentNode->children.contains(name)",__FILE__,13001318) : qt_noop()); | - |
| 1003 | QFileSystemModelPrivate::QFileSystemNode *node = parentNode->children[name]; | - |
| 1004 | | - |
| 1005 | node->populate(d->fileInfoGatherer.getInfo(QFileInfo(dir.absolutePath() + QDir::separator() + name))); | - |
| 1006 | | - |
| 1007 | d->addVisibleFiles(parentNode, QStringList(name)); | - |
| 1008 | return d->index(node); | - |
| 1009 | } | - |
| 1010 | | - |
| 1011 | | - |
| 1012 | | - |
| 1013 | | - |
| 1014 | QFile::Permissions QFileSystemModel::permissions(const QModelIndex &index) const | - |
| 1015 | { | - |
| 1016 | const QFileSystemModelPrivate * const d = d_func(); | - |
| 1017 | return d->node(index)->permissions(); | - |
| 1018 | } | - |
| 1019 | QModelIndex QFileSystemModel::setRootPath(const QString &newPath) | - |
| 1020 | { | - |
| 1021 | QFileSystemModelPrivate * const d = d_func(); | - |
| 1022 | | - |
| 1023 | | - |
| 1024 | | - |
| 1025 | | - |
| 1026 | | - |
| 1027 | | - |
| 1028 | | - |
| 1029 | QString longNewPath = newPath; | - |
| 1030 | | - |
| 1031 | QDir newPathDir(longNewPath); | - |
| 1032 | | - |
| 1033 | if (!newPath.isEmpty()) { | - |
| 1034 | longNewPath = QDir::cleanPath(longNewPath); | - |
| 1035 | newPathDir.setPath(longNewPath); | - |
| 1036 | } | - |
| 1037 | | - |
| 1038 | d->setRootPath = true; | - |
| 1039 | | - |
| 1040 | | - |
| 1041 | if (!newPath.isEmpty() && longNewPath.isEmpty()) | - |
| 1042 | return d->index(rootPath()); | - |
| 1043 | | - |
| 1044 | if (d->rootDir.path() == longNewPath) | - |
| 1045 | return d->index(rootPath()); | - |
| 1046 | | - |
| 1047 | bool showDrives = (longNewPath.isEmpty() || longNewPath == d->myComputer()); | - |
| 1048 | if (!showDrives && !newPathDir.exists()) | - |
| 1049 | return d->index(rootPath()); | - |
| 1050 | | - |
| 1051 | | - |
| 1052 | if (!rootPath().isEmpty() && rootPath() != QLatin1String(".")) { | - |
| 1053 | | - |
| 1054 | | - |
| 1055 | d->fileInfoGatherer.removePath(rootPath()); | - |
| 1056 | | - |
| 1057 | | - |
| 1058 | | - |
| 1059 | | - |
| 1060 | d->node(rootPath())->populatedChildren = false; | - |
| 1061 | } | - |
| 1062 | | - |
| 1063 | | - |
| 1064 | d->rootDir = newPathDir; | - |
| 1065 | QModelIndex newRootIndex; | - |
| 1066 | if (showDrives) { | - |
| 1067 | | - |
| 1068 | d->rootDir.setPath(QLatin1String("")); | - |
| 1069 | } else { | - |
| 1070 | newRootIndex = d->index(newPathDir.path()); | - |
| 1071 | } | - |
| 1072 | fetchMore(newRootIndex); | - |
| 1073 | rootPathChanged(longNewPath); | - |
| 1074 | d->forceSort = true; | - |
| 1075 | d->delayedSort(); | - |
| 1076 | return newRootIndex; | - |
| 1077 | } | - |
| 1078 | | - |
| 1079 | | - |
| 1080 | | - |
| 1081 | | - |
| 1082 | | - |
| 1083 | | - |
| 1084 | QString QFileSystemModel::rootPath() const | - |
| 1085 | { | - |
| 1086 | const QFileSystemModelPrivate * const d = d_func(); | - |
| 1087 | return d->rootDir.path(); | - |
| 1088 | } | - |
| 1089 | | - |
| 1090 | | - |
| 1091 | | - |
| 1092 | | - |
| 1093 | | - |
| 1094 | | - |
| 1095 | QDir QFileSystemModel::rootDirectory() const | - |
| 1096 | { | - |
| 1097 | const QFileSystemModelPrivate * const d = d_func(); | - |
| 1098 | QDir dir(d->rootDir); | - |
| 1099 | dir.setNameFilters(nameFilters()); | - |
| 1100 | dir.setFilter(filter()); | - |
| 1101 | return dir; | - |
| 1102 | } | - |
| 1103 | | - |
| 1104 | | - |
| 1105 | | - |
| 1106 | | - |
| 1107 | void QFileSystemModel::setIconProvider(QFileIconProvider *provider) | - |
| 1108 | { | - |
| 1109 | QFileSystemModelPrivate * const d = d_func(); | - |
| 1110 | | - |
| 1111 | d->fileInfoGatherer.setIconProvider(provider); | - |
| 1112 | | - |
| 1113 | d->root.updateIcon(provider, QString()); | - |
| 1114 | } | - |
| 1115 | | - |
| 1116 | | - |
| 1117 | | - |
| 1118 | | - |
| 1119 | QFileIconProvider *QFileSystemModel::iconProvider() const | - |
| 1120 | { | - |
| 1121 | | - |
| 1122 | const QFileSystemModelPrivate * const d = d_func(); | - |
| 1123 | return d->fileInfoGatherer.iconProvider(); | - |
| 1124 | | - |
| 1125 | | - |
| 1126 | | - |
| 1127 | } | - |
| 1128 | void QFileSystemModel::setFilter(QDir::Filters filters) | - |
| 1129 | { | - |
| 1130 | QFileSystemModelPrivate * const d = d_func(); | - |
| 1131 | if (d->filters == filters) | - |
| 1132 | return; | - |
| 1133 | d->filters = filters; | - |
| 1134 | | - |
| 1135 | setNameFilters(nameFilters()); | - |
| 1136 | d->forceSort = true; | - |
| 1137 | d->delayedSort(); | - |
| 1138 | } | - |
| 1139 | QDir::Filters QFileSystemModel::filter() const | - |
| 1140 | { | - |
| 1141 | const QFileSystemModelPrivate * const d = d_func(); | - |
| 1142 | return d->filters; | - |
| 1143 | } | - |
| 1144 | void QFileSystemModel::setResolveSymlinks(bool enable) | - |
| 1145 | { | - |
| 1146 | | - |
| 1147 | QFileSystemModelPrivate * const d = d_func(); | - |
| 1148 | d->fileInfoGatherer.setResolveSymlinks(enable); | - |
| 1149 | | - |
| 1150 | | - |
| 1151 | | - |
| 1152 | } | - |
| 1153 | | - |
| 1154 | bool QFileSystemModel::resolveSymlinks() const | - |
| 1155 | { | - |
| 1156 | | - |
| 1157 | const QFileSystemModelPrivate * const d = d_func(); | - |
| 1158 | return d->fileInfoGatherer.resolveSymlinks(); | - |
| 1159 | | - |
| 1160 | | - |
| 1161 | | - |
| 1162 | } | - |
| 1163 | void QFileSystemModel::setReadOnly(bool enable) | - |
| 1164 | { | - |
| 1165 | QFileSystemModelPrivate * const d = d_func(); | - |
| 1166 | d->readOnly = enable; | - |
| 1167 | } | - |
| 1168 | | - |
| 1169 | bool QFileSystemModel::isReadOnly() const | - |
| 1170 | { | - |
| 1171 | const QFileSystemModelPrivate * const d = d_func(); | - |
| 1172 | return d->readOnly; | - |
| 1173 | } | - |
| 1174 | | - |
| 1175 | | - |
| 1176 | | - |
| 1177 | | - |
| 1178 | | - |
| 1179 | | - |
| 1180 | | - |
| 1181 | void QFileSystemModel::setNameFilterDisables(bool enable) | - |
| 1182 | { | - |
| 1183 | QFileSystemModelPrivate * const d = d_func(); | - |
| 1184 | if (d->nameFilterDisables == enable) | - |
| 1185 | return; | - |
| 1186 | d->nameFilterDisables = enable; | - |
| 1187 | d->forceSort = true; | - |
| 1188 | d->delayedSort(); | - |
| 1189 | } | - |
| 1190 | | - |
| 1191 | bool QFileSystemModel::nameFilterDisables() const | - |
| 1192 | { | - |
| 1193 | const QFileSystemModelPrivate * const d = d_func(); | - |
| 1194 | return d->nameFilterDisables; | - |
| 1195 | } | - |
| 1196 | | - |
| 1197 | | - |
| 1198 | | - |
| 1199 | | - |
| 1200 | void QFileSystemModel::setNameFilters(const QStringList &filters) | - |
| 1201 | { | - |
| 1202 | | - |
| 1203 | | - |
| 1204 | QFileSystemModelPrivate * const d = d_func(); | - |
| 1205 | | - |
| 1206 | if (!d->bypassFilters.isEmpty()| TRUE | never evaluated | | FALSE | never evaluated |
) { | 0 |
| 1207 | | - |
| 1208 | d->bypassFilters.clear(); | - |
| 1209 | | - |
| 1210 | QPersistentModelIndex root(index(rootPath())); | - |
| 1211 | const QModelIndexList persistantListpersistentList = persistentIndexList(); | - |
| 1212 | for (int i = 0; i < persistantList.count(); ++iconst auto &persistentIndex : persistentList) { | - |
| 1213 | QFileSystemModelPrivate::QFileSystemNode *node;node = d->node(persistantList.at(i));persistentIndex); | - |
| 1214 | while (node| TRUE | never evaluated | | FALSE | never evaluated |
) { | 0 |
| 1215 | if (d->bypassFilters.contains(node)| TRUE | never evaluated | | FALSE | never evaluated |
) | 0 |
| 1216 | break; never executed: break; | 0 |
| 1217 | if (node->isDir()| TRUE | never evaluated | | FALSE | never evaluated |
) | 0 |
| 1218 | d->bypassFilters[node] = true; never executed: d->bypassFilters[node] = true; | 0 |
| 1219 | node = node->parent; | - |
| 1220 | } never executed: end of block | 0 |
| 1221 | } never executed: end of block | 0 |
| 1222 | } never executed: end of block | 0 |
| 1223 | | - |
| 1224 | d->nameFilters.clear(); | - |
| 1225 | const Qt::CaseSensitivity caseSensitive = | - |
| 1226 | (| TRUE | never evaluated | | FALSE | never evaluated |
filter() & QDir::CaseSensitive)| TRUE | never evaluated | | FALSE | never evaluated |
? Qt::CaseSensitive : Qt::CaseInsensitive; | 0 |
| 1227 | for (int i = 0; i <const auto &filter : filters.size(); ++i) | - |
| 1228 | {d->nameFilters << QRegExp(filters.at(i),filter, caseSensitive, QRegExp::Wildcard); never executed: d->nameFilters << QRegExp(filter, caseSensitive, QRegExp::Wildcard); | 0 |
| 1229 | }d->forceSort = true; | - |
| 1230 | d->delayedSort(); | - |
| 1231 | | - |
| 1232 | } never executed: end of block | 0 |
| 1233 | | - |
| 1234 | | - |
| 1235 | | - |
| 1236 | | - |
| 1237 | QStringList QFileSystemModel::nameFilters() const | - |
| 1238 | { | - |
| 1239 | const QFileSystemModelPrivate * const d = d_func(); | - |
| 1240 | QStringList filters; | - |
| 1241 | | - |
| 1242 | const int numNameFilters = d->nameFilters.size(); | - |
| 1243 | filters.reserve(numNameFilters); | - |
| 1244 | for (int i = 0; i < numNameFilters; ++i) { | - |
| 1245 | filters << d->nameFilters.at(i).pattern(); | - |
| 1246 | } | - |
| 1247 | | - |
| 1248 | return filters; | - |
| 1249 | } | - |
| 1250 | | - |
| 1251 | | - |
| 1252 | | - |
| 1253 | | - |
| 1254 | bool QFileSystemModel::event(QEvent *event) | - |
| 1255 | { | - |
| 1256 | | - |
| 1257 | QFileSystemModelPrivate * const d = d_func(); | - |
| 1258 | if (event->type() == QEvent::LanguageChange) { | - |
| 1259 | d->root.retranslateStrings(d->fileInfoGatherer.iconProvider(), QString()); | - |
| 1260 | return true; | - |
| 1261 | } | - |
| 1262 | | - |
| 1263 | return QAbstractItemModel::event(event); | - |
| 1264 | } | - |
| 1265 | | - |
| 1266 | bool QFileSystemModel::rmdir(const QModelIndex &aindex) | - |
| 1267 | { | - |
| 1268 | QString path = filePath(aindex); | - |
| 1269 | const bool success = QDir().rmdir(path); | - |
| 1270 | | - |
| 1271 | if (success) { | - |
| 1272 | QFileSystemModelPrivate * d = const_cast<QFileSystemModelPrivate*>(d_func()); | - |
| 1273 | d->fileInfoGatherer.removePath(path); | - |
| 1274 | } | - |
| 1275 | | - |
| 1276 | return success; | - |
| 1277 | } | - |
| 1278 | | - |
| 1279 | | - |
| 1280 | | - |
| 1281 | | - |
| 1282 | | - |
| 1283 | | - |
| 1284 | | - |
| 1285 | void QFileSystemModelPrivate::_q_directoryChanged(const QString &directory, const QStringList &files) | - |
| 1286 | { | - |
| 1287 | QFileSystemModelPrivate::QFileSystemNode *parentNode = node(directory, false); | - |
| 1288 | if (parentNode->children.count() == 0) | - |
| 1289 | return; | - |
| 1290 | QStringList toRemove; | - |
| 1291 | QStringList newFiles = files; | - |
| 1292 | std::sort(newFiles.begin(), newFiles.end()); | - |
| 1293 | QHash<QString, QFileSystemNode*>::const_iterator i = parentNode->children.constBegin(); | - |
| 1294 | while (i != parentNode->children.constEnd()) { | - |
| 1295 | QStringList::iterator iterator = std::lower_bound(newFiles.begin(), newFiles.end(), i.value()->fileName); | - |
| 1296 | if ((iterator == newFiles.end()) || (i.value()->fileName < *iterator)) | - |
| 1297 | toRemove.append(i.value()->fileName); | - |
| 1298 | | - |
| 1299 | ++i; | - |
| 1300 | } | - |
| 1301 | for (int i = 0 ; i < toRemove.count() ; ++i ) | - |
| 1302 | removeNode(parentNode, toRemove[i]); | - |
| 1303 | } | - |
| 1304 | QFileSystemModelPrivate::QFileSystemNode* QFileSystemModelPrivate::addNode(QFileSystemNode *parentNode, const QString &fileName, const QFileInfo& info) | - |
| 1305 | { | - |
| 1306 | | - |
| 1307 | QFileSystemModelPrivate::QFileSystemNode *node = new QFileSystemModelPrivate::QFileSystemNode(fileName, parentNode); | - |
| 1308 | | - |
| 1309 | node->populate(info); | - |
| 1310 | parentNode->children.insert(fileName, node); | - |
| 1311 | return node; | - |
| 1312 | } | - |
| 1313 | void QFileSystemModelPrivate::removeNode(QFileSystemModelPrivate::QFileSystemNode *parentNode, const QString& name) | - |
| 1314 | { | - |
| 1315 | QFileSystemModel * const q = q_func(); | - |
| 1316 | QModelIndex parent = index(parentNode); | - |
| 1317 | bool indexHidden = isHiddenByFilter(parentNode, parent); | - |
| 1318 | | - |
| 1319 | int vLocation = parentNode->visibleLocation(name); | - |
| 1320 | if (vLocation >= 0 && !indexHidden) | - |
| 1321 | q->beginRemoveRows(parent, translateVisibleLocation(parentNode, vLocation), | - |
| 1322 | translateVisibleLocation(parentNode, vLocation)); | - |
| 1323 | QFileSystemNode * node = parentNode->children.take(name); | - |
| 1324 | delete node; | - |
| 1325 | | - |
| 1326 | if (vLocation >= 0) | - |
| 1327 | parentNode->visibleChildren.removeAt(vLocation); | - |
| 1328 | if (vLocation >= 0 && !indexHidden) | - |
| 1329 | q->endRemoveRows(); | - |
| 1330 | } | - |
| 1331 | void QFileSystemModelPrivate::addVisibleFiles(QFileSystemNode *parentNode, const QStringList &newFiles) | - |
| 1332 | { | - |
| 1333 | QFileSystemModel * const q = q_func(); | - |
| 1334 | QModelIndex parent = index(parentNode); | - |
| 1335 | bool indexHidden = isHiddenByFilter(parentNode, parent); | - |
| 1336 | if (!indexHidden| TRUE | never evaluated | | FALSE | never evaluated |
) { | 0 |
| 1337 | q->beginInsertRows(parent, parentNode->visibleChildren.count() , parentNode->visibleChildren.count() + newFiles.count() - 1); | - |
| 1338 | } never executed: end of block | 0 |
| 1339 | | - |
| 1340 | if (parentNode->dirtyChildrenIndex == -1| TRUE | never evaluated | | FALSE | never evaluated |
) | 0 |
| 1341 | parentNode->dirtyChildrenIndex = parentNode->visibleChildren.count(); never executed: parentNode->dirtyChildrenIndex = parentNode->visibleChildren.count(); | 0 |
| 1342 | | - |
| 1343 | for (int i = 0; i <const auto &newFile : newFiles.count(); ++i) { | - |
| 1344 | parentNode->visibleChildren.append(newFiles.at(i));newFile); | - |
| 1345 | parentNode->children.value(newFiles.at(i))->newFile)->isVisible = true; | - |
| 1346 | } never executed: end of block | 0 |
| 1347 | if (!indexHidden| TRUE | never evaluated | | FALSE | never evaluated |
) | 0 |
| 1348 | q->endInsertRows(); never executed: q->endInsertRows(); | 0 |
| 1349 | } never executed: end of block | 0 |
| 1350 | void QFileSystemModelPrivate::removeVisibleFile(QFileSystemNode *parentNode, int vLocation) | - |
| 1351 | { | - |
| 1352 | QFileSystemModel * const q = q_func(); | - |
| 1353 | if (vLocation == -1) | - |
| 1354 | return; | - |
| 1355 | QModelIndex parent = index(parentNode); | - |
| 1356 | bool indexHidden = isHiddenByFilter(parentNode, parent); | - |
| 1357 | if (!indexHidden) | - |
| 1358 | q->beginRemoveRows(parent, translateVisibleLocation(parentNode, vLocation), | - |
| 1359 | translateVisibleLocation(parentNode, vLocation)); | - |
| 1360 | parentNode->children.value(parentNode->visibleChildren.at(vLocation))->isVisible = false; | - |
| 1361 | parentNode->visibleChildren.removeAt(vLocation); | - |
| 1362 | if (!indexHidden) | - |
| 1363 | q->endRemoveRows(); | - |
| 1364 | } | - |
| 1365 | | - |
| 1366 | | - |
| 1367 | | - |
| 1368 | | - |
| 1369 | | - |
| 1370 | | - |
| 1371 | | - |
| 1372 | void QFileSystemModelPrivate::_q_fileSystemChanged(const QString &path, const QVector<QPair<QString, QFileInfo> > &updates) | - |
| 1373 | { | - |
| 1374 | | - |
| 1375 | QFileSystemModel * const q = q_func(); | - |
| 1376 | QVector<QString> rowsToUpdate; | - |
| 1377 | QStringList newFiles; | - |
| 1378 | QFileSystemModelPrivate::QFileSystemNode *parentNode = node(path, false); | - |
| 1379 | QModelIndex parentIndex = index(parentNode); | - |
| 1380 | for (int i = 0; i <const auto &update : updates.count(); ++i) { | - |
| 1381 | QString fileName = updatesupdate.at(i).first; | - |
| 1382 | ((!(!fileName.isEmpty())) ? qt_assert("!fileName.isEmpty()",__FILE__,17821798) : qt_noop()); | - |
| 1383 | QExtendedInformation info = fileInfoGatherer.getInfo(updatesupdate.at(i).second); | - |
| 1384 | bool previouslyHere = parentNode->children.contains(fileName); | - |
| 1385 | if (!previouslyHere| TRUE | never evaluated | | FALSE | never evaluated |
) { | 0 |
| 1386 | addNode(parentNode, fileName, info.fileInfo()); | - |
| 1387 | } never executed: end of block | 0 |
| 1388 | QFileSystemModelPrivate::QFileSystemNode * node = parentNode->children.value(fileName); | - |
| 1389 | bool isCaseSensitive = parentNode->caseSensitive(); | - |
| 1390 | if (isCaseSensitive| TRUE | never evaluated | | FALSE | never evaluated |
) { | 0 |
| 1391 | if (node->fileName != fileName| TRUE | never evaluated | | FALSE | never evaluated |
) | 0 |
| 1392 | continue; never executed: continue; | 0 |
| 1393 | } never executed: end of block else { | 0 |
| 1394 | if (QString::compare(node->fileName,fileName,Qt::CaseInsensitive) != 0| TRUE | never evaluated | | FALSE | never evaluated |
) | 0 |
| 1395 | continue; never executed: continue; | 0 |
| 1396 | } never executed: end of block | 0 |
| 1397 | if (isCaseSensitive| TRUE | never evaluated | | FALSE | never evaluated |
) { | 0 |
| 1398 | ((!(node->fileName == fileName)) ? qt_assert("node->fileName == fileName",__FILE__,17981814) : qt_noop()); | - |
| 1399 | } never executed: end of block else { | 0 |
| 1400 | node->fileName = fileName; | - |
| 1401 | } never executed: end of block | 0 |
| 1402 | | - |
| 1403 | if (*| TRUE | never evaluated | | FALSE | never evaluated |
node != info| TRUE | never evaluated | | FALSE | never evaluated |
) { | 0 |
| 1404 | node->populate(info); | - |
| 1405 | bypassFilters.remove(node); | - |
| 1406 | | - |
| 1407 | if (filtersAcceptsNode(node)| TRUE | never evaluated | | FALSE | never evaluated |
) { | 0 |
| 1408 | if (!node->isVisible| TRUE | never evaluated | | FALSE | never evaluated |
) { | 0 |
| 1409 | newFiles.append(fileName); | - |
| 1410 | } never executed: end of block else { | 0 |
| 1411 | rowsToUpdate.append(fileName); | - |
| 1412 | } never executed: end of block | 0 |
| 1413 | } else { | - |
| 1414 | if (node->isVisible| TRUE | never evaluated | | FALSE | never evaluated |
) { | 0 |
| 1415 | int visibleLocation = parentNode->visibleLocation(fileName); | - |
| 1416 | removeVisibleFile(parentNode, visibleLocation); | - |
| 1417 | } never executed: end of block else { | 0 |
| 1418 | | - |
| 1419 | } never executed: end of block | 0 |
| 1420 | } | - |
| 1421 | } | - |
| 1422 | } never executed: end of block | 0 |
| 1423 | | - |
| 1424 | | - |
| 1425 | std::sort(rowsToUpdate.begin(), rowsToUpdate.end()); | - |
| 1426 | QString min; | - |
| 1427 | QString max; | - |
| 1428 | for (int i = 0; i < rowsToUpdate.count()| TRUE | never evaluated | | FALSE | never evaluated |
; ++i) { | 0 |
| 1429 | QString value = rowsToUpdate.at(i); | - |
| 1430 | max = value; | - |
| 1431 | min = value; | - |
| 1432 | int visibleMin = parentNode->visibleLocation(min); | - |
| 1433 | int visibleMax = parentNode->visibleLocation(max); | - |
| 1434 | if (visibleMin >= 0| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 1435 | && visibleMin < parentNode->visibleChildren.count()| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 1436 | && parentNode->visibleChildren.at(visibleMin) == min| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 1437 | && visibleMax >= 0| TRUE | never evaluated | | FALSE | never evaluated |
) { | 0 |
| 1438 | QModelIndex bottom = q->index(translateVisibleLocation(parentNode, visibleMin), 0, parentIndex); | - |
| 1439 | QModelIndex top = q->index(translateVisibleLocation(parentNode, visibleMax), 3, parentIndex); | - |
| 1440 | q->dataChanged(bottom, top); | - |
| 1441 | } never executed: end of block | 0 |
| 1442 | | - |
| 1443 | | - |
| 1444 | | - |
| 1445 | } never executed: end of block | 0 |
| 1446 | | - |
| 1447 | if (newFiles.count() > 0| TRUE | never evaluated | | FALSE | never evaluated |
) { | 0 |
| 1448 | addVisibleFiles(parentNode, newFiles); | - |
| 1449 | } never executed: end of block | 0 |
| 1450 | | - |
| 1451 | if (newFiles.count() > 0| TRUE | never evaluated | | FALSE | never evaluated |
|| (sortColumn != 0| TRUE | never evaluated | | FALSE | never evaluated |
&& rowsToUpdate.count() > 0| TRUE | never evaluated | | FALSE | never evaluated |
)) { | 0 |
| 1452 | forceSort = true; | - |
| 1453 | delayedSort(); | - |
| 1454 | } never executed: end of block | 0 |
| 1455 | | - |
| 1456 | | - |
| 1457 | | - |
| 1458 | | - |
| 1459 | } never executed: end of block | 0 |
| 1460 | | - |
| 1461 | | - |
| 1462 | | - |
| 1463 | | - |
| 1464 | void QFileSystemModelPrivate::_q_resolvedName(const QString &fileName, const QString &resolvedName) | - |
| 1465 | { | - |
| 1466 | resolvedSymLinks[fileName] = resolvedName; | - |
| 1467 | } | - |
| 1468 | | - |
| 1469 | | - |
| 1470 | | - |
| 1471 | | - |
| 1472 | void QFileSystemModelPrivate::init() | - |
| 1473 | { | - |
| 1474 | QFileSystemModel * const q = q_func(); | - |
| 1475 | qRegisterMetaType<QVector<QPair<QString,QFileInfo> > >(); | - |
| 1476 | | - |
| 1477 | q->connect(&fileInfoGatherer, qFlagLocation("2""newListOfFiles(QString,QStringList)" "\0" __FILE__ ":" "1889""1905"), | - |
| 1478 | q, qFlagLocation("1""_q_directoryChanged(QString,QStringList)" "\0" __FILE__ ":" "1890""1906")); | - |
| 1479 | q->connect(&fileInfoGatherer, qFlagLocation("2""updates(QString,QVector<QPair<QString,QFileInfo> >)" "\0" __FILE__ ":" "1891""1907"), | - |
| 1480 | q, qFlagLocation("1""_q_fileSystemChanged(QString,QVector<QPair<QString,QFileInfo> >)" "\0" __FILE__ ":" "1892""1908")); | - |
| 1481 | q->connect(&fileInfoGatherer, qFlagLocation("2""nameResolved(QString,QString)" "\0" __FILE__ ":" "1893""1909"), | - |
| 1482 | q, qFlagLocation("1""_q_resolvedName(QString,QString)" "\0" __FILE__ ":" "1894""1910")); | - |
| 1483 | q->connect(&fileInfoGatherer, qFlagLocation("2""directoryLoaded(QString)" "\0" __FILE__ ":" "1895""1911"), | - |
| 1484 | q, qFlagLocation("2""directoryLoaded(QString)" "\0" __FILE__ ":" "1896""1912")); | - |
| 1485 | | - |
| 1486 | q->connect(&delayedSortTimer, qFlagLocation("2""timeout()" "\0" __FILE__ ":" "1898""1914"), q, qFlagLocation("1""_q_performDelayedSort()" "\0" __FILE__ ":" "1898""1914"), Qt::QueuedConnection); | - |
| 1487 | | - |
| 1488 | roleNames.insertMulti(QFileSystemModel::FileIconRole, ([]() -> QByteArray { enum { Size = sizeof("fileIcon") - 1 }; static const QStaticByteArrayData<Size> qbytearray_literal = { { { { -1 } }, Size, 0, 0, sizeof(QByteArrayData) }, "fileIcon" }; QByteArrayDataPtr holder = { qbytearray_literal.data_ptr() }; const QByteArray ba(holder); return ba; }())); | - |
| 1489 | roleNames.insert(QFileSystemModel::FilePathRole, ([]() -> QByteArray { enum { Size = sizeof("filePath") - 1 }; static const QStaticByteArrayData<Size> qbytearray_literal = { { { { -1 } }, Size, 0, 0, sizeof(QByteArrayData) }, "filePath" }; QByteArrayDataPtr holder = { qbytearray_literal.data_ptr() }; const QByteArray ba(holder); return ba; }())); | - |
| 1490 | roleNames.insert(QFileSystemModel::FileNameRole, ([]() -> QByteArray { enum { Size = sizeof("fileName") - 1 }; static const QStaticByteArrayData<Size> qbytearray_literal = { { { { -1 } }, Size, 0, 0, sizeof(QByteArrayData) }, "fileName" }; QByteArrayDataPtr holder = { qbytearray_literal.data_ptr() }; const QByteArray ba(holder); return ba; }())); | - |
| 1491 | roleNames.insert(QFileSystemModel::FilePermissions, ([]() -> QByteArray { enum { Size = sizeof("filePermissions") - 1 }; static const QStaticByteArrayData<Size> qbytearray_literal = { { { { -1 } }, Size, 0, 0, sizeof(QByteArrayData) }, "filePermissions" }; QByteArrayDataPtr holder = { qbytearray_literal.data_ptr() }; const QByteArray ba(holder); return ba; }())); | - |
| 1492 | } | - |
| 1493 | bool QFileSystemModelPrivate::filtersAcceptsNode(const QFileSystemNode *node) const | - |
| 1494 | { | - |
| 1495 | | - |
| 1496 | if (node->parent == &root || bypassFilters.contains(node)) | - |
| 1497 | return true; | - |
| 1498 | | - |
| 1499 | | - |
| 1500 | if (!node->hasInformation()) | - |
| 1501 | return false; | - |
| 1502 | | - |
| 1503 | const bool filterPermissions = ((filters & QDir::PermissionMask) | - |
| 1504 | && (filters & QDir::PermissionMask) != QDir::PermissionMask); | - |
| 1505 | const bool hideDirs = !(filters & (QDir::Dirs | QDir::AllDirs)); | - |
| 1506 | const bool hideFiles = !(filters & QDir::Files); | - |
| 1507 | const bool hideReadable = !(!filterPermissions || (filters & QDir::Readable)); | - |
| 1508 | const bool hideWritable = !(!filterPermissions || (filters & QDir::Writable)); | - |
| 1509 | const bool hideExecutable = !(!filterPermissions || (filters & QDir::Executable)); | - |
| 1510 | const bool hideHidden = !(filters & QDir::Hidden); | - |
| 1511 | const bool hideSystem = !(filters & QDir::System); | - |
| 1512 | const bool hideSymlinks = (filters & QDir::NoSymLinks); | - |
| 1513 | const bool hideDot = (filters & QDir::NoDot); | - |
| 1514 | const bool hideDotDot = (filters & QDir::NoDotDot); | - |
| 1515 | | - |
| 1516 | | - |
| 1517 | bool isDot = (node->fileName == QLatin1String(".")); | - |
| 1518 | bool isDotDot = (node->fileName == QLatin1String("..")); | - |
| 1519 | if ( (hideHidden && !(isDot || isDotDot) && node->isHidden()) | - |
| 1520 | || (hideSystem && node->isSystem()) | - |
| 1521 | || (hideDirs && node->isDir()) | - |
| 1522 | || (hideFiles && node->isFile()) | - |
| 1523 | || (hideSymlinks && node->isSymLink()) | - |
| 1524 | || (hideReadable && node->isReadable()) | - |
| 1525 | || (hideWritable && node->isWritable()) | - |
| 1526 | || (hideExecutable && node->isExecutable()) | - |
| 1527 | || (hideDot && isDot) | - |
| 1528 | || (hideDotDot && isDotDot)) | - |
| 1529 | return false; | - |
| 1530 | | - |
| 1531 | return nameFilterDisables || passNameFilters(node); | - |
| 1532 | } | - |
| 1533 | | - |
| 1534 | | - |
| 1535 | | - |
| 1536 | | - |
| 1537 | | - |
| 1538 | | - |
| 1539 | bool QFileSystemModelPrivate::passNameFilters(const QFileSystemNode *node) const | - |
| 1540 | { | - |
| 1541 | | - |
| 1542 | if (nameFilters.isEmpty()| TRUE | never evaluated | | FALSE | never evaluated |
) | 0 |
| 1543 | return never executed: return true; true;never executed: return true; | 0 |
| 1544 | | - |
| 1545 | | - |
| 1546 | if (!(node->isDir()| TRUE | never evaluated | | FALSE | never evaluated |
&& (| TRUE | never evaluated | | FALSE | never evaluated |
filters & QDir::AllDirs)| TRUE | never evaluated | | FALSE | never evaluated |
)) { | 0 |
| 1547 | for (int i = 0; i <const auto &nameFilter : nameFilters.size(); ++i) { | - |
| 1548 | QRegExp copy = nameFilters.at(i);nameFilter; | - |
| 1549 | if (copy.exactMatch(node->fileName)| TRUE | never evaluated | | FALSE | never evaluated |
) | 0 |
| 1550 | return never executed: return true; true;never executed: return true; | 0 |
| 1551 | } never executed: end of block | 0 |
| 1552 | return never executed: return false; false;never executed: return false; | 0 |
| 1553 | } | - |
| 1554 | | - |
| 1555 | return never executed: return true; true;never executed: return true; | 0 |
| 1556 | } | - |
| 1557 | | - |
| 1558 | | - |
| 1559 | | - |
| | |