26#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 = [
this] {
71 mAbortPushButton->setText( tr(
"Abort" ) );
76 mAbortPushButton->setText( tr(
"Refresh" ) );
81 connect( mSourceModel, &QgsLayerMetadataResultsModel::progressChanged, mProgressBar, &QProgressBar::setValue );
82 connect( mSourceModel, &QgsLayerMetadataResultsModel::progressChanged,
this, [
this, updateLoadBtn](
int progress ) {
86 mReloadRequired =
false;
92 connect( mAbortPushButton, &QPushButton::clicked, mSourceModel, [
this, updateLoadBtn](
bool ) {
96 mReloadRequired =
true;
101 mProgressBar->hide();
102 mSourceModel->cancel();
104 mReloadRequired =
false;
109 connect( mMetadataTableView->selectionModel(), &QItemSelectionModel::selectionChanged,
this, [
this](
const QItemSelection &,
const QItemSelection & ) {
110 emit enableButtons( mMetadataTableView->selectionModel()->hasSelection() );
114 connect( mSearchFilterLineEdit, &
QgsFilterLineEdit::cleared, mProxyModel, [
this] { mProxyModel->setFilterString( QString() ); } );
117 connect( mGeometryTypeComboBox, qOverload<int>( &QComboBox::currentIndexChanged ),
this, [
this](
int index ) {
120 mProxyModel->setFilterGeometryTypeEnabled(
false );
121 mProxyModel->setFilterMapLayerTypeEnabled(
false );
125 const QVariant geomTypeFilterValue( mGeometryTypeComboBox->currentData() );
126 if ( geomTypeFilterValue.isValid() )
128 mProxyModel->setFilterGeometryTypeEnabled(
true );
129 mProxyModel->setFilterGeometryType( geomTypeFilterValue.value<
Qgis::GeometryType>() );
130 mProxyModel->setFilterMapLayerTypeEnabled(
true );
135 mProxyModel->setFilterGeometryTypeEnabled(
false );
136 mProxyModel->setFilterMapLayerTypeEnabled(
true );
150 connect( mButtonBox, &QDialogButtonBox::helpRequested,
this, &QgsLayerMetadataSearchWidget::showHelp );
155 if ( newMapCanvas &&
mapCanvas() != newMapCanvas )
172 else if ( index == 2 )
188 mReloadRequired =
true;
194 const QModelIndexList &selectedIndexes { mMetadataTableView->selectionModel()->selectedRows() };
195 if ( !selectedIndexes.isEmpty() )
197 for (
const auto &selectedIndex : std::as_const( selectedIndexes ) )
201 QString layerName = metadataResult.
title();
202 if ( layerName.isEmpty() )
205 if ( components.contains( QStringLiteral(
"layerName" ) ) )
207 layerName = components.value( QStringLiteral(
"layerName" ) ).toString();
209 else if ( components.contains( QStringLiteral(
"table" ) ) )
211 layerName = components.value( QStringLiteral(
"table" ) ).toString();
257 mSearchFilterLineEdit->clear();
258 mExtentFilterComboBox->setCurrentIndex( 0 );
263 QgsAbstractDataSourceWidget::showEvent( event );
264 mSearchFilterLineEdit->setText( mProxyModel->filterString() );
268void QgsLayerMetadataSearchWidget::showHelp()
270 QgsHelp::openHelp( QStringLiteral(
"managing_data_source/opening_data.html#the-layer-metadata-search-panel" ) );
273void QgsLayerMetadataSearchWidget::refreshInternal()
275 if ( mReloadRequired && isVisible() )
278 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.