@@ -293,6 +293,32 @@ SettingsDialog::SettingsDialog(MainWindow *parent) :
293293 ui->cwKeyModeSelect ->addItem (tr (" Ultimate" ), CWKey::ULTIMATE);
294294 ui->cwKeyModeSelect ->setCurrentIndex (ui->cwKeyModeSelect ->findData (CWKey::IAMBIC_B));
295295
296+ tileServers.append ({" OpenStreetMap (Default, System Language)" , QJsonObject{}});
297+ tileServers.append ({" OpenStreetMap (English)" , QJsonObject{
298+ {" url" , " https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png" },
299+ {" options" , QJsonObject{{" attribution" , " © OpenStreetMap" }}},
300+ }});
301+ tileServers.append ({" OpenStreetMap (French)" , QJsonObject{
302+ {" url" , " https://{s}.tile.openstreetmap.fr/osmfr/{z}/{x}/{y}.png" },
303+ {" options" , QJsonObject{{" attribution" , " © OpenStreetMap" }}},
304+ }});
305+ tileServers.append ({" OpenStreetMap (German)" , QJsonObject{
306+ {" url" , " https://tile.openstreetmap.de/{z}/{x}/{y}.png" },
307+ {" options" , QJsonObject{{" attribution" , " © OpenStreetMap" }}},
308+ }});
309+
310+ ui->tileServerComboBox ->setEditable (true );
311+ for (const auto &pair : tileServers) {
312+ QString name = pair.first ;
313+ QJsonObject info = pair.second ;
314+ ui->tileServerComboBox ->addItem (name);
315+ }
316+ ui->tileServerComboBox ->addItem (" Custom" );
317+
318+ connect (ui->tileServerComboBox , QOverload<int >::of (&QComboBox::currentIndexChanged),
319+ this , &SettingsDialog::onTileServerComboBoxChanged);
320+ onTileServerComboBoxChanged (ui->tileServerComboBox ->currentIndex ());
321+
296322 /* disable WSJTX Multicast by default */
297323 joinMulticastChanged (false );
298324
@@ -301,6 +327,47 @@ SettingsDialog::SettingsDialog(MainWindow *parent) :
301327 readSettings ();
302328}
303329
330+ void SettingsDialog::onTileServerComboBoxChanged (int index)
331+ {
332+ bool isCustom = index == (ui->tileServerComboBox ->count () - 1 );
333+ QString configStr = settings.value (" tileServer/config" , " {}" ).toString ();
334+
335+ if (isCustom) {
336+ ui->tileOptionsTextEdit ->setReadOnly (false );
337+ ui->tileMapUrlLineEdit ->setReadOnly (false );
338+
339+ QJsonDocument info = QJsonDocument::fromJson (configStr.toUtf8 ());
340+ if (info.object ().isEmpty () || settings.value (" tileServer/index" , 0 ).toInt ()) {
341+ ui->tileMapUrlLineEdit ->setText (" " );
342+ ui->tileOptionsTextEdit ->setPlainText (" " );
343+ return ;
344+ };
345+
346+ QJsonObject obj = info.object ();
347+ ui->tileMapUrlLineEdit ->setText (obj.contains (" options" ) ? obj[" url" ].toString () : " " );
348+ ui->tileOptionsTextEdit ->setPlainText (obj.contains (" options" )
349+ ? QJsonDocument (obj[" options" ].toObject ()).toJson (QJsonDocument::Compact)
350+ : " " );
351+ return ;
352+ } else {
353+ ui->tileOptionsTextEdit ->setReadOnly (true );
354+ ui->tileMapUrlLineEdit ->setReadOnly (true );
355+ }
356+
357+ QJsonObject info = tileServers[index].second ;
358+ if (info.isEmpty ()) {
359+ ui->tileMapUrlLineEdit ->setText (" " );
360+ ui->tileOptionsTextEdit ->setPlainText (" " );
361+ return ;
362+ };
363+
364+ ui->tileMapUrlLineEdit ->setText (info.contains (" options" ) ? info[" url" ].toString () : " " );
365+ ui->tileOptionsTextEdit ->setPlainText (info.contains (" options" )
366+ ? QJsonDocument (info[" options" ].toObject ()).toJson (QJsonDocument::Compact)
367+ : " " );
368+ }
369+
370+
304371void SettingsDialog::save () {
305372 FCT_IDENTIFICATION;
306373
@@ -2401,6 +2468,21 @@ void SettingsDialog::readSettings()
24012468 ui->dateFormatCustomRadioButton ->setChecked (!dateSystemFormat);
24022469 ui->dateFormatStringEdit ->setText (locale.getSettingDateFormat ());
24032470
2471+ /* *************/
2472+ /* Online Map */
2473+ /* *************/
2474+
2475+ int index = settings.value (" tileServer/index" , 0 ).toInt ();
2476+ QString configStr = settings.value (" tileServer/config" , " {}" ).toString ();
2477+
2478+ if (index >= ui->tileServerComboBox ->count ()) index = 0 ;
2479+ if (index == 0 && !QJsonDocument::fromJson (configStr.toUtf8 ()).object ().isEmpty ()) {
2480+ /* For convenience, `default' and `custom' use the same index, but options was stored only for `custom'. */
2481+ ui->tileServerComboBox ->setCurrentIndex (ui->tileServerComboBox ->count () - 1 );
2482+ } else {
2483+ ui->tileServerComboBox ->setCurrentIndex (index);
2484+ }
2485+
24042486 /* *****************/
24052487 /* END OF Reading */
24062488 /* *****************/
@@ -2525,6 +2607,26 @@ void SettingsDialog::writeSettings()
25252607 locale.setSettingUseSystemDateFormat (systemDateChecked);
25262608 if ( !systemDateChecked )
25272609 locale.setSettingDateFormat (ui->dateFormatStringEdit ->text ());
2610+
2611+ /* *************/
2612+ /* Online Map */
2613+ /* *************/
2614+ int index = ui->tileServerComboBox ->currentIndex ();
2615+ bool isCustom = index == (ui->tileServerComboBox ->count () - 1 );
2616+
2617+ if (isCustom) {
2618+ settings.setValue (" tileServer/index" , 0 );
2619+ QJsonObject info = QJsonObject{
2620+ {" url" , ui->tileMapUrlLineEdit ->text ()},
2621+ {" options" , QJsonDocument::fromJson (ui->tileOptionsTextEdit ->toPlainText ().toUtf8 ()).object ()}
2622+ };
2623+ settings.setValue (" tileServer/config" , QJsonDocument (info).toJson (QJsonDocument::Compact));
2624+ return ;
2625+ }
2626+
2627+ settings.setValue (" tileServer/index" , index);
2628+ QJsonObject info = tileServers[index].second ;
2629+ settings.setValue (" tileServer/config" , QJsonDocument (info).toJson (QJsonDocument::Compact));
25282630}
25292631
25302632/* this function is called when user modify rig progile
0 commit comments