Qt 4.8
qfilesystemmodel.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtGui module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #include "qfilesystemmodel_p.h"
43 #include "qfilesystemmodel.h"
44 #include <qlocale.h>
45 #include <qmime.h>
46 #include <qurl.h>
47 #include <qdebug.h>
48 #include <qmessagebox.h>
49 #include <qapplication.h>
50 
51 #ifdef Q_OS_WIN
52 #include <qt_windows.h>
53 #endif
54 #ifdef Q_OS_WIN32
55 #include <QtCore/QVarLengthArray>
56 #endif
57 
59 
60 #ifndef QT_NO_FILESYSTEMMODEL
61 
226 bool QFileSystemModel::remove(const QModelIndex &aindex) const
227 {
228  //### TODO optim
229  QString path = filePath(aindex);
230  QFileSystemModelPrivate * d = const_cast<QFileSystemModelPrivate*>(d_func());
231  d->fileInfoGatherer.removePath(path);
232  QDirIterator it(path,
236  while (it.hasNext())
237  children.prepend(it.next());
238  children.append(path);
239 
240  bool error = false;
241  for (int i = 0; i < children.count(); ++i) {
242  QFileInfo info(children.at(i));
243  QModelIndex modelIndex = index(children.at(i));
244  if (info.isDir()) {
245  QDir dir;
246  if (children.at(i) != path)
247  error |= remove(modelIndex);
248  error |= rmdir(modelIndex);
249  } else {
250  error |= QFile::remove(filePath(modelIndex));
251  }
252  }
253  return error;
254 }
255 
261 {
263  d->init();
264 }
265 
270  : QAbstractItemModel(dd, parent)
271 {
273  d->init();
274 }
275 
280 {
281 }
282 
286 QModelIndex QFileSystemModel::index(int row, int column, const QModelIndex &parent) const
287 {
288  Q_D(const QFileSystemModel);
289  if (row < 0 || column < 0 || row >= rowCount(parent) || column >= columnCount(parent))
290  return QModelIndex();
291 
292  // get the parent node
293  QFileSystemModelPrivate::QFileSystemNode *parentNode = (d->indexValid(parent) ? d->node(parent) :
294  const_cast<QFileSystemModelPrivate::QFileSystemNode*>(&d->root));
295  Q_ASSERT(parentNode);
296 
297  // now get the internal pointer for the index
298  QString childName = parentNode->visibleChildren[d->translateVisibleLocation(parentNode, row)];
299  const QFileSystemModelPrivate::QFileSystemNode *indexNode = parentNode->children.value(childName);
300  Q_ASSERT(indexNode);
301 
302  return createIndex(row, column, const_cast<QFileSystemModelPrivate::QFileSystemNode*>(indexNode));
303 }
304 
313 QModelIndex QFileSystemModel::index(const QString &path, int column) const
314 {
315  Q_D(const QFileSystemModel);
316  QFileSystemModelPrivate::QFileSystemNode *node = d->node(path, false);
317  QModelIndex idx = d->index(node);
318  if (idx.column() != column)
319  idx = idx.sibling(idx.row(), column);
320  return idx;
321 }
322 
332 {
333  if (!index.isValid())
334  return const_cast<QFileSystemNode*>(&root);
336  Q_ASSERT(indexNode);
337  return indexNode;
338 }
339 
340 #ifdef Q_OS_WIN32
341 static QString qt_GetLongPathName(const QString &strShortPath)
342 {
343  if (strShortPath.isEmpty()
344  || strShortPath == QLatin1String(".") || strShortPath == QLatin1String(".."))
345  return strShortPath;
346  if (strShortPath.length() == 2 && strShortPath.endsWith(QLatin1Char(':')))
347  return strShortPath.toUpper();
348  const QString absPath = QDir(strShortPath).absolutePath();
349  if (absPath.startsWith(QLatin1String("//"))
350  || absPath.startsWith(QLatin1String("\\\\"))) // unc
351  return QDir::fromNativeSeparators(absPath);
352  if (absPath.startsWith(QLatin1Char('/')))
353  return QString();
354  const QString inputString = QLatin1String("\\\\?\\") + QDir::toNativeSeparators(absPath);
355  QVarLengthArray<TCHAR, MAX_PATH> buffer(MAX_PATH);
356  DWORD result = ::GetLongPathName((wchar_t*)inputString.utf16(),
357  buffer.data(),
358  buffer.size());
359  if (result > DWORD(buffer.size())) {
360  buffer.resize(result);
361  result = ::GetLongPathName((wchar_t*)inputString.utf16(),
362  buffer.data(),
363  buffer.size());
364  }
365  if (result > 4) {
366  QString longPath = QString::fromWCharArray(buffer.data() + 4); // ignoring prefix
367  longPath[0] = longPath.at(0).toUpper(); // capital drive letters
368  return QDir::fromNativeSeparators(longPath);
369  } else {
370  return QDir::fromNativeSeparators(strShortPath);
371  }
372 }
373 #endif
374 
381 {
382  Q_Q(const QFileSystemModel);
383  Q_UNUSED(q);
384  if (path.isEmpty() || path == myComputer() || path.startsWith(QLatin1Char(':')))
385  return const_cast<QFileSystemModelPrivate::QFileSystemNode*>(&root);
386 
387  // Construct the nodes up to the new root path if they need to be built
388  QString absolutePath;
389 #ifdef Q_OS_WIN32
390  QString longPath = qt_GetLongPathName(path);
391 #else
392  QString longPath = path;
393 #endif
394  if (longPath == rootDir.path())
395  absolutePath = rootDir.absolutePath();
396  else
397  absolutePath = QDir(longPath).absolutePath();
398 
399  // ### TODO can we use bool QAbstractFileEngine::caseSensitive() const?
400  QStringList pathElements = absolutePath.split(QLatin1Char('/'), QString::SkipEmptyParts);
401  if ((pathElements.isEmpty())
402 #if (!defined(Q_OS_WIN) || defined(Q_OS_WINCE)) && !defined(Q_OS_SYMBIAN)
403  && QDir::fromNativeSeparators(longPath) != QLatin1String("/")
404 #endif
405  )
406  return const_cast<QFileSystemModelPrivate::QFileSystemNode*>(&root);
407  QModelIndex index = QModelIndex(); // start with "My Computer"
408 #if defined(Q_OS_WIN) && !defined(Q_OS_WINCE)
409  if (absolutePath.startsWith(QLatin1String("//"))) { // UNC path
410  QString host = QLatin1String("\\\\") + pathElements.first();
411  if (absolutePath == QDir::fromNativeSeparators(host))
412  absolutePath.append(QLatin1Char('/'));
413  if (longPath.endsWith(QLatin1Char('/')) && !absolutePath.endsWith(QLatin1Char('/')))
414  absolutePath.append(QLatin1Char('/'));
415  int r = 0;
417  if (!root.children.contains(host.toLower())) {
418  if (pathElements.count() == 1 && !absolutePath.endsWith(QLatin1Char('/')))
419  return rootNode;
420  QFileInfo info(host);
421  if (!info.exists())
422  return rootNode;
423  QFileSystemModelPrivate *p = const_cast<QFileSystemModelPrivate*>(this);
424  p->addNode(rootNode, host,info);
425  p->addVisibleFiles(rootNode, QStringList(host));
426  }
427  r = rootNode->visibleLocation(host);
428  r = translateVisibleLocation(rootNode, r);
429  index = q->index(r, 0, QModelIndex());
430  pathElements.pop_front();
431  } else
432 #endif
433 
434 #if (defined(Q_OS_WIN) && !defined(Q_OS_WINCE)) || defined(Q_OS_SYMBIAN)
435  {
436  if (!pathElements.at(0).contains(QLatin1String(":"))) {
437  // The reason we express it like this instead of with anonymous, temporary
438  // variables, is to workaround a compiler crash with Q_CC_NOKIAX86.
439  QString rootPath = QDir(longPath).rootPath();
440  pathElements.prepend(rootPath);
441  }
442  if (pathElements.at(0).endsWith(QLatin1Char('/')))
443  pathElements[0].chop(1);
444  }
445 #else
446  // add the "/" item, since it is a valid path element on Unix
447  if (absolutePath[0] == QLatin1Char('/'))
448  pathElements.prepend(QLatin1String("/"));
449 #endif
450 
452 
453  for (int i = 0; i < pathElements.count(); ++i) {
454  QString element = pathElements.at(i);
455 #ifdef Q_OS_WIN
456  // On Windows, "filename......." and "filename" are equivalent Task #133928
457  while (element.endsWith(QLatin1Char('.')))
458  element.chop(1);
459 #endif
460  bool alreadyExisted = parent->children.contains(element);
461 
462  // we couldn't find the path element, we create a new node since we
463  // _know_ that the path is valid
464  if (alreadyExisted) {
465  if ((parent->children.count() == 0)
466  || (parent->caseSensitive()
467  && parent->children.value(element)->fileName != element)
468  || (!parent->caseSensitive()
469  && parent->children.value(element)->fileName.toLower() != element.toLower()))
470  alreadyExisted = false;
471  }
472 
474  if (!alreadyExisted) {
475  // Someone might call ::index("file://cookie/monster/doesn't/like/veggies"),
476  // a path that doesn't exists, I.E. don't blindly create directories.
477  QFileInfo info(absolutePath);
478  if (!info.exists())
479  return const_cast<QFileSystemModelPrivate::QFileSystemNode*>(&root);
480  QFileSystemModelPrivate *p = const_cast<QFileSystemModelPrivate*>(this);
481  node = p->addNode(parent, element,info);
482 #ifndef QT_NO_FILESYSTEMWATCHER
483  node->populate(fileInfoGatherer.getInfo(info));
484 #endif
485  } else {
486  node = parent->children.value(element);
487  }
488 
489  Q_ASSERT(node);
490  if (!node->isVisible) {
491  // It has been filtered out
492  if (alreadyExisted && node->hasInformation() && !fetch)
493  return const_cast<QFileSystemModelPrivate::QFileSystemNode*>(&root);
494 
495  QFileSystemModelPrivate *p = const_cast<QFileSystemModelPrivate*>(this);
496  p->addVisibleFiles(parent, QStringList(element));
497  if (!p->bypassFilters.contains(node))
498  p->bypassFilters[node] = 1;
499  QString dir = q->filePath(this->index(parent));
500  if (!node->hasInformation() && fetch) {
501  Fetching f;
502  f.dir = dir;
503  f.file = element;
504  f.node = node;
505  p->toFetch.append(f);
506  p->fetchingTimer.start(0, const_cast<QFileSystemModel*>(q));
507  }
508  }
509  parent = node;
510  }
511 
512  return parent;
513 }
514 
519 {
521  if (event->timerId() == d->fetchingTimer.timerId()) {
522  d->fetchingTimer.stop();
523 #ifndef QT_NO_FILESYSTEMWATCHER
524  for (int i = 0; i < d->toFetch.count(); ++i) {
525  const QFileSystemModelPrivate::QFileSystemNode *node = d->toFetch.at(i).node;
526  if (!node->hasInformation()) {
527  d->fileInfoGatherer.fetchExtendedInformation(d->toFetch.at(i).dir,
528  QStringList(d->toFetch.at(i).file));
529  } else {
530  // qDebug() << "yah!, you saved a little gerbil soul";
531  }
532  }
533 #endif
534  d->toFetch.clear();
535  }
536 }
537 
543 {
544  // This function is for public usage only because it could create a file info
545  Q_D(const QFileSystemModel);
546  if (!index.isValid())
547  return true;
549  if (n->hasInformation())
550  return n->isDir();
551  return fileInfo(index).isDir();
552 }
553 
558 {
559  Q_D(const QFileSystemModel);
560  if (!index.isValid())
561  return 0;
562  return d->node(index)->size();
563 }
564 
569 {
570  Q_D(const QFileSystemModel);
571  if (!index.isValid())
572  return QString();
573  return d->node(index)->type();
574 }
575 
580 {
581  Q_D(const QFileSystemModel);
582  if (!index.isValid())
583  return QDateTime();
584  return d->node(index)->lastModified();
585 }
586 
591 {
592  Q_D(const QFileSystemModel);
593  if (!d->indexValid(index))
594  return QModelIndex();
595 
596  QFileSystemModelPrivate::QFileSystemNode *indexNode = d->node(index);
597  Q_ASSERT(indexNode != 0);
598  QFileSystemModelPrivate::QFileSystemNode *parentNode = (indexNode ? indexNode->parent : 0);
599  if (parentNode == 0 || parentNode == &d->root)
600  return QModelIndex();
601 
602  // get the parent's row
603  QFileSystemModelPrivate::QFileSystemNode *grandParentNode = parentNode->parent;
604  Q_ASSERT(grandParentNode->children.contains(parentNode->fileName));
605  int visualRow = d->translateVisibleLocation(grandParentNode, grandParentNode->visibleLocation(grandParentNode->children.value(parentNode->fileName)->fileName));
606  if (visualRow == -1)
607  return QModelIndex();
608  return createIndex(visualRow, 0, parentNode);
609 }
610 
611 /*
612  \internal
613 
614  return the index for node
615 */
617 {
618  Q_Q(const QFileSystemModel);
619  QFileSystemModelPrivate::QFileSystemNode *parentNode = (node ? node->parent : 0);
620  if (node == &root || !parentNode)
621  return QModelIndex();
622 
623  // get the parent's row
624  Q_ASSERT(node);
625  if (!node->isVisible)
626  return QModelIndex();
627 
628  int visualRow = translateVisibleLocation(parentNode, parentNode->visibleLocation(node->fileName));
629  return q->createIndex(visualRow, 0, const_cast<QFileSystemNode*>(node));
630 }
631 
636 {
637  Q_D(const QFileSystemModel);
638  if (parent.column() > 0)
639  return false;
640 
641  if (!parent.isValid()) // drives
642  return true;
643 
644  const QFileSystemModelPrivate::QFileSystemNode *indexNode = d->node(parent);
645  Q_ASSERT(indexNode);
646  return (indexNode->isDir());
647 }
648 
653 {
654  Q_D(const QFileSystemModel);
655  const QFileSystemModelPrivate::QFileSystemNode *indexNode = d->node(parent);
656  return (!indexNode->populatedChildren);
657 }
658 
663 {
665  if (!d->setRootPath)
666  return;
667  QFileSystemModelPrivate::QFileSystemNode *indexNode = d->node(parent);
668  if (indexNode->populatedChildren)
669  return;
670  indexNode->populatedChildren = true;
671  d->fileInfoGatherer.list(filePath(parent));
672 }
673 
678 {
679  Q_D(const QFileSystemModel);
680  if (parent.column() > 0)
681  return 0;
682 
683  if (!parent.isValid())
684  return d->root.visibleChildren.count();
685 
686  const QFileSystemModelPrivate::QFileSystemNode *parentNode = d->node(parent);
687  return parentNode->visibleChildren.count();
688 }
689 
694 {
695  return (parent.column() > 0) ? 0 : 4;
696 }
697 
704 {
705  Q_D(const QFileSystemModel);
706  switch (role) {
707  case Qt::DisplayRole:
708  return d->myComputer();
709  case Qt::DecorationRole:
710  return d->fileInfoGatherer.iconProvider()->icon(QFileIconProvider::Computer);
711  }
712  return QVariant();
713 }
714 
719 {
720  Q_D(const QFileSystemModel);
721  if (!index.isValid() || index.model() != this)
722  return QVariant();
723 
724  switch (role) {
725  case Qt::EditRole:
726  case Qt::DisplayRole:
727  switch (index.column()) {
728  case 0: return d->displayName(index);
729  case 1: return d->size(index);
730  case 2: return d->type(index);
731  case 3: return d->time(index);
732  default:
733  qWarning("data: invalid display value column %d", index.column());
734  break;
735  }
736  break;
737  case FilePathRole:
738  return filePath(index);
739  case FileNameRole:
740  return d->name(index);
741  case Qt::DecorationRole:
742  if (index.column() == 0) {
743  QIcon icon = d->icon(index);
744  if (icon.isNull()) {
745  if (d->node(index)->isDir())
746  icon = d->fileInfoGatherer.iconProvider()->icon(QFileIconProvider::Folder);
747  else
748  icon = d->fileInfoGatherer.iconProvider()->icon(QFileIconProvider::File);
749  }
750  return icon;
751  }
752  break;
754  if (index.column() == 1)
755  return Qt::AlignRight;
756  break;
757  case FilePermissions:
758  int p = permissions(index);
759  return p;
760  }
761 
762  return QVariant();
763 }
764 
769 {
770  if (!index.isValid())
771  return QString();
772  const QFileSystemNode *n = node(index);
773  if (n->isDir()) {
774 #ifdef Q_OS_MAC
775  return QLatin1String("--");
776 #else
777  return QLatin1String("");
778 #endif
779  // Windows - ""
780  // OS X - "--"
781  // Konqueror - "4 KB"
782  // Nautilus - "9 items" (the number of children)
783  }
784  return size(n->size());
785 }
786 
788 {
789  // According to the Si standard KB is 1000 bytes, KiB is 1024
790  // but on windows sizes are calculated by dividing by 1024 so we do what they do.
791  const qint64 kb = 1024;
792  const qint64 mb = 1024 * kb;
793  const qint64 gb = 1024 * mb;
794  const qint64 tb = 1024 * gb;
795  if (bytes >= tb)
796  return QFileSystemModel::tr("%1 TB").arg(QLocale().toString(qreal(bytes) / tb, 'f', 3));
797  if (bytes >= gb)
798  return QFileSystemModel::tr("%1 GB").arg(QLocale().toString(qreal(bytes) / gb, 'f', 2));
799  if (bytes >= mb)
800  return QFileSystemModel::tr("%1 MB").arg(QLocale().toString(qreal(bytes) / mb, 'f', 1));
801  if (bytes >= kb)
802  return QFileSystemModel::tr("%1 KB").arg(QLocale().toString(bytes / kb));
803  return QFileSystemModel::tr("%1 bytes").arg(QLocale().toString(bytes));
804 }
805 
810 {
811  if (!index.isValid())
812  return QString();
813 #ifndef QT_NO_DATESTRING
814  return node(index)->lastModified().toString(Qt::SystemLocaleDate);
815 #else
816  Q_UNUSED(index);
817  return QString();
818 #endif
819 }
820 
821 /*
822  \internal
823 */
825 {
826  if (!index.isValid())
827  return QString();
828  return node(index)->type();
829 }
830 
835 {
836  if (!index.isValid())
837  return QString();
838  QFileSystemNode *dirNode = node(index);
839  if (fileInfoGatherer.resolveSymlinks() && !resolvedSymLinks.isEmpty() &&
840  dirNode->isSymLink(/* ignoreNtfsSymLinks = */ true)) {
841  QString fullPath = QDir::fromNativeSeparators(filePath(index));
842  if (resolvedSymLinks.contains(fullPath))
843  return resolvedSymLinks[fullPath];
844  }
845  return dirNode->fileName;
846 }
847 
852 {
853 #if defined(Q_OS_WIN) && !defined(Q_OS_WINCE)
854  QFileSystemNode *dirNode = node(index);
855  if (!dirNode->volumeName.isNull())
856  return dirNode->volumeName + QLatin1String(" (") + name(index) + QLatin1Char(')');
857 #endif
858  return name(index);
859 }
860 
865 {
866  if (!index.isValid())
867  return QIcon();
868  return node(index)->icon();
869 }
870 
874 bool QFileSystemModel::setData(const QModelIndex &idx, const QVariant &value, int role)
875 {
877  if (!idx.isValid()
878  || idx.column() != 0
879  || role != Qt::EditRole
880  || (flags(idx) & Qt::ItemIsEditable) == 0) {
881  return false;
882  }
883 
884  QString newName = value.toString();
885  QString oldName = idx.data().toString();
886  if (newName == idx.data().toString())
887  return true;
888 
889  if (newName.isEmpty()
891  || !QDir(filePath(parent(idx))).rename(oldName, newName)) {
892 #ifndef QT_NO_MESSAGEBOX
893  QMessageBox::information(0, QFileSystemModel::tr("Invalid filename"),
894  QFileSystemModel::tr("<b>The name \"%1\" can not be used.</b><p>Try using another name, with fewer characters or no punctuations marks.")
895  .arg(newName),
897 #endif // QT_NO_MESSAGEBOX
898  return false;
899  } else {
900  /*
901  *After re-naming something we don't want the selection to change*
902  - can't remove rows and later insert
903  - can't quickly remove and insert
904  - index pointer can't change because treeview doesn't use persistant index's
905 
906  - if this get any more complicated think of changing it to just
907  use layoutChanged
908  */
909 
910  QFileSystemModelPrivate::QFileSystemNode *indexNode = d->node(idx);
911  QFileSystemModelPrivate::QFileSystemNode *parentNode = indexNode->parent;
912  int visibleLocation = parentNode->visibleLocation(parentNode->children.value(indexNode->fileName)->fileName);
913 
914  d->addNode(parentNode, newName,indexNode->info->fileInfo());
915  parentNode->visibleChildren.removeAt(visibleLocation);
916  QFileSystemModelPrivate::QFileSystemNode * oldValue = parentNode->children.value(oldName);
917  parentNode->children[newName] = oldValue;
918  QFileInfo info(d->rootDir, newName);
919  oldValue->fileName = newName;
920  oldValue->parent = parentNode;
921  oldValue->populate(d->fileInfoGatherer.getInfo(info));
922  oldValue->isVisible = true;
923 
924  parentNode->children.remove(oldName);
925  parentNode->visibleChildren.insert(visibleLocation, newName);
926 
927  d->delayedSort();
928  emit fileRenamed(filePath(idx.parent()), oldName, newName);
929  }
930  return true;
931 }
932 
936 QVariant QFileSystemModel::headerData(int section, Qt::Orientation orientation, int role) const
937 {
938  switch (role) {
939  case Qt::DecorationRole:
940  if (section == 0) {
941  // ### TODO oh man this is ugly and doesn't even work all the way!
942  // it is still 2 pixels off
943  QImage pixmap(16, 1, QImage::Format_Mono);
944  pixmap.fill(0);
945  pixmap.setAlphaChannel(pixmap.createAlphaMask());
946  return pixmap;
947  }
948  break;
950  return Qt::AlignLeft;
951  }
952 
953  if (orientation != Qt::Horizontal || role != Qt::DisplayRole)
954  return QAbstractItemModel::headerData(section, orientation, role);
955 
956  QString returnValue;
957  switch (section) {
958  case 0: returnValue = tr("Name");
959  break;
960  case 1: returnValue = tr("Size");
961  break;
962  case 2: returnValue =
963 #ifdef Q_OS_MAC
964  tr("Kind", "Match OS X Finder");
965 #else
966  tr("Type", "All other platforms");
967 #endif
968  break;
969  // Windows - Type
970  // OS X - Kind
971  // Konqueror - File Type
972  // Nautilus - Type
973  case 3: returnValue = tr("Date Modified");
974  break;
975  default: return QVariant();
976  }
977  return returnValue;
978 }
979 
983 Qt::ItemFlags QFileSystemModel::flags(const QModelIndex &index) const
984 {
985  Q_D(const QFileSystemModel);
986  Qt::ItemFlags flags = QAbstractItemModel::flags(index);
987  if (!index.isValid())
988  return flags;
989 
990  QFileSystemModelPrivate::QFileSystemNode *indexNode = d->node(index);
991  if (d->nameFilterDisables && !d->passNameFilters(indexNode)) {
992  flags &= ~Qt::ItemIsEnabled;
993  // ### TODO you shouldn't be able to set this as the current item, task 119433
994  return flags;
995  }
996 
997  flags |= Qt::ItemIsDragEnabled;
998  if (d->readOnly)
999  return flags;
1000  if ((index.column() == 0) && indexNode->permissions() & QFile::WriteUser) {
1001  flags |= Qt::ItemIsEditable;
1002  if (indexNode->isDir())
1003  flags |= Qt::ItemIsDropEnabled;
1004  }
1005  return flags;
1006 }
1007 
1012 {
1014  q->sort(sortColumn, sortOrder);
1015 }
1016 
1017 static inline QChar getNextChar(const QString &s, int location)
1018 {
1019  return (location < s.length()) ? s.at(location) : QChar();
1020 }
1021 
1036 {
1037  for (int l1 = 0, l2 = 0; l1 <= s1.count() && l2 <= s2.count(); ++l1, ++l2) {
1038  // skip spaces, tabs and 0's
1039  QChar c1 = getNextChar(s1, l1);
1040  while (c1.isSpace())
1041  c1 = getNextChar(s1, ++l1);
1042  QChar c2 = getNextChar(s2, l2);
1043  while (c2.isSpace())
1044  c2 = getNextChar(s2, ++l2);
1045 
1046  if (c1.isDigit() && c2.isDigit()) {
1047  while (c1.digitValue() == 0)
1048  c1 = getNextChar(s1, ++l1);
1049  while (c2.digitValue() == 0)
1050  c2 = getNextChar(s2, ++l2);
1051 
1052  int lookAheadLocation1 = l1;
1053  int lookAheadLocation2 = l2;
1054  int currentReturnValue = 0;
1055  // find the last digit, setting currentReturnValue as we go if it isn't equal
1056  for (
1057  QChar lookAhead1 = c1, lookAhead2 = c2;
1058  (lookAheadLocation1 <= s1.length() && lookAheadLocation2 <= s2.length());
1059  lookAhead1 = getNextChar(s1, ++lookAheadLocation1),
1060  lookAhead2 = getNextChar(s2, ++lookAheadLocation2)
1061  ) {
1062  bool is1ADigit = !lookAhead1.isNull() && lookAhead1.isDigit();
1063  bool is2ADigit = !lookAhead2.isNull() && lookAhead2.isDigit();
1064  if (!is1ADigit && !is2ADigit)
1065  break;
1066  if (!is1ADigit)
1067  return -1;
1068  if (!is2ADigit)
1069  return 1;
1070  if (currentReturnValue == 0) {
1071  if (lookAhead1 < lookAhead2) {
1072  currentReturnValue = -1;
1073  } else if (lookAhead1 > lookAhead2) {
1074  currentReturnValue = 1;
1075  }
1076  }
1077  }
1078  if (currentReturnValue != 0)
1079  return currentReturnValue;
1080  }
1081 
1082  if (cs == Qt::CaseInsensitive) {
1083  if (!c1.isLower()) c1 = c1.toLower();
1084  if (!c2.isLower()) c2 = c2.toLower();
1085  }
1086  int r = QString::localeAwareCompare(c1, c2);
1087  if (r < 0)
1088  return -1;
1089  if (r > 0)
1090  return 1;
1091  }
1092  // The two strings are the same (02 == 2) so fall back to the normal sort
1093  return QString::compare(s1, s2, cs);
1094 }
1095 
1096 /*
1097  \internal
1098  Helper functor used by sort()
1099 */
1101 {
1102 public:
1103  inline QFileSystemModelSorter(int column) : sortColumn(column) {}
1104 
1107  {
1108  switch (sortColumn) {
1109  case 0: {
1110 #ifndef Q_OS_MAC
1111  // place directories before files
1112  bool left = l->isDir();
1113  bool right = r->isDir();
1114  if (left ^ right)
1115  return left;
1116 #endif
1118  r->fileName, Qt::CaseInsensitive) < 0;
1119  }
1120  case 1:
1121  // Directories go first
1122  if (l->isDir() && !r->isDir())
1123  return true;
1124  return l->size() < r->size();
1125  case 2:
1126  return l->type() < r->type();
1127  case 3:
1128  return l->lastModified() < r->lastModified();
1129  }
1130  Q_ASSERT(false);
1131  return false;
1132  }
1133 
1136  {
1137  return compareNodes(l.first, r.first);
1138  }
1139 
1140 
1141 private:
1143 };
1144 
1145 /*
1146  \internal
1147 
1148  Sort all of the children of parent
1149 */
1151 {
1153  QFileSystemModelPrivate::QFileSystemNode *indexNode = node(parent);
1154  if (indexNode->children.count() == 0)
1155  return;
1156 
1159  int i = 0;
1160  for(iterator = indexNode->children.begin() ; iterator != indexNode->children.end() ; ++iterator) {
1161  if (filtersAcceptsNode(iterator.value())) {
1163  } else {
1164  iterator.value()->isVisible = false;
1165  }
1166  i++;
1167  }
1168  QFileSystemModelSorter ms(column);
1169  qStableSort(values.begin(), values.end(), ms);
1170  // First update the new visible list
1171  indexNode->visibleChildren.clear();
1172  //No more dirty item we reset our internal dirty index
1173  indexNode->dirtyChildrenIndex = -1;
1174  for (int i = 0; i < values.count(); ++i) {
1175  indexNode->visibleChildren.append(values.at(i).first->fileName);
1176  values.at(i).first->isVisible = true;
1177  }
1178 
1179  if (!disableRecursiveSort) {
1180  for (int i = 0; i < q->rowCount(parent); ++i) {
1181  const QModelIndex childIndex = q->index(i, 0, parent);
1182  QFileSystemModelPrivate::QFileSystemNode *indexNode = node(childIndex);
1183  //Only do a recursive sort on visible nodes
1184  if (indexNode->isVisible)
1185  sortChildren(column, childIndex);
1186  }
1187  }
1188 }
1189 
1193 void QFileSystemModel::sort(int column, Qt::SortOrder order)
1194 {
1196  if (d->sortOrder == order && d->sortColumn == column && !d->forceSort)
1197  return;
1198 
1202  for (int i = 0; i < oldList.count(); ++i) {
1203  QPair<QFileSystemModelPrivate::QFileSystemNode*, int> pair(d->node(oldList.at(i)), oldList.at(i).column());
1204  oldNodes.append(pair);
1205  }
1206 
1207  if (!(d->sortColumn == column && d->sortOrder != order && !d->forceSort)) {
1208  //we sort only from where we are, don't need to sort all the model
1209  d->sortChildren(column, index(rootPath()));
1210  d->sortColumn = column;
1211  d->forceSort = false;
1212  }
1213  d->sortOrder = order;
1214 
1215  QModelIndexList newList;
1216  for (int i = 0; i < oldNodes.count(); ++i) {
1217  QModelIndex idx = d->index(oldNodes.at(i).first);
1218  idx = idx.sibling(idx.row(), oldNodes.at(i).second);
1219  newList.append(idx);
1220  }
1221  changePersistentIndexList(oldList, newList);
1222  emit layoutChanged();
1223 }
1224 
1230 {
1231  return QStringList(QLatin1String("text/uri-list"));
1232 }
1233 
1243 {
1244  QList<QUrl> urls;
1246  for (; it != indexes.end(); ++it)
1247  if ((*it).column() == 0)
1248  urls << QUrl::fromLocalFile(filePath(*it));
1249  QMimeData *data = new QMimeData();
1250  data->setUrls(urls);
1251  return data;
1252 }
1253 
1262  int row, int column, const QModelIndex &parent)
1263 {
1264  Q_UNUSED(row);
1265  Q_UNUSED(column);
1266  if (!parent.isValid() || isReadOnly())
1267  return false;
1268 
1269  bool success = true;
1270  QString to = filePath(parent) + QDir::separator();
1271 
1272  QList<QUrl> urls = data->urls();
1274 
1275  switch (action) {
1276  case Qt::CopyAction:
1277  for (; it != urls.constEnd(); ++it) {
1278  QString path = (*it).toLocalFile();
1279  success = QFile::copy(path, to + QFileInfo(path).fileName()) && success;
1280  }
1281  break;
1282  case Qt::LinkAction:
1283  for (; it != urls.constEnd(); ++it) {
1284  QString path = (*it).toLocalFile();
1285  success = QFile::link(path, to + QFileInfo(path).fileName()) && success;
1286  }
1287  break;
1288  case Qt::MoveAction:
1289  for (; it != urls.constEnd(); ++it) {
1290  QString path = (*it).toLocalFile();
1291  success = QFile::rename(path, to + QFileInfo(path).fileName()) && success;
1292  }
1293  break;
1294  default:
1295  return false;
1296  }
1297 
1298  return success;
1299 }
1300 
1305 {
1307 }
1308 
1314 {
1315  Q_D(const QFileSystemModel);
1316  QString fullPath = d->filePath(index);
1317  QFileSystemModelPrivate::QFileSystemNode *dirNode = d->node(index);
1318  if (dirNode->isSymLink() && d->fileInfoGatherer.resolveSymlinks()
1319  && d->resolvedSymLinks.contains(fullPath)
1320  && dirNode->isDir()) {
1321  QFileInfo resolvedInfo(fullPath);
1322  resolvedInfo = resolvedInfo.canonicalFilePath();
1323  if (resolvedInfo.exists())
1324  return resolvedInfo.filePath();
1325  }
1326  return fullPath;
1327 }
1328 
1330 {
1331  Q_Q(const QFileSystemModel);
1332  Q_UNUSED(q);
1333  if (!index.isValid())
1334  return QString();
1335  Q_ASSERT(index.model() == q);
1336 
1337  QStringList path;
1338  QModelIndex idx = index;
1339  while (idx.isValid()) {
1340  QFileSystemModelPrivate::QFileSystemNode *dirNode = node(idx);
1341  if (dirNode)
1342  path.prepend(dirNode->fileName);
1343  idx = idx.parent();
1344  }
1345  QString fullPath = QDir::fromNativeSeparators(path.join(QDir::separator()));
1346 #if !defined(Q_OS_WIN) || defined(Q_OS_WINCE)
1347  if ((fullPath.length() > 2) && fullPath[0] == QLatin1Char('/') && fullPath[1] == QLatin1Char('/'))
1348  fullPath = fullPath.mid(1);
1349 #endif
1350 #if defined(Q_OS_WIN) || defined(Q_OS_SYMBIAN)
1351  if (fullPath.length() == 2 && fullPath.endsWith(QLatin1Char(':')))
1352  fullPath.append(QLatin1Char('/'));
1353 #endif
1354  return fullPath;
1355 }
1356 
1361 {
1363  if (!parent.isValid())
1364  return parent;
1365 
1366  QDir dir(filePath(parent));
1367  if (!dir.mkdir(name))
1368  return QModelIndex();
1369  QFileSystemModelPrivate::QFileSystemNode *parentNode = d->node(parent);
1370  d->addNode(parentNode, name, QFileInfo());
1371  Q_ASSERT(parentNode->children.contains(name));
1373  node->populate(d->fileInfoGatherer.getInfo(QFileInfo(dir.absolutePath() + QDir::separator() + name)));
1374  d->addVisibleFiles(parentNode, QStringList(name));
1375  return d->index(node);
1376 }
1377 
1381 QFile::Permissions QFileSystemModel::permissions(const QModelIndex &index) const
1382 {
1383  Q_D(const QFileSystemModel);
1384  QFile::Permissions p = d->node(index)->permissions();
1385  if (d->readOnly) {
1388  }
1389  return p;
1390 }
1391 
1406 {
1408 #ifdef Q_OS_WIN
1409 #ifdef Q_OS_WIN32
1410  QString longNewPath = qt_GetLongPathName(newPath);
1411 #else
1412  QString longNewPath = QDir::fromNativeSeparators(newPath);
1413 #endif
1414 #else
1415  QString longNewPath = newPath;
1416 #endif
1417  QDir newPathDir(longNewPath);
1418  //we remove .. and . from the given path if exist
1419  if (!newPath.isEmpty()) {
1420  longNewPath = QDir::cleanPath(longNewPath);
1421  newPathDir.setPath(longNewPath);
1422  }
1423 
1424  d->setRootPath = true;
1425 
1426  //user don't ask for the root path ("") but the conversion failed
1427  if (!newPath.isEmpty() && longNewPath.isEmpty())
1428  return d->index(rootPath());
1429 
1430  if (d->rootDir.path() == longNewPath)
1431  return d->index(rootPath());
1432 
1433  bool showDrives = (longNewPath.isEmpty() || longNewPath == d->myComputer());
1434  if (!showDrives && !newPathDir.exists())
1435  return d->index(rootPath());
1436 
1437  //We remove the watcher on the previous path
1438  if (!rootPath().isEmpty() && rootPath() != QLatin1String(".")) {
1439  //This remove the watcher for the old rootPath
1440  d->fileInfoGatherer.removePath(rootPath());
1441  //This line "marks" the node as dirty, so the next fetchMore
1442  //call on the path will ask the gatherer to install a watcher again
1443  //But it doesn't re-fetch everything
1444  d->node(rootPath())->populatedChildren = false;
1445  }
1446 
1447  // We have a new valid root path
1448  d->rootDir = newPathDir;
1449  QModelIndex newRootIndex;
1450  if (showDrives) {
1451  // otherwise dir will become '.'
1452  d->rootDir.setPath(QLatin1String(""));
1453  } else {
1454  newRootIndex = d->index(newPathDir.path());
1455  }
1456  fetchMore(newRootIndex);
1457  emit rootPathChanged(longNewPath);
1458  d->forceSort = true;
1459  d->delayedSort();
1460  return newRootIndex;
1461 }
1462 
1469 {
1470  Q_D(const QFileSystemModel);
1471  return d->rootDir.path();
1472 }
1473 
1480 {
1481  Q_D(const QFileSystemModel);
1482  QDir dir(d->rootDir);
1483  dir.setNameFilters(nameFilters());
1484  dir.setFilter(filter());
1485  return dir;
1486 }
1487 
1492 {
1494  d->fileInfoGatherer.setIconProvider(provider);
1495  d->root.updateIcon(provider, QString());
1496 }
1497 
1502 {
1503  Q_D(const QFileSystemModel);
1504  return d->fileInfoGatherer.iconProvider();
1505 }
1506 
1516 {
1518  if (d->filters == filters)
1519  return;
1520  d->filters = filters;
1521  // CaseSensitivity might have changed
1523  d->forceSort = true;
1524  d->delayedSort();
1525 }
1526 
1535 QDir::Filters QFileSystemModel::filter() const
1536 {
1537  Q_D(const QFileSystemModel);
1538  return d->filters;
1539 }
1540 
1553 {
1555  d->fileInfoGatherer.setResolveSymlinks(enable);
1556 }
1557 
1559 {
1560  Q_D(const QFileSystemModel);
1561  return d->fileInfoGatherer.resolveSymlinks();
1562 }
1563 
1577 {
1579  d->readOnly = enable;
1580 }
1581 
1583 {
1584  Q_D(const QFileSystemModel);
1585  return d->readOnly;
1586 }
1587 
1598 {
1600  if (d->nameFilterDisables == enable)
1601  return;
1602  d->nameFilterDisables = enable;
1603  d->forceSort = true;
1604  d->delayedSort();
1605 }
1606 
1608 {
1609  Q_D(const QFileSystemModel);
1610  return d->nameFilterDisables;
1611 }
1612 
1617 {
1618  // Prep the regexp's ahead of time
1619 #ifndef QT_NO_REGEXP
1621 
1622  if (!d->bypassFilters.isEmpty()) {
1623  // update the bypass filter to only bypass the stuff that must be kept around
1624  d->bypassFilters.clear();
1625  // We guarantee that rootPath will stick around
1627  QModelIndexList persistantList = persistentIndexList();
1628  for (int i = 0; i < persistantList.count(); ++i) {
1630  node = d->node(persistantList.at(i));
1631  while (node) {
1632  if (d->bypassFilters.contains(node))
1633  break;
1634  if (node->isDir())
1635  d->bypassFilters[node] = true;
1636  node = node->parent;
1637  }
1638  }
1639  }
1640 
1641  d->nameFilters.clear();
1642  const Qt::CaseSensitivity caseSensitive =
1644  for (int i = 0; i < filters.size(); ++i) {
1645  d->nameFilters << QRegExp(filters.at(i), caseSensitive, QRegExp::Wildcard);
1646  }
1647  d->forceSort = true;
1648  d->delayedSort();
1649 #endif
1650 }
1651 
1656 {
1657  Q_D(const QFileSystemModel);
1659 #ifndef QT_NO_REGEXP
1660  for (int i = 0; i < d->nameFilters.size(); ++i) {
1661  filters << d->nameFilters.at(i).pattern();
1662  }
1663 #endif
1664  return filters;
1665 }
1666 
1671 {
1673  if (event->type() == QEvent::LanguageChange) {
1674  d->root.retranslateStrings(d->fileInfoGatherer.iconProvider(), QString());
1675  return true;
1676  }
1677  return QAbstractItemModel::event(event);
1678 }
1679 
1680 bool QFileSystemModel::rmdir(const QModelIndex &aindex) const
1681 {
1682  QString path = filePath(aindex);
1683  QFileSystemModelPrivate * d = const_cast<QFileSystemModelPrivate*>(d_func());
1684  d->fileInfoGatherer.removePath(path);
1685  return QDir().rmdir(path);
1686 }
1687 
1698 {
1699  QFileSystemModelPrivate::QFileSystemNode *parentNode = node(directory, false);
1700  if (parentNode->children.count() == 0)
1701  return;
1702  QStringList toRemove;
1703 #if defined(Q_OS_SYMBIAN)
1704  // Filename case must be exact in qBinaryFind below, so create a list of all lowercase names.
1705  QStringList newFiles;
1706  for(int i = 0; i < files.size(); i++) {
1707  newFiles << files.at(i).toLower();
1708  }
1709 #else
1710  QStringList newFiles = files;
1711 #endif
1712  qSort(newFiles.begin(), newFiles.end());
1713  QHash<QString, QFileSystemNode*>::const_iterator i = parentNode->children.constBegin();
1714  while (i != parentNode->children.constEnd()) {
1715  QStringList::iterator iterator;
1716  iterator = qBinaryFind(newFiles.begin(), newFiles.end(),
1717 #if defined(Q_OS_SYMBIAN)
1718  i.value()->fileName.toLower());
1719 #else
1720  i.value()->fileName);
1721 #endif
1722  if (iterator == newFiles.end()) {
1723  toRemove.append(i.value()->fileName);
1724  }
1725  ++i;
1726  }
1727  for (int i = 0 ; i < toRemove.count() ; ++i )
1728  removeNode(parentNode, toRemove[i]);
1729 }
1730 
1739 {
1740  // In the common case, itemLocation == count() so check there first
1742 #ifndef QT_NO_FILESYSTEMWATCHER
1743  node->populate(info);
1744 #endif
1745 #if defined(Q_OS_WIN) && !defined(Q_OS_WINCE)
1746  //The parentNode is "" so we are listing the drives
1747  if (parentNode->fileName.isEmpty()) {
1748  wchar_t name[MAX_PATH + 1];
1749  //GetVolumeInformation requires to add trailing backslash
1750  const QString nodeName = fileName + QLatin1String("\\");
1751  BOOL success = ::GetVolumeInformation((wchar_t *)(nodeName.utf16()),
1752  name, MAX_PATH + 1, NULL, 0, NULL, NULL, 0);
1753  if (success && name[0])
1754  node->volumeName = QString::fromWCharArray(name);
1755  }
1756 #endif
1757  parentNode->children.insert(fileName, node);
1758  return node;
1759 }
1760 
1770 {
1772  QModelIndex parent = index(parentNode);
1773  bool indexHidden = isHiddenByFilter(parentNode, parent);
1774 
1775  int vLocation = parentNode->visibleLocation(name);
1776  if (vLocation >= 0 && !indexHidden)
1777  q->beginRemoveRows(parent, translateVisibleLocation(parentNode, vLocation),
1778  translateVisibleLocation(parentNode, vLocation));
1779  QFileSystemNode * node = parentNode->children.take(name);
1780  delete node;
1781  // cleanup sort files after removing rather then re-sorting which is O(n)
1782  if (vLocation >= 0)
1783  parentNode->visibleChildren.removeAt(vLocation);
1784  if (vLocation >= 0 && !indexHidden)
1785  q->endRemoveRows();
1786 }
1787 
1788 /*
1789  \internal
1790  Helper functor used by addVisibleFiles()
1791 */
1793 {
1794 public:
1795  inline QFileSystemModelVisibleFinder(QFileSystemModelPrivate::QFileSystemNode *node, QFileSystemModelSorter *sorter) : parentNode(node), sorter(sorter) {}
1796 
1797  bool operator()(const QString &, QString r) const
1798  {
1799  return sorter->compareNodes(parentNode->children.value(name), parentNode->children.value(r));
1800  }
1801 
1803 private:
1806 };
1807 
1817 {
1819  QModelIndex parent = index(parentNode);
1820  bool indexHidden = isHiddenByFilter(parentNode, parent);
1821  if (!indexHidden) {
1822  q->beginInsertRows(parent, parentNode->visibleChildren.count() , parentNode->visibleChildren.count() + newFiles.count() - 1);
1823  }
1824 
1825  if (parentNode->dirtyChildrenIndex == -1)
1826  parentNode->dirtyChildrenIndex = parentNode->visibleChildren.count();
1827 
1828  for (int i = 0; i < newFiles.count(); ++i) {
1829  parentNode->visibleChildren.append(newFiles.at(i));
1830  parentNode->children[newFiles.at(i)]->isVisible = true;
1831  }
1832  if (!indexHidden)
1833  q->endInsertRows();
1834 }
1835 
1844 {
1846  if (vLocation == -1)
1847  return;
1848  QModelIndex parent = index(parentNode);
1849  bool indexHidden = isHiddenByFilter(parentNode, parent);
1850  if (!indexHidden)
1851  q->beginRemoveRows(parent, translateVisibleLocation(parentNode, vLocation),
1852  translateVisibleLocation(parentNode, vLocation));
1853  parentNode->children[parentNode->visibleChildren.at(vLocation)]->isVisible = false;
1854  parentNode->visibleChildren.removeAt(vLocation);
1855  if (!indexHidden)
1856  q->endRemoveRows();
1857 }
1858 
1869 {
1871  QVector<QString> rowsToUpdate;
1872  QStringList newFiles;
1873  QFileSystemModelPrivate::QFileSystemNode *parentNode = node(path, false);
1874  QModelIndex parentIndex = index(parentNode);
1875  for (int i = 0; i < updates.count(); ++i) {
1876  QString fileName = updates.at(i).first;
1877  Q_ASSERT(!fileName.isEmpty());
1878  QExtendedInformation info = fileInfoGatherer.getInfo(updates.at(i).second);
1879  bool previouslyHere = parentNode->children.contains(fileName);
1880  if (!previouslyHere) {
1881  addNode(parentNode, fileName, info.fileInfo());
1882  }
1883  QFileSystemModelPrivate::QFileSystemNode * node = parentNode->children.value(fileName);
1884  bool isCaseSensitive = parentNode->caseSensitive();
1885  if (isCaseSensitive) {
1886  if (node->fileName != fileName)
1887  continue;
1888  } else {
1889  if (QString::compare(node->fileName,fileName,Qt::CaseInsensitive) != 0)
1890  continue;
1891  }
1892  if (isCaseSensitive) {
1893  Q_ASSERT(node->fileName == fileName);
1894  } else {
1895  node->fileName = fileName;
1896  }
1897 
1898  if (info.size() == -1 && !info.isSymLink()) {
1899  removeNode(parentNode, fileName);
1900  continue;
1901  }
1902  if (*node != info ) {
1903  node->populate(info);
1904  bypassFilters.remove(node);
1905  // brand new information.
1906  if (filtersAcceptsNode(node)) {
1907  if (!node->isVisible) {
1908  newFiles.append(fileName);
1909  } else {
1910  rowsToUpdate.append(fileName);
1911  }
1912  } else {
1913  if (node->isVisible) {
1914  int visibleLocation = parentNode->visibleLocation(fileName);
1915  removeVisibleFile(parentNode, visibleLocation);
1916  } else {
1917  // The file is not visible, don't do anything
1918  }
1919  }
1920  }
1921  }
1922 
1923  // bundle up all of the changed signals into as few as possible.
1924  qSort(rowsToUpdate.begin(), rowsToUpdate.end());
1925  QString min;
1926  QString max;
1927  for (int i = 0; i < rowsToUpdate.count(); ++i) {
1928  QString value = rowsToUpdate.at(i);
1929  //##TODO is there a way to bundle signals with QString as the content of the list?
1930  /*if (min.isEmpty()) {
1931  min = value;
1932  if (i != rowsToUpdate.count() - 1)
1933  continue;
1934  }
1935  if (i != rowsToUpdate.count() - 1) {
1936  if ((value == min + 1 && max.isEmpty()) || value == max + 1) {
1937  max = value;
1938  continue;
1939  }
1940  }*/
1941  max = value;
1942  min = value;
1943  int visibleMin = parentNode->visibleLocation(min);
1944  int visibleMax = parentNode->visibleLocation(max);
1945  if (visibleMin >= 0
1946  && visibleMin < parentNode->visibleChildren.count()
1947  && parentNode->visibleChildren.at(visibleMin) == min
1948  && visibleMax >= 0) {
1949  QModelIndex bottom = q->index(translateVisibleLocation(parentNode, visibleMin), 0, parentIndex);
1950  QModelIndex top = q->index(translateVisibleLocation(parentNode, visibleMax), 3, parentIndex);
1951  emit q->dataChanged(bottom, top);
1952  }
1953 
1954  /*min = QString();
1955  max = QString();*/
1956  }
1957 
1958  if (newFiles.count() > 0) {
1959  addVisibleFiles(parentNode, newFiles);
1960  }
1961 
1962  if (newFiles.count() > 0 || (sortColumn != 0 && rowsToUpdate.count() > 0)) {
1963  forceSort = true;
1964  delayedSort();
1965  }
1966 }
1967 
1972 {
1973  resolvedSymLinks[fileName] = resolvedName;
1974 }
1975 
1980 {
1982  qRegisterMetaType<QList<QPair<QString,QFileInfo> > >("QList<QPair<QString,QFileInfo> >");
1983  q->connect(&fileInfoGatherer, SIGNAL(newListOfFiles(QString,QStringList)),
1984  q, SLOT(_q_directoryChanged(QString,QStringList)));
1985  q->connect(&fileInfoGatherer, SIGNAL(updates(QString,QList<QPair<QString,QFileInfo> >)),
1986  q, SLOT(_q_fileSystemChanged(QString,QList<QPair<QString,QFileInfo> >)));
1987  q->connect(&fileInfoGatherer, SIGNAL(nameResolved(QString,QString)),
1988  q, SLOT(_q_resolvedName(QString,QString)));
1989  q->connect(&fileInfoGatherer, SIGNAL(directoryLoaded(QString)),
1991  q->connect(&delayedSortTimer, SIGNAL(timeout()), q, SLOT(_q_performDelayedSort()), Qt::QueuedConnection);
1992 
1993  QHash<int, QByteArray> roles = q->roleNames();
1994  roles.insertMulti(QFileSystemModel::FileIconRole, "fileIcon"); // == Qt::decoration
1995  roles.insert(QFileSystemModel::FilePathRole, "filePath");
1996  roles.insert(QFileSystemModel::FileNameRole, "fileName");
1997  roles.insert(QFileSystemModel::FilePermissions, "filePermissions");
1998  q->setRoleNames(roles);
1999 }
2000 
2010 {
2011  // always accept drives
2012  if (node->parent == &root || bypassFilters.contains(node))
2013  return true;
2014 
2015  // If we don't know anything yet don't accept it
2016  if (!node->hasInformation())
2017  return false;
2018 
2019  const bool filterPermissions = ((filters & QDir::PermissionMask)
2021  const bool hideDirs = !(filters & (QDir::Dirs | QDir::AllDirs));
2022  const bool hideFiles = !(filters & QDir::Files);
2023  const bool hideReadable = !(!filterPermissions || (filters & QDir::Readable));
2024  const bool hideWritable = !(!filterPermissions || (filters & QDir::Writable));
2025  const bool hideExecutable = !(!filterPermissions || (filters & QDir::Executable));
2026  const bool hideHidden = !(filters & QDir::Hidden);
2027  const bool hideSystem = !(filters & QDir::System);
2028  const bool hideSymlinks = (filters & QDir::NoSymLinks);
2029  const bool hideDot = (filters & QDir::NoDot) || (filters & QDir::NoDotAndDotDot); // ### Qt5: simplify (because NoDotAndDotDot=NoDot|NoDotDot)
2030  const bool hideDotDot = (filters & QDir::NoDotDot) || (filters & QDir::NoDotAndDotDot); // ### Qt5: simplify (because NoDotAndDotDot=NoDot|NoDotDot)
2031 
2032  // Note that we match the behavior of entryList and not QFileInfo on this and this
2033  // incompatibility won't be fixed until Qt 5 at least
2034  bool isDot = (node->fileName == QLatin1String("."));
2035  bool isDotDot = (node->fileName == QLatin1String(".."));
2036  if ( (hideHidden && !(isDot || isDotDot) && node->isHidden())
2037  || (hideSystem && node->isSystem())
2038  || (hideDirs && node->isDir())
2039  || (hideFiles && node->isFile())
2040  || (hideSymlinks && node->isSymLink())
2041  || (hideReadable && node->isReadable())
2042  || (hideWritable && node->isWritable())
2043  || (hideExecutable && node->isExecutable())
2044  || (hideDot && isDot)
2045  || (hideDotDot && isDotDot))
2046  return false;
2047 
2048  return nameFilterDisables || passNameFilters(node);
2049 }
2050 
2051 /*
2052  \internal
2053 
2054  Returns true if node passes the name filters and should be visible.
2055  */
2057 {
2058 #ifndef QT_NO_REGEXP
2059  if (nameFilters.isEmpty())
2060  return true;
2061 
2062  // Check the name regularexpression filters
2063  if (!(node->isDir() && (filters & QDir::AllDirs))) {
2064  for (int i = 0; i < nameFilters.size(); ++i) {
2065  if (nameFilters.at(i).exactMatch(node->fileName))
2066  return true;
2067  }
2068  return false;
2069  }
2070 #endif
2071  return true;
2072 }
2073 
2075 
2076 #include "moc_qfilesystemmodel.cpp"
2077 
2078 #endif // QT_NO_FILESYSTEMMODEL
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
static QString fromWCharArray(const wchar_t *, int size=-1)
Returns a copy of the string, where the encoding of string depends on the size of wchar...
Definition: qstring.cpp:1019
The QDir class provides access to directory structures and their contents.
Definition: qdir.h:58
void populate(const QExtendedInformation &fileInfo)
QBool contains(QChar c, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Definition: qstring.h:904
void resize(int size)
double d
Definition: qnumeric_p.h:62
int columnCount(const QModelIndex &parent=QModelIndex()) const
Reimplemented Function
void removePath(const QString &path)
void * internalPointer() const
Returns a void * pointer used by the model to associate the index with the internal data structure...
QHash< QString, QFileSystemNode * > children
bool rename(const QString &newName)
Renames the file currently specified by fileName() to newName.
Definition: qfile.cpp:766
The QHash::const_iterator class provides an STL-style const iterator for QHash and QMultiHash...
Definition: qhash.h:395
static int naturalCompare(const QString &s1, const QString &s2, Qt::CaseSensitivity cs)
Natural number sort, skips spaces.
The QFileSystemModel class provides a data model for the local filesystem.
QString displayName(const QModelIndex &index) const
void sort(int column, Qt::SortOrder order=Qt::AscendingOrder)
Reimplemented Function
QIcon icon(const QModelIndex &index) const
double qreal
Definition: qglobal.h:1193
bool passNameFilters(const QFileSystemNode *node) const
static mach_timebase_info_data_t info
QModelIndexList persistentIndexList() const
Returns the list of indexes stored as persistent indexes in the model.
QString filePath(const QModelIndex &index) const
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
bool canFetchMore(const QModelIndex &parent) const
Reimplemented Function
bool hasNext() const
Returns true if there is at least one more entry in the directory; otherwise, false is returned...
QString fileName(const QModelIndex &index) const
Returns the file name for the item stored in the model under the given index.
int digitValue() const
Returns the numeric value of the digit, or -1 if the character is not a digit.
Definition: qchar.cpp:817
const QChar at(int i) const
Returns the character at the given index position in the string.
Definition: qstring.h:698
QFileSystemModel(QObject *parent=0)
Constructs a file system model with the given parent.
The QRegExp class provides pattern matching using regular expressions.
Definition: qregexp.h:61
qint64 size(const QModelIndex &index) const
Returns the size in bytes of index.
QVariant data(int role=Qt::DisplayRole) const
Returns the data for the given role for the item referred to by the index.
void directoryLoaded(const QString &path)
This signal is emitted when the gatherer thread has finished to load the path.
void rootPathChanged(const QString &newPath)
This signal is emitted whenever the root path has been changed to a newPath.
bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole)
Reimplemented Function
QModelIndex sibling(int row, int column) const
Returns the sibling at row and column.
bool isNull() const
Returns true if the character is the Unicode character 0x0000 (&#39;\0&#39;); otherwise returns false...
Definition: qchar.h:262
#define it(className, varName)
QString name(const QModelIndex &index) const
int count(const T &t) const
Returns the number of occurrences of value in the vector.
Definition: qvector.h:742
void fileRenamed(const QString &path, const QString &oldName, const QString &newName)
This signal is emitted whenever a file with the oldName is successfully renamed to newName...
void setPath(const QString &path)
Sets the path of the directory to path.
Definition: qdir.cpp:590
void setNameFilterDisables(bool enable)
QString type(const QModelIndex &index) const
Returns the type of file index such as "Directory" or "JPEG file".
#define error(msg)
bool resolveSymlinks() const
void fill(uint pixel)
Fills the entire image with the given pixelValue.
Definition: qimage.cpp:2032
bool filtersAcceptsNode(const QFileSystemNode *node) const
void chop(int n)
Removes n characters from the end of the string.
Definition: qstring.cpp:4623
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
QString toUpper() const Q_REQUIRED_RESULT
Returns an uppercase copy of the string.
Definition: qstring.cpp:5483
#define SLOT(a)
Definition: qobjectdefs.h:226
T1 first
Definition: qpair.h:65
iterator begin()
Returns an STL-style iterator pointing to the first item in the list.
Definition: qlist.h:267
QString toString() const
Returns the variant as a QString if the variant has type() String , Bool , ByteArray ...
Definition: qvariant.cpp:2270
const_iterator constBegin() const
Returns a const STL-style iterator pointing to the first item in the list.
Definition: qlist.h:269
QModelIndex createIndex(int row, int column, void *data=0) const
Creates a model index for the given row and column with the internal pointer ptr. ...
bool mkdir(const QString &dirName) const
Creates a sub-directory called dirName.
Definition: qdir.cpp:1424
bool rmdir(const QModelIndex &index) const
Removes the directory corresponding to the model item index in the file system model and deletes the ...
bool hasChildren(const QModelIndex &parent=QModelIndex()) const
Reimplemented Function
bool startsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string starts with s; otherwise returns false.
Definition: qstring.cpp:3734
void insert(int i, const T &t)
Inserts value at index position i in the list.
Definition: qlist.h:575
static QString tr(const char *sourceText, const char *comment=0, int n=-1)
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
bool exists() const
Returns true if the file exists; otherwise returns false.
Definition: qfileinfo.cpp:675
void pop_front()
This function is provided for STL compatibility.
Definition: qlist.h:302
Q_OUTOFLINE_TEMPLATE RandomAccessIterator qBinaryFind(RandomAccessIterator begin, RandomAccessIterator end, const T &value)
Definition: qalgorithms.h:295
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
void fetchMore(const QModelIndex &parent)
Reimplemented Function
The QDirIterator class provides an iterator for directory entrylists.
Definition: qdiriterator.h:54
The QString class provides a Unicode character string.
Definition: qstring.h:83
void removeVisibleFile(QFileSystemNode *parentNode, int visibleLocation)
QFileIconProvider * iconProvider() const
Returns the file icon provider for this directory model.
bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent)
Handles the data supplied by a drag and drop operation that ended with the given action over the row ...
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
virtual bool event(QEvent *)
This virtual function receives events to an object and should return true if the event e was recogniz...
Definition: qobject.cpp:1200
#define Q_D(Class)
Definition: qglobal.h:2482
static QChar separator()
Returns the native directory separator: "/" under Unix (including Mac OS X) and "\\" under Windows...
Definition: qdir.cpp:1831
QFileSystemModelPrivate::QFileSystemNode * parentNode
The QChar class provides a 16-bit Unicode character.
Definition: qchar.h:72
QStringList nameFilters() const
Returns a list of filters applied to the names in the model.
void addVisibleFiles(QFileSystemNode *parentNode, const QStringList &newFiles)
QModelIndex parent() const
Returns the parent of the model index, or QModelIndex() if it has no parent.
Q_CORE_EXPORT QTextStream & right(QTextStream &s)
bool exists() const
Returns true if the directory exists; otherwise returns false.
Definition: qdir.cpp:1560
virtual QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const
Returns the data for the given role and section in the header with the specified orientation.
bool isSpace() const
Returns true if the character is a separator character (Separator_* categories); otherwise returns fa...
Definition: qchar.cpp:609
void setNameFilters(const QStringList &nameFilters)
Sets the name filters used by entryList() and entryInfoList() to the list of filters specified by nam...
Definition: qdir.cpp:966
void changePersistentIndexList(const QModelIndexList &from, const QModelIndexList &to)
Changes the QPersistentModelIndexes that is equal to the indexes in the given from model index list t...
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
bool isLower() const
Returns true if the character is a lowercase letter, i.
Definition: qchar.h:272
iterator insert(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
Definition: qhash.h:753
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the vector...
Definition: qvector.h:250
#define Q_Q(Class)
Definition: qglobal.h:2483
QFileSystemNode * node(const QModelIndex &index) const
Return the QFileSystemNode that goes to index.
QDateTime lastModified(const QModelIndex &index) const
Returns the date and time when index was last modified.
virtual Qt::ItemFlags flags(const QModelIndex &index) const
Returns the item flags for the given index.
#define SIGNAL(a)
Definition: qobjectdefs.h:227
bool event(QEvent *event)
Reimplemented Function
QModelIndex mkdir(const QModelIndex &parent, const QString &name)
Create a directory with the name in the parent model index.
void sortChildren(int column, const QModelIndex &parent)
SortOrder
Definition: qnamespace.h:189
static QString toString(Register *reg, int type, bool *ok=0)
QFileSystemNode * addNode(QFileSystemNode *parentNode, const QString &fileName, const QFileInfo &info)
bool operator()(const QPair< QFileSystemModelPrivate::QFileSystemNode *, int > &l, const QPair< QFileSystemModelPrivate::QFileSystemNode *, int > &r) const
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
QString filePath(const QModelIndex &index) const
Returns the path of the item stored in the model under the index given.
bool rename(const QString &oldName, const QString &newName)
Renames a file or directory from oldName to newName, and returns true if successful; otherwise return...
Definition: qdir.cpp:1771
Qt::DropActions supportedDropActions() const
Reimplemented Function
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
static bool isEmpty(const char *str)
bool isDir() const
Returns true if this object points to a directory or to a symbolic link to a directory; otherwise ret...
Definition: qfileinfo.cpp:990
void layoutAboutToBeChanged()
This signal is emitted just before the layout of a model is changed.
void setIconProvider(QFileIconProvider *provider)
Sets the provider of file icons for the directory model.
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
void setNameFilters(const QStringList &filters)
Sets the name filters to apply against the existing files.
QString absolutePath() const
Returns the absolute path (a path that starts with "/" or with a drive specification), which may contain symbolic links, but never contains redundant ".", ".." or multiple separators.
Definition: qdir.cpp:619
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the list...
Definition: qlist.h:270
int row() const
Returns the row this model index refers to.
const char * name
QFileInfo fileInfo() const
void prepend(const T &t)
Inserts value at the beginning of the list.
Definition: qlist.h:541
bool operator()(const QString &, QString r) const
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
#define emit
Definition: qobjectdefs.h:76
const QAbstractItemModel * model() const
Returns a pointer to the model containing the item that this index refers to.
bool isNull() const
Returns true if the icon is empty; otherwise returns false.
Definition: qicon.cpp:769
bool isDir(const QModelIndex &index) const
Returns true if the model item index represents a directory; otherwise returns false.
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
QString canonicalFilePath() const
Returns the canonical path including the file name, i.e.
Definition: qfileinfo.cpp:551
void append(const T &t)
Inserts value at the end of the vector.
Definition: qvector.h:573
const T & value() const
Returns the current item&#39;s value.
Definition: qhash.h:420
Q_CORE_EXPORT void qWarning(const char *,...)
The QFileIconProvider class provides file icons for the QDirModel and the QFileSystemModel classes...
int timerId() const
Returns the unique timer identifier, which is the same identifier as returned from QObject::startTime...
Definition: qcoreevent.h:346
void setUrls(const QList< QUrl > &urls)
Sets the URLs stored in the MIME data object to those specified by urls.
Definition: qmimedata.cpp:334
~QFileSystemModel()
Destroys this file system model.
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
bool nameFilterDisables() const
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
Definition: qstring.h:654
QVariant myComputer(int role=Qt::DisplayRole) const
Returns the data stored under the given role for the item "My Computer".
QImage createAlphaMask(Qt::ImageConversionFlags flags=Qt::AutoColor) const
Builds and returns a 1-bpp mask from the alpha buffer in this image.
Definition: qimage.cpp:4720
QChar toUpper() const
Returns the uppercase equivalent if the character is lowercase or titlecase; otherwise returns the ch...
Definition: qchar.cpp:1287
void removeNode(QFileSystemNode *parentNode, const QString &name)
friend class iterator
Definition: qlist.h:226
QList< QUrl > urls() const
Returns a list of URLs contained within the MIME data object.
Definition: qmimedata.cpp:310
void setFilter(QDir::Filters filters)
Sets the directory model&#39;s filter to that specified by filters.
DropAction
Definition: qnamespace.h:1597
void clear()
Removes all items from the list.
Definition: qlist.h:764
void layoutChanged()
This signal is emitted whenever the layout of items exposed by the model has changed; for example...
__int64 qint64
Definition: qglobal.h:942
QModelIndex setRootPath(const QString &path)
Sets the directory that is being watched by the model to newPath by installing a file system watcher ...
quint16 values[128]
static QString cleanPath(const QString &path)
Removes all multiple directory separators "/" and resolves any "."s or ".."s found in the path...
Definition: qdir.cpp:2082
QFile::Permissions permissions(const QModelIndex &index) const
Returns the complete OR-ed together combination of QFile::Permission for the index.
QHash< const QFileSystemNode *, bool > bypassFilters
QFileInfo fileInfo(const QModelIndex &index) const
Returns the QFileInfo for the item stored in the model under the given index.
The QMimeData class provides a container for data that records information about its MIME type...
Definition: qmimedata.h:57
void _q_fileSystemChanged(const QString &path, const QList< QPair< QString, QFileInfo > > &)
The thread has received new information about files, update and emit dataChanged if it has actually c...
bool isValid() const
Returns true if this model index is valid; otherwise returns false.
void qSort(RandomAccessIterator start, RandomAccessIterator end)
Definition: qalgorithms.h:177
int count() const
Definition: qstring.h:103
int localeAwareCompare(const QString &s) const
Definition: qstring.cpp:5197
void setResolveSymlinks(bool enable)
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
void timerEvent(QTimerEvent *event)
Reimplemented Function
The QAbstractItemModel class provides the abstract interface for item model classes.
QString type(const QModelIndex &index) const
void qStableSort(RandomAccessIterator start, RandomAccessIterator end)
Definition: qalgorithms.h:202
T & first()
Returns a reference to the first item in the list.
Definition: qlist.h:282
void _q_directoryChanged(const QString &directory, const QStringList &list)
Performed quick listing and see if any files have been added or removed, then fetch more information ...
QString mid(int position, int n=-1) const Q_REQUIRED_RESULT
Returns a string that contains n characters of this string, starting at the specified position index...
Definition: qstring.cpp:3706
CaseSensitivity
Definition: qnamespace.h:1451
static const char *const filters[3]
QString arg(qlonglong a, int fieldwidth=0, int base=10, const QChar &fillChar=QLatin1Char(' ')) const Q_REQUIRED_RESULT
Definition: qstring.cpp:7186
QModelIndex index(const QString &path)
QString & append(QChar c)
Definition: qstring.cpp:1777
QString next()
Advances the iterator to the next entry, and returns the file path of this new entry.
int compare(const QString &s) const
Definition: qstring.cpp:5037
The QDateTime class provides date and time functions.
Definition: qdatetime.h:216
The QTimerEvent class contains parameters that describe a timer event.
Definition: qcoreevent.h:341
iterator begin()
Returns an STL-style iterator pointing to the first item in the vector.
Definition: qvector.h:247
QString size(const QModelIndex &index) const
The QPersistentModelIndex class is used to locate data in a data model.
QString time(const QModelIndex &index) const
QObject * parent() const
Returns a pointer to the parent object.
Definition: qobject.h:273
QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const
Reimplemented Function
static QTestResult::TestLocation location
Definition: qtestresult.cpp:63
QString toLower() const Q_REQUIRED_RESULT
Returns a lowercase copy of the string.
Definition: qstring.cpp:5389
bool rmdir(const QString &dirName) const
Removes the directory specified by dirName.
Definition: qdir.cpp:1448
The QModelIndex class is used to locate data in a data model.
Qt::ItemFlags flags(const QModelIndex &index) const
Reimplemented Function
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const
Reimplemented Function
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
QDir rootDirectory() const
The currently set directory.
static QChar getNextChar(const QString &s, int location)
static StandardButton information(QWidget *parent, const QString &title, const QString &text, StandardButtons buttons=Ok, StandardButton defaultButton=NoButton)
Opens an information message box with the given title and text in front of the specified parent widge...
Definition: qnamespace.h:54
QFactoryLoader * l
const QObjectList & children() const
Returns a list of child objects.
Definition: qobject.h:197
QMimeData * mimeData(const QModelIndexList &indexes) const
Returns an object that contains a serialized description of the specified indexes.
bool copy(const QString &newName)
Copies the file currently specified by fileName() to a file called newName.
Definition: qfile.cpp:926
static QString rootPath()
Returns the absolute path of the root directory.
Definition: qdir.cpp:2016
bool remove()
Removes the file specified by fileName().
Definition: qfile.cpp:715
#define Q_OS_WIN
Definition: qglobal.h:270
bool isSymLink(bool ignoreNtfsSymLinks=false) const
static QUrl fromLocalFile(const QString &localfile)
Returns a QUrl representation of localFile, interpreted as a local file.
Definition: qurl.cpp:6374
void setReadOnly(bool enable)
int rowCount(const QModelIndex &parent=QModelIndex()) const
Reimplemented Function
QDir::Filters filter() const
Returns the filter specified for the directory model.
QFileSystemModelVisibleFinder(QFileSystemModelPrivate::QFileSystemNode *node, QFileSystemModelSorter *sorter)
QStringList split(const QString &sep, SplitBehavior behavior=KeepEmptyParts, Qt::CaseSensitivity cs=Qt::CaseSensitive) const Q_REQUIRED_RESULT
Splits the string into substrings wherever sep occurs, and returns the list of those strings...
Definition: qstring.cpp:6526
static QString fromNativeSeparators(const QString &pathName)
Returns pathName using &#39;/&#39; as file separator.
Definition: qdir.cpp:848
QFileSystemModelSorter * sorter
QString path() const
Returns the path.
Definition: qdir.cpp:605
bool remove(const QModelIndex &index) const
Removes the model item index from the file system model and deletes the corresponding file from the f...
void setAlphaChannel(const QImage &alphaChannel)
Sets the alpha channel of this image to the given alphaChannel.
Definition: qimage.cpp:6329
iterator insertMulti(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
Definition: qhash.h:772
QStringList mimeTypes() const
Returns a list of MIME types that can be used to describe a list of items in the model.
QString rootPath() const
The currently set root path.
bool endsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string ends with s; otherwise returns false.
Definition: qstring.cpp:3796
The QFileInfo class provides system-independent file information.
Definition: qfileinfo.h:60
bool compareNodes(const QFileSystemModelPrivate::QFileSystemNode *l, const QFileSystemModelPrivate::QFileSystemNode *r) const
QString filePath() const
Returns the file name, including the path (which may be absolute or relative).
Definition: qfileinfo.cpp:707
static QString toNativeSeparators(const QString &pathName)
Returns pathName with the &#39;/&#39; separators converted to separators that are appropriate for the underly...
Definition: qdir.cpp:812
Orientation
Definition: qnamespace.h:174
The QEvent class is the base class of all event classes.
Definition: qcoreevent.h:56
Type type() const
Returns the event type.
Definition: qcoreevent.h:303
Q_CORE_EXPORT QTextStream & left(QTextStream &s)
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729
QChar toLower() const
Returns the lowercase equivalent if the character is uppercase or titlecase; otherwise returns the ch...
Definition: qchar.cpp:1239
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55
bool isDigit() const
Returns true if the character is a decimal digit (Number_DecimalDigit); otherwise returns false...
Definition: qchar.cpp:699
void setFilter(Filters filter)
Sets the filter used by entryList() and entryInfoList() to filters.
Definition: qdir.cpp:1170
void start(int msec, QObject *obj)
Starts (or restarts) the timer with a msec milliseconds timeout.
bool link(const QString &newName)
Creates a link named linkName that points to the file currently specified by fileName().
Definition: qfile.cpp:877
int size() const
int column() const
Returns the column this model index refers to.
The QList class is a template class that provides lists.
Definition: qdatastream.h:62
QFileInfoGatherer fileInfoGatherer
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const
Reimplemented Function
const_iterator constEnd() const
Returns a const STL-style iterator pointing to the imaginary item after the last item in the list...
Definition: qlist.h:272
const ushort * utf16() const
Returns the QString as a &#39;\0\&#39;-terminated array of unsigned shorts.
Definition: qstring.cpp:5290
void _q_resolvedName(const QString &fileName, const QString &resolvedName)
The QIcon class provides scalable icons in different modes and states.
Definition: qicon.h:60
void removeAt(int i)
Removes the item at index position i.
Definition: qlist.h:480