QGIS API Documentation 3.29.0-Master (8c80f25a4f)
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 <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 ( fileInfo.suffix().compare( QLatin1String( "zip" ), Qt::CaseInsensitive ) == 0 ||
308 fileInfo.suffix().compare( QLatin1String( "tar" ), Qt::CaseInsensitive ) == 0 )
309 {
311 if ( item )
312 {
313 children.append( item );
314 continue;
315 }
316 }
317
318 bool createdItem = false;
319 for ( QgsDataItemProvider *provider : providers )
320 {
321 const int capabilities = provider->capabilities();
322
323 if ( !( ( fileInfo.isFile() && ( capabilities & QgsDataProvider::File ) ) ||
324 ( fileInfo.isDir() && ( capabilities & QgsDataProvider::Dir ) ) ) )
325 {
326 continue;
327 }
328
329 QgsDataItem *item = provider->createDataItem( path, this );
330 if ( item )
331 {
332 // 3rd party providers may not correctly set the ItemRepresentsFile capability, so force it here if we
333 // see that the item's path does match the original file path
334 if ( item->path() == path )
336
337 children.append( item );
338 createdItem = true;
339 }
340 }
341
342 if ( !createdItem )
343 {
344 // if item is a QGIS project, and no specific item provider has overridden handling of
345 // project items, then use the default project item behavior
346 if ( fileInfo.suffix().compare( QLatin1String( "qgs" ), Qt::CaseInsensitive ) == 0 ||
347 fileInfo.suffix().compare( QLatin1String( "qgz" ), Qt::CaseInsensitive ) == 0 )
348 {
349 QgsDataItem *item = new QgsProjectItem( this, fileInfo.completeBaseName(), path );
351 children.append( item );
352 continue;
353 }
354 }
355
356 }
357 return children;
358}
359
361{
363
364 if ( state == Qgis::BrowserItemState::Populated && mMonitored )
365 {
366 if ( !mFileSystemWatcher )
367 {
368 mFileSystemWatcher = new QFileSystemWatcher( this );
369 mFileSystemWatcher->addPath( mDirPath );
370 connect( mFileSystemWatcher, &QFileSystemWatcher::directoryChanged, this, &QgsDirectoryItem::directoryChanged );
371 }
372 mLastScan = QDateTime::currentDateTime();
373 }
375 {
376 if ( mFileSystemWatcher )
377 {
378 delete mFileSystemWatcher;
379 mFileSystemWatcher = nullptr;
380 }
381 }
382}
383
385{
386 // If the last scan was less than 10 seconds ago, skip this
387 if ( mLastScan.msecsTo( QDateTime::currentDateTime() ) < QgsSettings().value( QStringLiteral( "browser/minscaninterval" ), 10000 ).toInt() )
388 {
389 return;
390 }
392 {
393 // schedule to refresh later, because refresh() simply returns if Populating
394 mRefreshLater = true;
395 }
396 else
397 {
398 // We definintely don't want the temporary files created by sqlite
399 // to re-trigger a refresh in an infinite loop.
400 disconnect( mFileSystemWatcher, &QFileSystemWatcher::directoryChanged, this, &QgsDirectoryItem::directoryChanged );
401 // QFileSystemWhatcher::directoryChanged is emitted when a
402 // file is created and not when it is closed/flushed.
403 //
404 // Delay to give to OS the time to complete writing the file
405 // this happens when a new file appears in the directory and
406 // the item's children thread will try to open the file with
407 // GDAL or OGR even if it is still being written.
408 QTimer::singleShot( 100, this, [ = ] { refresh(); } );
409 }
410}
411
412bool QgsDirectoryItem::hiddenPath( const QString &path )
413{
414 const QgsSettings settings;
415 const QStringList hiddenItems = settings.value( QStringLiteral( "browser/hiddenPaths" ),
416 QStringList() ).toStringList();
417 const int idx = hiddenItems.indexOf( path );
418 return ( idx > -1 );
419}
420
422{
423 const QgsSettings settings;
424 if ( settings.value( QStringLiteral( "qgis/disableMonitorItemUris" ), QStringList() ).toStringList().contains( path ) )
426 else if ( settings.value( QStringLiteral( "qgis/alwaysMonitorItemUris" ), QStringList() ).toStringList().contains( path ) )
429}
430
432{
433 // check through path's parent directories, to see if any have an explicit
434 // always/never monitor setting. If so, this path will inherit that setting
435 const QString originalPath = QDir::cleanPath( path );
436 QString currentPath = originalPath;
437 QString prevPath;
438 while ( currentPath != prevPath )
439 {
440 prevPath = currentPath;
441 currentPath = QFileInfo( currentPath ).path();
442
443 switch ( monitoringForPath( currentPath ) )
444 {
446 return false;
448 return true;
450 break;
451 }
452 }
453
454 // else if we know that the path is on a slow device, we don't monitor by default
455 // as this can be very expensive and slow down QGIS
457 return false;
458
459 // paths are monitored by default if no explicit setting is in place, and the user hasn't
460 // completely opted out of all browser monitoring
461 return QgsSettings().value( QStringLiteral( "/qgis/monitorDirectoriesInBrowser" ), true ).toBool();
462}
463
465{
466 QgsDebugMsgLevel( QStringLiteral( "mRefreshLater = %1" ).arg( mRefreshLater ), 3 );
467
468 if ( mRefreshLater )
469 {
470 QgsDebugMsgLevel( QStringLiteral( "directory changed during createChidren() -> refresh() again" ), 3 );
471 mRefreshLater = false;
473 refresh();
474 }
475 else
476 {
478 }
479 // Re-connect the file watcher after all children have been created
480 if ( mFileSystemWatcher && mMonitored )
481 connect( mFileSystemWatcher, &QFileSystemWatcher::directoryChanged, this, &QgsDirectoryItem::directoryChanged );
482}
483
485{
486 //QgsDebugMsg ( mPath + " x " + other->mPath );
487 if ( type() != other->type() )
488 {
489 return false;
490 }
491 const QgsDirectoryItem *otherDirItem = qobject_cast< const QgsDirectoryItem * >( other );
492 if ( !otherDirItem )
493 return false;
494
495 return dirPath() == otherDirItem->dirPath();
496}
497
499{
500 return new QgsDirectoryParamWidget( mPath );
501}
502
504{
506 u.layerType = QStringLiteral( "directory" );
507 u.name = mName;
508 u.uri = mDirPath;
509 u.filePath = path();
510 return { u };
511}
512
513//
514// QgsDirectoryParamWidget
515//
516QgsDirectoryParamWidget::QgsDirectoryParamWidget( const QString &path, QWidget *parent )
517 : QTreeWidget( parent )
518{
519 setRootIsDecorated( false );
520
521 // name, size, date, permissions, owner, group, type
522 setColumnCount( 7 );
523 QStringList labels;
524 labels << tr( "Name" ) << tr( "Size" ) << tr( "Date" ) << tr( "Permissions" ) << tr( "Owner" ) << tr( "Group" ) << tr( "Type" );
525 setHeaderLabels( labels );
526
527 const QIcon iconDirectory = QgsApplication::getThemeIcon( QStringLiteral( "mIconFolder.svg" ) );
528 const QIcon iconFile = QgsApplication::getThemeIcon( QStringLiteral( "mIconFile.svg" ) );
529 const QIcon iconDirLink = QgsApplication::getThemeIcon( QStringLiteral( "mIconFolderLink.svg" ) );
530 const QIcon iconFileLink = QgsApplication::getThemeIcon( QStringLiteral( "mIconFileLink.svg" ) );
531
532 QList<QTreeWidgetItem *> items;
533
534 const QDir dir( path );
535 const QStringList entries = dir.entryList( QDir::AllEntries | QDir::NoDotAndDotDot, QDir::Name | QDir::IgnoreCase );
536 for ( const QString &name : entries )
537 {
538 const QFileInfo fi( dir.absoluteFilePath( name ) );
539 QStringList texts;
540 texts << name;
541 QString size;
542 if ( fi.size() > 1024 )
543 {
544 size = QStringLiteral( "%1 KiB" ).arg( QLocale().toString( fi.size() / 1024.0, 'f', 1 ) );
545 }
546 else if ( fi.size() > 1.048576e6 )
547 {
548 size = QStringLiteral( "%1 MiB" ).arg( QLocale().toString( fi.size() / 1.048576e6, 'f', 1 ) );
549 }
550 else
551 {
552 size = QStringLiteral( "%1 B" ).arg( fi.size() );
553 }
554 texts << size;
555 texts << QLocale().toString( fi.lastModified(), QLocale::ShortFormat );
556 QString perm;
557 perm += fi.permission( QFile::ReadOwner ) ? 'r' : '-';
558 perm += fi.permission( QFile::WriteOwner ) ? 'w' : '-';
559 perm += fi.permission( QFile::ExeOwner ) ? 'x' : '-';
560 // QFile::ReadUser, QFile::WriteUser, QFile::ExeUser
561 perm += fi.permission( QFile::ReadGroup ) ? 'r' : '-';
562 perm += fi.permission( QFile::WriteGroup ) ? 'w' : '-';
563 perm += fi.permission( QFile::ExeGroup ) ? 'x' : '-';
564 perm += fi.permission( QFile::ReadOther ) ? 'r' : '-';
565 perm += fi.permission( QFile::WriteOther ) ? 'w' : '-';
566 perm += fi.permission( QFile::ExeOther ) ? 'x' : '-';
567 texts << perm;
568
569 texts << fi.owner();
570 texts << fi.group();
571
572 QString type;
573 QIcon icon;
574 if ( fi.isDir() && fi.isSymLink() )
575 {
576 type = tr( "folder" );
577 icon = iconDirLink;
578 }
579 else if ( fi.isDir() )
580 {
581 type = tr( "folder" );
582 icon = iconDirectory;
583 }
584 else if ( fi.isFile() && fi.isSymLink() )
585 {
586 type = tr( "file" );
587 icon = iconFileLink;
588 }
589 else if ( fi.isFile() )
590 {
591 type = tr( "file" );
592 icon = iconFile;
593 }
594
595 texts << type;
596
597 QTreeWidgetItem *item = new QTreeWidgetItem( texts );
598 item->setIcon( 0, icon );
599 items << item;
600 }
601
602 addTopLevelItems( items );
603
604 // hide columns that are not requested
605 const QgsSettings settings;
606 const QList<QVariant> lst = settings.value( QStringLiteral( "dataitem/directoryHiddenColumns" ) ).toList();
607 for ( const QVariant &colVariant : lst )
608 {
609 setColumnHidden( colVariant.toInt(), true );
610 }
611}
612
614{
615 if ( event->button() == Qt::RightButton )
616 {
617 // show the popup menu
618 QMenu popupMenu;
619
620 QStringList labels;
621 labels << tr( "Name" ) << tr( "Size" ) << tr( "Date" ) << tr( "Permissions" ) << tr( "Owner" ) << tr( "Group" ) << tr( "Type" );
622 for ( int i = 0; i < labels.count(); i++ )
623 {
624 QAction *action = popupMenu.addAction( labels[i], this, &QgsDirectoryParamWidget::showHideColumn );
625 action->setObjectName( QString::number( i ) );
626 action->setCheckable( true );
627 action->setChecked( !isColumnHidden( i ) );
628 }
629
630 popupMenu.exec( event->globalPos() );
631 }
632}
633
635{
636 QAction *action = qobject_cast<QAction *>( sender() );
637 if ( !action )
638 return; // something is wrong
639
640 const int columnIndex = action->objectName().toInt();
641 setColumnHidden( columnIndex, !isColumnHidden( columnIndex ) );
642
643 // save in settings
644 QgsSettings settings;
645 QList<QVariant> lst;
646 for ( int i = 0; i < columnCount(); i++ )
647 {
648 if ( isColumnHidden( i ) )
649 lst.append( QVariant( i ) );
650 }
651 settings.setValue( QStringLiteral( "dataitem/directoryHiddenColumns" ), lst );
652}
653
654//
655// QgsProjectHomeItem
656//
657
658QgsProjectHomeItem::QgsProjectHomeItem( QgsDataItem *parent, const QString &name, const QString &dirPath, const QString &path )
659 : QgsDirectoryItem( parent, name, dirPath, path, QStringLiteral( "special:ProjectHome" ) )
660{
661}
662
664{
666 return QgsDirectoryItem::icon();
667 return QgsApplication::getThemeIcon( QStringLiteral( "mIconFolderProject.svg" ) );
668}
669
671{
672 return QStringLiteral( " 1" );
673}
674
675
BrowserItemState
Browser item states.
Definition: qgis.h:368
@ 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:426
@ 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
Definition: qgsdataitem.h:449
Qgis::BrowserItemType mType
Definition: qgsdataitem.h:444
void setToolTip(const QString &msg)
Definition: qgsdataitem.h:406
void dataChanged(QgsDataItem *item)
QString mPath
Definition: qgsdataitem.h:455
QVector< QgsDataItem * > children() const
Definition: qgsdataitem.h:337
virtual void deleteLater()
Safely delete the item:
Qgis::BrowserItemType type() const
Definition: qgsdataitem.h:324
Qgis::BrowserItemState state() const
virtual void childrenCreated()
QString name() const
Returns the name of the item (the displayed text for the item).
Definition: qgsdataitem.h:345
QString path() const
Definition: qgsdataitem.h:354
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.
Definition: qgsdataitem.h:310
virtual void refresh()
virtual Qgis::BrowserItemCapabilities capabilities2() const
Returns the capabilities for the data item.
Definition: qgsdataitem.h:303
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.
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:62
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.
Definition: qgssettings.cpp:90
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.
Definition: qgszipitem.cpp:150
#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.