Commit 5f86c598 authored by Dmitry Kazakov's avatar Dmitry Kazakov

Fix loading of files with 'Box' transformation filter

Summary:
We have released Krita with new name for the Box filter,
so now we have two variants for the name of this filer,
which is used in different places.

This patch adds aliases support for KoGenericRegistry and
makes 'Box' to be a variant for 'NearestNeighbour'

BUG:395979

Test Plan:
0) Add the following section to kritarc
```
[KisToolTransform]
filterId=Box
```
1) Start Krita
2) Krita shouldn't crash
3) Also try for other filter ids: Bicubic, NearestNeighbor, Bilinear

Reviewers: #krita, rempt

Tags: #krita

Differential Revision: https://phabricator.kde.org/D13796
parent 0ce8ef8d
......@@ -25,6 +25,8 @@
#include <QString>
#include <QHash>
#include "kis_assert.h"
/**
* Base class for registry objects.
*
......@@ -73,8 +75,11 @@ public:
*/
void add(T item)
{
Q_ASSERT(item);
QString id = item->id();
KIS_SAFE_ASSERT_RECOVER_RETURN(item);
const QString id = item->id();
KIS_SAFE_ASSERT_RECOVER_NOOP(!m_aliases.contains(id));
if (m_hash.contains(id)) {
m_doubleEntries << value(id);
remove(id);
......@@ -89,7 +94,9 @@ public:
*/
void add(const QString &id, T item)
{
Q_ASSERT(item);
KIS_SAFE_ASSERT_RECOVER_RETURN(item);
KIS_SAFE_ASSERT_RECOVER_NOOP(!m_aliases.contains(id));
if (m_hash.contains(id)) {
m_doubleEntries << value(id);
remove(id);
......@@ -105,6 +112,17 @@ public:
m_hash.remove(id);
}
void addAlias(const QString &alias, const QString &id)
{
KIS_SAFE_ASSERT_RECOVER_NOOP(!m_hash.contains(alias));
m_aliases[alias] = id;
}
void removeAlias(const QString &alias)
{
m_aliases.remove(alias);
}
/**
* Retrieve the object from the registry based on the unique
* identifier string.
......@@ -123,7 +141,13 @@ public:
*/
bool contains(const QString &id) const
{
return m_hash.contains(id);
bool result = m_hash.contains(id);
if (!result && m_aliases.contains(id)) {
result = m_hash.contains(m_aliases.value(id));
}
return result;
}
/**
......@@ -132,7 +156,13 @@ public:
*/
const T value(const QString &id) const
{
return m_hash.value(id);
T result = m_hash.value(id);
if (!result && m_aliases.contains(id)) {
result = m_hash.value(m_aliases.value(id));
}
return result;
}
/**
......@@ -165,6 +195,7 @@ private:
private:
QHash<QString, T> m_hash;
QHash<QString, QString> m_aliases;
};
#endif
......@@ -193,15 +193,16 @@ KisFilterStrategyRegistry::~KisFilterStrategyRegistry()
KisFilterStrategyRegistry* KisFilterStrategyRegistry::instance()
{
if (!s_instance.exists()) {
s_instance->add(new KisBoxFilterStrategy);
s_instance->addAlias("Box", "NearestNeighbor");
s_instance->add(new KisHermiteFilterStrategy);
s_instance->add(new KisBicubicFilterStrategy);
s_instance->add(new KisBoxFilterStrategy);
s_instance->add(new KisBilinearFilterStrategy);
s_instance->add(new KisBellFilterStrategy);
s_instance->add(new KisBSplineFilterStrategy);
s_instance->add(new KisLanczos3FilterStrategy);
s_instance->add(new KisMitchellFilterStrategy);
}
return s_instance;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment