QGIS API Documentation 3.34.0-Prizren (ffbdd678812)
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#include "qgssettings.h"
20#include "qgsapplication.h"
21#include "qgsdataitemprovider.h"
23#include "qgsdataprovider.h"
24#include "qgszipitem.h"
25#include "qgsprojectitem.h"
26#include "qgsfileutils.h"
27#include "qgsgdalutils.h"
28#include <QFileSystemWatcher>
29#include <QDir>
30#include <QMouseEvent>
31#include <QTimer>
32#include <QMenu>
33#include <QAction>
34
35//
36// QgsDirectoryItem
37//
38
39QgsDirectoryItem::QgsDirectoryItem( QgsDataItem *parent, const QString &name, const QString &path )
40 : QgsDataCollectionItem( parent, QDir::toNativeSeparators( name ), path )
41 , mDirPath( path )
42{
43 init( name );
44}
45
46QgsDirectoryItem::QgsDirectoryItem( QgsDataItem *parent, const QString &name,
47 const QString &dirPath, const QString &path,
48 const QString &providerKey )
49 : QgsDataCollectionItem( parent, QDir::toNativeSeparators( name ), path, providerKey )
50 , mDirPath( dirPath )
51{
52 init( name );
53}
54
55void QgsDirectoryItem::init( const QString &dirName )
56{
58 setToolTip( QDir::toNativeSeparators( mDirPath ) );
59
60 QgsSettings settings;
61
62 mMonitoring = monitoringForPath( mDirPath );
63 switch ( mMonitoring )
64 {
67 break;
69 mMonitored = false;
70 break;
72 mMonitored = true;
73 break;
74 }
75
76 settings.beginGroup( QStringLiteral( "qgis/browserPathColors" ) );
77 QString settingKey = mDirPath;
78 settingKey.replace( '/', QLatin1String( "|||" ) );
79 if ( settings.childKeys().contains( settingKey ) )
80 {
81 const QString colorString = settings.value( settingKey ).toString();
82 mIconColor = QColor( colorString );
83 }
84 settings.endGroup();
85
86 // we want directories shown before files
87 setSortKey( QStringLiteral( " %1" ).arg( dirName ) );
88}
89
91{
92 mMonitoring = monitoringForPath( mDirPath );
93 switch ( mMonitoring )
94 {
97 break;
99 mMonitored = false;
100 break;
102 mMonitored = true;
103 break;
104 }
105
106 const QVector<QgsDataItem *> childItems = children();
107 for ( QgsDataItem *child : childItems )
108 {
109 if ( QgsDirectoryItem *dirItem = qobject_cast< QgsDirectoryItem *>( child ) )
110 dirItem->reevaluateMonitoring();
111 }
112
113 createOrDestroyFileSystemWatcher();
114}
115
116void QgsDirectoryItem::createOrDestroyFileSystemWatcher()
117{
118 if ( !mMonitored && mFileSystemWatcher )
119 {
120 mFileSystemWatcher->deleteLater();
121 mFileSystemWatcher = nullptr;
122 }
123 else if ( mMonitored && state() == Qgis::BrowserItemState::Populated && !mFileSystemWatcher )
124 {
125 mFileSystemWatcher = new QFileSystemWatcher( this );
126 mFileSystemWatcher->addPath( mDirPath );
127 connect( mFileSystemWatcher, &QFileSystemWatcher::directoryChanged, this, &QgsDirectoryItem::directoryChanged );
128 }
129}
130
132{
133 return mIconColor;
134}
135
136void QgsDirectoryItem::setIconColor( const QColor &color )
137{
138 if ( color == mIconColor )
139 return;
140
141 mIconColor = color;
142 emit dataChanged( this );
143}
144
145void QgsDirectoryItem::setCustomColor( const QString &directory, const QColor &color )
146{
147 QgsSettings settings;
148 settings.beginGroup( QStringLiteral( "qgis/browserPathColors" ) );
149 QString settingKey = directory;
150 settingKey.replace( '/', QLatin1String( "|||" ) );
151 if ( color.isValid() )
152 settings.setValue( settingKey, color.name( QColor::HexArgb ) );
153 else
154 settings.remove( settingKey );
155 settings.endGroup();
156}
157
159{
160 if ( mDirPath == QDir::homePath() )
161 return homeDirIcon( mIconColor, mIconColor.darker() );
162
163 // still loading? show the spinner
165 return QgsDataItem::icon();
166
167 // symbolic link? use link icon
168 const QFileInfo fi( mDirPath );
169 if ( fi.isDir() && fi.isSymLink() )
170 {
171 return mIconColor.isValid()
172 ? QgsApplication::getThemeIcon( QStringLiteral( "/mIconFolderLinkParams.svg" ), mIconColor, mIconColor.darker() )
173 : QgsApplication::getThemeIcon( QStringLiteral( "/mIconFolderLink.svg" ) );
174 }
175
176 // loaded? show the open dir icon
178 return openDirIcon( mIconColor, mIconColor.darker() );
179
180 // show the closed dir icon
181 return iconDir( mIconColor, mIconColor.darker() );
182}
183
185{
186 return mMonitoring;
187}
188
190{
191 mMonitoring = monitoring;
192
193 QgsSettings settings;
194 QStringList noMonitorDirs = settings.value( QStringLiteral( "qgis/disableMonitorItemUris" ), QStringList() ).toStringList();
195 QStringList alwaysMonitorDirs = settings.value( QStringLiteral( "qgis/alwaysMonitorItemUris" ), QStringList() ).toStringList();
196
197 switch ( mMonitoring )
198 {
200 {
201 // remove disable/always setting for this path, so that default behavior is used
202 noMonitorDirs.removeAll( mDirPath );
203 settings.setValue( QStringLiteral( "qgis/disableMonitorItemUris" ), noMonitorDirs );
204
205 alwaysMonitorDirs.removeAll( mDirPath );
206 settings.setValue( QStringLiteral( "qgis/alwaysMonitorItemUris" ), alwaysMonitorDirs );
207
209 break;
210 }
211
213 {
214 if ( !noMonitorDirs.contains( mDirPath ) )
215 {
216 noMonitorDirs.append( mDirPath );
217 settings.setValue( QStringLiteral( "qgis/disableMonitorItemUris" ), noMonitorDirs );
218 }
219
220 alwaysMonitorDirs.removeAll( mDirPath );
221 settings.setValue( QStringLiteral( "qgis/alwaysMonitorItemUris" ), alwaysMonitorDirs );
222
223 mMonitored = false;
224 break;
225 }
226
228 {
229 noMonitorDirs.removeAll( mDirPath );
230 settings.setValue( QStringLiteral( "qgis/disableMonitorItemUris" ), noMonitorDirs );
231
232 if ( !alwaysMonitorDirs.contains( mDirPath ) )
233 {
234 alwaysMonitorDirs.append( mDirPath );
235 settings.setValue( QStringLiteral( "qgis/alwaysMonitorItemUris" ), alwaysMonitorDirs );
236 }
237
238 mMonitored = true;
239 break;
240 }
241 }
242
243 const QVector<QgsDataItem *> childItems = children();
244 for ( QgsDataItem *child : childItems )
245 {
246 if ( QgsDirectoryItem *dirItem = qobject_cast< QgsDirectoryItem *>( child ) )
247 dirItem->reevaluateMonitoring();
248 }
249
250 createOrDestroyFileSystemWatcher();
251}
252
253QVector<QgsDataItem *> QgsDirectoryItem::createChildren()
254{
255 QVector<QgsDataItem *> children;
256 const QDir dir( mDirPath );
257
258 const QList<QgsDataItemProvider *> providers = QgsApplication::dataItemProviderRegistry()->providers();
259
260 const QStringList entries = dir.entryList( QDir::AllDirs | QDir::NoDotAndDotDot, QDir::Name | QDir::IgnoreCase );
261 for ( const QString &subdir : entries )
262 {
263 if ( mRefreshLater )
264 {
266 return children;
267 }
268
269 const QString subdirPath = dir.absoluteFilePath( subdir );
270
271 QgsDebugMsgLevel( QStringLiteral( "creating subdir: %1" ).arg( subdirPath ), 2 );
272
273 const QString path = mPath + ( mPath.endsWith( '/' ) ? QString() : QStringLiteral( "/" ) ) + subdir; // may differ from subdirPath
275 continue;
276
277 bool handledByProvider = false;
278 for ( QgsDataItemProvider *provider : providers )
279 {
280 if ( provider->handlesDirectoryPath( subdirPath ) )
281 {
282 handledByProvider = true;
283 break;
284 }
285 }
286 if ( handledByProvider )
287 continue;
288
289 QgsDirectoryItem *item = new QgsDirectoryItem( this, subdir, subdirPath, path );
290
291 // propagate signals up to top
292
293 children.append( item );
294 }
295
296 const QStringList fileEntries = dir.entryList( QDir::Dirs | QDir::NoDotAndDotDot | QDir::Files, QDir::Name );
297 for ( const QString &name : fileEntries )
298 {
299 if ( mRefreshLater )
300 {
302 return children;
303 }
304
305 const QString path = dir.absoluteFilePath( name );
306 const QFileInfo fileInfo( path );
307
308 if ( QgsGdalUtils::isVsiArchiveFileExtension( fileInfo.suffix() ) )
309 {
310 if ( QgsDataItem *item = QgsZipItem::itemFromPath( this, path, name, path ) )
311 {
312 children.append( item );
313 continue;
314 }
315 }
316
317 bool createdItem = false;
318 for ( QgsDataItemProvider *provider : providers )
319 {
320 const int capabilities = provider->capabilities();
321
322 if ( !( ( fileInfo.isFile() && ( capabilities & QgsDataProvider::File ) ) ||
323 ( fileInfo.isDir() && ( capabilities & QgsDataProvider::Dir ) ) ) )
324 {
325 continue;
326 }
327
328 QgsDataItem *item = provider->createDataItem( path, this );
329 if ( item )
330 {
331 // 3rd party providers may not correctly set the ItemRepresentsFile capability, so force it here if we
332 // see that the item's path does match the original file path
333 if ( item->path() == path )
335
336 children.append( item );
337 createdItem = true;
338 }
339 }
340
341 if ( !createdItem )
342 {
343 // if item is a QGIS project, and no specific item provider has overridden handling of
344 // project items, then use the default project item behavior
345 if ( fileInfo.suffix().compare( QLatin1String( "qgs" ), Qt::CaseInsensitive ) == 0 ||
346 fileInfo.suffix().compare( QLatin1String( "qgz" ), Qt::CaseInsensitive ) == 0 )
347 {
348 QgsDataItem *item = new QgsProjectItem( this, fileInfo.completeBaseName(), path );
350 children.append( item );
351 continue;
352 }
353 }
354
355 }
356 return children;
357}
358
360{
362
363 if ( state == Qgis::BrowserItemState::Populated && mMonitored )
364 {
365 if ( !mFileSystemWatcher )
366 {
367 mFileSystemWatcher = new QFileSystemWatcher( this );
368 mFileSystemWatcher->addPath( mDirPath );
369 connect( mFileSystemWatcher, &QFileSystemWatcher::directoryChanged, this, &QgsDirectoryItem::directoryChanged );
370 }
371 mLastScan = QDateTime::currentDateTime();
372 }
374 {
375 if ( mFileSystemWatcher )
376 {
377 delete mFileSystemWatcher;
378 mFileSystemWatcher = nullptr;
379 }
380 }
381}
382
384{
385 // If the last scan was less than 10 seconds ago, skip this
386 if ( mLastScan.msecsTo( QDateTime::currentDateTime() ) < QgsSettings().value( QStringLiteral( "browser/minscaninterval" ), 10000 ).toInt() )
387 {
388 return;
389 }
391 {
392 // schedule to refresh later, because refresh() simply returns if Populating
393 mRefreshLater = true;
394 }
395 else
396 {
397 // We definintely don't want the temporary files created by sqlite
398 // to re-trigger a refresh in an infinite loop.
399 disconnect( mFileSystemWatcher, &QFileSystemWatcher::directoryChanged, this, &QgsDirectoryItem::directoryChanged );
400 // QFileSystemWhatcher::directoryChanged is emitted when a
401 // file is created and not when it is closed/flushed.
402 //
403 // Delay to give to OS the time to complete writing the file
404 // this happens when a new file appears in the directory and
405 // the item's children thread will try to open the file with
406 // GDAL or OGR even if it is still being written.
407 QTimer::singleShot( 100, this, [ = ] { refresh(); } );
408 }
409}
410
411bool QgsDirectoryItem::hiddenPath( const QString &path )
412{
413 const QgsSettings settings;
414 const QStringList hiddenItems = settings.value( QStringLiteral( "browser/hiddenPaths" ),
415 QStringList() ).toStringList();
416 const int idx = hiddenItems.indexOf( path );
417 return ( idx > -1 );
418}
419
421{
422 const QgsSettings settings;
423 if ( settings.value( QStringLiteral( "qgis/disableMonitorItemUris" ), QStringList() ).toStringList().contains( path ) )
425 else if ( settings.value( QStringLiteral( "qgis/alwaysMonitorItemUris" ), QStringList() ).toStringList().contains( path ) )
428}
429
431{
432 // check through path's parent directories, to see if any have an explicit
433 // always/never monitor setting. If so, this path will inherit that setting
434 const QString originalPath = QDir::cleanPath( path );
435 QString currentPath = originalPath;
436 QString prevPath;
437 while ( currentPath != prevPath )
438 {
439 prevPath = currentPath;
440 currentPath = QFileInfo( currentPath ).path();
441
442 switch ( monitoringForPath( currentPath ) )
443 {
445 return false;
447 return true;
449 break;
450 }
451 }
452
453 // else if we know that the path is on a slow device, we don't monitor by default
454 // as this can be very expensive and slow down QGIS
456 return false;
457
458 // paths are monitored by default if no explicit setting is in place, and the user hasn't
459 // completely opted out of all browser monitoring
460 return QgsSettings().value( QStringLiteral( "/qgis/monitorDirectoriesInBrowser" ), true ).toBool();
461}
462
464{
465 QgsDebugMsgLevel( QStringLiteral( "mRefreshLater = %1" ).arg( mRefreshLater ), 3 );
466
467 if ( mRefreshLater )
468 {
469 QgsDebugMsgLevel( QStringLiteral( "directory changed during createChidren() -> refresh() again" ), 3 );
470 mRefreshLater = false;
472 refresh();
473 }
474 else
475 {
477 }
478 // Re-connect the file watcher after all children have been created
479 if ( mFileSystemWatcher && mMonitored )
480 connect( mFileSystemWatcher, &QFileSystemWatcher::directoryChanged, this, &QgsDirectoryItem::directoryChanged );
481}
482
484{
485 //QgsDebugMsg ( mPath + " x " + other->mPath );
486 if ( type() != other->type() )
487 {
488 return false;
489 }
490 const QgsDirectoryItem *otherDirItem = qobject_cast< const QgsDirectoryItem * >( other );
491 if ( !otherDirItem )
492 return false;
493
494 return dirPath() == otherDirItem->dirPath();
495}
496
498{
499 return new QgsDirectoryParamWidget( mPath );
500}
501
503{
505 u.layerType = QStringLiteral( "directory" );
506 u.name = mName;
507 u.uri = mDirPath;
508 u.filePath = path();
509 return { u };
510}
511
512//
513// QgsDirectoryParamWidget
514//
515QgsDirectoryParamWidget::QgsDirectoryParamWidget( const QString &path, QWidget *parent )
516 : QTreeWidget( parent )
517{
518 setRootIsDecorated( false );
519
520 // name, size, date, permissions, owner, group, type
521 setColumnCount( 7 );
522 QStringList labels;
523 labels << tr( "Name" ) << tr( "Size" ) << tr( "Date" ) << tr( "Permissions" ) << tr( "Owner" ) << tr( "Group" ) << tr( "Type" );
524 setHeaderLabels( labels );
525
526 const QIcon iconDirectory = QgsApplication::getThemeIcon( QStringLiteral( "mIconFolder.svg" ) );
527 const QIcon iconFile = QgsApplication::getThemeIcon( QStringLiteral( "mIconFile.svg" ) );
528 const QIcon iconDirLink = QgsApplication::getThemeIcon( QStringLiteral( "mIconFolderLink.svg" ) );
529 const QIcon iconFileLink = QgsApplication::getThemeIcon( QStringLiteral( "mIconFileLink.svg" ) );
530
531 QList<QTreeWidgetItem *> items;
532
533 const QDir dir( path );
534 const QStringList entries = dir.entryList( QDir::AllEntries | QDir::NoDotAndDotDot, QDir::Name | QDir::IgnoreCase );
535 for ( const QString &name : entries )
536 {
537 const QFileInfo fi( dir.absoluteFilePath( name ) );
538 QStringList texts;
539 texts << name;
540 QString size;
541 if ( fi.size() > 1024 )
542 {
543 size = QStringLiteral( "%1 KiB" ).arg( QLocale().toString( fi.size() / 1024.0, 'f', 1 ) );
544 }
545 else if ( fi.size() > 1.048576e6 )
546 {
547 size = QStringLiteral( "%1 MiB" ).arg( QLocale().toString( fi.size() / 1.048576e6, 'f', 1 ) );
548 }
549 else
550 {
551 size = QStringLiteral( "%1 B" ).arg( fi.size() );
552 }
553 texts << size;
554 texts << QLocale().toString( fi.lastModified(), QLocale::ShortFormat );
555 QString perm;
556 perm += fi.permission( QFile::ReadOwner ) ? 'r' : '-';
557 perm += fi.permission( QFile::WriteOwner ) ? 'w' : '-';
558 perm += fi.permission( QFile::ExeOwner ) ? 'x' : '-';
559 // QFile::ReadUser, QFile::WriteUser, QFile::ExeUser
560 perm += fi.permission( QFile::ReadGroup ) ? 'r' : '-';
561 perm += fi.permission( QFile::WriteGroup ) ? 'w' : '-';
562 perm += fi.permission( QFile::ExeGroup ) ? 'x' : '-';
563 perm += fi.permission( QFile::ReadOther ) ? 'r' : '-';
564 perm += fi.permission( QFile::WriteOther ) ? 'w' : '-';
565 perm += fi.permission( QFile::ExeOther ) ? 'x' : '-';
566 texts << perm;
567
568 texts << fi.owner();
569 texts << fi.group();
570
571 QString type;
572 QIcon icon;
573 if ( fi.isDir() && fi.isSymLink() )
574 {
575 type = tr( "folder" );
576 icon = iconDirLink;
577 }
578 else if ( fi.isDir() )
579 {
580 type = tr( "folder" );
581 icon = iconDirectory;
582 }
583 else if ( fi.isFile() && fi.isSymLink() )
584 {
585 type = tr( "file" );
586 icon = iconFileLink;
587 }
588 else if ( fi.isFile() )
589 {
590 type = tr( "file" );
591 icon = iconFile;
592 }
593
594 texts << type;
595
596 QTreeWidgetItem *item = new QTreeWidgetItem( texts );
597 item->setIcon( 0, icon );
598 items << item;
599 }
600
601 addTopLevelItems( items );
602
603 // hide columns that are not requested
604 const QgsSettings settings;
605 const QList<QVariant> lst = settings.value( QStringLiteral( "dataitem/directoryHiddenColumns" ) ).toList();
606 for ( const QVariant &colVariant : lst )
607 {
608 setColumnHidden( colVariant.toInt(), true );
609 }
610}
611
613{
614 if ( event->button() == Qt::RightButton )
615 {
616 // show the popup menu
617 QMenu popupMenu;
618
619 QStringList labels;
620 labels << tr( "Name" ) << tr( "Size" ) << tr( "Date" ) << tr( "Permissions" ) << tr( "Owner" ) << tr( "Group" ) << tr( "Type" );
621 for ( int i = 0; i < labels.count(); i++ )
622 {
623 QAction *action = popupMenu.addAction( labels[i], this, &QgsDirectoryParamWidget::showHideColumn );
624 action->setObjectName( QString::number( i ) );
625 action->setCheckable( true );
626 action->setChecked( !isColumnHidden( i ) );
627 }
628
629 popupMenu.exec( event->globalPos() );
630 }
631}
632
634{
635 QAction *action = qobject_cast<QAction *>( sender() );
636 if ( !action )
637 return; // something is wrong
638
639 const int columnIndex = action->objectName().toInt();
640 setColumnHidden( columnIndex, !isColumnHidden( columnIndex ) );
641
642 // save in settings
643 QgsSettings settings;
644 QList<QVariant> lst;
645 for ( int i = 0; i < columnCount(); i++ )
646 {
647 if ( isColumnHidden( i ) )
648 lst.append( QVariant( i ) );
649 }
650 settings.setValue( QStringLiteral( "dataitem/directoryHiddenColumns" ), lst );
651}
652
653//
654// QgsProjectHomeItem
655//
656
657QgsProjectHomeItem::QgsProjectHomeItem( QgsDataItem *parent, const QString &name, const QString &dirPath, const QString &path )
658 : QgsDirectoryItem( parent, name, dirPath, path, QStringLiteral( "special:ProjectHome" ) )
659{
660}
661
663{
665 return QgsDirectoryItem::icon();
666 return QgsApplication::getThemeIcon( QStringLiteral( "mIconFolderProject.svg" ) );
667}
668
670{
671 return QStringLiteral( " 1" );
672}
673
674
BrowserItemState
Browser item states.
Definition qgis.h:625
@ NotPopulated
Children not yet created.
@ Populating
Creating children in separate thread (populating or refreshing)
@ Populated
Children created.
@ ItemRepresentsFile
Item's path() directly represents a file on disk (since QGIS 3.22)
BrowserDirectoryMonitoring
Browser directory item monitoring switches.
Definition qgis.h:684
@ Default
Use default logic to determine whether directory should be monitored.
@ AlwaysMonitor
Always monitor the directory, regardless of the default logic.
@ NeverMonitor
Never monitor the directory, regardless of the default logic.
@ Directory
Represents a file directory.
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.
A Collection: logical collection of layers or subcollections, e.g.
static QIcon homeDirIcon(const QColor &fillColor=QColor(), const QColor &strokeColor=QColor())
Shared home directory icon.
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.
This is the interface for those who want to add custom data items to the browser tree.
Base class for all items in the model.
Definition qgsdataitem.h:46
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)
QString mPath
QVector< QgsDataItem * > children() const
virtual void deleteLater()
Safely delete the item:
Qgis::BrowserItemType type() const
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()
virtual Qgis::BrowserItemCapabilities capabilities2() const
Returns the capabilities for the data item.
A directory: contains subdirectories and layers.
QVector< QgsDataItem * > createChildren() override
Create children.
Q_DECL_DEPRECATED QWidget * paramWidget() override
Returns source widget from data item for QgsBrowserPropertiesWidget.
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.
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.
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.
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
Browser parameter widget implementation for directory items.
void mousePressEvent(QMouseEvent *event) override
QgsDirectoryParamWidget(const QString &path, QWidget *parent=nullptr)
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.
This class is a composition of two QSettings instances:
Definition qgssettings.h:63
void endGroup()
Resets the group to what it was before the corresponding beginGroup() call.
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), Section section=NoSection) const
Returns the value for setting key.
void beginGroup(const QString &prefix, QgsSettings::Section section=QgsSettings::NoSection)
Appends prefix to the current group.
QStringList childKeys() const
Returns a list of all top-level keys that can be read using the QSettings object.
void remove(const QString &key, QgsSettings::Section section=QgsSettings::NoSection)
Removes the setting key and any sub-settings of key in a section.
void setValue(const QString &key, const QVariant &value, QgsSettings::Section section=QgsSettings::NoSection)
Sets the value of setting key to value.
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:39
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.