Qt 4.8
Classes | Public Functions | Static Public Functions | Public Variables | List of all members
QFileSystemModelPrivate Class Reference

#include <qfilesystemmodel_p.h>

Inheritance diagram for QFileSystemModelPrivate:
QAbstractItemModelPrivate QObjectPrivate QObjectData

Classes

struct  Fetching
 
class  QFileSystemNode
 

Public Functions

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 on visible files. More...
 
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 changed. More...
 
void _q_performDelayedSort ()
 
void _q_resolvedName (const QString &fileName, const QString &resolvedName)
 
QFileSystemNodeaddNode (QFileSystemNode *parentNode, const QString &fileName, const QFileInfo &info)
 
void addVisibleFiles (QFileSystemNode *parentNode, const QStringList &newFiles)
 
void delayedSort ()
 
QString displayName (const QModelIndex &index) const
 
QString filePath (const QModelIndex &index) const
 
bool filtersAcceptsNode (const QFileSystemNode *node) const
 
QIcon icon (const QModelIndex &index) const
 
QModelIndex index (const QString &path)
 
QModelIndex index (const QFileSystemNode *node) const
 
void init ()
 
bool isHiddenByFilter (QFileSystemNode *indexNode, const QModelIndex &index) const
 
QString name (const QModelIndex &index) const
 
QFileSystemNodenode (const QModelIndex &index) const
 Return the QFileSystemNode that goes to index. More...
 
QFileSystemNodenode (const QString &path, bool fetch=true) const
 
bool passNameFilters (const QFileSystemNode *node) const
 
 QFileSystemModelPrivate ()
 
void removeNode (QFileSystemNode *parentNode, const QString &name)
 
void removeVisibleFile (QFileSystemNode *parentNode, int visibleLocation)
 
QString size (const QModelIndex &index) const
 
void sortChildren (int column, const QModelIndex &parent)
 
QString time (const QModelIndex &index) const
 
int translateVisibleLocation (QFileSystemNode *parent, int row) const
 
QString type (const QModelIndex &index) const
 
- Public Functions inherited from QAbstractItemModelPrivate
bool allowMove (const QModelIndex &srcParent, int srcFirst, int srcLast, const QModelIndex &destinationParent, int destinationChild, Qt::Orientation orientation)
 Returns whether a move operation is valid. More...
 
void columnsAboutToBeInserted (const QModelIndex &parent, int first, int last)
 
void columnsAboutToBeRemoved (const QModelIndex &parent, int first, int last)
 
void columnsInserted (const QModelIndex &parent, int first, int last)
 
void columnsRemoved (const QModelIndex &parent, int first, int last)
 
QModelIndex createIndex (int row, int column, void *data=0) const
 
QModelIndex createIndex (int row, int column, int id) const
 
bool indexValid (const QModelIndex &index) const
 
void invalidatePersistentIndex (const QModelIndex &index)
 
void invalidatePersistentIndexes ()
 
void itemsAboutToBeMoved (const QModelIndex &srcParent, int srcFirst, int srcLast, const QModelIndex &destinationParent, int destinationChild, Qt::Orientation)
 
void itemsMoved (const QModelIndex &srcParent, int srcFirst, int srcLast, const QModelIndex &destinationParent, int destinationChild, Qt::Orientation orientation)
 
void movePersistentIndexes (QVector< QPersistentModelIndexData *> indexes, int change, const QModelIndex &parent, Qt::Orientation orientation)
 Moves persistent indexes indexes by amount change. More...
 
 QAbstractItemModelPrivate ()
 
void removePersistentIndexData (QPersistentModelIndexData *data)
 
void rowsAboutToBeInserted (const QModelIndex &parent, int first, int last)
 
void rowsAboutToBeRemoved (const QModelIndex &parent, int first, int last)
 
void rowsInserted (const QModelIndex &parent, int first, int last)
 
void rowsRemoved (const QModelIndex &parent, int first, int last)
 
- Public Functions inherited from QObjectPrivate
void _q_reregisterTimers (void *pointer)
 
void addConnection (int signal, Connection *c)
 
void cleanConnectionLists ()
 
void connectNotify (const char *signal)
 
void deleteChildren ()
 
void disconnectNotify (const char *signal)
 
bool isSender (const QObject *receiver, const char *signal) const
 
bool isSignalConnected (uint signalIdx) const
 Returns true if the signal with index signal_index from object sender is connected. More...
 
void moveToThread_helper ()
 
 QObjectPrivate (int version=QObjectPrivateVersion)
 
QObjectList receiverList (const char *signal) const
 
QObjectList senderList () const
 
void setParent_helper (QObject *)
 
