Qt 4.8
Classes | Public Functions | Public Variables | List of all members
QSortFilterProxyModelPrivate Class Reference
Inheritance diagram for QSortFilterProxyModelPrivate:
QAbstractProxyModelPrivate QAbstractItemModelPrivate QObjectPrivate QObjectData

Classes

struct  Mapping
 

Public Functions

void _q_clearMapping ()
 
void _q_sourceAboutToBeReset ()
 
void _q_sourceColumnsAboutToBeInserted (const QModelIndex &source_parent, int start, int end)
 
void _q_sourceColumnsAboutToBeRemoved (const QModelIndex &source_parent, int start, int end)
 
void _q_sourceColumnsInserted (const QModelIndex &source_parent, int start, int end)
 
void _q_sourceColumnsRemoved (const QModelIndex &source_parent, int start, int end)
 
void _q_sourceDataChanged (const QModelIndex &source_top_left, const QModelIndex &source_bottom_right)
 
void _q_sourceHeaderDataChanged (Qt::Orientation orientation, int start, int end)
 
void _q_sourceLayoutAboutToBeChanged ()
 
void _q_sourceLayoutChanged ()
 
virtual void _q_sourceModelDestroyed ()
 
void _q_sourceReset ()
 
void _q_sourceRowsAboutToBeInserted (const QModelIndex &source_parent, int start, int end)
 
void _q_sourceRowsAboutToBeRemoved (const QModelIndex &source_parent, int start, int end)
 
void _q_sourceRowsInserted (const QModelIndex &source_parent, int start, int end)
 
void _q_sourceRowsRemoved (const QModelIndex &source_parent, int start, int end)
 
void build_source_to_proxy_mapping (const QVector< int > &proxy_to_source, QVector< int > &source_to_proxy) const
 
bool can_create_mapping (const QModelIndex &source_parent) const
 
QModelIndex create_index (int row, int column, QHash< QModelIndex, Mapping *>::const_iterator it) const
 
QHash< QModelIndex, Mapping * >::const_iterator create_mapping (const QModelIndex &source_parent) const
 
void filter_changed (const QModelIndex &source_parent=QModelIndex())
 Updates the proxy model (adds/removes rows) based on the new filter. More...
 
QSet< int > handle_filter_changed (QVector< int > &source_to_proxy, QVector< int > &proxy_to_source, const QModelIndex &source_parent, Qt::Orientation orient)
 
QHash< QModelIndex, Mapping * >::const_iterator index_to_iterator (const QModelIndex &proxy_index) const
 
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. More...
 
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 part of that mapping), determines the corresponding proxy item intervals that should be removed from the proxy model. More...
 
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). More...
 
void proxy_item_range (const QVector< int > &source_to_proxy, const QVector< int > &source_items, int &proxy_low, int &proxy_high) const
 
QModelIndex proxy_to_source (const QModelIndex &proxyIndex) const
 
void remove_from_mapping (const QModelIndex &source_parent)
 
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. More...
 
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. More...
 
void sort ()
 Sorts the existing mappings. More...
 
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. More...
 
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()). More...
 
void source_items_inserted (const QModelIndex &source_parent, int start, int end, Qt::Orientation orient)
 Handles source model items insertion (columnsInserted(), rowsInserted()). More...
 
void source_items_removed (const QModelIndex &source_parent, int start, int end, Qt::Orientation orient)
 Handles source model items removal (columnsRemoved(), rowsRemoved()). More...
 
QModelIndex source_to_proxy (const QModelIndex &sourceIndex) const
 
QModelIndexPairList store_persistent_indexes ()
 Maps the persistent proxy indexes to source indexes and returns the list of source indexes. More...
 
void update_persistent_indexes (const QModelIndexPairList &source_indexes)
 Maps source_indexes to proxy indexes and stores those as persistent indexes. More...
 
bool update_source_sort_column ()
 
void updateChildrenMapping (const QModelIndex &source_parent, Mapping *parent_mapping, Qt::Orientation orient, int start, int end, int delta_item_count, bool remove)
 
- Public Functions inherited from QAbstractProxyModelPrivate
 QAbstractProxyModelPrivate ()
 
- Public Functions inherited from QAbstractItemModelPrivate
bool allowMove (const QModelIndex &srcParent, int srcFirst, int srcLast, const QModelIndex &destinationParent, int destinationChild, Qt::Orientation orientation)
 Returns whether a move operation is valid. More...
 
void columnsAboutToBeInserted (const QModelIndex &parent, int first, int last)
 
void columnsAboutToBeRemoved (const QModelIndex &parent, int first, int last)
 
void columnsInserted (const QModelIndex &parent, int first, int last)
 
void columnsRemoved (const QModelIndex &parent, int first, int last)
 
QModelIndex createIndex (int row, int column, void *data=0) const
 
QModelIndex createIndex (int row, int column, int id) const
 
bool indexValid (const QModelIndex &index) const
 
void invalidatePersistentIndex (const QModelIndex &index)
 
void invalidatePersistentIndexes ()
 
void itemsAboutToBeMoved (const QModelIndex &srcParent, int srcFirst, int srcLast, const QModelIndex &destinationParent, int destinationChild, Qt::Orientation)
 
void itemsMoved (const QModelIndex &srcParent, int srcFirst, int srcLast, const QModelIndex &destinationParent, int destinationChild, Qt::Orientation orientation)
 
void movePersistentIndexes (QVector< QPersistentModelIndexData *> indexes, int change, const QModelIndex &parent, Qt::Orientation orientation)
 Moves persistent indexes indexes by amount change. More...
 
 QAbstractItemModelPrivate ()
 
void removePersistentIndexData (QPersistentModelIndexData *data)
 
void rowsAboutToBeInserted (const QModelIndex &parent, int first, int last)
 
void rowsAboutToBeRemoved (const QModelIndex &parent, int first, int last)
 
void rowsInserted (const QModelIndex &parent, int first, int last)
 
void rowsRemoved (const QModelIndex &parent, int first, int last)
 
- Public Functions inherited from QObjectPrivate
void _q_reregisterTimers (void *pointer)
 
void addConnection (int signal, Connection *c)
 
void cleanConnectionLists ()
 
void connectNotify (const char *signal)
 
void deleteChildren ()
 
void disconnectNotify (const char *signal)
 
bool isSender (const QObject *receiver, const char *signal) const
 
bool isSignalConnected (uint signalIdx) const
 Returns true if the signal with index signal_index from object sender is connected. More...
 
void moveToThread_helper ()
 
 QObjectPrivate (int version=QObjectPrivateVersion)
 
QObjectList receiverList (const char *signal) const
 
QObjectList senderList () const
 
void setParent_helper (QObject *)
 
void setThreadData_helper (QThreadData *currentData, QThreadData *targetData)
 
int signalIndex (const char *signalName) const
 Returns the signal index used in the internal connectionLists vector. More...
 
virtual ~QObjectPrivate ()
 
- Public Functions inherited from QObjectData
virtual ~QObjectData ()=0
 

Public Variables

bool dynamic_sortfilter
 
int filter_column
 
QRegExp filter_regexp
 
int filter_role
 
QRowsRemoval itemsBeingRemoved
 
int proxy_sort_column
 
QModelIndexPairList saved_persistent_indexes
 
Qt::CaseSensitivity sort_casesensitivity
 
bool sort_localeaware
 
Qt::SortOrder sort_order
 
int sort_role
 
QHash< QModelIndex, Mapping * > source_index_mapping
 
int source_sort_column
 
- Public Variables inherited from QAbstractProxyModelPrivate
QAbstractItemModelmodel
 
- Public Variables inherited from QAbstractItemModelPrivate
QStack< Changechanges
 
struct QAbstractItemModelPrivate::Persistent persistent
 
QHash< int, QByteArrayroleNames
 
Qt::DropActions supportedDragActions
 
- Public Variables inherited from QObjectPrivate
union {
   QObject *   currentChildBeingDeleted
 
   QAbstractDeclarativeData *   declarativeData
 
}; 
 
quint32 connectedSignals [2]
 
QObjectConnectionListVectorconnectionLists
 
SendercurrentSender
 
QList< QPointer< QObject > > eventFilters
 
ExtraDataextraData
 
QString objectName
 
Connectionsenders
 
QAtomicPointer< QtSharedPointer::ExternalRefCountData > sharedRefcount
 
QThreadDatathreadData
 
void * unused
 
- Public Variables inherited from QObjectData
uint blockSig: 1
 
QObjectList children
 
uint hasGuards: 1
 
uint inEventHandler: 1
 
uint inThreadChangeEvent: 1
 
uint isWidget: 1
 
QMetaObjectmetaObject
 
uint ownObjectName: 1
 
QObjectparent
 
uint pendTimer: 1
 
int postedEvents
 
QObjectq_ptr
 
uint receiveChildEvents: 1
 
uint sendChildEvents: 1
 
uint unused: 22
 
uint wasDeleted: 1
 

Additional Inherited Members

- Public Types inherited from QObjectPrivate
typedef void(* StaticMetaCallFunction) (QObject *, QMetaObject::Call, int, void **)
 
- Static Public Functions inherited from QAbstractItemModelPrivate
static const QHash< int, QByteArray > & defaultRoleNames ()
 
