Changeset 846 for trunk/src/gui/itemviews
- Timestamp:
- May 5, 2011, 5:36:53 AM (14 years ago)
- Location:
- trunk
- Files:
-
- 67 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/qabstractitemdelegate.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) … … 292 292 293 293 /*! 294 Whenever an event occurs, this function is called with the \a event 295 \a model \a option and the \a index that corresponds to the item being edited. 294 When editing of an item starts, this function is called with the 295 \a event that triggered the editing, the \a model, the \a index of 296 the item, and the \a option used for rendering the item. 297 298 Mouse events are sent to editorEvent() even if they don't start 299 editing of the item. This can, for instance, be useful if you wish 300 to open a context menu when the right mouse button is pressed on 301 an item. 296 302 297 303 The base implementation returns false (indicating that it has not -
trunk/src/gui/itemviews/qabstractitemdelegate.h
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) -
trunk/src/gui/itemviews/qabstractitemview.cpp
r769 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) … … 105 105 currentIndexSet(false), 106 106 wrapItemText(false), 107 delayedPendingLayout(false) 108 { 107 delayedPendingLayout(true), 108 moveCursorUpdatedView(false) 109 { 110 keyboardInputTime.invalidate(); 109 111 } 110 112 … … 131 133 132 134 viewport->setBackgroundRole(QPalette::Base); 133 134 doDelayedItemsLayout();135 135 136 136 q->setAttribute(Qt::WA_InputMethodEnabled); … … 596 596 QAbstractItemView::~QAbstractItemView() 597 597 { 598 Q_D(QAbstractItemView); 599 // stop these timers here before ~QObject 600 d->delayedReset.stop(); 601 d->updateTimer.stop(); 602 d->delayedEditing.stop(); 603 d->delayedAutoScroll.stop(); 604 d->autoScrollTimer.stop(); 605 d->delayedLayout.stop(); 606 d->fetchMoreTimer.stop(); 598 607 } 599 608 … … 680 689 connect(d->model, SIGNAL(layoutChanged()), this, SLOT(_q_layoutChanged())); 681 690 } 682 setSelectionModel(new QItemSelectionModel(d->model, this)); 691 692 QItemSelectionModel *selection_model = new QItemSelectionModel(d->model, this); 693 connect(d->model, SIGNAL(destroyed()), selection_model, SLOT(deleteLater())); 694 setSelectionModel(selection_model); 695 683 696 reset(); // kill editors, set new root and do layout 684 697 } … … 824 837 825 838 \note If a delegate has been assigned to both a row and a column, the row 826 delegate (i.e., this delegate) will take pre sedence and manage the839 delegate (i.e., this delegate) will take precedence and manage the 827 840 intersecting cell index. 828 841 … … 882 895 883 896 \note If a delegate has been assigned to both a row and a column, the row 884 delegate will take pre sedence and manage the intersecting cell index.897 delegate will take precedence and manage the intersecting cell index. 885 898 886 899 \warning You should not share the same instance of a delegate between views. … … 1163 1176 \brief how the view scrolls its contents in the vertical direction 1164 1177 1165 This property control ls how the view scroll its contents vertically.1178 This property controls how the view scroll its contents vertically. 1166 1179 Scrolling can be done either per pixel or per item. 1167 1180 */ … … 1189 1202 \brief how the view scrolls its contents in the horizontal direction 1190 1203 1191 This property control ls how the view scroll its contents horizontally.1204 This property controls how the view scroll its contents horizontally. 1192 1205 Scrolling can be done either per pixel or per item. 1193 1206 */ … … 1272 1285 \brief the size of the area when auto scrolling is triggered 1273 1286 1274 This property control ls the size of the area at the edge of the viewport that1287 This property controls the size of the area at the edge of the viewport that 1275 1288 triggers autoscrolling. The default value is 16 pixels. 1276 1289 */ … … 1360 1373 Note that the model used needs to provide support for drag and drop operations. 1361 1374 1362 \sa setDragDropMode() {Using Drag and Drop with Item Views}1375 \sa setDragDropMode() {Using drag and drop with item views} 1363 1376 */ 1364 1377 … … 2094 2107 d->autoScroll = false; 2095 2108 QModelIndex index = moveCursor(MoveNext, Qt::NoModifier); // first visible index 2096 if (index.isValid() && d->isIndexEnabled(index) )2109 if (index.isValid() && d->isIndexEnabled(index) && event->reason() != Qt::MouseFocusReason) 2097 2110 selectionModel()->setCurrentIndex(index, QItemSelectionModel::NoUpdate); 2098 2111 d->autoScroll = autoScroll; … … 2214 2227 2215 2228 QPersistentModelIndex newCurrent; 2229 d->moveCursorUpdatedView = false; 2216 2230 switch (event->key()) { 2217 2231 case Qt::Key_Down: … … 2266 2280 d->selectionModel->setCurrentIndex(newCurrent, command); 2267 2281 d->pressedPosition = visualRect(newCurrent).center() + d->offset(); 2268 // We copy the same behaviour as for mousePressEvent(). 2269 QRect rect(d->pressedPosition - d->offset(), QSize(1, 1)); 2270 setSelection(rect, command); 2282 if (newCurrent.isValid()) { 2283 // We copy the same behaviour as for mousePressEvent(). 2284 QRect rect(d->pressedPosition - d->offset(), QSize(1, 1)); 2285 setSelection(rect, command); 2286 } 2271 2287 } 2288 event->accept(); 2272 2289 return; 2273 2290 } … … 2301 2318 case Qt::Key_Shift: 2302 2319 case Qt::Key_Control: 2320 case Qt::Key_Delete: 2321 case Qt::Key_Backspace: 2303 2322 event->ignore(); 2304 2323 break; … … 2365 2384 break; } 2366 2385 } 2386 if (d->moveCursorUpdatedView) 2387 event->accept(); 2367 2388 } 2368 2389 … … 2841 2862 QModelIndex start = currentIndex().isValid() ? currentIndex() 2842 2863 : d->model->index(0, 0, d->root); 2843 QTime now(QTime::currentTime());2844 2864 bool skipRow = false; 2845 if (search.isEmpty() 2846 || (d->keyboardInputTime.msecsTo(now) > QApplication::keyboardInputInterval())) { 2865 bool keyboardTimeWasValid = d->keyboardInputTime.isValid(); 2866 qint64 keyboardInputTimeElapsed = d->keyboardInputTime.restart(); 2867 if (search.isEmpty() || !keyboardTimeWasValid 2868 || keyboardInputTimeElapsed > QApplication::keyboardInputInterval()) { 2847 2869 d->keyboardInput = search; 2848 2870 skipRow = currentIndex().isValid(); //if it is not valid we should really start at QModelIndex(0,0) … … 2850 2872 d->keyboardInput += search; 2851 2873 } 2852 d->keyboardInputTime = now;2853 2874 2854 2875 // special case for searches with same key like 'aaaaa' -
trunk/src/gui/itemviews/qabstractitemview.h
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) -
trunk/src/gui/itemviews/qabstractitemview_p.h
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) … … 57 57 #include "private/qabstractitemmodel_p.h" 58 58 #include "QtGui/qapplication.h" 59 #include "QtCore/qdatetime.h"60 59 #include "QtGui/qevent.h" 61 60 #include "QtGui/qmime.h" … … 66 65 #include "QtGui/qpainter.h" 67 66 #include "QtCore/qbasictimer.h" 67 #include "QtCore/qelapsedtimer.h" 68 68 69 69 #ifndef QT_NO_ITEMVIEWS … … 391 391 392 392 QString keyboardInput; 393 Q TimekeyboardInputTime;393 QElapsedTimer keyboardInputTime; 394 394 395 395 bool autoScroll; … … 420 420 bool wrapItemText; 421 421 mutable bool delayedPendingLayout; 422 bool moveCursorUpdatedView; 422 423 423 424 private: -
trunk/src/gui/itemviews/qabstractproxymodel.cpp
r769 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) … … 188 188 QModelIndexList proxyIndexes = proxySelection.indexes(); 189 189 QItemSelection sourceSelection; 190 for (int i = 0; i < proxyIndexes.size(); ++i) 191 sourceSelection << QItemSelectionRange(mapToSource(proxyIndexes.at(i))); 190 for (int i = 0; i < proxyIndexes.size(); ++i) { 191 const QModelIndex proxyIdx = mapToSource(proxyIndexes.at(i)); 192 if (!proxyIdx.isValid()) 193 continue; 194 sourceSelection << QItemSelectionRange(proxyIdx); 195 } 192 196 return sourceSelection; 193 197 } … … 202 206 QModelIndexList sourceIndexes = sourceSelection.indexes(); 203 207 QItemSelection proxySelection; 204 for (int i = 0; i < sourceIndexes.size(); ++i) 205 proxySelection << QItemSelectionRange(mapFromSource(sourceIndexes.at(i))); 208 for (int i = 0; i < sourceIndexes.size(); ++i) { 209 const QModelIndex srcIdx = mapFromSource(sourceIndexes.at(i)); 210 if (!srcIdx.isValid()) 211 continue; 212 proxySelection << QItemSelectionRange(srcIdx); 213 } 206 214 return proxySelection; 207 215 } -
trunk/src/gui/itemviews/qabstractproxymodel.h
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) -
trunk/src/gui/itemviews/qabstractproxymodel_p.h
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) -
trunk/src/gui/itemviews/qbsptree.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) -
trunk/src/gui/itemviews/qbsptree_p.h
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) -
trunk/src/gui/itemviews/qcolumnview.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) -
trunk/src/gui/itemviews/qcolumnview.h
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) -
trunk/src/gui/itemviews/qcolumnview_p.h
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) -
trunk/src/gui/itemviews/qcolumnviewgrip.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) -
trunk/src/gui/itemviews/qcolumnviewgrip_p.h
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) -
trunk/src/gui/itemviews/qdatawidgetmapper.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) -
trunk/src/gui/itemviews/qdatawidgetmapper.h
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) -
trunk/src/gui/itemviews/qdirmodel.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) … … 186 186 /*! 187 187 \class QDirModel 188 188 \obsolete 189 189 \brief The QDirModel class provides a data model for the local filesystem. 190 190 191 191 \ingroup model-view 192 192 193 \noteThe usage of QDirModel is not recommended anymore. The193 The usage of QDirModel is not recommended anymore. The 194 194 QFileSystemModel class is a more performant alternative. 195 195 … … 201 201 QDirModel keeps a cache with file information. The cache needs to be 202 202 updated with refresh(). 203 204 A directory model that displays the contents of a default directory205 is usually constructed with a parent object:206 207 \snippet doc/src/snippets/shareddirmodel/main.cpp 2208 209 A tree view can be used to display the contents of the model210 211 \snippet doc/src/snippets/shareddirmodel/main.cpp 4212 213 and the contents of a particular directory can be displayed by214 setting the tree view's root index:215 216 \snippet doc/src/snippets/shareddirmodel/main.cpp 7217 218 The view's root index can be used to control how much of a219 hierarchical model is displayed. QDirModel provides a convenience220 function that returns a suitable model index for a path to a221 directory within the model.222 203 223 204 QDirModel can be accessed using the standard interface provided by … … 1183 1164 void QDirModelPrivate::init() 1184 1165 { 1166 Q_Q(QDirModel); 1185 1167 filters = QDir::AllEntries | QDir::NoDotAndDotDot; 1186 1168 sort = QDir::Name; … … 1189 1171 root.info = QFileInfo(); 1190 1172 clear(&root); 1173 QHash<int, QByteArray> roles = q->roleNames(); 1174 roles.insertMulti(QDirModel::FileIconRole, "fileIcon"); // == Qt::decoration 1175 roles.insert(QDirModel::FilePathRole, "filePath"); 1176 roles.insert(QDirModel::FileNameRole, "fileName"); 1177 q->setRoleNames(roles); 1191 1178 } 1192 1179 -
trunk/src/gui/itemviews/qdirmodel.h
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) -
trunk/src/gui/itemviews/qfileiconprovider.cpp
r829 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) … … 77 77 \class QFileIconProvider 78 78 79 \brief The QFileIconProvider class provides file icons for the QDirModel class.79 \brief The QFileIconProvider class provides file icons for the QDirModel and the QFileSystemModel classes. 80 80 */ 81 81 … … 106 106 #endif 107 107 QFileIconProvider *q_ptr; 108 QString homePath;108 const QString homePath; 109 109 110 110 private: 111 QIcon file;112 QIcon fileLink;113 QIcon directory;114 QIcon directoryLink;115 QIcon harddisk;116 QIcon floppy;117 QIcon cdrom;118 QIcon ram;119 QIcon network;120 QIcon computer;121 QIcon desktop;122 QIcon trashcan;123 QIcon generic;124 QIcon home;111 mutable QIcon file; 112 mutable QIcon fileLink; 113 mutable QIcon directory; 114 mutable QIcon directoryLink; 115 mutable QIcon harddisk; 116 mutable QIcon floppy; 117 mutable QIcon cdrom; 118 mutable QIcon ram; 119 mutable QIcon network; 120 mutable QIcon computer; 121 mutable QIcon desktop; 122 mutable QIcon trashcan; 123 mutable QIcon generic; 124 mutable QIcon home; 125 125 }; 126 126 127 QFileIconProviderPrivate::QFileIconProviderPrivate() 128 { 129 QStyle *style = QApplication::style(); 130 file = style->standardIcon(QStyle::SP_FileIcon); 131 directory = style->standardIcon(QStyle::SP_DirIcon); 132 fileLink = style->standardIcon(QStyle::SP_FileLinkIcon); 133 directoryLink = style->standardIcon(QStyle::SP_DirLinkIcon); 134 harddisk = style->standardIcon(QStyle::SP_DriveHDIcon); 135 floppy = style->standardIcon(QStyle::SP_DriveFDIcon); 136 cdrom = style->standardIcon(QStyle::SP_DriveCDIcon); 137 network = style->standardIcon(QStyle::SP_DriveNetIcon); 138 computer = style->standardIcon(QStyle::SP_ComputerIcon); 139 desktop = style->standardIcon(QStyle::SP_DesktopIcon); 140 trashcan = style->standardIcon(QStyle::SP_TrashIcon); 141 home = style->standardIcon(QStyle::SP_DirHomeIcon); 142 homePath = QDir::home().absolutePath(); 127 QFileIconProviderPrivate::QFileIconProviderPrivate() : 128 homePath(QDir::home().absolutePath()) 129 { 143 130 } 144 131 … … 147 134 switch (name) { 148 135 case QStyle::SP_FileIcon: 136 if (file.isNull()) 137 file = QApplication::style()->standardIcon(name); 149 138 return file; 150 139 case QStyle::SP_FileLinkIcon: 140 if (fileLink.isNull()) 141 fileLink = QApplication::style()->standardIcon(name); 151 142 return fileLink; 152 143 case QStyle::SP_DirIcon: 144 if (directory.isNull()) 145 directory = QApplication::style()->standardIcon(name); 153 146 return directory; 154 147 case QStyle::SP_DirLinkIcon: 148 if (directoryLink.isNull()) 149 directoryLink = QApplication::style()->standardIcon(name); 155 150 return directoryLink; 156 151 case QStyle::SP_DriveHDIcon: 152 if (harddisk.isNull()) 153 harddisk = QApplication::style()->standardIcon(name); 157 154 return harddisk; 158 155 case QStyle::SP_DriveFDIcon: 156 if (floppy.isNull()) 157 floppy = QApplication::style()->standardIcon(name); 159 158 return floppy; 160 159 case QStyle::SP_DriveCDIcon: 160 if (cdrom.isNull()) 161 cdrom = QApplication::style()->standardIcon(name); 161 162 return cdrom; 162 163 case QStyle::SP_DriveNetIcon: 164 if (network.isNull()) 165 network = QApplication::style()->standardIcon(name); 163 166 return network; 164 167 case QStyle::SP_ComputerIcon: 168 if (computer.isNull()) 169 computer = QApplication::style()->standardIcon(name); 165 170 return computer; 166 171 case QStyle::SP_DesktopIcon: 172 if (desktop.isNull()) 173 desktop = QApplication::style()->standardIcon(name); 167 174 return desktop; 168 175 case QStyle::SP_TrashIcon: 176 if (trashcan.isNull()) 177 trashcan = QApplication::style()->standardIcon(name); 169 178 return trashcan; 170 179 case QStyle::SP_DirHomeIcon: 180 if (home.isNull()) 181 home = QApplication::style()->standardIcon(name); 171 182 return home; 172 183 default: -
trunk/src/gui/itemviews/qfileiconprovider.h
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) -
trunk/src/gui/itemviews/qheaderview.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) … … 1699 1699 QBitArray sectionHidden(d->sectionHidden); 1700 1700 sectionHidden.resize(sectionHidden.count() + insertCount); 1701 //sectionHidden.fill(false, logicalFirst, logicalLast + 1); 1702 for (int i = logicalFirst; i <= logicalLast; ++i) 1703 // visual == logical in this range (see previous block) 1704 sectionHidden.setBit(i, false); 1701 sectionHidden.fill(false, logicalFirst, logicalLast + 1); 1705 1702 for (int j = logicalLast + 1; j < sectionHidden.count(); ++j) 1706 sectionHidden.setBit(d->visualIndex(j),1707 d->sectionHidden.testBit(d->visualIndex(j - insertCount)));1703 //here we simply copy the old sectionHidden 1704 sectionHidden.setBit(j, d->sectionHidden.testBit(j - insertCount)); 1708 1705 d->sectionHidden = sectionHidden; 1709 1706 } … … 1854 1851 return; 1855 1852 } 1853 1854 QBitArray oldSectionHidden = sectionHidden; 1856 1855 bool sectionCountChanged = false; 1857 for (int i = 0; i < sectionHidden.count(); ++i) {1858 if (sectionHidden.testBit(i))1859 q->setSectionHidden(logicalIndex(i), false);1860 }1861 1856 1862 1857 for (int i = 0; i < persistentHiddenSections.count(); ++i) { … … 1867 1862 : index.row()); 1868 1863 q->setSectionHidden(logical, true); 1864 oldSectionHidden.setBit(logical, false); 1869 1865 } else if (!sectionCountChanged && (modelSectionCount() != sectionCount)) { 1870 1866 sectionCountChanged = true; … … 1873 1869 } 1874 1870 persistentHiddenSections.clear(); 1871 1872 for (int i = 0; i < oldSectionHidden.count(); ++i) { 1873 if (oldSectionHidden.testBit(i)) 1874 q->setSectionHidden(i, false); 1875 } 1875 1876 1876 1877 // the number of sections changed; we need to reread the state of the model … … 2034 2035 } 2035 2036 break; } 2036 case QEvent::Timer: { // ### reimplement timerEvent() instead ?2037 case QEvent::Timer: { 2037 2038 QTimerEvent *te = static_cast<QTimerEvent*>(e); 2038 2039 if (te->timerId() == d->delayedResize.timerId()) { … … 2218 2219 } 2219 2220 case QHeaderViewPrivate::MoveSection: { 2220 if (qAbs(pos - d->firstPos) >= QApplication::startDragDistance()) { 2221 int indicatorCenter = (d->orientation == Qt::Horizontal 2222 ? d->sectionIndicator->width() 2223 : d->sectionIndicator->height()) / 2; 2224 int centerOffset = indicatorCenter - d->sectionIndicatorOffset; 2225 // This will drop the moved section to the position under the center of the indicator. 2226 // If centerOffset is 0, the section will be moved to the position of the mouse cursor. 2227 int visual = visualIndexAt(pos + centerOffset); 2221 if (qAbs(pos - d->firstPos) >= QApplication::startDragDistance() 2222 || !d->sectionIndicator->isHidden()) { 2223 int visual = visualIndexAt(pos); 2228 2224 if (visual == -1) 2229 2225 return; 2230 d->target = d->logicalIndex(visual); 2226 int posThreshold = d->headerSectionPosition(visual) + d->headerSectionSize(visual) / 2; 2227 int moving = visualIndex(d->section); 2228 if (visual < moving) { 2229 if (pos < posThreshold) 2230 d->target = d->logicalIndex(visual); 2231 else 2232 d->target = d->logicalIndex(visual + 1); 2233 } else if (visual > moving) { 2234 if (pos > posThreshold) 2235 d->target = d->logicalIndex(visual); 2236 else 2237 d->target = d->logicalIndex(visual - 1); 2238 } else { 2239 d->target = d->section; 2240 } 2231 2241 d->updateSectionIndicator(d->section, pos); 2232 } else {2233 int visual = visualIndexAt(d->firstPos);2234 if (visual == -1)2235 return;2236 d->target = d->logicalIndex(visual);2237 d->updateSectionIndicator(d->section, d->firstPos);2238 2242 } 2239 2243 return; … … 2301 2305 if (section != -1 && section == d->pressed) { 2302 2306 d->flipSortIndicator(section); 2303 emit sectionClicked( logicalIndexAt(pos));2307 emit sectionClicked(section); 2304 2308 } 2305 2309 if (d->pressed != -1) … … 2612 2616 d->layoutChildren(); 2613 2617 if (d->hasAutoResizeSections()) 2614 resizeSections();2618 d->doDelayedResizeSections(); 2615 2619 } 2616 2620 -
trunk/src/gui/itemviews/qheaderview.h
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) -
trunk/src/gui/itemviews/qheaderview_p.h
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) -
trunk/src/gui/itemviews/qitemdelegate.cpp
r769 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) … … 70 70 #include <qlocale.h> 71 71 #include <qdialog.h> 72 #include <qmath.h> 72 73 73 74 #include <limits.h> … … 667 668 Q_D(const QItemDelegate); 668 669 669 QPen pen = painter->pen();670 670 QPalette::ColorGroup cg = option.state & QStyle::State_Enabled 671 671 ? QPalette::Normal : QPalette::Disabled; … … 1024 1024 static QString qPixmapSerial(quint64 i, bool enabled) 1025 1025 { 1026 ushort arr[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '-', '0' + enabled};1026 ushort arr[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '-', ushort('0' + enabled) }; 1027 1027 ushort *ptr = &arr[16]; 1028 1028 … … 1149 1149 d->textLayout.setFont(font); 1150 1150 d->textLayout.setText(QItemDelegatePrivate::replaceNewLine(text)); 1151 const QSize size = d->doTextLayout(rect.width()).toSize(); 1151 QSizeF fpSize = d->doTextLayout(rect.width()); 1152 const QSize size = QSize(qCeil(fpSize.width()), qCeil(fpSize.height())); 1152 1153 // ###: textRectangle should take style option as argument 1153 1154 const int textMargin = QApplication::style()->pixelMetric(QStyle::PM_FocusFrameHMargin) + 1; -
trunk/src/gui/itemviews/qitemdelegate.h
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) -
trunk/src/gui/itemviews/qitemeditorfactory.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) -
trunk/src/gui/itemviews/qitemeditorfactory.h
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) -
trunk/src/gui/itemviews/qitemeditorfactory_p.h
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) -
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); -
trunk/src/gui/itemviews/qitemselectionmodel.h
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) … … 108 108 && top() <= bottom() && left() <= right()); 109 109 } 110 111 bool isEmpty() const; 110 112 111 113 QModelIndexList indexes() const; -
trunk/src/gui/itemviews/qitemselectionmodel_p.h
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) … … 71 71 QItemSelectionModel::SelectionFlags command) const; 72 72 73 void initModel(QAbstractItemModel *model); 74 73 75 void _q_rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end); 74 76 void _q_columnsAboutToBeRemoved(const QModelIndex &parent, int start, int end); -
trunk/src/gui/itemviews/qlistview.cpp
r769 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) … … 1388 1388 /*! 1389 1389 \reimp 1390 1391 Since 4.7, the returned region only contains rectangles intersecting 1392 (or included in) the viewport. 1390 1393 */ 1391 1394 QRegion QListView::visualRegionForSelection(const QItemSelection &selection) const … … 1395 1398 int c = d->column; 1396 1399 QRegion selectionRegion; 1400 const QRect &viewportRect = d->viewport->rect(); 1397 1401 for (int i = 0; i < selection.count(); ++i) { 1398 1402 if (!selection.at(i).isValid()) … … 1406 1410 int b = selection.at(i).bottomRight().row(); 1407 1411 if (d->viewMode == IconMode || d->isWrapping()) { // in non-static mode, we have to go through all selected items 1408 for (int r = t; r <= b; ++r) 1409 selectionRegion += QRegion(visualRect(d->model->index(r, c, parent))); 1412 for (int r = t; r <= b; ++r) { 1413 const QRect &rect = visualRect(d->model->index(r, c, parent)); 1414 if (viewportRect.intersects(rect)) 1415 selectionRegion += rect; 1416 } 1410 1417 } else { // in static mode, we can optimize a bit 1411 1418 while (t <= b && d->isHidden(t)) ++t; … … 1415 1422 QRect rect(visualRect(top).topLeft(), 1416 1423 visualRect(bottom).bottomRight()); 1417 selectionRegion += QRegion(rect); 1424 if (viewportRect.intersects(rect)) 1425 selectionRegion += rect; 1418 1426 } 1419 1427 } … … 1846 1854 horizontalScrollBar()->setSingleStep(step.width() + spacing()); 1847 1855 horizontalScrollBar()->setPageStep(viewport()->width()); 1848 horizontalScrollBar()->setRange(0, contentsSize.width() - viewport()->width() - 2 * spacing());1856 horizontalScrollBar()->setRange(0, contentsSize.width() - viewport()->width()); 1849 1857 } 1850 1858 … … 1853 1861 verticalScrollBar()->setSingleStep(step.height() + spacing()); 1854 1862 verticalScrollBar()->setPageStep(viewport()->height()); 1855 verticalScrollBar()->setRange(0, contentsSize.height() - viewport()->height() - 2 * spacing());1863 verticalScrollBar()->setRange(0, contentsSize.height() - viewport()->height()); 1856 1864 } 1857 1865 … … 2269 2277 QStyleOptionViewItemV4 option = viewOptions(); 2270 2278 option.rect = info.bounds; 2279 option.rect.adjust(info.spacing, info.spacing, -info.spacing, -info.spacing); 2271 2280 2272 2281 // The static layout data structures are as follows: … … 2774 2783 items.reserve(rowCount() - hiddenCount()); 2775 2784 } else { 2776 const QListViewItem item = items.at(info.first - 1); 2785 int idx = info.first - 1; 2786 while (idx > 0 && !items.at(idx).isValid()) 2787 --idx; 2788 const QListViewItem &item = items.at(idx); 2777 2789 x = item.x; 2778 2790 y = item.y; … … 2898 2910 bool done = (info.last >= rowCount() - 1); 2899 2911 // resize the content area 2900 if (done || !info.bounds.contains(item->rect())) 2901 contentsSize = QSize(rect.width(), rect.height()); 2912 if (done || !info.bounds.contains(item->rect())) { 2913 contentsSize = rect.size(); 2914 if (info.flow == QListView::LeftToRight) 2915 contentsSize.rheight() += info.spacing; 2916 else 2917 contentsSize.rwidth() += info.spacing; 2918 } 2919 if (rect.size().isEmpty()) 2920 return; 2902 2921 // resize tree 2903 2922 int insertFrom = info.first; -
trunk/src/gui/itemviews/qlistview.h
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) -
trunk/src/gui/itemviews/qlistview_p.h
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) -
trunk/src/gui/itemviews/qlistwidget.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) … … 792 792 This operator uses QListWidgetItem::write(). 793 793 794 \sa { Format of the QDataStream Operators}794 \sa {Serializing Qt Data Types} 795 795 */ 796 796 QDataStream &operator<<(QDataStream &out, const QListWidgetItem &item) … … 807 807 This operator uses QListWidgetItem::read(). 808 808 809 \sa { Format of the QDataStream Operators}809 \sa {Serializing Qt Data Types} 810 810 */ 811 811 QDataStream &operator>>(QDataStream &in, QListWidgetItem &item) -
trunk/src/gui/itemviews/qlistwidget.h
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) -
trunk/src/gui/itemviews/qlistwidget_p.h
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) -
trunk/src/gui/itemviews/qproxymodel.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) -
trunk/src/gui/itemviews/qproxymodel.h
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) … … 68 68 // implementing model interface 69 69 70 QModelIndex index(int row, int column, const QModelIndex &parent ) const;70 QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const; 71 71 QModelIndex parent(const QModelIndex &child) const; 72 72 73 int rowCount(const QModelIndex &parent ) const;74 int columnCount(const QModelIndex &parent ) const;75 bool hasChildren(const QModelIndex &parent ) const;73 int rowCount(const QModelIndex &parent = QModelIndex()) const; 74 int columnCount(const QModelIndex &parent = QModelIndex()) const; 75 bool hasChildren(const QModelIndex &parent = QModelIndex()) const; 76 76 77 QVariant data(const QModelIndex &index, int role ) const;78 bool setData(const QModelIndex &index, const QVariant &value, int role );77 QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; 78 bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole); 79 79 80 QVariant headerData(int section, Qt::Orientation orientation, int role ) const;80 QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const; 81 81 bool setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, 82 int role );82 int role = Qt::EditRole); 83 83 84 84 QStringList mimeTypes() const; … … 88 88 Qt::DropActions supportedDropActions() const; 89 89 90 bool insertRows(int row, int count, const QModelIndex &parent );91 bool insertColumns(int column, int count, const QModelIndex &parent );90 bool insertRows(int row, int count, const QModelIndex &parent = QModelIndex()); 91 bool insertColumns(int column, int count, const QModelIndex &parent = QModelIndex()); 92 92 93 93 void fetchMore(const QModelIndex &parent); 94 94 Qt::ItemFlags flags(const QModelIndex &index) const; 95 95 96 void sort(int column, Qt::SortOrder order );96 void sort(int column, Qt::SortOrder order = Qt::AscendingOrder); 97 97 98 98 QModelIndexList match(const QModelIndex &start, int role, const QVariant &value, 99 int hits, Qt::MatchFlags flags) const; 99 int hits = 1, Qt::MatchFlags flags = 100 Qt::MatchFlags(Qt::MatchStartsWith|Qt::MatchWrap)) const; 100 101 101 102 QSize span(const QModelIndex &index) const; -
trunk/src/gui/itemviews/qproxymodel_p.h
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) -
trunk/src/gui/itemviews/qsortfilterproxymodel.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) … … 112 112 113 113 114 //this struct is used to store what are the rows that are removed 115 //between a call to rowsAboutToBeRemoved and rowsRemoved 116 //it avoids readding rows to the mapping that are currently being removed 117 struct QRowsRemoval 118 { 119 QRowsRemoval(const QModelIndex &parent_source, int start, int end) : parent_source(parent_source), start(start), end(end) 120 { 121 } 122 123 QRowsRemoval() : start(-1), end(-1) 124 { 125 } 126 127 bool contains(QModelIndex parent, int row) 128 { 129 do { 130 if (parent == parent_source) 131 return row >= start && row <= end; 132 row = parent.row(); 133 parent = parent.parent(); 134 } while (row >= 0); 135 return false; 136 } 137 private: 138 QModelIndex parent_source; 139 int start; 140 int end; 141 }; 142 114 143 class QSortFilterProxyModelPrivate : public QAbstractProxyModelPrivate 115 144 { … … 123 152 QVector<int> proxy_columns; 124 153 QVector<QModelIndex> mapped_children; 125 Q Map<QModelIndex, Mapping *>::const_iterator map_iter;154 QHash<QModelIndex, Mapping *>::const_iterator map_iter; 126 155 }; 127 156 128 mutable Q Map<QModelIndex, Mapping*> source_index_mapping;157 mutable QHash<QModelIndex, Mapping*> source_index_mapping; 129 158 130 159 int source_sort_column; … … 140 169 141 170 bool dynamic_sortfilter; 171 QRowsRemoval itemsBeingRemoved; 142 172 143 173 QModelIndexPairList saved_persistent_indexes; 144 174 145 Q Map<QModelIndex, Mapping *>::const_iterator create_mapping(175 QHash<QModelIndex, Mapping *>::const_iterator create_mapping( 146 176 const QModelIndex &source_parent) const; 147 177 QModelIndex proxy_to_source(const QModelIndex &proxyIndex) const; … … 151 181 void remove_from_mapping(const QModelIndex &source_parent); 152 182 153 inline Q Map<QModelIndex, Mapping *>::const_iterator index_to_iterator(183 inline QHash<QModelIndex, Mapping *>::const_iterator index_to_iterator( 154 184 const QModelIndex &proxy_index) const 155 185 { … … 158 188 const void *p = proxy_index.internalPointer(); 159 189 Q_ASSERT(p); 160 Q Map<QModelIndex, Mapping *>::const_iterator it =190 QHash<QModelIndex, Mapping *>::const_iterator it = 161 191 static_cast<const Mapping*>(p)->map_iter; 162 192 Q_ASSERT(it != source_index_mapping.constEnd()); … … 166 196 167 197 inline QModelIndex create_index(int row, int column, 168 Q Map<QModelIndex, Mapping*>::const_iterator it) const198 QHash<QModelIndex, Mapping*>::const_iterator it) const 169 199 { 170 200 return q_func()->createIndex(row, column, *it); … … 247 277 }; 248 278 249 typedef Q Map<QModelIndex, QSortFilterProxyModelPrivate::Mapping *> IndexMap;279 typedef QHash<QModelIndex, QSortFilterProxyModelPrivate::Mapping *> IndexMap; 250 280 251 281 void QSortFilterProxyModelPrivate::_q_sourceModelDestroyed() … … 271 301 qDeleteAll(source_index_mapping); 272 302 source_index_mapping.clear(); 303 if (dynamic_sortfilter && update_source_sort_column()) { 304 //update_source_sort_column might have created wrong mapping so we have to clear it again 305 qDeleteAll(source_index_mapping); 306 source_index_mapping.clear(); 307 } 273 308 274 309 // update the persistent indexes … … 288 323 289 324 int source_rows = model->rowCount(source_parent); 325 m->source_rows.reserve(source_rows); 290 326 for (int i = 0; i < source_rows; ++i) { 291 327 if (q->filterAcceptsRow(i, source_parent)) … … 293 329 } 294 330 int source_cols = model->columnCount(source_parent); 331 m->source_columns.reserve(source_cols); 295 332 for (int i = 0; i < source_cols; ++i) { 296 333 if (q->filterAcceptsColumn(i, source_parent)) … … 559 596 int source_items_index = 0; 560 597 QVector<int> source_items_in_interval; 561 bool compare = (orient == Qt::Vertical && source_sort_column >= 0 );598 bool compare = (orient == Qt::Vertical && source_sort_column >= 0 && dynamic_sortfilter); 562 599 while (source_items_index < source_items.size()) { 563 600 source_items_in_interval.clear(); … … 738 775 // Items were inserted where there were none before. 739 776 // If it was new rows make sure to create mappings for columns so that a 740 // valid mapping can be retr eived later and vice-versa.777 // valid mapping can be retrieved later and vice-versa. 741 778 742 779 QVector<int> &orthogonal_proxy_to_source = (orient == Qt::Horizontal) ? m->source_rows : m->source_columns; … … 745 782 if (orthogonal_source_to_proxy.isEmpty()) { 746 783 const int ortho_end = (orient == Qt::Horizontal) ? model->rowCount(source_parent) : model->columnCount(source_parent); 784 785 orthogonal_source_to_proxy.resize(ortho_end); 747 786 748 787 for (int ortho_item = 0; ortho_item < ortho_end; ++ortho_item) { … … 752 791 } 753 792 } 754 orthogonal_source_to_proxy.resize(orthogonal_proxy_to_source.size());755 756 793 if (orient == Qt::Horizontal) { 757 794 // We're reacting to columnsInserted, but we've just inserted new rows. Sort them. … … 1063 1100 return; 1064 1101 QModelIndex source_parent = source_top_left.parent(); 1065 IndexMap::const_iterator it = create_mapping(source_parent);1102 IndexMap::const_iterator it = source_index_mapping.find(source_parent); 1066 1103 if (it == source_index_mapping.constEnd()) { 1067 1104 // Don't care, since we don't have mapping for this index … … 1090 1127 } 1091 1128 } else { 1092 if ( q->filterAcceptsRow(source_row, source_parent)) {1129 if (!itemsBeingRemoved.contains(source_parent, source_row) && q->filterAcceptsRow(source_row, source_parent)) { 1093 1130 // This source row now satisfies the filter, so it must be added 1094 1131 source_rows_insert.append(source_row); … … 1181 1218 Q_Q(QSortFilterProxyModel); 1182 1219 q->beginResetModel(); 1220 } 1221 1222 void QSortFilterProxyModelPrivate::_q_sourceReset() 1223 { 1224 Q_Q(QSortFilterProxyModel); 1183 1225 invalidatePersistentIndexes(); 1184 1226 clear_mapping(); 1185 }1186 1187 void QSortFilterProxyModelPrivate::_q_sourceReset()1188 {1189 Q_Q(QSortFilterProxyModel);1190 1227 // All internal structures are deleted in clear() 1191 1228 q->endResetModel(); … … 1209 1246 { 1210 1247 Q_Q(QSortFilterProxyModel); 1211 if (saved_persistent_indexes.isEmpty()) {1212 clear_mapping();1213 emit q->layoutChanged();1214 return;1215 }1216 1248 1217 1249 qDeleteAll(source_index_mapping); … … 1221 1253 saved_persistent_indexes.clear(); 1222 1254 1223 update_source_sort_column(); 1255 if (dynamic_sortfilter && update_source_sort_column()) { 1256 //update_source_sort_column might have created wrong mapping so we have to clear it again 1257 qDeleteAll(source_index_mapping); 1258 source_index_mapping.clear(); 1259 } 1224 1260 1225 1261 emit q->layoutChanged(); … … 1241 1277 { 1242 1278 source_items_inserted(source_parent, start, end, Qt::Vertical); 1243 if (update_source_sort_column() ) //previous call to update_source_sort_column may fail if the model has no column.1279 if (update_source_sort_column() && dynamic_sortfilter) //previous call to update_source_sort_column may fail if the model has no column. 1244 1280 sort(); // now it should succeed so we need to make sure to sort again 1245 1281 } … … 1248 1284 const QModelIndex &source_parent, int start, int end) 1249 1285 { 1286 itemsBeingRemoved = QRowsRemoval(source_parent, start, end); 1250 1287 source_items_about_to_be_removed(source_parent, start, end, 1251 1288 Qt::Vertical); … … 1255 1292 const QModelIndex &source_parent, int start, int end) 1256 1293 { 1294 itemsBeingRemoved = QRowsRemoval(); 1257 1295 source_items_removed(source_parent, start, end, Qt::Vertical); 1258 1296 } … … 1278 1316 return; //we sort according to the root column only 1279 1317 if (source_sort_column == -1) { 1280 //we update the source_sort_column depending on the prox _sort_column1281 if (update_source_sort_column() )1318 //we update the source_sort_column depending on the proxy_sort_column 1319 if (update_source_sort_column() && dynamic_sortfilter) 1282 1320 sort(); 1283 1321 } else { … … 1482 1520 d->filter_role = Qt::DisplayRole; 1483 1521 d->dynamic_sortfilter = false; 1484 connect(this, SIGNAL(modelReset()), this, SLOT(invalidate()));1485 1522 } 1486 1523 … … 2194 2231 whenever the contents of the source model change 2195 2232 2233 Note that you should not update the source model through the proxy 2234 model when dynamicSortFilter is true. For instance, if you set the 2235 proxy model on a QComboBox, then using functions that update the 2236 model, e.g., \l{QComboBox::}{addItem()}, will not work as 2237 expected. An alternative is to set dynamicSortFilter to false and 2238 call \l{QSortFilterProxyModel::}{sort()} after adding items to the 2239 QComboBox. 2240 2196 2241 The default value is false. 2197 2242 */ … … 2356 2401 switch (l.userType()) { 2357 2402 case QVariant::Invalid: 2358 return (r.type() == QVariant::Invalid);2403 return (r.type() != QVariant::Invalid); 2359 2404 case QVariant::Int: 2360 2405 return l.toInt() < r.toInt(); -
trunk/src/gui/itemviews/qsortfilterproxymodel.h
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) -
trunk/src/gui/itemviews/qstandarditemmodel.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) … … 1131 1131 user cannot interact with the item. 1132 1132 1133 This flag takes pre sedence over the other item flags; e.g. if an item is not1133 This flag takes precedence over the other item flags; e.g. if an item is not 1134 1134 enabled, it cannot be selected by the user, even if the Qt::ItemIsSelectable 1135 1135 flag has been set. … … 1922 1922 This operator uses QStandardItem::read(). 1923 1923 1924 \sa { Format of the QDataStream Operators}1924 \sa {Serializing Qt Data Types} 1925 1925 */ 1926 1926 QDataStream &operator>>(QDataStream &in, QStandardItem &item) … … 1938 1938 This operator uses QStandardItem::write(). 1939 1939 1940 \sa { Format of the QDataStream Operators}1940 \sa {Serializing Qt Data Types} 1941 1941 */ 1942 1942 QDataStream &operator<<(QDataStream &out, const QStandardItem &item) -
trunk/src/gui/itemviews/qstandarditemmodel.h
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) -
trunk/src/gui/itemviews/qstandarditemmodel_p.h
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) -
trunk/src/gui/itemviews/qstringlistmodel.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) -
trunk/src/gui/itemviews/qstringlistmodel.h
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) -
trunk/src/gui/itemviews/qstyleditemdelegate.cpp
r769 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) -
trunk/src/gui/itemviews/qstyleditemdelegate.h
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) -
trunk/src/gui/itemviews/qtableview.cpp
r769 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) … … 115 115 } else if (old_height > span->height()) { 116 116 //remove the span from all the subspans lists that intersect the columns not covered anymore 117 Index::iterator it_y = index.lowerBound(-qMax(span->bottom(), span->top())); //qMax useful lif height is 0117 Index::iterator it_y = index.lowerBound(-qMax(span->bottom(), span->top())); //qMax useful if height is 0 118 118 Q_ASSERT(it_y != index.end()); //it_y must exist since the span is in the list 119 119 while (-it_y.key() <= span->top() + old_height -1) { … … 1412 1412 1413 1413 if (showGrid) { 1414 // Find the bottom right (the last rows/col oumns might be hidden)1414 // Find the bottom right (the last rows/columns might be hidden) 1415 1415 while (verticalHeader->isSectionHidden(verticalHeader->logicalIndex(bottom))) --bottom; 1416 1416 QPen old = painter.pen(); … … 1847 1847 } 1848 1848 } else { // nothing moved 1849 selection.append(QItemSelectionRange(tl, br)); 1849 QItemSelectionRange range(tl, br); 1850 if (!range.isEmpty()) 1851 selection.append(range); 1850 1852 } 1851 1853 … … 1858 1860 Returns the rectangle from the viewport of the items in the given 1859 1861 \a selection. 1862 1863 Since 4.7, the returned region only contains rectangles intersecting 1864 (or included in) the viewport. 1860 1865 */ 1861 1866 QRegion QTableView::visualRegionForSelection(const QItemSelection &selection) const … … 1867 1872 1868 1873 QRegion selectionRegion; 1874 const QRect &viewportRect = d->viewport->rect(); 1869 1875 bool verticalMoved = verticalHeader()->sectionsMoved(); 1870 1876 bool horizontalMoved = horizontalHeader()->sectionsMoved(); … … 1876 1882 continue; 1877 1883 for (int r = range.top(); r <= range.bottom(); ++r) 1878 for (int c = range.left(); c <= range.right(); ++c) 1879 selectionRegion += QRegion(visualRect(d->model->index(r, c, d->root))); 1884 for (int c = range.left(); c <= range.right(); ++c) { 1885 const QRect &rangeRect = visualRect(d->model->index(r, c, d->root)); 1886 if (viewportRect.intersects(rangeRect)) 1887 selectionRegion += rangeRect; 1888 } 1880 1889 } 1881 1890 } else if (horizontalMoved) { … … 1889 1898 qSwap<int>(top, bottom); 1890 1899 int height = bottom - top; 1891 for (int c = range.left(); c <= range.right(); ++c) 1892 selectionRegion += QRegion(QRect(columnViewportPosition(c), top, 1893 columnWidth(c), height)); 1900 for (int c = range.left(); c <= range.right(); ++c) { 1901 const QRect rangeRect(columnViewportPosition(c), top, columnWidth(c), height); 1902 if (viewportRect.intersects(rangeRect)) 1903 selectionRegion += rangeRect; 1904 } 1894 1905 } 1895 1906 } else if (verticalMoved) { … … 1903 1914 qSwap<int>(left, right); 1904 1915 int width = right - left; 1905 for (int r = range.top(); r <= range.bottom(); ++r) 1906 selectionRegion += QRegion(QRect(left, rowViewportPosition(r), 1907 width, rowHeight(r))); 1916 for (int r = range.top(); r <= range.bottom(); ++r) { 1917 const QRect rangeRect(left, rowViewportPosition(r), width, rowHeight(r)); 1918 if (viewportRect.intersects(rangeRect)) 1919 selectionRegion += rangeRect; 1920 } 1908 1921 } 1909 1922 } else { // nothing moved … … 1926 1939 rright = columnViewportPosition(range.left()) + columnWidth(range.left()); 1927 1940 } 1928 selectionRegion += QRect(QPoint(rleft, rtop), QPoint(rright - 1 - gridAdjust, rbottom - 1 - gridAdjust)); 1941 const QRect rangeRect(QPoint(rleft, rtop), QPoint(rright - 1 - gridAdjust, rbottom - 1 - gridAdjust)); 1942 if (viewportRect.intersects(rangeRect)) 1943 selectionRegion += rangeRect; 1929 1944 if (d->hasSpans()) { 1930 1945 foreach (QSpanCollection::Span *s, 1931 1946 d->spans.spansInRect(range.left(), range.top(), range.width(), range.height())) { 1932 if (range.contains(s->top(), s->left(), range.parent())) 1933 selectionRegion += d->visualSpanRect(*s); 1947 if (range.contains(s->top(), s->left(), range.parent())) { 1948 const QRect &visualSpanRect = d->visualSpanRect(*s); 1949 if (viewportRect.intersects(visualSpanRect)) 1950 selectionRegion += visualSpanRect; 1951 } 1934 1952 } 1935 1953 } … … 1968 1986 { 1969 1987 Q_D(QTableView); 1970 updateGeometries(); 1971 if (verticalScrollMode() == QAbstractItemView::ScrollPerItem) 1972 d->verticalHeader->setOffsetToSectionPosition(verticalScrollBar()->value()); 1973 else 1974 d->verticalHeader->setOffset(verticalScrollBar()->value()); 1975 d->viewport->update(); 1988 d->doDelayedItemsLayout(); 1976 1989 } 1977 1990 … … 2133 2146 ensurePolished(); 2134 2147 2135 int left = qMax(0, columnAt(0));2136 int right = columnAt(d->viewport->width());2148 int left = qMax(0, d->horizontalHeader->visualIndexAt(0)); 2149 int right = d->horizontalHeader->visualIndexAt(d->viewport->width()); 2137 2150 if (right == -1) // the table don't have enough columns to fill the viewport 2138 2151 right = d->model->columnCount(d->root) - 1; … … 2192 2205 ensurePolished(); 2193 2206 2194 int top = qMax(0, rowAt(0));2195 int bottom = rowAt(d->viewport->height());2207 int top = qMax(0, d->verticalHeader->visualIndexAt(0)); 2208 int bottom = d->verticalHeader->visualIndexAt(d->viewport->height()); 2196 2209 if (!isVisible() || bottom == -1) // the table don't have enough rows to fill the viewport 2197 2210 bottom = d->model->rowCount(d->root) - 1; -
trunk/src/gui/itemviews/qtableview.h
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) -
trunk/src/gui/itemviews/qtableview_p.h
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) -
trunk/src/gui/itemviews/qtablewidget.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) … … 1429 1429 This operator uses QTableWidgetItem::read(). 1430 1430 1431 \sa { Format of the QDataStream Operators}1431 \sa {Serializing Qt Data Types} 1432 1432 */ 1433 1433 QDataStream &operator>>(QDataStream &in, QTableWidgetItem &item) … … 1444 1444 This operator uses QTableWidgetItem::write(). 1445 1445 1446 \sa { Format of the QDataStream Operators}1446 \sa {Serializing Qt Data Types} 1447 1447 */ 1448 1448 QDataStream &operator<<(QDataStream &out, const QTableWidgetItem &item) -
trunk/src/gui/itemviews/qtablewidget.h
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) -
trunk/src/gui/itemviews/qtablewidget_p.h
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) -
trunk/src/gui/itemviews/qtreeview.cpp
r769 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) … … 675 675 // since QAbstractItemView::dataChanged() will get the visualRect for the items anyway 676 676 677 bool sizeChanged = false; 677 678 int topViewIndex = d->viewIndex(topLeft); 678 if (topViewIndex == 0) 679 d->defaultItemHeight = indexRowSizeHint(topLeft); 680 bool sizeChanged = false; 679 if (topViewIndex == 0) { 680 int newDefaultItemHeight = indexRowSizeHint(topLeft); 681 sizeChanged = d->defaultItemHeight != newDefaultItemHeight; 682 d->defaultItemHeight = newDefaultItemHeight; 683 } 684 681 685 if (topViewIndex != -1) { 682 if (topLeft == bottomRight) {686 if (topLeft.row() == bottomRight.row()) { 683 687 int oldHeight = d->itemHeight(topViewIndex); 684 688 d->invalidateHeightCache(topViewIndex); 685 sizeChanged = (oldHeight != d->itemHeight(topViewIndex)); 689 sizeChanged |= (oldHeight != d->itemHeight(topViewIndex)); 690 if (topLeft.column() == 0) 691 d->viewItems[topViewIndex].hasChildren = d->hasVisibleChildren(topLeft); 686 692 } else { 687 693 int bottomViewIndex = d->viewIndex(bottomRight); … … 690 696 d->invalidateHeightCache(i); 691 697 sizeChanged |= (oldHeight != d->itemHeight(i)); 698 if (topLeft.column() == 0) 699 d->viewItems[i].hasChildren = d->hasVisibleChildren(d->viewItems.at(i).index); 692 700 } 693 701 } … … 955 963 start = d->model->index(0, 0, d->root); 956 964 957 QTime now(QTime::currentTime());958 965 bool skipRow = false; 959 if (search.isEmpty() 960 || (d->keyboardInputTime.msecsTo(now) > QApplication::keyboardInputInterval())) { 966 bool keyboardTimeWasValid = d->keyboardInputTime.isValid(); 967 qint64 keyboardInputTimeElapsed = d->keyboardInputTime.restart(); 968 if (search.isEmpty() || !keyboardTimeWasValid 969 || keyboardInputTimeElapsed > QApplication::keyboardInputInterval()) { 961 970 d->keyboardInput = search; 962 skipRow = true;971 skipRow = currentIndex().isValid(); //if it is not valid we should really start at QModelIndex(0,0) 963 972 } else { 964 973 d->keyboardInput += search; 965 974 } 966 d->keyboardInputTime = now;967 975 968 976 // special case for searches with same key like 'aaaaa' … … 1229 1237 d->hoverBranch = d->itemDecorationAt(he->pos()); 1230 1238 if (oldBranch != d->hoverBranch) { 1231 QModelIndex oldIndex = d->modelIndex(oldBranch),1232 newIndex = d->modelIndex(d->hoverBranch);1233 if (old Index != newIndex) {1234 QRect oldRect = visualRect(oldIndex);1235 QRect newRect = visualRect(newIndex);1236 oldRect.setLeft(oldRect.left() - d->indent);1237 newRect.setLeft(newRect.left() - d->indent);1238 //we need to paint the whole items (including the decoration) so that when the user1239 //moves the mouse over those elements they are updated1240 viewport()->update(oldRect);1241 viewport()->update( newRect);1239 //we need to paint the whole items (including the decoration) so that when the user 1240 //moves the mouse over those elements they are updated 1241 if (oldBranch >= 0) { 1242 int y = d->coordinateForItem(oldBranch); 1243 int h = d->itemHeight(oldBranch); 1244 viewport()->update(QRect(0, y, viewport()->width(), h)); 1245 } 1246 if (d->hoverBranch >= 0) { 1247 int y = d->coordinateForItem(d->hoverBranch); 1248 int h = d->itemHeight(d->hoverBranch); 1249 viewport()->update(QRect(0, y, viewport()->width(), h)); 1242 1250 } 1243 1251 } … … 1994 2002 { 1995 2003 Q_D(QTreeView); 2004 if (d->hasRemovedItems) { 2005 //clean the QSet that may contains old (and this invalid) indexes 2006 d->hasRemovedItems = false; 2007 QSet<QPersistentModelIndex>::iterator it = d->expandedIndexes.begin(); 2008 while (it != d->expandedIndexes.constEnd()) { 2009 if (!it->isValid()) 2010 it = d->expandedIndexes.erase(it); 2011 else 2012 ++it; 2013 } 2014 it = d->hiddenIndexes.begin(); 2015 while (it != d->hiddenIndexes.constEnd()) { 2016 if (!it->isValid()) 2017 it = d->hiddenIndexes.erase(it); 2018 else 2019 ++it; 2020 } 2021 } 1996 2022 d->viewItems.clear(); // prepare for new layout 1997 2023 QModelIndex parent = d->root; … … 2135 2161 case MoveLeft: { 2136 2162 QScrollBar *sb = horizontalScrollBar(); 2137 if (vi < d->viewItems.count() && d->viewItems.at(vi).expanded && d->itemsExpandable && sb->value() == sb->minimum()) 2163 if (vi < d->viewItems.count() && d->viewItems.at(vi).expanded && d->itemsExpandable && sb->value() == sb->minimum()) { 2138 2164 d->collapse(vi, true); 2139 else { 2165 d->moveCursorUpdatedView = true; 2166 } else { 2140 2167 bool descend = style()->styleHint(QStyle::SH_ItemView_ArrowKeysNavigateIntoChildren, 0, this); 2141 2168 if (descend) { … … 2157 2184 } 2158 2185 2186 int oldValue = sb->value(); 2159 2187 sb->setValue(sb->value() - sb->singleStep()); 2188 if (oldValue != sb->value()) 2189 d->moveCursorUpdatedView = true; 2160 2190 } 2161 2191 … … 2169 2199 && d->hasVisibleChildren(d->viewItems.at(vi).index)) { 2170 2200 d->expand(vi, true); 2201 d->moveCursorUpdatedView = true; 2171 2202 } else { 2172 2203 bool descend = style()->styleHint(QStyle::SH_ItemView_ArrowKeysNavigateIntoChildren, 0, this); … … 2191 2222 //last restort: we change the scrollbar value 2192 2223 QScrollBar *sb = horizontalScrollBar(); 2224 int oldValue = sb->value(); 2193 2225 sb->setValue(sb->value() + sb->singleStep()); 2226 if (oldValue != sb->value()) 2227 d->moveCursorUpdatedView = true; 2194 2228 } 2195 2229 } … … 2250 2284 Returns the rectangle from the viewport of the items in the given 2251 2285 \a selection. 2286 2287 Since 4.7, the returned region only contains rectangles intersecting 2288 (or included in) the viewport. 2252 2289 */ 2253 2290 QRegion QTreeView::visualRegionForSelection(const QItemSelection &selection) const … … 2258 2295 2259 2296 QRegion selectionRegion; 2297 const QRect &viewportRect = d->viewport->rect(); 2260 2298 for (int i = 0; i < selection.count(); ++i) { 2261 2299 QItemSelectionRange range = selection.at(i); … … 2290 2328 int height = bottom - top + 1; 2291 2329 if (d->header->sectionsMoved()) { 2292 for (int c = range.left(); c <= range.right(); ++c) 2293 selectionRegion += QRegion(QRect(columnViewportPosition(c), top, 2294 columnWidth(c), height)); 2330 for (int c = range.left(); c <= range.right(); ++c) { 2331 const QRect rangeRect(columnViewportPosition(c), top, columnWidth(c), height); 2332 if (viewportRect.intersects(rangeRect)) 2333 selectionRegion += rangeRect; 2334 } 2295 2335 } else { 2296 2336 QRect combined = leftRect|rightRect; 2297 2337 combined.setX(columnViewportPosition(isRightToLeft() ? range.right() : range.left())); 2298 selectionRegion += combined; 2338 if (viewportRect.intersects(combined)) 2339 selectionRegion += combined; 2299 2340 } 2300 2341 } … … 2403 2444 2404 2445 /*! 2405 \internal2406 */2407 static bool treeViewItemLessThan(const QTreeViewItem &left,2408 const QTreeViewItem &right)2409 {2410 if (left.level != right.level) {2411 Q_ASSERT(left.level > right.level);2412 QModelIndex leftParent = left.index.parent();2413 QModelIndex rightParent = right.index.parent();2414 // computer parent, don't get2415 while (leftParent.isValid() && leftParent.parent() != rightParent)2416 leftParent = leftParent.parent();2417 return (leftParent.row() < right.index.row());2418 }2419 return (left.index.row() < right.index.row());2420 }2421 2422 /*!2423 2446 Informs the view that the rows from the \a start row to the \a end row 2424 2447 inclusive have been inserted into the \a parent model item. … … 2449 2472 if (((parentItem != -1) && d->viewItems.at(parentItem).expanded && updatesEnabled()) 2450 2473 || (parent == d->root)) { 2451 const uint childLevel = (parentItem == -1) 2452 ? uint(0) : d->viewItems.at(parentItem).level + 1; 2453 const int firstChildItem = parentItem + 1; 2454 const int lastChildItem = firstChildItem + ((parentItem == -1) 2455 ? d->viewItems.count() 2456 : d->viewItems.at(parentItem).total) - 1; 2457 2458 if (parentRowCount == end + 1 && start > 0) { 2459 //need to Update hasMoreSiblings 2460 int previousRow = start - 1; 2461 QModelIndex previousSibilingModelIndex = d->model->index(previousRow, 0, parent); 2462 bool isHidden = d->isRowHidden(previousSibilingModelIndex); 2463 while (isHidden && previousRow > 0) { 2464 previousRow--; 2465 previousSibilingModelIndex = d->model->index(previousRow, 0, parent); 2466 isHidden = d->isRowHidden(previousSibilingModelIndex); 2467 } 2468 if (!isHidden) { 2469 const int previousSibilling = d->viewIndex(previousSibilingModelIndex); 2470 if(previousSibilling != -1) 2471 d->viewItems[previousSibilling].hasMoreSiblings = true; 2472 } 2473 } 2474 2475 QVector<QTreeViewItem> insertedItems(delta); 2476 for (int i = 0; i < delta; ++i) { 2477 QTreeViewItem &item = insertedItems[i]; 2478 item.index = d->model->index(i + start, 0, parent); 2479 item.level = childLevel; 2480 item.hasChildren = d->hasVisibleChildren(item.index); 2481 item.hasMoreSiblings = !((i == delta - 1) && (parentRowCount == end +1)); 2482 } 2483 if (d->viewItems.isEmpty()) 2484 d->defaultItemHeight = indexRowSizeHint(insertedItems[0].index); 2485 2486 int insertPos; 2487 if (lastChildItem < firstChildItem) { // no children 2488 insertPos = firstChildItem; 2489 } else { 2490 // do a binary search to figure out where to insert 2491 QVector<QTreeViewItem>::iterator it; 2492 it = qLowerBound(d->viewItems.begin() + firstChildItem, 2493 d->viewItems.begin() + lastChildItem + 1, 2494 insertedItems.at(0), treeViewItemLessThan); 2495 insertPos = it - d->viewItems.begin(); 2496 2497 // update stale model indexes of siblings 2498 for (int item = insertPos; item <= lastChildItem; ) { 2499 Q_ASSERT(d->viewItems.at(item).level == childLevel); 2500 const QModelIndex modelIndex = d->viewItems.at(item).index; 2501 //Q_ASSERT(modelIndex.parent() == parent); 2502 d->viewItems[item].index = d->model->index( 2503 modelIndex.row() + delta, modelIndex.column(), parent); 2504 2505 if (!d->viewItems[item].index.isValid()) { 2506 // Something really bad is happening, a bad model is 2507 // often the cause. We can't optimize in this case :( 2508 qWarning() << "QTreeView::rowsInserted internal representation of the model has been corrupted, resetting."; 2509 doItemsLayout(); 2510 return; 2511 } 2512 2513 item += d->viewItems.at(item).total + 1; 2514 } 2515 } 2516 2517 d->viewItems.insert(insertPos, delta, insertedItems.at(0)); 2518 if (delta > 1) { 2519 qCopy(insertedItems.begin() + 1, insertedItems.end(), 2520 d->viewItems.begin() + insertPos + 1); 2521 } 2522 2523 if (parentItem != -1) 2524 d->viewItems[parentItem].hasChildren = true; 2525 d->updateChildCount(parentItem, delta); 2526 2527 updateGeometries(); 2528 viewport()->update(); 2474 d->doDelayedItemsLayout(); 2529 2475 } else if ((parentItem != -1) && d->viewItems.at(parentItem).expanded) { 2530 2476 d->doDelayedItemsLayout(); … … 2544 2490 { 2545 2491 Q_D(QTreeView); 2546 d->rowsRemoved(parent, start, end, false);2547 2492 QAbstractItemView::rowsAboutToBeRemoved(parent, start, end); 2493 d->viewItems.clear(); 2548 2494 } 2549 2495 … … 2557 2503 { 2558 2504 Q_D(QTreeView); 2559 d->rowsRemoved(parent, start, end, true); 2505 d->viewItems.clear(); 2506 d->doDelayedItemsLayout(); 2507 d->hasRemovedItems = true; 2508 d->_q_rowsRemoved(parent, start, end); 2560 2509 } 2561 2510 … … 2659 2608 Q_D(QTreeView); 2660 2609 d->viewItems.clear(); 2661 d->expandedIndexes.clear();2662 2610 d->interruptDelayedItemsLayout(); 2663 d->layout(-1); 2664 for (int i = 0; i < d->viewItems.count(); ++i) { 2665 if (d->viewItems[i].expanded) 2666 continue; 2667 d->viewItems[i].expanded = true; 2668 d->layout(i); 2669 QModelIndex idx = d->viewItems.at(i).index; 2670 d->expandedIndexes.insert(idx); 2671 } 2611 d->layout(-1, true); 2672 2612 updateGeometries(); 2673 2613 d->viewport->update(); … … 2950 2890 } 2951 2891 2892 void QTreeViewPrivate::insertViewItems(int pos, int count, const QTreeViewItem &viewItem) 2893 { 2894 viewItems.insert(pos, count, viewItem); 2895 QTreeViewItem *items = viewItems.data(); 2896 for (int i = pos + count; i < viewItems.count(); i++) 2897 if (items[i].parentItem >= pos) 2898 items[i].parentItem += count; 2899 } 2900 2901 void QTreeViewPrivate::removeViewItems(int pos, int count) 2902 { 2903 viewItems.remove(pos, count); 2904 QTreeViewItem *items = viewItems.data(); 2905 for (int i = pos; i < viewItems.count(); i++) 2906 if (items[i].parentItem >= pos) 2907 items[i].parentItem -= count; 2908 } 2909 2910 #if 0 2911 bool QTreeViewPrivate::checkViewItems() const 2912 { 2913 for (int i = 0; i < viewItems.count(); ++i) { 2914 const QTreeViewItem &vi = viewItems.at(i); 2915 if (vi.parentItem == -1) { 2916 Q_ASSERT(!vi.index.parent().isValid() || vi.index.parent() == root); 2917 } else { 2918 Q_ASSERT(vi.index.parent() == viewItems.at(vi.parentItem).index); 2919 } 2920 } 2921 return true; 2922 } 2923 #endif 2924 2952 2925 void QTreeViewPrivate::collapse(int item, bool emitSignal) 2953 2926 { … … 2978 2951 viewItems[item].expanded = false; 2979 2952 int index = item; 2980 QModelIndex parent = modelIndex; 2981 while (parent.isValid() && parent != root) { 2982 Q_ASSERT(index > -1); 2953 while (index > -1) { 2983 2954 viewItems[index].total -= total; 2984 parent = parent.parent(); 2985 index = viewIndex(parent); 2986 } 2987 viewItems.remove(item + 1, total); // collapse 2955 index = viewItems[index].parentItem; 2956 } 2957 removeViewItems(item + 1, total); // collapse 2988 2958 q->setState(oldState); 2989 2959 … … 3122 3092 } 3123 3093 3124 void QTreeViewPrivate::layout(int i) 3094 /** \internal 3095 creates and initialize the viewItem structure of the children of the element \i 3096 3097 set \a recursiveExpanding if the function has to expand all the children (called from expandAll) 3098 \a afterIsUninitialized is when we recurse from layout(-1), it means all the items after 'i' are 3099 not yet initialized and need not to be moved 3100 */ 3101 void QTreeViewPrivate::layout(int i, bool recursiveExpanding, bool afterIsUninitialized) 3125 3102 { 3126 3103 Q_Q(QTreeView); … … 3149 3126 } 3150 3127 viewItems.resize(count); 3128 afterIsUninitialized = true; 3151 3129 } else if (viewItems[i].total != (uint)count) { 3152 viewItems.insert(i + 1, count, QTreeViewItem()); // expand 3130 if (!afterIsUninitialized) 3131 insertViewItems(i + 1, count, QTreeViewItem()); // expand 3132 else if (count > 0) 3133 viewItems.resize(viewItems.count() + count); 3153 3134 } else { 3154 3135 expanding = false; … … 3172 3153 item = &viewItems[last]; 3173 3154 item->index = current; 3155 item->parentItem = i; 3174 3156 item->level = level; 3175 3157 item->height = 0; … … 3178 3160 item->total = 0; 3179 3161 item->hasMoreSiblings = false; 3180 if (isIndexExpanded(current)) { 3162 if (recursiveExpanding || isIndexExpanded(current)) { 3163 if (recursiveExpanding) 3164 expandedIndexes.insert(current); 3181 3165 item->expanded = true; 3182 layout(last );3166 layout(last, recursiveExpanding, afterIsUninitialized); 3183 3167 item = &viewItems[last]; 3184 3168 children += item->total; … … 3192 3176 3193 3177 // remove hidden items 3194 if (hidden > 0) 3195 viewItems.remove(last + 1, hidden); // collapse 3178 if (hidden > 0) { 3179 if (!afterIsUninitialized) 3180 removeViewItems(last + 1, hidden); 3181 else 3182 viewItems.resize(viewItems.size() - hidden); 3183 } 3196 3184 3197 3185 if (!expanding) 3198 3186 return; // nothing changed 3199 3187 3200 while (parent != root) { 3201 Q_ASSERT(i > -1); 3188 while (i > -1) { 3202 3189 viewItems[i].total += count - hidden; 3203 parent = parent.parent(); 3204 i = viewIndex(parent); 3190 i = viewItems[i].parentItem; 3205 3191 } 3206 3192 } … … 3209 3195 { 3210 3196 int index = itemAtCoordinate(coordinateForItem(i) - viewport->height()); 3197 while (isItemHiddenOrDisabled(index)) 3198 index--; 3211 3199 return index == -1 ? 0 : index; 3212 3200 } … … 3215 3203 { 3216 3204 int index = itemAtCoordinate(coordinateForItem(i) + viewport->height()); 3205 while (isItemHiddenOrDisabled(index)) 3206 index++; 3217 3207 return index == -1 ? viewItems.count() - 1 : index; 3218 3208 } … … 3357 3347 const int totalCount = viewItems.count(); 3358 3348 const QModelIndex index = _index.sibling(_index.row(), 0); 3359 3360 3361 // A quick check near the last item to see if we are just incrementing 3362 const int start = lastViewedItem > 2 ? lastViewedItem - 2 : 0; 3363 const int end = lastViewedItem < totalCount - 2 ? lastViewedItem + 2 : totalCount; 3364 int row = index.row(); 3365 for (int i = start; i < end; ++i) { 3366 const QModelIndex &idx = viewItems.at(i).index; 3367 if (idx.row() == row) { 3368 if (idx.internalId() == index.internalId()) { 3369 lastViewedItem = i; 3370 return i; 3371 } 3372 } 3373 } 3374 3375 // NOTE: this function is slow if the item is outside the visible area 3376 // search in visible items first and below 3377 int t = firstVisibleItem(); 3378 t = t > 100 ? t - 100 : 0; // start 100 items above the visible area 3379 3380 for (int i = t; i < totalCount; ++i) { 3381 const QModelIndex &idx = viewItems.at(i).index; 3382 if (idx.row() == row) { 3383 if (idx.internalId() == index.internalId()) { 3384 lastViewedItem = i; 3385 return i; 3386 } 3387 } 3388 } 3389 // search from top to first visible 3390 for (int j = 0; j < t; ++j) { 3349 const int row = index.row(); 3350 const qint64 internalId = index.internalId(); 3351 3352 // We start nearest to the lastViewedItem 3353 int localCount = qMin(lastViewedItem - 1, totalCount - lastViewedItem); 3354 for (int i = 0; i < localCount; ++i) { 3355 const QModelIndex &idx1 = viewItems.at(lastViewedItem + i).index; 3356 if (idx1.row() == row && idx1.internalId() == internalId) { 3357 lastViewedItem = lastViewedItem + i; 3358 return lastViewedItem; 3359 } 3360 const QModelIndex &idx2 = viewItems.at(lastViewedItem - i - 1).index; 3361 if (idx2.row() == row && idx2.internalId() == internalId) { 3362 lastViewedItem = lastViewedItem - i - 1; 3363 return lastViewedItem; 3364 } 3365 } 3366 3367 for (int j = qMax(0, lastViewedItem + localCount); j < totalCount; ++j) { 3391 3368 const QModelIndex &idx = viewItems.at(j).index; 3392 if (idx.row() == row) { 3393 if (idx.internalId() == index.internalId()) { 3394 lastViewedItem = j; 3395 return j; 3396 } 3397 } 3398 } 3369 if (idx.row() == row && idx.internalId() == internalId) { 3370 lastViewedItem = j; 3371 return j; 3372 } 3373 } 3374 for (int j = qMin(totalCount, lastViewedItem - localCount) - 1; j >= 0; --j) { 3375 const QModelIndex &idx = viewItems.at(j).index; 3376 if (idx.row() == row && idx.internalId() == internalId) { 3377 lastViewedItem = j; 3378 return j; 3379 } 3380 } 3381 3399 3382 // nothing found 3400 3383 return -1; … … 3446 3429 } 3447 3430 3448 void QTreeViewPrivate::relayout(const QModelIndex &parent)3449 {3450 Q_Q(QTreeView);3451 // do a local relayout of the items3452 if (parent.isValid()) {3453 int parentViewIndex = viewIndex(parent);3454 if (parentViewIndex > -1 && viewItems.at(parentViewIndex).expanded) {3455 collapse(parentViewIndex, false); // remove the current layout3456 expand(parentViewIndex, false); // do the relayout3457 q->updateGeometries();3458 viewport->update();3459 }3460 } else {3461 viewItems.clear();3462 q->doItemsLayout();3463 }3464 }3465 3466 3467 3431 void QTreeViewPrivate::updateScrollBars() 3468 3432 { … … 3471 3435 if (!viewportSize.isValid()) 3472 3436 viewportSize = QSize(0, 0); 3437 3438 if (viewItems.isEmpty()) { 3439 q->doItemsLayout(); 3440 } 3473 3441 3474 3442 int itemsInViewport = 0; … … 3718 3686 } 3719 3687 3720 void QTreeViewPrivate::rowsRemoved(const QModelIndex &parent,3721 int start, int end, bool after)3722 {3723 Q_Q(QTreeView);3724 // if we are going to do a complete relayout anyway, there is no need to update3725 if (delayedPendingLayout) {3726 _q_rowsRemoved(parent, start, end);3727 return;3728 }3729 3730 const int parentItem = viewIndex(parent);3731 if ((parentItem != -1) || (parent == root)) {3732 3733 const uint childLevel = (parentItem == -1)3734 ? uint(0) : viewItems.at(parentItem).level + 1;3735 Q_UNUSED(childLevel); // unused in release mode, used in assert below3736 3737 const int firstChildItem = parentItem + 1;3738 int lastChildItem = firstChildItem + ((parentItem == -1)3739 ? viewItems.count()3740 : viewItems.at(parentItem).total) - 1;3741 3742 const int delta = end - start + 1;3743 3744 int previousSibiling = -1;3745 int removedCount = 0;3746 for (int item = firstChildItem; item <= lastChildItem; ) {3747 Q_ASSERT(viewItems.at(item).level == childLevel);3748 const QModelIndex modelIndex = viewItems.at(item).index;3749 //Q_ASSERT(modelIndex.parent() == parent);3750 const int count = viewItems.at(item).total + 1;3751 if (modelIndex.row() < start) {3752 previousSibiling = item;3753 // not affected by the removal3754 item += count;3755 } else if (modelIndex.row() <= end) {3756 // removed3757 viewItems.remove(item, count);3758 removedCount += count;3759 lastChildItem -= count;3760 } else {3761 if (after) {3762 // moved; update the model index3763 viewItems[item].index = model->index(3764 modelIndex.row() - delta, modelIndex.column(), parent);3765 }3766 item += count;3767 }3768 }3769 3770 if (previousSibiling != -1 && after && model->rowCount(parent) == start)3771 viewItems[previousSibiling].hasMoreSiblings = false;3772 3773 if (parentItem != -1) {3774 if (viewItems.at(parentItem).expanded) {3775 updateChildCount(parentItem, -removedCount);3776 if (viewItems.at(parentItem).total == 0)3777 viewItems[parentItem].hasChildren = false; //every children have been removed;3778 } else if (viewItems[parentItem].hasChildren && !hasVisibleChildren(parent)) {3779 viewItems[parentItem].hasChildren = false;3780 }3781 }3782 if (after) {3783 q->updateGeometries();3784 viewport->update();3785 } else {3786 //we have removed items: we should at least update the scroll bar values.3787 // They are used to determine the item geometry.3788 updateScrollBars();3789 }3790 } else {3791 // If an ancestor of root is removed then relayout3792 QModelIndex idx = root;3793 while (idx.isValid()) {3794 idx = idx.parent();3795 if (idx == parent) {3796 doDelayedItemsLayout();3797 break;3798 }3799 }3800 }3801 _q_rowsRemoved(parent, start, end);3802 3803 QSet<QPersistentModelIndex>::iterator it = expandedIndexes.begin();3804 while (it != expandedIndexes.constEnd()) {3805 if (!it->isValid())3806 it = expandedIndexes.erase(it);3807 else3808 ++it;3809 }3810 it = hiddenIndexes.begin();3811 while (it != hiddenIndexes.constEnd()) {3812 if (!it->isValid())3813 it = hiddenIndexes.erase(it);3814 else3815 ++it;3816 }3817 }3818 3819 void QTreeViewPrivate::updateChildCount(const int parentItem, const int delta)3820 {3821 if ((parentItem != -1) && delta) {3822 int level = viewItems.at(parentItem).level;3823 int item = parentItem;3824 do {3825 Q_ASSERT(item >= 0);3826 for ( ; int(viewItems.at(item).level) != level; --item) ;3827 viewItems[item].total += delta;3828 --level;3829 } while (level >= 0);3830 }3831 }3832 3833 3834 3688 void QTreeViewPrivate::_q_sortIndicatorChanged(int column, Qt::SortOrder order) 3835 3689 { -
trunk/src/gui/itemviews/qtreeview.h
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) -
trunk/src/gui/itemviews/qtreeview_p.h
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) … … 56 56 #include "private/qabstractitemview_p.h" 57 57 #include <QtCore/qvariantanimation.h> 58 #include <QtCore/qabstractitemmodel.h> 58 59 59 60 #ifndef QT_NO_TREEVIEW … … 63 64 struct QTreeViewItem 64 65 { 65 QTreeViewItem() : expanded(false), spanning(false), hasChildren(false),66 QTreeViewItem() : parentItem(-1), expanded(false), spanning(false), hasChildren(false), 66 67 hasMoreSiblings(false), total(0), level(0), height(0) {} 67 68 QModelIndex index; // we remove items whenever the indexes are invalidated 69 int parentItem; // parent item index in viewItems 68 70 uint expanded : 1; 69 71 uint spanning : 1; … … 75 77 }; 76 78 79 Q_DECLARE_TYPEINFO(QTreeViewItem, Q_MOVABLE_TYPE); 80 77 81 class QTreeViewPrivate : public QAbstractItemViewPrivate 78 82 { … … 88 92 allColumnsShowFocus(false), current(0), spanning(false), 89 93 animationsEnabled(false), columnResizeTimerID(0), 90 autoExpandDelay(-1), hoverBranch(-1), geometryRecursionBlock(false) {}94 autoExpandDelay(-1), hoverBranch(-1), geometryRecursionBlock(false), hasRemovedItems(false) {} 91 95 92 96 ~QTreeViewPrivate() {} … … 124 128 void _q_modelDestroyed(); 125 129 126 void layout(int item );130 void layout(int item, bool recusiveExpanding = false, bool afterIsUninitialized = false); 127 131 128 132 int pageUp(int item) const; … … 137 141 QModelIndex modelIndex(int i, int column = 0) const; 138 142 143 void insertViewItems(int pos, int count, const QTreeViewItem &viewItem); 144 void removeViewItems(int pos, int count); 145 #if 0 146 bool checkViewItems() const; 147 #endif 148 139 149 int firstVisibleItem(int *offset = 0) const; 140 150 int columnAt(int x) const; 141 151 bool hasVisibleChildren( const QModelIndex& parent) const; 142 152 143 void relayout(const QModelIndex &parent);144 153 bool expandOrCollapseItemAtPos(const QPoint &pos); 145 154 … … 156 165 157 166 void updateChildCount(const int parentItem, const int delta); 158 void rowsRemoved(const QModelIndex &parent,159 int start, int end, bool before);160 167 161 168 void paintAlternatingRowColors(QPainter *painter, QStyleOptionViewItemV4 *option, int y, int bottom) const; … … 233 240 // used for blocking recursion when calling setViewportMargins from updateGeometries 234 241 bool geometryRecursionBlock; 242 243 // If we should clean the set 244 bool hasRemovedItems; 235 245 }; 236 246 -
trunk/src/gui/itemviews/qtreewidget.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) … … 1473 1473 /*! 1474 1474 Destroys this tree widget item. 1475 1476 The item will be removed from \l{QTreeWidget}s to which it has 1477 been added. This makes it safe to delete an item at any time. 1478 1475 1479 */ 1476 1480 … … 2200 2204 This operator uses QTreeWidgetItem::write(). 2201 2205 2202 \sa { Format of the QDataStream Operators}2206 \sa {Serializing Qt Data Types} 2203 2207 */ 2204 2208 QDataStream &operator<<(QDataStream &out, const QTreeWidgetItem &item) … … 2215 2219 This operator uses QTreeWidgetItem::read(). 2216 2220 2217 \sa { Format of the QDataStream Operators}2221 \sa {Serializing Qt Data Types} 2218 2222 */ 2219 2223 QDataStream &operator>>(QDataStream &in, QTreeWidgetItem &item) … … 3040 3044 QModelIndexList indexes = selectionModel()->selectedIndexes(); 3041 3045 QList<QTreeWidgetItem*> items; 3046 items.reserve(indexes.count()); 3047 QSet<QTreeWidgetItem *> seen; 3048 seen.reserve(indexes.count()); 3042 3049 for (int i = 0; i < indexes.count(); ++i) { 3043 3050 QTreeWidgetItem *item = d->item(indexes.at(i)); 3044 if (isItemHidden(item) || items.contains(item)) // ### slow, optimize later3051 if (isItemHidden(item) || seen.contains(item)) 3045 3052 continue; 3053 seen.insert(item); 3046 3054 items.append(item); 3047 3055 } -
trunk/src/gui/itemviews/qtreewidget.h
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) -
trunk/src/gui/itemviews/qtreewidget_p.h
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) -
trunk/src/gui/itemviews/qtreewidgetitemiterator.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) -
trunk/src/gui/itemviews/qtreewidgetitemiterator.h
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) -
trunk/src/gui/itemviews/qtreewidgetitemiterator_p.h
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) -
trunk/src/gui/itemviews/qwidgetitemdata_p.h
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)
Note:
See TracChangeset
for help on using the changeset viewer.