qdirmodel.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. /****************************************************************************
  2. **
  3. ** Copyright (C) 2016 The Qt Company Ltd.
  4. ** Contact: https://www.qt.io/licensing/
  5. **
  6. ** This file is part of the QtWidgets 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 The Qt Company. For licensing terms
  14. ** and conditions see https://www.qt.io/terms-conditions. For further
  15. ** information use the contact form at https://www.qt.io/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 3 as published by the Free Software
  20. ** Foundation and appearing in the file LICENSE.LGPL3 included in the
  21. ** packaging of this file. Please review the following information to
  22. ** ensure the GNU Lesser General Public License version 3 requirements
  23. ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
  24. **
  25. ** GNU General Public License Usage
  26. ** Alternatively, this file may be used under the terms of the GNU
  27. ** General Public License version 2.0 or (at your option) the GNU General
  28. ** Public license version 3 or any later version approved by the KDE Free
  29. ** Qt Foundation. The licenses are as published by the Free Software
  30. ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
  31. ** included in the packaging of this file. Please review the following
  32. ** information to ensure the GNU General Public License requirements will
  33. ** be met: https://www.gnu.org/licenses/gpl-2.0.html and
  34. ** https://www.gnu.org/licenses/gpl-3.0.html.
  35. **
  36. ** $QT_END_LICENSE$
  37. **
  38. ****************************************************************************/
  39. #ifndef QDIRMODEL_H
  40. #define QDIRMODEL_H
  41. #include <QtCore/qabstractitemmodel.h>
  42. #include <QtCore/qdir.h>
  43. #include <QtWidgets/qfileiconprovider.h>
  44. QT_BEGIN_NAMESPACE
  45. #ifndef QT_NO_DIRMODEL
  46. class QDirModelPrivate;
  47. class Q_WIDGETS_EXPORT QDirModel : public QAbstractItemModel
  48. {
  49. Q_OBJECT
  50. Q_PROPERTY(bool resolveSymlinks READ resolveSymlinks WRITE setResolveSymlinks)
  51. Q_PROPERTY(bool readOnly READ isReadOnly WRITE setReadOnly)
  52. Q_PROPERTY(bool lazyChildCount READ lazyChildCount WRITE setLazyChildCount)
  53. public:
  54. enum Roles {
  55. FileIconRole = Qt::DecorationRole,
  56. FilePathRole = Qt::UserRole + 1,
  57. FileNameRole
  58. };
  59. QDirModel(const QStringList &nameFilters, QDir::Filters filters,
  60. QDir::SortFlags sort, QObject *parent = Q_NULLPTR);
  61. explicit QDirModel(QObject *parent = Q_NULLPTR);
  62. ~QDirModel();
  63. QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE;
  64. QModelIndex parent(const QModelIndex &child) const Q_DECL_OVERRIDE;
  65. int rowCount(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE;
  66. int columnCount(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE;
  67. QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const Q_DECL_OVERRIDE;
  68. bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) Q_DECL_OVERRIDE;
  69. QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const Q_DECL_OVERRIDE;
  70. bool hasChildren(const QModelIndex &index = QModelIndex()) const Q_DECL_OVERRIDE;
  71. Qt::ItemFlags flags(const QModelIndex &index) const Q_DECL_OVERRIDE;
  72. void sort(int column, Qt::SortOrder order = Qt::AscendingOrder) Q_DECL_OVERRIDE;
  73. QStringList mimeTypes() const Q_DECL_OVERRIDE;
  74. QMimeData *mimeData(const QModelIndexList &indexes) const Q_DECL_OVERRIDE;
  75. bool dropMimeData(const QMimeData *data, Qt::DropAction action,
  76. int row, int column, const QModelIndex &parent) Q_DECL_OVERRIDE;
  77. Qt::DropActions supportedDropActions() const Q_DECL_OVERRIDE;
  78. // QDirModel specific API
  79. void setIconProvider(QFileIconProvider *provider);
  80. QFileIconProvider *iconProvider() const;
  81. void setNameFilters(const QStringList &filters);
  82. QStringList nameFilters() const;
  83. void setFilter(QDir::Filters filters);
  84. QDir::Filters filter() const;
  85. void setSorting(QDir::SortFlags sort);
  86. QDir::SortFlags sorting() const;
  87. void setResolveSymlinks(bool enable);
  88. bool resolveSymlinks() const;
  89. void setReadOnly(bool enable);
  90. bool isReadOnly() const;
  91. void setLazyChildCount(bool enable);
  92. bool lazyChildCount() const;
  93. QModelIndex index(const QString &path, int column = 0) const;
  94. bool isDir(const QModelIndex &index) const;
  95. QModelIndex mkdir(const QModelIndex &parent, const QString &name);
  96. bool rmdir(const QModelIndex &index);
  97. bool remove(const QModelIndex &index);
  98. QString filePath(const QModelIndex &index) const;
  99. QString fileName(const QModelIndex &index) const;
  100. QIcon fileIcon(const QModelIndex &index) const;
  101. QFileInfo fileInfo(const QModelIndex &index) const;
  102. using QObject::parent;
  103. public Q_SLOTS:
  104. void refresh(const QModelIndex &parent = QModelIndex());
  105. protected:
  106. QDirModel(QDirModelPrivate &, QObject *parent = Q_NULLPTR);
  107. friend class QFileDialogPrivate;
  108. private:
  109. Q_DECLARE_PRIVATE(QDirModel)
  110. Q_DISABLE_COPY(QDirModel)
  111. Q_PRIVATE_SLOT(d_func(), void _q_refresh())
  112. };
  113. #endif // QT_NO_DIRMODEL
  114. QT_END_NAMESPACE
  115. #endif // QDIRMODEL_H