static QAbstractItemModelstaticEmptyModel ()
 
static bool variantLessThan (const QVariant &v1, const QVariant &v2)
 This function is used by our Q{Tree,Widget,Table}WidgetModel classes to sort. More...
 
- Static Public Functions inherited from QObjectPrivate
static void clearGuards (QObject *)
 
static QObjectPrivateget (QObject *o)
 
static void resetCurrentSender (QObject *receiver, Sender *currentSender, Sender *previousSender)
 
static SendersetCurrentSender (QObject *receiver, Sender *sender)
 
static void signalSignature (const QMetaMethod &signal, QVarLengthArray< char > *result)
 

Detailed Description

Definition at line 143 of file qsortfilterproxymodel.cpp.

Functions

◆ _q_clearMapping()

void QSortFilterProxyModelPrivate::_q_clearMapping ( )

Definition at line 296 of file qsortfilterproxymodel.cpp.

297 {
298  // store the persistent indexes
300 
302  source_index_mapping.clear();
304  //update_source_sort_column might have created wrong mapping so we have to clear it again
306  source_index_mapping.clear();
307  }
308 
309  // update the persistent indexes
310  update_persistent_indexes(source_indexes);
311 }
QModelIndexPairList store_persistent_indexes()
Maps the persistent proxy indexes to source indexes and returns the list of source indexes...
void update_persistent_indexes(const QModelIndexPairList &source_indexes)
Maps source_indexes to proxy indexes and stores those as persistent indexes.
QHash< QModelIndex, Mapping * > source_index_mapping
Q_OUTOFLINE_TEMPLATE void qDeleteAll(ForwardIterator begin, ForwardIterator end)
Definition: qalgorithms.h:319

◆ _q_sourceAboutToBeReset()

void QSortFilterProxyModelPrivate::_q_sourceAboutToBeReset ( )

Definition at line 1274 of file qsortfilterproxymodel.cpp.

1275 {
1277  q->beginResetModel();
1278 }
#define Q_Q(Class)
Definition: qglobal.h:2483
The QSortFilterProxyModel class provides support for sorting and filtering data passed between anothe...

◆ _q_sourceColumnsAboutToBeInserted()

void QSortFilterProxyModelPrivate::_q_sourceColumnsAboutToBeInserted ( const QModelIndex source_parent,
int  start,
int  end 
)

Definition at line 1356 of file qsortfilterproxymodel.cpp.

1358 {
1359  Q_UNUSED(start);
1360  Q_UNUSED(end);
1361  //Force the creation of a mapping now, even if its empty.
1362  //We need it because the proxy can be acessed at the moment it emits columnsAboutToBeInserted in insert_source_items
1363  if (can_create_mapping(source_parent))
1364  create_mapping(source_parent);
1365 }
QHash< QModelIndex, Mapping * >::const_iterator create_mapping(const QModelIndex &source_parent) const
bool can_create_mapping(const QModelIndex &source_parent) const
static const KeyPair *const end
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729

◆ _q_sourceColumnsAboutToBeRemoved()

void QSortFilterProxyModelPrivate::_q_sourceColumnsAboutToBeRemoved ( const QModelIndex source_parent,
int  start,
int  end 
)

Definition at line 1387 of file qsortfilterproxymodel.cpp.

1389 {
1390  source_items_about_to_be_removed(source_parent, start, end,
1391  Qt::Horizontal);
1392 }
static const KeyPair *const end
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()).

◆ _q_sourceColumnsInserted()

void QSortFilterProxyModelPrivate::_q_sourceColumnsInserted ( const QModelIndex source_parent,
int  start,
int  end 
)

Definition at line 1367 of file qsortfilterproxymodel.cpp.

1369 {
1370  Q_Q(const QSortFilterProxyModel);
1371  source_items_inserted(source_parent, start, end, Qt::Horizontal);
1372 
1373  if (source_parent.isValid())
1374  return; //we sort according to the root column only
1375  if (source_sort_column == -1) {
1376  //we update the source_sort_column depending on the proxy_sort_column
1378  sort();
1379  } else {
1380  if (start <= source_sort_column)
1381  source_sort_column += end - start + 1;
1382 
1383  proxy_sort_column = q->mapFromSource(model->index(0,source_sort_column, source_parent)).column();
1384  }
1385 }
void source_items_inserted(const QModelIndex &source_parent, int start, int end, Qt::Orientation orient)
Handles source model items insertion (columnsInserted(), rowsInserted()).
#define Q_Q(Class)
Definition: qglobal.h:2483
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 sort()
Sorts the existing mappings.
bool isValid() const
Returns true if this model index is valid; otherwise returns false.
The QSortFilterProxyModel class provides support for sorting and filtering data passed between anothe...
static const KeyPair *const end

◆ _q_sourceColumnsRemoved()

void QSortFilterProxyModelPrivate::_q_sourceColumnsRemoved ( const QModelIndex source_parent,
int  start,
int  end 
)

Definition at line 1394 of file qsortfilterproxymodel.cpp.

1396 {
1397  Q_Q(const QSortFilterProxyModel);
1398  source_items_removed(source_parent, start, end, Qt::Horizontal);
1399 
1400  if (source_parent.isValid())
1401  return; //we sort according to the root column only
1402  if (start <= source_sort_column) {
1403  if (end < source_sort_column)
1404  source_sort_column -= end - start + 1;
1405  else
1406  source_sort_column = -1;
1407  }
1408 
1409  proxy_sort_column = q->mapFromSource(model->index(0,source_sort_column, source_parent)).column();
1410 }
void source_items_removed(const QModelIndex &source_parent, int start, int end, Qt::Orientation orient)
Handles source model items removal (columnsRemoved(), rowsRemoved()).
#define Q_Q(Class)
Definition: qglobal.h:2483
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...
bool isValid() const
Returns true if this model index is valid; otherwise returns false.
The QSortFilterProxyModel class provides support for sorting and filtering data passed between anothe...
static const KeyPair *const end

◆ _q_sourceDataChanged()

void QSortFilterProxyModelPrivate::_q_sourceDataChanged ( const QModelIndex source_top_left,
const QModelIndex source_bottom_right 
)

Definition at line 1153 of file qsortfilterproxymodel.cpp.

