Qt 4.8
Public Types | Public Slots | Public Functions | Protected Functions | Properties | Friends | List of all members
QDirModel Class Reference

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

#include <qdirmodel.h>

Inheritance diagram for QDirModel:
QAbstractItemModel QObject

Public Types

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

Public Slots

void refresh (const QModelIndex &parent=QModelIndex())
 QDirModel caches file information. More...
 
- 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...
 

Public Functions

int columnCount (const QModelIndex &parent=QModelIndex()) const
 Returns the number of columns in the parent model item. More...
 
QVariant data (const QModelIndex &index, int role=Qt::DisplayRole) const
 Returns the data for the model item index with the given role. 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...
 
QIcon fileIcon (const QModelIndex &index) const
 Returns the icons for the item stored in the model under the given index. More...
 
QFileInfo fileInfo (const QModelIndex &index) const
 Returns the file information for the specified model index. More...
 
QString fileName (const QModelIndex &index) const
 Returns the name of the item stored in the model under the index given. 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 specification for the directory model. More...
 
Qt::ItemFlags flags (const QModelIndex &index) const
 Returns the item flags for the given index in the model. More...
 
bool hasChildren (const QModelIndex &index=QModelIndex()) const
 Returns true if the parent model item has children; otherwise returns false. More...
 
QVariant headerData (int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const
 Returns the data stored under the given role for the specified section of the header with the given orientation. More...
 
QFileIconProvidericonProvider () const
 Returns the file icon provider for this directory model. More...
 
QModelIndex index (int row, int column, const QModelIndex &parent=QModelIndex()) const
 Returns the model item index for the item in the parent with the given row and column. More...
 
QModelIndex index (const QString &path, int column=0) const
 Returns the model item index for the given path. More...
 
bool isDir (const QModelIndex &index) const
 Returns true if the model item index represents a directory; otherwise returns false. More...
 
bool isReadOnly () const
 
bool lazyChildCount () const
 
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 item. More...
 
QStringList nameFilters () const
 Returns a list of filters applied to the names in the model. More...
 
QModelIndex parent (const QModelIndex &child) const
 Return the parent of the given child model item. More...
 
 QDirModel (const QStringList &nameFilters, QDir::Filters filters, QDir::SortFlags sort, QObject *parent=0)
 Constructs a new directory model with the given parent. More...
 
 QDirModel (QObject *parent=0)
 Constructs a directory model with the given parent. More...
 
bool remove (const QModelIndex &index)
 Removes the model item index from the directory model and deletes the corresponding file from the file system, returning true if successful. More...
 
bool resolveSymlinks () const
 
bool rmdir (const QModelIndex &index)
 Removes the directory corresponding to the model item index in the directory model and deletes the corresponding directory from the file system, returning true if successful. More...
 
int rowCount (const QModelIndex &parent=QModelIndex()) const
 Returns the number of rows in the parent model item. More...
 
bool setData (const QModelIndex &index, const QVariant &value, int role=Qt::EditRole)
 Sets the data for the model item index with the given role to the data referenced by the value. 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 setLazyChildCount (bool enable)
 
void setNameFilters (const QStringList &filters)
 Sets the name filters for the directory model. More...
 
void setReadOnly (bool enable)
 
void setResolveSymlinks (bool enable)
 
void setSorting (QDir::SortFlags sort)
 Sets the directory model's sorting order to that specified by sort. More...
 
void sort (int column, Qt::SortOrder order=Qt::AscendingOrder)
 Sort the model items in the column using the order given. More...
 
QDir::SortFlags sorting () const
 Returns the sorting method used for the directory model. More...
 
Qt::DropActions supportedDropActions () const
 Returns the drop actions supported by this model. More...
 
 ~QDirModel ()
 Destroys this directory 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...
 
virtual bool canFetchMore (const QModelIndex &parent) const
 Returns true if there is more data available for parent; otherwise returns false. More...
 
virtual void fetchMore (const QModelIndex &parent)
 Fetches any available data for the items with the parent specified by the parent 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 event (QEvent *)
 This virtual function receives events to an object and should return true if the event e was recognized and processed. 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

 QDirModel (QDirModelPrivate &, QObject *parent=0)
 
- 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
 
virtual void timerEvent (QTimerEvent *)
 This event handler can be reimplemented in a subclass to receive timer events for the object. More...
 

Properties

bool lazyChildCount
 Whether the directory model optimizes the hasChildren function to only check if the item is a directory. 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

- 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...
 
- 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 QDirModel class provides a data model for the local filesystem.

The usage of QDirModel is not recommended anymore. The QFileSystemModel class is a more performant alternative.

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 filer.

QDirModel keeps a cache with file information. The cache needs to be updated with refresh().

QDirModel 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() and isDir() functions provide information about the underlying files and directories related to items in the model.

Directories can be created and removed using mkdir(), rmdir(), and the model will be automatically updated to take the changes into account.

Note
QDirModel requires an instance of a GUI application.
See also
nameFilters(), setFilter(), filter(), QListView, QTreeView, QFileSystemModel, {Dir View Example}, {Model Classes}

Definition at line 59 of file qdirmodel.h.

Enumerations

◆ Roles

  • FileIconRole
  • FilePathRole
  • FileNameRole
Enumerator
FileIconRole 
FilePathRole 
FileNameRole 

Definition at line 67 of file qdirmodel.h.

Constructors and Destructors

◆ QDirModel() [1/3]

QDirModel::QDirModel ( const QStringList nameFilters,
QDir::Filters  filters,
QDir::SortFlags  sort,
QObject parent = 0 
)

Constructs a new directory model with the given parent.

Only those files matching the nameFilters and the filters are included in the model. The sort order is given by the sort flags.

Definition at line 229 of file qdirmodel.cpp.

233  : QAbstractItemModel(*new QDirModelPrivate, parent)
234 {
235  Q_D(QDirModel);
236  // we always start with QDir::drives()
237  d->nameFilters = nameFilters.isEmpty() ? QStringList(QLatin1String("*")) : nameFilters;
238  d->filters = filters;
239  d->sort = sort;
240  d->root.parent = 0;
241  d->root.info = QFileInfo();
242  d->clear(&d->root);
243 }
double d
Definition: qnumeric_p.h:62
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
#define Q_D(Class)
Definition: qglobal.h:2482
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
static const char *const filters[3]
void sort(int column, Qt::SortOrder order=Qt::AscendingOrder)
Sort the model items in the column using the order given.
Definition: qdirmodel.cpp:509
QAbstractItemModel(QObject *parent=0)
Constructs an abstract item model with the given parent.
The QFileInfo class provides system-independent file information.
Definition: qfileinfo.h:60
The QDirModel class provides a data model for the local filesystem.
Definition: qdirmodel.h:59

◆ QDirModel() [2/3]

QDirModel::QDirModel ( QObject parent = 0)
explicit

Constructs a directory model with the given parent.

Definition at line 249 of file qdirmodel.cpp.

250  : QAbstractItemModel(*new QDirModelPrivate, parent)
251 {
252  Q_D(QDirModel);
253  d->init();
254 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
QAbstractItemModel(QObject *parent=0)
Constructs an abstract item model with the given parent.
The QDirModel class provides a data model for the local filesystem.
Definition: qdirmodel.h:59

◆ ~QDirModel()

QDirModel::~QDirModel ( )

Destroys this directory model.

Definition at line 270 of file qdirmodel.cpp.

271 {
272 
273 }

◆ QDirModel() [3/3]

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

Definition at line 259 of file qdirmodel.cpp.

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

Functions

◆ columnCount()

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

Returns the number of columns in the parent model item.

Implements QAbstractItemModel.

Definition at line 355 of file qdirmodel.cpp.

Referenced by index().

356 {
357  if (parent.column() > 0)
358  return 0;
359  return 4;
360 }
int column() const
Returns the column this model index refers to.

◆ data()

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

Returns the data for the model item index with the given role.

Implements QAbstractItemModel.

Definition at line 365 of file qdirmodel.cpp.

Referenced by QDeclarativeFolderListModel::data(), mimeData(), QDirModelPrivate::restorePersistentIndexes(), and QDirModelPrivate::savePersistentIndexes().

366 {
367  Q_D(const QDirModel);
368  if (!d->indexValid(index))
369  return QVariant();
370 
371  if (role == Qt::DisplayRole || role == Qt::EditRole) {
372  switch (index.column()) {
373  case 0: return d->name(index);
374  case 1: return d->size(index);
375  case 2: return d->type(index);
376  case 3: return d->time(index);
377  default:
378  qWarning("data: invalid display value column %d", index.column());
379  return QVariant();
380  }
381  }
382 
383  if (index.column() == 0) {
384  if (role == FileIconRole)
385  return fileIcon(index);
386  if (role == FilePathRole)
387  return filePath(index);
388  if (role == FileNameRole)
389  return fileName(index);
390  }
391 
392  if (index.column() == 1 && Qt::TextAlignmentRole == role) {
393  return Qt::AlignRight;
394  }
395  return QVariant();
396 }
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
QString fileName(const QModelIndex &index) const
Returns the name of the item stored in the model under the index given.
Definition: qdirmodel.cpp:1121
QString filePath(const QModelIndex &index) const
Returns the path of the item stored in the model under the index given.
Definition: qdirmodel.cpp:1103
#define Q_D(Class)
Definition: qglobal.h:2482
Q_CORE_EXPORT void qWarning(const char *,...)
The QDirModel class provides a data model for the local filesystem.
Definition: qdirmodel.h:59
QIcon fileIcon(const QModelIndex &index) const
Returns the icons for the item stored in the model under the given index.
Definition: qdirmodel.cpp:1139
int column() const
Returns the column this model index refers to.

◆ dropMimeData()

bool QDirModel::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 574 of file qdirmodel.cpp.

576 {
577  Q_D(QDirModel);
578  if (!d->indexValid(parent) || isReadOnly())
579  return false;
580 
581  bool success = true;
582  QString to = filePath(parent) + QDir::separator();
583  QModelIndex _parent = parent;
584 
585  QList<QUrl> urls = data->urls();
587 
588  switch (action) {
589  case Qt::CopyAction:
590  for (; it != urls.constEnd(); ++it) {
591  QString path = (*it).toLocalFile();
592  success = QFile::copy(path, to + QFileInfo(path).fileName()) && success;
593  }
594  break;
595  case Qt::LinkAction:
596  for (; it != urls.constEnd(); ++it) {
597  QString path = (*it).toLocalFile();
598  success = QFile::link(path, to + QFileInfo(path).fileName()) && success;
599  }
600  break;
601  case Qt::MoveAction:
602  for (; it != urls.constEnd(); ++it) {
603  QString path = (*it).toLocalFile();
604  if (QFile::copy(path, to + QFileInfo(path).fileName())
605  && QFile::remove(path)) {
606  QModelIndex idx=index(QFileInfo(path).path());
607  if (idx.isValid()) {
608  refresh(idx);
609  //the previous call to refresh may invalidate the _parent. so recreate a new QModelIndex
610  _parent = index(to);
611  }
612  } else {
613  success = false;
614  }
615  }
616  break;
617  default:
618  return false;
619  }
620 
621  if (success)
622  refresh(_parent);
623 
624  return success;
625 }
double d
Definition: qnumeric_p.h:62
QString fileName(const QModelIndex &index) const
Returns the name of the item stored in the model under the index given.
Definition: qdirmodel.cpp:1121
QString filePath(const QModelIndex &index) const
Returns the path of the item stored in the model under the index given.
Definition: qdirmodel.cpp:1103
#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
void refresh(const QModelIndex &parent=QModelIndex())
QDirModel caches file information.
Definition: qdirmodel.cpp:829
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
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 isReadOnly() const
Definition: qdirmodel.cpp:788
QObject * parent() const
Returns a pointer to the parent object.
Definition: qobject.h:273
The QModelIndex class is used to locate data in a data model.
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const
Returns the model item index for the item in the parent with the given row and column.
Definition: qdirmodel.cpp:281
bool copy(const QString &newName)
Copies the file currently specified by fileName() to a file called newName.
Definition: qfile.cpp:926
bool remove()
Removes the file specified by fileName().
Definition: qfile.cpp:715
The QFileInfo class provides system-independent file information.
Definition: qfileinfo.h:60
The QDirModel class provides a data model for the local filesystem.
Definition: qdirmodel.h:59
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

◆ fileIcon()

QIcon QDirModel::fileIcon ( const QModelIndex index) const

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

Definition at line 1139 of file qdirmodel.cpp.

Referenced by data().

1140 {
1141  Q_D(const QDirModel);
1142  if (!d->indexValid(index))
1143  return d->iconProvider->icon(QFileIconProvider::Computer);
1144  QDirModelPrivate::QDirNode *node = d->node(index);
1145  if (node->icon.isNull())
1146  node->icon = d->iconProvider->icon(node->info);
1147  return node->icon;
1148 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
bool isNull() const
Returns true if the icon is empty; otherwise returns false.
Definition: qicon.cpp:769
The QDirModel class provides a data model for the local filesystem.
Definition: qdirmodel.h:59

◆ fileInfo()

QFileInfo QDirModel::fileInfo ( const QModelIndex index) const

Returns the file information for the specified model index.

Note: If the model index represents a symbolic link in the underlying filing system, the file information returned will contain information about the symbolic link itself, regardless of whether resolveSymlinks is enabled or not.

See also
QFileInfo::symLinkTarget()

Definition at line 1161 of file qdirmodel.cpp.

Referenced by fileName(), filePath(), and flags().

1162 {
1163  Q_D(const QDirModel);
1164  Q_ASSERT(d->indexValid(index));
1165 
1166  QDirModelPrivate::QDirNode *node = d->node(index);
1167  return node->info;
1168 }
double d
Definition: qnumeric_p.h:62
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
#define Q_D(Class)
Definition: qglobal.h:2482
The QDirModel class provides a data model for the local filesystem.
Definition: qdirmodel.h:59

◆ fileName()

QString QDirModel::fileName ( const QModelIndex index) const

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

Definition at line 1121 of file qdirmodel.cpp.

Referenced by data(), and dropMimeData().

1122 {
1123  Q_D(const QDirModel);
1124  if (!d->indexValid(index))
1125  return QString();
1126  QFileInfo info = fileInfo(index);
1127  if (info.isRoot())
1128  return info.absoluteFilePath();
1129  if (d->resolveSymlinks && info.isSymLink())
1130  info = d->resolvedInfo(info);
1131  return info.fileName();
1132 }
double d
Definition: qnumeric_p.h:62
static mach_timebase_info_data_t info
QString fileName() const
Returns the name of the file, excluding the path.
Definition: qfileinfo.cpp:726
QString absoluteFilePath() const
Returns an absolute path including the file name.
Definition: qfileinfo.cpp:534
The QString class provides a Unicode character string.
Definition: qstring.h:83
#define Q_D(Class)
Definition: qglobal.h:2482
bool isRoot() const
Returns true if the object points to a directory or to a symbolic link to a directory, and that directory is the root directory; otherwise returns false.
Definition: qfileinfo.cpp:1062
QFileInfo fileInfo(const QModelIndex &index) const
Returns the file information for the specified model index.
Definition: qdirmodel.cpp:1161
bool isSymLink() const
Returns true if this object points to a symbolic link (or to a shortcut on Windows); otherwise return...
Definition: qfileinfo.cpp:1044
The QFileInfo class provides system-independent file information.
Definition: qfileinfo.h:60
The QDirModel class provides a data model for the local filesystem.
Definition: qdirmodel.h:59

◆ filePath()

QString QDirModel::filePath ( const QModelIndex index) const

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

Definition at line 1103 of file qdirmodel.cpp.

Referenced by data(), dropMimeData(), and mimeData().

1104 {
1105  Q_D(const QDirModel);
1106  if (d->indexValid(index)) {
1107  QFileInfo fi = fileInfo(index);
1108  if (d->resolveSymlinks && fi.isSymLink())
1109  fi = d->resolvedInfo(fi);
1110  return QDir::cleanPath(fi.absoluteFilePath());
1111  }
1112  return QString(); // root path
1113 }
double d
Definition: qnumeric_p.h:62
QString absoluteFilePath() const
Returns an absolute path including the file name.
Definition: qfileinfo.cpp:534
The QString class provides a Unicode character string.
Definition: qstring.h:83
#define Q_D(Class)
Definition: qglobal.h:2482
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
QFileInfo fileInfo(const QModelIndex &index) const
Returns the file information for the specified model index.
Definition: qdirmodel.cpp:1161
bool isSymLink() const
Returns true if this object points to a symbolic link (or to a shortcut on Windows); otherwise return...
Definition: qfileinfo.cpp:1044
The QFileInfo class provides system-independent file information.
Definition: qfileinfo.h:60
The QDirModel class provides a data model for the local filesystem.
Definition: qdirmodel.h:59

◆ filter()

QDir::Filters QDirModel::filter ( ) const

Returns the filter specification for the directory model.

See also
QDir::Filters

Definition at line 712 of file qdirmodel.cpp.

Referenced by QDeclarativeFolderListModel::handleDataChanged(), QDeclarativeFolderListModel::setShowDirs(), QDeclarativeFolderListModel::setShowDotAndDotDot(), and QDeclarativeFolderListModel::setShowOnlyReadable().

713 {
714  Q_D(const QDirModel);
715  return d->filters;
716 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QDirModel class provides a data model for the local filesystem.
Definition: qdirmodel.h:59

◆ flags()

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

Returns the item flags for the given index in the model.

See also
Qt::ItemFlags

Reimplemented from QAbstractItemModel.

Definition at line 486 of file qdirmodel.cpp.

Referenced by setData().

487 {
488  Q_D(const QDirModel);
489  Qt::ItemFlags flags = QAbstractItemModel::flags(index);
490  if (!d->indexValid(index))
491  return flags;
492  flags |= Qt::ItemIsDragEnabled;
493  if (d->readOnly)
494  return flags;
495  QDirModelPrivate::QDirNode *node = d->node(index);
496  if ((index.column() == 0) && node->info.isWritable()) {
497  flags |= Qt::ItemIsEditable;
498  if (fileInfo(index).isDir()) // is directory and is editable
499  flags |= Qt::ItemIsDropEnabled;
500  }
501  return flags;
502 }
double d
Definition: qnumeric_p.h:62
Qt::ItemFlags flags(const QModelIndex &index) const
Returns the item flags for the given index in the model.
Definition: qdirmodel.cpp:486
#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 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 file information for the specified model index.
Definition: qdirmodel.cpp:1161
The QDirModel class provides a data model for the local filesystem.
Definition: qdirmodel.h:59
bool isWritable() const
Returns true if the user can write to the file; otherwise returns false.
Definition: qfileinfo.cpp:914
int column() const
Returns the column this model index refers to.

◆ hasChildren()

bool QDirModel::hasChildren ( const QModelIndex index = QModelIndex()) const
virtual

Returns true if the parent model item has children; otherwise returns false.

Reimplemented from QAbstractItemModel.

Definition at line 465 of file qdirmodel.cpp.

466 {
467  Q_D(const QDirModel);
468  if (parent.column() > 0)
469  return false;
470 
471  if (!parent.isValid()) // the invalid index is the "My Computer" item
472  return true; // the drives
473  QDirModelPrivate::QDirNode *p = d->node(parent);
474  Q_ASSERT(p);
475 
476  if (d->lazyChildCount) // optimization that only checks for children if the node has been populated
477  return p->info.isDir();
478  return p->info.isDir() && rowCount(parent) > 0;
479 }
double d
Definition: qnumeric_p.h:62
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
#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
QObject * parent() const
Returns a pointer to the parent object.
Definition: qobject.h:273
int rowCount(const QModelIndex &parent=QModelIndex()) const
Returns the number of rows in the parent model item.
Definition: qdirmodel.cpp:331
The QDirModel class provides a data model for the local filesystem.
Definition: qdirmodel.h:59

◆ headerData()

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

Returns the data stored under the given role for the specified section of the header with the given orientation.

Reimplemented from QAbstractItemModel.

Definition at line 435 of file qdirmodel.cpp.

436 {
437  if (orientation == Qt::Horizontal) {
438  if (role != Qt::DisplayRole)
439  return QVariant();
440  switch (section) {
441  case 0: return tr("Name");
442  case 1: return tr("Size");
443  case 2: return
444 #ifdef Q_OS_MAC
445  tr("Kind", "Match OS X Finder");
446 #else
447  tr("Type", "All other platforms");
448 #endif
449  // Windows - Type
450  // OS X - Kind
451  // Konqueror - File Type
452  // Nautilus - Type
453  case 3: return tr("Date Modified");
454  default: return QVariant();
455  }
456  }
457  return QAbstractItemModel::headerData(section, orientation, role);
458 }
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)
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.

◆ iconProvider()

QFileIconProvider * QDirModel::iconProvider ( ) const

Returns the file icon provider for this directory model.

Definition at line 653 of file qdirmodel.cpp.

Referenced by QDirModelPrivate::type().

654 {
655  Q_D(const QDirModel);
656  return d->iconProvider;
657 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QDirModel class provides a data model for the local filesystem.
Definition: qdirmodel.h:59

◆ index() [1/2]

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

Returns the model item index for the item in the parent with the given row and column.

Implements QAbstractItemModel.

Definition at line 281 of file qdirmodel.cpp.

Referenced by QDeclarativeFolderListModel::data(), dropMimeData(), index(), QDeclarativeFolderListModel::isFolder(), mkdir(), QDeclarativeFolderListModel::refresh(), QDirModelPrivate::savePersistentIndexes(), and QDeclarativeFolderListModel::setFolder().

282 {
283  Q_D(const QDirModel);
284  // note that rowCount does lazy population
285  if (column < 0 || column >= columnCount(parent) || row < 0 || parent.column() > 0)
286  return QModelIndex();
287  // make sure the list of children is up to date
288  QDirModelPrivate::QDirNode *p = (d->indexValid(parent) ? d->node(parent) : &d->root);
289  Q_ASSERT(p);
290  if (!p->populated)
291  d->populate(p); // populate without stat'ing
292  if (row >= p->children.count())
293  return QModelIndex();
294  // now get the internal pointer for the index
295  QDirModelPrivate::QDirNode *n = d->node(row, d->indexValid(parent) ? p : 0);
296  Q_ASSERT(n);
297 
298  return createIndex(row, column, n);
299 }
double d
Definition: qnumeric_p.h:62
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
QVector< QDirNode > children
Definition: qdirmodel.cpp:81
int columnCount(const QModelIndex &parent=QModelIndex()) const
Returns the number of columns in the parent model item.
Definition: qdirmodel.cpp:355
The QModelIndex class is used to locate data in a data model.
The QDirModel class provides a data model for the local filesystem.
Definition: qdirmodel.h:59
int column() const
Returns the column this model index refers to.

◆ index() [2/2]

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

Returns the model item index for the given path.

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 863 of file qdirmodel.cpp.

864 {
865  Q_D(const QDirModel);
866 
867  if (path.isEmpty() || path == QCoreApplication::translate("QFileDialog", "My Computer"))
868  return QModelIndex();
869 
870  QString absolutePath = QDir(path).absolutePath();
871 #if (defined(Q_OS_WIN) && !defined(Q_OS_WINCE)) || defined(Q_OS_SYMBIAN)
872  absolutePath = absolutePath.toLower();
873 #endif
874 #if defined(Q_OS_WIN) && !defined(Q_OS_WINCE)
875  // On Windows, "filename......." and "filename" are equivalent
876  if (absolutePath.endsWith(QLatin1Char('.'))) {
877  int i;
878  for (i = absolutePath.count() - 1; i >= 0; --i) {
879  if (absolutePath.at(i) != QLatin1Char('.'))
880  break;
881  }
882  absolutePath = absolutePath.left(i+1);
883  }
884 #endif
885 
886  QStringList pathElements = absolutePath.split(QLatin1Char('/'), QString::SkipEmptyParts);
887  if ((pathElements.isEmpty() || !QFileInfo(path).exists())
888 #if !defined(Q_OS_WIN) || defined(Q_OS_WINCE)
889  && path != QLatin1String("/")
890 #endif
891  )
892  return QModelIndex();
893 
894  QModelIndex idx; // start with "My Computer"
895  if (!d->root.populated) // make sure the root is populated
896  d->populate(&d->root);
897 
898 #if defined(Q_OS_WIN) && !defined(Q_OS_WINCE)
899  if (absolutePath.startsWith(QLatin1String("//"))) { // UNC path
900  QString host = pathElements.first();
901  int r = 0;
902  for (; r < d->root.children.count(); ++r)
903  if (d->root.children.at(r).info.fileName() == host)
904  break;
905  bool childAppended = false;
906  if (r >= d->root.children.count() && d->allowAppendChild) {
907  d->appendChild(&d->root, QLatin1String("//") + host);
908  childAppended = true;
909  }
910  idx = index(r, 0, QModelIndex());
911  pathElements.pop_front();
912  if (childAppended)
913  emit const_cast<QDirModel*>(this)->layoutChanged();
914  } else
915 #endif
916 #if (defined(Q_OS_WIN) && !defined(Q_OS_WINCE)) || defined(Q_OS_SYMBIAN)
917  if (pathElements.at(0).endsWith(QLatin1Char(':'))) {
918  pathElements[0] += QLatin1Char('/');
919  }
920 #else
921  // add the "/" item, since it is a valid path element on unix
922  pathElements.prepend(QLatin1String("/"));
923 #endif
924 
925  for (int i = 0; i < pathElements.count(); ++i) {
926  Q_ASSERT(!pathElements.at(i).isEmpty());
927  QString element = pathElements.at(i);
928  QDirModelPrivate::QDirNode *parent = (idx.isValid() ? d->node(idx) : &d->root);
929 
930  Q_ASSERT(parent);
931  if (!parent->populated)
932  d->populate(parent);
933 
934  // search for the element in the child nodes first
935  int row = -1;
936  for (int j = parent->children.count() - 1; j >= 0; --j) {
937  const QFileInfo& fi = parent->children.at(j).info;
938  QString childFileName;
939  childFileName = idx.isValid() ? fi.fileName() : fi.absoluteFilePath();
940 #if (defined(Q_OS_WIN) && !defined(Q_OS_WINCE)) || defined(Q_OS_SYMBIAN)
941  childFileName = childFileName.toLower();
942 #endif
943  if (childFileName == element) {
944  if (i == pathElements.count() - 1)
945  parent->children[j].stat = true;
946  row = j;
947  break;
948  }
949  }
950 
951  // we couldn't find the path element, we create a new node since we _know_ that the path is valid
952  if (row == -1) {
953 #if defined(Q_OS_WINCE)
954  QString newPath;
955  if (parent->info.isRoot())
956  newPath = parent->info.absoluteFilePath() + element;
957  else
958  newPath = parent->info.absoluteFilePath() + QLatin1Char('/') + element;
959 #else
960  QString newPath = parent->info.absoluteFilePath() + QLatin1Char('/') + element;
961 #endif
962  if (!d->allowAppendChild || !QFileInfo(newPath).isDir())
963  return QModelIndex();
964  d->appendChild(parent, newPath);
965  row = parent->children.count() - 1;
966  if (i == pathElements.count() - 1) // always stat children of the last element
967  parent->children[row].stat = true;
968  emit const_cast<QDirModel*>(this)->layoutChanged();
969  }
970 
971  Q_ASSERT(row >= 0);
972  idx = createIndex(row, 0, static_cast<void*>(&parent->children[row]));
973  Q_ASSERT(idx.isValid());
974  }
975 
976  if (column != 0)
977  return idx.sibling(idx.row(), column);
978  return idx;
979 }
The QDir class provides access to directory structures and their contents.
Definition: qdir.h:58
double d
Definition: qnumeric_p.h:62
const QChar at(int i) const
Returns the character at the given index position in the string.
Definition: qstring.h:698
QModelIndex sibling(int row, int column) const
Returns the sibling at row and column.
QString fileName() const
Returns the name of the file, excluding the path.
Definition: qfileinfo.cpp:726
QModelIndex createIndex(int row, int column, void *data=0) const
Creates a model index for the given row and column with the internal pointer ptr. ...
bool 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
QString absoluteFilePath() const
Returns an absolute path including the file name.
Definition: qfileinfo.cpp:534
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
bool exists() const
Returns true if the file exists; otherwise returns false.
Definition: qfileinfo.cpp:675
void pop_front()
This function is provided for STL compatibility.
Definition: qlist.h:302
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
#define Q_D(Class)
Definition: qglobal.h:2482
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
static QString translate(const char *context, const char *key, const char *disambiguation=0, Encoding encoding=CodecForTr)
QVector< QDirNode > children
Definition: qdirmodel.cpp:81
QString left(int n) const Q_REQUIRED_RESULT
Returns a substring that contains the n leftmost characters of the string.
Definition: qstring.cpp:3664
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
int row() const
Returns the row this model index refers to.
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
#define emit
Definition: qobjectdefs.h:76
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
Definition: qstring.h:654
void layoutChanged()
This signal is emitted whenever the layout of items exposed by the model has changed; for example...
bool isValid() const
Returns true if this model index is valid; otherwise returns false.
int count() const
Definition: qstring.h:103
bool isDir(const QModelIndex &index) const
Returns true if the model item index represents a directory; otherwise returns false.
Definition: qdirmodel.cpp:986
T & first()
Returns a reference to the first item in the list.
Definition: qlist.h:282
bool isRoot() const
Returns true if the object points to a directory or to a symbolic link to a directory, and that directory is the root directory; otherwise returns false.
Definition: qfileinfo.cpp:1062
QObject * parent() const
Returns a pointer to the parent object.
Definition: qobject.h:273
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.
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const
Returns the model item index for the item in the parent with the given row and column.
Definition: qdirmodel.cpp:281
#define Q_OS_WIN
Definition: qglobal.h:270
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
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
The QDirModel class provides a data model for the local filesystem.
Definition: qdirmodel.h:59
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55

◆ isDir()

bool QDirModel::isDir ( const QModelIndex index) const

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

Definition at line 986 of file qdirmodel.cpp.

Referenced by index(), QDeclarativeFolderListModel::isFolder(), QDirModelPrivate::node(), and QDeclarativeFolderListModel::setFolder().

987 {
988  Q_D(const QDirModel);
989  Q_ASSERT(d->indexValid(index));
990  QDirModelPrivate::QDirNode *node = d->node(index);
991  return node->info.isDir();
992 }
double d
Definition: qnumeric_p.h:62
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
#define Q_D(Class)
Definition: qglobal.h:2482
The QDirModel class provides a data model for the local filesystem.
Definition: qdirmodel.h:59

◆ isReadOnly()

bool QDirModel::isReadOnly ( ) const

Definition at line 788 of file qdirmodel.cpp.

Referenced by dropMimeData(), mkdir(), remove(), and rmdir().

789 {
790  Q_D(const QDirModel);
791  return d->readOnly;
792 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QDirModel class provides a data model for the local filesystem.
Definition: qdirmodel.h:59

◆ lazyChildCount()

bool QDirModel::lazyChildCount ( ) const

Referenced by setLazyChildCount().

◆ mimeData()

QMimeData * QDirModel::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 554 of file qdirmodel.cpp.

555 {
556  QList<QUrl> urls;
558  for (; it != indexes.end(); ++it)
559  if ((*it).column() == 0)
560  urls << QUrl::fromLocalFile(filePath(*it));
561  QMimeData *data = new QMimeData();
562  data->setUrls(urls);
563  return data;
564 }
QString filePath(const QModelIndex &index) const
Returns the path of the item stored in the model under the index given.
Definition: qdirmodel.cpp:1103
#define it(className, varName)
iterator begin()
Returns an STL-style iterator pointing to the first item in the list.
Definition: qlist.h:267
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
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const
Returns the data for the model item index with the given role.
Definition: qdirmodel.cpp:365
static QUrl fromLocalFile(const QString &localfile)
Returns a QUrl representation of localFile, interpreted as a local file.
Definition: qurl.cpp:6374

◆ mimeTypes()

QStringList QDirModel::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 540 of file qdirmodel.cpp.

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

◆ mkdir()

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

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

Definition at line 998 of file qdirmodel.cpp.

999 {
1000  Q_D(QDirModel);
1001  if (!d->indexValid(parent) || isReadOnly())
1002  return QModelIndex();
1003 
1004  QDirModelPrivate::QDirNode *p = d->node(parent);
1005  QString path = p->info.absoluteFilePath();
1006  // For the indexOf() method to work, the new directory has to be a direct child of
1007  // the parent directory.
1008 
1009  QDir newDir(name);
1010  QDir dir(path);
1011  if (newDir.isRelative())
1012  newDir = QDir(path + QLatin1Char('/') + name);
1013  QString childName = newDir.dirName(); // Get the singular name of the directory
1014  newDir.cdUp();
1015 
1016  if (newDir.absolutePath() != dir.absolutePath() || !dir.mkdir(name))
1017  return QModelIndex(); // nothing happened
1018 
1019  refresh(parent);
1020 
1021  QStringList entryList = d->entryList(path);
1022  int r = entryList.indexOf(childName);
1023  QModelIndex i = index(r, 0, parent); // return an invalid index
1024 
1025  return i;
1026 }
The QDir class provides access to directory structures and their contents.
Definition: qdir.h:58
double d
Definition: qnumeric_p.h:62
void refresh(const QModelIndex &parent=QModelIndex())
QDirModel caches file information.
Definition: qdirmodel.cpp:829
QString absoluteFilePath() const
Returns an absolute path including the file name.
Definition: qfileinfo.cpp:534
The QString class provides a Unicode character string.
Definition: qstring.h:83
#define Q_D(Class)
Definition: qglobal.h:2482
int indexOf(const QRegExp &rx, int from=0) const
Returns the index position of the first exact match of rx in the list, searching forward from index p...
Definition: qstringlist.h:195
const char * name
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
bool isReadOnly() const
Definition: qdirmodel.cpp:788
The QModelIndex class is used to locate data in a data model.
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const
Returns the model item index for the item in the parent with the given row and column.
Definition: qdirmodel.cpp:281
The QDirModel class provides a data model for the local filesystem.
Definition: qdirmodel.h:59
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55

◆ nameFilters()

QStringList QDirModel::nameFilters ( ) const

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

Definition at line 679 of file qdirmodel.cpp.

Referenced by QDirModelPrivate::children(), QDirModelPrivate::entryInfoList(), QDirModelPrivate::entryList(), QDirModelPrivate::init(), and QDirModel().

680 {
681  Q_D(const QDirModel);
682  return d->nameFilters;
683 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QDirModel class provides a data model for the local filesystem.
Definition: qdirmodel.h:59

◆ parent()

QObject * QDirModel::parent ( const QModelIndex child) const
virtual

Return the parent of the given child model item.

Warning
This function is not part of the public interface.

Implements QAbstractItemModel.

Definition at line 305 of file qdirmodel.cpp.

306 {
307  Q_D(const QDirModel);
308 
309  if (!d->indexValid(child))
310  return QModelIndex();
311  QDirModelPrivate::QDirNode *node = d->node(child);
312  QDirModelPrivate::QDirNode *par = (node ? node->parent : 0);
313  if (par == 0) // parent is the root node
314  return QModelIndex();
315 
316  // get the parent's row
318  par->parent ? par->parent->children : d->root.children;
319  Q_ASSERT(children.count() > 0);
320  int row = (par - &(children.at(0)));
321  Q_ASSERT(row >= 0);
322 
323  return createIndex(row, 0, par);
324 }
double d
Definition: qnumeric_p.h:62
int count(const T &t) const
Returns the number of occurrences of value in the vector.
Definition: qvector.h:742
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
QVector< QDirNode > children
Definition: qdirmodel.cpp:81
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
The QModelIndex class is used to locate data in a data model.
const QObjectList & children() const
Returns a list of child objects.
Definition: qobject.h:197
The QDirModel class provides a data model for the local filesystem.
Definition: qdirmodel.h:59

◆ refresh

void QDirModel::refresh ( const QModelIndex parent = QModelIndex())
slot

QDirModel caches file information.

This function updates the cache. The parent parameter is the directory from which the model is updated; the default value will update the model from root directory of the file system (the entire model).

Definition at line 829 of file qdirmodel.cpp.

Referenced by dropMimeData(), mkdir(), remove(), rmdir(), setFilter(), setNameFilters(), and setSorting().

830 {
831  Q_D(QDirModel);
832 
833  QDirModelPrivate::QDirNode *n = d->indexValid(parent) ? d->node(parent) : &(d->root);
834 
835  int rows = n->children.count();
836  if (rows == 0) {
838  n->stat = true; // make sure that next time we read all the info
839  n->populated = false;
841  return;
842  }
843 
845  d->savePersistentIndexes();
846  d->rowsAboutToBeRemoved(parent, 0, rows - 1);
847  n->stat = true; // make sure that next time we read all the info
848  d->clear(n);
849  d->rowsRemoved(parent, 0, rows - 1);
850  d->restorePersistentIndexes();
852 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
QVector< QDirNode > children
Definition: qdirmodel.cpp:81
void layoutAboutToBeChanged()
This signal is emitted just before the layout of a model is changed.
#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 QDirModel class provides a data model for the local filesystem.
Definition: qdirmodel.h:59

◆ remove()

bool QDirModel::remove ( const QModelIndex index)

Removes the model item index from the directory 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 1075 of file qdirmodel.cpp.

1076 {
1077  Q_D(QDirModel);
1078  if (!d->indexValid(index) || isReadOnly())
1079  return false;
1080 
1081  QDirModelPrivate::QDirNode *n = d_func()->node(index);
1082  if (n->info.isDir())
1083  return false;
1084 
1085  QModelIndex par = parent(index);
1086  QDirModelPrivate::QDirNode *p = d_func()->node(par);
1087  QDir dir = p->info.dir(); // parent dir
1088  QString path = n->info.absoluteFilePath();
1089  if (!dir.remove(path))
1090  return false;
1091 
1092  refresh(par);
1093 
1094  return true;
1095 }
The QDir class provides access to directory structures and their contents.
Definition: qdir.h:58
double d
Definition: qnumeric_p.h:62
QDir dir() const
Returns the path of the object&#39;s parent directory as a QDir object.
Definition: qfileinfo.cpp:861
void refresh(const QModelIndex &parent=QModelIndex())
QDirModel caches file information.
Definition: qdirmodel.cpp:829
QString absoluteFilePath() const
Returns an absolute path including the file name.
Definition: qfileinfo.cpp:534
The QString class provides a Unicode character string.
Definition: qstring.h:83
#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
bool isReadOnly() const
Definition: qdirmodel.cpp:788
QObject * parent() const
Returns a pointer to the parent object.
Definition: qobject.h:273
The QModelIndex class is used to locate data in a data model.
bool remove(const QString &fileName)
Removes the file, fileName.
Definition: qdir.cpp:1751
The QDirModel class provides a data model for the local filesystem.
Definition: qdirmodel.h:59

◆ resolveSymlinks()

bool QDirModel::resolveSymlinks ( ) const

◆ rmdir()

bool QDirModel::rmdir ( const QModelIndex index)

Removes the directory corresponding to the model item index in the directory 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 1040 of file qdirmodel.cpp.

1041 {
1042  Q_D(QDirModel);
1043  if (!d->indexValid(index) || isReadOnly())
1044  return false;
1045 
1046  QDirModelPrivate::QDirNode *n = d_func()->node(index);
1047  if (!n->info.isDir()) {
1048  qWarning("rmdir: the node is not a directory");
1049  return false;
1050  }
1051 
1052  QModelIndex par = parent(index);
1053  QDirModelPrivate::QDirNode *p = d_func()->node(par);
1054  QDir dir = p->info.dir(); // parent dir
1055  QString path = n->info.absoluteFilePath();
1056  if (!dir.rmdir(path))
1057  return false;
1058 
1059  refresh(par);
1060 
1061  return true;
1062 }
The QDir class provides access to directory structures and their contents.
Definition: qdir.h:58
double d
Definition: qnumeric_p.h:62
QDir dir() const
Returns the path of the object&#39;s parent directory as a QDir object.
Definition: qfileinfo.cpp:861
void refresh(const QModelIndex &parent=QModelIndex())
QDirModel caches file information.
Definition: qdirmodel.cpp:829
QString absoluteFilePath() const
Returns an absolute path including the file name.
Definition: qfileinfo.cpp:534
The QString class provides a Unicode character string.
Definition: qstring.h:83
#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
Q_CORE_EXPORT void qWarning(const char *,...)
bool isReadOnly() const
Definition: qdirmodel.cpp:788
QObject * parent() const
Returns a pointer to the parent object.
Definition: qobject.h:273
bool rmdir(const QString &dirName) const
Removes the directory specified by dirName.
Definition: qdir.cpp:1448
The QModelIndex class is used to locate data in a data model.
The QDirModel class provides a data model for the local filesystem.
Definition: qdirmodel.h:59

◆ rowCount()

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

Returns the number of rows in the parent model item.

Implements QAbstractItemModel.

Definition at line 331 of file qdirmodel.cpp.

Referenced by hasChildren(), QDeclarativeFolderListModel::inserted(), QDeclarativeFolderListModel::refresh(), and QDeclarativeFolderListModel::removed().

332 {
333  Q_D(const QDirModel);
334  if (parent.column() > 0)
335  return 0;
336 
337  if (!parent.isValid()) {
338  if (!d->root.populated) // lazy population
339  d->populate(&d->root);
340  return d->root.children.count();
341  }
342  if (parent.model() != this)
343  return 0;
344  QDirModelPrivate::QDirNode *p = d->node(parent);
345  if (p->info.isDir() && !p->populated) // lazy population
346  d->populate(p);
347  return p->children.count();
348 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
QVector< QDirNode > children
Definition: qdirmodel.cpp:81
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
const QAbstractItemModel * model() const
Returns a pointer to the model containing the item that this index refers to.
bool isValid() const
Returns true if this model index is valid; otherwise returns false.
The QDirModel class provides a data model for the local filesystem.
Definition: qdirmodel.h:59
int column() const
Returns the column this model index refers to.

◆ setData()

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

Sets the data for the model item index with the given role to the data referenced by the value.

Returns true if successful; otherwise returns false.

See also
Qt::ItemDataRole

Reimplemented from QAbstractItemModel.

Definition at line 406 of file qdirmodel.cpp.

407 {
408  Q_D(QDirModel);
409  if (!d->indexValid(index) || index.column() != 0
410  || (flags(index) & Qt::ItemIsEditable) == 0 || role != Qt::EditRole)
411  return false;
412 
413  QDirModelPrivate::QDirNode *node = d->node(index);
414  QDir dir = node->info.dir();
415  QString name = value.toString();
416  if (dir.rename(node->info.fileName(), name)) {
417  node->info = QFileInfo(dir, name);
418  QModelIndex sibling = index.sibling(index.row(), 3);
419  emit dataChanged(index, sibling);
420 
421  d->toBeRefreshed = index.parent();
422  QMetaObject::invokeMethod(this, "_q_refresh", Qt::QueuedConnection);
423 
424  return true;
425  }
426 
427  return false;
428 }
The QDir class provides access to directory structures and their contents.
Definition: qdir.h:58
double d
Definition: qnumeric_p.h:62
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...
Qt::ItemFlags flags(const QModelIndex &index) const
Returns the item flags for the given index in the model.
Definition: qdirmodel.cpp:486
QDir dir() const
Returns the path of the object&#39;s parent directory as a QDir object.
Definition: qfileinfo.cpp:861
QModelIndex sibling(int row, int column) const
Returns the sibling at row and column.
QString fileName() const
Returns the name of the file, excluding the path.
Definition: qfileinfo.cpp:726
QString toString() const
Returns the variant as a QString if the variant has type() String , Bool , ByteArray ...
Definition: qvariant.cpp:2270
The QString class provides a Unicode character string.
Definition: qstring.h:83
#define Q_D(Class)
Definition: qglobal.h:2482
QModelIndex parent() const
Returns the parent of the model index, or QModelIndex() if it has no parent.
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
int row() const
Returns the row this model index refers to.
const char * name
#define emit
Definition: qobjectdefs.h:76
The QModelIndex class is used to locate data in a data model.
void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
This signal is emitted whenever the data in an existing item changes.
static bool invokeMethod(QObject *obj, const char *member, Qt::ConnectionType, QGenericReturnArgument ret, QGenericArgument val0=QGenericArgument(0), QGenericArgument val1=QGenericArgument(), QGenericArgument val2=QGenericArgument(), QGenericArgument val3=QGenericArgument(), QGenericArgument val4=QGenericArgument(), QGenericArgument val5=QGenericArgument(), QGenericArgument val6=QGenericArgument(), QGenericArgument val7=QGenericArgument(), QGenericArgument val8=QGenericArgument(), QGenericArgument val9=QGenericArgument())
Invokes the member (a signal or a slot name) on the object obj.
The QFileInfo class provides system-independent file information.
Definition: qfileinfo.h:60
The QDirModel class provides a data model for the local filesystem.
Definition: qdirmodel.h:59
int column() const
Returns the column this model index refers to.

◆ setFilter()

void QDirModel::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 QDirModel won't be able to read the directory structure.

See also
QDir::Filters

Definition at line 694 of file qdirmodel.cpp.

Referenced by QDeclarativeFolderListModel::QDeclarativeFolderListModel(), QDeclarativeFolderListModel::setShowDirs(), QDeclarativeFolderListModel::setShowDotAndDotDot(), and QDeclarativeFolderListModel::setShowOnlyReadable().

695 {
696  Q_D(QDirModel);
697  d->filters = filters;
699  if (d->shouldStat)
700  refresh(QModelIndex());
701  else
702  d->invalidate();
704 }
double d
Definition: qnumeric_p.h:62
void refresh(const QModelIndex &parent=QModelIndex())
QDirModel caches file information.
Definition: qdirmodel.cpp:829
#define Q_D(Class)
Definition: qglobal.h:2482
void layoutAboutToBeChanged()
This signal is emitted just before the layout of a model is changed.
#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...
static const char *const filters[3]
The QModelIndex class is used to locate data in a data model.
The QDirModel class provides a data model for the local filesystem.
Definition: qdirmodel.h:59

◆ setIconProvider()

void QDirModel::setIconProvider ( QFileIconProvider provider)

Sets the provider of file icons for the directory model.

Definition at line 643 of file qdirmodel.cpp.

644 {
645  Q_D(QDirModel);
646  d->iconProvider = provider;
647 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QDirModel class provides a data model for the local filesystem.
Definition: qdirmodel.h:59

◆ setLazyChildCount()

void QDirModel::setLazyChildCount ( bool  enable)

Definition at line 810 of file qdirmodel.cpp.

811 {
812  Q_D(QDirModel);
813  d->lazyChildCount = enable;
814 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QDirModel class provides a data model for the local filesystem.
Definition: qdirmodel.h:59

◆ setNameFilters()

void QDirModel::setNameFilters ( const QStringList filters)

Sets the name filters for the directory model.

Definition at line 663 of file qdirmodel.cpp.

Referenced by QDeclarativeFolderListModel::setNameFilters().

664 {
665  Q_D(QDirModel);
666  d->nameFilters = filters;
668  if (d->shouldStat)
669  refresh(QModelIndex());
670  else
671  d->invalidate();
673 }
double d
Definition: qnumeric_p.h:62
void refresh(const QModelIndex &parent=QModelIndex())
QDirModel caches file information.
Definition: qdirmodel.cpp:829
#define Q_D(Class)
Definition: qglobal.h:2482
void layoutAboutToBeChanged()
This signal is emitted just before the layout of a model is changed.
#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...
static const char *const filters[3]
The QModelIndex class is used to locate data in a data model.
The QDirModel class provides a data model for the local filesystem.
Definition: qdirmodel.h:59

◆ setReadOnly()

void QDirModel::setReadOnly ( bool  enable)

Definition at line 782 of file qdirmodel.cpp.

783 {
784  Q_D(QDirModel);
785  d->readOnly = enable;
786 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QDirModel class provides a data model for the local filesystem.
Definition: qdirmodel.h:59

◆ setResolveSymlinks()

void QDirModel::setResolveSymlinks ( bool  enable)

Definition at line 757 of file qdirmodel.cpp.

758 {
759  Q_D(QDirModel);
760  d->resolveSymlinks = enable;
761 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QDirModel class provides a data model for the local filesystem.
Definition: qdirmodel.h:59

◆ setSorting()

void QDirModel::setSorting ( QDir::SortFlags  sort)

Sets the directory model's sorting order to that specified by sort.

See also
QDir::SortFlags

Definition at line 724 of file qdirmodel.cpp.

Referenced by sort(), and QDeclarativeFolderListModelPrivate::updateSorting().

725 {
726  Q_D(QDirModel);
727  d->sort = sort;
729  if (d->shouldStat)
730  refresh(QModelIndex());
731  else
732  d->invalidate();
734 }
double d
Definition: qnumeric_p.h:62
void refresh(const QModelIndex &parent=QModelIndex())
QDirModel caches file information.
Definition: qdirmodel.cpp:829
#define Q_D(Class)
Definition: qglobal.h:2482
void layoutAboutToBeChanged()
This signal is emitted just before the layout of a model is changed.
#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.
void sort(int column, Qt::SortOrder order=Qt::AscendingOrder)
Sort the model items in the column using the order given.
Definition: qdirmodel.cpp:509
The QDirModel class provides a data model for the local filesystem.
Definition: qdirmodel.h:59

◆ sort()

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

Sort the model items in the column using the order given.

The order is a value defined in Qt::SortOrder .

Reimplemented from QAbstractItemModel.

Definition at line 509 of file qdirmodel.cpp.

Referenced by QDirModelPrivate::entryInfoList(), QDirModelPrivate::entryList(), QDirModelPrivate::init(), QDirModel(), and setSorting().

510 {
511  QDir::SortFlags sort = QDir::DirsFirst | QDir::IgnoreCase;
512  if (order == Qt::DescendingOrder)
513  sort |= QDir::Reversed;
514 
515  switch (column) {
516  case 0:
517  sort |= QDir::Name;
518  break;
519  case 1:
520  sort |= QDir::Size;
521  break;
522  case 2:
523  sort |= QDir::Type;
524  break;
525  case 3:
526  sort |= QDir::Time;
527  break;
528  default:
529  break;
530  }
531 
532  setSorting(sort);
533 }
void setSorting(QDir::SortFlags sort)
Sets the directory model&#39;s sorting order to that specified by sort.
Definition: qdirmodel.cpp:724
void sort(int column, Qt::SortOrder order=Qt::AscendingOrder)
Sort the model items in the column using the order given.
Definition: qdirmodel.cpp:509

◆ sorting()

QDir::SortFlags QDirModel::sorting ( ) const

Returns the sorting method used for the directory model.

See also
QDir::SortFlags

Definition at line 741 of file qdirmodel.cpp.

742 {
743  Q_D(const QDirModel);
744  return d->sort;
745 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QDirModel class provides a data model for the local filesystem.
Definition: qdirmodel.h:59

◆ supportedDropActions()

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

Returns the drop actions supported by this model.

See also
Qt::DropActions

Reimplemented from QAbstractItemModel.

Definition at line 633 of file qdirmodel.cpp.

634 {
635  return Qt::CopyAction | Qt::MoveAction; // FIXME: LinkAction is not supported yet
636 }

Friends and Related Functions

◆ QFileDialogPrivate

friend class QFileDialogPrivate
friend

Definition at line 146 of file qdirmodel.h.

Properties

◆ lazyChildCount

bool QDirModel::lazyChildCount
private

Whether the directory model optimizes the hasChildren function to only check if the item is a directory.

If this property is set to false, the directory model will make sure that a directory actually containes any files before reporting that it has children. Otherwise the directory model will report that an item has children if the item is a directory.

This property is false by default

Definition at line 64 of file qdirmodel.h.

◆ readOnly

QDirModel::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 63 of file qdirmodel.h.

◆ resolveSymlinks

bool QDirModel::resolveSymlinks
private

Whether the directory model should resolve symbolic links.

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

Definition at line 62 of file qdirmodel.h.


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