QGIS API Documentation  3.24.2-Tisler (13c1a02865)
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 
The Qgis class provides global constants for use throughout the application.
Definition: qgis.h:64
BrowserItemState
Browser item states.
Definition: qgis.h:281
BrowserDirectoryMonitoring
Browser directory item monitoring switches.
Definition: qgis.h:337
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.
Definition: qgsdataitem.cpp:96
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.
Definition: qgsdataitem.h:189
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 str(x)
Definition: qgis.cpp:37
#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