Qt 4.8
Public Types | Signals | Public Functions | Protected Functions | Properties | Friends | List of all members
QFileSystemModel Class Reference

The QFileSystemModel class provides a data model for the local filesystem. More...

#include <qfilesystemmodel.h>

Inheritance diagram for QFileSystemModel:
QAbstractItemModel QObject

Public Types

enum  Roles { FileIconRole = Qt::DecorationRole, FilePathRole = Qt::UserRole + 1, FileNameRole = Qt::UserRole + 2, FilePermissions = Qt::UserRole + 3 }
 

Signals

void directoryLoaded (const QString &path)
 This signal is emitted when the gatherer thread has finished to load the path. More...
 
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. More...
 
void rootPathChanged (const QString &newPath)
 This signal is emitted whenever the root path has been changed to a newPath. More...
 
- Signals inherited from QAbstractItemModel
void columnsAboutToBeInserted (const QModelIndex &parent, int first, int last)
 This signal is emitted just before columns are inserted into the model. More...
 
void columnsAboutToBeMoved (const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destinationParent, int destinationColumn)
 This signal is emitted just before columns are moved within the model. More...
 
void columnsAboutToBeRemoved (const QModelIndex &parent, int first, int last)
 This signal is emitted just before columns are removed from the model. More...
 
void columnsInserted (const QModelIndex &parent, int first, int last)
 This signal is emitted after columns have been inserted into the model. More...
 
void columnsMoved (const QModelIndex &parent, int start, int end, const QModelIndex &destination, int column)
 This signal is emitted after columns have been moved within the model. More...
 
void columnsRemoved (const QModelIndex &parent, int first, int last)
 This signal is emitted after columns have been removed from the model. More...
 
void dataChanged (const QModelIndex &topLeft, const QModelIndex &bottomRight)
 This signal is emitted whenever the data in an existing item changes. More...
 
void headerDataChanged (Qt::Orientation orientation, int first, int last)
 This signal is emitted whenever a header is changed. More...
 
void layoutAboutToBeChanged ()
 This signal is emitted just before the layout of a model is changed. More...
 
void layoutChanged ()
 This signal is emitted whenever the layout of items exposed by the model has changed; for example, when the model has been sorted. More...
 
void modelAboutToBeReset ()
 This signal is emitted when reset() is called, before the model's internal state (e. More...
 
void modelReset ()
 This signal is emitted when reset() is called, after the model's internal state (e. More...
 
void rowsAboutToBeInserted (const QModelIndex &parent, int first, int last)
 This signal is emitted just before rows are inserted into the model. More...
 
void rowsAboutToBeMoved (const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destinationParent, int destinationRow)
 This signal is emitted just before rows are moved within the model. More...
 
void rowsAboutToBeRemoved (const QModelIndex &parent, int first, int last)
 This signal is emitted just before rows are removed from the model. More...
 
void rowsInserted (const QModelIndex &parent, int first, int last)
 This signal is emitted after rows have been inserted into the model. More...
 
void rowsMoved (const QModelIndex &parent, int start, int end, const QModelIndex &destination, int row)
 This signal is emitted after rows have been moved within the model. More...
 
void rowsRemoved (const QModelIndex &parent, int first, int last)
 This signal is emitted after rows have been removed from the model. More...
 
- Signals inherited from QObject
void destroyed (QObject *=0)
 This signal is emitted immediately before the object obj is destroyed, and can not be blocked. More...
 

Public Functions

bool canFetchMore (const QModelIndex &parent) const
 Reimplemented Function More...
 
int columnCount (const QModelIndex &parent=QModelIndex()) const
 Reimplemented Function More...
 
QVariant data (const QModelIndex &index, int role=Qt::DisplayRole) const
 Reimplemented Function More...
 
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 in the model specified by the row and column and by the parent index. More...
 
void fetchMore (const QModelIndex &parent)
 Reimplemented Function More...
 
QIcon fileIcon (const QModelIndex &index) const
 Returns the icon for the item stored in the model under the given index. More...
 
QFileInfo fileInfo (const QModelIndex &index) const
 Returns the QFileInfo for the item stored in the model under the given index. More...
 
QString fileName (const QModelIndex &index) const
 Returns the file name for the item stored in the model under the given index. More...
 
QString filePath (const QModelIndex &index) const
 Returns the path of the item stored in the model under the index given. More...
 
QDir::Filters filter () const
 Returns the filter specified for the directory model. More...
 
Qt::ItemFlags flags (const QModelIndex &index) const
 Reimplemented Function More...
 
bool hasChildren (const QModelIndex &parent=QModelIndex()) const
 Reimplemented Function More...
 
QVariant headerData (int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const
 Reimplemented Function More...
 
QFileIconProvidericonProvider () const
 Returns the file icon provider for this directory model. More...
 
QModelIndex index (int row, int column, const QModelIndex &parent=QModelIndex()) const
 Reimplemented Function More...
 
QModelIndex index (const QString &path, int column=0) const
 Returns the model item index for the given path and column. More...
 
bool isDir (const QModelIndex &index) const
 Returns true if the model item index represents a directory; otherwise returns false. More...
 
bool isReadOnly () const
 
QDateTime lastModified (const QModelIndex &index) const
 Returns the date and time when index was last modified. More...
 
QMimeDatamimeData (const QModelIndexList &indexes) const
 Returns an object that contains a serialized description of the specified indexes. More...
 
QStringList mimeTypes () const
 Returns a list of MIME types that can be used to describe a list of items in the model. More...
 
QModelIndex mkdir (const QModelIndex &parent, const QString &name)
 Create a directory with the name in the parent model index. More...
 
QVariant myComputer (int role=Qt::DisplayRole) const
 Returns the data stored under the given role for the item "My Computer". More...
 
bool nameFilterDisables () const
 
QStringList nameFilters () const
 Returns a list of filters applied to the names in the model. More...
 
QModelIndex parent (const QModelIndex &child) const
 Reimplemented Function More...
 
QFile::Permissions permissions (const QModelIndex &index) const
 Returns the complete OR-ed together combination of QFile::Permission for the index. More...
 
 QFileSystemModel (QObject *parent=0)
 Constructs a file system model with the given parent. More...
 
bool remove (const QModelIndex &index) const
 Removes the model item index from the file system model and deletes the corresponding file from the file system, returning true if successful. More...
 
bool resolveSymlinks () const
 
bool rmdir (const QModelIndex &index) const
 Removes the directory corresponding to the model item index in the file system model and deletes the corresponding directory from the file system, returning true if successful. More...
 
QDir rootDirectory () const
 The currently set directory. More...
 
QString rootPath () const
 The currently set root path. More...
 
int rowCount (const QModelIndex &parent=QModelIndex()) const
 Reimplemented Function More...
 
bool setData (const QModelIndex &index, const QVariant &value, int role=Qt::EditRole)
 Reimplemented Function More...
 
void setFilter (QDir::Filters filters)
 Sets the directory model's filter to that specified by filters. More...
 
void setIconProvider (QFileIconProvider *provider)
 Sets the provider of file icons for the directory model. More...
 
void setNameFilterDisables (bool enable)
 
void setNameFilters (const QStringList &filters)
 Sets the name filters to apply against the existing files. More...
 
void setReadOnly (bool enable)
 
void setResolveSymlinks (bool enable)
 
QModelIndex setRootPath (const QString &path)
 Sets the directory that is being watched by the model to newPath by installing a file system watcher on it. More...
 
qint64 size (const QModelIndex &index) const
 Returns the size in bytes of index. More...
 
void sort (int column, Qt::SortOrder order=Qt::AscendingOrder)
 Reimplemented Function More...
 
Qt::DropActions supportedDropActions () const
 Reimplemented Function More...
 
QString type (const QModelIndex &index) const
 Returns the type of file index such as "Directory" or "JPEG file". More...
 
 ~QFileSystemModel ()
 Destroys this file system model. More...
 
- Public Functions inherited from QAbstractItemModel
virtual QModelIndex buddy (const QModelIndex &index) const
 Returns a model index for the buddy of the item represented by index. More...
 
bool hasIndex (int row, int column, const QModelIndex &parent=QModelIndex()) const
 Returns true if the model returns a valid QModelIndex for row and column with parent, otherwise returns false. More...
 
bool insertColumn (int column, const QModelIndex &parent=QModelIndex())
 Inserts a single column before the given column in the child items of the parent specified. More...
 
virtual bool insertColumns (int column, int count, const QModelIndex &parent=QModelIndex())
 On models that support this, inserts count new columns into the model before the given column. More...
 
bool insertRow (int row, const QModelIndex &parent=QModelIndex())
 Inserts a single row before the given row in the child items of the parent specified. More...
 
virtual bool insertRows (int row, int count, const QModelIndex &parent=QModelIndex())
 On models that support this, inserts count rows into the model before the given row. More...
 
virtual QMap< int, QVariantitemData (const QModelIndex &index) const
 Returns a map with values for all predefined roles in the model for the item at the given index. More...
 
virtual QModelIndexList match (const QModelIndex &start, int role, const QVariant &value, int hits=1, Qt::MatchFlags flags=Qt::MatchFlags(Qt::MatchStartsWith|Qt::MatchWrap)) const
 Returns a list of indexes for the items in the column of the start index where data stored under the given role matches the specified value. More...
 
 QAbstractItemModel (QObject *parent=0)
 Constructs an abstract item model with the given parent. More...
 
bool removeColumn (int column, const QModelIndex &parent=QModelIndex())
 Removes the given column from the child items of the parent specified. More...
 
virtual bool removeColumns (int column, int count, const QModelIndex &parent=QModelIndex())
 On models that support this, removes count columns starting with the given column under parent parent from the model. More...
 
bool removeRow (int row, const QModelIndex &parent=QModelIndex())
 Removes the given row from the child items of the parent specified. More...
 
virtual bool removeRows (int row, int count, const QModelIndex &parent=QModelIndex())
 On models that support this, removes count rows starting with the given row under parent parent from the model. More...
 
const QHash< int, QByteArray > & roleNames () const
 Returns the model's role names. More...
 
virtual bool setHeaderData (int section, Qt::Orientation orientation, const QVariant &value, int role=Qt::EditRole)
 Sets the data for the given role and section in the header with the specified orientation to the value supplied. More...
 
virtual bool setItemData (const QModelIndex &index, const QMap< int, QVariant > &roles)
 Sets the role data for the item at index to the associated value in roles, for every Qt::ItemDataRole. More...
 
void setSupportedDragActions (Qt::DropActions)
 Sets the supported drag actions for the items in the model. More...
 
QModelIndex sibling (int row, int column, const QModelIndex &idx) const
 Returns the sibling at row and column for the item at index, or an invalid QModelIndex if there is no sibling at that location. More...
 
virtual QSize span (const QModelIndex &index) const
 Returns the row and column span of the item represented by index. More...
 
Qt::DropActions supportedDragActions () const
 Returns the actions supported by the data in this model. More...
 
virtual ~QAbstractItemModel ()
 Destroys the abstract item model. More...
 
- Public Functions inherited from QObject
bool blockSignals (bool b)
 If block is true, signals emitted by this object are blocked (i.e., emitting a signal will not invoke anything connected to it). More...
 
const QObjectListchildren () const
 Returns a list of child objects. More...
 
bool connect (const QObject *sender, const char *signal, const char *member, Qt::ConnectionType type=Qt::AutoConnection) const
 
bool disconnect (const char *signal=0, const QObject *receiver=0, const char *member=0)
 
bool disconnect (const QObject *receiver, const char *member=0)
 
void dumpObjectInfo ()
 Dumps information about signal connections, etc. More...
 
void dumpObjectTree ()
 Dumps a tree of children to the debug output. More...
 
QList< QByteArraydynamicPropertyNames () const
 Returns the names of all properties that were dynamically added to the object using setProperty(). More...
 
virtual bool eventFilter (QObject *, QEvent *)
 Filters events if this object has been installed as an event filter for the watched object. More...
 
template<typename T >
findChild (const QString &aName=QString()) const
 Returns the child of this object that can be cast into type T and that is called name, or 0 if there is no such object. More...
 
template<typename T >
QList< T > findChildren (const QString &aName=QString()) const
 Returns all children of this object with the given name that can be cast to type T, or an empty list if there are no such objects. More...
 
template<typename T >
QList< T > findChildren (const QRegExp &re) const
 
bool inherits (const char *classname) const
 Returns true if this object is an instance of a class that inherits className or a QObject subclass that inherits className; otherwise returns false. More...
 
void installEventFilter (QObject *)
 Installs an event filter filterObj on this object. More...
 
bool isWidgetType () const
 Returns true if the object is a widget; otherwise returns false. More...
 
void killTimer (int id)
 Kills the timer with timer identifier, id. More...
 
virtual const QMetaObjectmetaObject () const
 Returns a pointer to the meta-object of this object. More...
 
void moveToThread (QThread *thread)
 Changes the thread affinity for this object and its children. More...
 
QString objectName () const
 
QObjectparent () const
 Returns a pointer to the parent object. More...
 
QVariant property (const char *name) const
 Returns the value of the object's name property. More...
 
Q_INVOKABLE QObject (QObject *parent=0)
 Constructs an object with parent object parent. More...
 
void removeEventFilter (QObject *)
 Removes an event filter object obj from this object. More...
 
void setObjectName (const QString &name)
 
void setParent (QObject *)
 Makes the object a child of parent. More...
 
bool setProperty (const char *name, const QVariant &value)
 Sets the value of the object's name property to value. More...
 
void setUserData (uint id, QObjectUserData *data)
 
bool signalsBlocked () const
 Returns true if signals are blocked; otherwise returns false. More...
 
int startTimer (int interval)
 Starts a timer and returns a timer identifier, or returns zero if it could not start a timer. More...
 
QThreadthread () const
 Returns the thread in which the object lives. More...
 
QObjectUserDatauserData (uint id) const
 
virtual ~QObject ()
 Destroys the object, deleting all its child objects. More...
 

Protected Functions

bool event (QEvent *event)
 Reimplemented Function More...
 
 QFileSystemModel (QFileSystemModelPrivate &, QObject *parent=0)
 
void timerEvent (QTimerEvent *event)
 Reimplemented Function More...
 
- Protected Functions inherited from QAbstractItemModel
void beginInsertColumns (const QModelIndex &parent, int first, int last)
 Begins a column insertion operation. More...
 
void beginInsertRows (const QModelIndex &parent, int first, int last)
 Begins a row insertion operation. More...
 
bool beginMoveColumns (const QModelIndex &sourceParent, int sourceFirst, int sourceLast, const QModelIndex &destinationParent, int destinationColumn)
 Begins a column move operation. More...
 
bool beginMoveRows (const QModelIndex &sourceParent, int sourceFirst, int sourceLast, const QModelIndex &destinationParent, int destinationRow)
 Begins a row move operation. More...
 
void beginRemoveColumns (const QModelIndex &parent, int first, int last)
 Begins a column removal operation. More...
 
void beginRemoveRows (const QModelIndex &parent, int first, int last)
 Begins a row removal operation. More...
 
void beginResetModel ()
 Begins a model reset operation. More...
 
void changePersistentIndex (const QModelIndex &from, const QModelIndex &to)
 Changes the QPersistentModelIndex that is equal to the given from model index to the given to model index. More...
 
void changePersistentIndexList (const QModelIndexList &from, const QModelIndexList &to)
 Changes the QPersistentModelIndexes that is equal to the indexes in the given from model index list to the given to model index list. More...
 
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. More...
 
QModelIndex createIndex (int row, int column, int id) const
 Use QModelIndex QAbstractItemModel::createIndex(int row, int column, quint32 id) instead. More...
 
QModelIndex createIndex (int row, int column, quint32 id) const
 Creates a model index for the given row and column with the internal identifier, id. More...
 
bool decodeData (int row, int column, const QModelIndex &parent, QDataStream &stream)
 
void encodeData (const QModelIndexList &indexes, QDataStream &stream) const
 
void endInsertColumns ()
 Ends a column insertion operation. More...
 
void endInsertRows ()
 Ends a row insertion operation. More...
 
void endMoveColumns ()
 Ends a column move operation. More...
 
void endMoveRows ()
 Ends a row move operation. More...
 
void endRemoveColumns ()
 Ends a column removal operation. More...
 
void endRemoveRows ()
 Ends a row removal operation. More...
 
void endResetModel ()
 Completes a model reset operation. More...
 
QModelIndexList persistentIndexList () const
 Returns the list of indexes stored as persistent indexes in the model. More...
 
 QAbstractItemModel (QAbstractItemModelPrivate &dd, QObject *parent=0)
 
void reset ()
 Resets the model to its original state in any attached views. More...
 
void setRoleNames (const QHash< int, QByteArray > &roleNames)
 Sets the model's role names to roleNames. More...
 
- Protected Functions inherited from QObject
virtual void childEvent (QChildEvent *)
 This event handler can be reimplemented in a subclass to receive child events. More...
 
virtual void connectNotify (const char *signal)
 This virtual function is called when something has been connected to signal in this object. More...
 
virtual void customEvent (QEvent *)
 This event handler can be reimplemented in a subclass to receive custom events. More...
 
virtual void disconnectNotify (const char *signal)
 This virtual function is called when something has been disconnected from signal in this object. More...
 
 QObject (QObjectPrivate &dd, QObject *parent=0)
 
int receivers (const char *signal) const
 Returns the number of receivers connected to the signal. More...
 
QObjectsender () const
 Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; otherwise it returns 0. More...
 
int senderSignalIndex () const
 

Properties

bool nameFilterDisables
 Whether files that don't pass the name filter are hidden or disabled. More...
 
bool readOnly
 Whether the directory model allows writing to the file system. More...
 
bool resolveSymlinks
 Whether the directory model should resolve symbolic links. More...
 

Friends

class QFileDialogPrivate
 

Additional Inherited Members

- Public Slots inherited from QAbstractItemModel
virtual void revert ()
 Lets the model know that it should discard cached information. More...
 
virtual bool submit ()
 Lets the model know that it should submit cached information to permanent storage. More...
 
- Public Slots inherited from QObject
void deleteLater ()
 Schedules this object for deletion. More...
 
- Static Public Functions inherited from QObject
static bool connect (const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
 Creates a connection of the given type from the signal in the sender object to the method in the receiver object. More...
 
static bool connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type=Qt::AutoConnection)
 
static bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *member)
 Disconnects signal in object sender from method in object receiver. More...
 
static bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &member)
 
static uint registerUserData ()
 
static QString tr (const char *sourceText, const char *comment=0, int n=-1)
 
static QString trUtf8 (const char *sourceText, const char *comment=0, int n=-1)
 
- Static Public Variables inherited from QObject
static const QMetaObject staticMetaObject
 This variable stores the meta-object for the class. More...
 
- Protected Slots inherited from QAbstractItemModel
void resetInternalData ()
 This slot is called just after the internal data of a model is cleared while it is being reset. More...
 
- Protected Variables inherited from QObject
QScopedPointer< QObjectDatad_ptr
 
- Static Protected Variables inherited from QObject
static const QMetaObject staticQtMetaObject
 

Detailed Description

The QFileSystemModel class provides a data model for the local filesystem.

Since
4.4

This class provides access to the local filesystem, providing functions for renaming and removing files and directories, and for creating new directories. In the simplest case, it can be used with a suitable display widget as part of a browser or filter.

QFileSystemModel can be accessed using the standard interface provided by QAbstractItemModel, but it also provides some convenience functions that are specific to a directory model. The fileInfo(), isDir(), name(), and path() functions provide information about the underlying files and directories related to items in the model. Directories can be created and removed using mkdir(), rmdir().

Note
QFileSystemModel requires an instance of a GUI application.

Example Usage

A directory model that displays the contents of a default directory is usually constructed with a parent object:

A tree view can be used to display the contents of the model

QTreeView *tree = new QTreeView(splitter);
tree->setModel(model);

and the contents of a particular directory can be displayed by setting the tree view's root index:

The view's root index can be used to control how much of a hierarchical model is displayed. QDirModel provides a convenience function that returns a suitable model index for a path to a directory within the model.

Caching and Performance

QFileSystemModel will not fetch any files or directories until setRootPath() is called. This will prevent any unnecessary querying on the file system until that point such as listing the drives on Windows.

Unlike QDirModel, QFileSystemModel uses a separate thread to populate itself so it will not cause the main thread to hang as the file system is being queried. Calls to rowCount() will return 0 until the model populates a directory.

QFileSystemModel keeps a cache with file information. The cache is automatically kept up to date using the QFileSystemWatcher.

See also
{Model Classes}

Definition at line 63 of file qfilesystemmodel.h.

Enumerations

◆ Roles

  • FileIconRole
  • FilePathRole
  • FileNameRole
  • FilePermissions
Enumerator
FileIconRole 
FilePathRole 
FileNameRole 
FilePermissions 

Definition at line 76 of file qfilesystemmodel.h.

Constructors and Destructors

◆ QFileSystemModel() [1/2]

QFileSystemModel::QFileSystemModel ( QObject parent = 0)
explicit

Constructs a file system model with the given parent.

Definition at line 259 of file qfilesystemmodel.cpp.

261 {
263  d->init();
264 }
double d
Definition: qnumeric_p.h:62
The QFileSystemModel class provides a data model for the local filesystem.
#define Q_D(Class)
Definition: qglobal.h:2482
QAbstractItemModel(QObject *parent=0)
Constructs an abstract item model with the given parent.

◆ ~QFileSystemModel()

QFileSystemModel::~QFileSystemModel ( )

Destroys this file system model.

Definition at line 279 of file qfilesystemmodel.cpp.

280 {
281 }

◆ QFileSystemModel() [2/2]

QFileSystemModel::QFileSystemModel ( QFileSystemModelPrivate dd,
QObject parent = 0 
)
protected
Warning
This function is not part of the public interface.

Definition at line 269 of file qfilesystemmodel.cpp.

270  : QAbstractItemModel(dd, parent)
271 {
273  d->init();
274 }
double d
Definition: qnumeric_p.h:62
The QFileSystemModel class provides a data model for the local filesystem.
#define Q_D(Class)
Definition: qglobal.h:2482
QAbstractItemModel(QObject *parent=0)
Constructs an abstract item model with the given parent.

Functions

◆ canFetchMore()

bool QFileSystemModel::canFetchMore ( const QModelIndex parent) const
virtual

Reimplemented Function

Reimplemented from QAbstractItemModel.

Definition at line 652 of file qfilesystemmodel.cpp.

653 {
654  Q_D(const QFileSystemModel);
655  const QFileSystemModelPrivate::QFileSystemNode *indexNode = d->node(parent);
656  return (!indexNode->populatedChildren);
657 }
double d
Definition: qnumeric_p.h:62
The QFileSystemModel class provides a data model for the local filesystem.
#define Q_D(Class)
Definition: qglobal.h:2482

◆ columnCount()

int QFileSystemModel::columnCount ( const QModelIndex parent = QModelIndex()) const
virtual

Reimplemented Function

Implements QAbstractItemModel.

Definition at line 693 of file qfilesystemmodel.cpp.

Referenced by index().

694 {
695  return (parent.column() > 0) ? 0 : 4;
696 }
int column() const
Returns the column this model index refers to.

◆ data()

QVariant QFileSystemModel::data ( const QModelIndex index,
int  role = Qt::DisplayRole 
) const
virtual

Reimplemented Function

Implements QAbstractItemModel.

Definition at line 718 of file qfilesystemmodel.cpp.

Referenced by fileName(), mimeData(), and QUrlModel::setData().

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 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
double d
Definition: qnumeric_p.h:62
The QFileSystemModel class provides a data model for the local filesystem.
#define Q_D(Class)
Definition: qglobal.h:2482
QString filePath(const QModelIndex &index) const
Returns the path of the item stored in the model under the index given.
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
Q_CORE_EXPORT void qWarning(const char *,...)
QFile::Permissions permissions(const QModelIndex &index) const
Returns the complete OR-ed together combination of QFile::Permission for the index.
bool isValid() const
Returns true if this model index is valid; otherwise returns false.
int column() const
Returns the column this model index refers to.
The QIcon class provides scalable icons in different modes and states.
Definition: qicon.h:60

◆ directoryLoaded

void QFileSystemModel::directoryLoaded ( const QString path)
signal

This signal is emitted when the gatherer thread has finished to load the path.

Since
4.7

Referenced by QFileSystemModelPrivate::init().

◆ dropMimeData()

bool QFileSystemModel::dropMimeData ( const QMimeData data,
Qt::DropAction  action,
int  row,
int  column,
const QModelIndex parent 
)
virtual

Handles the data supplied by a drag and drop operation that ended with the given action over the row in the model specified by the row and column and by the parent index.

See also
supportedDropActions()

Reimplemented from QAbstractItemModel.

Definition at line 1261 of file qfilesystemmodel.cpp.

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 }
bool rename(const QString &newName)
Renames the file currently specified by fileName() to newName.
Definition: qfile.cpp:766
QString fileName(const QModelIndex &index) const
Returns the file name for the item stored in the model under the given index.
#define it(className, varName)
const_iterator constBegin() const
Returns a const STL-style iterator pointing to the first item in the list.
Definition: qlist.h:269
The QString class provides a Unicode character string.
Definition: qstring.h:83
static QChar separator()
Returns the native directory separator: "/" under Unix (including Mac OS X) and "\\" under Windows...
Definition: qdir.cpp:1831
QString filePath(const QModelIndex &index) const
Returns the path of the item stored in the model under the index given.
QList< QUrl > urls() const
Returns a list of URLs contained within the MIME data object.
Definition: qmimedata.cpp:310
bool isValid() const
Returns true if this model index is valid; otherwise returns false.
bool copy(const QString &newName)
Copies the file currently specified by fileName() to a file called newName.
Definition: qfile.cpp:926
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
bool link(const QString &newName)
Creates a link named linkName that points to the file currently specified by fileName().
Definition: qfile.cpp:877
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

◆ event()

bool QFileSystemModel::event ( QEvent event)
protectedvirtual

Reimplemented Function

Reimplemented from QObject.

Definition at line 1670 of file qfilesystemmodel.cpp.

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 }
double d
Definition: qnumeric_p.h:62
The QFileSystemModel class provides a data model for the local filesystem.
The QString class provides a Unicode character string.
Definition: qstring.h:83
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
Type type() const
Returns the event type.
Definition: qcoreevent.h:303

◆ fetchMore()

void QFileSystemModel::fetchMore ( const QModelIndex parent)
virtual

Reimplemented Function

Reimplemented from QAbstractItemModel.

Definition at line 662 of file qfilesystemmodel.cpp.

Referenced by setRootPath(), and QFSCompleter::splitPath().

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 }
double d
Definition: qnumeric_p.h:62
The QFileSystemModel class provides a data model for the local filesystem.
#define Q_D(Class)
Definition: qglobal.h:2482
QString filePath(const QModelIndex &index) const
Returns the path of the item stored in the model under the index given.

◆ fileIcon()

QIcon QFileSystemModel::fileIcon ( const QModelIndex index) const
inline

Returns the icon for the item stored in the model under the given index.

Definition at line 168 of file qfilesystemmodel.h.

169 { return qvariant_cast<QIcon>(aindex.data(Qt::DecorationRole)); }
T qvariant_cast(const QVariant &)
Definition: qvariant.h:571
The QIcon class provides scalable icons in different modes and states.
Definition: qicon.h:60

◆ fileInfo()

QFileInfo QFileSystemModel::fileInfo ( const QModelIndex index) const
inline

Returns the QFileInfo for the item stored in the model under the given index.

Definition at line 170 of file qfilesystemmodel.h.

Referenced by isDir().

171 { return QFileInfo(filePath(aindex)); }
QString filePath(const QModelIndex &index) const
Returns the path of the item stored in the model under the index given.
The QFileInfo class provides system-independent file information.
Definition: qfileinfo.h:60

