QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
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"
22 #include "qgsdatacollectionitem.h"
23 #include <QDateTime>
24 #include <QTreeWidget>
25 
26 class QFileSystemWatcher;
27 class QMouseEvent;
28 
33 class 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 
123  Q_DECL_DEPRECATED QWidget *paramWidget() override SIP_FACTORY SIP_DEPRECATED;
124  bool hasDragEnabled() const override { return true; }
125  QgsMimeDataUtils::UriList mimeUris() const override;
126 
128  static bool hiddenPath( const QString &path );
129 
140  static Qgis::BrowserDirectoryMonitoring monitoringForPath( const QString &path );
141 
161  static bool pathShouldByMonitoredByDefault( const QString &path );
162 
169  bool isMonitored() const { return mMonitored; }
170 
177  Qgis::BrowserDirectoryMonitoring monitoring() const;
178 
187  void setMonitoring( Qgis::BrowserDirectoryMonitoring monitoring );
188 
196  void reevaluateMonitoring() SIP_SKIP;
197 
198  public slots:
199  void childrenCreated() override;
200  void directoryChanged();
201 
202  protected:
203  void init();
204 
205  QString mDirPath;
206 
207  private:
208 
209  void createOrDestroyFileSystemWatcher();
210 
211  Qgis::BrowserDirectoryMonitoring mMonitoring = Qgis::BrowserDirectoryMonitoring::Default;
212  bool mMonitored = true;
213  QFileSystemWatcher *mFileSystemWatcher = nullptr;
214  bool mRefreshLater = false;
215  QDateTime mLastScan;
216  QColor mIconColor;
217 
218  friend class TestQgsDataItem;
219 };
220 
221 // ---------
222 
223 // TODO: move to qgis_gui for QGIS 4
224 
231 class CORE_EXPORT QgsDirectoryParamWidget : public QTreeWidget
232 {
233  Q_OBJECT
234 
235  public:
236  QgsDirectoryParamWidget( const QString &path, QWidget *parent SIP_TRANSFERTHIS = nullptr );
237 
238  protected:
239  void mousePressEvent( QMouseEvent *event ) override;
240 
241  public slots:
242  void showHideColumn();
243 };
244 
245 
246 #ifndef SIP_RUN
247 
254 class CORE_EXPORT QgsProjectHomeItem : public QgsDirectoryItem
255 {
256  Q_OBJECT
257 
258  public:
259 
263  QgsProjectHomeItem( QgsDataItem *parent, const QString &name, const QString &dirPath, const QString &path );
264 
265  QIcon icon() override;
266  QVariant sortKey() const override;
267 
268 };
269 
270 #endif
271 
272 #endif // QGSDATAITEM_H
273 
274 
QgsDataItem::icon
virtual QIcon icon()
Definition: qgsdataitem.cpp:162
QgsDataCollectionItem
A Collection: logical collection of layers or subcollections, e.g. GRASS location/mapset,...
Definition: qgsdatacollectionitem.h:28
Qgis::BrowserItemState
BrowserItemState
Browser item states.
Definition: qgis.h:367
QgsDataItem::sortKey
virtual QVariant sortKey() const
Returns the sorting key for the item.
Definition: qgsdataitem.cpp:96
QgsProjectHomeItem
A directory item showing the current project directory.
Definition: qgsdirectoryitem.h:254
QgsDirectoryItem::icon
QIcon icon() override
Definition: qgsdirectoryitem.cpp:154
QgsMimeDataUtils::UriList
QList< QgsMimeDataUtils::Uri > UriList
Definition: qgsmimedatautils.h:164
QgsDataItem::equal
virtual bool equal(const QgsDataItem *other)
Returns true if this item is equal to another item (by testing item type and path).
Definition: qgsdataitem.cpp:501
SIP_FACTORY
#define SIP_FACTORY
Definition: qgis_sip.h:76
QgsDirectoryItem::dirPath
QString dirPath() const
Returns the full path to the directory the item represents.
Definition: qgsdirectoryitem.h:86
SIP_DEPRECATED
#define SIP_DEPRECATED
Definition: qgis_sip.h:106
SIP_SKIP
#define SIP_SKIP
Definition: qgis_sip.h:126
QgsDirectoryItem
A directory: contains subdirectories and layers.
Definition: qgsdirectoryitem.h:33
QgsDataItem::paramWidget
virtual Q_DECL_DEPRECATED QWidget * paramWidget()
Returns source widget from data item for QgsBrowserPropertiesWidget.
Definition: qgsdataitem.h:189
qgis_sip.h
QgsDataItem::setState
virtual void setState(Qgis::BrowserItemState state)
Set item state.
Definition: qgsdataitem.cpp:557
Qgis::BrowserDirectoryMonitoring
BrowserDirectoryMonitoring
Browser directory item monitoring switches.
Definition: qgis.h:425
str
#define str(x)
Definition: qgis.cpp:37
qgsdatacollectionitem.h
QgsDirectoryParamWidget
Browser parameter widget implementation for directory items.
Definition: qgsdirectoryitem.h:231
Qgis
The Qgis class provides global constants for use throughout the application.
Definition: qgis.h:71
QgsDataItem::mimeUris
virtual QgsMimeDataUtils::UriList mimeUris() const
Returns mime URIs for the data item, most data providers will only return a single URI but some data ...
Definition: qgsdataitem.cpp:523
QgsDataItem
Base class for all items in the model.
Definition: qgsdataitem.h:45
QgsDirectoryItem::isMonitored
bool isMonitored() const
Returns true if the directory is currently being monitored for changes and the item auto-refreshed wh...
Definition: qgsdirectoryitem.h:169
SIP_TRANSFERTHIS
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:53
QgsDataItem::createChildren
virtual QVector< QgsDataItem * > createChildren()
Create children.
Definition: qgsdataitem.cpp:184