QGIS API Documentation 3.99.0-Master (8e76e220402)
Loading...
Searching...
No Matches
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 ***************************************************************************/
16
18#include "qgsbrowserguimodel.h"
20#include "qgsbrowserwidget.h"
21#include "qgsdirectoryitem.h"
22#include "qgslayeritem.h"
23#include "qgsprojectitem.h"
24
25#include <QFileDialog>
26#include <QString>
27#include <QVBoxLayout>
28
29#include "moc_qgsbrowserdockwidget.cpp"
30
31using namespace Qt::StringLiterals;
32
33QgsBrowserDockWidget::QgsBrowserDockWidget( const QString &name, QgsBrowserGuiModel *browserModel, QWidget *parent )
34 : QgsDockWidget( parent )
35{
36 QVBoxLayout *layout = new QVBoxLayout();
37 layout->setContentsMargins( 0, 0, 0, 0 );
38 layout->setSpacing( 0 );
39 QWidget *container = new QWidget();
40 container->setLayout( layout );
41 setWidget( container );
42
43 setWindowTitle( name );
44
45 mWidget = new QgsBrowserWidget( browserModel );
46 layout->addWidget( mWidget );
47
51}
52
54
59
61{
62 mWidget->showContextMenu( pt );
63}
64
66{
67 const QModelIndex index = mWidget->mProxyModel->mapToSource( mWidget->mBrowserView->currentIndex() );
68 QgsDataItem *item = mWidget->mModel->dataItem( index );
69 if ( !item )
70 return;
71
72 QgsDirectoryItem *dirItem = qobject_cast<QgsDirectoryItem *>( item );
73 if ( !dirItem )
74 return;
75
77 addFavoriteDirectory( dirItem->dirPath() );
79}
80
82{
83 const QString directory = QFileDialog::getExistingDirectory( this, tr( "Add directory to favorites" ) );
84 if ( !directory.isEmpty() )
85 {
87 addFavoriteDirectory( directory );
89 }
90}
91
92void QgsBrowserDockWidget::addFavoriteDirectory( const QString &favDir, const QString &name )
93{
94 mWidget->mModel->addFavoriteDirectory( favDir, name );
95}
96
98{
99 mWidget->setMessageBar( bar );
100}
101
103{
104 return mWidget->messageBar();
105}
106
108{
109 mWidget->setMapCanvas( canvas );
110}
111
113{
114 return mWidget->mapCanvas();
115}
116
117void QgsBrowserDockWidget::setDisabledDataItemsKeys( const QStringList &filter )
118{
119 mWidget->setDisabledDataItemsKeys( filter );
120}
121
123{
124 mWidget->mModel->removeFavorite( mWidget->mProxyModel->mapToSource( mWidget->mBrowserView->currentIndex() ) );
125}
126
128{
129 mWidget->refreshModel( QModelIndex() );
130}
131
132bool QgsBrowserDockWidget::addLayerAtIndex( const QModelIndex &index )
133{
134 QgsDebugMsgLevel( u"rowCount() = %1"_s.arg( mWidget->mModel->rowCount( mWidget->mProxyModel->mapToSource( index ) ) ), 2 );
135 QgsDataItem *item = mWidget->mModel->dataItem( mWidget->mProxyModel->mapToSource( index ) );
136
137 if ( item && item->type() == Qgis::BrowserItemType::Project )
138 {
139 QgsProjectItem *projectItem = qobject_cast<QgsProjectItem *>( item );
140 if ( projectItem )
141 {
142 QApplication::setOverrideCursor( Qt::WaitCursor );
143 emit openFile( projectItem->path(), u"project"_s );
144 QApplication::restoreOverrideCursor();
145 }
146 return true;
147 }
148 else if ( item && item->type() == Qgis::BrowserItemType::Layer )
149 {
150 QgsLayerItem *layerItem = qobject_cast<QgsLayerItem *>( item );
151 if ( layerItem )
152 {
153 QApplication::setOverrideCursor( Qt::WaitCursor );
154 mWidget->addLayer( layerItem );
155 QApplication::restoreOverrideCursor();
156 }
157 return true;
158 }
159 return false;
160}
161
163{
164 mWidget->addSelectedLayers();
165}
166
168{
169 mWidget->hideItem();
170}
171
173{
174 mWidget->showProperties();
175}
176
178{
179 const QModelIndex index = mWidget->mProxyModel->mapToSource( mWidget->mBrowserView->currentIndex() );
180 QgsDataItem *item = mWidget->mModel->dataItem( index );
181 if ( !item )
182 return;
183
184 if ( item->type() == Qgis::BrowserItemType::Directory )
185 {
186 QgsSettings settings;
187 QStringList fastScanDirs = settings.value( u"qgis/scanItemsFastScanUris"_s, QStringList() ).toStringList();
188 const int idx = fastScanDirs.indexOf( item->path() );
189 if ( idx != -1 )
190 {
191 fastScanDirs.removeAt( idx );
192 }
193 else
194 {
195 fastScanDirs << item->path();
196 }
197 settings.setValue( u"qgis/scanItemsFastScanUris"_s, fastScanDirs );
198 }
199}
200
202{
203 mWidget->showFilterWidget( visible );
204}
205
207{
208 mWidget->setFilter();
209}
210
212{
213 mWidget->updateProjectHome();
214}
215
217{
218 mWidget->setFilterSyntax( action );
219}
220
222{
223 mWidget->setCaseSensitive( caseSensitive );
224}
225
226void QgsBrowserDockWidget::selectionChanged( const QItemSelection &selected, const QItemSelection &deselected )
227{
228 mWidget->selectionChanged( selected, deselected );
229}
230
232{
233 mWidget->enablePropertiesWidget( enable );
234}
235
236void QgsBrowserDockWidget::setActiveIndex( const QModelIndex &index )
237{
238 mWidget->setActiveIndex( index );
239}
240
@ Layer
Represents a map layer.
Definition qgis.h:941
@ Project
Represents a QGIS project.
Definition qgis.h:944
@ Directory
Represents a file directory.
Definition qgis.h:940
void refresh()
Refresh the browser model and view.
Q_DECL_DEPRECATED void enablePropertiesWidget(bool enable)
Enable/disable properties widget.
Q_DECL_DEPRECATED void addSelectedLayers()
Add selected layers to the project.
Q_DECL_DEPRECATED void toggleFastScan()
Toggle fast scan.
QgsMapCanvas * mapCanvas()
Returns the map canvas associated with the dock.
~QgsBrowserDockWidget() override
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.
Q_DECL_DEPRECATED void showContextMenu(QPoint)
Show context menu.
Q_DECL_DEPRECATED void showProperties()
Show the layer properties.
Q_DECL_DEPRECATED void setActiveIndex(const QModelIndex &index)
Sets the selection to index and expand it.
void setMapCanvas(QgsMapCanvas *canvas)
Sets a map canvas to use alongside the dock.
Q_DECL_DEPRECATED void removeFavorite()
Remove from favorite.
Q_DECL_DEPRECATED void setFilter()
Apply filter to the model.
QgsBrowserWidget * browserWidget()
Returns a pointer to the QgsBrowserWidget used by the dock widget.
QgsMessageBar * messageBar()
Returns the message bar associated with the dock.
Q_DECL_DEPRECATED void setCaseSensitive(bool caseSensitive)
Sets filter case sensitivity.
void handleDropUriList(const QgsMimeDataUtils::UriList &uris)
Emitted when drop uri list needs to be handled.
Q_DECL_DEPRECATED 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.
Q_DECL_DEPRECATED void showFilterWidget(bool visible)
Show/hide filter widget.
Q_DECL_DEPRECATED void selectionChanged(const QItemSelection &selected, const QItemSelection &deselected)
Selection has changed.
Q_DECL_DEPRECATED void setFilterSyntax(QAction *)
Sets filter syntax.
Q_DECL_DEPRECATED void updateProjectHome()
Update project home directory.
void openFile(const QString &fileName, const QString &fileTypeHint=QString())
Emitted when a file needs to be opened.
Q_DECL_DEPRECATED 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.
A widget showing a browser tree view along with toolbar and toggleable properties pane.
void connectionsChanged()
Connections changed in the browser.
void handleDropUriList(const QgsMimeDataUtils::UriList &)
Emitted when drop uri list needs to be handled.
void openFile(const QString &fileName, const QString &fileTypeHint=QString())
Emitted when a file needs to be opened.
Base class for all items in the model.
Definition qgsdataitem.h:50
Qgis::BrowserItemType type() const
QString path() const
A browser item for directories: contains subdirectories and layers.
QString dirPath() const
Returns the full path to the directory the item represents.
QgsDockWidget(QWidget *parent=nullptr, Qt::WindowFlags flags=Qt::WindowFlags())
Constructor for QgsDockWidget.
A browser item that represents a layer that can be opened with one of the providers.
Map canvas is a class for displaying all GIS data types on a canvas.
A bar for displaying non-blocking messages to the user.
Data item that can be used to represent QGIS projects.
Stores settings for use within QGIS.
Definition qgssettings.h:68
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), Section section=NoSection) const
Returns the value for setting key.
void setValue(const QString &key, const QVariant &value, QgsSettings::Section section=QgsSettings::NoSection)
Sets the value of setting key to value.
#define Q_NOWARN_DEPRECATED_POP
Definition qgis.h:7486
#define Q_NOWARN_DEPRECATED_PUSH
Definition qgis.h:7485
#define QgsDebugMsgLevel(str, level)
Definition qgslogger.h:63