◆ fileName()

QString QFileSystemModel::fileName ( const QModelIndex index) const
inline

Returns the file name for the item stored in the model under the given index.

Definition at line 166 of file qfilesystemmodel.h.

Referenced by QFileSystemModelPrivate::_q_fileSystemChanged(), QFileSystemModelPrivate::_q_resolvedName(), and dropMimeData().

167 { return aindex.data(Qt::DisplayRole).toString(); }

◆ filePath()

QString QFileSystemModel::filePath ( const QModelIndex index) const

Returns the path of the item stored in the model under the index given.

Definition at line 1313 of file qfilesystemmodel.cpp.

Referenced by data(), dropMimeData(), fetchMore(), mimeData(), mkdir(), QFileSystemModelPrivate::name(), remove(), rmdir(), and setData().

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 }
double d
Definition: qnumeric_p.h:62
The QFileSystemModel class provides a data model for the local filesystem.
The QString class provides a Unicode character string.
Definition: qstring.h:83
#define Q_D(Class)
Definition: qglobal.h:2482
bool isSymLink(bool ignoreNtfsSymLinks=false) const
The QFileInfo class provides system-independent file information.
Definition: qfileinfo.h:60

◆ fileRenamed

void QFileSystemModel::fileRenamed ( const QString path,
const QString oldName,
const QString newName 
)
signal

This signal is emitted whenever a file with the oldName is successfully renamed to newName.

The file is located in in the directory path.

Referenced by setData().

◆ filter()

QDir::Filters QFileSystemModel::filter ( ) const

Returns the filter specified for the directory model.

If a filter has not been set, the default filter is QDir::AllEntries | QDir::NoDotAndDotDot | QDir::AllDirs.

See also
QDir::Filters

Definition at line 1535 of file qfilesystemmodel.cpp.

Referenced by rootDirectory(), and setNameFilters().

1536 {
1537  Q_D(const QFileSystemModel);
1538  return d->filters;
1539 }
double d
Definition: qnumeric_p.h:62
The QFileSystemModel class provides a data model for the local filesystem.
#define Q_D(Class)
Definition: qglobal.h:2482

◆ flags()

Qt::ItemFlags QFileSystemModel::flags ( const QModelIndex index) const
virtual

Reimplemented Function

Reimplemented from QAbstractItemModel.

Definition at line 983 of file qfilesystemmodel.cpp.

Referenced by setData().

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 }
double d
Definition: qnumeric_p.h:62
The QFileSystemModel class provides a data model for the local filesystem.
#define Q_D(Class)
Definition: qglobal.h:2482
virtual Qt::ItemFlags flags(const QModelIndex &index) const
Returns the item flags for the given index.
bool isValid() const
Returns true if this model index is valid; otherwise returns false.
Qt::ItemFlags flags(const QModelIndex &index) const
Reimplemented Function
Definition: qnamespace.h:54
int column() const
Returns the column this model index refers to.

◆ hasChildren()

bool QFileSystemModel::hasChildren ( const QModelIndex parent = QModelIndex()) const
virtual

Reimplemented Function

Reimplemented from QAbstractItemModel.

Definition at line 635 of file qfilesystemmodel.cpp.

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 }
double d
Definition: qnumeric_p.h:62
The QFileSystemModel class provides a data model for the local filesystem.
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
#define Q_D(Class)
Definition: qglobal.h:2482
bool isValid() const
Returns true if this model index is valid; otherwise returns false.
int column() const
Returns the column this model index refers to.

◆ headerData()

QVariant QFileSystemModel::headerData ( int  section,
Qt::Orientation  orientation,
int  role = Qt::DisplayRole 
) const
virtual

Reimplemented Function

Reimplemented from QAbstractItemModel.

Definition at line 936 of file qfilesystemmodel.cpp.

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 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
static QString tr(const char *sourceText, const char *comment=0, int n=-1)
The QString class provides a Unicode character string.
Definition: qstring.h:83
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.
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87

◆ iconProvider()

QFileIconProvider * QFileSystemModel::iconProvider ( ) const

Returns the file icon provider for this directory model.

Definition at line 1501 of file qfilesystemmodel.cpp.

Referenced by QUrlModel::setUrl().

1502 {
1503  Q_D(const QFileSystemModel);
1504  return d->fileInfoGatherer.iconProvider();
1505 }
double d
Definition: qnumeric_p.h:62
The QFileSystemModel class provides a data model for the local filesystem.
#define Q_D(Class)
Definition: qglobal.h:2482

◆ index() [1/2]

QModelIndex QFileSystemModel::index ( int  row,
int  column,
const QModelIndex parent = QModelIndex() 
) const
virtual

Reimplemented Function

Implements QAbstractItemModel.

Definition at line 286 of file qfilesystemmodel.cpp.

Referenced by QFileDialogPrivate::_q_autoCompleteFileName(), QFileSystemModelPrivate::_q_fileSystemChanged(), QFileDialogPrivate::_q_goToDirectory(), QFileDialogPrivate::_q_goToUrl(), QFileDialogPrivate::_q_updateOkButton(), QUrlModel::addUrls(), QFileSystemModelPrivate::addVisibleFiles(), QUrlModel::canDrop(), QFileSystemModelPrivate::filePath(), QUrlModel::layoutChanged(), QFileSystemModelPrivate::node(), remove(), QFileDialogPrivate::removeDirectory(), QFileSystemModelPrivate::removeNode(), QFileSystemModelPrivate::removeVisibleFile(), QUrlModel::setData(), setNameFilters(), QFileDialogComboBox::showPopup(), and sort().

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 }
double d
Definition: qnumeric_p.h:62
int columnCount(const QModelIndex &parent=QModelIndex()) const
Reimplemented Function
QHash< QString, QFileSystemNode * > children
The QFileSystemModel class provides a data model for the local filesystem.
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. ...
The QString class provides a Unicode character string.
Definition: qstring.h:83
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
#define Q_D(Class)
Definition: qglobal.h:2482
The QModelIndex class is used to locate data in a data model.
int rowCount(const QModelIndex &parent=QModelIndex()) const
Reimplemented Function

◆ index() [2/2]

QModelIndex QFileSystemModel::index ( const QString path,
int  column = 0 
) const

Returns the model item index for the given path and column.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 313 of file qfilesystemmodel.cpp.

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 }
double d
Definition: qnumeric_p.h:62
The QFileSystemModel class provides a data model for the local filesystem.
QModelIndex sibling(int row, int column) const
Returns the sibling at row and column.
#define Q_D(Class)
Definition: qglobal.h:2482
int row() const
Returns the row this model index refers to.
The QModelIndex class is used to locate data in a data model.
int column() const
Returns the column this model index refers to.

◆ isDir()

bool QFileSystemModel::isDir ( const QModelIndex index) const

Returns true if the model item index represents a directory; otherwise returns false.

Definition at line 542 of file qfilesystemmodel.cpp.

