digiKam
similaritydb.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 : 2017-07-07
7  * Description : Similarity database interface.
8  *
9  * Copyright (C) 2009 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de>
10  * Copyright (C) 2009-2017 by Gilles Caulier <caulier dot gilles at gmail dot com>
11  * Copyright (C) 2017 by Swati Lodha <swatilodha27 at gmail dot com>
12  * Copyright (C) 2018 by Mario Frank <mario dot frank at uni minus potsdam dot de>
13  *
14  * This program is free software; you can redistribute it
15  * and/or modify it under the terms of the GNU General
16  * Public License as published by the Free Software Foundation;
17  * either version 2, or (at your option)
18  * any later version.
19  *
20  * This program is distributed in the hope that it will be useful,
21  * but WITHOUT ANY WARRANTY; without even the implied warranty of
22  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23  * GNU General Public License for more details.
24  *
25  * ============================================================ */
26 
27 #ifndef DIGIKAM_SIMILARITY_DB_H
28 #define DIGIKAM_SIMILARITY_DB_H
29 
30 // Qt includes
31 
32 #include <QStringList>
33 #include <QString>
34 #include <QList>
35 #include <QPair>
36 #include <QSet>
37 
38 // Local includes
39 
40 #include "dbenginesqlquery.h"
41 #include "similaritydbbackend.h"
42 #include "similaritydbaccess.h"
43 #include "digikam_export.h"
44 #include "iteminfo.h"
45 
46 namespace Digikam
47 {
48 
49 enum class FuzzyAlgorithm
50 {
51  Unknown = 0,
52  Haar = 1,
53  TfIdf = 2
54 };
55 
56 
57 class DIGIKAM_DATABASE_EXPORT SimilarityDb
58 {
59 public:
60 
67  bool setSetting(const QString& keyword, const QString& value);
68 
74  QString getSetting(const QString& keyword);
75 
81  QString getLegacySetting(const QString& keyword);
82 
87  QSet<qlonglong> registeredImageIds() const;
88 
89  // ----------- Methods for fingerprint (ImageHaarMatrix) table access ----------
90 
98  bool hasFingerprint(qlonglong imageId, FuzzyAlgorithm algorithm) const;
99 
104  bool hasFingerprints();
105 
111  bool hasFingerprints(FuzzyAlgorithm algorithm) const;
112 
120  bool hasDirtyOrMissingFingerprint(const ItemInfo& imageInfo,
121  FuzzyAlgorithm algorithm = FuzzyAlgorithm::Haar) const;
122 
131  QList<qlonglong> getDirtyOrMissingFingerprints(const QList<ItemInfo>& imageInfos,
133 
142  QStringList getDirtyOrMissingFingerprintURLs(const QList<ItemInfo>& imageInfos,
144 
152  void removeImageFingerprint(qlonglong imageID,
154 
158  void copySimilarityAttributes(qlonglong srcId,
159  qlonglong destId);
160 
161  // ----------- Methods for image similarity table access ----------
162 
168  double getImageSimilarity(qlonglong imageID1,
169  qlonglong imageID2,
171 
172  void setImageSimilarity(qlonglong imageID1,
173  qlonglong imageID2,
174  double value,
176 
182  void removeImageSimilarity(qlonglong imageID,
184 
191  void removeImageSimilarity(qlonglong imageID1,
192  qlonglong imageID2,
194 
201  QList<FuzzyAlgorithm> getImageSimilarityAlgorithms(qlonglong imageID1,
202  qlonglong imageID2);
203 
204  // ----------- Database shrinking and integrity check methods ----------
205 
210  bool integrityCheck();
211 
215  void vacuum();
216 
217 private:
218 
226  QString getImageSimilarityOrdered(qlonglong imageID1,
227  qlonglong imageID2,
229 
237  QPair<qlonglong, qlonglong> orderIds(qlonglong id1, qlonglong id2);
238 
243  explicit SimilarityDb(SimilarityDbBackend* const backend);
244 
248  ~SimilarityDb();
249 
250 private:
251 
252  // Disable
253  SimilarityDb(const SimilarityDb&) = delete;
254  SimilarityDb& operator=(const SimilarityDb&) = delete;
255 
256  class Private;
257  Private* const d;
258 
259  friend class SimilarityDbAccess;
260 };
261 
262 } // namespace Digikam
263 
264 #endif // DIGIKAM_SIMILARITY_DB_H
Definition: iteminfo.h:78
Definition: similaritydbaccess.h:45
Definition: similaritydbbackend.h:40
Definition: similaritydb.h:58
qulonglong value
Definition: itemviewutilities.cpp:592
Definition: datefolderview.cpp:43
FuzzyAlgorithm
Definition: similaritydb.h:50