summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorVolker Hilsheimer <[email protected]>2025-12-10 10:53:28 +0100
committerVolker Hilsheimer <[email protected]>2025-12-12 00:11:11 +0100
commit8bf53bb39855444dbfa37c4797dd23096778fb15 (patch)
treea183d947105aec9f24a132d0da02c7fd472751bc /src
parentcfc555bc4d35fc460fd8f963e7ed50f0dd2cb4e4 (diff)
QRMA: try to constrain the data source for insertColumn(s)
insertColumn can insert a data element, or a range of data elements, which then inserts one element from the source range for each row. insertColumns can insert a range of data elements (which is then the data inserted into each row), or a range of ranges of data elements (in which case we insert one range from the source for each row). Try to constrain this by inspecting the input data type, and allowing only compatible data elements, as well as ranges holding compatible data elements. Make the API test more specific - test with lists of integers, so that we can confirm that such input data wouldn't be allowed to add columns to a model holding pointers. Pick-to: 6.11 Change-Id: I1b67510b3f70f147530a3ae453b01328f2e639d2 Reviewed-by: Artem Dyomin <[email protected]>
Diffstat (limited to 'src')
-rw-r--r--src/corelib/itemmodels/qrangemodeladapter.h20
-rw-r--r--src/corelib/itemmodels/qrangemodeladapter.qdoc4
2 files changed, 15 insertions, 9 deletions
diff --git a/src/corelib/itemmodels/qrangemodeladapter.h b/src/corelib/itemmodels/qrangemodeladapter.h
index 593fcd766a2..0234c402248 100644
--- a/src/corelib/itemmodels/qrangemodeladapter.h
+++ b/src/corelib/itemmodels/qrangemodeladapter.h
@@ -76,16 +76,22 @@ class QT_TECH_PREVIEW_API QRangeModelAdapter
template <typename C>
using if_compatible_row_range = std::enable_if_t<is_compatible_row_range<C>, bool>;
template <typename Data>
- static constexpr bool is_compatible_data = true;
- // std::is_convertible_v<Data, decltype(*std::begin(std::declval<const_row_reference>()))>;
+ static constexpr bool is_compatible_data = std::is_convertible_v<Data, data_type>;
template <typename Data>
using if_compatible_data = std::enable_if_t<is_compatible_data<Data>, bool>;
template <typename C>
static constexpr bool is_compatible_data_range = is_compatible_data<
+ typename QRangeModelDetails::data_type<
+ typename QRangeModelDetails::row_traits<
decltype(*std::begin(std::declval<C&>()))
- >;
+ >::item_type
+ >::type
+ >;
+ template <typename C>
+ using if_compatible_column_data = std::enable_if_t<is_compatible_data<C>
+ || is_compatible_data_range<C>, bool>;
template <typename C>
- using if_compatible_data_range = std::enable_if_t<is_compatible_data_range<C>, bool>;
+ using if_compatible_column_range = std::enable_if_t<is_compatible_data_range<C>, bool>;
template <typename R>
using if_assignable_range = std::enable_if_t<std::is_assignable_v<range_type, R>, bool>;
@@ -1443,15 +1449,15 @@ public:
return storage.m_model->insertColumn(before);
}
- template <typename D = row_type, typename I = Impl,
- if_canInsertColumns<I> = true, if_compatible_data<D> = true>
+ template <typename D, typename I = Impl,
+ if_canInsertColumns<I> = true, if_compatible_column_data<D> = true>
bool insertColumn(int before, D &&data)
{
return insertColumnImpl(before, storage.root(), std::forward<D>(data));
}
template <typename C, typename I = Impl,
- if_canInsertColumns<I> = true, if_compatible_data_range<C> = true>
+ if_canInsertColumns<I> = true, if_compatible_column_range<C> = true>
bool insertColumns(int before, C &&data)
{
return insertColumnsImpl(before, storage.root(), std::forward<C>(data));
diff --git a/src/corelib/itemmodels/qrangemodeladapter.qdoc b/src/corelib/itemmodels/qrangemodeladapter.qdoc
index 721c8c92da1..88872589299 100644
--- a/src/corelib/itemmodels/qrangemodeladapter.qdoc
+++ b/src/corelib/itemmodels/qrangemodeladapter.qdoc
@@ -835,7 +835,7 @@
*/
/*!
- \fn template <typename Range, typename Protocol, typename Model> template <typename D, typename I, QRangeModelAdapter<Range, Protocol, Model>::if_canInsertColumns<I>, QRangeModelAdapter<Range, Protocol, Model>::if_compatible_data<D>> bool QRangeModelAdapter<Range, Protocol, Model>::insertColumn(int before, D &&data)
+ \fn template <typename Range, typename Protocol, typename Model> template <typename D, typename I, QRangeModelAdapter<Range, Protocol, Model>::if_canInsertColumns<I>, QRangeModelAdapter<Range, Protocol, Model>::if_compatible_column_data<D>> bool QRangeModelAdapter<Range, Protocol, Model>::insertColumn(int before, D &&data)
\overload
Inserts a single column constructed from \a data before the column specified
@@ -863,7 +863,7 @@
*/
/*!
- \fn template <typename Range, typename Protocol, typename Model> template <typename C, typename I, QRangeModelAdapter<Range, Protocol, Model>::if_canInsertColumns<I>, QRangeModelAdapter<Range, Protocol, Model>::if_compatible_data_range<C>> bool QRangeModelAdapter<Range, Protocol, Model>::insertColumns(int before, C &&data)
+ \fn template <typename Range, typename Protocol, typename Model> template <typename C, typename I, QRangeModelAdapter<Range, Protocol, Model>::if_canInsertColumns<I>, QRangeModelAdapter<Range, Protocol, Model>::if_compatible_column_range<C>> bool QRangeModelAdapter<Range, Protocol, Model>::insertColumns(int before, C &&data)
Inserts columns constructed from the elements in \a data before the column
specified by \a before into all rows, and returns whether the insertion was