File indexing completed on 2025-01-19 03:53:40

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 2007-03-22
0007  * Description : Building complex database SQL queries from search descriptions
0008  *
0009  * SPDX-FileCopyrightText: 2005      by Renchi Raju <renchi dot raju at gmail dot com>
0010  * SPDX-FileCopyrightText: 2007-2012 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de>
0011  * SPDX-FileCopyrightText: 2012-2024 by Gilles Caulier <caulier dot gilles at gmail dot com>
0012  *
0013  * SPDX-License-Identifier: GPL-2.0-or-later
0014  *
0015  * ============================================================ */
0016 
0017 #ifndef DIGIKAM_ITEM_QUERY_BUILDER_H
0018 #define DIGIKAM_ITEM_QUERY_BUILDER_H
0019 
0020 // Qt includes
0021 
0022 #include <QVariant>
0023 #include <QString>
0024 
0025 // Local includes
0026 
0027 #include "coredbsearchxml.h"
0028 #include "itemqueryposthooks.h"
0029 #include "digikam_export.h"
0030 
0031 class QUrl;
0032 
0033 namespace Digikam
0034 {
0035 
0036 class DIGIKAM_DATABASE_EXPORT ItemQueryBuilder
0037 {
0038 public:
0039 
0040     explicit ItemQueryBuilder();
0041 
0042     QString buildQuery(const QString& q, QList<QVariant>* boundValues, ItemQueryPostHooks* const hooks) const;
0043     QString buildQueryFromUrl(const QUrl& url, QList<QVariant>* boundValues) const;
0044     QString buildQueryFromXml(const QString& xml, QList<QVariant>* boundValues, ItemQueryPostHooks* const hooks) const;
0045     QString convertFromUrlToXml(const QUrl& url) const;
0046 
0047     /**
0048      * Use for special queries where ImageTagProperties table is JOIN'ed.
0049      * (Default: false)
0050      */
0051     void setImageTagPropertiesJoined(bool isJoined);
0052 
0053 public:
0054 
0055     static void addSqlOperator(QString& sql, SearchXml::Operator op, bool isFirst);
0056     static void addSqlRelation(QString& sql, SearchXml::Relation rel);
0057     static void addNoEffectContent(QString& sql, SearchXml::Operator op);
0058 
0059 protected:
0060 
0061     void buildGroup(QString& sql, SearchXmlCachingReader& reader,
0062                     QList<QVariant>* boundValues, ItemQueryPostHooks* const hooks) const;
0063     bool buildField(QString& sql, SearchXmlCachingReader& reader, const QString& name,
0064                     QList<QVariant>* boundValues, ItemQueryPostHooks* const hooks) const;
0065 
0066     QString possibleDate(const QString& str, bool& exact) const;
0067 
0068 protected:
0069 
0070     QString m_longMonths[12];
0071     QString m_shortMonths[12];
0072     bool    m_imageTagPropertiesJoined;
0073 };
0074 
0075 } // namespace Digikam
0076 
0077 #endif // DIGIKAM_ITEM_QUERY_BUILDER_H