void setThreadData_helper (QThreadData *currentData, QThreadData *targetData)
 
int signalIndex (const char *signalName) const
 Returns the signal index used in the internal connectionLists vector. More...
 
virtual ~QObjectPrivate ()
 
- Public Functions inherited from QObjectData
virtual ~QObjectData ()=0
 

Static Public Functions

static bool caseInsensitiveLessThan (const QString &s1, const QString &s2)
 
static QString myComputer ()
 
static int naturalCompare (const QString &s1, const QString &s2, Qt::CaseSensitivity cs)
 Natural number sort, skips spaces. More...
 
static bool nodeCaseInsensitiveLessThan (const QFileSystemModelPrivate::QFileSystemNode &s1, const QFileSystemModelPrivate::QFileSystemNode &s2)
 
static QString size (qint64 bytes)
 
- Static Public Functions inherited from QAbstractItemModelPrivate
static const QHash< int, QByteArray > & defaultRoleNames ()
 
static QAbstractItemModelstaticEmptyModel ()
 
static bool variantLessThan (const QVariant &v1, const QVariant &v2)
 This function is used by our Q{Tree,Widget,Table}WidgetModel classes to sort. More...
 
- Static Public Functions inherited from QObjectPrivate
static void clearGuards (QObject *)
 
static QObjectPrivateget (QObject *o)
 
static void resetCurrentSender (QObject *receiver, Sender *currentSender, Sender *previousSender)
 
static SendersetCurrentSender (QObject *receiver, Sender *sender)
 
static void signalSignature (const QMetaMethod &signal, QVarLengthArray< char > *result)
 

Public Variables

QHash< const QFileSystemNode *, bool > bypassFilters
 
QTimer delayedSortTimer
 
bool disableRecursiveSort
 
QBasicTimer fetchingTimer
 
QFileInfoGatherer fileInfoGatherer
 
QDir::Filters filters
 
bool forceSort
 
bool nameFilterDisables
 
QList< QRegExpnameFilters
 
bool readOnly
 
QHash< QString, QStringresolvedSymLinks
 
QFileSystemNode root
 
QDir rootDir
 
bool setRootPath
 
int sortColumn
 
Qt::SortOrder sortOrder
 
QList< FetchingtoFetch
 
- Public Variables inherited from QAbstractItemModelPrivate
QStack< Changechanges
 
struct QAbstractItemModelPrivate::Persistent persistent
 
QHash< int, QByteArrayroleNames
 
Qt::DropActions supportedDragActions
 
- Public Variables inherited from QObjectPrivate
union {
   QObject *   currentChildBeingDeleted
 
   QAbstractDeclarativeData *   declarativeData
 
}; 
 
quint32 connectedSignals [2]
 
QObjectConnectionListVectorconnectionLists
 
SendercurrentSender
 
QList< QPointer< QObject > > eventFilters
 
ExtraDataextraData
 
QString objectName
 
Connectionsenders
 
QAtomicPointer< QtSharedPointer::ExternalRefCountData > sharedRefcount
 
QThreadDatathreadData
 
void * unused
 
- Public Variables inherited from QObjectData
uint blockSig: 1
 
QObjectList children
 
uint hasGuards: 1
 
uint inEventHandler: 1
 
uint inThreadChangeEvent: 1
 
uint isWidget: 1
 
QMetaObjectmetaObject
 
uint ownObjectName: 1
 
QObjectparent
 
uint pendTimer: 1
 
int postedEvents
 
QObjectq_ptr
 
uint receiveChildEvents: 1
 
uint sendChildEvents: 1
 
uint unused: 22
 
uint wasDeleted: 1
 

Additional Inherited Members

- Public Types inherited from QObjectPrivate
typedef void(* StaticMetaCallFunction) (QObject *, QMetaObject::Call, int, void **)
 

Detailed Description

Definition at line 78 of file qfilesystemmodel_p.h.

Constructors and Destructors

◆ QFileSystemModelPrivate()

QFileSystemModelPrivate::QFileSystemModelPrivate ( )
inline

Definition at line 208 of file qfilesystemmodel_p.h.

Functions

◆ _q_directoryChanged()

void QFileSystemModelPrivate::_q_directoryChanged ( const QString directory,
const QStringList files 
)

Performed quick listing and see if any files have been added or removed, then fetch more information on visible files.

Warning
This function is not part of the public interface.

