QGIM: simplify constant for one-dimensional ranges
Introduce constant that we can check against directly rather than comparing repeatedly against 0. Change-Id: I717a5c3684d855f83ac28655b3fc2fc011b49865 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
This commit is contained in:
parent
b6782d148c
commit
29115f0d7c
@ -178,6 +178,7 @@ protected:
|
|||||||
static constexpr int static_row_count = QGenericItemModelDetails::static_size_v<range_type>;
|
static constexpr int static_row_count = QGenericItemModelDetails::static_size_v<range_type>;
|
||||||
static constexpr bool rows_are_pointers = std::is_pointer_v<row_type>;
|
static constexpr bool rows_are_pointers = std::is_pointer_v<row_type>;
|
||||||
static constexpr int static_column_count = QGenericItemModelDetails::static_size_v<row_type>;
|
static constexpr int static_column_count = QGenericItemModelDetails::static_size_v<row_type>;
|
||||||
|
static constexpr bool one_dimensional_range = static_column_count == 0;
|
||||||
|
|
||||||
static constexpr bool dynamicRows() { return isMutable() && static_row_count < 0; }
|
static constexpr bool dynamicRows() { return isMutable() && static_row_count < 0; }
|
||||||
static constexpr bool dynamicColumns() { return static_column_count < 0; }
|
static constexpr bool dynamicColumns() { return static_column_count < 0; }
|
||||||
@ -412,7 +413,7 @@ public:
|
|||||||
const_row_reference row = rowData(index);
|
const_row_reference row = rowData(index);
|
||||||
if constexpr (dynamicColumns())
|
if constexpr (dynamicColumns())
|
||||||
readData(*std::next(std::cbegin(row), index.column()));
|
readData(*std::next(std::cbegin(row), index.column()));
|
||||||
else if constexpr (static_column_count == 0)
|
else if constexpr (one_dimensional_range)
|
||||||
readData(row);
|
readData(row);
|
||||||
else if (QGenericItemModelDetails::isValid(row))
|
else if (QGenericItemModelDetails::isValid(row))
|
||||||
for_element_at(row, index.column(), readData);
|
for_element_at(row, index.column(), readData);
|
||||||
@ -475,7 +476,7 @@ public:
|
|||||||
const_row_reference row = rowData(index);
|
const_row_reference row = rowData(index);
|
||||||
if constexpr (dynamicColumns())
|
if constexpr (dynamicColumns())
|
||||||
readItemData(*std::next(std::cbegin(row), index.column()));
|
readItemData(*std::next(std::cbegin(row), index.column()));
|
||||||
else if constexpr (static_column_count == 0)
|
else if constexpr (one_dimensional_range)
|
||||||
readItemData(row);
|
readItemData(row);
|
||||||
else if (QGenericItemModelDetails::isValid(row))
|
else if (QGenericItemModelDetails::isValid(row))
|
||||||
for_element_at(row, index.column(), readItemData);
|
for_element_at(row, index.column(), readItemData);
|
||||||
@ -544,7 +545,7 @@ public:
|
|||||||
row_reference row = rowData(index);
|
row_reference row = rowData(index);
|
||||||
if constexpr (dynamicColumns()) {
|
if constexpr (dynamicColumns()) {
|
||||||
success = writeData(*std::next(std::begin(row), index.column()));
|
success = writeData(*std::next(std::begin(row), index.column()));
|
||||||
} else if constexpr (static_column_count == 0) {
|
} else if constexpr (one_dimensional_range) {
|
||||||
success = writeData(row);
|
success = writeData(row);
|
||||||
} else if (QGenericItemModelDetails::isValid(row)) {
|
} else if (QGenericItemModelDetails::isValid(row)) {
|
||||||
for_element_at(row, index.column(), [&writeData, &success](auto &&target){
|
for_element_at(row, index.column(), [&writeData, &success](auto &&target){
|
||||||
@ -656,7 +657,7 @@ public:
|
|||||||
row_reference row = rowData(index);
|
row_reference row = rowData(index);
|
||||||
if constexpr (dynamicColumns()) {
|
if constexpr (dynamicColumns()) {
|
||||||
success = writeItemData(*std::next(std::begin(row), index.column()));
|
success = writeItemData(*std::next(std::begin(row), index.column()));
|
||||||
} else if constexpr (static_column_count == 0) {
|
} else if constexpr (one_dimensional_range) {
|
||||||
success = writeItemData(row);
|
success = writeItemData(row);
|
||||||
} else if (QGenericItemModelDetails::isValid(row)) {
|
} else if (QGenericItemModelDetails::isValid(row)) {
|
||||||
for_element_at(row, index.column(), [&writeItemData, &success](auto &&target){
|
for_element_at(row, index.column(), [&writeItemData, &success](auto &&target){
|
||||||
@ -708,7 +709,7 @@ public:
|
|||||||
row_reference row = rowData(index);
|
row_reference row = rowData(index);
|
||||||
if constexpr (dynamicColumns()) {
|
if constexpr (dynamicColumns()) {
|
||||||
success = clearData(*std::next(std::begin(row), index.column()));
|
success = clearData(*std::next(std::begin(row), index.column()));
|
||||||
} else if constexpr (static_column_count == 0) {
|
} else if constexpr (one_dimensional_range) {
|
||||||
success = clearData(row);
|
success = clearData(row);
|
||||||
} else if (QGenericItemModelDetails::isValid(row)) {
|
} else if (QGenericItemModelDetails::isValid(row)) {
|
||||||
for_element_at(row, index.column(), [&clearData, &success](auto &&target){
|
for_element_at(row, index.column(), [&clearData, &success](auto &&target){
|
||||||
@ -1342,7 +1343,7 @@ protected:
|
|||||||
return int(Base::size(*this->m_data.model()) == 0
|
return int(Base::size(*this->m_data.model()) == 0
|
||||||
? 0
|
? 0
|
||||||
: Base::size(*std::cbegin(*this->m_data.model())));
|
: Base::size(*std::cbegin(*this->m_data.model())));
|
||||||
} else if constexpr (Base::static_column_count == 0) {
|
} else if constexpr (Base::one_dimensional_range) {
|
||||||
return row_traits::fixed_size();
|
return row_traits::fixed_size();
|
||||||
} else {
|
} else {
|
||||||
return Base::static_column_count;
|
return Base::static_column_count;
|
||||||
|
@ -193,7 +193,9 @@ namespace QGenericItemModelDetails
|
|||||||
template <typename T, typename = void>
|
template <typename T, typename = void>
|
||||||
struct row_traits {
|
struct row_traits {
|
||||||
static constexpr bool is_range = is_range_v<q20::remove_cvref_t<T>>;
|
static constexpr bool is_range = is_range_v<q20::remove_cvref_t<T>>;
|
||||||
// a static size of -1 indicates dynamically sized range
|
// A static size of -1 indicates dynamically sized range
|
||||||
|
// A static size of 0 indicates that the specified type doesn't
|
||||||
|
// represent static or dynamic range.
|
||||||
static constexpr int static_size = is_range ? -1 : 0;
|
static constexpr int static_size = is_range ? -1 : 0;
|
||||||
static constexpr int fixed_size() { return 1; }
|
static constexpr int fixed_size() { return 1; }
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user