Referenced by QFileDialogPrivate::_q_deleteCurrent(), QFileDialogPrivate::_q_enterDirectory(), QFileDialogPrivate::_q_selectionChanged(), QFileDialogPrivate::_q_updateOkButton(), QUrlModel::addUrls(), and QUrlModel::canDrop().

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 }
double d
Definition: qnumeric_p.h:62
The QFileSystemModel class provides a data model for the local filesystem.
#define Q_D(Class)
Definition: qglobal.h:2482
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
QFileInfo fileInfo(const QModelIndex &index) const
Returns the QFileInfo for the item stored in the model under the given index.
bool isValid() const
Returns true if this model index is valid; otherwise returns false.

◆ isReadOnly()

bool QFileSystemModel::isReadOnly ( ) const

Definition at line 1582 of file qfilesystemmodel.cpp.

Referenced by QFileDialogPrivate::_q_deleteCurrent(), and dropMimeData().

1583 {
1584  Q_D(const QFileSystemModel);
1585  return d->readOnly;
1586 }
double d
Definition: qnumeric_p.h:62
The QFileSystemModel class provides a data model for the local filesystem.
#define Q_D(Class)
Definition: qglobal.h:2482

◆ lastModified()

QDateTime QFileSystemModel::lastModified ( const QModelIndex index) const

Returns the date and time when index was last modified.

Definition at line 579 of file qfilesystemmodel.cpp.

580 {
581  Q_D(const QFileSystemModel);
582  if (!index.isValid())
583  return QDateTime();
584  return d->node(index)->lastModified();
585 }
double d
Definition: qnumeric_p.h:62
The QFileSystemModel class provides a data model for the local filesystem.
#define Q_D(Class)
Definition: qglobal.h:2482
bool isValid() const
Returns true if this model index is valid; otherwise returns false.
The QDateTime class provides date and time functions.
Definition: qdatetime.h:216

◆ mimeData()

QMimeData * QFileSystemModel::mimeData ( const QModelIndexList indexes) const
virtual

Returns an object that contains a serialized description of the specified indexes.

The format used to describe the items corresponding to the indexes is obtained from the mimeTypes() function.

If the list of indexes is empty, 0 is returned rather than a serialized empty list.

Reimplemented from QAbstractItemModel.

Definition at line 1242 of file qfilesystemmodel.cpp.

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 }
#define it(className, varName)
iterator begin()
Returns an STL-style iterator pointing to the first item in the list.
Definition: qlist.h:267
QString filePath(const QModelIndex &index) const
Returns the path of the item stored in the model under the index given.
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the list...
Definition: qlist.h:270
void setUrls(const QList< QUrl > &urls)
Sets the URLs stored in the MIME data object to those specified by urls.
Definition: qmimedata.cpp:334
The QMimeData class provides a container for data that records information about its MIME type...
Definition: qmimedata.h:57
static QUrl fromLocalFile(const QString &localfile)
Returns a QUrl representation of localFile, interpreted as a local file.
Definition: qurl.cpp:6374
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const
Reimplemented Function

◆ mimeTypes()

QStringList QFileSystemModel::mimeTypes ( ) const
virtual

Returns a list of MIME types that can be used to describe a list of items in the model.

Reimplemented from QAbstractItemModel.

Definition at line 1229 of file qfilesystemmodel.cpp.

1230 {
1231  return QStringList(QLatin1String("text/uri-list"));
1232 }
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QStringList class provides a list of strings.
Definition: qstringlist.h:66

◆ mkdir()

QModelIndex QFileSystemModel::mkdir ( const QModelIndex parent,
const QString name 
)

Create a directory with the name in the parent model index.

Definition at line 1360 of file qfilesystemmodel.cpp.

Referenced by QFileDialogPrivate::_q_createDirectory().

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 }
The QDir class provides access to directory structures and their contents.
Definition: qdir.h:58
double d
Definition: qnumeric_p.h:62
QHash< QString, QFileSystemNode * > children
The QFileSystemModel class provides a data model for the local filesystem.
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
#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
QString filePath(const QModelIndex &index) const
Returns the path of the item stored in the model under the index given.
const char * name
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.
The QModelIndex class is used to locate data in a data model.
The QFileInfo class provides system-independent file information.
Definition: qfileinfo.h:60

◆ myComputer()

QVariant QFileSystemModel::myComputer ( int  role = Qt::DisplayRole) const

Returns the data stored under the given role for the item "My Computer".

See also
Qt::ItemDataRole

Definition at line 703 of file qfilesystemmodel.cpp.

Referenced by QFileDialogPrivate::_q_goToDirectory(), QFileDialogPrivate::_q_navigateToParent(), QFileSystemModelPrivate::node(), and QUrlModel::setUrl().

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 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
double d
Definition: qnumeric_p.h:62
The QFileSystemModel class provides a data model for the local filesystem.
#define Q_D(Class)
Definition: qglobal.h:2482

◆ nameFilterDisables()

bool QFileSystemModel::nameFilterDisables ( ) const

◆ nameFilters()

QStringList QFileSystemModel::nameFilters ( ) const

Returns a list of filters applied to the names in the model.

Definition at line 1655 of file qfilesystemmodel.cpp.

Referenced by QFileSystemModelPrivate::passNameFilters(), rootDirectory(), and setFilter().

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 }
double d
Definition: qnumeric_p.h:62
The QFileSystemModel class provides a data model for the local filesystem.
#define Q_D(Class)
Definition: qglobal.h:2482
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
static const char *const filters[3]

◆ parent()

QModelIndex QFileSystemModel::parent ( const QModelIndex child) const
virtual

Reimplemented Function

Implements QAbstractItemModel.

Definition at line 590 of file qfilesystemmodel.cpp.

591 {
592  Q_D(const QFileSystemModel);
593  if (!d->indexValid(index))
594  return QModelIndex();
595 
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 }
double d
Definition: qnumeric_p.h:62
QHash< QString, QFileSystemNode * > children
The QFileSystemModel class provides a data model for the local filesystem.
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. ...
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
#define Q_D(Class)
Definition: qglobal.h:2482
The QModelIndex class is used to locate data in a data model.
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const
Reimplemented Function

◆ permissions()

QFile::Permissions QFileSystemModel::permissions ( const QModelIndex index) const

Returns the complete OR-ed together combination of QFile::Permission for the index.

Definition at line 1381 of file qfilesystemmodel.cpp.

Referenced by data().

1382 {
1383  Q_D(const QFileSystemModel);
1384  QFile::Permissions p = d->node(index)->permissions();
1385  if (d->readOnly) {
1388  }
1389  return p;
1390 }
double d
Definition: qnumeric_p.h:62
The QFileSystemModel class provides a data model for the local filesystem.
#define Q_D(Class)
Definition: qglobal.h:2482

◆ remove()

bool QFileSystemModel::remove ( const QModelIndex index) const

Removes the model item index from the file system model and deletes the corresponding file from the file system, returning true if successful.

If the item cannot be removed, false is returned.

Warning
This function deletes files from the file system; it does not move them to a location where they can be recovered.
See also
rmdir()

Definition at line 226 of file qfilesystemmodel.cpp.

