1 | // Copyright (C) 2016 The Qt Company Ltd. |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
3 | |
4 | #ifndef QSIDEBAR_H |
5 | #define |
6 | |
7 | // |
8 | // W A R N I N G |
9 | // ------------- |
10 | // |
11 | // This file is not part of the Qt API. It exists purely as an |
12 | // implementation detail. This header file may change from version to |
13 | // version without notice, or even be removed. |
14 | // |
15 | // We mean it. |
16 | // |
17 | |
18 | #include <QtWidgets/private/qtwidgetsglobal_p.h> |
19 | #include <qlist.h> |
20 | #include <qlistview.h> |
21 | #include <qstandarditemmodel.h> |
22 | #include <qstyleditemdelegate.h> |
23 | #include <qurl.h> |
24 | |
25 | QT_REQUIRE_CONFIG(filedialog); |
26 | |
27 | QT_BEGIN_NAMESPACE |
28 | |
29 | class QFileSystemModel; |
30 | |
31 | class : public QStyledItemDelegate |
32 | { |
33 | public: |
34 | (QWidget *parent = nullptr) : QStyledItemDelegate(parent) {} |
35 | void (QStyleOptionViewItem *option, |
36 | const QModelIndex &index) const override; |
37 | }; |
38 | |
39 | class Q_AUTOTEST_EXPORT QUrlModel : public QStandardItemModel |
40 | { |
41 | Q_OBJECT |
42 | |
43 | public: |
44 | enum Roles { |
45 | UrlRole = Qt::UserRole + 1, |
46 | EnabledRole = Qt::UserRole + 2 |
47 | }; |
48 | |
49 | QUrlModel(QObject *parent = nullptr); |
50 | ~QUrlModel(); |
51 | |
52 | QStringList mimeTypes() const override; |
53 | QMimeData *mimeData(const QModelIndexList &indexes) const override; |
54 | #if QT_CONFIG(draganddrop) |
55 | bool canDrop(QDragEnterEvent *event); |
56 | bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) override; |
57 | #endif |
58 | Qt::ItemFlags flags(const QModelIndex &index) const override; |
59 | bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole) override; |
60 | |
61 | void setUrls(const QList<QUrl> &list); |
62 | void addUrls(const QList<QUrl> &urls, int row = -1, bool move = true); |
63 | QList<QUrl> urls() const; |
64 | void setFileSystemModel(QFileSystemModel *model); |
65 | bool showFullPath; |
66 | |
67 | private Q_SLOTS: |
68 | void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight); |
69 | void layoutChanged(); |
70 | |
71 | private: |
72 | void setUrl(const QModelIndex &index, const QUrl &url, const QModelIndex &dirIndex); |
73 | void changed(const QString &path); |
74 | void addIndexToWatch(const QString &path, const QModelIndex &index); |
75 | QFileSystemModel *fileSystemModel; |
76 | struct WatchItem { |
77 | QModelIndex index; |
78 | QString path; |
79 | }; |
80 | friend class QTypeInfo<WatchItem>; |
81 | |
82 | QList<WatchItem> watching; |
83 | QList<QUrl> invalidUrls; |
84 | std::array<QMetaObject::Connection, 3> modelConnections; |
85 | }; |
86 | Q_DECLARE_TYPEINFO(QUrlModel::WatchItem, Q_RELOCATABLE_TYPE); |
87 | |
88 | class Q_AUTOTEST_EXPORT : public QListView |
89 | { |
90 | Q_OBJECT |
91 | |
92 | Q_SIGNALS: |
93 | void (const QUrl &url); |
94 | |
95 | public: |
96 | (QWidget *parent = nullptr); |
97 | void setModelAndUrls(QFileSystemModel *model, const QList<QUrl> &newUrls); |
98 | (); |
99 | |
100 | QSize () const override; |
101 | |
102 | void (const QList<QUrl> &list) { urlModel->setUrls(list); } |
103 | void (const QList<QUrl> &list, int row) { urlModel->addUrls(urls: list, row); } |
104 | QList<QUrl> () const { return urlModel->urls(); } |
105 | |
106 | void (const QUrl &url); |
107 | |
108 | protected: |
109 | bool (QEvent * e) override; |
110 | void (QFocusEvent *event) override; |
111 | #if QT_CONFIG(draganddrop) |
112 | void (QDragEnterEvent *event) override; |
113 | #endif |
114 | |
115 | private Q_SLOTS: |
116 | void (const QModelIndex &index); |
117 | #if QT_CONFIG(menu) |
118 | void (const QPoint &position); |
119 | #endif |
120 | void (); |
121 | |
122 | private: |
123 | QUrlModel *; |
124 | }; |
125 | |
126 | QT_END_NAMESPACE |
127 | |
128 | #endif // QSIDEBAR_H |
129 | |
130 | |