Qt 4.8
qdirmodel.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtGui module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #include "qdirmodel.h"
43 
44 #ifndef QT_NO_DIRMODEL
45 #include <qstack.h>
46 #include <qfile.h>
47 #include <qfilesystemmodel.h>
48 #include <qurl.h>
49 #include <qmime.h>
50 #include <qpair.h>
51 #include <qvector.h>
52 #include <qobject.h>
53 #include <qdatetime.h>
54 #include <qlocale.h>
55 #include <qstyle.h>
56 #include <qapplication.h>
57 #include <private/qabstractitemmodel_p.h>
58 #include <qdebug.h>
59 
68 
70 {
72 
73 public:
74  struct QDirNode
75  {
76  QDirNode() : parent(0), populated(false), stat(false) {}
77  ~QDirNode() { children.clear(); }
80  QIcon icon; // cache the icon
82  mutable bool populated; // have we read the children
83  mutable bool stat;
84  };
85 
87  : resolveSymlinks(true),
88  readOnly(true),
89  lazyChildCount(false),
90  allowAppendChild(true),
92  shouldStat(true) // ### This is set to false by QFileDialog
93  { }
94 
95  void init();
96  QDirNode *node(int row, QDirNode *parent) const;
97  QVector<QDirNode> children(QDirNode *parent, bool stat) const;
98 
99  void _q_refresh();
100 
101  void savePersistentIndexes();
103 
104  QFileInfoList entryInfoList(const QString &path) const;
105  QStringList entryList(const QString &path) const;
106 
107  QString name(const QModelIndex &index) const;
108  QString size(const QModelIndex &index) const;
109  QString type(const QModelIndex &index) const;
110  QString time(const QModelIndex &index) const;
111 
112  void appendChild(QDirModelPrivate::QDirNode *parent, const QString &path) const;
114 
115  inline QDirNode *node(const QModelIndex &index) const;
116  inline void populate(QDirNode *parent) const;
117  inline void clear(QDirNode *parent) const;
118 
119  void invalidate();
120 
121  mutable QDirNode root;
123  bool readOnly;
126 
127  QDir::Filters filters;
128  QDir::SortFlags sort;
130 
133 
136  int column;
139  };
142 
143  bool shouldStat; // use the "carefull not to stat directories" mode
144 };
145 
147 {
148  modelPrivate->shouldStat = false;
149 }
150 
152 {
154  static_cast<QDirModelPrivate::QDirNode*>(index.internalPointer());
155  Q_ASSERT(n);
156  return n;
157 }
158 
160 {
161  Q_ASSERT(parent);
162  parent->children = children(parent, parent->stat);
163  parent->populated = true;
164 }
165 
167 {
168  Q_ASSERT(parent);
169  parent->children.clear();
170  parent->populated = false;
171 }
172 
174 {
176  nodes.push(&root);
177  while (!nodes.empty()) {
178  const QDirNode *current = nodes.pop();
179  current->stat = false;
180  const QVector<QDirNode> children = current->children;
181  for (int i = 0; i < children.count(); ++i)
182  nodes.push(&children.at(i));
183  }
184 }
185 
230  QDir::Filters filters,
231  QDir::SortFlags sort,
232  QObject *parent)
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 }
244 
250  : QAbstractItemModel(*new QDirModelPrivate, parent)
251 {
252  Q_D(QDirModel);
253  d->init();
254 }
255 
260  : QAbstractItemModel(dd, parent)
261 {
262  Q_D(QDirModel);
263  d->init();
264 }
265 
271 {
272 
273 }
274 
281 QModelIndex QDirModel::index(int row, int column, const QModelIndex &parent) const
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 }
300 
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 }
325 
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 }
349 
356 {
357  if (parent.column() > 0)
358  return 0;
359  return 4;
360 }
361 
365 QVariant QDirModel::data(const QModelIndex &index, int role) const
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 }
397 
406 bool QDirModel::setData(const QModelIndex &index, const QVariant &value, int role)
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 }
429 
435 QVariant QDirModel::headerData(int section, Qt::Orientation orientation, int role) const
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 }
459 
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 }
480 
486 Qt::ItemFlags QDirModel::flags(const QModelIndex &index) const
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 }
503 
509 void QDirModel::sort(int column, Qt::SortOrder order)
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 }
534 
541 {
542  return QStringList(QLatin1String("text/uri-list"));
543 }
544 
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 }
565 
575  int /* row */, int /* column */, const QModelIndex &parent)
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 }
626 
633 Qt::DropActions QDirModel::supportedDropActions() const
634 {
635  return Qt::CopyAction | Qt::MoveAction; // FIXME: LinkAction is not supported yet
636 }
637 
644 {
645  Q_D(QDirModel);
646  d->iconProvider = provider;
647 }
648 
654 {
655  Q_D(const QDirModel);
656  return d->iconProvider;
657 }
658 
664 {
665  Q_D(QDirModel);
666  d->nameFilters = filters;
668  if (d->shouldStat)
669  refresh(QModelIndex());
670  else
671  d->invalidate();
673 }
674 
680 {
681  Q_D(const QDirModel);
682  return d->nameFilters;
683 }
684 
694 void QDirModel::setFilter(QDir::Filters filters)
695 {
696  Q_D(QDirModel);
697  d->filters = filters;
699  if (d->shouldStat)
700  refresh(QModelIndex());
701  else
702  d->invalidate();
704 }
705 
712 QDir::Filters QDirModel::filter() const
713 {
714  Q_D(const QDirModel);
715  return d->filters;
716 }
717 
724 void QDirModel::setSorting(QDir::SortFlags sort)
725 {
726  Q_D(QDirModel);
727  d->sort = sort;
729  if (d->shouldStat)
730  refresh(QModelIndex());
731  else
732  d->invalidate();
734 }
735 
741 QDir::SortFlags QDirModel::sorting() const
742 {
743  Q_D(const QDirModel);
744  return d->sort;
745 }
746 
758 {
759  Q_D(QDirModel);
760  d->resolveSymlinks = enable;
761 }
762 
763 bool QDirModel::resolveSymlinks() const
764 {
765  Q_D(const QDirModel);
766  return d->resolveSymlinks;
767 }
768 
782 void QDirModel::setReadOnly(bool enable)
783 {
784  Q_D(QDirModel);
785  d->readOnly = enable;
786 }
787 
789 {
790  Q_D(const QDirModel);
791  return d->readOnly;
792 }
793 
811 {
812  Q_D(QDirModel);
813  d->lazyChildCount = enable;
814 }
815 
816 bool QDirModel::lazyChildCount() const
817 {
818  Q_D(const QDirModel);
819  return d->lazyChildCount;
820 }
821 
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 }
853 
863 QModelIndex QDirModel::index(const QString &path, int column) const
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 }
980 
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 }
993 
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 }
1027 
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 }
1063 
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 }
1096 
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 }
1114 
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 }
1133 
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 }
1149 
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 }
1169 
1175 /*
1176  The root node is never seen outside the model.
1177 */
1178 
1180 {
1181  Q_Q(QDirModel);
1183  sort = QDir::Name;
1184  nameFilters << QLatin1String("*");
1185  root.parent = 0;
1186  root.info = QFileInfo();
1187  clear(&root);
1188  QHash<int, QByteArray> roles = q->roleNames();
1189  roles.insertMulti(QDirModel::FileIconRole, "fileIcon"); // == Qt::decoration
1190  roles.insert(QDirModel::FilePathRole, "filePath");
1191  roles.insert(QDirModel::FileNameRole, "fileName");
1192  q->setRoleNames(roles);
1193 }
1194 
1196 {
1197  if (row < 0)
1198  return 0;
1199 
1200  bool isDir = !parent || parent->info.isDir();
1201  QDirNode *p = (parent ? parent : &root);
1202  if (isDir && !p->populated)
1203  populate(p); // will also resolve symlinks
1204 
1205  if (row >= p->children.count()) {
1206  qWarning("node: the row does not exist");
1207  return 0;
1208  }
1209 
1210  return const_cast<QDirNode*>(&p->children.at(row));
1211 }
1212 
1214 {
1215  Q_ASSERT(parent);
1216  QFileInfoList infoList;
1217  if (parent == &root) {
1218  parent = 0;
1219  infoList = QDir::drives();
1220  } else if (parent->info.isDir()) {
1221  //resolve directory links only if requested.
1222  if (parent->info.isSymLink() && resolveSymlinks) {
1223  QString link = parent->info.symLinkTarget();
1224  if (link.size() > 1 && link.at(link.size() - 1) == QDir::separator())
1225  link.chop(1);
1226  if (stat)
1227  infoList = entryInfoList(link);
1228  else
1230  } else {
1231  if (stat)
1232  infoList = entryInfoList(parent->info.absoluteFilePath());
1233  else
1234  infoList = QDir(parent->info.absoluteFilePath()).entryInfoList(nameFilters, QDir::AllEntries | QDir::System);
1235  }
1236  }
1237 
1238  QVector<QDirNode> nodes(infoList.count());
1239  for (int i = 0; i < infoList.count(); ++i) {
1240  QDirNode &node = nodes[i];
1241  node.parent = parent;
1242  node.info = infoList.at(i);
1243  node.populated = false;
1244  node.stat = shouldStat;
1245  }
1246 
1247  return nodes;
1248 }
1249 
1251 {
1252  Q_Q(QDirModel);
1253  q->refresh(toBeRefreshed);
1254  toBeRefreshed = QModelIndex();
1255 }
1256 
1258 {
1259  Q_Q(QDirModel);
1260  savedPersistent.clear();
1261  foreach (QPersistentModelIndexData *data, persistent.indexes) {
1262  SavedPersistent saved;
1263  QModelIndex index = data->index;
1264  saved.path = q->filePath(index);
1265  saved.column = index.column();
1266  saved.data = data;
1267  saved.index = index;
1268  savedPersistent.append(saved);
1269  }
1270 }
1271 
1273 {
1274  Q_Q(QDirModel);
1275  bool allow = allowAppendChild;
1276  allowAppendChild = false;
1277  for (int i = 0; i < savedPersistent.count(); ++i) {
1278  QPersistentModelIndexData *data = savedPersistent.at(i).data;
1279  QString path = savedPersistent.at(i).path;
1280  int column = savedPersistent.at(i).column;
1281  QModelIndex idx = q->index(path, column);
1282  if (idx != data->index || data->model == 0) {
1283  //data->model may be equal to 0 if the model is getting destroyed
1284  persistent.indexes.remove(data->index);
1285  data->index = idx;
1286  data->model = q;
1287  if (idx.isValid())
1288  persistent.indexes.insert(idx, data);
1289  }
1290  }
1291  savedPersistent.clear();
1292  allowAppendChild = allow;
1293 }
1294 
1296 {
1297  const QDir dir(path);
1298  return dir.entryInfoList(nameFilters, filters, sort);
1299 }
1300 
1302 {
1303  const QDir dir(path);
1304  return dir.entryList(nameFilters, filters, sort);
1305 }
1306 
1308 {
1309  const QDirNode *n = node(index);
1310  const QFileInfo info = n->info;
1311  if (info.isRoot()) {
1312  QString name = info.absoluteFilePath();
1313 #if defined(Q_OS_WIN) && !defined(Q_OS_WINCE)
1314  if (name.startsWith(QLatin1Char('/'))) // UNC host
1315  return info.fileName();
1316 #endif
1317 #if (defined(Q_OS_WIN) && !defined(Q_OS_WINCE)) || defined(Q_OS_SYMBIAN)
1318  if (name.endsWith(QLatin1Char('/')))
1319  name.chop(1);
1320 #endif
1321  return name;
1322  }
1323  return info.fileName();
1324 }
1325 
1327 {
1328  const QDirNode *n = node(index);
1329  if (n->info.isDir()) {
1330 #ifdef Q_OS_MAC
1331  return QLatin1String("--");
1332 #else
1333  return QLatin1String("");
1334 #endif
1335  // Windows - ""
1336  // OS X - "--"
1337  // Konqueror - "4 KB"
1338  // Nautilus - "9 items" (the number of children)
1339  }
1340 
1341  // According to the Si standard KB is 1000 bytes, KiB is 1024
1342  // but on windows sizes are calulated by dividing by 1024 so we do what they do.
1343  const quint64 kb = 1024;
1344  const quint64 mb = 1024 * kb;
1345  const quint64 gb = 1024 * mb;
1346  const quint64 tb = 1024 * gb;
1347  quint64 bytes = n->info.size();
1348  if (bytes >= tb)
1349  return QFileSystemModel::tr("%1 TB").arg(QLocale().toString(qreal(bytes) / tb, 'f', 3));
1350  if (bytes >= gb)
1351  return QFileSystemModel::tr("%1 GB").arg(QLocale().toString(qreal(bytes) / gb, 'f', 2));
1352  if (bytes >= mb)
1353  return QFileSystemModel::tr("%1 MB").arg(QLocale().toString(qreal(bytes) / mb, 'f', 1));
1354  if (bytes >= kb)
1355  return QFileSystemModel::tr("%1 KB").arg(QLocale().toString(bytes / kb));
1356  return QFileSystemModel::tr("%1 byte(s)").arg(QLocale().toString(bytes));
1357 }
1358 
1360 {
1361  return iconProvider->type(node(index)->info);
1362 }
1363 
1365 {
1366 #ifndef QT_NO_DATESTRING
1367  return node(index)->info.lastModified().toString(Qt::LocalDate);
1368 #else
1369  Q_UNUSED(index);
1370  return QString();
1371 #endif
1372 }
1373 
1375 {
1377  node.populated = false;
1378  node.stat = shouldStat;
1379  node.parent = (parent == &root ? 0 : parent);
1380  node.info = QFileInfo(path);
1381  node.info.setCaching(true);
1382 
1383  // The following append(node) may reallocate the vector, thus
1384  // we need to update the pointers to the childnodes parent.
1385  QDirModelPrivate *that = const_cast<QDirModelPrivate *>(this);
1386  that->savePersistentIndexes();
1387  parent->children.append(node);
1388  for (int i = 0; i < parent->children.count(); ++i) {
1389  QDirNode *childNode = &parent->children[i];
1390  for (int j = 0; j < childNode->children.count(); ++j)
1391  childNode->children[j].parent = childNode;
1392  }
1393  that->restorePersistentIndexes();
1394 }
1395 
1397 {
1398 #ifdef Q_OS_WIN
1399  // On windows, we cannot create a shortcut to a shortcut.
1400  return QFileInfo(info.symLinkTarget());
1401 #else
1402  QStringList paths;
1403  do {
1404  QFileInfo link(info.symLinkTarget());
1405  if (link.isRelative())
1406  info.setFile(info.absolutePath(), link.filePath());
1407  else
1408  info = link;
1409  if (paths.contains(info.absoluteFilePath()))
1410  return QFileInfo();
1411  paths.append(info.absoluteFilePath());
1412  } while (info.isSymLink());
1413  return info;
1414 #endif
1415 }
1416 
1418 
1419 #include "moc_qdirmodel.cpp"
1420 
1421 #endif // QT_NO_DIRMODEL
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
The QDir class provides access to directory structures and their contents.
Definition: qdir.h:58
QStringList nameFilters() const
Returns a list of filters applied to the names in the model.
Definition: qdirmodel.cpp:679
double d
Definition: qnumeric_p.h:62
QDir::Filters filter() const
Returns the filter specification for the directory model.
Definition: qdirmodel.cpp:712
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.
Definition: qdirmodel.cpp:1121
bool resolveSymlinks() const
void setReadOnly(bool enable)
Definition: qdirmodel.cpp:782
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.
Definition: qdirmodel.cpp:1103
double qreal
Definition: qglobal.h:1193
Qt::ItemFlags flags(const QModelIndex &index) const
Returns the item flags for the given index in the model.
Definition: qdirmodel.cpp:486
QStringList mimeTypes() const
Returns a list of MIME types that can be used to describe a list of items in the model.
Definition: qdirmodel.cpp:540
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...
Definition: qdirmodel.cpp:1075
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
void clear(QDirNode *parent) const
Definition: qdirmodel.cpp:166
const QChar at(int i) const
Returns the character at the given index position in the string.
Definition: qstring.h:698
QDir dir() const
Returns the path of the object&#39;s parent directory as a QDir object.
Definition: qfileinfo.cpp:861
QString time(const QModelIndex &index) const
Definition: qdirmodel.cpp:1364
void qt_setDirModelShouldNotStat(QDirModelPrivate *modelPrivate)
Definition: qdirmodel.cpp:146
QModelIndex sibling(int row, int column) const
Returns the sibling at row and column.
#define it(className, varName)
QDir::SortFlags sort
Definition: qdirmodel.cpp:128
int count(const T &t) const
Returns the number of occurrences of value in the vector.
Definition: qvector.h:742
bool isRelative() const
Returns true if the directory path is relative; otherwise returns false.
Definition: qdir.cpp:1615
void setResolveSymlinks(bool enable)
Definition: qdirmodel.cpp:757
void chop(int n)
Removes n characters from the end of the string.
Definition: qstring.cpp:4623
static QFileInfo resolvedInfo(QFileInfo info)
Definition: qdirmodel.cpp:1396
QFileInfoList entryInfoList(const QString &path) const
Definition: qdirmodel.cpp:1295
QDir::SortFlags sorting() const
Returns the sorting method used for the directory model.
Definition: qdirmodel.cpp:741
QString fileName() const
Returns the name of the file, excluding the path.
Definition: qfileinfo.cpp:726
static void clear(QVariant::Private *d)
Definition: qvariant.cpp:197
iterator begin()
Returns an STL-style iterator pointing to the first item in the list.
Definition: qlist.h:267
QString toString() const
Returns the variant as a QString if the variant has type() String , Bool , ByteArray ...
Definition: qvariant.cpp:2270
const_iterator constBegin() const
Returns a const STL-style iterator pointing to the first item in the list.
Definition: qlist.h:269
QModelIndex createIndex(int row, int column, void *data=0) const
Creates a model index for the given row and column with the internal pointer ptr. ...
bool mkdir(const QString &dirName) const
Creates a sub-directory called dirName.
Definition: qdir.cpp:1424
bool startsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string starts with s; otherwise returns false.
Definition: qstring.cpp:3734
void 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
static QString tr(const char *sourceText, const char *comment=0, int n=-1)
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
bool exists() const
Returns true if the file exists; otherwise returns false.
Definition: qfileinfo.cpp:675
void setIconProvider(QFileIconProvider *provider)
Sets the provider of file icons for the directory model.
Definition: qdirmodel.cpp:643
void setCaching(bool on)
If enable is true, enables caching of file information.
Definition: qfileinfo.cpp:1364
The QStack class is a template class that provides a stack.
Definition: qcontainerfwd.h:63
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
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 ...
Definition: qdirmodel.cpp:574
QDirModel(const QStringList &nameFilters, QDir::Filters filters, QDir::SortFlags sort, QObject *parent=0)
Constructs a new directory model with the given parent.
Definition: qdirmodel.cpp:229
The QString class provides a Unicode character string.
Definition: qstring.h:83
QVector< QDirNode > children(QDirNode *parent, bool stat) const
Definition: qdirmodel.cpp:1213
QString type(const QModelIndex &index) const
Definition: qdirmodel.cpp:1359
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
The QVector class is a template class that provides a dynamic array.
Definition: qdatastream.h:64
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
bool empty() const
This function is provided for STL compatibility.
Definition: qvector.h:285
#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
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.
Definition: qlist.h:152
iterator insert(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
Definition: qhash.h:753
static QString translate(const char *context, const char *key, const char *disambiguation=0, Encoding encoding=CodecForTr)
#define Q_Q(Class)
Definition: qglobal.h:2483
T pop()
Removes the top item from the stack and returns it.
Definition: qstack.h:67
virtual Qt::ItemFlags flags(const QModelIndex &index) const
Returns the item flags for the given index.
QVector< QDirNode > children
Definition: qdirmodel.cpp:81
bool cdUp()
Changes directory by moving one directory up from the QDir&#39;s current directory.
Definition: qdir.cpp:937
SortOrder
Definition: qnamespace.h:189
static QString toString(Register *reg, int type, bool *ok=0)
void * data()
Definition: qvariant.cpp:3077
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 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
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
const QAbstractItemModel * model
unsigned __int64 quint64
Definition: qglobal.h:943
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
QString left(int n) const Q_REQUIRED_RESULT
Returns a substring that contains the n leftmost characters of the string.
Definition: qstring.cpp:3664
void layoutAboutToBeChanged()
This signal is emitted just before the layout of a model is changed.
void restorePersistentIndexes()
Definition: qdirmodel.cpp:1272
int size() const
Returns the number of characters in this string.
Definition: qstring.h:102
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
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the list...
Definition: qlist.h:270
int row() const
Returns the row this model index refers to.
const char * name
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
const QAbstractItemModel * model() const
Returns a pointer to the model containing the item that this index refers to.
bool isNull() const
Returns true if the icon is empty; otherwise returns false.
Definition: qicon.cpp:769
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
void setFile(const QString &file)
Sets the file that the QFileInfo provides information about to file.
Definition: qfileinfo.cpp:468
QStringList entryList(const QString &path) const
Definition: qdirmodel.cpp:1301
void appendChild(QDirModelPrivate::QDirNode *parent, const QString &path) const
Definition: qdirmodel.cpp:1374
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.
Definition: qmimedata.cpp:334
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
Definition: qstring.h:654
~QDirModel()
Destroys this directory model.
Definition: qdirmodel.cpp:270
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().
Definition: qdir.cpp:1316
QMimeData * mimeData(const QModelIndexList &indexes) const
Returns an object that contains a serialized description of the specified indexes.
Definition: qdirmodel.cpp:554
QList< QUrl > urls() const
Returns a list of URLs contained within the MIME data object.
Definition: qmimedata.cpp:310
void setFilter(QDir::Filters filters)
Sets the directory model&#39;s filter to that specified by filters.
Definition: qdirmodel.cpp:694
DropAction
Definition: qnamespace.h:1597
static QFileInfoList drives()
Returns a list of the root directories on this system.
Definition: qdir.cpp:1812
QFileIconProvider * iconProvider
Definition: qdirmodel.cpp:131
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.
Definition: qdirmodel.cpp:355
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
bool hasChildren(const QModelIndex &index=QModelIndex()) const
Returns true if the parent model item has children; otherwise returns false.
Definition: qdirmodel.cpp:465
The QMimeData class provides a container for data that records information about its MIME type...
Definition: qmimedata.h:57
void setSorting(QDir::SortFlags sort)
Sets the directory model&#39;s sorting order to that specified by sort.
Definition: qdirmodel.cpp:724
void push(const T &t)
Adds element t to the top of the stack.
Definition: qstack.h:60
QDirNode * node(int row, QDirNode *parent) const
Definition: qdirmodel.cpp:1195
bool isValid() const
Returns true if this model index is valid; otherwise returns false.
int count() const
Definition: qstring.h:103
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
void savePersistentIndexes()
Definition: qdirmodel.cpp:1257
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.
Definition: qdirmodel.cpp:986
bool isReadOnly() const
Definition: qdirmodel.cpp:788
T & first()
Returns a reference to the first item in the list.
Definition: qlist.h:282
static const char *const filters[3]
QString arg(qlonglong a, int fieldwidth=0, int base=10, const QChar &fillChar=QLatin1Char(' ')) const Q_REQUIRED_RESULT
Definition: qstring.cpp:7186
#define Q_DECLARE_PUBLIC(Class)
Definition: qglobal.h:2477
qint64 size() const
Returns the file size in bytes.
Definition: qfileinfo.cpp:1248
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
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.
Definition: qobject.h:273
QString toLower() const Q_REQUIRED_RESULT
Returns a lowercase copy of the string.
Definition: qstring.cpp:5389
bool rmdir(const QString &dirName) const
Removes the directory specified by dirName.
Definition: qdir.cpp:1448
The QModelIndex class is used to locate data in a data model.
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.
Definition: qdirmodel.cpp:281
void sort(int column, Qt::SortOrder order=Qt::AscendingOrder)
Sort the model items in the column using the order given.
Definition: qdirmodel.cpp:509
const QObjectList & children() const
Returns a list of child objects.
Definition: qobject.h:197
QString symLinkTarget() const
Returns the absolute path to the file or directory a symlink (or shortcut on Windows) points to...
Definition: qfileinfo.h:121
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
quint16 index
#define Q_OS_WIN
Definition: qglobal.h:270
QDir::Filters filters
Definition: qdirmodel.cpp:127
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
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...
Definition: qdirmodel.cpp:435
void setNameFilters(const QStringList &filters)
Sets the name filters for the directory model.
Definition: qdirmodel.cpp:663
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.
QPersistentModelIndex toBeRefreshed
Definition: qdirmodel.cpp:141
static QUrl fromLocalFile(const QString &localfile)
Returns a QUrl representation of localFile, interpreted as a local file.
Definition: qurl.cpp:6374
bool remove(const QString &fileName)
Removes the file, fileName.
Definition: qdir.cpp:1751
QString name(const QModelIndex &index) const
Definition: qdirmodel.cpp:1307
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 rmdir(const QModelIndex &index)
Removes the directory corresponding to the model item index in the directory model and deletes the co...
Definition: qdirmodel.cpp:1040
QPersistentModelIndex index
Definition: qdirmodel.cpp:138
QFileInfo fileInfo(const QModelIndex &index) const
Returns the file information for the specified model index.
Definition: qdirmodel.cpp:1161
iterator insertMulti(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
Definition: qhash.h:772
void setLazyChildCount(bool enable)
Definition: qdirmodel.cpp:810
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
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
void populate(QDirNode *parent) const
Definition: qdirmodel.cpp:159
QString dirName() const
Returns the name of the directory; this is not the same as the path, e.g.
Definition: qdir.cpp:663
Orientation
Definition: qnamespace.h:174
QModelIndex mkdir(const QModelIndex &parent, const QString &name)
Create a directory with the name in the parent model item.
Definition: qdirmodel.cpp:998
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729
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
QList< SavedPersistent > savedPersistent
Definition: qdirmodel.cpp:140
QIcon fileIcon(const QModelIndex &index) const
Returns the icons for the item stored in the model under the given index.
Definition: qdirmodel.cpp:1139
bool isWritable() const
Returns true if the user can write to the file; otherwise returns false.
Definition: qfileinfo.cpp:914
QString absolutePath() const
Returns a file&#39;s path absolute path.
Definition: qfileinfo.cpp:577
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...
Definition: qdir.cpp:1290
Qt::DropActions supportedDropActions() const
Returns the drop actions supported by this model.
Definition: qdirmodel.cpp:633
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55
QFileIconProvider defaultProvider
Definition: qdirmodel.cpp:132
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...
Definition: qdirmodel.cpp:406
QString size(const QModelIndex &index) const
Definition: qdirmodel.cpp:1326
bool link(const QString &newName)
Creates a link named linkName that points to the file currently specified by fileName().
Definition: qfile.cpp:877
QPersistentModelIndexData * data
Definition: qdirmodel.cpp:137
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...
Definition: qlist.h:272
QFileIconProvider * iconProvider() const
Returns the file icon provider for this directory model.
Definition: qdirmodel.cpp:653
The QIcon class provides scalable icons in different modes and states.
Definition: qicon.h:60
QStringList nameFilters
Definition: qdirmodel.cpp:129