Definition at line 1697 of file qfilesystemmodel.cpp.

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 }
QHash< QString, QFileSystemNode * > children
The QHash::const_iterator class provides an STL-style const iterator for QHash and QMultiHash...
Definition: qhash.h:395
iterator begin()
Returns an STL-style iterator pointing to the first item in the list.
Definition: qlist.h:267
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
QFileSystemNode * node(const QModelIndex &index) const
Return the QFileSystemNode that goes to index.
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the list...
Definition: qlist.h:270
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
void removeNode(QFileSystemNode *parentNode, const QString &name)
friend class iterator
Definition: qlist.h:226
void qSort(RandomAccessIterator start, RandomAccessIterator end)
Definition: qalgorithms.h:177
QString toLower() const Q_REQUIRED_RESULT
Returns a lowercase copy of the string.
Definition: qstring.cpp:5389
int size() const
Returns the number of items in the list.
Definition: qlist.h:137

◆ _q_fileSystemChanged()

void QFileSystemModelPrivate::_q_fileSystemChanged ( const QString path,
const QList< QPair< QString, QFileInfo > > &  updates 
)

The thread has received new information about files, update and emit dataChanged if it has actually changed.

Warning
This function is not part of the public interface.

Definition at line 1868 of file qfilesystemmodel.cpp.

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 }
QHash< QString, QFileSystemNode * > children
The QFileSystemModel class provides a data model for the local filesystem.
static mach_timebase_info_data_t info
int count(const T &t) const
Returns the number of occurrences of value in the vector.
Definition: qvector.h:742
bool filtersAcceptsNode(const QFileSystemNode *node) const
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
The QString class provides a Unicode character string.
Definition: qstring.h:83
void removeVisibleFile(QFileSystemNode *parentNode, int visibleLocation)
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
void addVisibleFiles(QFileSystemNode *parentNode, const QStringList &newFiles)
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.
QFileSystemNode * addNode(QFileSystemNode *parentNode, const QString &fileName, const QFileInfo &info)
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
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
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
void append(const T &t)
Inserts value at the end of the vector.
Definition: qvector.h:573
QExtendedInformation getInfo(const QFileInfo &info) const
void removeNode(QFileSystemNode *parentNode, const QString &name)
QHash< const QFileSystemNode *, bool > bypassFilters
void qSort(RandomAccessIterator start, RandomAccessIterator end)
Definition: qalgorithms.h:177
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
QModelIndex index(const QString &path)
int compare(const QString &s) const
Definition: qstring.cpp:5037
iterator begin()
Returns an STL-style iterator pointing to the first item in the vector.
Definition: qvector.h:247
The QModelIndex class is used to locate data in a data model.
int translateVisibleLocation(QFileSystemNode *parent, int row) const
static QString fileName(const QString &fileUrl)
QFileInfoGatherer fileInfoGatherer

◆ _q_performDelayedSort()

void QFileSystemModelPrivate::_q_performDelayedSort ( )
Warning
This function is not part of the public interface.

Definition at line 1011 of file qfilesystemmodel.cpp.

1012 {
1014  q->sort(sortColumn, sortOrder);
1015 }
The QFileSystemModel class provides a data model for the local filesystem.
#define Q_Q(Class)
Definition: qglobal.h:2483

◆ _q_resolvedName()

void QFileSystemModelPrivate::_q_resolvedName ( const QString fileName,
const QString resolvedName 
)
Warning
This function is not part of the public interface.

Definition at line 1971 of file qfilesystemmodel.cpp.

1972 {
1973  resolvedSymLinks[fileName] = resolvedName;
1974 }
QHash< QString, QString > resolvedSymLinks
static QString fileName(const QString &fileUrl)

◆ addNode()

QFileSystemModelPrivate::QFileSystemNode * QFileSystemModelPrivate::addNode ( QFileSystemNode parentNode,
const QString fileName,
const QFileInfo info 
)
Warning
This function is not part of the public interface.

Adds a new file to the children of parentNode

WARNING* this will change the count of children

Definition at line 1738 of file qfilesystemmodel.cpp.

Referenced by node().

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 }
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
void populate(const QExtendedInformation &fileInfo)
QString name(const QModelIndex &index) const
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QString class provides a Unicode character string.
Definition: qstring.h:83
QFileSystemNode * node(const QModelIndex &index) const
Return the QFileSystemNode that goes to index.
const ushort * utf16() const
Returns the QString as a &#39;\0\&#39;-terminated array of unsigned shorts.
Definition: qstring.cpp:5290

◆ addVisibleFiles()

void QFileSystemModelPrivate::addVisibleFiles ( QFileSystemNode parentNode,
const QStringList newFiles 
)
Warning
This function is not part of the public interface.

File at parentNode->children(itemLocation) was not visible before, but now should be and emit signals if necessary.

WARNING* this will change the visible count

Definition at line 1816 of file qfilesystemmodel.cpp.

