QGIS API Documentation  3.10.0-A Coruña (6c816b4204)
qgsbrowsermodel.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsbrowsermodel.cpp
3  ---------------------
4  begin : July 2011
5  copyright : (C) 2011 by Martin Dobias
6  email : wonder dot sk at gmail dot com
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 #include <QDir>
16 #include <QApplication>
17 #include <QStyle>
18 #include <QtConcurrentMap>
19 #include <QUrl>
20 
21 #include "qgis.h"
22 #include "qgsapplication.h"
23 #include "qgsdataitemprovider.h"
25 #include "qgsdataprovider.h"
26 #include "qgsmimedatautils.h"
27 #include "qgslogger.h"
28 #include "qgsproviderregistry.h"
29 #include "qgsbrowsermodel.h"
30 #include "qgsproject.h"
31 #include "qgssettings.h"
32 
33 #define PROJECT_HOME_PREFIX "project:"
34 #define HOME_PREFIX "home:"
35 
37  : QFutureWatcher( nullptr )
38  , mItem( item )
39 {
40 }
41 
42 // sort function for QList<QgsDataItem*>, e.g. sorted/grouped provider listings
43 static bool cmpByDataItemName_( QgsDataItem *a, QgsDataItem *b )
44 {
45  return QString::localeAwareCompare( a->name(), b->name() ) < 0;
46 }
47 
49  : QAbstractItemModel( parent )
50 
51 {
52 }
53 
55 {
57 }
58 
60 {
61  QString home = QgsProject::instance()->homePath();
62  if ( mProjectHome && mProjectHome->path().mid( QStringLiteral( PROJECT_HOME_PREFIX ).length() ) == home )
63  return;
64 
65  int idx = mRootItems.indexOf( mProjectHome );
66 
67  // using layoutAboutToBeChanged() was messing expanded items
68  if ( idx >= 0 )
69  {
70  beginRemoveRows( QModelIndex(), idx, idx );
71  mRootItems.remove( idx );
72  endRemoveRows();
73  }
74  delete mProjectHome;
75  mProjectHome = home.isNull() ? nullptr : new QgsProjectHomeItem( nullptr, tr( "Project Home" ), home, QStringLiteral( PROJECT_HOME_PREFIX ) + home );
76  if ( mProjectHome )
77  {
78  setupItemConnections( mProjectHome );
79 
80  beginInsertRows( QModelIndex(), 0, 0 );
81  mRootItems.insert( 0, mProjectHome );
82  endInsertRows();
83  }
84 }
85 
87 {
89 
90  // give the home directory a prominent third place
91  QgsDirectoryItem *item = new QgsDirectoryItem( nullptr, tr( "Home" ), QDir::homePath(), QStringLiteral( HOME_PREFIX ) + QDir::homePath() );
92  item->setSortKey( QStringLiteral( " 2" ) );
93  setupItemConnections( item );
94  mRootItems << item;
95 
96  // add favorite directories
97  mFavorites = new QgsFavoritesItem( nullptr, tr( "Favorites" ) );
98  if ( mFavorites )
99  {
100  setupItemConnections( mFavorites );
102  }
103 
104  // add drives
105  const auto drives { QDir::drives() };
106  for ( const QFileInfo &drive : drives )
107  {
108  const QString path = drive.absolutePath();
109 
110  if ( QgsDirectoryItem::hiddenPath( path ) )
111  continue;
112 
113  QgsDirectoryItem *item = new QgsDirectoryItem( nullptr, path, path );
114  item->setSortKey( QStringLiteral( " 3 %1" ).arg( path ) );
115  mDriveItems.insert( path, item );
116 
117  setupItemConnections( item );
118  mRootItems << item;
119  }
120 
121 #ifdef Q_OS_MAC
122  QString path = QString( "/Volumes" );
123  QgsDirectoryItem *vols = new QgsDirectoryItem( nullptr, path, path );
124  mRootItems << vols;
125 #endif
126 
127  // container for displaying providers as sorted groups (by QgsDataProvider::DataCapability enum)
128  QMap<int, QgsDataItem *> providerMap;
129 
130  const auto constProviders = QgsApplication::dataItemProviderRegistry()->providers();
131  for ( QgsDataItemProvider *pr : constProviders )
132  {
133  int capabilities = pr->capabilities();
134  if ( capabilities == QgsDataProvider::NoDataCapabilities )
135  {
136  QgsDebugMsgLevel( pr->name() + " does not have any dataCapabilities", 4 );
137  continue;
138  }
139 
140  QgsDataItem *item = pr->createDataItem( QString(), nullptr ); // empty path -> top level
141  if ( item )
142  {
143  // Forward the signal from the root items to the model (and then to the app)
145  QgsDebugMsgLevel( "Add new top level item : " + item->name(), 4 );
146  setupItemConnections( item );
147  providerMap.insertMulti( capabilities, item );
148  }
149  }
150 
151  // add as sorted groups by QgsDataProvider::DataCapability enum
152  const auto constUniqueKeys = providerMap.uniqueKeys();
153  for ( int key : constUniqueKeys )
154  {
155  QList<QgsDataItem *> providerGroup = providerMap.values( key );
156  if ( providerGroup.size() > 1 )
157  {
158  std::sort( providerGroup.begin(), providerGroup.end(), cmpByDataItemName_ );
159  }
160 
161  const auto constProviderGroup = providerGroup;
162  for ( QgsDataItem *ditem : constProviderGroup )
163  {
164  mRootItems << ditem;
165  }
166  }
167 }
168 
170 {
171  const auto constMRootItems = mRootItems;
172  for ( QgsDataItem *item : constMRootItems )
173  {
174  delete item;
175  }
176 
177  mRootItems.clear();
178  mDriveItems.clear();
179 }
180 
181 QMap<QString, QgsDirectoryItem *> QgsBrowserModel::driveItems() const
182 {
183  return mDriveItems;
184 }
185 
186 
188 {
189  if ( ! mInitialized )
190  {
192  addRootItems();
193  mInitialized = true;
194  }
195 }
196 
197 
198 Qt::ItemFlags QgsBrowserModel::flags( const QModelIndex &index ) const
199 {
200  if ( !index.isValid() )
201  return Qt::ItemFlags();
202 
203  Qt::ItemFlags flags = Qt::ItemIsEnabled | Qt::ItemIsSelectable;
204 
205  QgsDataItem *ptr = dataItem( index );
206 
207  if ( !ptr )
208  {
209  QgsDebugMsgLevel( QStringLiteral( "FLAGS PROBLEM!" ), 4 );
210  return Qt::ItemFlags();
211  }
212 
213  if ( ptr->hasDragEnabled() )
214  flags |= Qt::ItemIsDragEnabled;
215 
217  if ( ptr->acceptDrop() )
218  flags |= Qt::ItemIsDropEnabled;
220 
221  if ( ptr->capabilities2() & QgsDataItem::Rename )
222  flags |= Qt::ItemIsEditable;
223 
224  return flags;
225 }
226 
227 QVariant QgsBrowserModel::data( const QModelIndex &index, int role ) const
228 {
229  if ( !index.isValid() )
230  return QVariant();
231 
232  QgsDataItem *item = dataItem( index );
233  if ( !item )
234  {
235  return QVariant();
236  }
237  else if ( role == Qt::DisplayRole || role == Qt::EditRole )
238  {
239  return item->name();
240  }
241  else if ( role == QgsBrowserModel::SortRole )
242  {
243  return item->sortKey();
244  }
245  else if ( role == Qt::ToolTipRole )
246  {
247  return item->toolTip();
248  }
249  else if ( role == Qt::DecorationRole && index.column() == 0 )
250  {
251  return item->icon();
252  }
253  else if ( role == QgsBrowserModel::PathRole )
254  {
255  return item->path();
256  }
257  else if ( role == QgsBrowserModel::CommentRole )
258  {
259  if ( item->type() == QgsDataItem::Layer )
260  {
261  QgsLayerItem *lyrItem = qobject_cast<QgsLayerItem *>( item );
262  return lyrItem->comments();
263  }
264  return QVariant();
265  }
266  else
267  {
268  // unsupported role
269  return QVariant();
270  }
271 }
272 
273 bool QgsBrowserModel::setData( const QModelIndex &index, const QVariant &value, int role )
274 {
275  if ( !index.isValid() )
276  return false;
277 
278 
279  QgsDataItem *item = dataItem( index );
280  if ( !item )
281  {
282  return false;
283  }
284 
285  if ( !( item->capabilities2() & QgsDataItem::Rename ) )
286  return false;
287 
288  switch ( role )
289  {
290  case Qt::EditRole:
291  {
293  return item->rename( value.toString() );
295  }
296  }
297  return false;
298 }
299 
300 QVariant QgsBrowserModel::headerData( int section, Qt::Orientation orientation, int role ) const
301 {
302  Q_UNUSED( section )
303  if ( orientation == Qt::Horizontal && role == Qt::DisplayRole )
304  {
305  return QVariant( "header" );
306  }
307 
308  return QVariant();
309 }
310 
311 int QgsBrowserModel::rowCount( const QModelIndex &parent ) const
312 {
313  //QgsDebugMsg(QString("isValid = %1 row = %2 column = %3").arg(parent.isValid()).arg(parent.row()).arg(parent.column()));
314 
315  if ( !parent.isValid() )
316  {
317  // root item: its children are top level items
318  return mRootItems.count(); // mRoot
319  }
320  else
321  {
322  // ordinary item: number of its children
323  QgsDataItem *item = dataItem( parent );
324  //if ( item ) QgsDebugMsg(QString("path = %1 rowCount = %2").arg(item->path()).arg(item->rowCount()) );
325  return item ? item->rowCount() : 0;
326  }
327 }
328 
329 bool QgsBrowserModel::hasChildren( const QModelIndex &parent ) const
330 {
331  if ( !parent.isValid() )
332  return !mRootItems.isEmpty(); // root item: its children are top level items
333 
334  QgsDataItem *item = dataItem( parent );
335  return item && item->hasChildren();
336 }
337 
338 int QgsBrowserModel::columnCount( const QModelIndex &parent ) const
339 {
340  Q_UNUSED( parent )
341  return 1;
342 }
343 
344 QModelIndex QgsBrowserModel::findPath( const QString &path, Qt::MatchFlag matchFlag )
345 {
346  return findPath( this, path, matchFlag );
347 }
348 
349 QModelIndex QgsBrowserModel::findPath( QAbstractItemModel *model, const QString &path, Qt::MatchFlag matchFlag )
350 {
351  if ( !model )
352  return QModelIndex();
353 
354  QModelIndex index; // starting from root
355  bool foundChild = true;
356 
357  while ( foundChild )
358  {
359  foundChild = false; // assume that the next child item will not be found
360 
361  for ( int i = 0; i < model->rowCount( index ); i++ )
362  {
363  QModelIndex idx = model->index( i, 0, index );
364 
365  QString itemPath = model->data( idx, PathRole ).toString();
366  if ( itemPath == path )
367  {
368  QgsDebugMsgLevel( "Arrived " + itemPath, 4 );
369  return idx; // we have found the item we have been looking for
370  }
371 
372  // paths are slash separated identifier
373  if ( path.startsWith( itemPath + '/' ) )
374  {
375  foundChild = true;
376  index = idx;
377  break;
378  }
379  }
380  }
381 
382  if ( matchFlag == Qt::MatchStartsWith )
383  return index;
384 
385  QgsDebugMsgLevel( QStringLiteral( "path not found" ), 4 );
386  return QModelIndex(); // not found
387 }
388 
389 QModelIndex QgsBrowserModel::findUri( const QString &uri, QModelIndex index )
390 {
391  for ( int i = 0; i < this->rowCount( index ); i++ )
392  {
393  QModelIndex idx = this->index( i, 0, index );
394 
395  if ( qobject_cast<QgsLayerItem *>( dataItem( idx ) ) )
396  {
397  QString itemUri = qobject_cast<QgsLayerItem *>( dataItem( idx ) )->uri();
398 
399  if ( itemUri == uri )
400  {
401  QgsDebugMsgLevel( "Arrived " + itemUri, 4 );
402  return idx; // we have found the item we have been looking for
403  }
404  }
405 
406  QModelIndex childIdx = findUri( uri, idx );
407  if ( childIdx.isValid() )
408  return childIdx;
409  }
410  return QModelIndex();
411 }
412 
414 {
415  // deprecated, no use
416 }
417 
419 {
420  // TODO: put items creating currently children in threads to deleteLater (does not seem urget because reload() is not used in QGIS)
421  beginResetModel();
422  removeRootItems();
423  addRootItems();
424  endResetModel();
425 }
426 
428 {
429  const QList< QFileInfo > drives = QDir::drives();
430  // remove any removed drives
431  const QStringList existingDrives = mDriveItems.keys();
432  for ( const QString &drivePath : existingDrives )
433  {
434  bool stillExists = false;
435  for ( const QFileInfo &drive : drives )
436  {
437  if ( drivePath == drive.absolutePath() )
438  {
439  stillExists = true;
440  break;
441  }
442  }
443 
444  if ( stillExists )
445  continue;
446 
447  // drive has been removed, remove corresponding item
448  if ( QgsDirectoryItem *driveItem = mDriveItems.value( drivePath ) )
449  removeRootItem( driveItem );
450  }
451 
452  for ( const QFileInfo &drive : drives )
453  {
454  const QString path = drive.absolutePath();
455 
456  if ( QgsDirectoryItem::hiddenPath( path ) )
457  continue;
458 
459  // does an item for this drive already exist?
460  if ( !mDriveItems.contains( path ) )
461  {
462  QgsDirectoryItem *item = new QgsDirectoryItem( nullptr, path, path );
463  item->setSortKey( QStringLiteral( " 3 %1" ).arg( path ) );
464 
465  mDriveItems.insert( path, item );
466  setupItemConnections( item );
467 
468  beginInsertRows( QModelIndex(), mRootItems.count(), mRootItems.count() );
469  mRootItems << item;
470  endInsertRows();
471  }
472  }
473 }
474 
475 QModelIndex QgsBrowserModel::index( int row, int column, const QModelIndex &parent ) const
476 {
477  if ( column < 0 || column >= columnCount() || row < 0 )
478  return QModelIndex();
479 
480  QgsDataItem *p = dataItem( parent );
481  const QVector<QgsDataItem *> &items = p ? p->children() : mRootItems;
482  QgsDataItem *item = items.value( row, nullptr );
483  return item ? createIndex( row, column, item ) : QModelIndex();
484 }
485 
486 QModelIndex QgsBrowserModel::parent( const QModelIndex &index ) const
487 {
488  QgsDataItem *item = dataItem( index );
489  if ( !item )
490  return QModelIndex();
491 
492  return findItem( item->parent() );
493 }
494 
496 {
497  const QVector<QgsDataItem *> &items = parent ? parent->children() : mRootItems;
498 
499  for ( int i = 0; i < items.size(); i++ )
500  {
501  if ( items[i] == item )
502  return createIndex( i, 0, item );
503 
504  QModelIndex childIndex = findItem( item, items[i] );
505  if ( childIndex.isValid() )
506  return childIndex;
507  }
508  return QModelIndex();
509 }
510 
512 {
513  QgsDebugMsgLevel( "parent mPath = " + parent->path(), 3 );
514  QModelIndex idx = findItem( parent );
515  if ( !idx.isValid() )
516  return;
517  QgsDebugMsgLevel( QStringLiteral( "valid" ), 3 );
518  beginInsertRows( idx, first, last );
519  QgsDebugMsgLevel( QStringLiteral( "end" ), 3 );
520 }
522 {
523  QgsDebugMsgLevel( QStringLiteral( "Entered" ), 3 );
524  endInsertRows();
525 }
527 {
528  QgsDebugMsgLevel( "parent mPath = " + parent->path(), 3 );
529  QModelIndex idx = findItem( parent );
530  if ( !idx.isValid() )
531  return;
532  beginRemoveRows( idx, first, last );
533 }
535 {
536  QgsDebugMsgLevel( QStringLiteral( "Entered" ), 3 );
537  endRemoveRows();
538 }
540 {
541  QgsDebugMsgLevel( QStringLiteral( "Entered" ), 3 );
542  QModelIndex idx = findItem( item );
543  if ( !idx.isValid() )
544  return;
545  emit dataChanged( idx, idx );
546 }
548 {
549  if ( !item )
550  return;
551  QModelIndex idx = findItem( item );
552  if ( !idx.isValid() )
553  return;
554  QgsDebugMsgLevel( QStringLiteral( "item %1 state changed %2 -> %3" ).arg( item->path() ).arg( oldState ).arg( item->state() ), 4 );
555  emit stateChanged( idx, oldState );
556 }
557 
558 void QgsBrowserModel::setupItemConnections( QgsDataItem *item )
559 {
560  connect( item, &QgsDataItem::beginInsertItems,
562  connect( item, &QgsDataItem::endInsertItems,
564  connect( item, &QgsDataItem::beginRemoveItems,
566  connect( item, &QgsDataItem::endRemoveItems,
568  connect( item, &QgsDataItem::dataChanged,
570  connect( item, &QgsDataItem::stateChanged,
572 
573  // if it's a collection item, also forwards connectionsChanged
574  QgsDataCollectionItem *collectionItem = qobject_cast<QgsDataCollectionItem *>( item );
575  if ( collectionItem )
577 }
578 
579 QStringList QgsBrowserModel::mimeTypes() const
580 {
581  QStringList types;
582  // In theory the mime type convention is: application/x-vnd.<vendor>.<application>.<type>
583  // but it seems a bit over formalized. Would be an application/x-qgis-uri better?
584  types << QStringLiteral( "application/x-vnd.qgis.qgis.uri" );
585  return types;
586 }
587 
588 QMimeData *QgsBrowserModel::mimeData( const QModelIndexList &indexes ) const
589 {
591  const auto constIndexes = indexes;
592  for ( const QModelIndex &index : constIndexes )
593  {
594  if ( index.isValid() )
595  {
596  QgsDataItem *ptr = reinterpret_cast< QgsDataItem * >( index.internalPointer() );
597  QgsMimeDataUtils::Uri uri = ptr->mimeUri();
598  if ( uri.isValid() )
599  lst.append( uri );
600  }
601  }
602  return QgsMimeDataUtils::encodeUriList( lst );
603 }
604 
605 bool QgsBrowserModel::dropMimeData( const QMimeData *data, Qt::DropAction action, int, int, const QModelIndex &parent )
606 {
607  QgsDataItem *destItem = dataItem( parent );
608  if ( !destItem )
609  {
610  QgsDebugMsgLevel( QStringLiteral( "DROP PROBLEM!" ), 4 );
611  return false;
612  }
613 
615  return destItem->handleDrop( data, action );
617 }
618 
619 QgsDataItem *QgsBrowserModel::dataItem( const QModelIndex &idx ) const
620 {
621  void *v = idx.internalPointer();
622  QgsDataItem *d = reinterpret_cast<QgsDataItem *>( v );
623  Q_ASSERT( !v || d );
624  return d;
625 }
626 
627 bool QgsBrowserModel::canFetchMore( const QModelIndex &parent ) const
628 {
629  QgsDataItem *item = dataItem( parent );
630  // if ( item )
631  // QgsDebugMsg( QStringLiteral( "path = %1 canFetchMore = %2" ).arg( item->path() ).arg( item && ! item->isPopulated() ) );
632  return ( item && item->state() == QgsDataItem::NotPopulated );
633 }
634 
635 void QgsBrowserModel::fetchMore( const QModelIndex &parent )
636 {
637  QgsDataItem *item = dataItem( parent );
638 
639  if ( !item || item->state() == QgsDataItem::Populating || item->state() == QgsDataItem::Populated )
640  return;
641 
642  QgsDebugMsgLevel( "path = " + item->path(), 4 );
643 
644  item->populate();
645 }
646 
647 /* Refresh dir path */
648 void QgsBrowserModel::refresh( const QString &path )
649 {
650  QModelIndex index = findPath( path );
651  refresh( index );
652 }
653 
654 /* Refresh item */
655 void QgsBrowserModel::refresh( const QModelIndex &index )
656 {
657  QgsDataItem *item = dataItem( index );
658  if ( !item || item->state() == QgsDataItem::Populating )
659  return;
660 
661  QgsDebugMsgLevel( "Refresh " + item->path(), 4 );
662 
663  item->refresh();
664 }
665 
666 void QgsBrowserModel::addFavoriteDirectory( const QString &directory, const QString &name )
667 {
668  Q_ASSERT( mFavorites );
669  mFavorites->addDirectory( directory, name );
670 }
671 
672 void QgsBrowserModel::removeFavorite( const QModelIndex &index )
673 {
674  QgsDirectoryItem *item = qobject_cast<QgsDirectoryItem *>( dataItem( index ) );
675  if ( !item )
676  return;
677 
678  mFavorites->removeDirectory( item );
679 }
680 
681 void QgsBrowserModel::removeFavorite( QgsFavoriteItem *favorite )
682 {
683  if ( !favorite )
684  return;
685 
686  mFavorites->removeDirectory( favorite );
687 }
688 
690 {
691  QgsSettings settings;
692  QStringList hiddenItems = settings.value( QStringLiteral( "browser/hiddenPaths" ),
693  QStringList() ).toStringList();
694  int idx = hiddenItems.indexOf( item->path() );
695  if ( idx != -1 )
696  {
697  hiddenItems.removeAt( idx );
698  }
699  else
700  {
701  hiddenItems << item->path();
702  }
703  settings.setValue( QStringLiteral( "browser/hiddenPaths" ), hiddenItems );
704  if ( item->parent() )
705  {
706  item->parent()->deleteChildItem( item );
707  }
708  else
709  {
710  removeRootItem( item );
711  }
712 }
713 
714 
715 void QgsBrowserModel::removeRootItem( QgsDataItem *item )
716 {
717  int i = mRootItems.indexOf( item );
718  beginRemoveRows( QModelIndex(), i, i );
719  mRootItems.remove( i );
720  QgsDirectoryItem *dirItem = qobject_cast< QgsDirectoryItem * >( item );
721  if ( !mDriveItems.key( dirItem ).isEmpty() )
722  {
723  mDriveItems.remove( mDriveItems.key( dirItem ) );
724  }
725  item->deleteLater();
726  endRemoveRows();
727 }
728 
A Collection: logical collection of layers or subcollections, e.g.
Definition: qgsdataitem.h:571
virtual QVariant sortKey() const
Returns the sorting key for the item.
void beginInsertItems(QgsDataItem *parent, int first, int last)
QString path() const
Definition: qgsdataitem.h:309
void setSortKey(const QVariant &key)
Sets a custom sorting key for the item.
bool canFetchMore(const QModelIndex &parent) const override
QString name() const
Returns the name of the item (the displayed text for the item).
Definition: qgsdataitem.h:300
void connectionsChanged()
Connections changed in the browser, forwarded to the widget and used to notify the provider dialogs o...
void dataChanged(QgsDataItem *item)
QString toolTip() const
Definition: qgsdataitem.h:341
void hidePath(QgsDataItem *item)
Hide the given path in the browser model.
QgsBrowserModel(QObject *parent=nullptr)
Constructor for QgsBrowserModel, with the specified parent object.
This class is a composition of two QSettings instances:
Definition: qgssettings.h:58
void connectionsChanged()
Emitted when the provider&#39;s connections of the child items have changed This signal is normally forwa...
int rowCount(const QModelIndex &parent=QModelIndex()) const override
void fetchMore(const QModelIndex &parent) override
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), Section section=NoSection) const
Returns the value for setting key.
void refreshDrives()
Refreshes the list of drive items, removing any corresponding to removed drives and adding newly adde...
QModelIndex findPath(const QString &path, Qt::MatchFlag matchFlag=Qt::MatchExactly)
Returns index of item with given path.
void beginRemoveItems(QgsDataItem *parent, int first, int last)
virtual QIcon icon()
Q_DECL_DEPRECATED void connectItem(QgsDataItem *item)
#define Q_NOWARN_DEPRECATED_PUSH
Definition: qgis.h:649
#define PROJECT_HOME_PREFIX
Type type() const
Definition: qgsdataitem.h:281
static QMimeData * encodeUriList(const UriList &layers)
Encodes a URI list to a new QMimeData object.
bool isValid() const
Returns whether the object contains valid data.
virtual Q_DECL_DEPRECATED bool rename(const QString &name)
Sets a new name for the item, and returns true if the item was successfully renamed.
void itemStateChanged(QgsDataItem *item, QgsDataItem::State oldState)
QStringList mimeTypes() const override
QMap< QString, QgsDirectoryItem * > driveItems() const
Returns a map of the root drive items shown in the browser.
bool hasChildren(const QModelIndex &parent=QModelIndex()) const override
void endRemoveItems()
State state() const
Item path used to access path in the tree, see QgsDataItem::mPath.
QString homePath
Definition: qgsproject.h:94
QgsDirectoryItem * mProjectHome
static void deleteLater(QVector< QgsDataItem *> &items)
QList< QgsDataItemProvider * > providers() const
Returns the list of available providers.
QgsDataItem * parent() const
Gets item parent.
Definition: qgsdataitem.h:286
QgsFavoritesItem * mFavorites
void beginRemoveItems(QgsDataItem *parent, int first, int last)
#define QgsDebugMsgLevel(str, level)
Definition: qgslogger.h:39
QModelIndex parent(const QModelIndex &index) const override
QVector< QgsDataItem * > mRootItems
#define HOME_PREFIX
Children not yet created.
Definition: qgsdataitem.h:104
virtual Q_DECL_DEPRECATED bool acceptDrop()
Returns whether the item accepts drag and dropped layers - e.g.
Definition: qgsdataitem.h:183
Creating children in separate thread (populating or refreshing)
Definition: qgsdataitem.h:105
void initialize()
Delayed initialization, needed because the provider registry must be already populated.
QgsDataItem * dataItem(const QModelIndex &idx) const
Returns the data item at the specified index, or nullptr if no item exists at the index...
void removeFavorite(const QModelIndex &index)
Removes a favorite directory from its corresponding model index.
virtual bool hasDragEnabled() const
Returns true if the item may be dragged.
Definition: qgsdataitem.h:210
virtual QgsMimeDataUtils::Uri mimeUri() const
Returns mime URI for the data item.
Definition: qgsdataitem.h:218
QgsBrowserWatcher(QgsDataItem *item)
bool hasChildren()
static bool hiddenPath(const QString &path)
Check if the given path is hidden from the browser model.
void reload()
Reload the whole model.
A directory: contains subdirectories and layers.
Definition: qgsdataitem.h:611
Base class for all items in the model.
Definition: qgsdataitem.h:49
Custom sort role, see QgsDataItem::sortKey()
QVector< QgsDataItem * > children() const
Definition: qgsdataitem.h:292
#define Q_NOWARN_DEPRECATED_POP
Definition: qgis.h:650
QModelIndex findItem(QgsDataItem *item, QgsDataItem *parent=nullptr) const
Returns the model index corresponding to the specified data item.
QModelIndex findUri(const QString &uri, QModelIndex index=QModelIndex())
Returns index of layer item with given uri.
QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const override
~QgsBrowserModel() override
void addFavoriteDirectory(const QString &directory, const QString &name=QString())
Adds a directory to the favorites group.
void beginInsertItems(QgsDataItem *parent, int first, int last)
void setValue(const QString &key, const QVariant &value, QgsSettings::Section section=QgsSettings::NoSection)
Sets the value of setting key to value.
Contains various Favorites directories.
Definition: qgsdataitem.h:721
void removeDirectory(QgsDirectoryItem *item)
Removes an existing directory from the favorites group.
Item can be renamed.
Definition: qgsdataitem.h:227
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const override
void addDirectory(const QString &directory, const QString &name=QString())
Adds a new directory to the favorites group.
bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole) override
static QgsProject * instance()
Returns the QgsProject singleton instance.
Definition: qgsproject.cpp:442
int columnCount(const QModelIndex &parent=QModelIndex()) const override
bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) override
void stateChanged(const QModelIndex &index, QgsDataItem::State oldState)
Emitted when item children fetch was finished.
void refresh(const QString &path)
Refresh item specified by path.
QList< QgsMimeDataUtils::Uri > UriList
void endInsertItems()
QMimeData * mimeData(const QModelIndexList &indexes) const override
void homePathChanged()
Emitted when the home path of the project changes.
Item that represents a layer that can be opened with one of the providers.
Definition: qgsdataitem.h:452
virtual Q_DECL_DEPRECATED bool handleDrop(const QMimeData *, Qt::DropAction)
Attempts to process the mime data dropped on this item.
Definition: qgsdataitem.h:193
virtual void deleteChildItem(QgsDataItem *child)
Removes and deletes a child item, emitting relevant signals to the model.
void itemDataChanged(QgsDataItem *item)
Qt::ItemFlags flags(const QModelIndex &index) const override
virtual void populate(const QVector< QgsDataItem *> &children)
Children created.
Definition: qgsdataitem.h:106
virtual QString comments() const
Returns comments of the layer.
Definition: qgsdataitem.h:517
void addRootItems()
Populates the model.
static QgsDataItemProviderRegistry * dataItemProviderRegistry()
Returns the application&#39;s data item provider registry, which keeps a list of data item providers that...
virtual void refresh(const QVector< QgsDataItem *> &children)
Refresh the items from a specified list of child items.
This is the interface for those who want to add custom data items to the browser tree.
void stateChanged(QgsDataItem *item, QgsDataItem::State oldState)
virtual Capabilities capabilities2() const
Returns the capabilities for the data item.
Definition: qgsdataitem.h:265