Commit 288a5e2a authored by Boudewijn Rempt's avatar Boudewijn Rempt

Fix determining the format for a color value

QVariant::canConvert and QVariant::convert are not suitable here,
so check for the type. This fixes loading color generator layers.

BUG:390033
parent 7b87e02d
......@@ -95,20 +95,22 @@ void KisPropertiesConfiguration::fromXML(const QDomElement& e)
QString type = e.attribute("type");
QString name = e.attribute("name");
QString value = e.text();
if(type == "bytearray")
{
if (type == "bytearray") {
d->properties[name] = QVariant(QByteArray::fromBase64(value.toLatin1()));
}
else
else {
d->properties[name] = value;
}
}
else
else {
d->properties[e.attribute("name")] = QVariant(e.text());
}
}
}
n = n.nextSibling();
}
//dump();
dump();
}
void KisPropertiesConfiguration::toXML(QDomDocument& doc, QDomElement& root) const
......@@ -258,16 +260,18 @@ KisCubicCurve KisPropertiesConfiguration::getCubicCurve(const QString & name, co
KoColor KisPropertiesConfiguration::getColor(const QString& name, const KoColor& color) const
{
QVariant v = getProperty(name);
if (v.isValid()) {
if (v.canConvert<QColor>()) {
QColor c = v.value<QColor>();
KoColor kc(c, KoColorSpaceRegistry::instance()->rgb8());
return kc;
}
else if (v.type() == QVariant::UserType && v.userType() == qMetaTypeId<KoColor>()) {
return v.value<KoColor>();
switch(v.type()) {
case QVariant::UserType:
{
if (v.userType() == qMetaTypeId<KoColor>()) {
return v.value<KoColor>();
}
break;
}
else if (v.canConvert<QString>()) {
case QVariant::String:
{
QDomDocument doc;
if (doc.setContent(v.toString())) {
QDomElement e = doc.documentElement().firstChild().toElement();
......@@ -284,13 +288,25 @@ KoColor KisPropertiesConfiguration::getColor(const QString& name, const KoColor&
return kc;
}
}
break;
}
else if (v.canConvert<int>()) {
case QVariant::Color:
{
QColor c = v.value<QColor>();
KoColor kc(c, KoColorSpaceRegistry::instance()->rgb8());
return kc;
}
case QVariant::Int:
{
QColor c(v.toInt());
if (c.isValid()) {
KoColor kc(c, KoColorSpaceRegistry::instance()->rgb8());
return kc;
}
break;
}
default:
;
}
}
return color;
......@@ -300,7 +316,7 @@ void KisPropertiesConfiguration::dump() const
{
QMap<QString, QVariant>::Iterator it;
for (it = d->properties.begin(); it != d->properties.end(); ++it) {
dbgKrita << it.key() << " = " << it.value();
qDebug() << it.key() << " = " << it.value() << it.value().typeName();
}
}
......
......@@ -129,6 +129,7 @@ void KisPropertiesConfigurationTest::testGetColor()
pc.setProperty("colorAsKoColor", c);
pc.setProperty("colorAsQColor", QColor(Qt::red));
pc.setProperty("colorAsString", "#FF0000");
pc.setProperty("colorAsXML", "<!DOCTYPE color><color><RGB space=\"sRGB-elle-V2-g10.icc\" g=\"0\" b=\"0\" r=\"1\"/></color>");
kc = pc.getColor("colorAsKoColor");
QVERIFY(kc.toQColor() == QColor(Qt::red));
......@@ -136,7 +137,8 @@ void KisPropertiesConfigurationTest::testGetColor()
QVERIFY(kc.toQColor() == QColor(Qt::red));
kc = pc.getColor("colorAsString");
QVERIFY(kc.toQColor() == QColor(Qt::red));
kc = pc.getColor("colorAsXML");
QVERIFY(kc.toQColor() == QColor(Qt::red));
}
void roundTripStringList(const QStringList &refList)
......
......@@ -49,6 +49,7 @@ public:
/// Create a null KoColor. It will be valid, but all channels will be set to 0
explicit KoColor(const KoColorSpace * colorSpace);
/// Create a KoColor from a QColor. The QColor is immediately converted to native. The QColor
/// is assumed to have the current monitor profile.
KoColor(const QColor & color, const KoColorSpace * colorSpace);
......
......@@ -227,7 +227,7 @@ bool KisKraLoadVisitor::visit(KisAdjustmentLayer* layer)
return result;
}
bool KisKraLoadVisitor::visit(KisGeneratorLayer* layer)
bool KisKraLoadVisitor::visit(KisGeneratorLayer *layer)
{
if (!loadMetaData(layer)) {
return false;
......@@ -235,12 +235,9 @@ bool KisKraLoadVisitor::visit(KisGeneratorLayer* layer)
bool result = true;
loadNodeKeyframes(layer);
result = loadSelection(getLocation(layer), layer->internalSelection());
result = loadFilterConfiguration(layer->filter().data(), getLocation(layer, DOT_FILTERCONFIG));
layer->update();
result = visitAll(layer);
return result;
}
......@@ -544,7 +541,6 @@ bool KisKraLoadVisitor::loadFilterConfiguration(KisFilterConfigurationSP kfc, co
bool KisKraLoadVisitor::loadMetaData(KisNode* node)
{
dbgFile << "Load metadata for " << node->name();
KisLayer* layer = qobject_cast<KisLayer*>(node);
if (!layer) return true;
......@@ -554,7 +550,7 @@ bool KisKraLoadVisitor::loadMetaData(KisNode* node)
if (backend)
dbgFile << "Backend " << backend->id() << " does not support loading.";
else
dbgFile << "Could not load the XMP backenda t all";
dbgFile << "Could not load the XMP backend at all";
return true;
}
......
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