Referenced by node().

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 }
The QFileSystemModel class provides a data model for the local filesystem.
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
#define Q_Q(Class)
Definition: qglobal.h:2483
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
QModelIndex index(const QString &path)
The QModelIndex class is used to locate data in a data model.
QObject * parent
Definition: qobject.h:92
bool isHiddenByFilter(QFileSystemNode *indexNode, const QModelIndex &index) const

◆ caseInsensitiveLessThan()

static bool QFileSystemModelPrivate::caseInsensitiveLessThan ( const QString s1,
const QString s2 
)
inlinestatic

Definition at line 272 of file qfilesystemmodel_p.h.

273  {
274  return QString::compare(s1, s2, Qt::CaseInsensitive) < 0;
275  }
int compare(const QString &s) const
Definition: qstring.cpp:5037

◆ delayedSort()

void QFileSystemModelPrivate::delayedSort ( )
inline

Definition at line 267 of file qfilesystemmodel_p.h.

267  {
268  if (!delayedSortTimer.isActive())
270  }
bool isActive() const
Returns true if the timer is running (pending); otherwise returns false.
Definition: qtimer.h:69
void start(int msec)
Starts or restarts the timer with a timeout interval of msec milliseconds.
Definition: qtimer.cpp:249

◆ displayName()

QString QFileSystemModelPrivate::displayName ( const QModelIndex index) const
Warning
This function is not part of the public interface.

Definition at line 851 of file qfilesystemmodel.cpp.

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 }
QString name(const QModelIndex &index) const
QFileSystemNode * node(const QModelIndex &index) const
Return the QFileSystemNode that goes to index.
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
Definition: qstring.h:654
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55

◆ filePath()

QString QFileSystemModelPrivate::filePath ( const QModelIndex index) const

Definition at line 1329 of file qfilesystemmodel.cpp.

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()) {
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 }
The QFileSystemModel class provides a data model for the local filesystem.
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
The QString class provides a Unicode character string.
Definition: qstring.h:83
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
static QChar separator()
Returns the native directory separator: "/" under Unix (including Mac OS X) and "\\" under Windows...
Definition: qdir.cpp:1831
QModelIndex parent() const
Returns the parent of the model index, or QModelIndex() if it has no parent.
#define Q_Q(Class)
Definition: qglobal.h:2483
QFileSystemNode * node(const QModelIndex &index) const
Return the QFileSystemNode that goes to index.
const QAbstractItemModel * model() const
Returns a pointer to the model containing the item that this index refers to.
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
bool isValid() const
Returns true if this model index is valid; otherwise returns false.
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
QModelIndex index(const QString &path)
QString & append(QChar c)
Definition: qstring.cpp:1777
The QModelIndex class is used to locate data in a data model.
static QString fromNativeSeparators(const QString &pathName)
Returns pathName using &#39;/&#39; as file separator.
Definition: qdir.cpp:848
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
#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
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55

◆ filtersAcceptsNode()

bool QFileSystemModelPrivate::filtersAcceptsNode ( const QFileSystemNode node) const
Warning
This function is not part of the public interface.

Returns false if node doesn't pass the filters otherwise true

QDir::Modified is not supported QDir::Drives is not supported

Definition at line 2009 of file qfilesystemmodel.cpp.

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 
2049 }
bool passNameFilters(const QFileSystemNode *node) const
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
QFileSystemNode * node(const QModelIndex &index) const
Return the QFileSystemNode that goes to index.
QHash< const QFileSystemNode *, bool > bypassFilters
bool isSymLink(bool ignoreNtfsSymLinks=false) const

◆ icon()

QIcon QFileSystemModelPrivate::icon ( const QModelIndex index) const
Warning
This function is not part of the public interface.

Definition at line 864 of file qfilesystemmodel.cpp.

865 {
866  if (!index.isValid())
867  return QIcon();
868  return node(index)->icon();
869 }
QFileSystemNode * node(const QModelIndex &index) const
Return the QFileSystemNode that goes to index.
bool isValid() const
Returns true if this model index is valid; otherwise returns false.
The QIcon class provides scalable icons in different modes and states.
Definition: qicon.h:60

◆ index() [1/2]

QModelIndex QFileSystemModelPrivate::index ( const QString path)
inline

Definition at line 233 of file qfilesystemmodel_p.h.

Referenced by index().

233 { return index(node(path)); }
QFileSystemNode * node(const QModelIndex &index) const
Return the QFileSystemNode that goes to index.
QModelIndex index(const QString &path)

◆ index() [2/2]

QModelIndex QFileSystemModelPrivate::index ( const QFileSystemNode node) const

