digiKam
abstractmarkertiler.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 : 2009-12-01
7  * Description : An abstract base class for tiling of markers
8  *
9  * Copyright (C) 2009-2022 by Gilles Caulier <caulier dot gilles at gmail dot com>
10  * Copyright (C) 2009-2011 by Michael G. Hansen <mike at mghansen dot de>
11  *
12  * This program is free software; you can redistribute it
13  * and/or modify it under the terms of the GNU General
14  * Public License as published by the Free Software Foundation;
15  * either version 2, or (at your option)
16  * any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * ============================================================ */
24 
25 #ifndef DIGIKAM_ABSTRACT_MARKER_TILER_H
26 #define DIGIKAM_ABSTRACT_MARKER_TILER_H
27 
28 // Qt includes
29 
30 #include <QBitArray>
31 #include <QObject>
32 #include <QPoint>
33 
34 // Local includes
35 
36 #include "tileindex.h"
37 #include "geoifacetypes.h"
38 #include "digikam_export.h"
39 #include "geogroupstate.h"
40 
41 namespace Digikam
42 {
43 
44 class DIGIKAM_EXPORT AbstractMarkerTiler : public QObject
45 {
46  Q_OBJECT
47 
48 public:
49 
50  enum TilerFlag
51  {
52  FlagNull = 0,
53  FlagMovable = 1
54  };
55 
56  Q_DECLARE_FLAGS(TilerFlags, TilerFlag)
57 
58 public:
59 
60  class ClickInfo
61  {
62  public:
63 
66  GeoGroupState groupSelectionState;
67  GeoMouseModes currentMouseMode;
68  };
69 
70 public:
71 
72  class Tile
73  {
74  public:
75 
76  explicit Tile();
77  ~Tile();
78 
79  public:
80 
81  Tile* getChild(const int linearIndex);
82 
83  Tile* addChild(const int linearIndex, Tile* tilePointer);
84 
88  void deleteChild(Tile* const childTile, const int knownLinearIndex = -1);
89 
90  bool childrenEmpty() const;
91 
95  int nextNonEmptyIndex(int linearIndex) const;
96 
97  private:
98 
99  // Disable
100  Tile(const Tile&) = delete;
101  Tile& operator=(const Tile&) = delete;
102 
103  private:
104 
105  static int maxChildCount();
106 
107  void prepareForChildren();
108 
109  private:
110 
111  QVector<Tile*> children;
112  QVector<int> nonEmptyIndices;
113  };
114 
115 public:
116 
118  {
119  public:
120 
121  NonEmptyIterator(AbstractMarkerTiler* const model, const int level);
122  NonEmptyIterator(AbstractMarkerTiler* const model, const int level, const TileIndex& startIndex, const TileIndex& endIndex);
123  NonEmptyIterator(AbstractMarkerTiler* const model, const int level, const GeoCoordinates::PairList& normalizedMapBounds);
124  ~NonEmptyIterator();
125 
126  bool atEnd() const;
127  TileIndex nextIndex();
128  TileIndex currentIndex() const;
129  AbstractMarkerTiler* model() const;
130 
131  private:
132 
133  bool initializeNextBounds();
134 
135  private:
136 
137  // Disable
138  NonEmptyIterator(const NonEmptyIterator&) = delete;
139  NonEmptyIterator& operator=(const NonEmptyIterator&) = delete;
140 
141  private:
142 
143  class Private;
144  Private* const d;
145  };
146 
147 public:
148 
149  explicit AbstractMarkerTiler(QObject* const parent = nullptr);
150  ~AbstractMarkerTiler() override;
151 
153  virtual TilerFlags tilerFlags() const;
154  virtual Tile* tileNew() = 0;
155  virtual void prepareTiles(const GeoCoordinates& upperLeft, const GeoCoordinates& lowerRight, int level) = 0;
156  virtual void regenerateTiles() = 0;
157  virtual Tile* getTile(const TileIndex& tileIndex, const bool stopIfEmpty) = 0;
158  virtual int getTileMarkerCount(const TileIndex& tileIndex) = 0;
159  virtual int getTileSelectedCount(const TileIndex& tileIndex) = 0;
160 
162  virtual QVariant getTileRepresentativeMarker(const TileIndex& tileIndex, const int sortKey) = 0;
163  virtual QVariant bestRepresentativeIndexFromList(const QList<QVariant>& indices, const int sortKey) = 0;
164  virtual QPixmap pixmapFromRepresentativeIndex(const QVariant& index, const QSize& size) = 0;
165  virtual bool indicesEqual(const QVariant& a, const QVariant& b) const = 0;
166  virtual GeoGroupState getTileGroupState(const TileIndex& tileIndex) = 0;
167  virtual GeoGroupState getGlobalGroupState() = 0;
168 
170  virtual void onIndicesClicked(const ClickInfo& clickInfo);
171  virtual void onIndicesMoved(const TileIndex::List& tileIndicesList, const GeoCoordinates& targetCoordinates,
172  const QPersistentModelIndex& targetSnapIndex);
173 
174  virtual void setActive(const bool state) = 0;
175  Tile* rootTile();
176  bool indicesEqual(const QIntList& a, const QIntList& b, const int upToLevel) const;
177  bool isDirty() const;
178  void setDirty(const bool state = true);
179  void resetRootTile();
180 
181 Q_SIGNALS:
182 
184  void signalThumbnailAvailableForIndex(const QVariant& index, const QPixmap& pixmap);
185 
186 private:
187 
188  class Private;
189  Private* const d;
190 };
191 
192 } // namespace Digikam
193 
194 Q_DECLARE_OPERATORS_FOR_FLAGS(Digikam::AbstractMarkerTiler::TilerFlags)
195 
196 #endif // DIGIKAM_ABSTRACT_MARKER_TILER_H
Definition: abstractmarkertiler.h:61
TileIndex::List tileIndicesList
Definition: abstractmarkertiler.h:64
GeoGroupState groupSelectionState
Definition: abstractmarkertiler.h:66
GeoMouseModes currentMouseMode
Definition: abstractmarkertiler.h:67
QVariant representativeIndex
Definition: abstractmarkertiler.h:65
Definition: abstractmarkertiler.h:118
Definition: abstractmarkertiler.h:73
Definition: abstractmarkertiler.h:45
virtual int getTileMarkerCount(const TileIndex &tileIndex)=0
virtual void setActive(const bool state)=0
void signalThumbnailAvailableForIndex(const QVariant &index, const QPixmap &pixmap)
virtual QVariant bestRepresentativeIndexFromList(const QList< QVariant > &indices, const int sortKey)=0
virtual bool indicesEqual(const QVariant &a, const QVariant &b) const =0
TilerFlag
Definition: abstractmarkertiler.h:51
bool indicesEqual(const QIntList &a, const QIntList &b, const int upToLevel) const
virtual GeoGroupState getTileGroupState(const TileIndex &tileIndex)=0
virtual QVariant getTileRepresentativeMarker(const TileIndex &tileIndex, const int sortKey)=0
these should be implemented for thumbnail handling
virtual int getTileSelectedCount(const TileIndex &tileIndex)=0
virtual void prepareTiles(const GeoCoordinates &upperLeft, const GeoCoordinates &lowerRight, int level)=0
virtual QPixmap pixmapFromRepresentativeIndex(const QVariant &index, const QSize &size)=0
virtual Tile * getTile(const TileIndex &tileIndex, const bool stopIfEmpty)=0
virtual void regenerateTiles()=0
virtual GeoGroupState getGlobalGroupState()=0
virtual Tile * tileNew()=0
Definition: geocoordinates.h:49
Definition: tileindex.h:45
Definition: datefolderview.cpp:43