From 2332f827c5344dae2a528fb61f720694a364bffa Mon Sep 17 00:00:00 2001 From: Volker Hilsheimer Date: Thu, 27 Mar 2025 15:21:38 +0100 Subject: [PATCH] QGIM: check that row is valid also in flags() While we never access the data, accessing a MultiColumn item holding a nullptr would still dereference that nullptr, and then pass that reference to our lambda. And the results are misleading: if there is no gadget or object stored for that row yet, then the item is not editable - nothing can be stored. Change-Id: Ic24242296f8cdedae6e36a12da470831eb93ee2a Reviewed-by: Artem Dyomin --- src/corelib/itemmodels/qgenericitemmodel.h | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/corelib/itemmodels/qgenericitemmodel.h b/src/corelib/itemmodels/qgenericitemmodel.h index 3c6e2aeb1c8..05941f4a890 100644 --- a/src/corelib/itemmodels/qgenericitemmodel.h +++ b/src/corelib/itemmodels/qgenericitemmodel.h @@ -240,13 +240,19 @@ public: // we didn't remove the const of the range first. const_row_reference row = rowData(index); row_reference mutableRow = const_cast(row); - for_element_at(mutableRow, index.column(), [&f](auto &&ref){ - using target_type = decltype(ref); - if constexpr (std::is_const_v>) - f &= ~Qt::ItemIsEditable; - else if constexpr (std::is_lvalue_reference_v) - f |= Qt::ItemIsEditable; - }); + if (QGenericItemModelDetails::isValid(mutableRow)) { + for_element_at(mutableRow, index.column(), [&f](auto &&ref){ + using target_type = decltype(ref); + if constexpr (std::is_const_v>) + f &= ~Qt::ItemIsEditable; + else if constexpr (std::is_lvalue_reference_v) + f |= Qt::ItemIsEditable; + }); + } else { + // If there's no usable value stored in the row, then we can't + // do anything with this item. + f &= ~Qt::ItemIsEditable; + } } return f; }