Definition at line 616 of file qfilesystemmodel.cpp.

617 {
618  Q_Q(const QFileSystemModel);
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 }
The QFileSystemModel class provides a data model for the local filesystem.
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
#define Q_Q(Class)
Definition: qglobal.h:2483
QFileSystemNode * node(const QModelIndex &index) const
Return the QFileSystemNode that goes to index.
The QModelIndex class is used to locate data in a data model.
int translateVisibleLocation(QFileSystemNode *parent, int row) const

◆ init()

void QFileSystemModelPrivate::init ( )
Warning
This function is not part of the public interface.

Definition at line 1979 of file qfilesystemmodel.cpp.

1980 {
1982  qRegisterMetaType<QList<QPair<QString,QFileInfo> > >("QList<QPair<QString,QFileInfo> >");
1983  q->connect(&fileInfoGatherer, SIGNAL(newListOfFiles(QString,QStringList)),
1987  q->connect(&fileInfoGatherer, SIGNAL(nameResolved(QString,QString)),
1989  q->connect(&fileInfoGatherer, SIGNAL(directoryLoaded(QString)),
1990  q, 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 }
The QFileSystemModel class provides a data model for the local filesystem.
#define SLOT(a)
Definition: qobjectdefs.h:226
The QString class provides a Unicode character string.
Definition: qstring.h:83
iterator insert(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
Definition: qhash.h:753
#define Q_Q(Class)
Definition: qglobal.h:2483
#define SIGNAL(a)
Definition: qobjectdefs.h:227
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
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...
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 ...
iterator insertMulti(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
Definition: qhash.h:772
The QList class is a template class that provides lists.
Definition: qdatastream.h:62
QFileInfoGatherer fileInfoGatherer
void _q_resolvedName(const QString &fileName, const QString &resolvedName)

◆ isHiddenByFilter()

bool QFileSystemModelPrivate::isHiddenByFilter ( QFileSystemNode indexNode,
const QModelIndex index 
) const
inline

Definition at line 227 of file qfilesystemmodel_p.h.

228  {
229  return (indexNode != &root && !index.isValid());
230  }
bool isValid() const
Returns true if this model index is valid; otherwise returns false.

◆ myComputer()

static QString QFileSystemModelPrivate::myComputer ( )
inlinestatic

Definition at line 255 of file qfilesystemmodel_p.h.

255  {
256  // ### TODO We should query the system to find out what the string should be
257  // XP == "My Computer",
258  // Vista == "Computer",
259  // OS X == "Computer" (sometime user generated) "Benjamin's PowerBook G4"
260 #ifdef Q_OS_WIN
261  return QFileSystemModel::tr("My Computer");
262 #else
263  return QFileSystemModel::tr("Computer");
264 #endif
265  }
static QString tr(const char *sourceText, const char *comment=0, int n=-1)

◆ name()

QString QFileSystemModelPrivate::name ( const QModelIndex index) const
Warning
This function is not part of the public interface.

Definition at line 834 of file qfilesystemmodel.cpp.

835 {
836  if (!index.isValid())
837  return QString();
838  QFileSystemNode *dirNode = node(index);
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 }
QString filePath(const QModelIndex &index) const
The QString class provides a Unicode character string.
Definition: qstring.h:83
bool contains(const Key &key) const
Returns true if the hash contains an item with the key; otherwise returns false.
Definition: qhash.h:872
QFileSystemNode * node(const QModelIndex &index) const
Return the QFileSystemNode that goes to index.
bool isEmpty() const
Returns true if the hash contains no items; otherwise returns false.
Definition: qhash.h:297
bool isValid() const
Returns true if this model index is valid; otherwise returns false.
bool resolveSymlinks() const
QHash< QString, QString > resolvedSymLinks
static QString fromNativeSeparators(const QString &pathName)
Returns pathName using &#39;/&#39; as file separator.
Definition: qdir.cpp:848
QFileInfoGatherer fileInfoGatherer

◆ naturalCompare()

int QFileSystemModelPrivate::naturalCompare ( const QString s1,
const QString s2,
Qt::CaseSensitivity  cs 
)
static

Natural number sort, skips spaces.

Examples: 1, 2, 10, 55, 100 01.jpg, 2.jpg, 10.jpg

Note on the algorithm: Only as many characters as necessary are looked at and at most they all are looked at once.

Slower then QString::compare() (of course)

Definition at line 1035 of file qfilesystemmodel.cpp.

Referenced by QFileSystemModelSorter::compareNodes().

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 }
int digitValue() const
Returns the numeric value of the digit, or -1 if the character is not a digit.
Definition: qchar.cpp:817
bool isNull() const
Returns true if the character is the Unicode character 0x0000 (&#39;\0&#39;); otherwise returns false...
Definition: qchar.h:262
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
The QChar class provides a 16-bit Unicode character.
Definition: qchar.h:72
bool isSpace() const
Returns true if the character is a separator character (Separator_* categories); otherwise returns fa...
Definition: qchar.cpp:609
bool isLower() const
Returns true if the character is a lowercase letter, i.
Definition: qchar.h:272
int count() const
Definition: qstring.h:103
int localeAwareCompare(const QString &s) const
Definition: qstring.cpp:5197
int compare(const QString &s) const
Definition: qstring.cpp:5037
static QChar getNextChar(const QString &s, int location)
QChar toLower() const
Returns the lowercase equivalent if the character is uppercase or titlecase; otherwise returns the ch...
Definition: qchar.cpp:1239
bool isDigit() const
Returns true if the character is a decimal digit (Number_DecimalDigit); otherwise returns false...
Definition: qchar.cpp:699

◆ node() [1/2]

QFileSystemModelPrivate::QFileSystemNode * QFileSystemModelPrivate::node ( const QModelIndex index) const

Return the QFileSystemNode that goes to index.

Warning
This function is not part of the public interface.

Definition at line 331 of file qfilesystemmodel.cpp.

332 {
333  if (!index.isValid())
334  return const_cast<QFileSystemNode*>(&root);
336  Q_ASSERT(indexNode);
337  return indexNode;
338 }
void * internalPointer() const
Returns a void * pointer used by the model to associate the index with the internal data structure...
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
bool isValid() const
Returns true if this model index is valid; otherwise returns false.

◆ node() [2/2]

QFileSystemModelPrivate::QFileSystemNode * QFileSystemModelPrivate::node ( const QString path,
bool  fetch = true 
) const
Warning
This function is not part of the public interface.

Given a path return the matching QFileSystemNode or &root if invalid

Definition at line 380 of file qfilesystemmodel.cpp.

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
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 }
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
QHash< QString, QFileSystemNode * > children
The QFileSystemModel class provides a data model for the local filesystem.
static mach_timebase_info_data_t info
void chop(int n)
Removes n characters from the end of the string.
Definition: qstring.cpp:4623
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
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
void pop_front()
This function is provided for STL compatibility.
Definition: qlist.h:302
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
The QString class provides a Unicode character string.
Definition: qstring.h:83
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
void addVisibleFiles(QFileSystemNode *parentNode, const QStringList &newFiles)
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
#define Q_Q(Class)
Definition: qglobal.h:2483
QFileSystemNode * node(const QModelIndex &index) const
Return the QFileSystemNode that goes to index.
QFileSystemNode * addNode(QFileSystemNode *parentNode, const QString &fileName, const QFileInfo &info)
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
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
void prepend(const T &t)
Inserts value at the beginning of the list.
Definition: qlist.h:541
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
QExtendedInformation getInfo(const QFileInfo &info) const
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
Definition: qstring.h:654
QHash< const QFileSystemNode *, bool > bypassFilters
T & first()
Returns a reference to the first item in the list.
Definition: qlist.h:282
QModelIndex index(const QString &path)
QString & append(QChar c)
Definition: qstring.cpp:1777
QString toLower() const Q_REQUIRED_RESULT
Returns a lowercase copy of the string.
Definition: qstring.cpp:5389
The QModelIndex class is used to locate data in a data model.
static QString rootPath()
Returns the absolute path of the root directory.
Definition: qdir.cpp:2016
QObject * parent
Definition: qobject.h:92
#define Q_OS_WIN
Definition: qglobal.h:270
int translateVisibleLocation(QFileSystemNode *parent, int row) const
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
QString path() const
Returns the path.
Definition: qdir.cpp:605
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
#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
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55
void start(int msec, QObject *obj)
Starts (or restarts) the timer with a msec milliseconds timeout.
QFileInfoGatherer fileInfoGatherer

◆ nodeCaseInsensitiveLessThan()

static bool QFileSystemModelPrivate::nodeCaseInsensitiveLessThan ( const QFileSystemModelPrivate::QFileSystemNode s1,
const QFileSystemModelPrivate::QFileSystemNode s2 
)
inlinestatic

Definition at line 277 of file qfilesystemmodel_p.h.

278  {
280  }
int compare(const QString &s) const
Definition: qstring.cpp:5037

◆ passNameFilters()

bool QFileSystemModelPrivate::passNameFilters ( const QFileSystemNode node) const

Definition at line 2056 of file qfilesystemmodel.cpp.

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) {
2066  return true;
2067  }
2068  return false;
2069  }
2070 #endif
2071  return true;
2072 }
QList< QRegExp > nameFilters
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
QFileSystemNode * node(const QModelIndex &index) const
Return the QFileSystemNode that goes to index.
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
bool exactMatch(const QString &str) const
Returns true if str is matched exactly by this regular expression; otherwise returns false...
Definition: qregexp.cpp:4094

◆ removeNode()

void QFileSystemModelPrivate::removeNode ( QFileSystemModelPrivate::QFileSystemNode parentNode,
const QString name 
)
Warning
This function is not part of the public interface.

File at parentNode->children(itemLocation) has been removed, remove from the lists and emit signals if necessary

WARNING* this will change the count of children and could change visibleChildren

Definition at line 1769 of file qfilesystemmodel.cpp.

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 }
QHash< QString, QFileSystemNode * > children
The QFileSystemModel class provides a data model for the local filesystem.
#define Q_Q(Class)
Definition: qglobal.h:2483
QFileSystemNode * node(const QModelIndex &index) const
Return the QFileSystemNode that goes to index.
QModelIndex index(const QString &path)
The QModelIndex class is used to locate data in a data model.
QObject * parent
Definition: qobject.h:92
int translateVisibleLocation(QFileSystemNode *parent, int row) const
bool isHiddenByFilter(QFileSystemNode *indexNode, const QModelIndex &index) const
void removeAt(int i)
Removes the item at index position i.
Definition: qlist.h:480

