QGIS API Documentation 4.1.0-Master (60fea48833c)
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 <QString>
35#include <QTimer>
36
37#include "moc_qgsdirectoryitem.cpp"
38
39using namespace Qt::StringLiterals;
40
41//
42// QgsDirectoryItem
43//
44
46 : QgsDataCollectionItem( parent, QDir::toNativeSeparators( name ), path )
47 , mDirPath( path )
48{
49 init( name );
50}
51
52QgsDirectoryItem::QgsDirectoryItem( QgsDataItem *parent, const QString &name, const QString &dirPath, const QString &path, const QString &providerKey )
53 : QgsDataCollectionItem( parent, QDir::toNativeSeparators( name ), path, providerKey )
54 , mDirPath( dirPath )
55{
56 init( name );
57}
58
59void QgsDirectoryItem::init( const QString &dirName )
60{
62 setToolTip( QDir::toNativeSeparators( mDirPath ) );
63
64 QgsSettings settings;
65
66 const QFileInfo fi { mDirPath };
67 mIsDir = fi.isDir();
68 mIsSymLink = fi.isSymLink();
69
70 mMonitoring = monitoringForPath( mDirPath );
71 switch ( mMonitoring )
72 {
75 break;
77 mMonitored = false;
78 break;
80 mMonitored = true;
81 break;
82 }
83
84 settings.beginGroup( u"qgis/browserPathColors"_s );
85 QString settingKey = mDirPath;
86 settingKey.replace( '/', "|||"_L1 );
87 if ( settings.childKeys().contains( settingKey ) )
88 {
89 const QString colorString = settings.value( settingKey ).toString();
90 mIconColor = QColor( colorString );
91 }
92 settings.endGroup();
93
94 // we want directories shown before files
95 setSortKey( u" %1"_s.arg( dirName ) );
96}
97
99{
100 mMonitoring = monitoringForPath( mDirPath );
101 switch ( mMonitoring )
102 {
105 break;
107 mMonitored = false;
108 break;
110 mMonitored = true;
111 break;
112 }
113
114 const QVector<QgsDataItem *> childItems = children();
115 for ( QgsDataItem *child : childItems )
116 {
117 if ( QgsDirectoryItem *dirItem = qobject_cast< QgsDirectoryItem *>( child ) )
118 dirItem->reevaluateMonitoring();
119 }
120
121 createOrDestroyFileSystemWatcher();
122}
123
124void QgsDirectoryItem::createOrDestroyFileSystemWatcher()
125{
126 if ( !mMonitored && mFileSystemWatcher )
127 {
128 mFileSystemWatcher->deleteLater();
129 mFileSystemWatcher = nullptr;
130 }
131 else if ( mMonitored && state() == Qgis::BrowserItemState::Populated && !mFileSystemWatcher )
132 {
133 mFileSystemWatcher = new QFileSystemWatcher( this );
134 mFileSystemWatcher->addPath( mDirPath );
135 connect( mFileSystemWatcher, &QFileSystemWatcher::directoryChanged, this, &QgsDirectoryItem::directoryChanged );
136 }
137}
138
140{
141 return mIconColor;
142}
143
144void QgsDirectoryItem::setIconColor( const QColor &color )
145{
146 if ( color == mIconColor )
147 return;
148
149 mIconColor = color;
150 emit dataChanged( this );
151}
152
153void QgsDirectoryItem::setCustomColor( const QString &directory, const QColor &color )
154{
155 QgsSettings settings;
156 settings.beginGroup( u"qgis/browserPathColors"_s );
157 QString settingKey = directory;
158 settingKey.replace( '/', "|||"_L1 );
159 if ( color.isValid() )
160 settings.setValue( settingKey, color.name( QColor::HexArgb ) );
161 else
162 settings.remove( settingKey );
163 settings.endGroup();
164}
165
167{
168 if ( mDirPath == QDir::homePath() )
169 return homeDirIcon( mIconColor, mIconColor.darker() );
170
171 // still loading? show the spinner
173 return QgsDataItem::icon();
174
175 // symbolic link? use link icon
176 if ( mIsDir && mIsSymLink )
177 {
178 return mIconColor.isValid() ? QgsApplication::getThemeIcon( u"/mIconFolderLinkParams.svg"_s, mIconColor, mIconColor.darker() ) : QgsApplication::getThemeIcon( u"/mIconFolderLink.svg"_s );
179 }
180
181 // loaded? show the open dir icon
183 return openDirIcon( mIconColor, mIconColor.darker() );
184
185 // show the closed dir icon
186 return iconDir( mIconColor, mIconColor.darker() );
187}
188
190{
191 return mMonitoring;
192}
193
195{
196 mMonitoring = monitoring;
197
198 QgsSettings settings;
199 QStringList noMonitorDirs = settings.value( u"qgis/disableMonitorItemUris"_s, QStringList() ).toStringList();
200 QStringList alwaysMonitorDirs = settings.value( u"qgis/alwaysMonitorItemUris"_s, QStringList() ).toStringList();
201
202 switch ( mMonitoring )
203 {
205 {
206 // remove disable/always setting for this path, so that default behavior is used
207 noMonitorDirs.removeAll( mDirPath );
208 settings.setValue( u"qgis/disableMonitorItemUris"_s, noMonitorDirs );
209
210 alwaysMonitorDirs.removeAll( mDirPath );
211 settings.setValue( u"qgis/alwaysMonitorItemUris"_s, alwaysMonitorDirs );
212
214 break;
215 }
216
218 {
219 if ( !noMonitorDirs.contains( mDirPath ) )
220 {
221 noMonitorDirs.append( mDirPath );
222 settings.setValue( u"qgis/disableMonitorItemUris"_s, noMonitorDirs );
223 }
224
225 alwaysMonitorDirs.removeAll( mDirPath );
226 settings.setValue( u"qgis/alwaysMonitorItemUris"_s, alwaysMonitorDirs );
227
228 mMonitored = false;
229 break;
230 }
231
233 {
234 noMonitorDirs.removeAll( mDirPath );
235 settings.setValue( u"qgis/disableMonitorItemUris"_s, noMonitorDirs );
236
237 if ( !alwaysMonitorDirs.contains( mDirPath ) )
238 {
239 alwaysMonitorDirs.append( mDirPath );
240 settings.setValue( u"qgis/alwaysMonitorItemUris"_s, alwaysMonitorDirs );
241 }
242
243 mMonitored = true;
244 break;
245 }
246 }
247
248 const QVector<QgsDataItem *> childItems = children();
249 for ( QgsDataItem *child : childItems )
250 {
251 if ( QgsDirectoryItem *dirItem = qobject_cast< QgsDirectoryItem *>( child ) )
252 dirItem->reevaluateMonitoring();
253 }
254
255 createOrDestroyFileSystemWatcher();
256}
257
258QVector<QgsDataItem *> QgsDirectoryItem::createChildren()
259{
260 QVector<QgsDataItem *> children;
261 const QDir dir( mDirPath );
262
263 const QList<QgsDataItemProvider *> providers = QgsApplication::dataItemProviderRegistry()->providers();
264
265 const QStringList entries = dir.entryList( QDir::AllDirs | QDir::NoDotAndDotDot, QDir::Name | QDir::IgnoreCase );
266 for ( const QString &subdir : entries )
267 {
268 if ( mRefreshLater )
269 {
271 return children;
272 }
273
274 const QString subdirPath = dir.absoluteFilePath( subdir );
275
276 QgsDebugMsgLevel( u"creating subdir: %1"_s.arg( subdirPath ), 2 );
277
278 const QString path = mPath + ( mPath.endsWith( '/' ) ? QString() : u"/"_s ) + subdir; // may differ from subdirPath
280 continue;
281
282 bool handledByProvider = false;
283 for ( QgsDataItemProvider *provider : providers )
284 {
285 if ( provider->handlesDirectoryPath( subdirPath ) )
286 {
287 handledByProvider = true;
288 break;
289 }
290 }
291 if ( handledByProvider )
292 continue;
293
294 QgsDirectoryItem *item = new QgsDirectoryItem( this, subdir, subdirPath, path );
295
296 // propagate signals up to top
297
298 children.append( item );
299 }
300
301 const QStringList fileEntries = dir.entryList( QDir::Dirs | QDir::NoDotAndDotDot | QDir::Files, QDir::Name );
302 for ( const QString &name : fileEntries )
303 {
304 if ( mRefreshLater )
305 {
307 return children;
308 }
309
310 const QString path = dir.absoluteFilePath( name );
311 const QFileInfo fileInfo( path );
312
313 if ( QgsGdalUtils::isVsiArchiveFileExtension( fileInfo.suffix() ) )
314 {
315 if ( QgsDataItem *item = QgsZipItem::itemFromPath( this, path, name, path ) )
316 {
317 children.append( item );
318 continue;
319 }
320 }
321
322 bool createdItem = false;
323 for ( QgsDataItemProvider *provider : providers )
324 {
325 const Qgis::DataItemProviderCapabilities capabilities = provider->capabilities();
326
327 if ( !( ( fileInfo.isFile() && ( capabilities & Qgis::DataItemProviderCapability::Files ) ) || ( fileInfo.isDir() && ( capabilities & Qgis::DataItemProviderCapability::Directories ) ) ) )
328 {
329 continue;
330 }
331
332 QgsDataItem *item = provider->createDataItem( path, this );
333 if ( item )
334 {
335 // 3rd party providers may not correctly set the ItemRepresentsFile capability, so force it here if we
336 // see that the item's path does match the original file path
337 if ( item->path() == path )
339
340 children.append( item );
341 createdItem = true;
342 }
343 }
344
345 if ( !createdItem )
346 {
347 // if item is a QGIS project, and no specific item provider has overridden handling of
348 // project items, then use the default project item behavior
349 if ( fileInfo.suffix().compare( "qgs"_L1, Qt::CaseInsensitive ) == 0 || fileInfo.suffix().compare( "qgz"_L1, Qt::CaseInsensitive ) == 0 )
350 {
351 QgsDataItem *item = new QgsProjectItem( this, fileInfo.completeBaseName(), path );
353 children.append( item );
354 continue;
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( u"browser/minscaninterval"_s, 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( u"browser/hiddenPaths"_s, QStringList() ).toStringList();
417 const int idx = hiddenItems.indexOf( path );
418 return ( idx > -1 );
419}
420
422{
423 const QgsSettings settings;
424 if ( settings.value( u"qgis/disableMonitorItemUris"_s, QStringList() ).toStringList().contains( path ) )
426 else if ( settings.value( u"qgis/alwaysMonitorItemUris"_s, 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
456 // Add trailing slash or windows API functions like GetDriveTypeW won't identify
457 // UNC network drives correctly
458 if ( QgsFileUtils::pathIsSlowDevice( path.endsWith( '/' ) ? path : path + '/' ) )
459 return false;
460
461 // paths are monitored by default if no explicit setting is in place, and the user hasn't
462 // completely opted out of all browser monitoring
463 return QgsSettings().value( u"/qgis/monitorDirectoriesInBrowser"_s, true ).toBool();
464}
465
467{
468 QgsDebugMsgLevel( u"mRefreshLater = %1"_s.arg( mRefreshLater ), 3 );
469
470 if ( mRefreshLater )
471 {
472 QgsDebugMsgLevel( u"directory changed during createChildren() -> refresh() again"_s, 3 );
473 mRefreshLater = false;
475 refresh();
476 }
477 else
478 {
480 }
481 // Re-connect the file watcher after all children have been created
482 if ( mFileSystemWatcher && mMonitored )
483 connect( mFileSystemWatcher, &QFileSystemWatcher::directoryChanged, this, &QgsDirectoryItem::directoryChanged );
484}
485
487{
488 //QgsDebugMsg ( mPath + " x " + other->mPath );
489 if ( type() != other->type() )
490 {
491 return false;
492 }
493 const QgsDirectoryItem *otherDirItem = qobject_cast< const QgsDirectoryItem * >( other );
494 if ( !otherDirItem )
495 return false;
496
497 return dirPath() == otherDirItem->dirPath();
498}
499
501{
502 return new QgsDirectoryParamWidget( mPath );
503}
504
506{
508 u.layerType = u"directory"_s;
509 u.name = mName;
510 u.uri = mDirPath;
511 u.filePath = path();
512 return { u };
513}
514
515//
516// QgsDirectoryParamWidget
517//
518QgsDirectoryParamWidget::QgsDirectoryParamWidget( const QString &path, QWidget *parent )
519 : QTreeWidget( parent )
520{
521 setRootIsDecorated( false );
522
523 // name, size, date, permissions, owner, group, type
524 setColumnCount( 7 );
525 QStringList labels;
526 labels << tr( "Name" ) << tr( "Size" ) << tr( "Date" ) << tr( "Permissions" ) << tr( "Owner" ) << tr( "Group" ) << tr( "Type" );
527 setHeaderLabels( labels );
528
529 const QIcon iconDirectory = QgsApplication::getThemeIcon( u"mIconFolder.svg"_s );
530 const QIcon iconFile = QgsApplication::getThemeIcon( u"mIconFile.svg"_s );
531 const QIcon iconDirLink = QgsApplication::getThemeIcon( u"mIconFolderLink.svg"_s );
532 const QIcon iconFileLink = QgsApplication::getThemeIcon( u"mIconFileLink.svg"_s );
533
534 QList<QTreeWidgetItem *> items;
535
536 const QDir dir( path );
537 const QStringList entries = dir.entryList( QDir::AllEntries | QDir::NoDotAndDotDot, QDir::Name | QDir::IgnoreCase );
538 for ( const QString &name : entries )
539 {
540 const QFileInfo fi( dir.absoluteFilePath( name ) );
541 QStringList texts;
542 texts << name;
543 QString size;
544 if ( fi.size() > 1024 )
545 {
546 size = u"%1 KiB"_s.arg( QLocale().toString( fi.size() / 1024.0, 'f', 1 ) );
547 }
548 else if ( fi.size() > 1.048576e6 )
549 {
550 size = u"%1 MiB"_s.arg( QLocale().toString( fi.size() / 1.048576e6, 'f', 1 ) );
551 }
552 else
553 {
554 size = u"%1 B"_s.arg( fi.size() );
555 }
556 texts << size;
557 texts << QLocale().toString( fi.lastModified(), QLocale::ShortFormat );
558 QString perm;
559 perm += fi.permission( QFile::ReadOwner ) ? 'r' : '-';
560 perm += fi.permission( QFile::WriteOwner ) ? 'w' : '-';
561 perm += fi.permission( QFile::ExeOwner ) ? 'x' : '-';
562 // QFile::ReadUser, QFile::WriteUser, QFile::ExeUser
563 perm += fi.permission( QFile::ReadGroup ) ? 'r' : '-';
564 perm += fi.permission( QFile::WriteGroup ) ? 'w' : '-';
565 perm += fi.permission( QFile::ExeGroup ) ? 'x' : '-';
566 perm += fi.permission( QFile::ReadOther ) ? 'r' : '-';
567 perm += fi.permission( QFile::WriteOther ) ? 'w' : '-';
568 perm += fi.permission( QFile::ExeOther ) ? 'x' : '-';
569 texts << perm;
570
571 texts << fi.owner();
572 texts << fi.group();
573
574 QString type;
575 QIcon icon;
576 if ( fi.isDir() && fi.isSymLink() )
577 {
578 type = tr( "folder" );
579 icon = iconDirLink;
580 }
581 else if ( fi.isDir() )
582 {
583 type = tr( "folder" );
584 icon = iconDirectory;
585 }
586 else if ( fi.isFile() && fi.isSymLink() )
587 {
588 type = tr( "file" );
589 icon = iconFileLink;
590 }
591 else if ( fi.isFile() )
592 {
593 type = tr( "file" );
594 icon = iconFile;
595 }
596
597 texts << type;
598
599 QTreeWidgetItem *item = new QTreeWidgetItem( texts );
600 item->setIcon( 0, icon );
601 items << item;
602 }
603
604 addTopLevelItems( items );
605
606 // hide columns that are not requested
607 const QgsSettings settings;
608 const QList<QVariant> lst = settings.value( u"dataitem/directoryHiddenColumns"_s ).toList();
609 for ( const QVariant &colVariant : lst )
610 {
611 setColumnHidden( colVariant.toInt(), true );
612 }
613}
614
616{
617 if ( event->button() == Qt::RightButton )
618 {
619 // show the popup menu
620 QMenu popupMenu;
621
622 QStringList labels;
623 labels << tr( "Name" ) << tr( "Size" ) << tr( "Date" ) << tr( "Permissions" ) << tr( "Owner" ) << tr( "Group" ) << tr( "Type" );
624 for ( int i = 0; i < labels.count(); i++ )
625 {
626 QAction *action = popupMenu.addAction( labels[i], this, &QgsDirectoryParamWidget::showHideColumn );
627 action->setObjectName( QString::number( i ) );
628 action->setCheckable( true );
629 action->setChecked( !isColumnHidden( i ) );
630 }
631
632 popupMenu.exec( event->globalPos() );
633 }
634}
635
637{
638 QAction *action = qobject_cast<QAction *>( sender() );
639 if ( !action )
640 return; // something is wrong
641
642 const int columnIndex = action->objectName().toInt();
643 setColumnHidden( columnIndex, !isColumnHidden( columnIndex ) );
644
645 // save in settings
646 QgsSettings settings;
647 QList<QVariant> lst;
648 for ( int i = 0; i < columnCount(); i++ )
649 {
650 if ( isColumnHidden( i ) )
651 lst.append( QVariant( i ) );
652 }
653 settings.setValue( u"dataitem/directoryHiddenColumns"_s, lst );
654}
655
656//
657// QgsProjectHomeItem
658//
659
660QgsProjectHomeItem::QgsProjectHomeItem( QgsDataItem *parent, const QString &name, const QString &dirPath, const QString &path )
661 : QgsDirectoryItem( parent, name, dirPath, path, u"special:ProjectHome"_s )
662{}
663
665{
667 return QgsDirectoryItem::icon();
668 return QgsApplication::getThemeIcon( u"mIconFolderProject.svg"_s );
669}
670
672{
673 return u" 1"_s;
674}
@ Files
Can provides items which corresponds to files.
Definition qgis.h:1004
@ Directories
Can provides items which corresponds to directories.
Definition qgis.h:1005
BrowserItemState
Browser item states.
Definition qgis.h:964
@ NotPopulated
Children not yet created.
Definition qgis.h:965
@ Populating
Creating children in separate thread (populating or refreshing).
Definition qgis.h:966
@ Populated
Children created.
Definition qgis.h:967
@ ItemRepresentsFile
Item's path() directly represents a file on disk.
Definition qgis.h:985
BrowserDirectoryMonitoring
Browser directory item monitoring switches.
Definition qgis.h:1051
@ Default
Use default logic to determine whether directory should be monitored.
Definition qgis.h:1052
@ AlwaysMonitor
Always monitor the directory, regardless of the default logic.
Definition qgis.h:1054
@ NeverMonitor
Never monitor the directory, regardless of the default logic.
Definition qgis.h:1053
QFlags< DataItemProviderCapability > DataItemProviderCapabilities
Capabilities for data item providers.
Definition qgis.h:1018
@ Directory
Represents a file directory.
Definition qgis.h:947
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:68
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:63
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.