QGIS API Documentation 3.41.0-Master (af5edcb665c)
Loading...
Searching...
No Matches
qgsdirectoryitem.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsddirectoryitem.h
3 -------------------
4 begin : 2011-04-01
5 copyright : (C) 2011 Radim Blazek
6 email : radim dot blazek at gmail dot com
7 ***************************************************************************/
8
9/***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
17#ifndef QGSDIRECTORYITEM_H
18#define QGSDIRECTORYITEM_H
19
20#include "qgis_sip.h"
21#include "qgis_core.h"
23#include <QDateTime>
24#include <QTreeWidget>
25
26class QFileSystemWatcher;
27class QMouseEvent;
28
33class CORE_EXPORT QgsDirectoryItem : public QgsDataCollectionItem
34{
35 Q_OBJECT
36 public:
37
48 QgsDirectoryItem( QgsDataItem *parent SIP_TRANSFERTHIS, const QString &name, const QString &path );
49
50
51 // TODO QGIS 4.0 -- rename "name" to "title" or "text" or something more descriptive, and "path" to something
52 // else to clarify the role of dirPath vs path
53
70 QgsDirectoryItem( QgsDataItem *parent SIP_TRANSFERTHIS, const QString &name, const QString &dirPath, const QString &path, const QString &providerKey = QString() );
71
72#ifdef SIP_RUN
73 SIP_PYOBJECT __repr__();
74 % MethodCode
75 QString str = QStringLiteral( "<QgsDirectoryItem: %1 - %2>" ).arg( sipCpp->dirPath(), sipCpp->path() );
76 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
77 % End
78#endif
79 void setState( Qgis::BrowserItemState state ) override;
80
81 QVector<QgsDataItem *> createChildren() override;
82
86 QString dirPath() const { return mDirPath; }
87
88 bool equal( const QgsDataItem *other ) override;
89 QIcon icon() override;
90
99 QColor iconColor() const;
100
112 void setIconColor( const QColor &color );
113
121 static void setCustomColor( const QString &directory, const QColor &color );
122
126 Q_DECL_DEPRECATED QWidget *paramWidget() override SIP_FACTORY SIP_DEPRECATED;
127 bool hasDragEnabled() const override { return true; }
128 QgsMimeDataUtils::UriList mimeUris() const override;
129
131 static bool hiddenPath( const QString &path );
132
143 static Qgis::BrowserDirectoryMonitoring monitoringForPath( const QString &path );
144
164 static bool pathShouldByMonitoredByDefault( const QString &path );
165
172 bool isMonitored() const { return mMonitored; }
173
180 Qgis::BrowserDirectoryMonitoring monitoring() const;
181
190 void setMonitoring( Qgis::BrowserDirectoryMonitoring monitoring );
191
199 void reevaluateMonitoring() SIP_SKIP;
200
201 public slots:
202 void childrenCreated() override;
203 void directoryChanged();
204
205 protected:
206
207 QString mDirPath;
208
209 private:
210
211 void init( const QString &dirName );
212
213 void createOrDestroyFileSystemWatcher();
214
215 Qgis::BrowserDirectoryMonitoring mMonitoring = Qgis::BrowserDirectoryMonitoring::Default;
216 bool mMonitored = true;
217 QFileSystemWatcher *mFileSystemWatcher = nullptr;
218 bool mRefreshLater = false;
219 QDateTime mLastScan;
220 QColor mIconColor;
221
222 bool mIsDir = false;
223 bool mIsSymLink = false;
224
225 friend class TestQgsDataItem;
226};
227
228// ---------
229
230// TODO: move to qgis_gui for QGIS 4
231
238class CORE_EXPORT QgsDirectoryParamWidget : public QTreeWidget
239{
240 Q_OBJECT
241
242 public:
243 QgsDirectoryParamWidget( const QString &path, QWidget *parent SIP_TRANSFERTHIS = nullptr );
244
245 protected:
246 void mousePressEvent( QMouseEvent *event ) override;
247
248 public slots:
249 void showHideColumn();
250};
251
252
253#ifndef SIP_RUN
254
260class CORE_EXPORT QgsProjectHomeItem : public QgsDirectoryItem
261{
262 Q_OBJECT
263
264 public:
265
269 QgsProjectHomeItem( QgsDataItem *parent, const QString &name, const QString &dirPath, const QString &path );
270
271 QIcon icon() override;
272 QVariant sortKey() const override;
273
274};
275
276#endif
277
278#endif // QGSDATAITEM_H
The Qgis class provides global constants for use throughout the application.
Definition qgis.h:54
BrowserItemState
Browser item states.
Definition qgis.h:872
BrowserDirectoryMonitoring
Browser directory item monitoring switches.
Definition qgis.h:959
A Collection: logical collection of layers or subcollections, e.g.
Base class for all items in the model.
Definition qgsdataitem.h:46
virtual QVariant sortKey() const
Returns the sorting key for the item.
virtual QVector< QgsDataItem * > createChildren()
Create children.
virtual QIcon icon()
virtual void setState(Qgis::BrowserItemState state)
Set item state.
virtual Q_DECL_DEPRECATED QWidget * paramWidget()
Returns source widget from data item for QgsBrowserPropertiesWidget.
virtual QgsMimeDataUtils::UriList mimeUris() const
Returns mime URIs for the data item, most data providers will only return a single URI but some data ...
virtual bool equal(const QgsDataItem *other)
Returns true if this item is equal to another item (by testing item type and path).
A directory: contains subdirectories and layers.
bool isMonitored() const
Returns true if the directory is currently being monitored for changes and the item auto-refreshed wh...
QString dirPath() const
Returns the full path to the directory the item represents.
Browser parameter widget implementation for directory items.
QList< QgsMimeDataUtils::Uri > UriList
A directory item showing the current project directory.
#define SIP_DEPRECATED
Definition qgis_sip.h:106
#define SIP_TRANSFERTHIS
Definition qgis_sip.h:53
#define SIP_SKIP
Definition qgis_sip.h:126
#define SIP_FACTORY
Definition qgis_sip.h:76