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