Changeset 846 for trunk/src/gui/itemviews/qitemselectionmodel.cpp
- Timestamp:
- May 5, 2011, 5:36:53 AM (14 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
- Property svn:mergeinfo changed
/branches/vendor/nokia/qt/4.7.2 (added) merged: 845 /branches/vendor/nokia/qt/current merged: 844 /branches/vendor/nokia/qt/4.6.3 removed
- Property svn:mergeinfo changed
-
trunk/src/gui/itemviews/qitemselectionmodel.cpp
r651 r846 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation (qt-info@nokia.com) … … 293 293 294 294 /*! 295 Returns true if the selection range contains no selectable item 296 \since 4.7 297 */ 298 299 bool QItemSelectionRange::isEmpty() const 300 { 301 if (!isValid() || !model()) 302 return true; 303 304 for (int column = left(); column <= right(); ++column) { 305 for (int row = top(); row <= bottom(); ++row) { 306 QModelIndex index = model()->index(row, column, parent()); 307 Qt::ItemFlags flags = model()->flags(index); 308 if ((flags & Qt::ItemIsSelectable) && (flags & Qt::ItemIsEnabled)) 309 return false; 310 } 311 } 312 return true; 313 } 314 315 /*! 295 316 Returns the list of model index items stored in the selection. 296 317 */ … … 525 546 result->append(QItemSelectionRange(tl, br)); 526 547 right = other_right; 548 } 549 } 550 551 552 void QItemSelectionModelPrivate::initModel(QAbstractItemModel *model) 553 { 554 this->model = model; 555 if (model) { 556 Q_Q(QItemSelectionModel); 557 QObject::connect(model, SIGNAL(rowsAboutToBeRemoved(QModelIndex,int,int)), 558 q, SLOT(_q_rowsAboutToBeRemoved(QModelIndex,int,int))); 559 QObject::connect(model, SIGNAL(columnsAboutToBeRemoved(QModelIndex,int,int)), 560 q, SLOT(_q_columnsAboutToBeRemoved(QModelIndex,int,int))); 561 QObject::connect(model, SIGNAL(rowsAboutToBeInserted(QModelIndex,int,int)), 562 q, SLOT(_q_rowsAboutToBeInserted(QModelIndex,int,int))); 563 QObject::connect(model, SIGNAL(columnsAboutToBeInserted(QModelIndex,int,int)), 564 q, SLOT(_q_columnsAboutToBeInserted(QModelIndex,int,int))); 565 QObject::connect(model, SIGNAL(layoutAboutToBeChanged()), 566 q, SLOT(_q_layoutAboutToBeChanged())); 567 QObject::connect(model, SIGNAL(layoutChanged()), 568 q, SLOT(_q_layoutChanged())); 527 569 } 528 570 } … … 731 773 savedPersistentCurrentIndexes.clear(); 732 774 733 // optimi sation for when all indexes are selected775 // optimization for when all indexes are selected 734 776 // (only if there is lots of items (1000) because this is not entirely correct) 735 777 if (ranges.isEmpty() && currentSelection.count() == 1) { … … 794 836 QModelIndex nextTl = colSpans.at(i).topLeft(); 795 837 QModelIndex nextBr = colSpans.at(i).bottomRight(); 838 839 if (nextTl.parent() != tl.parent()) 840 break; // we can't merge selection ranges from different parents 841 796 842 if ((nextTl.column() == prevTl.column()) && (nextBr.column() == br.column()) 797 843 && (nextTl.row() == prevTl.row() + 1) && (nextBr.row() == br.row() + 1)) { … … 891 937 : QObject(*new QItemSelectionModelPrivate, model) 892 938 { 893 d_func()->model = model; 894 if (model) { 895 connect(model, SIGNAL(rowsAboutToBeRemoved(QModelIndex,int,int)), 896 this, SLOT(_q_rowsAboutToBeRemoved(QModelIndex,int,int))); 897 connect(model, SIGNAL(columnsAboutToBeRemoved(QModelIndex,int,int)), 898 this, SLOT(_q_columnsAboutToBeRemoved(QModelIndex,int,int))); 899 connect(model, SIGNAL(rowsAboutToBeInserted(QModelIndex,int,int)), 900 this, SLOT(_q_rowsAboutToBeInserted(QModelIndex,int,int))); 901 connect(model, SIGNAL(columnsAboutToBeInserted(QModelIndex,int,int)), 902 this, SLOT(_q_columnsAboutToBeInserted(QModelIndex,int,int))); 903 connect(model, SIGNAL(layoutAboutToBeChanged()), 904 this, SLOT(_q_layoutAboutToBeChanged())); 905 connect(model, SIGNAL(layoutChanged()), 906 this, SLOT(_q_layoutChanged())); 907 } 939 d_func()->initModel(model); 908 940 } 909 941 … … 914 946 : QObject(*new QItemSelectionModelPrivate, parent) 915 947 { 916 d_func()->model = model; 917 if (model) { 918 connect(model, SIGNAL(rowsAboutToBeRemoved(QModelIndex,int,int)), 919 this, SLOT(_q_rowsAboutToBeRemoved(QModelIndex,int,int))); 920 connect(model, SIGNAL(columnsAboutToBeRemoved(QModelIndex,int,int)), 921 this, SLOT(_q_columnsAboutToBeRemoved(QModelIndex,int,int))); 922 connect(model, SIGNAL(rowsAboutToBeInserted(QModelIndex,int,int)), 923 this, SLOT(_q_rowsAboutToBeInserted(QModelIndex,int,int))); 924 connect(model, SIGNAL(columnsAboutToBeInserted(QModelIndex,int,int)), 925 this, SLOT(_q_columnsAboutToBeInserted(QModelIndex,int,int))); 926 connect(model, SIGNAL(layoutAboutToBeChanged()), 927 this, SLOT(_q_layoutAboutToBeChanged())); 928 connect(model, SIGNAL(layoutChanged()), 929 this, SLOT(_q_layoutChanged())); 930 } 948 d_func()->initModel(model); 931 949 } 932 950 … … 937 955 : QObject(dd, model) 938 956 { 939 d_func()->model = model; 940 if (model) { 941 connect(model, SIGNAL(rowsAboutToBeRemoved(QModelIndex,int,int)), 942 this, SLOT(_q_rowsAboutToBeRemoved(QModelIndex,int,int))); 943 connect(model, SIGNAL(columnsAboutToBeRemoved(QModelIndex,int,int)), 944 this, SLOT(_q_columnsAboutToBeRemoved(QModelIndex,int,int))); 945 connect(model, SIGNAL(rowsAboutToBeInserted(QModelIndex,int,int)), 946 this, SLOT(_q_rowsAboutToBeInserted(QModelIndex,int,int))); 947 connect(model, SIGNAL(columnsAboutToBeInserted(QModelIndex,int,int)), 948 this, SLOT(_q_columnsAboutToBeInserted(QModelIndex,int,int))); 949 connect(model, SIGNAL(layoutAboutToBeChanged()), 950 this, SLOT(_q_layoutAboutToBeChanged())); 951 connect(model, SIGNAL(layoutChanged()), 952 this, SLOT(_q_layoutChanged())); 953 } 957 dd.initModel(model); 954 958 } 955 959 … … 959 963 QItemSelectionModel::~QItemSelectionModel() 960 964 { 961 Q_D(QItemSelectionModel);962 if (d->model) {963 disconnect(d->model, SIGNAL(rowsAboutToBeRemoved(QModelIndex,int,int)),964 this, SLOT(_q_rowsAboutToBeRemoved(QModelIndex,int,int)));965 disconnect(d->model, SIGNAL(columnsAboutToBeRemoved(QModelIndex,int,int)),966 this, SLOT(_q_columnsAboutToBeRemoved(QModelIndex,int,int)));967 disconnect(d->model, SIGNAL(rowsAboutToBeInserted(QModelIndex,int,int)),968 this, SLOT(_q_rowsAboutToBeInserted(QModelIndex,int,int)));969 disconnect(d->model, SIGNAL(columnsAboutToBeInserted(QModelIndex,int,int)),970 this, SLOT(_q_columnsAboutToBeInserted(QModelIndex,int,int)));971 disconnect(d->model, SIGNAL(layoutAboutToBeChanged()),972 this, SLOT(_q_layoutAboutToBeChanged()));973 disconnect(d->model, SIGNAL(layoutChanged()),974 this, SLOT(_q_layoutChanged()));975 }976 965 } 977 966 … … 1071 1060 // store old selection 1072 1061 QItemSelection sel = selection; 1062 // If d->ranges is non-empty when the source model is reset the persistent indexes 1063 // it contains will be invalid. We can't clear them in a modelReset slot because that might already 1064 // be too late if another model observer is connected to the same modelReset slot and is invoked first 1065 // it might call select() on this selection model before any such QItemSelectionModelPrivate::_q_modelReset() slot 1066 // is invoked, so it would not be cleared yet. We clear it invalid ranges in it here. 1067 QItemSelection::iterator it = d->ranges.begin(); 1068 while (it != d->ranges.end()) { 1069 if (!it->isValid()) 1070 it = d->ranges.erase(it); 1071 else 1072 ++it; 1073 } 1074 1073 1075 QItemSelection old = d->ranges; 1074 1076 old.merge(d->currentSelection, d->currentCommand);
Note:
See TracChangeset
for help on using the changeset viewer.