| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/corelib/itemmodels/qsortfilterproxymodel.cpp |
| Switch to Source code | Preprocessed file |
| Line | Source | Count | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | - | |||||||||||||||||||||||||
| 2 | - | |||||||||||||||||||||||||
| 3 | - | |||||||||||||||||||||||||
| 4 | - | |||||||||||||||||||||||||
| 5 | - | |||||||||||||||||||||||||
| 6 | - | |||||||||||||||||||||||||
| 7 | - | |||||||||||||||||||||||||
| 8 | - | |||||||||||||||||||||||||
| 9 | typedef QListQVector<QPair<QModelIndex, QPersistentModelIndex> > QModelIndexPairList; | - | ||||||||||||||||||||||||
| 10 | - | |||||||||||||||||||||||||
| 11 | static inline QSet<int> qVectorToSet(const QVector<int> &vector) | - | ||||||||||||||||||||||||
| 12 | { | - | ||||||||||||||||||||||||
| 13 | QSet<int> set; | - | ||||||||||||||||||||||||
| 14 | set.reserve(vector.size()); | - | ||||||||||||||||||||||||
| 15 | for(int i=0; i < vector.size(); ++i) | - | ||||||||||||||||||||||||
| 16 | set << vector.at(i); | - | ||||||||||||||||||||||||
| 17 | return set; | - | ||||||||||||||||||||||||
| 18 | } | - | ||||||||||||||||||||||||
| 19 | - | |||||||||||||||||||||||||
| 20 | class QSortFilterProxyModelLessThan | - | ||||||||||||||||||||||||
| 21 | { | - | ||||||||||||||||||||||||
| 22 | public: | - | ||||||||||||||||||||||||
| 23 | inline QSortFilterProxyModelLessThan(int column, const QModelIndex &parent, | - | ||||||||||||||||||||||||
| 24 | const QAbstractItemModel *source, | - | ||||||||||||||||||||||||
| 25 | const QSortFilterProxyModel *proxy) | - | ||||||||||||||||||||||||
| 26 | : sort_column(column), source_parent(parent), source_model(source), proxy_model(proxy) {} | - | ||||||||||||||||||||||||
| 27 | - | |||||||||||||||||||||||||
| 28 | inline bool operator()(int r1, int r2) const | - | ||||||||||||||||||||||||
| 29 | { | - | ||||||||||||||||||||||||
| 30 | QModelIndex i1 = source_model->index(r1, sort_column, source_parent); | - | ||||||||||||||||||||||||
| 31 | QModelIndex i2 = source_model->index(r2, sort_column, source_parent); | - | ||||||||||||||||||||||||
| 32 | return proxy_model->lessThan(i1, i2); | - | ||||||||||||||||||||||||
| 33 | } | - | ||||||||||||||||||||||||
| 34 | - | |||||||||||||||||||||||||
| 35 | private: | - | ||||||||||||||||||||||||
| 36 | int sort_column; | - | ||||||||||||||||||||||||
| 37 | QModelIndex source_parent; | - | ||||||||||||||||||||||||
| 38 | const QAbstractItemModel *source_model; | - | ||||||||||||||||||||||||
| 39 | const QSortFilterProxyModel *proxy_model; | - | ||||||||||||||||||||||||
| 40 | }; | - | ||||||||||||||||||||||||
| 41 | - | |||||||||||||||||||||||||
| 42 | class QSortFilterProxyModelGreaterThan | - | ||||||||||||||||||||||||
| 43 | { | - | ||||||||||||||||||||||||
| 44 | public: | - | ||||||||||||||||||||||||
| 45 | inline QSortFilterProxyModelGreaterThan(int column, const QModelIndex &parent, | - | ||||||||||||||||||||||||
| 46 | const QAbstractItemModel *source, | - | ||||||||||||||||||||||||
| 47 | const QSortFilterProxyModel *proxy) | - | ||||||||||||||||||||||||
| 48 | : sort_column(column), source_parent(parent), | - | ||||||||||||||||||||||||
| 49 | source_model(source), proxy_model(proxy) {} | - | ||||||||||||||||||||||||
| 50 | - | |||||||||||||||||||||||||
| 51 | inline bool operator()(int r1, int r2) const | - | ||||||||||||||||||||||||
| 52 | { | - | ||||||||||||||||||||||||
| 53 | QModelIndex i1 = source_model->index(r1, sort_column, source_parent); | - | ||||||||||||||||||||||||
| 54 | QModelIndex i2 = source_model->index(r2, sort_column, source_parent); | - | ||||||||||||||||||||||||
| 55 | return proxy_model->lessThan(i2, i1); | - | ||||||||||||||||||||||||
| 56 | } | - | ||||||||||||||||||||||||
| 57 | - | |||||||||||||||||||||||||
| 58 | private: | - | ||||||||||||||||||||||||
| 59 | int sort_column; | - | ||||||||||||||||||||||||
| 60 | QModelIndex source_parent; | - | ||||||||||||||||||||||||
| 61 | const QAbstractItemModel *source_model; | - | ||||||||||||||||||||||||
| 62 | const QSortFilterProxyModel *proxy_model; | - | ||||||||||||||||||||||||
| 63 | }; | - | ||||||||||||||||||||||||
| 64 | - | |||||||||||||||||||||||||
| 65 | - | |||||||||||||||||||||||||
| 66 | - | |||||||||||||||||||||||||
| 67 | - | |||||||||||||||||||||||||
| 68 | - | |||||||||||||||||||||||||
| 69 | struct QRowsRemoval | - | ||||||||||||||||||||||||
| 70 | { | - | ||||||||||||||||||||||||
| 71 | QRowsRemoval(const QModelIndex &parent_source, int start, int end) : parent_source(parent_source), start(start), end(end) | - | ||||||||||||||||||||||||
| 72 | { | - | ||||||||||||||||||||||||
| 73 | } | - | ||||||||||||||||||||||||
| 74 | - | |||||||||||||||||||||||||
| 75 | QRowsRemoval() : start(-1), end(-1) | - | ||||||||||||||||||||||||
| 76 | { | - | ||||||||||||||||||||||||
| 77 | } | - | ||||||||||||||||||||||||
| 78 | - | |||||||||||||||||||||||||
| 79 | bool contains(QModelIndex parent, int row) | - | ||||||||||||||||||||||||
| 80 | { | - | ||||||||||||||||||||||||
| 81 | do { | - | ||||||||||||||||||||||||
| 82 | if (parent == parent_source) | - | ||||||||||||||||||||||||
| 83 | return row >= start && row <= end; | - | ||||||||||||||||||||||||
| 84 | row = parent.row(); | - | ||||||||||||||||||||||||
| 85 | parent = parent.parent(); | - | ||||||||||||||||||||||||
| 86 | } while (row >= 0); | - | ||||||||||||||||||||||||
| 87 | return false; | - | ||||||||||||||||||||||||
| 88 | } | - | ||||||||||||||||||||||||
| 89 | private: | - | ||||||||||||||||||||||||
| 90 | QModelIndex parent_source; | - | ||||||||||||||||||||||||
| 91 | int start; | - | ||||||||||||||||||||||||
| 92 | int end; | - | ||||||||||||||||||||||||
| 93 | }; | - | ||||||||||||||||||||||||
| 94 | - | |||||||||||||||||||||||||
| 95 | class QSortFilterProxyModelPrivate : public QAbstractProxyModelPrivate | - | ||||||||||||||||||||||||
| 96 | { | - | ||||||||||||||||||||||||
| 97 | inline QSortFilterProxyModel* q_func() { return static_cast<QSortFilterProxyModel *>(q_ptr); } inline const QSortFilterProxyModel* q_func() const { return static_cast<const QSortFilterProxyModel *>(q_ptr); } friend class QSortFilterProxyModel; | - | ||||||||||||||||||||||||
| 98 | - | |||||||||||||||||||||||||
| 99 | public: | - | ||||||||||||||||||||||||
| 100 | struct Mapping { | - | ||||||||||||||||||||||||
| 101 | QVector<int> source_rows; | - | ||||||||||||||||||||||||
| 102 | QVector<int> source_columns; | - | ||||||||||||||||||||||||
| 103 | QVector<int> proxy_rows; | - | ||||||||||||||||||||||||
| 104 | QVector<int> proxy_columns; | - | ||||||||||||||||||||||||
| 105 | QVector<QModelIndex> mapped_children; | - | ||||||||||||||||||||||||
| 106 | QHash<QModelIndex, Mapping *>::const_iterator map_iter; | - | ||||||||||||||||||||||||
| 107 | }; | - | ||||||||||||||||||||||||
| 108 | - | |||||||||||||||||||||||||
| 109 | mutable QHash<QModelIndex, Mapping*> source_index_mapping; | - | ||||||||||||||||||||||||
| 110 | - | |||||||||||||||||||||||||
| 111 | int source_sort_column; | - | ||||||||||||||||||||||||
| 112 | int proxy_sort_column; | - | ||||||||||||||||||||||||
| 113 | Qt::SortOrder sort_order; | - | ||||||||||||||||||||||||
| 114 | Qt::CaseSensitivity sort_casesensitivity; | - | ||||||||||||||||||||||||
| 115 | int sort_role; | - | ||||||||||||||||||||||||
| 116 | bool sort_localeaware; | - | ||||||||||||||||||||||||
| 117 | - | |||||||||||||||||||||||||
| 118 | int filter_column; | - | ||||||||||||||||||||||||
| 119 | QRegExp filter_regexp; | - | ||||||||||||||||||||||||
| 120 | int filter_role; | - | ||||||||||||||||||||||||
| 121 | - | |||||||||||||||||||||||||
| 122 | bool dynamic_sortfilter; | - | ||||||||||||||||||||||||
| 123 | QRowsRemoval itemsBeingRemoved; | - | ||||||||||||||||||||||||
| 124 | - | |||||||||||||||||||||||||
| 125 | QModelIndexPairList saved_persistent_indexes; | - | ||||||||||||||||||||||||
| 126 | - | |||||||||||||||||||||||||
| 127 | QHash<QModelIndex, Mapping *>::const_iterator create_mapping( | - | ||||||||||||||||||||||||
| 128 | const QModelIndex &source_parent) const; | - | ||||||||||||||||||||||||
| 129 | QModelIndex proxy_to_source(const QModelIndex &proxyIndex) const; | - | ||||||||||||||||||||||||
| 130 | QModelIndex source_to_proxy(const QModelIndex &sourceIndex) const; | - | ||||||||||||||||||||||||
| 131 | bool can_create_mapping(const QModelIndex &source_parent) const; | - | ||||||||||||||||||||||||
| 132 | - | |||||||||||||||||||||||||
| 133 | void remove_from_mapping(const QModelIndex &source_parent); | - | ||||||||||||||||||||||||
| 134 | - | |||||||||||||||||||||||||
| 135 | inline QHash<QModelIndex, Mapping *>::const_iterator index_to_iterator( | - | ||||||||||||||||||||||||
| 136 | const QModelIndex &proxy_index) const | - | ||||||||||||||||||||||||
| 137 | { | - | ||||||||||||||||||||||||
| 138 | ((!(proxy_index.isValid())) ? qt_assert("proxy_index.isValid()",__FILE__,180186) : qt_noop()); | - | ||||||||||||||||||||||||
| 139 | ((!(proxy_index.model() == q_func())) ? qt_assert("proxy_index.model() == q_func()",__FILE__,181187) : qt_noop()); | - | ||||||||||||||||||||||||
| 140 | const void *p = proxy_index.internalPointer(); | - | ||||||||||||||||||||||||
| 141 | ((!(p)) ? qt_assert("p",__FILE__,183189) : qt_noop()); | - | ||||||||||||||||||||||||
| 142 | QHash<QModelIndex, Mapping *>::const_iterator it = | - | ||||||||||||||||||||||||
| 143 | static_cast<const Mapping*>(p)->map_iter; | - | ||||||||||||||||||||||||
| 144 | ((!(it != source_index_mapping.constEnd())) ? qt_assert("it != source_index_mapping.constEnd()",__FILE__,186192) : qt_noop()); | - | ||||||||||||||||||||||||
| 145 | ((!(it.value())) ? qt_assert("it.value()",__FILE__,187193) : qt_noop()); | - | ||||||||||||||||||||||||
| 146 | return it; | - | ||||||||||||||||||||||||
| 147 | } | - | ||||||||||||||||||||||||
| 148 | - | |||||||||||||||||||||||||
| 149 | inline QModelIndex create_index(int row, int column, | - | ||||||||||||||||||||||||
| 150 | QHash<QModelIndex, Mapping*>::const_iterator it) const | - | ||||||||||||||||||||||||
| 151 | { | - | ||||||||||||||||||||||||
| 152 | return q_func()->createIndex(row, column, *it); | - | ||||||||||||||||||||||||
| 153 | } | - | ||||||||||||||||||||||||
| 154 | - | |||||||||||||||||||||||||
| 155 | void _q_sourceDataChanged(const QModelIndex &source_top_left, | - | ||||||||||||||||||||||||
| 156 | const QModelIndex &source_bottom_right, | - | ||||||||||||||||||||||||
| 157 | const QVector<int> &roles); | - | ||||||||||||||||||||||||
| 158 | void _q_sourceHeaderDataChanged(Qt::Orientation orientation, int start, int end); | - | ||||||||||||||||||||||||
| 159 | - | |||||||||||||||||||||||||
| 160 | void _q_sourceAboutToBeReset(); | - | ||||||||||||||||||||||||
| 161 | void _q_sourceReset(); | - | ||||||||||||||||||||||||
| 162 | - | |||||||||||||||||||||||||
| 163 | void _q_sourceLayoutAboutToBeChanged(const QList<QPersistentModelIndex> &sourceParents, QAbstractItemModel::LayoutChangeHint hint); | - | ||||||||||||||||||||||||
| 164 | void _q_sourceLayoutChanged(const QList<QPersistentModelIndex> &sourceParents, QAbstractItemModel::LayoutChangeHint hint); | - | ||||||||||||||||||||||||
| 165 | - | |||||||||||||||||||||||||
| 166 | void _q_sourceRowsAboutToBeInserted(const QModelIndex &source_parent, | - | ||||||||||||||||||||||||
| 167 | int start, int end); | - | ||||||||||||||||||||||||
| 168 | void _q_sourceRowsInserted(const QModelIndex &source_parent, | - | ||||||||||||||||||||||||
| 169 | int start, int end); | - | ||||||||||||||||||||||||
| 170 | void _q_sourceRowsAboutToBeRemoved(const QModelIndex &source_parent, | - | ||||||||||||||||||||||||
| 171 | int start, int end); | - | ||||||||||||||||||||||||
| 172 | void _q_sourceRowsRemoved(const QModelIndex &source_parent, | - | ||||||||||||||||||||||||
| 173 | int start, int end); | - | ||||||||||||||||||||||||
| 174 | void _q_sourceRowsAboutToBeMoved(const QModelIndex &sourceParent, | - | ||||||||||||||||||||||||
| 175 | int sourceStart, int sourceEnd, | - | ||||||||||||||||||||||||
| 176 | const QModelIndex &destParent, int dest); | - | ||||||||||||||||||||||||
| 177 | void _q_sourceRowsMoved(const QModelIndex &sourceParent, | - | ||||||||||||||||||||||||
| 178 | int sourceStart, int sourceEnd, | - | ||||||||||||||||||||||||
| 179 | const QModelIndex &destParent, int dest); | - | ||||||||||||||||||||||||
| 180 | void _q_sourceColumnsAboutToBeInserted(const QModelIndex &source_parent, | - | ||||||||||||||||||||||||
| 181 | int start, int end); | - | ||||||||||||||||||||||||
| 182 | void _q_sourceColumnsInserted(const QModelIndex &source_parent, | - | ||||||||||||||||||||||||
| 183 | int start, int end); | - | ||||||||||||||||||||||||
| 184 | void _q_sourceColumnsAboutToBeRemoved(const QModelIndex &source_parent, | - | ||||||||||||||||||||||||
| 185 | int start, int end); | - | ||||||||||||||||||||||||
| 186 | void _q_sourceColumnsRemoved(const QModelIndex &source_parent, | - | ||||||||||||||||||||||||
| 187 | int start, int end); | - | ||||||||||||||||||||||||
| 188 | void _q_sourceColumnsAboutToBeMoved(const QModelIndex &sourceParent, | - | ||||||||||||||||||||||||
| 189 | int sourceStart, int sourceEnd, | - | ||||||||||||||||||||||||
| 190 | const QModelIndex &destParent, int dest); | - | ||||||||||||||||||||||||
| 191 | void _q_sourceColumnsMoved(const QModelIndex &sourceParent, | - | ||||||||||||||||||||||||
| 192 | int sourceStart, int sourceEnd, | - | ||||||||||||||||||||||||
| 193 | const QModelIndex &destParent, int dest); | - | ||||||||||||||||||||||||
| 194 | - | |||||||||||||||||||||||||
| 195 | void _q_clearMapping(); | - | ||||||||||||||||||||||||
| 196 | - | |||||||||||||||||||||||||
| 197 | void sort(); | - | ||||||||||||||||||||||||
| 198 | bool update_source_sort_column(); | - | ||||||||||||||||||||||||
| 199 | void sort_source_rows(QVector<int> &source_rows, | - | ||||||||||||||||||||||||
| 200 | const QModelIndex &source_parent) const; | - | ||||||||||||||||||||||||
| 201 | QVector<QPair<int, QVector<int > > > proxy_intervals_for_source_items_to_add( | - | ||||||||||||||||||||||||
| 202 | const QVector<int> &proxy_to_source, const QVector<int> &source_items, | - | ||||||||||||||||||||||||
| 203 | const QModelIndex &source_parent, Qt::Orientation orient) const; | - | ||||||||||||||||||||||||
| 204 | QVector<QPair<int, int > > proxy_intervals_for_source_items( | - | ||||||||||||||||||||||||
| 205 | const QVector<int> &source_to_proxy, const QVector<int> &source_items) const; | - | ||||||||||||||||||||||||
| 206 | void insert_source_items( | - | ||||||||||||||||||||||||
| 207 | QVector<int> &source_to_proxy, QVector<int> &proxy_to_source, | - | ||||||||||||||||||||||||
| 208 | const QVector<int> &source_items, const QModelIndex &source_parent, | - | ||||||||||||||||||||||||
| 209 | Qt::Orientation orient, bool emit_signal = true); | - | ||||||||||||||||||||||||
| 210 | void remove_source_items( | - | ||||||||||||||||||||||||
| 211 | QVector<int> &source_to_proxy, QVector<int> &proxy_to_source, | - | ||||||||||||||||||||||||
| 212 | const QVector<int> &source_items, const QModelIndex &source_parent, | - | ||||||||||||||||||||||||
| 213 | Qt::Orientation orient, bool emit_signal = true); | - | ||||||||||||||||||||||||
| 214 | void remove_proxy_interval( | - | ||||||||||||||||||||||||
| 215 | QVector<int> &source_to_proxy, QVector<int> &proxy_to_source, | - | ||||||||||||||||||||||||
| 216 | int proxy_start, int proxy_end, const QModelIndex &proxy_parent, | - | ||||||||||||||||||||||||
| 217 | Qt::Orientation orient, bool emit_signal = true); | - | ||||||||||||||||||||||||
| 218 | void build_source_to_proxy_mapping( | - | ||||||||||||||||||||||||
| 219 | const QVector<int> &proxy_to_source, QVector<int> &source_to_proxy) const; | - | ||||||||||||||||||||||||
| 220 | void source_items_inserted(const QModelIndex &source_parent, | - | ||||||||||||||||||||||||
| 221 | int start, int end, Qt::Orientation orient); | - | ||||||||||||||||||||||||
| 222 | void source_items_about_to_be_removed(const QModelIndex &source_parent, | - | ||||||||||||||||||||||||
| 223 | int start, int end, Qt::Orientation orient); | - | ||||||||||||||||||||||||
| 224 | void source_items_removed(const QModelIndex &source_parent, | - | ||||||||||||||||||||||||
| 225 | int start, int end, Qt::Orientation orient); | - | ||||||||||||||||||||||||
| 226 | void proxy_item_range( | - | ||||||||||||||||||||||||
| 227 | const QVector<int> &source_to_proxy, const QVector<int> &source_items, | - | ||||||||||||||||||||||||
| 228 | int &proxy_low, int &proxy_high) const; | - | ||||||||||||||||||||||||
| 229 | - | |||||||||||||||||||||||||
| 230 | QModelIndexPairList store_persistent_indexes();() const; | - | ||||||||||||||||||||||||
| 231 | void update_persistent_indexes(const QModelIndexPairList &source_indexes); | - | ||||||||||||||||||||||||
| 232 | - | |||||||||||||||||||||||||
| 233 | void filter_about_to_be_changed(const QModelIndex &source_parent = QModelIndex()); | - | ||||||||||||||||||||||||
| 234 | void filter_changed(const QModelIndex &source_parent = QModelIndex()); | - | ||||||||||||||||||||||||
| 235 | QSet<int> handle_filter_changed( | - | ||||||||||||||||||||||||
| 236 | QVector<int> &source_to_proxy, QVector<int> &proxy_to_source, | - | ||||||||||||||||||||||||
| 237 | const QModelIndex &source_parent, Qt::Orientation orient); | - | ||||||||||||||||||||||||
| 238 | - | |||||||||||||||||||||||||
| 239 | void updateChildrenMapping(const QModelIndex &source_parent, Mapping *parent_mapping, | - | ||||||||||||||||||||||||
| 240 | Qt::Orientation orient, int start, int end, int delta_item_count, bool remove); | - | ||||||||||||||||||||||||
| 241 | - | |||||||||||||||||||||||||
| 242 | virtual void _q_sourceModelDestroyed() override; | - | ||||||||||||||||||||||||
| 243 | }; | - | ||||||||||||||||||||||||
| 244 | - | |||||||||||||||||||||||||
| 245 | typedef QHash<QModelIndex, QSortFilterProxyModelPrivate::Mapping *> IndexMap; | - | ||||||||||||||||||||||||
| 246 | - | |||||||||||||||||||||||||
| 247 | void QSortFilterProxyModelPrivate::_q_sourceModelDestroyed() | - | ||||||||||||||||||||||||
| 248 | { | - | ||||||||||||||||||||||||
| 249 | QAbstractProxyModelPrivate::_q_sourceModelDestroyed(); | - | ||||||||||||||||||||||||
| 250 | qDeleteAll(source_index_mapping); | - | ||||||||||||||||||||||||
| 251 | source_index_mapping.clear(); | - | ||||||||||||||||||||||||
| 252 | } | - | ||||||||||||||||||||||||
| 253 | - | |||||||||||||||||||||||||
| 254 | void QSortFilterProxyModelPrivate::remove_from_mapping(const QModelIndex &source_parent) | - | ||||||||||||||||||||||||
| 255 | { | - | ||||||||||||||||||||||||
| 256 | if (Mapping *m = source_index_mapping.take(source_parent)) { | - | ||||||||||||||||||||||||
| 257 | for (int i = 0; i < m->mapped_children.size(); ++i) | - | ||||||||||||||||||||||||
| 258 | remove_from_mapping(m->mapped_children.at(i)); | - | ||||||||||||||||||||||||
| 259 | delete m; | - | ||||||||||||||||||||||||
| 260 | } | - | ||||||||||||||||||||||||
| 261 | } | - | ||||||||||||||||||||||||
| 262 | - | |||||||||||||||||||||||||
| 263 | void QSortFilterProxyModelPrivate::_q_clearMapping() | - | ||||||||||||||||||||||||
| 264 | { | - | ||||||||||||||||||||||||
| 265 | - | |||||||||||||||||||||||||
| 266 | QModelIndexPairList source_indexes = store_persistent_indexes(); | - | ||||||||||||||||||||||||
| 267 | - | |||||||||||||||||||||||||
| 268 | qDeleteAll(source_index_mapping); | - | ||||||||||||||||||||||||
| 269 | source_index_mapping.clear(); | - | ||||||||||||||||||||||||
| 270 | if (dynamic_sortfilter && update_source_sort_column()) { | - | ||||||||||||||||||||||||
| 271 | - | |||||||||||||||||||||||||
| 272 | qDeleteAll(source_index_mapping); | - | ||||||||||||||||||||||||
| 273 | source_index_mapping.clear(); | - | ||||||||||||||||||||||||
| 274 | } | - | ||||||||||||||||||||||||
| 275 | - | |||||||||||||||||||||||||
| 276 | - | |||||||||||||||||||||||||
| 277 | update_persistent_indexes(source_indexes); | - | ||||||||||||||||||||||||
| 278 | } | - | ||||||||||||||||||||||||
| 279 | - | |||||||||||||||||||||||||
| 280 | IndexMap::const_iterator QSortFilterProxyModelPrivate::create_mapping( | - | ||||||||||||||||||||||||
| 281 | const QModelIndex &source_parent) const | - | ||||||||||||||||||||||||
| 282 | { | - | ||||||||||||||||||||||||
| 283 | const QSortFilterProxyModel * const q = q_func(); | - | ||||||||||||||||||||||||
| 284 | - | |||||||||||||||||||||||||
| 285 | IndexMap::const_iterator it = source_index_mapping.constFind(source_parent); | - | ||||||||||||||||||||||||
| 286 | if (it != source_index_mapping.constEnd()) | - | ||||||||||||||||||||||||
| 287 | return it; | - | ||||||||||||||||||||||||
| 288 | - | |||||||||||||||||||||||||
| 289 | Mapping *m = new Mapping; | - | ||||||||||||||||||||||||
| 290 | - | |||||||||||||||||||||||||
| 291 | int source_rows = model->rowCount(source_parent); | - | ||||||||||||||||||||||||
| 292 | m->source_rows.reserve(source_rows); | - | ||||||||||||||||||||||||
| 293 | for (int i = 0; i < source_rows; ++i) { | - | ||||||||||||||||||||||||
| 294 | if (q->filterAcceptsRow(i, source_parent)) | - | ||||||||||||||||||||||||
| 295 | m->source_rows.append(i); | - | ||||||||||||||||||||||||
| 296 | } | - | ||||||||||||||||||||||||
| 297 | int source_cols = model->columnCount(source_parent); | - | ||||||||||||||||||||||||
| 298 | m->source_columns.reserve(source_cols); | - | ||||||||||||||||||||||||
| 299 | for (int i = 0; i < source_cols; ++i) { | - | ||||||||||||||||||||||||
| 300 | if (q->filterAcceptsColumn(i, source_parent)) | - | ||||||||||||||||||||||||
| 301 | m->source_columns.append(i); | - | ||||||||||||||||||||||||
| 302 | } | - | ||||||||||||||||||||||||
| 303 | - | |||||||||||||||||||||||||
| 304 | sort_source_rows(m->source_rows, source_parent); | - | ||||||||||||||||||||||||
| 305 | m->proxy_rows.resize(source_rows); | - | ||||||||||||||||||||||||
| 306 | build_source_to_proxy_mapping(m->source_rows, m->proxy_rows); | - | ||||||||||||||||||||||||
| 307 | m->proxy_columns.resize(source_cols); | - | ||||||||||||||||||||||||
| 308 | build_source_to_proxy_mapping(m->source_columns, m->proxy_columns); | - | ||||||||||||||||||||||||
| 309 | - | |||||||||||||||||||||||||
| 310 | it = IndexMap::const_iterator(source_index_mapping.insert(source_parent, m)); | - | ||||||||||||||||||||||||
| 311 | m->map_iter = it; | - | ||||||||||||||||||||||||
| 312 | - | |||||||||||||||||||||||||
| 313 | if (source_parent.isValid()) { | - | ||||||||||||||||||||||||
| 314 | QModelIndex source_grand_parent = source_parent.parent(); | - | ||||||||||||||||||||||||
| 315 | IndexMap::const_iterator it2 = create_mapping(source_grand_parent); | - | ||||||||||||||||||||||||
| 316 | ((!(it2 != source_index_mapping.constEnd())) ? qt_assert("it2 != source_index_mapping.constEnd()",__FILE__,358364) : qt_noop()); | - | ||||||||||||||||||||||||
| 317 | it2.value()->mapped_children.append(source_parent); | - | ||||||||||||||||||||||||
| 318 | } | - | ||||||||||||||||||||||||
| 319 | - | |||||||||||||||||||||||||
| 320 | ((!(it != source_index_mapping.constEnd())) ? qt_assert("it != source_index_mapping.constEnd()",__FILE__,362368) : qt_noop()); | - | ||||||||||||||||||||||||
| 321 | ((!(it.value())) ? qt_assert("it.value()",__FILE__,363369) : qt_noop()); | - | ||||||||||||||||||||||||
| 322 | - | |||||||||||||||||||||||||
| 323 | return it; | - | ||||||||||||||||||||||||
| 324 | } | - | ||||||||||||||||||||||||
| 325 | - | |||||||||||||||||||||||||
| 326 | QModelIndex QSortFilterProxyModelPrivate::proxy_to_source(const QModelIndex &proxy_index) const | - | ||||||||||||||||||||||||
| 327 | { | - | ||||||||||||||||||||||||
| 328 | if (!proxy_index.isValid()
| 111403-111693 | ||||||||||||||||||||||||
| 329 | return executed 111403 times by 13 tests: QModelIndex();return QModelIndex();Executed by:
executed 111403 times by 13 tests: return QModelIndex();Executed by:
| 111403 | ||||||||||||||||||||||||
| 330 | if (proxy_index.model() != q_func()
| 0-111693 | ||||||||||||||||||||||||
| 331 | QMessageLogger(__FILE__, 373379, __PRETTY_FUNCTION__).warning() << ("QSortFilterProxyModel: index from wrong model passed to mapToSource";); | - | ||||||||||||||||||||||||
| 332 | ((!(!"QSortFilterProxyModel: index from wrong model passed to mapToSource")) ? qt_assert("!\"QSortFilterProxyModel: index from wrong model passed to mapToSource\"",__FILE__,374380) : qt_noop()); | - | ||||||||||||||||||||||||
| 333 | return never executed: QModelIndex();return QModelIndex();never executed: return QModelIndex(); | 0 | ||||||||||||||||||||||||
| 334 | } | - | ||||||||||||||||||||||||
| 335 | IndexMap::const_iterator it = index_to_iterator(proxy_index); | - | ||||||||||||||||||||||||
| 336 | Mapping *m = it.value(); | - | ||||||||||||||||||||||||
| 337 | if ((
| 0-111693 | ||||||||||||||||||||||||
| 338 | return never executed: QModelIndex();return QModelIndex();never executed: return QModelIndex(); | 0 | ||||||||||||||||||||||||
| 339 | int source_row = m->source_rows.at(proxy_index.row()); | - | ||||||||||||||||||||||||
| 340 | int source_col = m->source_columns.at(proxy_index.column()); | - | ||||||||||||||||||||||||
| 341 | return executed 111693 times by 13 tests: model->index(source_row, source_col, it.key());return model->index(source_row, source_col, it.key());Executed by:
executed 111693 times by 13 tests: return model->index(source_row, source_col, it.key());Executed by:
| 111693 | ||||||||||||||||||||||||
| 342 | } | - | ||||||||||||||||||||||||
| 343 | - | |||||||||||||||||||||||||
| 344 | QModelIndex QSortFilterProxyModelPrivate::source_to_proxy(const QModelIndex &source_index) const | - | ||||||||||||||||||||||||
| 345 | { | - | ||||||||||||||||||||||||
| 346 | if (!source_index.isValid()
| 7964-16107 | ||||||||||||||||||||||||
| 347 | return executed 16107 times by 13 tests: QModelIndex();return QModelIndex();Executed by:
executed 16107 times by 13 tests: return QModelIndex();Executed by:
| 16107 | ||||||||||||||||||||||||
| 348 | if (source_index.model() != model
| 0-7964 | ||||||||||||||||||||||||
| 349 | QMessageLogger(__FILE__, 391397, __PRETTY_FUNCTION__).warning() << ("QSortFilterProxyModel: index from wrong model passed to mapFromSource";); | - | ||||||||||||||||||||||||
| 350 | ((!(!"QSortFilterProxyModel: index from wrong model passed to mapFromSource")) ? qt_assert("!\"QSortFilterProxyModel: index from wrong model passed to mapFromSource\"",__FILE__,392398) : qt_noop()); | - | ||||||||||||||||||||||||
| 351 | return never executed: QModelIndex();return QModelIndex();never executed: return QModelIndex(); | 0 | ||||||||||||||||||||||||
| 352 | } | - | ||||||||||||||||||||||||
| 353 | QModelIndex source_parent = source_index.parent(); | - | ||||||||||||||||||||||||
| 354 | IndexMap::const_iterator it = create_mapping(source_parent); | - | ||||||||||||||||||||||||
| 355 | Mapping *m = it.value(); | - | ||||||||||||||||||||||||
| 356 | if ((
| 0-7964 | ||||||||||||||||||||||||
| 357 | return never executed: QModelIndex();return QModelIndex();never executed: return QModelIndex(); | 0 | ||||||||||||||||||||||||
| 358 | int proxy_row = m->proxy_rows.at(source_index.row()); | - | ||||||||||||||||||||||||
| 359 | int proxy_column = m->proxy_columns.at(source_index.column()); | - | ||||||||||||||||||||||||
| 360 | if (proxy_row == -1
| 0-7924 | ||||||||||||||||||||||||
| 361 | return executed 40 times by 2 tests: QModelIndex();return QModelIndex();Executed by:
executed 40 times by 2 tests: return QModelIndex();Executed by:
| 40 | ||||||||||||||||||||||||
| 362 | return executed 7924 times by 11 tests: create_index(proxy_row, proxy_column, it);return create_index(proxy_row, proxy_column, it);Executed by:
executed 7924 times by 11 tests: return create_index(proxy_row, proxy_column, it);Executed by:
| 7924 | ||||||||||||||||||||||||
| 363 | } | - | ||||||||||||||||||||||||
| 364 | - | |||||||||||||||||||||||||
| 365 | bool QSortFilterProxyModelPrivate::can_create_mapping(const QModelIndex &source_parent) const | - | ||||||||||||||||||||||||
| 366 | { | - | ||||||||||||||||||||||||
| 367 | if (source_parent.isValid()) { | - | ||||||||||||||||||||||||
| 368 | QModelIndex source_grand_parent = source_parent.parent(); | - | ||||||||||||||||||||||||
| 369 | IndexMap::const_iterator it = source_index_mapping.constFind(source_grand_parent); | - | ||||||||||||||||||||||||
| 370 | if (it == source_index_mapping.constEnd()) { | - | ||||||||||||||||||||||||
| 371 | - | |||||||||||||||||||||||||
| 372 | return false; | - | ||||||||||||||||||||||||
| 373 | } | - | ||||||||||||||||||||||||
| 374 | Mapping *gm = it.value(); | - | ||||||||||||||||||||||||
| 375 | if (gm->proxy_rows.at(source_parent.row()) == -1 || | - | ||||||||||||||||||||||||
| 376 | gm->proxy_columns.at(source_parent.column()) == -1) { | - | ||||||||||||||||||||||||
| 377 | - | |||||||||||||||||||||||||
| 378 | return false; | - | ||||||||||||||||||||||||
| 379 | } | - | ||||||||||||||||||||||||
| 380 | } | - | ||||||||||||||||||||||||
| 381 | return true; | - | ||||||||||||||||||||||||
| 382 | } | - | ||||||||||||||||||||||||
| 383 | - | |||||||||||||||||||||||||
| 384 | - | |||||||||||||||||||||||||
| 385 | - | |||||||||||||||||||||||||
| 386 | - | |||||||||||||||||||||||||
| 387 | - | |||||||||||||||||||||||||
| 388 | - | |||||||||||||||||||||||||
| 389 | void QSortFilterProxyModelPrivate::sort() | - | ||||||||||||||||||||||||
| 390 | { | - | ||||||||||||||||||||||||
| 391 | QSortFilterProxyModel * const q = q_func(); | - | ||||||||||||||||||||||||
| 392 | q->layoutAboutToBeChanged(QList<QPersistentModelIndex>(), QAbstractItemModel::VerticalSortHint); | - | ||||||||||||||||||||||||
| 393 | QModelIndexPairList source_indexes = store_persistent_indexes(); | - | ||||||||||||||||||||||||
| 394 | IndexMap::const_iterator it = source_index_mapping.constBegin(); | - | ||||||||||||||||||||||||
| 395 | for (; it != source_index_mapping.constEnd(); ++it) { | - | ||||||||||||||||||||||||
| 396 | QModelIndex source_parent = it.key(); | - | ||||||||||||||||||||||||
| 397 | Mapping *m = it.value(); | - | ||||||||||||||||||||||||
| 398 | sort_source_rows(m->source_rows, source_parent); | - | ||||||||||||||||||||||||
| 399 | build_source_to_proxy_mapping(m->source_rows, m->proxy_rows); | - | ||||||||||||||||||||||||
| 400 | } | - | ||||||||||||||||||||||||
| 401 | update_persistent_indexes(source_indexes); | - | ||||||||||||||||||||||||
| 402 | q->layoutChanged(QList<QPersistentModelIndex>(), QAbstractItemModel::VerticalSortHint); | - | ||||||||||||||||||||||||
| 403 | } | - | ||||||||||||||||||||||||
| 404 | - | |||||||||||||||||||||||||
| 405 | - | |||||||||||||||||||||||||
| 406 | - | |||||||||||||||||||||||||
| 407 | - | |||||||||||||||||||||||||
| 408 | - | |||||||||||||||||||||||||
| 409 | - | |||||||||||||||||||||||||
| 410 | - | |||||||||||||||||||||||||
| 411 | bool QSortFilterProxyModelPrivate::update_source_sort_column() | - | ||||||||||||||||||||||||
| 412 | { | - | ||||||||||||||||||||||||
| 413 | int old_source_sort_column = source_sort_column; | - | ||||||||||||||||||||||||
| 414 | - | |||||||||||||||||||||||||
| 415 | if (proxy_sort_column == -1) { | - | ||||||||||||||||||||||||
| 416 | source_sort_column = -1; | - | ||||||||||||||||||||||||
| 417 | } else { | - | ||||||||||||||||||||||||
| 418 | - | |||||||||||||||||||||||||
| 419 | - | |||||||||||||||||||||||||
| 420 | - | |||||||||||||||||||||||||
| 421 | Mapping *m = create_mapping(QModelIndex()).value(); | - | ||||||||||||||||||||||||
| 422 | if (proxy_sort_column < m->source_columns.size()) | - | ||||||||||||||||||||||||
| 423 | source_sort_column = m->source_columns.at(proxy_sort_column); | - | ||||||||||||||||||||||||
| 424 | else | - | ||||||||||||||||||||||||
| 425 | source_sort_column = -1; | - | ||||||||||||||||||||||||
| 426 | } | - | ||||||||||||||||||||||||
| 427 | - | |||||||||||||||||||||||||
| 428 | return old_source_sort_column != source_sort_column; | - | ||||||||||||||||||||||||
| 429 | } | - | ||||||||||||||||||||||||
| 430 | - | |||||||||||||||||||||||||
| 431 | - | |||||||||||||||||||||||||
| 432 | - | |||||||||||||||||||||||||
| 433 | - | |||||||||||||||||||||||||
| 434 | - | |||||||||||||||||||||||||
| 435 | - | |||||||||||||||||||||||||
| 436 | - | |||||||||||||||||||||||||
| 437 | void QSortFilterProxyModelPrivate::sort_source_rows( | - | ||||||||||||||||||||||||
| 438 | QVector<int> &source_rows, const QModelIndex &source_parent) const | - | ||||||||||||||||||||||||
| 439 | { | - | ||||||||||||||||||||||||
| 440 | const QSortFilterProxyModel * const q = q_func(); | - | ||||||||||||||||||||||||
| 441 | if (source_sort_column >= 0) { | - | ||||||||||||||||||||||||
| 442 | if (sort_order == Qt::AscendingOrder) { | - | ||||||||||||||||||||||||
| 443 | QSortFilterProxyModelLessThan lt(source_sort_column, source_parent, model, q); | - | ||||||||||||||||||||||||
| 444 | std::stable_sort(source_rows.begin(), source_rows.end(), lt); | - | ||||||||||||||||||||||||
| 445 | } else { | - | ||||||||||||||||||||||||
| 446 | QSortFilterProxyModelGreaterThan gt(source_sort_column, source_parent, model, q); | - | ||||||||||||||||||||||||
| 447 | std::stable_sort(source_rows.begin(), source_rows.end(), gt); | - | ||||||||||||||||||||||||
| 448 | } | - | ||||||||||||||||||||||||
| 449 | } else { | - | ||||||||||||||||||||||||
| 450 | std::stable_sort(source_rows.begin(), source_rows.end()); | - | ||||||||||||||||||||||||
| 451 | } | - | ||||||||||||||||||||||||
| 452 | } | - | ||||||||||||||||||||||||
| 453 | QVector<QPair<int, int > > QSortFilterProxyModelPrivate::proxy_intervals_for_source_items( | - | ||||||||||||||||||||||||
| 454 | const QVector<int> &source_to_proxy, const QVector<int> &source_items) const | - | ||||||||||||||||||||||||
| 455 | { | - | ||||||||||||||||||||||||
| 456 | QVector<QPair<int, int> > proxy_intervals; | - | ||||||||||||||||||||||||
| 457 | if (source_items.isEmpty()) | - | ||||||||||||||||||||||||
| 458 | return proxy_intervals; | - | ||||||||||||||||||||||||
| 459 | - | |||||||||||||||||||||||||
| 460 | int source_items_index = 0; | - | ||||||||||||||||||||||||
| 461 | while (source_items_index < source_items.size()) { | - | ||||||||||||||||||||||||
| 462 | int first_proxy_item = source_to_proxy.at(source_items.at(source_items_index)); | - | ||||||||||||||||||||||||
| 463 | ((!(first_proxy_item != -1)) ? qt_assert("first_proxy_item != -1",__FILE__,517523) : qt_noop()); | - | ||||||||||||||||||||||||
| 464 | int last_proxy_item = first_proxy_item; | - | ||||||||||||||||||||||||
| 465 | ++source_items_index; | - | ||||||||||||||||||||||||
| 466 | - | |||||||||||||||||||||||||
| 467 | while ((source_items_index < source_items.size()) | - | ||||||||||||||||||||||||
| 468 | && (source_to_proxy.at(source_items.at(source_items_index)) == last_proxy_item + 1)) { | - | ||||||||||||||||||||||||
| 469 | ++last_proxy_item; | - | ||||||||||||||||||||||||
| 470 | ++source_items_index; | - | ||||||||||||||||||||||||
| 471 | } | - | ||||||||||||||||||||||||
| 472 | - | |||||||||||||||||||||||||
| 473 | proxy_intervals.append(QPair<int, int>(first_proxy_item, last_proxy_item)); | - | ||||||||||||||||||||||||
| 474 | } | - | ||||||||||||||||||||||||
| 475 | std::stable_sort(proxy_intervals.begin(), proxy_intervals.end()); | - | ||||||||||||||||||||||||
| 476 | return proxy_intervals; | - | ||||||||||||||||||||||||
| 477 | } | - | ||||||||||||||||||||||||
| 478 | void QSortFilterProxyModelPrivate::remove_source_items( | - | ||||||||||||||||||||||||
| 479 | QVector<int> &source_to_proxy, QVector<int> &proxy_to_source, | - | ||||||||||||||||||||||||
| 480 | const QVector<int> &source_items, const QModelIndex &source_parent, | - | ||||||||||||||||||||||||
| 481 | Qt::Orientation orient, bool emit_signal) | - | ||||||||||||||||||||||||
| 482 | { | - | ||||||||||||||||||||||||
| 483 | QSortFilterProxyModel * const q = q_func(); | - | ||||||||||||||||||||||||
| 484 | QModelIndex proxy_parent = q->mapFromSource(source_parent); | - | ||||||||||||||||||||||||
| 485 | if (!proxy_parent.isValid() && source_parent.isValid()) | - | ||||||||||||||||||||||||
| 486 | return; | - | ||||||||||||||||||||||||
| 487 | - | |||||||||||||||||||||||||
| 488 | QVector<QPair<int, int> > proxy_intervals; | - | ||||||||||||||||||||||||
| 489 | proxy_intervals = proxy_intervals_for_source_items(source_to_proxy, source_items); | - | ||||||||||||||||||||||||
| 490 | - | |||||||||||||||||||||||||
| 491 | for (int i = proxy_intervals.size()-1; i >= 0; --i) { | - | ||||||||||||||||||||||||
| 492 | QPair<int, int> interval = proxy_intervals.at(i); | - | ||||||||||||||||||||||||
| 493 | int proxy_start = interval.first; | - | ||||||||||||||||||||||||
| 494 | int proxy_end = interval.second; | - | ||||||||||||||||||||||||
| 495 | remove_proxy_interval(source_to_proxy, proxy_to_source, proxy_start, proxy_end, | - | ||||||||||||||||||||||||
| 496 | proxy_parent, orient, emit_signal); | - | ||||||||||||||||||||||||
| 497 | } | - | ||||||||||||||||||||||||
| 498 | } | - | ||||||||||||||||||||||||
| 499 | void QSortFilterProxyModelPrivate::remove_proxy_interval( | - | ||||||||||||||||||||||||
| 500 | QVector<int> &source_to_proxy, QVector<int> &proxy_to_source, int proxy_start, int proxy_end, | - | ||||||||||||||||||||||||
| 501 | const QModelIndex &proxy_parent, Qt::Orientation orient, bool emit_signal) | - | ||||||||||||||||||||||||
| 502 | { | - | ||||||||||||||||||||||||
| 503 | QSortFilterProxyModel * const q = q_func(); | - | ||||||||||||||||||||||||
| 504 | if (emit_signal) { | - | ||||||||||||||||||||||||
| 505 | if (orient == Qt::Vertical) | - | ||||||||||||||||||||||||
| 506 | q->beginRemoveRows(proxy_parent, proxy_start, proxy_end); | - | ||||||||||||||||||||||||
| 507 | else | - | ||||||||||||||||||||||||
| 508 | q->beginRemoveColumns(proxy_parent, proxy_start, proxy_end); | - | ||||||||||||||||||||||||
| 509 | } | - | ||||||||||||||||||||||||
| 510 | - | |||||||||||||||||||||||||
| 511 | - | |||||||||||||||||||||||||
| 512 | proxy_to_source.remove(proxy_start, proxy_end - proxy_start + 1); | - | ||||||||||||||||||||||||
| 513 | - | |||||||||||||||||||||||||
| 514 | build_source_to_proxy_mapping(proxy_to_source, source_to_proxy); | - | ||||||||||||||||||||||||
| 515 | - | |||||||||||||||||||||||||
| 516 | if (emit_signal) { | - | ||||||||||||||||||||||||
| 517 | if (orient == Qt::Vertical) | - | ||||||||||||||||||||||||
| 518 | q->endRemoveRows(); | - | ||||||||||||||||||||||||
| 519 | else | - | ||||||||||||||||||||||||
| 520 | q->endRemoveColumns(); | - | ||||||||||||||||||||||||
| 521 | } | - | ||||||||||||||||||||||||
| 522 | } | - | ||||||||||||||||||||||||
| 523 | QVector<QPair<int, QVector<int > > > QSortFilterProxyModelPrivate::proxy_intervals_for_source_items_to_add( | - | ||||||||||||||||||||||||
| 524 | const QVector<int> &proxy_to_source, const QVector<int> &source_items, | - | ||||||||||||||||||||||||
| 525 | const QModelIndex &source_parent, Qt::Orientation orient) const | - | ||||||||||||||||||||||||
| 526 | { | - | ||||||||||||||||||||||||
| 527 | const QSortFilterProxyModel * const q = q_func(); | - | ||||||||||||||||||||||||
| 528 | QVector<QPair<int, QVector<int> > > proxy_intervals; | - | ||||||||||||||||||||||||
| 529 | if (source_items.isEmpty()) | - | ||||||||||||||||||||||||
| 530 | return proxy_intervals; | - | ||||||||||||||||||||||||
| 531 | - | |||||||||||||||||||||||||
| 532 | int proxy_low = 0; | - | ||||||||||||||||||||||||
| 533 | int proxy_item = 0; | - | ||||||||||||||||||||||||
| 534 | int source_items_index = 0; | - | ||||||||||||||||||||||||
| 535 | QVector<int> source_items_in_interval; | - | ||||||||||||||||||||||||
| 536 | bool compare = (orient == Qt::Vertical && source_sort_column >= 0 && dynamic_sortfilter); | - | ||||||||||||||||||||||||
| 537 | while (source_items_index < source_items.size()) { | - | ||||||||||||||||||||||||
| 538 | source_items_in_interval.clear(); | - | ||||||||||||||||||||||||
| 539 | int first_new_source_item = source_items.at(source_items_index); | - | ||||||||||||||||||||||||
| 540 | source_items_in_interval.append(first_new_source_item); | - | ||||||||||||||||||||||||
| 541 | ++source_items_index; | - | ||||||||||||||||||||||||
| 542 | - | |||||||||||||||||||||||||
| 543 | - | |||||||||||||||||||||||||
| 544 | int proxy_high = proxy_to_source.size() - 1; | - | ||||||||||||||||||||||||
| 545 | QModelIndex i1 = compare ? model->index(first_new_source_item, source_sort_column, source_parent) : QModelIndex(); | - | ||||||||||||||||||||||||
| 546 | while (proxy_low <= proxy_high) { | - | ||||||||||||||||||||||||
| 547 | proxy_item = (proxy_low + proxy_high) / 2; | - | ||||||||||||||||||||||||
| 548 | if (compare) { | - | ||||||||||||||||||||||||
| 549 | QModelIndex i2 = model->index(proxy_to_source.at(proxy_item), source_sort_column, source_parent); | - | ||||||||||||||||||||||||
| 550 | if ((sort_order == Qt::AscendingOrder) ? q->lessThan(i1, i2) : q->lessThan(i2, i1)) | - | ||||||||||||||||||||||||
| 551 | proxy_high = proxy_item - 1; | - | ||||||||||||||||||||||||
| 552 | else | - | ||||||||||||||||||||||||
| 553 | proxy_low = proxy_item + 1; | - | ||||||||||||||||||||||||
| 554 | } else { | - | ||||||||||||||||||||||||
| 555 | if (first_new_source_item < proxy_to_source.at(proxy_item)) | - | ||||||||||||||||||||||||
| 556 | proxy_high = proxy_item - 1; | - | ||||||||||||||||||||||||
| 557 | else | - | ||||||||||||||||||||||||
| 558 | proxy_low = proxy_item + 1; | - | ||||||||||||||||||||||||
| 559 | } | - | ||||||||||||||||||||||||
| 560 | } | - | ||||||||||||||||||||||||
| 561 | proxy_item = proxy_low; | - | ||||||||||||||||||||||||
| 562 | - | |||||||||||||||||||||||||
| 563 | - | |||||||||||||||||||||||||
| 564 | if (proxy_item >= proxy_to_source.size()) { | - | ||||||||||||||||||||||||
| 565 | for ( ; source_items_index < source_items.size(); ++source_items_index) | - | ||||||||||||||||||||||||
| 566 | source_items_in_interval.append(source_items.at(source_items_index)); | - | ||||||||||||||||||||||||
| 567 | } else { | - | ||||||||||||||||||||||||
| 568 | i1 = compare ? model->index(proxy_to_source.at(proxy_item), source_sort_column, source_parent) : QModelIndex(); | - | ||||||||||||||||||||||||
| 569 | for ( ; source_items_index < source_items.size(); ++source_items_index) { | - | ||||||||||||||||||||||||
| 570 | int new_source_item = source_items.at(source_items_index); | - | ||||||||||||||||||||||||
| 571 | if (compare) { | - | ||||||||||||||||||||||||
| 572 | QModelIndex i2 = model->index(new_source_item, source_sort_column, source_parent); | - | ||||||||||||||||||||||||
| 573 | if ((sort_order == Qt::AscendingOrder) ? q->lessThan(i1, i2) : q->lessThan(i2, i1)) | - | ||||||||||||||||||||||||
| 574 | break; | - | ||||||||||||||||||||||||
| 575 | } else { | - | ||||||||||||||||||||||||
| 576 | if (proxy_to_source.at(proxy_item) < new_source_item) | - | ||||||||||||||||||||||||
| 577 | break; | - | ||||||||||||||||||||||||
| 578 | } | - | ||||||||||||||||||||||||
| 579 | source_items_in_interval.append(new_source_item); | - | ||||||||||||||||||||||||
| 580 | } | - | ||||||||||||||||||||||||
| 581 | } | - | ||||||||||||||||||||||||
| 582 | - | |||||||||||||||||||||||||
| 583 | - | |||||||||||||||||||||||||
| 584 | proxy_intervals.append(QPair<int, QVector<int> >(proxy_item, source_items_in_interval)); | - | ||||||||||||||||||||||||
| 585 | } | - | ||||||||||||||||||||||||
| 586 | return proxy_intervals; | - | ||||||||||||||||||||||||
| 587 | } | - | ||||||||||||||||||||||||
| 588 | void QSortFilterProxyModelPrivate::insert_source_items( | - | ||||||||||||||||||||||||
| 589 | QVector<int> &source_to_proxy, QVector<int> &proxy_to_source, | - | ||||||||||||||||||||||||
| 590 | const QVector<int> &source_items, const QModelIndex &source_parent, | - | ||||||||||||||||||||||||
| 591 | Qt::Orientation orient, bool emit_signal) | - | ||||||||||||||||||||||||
| 592 | { | - | ||||||||||||||||||||||||
| 593 | QSortFilterProxyModel * const q = q_func(); | - | ||||||||||||||||||||||||
| 594 | QModelIndex proxy_parent = q->mapFromSource(source_parent); | - | ||||||||||||||||||||||||
| 595 | if (!proxy_parent.isValid() && source_parent.isValid()) | - | ||||||||||||||||||||||||
| 596 | return; | - | ||||||||||||||||||||||||
| 597 | - | |||||||||||||||||||||||||
| 598 | QVector<QPair<int, QVector<int> > > proxy_intervals; | - | ||||||||||||||||||||||||
| 599 | proxy_intervals = proxy_intervals_for_source_items_to_add( | - | ||||||||||||||||||||||||
| 600 | proxy_to_source, source_items, source_parent, orient); | - | ||||||||||||||||||||||||
| 601 | - | |||||||||||||||||||||||||
| 602 | for (int i = proxy_intervals.size()-1; i >= 0; --i) { | - | ||||||||||||||||||||||||
| 603 | QPair<int, QVector<int> > interval = proxy_intervals.at(i); | - | ||||||||||||||||||||||||
| 604 | int proxy_start = interval.first; | - | ||||||||||||||||||||||||
| 605 | QVector<int> source_items = interval.second; | - | ||||||||||||||||||||||||
| 606 | int proxy_end = proxy_start + source_items.size() - 1; | - | ||||||||||||||||||||||||
| 607 | - | |||||||||||||||||||||||||
| 608 | if (emit_signal) { | - | ||||||||||||||||||||||||
| 609 | if (orient == Qt::Vertical) | - | ||||||||||||||||||||||||
| 610 | q->beginInsertRows(proxy_parent, proxy_start, proxy_end); | - | ||||||||||||||||||||||||
| 611 | else | - | ||||||||||||||||||||||||
| 612 | q->beginInsertColumns(proxy_parent, proxy_start, proxy_end); | - | ||||||||||||||||||||||||
| 613 | } | - | ||||||||||||||||||||||||
| 614 | - | |||||||||||||||||||||||||
| 615 | for (int i = 0; i < source_items.size(); ++i) | - | ||||||||||||||||||||||||
| 616 | proxy_to_source.insert(proxy_start + i, source_items.at(i)); | - | ||||||||||||||||||||||||
| 617 | - | |||||||||||||||||||||||||
| 618 | build_source_to_proxy_mapping(proxy_to_source, source_to_proxy); | - | ||||||||||||||||||||||||
| 619 | - | |||||||||||||||||||||||||
| 620 | if (emit_signal) { | - | ||||||||||||||||||||||||
| 621 | if (orient == Qt::Vertical) | - | ||||||||||||||||||||||||
| 622 | q->endInsertRows(); | - | ||||||||||||||||||||||||
| 623 | else | - | ||||||||||||||||||||||||
| 624 | q->endInsertColumns(); | - | ||||||||||||||||||||||||
| 625 | } | - | ||||||||||||||||||||||||
| 626 | } | - | ||||||||||||||||||||||||
| 627 | } | - | ||||||||||||||||||||||||
| 628 | void QSortFilterProxyModelPrivate::source_items_inserted( | - | ||||||||||||||||||||||||
| 629 | const QModelIndex &source_parent, int start, int end, Qt::Orientation orient) | - | ||||||||||||||||||||||||
| 630 | { | - | ||||||||||||||||||||||||
| 631 | QSortFilterProxyModel * const q = q_func(); | - | ||||||||||||||||||||||||
| 632 | if ((start < 0) || (end < 0)) | - | ||||||||||||||||||||||||
| 633 | return; | - | ||||||||||||||||||||||||
| 634 | IndexMap::const_iterator it = source_index_mapping.constFind(source_parent); | - | ||||||||||||||||||||||||
| 635 | if (it == source_index_mapping.constEnd()) { | - | ||||||||||||||||||||||||
| 636 | if (!can_create_mapping(source_parent)) | - | ||||||||||||||||||||||||
| 637 | return; | - | ||||||||||||||||||||||||
| 638 | it = create_mapping(source_parent); | - | ||||||||||||||||||||||||
| 639 | Mapping *m = it.value(); | - | ||||||||||||||||||||||||
| 640 | QModelIndex proxy_parent = q->mapFromSource(source_parent); | - | ||||||||||||||||||||||||
| 641 | if (m->source_rows.count() > 0) { | - | ||||||||||||||||||||||||
| 642 | q->beginInsertRows(proxy_parent, 0, m->source_rows.count() - 1); | - | ||||||||||||||||||||||||
| 643 | q->endInsertRows(); | - | ||||||||||||||||||||||||
| 644 | } | - | ||||||||||||||||||||||||
| 645 | if (m->source_columns.count() > 0) { | - | ||||||||||||||||||||||||
| 646 | q->beginInsertColumns(proxy_parent, 0, m->source_columns.count() - 1); | - | ||||||||||||||||||||||||
| 647 | q->endInsertColumns(); | - | ||||||||||||||||||||||||
| 648 | } | - | ||||||||||||||||||||||||
| 649 | return; | - | ||||||||||||||||||||||||
| 650 | } | - | ||||||||||||||||||||||||
| 651 | - | |||||||||||||||||||||||||
| 652 | Mapping *m = it.value(); | - | ||||||||||||||||||||||||
| 653 | QVector<int> &source_to_proxy = (orient == Qt::Vertical) ? m->proxy_rows : m->proxy_columns; | - | ||||||||||||||||||||||||
| 654 | QVector<int> &proxy_to_source = (orient == Qt::Vertical) ? m->source_rows : m->source_columns; | - | ||||||||||||||||||||||||
| 655 | - | |||||||||||||||||||||||||
| 656 | int delta_item_count = end - start + 1; | - | ||||||||||||||||||||||||
| 657 | int old_item_count = source_to_proxy.size(); | - | ||||||||||||||||||||||||
| 658 | - | |||||||||||||||||||||||||
| 659 | updateChildrenMapping(source_parent, m, orient, start, end, delta_item_count, false); | - | ||||||||||||||||||||||||
| 660 | - | |||||||||||||||||||||||||
| 661 | - | |||||||||||||||||||||||||
| 662 | if (start < 0 || start > source_to_proxy.size()) { | - | ||||||||||||||||||||||||
| 663 | QMessageLogger(__FILE__, 769775, __PRETTY_FUNCTION__).warning("QSortFilterProxyModel: invalid inserted rows reported by source model"); | - | ||||||||||||||||||||||||
| 664 | remove_from_mapping(source_parent); | - | ||||||||||||||||||||||||
| 665 | return; | - | ||||||||||||||||||||||||
| 666 | } | - | ||||||||||||||||||||||||
| 667 | source_to_proxy.insert(start, delta_item_count, -1); | - | ||||||||||||||||||||||||
| 668 | - | |||||||||||||||||||||||||
| 669 | if (start < old_item_count) { | - | ||||||||||||||||||||||||
| 670 | - | |||||||||||||||||||||||||
| 671 | int proxy_count = proxy_to_source.size(); | - | ||||||||||||||||||||||||
| 672 | for (int proxy_item = 0; proxy_item < proxy_count; ++proxy_item) { | - | ||||||||||||||||||||||||
| 673 | int source_item = proxy_to_source.at(proxy_item); | - | ||||||||||||||||||||||||
| 674 | if (source_item >= start) | - | ||||||||||||||||||||||||
| 675 | proxy_to_source.replace(proxy_item, source_item + delta_item_count); | - | ||||||||||||||||||||||||
| 676 | } | - | ||||||||||||||||||||||||
| 677 | build_source_to_proxy_mapping(proxy_to_source, source_to_proxy); | - | ||||||||||||||||||||||||
| 678 | } | - | ||||||||||||||||||||||||
| 679 | - | |||||||||||||||||||||||||
| 680 | - | |||||||||||||||||||||||||
| 681 | QVector<int> source_items; | - | ||||||||||||||||||||||||
| 682 | for (int i = start; i <= end; ++i) { | - | ||||||||||||||||||||||||
| 683 | if ((orient == Qt::Vertical) | - | ||||||||||||||||||||||||
| 684 | ? q->filterAcceptsRow(i, source_parent) | - | ||||||||||||||||||||||||
| 685 | : q->filterAcceptsColumn(i, source_parent)) { | - | ||||||||||||||||||||||||
| 686 | source_items.append(i); | - | ||||||||||||||||||||||||
| 687 | } | - | ||||||||||||||||||||||||
| 688 | } | - | ||||||||||||||||||||||||
| 689 | - | |||||||||||||||||||||||||
| 690 | if (model->rowCount(source_parent) == delta_item_count) { | - | ||||||||||||||||||||||||
| 691 | - | |||||||||||||||||||||||||
| 692 | - | |||||||||||||||||||||||||
| 693 | - | |||||||||||||||||||||||||
| 694 | - | |||||||||||||||||||||||||
| 695 | QVector<int> &orthogonal_proxy_to_source = (orient == Qt::Horizontal) ? m->source_rows : m->source_columns; | - | ||||||||||||||||||||||||
| 696 | QVector<int> &orthogonal_source_to_proxy = (orient == Qt::Horizontal) ? m->proxy_rows : m->proxy_columns; | - | ||||||||||||||||||||||||
| 697 | - | |||||||||||||||||||||||||
| 698 | if (orthogonal_source_to_proxy.isEmpty()) { | - | ||||||||||||||||||||||||
| 699 | const int ortho_end = (orient == Qt::Horizontal) ? model->rowCount(source_parent) : model->columnCount(source_parent); | - | ||||||||||||||||||||||||
| 700 | - | |||||||||||||||||||||||||
| 701 | orthogonal_source_to_proxy.resize(ortho_end); | - | ||||||||||||||||||||||||
| 702 | - | |||||||||||||||||||||||||
| 703 | for (int ortho_item = 0; ortho_item < ortho_end; ++ortho_item) { | - | ||||||||||||||||||||||||
| 704 | if ((orient == Qt::Horizontal) ? q->filterAcceptsRow(ortho_item, source_parent) | - | ||||||||||||||||||||||||
| 705 | : q->filterAcceptsColumn(ortho_item, source_parent)) { | - | ||||||||||||||||||||||||
| 706 | orthogonal_proxy_to_source.append(ortho_item); | - | ||||||||||||||||||||||||
| 707 | } | - | ||||||||||||||||||||||||
| 708 | } | - | ||||||||||||||||||||||||
| 709 | if (orient == Qt::Horizontal) { | - | ||||||||||||||||||||||||
| 710 | - | |||||||||||||||||||||||||
| 711 | sort_source_rows(orthogonal_proxy_to_source, source_parent); | - | ||||||||||||||||||||||||
| 712 | } | - | ||||||||||||||||||||||||
| 713 | build_source_to_proxy_mapping(orthogonal_proxy_to_source, orthogonal_source_to_proxy); | - | ||||||||||||||||||||||||
| 714 | } | - | ||||||||||||||||||||||||
| 715 | } | - | ||||||||||||||||||||||||
| 716 | - | |||||||||||||||||||||||||
| 717 | - | |||||||||||||||||||||||||
| 718 | if (orient == Qt::Vertical) | - | ||||||||||||||||||||||||
| 719 | sort_source_rows(source_items, source_parent); | - | ||||||||||||||||||||||||
| 720 | insert_source_items(source_to_proxy, proxy_to_source, source_items, source_parent, orient); | - | ||||||||||||||||||||||||
| 721 | } | - | ||||||||||||||||||||||||
| 722 | - | |||||||||||||||||||||||||
| 723 | - | |||||||||||||||||||||||||
| 724 | - | |||||||||||||||||||||||||
| 725 | - | |||||||||||||||||||||||||
| 726 | - | |||||||||||||||||||||||||
| 727 | - | |||||||||||||||||||||||||
| 728 | - | |||||||||||||||||||||||||
| 729 | void QSortFilterProxyModelPrivate::source_items_about_to_be_removed( | - | ||||||||||||||||||||||||
| 730 | const QModelIndex &source_parent, int start, int end, Qt::Orientation orient) | - | ||||||||||||||||||||||||
| 731 | { | - | ||||||||||||||||||||||||
| 732 | if ((start < 0) || (end < 0)) | - | ||||||||||||||||||||||||
| 733 | return; | - | ||||||||||||||||||||||||
| 734 | IndexMap::const_iterator it = source_index_mapping.constFind(source_parent); | - | ||||||||||||||||||||||||
| 735 | if (it == source_index_mapping.constEnd()) { | - | ||||||||||||||||||||||||
| 736 | - | |||||||||||||||||||||||||
| 737 | return; | - | ||||||||||||||||||||||||
| 738 | } | - | ||||||||||||||||||||||||
| 739 | - | |||||||||||||||||||||||||
| 740 | Mapping *m = it.value(); | - | ||||||||||||||||||||||||
| 741 | QVector<int> &source_to_proxy = (orient == Qt::Vertical) ? m->proxy_rows : m->proxy_columns; | - | ||||||||||||||||||||||||
| 742 | QVector<int> &proxy_to_source = (orient == Qt::Vertical) ? m->source_rows : m->source_columns; | - | ||||||||||||||||||||||||
| 743 | - | |||||||||||||||||||||||||
| 744 | - | |||||||||||||||||||||||||
| 745 | QVector<int> source_items_to_remove; | - | ||||||||||||||||||||||||
| 746 | int proxy_count = proxy_to_source.size(); | - | ||||||||||||||||||||||||
| 747 | for (int proxy_item = 0; proxy_item < proxy_count; ++proxy_item) { | - | ||||||||||||||||||||||||
| 748 | int source_item = proxy_to_source.at(proxy_item); | - | ||||||||||||||||||||||||
| 749 | if ((source_item >= start) && (source_item <= end)) | - | ||||||||||||||||||||||||
| 750 | source_items_to_remove.append(source_item); | - | ||||||||||||||||||||||||
| 751 | } | - | ||||||||||||||||||||||||
| 752 | - | |||||||||||||||||||||||||
| 753 | remove_source_items(source_to_proxy, proxy_to_source, source_items_to_remove, | - | ||||||||||||||||||||||||
| 754 | source_parent, orient); | - | ||||||||||||||||||||||||
| 755 | } | - | ||||||||||||||||||||||||
| 756 | - | |||||||||||||||||||||||||
| 757 | - | |||||||||||||||||||||||||
| 758 | - | |||||||||||||||||||||||||
| 759 | - | |||||||||||||||||||||||||
| 760 | - | |||||||||||||||||||||||||
| 761 | - | |||||||||||||||||||||||||
| 762 | void QSortFilterProxyModelPrivate::source_items_removed( | - | ||||||||||||||||||||||||
| 763 | const QModelIndex &source_parent, int start, int end, Qt::Orientation orient) | - | ||||||||||||||||||||||||
| 764 | { | - | ||||||||||||||||||||||||
| 765 | if ((start < 0) || (end < 0)) | - | ||||||||||||||||||||||||
| 766 | return; | - | ||||||||||||||||||||||||
| 767 | IndexMap::const_iterator it = source_index_mapping.constFind(source_parent); | - | ||||||||||||||||||||||||
| 768 | if (it == source_index_mapping.constEnd()) { | - | ||||||||||||||||||||||||
| 769 | - | |||||||||||||||||||||||||
| 770 | return; | - | ||||||||||||||||||||||||
| 771 | } | - | ||||||||||||||||||||||||
| 772 | - | |||||||||||||||||||||||||
| 773 | Mapping *m = it.value(); | - | ||||||||||||||||||||||||
| 774 | QVector<int> &source_to_proxy = (orient == Qt::Vertical) ? m->proxy_rows : m->proxy_columns; | - | ||||||||||||||||||||||||
| 775 | QVector<int> &proxy_to_source = (orient == Qt::Vertical) ? m->source_rows : m->source_columns; | - | ||||||||||||||||||||||||
| 776 | - | |||||||||||||||||||||||||
| 777 | if (end >= source_to_proxy.size()) | - | ||||||||||||||||||||||||
| 778 | end = source_to_proxy.size() - 1; | - | ||||||||||||||||||||||||
| 779 | - | |||||||||||||||||||||||||
| 780 | - | |||||||||||||||||||||||||
| 781 | int delta_item_count = end - start + 1; | - | ||||||||||||||||||||||||
| 782 | source_to_proxy.remove(start, delta_item_count); | - | ||||||||||||||||||||||||
| 783 | - | |||||||||||||||||||||||||
| 784 | int proxy_count = proxy_to_source.size(); | - | ||||||||||||||||||||||||
| 785 | if (proxy_count > source_to_proxy.size()) { | - | ||||||||||||||||||||||||
| 786 | - | |||||||||||||||||||||||||
| 787 | QMessageLogger(__FILE__, 893899, __PRETTY_FUNCTION__).warning("QSortFilterProxyModel: inconsistent changes reported by source model"); | - | ||||||||||||||||||||||||
| 788 | QSortFilterProxyModel * const q = q_func(); | - | ||||||||||||||||||||||||
| 789 | q->beginResetModel(); | - | ||||||||||||||||||||||||
| 790 | remove_from_mapping(source_parent); | - | ||||||||||||||||||||||||
| 791 | q->endResetModel(); | - | ||||||||||||||||||||||||
| 792 | return; | - | ||||||||||||||||||||||||
| 793 | } | - | ||||||||||||||||||||||||
| 794 | - | |||||||||||||||||||||||||
| 795 | - | |||||||||||||||||||||||||
| 796 | for (int proxy_item = 0; proxy_item < proxy_count; ++proxy_item) { | - | ||||||||||||||||||||||||
| 797 | int source_item = proxy_to_source.at(proxy_item); | - | ||||||||||||||||||||||||
| 798 | if (source_item >= start) { | - | ||||||||||||||||||||||||
| 799 | ((!(source_item - delta_item_count >= 0)) ? qt_assert("source_item - delta_item_count >= 0",__FILE__,905911) : qt_noop()); | - | ||||||||||||||||||||||||
| 800 | proxy_to_source.replace(proxy_item, source_item - delta_item_count); | - | ||||||||||||||||||||||||
| 801 | } | - | ||||||||||||||||||||||||
| 802 | } | - | ||||||||||||||||||||||||
| 803 | build_source_to_proxy_mapping(proxy_to_source, source_to_proxy); | - | ||||||||||||||||||||||||
| 804 | - | |||||||||||||||||||||||||
| 805 | updateChildrenMapping(source_parent, m, orient, start, end, delta_item_count, true); | - | ||||||||||||||||||||||||
| 806 | - | |||||||||||||||||||||||||
| 807 | } | - | ||||||||||||||||||||||||
| 808 | - | |||||||||||||||||||||||||
| 809 | - | |||||||||||||||||||||||||
| 810 | - | |||||||||||||||||||||||||
| 811 | - | |||||||||||||||||||||||||
| 812 | - | |||||||||||||||||||||||||
| 813 | - | |||||||||||||||||||||||||
| 814 | void QSortFilterProxyModelPrivate::updateChildrenMapping(const QModelIndex &source_parent, Mapping *parent_mapping, | - | ||||||||||||||||||||||||
| 815 | Qt::Orientation orient, int start, int end, int delta_item_count, bool remove) | - | ||||||||||||||||||||||||
| 816 | { | - | ||||||||||||||||||||||||
| 817 | - | |||||||||||||||||||||||||
| 818 | QVector<QPair<QModelIndex, Mapping*> > moved_source_index_mappings; | - | ||||||||||||||||||||||||
| 819 | QVector<QModelIndex>::iterator it2 = parent_mapping->mapped_children.begin(); | - | ||||||||||||||||||||||||
| 820 | for ( ; it2 != parent_mapping->mapped_children.end();) { | - | ||||||||||||||||||||||||
| 821 | const QModelIndex source_child_index = *it2; | - | ||||||||||||||||||||||||
| 822 | const int pos = (orient == Qt::Vertical) | - | ||||||||||||||||||||||||
| 823 | ? source_child_index.row() | - | ||||||||||||||||||||||||
| 824 | : source_child_index.column(); | - | ||||||||||||||||||||||||
| 825 | if (pos < start) { | - | ||||||||||||||||||||||||
| 826 | - | |||||||||||||||||||||||||
| 827 | ++it2; | - | ||||||||||||||||||||||||
| 828 | } else if (remove && pos <= end) { | - | ||||||||||||||||||||||||
| 829 | - | |||||||||||||||||||||||||
| 830 | it2 = parent_mapping->mapped_children.erase(it2); | - | ||||||||||||||||||||||||
| 831 | remove_from_mapping(source_child_index); | - | ||||||||||||||||||||||||
| 832 | } else { | - | ||||||||||||||||||||||||
| 833 | - | |||||||||||||||||||||||||
| 834 | QModelIndex new_index; | - | ||||||||||||||||||||||||
| 835 | const int newpos = remove ? pos - delta_item_count : pos + delta_item_count; | - | ||||||||||||||||||||||||
| 836 | if (orient == Qt::Vertical) { | - | ||||||||||||||||||||||||
| 837 | new_index = model->index(newpos, | - | ||||||||||||||||||||||||
| 838 | source_child_index.column(), | - | ||||||||||||||||||||||||
| 839 | source_parent); | - | ||||||||||||||||||||||||
| 840 | } else { | - | ||||||||||||||||||||||||
| 841 | new_index = model->index(source_child_index.row(), | - | ||||||||||||||||||||||||
| 842 | newpos, | - | ||||||||||||||||||||||||
| 843 | source_parent); | - | ||||||||||||||||||||||||
| 844 | } | - | ||||||||||||||||||||||||
| 845 | *it2 = new_index; | - | ||||||||||||||||||||||||
| 846 | ++it2; | - | ||||||||||||||||||||||||
| 847 | - | |||||||||||||||||||||||||
| 848 | - | |||||||||||||||||||||||||
| 849 | Mapping *cm = source_index_mapping.take(source_child_index); | - | ||||||||||||||||||||||||
| 850 | ((!(cm)) ? qt_assert("cm",__FILE__,956962) : qt_noop()); | - | ||||||||||||||||||||||||
| 851 | - | |||||||||||||||||||||||||
| 852 | moved_source_index_mappings.append(QPair<QModelIndex, Mapping*>(new_index, cm)); | - | ||||||||||||||||||||||||
| 853 | } | - | ||||||||||||||||||||||||
| 854 | } | - | ||||||||||||||||||||||||
| 855 | - | |||||||||||||||||||||||||
| 856 | - | |||||||||||||||||||||||||
| 857 | QVector<QPair<QModelIndex, Mapping*> >::iterator it = moved_source_index_mappings.begin(); | - | ||||||||||||||||||||||||
| 858 | for (; it != moved_source_index_mappings.end(); ++it) { | - | ||||||||||||||||||||||||
| 859 | - | |||||||||||||||||||||||||
| 860 | - | |||||||||||||||||||||||||
| 861 | - | |||||||||||||||||||||||||
| 862 | - | |||||||||||||||||||||||||
| 863 | (*it).second->map_iter = source_index_mapping.insert((*it).first, (*it).second); | - | ||||||||||||||||||||||||
| 864 | - | |||||||||||||||||||||||||
| 865 | } | - | ||||||||||||||||||||||||
| 866 | } | - | ||||||||||||||||||||||||
| 867 | - | |||||||||||||||||||||||||
| 868 | - | |||||||||||||||||||||||||
| 869 | - | |||||||||||||||||||||||||
| 870 | - | |||||||||||||||||||||||||
| 871 | void QSortFilterProxyModelPrivate::proxy_item_range( | - | ||||||||||||||||||||||||
| 872 | const QVector<int> &source_to_proxy, const QVector<int> &source_items, | - | ||||||||||||||||||||||||
| 873 | int &proxy_low, int &proxy_high) const | - | ||||||||||||||||||||||||
| 874 | { | - | ||||||||||||||||||||||||
| 875 | proxy_low = 2147483647; | - | ||||||||||||||||||||||||
| 876 | proxy_high = (-2147483647 - 1); | - | ||||||||||||||||||||||||
| 877 | for (int i = 0; i < source_items.count(); ++i) { | - | ||||||||||||||||||||||||
| 878 | int proxy_item = source_to_proxy.at(source_items.at(i)); | - | ||||||||||||||||||||||||
| 879 | ((!(proxy_item != -1)) ? qt_assert("proxy_item != -1",__FILE__,985991) : qt_noop()); | - | ||||||||||||||||||||||||
| 880 | if (proxy_item < proxy_low) | - | ||||||||||||||||||||||||
| 881 | proxy_low = proxy_item; | - | ||||||||||||||||||||||||
| 882 | if (proxy_item > proxy_high) | - | ||||||||||||||||||||||||
| 883 | proxy_high = proxy_item; | - | ||||||||||||||||||||||||
| 884 | } | - | ||||||||||||||||||||||||
| 885 | } | - | ||||||||||||||||||||||||
| 886 | - | |||||||||||||||||||||||||
| 887 | - | |||||||||||||||||||||||||
| 888 | - | |||||||||||||||||||||||||
| 889 | - | |||||||||||||||||||||||||
| 890 | void QSortFilterProxyModelPrivate::build_source_to_proxy_mapping( | - | ||||||||||||||||||||||||
| 891 | const QVector<int> &proxy_to_source, QVector<int> &source_to_proxy) const | - | ||||||||||||||||||||||||
| 892 | { | - | ||||||||||||||||||||||||
| 893 | source_to_proxy.fill(-1); | - | ||||||||||||||||||||||||
| 894 | int proxy_count = proxy_to_source.size(); | - | ||||||||||||||||||||||||
| 895 | for (int i = 0; i < proxy_count; ++i) | - | ||||||||||||||||||||||||
| 896 | source_to_proxy[proxy_to_source.at(i)] = i; | - | ||||||||||||||||||||||||
| 897 | } | - | ||||||||||||||||||||||||
| 898 | - | |||||||||||||||||||||||||
| 899 | - | |||||||||||||||||||||||||
| 900 | - | |||||||||||||||||||||||||
| 901 | - | |||||||||||||||||||||||||
| 902 | - | |||||||||||||||||||||||||
| 903 | - | |||||||||||||||||||||||||
| 904 | - | |||||||||||||||||||||||||
| 905 | QModelIndexPairList QSortFilterProxyModelPrivate::store_persistent_indexes() const | - | ||||||||||||||||||||||||
| 906 | { | - | ||||||||||||||||||||||||
| 907 | const QSortFilterProxyModel * const q = q_func(); | - | ||||||||||||||||||||||||
| 908 | QModelIndexPairList source_indexes; | - | ||||||||||||||||||||||||
| 909 | source_indexes.reserve(persistent.indexes.count()); | - | ||||||||||||||||||||||||
| 910 | for (QForeachContainer<typename QtPrivate::remove_reference<decltype(persistent.indexes)>::type> _container_((persistent.indexes)); _container_.control && _container_.i != _container_.e; ++_container_.i, _container_.control ^= 1)for (QPersistentModelIndexData *data = *_container_.i; _container_.control; _container_: qAsConst(persistent.control = 0)indexes)) { | - | ||||||||||||||||||||||||
| 911 | QModelIndex proxy_index = data->index; | - | ||||||||||||||||||||||||
| 912 | QModelIndex source_index = q->mapToSource(proxy_index); | - | ||||||||||||||||||||||||
| 913 | source_indexes.append(qMakePair(proxy_index, QPersistentModelIndex(source_index))); | - | ||||||||||||||||||||||||
| 914 | } executed 402 times by 10 tests: end of blockExecuted by:
| 402 | ||||||||||||||||||||||||
| 915 | return executed 1118 times by 13 tests: source_indexes;return source_indexes;Executed by:
executed 1118 times by 13 tests: return source_indexes;Executed by:
| 1118 | ||||||||||||||||||||||||
| 916 | } | - | ||||||||||||||||||||||||
| 917 | - | |||||||||||||||||||||||||
| 918 | - | |||||||||||||||||||||||||
| 919 | - | |||||||||||||||||||||||||
| 920 | - | |||||||||||||||||||||||||
| 921 | - | |||||||||||||||||||||||||
| 922 | - | |||||||||||||||||||||||||
| 923 | - | |||||||||||||||||||||||||
| 924 | void QSortFilterProxyModelPrivate::update_persistent_indexes( | - | ||||||||||||||||||||||||
| 925 | const QModelIndexPairList &source_indexes) | - | ||||||||||||||||||||||||
| 926 | { | - | ||||||||||||||||||||||||
| 927 | QSortFilterProxyModel * const q = q_func(); | - | ||||||||||||||||||||||||
| 928 | QModelIndexList from, to; | - | ||||||||||||||||||||||||
| 929 | const int numSourceIndexes = source_indexes.count(); | - | ||||||||||||||||||||||||
| 930 | from.reserve(numSourceIndexes); | - | ||||||||||||||||||||||||
| 931 | to.reserve(numSourceIndexes); | - | ||||||||||||||||||||||||
| 932 | for (int i = 0; i < numSourceIndexes; ++i) { | - | ||||||||||||||||||||||||
| 933 | QModelIndex source_index = source_indexes.at(i).second; | - | ||||||||||||||||||||||||
| 934 | QModelIndex old_proxy_index = source_indexes.at(i).first; | - | ||||||||||||||||||||||||
| 935 | create_mapping(source_index.parent()); | - | ||||||||||||||||||||||||
| 936 | QModelIndex proxy_index = q->mapFromSource(source_index); | - | ||||||||||||||||||||||||
| 937 | from << old_proxy_index; | - | ||||||||||||||||||||||||
| 938 | to << proxy_index; | - | ||||||||||||||||||||||||
| 939 | } | - | ||||||||||||||||||||||||
| 940 | q->changePersistentIndexList(from, to); | - | ||||||||||||||||||||||||
| 941 | } | - | ||||||||||||||||||||||||
| 942 | - | |||||||||||||||||||||||||
| 943 | - | |||||||||||||||||||||||||
| 944 | - | |||||||||||||||||||||||||
| 945 | - | |||||||||||||||||||||||||
| 946 | - | |||||||||||||||||||||||||
| 947 | - | |||||||||||||||||||||||||
| 948 | - | |||||||||||||||||||||||||
| 949 | void QSortFilterProxyModelPrivate::filter_about_to_be_changed(const QModelIndex &source_parent) | - | ||||||||||||||||||||||||
| 950 | { | - | ||||||||||||||||||||||||
| 951 | if (!filter_regexp.pattern().isEmpty() && | - | ||||||||||||||||||||||||
| 952 | source_index_mapping.constFind(source_parent) == source_index_mapping.constEnd()) | - | ||||||||||||||||||||||||
| 953 | create_mapping(source_parent); | - | ||||||||||||||||||||||||
| 954 | } | - | ||||||||||||||||||||||||
| 955 | void QSortFilterProxyModelPrivate::filter_changed(const QModelIndex &source_parent) | - | ||||||||||||||||||||||||
| 956 | { | - | ||||||||||||||||||||||||
| 957 | IndexMap::const_iterator it = source_index_mapping.constFind(source_parent); | - | ||||||||||||||||||||||||
| 958 | if (it == source_index_mapping.constEnd()) | - | ||||||||||||||||||||||||
| 959 | return; | - | ||||||||||||||||||||||||
| 960 | Mapping *m = it.value(); | - | ||||||||||||||||||||||||
| 961 | QSet<int> rows_removed = handle_filter_changed(m->proxy_rows, m->source_rows, source_parent, Qt::Vertical); | - | ||||||||||||||||||||||||
| 962 | QSet<int> columns_removed = handle_filter_changed(m->proxy_columns, m->source_columns, source_parent, Qt::Horizontal); | - | ||||||||||||||||||||||||
| 963 | - | |||||||||||||||||||||||||
| 964 | - | |||||||||||||||||||||||||
| 965 | - | |||||||||||||||||||||||||
| 966 | - | |||||||||||||||||||||||||
| 967 | - | |||||||||||||||||||||||||
| 968 | const QVector<QModelIndex> mappedChildren = m->mapped_children; | - | ||||||||||||||||||||||||
| 969 | QVector<int> indexesToRemove; | - | ||||||||||||||||||||||||
| 970 | for (int i = 0; i < mappedChildren.size(); ++i) { | - | ||||||||||||||||||||||||
| 971 | const QModelIndex source_child_index = mappedChildren.at(i); | - | ||||||||||||||||||||||||
| 972 | if (rows_removed.contains(source_child_index.row()) || columns_removed.contains(source_child_index.column())) { | - | ||||||||||||||||||||||||
| 973 | indexesToRemove.push_back(i); | - | ||||||||||||||||||||||||
| 974 | remove_from_mapping(source_child_index); | - | ||||||||||||||||||||||||
| 975 | } else { | - | ||||||||||||||||||||||||
| 976 | filter_changed(source_child_index); | - | ||||||||||||||||||||||||
| 977 | } | - | ||||||||||||||||||||||||
| 978 | } | - | ||||||||||||||||||||||||
| 979 | QVector<int>::const_iterator removeIt = indexesToRemove.constEnd(); | - | ||||||||||||||||||||||||
| 980 | const QVector<int>::const_iterator removeBegin = indexesToRemove.constBegin(); | - | ||||||||||||||||||||||||
| 981 | - | |||||||||||||||||||||||||
| 982 | - | |||||||||||||||||||||||||
| 983 | - | |||||||||||||||||||||||||
| 984 | - | |||||||||||||||||||||||||
| 985 | - | |||||||||||||||||||||||||
| 986 | - | |||||||||||||||||||||||||
| 987 | while (removeIt != removeBegin) { | - | ||||||||||||||||||||||||
| 988 | --removeIt; | - | ||||||||||||||||||||||||
| 989 | m->mapped_children.remove(*removeIt); | - | ||||||||||||||||||||||||
| 990 | } | - | ||||||||||||||||||||||||
| 991 | } | - | ||||||||||||||||||||||||
| 992 | - | |||||||||||||||||||||||||
| 993 | - | |||||||||||||||||||||||||
| 994 | - | |||||||||||||||||||||||||
| 995 | - | |||||||||||||||||||||||||
| 996 | - | |||||||||||||||||||||||||
| 997 | QSet<int> QSortFilterProxyModelPrivate::handle_filter_changed( | - | ||||||||||||||||||||||||
| 998 | QVector<int> &source_to_proxy, QVector<int> &proxy_to_source, | - | ||||||||||||||||||||||||
| 999 | const QModelIndex &source_parent, Qt::Orientation orient) | - | ||||||||||||||||||||||||
| 1000 | { | - | ||||||||||||||||||||||||
| 1001 | QSortFilterProxyModel * const q = q_func(); | - | ||||||||||||||||||||||||
| 1002 | - | |||||||||||||||||||||||||
| 1003 | QVector<int> source_items_remove; | - | ||||||||||||||||||||||||
| 1004 | for (int i = 0; i < proxy_to_source.count(); ++i) { | - | ||||||||||||||||||||||||
| 1005 | const int source_item = proxy_to_source.at(i); | - | ||||||||||||||||||||||||
| 1006 | if ((orient == Qt::Vertical) | - | ||||||||||||||||||||||||
| 1007 | ? !q->filterAcceptsRow(source_item, source_parent) | - | ||||||||||||||||||||||||
| 1008 | : !q->filterAcceptsColumn(source_item, source_parent)) { | - | ||||||||||||||||||||||||
| 1009 | - | |||||||||||||||||||||||||
| 1010 | source_items_remove.append(source_item); | - | ||||||||||||||||||||||||
| 1011 | } | - | ||||||||||||||||||||||||
| 1012 | } | - | ||||||||||||||||||||||||
| 1013 | - | |||||||||||||||||||||||||
| 1014 | QVector<int> source_items_insert; | - | ||||||||||||||||||||||||
| 1015 | int source_count = source_to_proxy.size(); | - | ||||||||||||||||||||||||
| 1016 | for (int source_item = 0; source_item < source_count; ++source_item) { | - | ||||||||||||||||||||||||
| 1017 | if (source_to_proxy.at(source_item) == -1) { | - | ||||||||||||||||||||||||
| 1018 | if ((orient == Qt::Vertical) | - | ||||||||||||||||||||||||
| 1019 | ? q->filterAcceptsRow(source_item, source_parent) | - | ||||||||||||||||||||||||
| 1020 | : q->filterAcceptsColumn(source_item, source_parent)) { | - | ||||||||||||||||||||||||
| 1021 | - | |||||||||||||||||||||||||
| 1022 | source_items_insert.append(source_item); | - | ||||||||||||||||||||||||
| 1023 | } | - | ||||||||||||||||||||||||
| 1024 | } | - | ||||||||||||||||||||||||
| 1025 | } | - | ||||||||||||||||||||||||
| 1026 | if (!source_items_remove.isEmpty() || !source_items_insert.isEmpty()) { | - | ||||||||||||||||||||||||
| 1027 | - | |||||||||||||||||||||||||
| 1028 | remove_source_items(source_to_proxy, proxy_to_source, | - | ||||||||||||||||||||||||
| 1029 | source_items_remove, source_parent, orient); | - | ||||||||||||||||||||||||
| 1030 | if (orient == Qt::Vertical) | - | ||||||||||||||||||||||||
| 1031 | sort_source_rows(source_items_insert, source_parent); | - | ||||||||||||||||||||||||
| 1032 | insert_source_items(source_to_proxy, proxy_to_source, | - | ||||||||||||||||||||||||
| 1033 | source_items_insert, source_parent, orient); | - | ||||||||||||||||||||||||
| 1034 | } | - | ||||||||||||||||||||||||
| 1035 | return qVectorToSet(source_items_remove); | - | ||||||||||||||||||||||||
| 1036 | } | - | ||||||||||||||||||||||||
| 1037 | - | |||||||||||||||||||||||||
| 1038 | void QSortFilterProxyModelPrivate::_q_sourceDataChanged(const QModelIndex &source_top_left, | - | ||||||||||||||||||||||||
| 1039 | const QModelIndex &source_bottom_right, | - | ||||||||||||||||||||||||
| 1040 | const QVector<int> &roles) | - | ||||||||||||||||||||||||
| 1041 | { | - | ||||||||||||||||||||||||
| 1042 | QSortFilterProxyModel * const q = q_func(); | - | ||||||||||||||||||||||||
| 1043 | if (!source_top_left.isValid() || !source_bottom_right.isValid()) | - | ||||||||||||||||||||||||
| 1044 | return; | - | ||||||||||||||||||||||||
| 1045 | QModelIndex source_parent = source_top_left.parent(); | - | ||||||||||||||||||||||||
| 1046 | IndexMap::const_iterator it = source_index_mapping.constFind(source_parent); | - | ||||||||||||||||||||||||
| 1047 | if (it == source_index_mapping.constEnd()) { | - | ||||||||||||||||||||||||
| 1048 | - | |||||||||||||||||||||||||
| 1049 | return; | - | ||||||||||||||||||||||||
| 1050 | } | - | ||||||||||||||||||||||||
| 1051 | Mapping *m = it.value(); | - | ||||||||||||||||||||||||
| 1052 | - | |||||||||||||||||||||||||
| 1053 | - | |||||||||||||||||||||||||
| 1054 | QVector<int> source_rows_remove; | - | ||||||||||||||||||||||||
| 1055 | QVector<int> source_rows_insert; | - | ||||||||||||||||||||||||
| 1056 | QVector<int> source_rows_change; | - | ||||||||||||||||||||||||
| 1057 | QVector<int> source_rows_resort; | - | ||||||||||||||||||||||||
| 1058 | int end = qMin(source_bottom_right.row(), m->proxy_rows.count() - 1); | - | ||||||||||||||||||||||||
| 1059 | for (int source_row = source_top_left.row(); source_row <= end; ++source_row) { | - | ||||||||||||||||||||||||
| 1060 | if (dynamic_sortfilter) { | - | ||||||||||||||||||||||||
| 1061 | if (m->proxy_rows.at(source_row) != -1) { | - | ||||||||||||||||||||||||
| 1062 | if (!q->filterAcceptsRow(source_row, source_parent)) { | - | ||||||||||||||||||||||||
| 1063 | - | |||||||||||||||||||||||||
| 1064 | source_rows_remove.append(source_row); | - | ||||||||||||||||||||||||
| 1065 | } else if (source_sort_column >= source_top_left.column() && source_sort_column <= source_bottom_right.column()) { | - | ||||||||||||||||||||||||
| 1066 | - | |||||||||||||||||||||||||
| 1067 | source_rows_resort.append(source_row); | - | ||||||||||||||||||||||||
| 1068 | } else { | - | ||||||||||||||||||||||||
| 1069 | - | |||||||||||||||||||||||||
| 1070 | source_rows_change.append(source_row); | - | ||||||||||||||||||||||||
| 1071 | } | - | ||||||||||||||||||||||||
| 1072 | } else { | - | ||||||||||||||||||||||||
| 1073 | if (!itemsBeingRemoved.contains(source_parent, source_row) && q->filterAcceptsRow(source_row, source_parent)) { | - | ||||||||||||||||||||||||
| 1074 | - | |||||||||||||||||||||||||
| 1075 | source_rows_insert.append(source_row); | - | ||||||||||||||||||||||||
| 1076 | } | - | ||||||||||||||||||||||||
| 1077 | } | - | ||||||||||||||||||||||||
| 1078 | } else { | - | ||||||||||||||||||||||||
| 1079 | if (m->proxy_rows.at(source_row) != -1) | - | ||||||||||||||||||||||||
| 1080 | source_rows_change.append(source_row); | - | ||||||||||||||||||||||||
| 1081 | } | - | ||||||||||||||||||||||||
| 1082 | } | - | ||||||||||||||||||||||||
| 1083 | - | |||||||||||||||||||||||||
| 1084 | if (!source_rows_remove.isEmpty()) { | - | ||||||||||||||||||||||||
| 1085 | remove_source_items(m->proxy_rows, m->source_rows, | - | ||||||||||||||||||||||||
| 1086 | source_rows_remove, source_parent, Qt::Vertical); | - | ||||||||||||||||||||||||
| 1087 | QSet<int> source_rows_remove_set = qVectorToSet(source_rows_remove); | - | ||||||||||||||||||||||||
| 1088 | QVector<QModelIndex>::iterator childIt = m->mapped_children.end(); | - | ||||||||||||||||||||||||
| 1089 | while (childIt != m->mapped_children.begin()) { | - | ||||||||||||||||||||||||
| 1090 | --childIt; | - | ||||||||||||||||||||||||
| 1091 | const QModelIndex source_child_index = *childIt; | - | ||||||||||||||||||||||||
| 1092 | if (source_rows_remove_set.contains(source_child_index.row())) { | - | ||||||||||||||||||||||||
| 1093 | childIt = m->mapped_children.erase(childIt); | - | ||||||||||||||||||||||||
| 1094 | remove_from_mapping(source_child_index); | - | ||||||||||||||||||||||||
| 1095 | } | - | ||||||||||||||||||||||||
| 1096 | } | - | ||||||||||||||||||||||||
| 1097 | } | - | ||||||||||||||||||||||||
| 1098 | - | |||||||||||||||||||||||||
| 1099 | if (!source_rows_resort.isEmpty()) { | - | ||||||||||||||||||||||||
| 1100 | - | |||||||||||||||||||||||||
| 1101 | QList<QPersistentModelIndex> parents; | - | ||||||||||||||||||||||||
| 1102 | parents << q->mapFromSource(source_parent); | - | ||||||||||||||||||||||||
| 1103 | q->layoutAboutToBeChanged(parents, QAbstractItemModel::VerticalSortHint); | - | ||||||||||||||||||||||||
| 1104 | QModelIndexPairList source_indexes = store_persistent_indexes(); | - | ||||||||||||||||||||||||
| 1105 | remove_source_items(m->proxy_rows, m->source_rows, source_rows_resort, | - | ||||||||||||||||||||||||
| 1106 | source_parent, Qt::Vertical, false); | - | ||||||||||||||||||||||||
| 1107 | sort_source_rows(source_rows_resort, source_parent); | - | ||||||||||||||||||||||||
| 1108 | insert_source_items(m->proxy_rows, m->source_rows, source_rows_resort, | - | ||||||||||||||||||||||||
| 1109 | source_parent, Qt::Vertical, false); | - | ||||||||||||||||||||||||
| 1110 | update_persistent_indexes(source_indexes); | - | ||||||||||||||||||||||||
| 1111 | q->layoutChanged(parents, QAbstractItemModel::VerticalSortHint); | - | ||||||||||||||||||||||||
| 1112 | - | |||||||||||||||||||||||||
| 1113 | source_rows_change += source_rows_resort; | - | ||||||||||||||||||||||||
| 1114 | } | - | ||||||||||||||||||||||||
| 1115 | - | |||||||||||||||||||||||||
| 1116 | if (!source_rows_change.isEmpty()) { | - | ||||||||||||||||||||||||
| 1117 | - | |||||||||||||||||||||||||
| 1118 | int proxy_start_row; | - | ||||||||||||||||||||||||
| 1119 | int proxy_end_row; | - | ||||||||||||||||||||||||
| 1120 | proxy_item_range(m->proxy_rows, source_rows_change, | - | ||||||||||||||||||||||||
| 1121 | proxy_start_row, proxy_end_row); | - | ||||||||||||||||||||||||
| 1122 | - | |||||||||||||||||||||||||
| 1123 | if (proxy_end_row >= 0) { | - | ||||||||||||||||||||||||
| 1124 | - | |||||||||||||||||||||||||
| 1125 | int source_left_column = source_top_left.column(); | - | ||||||||||||||||||||||||
| 1126 | while (source_left_column < source_bottom_right.column() | - | ||||||||||||||||||||||||
| 1127 | && m->proxy_columns.at(source_left_column) == -1) | - | ||||||||||||||||||||||||
| 1128 | ++source_left_column; | - | ||||||||||||||||||||||||
| 1129 | const QModelIndex proxy_top_left = create_index( | - | ||||||||||||||||||||||||
| 1130 | proxy_start_row, m->proxy_columns.at(source_left_column), it); | - | ||||||||||||||||||||||||
| 1131 | int source_right_column = source_bottom_right.column(); | - | ||||||||||||||||||||||||
| 1132 | while (source_right_column > source_top_left.column() | - | ||||||||||||||||||||||||
| 1133 | && m->proxy_columns.at(source_right_column) == -1) | - | ||||||||||||||||||||||||
| 1134 | --source_right_column; | - | ||||||||||||||||||||||||
| 1135 | const QModelIndex proxy_bottom_right = create_index( | - | ||||||||||||||||||||||||
| 1136 | proxy_end_row, m->proxy_columns.at(source_right_column), it); | - | ||||||||||||||||||||||||
| 1137 | q->dataChanged(proxy_top_left, proxy_bottom_right, roles); | - | ||||||||||||||||||||||||
| 1138 | } | - | ||||||||||||||||||||||||
| 1139 | } | - | ||||||||||||||||||||||||
| 1140 | - | |||||||||||||||||||||||||
| 1141 | if (!source_rows_insert.isEmpty()) { | - | ||||||||||||||||||||||||
| 1142 | sort_source_rows(source_rows_insert, source_parent); | - | ||||||||||||||||||||||||
| 1143 | insert_source_items(m->proxy_rows, m->source_rows, | - | ||||||||||||||||||||||||
| 1144 | source_rows_insert, source_parent, Qt::Vertical); | - | ||||||||||||||||||||||||
| 1145 | } | - | ||||||||||||||||||||||||
| 1146 | } | - | ||||||||||||||||||||||||
| 1147 | - | |||||||||||||||||||||||||
| 1148 | void QSortFilterProxyModelPrivate::_q_sourceHeaderDataChanged(Qt::Orientation orientation, | - | ||||||||||||||||||||||||
| 1149 | int start, int end) | - | ||||||||||||||||||||||||
| 1150 | { | - | ||||||||||||||||||||||||
| 1151 | ((!(start <= end)) ? qt_assert("start <= end",__FILE__,12651271) : qt_noop()); | - | ||||||||||||||||||||||||
| 1152 | - | |||||||||||||||||||||||||
| 1153 | QSortFilterProxyModel * const q = q_func(); | - | ||||||||||||||||||||||||
| 1154 | Mapping *m = create_mapping(QModelIndex()).value(); | - | ||||||||||||||||||||||||
| 1155 | - | |||||||||||||||||||||||||
| 1156 | const QVector<int> &source_to_proxy = (orientation == Qt::Vertical) ? m->proxy_rows : m->proxy_columns; | - | ||||||||||||||||||||||||
| 1157 | - | |||||||||||||||||||||||||
| 1158 | QVector<int> proxy_positions; | - | ||||||||||||||||||||||||
| 1159 | proxy_positions.reserve(end - start + 1); | - | ||||||||||||||||||||||||
| 1160 | { | - | ||||||||||||||||||||||||
| 1161 | ((!(source_to_proxy.size() > end)) ? qt_assert("source_to_proxy.size() > end",__FILE__,12751281) : qt_noop()); | - | ||||||||||||||||||||||||
| 1162 | QVector<int>::const_iterator it = source_to_proxy.constBegin() + start; | - | ||||||||||||||||||||||||
| 1163 | const QVector<int>::const_iterator endIt = source_to_proxy.constBegin() + end + 1; | - | ||||||||||||||||||||||||
| 1164 | for ( ; it != endIt; ++it) { | - | ||||||||||||||||||||||||
| 1165 | if (*it != -1) | - | ||||||||||||||||||||||||
| 1166 | proxy_positions.push_back(*it); | - | ||||||||||||||||||||||||
| 1167 | } | - | ||||||||||||||||||||||||
| 1168 | } | - | ||||||||||||||||||||||||
| 1169 | - | |||||||||||||||||||||||||
| 1170 | std::sort(proxy_positions.begin(), proxy_positions.end()); | - | ||||||||||||||||||||||||
| 1171 | - | |||||||||||||||||||||||||
| 1172 | int last_index = 0; | - | ||||||||||||||||||||||||
| 1173 | const int numItems = proxy_positions.size(); | - | ||||||||||||||||||||||||
| 1174 | while (last_index < numItems) { | - | ||||||||||||||||||||||||
| 1175 | const int proxyStart = proxy_positions.at(last_index); | - | ||||||||||||||||||||||||
| 1176 | int proxyEnd = proxyStart; | - | ||||||||||||||||||||||||
| 1177 | ++last_index; | - | ||||||||||||||||||||||||
| 1178 | for (int i = last_index; i < numItems; ++i) { | - | ||||||||||||||||||||||||
| 1179 | if (proxy_positions.at(i) == proxyEnd + 1) { | - | ||||||||||||||||||||||||
| 1180 | ++last_index; | - | ||||||||||||||||||||||||
| 1181 | ++proxyEnd; | - | ||||||||||||||||||||||||
| 1182 | } else { | - | ||||||||||||||||||||||||
| 1183 | break; | - | ||||||||||||||||||||||||
| 1184 | } | - | ||||||||||||||||||||||||
| 1185 | } | - | ||||||||||||||||||||||||
| 1186 | q->headerDataChanged(orientation, proxyStart, proxyEnd); | - | ||||||||||||||||||||||||
| 1187 | } | - | ||||||||||||||||||||||||
| 1188 | } | - | ||||||||||||||||||||||||
| 1189 | - | |||||||||||||||||||||||||
| 1190 | void QSortFilterProxyModelPrivate::_q_sourceAboutToBeReset() | - | ||||||||||||||||||||||||
| 1191 | { | - | ||||||||||||||||||||||||
| 1192 | QSortFilterProxyModel * const q = q_func(); | - | ||||||||||||||||||||||||
| 1193 | q->beginResetModel(); | - | ||||||||||||||||||||||||
| 1194 | } | - | ||||||||||||||||||||||||
| 1195 | - | |||||||||||||||||||||||||
| 1196 | void QSortFilterProxyModelPrivate::_q_sourceReset() | - | ||||||||||||||||||||||||
| 1197 | { | - | ||||||||||||||||||||||||
| 1198 | QSortFilterProxyModel * const q = q_func(); | - | ||||||||||||||||||||||||
| 1199 | invalidatePersistentIndexes(); | - | ||||||||||||||||||||||||
| 1200 | _q_clearMapping(); | - | ||||||||||||||||||||||||
| 1201 | - | |||||||||||||||||||||||||
| 1202 | q->endResetModel(); | - | ||||||||||||||||||||||||
| 1203 | update_source_sort_column(); | - | ||||||||||||||||||||||||
| 1204 | if (dynamic_sortfilter) | - | ||||||||||||||||||||||||
| 1205 | sort(); | - | ||||||||||||||||||||||||
| 1206 | } | - | ||||||||||||||||||||||||
| 1207 | - | |||||||||||||||||||||||||
| 1208 | void QSortFilterProxyModelPrivate::_q_sourceLayoutAboutToBeChanged(const QList<QPersistentModelIndex> &sourceParents, QAbstractItemModel::LayoutChangeHint hint) | - | ||||||||||||||||||||||||
| 1209 | { | - | ||||||||||||||||||||||||
| 1210 | QSortFilterProxyModel * const q = q_func(); | - | ||||||||||||||||||||||||
| 1211 | (void)hint;; | - | ||||||||||||||||||||||||
| 1212 | saved_persistent_indexes.clear(); | - | ||||||||||||||||||||||||
| 1213 | - | |||||||||||||||||||||||||
| 1214 | QList<QPersistentModelIndex> parents; | - | ||||||||||||||||||||||||
| for (QForeachContainer<typename QtPrivate::remove_reference<decltype(sourceParents)>::type> _container_((sourceParents)); _container_.control && _container_.i != _container_.e; | ||||||||||||||||||||||||||
| 1215 | ++_container_.i, _container_.control ^= 1)for (const QPersistentModelIndex &parent = *_container_.i; _container_.control; _container_.control = 0: sourceParents) { | - | ||||||||||||||||||||||||
| 1216 | if (!parent.isValid()
| 4-5 | ||||||||||||||||||||||||
| 1217 | parents << QPersistentModelIndex(); | - | ||||||||||||||||||||||||
| 1218 | continue; executed 4 times by 2 tests: continue;Executed by:
| 4 | ||||||||||||||||||||||||
| 1219 | } | - | ||||||||||||||||||||||||
| 1220 | const QModelIndex mappedParent = q->mapFromSource(parent); | - | ||||||||||||||||||||||||
| 1221 | - | |||||||||||||||||||||||||
| 1222 | if (mappedParent.isValid()
| 2-3 | ||||||||||||||||||||||||
| 1223 | parents << mappedParent; executed 2 times by 1 test: parents << mappedParent;Executed by:
| 2 | ||||||||||||||||||||||||
| 1224 | } executed 5 times by 1 test: end of blockExecuted by:
| 5 | ||||||||||||||||||||||||
| 1225 | - | |||||||||||||||||||||||||
| 1226 | - | |||||||||||||||||||||||||
| 1227 | if (!sourceParents.isEmpty()
| 1-7 | ||||||||||||||||||||||||
| 1228 | return; executed 1 time by 1 test: return;Executed by:
| 1 | ||||||||||||||||||||||||
| 1229 | - | |||||||||||||||||||||||||
| 1230 | q->layoutAboutToBeChanged(parents); | - | ||||||||||||||||||||||||
| 1231 | if (persistent.indexes.isEmpty()
| 4-6 | ||||||||||||||||||||||||
| 1232 | return; executed 4 times by 2 tests: return;Executed by:
| 4 | ||||||||||||||||||||||||
| 1233 | - | |||||||||||||||||||||||||
| 1234 | saved_persistent_indexes = store_persistent_indexes(); | - | ||||||||||||||||||||||||
| 1235 | } executed 6 times by 2 tests: end of blockExecuted by:
| 6 | ||||||||||||||||||||||||
| 1236 | - | |||||||||||||||||||||||||
| 1237 | void QSortFilterProxyModelPrivate::_q_sourceLayoutChanged(const QList<QPersistentModelIndex> &sourceParents, QAbstractItemModel::LayoutChangeHint hint) | - | ||||||||||||||||||||||||
| 1238 | { | - | ||||||||||||||||||||||||
| 1239 | QSortFilterProxyModel * const q = q_func(); | - | ||||||||||||||||||||||||
| 1240 | (void)hint;; | - | ||||||||||||||||||||||||
| 1241 | - | |||||||||||||||||||||||||
| 1242 | - | |||||||||||||||||||||||||
| 1243 | - | |||||||||||||||||||||||||
| 1244 | qDeleteAll(source_index_mapping); | - | ||||||||||||||||||||||||
| 1245 | source_index_mapping.clear(); | - | ||||||||||||||||||||||||
| 1246 | - | |||||||||||||||||||||||||
| 1247 | update_persistent_indexes(saved_persistent_indexes); | - | ||||||||||||||||||||||||
| 1248 | saved_persistent_indexes.clear(); | - | ||||||||||||||||||||||||
| 1249 | - | |||||||||||||||||||||||||
| 1250 | if (dynamic_sortfilter
| 0-11 | ||||||||||||||||||||||||
| 1251 | - | |||||||||||||||||||||||||
| 1252 | qDeleteAll(source_index_mapping); | - | ||||||||||||||||||||||||
| 1253 | source_index_mapping.clear(); | - | ||||||||||||||||||||||||
| 1254 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1255 | - | |||||||||||||||||||||||||
| 1256 | QList<QPersistentModelIndex> parents; | - | ||||||||||||||||||||||||
| for (QForeachContainer<typename QtPrivate::remove_reference<decltype(sourceParents)>::type> _container_((sourceParents)); _container_.control && _container_.i != _container_.e; | ||||||||||||||||||||||||||
| 1257 | ++_container_.i, _container_.control ^= 1)for (const QPersistentModelIndex &parent = *_container_.i; _container_.control; _container_.control = 0: sourceParents) { | - | ||||||||||||||||||||||||
| 1258 | if (!parent.isValid()
| 4-5 | ||||||||||||||||||||||||
| 1259 | parents << QPersistentModelIndex(); | - | ||||||||||||||||||||||||
| 1260 | continue; executed 4 times by 2 tests: continue;Executed by:
| 4 | ||||||||||||||||||||||||
| 1261 | } | - | ||||||||||||||||||||||||
| 1262 | const QModelIndex mappedParent = q->mapFromSource(parent); | - | ||||||||||||||||||||||||
| 1263 | if (mappedParent.isValid()
| 2-3 | ||||||||||||||||||||||||
| 1264 | parents << mappedParent; executed 2 times by 1 test: parents << mappedParent;Executed by:
| 2 | ||||||||||||||||||||||||
| 1265 | } executed 5 times by 1 test: end of blockExecuted by:
| 5 | ||||||||||||||||||||||||
| 1266 | - | |||||||||||||||||||||||||
| 1267 | if (!sourceParents.isEmpty()
| 1-7 | ||||||||||||||||||||||||
| 1268 | return; executed 1 time by 1 test: return;Executed by:
| 1 | ||||||||||||||||||||||||
| 1269 | - | |||||||||||||||||||||||||
| 1270 | q->layoutChanged(parents); | - | ||||||||||||||||||||||||
| 1271 | } executed 10 times by 3 tests: end of blockExecuted by:
| 10 | ||||||||||||||||||||||||
| 1272 | - | |||||||||||||||||||||||||
| 1273 | void QSortFilterProxyModelPrivate::_q_sourceRowsAboutToBeInserted( | - | ||||||||||||||||||||||||
| 1274 | const QModelIndex &source_parent, int start, int end) | - | ||||||||||||||||||||||||
| 1275 | { | - | ||||||||||||||||||||||||
| 1276 | (void)start;; | - | ||||||||||||||||||||||||
| 1277 | (void)end;; | - | ||||||||||||||||||||||||
| 1278 | - | |||||||||||||||||||||||||
| 1279 | - | |||||||||||||||||||||||||
| 1280 | if (can_create_mapping(source_parent)) | - | ||||||||||||||||||||||||
| 1281 | create_mapping(source_parent); | - | ||||||||||||||||||||||||
| 1282 | } | - | ||||||||||||||||||||||||
| 1283 | - | |||||||||||||||||||||||||
| 1284 | void QSortFilterProxyModelPrivate::_q_sourceRowsInserted( | - | ||||||||||||||||||||||||
| 1285 | const QModelIndex &source_parent, int start, int end) | - | ||||||||||||||||||||||||
| 1286 | { | - | ||||||||||||||||||||||||
| 1287 | source_items_inserted(source_parent, start, end, Qt::Vertical); | - | ||||||||||||||||||||||||
| 1288 | if (update_source_sort_column() && dynamic_sortfilter) | - | ||||||||||||||||||||||||
| 1289 | sort(); | - | ||||||||||||||||||||||||
| 1290 | } | - | ||||||||||||||||||||||||
| 1291 | - | |||||||||||||||||||||||||
| 1292 | void QSortFilterProxyModelPrivate::_q_sourceRowsAboutToBeRemoved( | - | ||||||||||||||||||||||||
| 1293 | const QModelIndex &source_parent, int start, int end) | - | ||||||||||||||||||||||||
| 1294 | { | - | ||||||||||||||||||||||||
| 1295 | itemsBeingRemoved = QRowsRemoval(source_parent, start, end); | - | ||||||||||||||||||||||||
| 1296 | source_items_about_to_be_removed(source_parent, start, end, | - | ||||||||||||||||||||||||
| 1297 | Qt::Vertical); | - | ||||||||||||||||||||||||
| 1298 | } | - | ||||||||||||||||||||||||
| 1299 | - | |||||||||||||||||||||||||
| 1300 | void QSortFilterProxyModelPrivate::_q_sourceRowsRemoved( | - | ||||||||||||||||||||||||
| 1301 | const QModelIndex &source_parent, int start, int end) | - | ||||||||||||||||||||||||
| 1302 | { | - | ||||||||||||||||||||||||
| 1303 | itemsBeingRemoved = QRowsRemoval(); | - | ||||||||||||||||||||||||
| 1304 | source_items_removed(source_parent, start, end, Qt::Vertical); | - | ||||||||||||||||||||||||
| 1305 | } | - | ||||||||||||||||||||||||
| 1306 | - | |||||||||||||||||||||||||
| 1307 | void QSortFilterProxyModelPrivate::_q_sourceRowsAboutToBeMoved( | - | ||||||||||||||||||||||||
| 1308 | const QModelIndex &sourceParent, int , int , const QModelIndex &destParent, int ) | - | ||||||||||||||||||||||||
| 1309 | { | - | ||||||||||||||||||||||||
| 1310 | QSortFilterProxyModel * const q = q_func(); | - | ||||||||||||||||||||||||
| 1311 | - | |||||||||||||||||||||||||
| 1312 | - | |||||||||||||||||||||||||
| 1313 | - | |||||||||||||||||||||||||
| 1314 | - | |||||||||||||||||||||||||
| 1315 | - | |||||||||||||||||||||||||
| 1316 | - | |||||||||||||||||||||||||
| 1317 | saved_persistent_indexes.clear(); | - | ||||||||||||||||||||||||
| 1318 | - | |||||||||||||||||||||||||
| 1319 | QList<QPersistentModelIndex> parents; | - | ||||||||||||||||||||||||
| 1320 | parents << q->mapFromSource(sourceParent); | - | ||||||||||||||||||||||||
| 1321 | if (sourceParent != destParent) | - | ||||||||||||||||||||||||
| 1322 | parents << q->mapFromSource(destParent); | - | ||||||||||||||||||||||||
| 1323 | q->layoutAboutToBeChanged(parents); | - | ||||||||||||||||||||||||
| 1324 | if (persistent.indexes.isEmpty()) | - | ||||||||||||||||||||||||
| 1325 | return; | - | ||||||||||||||||||||||||
| 1326 | saved_persistent_indexes = store_persistent_indexes(); | - | ||||||||||||||||||||||||
| 1327 | } | - | ||||||||||||||||||||||||
| 1328 | - | |||||||||||||||||||||||||
| 1329 | void QSortFilterProxyModelPrivate::_q_sourceRowsMoved( | - | ||||||||||||||||||||||||
| 1330 | const QModelIndex &sourceParent, int , int , const QModelIndex &destParent, int ) | - | ||||||||||||||||||||||||
| 1331 | { | - | ||||||||||||||||||||||||
| 1332 | QSortFilterProxyModel * const q = q_func(); | - | ||||||||||||||||||||||||
| 1333 | - | |||||||||||||||||||||||||
| 1334 | - | |||||||||||||||||||||||||
| 1335 | - | |||||||||||||||||||||||||
| 1336 | qDeleteAll(source_index_mapping); | - | ||||||||||||||||||||||||
| 1337 | source_index_mapping.clear(); | - | ||||||||||||||||||||||||
| 1338 | - | |||||||||||||||||||||||||
| 1339 | update_persistent_indexes(saved_persistent_indexes); | - | ||||||||||||||||||||||||
| 1340 | saved_persistent_indexes.clear(); | - | ||||||||||||||||||||||||
| 1341 | - | |||||||||||||||||||||||||
| 1342 | if (dynamic_sortfilter && update_source_sort_column()) { | - | ||||||||||||||||||||||||
| 1343 | - | |||||||||||||||||||||||||
| 1344 | qDeleteAll(source_index_mapping); | - | ||||||||||||||||||||||||
| 1345 | source_index_mapping.clear(); | - | ||||||||||||||||||||||||
| 1346 | } | - | ||||||||||||||||||||||||
| 1347 | - | |||||||||||||||||||||||||
| 1348 | QList<QPersistentModelIndex> parents; | - | ||||||||||||||||||||||||
| 1349 | parents << q->mapFromSource(sourceParent); | - | ||||||||||||||||||||||||
| 1350 | if (sourceParent != destParent) | - | ||||||||||||||||||||||||
| 1351 | parents << q->mapFromSource(destParent); | - | ||||||||||||||||||||||||
| 1352 | q->layoutChanged(parents); | - | ||||||||||||||||||||||||
| 1353 | } | - | ||||||||||||||||||||||||
| 1354 | - | |||||||||||||||||||||||||
| 1355 | void QSortFilterProxyModelPrivate::_q_sourceColumnsAboutToBeInserted( | - | ||||||||||||||||||||||||
| 1356 | const QModelIndex &source_parent, int start, int end) | - | ||||||||||||||||||||||||
| 1357 | { | - | ||||||||||||||||||||||||
| 1358 | (void)start;; | - | ||||||||||||||||||||||||
| 1359 | (void)end;; | - | ||||||||||||||||||||||||
| 1360 | - | |||||||||||||||||||||||||
| 1361 | - | |||||||||||||||||||||||||
| 1362 | if (can_create_mapping(source_parent)) | - | ||||||||||||||||||||||||
| 1363 | create_mapping(source_parent); | - | ||||||||||||||||||||||||
| 1364 | } | - | ||||||||||||||||||||||||
| 1365 | - | |||||||||||||||||||||||||
| 1366 | void QSortFilterProxyModelPrivate::_q_sourceColumnsInserted( | - | ||||||||||||||||||||||||
| 1367 | const QModelIndex &source_parent, int start, int end) | - | ||||||||||||||||||||||||
| 1368 | { | - | ||||||||||||||||||||||||
| 1369 | const QSortFilterProxyModel * const q = q_func(); | - | ||||||||||||||||||||||||
| 1370 | source_items_inserted(source_parent, start, end, Qt::Horizontal); | - | ||||||||||||||||||||||||
| 1371 | - | |||||||||||||||||||||||||
| 1372 | if (source_parent.isValid()) | - | ||||||||||||||||||||||||
| 1373 | return; | - | ||||||||||||||||||||||||
| 1374 | if (source_sort_column == -1) { | - | ||||||||||||||||||||||||
| 1375 | - | |||||||||||||||||||||||||
| 1376 | if (update_source_sort_column() && dynamic_sortfilter) | - | ||||||||||||||||||||||||
| 1377 | sort(); | - | ||||||||||||||||||||||||
| 1378 | } else { | - | ||||||||||||||||||||||||
| 1379 | if (start <= source_sort_column) | - | ||||||||||||||||||||||||
| 1380 | source_sort_column += end - start + 1; | - | ||||||||||||||||||||||||
| 1381 | - | |||||||||||||||||||||||||
| 1382 | proxy_sort_column = q->mapFromSource(model->index(0,source_sort_column, source_parent)).column(); | - | ||||||||||||||||||||||||
| 1383 | } | - | ||||||||||||||||||||||||
| 1384 | } | - | ||||||||||||||||||||||||
| 1385 | - | |||||||||||||||||||||||||
| 1386 | void QSortFilterProxyModelPrivate::_q_sourceColumnsAboutToBeRemoved( | - | ||||||||||||||||||||||||
| 1387 | const QModelIndex &source_parent, int start, int end) | - | ||||||||||||||||||||||||
| 1388 | { | - | ||||||||||||||||||||||||
| 1389 | source_items_about_to_be_removed(source_parent, start, end, | - | ||||||||||||||||||||||||
| 1390 | Qt::Horizontal); | - | ||||||||||||||||||||||||
| 1391 | } | - | ||||||||||||||||||||||||
| 1392 | - | |||||||||||||||||||||||||
| 1393 | void QSortFilterProxyModelPrivate::_q_sourceColumnsRemoved( | - | ||||||||||||||||||||||||
| 1394 | const QModelIndex &source_parent, int start, int end) | - | ||||||||||||||||||||||||
| 1395 | { | - | ||||||||||||||||||||||||
| 1396 | const QSortFilterProxyModel * const q = q_func(); | - | ||||||||||||||||||||||||
| 1397 | source_items_removed(source_parent, start, end, Qt::Horizontal); | - | ||||||||||||||||||||||||
| 1398 | - | |||||||||||||||||||||||||
| 1399 | if (source_parent.isValid()) | - | ||||||||||||||||||||||||
| 1400 | return; | - | ||||||||||||||||||||||||
| 1401 | if (start <= source_sort_column) { | - | ||||||||||||||||||||||||
| 1402 | if (end < source_sort_column) | - | ||||||||||||||||||||||||
| 1403 | source_sort_column -= end - start + 1; | - | ||||||||||||||||||||||||
| 1404 | else | - | ||||||||||||||||||||||||
| 1405 | source_sort_column = -1; | - | ||||||||||||||||||||||||
| 1406 | } | - | ||||||||||||||||||||||||
| 1407 | - | |||||||||||||||||||||||||
| 1408 | proxy_sort_column = q->mapFromSource(model->index(0,source_sort_column, source_parent)).column(); | - | ||||||||||||||||||||||||
| 1409 | } | - | ||||||||||||||||||||||||
| 1410 | - | |||||||||||||||||||||||||
| 1411 | void QSortFilterProxyModelPrivate::_q_sourceColumnsAboutToBeMoved( | - | ||||||||||||||||||||||||
| 1412 | const QModelIndex &sourceParent, int , int , const QModelIndex &destParent, int ) | - | ||||||||||||||||||||||||
| 1413 | { | - | ||||||||||||||||||||||||
| 1414 | QSortFilterProxyModel * const q = q_func(); | - | ||||||||||||||||||||||||
| 1415 | - | |||||||||||||||||||||||||
| 1416 | saved_persistent_indexes.clear(); | - | ||||||||||||||||||||||||
| 1417 | - | |||||||||||||||||||||||||
| 1418 | QList<QPersistentModelIndex> parents; | - | ||||||||||||||||||||||||
| 1419 | parents << q->mapFromSource(sourceParent); | - | ||||||||||||||||||||||||
| 1420 | if (sourceParent != destParent) | - | ||||||||||||||||||||||||
| 1421 | parents << q->mapFromSource(destParent); | - | ||||||||||||||||||||||||
| 1422 | q->layoutAboutToBeChanged(parents); | - | ||||||||||||||||||||||||
| 1423 | - | |||||||||||||||||||||||||
| 1424 | if (persistent.indexes.isEmpty()) | - | ||||||||||||||||||||||||
| 1425 | return; | - | ||||||||||||||||||||||||
| 1426 | saved_persistent_indexes = store_persistent_indexes(); | - | ||||||||||||||||||||||||
| 1427 | } | - | ||||||||||||||||||||||||
| 1428 | - | |||||||||||||||||||||||||
| 1429 | void QSortFilterProxyModelPrivate::_q_sourceColumnsMoved( | - | ||||||||||||||||||||||||
| 1430 | const QModelIndex &sourceParent, int , int , const QModelIndex &destParent, int ) | - | ||||||||||||||||||||||||
| 1431 | { | - | ||||||||||||||||||||||||
| 1432 | QSortFilterProxyModel * const q = q_func(); | - | ||||||||||||||||||||||||
| 1433 | - | |||||||||||||||||||||||||
| 1434 | qDeleteAll(source_index_mapping); | - | ||||||||||||||||||||||||
| 1435 | source_index_mapping.clear(); | - | ||||||||||||||||||||||||
| 1436 | - | |||||||||||||||||||||||||
| 1437 | update_persistent_indexes(saved_persistent_indexes); | - | ||||||||||||||||||||||||
| 1438 | saved_persistent_indexes.clear(); | - | ||||||||||||||||||||||||
| 1439 | - | |||||||||||||||||||||||||
| 1440 | if (dynamic_sortfilter && update_source_sort_column()) { | - | ||||||||||||||||||||||||
| 1441 | qDeleteAll(source_index_mapping); | - | ||||||||||||||||||||||||
| 1442 | source_index_mapping.clear(); | - | ||||||||||||||||||||||||
| 1443 | } | - | ||||||||||||||||||||||||
| 1444 | - | |||||||||||||||||||||||||
| 1445 | QList<QPersistentModelIndex> parents; | - | ||||||||||||||||||||||||
| 1446 | parents << q->mapFromSource(sourceParent); | - | ||||||||||||||||||||||||
| 1447 | if (sourceParent != destParent) | - | ||||||||||||||||||||||||
| 1448 | parents << q->mapFromSource(destParent); | - | ||||||||||||||||||||||||
| 1449 | q->layoutChanged(parents); | - | ||||||||||||||||||||||||
| 1450 | } | - | ||||||||||||||||||||||||
| 1451 | QSortFilterProxyModel::QSortFilterProxyModel(QObject *parent) | - | ||||||||||||||||||||||||
| 1452 | : QAbstractProxyModel(*new QSortFilterProxyModelPrivate, parent) | - | ||||||||||||||||||||||||
| 1453 | { | - | ||||||||||||||||||||||||
| 1454 | QSortFilterProxyModelPrivate * const d = d_func(); | - | ||||||||||||||||||||||||
| 1455 | d->proxy_sort_column = d->source_sort_column = -1; | - | ||||||||||||||||||||||||
| 1456 | d->sort_order = Qt::AscendingOrder; | - | ||||||||||||||||||||||||
| 1457 | d->sort_casesensitivity = Qt::CaseSensitive; | - | ||||||||||||||||||||||||
| 1458 | d->sort_role = Qt::DisplayRole; | - | ||||||||||||||||||||||||
| 1459 | d->sort_localeaware = false; | - | ||||||||||||||||||||||||
| 1460 | d->filter_column = 0; | - | ||||||||||||||||||||||||
| 1461 | d->filter_role = Qt::DisplayRole; | - | ||||||||||||||||||||||||
| 1462 | d->dynamic_sortfilter = true; | - | ||||||||||||||||||||||||
| 1463 | connect(this, qFlagLocation("2""modelReset()" "\0" __FILE__ ":" "1735""1741"), this, qFlagLocation("1""_q_clearMapping()" "\0" __FILE__ ":" "1735""1741")); | - | ||||||||||||||||||||||||
| 1464 | } | - | ||||||||||||||||||||||||
| 1465 | - | |||||||||||||||||||||||||
| 1466 | - | |||||||||||||||||||||||||
| 1467 | - | |||||||||||||||||||||||||
| 1468 | - | |||||||||||||||||||||||||
| 1469 | QSortFilterProxyModel::~QSortFilterProxyModel() | - | ||||||||||||||||||||||||
| 1470 | { | - | ||||||||||||||||||||||||
| 1471 | QSortFilterProxyModelPrivate * const d = d_func(); | - | ||||||||||||||||||||||||
| 1472 | qDeleteAll(d->source_index_mapping); | - | ||||||||||||||||||||||||
| 1473 | d->source_index_mapping.clear(); | - | ||||||||||||||||||||||||
| 1474 | } | - | ||||||||||||||||||||||||
| 1475 | - | |||||||||||||||||||||||||
| 1476 | - | |||||||||||||||||||||||||
| 1477 | - | |||||||||||||||||||||||||
| 1478 | - | |||||||||||||||||||||||||
| 1479 | void QSortFilterProxyModel::setSourceModel(QAbstractItemModel *sourceModel) | - | ||||||||||||||||||||||||
| 1480 | { | - | ||||||||||||||||||||||||
| 1481 | QSortFilterProxyModelPrivate * const d = d_func(); | - | ||||||||||||||||||||||||
| 1482 | - | |||||||||||||||||||||||||
| 1483 | beginResetModel(); | - | ||||||||||||||||||||||||
| 1484 | - | |||||||||||||||||||||||||
| 1485 | disconnect(d->model, qFlagLocation("2""dataChanged(QModelIndex,QModelIndex,QVector<int>)" "\0" __FILE__ ":" "1757""1763"), | - | ||||||||||||||||||||||||
| 1486 | this, qFlagLocation("1""_q_sourceDataChanged(QModelIndex,QModelIndex,QVector<int>)" "\0" __FILE__ ":" "1758""1764")); | - | ||||||||||||||||||||||||
| 1487 | - | |||||||||||||||||||||||||
| 1488 | disconnect(d->model, qFlagLocation("2""headerDataChanged(Qt::Orientation,int,int)" "\0" __FILE__ ":" "1760""1766"), | - | ||||||||||||||||||||||||
| 1489 | this, qFlagLocation("1""_q_sourceHeaderDataChanged(Qt::Orientation,int,int)" "\0" __FILE__ ":" "1761""1767")); | - | ||||||||||||||||||||||||
| 1490 | - | |||||||||||||||||||||||||
| 1491 | disconnect(d->model, qFlagLocation("2""rowsAboutToBeInserted(QModelIndex,int,int)" "\0" __FILE__ ":" "1763""1769"), | - | ||||||||||||||||||||||||
| 1492 | this, qFlagLocation("1""_q_sourceRowsAboutToBeInserted(QModelIndex,int,int)" "\0" __FILE__ ":" "1764""1770")); | - | ||||||||||||||||||||||||
| 1493 | - | |||||||||||||||||||||||||
| 1494 | disconnect(d->model, qFlagLocation("2""rowsInserted(QModelIndex,int,int)" "\0" __FILE__ ":" "1766""1772"), | - | ||||||||||||||||||||||||
| 1495 | this, qFlagLocation("1""_q_sourceRowsInserted(QModelIndex,int,int)" "\0" __FILE__ ":" "1767""1773")); | - | ||||||||||||||||||||||||
| 1496 | - | |||||||||||||||||||||||||
| 1497 | disconnect(d->model, qFlagLocation("2""columnsAboutToBeInserted(QModelIndex,int,int)" "\0" __FILE__ ":" "1769""1775"), | - | ||||||||||||||||||||||||
| 1498 | this, qFlagLocation("1""_q_sourceColumnsAboutToBeInserted(QModelIndex,int,int)" "\0" __FILE__ ":" "1770""1776")); | - | ||||||||||||||||||||||||
| 1499 | - | |||||||||||||||||||||||||
| 1500 | disconnect(d->model, qFlagLocation("2""columnsInserted(QModelIndex,int,int)" "\0" __FILE__ ":" "1772""1778"), | - | ||||||||||||||||||||||||
| 1501 | this, qFlagLocation("1""_q_sourceColumnsInserted(QModelIndex,int,int)" "\0" __FILE__ ":" "1773""1779")); | - | ||||||||||||||||||||||||
| 1502 | - | |||||||||||||||||||||||||
| 1503 | disconnect(d->model, qFlagLocation("2""rowsAboutToBeRemoved(QModelIndex,int,int)" "\0" __FILE__ ":" "1775""1781"), | - | ||||||||||||||||||||||||
| 1504 | this, qFlagLocation("1""_q_sourceRowsAboutToBeRemoved(QModelIndex,int,int)" "\0" __FILE__ ":" "1776""1782")); | - | ||||||||||||||||||||||||
| 1505 | - | |||||||||||||||||||||||||
| 1506 | disconnect(d->model, qFlagLocation("2""rowsRemoved(QModelIndex,int,int)" "\0" __FILE__ ":" "1778""1784"), | - | ||||||||||||||||||||||||
| 1507 | this, qFlagLocation("1""_q_sourceRowsRemoved(QModelIndex,int,int)" "\0" __FILE__ ":" "1779""1785")); | - | ||||||||||||||||||||||||
| 1508 | - | |||||||||||||||||||||||||
| 1509 | disconnect(d->model, qFlagLocation("2""columnsAboutToBeRemoved(QModelIndex,int,int)" "\0" __FILE__ ":" "1781""1787"), | - | ||||||||||||||||||||||||
| 1510 | this, qFlagLocation("1""_q_sourceColumnsAboutToBeRemoved(QModelIndex,int,int)" "\0" __FILE__ ":" "1782""1788")); | - | ||||||||||||||||||||||||
| 1511 | - | |||||||||||||||||||||||||
| 1512 | disconnect(d->model, qFlagLocation("2""columnsRemoved(QModelIndex,int,int)" "\0" __FILE__ ":" "1784""1790"), | - | ||||||||||||||||||||||||
| 1513 | this, qFlagLocation("1""_q_sourceColumnsRemoved(QModelIndex,int,int)" "\0" __FILE__ ":" "1785""1791")); | - | ||||||||||||||||||||||||
| 1514 | - | |||||||||||||||||||||||||
| 1515 | disconnect(d->model, qFlagLocation("2""rowsAboutToBeMoved(QModelIndex,int,int,QModelIndex,int)" "\0" __FILE__ ":" "1787""1793"), | - | ||||||||||||||||||||||||
| 1516 | this, qFlagLocation("1""_q_sourceRowsAboutToBeMoved(QModelIndex,int,int,QModelIndex,int)" "\0" __FILE__ ":" "1788""1794")); | - | ||||||||||||||||||||||||
| 1517 | - | |||||||||||||||||||||||||
| 1518 | disconnect(d->model, qFlagLocation("2""rowsMoved(QModelIndex,int,int,QModelIndex,int)" "\0" __FILE__ ":" "1790""1796"), | - | ||||||||||||||||||||||||
| 1519 | this, qFlagLocation("1""_q_sourceRowsMoved(QModelIndex,int,int,QModelIndex,int)" "\0" __FILE__ ":" "1791""1797")); | - | ||||||||||||||||||||||||
| 1520 | - | |||||||||||||||||||||||||
| 1521 | disconnect(d->model, qFlagLocation("2""columnsAboutToBeMoved(QModelIndex,int,int,QModelIndex,int)" "\0" __FILE__ ":" "1793""1799"), | - | ||||||||||||||||||||||||
| 1522 | this, qFlagLocation("1""_q_sourceColumnsAboutToBeMoved(QModelIndex,int,int,QModelIndex,int)" "\0" __FILE__ ":" "1794""1800")); | - | ||||||||||||||||||||||||
| 1523 | - | |||||||||||||||||||||||||
| 1524 | disconnect(d->model, qFlagLocation("2""columnsMoved(QModelIndex,int,int,QModelIndex,int)" "\0" __FILE__ ":" "1796""1802"), | - | ||||||||||||||||||||||||
| 1525 | this, qFlagLocation("1""_q_sourceColumnsMoved(QModelIndex,int,int,QModelIndex,int)" "\0" __FILE__ ":" "1797""1803")); | - | ||||||||||||||||||||||||
| 1526 | - | |||||||||||||||||||||||||
| 1527 | disconnect(d->model, qFlagLocation("2""layoutAboutToBeChanged(QList<QPersistentModelIndex>,QAbstractItemModel::LayoutChangeHint)" "\0" __FILE__ ":" "1799""1805"), | - | ||||||||||||||||||||||||
| 1528 | this, qFlagLocation("1""_q_sourceLayoutAboutToBeChanged(QList<QPersistentModelIndex>,QAbstractItemModel::LayoutChangeHint)" "\0" __FILE__ ":" "1800""1806")); | - | ||||||||||||||||||||||||
| 1529 | - | |||||||||||||||||||||||||
| 1530 | disconnect(d->model, qFlagLocation("2""layoutChanged(QList<QPersistentModelIndex>,QAbstractItemModel::LayoutChangeHint)" "\0" __FILE__ ":" "1802""1808"), | - | ||||||||||||||||||||||||
| 1531 | this, qFlagLocation("1""_q_sourceLayoutChanged(QList<QPersistentModelIndex>,QAbstractItemModel::LayoutChangeHint)" "\0" __FILE__ ":" "1803""1809")); | - | ||||||||||||||||||||||||
| 1532 | - | |||||||||||||||||||||||||
| 1533 | disconnect(d->model, qFlagLocation("2""modelAboutToBeReset()" "\0" __FILE__ ":" "1805""1811"), this, qFlagLocation("1""_q_sourceAboutToBeReset()" "\0" __FILE__ ":" "1805""1811")); | - | ||||||||||||||||||||||||
| 1534 | disconnect(d->model, qFlagLocation("2""modelReset()" "\0" __FILE__ ":" "1806""1812"), this, qFlagLocation("1""_q_sourceReset()" "\0" __FILE__ ":" "1806""1812")); | - | ||||||||||||||||||||||||
| 1535 | - | |||||||||||||||||||||||||
| 1536 | QAbstractProxyModel::setSourceModel(sourceModel); | - | ||||||||||||||||||||||||
| 1537 | - | |||||||||||||||||||||||||
| 1538 | connect(d->model, qFlagLocation("2""dataChanged(QModelIndex,QModelIndex,QVector<int>)" "\0" __FILE__ ":" "1810""1816"), | - | ||||||||||||||||||||||||
| 1539 | this, qFlagLocation("1""_q_sourceDataChanged(QModelIndex,QModelIndex,QVector<int>)" "\0" __FILE__ ":" "1811""1817")); | - | ||||||||||||||||||||||||
| 1540 | - | |||||||||||||||||||||||||
| 1541 | connect(d->model, qFlagLocation("2""headerDataChanged(Qt::Orientation,int,int)" "\0" __FILE__ ":" "1813""1819"), | - | ||||||||||||||||||||||||
| 1542 | this, qFlagLocation("1""_q_sourceHeaderDataChanged(Qt::Orientation,int,int)" "\0" __FILE__ ":" "1814""1820")); | - | ||||||||||||||||||||||||
| 1543 | - | |||||||||||||||||||||||||
| 1544 | connect(d->model, qFlagLocation("2""rowsAboutToBeInserted(QModelIndex,int,int)" "\0" __FILE__ ":" "1816""1822"), | - | ||||||||||||||||||||||||
| 1545 | this, qFlagLocation("1""_q_sourceRowsAboutToBeInserted(QModelIndex,int,int)" "\0" __FILE__ ":" "1817""1823")); | - | ||||||||||||||||||||||||
| 1546 | - | |||||||||||||||||||||||||
| 1547 | connect(d->model, qFlagLocation("2""rowsInserted(QModelIndex,int,int)" "\0" __FILE__ ":" "1819""1825"), | - | ||||||||||||||||||||||||
| 1548 | this, qFlagLocation("1""_q_sourceRowsInserted(QModelIndex,int,int)" "\0" __FILE__ ":" "1820""1826")); | - | ||||||||||||||||||||||||
| 1549 | - | |||||||||||||||||||||||||
| 1550 | connect(d->model, qFlagLocation("2""columnsAboutToBeInserted(QModelIndex,int,int)" "\0" __FILE__ ":" "1822""1828"), | - | ||||||||||||||||||||||||
| 1551 | this, qFlagLocation("1""_q_sourceColumnsAboutToBeInserted(QModelIndex,int,int)" "\0" __FILE__ ":" "1823""1829")); | - | ||||||||||||||||||||||||
| 1552 | - | |||||||||||||||||||||||||
| 1553 | connect(d->model, qFlagLocation("2""columnsInserted(QModelIndex,int,int)" "\0" __FILE__ ":" "1825""1831"), | - | ||||||||||||||||||||||||
| 1554 | this, qFlagLocation("1""_q_sourceColumnsInserted(QModelIndex,int,int)" "\0" __FILE__ ":" "1826""1832")); | - | ||||||||||||||||||||||||
| 1555 | - | |||||||||||||||||||||||||
| 1556 | connect(d->model, qFlagLocation("2""rowsAboutToBeRemoved(QModelIndex,int,int)" "\0" __FILE__ ":" "1828""1834"), | - | ||||||||||||||||||||||||
| 1557 | this, qFlagLocation("1""_q_sourceRowsAboutToBeRemoved(QModelIndex,int,int)" "\0" __FILE__ ":" "1829""1835")); | - | ||||||||||||||||||||||||
| 1558 | - | |||||||||||||||||||||||||
| 1559 | connect(d->model, qFlagLocation("2""rowsRemoved(QModelIndex,int,int)" "\0" __FILE__ ":" "1831""1837"), | - | ||||||||||||||||||||||||
| 1560 | this, qFlagLocation("1""_q_sourceRowsRemoved(QModelIndex,int,int)" "\0" __FILE__ ":" "1832""1838")); | - | ||||||||||||||||||||||||
| 1561 | - | |||||||||||||||||||||||||
| 1562 | connect(d->model, qFlagLocation("2""columnsAboutToBeRemoved(QModelIndex,int,int)" "\0" __FILE__ ":" "1834""1840"), | - | ||||||||||||||||||||||||
| 1563 | this, qFlagLocation("1""_q_sourceColumnsAboutToBeRemoved(QModelIndex,int,int)" "\0" __FILE__ ":" "1835""1841")); | - | ||||||||||||||||||||||||
| 1564 | - | |||||||||||||||||||||||||
| 1565 | connect(d->model, qFlagLocation("2""columnsRemoved(QModelIndex,int,int)" "\0" __FILE__ ":" "1837""1843"), | - | ||||||||||||||||||||||||
| 1566 | this, qFlagLocation("1""_q_sourceColumnsRemoved(QModelIndex,int,int)" "\0" __FILE__ ":" "1838""1844")); | - | ||||||||||||||||||||||||
| 1567 | - | |||||||||||||||||||||||||
| 1568 | connect(d->model, qFlagLocation("2""rowsAboutToBeMoved(QModelIndex,int,int,QModelIndex,int)" "\0" __FILE__ ":" "1840""1846"), | - | ||||||||||||||||||||||||
| 1569 | this, qFlagLocation("1""_q_sourceRowsAboutToBeMoved(QModelIndex,int,int,QModelIndex,int)" "\0" __FILE__ ":" "1841""1847")); | - | ||||||||||||||||||||||||
| 1570 | - | |||||||||||||||||||||||||
| 1571 | connect(d->model, qFlagLocation("2""rowsMoved(QModelIndex,int,int,QModelIndex,int)" "\0" __FILE__ ":" "1843""1849"), | - | ||||||||||||||||||||||||
| 1572 | this, qFlagLocation("1""_q_sourceRowsMoved(QModelIndex,int,int,QModelIndex,int)" "\0" __FILE__ ":" "1844""1850")); | - | ||||||||||||||||||||||||
| 1573 | - | |||||||||||||||||||||||||
| 1574 | connect(d->model, qFlagLocation("2""columnsAboutToBeMoved(QModelIndex,int,int,QModelIndex,int)" "\0" __FILE__ ":" "1846""1852"), | - | ||||||||||||||||||||||||
| 1575 | this, qFlagLocation("1""_q_sourceColumnsAboutToBeMoved(QModelIndex,int,int,QModelIndex,int)" "\0" __FILE__ ":" "1847""1853")); | - | ||||||||||||||||||||||||
| 1576 | - | |||||||||||||||||||||||||
| 1577 | connect(d->model, qFlagLocation("2""columnsMoved(QModelIndex,int,int,QModelIndex,int)" "\0" __FILE__ ":" "1849""1855"), | - | ||||||||||||||||||||||||
| 1578 | this, qFlagLocation("1""_q_sourceColumnsMoved(QModelIndex,int,int,QModelIndex,int)" "\0" __FILE__ ":" "1850""1856")); | - | ||||||||||||||||||||||||
| 1579 | - | |||||||||||||||||||||||||
| 1580 | connect(d->model, qFlagLocation("2""layoutAboutToBeChanged(QList<QPersistentModelIndex>,QAbstractItemModel::LayoutChangeHint)" "\0" __FILE__ ":" "1852""1858"), | - | ||||||||||||||||||||||||
| 1581 | this, qFlagLocation("1""_q_sourceLayoutAboutToBeChanged(QList<QPersistentModelIndex>,QAbstractItemModel::LayoutChangeHint)" "\0" __FILE__ ":" "1853""1859")); | - | ||||||||||||||||||||||||
| 1582 | - | |||||||||||||||||||||||||
| 1583 | connect(d->model, qFlagLocation("2""layoutChanged(QList<QPersistentModelIndex>,QAbstractItemModel::LayoutChangeHint)" "\0" __FILE__ ":" "1855""1861"), | - | ||||||||||||||||||||||||
| 1584 | this, qFlagLocation("1""_q_sourceLayoutChanged(QList<QPersistentModelIndex>,QAbstractItemModel::LayoutChangeHint)" "\0" __FILE__ ":" "1856""1862")); | - | ||||||||||||||||||||||||
| 1585 | - | |||||||||||||||||||||||||
| 1586 | connect(d->model, qFlagLocation("2""modelAboutToBeReset()" "\0" __FILE__ ":" "1858""1864"), this, qFlagLocation("1""_q_sourceAboutToBeReset()" "\0" __FILE__ ":" "1858""1864")); | - | ||||||||||||||||||||||||
| 1587 | connect(d->model, qFlagLocation("2""modelReset()" "\0" __FILE__ ":" "1859""1865"), this, qFlagLocation("1""_q_sourceReset()" "\0" __FILE__ ":" "1859""1865")); | - | ||||||||||||||||||||||||
| 1588 | - | |||||||||||||||||||||||||
| 1589 | d->_q_clearMapping(); | - | ||||||||||||||||||||||||
| 1590 | endResetModel(); | - | ||||||||||||||||||||||||
| 1591 | if (d->update_source_sort_column() && d->dynamic_sortfilter) | - | ||||||||||||||||||||||||
| 1592 | d->sort(); | - | ||||||||||||||||||||||||
| 1593 | } | - | ||||||||||||||||||||||||
| 1594 | - | |||||||||||||||||||||||||
| 1595 | - | |||||||||||||||||||||||||
| 1596 | - | |||||||||||||||||||||||||
| 1597 | - | |||||||||||||||||||||||||
| 1598 | QModelIndex QSortFilterProxyModel::index(int row, int column, const QModelIndex &parent) const | - | ||||||||||||||||||||||||
| 1599 | { | - | ||||||||||||||||||||||||
| 1600 | const QSortFilterProxyModelPrivate * const d = d_func(); | - | ||||||||||||||||||||||||
| 1601 | if (row < 0 || column < 0) | - | ||||||||||||||||||||||||
| 1602 | return QModelIndex(); | - | ||||||||||||||||||||||||
| 1603 | - | |||||||||||||||||||||||||
| 1604 | QModelIndex source_parent = mapToSource(parent); | - | ||||||||||||||||||||||||
| 1605 | IndexMap::const_iterator it = d->create_mapping(source_parent); | - | ||||||||||||||||||||||||
| 1606 | if (it.value()->source_rows.count() <= row || it.value()->source_columns.count() <= column) | - | ||||||||||||||||||||||||
| 1607 | return QModelIndex(); | - | ||||||||||||||||||||||||
| 1608 | - | |||||||||||||||||||||||||
| 1609 | return d->create_index(row, column, it); | - | ||||||||||||||||||||||||
| 1610 | } | - | ||||||||||||||||||||||||
| 1611 | - | |||||||||||||||||||||||||
| 1612 | - | |||||||||||||||||||||||||
| 1613 | - | |||||||||||||||||||||||||
| 1614 | - | |||||||||||||||||||||||||
| 1615 | QModelIndex QSortFilterProxyModel::parent(const QModelIndex &child) const | - | ||||||||||||||||||||||||
| 1616 | { | - | ||||||||||||||||||||||||
| 1617 | const QSortFilterProxyModelPrivate * const d = d_func(); | - | ||||||||||||||||||||||||
| 1618 | if (!d->indexValid(child)) | - | ||||||||||||||||||||||||
| 1619 | return QModelIndex(); | - | ||||||||||||||||||||||||
| 1620 | IndexMap::const_iterator it = d->index_to_iterator(child); | - | ||||||||||||||||||||||||
| 1621 | ((!(it != d->source_index_mapping.constEnd())) ? qt_assert("it != d->source_index_mapping.constEnd()",__FILE__,18931899) : qt_noop()); | - | ||||||||||||||||||||||||
| 1622 | QModelIndex source_parent = it.key(); | - | ||||||||||||||||||||||||
| 1623 | QModelIndex proxy_parent = mapFromSource(source_parent); | - | ||||||||||||||||||||||||
| 1624 | return proxy_parent; | - | ||||||||||||||||||||||||
| 1625 | } | - | ||||||||||||||||||||||||
| 1626 | - | |||||||||||||||||||||||||
| 1627 | - | |||||||||||||||||||||||||
| 1628 | - | |||||||||||||||||||||||||
| 1629 | - | |||||||||||||||||||||||||
| 1630 | QModelIndex QSortFilterProxyModel::sibling(int row, int column, const QModelIndex &idx) const | - | ||||||||||||||||||||||||
| 1631 | { | - | ||||||||||||||||||||||||
| 1632 | const QSortFilterProxyModelPrivate * const d = d_func(); | - | ||||||||||||||||||||||||
| 1633 | if (!d->indexValid(idx)) | - | ||||||||||||||||||||||||
| 1634 | return QModelIndex(); | - | ||||||||||||||||||||||||
| 1635 | - | |||||||||||||||||||||||||
| 1636 | const IndexMap::const_iterator it = d->index_to_iterator(idx); | - | ||||||||||||||||||||||||
| 1637 | if (it.value()->source_rows.count() <= row || it.value()->source_columns.count() <= column) | - | ||||||||||||||||||||||||
| 1638 | return QModelIndex(); | - | ||||||||||||||||||||||||
| 1639 | - | |||||||||||||||||||||||||
| 1640 | return d->create_index(row, column, it); | - | ||||||||||||||||||||||||
| 1641 | } | - | ||||||||||||||||||||||||
| 1642 | - | |||||||||||||||||||||||||
| 1643 | - | |||||||||||||||||||||||||
| 1644 | - | |||||||||||||||||||||||||
| 1645 | - | |||||||||||||||||||||||||
| 1646 | int QSortFilterProxyModel::rowCount(const QModelIndex &parent) const | - | ||||||||||||||||||||||||
| 1647 | { | - | ||||||||||||||||||||||||
| 1648 | const QSortFilterProxyModelPrivate * const d = d_func(); | - | ||||||||||||||||||||||||
| 1649 | QModelIndex source_parent = mapToSource(parent); | - | ||||||||||||||||||||||||
| 1650 | if (parent.isValid() && !source_parent.isValid()) | - | ||||||||||||||||||||||||
| 1651 | return 0; | - | ||||||||||||||||||||||||
| 1652 | IndexMap::const_iterator it = d->create_mapping(source_parent); | - | ||||||||||||||||||||||||
| 1653 | return it.value()->source_rows.count(); | - | ||||||||||||||||||||||||
| 1654 | } | - | ||||||||||||||||||||||||
| 1655 | - | |||||||||||||||||||||||||
| 1656 | - | |||||||||||||||||||||||||
| 1657 | - | |||||||||||||||||||||||||
| 1658 | - | |||||||||||||||||||||||||
| 1659 | int QSortFilterProxyModel::columnCount(const QModelIndex &parent) const | - | ||||||||||||||||||||||||
| 1660 | { | - | ||||||||||||||||||||||||
| 1661 | const QSortFilterProxyModelPrivate * const d = d_func(); | - | ||||||||||||||||||||||||
| 1662 | QModelIndex source_parent = mapToSource(parent); | - | ||||||||||||||||||||||||
| 1663 | if (parent.isValid() && !source_parent.isValid()) | - | ||||||||||||||||||||||||
| 1664 | return 0; | - | ||||||||||||||||||||||||
| 1665 | IndexMap::const_iterator it = d->create_mapping(source_parent); | - | ||||||||||||||||||||||||
| 1666 | return it.value()->source_columns.count(); | - | ||||||||||||||||||||||||
| 1667 | } | - | ||||||||||||||||||||||||
| 1668 | - | |||||||||||||||||||||||||
| 1669 | - | |||||||||||||||||||||||||
| 1670 | - | |||||||||||||||||||||||||
| 1671 | - | |||||||||||||||||||||||||
| 1672 | bool QSortFilterProxyModel::hasChildren(const QModelIndex &parent) const | - | ||||||||||||||||||||||||
| 1673 | { | - | ||||||||||||||||||||||||
| 1674 | const QSortFilterProxyModelPrivate * const d = d_func(); | - | ||||||||||||||||||||||||
| 1675 | QModelIndex source_parent = mapToSource(parent); | - | ||||||||||||||||||||||||
| 1676 | if (parent.isValid() && !source_parent.isValid()) | - | ||||||||||||||||||||||||
| 1677 | return false; | - | ||||||||||||||||||||||||
| 1678 | if (!d->model->hasChildren(source_parent)) | - | ||||||||||||||||||||||||
| 1679 | return false; | - | ||||||||||||||||||||||||
| 1680 | - | |||||||||||||||||||||||||
| 1681 | if (d->model->canFetchMore(source_parent)) | - | ||||||||||||||||||||||||
| 1682 | return true; | - | ||||||||||||||||||||||||
| 1683 | - | |||||||||||||||||||||||||
| 1684 | QSortFilterProxyModelPrivate::Mapping *m = d->create_mapping(source_parent).value(); | - | ||||||||||||||||||||||||
| 1685 | return m->source_rows.count() != 0 && m->source_columns.count() != 0; | - | ||||||||||||||||||||||||
| 1686 | } | - | ||||||||||||||||||||||||
| 1687 | - | |||||||||||||||||||||||||
| 1688 | - | |||||||||||||||||||||||||
| 1689 | - | |||||||||||||||||||||||||
| 1690 | - | |||||||||||||||||||||||||
| 1691 | QVariant QSortFilterProxyModel::data(const QModelIndex &index, int role) const | - | ||||||||||||||||||||||||
| 1692 | { | - | ||||||||||||||||||||||||
| 1693 | const QSortFilterProxyModelPrivate * const d = d_func(); | - | ||||||||||||||||||||||||
| 1694 | QModelIndex source_index = mapToSource(index); | - | ||||||||||||||||||||||||
| 1695 | if (index.isValid() && !source_index.isValid()) | - | ||||||||||||||||||||||||
| 1696 | return QVariant(); | - | ||||||||||||||||||||||||
| 1697 | return d->model->data(source_index, role); | - | ||||||||||||||||||||||||
| 1698 | } | - | ||||||||||||||||||||||||
| 1699 | - | |||||||||||||||||||||||||
| 1700 | - | |||||||||||||||||||||||||
| 1701 | - | |||||||||||||||||||||||||
| 1702 | - | |||||||||||||||||||||||||
| 1703 | bool QSortFilterProxyModel::setData(const QModelIndex &index, const QVariant &value, int role) | - | ||||||||||||||||||||||||
| 1704 | { | - | ||||||||||||||||||||||||
| 1705 | QSortFilterProxyModelPrivate * const d = d_func(); | - | ||||||||||||||||||||||||
| 1706 | QModelIndex source_index = mapToSource(index); | - | ||||||||||||||||||||||||
| 1707 | if (index.isValid() && !source_index.isValid()) | - | ||||||||||||||||||||||||
| 1708 | return false; | - | ||||||||||||||||||||||||
| 1709 | return d->model->setData(source_index, value, role); | - | ||||||||||||||||||||||||
| 1710 | } | - | ||||||||||||||||||||||||
| 1711 | - | |||||||||||||||||||||||||
| 1712 | - | |||||||||||||||||||||||||
| 1713 | - | |||||||||||||||||||||||||
| 1714 | - | |||||||||||||||||||||||||
| 1715 | QVariant QSortFilterProxyModel::headerData(int section, Qt::Orientation orientation, int role) const | - | ||||||||||||||||||||||||
| 1716 | { | - | ||||||||||||||||||||||||
| 1717 | const QSortFilterProxyModelPrivate * const d = d_func(); | - | ||||||||||||||||||||||||
| 1718 | IndexMap::const_iterator it = d->create_mapping(QModelIndex()); | - | ||||||||||||||||||||||||
| 1719 | if (it.value()->source_rows.count() * it.value()->source_columns.count() > 0) | - | ||||||||||||||||||||||||
| 1720 | return QAbstractProxyModel::headerData(section, orientation, role); | - | ||||||||||||||||||||||||
| 1721 | int source_section; | - | ||||||||||||||||||||||||
| 1722 | if (orientation == Qt::Vertical) { | - | ||||||||||||||||||||||||
| 1723 | if (section < 0 || section >= it.value()->source_rows.count()) | - | ||||||||||||||||||||||||
| 1724 | return QVariant(); | - | ||||||||||||||||||||||||
| 1725 | source_section = it.value()->source_rows.at(section); | - | ||||||||||||||||||||||||
| 1726 | } else { | - | ||||||||||||||||||||||||
| 1727 | if (section < 0 || section >= it.value()->source_columns.count()) | - | ||||||||||||||||||||||||
| 1728 | return QVariant(); | - | ||||||||||||||||||||||||
| 1729 | source_section = it.value()->source_columns.at(section); | - | ||||||||||||||||||||||||
| 1730 | } | - | ||||||||||||||||||||||||
| 1731 | return d->model->headerData(source_section, orientation, role); | - | ||||||||||||||||||||||||
| 1732 | } | - | ||||||||||||||||||||||||
| 1733 | - | |||||||||||||||||||||||||
| 1734 | - | |||||||||||||||||||||||||
| 1735 | - | |||||||||||||||||||||||||
| 1736 | - | |||||||||||||||||||||||||
| 1737 | bool QSortFilterProxyModel::setHeaderData(int section, Qt::Orientation orientation, | - | ||||||||||||||||||||||||
| 1738 | const QVariant &value, int role) | - | ||||||||||||||||||||||||
| 1739 | { | - | ||||||||||||||||||||||||
| 1740 | QSortFilterProxyModelPrivate * const d = d_func(); | - | ||||||||||||||||||||||||
| 1741 | IndexMap::const_iterator it = d->create_mapping(QModelIndex()); | - | ||||||||||||||||||||||||
| 1742 | if (it.value()->source_rows.count() * it.value()->source_columns.count() > 0) | - | ||||||||||||||||||||||||
| 1743 | return QAbstractProxyModel::setHeaderData(section, orientation, value, role); | - | ||||||||||||||||||||||||
| 1744 | int source_section; | - | ||||||||||||||||||||||||
| 1745 | if (orientation == Qt::Vertical) { | - | ||||||||||||||||||||||||
| 1746 | if (section < 0 || section >= it.value()->source_rows.count()) | - | ||||||||||||||||||||||||
| 1747 | return false; | - | ||||||||||||||||||||||||
| 1748 | source_section = it.value()->source_rows.at(section); | - | ||||||||||||||||||||||||
| 1749 | } else { | - | ||||||||||||||||||||||||
| 1750 | if (section < 0 || section >= it.value()->source_columns.count()) | - | ||||||||||||||||||||||||
| 1751 | return false; | - | ||||||||||||||||||||||||
| 1752 | source_section = it.value()->source_columns.at(section); | - | ||||||||||||||||||||||||
| 1753 | } | - | ||||||||||||||||||||||||
| 1754 | return d->model->setHeaderData(source_section, orientation, value, role); | - | ||||||||||||||||||||||||
| 1755 | } | - | ||||||||||||||||||||||||
| 1756 | - | |||||||||||||||||||||||||
| 1757 | - | |||||||||||||||||||||||||
| 1758 | - | |||||||||||||||||||||||||
| 1759 | - | |||||||||||||||||||||||||
| 1760 | QMimeData *QSortFilterProxyModel::mimeData(const QModelIndexList &indexes) const | - | ||||||||||||||||||||||||
| 1761 | { | - | ||||||||||||||||||||||||
| 1762 | const QSortFilterProxyModelPrivate * const d = d_func(); | - | ||||||||||||||||||||||||
| 1763 | QModelIndexList source_indexes; | - | ||||||||||||||||||||||||
| 1764 | const int numIndexes = indexes.count(); | - | ||||||||||||||||||||||||
| 1765 | source_indexes.reserve(numIndexes); | - | ||||||||||||||||||||||||
| 1766 | for (int i = 0; i < numIndexes; ++i) | - | ||||||||||||||||||||||||
| 1767 | source_indexes << mapToSource(indexes.at(i)); | - | ||||||||||||||||||||||||
| 1768 | return d->model->mimeData(source_indexes); | - | ||||||||||||||||||||||||
| 1769 | } | - | ||||||||||||||||||||||||
| 1770 | - | |||||||||||||||||||||||||
| 1771 | - | |||||||||||||||||||||||||
| 1772 | - | |||||||||||||||||||||||||
| 1773 | - | |||||||||||||||||||||||||
| 1774 | QStringList QSortFilterProxyModel::mimeTypes() const | - | ||||||||||||||||||||||||
| 1775 | { | - | ||||||||||||||||||||||||
| 1776 | const QSortFilterProxyModelPrivate * const d = d_func(); | - | ||||||||||||||||||||||||
| 1777 | return d->model->mimeTypes(); | - | ||||||||||||||||||||||||
| 1778 | } | - | ||||||||||||||||||||||||
| 1779 | - | |||||||||||||||||||||||||
| 1780 | - | |||||||||||||||||||||||||
| 1781 | - | |||||||||||||||||||||||||
| 1782 | - | |||||||||||||||||||||||||
| 1783 | Qt::DropActions QSortFilterProxyModel::supportedDropActions() const | - | ||||||||||||||||||||||||
| 1784 | { | - | ||||||||||||||||||||||||
| 1785 | const QSortFilterProxyModelPrivate * const d = d_func(); | - | ||||||||||||||||||||||||
| 1786 | return d->model->supportedDropActions(); | - | ||||||||||||||||||||||||
| 1787 | } | - | ||||||||||||||||||||||||
| 1788 | - | |||||||||||||||||||||||||
| 1789 | - | |||||||||||||||||||||||||
| 1790 | - | |||||||||||||||||||||||||
| 1791 | - | |||||||||||||||||||||||||
| 1792 | - | |||||||||||||||||||||||||
| 1793 | bool QSortFilterProxyModel::dropMimeData(const QMimeData *data, Qt::DropAction action, | - | ||||||||||||||||||||||||
| 1794 | int row, int column, const QModelIndex &parent) | - | ||||||||||||||||||||||||
| 1795 | { | - | ||||||||||||||||||||||||
| 1796 | return QAbstractProxyModel::dropMimeData(data, action, row, column, parent); | - | ||||||||||||||||||||||||
| 1797 | } | - | ||||||||||||||||||||||||
| 1798 | - | |||||||||||||||||||||||||
| 1799 | - | |||||||||||||||||||||||||
| 1800 | - | |||||||||||||||||||||||||
| 1801 | - | |||||||||||||||||||||||||
| 1802 | bool QSortFilterProxyModel::insertRows(int row, int count, const QModelIndex &parent) | - | ||||||||||||||||||||||||
| 1803 | { | - | ||||||||||||||||||||||||
| 1804 | QSortFilterProxyModelPrivate * const d = d_func(); | - | ||||||||||||||||||||||||
| 1805 | if (row < 0 || count <= 0) | - | ||||||||||||||||||||||||
| 1806 | return false; | - | ||||||||||||||||||||||||
| 1807 | QModelIndex source_parent = mapToSource(parent); | - | ||||||||||||||||||||||||
| 1808 | if (parent.isValid() && !source_parent.isValid()) | - | ||||||||||||||||||||||||
| 1809 | return false; | - | ||||||||||||||||||||||||
| 1810 | QSortFilterProxyModelPrivate::Mapping *m = d->create_mapping(source_parent).value(); | - | ||||||||||||||||||||||||
| 1811 | if (row > m->source_rows.count()) | - | ||||||||||||||||||||||||
| 1812 | return false; | - | ||||||||||||||||||||||||
| 1813 | int source_row = (row >= m->source_rows.count() | - | ||||||||||||||||||||||||
| 1814 | ? m->source_rows.count() | - | ||||||||||||||||||||||||
| 1815 | : m->source_rows.at(row)); | - | ||||||||||||||||||||||||
| 1816 | return d->model->insertRows(source_row, count, source_parent); | - | ||||||||||||||||||||||||
| 1817 | } | - | ||||||||||||||||||||||||
| 1818 | - | |||||||||||||||||||||||||
| 1819 | - | |||||||||||||||||||||||||
| 1820 | - | |||||||||||||||||||||||||
| 1821 | - | |||||||||||||||||||||||||
| 1822 | bool QSortFilterProxyModel::insertColumns(int column, int count, const QModelIndex &parent) | - | ||||||||||||||||||||||||
| 1823 | { | - | ||||||||||||||||||||||||
| 1824 | QSortFilterProxyModelPrivate * const d = d_func(); | - | ||||||||||||||||||||||||
| 1825 | if (column < 0|| count <= 0) | - | ||||||||||||||||||||||||
| 1826 | return false; | - | ||||||||||||||||||||||||
| 1827 | QModelIndex source_parent = mapToSource(parent); | - | ||||||||||||||||||||||||
| 1828 | if (parent.isValid() && !source_parent.isValid()) | - | ||||||||||||||||||||||||
| 1829 | return false; | - | ||||||||||||||||||||||||
| 1830 | QSortFilterProxyModelPrivate::Mapping *m = d->create_mapping(source_parent).value(); | - | ||||||||||||||||||||||||
| 1831 | if (column > m->source_columns.count()) | - | ||||||||||||||||||||||||
| 1832 | return false; | - | ||||||||||||||||||||||||
| 1833 | int source_column = (column >= m->source_columns.count() | - | ||||||||||||||||||||||||
| 1834 | ? m->source_columns.count() | - | ||||||||||||||||||||||||
| 1835 | : m->source_columns.at(column)); | - | ||||||||||||||||||||||||
| 1836 | return d->model->insertColumns(source_column, count, source_parent); | - | ||||||||||||||||||||||||
| 1837 | } | - | ||||||||||||||||||||||||
| 1838 | - | |||||||||||||||||||||||||
| 1839 | - | |||||||||||||||||||||||||
| 1840 | - | |||||||||||||||||||||||||
| 1841 | - | |||||||||||||||||||||||||
| 1842 | bool QSortFilterProxyModel::removeRows(int row, int count, const QModelIndex &parent) | - | ||||||||||||||||||||||||
| 1843 | { | - | ||||||||||||||||||||||||
| 1844 | QSortFilterProxyModelPrivate * const d = d_func(); | - | ||||||||||||||||||||||||
| 1845 | if (row < 0 || count <= 0) | - | ||||||||||||||||||||||||
| 1846 | return false; | - | ||||||||||||||||||||||||
| 1847 | QModelIndex source_parent = mapToSource(parent); | - | ||||||||||||||||||||||||
| 1848 | if (parent.isValid() && !source_parent.isValid()) | - | ||||||||||||||||||||||||
| 1849 | return false; | - | ||||||||||||||||||||||||
| 1850 | QSortFilterProxyModelPrivate::Mapping *m = d->create_mapping(source_parent).value(); | - | ||||||||||||||||||||||||
| 1851 | if (row + count > m->source_rows.count()) | - | ||||||||||||||||||||||||
| 1852 | return false; | - | ||||||||||||||||||||||||
| 1853 | if ((count == 1) | - | ||||||||||||||||||||||||
| 1854 | || ((d->source_sort_column < 0) && (m->proxy_rows.count() == m->source_rows.count()))) { | - | ||||||||||||||||||||||||
| 1855 | int source_row = m->source_rows.at(row); | - | ||||||||||||||||||||||||
| 1856 | return d->model->removeRows(source_row, count, source_parent); | - | ||||||||||||||||||||||||
| 1857 | } | - | ||||||||||||||||||||||||
| 1858 | - | |||||||||||||||||||||||||
| 1859 | - | |||||||||||||||||||||||||
| 1860 | QVector<int> rows; | - | ||||||||||||||||||||||||
| 1861 | rows.reserve(count); | - | ||||||||||||||||||||||||
| 1862 | for (int i = row; i < row + count; ++i) | - | ||||||||||||||||||||||||
| 1863 | rows.append(m->source_rows.at(i)); | - | ||||||||||||||||||||||||
| 1864 | std::sort(rows.begin(), rows.end()); | - | ||||||||||||||||||||||||
| 1865 | - | |||||||||||||||||||||||||
| 1866 | int pos = rows.count() - 1; | - | ||||||||||||||||||||||||
| 1867 | bool ok = true; | - | ||||||||||||||||||||||||
| 1868 | while (pos >= 0) { | - | ||||||||||||||||||||||||
| 1869 | const int source_end = rows.at(pos--); | - | ||||||||||||||||||||||||
| 1870 | int source_start = source_end; | - | ||||||||||||||||||||||||
| 1871 | while ((pos >= 0) && (rows.at(pos) == (source_start - 1))) { | - | ||||||||||||||||||||||||
| 1872 | --source_start; | - | ||||||||||||||||||||||||
| 1873 | --pos; | - | ||||||||||||||||||||||||
| 1874 | } | - | ||||||||||||||||||||||||
| 1875 | ok = ok && d->model->removeRows(source_start, source_end - source_start + 1, | - | ||||||||||||||||||||||||
| 1876 | source_parent); | - | ||||||||||||||||||||||||
| 1877 | } | - | ||||||||||||||||||||||||
| 1878 | return ok; | - | ||||||||||||||||||||||||
| 1879 | } | - | ||||||||||||||||||||||||
| 1880 | - | |||||||||||||||||||||||||
| 1881 | - | |||||||||||||||||||||||||
| 1882 | - | |||||||||||||||||||||||||
| 1883 | - | |||||||||||||||||||||||||
| 1884 | bool QSortFilterProxyModel::removeColumns(int column, int count, const QModelIndex &parent) | - | ||||||||||||||||||||||||
| 1885 | { | - | ||||||||||||||||||||||||
| 1886 | QSortFilterProxyModelPrivate * const d = d_func(); | - | ||||||||||||||||||||||||
| 1887 | if (column < 0 || count <= 0) | - | ||||||||||||||||||||||||
| 1888 | return false; | - | ||||||||||||||||||||||||
| 1889 | QModelIndex source_parent = mapToSource(parent); | - | ||||||||||||||||||||||||
| 1890 | if (parent.isValid() && !source_parent.isValid()) | - | ||||||||||||||||||||||||
| 1891 | return false; | - | ||||||||||||||||||||||||
| 1892 | QSortFilterProxyModelPrivate::Mapping *m = d->create_mapping(source_parent).value(); | - | ||||||||||||||||||||||||
| 1893 | if (column + count > m->source_columns.count()) | - | ||||||||||||||||||||||||
| 1894 | return false; | - | ||||||||||||||||||||||||
| 1895 | if ((count == 1) || (m->proxy_columns.count() == m->source_columns.count())) { | - | ||||||||||||||||||||||||
| 1896 | int source_column = m->source_columns.at(column); | - | ||||||||||||||||||||||||
| 1897 | return d->model->removeColumns(source_column, count, source_parent); | - | ||||||||||||||||||||||||
| 1898 | } | - | ||||||||||||||||||||||||
| 1899 | - | |||||||||||||||||||||||||
| 1900 | QVector<int> columns; | - | ||||||||||||||||||||||||
| 1901 | columns.reserve(count); | - | ||||||||||||||||||||||||
| 1902 | for (int i = column; i < column + count; ++i) | - | ||||||||||||||||||||||||
| 1903 | columns.append(m->source_columns.at(i)); | - | ||||||||||||||||||||||||
| 1904 | - | |||||||||||||||||||||||||
| 1905 | int pos = columns.count() - 1; | - | ||||||||||||||||||||||||
| 1906 | bool ok = true; | - | ||||||||||||||||||||||||
| 1907 | while (pos >= 0) { | - | ||||||||||||||||||||||||
| 1908 | const int source_end = columns.at(pos--); | - | ||||||||||||||||||||||||
| 1909 | int source_start = source_end; | - | ||||||||||||||||||||||||
| 1910 | while ((pos >= 0) && (columns.at(pos) == (source_start - 1))) { | - | ||||||||||||||||||||||||
| 1911 | --source_start; | - | ||||||||||||||||||||||||
| 1912 | --pos; | - | ||||||||||||||||||||||||
| 1913 | } | - | ||||||||||||||||||||||||
| 1914 | ok = ok && d->model->removeColumns(source_start, source_end - source_start + 1, | - | ||||||||||||||||||||||||
| 1915 | source_parent); | - | ||||||||||||||||||||||||
| 1916 | } | - | ||||||||||||||||||||||||
| 1917 | return ok; | - | ||||||||||||||||||||||||
| 1918 | } | - | ||||||||||||||||||||||||
| 1919 | - | |||||||||||||||||||||||||
| 1920 | - | |||||||||||||||||||||||||
| 1921 | - | |||||||||||||||||||||||||
| 1922 | - | |||||||||||||||||||||||||
| 1923 | void QSortFilterProxyModel::fetchMore(const QModelIndex &parent) | - | ||||||||||||||||||||||||
| 1924 | { | - | ||||||||||||||||||||||||
| 1925 | QSortFilterProxyModelPrivate * const d = d_func(); | - | ||||||||||||||||||||||||
| 1926 | QModelIndex source_parent; | - | ||||||||||||||||||||||||
| 1927 | if (d->indexValid(parent)) | - | ||||||||||||||||||||||||
| 1928 | source_parent = mapToSource(parent); | - | ||||||||||||||||||||||||
| 1929 | d->model->fetchMore(source_parent); | - | ||||||||||||||||||||||||
| 1930 | } | - | ||||||||||||||||||||||||
| 1931 | - | |||||||||||||||||||||||||
| 1932 | - | |||||||||||||||||||||||||
| 1933 | - | |||||||||||||||||||||||||
| 1934 | - | |||||||||||||||||||||||||
| 1935 | bool QSortFilterProxyModel::canFetchMore(const QModelIndex &parent) const | - | ||||||||||||||||||||||||
| 1936 | { | - | ||||||||||||||||||||||||
| 1937 | const QSortFilterProxyModelPrivate * const d = d_func(); | - | ||||||||||||||||||||||||
| 1938 | QModelIndex source_parent; | - | ||||||||||||||||||||||||
| 1939 | if (d->indexValid(parent)) | - | ||||||||||||||||||||||||
| 1940 | source_parent = mapToSource(parent); | - | ||||||||||||||||||||||||
| 1941 | return d->model->canFetchMore(source_parent); | - | ||||||||||||||||||||||||
| 1942 | } | - | ||||||||||||||||||||||||
| 1943 | - | |||||||||||||||||||||||||
| 1944 | - | |||||||||||||||||||||||||
| 1945 | - | |||||||||||||||||||||||||
| 1946 | - | |||||||||||||||||||||||||
| 1947 | Qt::ItemFlags QSortFilterProxyModel::flags(const QModelIndex &index) const | - | ||||||||||||||||||||||||
| 1948 | { | - | ||||||||||||||||||||||||
| 1949 | const QSortFilterProxyModelPrivate * const d = d_func(); | - | ||||||||||||||||||||||||
| 1950 | QModelIndex source_index; | - | ||||||||||||||||||||||||
| 1951 | if (d->indexValid(index)) | - | ||||||||||||||||||||||||
| 1952 | source_index = mapToSource(index); | - | ||||||||||||||||||||||||
| 1953 | return d->model->flags(source_index); | - | ||||||||||||||||||||||||
| 1954 | } | - | ||||||||||||||||||||||||
| 1955 | - | |||||||||||||||||||||||||
| 1956 | - | |||||||||||||||||||||||||
| 1957 | - | |||||||||||||||||||||||||
| 1958 | - | |||||||||||||||||||||||||
| 1959 | QModelIndex QSortFilterProxyModel::buddy(const QModelIndex &index) const | - | ||||||||||||||||||||||||
| 1960 | { | - | ||||||||||||||||||||||||
| 1961 | const QSortFilterProxyModelPrivate * const d = d_func(); | - | ||||||||||||||||||||||||
| 1962 | if (!d->indexValid(index)) | - | ||||||||||||||||||||||||
| 1963 | return QModelIndex(); | - | ||||||||||||||||||||||||
| 1964 | QModelIndex source_index = mapToSource(index); | - | ||||||||||||||||||||||||
| 1965 | QModelIndex source_buddy = d->model->buddy(source_index); | - | ||||||||||||||||||||||||
| 1966 | if (source_index == source_buddy) | - | ||||||||||||||||||||||||
| 1967 | return index; | - | ||||||||||||||||||||||||
| 1968 | return mapFromSource(source_buddy); | - | ||||||||||||||||||||||||
| 1969 | } | - | ||||||||||||||||||||||||
| 1970 | - | |||||||||||||||||||||||||
| 1971 | - | |||||||||||||||||||||||||
| 1972 | - | |||||||||||||||||||||||||
| 1973 | - | |||||||||||||||||||||||||
| 1974 | QModelIndexList QSortFilterProxyModel::match(const QModelIndex &start, int role, | - | ||||||||||||||||||||||||
| 1975 | const QVariant &value, int hits, | - | ||||||||||||||||||||||||
| 1976 | Qt::MatchFlags flags) const | - | ||||||||||||||||||||||||
| 1977 | { | - | ||||||||||||||||||||||||
| 1978 | return QAbstractProxyModel::match(start, role, value, hits, flags); | - | ||||||||||||||||||||||||
| 1979 | } | - | ||||||||||||||||||||||||
| 1980 | - | |||||||||||||||||||||||||
| 1981 | - | |||||||||||||||||||||||||
| 1982 | - | |||||||||||||||||||||||||
| 1983 | - | |||||||||||||||||||||||||
| 1984 | QSize QSortFilterProxyModel::span(const QModelIndex &index) const | - | ||||||||||||||||||||||||
| 1985 | { | - | ||||||||||||||||||||||||
| 1986 | const QSortFilterProxyModelPrivate * const d = d_func(); | - | ||||||||||||||||||||||||
| 1987 | QModelIndex source_index = mapToSource(index); | - | ||||||||||||||||||||||||
| 1988 | if (index.isValid() && !source_index.isValid()) | - | ||||||||||||||||||||||||
| 1989 | return QSize(); | - | ||||||||||||||||||||||||
| 1990 | return d->model->span(source_index); | - | ||||||||||||||||||||||||
| 1991 | } | - | ||||||||||||||||||||||||
| 1992 | - | |||||||||||||||||||||||||
| 1993 | - | |||||||||||||||||||||||||
| 1994 | - | |||||||||||||||||||||||||
| 1995 | - | |||||||||||||||||||||||||
| 1996 | void QSortFilterProxyModel::sort(int column, Qt::SortOrder order) | - | ||||||||||||||||||||||||
| 1997 | { | - | ||||||||||||||||||||||||
| 1998 | QSortFilterProxyModelPrivate * const d = d_func(); | - | ||||||||||||||||||||||||
| 1999 | if (d->dynamic_sortfilter && d->proxy_sort_column == column && d->sort_order == order) | - | ||||||||||||||||||||||||
| 2000 | return; | - | ||||||||||||||||||||||||
| 2001 | d->sort_order = order; | - | ||||||||||||||||||||||||
| 2002 | d->proxy_sort_column = column; | - | ||||||||||||||||||||||||
| 2003 | d->update_source_sort_column(); | - | ||||||||||||||||||||||||
| 2004 | d->sort(); | - | ||||||||||||||||||||||||
| 2005 | } | - | ||||||||||||||||||||||||
| 2006 | - | |||||||||||||||||||||||||
| 2007 | - | |||||||||||||||||||||||||
| 2008 | - | |||||||||||||||||||||||||
| 2009 | - | |||||||||||||||||||||||||
| 2010 | - | |||||||||||||||||||||||||
| 2011 | - | |||||||||||||||||||||||||
| 2012 | - | |||||||||||||||||||||||||
| 2013 | int QSortFilterProxyModel::sortColumn() const | - | ||||||||||||||||||||||||
| 2014 | { | - | ||||||||||||||||||||||||
| 2015 | const QSortFilterProxyModelPrivate * const d = d_func(); | - | ||||||||||||||||||||||||
| 2016 | return d->proxy_sort_column; | - | ||||||||||||||||||||||||
| 2017 | } | - | ||||||||||||||||||||||||
| 2018 | - | |||||||||||||||||||||||||
| 2019 | - | |||||||||||||||||||||||||
| 2020 | - | |||||||||||||||||||||||||
| 2021 | - | |||||||||||||||||||||||||
| 2022 | - | |||||||||||||||||||||||||
| 2023 | - | |||||||||||||||||||||||||
| 2024 | - | |||||||||||||||||||||||||
| 2025 | Qt::SortOrder QSortFilterProxyModel::sortOrder() const | - | ||||||||||||||||||||||||
| 2026 | { | - | ||||||||||||||||||||||||
| 2027 | const QSortFilterProxyModelPrivate * const d = d_func(); | - | ||||||||||||||||||||||||
| 2028 | return d->sort_order; | - | ||||||||||||||||||||||||
| 2029 | } | - | ||||||||||||||||||||||||
| 2030 | QRegExp QSortFilterProxyModel::filterRegExp() const | - | ||||||||||||||||||||||||
| 2031 | { | - | ||||||||||||||||||||||||
| 2032 | const QSortFilterProxyModelPrivate * const d = d_func(); | - | ||||||||||||||||||||||||
| 2033 | return d->filter_regexp; | - | ||||||||||||||||||||||||
| 2034 | } | - | ||||||||||||||||||||||||
| 2035 | - | |||||||||||||||||||||||||
| 2036 | void QSortFilterProxyModel::setFilterRegExp(const QRegExp ®Exp) | - | ||||||||||||||||||||||||
| 2037 | { | - | ||||||||||||||||||||||||
| 2038 | QSortFilterProxyModelPrivate * const d = d_func(); | - | ||||||||||||||||||||||||
| 2039 | d->filter_about_to_be_changed(); | - | ||||||||||||||||||||||||
| 2040 | d->filter_regexp = regExp; | - | ||||||||||||||||||||||||
| 2041 | d->filter_changed(); | - | ||||||||||||||||||||||||
| 2042 | } | - | ||||||||||||||||||||||||
| 2043 | int QSortFilterProxyModel::filterKeyColumn() const | - | ||||||||||||||||||||||||
| 2044 | { | - | ||||||||||||||||||||||||
| 2045 | const QSortFilterProxyModelPrivate * const d = d_func(); | - | ||||||||||||||||||||||||
| 2046 | return d->filter_column; | - | ||||||||||||||||||||||||
| 2047 | } | - | ||||||||||||||||||||||||
| 2048 | - | |||||||||||||||||||||||||
| 2049 | void QSortFilterProxyModel::setFilterKeyColumn(int column) | - | ||||||||||||||||||||||||
| 2050 | { | - | ||||||||||||||||||||||||
| 2051 | QSortFilterProxyModelPrivate * const d = d_func(); | - | ||||||||||||||||||||||||
| 2052 | d->filter_about_to_be_changed(); | - | ||||||||||||||||||||||||
| 2053 | d->filter_column = column; | - | ||||||||||||||||||||||||
| 2054 | d->filter_changed(); | - | ||||||||||||||||||||||||
| 2055 | } | - | ||||||||||||||||||||||||
| 2056 | Qt::CaseSensitivity QSortFilterProxyModel::filterCaseSensitivity() const | - | ||||||||||||||||||||||||
| 2057 | { | - | ||||||||||||||||||||||||
| 2058 | const QSortFilterProxyModelPrivate * const d = d_func(); | - | ||||||||||||||||||||||||
| 2059 | return d->filter_regexp.caseSensitivity(); | - | ||||||||||||||||||||||||
| 2060 | } | - | ||||||||||||||||||||||||
| 2061 | - | |||||||||||||||||||||||||
| 2062 | void QSortFilterProxyModel::setFilterCaseSensitivity(Qt::CaseSensitivity cs) | - | ||||||||||||||||||||||||
| 2063 | { | - | ||||||||||||||||||||||||
| 2064 | QSortFilterProxyModelPrivate * const d = d_func(); | - | ||||||||||||||||||||||||
| 2065 | if (cs == d->filter_regexp.caseSensitivity()) | - | ||||||||||||||||||||||||
| 2066 | return; | - | ||||||||||||||||||||||||
| 2067 | d->filter_about_to_be_changed(); | - | ||||||||||||||||||||||||
| 2068 | d->filter_regexp.setCaseSensitivity(cs); | - | ||||||||||||||||||||||||
| 2069 | d->filter_changed(); | - | ||||||||||||||||||||||||
| 2070 | } | - | ||||||||||||||||||||||||
| 2071 | Qt::CaseSensitivity QSortFilterProxyModel::sortCaseSensitivity() const | - | ||||||||||||||||||||||||
| 2072 | { | - | ||||||||||||||||||||||||
| 2073 | const QSortFilterProxyModelPrivate * const d = d_func(); | - | ||||||||||||||||||||||||
| 2074 | return d->sort_casesensitivity; | - | ||||||||||||||||||||||||
| 2075 | } | - | ||||||||||||||||||||||||
| 2076 | - | |||||||||||||||||||||||||
| 2077 | void QSortFilterProxyModel::setSortCaseSensitivity(Qt::CaseSensitivity cs) | - | ||||||||||||||||||||||||
| 2078 | { | - | ||||||||||||||||||||||||
| 2079 | QSortFilterProxyModelPrivate * const d = d_func(); | - | ||||||||||||||||||||||||
| 2080 | if (d->sort_casesensitivity == cs) | - | ||||||||||||||||||||||||
| 2081 | return; | - | ||||||||||||||||||||||||
| 2082 | - | |||||||||||||||||||||||||
| 2083 | d->sort_casesensitivity = cs; | - | ||||||||||||||||||||||||
| 2084 | d->sort(); | - | ||||||||||||||||||||||||
| 2085 | } | - | ||||||||||||||||||||||||
| 2086 | bool QSortFilterProxyModel::isSortLocaleAware() const | - | ||||||||||||||||||||||||
| 2087 | { | - | ||||||||||||||||||||||||
| 2088 | const QSortFilterProxyModelPrivate * const d = d_func(); | - | ||||||||||||||||||||||||
| 2089 | return d->sort_localeaware; | - | ||||||||||||||||||||||||
| 2090 | } | - | ||||||||||||||||||||||||
| 2091 | - | |||||||||||||||||||||||||
| 2092 | void QSortFilterProxyModel::setSortLocaleAware(bool on) | - | ||||||||||||||||||||||||
| 2093 | { | - | ||||||||||||||||||||||||
| 2094 | QSortFilterProxyModelPrivate * const d = d_func(); | - | ||||||||||||||||||||||||
| 2095 | if (d->sort_localeaware == on) | - | ||||||||||||||||||||||||
| 2096 | return; | - | ||||||||||||||||||||||||
| 2097 | - | |||||||||||||||||||||||||
| 2098 | d->sort_localeaware = on; | - | ||||||||||||||||||||||||
| 2099 | d->sort(); | - | ||||||||||||||||||||||||
| 2100 | } | - | ||||||||||||||||||||||||
| 2101 | void QSortFilterProxyModel::setFilterRegExp(const QString &pattern) | - | ||||||||||||||||||||||||
| 2102 | { | - | ||||||||||||||||||||||||
| 2103 | QSortFilterProxyModelPrivate * const d = d_func(); | - | ||||||||||||||||||||||||
| 2104 | d->filter_about_to_be_changed(); | - | ||||||||||||||||||||||||
| 2105 | d->filter_regexp.setPatternSyntax(QRegExp::RegExp); | - | ||||||||||||||||||||||||
| 2106 | d->filter_regexp.setPattern(pattern); | - | ||||||||||||||||||||||||
| 2107 | d->filter_changed(); | - | ||||||||||||||||||||||||
| 2108 | } | - | ||||||||||||||||||||||||
| 2109 | - | |||||||||||||||||||||||||
| 2110 | - | |||||||||||||||||||||||||
| 2111 | - | |||||||||||||||||||||||||
| 2112 | - | |||||||||||||||||||||||||
| 2113 | - | |||||||||||||||||||||||||
| 2114 | - | |||||||||||||||||||||||||
| 2115 | - | |||||||||||||||||||||||||
| 2116 | void QSortFilterProxyModel::setFilterWildcard(const QString &pattern) | - | ||||||||||||||||||||||||
| 2117 | { | - | ||||||||||||||||||||||||
| 2118 | QSortFilterProxyModelPrivate * const d = d_func(); | - | ||||||||||||||||||||||||
| 2119 | d->filter_about_to_be_changed(); | - | ||||||||||||||||||||||||
| 2120 | d->filter_regexp.setPatternSyntax(QRegExp::Wildcard); | - | ||||||||||||||||||||||||
| 2121 | d->filter_regexp.setPattern(pattern); | - | ||||||||||||||||||||||||
| 2122 | d->filter_changed(); | - | ||||||||||||||||||||||||
| 2123 | } | - | ||||||||||||||||||||||||
| 2124 | - | |||||||||||||||||||||||||
| 2125 | - | |||||||||||||||||||||||||
| 2126 | - | |||||||||||||||||||||||||
| 2127 | - | |||||||||||||||||||||||||
| 2128 | - | |||||||||||||||||||||||||
| 2129 | - | |||||||||||||||||||||||||
| 2130 | - | |||||||||||||||||||||||||
| 2131 | void QSortFilterProxyModel::setFilterFixedString(const QString &pattern) | - | ||||||||||||||||||||||||
| 2132 | { | - | ||||||||||||||||||||||||
| 2133 | QSortFilterProxyModelPrivate * const d = d_func(); | - | ||||||||||||||||||||||||
| 2134 | d->filter_about_to_be_changed(); | - | ||||||||||||||||||||||||
| 2135 | d->filter_regexp.setPatternSyntax(QRegExp::FixedString); | - | ||||||||||||||||||||||||
| 2136 | d->filter_regexp.setPattern(pattern); | - | ||||||||||||||||||||||||
| 2137 | d->filter_changed(); | - | ||||||||||||||||||||||||
| 2138 | } | - | ||||||||||||||||||||||||
| 2139 | bool QSortFilterProxyModel::dynamicSortFilter() const | - | ||||||||||||||||||||||||
| 2140 | { | - | ||||||||||||||||||||||||
| 2141 | const QSortFilterProxyModelPrivate * const d = d_func(); | - | ||||||||||||||||||||||||
| 2142 | return d->dynamic_sortfilter; | - | ||||||||||||||||||||||||
| 2143 | } | - | ||||||||||||||||||||||||
| 2144 | - | |||||||||||||||||||||||||
| 2145 | void QSortFilterProxyModel::setDynamicSortFilter(bool enable) | - | ||||||||||||||||||||||||
| 2146 | { | - | ||||||||||||||||||||||||
| 2147 | QSortFilterProxyModelPrivate * const d = d_func(); | - | ||||||||||||||||||||||||
| 2148 | d->dynamic_sortfilter = enable; | - | ||||||||||||||||||||||||
| 2149 | if (enable) | - | ||||||||||||||||||||||||
| 2150 | d->sort(); | - | ||||||||||||||||||||||||
| 2151 | } | - | ||||||||||||||||||||||||
| 2152 | int QSortFilterProxyModel::sortRole() const | - | ||||||||||||||||||||||||
| 2153 | { | - | ||||||||||||||||||||||||
| 2154 | const QSortFilterProxyModelPrivate * const d = d_func(); | - | ||||||||||||||||||||||||
| 2155 | return d->sort_role; | - | ||||||||||||||||||||||||
| 2156 | } | - | ||||||||||||||||||||||||
| 2157 | - | |||||||||||||||||||||||||
| 2158 | void QSortFilterProxyModel::setSortRole(int role) | - | ||||||||||||||||||||||||
| 2159 | { | - | ||||||||||||||||||||||||
| 2160 | QSortFilterProxyModelPrivate * const d = d_func(); | - | ||||||||||||||||||||||||
| 2161 | if (d->sort_role == role) | - | ||||||||||||||||||||||||
| 2162 | return; | - | ||||||||||||||||||||||||
| 2163 | d->sort_role = role; | - | ||||||||||||||||||||||||
| 2164 | d->sort(); | - | ||||||||||||||||||||||||
| 2165 | } | - | ||||||||||||||||||||||||
| 2166 | int QSortFilterProxyModel::filterRole() const | - | ||||||||||||||||||||||||
| 2167 | { | - | ||||||||||||||||||||||||
| 2168 | const QSortFilterProxyModelPrivate * const d = d_func(); | - | ||||||||||||||||||||||||
| 2169 | return d->filter_role; | - | ||||||||||||||||||||||||
| 2170 | } | - | ||||||||||||||||||||||||
| 2171 | - | |||||||||||||||||||||||||
| 2172 | void QSortFilterProxyModel::setFilterRole(int role) | - | ||||||||||||||||||||||||
| 2173 | { | - | ||||||||||||||||||||||||
| 2174 | QSortFilterProxyModelPrivate * const d = d_func(); | - | ||||||||||||||||||||||||
| 2175 | if (d->filter_role == role) | - | ||||||||||||||||||||||||
| 2176 | return; | - | ||||||||||||||||||||||||
| 2177 | d->filter_about_to_be_changed(); | - | ||||||||||||||||||||||||
| 2178 | d->filter_role = role; | - | ||||||||||||||||||||||||
| 2179 | d->filter_changed(); | - | ||||||||||||||||||||||||
| 2180 | } | - | ||||||||||||||||||||||||
| 2181 | - | |||||||||||||||||||||||||
| 2182 | - | |||||||||||||||||||||||||
| 2183 | - | |||||||||||||||||||||||||
| 2184 | - | |||||||||||||||||||||||||
| 2185 | - | |||||||||||||||||||||||||
| 2186 | - | |||||||||||||||||||||||||
| 2187 | void QSortFilterProxyModel::clear() | - | ||||||||||||||||||||||||
| 2188 | { | - | ||||||||||||||||||||||||
| 2189 | QSortFilterProxyModelPrivate * const d = d_func(); | - | ||||||||||||||||||||||||
| 2190 | layoutAboutToBeChanged(); | - | ||||||||||||||||||||||||
| 2191 | d->_q_clearMapping(); | - | ||||||||||||||||||||||||
| 2192 | layoutChanged(); | - | ||||||||||||||||||||||||
| 2193 | } | - | ||||||||||||||||||||||||
| 2194 | void QSortFilterProxyModel::invalidate() | - | ||||||||||||||||||||||||
| 2195 | { | - | ||||||||||||||||||||||||
| 2196 | QSortFilterProxyModelPrivate * const d = d_func(); | - | ||||||||||||||||||||||||
| 2197 | layoutAboutToBeChanged(); | - | ||||||||||||||||||||||||
| 2198 | d->_q_clearMapping(); | - | ||||||||||||||||||||||||
| 2199 | layoutChanged(); | - | ||||||||||||||||||||||||
| 2200 | } | - | ||||||||||||||||||||||||
| 2201 | - | |||||||||||||||||||||||||
| 2202 | - | |||||||||||||||||||||||||
| 2203 | - | |||||||||||||||||||||||||
| 2204 | - | |||||||||||||||||||||||||
| 2205 | - | |||||||||||||||||||||||||
| 2206 | - | |||||||||||||||||||||||||
| 2207 | void QSortFilterProxyModel::filterChanged() | - | ||||||||||||||||||||||||
| 2208 | { | - | ||||||||||||||||||||||||
| 2209 | QSortFilterProxyModelPrivate * const d = d_func(); | - | ||||||||||||||||||||||||
| 2210 | d->filter_changed(); | - | ||||||||||||||||||||||||
| 2211 | } | - | ||||||||||||||||||||||||
| 2212 | void QSortFilterProxyModel::invalidateFilter() | - | ||||||||||||||||||||||||
| 2213 | { | - | ||||||||||||||||||||||||
| 2214 | QSortFilterProxyModelPrivate * const d = d_func(); | - | ||||||||||||||||||||||||
| 2215 | d->filter_changed(); | - | ||||||||||||||||||||||||
| 2216 | } | - | ||||||||||||||||||||||||
| 2217 | bool QSortFilterProxyModel::lessThan(const QModelIndex &source_left, const QModelIndex &source_right) const | - | ||||||||||||||||||||||||
| 2218 | { | - | ||||||||||||||||||||||||
| 2219 | const QSortFilterProxyModelPrivate * const d = d_func(); | - | ||||||||||||||||||||||||
| 2220 | QVariant l = (source_left.model() ? source_left.model()->data(source_left, d->sort_role) : QVariant()); | - | ||||||||||||||||||||||||
| 2221 | QVariant r = (source_right.model() ? source_right.model()->data(source_right, d->sort_role) : QVariant()); | - | ||||||||||||||||||||||||
| 2222 | - | |||||||||||||||||||||||||
| 2223 | if (l.userType() == QVariant::Invalid) | - | ||||||||||||||||||||||||
| 2224 | return false; | - | ||||||||||||||||||||||||
| 2225 | if (r.userType() == QVariant::Invalid) | - | ||||||||||||||||||||||||
| 2226 | return true; | - | ||||||||||||||||||||||||
| 2227 | switch (l.userType()) { | - | ||||||||||||||||||||||||
| 2228 | case QVariant::Int: | - | ||||||||||||||||||||||||
| 2229 | return l.toInt() < r.toInt(); | - | ||||||||||||||||||||||||
| 2230 | case QVariant::UInt: | - | ||||||||||||||||||||||||
| 2231 | return l.toUInt() < r.toUInt(); | - | ||||||||||||||||||||||||
| 2232 | case QVariant::LongLong: | - | ||||||||||||||||||||||||
| 2233 | return l.toLongLong() < r.toLongLong(); | - | ||||||||||||||||||||||||
| 2234 | case QVariant::ULongLong: | - | ||||||||||||||||||||||||
| 2235 | return l.toULongLong() < r.toULongLong(); | - | ||||||||||||||||||||||||
| 2236 | case QMetaType::Float: | - | ||||||||||||||||||||||||
| 2237 | return l.toFloat() < r.toFloat(); | - | ||||||||||||||||||||||||
| 2238 | case QVariant::Double: | - | ||||||||||||||||||||||||
| 2239 | return l.toDouble() < r.toDouble(); | - | ||||||||||||||||||||||||
| 2240 | case QVariant::Char: | - | ||||||||||||||||||||||||
| 2241 | return l.toChar() < r.toChar(); | - | ||||||||||||||||||||||||
| 2242 | case QVariant::Date: | - | ||||||||||||||||||||||||
| 2243 | return l.toDate() < r.toDate(); | - | ||||||||||||||||||||||||
| 2244 | case QVariant::Time: | - | ||||||||||||||||||||||||
| 2245 | return l.toTime() < r.toTime(); | - | ||||||||||||||||||||||||
| 2246 | case QVariant::DateTime: | - | ||||||||||||||||||||||||
| 2247 | return l.toDateTime() < r.toDateTime(); | - | ||||||||||||||||||||||||
| 2248 | case QVariant::String: | - | ||||||||||||||||||||||||
| 2249 | default: | - | ||||||||||||||||||||||||
| 2250 | if (d->sort_localeaware) | - | ||||||||||||||||||||||||
| 2251 | return l.toString().localeAwareCompare(r.toString()) < 0; | - | ||||||||||||||||||||||||
| 2252 | else | - | ||||||||||||||||||||||||
| 2253 | return l.toString().compare(r.toString(), d->sort_casesensitivity) < 0; | - | ||||||||||||||||||||||||
| 2254 | } | - | ||||||||||||||||||||||||
| 2255 | return dead code: false;return false;dead code: return false; | - | ||||||||||||||||||||||||
| 2256 | } | - | ||||||||||||||||||||||||
| 2257 | bool QSortFilterProxyModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const | - | ||||||||||||||||||||||||
| 2258 | { | - | ||||||||||||||||||||||||
| 2259 | const QSortFilterProxyModelPrivate * const d = d_func(); | - | ||||||||||||||||||||||||
| 2260 | if (d->filter_regexp.isEmpty()) | - | ||||||||||||||||||||||||
| 2261 | return true; | - | ||||||||||||||||||||||||
| 2262 | if (d->filter_column == -1) { | - | ||||||||||||||||||||||||
| 2263 | int column_count = d->model->columnCount(source_parent); | - | ||||||||||||||||||||||||
| 2264 | for (int column = 0; column < column_count; ++column) { | - | ||||||||||||||||||||||||
| 2265 | QModelIndex source_index = d->model->index(source_row, column, source_parent); | - | ||||||||||||||||||||||||
| 2266 | QString key = d->model->data(source_index, d->filter_role).toString(); | - | ||||||||||||||||||||||||
| 2267 | if (key.contains(d->filter_regexp)) | - | ||||||||||||||||||||||||
| 2268 | return true; | - | ||||||||||||||||||||||||
| 2269 | } | - | ||||||||||||||||||||||||
| 2270 | return false; | - | ||||||||||||||||||||||||
| 2271 | } | - | ||||||||||||||||||||||||
| 2272 | QModelIndex source_index = d->model->index(source_row, d->filter_column, source_parent); | - | ||||||||||||||||||||||||
| 2273 | if (!source_index.isValid()) | - | ||||||||||||||||||||||||
| 2274 | return true; | - | ||||||||||||||||||||||||
| 2275 | QString key = d->model->data(source_index, d->filter_role).toString(); | - | ||||||||||||||||||||||||
| 2276 | return key.contains(d->filter_regexp); | - | ||||||||||||||||||||||||
| 2277 | } | - | ||||||||||||||||||||||||
| 2278 | bool QSortFilterProxyModel::filterAcceptsColumn(int source_column, const QModelIndex &source_parent) const | - | ||||||||||||||||||||||||
| 2279 | { | - | ||||||||||||||||||||||||
| 2280 | (void)source_column;; | - | ||||||||||||||||||||||||
| 2281 | (void)source_parent;; | - | ||||||||||||||||||||||||
| 2282 | return true; | - | ||||||||||||||||||||||||
| 2283 | } | - | ||||||||||||||||||||||||
| 2284 | - | |||||||||||||||||||||||||
| 2285 | - | |||||||||||||||||||||||||
| 2286 | - | |||||||||||||||||||||||||
| 2287 | - | |||||||||||||||||||||||||
| 2288 | - | |||||||||||||||||||||||||
| 2289 | - | |||||||||||||||||||||||||
| 2290 | - | |||||||||||||||||||||||||
| 2291 | QModelIndex QSortFilterProxyModel::mapToSource(const QModelIndex &proxyIndex) const | - | ||||||||||||||||||||||||
| 2292 | { | - | ||||||||||||||||||||||||
| 2293 | const QSortFilterProxyModelPrivate * const d = d_func(); | - | ||||||||||||||||||||||||
| 2294 | return d->proxy_to_source(proxyIndex); | - | ||||||||||||||||||||||||
| 2295 | } | - | ||||||||||||||||||||||||
| 2296 | - | |||||||||||||||||||||||||
| 2297 | - | |||||||||||||||||||||||||
| 2298 | - | |||||||||||||||||||||||||
| 2299 | - | |||||||||||||||||||||||||
| 2300 | - | |||||||||||||||||||||||||
| 2301 | - | |||||||||||||||||||||||||
| 2302 | - | |||||||||||||||||||||||||
| 2303 | QModelIndex QSortFilterProxyModel::mapFromSource(const QModelIndex &sourceIndex) const | - | ||||||||||||||||||||||||
| 2304 | { | - | ||||||||||||||||||||||||
| 2305 | const QSortFilterProxyModelPrivate * const d = d_func(); | - | ||||||||||||||||||||||||
| 2306 | return d->source_to_proxy(sourceIndex); | - | ||||||||||||||||||||||||
| 2307 | } | - | ||||||||||||||||||||||||
| 2308 | - | |||||||||||||||||||||||||
| 2309 | - | |||||||||||||||||||||||||
| 2310 | - | |||||||||||||||||||||||||
| 2311 | - | |||||||||||||||||||||||||
| 2312 | QItemSelection QSortFilterProxyModel::mapSelectionToSource(const QItemSelection &proxySelection) const | - | ||||||||||||||||||||||||
| 2313 | { | - | ||||||||||||||||||||||||
| 2314 | return QAbstractProxyModel::mapSelectionToSource(proxySelection); | - | ||||||||||||||||||||||||
| 2315 | } | - | ||||||||||||||||||||||||
| 2316 | - | |||||||||||||||||||||||||
| 2317 | - | |||||||||||||||||||||||||
| 2318 | - | |||||||||||||||||||||||||
| 2319 | - | |||||||||||||||||||||||||
| 2320 | QItemSelection QSortFilterProxyModel::mapSelectionFromSource(const QItemSelection &sourceSelection) const | - | ||||||||||||||||||||||||
| 2321 | { | - | ||||||||||||||||||||||||
| 2322 | return QAbstractProxyModel::mapSelectionFromSource(sourceSelection); | - | ||||||||||||||||||||||||
| 2323 | } | - | ||||||||||||||||||||||||
| 2324 | - | |||||||||||||||||||||||||
| 2325 | - | |||||||||||||||||||||||||
| 2326 | - | |||||||||||||||||||||||||
| Switch to Source code | Preprocessed file |