Skip to content

Commit

Permalink
stac gui for browser implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
uclaros committed Oct 4, 2024
1 parent 7ed550c commit d770e55
Show file tree
Hide file tree
Showing 21 changed files with 1,329 additions and 0 deletions.
1 change: 1 addition & 0 deletions images/images.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -1009,6 +1009,7 @@
<file>themes/default/mActionTextInsideRect.svg</file>
<file>themes/default/mIconLabelingRules.svg</file>
<file>themes/default/stacked-diagram.svg</file>
<file>themes/default/mIconStac.svg</file>
</qresource>
<qresource prefix="/images/tips">
<file alias="symbol_levels.png">qgis_tips/symbol_levels.png</file>
Expand Down
82 changes: 82 additions & 0 deletions images/themes/default/mIconStac.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@
QgsManageConnectionsDialog.TiledScene = QgsManageConnectionsDialog.Type.TiledScene
QgsManageConnectionsDialog.SensorThings = QgsManageConnectionsDialog.Type.SensorThings
QgsManageConnectionsDialog.CloudStorage = QgsManageConnectionsDialog.Type.CloudStorage
QgsManageConnectionsDialog.STAC = QgsManageConnectionsDialog.Type.STAC
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class QgsManageConnectionsDialog : QDialog
TiledScene,
SensorThings,
CloudStorage,
STAC,
};

QgsManageConnectionsDialog( QWidget *parent /TransferThis/ = 0, Mode mode = Export, Type type = WMS, const QString &fileName = QString() );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class QgsManageConnectionsDialog : QDialog
TiledScene,
SensorThings,
CloudStorage,
STAC,
};

QgsManageConnectionsDialog( QWidget *parent /TransferThis/ = 0, Mode mode = Export, Type type = WMS, const QString &fileName = QString() );
Expand Down
4 changes: 4 additions & 0 deletions src/app/qgisapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,8 @@
#include "qgscustomlayerorderwidget.h"
#include "qgsdataitemproviderregistry.h"
#include "qgsdataitemguiproviderregistry.h"
#include "qgsstacdataitems.h"
#include "qgsstacdataitemguiprovider.h"
#include "qgsdatasourceuri.h"
#include "qgsdatumtransformdialog.h"
#include "qgsdoublespinbox.h"
Expand Down Expand Up @@ -1442,6 +1444,7 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, bool skipBadLayers
QgsGui::dataItemGuiProviderRegistry()->addProvider( new QgsFieldDomainItemGuiProvider() );
QgsGui::dataItemGuiProviderRegistry()->addProvider( new QgsRelationshipItemGuiProvider() );
QgsGui::dataItemGuiProviderRegistry()->addProvider( new QgsDatabaseItemGuiProvider() );
QgsGui::dataItemGuiProviderRegistry()->addProvider( new QgsStacDataItemGuiProvider() );

QShortcut *showBrowserDock = new QShortcut( QKeySequence( tr( "Ctrl+2" ) ), this );
connect( showBrowserDock, &QShortcut::activated, mBrowserWidget, &QgsDockWidget::toggleUserVisible );
Expand Down Expand Up @@ -1647,6 +1650,7 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, bool skipBadLayers
#endif

QgsApplication::dataItemProviderRegistry()->addProvider( new QgsProjectDataItemProvider() );
QgsApplication::dataItemProviderRegistry()->addProvider( new QgsStacDataItemProvider() );

