diff --git a/plugins/extensions/metadataeditor/kis_entry_editor.cc b/plugins/extensions/metadataeditor/kis_entry_editor.cc index a0af0f6d8a..046b471eb0 100644 --- a/plugins/extensions/metadataeditor/kis_entry_editor.cc +++ b/plugins/extensions/metadataeditor/kis_entry_editor.cc @@ -1,100 +1,105 @@ /* * Copyright (c) 2007,2010 Cyrille Berger * * This library is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "kis_entry_editor.h" #include #include #include #include #include #include struct KisEntryEditor::Private { - QObject* object; + QWidget* object; QString propertyName; KisMetaData::Store* store; QString key; QString structField; int arrayIndex; + KisMetaData::Value value() { KisMetaData::Value value = store->getEntry(key).value(); + if (value.type() == KisMetaData::Value::Structure && !structField.isEmpty()) { QMap structure = value.asStructure(); return structure[ structField ]; - } else if (value.isArray() && arrayIndex > -1) { + } + else if (value.isArray() && arrayIndex > -1) { QList array = value.asArray(); if (arrayIndex < array.size()) { return array[arrayIndex]; } else { return KisMetaData::Value(); } } return value; } void setValue(const QVariant& variant) { KisMetaData::Value& value = store->getEntry(key).value(); if (value.type() == KisMetaData::Value::Structure && !structField.isEmpty()) { QMap structure = value.asStructure(); value = structure[ structField ]; value.setVariant(variant); value.setStructureVariant(structField, variant); } else if (value.isArray() && arrayIndex > -1) { value.setArrayVariant(arrayIndex, variant); } else { value.setVariant(variant); } } }; -KisEntryEditor::KisEntryEditor(QObject* obj, KisMetaData::Store* store, QString key, QString propertyName, QString structField, int arrayIndex) : d(new Private) +KisEntryEditor::KisEntryEditor(QWidget* obj, KisMetaData::Store* store, QString key, QString propertyName, QString structField, int arrayIndex) + : d(new Private) { Q_ASSERT(obj); Q_ASSERT(store); d->object = obj; d->propertyName = propertyName; d->store = store; d->key = key; d->structField = structField; d->arrayIndex = arrayIndex; valueChanged(); } KisEntryEditor::~KisEntryEditor() { delete d; } void KisEntryEditor::valueChanged() { if (d->store->containsEntry(d->key)) { bool blocked = d->object->blockSignals(true); - d->object->setProperty(d->propertyName.toLatin1(), d->value().asVariant()); + KisMetaData::Value val = d->value(); + d->object->setProperty(d->propertyName.toLatin1(), val.asVariant()); d->object->blockSignals(blocked); } } void KisEntryEditor::valueEdited() { QVariant val = d->object->property(d->propertyName.toLatin1()); dbgMetaData << "Value edited: " << d->propertyName << val; d->setValue(val); emit valueHasBeenEdited(); } diff --git a/plugins/extensions/metadataeditor/kis_entry_editor.h b/plugins/extensions/metadataeditor/kis_entry_editor.h index 53fd109632..f10d38ee1f 100644 --- a/plugins/extensions/metadataeditor/kis_entry_editor.h +++ b/plugins/extensions/metadataeditor/kis_entry_editor.h @@ -1,47 +1,47 @@ /* * Copyright (c) 2007 Cyrille Berger * * This library is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef _KIS_ENTRY_EDITOR_H_ #define _KIS_ENTRY_EDITOR_H_ -#include +#include class QString; namespace KisMetaData { class Store; } class KisEntryEditor : public QObject { Q_OBJECT struct Private; public: - KisEntryEditor(QObject* obj, KisMetaData::Store* store, QString key, QString propertyName, QString structField, int arrayIndex); + KisEntryEditor(QWidget *obj, KisMetaData::Store* store, QString key, QString propertyName, QString structField, int arrayIndex); ~KisEntryEditor() override; public Q_SLOTS: void valueEdited(); void valueChanged(); Q_SIGNALS: void valueHasBeenEdited(); private: Private* const d; }; #endif diff --git a/plugins/extensions/metadataeditor/kis_meta_data_editor.cc b/plugins/extensions/metadataeditor/kis_meta_data_editor.cc index ba7f03669b..e24865b7e0 100644 --- a/plugins/extensions/metadataeditor/kis_meta_data_editor.cc +++ b/plugins/extensions/metadataeditor/kis_meta_data_editor.cc @@ -1,156 +1,159 @@ /* * Copyright (c) 2007,2010 Cyrille Berger * * This library is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "kis_meta_data_editor.h" #include #include #include #include #include #include #include #include #include #include #include #include "kis_entry_editor.h" #include #include "kis_meta_data_model.h" #include struct KisMetaDataEditor::Private { KisMetaData::Store* originalStore; KisMetaData::Store* store; QMultiHash entryEditors; }; KisMetaDataEditor::KisMetaDataEditor(QWidget* parent, KisMetaData::Store* originalStore) : KPageDialog(parent), d(new Private) { d->originalStore = originalStore; d->store = new KisMetaData::Store(*originalStore); QStringList files = KoResourcePaths::findAllResources("data", "kritaplugins/metadataeditor/*.xmlgui"); QMap widgets; widgets["dublincore.ui"] = new WdgDublinCore(this); widgets["exif.ui"] = new WdgExif(this); Q_FOREACH (const QString & file, files) { QFile xmlFile(file); xmlFile.open(QFile::ReadOnly); QString errMsg; int errLine, errCol; QDomDocument document; if (!document.setContent(&xmlFile, false, &errMsg, &errLine, &errCol)) { dbgMetaData << "Error reading XML at line" << errLine << " column" << errCol << " :" << errMsg; } QDomElement rootElement = document.documentElement(); if (rootElement.tagName() != "MetaDataEditor") { dbgMetaData << "Invalid XML file"; } const QString uiFileName = rootElement.attribute("uiFile"); const QString pageName = i18nc("metadata editor page", rootElement.attribute("name").toUtf8()); const QString iconName = rootElement.attribute("icon"); if (uiFileName == "") continue; QWidget *widget = widgets[uiFileName]; QDomNodeList list = rootElement.childNodes(); const int size = list.size(); for (int i = 0; i < size; ++i) { QDomElement elem = list.item(i).toElement(); if (elem.isNull() || elem.tagName() != "EntryEditor") continue; const QString editorName = elem.attribute("editorName"); const QString schemaUri = elem.attribute("schemaUri"); const QString entryName = elem.attribute("entryName"); const QString editorSignal = '2' + elem.attribute("editorSignal"); const QString propertyName = elem.attribute("propertyName"); const QString structureField = elem.attribute("structureField"); - bool ok; - int arrayIndex = elem.attribute("arrayIndex", "-1").toInt(&ok); - if (!ok) arrayIndex = -1; + int arrayIndex = 0; + if (elem.hasAttribute("arrayIndex")) { + bool ok; + arrayIndex = elem.attribute("arrayIndex", "0").toInt(&ok); + if (!ok) arrayIndex = 0; + } dbgMetaData << ppVar(editorName) << ppVar(arrayIndex); - QWidget* obj = widget->findChild(editorName); - if (obj) { + QWidget* metaDataEditorPage = widget->findChild(editorName); + if (metaDataEditorPage) { const KisMetaData::Schema* schema = KisMetaData::SchemaRegistry::instance()->schemaFromUri(schemaUri); if (schema) { if (!d->store->containsEntry(schema, entryName)) { dbgMetaData << " Store does not have yet entry :" << entryName << " in" << schemaUri << " ==" << schema->generateQualifiedName(entryName); } QString key = schema->generateQualifiedName(entryName); - KisEntryEditor* ee = new KisEntryEditor(obj, d->store, key, propertyName, structureField, arrayIndex); - connect(obj, editorSignal.toLatin1(), ee, SLOT(valueEdited())); + KisEntryEditor* ee = new KisEntryEditor(metaDataEditorPage, d->store, key, propertyName, structureField, arrayIndex); + connect(metaDataEditorPage, editorSignal.toLatin1(), ee, SLOT(valueEdited())); QList otherEditors = d->entryEditors.values(key); Q_FOREACH (KisEntryEditor* oe, otherEditors) { connect(ee, SIGNAL(valueHasBeenEdited()), oe, SLOT(valueChanged())); connect(oe, SIGNAL(valueHasBeenEdited()), ee, SLOT(valueChanged())); } d->entryEditors.insert(key, ee); } else { dbgMetaData << "Unknown schema :" << schemaUri; } } else { dbgMetaData << "Unknown object :" << editorName; } } xmlFile.close(); KPageWidgetItem *page = new KPageWidgetItem(widget, pageName); if (!iconName.isEmpty()) { page->setIcon(KisIconUtils::loadIcon(iconName)); } addPage(page); } // Add the list page QTableView* tableView = new QTableView; KisMetaDataModel* model = new KisMetaDataModel(d->store); tableView->setModel(model); tableView->verticalHeader()->setVisible(false); tableView->resizeColumnsToContents(); KPageWidgetItem *page = new KPageWidgetItem(tableView, i18n("List")); page->setIcon(KisIconUtils::loadIcon("format-list-unordered")); addPage(page); } KisMetaDataEditor::~KisMetaDataEditor() { Q_FOREACH (KisEntryEditor* e, d->entryEditors) { delete e; } delete d->store; delete d; } void KisMetaDataEditor::accept() { KPageDialog::accept(); d->originalStore->copyFrom(d->store); }