28#include "moc_qgslayermetadatasearchwidget.cpp"
30using namespace Qt::StringLiterals;
41 mSourceModel =
new QgsLayerMetadataResultsModel( searchContext,
this );
43 mProxyModel->setSourceModel( mSourceModel );
44 mMetadataTableView->setModel( mProxyModel );
45 mMetadataTableView->setSortingEnabled(
true );
46 mMetadataTableView->sortByColumn( 0, Qt::SortOrder::AscendingOrder );
47 mMetadataTableView->horizontalHeader()->setSectionResizeMode( QgsLayerMetadataResultsModel::Sections::Identifier, QHeaderView::ResizeMode::Stretch );
48 mMetadataTableView->horizontalHeader()->setSectionResizeMode( QgsLayerMetadataResultsModel::Sections::Title, QHeaderView::ResizeMode::Stretch );
49 mMetadataTableView->horizontalHeader()->setSectionResizeMode( QgsLayerMetadataResultsModel::Sections::Abstract, QHeaderView::ResizeMode::Stretch );
50 mMetadataTableView->horizontalHeader()->setSectionResizeMode( QgsLayerMetadataResultsModel::Sections::DataProviderName, QHeaderView::ResizeMode::ResizeToContents );
51 mMetadataTableView->horizontalHeader()->setSectionResizeMode( QgsLayerMetadataResultsModel::Sections::GeometryType, QHeaderView::ResizeMode::ResizeToContents );
52 mMetadataTableView->setSelectionBehavior( QAbstractItemView::SelectRows );
54 mExtentFilterComboBox->addItem( QString() );
55 mExtentFilterComboBox->addItem( u
"Map Canvas Extent"_s );
56 mExtentFilterComboBox->addItem( u
"Current Project Extent"_s );
57 mExtentFilterComboBox->setCurrentIndex( 0 );
58 mExtentFilterComboBox->setSizeAdjustPolicy( QComboBox::SizeAdjustPolicy::AdjustToContents );
59 mExtentFilterComboBox->adjustSize();
61 mGeometryTypeComboBox->addItem( QString(), QVariant() );
68 mGeometryTypeComboBox->setCurrentIndex( 0 );
69 mGeometryTypeComboBox->setSizeAdjustPolicy( QComboBox::SizeAdjustPolicy::AdjustToContents );
70 mGeometryTypeComboBox->adjustSize();
72 auto updateLoadBtn = [
this] {
75 mAbortPushButton->setText( tr(
"Abort" ) );
80 mAbortPushButton->setText( tr(
"Refresh" ) );
85 connect( mSourceModel, &QgsLayerMetadataResultsModel::progressChanged, mProgressBar, &QProgressBar::setValue );
86 connect( mSourceModel, &QgsLayerMetadataResultsModel::progressChanged,
this, [
this, updateLoadBtn](
int progress ) {
90 mReloadRequired =
false;
96 connect( mAbortPushButton, &QPushButton::clicked, mSourceModel, [
this, updateLoadBtn](
bool ) {
100 mReloadRequired =
true;
105 mProgressBar->hide();
106 mSourceModel->cancel();
108 mReloadRequired =
false;
113 connect( mMetadataTableView->selectionModel(), &QItemSelectionModel::selectionChanged,
this, [
this](
const QItemSelection &,
const QItemSelection & ) {
114 emit enableButtons( mMetadataTableView->selectionModel()->hasSelection() );
118 connect( mSearchFilterLineEdit, &
QgsFilterLineEdit::cleared, mProxyModel, [
this] { mProxyModel->setFilterString( QString() ); } );
121 connect( mGeometryTypeComboBox, qOverload<int>( &QComboBox::currentIndexChanged ),
this, [
this](
int index ) {
124 mProxyModel->setFilterGeometryTypeEnabled(
false );
125 mProxyModel->setFilterMapLayerTypeEnabled(
false );
129 const QVariant geomTypeFilterValue( mGeometryTypeComboBox->currentData() );
130 if ( geomTypeFilterValue.isValid() )
132 mProxyModel->setFilterGeometryTypeEnabled(
true );
133 mProxyModel->setFilterGeometryType( geomTypeFilterValue.value<
Qgis::GeometryType>() );
134 mProxyModel->setFilterMapLayerTypeEnabled(
true );
139 mProxyModel->setFilterGeometryTypeEnabled(
false );
140 mProxyModel->setFilterMapLayerTypeEnabled(
true );
154 connect( mButtonBox, &QDialogButtonBox::helpRequested,
this, &QgsLayerMetadataSearchWidget::showHelp );
159 if ( newMapCanvas &&
mapCanvas() != newMapCanvas )
176 else if ( index == 2 )
192 mReloadRequired =
true;
198 const QModelIndexList &selectedIndexes { mMetadataTableView->selectionModel()->selectedRows() };
199 if ( !selectedIndexes.isEmpty() )
201 for (
const auto &selectedIndex : std::as_const( selectedIndexes ) )
205 QString layerName = metadataResult.
title();
206 if ( layerName.isEmpty() )
209 if ( components.contains( u
"layerName"_s ) )
211 layerName = components.value( u
"layerName"_s ).toString();
213 else if ( components.contains( u
"table"_s ) )
215 layerName = components.value( u
"table"_s ).toString();
261 mSearchFilterLineEdit->clear();
262 mExtentFilterComboBox->setCurrentIndex( 0 );
267 QgsAbstractDataSourceWidget::showEvent( event );
268 mSearchFilterLineEdit->setText( mProxyModel->filterString() );
272void QgsLayerMetadataSearchWidget::showHelp()
274 QgsHelp::openHelp( u
"managing_data_source/opening_data.html#the-layer-metadata-search-panel"_s );
277void QgsLayerMetadataSearchWidget::refreshInternal()
279 if ( mReloadRequired && isVisible() )
282 mSourceModel->reloadAsync();
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 Q_INVOKABLE 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.