[graphics/krita/krita/5.0] /: Metadata editor: reimplement entry handling

L. E. Segovia null at kde.org
Wed Aug 25 02:50:47 BST 2021


Git commit 8702bb9001eb09519e5b8f49d3634816f8db398d by L. E. Segovia.
Committed on 25/08/2021 at 01:48.
Pushed by lsegovia into branch 'krita/5.0'.

Metadata editor: reimplement entry handling

This commit implements entry handling based entirely on a few compile
time macros and Qt's newer signal/slot syntax.

This allows me to add support for flash metadata, which was
broken since at least 67b39577b6dc9e5f2e5e2885b2188cbd393c55f6.

While at it, add a default icon to the Dublin Core pane; the old one in
the xmlgui file was missing since forever.

BUG: 410341

CCMAIL: kimageshop at kde.org
(cherry picked from commit db407cd7993794ebb125ae63b720e11325f7365c)

M  +0    -6    Messages.sh
M  +0    -1    plugins/extensions/metadataeditor/CMakeLists.txt
M  +12   -30   plugins/extensions/metadataeditor/editors/dublincore.ui
D  +0    -33   plugins/extensions/metadataeditor/editors/dublincore.xmlgui
M  +4    -101  plugins/extensions/metadataeditor/editors/exif.ui
D  +0    -157  plugins/extensions/metadataeditor/editors/exif.xmlgui
M  +144  -99   plugins/extensions/metadataeditor/kis_meta_data_editor.cc
M  +1    -0    plugins/extensions/metadataeditor/kis_meta_data_editor.h

https://invent.kde.org/graphics/krita/commit/8702bb9001eb09519e5b8f49d3634816f8db398d

diff --git a/Messages.sh b/Messages.sh
index e858eb3ae3..5c1520d76f 100755
--- a/Messages.sh
+++ b/Messages.sh
@@ -7,8 +7,6 @@ source kundo2_aware_xgettext.sh
 
 $EXTRACTRC `find . -name \*.ui | grep -v '/tests/'` >> rc.cpp
 RCFILES=`find . -name \*.xmlgui                                               \
-	| grep -v plugins/extensions/metadataeditor/editors/dublincore.xmlgui \
-	| grep -v plugins/extensions/metadataeditor/editors/exif.xmlgui       \
 	| grep -v krita/sketch/KritaSketchWin.xmlgui                          \
 	| grep -v krita/gemini/KritaGeminiWin.xmlgui
          `
@@ -20,10 +18,6 @@ ACTIONFILES=`find . -name \*.action | grep -v '/tests/'`
 # extracti18n.pl extracts additional data from brushes, palettes etc.
 perl extracti18n.pl >> rc.cpp
 
