Skip to content

Commit 8db8acd

Browse files
authoredApr 24, 2023
Merge pull request #52819 from elpaso/ogcapi-ux
GDAL/OGR source select UX: add OGCAPI radio
2 parents 2175537 + 021a13c commit 8db8acd

File tree

6 files changed

+110
-36
lines changed

6 files changed

+110
-36
lines changed
 

‎src/gui/providers/gdal/qgsgdalsourceselect.cpp

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,10 @@ QgsGdalSourceSelect::QgsGdalSourceSelect( QWidget *parent, Qt::WindowFlags fl, Q
3232
setupUi( this );
3333
setupButtons( buttonBox );
3434

35+
mOpenOptionsGroupBox->setCollapsed( false );
36+
3537
connect( radioSrcFile, &QRadioButton::toggled, this, &QgsGdalSourceSelect::radioSrcFile_toggled );
38+
connect( radioSrcOgcApi, &QRadioButton::toggled, this, &QgsGdalSourceSelect::radioSrcOgcApi_toggled );
3639
connect( radioSrcProtocol, &QRadioButton::toggled, this, &QgsGdalSourceSelect::radioSrcProtocol_toggled );
3740
connect( cmbProtocolTypes, &QComboBox::currentTextChanged, this, &QgsGdalSourceSelect::cmbProtocolTypes_currentIndexChanged );
3841

@@ -80,7 +83,7 @@ QgsGdalSourceSelect::QgsGdalSourceSelect( QWidget *parent, Qt::WindowFlags fl, Q
8083
mFileWidget->setOptions( QFileDialog::HideNameFilterDetails );
8184
connect( mFileWidget, &QgsFileWidget::fileChanged, this, [ = ]( const QString & path )
8285
{
83-
mRasterPath = path;
86+
mRasterPath = mIsOgcApi ? QStringLiteral( "OGCAPI:%1" ).arg( path ) : path;
8487
emit enableButtons( ! mRasterPath.isEmpty() );
8588
fillOpenOptions();
8689
} );
@@ -136,6 +139,27 @@ void QgsGdalSourceSelect::radioSrcFile_toggled( bool checked )
136139
}
137140
}
138141

142+
void QgsGdalSourceSelect::radioSrcOgcApi_toggled( bool checked )
143+
{
144+
mIsOgcApi = checked;
145+
radioSrcFile_toggled( checked );
146+
if ( checked )
147+
{
148+
rasterDatasetLabel->setText( tr( "OGC API Endpoint" ) );
149+
const QString vectorPath = mFileWidget->filePath();
150+
emit enableButtons( ! vectorPath.isEmpty() );
151+
if ( mRasterPath.isEmpty() )
152+
{
153+
mRasterPath = QStringLiteral( "OGCAPI:" );
154+
}
155+
fillOpenOptions();
156+
}
157+
else
158+
{
159+
rasterDatasetLabel->setText( tr( "Raster dataset(s)" ) );
160+
}
161+
}
162+
139163
void QgsGdalSourceSelect::radioSrcProtocol_toggled( bool checked )
140164
{
141165
if ( checked )
@@ -238,7 +262,7 @@ void QgsGdalSourceSelect::computeDataSources()
238262
}
239263
}
240264

241-
if ( radioSrcFile->isChecked() )
265+
if ( radioSrcFile->isChecked() || radioSrcOgcApi->isChecked() )
242266
{
243267
for ( const auto &filePath : QgsFileWidget::splitFilePaths( mRasterPath ) )
244268
{
@@ -423,6 +447,7 @@ void QgsGdalSourceSelect::fillOpenOptions()
423447
}
424448

425449
mOpenOptionsGroupBox->setVisible( !mOpenOptionsWidgets.empty() );
450+
426451
}
427452

428453
///@endcond

‎src/gui/providers/gdal/qgsgdalsourceselect.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ class QgsGdalSourceSelect : public QgsAbstractDataSourceWidget, private Ui::QgsG
4747
void setProtocolWidgetsVisibility();
4848

4949
void radioSrcFile_toggled( bool checked );
50+
void radioSrcOgcApi_toggled( bool checked );
5051
void radioSrcProtocol_toggled( bool checked );
5152
void cmbProtocolTypes_currentIndexChanged( const QString &text );
5253

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

6061
QString mRasterPath;
6162
QStringList mDataSources;
62-
63+
bool mIsOgcApi = false;
6364
};
6465

6566
///@endcond

