QGIS API Documentation  3.12.1-BucureČ™ti (121cc00ff0)
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(),
92  QStringLiteral( HOME_PREFIX ) + QDir::homePath(),
93  QStringLiteral( "special:Home" ) );
94  item->setSortKey( QStringLiteral( " 2" ) );
95  setupItemConnections( item );
96  mRootItems << item;
97 
98  // add favorite directories
99  mFavorites = new QgsFavoritesItem( nullptr, tr( "Favorites" ) );
100  if ( mFavorites )
101  {
102  setupItemConnections( mFavorites );
104  }
105 
106  // add drives
107  const auto drives { QDir::drives() };
108  for ( const QFileInfo &drive : drives )
109  {
110  const QString path = drive.absolutePath();
111 
112  if ( QgsDirectoryItem::hiddenPath( path ) )
113  continue;
114 
115  QgsDirectoryItem *item = new QgsDirectoryItem( nullptr, path, path, path, QStringLiteral( "special:Drives" ) );
116  item->setSortKey( QStringLiteral( " 3 %1" ).arg( path ) );
117  mDriveItems.insert( path, item );
118 
119  setupItemConnections( item );
120  mRootItems << item;
121  }
122 
123 #ifdef Q_OS_MAC
124  QString path = QString( "/Volumes" );
125  QgsDirectoryItem *vols = new QgsDirectoryItem( nullptr, path, path, path, QStringLiteral( "special:Volumes" ) );
126  mRootItems << vols;
127 #endif
128 
129  // container for displaying providers as sorted groups (by QgsDataProvider::DataCapability enum)
130  QMap<int, QgsDataItem *> providerMap;
131 
132  const auto constProviders = QgsApplication::dataItemProviderRegistry()->providers();
133  for ( QgsDataItemProvider *pr : constProviders )
134  {
135  int capabilities = pr->capabilities();
136  if ( capabilities == QgsDataProvider::NoDataCapabilities )
137  {
138  QgsDebugMsgLevel( pr->name() + " does not have any dataCapabilities", 4 );
139  continue;
140  }
141 
142  QgsDataItem *item = pr->createDataItem( QString(), nullptr ); // empty path -> top level
143  if ( item )
144  {
145  // make sure the top level key is set always
146  item->setProviderKey( pr->name() );
147  // Forward the signal from the root items to the model (and then to the app)
149  QgsDebugMsgLevel( "Add new top level item : " + item->name(), 4 );
150  setupItemConnections( item );
151  providerMap.insertMulti( capabilities, item );
152  }
153  }
154 
155  // add as sorted groups by QgsDataProvider::DataCapability enum
156  const auto constUniqueKeys = providerMap.uniqueKeys();
157  for ( int key : constUniqueKeys )
158  {
159  QList<QgsDataItem *> providerGroup = providerMap.values( key );
160  if ( providerGroup.size() > 1 )
161  {
162  std::sort( providerGroup.begin(), providerGroup.end(), cmpByDataItemName_ );
163  }
164 
165  const auto constProviderGroup = providerGroup;
166  for ( QgsDataItem *ditem : constProviderGroup )
167  {
168  mRootItems << ditem;
169  }
170  }
171 }
172 
174 {
175  const auto constMRootItems = mRootItems;
176  for ( QgsDataItem *item : constMRootItems )
177  {
178  delete item;
179  }
180 
181  mRootItems.clear();
182  mDriveItems.clear();
183 }
184 
185 QMap<QString, QgsDirectoryItem *> QgsBrowserModel::driveItems() const
186 {
187  return mDriveItems;
188 }
189 
190 
192 {
193  if ( ! mInitialized )
194  {
196  addRootItems();
197  mInitialized = true;
198  }
199 }
200 
201 Qt::ItemFlags QgsBrowserModel::flags( const QModelIndex &index ) const
202 {
203  if ( !index.isValid() )
204  return Qt::ItemFlags();
205 
206  Qt::ItemFlags flags = Qt::ItemIsEnabled | Qt::ItemIsSelectable;
207 
208  QgsDataItem *ptr = dataItem( index );
209 
210  if ( !ptr )
211  {
212  QgsDebugMsgLevel( QStringLiteral( "FLAGS PROBLEM!" ), 4 );
213  return Qt::ItemFlags();
214  }
215 
216  if ( ptr->hasDragEnabled() )
217  flags |= Qt::ItemIsDragEnabled;
218 
220  if ( ptr->acceptDrop() )
221  flags |= Qt::ItemIsDropEnabled;
223 
224  if ( ptr->capabilities2() & QgsDataItem::Rename )
225  flags |= Qt::ItemIsEditable;
226 
227  return flags;
228 }
229 
230 QVariant QgsBrowserModel::data( const QModelIndex &index, int role ) const
231 {
232  if ( !index.isValid() )
233  return QVariant();
234 
235  QgsDataItem *item = dataItem( index );
236  if ( !item )
237  {
238  return QVariant();
239  }
240  else if ( role == Qt::DisplayRole || role == Qt::EditRole )
241  {
242  return item->name();
243  }
244  else if ( role == QgsBrowserModel::SortRole )
245  {
246  return item->sortKey();
247  }
248  else if ( role == Qt::ToolTipRole )
249  {
250  return item->toolTip();
251  }
252  else if ( role == Qt::DecorationRole && index.column() == 0 )
253  {
254  return item->icon();
255  }
256  else if ( role == QgsBrowserModel::PathRole )
257  {
258  return item->path();
259  }
260  else if ( role == QgsBrowserModel::CommentRole )
261  {
262  if ( item->type() == QgsDataItem::Layer )
263  {
264  QgsLayerItem *lyrItem = qobject_cast<QgsLayerItem *>( item );
265  return lyrItem->comments();
266  }
267  return QVariant();
268  }
269  else if ( role == QgsBrowserModel::ProviderKeyRole )
270  {
271  return item->providerKey();
272  }
273  else
274  {
275  // unsupported role
276  return QVariant();
277  }
278 }
279 
280 bool QgsBrowserModel::setData( const QModelIndex &index, const QVariant &value, int role )
281 {
282  if ( !index.isValid() )
283  return false;
284 
285 
286  QgsDataItem *item = dataItem( index );
287  if ( !item )
288  {
289  return false;
290  }
291 
292  if ( !( item->capabilities2() & QgsDataItem::Rename ) )
293  return false;
294 
295  switch ( role )
296  {
297  case Qt::EditRole:
298  {
300  return item->rename( value.toString() );
302  }
303  }
304  return false;
305 }
306 
307 QVariant QgsBrowserModel::headerData( int section, Qt::Orientation orientation, int role ) const
308 {
309  Q_UNUSED( section )
310  if ( orientation == Qt::Horizontal && role == Qt::DisplayRole )
311  {
312  return QVariant( "header" );
313  }
314 
315  return QVariant();
316 }
317 
318 int QgsBrowserModel::rowCount( const QModelIndex &parent ) const
319 {
320  //QgsDebugMsg(QString("isValid = %1 row = %2 column = %3").arg(parent.isValid()).arg(parent.row()).arg(parent.column()));
321 
322  if ( !parent.isValid() )
323  {
324  // root item: its children are top level items
325  return mRootItems.count(); // mRoot
326  }
327  else
328  {
329  // ordinary item: number of its children
330  QgsDataItem *item = dataItem( parent );
331  //if ( item ) QgsDebugMsg(QString("path = %1 rowCount = %2").arg(item->path()).arg(item->rowCount()) );
332  return item ? item->rowCount() : 0;
333  }
334 }
335 
336 bool QgsBrowserModel::hasChildren( const QModelIndex &parent ) const
337 {
338  if ( !parent.isValid() )
339  return !mRootItems.isEmpty(); // root item: its children are top level items
340 
341  QgsDataItem *item = dataItem( parent );
342  return item && item->hasChildren();
343 }
344 
345 int QgsBrowserModel::columnCount( const QModelIndex &parent ) const
346 {
347  Q_UNUSED( parent )
348  return 1;
349 }
350 
351 QModelIndex QgsBrowserModel::findPath( const QString &path, Qt::MatchFlag matchFlag )
352 {
353  return findPath( this, path, matchFlag );
354 }
355 
356 QModelIndex QgsBrowserModel::findPath( QAbstractItemModel *model, const QString &path, Qt::MatchFlag matchFlag )
357 {
358  if ( !model )
359  return QModelIndex();
360 
361  QModelIndex index; // starting from root
362  bool foundChild = true;
363 
364  while ( foundChild )
365  {
366  foundChild = false; // assume that the next child item will not be found
367 
368  for ( int i = 0; i < model->rowCount( index ); i++ )
369  {
370  QModelIndex idx = model->index( i, 0, index );
371 
372  QString itemPath = model->data( idx, PathRole ).toString();
373  if ( itemPath == path )
374  {
375  QgsDebugMsgLevel( "Arrived " + itemPath, 4 );
376  return idx; // we have found the item we have been looking for
377  }
378 
379  // paths are slash separated identifier
380  if ( path.startsWith( itemPath + '/' ) )
381  {
382  foundChild = true;
383  index = idx;
384  break;
385  }
386  }
387  }
388 
389  if ( matchFlag == Qt::MatchStartsWith )
390  return index;
391 
392  QgsDebugMsgLevel( QStringLiteral( "path not found" ), 4 );
393  return QModelIndex(); // not found
394 }
395 
396 QModelIndex QgsBrowserModel::findUri( const QString &uri, QModelIndex index )
397 {
398  for ( int i = 0; i < this->rowCount( index ); i++ )
399  {
400  QModelIndex idx = this->index( i, 0, index );
401 
402  if ( qobject_cast<QgsLayerItem *>( dataItem( idx ) ) )
403  {
404  QString itemUri = qobject_cast<QgsLayerItem *>( dataItem( idx ) )->uri();
405 
406  if ( itemUri == uri )
407  {
408  QgsDebugMsgLevel( "Arrived " + itemUri, 4 );
409  return idx; // we have found the item we have been looking for
410  }
411  }
412 
413  QModelIndex childIdx = findUri( uri, idx );
414  if ( childIdx.isValid() )
415  return childIdx;
416  }
417  return QModelIndex();
418 }
419 
421 {
422  // deprecated, no use
423 }
424 
426 {
427  // TODO: put items creating currently children in threads to deleteLater (does not seem urget because reload() is not used in QGIS)
428  beginResetModel();
429  removeRootItems();
430  addRootItems();
431  endResetModel();
432 }
433 
435 {
436  const QList< QFileInfo > drives = QDir::drives();
437  // remove any removed drives
438  const QStringList existingDrives = mDriveItems.keys();
439  for ( const QString &drivePath : existingDrives )
440  {
441  bool stillExists = false;
442  for ( const QFileInfo &drive : drives )
443  {
444  if ( drivePath == drive.absolutePath() )
445  {
446  stillExists = true;
447  break;
448  }
449  }
450 
451  if ( stillExists )
452  continue;
453 
454  // drive has been removed, remove corresponding item
455  if ( QgsDirectoryItem *driveItem = mDriveItems.value( drivePath ) )
456  removeRootItem( driveItem );
457  }
458 
459  for ( const QFileInfo &drive : drives )
460  {
461  const QString path = drive.absolutePath();
462 
463  if ( QgsDirectoryItem::hiddenPath( path ) )
464  continue;
465 
466  // does an item for this drive already exist?
467  if ( !mDriveItems.contains( path ) )
468  {
469  QgsDirectoryItem *item = new QgsDirectoryItem( nullptr, path, path, path, QStringLiteral( "special:Drives" ) );
470  item->setSortKey( QStringLiteral( " 3 %1" ).arg( path ) );
471 
472  mDriveItems.insert( path, item );
473  setupItemConnections( item );
474 
475  beginInsertRows( QModelIndex(), mRootItems.count(), mRootItems.count() );
476  mRootItems << item;
477  endInsertRows();
478  }
479  }
480 }
481 
482 QModelIndex QgsBrowserModel::index( int row, int column, const QModelIndex &parent ) const
483 {
484  if ( column < 0 || column >= columnCount() || row < 0 )
485  return QModelIndex();
486 
487  QgsDataItem *p = dataItem( parent );
488  const QVector<QgsDataItem *> &items = p ? p->children() : mRootItems;
489  QgsDataItem *item = items.value( row, nullptr );
490  return item ? createIndex( row, column, item ) : QModelIndex();
491 }
492 
493 QModelIndex QgsBrowserModel::parent( const QModelIndex &index ) const
494 {
495  QgsDataItem *item = dataItem( index );
496  if ( !item )
497  return QModelIndex();
498 
499  return findItem( item->parent() );
500 }
501 
503 {
504  const QVector<QgsDataItem *> &items = parent ? parent->children() : mRootItems;
505 
506  for ( int i = 0; i < items.size(); i++ )
507  {
508  if ( items[i] == item )
509  return createIndex( i, 0, item );
510 
511  QModelIndex childIndex = findItem( item, items[i] );
512  if ( childIndex.isValid() )
513  return childIndex;
514  }
515  return QModelIndex();
516 }
517 
519 {
520  QgsDebugMsgLevel( "parent mPath = " + parent->path(), 3 );
521  QModelIndex idx = findItem( parent );
522  if ( !idx.isValid() )
523  return;
524  QgsDebugMsgLevel( QStringLiteral( "valid" ), 3 );
525  beginInsertRows( idx, first, last );
526  QgsDebugMsgLevel( QStringLiteral( "end" ), 3 );
527 }
529 {
530  QgsDebugMsgLevel( QStringLiteral( "Entered" ), 3 );
531  endInsertRows();
532 }
534 {
535  QgsDebugMsgLevel( "parent mPath = " + parent->path(), 3 );
536  QModelIndex idx = findItem( parent );
537  if ( !idx.isValid() )
538  return;
539  beginRemoveRows( idx, first, last );
540 }
542 {
543  QgsDebugMsgLevel( QStringLiteral( "Entered" ), 3 );
544  endRemoveRows();
545 }
547 {
548  QgsDebugMsgLevel( QStringLiteral( "Entered" ), 3 );
549  QModelIndex idx = findItem( item );
550  if ( !idx.isValid() )
551  return;
552  emit dataChanged( idx, idx );
553 }
555 {
556  if ( !item )
557  return;
558  QModelIndex idx = findItem( item );
559  if ( !idx.isValid() )
560  return;
561  QgsDebugMsgLevel( QStringLiteral( "item %1 state changed %2 -> %3" ).arg( item->path() ).arg( oldState ).arg( item->state() ), 4 );
562  emit stateChanged( idx, oldState );
563 }
564 
565 void QgsBrowserModel::setupItemConnections( QgsDataItem *item )
566 {
567  connect( item, &QgsDataItem::beginInsertItems,
569  connect( item, &QgsDataItem::endInsertItems,
571  connect( item, &QgsDataItem::beginRemoveItems,
573  connect( item, &QgsDataItem::endRemoveItems,
575  connect( item, &QgsDataItem::dataChanged,
577  connect( item, &QgsDataItem::stateChanged,
579 
580  // if it's a collection item, also forwards connectionsChanged
581  QgsDataCollectionItem *collectionItem = qobject_cast<QgsDataCollectionItem *>( item );
582  if ( collectionItem )
584 }
585 
586 QStringList QgsBrowserModel::mimeTypes() const
587 {
588  QStringList types;
589  // In theory the mime type convention is: application/x-vnd.<vendor>.<application>.<type>
590  // but it seems a bit over formalized. Would be an application/x-qgis-uri better?
591  types << QStringLiteral( "application/x-vnd.qgis.qgis.uri" );
592  return types;
593 }
594 
595 QMimeData *QgsBrowserModel::mimeData( const QModelIndexList &indexes ) const
596 {
598  const auto constIndexes = indexes;
599  for ( const QModelIndex &index : constIndexes )
600  {
601  if ( index.isValid() )
602  {
603  QgsDataItem *ptr = reinterpret_cast< QgsDataItem * >( index.internalPointer() );
604  QgsMimeDataUtils::Uri uri = ptr->mimeUri();
605  if ( uri.isValid() )
606  lst.append( uri );
607  }
608  }
609  return QgsMimeDataUtils::encodeUriList( lst );
610 }
611 
612 bool QgsBrowserModel::dropMimeData( const QMimeData *data, Qt::DropAction action, int, int, const QModelIndex &parent )
613 {
614  QgsDataItem *destItem = dataItem( parent );
615  if ( !destItem )
616  {
617  QgsDebugMsgLevel( QStringLiteral( "DROP PROBLEM!" ), 4 );
618  return false;
619  }
620 
622  return destItem->handleDrop( data, action );
624 }
625 
626 QgsDataItem *QgsBrowserModel::dataItem( const QModelIndex &idx ) const
627 {
628  void *v = idx.internalPointer();
629  QgsDataItem *d = reinterpret_cast<QgsDataItem *>( v );
630  Q_ASSERT( !v || d );
631  return d;
632 }
633 
634 bool QgsBrowserModel::canFetchMore( const QModelIndex &parent ) const
635 {
636  QgsDataItem *item = dataItem( parent );
637  // if ( item )
638  // QgsDebugMsg( QStringLiteral( "path = %1 canFetchMore = %2" ).arg( item->path() ).arg( item && ! item->isPopulated() ) );
639  return ( item && item->state() == QgsDataItem::NotPopulated );
640 }
641 
642 void QgsBrowserModel::fetchMore( const QModelIndex &parent )
643 {
644  QgsDataItem *item = dataItem( parent );
645 
646  if ( !item || item->state() == QgsDataItem::Populating || item->state() == QgsDataItem::Populated )
647  return;
648 
649  QgsDebugMsgLevel( "path = " + item->path(), 4 );
650 
651  item->populate();
652 }
653 
654 /* Refresh dir path */
655 void QgsBrowserModel::refresh( const QString &path )
656 {
657  QModelIndex index = findPath( path );
658  refresh( index );
659 }
660 
661 /* Refresh item */
662 void QgsBrowserModel::refresh( const QModelIndex &index )
663 {
664  QgsDataItem *item = dataItem( index );
665  if ( !item || item->state() == QgsDataItem::Populating )
666  return;
667 
668  QgsDebugMsgLevel( "Refresh " + item->path(), 4 );
669 
670  item->refresh();
671 }
672 
673 void QgsBrowserModel::addFavoriteDirectory( const QString &directory, const QString &name )
674 {
675  Q_ASSERT( mFavorites );
676  mFavorites->addDirectory( directory, name );
677 }
678 
679 void QgsBrowserModel::removeFavorite( const QModelIndex &index )
680 {
681  QgsDirectoryItem *item = qobject_cast<QgsDirectoryItem *>( dataItem( index ) );
682  if ( !item )
683  return;
684 
685  mFavorites->removeDirectory( item );
686 }
687 
688 void QgsBrowserModel::removeFavorite( QgsFavoriteItem *favorite )
689 {
690  if ( !favorite )
691  return;
692 
693  mFavorites->removeDirectory( favorite );
694 }
695 
697 {
698  QgsSettings settings;
699  QStringList hiddenItems = settings.value( QStringLiteral( "browser/hiddenPaths" ),
700  QStringList() ).toStringList();
701  int idx = hiddenItems.indexOf( item->path() );
702  if ( idx != -1 )
703  {
704  hiddenItems.removeAt( idx );
705  }
706  else
707  {
708  hiddenItems << item->path();
709  }
710  settings.setValue( QStringLiteral( "browser/hiddenPaths" ), hiddenItems );
711  if ( item->parent() )
712  {
713  item->parent()->deleteChildItem( item );
714  }
715  else
716  {
717  removeRootItem( item );
718  }
719 }
720 
721 
722 void QgsBrowserModel::removeRootItem( QgsDataItem *item )
723 {
724  int i = mRootItems.indexOf( item );
725  beginRemoveRows( QModelIndex(), i, i );
726  mRootItems.remove( i );
727  QgsDirectoryItem *dirItem = qobject_cast< QgsDirectoryItem * >( item );
728  if ( !mDriveItems.key( dirItem ).isEmpty() )
729  {
730  mDriveItems.remove( mDriveItems.key( dirItem ) );
731  }
732  item->deleteLater();
733  endRemoveRows();
734 }
735 
A Collection: logical collection of layers or subcollections, e.g.
Definition: qgsdataitem.h:601
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:320
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:311
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:373
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:731
#define PROJECT_HOME_PREFIX
Type type() const
Definition: qgsdataitem.h:292
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 setProviderKey(const QString &value)
Sets the provider key that created this item (e.g.
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:96
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:297
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:115
virtual Q_DECL_DEPRECATED bool acceptDrop()
Returns whether the item accepts drag and dropped layers - e.g.
Definition: qgsdataitem.h:194
Creating children in separate thread (populating or refreshing)
Definition: qgsdataitem.h:116
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:221
virtual QgsMimeDataUtils::Uri mimeUri() const
Returns mime URI for the data item.
Definition: qgsdataitem.h:229
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:654
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:303
#define Q_NOWARN_DEPRECATED_POP
Definition: qgis.h:732
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)
QString providerKey() const
Returns the provider key that created this item (e.g.
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:789
void removeDirectory(QgsDirectoryItem *item)
Removes an existing directory from the favorites group.
Data item provider key that created the item,.
Item can be renamed.
Definition: qgsdataitem.h:238
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:450
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:485
virtual Q_DECL_DEPRECATED bool handleDrop(const QMimeData *, Qt::DropAction)
Attempts to process the mime data dropped on this item.
Definition: qgsdataitem.h:204
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:117
virtual QString comments() const
Returns comments of the layer.
Definition: qgsdataitem.h:550
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:276