QGIS API Documentation  3.20.0-Odense (decaadbb31)
qgsbrowserdockwidget.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsbrowserdockwidget.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 "qgsbrowserdockwidget.h"
16 #include "qgsbrowserdockwidget_p.h"
17 
18 #include <QAbstractTextDocumentLayout>
19 #include <QHeaderView>
20 #include <QTreeView>
21 #include <QMenu>
22 #include <QToolButton>
23 #include <QFileDialog>
24 #include <QPlainTextDocumentLayout>
25 #include <QSortFilterProxyModel>
26 
27 #include "qgsbrowserguimodel.h"
28 #include "qgsbrowsertreeview.h"
29 #include "qgslogger.h"
30 #include "qgsrasterlayer.h"
31 #include "qgsvectorlayer.h"
32 #include "qgsproject.h"
33 #include "qgssettings.h"
34 #include "qgsnewnamedialog.h"
35 #include "qgsbrowserproxymodel.h"
36 #include "qgsgui.h"
38 #include "qgsnative.h"
40 #include "qgsdataitemguiprovider.h"
41 #include "qgsdirectoryitem.h"
42 #include "qgslayeritem.h"
43 #include "qgsprojectitem.h"
44 
45 // browser layer properties dialog
46 #include "qgsapplication.h"
47 #include "qgsmapcanvas.h"
48 
49 #include <QDragEnterEvent>
50 #include <functional>
51 
52 QgsBrowserDockWidget::QgsBrowserDockWidget( const QString &name, QgsBrowserGuiModel *browserModel, QWidget *parent )
53  : QgsDockWidget( parent )
54  , mModel( browserModel )
55  , mPropertiesWidgetEnabled( false )
56  , mPropertiesWidgetHeight( 0 )
57 {
58  setupUi( this );
59 
60  mContents->layout()->setContentsMargins( 0, 0, 0, 0 );
61  static_cast< QVBoxLayout * >( mContents->layout() )->setSpacing( 0 );
62 
63  setWindowTitle( name );
64 
65  mBrowserView = new QgsDockBrowserTreeView( this );
66  mLayoutBrowser->addWidget( mBrowserView );
67 
68  mWidgetFilter->hide();
69  mLeFilter->setPlaceholderText( tr( "Type here to filter visible items…" ) );
70  // icons from http://www.fatcow.com/free-icons License: CC Attribution 3.0
71 
72  QMenu *menu = new QMenu( this );
73  menu->setSeparatorsCollapsible( false );
74  mBtnFilterOptions->setMenu( menu );
75  QAction *action = new QAction( tr( "Case Sensitive" ), menu );
76  action->setData( "case" );
77  action->setCheckable( true );
78  action->setChecked( false );
79  connect( action, &QAction::toggled, this, &QgsBrowserDockWidget::setCaseSensitive );
80  menu->addAction( action );
81  QActionGroup *group = new QActionGroup( menu );
82  action = new QAction( tr( "Filter Pattern Syntax" ), group );
83  action->setSeparator( true );
84  menu->addAction( action );
85  action = new QAction( tr( "Normal" ), group );
86  action->setData( QgsBrowserProxyModel::Normal );
87  action->setCheckable( true );
88  action->setChecked( true );
89  menu->addAction( action );
90  action = new QAction( tr( "Wildcard(s)" ), group );
91  action->setData( QgsBrowserProxyModel::Wildcards );
92  action->setCheckable( true );
93  menu->addAction( action );
94  action = new QAction( tr( "Regular Expression" ), group );
95  action->setData( QgsBrowserProxyModel::RegularExpression );
96  action->setCheckable( true );
97  menu->addAction( action );
98 
99  mBrowserView->setExpandsOnDoubleClick( false );
100 
101  connect( mActionRefresh, &QAction::triggered, this, &QgsBrowserDockWidget::refresh );
102  connect( mActionAddLayers, &QAction::triggered, this, &QgsBrowserDockWidget::addSelectedLayers );
103  connect( mActionCollapse, &QAction::triggered, mBrowserView, &QgsDockBrowserTreeView::collapseAll );
104  connect( mActionShowFilter, &QAction::triggered, this, &QgsBrowserDockWidget::showFilterWidget );
105  connect( mActionPropertiesWidget, &QAction::triggered, this, &QgsBrowserDockWidget::enablePropertiesWidget );
106  connect( mLeFilter, &QgsFilterLineEdit::returnPressed, this, &QgsBrowserDockWidget::setFilter );
107  connect( mLeFilter, &QgsFilterLineEdit::cleared, this, &QgsBrowserDockWidget::setFilter );
108  connect( mLeFilter, &QgsFilterLineEdit::textChanged, this, &QgsBrowserDockWidget::setFilter );
109  connect( group, &QActionGroup::triggered, this, &QgsBrowserDockWidget::setFilterSyntax );
110  connect( mBrowserView, &QgsDockBrowserTreeView::customContextMenuRequested, this, &QgsBrowserDockWidget::showContextMenu );
111  connect( mBrowserView, &QgsDockBrowserTreeView::doubleClicked, this, &QgsBrowserDockWidget::itemDoubleClicked );
112  connect( mSplitter, &QSplitter::splitterMoved, this, &QgsBrowserDockWidget::splitterMoved );
113 
114  connect( QgsGui::instance(), &QgsGui::optionsChanged, this, &QgsBrowserDockWidget::onOptionsChanged );
115 }
116 
118 {
119  QgsSettings settings;
120  settings.setValue( settingsSection() + "/propertiesWidgetEnabled", mPropertiesWidgetEnabled );
121  //settings.setValue(settingsSection() + "/propertiesWidgetHeight", mPropertiesWidget->size().height() );
122  settings.setValue( settingsSection() + "/propertiesWidgetHeight", mPropertiesWidgetHeight );
123 }
124 
125 void QgsBrowserDockWidget::showEvent( QShowEvent *e )
126 {
127  // delayed initialization of the model
128  if ( !mModel->initialized( ) )
129  {
130  mModel->initialize();
131  }
132  if ( ! mProxyModel )
133  {
134  mProxyModel = new QgsBrowserProxyModel( this );
135  mProxyModel->setBrowserModel( mModel );
136  mProxyModel->setHiddenDataItemProviderKeyFilter( mDisabledDataItemsKeys );
137  mBrowserView->setSettingsSection( objectName().toLower() ); // to distinguish 2 or more instances of the browser
138  mBrowserView->setBrowserModel( mModel );
139  mBrowserView->setModel( mProxyModel );
140  mBrowserView->setSortingEnabled( true );
141  mBrowserView->sortByColumn( 0, Qt::AscendingOrder );
142  // provide a horizontal scroll bar instead of using ellipse (...) for longer items
143  mBrowserView->setTextElideMode( Qt::ElideNone );
144  mBrowserView->header()->setSectionResizeMode( 0, QHeaderView::ResizeToContents );
145  mBrowserView->header()->setStretchLastSection( false );
146 
147  // selectionModel is created when model is set on tree
148  connect( mBrowserView->selectionModel(), &QItemSelectionModel::selectionChanged,
150 
151  // Forward the model changed signals to the widget
152  connect( mModel, &QgsBrowserModel::connectionsChanged,
154 
155 
156  // objectName used by settingsSection() is not yet set in constructor
157  QgsSettings settings;
158  mPropertiesWidgetEnabled = settings.value( settingsSection() + "/propertiesWidgetEnabled", false ).toBool();
159  mActionPropertiesWidget->setChecked( mPropertiesWidgetEnabled );
160  mPropertiesWidget->setVisible( false ); // false until item is selected
161 
162  mPropertiesWidgetHeight = settings.value( settingsSection() + "/propertiesWidgetHeight" ).toFloat();
163  QList<int> sizes = mSplitter->sizes();
164  int total = sizes.value( 0 ) + sizes.value( 1 );
165  int height = static_cast<int>( total * mPropertiesWidgetHeight );
166  sizes.clear();
167  sizes << total - height << height;
168  mSplitter->setSizes( sizes );
169  }
170 
172 }
173 
174 void QgsBrowserDockWidget::itemDoubleClicked( const QModelIndex &index )
175 {
176  QgsDataItem *item = mModel->dataItem( mProxyModel->mapToSource( index ) );
177  if ( !item )
178  return;
179 
180  QgsDataItemGuiContext context = createContext();
181 
182  const QList< QgsDataItemGuiProvider * > providers = QgsGui::instance()->dataItemGuiProviderRegistry()->providers();
183  for ( QgsDataItemGuiProvider *provider : providers )
184  {
185  if ( provider->handleDoubleClick( item, context ) )
186  return;
187  }
188 
189  // if no providers overrode the double-click handling for this item, we give the item itself a chance
190  if ( !item->handleDoubleClick() )
191  {
192  // double-click not handled by browser model, so use as default view expand behavior
193  if ( mBrowserView->isExpanded( index ) )
194  mBrowserView->collapse( index );
195  else
196  mBrowserView->expand( index );
197  }
198 }
199 
200 void QgsBrowserDockWidget::onOptionsChanged()
201 {
202  std::function< void( const QModelIndex &index ) > updateItem;
203  updateItem = [this, &updateItem]( const QModelIndex & index )
204  {
205  if ( QgsDirectoryItem *dirItem = qobject_cast< QgsDirectoryItem * >( mModel->dataItem( index ) ) )
206  {
207  dirItem->reevaluateMonitoring();
208  }
209 
210  const int rowCount = mModel->rowCount( index );
211  for ( int i = 0; i < rowCount; ++i )
212  {
213  const QModelIndex child = mModel->index( i, 0, index );
214  updateItem( child );
215  }
216  };
217 
218  for ( int i = 0; i < mModel->rowCount(); ++i )
219  {
220  updateItem( mModel->index( i, 0 ) );
221  }
222 }
223 
225 {
226  QModelIndex index = mProxyModel->mapToSource( mBrowserView->indexAt( pt ) );
227  QgsDataItem *item = mModel->dataItem( index );
228  if ( !item )
229  return;
230 
231  const QModelIndexList selection = mBrowserView->selectionModel()->selectedIndexes();
232  QList< QgsDataItem * > selectedItems;
233  selectedItems.reserve( selection.size() );
234  for ( const QModelIndex &selectedIndex : selection )
235  {
236  QgsDataItem *selectedItem = mProxyModel->dataItem( selectedIndex );
237  if ( selectedItem )
238  selectedItems << selectedItem;
239  }
240 
241  QMenu *menu = new QMenu( this );
242 
243  const QList<QMenu *> menus = item->menus( menu );
244  QList<QAction *> actions = item->actions( menu );
245 
246  if ( !menus.isEmpty() )
247  {
248  for ( QMenu *mn : menus )
249  {
250  menu->addMenu( mn );
251  }
252  }
253 
254  if ( !actions.isEmpty() )
255  {
256  if ( !menu->actions().isEmpty() )
257  menu->addSeparator();
258  // add action to the menu
259  menu->addActions( actions );
260  }
261 
262  QgsDataItemGuiContext context = createContext();
263 
264  const QList< QgsDataItemGuiProvider * > providers = QgsGui::instance()->dataItemGuiProviderRegistry()->providers();
265  for ( QgsDataItemGuiProvider *provider : providers )
266  {
267  provider->populateContextMenu( item, menu, selectedItems, context );
268  }
269 
270  if ( menu->actions().isEmpty() )
271  {
272  delete menu;
273  return;
274  }
275 
276  menu->popup( mBrowserView->mapToGlobal( pt ) );
277 }
278 
280 {
281  QModelIndex index = mProxyModel->mapToSource( mBrowserView->currentIndex() );
282  QgsDataItem *item = mModel->dataItem( index );
283  if ( !item )
284  return;
285 
286  QgsDirectoryItem *dirItem = qobject_cast<QgsDirectoryItem *>( item );
287  if ( !dirItem )
288  return;
289 
291  addFavoriteDirectory( dirItem->dirPath() );
293 }
294 
296 {
297  QString directory = QFileDialog::getExistingDirectory( this, tr( "Add directory to favorites" ) );
298  if ( !directory.isEmpty() )
299  {
301  addFavoriteDirectory( directory );
303  }
304 }
305 
306 void QgsBrowserDockWidget::addFavoriteDirectory( const QString &favDir, const QString &name )
307 {
308  mModel->addFavoriteDirectory( favDir, name );
309 }
310 
312 {
313  mMessageBar = bar;
314  mModel->setMessageBar( bar );
315 }
316 
318 {
319  return mMessageBar;
320 }
321 
322 void QgsBrowserDockWidget::setDisabledDataItemsKeys( const QStringList &filter )
323 {
324  mDisabledDataItemsKeys = filter;
325 
326  if ( !mProxyModel )
327  return;
328 
329  mProxyModel->setHiddenDataItemProviderKeyFilter( mDisabledDataItemsKeys );
330 }
331 
333 {
334  mModel->removeFavorite( mProxyModel->mapToSource( mBrowserView->currentIndex() ) );
335 }
336 
338 {
339  refreshModel( QModelIndex() );
340 }
341 
342 void QgsBrowserDockWidget::refreshModel( const QModelIndex &index )
343 {
344  if ( mModel && mProxyModel )
345  {
346  QgsDataItem *item = mModel->dataItem( index );
347  if ( item )
348  {
349  QgsDebugMsgLevel( "path = " + item->path(), 4 );
350  }
351  else
352  {
353  QgsDebugMsgLevel( QStringLiteral( "invalid item" ), 4 );
354  }
355 
356  if ( item && ( item->capabilities2() & Qgis::BrowserItemCapability::Fertile ) )
357  {
358  mModel->refresh( index );
359  }
360 
361  for ( int i = 0; i < mModel->rowCount( index ); i++ )
362  {
363  QModelIndex idx = mModel->index( i, 0, index );
364  QModelIndex proxyIdx = mProxyModel->mapFromSource( idx );
365  QgsDataItem *child = mModel->dataItem( idx );
366 
367  // Check also expanded descendants so that the whole expanded path does not get collapsed if one item is collapsed.
368  // Fast items (usually root items) are refreshed so that when collapsed, it is obvious they are if empty (no expand symbol).
369  if ( mBrowserView->isExpanded( proxyIdx ) || mBrowserView->hasExpandedDescendant( proxyIdx ) || ( child && child->capabilities2() & Qgis::BrowserItemCapability::Fast ) )
370  {
371  refreshModel( idx );
372  }
373  else
374  {
375  if ( child && ( child->capabilities2() & Qgis::BrowserItemCapability::Fertile ) )
376  {
377  child->depopulate();
378  }
379  }
380  }
381  }
382 }
383 
384 void QgsBrowserDockWidget::addLayer( QgsLayerItem *layerItem )
385 {
386  if ( !layerItem )
387  return;
388 
389  emit handleDropUriList( layerItem->mimeUris() );
390 }
391 
392 bool QgsBrowserDockWidget::addLayerAtIndex( const QModelIndex &index )
393 {
394  QgsDebugMsg( QStringLiteral( "rowCount() = %1" ).arg( mModel->rowCount( mProxyModel->mapToSource( index ) ) ) );
395  QgsDataItem *item = mModel->dataItem( mProxyModel->mapToSource( index ) );
396 
397  if ( item && item->type() == Qgis::BrowserItemType::Project )
398  {
399  QgsProjectItem *projectItem = qobject_cast<QgsProjectItem *>( item );
400  if ( projectItem )
401  {
402  QApplication::setOverrideCursor( Qt::WaitCursor );
403  emit openFile( projectItem->path(), QStringLiteral( "project" ) );
404  QApplication::restoreOverrideCursor();
405  }
406  return true;
407  }
408  else if ( item && item->type() == Qgis::BrowserItemType::Layer )
409  {
410  QgsLayerItem *layerItem = qobject_cast<QgsLayerItem *>( item );
411  if ( layerItem )
412  {
413  QApplication::setOverrideCursor( Qt::WaitCursor );
414  addLayer( layerItem );
415  QApplication::restoreOverrideCursor();
416  }
417  return true;
418  }
419  return false;
420 }
421 
423 {
424  QApplication::setOverrideCursor( Qt::WaitCursor );
425 
426  // get a sorted list of selected indexes
427  QModelIndexList list = mBrowserView->selectionModel()->selectedIndexes();
428  std::sort( list.begin(), list.end() );
429 
430  // If any of the layer items are QGIS we just open and exit the loop
431  const auto constList = list;
432  for ( const QModelIndex &index : constList )
433  {
434  QgsDataItem *item = mModel->dataItem( mProxyModel->mapToSource( index ) );
435  if ( item && item->type() == Qgis::BrowserItemType::Project )
436  {
437  QgsProjectItem *projectItem = qobject_cast<QgsProjectItem *>( item );
438  if ( projectItem )
439  emit openFile( projectItem->path(), QStringLiteral( "project" ) );
440 
441  QApplication::restoreOverrideCursor();
442  return;
443  }
444  }
445 
446  // add items in reverse order so they are in correct order in the layers dock
447  for ( int i = list.size() - 1; i >= 0; i-- )
448  {
449  QgsDataItem *item = mModel->dataItem( mProxyModel->mapToSource( list[i] ) );
450  if ( item && item->type() == Qgis::BrowserItemType::Layer )
451  {
452  QgsLayerItem *layerItem = qobject_cast<QgsLayerItem *>( item );
453  if ( layerItem )
454  addLayer( layerItem );
455  }
456  }
457 
458  QApplication::restoreOverrideCursor();
459 }
460 
462 {
463  QModelIndex index = mProxyModel->mapToSource( mBrowserView->currentIndex() );
464  QgsDataItem *item = mModel->dataItem( index );
465  if ( ! item )
466  return;
467 
468  if ( item->type() == Qgis::BrowserItemType::Directory )
469  {
470  mModel->hidePath( item );
471  }
472 }
473 
475 {
476  QModelIndex index = mProxyModel->mapToSource( mBrowserView->currentIndex() );
477  QgsDataItem *item = mModel->dataItem( index );
478  if ( ! item )
479  return;
480 
482  {
483  QgsBrowserPropertiesDialog *dialog = new QgsBrowserPropertiesDialog( settingsSection(), this );
484  dialog->setAttribute( Qt::WA_DeleteOnClose );
485  dialog->setItem( item, createContext() );
486  dialog->show();
487  }
488 }
489 
491 {
492  QModelIndex index = mProxyModel->mapToSource( mBrowserView->currentIndex() );
493  QgsDataItem *item = mModel->dataItem( index );
494  if ( ! item )
495  return;
496 
497  if ( item->type() == Qgis::BrowserItemType::Directory )
498  {
499  QgsSettings settings;
500  QStringList fastScanDirs = settings.value( QStringLiteral( "qgis/scanItemsFastScanUris" ),
501  QStringList() ).toStringList();
502  int idx = fastScanDirs.indexOf( item->path() );
503  if ( idx != -1 )
504  {
505  fastScanDirs.removeAt( idx );
506  }
507  else
508  {
509  fastScanDirs << item->path();
510  }
511  settings.setValue( QStringLiteral( "qgis/scanItemsFastScanUris" ), fastScanDirs );
512  }
513 }
514 
516 {
517  mWidgetFilter->setVisible( visible );
518  if ( ! visible )
519  {
520  mLeFilter->setText( QString() );
521  setFilter();
522  }
523  else
524  {
525  mLeFilter->setFocus();
526  }
527 }
528 
530 {
531  QString filter = mLeFilter->text();
532  if ( mProxyModel )
533  mProxyModel->setFilterString( filter );
534 }
535 
537 {
538  if ( mModel )
539  mModel->updateProjectHome();
540 }
541 
543 {
544  if ( !action || ! mProxyModel )
545  return;
546 
547  mProxyModel->setFilterSyntax( static_cast< QgsBrowserProxyModel::FilterSyntax >( action->data().toInt() ) );
548 }
549 
550 void QgsBrowserDockWidget::setCaseSensitive( bool caseSensitive )
551 {
552  if ( ! mProxyModel )
553  return;
554  mProxyModel->setFilterCaseSensitivity( caseSensitive ? Qt::CaseSensitive : Qt::CaseInsensitive );
555 }
556 
557 int QgsBrowserDockWidget::selectedItemsCount()
558 {
559  QItemSelectionModel *selectionModel = mBrowserView->selectionModel();
560  if ( selectionModel )
561  {
562  return selectionModel->selectedIndexes().size();
563  }
564  return 0;
565 }
566 
567 QgsDataItemGuiContext QgsBrowserDockWidget::createContext()
568 {
569  QgsDataItemGuiContext context;
570  context.setMessageBar( mMessageBar );
571  return context;
572 }
573 
574 void QgsBrowserDockWidget::selectionChanged( const QItemSelection &selected, const QItemSelection &deselected )
575 {
576  Q_UNUSED( selected )
577  Q_UNUSED( deselected )
578  if ( mPropertiesWidgetEnabled )
579  {
580  setPropertiesWidget();
581  }
582 }
583 
584 void QgsBrowserDockWidget::clearPropertiesWidget()
585 {
586  while ( mPropertiesLayout->count() > 0 )
587  {
588  delete mPropertiesLayout->itemAt( 0 )->widget();
589  }
590  mPropertiesWidget->setVisible( false );
591 }
592 
593 void QgsBrowserDockWidget::setPropertiesWidget()
594 {
595  clearPropertiesWidget();
596  QItemSelectionModel *selectionModel = mBrowserView->selectionModel();
597  if ( selectionModel )
598  {
599  QModelIndexList indexes = selectionModel->selectedIndexes();
600  if ( indexes.size() == 1 )
601  {
602  QModelIndex index = mProxyModel->mapToSource( indexes.value( 0 ) );
603  QgsDataItem *item = mModel->dataItem( index );
604  QgsDataItemGuiContext context = createContext();
605  QgsBrowserPropertiesWidget *propertiesWidget = QgsBrowserPropertiesWidget::createWidget( item, context, mPropertiesWidget );
606  if ( propertiesWidget )
607  {
608  propertiesWidget->setCondensedMode( true );
609  mPropertiesLayout->addWidget( propertiesWidget );
610  }
611  }
612  }
613  mPropertiesWidget->setVisible( mPropertiesLayout->count() > 0 );
614 }
615 
617 {
618  mPropertiesWidgetEnabled = enable;
619  if ( enable && selectedItemsCount() == 1 )
620  {
621  setPropertiesWidget();
622  }
623  else
624  {
625  clearPropertiesWidget();
626  }
627 }
628 
629 void QgsBrowserDockWidget::setActiveIndex( const QModelIndex &index )
630 {
631  if ( index.isValid() )
632  {
633  QModelIndex proxyIndex = mProxyModel->mapFromSource( index );
634  mBrowserView->expand( proxyIndex );
635  mBrowserView->setCurrentIndex( proxyIndex );
636  }
637 }
638 
640 {
641  QList<int> sizes = mSplitter->sizes();
642  float total = sizes.value( 0 ) + sizes.value( 1 );
643  mPropertiesWidgetHeight = total > 0 ? sizes.value( 1 ) / total : 0;
644 }
@ Fertile
Can create children. Even items without this capability may have children, but cannot create them,...
@ Fast
CreateChildren() is fast enough to be run in main thread when refreshing items, most root items (wms,...
@ Layer
Represents a map layer.
@ Project
Represents a QGIS project.
@ Directory
Represents a file directory.
void refresh()
Refresh browser view model (and view)
void enablePropertiesWidget(bool enable)
Enable/disable properties widget.
void addSelectedLayers()
Add selected layers to the project.
Q_DECL_DEPRECATED void toggleFastScan()
Toggle fast scan.
QgsBrowserDockWidget(const QString &name, QgsBrowserGuiModel *browserModel, QWidget *parent=nullptr)
Constructor for QgsBrowserDockWidget.
void connectionsChanged()
Connections changed in the browser.
Q_DECL_DEPRECATED void addFavoriteDirectory()
Add directory from file dialog to favorite.
void showContextMenu(QPoint)
Show context menu.
void showProperties()
Show the layer properties.
void setActiveIndex(const QModelIndex &index)
Sets the selection to index and expand it.
Q_DECL_DEPRECATED void removeFavorite()
Remove from favorite.
void setFilter()
Apply filter to the model.
QgsMessageBar * messageBar()
Returns the message bar associated with the dock.
void handleDropUriList(const QgsMimeDataUtils::UriList &)
Emitted when drop uri list needs to be handled.
void setCaseSensitive(bool caseSensitive)
Sets filter case sensitivity.
void showEvent(QShowEvent *event) override
Show event override.
void hideItem()
Hide current item.
void setMessageBar(QgsMessageBar *bar)
Sets a message bar to use alongside the dock widget.
Q_DECL_DEPRECATED void addFavorite()
Add current item to favorite.
void showFilterWidget(bool visible)
Show/hide filter widget.
void selectionChanged(const QItemSelection &selected, const QItemSelection &deselected)
Selection has changed.
void setFilterSyntax(QAction *)
Sets filter syntax.
void updateProjectHome()
Update project home directory.
void openFile(const QString &fileName, const QString &fileTypeHint=QString())
Emitted when a file needs to be opened.
void splitterMoved()
Splitter has been moved.
Q_DECL_DEPRECATED bool addLayerAtIndex(const QModelIndex &index)
Adds the layer corresponding to the specified model index.
void setDisabledDataItemsKeys(const QStringList &filter)
Sets the customization for data items based on item's data provider key.
A model for showing available data sources and other items in a structured tree.
void setMessageBar(QgsMessageBar *bar)
Sets message bar that will be passed in QgsDataItemGuiContext to data items.
void connectionsChanged(const QString &providerKey)
Emitted when connections for the specified providerKey have changed in the browser.
QgsDataItem * dataItem(const QModelIndex &idx) const
Returns the data item at the specified index, or nullptr if no item exists at the index.
void hidePath(QgsDataItem *item)
Hide the given path in the browser model.
void refresh(const QString &path)
Refresh item specified by path.
int rowCount(const QModelIndex &parent=QModelIndex()) const override
void initialize()
Delayed initialization, needed because the provider registry must be already populated.
void addFavoriteDirectory(const QString &directory, const QString &name=QString())
Adds a directory to the favorites group.
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const override
bool initialized() const
Returns true if the model has been initialized.
void removeFavorite(const QModelIndex &index)
Removes a favorite directory from its corresponding model index.
A QSortFilterProxyModel subclass for filtering and sorting browser model items.
FilterSyntax
Filter syntax options.
@ RegularExpression
Regular expression filtering.
@ Wildcards
Wildcard filtering.
@ Normal
Standard string filtering.
void setHiddenDataItemProviderKeyFilter(const QStringList &hiddenItemsFilter)
Sets a filter to hide data items based on QgsDataItem::providerKey() associated with the item.
void setFilterString(const QString &filter)
Sets the filter string to use when filtering items in the model.
QgsDataItem * dataItem(const QModelIndex &index) const
Returns the data item at the specified proxy index, or nullptr if no item exists at the index.
void setFilterCaseSensitivity(Qt::CaseSensitivity sensitivity)
Sets whether item filtering should be case sensitive.
void setFilterSyntax(FilterSyntax syntax)
Sets the filter syntax.
void setBrowserModel(QgsBrowserModel *model)
Sets the underlying browser model.
Encapsulates the context in which a QgsDataItem is shown within the application GUI.
void setMessageBar(QgsMessageBar *bar)
Sets the associated message bar.
QList< QgsDataItemGuiProvider * > providers() const
Returns the list of available providers.
Abstract base class for providers which affect how QgsDataItem items behave within the application GU...
Base class for all items in the model.
Definition: qgsdataitem.h:46
virtual QList< QMenu * > menus(QWidget *parent)
Returns the list of menus available for this item.
virtual bool handleDoubleClick()
Called when a user double clicks on the item.
Qgis::BrowserItemType type() const
Definition: qgsdataitem.h:316
virtual QList< QAction * > actions(QWidget *parent)
Returns the list of actions available for this item.
QString path() const
Definition: qgsdataitem.h:346
virtual Qgis::BrowserItemCapabilities capabilities2() const
Returns the capabilities for the data item.
Definition: qgsdataitem.h:295
virtual void depopulate()
Remove children recursively and set as not populated. This is used when refreshing collapsed items.
A directory: contains subdirectories and layers.
QString dirPath() const
Returns the full path to the directory the item represents.
QgsDockWidget subclass with more fine-grained control over how the widget is closed or opened.
Definition: qgsdockwidget.h:32
void showEvent(QShowEvent *event) override
void cleared()
Emitted when the widget is cleared.
void optionsChanged()
This signal is emitted whenever the application options have been changed.
static QgsGui * instance()
Returns a pointer to the singleton instance.
Definition: qgsgui.cpp:65
static QgsDataItemGuiProviderRegistry * dataItemGuiProviderRegistry()
Returns the global data item GUI provider registry, used for tracking providers which affect the brow...
Definition: qgsgui.cpp:141
Item that represents a layer that can be opened with one of the providers.
Definition: qgslayeritem.h:30
QgsMimeDataUtils::UriList mimeUris() const override
Returns mime URIs for the data item, most data providers will only return a single URI but some data ...
A bar for displaying non-blocking messages to the user.
Definition: qgsmessagebar.h:61
Data item that can be used to represent QGIS projects.
#define Q_NOWARN_DEPRECATED_POP
Definition: qgis.h:1080
#define Q_NOWARN_DEPRECATED_PUSH
Definition: qgis.h:1079
#define QgsDebugMsgLevel(str, level)
Definition: qgslogger.h:39
#define QgsDebugMsg(str)
Definition: qgslogger.h:38