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() );
69 mGeometryTypeComboBox->setCurrentIndex( 0 );
70 mGeometryTypeComboBox->setSizeAdjustPolicy( QComboBox::SizeAdjustPolicy::AdjustToContents );
71 mGeometryTypeComboBox->adjustSize();
73 auto updateLoadBtn = [
this] {
76 mAbortPushButton->setText( tr(
"Abort" ) );
81 mAbortPushButton->setText( tr(
"Refresh" ) );
86 connect( mSourceModel, &QgsLayerMetadataResultsModel::progressChanged, mProgressBar, &QProgressBar::setValue );
87 connect( mSourceModel, &QgsLayerMetadataResultsModel::progressChanged,
this, [
this, updateLoadBtn](
int progress ) {
91 mReloadRequired =
false;
97 connect( mAbortPushButton, &QPushButton::clicked, mSourceModel, [
this, updateLoadBtn](
bool ) {
100 mProgressBar->show();
101 mReloadRequired =
true;
106 mProgressBar->hide();
107 mSourceModel->cancel();
109 mReloadRequired =
false;
114 connect( mMetadataTableView->selectionModel(), &QItemSelectionModel::selectionChanged,
this, [
this](
const QItemSelection &,
const QItemSelection & ) {
115 emit enableButtons( mMetadataTableView->selectionModel()->hasSelection() );
119 connect( mSearchFilterLineEdit, &
QgsFilterLineEdit::cleared, mProxyModel, [
this] { mProxyModel->setFilterString( QString() ); } );
122 connect( mGeometryTypeComboBox, qOverload<int>( &QComboBox::currentIndexChanged ),
this, [
this](
int index ) {
125 mProxyModel->setFilterGeometryTypeEnabled(
false );
126 mProxyModel->setFilterMapLayerTypeEnabled(
false );
130 const QVariant geomTypeFilterValue( mGeometryTypeComboBox->currentData() );
131 if ( geomTypeFilterValue.isValid() )
133 mProxyModel->setFilterGeometryTypeEnabled(
true );
134 mProxyModel->setFilterGeometryType( geomTypeFilterValue.value<
Qgis::GeometryType>() );
135 mProxyModel->setFilterMapLayerTypeEnabled(
true );
140 mProxyModel->setFilterGeometryTypeEnabled(
false );
141 mProxyModel->setFilterMapLayerTypeEnabled(
true );
151 connect( mButtonBox, &QDialogButtonBox::helpRequested,
this, &QgsLayerMetadataSearchWidget::showHelp );
156 if ( newMapCanvas &&
mapCanvas() != newMapCanvas )
171 else if ( index == 2 )
187 mReloadRequired =
true;
193 const QModelIndexList &selectedIndexes { mMetadataTableView->selectionModel()->selectedRows() };
194 if ( !selectedIndexes.isEmpty() )
196 for (
const auto &selectedIndex : std::as_const( selectedIndexes ) )
199 mSourceModel->data( mProxyModel->mapToSource( selectedIndex ),
static_cast<int>( QgsLayerMetadataResultsModel::CustomRole::Metadata ) ).value<
QgsLayerMetadataProviderResult>()
202 QString layerName = metadataResult.
title();
203 if ( layerName.isEmpty() )
206 if ( components.contains( u
"layerName"_s ) )
208 layerName = components.value( u
"layerName"_s ).toString();
210 else if ( components.contains( u
"table"_s ) )
212 layerName = components.value( u
"table"_s ).toString();
258 mSearchFilterLineEdit->clear();
259 mExtentFilterComboBox->setCurrentIndex( 0 );
264 QgsAbstractDataSourceWidget::showEvent( event );
265 mSearchFilterLineEdit->setText( mProxyModel->filterString() );
269void QgsLayerMetadataSearchWidget::showHelp()
271 QgsHelp::openHelp( u
"managing_data_source/opening_data.html#the-layer-metadata-search-panel"_s );
274void QgsLayerMetadataSearchWidget::refreshInternal()
276 if ( mReloadRequired && isVisible() )
279 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.