QGIS API Documentation 3.99.0-Master (2fe06baccd8)
Loading...
Searching...
No Matches
qgsdirectoryitem.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsddirectoryitem.cpp
3 -------------------
4 begin : 2011-04-01
5 copyright : (C) 2011 Radim Blazek
6 email : radim dot blazek at gmail dot com
7 ***************************************************************************/
8
9/***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
17
18#include "qgsdirectoryitem.h"
19
20#include "qgsapplication.h"
21#include "qgsdataitemprovider.h"
23#include "qgsfileutils.h"
24#include "qgsgdalutils.h"
25#include "qgsprojectitem.h"
26#include "qgssettings.h"
27#include "qgszipitem.h"
28
29#include <QAction>
30#include <QDir>
31#include <QFileSystemWatcher>
32#include <QMenu>
33#include <QMouseEvent>
34#include <QTimer>
35
36#include "moc_qgsdirectoryitem.cpp"
37
38//
39// QgsDirectoryItem
40//
41
43 : QgsDataCollectionItem( parent, QDir::toNativeSeparators( name ), path )
44 , mDirPath( path )
45{
46 init( name );
47}
48
50 const QString &dirPath, const QString &path,
51 const QString &providerKey )
52 : QgsDataCollectionItem( parent, QDir::toNativeSeparators( name ), path, providerKey )
53 , mDirPath( dirPath )
54{
55 init( name );
56}
57
58void QgsDirectoryItem::init( const QString &dirName )
59{
61 setToolTip( QDir::toNativeSeparators( mDirPath ) );
62
63 QgsSettings settings;
64
65 const QFileInfo fi { mDirPath };
66 mIsDir = fi.isDir();
67 mIsSymLink = fi.isSymLink();
68
69 mMonitoring = monitoringForPath( mDirPath );
70 switch ( mMonitoring )
71 {
74 break;
76 mMonitored = false;
77 break;
79 mMonitored = true;
80 break;
81 }
82
83 settings.beginGroup( QStringLiteral( "qgis/browserPathColors" ) );
84 QString settingKey = mDirPath;
85 settingKey.replace( '/', QLatin1String( "|||" ) );
86 if ( settings.childKeys().contains( settingKey ) )
87 {
88 const QString colorString = settings.value( settingKey ).toString();
89 mIconColor = QColor( colorString );
90 }
91 settings.endGroup();
92
93 // we want directories shown before files
94 setSortKey( QStringLiteral( " %1" ).arg( dirName ) );
95}
96
98{
99 mMonitoring = monitoringForPath( mDirPath );
100 switch ( mMonitoring )
101 {
104 break;
106 mMonitored = false;
107 break;
109 mMonitored = true;
110 break;
111 }
112
113 const QVector<QgsDataItem *> childItems = children();
114 for ( QgsDataItem *child : childItems )
115 {
116 if ( QgsDirectoryItem *dirItem = qobject_cast< QgsDirectoryItem *>( child ) )
117 dirItem->reevaluateMonitoring();
118 }
119
120 createOrDestroyFileSystemWatcher();
121}
122
123void QgsDirectoryItem::createOrDestroyFileSystemWatcher()
124{
125 if ( !mMonitored && mFileSystemWatcher )
126 {
127 mFileSystemWatcher->deleteLater();
128 mFileSystemWatcher = nullptr;
129 }
130 else if ( mMonitored && state() == Qgis::BrowserItemState::Populated && !mFileSystemWatcher )
131 {
132 mFileSystemWatcher = new QFileSystemWatcher( this );
133 mFileSystemWatcher->addPath( mDirPath );
134 connect( mFileSystemWatcher, &QFileSystemWatcher::directoryChanged, this, &QgsDirectoryItem::directoryChanged );
135 }
136}
137
139{
140 return mIconColor;
141}
142
143void QgsDirectoryItem::setIconColor( const QColor &color )
144{
145 if ( color == mIconColor )
146 return;
147
148 mIconColor = color;
149 emit dataChanged( this );
150}
151
152void QgsDirectoryItem::setCustomColor( const QString &directory, const QColor &color )
153{
154 QgsSettings settings;
155 settings.beginGroup( QStringLiteral( "qgis/browserPathColors" ) );
156 QString settingKey = directory;
157 settingKey.replace( '/', QLatin1String( "|||" ) );
158 if ( color.isValid() )
159 settings.setValue( settingKey, color.name( QColor::HexArgb ) );
160 else
161 settings.remove( settingKey );
162 settings.endGroup();
163}
164
166{
167 if ( mDirPath == QDir::homePath() )
168 return homeDirIcon( mIconColor, mIconColor.darker() );
169
170 // still loading? show the spinner
172 return QgsDataItem::icon();
173
174 // symbolic link? use link icon
175 if ( mIsDir && mIsSymLink )
176 {
177 return mIconColor.isValid()
178 ? QgsApplication::getThemeIcon( QStringLiteral( "/mIconFolderLinkParams.svg" ), mIconColor, mIconColor.darker() )
179 : QgsApplication::getThemeIcon( QStringLiteral( "/mIconFolderLink.svg" ) );
180 }
181
182 // loaded? show the open dir icon
184 return openDirIcon( mIconColor, mIconColor.darker() );
185
186 // show the closed dir icon
187 return iconDir( mIconColor, mIconColor.darker() );
188}
189
191{
192 return mMonitoring;
193}
194
196{
197 mMonitoring = monitoring;
198
199 QgsSettings settings;
200 QStringList noMonitorDirs = settings.value( QStringLiteral( "qgis/disableMonitorItemUris" ), QStringList() ).toStringList();
201 QStringList alwaysMonitorDirs = settings.value( QStringLiteral( "qgis/alwaysMonitorItemUris" ), QStringList() ).toStringList();
202
203 switch ( mMonitoring )
204 {
206 {
207 // remove disable/always setting for this path, so that default behavior is used
208 noMonitorDirs.removeAll( mDirPath );
209 settings.setValue( QStringLiteral( "qgis/disableMonitorItemUris" ), noMonitorDirs );
210
211 alwaysMonitorDirs.removeAll( mDirPath );
212 settings.setValue( QStringLiteral( "qgis/alwaysMonitorItemUris" ), alwaysMonitorDirs );
213
215 break;
216 }
217
219 {
220 if ( !noMonitorDirs.contains( mDirPath ) )
221 {
222 noMonitorDirs.append( mDirPath );
223 settings.setValue( QStringLiteral( "qgis/disableMonitorItemUris" ), noMonitorDirs );
224 }
225
226 alwaysMonitorDirs.removeAll( mDirPath );
227 settings.setValue( QStringLiteral( "qgis/alwaysMonitorItemUris" ), alwaysMonitorDirs );
228
229 mMonitored = false;
230 break;
231 }
232
234 {
235 noMonitorDirs.removeAll( mDirPath );
236 settings.setValue( QStringLiteral( "qgis/disableMonitorItemUris" ), noMonitorDirs );
237
238 if ( !alwaysMonitorDirs.contains( mDirPath ) )
239 {
240 alwaysMonitorDirs.append( mDirPath );
241 settings.setValue( QStringLiteral( "qgis/alwaysMonitorItemUris" ), alwaysMonitorDirs );
242 }
243
244 mMonitored = true;
245 break;
246 }
247 }
248
249 const QVector<QgsDataItem *> childItems = children();
250 for ( QgsDataItem *child : childItems )
251 {
252 if ( QgsDirectoryItem *dirItem = qobject_cast< QgsDirectoryItem *>( child ) )
253 dirItem->reevaluateMonitoring();
254 }
255
256 createOrDestroyFileSystemWatcher();
257}
258
259QVector<QgsDataItem *> QgsDirectoryItem::createChildren()
260{
261 QVector<QgsDataItem *> children;
262 const QDir dir( mDirPath );
263
264 const QList<QgsDataItemProvider *> providers = QgsApplication::dataItemProviderRegistry()->providers();
265
266 const QStringList entries = dir.entryList( QDir::AllDirs | QDir::NoDotAndDotDot, QDir::Name | QDir::IgnoreCase );
267 for ( const QString &subdir : entries )
268 {
269 if ( mRefreshLater )
270 {
272 return children;
273 }
274
275 const QString subdirPath = dir.absoluteFilePath( subdir );
276
277 QgsDebugMsgLevel( QStringLiteral( "creating subdir: %1" ).arg( subdirPath ), 2 );
278
279 const QString path = mPath + ( mPath.endsWith( '/' ) ? QString() : QStringLiteral( "/" ) ) + subdir; // may differ from subdirPath
281 continue;
282
283 bool handledByProvider = false;
284 for ( QgsDataItemProvider *provider : providers )
285 {
286 if ( provider->handlesDirectoryPath( subdirPath ) )
287 {
288 handledByProvider = true;
289 break;
290 }
291 }
292 if ( handledByProvider )
293 continue;
294
295 QgsDirectoryItem *item = new QgsDirectoryItem( this, subdir, subdirPath, path );
296
297 // propagate signals up to top
298
299 children.append( item );
300 }
301
302 const QStringList fileEntries = dir.entryList( QDir::Dirs | QDir::NoDotAndDotDot | QDir::Files, QDir::Name );
303 for ( const QString &name : fileEntries )
304 {
305 if ( mRefreshLater )
306 {
308 return children;
309 }
310
311 const QString path = dir.absoluteFilePath( name );
312 const QFileInfo fileInfo( path );
313
314 if ( QgsGdalUtils::isVsiArchiveFileExtension( fileInfo.suffix() ) )
315 {
316 if ( QgsDataItem *item = QgsZipItem::itemFromPath( this, path, name, path ) )
317 {
318 children.append( item );
319 continue;
320 }
321 }
322
323 bool createdItem = false;
324 for ( QgsDataItemProvider *provider : providers )
325 {
326 const Qgis::DataItemProviderCapabilities capabilities = provider->capabilities();
327
328 if ( !( ( fileInfo.isFile() && ( capabilities & Qgis::DataItemProviderCapability::Files ) ) ||
329 ( fileInfo.isDir() && ( capabilities & Qgis::DataItemProviderCapability::Directories ) ) ) )
330 {
331 continue;
332 }
333
334 QgsDataItem *item = provider->createDataItem( path, this );
335 if ( item )
336 {
337 // 3rd party providers may not correctly set the ItemRepresentsFile capability, so force it here if we
338 // see that the item's path does match the original file path
339 if ( item->path() == path )
341
342 children.append( item );
343 createdItem = true;
344 }
345 }
346
347 if ( !createdItem )
348 {
349 // if item is a QGIS project, and no specific item provider has overridden handling of
350 // project items, then use the default project item behavior
351 if ( fileInfo.suffix().compare( QLatin1String( "qgs" ), Qt::CaseInsensitive ) == 0 ||
352 fileInfo.suffix().compare( QLatin1String( "qgz" ), Qt::CaseInsensitive ) == 0 )
353 {
354 QgsDataItem *item = new QgsProjectItem( this, fileInfo.completeBaseName(), path );
356 children.append( item );
357 continue;
358 }
359 }
360
361 }
362 return children;
363}
364
366{
368
369 if ( state == Qgis::BrowserItemState::Populated && mMonitored )
370 {
371 if ( !mFileSystemWatcher )
372 {
373 mFileSystemWatcher = new QFileSystemWatcher( this );
374 mFileSystemWatcher->addPath( mDirPath );
375 connect( mFileSystemWatcher, &QFileSystemWatcher::directoryChanged, this, &QgsDirectoryItem::directoryChanged );
376 }
377 mLastScan = QDateTime::currentDateTime();
378 }
380 {
381 if ( mFileSystemWatcher )
382 {
383 delete mFileSystemWatcher;
384 mFileSystemWatcher = nullptr;
385 }
386 }
387}
388
390{
391 // If the last scan was less than 10 seconds ago, skip this
392 if ( mLastScan.msecsTo( QDateTime::currentDateTime() ) < QgsSettings().value( QStringLiteral( "browser/minscaninterval" ), 10000 ).toInt() )
393 {
394 return;
395 }
397 {
398 // schedule to refresh later, because refresh() simply returns if Populating
399 mRefreshLater = true;
400 }
401 else
402 {
403 // We definintely don't want the temporary files created by sqlite
404 // to re-trigger a refresh in an infinite loop.
405 disconnect( mFileSystemWatcher, &QFileSystemWatcher::directoryChanged, this, &QgsDirectoryItem::directoryChanged );
406 // QFileSystemWhatcher::directoryChanged is emitted when a
407 // file is created and not when it is closed/flushed.
408 //
409 // Delay to give to OS the time to complete writing the file
410 // this happens when a new file appears in the directory and
411 // the item's children thread will try to open the file with
412 // GDAL or OGR even if it is still being written.
413 QTimer::singleShot( 100, this, [this] { refresh(); } );
414 }
415}
416
417bool QgsDirectoryItem::hiddenPath( const QString &path )
418{
419 const QgsSettings settings;
420 const QStringList hiddenItems = settings.value( QStringLiteral( "browser/hiddenPaths" ),
421 QStringList() ).toStringList();
422 const int idx = hiddenItems.indexOf( path );
423 return ( idx > -1 );
424}
425
427{
428 const QgsSettings settings;
429 if ( settings.value( QStringLiteral( "qgis/disableMonitorItemUris" ), QStringList() ).toStringList().contains( path ) )
431 else if ( settings.value( QStringLiteral( "qgis/alwaysMonitorItemUris" ), QStringList() ).toStringList().contains( path ) )
434}
435
437{
438 // check through path's parent directories, to see if any have an explicit
439 // always/never monitor setting. If so, this path will inherit that setting
440 const QString originalPath = QDir::cleanPath( path );
441 QString currentPath = originalPath;
442 QString prevPath;
443 while ( currentPath != prevPath )
444 {
445 prevPath = currentPath;
446 currentPath = QFileInfo( currentPath ).path();
447
448 switch ( monitoringForPath( currentPath ) )
449 {
451 return false;
453 return true;
455 break;
456 }
457 }
458
459 // else if we know that the path is on a slow device, we don't monitor by default
460 // as this can be very expensive and slow down QGIS
461 // Add trailing slash or windows API functions like GetDriveTypeW won't identify
462 // UNC network drives correctly
463 if ( QgsFileUtils::pathIsSlowDevice( path.endsWith( '/' ) ? path : path + '/' ) )
464 return false;
465
466 // paths are monitored by default if no explicit setting is in place, and the user hasn't
467 // completely opted out of all browser monitoring
468 return QgsSettings().value( QStringLiteral( "/qgis/monitorDirectoriesInBrowser" ), true ).toBool();
469}
470
472{
473 QgsDebugMsgLevel( QStringLiteral( "mRefreshLater = %1" ).arg( mRefreshLater ), 3 );
474
475 if ( mRefreshLater )
476 {
477 QgsDebugMsgLevel( QStringLiteral( "directory changed during createChildren() -> refresh() again" ), 3 );
478 mRefreshLater = false;
480 refresh();
481 }
482 else
483 {
485 }
486 // Re-connect the file watcher after all children have been created
487 if ( mFileSystemWatcher && mMonitored )
488 connect( mFileSystemWatcher, &QFileSystemWatcher::directoryChanged, this, &QgsDirectoryItem::directoryChanged );
489}
490
492{
493 //QgsDebugMsg ( mPath + " x " + other->mPath );
494 if ( type() != other->type() )
495 {
496 return false;
497 }
498 const QgsDirectoryItem *otherDirItem = qobject_cast< const QgsDirectoryItem * >( other );
499 if ( !otherDirItem )
500 return false;
501
502 return dirPath() == otherDirItem->dirPath();
503}
504
506{
507 return new QgsDirectoryParamWidget( mPath );
508}
509
511{
513 u.layerType = QStringLiteral( "directory" );
514 u.name = mName;
515 u.uri = mDirPath;
516 u.filePath = path();
517 return { u };
518}
519
520//
521// QgsDirectoryParamWidget
522//
523QgsDirectoryParamWidget::QgsDirectoryParamWidget( const QString &path, QWidget *parent )
524 : QTreeWidget( parent )
525{
526 setRootIsDecorated( false );
527
528 // name, size, date, permissions, owner, group, type
529 setColumnCount( 7 );
530 QStringList labels;
531 labels << tr( "Name" ) << tr( "Size" ) << tr( "Date" ) << tr( "Permissions" ) << tr( "Owner" ) << tr( "Group" ) << tr( "Type" );
532 setHeaderLabels( labels );
533
534 const QIcon iconDirectory = QgsApplication::getThemeIcon( QStringLiteral( "mIconFolder.svg" ) );
535 const QIcon iconFile = QgsApplication::getThemeIcon( QStringLiteral( "mIconFile.svg" ) );
536 const QIcon iconDirLink = QgsApplication::getThemeIcon( QStringLiteral( "mIconFolderLink.svg" ) );
537 const QIcon iconFileLink = QgsApplication::getThemeIcon( QStringLiteral( "mIconFileLink.svg" ) );
538
539 QList<QTreeWidgetItem *> items;
540
541 const QDir dir( path );
542 const QStringList entries = dir.entryList( QDir::AllEntries | QDir::NoDotAndDotDot, QDir::Name | QDir::IgnoreCase );
543 for ( const QString &name : entries )
544 {
545 const QFileInfo fi( dir.absoluteFilePath( name ) );
546 QStringList texts;
547 texts << name;
548 QString size;
549 if ( fi.size() > 1024 )
550 {
551 size = QStringLiteral( "%1 KiB" ).arg( QLocale().toString( fi.size() / 1024.0, 'f', 1 ) );
552 }
553 else if ( fi.size() > 1.048576e6 )
554 {
555 size = QStringLiteral( "%1 MiB" ).arg( QLocale().toString( fi.size() / 1.048576e6, 'f', 1 ) );
556 }
557 else
558 {
559 size = QStringLiteral( "%1 B" ).arg( fi.size() );
560 }
561 texts << size;
562 texts << QLocale().toString( fi.lastModified(), QLocale::ShortFormat );
563 QString perm;
564 perm += fi.permission( QFile::ReadOwner ) ? 'r' : '-';
565 perm += fi.permission( QFile::WriteOwner ) ? 'w' : '-';
566 perm += fi.permission( QFile::ExeOwner ) ? 'x' : '-';
567 // QFile::ReadUser, QFile::WriteUser, QFile::ExeUser
568 perm += fi.permission( QFile::ReadGroup ) ? 'r' : '-';
569 perm += fi.permission( QFile::WriteGroup ) ? 'w' : '-';
570 perm += fi.permission( QFile::ExeGroup ) ? 'x' : '-';
571 perm += fi.permission( QFile::ReadOther ) ? 'r' : '-';
572 perm += fi.permission( QFile::WriteOther ) ? 'w' : '-';
573 perm += fi.permission( QFile::ExeOther ) ? 'x' : '-';
574 texts << perm;
575
576 texts << fi.owner();
577 texts << fi.group();
578
579 QString type;
580 QIcon icon;
581 if ( fi.isDir() && fi.isSymLink() )
582 {
583 type = tr( "folder" );
584 icon = iconDirLink;
585 }
586 else if ( fi.isDir() )
587 {
588 type = tr( "folder" );
589 icon = iconDirectory;
590 }
591 else if ( fi.isFile() && fi.isSymLink() )
592 {
593 type = tr( "file" );
594 icon = iconFileLink;
595 }
596 else if ( fi.isFile() )
597 {
598 type = tr( "file" );
599 icon = iconFile;
600 }
601
602 texts << type;
603
604 QTreeWidgetItem *item = new QTreeWidgetItem( texts );
605 item->setIcon( 0, icon );
606 items << item;
607 }
608
609 addTopLevelItems( items );
610
611 // hide columns that are not requested
612 const QgsSettings settings;
613 const QList<QVariant> lst = settings.value( QStringLiteral( "dataitem/directoryHiddenColumns" ) ).toList();
614 for ( const QVariant &colVariant : lst )
615 {
616 setColumnHidden( colVariant.toInt(), true );
617 }
618}
619
621{
622 if ( event->button() == Qt::RightButton )
623 {
624 // show the popup menu
625 QMenu popupMenu;
626
627 QStringList labels;
628 labels << tr( "Name" ) << tr( "Size" ) << tr( "Date" ) << tr( "Permissions" ) << tr( "Owner" ) << tr( "Group" ) << tr( "Type" );
629 for ( int i = 0; i < labels.count(); i++ )
630 {
631 QAction *action = popupMenu.addAction( labels[i], this, &QgsDirectoryParamWidget::showHideColumn );
632 action->setObjectName( QString::number( i ) );
633 action->setCheckable( true );
634 action->setChecked( !isColumnHidden( i ) );
635 }
636
637 popupMenu.exec( event->globalPos() );
638 }
639}
640
642{
643 QAction *action = qobject_cast<QAction *>( sender() );
644 if ( !action )
645 return; // something is wrong
646
647 const int columnIndex = action->objectName().toInt();
648 setColumnHidden( columnIndex, !isColumnHidden( columnIndex ) );
649
650 // save in settings
651 QgsSettings settings;
652 QList<QVariant> lst;
653 for ( int i = 0; i < columnCount(); i++ )
654 {
655 if ( isColumnHidden( i ) )
656 lst.append( QVariant( i ) );
657 }
658 settings.setValue( QStringLiteral( "dataitem/directoryHiddenColumns" ), lst );
659}
660
661//
662// QgsProjectHomeItem
663//
664
665QgsProjectHomeItem::QgsProjectHomeItem( QgsDataItem *parent, const QString &name, const QString &dirPath, const QString &path )
666 : QgsDirectoryItem( parent, name, dirPath, path, QStringLiteral( "special:ProjectHome" ) )
667{
668}
669
671{
673 return QgsDirectoryItem::icon();
674 return QgsApplication::getThemeIcon( QStringLiteral( "mIconFolderProject.svg" ) );
675}
676
678{
679 return QStringLiteral( " 1" );
680}
681
682
@ Files
Can provides items which corresponds to files.
Definition qgis.h:978
@ Directories
Can provides items which corresponds to directories.
Definition qgis.h:979
BrowserItemState
Browser item states.
Definition qgis.h:938
@ NotPopulated
Children not yet created.
Definition qgis.h:939
@ Populating
Creating children in separate thread (populating or refreshing).
Definition qgis.h:940
@ Populated
Children created.
Definition qgis.h:941
@ ItemRepresentsFile
Item's path() directly represents a file on disk.
Definition qgis.h:959
BrowserDirectoryMonitoring
Browser directory item monitoring switches.
Definition qgis.h:1025
@ Default
Use default logic to determine whether directory should be monitored.
Definition qgis.h:1026
@ AlwaysMonitor
Always monitor the directory, regardless of the default logic.
Definition qgis.h:1028
@ NeverMonitor
Never monitor the directory, regardless of the default logic.
Definition qgis.h:1027
QFlags< DataItemProviderCapability > DataItemProviderCapabilities
Capabilities for data item providers.
Definition qgis.h:992
@ Directory
Represents a file directory.
Definition qgis.h:921
static QgsDataItemProviderRegistry * dataItemProviderRegistry()
Returns the application's data item provider registry, which keeps a list of data item providers that...
static QIcon getThemeIcon(const QString &name, const QColor &fillColor=QColor(), const QColor &strokeColor=QColor())
Helper to get a theme icon.
static QIcon homeDirIcon(const QColor &fillColor=QColor(), const QColor &strokeColor=QColor())
Shared home directory icon.
QgsDataCollectionItem(QgsDataItem *parent, const QString &name, const QString &path=QString(), const QString &providerKey=QString())
Constructor for QgsDataCollectionItem, with the specified parent item.
static QIcon iconDir(const QColor &fillColor=QColor(), const QColor &strokeColor=QColor())
Returns the standard browser directory icon.
static QIcon openDirIcon(const QColor &fillColor=QColor(), const QColor &strokeColor=QColor())
Shared open directory icon.
QList< QgsDataItemProvider * > providers() const
Returns the list of available providers.
Interface for providers that add custom data items to the browser tree.
void setSortKey(const QVariant &key)
Sets a custom sorting key for the item.
QString mName
Qgis::BrowserItemType mType
void setToolTip(const QString &msg)
void dataChanged(QgsDataItem *item)
Emitted when data changes for an item.
QString mPath
QVector< QgsDataItem * > children() const
virtual void deleteLater()
Safely delete the item:
Qgis::BrowserItemType type() const
QgsDataItem(Qgis::BrowserItemType type, QgsDataItem *parent, const QString &name, const QString &path, const QString &providerKey=QString())
Constructor for QgsDataItem, with the specified parent item.
Qgis::BrowserItemState state() const
virtual void childrenCreated()
QString name() const
Returns the name of the item (the displayed text for the item).
QString path() const
virtual QIcon icon()
virtual void setState(Qgis::BrowserItemState state)
Set item state.
virtual void setCapabilities(Qgis::BrowserItemCapabilities capabilities)
Sets the capabilities for the data item.
virtual void refresh()
QgsDataItem * parent() const
Gets item parent.
QString providerKey() const
Returns the provider key that created this item (e.g.
virtual Qgis::BrowserItemCapabilities capabilities2() const
Returns the capabilities for the data item.
QVector< QgsDataItem * > createChildren() override
Create children.
Q_DECL_DEPRECATED QWidget * paramWidget() override
static Qgis::BrowserDirectoryMonitoring monitoringForPath(const QString &path)
Returns the monitoring setting for a directory path.
QgsMimeDataUtils::UriList mimeUris() const override
Returns mime URIs for the data item, most data providers will only return a single URI but some data ...
Qgis::BrowserDirectoryMonitoring monitoring() const
Returns the monitoring setting for this directory item.
static void setCustomColor(const QString &directory, const QColor &color)
Sets a custom icon color to use for the items for the corresponding directory path.
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.
Stores settings for use within QGIS.
Definition qgssettings.h:65
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:61
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.