◆ removeVisibleFile()

void QFileSystemModelPrivate::removeVisibleFile ( QFileSystemNode parentNode,
int  vLocation 
)
Warning
This function is not part of the public interface.

File was visible before, but now should NOT be

WARNING* this will change the visible count

Definition at line 1843 of file qfilesystemmodel.cpp.

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 }
The QFileSystemModel class provides a data model for the local filesystem.
#define Q_Q(Class)
Definition: qglobal.h:2483
QModelIndex index(const QString &path)
The QModelIndex class is used to locate data in a data model.
QObject * parent
Definition: qobject.h:92
int translateVisibleLocation(QFileSystemNode *parent, int row) const
bool isHiddenByFilter(QFileSystemNode *indexNode, const QModelIndex &index) const

◆ size() [1/2]

QString QFileSystemModelPrivate::size ( const QModelIndex index) const
Warning
This function is not part of the public interface.

Definition at line 768 of file qfilesystemmodel.cpp.

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 }
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QString class provides a Unicode character string.
Definition: qstring.h:83
QFileSystemNode * node(const QModelIndex &index) const
Return the QFileSystemNode that goes to index.
bool isValid() const
Returns true if this model index is valid; otherwise returns false.
QString size(const QModelIndex &index) const

◆ size() [2/2]