1155 {
1157  if (!source_top_left.isValid() || !source_bottom_right.isValid())
1158  return;
1159  QModelIndex source_parent = source_top_left.parent();
1160  IndexMap::const_iterator it = source_index_mapping.find(source_parent);
1161  if (it == source_index_mapping.constEnd()) {
1162  // Don't care, since we don't have mapping for this index
1163  return;
1164  }
1165  Mapping *m = it.value();
1166 
1167  // Figure out how the source changes affect us
1168  QVector<int> source_rows_remove;
1169  QVector<int> source_rows_insert;
1170  QVector<int> source_rows_change;
1171  QVector<int> source_rows_resort;
1172  int end = qMin(source_bottom_right.row(), m->proxy_rows.count() - 1);
1173  for (int source_row = source_top_left.row(); source_row <= end; ++source_row) {
1174  if (dynamic_sortfilter) {
1175  if (m->proxy_rows.at(source_row) != -1) {
1176  if (!q->filterAcceptsRow(source_row, source_parent)) {
1177  // This source row no longer satisfies the filter, so it must be removed
1178  source_rows_remove.append(source_row);
1179  } else if (source_sort_column >= source_top_left.column() && source_sort_column <= source_bottom_right.column()) {
1180  // This source row has changed in a way that may affect sorted order
1181  source_rows_resort.append(source_row);
1182  } else {
1183  // This row has simply changed, without affecting filtering nor sorting
1184  source_rows_change.append(source_row);
1185  }
1186  } else {
1187  if (!itemsBeingRemoved.contains(source_parent, source_row) && q->filterAcceptsRow(source_row, source_parent)) {
1188  // This source row now satisfies the filter, so it must be added
1189  source_rows_insert.append(source_row);
1190  }
1191  }
1192  } else {
1193  if (m->proxy_rows.at(source_row) != -1)
1194  source_rows_change.append(source_row);
1195  }
1196  }
1197 
1198  if (!source_rows_remove.isEmpty()) {
1199  remove_source_items(m->proxy_rows, m->source_rows,
1200  source_rows_remove, source_parent, Qt::Vertical);
1201  QSet<int> source_rows_remove_set = qVectorToSet(source_rows_remove);
1202  QVector<QModelIndex>::iterator it = m->mapped_children.end();
1203  while (it != m->mapped_children.begin()) {
1204  --it;
1205  const QModelIndex source_child_index = *it;
1206  if (source_rows_remove_set.contains(source_child_index.row())) {
1207  it = m->mapped_children.erase(it);
1208  remove_from_mapping(source_child_index);
1209  }
1210  }
1211  }
1212 
1213  if (!source_rows_resort.isEmpty()) {
1214  // Re-sort the rows
1215  emit q->layoutAboutToBeChanged();
1216  QModelIndexPairList source_indexes = store_persistent_indexes();
1217  remove_source_items(m->proxy_rows, m->source_rows, source_rows_resort,
1218  source_parent, Qt::Vertical, false);
1219  sort_source_rows(source_rows_resort, source_parent);
1220  insert_source_items(m->proxy_rows, m->source_rows, source_rows_resort,
1221  source_parent, Qt::Vertical, false);
1222  update_persistent_indexes(source_indexes);
1223  emit q->layoutChanged();
1224  // Make sure we also emit dataChanged for the rows
1225  source_rows_change += source_rows_resort;
1226  }
1227 
1228  if (!source_rows_change.isEmpty()) {
1229  // Find the proxy row range
1230  int proxy_start_row;
1231  int proxy_end_row;
1232  proxy_item_range(m->proxy_rows, source_rows_change,
1233  proxy_start_row, proxy_end_row);
1234  // ### Find the proxy column range also
1235  if (proxy_end_row >= 0) {
1236  // the row was accepted, but some columns might still be filtered out
1237  int source_left_column = source_top_left.column();
1238  while (source_left_column < source_bottom_right.column()
1239  && m->proxy_columns.at(source_left_column) == -1)
1240  ++source_left_column;
1241  const QModelIndex proxy_top_left = create_index(
1242  proxy_start_row, m->proxy_columns.at(source_left_column), it);
1243  int source_right_column = source_bottom_right.column();
1244  while (source_right_column > source_top_left.column()
1245  && m->proxy_columns.at(source_right_column) == -1)
1246  --source_right_column;
1247  const QModelIndex proxy_bottom_right = create_index(
1248  proxy_end_row, m->proxy_columns.at(source_right_column), it);
1249  emit q->dataChanged(proxy_top_left, proxy_bottom_right);
1250  }
1251  }
1252 
1253  if (!source_rows_insert.isEmpty()) {
1254  sort_source_rows(source_rows_insert, source_parent);
1255  insert_source_items(m->proxy_rows, m->source_rows,
1256  source_rows_insert, source_parent, Qt::Vertical);
1257  }
1258 }
QModelIndexPairList store_persistent_indexes()
Maps the persistent proxy indexes to source indexes and returns the list of source indexes...
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
void proxy_item_range(const QVector< int > &source_to_proxy, const QVector< int > &source_items, int &proxy_low, int &proxy_high) const
#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.
bool contains(QModelIndex parent, int row)
void update_persistent_indexes(const QModelIndexPairList &source_indexes)
Maps source_indexes to proxy indexes and stores those as persistent indexes.
QModelIndex parent() const
Returns the parent of the model index, or QModelIndex() if it has no parent.
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the vector...
Definition: qvector.h:250
#define Q_Q(Class)
Definition: qglobal.h:2483
static QSet< int > qVectorToSet(const QVector< int > &vector)
bool contains(const T &value) const
Definition: qset.h:91
int row() const
Returns the row this model index refers to.
#define emit
Definition: qobjectdefs.h:76
void append(const T &t)
Inserts value at the end of the vector.
Definition: qvector.h:573
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.
QHash< QModelIndex, Mapping * > source_index_mapping
bool isValid() const
Returns true if this model index is valid; otherwise returns false.
The QSortFilterProxyModel class provides support for sorting and filtering data passed between anothe...
iterator begin()
Returns an STL-style iterator pointing to the first item in the vector.
Definition: qvector.h:247
iterator erase(iterator begin, iterator end)
Removes all the items from begin up to (but not including) end.
Definition: qvector.h:627
The QModelIndex class is used to locate data in a data model.
QModelIndex create_index(int row, int column, QHash< QModelIndex, Mapping *>::const_iterator it) const
bool isEmpty() const
Returns true if the vector has size 0; otherwise returns false.
Definition: qvector.h:139
static const KeyPair *const end
int column() const
Returns the column this model index refers to.
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.

◆ _q_sourceHeaderDataChanged()

void QSortFilterProxyModelPrivate::_q_sourceHeaderDataChanged ( Qt::Orientation  orientation,
int  start,
int  end 
)

Definition at line 1260 of file qsortfilterproxymodel.cpp.

1262 {
1264  Mapping *m = create_mapping(QModelIndex()).value();
1265  int proxy_start = (orientation == Qt::Vertical
1266  ? m->proxy_rows.at(start)
1267  : m->proxy_columns.at(start));
1268  int proxy_end = (orientation == Qt::Vertical
1269  ? m->proxy_rows.at(end)
1270  : m->proxy_columns.at(end));
1271  emit q->headerDataChanged(orientation, proxy_start, proxy_end);
1272 }
#define Q_Q(Class)
Definition: qglobal.h:2483
#define emit
Definition: qobjectdefs.h:76
The QSortFilterProxyModel class provides support for sorting and filtering data passed between anothe...
The QModelIndex class is used to locate data in a data model.
QHash< QModelIndex, Mapping * >::const_iterator create_mapping(const QModelIndex &source_parent) const
static const KeyPair *const end

◆ _q_sourceLayoutAboutToBeChanged()

void QSortFilterProxyModelPrivate::_q_sourceLayoutAboutToBeChanged ( )

Definition at line 1292 of file qsortfilterproxymodel.cpp.

1293 {
1296  emit q->layoutAboutToBeChanged();
1297  if (persistent.indexes.isEmpty())
1298  return;
1299 
1301 }
QModelIndexPairList store_persistent_indexes()
Maps the persistent proxy indexes to source indexes and returns the list of source indexes...
QHash< QModelIndex, QPersistentModelIndexData * > indexes
#define Q_Q(Class)
Definition: qglobal.h:2483
QModelIndexPairList saved_persistent_indexes
#define emit
Definition: qobjectdefs.h:76
bool isEmpty() const
Returns true if the hash contains no items; otherwise returns false.
Definition: qhash.h:297
void clear()
Removes all items from the list.
Definition: qlist.h:764
struct QAbstractItemModelPrivate::Persistent persistent
The QSortFilterProxyModel class provides support for sorting and filtering data passed between anothe...

◆ _q_sourceLayoutChanged()

void QSortFilterProxyModelPrivate::_q_sourceLayoutChanged ( )

Definition at line 1303 of file qsortfilterproxymodel.cpp.

1304 {
1306 
1308  source_index_mapping.clear();
1309 
1312 
1314  //update_source_sort_column might have created wrong mapping so we have to clear it again
1316  source_index_mapping.clear();
1317  }
1318 
1319  emit q->layoutChanged();
1320 }
void update_persistent_indexes(const QModelIndexPairList &source_indexes)
Maps source_indexes to proxy indexes and stores those as persistent indexes.
#define Q_Q(Class)
Definition: qglobal.h:2483
QModelIndexPairList saved_persistent_indexes
#define emit
Definition: qobjectdefs.h:76
void clear()
Removes all items from the list.
Definition: qlist.h:764
QHash< QModelIndex, Mapping * > source_index_mapping
The QSortFilterProxyModel class provides support for sorting and filtering data passed between anothe...
Q_OUTOFLINE_TEMPLATE void qDeleteAll(ForwardIterator begin, ForwardIterator end)
Definition: qalgorithms.h:319

◆ _q_sourceModelDestroyed()

void QSortFilterProxyModelPrivate::_q_sourceModelDestroyed ( )
virtual

◆ _q_sourceReset()

void QSortFilterProxyModelPrivate::_q_sourceReset ( )

Definition at line 1280 of file qsortfilterproxymodel.cpp.

1281 {
1284  _q_clearMapping();
1285  // All internal structures are deleted in clear()
1286  q->endResetModel();
1288  if (dynamic_sortfilter)
1289  sort();
1290 }
#define Q_Q(Class)
Definition: qglobal.h:2483
void sort()
Sorts the existing mappings.
The QSortFilterProxyModel class provides support for sorting and filtering data passed between anothe...

◆ _q_sourceRowsAboutToBeInserted()

void QSortFilterProxyModelPrivate::_q_sourceRowsAboutToBeInserted ( const QModelIndex source_parent,
int  start,
int  end 
)

Definition at line 1322 of file qsortfilterproxymodel.cpp.

1324 {
1325  Q_UNUSED(start);
1326  Q_UNUSED(end);
1327  //Force the creation of a mapping now, even if its empty.
1328  //We need it because the proxy can be acessed at the moment it emits rowsAboutToBeInserted in insert_source_items
1329  if (can_create_mapping(source_parent))
1330  create_mapping(source_parent);
1331 }
QHash< QModelIndex, Mapping * >::const_iterator create_mapping(const QModelIndex &source_parent) const
bool can_create_mapping(const QModelIndex &source_parent) const
static const KeyPair *const end
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729

◆ _q_sourceRowsAboutToBeRemoved()

void QSortFilterProxyModelPrivate::_q_sourceRowsAboutToBeRemoved ( const QModelIndex source_parent,
int  start,
int  end 
)

Definition at line 1341 of file qsortfilterproxymodel.cpp.

1343 {
1344  itemsBeingRemoved = QRowsRemoval(source_parent, start, end);
1345  source_items_about_to_be_removed(source_parent, start, end,
1346  Qt::Vertical);
1347 }
static const KeyPair *const end
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()).

◆ _q_sourceRowsInserted()

void QSortFilterProxyModelPrivate::_q_sourceRowsInserted ( const QModelIndex source_parent,
int  start,
int  end 
)

Definition at line 1333 of file qsortfilterproxymodel.cpp.

