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 inline 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 inline 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>
1029 return !(lhs
== rhs);
1033 template <
typename Entry>
1070 template <
bool cacheProperties,
bool itemsAreQObjects>
1102 return lhs.sender == rhs.sender && lhs
.role == rhs
.role;
1106 return qHashMulti(seed, c.sender, c
.role);
1130 template <
typename ModelStorage,
typename =
void>
1149 template <
typename ModelStorage,
typename PropertyStorage>
1160 template <
typename Model = ModelStorage>
1196 bool setHeaderData(
int section, Qt::Orientation orientation,
const QVariant &data,
int role);
1197 bool setData(
const QModelIndex &index,
const QVariant &data,
int role);
1198 bool setItemData(
const QModelIndex &index,
const QMap<
int, QVariant> &data);
1202 bool moveColumns(
const QModelIndex &sourceParent,
int sourceColumn,
int count,
const QModelIndex &destParent,
int destColumn);
1205 bool moveRows(
const QModelIndex &sourceParent,
int sourceRow,
int count,
const QModelIndex &destParent,
int destRow);
1218 void multiData(
const QModelIndex &index, QModelRoleDataSpan roleDataSpan)
const;
1222 void sort(
int column, Qt::SortOrder order);
1224 int hits, Qt::MatchFlags flags)
const;
1230 const QModelIndex &parent)
const;
1231 bool dropMimeData(
const QMimeData *data, Qt::DropAction action,
int row,
int column,
1232 const QModelIndex &parent);
1276 template <
typename C>
1317 friend class QRangeModelPrivate;
1320 QRangeModel *m_rangeModel;
1324 : m_rangeModel(itemModel)
1330 inline void dataChanged(
const QModelIndex &from,
const QModelIndex &to,
1331 const QList<
int> &roles);
1338 inline bool beginMoveColumns(
const QModelIndex &sourceParent,
int sourceFirst,
int sourceLast,
1339 const QModelIndex &destParent,
int destRow);
1341 inline void beginInsertRows(
const QModelIndex &parent,
int start,
int count);
1343 inline void beginRemoveRows(
const QModelIndex &parent,
int start,
int count);
1345 inline bool beginMoveRows(
const QModelIndex &sourceParent,
int sourceFirst,
int sourceLast,
1346 const QModelIndex &destParent,
int destRow);
1352 const QCollator *collator);
1370 QRangeModelDetails::AutoConnectContext *context,
1371 int role,
const QMetaProperty &property);
1373 QRangeModelDetails::AutoConnectContext *context,
1374 int role,
const QMetaProperty &property);
1376 QRangeModelDetails::AutoConnectContext *context,
1377 const QHash<
int, QMetaProperty> &properties);
1379 QRangeModelDetails::AutoConnectContext *context,
1380 const QHash<
int, QMetaProperty> &properties);
1387 Qt::MatchFlags flags);
1389 Qt::MatchFlags flags,
const QCollator &collator);
1390 static bool matchValue(
const QVariant &itemData,
const QVariant &value, Qt::MatchFlags flags,
1391 const QCollator &collator)
1393 if ((flags & Qt::MatchTypeMask) == Qt::MatchExactly)
1394 return itemData == value;
1395 return matchValue(itemData.toString(), value, flags, collator);
1401template <
typename Structure,
typename Range,
1402 typename Protocol = QRangeModelDetails::table_protocol_t<Range>>
1438 "Currently, std::optional is not supported for ranges and rows, as "
1439 "it has range semantics in c++26. Once the required behavior is clarified, "
1440 "std::optional for ranges and rows will be supported.");
1447 Structure&
that() {
return static_cast<Structure &>(*
this); }
1448 const Structure&
that()
const {
return static_cast<
const Structure &>(*
this); }
1450 template <
typename C>
1451 static constexpr int size(
const C &c)
1456 if constexpr (QRangeModelDetails::test_size<C>()) {
1458 return int(size(c));
1460#if defined(__cpp_lib_ranges)
1461 using std::ranges::distance;
1463 using std::distance;
1465 using container_type = std::conditional_t<QRangeModelDetails::range_traits<C>::has_cbegin,
1466 const QRangeModelDetails::wrapped_t<C>,
1467 QRangeModelDetails::wrapped_t<C>>;
1468 container_type& container =
const_cast<container_type &>(
QRangeModelDetails::refTo(c));
1484 return this->blockDataChangedDispatch();
1494 template <
typename T>
1514 {
return lhs.n == rhs.n; }
1516 {
return !(lhs == rhs); }
1527 "The range holding a move-only row-type must support insert(pos, start, end)");
1535 return range_features::is_mutable && row_features::is_mutable
1536 && std::is_reference_v<row_reference>
1537 && Structure::is_mutable_impl;
1554 versionNumber = QT_VERSION;
1565 if (row < 0 || column < 0 || column >= columnCount(parent)
1566 || row >= rowCount(parent)) {
1570 return that().indexImpl(row, column, parent);
1575 if (row == index.row() && column == index.column())
1579 if (column >=
this->columnCount({}))
1582 if (row == index.row())
1583 return this->createIndex(row, column, index.constInternalPointer());
1585 const_row_ptr parentRow =
static_cast<const_row_ptr>(index.constInternalPointer());
1586 const auto siblingCount = size(that().childrenOf(parentRow));
1587 if (row < 0 || row >=
int(siblingCount))
1589 return this->createIndex(row, column, parentRow);
1594 if (!index.isValid()) {
1595 if constexpr (isMutable())
1596 return Qt::ItemIsDropEnabled;
1598 return Qt::NoItemFlags;
1602 std::optional<Qt::ItemFlags> customFlags = std::nullopt;
1603 if constexpr (QRangeModelDetails::hasRowFlags<wrapped_row_type>) {
1604 const_row_reference row = rowData(index);
1606 customFlags = QRangeModelDetails::QRangeModelRowOptions<wrapped_row_type>::flags(
1607 QRangeModelDetails::refTo(row)
1612 readAt(index, [&customFlags](
auto &&ref){
1614 using wrapped_value_type = q20::remove_cvref_t<QRangeModelDetails::wrapped_t<
decltype(ref)>>;
1615 if constexpr (QRangeModelDetails::item_access<wrapped_value_type>::hasFlags) {
1616 using ItemAccess = QRangeModelDetails::QRangeModelItemAccess<wrapped_value_type>;
1618 customFlags = ItemAccess::flags(QRangeModelDetails::refTo(ref));
1625 Qt::ItemFlags f = customFlags ? *customFlags : Structure::defaultFlags();
1627 if constexpr (!isMutable())
1628 f &= ~(Qt::ItemIsEditable | Qt::ItemIsDropEnabled);
1630 f |= Qt::ItemNeverHasChildren;
1635 if (!
this->itemModel().mimeTypes().isEmpty()) {
1636 f |= Qt::ItemIsDragEnabled;
1637 if constexpr (isMutable())
1638 f |= Qt::ItemIsDropEnabled;
1641 if constexpr (QRangeModelDetails::is_owning_or_raw_pointer<row_type>()) {
1643 const_row_reference row = rowData(index);
1644 if (!QRangeModelDetails::isValid(row))
1645 f &= ~Qt::ItemIsDragEnabled;
1648 if constexpr (isMutable()) {
1653 if constexpr (row_traits::hasMetaObject) {
1654 if (index.column() < row_traits::fixed_size()) {
1655 const QMetaObject mo = wrapped_row_type::staticMetaObject;
1656 const QMetaProperty prop = mo.property(index.column() + mo.propertyOffset());
1657 if (prop.isWritable())
1658 f |= Qt::ItemIsEditable;
1661 using item_type =
typename row_traits::item_type;
1662 if constexpr (QRangeModelDetails::is_owning_or_raw_pointer<item_type>()) {
1664 if (!readAt(index, [](
auto &&i){
return QRangeModelDetails::isValid(i); }))
1665 f &= ~Qt::ItemIsDragEnabled;
1667 f |= Qt::ItemIsEditable;
1668 }
else if constexpr (std::is_reference_v<row_reference> && !std::is_const_v<row_reference>) {
1671 const_row_reference row = rowData(index);
1672 row_reference mutableRow =
const_cast<row_reference>(row);
1674 row_traits::for_element_at(mutableRow, index.column(), [&f](
auto &&ref){
1675 using target_type =
decltype(ref);
1676 if constexpr (QRangeModelDetails::is_owning_or_raw_pointer<target_type>()) {
1678 if (!QRangeModelDetails::isValid(ref))
1679 f &= ~Qt::ItemIsDragEnabled;
1681 if constexpr (std::is_const_v<std::remove_reference_t<target_type>>)
1682 f &= ~Qt::ItemIsEditable;
1683 else if constexpr (std::is_lvalue_reference_v<target_type>)
1684 f |= Qt::ItemIsEditable;
1689 f &= ~Qt::ItemIsEditable;
1699 if constexpr (QRangeModelDetails::hasHeaderData<wrapped_row_type>) {
1700 if (orientation == Qt::Horizontal) {
1701 result = QRangeModelDetails::QRangeModelRowOptions<wrapped_row_type>::headerData(
1704 if (result.isValid())
1709 if (role != Qt::DisplayRole || orientation != Qt::Horizontal
1710 || section < 0 || section >= columnCount({})) {
1711 return this->itemModel().QAbstractItemModel::headerData(section, orientation, role);
1714 result = row_traits::column_name(section);
1715 if (!result.isValid())
1716 result =
this->itemModel().QAbstractItemModel::headerData(section, orientation, role);
1722 if (!index.isValid())
1725 QModelRoleData result(role);
1726 multiData(index, result);
1727 return std::move(result.data());
1732 return role == Qt::RangeModelDataRole
1733 || role == Qt::RangeModelAdapterRole;
1738 return role == Qt::DisplayRole || role == Qt::EditRole;
1743 QMap<
int, QVariant> result;
1745 if (index.isValid()) {
1747 if (!readAt(index, [&result](
const auto &value) {
1748 if constexpr (std::is_convertible_v<
decltype(value),
decltype(result)>) {
1754 const auto roles =
this->itemModel().roleNames().keys();
1755 QVarLengthArray<QModelRoleData, 16> roleDataArray;
1756 roleDataArray.reserve(roles.size());
1757 for (
auto role : roles) {
1758 if (isRangeModelRole(role))
1760 roleDataArray.emplace_back(role);
1762 QModelRoleDataSpan roleDataSpan(roleDataArray);
1763 multiData(index, roleDataSpan);
1765 for (QModelRoleData &roleData : roleDataSpan) {
1766 if (roleData.data().isValid())
1767 result[roleData.role()] = std::move(roleData.data());
1776 template <
typename value_type>
1779 using multi_role = QRangeModelDetails::is_multi_role<value_type>;
1780 using wrapped_value_type = QRangeModelDetails::wrapped_t<value_type>;
1782 const auto readModelData = [&value](QModelRoleData &roleData){
1784 roleData.clearData();
1788 const int role = roleData.role();
1789 if (role == Qt::RangeModelDataRole) {
1793 if constexpr (std::is_copy_assignable_v<wrapped_value_type>)
1794 roleData.setData(QVariant::fromValue(QRangeModelDetails::refTo(value)));
1796 roleData.setData(QVariant::fromValue(QRangeModelDetails::pointerTo(value)));
1797 }
else if (role == Qt::RangeModelAdapterRole) {
1799 if constexpr (
std::is_copy_assignable_v<value_type>)
1800 roleData.setData(QVariant::fromValue(value));
1802 roleData.setData(QVariant::fromValue(QRangeModelDetails::pointerTo(value)));
1809 if constexpr (QRangeModelDetails::item_access<wrapped_value_type>::hasReadRole) {
1810 using ItemAccess = QRangeModelDetails::QRangeModelItemAccess<wrapped_value_type>;
1811 for (
auto &roleData : roleDataSpan) {
1812 if (!readModelData(roleData)) {
1813 roleData.setData(ItemAccess::readRole(QRangeModelDetails::refTo(value),
1817 }
else if constexpr (multi_role()) {
1818 const auto roleNames = [
this]() -> QHash<
int, QByteArray> {
1820 if constexpr (!multi_role::int_key)
1821 return that->itemModel().roleNames();
1825 using key_type =
typename value_type::key_type;
1826 for (
auto &roleData : roleDataSpan) {
1827 const auto &it = [&roleNames, &value, role = roleData.role()]{
1828 Q_UNUSED(roleNames);
1829 if constexpr (multi_role::int_key)
1830 return value.find(key_type(role));
1832 return value.find(roleNames.value(role));
1834 if (it != QRangeModelDetails::adl_end(value))
1835 roleData.setData(QRangeModelDetails::value(it));
1837 roleData.clearData();
1839 }
else if constexpr (has_metaobject<value_type>) {
1840 if (row_traits::fixed_size() <= 1) {
1841 for (
auto &roleData : roleDataSpan) {
1842 if (!readModelData(roleData)) {
1843 roleData.setData(that->readRole(index, roleData.role(),
1844 QRangeModelDetails::pointerTo(value)));
1847 }
else if (index.column() <= row_traits::fixed_size()) {
1848 for (
auto &roleData : roleDataSpan) {
1849 const int role = roleData.role();
1850 if (isPrimaryRole(role)) {
1851 roleData.setData(that->readProperty(index,
1852 QRangeModelDetails::pointerTo(value)));
1854 roleData.clearData();
1859 for (
auto &roleData : roleDataSpan) {
1860 const int role = roleData.role();
1861 if (isPrimaryRole(role) || isRangeModelRole(role))
1862 roleData.setData(read(value));
1864 roleData.clearData();
1875 void multiData(
const QModelIndex &index, QModelRoleDataSpan roleDataSpan)
const
1877 if (!readAt(index,
ItemReader{index, roleDataSpan,
this})) {
1878 for (
auto &roleData : roleDataSpan)
1879 roleData.clearData();
1883 bool setData(
const QModelIndex &index,
const QVariant &data,
int role)
1885 if (!index.isValid())
1888 if constexpr (isMutable()) {
1889 auto emitDataChanged = qScopeGuard([
this, &index, role]{
1890 Q_EMIT
this->dataChanged(index, index,
1891 role == Qt::EditRole || role == Qt::RangeModelDataRole
1892 || role == Qt::RangeModelAdapterRole
1893 ? QList<
int>{} : QList<
int>{role});
1898 const auto writeData = [
this, column = index.column(), &data, role](
auto &&target) ->
bool {
1899 using value_type = q20::remove_cvref_t<
decltype(target)>;
1900 using wrapped_value_type = QRangeModelDetails::wrapped_t<value_type>;
1901 using multi_role = QRangeModelDetails::is_multi_role<value_type>;
1903 if constexpr (std::conjunction_v<QRangeModelDetails::is_any_owning_ptr<value_type>,
1904 std::is_default_constructible<wrapped_value_type>>) {
1906 target.reset(
new wrapped_value_type);
1909 auto setRangeModelDataRole = [&target, &data]{
1910 constexpr auto targetMetaType = QMetaType::fromType<value_type>();
1911 const auto dataMetaType = data.metaType();
1912 constexpr bool isWrapped = QRangeModelDetails::is_wrapped<value_type>();
1913 if constexpr (!std::is_copy_assignable_v<wrapped_value_type>) {
1917 if constexpr (isWrapped) {
1918 constexpr bool is_raw_pointer = std::is_pointer_v<value_type>;
1919 if constexpr (!is_raw_pointer && std::is_copy_assignable_v<value_type>) {
1920 if (data.canConvert(targetMetaType)) {
1921 target = data.value<value_type>();
1924 }
else if constexpr (is_raw_pointer) {
1926 target = data.value<value_type>();
1935 }
else if constexpr (isWrapped) {
1940 if (
const auto mt = QMetaType::fromType<wrapped_value_type>();
1941 data.canConvert(mt)) {
1942 targetRef = data.value<wrapped_value_type>();
1944 }
else if (
const auto mtp = QMetaType::fromType<wrapped_value_type *>();
1945 data.canConvert(mtp)) {
1946 targetRef = *data.value<wrapped_value_type *>();
1950 }
else if (targetMetaType == dataMetaType) {
1951 QRangeModelDetails::refTo(target) = data.value<value_type>();
1953 }
else if (dataMetaType.flags() & QMetaType::PointerToGadget) {
1954 QRangeModelDetails::refTo(target) = *data.value<value_type *>();
1958 qCritical(
"Not able to assign %s to %s",
1959 qPrintable(QDebug::toString(data)), targetMetaType.name());
1964 if constexpr (QRangeModelDetails::item_access<wrapped_value_type>::hasWriteRole) {
1965 using ItemAccess = QRangeModelDetails::QRangeModelItemAccess<wrapped_value_type>;
1966 if (isRangeModelRole(role))
1967 return setRangeModelDataRole();
1968 return ItemAccess::writeRole(QRangeModelDetails::refTo(target), data, role);
1969 }
else if constexpr (has_metaobject<value_type>) {
1970 if (row_traits::fixed_size() <= 1) {
1971 if (isRangeModelRole(role))
1972 return setRangeModelDataRole();
1974 }
else if (column <= row_traits::fixed_size()
1975 && (isPrimaryRole(role) || isRangeModelRole(role))) {
1978 }
else if constexpr (multi_role::value) {
1979 Qt::ItemDataRole roleToSet = Qt::ItemDataRole(role);
1982 const auto roleNames = [
this]() -> QHash<
int, QByteArray> {
1984 if constexpr (!multi_role::int_key)
1985 return this->itemModel().roleNames();
1989 if (role == Qt::EditRole) {
1990 if constexpr (multi_role::int_key) {
1991 if (target.find(roleToSet) == target.end())
1992 roleToSet = Qt::DisplayRole;
1994 if (target.find(roleNames.value(roleToSet)) == target.end())
1995 roleToSet = Qt::DisplayRole;
1998 if constexpr (multi_role::int_key)
1999 return write(target[roleToSet], data);
2001 return write(target[roleNames.value(roleToSet)], data);
2002 }
else if (isPrimaryRole(role) || isRangeModelRole(role)) {
2003 return write(target, data);
2008 if (!writeAt(index, writeData)) {
2009 emitDataChanged.dismiss();
2012 if (isRangeModelRole(role) &&
this->autoConnectPolicy() == AutoConnectPolicy::Full) {
2013 if (QObject *item = data.value<QObject *>())
2014 Self::connectProperties(index, item, m_data.context, m_data.properties);
2022 template <
typename LHS,
typename RHS>
2025 if constexpr (
std::is_pointer_v<RHS>)
2027 else if constexpr (
std::is_assignable_v<LHS, RHS>)
2028 org =
std::forward<RHS>(copy);
2032 template <
typename LHS,
typename RHS>
2035 updateTarget(*org,
std::forward<RHS>(copy));
2038 bool setItemData(
const QModelIndex &index,
const QMap<
int, QVariant> &data)
2040 if (!index.isValid() || data.isEmpty())
2043 if constexpr (isMutable()) {
2044 auto emitDataChanged = qScopeGuard([
this, &index, &data]{
2045 Q_EMIT
this->dataChanged(index, index, data.keys());
2051 auto writeItemData = [
this, &tried, &data](
auto &target) ->
bool {
2053 using value_type = q20::remove_cvref_t<
decltype(target)>;
2054 using multi_role = QRangeModelDetails::is_multi_role<value_type>;
2055 using wrapped_value_type = QRangeModelDetails::wrapped_t<value_type>;
2059 auto makeCopy = [](
const value_type &original){
2060 if constexpr (!std::is_copy_assignable_v<wrapped_value_type>)
2062 else if constexpr (std::is_pointer_v<
decltype(original)>)
2064 else if constexpr (std::is_copy_assignable_v<value_type>)
2070 const auto roleNames =
this->itemModel().roleNames();
2072 if constexpr (QRangeModelDetails::item_access<wrapped_value_type>::hasWriteRole) {
2074 using ItemAccess = QRangeModelDetails::QRangeModelItemAccess<wrapped_value_type>;
2075 const auto roles = roleNames.keys();
2076 auto targetCopy = makeCopy(target);
2077 for (
int role : roles) {
2078 if (!ItemAccess::writeRole(QRangeModelDetails::refTo(targetCopy),
2079 data.value(role), role)) {
2083 updateTarget(target,
std::move(targetCopy));
2085 }
else if constexpr (multi_role()) {
2086 using key_type =
typename value_type::key_type;
2088 const auto roleName = [&roleNames](
int role) {
2089 return roleNames.value(role);
2094 if constexpr (!multi_role::int_key)
2096 auto invalid =
std::find_if(data.keyBegin(), data.keyEnd(),
2097 [&roleName](
int role) {
return roleName(role).isEmpty(); }
2100 if (invalid != data.keyEnd()) {
2102 qWarning(
"No role name set for %d", *invalid);
2108 for (
auto &&[role, value] : data.asKeyValueRange()) {
2109 if constexpr (multi_role::int_key)
2110 target[
static_cast<key_type>(role)] = value;
2112 target[QString::fromUtf8(roleName(role))] = value;
2115 }
else if constexpr (has_metaobject<value_type>) {
2116 if (row_traits::fixed_size() <= 1) {
2118 auto targetCopy = makeCopy(target);
2119 for (
auto &&[role, value] : data.asKeyValueRange()) {
2120 if (isRangeModelRole(role))
2122 if (!writeRole(role, QRangeModelDetails::pointerTo(targetCopy), value)) {
2123 const QByteArray roleName = roleNames.value(role);
2125 qWarning(
"Failed to write value '%s' to role '%s'",
2126 qPrintable(QDebug::toString(value)), roleName.data());
2131 updateTarget(target,
std::move(targetCopy));
2138 if (!writeAt(index, writeItemData)) {
2139 emitDataChanged.dismiss();
2141 return this->itemModel().QAbstractItemModel::setItemData(index, data);
2150 if (!index.isValid())
2153 if constexpr (isMutable()) {
2154 auto emitDataChanged = qScopeGuard([
this, &index]{
2155 Q_EMIT
this->dataChanged(index, index, {});
2158 auto clearData = [column = index.column()](
auto &&target) {
2159 if constexpr (row_traits::hasMetaObject) {
2160 if (row_traits::fixed_size() <= 1) {
2163 }
else if (column <= row_traits::fixed_size()) {
2173 if (!writeAt(index, clearData)) {
2174 emitDataChanged.dismiss();
2185 using item_type = QRangeModelDetails::wrapped_t<
typename row_traits::item_type>;
2186 using item_traits =
typename QRangeModelDetails::item_traits<item_type>;
2187 return item_traits::roleNames(
this);
2194 return row_traits::for_each_element(QRangeModelDetails::refTo(row),
2195 this->itemModel().index(rowIndex, 0, parent),
2196 [
this](
const QModelIndex &index,
const QObject *item) {
2197 if constexpr (isMutable())
2198 return Self::connectProperties(index, item, m_data.context, m_data.properties);
2200 return Self::connectPropertiesConst(index, item, m_data.context, m_data.properties);
2208 row_traits::for_each_element(QRangeModelDetails::refTo(row),
2209 this->itemModel().index(rowIndex, 0, parent),
2210 [
this](
const QModelIndex &,
const QObject *item) {
2211 m_data.connections.removeIf([item](
const auto &connection) {
2212 return connection.sender == item;
2221 using item_type = std::remove_pointer_t<
typename row_traits::item_type>;
2222 using Mapping = QRangeModelDetails::AutoConnectContext::AutoConnectMapping;
2224 delete m_data.context;
2225 m_data.connections = {};
2226 switch (
this->autoConnectPolicy()) {
2227 case AutoConnectPolicy::None:
2228 m_data.context =
nullptr;
2230 case AutoConnectPolicy::Full:
2231 m_data.context =
new QRangeModelDetails::AutoConnectContext(&
this->itemModel());
2233 m_data.properties = QRangeModelImplBase::roleProperties(
this->itemModel(),
2234 item_type::staticMetaObject);
2235 m_data.context->mapping = Mapping::Roles;
2237 m_data.properties = QRangeModelImplBase::columnProperties(wrapped_row_type::staticMetaObject);
2238 m_data.context->mapping = Mapping::Columns;
2240 if (!m_data.properties.isEmpty())
2241 that().autoConnectPropertiesImpl();
2243 case AutoConnectPolicy::OnRead:
2244 m_data.context =
new QRangeModelDetails::AutoConnectContext(&
this->itemModel());
2246 m_data.context->mapping = Mapping::Roles;
2248 m_data.properties = QRangeModelImplBase::columnProperties(wrapped_row_type::staticMetaObject);
2249 m_data.context->mapping = Mapping::Columns;
2255 qWarning(
"All items in the range must be QObject subclasses");
2269 template <
typename C,
typename LessThan>
2271 static constexpr bool hasSortMember = qxp::is_detected_v<sortMember_test, range_type, Compare>;
2289 template <
typename Item>
2290 auto operator()(
const Item &lhs,
const Item &rhs)
const
2292 auto ordering = compare(lhs, rhs);
2293 return m_order == Qt::AscendingOrder ? ordering < 0 : ordering > 0;
2296 template <
typename Item>
2297 auto compare(
const Item &lhs,
const Item &rhs)
const
2299 using value_type = QRangeModelDetails::wrapped_t<Item>;
2300 using multi_role = QRangeModelDetails::is_multi_role<value_type>;
2302 if constexpr (QRangeModelDetails::item_access<value_type>::hasReadRole
2303 || multi_role() || has_metaobject<value_type>) {
2311 Q_ASSERT(!reader.index.isValid());
2313 const QVariant lhsVariant =
std::move(result.data());
2315 const QVariant rhsVariant =
std::move(result.data());
2316 return QRangeModelImplBase::compareData(lhsVariant, rhsVariant, collator);
2317 }
else if constexpr (std::is_same_v<QVariant, value_type>) {
2318 return QRangeModelImplBase::compareData(lhs, rhs, collator);
2319 }
else if constexpr (QtOrderingPrivate::CompareThreeWayTester::hasCompareThreeWay_v
2320 <value_type, value_type>) {
2322 if constexpr (hasCollatedCompare<value_type>) {
2324 using ordering =
decltype(qCompareThreeWay(lhs, rhs));
2325 int res = collator->compare(lhs, rhs);
2327 return ordering::less;
2329 return ordering::greater;
2330 return ordering::equal;
2333 return qCompareThreeWay(lhs, rhs);
2341 return that->readAt(
that->index(0, 0, {}), [
this](
const auto &item){
2346 using ordering =
decltype(compare(item, item));
2349 const QMetaType itemtype = QMetaType::fromType<QRangeModelDetails::wrapped_t<
2350 q20::remove_cvref_t<
decltype(item)>>
2352 qCritical(
"QRangeModel: Cannot compare items of type %s in column %d!",
2353 itemtype.name(), m_index.column());
2364 template <
typename Item>
2372 return std::nullopt;
2382 void sort(
int column, Qt::SortOrder order)
2384 if constexpr (isMutable() && std::is_swappable_v<row_type>) {
2385 if (rowCount({}) < 2 || column >= columnCount({}))
2387 Compare compare(
this, column, order);
2388 if (!compare.checkComparable())
2391 this->beginLayoutChange();
2392 QScopeGuard endLayoutChange([
this]{
this->endLayoutChange(); });
2393 that().sortImpl([&compare](
const auto &leftRow,
const auto &rightRow) {
2394 if (
auto anyInvalid =
Compare::compareInvalid(leftRow, rightRow))
2396 return row_traits::for_element_at(leftRow, compare.m_index.column(),
2397 [&rightRow, &compare](
const auto &leftItem){
2398 return row_traits::for_element_at(rightRow, compare.m_index.column(),
2399 [&leftItem, &compare](
const auto &rightItem){
2402 if constexpr (std::is_same_v<
decltype(leftItem),
decltype(rightItem)>) {
2403 if (
auto anyInvalid = Compare::compareInvalid(leftItem, rightItem))
2405 return compare(QRangeModelDetails::refTo(leftItem),
2406 QRangeModelDetails::refTo(rightItem));
2417 template <
typename LessThan>
2418 void sortSubRange(range_type &range, row_ptr expectedParent,
const LessThan &lessThan)
2425 QModelIndexList persistentIndexes =
this->persistentIndexList();
2426 that().prunePersistentIndexList(persistentIndexes, expectedParent);
2428 if (persistentIndexes.isEmpty()) {
2429 using It =
typename range_features::iterator;
2430 constexpr bool is_random_access = std::is_base_of_v<std::random_access_iterator_tag,
2431 typename std::iterator_traits<It>::iterator_category>;
2433 if constexpr (
Compare::hasSortMember) {
2434 range.sort(lessThan);
2436 }
else if constexpr (is_random_access) {
2437 std::stable_sort(begin, end, lessThan);
2450 const int rangeSize = size(range);
2453 std::vector<SortTracker> tracked;
2454 tracked.reserve(rangeSize);
2455 std::vector<
int> newRows;
2456 newRows.resize(rangeSize);
2460 for (
auto &&it =
std::move_iterator(begin); it !=
std::move_iterator(end); ++it)
2461 tracked.emplace_back(SortTracker{*it, ++row});
2464 std::stable_sort(tracked.begin(), tracked.end(),
2465 [&lessThan](
const SortTracker &lhs,
const SortTracker &rhs){
2466 return lessThan(lhs.row, rhs.row);
2471 auto sorted =
std::move_iterator(tracked.begin());
2473 qsizetype changedIndexCount = 0;
2474 for (
int newIndex = 0; newIndex < rangeSize; ++write, ++sorted, ++newIndex) {
2475 auto &&tracker = *sorted;
2476 changedIndexCount += (tracker.index != newIndex);
2477 *write =
std::move(tracker.row);
2478 newRows[tracker.index] = newIndex;
2483 tracked.shrink_to_fit();
2486 for (
const auto &fromIndex : std::as_const(persistentIndexes)) {
2487 const int newRow = newRows.at(fromIndex.row());
2488 if (fromIndex.row() == newRow)
2490 const QModelIndex toIndex = that().indexImpl(newRow,
2492 fromIndex.parent());
2493 this->changePersistentIndex(fromIndex, toIndex);
2498 Qt::MatchFlags flags)
const
2500 QCollator collator =
this->matchCollator();
2501 collator.setCaseSensitivity(flags.testFlag(Qt::MatchCaseSensitive) ? Qt::CaseSensitive
2502 : Qt::CaseInsensitive);
2503 return that().matchImpl(start, role,
2504 QRangeModelImplBase::convertMatchValue(value, flags), hits,
2508 bool matchRow(const_row_reference row,
const QModelIndex &index,
int role,
const QVariant &value,
2509 Qt::MatchFlags flags,
const QCollator &collator)
const
2511 const uint matchType = (flags & Qt::MatchTypeMask).toInt();
2513 return row_traits::for_element_at(row, index.column(), [&](
const auto &element) {
2514 using value_type = q20::remove_cvref_t<
decltype(element)>;
2515 using wrapped_value_type = QRangeModelDetails::wrapped_t<value_type>;
2516 using multi_role = QRangeModelDetails::is_multi_role<value_type>;
2518 if constexpr (QRangeModelDetails::item_access<wrapped_value_type>::hasReadRole
2519 || multi_role() || has_metaobject<value_type>) {
2520 QModelRoleData roleData(role);
2521 ItemReader reader{index, roleData,
this};
2523 return QRangeModelImplBase::matchValue(roleData.data(), value, flags, collator);
2524 }
else if constexpr (std::is_same_v<wrapped_value_type, QVariant>) {
2525 return QRangeModelImplBase::matchValue(element, value, flags, collator);
2527 constexpr QMetaType mt = QMetaType::fromType<wrapped_value_type>();
2528 if (mt == value.metaType()) {
2529 if (matchType == Qt::MatchExactly)
2530 return mt.equals(QRangeModelDetails::pointerTo(element), value.constData());
2531 else if constexpr (std::is_same_v<wrapped_value_type, QString>)
2532 return QRangeModelImplBase::matchValue(element, value, flags, collator);
2534 return QRangeModelImplBase::matchValue(QVariant::fromValue(QRangeModelDetails::refTo(element)),
2535 value, flags, collator);
2542 template <
typename InsertFn>
2547 range_type *
const children = childRange(parent);
2551 this->beginInsertColumns(parent, column, column + count - 1);
2553 for (
auto &child : *children) {
2554 auto it = QRangeModelDetails::pos(child, column);
2555 (
void)insertFn(QRangeModelDetails::refTo(child), it, count);
2558 this->endInsertColumns();
2564 if (m_data.context &&
this->autoConnectPolicy() == AutoConnectPolicy::Full) {
2565 for (
int r = 0; r < that().rowCount(parent); ++r) {
2566 for (
int c = column; c < column + count; ++c) {
2567 const QModelIndex index = that().index(r, c, parent);
2568 writeAt(index, [
this, &index](QObject *item){
2569 return Self::connectProperties(index, item,
2570 m_data.context, m_data.properties);
2582 if constexpr (dynamicColumns() && isMutable() && row_features::has_insert) {
2583 return doInsertColumns(column, count, parent, [](
auto &row,
auto it,
int n){
2584 row.insert(it, n, {});
2594 if constexpr (dynamicColumns() && isMutable() && row_features::has_erase) {
2595 if (column < 0 || column + count > columnCount(parent))
2598 range_type *
const children = childRange(parent);
2603 if (m_data.context &&
this->autoConnectPolicy() == AutoConnectPolicy::OnRead) {
2604 for (
int r = 0; r < that().rowCount(parent); ++r) {
2605 for (
int c = column; c < column + count; ++c) {
2606 const QModelIndex index = that().index(r, c, parent);
2607 writeAt(index, [
this](QObject *item){
2608 m_data.connections.removeIf([item](
const auto &connection) {
2609 return connection.sender == item;
2618 this->beginRemoveColumns(parent, column, column + count - 1);
2619 for (
auto &child : *children) {
2620 const auto start = QRangeModelDetails::pos(child, column);
2621 QRangeModelDetails::refTo(child).erase(start, std::next(start, count));
2623 this->endRemoveColumns();
2629 bool moveColumns(
const QModelIndex &sourceParent,
int sourceColumn,
int count,
2630 const QModelIndex &destParent,
int destColumn)
2633 if (sourceParent != destParent)
2635 if constexpr (isMutable() && (row_features::has_rotate || row_features::has_splice)) {
2636 if (!Structure::canMoveColumns(sourceParent, destParent))
2642 range_type *
const children = childRange(sourceParent);
2646 if (!
this->beginMoveColumns(sourceParent, sourceColumn, sourceColumn + count - 1,
2647 destParent, destColumn)) {
2651 for (
auto &child : *children)
2652 QRangeModelDetails::rotate(child, sourceColumn, count, destColumn);
2654 this->endMoveColumns();
2661 template <
typename InsertFn>
2662 bool doInsertRows(
int row,
int count,
const QModelIndex &parent, InsertFn &&insertFn)
2664 range_type *children = childRange(parent);
2668 this->beginInsertRows(parent, row, row + count - 1);
2670 row_ptr parentRow = parent.isValid()
2673 (
void)
std::forward<InsertFn>(insertFn)(*children, parentRow, row, count);
2677 that().resetParentInChildren(children);
2679 this->endInsertRows();
2685 if (m_data.context &&
this->autoConnectPolicy() == AutoConnectPolicy::Full) {
2687 const auto end =
std::next(begin, count);
2689 for (
auto it = begin; it != end; ++it, ++rowIndex)
2690 autoConnectPropertiesInRow(*it, rowIndex, parent);
2700 return doInsertRows(row, count, parent,
2701 [
this](range_type &children, row_ptr parentRow,
int r,
int n){
2705 if constexpr (range_features::has_insert_range) {
2708 auto start = children.insert(pos, n,
nullptr);
2711 children.insert(pos, n,
std::move(*generator));
2720 bool removeRows(
int row,
int count,
const QModelIndex &parent = {})
2723 const int prevRowCount = rowCount(parent);
2724 if (row < 0 || row + count > prevRowCount)
2727 range_type *children = childRange(parent);
2732 if (m_data.context &&
this->autoConnectPolicy() == AutoConnectPolicy::OnRead) {
2734 const auto end =
std::next(begin, count);
2736 for (
auto it = begin; it != end; ++it, ++rowIndex)
2737 clearConnectionInRow(*it, rowIndex, parent);
2741 this->beginRemoveRows(parent, row, row + count - 1);
2742 [[maybe_unused]]
bool callEndRemoveColumns =
false;
2746 if (prevRowCount == count) {
2747 if (
const int columns = columnCount(parent)) {
2748 callEndRemoveColumns =
true;
2749 this->beginRemoveColumns(parent, 0, columns - 1);
2755 const auto end =
std::next(begin, count);
2756 that().deleteRemovedRows(begin, end);
2757 children->erase(begin, end);
2761 that().resetParentInChildren(children);
2764 if (callEndRemoveColumns) {
2765 Q_ASSERT(columnCount(parent) == 0);
2766 this->endRemoveColumns();
2769 this->endRemoveRows();
2776 bool moveRows(
const QModelIndex &sourceParent,
int sourceRow,
int count,
2777 const QModelIndex &destParent,
int destRow)
2779 if constexpr (isMutable() && (range_features::has_rotate || range_features::has_splice)) {
2780 if (!Structure::canMoveRows(sourceParent, destParent))
2783 if (sourceParent != destParent) {
2784 return that().moveRowsAcross(sourceParent, sourceRow, count,
2785 destParent, destRow);
2788 if (sourceRow == destRow || sourceRow == destRow - 1 || count <= 0
2789 || sourceRow < 0 || sourceRow + count - 1 >=
this->rowCount(sourceParent)
2790 || destRow < 0 || destRow >
this->rowCount(destParent)) {
2794 range_type *source = childRange(sourceParent);
2796 if (!
this->beginMoveRows(sourceParent, sourceRow, sourceRow + count - 1, destParent, destRow))
2801 that().resetParentInChildren(source);
2803 this->endMoveRows();
2815 int rowCount(
const QModelIndex &parent)
const {
return that().rowCountImpl(parent); }
2820 return row_traits::fixed_size();
2824 int columnCount(
const QModelIndex &parent)
const {
return that().columnCountImpl(parent); }
2829 if constexpr (!isMutable())
2830 dragActions &= ~Qt::MoveAction;
2835 if constexpr (!isMutable())
2836 dropActions = Qt::IgnoreAction;
2843 using ItemType = QRangeModelDetails::wrapped_t<
typename row_traits::item_type>;
2844 if constexpr (QRangeModelDetails::item_access<ItemType>::hasMimeTypes)
2845 return QRangeModelDetails::QRangeModelItemAccess<ItemType>::mimeTypes();
2846 else if constexpr (QRangeModelDetails::hasMimeTypes<wrapped_row_type>)
2847 return QRangeModelDetails::QRangeModelRowOptions<wrapped_row_type>::mimeTypes();
2849 return this->itemModel().QAbstractItemModel::mimeTypes();
2853 const QModelIndex &target)
const
2855 if constexpr (isMutable()) {
2857 using RowOptions = QRangeModelDetails::QRangeModelRowOptions<wrapped_row_type>;
2858 using ItemType = QRangeModelDetails::wrapped_t<
typename row_traits::item_type>;
2859 using ItemAccess = QRangeModelDetails::QRangeModelItemAccess<ItemType>;
2860 if constexpr (QRangeModelDetails::item_access<ItemType>::hasCanDropMimeDataFull) {
2861 canDrop = ItemAccess::canDropMimeData(data, action, row, column, target);
2862 }
else if constexpr (QRangeModelDetails::hasCanDropMimeDataFull<wrapped_row_type>) {
2863 canDrop = RowOptions::canDropMimeData(data, action, row, column, target);
2865 canDrop =
this->itemModel().QAbstractItemModel::canDropMimeData(data, action, row,
2867 if constexpr (QRangeModelDetails::item_access<ItemType>::hasCanDropMimeData)
2868 canDrop &= ItemAccess::canDropMimeData(data);
2869 else if constexpr (QRangeModelDetails::hasCanDropMimeData<wrapped_row_type>)
2870 canDrop &= RowOptions::canDropMimeData(data);
2879 template <Qt::Orientation orient,
typename Entry>
2880 bool doDropMimeData(std::vector<QRangeModelDetails::DroppedEntry<Entry>> &droppedEntries,
2881 DropOperation dropOperation,
int row,
int column,
const QModelIndex &target)
2884 using Cell =
typename DroppedEntry::Cell;
2885 if (dropOperation == DropOperation::DontDrop)
2888 const bool dropOnTarget = row == -1 && column == -1 && target.isValid();
2889 const QModelIndex parent = dropOperation == DropOperation::InsertAsChildren
2890 ? target.siblingAtColumn(0) : target.parent();
2893 if constexpr (orient == Qt::Horizontal)
2898 int rightColumn = -1;
2901 int maxColumn = that().columnCount(parent) - 1;
2902 for (
auto &droppedEntry : droppedEntries) {
2903 if (droppedEntry.m_cell == Cell{-1, -1}) {
2904 if constexpr (orient == Qt::Horizontal) {
2907 droppedEntry.m_cell = {lastCell.m_row, lastCell.m_column + 1};
2908 if (droppedEntry.m_cell.m_column > maxColumn) {
2909 droppedEntry.m_cell.m_column = 0;
2910 ++droppedEntry.m_cell.m_row;
2913 droppedEntry.m_cell = {lastCell.m_row + 1, lastCell.m_column};
2916 lastCell = droppedEntry.m_cell;
2917 bottomRow = std::max(lastCell.m_row, bottomRow);
2918 rightColumn = std::max(lastCell.m_column, rightColumn);
2921 if (dropOperation == DropOperation::InsertAsChildren) {
2922 row = rowCount(parent);
2924 }
else if (dropOnTarget) {
2926 column = target.column();
2929 row = rowCount(parent);
2934 const bool overwrite = dropOperation == DropOperation::OverwriteAndIgnore
2935 || dropOperation == DropOperation::OverwriteAndExtend;
2938 const int overwriteRows = overwrite
2939 ?
std::min(bottomRow + 1, rowCount(parent) - row)
2941 const int newRows = dropOperation == DropOperation::OverwriteAndExtend
2942 ? bottomRow - overwriteRows + 1
2943 : (dropOperation == DropOperation::InsertAsChildren
2944 || dropOperation == DropOperation::InsertAsSiblings)
2947 if (newRows > 0 && !insertRows(row, newRows, parent))
2951 const int overwriteColumns = overwrite
2952 ?
std::min(rightColumn + 1, columnCount(parent) - column)
2954 const int newColumns = dropOperation == DropOperation::OverwriteAndExtend
2955 ? rightColumn - overwriteColumns + 1 : 0;
2956 if (newColumns > 0 && !insertColumns(column, newColumns, parent))
2960 range_type *parentRange = that().childRange(parent);
2963 range_type &targetRange = *parentRange;
2965 int maxRow = that().rowCount(parent) - 1;
2966 maxColumn = that().columnCount(parent) - 1;
2967 auto begin =
std::move_iterator(droppedEntries.begin());
2968 auto end =
std::move_iterator(droppedEntries.end());
2969 for (; begin != end; ++begin) {
2970 DroppedEntry droppedEntry = *begin;
2971 const Cell cell = {droppedEntry.m_cell.m_row + row, droppedEntry.m_cell.m_column + column};
2972 if (cell.m_row > maxRow || cell.m_column > maxColumn)
2975 if constexpr (orient == Qt::Vertical) {
2976 if constexpr (QRangeModelDetails::is_owning_or_raw_pointer<row_type>()) {
2978 *writeRow =
this->protocol().newRow();
2979 **writeRow =
std::move(droppedEntry);
2981 *writeRow =
std::move(droppedEntry);
2984 row_traits::for_element_at(*writeRow, cell.m_column, [&](
auto &item){
2985 using item_type = q20::remove_cvref_t<
decltype(item)>;
2986 using wrapped_item_type = QRangeModelDetails::wrapped_t<item_type>;
2987 if constexpr (QRangeModelDetails::is_any_owning_ptr<item_type>()) {
2988 if (!QRangeModelDetails::isValid(item))
2989 item.reset(
new wrapped_item_type{std::move(droppedEntry)});
2991 *item = std::move(droppedEntry);
2992 }
else if (!QRangeModelDetails::isValid(item)) {
2995 item = std::move(droppedEntry);
3002 that().resetParentInChildren(&targetRange);
3004 const QModelIndex topLeft = index(row, column, parent);
3005 const QModelIndex bottomRight = orient == Qt::Horizontal
3006 ? sibling(row + bottomRow, column + rightColumn, topLeft)
3007 : sibling(row + bottomRow, maxColumn, topLeft);
3008 this->dataChanged(topLeft, bottomRight, {});
3013 bool dropMimeData(
const QMimeData *data, Qt::DropAction action,
int row,
int column,
3014 const QModelIndex &target)
3016 if constexpr (isMutable()) {
3017 if (!canDropMimeData(data, action, row, column, target))
3020 const bool dropOnTarget = row == -1 && column == -1 && target.isValid();
3022 auto automaticDropOption = [=](
auto dropResult){
3023 DropOperation dropOperation;
3024 if constexpr (
std::is_same_v<
bool,
decltype(dropResult)>) {
3025 dropOperation = dropResult ? DropOperation::Automatic
3026 : DropOperation::DontDrop;
3028 dropOperation =
static_cast<DropOperation>(dropResult);
3031 if (dropOperation == DropOperation::Automatic) {
3032 if constexpr (!canInsertRows())
3033 dropOperation = DropOperation::OverwriteAndIgnore;
3034 else if (!dropOnTarget)
3035 dropOperation = DropOperation::InsertAsSiblings;
3036 else if (target.siblingAtColumn(0).flags().testFlag(Qt::ItemNeverHasChildren))
3037 dropOperation = DropOperation::OverwriteAndExtend;
3039 dropOperation = DropOperation::InsertAsChildren;
3041 return dropOperation;
3044 using ItemType = QRangeModelDetails::wrapped_t<
typename row_traits::item_type>;
3045 if constexpr (QRangeModelDetails::item_access<ItemType>::hasDropMimeDataFull
3046 || QRangeModelDetails::item_access<ItemType>::hasDropMimeData) {
3047 using ItemAccess = QRangeModelDetails::QRangeModelItemAccess<ItemType>;
3048 using DroppedItem = QRangeModelDetails::DroppedEntry<ItemType>;
3049 std::vector<DroppedItem> droppedItems;
3050 DropOperation dropOperation = automaticDropOption([&]{
3051 auto inserter =
std::back_inserter(droppedItems);
3052 if constexpr (QRangeModelDetails::item_access<ItemType>::hasDropMimeDataFull)
3053 return ItemAccess::dropMimeData(data, action, row, column, target, inserter);
3055 return ItemAccess::dropMimeData(data, inserter);
3057 if (doDropMimeData<Qt::Horizontal>(droppedItems, dropOperation, row, column, target))
3060 }
else if constexpr (QRangeModelDetails::hasDropMimeDataFull<wrapped_row_type>
3061 || QRangeModelDetails::hasDropMimeData<wrapped_row_type>) {
3062 using RowOptions = QRangeModelDetails::QRangeModelRowOptions<wrapped_row_type>;
3063 using DroppedRow = QRangeModelDetails::DroppedEntry<wrapped_row_type>;
3064 std::vector<DroppedRow> droppedRows;
3065 DropOperation dropOperation = automaticDropOption([&]{
3066 auto inserter =
std::back_inserter(droppedRows);
3067 if constexpr (QRangeModelDetails::hasDropMimeDataFull<wrapped_row_type>)
3068 return RowOptions::dropMimeData(data, action, row, column, target, inserter);
3070 return RowOptions::dropMimeData(data, inserter);
3072 if (doDropMimeData<Qt::Vertical>(droppedRows, dropOperation, row, column, target))
3076 if (dropOnTarget && that().dropOnItem(data, target))
3094 using pointer [[maybe_unused]] =
void;
3100 , m_columnCount(model->columnCount({}))
3102 updateCurrentIndexFullRow();
3107 const QModelIndex &index = *m_it;
3108 return {m_model->rowData(index),
3109 m_currentIndexIsFullRow
3110 ? m_model->createIndex(m_it->row(), -1, m_it->internalPointer()) : index};
3114 if (m_currentIndexIsFullRow)
3115 m_it += m_columnCount;
3118 updateCurrentIndexFullRow();
3125 m_currentIndexIsFullRow =
false;
3126 const int lastColumn = m_columnCount - 1;
3127 if (m_it - m_begin >= lastColumn && m_it->column() == lastColumn) {
3128 const QModelIndex &firstInRow = m_it[-lastColumn];
3129 if (m_it->row() == firstInRow.row()
3130 && firstInRow.internalPointer() == m_it->internalPointer()) {
3131 m_currentIndexIsFullRow =
true;
3141 auto tmp = *
this; tmp.m_it -= n;
return tmp;
3148 void updateCurrentIndexFullRow()
3150 m_currentIndexIsFullRow =
false;
3151 if (m_it == m_end || m_it->column() || m_end - m_it < m_columnCount)
3153 const QModelIndex &lastInRow = m_it[m_columnCount - 1];
3154 m_currentIndexIsFullRow = lastInRow.row() == m_it->row()
3155 && lastInRow.internalPointer() == m_it->internalPointer();
3159 base_iterator m_begin;
3160 base_iterator m_end;
3162 int m_columnCount = 0;
3163 bool m_currentIndexIsFullRow =
false;
3177 using pointer [[maybe_unused]] =
void;
3181 const QModelIndex &index = *m_it;
3183 const item_type *pitem =
nullptr;
3184 const auto &row =
m_model->rowData(index);
3186 row_traits::for_element_at(QRangeModelDetails::refTo(row), index.column(),
3187 [&pitem](
const auto &item){
3192 if constexpr (std::disjunction_v<QRangeModelDetails::is_owning_or_raw_pointer<row_type>,
3193 QRangeModelDetails::is_owning_or_raw_pointer<item_type>>) {
3197 constexpr bool is_constexpr_default_constructible_v =
3198 value_type::
template is_constexpr_default_constructible<item_type>::value;
3199 if constexpr (is_constexpr_default_constructible_v) {
3200 Q_CONSTINIT
static const item_type emptyDefault;
3201 return {emptyDefault, index};
3204 static const item_type emptyDefault;
3205 return {emptyDefault, index};
3210 return {*pitem, index};
3220 auto tmp = *
this; tmp.m_it -= n;
return tmp;
3230 template <
typename Iterator>
3246 QMimeData *result =
nullptr;
3247 using RowOptions = QRangeModelDetails::QRangeModelRowOptions<wrapped_row_type>;
3248 using ItemType = QRangeModelDetails::wrapped_t<
typename row_traits::item_type>;
3250 if constexpr (QRangeModelDetails::item_access<ItemType>::hasMimeData) {
3251 using ItemAccess = QRangeModelDetails::QRangeModelItemAccess<ItemType>;
3254 result = ItemAccess::mimeData(MimeDataRange<MimeDataItemIterator>{begin, end});
3255 }
else if constexpr (QRangeModelDetails::hasMimeDataRowSpan<wrapped_row_type>) {
3256 const auto begin =
MimeDataRowIterator(indexes.begin(), indexes.begin(), indexes.end(),
this);
3257 const auto end =
MimeDataRowIterator(indexes.end(), indexes.begin(), indexes.end(),
this);
3258 result = RowOptions::mimeData(MimeDataRange<MimeDataRowIterator>{begin, end});
3259 }
else if constexpr (QRangeModelDetails::hasMimeDataIndexList<wrapped_row_type>) {
3260 result = RowOptions::mimeData(indexes);
3326 static constexpr bool modelCopied = !QRangeModelDetails::is_wrapped<Range>() &&
3327 (std::is_reference_v<Range> || std::is_const_v<std::remove_reference_t<Range>>);
3329 static constexpr bool modelShared = QRangeModelDetails::is_any_shared_ptr<Range>();
3331 static constexpr bool default_row_deleter = protocol_traits::is_default &&
3332 protocol_traits::has_deleteRow;
3334 static constexpr bool ambiguousRowOwnership = (modelCopied || modelShared) &&
3337 static_assert(!ambiguousRowOwnership,
3338 "Using of copied and shared tree and table models with rows as raw pointers, "
3339 "and the default protocol is not allowed due to ambiguity of rows ownership. "
3340 "Move the model in, use another row type, or implement a custom tree protocol.");
3342 if constexpr (protocol_traits::has_deleteRow && !std::is_pointer_v<Range>
3343 && !QRangeModelDetails::is_any_of<Range, std::reference_wrapper>()) {
3346 that().deleteRemovedRows(begin, end);
3352 if constexpr (dynamicColumns() && !row_features::has_resize) {
3356 }
else if constexpr (!protocol_traits::has_newRow) {
3359 }
else if constexpr (!range_features::has_insert_range
3360 && !std::is_copy_constructible_v<row_type>) {
3366 return Structure::canInsertRowsImpl();
3372 return Structure::canRemoveRowsImpl();
3375 template <
typename F>
3376 bool writeAt(
const QModelIndex &index, F&& writer)
3378 row_reference row = rowData(index);
3381 return row_traits::for_element_at(row, index.column(), [&writer](
auto &&target) {
3382 using target_type =
decltype(target);
3384 if constexpr (std::is_lvalue_reference_v<target_type>
3385 && !std::is_const_v<std::remove_reference_t<target_type>>) {
3386 return writer(std::forward<target_type>(target));
3393 template <
typename F>
3394 bool readAt(
const QModelIndex &index, F&& reader)
const {
3395 const_row_reference row = rowData(index);
3398 return row_traits::for_element_at(row, index.column(), std::forward<F>(reader));
3401 template <
typename Value>
3404 if constexpr (std::is_constructible_v<QVariant, Value>)
3405 return QVariant(value);
3407 return QVariant::fromValue(value);
3409 template <
typename Value>
3413 if constexpr (std::is_constructible_v<QVariant, Value *>)
3414 return QVariant(value);
3416 return read(*value);
3421 template <
typename Target>
3422 static bool write(Target &target,
const QVariant &value)
3424 using Type = std::remove_reference_t<Target>;
3425 if constexpr (std::is_constructible_v<Target, QVariant>) {
3428 }
else if (value.canConvert<Type>()) {
3429 target = value.value<Type>();
3434 template <
typename Target>
3435 static bool write(Target *target,
const QVariant &value)
3438 return write(*target, value);
3442 template <
typename ItemType>
3446 operator QMetaProperty()
const {
3447 const QByteArray roleName = that.itemModel().roleNames().value(role);
3448 const QMetaObject &mo = ItemType::staticMetaObject;
3449 if (
const int index = mo.indexOfProperty(roleName.data());
3451 return mo.property(index);
3455 const QRangeModelImpl &that;
3457 } findProperty{*
this, role};
3459 if constexpr (ModelData::cachesProperties)
3460 return *m_data.properties.tryEmplace(role, findProperty).iterator;
3462 return findProperty;
3466 const QObject *gadget,
const QMetaProperty &prop)
const
3468 if (!index.isValid())
3470 const typename ModelData::Connection connection = {gadget, role};
3471 if (prop.hasNotifySignal() &&
this->autoConnectPolicy() == AutoConnectPolicy::OnRead
3472 && !m_data.connections.contains(connection)) {
3473 if constexpr (isMutable())
3474 Self::connectProperty(index, gadget, m_data.context, role, prop);
3476 Self::connectPropertyConst(index, gadget, m_data.context, role, prop);
3477 m_data.connections.insert(connection);
3481 template <
typename ItemType>
3484 using item_type = std::remove_pointer_t<ItemType>;
3486 QMetaProperty prop = roleProperty<item_type>(role);
3487 if (!prop.isValid() && role == Qt::EditRole) {
3488 role = Qt::DisplayRole;
3489 prop = roleProperty<item_type>(Qt::DisplayRole);
3492 if (prop.isValid()) {
3493 if constexpr (itemsAreQObjects)
3494 connectPropertyOnRead(index, role, gadget, prop);
3495 result = readProperty(prop, gadget);
3500 template <
typename ItemType>
3503 return readRole(index, role, &gadget);
3506 template <
typename ItemType>
3509 if constexpr (std::is_base_of_v<QObject, ItemType>)
3510 return prop.read(gadget);
3512 return prop.readOnGadget(gadget);
3515 template <
typename ItemType>
3518 using item_type = std::remove_pointer_t<ItemType>;
3519 const QMetaObject &mo = item_type::staticMetaObject;
3520 const QMetaProperty prop = mo.property(index.column() + mo.propertyOffset());
3522 if constexpr (rowsAreQObjects)
3523 connectPropertyOnRead(index, Qt::DisplayRole, gadget, prop);
3525 return readProperty(prop, gadget);
3528 template <
typename ItemType>
3531 return readProperty(index, &gadget);
3534 template <
typename ItemType>
3535 bool writeRole(
int role, ItemType *gadget,
const QVariant &data)
3537 using item_type = std::remove_pointer_t<ItemType>;
3538 auto prop = roleProperty<item_type>(role);
3539 if (!prop.isValid() && role == Qt::EditRole)
3540 prop = roleProperty<item_type>(Qt::DisplayRole);
3542 return prop.isValid() ? writeProperty(prop, gadget, data) :
false;
3545 template <
typename ItemType>
3546 bool writeRole(
int role, ItemType &&gadget,
const QVariant &data)
3548 return writeRole(role, &gadget, data);
3551 template <
typename ItemType>
3552 static bool writeProperty(
const QMetaProperty &prop, ItemType *gadget,
const QVariant &data)
3554 if constexpr (std::is_base_of_v<QObject, ItemType>)
3555 return prop.write(gadget, data);
3557 return prop.writeOnGadget(gadget, data);
3559 template <
typename ItemType>
3562 using item_type = std::remove_pointer_t<ItemType>;
3563 const QMetaObject &mo = item_type::staticMetaObject;
3564 return writeProperty(mo.property(property + mo.propertyOffset()), gadget, data);
3567 template <
typename ItemType>
3568 static bool writeProperty(
int property, ItemType &&gadget,
const QVariant &data)
3570 return writeProperty(property, &gadget, data);
3573 template <
typename ItemType>
3576 using item_type = std::remove_pointer_t<ItemType>;
3577 const QMetaObject &mo = item_type::staticMetaObject;
3578 bool success =
true;
3579 if (property == -1) {
3581 if constexpr (std::is_base_of_v<QObject, item_type>) {
3582 for (
int p = mo.propertyOffset(); p < mo.propertyCount(); ++p)
3583 success = writeProperty(mo.property(p), object, {}) && success;
3588 success = writeProperty(mo.property(property + mo.propertyOffset()), object, {});
3593 template <
typename ItemType>
3596 return resetProperty(property, &object);
3602 Q_ASSERT(index.isValid());
3603 return that().rowDataImpl(index);
3608 Q_ASSERT(index.isValid());
3609 return that().rowDataImpl(index);
3614 if (!index.isValid())
3615 return m_data.model();
3618 return that().childRangeImpl(index);
3623 if (!index.isValid())
3624 return m_data.model();
3627 return that().childRangeImpl(index);
3638template <
typename Range,
typename Protocol>
3645 using range_type =
typename Base::range_type;
3646 using range_features =
typename Base::range_features;
3647 using row_type =
typename Base::row_type;
3648 using row_ptr =
typename Base::row_ptr;
3649 using const_row_ptr =
typename Base::const_row_ptr;
3651 using tree_traits =
typename Base::protocol_traits;
3652 static constexpr bool is_mutable_impl = tree_traits::has_mutable_childRows;
3654 static constexpr bool rows_are_any_refs_or_pointers = Base::rows_are_raw_pointers ||
3655 QRangeModelDetails::is_smart_ptr<row_type>() ||
3656 QRangeModelDetails::is_any_of<row_type,
std::reference_wrapper>();
3657 static_assert(!Base::dynamicColumns(),
"A tree must have a static number of columns!");
3661 : Base(
std::forward<Range>(model),
std::forward<Protocol>(p), itemModel)
3666 for (
auto &&child : children)
3678 auto *children =
this->childRange(parent);
3681 return autoConnectPropertiesRange(QRangeModelDetails::refTo(children), parent);
3687 if (!parent.isValid())
3688 return this->createIndex(row, column);
3690 if (parent.column())
3691 return QModelIndex();
3693 const_row_ptr grandParent =
static_cast<const_row_ptr>(parent.constInternalPointer());
3694 const auto &parentSiblings = childrenOf(grandParent);
3701 if (!child.isValid())
3705 const_row_ptr parentRow =
static_cast<const_row_ptr>(child.constInternalPointer());
3710 auto &&grandParent =
this->protocol().parentRow(
QRangeModelDetails::refTo(parentRow));
3711 const range_type &parentSiblings = childrenOf(
QRangeModelDetails::pointerTo(grandParent));
3715 const auto it =
std::find_if(begin, end, [parentRow](
auto &&s){
3719 return this->createIndex(
std::distance(begin, it), 0,
3726 return Base::size(
this->childRange(parent));
3733 return Base::fixedColumnCount();
3738 return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
3746 return (rows_are_any_refs_or_pointers || tree_traits::has_setParentRow)
3747 && Base::dynamicRows() && range_features::has_insert;
3755 return (rows_are_any_refs_or_pointers || tree_traits::has_setParentRow)
3756 && Base::dynamicRows() && range_features::has_erase;
3764 static constexpr bool canMoveRows(
const QModelIndex &,
const QModelIndex &)
3770 const QModelIndex &destParent,
int destRow)
3775 if constexpr (!rows_are_any_refs_or_pointers && !tree_traits::has_setParentRow) {
3777 }
else if constexpr (!(range_features::has_insert && range_features::has_erase)) {
3779 }
else if (!
this->beginMoveRows(sourceParent, sourceRow, sourceRow + count - 1,
3780 destParent, destRow)) {
3784 range_type *source =
this->childRange(sourceParent);
3785 range_type *destination =
this->childRange(destParent);
3790 if constexpr (range_features::has_insert_range) {
3792 const auto sourceEnd =
std::next(sourceStart, count);
3794 destination->insert(destStart,
std::move_iterator(sourceStart),
3795 std::move_iterator(sourceEnd));
3796 }
else if constexpr (
std::is_copy_constructible_v<row_type>) {
3798 destination->insert(destStart, count, row_type{});
3801 row_ptr parentRow = destParent.isValid()
3807 if (parentRow ==
static_cast<row_ptr>(sourceParent.internalPointer())) {
3808 if (sourceParent.row() < destRow) {
3809 source =
this->childRange(sourceParent);
3812 source =
this->childRange(
this->createIndex(sourceParent.row() + count, 0,
3813 sourceParent.internalPointer()));
3820 const auto writeEnd =
std::next(writeStart, count);
3822 const auto sourceEnd =
std::next(sourceStart, count);
3824 for (
auto write = writeStart, read = sourceStart; write != writeEnd; ++write, ++read) {
3827 if constexpr (!range_features::has_insert_range)
3828 *write =
std::move(*read);
3832 source->erase(sourceStart, sourceEnd);
3842 this->endMoveRows();
3850 static_assert(tree_traits::has_setParentRow);
3851 row_type empty_row =
this->protocol().newRow();
3857 template <
typename It,
typename Sentinel>
3860 if constexpr (tree_traits::has_deleteRow) {
3861 for (
auto it = begin; it != end; ++it) {
3862 if constexpr (Base::isMutable()) {
3863 decltype(
auto) children =
this->protocol().childRows(
QRangeModelDetails::refTo(*it));
3871 this->protocol().deleteRow(
std::move(*it));
3878 const auto persistentIndexList =
this->persistentIndexList();
3879 const auto [firstColumn, lastColumn] = [&persistentIndexList]{
3880 int first = std::numeric_limits<
int>::max();
3882 for (
const auto &pmi : persistentIndexList) {
3883 first = (
std::min)(pmi.column(), first);
3884 last = (
std::max)(pmi.column(), last);
3886 return std::pair(first, last);
3894 if constexpr (tree_traits::has_setParentRow && !rows_are_any_refs_or_pointers) {
3895 const bool changePersistentIndexes = pmiToColumn >= pmiFromColumn;
3898 for (
auto it = begin; it != end; ++it) {
3899 decltype(
auto) maybeChildren =
this->protocol().childRows(*it);
3905 for (
auto &child : childrenRef) {
3906 const_row_ptr oldParent =
this->protocol().parentRow(child);
3907 if (oldParent != parentRow) {
3908 if (changePersistentIndexes) {
3909 for (
int column = pmiFromColumn; column <= pmiToColumn; ++column) {
3910 this->changePersistentIndex(
this->createIndex(row, column, oldParent),
3911 this->createIndex(row, column, parentRow));
3914 this->protocol().setParentRow(child, parentRow);
3927 for (
const auto &row : range) {
3928 if (!
this->autoConnectPropertiesInRow(row, rowIndex, parent))
3933 if (!autoConnectPropertiesRange(QRangeModelDetails::refTo(children),
3934 this->itemModel().index(rowIndex, 0, parent))) {
3945 return autoConnectPropertiesRange(*
this->m_data.model(), {});
3950 const_row_ptr parentRow =
static_cast<const_row_ptr>(index.constInternalPointer());
3951 const range_type &siblings = childrenOf(parentRow);
3952 Q_ASSERT(index.row() <
int(Base::size(siblings)));
3958 row_ptr parentRow =
static_cast<row_ptr>(index.internalPointer());
3959 range_type &siblings = childrenOf(parentRow);
3960 Q_ASSERT(index.row() <
int(Base::size(siblings)));
3966 const auto &row =
this->rowData(index);
3968 return static_cast<
const range_type *>(
nullptr);
3970 decltype(
auto) children =
this->protocol().childRows(
QRangeModelDetails::refTo(row));
3976 auto &row =
this->rowData(index);
3978 return static_cast<range_type *>(
nullptr);
3980 decltype(
auto) children =
this->protocol().childRows(
QRangeModelDetails::refTo(row));
3981 using Children = std::remove_reference_t<
decltype(children)>;
3983 if constexpr (QRangeModelDetails::is_any_of<Children, std::optional>())
3984 if constexpr (std::is_default_constructible<
typename Children::value_type>()) {
3986 children.emplace(range_type{});
3995 : *
this->m_data.model();
4001 : *
this->m_data.model();
4004 template <
typename LessThan>
4007 for (
auto &row : range) {
4008 decltype(
auto) children =
this->protocol().childRows(
QRangeModelDetails::refTo(row));
4014 this->sortSubRange(range, parentRow, lessThan);
4017 template <
typename LessThan>
4020 sortImplRecursive(*
this->m_data.model(),
nullptr, lessThan);
4026 erase_if(list, [expectedParent](
const QModelIndex &index){
4027 return static_cast<row_ptr>(index.internalPointer()) != expectedParent;
4032 int role,
const QVariant &value,
int hits, Qt::MatchFlags flags,
int column,
4033 QModelIndexList &result,
const QCollator &collator)
const
4038 const bool recurse = flags.testAnyFlag(Qt::MatchRecursive);
4039 const bool allHits = (hits == -1);
4041 for (
int r = from; it != end && r < to && (allHits || result.size() < hits); ++it, ++r) {
4042 const QModelIndex index =
this->createIndex(r, column, parentPtr);
4043 if (
this->matchRow(*it, index, role, value, flags, collator))
4044 result.append(index);
4047 decltype(
auto) children =
this->protocol().childRows(
QRangeModelDetails::refTo(*it));
4050 matchImplRecursive(QRangeModelDetails::refTo(children),
4051 QRangeModelDetails::pointerTo(*it), 0,
4052 int(QRangeModelDetails::size(QRangeModelDetails::refTo(children))),
4053 role, value, hits, flags, column, result, collator);
4060 Qt::MatchFlags flags,
const QCollator &collator)
const
4062 QModelIndexList result;
4063 const bool wrap = flags.testAnyFlag(Qt::MatchWrap);
4064 const int column = start.column();
4065 const int from = start.row();
4066 const int to =
this->rowCount(start.parent());
4068 for (
int i = 0; (wrap && i < 2) || (!wrap && i < 1); ++i) {
4069 const int fromRow = (i == 0) ? from : 0;
4070 const int toRow = (i == 0) ? to : from;
4071 matchImplRecursive(*
this->m_data.model(),
nullptr, fromRow, toRow,
4072 role, value, hits, flags, column, result, collator);
4086template <
typename Range>
4093 static constexpr bool is_mutable_impl =
true;
4111 if constexpr (Base::dynamicColumns()) {
4112 if (column <
int(Base::size(*QRangeModelDetails::pos(*
this->m_data.model(), row))))
4113 return this->createIndex(row, column);
4116 qCritical(
"QRangeModel: Column-range at row %d is not large enough!", row);
4120 return this->createIndex(row, column);
4131 if (parent.isValid())
4133 return int(Base::size(*
this->m_data.model()));
4138 if (parent.isValid())
4142 if constexpr (Base::dynamicColumns()) {
4143 return int(Base::size(*
this->m_data.model()) == 0
4145 : Base::size(*QRangeModelDetails::adl_begin(*
this->m_data.model())));
4147 return Base::fixedColumnCount();
4153 return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemNeverHasChildren;
4158 return Base::dynamicRows() && range_features::has_insert;
4163 return Base::dynamicRows() && range_features::has_erase;
4166 static constexpr bool canMoveColumns(
const QModelIndex &source,
const QModelIndex &destination)
4168 return !source.isValid() && !destination.isValid();
4171 static constexpr bool canMoveRows(
const QModelIndex &source,
const QModelIndex &destination)
4173 return !source.isValid() && !destination.isValid();
4177 const QModelIndex &,
int)
noexcept
4185 row_type empty_row =
this->protocol().newRow();
4188 if constexpr (Base::dynamicColumns() && row_features::has_resize) {
4196 template <
typename It,
typename Sentinel>
4199 if constexpr (Base::protocol_traits::has_deleteRow) {
4200 for (
auto it = begin; it != end; ++it)
4201 this->protocol().deleteRow(
std::move(*it));
4207 Q_ASSERT(q20::cmp_less(index.row(), Base::size(*
this->m_data.model())));
4213 Q_ASSERT(q20::cmp_less(index.row(), Base::size(*
this->m_data.model())));
4230 return *
this->m_data.model();
4236 return *
this->m_data.model();
4247 for (
const auto &row : *
this->m_data.model()) {
4248 result &=
this->autoConnectPropertiesInRow(row, rowIndex, {});
4254 template <
typename LessThan>
4257 this->sortSubRange(*
this->m_data.model(),
nullptr, lessThan);
4263 int hits, Qt::MatchFlags flags,
const QCollator &collator)
const
4265 QModelIndexList result;
4266 const bool wrap = flags.testAnyFlag(Qt::MatchWrap);
4267 const bool allHits = (hits == -1);
4268 const int column = start.column();
4269 int from = start.row();
4270 int to =
this->rowCount({});
4271 decltype(
auto) siblings = *
this->m_data.model();
4273 for (
int i = 0; (wrap && i < 2) || (!wrap && i < 1); ++i) {
4276 for (
int r = from; it != end && r < to && (allHits || result.size() < hits);
4280 const QModelIndex index =
this->createIndex(r, column,
nullptr);
4281 if (
this->matchRow(*it, index, role, value, flags, collator))
4282 result.append(index);
4294 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)
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
QModelIndexList matchImpl(const QModelIndex &start, int role, const QVariant &value, int hits, Qt::MatchFlags flags, const QCollator &collator) 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 &)
bool dropOnItem(const QMimeData *, const QModelIndex &)
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)
QModelIndexList matchImpl(const QModelIndex &start, int role, const QVariant &value, int hits, Qt::MatchFlags flags, const QCollator &collator) const
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)
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 QCollator &collator) const
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
static Qt::weak_ordering compareData(const QVariant &lhs, const QVariant &rhs, const QCollator *collator)
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
static Q_CORE_EXPORT bool matchValue(const QString &itemData, const QVariant &value, Qt::MatchFlags flags, const QCollator &collator)
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)
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 matchRow(const_row_reference row, const QModelIndex &index, int role, const QVariant &value, Qt::MatchFlags flags, const QCollator &collator) const
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)
decltype(QRangeModelRowOptions< row_type >::mimeTypes()) hasMimeTypes_test
static auto adl_end(C &&c) -> decltype(end(QRangeModelDetails::refTo(std::forward< C >(c))))
constexpr bool isValid(const T &t) noexcept
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
decltype(auto) refTo(T &&t)
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 auto pos(C &&c, int i)
static constexpr bool hasHeaderData
static constexpr bool hasCanDropMimeData
static constexpr bool hasRowFlags
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 DroppedEntryCell &lhs, const DroppedEntryCell &rhs) noexcept
friend bool operator==(const DroppedEntryCell &lhs, const DroppedEntryCell &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