Skip to content

Commit

Permalink
GDAL/OGR source select UX: add OGCAPI
Browse files Browse the repository at this point in the history
Adds an entry for OGCAPI, in order to add
the endpoint without the need of OGCAPI: prefix.
  • Loading branch information
elpaso committed Apr 21, 2023
1 parent 456d725 commit 985621b
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 35 deletions.
17 changes: 15 additions & 2 deletions src/gui/providers/gdal/qgsgdalsourceselect.cpp
Expand Up @@ -33,6 +33,7 @@ QgsGdalSourceSelect::QgsGdalSourceSelect( QWidget *parent, Qt::WindowFlags fl, Q
setupButtons( buttonBox );

connect( radioSrcFile, &QRadioButton::toggled, this, &QgsGdalSourceSelect::radioSrcFile_toggled );
connect( radioSrcOgcApi, &QRadioButton::toggled, this, &QgsGdalSourceSelect::radioSrcOgcApi_toggled );
connect( radioSrcProtocol, &QRadioButton::toggled, this, &QgsGdalSourceSelect::radioSrcProtocol_toggled );
connect( cmbProtocolTypes, &QComboBox::currentTextChanged, this, &QgsGdalSourceSelect::cmbProtocolTypes_currentIndexChanged );

Expand Down Expand Up @@ -80,7 +81,7 @@ QgsGdalSourceSelect::QgsGdalSourceSelect( QWidget *parent, Qt::WindowFlags fl, Q
mFileWidget->setOptions( QFileDialog::HideNameFilterDetails );
connect( mFileWidget, &QgsFileWidget::fileChanged, this, [ = ]( const QString & path )
{
mRasterPath = path;
mRasterPath = mIsOgcApi ? QStringLiteral( "OGCAPI:%1" ).arg( path ) : path;
emit enableButtons( ! mRasterPath.isEmpty() );
fillOpenOptions();
} );
Expand Down Expand Up @@ -136,6 +137,18 @@ void QgsGdalSourceSelect::radioSrcFile_toggled( bool checked )
}
}

void QgsGdalSourceSelect::radioSrcOgcApi_toggled( bool checked )
{
mIsOgcApi = checked;
radioSrcFile_toggled( checked );
if ( checked )
{
const QString vectorPath = mFileWidget->filePath();
emit enableButtons( ! vectorPath.isEmpty() );
fillOpenOptions();
}
}

void QgsGdalSourceSelect::radioSrcProtocol_toggled( bool checked )
{
if ( checked )
Expand Down Expand Up @@ -238,7 +251,7 @@ void QgsGdalSourceSelect::computeDataSources()
}
}

