QGIS API Documentation 3.99.0-Master (26c88405ac0)
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 <QTreeWidget>
26
27class QFileSystemWatcher;
28class QMouseEvent;
29
34class CORE_EXPORT QgsDirectoryItem : public QgsDataCollectionItem
35{
36 Q_OBJECT
37 public:
38
49 QgsDirectoryItem( QgsDataItem *parent SIP_TRANSFERTHIS, const QString &name, const QString &path );
50
51
52 // TODO QGIS 4.0 -- rename "name" to "title" or "text" or something more descriptive, and "path" to something
53 // else to clarify the role of dirPath vs path
54
71 QgsDirectoryItem( QgsDataItem *parent SIP_TRANSFERTHIS, const QString &name, const QString &dirPath, const QString &path, const QString &providerKey = QString() );
72
73#ifdef SIP_RUN
74 SIP_PYOBJECT __repr__();
75 % MethodCode
76 QString str = QStringLiteral( "<QgsDirectoryItem: %1 - %2>" ).arg( sipCpp->dirPath(), sipCpp->path() );
77 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
78 % End
79#endif
80 void setState( Qgis::BrowserItemState state ) override;
81
82 QVector<QgsDataItem *> createChildren() override;
83
87 QString dirPath() const { return mDirPath; }
88
89 bool equal( const QgsDataItem *other ) override;
90 QIcon icon() override;
91
100 QColor iconColor() const;
101
113 void setIconColor( const QColor &color );
114
122 static void setCustomColor( const QString &directory, const QColor &color );
123
127 Q_DECL_DEPRECATED QWidget *paramWidget() override SIP_FACTORY SIP_DEPRECATED;
128 bool hasDragEnabled() const override { return true; }
129 QgsMimeDataUtils::UriList mimeUris() const override;
130
132 static bool hiddenPath( const QString &path );
133
144 static Qgis::BrowserDirectoryMonitoring monitoringForPath( const QString &path );
145
165 static bool pathShouldByMonitoredByDefault( const QString &path );
166
173 bool isMonitored() const { return mMonitored; }
174
181 Qgis::BrowserDirectoryMonitoring monitoring() const;
182
191 void setMonitoring( Qgis::BrowserDirectoryMonitoring monitoring );
192
200 void reevaluateMonitoring() SIP_SKIP;
201
202 public slots:
203 void childrenCreated() override;
204 void directoryChanged();
205
206 protected:
207
208 QString mDirPath;
209
210 private:
211
212 void init( const QString &dirName );
213
214 void createOrDestroyFileSystemWatcher();
215
216 Qgis::BrowserDirectoryMonitoring mMonitoring = Qgis::BrowserDirectoryMonitoring::Default;
217 bool mMonitored = true;
218 QFileSystemWatcher *mFileSystemWatcher = nullptr;
219 bool mRefreshLater = false;
220 QDateTime mLastScan;
221 QColor mIconColor;
222
223 bool mIsDir = false;
224 bool mIsSymLink = false;
225
226 friend class TestQgsDataItem;
227};
228
229// ---------
230
231// TODO: move to qgis_gui for QGIS 4
232
239class CORE_EXPORT QgsDirectoryParamWidget : public QTreeWidget
240{
241 Q_OBJECT
242
243 public:
244 QgsDirectoryParamWidget( const QString &path, QWidget *parent SIP_TRANSFERTHIS = nullptr );
245
246 protected:
247 void mousePressEvent( QMouseEvent *event ) override;
248
249 public slots:
250 void showHideColumn();
251};
252
253
254#ifndef SIP_RUN
255
261class CORE_EXPORT QgsProjectHomeItem : public QgsDirectoryItem
262{
263 Q_OBJECT
264
265 public:
266
270 QgsProjectHomeItem( QgsDataItem *parent, const QString &name, const QString &dirPath, const QString &path );
271
272 QIcon icon() override;
273 QVariant sortKey() const override;
274
275};
276
277#endif
278
279#endif // QGSDATAITEM_H
Provides global constants and enumerations for use throughout the application.
Definition qgis.h:56
BrowserItemState
Browser item states.
Definition qgis.h:938
BrowserDirectoryMonitoring
Browser directory item monitoring switches.
Definition qgis.h:1025
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:47
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