44 #ifndef QT_NO_SORTFILTERPROXYMODEL 52 #include <private/qabstractitemmodel_p.h> 53 #include <private/qabstractproxymodel_p.h> 63 for(
int i=0; i < vector.
size(); ++i)
130 if (parent == parent_source)
131 return row >= start && row <=
end;
191 static_cast<const Mapping*
>(p)->map_iter;
200 return q_func()->createIndex(row, column, *it);
203 void _q_sourceDataChanged(
const QModelIndex &source_top_left,
207 void _q_sourceAboutToBeReset();
208 void _q_sourceReset();
210 void _q_sourceLayoutAboutToBeChanged();
211 void _q_sourceLayoutChanged();
215 void _q_sourceRowsInserted(
const QModelIndex &source_parent,
217 void _q_sourceRowsAboutToBeRemoved(
const QModelIndex &source_parent,
219 void _q_sourceRowsRemoved(
const QModelIndex &source_parent,
221 void _q_sourceColumnsAboutToBeInserted(
const QModelIndex &source_parent,
223 void _q_sourceColumnsInserted(
const QModelIndex &source_parent,
225 void _q_sourceColumnsAboutToBeRemoved(
const QModelIndex &source_parent,
227 void _q_sourceColumnsRemoved(
const QModelIndex &source_parent,
230 void _q_clearMapping();
233 bool update_source_sort_column();
241 void insert_source_items(
245 void remove_source_items(
249 void remove_proxy_interval(
251 int proxy_start,
int proxy_end,
const QModelIndex &proxy_parent,
253 void build_source_to_proxy_mapping(
255 void source_items_inserted(
const QModelIndex &source_parent,
257 void source_items_about_to_be_removed(
const QModelIndex &source_parent,
259 void source_items_removed(
const QModelIndex &source_parent,
261 void proxy_item_range(
263 int &proxy_low,
int &proxy_high)
const;
274 Qt::Orientation orient,
int start,
int end,
int delta_item_count,
bool remove);
276 virtual void _q_sourceModelDestroyed();
289 if (
Mapping *m = source_index_mapping.take(source_parent)) {
290 for (
int i = 0; i < m->mapped_children.size(); ++i)
291 remove_from_mapping(m->mapped_children.at(i));
302 source_index_mapping.clear();
303 if (dynamic_sortfilter && update_source_sort_column()) {
306 source_index_mapping.clear();
310 update_persistent_indexes(source_indexes);
319 if (it != source_index_mapping.constEnd())
324 int source_rows = model->rowCount(source_parent);
326 for (
int i = 0; i < source_rows; ++i) {
327 if (q->filterAcceptsRow(i, source_parent))
330 int source_cols = model->columnCount(source_parent);
332 for (
int i = 0; i < source_cols; ++i) {
333 if (q->filterAcceptsColumn(i, source_parent))
349 Q_ASSERT(it2 != source_index_mapping.constEnd());
350 it2.value()->mapped_children.append(source_parent);
353 Q_ASSERT(it != source_index_mapping.constEnd());
363 if (proxy_index.
model() != q_func()) {
364 qWarning() <<
"QSortFilterProxyModel: index from wrong model passed to mapToSource";
365 Q_ASSERT(!
"QSortFilterProxyModel: index from wrong model passed to mapToSource");
374 return model->index(source_row, source_col, it.key());
381 if (source_index.
model() != model) {
382 qWarning() <<
"QSortFilterProxyModel: index from wrong model passed to mapFromSource";
383 Q_ASSERT(!
"QSortFilterProxyModel: index from wrong model passed to mapFromSource");
393 if (proxy_row == -1 || proxy_column == -1)
395 return create_index(proxy_row, proxy_column, it);
403 if (it == source_index_mapping.constEnd()) {
428 emit q->layoutAboutToBeChanged();
431 for (; it != source_index_mapping.constEnd(); ++
it) {
437 update_persistent_indexes(source_indexes);
438 emit q->layoutChanged();
451 int old_source_sort_colum = source_sort_column;
452 source_sort_column = q->mapToSource(proxy_index).
column();
453 return old_source_sort_colum != source_sort_column;
469 if (source_sort_column >= 0) {
501 return proxy_intervals;
503 int source_items_index = 0;
504 while (source_items_index < source_items.
size()) {
505 int first_proxy_item = source_to_proxy.
at(source_items.
at(source_items_index));
507 int last_proxy_item = first_proxy_item;
508 ++source_items_index;
510 while ((source_items_index < source_items.
size())
511 && (source_to_proxy.
at(source_items.
at(source_items_index)) == last_proxy_item + 1)) {
513 ++source_items_index;
519 return proxy_intervals;
539 QModelIndex proxy_parent = q->mapFromSource(source_parent);
544 proxy_intervals = proxy_intervals_for_source_items(source_to_proxy, source_items);
546 for (
int i = proxy_intervals.
size()-1; i >= 0; --i) {
548 int proxy_start = interval.
first;
549 int proxy_end = interval.
second;
550 remove_proxy_interval(source_to_proxy, proxy_to_source, proxy_start, proxy_end,
551 proxy_parent, orient, emit_signal);
572 q->beginRemoveRows(proxy_parent, proxy_start, proxy_end);
574 q->beginRemoveColumns(proxy_parent, proxy_start, proxy_end);
578 proxy_to_source.
remove(proxy_start, proxy_end - proxy_start + 1);
580 build_source_to_proxy_mapping(proxy_to_source, source_to_proxy);
586 q->endRemoveColumns();
612 return proxy_intervals;
616 int source_items_index = 0;
619 while (source_items_index < source_items.
size()) {
620 source_items_in_interval.
clear();
621 int first_new_source_item = source_items.
at(source_items_index);
622 source_items_in_interval.
append(first_new_source_item);
623 ++source_items_index;
626 int proxy_high = proxy_to_source.
size() - 1;
627 QModelIndex i1 = compare ? model->index(first_new_source_item, source_sort_column, source_parent) :
QModelIndex();
628 while (proxy_low <= proxy_high) {
629 proxy_item = (proxy_low + proxy_high) / 2;
633 proxy_high = proxy_item - 1;
635 proxy_low = proxy_item + 1;
637 if (first_new_source_item < proxy_to_source.
at(proxy_item))
638 proxy_high = proxy_item - 1;
640 proxy_low = proxy_item + 1;
643 proxy_item = proxy_low;
646 if (proxy_item >= proxy_to_source.
size()) {
647 for ( ; source_items_index < source_items.
size(); ++source_items_index)
648 source_items_in_interval.
append(source_items.
at(source_items_index));
651 for ( ; source_items_index < source_items.
size(); ++source_items_index) {
652 int new_source_item = source_items.
at(source_items_index);
654 QModelIndex i2 = model->index(new_source_item, source_sort_column, source_parent);
658 if (proxy_to_source.
at(proxy_item) < new_source_item)
661 source_items_in_interval.
append(new_source_item);
668 return proxy_intervals;
688 QModelIndex proxy_parent = q->mapFromSource(source_parent);
693 proxy_intervals = proxy_intervals_for_source_items_to_add(
694 proxy_to_source, source_items, source_parent, orient);
696 for (
int i = proxy_intervals.
size()-1; i >= 0; --i) {
698 int proxy_start = interval.
first;
700 int proxy_end = proxy_start + source_items.
size() - 1;
704 q->beginInsertRows(proxy_parent, proxy_start, proxy_end);
706 q->beginInsertColumns(proxy_parent, proxy_start, proxy_end);
709 for (
int i = 0; i < source_items.
size(); ++i)
710 proxy_to_source.
insert(proxy_start + i, source_items.
at(i));
712 build_source_to_proxy_mapping(proxy_to_source, source_to_proxy);
718 q->endInsertColumns();
742 if ((start < 0) || (end < 0))
745 if (it == source_index_mapping.constEnd()) {
746 if (!can_create_mapping(source_parent))
748 it = create_mapping(source_parent);
750 QModelIndex proxy_parent = q->mapFromSource(source_parent);
757 q->endInsertColumns();
766 int delta_item_count = end - start + 1;
767 int old_item_count = source_to_proxy.
size();
769 updateChildrenMapping(source_parent, m, orient, start, end, delta_item_count,
false);
772 if (start < 0 || start > source_to_proxy.
size()) {
773 qWarning(
"QSortFilterProxyModel: invalid inserted rows reported by source model");
774 remove_from_mapping(source_parent);
777 source_to_proxy.
insert(start, delta_item_count, -1);
779 if (start < old_item_count) {
781 int proxy_count = proxy_to_source.size();
782 for (
int proxy_item = 0; proxy_item < proxy_count; ++proxy_item) {
783 int source_item = proxy_to_source.at(proxy_item);
784 if (source_item >= start)
785 proxy_to_source.replace(proxy_item, source_item + delta_item_count);
787 build_source_to_proxy_mapping(proxy_to_source, source_to_proxy);
792 for (
int i = start; i <=
end; ++i) {
794 ? q->filterAcceptsRow(i, source_parent)
795 : q->filterAcceptsColumn(i, source_parent)) {
800 if (model->rowCount(source_parent) == delta_item_count) {
808 if (orthogonal_source_to_proxy.isEmpty()) {
809 const int ortho_end = (orient ==
Qt::Horizontal) ? model->rowCount(source_parent) : model->columnCount(source_parent);
811 orthogonal_source_to_proxy.
resize(ortho_end);
813 for (
int ortho_item = 0; ortho_item < ortho_end; ++ortho_item) {
814 if ((orient ==
Qt::Horizontal) ? q->filterAcceptsRow(ortho_item, source_parent)
815 : q->filterAcceptsColumn(ortho_item, source_parent)) {
816 orthogonal_proxy_to_source.
append(ortho_item);
821 sort_source_rows(orthogonal_proxy_to_source, source_parent);
823 build_source_to_proxy_mapping(orthogonal_proxy_to_source, orthogonal_source_to_proxy);
829 sort_source_rows(source_items, source_parent);
830 insert_source_items(source_to_proxy, proxy_to_source, source_items, source_parent, orient);
845 if ((start < 0) || (end < 0))
848 if (it == source_index_mapping.constEnd()) {
859 int proxy_count = proxy_to_source.
size();
860 for (
int proxy_item = 0; proxy_item < proxy_count; ++proxy_item) {
861 int source_item = proxy_to_source.at(proxy_item);
862 if ((source_item >= start) && (source_item <= end))
863 source_items_to_remove.
append(source_item);
866 remove_source_items(source_to_proxy, proxy_to_source, source_items_to_remove,
867 source_parent, orient);
881 if ((start < 0) || (end < 0))
884 if (it == source_index_mapping.constEnd()) {
893 if (end >= source_to_proxy.
size())
894 end = source_to_proxy.
size() - 1;
897 int delta_item_count = end - start + 1;
898 source_to_proxy.
remove(start, delta_item_count);
900 int proxy_count = proxy_to_source.size();
901 if (proxy_count > source_to_proxy.
size()) {
903 qWarning(
"QSortFilterProxyModel: inconsistent changes reported by source model");
904 remove_from_mapping(source_parent);
911 for (
int proxy_item = 0; proxy_item < proxy_count; ++proxy_item) {
912 int source_item = proxy_to_source.at(proxy_item);
913 if (source_item >= start) {
914 Q_ASSERT(source_item - delta_item_count >= 0);
915 proxy_to_source.replace(proxy_item, source_item - delta_item_count);
918 build_source_to_proxy_mapping(proxy_to_source, source_to_proxy);
920 updateChildrenMapping(source_parent, m, orient, start, end, delta_item_count,
true);
938 ? source_child_index.
row()
939 : source_child_index.
column();
943 }
else if (
remove && pos <= end) {
946 remove_from_mapping(source_child_index);
950 const int newpos =
remove ? pos - delta_item_count : pos + delta_item_count;
952 new_index = model->index(newpos,
953 source_child_index.
column(),
956 new_index = model->index(source_child_index.
row(),
964 Mapping *cm = source_index_mapping.take(source_child_index);
973 for (; it != moved_source_index_mappings.
end(); ++
it) {
974 #ifdef QT_STRICT_ITERATORS 975 source_index_mapping.insert((*it).first, (*it).second);
976 (*it).second->map_iter = source_index_mapping.constFind((*it).first);
978 (*it).second->map_iter = source_index_mapping.insert((*it).first, (*it).second);
988 int &proxy_low,
int &proxy_high)
const 991 proxy_high = INT_MIN;
992 for (
int i = 0; i < source_items.
count(); ++i) {
993 int proxy_item = source_to_proxy.
at(source_items.
at(i));
995 if (proxy_item < proxy_low)
996 proxy_low = proxy_item;
997 if (proxy_item > proxy_high)
998 proxy_high = proxy_item;
1008 source_to_proxy.
fill(-1);
1009 int proxy_count = proxy_to_source.
size();
1010 for (
int i = 0; i < proxy_count; ++i)
1011 source_to_proxy[proxy_to_source.
at(i)] = i;
1029 QModelIndex source_index = q->mapToSource(proxy_index);
1032 return source_indexes;
1049 for (
int i = 0; i < source_indexes.
count(); ++i) {
1052 create_mapping(source_index.
parent());
1053 QModelIndex proxy_index = q->mapFromSource(source_index);
1054 from << old_proxy_index;
1057 q->changePersistentIndexList(from, to);
1073 if (it == source_index_mapping.constEnd())
1085 for (
int i = 0; i < mappedChildren.
size(); ++i) {
1086 const QModelIndex source_child_index = mappedChildren.
at(i);
1089 remove_from_mapping(source_child_index);
1091 filter_changed(source_child_index);
1102 while (removeIt != removeBegin) {
1119 for (
int i = 0; i < proxy_to_source.
count(); ++i) {
1120 const int source_item = proxy_to_source.
at(i);
1122 ? !q->filterAcceptsRow(source_item, source_parent)
1123 : !q->filterAcceptsColumn(source_item, source_parent)) {
1125 source_items_remove.
append(source_item);
1130 int source_count = source_to_proxy.
size();
1131 for (
int source_item = 0; source_item < source_count; ++source_item) {
1132 if (source_to_proxy.
at(source_item) == -1) {
1134 ? q->filterAcceptsRow(source_item, source_parent)
1135 : q->filterAcceptsColumn(source_item, source_parent)) {
1137 source_items_insert.
append(source_item);
1141 if (!source_items_remove.
isEmpty() || !source_items_insert.
isEmpty()) {
1143 remove_source_items(source_to_proxy, proxy_to_source,
1144 source_items_remove, source_parent, orient);
1146 sort_source_rows(source_items_insert, source_parent);
1147 insert_source_items(source_to_proxy, proxy_to_source,
1148 source_items_insert, source_parent, orient);
1157 if (!source_top_left.
isValid() || !source_bottom_right.
isValid())
1161 if (it == source_index_mapping.constEnd()) {
1173 for (
int source_row = source_top_left.
row(); source_row <=
end; ++source_row) {
1174 if (dynamic_sortfilter) {
1176 if (!q->filterAcceptsRow(source_row, source_parent)) {
1178 source_rows_remove.
append(source_row);
1179 }
else if (source_sort_column >= source_top_left.
column() && source_sort_column <= source_bottom_right.
column()) {
1181 source_rows_resort.
append(source_row);
1184 source_rows_change.
append(source_row);
1187 if (!itemsBeingRemoved.contains(source_parent, source_row) && q->filterAcceptsRow(source_row, source_parent)) {
1189 source_rows_insert.
append(source_row);
1194 source_rows_change.
append(source_row);
1198 if (!source_rows_remove.
isEmpty()) {
1206 if (source_rows_remove_set.
contains(source_child_index.
row())) {
1208 remove_from_mapping(source_child_index);
1213 if (!source_rows_resort.
isEmpty()) {
1215 emit q->layoutAboutToBeChanged();
1219 sort_source_rows(source_rows_resort, source_parent);
1222 update_persistent_indexes(source_indexes);
1223 emit q->layoutChanged();
1225 source_rows_change += source_rows_resort;
1228 if (!source_rows_change.
isEmpty()) {
1230 int proxy_start_row;
1232 proxy_item_range(m->
proxy_rows, source_rows_change,
1233 proxy_start_row, proxy_end_row);
1235 if (proxy_end_row >= 0) {
1237 int source_left_column = source_top_left.
column();
1238 while (source_left_column < source_bottom_right.
column()
1240 ++source_left_column;
1243 int source_right_column = source_bottom_right.
column();
1244 while (source_right_column > source_top_left.
column()
1246 --source_right_column;
1247 const QModelIndex proxy_bottom_right = create_index(
1249 emit q->dataChanged(proxy_top_left, proxy_bottom_right);
1253 if (!source_rows_insert.
isEmpty()) {
1254 sort_source_rows(source_rows_insert, source_parent);
1271 emit q->headerDataChanged(orientation, proxy_start, proxy_end);
1277 q->beginResetModel();
1283 invalidatePersistentIndexes();
1287 update_source_sort_column();
1288 if (dynamic_sortfilter)
1295 saved_persistent_indexes.clear();
1296 emit q->layoutAboutToBeChanged();
1297 if (persistent.indexes.isEmpty())
1300 saved_persistent_indexes = store_persistent_indexes();
1308 source_index_mapping.clear();
1310 update_persistent_indexes(saved_persistent_indexes);
1311 saved_persistent_indexes.clear();
1313 if (dynamic_sortfilter && update_source_sort_column()) {
1316 source_index_mapping.clear();
1319 emit q->layoutChanged();
1329 if (can_create_mapping(source_parent))
1330 create_mapping(source_parent);
1336 source_items_inserted(source_parent, start, end,
Qt::Vertical);
1337 if (update_source_sort_column() && dynamic_sortfilter)
1344 itemsBeingRemoved =
QRowsRemoval(source_parent, start, end);
1345 source_items_about_to_be_removed(source_parent, start, end,
1353 source_items_removed(source_parent, start, end,
Qt::Vertical);
1363 if (can_create_mapping(source_parent))
1364 create_mapping(source_parent);
1371 source_items_inserted(source_parent, start, end,
Qt::Horizontal);
1375 if (source_sort_column == -1) {
1377 if (update_source_sort_column() && dynamic_sortfilter)
1380 if (start <= source_sort_column)
1381 source_sort_column += end - start + 1;
1383 proxy_sort_column = q->mapFromSource(model->index(0,source_sort_column, source_parent)).column();
1390 source_items_about_to_be_removed(source_parent, start, end,
1402 if (start <= source_sort_column) {
1403 if (end < source_sort_column)
1404 source_sort_column -= end - start + 1;
1406 source_sort_column = -1;
1409 proxy_sort_column = q->mapFromSource(model->index(0,source_sort_column, source_parent)).column();
1573 d->proxy_sort_column =
d->source_sort_column = -1;
1577 d->sort_localeaware =
false;
1578 d->filter_column = 0;
1580 d->dynamic_sortfilter =
false;
1591 d->source_index_mapping.clear();
1634 this,
SLOT(_q_sourceLayoutAboutToBeChanged()));
1637 this,
SLOT(_q_sourceLayoutChanged()));
1675 this,
SLOT(_q_sourceLayoutAboutToBeChanged()));
1678 this,
SLOT(_q_sourceLayoutChanged()));
1683 d->_q_clearMapping();
1685 if (
d->update_source_sort_column() &&
d->dynamic_sortfilter)
1695 if (row < 0 || column < 0)
1700 if (it.value()->source_rows.count() <= row || it.value()->source_columns.count() <= column)
1703 return d->create_index(row, column, it);
1712 if (!
d->indexValid(child))
1715 Q_ASSERT(it !=
d->source_index_mapping.constEnd());
1718 return proxy_parent;
1731 return it.value()->source_rows.count();
1744 return it.value()->source_columns.count();
1756 if (!
d->model->hasChildren(source_parent))
1759 if (
d->model->canFetchMore(source_parent))
1775 return d->model->data(source_index, role);
1787 return d->model->setData(source_index, value, role);
1797 if (it.value()->source_rows.count() * it.value()->source_columns.count() > 0)
1801 if (section < 0 || section >= it.value()->source_rows.count())
1803 source_section = it.
value()->source_rows.at(section);
1805 if (section < 0 || section >= it.value()->source_columns.count())
1807 source_section = it.
value()->source_columns.at(section);
1809 return d->model->headerData(source_section, orientation, role);
1820 if (it.value()->source_rows.count() * it.value()->source_columns.count() > 0)
1824 if (section < 0 || section >= it.value()->source_rows.count())
1826 source_section = it.value()->source_rows.at(section);
1828 if (section < 0 || section >= it.value()->source_columns.count())
1830 source_section = it.value()->source_columns.at(section);
1832 return d->model->setHeaderData(source_section, orientation, value, role);
1842 for (
int i = 0; i < indexes.
count(); ++i)
1844 return d->model->mimeData(source_indexes);
1853 return d->model->mimeTypes();
1862 return d->model->supportedDropActions();
1872 if ((row == -1) && (column == -1))
1873 return d->model->dropMimeData(data, action, -1, -1,
mapToSource(parent));
1874 int source_destination_row = -1;
1875 int source_destination_column = -1;
1879 source_destination_row =
d->model->rowCount(source_parent);
1883 source_destination_row = source_index.
row();
1884 source_destination_column = source_index.
column();
1885 source_parent = source_index.
parent();
1887 return d->model->dropMimeData(data, action, source_destination_row,
1888 source_destination_column, source_parent);
1897 if (row < 0 || count <= 0)
1908 return d->model->insertRows(source_row, count, source_parent);
1917 if (column < 0|| count <= 0)
1928 return d->model->insertColumns(source_column, count, source_parent);
1937 if (row < 0 || count <= 0)
1948 return d->model->removeRows(source_row, count, source_parent);
1953 for (
int i = row; i < row + count; ++i)
1957 int pos = rows.
count() - 1;
1960 const int source_end = rows.
at(pos--);
1961 int source_start = source_end;
1962 while ((pos >= 0) && (rows.
at(pos) == (source_start - 1))) {
1966 ok = ok &&
d->model->removeRows(source_start, source_end - source_start + 1,
1978 if (column < 0 || count <= 0)
1988 return d->model->removeColumns(source_column, count, source_parent);
1992 for (
int i = column; i < column + count; ++i)
1995 int pos = columns.
count() - 1;
1998 const int source_end = columns.
at(pos--);
1999 int source_start = source_end;
2000 while ((pos >= 0) && (columns.
at(pos) == (source_start - 1))) {
2004 ok = ok &&
d->model->removeColumns(source_start, source_end - source_start + 1,
2017 if (
d->indexValid(parent))
2019 d->model->fetchMore(source_parent);
2029 if (
d->indexValid(parent))
2031 return d->model->canFetchMore(source_parent);
2041 if (
d->indexValid(index))
2043 return d->model->flags(source_index);
2052 if (!
d->indexValid(index))
2055 QModelIndex source_buddy =
d->model->buddy(source_index);
2056 if (source_index == source_buddy)
2066 Qt::MatchFlags
flags)
const 2080 return d->model->span(source_index);
2089 if (
d->dynamic_sortfilter &&
d->proxy_sort_column == column &&
d->sort_order == order)
2091 d->sort_order = order;
2092 d->proxy_sort_column = column;
2093 d->update_source_sort_column();
2109 return d->proxy_sort_column;
2124 return d->sort_order;
2146 return d->filter_regexp;
2152 d->filter_regexp = regExp;
2153 d->filter_changed();
2170 return d->filter_column;
2176 d->filter_column = column;
2177 d->filter_changed();
2196 return d->filter_regexp.caseSensitivity();
2202 if (cs ==
d->filter_regexp.caseSensitivity())
2204 d->filter_regexp.setCaseSensitivity(cs);
2205 d->filter_changed();
2223 return d->sort_casesensitivity;
2229 if (
d->sort_casesensitivity == cs)
2232 d->sort_casesensitivity = cs;
2251 return d->sort_localeaware;
2257 if (
d->sort_localeaware == on)
2260 d->sort_localeaware = on;
2279 d->filter_regexp.setPattern(pattern);
2280 d->filter_changed();
2293 d->filter_regexp.setPattern(pattern);
2294 d->filter_changed();
2307 d->filter_regexp.setPattern(pattern);
2308 d->filter_changed();
2333 return d->dynamic_sortfilter;
2339 d->dynamic_sortfilter = enable;
2359 return d->sort_role;
2365 if (
d->sort_role == role)
2367 d->sort_role = role;
2386 return d->filter_role;
2392 if (
d->filter_role == role)
2394 d->filter_role = role;
2395 d->filter_changed();
2410 d->_q_clearMapping();
2428 d->_q_clearMapping();
2443 d->filter_changed();
2462 d->filter_changed();
2531 if (
d->sort_localeaware)
2556 if (
d->filter_regexp.isEmpty())
2558 if (
d->filter_column == -1) {
2559 int column_count =
d->model->columnCount(source_parent);
2560 for (
int column = 0; column < column_count; ++column) {
2561 QModelIndex source_index =
d->model->index(source_row, column, source_parent);
2562 QString key =
d->model->data(source_index,
d->filter_role).toString();
2568 QModelIndex source_index =
d->model->index(source_row,
d->filter_column, source_parent);
2571 QString key =
d->model->data(source_index,
d->filter_role).toString();
2603 return d->proxy_to_source(proxyIndex);
2615 return d->source_to_proxy(sourceIndex);
2641 #include "moc_qsortfilterproxymodel.cpp" 2643 #endif // QT_NO_SORTFILTERPROXYMODEL The QVariant class acts like a union for the most common Qt data types.
void source_items_inserted(const QModelIndex &source_parent, int start, int end, Qt::Orientation orient)
Handles source model items insertion (columnsInserted(), rowsInserted()).
QBool contains(QChar c, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
virtual QModelIndexList match(const QModelIndex &start, int role, const QVariant &value, int hits=1, Qt::MatchFlags flags=Qt::MatchFlags(Qt::MatchStartsWith|Qt::MatchWrap)) const
Returns a list of indexes for the items in the column of the start index where data stored under the ...
void * internalPointer() const
Returns a void * pointer used by the model to associate the index with the internal data structure...
QModelIndexPairList store_persistent_indexes()
Maps the persistent proxy indexes to source indexes and returns the list of source indexes...
void _q_sourceColumnsInserted(const QModelIndex &source_parent, int start, int end)
The QHash::const_iterator class provides an STL-style const iterator for QHash and QMultiHash...
Qt::CaseSensitivity sort_casesensitivity
bool isSortLocaleAware() const
void _q_sourceRowsAboutToBeRemoved(const QModelIndex &source_parent, int start, int end)
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
#define QT_END_NAMESPACE
This macro expands to.
QModelIndex mapToSource(const QModelIndex &proxyIndex) const
Returns the source model index corresponding to the given proxyIndex from the sorting filter model...
void _q_sourceColumnsRemoved(const QModelIndex &source_parent, int start, int end)
bool operator()(int r1, int r2) const
void proxy_item_range(const QVector< int > &source_to_proxy, const QVector< int > &source_items, int &proxy_low, int &proxy_high) const
void remove(int i)
Removes the element at index position i.
The QRegExp class provides pattern matching using regular expressions.
void setSortRole(int role)
QHash< QModelIndex, QSortFilterProxyModelPrivate::Mapping * > IndexMap
QVector< T > & fill(const T &t, int size=-1)
Assigns value to all items in the vector.
void setFilterWildcard(const QString &pattern)
Sets the wildcard expression used to filter the contents of the source model to the given pattern...
#define it(className, varName)
void sort_source_rows(QVector< int > &source_rows, const QModelIndex &source_parent) const
Sorts the given source_rows according to current sort column and order.
void clear()
This function is obsolete.
int count(const T &t) const
Returns the number of occurrences of value in the vector.
virtual QItemSelection mapSelectionToSource(const QItemSelection &selection) const
Returns a source selection mapped from the specified proxySelection.
void _q_sourceRowsAboutToBeInserted(const QModelIndex &source_parent, int start, int end)
void updateChildrenMapping(const QModelIndex &source_parent, Mapping *parent_mapping, Qt::Orientation orient, int start, int end, int delta_item_count, bool remove)
virtual QItemSelection mapSelectionFromSource(const QItemSelection &selection) const
Returns a proxy selection mapped from the specified sourceSelection.
QVariant headerData(int section, Qt::Orientation orientation, int role) const
Reimplemented Function
int rowCount(const QModelIndex &parent=QModelIndex()) const
Reimplemented Function
virtual void setSourceModel(QAbstractItemModel *sourceModel)
Sets the given sourceModel to be processed by the proxy model.
virtual void _q_sourceModelDestroyed()
void setFilterFixedString(const QString &pattern)
Sets the fixed string used to filter the contents of the source model to the given pattern...
const_iterator constEnd() const
Returns a const STL-style iterator pointing to the imaginary item after the last item in the vector...
const QAbstractItemModel * source_model
QString toString() const
Returns the variant as a QString if the variant has type() String , Bool , ByteArray ...
QDateTime toDateTime() const
Returns the variant as a QDateTime if the variant has type() DateTime , Date , or String ; otherwise ...
QStringList mimeTypes() const
Reimplemented Function
void remove_proxy_interval(QVector< int > &source_to_proxy, QVector< int > &proxy_to_source, int proxy_start, int proxy_end, const QModelIndex &proxy_parent, Qt::Orientation orient, bool emit_signal=true)
Given source-to-proxy mapping source_to_proxy and proxy-to-source mapping proxy_to_source, removes items from proxy_start to proxy_end (inclusive) from this proxy model.
bool setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role=Qt::EditRole)
Reimplemented Function
void columnsInserted(const QModelIndex &parent, int first, int last)
This signal is emitted after columns have been inserted into the model.
bool contains(QModelIndex parent, int row)
void build_source_to_proxy_mapping(const QVector< int > &proxy_to_source, QVector< int > &source_to_proxy) const
QRowsRemoval itemsBeingRemoved
Qt::DropActions supportedDropActions() const
Reimplemented Function
void _q_sourceRowsInserted(const QModelIndex &source_parent, int start, int end)
int sortColumn() const
the column currently used for sorting
int count(const T &t) const
Returns the number of occurrences of value in the list.
virtual bool filterAcceptsColumn(int source_column, const QModelIndex &source_parent) const
Returns true if the item in the column indicated by the given source_column and source_parent should ...
~QSortFilterProxyModel()
Destroys this sorting filter model.
void source_items_removed(const QModelIndex &source_parent, int start, int end, Qt::Orientation orient)
Handles source model items removal (columnsRemoved(), rowsRemoved()).
The QString class provides a Unicode character string.
The QHash class is a template class that provides a hash-table-based dictionary.
The QObject class is the base class of all Qt objects.
void setFilterRole(int role)
QSize span(const QModelIndex &index) const
Reimplemented Function
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const
Reimplemented Function
QSortFilterProxyModelLessThan(int column, const QModelIndex &parent, const QAbstractItemModel *source, const QSortFilterProxyModel *proxy)
QHash< QModelIndex, Mapping * >::const_iterator index_to_iterator(const QModelIndex &proxy_index) const
void update_persistent_indexes(const QModelIndexPairList &source_indexes)
Maps source_indexes to proxy indexes and stores those as persistent indexes.
bool removeColumns(int column, int count, const QModelIndex &parent=QModelIndex())
Reimplemented Function
void endResetModel()
Completes a model reset operation.
void _q_sourceDataChanged(const QModelIndex &source_top_left, const QModelIndex &source_bottom_right)
QModelIndex parent() const
Returns the parent of the model index, or QModelIndex() if it has no parent.
Q_CORE_EXPORT QTextStream & right(QTextStream &s)
QSet< int > handle_filter_changed(QVector< int > &source_to_proxy, QVector< int > &proxy_to_source, const QModelIndex &source_parent, Qt::Orientation orient)
bool setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role=Qt::EditRole)
Reimplemented Function
Qt::CaseSensitivity filterCaseSensitivity() const
void resize(int size)
Sets the size of the vector to size.
QRowsRemoval(const QModelIndex &parent_source, int start, int end)
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the vector...
int toInt(bool *ok=0) const
Returns the variant as an int if the variant has type() Int , Bool , ByteArray , Char ...
const QAbstractItemModel * source_model
QModelIndex source_parent
virtual QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const =0
Returns the index of the item in the model specified by the given row, column and parent index...
void _q_sourceColumnsAboutToBeInserted(const QModelIndex &source_parent, int start, int end)
void setSortCaseSensitivity(Qt::CaseSensitivity cs)
const_iterator constBegin() const
Returns a const STL-style iterator pointing to the first item in the vector.
void columnsAboutToBeInserted(const QModelIndex &parent, int first, int last)
This signal is emitted just before columns are inserted into the model.
Qt::CaseSensitivity sortCaseSensitivity() const
void sort()
Sorts the existing mappings.
void setFilterRegExp(const QRegExp ®Exp)
void append(const T &t)
Inserts value at the end of the list.
void _q_sourceLayoutChanged()
static QSet< int > qVectorToSet(const QVector< int > &vector)
#define QT_BEGIN_NAMESPACE
This macro expands to.
qlonglong toLongLong(bool *ok=0) const
Returns the variant as a long long int if the variant has type() LongLong , Bool , ByteArray , Char , Double , Int , String , UInt , or ULongLong ; otherwise returns 0.
static bool compare(const QVariant::Private *a, const QVariant::Private *b)
Compares a to b.
bool hasChildren(const QModelIndex &parent=QModelIndex()) const
Reimplemented Function
bool removeRows(int row, int count, const QModelIndex &parent=QModelIndex())
Reimplemented Function
QItemSelection mapSelectionToSource(const QItemSelection &proxySelection) const
Reimplemented Function
QModelIndexPairList saved_persistent_indexes
virtual bool lessThan(const QModelIndex &left, const QModelIndex &right) const
Returns true if the value of the item referred to by the given index left is less than the value of t...
QVector< int > proxy_columns
void layoutAboutToBeChanged()
This signal is emitted just before the layout of a model is changed.
void clear()
Removes all the elements from the vector and releases the memory used by the vector.
bool contains(const T &value) const
static void sort(T *array, int count, LessThan lessThan)
QAbstractItemModel * sourceModel() const
Returns the model that contains the data that is available through the proxy model.
static bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
Creates a connection of the given type from the signal in the sender object to the method in the rece...
void rowsAboutToBeInserted(const QModelIndex &parent, int first, int last)
This signal is emitted just before rows are inserted into the model.
QMimeData * mimeData(const QModelIndexList &indexes) const
Reimplemented Function
bool insertRows(int row, int count, const QModelIndex &parent=QModelIndex())
Reimplemented Function
QVector< QModelIndex > mapped_children
void _q_sourceColumnsAboutToBeRemoved(const QModelIndex &source_parent, int start, int end)
int row() const
Returns the row this model index refers to.
const T & at(int i) const
Returns the item at index position i in the list.
const QAbstractItemModel * model() const
Returns a pointer to the model containing the item that this index refers to.
The QStringList class provides a list of strings.
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const
Reimplemented Function
void append(const T &t)
Inserts value at the end of the vector.
void fetchMore(const QModelIndex &parent)
Reimplemented Function
void modelAboutToBeReset()
This signal is emitted when reset() is called, before the model's internal state (e.
qulonglong toULongLong(bool *ok=0) const
Returns the variant as as an unsigned long long int if the variant has type() ULongLong ...
const T & value() const
Returns the current item's value.
void setFilterKeyColumn(int column)
Q_CORE_EXPORT void qWarning(const char *,...)
void invalidateFilter()
Invalidates the current filtering.
static const char * data(const QByteArray &arr)
QVector< QPair< int, int > > proxy_intervals_for_source_items(const QVector< int > &source_to_proxy, const QVector< int > &source_items) const
Given source-to-proxy mapping source_to_proxy and the set of source items source_items (which are par...
QVector< int > source_rows
virtual bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const
Returns true if the item in the row indicated by the given source_row and source_parent should be inc...
virtual QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const =0
Returns the data stored under the given role for the item referred to by the index.
QModelIndex proxy_to_source(const QModelIndex &proxyIndex) const
void sort(int column, Qt::SortOrder order=Qt::AscendingOrder)
Reimplemented Function
QVector< int > source_columns
bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent)
Reimplemented Function
void remove_source_items(QVector< int > &source_to_proxy, QVector< int > &proxy_to_source, const QVector< int > &source_items, const QModelIndex &source_parent, Qt::Orientation orient, bool emit_signal=true)
Given source-to-proxy mapping src_to_proxy and proxy-to-source mapping proxy_to_source, removes source_items from this proxy model.
void layoutChanged()
This signal is emitted whenever the layout of items exposed by the model has changed; for example...
QModelIndexList match(const QModelIndex &start, int role, const QVariant &value, int hits=1, Qt::MatchFlags flags=Qt::MatchFlags(Qt::MatchStartsWith|Qt::MatchWrap)) const
Reimplemented Function
QHash< QModelIndex, Mapping * > source_index_mapping
The QMimeData class provides a container for data that records information about its MIME type...
const QSortFilterProxyModel * proxy_model
bool dynamicSortFilter() const
bool isValid() const
Returns true if this model index is valid; otherwise returns false.
QModelIndex source_parent
void qSort(RandomAccessIterator start, RandomAccessIterator end)
int localeAwareCompare(const QString &s) const
QSortFilterProxyModelGreaterThan(int column, const QModelIndex &parent, const QAbstractItemModel *source, const QSortFilterProxyModel *proxy)
const T & at(int i) const
Returns the item at index position i in the vector.
The QAbstractItemModel class provides the abstract interface for item model classes.
The QAbstractProxyModel class provides a base class for proxy item models that can do sorting...
bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole)
Reimplemented Function
void qStableSort(RandomAccessIterator start, RandomAccessIterator end)
QVector< int > proxy_rows
QModelIndex parent_source
void filter_changed(const QModelIndex &source_parent=QModelIndex())
Updates the proxy model (adds/removes rows) based on the new filter.
void _q_sourceHeaderDataChanged(Qt::Orientation orientation, int start, int end)
void columnsAboutToBeRemoved(const QModelIndex &parent, int first, int last)
This signal is emitted just before columns are removed from the model.
static bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *member)
Disconnects signal in object sender from method in object receiver.
void insert(int i, const T &t)
Inserts value at index position i in the vector.
const_iterator constEnd() const
Returns a const STL-style iterator pointing to the imaginary item after the last item in the hash...
void setSourceModel(QAbstractItemModel *sourceModel)
Reimplemented Function
QDate toDate() const
Returns the variant as a QDate if the variant has type() Date , DateTime , or String ; otherwise retu...
The QSortFilterProxyModel class provides support for sorting and filtering data passed between anothe...
int userType() const
Returns the storage type of the value stored in the variant.
#define Q_DECLARE_PUBLIC(Class)
The QItemSelection class manages information about selected items in a model.
int compare(const QString &s) const
QSortFilterProxyModel(QObject *parent=0)
Constructs a sorting filter model with the given parent.
iterator begin()
Returns an STL-style iterator pointing to the first item in the vector.
QRegExp filterRegExp() const
void headerDataChanged(Qt::Orientation orientation, int first, int last)
This signal is emitted whenever a header is changed.
The QPersistentModelIndex class is used to locate data in a data model.
void rowsInserted(const QModelIndex &parent, int first, int last)
This signal is emitted after rows have been inserted into the model.
QModelIndex source_to_proxy(const QModelIndex &sourceIndex) const
Type type() const
Returns the storage type of the value stored in the variant.
QObject * parent() const
Returns a pointer to the parent object.
Q_OUTOFLINE_TEMPLATE QPair< T1, T2 > qMakePair(const T1 &x, const T2 &y)
iterator erase(iterator begin, iterator end)
Removes all the items from begin up to (but not including) end.
Qt::ItemFlags flags(const QModelIndex &index) const
Reimplemented Function
const QSortFilterProxyModel * proxy_model
QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const
Reimplemented Function
QVector< QPair< int, QVector< int > > > proxy_intervals_for_source_items_to_add(const QVector< int > &proxy_to_source, const QVector< int > &source_items, const QModelIndex &source_parent, Qt::Orientation orient) const
Given proxy-to-source mapping proxy_to_source and a set of unmapped source items source_items, determines the proxy item intervals at which the subsets of source items should be inserted (but does not actually add them to the mapping).
The QModelIndex class is used to locate data in a data model.
uint toUInt(bool *ok=0) const
Returns the variant as an unsigned int if the variant has type() UInt , Bool , ByteArray ...
float toFloat(bool *ok=0) const
Returns the variant as a float if the variant has type() Double , QMetaType::Float ...
void modelReset()
This signal is emitted when reset() is called, after the model's internal state (e.
void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
This signal is emitted whenever the data in an existing item changes.
QModelIndex create_index(int row, int column, QHash< QModelIndex, Mapping *>::const_iterator it) const
bool operator()(int r1, int r2) const
QList< QPair< QModelIndex, QPersistentModelIndex > > QModelIndexPairList
void push_back(const T &t)
This function is provided for STL compatibility.
double toDouble(bool *ok=0) const
Returns the variant as a double if the variant has type() Double , QMetaType::Float ...
bool update_source_sort_column()
bool insertColumns(int column, int count, const QModelIndex &parent=QModelIndex())
Reimplemented Function
void setFilterCaseSensitivity(Qt::CaseSensitivity cs)
void setSortLocaleAware(bool on)
QHash< QModelIndex, Mapping * >::const_iterator create_mapping(const QModelIndex &source_parent) const
bool can_create_mapping(const QModelIndex &source_parent) const
void invalidate()
Invalidates the current sorting and filtering.
void _q_sourceRowsRemoved(const QModelIndex &source_parent, int start, int end)
The QSize class defines the size of a two-dimensional object using integer point precision.
QModelIndex buddy(const QModelIndex &index) const
Reimplemented Function
bool isEmpty() const
Returns true if the vector has size 0; otherwise returns false.
bool canFetchMore(const QModelIndex &parent) const
Reimplemented Function
QTime toTime() const
Returns the variant as a QTime if the variant has type() Time , DateTime , or String ; otherwise retu...
void reserve(int size)
Attempts to allocate memory for at least size elements.
int columnCount(const QModelIndex &parent=QModelIndex()) const
Reimplemented Function
virtual void _q_sourceModelDestroyed()
void _q_sourceAboutToBeReset()
QHash< QModelIndex, Mapping * >::const_iterator map_iter
T value() const
Returns the stored value converted to the template type T.
static const KeyPair *const end
void rowsAboutToBeRemoved(const QModelIndex &parent, int first, int last)
This signal is emitted just before rows are removed from the model.
void setDynamicSortFilter(bool enable)
QChar toChar() const
Returns the variant as a QChar if the variant has type() Char , Int , or UInt ; otherwise returns an ...
Qt::SortOrder sortOrder() const
the order currently used for sorting
Q_CORE_EXPORT QTextStream & left(QTextStream &s)
void rowsRemoved(const QModelIndex &parent, int first, int last)
This signal is emitted after rows have been removed from the model.
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Q_OUTOFLINE_TEMPLATE void qDeleteAll(ForwardIterator begin, ForwardIterator end)
QItemSelection mapSelectionFromSource(const QItemSelection &sourceSelection) const
Reimplemented Function
int size() const
Returns the number of items in the vector.
void columnsRemoved(const QModelIndex &parent, int first, int last)
This signal is emitted after columns have been removed from the model.
void filterChanged()
This function is obsolete.
void beginResetModel()
Begins a model reset operation.
void _q_sourceLayoutAboutToBeChanged()
int filterKeyColumn() const
friend class const_iterator
void source_items_about_to_be_removed(const QModelIndex &source_parent, int start, int end, Qt::Orientation orient)
Handles source model items removal (columnsAboutToBeRemoved(), rowsAboutToBeRemoved()).
int column() const
Returns the column this model index refers to.
The QList class is a template class that provides lists.
QModelIndex mapFromSource(const QModelIndex &sourceIndex) const
Returns the model index in the QSortFilterProxyModel given the sourceIndex from the source model...
void remove_from_mapping(const QModelIndex &source_parent)
void insert_source_items(QVector< int > &source_to_proxy, QVector< int > &proxy_to_source, const QVector< int > &source_items, const QModelIndex &source_parent, Qt::Orientation orient, bool emit_signal=true)
Given source-to-proxy mapping source_to_proxy and proxy-to-source mapping proxy_to_source, inserts the given source_items into this proxy model.