if ( radioSrcFile->isChecked() )
if ( radioSrcFile->isChecked() || radioSrcOgcApi->isChecked() )
{
for ( const auto &filePath : QgsFileWidget::splitFilePaths( mRasterPath ) )
{
Expand Down
3 changes: 2 additions & 1 deletion src/gui/providers/gdal/qgsgdalsourceselect.h
Expand Up @@ -47,6 +47,7 @@ class QgsGdalSourceSelect : public QgsAbstractDataSourceWidget, private Ui::QgsG
void setProtocolWidgetsVisibility();

void radioSrcFile_toggled( bool checked );
void radioSrcOgcApi_toggled( bool checked );
void radioSrcProtocol_toggled( bool checked );
void cmbProtocolTypes_currentIndexChanged( const QString &text );

Expand All @@ -59,7 +60,7 @@ class QgsGdalSourceSelect : public QgsAbstractDataSourceWidget, private Ui::QgsG

QString mRasterPath;
QStringList mDataSources;

bool mIsOgcApi = false;
};

///@endcond
Expand Down
30 changes: 27 additions & 3 deletions src/gui/providers/ogr/qgsogrsourceselect.cpp
Expand Up @@ -43,6 +43,7 @@ QgsOgrSourceSelect::QgsOgrSourceSelect( QWidget *parent, Qt::WindowFlags fl, Qgs
QgsGui::enableAutoGeometryRestore( this );

connect( radioSrcFile, &QRadioButton::toggled, this, &QgsOgrSourceSelect::radioSrcFile_toggled );
connect( radioSrcOgcApi, &QRadioButton::toggled, this, &QgsOgrSourceSelect::radioSrcOgcApi_toggled );
connect( radioSrcDirectory, &QRadioButton::toggled, this, &QgsOgrSourceSelect::radioSrcDirectory_toggled );
connect( radioSrcDatabase, &QRadioButton::toggled, this, &QgsOgrSourceSelect::radioSrcDatabase_toggled );
connect( radioSrcProtocol, &QRadioButton::toggled, this, &QgsOgrSourceSelect::radioSrcProtocol_toggled );
Expand Down Expand Up @@ -115,7 +116,7 @@ QgsOgrSourceSelect::QgsOgrSourceSelect( QWidget *parent, Qt::WindowFlags fl, Qgs
connect( mFileWidget, &QgsFileWidget::fileChanged, this, [ = ]( const QString & path )
{
mVectorPath = path;
if ( radioSrcFile->isChecked() || radioSrcDirectory->isChecked() )
if ( radioSrcFile->isChecked() || radioSrcDirectory->isChecked() || radioSrcOgcApi->isChecked() )
emit enableButtons( ! mVectorPath.isEmpty() );
fillOpenOptions();
} );
Expand Down Expand Up @@ -440,10 +441,16 @@ void QgsOgrSourceSelect::computeDataSources( bool interactive )
mAuthSettingsProtocol->password() ) );
mDataSources << QgsProviderRegistry::instance()->encodeUri( QStringLiteral( "ogr" ), parts );
}
else if ( radioSrcFile->isChecked() )
else if ( radioSrcFile->isChecked() || radioSrcOgcApi->isChecked() )
{
if ( mVectorPath.isEmpty() )
{
if ( mIsOgcApi )
{
mDataSources.push_back( QStringLiteral( "OGCAPI:" ) );
return;
}

if ( interactive )
{
QMessageBox::information( this,
Expand All @@ -458,7 +465,7 @@ void QgsOgrSourceSelect::computeDataSources( bool interactive )
QVariantMap parts;
if ( !openOptions.isEmpty() )
parts.insert( QStringLiteral( "openOptions" ), openOptions );
parts.insert( QStringLiteral( "path" ), filePath );
parts.insert( QStringLiteral( "path" ), mIsOgcApi ? QStringLiteral( "OGCAPI:%1" ).arg( filePath ) : filePath );
mDataSources << QgsProviderRegistry::instance()->encodeUri( QStringLiteral( "ogr" ), parts );
}
}
Expand Down Expand Up @@ -526,6 +533,23 @@ void QgsOgrSourceSelect::radioSrcFile_toggled( bool checked )
}
}

void QgsOgrSourceSelect::radioSrcOgcApi_toggled( bool checked )
{
mIsOgcApi = checked;
radioSrcFile_toggled( checked );
if ( checked )
{
labelSrcDataset->setText( tr( "OGC API Endpoint" ) );
mVectorPath = mFileWidget->filePath();
emit enableButtons( ! mVectorPath.isEmpty() );
fillOpenOptions();
}
else
{
labelSrcDataset->setText( tr( "Vector Dataset(s)" ) );
}
}

