5#ifndef QRANGEMODEL_IMPL_H
6#define QRANGEMODEL_IMPL_H
11#error Do not include qrangemodel_impl.h directly
15#pragma qt_sync_skip_header_check
16#pragma qt_sync_stop_processing
19#include <QtCore/qabstractitemmodel.h>
20#include <QtCore/qcollator.h>
21#include <QtCore/qquasivirtual_impl.h>
22#include <QtCore/qmetaobject.h>
23#include <QtCore/qvariant.h>
24#include <QtCore/qmap.h>
25#include <QtCore/qscopedvaluerollback.h>
26#include <QtCore/qset.h>
27#include <QtCore/qregularexpression.h>
28#include <QtCore/qvarlengtharray.h>
34#include <QtCore/qxptype_traits.h>
36#include <QtCore/q23utility.h>
42 template <
typename T,
template <
typename...>
typename... Templates>
45 template <
template <
typename...>
typename Template,
47 template <
typename...>
typename...
Templates>
51 template <
typename...>
typename Template,
52 template <
typename...>
typename...
Templates>
55 template <
typename T,
template <
typename...>
typename...
Templates>
58 template <
typename T,
typename =
void>
65 template <
typename T,
typename =
void>
82#ifndef QT_NO_SCOPED_POINTER
100 using Type = q20::remove_cvref_t<T>;
101 if constexpr (is_any_of<Type, std::optional>())
102 return t ?
std::addressof(*
std::forward<T>(t)) :
nullptr;
103 else if constexpr (std::is_pointer<Type>())
105 else if constexpr (is_smart_ptr<Type>())
107 else if constexpr (is_any_of<Type, std::reference_wrapper>())
108 return std::addressof(t.get());
110 return std::addressof(
std::forward<T>(t));
113 template <
typename T>
123 template <
typename T>
126 template <
typename T>
131 template <
typename T,
typename =
void>
135 template <
typename T>
138 template <
typename T>
141 template <
typename T,
typename =
void>
147 template <
typename T>
150 template <
typename T,
typename =
void>
152 template <
typename T>
155 template <
typename T>
158 template <
typename T>
159 static constexpr bool isValid(
const T &t)
noexcept
161 if constexpr (
std::is_array_v<T>)
163 else if constexpr (is_validatable<T>())
169 template <
typename T>
170 static decltype(
auto)
refTo(T&& t) {
173 using Type = q20::remove_cvref_t<T>;
174 if constexpr (is_any_of<T, std::optional>())
175 return *
std::forward<T>(t);
176 if constexpr (!is_wrapped<Type>() || is_any_unique_ptr<Type>())
177 return q23::forward_like<T>(*QRangeModelDetails::pointerTo(t));
182 template <
typename It>
183 auto key(It&& it) ->
decltype(it.key()) {
return std::forward<It>(it).key(); }
184 template <
typename It>
185 auto key(It&& it) ->
decltype((it->first)) {
return std::forward<It>(it)->first; }
187 template <
typename It>
188 auto value(It&& it) ->
decltype(it.value()) {
return std::forward<It>(it).value(); }
189 template <
typename It>
190 auto value(It&& it) ->
decltype((it->second)) {
return std::forward<It>(it)->second; }
196 template <
typename C>
199 template <
typename C>
202 template <
typename C>
203 static auto pos(C &&c,
int i)
211 template <
typename C,
typename =
void>
214 template <
typename C>
225 template <
typename C,
typename =
void>
228 template <
typename C>
237 template <
typename C,
typename =
void>
240 template <
typename C>
248 template <
typename C,
typename =
void>
251 template <
typename C>
262 template <
typename It>
264 std::is_swappable<
decltype(*
std::declval<It>())>,
265 std::is_base_of<
std::forward_iterator_tag,
269 template <
typename C,
typename =
void>
272 template <
typename C>
282 template <
typename C>
283 static void rotate(C& c,
int src,
int count,
int dst) {
285 using Container = std::remove_reference_t<
decltype(container)>;
288 const auto srcEnd =
std::next(srcBegin, count);
291 if constexpr (test_splice<Container>::value) {
292 if (dst > src && dst < src + count)
293 container.splice(srcBegin, container, dstBegin, srcEnd);
295 container.splice(dstBegin, container, srcBegin, srcEnd);
298 std::rotate(srcBegin, srcEnd, dstBegin);
300 std::rotate(dstBegin, srcBegin, srcEnd);
313 template <
typename C>
322 template <
typename C>
327 template <
typename C,
typename =
void>
329 template <
typename C>
332 template <
typename C,
typename =
void>
334 template <
typename C>
339 template <
typename C,
typename =
void>
350 template <
typename C>
391 template <
typename C>
393 template <
typename C>
399 template <
typename T>
408 static constexpr bool hasReadRole = qxp::is_detected_v<hasReadRole_test, ItemAccess, ItemType>;
413 static constexpr bool hasWriteRole = qxp::is_detected_v<hasWriteRole_test, ItemAccess, ItemType>;
415 template <
typename Access,
typename Test>
418 static constexpr bool hasFlags = qxp::is_detected_v<hasFlags_test, ItemAccess, ItemType>;
420 template <
typename Access,
typename Test>
422 static constexpr bool hasMimeTypes = qxp::is_detected_v<hasMimeTypes_test, ItemAccess, ItemType>;
426 static constexpr bool hasMimeData = qxp::is_detected_v<hasMimeData_test, ItemAccess, ItemType>;
428 template <
typename Access>
439 ItemAccess, ItemType>;
442 template <
typename Access>
455 ItemAccess, ItemType>;
462 template <
typename T,
typename =
void>
468 template <
typename T>
482 template <
typename row_type>
485 static constexpr bool hasRowFlags = qxp::is_detected_v<hasRowFlags_test, row_type>;
488 template <
typename row_type>
491 static constexpr bool hasMimeTypes = qxp::is_detected_v<hasMimeTypes_test, row_type>;
519 static constexpr bool hasDropMimeData = qxp::is_detected_v<hasDropMimeData_test, row_type>;
542 template <
typename T,
typename =
void>
559 template <
typename C,
typename Fn>
565 return std::forward<Fn>(fn)(
std::forward<C>(container));
568 template <
typename Fn>
574 int columnIndex = -1;
577 return std::forward<Fn>(fn)(firstIndex.siblingAtColumn(++columnIndex),
585 template <
typename T>
605 template <
typename C,
typename F>
640 template <
typename Fn>
660 template <
typename C,
typename F>
672 template <
typename Fn>
688 template <
typename T>
709 template <
typename C,
typename F>
729 template <
typename Fn>
736 template <
typename T,
typename =
void>
739 template <
typename That>
742 return That::roleNamesForSimpleType();
749 template <
typename That>
756 template <
typename T>
762 template <
typename T>
765 template <
typename That>
772 template <
typename T>
776 template <
typename Range>
782 auto newRow() ->
decltype(R{}) {
return R{}; }
785 template <
typename Range>
813 template <
typename Range,
821 template <
typename Range>
824 template <
typename R >
825 auto parentRow(
const R& row)
const ->
decltype(row.parentRow())
827 return row.parentRow();
830 template <
typename R >
831 auto setParentRow(R &row, R* parent) ->
decltype(row.setParentRow(parent))
833 row.setParentRow(parent);
836 template <
typename R >
837 auto childRows(
const R &row)
const ->
decltype(row.childRows())
839 return row.childRows();
842 template <
typename R >
845 return row.childRows();
849 template <
typename P,
typename R>
852 template <
typename P,
typename R>
855 template <
typename P,
typename R>
858 template <
typename P,
typename R>
861 template <
typename P,
typename R>
865 template <
typename P,
typename R>
868 template <
typename P,
typename R>
871 template <
typename P,
typename R>
874 template <
typename P,
typename =
void>
876 template <
typename P>
880 template <
typename P,
typename R,
typename =
void>
882 template <
typename P,
typename R>
887 template <
typename Range,
899 template <
typename Range>
912 template <
typename Range,
typename Protocol>
936 template <
typename Entry>
941 template<
typename T,
typename =
void>
952 if constexpr (QRangeModelDetails::is_owning_or_raw_pointer<entry_type>()) {
958 qDebug(
"QRangeModel::mimeData: null-entry, test with isValid before accessing");
960 constexpr bool is_constexpr_default_constructible_v =
961 is_constexpr_default_constructible<wrapped_entry>::value;
962 if constexpr (is_constexpr_default_constructible_v) {
963 Q_CONSTINIT
static const wrapped_entry emptyDefault;
967 static const wrapped_entry emptyDefault;
972 return std::as_const(QRangeModelDetails::refTo(m_entry));
977 template <
std::size_t N>
980 if constexpr (N == 0)
981 return entry.entry();
982 else if constexpr (N == 1)
983 return entry.index();
1000template <
typename T>
1012 template <
typename Entry>
1025 return lhs.m_row == rhs.m_row && lhs.m_column == rhs.m_column;
1061 template <
bool cacheProperties,
bool itemsAreQObjects>
1093 return lhs.sender == rhs.sender && lhs
.role == rhs
.role;
1097 return qHashMulti(seed, c.sender, c
.role);
1121 template <
typename ModelStorage,
typename =
void>
1140 template <
typename ModelStorage,
typename PropertyStorage>
1151 template <
typename Model = ModelStorage>
1187 bool setHeaderData(
int section, Qt::Orientation orientation,
const QVariant &data,
int role);
1188 bool setData(
const QModelIndex &index,
const QVariant &data,
int role);
1189 bool setItemData(
const QModelIndex &index,
const QMap<
int, QVariant> &data);
1193 bool moveColumns(
const QModelIndex &sourceParent,
int sourceColumn,
int count,
const QModelIndex &destParent,
int destColumn);
1196 bool moveRows(
const QModelIndex &sourceParent,
int sourceRow,
int count,
const QModelIndex &destParent,
int destRow);
1209 void multiData(
const QModelIndex &index, QModelRoleDataSpan roleDataSpan)
const;
1213 void sort(
int column, Qt::SortOrder order);
1215 int hits, Qt::MatchFlags flags)
const;
1221 const QModelIndex &parent)
const;
1222 bool dropMimeData(
const QMimeData *data, Qt::DropAction action,
int row,
int column,
1223 const QModelIndex &parent);
1267 template <
typename C>
1308 friend class QRangeModelPrivate;
1311 QRangeModel *m_rangeModel;
1315 : m_rangeModel(itemModel)
1321 inline void dataChanged(
const QModelIndex &from,
const QModelIndex &to,
1322 const QList<
int> &roles);
1329 inline bool beginMoveColumns(
const QModelIndex &sourceParent,
int sourceFirst,
int sourceLast,
1330 const QModelIndex &destParent,
int destRow);
1332 inline void beginInsertRows(
const QModelIndex &parent,
int start,
int count);
1334 inline void beginRemoveRows(
const QModelIndex &parent,
int start,
int count);
1336 inline bool beginMoveRows(
const QModelIndex &sourceParent,
int sourceFirst,
int sourceLast,
1337 const QModelIndex &destParent,
int destRow);
1343 const QCollator *collator);
1361 QRangeModelDetails::AutoConnectContext *context,
1362 int role,
const QMetaProperty &property);
1364 QRangeModelDetails::AutoConnectContext *context,
1365 int role,
const QMetaProperty &property);
1367 QRangeModelDetails::AutoConnectContext *context,
1368 const QHash<
int, QMetaProperty> &properties);
1370 QRangeModelDetails::AutoConnectContext *context,
1371 const QHash<
int, QMetaProperty> &properties);
1377 Qt::MatchFlags flags);
1378 static bool matchValue(
const QVariant &itemData,
const QVariant &value, Qt::MatchFlags flags)
1380 if ((flags & Qt::MatchTypeMask) == Qt::MatchExactly)
1381 return itemData == value;
1382 return matchValue(itemData.toString(), value, flags);
1388template <
typename Structure,
typename Range,
1389 typename Protocol = QRangeModelDetails::table_protocol_t<Range>>
1425 "Currently, std::optional is not supported for ranges and rows, as "
1426 "it has range semantics in c++26. Once the required behavior is clarified, "
1427 "std::optional for ranges and rows will be supported.");
1434 Structure&
that() {
return static_cast<Structure &>(*
this); }
1435 const Structure&
that()
const {
return static_cast<
const Structure &>(*
this); }
1437 template <
typename C>
1438 static constexpr int size(
const C &c)
1443 if constexpr (QRangeModelDetails::test_size<C>()) {
1445 return int(size(c));
1447#if defined(__cpp_lib_ranges)
1448 using std::ranges::distance;
1450 using std::distance;
1452 using container_type = std::conditional_t<QRangeModelDetails::range_traits<C>::has_cbegin,
1453 const QRangeModelDetails::wrapped_t<C>,
1454 QRangeModelDetails::wrapped_t<C>>;
1455 container_type& container =
const_cast<container_type &>(
QRangeModelDetails::refTo(c));
1471 return this->blockDataChangedDispatch();
1481 template <
typename T>
1501 {
return lhs.n == rhs.n; }
1503 {
return !(lhs == rhs); }
1514 "The range holding a move-only row-type must support insert(pos, start, end)");
1522 return range_features::is_mutable && row_features::is_mutable
1523 && std::is_reference_v<row_reference>
1524 && Structure::is_mutable_impl;
1541 versionNumber = QT_VERSION;
1552 if (row < 0 || column < 0 || column >= columnCount(parent)
1553 || row >= rowCount(parent)) {
1557 return that().indexImpl(row, column, parent);
1562 if (row == index.row() && column == index.column())
1566 if (column >=
this->columnCount({}))
1569 if (row == index.row())
1570 return this->createIndex(row, column, index.constInternalPointer());
1572 const_row_ptr parentRow =
static_cast<const_row_ptr>(index.constInternalPointer());
1573 const auto siblingCount = size(that().childrenOf(parentRow));
1574 if (row < 0 || row >=
int(siblingCount))
1576 return this->createIndex(row, column, parentRow);
1581 if (!index.isValid()) {
1582 if constexpr (isMutable())
1583 return Qt::ItemIsDropEnabled;
1585 return Qt::NoItemFlags;
1589 std::optional<Qt::ItemFlags> customFlags;
1590 if constexpr (QRangeModelDetails::hasRowFlags<wrapped_row_type>) {
1591 const_row_reference row = rowData(index);
1593 customFlags = QRangeModelDetails::QRangeModelRowOptions<wrapped_row_type>::flags(
1594 QRangeModelDetails::refTo(row)
1599 readAt(index, [&customFlags](
auto &&ref){
1601 using wrapped_value_type = q20::remove_cvref_t<QRangeModelDetails::wrapped_t<
decltype(ref)>>;
1602 if constexpr (QRangeModelDetails::item_access<wrapped_value_type>::hasFlags) {
1603 using ItemAccess = QRangeModelDetails::QRangeModelItemAccess<wrapped_value_type>;
1605 customFlags = ItemAccess::flags(QRangeModelDetails::refTo(ref));
1612 Qt::ItemFlags f = customFlags ? *customFlags : Structure::defaultFlags();
1614 if constexpr (!isMutable())
1615 f &= ~(Qt::ItemIsEditable | Qt::ItemIsDropEnabled);
1617 f |= Qt::ItemNeverHasChildren;
1622 if (!
this->itemModel().mimeTypes().isEmpty()) {
1623 f |= Qt::ItemIsDragEnabled;
1624 if constexpr (isMutable())
1625 f |= Qt::ItemIsDropEnabled;
1628 if constexpr (QRangeModelDetails::is_owning_or_raw_pointer<row_type>()) {
1630 const_row_reference row = rowData(index);
1631 if (!QRangeModelDetails::isValid(row))
1632 f &= ~Qt::ItemIsDragEnabled;
1635 if constexpr (isMutable()) {
1640 if constexpr (row_traits::hasMetaObject) {
1641 if (index.column() < row_traits::fixed_size()) {
1642 const QMetaObject mo = wrapped_row_type::staticMetaObject;
1643 const QMetaProperty prop = mo.property(index.column() + mo.propertyOffset());
1644 if (prop.isWritable())
1645 f |= Qt::ItemIsEditable;
1648 using item_type =
typename row_traits::item_type;
1649 if constexpr (QRangeModelDetails::is_owning_or_raw_pointer<item_type>()) {
1651 if (!readAt(index, [](
auto &&i){
return QRangeModelDetails::isValid(i); }))
1652 f &= ~Qt::ItemIsDragEnabled;
1654 f |= Qt::ItemIsEditable;
1655 }
else if constexpr (std::is_reference_v<row_reference> && !std::is_const_v<row_reference>) {
1658 const_row_reference row = rowData(index);
1659 row_reference mutableRow =
const_cast<row_reference>(row);
1661 row_traits::for_element_at(mutableRow, index.column(), [&f](
auto &&ref){
1662 using target_type =
decltype(ref);
1663 if constexpr (QRangeModelDetails::is_owning_or_raw_pointer<target_type>()) {
1665 if (!QRangeModelDetails::isValid(ref))
1666 f &= ~Qt::ItemIsDragEnabled;
1668 if constexpr (std::is_const_v<std::remove_reference_t<target_type>>)
1669 f &= ~Qt::ItemIsEditable;
1670 else if constexpr (std::is_lvalue_reference_v<target_type>)
1671 f |= Qt::ItemIsEditable;
1676 f &= ~Qt::ItemIsEditable;
1686 if constexpr (QRangeModelDetails::hasHeaderData<wrapped_row_type>) {
1687 if (orientation == Qt::Horizontal) {
1688 result = QRangeModelDetails::QRangeModelRowOptions<wrapped_row_type>::headerData(
1691 if (result.isValid())
1696 if (role != Qt::DisplayRole || orientation != Qt::Horizontal
1697 || section < 0 || section >= columnCount({})) {
1698 return this->itemModel().QAbstractItemModel::headerData(section, orientation, role);
1701 result = row_traits::column_name(section);
1702 if (!result.isValid())
1703 result =
this->itemModel().QAbstractItemModel::headerData(section, orientation, role);
1709 if (!index.isValid())
1712 QModelRoleData result(role);
1713 multiData(index, result);
1714 return std::move(result.data());
1719 return role == Qt::RangeModelDataRole
1720 || role == Qt::RangeModelAdapterRole;
1725 return role == Qt::DisplayRole || role == Qt::EditRole;
1730 QMap<
int, QVariant> result;
1732 if (index.isValid()) {
1734 if (!readAt(index, [&result](
const auto &value) {
1735 if constexpr (std::is_convertible_v<
decltype(value),
decltype(result)>) {
1741 const auto roles =
this->itemModel().roleNames().keys();
1742 QVarLengthArray<QModelRoleData, 16> roleDataArray;
1743 roleDataArray.reserve(roles.size());
1744 for (
auto role : roles) {
1745 if (isRangeModelRole(role))
1747 roleDataArray.emplace_back(role);
1749 QModelRoleDataSpan roleDataSpan(roleDataArray);
1750 multiData(index, roleDataSpan);
1752 for (QModelRoleData &roleData : roleDataSpan) {
1753 if (roleData.data().isValid())
1754 result[roleData.role()] = std::move(roleData.data());
1763 template <
typename value_type>
1766 using multi_role = QRangeModelDetails::is_multi_role<value_type>;
1767 using wrapped_value_type = QRangeModelDetails::wrapped_t<value_type>;
1769 const auto readModelData = [&value](QModelRoleData &roleData){
1771 roleData.clearData();
1775 const int role = roleData.role();
1776 if (role == Qt::RangeModelDataRole) {
1780 if constexpr (std::is_copy_assignable_v<wrapped_value_type>)
1781 roleData.setData(QVariant::fromValue(QRangeModelDetails::refTo(value)));
1783 roleData.setData(QVariant::fromValue(QRangeModelDetails::pointerTo(value)));
1784 }
else if (role == Qt::RangeModelAdapterRole) {
1786 if constexpr (
std::is_copy_assignable_v<value_type>)
1787 roleData.setData(QVariant::fromValue(value));
1789 roleData.setData(QVariant::fromValue(QRangeModelDetails::pointerTo(value)));
1796 if constexpr (QRangeModelDetails::item_access<wrapped_value_type>::hasReadRole) {
1797 using ItemAccess = QRangeModelDetails::QRangeModelItemAccess<wrapped_value_type>;
1798 for (
auto &roleData : roleDataSpan) {
1799 if (!readModelData(roleData)) {
1800 roleData.setData(ItemAccess::readRole(QRangeModelDetails::refTo(value),
1804 }
else if constexpr (multi_role()) {
1805 const auto roleNames = [
this]() -> QHash<
int, QByteArray> {
1807 if constexpr (!multi_role::int_key)
1808 return that->itemModel().roleNames();
1812 using key_type =
typename value_type::key_type;
1813 for (
auto &roleData : roleDataSpan) {
1814 const auto &it = [&roleNames, &value, role = roleData.role()]{
1815 Q_UNUSED(roleNames);
1816 if constexpr (multi_role::int_key)
1817 return value.find(key_type(role));
1819 return value.find(roleNames.value(role));
1821 if (it != QRangeModelDetails::adl_end(value))
1822 roleData.setData(QRangeModelDetails::value(it));
1824 roleData.clearData();
1826 }
else if constexpr (has_metaobject<value_type>) {
1827 if (row_traits::fixed_size() <= 1) {
1828 for (
auto &roleData : roleDataSpan) {
1829 if (!readModelData(roleData)) {
1830 roleData.setData(that->readRole(index, roleData.role(),
1831 QRangeModelDetails::pointerTo(value)));
1834 }
else if (index.column() <= row_traits::fixed_size()) {
1835 for (
auto &roleData : roleDataSpan) {
1836 const int role = roleData.role();
1837 if (isPrimaryRole(role)) {
1838 roleData.setData(that->readProperty(index,
1839 QRangeModelDetails::pointerTo(value)));
1841 roleData.clearData();
1846 for (
auto &roleData : roleDataSpan) {
1847 const int role = roleData.role();
1848 if (isPrimaryRole(role) || isRangeModelRole(role))
1849 roleData.setData(read(value));
1851 roleData.clearData();
1862 void multiData(
const QModelIndex &index, QModelRoleDataSpan roleDataSpan)
const
1864 if (!readAt(index,
ItemReader{index, roleDataSpan,
this})) {
1865 for (
auto &roleData : roleDataSpan)
1866 roleData.clearData();
1870 bool setData(
const QModelIndex &index,
const QVariant &data,
int role)
1872 if (!index.isValid())
1875 if constexpr (isMutable()) {
1876 auto emitDataChanged = qScopeGuard([
this, &index, role]{
1877 Q_EMIT
this->dataChanged(index, index,
1878 role == Qt::EditRole || role == Qt::RangeModelDataRole
1879 || role == Qt::RangeModelAdapterRole
1880 ? QList<
int>{} : QList<
int>{role});
1885 const auto writeData = [
this, column = index.column(), &data, role](
auto &&target) ->
bool {
1886 using value_type = q20::remove_cvref_t<
decltype(target)>;
1887 using wrapped_value_type = QRangeModelDetails::wrapped_t<value_type>;
1888 using multi_role = QRangeModelDetails::is_multi_role<value_type>;
1890 if constexpr (std::conjunction_v<QRangeModelDetails::is_any_owning_ptr<value_type>,
1891 std::is_default_constructible<wrapped_value_type>>) {
1893 target.reset(
new wrapped_value_type);
1896 auto setRangeModelDataRole = [&target, &data]{
1897 constexpr auto targetMetaType = QMetaType::fromType<value_type>();
1898 const auto dataMetaType = data.metaType();
1899 constexpr bool isWrapped = QRangeModelDetails::is_wrapped<value_type>();
1900 if constexpr (!std::is_copy_assignable_v<wrapped_value_type>) {
1904 if constexpr (isWrapped) {
1905 constexpr bool is_raw_pointer = std::is_pointer_v<value_type>;
1906 if constexpr (!is_raw_pointer && std::is_copy_assignable_v<value_type>) {
1907 if (data.canConvert(targetMetaType)) {
1908 target = data.value<value_type>();
1911 }
else if constexpr (is_raw_pointer) {
1913 target = data.value<value_type>();
1922 }
else if constexpr (isWrapped) {
1927 if (
const auto mt = QMetaType::fromType<wrapped_value_type>();
1928 data.canConvert(mt)) {
1929 targetRef = data.value<wrapped_value_type>();
1931 }
else if (
const auto mtp = QMetaType::fromType<wrapped_value_type *>();
1932 data.canConvert(mtp)) {
1933 targetRef = *data.value<wrapped_value_type *>();
1937 }
else if (targetMetaType == dataMetaType) {
1938 QRangeModelDetails::refTo(target) = data.value<value_type>();
1940 }
else if (dataMetaType.flags() & QMetaType::PointerToGadget) {
1941 QRangeModelDetails::refTo(target) = *data.value<value_type *>();
1945 qCritical(
"Not able to assign %s to %s",
1946 qPrintable(QDebug::toString(data)), targetMetaType.name());
1951 if constexpr (QRangeModelDetails::item_access<wrapped_value_type>::hasWriteRole) {
1952 using ItemAccess = QRangeModelDetails::QRangeModelItemAccess<wrapped_value_type>;
1953 if (isRangeModelRole(role))
1954 return setRangeModelDataRole();
1955 return ItemAccess::writeRole(QRangeModelDetails::refTo(target), data, role);
1956 }
else if constexpr (has_metaobject<value_type>) {
1957 if (row_traits::fixed_size() <= 1) {
1958 if (isRangeModelRole(role))
1959 return setRangeModelDataRole();
1961 }
else if (column <= row_traits::fixed_size()
1962 && (isPrimaryRole(role) || isRangeModelRole(role))) {
1965 }
else if constexpr (multi_role::value) {
1966 Qt::ItemDataRole roleToSet = Qt::ItemDataRole(role);
1969 const auto roleNames = [
this]() -> QHash<
int, QByteArray> {
1971 if constexpr (!multi_role::int_key)
1972 return this->itemModel().roleNames();
1976 if (role == Qt::EditRole) {
1977 if constexpr (multi_role::int_key) {
1978 if (target.find(roleToSet) == target.end())
1979 roleToSet = Qt::DisplayRole;
1981 if (target.find(roleNames.value(roleToSet)) == target.end())
1982 roleToSet = Qt::DisplayRole;
1985 if constexpr (multi_role::int_key)
1986 return write(target[roleToSet], data);
1988 return write(target[roleNames.value(roleToSet)], data);
1989 }
else if (isPrimaryRole(role) || isRangeModelRole(role)) {
1990 return write(target, data);
1995 if (!writeAt(index, writeData)) {
1996 emitDataChanged.dismiss();
1999 if (isRangeModelRole(role) &&
this->autoConnectPolicy() == AutoConnectPolicy::Full) {
2000 if (QObject *item = data.value<QObject *>())
2001 Self::connectProperties(index, item, m_data.context, m_data.properties);
2009 template <
typename LHS,
typename RHS>
2012 if constexpr (
std::is_pointer_v<RHS>)
2014 else if constexpr (
std::is_assignable_v<LHS, RHS>)
2015 org =
std::forward<RHS>(copy);
2019 template <
typename LHS,
typename RHS>
2022 updateTarget(*org,
std::forward<RHS>(copy));
2025 bool setItemData(
const QModelIndex &index,
const QMap<
int, QVariant> &data)
2027 if (!index.isValid() || data.isEmpty())
2030 if constexpr (isMutable()) {
2031 auto emitDataChanged = qScopeGuard([
this, &index, &data]{
2032 Q_EMIT
this->dataChanged(index, index, data.keys());
2038 auto writeItemData = [
this, &tried, &data](
auto &target) ->
bool {
2040 using value_type = q20::remove_cvref_t<
decltype(target)>;
2041 using multi_role = QRangeModelDetails::is_multi_role<value_type>;
2042 using wrapped_value_type = QRangeModelDetails::wrapped_t<value_type>;
2046 auto makeCopy = [](
const value_type &original){
2047 if constexpr (!std::is_copy_assignable_v<wrapped_value_type>)
2049 else if constexpr (std::is_pointer_v<
decltype(original)>)
2051 else if constexpr (std::is_copy_assignable_v<value_type>)
2057 const auto roleNames =
this->itemModel().roleNames();
2059 if constexpr (QRangeModelDetails::item_access<wrapped_value_type>::hasWriteRole) {
2061 using ItemAccess = QRangeModelDetails::QRangeModelItemAccess<wrapped_value_type>;
2062 const auto roles = roleNames.keys();
2063 auto targetCopy = makeCopy(target);
2064 for (
int role : roles) {
2065 if (!ItemAccess::writeRole(QRangeModelDetails::refTo(targetCopy),
2066 data.value(role), role)) {
2070 updateTarget(target,
std::move(targetCopy));
2072 }
else if constexpr (multi_role()) {
2073 using key_type =
typename value_type::key_type;
2075 const auto roleName = [&roleNames](
int role) {
2076 return roleNames.value(role);
2081 if constexpr (!multi_role::int_key)
2083 auto invalid =
std::find_if(data.keyBegin(), data.keyEnd(),
2084 [&roleName](
int role) {
return roleName(role).isEmpty(); }
2087 if (invalid != data.keyEnd()) {
2089 qWarning(
"No role name set for %d", *invalid);
2095 for (
auto &&[role, value] : data.asKeyValueRange()) {
2096 if constexpr (multi_role::int_key)
2097 target[
static_cast<key_type>(role)] = value;
2099 target[QString::fromUtf8(roleName(role))] = value;
2102 }
else if constexpr (has_metaobject<value_type>) {
2103 if (row_traits::fixed_size() <= 1) {
2105 auto targetCopy = makeCopy(target);
2106 for (
auto &&[role, value] : data.asKeyValueRange()) {
2107 if (isRangeModelRole(role))
2109 if (!writeRole(role, QRangeModelDetails::pointerTo(targetCopy), value)) {
2110 const QByteArray roleName = roleNames.value(role);
2112 qWarning(
"Failed to write value '%s' to role '%s'",
2113 qPrintable(QDebug::toString(value)), roleName.data());
2118 updateTarget(target,
std::move(targetCopy));
2125 if (!writeAt(index, writeItemData)) {
2126 emitDataChanged.dismiss();
2128 return this->itemModel().QAbstractItemModel::setItemData(index, data);
2137 if (!index.isValid())
2140 if constexpr (isMutable()) {
2141 auto emitDataChanged = qScopeGuard([
this, &index]{
2142 Q_EMIT
this->dataChanged(index, index, {});
2145 auto clearData = [column = index.column()](
auto &&target) {
2146 if constexpr (row_traits::hasMetaObject) {
2147 if (row_traits::fixed_size() <= 1) {
2150 }
else if (column <= row_traits::fixed_size()) {
2160 if (!writeAt(index, clearData)) {
2161 emitDataChanged.dismiss();
2172 using item_type = QRangeModelDetails::wrapped_t<
typename row_traits::item_type>;
2173 using item_traits =
typename QRangeModelDetails::item_traits<item_type>;
2174 return item_traits::roleNames(
this);
2181 return row_traits::for_each_element(QRangeModelDetails::refTo(row),
2182 this->itemModel().index(rowIndex, 0, parent),
2183 [
this](
const QModelIndex &index,
const QObject *item) {
2184 if constexpr (isMutable())
2185 return Self::connectProperties(index, item, m_data.context, m_data.properties);
2187 return Self::connectPropertiesConst(index, item, m_data.context, m_data.properties);
2195 row_traits::for_each_element(QRangeModelDetails::refTo(row),
2196 this->itemModel().index(rowIndex, 0, parent),
2197 [
this](
const QModelIndex &,
const QObject *item) {
2198 m_data.connections.removeIf([item](
const auto &connection) {
2199 return connection.sender == item;
2208 using item_type = std::remove_pointer_t<
typename row_traits::item_type>;
2209 using Mapping = QRangeModelDetails::AutoConnectContext::AutoConnectMapping;
2211 delete m_data.context;
2212 m_data.connections = {};
2213 switch (
this->autoConnectPolicy()) {
2214 case AutoConnectPolicy::None:
2215 m_data.context =
nullptr;
2217 case AutoConnectPolicy::Full:
2218 m_data.context =
new QRangeModelDetails::AutoConnectContext(&
this->itemModel());
2220 m_data.properties = QRangeModelImplBase::roleProperties(
this->itemModel(),
2221 item_type::staticMetaObject);
2222 m_data.context->mapping = Mapping::Roles;
2224 m_data.properties = QRangeModelImplBase::columnProperties(wrapped_row_type::staticMetaObject);
2225 m_data.context->mapping = Mapping::Columns;
2227 if (!m_data.properties.isEmpty())
2228 that().autoConnectPropertiesImpl();
2230 case AutoConnectPolicy::OnRead:
2231 m_data.context =
new QRangeModelDetails::AutoConnectContext(&
this->itemModel());
2233 m_data.context->mapping = Mapping::Roles;
2235 m_data.properties = QRangeModelImplBase::columnProperties(wrapped_row_type::staticMetaObject);
2236 m_data.context->mapping = Mapping::Columns;
2242 qWarning(
"All items in the range must be QObject subclasses");
2256 template <
typename C,
typename LessThan>
2258 static constexpr bool hasSortMember = qxp::is_detected_v<sortMember_test, range_type, Compare>;
2276 template <
typename Item>
2277 auto operator()(
const Item &lhs,
const Item &rhs)
const
2279 auto ordering = compare(lhs, rhs);
2280 return m_order == Qt::AscendingOrder ? ordering < 0 : ordering > 0;
2283 template <
typename Item>
2284 auto compare(
const Item &lhs,
const Item &rhs)
const
2286 using value_type = QRangeModelDetails::wrapped_t<Item>;
2287 using multi_role = QRangeModelDetails::is_multi_role<value_type>;
2289 if constexpr (QRangeModelDetails::item_access<value_type>::hasReadRole
2290 || multi_role() || has_metaobject<value_type>) {
2298 Q_ASSERT(!reader.index.isValid());
2300 const QVariant lhsVariant =
std::move(result.data());
2302 const QVariant rhsVariant =
std::move(result.data());
2303 return QRangeModelImplBase::compareData(lhsVariant, rhsVariant, collator);
2304 }
else if constexpr (std::is_same_v<QVariant, value_type>) {
2305 return QRangeModelImplBase::compareData(lhs, rhs, collator);
2306 }
else if constexpr (QtOrderingPrivate::CompareThreeWayTester::hasCompareThreeWay_v
2307 <value_type, value_type>) {
2309 if constexpr (hasCollatedCompare<value_type>) {
2311 using ordering =
decltype(qCompareThreeWay(lhs, rhs));
2312 int res = collator->compare(lhs, rhs);
2314 return ordering::less;
2316 return ordering::greater;
2317 return ordering::equal;
2320 return qCompareThreeWay(lhs, rhs);
2328 return that->readAt(
that->index(0, 0, {}), [
this](
const auto &item){
2333 using ordering =
decltype(compare(item, item));
2336 const QMetaType itemtype = QMetaType::fromType<QRangeModelDetails::wrapped_t<
2337 q20::remove_cvref_t<
decltype(item)>>
2339 qCritical(
"QRangeModel: Cannot compare items of type %s in column %d!",
2340 itemtype.name(), m_index.column());
2351 template <
typename Item>
2359 return std::nullopt;
2369 void sort(
int column, Qt::SortOrder order)
2371 if constexpr (isMutable() && std::is_swappable_v<row_type>) {
2372 if (rowCount({}) < 2 || column >= columnCount({}))
2374 Compare compare(
this, column, order);
2375 if (!compare.checkComparable())
2378 this->beginLayoutChange();
2379 QScopeGuard endLayoutChange([
this]{
this->endLayoutChange(); });
2380 that().sortImpl([&compare](
const auto &leftRow,
const auto &rightRow) {
2381 if (
auto anyInvalid =
Compare::compareInvalid(leftRow, rightRow))
2383 return row_traits::for_element_at(leftRow, compare.m_index.column(),
2384 [&rightRow, &compare](
const auto &leftItem){
2385 return row_traits::for_element_at(rightRow, compare.m_index.column(),
2386 [&leftItem, &compare](
const auto &rightItem){
2389 if constexpr (std::is_same_v<
decltype(leftItem),
decltype(rightItem)>) {
2390 if (
auto anyInvalid = Compare::compareInvalid(leftItem, rightItem))
2392 return compare(QRangeModelDetails::refTo(leftItem),
2393 QRangeModelDetails::refTo(rightItem));
2404 template <
typename LessThan>
2405 void sortSubRange(range_type &range, row_ptr expectedParent,
const LessThan &lessThan)
2412 QModelIndexList persistentIndexes =
this->persistentIndexList();
2413 that().prunePersistentIndexList(persistentIndexes, expectedParent);
2415 if (persistentIndexes.isEmpty()) {
2416 using It =
typename range_features::iterator;
2417 constexpr bool is_random_access = std::is_base_of_v<std::random_access_iterator_tag,
2418 typename std::iterator_traits<It>::iterator_category>;
2420 if constexpr (
Compare::hasSortMember) {
2421 range.sort(lessThan);
2423 }
else if constexpr (is_random_access) {
2424 std::stable_sort(begin, end, lessThan);
2437 const int rangeSize = size(range);
2440 std::vector<SortTracker> tracked;
2441 tracked.reserve(rangeSize);
2442 std::vector<
int> newRows;
2443 newRows.resize(rangeSize);
2447 for (
auto &&it =
std::move_iterator(begin); it !=
std::move_iterator(end); ++it)
2448 tracked.emplace_back(SortTracker{*it, ++row});
2451 std::stable_sort(tracked.begin(), tracked.end(),
2452 [&lessThan](
const SortTracker &lhs,
const SortTracker &rhs){
2453 return lessThan(lhs.row, rhs.row);
2458 auto sorted =
std::move_iterator(tracked.begin());
2460 qsizetype changedIndexCount = 0;
2461 for (
int newIndex = 0; newIndex < rangeSize; ++write, ++sorted, ++newIndex) {
2462 auto &&tracker = *sorted;
2463 changedIndexCount += (tracker.index != newIndex);
2464 *write =
std::move(tracker.row);
2465 newRows[tracker.index] = newIndex;
2470 tracked.shrink_to_fit();
2473 for (
const auto &fromIndex : std::as_const(persistentIndexes)) {
2474 const int newRow = newRows.at(fromIndex.row());
2475 if (fromIndex.row() == newRow)
2477 const QModelIndex toIndex = that().indexImpl(newRow,
2479 fromIndex.parent());
2480 this->changePersistentIndex(fromIndex, toIndex);
2485 Qt::MatchFlags flags)
const
2487 return that().matchImpl(start, role,
2488 QRangeModelImplBase::convertMatchValue(value, flags), hits, flags);
2491 bool matchRow(const_row_reference row,
const QModelIndex &index,
int role,
const QVariant &value,
2492 Qt::MatchFlags flags)
const
2494 const uint matchType = (flags & Qt::MatchTypeMask).toInt();
2496 return row_traits::for_element_at(row, index.column(), [&](
const auto &element) {
2497 using value_type = q20::remove_cvref_t<
decltype(element)>;
2498 using wrapped_value_type = QRangeModelDetails::wrapped_t<value_type>;
2499 using multi_role = QRangeModelDetails::is_multi_role<value_type>;
2501 if constexpr (QRangeModelDetails::item_access<wrapped_value_type>::hasReadRole
2502 || multi_role() || has_metaobject<value_type>) {
2503 QModelRoleData roleData(role);
2504 ItemReader reader{index, roleData,
this};
2506 return QRangeModelImplBase::matchValue(roleData.data(), value, flags);
2507 }
else if constexpr (std::is_same_v<wrapped_value_type, QVariant>) {
2508 return QRangeModelImplBase::matchValue(element, value, flags);
2510 constexpr QMetaType mt = QMetaType::fromType<wrapped_value_type>();
2511 if (mt == value.metaType()) {
2512 if (matchType == Qt::MatchExactly)
2513 return mt.equals(QRangeModelDetails::pointerTo(element), value.constData());
2514 else if constexpr (std::is_same_v<wrapped_value_type, QString>)
2515 return QRangeModelImplBase::matchValue(element, value, flags);
2517 return QRangeModelImplBase::matchValue(QVariant::fromValue(QRangeModelDetails::refTo(element)),
2525 template <
typename InsertFn>
2530 range_type *
const children = childRange(parent);
2534 this->beginInsertColumns(parent, column, column + count - 1);
2536 for (
auto &child : *children) {
2537 auto it = QRangeModelDetails::pos(child, column);
2538 (
void)insertFn(QRangeModelDetails::refTo(child), it, count);
2541 this->endInsertColumns();
2547 if (m_data.context &&
this->autoConnectPolicy() == AutoConnectPolicy::Full) {
2548 for (
int r = 0; r < that().rowCount(parent); ++r) {
2549 for (
int c = column; c < column + count; ++c) {
2550 const QModelIndex index = that().index(r, c, parent);
2551 writeAt(index, [
this, &index](QObject *item){
2552 return Self::connectProperties(index, item,
2553 m_data.context, m_data.properties);
2565 if constexpr (dynamicColumns() && isMutable() && row_features::has_insert) {
2566 return doInsertColumns(column, count, parent, [](
auto &row,
auto it,
int n){
2567 row.insert(it, n, {});
2577 if constexpr (dynamicColumns() && isMutable() && row_features::has_erase) {
2578 if (column < 0 || column + count > columnCount(parent))
2581 range_type *
const children = childRange(parent);
2586 if (m_data.context &&
this->autoConnectPolicy() == AutoConnectPolicy::OnRead) {
2587 for (
int r = 0; r < that().rowCount(parent); ++r) {
2588 for (
int c = column; c < column + count; ++c) {
2589 const QModelIndex index = that().index(r, c, parent);
2590 writeAt(index, [
this](QObject *item){
2591 m_data.connections.removeIf([item](
const auto &connection) {
2592 return connection.sender == item;
2601 this->beginRemoveColumns(parent, column, column + count - 1);
2602 for (
auto &child : *children) {
2603 const auto start = QRangeModelDetails::pos(child, column);
2604 QRangeModelDetails::refTo(child).erase(start, std::next(start, count));
2606 this->endRemoveColumns();
2612 bool moveColumns(
const QModelIndex &sourceParent,
int sourceColumn,
int count,
2613 const QModelIndex &destParent,
int destColumn)
2616 if (sourceParent != destParent)
2618 if constexpr (isMutable() && (row_features::has_rotate || row_features::has_splice)) {
2619 if (!Structure::canMoveColumns(sourceParent, destParent))
2625 range_type *
const children = childRange(sourceParent);
2629 if (!
this->beginMoveColumns(sourceParent, sourceColumn, sourceColumn + count - 1,
2630 destParent, destColumn)) {
2634 for (
auto &child : *children)
2635 QRangeModelDetails::rotate(child, sourceColumn, count, destColumn);
2637 this->endMoveColumns();
2644 template <
typename InsertFn>
2645 bool doInsertRows(
int row,
int count,
const QModelIndex &parent, InsertFn &&insertFn)
2647 range_type *children = childRange(parent);
2651 this->beginInsertRows(parent, row, row + count - 1);
2653 row_ptr parentRow = parent.isValid()
2656 (
void)
std::forward<InsertFn>(insertFn)(*children, parentRow, row, count);
2660 that().resetParentInChildren(children);
2662 this->endInsertRows();
2668 if (m_data.context &&
this->autoConnectPolicy() == AutoConnectPolicy::Full) {
2670 const auto end =
std::next(begin, count);
2672 for (
auto it = begin; it != end; ++it, ++rowIndex)
2673 autoConnectPropertiesInRow(*it, rowIndex, parent);
2683 return doInsertRows(row, count, parent,
2684 [
this](range_type &children, row_ptr parentRow,
int r,
int n){
2688 if constexpr (range_features::has_insert_range) {
2691 auto start = children.insert(pos, n,
nullptr);
2694 children.insert(pos, n,
std::move(*generator));
2703 bool removeRows(
int row,
int count,
const QModelIndex &parent = {})
2706 const int prevRowCount = rowCount(parent);
2707 if (row < 0 || row + count > prevRowCount)
2710 range_type *children = childRange(parent);
2715 if (m_data.context &&
this->autoConnectPolicy() == AutoConnectPolicy::OnRead) {
2717 const auto end =
std::next(begin, count);
2719 for (
auto it = begin; it != end; ++it, ++rowIndex)
2720 clearConnectionInRow(*it, rowIndex, parent);
2724 this->beginRemoveRows(parent, row, row + count - 1);
2725 [[maybe_unused]]
bool callEndRemoveColumns =
false;
2729 if (prevRowCount == count) {
2730 if (
const int columns = columnCount(parent)) {
2731 callEndRemoveColumns =
true;
2732 this->beginRemoveColumns(parent, 0, columns - 1);
2738 const auto end =
std::next(begin, count);
2739 that().deleteRemovedRows(begin, end);
2740 children->erase(begin, end);
2744 that().resetParentInChildren(children);
2747 if (callEndRemoveColumns) {
2748 Q_ASSERT(columnCount(parent) == 0);
2749 this->endRemoveColumns();
2752 this->endRemoveRows();
2759 bool moveRows(
const QModelIndex &sourceParent,
int sourceRow,
int count,
2760 const QModelIndex &destParent,
int destRow)
2762 if constexpr (isMutable() && (range_features::has_rotate || range_features::has_splice)) {
2763 if (!Structure::canMoveRows(sourceParent, destParent))
2766 if (sourceParent != destParent) {
2767 return that().moveRowsAcross(sourceParent, sourceRow, count,
2768 destParent, destRow);
2771 if (sourceRow == destRow || sourceRow == destRow - 1 || count <= 0
2772 || sourceRow < 0 || sourceRow + count - 1 >=
this->rowCount(sourceParent)
2773 || destRow < 0 || destRow >
this->rowCount(destParent)) {
2777 range_type *source = childRange(sourceParent);
2779 if (!
this->beginMoveRows(sourceParent, sourceRow, sourceRow + count - 1, destParent, destRow))
2784 that().resetParentInChildren(source);
2786 this->endMoveRows();
2798 int rowCount(
const QModelIndex &parent)
const {
return that().rowCountImpl(parent); }
2803 return row_traits::fixed_size();
2807 int columnCount(
const QModelIndex &parent)
const {
return that().columnCountImpl(parent); }
2812 if constexpr (!isMutable())
2813 dragActions &= ~Qt::MoveAction;
2818 if constexpr (!isMutable())
2819 dropActions = Qt::IgnoreAction;
2826 using ItemType = QRangeModelDetails::wrapped_t<
typename row_traits::item_type>;
2827 if constexpr (QRangeModelDetails::item_access<ItemType>::hasMimeTypes)
2828 return QRangeModelDetails::QRangeModelItemAccess<ItemType>::mimeTypes();
2829 else if constexpr (QRangeModelDetails::hasMimeTypes<wrapped_row_type>)
2830 return QRangeModelDetails::QRangeModelRowOptions<wrapped_row_type>::mimeTypes();
2832 return this->itemModel().QAbstractItemModel::mimeTypes();
2836 const QModelIndex &target)
const
2838 if constexpr (isMutable()) {
2840 using RowOptions = QRangeModelDetails::QRangeModelRowOptions<wrapped_row_type>;
2841 using ItemType = QRangeModelDetails::wrapped_t<
typename row_traits::item_type>;
2842 using ItemAccess = QRangeModelDetails::QRangeModelItemAccess<ItemType>;
2843 if constexpr (QRangeModelDetails::item_access<ItemType>::hasCanDropMimeDataFull) {
2844 canDrop = ItemAccess::canDropMimeData(data, action, row, column, target);
2845 }
else if constexpr (QRangeModelDetails::hasCanDropMimeDataFull<wrapped_row_type>) {
2846 canDrop = RowOptions::canDropMimeData(data, action, row, column, target);
2848 canDrop =
this->itemModel().QAbstractItemModel::canDropMimeData(data, action, row,
2850 if constexpr (QRangeModelDetails::item_access<ItemType>::hasCanDropMimeData)
2851 canDrop &= ItemAccess::canDropMimeData(data);
2852 else if constexpr (QRangeModelDetails::hasCanDropMimeData<wrapped_row_type>)
2853 canDrop &= RowOptions::canDropMimeData(data);
2862 template <Qt::Orientation orient,
typename Entry>
2863 bool doDropMimeData(std::vector<QRangeModelDetails::DroppedEntry<Entry>> &droppedEntries,
2864 DropOperation dropOperation,
int row,
int column,
const QModelIndex &target)
2867 using Cell =
typename DroppedEntry::Cell;
2868 if (dropOperation == DropOperation::DontDrop)
2871 const bool dropOnTarget = row == -1 && column == -1 && target.isValid();
2872 const QModelIndex parent = dropOperation == DropOperation::InsertAsChildren
2873 ? target.siblingAtColumn(0) : target.parent();
2876 if constexpr (orient == Qt::Horizontal)
2881 int rightColumn = -1;
2884 int maxColumn = that().columnCount(parent) - 1;
2885 for (
auto &droppedEntry : droppedEntries) {
2886 if (droppedEntry.m_cell == Cell{-1, -1}) {
2887 if constexpr (orient == Qt::Horizontal) {
2890 droppedEntry.m_cell = {lastCell.m_row, lastCell.m_column + 1};
2891 if (droppedEntry.m_cell.m_column > maxColumn) {
2892 droppedEntry.m_cell.m_column = 0;
2893 ++droppedEntry.m_cell.m_row;
2896 droppedEntry.m_cell = {lastCell.m_row + 1, lastCell.m_column};
2899 lastCell = droppedEntry.m_cell;
2900 bottomRow = std::max(lastCell.m_row, bottomRow);
2901 rightColumn = std::max(lastCell.m_column, rightColumn);
2904 if (dropOperation == DropOperation::InsertAsChildren) {
2905 row = rowCount(parent);
2907 }
else if (dropOnTarget) {
2909 column = target.column();
2912 row = rowCount(parent);
2917 const bool overwrite = dropOperation == DropOperation::OverwriteAndIgnore
2918 || dropOperation == DropOperation::OverwriteAndExtend;
2921 const int overwriteRows = overwrite
2922 ?
std::min(bottomRow + 1, rowCount(parent) - row)
2924 const int newRows = dropOperation == DropOperation::OverwriteAndExtend
2925 ? bottomRow - overwriteRows + 1
2926 : (dropOperation == DropOperation::InsertAsChildren
2927 || dropOperation == DropOperation::InsertAsSiblings)
2930 if (newRows > 0 && !insertRows(row, newRows, parent))
2934 const int overwriteColumns = overwrite
2935 ?
std::min(rightColumn + 1, columnCount(parent) - column)
2937 const int newColumns = dropOperation == DropOperation::OverwriteAndExtend
2938 ? rightColumn - overwriteColumns + 1 : 0;
2939 if (newColumns > 0 && !insertColumns(column, newColumns, parent))
2943 range_type *parentRange = that().childRange(parent);
2946 range_type &targetRange = *parentRange;
2948 int maxRow = that().rowCount(parent) - 1;
2949 maxColumn = that().columnCount(parent) - 1;
2950 auto begin =
std::move_iterator(droppedEntries.begin());
2951 auto end =
std::move_iterator(droppedEntries.end());
2952 for (; begin != end; ++begin) {
2953 DroppedEntry droppedEntry = *begin;
2954 const Cell cell = {droppedEntry.m_cell.m_row + row, droppedEntry.m_cell.m_column + column};
2955 if (cell.m_row > maxRow || cell.m_column > maxColumn)
2958 if constexpr (orient == Qt::Vertical) {
2959 if constexpr (QRangeModelDetails::is_owning_or_raw_pointer<row_type>()) {
2961 *writeRow =
this->protocol().newRow();
2962 **writeRow =
std::move(droppedEntry);
2964 *writeRow =
std::move(droppedEntry);
2967 row_traits::for_element_at(*writeRow, cell.m_column, [&](
auto &item){
2968 using item_type = q20::remove_cvref_t<
decltype(item)>;
2969 using wrapped_item_type = QRangeModelDetails::wrapped_t<item_type>;
2970 if constexpr (QRangeModelDetails::is_any_owning_ptr<item_type>()) {
2971 if (!QRangeModelDetails::isValid(item))
2972 item.reset(
new wrapped_item_type{std::move(droppedEntry)});
2974 *item = std::move(droppedEntry);
2975 }
else if (!QRangeModelDetails::isValid(item)) {
2978 item = std::move(droppedEntry);
2985 that().resetParentInChildren(&targetRange);
2987 const QModelIndex topLeft = index(row, column, parent);
2988 const QModelIndex bottomRight = orient == Qt::Horizontal
2989 ? sibling(row + bottomRow, column + rightColumn, topLeft)
2990 : sibling(row + bottomRow, maxColumn, topLeft);
2991 this->dataChanged(topLeft, bottomRight, {});
2996 bool dropMimeData(
const QMimeData *data, Qt::DropAction action,
int row,
int column,
2997 const QModelIndex &target)
2999 if constexpr (isMutable()) {
3000 if (!canDropMimeData(data, action, row, column, target))
3003 const bool dropOnTarget = row == -1 && column == -1 && target.isValid();
3005 auto automaticDropOption = [=](
auto dropResult){
3006 DropOperation dropOperation;
3007 if constexpr (
std::is_same_v<
bool,
decltype(dropResult)>) {
3008 dropOperation = dropResult ? DropOperation::Automatic
3009 : DropOperation::DontDrop;
3011 dropOperation =
static_cast<DropOperation>(dropResult);
3014 if (dropOperation == DropOperation::Automatic) {
3015 if constexpr (!canInsertRows())
3016 dropOperation = DropOperation::OverwriteAndIgnore;
3017 else if (!dropOnTarget)
3018 dropOperation = DropOperation::InsertAsSiblings;
3019 else if (target.siblingAtColumn(0).flags().testFlag(Qt::ItemNeverHasChildren))
3020 dropOperation = DropOperation::OverwriteAndExtend;
3022 dropOperation = DropOperation::InsertAsChildren;
3024 return dropOperation;
3027 using ItemType = QRangeModelDetails::wrapped_t<
typename row_traits::item_type>;
3028 if constexpr (QRangeModelDetails::item_access<ItemType>::hasDropMimeDataFull
3029 || QRangeModelDetails::item_access<ItemType>::hasDropMimeData) {
3030 using ItemAccess = QRangeModelDetails::QRangeModelItemAccess<ItemType>;
3031 using DroppedItem = QRangeModelDetails::DroppedEntry<ItemType>;
3032 std::vector<DroppedItem> droppedItems;
3033 DropOperation dropOperation = automaticDropOption([&]{
3034 auto inserter =
std::back_inserter(droppedItems);
3035 if constexpr (QRangeModelDetails::item_access<ItemType>::hasDropMimeDataFull)
3036 return ItemAccess::dropMimeData(data, action, row, column, target, inserter);
3038 return ItemAccess::dropMimeData(data, inserter);
3040 if (doDropMimeData<Qt::Horizontal>(droppedItems, dropOperation, row, column, target))
3043 }
else if constexpr (QRangeModelDetails::hasDropMimeDataFull<wrapped_row_type>
3044 || QRangeModelDetails::hasDropMimeData<wrapped_row_type>) {
3045 using RowOptions = QRangeModelDetails::QRangeModelRowOptions<wrapped_row_type>;
3046 using DroppedRow = QRangeModelDetails::DroppedEntry<wrapped_row_type>;
3047 std::vector<DroppedRow> droppedRows;
3048 DropOperation dropOperation = automaticDropOption([&]{
3049 auto inserter =
std::back_inserter(droppedRows);
3050 if constexpr (QRangeModelDetails::hasDropMimeDataFull<wrapped_row_type>)
3051 return RowOptions::dropMimeData(data, action, row, column, target, inserter);
3053 return RowOptions::dropMimeData(data, inserter);
3055 if (doDropMimeData<Qt::Vertical>(droppedRows, dropOperation, row, column, target))
3059 if (dropOnTarget && that().dropOnItem(data, target))
3077 using pointer [[maybe_unused]] =
void;
3083 , m_columnCount(model->columnCount({}))
3085 updateCurrentIndexFullRow();
3090 const QModelIndex &index = *m_it;
3091 return {m_model->rowData(index),
3092 m_currentIndexIsFullRow
3093 ? m_model->createIndex(m_it->row(), -1, m_it->internalPointer()) : index};
3097 if (m_currentIndexIsFullRow)
3098 m_it += m_columnCount;
3101 updateCurrentIndexFullRow();
3108 m_currentIndexIsFullRow =
false;
3109 const int lastColumn = m_columnCount - 1;
3110 if (m_it - m_begin >= lastColumn && m_it->column() == lastColumn) {
3111 const QModelIndex &firstInRow = m_it[-lastColumn];
3112 if (m_it->row() == firstInRow.row()
3113 && firstInRow.internalPointer() == m_it->internalPointer()) {
3114 m_currentIndexIsFullRow =
true;
3124 auto tmp = *
this; tmp.m_it -= n;
return tmp;
3131 void updateCurrentIndexFullRow()
3133 m_currentIndexIsFullRow =
false;
3134 if (m_it == m_end || m_it->column() || m_end - m_it < m_columnCount)
3136 const QModelIndex &lastInRow = m_it[m_columnCount - 1];
3137 m_currentIndexIsFullRow = lastInRow.row() == m_it->row()
3138 && lastInRow.internalPointer() == m_it->internalPointer();
3142 base_iterator m_begin;
3143 base_iterator m_end;
3145 int m_columnCount = 0;
3146 bool m_currentIndexIsFullRow =
false;
3160 using pointer [[maybe_unused]] =
void;
3164 const QModelIndex &index = *m_it;
3166 const item_type *pitem =
nullptr;
3167 const auto &row =
m_model->rowData(index);
3169 row_traits::for_element_at(QRangeModelDetails::refTo(row), index.column(),
3170 [&pitem](
const auto &item){
3175 if constexpr (std::disjunction_v<QRangeModelDetails::is_owning_or_raw_pointer<row_type>,
3176 QRangeModelDetails::is_owning_or_raw_pointer<item_type>>) {
3180 constexpr bool is_constexpr_default_constructible_v =
3181 value_type::
template is_constexpr_default_constructible<item_type>::value;
3182 if constexpr (is_constexpr_default_constructible_v) {
3183 Q_CONSTINIT
static const item_type emptyDefault;
3184 return {emptyDefault, index};
3187 static const item_type emptyDefault;
3188 return {emptyDefault, index};
3193 return {*pitem, index};
3203 auto tmp = *
this; tmp.m_it -= n;
return tmp;
3213 template <
typename Iterator>
3229 QMimeData *result =
nullptr;
3230 using RowOptions = QRangeModelDetails::QRangeModelRowOptions<wrapped_row_type>;
3231 using ItemType = QRangeModelDetails::wrapped_t<
typename row_traits::item_type>;
3233 if constexpr (QRangeModelDetails::item_access<ItemType>::hasMimeData) {
3234 using ItemAccess = QRangeModelDetails::QRangeModelItemAccess<ItemType>;
3237 result = ItemAccess::mimeData(MimeDataRange<MimeDataItemIterator>{begin, end});
3238 }
else if constexpr (QRangeModelDetails::hasMimeDataRowSpan<wrapped_row_type>) {
3239 const auto begin =
MimeDataRowIterator(indexes.begin(), indexes.begin(), indexes.end(),
this);
3240 const auto end =
MimeDataRowIterator(indexes.end(), indexes.begin(), indexes.end(),
this);
3241 result = RowOptions::mimeData(MimeDataRange<MimeDataRowIterator>{begin, end});
3242 }
else if constexpr (QRangeModelDetails::hasMimeDataIndexList<wrapped_row_type>) {
3243 result = RowOptions::mimeData(indexes);
3309 static constexpr bool modelCopied = !QRangeModelDetails::is_wrapped<Range>() &&
3310 (std::is_reference_v<Range> || std::is_const_v<std::remove_reference_t<Range>>);
3312 static constexpr bool modelShared = QRangeModelDetails::is_any_shared_ptr<Range>();
3314 static constexpr bool default_row_deleter = protocol_traits::is_default &&
3315 protocol_traits::has_deleteRow;
3317 static constexpr bool ambiguousRowOwnership = (modelCopied || modelShared) &&
3320 static_assert(!ambiguousRowOwnership,
3321 "Using of copied and shared tree and table models with rows as raw pointers, "
3322 "and the default protocol is not allowed due to ambiguity of rows ownership. "
3323 "Move the model in, use another row type, or implement a custom tree protocol.");
3325 if constexpr (protocol_traits::has_deleteRow && !std::is_pointer_v<Range>
3326 && !QRangeModelDetails::is_any_of<Range, std::reference_wrapper>()) {
3329 that().deleteRemovedRows(begin, end);
3335 if constexpr (dynamicColumns() && !row_features::has_resize) {
3339 }
else if constexpr (!protocol_traits::has_newRow) {
3342 }
else if constexpr (!range_features::has_insert_range
3343 && !std::is_copy_constructible_v<row_type>) {
3349 return Structure::canInsertRowsImpl();
3355 return Structure::canRemoveRowsImpl();
3358 template <
typename F>
3359 bool writeAt(
const QModelIndex &index, F&& writer)
3361 row_reference row = rowData(index);
3364 return row_traits::for_element_at(row, index.column(), [&writer](
auto &&target) {
3365 using target_type =
decltype(target);
3367 if constexpr (std::is_lvalue_reference_v<target_type>
3368 && !std::is_const_v<std::remove_reference_t<target_type>>) {
3369 return writer(std::forward<target_type>(target));
3376 template <
typename F>
3377 bool readAt(
const QModelIndex &index, F&& reader)
const {
3378 const_row_reference row = rowData(index);
3381 return row_traits::for_element_at(row, index.column(), std::forward<F>(reader));
3384 template <
typename Value>
3387 if constexpr (std::is_constructible_v<QVariant, Value>)
3388 return QVariant(value);
3390 return QVariant::fromValue(value);
3392 template <
typename Value>
3396 if constexpr (std::is_constructible_v<QVariant, Value *>)
3397 return QVariant(value);
3399 return read(*value);
3404 template <
typename Target>
3405 static bool write(Target &target,
const QVariant &value)
3407 using Type = std::remove_reference_t<Target>;
3408 if constexpr (std::is_constructible_v<Target, QVariant>) {
3411 }
else if (value.canConvert<Type>()) {
3412 target = value.value<Type>();
3417 template <
typename Target>
3418 static bool write(Target *target,
const QVariant &value)
3421 return write(*target, value);
3425 template <
typename ItemType>
3429 operator QMetaProperty()
const {
3430 const QByteArray roleName = that.itemModel().roleNames().value(role);
3431 const QMetaObject &mo = ItemType::staticMetaObject;
3432 if (
const int index = mo.indexOfProperty(roleName.data());
3434 return mo.property(index);
3438 const QRangeModelImpl &that;
3440 } findProperty{*
this, role};
3442 if constexpr (ModelData::cachesProperties)
3443 return *m_data.properties.tryEmplace(role, findProperty).iterator;
3445 return findProperty;
3449 const QObject *gadget,
const QMetaProperty &prop)
const
3451 if (!index.isValid())
3453 const typename ModelData::Connection connection = {gadget, role};
3454 if (prop.hasNotifySignal() &&
this->autoConnectPolicy() == AutoConnectPolicy::OnRead
3455 && !m_data.connections.contains(connection)) {
3456 if constexpr (isMutable())
3457 Self::connectProperty(index, gadget, m_data.context, role, prop);
3459 Self::connectPropertyConst(index, gadget, m_data.context, role, prop);
3460 m_data.connections.insert(connection);
3464 template <
typename ItemType>
3467 using item_type = std::remove_pointer_t<ItemType>;
3469 QMetaProperty prop = roleProperty<item_type>(role);
3470 if (!prop.isValid() && role == Qt::EditRole) {
3471 role = Qt::DisplayRole;
3472 prop = roleProperty<item_type>(Qt::DisplayRole);
3475 if (prop.isValid()) {
3476 if constexpr (itemsAreQObjects)
3477 connectPropertyOnRead(index, role, gadget, prop);
3478 result = readProperty(prop, gadget);
3483 template <
typename ItemType>
3486 return readRole(index, role, &gadget);
3489 template <
typename ItemType>
3492 if constexpr (std::is_base_of_v<QObject, ItemType>)
3493 return prop.read(gadget);
3495 return prop.readOnGadget(gadget);
3498 template <
typename ItemType>
3501 using item_type = std::remove_pointer_t<ItemType>;
3502 const QMetaObject &mo = item_type::staticMetaObject;
3503 const QMetaProperty prop = mo.property(index.column() + mo.propertyOffset());
3505 if constexpr (rowsAreQObjects)
3506 connectPropertyOnRead(index, Qt::DisplayRole, gadget, prop);
3508 return readProperty(prop, gadget);
3511 template <
typename ItemType>
3514 return readProperty(index, &gadget);
3517 template <
typename ItemType>
3518 bool writeRole(
int role, ItemType *gadget,
const QVariant &data)
3520 using item_type = std::remove_pointer_t<ItemType>;
3521 auto prop = roleProperty<item_type>(role);
3522 if (!prop.isValid() && role == Qt::EditRole)
3523 prop = roleProperty<item_type>(Qt::DisplayRole);
3525 return prop.isValid() ? writeProperty(prop, gadget, data) :
false;
3528 template <
typename ItemType>
3529 bool writeRole(
int role, ItemType &&gadget,
const QVariant &data)
3531 return writeRole(role, &gadget, data);
3534 template <
typename ItemType>
3535 static bool writeProperty(
const QMetaProperty &prop, ItemType *gadget,
const QVariant &data)
3537 if constexpr (std::is_base_of_v<QObject, ItemType>)
3538 return prop.write(gadget, data);
3540 return prop.writeOnGadget(gadget, data);
3542 template <
typename ItemType>
3545 using item_type = std::remove_pointer_t<ItemType>;
3546 const QMetaObject &mo = item_type::staticMetaObject;
3547 return writeProperty(mo.property(property + mo.propertyOffset()), gadget, data);
3550 template <
typename ItemType>
3551 static bool writeProperty(
int property, ItemType &&gadget,
const QVariant &data)
3553 return writeProperty(property, &gadget, data);
3556 template <
typename ItemType>
3559 using item_type = std::remove_pointer_t<ItemType>;
3560 const QMetaObject &mo = item_type::staticMetaObject;
3561 bool success =
true;
3562 if (property == -1) {
3564 if constexpr (std::is_base_of_v<QObject, item_type>) {
3565 for (
int p = mo.propertyOffset(); p < mo.propertyCount(); ++p)
3566 success = writeProperty(mo.property(p), object, {}) && success;
3571 success = writeProperty(mo.property(property + mo.propertyOffset()), object, {});
3576 template <
typename ItemType>
3579 return resetProperty(property, &object);
3585 Q_ASSERT(index.isValid());
3586 return that().rowDataImpl(index);
3591 Q_ASSERT(index.isValid());
3592 return that().rowDataImpl(index);
3597 if (!index.isValid())
3598 return m_data.model();
3601 return that().childRangeImpl(index);
3606 if (!index.isValid())
3607 return m_data.model();
3610 return that().childRangeImpl(index);
3621template <
typename Range,
typename Protocol>
3628 using range_type =
typename Base::range_type;
3629 using range_features =
typename Base::range_features;
3630 using row_type =
typename Base::row_type;
3631 using row_ptr =
typename Base::row_ptr;
3632 using const_row_ptr =
typename Base::const_row_ptr;
3634 using tree_traits =
typename Base::protocol_traits;
3635 static constexpr bool is_mutable_impl = tree_traits::has_mutable_childRows;
3637 static constexpr bool rows_are_any_refs_or_pointers = Base::rows_are_raw_pointers ||
3638 QRangeModelDetails::is_smart_ptr<row_type>() ||
3639 QRangeModelDetails::is_any_of<row_type,
std::reference_wrapper>();
3640 static_assert(!Base::dynamicColumns(),
"A tree must have a static number of columns!");
3644 : Base(
std::forward<Range>(model),
std::forward<Protocol>(p), itemModel)
3649 for (
auto &&child : children)
3661 auto *children =
this->childRange(parent);
3664 return autoConnectPropertiesRange(QRangeModelDetails::refTo(children), parent);
3670 if (!parent.isValid())
3671 return this->createIndex(row, column);
3673 if (parent.column())
3674 return QModelIndex();
3676 const_row_ptr grandParent =
static_cast<const_row_ptr>(parent.constInternalPointer());
3677 const auto &parentSiblings = childrenOf(grandParent);
3684 if (!child.isValid())
3688 const_row_ptr parentRow =
static_cast<const_row_ptr>(child.constInternalPointer());
3693 auto &&grandParent =
this->protocol().parentRow(
QRangeModelDetails::refTo(parentRow));
3694 const range_type &parentSiblings = childrenOf(
QRangeModelDetails::pointerTo(grandParent));
3698 const auto it =
std::find_if(begin, end, [parentRow](
auto &&s){
3702 return this->createIndex(
std::distance(begin, it), 0,
3709 return Base::size(
this->childRange(parent));
3716 return Base::fixedColumnCount();
3721 return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
3729 return (rows_are_any_refs_or_pointers || tree_traits::has_setParentRow)
3730 && Base::dynamicRows() && range_features::has_insert;
3738 return (rows_are_any_refs_or_pointers || tree_traits::has_setParentRow)
3739 && Base::dynamicRows() && range_features::has_erase;
3747 static constexpr bool canMoveRows(
const QModelIndex &,
const QModelIndex &)
3753 const QModelIndex &destParent,
int destRow)
3758 if constexpr (!rows_are_any_refs_or_pointers && !tree_traits::has_setParentRow) {
3760 }
else if constexpr (!(range_features::has_insert && range_features::has_erase)) {
3762 }
else if (!
this->beginMoveRows(sourceParent, sourceRow, sourceRow + count - 1,
3763 destParent, destRow)) {
3767 range_type *source =
this->childRange(sourceParent);
3768 range_type *destination =
this->childRange(destParent);
3773 if constexpr (range_features::has_insert_range) {
3775 const auto sourceEnd =
std::next(sourceStart, count);
3777 destination->insert(destStart,
std::move_iterator(sourceStart),
3778 std::move_iterator(sourceEnd));
3779 }
else if constexpr (
std::is_copy_constructible_v<row_type>) {
3781 destination->insert(destStart, count, row_type{});
3784 row_ptr parentRow = destParent.isValid()
3790 if (parentRow ==
static_cast<row_ptr>(sourceParent.internalPointer())) {
3791 if (sourceParent.row() < destRow) {
3792 source =
this->childRange(sourceParent);
3795 source =
this->childRange(
this->createIndex(sourceParent.row() + count, 0,
3796 sourceParent.internalPointer()));
3803 const auto writeEnd =
std::next(writeStart, count);
3805 const auto sourceEnd =
std::next(sourceStart, count);
3807 for (
auto write = writeStart, read = sourceStart; write != writeEnd; ++write, ++read) {
3810 if constexpr (!range_features::has_insert_range)
3811 *write =
std::move(*read);
3815 source->erase(sourceStart, sourceEnd);
3825 this->endMoveRows();
3833 static_assert(tree_traits::has_setParentRow);
3834 row_type empty_row =
this->protocol().newRow();
3840 template <
typename It,
typename Sentinel>
3843 if constexpr (tree_traits::has_deleteRow) {
3844 for (
auto it = begin; it != end; ++it) {
3845 if constexpr (Base::isMutable()) {
3846 decltype(
auto) children =
this->protocol().childRows(
QRangeModelDetails::refTo(*it));
3854 this->protocol().deleteRow(
std::move(*it));
3861 const auto persistentIndexList =
this->persistentIndexList();
3862 const auto [firstColumn, lastColumn] = [&persistentIndexList]{
3863 int first = std::numeric_limits<
int>::max();
3865 for (
const auto &pmi : persistentIndexList) {
3866 first = (
std::min)(pmi.column(), first);
3867 last = (
std::max)(pmi.column(), last);
3869 return std::pair(first, last);
3877 if constexpr (tree_traits::has_setParentRow && !rows_are_any_refs_or_pointers) {
3878 const bool changePersistentIndexes = pmiToColumn >= pmiFromColumn;
3881 for (
auto it = begin; it != end; ++it) {
3882 decltype(
auto) maybeChildren =
this->protocol().childRows(*it);
3888 for (
auto &child : childrenRef) {
3889 const_row_ptr oldParent =
this->protocol().parentRow(child);
3890 if (oldParent != parentRow) {
3891 if (changePersistentIndexes) {
3892 for (
int column = pmiFromColumn; column <= pmiToColumn; ++column) {
3893 this->changePersistentIndex(
this->createIndex(row, column, oldParent),
3894 this->createIndex(row, column, parentRow));
3897 this->protocol().setParentRow(child, parentRow);
3910 for (
const auto &row : range) {
3911 if (!
this->autoConnectPropertiesInRow(row, rowIndex, parent))
3916 if (!autoConnectPropertiesRange(QRangeModelDetails::refTo(children),
3917 this->itemModel().index(rowIndex, 0, parent))) {
3928 return autoConnectPropertiesRange(*
this->m_data.model(), {});
3933 const_row_ptr parentRow =
static_cast<const_row_ptr>(index.constInternalPointer());
3934 const range_type &siblings = childrenOf(parentRow);
3935 Q_ASSERT(index.row() <
int(Base::size(siblings)));
3941 row_ptr parentRow =
static_cast<row_ptr>(index.internalPointer());
3942 range_type &siblings = childrenOf(parentRow);
3943 Q_ASSERT(index.row() <
int(Base::size(siblings)));
3949 const auto &row =
this->rowData(index);
3951 return static_cast<
const range_type *>(
nullptr);
3953 decltype(
auto) children =
this->protocol().childRows(
QRangeModelDetails::refTo(row));
3959 auto &row =
this->rowData(index);
3961 return static_cast<range_type *>(
nullptr);
3963 decltype(
auto) children =
this->protocol().childRows(
QRangeModelDetails::refTo(row));
3964 using Children = std::remove_reference_t<
decltype(children)>;
3966 if constexpr (QRangeModelDetails::is_any_of<Children, std::optional>())
3967 if constexpr (std::is_default_constructible<
typename Children::value_type>()) {
3969 children.emplace(range_type{});
3978 : *
this->m_data.model();
3984 : *
this->m_data.model();
3987 template <
typename LessThan>
3990 for (
auto &row : range) {
3991 decltype(
auto) children =
this->protocol().childRows(
QRangeModelDetails::refTo(row));
3997 this->sortSubRange(range, parentRow, lessThan);
4000 template <
typename LessThan>
4003 sortImplRecursive(*
this->m_data.model(),
nullptr, lessThan);
4009 erase_if(list, [expectedParent](
const QModelIndex &index){
4010 return static_cast<row_ptr>(index.internalPointer()) != expectedParent;
4015 int role,
const QVariant &value,
int hits, Qt::MatchFlags flags,
int column,
4016 QModelIndexList &result)
const
4021 const bool recurse = flags.testAnyFlag(Qt::MatchRecursive);
4022 const bool allHits = (hits == -1);
4024 for (
int r = from; it != end && r < to && (allHits || result.size() < hits); ++it, ++r) {
4025 const QModelIndex index =
this->createIndex(r, column, parentPtr);
4026 if (
this->matchRow(*it, index, role, value, flags))
4027 result.append(index);
4030 decltype(
auto) children =
this->protocol().childRows(
QRangeModelDetails::refTo(*it));
4033 matchImplRecursive(QRangeModelDetails::refTo(children),
4034 QRangeModelDetails::pointerTo(*it), 0,
4035 int(QRangeModelDetails::size(QRangeModelDetails::refTo(children))),
4036 role, value, hits, flags, column, result);
4043 Qt::MatchFlags flags)
const
4045 QModelIndexList result;
4046 const bool wrap = flags.testAnyFlag(Qt::MatchWrap);
4047 const int column = start.column();
4048 const int from = start.row();
4049 const int to =
this->rowCount(start.parent());
4051 for (
int i = 0; (wrap && i < 2) || (!wrap && i < 1); ++i) {
4052 const int fromRow = (i == 0) ? from : 0;
4053 const int toRow = (i == 0) ? to : from;
4054 matchImplRecursive(*
this->m_data.model(),
nullptr, fromRow, toRow,
4055 role, value, hits, flags, column, result);
4069template <
typename Range>
4076 static constexpr bool is_mutable_impl =
true;
4094 if constexpr (Base::dynamicColumns()) {
4095 if (column <
int(Base::size(*QRangeModelDetails::pos(*
this->m_data.model(), row))))
4096 return this->createIndex(row, column);
4099 qCritical(
"QRangeModel: Column-range at row %d is not large enough!", row);
4103 return this->createIndex(row, column);
4114 if (parent.isValid())
4116 return int(Base::size(*
this->m_data.model()));
4121 if (parent.isValid())
4125 if constexpr (Base::dynamicColumns()) {
4126 return int(Base::size(*
this->m_data.model()) == 0
4128 : Base::size(*QRangeModelDetails::adl_begin(*
this->m_data.model())));
4130 return Base::fixedColumnCount();
4136 return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemNeverHasChildren;
4141 return Base::dynamicRows() && range_features::has_insert;
4146 return Base::dynamicRows() && range_features::has_erase;
4149 static constexpr bool canMoveColumns(
const QModelIndex &source,
const QModelIndex &destination)
4151 return !source.isValid() && !destination.isValid();
4154 static constexpr bool canMoveRows(
const QModelIndex &source,
const QModelIndex &destination)
4156 return !source.isValid() && !destination.isValid();
4160 const QModelIndex &,
int)
noexcept
4168 row_type empty_row =
this->protocol().newRow();
4171 if constexpr (Base::dynamicColumns() && row_features::has_resize) {
4179 template <
typename It,
typename Sentinel>
4182 if constexpr (Base::protocol_traits::has_deleteRow) {
4183 for (
auto it = begin; it != end; ++it)
4184 this->protocol().deleteRow(
std::move(*it));
4190 Q_ASSERT(q20::cmp_less(index.row(), Base::size(*
this->m_data.model())));
4196 Q_ASSERT(q20::cmp_less(index.row(), Base::size(*
this->m_data.model())));
4213 return *
this->m_data.model();
4219 return *
this->m_data.model();
4230 for (
const auto &row : *
this->m_data.model()) {
4231 result &=
this->autoConnectPropertiesInRow(row, rowIndex, {});
4237 template <
typename LessThan>
4240 this->sortSubRange(*
this->m_data.model(),
nullptr, lessThan);
4246 int hits, Qt::MatchFlags flags)
const
4248 QModelIndexList result;
4249 const bool wrap = flags.testAnyFlag(Qt::MatchWrap);
4250 const bool allHits = (hits == -1);
4251 const int column = start.column();
4252 int from = start.row();
4253 int to =
this->rowCount({});
4254 decltype(
auto) siblings = *
this->m_data.model();
4256 for (
int i = 0; (wrap && i < 2) || (!wrap && i < 1); ++i) {
4259 for (
int r = from; it != end && r < to && (allHits || result.size() < hits);
4263 const QModelIndex index =
this->createIndex(r, column,
nullptr);
4264 if (
this->matchRow(*it, index, role, value, flags))
4265 result.append(index);
4277 return this->dropDataOnItem(data, index);
QModelIndex parentImpl(const QModelIndex &) const
static constexpr bool canMoveRows(const QModelIndex &source, const QModelIndex &destination)
void deleteRemovedRows(It &&begin, Sentinel &&end)
QModelIndexList matchImpl(const QModelIndex &start, int role, const QVariant &value, int hits, Qt::MatchFlags flags) const
const range_type & childrenOf(const_row_ptr row) const
static constexpr bool canRemoveRowsImpl()
bool dropOnItem(const QMimeData *data, const QModelIndex &index)
QGenericTableItemModelImpl(Range &&model, QRangeModel *itemModel)
range_type * childRangeImpl(const QModelIndex &)
int columnCountImpl(const QModelIndex &parent) const
constexpr bool moveRowsAcross(const QModelIndex &, int, int, const QModelIndex &, int) noexcept
decltype(auto) rowDataImpl(const QModelIndex &index) const
static constexpr bool canInsertRowsImpl()
const range_type * childRangeImpl(const QModelIndex &) const
int rowCountImpl(const QModelIndex &parent) const
void resetParentInChildren(range_type *)
void prunePersistentIndexList(QModelIndexList &, typename Base::row_ptr)
bool autoConnectPropertiesImpl() const
static constexpr bool canMoveColumns(const QModelIndex &source, const QModelIndex &destination)
decltype(auto) rowDataImpl(const QModelIndex &index)
QModelIndex indexImpl(int row, int column, const QModelIndex &) const
range_type & childrenOf(row_ptr row)
static constexpr Qt::ItemFlags defaultFlags()
void sortImpl(const LessThan &lessThan)
auto makeEmptyRow(typename Base::row_ptr)
static constexpr bool canMoveColumns(const QModelIndex &, const QModelIndex &)
void matchImplRecursive(const range_type &range, const_row_ptr parentPtr, int from, int to, int role, const QVariant &value, int hits, Qt::MatchFlags flags, int column, QModelIndexList &result) const
bool dropOnItem(const QMimeData *, const QModelIndex &)
QModelIndexList matchImpl(const QModelIndex &start, int role, const QVariant &value, int hits, Qt::MatchFlags flags) const
auto makeEmptyRow(row_ptr parentRow)
void setParentRow(range_type &children, row_ptr parent)
bool autoConnectPropertiesImpl() const
range_type * childRangeImpl(const QModelIndex &index)
bool moveRowsAcross(const QModelIndex &sourceParent, int sourceRow, int count, const QModelIndex &destParent, int destRow)
void resetParentInChildren(range_type *children)
int rowCountImpl(const QModelIndex &parent) const
range_type & childrenOf(row_ptr row)
static constexpr bool canRemoveRowsImpl()
void resetParentInChildrenRecursive(range_type *children, int pmiFromColumn, int pmiToColumn)
int columnCountImpl(const QModelIndex &) const
static constexpr bool canMoveRows(const QModelIndex &, const QModelIndex &)
const range_type & childrenOf(const_row_ptr row) const
decltype(auto) rowDataImpl(const QModelIndex &index)
QGenericTreeItemModelImpl(Range &&model, Protocol &&p, QRangeModel *itemModel)
void prunePersistentIndexList(QModelIndexList &list, row_ptr expectedParent)
bool autoConnectPropertiesRange(const range_type &range, const QModelIndex &parent) const
QModelIndex indexImpl(int row, int column, const QModelIndex &parent) const
void deleteRemovedRows(It &&begin, Sentinel &&end)
bool autoConnectProperties(const QModelIndex &parent) const
void sortImplRecursive(range_type &range, row_ptr parentRow, const LessThan &lessThan)
const range_type * childRangeImpl(const QModelIndex &index) const
static constexpr bool canInsertRowsImpl()
decltype(auto) rowDataImpl(const QModelIndex &index) const
void deleteRemovedRows(range_type &range)
static constexpr Qt::ItemFlags defaultFlags()
void sortImpl(const LessThan &lessThan)
QModelIndex parentImpl(const QModelIndex &child) const
const QAbstractItemModel & itemModel() const
void beginInsertRows(const QModelIndex &parent, int start, int count)
void multiData(const QModelIndex &index, QModelRoleDataSpan roleDataSpan) const
bool beginMoveColumns(const QModelIndex &sourceParent, int sourceFirst, int sourceLast, const QModelIndex &destParent, int destRow)
QStringList mimeTypes() const
bool setItemData(const QModelIndex &index, const QMap< int, QVariant > &data)
QMap< int, QVariant > itemData(const QModelIndex &index) const
bool insertRows(int row, int count, const QModelIndex &parent)
Qt::DropActions adjustSupportedDropActions(Qt::DropActions dropActions)
Qt::ItemFlags flags(const QModelIndex &index) const
bool beginMoveRows(const QModelIndex &sourceParent, int sourceFirst, int sourceLast, const QModelIndex &destParent, int destRow)
void beginRemoveRows(const QModelIndex &parent, int start, int count)
bool clearItemData(const QModelIndex &index)
QVariant data(const QModelIndex &index, int role) const
QRangeModelImplBase(QRangeModel *itemModel)
QModelIndexList persistentIndexList() const
bool canDropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) const
int columnCount(const QModelIndex &parent) const
static Q_CORE_EXPORT bool connectProperties(const QModelIndex &index, const QObject *item, QRangeModelDetails::AutoConnectContext *context, const QHash< int, QMetaProperty > &properties)
QModelIndex sibling(int row, int column, const QModelIndex &index) const
void beginInsertColumns(const QModelIndex &parent, int start, int count)
bool insertColumns(int column, int count, const QModelIndex &parent)
void setAutoConnectPolicy()
bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent)
void sort(int column, Qt::SortOrder order)
bool removeRows(int row, int count, const QModelIndex &parent)
Qt::DropActions adjustSupportedDragActions(Qt::DropActions dragActions)
static Q_CORE_EXPORT bool matchValue(const QString &itemData, const QVariant &value, Qt::MatchFlags flags)
QModelIndex parent(const QModelIndex &child) const
void changePersistentIndex(const QModelIndex &from, const QModelIndex &to)
QAbstractItemModel & itemModel()
QModelIndex createIndex(int row, int column, const void *ptr=nullptr) const
QHash< int, QByteArray > roleNames() const
void interfaceVersion(int &version) const
bool moveColumns(const QModelIndex &sourceParent, int sourceColumn, int count, const QModelIndex &destParent, int destColumn)
bool setData(const QModelIndex &index, const QVariant &data, int role)
void dataChanged(const QModelIndex &from, const QModelIndex &to, const QList< int > &roles)
QVariant headerData(int section, Qt::Orientation orientation, int role) const
static Q_CORE_EXPORT bool connectPropertiesConst(const QModelIndex &index, const QObject *item, QRangeModelDetails::AutoConnectContext *context, const QHash< int, QMetaProperty > &properties)
static Qt::partial_ordering compareData(const QVariant &lhs, const QVariant &rhs, const QCollator *collator)
AutoConnectPolicy autoConnectPolicy() const
bool removeColumns(int column, int count, const QModelIndex &parent)
Q_CORE_EXPORT bool dropDataOnItem(const QMimeData *data, const QModelIndex &index)
static Q_CORE_EXPORT bool connectPropertyConst(const QModelIndex &index, const QObject *item, QRangeModelDetails::AutoConnectContext *context, int role, const QMetaProperty &property)
std::tuple< typename C::Destroy, typename C::InvalidateCaches, typename C::SetHeaderData, typename C::SetData, typename C::SetItemData, typename C::ClearItemData, typename C::InsertColumns, typename C::RemoveColumns, typename C::MoveColumns, typename C::InsertRows, typename C::RemoveRows, typename C::MoveRows, typename C::Index, typename C::Parent, typename C::Sibling, typename C::RowCount, typename C::ColumnCount, typename C::Flags, typename C::HeaderData, typename C::Data, typename C::ItemData, typename C::RoleNames, typename C::MultiData, typename C::SetAutoConnectPolicy, typename C::InterfaceVersion, typename C::Sort, typename C::Match, typename C::AdjustSupportedDragActions, typename C::AdjustSupportedDropActions, typename C::MimeTypes, typename C::CanDropMimeData, typename C::DropMimeData, typename C::MimeData > MethodTemplates
QModelIndex index(int row, int column, const QModelIndex &parent) const
QModelIndexList match(const QModelIndex &start, int role, const QVariant &value, int hits, Qt::MatchFlags flags) const
QMimeData * mimeData(const QModelIndexList &indexes) const
bool setHeaderData(int section, Qt::Orientation orientation, const QVariant &data, int role)
int rowCount(const QModelIndex &parent) const
Q_CORE_EXPORT int sortRole() const
static Q_CORE_EXPORT bool connectProperty(const QModelIndex &index, const QObject *item, QRangeModelDetails::AutoConnectContext *context, int role, const QMetaProperty &property)
void beginRemoveColumns(const QModelIndex &parent, int start, int count)
bool moveRows(const QModelIndex &sourceParent, int sourceRow, int count, const QModelIndex &destParent, int destRow)
bool removeRows(int row, int count, const QModelIndex &parent={})
static QVariant readProperty(const QMetaProperty &prop, ItemType *gadget)
QHash< int, QByteArray > roleNames() const
row_reference rowData(const QModelIndex &index)
static constexpr bool dynamicRows()
static QVariant read(const Value &value)
const range_type * childRange(const QModelIndex &index) const
bool moveColumns(const QModelIndex &sourceParent, int sourceColumn, int count, const QModelIndex &destParent, int destColumn)
auto maybeBlockDataChangedDispatch()
static constexpr bool has_metaobject
QMetaProperty roleProperty(int role) const
int columnCount(const QModelIndex &parent) const
bool writeRole(int role, ItemType &&gadget, const QVariant &data)
static bool write(Target *target, const QVariant &value)
void connectPropertyOnRead(const QModelIndex &index, int role, const QObject *gadget, const QMetaProperty &prop) const
Qt::ItemFlags flags(const QModelIndex &index) const
bool insertColumns(int column, int count, const QModelIndex &parent)
bool doDropMimeData(std::vector< QRangeModelDetails::DroppedEntry< Entry > > &droppedEntries, DropOperation dropOperation, int row, int column, const QModelIndex &target)
QVariant data(const QModelIndex &index, int role) const
QModelIndexList match(const QModelIndex &start, int role, const QVariant &value, int hits, Qt::MatchFlags flags) const
QVariant headerData(int section, Qt::Orientation orientation, int role) const
static constexpr bool isRangeModelRole(int role)
bool clearItemData(const QModelIndex &index)
void multiData(const QModelIndex &index, QModelRoleDataSpan roleDataSpan) const
bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &target)
static constexpr int fixedColumnCount()
const protocol_type & protocol() const
static bool resetProperty(int property, ItemType &&object)
QModelIndex sibling(int row, int column, const QModelIndex &index) const
static bool writeProperty(int property, ItemType &&gadget, const QVariant &data)
bool setItemData(const QModelIndex &index, const QMap< int, QVariant > &data)
bool insertRows(int row, int count, const QModelIndex &parent)
static constexpr bool canInsertRows()
void interfaceVersion(int &versionNumber) const
static bool writeProperty(const QMetaProperty &prop, ItemType *gadget, const QVariant &data)
QVariant readProperty(const QModelIndex &index, ItemType *gadget) const
void sort(int column, Qt::SortOrder order)
static constexpr int size(const C &c)
const_row_reference rowData(const QModelIndex &index) const
bool writeAt(const QModelIndex &index, F &&writer)
static constexpr bool one_dimensional_range
static constexpr bool rows_are_raw_pointers
bool setHeaderData(int, Qt::Orientation, const QVariant &, int)
bool removeColumns(int column, int count, const QModelIndex &parent)
static constexpr bool isMutable()
bool setData(const QModelIndex &index, const QVariant &data, int role)
QModelIndex parent(const QModelIndex &child) const
static QVariant read(Value *value)
static bool write(Target &target, const QVariant &value)
bool writeRole(int role, ItemType *gadget, const QVariant &data)
QVariant readRole(const QModelIndex &index, int role, const ItemType &gadget) const
Qt::DropActions adjustSupportedDragActions(Qt::DropActions dragActions)
QRangeModelImpl< Structure, Range, Protocol > Self
bool canDropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &target) const
static constexpr bool canRemoveRows()
static constexpr int static_column_count
QVariant readProperty(const QModelIndex &index, const ItemType &gadget) const
protocol_type & protocol()
int rowCount(const QModelIndex &parent) const
static constexpr bool rows_are_owning_or_raw_pointers
QModelIndex index(int row, int column, const QModelIndex &parent) const
static constexpr int static_row_count
void setAutoConnectPolicy()
static bool writeProperty(int property, ItemType *gadget, const QVariant &data)
QRangeModelImpl(Range &&model, Protocol &&protocol, QRangeModel *itemModel)
void sortSubRange(range_type &range, row_ptr expectedParent, const LessThan &lessThan)
const Structure & that() const
static constexpr bool isPrimaryRole(int role)
void updateTarget(LHS *org, RHS &©) noexcept
static constexpr bool itemsAreQObjects
static constexpr bool dynamicColumns()
range_type * childRange(const QModelIndex &index)
bool moveRows(const QModelIndex &sourceParent, int sourceRow, int count, const QModelIndex &destParent, int destRow)
QStringList mimeTypes() const
QVariant readRole(const QModelIndex &index, int role, ItemType *gadget) const
static bool resetProperty(int property, ItemType *object)
bool autoConnectPropertiesInRow(const row_type &row, int rowIndex, const QModelIndex &parent) const
bool readAt(const QModelIndex &index, F &&reader) const
static constexpr bool rowsAreQObjects
bool doInsertColumns(int column, int count, const QModelIndex &parent, InsertFn insertFn)
void updateTarget(LHS &org, RHS &©) noexcept
QMimeData * mimeData(const QModelIndexList &indexes) const
Qt::DropActions adjustSupportedDropActions(Qt::DropActions dropActions)
QMap< int, QVariant > itemData(const QModelIndex &index) const
void clearConnectionInRow(const row_type &row, int rowIndex, const QModelIndex &parent) const
bool doInsertRows(int row, int count, const QModelIndex &parent, InsertFn &&insertFn)
bool matchRow(const_row_reference row, const QModelIndex &index, int role, const QVariant &value, Qt::MatchFlags flags) const
decltype(QRangeModelRowOptions< row_type >::mimeTypes()) hasMimeTypes_test
static auto adl_end(C &&c) -> decltype(end(QRangeModelDetails::refTo(std::forward< C >(c))))
decltype(QRangeModelRowOptions< row_type >::flags(std::declval< const row_type & >())) hasRowFlags_test
static constexpr bool hasMimeDataRowSpan
static constexpr bool hasMimeTypes
static constexpr bool has_metaobject_v
static constexpr bool is_range_v
static constexpr bool array_like_v
static constexpr bool hasMimeDataIndexList
static void rotate(C &c, int src, int count, int dst)
static constexpr bool hasDropMimeData
static constexpr bool tuple_like_v
typename QRangeModelDetails::wrapped_helper< T >::type wrapped_t
auto value(It &&it) -> decltype(it.value())
std::conjunction< std::is_swappable< decltype(*std::declval< It >())>, std::is_base_of< std::forward_iterator_tag, typename std::iterator_traits< It >::iterator_category > > test_rotate
auto key(It &&it) -> decltype(it.key())
static constexpr bool hasDropMimeDataFull
static constexpr int static_size_v
static constexpr bool isValid(const T &t) noexcept
static auto pos(C &&c, int i)
static constexpr bool hasHeaderData
static constexpr bool hasCanDropMimeData
static decltype(auto) refTo(T &&t)
static constexpr bool hasRowFlags
static auto pointerTo(T &&t)
static constexpr bool hasCanDropMimeDataFull
static auto adl_begin(C &&c) -> decltype(begin(QRangeModelDetails::refTo(std::forward< C >(c))))
static constexpr bool is_multi_role_v
friend bool operator==(const Connection &lhs, const Connection &rhs) noexcept
friend size_t qHash(const Connection &c, size_t seed) noexcept
QSet< Connection > connections
~ConnectionStorage()=default
AutoConnectContext * context
auto setParentRow(R &row, R *parent) -> decltype(row.setParentRow(parent))
auto childRows(R &row) -> decltype(row.childRows())
auto childRows(const R &row) const -> decltype(row.childRows())
auto parentRow(const R &row) const -> decltype(row.parentRow())
friend bool operator==(const Cell &lhs, const Cell &rhs) noexcept
auto newRow() -> decltype(R{})
const QModelIndex & index() const
friend decltype(auto) get(const MimeDataEntry &entry)
const wrapped_entry & entry() const
const QModelIndex m_index
QHash< int, QMetaProperty > properties
static constexpr bool cachesProperties
QHash< int, QMetaProperty > properties
static constexpr bool cachesProperties
std::remove_const_t< ModelStorage > m_model
static constexpr bool int_key
static constexpr bool hasCanDropMimeDataFull
static constexpr bool hasFlags
static constexpr bool hasMimeData
decltype(Access::flags(std::declval< const Test & >())) hasFlags_test
static constexpr bool hasReadRole
static constexpr bool hasWriteRole
static constexpr bool hasDropMimeData
decltype(Access::mimeTypes()) hasMimeTypes_test
static constexpr bool hasMimeTypes
static constexpr bool hasDropMimeDataFull
static constexpr bool hasCanDropMimeData
static QHash< int, QByteArray > roleNames(That *)
static constexpr bool has_erase
static constexpr bool has_splice
static constexpr bool has_resize
static constexpr bool is_mutable
static constexpr bool has_rotate
static constexpr bool has_cbegin
static constexpr bool has_insert
static constexpr bool is_default
static constexpr bool has_setParentRow
static constexpr bool is_list
static constexpr bool has_mutable_childRows
static constexpr bool has_deleteRow
static constexpr bool has_newRow
static constexpr bool is_tree
static constexpr bool is_table
static constexpr bool has_insert_range
static constexpr bool is_mutable
static constexpr bool has_rotate
static constexpr bool has_resize
static constexpr bool has_insert
static constexpr bool has_cbegin
static constexpr bool has_splice
static constexpr bool has_erase
static constexpr bool isMultiRole
static constexpr int fixed_size()
static bool for_each_element(const T &row, const QModelIndex &firstIndex, Fn &&fn)
static QVariant column_name(int)
static bool for_element_at(C &&container, std::size_t idx, Fn &&fn)
static constexpr int static_size
static constexpr bool is_range
static constexpr bool hasMetaObject
decltype(std::declval< C & >().sort(std::declval< LessThan && >())) sortMember_test
static constexpr bool hasCollatedCompare
const QRangeModelImpl *const that
const QCollator *const collator
auto compare(const Item &lhs, const Item &rhs) const
static constexpr bool hasSortMember
auto operator()(const Item &lhs, const Item &rhs) const
Compare(const QRangeModelImpl *impl, int column, Qt::SortOrder order)
const QModelIndex m_index
const Qt::SortOrder m_order
static std::optional< bool > compareInvalid(const Item &lhs, const Item &rhs)
bool checkComparable() const
std::input_iterator_tag iterator_category
friend bool operator==(const EmptyRowGenerator &lhs, const EmptyRowGenerator &rhs) noexcept
friend bool operator!=(const EmptyRowGenerator &lhs, const EmptyRowGenerator &rhs) noexcept
EmptyRowGenerator & operator++()
bool operator()(const value_type &value) const
const QRangeModelImpl *const that
QModelRoleDataSpan roleDataSpan
const QModelIndex & index
MimeDataItemIterator operator++(int)
MimeDataItemIterator & operator++()
std::bidirectional_iterator_tag iterator_category
MimeDataItemIterator & operator--()
bool operator!=(const MimeDataItemIterator &other) const
const_reference operator*() const
MimeDataItemIterator operator-(difference_type n) const
MimeDataItemIterator operator--(int)
const QRangeModelImpl * m_model
bool operator==(const MimeDataItemIterator &other) const
MimeDataRowIterator operator--(int)
MimeDataRowIterator operator-(difference_type n) const
bool operator!=(const MimeDataRowIterator &other) const
MimeDataRowIterator & operator--()
MimeDataRowIterator & operator++()
MimeDataRowIterator()=default
MimeDataRowIterator operator++(int)
bool operator==(const MimeDataRowIterator &other) const
MimeDataRowIterator(base_iterator it, base_iterator begin, base_iterator end, const QRangeModelImpl *model)
std::bidirectional_iterator_tag iterator_category
const_reference operator*() const
friend constexpr bool operator<(unordered, QtPrivate::CompareAgainstLiteralZero) noexcept
friend constexpr bool operator>(unordered, QtPrivate::CompareAgainstLiteralZero) noexcept