// now when all data item providers are registered, customize both browsers
QgsCustomization::instance()->updateBrowserWidget( mBrowserWidget );
Expand Down
11 changes: 11 additions & 0 deletions src/gui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,11 @@ set(QGIS_GUI_SRCS
settings/qgssettingstreemodel.cpp
settings/qgssettingstreewidget.cpp

stac/qgsstacconnectiondialog.cpp
stac/qgsstacdataitemguiprovider.cpp
stac/qgsstacdownloadassetsdialog.cpp
stac/qgsstacobjectdetailsdialog.cpp

tableeditor/qgstableeditordialog.cpp
tableeditor/qgstableeditorformattingwidget.cpp
tableeditor/qgstableeditorwidget.cpp
Expand Down Expand Up @@ -1560,6 +1565,11 @@ set(QGIS_GUI_HDRS
settings/qgssettingstreemodel.h
settings/qgssettingstreewidget.h

stac/qgsstacconnectiondialog.h
stac/qgsstacdataitemguiprovider.h
stac/qgsstacdownloadassetsdialog.h
stac/qgsstacobjectdetailsdialog.h

tableeditor/qgstableeditordialog.h
tableeditor/qgstableeditorformattingwidget.h
tableeditor/qgstableeditorwidget.h
Expand Down Expand Up @@ -1720,6 +1730,7 @@ target_include_directories(qgis_gui PUBLIC
${CMAKE_SOURCE_DIR}/src/gui/raster
${CMAKE_SOURCE_DIR}/src/gui/sensor
${CMAKE_SOURCE_DIR}/src/gui/settings
${CMAKE_SOURCE_DIR}/src/gui/stac
${CMAKE_SOURCE_DIR}/src/gui/tableeditor
${CMAKE_SOURCE_DIR}/src/gui/tiledscene
${CMAKE_SOURCE_DIR}/src/gui/vector
Expand Down
127 changes: 127 additions & 0 deletions src/gui/qgsmanageconnectionsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "qgstiledsceneconnection.h"
#include "qgssensorthingsconnection.h"
#include "qgsgdalcloudconnection.h"
#include "qgsstacconnection.h"

QgsManageConnectionsDialog::QgsManageConnectionsDialog( QWidget *parent, Mode mode, Type type, const QString &fileName )
: QDialog( parent )
Expand Down Expand Up @@ -159,6 +160,9 @@ void QgsManageConnectionsDialog::doExportImport()
case CloudStorage:
doc = saveCloudStorageConnections( items );
break;
case STAC:
doc = saveStacConnections( items );
break;
}

QFile file( mFileName );
Expand Down Expand Up @@ -245,6 +249,9 @@ void QgsManageConnectionsDialog::doExportImport()
case CloudStorage:
loadCloudStorageConnections( doc, items );
break;
case STAC:
loadStacConnections( doc, items );
break;
}
// clear connections list and close window
listConnections->clear();
Expand Down Expand Up @@ -307,6 +314,9 @@ bool QgsManageConnectionsDialog::populateConnections()
case CloudStorage:
connections = QgsGdalCloudProviderConnection::sTreeConnectionCloud->items();
break;
case STAC:
connections = QgsStacConnection::sTreeConnectionStac->items();
break;
}
for ( const QString &connection : std::as_const( connections ) )
{
Expand Down Expand Up @@ -462,6 +472,14 @@ bool QgsManageConnectionsDialog::populateConnections()
return false;
}
break;
case STAC:
if ( root.tagName() != QLatin1String( "qgsStacConnections" ) )
{
QMessageBox::information( this, tr( "Loading Connections" ),
tr( "The file is not a STAC connections exchange file." ) );
return false;
}
break;
}

QDomElement child = root.firstChildElement();
Expand Down Expand Up @@ -891,6 +909,32 @@ QDomDocument QgsManageConnectionsDialog::saveCloudStorageConnections( const QStr
return doc;
}

QDomDocument QgsManageConnectionsDialog::saveStacConnections( const QStringList &connections )
{
QDomDocument doc( QStringLiteral( "connections" ) );
QDomElement root = doc.createElement( QStringLiteral( "qgsStacConnections" ) );
root.setAttribute( QStringLiteral( "version" ), QStringLiteral( "1.0" ) );
doc.appendChild( root );

for ( int i = 0; i < connections.count(); ++i )
{
QDomElement el = doc.createElement( QStringLiteral( "stac" ) );

el.setAttribute( QStringLiteral( "name" ), connections[ i ] );
el.setAttribute( QStringLiteral( "url" ), QgsStacConnection::settingsUrl->value( connections[ i ] ) );
el.setAttribute( QStringLiteral( "authcfg" ), QgsStacConnection::settingsAuthcfg->value( connections[ i ] ) );
el.setAttribute( QStringLiteral( "username" ), QgsStacConnection::settingsUsername->value( connections[ i ] ) );
el.setAttribute( QStringLiteral( "password" ), QgsStacConnection::settingsPassword->value( connections[ i ] ) );

QgsHttpHeaders httpHeader( QgsStacConnection::settingsHeaders->value( connections[ i ] ) );
httpHeader.updateDomElement( el );

root.appendChild( el );
}

return doc;
}

