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