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

Use fontfamily metadata more efficiently.

Wolthera van Hövell tot Westerfliereb4808066d0f
diff --git a/plugins/dockers/textproperties/TagFilterProxyModelQmlWrapper.cpp b/plugins/dockers/textproperties/TagFilterProxyModelQmlWrapper.cpp
index 82ae5af827..78d788aaab 100644
--- a/plugins/dockers/textproperties/TagFilterProxyModelQmlWrapper.cpp
+++ b/plugins/dockers/textproperties/TagFilterProxyModelQmlWrapper.cpp
@@ -144,20 +144,19 @@ void TagFilterProxyModelQmlWrapper::untagResource(const int &tagIndex, const int
}
}
-QString TagFilterProxyModelQmlWrapper::localizedNameForIndex(
- const int &resourceIndex,
+QString TagFilterProxyModelQmlWrapper::localizedNameFromMetadata(
+ const QMap<QString, QVariant> &metadata,
const QStringList &locales,
const QString &fallBack)
{
- QModelIndex resourceIdx = d->tagFilterProxyModel->index(resourceIndex, 0);
- QString name = fallBack;
- if (resourceIdx.isValid()) {
- name = d->tagFilterProxyModel->data(resourceIdx, Qt::UserRole + KisResourceModel::Name).toString();
- QMap<QString, QVariant> metadata = d->tagFilterProxyModel->data(resourceIdx, Qt::UserRole + KisResourceModel::MetaData).toMap();
- QVariantMap localizedNames = metadata.value("localized_font_family").toMap();
- Q_FOREACH(const QString locale, locales) {
- if (localizedNames.keys().contains(locale) ) {
- name = localizedNames.value(locale).toString();
+ 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);
+ Q_FOREACH(const QString key, localizedNames.keys()) {
+ if (QLocale(key) == l) {
+ name = localizedNames.value(key, name).toString();
break;
}
}
@@ -174,21 +173,17 @@ QVariantMap TagFilterProxyModelQmlWrapper::metadataForIndex(const int &resourceI
}
#include <KoWritingSystemUtils.h>
-QString TagFilterProxyModelQmlWrapper::localizedSampleForIndex(const int &resourceIndex, const QStringList &locales, const QString &fallBack)
+QString TagFilterProxyModelQmlWrapper::localizedSampleFromMetadata(const QMap<QString, QVariant> &metadata, const QStringList &locales, const QString &fallBack)
{
- QModelIndex resourceIdx = d->tagFilterProxyModel->index(resourceIndex, 0);
QString sample = fallBack;
- if (resourceIdx.isValid()) {
- QMap<QString, QVariant> metadata = d->tagFilterProxyModel->data(resourceIdx, Qt::UserRole + KisResourceModel::MetaData).toMap();
- QVariantMap samples = metadata.value("sample_svg").toMap();
- if (!samples.isEmpty()) sample = samples.value("s_Latn", samples.values().first()).toString();
- if (!locales.isEmpty()) {
- Q_FOREACH(const QString locale, locales) {
- const QString tag = KoWritingSystemUtils::sampleTagForQLocale(QLocale (locale));
- if (samples.keys().contains(tag) ) {
- sample = samples.value(tag).toString();
- break;
- }
+ QVariantMap samples = metadata.value("sample_svg").toMap();
+ if (!samples.isEmpty()) sample = samples.value("s_Latn", samples.values().first()).toString();
+ if (!locales.isEmpty()) {
+ Q_FOREACH(const QString locale, locales) {
+ const QString tag = KoWritingSystemUtils::sampleTagForQLocale(QLocale (locale));
+ if (samples.keys().contains(tag) ) {
+ sample = samples.value(tag).toString();
+ break;
}
}
}
diff --git a/plugins/dockers/textproperties/TagFilterProxyModelQmlWrapper.h b/plugins/dockers/textproperties/TagFilterProxyModelQmlWrapper.h
index 7f7bc5fef3..c2d9a6f5e7 100644
--- a/plugins/dockers/textproperties/TagFilterProxyModelQmlWrapper.h
+++ b/plugins/dockers/textproperties/TagFilterProxyModelQmlWrapper.h
@@ -64,11 +64,11 @@ public:
Q_INVOKABLE void untagResource(const int &tagIndex, const int &resourceIndex);
/// Get localized name for index, retrieved from the resource metadata.
- Q_INVOKABLE QString localizedNameForIndex(const int &resourceIndex, const QStringList &locales, const QString &fallBack = "");
+ Q_INVOKABLE static QString localizedNameFromMetadata(const QMap<QString, QVariant> &metadata, const QStringList &locales, const QString &fallBack = "");
Q_INVOKABLE QVariantMap metadataForIndex(const int &resourceIndex) const;
/// Get localized sample string based on scripts of locale.
- Q_INVOKABLE QString localizedSampleForIndex(const int &resourceIndex, const QStringList &locales, const QString &fallBack = "");
+ Q_INVOKABLE static QString localizedSampleFromMetadata(const QMap<QString, QVariant> &metadata, const QStringList &locales, const QString &fallBack = "");
/// Get a variantlist with the tags for the given resource index.
Q_INVOKABLE QVariantList taggedResourceModel (const int &resourceIndex) const;
diff --git a/plugins/dockers/textproperties/qml/FontResourceDropdown.qml b/plugins/dockers/textproperties/qml/FontResourceDropdown.qml
index b5bdf9f272..77e77c99f6 100644
--- a/plugins/dockers/textproperties/qml/FontResourceDropdown.qml
+++ b/plugins/dockers/textproperties/qml/FontResourceDropdown.qml
@@ -38,16 +38,16 @@ Button {
id: fontDelegateItem;
required property var model;
property string fontName: model.name;
+ property var meta: familyCmb.modelWrapper.metadataForIndex(model.index);
// TODO: change this to use the text locale, if possible.
- property string sample: familyCmb.modelWrapper.localizedSampleForIndex(model.index, locales, "");
+ property string sample: familyCmb.modelWrapper.localizedSampleFromMetadata(meta, locales, "");
/// When updating the model wrapper, the "model" doesn't always update on the delegate, so we need to manually load
/// the metadata from the modelwrapper.
- property var meta: familyCmb.modelWrapper.metadataForIndex(model.index);
width: fontResourceView.listWidth;
highlighted: familyCmb.highlightedIndex === model.index;
Component.onCompleted: {
- fontName = familyCmb.modelWrapper.localizedNameForIndex(model.index, locales, model.name);
+ fontName = familyCmb.modelWrapper.localizedNameFromMetadata(meta, locales, model.name);
}
contentItem: KoShapeQtQuickLabel {
@@ -167,6 +167,7 @@ Button {
onHoveredChanged: familyCmb.highlightedIndex = fontDelegateItem.model.index;
function openContextMenu(x, y) {
+ tagActionsContextMenu.resourceName = fontDelegateItem.model.name;
tagActionsContextMenu.resourceIndex = fontDelegateItem.model.index;
tagActionsContextMenu.popup()
}
@@ -229,7 +230,7 @@ Button {
property var resourceTaggedModel : [];
enabled: resourceIndex >= 0;
onResourceIndexChanged: {
- resourceName = modelWrapper.localizedNameForIndex(resourceIndex, locales);
+ resourceName = modelWrapper.localizedNameFromMetadata(modelWrapper.metadataForIndex(tagActionsContextMenu.resourceIndex), locales, resourceName);
updateResourceTaggedModel();
}
function updateResourceTaggedModel() {