44 #ifndef QT_NO_DIRMODEL 57 #include <private/qabstractitemmodel_p.h> 177 while (!nodes.
empty()) {
179 current->
stat =
false;
181 for (
int i = 0; i < children.
count(); ++i)
182 nodes.
push(&children.
at(i));
231 QDir::SortFlags
sort,
285 if (column < 0 || column >=
columnCount(parent) || row < 0 || parent.
column() > 0)
309 if (!
d->indexValid(child))
320 int row = (par - &(children.
at(0)));
338 if (!
d->root.populated)
339 d->populate(&
d->root);
340 return d->root.children.count();
342 if (parent.
model() !=
this)
368 if (!
d->indexValid(index))
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);
378 qWarning(
"data: invalid display value column %d", index.
column());
383 if (index.
column() == 0) {
409 if (!
d->indexValid(index) || index.
column() != 0
421 d->toBeRefreshed = index.
parent();
441 case 0:
return tr(
"Name");
442 case 1:
return tr(
"Size");
445 tr(
"Kind",
"Match OS X Finder");
447 tr(
"Type",
"All other platforms");
453 case 3:
return tr(
"Date Modified");
476 if (
d->lazyChildCount)
490 if (!
d->indexValid(index))
558 for (; it != indexes.
end(); ++
it)
559 if ((*it).column() == 0)
591 QString path = (*it).toLocalFile();
597 QString path = (*it).toLocalFile();
603 QString path = (*it).toLocalFile();
646 d->iconProvider = provider;
656 return d->iconProvider;
682 return d->nameFilters;
760 d->resolveSymlinks = enable;
766 return d->resolveSymlinks;
785 d->readOnly = enable;
813 d->lazyChildCount = enable;
819 return d->lazyChildCount;
845 d->savePersistentIndexes();
846 d->rowsAboutToBeRemoved(parent, 0, rows - 1);
849 d->rowsRemoved(parent, 0, rows - 1);
850 d->restorePersistentIndexes();
871 #if (defined(Q_OS_WIN) && !defined(Q_OS_WINCE)) || defined(Q_OS_SYMBIAN) 872 absolutePath = absolutePath.
toLower();
874 #if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) 878 for (i = absolutePath.
count() - 1; i >= 0; --i) {
882 absolutePath = absolutePath.
left(i+1);
888 #
if !defined(
Q_OS_WIN) || defined(Q_OS_WINCE)
895 if (!
d->root.populated)
896 d->populate(&
d->root);
898 #if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) 902 for (; r <
d->root.children.count(); ++r)
903 if (
d->root.children.at(r).info.fileName() == host)
905 bool childAppended =
false;
906 if (r >=
d->root.children.count() &&
d->allowAppendChild) {
908 childAppended =
true;
916 #if (defined(Q_OS_WIN) && !defined(Q_OS_WINCE)) || defined(Q_OS_SYMBIAN) 925 for (
int i = 0; i < pathElements.
count(); ++i) {
936 for (
int j = parent->
children.count() - 1; j >= 0; --j) {
940 #if (defined(Q_OS_WIN) && !defined(Q_OS_WINCE)) || defined(Q_OS_SYMBIAN) 941 childFileName = childFileName.
toLower();
943 if (childFileName == element) {
944 if (i == pathElements.
count() - 1)
953 #if defined(Q_OS_WINCE) 964 d->appendChild(parent, newPath);
966 if (i == pathElements.
count() - 1)
968 emit const_cast<QDirModel*>(
this)->layoutChanged();
991 return node->info.isDir();
1022 int r = entryList.
indexOf(childName);
1048 qWarning(
"rmdir: the node is not a directory");
1056 if (!dir.
rmdir(path))
1106 if (
d->indexValid(index)) {
1109 fi =
d->resolvedInfo(fi);
1124 if (!
d->indexValid(index))
1130 info =
d->resolvedInfo(info);
1142 if (!
d->indexValid(index))
1146 node->
icon =
d->iconProvider->icon(node->
info);
1192 q->setRoleNames(roles);
1206 qWarning(
"node: the row does not exist");
1217 if (parent == &root) {
1227 infoList = entryInfoList(link);
1239 for (
int i = 0; i < infoList.
count(); ++i) {
1242 node.
info = infoList.
at(i);
1244 node.
stat = shouldStat;
1253 q->refresh(toBeRefreshed);
1260 savedPersistent.clear();
1264 saved.
path = q->filePath(index);
1268 savedPersistent.append(saved);
1275 bool allow = allowAppendChild;
1276 allowAppendChild =
false;
1277 for (
int i = 0; i < savedPersistent.count(); ++i) {
1279 QString path = savedPersistent.
at(i).path;
1280 int column = savedPersistent.at(i).column;
1282 if (idx != data->
index || data->
model == 0) {
1284 persistent.indexes.remove(data->
index);
1288 persistent.indexes.insert(idx, data);
1291 savedPersistent.clear();
1292 allowAppendChild = allow;
1297 const QDir dir(path);
1303 const QDir dir(path);
1313 #if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) 1317 #if (defined(Q_OS_WIN) && !defined(Q_OS_WINCE)) || defined(Q_OS_SYMBIAN) 1366 #ifndef QT_NO_DATESTRING 1367 return node(index)->info.lastModified().toString(
Qt::LocalDate);
1378 node.
stat = shouldStat;
1388 for (
int i = 0; i < parent->
children.count(); ++i) {
1390 for (
int j = 0; j < childNode->
children.count(); ++j)
1391 childNode->
children[j].parent = childNode;
1405 if (link.isRelative())
1419 #include "moc_qdirmodel.cpp" 1421 #endif // QT_NO_DIRMODEL The QVariant class acts like a union for the most common Qt data types.
The QDir class provides access to directory structures and their contents.
QStringList nameFilters() const
Returns a list of filters applied to the names in the model.
QDir::Filters filter() const
Returns the filter specification for the directory model.
void * internalPointer() const
Returns a void * pointer used by the model to associate the index with the internal data structure...
QString fileName(const QModelIndex &index) const
Returns the name of the item stored in the model under the index given.
bool resolveSymlinks() const
void setReadOnly(bool enable)
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...
QString filePath(const QModelIndex &index) const
Returns the path of the item stored in the model under the index given.
Qt::ItemFlags flags(const QModelIndex &index) const
Returns the item flags for the given index in the model.
QStringList mimeTypes() const
Returns a list of MIME types that can be used to describe a list of items in the model.
static mach_timebase_info_data_t info
bool remove(const QModelIndex &index)
Removes the model item index from the directory model and deletes the corresponding file from the fil...
#define QT_END_NAMESPACE
This macro expands to.
void clear(QDirNode *parent) const
const QChar at(int i) const
Returns the character at the given index position in the string.
QDir dir() const
Returns the path of the object's parent directory as a QDir object.
QString time(const QModelIndex &index) const
void qt_setDirModelShouldNotStat(QDirModelPrivate *modelPrivate)
QModelIndex sibling(int row, int column) const
Returns the sibling at row and column.
#define it(className, varName)
int count(const T &t) const
Returns the number of occurrences of value in the vector.
bool isRelative() const
Returns true if the directory path is relative; otherwise returns false.
void setResolveSymlinks(bool enable)
void chop(int n)
Removes n characters from the end of the string.
static QFileInfo resolvedInfo(QFileInfo info)
QFileInfoList entryInfoList(const QString &path) const
QDir::SortFlags sorting() const
Returns the sorting method used for the directory model.
QString fileName() const
Returns the name of the file, excluding the path.
static void clear(QVariant::Private *d)
iterator begin()
Returns an STL-style iterator pointing to the first item in the list.
QString toString() const
Returns the variant as a QString if the variant has type() String , Bool , ByteArray ...
const_iterator constBegin() const
Returns a const STL-style iterator pointing to the first item in the list.
QModelIndex createIndex(int row, int column, void *data=0) const
Creates a model index for the given row and column with the internal pointer ptr. ...
bool mkdir(const QString &dirName) const
Creates a sub-directory called dirName.
bool startsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string starts with s; otherwise returns false.
void refresh(const QModelIndex &parent=QModelIndex())
QDirModel caches file information.
QString absoluteFilePath() const
Returns an absolute path including the file name.
static QString tr(const char *sourceText, const char *comment=0, int n=-1)
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
bool exists() const
Returns true if the file exists; otherwise returns false.
void setIconProvider(QFileIconProvider *provider)
Sets the provider of file icons for the directory model.
void setCaching(bool on)
If enable is true, enables caching of file information.
The QStack class is a template class that provides a stack.
void pop_front()
This function is provided for STL compatibility.
int count(const T &t) const
Returns the number of occurrences of value in the list.
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 ...
QDirModel(const QStringList &nameFilters, QDir::Filters filters, QDir::SortFlags sort, QObject *parent=0)
Constructs a new directory model with the given parent.
The QString class provides a Unicode character string.
QVector< QDirNode > children(QDirNode *parent, bool stat) const
QString type(const QModelIndex &index) const
The QVector class is a template class that provides a dynamic array.
The QObject class is the base class of all Qt objects.
bool empty() const
This function is provided for STL compatibility.
static QChar separator()
Returns the native directory separator: "/" under Unix (including Mac OS X) and "\\" under Windows...
QModelIndex parent() const
Returns the parent of the model index, or QModelIndex() if it has no parent.
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.
virtual QString type(const QFileInfo &info) const
Returns the type of the file described by info.
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
iterator insert(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
static QString translate(const char *context, const char *key, const char *disambiguation=0, Encoding encoding=CodecForTr)
T pop()
Removes the top item from the stack and returns it.
virtual Qt::ItemFlags flags(const QModelIndex &index) const
Returns the item flags for the given index.
QVector< QDirNode > children
bool cdUp()
Changes directory by moving one directory up from the QDir's current directory.
static QString toString(Register *reg, int type, bool *ok=0)
bool rename(const QString &oldName, const QString &newName)
Renames a file or directory from oldName to newName, and returns true if successful; otherwise return...
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...
#define QT_BEGIN_NAMESPACE
This macro expands to.
const QAbstractItemModel * model
bool isDir() const
Returns true if this object points to a directory or to a symbolic link to a directory; otherwise ret...
QString left(int n) const Q_REQUIRED_RESULT
Returns a substring that contains the n leftmost characters of the string.
void layoutAboutToBeChanged()
This signal is emitted just before the layout of a model is changed.
void restorePersistentIndexes()
int size() const
Returns the number of characters in this string.
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
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.
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the list...
int row() const
Returns the row this model index refers to.
void prepend(const T &t)
Inserts value at the beginning of the list.
const T & at(int i) const
Returns the item at index position i in the list.
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.
The QStringList class provides a list of strings.
void setFile(const QString &file)
Sets the file that the QFileInfo provides information about to file.
QStringList entryList(const QString &path) const
void appendChild(QDirModelPrivate::QDirNode *parent, const QString &path) const
Q_CORE_EXPORT void qWarning(const char *,...)
The QFileIconProvider class provides file icons for the QDirModel and the QFileSystemModel classes...
void setUrls(const QList< QUrl > &urls)
Sets the URLs stored in the MIME data object to those specified by urls.
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
~QDirModel()
Destroys this directory model.
QFileInfoList entryInfoList(Filters filters=NoFilter, SortFlags sort=NoSort) const
Returns a list of QFileInfo objects for all the files and directories in the directory, ordered according to the name and attribute filters previously set with setNameFilters() and setFilter(), and sorted according to the flags set with setSorting().
QMimeData * mimeData(const QModelIndexList &indexes) const
Returns an object that contains a serialized description of the specified indexes.
QList< QUrl > urls() const
Returns a list of URLs contained within the MIME data object.
void setFilter(QDir::Filters filters)
Sets the directory model's filter to that specified by filters.
static QFileInfoList drives()
Returns a list of the root directories on this system.
QFileIconProvider * iconProvider
void layoutChanged()
This signal is emitted whenever the layout of items exposed by the model has changed; for example...
int columnCount(const QModelIndex &parent=QModelIndex()) const
Returns the number of columns in the parent model item.
static QString cleanPath(const QString &path)
Removes all multiple directory separators "/" and resolves any "."s or ".."s found in the path...
bool hasChildren(const QModelIndex &index=QModelIndex()) const
Returns true if the parent model item has children; otherwise returns false.
The QMimeData class provides a container for data that records information about its MIME type...
void setSorting(QDir::SortFlags sort)
Sets the directory model's sorting order to that specified by sort.
void push(const T &t)
Adds element t to the top of the stack.
QDirNode * node(int row, QDirNode *parent) const
bool isValid() const
Returns true if this model index is valid; otherwise returns false.
const T & at(int i) const
Returns the item at index position i in the vector.
void savePersistentIndexes()
The QAbstractItemModel class provides the abstract interface for item model classes.
bool isDir(const QModelIndex &index) const
Returns true if the model item index represents a directory; otherwise returns false.
T & first()
Returns a reference to the first item in the list.
static const char *const filters[3]
QString arg(qlonglong a, int fieldwidth=0, int base=10, const QChar &fillChar=QLatin1Char(' ')) const Q_REQUIRED_RESULT
#define Q_DECLARE_PUBLIC(Class)
qint64 size() const
Returns the file size in bytes.
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.
bool lazyChildCount() const
The QPersistentModelIndex class is used to locate data in a data model.
QObject * parent() const
Returns a pointer to the parent object.
QString toLower() const Q_REQUIRED_RESULT
Returns a lowercase copy of the string.
bool rmdir(const QString &dirName) const
Removes the directory specified by dirName.
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.
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.
void sort(int column, Qt::SortOrder order=Qt::AscendingOrder)
Sort the model items in the column using the order given.
const QObjectList & children() const
Returns a list of child objects.
QString symLinkTarget() const
Returns the absolute path to the file or directory a symlink (or shortcut on Windows) points to...
bool copy(const QString &newName)
Copies the file currently specified by fileName() to a file called newName.
bool remove()
Removes the file specified by fileName().
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const
Returns the data for the model item index with the given role.
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 o...
void setNameFilters(const QStringList &filters)
Sets the name filters for the directory model.
QPersistentModelIndex toBeRefreshed
static QUrl fromLocalFile(const QString &localfile)
Returns a QUrl representation of localFile, interpreted as a local file.
bool remove(const QString &fileName)
Removes the file, fileName.
QString name(const QModelIndex &index) const
QStringList split(const QString &sep, SplitBehavior behavior=KeepEmptyParts, Qt::CaseSensitivity cs=Qt::CaseSensitive) const Q_REQUIRED_RESULT
Splits the string into substrings wherever sep occurs, and returns the list of those strings...
bool rmdir(const QModelIndex &index)
Removes the directory corresponding to the model item index in the directory model and deletes the co...
QPersistentModelIndex index
QFileInfo fileInfo(const QModelIndex &index) const
Returns the file information for the specified model index.
iterator insertMulti(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
void setLazyChildCount(bool enable)
bool endsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string ends with s; otherwise returns false.
bool isSymLink() const
Returns true if this object points to a symbolic link (or to a shortcut on Windows); otherwise return...
The QFileInfo class provides system-independent file information.
void populate(QDirNode *parent) const
QString dirName() const
Returns the name of the directory; this is not the same as the path, e.g.
QModelIndex mkdir(const QModelIndex &parent, const QString &name)
Create a directory with the name in the parent model item.
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
int rowCount(const QModelIndex &parent=QModelIndex()) const
Returns the number of rows in the parent model item.
The QDirModel class provides a data model for the local filesystem.
QList< SavedPersistent > savedPersistent
QIcon fileIcon(const QModelIndex &index) const
Returns the icons for the item stored in the model under the given index.
bool isWritable() const
Returns true if the user can write to the file; otherwise returns false.
QString absolutePath() const
Returns a file's path absolute path.
QStringList entryList(Filters filters=NoFilter, SortFlags sort=NoSort) const
Returns a list of the names of all the files and directories in the directory, ordered according to t...
Qt::DropActions supportedDropActions() const
Returns the drop actions supported by this model.
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
QFileIconProvider defaultProvider
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...
QString size(const QModelIndex &index) const
bool link(const QString &newName)
Creates a link named linkName that points to the file currently specified by fileName().
QPersistentModelIndexData * data
int column() const
Returns the column this model index refers to.
const_iterator constEnd() const
Returns a const STL-style iterator pointing to the imaginary item after the last item in the list...
QFileIconProvider * iconProvider() const
Returns the file icon provider for this directory model.
The QIcon class provides scalable icons in different modes and states.