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