Skip to content

Commit

Permalink
Removed isValid() method and expanded missing docstrings
Browse files Browse the repository at this point in the history
  • Loading branch information
uclaros authored and wonder-sk committed Oct 9, 2024
1 parent 3af3539 commit a758dfd
Show file tree
Hide file tree
Showing 14 changed files with 46 additions and 51 deletions.
4 changes: 0 additions & 4 deletions src/core/stac/qgsstaccatalog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ QgsStacCatalog::QgsStacCatalog( const QString &id,
: QgsStacObject( id, version, links )
, mDescription( description )
{
mValid = true;
}

QgsStacObject::Type QgsStacCatalog::type() const
Expand All @@ -32,9 +31,6 @@ QgsStacObject::Type QgsStacCatalog::type() const

QString QgsStacCatalog::toHtml() const
{
if ( !mValid )
return QString();

QString html = QStringLiteral( "<html><head></head>\n<body>\n" );

html += QStringLiteral( "<h1>%1</h1>\n<hr>\n" ).arg( QStringLiteral( "Catalog" ) );
Expand Down
4 changes: 2 additions & 2 deletions src/core/stac/qgsstaccatalog.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 0 additions & 4 deletions src/core/stac/qgsstaccollection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ QgsStacCollection::QgsStacCollection( const QString &id,
, mLicense( license )
, mExtent( extent )
{
mValid = true;
}

QgsStacObject::Type QgsStacCollection::type() const
Expand All @@ -37,9 +36,6 @@ QgsStacObject::Type QgsStacCollection::type() const

QString QgsStacCollection::toHtml() const
{
if ( !mValid )
return QString();

QString html = QStringLiteral( "<html><head></head>\n<body>\n" );

html += QStringLiteral( "<h1>%1</h1>\n<hr>\n" ).arg( QStringLiteral( "Collection" ) );
Expand Down
4 changes: 2 additions & 2 deletions src/core/stac/qgsstaccollection.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions src/core/stac/qgsstaccontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
28 changes: 27 additions & 1 deletion src/core/stac/qgsstaccontroller.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 );

Expand All @@ -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:
Expand Down
9 changes: 3 additions & 6 deletions src/core/stac/qgsstacdataitems.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ QVector<QgsDataItem *> QgsStacItemItem::createChildren()
QgsStacItem *item = dynamic_cast<QgsStacItem *>( obj );
setStacItem( item );

if ( !mStacItem || !mStacItem->isValid() )
if ( !mStacItem )
return { new QgsErrorItem( this, error, path() + QStringLiteral( "/error" ) ) };

return {};
Expand Down Expand Up @@ -323,7 +323,7 @@ QVector<QgsDataItem *> QgsStacCatalogItem::createChildren()
QgsStacCatalog *cat = dynamic_cast<QgsStacCatalog *>( obj );
setStacCatalog( cat );

if ( !mStacCatalog || !mStacCatalog->isValid() )
if ( !mStacCatalog )
return { new QgsErrorItem( this, error, path() + QStringLiteral( "/error" ) ) };

int itemsCount = 0;
Expand Down Expand Up @@ -457,11 +457,8 @@ QVector< QgsDataItem * > QgsStacCatalogItem::createItems( const QVector<QgsStacI
contents.reserve( items.size() );
for ( QgsStacItem *item : items )
{
if ( !item->isValid() )
{
delete item;
if ( !item )
continue;
}

const QString name = item->properties().value( QStringLiteral( "title" ), item->id() ).toString();

Expand Down
4 changes: 0 additions & 4 deletions src/core/stac/qgsstacitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ QgsStacItem::QgsStacItem( const QString &id,
, mProperties( properties )
, mAssets( assets )
{
mValid = true;
}

QgsStacObject::Type QgsStacItem::type() const
Expand All @@ -39,9 +38,6 @@ QgsStacObject::Type QgsStacItem::type() const

QString QgsStacItem::toHtml() const
{
if ( !mValid )
return QString();

QString html = QStringLiteral( "<html><head></head>\n<body>\n" );

html += QStringLiteral( "<h1>%1</h1>\n<hr>\n" ).arg( QStringLiteral( "Item" ) );
Expand Down
4 changes: 2 additions & 2 deletions src/core/stac/qgsstacitem.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 1 addition & 7 deletions src/core/stac/qgsstacitemcollection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
{
Expand Down Expand Up @@ -83,8 +82,3 @@ int QgsStacItemCollection::numberMatched() const
{
return mNumberMatched;
}

bool QgsStacItemCollection::isValid() const
{
return mValid;
}
8 changes: 2 additions & 6 deletions src/core/stac/qgsstacitemcollection.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down
5 changes: 0 additions & 5 deletions src/core/stac/qgsstacobject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 1 addition & 5 deletions src/core/stac/qgsstacobject.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand All @@ -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;

Expand Down Expand Up @@ -97,7 +94,6 @@ class CORE_EXPORT QgsStacObject


protected:
bool mValid = false;
Type mType = Type::Unknown;
QString mId;
QString mStacVersion;
Expand Down
3 changes: 0 additions & 3 deletions tests/src/core/testqgsstac.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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" ) );
Expand All @@ -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" ) );
Expand Down Expand Up @@ -139,7 +137,6 @@ void TestQgsStac::testParseLocalItem()
QgsStacItem *item = dynamic_cast<QgsStacItem *>( 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 );
Expand Down

0 comments on commit a758dfd

Please sign in to comment.