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++
Replace three different undo commands for metadata with one
Dmitry Kazakov934433812920
diff --git a/libs/command/kis_command_ids.h b/libs/command/kis_command_ids.hindex 5d6725f008..2a069038b0 100644--- a/libs/command/kis_command_ids.h+++ b/libs/command/kis_command_ids.h@@ -45,9 +45,7 @@ enum CommandId {ImageAnimSettingCommandId,SvgTextChangeTransformsOnRangeCommandId,SvgTextPathInfoChangeCommandId,- ChangeImageHdrContentLightLevelId,- ChangeImageHdrColorVolumeId,- ChangeImageHdrDiffuseWhiteId+ ChangeImageHdrMetadataId,};}diff --git a/libs/image/CMakeLists.txt b/libs/image/CMakeLists.txtindex 7dacfb9269..f7363e2d74 100644--- a/libs/image/CMakeLists.txt+++ b/libs/image/CMakeLists.txt@@ -122,9 +122,7 @@ set(kritaimage_LIB_SRCScommands_new/KisLazyCreateTransformMaskKeyframesCommand.cppcommands_new/KisChangeCloneLayersCommand.cppcommands_new/KisLayerCollapseCommand.cpp- commands_new/KisChangeImageHdrContentLightLevelCommand.cpp- commands_new/KisChangeImageHdrColorVolumeCommand.cpp- commands_new/KisChangeImageHdrReferenceWhiteCommand.cpp+ commands_new/KisChangeImageHdrMetadataCommand.cppprocessing/kis_do_nothing_processing_visitor.cppprocessing/kis_simple_processing_visitor.cppprocessing/kis_convert_color_space_processing_visitor.cppdiff --git a/libs/image/commands_new/KisChangeImageHdrColorVolumeCommand.cpp b/libs/image/commands_new/KisChangeImageHdrColorVolumeCommand.cppdeleted file mode 100644index 7d6a8f6ec7..0000000000--- a/libs/image/commands_new/KisChangeImageHdrColorVolumeCommand.cpp+++ /dev/null@@ -1,52 +0,0 @@-/*- * SPDX-FileCopyrightText: 2026 Wolthera van Hövell tot Westerflier <[email protected]>- *- * SPDX-License-Identifier: GPL-2.0-or-later- */-#include "KisChangeImageHdrColorVolumeCommand.h"-#include "kis_command_ids.h"-#include <kis_image.h>--KisChangeImageHdrColorVolumeCommand::KisChangeImageHdrColorVolumeCommand(KisImageWSP image,- std::optional<KisColorVolumeInformation> cvi,- KUndo2Command *parent)- : KUndo2Command(kundo2_i18n("Set HDR Color Volume Information"), parent)- , m_image(image)- , m_cvi(cvi)-{- KisImageSP img = m_image.toStrongRef();- if (img) {- m_oldCvi = img->colorVolumeInformation();- }-}--void KisChangeImageHdrColorVolumeCommand::redo()-{- KisImageSP img = m_image.toStrongRef();- if (!img) return;-- img->setColorVolumeInformation(m_cvi);--}--void KisChangeImageHdrColorVolumeCommand::undo()-{- KisImageSP img = m_image.toStrongRef();- if (!img) return;-- img->setColorVolumeInformation(m_oldCvi);-}--int KisChangeImageHdrColorVolumeCommand::id() const-{- return KisCommandUtils::ChangeImageHdrColorVolumeId;-}--bool KisChangeImageHdrColorVolumeCommand::mergeWith(const KUndo2Command *otherCommand)-{- const KisChangeImageHdrColorVolumeCommand *other = dynamic_cast<const KisChangeImageHdrColorVolumeCommand *>(otherCommand);- if (!other || other->m_image != m_image) return false;-- m_cvi = other->m_cvi;- return true;-}diff --git a/libs/image/commands_new/KisChangeImageHdrColorVolumeCommand.h b/libs/image/commands_new/KisChangeImageHdrColorVolumeCommand.hdeleted file mode 100644index 11f6f4f6cb..0000000000--- a/libs/image/commands_new/KisChangeImageHdrColorVolumeCommand.h+++ /dev/null@@ -1,33 +0,0 @@-/*- * SPDX-FileCopyrightText: 2026 Wolthera van Hövell tot Westerflier <[email protected]>- *- * SPDX-License-Identifier: GPL-2.0-or-later- */-#ifndef KISCHANGEIMAGEHDRCOLORVOLUMECOMMAND_H-#define KISCHANGEIMAGEHDRCOLORVOLUMECOMMAND_H--#include <kundo2command.h>-#include <kis_types.h>-#include <kis_hdr_metadata.h>-#include "kritaimage_export.h"-#include <optional>--class KRITAIMAGE_EXPORT KisChangeImageHdrColorVolumeCommand : public KUndo2Command-{-public:- KisChangeImageHdrColorVolumeCommand(KisImageWSP image,- std::optional<KisColorVolumeInformation> cvi,- KUndo2Command *parent = nullptr);-- void redo() override;- void undo() override;-- int id() const override;- bool mergeWith(const KUndo2Command *other) override;-private:- KisImageWSP m_image;- std::optional<KisColorVolumeInformation> m_cvi;- std::optional<KisColorVolumeInformation> m_oldCvi;-};--#endif // KISCHANGEIMAGEHDRMETADATACOMMAND_Hdiff --git a/libs/image/commands_new/KisChangeImageHdrContentLightLevelCommand.cpp b/libs/image/commands_new/KisChangeImageHdrContentLightLevelCommand.cppdeleted file mode 100644index f918a6b181..0000000000--- a/libs/image/commands_new/KisChangeImageHdrContentLightLevelCommand.cpp+++ /dev/null@@ -1,60 +0,0 @@-/*- * SPDX-FileCopyrightText: 2026 Wolthera van Hövell tot Westerflier <[email protected]>- *- * SPDX-License-Identifier: GPL-2.0-or-later- */-#include "KisChangeImageHdrContentLightLevelCommand.h"-#include "kis_command_ids.h"-#include <kis_image.h>--KisChangeImageHdrContentLightLevelCommand::KisChangeImageHdrContentLightLevelCommand(KisImageWSP image,- std::optional<KisRelativeContentLightLevelInformation> clli,- KUndo2Command *parent)- : KUndo2Command(kundo2_i18n("Set HDR Content Light Level"), parent)- , m_image(image)- , m_clli(clli)-{- KisImageSP img = m_image.toStrongRef();- if (img) {- m_oldClli = img->relativeContentLightLevelInformation();- }-}--void KisChangeImageHdrContentLightLevelCommand::redo()-{- KisImageSP img = m_image.toStrongRef();- if (!img) return;-- if (img->relativeContentLightLevelInformation() != m_clli) {- img->setRelativeContentLightLevelInformation(m_clli);- }-}--void KisChangeImageHdrContentLightLevelCommand::undo()-{- KisImageSP img = m_image.toStrongRef();- if (!img) return;-- img->setRelativeContentLightLevelInformation(m_oldClli);-}--int KisChangeImageHdrContentLightLevelCommand::id() const-{- return KisCommandUtils::ChangeImageHdrContentLightLevelId;-}--bool KisChangeImageHdrContentLightLevelCommand::canMergeWith(const KUndo2Command *otherCommand) const-{- const KisChangeImageHdrContentLightLevelCommand *other = dynamic_cast<const KisChangeImageHdrContentLightLevelCommand *>(otherCommand);- if (!other || other->m_image != m_image) return false;- return true;-}--bool KisChangeImageHdrContentLightLevelCommand::mergeWith(const KUndo2Command *otherCommand)-{- const KisChangeImageHdrContentLightLevelCommand *other = dynamic_cast<const KisChangeImageHdrContentLightLevelCommand *>(otherCommand);- if (!other || other->m_image != m_image) return false;-- m_clli = other->m_clli;- return true;-}diff --git a/libs/image/commands_new/KisChangeImageHdrMetadataCommand.cpp b/libs/image/commands_new/KisChangeImageHdrMetadataCommand.cppnew file mode 100644index 0000000000..2db89cef56--- /dev/null+++ b/libs/image/commands_new/KisChangeImageHdrMetadataCommand.cpp@@ -0,0 +1,65 @@+/*+ * SPDX-FileCopyrightText: 2026 Wolthera van Hövell tot Westerflier <[email protected]>+ *+ * SPDX-License-Identifier: GPL-2.0-or-later+ */+#include "KisChangeImageHdrMetadataCommand.h"+#include "kis_command_ids.h"+#include <kis_image.h>++KisChangeImageHdrMetadataCommand::KisChangeImageHdrMetadataCommand(+ KisImageWSP image,+ std::optional<double> referenceWhite,+ std::optional<KisRelativeContentLightLevelInformation> clli,+ std::optional<KisColorVolumeInformation> cvi,+ KUndo2Command *parent)+ : KUndo2Command(kundo2_i18n("Set HDR Metadata"), parent)+ , m_image(image)+ , m_referenceWhite(referenceWhite)+ , m_clli(clli)+ , m_cvi(cvi)+{+ KisImageSP img = m_image.toStrongRef();+ if (img) {+ m_oldReferenceWhite = img->hdrReferenceWhiteLightLevel();+ m_oldClli = img->relativeContentLightLevelInformation();+ m_oldCvi = img->colorVolumeInformation();+ }+}++void KisChangeImageHdrMetadataCommand::redo()+{+ KisImageSP img = m_image.toStrongRef();+ if (!img) return;++ img->setHdrReferenceWhiteLightLevel(m_referenceWhite);+ img->setRelativeContentLightLevelInformation(m_clli);+ img->setColorVolumeInformation(m_cvi);+}++void KisChangeImageHdrMetadataCommand::undo()+{+ KisImageSP img = m_image.toStrongRef();+ if (!img) return;++ img->setHdrReferenceWhiteLightLevel(m_oldReferenceWhite);+ img->setRelativeContentLightLevelInformation(m_oldClli);+ img->setColorVolumeInformation(m_oldCvi);+}++int KisChangeImageHdrMetadataCommand::id() const+{+ return KisCommandUtils::ChangeImageHdrMetadataId;+}++bool KisChangeImageHdrMetadataCommand::mergeWith(const KUndo2Command *otherCommand)+{+ const KisChangeImageHdrMetadataCommand *other = dynamic_cast<const KisChangeImageHdrMetadataCommand *>(otherCommand);+ if (!other || other->m_image != m_image) return false;++ m_referenceWhite = other->m_referenceWhite;+ m_clli = other->m_clli;+ m_cvi = other->m_cvi;++ return true;+}diff --git a/libs/image/commands_new/KisChangeImageHdrContentLightLevelCommand.h b/libs/image/commands_new/KisChangeImageHdrMetadataCommand.hsimilarity index 52%rename from libs/image/commands_new/KisChangeImageHdrContentLightLevelCommand.hrename to libs/image/commands_new/KisChangeImageHdrMetadataCommand.hindex f59c5162c7..6ebde94572 100644--- a/libs/image/commands_new/KisChangeImageHdrContentLightLevelCommand.h+++ b/libs/image/commands_new/KisChangeImageHdrMetadataCommand.h@@ -7,29 +7,35 @@#define KISCHANGEIMAGEHDRMETADATACOMMAND_H#include <kundo2command.h>-#include <commands_new/KisAsynchronouslyMergeableCommandInterface.h>#include <kis_types.h>#include <kis_hdr_metadata.h>#include "kritaimage_export.h"#include <optional>-class KRITAIMAGE_EXPORT KisChangeImageHdrContentLightLevelCommand : public KUndo2Command, public KisAsynchronouslyMergeableCommandInterface+class KRITAIMAGE_EXPORT KisChangeImageHdrMetadataCommand : public KUndo2Command{public:- KisChangeImageHdrContentLightLevelCommand(KisImageWSP image,- std::optional<KisRelativeContentLightLevelInformation> clli,- KUndo2Command *parent = nullptr);+ KisChangeImageHdrMetadataCommand(KisImageWSP image,+ std::optional<double> referenceWhite,+ std::optional<KisRelativeContentLightLevelInformation> clli,+ std::optional<KisColorVolumeInformation> cvi,+ KUndo2Command *parent = nullptr);void redo() override;void undo() override;int id() const override;- bool canMergeWith(const KUndo2Command *other) const override;bool mergeWith(const KUndo2Command *other) override;private:KisImageWSP m_image;++ std::optional<double> m_referenceWhite;std::optional<KisRelativeContentLightLevelInformation> m_clli;+ std::optional<KisColorVolumeInformation> m_cvi;++ std::optional<double> m_oldReferenceWhite;std::optional<KisRelativeContentLightLevelInformation> m_oldClli;+ std::optional<KisColorVolumeInformation> m_oldCvi;};#endif // KISCHANGEIMAGEHDRMETADATACOMMAND_Hdiff --git a/libs/image/commands_new/KisChangeImageHdrReferenceWhiteCommand.cpp b/libs/image/commands_new/KisChangeImageHdrReferenceWhiteCommand.cppdeleted file mode 100644index 807b4bfab7..0000000000--- a/libs/image/commands_new/KisChangeImageHdrReferenceWhiteCommand.cpp+++ /dev/null@@ -1,51 +0,0 @@-/*- * SPDX-FileCopyrightText: 2026 Wolthera van Hövell tot Westerflier <[email protected]>- *- * SPDX-License-Identifier: GPL-2.0-or-later- */-#include "KisChangeImageHdrReferenceWhiteCommand.h"-#include "kis_command_ids.h"-#include <kis_image.h>--KisChangeImageHdrReferenceWhiteCommand::KisChangeImageHdrReferenceWhiteCommand(KisImageWSP image,- std::optional<double> diffuseWhite,- KUndo2Command *parent)- : KUndo2Command(kundo2_i18n("Set HDR Diffuse White Light Level"), parent)- , m_image(image)- , m_diffuseWhite(diffuseWhite)-{- KisImageSP img = m_image.toStrongRef();- if (img) {- m_oldDiffuseWhite = img->hdrReferenceWhiteLightLevel();- }-}--void KisChangeImageHdrReferenceWhiteCommand::redo()-{- KisImageSP img = m_image.toStrongRef();- if (!img) return;-- img->setHdrReferenceWhiteLightLevel(m_diffuseWhite);-}--void KisChangeImageHdrReferenceWhiteCommand::undo()-{- KisImageSP img = m_image.toStrongRef();- if (!img) return;-- img->setHdrReferenceWhiteLightLevel(m_oldDiffuseWhite);-}--int KisChangeImageHdrReferenceWhiteCommand::id() const-{- return KisCommandUtils::ChangeImageHdrDiffuseWhiteId;-}--bool KisChangeImageHdrReferenceWhiteCommand::mergeWith(const KUndo2Command *otherCommand)-{- const KisChangeImageHdrReferenceWhiteCommand *other = dynamic_cast<const KisChangeImageHdrReferenceWhiteCommand *>(otherCommand);- if (!other || other->m_image != m_image) return false;-- m_diffuseWhite = other->m_diffuseWhite;- return true;-}diff --git a/libs/image/commands_new/KisChangeImageHdrReferenceWhiteCommand.h b/libs/image/commands_new/KisChangeImageHdrReferenceWhiteCommand.hdeleted file mode 100644index 218e5566e9..0000000000--- a/libs/image/commands_new/KisChangeImageHdrReferenceWhiteCommand.h+++ /dev/null@@ -1,32 +0,0 @@-/*- * SPDX-FileCopyrightText: 2026 Wolthera van Hövell tot Westerflier <[email protected]>- *- * SPDX-License-Identifier: GPL-2.0-or-later- */-#ifndef KISCHANGEIMAGEHDRREFERENCEWHITECOMMAND_H-#define KISCHANGEIMAGEHDRREFERENCEWHITECOMMAND_H--#include <kundo2command.h>-#include <kis_types.h>-#include "kritaimage_export.h"-#include <optional>--class KRITAIMAGE_EXPORT KisChangeImageHdrReferenceWhiteCommand : public KUndo2Command-{-public:- KisChangeImageHdrReferenceWhiteCommand(KisImageWSP image,- std::optional<double> diffuseWhite,- KUndo2Command *parent = nullptr);-- void redo() override;- void undo() override;-- int id() const override;- bool mergeWith(const KUndo2Command *other) override;-private:- KisImageWSP m_image;- std::optional<double> m_diffuseWhite;- std::optional<double> m_oldDiffuseWhite;-};--#endif // KISCHANGEIMAGEHDRREFERENCEWHITECOMMAND_Hdiff --git a/libs/image/kis_hdr_metadata_models.cpp b/libs/image/kis_hdr_metadata_models.cppindex b974ceeed2..02268bd4ac 100644--- a/libs/image/kis_hdr_metadata_models.cpp+++ b/libs/image/kis_hdr_metadata_models.cpp@@ -222,15 +222,6 @@ void KisHDRMetadataModel::setClli(const std::optional<KisRelativeContentLightLev}}-std::optional<KisRelativeContentLightLevelInformation> KisHDRMetadataModel::clli() const-{- const bool enabled = clliPresentData.get();- if (enabled) {- return std::make_optional(clliData.get());- }- return std::nullopt;-}-void KisHDRMetadataModel::setCvi(const std::optional<KisColorVolumeInformation> &cvi){if (cvi) {@@ -242,15 +233,6 @@ void KisHDRMetadataModel::setCvi(const std::optional<KisColorVolumeInformation>}}-std::optional<KisColorVolumeInformation> KisHDRMetadataModel::cvi() const-{- const bool enabled = cviPresentData.get();- if (enabled) {- return std::make_optional(cviData.get());- }- return std::nullopt;-}-void KisHDRMetadataModel::setImageHdrReferenceWhiteMetadata(const std::optional<double> &refWhite){if (refWhite) {@@ -262,14 +244,6 @@ void KisHDRMetadataModel::setImageHdrReferenceWhiteMetadata(const std::optional<}}-std::optional<double> KisHDRMetadataModel::imageHdrReferenceWhiteMetadata() const-{- if (referenceWhitePresentData.get() && imageProfileIsRelativeData.get()) {- return referenceWhiteData.get();- }- return std::nullopt;-}-void KisHDRMetadataModel::setImageProfileHdrReferenceWhite(const std::optional<double> &refWhite){if (refWhite) {diff --git a/libs/image/kis_hdr_metadata_models.h b/libs/image/kis_hdr_metadata_models.hindex bee4c9d7e7..5a38761688 100644--- a/libs/image/kis_hdr_metadata_models.h+++ b/libs/image/kis_hdr_metadata_models.h@@ -71,11 +71,8 @@ public:LAGER_QT_CURSOR(double, cviMinLuminance);void setClli(const std::optional<KisRelativeContentLightLevelInformation> &clli);- std::optional<KisRelativeContentLightLevelInformation> clli() const;void setCvi(const std::optional<KisColorVolumeInformation> &cvi);- std::optional<KisColorVolumeInformation> cvi() const;void setImageHdrReferenceWhiteMetadata(const std::optional<double> &refWhite);- std::optional<double> imageHdrReferenceWhiteMetadata() const;void setImageProfileHdrReferenceWhite(const std::optional<double> &refWhite);};diff --git a/libs/ui/dialogs/kis_dlg_image_properties.cc b/libs/ui/dialogs/kis_dlg_image_properties.ccindex f0dc55dd00..e5ffa87d3b 100644--- a/libs/ui/dialogs/kis_dlg_image_properties.cc+++ b/libs/ui/dialogs/kis_dlg_image_properties.cc@@ -32,9 +32,8 @@#include <kis_types.h>#include <kis_group_layer.h>-#include <commands_new/KisChangeImageHdrContentLightLevelCommand.h>-#include <commands_new/KisChangeImageHdrColorVolumeCommand.h>-#include <commands_new/KisChangeImageHdrReferenceWhiteCommand.h>+#include <commands_new/KisChangeImageHdrMetadataCommand.h>+#include <KisContentLightLevelProcessingVistor.h>#include <kis_signal_compressor_with_param.h>@@ -209,9 +208,26 @@ int KisDlgImageProperties::exec()} else {d->image->setProofingConfiguration(nullptr);}- setHDRDiffuseWhiteOnImage();- setHDRLightLevelsOnImage();- setHDRColorVolumeOnImage();++ std::optional<double> effectiveHdrReferenceWhite = d->hdrMetadataModel.effectiveReferenceWhite();+ std::optional<KisRelativeContentLightLevelInformation> effectiveClli;+ std::optional<KisColorVolumeInformation> effectiveCvi;++ if (d->hdrMetadataModel.effectiveClliPresent()) {+ effectiveClli = d->hdrMetadataModel.clliData.get();+ }++ if (d->hdrMetadataModel.cviPresent()) {+ effectiveCvi = d->hdrMetadataModel.cviData.get();+ }++ if (effectiveHdrReferenceWhite != d->image->hdrReferenceWhiteLightLevel() ||+ effectiveClli != d->image->relativeContentLightLevelInformation() ||+ effectiveCvi != d->image->colorVolumeInformation()) {++ KUndo2Command *cmd = new KisChangeImageHdrMetadataCommand(d->image, effectiveHdrReferenceWhite, effectiveClli, effectiveCvi);+ KisProcessingApplicator::runSingleCommandStroke(d->image, cmd);+ }} else {d->image->setProofingConfiguration(d->originalProofingConfig);}@@ -253,34 +269,6 @@ void KisDlgImageProperties::updateDisplayConfigInfo()m_page->wdgProofingOptions->setDisplayConfigOptions(d->colorConverter->conversionOptions());}-void KisDlgImageProperties::setHDRLightLevelsOnImage()-{- std::optional<KisRelativeContentLightLevelInformation> optClli = d->hdrMetadataModel.clli();-- if (d->image->relativeContentLightLevelInformation() != optClli) {- KisProcessingApplicator::runSingleCommandStroke(d->image,- new KisChangeImageHdrContentLightLevelCommand(d->image, optClli));- }-}--void KisDlgImageProperties::setHDRDiffuseWhiteOnImage()-{- std::optional<double> dw = d->hdrMetadataModel.imageHdrReferenceWhiteMetadata();- if (d->image->hdrReferenceWhiteLightLevel() != dw) {- KUndo2Command *cmd = new KisChangeImageHdrReferenceWhiteCommand(d->image, dw);- d->image->undoAdapter()->addCommand(cmd);- }-}--void KisDlgImageProperties::setHDRColorVolumeOnImage()-{- std::optional<KisColorVolumeInformation> optCvi = d->hdrMetadataModel.cvi();- if (d->image->colorVolumeInformation() != optCvi) {- KUndo2Command *cmd = new KisChangeImageHdrColorVolumeCommand(d->image, optCvi);- d->image->undoAdapter()->addCommand(cmd);- }-}-void KisDlgImageProperties::slotCalculateLightLevels(){KisRelativeContentLightLevelInformation::CalculationType type = d->hdrMetadataModel.clliCalculationType();diff --git a/libs/ui/dialogs/kis_dlg_image_properties.h b/libs/ui/dialogs/kis_dlg_image_properties.hindex a1e9768edd..e38a30249a 100644--- a/libs/ui/dialogs/kis_dlg_image_properties.h+++ b/libs/ui/dialogs/kis_dlg_image_properties.h@@ -45,10 +45,6 @@ private Q_SLOTS:void setProofingConfigToImage();void updateDisplayConfigInfo();- void setHDRDiffuseWhiteOnImage();- void setHDRLightLevelsOnImage();- void setHDRColorVolumeOnImage();-void slotCalculateLightLevels();void slotColorSpaceChanged(const KoColorSpace*);