1335 {
1336  source_items_inserted(source_parent, start, end, Qt::Vertical);
1337  if (update_source_sort_column() && dynamic_sortfilter) //previous call to update_source_sort_column may fail if the model has no column.
1338  sort(); // now it should succeed so we need to make sure to sort again
1339 }
void source_items_inserted(const QModelIndex &source_parent, int start, int end, Qt::Orientation orient)
Handles source model items insertion (columnsInserted(), rowsInserted()).
void sort()
Sorts the existing mappings.
static const KeyPair *const end

◆ _q_sourceRowsRemoved()

void QSortFilterProxyModelPrivate::_q_sourceRowsRemoved ( const QModelIndex source_parent,
int  start,
int  end 
)

Definition at line 1349 of file qsortfilterproxymodel.cpp.

1351 {
1353  source_items_removed(source_parent, start, end, Qt::Vertical);
1354 }
void source_items_removed(const QModelIndex &source_parent, int start, int end, Qt::Orientation orient)
Handles source model items removal (columnsRemoved(), rowsRemoved()).
static const KeyPair *const end

◆ build_source_to_proxy_mapping()

void QSortFilterProxyModelPrivate::build_source_to_proxy_mapping ( const QVector< int > &  proxy_to_source,
QVector< int > &  source_to_proxy 
) const
Warning
This function is not part of the public interface.

Definition at line 1005 of file qsortfilterproxymodel.cpp.

1007 {
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;
1012 }
QVector< T > & fill(const T &t, int size=-1)
Assigns value to all items in the vector.
Definition: qvector.h:665
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137

◆ can_create_mapping()

bool QSortFilterProxyModelPrivate::can_create_mapping ( const QModelIndex source_parent) const

Definition at line 398 of file qsortfilterproxymodel.cpp.

399 {
400  if (source_parent.isValid()) {
401  QModelIndex source_grand_parent = source_parent.parent();
402  IndexMap::const_iterator it = source_index_mapping.constFind(source_grand_parent);
403  if (it == source_index_mapping.constEnd()) {
404  // Don't care, since we don't have mapping for the grand parent
405  return false;
406  }
407  Mapping *gm = it.value();
408  if (gm->proxy_rows.at(source_parent.row()) == -1 ||
409  gm->proxy_columns.at(source_parent.column()) == -1) {
410  // Don't care, since parent is filtered
411  return false;
412  }
413  }
414  return true;
415 }
#define it(className, varName)
QModelIndex parent() const
Returns the parent of the model index, or QModelIndex() if it has no parent.
int row() const
Returns the row this model index refers to.
QHash< QModelIndex, Mapping * > source_index_mapping
bool isValid() const
Returns true if this model index is valid; otherwise returns false.
The QModelIndex class is used to locate data in a data model.
int column() const
Returns the column this model index refers to.

◆ create_index()

QModelIndex QSortFilterProxyModelPrivate::create_index ( int  row,
int  column,
QHash< QModelIndex, Mapping *>::const_iterator  it 
) const
inline

Definition at line 197 of file qsortfilterproxymodel.cpp.

199  {
200  return q_func()->createIndex(row, column, *it);
201  }

◆ create_mapping()

IndexMap::const_iterator QSortFilterProxyModelPrivate::create_mapping ( const QModelIndex source_parent) const

Definition at line 313 of file qsortfilterproxymodel.cpp.

315 {
316  Q_Q(const QSortFilterProxyModel);
317 
318  IndexMap::const_iterator it = source_index_mapping.constFind(source_parent);
319  if (it != source_index_mapping.constEnd()) // was mapped already
320  return it;
321 
322  Mapping *m = new Mapping;
323 
324  int source_rows = model->rowCount(source_parent);
325  m->source_rows.reserve(source_rows);
326  for (int i = 0; i < source_rows; ++i) {
327  if (q->filterAcceptsRow(i, source_parent))
328  m->source_rows.append(i);
329  }
330  int source_cols = model->columnCount(source_parent);
331  m->source_columns.reserve(source_cols);
332  for (int i = 0; i < source_cols; ++i) {
333  if (q->filterAcceptsColumn(i, source_parent))
334  m->source_columns.append(i);
335  }
336 
337  sort_source_rows(m->source_rows, source_parent);
338  m->proxy_rows.resize(source_rows);
339  build_source_to_proxy_mapping(m->source_rows, m->proxy_rows);
340  m->proxy_columns.resize(source_cols);
341  build_source_to_proxy_mapping(m->source_columns, m->proxy_columns);
342 
343  it = IndexMap::const_iterator(source_index_mapping.insert(source_parent, m));
344  m->map_iter = it;
345 
346  if (source_parent.isValid()) {
347  QModelIndex source_grand_parent = source_parent.parent();
348  IndexMap::const_iterator it2 = create_mapping(source_grand_parent);
349  Q_ASSERT(it2 != source_index_mapping.constEnd());
350  it2.value()->mapped_children.append(source_parent);
351  }
352 
353  Q_ASSERT(it != source_index_mapping.constEnd());
354  Q_ASSERT(it.value());
355 
356  return it;
357 }
virtual int columnCount(const QModelIndex &parent=QModelIndex()) const =0
Returns the number of columns for the children of the given parent.
#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.
virtual int rowCount(const QModelIndex &parent=QModelIndex()) const =0
Returns the number of rows under the given parent.
void build_source_to_proxy_mapping(const QVector< int > &proxy_to_source, QVector< int > &source_to_proxy) const
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
QModelIndex parent() const
Returns the parent of the model index, or QModelIndex() if it has no parent.
#define Q_Q(Class)
Definition: qglobal.h:2483
QHash< QModelIndex, Mapping * > source_index_mapping
bool isValid() const
Returns true if this model index is valid; otherwise returns false.
The QSortFilterProxyModel class provides support for sorting and filtering data passed between anothe...
The QModelIndex class is used to locate data in a data model.
QHash< QModelIndex, Mapping * >::const_iterator create_mapping(const QModelIndex &source_parent) const

◆ filter_changed()

void QSortFilterProxyModelPrivate::filter_changed ( const QModelIndex source_parent = QModelIndex())

Updates the proxy model (adds/removes rows) based on the new filter.

Warning
This function is not part of the public interface.

Definition at line 1070 of file qsortfilterproxymodel.cpp.

1071 {
1072  IndexMap::const_iterator it = source_index_mapping.constFind(source_parent);
1073  if (it == source_index_mapping.constEnd())
1074  return;
1075  Mapping *m = it.value();
1076  QSet<int> rows_removed = handle_filter_changed(m->proxy_rows, m->source_rows, source_parent, Qt::Vertical);
1077  QSet<int> columns_removed = handle_filter_changed(m->proxy_columns, m->source_columns, source_parent, Qt::Horizontal);
1078 
1079  // We need to iterate over a copy of m->mapped_children because otherwise it may be changed by other code, invalidating
1080  // the iterator it2.
1081  // The m->mapped_children vector can be appended to with indexes which are no longer filtered
1082  // out (in create_mapping) when this function recurses for child indexes.
1083  const QVector<QModelIndex> mappedChildren = m->mapped_children;
1084  QVector<int> indexesToRemove;
1085  for (int i = 0; i < mappedChildren.size(); ++i) {
1086  const QModelIndex source_child_index = mappedChildren.at(i);
1087  if (rows_removed.contains(source_child_index.row()) || columns_removed.contains(source_child_index.column())) {
1088  indexesToRemove.push_back(i);
1089  remove_from_mapping(source_child_index);
1090  } else {
1091  filter_changed(source_child_index);
1092  }
1093  }
1094  QVector<int>::const_iterator removeIt = indexesToRemove.constEnd();
1095  const QVector<int>::const_iterator removeBegin = indexesToRemove.constBegin();
1096 
1097  // We can't just remove these items from mappedChildren while iterating above and then
1098  // do something like m->mapped_children = mappedChildren, because mapped_children might
1099  // be appended to in create_mapping, and we would lose those new items.
1100  // Because they are always appended in create_mapping, we can still remove them by
1101  // position here.
1102  while (removeIt != removeBegin) {
1103  --removeIt;
1104  m->mapped_children.remove(*removeIt);
1105  }
1106 }
void remove(int i)
Removes the element at index position i.
Definition: qvector.h:374
#define it(className, varName)
const_iterator constEnd() const
Returns a const STL-style iterator pointing to the imaginary item after the last item in the vector...
Definition: qvector.h:252
QSet< int > handle_filter_changed(QVector< int > &source_to_proxy, QVector< int > &proxy_to_source, const QModelIndex &source_parent, Qt::Orientation orient)
const_iterator constBegin() const
Returns a const STL-style iterator pointing to the first item in the vector.
Definition: qvector.h:249
bool contains(const T &value) const
Definition: qset.h:91
int row() const
Returns the row this model index refers to.
QHash< QModelIndex, Mapping * > source_index_mapping
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
void filter_changed(const QModelIndex &source_parent=QModelIndex())
Updates the proxy model (adds/removes rows) based on the new filter.
The QModelIndex class is used to locate data in a data model.
void push_back(const T &t)
This function is provided for STL compatibility.
Definition: qvector.h:281
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137
int column() const
Returns the column this model index refers to.
void remove_from_mapping(const QModelIndex &source_parent)

◆ handle_filter_changed()