Referenced by QFileDialogPrivate::_q_deleteCurrent(), and QFileDialogPrivate::removeDirectory().

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 }
The QDir class provides access to directory structures and their contents.
Definition: qdir.h:58
double d
Definition: qnumeric_p.h:62
void removePath(const QString &path)
static mach_timebase_info_data_t info
#define it(className, varName)
#define error(msg)
bool rmdir(const QModelIndex &index) const
Removes the directory corresponding to the model item index in the file system model and deletes the ...
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
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 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.
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
The QModelIndex class is used to locate data in a data model.
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const
Reimplemented Function
const QObjectList & children() const
Returns a list of child objects.
Definition: qobject.h:197
bool remove()
Removes the file specified by fileName().
Definition: qfile.cpp:715
The QFileInfo class provides system-independent file information.
Definition: qfileinfo.h:60
QFileInfoGatherer fileInfoGatherer

◆ resolveSymlinks()

bool QFileSystemModel::resolveSymlinks ( ) const

Referenced by setResolveSymlinks().

◆ rmdir()

bool QFileSystemModel::rmdir ( const QModelIndex index) const

Removes the directory corresponding to the model item index in the file system model and deletes the corresponding directory from the file system, returning true if successful.

If the directory cannot be removed, false is returned.

Warning
This function deletes directories from the file system; it does not move them to a location where they can be recovered.
See also
remove()

Definition at line 1680 of file qfilesystemmodel.cpp.

Referenced by remove().

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 }
The QDir class provides access to directory structures and their contents.
Definition: qdir.h:58
double d
Definition: qnumeric_p.h:62
void removePath(const QString &path)
The QString class provides a Unicode character string.
Definition: qstring.h:83
QString filePath(const QModelIndex &index) const
Returns the path of the item stored in the model under the index given.
bool rmdir(const QString &dirName) const
Removes the directory specified by dirName.
Definition: qdir.cpp:1448
QFileInfoGatherer fileInfoGatherer

◆ rootDirectory()

QDir QFileSystemModel::rootDirectory ( ) const

The currently set directory.

See also
rootPath()

Definition at line 1479 of file qfilesystemmodel.cpp.

Referenced by QFileDialogPrivate::_q_navigateToParent(), and QFileDialogPrivate::_q_pathChanged().

1480 {
1481  Q_D(const QFileSystemModel);
1482  QDir dir(d->rootDir);
1483  dir.setNameFilters(nameFilters());
1484  dir.setFilter(filter());
1485  return dir;
1486 }
The QDir class provides access to directory structures and their contents.
Definition: qdir.h:58
double d
Definition: qnumeric_p.h:62
The QFileSystemModel class provides a data model for the local filesystem.
#define Q_D(Class)
Definition: qglobal.h:2482
QStringList nameFilters() const
Returns a list of filters applied to the names in the model.
QDir::Filters filter() const
Returns the filter specified for the directory model.

◆ rootPath()

QString QFileSystemModel::rootPath ( ) const

The currently set root path.

See also
rootDirectory()

Definition at line 1468 of file qfilesystemmodel.cpp.

Referenced by QFileSystemModelPrivate::node(), setNameFilters(), setRootPath(), and sort().

1469 {
1470  Q_D(const QFileSystemModel);
1471  return d->rootDir.path();
1472 }
double d
Definition: qnumeric_p.h:62
The QFileSystemModel class provides a data model for the local filesystem.
#define Q_D(Class)
Definition: qglobal.h:2482

◆ rootPathChanged

void QFileSystemModel::rootPathChanged ( const QString newPath)
signal

This signal is emitted whenever the root path has been changed to a newPath.

Referenced by setRootPath().

◆ rowCount()

int QFileSystemModel::rowCount ( const QModelIndex parent = QModelIndex()) const
virtual

Reimplemented Function

Implements QAbstractItemModel.

Definition at line 677 of file qfilesystemmodel.cpp.

Referenced by index().

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 }
double d
Definition: qnumeric_p.h:62
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_D(Class)
Definition: qglobal.h:2482
bool isValid() const
Returns true if this model index is valid; otherwise returns false.
int column() const
Returns the column this model index refers to.

◆ setData()

bool QFileSystemModel::setData ( const QModelIndex index,
const QVariant value,
int  role = Qt::EditRole 
)
virtual

Reimplemented Function

Reimplemented from QAbstractItemModel.

Definition at line 874 of file qfilesystemmodel.cpp.

Referenced by QFileDialogComboBox::showPopup().

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 }
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
double d
Definition: qnumeric_p.h:62
QHash< QString, QFileSystemNode * > children
The QFileSystemModel class provides a data model for the local filesystem.
static mach_timebase_info_data_t info
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...
QString toString() const
Returns the variant as a QString if the variant has type() String , Bool , ByteArray ...
Definition: qvariant.cpp:2270
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)
The QString class provides a Unicode character string.
Definition: qstring.h:83
#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
QChar * data()
Returns a pointer to the data stored in the QString.
Definition: qstring.h:710
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
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
QFileInfo fileInfo() const
#define emit
Definition: qobjectdefs.h:76
QObject * parent() const
Returns a pointer to the parent object.
Definition: qobject.h:273
Qt::ItemFlags flags(const QModelIndex &index) const
Reimplemented Function
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...
The QFileInfo class provides system-independent file information.
Definition: qfileinfo.h:60
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
void removeAt(int i)
Removes the item at index position i.
Definition: qlist.h:480

◆ setFilter()

void QFileSystemModel::setFilter ( QDir::Filters  filters)

Sets the directory model's filter to that specified by filters.

Note that the filter you set should always include the QDir::AllDirs enum value, otherwise QFileSystemModel won't be able to read the directory structure.

See also
QDir::Filters

Definition at line 1515 of file qfilesystemmodel.cpp.

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 }
double d
Definition: qnumeric_p.h:62
The QFileSystemModel class provides a data model for the local filesystem.
#define Q_D(Class)
Definition: qglobal.h:2482
QStringList nameFilters() const
Returns a list of filters applied to the names in the model.
void setNameFilters(const QStringList &filters)
Sets the name filters to apply against the existing files.
static const char *const filters[3]

◆ setIconProvider()

void QFileSystemModel::setIconProvider ( QFileIconProvider provider)

Sets the provider of file icons for the directory model.

Definition at line 1491 of file qfilesystemmodel.cpp.

1492 {
1494  d->fileInfoGatherer.setIconProvider(provider);
1495  d->root.updateIcon(provider, QString());
1496 }
double d
Definition: qnumeric_p.h:62
The QFileSystemModel class provides a data model for the local filesystem.
The QString class provides a Unicode character string.
Definition: qstring.h:83
#define Q_D(Class)
Definition: qglobal.h:2482

◆ setNameFilterDisables()

void QFileSystemModel::setNameFilterDisables ( bool  enable)

Definition at line 1597 of file qfilesystemmodel.cpp.

Referenced by QFileDialogPrivate::createWidgets().

1598 {
1600  if (d->nameFilterDisables == enable)
1601  return;
1602  d->nameFilterDisables = enable;
1603  d->forceSort = true;
1604  d->delayedSort();
1605 }
double d
Definition: qnumeric_p.h:62
The QFileSystemModel class provides a data model for the local filesystem.
#define Q_D(Class)
Definition: qglobal.h:2482

