QGIS API Documentation 3.99.0-Master (2fe06baccd8)
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 <QVBoxLayout>
27
28#include "moc_qgsbrowserdockwidget.cpp"
29
30QgsBrowserDockWidget::QgsBrowserDockWidget( const QString &name, QgsBrowserGuiModel *browserModel, QWidget *parent )
31 : QgsDockWidget( parent )
32{
33 QVBoxLayout *layout = new QVBoxLayout();
34 layout->setContentsMargins( 0, 0, 0, 0 );
35 layout->setSpacing( 0 );
36 QWidget *container = new QWidget();
37 container->setLayout( layout );
38 setWidget( container );
39
40 setWindowTitle( name );
41
42 mWidget = new QgsBrowserWidget( browserModel );
43 layout->addWidget( mWidget );
44
48}
49
51
56
58{
59 mWidget->showContextMenu( pt );
60}
61
63{
64 const QModelIndex index = mWidget->mProxyModel->mapToSource( mWidget->mBrowserView->currentIndex() );
65 QgsDataItem *item = mWidget->mModel->dataItem( index );
66 if ( !item )
67 return;
68
69 QgsDirectoryItem *dirItem = qobject_cast<QgsDirectoryItem *>( item );
70 if ( !dirItem )
71 return;
72
74 addFavoriteDirectory( dirItem->dirPath() );
76}
77
79{
80 const QString directory = QFileDialog::getExistingDirectory( this, tr( "Add directory to favorites" ) );
81 if ( !directory.isEmpty() )
82 {
84 addFavoriteDirectory( directory );
86 }
87}
88
89void QgsBrowserDockWidget::addFavoriteDirectory( const QString &favDir, const QString &name )
90{
91 mWidget->mModel->addFavoriteDirectory( favDir, name );
92}
93
95{
96 mWidget->setMessageBar( bar );
97}
98
100{
101 return mWidget->messageBar();
102}
103
105{
106 mWidget->setMapCanvas( canvas );
107}
108
110{
111 return mWidget->mapCanvas();
112}
113
114void QgsBrowserDockWidget::setDisabledDataItemsKeys( const QStringList &filter )
115{
116 mWidget->setDisabledDataItemsKeys( filter );
117}
118
120{
121 mWidget->mModel->removeFavorite( mWidget->mProxyModel->mapToSource( mWidget->mBrowserView->currentIndex() ) );
122}
123
125{
126 mWidget->refreshModel( QModelIndex() );
127}
128
129bool QgsBrowserDockWidget::addLayerAtIndex( const QModelIndex &index )
130{
131 QgsDebugMsgLevel( QStringLiteral( "rowCount() = %1" ).arg( mWidget->mModel->rowCount( mWidget->mProxyModel->mapToSource( index ) ) ), 2 );
132 QgsDataItem *item = mWidget->mModel->dataItem( mWidget->mProxyModel->mapToSource( index ) );
133
134 if ( item && item->type() == Qgis::BrowserItemType::Project )
135 {
136 QgsProjectItem *projectItem = qobject_cast<QgsProjectItem *>( item );
137 if ( projectItem )
138 {
139 QApplication::setOverrideCursor( Qt::WaitCursor );
140 emit openFile( projectItem->path(), QStringLiteral( "project" ) );
141 QApplication::restoreOverrideCursor();
142 }
143 return true;
144 }
145 else if ( item && item->type() == Qgis::BrowserItemType::Layer )
146 {
147 QgsLayerItem *layerItem = qobject_cast<QgsLayerItem *>( item );
148 if ( layerItem )
149 {
150 QApplication::setOverrideCursor( Qt::WaitCursor );
151 mWidget->addLayer( layerItem );
152 QApplication::restoreOverrideCursor();
153 }
154 return true;
155 }
156 return false;
157}
158
160{
161 mWidget->addSelectedLayers();
162}
163
165{
166 mWidget->hideItem();
167}
168
170{
171 mWidget->showProperties();
172}
173
175{
176 const QModelIndex index = mWidget->mProxyModel->mapToSource( mWidget->mBrowserView->currentIndex() );
177 QgsDataItem *item = mWidget->mModel->dataItem( index );
178 if ( !item )
179 return;
180
181 if ( item->type() == Qgis::BrowserItemType::Directory )
182 {
183 QgsSettings settings;
184 QStringList fastScanDirs = settings.value( QStringLiteral( "qgis/scanItemsFastScanUris" ), QStringList() ).toStringList();
185 const int idx = fastScanDirs.indexOf( item->path() );
186 if ( idx != -1 )
187 {
188 fastScanDirs.removeAt( idx );
189 }
190 else
191 {
192 fastScanDirs << item->path();
193 }
194 settings.setValue( QStringLiteral( "qgis/scanItemsFastScanUris" ), fastScanDirs );
195 }
196}
197
199{
200 mWidget->showFilterWidget( visible );
201}
202
204{
205 mWidget->setFilter();
206}
207
209{
210 mWidget->updateProjectHome();
211}
212
214{
215 mWidget->setFilterSyntax( action );
216}
217
219{
220 mWidget->setCaseSensitive( caseSensitive );
221}
222
223void QgsBrowserDockWidget::selectionChanged( const QItemSelection &selected, const QItemSelection &deselected )
224{
225 mWidget->selectionChanged( selected, deselected );
226}
227
229{
230 mWidget->enablePropertiesWidget( enable );
231}
232
233void QgsBrowserDockWidget::setActiveIndex( const QModelIndex &index )
234{
235 mWidget->setActiveIndex( index );
236}
237
@ Layer
Represents a map layer.
Definition qgis.h:922
@ Project
Represents a QGIS project.
Definition qgis.h:925
@ Directory
Represents a file directory.
Definition qgis.h:921
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:47
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:65
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:7170
#define Q_NOWARN_DEPRECATED_PUSH
Definition qgis.h:7169
#define QgsDebugMsgLevel(str, level)
Definition qgslogger.h:61