QSet< int > QSortFilterProxyModelPrivate::handle_filter_changed ( QVector< int > &  source_to_proxy,
QVector< int > &  proxy_to_source,
const QModelIndex source_parent,
Qt::Orientation  orient 
)
Warning
This function is not part of the public interface. returns the removed items indexes

Definition at line 1112 of file qsortfilterproxymodel.cpp.

1115 {
1117  // Figure out which mapped items to remove
1118  QVector<int> source_items_remove;
1119  for (int i = 0; i < proxy_to_source.count(); ++i) {
1120  const int source_item = proxy_to_source.at(i);
1121  if ((orient == Qt::Vertical)
1122  ? !q->filterAcceptsRow(source_item, source_parent)
1123  : !q->filterAcceptsColumn(source_item, source_parent)) {
1124  // This source item does not satisfy the filter, so it must be removed
1125  source_items_remove.append(source_item);
1126  }
1127  }
1128  // Figure out which non-mapped items to insert
1129  QVector<int> source_items_insert;
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) {
1133  if ((orient == Qt::Vertical)
1134  ? q->filterAcceptsRow(source_item, source_parent)
1135  : q->filterAcceptsColumn(source_item, source_parent)) {
1136  // This source item satisfies the filter, so it must be added
1137  source_items_insert.append(source_item);
1138  }
1139  }
1140  }
1141  if (!source_items_remove.isEmpty() || !source_items_insert.isEmpty()) {
1142  // Do item removal and insertion
1143  remove_source_items(source_to_proxy, proxy_to_source,
1144  source_items_remove, source_parent, orient);
1145  if (orient == Qt::Vertical)
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);
1149  }
1150  return qVectorToSet(source_items_remove);
1151 }
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.
int count(const T &t) const
Returns the number of occurrences of value in the vector.
Definition: qvector.h:742
#define Q_Q(Class)
Definition: qglobal.h:2483
static QSet< int > qVectorToSet(const QVector< int > &vector)
void append(const T &t)
Inserts value at the end of the vector.
Definition: qvector.h:573
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.
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
The QSortFilterProxyModel class provides support for sorting and filtering data passed between anothe...
bool isEmpty() const
Returns true if the vector has size 0; otherwise returns false.
Definition: qvector.h:139
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137
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.

◆ index_to_iterator()

QHash<QModelIndex, Mapping *>::const_iterator QSortFilterProxyModelPrivate::index_to_iterator ( const QModelIndex proxy_index) const
inline

Definition at line 183 of file qsortfilterproxymodel.cpp.

185  {
186  Q_ASSERT(proxy_index.isValid());
187  Q_ASSERT(proxy_index.model() == q_func());
188  const void *p = proxy_index.internalPointer();
189  Q_ASSERT(p);
191  static_cast<const Mapping*>(p)->map_iter;
192  Q_ASSERT(it != source_index_mapping.constEnd());
193  Q_ASSERT(it.value());
194  return it;
195  }
void * internalPointer() const
Returns a void * pointer used by the model to associate the index with the internal data structure...
The QHash::const_iterator class provides an STL-style const iterator for QHash and QMultiHash...
Definition: qhash.h:395
#define it(className, varName)
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
const QAbstractItemModel * model() const
Returns a pointer to the model containing the item that this index refers to.
const T & value() const
Returns the current item&#39;s value.
Definition: qhash.h:420
QHash< QModelIndex, Mapping * > source_index_mapping
bool isValid() const
Returns true if this model index is valid; otherwise returns false.

◆ insert_source_items()

void QSortFilterProxyModelPrivate::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.

Warning
This function is not part of the public interface.

The source items are inserted in intervals (based on some sorted order), so that the proper rows/columnsInserted(start, end) signals will be generated.

Definition at line 682 of file qsortfilterproxymodel.cpp.

686 {
688  QModelIndex proxy_parent = q->mapFromSource(source_parent);
689  if (!proxy_parent.isValid() && source_parent.isValid())
690  return; // nothing to do (source_parent is not mapped)
691 
692  QVector<QPair<int, QVector<int> > > proxy_intervals;
693  proxy_intervals = proxy_intervals_for_source_items_to_add(
694  proxy_to_source, source_items, source_parent, orient);
695 
696  for (int i = proxy_intervals.size()-1; i >= 0; --i) {
697  QPair<int, QVector<int> > interval = proxy_intervals.at(i);
698  int proxy_start = interval.first;
699  QVector<int> source_items = interval.second;
700  int proxy_end = proxy_start + source_items.size() - 1;
701 
702  if (emit_signal) {
703  if (orient == Qt::Vertical)
704  q->beginInsertRows(proxy_parent, proxy_start, proxy_end);
705  else
706  q->beginInsertColumns(proxy_parent, proxy_start, proxy_end);
707  }
708 
709  for (int i = 0; i < source_items.size(); ++i)
710  proxy_to_source.insert(proxy_start + i, source_items.at(i));
711 
712  build_source_to_proxy_mapping(proxy_to_source, source_to_proxy);
713 
714  if (emit_signal) {
715  if (orient == Qt::Vertical)
716  q->endInsertRows();
717  else
718  q->endInsertColumns();
719  }
720  }
721 }
T1 first
Definition: qpair.h:65
T2 second
Definition: qpair.h:66
void build_source_to_proxy_mapping(const QVector< int > &proxy_to_source, QVector< int > &source_to_proxy) const
The QVector class is a template class that provides a dynamic array.
Definition: qdatastream.h:64
#define Q_Q(Class)
Definition: qglobal.h:2483
bool isValid() const
Returns true if this model index is valid; otherwise returns false.
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
void insert(int i, const T &t)
Inserts value at index position i in the vector.
Definition: qvector.h:362
The QSortFilterProxyModel class provides support for sorting and filtering data passed between anothe...
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.
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137

◆ proxy_intervals_for_source_items()

QVector< QPair< int, int > > QSortFilterProxyModelPrivate::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 part of that mapping), determines the corresponding proxy item intervals that should be removed from the proxy model.

Warning
This function is not part of the public interface.

The result is a vector of pairs, where each pair represents a (start, end) tuple, sorted in ascending order.

Definition at line 496 of file qsortfilterproxymodel.cpp.

498 {
499  QVector<QPair<int, int> > proxy_intervals;
500  if (source_items.isEmpty())
501  return proxy_intervals;
502 
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));
506  Q_ASSERT(first_proxy_item != -1);
507  int last_proxy_item = first_proxy_item;
508  ++source_items_index;
509  // Find end of interval
510  while ((source_items_index < source_items.size())
511  && (source_to_proxy.at(source_items.at(source_items_index)) == last_proxy_item + 1)) {
512  ++last_proxy_item;
513  ++source_items_index;
514  }
515  // Add interval to result
516  proxy_intervals.append(QPair<int, int>(first_proxy_item, last_proxy_item));
517  }
518  qStableSort(proxy_intervals.begin(), proxy_intervals.end());
519  return proxy_intervals;
520 }
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
The QVector class is a template class that provides a dynamic array.
Definition: qdatastream.h:64
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the vector...
Definition: qvector.h:250
void append(const T &t)
Inserts value at the end of the vector.
Definition: qvector.h:573
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
void qStableSort(RandomAccessIterator start, RandomAccessIterator end)
Definition: qalgorithms.h:202
iterator begin()
Returns an STL-style iterator pointing to the first item in the vector.
Definition: qvector.h:247
bool isEmpty() const
Returns true if the vector has size 0; otherwise returns false.
Definition: qvector.h:139
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137

◆ proxy_intervals_for_source_items_to_add()

QVector< QPair< int, QVector< int > > > QSortFilterProxyModelPrivate::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).

Warning
This function is not part of the public interface.

The result is a vector of pairs, each pair representing a tuple (start, items), where items is a vector containing the (sorted) source items that should be inserted at that proxy model location.

Definition at line 605 of file qsortfilterproxymodel.cpp.

608 {
609  Q_Q(const QSortFilterProxyModel);
610  QVector<QPair<int, QVector<int> > > proxy_intervals;
611  if (source_items.isEmpty())
612  return proxy_intervals;
613 
614  int proxy_low = 0;
615  int proxy_item = 0;
616  int source_items_index = 0;
617  QVector<int> source_items_in_interval;
618  bool compare = (orient == Qt::Vertical && source_sort_column >= 0 && dynamic_sortfilter);
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;
624 
625  // Find proxy item at which insertion should be started
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;
630  if (compare) {
631  QModelIndex i2 = model->index(proxy_to_source.at(proxy_item), source_sort_column, source_parent);
632  if ((sort_order == Qt::AscendingOrder) ? q->lessThan(i1, i2) : q->lessThan(i2, i1))
633  proxy_high = proxy_item - 1;
634  else
635  proxy_low = proxy_item + 1;
636  } else {
637  if (first_new_source_item < proxy_to_source.at(proxy_item))
638  proxy_high = proxy_item - 1;
639  else
640  proxy_low = proxy_item + 1;
641  }
642  }
643  proxy_item = proxy_low;
644 
645  // Find the sequence of new source items that should be inserted here
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));
649  } else {
650  i1 = compare ? model->index(proxy_to_source.at(proxy_item), source_sort_column, source_parent) : QModelIndex();
651  for ( ; source_items_index < source_items.size(); ++source_items_index) {
652  int new_source_item = source_items.at(source_items_index);
653  if (compare) {
654  QModelIndex i2 = model->index(new_source_item, source_sort_column, source_parent);
655  if ((sort_order == Qt::AscendingOrder) ? q->lessThan(i1, i2) : q->lessThan(i2, i1))
656  break;
657  } else {
658  if (proxy_to_source.at(proxy_item) < new_source_item)
659  break;
660  }
661  source_items_in_interval.append(new_source_item);
662  }
663  }
664 
665  // Add interval to result
666  proxy_intervals.append(QPair<int, QVector<int> >(proxy_item, source_items_in_interval));
667  }
668  return proxy_intervals;
669 }
The QVector class is a template class that provides a dynamic array.
Definition: qdatastream.h:64
#define Q_Q(Class)
Definition: qglobal.h:2483
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...
static bool compare(const QVariant::Private *a, const QVariant::Private *b)
Compares a to b.
Definition: qvariant.cpp:383
void clear()
Removes all the elements from the vector and releases the memory used by the vector.
Definition: qvector.h:347
void append(const T &t)
Inserts value at the end of the vector.
Definition: qvector.h:573
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
The QSortFilterProxyModel class provides support for sorting and filtering data passed between anothe...
The QModelIndex class is used to locate data in a data model.
bool isEmpty() const
Returns true if the vector has size 0; otherwise returns false.
Definition: qvector.h:139
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137

