QGIS API Documentation 4.1.0-Master (3b8ef1f72a3)
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;
33
38class CORE_EXPORT QgsDirectoryItem : public QgsDataCollectionItem
39{
40 Q_OBJECT
41 public:
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 // clang-format off
78 SIP_PYOBJECT __repr__();
79 % MethodCode
80 QString str = u"<QgsDirectoryItem: %1 - %2>"_s.arg( sipCpp->dirPath(), sipCpp->path() );
81 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
82 % End
83// clang-format on
84#endif
85 void setState( Qgis::BrowserItemState state ) override;
86
87 QVector<QgsDataItem *> createChildren() override;
88
92 QString dirPath() const { return mDirPath; }
93
94 bool equal( const QgsDataItem *other ) override;
95 QIcon icon() override;
96
105 QColor iconColor() const;
106
118 void setIconColor( const QColor &color );
119
127 static void setCustomColor( const QString &directory, const QColor &color );
128
132 Q_DECL_DEPRECATED QWidget *paramWidget() override SIP_FACTORY SIP_DEPRECATED;
133 bool hasDragEnabled() const override { return true; }
134 QgsMimeDataUtils::UriList mimeUris() const override;
135
137 static bool hiddenPath( const QString &path );
138
149 static Qgis::BrowserDirectoryMonitoring monitoringForPath( const QString &path );
150
170 static bool pathShouldByMonitoredByDefault( const QString &path );
171
172#ifndef SIP_RUN
173
179#endif
180
187 bool isMonitored() const { return mMonitored; }
188
195 Qgis::BrowserDirectoryMonitoring monitoring() const;
196
205 void setMonitoring( Qgis::BrowserDirectoryMonitoring monitoring );
206
214 void reevaluateMonitoring() SIP_SKIP;
215
216 public slots:
217 void childrenCreated() override;
218 void directoryChanged();
219
220 protected:
221 QString mDirPath;
222
223 private:
224 void init( const QString &dirName );
225
226 void createOrDestroyFileSystemWatcher();
227
228 Qgis::BrowserDirectoryMonitoring mMonitoring = Qgis::BrowserDirectoryMonitoring::Default;
229 bool mMonitored = true;
230 QFileSystemWatcher *mFileSystemWatcher = nullptr;
231 bool mRefreshLater = false;
232 QDateTime mLastScan;
233 QColor mIconColor;
234
235 bool mIsDir = false;
236 bool mIsSymLink = false;
237
238 friend class TestQgsDataItem;
239};
240
241// ---------
242
243// TODO: move to qgis_gui for QGIS 5
244
251class CORE_EXPORT QgsDirectoryParamWidget : public QTreeWidget
252{
253 Q_OBJECT
254
255 public:
256 QgsDirectoryParamWidget( const QString &path, QWidget *parent SIP_TRANSFERTHIS = nullptr );
257
258 protected:
259 void mousePressEvent( QMouseEvent *event ) override;
260
261 public slots:
262 void showHideColumn();
263};
264
265
266#ifndef SIP_RUN
267
273class CORE_EXPORT QgsProjectHomeItem : public QgsDirectoryItem
274{
275 Q_OBJECT
276
277 public:
281 QgsProjectHomeItem( QgsDataItem *parent, const QString &name, const QString &dirPath, const QString &path );
282
283 QIcon icon() override;
284 QVariant sortKey() const override;
285};
286
287#endif
288
289#endif // QGSDATAITEM_H
Provides global constants and enumerations for use throughout the application.
Definition qgis.h:62
BrowserItemState
Browser item states.
Definition qgis.h:985
BrowserDirectoryMonitoring
Browser directory item monitoring switches.
Definition qgis.h:1091
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.
static const QgsSettingsEntryBool * settingsMonitorDirectoriesInBrowser
Settings entry for monitor directories in browser.
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.
A boolean settings entry.
#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