17#include "moc_qgslayermetadatasearchwidget.cpp"
37 mSourceModel =
new QgsLayerMetadataResultsModel( searchContext,
this );
39 mProxyModel->setSourceModel( mSourceModel );
40 mMetadataTableView->setModel( mProxyModel );
41 mMetadataTableView->setSortingEnabled(
true );
42 mMetadataTableView->sortByColumn( 0, Qt::SortOrder::AscendingOrder );
43 mMetadataTableView->horizontalHeader()->setSectionResizeMode( QgsLayerMetadataResultsModel::Sections::Identifier, QHeaderView::ResizeMode::Stretch );
44 mMetadataTableView->horizontalHeader()->setSectionResizeMode( QgsLayerMetadataResultsModel::Sections::Title, QHeaderView::ResizeMode::Stretch );
45 mMetadataTableView->horizontalHeader()->setSectionResizeMode( QgsLayerMetadataResultsModel::Sections::Abstract, QHeaderView::ResizeMode::Stretch );
46 mMetadataTableView->horizontalHeader()->setSectionResizeMode( QgsLayerMetadataResultsModel::Sections::DataProviderName, QHeaderView::ResizeMode::ResizeToContents );
47 mMetadataTableView->horizontalHeader()->setSectionResizeMode( QgsLayerMetadataResultsModel::Sections::GeometryType, QHeaderView::ResizeMode::ResizeToContents );
48 mMetadataTableView->setSelectionBehavior( QAbstractItemView::SelectRows );
50 mExtentFilterComboBox->addItem( QString( ) );
51 mExtentFilterComboBox->addItem( QStringLiteral(
"Map Canvas Extent" ) );
52 mExtentFilterComboBox->addItem( QStringLiteral(
"Current Project Extent" ) );
53 mExtentFilterComboBox->setCurrentIndex( 0 );
54 mExtentFilterComboBox->setSizeAdjustPolicy( QComboBox::SizeAdjustPolicy::AdjustToContents );
55 mExtentFilterComboBox->adjustSize();
57 mGeometryTypeComboBox->addItem( QString( ), QVariant() );
64 mGeometryTypeComboBox->setCurrentIndex( 0 );
65 mGeometryTypeComboBox->setSizeAdjustPolicy( QComboBox::SizeAdjustPolicy::AdjustToContents );
66 mGeometryTypeComboBox->adjustSize();
68 auto updateLoadBtn = [ = ]
72 mAbortPushButton->setText( tr(
"Abort" ) );
77 mAbortPushButton->setText( tr(
"Refresh" ) );
82 connect( mSourceModel, &QgsLayerMetadataResultsModel::progressChanged, mProgressBar, &QProgressBar::setValue );
83 connect( mSourceModel, &QgsLayerMetadataResultsModel::progressChanged,
this, [ = ](
int progress )
93 connect( mAbortPushButton, &QPushButton::clicked, mSourceModel, [ = ](
bool )
99 mSourceModel->reloadAsync( );
103 mProgressBar->hide();
104 mSourceModel->cancel();
110 connect( mMetadataTableView->selectionModel(), &QItemSelectionModel::selectionChanged,
this, [ = ](
const QItemSelection &,
const QItemSelection & )
112 emit enableButtons( mMetadataTableView->selectionModel()->hasSelection() );
119 connect( mGeometryTypeComboBox, qOverload<int>( &QComboBox::currentIndexChanged ),
this, [ = ](
int index )
128 const QVariant geomTypeFilterValue( mGeometryTypeComboBox->currentData() );
129 if ( geomTypeFilterValue.isValid() )
156 connect( mButtonBox, &QDialogButtonBox::helpRequested,
this, &QgsLayerMetadataSearchWidget::showHelp );
159 mSourceModel->reloadAsync();
166 if ( newMapCanvas &&
mapCanvas() != newMapCanvas )
184 else if ( index == 2 )
199 mSourceModel->reloadAsync();
204 const QModelIndexList &selectedIndexes { mMetadataTableView->selectionModel()->selectedRows() };
205 if ( ! selectedIndexes.isEmpty() )
207 for (
const auto &selectedIndex : std::as_const( selectedIndexes ) )
211 QString layerName = metadataResult.
title();
212 if ( layerName.isEmpty() )
215 if ( components.contains( QStringLiteral(
"layerName" ) ) )
217 layerName = components.value( QStringLiteral(
"layerName" ) ).toString();
219 else if ( components.contains( QStringLiteral(
"table" ) ) )
221 layerName = components.value( QStringLiteral(
"table" ) ).toString();
225 layerName = metadataResult.identifier();
229 switch ( metadataResult.layerType() )
234 emit
addRasterLayer( metadataResult.uri(), layerName, metadataResult.dataProviderName() );
236 emit
addLayer( metadataResult.layerType(), metadataResult.uri(), layerName, metadataResult.dataProviderName() );
242 emit
addVectorLayer( metadataResult.uri(), layerName, metadataResult.dataProviderName() );
244 emit
addLayer( metadataResult.layerType(), metadataResult.uri(), layerName, metadataResult.dataProviderName() );
250 emit
addMeshLayer( metadataResult.uri(), layerName, metadataResult.dataProviderName() );
252 emit
addLayer( metadataResult.layerType(), metadataResult.uri(), layerName, metadataResult.dataProviderName() );
267 mSearchFilterLineEdit->clear();
268 mExtentFilterComboBox->setCurrentIndex( 0 );
273 QgsAbstractDataSourceWidget::showEvent( event );
274 mSearchFilterLineEdit->setText( mProxyModel->
filterString( ) );
277void QgsLayerMetadataSearchWidget::showHelp()
279 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.