From a758dfd355d4f9e22d6a1cda6f499e40fab2c62c Mon Sep 17 00:00:00 2001 From: uclaros Date: Tue, 8 Oct 2024 23:25:29 +0300 Subject: [PATCH] Removed isValid() method and expanded missing docstrings --- src/core/stac/qgsstaccatalog.cpp | 4 ---- src/core/stac/qgsstaccatalog.h | 4 ++-- src/core/stac/qgsstaccollection.cpp | 4 ---- src/core/stac/qgsstaccollection.h | 4 ++-- src/core/stac/qgsstaccontroller.cpp | 6 ++++++ src/core/stac/qgsstaccontroller.h | 28 ++++++++++++++++++++++++- src/core/stac/qgsstacdataitems.cpp | 9 +++----- src/core/stac/qgsstacitem.cpp | 4 ---- src/core/stac/qgsstacitem.h | 4 ++-- src/core/stac/qgsstacitemcollection.cpp | 8 +------ src/core/stac/qgsstacitemcollection.h | 8 ++----- src/core/stac/qgsstacobject.cpp | 5 ----- src/core/stac/qgsstacobject.h | 6 +----- tests/src/core/testqgsstac.cpp | 3 --- 14 files changed, 46 insertions(+), 51 deletions(-) diff --git a/src/core/stac/qgsstaccatalog.cpp b/src/core/stac/qgsstaccatalog.cpp index c8cd6305913c..2d2360ef79c0 100644 --- a/src/core/stac/qgsstaccatalog.cpp +++ b/src/core/stac/qgsstaccatalog.cpp @@ -22,7 +22,6 @@ QgsStacCatalog::QgsStacCatalog( const QString &id, : QgsStacObject( id, version, links ) , mDescription( description ) { - mValid = true; } QgsStacObject::Type QgsStacCatalog::type() const @@ -32,9 +31,6 @@ QgsStacObject::Type QgsStacCatalog::type() const QString QgsStacCatalog::toHtml() const { - if ( !mValid ) - return QString(); - QString html = QStringLiteral( "\n\n" ); html += QStringLiteral( "

%1

\n
\n" ).arg( QStringLiteral( "Catalog" ) ); diff --git a/src/core/stac/qgsstaccatalog.h b/src/core/stac/qgsstaccatalog.h index ed8fa4395aa3..48703cac0aeb 100644 --- a/src/core/stac/qgsstaccatalog.h +++ b/src/core/stac/qgsstaccatalog.h @@ -35,8 +35,8 @@ class CORE_EXPORT QgsStacCatalog : public QgsStacObject { public: - //! Default constructor creates an invalid catalog - QgsStacCatalog() = default; + //! Default constructor deleted, use the variant with required parameters + QgsStacCatalog() = delete; /** * Constructs a valid QgsStacCatalog diff --git a/src/core/stac/qgsstaccollection.cpp b/src/core/stac/qgsstaccollection.cpp index 21336ff4a513..c8af651c109b 100644 --- a/src/core/stac/qgsstaccollection.cpp +++ b/src/core/stac/qgsstaccollection.cpp @@ -27,7 +27,6 @@ QgsStacCollection::QgsStacCollection( const QString &id, , mLicense( license ) , mExtent( extent ) { - mValid = true; } QgsStacObject::Type QgsStacCollection::type() const @@ -37,9 +36,6 @@ QgsStacObject::Type QgsStacCollection::type() const QString QgsStacCollection::toHtml() const { - if ( !mValid ) - return QString(); - QString html = QStringLiteral( "\n\n" ); html += QStringLiteral( "

%1

\n
\n" ).arg( QStringLiteral( "Collection" ) ); diff --git a/src/core/stac/qgsstaccollection.h b/src/core/stac/qgsstaccollection.h index 301a5b985d54..2db00f0ed7da 100644 --- a/src/core/stac/qgsstaccollection.h +++ b/src/core/stac/qgsstaccollection.h @@ -35,8 +35,8 @@ class CORE_EXPORT QgsStacCollection : public QgsStacCatalog { public: - //! Default constructor creates an invalid collection - QgsStacCollection() = default; + //! Default constructor deleted, use the variant with required parameters + QgsStacCollection() = delete; /** * Constructs a valid QgsStacCollection diff --git a/src/core/stac/qgsstaccontroller.cpp b/src/core/stac/qgsstaccontroller.cpp index 5fab0ae1c954..ad84b16f2418 100644 --- a/src/core/stac/qgsstaccontroller.cpp +++ b/src/core/stac/qgsstaccontroller.cpp @@ -66,6 +66,12 @@ QNetworkReply *QgsStacController::fetchAsync( const QUrl &url ) QgsNetworkAccessManager *nam = QgsNetworkAccessManager::instance(); QNetworkReply *reply = nam->get( req ); + + if ( !mAuthCfg.isEmpty() ) + { + QgsApplication::authManager()->updateNetworkReply( reply, mAuthCfg ); + } + mReplies.append( reply ); QgsDebugMsgLevel( QStringLiteral( "Fired STAC request with id %1" ).arg( reply->property( "requestId" ).toInt() ), 2 ); diff --git a/src/core/stac/qgsstaccontroller.h b/src/core/stac/qgsstaccontroller.h index 7318ddbfee1a..78d10c732401 100644 --- a/src/core/stac/qgsstaccontroller.h +++ b/src/core/stac/qgsstaccontroller.h @@ -100,14 +100,22 @@ class CORE_EXPORT QgsStacController : public QObject int fetchItemCollectionAsync( const QUrl &url ); /** - * Returns the STAC object fetched with the specified \a requestId + * Returns the STAC object fetched with the specified \a requestId. + * It should be used after the finishedStacObjectRequest signal is fired to get the fetched STAC object. + * Returns NULLPTR if the requestId was not found, request was canceled, request failed or parsing the STAC object failed. * The caller takes ownership of the returned object + * \see fetchStacObjectAsync + * \see finishedStacObjectRequest */ QgsStacObject *takeStacObject( int requestId ); /** * Returns the feature collection fetched with the specified \a requestId + * It should be used after the finishedItemCollectionRequest signal is fired to get the fetched STAC item collection. + * Returns NULLPTR if the requestId was not found, request was canceled, request failed or parsing the STAC object failed. * The caller takes ownership of the returned feature collection + * \see fetchItemCollectionAsync + * \see finishedItemCollectionRequest */ QgsStacItemCollection *takeItemCollection( int requestId ); @@ -124,7 +132,25 @@ class CORE_EXPORT QgsStacController : public QObject void setAuthCfg( const QString &authCfg ); signals: + + /** + * This signal is fired when an async request initiated with fetchStacObjectAsync is finished. + * The parsed STAC object can be retrieved using takeStacObject + * \param id The requestId attribute of the finished request + * \param errorMessage Reason the request or parsing of the STAC object may have failed + * \see fetchStacObjectAsync + * \see takeStacObject + */ void finishedStacObjectRequest( int id, QString errorMessage ); + + /** + * This signal is fired when an async request initiated with fetchItemCollectionAsync is finished. + * The parsed STAC item collection can be retrieved using takeItemCollection + * \param id The requestId attribute of the finished request + * \param errorMessage Reason the request or parsing of the STAC item collection may have failed + * \see fetchItemCollectionAsync + * \see takeItemCollection + */ void finishedItemCollectionRequest( int id, QString errorMessage ); private slots: diff --git a/src/core/stac/qgsstacdataitems.cpp b/src/core/stac/qgsstacdataitems.cpp index ddc19825d0d9..b0dc8d7ef52c 100644 --- a/src/core/stac/qgsstacdataitems.cpp +++ b/src/core/stac/qgsstacdataitems.cpp @@ -70,7 +70,7 @@ QVector QgsStacItemItem::createChildren() QgsStacItem *item = dynamic_cast( obj ); setStacItem( item ); - if ( !mStacItem || !mStacItem->isValid() ) + if ( !mStacItem ) return { new QgsErrorItem( this, error, path() + QStringLiteral( "/error" ) ) }; return {}; @@ -323,7 +323,7 @@ QVector QgsStacCatalogItem::createChildren() QgsStacCatalog *cat = dynamic_cast( obj ); setStacCatalog( cat ); - if ( !mStacCatalog || !mStacCatalog->isValid() ) + if ( !mStacCatalog ) return { new QgsErrorItem( this, error, path() + QStringLiteral( "/error" ) ) }; int itemsCount = 0; @@ -457,11 +457,8 @@ QVector< QgsDataItem * > QgsStacCatalogItem::createItems( const QVectorisValid() ) - { - delete item; + if ( !item ) continue; - } const QString name = item->properties().value( QStringLiteral( "title" ), item->id() ).toString(); diff --git a/src/core/stac/qgsstacitem.cpp b/src/core/stac/qgsstacitem.cpp index aca922b80851..84e16aae8668 100644 --- a/src/core/stac/qgsstacitem.cpp +++ b/src/core/stac/qgsstacitem.cpp @@ -29,7 +29,6 @@ QgsStacItem::QgsStacItem( const QString &id, , mProperties( properties ) , mAssets( assets ) { - mValid = true; } QgsStacObject::Type QgsStacItem::type() const @@ -39,9 +38,6 @@ QgsStacObject::Type QgsStacItem::type() const QString QgsStacItem::toHtml() const { - if ( !mValid ) - return QString(); - QString html = QStringLiteral( "\n\n" ); html += QStringLiteral( "

%1

\n
\n" ).arg( QStringLiteral( "Item" ) ); diff --git a/src/core/stac/qgsstacitem.h b/src/core/stac/qgsstacitem.h index 6a74710e9d31..612acbeb72f9 100644 --- a/src/core/stac/qgsstacitem.h +++ b/src/core/stac/qgsstacitem.h @@ -36,8 +36,8 @@ class CORE_EXPORT QgsStacItem : public QgsStacObject { public: - //! Default constructor creates an invalid item - QgsStacItem() = default; + //! Default constructor deleted, use the variant with required parameters + QgsStacItem() = delete; /** * Constructs a valid QgsStacItem diff --git a/src/core/stac/qgsstacitemcollection.cpp b/src/core/stac/qgsstacitemcollection.cpp index 1ed81ac1b652..c8da8bbe5ff5 100644 --- a/src/core/stac/qgsstacitemcollection.cpp +++ b/src/core/stac/qgsstacitemcollection.cpp @@ -16,8 +16,7 @@ #include "qgsstacitemcollection.h" QgsStacItemCollection::QgsStacItemCollection( const QVector< QgsStacItem * > items, const QVector< QgsStacLink > links, int numberMatched ) - : mValid( true ) - , mItems( items ) + : mItems( items ) , mLinks( links ) , mNumberMatched( numberMatched ) { @@ -83,8 +82,3 @@ int QgsStacItemCollection::numberMatched() const { return mNumberMatched; } - -bool QgsStacItemCollection::isValid() const -{ - return mValid; -} diff --git a/src/core/stac/qgsstacitemcollection.h b/src/core/stac/qgsstacitemcollection.h index 4ffccd667681..a0e8adf732de 100644 --- a/src/core/stac/qgsstacitemcollection.h +++ b/src/core/stac/qgsstacitemcollection.h @@ -32,8 +32,8 @@ class CORE_EXPORT QgsStacItemCollection { public: - //! Default constructor creates an invalid item collection - QgsStacItemCollection() = default; + //! Default constructor deleted, use the variant with required parameters + QgsStacItemCollection() = delete; /** * Constructs a valid item collection @@ -93,11 +93,7 @@ class CORE_EXPORT QgsStacItemCollection */ int numberMatched() const; - //! Returns TRUE if the item collection is valid, FALSE otherwise - bool isValid() const; - private: - bool mValid = false; QVector< QgsStacItem * > mItems; const QVector< QgsStacLink > mLinks; QMap< QString, QString > mUrls; diff --git a/src/core/stac/qgsstacobject.cpp b/src/core/stac/qgsstacobject.cpp index 4500034cd15e..c911a5394834 100644 --- a/src/core/stac/qgsstacobject.cpp +++ b/src/core/stac/qgsstacobject.cpp @@ -23,11 +23,6 @@ QgsStacObject::QgsStacObject( const QString &id, const QString &version, const Q { } -bool QgsStacObject::isValid() const -{ - return mValid; -} - QString QgsStacObject::stacVersion() const { return mStacVersion; diff --git a/src/core/stac/qgsstacobject.h b/src/core/stac/qgsstacobject.h index e380e42c2511..6a301d509cdf 100644 --- a/src/core/stac/qgsstacobject.h +++ b/src/core/stac/qgsstacobject.h @@ -45,7 +45,7 @@ class CORE_EXPORT QgsStacObject }; //! Default constructor is used for creating invalid objects - QgsStacObject() = default; + QgsStacObject() = delete; //! Constructor for valid objects QgsStacObject( const QString &id, const QString &version, const QVector< QgsStacLink > &links ); @@ -59,9 +59,6 @@ class CORE_EXPORT QgsStacObject //! Returns an HTML representation of the STAC object virtual QString toHtml() const = 0; - //! Returns TRUE is it is a valid constructed STAC object, FALSE otherwise - bool isValid() const; - //! Returns the STAC version the object implements QString stacVersion() const; @@ -97,7 +94,6 @@ class CORE_EXPORT QgsStacObject protected: - bool mValid = false; Type mType = Type::Unknown; QString mId; QString mStacVersion; diff --git a/tests/src/core/testqgsstac.cpp b/tests/src/core/testqgsstac.cpp index 0217b66633a0..1bfa570aa7fd 100644 --- a/tests/src/core/testqgsstac.cpp +++ b/tests/src/core/testqgsstac.cpp @@ -77,7 +77,6 @@ void TestQgsStac::testParseLocalCatalog() QgsStacCatalog *cat = dynamic_cast< QgsStacCatalog * >( obj ); QVERIFY( cat ); - QVERIFY( cat->isValid() ); QCOMPARE( cat->id(), QLatin1String( "examples" ) ); QCOMPARE( cat->stacVersion(), QLatin1String( "1.0.0" ) ); QCOMPARE( cat->title(), QLatin1String( "Example Catalog" ) ); @@ -98,7 +97,6 @@ void TestQgsStac::testParseLocalCollection() QgsStacCollection *col = dynamic_cast< QgsStacCollection * >( obj ); QVERIFY( col ); - QVERIFY( col->isValid() ); QCOMPARE( col->id(), QLatin1String( "simple-collection" ) ); QCOMPARE( col->stacVersion(), QLatin1String( "1.0.0" ) ); QCOMPARE( col->title(), QLatin1String( "Simple Example Collection" ) ); @@ -139,7 +137,6 @@ void TestQgsStac::testParseLocalItem() QgsStacItem *item = dynamic_cast( obj ); QVERIFY( item ); - QVERIFY( item->isValid() ); QCOMPARE( item->id(), QLatin1String( "20201211_223832_CS2" ) ); QCOMPARE( item->stacVersion(), QLatin1String( "1.0.0" ) ); QCOMPARE( item->links().size(), 4 );