-# Extract the name of configuration pages in the metadata editor plugin.
-$EXTRACTATTR --attr=MetaDataEditor,name --context='metadata editor page' \
-  plugins/extensions/metadataeditor/editors/*.xmlgui >> rc.cpp
-
 # Ignore sdk/templates which contains templates for writing future plugins.
 # Also ignore crashreporter, it has it's own catalog
 # None of the placeholder strings inside will be seen by users.
diff --git a/plugins/extensions/metadataeditor/CMakeLists.txt b/plugins/extensions/metadataeditor/CMakeLists.txt
index 0aa8d25e59..8064b73502 100644
--- a/plugins/extensions/metadataeditor/CMakeLists.txt
+++ b/plugins/extensions/metadataeditor/CMakeLists.txt
@@ -9,4 +9,3 @@ add_library(kritametadataeditor MODULE ${kritametadataeditor_SOURCES})
 target_link_libraries(kritametadataeditor kritaui )
 install(TARGETS kritametadataeditor  DESTINATION ${KRITA_PLUGIN_INSTALL_DIR})
 install( FILES metadataeditor.xmlgui DESTINATION ${DATA_INSTALL_DIR}/kritaplugins )
-install( FILES editors/dublincore.xmlgui editors/exif.xmlgui DESTINATION ${DATA_INSTALL_DIR}/kritaplugins/metadataeditor )
diff --git a/plugins/extensions/metadataeditor/editors/dublincore.ui b/plugins/extensions/metadataeditor/editors/dublincore.ui
index eb9a17dbba..1827a56e34 100644
--- a/plugins/extensions/metadataeditor/editors/dublincore.ui
+++ b/plugins/extensions/metadataeditor/editors/dublincore.ui
@@ -20,64 +20,52 @@
      <property name="text">
       <string>Creator name:</string>
      </property>
-     <property name="alignment">
-      <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
-     </property>
      <property name="buddy">
-      <cstring>editCreator</cstring>
+      <cstring>creator</cstring>
      </property>
     </widget>
    </item>
    <item row="0" column="1">
-    <widget class="QLineEdit" name="editCreator"/>
+    <widget class="QLineEdit" name="creator"/>
    </item>
    <item row="1" column="0">
     <widget class="QLabel" name="label_4">
      <property name="text">
       <string>Publisher:</string>
      </property>
-     <property name="alignment">
-      <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
-     </property>
      <property name="buddy">
-      <cstring>editPublisher</cstring>
+      <cstring>publisher</cstring>
      </property>
     </widget>
    </item>
    <item row="1" column="1">
-    <widget class="QLineEdit" name="editPublisher"/>
+    <widget class="QLineEdit" name="publisher"/>
    </item>
    <item row="2" column="0">
     <widget class="QLabel" name="label_5">
      <property name="text">
       <string>Rights:</string>
      </property>
-     <property name="alignment">
-      <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
-     </property>
      <property name="buddy">
-      <cstring>editRights</cstring>
+      <cstring>rights</cstring>
      </property>
     </widget>
    </item>
    <item row="2" column="1">
-    <widget class="QLineEdit" name="editRights"/>
+    <widget class="QLineEdit" name="rights"/>
    </item>
    <item row="3" column="0">
     <widget class="QLabel" name="label_2">
      <property name="text">
       <string>Date:</string>
      </property>
-     <property name="alignment">
-      <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
-     </property>
      <property name="buddy">
-      <cstring>editDate</cstring>
+      <cstring>date</cstring>
      </property>
     </widget>
    </item>
    <item row="3" column="1">
-    <widget class="QDateTimeEdit" name="editDate">
+    <widget class="QDateTimeEdit" name="date">
      <property name="calendarPopup">
       <bool>true</bool>
      </property>
@@ -88,32 +76,26 @@
      <property name="text">
       <string>Title:</string>
      </property>
-     <property name="alignment">
-      <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
-     </property>
      <property name="buddy">
-      <cstring>editTitle</cstring>
+      <cstring>title</cstring>
      </property>
     </widget>
    </item>
    <item row="4" column="1">
-    <widget class="QLineEdit" name="editTitle"/>
+    <widget class="QLineEdit" name="title"/>
    </item>
    <item row="5" column="0">
     <widget class="QLabel" name="label_3">
      <property name="text">
       <string>Description:</string>
      </property>
-     <property name="alignment">
-      <set>Qt::AlignRight|Qt::AlignTop|Qt::AlignTrailing</set>
-     </property>
      <property name="buddy">
-      <cstring>editDescription</cstring>
+      <cstring>description</cstring>
      </property>
     </widget>
    </item>
    <item row="5" column="1">
-    <widget class="QTextEdit" name="editDescription"/>
+    <widget class="QTextEdit" name="description"/>
    </item>
   </layout>
  </widget>
diff --git a/plugins/extensions/metadataeditor/editors/dublincore.xmlgui b/plugins/extensions/metadataeditor/editors/dublincore.xmlgui
deleted file mode 100644
index a5813d16fa..0000000000
--- a/plugins/extensions/metadataeditor/editors/dublincore.xmlgui
+++ /dev/null
@@ -1,33 +0,0 @@
-<?xml version="1.0"?>
-<MetaDataEditor name="Dublin Core" uiFile="dublincore.ui" icon="user-properties">
-    <EntryEditor editorName = "editCreator"
-                schemaUri = "http://purl.org/dc/elements/1.1/"
-                entryName = "creator"
-                editorSignal = "textEdited(const QString&)"
-                propertyName = "text" />
-    <EntryEditor editorName = "editPublisher"
-                schemaUri = "http://purl.org/dc/elements/1.1/"
-                entryName = "publisher"
-                editorSignal = "textEdited(const QString&)"
-                propertyName = "text" />
-    <EntryEditor editorName = "editRights"
-                schemaUri = "http://purl.org/dc/elements/1.1/"
-                entryName = "rights"
-                editorSignal = "textEdited(const QString&)"
-                propertyName = "text" />
-    <EntryEditor editorName = "editDate"
-                schemaUri = "http://purl.org/dc/elements/1.1/"
-                entryName = "date"
-                editorSignal = "editingFinished()"
-                propertyName = "date" />
-    <EntryEditor editorName = "editTitle"
-                schemaUri = "http://purl.org/dc/elements/1.1/"
-                entryName = "title"
-                editorSignal = "textEdited(const QString&)"
-                propertyName = "text" />
-    <EntryEditor editorName = "editDescription"
-                schemaUri = "http://purl.org/dc/elements/1.1/"
-                entryName = "description"
-                editorSignal = "textChanged()"
-                propertyName = "plainText" />
-</MetaDataEditor>
diff --git a/plugins/extensions/metadataeditor/editors/exif.ui b/plugins/extensions/metadataeditor/editors/exif.ui
index f03aa55a65..0e1308e9b6 100644
--- a/plugins/extensions/metadataeditor/editors/exif.ui
+++ b/plugins/extensions/metadataeditor/editors/exif.ui
@@ -36,9 +36,6 @@
          <property name="text">
           <string comment="EXIF: exposure">Brightness &value:</string>
          </property>
-         <property name="alignment">
-          <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
-         </property>
          <property name="buddy">
           <cstring>editBrightnessValue</cstring>
          </property>
@@ -52,16 +49,13 @@
          <property name="text">
           <string comment="EXIF: exposure">&ISO:</string>
          </property>
-         <property name="alignment">
-          <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
-         </property>
          <property name="buddy">
-          <cstring>editISO</cstring>
+          <cstring>editISOSpeedRatings</cstring>
          </property>
         </widget>
        </item>
        <item row="1" column="1">
-        <widget class="KisIntParseSpinBox" name="editISO">
+        <widget class="KisIntParseSpinBox" name="editISOSpeedRatings">
          <property name="maximum">
           <number>3600</number>
          </property>
@@ -78,9 +72,6 @@
          <property name="text">
           <string comment="EXIF: exposure">Exposure &time:</string>
          </property>
-         <property name="alignment">
-          <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
-         </property>
          <property name="buddy">
           <cstring>editExposureTime</cstring>
          </property>
@@ -94,9 +85,6 @@
          <property name="text">
           <string comment="EXIF: exposure">E&xposure mode:</string>
          </property>
-         <property name="alignment">
-          <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
-         </property>
          <property name="buddy">
           <cstring>editExposureMode</cstring>
          </property>
@@ -126,9 +114,6 @@
          <property name="text">
           <string comment="EXIF: exposure">Exposure pro&gram:</string>
          </property>
-         <property name="alignment">
-          <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
-         </property>
          <property name="buddy">
           <cstring>editExposureProgram</cstring>
          </property>
@@ -188,9 +173,6 @@
          <property name="text">
           <string comment="EXIF: exposure">Exposure index:</string>
          </property>
-         <property name="alignment">
-          <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
-         </property>
          <property name="buddy">
           <cstring>editExposureIndex</cstring>
          </property>
@@ -204,9 +186,6 @@
          <property name="text">
           <string comment="EXIF: exposure">Exposure bias:</string>
          </property>
-         <property name="alignment">
-          <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
-         </property>
          <property name="buddy">
           <cstring>editExposureBiasValue</cstring>
          </property>
@@ -220,9 +199,6 @@
          <property name="text">
           <string comment="EXIF: exposure">Ape&rture:</string>
          </property>
-         <property name="alignment">
-          <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
-         </property>
          <property name="buddy">
           <cstring>editApertureValue</cstring>
          </property>
@@ -236,9 +212,6 @@
          <property name="text">
           <string comment="EXIF: exposure">Shutter speed:</string>
          </property>
-         <property name="alignment">
-          <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
-         </property>
          <property name="buddy">
           <cstring>editShutterSpeedValue</cstring>
          </property>
@@ -252,9 +225,6 @@
          <property name="text">
           <string comment="EXIF: exposure">&F Number:</string>
          </property>
-         <property name="alignment">
-          <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
-         </property>
          <property name="buddy">
           <cstring>editFNumber</cstring>
          </property>
@@ -263,19 +233,6 @@
        <item row="9" column="1">
         <widget class="QLineEdit" name="editFNumber"/>
        </item>
-       <item row="10" column="0" colspan="2">
-        <spacer name="verticalSpacer">
-         <property name="orientation">
-          <enum>Qt::Vertical</enum>
-         </property>
-         <property name="sizeHint" stdset="0">
-          <size>
-           <width>20</width>
-           <height>40</height>
-          </size>
-         </property>
-        </spacer>
-       </item>
       </layout>
      </widget>
      <widget class="QWidget" name="tab_2">
@@ -288,9 +245,6 @@
          <property name="text">
           <string comment="EXIF: lens">&Focal length:</string>
          </property>
-         <property name="alignment">
-          <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
-         </property>
          <property name="buddy">
           <cstring>editFocalLength</cstring>
          </property>
@@ -314,9 +268,6 @@
          <property name="text">
           <string comment="EXIF: lens">Focal length (&35mm equivalent):</string>
          </property>
-         <property name="alignment">
-          <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
-         </property>
          <property name="buddy">
           <cstring>editFocalLengthIn35mmFilm</cstring>
          </property>
@@ -340,9 +291,6 @@
          <property name="text">
           <string comment="EXIF: lens">Max aperture:</string>
          </property>
-         <property name="alignment">
-          <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
-         </property>
          <property name="buddy">
           <cstring>editMaxApertureValue</cstring>
          </property>
@@ -363,9 +311,6 @@
          <property name="text">
           <string comment="EXIF: autofocus">Sub&ject distance:</string>
          </property>
-         <property name="alignment">
-          <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
-         </property>
          <property name="buddy">
           <cstring>editSubjectDistance</cstring>
          </property>
@@ -379,9 +324,6 @@
          <property name="text">
           <string comment="EXIF: autofocus">Meterin&g mode:</string>
          </property>
-         <property name="alignment">
-          <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
-         </property>
          <property name="buddy">
           <cstring>editMeteringMode</cstring>
          </property>
@@ -436,9 +378,6 @@
          <property name="text">
           <string comment="EXIF: autofocus">D&istance range:</string>
          </property>
-         <property name="alignment">
-          <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
-         </property>
          <property name="buddy">
           <cstring>editSubjectDistanceRange</cstring>
          </property>
@@ -487,16 +426,13 @@
          <property name="text">
           <string comment="EXIF: flash">Stro&be return:</string>
          </property>
-         <property name="alignment">
-          <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
-         </property>
          <property name="buddy">
-          <cstring>editStrobeReturn</cstring>
+          <cstring>editFlashStrobeReturn</cstring>
          </property>
         </widget>
        </item>
        <item row="1" column="1">
-        <widget class="QComboBox" name="editStrobeReturn">
+        <widget class="QComboBox" name="editFlashStrobeReturn">
          <item>
           <property name="text">
            <string comment="EXIF: flash - strobe return">No strobe return detection</string>
@@ -524,9 +460,6 @@
          <property name="text">
           <string comment="EXIF: flash">Mode:</string>
          </property>
-         <property name="alignment">
-          <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
-         </property>
          <property name="buddy">
           <cstring>editFlashMode</cstring>
          </property>
@@ -575,9 +508,6 @@
          <property name="text">
           <string comment="EXIF: flash">Flash ener&gy:</string>
          </property>
-         <property name="alignment">
-          <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
-         </property>
          <property name="buddy">
           <cstring>editFlashEnergy</cstring>
          </property>
@@ -598,9 +528,6 @@
          <property name="text">
           <string comment="EXIF: postprocessing">&Gain control:</string>
          </property>
-         <property name="alignment">
-          <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
-         </property>
          <property name="buddy">
           <cstring>editGainControl</cstring>
          </property>
@@ -646,9 +573,6 @@
          <property name="text">
           <string comment="EXIF: postprocessing">L&ight source:</string>
          </property>
-         <property name="alignment">
-          <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
-         </property>
          <property name="buddy">
           <cstring>editLightSource</cstring>
          </property>
@@ -793,9 +717,6 @@
          <property name="text">
           <string comment="EXIF: postprocessing">Sharpness:</string>
          </property>
-         <property name="alignment">
-          <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
-         </property>
          <property name="buddy">
           <cstring>editSharpness</cstring>
          </property>
@@ -825,9 +746,6 @@
          <property name="text">
           <string comment="EXIF: postprocessing">Contrast:</string>
          </property>
-         <property name="alignment">
-          <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
-         </property>
          <property name="buddy">
           <cstring>editContrast</cstring>
          </property>
@@ -857,9 +775,6 @@
          <property name="text">
           <string comment="EXIF: postprocessing">White &balance:</string>
          </property>
-         <property name="alignment">
-          <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
-         </property>
          <property name="buddy">
           <cstring>editWhiteBalance</cstring>
          </property>
@@ -891,9 +806,6 @@
          <property name="text">
           <string comment="EXIF: misc">Scene capture t&ype:</string>
          </property>
-         <property name="alignment">
-          <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
-         </property>
          <property name="buddy">
           <cstring>editSceneCaptureType</cstring>
          </property>
@@ -928,9 +840,6 @@
          <property name="text">
           <string comment="EXIF: misc">Ma&ker:</string>
          </property>
-         <property name="alignment">
-          <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
-         </property>
          <property name="buddy">
           <cstring>editMake</cstring>
          </property>
@@ -944,9 +853,6 @@
          <property name="text">
           <string comment="EXIF: misc (model name or model number)">Model:</string>
          </property>
-         <property name="alignment">
-          <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
-         </property>
          <property name="buddy">
           <cstring>editModel</cstring>
          </property>
@@ -960,9 +866,6 @@
          <property name="text">
           <string comment="EXIF: misc">Sens&ing method type:</string>
          </property>
-         <property name="alignment">
-          <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
-         </property>
          <property name="buddy">
           <cstring>editSensingMethod</cstring>
          </property>
diff --git a/plugins/extensions/metadataeditor/editors/exif.xmlgui b/plugins/extensions/metadataeditor/editors/exif.xmlgui
deleted file mode 100644
index a626fdbbc1..0000000000
--- a/plugins/extensions/metadataeditor/editors/exif.xmlgui
+++ /dev/null
@@ -1,157 +0,0 @@
-<?xml version="1.0"?>
-<MetaDataEditor name="Exif" uiFile="exif.ui" icon="camera-photo">
-    <EntryEditor editorName = "editBrightnessValue"
-                schemaUri = "http://ns.adobe.com/exif/1.0/"
-                entryName = "BrightnessValue"
-                editorSignal = "textEdited(const QString&)"
-                propertyName = "text" />
-    <EntryEditor editorName = "editExposureTime"
-                schemaUri = "http://ns.adobe.com/exif/1.0/"
-                entryName = "ExposureTime"
-                editorSignal = "textEdited(const QString&)"
-                propertyName = "text" />
-    <EntryEditor editorName = "editISO"
-                schemaUri = "http://ns.adobe.com/exif/1.0/"
-                entryName = "ISOSpeedRatings"
-                editorSignal = "valueChanged(int)"
-                propertyName = "value"
-                arrayIndex = "0" />
-    <EntryEditor editorName = "editExposureMode"
-                schemaUri = "http://ns.adobe.com/exif/1.0/"
-                entryName = "ExposureMode"
-                editorSignal = "activated(int)"
-                propertyName = "currentIndex" />
-    <EntryEditor editorName = "editExposureProgram"
-                schemaUri = "http://ns.adobe.com/exif/1.0/"
-                entryName = "ExposureProgram"
-                editorSignal = "activated(int)"
-                propertyName = "currentIndex" />
-    <EntryEditor editorName = "editExposureIndex"
-                schemaUri = "http://ns.adobe.com/exif/1.0/"
-                entryName = "ExposureIndex"
-                editorSignal = "textEdited(const QString&)"
-                propertyName = "text" />
-    <EntryEditor editorName = "editExposureBiasValue"
-                schemaUri = "http://ns.adobe.com/exif/1.0/"
-                entryName = "ExposureBiasValue"
-                editorSignal = "textEdited(const QString&)"
-                propertyName = "text" />
-    <EntryEditor editorName = "editApertureValue"
-                schemaUri = "http://ns.adobe.com/exif/1.0/"
-                entryName = "ApertureValue"
-                editorSignal = "textEdited(const QString&)"
-                propertyName = "text" />
-    <EntryEditor editorName = "editShutterSpeedValue"
-                schemaUri = "http://ns.adobe.com/exif/1.0/"
-                entryName = "ShutterSpeedValue"
-                editorSignal = "textEdited(const QString&)"
-                propertyName = "text" />
-    <EntryEditor editorName = "editFNumber"
-                schemaUri = "http://ns.adobe.com/exif/1.0/"
-                entryName = "FNumber"
-                editorSignal = "textEdited(const QString&)"
-                propertyName = "text" />
-<!--  lens tab    -->
-    <EntryEditor editorName = "editFocalLengthIn35mmFilm"
-                schemaUri = "http://ns.adobe.com/exif/1.0/"
-                entryName = "FocalLengthIn35mmFilm"
-                editorSignal = "valueChanged(int)"
-                propertyName = "value" />
-    <EntryEditor editorName = "editFocalLength"
-                schemaUri = "http://ns.adobe.com/exif/1.0/"
-                entryName = "FocalLength"
-                editorSignal = "valueChanged(int)"
-                propertyName = "value" />
-    <EntryEditor editorName = "editMaxApertureValue"
-                schemaUri = "http://ns.adobe.com/exif/1.0/"
-                entryName = "MaxApertureValue"
-                editorSignal = "textEdited(const QString&)"
-                propertyName = "text" />
-<!--  autofocus tab    -->
-    <EntryEditor editorName = "editMeteringMode"
-                schemaUri = "http://ns.adobe.com/exif/1.0/"
-                entryName = "MeteringMode"
-                editorSignal = "activated(int)"
-                propertyName = "currentIndex" />
-    <EntryEditor editorName = "editSubjectDistance"
-                schemaUri = "http://ns.adobe.com/exif/1.0/"
-                entryName = "SubjectDistance"
-                editorSignal = "textEdited(const QString&)"
-                propertyName = "text" />
-    <EntryEditor editorName = "editSubjectDistanceRange"
-                schemaUri = "http://ns.adobe.com/exif/1.0/"
-                entryName = "SubjectDistanceRange"
-                editorSignal = "activated(int)"
-                propertyName = "currentIndex" />
-<!--  Flash    -->
-    <EntryEditor editorName = "editFlashFired"
-                schemaUri = "http://ns.adobe.com/exif/1.0/"
-                entryName = "Flash"
-                structureField = "Fired"
-                editorSignal = "toggled(bool)"
-                propertyName = "checked" />
-    <EntryEditor editorName = "editFlashFunction"
-                schemaUri = "http://ns.adobe.com/exif/1.0/"
-                entryName = "Flash"
-                structureField = "Function"
-                editorSignal = "toggled(bool)"
-                propertyName = "checked" />
-    <EntryEditor editorName = "editFlashRedEyeMode"
-                schemaUri = "http://ns.adobe.com/exif/1.0/"
-                entryName = "Flash"
-                structureField = "RedEyeMode"
-                editorSignal = "toggled(bool)"
-                propertyName = "checked" />
-    <EntryEditor editorName = "editFlashEnergy"
-                schemaUri = "http://ns.adobe.com/exif/1.0/"
-                entryName = "FlashEnergy"
-                editorSignal = "textEdited(const QString&)"
-                propertyName = "text" />
-<!--  postprocessing    -->
-    <EntryEditor editorName = "editGainControl"
-                schemaUri = "http://ns.adobe.com/exif/1.0/"
-                entryName = "GainControl"
-                editorSignal = "activated(int)"
-                propertyName = "currentIndex" />
-    <EntryEditor editorName = "editLightSource"
-                schemaUri = "http://ns.adobe.com/exif/1.0/"
-                entryName = "LightSource"
-                editorSignal = "activated(int)"
-                propertyName = "currentIndex" />
-    <EntryEditor editorName = "editSharpness"
-                schemaUri = "http://ns.adobe.com/exif/1.0/"
-                entryName = "Sharpness"
-                editorSignal = "activated(int)"
-                propertyName = "currentIndex" />
-    <EntryEditor editorName = "editContrast"
-                schemaUri = "http://ns.adobe.com/exif/1.0/"
-                entryName = "Contrast"
-                editorSignal = "activated(int)"
-                propertyName = "currentIndex" />
-    <EntryEditor editorName = "editWhiteBalance"
-                schemaUri = "http://ns.adobe.com/exif/1.0/"
-                entryName = "WhiteBalance"
-                editorSignal = "activated(int)"
-                propertyName = "currentIndex" />
-<!--  misc    -->
-    <EntryEditor editorName = "editSceneCaptureType"
-                schemaUri = "http://ns.adobe.com/exif/1.0/"
-                entryName = "SceneCaptureType"
-                editorSignal = "activated(int)"
-                propertyName = "currentIndex" />
-    <EntryEditor editorName = "editMake"
-                schemaUri = "http://ns.adobe.com/tiff/1.0/"
-                entryName = "Make"
-                editorSignal = "textEdited(const QString&)"
-                propertyName = "text" />
-    <EntryEditor editorName = "editModel"
-                schemaUri = "http://ns.adobe.com/tiff/1.0/"
-                entryName = "Model"
-                editorSignal = "textEdited(const QString&)"
-                propertyName = "text" />
-    <EntryEditor editorName = "editSensingMethod"
-                schemaUri = "http://ns.adobe.com/exif/1.0/"
-                entryName = "SensingMethod"
-                editorSignal = "activated(int)"
-                propertyName = "currentIndex" />
-</MetaDataEditor>
diff --git a/plugins/extensions/metadataeditor/kis_meta_data_editor.cc b/plugins/extensions/metadataeditor/kis_meta_data_editor.cc
index b19f84f0df..f94e652e12 100644
--- a/plugins/extensions/metadataeditor/kis_meta_data_editor.cc
+++ b/plugins/extensions/metadataeditor/kis_meta_data_editor.cc
@@ -1,5 +1,6 @@
 /*
  *  SPDX-FileCopyrightText: 2007, 2010 Cyrille Berger <cberger at cberger.net>
+ *  SPDX-FileCopyrightText: 2021 L. E. Segovia <amy at amyspark.me>
  *
  *  SPDX-License-Identifier: LGPL-2.1-or-later
  */
