17#include "moc_qgslayermetadataresultsmodel.cpp"
27QgsLayerMetadataResultsModel::QgsLayerMetadataResultsModel(
const QgsMetadataSearchContext &searchContext, QObject *parent )
28 : QAbstractTableModel( parent )
29 , mSearchContext( searchContext )
31 qRegisterMetaType<QgsLayerMetadataSearchResults>(
"QgsLayerMetadataSearchResults" );
32 qRegisterMetaType<QgsLayerMetadataProviderResult>(
"QgsLayerMetadataProviderResult" );
35QgsLayerMetadataResultsModel::~QgsLayerMetadataResultsModel()
40int QgsLayerMetadataResultsModel::rowCount(
const QModelIndex &parent )
const
42 return parent.isValid() ? 0 : mResult.metadata().count();
45int QgsLayerMetadataResultsModel::columnCount(
const QModelIndex &parent )
const
47 return parent.isValid() ? 0 : 5;
50QVariant QgsLayerMetadataResultsModel::data(
const QModelIndex &index,
int role )
const
52 if ( index.isValid() && index.row() < mResult.metadata().count() )
56 case Qt::ItemDataRole::DisplayRole:
58 switch ( index.column() )
60 case Sections::Identifier:
61 return mResult.metadata().at( index.row() ).identifier();
63 return mResult.metadata().at( index.row() ).title();
64 case Sections::Abstract:
65 return mResult.metadata().at( index.row() ).abstract();
66 case Sections::DataProviderName:
68 const QString providerName { mResult.metadata().at( index.row() ).dataProviderName() };
72 case Sections::GeometryType:
74 const QList<QgsLayerMetadataProviderResult> metadata = mResult.metadata();
77 return tr(
"Raster" );
85 case Qt::ItemDataRole::ToolTipRole:
88 return tr( R
"HTML(<html><body><!-- metadata headers ---><h3>Identification</h3>%1</body></html>)HTML" )
90 formatter.identificationSectionHtml()
94 case Qt::ItemDataRole::DecorationRole:
96 if ( index.column() == 0 )
98 const QList<QgsLayerMetadataProviderResult> metadata = mResult.metadata();
106 case static_cast<int>( CustomRole::Metadata ):
108 return QVariant::fromValue( mResult.metadata().at( index.row() ) );
118QVariant QgsLayerMetadataResultsModel::headerData(
int section, Qt::Orientation orientation,
int role )
const
120 if ( orientation == Qt::Orientation::Horizontal && section < columnCount( createIndex( -1, -1 ) ) )
122 if ( role == Qt::ItemDataRole::DisplayRole )
126 case Sections::Identifier:
127 return tr(
"Identifier" );
128 case Sections::Title:
129 return tr(
"Title" );
130 case Sections::Abstract:
131 return tr(
"Abstract" );
132 case Sections::DataProviderName:
133 return tr(
"Provider" );
134 case Sections::GeometryType:
135 return tr(
"Layer Type" );
140 return QAbstractTableModel::headerData( section, orientation, role );
143void QgsLayerMetadataResultsModel::reload()
152 const QList<QgsLayerMetadataProviderResult> results { mdProvider->search( mSearchContext ).metadata() };
155 mResult.addMetadata( metadata );
161void QgsLayerMetadataResultsModel::reloadAsync()
168 mFeedback->setProgress( 0 );
172 std::unique_ptr<QgsMetadataResultsFetcher> fetcher = std::make_unique<QgsMetadataResultsFetcher>( mdProvider, mSearchContext, mFeedback.get() );
173 std::unique_ptr<QThread> thread = std::make_unique<QThread>();
174 fetcher->moveToThread( thread.get() );
177 resultsReady( results );
179 connect( thread.get(), &QThread::started, fetcher.get(), &QgsMetadataResultsFetcher::fetchMetadata );
180 mWorkerThreads.push_back( std::move( thread ) );
181 mWorkers.push_back( std::move( fetcher ) );
182 mWorkerThreads.back()->start();
189 beginInsertRows( QModelIndex(), mResult.metadata().count(), mResult.metadata().count() + results.
metadata().count() - 1 );
190 const QList<QgsLayerMetadataProviderResult> metadata { results.
metadata() };
193 mResult.addMetadata( result );
198void QgsLayerMetadataResultsModel::cancel()
205 for (
const auto &workerThread : std::as_const( mWorkerThreads ) )
207 workerThread->quit();
208 workerThread->wait();
212 mWorkerThreads.clear();
214 mFeedback = std::make_unique<QgsFeedback>();
222 : mLayerMetadataProvider( metadataProvider )
223 , mSearchContext( searchContext )
224 , mFeedback( feedback )
228void QgsMetadataResultsFetcher::fetchMetadata()
230 emit resultsReady( mLayerMetadataProvider->search( mSearchContext, QString(),
QgsRectangle(), mFeedback ) );
static QgsLayerMetadataProviderRegistry * layerMetadataProviderRegistry()
Returns registry of available layer metadata provider implementations.
static QgsApplication * instance()
Returns the singleton instance of the QgsApplication.
static QIcon getThemeIcon(const QString &name, const QColor &fillColor=QColor(), const QColor &strokeColor=QColor())
Helper to get a theme icon.
Base class for feedback objects to be used for cancellation of something running in a worker thread.
void progressChanged(double progress)
Emitted when the feedback object reports a progress change.
static QIcon iconForGeometryType(Qgis::GeometryType typeGroup)
Returns the icon for a vector layer whose geometry typeGroup is provided.
static QgsProviderRegistry * instance(const QString &pluginPath=QString())
Means of accessing canonical single instance.
QgsProviderMetadata * providerMetadata(const QString &providerKey) const
Returns metadata of the provider or nullptr if not found.
A rectangle specified with double values.
Handles storage of information regarding WKB types and their properties.
static QString geometryDisplayString(Qgis::GeometryType type)
Returns a display string for a geometry type.