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