@@ -321,10 +321,10 @@ void PeakDialog::handle_openWikiLink() {
321
321
* Creates a Google Maps search link based on the peak's name and sets it as the Google Maps link.
322
322
*/
323
323
void PeakDialog::handle_findMapsLink () {
324
- const QString sanitizedPeakName = urlSanitize (nameLineEdit-> text (), " +" );
325
- if (sanitizedPeakName .isEmpty ()) return ;
324
+ const QString sanitizedSearchString = createSanitizedSearchString ( " +" );
325
+ if (sanitizedSearchString .isEmpty ()) return ;
326
326
327
- const QString link = " https://www.google.com/maps/search/" + sanitizedPeakName ;
327
+ const QString link = " https://www.google.com/maps/search/" + sanitizedSearchString ;
328
328
mapsLineEdit->setText (link );
329
329
}
330
330
@@ -334,10 +334,10 @@ void PeakDialog::handle_findMapsLink() {
334
334
* Creates a Google Earth search link based on the peak's name and sets it as the Google Earth link.
335
335
*/
336
336
void PeakDialog::handle_findEarthLink () {
337
- const QString sanitizedPeakName = urlSanitize (nameLineEdit-> text (), " +" );
338
- if (sanitizedPeakName .isEmpty ()) return ;
337
+ const QString sanitizedSearchString = createSanitizedSearchString ( " +" );
338
+ if (sanitizedSearchString .isEmpty ()) return ;
339
339
340
- const QString link = " https://earth.google.com/web/search/" + sanitizedPeakName ;
340
+ const QString link = " https://earth.google.com/web/search/" + sanitizedSearchString ;
341
341
earthLineEdit->setText (link );
342
342
}
343
343
@@ -355,10 +355,10 @@ void PeakDialog::handle_findWikiLink() {
355
355
const QString website = tr (" en" ) + " .wikipedia.org" ;
356
356
357
357
if (Settings::googleApiKey.get ().isEmpty ()) {
358
- const QString sanitizedPeakName = urlSanitize (peakName, " _" );
359
- if (sanitizedPeakName .isEmpty ()) return ;
358
+ const QString sanitizedSearchString = createSanitizedSearchString ( " _" );
359
+ if (sanitizedSearchString .isEmpty ()) return ;
360
360
361
- const QString link = " https://" + website + " /wiki/" + sanitizedPeakName ;
361
+ const QString link = " https://" + website + " /wiki/" + sanitizedSearchString ;
362
362
wikiLineEdit->setText (link );
363
363
return ;
364
364
}
@@ -431,6 +431,26 @@ void PeakDialog::aboutToClose()
431
431
432
432
433
433
434
+ /* *
435
+ * Creates a search string from currently set peak name and, if present, region name and sanitizes
436
+ * it using the given replacement for spaces.
437
+ *
438
+ * @param spaceReplacement The string to replace spaces with.
439
+ * @return The sanitized search string, containing peak and region names.
440
+ */
441
+ QString PeakDialog::createSanitizedSearchString (const QString& spaceReplacement)
442
+ {
443
+ QString searchString = nameLineEdit->text ();
444
+
445
+ if (regionCombo->currentIndex () > 0 ) {
446
+ const ValidItemID regionID = selectableRegionIDs.at (regionCombo->currentIndex () - 1 );
447
+ const QString regionName = db.regionsTable .nameColumn .getValueFor (regionID).toString ();
448
+ searchString += " " + regionName;
449
+ }
450
+
451
+ return urlSanitize (searchString, spaceReplacement);
452
+ }
453
+
434
454
/* *
435
455
* Creates a URL for a Google Programmable Search Engine search for the given peak on the given
436
456
* website.
@@ -445,11 +465,8 @@ QUrl PeakDialog::createLinkSearchUrl(const Database& db, const QString& website,
445
465
{
446
466
QString searchString = peakName;
447
467
if (regionID.isValid ()) {
448
- const ItemID rangeID = db.regionsTable .rangeIDColumn .getValueFor (FORCE_VALID (regionID));
449
- if (rangeID.isValid ()) {
450
- const QString rangeName = db.rangesTable .nameColumn .getValueFor (FORCE_VALID (rangeID)).toString ();
451
- searchString += " " + rangeName;
452
- }
468
+ const QString regionName = db.regionsTable .nameColumn .getValueFor (FORCE_VALID (regionID)).toString ();
469
+ searchString += " " + regionName;
453
470
}
454
471
const QString sanitizedSearchString = urlSanitize (searchString, " +" );
455
472
0 commit comments