QGIS API Documentation 4.0.0-Norrköping (1ddcee3d0e4)
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:
51 QgsDirectoryItem( QgsDataItem *parent SIP_TRANSFERTHIS, const QString &name, const QString &path );
52
53
54 // TODO QGIS 5.0 -- rename "name" to "title" or "text" or something more descriptive, and "path" to something
55 // else to clarify the role of dirPath vs path
56
73 QgsDirectoryItem( QgsDataItem *parent SIP_TRANSFERTHIS, const QString &name, const QString &dirPath, const QString &path, const QString &providerKey = QString() );
74
75#ifdef SIP_RUN
76 // clang-format off
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// clang-format on
83#endif
84 void setState( Qgis::BrowserItemState state ) override;
85
86 QVector<QgsDataItem *> createChildren() override;
87
91 QString dirPath() const { return mDirPath; }
92
93 bool equal( const QgsDataItem *other ) override;
94 QIcon icon() override;
95
104 QColor iconColor() const;
105
117 void setIconColor( const QColor &color );
118
126 static void setCustomColor( const QString &directory, const QColor &color );
127
131 Q_DECL_DEPRECATED QWidget *paramWidget() override SIP_FACTORY SIP_DEPRECATED;
132 bool hasDragEnabled() const override { return true; }
133 QgsMimeDataUtils::UriList mimeUris() const override;
134
136 static bool hiddenPath( const QString &path );
137
148 static Qgis::BrowserDirectoryMonitoring monitoringForPath( const QString &path );
149
169 static bool pathShouldByMonitoredByDefault( const QString &path );
170
177 bool isMonitored() const { return mMonitored; }
178
185 Qgis::BrowserDirectoryMonitoring monitoring() const;
186
195 void setMonitoring( Qgis::BrowserDirectoryMonitoring monitoring );
196
204 void reevaluateMonitoring() SIP_SKIP;
205
206 public slots:
207 void childrenCreated() override;
208 void directoryChanged();
209
210 protected:
211 QString mDirPath;
212
213 private:
214 void init( const QString &dirName );
215
216 void createOrDestroyFileSystemWatcher();
217
218 Qgis::BrowserDirectoryMonitoring mMonitoring = Qgis::BrowserDirectoryMonitoring::Default;
219 bool mMonitored = true;
220 QFileSystemWatcher *mFileSystemWatcher = nullptr;
221 bool mRefreshLater = false;
222 QDateTime mLastScan;
223 QColor mIconColor;
224
225 bool mIsDir = false;
226 bool mIsSymLink = false;
227
228 friend class TestQgsDataItem;
229};
230
231// ---------
232
233// TODO: move to qgis_gui for QGIS 5
234
241class CORE_EXPORT QgsDirectoryParamWidget : public QTreeWidget
242{
243 Q_OBJECT
244
245 public:
246 QgsDirectoryParamWidget( const QString &path, QWidget *parent SIP_TRANSFERTHIS = nullptr );
247
248 protected:
249 void mousePressEvent( QMouseEvent *event ) override;
250
251 public slots:
252 void showHideColumn();
253};
254
255
256#ifndef SIP_RUN
257
263class CORE_EXPORT QgsProjectHomeItem : public QgsDirectoryItem
264{
265 Q_OBJECT
266
267 public:
271 QgsProjectHomeItem( QgsDataItem *parent, const QString &name, const QString &dirPath, const QString &path );
272
273 QIcon icon() override;
274 QVariant sortKey() const override;
275};
276
277#endif
278
279#endif // QGSDATAITEM_H
Provides global constants and enumerations for use throughout the application.
Definition qgis.h:62
BrowserItemState
Browser item states.
Definition qgis.h:964
BrowserDirectoryMonitoring
Browser directory item monitoring switches.
Definition qgis.h:1051
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:113
#define SIP_TRANSFERTHIS
Definition qgis_sip.h:52
#define SIP_SKIP
Definition qgis_sip.h:133
#define SIP_FACTORY
Definition qgis_sip.h:83