‎src/gui/providers/ogr/qgsogrsourceselect.cpp

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,10 @@ QgsOgrSourceSelect::QgsOgrSourceSelect( QWidget *parent, Qt::WindowFlags fl, Qgs
4242
setupUi( this );
4343
QgsGui::enableAutoGeometryRestore( this );
4444

45+
mOpenOptionsGroupBox->setCollapsed( false );
46+
4547
connect( radioSrcFile, &QRadioButton::toggled, this, &QgsOgrSourceSelect::radioSrcFile_toggled );
48+
connect( radioSrcOgcApi, &QRadioButton::toggled, this, &QgsOgrSourceSelect::radioSrcOgcApi_toggled );
4649
connect( radioSrcDirectory, &QRadioButton::toggled, this, &QgsOgrSourceSelect::radioSrcDirectory_toggled );
4750
connect( radioSrcDatabase, &QRadioButton::toggled, this, &QgsOgrSourceSelect::radioSrcDatabase_toggled );
4851
connect( radioSrcProtocol, &QRadioButton::toggled, this, &QgsOgrSourceSelect::radioSrcProtocol_toggled );
@@ -115,7 +118,7 @@ QgsOgrSourceSelect::QgsOgrSourceSelect( QWidget *parent, Qt::WindowFlags fl, Qgs
115118
connect( mFileWidget, &QgsFileWidget::fileChanged, this, [ = ]( const QString & path )
116119
{
117120
mVectorPath = path;
118-
if ( radioSrcFile->isChecked() || radioSrcDirectory->isChecked() )
121+
if ( radioSrcFile->isChecked() || radioSrcDirectory->isChecked() || radioSrcOgcApi->isChecked() )
119122
emit enableButtons( ! mVectorPath.isEmpty() );
120123
fillOpenOptions();
121124
} );
@@ -440,10 +443,16 @@ void QgsOgrSourceSelect::computeDataSources( bool interactive )
440443
mAuthSettingsProtocol->password() ) );
441444
mDataSources << QgsProviderRegistry::instance()->encodeUri( QStringLiteral( "ogr" ), parts );
442445
}
443-
else if ( radioSrcFile->isChecked() )
446+
else if ( radioSrcFile->isChecked() || radioSrcOgcApi->isChecked() )
444447
{
445448
if ( mVectorPath.isEmpty() )
446449
{
450+
if ( mIsOgcApi )
451+
{
452+
mDataSources.push_back( QStringLiteral( "OGCAPI:" ) );
453+
return;
454+
}
455+
447456
if ( interactive )
448457
{
449458
QMessageBox::information( this,
@@ -458,7 +467,7 @@ void QgsOgrSourceSelect::computeDataSources( bool interactive )
458467
QVariantMap parts;
459468
if ( !openOptions.isEmpty() )
460469
parts.insert( QStringLiteral( "openOptions" ), openOptions );
461-
parts.insert( QStringLiteral( "path" ), filePath );
470+
parts.insert( QStringLiteral( "path" ), mIsOgcApi ? QStringLiteral( "OGCAPI:%1" ).arg( filePath ) : filePath );
462471
mDataSources << QgsProviderRegistry::instance()->encodeUri( QStringLiteral( "ogr" ), parts );
463472
}
464473
}
@@ -526,6 +535,23 @@ void QgsOgrSourceSelect::radioSrcFile_toggled( bool checked )
526535
}
527536
}
528537

538+
void QgsOgrSourceSelect::radioSrcOgcApi_toggled( bool checked )
539+
{
540+
mIsOgcApi = checked;
541+
radioSrcFile_toggled( checked );
542+
if ( checked )
543+
{
544+
labelSrcDataset->setText( tr( "OGC API Endpoint" ) );
545+
mVectorPath = mFileWidget->filePath();
546+
emit enableButtons( ! mVectorPath.isEmpty() );
547+
fillOpenOptions();
548+
}
549+
else
550+
{
551+
labelSrcDataset->setText( tr( "Vector Dataset(s)" ) );
552+
}
553+
}
554+
529555
void QgsOgrSourceSelect::radioSrcDirectory_toggled( bool checked )
530556
{
531557
if ( checked )

‎src/gui/providers/ogr/qgsogrsourceselect.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ class QgsOgrSourceSelect : public QgsAbstractDataSourceWidget, private Ui::QgsOg
100100
void setProtocolWidgetsVisibility();
101101

102102
void radioSrcFile_toggled( bool checked );
103+
void radioSrcOgcApi_toggled( bool checked );
103104
void radioSrcDirectory_toggled( bool checked );
104105
void radioSrcDatabase_toggled( bool checked );
105106
void radioSrcProtocol_toggled( bool checked );
@@ -117,7 +118,7 @@ class QgsOgrSourceSelect : public QgsAbstractDataSourceWidget, private Ui::QgsOg
117118
void clearOpenOptions();
118119
void fillOpenOptions();
119120
std::vector<QWidget *> mOpenOptionsWidgets;
120-
121+
bool mIsOgcApi = false;
121122
QString mVectorPath;
122123

123124
};

