File indexing completed on 2025-01-05 03:58:36
0001 /* ============================================================ 0002 * 0003 * This file is a part of digiKam project 0004 * https://www.digikam.org 0005 * 0006 * Date : 2009-12-01 0007 * Description : world map widget library - Settings Management 0008 * 0009 * SPDX-FileCopyrightText: 2010-2024 by Gilles Caulier <caulier dot gilles at gmail dot com> 0010 * SPDX-FileCopyrightText: 2009-2011 by Michael G. Hansen <mike at mghansen dot de> 0011 * SPDX-FileCopyrightText: 2014 by Justus Schwartz <justus at gmx dot li> 0012 * 0013 * SPDX-License-Identifier: GPL-2.0-or-later 0014 * 0015 * ============================================================ */ 0016 0017 #include "mapwidget_p.h" 0018 0019 namespace Digikam 0020 { 0021 0022 void MapWidget::saveSettingsToGroup(KConfigGroup* const group) 0023 { 0024 GEOIFACE_ASSERT(group != nullptr); 0025 0026 if (!group) 0027 { 0028 return; 0029 } 0030 0031 if (!d->currentBackendName.isEmpty()) 0032 { 0033 group->writeEntry("Backend", d->currentBackendName); 0034 } 0035 0036 group->writeEntry("Center", getCenter().geoUrl()); 0037 group->writeEntry("Zoom", getZoom()); 0038 group->writeEntry("Preview Single Items", s->previewSingleItems); 0039 group->writeEntry("Preview Grouped Items", s->previewGroupedItems); 0040 group->writeEntry("Show numbers on items", s->showNumbersOnItems); 0041 group->writeEntry("Thumbnail Size", s->thumbnailSize); 0042 group->writeEntry("Thumbnail Grouping Radius", s->thumbnailGroupingRadius); 0043 group->writeEntry("Marker Grouping Radius", s->markerGroupingRadius); 0044 group->writeEntry("Show Thumbnails", s->showThumbnails); 0045 group->writeEntry("Mouse Mode", int(s->currentMouseMode)); 0046 0047 if (d->visibleExtraActions.testFlag(ExtraActionSticky)) 0048 { 0049 group->writeEntry("Sticky Mode State", d->actionStickyMode->isChecked()); 0050 } 0051 0052 for (int i = 0 ; i < d->loadedBackends.size() ; ++i) 0053 { 0054 d->loadedBackends.at(i)->saveSettingsToGroup(group); 0055 } 0056 } 0057 0058 void MapWidget::readSettingsFromGroup(const KConfigGroup* const group) 0059 { 0060 GEOIFACE_ASSERT(group != nullptr); 0061 0062 if (!group) 0063 { 0064 return; 0065 } 0066 0067 #ifdef HAVE_GEOLOCATION 0068 0069 setBackend(group->readEntry("Backend", "marble")); 0070 0071 #endif 0072 0073 // Options concerning the display of markers 0074 0075 d->actionPreviewSingleItems->setChecked(group->readEntry("Preview Single Items", true)); 0076 d->actionPreviewGroupedItems->setChecked(group->readEntry("Preview Grouped Items", true)); 0077 d->actionShowNumbersOnItems->setChecked(group->readEntry("Show numbers on items", true)); 0078 0079 setThumnailSize(group->readEntry("Thumbnail Size", 2*GeoIfaceMinThumbnailSize)); 0080 setThumbnailGroupingRadius(group->readEntry("Thumbnail Grouping Radius", 2*GeoIfaceMinThumbnailGroupingRadius)); 0081 setMarkerGroupingRadius(group->readEntry("Edit Grouping Radius", GeoIfaceMinMarkerGroupingRadius)); 0082 s->showThumbnails = group->readEntry("Show Thumbnails", s->showThumbnails); 0083 d->actionShowThumbnails->setChecked(s->showThumbnails); 0084 d->actionStickyMode->setChecked(group->readEntry("Sticky Mode State", d->actionStickyMode->isChecked())); 0085 0086 // let the backends load their settings 0087 0088 for (int i = 0 ; i < d->loadedBackends.size() ; ++i) 0089 { 0090 d->loadedBackends.at(i)->readSettingsFromGroup(group); 0091 } 0092 0093 // current map state 0094 0095 const GeoCoordinates centerDefault = GeoCoordinates(52.0, 6.0); 0096 const QString centerGeoUrl = group->readEntry("Center", centerDefault.geoUrl()); 0097 bool centerGeoUrlValid = false; 0098 const GeoCoordinates centerCoordinate = GeoCoordinates::fromGeoUrl(centerGeoUrl, ¢erGeoUrlValid); 0099 d->cacheCenterCoordinate = centerGeoUrlValid ? centerCoordinate : centerDefault; 0100 d->cacheZoom = group->readEntry("Zoom", d->cacheZoom); 0101 s->currentMouseMode = GeoMouseModes(group->readEntry("Mouse Mode", int(s->currentMouseMode))); 0102 0103 // propagate the loaded values to the map, if appropriate 0104 0105 applyCacheToBackend(); 0106 slotUpdateActionsEnabled(); 0107 } 0108 0109 void MapWidget::slotItemDisplaySettingsChanged() 0110 { 0111 s->previewSingleItems = d->actionPreviewSingleItems->isChecked(); 0112 s->previewGroupedItems = d->actionPreviewGroupedItems->isChecked(); 0113 s->showNumbersOnItems = d->actionShowNumbersOnItems->isChecked(); 0114 0115 /// @todo Update action availability? 0116 0117 /// @todo We just need to update the display, no need to recluster? 0118 0119 slotRequestLazyReclustering(); 0120 } 0121 0122 void MapWidget::slotApplySettings() 0123 { 0124 GeolocationSettings::instance()->registerWidget(this); 0125 } 0126 0127 } // namespace Digikam 0128