Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nominatim Geocoder Locator filter - add countryCodes configuration option #60719

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
29 changes: 29 additions & 0 deletions src/app/locator/qgsnominatimlocatorfilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

#include "qgsnominatimlocatorfilter.h"
#include "moc_qgsnominatimlocatorfilter.cpp"
#include "qgsgeocoder.h"
#include "qgslocatorfilter.h"
#include "qgssettings.h"
#include "qgsmessagebaritem.h"
#include "qgsmessagebar.h"
Expand Down Expand Up @@ -50,3 +52,30 @@ void QgsNominatimLocatorFilter::triggerResult( const QgsLocatorResult &result )
}
QgsGeocoderLocatorFilter::triggerResult( result );
}

void QgsNominatimLocatorFilter::openConfigWidget( QWidget *parent )
{
auto dlg = std::make_unique<QDialog>( parent );
dlg->setWindowTitle( "Nominatim Geocoder Country Codes" );

QGridLayout *formLayout = new QGridLayout;
QLineEdit *countryCodesEdit = new QLineEdit( dlg.get() );

// Load existing settings
QgsSettings settings;
countryCodesEdit->setText( settings.value( "locator_filters/nominatim_geocoder/country_codes", "", QgsSettings::App ).toString() );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe use new settings tree API here and in other places?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't know, I used the code from other Locator filters as example. Like this


I can check this, but not sure what will be better. Is approach I used deprecated?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not deprecated, but IMHO for new code we should use new API. Also with this API new setting will be nicely exposed in the advanced settings editor.


formLayout->addRow( tr( "Two letter Country Codes (comma-separated)" ), countryCodesEdit );
QDialogButtonBox *buttonbBox = new QDialogButtonBox( QDialogButtonBox::Ok | QDialogButtonBox::Cancel, dlg.get() );
formLayout->addRow( buttonbBox );
dlg->setLayout( formLayout );

// Save settings when dialog accepted
connect( buttonbBox, &QDialogButtonBox::accepted, dlg.get(), [&]() {
settings.setValue( "locator_filters/nominatim_geocoder/country_codes", countryCodesEdit->text().trimmed(), QgsSettings::App );
dlg->accept();
} );

connect( buttonbBox, &QDialogButtonBox::rejected, dlg.get(), &QDialog::reject );
dlg->exec();
}
2 changes: 2 additions & 0 deletions src/app/locator/qgsnominatimlocatorfilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ class APP_EXPORT QgsNominatimLocatorFilter : public QgsGeocoderLocatorFilter
QgsNominatimLocatorFilter( QgsGeocoderInterface *geocoder, QgsMapCanvas *canvas );

void triggerResult( const QgsLocatorResult &result ) override;
bool hasConfigWidget() const override { return true; }
void openConfigWidget( QWidget *parent ) override;
};

#endif // QGSNOMINATIMLOCATORFILTERS_H
Loading