QString QFileSystemModelPrivate::size ( qint64  bytes)
static

Definition at line 787 of file qfilesystemmodel.cpp.

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 }
double qreal
Definition: qglobal.h:1193
static QString tr(const char *sourceText, const char *comment=0, int n=-1)
static QString toString(Register *reg, int type, bool *ok=0)
__int64 qint64
Definition: qglobal.h:942
QString arg(qlonglong a, int fieldwidth=0, int base=10, const QChar &fillChar=QLatin1Char(' ')) const Q_REQUIRED_RESULT
Definition: qstring.cpp:7186

◆ sortChildren()

void QFileSystemModelPrivate::sortChildren ( int  column,
const QModelIndex parent 
)

Definition at line 1150 of file qfilesystemmodel.cpp.

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 }
QHash< QString, QFileSystemNode * > children
The QHash::const_iterator class provides an STL-style const iterator for QHash and QMultiHash...
Definition: qhash.h:395
The QFileSystemModel class provides a data model for the local filesystem.
bool filtersAcceptsNode(const QFileSystemNode *node) const
iterator begin()
Returns an STL-style iterator pointing to the first item in the list.
Definition: qlist.h:267
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
#define Q_Q(Class)
Definition: qglobal.h:2483
QFileSystemNode * node(const QModelIndex &index) const
Return the QFileSystemNode that goes to index.
void sortChildren(int column, const QModelIndex &parent)
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the list...
Definition: qlist.h:270
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
const T & value() const
Returns the current item&#39;s value.
Definition: qhash.h:420
void clear()
Removes all items from the list.
Definition: qlist.h:764
quint16 values[128]
void qStableSort(RandomAccessIterator start, RandomAccessIterator end)
Definition: qalgorithms.h:202
The QModelIndex class is used to locate data in a data model.
The QList class is a template class that provides lists.
Definition: qdatastream.h:62

◆ time()

