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 | |
51 | QStringList mimeTypes() const override; |
52 | QMimeData *mimeData(const QModelIndexList &indexes) const override; |
53 | #if QT_CONFIG(draganddrop) |
54 | bool canDrop(QDragEnterEvent *event); |
55 | bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) override; |
56 | #endif |
57 | Qt::ItemFlags flags(const QModelIndex &index) const override; |
58 | bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole) override; |
59 | |
60 | void setUrls(const QList<QUrl> &list); |
61 | void addUrls(const QList<QUrl> &urls, int row = -1, bool move = true); |
62 | QList<QUrl> urls() const; |
63 | void setFileSystemModel(QFileSystemModel *model); |
64 | bool showFullPath; |
65 | |
66 | private Q_SLOTS: |
67 | void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight); |
68 | void layoutChanged(); |
69 | |
70 | private: |
71 | void setUrl(const QModelIndex &index, const QUrl &url, const QModelIndex &dirIndex); |
72 | void changed(const QString &path); |
73 | void addIndexToWatch(const QString &path, const QModelIndex &index); |
74 | QFileSystemModel *fileSystemModel; |
75 | struct WatchItem { |
76 | QModelIndex index; |
77 | QString path; |
78 | }; |
79 | friend class QTypeInfo<WatchItem>; |
80 | |
81 | QList<WatchItem> watching; |
82 | QList<QUrl> invalidUrls; |
83 | }; |
84 | Q_DECLARE_TYPEINFO(QUrlModel::WatchItem, Q_RELOCATABLE_TYPE); |
85 | |
86 | class Q_AUTOTEST_EXPORT : public QListView |
87 | { |
88 | Q_OBJECT |
89 | |
90 | Q_SIGNALS: |
91 | void (const QUrl &url); |
92 | |
93 | public: |
94 | (QWidget *parent = nullptr); |
95 | void setModelAndUrls(QFileSystemModel *model, const QList<QUrl> &newUrls); |
96 | (); |
97 | |
98 | QSize () const override; |
99 | |
100 | void (const QList<QUrl> &list) { urlModel->setUrls(list); } |
101 | void (const QList<QUrl> &list, int row) { urlModel->addUrls(urls: list, row); } |
102 | QList<QUrl> () const { return urlModel->urls(); } |
103 | |
104 | void (const QUrl &url); |
105 | |
106 | protected: |
107 | bool (QEvent * e) override; |
108 | void (QFocusEvent *event) override; |
109 | #if QT_CONFIG(draganddrop) |
110 | void (QDragEnterEvent *event) override; |
111 | #endif |
112 | |
113 | private Q_SLOTS: |
114 | void (const QModelIndex &index); |
115 | #if QT_CONFIG(menu) |
116 | void (const QPoint &position); |
117 | #endif |
118 | void (); |
119 | |
120 | private: |
121 | QUrlModel *; |
122 | }; |
123 | |
124 | QT_END_NAMESPACE |
125 | |
126 | #endif // QSIDEBAR_H |
127 | |
128 | |