◆ proxy_item_range()

void QSortFilterProxyModelPrivate::proxy_item_range ( const QVector< int > &  source_to_proxy,
const QVector< int > &  source_items,
int &  proxy_low,
int &  proxy_high 
) const
Warning
This function is not part of the public interface.

Definition at line 986 of file qsortfilterproxymodel.cpp.

989 {
990  proxy_low = INT_MAX;
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));
994  Q_ASSERT(proxy_item != -1);
995  if (proxy_item < proxy_low)
996  proxy_low = proxy_item;
997  if (proxy_item > proxy_high)
998  proxy_high = proxy_item;
999  }
1000 }
int count(const T &t) const
Returns the number of occurrences of value in the vector.
Definition: qvector.h:742
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
#define INT_MAX

◆ proxy_to_source()

QModelIndex QSortFilterProxyModelPrivate::proxy_to_source ( const QModelIndex proxyIndex) const

Definition at line 359 of file qsortfilterproxymodel.cpp.

360 {
361  if (!proxy_index.isValid())
362  return QModelIndex(); // for now; we may want to be able to set a root index later
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");
366  return QModelIndex();
367  }
369  Mapping *m = it.value();
370  if ((proxy_index.row() >= m->source_rows.size()) || (proxy_index.column() >= m->source_columns.size()))
371  return QModelIndex();
372  int source_row = m->source_rows.at(proxy_index.row());
373  int source_col = m->source_columns.at(proxy_index.column());
374  return model->index(source_row, source_col, it.key());
375 }
#define it(className, varName)
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
QHash< QModelIndex, Mapping * >::const_iterator index_to_iterator(const QModelIndex &proxy_index) const
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...
Q_CORE_EXPORT void qWarning(const char *,...)
The QModelIndex class is used to locate data in a data model.

◆ remove_from_mapping()

void QSortFilterProxyModelPrivate::remove_from_mapping ( const QModelIndex source_parent)

Definition at line 287 of file qsortfilterproxymodel.cpp.

288 {
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));
292  delete m;
293  }
294 }
QHash< QModelIndex, Mapping * > source_index_mapping
void remove_from_mapping(const QModelIndex &source_parent)

◆ remove_proxy_interval()

void QSortFilterProxyModelPrivate::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.

Warning
This function is not part of the public interface.

Definition at line 565 of file qsortfilterproxymodel.cpp.

568 {
570  if (emit_signal) {
571  if (orient == Qt::Vertical)
572  q->beginRemoveRows(proxy_parent, proxy_start, proxy_end);
573  else
574  q->beginRemoveColumns(proxy_parent, proxy_start, proxy_end);
575  }
576 
577  // Remove items from proxy-to-source mapping
578  proxy_to_source.remove(proxy_start, proxy_end - proxy_start + 1);
579 
580  build_source_to_proxy_mapping(proxy_to_source, source_to_proxy);
581 
582  if (emit_signal) {
583  if (orient == Qt::Vertical)
584  q->endRemoveRows();
585  else
586  q->endRemoveColumns();
587  }
588 }
void remove(int i)
Removes the element at index position i.
Definition: qvector.h:374
void build_source_to_proxy_mapping(const QVector< int > &proxy_to_source, QVector< int > &source_to_proxy) const
#define Q_Q(Class)
Definition: qglobal.h:2483
The QSortFilterProxyModel class provides support for sorting and filtering data passed between anothe...

◆ remove_source_items()

void QSortFilterProxyModelPrivate::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.

Warning
This function is not part of the public interface.

The corresponding proxy items are removed in intervals, so that the proper rows/columnsRemoved(start, end) signals will be generated.

Definition at line 533 of file qsortfilterproxymodel.cpp.

537 {
539  QModelIndex proxy_parent = q->mapFromSource(source_parent);
540  if (!proxy_parent.isValid() && source_parent.isValid())
541  return; // nothing to do (already removed)
542 
543  QVector<QPair<int, int> > proxy_intervals;
544  proxy_intervals = proxy_intervals_for_source_items(source_to_proxy, source_items);
545 
546  for (int i = proxy_intervals.size()-1; i >= 0; --i) {
547  QPair<int, int> interval = proxy_intervals.at(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);
552  }
553 }
T1 first
Definition: qpair.h:65
T2 second
Definition: qpair.h:66
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.
The QVector class is a template class that provides a dynamic array.
Definition: qdatastream.h:64
#define Q_Q(Class)
Definition: qglobal.h:2483
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...
bool isValid() const
Returns true if this model index is valid; otherwise returns false.
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
The QSortFilterProxyModel class provides support for sorting and filtering data passed between anothe...
The QModelIndex class is used to locate data in a data model.
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137

◆ sort()

void QSortFilterProxyModelPrivate::sort ( )

Sorts the existing mappings.

Warning
This function is not part of the public interface.

Definition at line 425 of file qsortfilterproxymodel.cpp.

426 {
428  emit q->layoutAboutToBeChanged();
431  for (; it != source_index_mapping.constEnd(); ++it) {
432  QModelIndex source_parent = it.key();
433  Mapping *m = it.value();
434  sort_source_rows(m->source_rows, source_parent);
435  build_source_to_proxy_mapping(m->source_rows, m->proxy_rows);
436  }
437  update_persistent_indexes(source_indexes);
438  emit q->layoutChanged();
439 }
QModelIndexPairList store_persistent_indexes()
Maps the persistent proxy indexes to source indexes and returns the list of source indexes...
#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 build_source_to_proxy_mapping(const QVector< int > &proxy_to_source, QVector< int > &source_to_proxy) const
void update_persistent_indexes(const QModelIndexPairList &source_indexes)
Maps source_indexes to proxy indexes and stores those as persistent indexes.
#define Q_Q(Class)
Definition: qglobal.h:2483
#define emit
Definition: qobjectdefs.h:76
QHash< QModelIndex, Mapping * > source_index_mapping
The QSortFilterProxyModel class provides support for sorting and filtering data passed between anothe...
The QModelIndex class is used to locate data in a data model.

◆ sort_source_rows()

void QSortFilterProxyModelPrivate::sort_source_rows ( QVector< int > &  source_rows,
const QModelIndex source_parent 
) const

Sorts the given source_rows according to current sort column and order.

Warning
This function is not part of the public interface.

Definition at line 465 of file qsortfilterproxymodel.cpp.

467 {
468  Q_Q(const QSortFilterProxyModel);
469  if (source_sort_column >= 0) {
472  qStableSort(source_rows.begin(), source_rows.end(), lt);
473  } else {
475  qStableSort(source_rows.begin(), source_rows.end(), gt);
476  }
477  } else { // restore the source model order
478  qStableSort(source_rows.begin(), source_rows.end());
479  }
480 }
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the vector...
Definition: qvector.h:250
#define Q_Q(Class)
Definition: qglobal.h:2483
void qStableSort(RandomAccessIterator start, RandomAccessIterator end)
Definition: qalgorithms.h:202
The QSortFilterProxyModel class provides support for sorting and filtering data passed between anothe...
iterator begin()
Returns an STL-style iterator pointing to the first item in the vector.
Definition: qvector.h:247

◆ source_items_about_to_be_removed()

void QSortFilterProxyModelPrivate::source_items_about_to_be_removed ( const QModelIndex source_parent,
int  start,
int  end,
Qt::Orientation  orient 
)

Handles source model items removal (columnsAboutToBeRemoved(), rowsAboutToBeRemoved()).

Warning
This function is not part of the public interface.

Definition at line 842 of file qsortfilterproxymodel.cpp.

