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++
Implement kiszug::has_value
Dmitry Kazakov98ea24d9519a
diff --git a/libs/global/KisZug.h b/libs/global/KisZug.hindex 4d37d3e0a8..840b26ceaf 100644--- a/libs/global/KisZug.h+++ b/libs/global/KisZug.h@@ -63,6 +63,9 @@ inline constexpr auto map_less_equal<qreal> = [] (qreal value) { return zug::mapconstexpr auto map_round = zug::map([](qreal x) -> int { return qRound(x); });+// a state getter for an std::optional+constexpr auto has_value = zug::map([](auto&& x) -> bool { return x.has_value(); });+struct empty_t{};diff --git a/libs/global/tests/CMakeLists.txt b/libs/global/tests/CMakeLists.txtindex a947485d66..a53fb39acd 100644--- a/libs/global/tests/CMakeLists.txt+++ b/libs/global/tests/CMakeLists.txt@@ -2,6 +2,7 @@ kis_add_tests(KisSignalAutoConnectionTest.cppKisSignalCompressorTest.cppKisForestTest.cppKisMplTest.cpp+ KisLagerTest.cppKisRectsGridTest.cppKisLazyStorageTest.cppKisValueCacheTest.cppdiff --git a/libs/global/tests/KisLagerTest.cpp b/libs/global/tests/KisLagerTest.cppnew file mode 100644index 0000000000..19f5d4ed8a--- /dev/null+++ b/libs/global/tests/KisLagerTest.cpp@@ -0,0 +1,38 @@+/*+ * SPDX-FileCopyrightText: 2026 Dmitry Kazakov <[email protected]>+ *+ * SPDX-License-Identifier: GPL-2.0-or-later+ */+#include "KisLagerTest.h"++#include <simpletest.h>++#include <kis_debug.h>++#include <optional>++#include <lager/state.hpp>++#include <KisLager.h>+#include <KisZug.h>+++void KisLagerTest::testOptionalHasValue()+{+ auto x = lager::state<std::optional<int>, lager::automatic_tag>{};+ x.set(11);++ // connect to the presence state+ auto isPresentReader = lager::reader<bool>{x.xform(kiszug::has_value)};+ auto valueReader = lager::reader<int>{x.zoom(lager::lenses::value_or(42))};++ QCOMPARE(isPresentReader.get(), true);+ QCOMPARE(valueReader.get(), 11);++ x.set(std::nullopt);++ QCOMPARE(isPresentReader.get(), false);+ QCOMPARE(valueReader.get(), 42);+}++SIMPLE_TEST_MAIN(KisLagerTest)diff --git a/libs/global/tests/KisLagerTest.h b/libs/global/tests/KisLagerTest.hnew file mode 100644index 0000000000..e9d9342fd7--- /dev/null+++ b/libs/global/tests/KisLagerTest.h@@ -0,0 +1,18 @@+/*+ * SPDX-FileCopyrightText: 2026 Dmitry Kazakov <[email protected]>+ *+ * SPDX-License-Identifier: GPL-2.0-or-later+ */+#ifndef KISLAGERTEST_H+#define KISLAGERTEST_H++#include <QTest>++class KisLagerTest : public QObject+{+ Q_OBJECT+private Q_SLOTS:+ void testOptionalHasValue();+};++#endif // KISLAGERTEST_H