36 mSourceModel =
new QgsLayerMetadataResultsModel( searchContext,
this );
38 mProxyModel->setSourceModel( mSourceModel );
39 mMetadataTableView->setModel( mProxyModel );
40 mMetadataTableView->setSortingEnabled(
true );
41 mMetadataTableView->sortByColumn( 0, Qt::SortOrder::AscendingOrder );
42 mMetadataTableView->horizontalHeader()->setSectionResizeMode( QgsLayerMetadataResultsModel::Sections::Identifier, QHeaderView::ResizeMode::Stretch );
43 mMetadataTableView->horizontalHeader()->setSectionResizeMode( QgsLayerMetadataResultsModel::Sections::Title, QHeaderView::ResizeMode::Stretch );
44 mMetadataTableView->horizontalHeader()->setSectionResizeMode( QgsLayerMetadataResultsModel::Sections::Abstract, QHeaderView::ResizeMode::Stretch );
45 mMetadataTableView->horizontalHeader()->setSectionResizeMode( QgsLayerMetadataResultsModel::Sections::DataProviderName, QHeaderView::ResizeMode::ResizeToContents );
46 mMetadataTableView->horizontalHeader()->setSectionResizeMode( QgsLayerMetadataResultsModel::Sections::GeometryType, QHeaderView::ResizeMode::ResizeToContents );
47 mMetadataTableView->setSelectionBehavior( QAbstractItemView::SelectRows );
49 mExtentFilterComboBox->addItem( QString( ) );
50 mExtentFilterComboBox->addItem( QStringLiteral(
"Map Canvas Extent" ) );
51 mExtentFilterComboBox->addItem( QStringLiteral(
"Current Project Extent" ) );
52 mExtentFilterComboBox->setCurrentIndex( 0 );
53 mExtentFilterComboBox->setSizeAdjustPolicy( QComboBox::SizeAdjustPolicy::AdjustToContents );
54 mExtentFilterComboBox->adjustSize();
56 mGeometryTypeComboBox->addItem( QString( ), QVariant() );
63 mGeometryTypeComboBox->setCurrentIndex( 0 );
64 mGeometryTypeComboBox->setSizeAdjustPolicy( QComboBox::SizeAdjustPolicy::AdjustToContents );
65 mGeometryTypeComboBox->adjustSize();
67 auto updateLoadBtn = [ = ]
71 mAbortPushButton->setText( tr(
"Abort" ) );
76 mAbortPushButton->setText( tr(
"Refresh" ) );
81 connect( mSourceModel, &QgsLayerMetadataResultsModel::progressChanged, mProgressBar, &QProgressBar::setValue );
82 connect( mSourceModel, &QgsLayerMetadataResultsModel::progressChanged,
this, [ = ](
int progress )
92 connect( mAbortPushButton, &QPushButton::clicked, mSourceModel, [ = ](
bool )
98 mSourceModel->reloadAsync( );
102 mProgressBar->hide();
103 mSourceModel->cancel();
109 connect( mMetadataTableView->selectionModel(), &QItemSelectionModel::selectionChanged,
this, [ = ](
const QItemSelection &,
const QItemSelection & )
111 emit enableButtons( mMetadataTableView->selectionModel()->hasSelection() );
118 connect( mGeometryTypeComboBox, qOverload<int>( &QComboBox::currentIndexChanged ),
this, [ = ](
int index )
127 const QVariant geomTypeFilterValue( mGeometryTypeComboBox->currentData() );
128 if ( geomTypeFilterValue.isValid() )
155 connect( mButtonBox, &QDialogButtonBox::helpRequested,
this, &QgsLayerMetadataSearchWidget::showHelp );
158 mSourceModel->reloadAsync();
165 if ( newMapCanvas &&
mapCanvas() != newMapCanvas )
183 else if ( index == 2 )
198 mSourceModel->reloadAsync();
203 const QModelIndexList &selectedIndexes { mMetadataTableView->selectionModel()->selectedRows() };
204 if ( ! selectedIndexes.isEmpty() )
206 for (
const auto &selectedIndex : std::as_const( selectedIndexes ) )
210 QString layerName = metadataResult.
title();
211 if ( layerName.isEmpty() )
214 if ( components.contains( QStringLiteral(
"layerName" ) ) )
216 layerName = components.value( QStringLiteral(
"layerName" ) ).toString();
218 else if ( components.contains( QStringLiteral(
"table" ) ) )
220 layerName = components.value( QStringLiteral(
"table" ) ).toString();
224 layerName = metadataResult.identifier();
228 switch ( metadataResult.layerType() )
233 emit
addRasterLayer( metadataResult.uri(), layerName, metadataResult.dataProviderName() );
235 emit
addLayer( metadataResult.layerType(), metadataResult.uri(), layerName, metadataResult.dataProviderName() );
241 emit
addVectorLayer( metadataResult.uri(), layerName, metadataResult.dataProviderName() );
243 emit
addLayer( metadataResult.layerType(), metadataResult.uri(), layerName, metadataResult.dataProviderName() );
249 emit
addMeshLayer( metadataResult.uri(), layerName, metadataResult.dataProviderName() );
251 emit
addLayer( metadataResult.layerType(), metadataResult.uri(), layerName, metadataResult.dataProviderName() );
266 mSearchFilterLineEdit->clear();
267 mExtentFilterComboBox->setCurrentIndex( 0 );
272 QgsAbstractDataSourceWidget::showEvent( event );
273 mSearchFilterLineEdit->setText( mProxyModel->
filterString( ) );
276void QgsLayerMetadataSearchWidget::showHelp()
278 QgsHelp::openHelp( QStringLiteral(
"managing_data_source/opening_data.html#the-layer-metadata-search-panel" ) );
GeometryType
The geometry types are used to group Qgis::WkbType in a coarse way.
@ Mesh
Mesh layer. Added in QGIS 3.2.
static QIcon getThemeIcon(const QString &name, const QColor &fillColor=QColor(), const QColor &strokeColor=QColor())
Helper to get a theme icon.
static Q_INVOKABLE QgsCoordinateReferenceSystem fromEpsgId(long epsg)
Creates a CRS from a given EPSG ID.
void cleared()
Emitted when the widget is cleared.
static void openHelp(const QString &key)
Opens help topic for the given help key using default system web browser.
static QIcon iconForGeometryType(Qgis::GeometryType typeGroup)
Returns the icon for a vector layer whose geometry typeGroup is provided.
Map canvas is a class for displaying all GIS data types on a canvas.
void extentsChanged()
Emitted when the extents of the map change.
QgsReferencedRectangle fullExtent() const
Returns the full extent of the project, which represents the maximal limits of the project.
void layersRemoved(const QStringList &layerIds)
Emitted after one or more layers were removed from the registry.
static QgsProject * instance()
Returns the QgsProject singleton instance.
QgsCoordinateTransformContext transformContext
const QgsProjectViewSettings * viewSettings() const
Returns the project's view settings, which contains settings and properties relating to how a QgsProj...
void layersAdded(const QList< QgsMapLayer * > &layers)
Emitted when one or more layers were added to the registry.
QVariantMap decodeUri(const QString &providerKey, const QString &uri)
Breaks a provider data source URI into its component paths (e.g.
static QgsProviderRegistry * instance(const QString &pluginPath=QString())
Means of accessing canonical single instance.
WidgetMode
Different ways a source select dialog can be used.
A rectangle specified with double values.
QgsCoordinateReferenceSystem crs() const
Returns the associated coordinate reference system, or an invalid CRS if no reference system is set.
A QgsRectangle with associated coordinate reference system.
static QString geometryDisplayString(Qgis::GeometryType type)
Returns a display string for a geometry type.
#define Q_NOWARN_DEPRECATED_POP
#define Q_NOWARN_DEPRECATED_PUSH
QgsCoordinateTransformContext transformContext
Coordinate transform context.