844 {
845  if ((start < 0) || (end < 0))
846  return;
847  IndexMap::const_iterator it = source_index_mapping.constFind(source_parent);
848  if (it == source_index_mapping.constEnd()) {
849  // Don't care, since we don't have mapping for this index
850  return;
851  }
852 
853  Mapping *m = it.value();
854  QVector<int> &source_to_proxy = (orient == Qt::Vertical) ? m->proxy_rows : m->proxy_columns;
855  QVector<int> &proxy_to_source = (orient == Qt::Vertical) ? m->source_rows : m->source_columns;
856 
857  // figure out which items to remove
858  QVector<int> source_items_to_remove;
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);
864  }
865 
866  remove_source_items(source_to_proxy, proxy_to_source, source_items_to_remove,
867  source_parent, orient);
868 }
#define it(className, varName)
void append(const T &t)
Inserts value at the end of the vector.
Definition: qvector.h:573
QModelIndex proxy_to_source(const QModelIndex &proxyIndex) const
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.
QHash< QModelIndex, Mapping * > source_index_mapping
QModelIndex source_to_proxy(const QModelIndex &sourceIndex) const
static const KeyPair *const end

◆ source_items_inserted()

void QSortFilterProxyModelPrivate::source_items_inserted ( const QModelIndex source_parent,
int  start,
int  end,
Qt::Orientation  orient 
)

Handles source model items insertion (columnsInserted(), rowsInserted()).

Warning
This function is not part of the public interface.

Determines 1) which of the inserted items to also insert into proxy model (filtering), 2) where to insert the items into the proxy model (sorting), then inserts those items. The items are inserted into the proxy model in intervals (based on sorted order), so that the proper rows/columnsInserted(start, end) signals will be generated.

Definition at line 738 of file qsortfilterproxymodel.cpp.

740 {
742  if ((start < 0) || (end < 0))
743  return;
744  IndexMap::const_iterator it = source_index_mapping.constFind(source_parent);
745  if (it == source_index_mapping.constEnd()) {
746  if (!can_create_mapping(source_parent))
747  return;
748  it = create_mapping(source_parent);
749  Mapping *m = it.value();
750  QModelIndex proxy_parent = q->mapFromSource(source_parent);
751  if (m->source_rows.count() > 0) {
752  q->beginInsertRows(proxy_parent, 0, m->source_rows.count() - 1);
753  q->endInsertRows();
754  }
755  if (m->source_columns.count() > 0) {
756  q->beginInsertColumns(proxy_parent, 0, m->source_columns.count() - 1);
757  q->endInsertColumns();
758  }
759  return;
760  }
761 
762  Mapping *m = it.value();
763  QVector<int> &source_to_proxy = (orient == Qt::Vertical) ? m->proxy_rows : m->proxy_columns;
764  QVector<int> &proxy_to_source = (orient == Qt::Vertical) ? m->source_rows : m->source_columns;
765 
766  int delta_item_count = end - start + 1;
767  int old_item_count = source_to_proxy.size();
768 
769  updateChildrenMapping(source_parent, m, orient, start, end, delta_item_count, false);
770 
771  // Expand source-to-proxy mapping to account for new items
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);
775  return;
776  }
777  source_to_proxy.insert(start, delta_item_count, -1);
778 
779  if (start < old_item_count) {
780  // Adjust existing "stale" indexes in proxy-to-source mapping
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);
786  }
788  }
789 
790  // Figure out which items to add to mapping based on filter
791  QVector<int> source_items;
792  for (int i = start; i <= end; ++i) {
793  if ((orient == Qt::Vertical)
794  ? q->filterAcceptsRow(i, source_parent)
795  : q->filterAcceptsColumn(i, source_parent)) {
796  source_items.append(i);
797  }
798  }
799 
800  if (model->rowCount(source_parent) == delta_item_count) {
801  // Items were inserted where there were none before.
802  // If it was new rows make sure to create mappings for columns so that a
803  // valid mapping can be retrieved later and vice-versa.
804 
805  QVector<int> &orthogonal_proxy_to_source = (orient == Qt::Horizontal) ? m->source_rows : m->source_columns;
806  QVector<int> &orthogonal_source_to_proxy = (orient == Qt::Horizontal) ? m->proxy_rows : m->proxy_columns;
807 
808  if (orthogonal_source_to_proxy.isEmpty()) {
809  const int ortho_end = (orient == Qt::Horizontal) ? model->rowCount(source_parent) : model->columnCount(source_parent);
810 
811  orthogonal_source_to_proxy.resize(ortho_end);
812 
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);
817  }
818  }
819  if (orient == Qt::Horizontal) {
820  // We're reacting to columnsInserted, but we've just inserted new rows. Sort them.
821  sort_source_rows(orthogonal_proxy_to_source, source_parent);
822  }
823  build_source_to_proxy_mapping(orthogonal_proxy_to_source, orthogonal_source_to_proxy);
824  }
825  }
826 
827  // Sort and insert the items
828  if (orient == Qt::Vertical) // Only sort rows
829  sort_source_rows(source_items, source_parent);
830  insert_source_items(source_to_proxy, proxy_to_source, source_items, source_parent, orient);
831 }
virtual int columnCount(const QModelIndex &parent=QModelIndex()) const =0
Returns the number of columns for the children of the given parent.
#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 updateChildrenMapping(const QModelIndex &source_parent, Mapping *parent_mapping, Qt::Orientation orient, int start, int end, int delta_item_count, bool remove)
virtual int rowCount(const QModelIndex &parent=QModelIndex()) const =0
Returns the number of rows under the given parent.
void build_source_to_proxy_mapping(const QVector< int > &proxy_to_source, QVector< int > &source_to_proxy) const
#define Q_Q(Class)
Definition: qglobal.h:2483
void append(const T &t)
Inserts value at the end of the vector.
Definition: qvector.h:573
Q_CORE_EXPORT void qWarning(const char *,...)
QModelIndex proxy_to_source(const QModelIndex &proxyIndex) const
QHash< QModelIndex, Mapping * > source_index_mapping
void insert(int i, const T &t)
Inserts value at index position i in the vector.
Definition: qvector.h:362
The QSortFilterProxyModel class provides support for sorting and filtering data passed between anothe...
QModelIndex source_to_proxy(const QModelIndex &sourceIndex) const
The QModelIndex class is used to locate data in a data model.
QHash< QModelIndex, Mapping * >::const_iterator create_mapping(const QModelIndex &source_parent) const
bool can_create_mapping(const QModelIndex &source_parent) const
static const KeyPair *const end
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137
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.

◆ source_items_removed()

void QSortFilterProxyModelPrivate::source_items_removed ( const QModelIndex source_parent,
int  start,
int  end,
Qt::Orientation  orient 
)

Handles source model items removal (columnsRemoved(), rowsRemoved()).

Warning
This function is not part of the public interface.

Definition at line 878 of file qsortfilterproxymodel.cpp.

880 {
881  if ((start < 0) || (end < 0))
882  return;
883  IndexMap::const_iterator it = source_index_mapping.constFind(source_parent);
884  if (it == source_index_mapping.constEnd()) {
885  // Don't care, since we don't have mapping for this index
886  return;
887  }
888 
889  Mapping *m = it.value();
890  QVector<int> &source_to_proxy = (orient == Qt::Vertical) ? m->proxy_rows : m->proxy_columns;
891  QVector<int> &proxy_to_source = (orient == Qt::Vertical) ? m->source_rows : m->source_columns;
892 
893  if (end >= source_to_proxy.size())
894  end = source_to_proxy.size() - 1;
895 
896  // Shrink the source-to-proxy mapping to reflect the new item count
897  int delta_item_count = end - start + 1;
898  source_to_proxy.remove(start, delta_item_count);
899 
900  int proxy_count = proxy_to_source.size();
901  if (proxy_count > source_to_proxy.size()) {
902  // mapping is in an inconsistent state -- redo the whole mapping
903  qWarning("QSortFilterProxyModel: inconsistent changes reported by source model");
904  remove_from_mapping(source_parent);
906  q->reset();
907  return;
908  }
909 
910  // Adjust "stale" indexes in proxy-to-source mapping
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);
916  }
917  }
919 
920  updateChildrenMapping(source_parent, m, orient, start, end, delta_item_count, true);
921 
922 }
void remove(int i)
Removes the element at index position i.
Definition: qvector.h:374
#define it(className, varName)
void updateChildrenMapping(const QModelIndex &source_parent, Mapping *parent_mapping, Qt::Orientation orient, int start, int end, int delta_item_count, bool remove)
void build_source_to_proxy_mapping(const QVector< int > &proxy_to_source, QVector< int > &source_to_proxy) const
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
#define Q_Q(Class)
Definition: qglobal.h:2483
Q_CORE_EXPORT void qWarning(const char *,...)
QModelIndex proxy_to_source(const QModelIndex &proxyIndex) const
QHash< QModelIndex, Mapping * > source_index_mapping
The QSortFilterProxyModel class provides support for sorting and filtering data passed between anothe...
QModelIndex source_to_proxy(const QModelIndex &sourceIndex) const
static const KeyPair *const end
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137
void remove_from_mapping(const QModelIndex &source_parent)

◆ source_to_proxy()

QModelIndex QSortFilterProxyModelPrivate::source_to_proxy ( const QModelIndex sourceIndex) const

Definition at line 377 of file qsortfilterproxymodel.cpp.

