digiKam
geoifacecommon.h
Go to the documentation of this file.
1 /* ============================================================
2  *
3  * This file is a part of digiKam project
4  * https://www.digikam.org
5  *
6  * Date : 2010-07-14
7  * Description : Common internal data structures for geolocation interface
8  *
9  * Copyright (C) 2010-2022 by Gilles Caulier <caulier dot gilles at gmail dot com>
10  * Copyright (C) 2010-2014 by Michael G. Hansen <mike at mghansen dot de>
11  * Copyright (C) 2014 by Justus Schwartz <justus at gmx dot li>
12  *
13  * This program is free software; you can redistribute it
14  * and/or modify it under the terms of the GNU General
15  * Public License as published by the Free Software Foundation;
16  * either version 2, or (at your option)
17  * any later version.
18  *
19  * This program is distributed in the hope that it will be useful,
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22  * GNU General Public License for more details.
23  *
24  * ============================================================ */
25 
26 #ifndef DIGIKAM_GEO_IFACE_COMMON_H
27 #define DIGIKAM_GEO_IFACE_COMMON_H
28 
29 // Qt includes
30 
31 #include <QFlags>
32 #include <QPoint>
33 #include <QPointer>
34 #include <QSharedData>
35 #include <QSize>
36 #include <QWidget>
37 #include <QPixmap>
38 
39 // Local includes
40 
41 #include "geoifacetypes.h"
42 #include "tileindex.h"
43 #include "groupstatecomputer.h"
44 #include "digikam_export.h"
45 
46 namespace Digikam
47 {
48 class MapWidget;
49 class AbstractMarkerTiler;
50 class TileGrouper;
51 class TrackManager;
52 class MapBackend;
53 class GeoModelHelper;
54 
60 class DIGIKAM_EXPORT GeoIfaceInternalWidgetInfo
61 {
62 public:
63 
64  typedef void (*DeleteFunction)(GeoIfaceInternalWidgetInfo* const info);
65 
67  {
68  InternalWidgetReleased = 1,
69  InternalWidgetUndocked = 2,
70  InternalWidgetStillDocked = 4
71  };
72 
73  // cppcheck-suppress unknownMacro
74  Q_DECLARE_FLAGS(InternalWidgetStates, InternalWidgetState)
75 
77  : state (),
78  widget (),
79  backendData (),
80  backendName (),
81  currentOwner (nullptr),
82  deleteFunction(nullptr)
83  {
84  }
85 
86 public:
87 
88  InternalWidgetStates state;
89  QPointer<QWidget> widget;
90  QVariant backendData;
91  QString backendName;
92  QPointer<QObject> currentOwner;
93  DeleteFunction deleteFunction;
94 };
95 
96 Q_DECLARE_OPERATORS_FOR_FLAGS(GeoIfaceInternalWidgetInfo::InternalWidgetStates)
97 
98 // ----------------------------------------------------------------------------------------------
99 
100 
104 class DIGIKAM_EXPORT GeoIfaceGlobalObject : public QObject
105 {
106  Q_OBJECT
107 
108 public:
109 
110  static GeoIfaceGlobalObject* instance();
111 
113 
114  QPixmap getMarkerPixmap(const QString& pixmapId);
115  QPixmap getStandardMarkerPixmap();
116  QUrl locateDataFile(const QString& filename);
118 
120 
121  void removeMyInternalWidgetFromPool(const MapBackend* const mapBackend);
122  bool getInternalWidgetFromPool(const MapBackend* const mapBackend, GeoIfaceInternalWidgetInfo* const targetInfo);
123  void addMyInternalWidgetToPool(const GeoIfaceInternalWidgetInfo& info);
124  void updatePooledWidgetState(const QWidget* const widget, const GeoIfaceInternalWidgetInfo::InternalWidgetState newState);
125  void clearWidgetPool();
127 
128 private:
129 
130  // Disable
131  explicit GeoIfaceGlobalObject(QObject*) = delete;
133  ~GeoIfaceGlobalObject() override;
134 
135  Q_DISABLE_COPY(GeoIfaceGlobalObject)
136 
137 private:
138 
139  class Private;
140  Private* const d;
141 
142  friend class GeoIfaceGlobalObjectCreator;
143 };
144 
145 // ----------------------------------------------------------------------------------------------
146 
147 class DIGIKAM_EXPORT GeoIfaceCluster
148 {
149 
150 public:
151 
153  {
156  PixmapImage
157  } pixmapType;
158 
160 
161 public:
162 
164  : pixmapType (PixmapMarker),
165  tileIndicesList (),
166  markerCount (0),
167  markerSelectedCount (0),
168  coordinates (),
169  pixelPos (),
170  groupState (SelectedNone),
171  representativeMarkers (),
172  pixmapSize (),
173  pixmapOffset ()
174  {
175  }
176 
181  QPoint pixelPos;
182  GeoGroupState groupState;
183  QMap<int, QVariant> representativeMarkers;
184 
185  QSize pixmapSize;
186 
188  QPoint pixmapOffset;
189 };
190 
191 // ----------------------------------------------------------------------------------------------
192 
197 
198 // ----------------------------------------------------------------------------------------------
199 
208 DIGIKAM_EXPORT int QPointSquareDistance(const QPoint& a, const QPoint& b);
209 
210 // ----------------------------------------------------------------------------------------------
211 
212 class DIGIKAM_EXPORT GeoIfaceSharedData : public QSharedData
213 {
214 public:
215 
217  : QSharedData (),
218  worldMapWidget (nullptr),
219  tileGrouper (nullptr),
220  markerModel (nullptr),
221  clusterList (),
222  trackManager (nullptr),
223  showThumbnails (true),
224  thumbnailSize (GeoIfaceMinThumbnailSize),
225  thumbnailGroupingRadius (GeoIfaceMinThumbnailGroupingRadius),
226  markerGroupingRadius (GeoIfaceMinMarkerGroupingRadius),
227  previewSingleItems (true),
228  previewGroupedItems (true),
229  showNumbersOnItems (true),
230  sortKey (0),
231  modificationsAllowed (true),
232  selectionRectangle (),
233  haveMovingCluster (false),
234  currentMouseMode (),
235  availableMouseModes (),
236  visibleMouseModes (),
237  activeState (false)
238  {
239  }
240 
242  bool hasRegionSelection() const
243  {
244  return selectionRectangle.first.hasCoordinates();
245  }
246 
247 public:
248 
250 
258 
260 
268  int sortKey;
271 
273 
276  GeoMouseModes currentMouseMode;
277  GeoMouseModes availableMouseModes;
278  GeoMouseModes visibleMouseModes;
281 };
282 
283 // ----------------------------------------------------------------------------------------------
284 
286 
287 DIGIKAM_EXPORT bool GeoIfaceHelperParseLatLonString(const QString& latLonString,
288  GeoCoordinates* const coordinates);
289 
290 DIGIKAM_EXPORT bool GeoIfaceHelperParseXYStringToPoint(const QString& xyString,
291  QPoint* const point);
292 
293 DIGIKAM_EXPORT bool GeoIfaceHelperParseBoundsString(const QString& boundsString,
294  QPair<GeoCoordinates, GeoCoordinates>* const boundsCoordinates);
295 
297 
298 DIGIKAM_EXPORT void GeoIface_assert(const char* const condition,
299  const char* const filename,
300  const int lineNumber);
301 
302 } // namespace Digikam
303 
304 #define GEOIFACE_ASSERT(cond) ((!(cond)) ? Digikam::GeoIface_assert(#cond,__FILE__,__LINE__) : qt_noop())
305 
306 #endif // DIGIKAM_GEO_IFACE_COMMON_H
Definition: abstractmarkertiler.h:45
Definition: geocoordinates.h:49
QPair< GeoCoordinates, GeoCoordinates > Pair
Definition: geocoordinates.h:64
Definition: geoifacecommon.h:148
PixmapType
Definition: geoifacecommon.h:153
@ PixmapMarker
Definition: geoifacecommon.h:154
@ PixmapCircle
Definition: geoifacecommon.h:155
QList< TileIndex > tileIndicesList
Definition: geoifacecommon.h:177
int markerCount
Definition: geoifacecommon.h:178
QSize pixmapSize
Definition: geoifacecommon.h:185
GeoIfaceCluster()
Definition: geoifacecommon.h:163
QPoint pixelPos
Definition: geoifacecommon.h:181
QMap< int, QVariant > representativeMarkers
Definition: geoifacecommon.h:183
GeoCoordinates coordinates
Definition: geoifacecommon.h:180
QPoint pixmapOffset
anchor point of the image, measured from bottom-left
Definition: geoifacecommon.h:188
int markerSelectedCount
Definition: geoifacecommon.h:179
GeoGroupState groupState
Definition: geoifacecommon.h:182
QList< GeoIfaceCluster > List
Definition: geoifacecommon.h:159
Global object for geolocation interface to hold items common to all geolocation interface Widget inst...
Definition: geoifacecommon.h:105
Class to hold information about map widgets stored in the GeoIfaceGlobalObject.
Definition: geoifacecommon.h:61
InternalWidgetStates state
Definition: geoifacecommon.h:88
QString backendName
Definition: geoifacecommon.h:91
QPointer< QObject > currentOwner
Definition: geoifacecommon.h:92
QPointer< QWidget > widget
Definition: geoifacecommon.h:89
QVariant backendData
Definition: geoifacecommon.h:90
DeleteFunction deleteFunction
Definition: geoifacecommon.h:93
InternalWidgetState
Definition: geoifacecommon.h:67
Definition: geoifacecommon.h:213
MapWidget * worldMapWidget
Definition: geoifacecommon.h:251
GeoIfaceSharedData()
Definition: geoifacecommon.h:216
GeoCoordinates::Pair selectionRectangle
Definition: geoifacecommon.h:274
AbstractMarkerTiler * markerModel
Definition: geoifacecommon.h:253
int thumbnailSize
Definition: geoifacecommon.h:262
bool hasRegionSelection() const
Definition: geoifacecommon.h:242
GeoIfaceCluster::List clusterList
Definition: geoifacecommon.h:254
bool previewGroupedItems
Definition: geoifacecommon.h:266
bool showThumbnails
Definition: geoifacecommon.h:261
GeoMouseModes currentMouseMode
Definition: geoifacecommon.h:276
TrackManager * trackManager
Definition: geoifacecommon.h:256
GeoMouseModes availableMouseModes
Definition: geoifacecommon.h:277
bool activeState
Definition: geoifacecommon.h:279
int sortKey
Definition: geoifacecommon.h:268
GeoMouseModes visibleMouseModes
Definition: geoifacecommon.h:278
QList< GeoModelHelper * > ungroupedModels
Definition: geoifacecommon.h:255
TileGrouper * tileGrouper
Definition: geoifacecommon.h:252
bool showNumbersOnItems
Definition: geoifacecommon.h:267
int markerGroupingRadius
Definition: geoifacecommon.h:264
int thumbnailGroupingRadius
Definition: geoifacecommon.h:263
bool modificationsAllowed
Definition: geoifacecommon.h:269
bool haveMovingCluster
Definition: geoifacecommon.h:275
bool previewSingleItems
Definition: geoifacecommon.h:265
Definition: mapbackend.h:52
The central map view class of geolocation interface.
Definition: mapwidget.h:58
Definition: tilegrouper.h:38
Definition: trackmanager.h:46
Definition: datefolderview.cpp:43
const int GeoIfaceMinMarkerGroupingRadius
Definition: geoifacecommon.h:194
const int GeoIfaceMinThumbnailSize
Definition: geoifacecommon.h:196
bool GeoIfaceHelperParseXYStringToPoint(const QString &xyString, QPoint *const point)
Parse a '(X.xxx,Y.yyy)' string as returned by the JavaScript parts.
Definition: geoifacecommon.cpp:177
void GeoIface_assert(const char *const condition, const char *const filename, const int lineNumber)
Definition: geoifacecommon.cpp:425
int QPointSquareDistance(const QPoint &a, const QPoint &b)
Helper function, returns the square of the distance between two points.
Definition: geoifacecommon.cpp:437
@ SelectedNone
Definition: geogroupstate.h:55
GeoCoordinates::PairList GeoIfaceHelperNormalizeBounds(const GeoCoordinates::Pair &boundsPair)
Split bounds crossing the dateline into parts which do not cross the dateline.
Definition: geoifacecommon.cpp:283
bool GeoIfaceHelperParseBoundsString(const QString &boundsString, QPair< GeoCoordinates, GeoCoordinates > *const boundsCoordinates)
Parses a '((lat1, lon1), (lat2, lon2))' bounds string as returned by the JavaScript parts.
Definition: geoifacecommon.cpp:225
const int GeoIfaceMinThumbnailGroupingRadius
Definition: geoifacecommon.h:195
bool GeoIfaceHelperParseLatLonString(const QString &latLonString, GeoCoordinates *const coordinates)
Parse a 'lat,lon' string a returned by the JavaScript parts.
Definition: geoifacecommon.cpp:143