Krita Source Code Documentation
Loading...
Searching...
No Matches
KisResourceMetaDataModel.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2025 Dmitry Kazakov <dimula73@gmail.com>
3 *
4 * SPDX-License-Identifier: LGPL-2.0-or-later
5 */
7
8#include <QtSql>
9
11{
12 QSqlQuery query;
13 bool isQueryPrepared = false;
14};
15
17 : m_d(new Private)
18{
19 m_d->query.setForwardOnly(true);
20
21 m_d->isQueryPrepared =
22 m_d->query.prepare(
23 "SELECT value\n"
24 "FROM metadata\n"
25 "WHERE foreign_id = :id\n"
26 "AND table_name = :table\n"
27 "AND key = :key\n"
28 "LIMIT 1");
29
30 if (!m_d->isQueryPrepared) {
31 qWarning() << "Could not prepare metadata query" << m_d->query.lastError();
32 return;
33 } else {
34 m_d->query.bindValue(":table", tableName);
35 }
36}
37
41
42QVariant KisResourceMetaDataModel::metaDataValue(int resourceId, const QString &key)
43{
44 QVariant resultValue;
45
46 if (!m_d->isQueryPrepared) return resultValue;
47
48 m_d->query.bindValue(":id", resourceId);
49 m_d->query.bindValue(":key", key);
50
51 if (!m_d->query.exec()) {
52 qWarning() << "Could not execute metadata query" << m_d->query.lastError();
53 return resultValue;
54 }
55
56 if (m_d->query.size() > 1) {
57 qWarning() << "Found duplicated entries for metadata for resource" << resourceId << "and key" << key;
58 }
59
60 if (m_d->query.first()) {
61 QByteArray ba = m_d->query.value(0).toByteArray();
62 if (!ba.isEmpty()) {
63 QDataStream ds(QByteArray::fromBase64(ba));
64 QVariant value;
65 ds >> value;
66 resultValue = value;
67 }
68 }
69
70 return resultValue;
71}
float value(const T *src, size_t ch)
KisResourceMetaDataModel(const QString &tableName)
QVariant metaDataValue(int resourceId, const QString &key)
QScopedPointer< Private > m_d