diff --git a/src/corelib/itemmodels/qrangemodel_impl.h b/src/corelib/itemmodels/qrangemodel_impl.h index 2ec01e45a4a..efd1fbd2aa2 100644 --- a/src/corelib/itemmodels/qrangemodel_impl.h +++ b/src/corelib/itemmodels/qrangemodel_impl.h @@ -1187,33 +1187,34 @@ public: Qt::ItemFlags f = Structure::defaultFlags(); - if constexpr (row_traits::hasMetaObject) { - if (index.column() < row_traits::fixed_size()) { - const QMetaObject mo = wrapped_row_type::staticMetaObject; - const QMetaProperty prop = mo.property(index.column() + mo.propertyOffset()); - if (prop.isWritable()) - f |= Qt::ItemIsEditable; - } - } else if constexpr (static_column_count <= 0) { - if constexpr (isMutable()) - f |= Qt::ItemIsEditable; - } else if constexpr (std::is_reference_v && !std::is_const_v) { - // we want to know if the elements in the tuple are const; they'd always be, if - // we didn't remove the const of the range first. - const_row_reference row = rowData(index); - row_reference mutableRow = const_cast(row); - if (QRangeModelDetails::isValid(mutableRow)) { - QRangeModelImplBase::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) + if constexpr (isMutable()) { + if constexpr (row_traits::hasMetaObject) { + if (index.column() < row_traits::fixed_size()) { + const QMetaObject mo = wrapped_row_type::staticMetaObject; + const QMetaProperty prop = mo.property(index.column() + mo.propertyOffset()); + if (prop.isWritable()) 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; + } + } else if constexpr (static_column_count <= 0) { + f |= Qt::ItemIsEditable; + } else if constexpr (std::is_reference_v && !std::is_const_v) { + // we want to know if the elements in the tuple are const; they'd always be, if + // we didn't remove the const of the range first. + const_row_reference row = rowData(index); + row_reference mutableRow = const_cast(row); + if (QRangeModelDetails::isValid(mutableRow)) { + QRangeModelImplBase::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; @@ -2399,7 +2400,7 @@ protected: { if constexpr (tree_traits::has_deleteRow) { for (auto it = begin; it != end; ++it) { - if constexpr (is_mutable_impl) { + if constexpr (Base::isMutable()) { decltype(auto) children = this->protocol().childRows(QRangeModelDetails::refTo(*it)); if (QRangeModelDetails::isValid(children)) { deleteRemovedRows(QRangeModelDetails::begin(children), diff --git a/tests/auto/corelib/itemmodels/qrangemodel/tst_qrangemodel.cpp b/tests/auto/corelib/itemmodels/qrangemodel/tst_qrangemodel.cpp index c7490fface8..5c865ac357d 100644 --- a/tests/auto/corelib/itemmodels/qrangemodel/tst_qrangemodel.cpp +++ b/tests/auto/corelib/itemmodels/qrangemodel/tst_qrangemodel.cpp @@ -1433,9 +1433,12 @@ void tst_QRangeModel::tree() QFETCH(const int, expectedRootRowCount); QFETCH(const int, expectedColumnCount); QFETCH(QList, rowsWithChildren); + QFETCH(ChangeActions, changeActions); QCOMPARE(model->rowCount(), expectedRootRowCount); QCOMPARE(model->columnCount(), expectedColumnCount); + QCOMPARE(model->flags(model->index(0, 0)).testFlag(Qt::ItemIsEditable), + !!(changeActions & ChangeAction::SetData)); for (int row = 0; row < model->rowCount(); ++row) { const bool expectedChildren = rowsWithChildren.contains(row);