From 47cf0433294e3878416dc436bd27fb6efb6fcdc8 Mon Sep 17 00:00:00 2001 From: Artem Dyomin Date: Sat, 22 Mar 2025 00:51:03 +0100 Subject: [PATCH] QGIM: Add utilities for generic access of keys and values of iterators Since Qt associative containers don't have the same iterator API as their std equivalents, generic access to the key/value pair of a container will be useful when adding support for multi-role storage types and sparse tables. Change-Id: I409e94485257982ac8a231f9bffd791a53867968 Reviewed-by: Volker Hilsheimer --- src/corelib/itemmodels/qgenericitemmodel_impl.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/corelib/itemmodels/qgenericitemmodel_impl.h b/src/corelib/itemmodels/qgenericitemmodel_impl.h index b545a8eade8..9b03be109f1 100644 --- a/src/corelib/itemmodels/qgenericitemmodel_impl.h +++ b/src/corelib/itemmodels/qgenericitemmodel_impl.h @@ -155,6 +155,18 @@ namespace QGenericItemModelDetails template static auto pointerTo(T &t) { return std::addressof(t); } template static auto pointerTo(const T &&t) = delete; + template + auto key(It&& it) -> decltype(it.key()) { return it.key(); } + + template + auto key(It&& it) -> decltype((it->first) /*pars for ref type*/ ) { return it->first; } + + template + auto value(It&& it) -> decltype(it.value()) { return it.value(); } + + template + auto value(It&& it) -> decltype((it->second)) { return it->second; } + // The storage of the model data. We might store it as a pointer, or as a // (copied- or moved-into) value. But we always return a pointer. template