@@ -8,140 +9,184 @@
 
 #include <QDomDocument>
 #include <QFile>
+#include <QHeaderView>
+#include <QTableView>
 
-#include <klocalizedstring.h>
 #include <KoResourcePaths.h>
-
-
 #include <kis_debug.h>
-
-#include <kis_meta_data_store.h>
+#include <kis_icon.h>
 #include <kis_meta_data_entry.h>
-#include <kis_meta_data_value.h>
 #include <kis_meta_data_schema.h>
 #include <kis_meta_data_schema_registry.h>
-#include <kis_icon.h>
+#include <kis_meta_data_store.h>
+#include <kis_meta_data_value.h>
+#include <klocalizedstring.h>
+
 #include "kis_entry_editor.h"
-#include <QTableView>
 #include "kis_meta_data_model.h"
-#include <QHeaderView>
+
 
 struct KisMetaDataEditor::Private {
-    KisMetaData::Store* originalStore;
-    KisMetaData::Store* store;
-    QMultiHash<QString, KisEntryEditor*> entryEditors;
+    KisMetaData::Store *store;
+    KisMetaData::Store *temporaryStorage;
+    QList<KisEntryEditor *> entryHandlers;
 };
 
+#define GET_VALUE(entryName, wdg, wdgPropertyName, editorSignal) \
+    QString key = schema->generateQualifiedName(#entryName); \
+    KisEntryEditor *ee = new KisEntryEditor(wdg, d->temporaryStorage, key, #wdgPropertyName, QString(), 0); \
+    connect(wdg, editorSignal, ee, &KisEntryEditor::valueEdited); \
+    d->entryHandlers.push_back(ee);
+
+#define GET_ARRAY_VALUE(entryName, arrayIndex, wdg, wdgPropertyName, editorSignal) \
+    QString key = schema->generateQualifiedName(#entryName); \
+    KisEntryEditor *ee = new KisEntryEditor(wdg, d->temporaryStorage, key, #wdgPropertyName, QString(), arrayIndex); \
+    connect(wdg, editorSignal, ee, &KisEntryEditor::valueEdited); \
+    d->entryHandlers.push_back(ee);
+
+#define GET_STRUCTURE_VALUE(entryName, structureField, wdg, wdgPropertyName, editorSignal) \
+    QString key = schema->generateQualifiedName(#entryName); \
+    KisEntryEditor *ee = new KisEntryEditor(wdg, d->temporaryStorage, key, #wdgPropertyName, #structureField, 0); \
+    connect(wdg, editorSignal, ee, &KisEntryEditor::valueEdited); \
+    d->entryHandlers.push_back(ee);
+
+#define GET_DC_VALUE(entryName, wdgPropertyName, editorSignal) { \
+    GET_VALUE(entryName, wdg->entryName, wdgPropertyName, editorSignal) \
+}
 
-KisMetaDataEditor::KisMetaDataEditor(QWidget* parent, KisMetaData::Store* originalStore) :
-        KPageDialog(parent), d(new Private)
-{
-    d->originalStore = originalStore;
-    d->store = new KisMetaData::Store(*originalStore);
+#define GET_EXIF_VALUE(entryName, wdgPropertyName, editorSignal) { \
+    GET_VALUE(entryName, wdg->edit##entryName, wdgPropertyName, editorSignal) \
+}
 
-    QStringList files = KoResourcePaths::findAllResources("data", "kritaplugins/metadataeditor/*.xmlgui");
+#define GET_EXIF_ARRAY_VALUE(entryName, arrayIndex, wdgPropertyName, editorSignal) { \
+    GET_ARRAY_VALUE(entryName, arrayIndex, wdg->edit##entryName, wdgPropertyName, editorSignal) \
+}
 
-    QMap<QString, QWidget*> widgets;
-    widgets["dublincore.ui"] = new WdgDublinCore(this);
-    widgets["exif.ui"] = new WdgExif(this);
+#define GET_EXIF_STRUCTURE_VALUE(entryName, structureField, wdgPropertyName, editorSignal) { \
+    GET_STRUCTURE_VALUE(entryName, structureField, wdg->edit##entryName##structureField, wdgPropertyName, editorSignal) \
+}
 
-    Q_FOREACH (const QString & file, files) {
+KisMetaDataEditor::KisMetaDataEditor(QWidget *parent, KisMetaData::Store *store)
+    : KPageDialog(parent)
+    , d(new Private)
+{
+    d->temporaryStorage = new KisMetaData::Store(*store);
+    d->store = store;
+
+    // Add the Dublin Core widget
+    {
+        WdgDublinCore *wdg = new WdgDublinCore(this);
+
+        {
+            // copy from dublin core
+            const KisMetaData::Schema *schema =
+                KisMetaData::SchemaRegistry::instance()->schemaFromUri(KisMetaData::Schema::DublinCoreSchemaUri);
+
+            Q_ASSERT(schema);
+
+            GET_DC_VALUE(creator, text, &QLineEdit::textEdited);
+            GET_DC_VALUE(publisher, text, &QLineEdit::textEdited);
+            GET_DC_VALUE(rights, text, &QLineEdit::textEdited);
+            GET_DC_VALUE(date, date, &QDateTimeEdit::editingFinished);
+            GET_DC_VALUE(title, text, &QLineEdit::textEdited);
+            GET_DC_VALUE(description, plainText, &QTextEdit::textChanged);
+        }
 
-        QFile xmlFile(file);
-        xmlFile.open(QFile::ReadOnly);
-        QString errMsg;
-        int errLine, errCol;
+        KPageWidgetItem *page = new KPageWidgetItem(wdg, i18n("Dublin Core"));
+        page->setIcon(KisIconUtils::loadIcon("user-identity"));
+        addPage(page);
+    }
 
-        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";
+    // Add the Exif widget
+    {
+        WdgExif *wdg = new WdgExif(this);
+
+        {
+            // copy from exif
+            const KisMetaData::Schema *schema =
+                KisMetaData::SchemaRegistry::instance()->schemaFromUri(KisMetaData::Schema::EXIFSchemaUri);
+
+            Q_ASSERT(schema);
+
+            /* exposure tab */
+            GET_EXIF_VALUE(BrightnessValue, text, &QLineEdit::textEdited);
+            GET_EXIF_VALUE(ExposureTime, text, &QLineEdit::textEdited);
+            GET_EXIF_ARRAY_VALUE(ISOSpeedRatings, 0, value, QOverload<int>::of(&KisIntParseSpinBox::valueChanged));
+            GET_EXIF_VALUE(ExposureMode, currentIndex, QOverload<int>::of(&QComboBox::activated));
+            GET_EXIF_VALUE(ExposureProgram, currentIndex, QOverload<int>::of(&QComboBox::activated));
+            GET_EXIF_VALUE(ExposureIndex, text, &QLineEdit::textEdited);
+            GET_EXIF_VALUE(ExposureBiasValue, text, &QLineEdit::textEdited);
+            GET_EXIF_VALUE(ApertureValue, text, &QLineEdit::textEdited);
+            GET_EXIF_VALUE(ShutterSpeedValue, text, &QLineEdit::textEdited);
+            GET_EXIF_VALUE(FNumber, text, &QLineEdit::textEdited);
+            /*  lens tab  */
+            GET_EXIF_VALUE(FocalLengthIn35mmFilm, value, QOverload<int>::of(&QSpinBox::valueChanged));
+            GET_EXIF_VALUE(FocalLength, value, QOverload<int>::of(&QSpinBox::valueChanged));
+            GET_EXIF_VALUE(MaxApertureValue, text, &QLineEdit::textEdited);
+            /*  autofocus tab  */
+            GET_EXIF_VALUE(MeteringMode, currentIndex, QOverload<int>::of(&QComboBox::activated));
+            GET_EXIF_VALUE(SubjectDistance, text, &QLineEdit::textEdited);
+            GET_EXIF_VALUE(SubjectDistanceRange, currentIndex, QOverload<int>::of(&QComboBox::activated));
+            /*  flash  */
+            GET_EXIF_STRUCTURE_VALUE(Flash, Fired, isChecked, QOverload<bool>::of(&QCheckBox::toggled));
+            GET_EXIF_STRUCTURE_VALUE(Flash, StrobeReturn, currentIndex, QOverload<int>::of(&QComboBox::activated));
+            GET_EXIF_STRUCTURE_VALUE(Flash, Mode, currentIndex, QOverload<int>::of(&QComboBox::activated));
+            GET_EXIF_STRUCTURE_VALUE(Flash, Function, isChecked, QOverload<bool>::of(&QCheckBox::toggled));
+            GET_EXIF_STRUCTURE_VALUE(Flash, RedEyeMode, isChecked, QOverload<bool>::of(&QCheckBox::toggled));
+            GET_EXIF_VALUE(FlashEnergy, text, &QLineEdit::textEdited);
+            /*  postprocessing tab */
+            GET_EXIF_VALUE(GainControl, currentIndex, QOverload<int>::of(&QComboBox::activated));
+            GET_EXIF_VALUE(LightSource, currentIndex, QOverload<int>::of(&QComboBox::activated));
+            GET_EXIF_VALUE(Sharpness, currentIndex, QOverload<int>::of(&QComboBox::activated));
+            GET_EXIF_VALUE(Contrast, currentIndex, QOverload<int>::of(&QComboBox::activated));
+            GET_EXIF_VALUE(WhiteBalance, currentIndex, QOverload<int>::of(&QComboBox::activated));
+            /*  misc tab */
+            GET_EXIF_VALUE(SceneCaptureType, currentIndex, QOverload<int>::of(&QComboBox::activated));
+            GET_EXIF_VALUE(SensingMethod, currentIndex, QOverload<int>::of(&QComboBox::activated));
         }
 
-        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");
-            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* metaDataEditorPage = widget->findChild<QWidget*>(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(metaDataEditorPage, d->store, key, propertyName, structureField, arrayIndex);
-                    connect(metaDataEditorPage, editorSignal.toLatin1(), ee, SLOT(valueEdited()));
-                    QList<KisEntryEditor*> 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();
+        {
+            // copy from exif (tiff schema)
+            const KisMetaData::Schema *schema =
+                KisMetaData::SchemaRegistry::instance()->schemaFromUri(KisMetaData::Schema::TIFFSchemaUri);
 
-        KPageWidgetItem *page = new KPageWidgetItem(widget, pageName);
-        if (!iconName.isEmpty()) {
-            page->setIcon(KisIconUtils::loadIcon(iconName));
+            Q_ASSERT(schema);
+
+            /*  misc  */
+            GET_EXIF_VALUE(Make, text, &QLineEdit::textEdited);
+            GET_EXIF_VALUE(Model, text, &QLineEdit::textEdited);
         }
+
+        KPageWidgetItem *page = new KPageWidgetItem(wdg, i18n("Exif"));
+        page->setIcon(KisIconUtils::loadIcon("camera-photo"));
         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);
+    {
+        // 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) {
+    Q_FOREACH (KisEntryEditor *e, d->entryHandlers) {
         delete e;
     }
-    delete d->store;
+    delete d->temporaryStorage;
     delete d;
 }
 
 void KisMetaDataEditor::accept()
 {
     KPageDialog::accept();
-    d->originalStore->copyFrom(d->store);
-}
 
+    d->store->copyFrom(d->temporaryStorage);
+}
diff --git a/plugins/extensions/metadataeditor/kis_meta_data_editor.h b/plugins/extensions/metadataeditor/kis_meta_data_editor.h
index e633c8fa97..8f93d16814 100644
--- a/plugins/extensions/metadataeditor/kis_meta_data_editor.h
+++ b/plugins/extensions/metadataeditor/kis_meta_data_editor.h
@@ -1,5 +1,6 @@
 /*
  *  SPDX-FileCopyrightText: 2007 Cyrille Berger <cberger at cberger.net>
+ *  SPDX-FileCopyrightText: 2021 L. E. Segovia <amy at amyspark.me>
  *
  *  SPDX-License-Identifier: LGPL-2.1-or-later
  */



More information about the kimageshop mailing list