‎src/ui/qgsgdalsourceselectbase.ui

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<x>0</x>
88
<y>0</y>
99
<width>355</width>
10-
<height>229</height>
10+
<height>501</height>
1111
</rect>
1212
</property>
1313
<property name="windowTitle">
@@ -52,6 +52,13 @@
5252
</property>
5353
</widget>
5454
</item>
55+
<item>
56+
<widget class="QRadioButton" name="radioSrcOgcApi">
57+
<property name="text">
58+
<string>OGC API</string>
59+
</property>
60+
</widget>
61+
</item>
5562
<item>
5663
<spacer name="horizontalSpacer">
5764
<property name="orientation">
@@ -81,7 +88,7 @@
8188
</property>
8289
<layout class="QHBoxLayout" name="horizontalLayout">
8390
<item>
84-
<widget class="QLabel" name="label">
91+
<widget class="QLabel" name="rasterDatasetLabel">
8592
<property name="text">
8693
<string>Raster dataset(s)</string>
8794
</property>
@@ -208,25 +215,25 @@
208215
</widget>
209216
</item>
210217
<item>
211-
<widget class="QgsCollapsibleGroupBox" name="mOpenOptionsGroupBox">
212-
<property name="title">
218+
<widget class="QgsCollapsibleGroupBox" name="mOpenOptionsGroupBox" native="true">
219+
<property name="title" stdset="0">
213220
<string>Options</string>
214221
</property>
215222
<layout class="QVBoxLayout" name="openOptionsVBoxLayout">
216-
<item>
217-
<widget class="QLabel" name="mOpenOptionsLabel">
218-
<property name="text">
219-
<string></string>
220-
</property>
221-
</widget>
222-
</item>
223-
<item>
224-
<layout class="QFormLayout" name="mOpenOptionsLayout">
225-
<property name="fieldGrowthPolicy">
226-
<enum>QFormLayout::AllNonFixedFieldsGrow</enum>
227-
</property>
228-
</layout>
229-
</item>
223+
<item>
224+
<widget class="QLabel" name="mOpenOptionsLabel">
225+
<property name="text">
226+
<string/>
227+
</property>
228+
</widget>
229+
</item>
230+
<item>
231+
<layout class="QFormLayout" name="mOpenOptionsLayout">
232+
<property name="fieldGrowthPolicy">
233+
<enum>QFormLayout::AllNonFixedFieldsGrow</enum>
234+
</property>
235+
</layout>
236+
</item>
230237
</layout>
231238
</widget>
232239
</item>
@@ -260,13 +267,20 @@
260267
<class>QgsFileWidget</class>
261268
<extends>QWidget</extends>
262269
<header>qgsfilewidget.h</header>
270+
<container>1</container>
263271
</customwidget>
264272
<customwidget>
265273
<class>QgsAuthSettingsWidget</class>
266274
<extends>QWidget</extends>
267275
<header>qgsauthsettingswidget.h</header>
268276
<container>1</container>
269277
</customwidget>
278+
<customwidget>
279+
<class>QgsCollapsibleGroupBox</class>
280+
<extends>QWidget</extends>
281+
<header>qgscollapsiblegroupbox.h</header>
282+
<container>1</container>
283+
</customwidget>
270284
</customwidgets>
271285
<tabstops>
272286
<tabstop>mOpenOptionsGroupBox</tabstop>

‎src/ui/qgsogrsourceselectbase.ui

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@
5151
<property name="geometry">
5252
<rect>
5353
<x>0</x>
54-
<y>-282</y>
55-
<width>508</width>
56-
<height>745</height>
54+
<y>0</y>
55+
<width>537</width>
56+
<height>757</height>
5757
</rect>
5858
</property>
5959
<layout class="QVBoxLayout" name="verticalLayout_5">
@@ -101,6 +101,13 @@
101101
</property>
102102
</widget>
103103
</item>
104+
<item>
105+
<widget class="QRadioButton" name="radioSrcOgcApi">
106+
<property name="text">
107+
<string>OGC API</string>
108+
</property>
109+
</widget>
110+
</item>
104111
<item>
105112
<spacer name="horizontalSpacer">
106113
<property name="orientation">
@@ -383,8 +390,8 @@
383390
</widget>
384391
</item>
385392
<item>
386-
<widget class="QgsCollapsibleGroupBox" name="mOpenOptionsGroupBox">
387-
<property name="title">
393+
<widget class="QgsCollapsibleGroupBox" name="mOpenOptionsGroupBox" native="true">
394+
<property name="title" stdset="0">
388395
<string>Options</string>
389396
</property>
390397
<layout class="QVBoxLayout" name="openOptionsVBoxLayout">
@@ -435,12 +442,6 @@
435442
</widget>
436443
<layoutdefault spacing="6" margin="11"/>
437444
<customwidgets>
438-
<customwidget>
439-
<class>QgsCollapsibleGroupBox</class>
440-
<extends>QGroupBox</extends>
441-
<header>qgscollapsiblegroupbox.h</header>
442-
<container>1</container>
443-
</customwidget>
444445
<customwidget>
445446
<class>QgsFileWidget</class>
446447
<extends>QWidget</extends>
@@ -453,6 +454,12 @@
453454
<header>qgsauthsettingswidget.h</header>
454455
<container>1</container>
455456
</customwidget>
457+
<customwidget>
458+
<class>QgsCollapsibleGroupBox</class>
459+
<extends>QWidget</extends>
460+
<header>qgscollapsiblegroupbox.h</header>
461+
<container>1</container>
462+
</customwidget>
456463
<customwidget>
457464
<class>QgsScrollArea</class>
458465
<extends>QScrollArea</extends>

0 commit comments

Comments
 (0)
Please sign in to comment.