void QgsOgrSourceSelect::radioSrcDirectory_toggled( bool checked )
{
if ( checked )
Expand Down
3 changes: 2 additions & 1 deletion src/gui/providers/ogr/qgsogrsourceselect.h
Expand Up @@ -100,6 +100,7 @@ class QgsOgrSourceSelect : public QgsAbstractDataSourceWidget, private Ui::QgsOg
void setProtocolWidgetsVisibility();

void radioSrcFile_toggled( bool checked );
void radioSrcOgcApi_toggled( bool checked );
void radioSrcDirectory_toggled( bool checked );
void radioSrcDatabase_toggled( bool checked );
void radioSrcProtocol_toggled( bool checked );
Expand All @@ -117,7 +118,7 @@ class QgsOgrSourceSelect : public QgsAbstractDataSourceWidget, private Ui::QgsOg
void clearOpenOptions();
void fillOpenOptions();
std::vector<QWidget *> mOpenOptionsWidgets;

bool mIsOgcApi = false;
QString mVectorPath;

};
Expand Down
48 changes: 31 additions & 17 deletions src/ui/qgsgdalsourceselectbase.ui
Expand Up @@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>355</width>
<height>229</height>
<height>501</height>
</rect>
</property>
<property name="windowTitle">
Expand Down Expand Up @@ -52,6 +52,13 @@
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="radioSrcOgcApi">
<property name="text">
<string>OGC API</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
Expand Down Expand Up @@ -208,25 +215,25 @@
</widget>
</item>
<item>
<widget class="QgsCollapsibleGroupBox" name="mOpenOptionsGroupBox">
<property name="title">
<widget class="QgsCollapsibleGroupBox" name="mOpenOptionsGroupBox" native="true">
<property name="title" stdset="0">
<string>Options</string>
</property>
<layout class="QVBoxLayout" name="openOptionsVBoxLayout">
<item>
<widget class="QLabel" name="mOpenOptionsLabel">
<property name="text">
<string></string>
</property>
</widget>
</item>
<item>
<layout class="QFormLayout" name="mOpenOptionsLayout">
<property name="fieldGrowthPolicy">
<enum>QFormLayout::AllNonFixedFieldsGrow</enum>
</property>
</layout>
</item>
<item>
<widget class="QLabel" name="mOpenOptionsLabel">
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<layout class="QFormLayout" name="mOpenOptionsLayout">
<property name="fieldGrowthPolicy">
<enum>QFormLayout::AllNonFixedFieldsGrow</enum>
</property>
</layout>
</item>
</layout>
</widget>
</item>
Expand Down Expand Up @@ -260,13 +267,20 @@
<class>QgsFileWidget</class>
<extends>QWidget</extends>
<header>qgsfilewidget.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>QgsAuthSettingsWidget</class>
<extends>QWidget</extends>
<header>qgsauthsettingswidget.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>QgsCollapsibleGroupBox</class>
<extends>QWidget</extends>
<header>qgscollapsiblegroupbox.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>mOpenOptionsGroupBox</tabstop>
Expand Down
29 changes: 18 additions & 11 deletions src/ui/qgsogrsourceselectbase.ui
Expand Up @@ -51,9 +51,9 @@
<property name="geometry">
<rect>
<x>0</x>
<y>-282</y>
<width>508</width>
<height>745</height>
<y>0</y>
<width>537</width>
<height>757</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_5">
Expand Down Expand Up @@ -101,6 +101,13 @@
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="radioSrcOgcApi">
<property name="text">
<string>OGC API</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
Expand Down Expand Up @@ -383,8 +390,8 @@
</widget>
</item>
<item>
<widget class="QgsCollapsibleGroupBox" name="mOpenOptionsGroupBox">
<property name="title">
<widget class="QgsCollapsibleGroupBox" name="mOpenOptionsGroupBox" native="true">
<property name="title" stdset="0">
<string>Options</string>
</property>
<layout class="QVBoxLayout" name="openOptionsVBoxLayout">
Expand Down Expand Up @@ -435,12 +442,6 @@
</widget>
<layoutdefault spacing="6" margin="11"/>
<customwidgets>
<customwidget>
<class>QgsCollapsibleGroupBox</class>
<extends>QGroupBox</extends>
<header>qgscollapsiblegroupbox.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>QgsFileWidget</class>
<extends>QWidget</extends>
Expand All @@ -453,6 +454,12 @@
<header>qgsauthsettingswidget.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>QgsCollapsibleGroupBox</class>
<extends>QWidget</extends>
<header>qgscollapsiblegroupbox.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>QgsScrollArea</class>
<extends>QScrollArea</extends>
Expand Down

0 comments on commit 985621b

Please sign in to comment.