-
-
Notifications
You must be signed in to change notification settings - Fork 3k
/
qgsdirectoryitem.h
274 lines (227 loc) · 9.16 KB
/
qgsdirectoryitem.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
/***************************************************************************
qgsddirectoryitem.h
-------------------
begin : 2011-04-01
copyright : (C) 2011 Radim Blazek
email : radim dot blazek at gmail dot com
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#ifndef QGSDIRECTORYITEM_H
#define QGSDIRECTORYITEM_H
#include "qgis_sip.h"
#include "qgis_core.h"
#include "qgsdatacollectionitem.h"
#include <QDateTime>
#include <QTreeWidget>
class QFileSystemWatcher;
class QMouseEvent;
/**
* \ingroup core
* \brief A directory: contains subdirectories and layers
*/
class CORE_EXPORT QgsDirectoryItem : public QgsDataCollectionItem
{
Q_OBJECT
public:
/**
* Constructor for QgsDirectoryItem, with the specified \a parent item.
*
* The \a name argument specifies the text to show in the model for the item. This is usually
* the directory name, but in certain cases may differ for special directories (e.g. "Home").
* If a non-directory-name text is used, it should be a translated string when appropriate.
*
* The \a path argument specifies the directory path in the file system (e.g. "/home/gsherman/stuff"). A valid
* directory path must be specified.
*/
QgsDirectoryItem( QgsDataItem *parent SIP_TRANSFERTHIS, const QString &name, const QString &path );
// TODO QGIS 4.0 -- rename "name" to "title" or "text" or something more descriptive, and "path" to something
// else to clarify the role of dirPath vs path
/**
* Constructor for QgsDirectoryItem, with the specified \a parent item.
*
* The \a name argument specifies the text to show in the model for the item. This is usually
* the directory name, but in certain cases may differ for special directories (e.g. "Home").
* If a non-directory-name text is used, it should be a translated string when appropriate.
*
* The \a dirPath argument specifies the directory path in the file system (e.g. "/home/gsherman/stuff"). A valid
* directory path must be specified.
*
* The \a path argument gives the item path in the browser tree. The \a path string can take any form, but is usually
* the same as \a dirPath or \a dirPath with a prefix, e.g. "favorites:/home/gsherman/Downloads"). QgsDirectoryItem
* items pointing to different \a dirPaths should always use a different item \a path.
*
* The optional \a providerKey string can be used to specify the key for the QgsDataItemProvider that created this item.
*/
QgsDirectoryItem( QgsDataItem *parent SIP_TRANSFERTHIS, const QString &name, const QString &dirPath, const QString &path, const QString &providerKey = QString() );
#ifdef SIP_RUN
SIP_PYOBJECT __repr__();
% MethodCode
QString str = QStringLiteral( "<QgsDirectoryItem: %1 - %2>" ).arg( sipCpp->dirPath(), sipCpp->path() );
sipRes = PyUnicode_FromString( str.toUtf8().constData() );
% End
#endif
void setState( Qgis::BrowserItemState state ) override;
QVector<QgsDataItem *> createChildren() override;
/**
* Returns the full path to the directory the item represents.
*/
QString dirPath() const { return mDirPath; }
bool equal( const QgsDataItem *other ) override;
QIcon icon() override;
/**
* Returns the directory's icon color.
*
* An invalid color will be returned if the default icon color is used.
*
* \see setIconColor()
* \since QGIS 3.20
*/
QColor iconColor() const;
/**
* Sets the directory's icon \a color.
*
* Setting an invalid color will cause the default icon color to be used.
*
* This is a transient property, and will not permanently alter the directory's colors
* in future QGIS sessions. Use setCustomColor() to permanently set the directory's color.
*
* \see iconColor()
* \since QGIS 3.20
*/
void setIconColor( const QColor &color );
/**
* Sets a custom icon \a color to use for the items for the corresponding \a directory path.
*
* If \a color is an invalid color then the default icon color will be used.
*
* \since QGIS 3.20
*/
static void setCustomColor( const QString &directory, const QColor &color );
Q_DECL_DEPRECATED QWidget *paramWidget() override SIP_FACTORY SIP_DEPRECATED;
bool hasDragEnabled() const override { return true; }
QgsMimeDataUtils::UriList mimeUris() const override;
//! Check if the given path is hidden from the browser model
static bool hiddenPath( const QString &path );
/**
* Returns the monitoring setting for a directory \a path.
*
* This method returns the monitoring setting for \a path only. If no explicit monitoring setting
* is in place for the path then Qgis::BrowserDirectoryMonitoring::Default is returned.
*
* This method does not consider the monitoring setting of parent directories.
*
* \since QGIS 3.20
*/
static Qgis::BrowserDirectoryMonitoring monitoringForPath( const QString &path );
/**
* Returns TRUE if a directory \a path should be monitored by default.
*
* In the absence of any other settings this will dictate whether the directory is monitored. This method
* does not consider an explicit monitoring setting set for the path, which can be determined by
* calling monitoringForPath().
*
* All parent directories will be checked to determine whether they have monitoring
* manually enabled or disabled. As soon as a parent directory is found which has monitoring
* manually enabled or disabled then the corresponding value will be returned.
*
* If no explicit setting is in place for a parent directory, then a check will be made to determine
* whether the path resides on a known slow drive. If so, monitoring is disabled by default and
* FALSE will be returned. Otherwise paths are monitored by default and the function will return TRUE.
*
* \see isMonitored()
* \see setMonitoring()
* \since QGIS 3.20
*/
static bool pathShouldByMonitoredByDefault( const QString &path );
/**
* Returns TRUE if the directory is currently being monitored for changes and the item auto-refreshed
* when these occur.
*
* \since QGIS 3.20
*/
bool isMonitored() const { return mMonitored; }
/**
* Returns the monitoring setting for this directory item.
*
* \see setMonitoring()
* \since QGIS 3.20
*/
Qgis::BrowserDirectoryMonitoring monitoring() const;
/**
* Sets the \a monitoring setting for this directory.
*
* This is a persistent setting, which is saved in QSettings.
*
* \see monitoring()
* \since QGIS 3.20
*/
void setMonitoring( Qgis::BrowserDirectoryMonitoring monitoring );
public slots:
void childrenCreated() override;
void directoryChanged();
protected:
void init();
/**
* Re-evaluate whether the directory item should be monitored for changes.
*
* Should be called whenever the parent directory item's monitoring is overridden.
*
* \since QGIS 3.20
*/
void reevaluateMonitoring() SIP_SKIP;
QString mDirPath;
private:
void createOrDestroyFileSystemWatcher();
Qgis::BrowserDirectoryMonitoring mMonitoring = Qgis::BrowserDirectoryMonitoring::Default;
bool mMonitored = true;
QFileSystemWatcher *mFileSystemWatcher = nullptr;
bool mRefreshLater;
QDateTime mLastScan;
QColor mIconColor;
friend class TestQgsDataItem;
};
// ---------
// TODO: move to qgis_gui for QGIS 4
/**
* \ingroup core
* \class QgsDirectoryParamWidget
*
* \brief Browser parameter widget implementation for directory items.
*/
class CORE_EXPORT QgsDirectoryParamWidget : public QTreeWidget
{
Q_OBJECT
public:
QgsDirectoryParamWidget( const QString &path, QWidget *parent SIP_TRANSFERTHIS = nullptr );
protected:
void mousePressEvent( QMouseEvent *event ) override;
public slots:
void showHideColumn();
};
#ifndef SIP_RUN
/**
* \ingroup core
* \brief A directory item showing the current project directory.
* \note Not available in Python bindings.
* \since QGIS 3.0
*/
class CORE_EXPORT QgsProjectHomeItem : public QgsDirectoryItem
{
Q_OBJECT
public:
/**
* Constructor for QgsProjectHomeItem.
*/
QgsProjectHomeItem( QgsDataItem *parent, const QString &name, const QString &dirPath, const QString &path );
QIcon icon() override;
QVariant sortKey() const override;
};
#endif
#endif // QGSDATAITEM_H