378 {
379  if (!source_index.isValid())
380  return QModelIndex(); // for now; we may want to be able to set a root index later
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");
384  return QModelIndex();
385  }
386  QModelIndex source_parent = source_index.parent();
387  IndexMap::const_iterator it = create_mapping(source_parent);
388  Mapping *m = it.value();
389  if ((source_index.row() >= m->proxy_rows.size()) || (source_index.column() >= m->proxy_columns.size()))
390  return QModelIndex();
391  int proxy_row = m->proxy_rows.at(source_index.row());
392  int proxy_column = m->proxy_columns.at(source_index.column());
393  if (proxy_row == -1 || proxy_column == -1)
394  return QModelIndex();
395  return create_index(proxy_row, proxy_column, it);
396 }
#define it(className, varName)
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
QModelIndex parent() const
Returns the parent of the model index, or QModelIndex() if it has no parent.
Q_CORE_EXPORT void qWarning(const char *,...)
The QModelIndex class is used to locate data in a data model.
QModelIndex create_index(int row, int column, QHash< QModelIndex, Mapping *>::const_iterator it) const
QHash< QModelIndex, Mapping * >::const_iterator create_mapping(const QModelIndex &source_parent) const

◆ store_persistent_indexes()

QModelIndexPairList QSortFilterProxyModelPrivate::store_persistent_indexes ( )

Maps the persistent proxy indexes to source indexes and returns the list of source indexes.

Warning
This function is not part of the public interface.

Definition at line 1023 of file qsortfilterproxymodel.cpp.

1024 {
1026  QModelIndexPairList source_indexes;
1028  QModelIndex proxy_index = data->index;
1029  QModelIndex source_index = q->mapToSource(proxy_index);
1030  source_indexes.append(qMakePair(proxy_index, QPersistentModelIndex(source_index)));
1031  }
1032  return source_indexes;
1033 }
QHash< QModelIndex, QPersistentModelIndexData * > indexes
#define Q_Q(Class)
Definition: qglobal.h:2483
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
static const char * data(const QByteArray &arr)
struct QAbstractItemModelPrivate::Persistent persistent
The QSortFilterProxyModel class provides support for sorting and filtering data passed between anothe...
The QPersistentModelIndex class is used to locate data in a data model.
Q_OUTOFLINE_TEMPLATE QPair< T1, T2 > qMakePair(const T1 &x, const T2 &y)
Definition: qpair.h:102
The QModelIndex class is used to locate data in a data model.

◆ update_persistent_indexes()

void QSortFilterProxyModelPrivate::update_persistent_indexes ( const QModelIndexPairList source_indexes)

Maps source_indexes to proxy indexes and stores those as persistent indexes.

Warning
This function is not part of the public interface.

Definition at line 1044 of file qsortfilterproxymodel.cpp.

1046 {
1048  QModelIndexList from, to;
1049  for (int i = 0; i < source_indexes.count(); ++i) {
1050  QModelIndex source_index = source_indexes.at(i).second;
1051  QModelIndex old_proxy_index = source_indexes.at(i).first;
1052  create_mapping(source_index.parent());
1053  QModelIndex proxy_index = q->mapFromSource(source_index);
1054  from << old_proxy_index;
1055  to << proxy_index;
1056  }
1057  q->changePersistentIndexList(from, to);
1058 }
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
QModelIndex parent() const
Returns the parent of the model index, or QModelIndex() if it has no parent.
#define Q_Q(Class)
Definition: qglobal.h:2483
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
The QSortFilterProxyModel class provides support for sorting and filtering data passed between anothe...
The QModelIndex class is used to locate data in a data model.
QHash< QModelIndex, Mapping * >::const_iterator create_mapping(const QModelIndex &source_parent) const

◆ update_source_sort_column()

bool QSortFilterProxyModelPrivate::update_source_sort_column ( )
Warning
This function is not part of the public interface.

update the source_sort_column according to the proxy_sort_column return true if the column was changed

Definition at line 447 of file qsortfilterproxymodel.cpp.

448 {
450  QModelIndex proxy_index = q->index(0, proxy_sort_column, QModelIndex());
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;
454 }
#define Q_Q(Class)
Definition: qglobal.h:2483
The QSortFilterProxyModel class provides support for sorting and filtering data passed between anothe...
The QModelIndex class is used to locate data in a data model.

◆ updateChildrenMapping()

void QSortFilterProxyModelPrivate::updateChildrenMapping ( const QModelIndex source_parent,
Mapping parent_mapping,
Qt::Orientation  orient,
int  start,
int  end,
int  delta_item_count,
bool  remove 
)
Warning
This function is not part of the public interface. updates the mapping of the children when inserting or removing items

Definition at line 929 of file qsortfilterproxymodel.cpp.

931 {
932  // see if any mapped children should be (re)moved
933  QVector<QPair<QModelIndex, Mapping*> > moved_source_index_mappings;
934  QVector<QModelIndex>::iterator it2 = parent_mapping->mapped_children.begin();
935  for ( ; it2 != parent_mapping->mapped_children.end();) {
936  const QModelIndex source_child_index = *it2;
937  const int pos = (orient == Qt::Vertical)
938  ? source_child_index.row()
939  : source_child_index.column();
940  if (pos < start) {
941  // not affected
942  ++it2;
943  } else if (remove && pos <= end) {
944  // in the removed interval
945  it2 = parent_mapping->mapped_children.erase(it2);
946  remove_from_mapping(source_child_index);
947  } else {
948  // below the removed items -- recompute the index
949  QModelIndex new_index;
950  const int newpos = remove ? pos - delta_item_count : pos + delta_item_count;
951  if (orient == Qt::Vertical) {
952  new_index = model->index(newpos,
953  source_child_index.column(),
954  source_parent);
955  } else {
956  new_index = model->index(source_child_index.row(),
957  newpos,
958  source_parent);
959  }
960  *it2 = new_index;
961  ++it2;
962 
963  // update mapping
964  Mapping *cm = source_index_mapping.take(source_child_index);
965  Q_ASSERT(cm);
966  // we do not reinsert right away, because the new index might be identical with another, old index
967  moved_source_index_mappings.append(QPair<QModelIndex, Mapping*>(new_index, cm));
968  }
969  }
970 
971  // reinsert moved, mapped indexes
972  QVector<QPair<QModelIndex, Mapping*> >::iterator it = moved_source_index_mappings.begin();
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);
977 #else
978  (*it).second->map_iter = source_index_mapping.insert((*it).first, (*it).second);
979 #endif
980  }
981 }
#define it(className, varName)
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
The QVector class is a template class that provides a dynamic array.
Definition: qdatastream.h:64
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the vector...
Definition: qvector.h:250
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...
int row() const
Returns the row this model index refers to.
void append(const T &t)
Inserts value at the end of the vector.
Definition: qvector.h:573
QHash< QModelIndex, Mapping * > source_index_mapping
iterator begin()
Returns an STL-style iterator pointing to the first item in the vector.
Definition: qvector.h:247
iterator erase(iterator begin, iterator end)
Removes all the items from begin up to (but not including) end.
Definition: qvector.h:627
The QModelIndex class is used to locate data in a data model.
static const KeyPair *const end
int column() const
Returns the column this model index refers to.
void remove_from_mapping(const QModelIndex &source_parent)

Properties

◆ dynamic_sortfilter

bool QSortFilterProxyModelPrivate::dynamic_sortfilter

Definition at line 170 of file qsortfilterproxymodel.cpp.

◆ filter_column

int QSortFilterProxyModelPrivate::filter_column

Definition at line 166 of file qsortfilterproxymodel.cpp.

◆ filter_regexp

QRegExp QSortFilterProxyModelPrivate::filter_regexp

Definition at line 167 of file qsortfilterproxymodel.cpp.

◆ filter_role

int QSortFilterProxyModelPrivate::filter_role

Definition at line 168 of file qsortfilterproxymodel.cpp.

◆ itemsBeingRemoved

QRowsRemoval QSortFilterProxyModelPrivate::itemsBeingRemoved

Definition at line 171 of file qsortfilterproxymodel.cpp.

◆ proxy_sort_column

int QSortFilterProxyModelPrivate::proxy_sort_column

Definition at line 160 of file qsortfilterproxymodel.cpp.

◆ saved_persistent_indexes

QModelIndexPairList QSortFilterProxyModelPrivate::saved_persistent_indexes

Definition at line 173 of file qsortfilterproxymodel.cpp.

◆ sort_casesensitivity

Qt::CaseSensitivity QSortFilterProxyModelPrivate::sort_casesensitivity

Definition at line 162 of file qsortfilterproxymodel.cpp.

◆ sort_localeaware

bool QSortFilterProxyModelPrivate::sort_localeaware

Definition at line 164 of file qsortfilterproxymodel.cpp.

◆ sort_order

Qt::SortOrder QSortFilterProxyModelPrivate::sort_order

Definition at line 161 of file qsortfilterproxymodel.cpp.

◆ sort_role

int QSortFilterProxyModelPrivate::sort_role

Definition at line 163 of file qsortfilterproxymodel.cpp.

◆ source_index_mapping

QHash<QModelIndex, Mapping*> QSortFilterProxyModelPrivate::source_index_mapping
mutable

Definition at line 157 of file qsortfilterproxymodel.cpp.

◆ source_sort_column

int QSortFilterProxyModelPrivate::source_sort_column

Definition at line 159 of file qsortfilterproxymodel.cpp.


The documentation for this class was generated from the following file: