QGIS API Documentation 3.41.0-Master (cea29feecf2)
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#include "moc_qgsbrowserdockwidget.cpp"
18#include "qgsbrowserwidget.h"
20#include "qgsbrowserguimodel.h"
21#include "qgsdirectoryitem.h"
22#include "qgsprojectitem.h"
23#include "qgslayeritem.h"
24
25#include <QVBoxLayout>
26#include <QFileDialog>
27
28QgsBrowserDockWidget::QgsBrowserDockWidget( const QString &name, QgsBrowserGuiModel *browserModel, QWidget *parent )
29 : QgsDockWidget( parent )
30{
31 QVBoxLayout *layout = new QVBoxLayout();
32 layout->setContentsMargins( 0, 0, 0, 0 );
33 layout->setSpacing( 0 );
34 QWidget *container = new QWidget();
35 container->setLayout( layout );
36 setWidget( container );
37
38 setWindowTitle( name );
39
40 mWidget = new QgsBrowserWidget( browserModel );
41 layout->addWidget( mWidget );
42
46}
47
49
54
56{
57 mWidget->showContextMenu( pt );
58}
59
61{
62 const QModelIndex index = mWidget->mProxyModel->mapToSource( mWidget->mBrowserView->currentIndex() );
63 QgsDataItem *item = mWidget->mModel->dataItem( index );
64 if ( !item )
65 return;
66
67 QgsDirectoryItem *dirItem = qobject_cast<QgsDirectoryItem *>( item );
68 if ( !dirItem )
69 return;
70
72 addFavoriteDirectory( dirItem->dirPath() );
74}
75
77{
78 const QString directory = QFileDialog::getExistingDirectory( this, tr( "Add directory to favorites" ) );
79 if ( !directory.isEmpty() )
80 {
82 addFavoriteDirectory( directory );
84 }
85}
86
87void QgsBrowserDockWidget::addFavoriteDirectory( const QString &favDir, const QString &name )
88{
89 mWidget->mModel->addFavoriteDirectory( favDir, name );
90}
91
93{
94 mWidget->setMessageBar( bar );
95}
96
101
102void QgsBrowserDockWidget::setDisabledDataItemsKeys( const QStringList &filter )
103{
104 mWidget->setDisabledDataItemsKeys( filter );
105}
106
108{
109 mWidget->mModel->removeFavorite( mWidget->mProxyModel->mapToSource( mWidget->mBrowserView->currentIndex() ) );
110}
111
113{
114 mWidget->refreshModel( QModelIndex() );
115}
116
117bool QgsBrowserDockWidget::addLayerAtIndex( const QModelIndex &index )
118{
119 QgsDebugMsgLevel( QStringLiteral( "rowCount() = %1" ).arg( mWidget->mModel->rowCount( mWidget->mProxyModel->mapToSource( index ) ) ), 2 );
120 QgsDataItem *item = mWidget->mModel->dataItem( mWidget->mProxyModel->mapToSource( index ) );
121
122 if ( item && item->type() == Qgis::BrowserItemType::Project )
123 {
124 QgsProjectItem *projectItem = qobject_cast<QgsProjectItem *>( item );
125 if ( projectItem )
126 {
127 QApplication::setOverrideCursor( Qt::WaitCursor );
128 emit openFile( projectItem->path(), QStringLiteral( "project" ) );
129 QApplication::restoreOverrideCursor();
130 }
131 return true;
132 }
133 else if ( item && item->type() == Qgis::BrowserItemType::Layer )
134 {
135 QgsLayerItem *layerItem = qobject_cast<QgsLayerItem *>( item );
136 if ( layerItem )
137 {
138 QApplication::setOverrideCursor( Qt::WaitCursor );
139 mWidget->addLayer( layerItem );
140 QApplication::restoreOverrideCursor();
141 }
142 return true;
143 }
144 return false;
145}
146
148{
149 mWidget->addSelectedLayers();
150}
151
153{
154 mWidget->hideItem();
155}
156
158{
159 mWidget->showProperties();
160}
161
163{
164 const QModelIndex index = mWidget->mProxyModel->mapToSource( mWidget->mBrowserView->currentIndex() );
165 QgsDataItem *item = mWidget->mModel->dataItem( index );
166 if ( !item )
167 return;
168
169 if ( item->type() == Qgis::BrowserItemType::Directory )
170 {
171 QgsSettings settings;
172 QStringList fastScanDirs = settings.value( QStringLiteral( "qgis/scanItemsFastScanUris" ), QStringList() ).toStringList();
173 const int idx = fastScanDirs.indexOf( item->path() );
174 if ( idx != -1 )
175 {
176 fastScanDirs.removeAt( idx );
177 }
178 else
179 {
180 fastScanDirs << item->path();
181 }
182 settings.setValue( QStringLiteral( "qgis/scanItemsFastScanUris" ), fastScanDirs );
183 }
184}
185
187{
188 mWidget->showFilterWidget( visible );
189}
190
192{
193 mWidget->setFilter();
194}
195
200
202{
203 mWidget->setFilterSyntax( action );
204}
205
207{
208 mWidget->setCaseSensitive( caseSensitive );
209}
210
211void QgsBrowserDockWidget::selectionChanged( const QItemSelection &selected, const QItemSelection &deselected )
212{
213 mWidget->selectionChanged( selected, deselected );
214}
215
217{
218 mWidget->enablePropertiesWidget( enable );
219}
220
221void QgsBrowserDockWidget::setActiveIndex( const QModelIndex &index )
222{
223 mWidget->setActiveIndex( index );
224}
225
@ Layer
Represents a map layer.
@ Project
Represents a QGIS project.
@ Directory
Represents a file directory.
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.
~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.
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.
QgsDataItem * dataItem(const QModelIndex &idx) const
Returns the data item at the specified index, or nullptr if no item exists at the index.
int rowCount(const QModelIndex &parent=QModelIndex()) const override
void addFavoriteDirectory(const QString &directory, const QString &name=QString())
Adds a directory to the favorites group.
void removeFavorite(const QModelIndex &index)
Removes a favorite directory from its corresponding model index.
A widget showing a browser tree view along with toolbar and toggleable properties pane.
void updateProjectHome()
Update project home directory.
void setActiveIndex(const QModelIndex &index)
Sets the selection to index and expands it.
QgsMessageBar * messageBar()
Returns the message bar associated with the widget.
void connectionsChanged()
Connections changed in the browser.
void handleDropUriList(const QgsMimeDataUtils::UriList &)
Emitted when drop uri list needs to be handled.
void setMessageBar(QgsMessageBar *bar)
Sets a message bar to use alongside the widget.
void openFile(const QString &fileName, const QString &fileTypeHint=QString())
Emitted when a file needs to be opened.
void setDisabledDataItemsKeys(const QStringList &filter)
Sets the customization for data items based on item's data provider key.
Base class for all items in the model.
Definition qgsdataitem.h:46
Qgis::BrowserItemType type() const
QString path() const
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.
Item that represents a layer that can be opened with one of the providers.
A bar for displaying non-blocking messages to the user.
Data item that can be used to represent QGIS projects.
This class is a composition of two QSettings instances:
Definition qgssettings.h:64
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:6601
#define Q_NOWARN_DEPRECATED_PUSH
Definition qgis.h:6600
#define QgsDebugMsgLevel(str, level)
Definition qgslogger.h:39