QGIM: do nothing in resetParent if model doesn't hold values
Move the check into the implementation. Change-Id: I553f4883e9bf7bcccbfc66e009a5f7fc22fb03c5 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
This commit is contained in:
parent
7718dcb53c
commit
fffe4f32dd
@ -812,11 +812,10 @@ public:
|
|||||||
} else {
|
} else {
|
||||||
children->insert(pos, count, *generator);
|
children->insert(pos, count, *generator);
|
||||||
}
|
}
|
||||||
if constexpr (!rows_are_raw_pointers) {
|
|
||||||
// fix the parent in all children of the modified row, as the
|
// fix the parent in all children of the modified row, as the
|
||||||
// references back to the parent might have become invalid.
|
// references back to the parent might have become invalid.
|
||||||
that().resetParentInChildren(children);
|
that().resetParentInChildren(children);
|
||||||
}
|
|
||||||
|
|
||||||
endInsertRows();
|
endInsertRows();
|
||||||
return true;
|
return true;
|
||||||
@ -857,8 +856,8 @@ public:
|
|||||||
}
|
}
|
||||||
// fix the parent in all children of the modified row, as the
|
// fix the parent in all children of the modified row, as the
|
||||||
// references back to the parent might have become invalid.
|
// references back to the parent might have become invalid.
|
||||||
if constexpr (!rows_are_raw_pointers)
|
|
||||||
that().resetParentInChildren(children);
|
that().resetParentInChildren(children);
|
||||||
|
|
||||||
if constexpr (dynamicColumns()) {
|
if constexpr (dynamicColumns()) {
|
||||||
if (callEndRemoveColumns) {
|
if (callEndRemoveColumns) {
|
||||||
Q_ASSERT(that().columnCount(parent) == 0);
|
Q_ASSERT(that().columnCount(parent) == 0);
|
||||||
@ -904,7 +903,6 @@ public:
|
|||||||
else // moving up
|
else // moving up
|
||||||
std::rotate(last, first, middle);
|
std::rotate(last, first, middle);
|
||||||
|
|
||||||
if constexpr (!rows_are_raw_pointers)
|
|
||||||
that().resetParentInChildren(source);
|
that().resetParentInChildren(source);
|
||||||
|
|
||||||
endMoveRows();
|
endMoveRows();
|
||||||
@ -1181,7 +1179,9 @@ class QGenericTreeItemModelImpl
|
|||||||
Protocol>;
|
Protocol>;
|
||||||
static constexpr bool is_mutable_impl = tree_traits::has_mutable_childRows;
|
static constexpr bool is_mutable_impl = tree_traits::has_mutable_childRows;
|
||||||
|
|
||||||
|
static constexpr bool rows_are_any_refs_or_pointers = Base::rows_are_raw_pointers ||
|
||||||
|
QGenericItemModelDetails::is_smart_ptr<row_type>() ||
|
||||||
|
QGenericItemModelDetails::is_any_of<row_type, std::reference_wrapper>();
|
||||||
static_assert(!Base::dynamicColumns(), "A tree must have a static number of columns!");
|
static_assert(!Base::dynamicColumns(), "A tree must have a static number of columns!");
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@ -1256,7 +1256,7 @@ protected:
|
|||||||
// We must not insert rows if we cannot adjust the parents of the
|
// We must not insert rows if we cannot adjust the parents of the
|
||||||
// children of the following rows. We don't have to do that if the
|
// children of the following rows. We don't have to do that if the
|
||||||
// range operates on pointers.
|
// range operates on pointers.
|
||||||
return (Base::rows_are_raw_pointers || tree_traits::has_setParentRow)
|
return (rows_are_any_refs_or_pointers || tree_traits::has_setParentRow)
|
||||||
&& Base::dynamicRows() && range_features::has_insert;
|
&& Base::dynamicRows() && range_features::has_insert;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1265,7 +1265,7 @@ protected:
|
|||||||
// We must not remove rows if we cannot adjust the parents of the
|
// We must not remove rows if we cannot adjust the parents of the
|
||||||
// children of the following rows. We don't have to do that if the
|
// children of the following rows. We don't have to do that if the
|
||||||
// range operates on pointers.
|
// range operates on pointers.
|
||||||
return (Base::rows_are_raw_pointers || tree_traits::has_setParentRow)
|
return (rows_are_any_refs_or_pointers || tree_traits::has_setParentRow)
|
||||||
&& Base::dynamicRows() && range_features::has_erase;
|
&& Base::dynamicRows() && range_features::has_erase;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1285,7 +1285,7 @@ protected:
|
|||||||
// If rows are pointers, then reference to the parent row don't
|
// If rows are pointers, then reference to the parent row don't
|
||||||
// change, so we can move them around freely. Otherwise we need to
|
// change, so we can move them around freely. Otherwise we need to
|
||||||
// be able to explicitly update the parent pointer.
|
// be able to explicitly update the parent pointer.
|
||||||
if constexpr (!Base::rows_are_raw_pointers && !tree_traits::has_setParentRow) {
|
if constexpr (!rows_are_any_refs_or_pointers && !tree_traits::has_setParentRow) {
|
||||||
return false;
|
return false;
|
||||||
} else if constexpr (!(range_features::has_insert && range_features::has_erase)) {
|
} else if constexpr (!(range_features::has_insert && range_features::has_erase)) {
|
||||||
return false;
|
return false;
|
||||||
@ -1349,10 +1349,8 @@ protected:
|
|||||||
// ranges, as the references to the entries might have become invalid.
|
// ranges, as the references to the entries might have become invalid.
|
||||||
// We don't have to do that if the rows are pointers, as in that case
|
// We don't have to do that if the rows are pointers, as in that case
|
||||||
// the references to the entries are stable.
|
// the references to the entries are stable.
|
||||||
if constexpr (!Base::rows_are_raw_pointers) {
|
|
||||||
resetParentInChildren(destination);
|
resetParentInChildren(destination);
|
||||||
resetParentInChildren(source);
|
resetParentInChildren(source);
|
||||||
}
|
|
||||||
|
|
||||||
this->endMoveRows();
|
this->endMoveRows();
|
||||||
return true;
|
return true;
|
||||||
@ -1388,7 +1386,7 @@ protected:
|
|||||||
|
|
||||||
void resetParentInChildren(range_type *children)
|
void resetParentInChildren(range_type *children)
|
||||||
{
|
{
|
||||||
if constexpr (tree_traits::has_setParentRow) {
|
if constexpr (tree_traits::has_setParentRow && !rows_are_any_refs_or_pointers) {
|
||||||
const auto begin = QGenericItemModelDetails::begin(*children);
|
const auto begin = QGenericItemModelDetails::begin(*children);
|
||||||
const auto end = QGenericItemModelDetails::end(*children);
|
const auto end = QGenericItemModelDetails::end(*children);
|
||||||
for (auto it = begin; it != end; ++it) {
|
for (auto it = begin; it != end; ++it) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user