File indexing completed on 2025-03-09 03:57:06

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 2010-05-19
0007  * Description : a db option key
0008  *
0009  * SPDX-FileCopyrightText: 2009-2012 by Andi Clemens <andi dot clemens at gmail dot com>
0010  *
0011  * SPDX-License-Identifier: GPL-2.0-or-later
0012  *
0013  * ============================================================ */
0014 
0015 #ifndef DIGIKAM_DB_KEYS_COLLECTION_H
0016 #define DIGIKAM_DB_KEYS_COLLECTION_H
0017 
0018 // Qt includes
0019 
0020 #include <QMap>
0021 
0022 // Local includes
0023 
0024 #include "parsesettings.h"
0025 
0026 namespace Digikam
0027 {
0028 
0029 typedef QMap<QString, QString> DbKeyIdsMap;
0030 
0031 /**
0032  * @brief A class for managing / grouping database keys.
0033  *
0034  * This class manages database keys and provides methods to get the
0035  * appropriate value from the database.
0036  */
0037 class DbKeysCollection
0038 {
0039 public:
0040 
0041     /**
0042      * Default constructor.
0043      *
0044      * @param n collection name
0045      */
0046     explicit DbKeysCollection(const QString& n);
0047     virtual ~DbKeysCollection();
0048 
0049     /**
0050      * Get a value from the database.
0051      * @param key           the key representing the value in the database
0052      * @param settings      the %ParseSettings object holding all relevant information
0053      *                      about the image.
0054      * @return  the value of the given database key
0055      */
0056     QString getValue(const QString& key, ParseSettings& settings);
0057 
0058     /**
0059      * Get all IDs associated with this key collection.
0060      * @return a map of all associated ids and their description
0061      */
0062     DbKeyIdsMap ids() const;
0063 
0064     /**
0065      * Get the name of the %DbKeysCollection
0066      * @return the name of the collection
0067      */
0068     QString collectionName() const;
0069 
0070 protected:
0071 
0072     /**
0073      * Abstract method for retrieving the value from the database for the given key.
0074      *
0075      * This method has to be implemented by all child classes. It is called by the
0076      * getValue() method.
0077      *
0078      * @param key           the key representing the value in the database
0079      * @param settings      the %ParseSettings object holding all relevant information
0080      *                      about the image.
0081      *
0082      * @return  the value of the given database key
0083      * @see DbKeysCollection::getValue()
0084      */
0085     virtual QString getDbValue(const QString& key, ParseSettings& settings) = 0;
0086 
0087     /**
0088      * Add an ID to the key collection.
0089      *
0090      * @param id            the id of the database key
0091      * @param description   a short description of the database key
0092      */
0093     void addId(const QString& id, const QString& description);
0094 
0095 private:
0096 
0097     DbKeyIdsMap idsMap;
0098     QString     name;
0099 
0100 private:
0101 
0102     DbKeysCollection(const DbKeysCollection&)            = delete;
0103     DbKeysCollection& operator=(const DbKeysCollection&) = delete;
0104 };
0105 
0106 } // namespace Digikam
0107 
0108 #endif // DIGIKAM_DB_KEYS_COLLECTION_H