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++
Simplify model wrapper further and fix more issues.
Wolthera van Hövell tot Westerflierc89fcd620a02
diff --git a/plugins/dockers/textproperties/TagFilterProxyModelQmlWrapper.cpp b/plugins/dockers/textproperties/TagFilterProxyModelQmlWrapper.cppindex 50a0835a5c..59f6bdc9eb 100644--- a/plugins/dockers/textproperties/TagFilterProxyModelQmlWrapper.cpp+++ b/plugins/dockers/textproperties/TagFilterProxyModelQmlWrapper.cpp@@ -20,10 +20,12 @@ struct TagFilterProxyModelQmlWrapper::Private {, tagModel(new KisTagModel(ResourceType::FontFamilies)), compressor(KisSignalCompressor(100, KisSignalCompressor::POSTPONE)){+ allResourceModel = KisResourceModelProvider::resourceModel(ResourceType::FontFamilies);tagFilterProxyModel->sort(KisAbstractResourceModel::Name);tagFilterProxyModel->setTagFilter(tagModel->tagForIndex(tagModel->index(0, 0)));}KisTagFilterResourceProxyModel *tagFilterProxyModel {nullptr};+ KisAllResourcesModel *allResourceModel {nullptr};KisTagModel *tagModel {nullptr};KisSignalCompressor compressor;QString currentSearchText;@@ -47,21 +49,6 @@ QAbstractItemModel *TagFilterProxyModelQmlWrapper::model() constreturn d->tagFilterProxyModel;}-QAbstractItemModel *TagFilterProxyModelQmlWrapper::sourceModel() const-{- return d->tagFilterProxyModel->sourceModel();-}--void TagFilterProxyModelQmlWrapper::setSourceModel(QAbstractItemModel *newSourceModel)-{- if (newSourceModel != d->tagFilterProxyModel->sourceModel()) {- d->tagFilterProxyModel->setSourceModel(newSourceModel);- emit sourceModelChanged();- emit modelChanged();- emit modelSortUpdated();- }-}-QAbstractItemModel *TagFilterProxyModelQmlWrapper::tagModel() const{return d->tagModel;@@ -180,6 +167,8 @@ QString TagFilterProxyModelQmlWrapper::localizedNameForIndex(QVariantMap TagFilterProxyModelQmlWrapper::metadataForIndex(const int &resourceIndex) const{QModelIndex resourceIdx = d->tagFilterProxyModel->index(resourceIndex, 0);+ // NOTE: KisTagFilterProxyModel has this weird thing where it switches between source models depending+ // on whether filtering by tag happens. This somehow causes index() to not always work.return d->tagFilterProxyModel->data(resourceIdx, Qt::UserRole + KisResourceModel::MetaData).toMap();}@@ -240,11 +229,8 @@ void TagFilterProxyModelQmlWrapper::setCurrentIndex(const int &index)void TagFilterProxyModelQmlWrapper::setResourceToFileName(const QString &filename){- QModelIndex index;KoResourceSP resource = d->currentResource;- KisAllResourcesModel *fontModel = dynamic_cast<KisAllResourcesModel*>(d->tagFilterProxyModel->sourceModel());- if (!fontModel) return;- QVector<KoResourceSP> resources = fontModel->resourcesForFilename(filename);+ QVector<KoResourceSP> resources = d->allResourceModel->resourcesForFilename(filename);if (!resources.isEmpty()) {resource = resources.first();}diff --git a/plugins/dockers/textproperties/TagFilterProxyModelQmlWrapper.h b/plugins/dockers/textproperties/TagFilterProxyModelQmlWrapper.hindex a2cf8c3146..0501e35d00 100644--- a/plugins/dockers/textproperties/TagFilterProxyModelQmlWrapper.h+++ b/plugins/dockers/textproperties/TagFilterProxyModelQmlWrapper.h@@ -19,7 +19,6 @@ class TagFilterProxyModelQmlWrapper : public QObject{Q_OBJECTQ_PROPERTY(QAbstractItemModel *model READ model NOTIFY modelChanged)- Q_PROPERTY(QAbstractItemModel *sourceModel READ sourceModel WRITE setSourceModel NOTIFY sourceModelChanged)Q_PROPERTY(QAbstractItemModel *tagModel READ tagModel NOTIFY tagModelChanged)Q_PROPERTY(QString searchText READ searchText WRITE setSearchText NOTIFY searchTextChanged)@@ -35,11 +34,6 @@ public:/// The tagfilterproxymodelQAbstractItemModel *model() const;- /// The source model.- QAbstractItemModel *sourceModel() const;- /// Set the source model on the tag filter proxy model.- void setSourceModel(QAbstractItemModel *newSourceModel);-/// Associated tagmodelQAbstractItemModel *tagModel() const;@@ -89,7 +83,6 @@ public:QString resourceFilename();Q_SIGNALS:- void sourceModelChanged();void modelChanged();void searchTextChanged();void activeTagChanged();diff --git a/plugins/dockers/textproperties/TextPropertiesDock.cpp b/plugins/dockers/textproperties/TextPropertiesDock.cppindex 0d6c06bb3b..7ced465d64 100644--- a/plugins/dockers/textproperties/TextPropertiesDock.cpp+++ b/plugins/dockers/textproperties/TextPropertiesDock.cpp@@ -95,7 +95,7 @@ struct TextPropertiesDock::PrivateKoSvgTextPropertiesModel *textModel {new KoSvgTextPropertiesModel()};FontStyleModel stylesModel;FontAxesModel axesModel;- KisAllResourcesModel *fontModel{nullptr};+ KisResourceModel *fontModel{nullptr};KisCanvasResourceProvider *provider{nullptr};};@@ -124,7 +124,7 @@ TextPropertiesDock::TextPropertiesDock()m_quickWidget->setPalette(this->palette());m_quickWidget->setMinimumHeight(100);- d->fontModel = KisResourceModelProvider::resourceModel(ResourceType::FontFamilies);+ d->fontModel = new KisResourceModel(ResourceType::FontFamilies);QList<QLocale> locales;QStringList wellFormedBCPNames;@@ -139,7 +139,6 @@ TextPropertiesDock::TextPropertiesDock()m_quickWidget->rootContext()->setContextProperty("textPropertiesModel", d->textModel);- m_quickWidget->rootContext()->setContextProperty("fontFamiliesModel", QVariant::fromValue(d->fontModel));m_quickWidget->rootContext()->setContextProperty("fontStylesModel", QVariant::fromValue(&d->stylesModel));m_quickWidget->rootContext()->setContextProperty("fontAxesModel", QVariant::fromValue(&d->axesModel));m_quickWidget->rootContext()->setContextProperty("locales", QVariant::fromValue(wellFormedBCPNames));diff --git a/plugins/dockers/textproperties/qml/FontFamily.qml b/plugins/dockers/textproperties/qml/FontFamily.qmlindex fbfe308ab5..e09c8550e8 100644--- a/plugins/dockers/textproperties/qml/FontFamily.qml+++ b/plugins/dockers/textproperties/qml/FontFamily.qml@@ -17,7 +17,6 @@ CollapsibleGroupProperty {"font-family, typeface, font, fallback");property var fontFamilies: [];- property var fontFamilyModel : [];onPropertiesUpdated: {blockSignals = true;@@ -52,7 +51,6 @@ CollapsibleGroupProperty {}FontResourceDropdown {id: mainFamilyCmb;- modelWrapper.sourceModel: fontFamilyModel;Layout.fillWidth: true;onActivated: {if (fontFamilies.length >0) {@@ -62,10 +60,14 @@ CollapsibleGroupProperty {}}function updateCurrentIndex() {- modelWrapper.setResourceToFileName(mainWindow.wwsFontFamilyName(fontFamilies[0]))+ var name = mainWindow.wwsFontFamilyName(fontFamilies[0]);+ if (name !== modelWrapper.resourceFilename) {+ modelWrapper.currentTag = 0;+ modelWrapper.currentIndex = -1;+ }+ modelWrapper.setResourceToFileName(name)}}-}onEnableProperty: properties.fontFamiliesState = KoSvgTextPropertiesModel.PropertySet;@@ -97,7 +99,6 @@ CollapsibleGroupProperty {property int dIndex: index;FontResourceDropdown {id: fontCmb;- modelWrapper.sourceModel: fontFamilyModel;Layout.fillWidth: true;onActivated: {fontFamilies[fontListDelegate.dIndex] = text;@@ -105,8 +106,9 @@ CollapsibleGroupProperty {Component.onCompleted: {if (fontListDelegate.dIndex === 0) {modelWrapper = mainFamilyCmb.modelWrapper;+ } else {+ updateCurrentIndex();}- updateCurrentIndex();}function updateCurrentIndex() {modelWrapper.setResourceToFileName(mainWindow.wwsFontFamilyName(fontFamilies[fontListDelegate.dIndex]))diff --git a/plugins/dockers/textproperties/qml/FontResourceDropdown.qml b/plugins/dockers/textproperties/qml/FontResourceDropdown.qmlindex 8aceed0afe..e30527f496 100644--- a/plugins/dockers/textproperties/qml/FontResourceDropdown.qml+++ b/plugins/dockers/textproperties/qml/FontResourceDropdown.qml@@ -51,18 +51,18 @@ Button {contentItem: KoShapeQtQuickLabel {id: fontFamilyDelegate;property alias meta: fontDelegateItem.meta;- property bool colorBitmap : meta.color_bitmap;- property bool colorCLRV0 : meta.color_clrv0;- property bool colorCLRV1 : meta.color_clrv1;- property bool colorSVG : meta.color_svg;- property bool isVariable : meta.is_variable;- property int type : meta.font_type;+ property bool colorBitmap : typeof meta.color_bitmap === 'boolean'? meta.color_bitmap: false;+ property bool colorCLRV0 : typeof meta.color_clrv0 === 'boolean'? meta.color_clrv0: false;+ property bool colorCLRV1 : typeof meta.color_clrv1 === 'boolean'? meta.color_clrv1: false;+ property bool colorSVG : typeof meta.color_svg === 'boolean'? meta.color_svg: false;+ property bool isVariable : typeof meta.is_variable === 'boolean'? meta.is_variable: false;+ property int type : typeof meta.font_type === 'number'? meta.font_type: 0;property string fontName: fontDelegateItem.fontName;width: parent.width;height: nameLabel.height * 5;imageScale: 3;imagePadding: nameLabel.height;- svgData: meta.sample_svg;+ svgData: typeof meta.sample_svg === 'string'? meta.sample_svg: "";foregroundColor: sysPalette.text;fullColor: colorBitmap || colorCLRV0 || colorCLRV1 || colorSVG;diff --git a/plugins/dockers/textproperties/qml/TextPropertyBaseList.qml b/plugins/dockers/textproperties/qml/TextPropertyBaseList.qmlindex 31dc5f02ba..c3cdd795ff 100644--- a/plugins/dockers/textproperties/qml/TextPropertyBaseList.qml+++ b/plugins/dockers/textproperties/qml/TextPropertyBaseList.qml@@ -107,7 +107,6 @@ ColumnLayout {FontSize {}FontFamily {- fontFamilyModel: fontFamiliesModel;}FontStyle {}