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)
210 template <
typename Value>
211 decltype(
auto)
clearItem(Value &&value) {
return value = q20::remove_cvref_t<Value>(); }
219 template <
typename C,
typename =
void>
222 template <
typename C>
233 template <
typename C,
typename =
void>
236 template <
typename C>
245 template <
typename C,
typename =
void>
248 template <
typename C>
256 template <
typename C,
typename =
void>
259 template <
typename C>
270 template <
typename It>
272 std::is_swappable<
decltype(*
std::declval<It>())>,
273 std::is_base_of<
std::forward_iterator_tag,
277 template <
typename C,
typename =
void>
280 template <
typename C>
290 template <
typename C>
291 static void rotate(C& c,
int src,
int count,
int dst) {
293 using Container = std::remove_reference_t<
decltype(container)>;
296 const auto srcEnd =
std::next(srcBegin, count);
299 if constexpr (test_splice<Container>::value) {
300 if (dst > src && dst < src + count)
301 container.splice(srcBegin, container, dstBegin, srcEnd);
303 container.splice(dstBegin, container, srcBegin, srcEnd);
306 std::rotate(srcBegin, srcEnd, dstBegin);
308 std::rotate(dstBegin, srcBegin, srcEnd);
321 template <
typename C>
330 template <
typename C>
335 template <
typename C,
typename =
void>
337 template <
typename C>
340 template <
typename C,
typename =
void>
342 template <
typename C>
347 template <
typename C,
typename =
void>
358 template <
typename C>
399 template <
typename C>
401 template <
typename C>
407 template <
typename T>
416 static constexpr bool hasReadRole = qxp::is_detected_v<hasReadRole_test, ItemAccess, ItemType>;
421 static constexpr bool hasWriteRole = qxp::is_detected_v<hasWriteRole_test, ItemAccess, ItemType>;
423 template <
typename Access,
typename Test>
426 static constexpr bool hasFlags = qxp::is_detected_v<hasFlags_test, ItemAccess, ItemType>;
428 template <
typename Access,
typename Test>
430 static constexpr bool hasMimeTypes = qxp::is_detected_v<hasMimeTypes_test, ItemAccess, ItemType>;
434 static constexpr bool hasMimeData = qxp::is_detected_v<hasMimeData_test, ItemAccess, ItemType>;
436 template <
typename Access>
447 ItemAccess, ItemType>;
450 template <
typename Access>
463 ItemAccess, ItemType>;
470 template <
typename T,
typename =
void>
476 template <
typename T>
490 template <
typename row_type>
493 static constexpr bool hasRowFlags = qxp::is_detected_v<hasRowFlags_test, row_type>;
496 template <
typename row_type>
499 static constexpr bool hasMimeTypes = qxp::is_detected_v<hasMimeTypes_test, row_type>;
527 static constexpr bool hasDropMimeData = qxp::is_detected_v<hasDropMimeData_test, row_type>;
550 template <
typename T,
typename =
void>
567 template <
typename C,
typename Fn>
571 return std::forward<Fn>(fn)(
574 return std::forward<Fn>(fn)(
std::forward<C>(container));
577 template <
typename Fn>
583 int columnIndex = -1;
586 return std::forward<Fn>(fn)(firstIndex.siblingAtColumn(++columnIndex),
594 template <
typename T>
614 template <
typename C,
typename F>
649 template <
typename Fn>
669 template <
typename C,
typename F>
681 template <
typename Fn>
697 template <
typename T>
718 template <
typename C,
typename F>
738 template <
typename Fn>
745 template <
typename T,
typename =
void>
748 template <
typename That>
751 return That::roleNamesForSimpleType();
758 template <
typename That>
765 template <
typename T>
771 template <
typename T>
774 template <
typename That>
781 template <
typename T>
785 template <
typename Range>
791 auto newRow() ->
decltype(R{}) {
return R{}; }
794 template <
typename Range>
822 template <
typename Range,
830 template <
typename Range>
833 template <
typename R >
834 auto parentRow(
const R& row)
const ->
decltype(row.parentRow())
836 return row.parentRow();
839 template <
typename R >
840 auto setParentRow(R &row, R* parent) ->
decltype(row.setParentRow(parent))
842 row.setParentRow(parent);
845 template <
typename R >
846 auto childRows(
const R &row)
const ->
decltype(row.childRows())
848 return row.childRows();
851 template <
typename R >
854 return row.childRows();
858 template <
typename P,
typename R>
861 template <
typename P,
typename R>
864 template <
typename P,
typename R>
867 template <
typename P,
typename R>
870 template <
typename P,
typename R>
874 template <
typename P,
typename R>
877 template <
typename P,
typename R>
880 template <
typename P,
typename R>
883 template <
typename P,
typename =
void>
885 template <
typename P>
889 template <
typename P,
typename R,
typename =
void>
891 template <
typename P,
typename R>
896 template <
typename Range,
908 template <
typename Range>
921 template <
typename Range,
typename Protocol>
945 template <
typename Entry>
950 template<
typename T,
typename =
void>
961 if constexpr (QRangeModelDetails::is_owning_or_raw_pointer<entry_type>()) {
967 qDebug(
"QRangeModel::mimeData: null-entry, test with isValid before accessing");
969 constexpr bool is_constexpr_default_constructible_v =
970 is_constexpr_default_constructible<wrapped_entry>::value;
971 if constexpr (is_constexpr_default_constructible_v) {
972 Q_CONSTINIT
static const wrapped_entry emptyDefault;
976 static const wrapped_entry emptyDefault;
981 return std::as_const(QRangeModelDetails::refTo(m_entry));
986 template <
std::size_t N>
989 if constexpr (N == 0)
990 return entry.entry();
991 else if constexpr (N == 1)
992 return entry.index();
1003template <
typename T>
1006template <
typename T>
1009template <
typename T>
1038 return !(lhs
== rhs);
1042 template <
typename Entry>
1079 template <
bool cacheProperties,
bool itemsAreQObjects>
1111 return lhs.sender == rhs.sender && lhs
.role == rhs
.role;
1115 return qHashMulti(seed, c.sender, c
.role);
1139 template <
typename ModelStorage,
typename =
void>
1158 template <
typename ModelStorage,
typename PropertyStorage>
1169 template <
typename Model = ModelStorage>
1205 bool setHeaderData(
int section, Qt::Orientation orientation,
const QVariant &data,
int role);
1206 bool setData(
const QModelIndex &index,
const QVariant &data,
int role);
1207 bool setItemData(
const QModelIndex &index,
const QMap<
int, QVariant> &data);
1211 bool moveColumns(
const QModelIndex &sourceParent,
int sourceColumn,
int count,
const QModelIndex &destParent,
int destColumn);
1214 bool moveRows(
const QModelIndex &sourceParent,
int sourceRow,
int count,
const QModelIndex &destParent,
int destRow);
1227 void multiData(
const QModelIndex &index, QModelRoleDataSpan roleDataSpan)
const;
1231 void sort(
int column, Qt::SortOrder order);
1233 int hits, Qt::MatchFlags flags)
const;
1239 const QModelIndex &parent)
const;
1240 bool dropMimeData(
const QMimeData *data, Qt::DropAction action,
int row,
int column,
1241 const QModelIndex &parent);
1285 template <
typename C>
1326 friend class QRangeModelPrivate;
1329 QRangeModel *m_rangeModel;
1333 : m_rangeModel(itemModel)
1339 inline void dataChanged(
const QModelIndex &from,
const QModelIndex &to,
1340 const QList<
int> &roles);
1347 inline bool beginMoveColumns(
const QModelIndex &sourceParent,
int sourceFirst,
int sourceLast,
1348 const QModelIndex &destParent,
int destRow);
1350 inline void beginInsertRows(
const QModelIndex &parent,
int start,
int count);
1352 inline void beginRemoveRows(
const QModelIndex &parent,
int start,
int count);
1354 inline bool beginMoveRows(
const QModelIndex &sourceParent,
int sourceFirst,
int sourceLast,
1355 const QModelIndex &destParent,
int destRow);
1361 const QCollator *collator);
1379 QRangeModelDetails::AutoConnectContext *context,
1380 int role,
const QMetaProperty &property);
1382 QRangeModelDetails::AutoConnectContext *context,
1383 int role,
const QMetaProperty &property);
1385 QRangeModelDetails::AutoConnectContext *context,
1386 const QHash<
int, QMetaProperty> &properties);
1388 QRangeModelDetails::AutoConnectContext *context,
1389 const QHash<
int, QMetaProperty> &properties);
1396 Qt::MatchFlags flags);
1398 Qt::MatchFlags flags,
const QCollator &collator);
1399 static bool matchValue(
const QVariant &itemData,
const QVariant &value, Qt::MatchFlags flags,
1400 const QCollator &collator)
1402 if ((flags & Qt::MatchTypeMask) == Qt::MatchExactly)
1403 return itemData == value;
1404 return matchValue(itemData.toString(), value, flags, collator);
1410template <
typename Structure,
typename Range,
1411 typename Protocol = QRangeModelDetails::table_protocol_t<Range>>
1447 "Currently, std::optional is not supported for ranges and rows, as "
1448 "it has range semantics in c++26. Once the required behavior is clarified, "
1449 "std::optional for ranges and rows will be supported.");
1456 Structure&
that() {
return static_cast<Structure &>(*
this); }
1457 const Structure&
that()
const {
return static_cast<
const Structure &>(*
this); }
1459 template <
typename C>
1460 static constexpr int size(
const C &c)
1465 if constexpr (QRangeModelDetails::test_size<C>()) {
1467 return int(size(c));
1469#if defined(__cpp_lib_ranges)
1470 using std::ranges::distance;
1472 using std::distance;
1474 using container_type = std::conditional_t<QRangeModelDetails::range_traits<C>::has_cbegin,
1475 const QRangeModelDetails::wrapped_t<C>,
1476 QRangeModelDetails::wrapped_t<C>>;
1477 container_type& container =
const_cast<container_type &>(
QRangeModelDetails::refTo(c));
1493 return this->blockDataChangedDispatch();
1503 template <
typename T>
1523 {
return lhs.n == rhs.n; }
1525 {
return !(lhs == rhs); }
1536 "The range holding a move-only row-type must support insert(pos, start, end)");
1544 return range_features::is_mutable && row_features::is_mutable
1545 && std::is_reference_v<row_reference>
1546 && Structure::is_mutable_impl;
1563 versionNumber = QT_VERSION;
1574 if (row < 0 || column < 0 || column >= columnCount(parent)
1575 || row >= rowCount(parent)) {
1579 return that().indexImpl(row, column, parent);
1584 if (row == index.row() && column == index.column())
1588 if (column >=
this->columnCount({}))
1591 if (row == index.row())
1592 return this->createIndex(row, column, index.constInternalPointer());
1594 const_row_ptr parentRow =
static_cast<const_row_ptr>(index.constInternalPointer());
1595 const auto siblingCount = size(that().childrenOf(parentRow));
1596 if (row < 0 || row >=
int(siblingCount))
1598 return this->createIndex(row, column, parentRow);
1603 if (!index.isValid()) {
1604 if constexpr (isMutable())
1605 return Qt::ItemIsDropEnabled;
1607 return Qt::NoItemFlags;
1611 std::optional<Qt::ItemFlags> customFlags = std::nullopt;
1612 if constexpr (QRangeModelDetails::hasRowFlags<wrapped_row_type>) {
1613 const_row_reference row = rowData(index);
1615 customFlags = QRangeModelDetails::QRangeModelRowOptions<wrapped_row_type>::flags(
1616 QRangeModelDetails::refTo(row)
1621 readAt(index, [&customFlags](
auto &&ref){
1623 using wrapped_value_type = q20::remove_cvref_t<QRangeModelDetails::wrapped_t<
decltype(ref)>>;
1624 if constexpr (QRangeModelDetails::item_access<wrapped_value_type>::hasFlags) {
1625 using ItemAccess = QRangeModelDetails::QRangeModelItemAccess<wrapped_value_type>;
1627 customFlags = ItemAccess::flags(QRangeModelDetails::refTo(ref));
1634 Qt::ItemFlags f = customFlags ? *customFlags : Structure::defaultFlags();
1636 if constexpr (!isMutable())
1637 f &= ~(Qt::ItemIsEditable | Qt::ItemIsDropEnabled);
1639 f |= Qt::ItemNeverHasChildren;
1644 if (!
this->itemModel().mimeTypes().isEmpty()) {
1645 f |= Qt::ItemIsDragEnabled;
1646 if constexpr (isMutable())
1647 f |= Qt::ItemIsDropEnabled;
1650 if constexpr (QRangeModelDetails::is_owning_or_raw_pointer<row_type>()) {
1652 const_row_reference row = rowData(index);
1654 f &= ~Qt::ItemIsDragEnabled;
1657 if constexpr (isMutable()) {
1662 if constexpr (row_traits::hasMetaObject) {
1663 if (index.column() < row_traits::fixed_size()) {
1664 const QMetaObject mo = wrapped_row_type::staticMetaObject;
1665 const QMetaProperty prop = mo.property(index.column() + mo.propertyOffset());
1666 if (prop.isWritable())
1667 f |= Qt::ItemIsEditable;
1670 using item_type =
typename row_traits::item_type;
1671 if constexpr (QRangeModelDetails::is_owning_or_raw_pointer<item_type>()) {
1674 f &= ~Qt::ItemIsDragEnabled;
1676 f |= Qt::ItemIsEditable;
1677 }
else if constexpr (std::is_reference_v<row_reference> && !std::is_const_v<row_reference>) {
1680 const_row_reference row = rowData(index);
1681 row_reference mutableRow =
const_cast<row_reference>(row);
1683 row_traits::for_element_at(mutableRow, index.column(), [&f](
auto &&ref){
1684 using target_type =
decltype(ref);
1685 if constexpr (QRangeModelDetails::is_owning_or_raw_pointer<target_type>()) {
1687 if (!QRangeModelDetails::isValid(ref))
1688 f &= ~Qt::ItemIsDragEnabled;
1690 if constexpr (std::is_const_v<std::remove_reference_t<target_type>>)
1691 f &= ~Qt::ItemIsEditable;
1692 else if constexpr (std::is_lvalue_reference_v<target_type>)
1693 f |= Qt::ItemIsEditable;
1698 f &= ~Qt::ItemIsEditable;
1708 if constexpr (QRangeModelDetails::hasHeaderData<wrapped_row_type>) {
1709 if (orientation == Qt::Horizontal) {
1710 result = QRangeModelDetails::QRangeModelRowOptions<wrapped_row_type>::headerData(
1713 if (result.isValid())
1718 if (role != Qt::DisplayRole || orientation != Qt::Horizontal
1719 || section < 0 || section >= columnCount({})) {
1720 return this->itemModel().QAbstractItemModel::headerData(section, orientation, role);
1723 result = row_traits::column_name(section);
1724 if (!result.isValid())
1725 result =
this->itemModel().QAbstractItemModel::headerData(section, orientation, role);
1731 if (!index.isValid())
1734 QModelRoleData result(role);
1735 multiData(index, result);
1736 return std::move(result.data());
1741 return role == Qt::RangeModelDataRole
1742 || role == Qt::RangeModelAdapterRole;
1747 return role == Qt::DisplayRole || role == Qt::EditRole;
1752 QMap<
int, QVariant> result;
1754 if (index.isValid()) {
1756 if (!readAt(index, [&result](
const auto &value) {
1757 if constexpr (std::is_convertible_v<
decltype(value),
decltype(result)>) {
1763 const auto roles =
this->itemModel().roleNames().keys();
1764 QVarLengthArray<QModelRoleData, 16> roleDataArray;
1765 roleDataArray.reserve(roles.size());
1766 for (
auto role : roles) {
1767 if (isRangeModelRole(role))
1769 roleDataArray.emplace_back(role);
1771 QModelRoleDataSpan roleDataSpan(roleDataArray);
1772 multiData(index, roleDataSpan);
1774 for (QModelRoleData &roleData : roleDataSpan) {
1775 if (roleData.data().isValid())
1776 result[roleData.role()] = std::move(roleData.data());
1785 template <
typename value_type>
1788 using multi_role = QRangeModelDetails::is_multi_role<value_type>;
1789 using wrapped_value_type = QRangeModelDetails::wrapped_t<value_type>;
1791 const auto readModelData = [&value](QModelRoleData &roleData){
1793 roleData.clearData();
1797 const int role = roleData.role();
1798 if (role == Qt::RangeModelDataRole) {
1802 if constexpr (std::is_copy_assignable_v<wrapped_value_type>)
1803 roleData.setData(QVariant::fromValue(QRangeModelDetails::refTo(value)));
1805 roleData.setData(QVariant::fromValue(QRangeModelDetails::pointerTo(value)));
1806 }
else if (role == Qt::RangeModelAdapterRole) {
1808 if constexpr (
std::is_copy_assignable_v<value_type>)
1809 roleData.setData(QVariant::fromValue(value));
1811 roleData.setData(QVariant::fromValue(QRangeModelDetails::pointerTo(value)));
1818 if constexpr (QRangeModelDetails::item_access<wrapped_value_type>::hasReadRole) {
1819 using ItemAccess = QRangeModelDetails::QRangeModelItemAccess<wrapped_value_type>;
1820 for (
auto &roleData : roleDataSpan) {
1821 if (!readModelData(roleData)) {
1822 roleData.setData(ItemAccess::readRole(QRangeModelDetails::refTo(value),
1826 }
else if constexpr (multi_role()) {
1827 const auto roleNames = [
this]() -> QHash<
int, QByteArray> {
1829 if constexpr (!multi_role::int_key)
1830 return that->itemModel().roleNames();
1834 using key_type =
typename value_type::key_type;
1835 for (
auto &roleData : roleDataSpan) {
1836 const auto &it = [&roleNames, &value, role = roleData.role()]{
1837 Q_UNUSED(roleNames);
1838 if constexpr (multi_role::int_key)
1839 return value.find(key_type(role));
1841 return value.find(roleNames.value(role));
1843 if (it != QRangeModelDetails::adl_end(value))
1844 roleData.setData(QRangeModelDetails::value(it));
1846 roleData.clearData();
1848 }
else if constexpr (has_metaobject<value_type>) {
1849 if (row_traits::fixed_size() <= 1) {
1850 for (
auto &roleData : roleDataSpan) {
1851 if (!readModelData(roleData)) {
1852 roleData.setData(that->readRole(index, roleData.role(),
1853 QRangeModelDetails::pointerTo(value)));
1856 }
else if (index.column() <= row_traits::fixed_size()) {
1857 for (
auto &roleData : roleDataSpan) {
1858 const int role = roleData.role();
1859 if (isPrimaryRole(role)) {
1860 roleData.setData(that->readProperty(index,
1861 QRangeModelDetails::pointerTo(value)));
1863 roleData.clearData();
1868 for (
auto &roleData : roleDataSpan) {
1869 const int role = roleData.role();
1870 if (isPrimaryRole(role) || isRangeModelRole(role))
1871 roleData.setData(read(value));
1873 roleData.clearData();
1884 void multiData(
const QModelIndex &index, QModelRoleDataSpan roleDataSpan)
const
1886 if (!readAt(index,
ItemReader{index, roleDataSpan,
this})) {
1887 for (
auto &roleData : roleDataSpan)
1888 roleData.clearData();
1892 bool setData(
const QModelIndex &index,
const QVariant &data,
int role)
1894 if (!index.isValid())
1897 if constexpr (isMutable()) {
1898 auto emitDataChanged = qScopeGuard([
this, &index, role]{
1899 Q_EMIT
this->dataChanged(index, index,
1900 role == Qt::EditRole || role == Qt::RangeModelDataRole
1901 || role == Qt::RangeModelAdapterRole
1902 ? QList<
int>{} : QList<
int>{role});
1907 const auto writeData = [
this, column = index.column(), &data, role](
auto &&target) ->
bool {
1908 using value_type = q20::remove_cvref_t<
decltype(target)>;
1909 using wrapped_value_type = QRangeModelDetails::wrapped_t<value_type>;
1910 using multi_role = QRangeModelDetails::is_multi_role<value_type>;
1912 if constexpr (std::conjunction_v<QRangeModelDetails::is_any_owning_ptr<value_type>,
1913 std::is_default_constructible<wrapped_value_type>>) {
1915 target.reset(
new wrapped_value_type);
1918 auto setRangeModelDataRole = [&target, &data]{
1919 constexpr auto targetMetaType = QMetaType::fromType<value_type>();
1920 const auto dataMetaType = data.metaType();
1921 constexpr bool isWrapped = QRangeModelDetails::is_wrapped<value_type>();
1922 if constexpr (!std::is_copy_assignable_v<wrapped_value_type>) {
1926 if constexpr (isWrapped) {
1927 constexpr bool is_raw_pointer = std::is_pointer_v<value_type>;
1928 if constexpr (!is_raw_pointer && std::is_copy_assignable_v<value_type>) {
1929 if (data.canConvert(targetMetaType)) {
1930 target = data.value<value_type>();
1933 }
else if constexpr (is_raw_pointer) {
1935 target = data.value<value_type>();
1944 }
else if constexpr (isWrapped) {
1949 if (
const auto mt = QMetaType::fromType<wrapped_value_type>();
1950 data.canConvert(mt)) {
1951 targetRef = data.value<wrapped_value_type>();
1953 }
else if (
const auto mtp = QMetaType::fromType<wrapped_value_type *>();
1954 data.canConvert(mtp)) {
1955 targetRef = *data.value<wrapped_value_type *>();
1959 }
else if (targetMetaType == dataMetaType) {
1960 QRangeModelDetails::refTo(target) = data.value<value_type>();
1962 }
else if (dataMetaType.flags() & QMetaType::PointerToGadget) {
1963 QRangeModelDetails::refTo(target) = *data.value<value_type *>();
1967 qCritical(
"Not able to assign %s to %s",
1968 qPrintable(QDebug::toString(data)), targetMetaType.name());
1973 if constexpr (QRangeModelDetails::item_access<wrapped_value_type>::hasWriteRole) {
1974 using ItemAccess = QRangeModelDetails::QRangeModelItemAccess<wrapped_value_type>;
1975 if (isRangeModelRole(role))
1976 return setRangeModelDataRole();
1977 return ItemAccess::writeRole(QRangeModelDetails::refTo(target), data, role);
1978 }
else if constexpr (has_metaobject<value_type>) {
1979 if (row_traits::fixed_size() <= 1) {
1980 if (isRangeModelRole(role))
1981 return setRangeModelDataRole();
1983 }
else if (column <= row_traits::fixed_size()
1984 && (isPrimaryRole(role) || isRangeModelRole(role))) {
1987 }
else if constexpr (multi_role::value) {
1988 Qt::ItemDataRole roleToSet = Qt::ItemDataRole(role);
1991 const auto roleNames = [
this]() -> QHash<
int, QByteArray> {
1993 if constexpr (!multi_role::int_key)
1994 return this->itemModel().roleNames();
1998 if (role == Qt::EditRole) {
1999 if constexpr (multi_role::int_key) {
2000 if (target.find(roleToSet) == target.end())
2001 roleToSet = Qt::DisplayRole;
2003 if (target.find(roleNames.value(roleToSet)) == target.end())
2004 roleToSet = Qt::DisplayRole;
2007 if constexpr (multi_role::int_key)
2008 return write(target[roleToSet], data);
2010 return write(target[roleNames.value(roleToSet)], data);
2011 }
else if (isPrimaryRole(role) || isRangeModelRole(role)) {
2012 return write(target, data);
2017 if (!writeAt(index, writeData)) {
2018 emitDataChanged.dismiss();
2021 if (isRangeModelRole(role) &&
this->autoConnectPolicy() == AutoConnectPolicy::Full) {
2022 if (QObject *item = data.value<QObject *>())
2023 Self::connectProperties(index, item, m_data.context, m_data.properties);
2031 template <
typename LHS,
typename RHS>
2034 if constexpr (
std::is_pointer_v<RHS>)
2036 else if constexpr (
std::is_assignable_v<LHS, RHS>)
2037 org =
std::forward<RHS>(copy);
2041 template <
typename LHS,
typename RHS>
2044 updateTarget(*org,
std::forward<RHS>(copy));
2047 bool setItemData(
const QModelIndex &index,
const QMap<
int, QVariant> &data)
2049 if (!index.isValid() || data.isEmpty())
2052 if constexpr (isMutable()) {
2053 auto emitDataChanged = qScopeGuard([
this, &index, &data]{
2054 Q_EMIT
this->dataChanged(index, index, data.keys());
2060 auto writeItemData = [
this, &tried, &data](
auto &target) ->
bool {
2062 using value_type = q20::remove_cvref_t<
decltype(target)>;
2063 using multi_role = QRangeModelDetails::is_multi_role<value_type>;
2064 using wrapped_value_type = QRangeModelDetails::wrapped_t<value_type>;
2068 auto makeCopy = [](
const value_type &original){
2069 if constexpr (!std::is_copy_assignable_v<wrapped_value_type>)
2071 else if constexpr (std::is_pointer_v<
decltype(original)>)
2073 else if constexpr (std::is_copy_assignable_v<value_type>)
2079 const auto roleNames =
this->itemModel().roleNames();
2081 if constexpr (QRangeModelDetails::item_access<wrapped_value_type>::hasWriteRole) {
2083 using ItemAccess = QRangeModelDetails::QRangeModelItemAccess<wrapped_value_type>;
2084 const auto roles = roleNames.keys();
2085 auto targetCopy = makeCopy(target);
2086 for (
int role : roles) {
2087 if (!ItemAccess::writeRole(QRangeModelDetails::refTo(targetCopy),
2088 data.value(role), role)) {
2092 updateTarget(target,
std::move(targetCopy));
2094 }
else if constexpr (multi_role()) {
2095 using key_type =
typename value_type::key_type;
2097 const auto roleName = [&roleNames](
int role) {
2098 return roleNames.value(role);
2103 if constexpr (!multi_role::int_key)
2105 auto invalid =
std::find_if(data.keyBegin(), data.keyEnd(),
2106 [&roleName](
int role) {
return roleName(role).isEmpty(); }
2109 if (invalid != data.keyEnd()) {
2111 qWarning(
"No role name set for %d", *invalid);
2117 for (
auto &&[role, value] : data.asKeyValueRange()) {
2118 if constexpr (multi_role::int_key)
2119 target[
static_cast<key_type>(role)] = value;
2121 target[QString::fromUtf8(roleName(role))] = value;
2124 }
else if constexpr (has_metaobject<value_type>) {
2125 if (row_traits::fixed_size() <= 1) {
2127 auto targetCopy = makeCopy(target);
2128 for (
auto &&[role, value] : data.asKeyValueRange()) {
2129 if (isRangeModelRole(role))
2131 if (!writeRole(role, QRangeModelDetails::pointerTo(targetCopy), value)) {
2132 const QByteArray roleName = roleNames.value(role);
2134 qWarning(
"Failed to write value '%s' to role '%s'",
2135 qPrintable(QDebug::toString(value)), roleName.data());
2140 updateTarget(target,
std::move(targetCopy));
2147 if (!writeAt(index, writeItemData)) {
2148 emitDataChanged.dismiss();
2150 return this->itemModel().QAbstractItemModel::setItemData(index, data);
2159 if (!index.isValid())
2162 if constexpr (isMutable()) {
2163 auto emitDataChanged = qScopeGuard([
this, &index]{
2164 Q_EMIT
this->dataChanged(index, index, {});
2167 auto clearData = [column = index.column()](
auto &&target) {
2168 if constexpr (row_traits::hasMetaObject) {
2169 if (row_traits::fixed_size() <= 1) {
2172 }
else if (column <= row_traits::fixed_size()) {
2182 if (!writeAt(index, clearData)) {
2183 emitDataChanged.dismiss();
2194 using item_type = QRangeModelDetails::wrapped_t<
typename row_traits::item_type>;
2195 using item_traits =
typename QRangeModelDetails::item_traits<item_type>;
2196 return item_traits::roleNames(
this);
2203 return row_traits::for_each_element(QRangeModelDetails::refTo(row),
2204 this->itemModel().index(rowIndex, 0, parent),
2205 [
this](
const QModelIndex &index,
const QObject *item) {
2206 if constexpr (isMutable())
2207 return Self::connectProperties(index, item, m_data.context, m_data.properties);
2209 return Self::connectPropertiesConst(index, item, m_data.context, m_data.properties);
2217 row_traits::for_each_element(QRangeModelDetails::refTo(row),
2218 this->itemModel().index(rowIndex, 0, parent),
2219 [
this](
const QModelIndex &,
const QObject *item) {
2220 m_data.connections.removeIf([item](
const auto &connection) {
2221 return connection.sender == item;
2230 using item_type = std::remove_pointer_t<
typename row_traits::item_type>;
2231 using Mapping = QRangeModelDetails::AutoConnectContext::AutoConnectMapping;
2233 delete m_data.context;
2234 m_data.connections = {};
2235 switch (
this->autoConnectPolicy()) {
2236 case AutoConnectPolicy::None:
2237 m_data.context =
nullptr;
2239 case AutoConnectPolicy::Full:
2240 m_data.context =
new QRangeModelDetails::AutoConnectContext(&
this->itemModel());
2242 m_data.properties = QRangeModelImplBase::roleProperties(
this->itemModel(),
2243 item_type::staticMetaObject);
2244 m_data.context->mapping = Mapping::Roles;
2246 m_data.properties = QRangeModelImplBase::columnProperties(wrapped_row_type::staticMetaObject);
2247 m_data.context->mapping = Mapping::Columns;
2249 if (!m_data.properties.isEmpty())
2250 that().autoConnectPropertiesImpl();
2252 case AutoConnectPolicy::OnRead:
2253 m_data.context =
new QRangeModelDetails::AutoConnectContext(&
this->itemModel());
2255 m_data.context->mapping = Mapping::Roles;
2257 m_data.properties = QRangeModelImplBase::columnProperties(wrapped_row_type::staticMetaObject);
2258 m_data.context->mapping = Mapping::Columns;
2264 qWarning(
"All items in the range must be QObject subclasses");
2278 template <
typename C,
typename LessThan>
2280 static constexpr bool hasSortMember = qxp::is_detected_v<sortMember_test, range_type, Compare>;
2298 template <
typename Item>
2299 auto operator()(
const Item &lhs,
const Item &rhs)
const
2301 auto ordering = compare(lhs, rhs);
2302 return m_order == Qt::AscendingOrder ? ordering < 0 : ordering > 0;
2305 template <
typename Item>
2306 auto compare(
const Item &lhs,
const Item &rhs)
const
2308 using value_type = QRangeModelDetails::wrapped_t<Item>;
2309 using multi_role = QRangeModelDetails::is_multi_role<value_type>;
2311 if constexpr (QRangeModelDetails::item_access<value_type>::hasReadRole
2312 || multi_role() || has_metaobject<value_type>) {
2320 Q_ASSERT(!reader.index.isValid());
2322 const QVariant lhsVariant =
std::move(result.data());
2324 const QVariant rhsVariant =
std::move(result.data());
2325 return QRangeModelImplBase::compareData(lhsVariant, rhsVariant, collator);
2326 }
else if constexpr (std::is_same_v<QVariant, value_type>) {
2327 return QRangeModelImplBase::compareData(lhs, rhs, collator);
2328 }
else if constexpr (QtOrderingPrivate::CompareThreeWayTester::hasCompareThreeWay_v
2329 <value_type, value_type>) {
2331 if constexpr (hasCollatedCompare<value_type>) {
2333 using ordering =
decltype(qCompareThreeWay(lhs, rhs));
2334 int res = collator->compare(lhs, rhs);
2336 return ordering::less;
2338 return ordering::greater;
2339 return ordering::equal;
2342 return qCompareThreeWay(lhs, rhs);
2350 return that->readAt(
that->index(0, 0, {}), [
this](
const auto &item){
2355 using ordering =
decltype(compare(item, item));
2358 const QMetaType itemtype = QMetaType::fromType<QRangeModelDetails::wrapped_t<
2359 q20::remove_cvref_t<
decltype(item)>>
2361 qCritical(
"QRangeModel: Cannot compare items of type %s in column %d!",
2362 itemtype.name(), m_index.column());
2373 template <
typename Item>
2381 return std::nullopt;
2391 void sort(
int column, Qt::SortOrder order)
2393 if constexpr (isMutable() && std::is_swappable_v<row_type>) {
2394 if (rowCount({}) < 2 || column >= columnCount({}))
2396 Compare compare(
this, column, order);
2397 if (!compare.checkComparable())
2400 this->beginLayoutChange();
2401 QScopeGuard endLayoutChange([
this]{
this->endLayoutChange(); });
2402 that().sortImpl([&compare](
const auto &leftRow,
const auto &rightRow) {
2403 if (
auto anyInvalid =
Compare::compareInvalid(leftRow, rightRow))
2405 return row_traits::for_element_at(leftRow, compare.m_index.column(),
2406 [&rightRow, &compare](
const auto &leftItem){
2407 return row_traits::for_element_at(rightRow, compare.m_index.column(),
2408 [&leftItem, &compare](
const auto &rightItem){
2411 if constexpr (std::is_same_v<
decltype(leftItem),
decltype(rightItem)>) {
2412 if (
auto anyInvalid = Compare::compareInvalid(leftItem, rightItem))
2414 return compare(QRangeModelDetails::refTo(leftItem),
2415 QRangeModelDetails::refTo(rightItem));
2426 template <
typename LessThan>
2427 void sortSubRange(range_type &range, row_ptr expectedParent,
const LessThan &lessThan)
2434 QModelIndexList persistentIndexes =
this->persistentIndexList();
2435 that().prunePersistentIndexList(persistentIndexes, expectedParent);
2437 if (persistentIndexes.isEmpty()) {
2438 using It =
typename range_features::iterator;
2439 constexpr bool is_random_access = std::is_base_of_v<std::random_access_iterator_tag,
2440 typename std::iterator_traits<It>::iterator_category>;
2442 if constexpr (
Compare::hasSortMember) {
2443 range.sort(lessThan);
2445 }
else if constexpr (is_random_access) {
2446 std::stable_sort(begin, end, lessThan);
2459 const int rangeSize = size(range);
2462 std::vector<SortTracker> tracked;
2463 tracked.reserve(rangeSize);
2464 std::vector<
int> newRows;
2465 newRows.resize(rangeSize);
2469 for (
auto &&it =
std::move_iterator(begin); it !=
std::move_iterator(end); ++it)
2470 tracked.emplace_back(SortTracker{*it, ++row});
2473 std::stable_sort(tracked.begin(), tracked.end(),
2474 [&lessThan](
const SortTracker &lhs,
const SortTracker &rhs){
2475 return lessThan(lhs.row, rhs.row);
2480 auto sorted =
std::move_iterator(tracked.begin());
2482 for (
int newIndex = 0; newIndex < rangeSize; ++write, ++sorted, ++newIndex) {
2483 auto &&tracker = *sorted;
2484 *write =
std::move(tracker.row);
2485 newRows[tracker.index] = newIndex;
2490 tracked.shrink_to_fit();
2493 for (
const auto &fromIndex : std::as_const(persistentIndexes)) {
2494 const int newRow = newRows.at(fromIndex.row());
2495 if (fromIndex.row() == newRow)
2497 const QModelIndex toIndex = that().indexImpl(newRow,
2499 fromIndex.parent());
2500 this->changePersistentIndex(fromIndex, toIndex);
2505 Qt::MatchFlags flags)
const
2507 QCollator collator =
this->matchCollator();
2508 collator.setCaseSensitivity(flags.testFlag(Qt::MatchCaseSensitive) ? Qt::CaseSensitive
2509 : Qt::CaseInsensitive);
2510 return that().matchImpl(start, role,
2511 QRangeModelImplBase::convertMatchValue(value, flags), hits,
2515 bool matchRow(const_row_reference row,
const QModelIndex &index,
int role,
const QVariant &value,
2516 Qt::MatchFlags flags,
const QCollator &collator)
const
2518 const uint matchType = (flags & Qt::MatchTypeMask).toInt();
2520 return row_traits::for_element_at(row, index.column(), [&](
const auto &element) {
2521 using value_type = q20::remove_cvref_t<
decltype(element)>;
2522 using wrapped_value_type = QRangeModelDetails::wrapped_t<value_type>;
2523 using multi_role = QRangeModelDetails::is_multi_role<value_type>;
2525 if constexpr (QRangeModelDetails::item_access<wrapped_value_type>::hasReadRole
2526 || multi_role() || has_metaobject<value_type>) {
2527 QModelRoleData roleData(role);
2528 ItemReader reader{index, roleData,
this};
2530 return QRangeModelImplBase::matchValue(roleData.data(), value, flags, collator);
2531 }
else if constexpr (std::is_same_v<wrapped_value_type, QVariant>) {
2532 return QRangeModelImplBase::matchValue(element, value, flags, collator);
2534 constexpr QMetaType mt = QMetaType::fromType<wrapped_value_type>();
2535 if (mt == value.metaType()) {
2536 if (matchType == Qt::MatchExactly)
2537 return mt.equals(QRangeModelDetails::pointerTo(element), value.constData());
2538 else if constexpr (std::is_same_v<wrapped_value_type, QString>)
2539 return QRangeModelImplBase::matchValue(element, value, flags, collator);
2541 return QRangeModelImplBase::matchValue(QVariant::fromValue(QRangeModelDetails::refTo(element)),
2542 value, flags, collator);
2549 template <
typename InsertFn>
2554 range_type *
const children = childRange(parent);
2558 this->beginInsertColumns(parent, column, column + count - 1);
2560 for (
auto &child : *children) {
2561 auto it = QRangeModelDetails::pos(child, column);
2562 (
void)insertFn(QRangeModelDetails::refTo(child), it, count);
2565 this->endInsertColumns();
2571 if (m_data.context &&
this->autoConnectPolicy() == AutoConnectPolicy::Full) {
2572 for (
int r = 0; r < that().rowCount(parent); ++r) {
2573 for (
int c = column; c < column + count; ++c) {
2574 const QModelIndex index = that().index(r, c, parent);
2575 writeAt(index, [
this, &index](QObject *item){
2576 return Self::connectProperties(index, item,
2577 m_data.context, m_data.properties);
2589 if constexpr (dynamicColumns() && isMutable() && row_features::has_insert) {
2590 return doInsertColumns(column, count, parent, [](
auto &row,
auto it,
int n){
2591 row.insert(it, n, {});
2601 if constexpr (dynamicColumns() && isMutable() && row_features::has_erase) {
2602 if (column < 0 || column + count > columnCount(parent))
2605 range_type *
const children = childRange(parent);
2610 if (m_data.context &&
this->autoConnectPolicy() == AutoConnectPolicy::OnRead) {
2611 for (
int r = 0; r < that().rowCount(parent); ++r) {
2612 for (
int c = column; c < column + count; ++c) {
2613 const QModelIndex index = that().index(r, c, parent);
2614 writeAt(index, [
this](QObject *item){
2615 m_data.connections.removeIf([item](
const auto &connection) {
2616 return connection.sender == item;
2625 this->beginRemoveColumns(parent, column, column + count - 1);
2626 for (
auto &child : *children) {
2627 const auto start = QRangeModelDetails::pos(child, column);
2628 QRangeModelDetails::refTo(child).erase(start, std::next(start, count));
2630 this->endRemoveColumns();
2636 bool moveColumns(
const QModelIndex &sourceParent,
int sourceColumn,
int count,
2637 const QModelIndex &destParent,
int destColumn)
2640 if (sourceParent != destParent)
2642 if constexpr (isMutable() && (row_features::has_rotate || row_features::has_splice)) {
2643 if (!Structure::canMoveColumns(sourceParent, destParent))
2649 range_type *
const children = childRange(sourceParent);
2653 if (!
this->beginMoveColumns(sourceParent, sourceColumn, sourceColumn + count - 1,
2654 destParent, destColumn)) {
2658 for (
auto &child : *children)
2659 QRangeModelDetails::rotate(child, sourceColumn, count, destColumn);
2661 this->endMoveColumns();
2668 template <
typename InsertFn>
2669 bool doInsertRows(
int row,
int count,
const QModelIndex &parent, InsertFn &&insertFn)
2671 range_type *children = childRange(parent);
2675 this->beginInsertRows(parent, row, row + count - 1);
2677 row_ptr parentRow = parent.isValid()
2680 (
void)
std::forward<InsertFn>(insertFn)(*children, parentRow, row, count);
2684 that().resetParentInChildren(children);
2686 this->endInsertRows();
2692 if (m_data.context &&
this->autoConnectPolicy() == AutoConnectPolicy::Full) {
2694 const auto end =
std::next(begin, count);
2696 for (
auto it = begin; it != end; ++it, ++rowIndex)
2697 autoConnectPropertiesInRow(*it, rowIndex, parent);
2707 return doInsertRows(row, count, parent,
2708 [
this](range_type &children, row_ptr parentRow,
int r,
int n){
2712 if constexpr (range_features::has_insert_range) {
2715 auto start = children.insert(pos, n,
nullptr);
2718 children.insert(pos, n,
std::move(*generator));
2727 bool removeRows(
int row,
int count,
const QModelIndex &parent = {})
2730 const int prevRowCount = rowCount(parent);
2731 if (row < 0 || row + count > prevRowCount)
2734 range_type *children = childRange(parent);
2739 if (m_data.context &&
this->autoConnectPolicy() == AutoConnectPolicy::OnRead) {
2741 const auto end =
std::next(begin, count);
2743 for (
auto it = begin; it != end; ++it, ++rowIndex)
2744 clearConnectionInRow(*it, rowIndex, parent);
2748 this->beginRemoveRows(parent, row, row + count - 1);
2749 [[maybe_unused]]
bool callEndRemoveColumns =
false;
2753 if (prevRowCount == count) {
2754 if (
const int columns = columnCount(parent)) {
2755 callEndRemoveColumns =
true;
2756 this->beginRemoveColumns(parent, 0, columns - 1);
2762 const auto end =
std::next(begin, count);
2763 that().deleteRemovedRows(begin, end);
2764 children->erase(begin, end);
2768 that().resetParentInChildren(children);
2771 if (callEndRemoveColumns) {
2772 Q_ASSERT(columnCount(parent) == 0);
2773 this->endRemoveColumns();
2776 this->endRemoveRows();
2783 bool moveRows(
const QModelIndex &sourceParent,
int sourceRow,
int count,
2784 const QModelIndex &destParent,
int destRow)
2786 if constexpr (isMutable() && (range_features::has_rotate || range_features::has_splice)) {
2787 if (!Structure::canMoveRows(sourceParent, destParent))
2790 if (sourceParent != destParent) {
2791 return that().moveRowsAcross(sourceParent, sourceRow, count,
2792 destParent, destRow);
2795 if (sourceRow == destRow || sourceRow == destRow - 1 || count <= 0
2796 || sourceRow < 0 || sourceRow + count - 1 >=
this->rowCount(sourceParent)
2797 || destRow < 0 || destRow >
this->rowCount(destParent)) {
2801 range_type *source = childRange(sourceParent);
2803 if (!
this->beginMoveRows(sourceParent, sourceRow, sourceRow + count - 1, destParent, destRow))
2808 that().resetParentInChildren(source);
2810 this->endMoveRows();
2822 int rowCount(
const QModelIndex &parent)
const {
return that().rowCountImpl(parent); }
2827 return row_traits::fixed_size();
2831 int columnCount(
const QModelIndex &parent)
const {
return that().columnCountImpl(parent); }
2836 if constexpr (!isMutable())
2837 dragActions &= ~Qt::MoveAction;
2842 if constexpr (!isMutable())
2843 dropActions = Qt::IgnoreAction;
2850 using ItemType = QRangeModelDetails::wrapped_t<
typename row_traits::item_type>;
2851 if constexpr (QRangeModelDetails::item_access<ItemType>::hasMimeTypes)
2852 return QRangeModelDetails::QRangeModelItemAccess<ItemType>::mimeTypes();
2853 else if constexpr (QRangeModelDetails::hasMimeTypes<wrapped_row_type>)
2854 return QRangeModelDetails::QRangeModelRowOptions<wrapped_row_type>::mimeTypes();
2856 return this->itemModel().QAbstractItemModel::mimeTypes();
2860 const QModelIndex &target)
const
2862 if constexpr (isMutable()) {
2864 using RowOptions = QRangeModelDetails::QRangeModelRowOptions<wrapped_row_type>;
2865 using ItemType = QRangeModelDetails::wrapped_t<
typename row_traits::item_type>;
2866 using ItemAccess = QRangeModelDetails::QRangeModelItemAccess<ItemType>;
2867 if constexpr (QRangeModelDetails::item_access<ItemType>::hasCanDropMimeDataFull) {
2868 canDrop = ItemAccess::canDropMimeData(data, action, row, column, target);
2869 }
else if constexpr (QRangeModelDetails::hasCanDropMimeDataFull<wrapped_row_type>) {
2870 canDrop = RowOptions::canDropMimeData(data, action, row, column, target);
2872 canDrop =
this->itemModel().QAbstractItemModel::canDropMimeData(data, action, row,
2874 if constexpr (QRangeModelDetails::item_access<ItemType>::hasCanDropMimeData)
2875 canDrop &= ItemAccess::canDropMimeData(data);
2876 else if constexpr (QRangeModelDetails::hasCanDropMimeData<wrapped_row_type>)
2877 canDrop &= RowOptions::canDropMimeData(data);
2886 template <Qt::Orientation orient,
typename Entry>
2887 bool doDropMimeData(std::vector<QRangeModelDetails::DroppedEntry<Entry>> &droppedEntries,
2888 DropOperation dropOperation,
int row,
int column,
const QModelIndex &target)
2891 using Cell =
typename DroppedEntry::Cell;
2892 if (dropOperation == DropOperation::DontDrop)
2895 const bool dropOnTarget = row == -1 && column == -1 && target.isValid();
2896 const QModelIndex parent = dropOperation == DropOperation::InsertAsChildren
2897 ? target.siblingAtColumn(0) : target.parent();
2900 if constexpr (orient == Qt::Horizontal)
2905 int rightColumn = -1;
2908 int maxColumn = that().columnCount(parent) - 1;
2909 for (
auto &droppedEntry : droppedEntries) {
2910 if (droppedEntry.m_cell == Cell{-1, -1}) {
2911 if constexpr (orient == Qt::Horizontal) {
2914 droppedEntry.m_cell = {lastCell.m_row, lastCell.m_column + 1};
2915 if (droppedEntry.m_cell.m_column > maxColumn) {
2916 droppedEntry.m_cell.m_column = 0;
2917 ++droppedEntry.m_cell.m_row;
2920 droppedEntry.m_cell = {lastCell.m_row + 1, lastCell.m_column};
2923 lastCell = droppedEntry.m_cell;
2924 bottomRow = std::max(lastCell.m_row, bottomRow);
2925 rightColumn = std::max(lastCell.m_column, rightColumn);
2928 if (dropOperation == DropOperation::InsertAsChildren) {
2929 row = rowCount(parent);
2931 }
else if (dropOnTarget) {
2933 column = target.column();
2936 row = rowCount(parent);
2941 const bool overwrite = dropOperation == DropOperation::OverwriteAndIgnore
2942 || dropOperation == DropOperation::OverwriteAndExtend;
2945 const int overwriteRows = overwrite
2946 ?
std::min(bottomRow + 1, rowCount(parent) - row)
2948 const int newRows = dropOperation == DropOperation::OverwriteAndExtend
2949 ? bottomRow - overwriteRows + 1
2950 : (dropOperation == DropOperation::InsertAsChildren
2951 || dropOperation == DropOperation::InsertAsSiblings)
2954 if (newRows > 0 && !insertRows(row, newRows, parent))
2958 const int overwriteColumns = overwrite
2959 ?
std::min(rightColumn + 1, columnCount(parent) - column)
2961 const int newColumns = dropOperation == DropOperation::OverwriteAndExtend
2962 ? rightColumn - overwriteColumns + 1 : 0;
2963 if (newColumns > 0 && !insertColumns(column, newColumns, parent))
2967 range_type *parentRange = that().childRange(parent);
2970 range_type &targetRange = *parentRange;
2972 int maxRow = that().rowCount(parent) - 1;
2973 maxColumn = that().columnCount(parent) - 1;
2974 auto begin =
std::move_iterator(droppedEntries.begin());
2975 auto end =
std::move_iterator(droppedEntries.end());
2976 for (; begin != end; ++begin) {
2977 DroppedEntry droppedEntry = *begin;
2978 const Cell cell = {droppedEntry.m_cell.m_row + row, droppedEntry.m_cell.m_column + column};
2979 if (cell.m_row > maxRow || cell.m_column > maxColumn)
2982 if constexpr (orient == Qt::Vertical) {
2983 if constexpr (QRangeModelDetails::is_owning_or_raw_pointer<row_type>()) {
2985 *writeRow =
this->protocol().newRow();
2986 **writeRow =
std::move(droppedEntry);
2988 *writeRow =
std::move(droppedEntry);
2991 row_traits::for_element_at(*writeRow, cell.m_column, [&](
auto &item){
2992 using item_type = q20::remove_cvref_t<
decltype(item)>;
2993 using wrapped_item_type = QRangeModelDetails::wrapped_t<item_type>;
2994 if constexpr (QRangeModelDetails::is_any_owning_ptr<item_type>()) {
2995 if (!QRangeModelDetails::isValid(item))
2996 item.reset(
new wrapped_item_type{std::move(droppedEntry)});
2998 *item = std::move(droppedEntry);
2999 }
else if (!QRangeModelDetails::isValid(item)) {
3002 item = std::move(droppedEntry);
3009 that().resetParentInChildren(&targetRange);
3011 const QModelIndex topLeft = index(row, column, parent);
3012 const QModelIndex bottomRight = orient == Qt::Horizontal
3013 ? sibling(row + bottomRow, column + rightColumn, topLeft)
3014 : sibling(row + bottomRow, maxColumn, topLeft);
3015 this->dataChanged(topLeft, bottomRight, {});
3020 bool dropMimeData(
const QMimeData *data, Qt::DropAction action,
int row,
int column,
3021 const QModelIndex &target)
3023 if constexpr (isMutable()) {
3024 if (!canDropMimeData(data, action, row, column, target))
3027 const bool dropOnTarget = row == -1 && column == -1 && target.isValid();
3029 auto automaticDropOption = [=](
auto dropResult){
3030 DropOperation dropOperation;
3031 if constexpr (
std::is_same_v<
bool,
decltype(dropResult)>) {
3032 dropOperation = dropResult ? DropOperation::Automatic
3033 : DropOperation::DontDrop;
3035 dropOperation =
static_cast<DropOperation>(dropResult);
3038 if (dropOperation == DropOperation::Automatic) {
3040 dropOperation = DropOperation::OverwriteAndIgnore;
3041 else if (!dropOnTarget)
3042 dropOperation = DropOperation::InsertAsSiblings;
3043 else if (target.siblingAtColumn(0).flags().testFlag(Qt::ItemNeverHasChildren))
3044 dropOperation = DropOperation::OverwriteAndExtend;
3046 dropOperation = DropOperation::InsertAsChildren;
3048 return dropOperation;
3051 using ItemType = QRangeModelDetails::wrapped_t<
typename row_traits::item_type>;
3052 if constexpr (QRangeModelDetails::item_access<ItemType>::hasDropMimeDataFull
3053 || QRangeModelDetails::item_access<ItemType>::hasDropMimeData) {
3054 using ItemAccess = QRangeModelDetails::QRangeModelItemAccess<ItemType>;
3055 using DroppedItem = QRangeModelDetails::DroppedEntry<ItemType>;
3056 std::vector<DroppedItem> droppedItems;
3057 DropOperation dropOperation = automaticDropOption([&]{
3058 auto inserter =
std::back_inserter(droppedItems);
3059 if constexpr (QRangeModelDetails::item_access<ItemType>::hasDropMimeDataFull)
3060 return ItemAccess::dropMimeData(data, action, row, column, target, inserter);
3062 return ItemAccess::dropMimeData(data, inserter);
3064 if (doDropMimeData<Qt::Horizontal>(droppedItems, dropOperation, row, column, target))
3067 }
else if constexpr (QRangeModelDetails::hasDropMimeDataFull<wrapped_row_type>
3068 || QRangeModelDetails::hasDropMimeData<wrapped_row_type>) {
3069 using RowOptions = QRangeModelDetails::QRangeModelRowOptions<wrapped_row_type>;
3070 using DroppedRow = QRangeModelDetails::DroppedEntry<wrapped_row_type>;
3071 std::vector<DroppedRow> droppedRows;
3072 DropOperation dropOperation = automaticDropOption([&]{
3073 auto inserter =
std::back_inserter(droppedRows);
3074 if constexpr (QRangeModelDetails::hasDropMimeDataFull<wrapped_row_type>)
3075 return RowOptions::dropMimeData(data, action, row, column, target, inserter);
3077 return RowOptions::dropMimeData(data, inserter);
3079 if (doDropMimeData<Qt::Vertical>(droppedRows, dropOperation, row, column, target))
3083 if (dropOnTarget && that().dropOnItem(data, target))
3107 , m_columnCount(model->columnCount({}))
3109 updateCurrentIndexFullRow();
3114 const QModelIndex &index = *m_it;
3115 return {m_model->rowData(index),
3116 m_currentIndexIsFullRow
3117 ? m_model->createIndex(m_it->row(), -1, m_it->internalPointer()) : index};
3121 if (m_currentIndexIsFullRow)
3122 m_it += m_columnCount;
3125 updateCurrentIndexFullRow();
3132 m_currentIndexIsFullRow =
false;
3133 const int lastColumn = m_columnCount - 1;
3134 if (m_it - m_begin >= lastColumn && m_it->column() == lastColumn) {
3135 const QModelIndex &firstInRow = m_it[-lastColumn];
3136 if (m_it->row() == firstInRow.row()
3137 && firstInRow.internalPointer() == m_it->internalPointer()) {
3138 m_currentIndexIsFullRow =
true;
3148 auto tmp = *
this; tmp.m_it -= n;
return tmp;
3155 void updateCurrentIndexFullRow()
3157 m_currentIndexIsFullRow =
false;
3158 if (m_it == m_end || m_it->column() || m_end - m_it < m_columnCount)
3160 const QModelIndex &lastInRow = m_it[m_columnCount - 1];
3161 m_currentIndexIsFullRow = lastInRow.row() == m_it->row()
3162 && lastInRow.internalPointer() == m_it->internalPointer();
3166 base_iterator m_begin;
3167 base_iterator m_end;
3169 int m_columnCount = 0;
3170 bool m_currentIndexIsFullRow =
false;
3188 const QModelIndex &index = *m_it;
3190 const item_type *pitem =
nullptr;
3191 const auto &row =
m_model->rowData(index);
3193 row_traits::for_element_at(QRangeModelDetails::refTo(row), index.column(),
3194 [&pitem](
const auto &item){
3199 if constexpr (std::disjunction_v<QRangeModelDetails::is_owning_or_raw_pointer<row_type>,
3200 QRangeModelDetails::is_owning_or_raw_pointer<item_type>>) {
3204 constexpr bool is_constexpr_default_constructible_v =
3205 value_type::
template is_constexpr_default_constructible<item_type>::value;
3206 if constexpr (is_constexpr_default_constructible_v) {
3207 Q_CONSTINIT
static const item_type emptyDefault;
3208 return {emptyDefault, index};
3211 static const item_type emptyDefault;
3212 return {emptyDefault, index};
3217 return {*pitem, index};
3227 auto tmp = *
this; tmp.m_it -= n;
return tmp;
3237 template <
typename Iterator>
3253 QMimeData *result =
nullptr;
3254 using RowOptions = QRangeModelDetails::QRangeModelRowOptions<wrapped_row_type>;
3255 using ItemType = QRangeModelDetails::wrapped_t<
typename row_traits::item_type>;
3257 if constexpr (QRangeModelDetails::item_access<ItemType>::hasMimeData) {
3258 using ItemAccess = QRangeModelDetails::QRangeModelItemAccess<ItemType>;
3261 result = ItemAccess::mimeData(MimeDataRange<MimeDataItemIterator>{begin, end});
3262 }
else if constexpr (QRangeModelDetails::hasMimeDataRowSpan<wrapped_row_type>) {
3263 const auto begin =
MimeDataRowIterator(indexes.begin(), indexes.begin(), indexes.end(),
this);
3264 const auto end =
MimeDataRowIterator(indexes.end(), indexes.begin(), indexes.end(),
this);
3265 result = RowOptions::mimeData(MimeDataRange<MimeDataRowIterator>{begin, end});
3266 }
else if constexpr (QRangeModelDetails::hasMimeDataIndexList<wrapped_row_type>) {
3267 result = RowOptions::mimeData(indexes);
3333 static constexpr bool modelCopied = !QRangeModelDetails::is_wrapped<Range>() &&
3334 (std::is_reference_v<Range> || std::is_const_v<std::remove_reference_t<Range>>);
3336 static constexpr bool modelShared = QRangeModelDetails::is_any_shared_ptr<Range>();
3338 static constexpr bool default_row_deleter = protocol_traits::is_default &&
3339 protocol_traits::has_deleteRow;
3341 static constexpr bool ambiguousRowOwnership = (modelCopied || modelShared) &&
3344 static_assert(!ambiguousRowOwnership,
3345 "Using of copied and shared tree and table models with rows as raw pointers, "
3346 "and the default protocol is not allowed due to ambiguity of rows ownership. "
3347 "Move the model in, use another row type, or implement a custom tree protocol.");
3349 if constexpr (protocol_traits::has_deleteRow && !std::is_pointer_v<Range>
3350 && !QRangeModelDetails::is_any_of<Range, std::reference_wrapper>()) {
3353 that().deleteRemovedRows(begin, end);
3359 if constexpr (dynamicColumns() && !row_features::has_resize) {
3363 }
else if constexpr (!protocol_traits::has_newRow) {
3366 }
else if constexpr (!range_features::has_insert_range
3367 && !std::is_copy_constructible_v<row_type>) {
3373 return Structure::canInsertRowsImpl();
3379 return Structure::canRemoveRowsImpl();
3382 template <
typename F>
3383 bool writeAt(
const QModelIndex &index, F&& writer)
3385 row_reference row = rowData(index);
3388 return row_traits::for_element_at(row, index.column(), [&writer](
auto &&target) {
3389 using target_type =
decltype(target);
3391 if constexpr (std::is_lvalue_reference_v<target_type>
3392 && !std::is_const_v<std::remove_reference_t<target_type>>) {
3393 return writer(std::forward<target_type>(target));
3400 template <
typename F>
3401 bool readAt(
const QModelIndex &index, F&& reader)
const {
3402 const_row_reference row = rowData(index);
3405 return row_traits::for_element_at(row, index.column(), std::forward<F>(reader));
3408 template <
typename Value>
3411 if constexpr (std::is_constructible_v<QVariant, Value>)
3412 return QVariant(value);
3414 return QVariant::fromValue(value);
3416 template <
typename Value>
3420 if constexpr (std::is_constructible_v<QVariant, Value *>)
3421 return QVariant(value);
3423 return read(*value);
3428 template <
typename Target>
3429 static bool write(Target &target,
const QVariant &value)
3431 using Type = std::remove_reference_t<Target>;
3432 if constexpr (std::is_constructible_v<Target, QVariant>) {
3435 }
else if (value.canConvert<Type>()) {
3436 target = value.value<Type>();
3441 template <
typename Target>
3442 static bool write(Target *target,
const QVariant &value)
3445 return write(*target, value);
3449 template <
typename ItemType>
3453 operator QMetaProperty()
const {
3454 const QByteArray roleName = that.itemModel().roleNames().value(role);
3455 const QMetaObject &mo = ItemType::staticMetaObject;
3456 if (
const int index = mo.indexOfProperty(roleName.data());
3458 return mo.property(index);
3462 const QRangeModelImpl &that;
3464 } findProperty{*
this, role};
3466 if constexpr (ModelData::cachesProperties)
3467 return *m_data.properties.tryEmplace(role, findProperty).iterator;
3469 return findProperty;
3473 const QObject *gadget,
const QMetaProperty &prop)
const
3475 if (!index.isValid())
3477 const typename ModelData::Connection connection = {gadget, role};
3478 if (prop.hasNotifySignal() &&
this->autoConnectPolicy() == AutoConnectPolicy::OnRead
3479 && !m_data.connections.contains(connection)) {
3480 if constexpr (isMutable())
3481 Self::connectProperty(index, gadget, m_data.context, role, prop);
3483 Self::connectPropertyConst(index, gadget, m_data.context, role, prop);
3484 m_data.connections.insert(connection);
3488 template <
typename ItemType>
3491 using item_type = std::remove_pointer_t<ItemType>;
3493 QMetaProperty prop = roleProperty<item_type>(role);
3494 if (!prop.isValid() && role == Qt::EditRole) {
3495 role = Qt::DisplayRole;
3496 prop = roleProperty<item_type>(Qt::DisplayRole);
3499 if (prop.isValid()) {
3500 if constexpr (itemsAreQObjects)
3501 connectPropertyOnRead(index, role, gadget, prop);
3502 result = readProperty(prop, gadget);
3507 template <
typename ItemType>
3510 return readRole(index, role, &gadget);
3513 template <
typename ItemType>
3516 if constexpr (std::is_base_of_v<QObject, ItemType>)
3517 return prop.read(gadget);
3519 return prop.readOnGadget(gadget);
3522 template <
typename ItemType>
3525 using item_type = std::remove_pointer_t<ItemType>;
3526 const QMetaObject &mo = item_type::staticMetaObject;
3527 const QMetaProperty prop = mo.property(index.column() + mo.propertyOffset());
3529 if constexpr (rowsAreQObjects)
3530 connectPropertyOnRead(index, Qt::DisplayRole, gadget, prop);
3532 return readProperty(prop, gadget);
3535 template <
typename ItemType>
3538 return readProperty(index, &gadget);
3541 template <
typename ItemType>
3542 bool writeRole(
int role, ItemType *gadget,
const QVariant &data)
3544 using item_type = std::remove_pointer_t<ItemType>;
3545 auto prop = roleProperty<item_type>(role);
3546 if (!prop.isValid() && role == Qt::EditRole)
3547 prop = roleProperty<item_type>(Qt::DisplayRole);
3549 return prop.isValid() ? writeProperty(prop, gadget, data) :
false;
3552 template <
typename ItemType>
3553 bool writeRole(
int role, ItemType &&gadget,
const QVariant &data)
3555 return writeRole(role, &gadget, data);
3558 template <
typename ItemType>
3559 static bool writeProperty(
const QMetaProperty &prop, ItemType *gadget,
const QVariant &data)
3561 if constexpr (std::is_base_of_v<QObject, ItemType>)
3562 return prop.write(gadget, data);
3564 return prop.writeOnGadget(gadget, data);
3566 template <
typename ItemType>
3569 using item_type = std::remove_pointer_t<ItemType>;
3570 const QMetaObject &mo = item_type::staticMetaObject;
3571 return writeProperty(mo.property(property + mo.propertyOffset()), gadget, data);
3574 template <
typename ItemType>
3575 static bool writeProperty(
int property, ItemType &&gadget,
const QVariant &data)
3577 return writeProperty(property, &gadget, data);
3580 template <
typename ItemType>
3583 using item_type = std::remove_pointer_t<ItemType>;
3584 const QMetaObject &mo = item_type::staticMetaObject;
3585 bool success =
true;
3586 if (property == -1) {
3588 if constexpr (std::is_base_of_v<QObject, item_type>) {
3589 for (
int p = mo.propertyOffset(); p < mo.propertyCount(); ++p)
3590 success = writeProperty(mo.property(p), object, {}) && success;
3595 success = writeProperty(mo.property(property + mo.propertyOffset()), object, {});
3600 template <
typename ItemType>
3603 return resetProperty(property, &object);
3609 Q_ASSERT(index.isValid());
3610 return that().rowDataImpl(index);
3615 Q_ASSERT(index.isValid());
3616 return that().rowDataImpl(index);
3621 if (!index.isValid())
3622 return m_data.model();
3625 return that().childRangeImpl(index);
3630 if (!index.isValid())
3631 return m_data.model();
3634 return that().childRangeImpl(index);
3645template <
typename Range,
typename Protocol>
3652 using range_type =
typename Base::range_type;
3653 using range_features =
typename Base::range_features;
3654 using row_type =
typename Base::row_type;
3655 using row_ptr =
typename Base::row_ptr;
3656 using const_row_ptr =
typename Base::const_row_ptr;
3658 using tree_traits =
typename Base::protocol_traits;
3659 static constexpr bool is_mutable_impl = tree_traits::has_mutable_childRows;
3661 static constexpr bool rows_are_any_refs_or_pointers = Base::rows_are_raw_pointers ||
3662 QRangeModelDetails::is_smart_ptr<row_type>() ||
3663 QRangeModelDetails::is_any_of<row_type,
std::reference_wrapper>();
3664 static_assert(!Base::dynamicColumns(),
"A tree must have a static number of columns!");
3668 : Base(
std::forward<Range>(model),
std::forward<Protocol>(p), itemModel)
3673 for (
auto &&child : children)
3685 auto *children =
this->childRange(parent);
3688 return autoConnectPropertiesRange(QRangeModelDetails::refTo(children), parent);
3694 if (!parent.isValid())
3695 return this->createIndex(row, column);
3697 if (parent.column())
3698 return QModelIndex();
3700 const_row_ptr grandParent =
static_cast<const_row_ptr>(parent.constInternalPointer());
3701 const auto &parentSiblings = childrenOf(grandParent);
3708 if (!child.isValid())
3712 const_row_ptr parentRow =
static_cast<const_row_ptr>(child.constInternalPointer());
3717 auto &&grandParent =
this->protocol().parentRow(
QRangeModelDetails::refTo(parentRow));
3718 const range_type &parentSiblings = childrenOf(
QRangeModelDetails::pointerTo(grandParent));
3722 const auto it =
std::find_if(begin, end, [parentRow](
auto &&s){
3726 return this->createIndex(
std::distance(begin, it), 0,
3733 return Base::size(
this->childRange(parent));
3740 return Base::fixedColumnCount();
3745 return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
3753 return (rows_are_any_refs_or_pointers || tree_traits::has_setParentRow)
3754 && Base::dynamicRows() && range_features::has_insert;
3762 return (rows_are_any_refs_or_pointers || tree_traits::has_setParentRow)
3763 && Base::dynamicRows() && range_features::has_erase;
3771 static constexpr bool canMoveRows(
const QModelIndex &,
const QModelIndex &)
3777 const QModelIndex &destParent,
int destRow)
3782 if constexpr (!rows_are_any_refs_or_pointers && !tree_traits::has_setParentRow) {
3784 }
else if constexpr (!(range_features::has_insert && range_features::has_erase)) {
3786 }
else if (!
this->beginMoveRows(sourceParent, sourceRow, sourceRow + count - 1,
3787 destParent, destRow)) {
3791 range_type *source =
this->childRange(sourceParent);
3792 range_type *destination =
this->childRange(destParent);
3797 if constexpr (range_features::has_insert_range) {
3799 const auto sourceEnd =
std::next(sourceStart, count);
3801 destination->insert(destStart,
std::move_iterator(sourceStart),
3802 std::move_iterator(sourceEnd));
3803 }
else if constexpr (
std::is_copy_constructible_v<row_type>) {
3805 destination->insert(destStart, count, row_type{});
3808 row_ptr parentRow = destParent.isValid()
3814 if (parentRow ==
static_cast<row_ptr>(sourceParent.internalPointer())) {
3815 if (sourceParent.row() < destRow) {
3816 source =
this->childRange(sourceParent);
3819 source =
this->childRange(
this->createIndex(sourceParent.row() + count, 0,
3820 sourceParent.internalPointer()));
3827 const auto writeEnd =
std::next(writeStart, count);
3829 const auto sourceEnd =
std::next(sourceStart, count);
3831 for (
auto write = writeStart, read = sourceStart; write != writeEnd; ++write, ++read) {
3834 if constexpr (!range_features::has_insert_range)
3835 *write =
std::move(*read);
3839 source->erase(sourceStart, sourceEnd);
3849 this->endMoveRows();
3857 static_assert(tree_traits::has_setParentRow);
3858 row_type empty_row =
this->protocol().newRow();
3864 template <
typename It,
typename Sentinel>
3867 if constexpr (tree_traits::has_deleteRow) {
3868 for (
auto it = begin; it != end; ++it) {
3869 if constexpr (Base::isMutable()) {
3870 decltype(
auto) children =
this->protocol().childRows(
QRangeModelDetails::refTo(*it));
3878 this->protocol().deleteRow(
std::move(*it));
3885 const auto persistentIndexList =
this->persistentIndexList();
3886 const auto [firstColumn, lastColumn] = [&persistentIndexList]{
3887 int first = std::numeric_limits<
int>::max();
3889 for (
const auto &pmi : persistentIndexList) {
3890 first = (
std::min)(pmi.column(), first);
3891 last = (
std::max)(pmi.column(), last);
3893 return std::pair(first, last);
3901 if constexpr (tree_traits::has_setParentRow && !rows_are_any_refs_or_pointers) {
3902 const bool changePersistentIndexes = pmiToColumn >= pmiFromColumn;
3905 for (
auto it = begin; it != end; ++it) {
3906 decltype(
auto) maybeChildren =
this->protocol().childRows(*it);
3912 for (
auto &child : childrenRef) {
3913 const_row_ptr oldParent =
this->protocol().parentRow(child);
3914 if (oldParent != parentRow) {
3915 if (changePersistentIndexes) {
3916 for (
int column = pmiFromColumn; column <= pmiToColumn; ++column) {
3917 this->changePersistentIndex(
this->createIndex(row, column, oldParent),
3918 this->createIndex(row, column, parentRow));
3921 this->protocol().setParentRow(child, parentRow);
3934 for (
const auto &row : range) {
3935 if (!
this->autoConnectPropertiesInRow(row, rowIndex, parent))
3940 if (!autoConnectPropertiesRange(QRangeModelDetails::refTo(children),
3941 this->itemModel().index(rowIndex, 0, parent))) {
3952 return autoConnectPropertiesRange(*
this->m_data.model(), {});
3957 const_row_ptr parentRow =
static_cast<const_row_ptr>(index.constInternalPointer());
3958 const range_type &siblings = childrenOf(parentRow);
3959 Q_ASSERT(index.row() <
int(Base::size(siblings)));
3965 row_ptr parentRow =
static_cast<row_ptr>(index.internalPointer());
3966 range_type &siblings = childrenOf(parentRow);
3967 Q_ASSERT(index.row() <
int(Base::size(siblings)));
3973 const auto &row =
this->rowData(index);
3975 return static_cast<
const range_type *>(
nullptr);
3977 decltype(
auto) children =
this->protocol().childRows(
QRangeModelDetails::refTo(row));
3983 auto &row =
this->rowData(index);
3985 return static_cast<range_type *>(
nullptr);
3987 decltype(
auto) children =
this->protocol().childRows(
QRangeModelDetails::refTo(row));
3988 using Children = std::remove_reference_t<
decltype(children)>;
3990 if constexpr (QRangeModelDetails::is_any_of<Children, std::optional>())
3991 if constexpr (std::is_default_constructible<
typename Children::value_type>()) {
3993 children.emplace(range_type{});
4002 : *
this->m_data.model();
4008 : *
this->m_data.model();
4011 template <
typename LessThan>
4014 for (
auto &row : range) {
4015 decltype(
auto) children =
this->protocol().childRows(
QRangeModelDetails::refTo(row));
4021 this->sortSubRange(range, parentRow, lessThan);
4024 template <
typename LessThan>
4027 sortImplRecursive(*
this->m_data.model(),
nullptr, lessThan);
4033 erase_if(list, [expectedParent](
const QModelIndex &index){
4034 return static_cast<row_ptr>(index.internalPointer()) != expectedParent;
4039 int role,
const QVariant &value,
int hits, Qt::MatchFlags flags,
int column,
4040 QModelIndexList &result,
const QCollator &collator)
const
4045 const bool recurse = flags.testAnyFlag(Qt::MatchRecursive);
4046 const bool allHits = (hits == -1);
4048 for (
int r = from; it != end && r < to && (allHits || result.size() < hits); ++it, ++r) {
4049 const QModelIndex index =
this->createIndex(r, column, parentPtr);
4050 if (
this->matchRow(*it, index, role, value, flags, collator))
4051 result.append(index);
4054 decltype(
auto) children =
this->protocol().childRows(
QRangeModelDetails::refTo(*it));
4057 matchImplRecursive(QRangeModelDetails::refTo(children),
4058 QRangeModelDetails::pointerTo(*it), 0,
4059 int(QRangeModelDetails::size(QRangeModelDetails::refTo(children))),
4060 role, value, hits, flags, column, result, collator);
4067 Qt::MatchFlags flags,
const QCollator &collator)
const
4069 QModelIndexList result;
4070 const bool wrap = flags.testAnyFlag(Qt::MatchWrap);
4071 const int column = start.column();
4072 const int from = start.row();
4073 const int to =
this->rowCount(start.parent());
4075 for (
int i = 0; (wrap && i < 2) || (!wrap && i < 1); ++i) {
4076 const int fromRow = (i == 0) ? from : 0;
4077 const int toRow = (i == 0) ? to : from;
4078 matchImplRecursive(*
this->m_data.model(),
nullptr, fromRow, toRow,
4079 role, value, hits, flags, column, result, collator);
4093template <
typename Range>
4100 static constexpr bool is_mutable_impl =
true;
4118 if constexpr (Base::dynamicColumns()) {
4119 if (column <
int(Base::size(*QRangeModelDetails::pos(*
this->m_data.model(), row))))
4120 return this->createIndex(row, column);
4123 qCritical(
"QRangeModel: Column-range at row %d is not large enough!", row);
4127 return this->createIndex(row, column);
4138 if (parent.isValid())
4140 return int(Base::size(*
this->m_data.model()));
4145 if (parent.isValid())
4149 if constexpr (Base::dynamicColumns()) {
4150 return int(Base::size(*
this->m_data.model()) == 0
4152 : Base::size(*QRangeModelDetails::adl_begin(*
this->m_data.model())));
4154 return Base::fixedColumnCount();
4160 return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemNeverHasChildren;
4165 return Base::dynamicRows() && range_features::has_insert;
4170 return Base::dynamicRows() && range_features::has_erase;
4173 static constexpr bool canMoveColumns(
const QModelIndex &source,
const QModelIndex &destination)
4175 return !source.isValid() && !destination.isValid();
4178 static constexpr bool canMoveRows(
const QModelIndex &source,
const QModelIndex &destination)
4180 return !source.isValid() && !destination.isValid();
4184 const QModelIndex &,
int)
noexcept
4192 row_type empty_row =
this->protocol().newRow();
4195 if constexpr (Base::dynamicColumns() && row_features::has_resize) {
4203 template <
typename It,
typename Sentinel>
4206 if constexpr (Base::protocol_traits::has_deleteRow) {
4207 for (
auto it = begin; it != end; ++it)
4208 this->protocol().deleteRow(
std::move(*it));
4214 Q_ASSERT(q20::cmp_less(index.row(), Base::size(*
this->m_data.model())));
4220 Q_ASSERT(q20::cmp_less(index.row(), Base::size(*
this->m_data.model())));
4237 return *
this->m_data.model();
4243 return *
this->m_data.model();
4254 for (
const auto &row : *
this->m_data.model()) {
4255 result &=
this->autoConnectPropertiesInRow(row, rowIndex, {});
4261 template <
typename LessThan>
4264 this->sortSubRange(*
this->m_data.model(),
nullptr, lessThan);
4270 int hits, Qt::MatchFlags flags,
const QCollator &collator)
const
4272 QModelIndexList result;
4273 const bool wrap = flags.testAnyFlag(Qt::MatchWrap);
4274 const bool allHits = (hits == -1);
4275 const int column = start.column();
4276 int from = start.row();
4277 int to =
this->rowCount({});
4278 decltype(
auto) siblings = *
this->m_data.model();
4280 for (
int i = 0; (wrap && i < 2) || (!wrap && i < 1); ++i) {
4283 for (
int r = from; it != end && r < to && (allHits || result.size() < hits);
4287 const QModelIndex index =
this->createIndex(r, column,
nullptr);
4288 if (
this->matchRow(*it, index, role, value, flags, collator))
4289 result.append(index);
4301 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
decltype(auto) clearItem(Value &&value)
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