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 QSIDEBAR_H
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
25QT_REQUIRE_CONFIG(filedialog);
26
27QT_BEGIN_NAMESPACE
28
29class QFileSystemModel;
30
31class QSideBarDelegate : public QStyledItemDelegate
32{
33 public:
34 QSideBarDelegate(QWidget *parent = nullptr) : QStyledItemDelegate(parent) {}
35 void initStyleOption(QStyleOptionViewItem *option,
36 const QModelIndex &index) const override;
37};
38
39class Q_AUTOTEST_EXPORT QUrlModel : public QStandardItemModel
40{
41 Q_OBJECT
42
43public:
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
67private Q_SLOTS:
68 void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight);
69 void layoutChanged();
70
71private:
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};
86Q_DECLARE_TYPEINFO(QUrlModel::WatchItem, Q_RELOCATABLE_TYPE);
87
88class Q_AUTOTEST_EXPORT QSidebar : public QListView
89{
90 Q_OBJECT
91
92Q_SIGNALS:
93 void goToUrl(const QUrl &url);
94
95public:
96 QSidebar(QWidget *parent = nullptr);
97 void setModelAndUrls(QFileSystemModel *model, const QList<QUrl> &newUrls);
98 ~QSidebar();
99
100 QSize sizeHint() const override;
101
102 void setUrls(const QList<QUrl> &list) { urlModel->setUrls(list); }
103 void addUrls(const QList<QUrl> &list, int row) { urlModel->addUrls(urls: list, row); }
104 QList<QUrl> urls() const { return urlModel->urls(); }
105
106 void selectUrl(const QUrl &url);
107
108protected:
109 bool event(QEvent * e) override;
110 void focusInEvent(QFocusEvent *event) override;
111#if QT_CONFIG(draganddrop)
112 void dragEnterEvent(QDragEnterEvent *event) override;
113#endif
114
115private Q_SLOTS:
116 void clicked(const QModelIndex &index);
117#if QT_CONFIG(menu)
118 void showContextMenu(const QPoint &position);
119#endif
120 void removeEntry();
121
122private:
123 QUrlModel *urlModel;
124};
125
126QT_END_NAMESPACE
127
128#endif // QSIDEBAR_H
129
130

Provided by KDAB

Privacy Policy
Start learning QML with our Intro Training
Find out more

source code of qtbase/src/widgets/dialogs/qsidebar_p.h