◆ setNameFilters()

void QFileSystemModel::setNameFilters ( const QStringList filters)

Sets the name filters to apply against the existing files.

Definition at line 1616 of file qfilesystemmodel.cpp.

Referenced by QFileDialogPrivate::_q_useNameFilter(), and setFilter().

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 }
double d
Definition: qnumeric_p.h:62
The QFileSystemModel class provides a data model for the local filesystem.
QModelIndexList persistentIndexList() const
Returns the list of indexes stored as persistent indexes in the model.
The QRegExp class provides pattern matching using regular expressions.
Definition: qregexp.h:61
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
#define Q_D(Class)
Definition: qglobal.h:2482
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
CaseSensitivity
Definition: qnamespace.h:1451
The QPersistentModelIndex class is used to locate data in a data model.
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::Filters filter() const
Returns the filter specified for the directory model.
QString rootPath() const
The currently set root path.

◆ setReadOnly()

void QFileSystemModel::setReadOnly ( bool  enable)

Definition at line 1576 of file qfilesystemmodel.cpp.

Referenced by QFileDialogPrivate::createWidgets().

1577 {
1579  d->readOnly = enable;
1580 }
double d
Definition: qnumeric_p.h:62
The QFileSystemModel class provides a data model for the local filesystem.
#define Q_D(Class)
Definition: qglobal.h:2482

◆ setResolveSymlinks()

void QFileSystemModel::setResolveSymlinks ( bool  enable)

Definition at line 1552 of file qfilesystemmodel.cpp.

1553 {
1555  d->fileInfoGatherer.setResolveSymlinks(enable);
1556 }
double d
Definition: qnumeric_p.h:62
The QFileSystemModel class provides a data model for the local filesystem.
#define Q_D(Class)
Definition: qglobal.h:2482

◆ setRootPath()

QModelIndex QFileSystemModel::setRootPath ( const QString newPath)

Sets the directory that is being watched by the model to newPath by installing a file system watcher on it.

Any changes to files and directories within this directory will be reflected in the model.

If the path is changed, the rootPathChanged() signal will be emitted.

Note
This function does not change the structure of the model or modify the data available to views. In other words, the "root" of the model is not changed to include only files and directories within the directory specified by newPath in the file system.

Definition at line 1405 of file qfilesystemmodel.cpp.

Referenced by QUnixPrintWidgetPrivate::QUnixPrintWidgetPrivate().

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 }
The QDir class provides access to directory structures and their contents.
Definition: qdir.h:58
double d
Definition: qnumeric_p.h:62
The QFileSystemModel class provides a data model for the local filesystem.
void rootPathChanged(const QString &newPath)
This signal is emitted whenever the root path has been changed to a newPath.
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
void fetchMore(const QModelIndex &parent)
Reimplemented Function
The QString class provides a Unicode character string.
Definition: qstring.h:83
#define Q_D(Class)
Definition: qglobal.h:2482
static bool isEmpty(const char *str)
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
#define emit
Definition: qobjectdefs.h:76
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
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
QString rootPath() const
The currently set root path.

◆ size()

qint64 QFileSystemModel::size ( const QModelIndex index) const

Returns the size in bytes of index.

If the file does not exist, 0 is returned.

Definition at line 557 of file qfilesystemmodel.cpp.

Referenced by QFileSystemModelPrivate::size().

558 {
559  Q_D(const QFileSystemModel);
560  if (!index.isValid())
561  return 0;
562  return d->node(index)->size();
563 }
double d
Definition: qnumeric_p.h:62
The QFileSystemModel class provides a data model for the local filesystem.
#define Q_D(Class)
Definition: qglobal.h:2482
bool isValid() const
Returns true if this model index is valid; otherwise returns false.

◆ sort()

void QFileSystemModel::sort ( int  column,
Qt::SortOrder  order = Qt::AscendingOrder 
)
virtual

Reimplemented Function

Reimplemented from QAbstractItemModel.

Definition at line 1193 of file qfilesystemmodel.cpp.

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 }
double d
Definition: qnumeric_p.h:62
The QFileSystemModel class provides a data model for the local filesystem.
QModelIndexList persistentIndexList() const
Returns the list of indexes stored as persistent indexes in the model.
QModelIndex sibling(int row, int column) const
Returns the sibling at row and column.
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
#define Q_D(Class)
Definition: qglobal.h:2482
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...
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
void layoutAboutToBeChanged()
This signal is emitted just before the layout of a model is changed.
int row() const
Returns the row this model index refers to.
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
void layoutChanged()
This signal is emitted whenever the layout of items exposed by the model has changed; for example...
The QModelIndex class is used to locate data in a data model.
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const
Reimplemented Function
QString rootPath() const
The currently set root path.
int column() const
Returns the column this model index refers to.

◆ supportedDropActions()

Qt::DropActions QFileSystemModel::supportedDropActions ( ) const
virtual

Reimplemented Function

Reimplemented from QAbstractItemModel.

Definition at line 1304 of file qfilesystemmodel.cpp.

◆ timerEvent()

void QFileSystemModel::timerEvent ( QTimerEvent event)
protectedvirtual

Reimplemented Function

Reimplemented from QObject.

Definition at line 518 of file qfilesystemmodel.cpp.

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 }
double d
Definition: qnumeric_p.h:62
The QFileSystemModel class provides a data model for the local filesystem.
#define Q_D(Class)
Definition: qglobal.h:2482
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
int timerId() const
Returns the unique timer identifier, which is the same identifier as returned from QObject::startTime...
Definition: qcoreevent.h:346

◆ type()

QString QFileSystemModel::type ( const QModelIndex index) const

Returns the type of file index such as "Directory" or "JPEG file".

Definition at line 568 of file qfilesystemmodel.cpp.

569 {
570  Q_D(const QFileSystemModel);
571  if (!index.isValid())
572  return QString();
573  return d->node(index)->type();
574 }
double d
Definition: qnumeric_p.h:62
The QFileSystemModel class provides a data model for the local filesystem.
The QString class provides a Unicode character string.
Definition: qstring.h:83
#define Q_D(Class)
Definition: qglobal.h:2482
bool isValid() const
Returns true if this model index is valid; otherwise returns false.

Friends and Related Functions

◆ QFileDialogPrivate

friend class QFileDialogPrivate
friend

Definition at line 163 of file qfilesystemmodel.h.

Properties

◆ nameFilterDisables

bool QFileSystemModel::nameFilterDisables
private

Whether files that don't pass the name filter are hidden or disabled.

This property is true by default

Definition at line 68 of file qfilesystemmodel.h.

◆ readOnly

QFileSystemModel::readOnly
private

Whether the directory model allows writing to the file system.

If this property is set to false, the directory model will allow renaming, copying and deleting of files and directories.

This property is true by default

Definition at line 67 of file qfilesystemmodel.h.

◆ resolveSymlinks

bool QFileSystemModel::resolveSymlinks
private

Whether the directory model should resolve symbolic links.

This is only relevant on operating systems that support symbolic links.

By default, this property is false.

Definition at line 66 of file qfilesystemmodel.h.


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