QString QFileSystemModelPrivate::time ( const QModelIndex index) const
Warning
This function is not part of the public interface.

Definition at line 809 of file qfilesystemmodel.cpp.

810 {
811  if (!index.isValid())
812  return QString();
813 #ifndef QT_NO_DATESTRING
815 #else
816  Q_UNUSED(index);
817  return QString();
818 #endif
819 }
The QString class provides a Unicode character string.
Definition: qstring.h:83
QString toString(Qt::DateFormat f=Qt::TextDate) const
Returns the datetime as a string in the format given.
Definition: qdatetime.cpp:2628
QFileSystemNode * node(const QModelIndex &index) const
Return the QFileSystemNode that goes to index.
bool isValid() const
Returns true if this model index is valid; otherwise returns false.
#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

◆ translateVisibleLocation()

int QFileSystemModelPrivate::translateVisibleLocation ( QFileSystemNode parent,
int  row 
) const
inline

Definition at line 243 of file qfilesystemmodel_p.h.

243  {
244  if (sortOrder != Qt::AscendingOrder) {
245  if (parent->dirtyChildrenIndex == -1)
246  return parent->visibleChildren.count() - row - 1;
247 
248  if (row < parent->dirtyChildrenIndex)
249  return parent->dirtyChildrenIndex - row - 1;
250  }
251 
252  return row;
253  }
QObject * parent
Definition: qobject.h:92

◆ type()

QString QFileSystemModelPrivate::type ( const QModelIndex index) const

Definition at line 824 of file qfilesystemmodel.cpp.

825 {
826  if (!index.isValid())
827  return QString();
828  return node(index)->type();
829 }
The QString class provides a Unicode character string.
Definition: qstring.h:83
QFileSystemNode * node(const QModelIndex &index) const
Return the QFileSystemNode that goes to index.
bool isValid() const
Returns true if this model index is valid; otherwise returns false.

Properties

◆ bypassFilters

QHash<const QFileSystemNode*, bool> QFileSystemModelPrivate::bypassFilters

Definition at line 309 of file qfilesystemmodel_p.h.

Referenced by node().

◆ delayedSortTimer

QTimer QFileSystemModelPrivate::delayedSortTimer

Definition at line 302 of file qfilesystemmodel_p.h.

◆ disableRecursiveSort

bool QFileSystemModelPrivate::disableRecursiveSort

Definition at line 314 of file qfilesystemmodel_p.h.

◆ fetchingTimer

QBasicTimer QFileSystemModelPrivate::fetchingTimer

Definition at line 323 of file qfilesystemmodel_p.h.

Referenced by node().

◆ fileInfoGatherer

QFileInfoGatherer QFileSystemModelPrivate::fileInfoGatherer

Definition at line 300 of file qfilesystemmodel_p.h.

Referenced by QFileSystemModel::remove(), and QFileSystemModel::rmdir().

◆ filters

QDir::Filters QFileSystemModelPrivate::filters

Definition at line 308 of file qfilesystemmodel_p.h.

◆ forceSort

bool QFileSystemModelPrivate::forceSort

Definition at line 303 of file qfilesystemmodel_p.h.

◆ nameFilterDisables

bool QFileSystemModelPrivate::nameFilterDisables

Definition at line 310 of file qfilesystemmodel_p.h.

◆ nameFilters

QList<QRegExp> QFileSystemModelPrivate::nameFilters

Definition at line 316 of file qfilesystemmodel_p.h.

◆ readOnly

bool QFileSystemModelPrivate::readOnly

Definition at line 306 of file qfilesystemmodel_p.h.

◆ resolvedSymLinks

QHash<QString, QString> QFileSystemModelPrivate::resolvedSymLinks

Definition at line 319 of file qfilesystemmodel_p.h.

◆ root

QFileSystemNode QFileSystemModelPrivate::root

Definition at line 321 of file qfilesystemmodel_p.h.

◆ rootDir

QDir QFileSystemModelPrivate::rootDir

Definition at line 298 of file qfilesystemmodel_p.h.

◆ setRootPath

bool QFileSystemModelPrivate::setRootPath

Definition at line 307 of file qfilesystemmodel_p.h.

◆ sortColumn

int QFileSystemModelPrivate::sortColumn

Definition at line 304 of file qfilesystemmodel_p.h.

◆ sortOrder

Qt::SortOrder QFileSystemModelPrivate::sortOrder

Definition at line 305 of file qfilesystemmodel_p.h.

◆ toFetch

QList<Fetching> QFileSystemModelPrivate::toFetch

Definition at line 329 of file qfilesystemmodel_p.h.

Referenced by node().


The documentation for this class was generated from the following files: