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 ) )
208 const QgsLayerMetadataProviderResult metadataResult { mSourceModel->data( mProxyModel->mapToSource( selectedIndex ), QgsLayerMetadataResultsModel::Roles::Metadata ).value<QgsLayerMetadataProviderResult>() };
209 switch ( metadataResult.layerType() )
214 emit
addRasterLayer( metadataResult.uri(), metadataResult.identifier(), metadataResult.dataProviderName() );
216 emit
addLayer( metadataResult.layerType(), metadataResult.uri(), metadataResult.identifier(), metadataResult.dataProviderName() );
222 emit
addVectorLayer( metadataResult.uri(), metadataResult.identifier(), metadataResult.dataProviderName() );
224 emit
addLayer( metadataResult.layerType(), metadataResult.uri(), metadataResult.identifier(), metadataResult.dataProviderName() );
230 emit
addMeshLayer( metadataResult.uri(), metadataResult.identifier(), metadataResult.dataProviderName() );
232 emit
addLayer( metadataResult.layerType(), metadataResult.uri(), metadataResult.identifier(), metadataResult.dataProviderName() );
247 mSearchFilterLineEdit->clear();
248 mExtentFilterComboBox->setCurrentIndex( 0 );
253 QgsAbstractDataSourceWidget::showEvent( event );
254 mSearchFilterLineEdit->setText( mProxyModel->
filterString( ) );
257void QgsLayerMetadataSearchWidget::showHelp()
259 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.
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.