Krita is a free and open source cross-platform application that offers an end-to-end solution for creating digital art files from scratch built on the KDE and Qt frameworks.
C++
Add database migrations for new storage types, so font storage is added appropriately.
Wolthera van Hövell tot Westerflierff6a3d4208a7
diff --git a/libs/resources/KisResourceCacheDb.cpp b/libs/resources/KisResourceCacheDb.cppindex 377cc94361..8e8be7d731 100644--- a/libs/resources/KisResourceCacheDb.cpp+++ b/libs/resources/KisResourceCacheDb.cpp@@ -1421,6 +1421,46 @@ bool KisResourceCacheDb::addTags(KisResourceStorageSP storage, QString resourceTreturn true;}+bool KisResourceCacheDb::registerStorageType(const KisResourceStorage::StorageType storageType)+{+ // Check whether the type already exists+ const QString name = KisResourceStorage::storageTypeToUntranslatedString(storageType);++ {+ QSqlQuery q;+ if (!q.prepare("SELECT count(*)\n"+ "FROM storage_types\n"+ "WHERE name = :storage_type\n")) {+ qWarning() << "Could not prepare select from storage_types query" << q.lastError();+ return false;+ }+ q.bindValue(":storage_type", name);+ if (!q.exec()) {+ qWarning() << "Could not execute select from storage_types query" << q.lastError();+ return false;+ }+ q.first();+ int rowCount = q.value(0).toInt();+ if (rowCount > 0) {+ return true;+ }+ }+ // if not, add it+ QFile f(":/fill_storage_types.sql");+ if (f.open(QFile::ReadOnly)) {+ QString sql = f.readAll();+ QSqlQuery q(sql);+ q.addBindValue(name);+ if (!q.exec()) {+ qWarning() << "Could not insert" << name << q.lastError();+ return false;+ }+ return true;+ }+ qWarning() << "Could not open fill_storage_types.sql";+ return false;+}+bool KisResourceCacheDb::addStorage(KisResourceStorageSP storage, bool preinstalled){bool r = true;diff --git a/libs/resources/KisResourceCacheDb.h b/libs/resources/KisResourceCacheDb.hindex 685c0451cf..34778e80c8 100644--- a/libs/resources/KisResourceCacheDb.h+++ b/libs/resources/KisResourceCacheDb.h@@ -114,6 +114,12 @@ private:static bool addTag(const QString &resourceType, const QString storageLocation, KisTagSP tag);static bool addTags(KisResourceStorageSP storage, QString resourceType);+ /**+ * @brief registerStorageType registers this storage type in the database+ * @param storageType the enum value that represents the type+ * @return true if the type was registered or had already been registered+ */+ static bool registerStorageType(const KisResourceStorage::StorageType storageType);static bool addStorage(KisResourceStorageSP storage, bool preinstalled);static bool addStorageTags(KisResourceStorageSP storage);diff --git a/libs/resources/KisResourceLocator.cpp b/libs/resources/KisResourceLocator.cppindex 8ad4aa9cc3..cbe8c2cf3a 100644--- a/libs/resources/KisResourceLocator.cpp+++ b/libs/resources/KisResourceLocator.cpp@@ -1090,6 +1090,11 @@ void KisResourceLocator::findStorages()}d->storages[storage->location()] = storage;}++ // Add any missing storage types to the resource cache database.+ Q_FOREACH(const KisResourceStorage::StorageType &type, KisStoragePluginRegistry::instance()->storageTypes()) {+ KisResourceCacheDb::registerStorageType(type);+ }}QList<KisResourceStorageSP> KisResourceLocator::storages() constdiff --git a/libs/resources/KisResourceStorage.cpp b/libs/resources/KisResourceStorage.cppindex c5ae99ad28..343ef7db24 100644--- a/libs/resources/KisResourceStorage.cpp+++ b/libs/resources/KisResourceStorage.cpp@@ -65,6 +65,11 @@ void KisStoragePluginRegistry::addStoragePluginFactory(KisResourceStorage::Storam_storageFactoryMap[storageType] = factory;}+QList<KisResourceStorage::StorageType> KisStoragePluginRegistry::storageTypes() const+{+ return m_storageFactoryMap.keys();+}+KisStoragePluginRegistry *KisStoragePluginRegistry::instance(){return s_instance;diff --git a/libs/resources/KisResourceStorage.h b/libs/resources/KisResourceStorage.hindex 2fbb6a6b16..3f9b1f2db6 100644--- a/libs/resources/KisResourceStorage.h+++ b/libs/resources/KisResourceStorage.h@@ -304,6 +304,7 @@ public:virtual ~KisStoragePluginRegistry();void addStoragePluginFactory(KisResourceStorage::StorageType storageType, KisStoragePluginFactoryBase *factory);+ QList<KisResourceStorage::StorageType> storageTypes() const;static KisStoragePluginRegistry *instance();private:friend class KisResourceStorage;