QGIS API Documentation 3.99.0-Master (8e76e220402)
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_core.h"
21#include "qgis_sip.h"
23
24#include <QDateTime>
25#include <QString>
26#include <QTreeWidget>
27
28using namespace Qt::StringLiterals;
29
30class QFileSystemWatcher;
31class QMouseEvent;
32
37class CORE_EXPORT QgsDirectoryItem : public QgsDataCollectionItem
38{
39 Q_OBJECT
40 public:
41
52 QgsDirectoryItem( QgsDataItem *parent SIP_TRANSFERTHIS, const QString &name, const QString &path );
53
54
55 // TODO QGIS 5.0 -- rename "name" to "title" or "text" or something more descriptive, and "path" to something
56 // else to clarify the role of dirPath vs path
57
74 QgsDirectoryItem( QgsDataItem *parent SIP_TRANSFERTHIS, const QString &name, const QString &dirPath, const QString &path, const QString &providerKey = QString() );
75
76#ifdef SIP_RUN
77 SIP_PYOBJECT __repr__();
78 % MethodCode
79 QString str = u"<QgsDirectoryItem: %1 - %2>"_s.arg( sipCpp->dirPath(), sipCpp->path() );
80 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
81 % End
82#endif
83 void setState( Qgis::BrowserItemState state ) override;
84
85 QVector<QgsDataItem *> createChildren() override;
86
90 QString dirPath() const { return mDirPath; }
91
92 bool equal( const QgsDataItem *other ) override;
93 QIcon icon() override;
94
103 QColor iconColor() const;
104
116 void setIconColor( const QColor &color );
117
125 static void setCustomColor( const QString &directory, const QColor &color );
126
130 Q_DECL_DEPRECATED QWidget *paramWidget() override SIP_FACTORY SIP_DEPRECATED;
131 bool hasDragEnabled() const override { return true; }
132 QgsMimeDataUtils::UriList mimeUris() const override;
133
135 static bool hiddenPath( const QString &path );
136
147 static Qgis::BrowserDirectoryMonitoring monitoringForPath( const QString &path );
148
168 static bool pathShouldByMonitoredByDefault( const QString &path );
169
176 bool isMonitored() const { return mMonitored; }
177
184 Qgis::BrowserDirectoryMonitoring monitoring() const;
185
194 void setMonitoring( Qgis::BrowserDirectoryMonitoring monitoring );
195
203 void reevaluateMonitoring() SIP_SKIP;
204
205 public slots:
206 void childrenCreated() override;
207 void directoryChanged();
208
209 protected:
210
211 QString mDirPath;
212
213 private:
214
215 void init( const QString &dirName );
216
217 void createOrDestroyFileSystemWatcher();
218
219 Qgis::BrowserDirectoryMonitoring mMonitoring = Qgis::BrowserDirectoryMonitoring::Default;
220 bool mMonitored = true;
221 QFileSystemWatcher *mFileSystemWatcher = nullptr;
222 bool mRefreshLater = false;
223 QDateTime mLastScan;
224 QColor mIconColor;
225
226 bool mIsDir = false;
227 bool mIsSymLink = false;
228
229 friend class TestQgsDataItem;
230};
231
232// ---------
233
234// TODO: move to qgis_gui for QGIS 5
235
242class CORE_EXPORT QgsDirectoryParamWidget : public QTreeWidget
243{
244 Q_OBJECT
245
246 public:
247 QgsDirectoryParamWidget( const QString &path, QWidget *parent SIP_TRANSFERTHIS = nullptr );
248
249 protected:
250 void mousePressEvent( QMouseEvent *event ) override;
251
252 public slots:
253 void showHideColumn();
254};
255
256
257#ifndef SIP_RUN
258
264class CORE_EXPORT QgsProjectHomeItem : public QgsDirectoryItem
265{
266 Q_OBJECT
267
268 public:
269
273 QgsProjectHomeItem( QgsDataItem *parent, const QString &name, const QString &dirPath, const QString &path );
274
275 QIcon icon() override;
276 QVariant sortKey() const override;
277
278};
279
280#endif
281
282#endif // QGSDATAITEM_H
Provides global constants and enumerations for use throughout the application.
Definition qgis.h:59
BrowserItemState
Browser item states.
Definition qgis.h:957
BrowserDirectoryMonitoring
Browser directory item monitoring switches.
Definition qgis.h:1044
QgsDataCollectionItem(QgsDataItem *parent, const QString &name, const QString &path=QString(), const QString &providerKey=QString())
Constructor for QgsDataCollectionItem, with the specified parent item.
Base class for all items in the model.
Definition qgsdataitem.h:50
virtual QVariant sortKey() const
Returns the sorting key for the item.
QgsDataItem(Qgis::BrowserItemType type, QgsDataItem *parent, const QString &name, const QString &path, const QString &providerKey=QString())
Constructor for QgsDataItem, with the specified parent item.
virtual QVector< QgsDataItem * > createChildren()
Create children.
Qgis::BrowserItemState state() const
QString name() const
Returns the name of the item (the displayed text for the item).
QString path() const
virtual QIcon icon()
virtual void setState(Qgis::BrowserItemState state)
Set item state.
QgsDataItem * parent() const
Gets item parent.
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 ...
QString providerKey() const
Returns the provider key that created this item (e.g.
virtual bool equal(const QgsDataItem *other)
Returns true if this item is equal to another item (by testing item type and path).
friend class TestQgsDataItem
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.
QgsDirectoryItem(QgsDataItem *parent, const QString &name, const QString &path)
Constructor for QgsDirectoryItem, with the specified parent item.
bool hasDragEnabled() const override
Returns true if the item may be dragged.
void mousePressEvent(QMouseEvent *event) override
QgsDirectoryParamWidget(const QString &path, QWidget *parent=nullptr)
QList< QgsMimeDataUtils::Uri > UriList
QgsProjectHomeItem(QgsDataItem *parent, const QString &name, const QString &dirPath, const QString &path)
Constructor for QgsProjectHomeItem.
#define SIP_DEPRECATED
Definition qgis_sip.h:114
#define SIP_TRANSFERTHIS
Definition qgis_sip.h:53
#define SIP_SKIP
Definition qgis_sip.h:134
#define SIP_FACTORY
Definition qgis_sip.h:84