void QgsManageConnectionsDialog::loadOWSConnections( const QDomDocument &doc, const QStringList &items, const QString &service )
{
const QDomElement root = doc.documentElement();
Expand Down Expand Up @@ -1974,6 +2018,89 @@ void QgsManageConnectionsDialog::loadCloudStorageConnections( const QDomDocument
}
}

void QgsManageConnectionsDialog::loadStacConnections( const QDomDocument &doc, const QStringList &items )
{
const QDomElement root = doc.documentElement();
if ( root.tagName() != QLatin1String( "qgsStacConnections" ) )
{
QMessageBox::information( this, tr( "Loading Connections" ),
tr( "The file is not a STAC connections exchange file." ) );
return;
}

QString connectionName;
QgsSettings settings;
settings.beginGroup( QStringLiteral( "/qgis/connections-stac" ) );
QStringList keys = settings.childGroups();
settings.endGroup();
QDomElement child = root.firstChildElement();
bool prompt = true;
bool overwrite = true;

while ( !child.isNull() )
{
connectionName = child.attribute( QStringLiteral( "name" ) );
if ( !items.contains( connectionName ) )
{
child = child.nextSiblingElement();
continue;
}

// check for duplicates
if ( keys.contains( connectionName ) && prompt )
{
const int res = QMessageBox::warning( this,
tr( "Loading Connections" ),
tr( "Connection with name '%1' already exists. Overwrite?" )
.arg( connectionName ),
QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel );

switch ( res )
{
case QMessageBox::Cancel:
return;
case QMessageBox::No:
child = child.nextSiblingElement();
continue;
case QMessageBox::Yes:
overwrite = true;
break;
case QMessageBox::YesToAll:
prompt = false;
overwrite = true;
break;
case QMessageBox::NoToAll:
prompt = false;
overwrite = false;
break;
}
}

if ( keys.contains( connectionName ) )
{
if ( !overwrite )
{
child = child.nextSiblingElement();
continue;
}
}
else
{
keys << connectionName;
}

QgsStacConnection::settingsUrl->setValue( child.attribute( QStringLiteral( "url" ) ), connectionName );
QgsStacConnection::settingsAuthcfg->setValue( child.attribute( QStringLiteral( "authcfg" ) ), connectionName );
QgsStacConnection::settingsUsername->setValue( child.attribute( QStringLiteral( "username" ) ), connectionName );
QgsStacConnection::settingsPassword->setValue( child.attribute( QStringLiteral( "password" ) ), connectionName );

QgsHttpHeaders httpHeader( child );
QgsStacConnection::settingsHeaders->setValue( httpHeader.headers(), connectionName );

child = child.nextSiblingElement();
}
}

void QgsManageConnectionsDialog::selectAll()
{
listConnections->selectAll();
Expand Down
3 changes: 3 additions & 0 deletions src/gui/qgsmanageconnectionsdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class GUI_EXPORT QgsManageConnectionsDialog : public QDialog, private Ui::QgsMan
TiledScene, //!< Tiled scene connection \since QGIS 3.34
SensorThings, //!< SensorThings connections \since QGIS 3.36
CloudStorage, //!< Cloud storage connections \since QGIS 3.40
STAC, //!< SpatioTemporal Asset Catalog connections \since QGIS 3.40
};

/**
Expand Down Expand Up @@ -83,6 +84,7 @@ class GUI_EXPORT QgsManageConnectionsDialog : public QDialog, private Ui::QgsMan
QDomDocument saveTiledSceneConnections( const QStringList &connections );
QDomDocument saveSensorThingsConnections( const QStringList &connections );
QDomDocument saveCloudStorageConnections( const QStringList &connections );
QDomDocument saveStacConnections( const QStringList &connections );

void loadOWSConnections( const QDomDocument &doc, const QStringList &items, const QString &service );
void loadWfsConnections( const QDomDocument &doc, const QStringList &items );
Expand All @@ -96,6 +98,7 @@ class GUI_EXPORT QgsManageConnectionsDialog : public QDialog, private Ui::QgsMan
void loadTiledSceneConnections( const QDomDocument &doc, const QStringList &items );
void loadSensorThingsConnections( const QDomDocument &doc, const QStringList &items );
void loadCloudStorageConnections( const QDomDocument &doc, const QStringList &items );
void loadStacConnections( const QDomDocument &doc, const QStringList &items );

QString mFileName;
Mode mDialogMode;
Expand Down
Loading

0 comments on commit d770e55

Please sign in to comment.