QGIS API Documentation 4.1.0-Master (376402f9aeb)
Loading...
Searching...
No Matches
qgsdirectoryitem.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsddirectoryitem.cpp
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
18#include "qgsdirectoryitem.h"
19
20#include "qgsapplication.h"
21#include "qgsdataitemprovider.h"
23#include "qgsfileutils.h"
24#include "qgsgdalutils.h"
25#include "qgsprojectitem.h"
26#include "qgssettings.h"
28#include "qgssettingstree.h"
29#include "qgszipitem.h"
30
31#include <QAction>
32#include <QDir>
33#include <QFileSystemWatcher>
34#include <QMenu>
35#include <QMouseEvent>
36#include <QString>
37#include <QTimer>
38
39#include "moc_qgsdirectoryitem.cpp"
40
41using namespace Qt::StringLiterals;
42
44 = new QgsSettingsEntryBool( u"monitor-directories-in-browser"_s, QgsSettingsTree::sTreeQgis, true, u"If true, directories are automatically monitored and refreshed in the browser when their contents change outside of QGIS."_s );
46 = new QgsSettingsEntryStringList( u"hiddenPaths"_s, QgsSettingsTree::sTreeBrowser, QStringList(), u"List of directory paths which should be hidden from the browser."_s );
48 = new QgsSettingsEntryStringList( u"disableMonitorItemUris"_s, QgsSettingsTree::sTreeQgis, QStringList(), u"List of browser item URIs for which automatic monitoring is explicitly disabled."_s );
50 = new QgsSettingsEntryStringList( u"alwaysMonitorItemUris"_s, QgsSettingsTree::sTreeQgis, QStringList(), u"List of browser item URIs for which automatic monitoring is always enabled, regardless of other monitoring rules."_s );
52 = new QgsSettingsEntryInteger( u"minscaninterval"_s, QgsSettingsTree::sTreeBrowser, 10000, u"Minimum interval (in milliseconds) between two successive scans of a directory in the browser."_s );
54 = new QgsSettingsEntryString( u"path-colors/%1"_s, QgsSettingsTree::sTreeBrowser, QString(), u"Custom icon color for a directory in the browser, keyed by the mangled directory path (slashes replaced with '|||'). Stored as a HexArgb string."_s );
55
57 = new QgsSettingsEntryVariant( u"directory-hidden-columns"_s, QgsSettingsTree::sTreeBrowser, QVariant( QVariantList() ), u"Indices of columns hidden in the directory browser parameter widget"_s );
58
59//
60// QgsDirectoryItem
61//
62
64 : QgsDataCollectionItem( parent, QDir::toNativeSeparators( name ), path )
65 , mDirPath( path )
66{
67 init( name );
68}
69
70QgsDirectoryItem::QgsDirectoryItem( QgsDataItem *parent, const QString &name, const QString &dirPath, const QString &path, const QString &providerKey )
71 : QgsDataCollectionItem( parent, QDir::toNativeSeparators( name ), path, providerKey )
72 , mDirPath( dirPath )
73{
74 init( name );
75}
76
77void QgsDirectoryItem::init( const QString &dirName )
78{
80 setToolTip( QDir::toNativeSeparators( mDirPath ) );
81
82 const QFileInfo fi { mDirPath };
83 mIsDir = fi.isDir();
84 mIsSymLink = fi.isSymLink();
85
86 mMonitoring = monitoringForPath( mDirPath );
87 switch ( mMonitoring )
88 {
91 break;
93 mMonitored = false;
94 break;
96 mMonitored = true;
97 break;
98 }
99
100 QString settingKey = mDirPath;
101 settingKey.replace( '/', "|||"_L1 );
102 if ( settingsCustomPathColor->exists( settingKey ) )
103 {
104 mIconColor = QColor( settingsCustomPathColor->value( settingKey ) );
105 }
106
107 // we want directories shown before files
108 setSortKey( u" %1"_s.arg( dirName ) );
109}
110
112{
113 mMonitoring = monitoringForPath( mDirPath );
114 switch ( mMonitoring )
115 {
118 break;
120 mMonitored = false;
121 break;
123 mMonitored = true;
124 break;
125 }
126
127 const QVector<QgsDataItem *> childItems = children();
128 for ( QgsDataItem *child : childItems )
129 {
130 if ( QgsDirectoryItem *dirItem = qobject_cast< QgsDirectoryItem *>( child ) )
131 dirItem->reevaluateMonitoring();
132 }
133
134 createOrDestroyFileSystemWatcher();
135}
136
137void QgsDirectoryItem::createOrDestroyFileSystemWatcher()
138{
139 if ( !mMonitored && mFileSystemWatcher )
140 {
141 mFileSystemWatcher->deleteLater();
142 mFileSystemWatcher = nullptr;
143 }
144 else if ( mMonitored && state() == Qgis::BrowserItemState::Populated && !mFileSystemWatcher )
145 {
146 mFileSystemWatcher = new QFileSystemWatcher( this );
147 mFileSystemWatcher->addPath( mDirPath );
148 connect( mFileSystemWatcher, &QFileSystemWatcher::directoryChanged, this, &QgsDirectoryItem::directoryChanged );
149 }
150}
151
153{
154 return mIconColor;
155}
156
157void QgsDirectoryItem::setIconColor( const QColor &color )
158{
159 if ( color == mIconColor )
160 return;
161
162 mIconColor = color;
163 emit dataChanged( this );
164}
165
166void QgsDirectoryItem::setCustomColor( const QString &directory, const QColor &color )
167{
168 QString settingKey = directory;
169 settingKey.replace( '/', "|||"_L1 );
170 if ( color.isValid() )
171 settingsCustomPathColor->setValue( color.name( QColor::HexArgb ), { settingKey } );
172 else
173 settingsCustomPathColor->remove( { settingKey } );
174}
175
177{
178 if ( mDirPath == QDir::homePath() )
179 return homeDirIcon( mIconColor, mIconColor.darker() );
180
181 // still loading? show the spinner
183 return QgsDataItem::icon();
184
185 // symbolic link? use link icon
186 if ( mIsDir && mIsSymLink )
187 {
188 return mIconColor.isValid() ? QgsApplication::getThemeIcon( u"/mIconFolderLinkParams.svg"_s, mIconColor, mIconColor.darker() ) : QgsApplication::getThemeIcon( u"/mIconFolderLink.svg"_s );
189 }
190
191 // loaded? show the open dir icon
193 return openDirIcon( mIconColor, mIconColor.darker() );
194
195 // show the closed dir icon
196 return iconDir( mIconColor, mIconColor.darker() );
197}
198
200{
201 return mMonitoring;
202}
203
205{
206 mMonitoring = monitoring;
207
208 QStringList noMonitorDirs = settingsDisableMonitorItemUris->value();
209 QStringList alwaysMonitorDirs = settingsAlwaysMonitorItemUris->value();
210
211 switch ( mMonitoring )
212 {
214 {
215 // remove disable/always setting for this path, so that default behavior is used
216 noMonitorDirs.removeAll( mDirPath );
217 settingsDisableMonitorItemUris->setValue( noMonitorDirs );
218
219 alwaysMonitorDirs.removeAll( mDirPath );
220 settingsAlwaysMonitorItemUris->setValue( alwaysMonitorDirs );
221
223 break;
224 }
225
227 {
228 if ( !noMonitorDirs.contains( mDirPath ) )
229 {
230 noMonitorDirs.append( mDirPath );
231 settingsDisableMonitorItemUris->setValue( noMonitorDirs );
232 }
233
234 alwaysMonitorDirs.removeAll( mDirPath );
235 settingsAlwaysMonitorItemUris->setValue( alwaysMonitorDirs );
236
237 mMonitored = false;
238 break;
239 }
240
242 {
243 noMonitorDirs.removeAll( mDirPath );
244 settingsDisableMonitorItemUris->setValue( noMonitorDirs );
245
246 if ( !alwaysMonitorDirs.contains( mDirPath ) )
247 {
248 alwaysMonitorDirs.append( mDirPath );
249 settingsAlwaysMonitorItemUris->setValue( alwaysMonitorDirs );
250 }
251
252 mMonitored = true;
253 break;
254 }
255 }
256
257 const QVector<QgsDataItem *> childItems = children();
258 for ( QgsDataItem *child : childItems )
259 {
260 if ( QgsDirectoryItem *dirItem = qobject_cast< QgsDirectoryItem *>( child ) )
261 dirItem->reevaluateMonitoring();
262 }
263
264 createOrDestroyFileSystemWatcher();
265}
266
267QVector<QgsDataItem *> QgsDirectoryItem::createChildren()
268{
269 QVector<QgsDataItem *> children;
270 const QDir dir( mDirPath );
271
272 const QList<QgsDataItemProvider *> providers = QgsApplication::dataItemProviderRegistry()->providers();
273
274 const QStringList entries = dir.entryList( QDir::AllDirs | QDir::NoDotAndDotDot, QDir::Name | QDir::IgnoreCase );
275 for ( const QString &subdir : entries )
276 {
277 if ( mRefreshLater )
278 {
280 return children;
281 }
282
283 const QString subdirPath = dir.absoluteFilePath( subdir );
284
285 QgsDebugMsgLevel( u"creating subdir: %1"_s.arg( subdirPath ), 2 );
286
287 const QString path = mPath + ( mPath.endsWith( '/' ) ? QString() : u"/"_s ) + subdir; // may differ from subdirPath
289 continue;
290
291 bool handledByProvider = false;
292 for ( QgsDataItemProvider *provider : providers )
293 {
294 if ( provider->handlesDirectoryPath( subdirPath ) )
295 {
296 handledByProvider = true;
297 break;
298 }
299 }
300 if ( handledByProvider )
301 continue;
302
303 QgsDirectoryItem *item = new QgsDirectoryItem( this, subdir, subdirPath, path );
304
305 // propagate signals up to top
306
307 children.append( item );
308 }
309
310 const QStringList fileEntries = dir.entryList( QDir::Dirs | QDir::NoDotAndDotDot | QDir::Files, QDir::Name );
311 for ( const QString &name : fileEntries )
312 {
313 if ( mRefreshLater )
314 {
316 return children;
317 }
318
319 const QString path = dir.absoluteFilePath( name );
320 const QFileInfo fileInfo( path );
321
322 if ( QgsGdalUtils::isVsiArchiveFileExtension( fileInfo.suffix() ) )
323 {
324 if ( QgsDataItem *item = QgsZipItem::itemFromPath( this, path, name, path ) )
325 {
326 children.append( item );
327 continue;
328 }
329 }
330
331 bool createdItem = false;
332 for ( QgsDataItemProvider *provider : providers )
333 {
334 const Qgis::DataItemProviderCapabilities capabilities = provider->capabilities();
335
336 if ( !( ( fileInfo.isFile() && ( capabilities & Qgis::DataItemProviderCapability::Files ) ) || ( fileInfo.isDir() && ( capabilities & Qgis::DataItemProviderCapability::Directories ) ) ) )
337 {
338 continue;
339 }
340
341 QgsDataItem *item = provider->createDataItem( path, this );
342 if ( item )
343 {
344 // 3rd party providers may not correctly set the ItemRepresentsFile capability, so force it here if we
345 // see that the item's path does match the original file path
346 if ( item->path() == path )
348
349 children.append( item );
350 createdItem = true;
351 }
352 }
353
354 if ( !createdItem )
355 {
356 // if item is a QGIS project, and no specific item provider has overridden handling of
357 // project items, then use the default project item behavior
358 if ( fileInfo.suffix().compare( "qgs"_L1, Qt::CaseInsensitive ) == 0 || fileInfo.suffix().compare( "qgz"_L1, Qt::CaseInsensitive ) == 0 )
359 {
360 QgsDataItem *item = new QgsProjectItem( this, fileInfo.completeBaseName(), path );
362 children.append( item );
363 continue;
364 }
365 }
366 }
367 return children;
368}
369
371{
373
374 if ( state == Qgis::BrowserItemState::Populated && mMonitored )
375 {
376 if ( !mFileSystemWatcher )
377 {
378 mFileSystemWatcher = new QFileSystemWatcher( this );
379 mFileSystemWatcher->addPath( mDirPath );
380 connect( mFileSystemWatcher, &QFileSystemWatcher::directoryChanged, this, &QgsDirectoryItem::directoryChanged );
381 }
382 mLastScan = QDateTime::currentDateTime();
383 }
385 {
386 if ( mFileSystemWatcher )
387 {
388 delete mFileSystemWatcher;
389 mFileSystemWatcher = nullptr;
390 }
391 }
392}
393
395{
396 // If the last scan was less than 10 seconds ago, skip this
397 if ( mLastScan.msecsTo( QDateTime::currentDateTime() ) < settingsMinScanInterval->value() )
398 {
399 return;
400 }
402 {
403 // schedule to refresh later, because refresh() simply returns if Populating
404 mRefreshLater = true;
405 }
406 else
407 {
408 // We definintely don't want the temporary files created by sqlite
409 // to re-trigger a refresh in an infinite loop.
410 disconnect( mFileSystemWatcher, &QFileSystemWatcher::directoryChanged, this, &QgsDirectoryItem::directoryChanged );
411 // QFileSystemWhatcher::directoryChanged is emitted when a
412 // file is created and not when it is closed/flushed.
413 //
414 // Delay to give to OS the time to complete writing the file
415 // this happens when a new file appears in the directory and
416 // the item's children thread will try to open the file with
417 // GDAL or OGR even if it is still being written.
418 QTimer::singleShot( 100, this, [this] { refresh(); } );
419 }
420}
421
422bool QgsDirectoryItem::hiddenPath( const QString &path )
423{
424 const QStringList hiddenItems = settingsHiddenPaths->value();
425 const int idx = hiddenItems.indexOf( path );
426 return ( idx > -1 );
427}
428
437
439{
440 // check through path's parent directories, to see if any have an explicit
441 // always/never monitor setting. If so, this path will inherit that setting
442 const QString originalPath = QDir::cleanPath( path );
443 QString currentPath = originalPath;
444 QString prevPath;
445 while ( currentPath != prevPath )
446 {
447 prevPath = currentPath;
448 currentPath = QFileInfo( currentPath ).path();
449
450 switch ( monitoringForPath( currentPath ) )
451 {
453 return false;
455 return true;
457 break;
458 }
459 }
460
461 // else if we know that the path is on a slow device, we don't monitor by default
462 // as this can be very expensive and slow down QGIS
463 // Add trailing slash or windows API functions like GetDriveTypeW won't identify
464 // UNC network drives correctly
465 if ( QgsFileUtils::pathIsSlowDevice( path.endsWith( '/' ) ? path : path + '/' ) )
466 return false;
467
468 // paths are monitored by default if no explicit setting is in place, and the user hasn't
469 // completely opted out of all browser monitoring
471}
472
474{
475 QgsDebugMsgLevel( u"mRefreshLater = %1"_s.arg( mRefreshLater ), 3 );
476
477 if ( mRefreshLater )
478 {
479 QgsDebugMsgLevel( u"directory changed during createChildren() -> refresh() again"_s, 3 );
480 mRefreshLater = false;
482 refresh();
483 }
484 else
485 {
487 }
488 // Re-connect the file watcher after all children have been created
489 if ( mFileSystemWatcher && mMonitored )
490 connect( mFileSystemWatcher, &QFileSystemWatcher::directoryChanged, this, &QgsDirectoryItem::directoryChanged );
491}
492
494{
495 //QgsDebugMsg ( mPath + " x " + other->mPath );
496 if ( type() != other->type() )
497 {
498 return false;
499 }
500 const QgsDirectoryItem *otherDirItem = qobject_cast< const QgsDirectoryItem * >( other );
501 if ( !otherDirItem )
502 return false;
503
504 return dirPath() == otherDirItem->dirPath();
505}
506
508{
509 return new QgsDirectoryParamWidget( mPath );
510}
511
513{
515 u.layerType = u"directory"_s;
516 u.name = mName;
517 u.uri = mDirPath;
518 u.filePath = path();
519 return { u };
520}
521
522//
523// QgsDirectoryParamWidget
524//
525QgsDirectoryParamWidget::QgsDirectoryParamWidget( const QString &path, QWidget *parent )
526 : QTreeWidget( parent )
527{
528 setRootIsDecorated( false );
529
530 // name, size, date, permissions, owner, group, type
531 setColumnCount( 7 );
532 QStringList labels;
533 labels << tr( "Name" ) << tr( "Size" ) << tr( "Date" ) << tr( "Permissions" ) << tr( "Owner" ) << tr( "Group" ) << tr( "Type" );
534 setHeaderLabels( labels );
535
536 const QIcon iconDirectory = QgsApplication::getThemeIcon( u"mIconFolder.svg"_s );
537 const QIcon iconFile = QgsApplication::getThemeIcon( u"mIconFile.svg"_s );
538 const QIcon iconDirLink = QgsApplication::getThemeIcon( u"mIconFolderLink.svg"_s );
539 const QIcon iconFileLink = QgsApplication::getThemeIcon( u"mIconFileLink.svg"_s );
540
541 QList<QTreeWidgetItem *> items;
542
543 const QDir dir( path );
544 const QStringList entries = dir.entryList( QDir::AllEntries | QDir::NoDotAndDotDot, QDir::Name | QDir::IgnoreCase );
545 for ( const QString &name : entries )
546 {
547 const QFileInfo fi( dir.absoluteFilePath( name ) );
548 QStringList texts;
549 texts << name;
550 QString size;
551 if ( fi.size() > 1024 )
552 {
553 size = u"%1 KiB"_s.arg( QLocale().toString( fi.size() / 1024.0, 'f', 1 ) );
554 }
555 else if ( fi.size() > 1.048576e6 )
556 {
557 size = u"%1 MiB"_s.arg( QLocale().toString( fi.size() / 1.048576e6, 'f', 1 ) );
558 }
559 else
560 {
561 size = u"%1 B"_s.arg( fi.size() );
562 }
563 texts << size;
564 texts << QLocale().toString( fi.lastModified(), QLocale::ShortFormat );
565 QString perm;
566 perm += fi.permission( QFile::ReadOwner ) ? 'r' : '-';
567 perm += fi.permission( QFile::WriteOwner ) ? 'w' : '-';
568 perm += fi.permission( QFile::ExeOwner ) ? 'x' : '-';
569 // QFile::ReadUser, QFile::WriteUser, QFile::ExeUser
570 perm += fi.permission( QFile::ReadGroup ) ? 'r' : '-';
571 perm += fi.permission( QFile::WriteGroup ) ? 'w' : '-';
572 perm += fi.permission( QFile::ExeGroup ) ? 'x' : '-';
573 perm += fi.permission( QFile::ReadOther ) ? 'r' : '-';
574 perm += fi.permission( QFile::WriteOther ) ? 'w' : '-';
575 perm += fi.permission( QFile::ExeOther ) ? 'x' : '-';
576 texts << perm;
577
578 texts << fi.owner();
579 texts << fi.group();
580
581 QString type;
582 QIcon icon;
583 if ( fi.isDir() && fi.isSymLink() )
584 {
585 type = tr( "folder" );
586 icon = iconDirLink;
587 }
588 else if ( fi.isDir() )
589 {
590 type = tr( "folder" );
591 icon = iconDirectory;
592 }
593 else if ( fi.isFile() && fi.isSymLink() )
594 {
595 type = tr( "file" );
596 icon = iconFileLink;
597 }
598 else if ( fi.isFile() )
599 {
600 type = tr( "file" );
601 icon = iconFile;
602 }
603
604 texts << type;
605
606 QTreeWidgetItem *item = new QTreeWidgetItem( texts );
607 item->setIcon( 0, icon );
608 items << item;
609 }
610
611 addTopLevelItems( items );
612
613 // hide columns that are not requested
614 const QList<QVariant> lst = settingsDirectoryHiddenColumns->value().toList();
615 for ( const QVariant &colVariant : lst )
616 {
617 setColumnHidden( colVariant.toInt(), true );
618 }
619}
620
622{
623 if ( event->button() == Qt::RightButton )
624 {
625 // show the popup menu
626 QMenu popupMenu;
627
628 QStringList labels;
629 labels << tr( "Name" ) << tr( "Size" ) << tr( "Date" ) << tr( "Permissions" ) << tr( "Owner" ) << tr( "Group" ) << tr( "Type" );
630 for ( int i = 0; i < labels.count(); i++ )
631 {
632 QAction *action = popupMenu.addAction( labels[i], this, &QgsDirectoryParamWidget::showHideColumn );
633 action->setObjectName( QString::number( i ) );
634 action->setCheckable( true );
635 action->setChecked( !isColumnHidden( i ) );
636 }
637
638 popupMenu.exec( event->globalPos() );
639 }
640}
641
643{
644 QAction *action = qobject_cast<QAction *>( sender() );
645 if ( !action )
646 return; // something is wrong
647
648 const int columnIndex = action->objectName().toInt();
649 setColumnHidden( columnIndex, !isColumnHidden( columnIndex ) );
650
651 // save in settings
652 QList<QVariant> lst;
653 for ( int i = 0; i < columnCount(); i++ )
654 {
655 if ( isColumnHidden( i ) )
656 lst.append( QVariant( i ) );
657 }
658 settingsDirectoryHiddenColumns->setValue( lst );
659}
660
661//
662// QgsProjectHomeItem
663//
664
665QgsProjectHomeItem::QgsProjectHomeItem( QgsDataItem *parent, const QString &name, const QString &dirPath, const QString &path )
666 : QgsDirectoryItem( parent, name, dirPath, path, u"special:ProjectHome"_s )
667{}
668
670{
672 return QgsDirectoryItem::icon();
673 return QgsApplication::getThemeIcon( u"mIconFolderProject.svg"_s );
674}
675
677{
678 return u" 1"_s;
679}
@ Files
Can provides items which corresponds to files.
Definition qgis.h:1045
@ Directories
Can provides items which corresponds to directories.
Definition qgis.h:1046
BrowserItemState
Browser item states.
Definition qgis.h:986
@ NotPopulated
Children not yet created.
Definition qgis.h:987
@ Populating
Creating children in separate thread (populating or refreshing).
Definition qgis.h:988
@ Populated
Children created.
Definition qgis.h:989
@ ItemRepresentsFile
Item's path() directly represents a file on disk.
Definition qgis.h:1007
BrowserDirectoryMonitoring
Browser directory item monitoring switches.
Definition qgis.h:1092
@ Default
Use default logic to determine whether directory should be monitored.
Definition qgis.h:1093
@ AlwaysMonitor
Always monitor the directory, regardless of the default logic.
Definition qgis.h:1095
@ NeverMonitor
Never monitor the directory, regardless of the default logic.
Definition qgis.h:1094
QFlags< DataItemProviderCapability > DataItemProviderCapabilities
Capabilities for data item providers.
Definition qgis.h:1059
@ Directory
Represents a file directory.
Definition qgis.h:969
static QgsDataItemProviderRegistry * dataItemProviderRegistry()
Returns the application's data item provider registry, which keeps a list of data item providers that...
static QIcon getThemeIcon(const QString &name, const QColor &fillColor=QColor(), const QColor &strokeColor=QColor())
Helper to get a theme icon.
static QIcon homeDirIcon(const QColor &fillColor=QColor(), const QColor &strokeColor=QColor())
Shared home directory icon.
QgsDataCollectionItem(QgsDataItem *parent, const QString &name, const QString &path=QString(), const QString &providerKey=QString())
Constructor for QgsDataCollectionItem, with the specified parent item.
static QIcon iconDir(const QColor &fillColor=QColor(), const QColor &strokeColor=QColor())
Returns the standard browser directory icon.
static QIcon openDirIcon(const QColor &fillColor=QColor(), const QColor &strokeColor=QColor())
Shared open directory icon.
QList< QgsDataItemProvider * > providers() const
Returns the list of available providers.
Interface for providers that add custom data items to the browser tree.
void setSortKey(const QVariant &key)
Sets a custom sorting key for the item.
QString mName
Qgis::BrowserItemType mType
void setToolTip(const QString &msg)
void dataChanged(QgsDataItem *item)
Emitted when data changes for an item.
QString mPath
QVector< QgsDataItem * > children() const
virtual void deleteLater()
Safely delete the item:
Qgis::BrowserItemType type() const
QgsDataItem(Qgis::BrowserItemType type, QgsDataItem *parent, const QString &name, const QString &path, const QString &providerKey=QString())
Constructor for QgsDataItem, with the specified parent item.
Qgis::BrowserItemState state() const
virtual void childrenCreated()
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.
virtual void setCapabilities(Qgis::BrowserItemCapabilities capabilities)
Sets the capabilities for the data item.
virtual void refresh()
QgsDataItem * parent() const
Gets item parent.
QString providerKey() const
Returns the provider key that created this item (e.g.
virtual Qgis::BrowserItemCapabilities capabilities2() const
Returns the capabilities for the data item.
static const QgsSettingsEntryString * settingsCustomPathColor
QVector< QgsDataItem * > createChildren() override
Create children.
Q_DECL_DEPRECATED QWidget * paramWidget() override
static Qgis::BrowserDirectoryMonitoring monitoringForPath(const QString &path)
Returns the monitoring setting for a directory path.
QgsMimeDataUtils::UriList mimeUris() const override
Returns mime URIs for the data item, most data providers will only return a single URI but some data ...
Qgis::BrowserDirectoryMonitoring monitoring() const
Returns the monitoring setting for this directory item.
static void setCustomColor(const QString &directory, const QColor &color)
Sets a custom icon color to use for the items for the corresponding directory path.
static const QgsSettingsEntryInteger * settingsMinScanInterval
bool equal(const QgsDataItem *other) override
Returns true if this item is equal to another item (by testing item type and path).
QString dirPath() const
Returns the full path to the directory the item represents.
void setMonitoring(Qgis::BrowserDirectoryMonitoring monitoring)
Sets the monitoring setting for this directory.
static const QgsSettingsEntryBool * settingsMonitorDirectoriesInBrowser
static const QgsSettingsEntryStringList * settingsHiddenPaths
QColor iconColor() const
Returns the directory's icon color.
void childrenCreated() override
void setIconColor(const QColor &color)
Sets the directory's icon color.
QgsDirectoryItem(QgsDataItem *parent, const QString &name, const QString &path)
Constructor for QgsDirectoryItem, with the specified parent item.
void reevaluateMonitoring()
Re-evaluate whether the directory item should be monitored for changes.
static bool hiddenPath(const QString &path)
Check if the given path is hidden from the browser model.
static const QgsSettingsEntryStringList * settingsAlwaysMonitorItemUris
void setState(Qgis::BrowserItemState state) override
Set item state.
static bool pathShouldByMonitoredByDefault(const QString &path)
Returns true if a directory path should be monitored by default.
QIcon icon() override
static const QgsSettingsEntryStringList * settingsDisableMonitorItemUris
Browser parameter widget implementation for directory items.
void mousePressEvent(QMouseEvent *event) override
QgsDirectoryParamWidget(const QString &path, QWidget *parent=nullptr)
static const QgsSettingsEntryVariant * settingsDirectoryHiddenColumns
static bool pathIsSlowDevice(const QString &path)
Returns true if the specified path is assumed to reside on a slow device, e.g.
static bool isVsiArchiveFileExtension(const QString &extension)
Returns true if a file extension is a supported archive style container (e.g.
QList< QgsMimeDataUtils::Uri > UriList
QIcon icon() override
QVariant sortKey() const override
Returns the sorting key for the item.
QgsProjectHomeItem(QgsDataItem *parent, const QString &name, const QString &dirPath, const QString &path)
Constructor for QgsProjectHomeItem.
Data item that can be used to represent QGIS projects.
A boolean settings entry.
An integer settings entry.
A string list settings entry.
A string settings entry.
A variant settings entry.
static QgsSettingsTreeNode * sTreeBrowser
static QgsSettingsTreeNode * sTreeQgis
static QgsDataItem * itemFromPath(QgsDataItem *parent, const QString &path, const QString &name)
Creates a new data item from the specified path.
#define QgsDebugMsgLevel(str, level)
Definition qgslogger.h:63
QString filePath
Path to file, if uri is associated with a file.
QString uri
Identifier of the data source recognized by its providerKey.
QString name
Human readable name to be used e.g. in layer tree.
QString layerType
Type of URI.