Skip to content

armgit / krita

Public Imported from GitHub
0

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++

Make the Font filter proxy model responsible for retrieving the correct name.

Wolthera van Hövell tot Westerflier4552f282832b
diff --git a/plugins/dockers/textproperties/TagFilterProxyModelQmlWrapper.cpp b/plugins/dockers/textproperties/TagFilterProxyModelQmlWrapper.cpp
index 2aede96df8..df154a1f0b 100644
--- a/plugins/dockers/textproperties/TagFilterProxyModelQmlWrapper.cpp
+++ b/plugins/dockers/textproperties/TagFilterProxyModelQmlWrapper.cpp
@@ -190,29 +190,6 @@ void TagFilterProxyModelQmlWrapper::untagResource(const int &tagIndex, const int
}
}
-QString TagFilterProxyModelQmlWrapper::localizedNameFromMetadata(
- const QMap<QString, QVariant> &metadata,
- const QStringList &locales,
- const QString &fallBack)
-{
- const QVariantMap localizedNames = metadata.value("localized_font_family").toMap();
- QString name = fallBack.isEmpty()? localizedNames.value("en").toString(): fallBack;
-
- Q_FOREACH(const QString locale, locales) {
- const QLocale l(locale);
- bool found = false;
- Q_FOREACH(const QString key, localizedNames.keys()) {
- if (QLocale(key) == l) {
- name = localizedNames.value(key, name).toString();
- found = true;
- break;
- }
- }
- if (found) break;
- }
- return name;
-}
-
#include <KoWritingSystemUtils.h>
QString TagFilterProxyModelQmlWrapper::localizedSampleFromMetadata(const QMap<QString, QVariant> &metadata, const QStringList &locales, const QString &fallBack)
{
@@ -364,6 +341,35 @@ FontFamilyTagFilterModel::FontFamilyTagFilterModel(QObject *parent)
{
}
+QVariant FontFamilyTagFilterModel::data(const QModelIndex &index, int role) const
+{
+ QModelIndex sourceIdx = mapToSource(index);
+ if (sourceIdx.isValid()) {
+ if (role == (Qt::UserRole + KisAbstractResourceModel::Name)) {
+ const int resourceId = sourceModel()->data(sourceIdx, Qt::UserRole + KisAbstractResourceModel::Id).toInt();
+ const QVariantMap localizedNames = KisResourceModelProvider::resourceMetadataModel()->metaDataValue(resourceId, "localized_font_family").toMap();
+ const QString fallBack = sourceModel()->data(sourceIdx, Qt::UserRole + KisAbstractResourceModel::Name).toString();
+ QString name = fallBack.isEmpty()? localizedNames.value("en").toString(): fallBack;
+
+ Q_FOREACH(const QLocale locale, KLocalizedString::languages()) {
+ bool found = false;
+ Q_FOREACH(const QString key, localizedNames.keys()) {
+ if (QLocale(key) == locale) {
+ name = localizedNames.value(key, name).toString();
+ found = true;
+ break;
+ }
+ }
+ if (found) break;
+ }
+ return name;
+ } else {
+ return sourceModel()->data(sourceIdx, role);
+ }
+ }
+ return QVariant();
+}
+
bool FontFamilyTagFilterModel::additionalResourceNameChecks(const QModelIndex &index, const KisResourceSearchBoxFilter *filter) const
{
bool match = false;
diff --git a/plugins/dockers/textproperties/TagFilterProxyModelQmlWrapper.h b/plugins/dockers/textproperties/TagFilterProxyModelQmlWrapper.h
index 319d229a23..eec292802e 100644
--- a/plugins/dockers/textproperties/TagFilterProxyModelQmlWrapper.h
+++ b/plugins/dockers/textproperties/TagFilterProxyModelQmlWrapper.h
@@ -76,9 +76,6 @@ public:
/// Untag the resource
Q_INVOKABLE void untagResource(const int &tagIndex, const int &resourceIndex);
- /// Get localized name for index, retrieved from the resource metadata.
- Q_INVOKABLE static QString localizedNameFromMetadata(const QMap<QString, QVariant> &metadata, const QStringList &locales, const QString &fallBack = "");
-
/// Get localized sample string based on scripts of locale.
Q_INVOKABLE static QString localizedSampleFromMetadata(const QMap<QString, QVariant> &metadata, const QStringList &locales, const QString &fallBack = "");
@@ -133,6 +130,8 @@ class FontFamilyTagFilterModel: public KisTagFilterResourceProxyModel {
public:
FontFamilyTagFilterModel(QObject *parent = nullptr);
+ QVariant data(const QModelIndex &index, int role) const override;
+
bool additionalResourceNameChecks(const QModelIndex &index, const KisResourceSearchBoxFilter *filter) const override;
};
diff --git a/plugins/dockers/textproperties/qml/FontResourceDropdown.qml b/plugins/dockers/textproperties/qml/FontResourceDropdown.qml
index bedc3e41ca..1fc5c906f5 100644
--- a/plugins/dockers/textproperties/qml/FontResourceDropdown.qml
+++ b/plugins/dockers/textproperties/qml/FontResourceDropdown.qml
@@ -156,7 +156,6 @@ Button {
function updateNameAndSample() {
if (typeof metadata == "undefined") return;
- fontName = modelWrapper.localizedNameFromMetadata(metadata, familyCmb.locales, name);
sample = modelWrapper.localizedSampleFromMetadata(metadata, familyCmb.locales, "");
}
diff --git a/plugins/dockers/textproperties/qml/ResourceView.qml b/plugins/dockers/textproperties/qml/ResourceView.qml
index ddb8e26ab5..4603f3d707 100644
--- a/plugins/dockers/textproperties/qml/ResourceView.qml
+++ b/plugins/dockers/textproperties/qml/ResourceView.qml
@@ -121,7 +121,6 @@ Control {
property var resourceTaggedModel : [];
enabled: resourceIndex >= 0;
onResourceIndexChanged: {
- resourceName = modelWrapper.localizedNameFromMetadata(modelWrapper.metadataForIndex(tagActionsContextMenu.resourceIndex), locales, resourceName);
updateResourceTaggedModel();
}
function updateResourceTaggedModel() {