QGIM: simplify EmptyRowGenerator
Make it constructible without a model so that we can default-construct entries in flat ranges. Change-Id: I51a97733a0de0b55d8cdbbca56ff528edd557ba6 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
This commit is contained in:
parent
5898d8da9a
commit
7718dcb53c
@ -242,7 +242,7 @@ protected:
|
|||||||
using iterator_category = std::input_iterator_tag;
|
using iterator_category = std::input_iterator_tag;
|
||||||
using difference_type = int;
|
using difference_type = int;
|
||||||
|
|
||||||
value_type operator*() { return impl.makeEmptyRow(parent); }
|
value_type operator*() { return impl->makeEmptyRow(*parent); }
|
||||||
EmptyRowGenerator &operator++() { ++n; return *this; }
|
EmptyRowGenerator &operator++() { ++n; return *this; }
|
||||||
friend bool operator==(const EmptyRowGenerator &lhs, const EmptyRowGenerator &rhs) noexcept
|
friend bool operator==(const EmptyRowGenerator &lhs, const EmptyRowGenerator &rhs) noexcept
|
||||||
{ return lhs.n == rhs.n; }
|
{ return lhs.n == rhs.n; }
|
||||||
@ -250,8 +250,8 @@ protected:
|
|||||||
{ return !(lhs == rhs); }
|
{ return !(lhs == rhs); }
|
||||||
|
|
||||||
difference_type n = 0;
|
difference_type n = 0;
|
||||||
Structure &impl;
|
Structure *impl = nullptr;
|
||||||
const QModelIndex parent;
|
const QModelIndex* parent = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
// If we have a move-only row_type and can add/remove rows, then the range
|
// If we have a move-only row_type and can add/remove rows, then the range
|
||||||
@ -799,20 +799,18 @@ public:
|
|||||||
if (!children)
|
if (!children)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
EmptyRowGenerator generator{0, &that(), &parent};
|
||||||
|
|
||||||
beginInsertRows(parent, row, row + count - 1);
|
beginInsertRows(parent, row, row + count - 1);
|
||||||
|
|
||||||
const auto pos = QGenericItemModelDetails::pos(children, row);
|
const auto pos = QGenericItemModelDetails::pos(children, row);
|
||||||
if constexpr (range_features::has_insert_range) {
|
if constexpr (range_features::has_insert_range) {
|
||||||
EmptyRowGenerator first{0, that(), parent};
|
children->insert(pos, generator, EmptyRowGenerator{count});
|
||||||
EmptyRowGenerator last{count, that(), parent};
|
} else if constexpr (rows_are_owning_or_raw_pointers) {
|
||||||
children->insert(pos, first, last);
|
auto start = children->insert(pos, count, row_type{});
|
||||||
} else if constexpr (rows_are_raw_pointers) {
|
std::copy(generator, EmptyRowGenerator{count}, start);
|
||||||
auto start = children->insert(pos, count, nullptr);
|
|
||||||
auto end = std::next(start, count);
|
|
||||||
for (auto it = start; it != end; ++it)
|
|
||||||
*it = that().makeEmptyRow(parent);
|
|
||||||
} else {
|
} else {
|
||||||
children->insert(pos, count, that().makeEmptyRow(parent));
|
children->insert(pos, count, *generator);
|
||||||
}
|
}
|
||||||
if constexpr (!rows_are_raw_pointers) {
|
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
|
||||||
|
Loading…
x
Reference in New Issue
Block a user