| Line | Source Code | Coverage |
|---|
| 1 | /**************************************************************************** | - |
| 2 | ** | - |
| 3 | ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). | - |
| 4 | ** Contact: http://www.qt-project.org/legal | - |
| 5 | ** | - |
| 6 | ** This file is part of the QtGui module of the Qt Toolkit. | - |
| 7 | ** | - |
| 8 | ** $QT_BEGIN_LICENSE:LGPL$ | - |
| 9 | ** Commercial License Usage | - |
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in | - |
| 11 | ** accordance with the commercial license agreement provided with the | - |
| 12 | ** Software or, alternatively, in accordance with the terms contained in | - |
| 13 | ** a written agreement between you and Digia. For licensing terms and | - |
| 14 | ** conditions see http://qt.digia.com/licensing. For further information | - |
| 15 | ** use the contact form at http://qt.digia.com/contact-us. | - |
| 16 | ** | - |
| 17 | ** GNU Lesser General Public License Usage | - |
| 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - |
| 19 | ** General Public License version 2.1 as published by the Free Software | - |
| 20 | ** Foundation and appearing in the file LICENSE.LGPL included in the | - |
| 21 | ** packaging of this file. Please review the following information to | - |
| 22 | ** ensure the GNU Lesser General Public License version 2.1 requirements | - |
| 23 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | - |
| 24 | ** | - |
| 25 | ** In addition, as a special exception, Digia gives you certain additional | - |
| 26 | ** rights. These rights are described in the Digia Qt LGPL Exception | - |
| 27 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | - |
| 28 | ** | - |
| 29 | ** GNU General Public License Usage | - |
| 30 | ** Alternatively, this file may be used under the terms of the GNU | - |
| 31 | ** General Public License version 3.0 as published by the Free Software | - |
| 32 | ** Foundation and appearing in the file LICENSE.GPL included in the | - |
| 33 | ** packaging of this file. Please review the following information to | - |
| 34 | ** ensure the GNU General Public License version 3.0 requirements will be | - |
| 35 | ** met: http://www.gnu.org/copyleft/gpl.html. | - |
| 36 | ** | - |
| 37 | ** | - |
| 38 | ** $QT_END_LICENSE$ | - |
| 39 | ** | - |
| 40 | ****************************************************************************/ | - |
| 41 | | - |
| 42 | #include "qitemselectionmodel.h" | - |
| 43 | #include <private/qitemselectionmodel_p.h> | - |
| 44 | #include <qdebug.h> | - |
| 45 | | - |
| 46 | #include <algorithm> | - |
| 47 | | - |
| 48 | #ifndef QT_NO_ITEMVIEWS | - |
| 49 | | - |
| 50 | QT_BEGIN_NAMESPACE | - |
| 51 | | - |
| 52 | /*! | - |
| 53 | \class QItemSelectionRange | - |
| 54 | \inmodule QtCore | - |
| 55 | | - |
| 56 | \brief The QItemSelectionRange class manages information about a | - |
| 57 | range of selected items in a model. | - |
| 58 | | - |
| 59 | \ingroup model-view | - |
| 60 | | - |
| 61 | A QItemSelectionRange contains information about a range of | - |
| 62 | selected items in a model. A range of items is a contiguous array | - |
| 63 | of model items, extending to cover a number of adjacent rows and | - |
| 64 | columns with a common parent item; this can be visualized as a | - |
| 65 | two-dimensional block of cells in a table. A selection range has a | - |
| 66 | top(), left() a bottom(), right() and a parent(). | - |
| 67 | | - |
| 68 | The QItemSelectionRange class is one of the \l{Model/View Classes} | - |
| 69 | and is part of Qt's \l{Model/View Programming}{model/view framework}. | - |
| 70 | | - |
| 71 | The model items contained in the selection range can be obtained | - |
| 72 | using the indexes() function. Use QItemSelectionModel::selectedIndexes() | - |
| 73 | to get a list of all selected items for a view. | - |
| 74 | | - |
| 75 | You can determine whether a given model item lies within a | - |
| 76 | particular range by using the contains() function. Ranges can also | - |
| 77 | be compared using the overloaded operators for equality and | - |
| 78 | inequality, and the intersects() function allows you to determine | - |
| 79 | whether two ranges overlap. | - |
| 80 | | - |
| 81 | \sa {Model/View Programming}, QAbstractItemModel, QItemSelection, | - |
| 82 | QItemSelectionModel | - |
| 83 | */ | - |
| 84 | | - |
| 85 | /*! | - |
| 86 | \fn QItemSelectionRange::QItemSelectionRange() | - |
| 87 | | - |
| 88 | Constructs an empty selection range. | - |
| 89 | */ | - |
| 90 | | - |
| 91 | /*! | - |
| 92 | \fn QItemSelectionRange::QItemSelectionRange(const QItemSelectionRange &other) | - |
| 93 | | - |
| 94 | Copy constructor. Constructs a new selection range with the same contents | - |
| 95 | as the \a other range given. | - |
| 96 | | - |
| 97 | */ | - |
| 98 | | - |
| 99 | /*! | - |
| 100 | \fn QItemSelectionRange::QItemSelectionRange(const QModelIndex &topLeft, const QModelIndex &bottomRight) | - |
| 101 | | - |
| 102 | Constructs a new selection range containing only the index specified | - |
| 103 | by the \a topLeft and the index \a bottomRight. | - |
| 104 | | - |
| 105 | */ | - |
| 106 | | - |
| 107 | /*! | - |
| 108 | \fn QItemSelectionRange::QItemSelectionRange(const QModelIndex &index) | - |
| 109 | | - |
| 110 | Constructs a new selection range containing only the model item specified | - |
| 111 | by the model index \a index. | - |
| 112 | */ | - |
| 113 | | - |
| 114 | /*! | - |
| 115 | \fn int QItemSelectionRange::top() const | - |
| 116 | | - |
| 117 | Returns the row index corresponding to the uppermost selected row in the | - |
| 118 | selection range. | - |
| 119 | | - |
| 120 | */ | - |
| 121 | | - |
| 122 | /*! | - |
| 123 | \fn int QItemSelectionRange::left() const | - |
| 124 | | - |
| 125 | Returns the column index corresponding to the leftmost selected column in the | - |
| 126 | selection range. | - |
| 127 | */ | - |
| 128 | | - |
| 129 | /*! | - |
| 130 | \fn int QItemSelectionRange::bottom() const | - |
| 131 | | - |
| 132 | Returns the row index corresponding to the lowermost selected row in the | - |
| 133 | selection range. | - |
| 134 | | - |
| 135 | */ | - |
| 136 | | - |
| 137 | /*! | - |
| 138 | \fn int QItemSelectionRange::right() const | - |
| 139 | | - |
| 140 | Returns the column index corresponding to the rightmost selected column in | - |
| 141 | the selection range. | - |
| 142 | | - |
| 143 | */ | - |
| 144 | | - |
| 145 | /*! | - |
| 146 | \fn int QItemSelectionRange::width() const | - |
| 147 | | - |
| 148 | Returns the number of selected columns in the selection range. | - |
| 149 | | - |
| 150 | */ | - |
| 151 | | - |
| 152 | /*! | - |
| 153 | \fn int QItemSelectionRange::height() const | - |
| 154 | | - |
| 155 | Returns the number of selected rows in the selection range. | - |
| 156 | | - |
| 157 | */ | - |
| 158 | | - |
| 159 | /*! | - |
| 160 | \fn const QAbstractItemModel *QItemSelectionRange::model() const | - |
| 161 | | - |
| 162 | Returns the model that the items in the selection range belong to. | - |
| 163 | */ | - |
| 164 | | - |
| 165 | /*! | - |
| 166 | \fn QModelIndex QItemSelectionRange::topLeft() const | - |
| 167 | | - |
| 168 | Returns the index for the item located at the top-left corner of | - |
| 169 | the selection range. | - |
| 170 | | - |
| 171 | \sa top(), left(), bottomRight() | - |
| 172 | */ | - |
| 173 | | - |
| 174 | /*! | - |
| 175 | \fn QModelIndex QItemSelectionRange::bottomRight() const | - |
| 176 | | - |
| 177 | Returns the index for the item located at the bottom-right corner | - |
| 178 | of the selection range. | - |
| 179 | | - |
| 180 | \sa bottom(), right(), topLeft() | - |
| 181 | */ | - |
| 182 | | - |
| 183 | /*! | - |
| 184 | \fn QModelIndex QItemSelectionRange::parent() const | - |
| 185 | | - |
| 186 | Returns the parent model item index of the items in the selection range. | - |
| 187 | | - |
| 188 | */ | - |
| 189 | | - |
| 190 | /*! | - |
| 191 | \fn bool QItemSelectionRange::contains(const QModelIndex &index) const | - |
| 192 | | - |
| 193 | Returns true if the model item specified by the \a index lies within the | - |
| 194 | range of selected items; otherwise returns false. | - |
| 195 | */ | - |
| 196 | | - |
| 197 | /*! | - |
| 198 | \fn bool QItemSelectionRange::contains(int row, int column, | - |
| 199 | const QModelIndex &parentIndex) const | - |
| 200 | \overload | - |
| 201 | | - |
| 202 | Returns true if the model item specified by (\a row, \a column) | - |
| 203 | and with \a parentIndex as the parent item lies within the range | - |
| 204 | of selected items; otherwise returns false. | - |
| 205 | */ | - |
| 206 | | - |
| 207 | /*! | - |
| 208 | \fn bool QItemSelectionRange::intersects(const QItemSelectionRange &other) const | - |
| 209 | | - |
| 210 | Returns true if this selection range intersects (overlaps with) the \a other | - |
| 211 | range given; otherwise returns false. | - |
| 212 | | - |
| 213 | */ | - |
| 214 | bool QItemSelectionRange::intersects(const QItemSelectionRange &other) const | - |
| 215 | { | - |
| 216 | return (isValid() && other.isValid() executed: return (isValid() && other.isValid() && parent() == other.parent() && model() == other.model() && ((top() <= other.top() && bottom() >= other.top()) || (top() >= other.top() && top() <= other.bottom())) && ((left() <= other.left() && right() >= other.left()) || (left() >= other.left() && left() <= other.right())));Execution Count:10580 | 10580 |
| 217 | && parent() == other.parent() executed: return (isValid() && other.isValid() && parent() == other.parent() && model() == other.model() && ((top() <= other.top() && bottom() >= other.top()) || (top() >= other.top() && top() <= other.bottom())) && ((left() <= other.left() && right() >= other.left()) || (left() >= other.left() && left() <= other.right())));Execution Count:10580 | 10580 |
| 218 | && model() == other.model() executed: return (isValid() && other.isValid() && parent() == other.parent() && model() == other.model() && ((top() <= other.top() && bottom() >= other.top()) || (top() >= other.top() && top() <= other.bottom())) && ((left() <= other.left() && right() >= other.left()) || (left() >= other.left() && left() <= other.right())));Execution Count:10580 | 10580 |
| 219 | && ((top() <= other.top() && bottom() >= other.top()) executed: return (isValid() && other.isValid() && parent() == other.parent() && model() == other.model() && ((top() <= other.top() && bottom() >= other.top()) || (top() >= other.top() && top() <= other.bottom())) && ((left() <= other.left() && right() >= other.left()) || (left() >= other.left() && left() <= other.right())));Execution Count:10580 | 10580 |
| 220 | || (top() >= other.top() && top() <= other.bottom())) executed: return (isValid() && other.isValid() && parent() == other.parent() && model() == other.model() && ((top() <= other.top() && bottom() >= other.top()) || (top() >= other.top() && top() <= other.bottom())) && ((left() <= other.left() && right() >= other.left()) || (left() >= other.left() && left() <= other.right())));Execution Count:10580 | 10580 |
| 221 | && ((left() <= other.left() && right() >= other.left()) executed: return (isValid() && other.isValid() && parent() == other.parent() && model() == other.model() && ((top() <= other.top() && bottom() >= other.top()) || (top() >= other.top() && top() <= other.bottom())) && ((left() <= other.left() && right() >= other.left()) || (left() >= other.left() && left() <= other.right())));Execution Count:10580 | 10580 |
| 222 | || (left() >= other.left() && left() <= other.right()))); executed: return (isValid() && other.isValid() && parent() == other.parent() && model() == other.model() && ((top() <= other.top() && bottom() >= other.top()) || (top() >= other.top() && top() <= other.bottom())) && ((left() <= other.left() && right() >= other.left()) || (left() >= other.left() && left() <= other.right())));Execution Count:10580 | 10580 |
| 223 | } | - |
| 224 | | - |
| 225 | /*! | - |
| 226 | \fn QItemSelectionRange QItemSelectionRange::intersect(const QItemSelectionRange &other) const | - |
| 227 | \obsolete | - |
| 228 | | - |
| 229 | Use intersected(\a other) instead. | - |
| 230 | */ | - |
| 231 | | - |
| 232 | /*! | - |
| 233 | \fn QItemSelectionRange QItemSelectionRange::intersected(const QItemSelectionRange &other) const | - |
| 234 | \since 4.2 | - |
| 235 | | - |
| 236 | Returns a new selection range containing only the items that are found in | - |
| 237 | both the selection range and the \a other selection range. | - |
| 238 | */ | - |
| 239 | | - |
| 240 | QItemSelectionRange QItemSelectionRange::intersected(const QItemSelectionRange &other) const | - |
| 241 | { | - |
| 242 | if (model() == other.model() && parent() == other.parent()) { partially evaluated: model() == other.model()| yes Evaluation Count:1151 | no Evaluation Count:0 |
partially evaluated: parent() == other.parent()| yes Evaluation Count:1151 | no Evaluation Count:0 |
| 0-1151 |
| 243 | QModelIndex topLeft = model()->index(qMax(top(), other.top()), executed (the execution status of this line is deduced): QModelIndex topLeft = model()->index(qMax(top(), other.top()), | - |
| 244 | qMax(left(), other.left()), executed (the execution status of this line is deduced): qMax(left(), other.left()), | - |
| 245 | other.parent()); executed (the execution status of this line is deduced): other.parent()); | - |
| 246 | QModelIndex bottomRight = model()->index(qMin(bottom(), other.bottom()), executed (the execution status of this line is deduced): QModelIndex bottomRight = model()->index(qMin(bottom(), other.bottom()), | - |
| 247 | qMin(right(), other.right()), executed (the execution status of this line is deduced): qMin(right(), other.right()), | - |
| 248 | other.parent()); executed (the execution status of this line is deduced): other.parent()); | - |
| 249 | return QItemSelectionRange(topLeft, bottomRight); executed: return QItemSelectionRange(topLeft, bottomRight);Execution Count:1151 | 1151 |
| 250 | } | - |
| 251 | return QItemSelectionRange(); never executed: return QItemSelectionRange(); | 0 |
| 252 | } | - |
| 253 | | - |
| 254 | /*! | - |
| 255 | \fn bool QItemSelectionRange::operator==(const QItemSelectionRange &other) const | - |
| 256 | | - |
| 257 | Returns true if the selection range is exactly the same as the \a other | - |
| 258 | range given; otherwise returns false. | - |
| 259 | | - |
| 260 | */ | - |
| 261 | | - |
| 262 | /*! | - |
| 263 | \fn bool QItemSelectionRange::operator!=(const QItemSelectionRange &other) const | - |
| 264 | | - |
| 265 | Returns true if the selection range differs from the \a other range given; | - |
| 266 | otherwise returns false. | - |
| 267 | | - |
| 268 | */ | - |
| 269 | | - |
| 270 | /*! | - |
| 271 | \fn bool QItemSelectionRange::operator<(const QItemSelectionRange &other) const | - |
| 272 | | - |
| 273 | Returns true if the selection range is less than the \a other | - |
| 274 | range given; otherwise returns false. | - |
| 275 | | - |
| 276 | The less than calculation is not directly useful to developers - the way that ranges | - |
| 277 | with different parents compare is not defined. This operator only exists so that the | - |
| 278 | class can be used with QMap. | - |
| 279 | | - |
| 280 | */ | - |
| 281 | | - |
| 282 | /*! | - |
| 283 | \fn bool QItemSelectionRange::isValid() const | - |
| 284 | | - |
| 285 | Returns true if the selection range is valid; otherwise returns false. | - |
| 286 | | - |
| 287 | */ | - |
| 288 | | - |
| 289 | static void rowLengthsFromRange(const QItemSelectionRange &range, QVector<QPair<QPersistentModelIndex, uint> > &result) | - |
| 290 | { | - |
| 291 | if (range.isValid() && range.model()) { evaluated: range.isValid()| yes Evaluation Count:9 | yes Evaluation Count:2 |
partially evaluated: range.model()| yes Evaluation Count:9 | no Evaluation Count:0 |
| 0-9 |
| 292 | const QModelIndex topLeft = range.topLeft(); executed (the execution status of this line is deduced): const QModelIndex topLeft = range.topLeft(); | - |
| 293 | const int bottom = range.bottom(); executed (the execution status of this line is deduced): const int bottom = range.bottom(); | - |
| 294 | const uint width = range.width(); executed (the execution status of this line is deduced): const uint width = range.width(); | - |
| 295 | const int column = topLeft.column(); executed (the execution status of this line is deduced): const int column = topLeft.column(); | - |
| 296 | for (int row = topLeft.row(); row <= bottom; ++row) { evaluated: row <= bottom| yes Evaluation Count:14 | yes Evaluation Count:9 |
| 9-14 |
| 297 | // We don't need to keep track of ItemIsSelectable and ItemIsEnabled here. That is | - |
| 298 | // required in indexesFromRange() because that method is called from public API | - |
| 299 | // which requires the limitation. | - |
| 300 | result.push_back(qMakePair(QPersistentModelIndex(topLeft.sibling(row, column)), width)); executed (the execution status of this line is deduced): result.push_back(qMakePair(QPersistentModelIndex(topLeft.sibling(row, column)), width)); | - |
| 301 | } executed: }Execution Count:14 | 14 |
| 302 | } executed: }Execution Count:9 | 9 |
| 303 | } executed: }Execution Count:11 | 11 |
| 304 | | - |
| 305 | template<typename ModelIndexContainer> | - |
| 306 | static void indexesFromRange(const QItemSelectionRange &range, ModelIndexContainer &result) | - |
| 307 | { | - |
| 308 | if (range.isValid() && range.model()) { partially evaluated: range.isValid()| yes Evaluation Count:704 | no Evaluation Count:0 |
partially evaluated: range.model()| yes Evaluation Count:704 | no Evaluation Count:0 |
| 0-704 |
| 309 | const QModelIndex topLeft = range.topLeft(); executed (the execution status of this line is deduced): const QModelIndex topLeft = range.topLeft(); | - |
| 310 | const int bottom = range.bottom(); executed (the execution status of this line is deduced): const int bottom = range.bottom(); | - |
| 311 | const int right = range.right(); executed (the execution status of this line is deduced): const int right = range.right(); | - |
| 312 | for (int row = topLeft.row(); row <= bottom; ++row) { evaluated: row <= bottom| yes Evaluation Count:1657 | yes Evaluation Count:704 |
| 704-1657 |
| 313 | const QModelIndex columnLeader = topLeft.sibling(row, topLeft.column()); executed (the execution status of this line is deduced): const QModelIndex columnLeader = topLeft.sibling(row, topLeft.column()); | - |
| 314 | for (int column = topLeft.column(); column <= right; ++column) { evaluated: column <= right| yes Evaluation Count:3873 | yes Evaluation Count:1657 |
| 1657-3873 |
| 315 | QModelIndex index = columnLeader.sibling(row, column); executed (the execution status of this line is deduced): QModelIndex index = columnLeader.sibling(row, column); | - |
| 316 | Qt::ItemFlags flags = range.model()->flags(index); executed (the execution status of this line is deduced): Qt::ItemFlags flags = range.model()->flags(index); | - |
| 317 | if ((flags & Qt::ItemIsSelectable) && (flags & Qt::ItemIsEnabled)) evaluated: (flags & Qt::ItemIsSelectable)| yes Evaluation Count:3862 | yes Evaluation Count:11 |
evaluated: (flags & Qt::ItemIsEnabled)| yes Evaluation Count:3860 | yes Evaluation Count:2 |
| 2-3862 |
| 318 | result.push_back(index); executed: result.push_back(index);Execution Count:3860 | 3860 |
| 319 | } executed: }Execution Count:3873 | 3873 |
| 320 | } executed: }Execution Count:1657 | 1657 |
| 321 | } executed: }Execution Count:704 | 704 |
| 322 | } executed: }Execution Count:704 | 704 |
| 323 | | - |
| 324 | /*! | - |
| 325 | Returns true if the selection range contains no selectable item | - |
| 326 | \since 4.7 | - |
| 327 | */ | - |
| 328 | | - |
| 329 | bool QItemSelectionRange::isEmpty() const | - |
| 330 | { | - |
| 331 | if (!isValid() || !model()) partially evaluated: !isValid()| no Evaluation Count:0 | yes Evaluation Count:417 |
partially evaluated: !model()| no Evaluation Count:0 | yes Evaluation Count:417 |
| 0-417 |
| 332 | return true; never executed: return true; | 0 |
| 333 | | - |
| 334 | for (int column = left(); column <= right(); ++column) { partially evaluated: column <= right()| yes Evaluation Count:417 | no Evaluation Count:0 |
| 0-417 |
| 335 | for (int row = top(); row <= bottom(); ++row) { partially evaluated: row <= bottom()| yes Evaluation Count:417 | no Evaluation Count:0 |
| 0-417 |
| 336 | QModelIndex index = model()->index(row, column, parent()); executed (the execution status of this line is deduced): QModelIndex index = model()->index(row, column, parent()); | - |
| 337 | Qt::ItemFlags flags = model()->flags(index); executed (the execution status of this line is deduced): Qt::ItemFlags flags = model()->flags(index); | - |
| 338 | if ((flags & Qt::ItemIsSelectable) && (flags & Qt::ItemIsEnabled)) partially evaluated: (flags & Qt::ItemIsSelectable)| yes Evaluation Count:417 | no Evaluation Count:0 |
partially evaluated: (flags & Qt::ItemIsEnabled)| yes Evaluation Count:417 | no Evaluation Count:0 |
| 0-417 |
| 339 | return false; executed: return false;Execution Count:417 | 417 |
| 340 | } | 0 |
| 341 | } | 0 |
| 342 | return true; never executed: return true; | 0 |
| 343 | } | - |
| 344 | | - |
| 345 | /*! | - |
| 346 | Returns the list of model index items stored in the selection. | - |
| 347 | */ | - |
| 348 | | - |
| 349 | QModelIndexList QItemSelectionRange::indexes() const | - |
| 350 | { | - |
| 351 | QModelIndexList result; never executed (the execution status of this line is deduced): QModelIndexList result; | - |
| 352 | indexesFromRange(*this, result); never executed (the execution status of this line is deduced): indexesFromRange(*this, result); | - |
| 353 | return result; never executed: return result; | 0 |
| 354 | } | - |
| 355 | | - |
| 356 | /*! | - |
| 357 | \class QItemSelection | - |
| 358 | \inmodule QtCore | - |
| 359 | | - |
| 360 | \brief The QItemSelection class manages information about selected items in a model. | - |
| 361 | | - |
| 362 | \ingroup model-view | - |
| 363 | | - |
| 364 | A QItemSelection describes the items in a model that have been | - |
| 365 | selected by the user. A QItemSelection is basically a list of | - |
| 366 | selection ranges, see QItemSelectionRange. It provides functions for | - |
| 367 | creating and manipulating selections, and selecting a range of items | - |
| 368 | from a model. | - |
| 369 | | - |
| 370 | The QItemSelection class is one of the \l{Model/View Classes} | - |
| 371 | and is part of Qt's \l{Model/View Programming}{model/view framework}. | - |
| 372 | | - |
| 373 | An item selection can be constructed and initialized to contain a | - |
| 374 | range of items from an existing model. The following example constructs | - |
| 375 | a selection that contains a range of items from the given \c model, | - |
| 376 | beginning at the \c topLeft, and ending at the \c bottomRight. | - |
| 377 | | - |
| 378 | \snippet code/src_gui_itemviews_qitemselectionmodel.cpp 0 | - |
| 379 | | - |
| 380 | An empty item selection can be constructed, and later populated as | - |
| 381 | required. So, if the model is going to be unavailable when we construct | - |
| 382 | the item selection, we can rewrite the above code in the following way: | - |
| 383 | | - |
| 384 | \snippet code/src_gui_itemviews_qitemselectionmodel.cpp 1 | - |
| 385 | | - |
| 386 | QItemSelection saves memory, and avoids unnecessary work, by working with | - |
| 387 | selection ranges rather than recording the model item index for each | - |
| 388 | item in the selection. Generally, an instance of this class will contain | - |
| 389 | a list of non-overlapping selection ranges. | - |
| 390 | | - |
| 391 | Use merge() to merge one item selection into another without making | - |
| 392 | overlapping ranges. Use split() to split one selection range into | - |
| 393 | smaller ranges based on a another selection range. | - |
| 394 | | - |
| 395 | \sa {Model/View Programming}, QItemSelectionModel | - |
| 396 | */ | - |
| 397 | | - |
| 398 | /*! | - |
| 399 | \fn QItemSelection::QItemSelection() | - |
| 400 | | - |
| 401 | Constructs an empty selection. | - |
| 402 | */ | - |
| 403 | | - |
| 404 | /*! | - |
| 405 | Constructs an item selection that extends from the top-left model item, | - |
| 406 | specified by the \a topLeft index, to the bottom-right item, specified | - |
| 407 | by \a bottomRight. | - |
| 408 | */ | - |
| 409 | QItemSelection::QItemSelection(const QModelIndex &topLeft, const QModelIndex &bottomRight) | - |
| 410 | { | - |
| 411 | select(topLeft, bottomRight); executed (the execution status of this line is deduced): select(topLeft, bottomRight); | - |
| 412 | } executed: }Execution Count:4308 | 4308 |
| 413 | | - |
| 414 | /*! | - |
| 415 | Adds the items in the range that extends from the top-left model | - |
| 416 | item, specified by the \a topLeft index, to the bottom-right item, | - |
| 417 | specified by \a bottomRight to the list. | - |
| 418 | | - |
| 419 | \note \a topLeft and \a bottomRight must have the same parent. | - |
| 420 | */ | - |
| 421 | void QItemSelection::select(const QModelIndex &topLeft, const QModelIndex &bottomRight) | - |
| 422 | { | - |
| 423 | if (!topLeft.isValid() || !bottomRight.isValid()) evaluated: !topLeft.isValid()| yes Evaluation Count:271 | yes Evaluation Count:4705 |
evaluated: !bottomRight.isValid()| yes Evaluation Count:1 | yes Evaluation Count:4704 |
| 1-4705 |
| 424 | return; executed: return;Execution Count:272 | 272 |
| 425 | | - |
| 426 | if ((topLeft.model() != bottomRight.model()) partially evaluated: (topLeft.model() != bottomRight.model())| no Evaluation Count:0 | yes Evaluation Count:4704 |
| 0-4704 |
| 427 | || topLeft.parent() != bottomRight.parent()) { evaluated: topLeft.parent() != bottomRight.parent()| yes Evaluation Count:1 | yes Evaluation Count:4703 |
| 1-4703 |
| 428 | qWarning("Can't select indexes from different model or with different parents"); executed (the execution status of this line is deduced): QMessageLogger("itemmodels/qitemselectionmodel.cpp", 428, __PRETTY_FUNCTION__).warning("Can't select indexes from different model or with different parents"); | - |
| 429 | return; executed: return;Execution Count:1 | 1 |
| 430 | } | - |
| 431 | if (topLeft.row() > bottomRight.row() || topLeft.column() > bottomRight.column()) { partially evaluated: topLeft.row() > bottomRight.row()| no Evaluation Count:0 | yes Evaluation Count:4703 |
partially evaluated: topLeft.column() > bottomRight.column()| no Evaluation Count:0 | yes Evaluation Count:4703 |
| 0-4703 |
| 432 | int top = qMin(topLeft.row(), bottomRight.row()); never executed (the execution status of this line is deduced): int top = qMin(topLeft.row(), bottomRight.row()); | - |
| 433 | int bottom = qMax(topLeft.row(), bottomRight.row()); never executed (the execution status of this line is deduced): int bottom = qMax(topLeft.row(), bottomRight.row()); | - |
| 434 | int left = qMin(topLeft.column(), bottomRight.column()); never executed (the execution status of this line is deduced): int left = qMin(topLeft.column(), bottomRight.column()); | - |
| 435 | int right = qMax(topLeft.column(), bottomRight.column()); never executed (the execution status of this line is deduced): int right = qMax(topLeft.column(), bottomRight.column()); | - |
| 436 | QModelIndex tl = topLeft.sibling(top, left); never executed (the execution status of this line is deduced): QModelIndex tl = topLeft.sibling(top, left); | - |
| 437 | QModelIndex br = bottomRight.sibling(bottom, right); never executed (the execution status of this line is deduced): QModelIndex br = bottomRight.sibling(bottom, right); | - |
| 438 | append(QItemSelectionRange(tl, br)); never executed (the execution status of this line is deduced): append(QItemSelectionRange(tl, br)); | - |
| 439 | return; | 0 |
| 440 | } | - |
| 441 | append(QItemSelectionRange(topLeft, bottomRight)); executed (the execution status of this line is deduced): append(QItemSelectionRange(topLeft, bottomRight)); | - |
| 442 | } executed: }Execution Count:4703 | 4703 |
| 443 | | - |
| 444 | /*! | - |
| 445 | Returns true if the selection contains the given \a index; otherwise | - |
| 446 | returns false. | - |
| 447 | */ | - |
| 448 | | - |
| 449 | bool QItemSelection::contains(const QModelIndex &index) const | - |
| 450 | { | - |
| 451 | if (index.flags() & Qt::ItemIsSelectable) { evaluated: index.flags() & Qt::ItemIsSelectable| yes Evaluation Count:8680 | yes Evaluation Count:7 |
| 7-8680 |
| 452 | QList<QItemSelectionRange>::const_iterator it = begin(); executed (the execution status of this line is deduced): QList<QItemSelectionRange>::const_iterator it = begin(); | - |
| 453 | for (; it != end(); ++it) evaluated: it != end()| yes Evaluation Count:10805 | yes Evaluation Count:7047 |
| 7047-10805 |
| 454 | if ((*it).contains(index)) evaluated: (*it).contains(index)| yes Evaluation Count:1633 | yes Evaluation Count:9172 |
| 1633-9172 |
| 455 | return true; executed: return true;Execution Count:1633 | 1633 |
| 456 | } executed: }Execution Count:7047 | 7047 |
| 457 | return false; executed: return false;Execution Count:7054 | 7054 |
| 458 | } | - |
| 459 | | - |
| 460 | /*! | - |
| 461 | Returns a list of model indexes that correspond to the selected items. | - |
| 462 | */ | - |
| 463 | | - |
| 464 | QModelIndexList QItemSelection::indexes() const | - |
| 465 | { | - |
| 466 | QModelIndexList result; executed (the execution status of this line is deduced): QModelIndexList result; | - |
| 467 | QList<QItemSelectionRange>::const_iterator it = begin(); executed (the execution status of this line is deduced): QList<QItemSelectionRange>::const_iterator it = begin(); | - |
| 468 | for (; it != end(); ++it) evaluated: it != end()| yes Evaluation Count:693 | yes Evaluation Count:779 |
| 693-779 |
| 469 | indexesFromRange(*it, result); executed: indexesFromRange(*it, result);Execution Count:693 | 693 |
| 470 | return result; executed: return result;Execution Count:779 | 779 |
| 471 | } | - |
| 472 | | - |
| 473 | static QVector<QPersistentModelIndex> qSelectionPersistentindexes(const QItemSelection &sel) | - |
| 474 | { | - |
| 475 | QVector<QPersistentModelIndex> result; executed (the execution status of this line is deduced): QVector<QPersistentModelIndex> result; | - |
| 476 | QList<QItemSelectionRange>::const_iterator it = sel.constBegin(); executed (the execution status of this line is deduced): QList<QItemSelectionRange>::const_iterator it = sel.constBegin(); | - |
| 477 | for (; it != sel.constEnd(); ++it) evaluated: it != sel.constEnd()| yes Evaluation Count:11 | yes Evaluation Count:4184 |
| 11-4184 |
| 478 | indexesFromRange(*it, result); executed: indexesFromRange(*it, result);Execution Count:11 | 11 |
| 479 | return result; executed: return result;Execution Count:4184 | 4184 |
| 480 | } | - |
| 481 | | - |
| 482 | static QVector<QPair<QPersistentModelIndex, uint> > qSelectionPersistentRowLengths(const QItemSelection &sel) | - |
| 483 | { | - |
| 484 | QVector<QPair<QPersistentModelIndex, uint> > result; executed (the execution status of this line is deduced): QVector<QPair<QPersistentModelIndex, uint> > result; | - |
| 485 | Q_FOREACH (const QItemSelectionRange &range, sel) executed (the execution status of this line is deduced): for (QForeachContainer<__typeof__(sel)> _container_(sel); !_container_.brk && _container_.i != _container_.e; __extension__ ({ ++_container_.brk; ++_container_.i; })) for (const QItemSelectionRange &range = *_container_.i;; __extension__ ({--_container_.brk; break;})) | - |
| 486 | rowLengthsFromRange(range, result); executed: rowLengthsFromRange(range, result);Execution Count:11 | 11 |
| 487 | return result; executed: return result;Execution Count:222 | 222 |
| 488 | } | - |
| 489 | | - |
| 490 | /*! | - |
| 491 | Merges the \a other selection with this QItemSelection using the | - |
| 492 | \a command given. This method guarantees that no ranges are overlapping. | - |
| 493 | | - |
| 494 | Note that only QItemSelectionModel::Select, | - |
| 495 | QItemSelectionModel::Deselect, and QItemSelectionModel::Toggle are | - |
| 496 | supported. | - |
| 497 | | - |
| 498 | \sa split() | - |
| 499 | */ | - |
| 500 | void QItemSelection::merge(const QItemSelection &other, QItemSelectionModel::SelectionFlags command) | - |
| 501 | { | - |
| 502 | if (other.isEmpty() || evaluated: other.isEmpty()| yes Evaluation Count:210598 | yes Evaluation Count:11755 |
| 11755-210598 |
| 503 | !(command & QItemSelectionModel::Select || evaluated: command & QItemSelectionModel::Select| yes Evaluation Count:10811 | yes Evaluation Count:944 |
| 944-10811 |
| 504 | command & QItemSelectionModel::Deselect || evaluated: command & QItemSelectionModel::Deselect| yes Evaluation Count:830 | yes Evaluation Count:114 |
| 114-830 |
| 505 | command & QItemSelectionModel::Toggle)) partially evaluated: command & QItemSelectionModel::Toggle| yes Evaluation Count:114 | no Evaluation Count:0 |
| 0-114 |
| 506 | return; executed: return;Execution Count:210598 | 210598 |
| 507 | | - |
| 508 | QItemSelection newSelection = other; executed (the execution status of this line is deduced): QItemSelection newSelection = other; | - |
| 509 | // Collect intersections | - |
| 510 | QItemSelection intersections; executed (the execution status of this line is deduced): QItemSelection intersections; | - |
| 511 | QItemSelection::iterator it = newSelection.begin(); executed (the execution status of this line is deduced): QItemSelection::iterator it = newSelection.begin(); | - |
| 512 | while (it != newSelection.end()) { evaluated: it != newSelection.end()| yes Evaluation Count:12205 | yes Evaluation Count:11755 |
| 11755-12205 |
| 513 | if (!(*it).isValid()) { evaluated: !(*it).isValid()| yes Evaluation Count:311 | yes Evaluation Count:11894 |
| 311-11894 |
| 514 | it = newSelection.erase(it); executed (the execution status of this line is deduced): it = newSelection.erase(it); | - |
| 515 | continue; executed: continue;Execution Count:311 | 311 |
| 516 | } | - |
| 517 | for (int t = 0; t < count(); ++t) { evaluated: t < count()| yes Evaluation Count:3436 | yes Evaluation Count:11894 |
| 3436-11894 |
| 518 | if ((*it).intersects(at(t))) evaluated: (*it).intersects(at(t))| yes Evaluation Count:846 | yes Evaluation Count:2590 |
| 846-2590 |
| 519 | intersections.append(at(t).intersected(*it)); executed: intersections.append(at(t).intersected(*it));Execution Count:846 | 846 |
| 520 | } executed: }Execution Count:3436 | 3436 |
| 521 | ++it; executed (the execution status of this line is deduced): ++it; | - |
| 522 | } executed: }Execution Count:11894 | 11894 |
| 523 | | - |
| 524 | // Split the old (and new) ranges using the intersections | - |
| 525 | for (int i = 0; i < intersections.count(); ++i) { // for each intersection evaluated: i < intersections.count()| yes Evaluation Count:846 | yes Evaluation Count:11755 |
| 846-11755 |
| 526 | for (int t = 0; t < count();) { // splitt each old range evaluated: t < count()| yes Evaluation Count:2939 | yes Evaluation Count:846 |
| 846-2939 |
| 527 | if (at(t).intersects(intersections.at(i))) { evaluated: at(t).intersects(intersections.at(i))| yes Evaluation Count:846 | yes Evaluation Count:2093 |
| 846-2093 |
| 528 | split(at(t), intersections.at(i), this); executed (the execution status of this line is deduced): split(at(t), intersections.at(i), this); | - |
| 529 | removeAt(t); executed (the execution status of this line is deduced): removeAt(t); | - |
| 530 | } else { executed: }Execution Count:846 | 846 |
| 531 | ++t; executed (the execution status of this line is deduced): ++t; | - |
| 532 | } executed: }Execution Count:2093 | 2093 |
| 533 | } | - |
| 534 | // only split newSelection if Toggle is specified | - |
| 535 | for (int n = 0; (command & QItemSelectionModel::Toggle) && n < newSelection.count();) { evaluated: (command & QItemSelectionModel::Toggle)| yes Evaluation Count:173 | yes Evaluation Count:765 |
evaluated: n < newSelection.count()| yes Evaluation Count:92 | yes Evaluation Count:81 |
| 81-765 |
| 536 | if (newSelection.at(n).intersects(intersections.at(i))) { evaluated: newSelection.at(n).intersects(intersections.at(i))| yes Evaluation Count:81 | yes Evaluation Count:11 |
| 11-81 |
| 537 | split(newSelection.at(n), intersections.at(i), &newSelection); executed (the execution status of this line is deduced): split(newSelection.at(n), intersections.at(i), &newSelection); | - |
| 538 | newSelection.removeAt(n); executed (the execution status of this line is deduced): newSelection.removeAt(n); | - |
| 539 | } else { executed: }Execution Count:81 | 81 |
| 540 | ++n; executed (the execution status of this line is deduced): ++n; | - |
| 541 | } executed: }Execution Count:11 | 11 |
| 542 | } | - |
| 543 | } executed: }Execution Count:846 | 846 |
| 544 | // do not add newSelection for Deselect | - |
| 545 | if (!(command & QItemSelectionModel::Deselect)) evaluated: !(command & QItemSelectionModel::Deselect)| yes Evaluation Count:10925 | yes Evaluation Count:830 |
| 830-10925 |
| 546 | operator+=(newSelection); executed: operator+=(newSelection);Execution Count:10925 | 10925 |
| 547 | } executed: }Execution Count:11755 | 11755 |
| 548 | | - |
| 549 | /*! | - |
| 550 | Splits the selection \a range using the selection \a other range. | - |
| 551 | Removes all items in \a other from \a range and puts the result in \a result. | - |
| 552 | This can be compared with the semantics of the \e subtract operation of a set. | - |
| 553 | \sa merge() | - |
| 554 | */ | - |
| 555 | | - |
| 556 | void QItemSelection::split(const QItemSelectionRange &range, | - |
| 557 | const QItemSelectionRange &other, QItemSelection *result) | - |
| 558 | { | - |
| 559 | if (range.parent() != other.parent() || range.model() != other.model()) partially evaluated: range.parent() != other.parent()| no Evaluation Count:0 | yes Evaluation Count:1550 |
evaluated: range.model() != other.model()| yes Evaluation Count:1 | yes Evaluation Count:1549 |
| 0-1550 |
| 560 | return; executed: return;Execution Count:1 | 1 |
| 561 | | - |
| 562 | QModelIndex parent = other.parent(); executed (the execution status of this line is deduced): QModelIndex parent = other.parent(); | - |
| 563 | int top = range.top(); executed (the execution status of this line is deduced): int top = range.top(); | - |
| 564 | int left = range.left(); executed (the execution status of this line is deduced): int left = range.left(); | - |
| 565 | int bottom = range.bottom(); executed (the execution status of this line is deduced): int bottom = range.bottom(); | - |
| 566 | int right = range.right(); executed (the execution status of this line is deduced): int right = range.right(); | - |
| 567 | int other_top = other.top(); executed (the execution status of this line is deduced): int other_top = other.top(); | - |
| 568 | int other_left = other.left(); executed (the execution status of this line is deduced): int other_left = other.left(); | - |
| 569 | int other_bottom = other.bottom(); executed (the execution status of this line is deduced): int other_bottom = other.bottom(); | - |
| 570 | int other_right = other.right(); executed (the execution status of this line is deduced): int other_right = other.right(); | - |
| 571 | const QAbstractItemModel *model = range.model(); executed (the execution status of this line is deduced): const QAbstractItemModel *model = range.model(); | - |
| 572 | Q_ASSERT(model); executed (the execution status of this line is deduced): qt_noop(); | - |
| 573 | if (other_top > top) { evaluated: other_top > top| yes Evaluation Count:209 | yes Evaluation Count:1340 |
| 209-1340 |
| 574 | QModelIndex tl = model->index(top, left, parent); executed (the execution status of this line is deduced): QModelIndex tl = model->index(top, left, parent); | - |
| 575 | QModelIndex br = model->index(other_top - 1, right, parent); executed (the execution status of this line is deduced): QModelIndex br = model->index(other_top - 1, right, parent); | - |
| 576 | result->append(QItemSelectionRange(tl, br)); executed (the execution status of this line is deduced): result->append(QItemSelectionRange(tl, br)); | - |
| 577 | top = other_top; executed (the execution status of this line is deduced): top = other_top; | - |
| 578 | } executed: }Execution Count:209 | 209 |
| 579 | if (other_bottom < bottom) { evaluated: other_bottom < bottom| yes Evaluation Count:258 | yes Evaluation Count:1291 |
| 258-1291 |
| 580 | QModelIndex tl = model->index(other_bottom + 1, left, parent); executed (the execution status of this line is deduced): QModelIndex tl = model->index(other_bottom + 1, left, parent); | - |
| 581 | QModelIndex br = model->index(bottom, right, parent); executed (the execution status of this line is deduced): QModelIndex br = model->index(bottom, right, parent); | - |
| 582 | result->append(QItemSelectionRange(tl, br)); executed (the execution status of this line is deduced): result->append(QItemSelectionRange(tl, br)); | - |
| 583 | bottom = other_bottom; executed (the execution status of this line is deduced): bottom = other_bottom; | - |
| 584 | } executed: }Execution Count:258 | 258 |
| 585 | if (other_left > left) { evaluated: other_left > left| yes Evaluation Count:205 | yes Evaluation Count:1344 |
| 205-1344 |
| 586 | QModelIndex tl = model->index(top, left, parent); executed (the execution status of this line is deduced): QModelIndex tl = model->index(top, left, parent); | - |
| 587 | QModelIndex br = model->index(bottom, other_left - 1, parent); executed (the execution status of this line is deduced): QModelIndex br = model->index(bottom, other_left - 1, parent); | - |
| 588 | result->append(QItemSelectionRange(tl, br)); executed (the execution status of this line is deduced): result->append(QItemSelectionRange(tl, br)); | - |
| 589 | left = other_left; executed (the execution status of this line is deduced): left = other_left; | - |
| 590 | } executed: }Execution Count:205 | 205 |
| 591 | if (other_right < right) { evaluated: other_right < right| yes Evaluation Count:265 | yes Evaluation Count:1284 |
| 265-1284 |
| 592 | QModelIndex tl = model->index(top, other_right + 1, parent); executed (the execution status of this line is deduced): QModelIndex tl = model->index(top, other_right + 1, parent); | - |
| 593 | QModelIndex br = model->index(bottom, right, parent); executed (the execution status of this line is deduced): QModelIndex br = model->index(bottom, right, parent); | - |
| 594 | result->append(QItemSelectionRange(tl, br)); executed (the execution status of this line is deduced): result->append(QItemSelectionRange(tl, br)); | - |
| 595 | right = other_right; executed (the execution status of this line is deduced): right = other_right; | - |
| 596 | } executed: }Execution Count:265 | 265 |
| 597 | } executed: }Execution Count:1549 | 1549 |
| 598 | | - |
| 599 | | - |
| 600 | void QItemSelectionModelPrivate::initModel(QAbstractItemModel *model) | - |
| 601 | { | - |
| 602 | this->model = model; executed (the execution status of this line is deduced): this->model = model; | - |
| 603 | if (model) { partially evaluated: model| yes Evaluation Count:4165 | no Evaluation Count:0 |
| 0-4165 |
| 604 | Q_Q(QItemSelectionModel); executed (the execution status of this line is deduced): QItemSelectionModel * const q = q_func(); | - |
| 605 | QObject::connect(model, SIGNAL(rowsAboutToBeRemoved(QModelIndex,int,int)), executed (the execution status of this line is deduced): QObject::connect(model, "2""rowsAboutToBeRemoved(QModelIndex,int,int)", | - |
| 606 | q, SLOT(_q_rowsAboutToBeRemoved(QModelIndex,int,int))); executed (the execution status of this line is deduced): q, "1""_q_rowsAboutToBeRemoved(QModelIndex,int,int)"); | - |
| 607 | QObject::connect(model, SIGNAL(columnsAboutToBeRemoved(QModelIndex,int,int)), executed (the execution status of this line is deduced): QObject::connect(model, "2""columnsAboutToBeRemoved(QModelIndex,int,int)", | - |
| 608 | q, SLOT(_q_columnsAboutToBeRemoved(QModelIndex,int,int))); executed (the execution status of this line is deduced): q, "1""_q_columnsAboutToBeRemoved(QModelIndex,int,int)"); | - |
| 609 | QObject::connect(model, SIGNAL(rowsAboutToBeInserted(QModelIndex,int,int)), executed (the execution status of this line is deduced): QObject::connect(model, "2""rowsAboutToBeInserted(QModelIndex,int,int)", | - |
| 610 | q, SLOT(_q_rowsAboutToBeInserted(QModelIndex,int,int))); executed (the execution status of this line is deduced): q, "1""_q_rowsAboutToBeInserted(QModelIndex,int,int)"); | - |
| 611 | QObject::connect(model, SIGNAL(columnsAboutToBeInserted(QModelIndex,int,int)), executed (the execution status of this line is deduced): QObject::connect(model, "2""columnsAboutToBeInserted(QModelIndex,int,int)", | - |
| 612 | q, SLOT(_q_columnsAboutToBeInserted(QModelIndex,int,int))); executed (the execution status of this line is deduced): q, "1""_q_columnsAboutToBeInserted(QModelIndex,int,int)"); | - |
| 613 | QObject::connect(model, SIGNAL(rowsAboutToBeMoved(QModelIndex,int,int,QModelIndex,int)), executed (the execution status of this line is deduced): QObject::connect(model, "2""rowsAboutToBeMoved(QModelIndex,int,int,QModelIndex,int)", | - |
| 614 | q, SLOT(_q_layoutAboutToBeChanged())); executed (the execution status of this line is deduced): q, "1""_q_layoutAboutToBeChanged()"); | - |
| 615 | QObject::connect(model, SIGNAL(columnsAboutToBeMoved(QModelIndex,int,int,QModelIndex,int)), executed (the execution status of this line is deduced): QObject::connect(model, "2""columnsAboutToBeMoved(QModelIndex,int,int,QModelIndex,int)", | - |
| 616 | q, SLOT(_q_layoutAboutToBeChanged())); executed (the execution status of this line is deduced): q, "1""_q_layoutAboutToBeChanged()"); | - |
| 617 | QObject::connect(model, SIGNAL(rowsMoved(QModelIndex,int,int,QModelIndex,int)), executed (the execution status of this line is deduced): QObject::connect(model, "2""rowsMoved(QModelIndex,int,int,QModelIndex,int)", | - |
| 618 | q, SLOT(_q_layoutChanged())); executed (the execution status of this line is deduced): q, "1""_q_layoutChanged()"); | - |
| 619 | QObject::connect(model, SIGNAL(columnsMoved(QModelIndex,int,int,QModelIndex,int)), executed (the execution status of this line is deduced): QObject::connect(model, "2""columnsMoved(QModelIndex,int,int,QModelIndex,int)", | - |
| 620 | q, SLOT(_q_layoutChanged())); executed (the execution status of this line is deduced): q, "1""_q_layoutChanged()"); | - |
| 621 | QObject::connect(model, SIGNAL(layoutAboutToBeChanged(QList<QPersistentModelIndex>,QAbstractItemModel::LayoutChangeHint)), executed (the execution status of this line is deduced): QObject::connect(model, "2""layoutAboutToBeChanged(QList<QPersistentModelIndex>,QAbstractItemModel::LayoutChangeHint)", | - |
| 622 | q, SLOT(_q_layoutAboutToBeChanged(QList<QPersistentModelIndex>,QAbstractItemModel::LayoutChangeHint))); executed (the execution status of this line is deduced): q, "1""_q_layoutAboutToBeChanged(QList<QPersistentModelIndex>,QAbstractItemModel::LayoutChangeHint)"); | - |
| 623 | QObject::connect(model, SIGNAL(layoutChanged(QList<QPersistentModelIndex>,QAbstractItemModel::LayoutChangeHint)), executed (the execution status of this line is deduced): QObject::connect(model, "2""layoutChanged(QList<QPersistentModelIndex>,QAbstractItemModel::LayoutChangeHint)", | - |
| 624 | q, SLOT(_q_layoutChanged(QList<QPersistentModelIndex>,QAbstractItemModel::LayoutChangeHint))); executed (the execution status of this line is deduced): q, "1""_q_layoutChanged(QList<QPersistentModelIndex>,QAbstractItemModel::LayoutChangeHint)"); | - |
| 625 | } executed: }Execution Count:4165 | 4165 |
| 626 | } executed: }Execution Count:4165 | 4165 |
| 627 | | - |
| 628 | /*! | - |
| 629 | \internal | - |
| 630 | | - |
| 631 | returns a QItemSelection where all ranges have been expanded to: | - |
| 632 | Rows: left: 0 and right: columnCount()-1 | - |
| 633 | Columns: top: 0 and bottom: rowCount()-1 | - |
| 634 | */ | - |
| 635 | | - |
| 636 | QItemSelection QItemSelectionModelPrivate::expandSelection(const QItemSelection &selection, | - |
| 637 | QItemSelectionModel::SelectionFlags command) const | - |
| 638 | { | - |
| 639 | if (selection.isEmpty() && !((command & QItemSelectionModel::Rows) || evaluated: selection.isEmpty()| yes Evaluation Count:11 | yes Evaluation Count:472 |
partially evaluated: (command & QItemSelectionModel::Rows)| yes Evaluation Count:11 | no Evaluation Count:0 |
| 0-472 |
| 640 | (command & QItemSelectionModel::Columns))) never evaluated: (command & QItemSelectionModel::Columns) | 0 |
| 641 | return selection; never executed: return selection; | 0 |
| 642 | | - |
| 643 | QItemSelection expanded; executed (the execution status of this line is deduced): QItemSelection expanded; | - |
| 644 | if (command & QItemSelectionModel::Rows) { evaluated: command & QItemSelectionModel::Rows| yes Evaluation Count:461 | yes Evaluation Count:22 |
| 22-461 |
| 645 | for (int i = 0; i < selection.count(); ++i) { evaluated: i < selection.count()| yes Evaluation Count:455 | yes Evaluation Count:461 |
| 455-461 |
| 646 | QModelIndex parent = selection.at(i).parent(); executed (the execution status of this line is deduced): QModelIndex parent = selection.at(i).parent(); | - |
| 647 | int colCount = model->columnCount(parent); executed (the execution status of this line is deduced): int colCount = model->columnCount(parent); | - |
| 648 | QModelIndex tl = model->index(selection.at(i).top(), 0, parent); executed (the execution status of this line is deduced): QModelIndex tl = model->index(selection.at(i).top(), 0, parent); | - |
| 649 | QModelIndex br = model->index(selection.at(i).bottom(), colCount - 1, parent); executed (the execution status of this line is deduced): QModelIndex br = model->index(selection.at(i).bottom(), colCount - 1, parent); | - |
| 650 | //we need to merge because the same row could have already been inserted | - |
| 651 | expanded.merge(QItemSelection(tl, br), QItemSelectionModel::Select); executed (the execution status of this line is deduced): expanded.merge(QItemSelection(tl, br), QItemSelectionModel::Select); | - |
| 652 | } executed: }Execution Count:455 | 455 |
| 653 | } executed: }Execution Count:461 | 461 |
| 654 | if (command & QItemSelectionModel::Columns) { evaluated: command & QItemSelectionModel::Columns| yes Evaluation Count:22 | yes Evaluation Count:461 |
| 22-461 |
| 655 | for (int i = 0; i < selection.count(); ++i) { evaluated: i < selection.count()| yes Evaluation Count:22 | yes Evaluation Count:22 |
| 22 |
| 656 | QModelIndex parent = selection.at(i).parent(); executed (the execution status of this line is deduced): QModelIndex parent = selection.at(i).parent(); | - |
| 657 | int rowCount = model->rowCount(parent); executed (the execution status of this line is deduced): int rowCount = model->rowCount(parent); | - |
| 658 | QModelIndex tl = model->index(0, selection.at(i).left(), parent); executed (the execution status of this line is deduced): QModelIndex tl = model->index(0, selection.at(i).left(), parent); | - |
| 659 | QModelIndex br = model->index(rowCount - 1, selection.at(i).right(), parent); executed (the execution status of this line is deduced): QModelIndex br = model->index(rowCount - 1, selection.at(i).right(), parent); | - |
| 660 | //we need to merge because the same column could have already been inserted | - |
| 661 | expanded.merge(QItemSelection(tl, br), QItemSelectionModel::Select); executed (the execution status of this line is deduced): expanded.merge(QItemSelection(tl, br), QItemSelectionModel::Select); | - |
| 662 | } executed: }Execution Count:22 | 22 |
| 663 | } executed: }Execution Count:22 | 22 |
| 664 | return expanded; executed: return expanded;Execution Count:483 | 483 |
| 665 | } | - |
| 666 | | - |
| 667 | /*! | - |
| 668 | \internal | - |
| 669 | */ | - |
| 670 | void QItemSelectionModelPrivate::_q_rowsAboutToBeRemoved(const QModelIndex &parent, | - |
| 671 | int start, int end) | - |
| 672 | { | - |
| 673 | Q_Q(QItemSelectionModel); executed (the execution status of this line is deduced): QItemSelectionModel * const q = q_func(); | - |
| 674 | finalize(); executed (the execution status of this line is deduced): finalize(); | - |
| 675 | | - |
| 676 | // update current index | - |
| 677 | if (currentIndex.isValid() && parent == currentIndex.parent() evaluated: currentIndex.isValid()| yes Evaluation Count:28 | yes Evaluation Count:3104 |
evaluated: parent == currentIndex.parent()| yes Evaluation Count:15 | yes Evaluation Count:13 |
| 13-3104 |
| 678 | && currentIndex.row() >= start && currentIndex.row() <= end) { evaluated: currentIndex.row() >= start| yes Evaluation Count:10 | yes Evaluation Count:5 |
evaluated: currentIndex.row() <= end| yes Evaluation Count:4 | yes Evaluation Count:6 |
| 4-10 |
| 679 | QModelIndex old = currentIndex; executed (the execution status of this line is deduced): QModelIndex old = currentIndex; | - |
| 680 | if (start > 0) // there are rows left above the change evaluated: start > 0| yes Evaluation Count:1 | yes Evaluation Count:3 |
| 1-3 |
| 681 | currentIndex = model->index(start - 1, old.column(), parent); executed: currentIndex = model->index(start - 1, old.column(), parent);Execution Count:1 | 1 |
| 682 | else if (model && end < model->rowCount(parent) - 1) // there are rows left below the change partially evaluated: model| yes Evaluation Count:3 | no Evaluation Count:0 |
partially evaluated: end < model->rowCount(parent) - 1| no Evaluation Count:0 | yes Evaluation Count:3 |
| 0-3 |
| 683 | currentIndex = model->index(end + 1, old.column(), parent); never executed: currentIndex = model->index(end + 1, old.column(), parent); | 0 |
| 684 | else // there are no rows left in the table | - |
| 685 | currentIndex = QModelIndex(); executed: currentIndex = QModelIndex();Execution Count:3 | 3 |
| 686 | emit q->currentChanged(currentIndex, old); executed (the execution status of this line is deduced): q->currentChanged(currentIndex, old); | - |
| 687 | emit q->currentRowChanged(currentIndex, old); executed (the execution status of this line is deduced): q->currentRowChanged(currentIndex, old); | - |
| 688 | if (currentIndex.column() != old.column()) evaluated: currentIndex.column() != old.column()| yes Evaluation Count:3 | yes Evaluation Count:1 |
| 1-3 |
| 689 | emit q->currentColumnChanged(currentIndex, old); executed: q->currentColumnChanged(currentIndex, old);Execution Count:3 | 3 |
| 690 | } executed: }Execution Count:4 | 4 |
| 691 | | - |
| 692 | QItemSelection deselected; executed (the execution status of this line is deduced): QItemSelection deselected; | - |
| 693 | QItemSelection newParts; executed (the execution status of this line is deduced): QItemSelection newParts; | - |
| 694 | QItemSelection::iterator it = ranges.begin(); executed (the execution status of this line is deduced): QItemSelection::iterator it = ranges.begin(); | - |
| 695 | while (it != ranges.end()) { evaluated: it != ranges.end()| yes Evaluation Count:156 | yes Evaluation Count:3132 |
| 156-3132 |
| 696 | if (it->topLeft().parent() != parent) { // Check parents until reaching root or contained in range evaluated: it->topLeft().parent() != parent| yes Evaluation Count:13 | yes Evaluation Count:143 |
| 13-143 |
| 697 | QModelIndex itParent = it->topLeft().parent(); executed (the execution status of this line is deduced): QModelIndex itParent = it->topLeft().parent(); | - |
| 698 | while (itParent.isValid() && itParent.parent() != parent) evaluated: itParent.isValid()| yes Evaluation Count:7 | yes Evaluation Count:11 |
evaluated: itParent.parent() != parent| yes Evaluation Count:5 | yes Evaluation Count:2 |
| 2-11 |
| 699 | itParent = itParent.parent(); executed: itParent = itParent.parent();Execution Count:5 | 5 |
| 700 | | - |
| 701 | if (itParent.isValid() && start <= itParent.row() && itParent.row() <= end) { evaluated: itParent.isValid()| yes Evaluation Count:2 | yes Evaluation Count:11 |
partially evaluated: start <= itParent.row()| yes Evaluation Count:2 | no Evaluation Count:0 |
partially evaluated: itParent.row() <= end| yes Evaluation Count:2 | no Evaluation Count:0 |
| 0-11 |
| 702 | deselected.append(*it); executed (the execution status of this line is deduced): deselected.append(*it); | - |
| 703 | it = ranges.erase(it); executed (the execution status of this line is deduced): it = ranges.erase(it); | - |
| 704 | } else { executed: }Execution Count:2 | 2 |
| 705 | ++it; executed (the execution status of this line is deduced): ++it; | - |
| 706 | } executed: }Execution Count:11 | 11 |
| 707 | } else if (start <= it->bottom() && it->bottom() <= end // Full inclusion evaluated: start <= it->bottom()| yes Evaluation Count:131 | yes Evaluation Count:12 |
evaluated: it->bottom() <= end| yes Evaluation Count:118 | yes Evaluation Count:13 |
| 12-131 |
| 708 | && start <= it->top() && it->top() <= end) { evaluated: start <= it->top()| yes Evaluation Count:117 | yes Evaluation Count:1 |
partially evaluated: it->top() <= end| yes Evaluation Count:117 | no Evaluation Count:0 |
| 0-117 |
| 709 | deselected.append(*it); executed (the execution status of this line is deduced): deselected.append(*it); | - |
| 710 | it = ranges.erase(it); executed (the execution status of this line is deduced): it = ranges.erase(it); | - |
| 711 | } else if (start <= it->top() && it->top() <= end) { // Top intersection executed: }Execution Count:117 evaluated: start <= it->top()| yes Evaluation Count:11 | yes Evaluation Count:15 |
evaluated: it->top() <= end| yes Evaluation Count:2 | yes Evaluation Count:9 |
| 2-117 |
| 712 | deselected.append(QItemSelectionRange(it->topLeft(), model->index(end, it->left(), it->parent()))); executed (the execution status of this line is deduced): deselected.append(QItemSelectionRange(it->topLeft(), model->index(end, it->left(), it->parent()))); | - |
| 713 | *it = QItemSelectionRange(model->index(end + 1, it->left(), it->parent()), it->bottomRight()); executed (the execution status of this line is deduced): *it = QItemSelectionRange(model->index(end + 1, it->left(), it->parent()), it->bottomRight()); | - |
| 714 | ++it; executed (the execution status of this line is deduced): ++it; | - |
| 715 | } else if (start <= it->bottom() && it->bottom() <= end) { // Bottom intersection executed: }Execution Count:2 evaluated: start <= it->bottom()| yes Evaluation Count:12 | yes Evaluation Count:12 |
evaluated: it->bottom() <= end| yes Evaluation Count:1 | yes Evaluation Count:11 |
| 1-12 |
| 716 | deselected.append(QItemSelectionRange(model->index(start, it->right(), it->parent()), it->bottomRight())); executed (the execution status of this line is deduced): deselected.append(QItemSelectionRange(model->index(start, it->right(), it->parent()), it->bottomRight())); | - |
| 717 | *it = QItemSelectionRange(it->topLeft(), model->index(start - 1, it->right(), it->parent())); executed (the execution status of this line is deduced): *it = QItemSelectionRange(it->topLeft(), model->index(start - 1, it->right(), it->parent())); | - |
| 718 | ++it; executed (the execution status of this line is deduced): ++it; | - |
| 719 | } else if (it->top() < start && end < it->bottom()) { // Middle intersection executed: }Execution Count:1 evaluated: it->top() < start| yes Evaluation Count:14 | yes Evaluation Count:9 |
evaluated: end < it->bottom()| yes Evaluation Count:2 | yes Evaluation Count:12 |
| 1-14 |
| 720 | // If the parent contains (1, 2, 3, 4, 5, 6, 7, 8) and [3, 4, 5, 6] is selected, | - |
| 721 | // and [4, 5] is removed, we need to split [3, 4, 5, 6] into [3], [4, 5] and [6]. | - |
| 722 | // [4, 5] is appended to deselected, and [3] and [6] remain part of the selection | - |
| 723 | // in ranges. | - |
| 724 | const QItemSelectionRange removedRange(model->index(start, it->right(), it->parent()), executed (the execution status of this line is deduced): const QItemSelectionRange removedRange(model->index(start, it->right(), it->parent()), | - |
| 725 | model->index(end, it->left(), it->parent())); executed (the execution status of this line is deduced): model->index(end, it->left(), it->parent())); | - |
| 726 | deselected.append(removedRange); executed (the execution status of this line is deduced): deselected.append(removedRange); | - |
| 727 | QItemSelection::split(*it, removedRange, &newParts); executed (the execution status of this line is deduced): QItemSelection::split(*it, removedRange, &newParts); | - |
| 728 | it = ranges.erase(it); executed (the execution status of this line is deduced): it = ranges.erase(it); | - |
| 729 | } else executed: }Execution Count:2 | 2 |
| 730 | ++it; executed: ++it;Execution Count:21 | 21 |
| 731 | } | - |
| 732 | ranges.append(newParts); executed (the execution status of this line is deduced): ranges.append(newParts); | - |
| 733 | | - |
| 734 | if (!deselected.isEmpty()) evaluated: !deselected.isEmpty()| yes Evaluation Count:124 | yes Evaluation Count:3008 |
| 124-3008 |
| 735 | emit q->selectionChanged(QItemSelection(), deselected); executed: q->selectionChanged(QItemSelection(), deselected);Execution Count:124 | 124 |
| 736 | } executed: }Execution Count:3132 | 3132 |
| 737 | | - |
| 738 | /*! | - |
| 739 | \internal | - |
| 740 | */ | - |
| 741 | void QItemSelectionModelPrivate::_q_columnsAboutToBeRemoved(const QModelIndex &parent, | - |
| 742 | int start, int end) | - |
| 743 | { | - |
| 744 | Q_Q(QItemSelectionModel); executed (the execution status of this line is deduced): QItemSelectionModel * const q = q_func(); | - |
| 745 | | - |
| 746 | // update current index | - |
| 747 | if (currentIndex.isValid() && parent == currentIndex.parent() evaluated: currentIndex.isValid()| yes Evaluation Count:8 | yes Evaluation Count:272 |
partially evaluated: parent == currentIndex.parent()| yes Evaluation Count:8 | no Evaluation Count:0 |
| 0-272 |
| 748 | && currentIndex.column() >= start && currentIndex.column() <= end) { evaluated: currentIndex.column() >= start| yes Evaluation Count:7 | yes Evaluation Count:1 |
evaluated: currentIndex.column() <= end| yes Evaluation Count:2 | yes Evaluation Count:5 |
| 1-7 |
| 749 | QModelIndex old = currentIndex; executed (the execution status of this line is deduced): QModelIndex old = currentIndex; | - |
| 750 | if (start > 0) // there are columns to the left of the change evaluated: start > 0| yes Evaluation Count:1 | yes Evaluation Count:1 |
| 1 |
| 751 | currentIndex = model->index(old.row(), start - 1, parent); executed: currentIndex = model->index(old.row(), start - 1, parent);Execution Count:1 | 1 |
| 752 | else if (model && end < model->columnCount() - 1) // there are columns to the right of the change partially evaluated: model| yes Evaluation Count:1 | no Evaluation Count:0 |
partially evaluated: end < model->columnCount() - 1| yes Evaluation Count:1 | no Evaluation Count:0 |
| 0-1 |
| 753 | currentIndex = model->index(old.row(), end + 1, parent); executed: currentIndex = model->index(old.row(), end + 1, parent);Execution Count:1 | 1 |
| 754 | else // there are no columns left in the table | - |
| 755 | currentIndex = QModelIndex(); never executed: currentIndex = QModelIndex(); | 0 |
| 756 | emit q->currentChanged(currentIndex, old); executed (the execution status of this line is deduced): q->currentChanged(currentIndex, old); | - |
| 757 | if (currentIndex.row() != old.row()) partially evaluated: currentIndex.row() != old.row()| no Evaluation Count:0 | yes Evaluation Count:2 |
| 0-2 |
| 758 | emit q->currentRowChanged(currentIndex, old); never executed: q->currentRowChanged(currentIndex, old); | 0 |
| 759 | emit q->currentColumnChanged(currentIndex, old); executed (the execution status of this line is deduced): q->currentColumnChanged(currentIndex, old); | - |
| 760 | } executed: }Execution Count:2 | 2 |
| 761 | | - |
| 762 | // update selections | - |
| 763 | QModelIndex tl = model->index(0, start, parent); executed (the execution status of this line is deduced): QModelIndex tl = model->index(0, start, parent); | - |
| 764 | QModelIndex br = model->index(model->rowCount(parent) - 1, end, parent); executed (the execution status of this line is deduced): QModelIndex br = model->index(model->rowCount(parent) - 1, end, parent); | - |
| 765 | q->select(QItemSelection(tl, br), QItemSelectionModel::Deselect); executed (the execution status of this line is deduced): q->select(QItemSelection(tl, br), QItemSelectionModel::Deselect); | - |
| 766 | finalize(); executed (the execution status of this line is deduced): finalize(); | - |
| 767 | } executed: }Execution Count:280 | 280 |
| 768 | | - |
| 769 | /*! | - |
| 770 | \internal | - |
| 771 | | - |
| 772 | Split selection ranges if columns are about to be inserted in the middle. | - |
| 773 | */ | - |
| 774 | void QItemSelectionModelPrivate::_q_columnsAboutToBeInserted(const QModelIndex &parent, | - |
| 775 | int start, int end) | - |
| 776 | { | - |
| 777 | Q_UNUSED(end); executed (the execution status of this line is deduced): (void)end;; | - |
| 778 | finalize(); executed (the execution status of this line is deduced): finalize(); | - |
| 779 | QList<QItemSelectionRange> split; executed (the execution status of this line is deduced): QList<QItemSelectionRange> split; | - |
| 780 | QList<QItemSelectionRange>::iterator it = ranges.begin(); executed (the execution status of this line is deduced): QList<QItemSelectionRange>::iterator it = ranges.begin(); | - |
| 781 | for (; it != ranges.end(); ) { partially evaluated: it != ranges.end()| no Evaluation Count:0 | yes Evaluation Count:833 |
| 0-833 |
| 782 | if ((*it).isValid() && (*it).parent() == parent never evaluated: (*it).isValid() never evaluated: (*it).parent() == parent | 0 |
| 783 | && (*it).left() < start && (*it).right() >= start) { never evaluated: (*it).left() < start never evaluated: (*it).right() >= start | 0 |
| 784 | QModelIndex bottomMiddle = model->index((*it).bottom(), start - 1, (*it).parent()); never executed (the execution status of this line is deduced): QModelIndex bottomMiddle = model->index((*it).bottom(), start - 1, (*it).parent()); | - |
| 785 | QItemSelectionRange left((*it).topLeft(), bottomMiddle); never executed (the execution status of this line is deduced): QItemSelectionRange left((*it).topLeft(), bottomMiddle); | - |
| 786 | QModelIndex topMiddle = model->index((*it).top(), start, (*it).parent()); never executed (the execution status of this line is deduced): QModelIndex topMiddle = model->index((*it).top(), start, (*it).parent()); | - |
| 787 | QItemSelectionRange right(topMiddle, (*it).bottomRight()); never executed (the execution status of this line is deduced): QItemSelectionRange right(topMiddle, (*it).bottomRight()); | - |
| 788 | it = ranges.erase(it); never executed (the execution status of this line is deduced): it = ranges.erase(it); | - |
| 789 | split.append(left); never executed (the execution status of this line is deduced): split.append(left); | - |
| 790 | split.append(right); never executed (the execution status of this line is deduced): split.append(right); | - |
| 791 | } else { | 0 |
| 792 | ++it; never executed (the execution status of this line is deduced): ++it; | - |
| 793 | } | 0 |
| 794 | } | - |
| 795 | ranges += split; executed (the execution status of this line is deduced): ranges += split; | - |
| 796 | } executed: }Execution Count:833 | 833 |
| 797 | | - |
| 798 | /*! | - |
| 799 | \internal | - |
| 800 | | - |
| 801 | Split selection ranges if rows are about to be inserted in the middle. | - |
| 802 | */ | - |
| 803 | void QItemSelectionModelPrivate::_q_rowsAboutToBeInserted(const QModelIndex &parent, | - |
| 804 | int start, int end) | - |
| 805 | { | - |
| 806 | Q_UNUSED(end); executed (the execution status of this line is deduced): (void)end;; | - |
| 807 | finalize(); executed (the execution status of this line is deduced): finalize(); | - |
| 808 | QList<QItemSelectionRange> split; executed (the execution status of this line is deduced): QList<QItemSelectionRange> split; | - |
| 809 | QList<QItemSelectionRange>::iterator it = ranges.begin(); executed (the execution status of this line is deduced): QList<QItemSelectionRange>::iterator it = ranges.begin(); | - |
| 810 | for (; it != ranges.end(); ) { evaluated: it != ranges.end()| yes Evaluation Count:3034 | yes Evaluation Count:195772 |
| 3034-195772 |
| 811 | if ((*it).isValid() && (*it).parent() == parent partially evaluated: (*it).isValid()| yes Evaluation Count:3034 | no Evaluation Count:0 |
evaluated: (*it).parent() == parent| yes Evaluation Count:316 | yes Evaluation Count:2718 |
| 0-3034 |
| 812 | && (*it).top() < start && (*it).bottom() >= start) { evaluated: (*it).top() < start| yes Evaluation Count:312 | yes Evaluation Count:4 |
evaluated: (*it).bottom() >= start| yes Evaluation Count:3 | yes Evaluation Count:309 |
| 3-312 |
| 813 | QModelIndex middleRight = model->index(start - 1, (*it).right(), (*it).parent()); executed (the execution status of this line is deduced): QModelIndex middleRight = model->index(start - 1, (*it).right(), (*it).parent()); | - |
| 814 | QItemSelectionRange top((*it).topLeft(), middleRight); executed (the execution status of this line is deduced): QItemSelectionRange top((*it).topLeft(), middleRight); | - |
| 815 | QModelIndex middleLeft = model->index(start, (*it).left(), (*it).parent()); executed (the execution status of this line is deduced): QModelIndex middleLeft = model->index(start, (*it).left(), (*it).parent()); | - |
| 816 | QItemSelectionRange bottom(middleLeft, (*it).bottomRight()); executed (the execution status of this line is deduced): QItemSelectionRange bottom(middleLeft, (*it).bottomRight()); | - |
| 817 | it = ranges.erase(it); executed (the execution status of this line is deduced): it = ranges.erase(it); | - |
| 818 | split.append(top); executed (the execution status of this line is deduced): split.append(top); | - |
| 819 | split.append(bottom); executed (the execution status of this line is deduced): split.append(bottom); | - |
| 820 | } else { executed: }Execution Count:3 | 3 |
| 821 | ++it; executed (the execution status of this line is deduced): ++it; | - |
| 822 | } executed: }Execution Count:3031 | 3031 |
| 823 | } | - |
| 824 | ranges += split; executed (the execution status of this line is deduced): ranges += split; | - |
| 825 | } executed: }Execution Count:195772 | 195772 |
| 826 | | - |
| 827 | /*! | - |
| 828 | \internal | - |
| 829 | | - |
| 830 | Split selection into individual (persistent) indexes. This is done in | - |
| 831 | preparation for the layoutChanged() signal, where the indexes can be | - |
| 832 | merged again. | - |
| 833 | */ | - |
| 834 | void QItemSelectionModelPrivate::_q_layoutAboutToBeChanged(const QList<QPersistentModelIndex> &, QAbstractItemModel::LayoutChangeHint hint) | - |
| 835 | { | - |
| 836 | savedPersistentIndexes.clear(); executed (the execution status of this line is deduced): savedPersistentIndexes.clear(); | - |
| 837 | savedPersistentCurrentIndexes.clear(); executed (the execution status of this line is deduced): savedPersistentCurrentIndexes.clear(); | - |
| 838 | savedPersistentRowLengths.clear(); executed (the execution status of this line is deduced): savedPersistentRowLengths.clear(); | - |
| 839 | savedPersistentCurrentRowLengths.clear(); executed (the execution status of this line is deduced): savedPersistentCurrentRowLengths.clear(); | - |
| 840 | | - |
| 841 | // optimization for when all indexes are selected | - |
| 842 | // (only if there is lots of items (1000) because this is not entirely correct) | - |
| 843 | if (ranges.isEmpty() && currentSelection.count() == 1) { evaluated: ranges.isEmpty()| yes Evaluation Count:2196 | yes Evaluation Count:7 |
evaluated: currentSelection.count() == 1| yes Evaluation Count:11 | yes Evaluation Count:2185 |
| 7-2196 |
| 844 | QItemSelectionRange range = currentSelection.first(); executed (the execution status of this line is deduced): QItemSelectionRange range = currentSelection.first(); | - |
| 845 | QModelIndex parent = range.parent(); executed (the execution status of this line is deduced): QModelIndex parent = range.parent(); | - |
| 846 | tableRowCount = model->rowCount(parent); executed (the execution status of this line is deduced): tableRowCount = model->rowCount(parent); | - |
| 847 | tableColCount = model->columnCount(parent); executed (the execution status of this line is deduced): tableColCount = model->columnCount(parent); | - |
| 848 | if (tableRowCount * tableColCount > 1000 partially evaluated: tableRowCount * tableColCount > 1000| no Evaluation Count:0 | yes Evaluation Count:11 |
| 0-11 |
| 849 | && range.top() == 0 never evaluated: range.top() == 0 | 0 |
| 850 | && range.left() == 0 never evaluated: range.left() == 0 | 0 |
| 851 | && range.bottom() == tableRowCount - 1 never evaluated: range.bottom() == tableRowCount - 1 | 0 |
| 852 | && range.right() == tableColCount - 1) { never evaluated: range.right() == tableColCount - 1 | 0 |
| 853 | tableSelected = true; never executed (the execution status of this line is deduced): tableSelected = true; | - |
| 854 | tableParent = parent; never executed (the execution status of this line is deduced): tableParent = parent; | - |
| 855 | return; | 0 |
| 856 | } | - |
| 857 | } executed: }Execution Count:11 | 11 |
| 858 | tableSelected = false; executed (the execution status of this line is deduced): tableSelected = false; | - |
| 859 | | - |
| 860 | if (hint == QAbstractItemModel::VerticalSortHint) { evaluated: hint == QAbstractItemModel::VerticalSortHint| yes Evaluation Count:111 | yes Evaluation Count:2092 |
| 111-2092 |
| 861 | // Special case when we know we're sorting vertically. We can assume that all indexes for columns | - |
| 862 | // are displaced the same way, and therefore we only need to track an index from one column per | - |
| 863 | // row with a QPersistentModelIndex together with the length of items to the right of it | - |
| 864 | // which are displaced the same way. | - |
| 865 | // An algorithm which contains the same assumption is used to process layoutChanged. | - |
| 866 | savedPersistentRowLengths = qSelectionPersistentRowLengths(ranges); executed (the execution status of this line is deduced): savedPersistentRowLengths = qSelectionPersistentRowLengths(ranges); | - |
| 867 | savedPersistentCurrentRowLengths = qSelectionPersistentRowLengths(currentSelection); executed (the execution status of this line is deduced): savedPersistentCurrentRowLengths = qSelectionPersistentRowLengths(currentSelection); | - |
| 868 | } else { executed: }Execution Count:111 | 111 |
| 869 | savedPersistentIndexes = qSelectionPersistentindexes(ranges); executed (the execution status of this line is deduced): savedPersistentIndexes = qSelectionPersistentindexes(ranges); | - |
| 870 | savedPersistentCurrentIndexes = qSelectionPersistentindexes(currentSelection); executed (the execution status of this line is deduced): savedPersistentCurrentIndexes = qSelectionPersistentindexes(currentSelection); | - |
| 871 | } executed: }Execution Count:2092 | 2092 |
| 872 | } | - |
| 873 | /*! | - |
| 874 | \internal | - |
| 875 | */ | - |
| 876 | static QItemSelection mergeRowLengths(const QVector<QPair<QPersistentModelIndex, uint> > &rowLengths) | - |
| 877 | { | - |
| 878 | if (rowLengths.isEmpty()) evaluated: rowLengths.isEmpty()| yes Evaluation Count:3 | yes Evaluation Count:7 |
| 3-7 |
| 879 | return QItemSelection(); executed: return QItemSelection();Execution Count:3 | 3 |
| 880 | | - |
| 881 | QItemSelection result; executed (the execution status of this line is deduced): QItemSelection result; | - |
| 882 | int i = 0; executed (the execution status of this line is deduced): int i = 0; | - |
| 883 | while (i < rowLengths.count()) { evaluated: i < rowLengths.count()| yes Evaluation Count:8 | yes Evaluation Count:7 |
| 7-8 |
| 884 | const QPersistentModelIndex &tl = rowLengths.at(i).first; executed (the execution status of this line is deduced): const QPersistentModelIndex &tl = rowLengths.at(i).first; | - |
| 885 | if (!tl.isValid()) { partially evaluated: !tl.isValid()| no Evaluation Count:0 | yes Evaluation Count:8 |
| 0-8 |
| 886 | ++i; never executed (the execution status of this line is deduced): ++i; | - |
| 887 | continue; never executed: continue; | 0 |
| 888 | } | - |
| 889 | QPersistentModelIndex br = tl; executed (the execution status of this line is deduced): QPersistentModelIndex br = tl; | - |
| 890 | const uint length = rowLengths.at(i).second; executed (the execution status of this line is deduced): const uint length = rowLengths.at(i).second; | - |
| 891 | while (++i < rowLengths.count()) { evaluated: ++i < rowLengths.count()| yes Evaluation Count:7 | yes Evaluation Count:7 |
| 7 |
| 892 | const QPersistentModelIndex &next = rowLengths.at(i).first; executed (the execution status of this line is deduced): const QPersistentModelIndex &next = rowLengths.at(i).first; | - |
| 893 | if (!next.isValid()) partially evaluated: !next.isValid()| no Evaluation Count:0 | yes Evaluation Count:7 |
| 0-7 |
| 894 | continue; never executed: continue; | 0 |
| 895 | const uint nextLength = rowLengths.at(i).second; executed (the execution status of this line is deduced): const uint nextLength = rowLengths.at(i).second; | - |
| 896 | if ((nextLength == length) partially evaluated: (nextLength == length)| yes Evaluation Count:7 | no Evaluation Count:0 |
| 0-7 |
| 897 | && (next.row() == br.row() + 1) evaluated: (next.row() == br.row() + 1)| yes Evaluation Count:6 | yes Evaluation Count:1 |
| 1-6 |
| 898 | && (next.parent() == br.parent())) { partially evaluated: (next.parent() == br.parent())| yes Evaluation Count:6 | no Evaluation Count:0 |
| 0-6 |
| 899 | br = next; executed (the execution status of this line is deduced): br = next; | - |
| 900 | } else { executed: }Execution Count:6 | 6 |
| 901 | break; executed: break;Execution Count:1 | 1 |
| 902 | } | - |
| 903 | } | - |
| 904 | result.append(QItemSelectionRange(tl, br.sibling(br.row(), length - 1))); executed (the execution status of this line is deduced): result.append(QItemSelectionRange(tl, br.sibling(br.row(), length - 1))); | - |
| 905 | } executed: }Execution Count:8 | 8 |
| 906 | return result; executed: return result;Execution Count:7 | 7 |
| 907 | } | - |
| 908 | | - |
| 909 | /*! | - |
| 910 | \internal | - |
| 911 | | - |
| 912 | Merges \a indexes into an item selection made up of ranges. | - |
| 913 | Assumes that the indexes are sorted. | - |
| 914 | */ | - |
| 915 | static QItemSelection mergeIndexes(const QVector<QPersistentModelIndex> &indexes) | - |
| 916 | { | - |
| 917 | QItemSelection colSpans; executed (the execution status of this line is deduced): QItemSelection colSpans; | - |
| 918 | // merge columns | - |
| 919 | int i = 0; executed (the execution status of this line is deduced): int i = 0; | - |
| 920 | while (i < indexes.count()) { evaluated: i < indexes.count()| yes Evaluation Count:24 | yes Evaluation Count:20 |
| 20-24 |
| 921 | const QPersistentModelIndex &tl = indexes.at(i); executed (the execution status of this line is deduced): const QPersistentModelIndex &tl = indexes.at(i); | - |
| 922 | if (!tl.isValid()) { partially evaluated: !tl.isValid()| no Evaluation Count:0 | yes Evaluation Count:24 |
| 0-24 |
| 923 | ++i; never executed (the execution status of this line is deduced): ++i; | - |
| 924 | continue; never executed: continue; | 0 |
| 925 | } | - |
| 926 | QPersistentModelIndex br = tl; executed (the execution status of this line is deduced): QPersistentModelIndex br = tl; | - |
| 927 | QModelIndex brParent = br.parent(); executed (the execution status of this line is deduced): QModelIndex brParent = br.parent(); | - |
| 928 | int brRow = br.row(); executed (the execution status of this line is deduced): int brRow = br.row(); | - |
| 929 | int brColumn = br.column(); executed (the execution status of this line is deduced): int brColumn = br.column(); | - |
| 930 | while (++i < indexes.count()) { evaluated: ++i < indexes.count()| yes Evaluation Count:319 | yes Evaluation Count:10 |
| 10-319 |
| 931 | const QPersistentModelIndex &next = indexes.at(i); executed (the execution status of this line is deduced): const QPersistentModelIndex &next = indexes.at(i); | - |
| 932 | if (!next.isValid()) partially evaluated: !next.isValid()| no Evaluation Count:0 | yes Evaluation Count:319 |
| 0-319 |
| 933 | continue; never executed: continue; | 0 |
| 934 | const QModelIndex nextParent = next.parent(); executed (the execution status of this line is deduced): const QModelIndex nextParent = next.parent(); | - |
| 935 | const int nextRow = next.row(); executed (the execution status of this line is deduced): const int nextRow = next.row(); | - |
| 936 | const int nextColumn = next.column(); executed (the execution status of this line is deduced): const int nextColumn = next.column(); | - |
| 937 | if ((nextParent == brParent) partially evaluated: (nextParent == brParent)| yes Evaluation Count:319 | no Evaluation Count:0 |
| 0-319 |
| 938 | && (nextRow == brRow) evaluated: (nextRow == brRow)| yes Evaluation Count:305 | yes Evaluation Count:14 |
| 14-305 |
| 939 | && (nextColumn == brColumn + 1)) { partially evaluated: (nextColumn == brColumn + 1)| yes Evaluation Count:305 | no Evaluation Count:0 |
| 0-305 |
| 940 | br = next; executed (the execution status of this line is deduced): br = next; | - |
| 941 | brParent = nextParent; executed (the execution status of this line is deduced): brParent = nextParent; | - |
| 942 | brRow = nextRow; executed (the execution status of this line is deduced): brRow = nextRow; | - |
| 943 | brColumn = nextColumn; executed (the execution status of this line is deduced): brColumn = nextColumn; | - |
| 944 | } else { executed: }Execution Count:305 | 305 |
| 945 | break; executed: break;Execution Count:14 | 14 |
| 946 | } | - |
| 947 | } | - |
| 948 | colSpans.append(QItemSelectionRange(tl, br)); executed (the execution status of this line is deduced): colSpans.append(QItemSelectionRange(tl, br)); | - |
| 949 | } executed: }Execution Count:24 | 24 |
| 950 | // merge rows | - |
| 951 | QItemSelection rowSpans; executed (the execution status of this line is deduced): QItemSelection rowSpans; | - |
| 952 | i = 0; executed (the execution status of this line is deduced): i = 0; | - |
| 953 | while (i < colSpans.count()) { evaluated: i < colSpans.count()| yes Evaluation Count:24 | yes Evaluation Count:20 |
| 20-24 |
| 954 | QModelIndex tl = colSpans.at(i).topLeft(); executed (the execution status of this line is deduced): QModelIndex tl = colSpans.at(i).topLeft(); | - |
| 955 | QModelIndex br = colSpans.at(i).bottomRight(); executed (the execution status of this line is deduced): QModelIndex br = colSpans.at(i).bottomRight(); | - |
| 956 | QModelIndex prevTl = tl; executed (the execution status of this line is deduced): QModelIndex prevTl = tl; | - |
| 957 | while (++i < colSpans.count()) { evaluated: ++i < colSpans.count()| yes Evaluation Count:14 | yes Evaluation Count:10 |
| 10-14 |
| 958 | QModelIndex nextTl = colSpans.at(i).topLeft(); executed (the execution status of this line is deduced): QModelIndex nextTl = colSpans.at(i).topLeft(); | - |
| 959 | QModelIndex nextBr = colSpans.at(i).bottomRight(); executed (the execution status of this line is deduced): QModelIndex nextBr = colSpans.at(i).bottomRight(); | - |
| 960 | | - |
| 961 | if (nextTl.parent() != tl.parent()) partially evaluated: nextTl.parent() != tl.parent()| no Evaluation Count:0 | yes Evaluation Count:14 |
| 0-14 |
| 962 | break; // we can't merge selection ranges from different parents | 0 |
| 963 | | - |
| 964 | if ((nextTl.column() == prevTl.column()) && (nextBr.column() == br.column()) partially evaluated: (nextTl.column() == prevTl.column())| yes Evaluation Count:14 | no Evaluation Count:0 |
partially evaluated: (nextBr.column() == br.column())| yes Evaluation Count:14 | no Evaluation Count:0 |
| 0-14 |
| 965 | && (nextTl.row() == prevTl.row() + 1) && (nextBr.row() == br.row() + 1)) { partially evaluated: (nextTl.row() == prevTl.row() + 1)| no Evaluation Count:0 | yes Evaluation Count:14 |
never evaluated: (nextBr.row() == br.row() + 1) | 0-14 |
| 966 | br = nextBr; never executed (the execution status of this line is deduced): br = nextBr; | - |
| 967 | prevTl = nextTl; never executed (the execution status of this line is deduced): prevTl = nextTl; | - |
| 968 | } else { | 0 |
| 969 | break; executed: break;Execution Count:14 | 14 |
| 970 | } | - |
| 971 | } | - |
| 972 | rowSpans.append(QItemSelectionRange(tl, br)); executed (the execution status of this line is deduced): rowSpans.append(QItemSelectionRange(tl, br)); | - |
| 973 | } executed: }Execution Count:24 | 24 |
| 974 | return rowSpans; executed: return rowSpans;Execution Count:20 | 20 |
| 975 | } | - |
| 976 | | - |
| 977 | /*! | - |
| 978 | \internal | - |
| 979 | | - |
| 980 | Merge the selected indexes into selection ranges again. | - |
| 981 | */ | - |
| 982 | void QItemSelectionModelPrivate::_q_layoutChanged(const QList<QPersistentModelIndex> &, QAbstractItemModel::LayoutChangeHint hint) | - |
| 983 | { | - |
| 984 | // special case for when all indexes are selected | - |
| 985 | if (tableSelected && tableColCount == model->columnCount(tableParent) partially evaluated: tableSelected| no Evaluation Count:0 | yes Evaluation Count:2204 |
never evaluated: tableColCount == model->columnCount(tableParent) | 0-2204 |
| 986 | && tableRowCount == model->rowCount(tableParent)) { never evaluated: tableRowCount == model->rowCount(tableParent) | 0 |
| 987 | ranges.clear(); never executed (the execution status of this line is deduced): ranges.clear(); | - |
| 988 | currentSelection.clear(); never executed (the execution status of this line is deduced): currentSelection.clear(); | - |
| 989 | int bottom = tableRowCount - 1; never executed (the execution status of this line is deduced): int bottom = tableRowCount - 1; | - |
| 990 | int right = tableColCount - 1; never executed (the execution status of this line is deduced): int right = tableColCount - 1; | - |
| 991 | QModelIndex tl = model->index(0, 0, tableParent); never executed (the execution status of this line is deduced): QModelIndex tl = model->index(0, 0, tableParent); | - |
| 992 | QModelIndex br = model->index(bottom, right, tableParent); never executed (the execution status of this line is deduced): QModelIndex br = model->index(bottom, right, tableParent); | - |
| 993 | currentSelection << QItemSelectionRange(tl, br); never executed (the execution status of this line is deduced): currentSelection << QItemSelectionRange(tl, br); | - |
| 994 | tableParent = QModelIndex(); never executed (the execution status of this line is deduced): tableParent = QModelIndex(); | - |
| 995 | tableSelected = false; never executed (the execution status of this line is deduced): tableSelected = false; | - |
| 996 | return; | 0 |
| 997 | } | - |
| 998 | | - |
| 999 | if ((hint != QAbstractItemModel::VerticalSortHint && savedPersistentCurrentIndexes.isEmpty() && savedPersistentIndexes.isEmpty()) evaluated: hint != QAbstractItemModel::VerticalSortHint| yes Evaluation Count:2093 | yes Evaluation Count:111 |
evaluated: savedPersistentCurrentIndexes.isEmpty()| yes Evaluation Count:2088 | yes Evaluation Count:5 |
evaluated: savedPersistentIndexes.isEmpty()| yes Evaluation Count:2083 | yes Evaluation Count:5 |
| 5-2093 |
| 1000 | || (hint == QAbstractItemModel::VerticalSortHint && savedPersistentRowLengths.isEmpty() && savedPersistentCurrentRowLengths.isEmpty())) { evaluated: hint == QAbstractItemModel::VerticalSortHint| yes Evaluation Count:111 | yes Evaluation Count:10 |
evaluated: savedPersistentRowLengths.isEmpty()| yes Evaluation Count:109 | yes Evaluation Count:2 |
evaluated: savedPersistentCurrentRowLengths.isEmpty()| yes Evaluation Count:106 | yes Evaluation Count:3 |
| 2-111 |
| 1001 | // either the selection was actually empty, or we | - |
| 1002 | // didn't get the layoutAboutToBeChanged() signal | - |
| 1003 | return; executed: return;Execution Count:2189 | 2189 |
| 1004 | } | - |
| 1005 | | - |
| 1006 | // clear the "old" selection | - |
| 1007 | ranges.clear(); executed (the execution status of this line is deduced): ranges.clear(); | - |
| 1008 | currentSelection.clear(); executed (the execution status of this line is deduced): currentSelection.clear(); | - |
| 1009 | | - |
| 1010 | if (hint != QAbstractItemModel::VerticalSortHint) { evaluated: hint != QAbstractItemModel::VerticalSortHint| yes Evaluation Count:10 | yes Evaluation Count:5 |
| 5-10 |
| 1011 | // sort the "new" selection, as preparation for merging | - |
| 1012 | std::stable_sort(savedPersistentIndexes.begin(), savedPersistentIndexes.end()); executed (the execution status of this line is deduced): std::stable_sort(savedPersistentIndexes.begin(), savedPersistentIndexes.end()); | - |
| 1013 | std::stable_sort(savedPersistentCurrentIndexes.begin(), savedPersistentCurrentIndexes.end()); executed (the execution status of this line is deduced): std::stable_sort(savedPersistentCurrentIndexes.begin(), savedPersistentCurrentIndexes.end()); | - |
| 1014 | | - |
| 1015 | // update the selection by merging the individual indexes | - |
| 1016 | ranges = mergeIndexes(savedPersistentIndexes); executed (the execution status of this line is deduced): ranges = mergeIndexes(savedPersistentIndexes); | - |
| 1017 | currentSelection = mergeIndexes(savedPersistentCurrentIndexes); executed (the execution status of this line is deduced): currentSelection = mergeIndexes(savedPersistentCurrentIndexes); | - |
| 1018 | | - |
| 1019 | // release the persistent indexes | - |
| 1020 | savedPersistentIndexes.clear(); executed (the execution status of this line is deduced): savedPersistentIndexes.clear(); | - |
| 1021 | savedPersistentCurrentIndexes.clear(); executed (the execution status of this line is deduced): savedPersistentCurrentIndexes.clear(); | - |
| 1022 | } else { executed: }Execution Count:10 | 10 |
| 1023 | // sort the "new" selection, as preparation for merging | - |
| 1024 | std::stable_sort(savedPersistentRowLengths.begin(), savedPersistentRowLengths.end()); executed (the execution status of this line is deduced): std::stable_sort(savedPersistentRowLengths.begin(), savedPersistentRowLengths.end()); | - |
| 1025 | std::stable_sort(savedPersistentCurrentRowLengths.begin(), savedPersistentCurrentRowLengths.end()); executed (the execution status of this line is deduced): std::stable_sort(savedPersistentCurrentRowLengths.begin(), savedPersistentCurrentRowLengths.end()); | - |
| 1026 | | - |
| 1027 | // update the selection by merging the individual indexes | - |
| 1028 | ranges = mergeRowLengths(savedPersistentRowLengths); executed (the execution status of this line is deduced): ranges = mergeRowLengths(savedPersistentRowLengths); | - |
| 1029 | currentSelection = mergeRowLengths(savedPersistentCurrentRowLengths); executed (the execution status of this line is deduced): currentSelection = mergeRowLengths(savedPersistentCurrentRowLengths); | - |
| 1030 | | - |
| 1031 | // release the persistent indexes | - |
| 1032 | savedPersistentRowLengths.clear(); executed (the execution status of this line is deduced): savedPersistentRowLengths.clear(); | - |
| 1033 | savedPersistentCurrentRowLengths.clear(); executed (the execution status of this line is deduced): savedPersistentCurrentRowLengths.clear(); | - |
| 1034 | } executed: }Execution Count:5 | 5 |
| 1035 | } | - |
| 1036 | | - |
| 1037 | /*! | - |
| 1038 | \class QItemSelectionModel | - |
| 1039 | \inmodule QtCore | - |
| 1040 | | - |
| 1041 | \brief The QItemSelectionModel class keeps track of a view's selected items. | - |
| 1042 | | - |
| 1043 | \ingroup model-view | - |
| 1044 | | - |
| 1045 | A QItemSelectionModel keeps track of the selected items in a view, or | - |
| 1046 | in several views onto the same model. It also keeps track of the | - |
| 1047 | currently selected item in a view. | - |
| 1048 | | - |
| 1049 | The QItemSelectionModel class is one of the \l{Model/View Classes} | - |
| 1050 | and is part of Qt's \l{Model/View Programming}{model/view framework}. | - |
| 1051 | | - |
| 1052 | The selected items are stored using ranges. Whenever you want to | - |
| 1053 | modify the selected items use select() and provide either a | - |
| 1054 | QItemSelection, or a QModelIndex and a QItemSelectionModel::SelectionFlag. | - |
| 1055 | | - |
| 1056 | The QItemSelectionModel takes a two layer approach to selection | - |
| 1057 | management, dealing with both selected items that have been committed | - |
| 1058 | and items that are part of the current selection. The current | - |
| 1059 | selected items are part of the current interactive selection (for | - |
| 1060 | example with rubber-band selection or keyboard-shift selections). | - |
| 1061 | | - |
| 1062 | To update the currently selected items, use the bitwise OR of | - |
| 1063 | QItemSelectionModel::Current and any of the other SelectionFlags. | - |
| 1064 | If you omit the QItemSelectionModel::Current command, a new current | - |
| 1065 | selection will be created, and the previous one added to the whole | - |
| 1066 | selection. All functions operate on both layers; for example, | - |
| 1067 | selectedItems() will return items from both layers. | - |
| 1068 | | - |
| 1069 | \sa {Model/View Programming}, QAbstractItemModel, {Chart Example} | - |
| 1070 | */ | - |
| 1071 | | - |
| 1072 | /*! | - |
| 1073 | Constructs a selection model that operates on the specified item \a model. | - |
| 1074 | */ | - |
| 1075 | QItemSelectionModel::QItemSelectionModel(QAbstractItemModel *model) | - |
| 1076 | : QObject(*new QItemSelectionModelPrivate, model) | - |
| 1077 | { | - |
| 1078 | d_func()->initModel(model); executed (the execution status of this line is deduced): d_func()->initModel(model); | - |
| 1079 | } executed: }Execution Count:32 | 32 |
| 1080 | | - |
| 1081 | /*! | - |
| 1082 | Constructs a selection model that operates on the specified item \a model with \a parent. | - |
| 1083 | */ | - |
| 1084 | QItemSelectionModel::QItemSelectionModel(QAbstractItemModel *model, QObject *parent) | - |
| 1085 | : QObject(*new QItemSelectionModelPrivate, parent) | - |
| 1086 | { | - |
| 1087 | d_func()->initModel(model); executed (the execution status of this line is deduced): d_func()->initModel(model); | - |
| 1088 | } executed: }Execution Count:4133 | 4133 |
| 1089 | | - |
| 1090 | /*! | - |
| 1091 | \internal | - |
| 1092 | */ | - |
| 1093 | QItemSelectionModel::QItemSelectionModel(QItemSelectionModelPrivate &dd, QAbstractItemModel *model) | - |
| 1094 | : QObject(dd, model) | - |
| 1095 | { | - |
| 1096 | dd.initModel(model); never executed (the execution status of this line is deduced): dd.initModel(model); | - |
| 1097 | } | 0 |
| 1098 | | - |
| 1099 | /*! | - |
| 1100 | Destroys the selection model. | - |
| 1101 | */ | - |
| 1102 | QItemSelectionModel::~QItemSelectionModel() | - |
| 1103 | { | - |
| 1104 | } | - |
| 1105 | | - |
| 1106 | /*! | - |
| 1107 | Selects the model item \a index using the specified \a command, and emits | - |
| 1108 | selectionChanged(). | - |
| 1109 | | - |
| 1110 | \sa QItemSelectionModel::SelectionFlags | - |
| 1111 | */ | - |
| 1112 | void QItemSelectionModel::select(const QModelIndex &index, QItemSelectionModel::SelectionFlags command) | - |
| 1113 | { | - |
| 1114 | QItemSelection selection(index, index); executed (the execution status of this line is deduced): QItemSelection selection(index, index); | - |
| 1115 | select(selection, command); executed (the execution status of this line is deduced): select(selection, command); | - |
| 1116 | } executed: }Execution Count:3426 | 3426 |
| 1117 | | - |
| 1118 | /*! | - |
| 1119 | \fn void QItemSelectionModel::currentChanged(const QModelIndex ¤t, const QModelIndex &previous) | - |
| 1120 | | - |
| 1121 | This signal is emitted whenever the current item changes. The \a previous | - |
| 1122 | model item index is replaced by the \a current index as the selection's | - |
| 1123 | current item. | - |
| 1124 | | - |
| 1125 | Note that this signal will not be emitted when the item model is reset. | - |
| 1126 | | - |
| 1127 | \sa currentIndex(), setCurrentIndex(), selectionChanged() | - |
| 1128 | */ | - |
| 1129 | | - |
| 1130 | /*! | - |
| 1131 | \fn void QItemSelectionModel::currentColumnChanged(const QModelIndex ¤t, const QModelIndex &previous) | - |
| 1132 | | - |
| 1133 | This signal is emitted if the \a current item changes and its column is | - |
| 1134 | different to the column of the \a previous current item. | - |
| 1135 | | - |
| 1136 | Note that this signal will not be emitted when the item model is reset. | - |
| 1137 | | - |
| 1138 | \sa currentChanged(), currentRowChanged(), currentIndex(), setCurrentIndex() | - |
| 1139 | */ | - |
| 1140 | | - |
| 1141 | /*! | - |
| 1142 | \fn void QItemSelectionModel::currentRowChanged(const QModelIndex ¤t, const QModelIndex &previous) | - |
| 1143 | | - |
| 1144 | This signal is emitted if the \a current item changes and its row is | - |
| 1145 | different to the row of the \a previous current item. | - |
| 1146 | | - |
| 1147 | Note that this signal will not be emitted when the item model is reset. | - |
| 1148 | | - |
| 1149 | \sa currentChanged(), currentColumnChanged(), currentIndex(), setCurrentIndex() | - |
| 1150 | */ | - |
| 1151 | | - |
| 1152 | /*! | - |
| 1153 | \fn void QItemSelectionModel::selectionChanged(const QItemSelection &selected, const QItemSelection &deselected) | - |
| 1154 | | - |
| 1155 | This signal is emitted whenever the selection changes. The change in the | - |
| 1156 | selection is represented as an item selection of \a deselected items and | - |
| 1157 | an item selection of \a selected items. | - |
| 1158 | | - |
| 1159 | Note the that the current index changes independently from the selection. | - |
| 1160 | Also note that this signal will not be emitted when the item model is reset. | - |
| 1161 | | - |
| 1162 | \sa select(), currentChanged() | - |
| 1163 | */ | - |
| 1164 | | - |
| 1165 | /*! | - |
| 1166 | \enum QItemSelectionModel::SelectionFlag | - |
| 1167 | | - |
| 1168 | This enum describes the way the selection model will be updated. | - |
| 1169 | | - |
| 1170 | \value NoUpdate No selection will be made. | - |
| 1171 | \value Clear The complete selection will be cleared. | - |
| 1172 | \value Select All specified indexes will be selected. | - |
| 1173 | \value Deselect All specified indexes will be deselected. | - |
| 1174 | \value Toggle All specified indexes will be selected or | - |
| 1175 | deselected depending on their current state. | - |
| 1176 | \value Current The current selection will be updated. | - |
| 1177 | \value Rows All indexes will be expanded to span rows. | - |
| 1178 | \value Columns All indexes will be expanded to span columns. | - |
| 1179 | \value SelectCurrent A combination of Select and Current, provided for | - |
| 1180 | convenience. | - |
| 1181 | \value ToggleCurrent A combination of Toggle and Current, provided for | - |
| 1182 | convenience. | - |
| 1183 | \value ClearAndSelect A combination of Clear and Select, provided for | - |
| 1184 | convenience. | - |
| 1185 | */ | - |
| 1186 | | - |
| 1187 | /*! | - |
| 1188 | Selects the item \a selection using the specified \a command, and emits | - |
| 1189 | selectionChanged(). | - |
| 1190 | | - |
| 1191 | \sa QItemSelectionModel::SelectionFlag | - |
| 1192 | */ | - |
| 1193 | void QItemSelectionModel::select(const QItemSelection &selection, QItemSelectionModel::SelectionFlags command) | - |
| 1194 | { | - |
| 1195 | Q_D(QItemSelectionModel); executed (the execution status of this line is deduced): QItemSelectionModelPrivate * const d = d_func(); | - |
| 1196 | if (command == NoUpdate) evaluated: command == NoUpdate| yes Evaluation Count:44 | yes Evaluation Count:6493 |
| 44-6493 |
| 1197 | return; executed: return;Execution Count:44 | 44 |
| 1198 | | - |
| 1199 | // store old selection | - |
| 1200 | QItemSelection sel = selection; executed (the execution status of this line is deduced): QItemSelection sel = selection; | - |
| 1201 | // If d->ranges is non-empty when the source model is reset the persistent indexes | - |
| 1202 | // it contains will be invalid. We can't clear them in a modelReset slot because that might already | - |
| 1203 | // be too late if another model observer is connected to the same modelReset slot and is invoked first | - |
| 1204 | // it might call select() on this selection model before any such QItemSelectionModelPrivate::_q_modelReset() slot | - |
| 1205 | // is invoked, so it would not be cleared yet. We clear it invalid ranges in it here. | - |
| 1206 | QItemSelection::iterator it = d->ranges.begin(); executed (the execution status of this line is deduced): QItemSelection::iterator it = d->ranges.begin(); | - |
| 1207 | while (it != d->ranges.end()) { evaluated: it != d->ranges.end()| yes Evaluation Count:1254 | yes Evaluation Count:6493 |
| 1254-6493 |
| 1208 | if (!it->isValid()) evaluated: !it->isValid()| yes Evaluation Count:2 | yes Evaluation Count:1252 |
| 2-1252 |
| 1209 | it = d->ranges.erase(it); executed: it = d->ranges.erase(it);Execution Count:2 | 2 |
| 1210 | else | - |
| 1211 | ++it; executed: ++it;Execution Count:1252 | 1252 |
| 1212 | } | - |
| 1213 | | - |
| 1214 | QItemSelection old = d->ranges; executed (the execution status of this line is deduced): QItemSelection old = d->ranges; | - |
| 1215 | old.merge(d->currentSelection, d->currentCommand); executed (the execution status of this line is deduced): old.merge(d->currentSelection, d->currentCommand); | - |
| 1216 | | - |
| 1217 | // expand selection according to SelectionBehavior | - |
| 1218 | if (command & Rows || command & Columns) evaluated: command & Rows| yes Evaluation Count:461 | yes Evaluation Count:6032 |
evaluated: command & Columns| yes Evaluation Count:22 | yes Evaluation Count:6010 |
| 22-6032 |
| 1219 | sel = d->expandSelection(sel, command); executed: sel = d->expandSelection(sel, command);Execution Count:483 | 483 |
| 1220 | | - |
| 1221 | // clear ranges and currentSelection | - |
| 1222 | if (command & Clear) { evaluated: command & Clear| yes Evaluation Count:4742 | yes Evaluation Count:1751 |
| 1751-4742 |
| 1223 | d->ranges.clear(); executed (the execution status of this line is deduced): d->ranges.clear(); | - |
| 1224 | d->currentSelection.clear(); executed (the execution status of this line is deduced): d->currentSelection.clear(); | - |
| 1225 | } executed: }Execution Count:4742 | 4742 |
| 1226 | | - |
| 1227 | // merge and clear currentSelection if Current was not set (ie. start new currentSelection) | - |
| 1228 | if (!(command & Current)) evaluated: !(command & Current)| yes Evaluation Count:5780 | yes Evaluation Count:713 |
| 713-5780 |
| 1229 | d->finalize(); executed: d->finalize();Execution Count:5780 | 5780 |
| 1230 | | - |
| 1231 | // update currentSelection | - |
| 1232 | if (command & Toggle || command & Select || command & Deselect) { evaluated: command & Toggle| yes Evaluation Count:28 | yes Evaluation Count:6465 |
evaluated: command & Select| yes Evaluation Count:4827 | yes Evaluation Count:1638 |
evaluated: command & Deselect| yes Evaluation Count:372 | yes Evaluation Count:1266 |
| 28-6465 |
| 1233 | d->currentCommand = command; executed (the execution status of this line is deduced): d->currentCommand = command; | - |
| 1234 | d->currentSelection = sel; executed (the execution status of this line is deduced): d->currentSelection = sel; | - |
| 1235 | } executed: }Execution Count:5227 | 5227 |
| 1236 | | - |
| 1237 | // generate new selection, compare with old and emit selectionChanged() | - |
| 1238 | QItemSelection newSelection = d->ranges; executed (the execution status of this line is deduced): QItemSelection newSelection = d->ranges; | - |
| 1239 | newSelection.merge(d->currentSelection, d->currentCommand); executed (the execution status of this line is deduced): newSelection.merge(d->currentSelection, d->currentCommand); | - |
| 1240 | emitSelectionChanged(newSelection, old); executed (the execution status of this line is deduced): emitSelectionChanged(newSelection, old); | - |
| 1241 | } executed: }Execution Count:6493 | 6493 |
| 1242 | | - |
| 1243 | /*! | - |
| 1244 | Clears the selection model. Emits selectionChanged() and currentChanged(). | - |
| 1245 | */ | - |
| 1246 | void QItemSelectionModel::clear() | - |
| 1247 | { | - |
| 1248 | clearSelection(); executed (the execution status of this line is deduced): clearSelection(); | - |
| 1249 | clearCurrentIndex(); executed (the execution status of this line is deduced): clearCurrentIndex(); | - |
| 1250 | } executed: }Execution Count:8326 | 8326 |
| 1251 | | - |
| 1252 | /*! | - |
| 1253 | Clears the current index. Emits currentChanged(). | - |
| 1254 | */ | - |
| 1255 | void QItemSelectionModel::clearCurrentIndex() | - |
| 1256 | { | - |
| 1257 | Q_D(QItemSelectionModel); executed (the execution status of this line is deduced): QItemSelectionModelPrivate * const d = d_func(); | - |
| 1258 | QModelIndex previous = d->currentIndex; executed (the execution status of this line is deduced): QModelIndex previous = d->currentIndex; | - |
| 1259 | d->currentIndex = QModelIndex(); executed (the execution status of this line is deduced): d->currentIndex = QModelIndex(); | - |
| 1260 | if (previous.isValid()) { evaluated: previous.isValid()| yes Evaluation Count:801 | yes Evaluation Count:7528 |
| 801-7528 |
| 1261 | emit currentChanged(d->currentIndex, previous); executed (the execution status of this line is deduced): currentChanged(d->currentIndex, previous); | - |
| 1262 | emit currentRowChanged(d->currentIndex, previous); executed (the execution status of this line is deduced): currentRowChanged(d->currentIndex, previous); | - |
| 1263 | emit currentColumnChanged(d->currentIndex, previous); executed (the execution status of this line is deduced): currentColumnChanged(d->currentIndex, previous); | - |
| 1264 | } executed: }Execution Count:801 | 801 |
| 1265 | } executed: }Execution Count:8329 | 8329 |
| 1266 | | - |
| 1267 | /*! | - |
| 1268 | Clears the selection model. Does not emit any signals. | - |
| 1269 | */ | - |
| 1270 | void QItemSelectionModel::reset() | - |
| 1271 | { | - |
| 1272 | bool block = blockSignals(true); executed (the execution status of this line is deduced): bool block = blockSignals(true); | - |
| 1273 | clear(); executed (the execution status of this line is deduced): clear(); | - |
| 1274 | blockSignals(block); executed (the execution status of this line is deduced): blockSignals(block); | - |
| 1275 | } executed: }Execution Count:6095 | 6095 |
| 1276 | | - |
| 1277 | /*! | - |
| 1278 | \since 4.2 | - |
| 1279 | Clears the selection in the selection model. Emits selectionChanged(). | - |
| 1280 | */ | - |
| 1281 | void QItemSelectionModel::clearSelection() | - |
| 1282 | { | - |
| 1283 | Q_D(QItemSelectionModel); executed (the execution status of this line is deduced): QItemSelectionModelPrivate * const d = d_func(); | - |
| 1284 | if (d->ranges.count() == 0 && d->currentSelection.count() == 0) evaluated: d->ranges.count() == 0| yes Evaluation Count:8287 | yes Evaluation Count:54 |
evaluated: d->currentSelection.count() == 0| yes Evaluation Count:7077 | yes Evaluation Count:1210 |
| 54-8287 |
| 1285 | return; executed: return;Execution Count:7077 | 7077 |
| 1286 | | - |
| 1287 | select(QItemSelection(), Clear); executed (the execution status of this line is deduced): select(QItemSelection(), Clear); | - |
| 1288 | } executed: }Execution Count:1264 | 1264 |
| 1289 | | - |
| 1290 | | - |
| 1291 | /*! | - |
| 1292 | Sets the model item \a index to be the current item, and emits | - |
| 1293 | currentChanged(). The current item is used for keyboard navigation and | - |
| 1294 | focus indication; it is independent of any selected items, although a | - |
| 1295 | selected item can also be the current item. | - |
| 1296 | | - |
| 1297 | Depending on the specified \a command, the \a index can also become part | - |
| 1298 | of the current selection. | - |
| 1299 | \sa select() | - |
| 1300 | */ | - |
| 1301 | void QItemSelectionModel::setCurrentIndex(const QModelIndex &index, QItemSelectionModel::SelectionFlags command) | - |
| 1302 | { | - |
| 1303 | Q_D(QItemSelectionModel); executed (the execution status of this line is deduced): QItemSelectionModelPrivate * const d = d_func(); | - |
| 1304 | if (index == d->currentIndex) { evaluated: index == d->currentIndex| yes Evaluation Count:167 | yes Evaluation Count:3576 |
| 167-3576 |
| 1305 | if (command != NoUpdate) evaluated: command != NoUpdate| yes Evaluation Count:51 | yes Evaluation Count:116 |
| 51-116 |
| 1306 | select(index, command); // select item executed: select(index, command);Execution Count:51 | 51 |
| 1307 | return; executed: return;Execution Count:167 | 167 |
| 1308 | } | - |
| 1309 | QPersistentModelIndex previous = d->currentIndex; executed (the execution status of this line is deduced): QPersistentModelIndex previous = d->currentIndex; | - |
| 1310 | d->currentIndex = index; // set current before emitting selection changed below executed (the execution status of this line is deduced): d->currentIndex = index; | - |
| 1311 | if (command != NoUpdate) evaluated: command != NoUpdate| yes Evaluation Count:2726 | yes Evaluation Count:850 |
| 850-2726 |
| 1312 | select(d->currentIndex, command); // select item executed: select(d->currentIndex, command);Execution Count:2726 | 2726 |
| 1313 | emit currentChanged(d->currentIndex, previous); executed (the execution status of this line is deduced): currentChanged(d->currentIndex, previous); | - |
| 1314 | if (d->currentIndex.row() != previous.row() || evaluated: d->currentIndex.row() != previous.row()| yes Evaluation Count:3035 | yes Evaluation Count:541 |
| 541-3035 |
| 1315 | d->currentIndex.parent() != previous.parent()) evaluated: d->currentIndex.parent() != previous.parent()| yes Evaluation Count:14 | yes Evaluation Count:527 |
| 14-527 |
| 1316 | emit currentRowChanged(d->currentIndex, previous); executed: currentRowChanged(d->currentIndex, previous);Execution Count:3049 | 3049 |
| 1317 | if (d->currentIndex.column() != previous.column() || evaluated: d->currentIndex.column() != previous.column()| yes Evaluation Count:1891 | yes Evaluation Count:1685 |
| 1685-1891 |
| 1318 | d->currentIndex.parent() != previous.parent()) evaluated: d->currentIndex.parent() != previous.parent()| yes Evaluation Count:28 | yes Evaluation Count:1657 |
| 28-1657 |
| 1319 | emit currentColumnChanged(d->currentIndex, previous); executed: currentColumnChanged(d->currentIndex, previous);Execution Count:1919 | 1919 |
| 1320 | } executed: }Execution Count:3576 | 3576 |
| 1321 | | - |
| 1322 | /*! | - |
| 1323 | Returns the model item index for the current item, or an invalid index | - |
| 1324 | if there is no current item. | - |
| 1325 | */ | - |
| 1326 | QModelIndex QItemSelectionModel::currentIndex() const | - |
| 1327 | { | - |
| 1328 | return static_cast<QModelIndex>(d_func()->currentIndex); executed: return static_cast<QModelIndex>(d_func()->currentIndex);Execution Count:28221 | 28221 |
| 1329 | } | - |
| 1330 | | - |
| 1331 | /*! | - |
| 1332 | Returns true if the given model item \a index is selected. | - |
| 1333 | */ | - |
| 1334 | bool QItemSelectionModel::isSelected(const QModelIndex &index) const | - |
| 1335 | { | - |
| 1336 | Q_D(const QItemSelectionModel); executed (the execution status of this line is deduced): const QItemSelectionModelPrivate * const d = d_func(); | - |
| 1337 | if (d->model != index.model() || !index.isValid()) evaluated: d->model != index.model()| yes Evaluation Count:20 | yes Evaluation Count:21974 |
partially evaluated: !index.isValid()| no Evaluation Count:0 | yes Evaluation Count:21974 |
| 0-21974 |
| 1338 | return false; executed: return false;Execution Count:20 | 20 |
| 1339 | | - |
| 1340 | bool selected = false; executed (the execution status of this line is deduced): bool selected = false; | - |
| 1341 | // search model ranges | - |
| 1342 | QList<QItemSelectionRange>::const_iterator it = d->ranges.begin(); executed (the execution status of this line is deduced): QList<QItemSelectionRange>::const_iterator it = d->ranges.begin(); | - |
| 1343 | for (; it != d->ranges.end(); ++it) { evaluated: it != d->ranges.end()| yes Evaluation Count:2845 | yes Evaluation Count:21266 |
| 2845-21266 |
| 1344 | if ((*it).isValid() && (*it).contains(index)) { partially evaluated: (*it).isValid()| yes Evaluation Count:2845 | no Evaluation Count:0 |
evaluated: (*it).contains(index)| yes Evaluation Count:708 | yes Evaluation Count:2137 |
| 0-2845 |
| 1345 | selected = true; executed (the execution status of this line is deduced): selected = true; | - |
| 1346 | break; executed: break;Execution Count:708 | 708 |
| 1347 | } | - |
| 1348 | } executed: }Execution Count:2137 | 2137 |
| 1349 | | - |
| 1350 | // check currentSelection | - |
| 1351 | if (d->currentSelection.count()) { evaluated: d->currentSelection.count()| yes Evaluation Count:8944 | yes Evaluation Count:13030 |
| 8944-13030 |
| 1352 | if ((d->currentCommand & Deselect) && selected) evaluated: (d->currentCommand & Deselect)| yes Evaluation Count:265 | yes Evaluation Count:8679 |
evaluated: selected| yes Evaluation Count:192 | yes Evaluation Count:73 |
| 73-8679 |
| 1353 | selected = !d->currentSelection.contains(index); executed: selected = !d->currentSelection.contains(index);Execution Count:192 | 192 |
| 1354 | else if (d->currentCommand & Toggle) evaluated: d->currentCommand & Toggle| yes Evaluation Count:65 | yes Evaluation Count:8687 |
| 65-8687 |
| 1355 | selected ^= d->currentSelection.contains(index); executed: selected ^= d->currentSelection.contains(index);Execution Count:65 | 65 |
| 1356 | else if ((d->currentCommand & Select) && !selected) evaluated: (d->currentCommand & Select)| yes Evaluation Count:8614 | yes Evaluation Count:73 |
evaluated: !selected| yes Evaluation Count:8364 | yes Evaluation Count:250 |
| 73-8614 |
| 1357 | selected = d->currentSelection.contains(index); executed: selected = d->currentSelection.contains(index);Execution Count:8364 | 8364 |
| 1358 | } | - |
| 1359 | | - |
| 1360 | if (selected) { evaluated: selected| yes Evaluation Count:1990 | yes Evaluation Count:19984 |
| 1990-19984 |
| 1361 | Qt::ItemFlags flags = d->model->flags(index); executed (the execution status of this line is deduced): Qt::ItemFlags flags = d->model->flags(index); | - |
| 1362 | return (flags & Qt::ItemIsSelectable); executed: return (flags & Qt::ItemIsSelectable);Execution Count:1990 | 1990 |
| 1363 | } | - |
| 1364 | | - |
| 1365 | return false; executed: return false;Execution Count:19984 | 19984 |
| 1366 | } | - |
| 1367 | | - |
| 1368 | /*! | - |
| 1369 | Returns true if all items are selected in the \a row with the given | - |
| 1370 | \a parent. | - |
| 1371 | | - |
| 1372 | Note that this function is usually faster than calling isSelected() | - |
| 1373 | on all items in the same row and that unselectable items are | - |
| 1374 | ignored. | - |
| 1375 | */ | - |
| 1376 | bool QItemSelectionModel::isRowSelected(int row, const QModelIndex &parent) const | - |
| 1377 | { | - |
| 1378 | Q_D(const QItemSelectionModel); executed (the execution status of this line is deduced): const QItemSelectionModelPrivate * const d = d_func(); | - |
| 1379 | if (parent.isValid() && d->model != parent.model()) evaluated: parent.isValid()| yes Evaluation Count:220 | yes Evaluation Count:929 |
partially evaluated: d->model != parent.model()| no Evaluation Count:0 | yes Evaluation Count:220 |
| 0-929 |
| 1380 | return false; never executed: return false; | 0 |
| 1381 | | - |
| 1382 | // return false if row exist in currentSelection (Deselect) | - |
| 1383 | if (d->currentCommand & Deselect && d->currentSelection.count()) { evaluated: d->currentCommand & Deselect| yes Evaluation Count:76 | yes Evaluation Count:1073 |
partially evaluated: d->currentSelection.count()| yes Evaluation Count:76 | no Evaluation Count:0 |
| 0-1073 |
| 1384 | for (int i=0; i<d->currentSelection.count(); ++i) { evaluated: i<d->currentSelection.count()| yes Evaluation Count:76 | yes Evaluation Count:55 |
| 55-76 |
| 1385 | if (d->currentSelection.at(i).parent() == parent && partially evaluated: d->currentSelection.at(i).parent() == parent| yes Evaluation Count:76 | no Evaluation Count:0 |
| 0-76 |
| 1386 | row >= d->currentSelection.at(i).top() && evaluated: row >= d->currentSelection.at(i).top()| yes Evaluation Count:62 | yes Evaluation Count:14 |
| 14-62 |
| 1387 | row <= d->currentSelection.at(i).bottom()) evaluated: row <= d->currentSelection.at(i).bottom()| yes Evaluation Count:21 | yes Evaluation Count:41 |
| 21-41 |
| 1388 | return false; executed: return false;Execution Count:21 | 21 |
| 1389 | } executed: }Execution Count:55 | 55 |
| 1390 | } executed: }Execution Count:55 | 55 |
| 1391 | // return false if ranges in both currentSelection and ranges | - |
| 1392 | // intersect and have the same row contained | - |
| 1393 | if (d->currentCommand & Toggle && d->currentSelection.count()) { evaluated: d->currentCommand & Toggle| yes Evaluation Count:20 | yes Evaluation Count:1108 |
partially evaluated: d->currentSelection.count()| yes Evaluation Count:20 | no Evaluation Count:0 |
| 0-1108 |
| 1394 | for (int i=0; i<d->currentSelection.count(); ++i) evaluated: i<d->currentSelection.count()| yes Evaluation Count:20 | yes Evaluation Count:20 |
| 20 |
| 1395 | if (d->currentSelection.at(i).top() <= row && evaluated: d->currentSelection.at(i).top() <= row| yes Evaluation Count:10 | yes Evaluation Count:10 |
| 10 |
| 1396 | d->currentSelection.at(i).bottom() >= row) partially evaluated: d->currentSelection.at(i).bottom() >= row| no Evaluation Count:0 | yes Evaluation Count:10 |
| 0-10 |
| 1397 | for (int j=0; j<d->ranges.count(); ++j) never evaluated: j<d->ranges.count() | 0 |
| 1398 | if (d->ranges.at(j).top() <= row && d->ranges.at(j).bottom() >= row never evaluated: d->ranges.at(j).top() <= row never evaluated: d->ranges.at(j).bottom() >= row | 0 |
| 1399 | && d->currentSelection.at(i).intersected(d->ranges.at(j)).isValid()) never evaluated: d->currentSelection.at(i).intersected(d->ranges.at(j)).isValid() | 0 |
| 1400 | return false; never executed: return false; | 0 |
| 1401 | } executed: }Execution Count:20 | 20 |
| 1402 | // add ranges and currentSelection and check through them all | - |
| 1403 | QList<QItemSelectionRange>::const_iterator it; executed (the execution status of this line is deduced): QList<QItemSelectionRange>::const_iterator it; | - |
| 1404 | QList<QItemSelectionRange> joined = d->ranges; executed (the execution status of this line is deduced): QList<QItemSelectionRange> joined = d->ranges; | - |
| 1405 | if (d->currentSelection.count()) evaluated: d->currentSelection.count()| yes Evaluation Count:1011 | yes Evaluation Count:117 |
| 117-1011 |
| 1406 | joined += d->currentSelection; executed: joined += d->currentSelection;Execution Count:1011 | 1011 |
| 1407 | int colCount = d->model->columnCount(parent); executed (the execution status of this line is deduced): int colCount = d->model->columnCount(parent); | - |
| 1408 | for (int column = 0; column < colCount; ++column) { evaluated: column < colCount| yes Evaluation Count:1407 | yes Evaluation Count:397 |
| 397-1407 |
| 1409 | for (it = joined.constBegin(); it != joined.constEnd(); ++it) { evaluated: it != joined.constEnd()| yes Evaluation Count:2682 | yes Evaluation Count:731 |
| 731-2682 |
| 1410 | if ((*it).contains(row, column, parent)) { evaluated: (*it).contains(row, column, parent)| yes Evaluation Count:686 | yes Evaluation Count:1996 |
| 686-1996 |
| 1411 | bool selectable = false; executed (the execution status of this line is deduced): bool selectable = false; | - |
| 1412 | for (int i = column; !selectable && i <= (*it).right(); ++i) { evaluated: !selectable| yes Evaluation Count:697 | yes Evaluation Count:676 |
evaluated: i <= (*it).right()| yes Evaluation Count:687 | yes Evaluation Count:10 |
| 10-697 |
| 1413 | Qt::ItemFlags flags = d->model->index(row, i, parent).flags(); executed (the execution status of this line is deduced): Qt::ItemFlags flags = d->model->index(row, i, parent).flags(); | - |
| 1414 | selectable = flags & Qt::ItemIsSelectable; executed (the execution status of this line is deduced): selectable = flags & Qt::ItemIsSelectable; | - |
| 1415 | } executed: }Execution Count:687 | 687 |
| 1416 | if (selectable){ evaluated: selectable| yes Evaluation Count:676 | yes Evaluation Count:10 |
| 10-676 |
| 1417 | column = qMax(column, (*it).right()); executed (the execution status of this line is deduced): column = qMax(column, (*it).right()); | - |
| 1418 | break; executed: break;Execution Count:676 | 676 |
| 1419 | } | - |
| 1420 | } executed: }Execution Count:10 | 10 |
| 1421 | } executed: }Execution Count:2006 | 2006 |
| 1422 | if (it == joined.constEnd()) evaluated: it == joined.constEnd()| yes Evaluation Count:731 | yes Evaluation Count:676 |
| 676-731 |
| 1423 | return false; executed: return false;Execution Count:731 | 731 |
| 1424 | } executed: }Execution Count:676 | 676 |
| 1425 | return colCount > 0; // no columns means no selected items executed: return colCount > 0;Execution Count:397 | 397 |
| 1426 | } | - |
| 1427 | | - |
| 1428 | /*! | - |
| 1429 | Returns true if all items are selected in the \a column with the given | - |
| 1430 | \a parent. | - |
| 1431 | | - |
| 1432 | Note that this function is usually faster than calling isSelected() | - |
| 1433 | on all items in the same column and that unselectable items are | - |
| 1434 | ignored. | - |
| 1435 | */ | - |
| 1436 | bool QItemSelectionModel::isColumnSelected(int column, const QModelIndex &parent) const | - |
| 1437 | { | - |
| 1438 | Q_D(const QItemSelectionModel); executed (the execution status of this line is deduced): const QItemSelectionModelPrivate * const d = d_func(); | - |
| 1439 | if (parent.isValid() && d->model != parent.model()) evaluated: parent.isValid()| yes Evaluation Count:20 | yes Evaluation Count:867 |
partially evaluated: d->model != parent.model()| no Evaluation Count:0 | yes Evaluation Count:20 |
| 0-867 |
| 1440 | return false; never executed: return false; | 0 |
| 1441 | | - |
| 1442 | // return false if column exist in currentSelection (Deselect) | - |
| 1443 | if (d->currentCommand & Deselect && d->currentSelection.count()) { evaluated: d->currentCommand & Deselect| yes Evaluation Count:50 | yes Evaluation Count:837 |
partially evaluated: d->currentSelection.count()| yes Evaluation Count:50 | no Evaluation Count:0 |
| 0-837 |
| 1444 | for (int i = 0; i < d->currentSelection.count(); ++i) { evaluated: i < d->currentSelection.count()| yes Evaluation Count:50 | yes Evaluation Count:29 |
| 29-50 |
| 1445 | if (d->currentSelection.at(i).parent() == parent && partially evaluated: d->currentSelection.at(i).parent() == parent| yes Evaluation Count:50 | no Evaluation Count:0 |
| 0-50 |
| 1446 | column >= d->currentSelection.at(i).left() && evaluated: column >= d->currentSelection.at(i).left()| yes Evaluation Count:41 | yes Evaluation Count:9 |
| 9-41 |
| 1447 | column <= d->currentSelection.at(i).right()) evaluated: column <= d->currentSelection.at(i).right()| yes Evaluation Count:21 | yes Evaluation Count:20 |
| 20-21 |
| 1448 | return false; executed: return false;Execution Count:21 | 21 |
| 1449 | } executed: }Execution Count:29 | 29 |
| 1450 | } executed: }Execution Count:29 | 29 |
| 1451 | // return false if ranges in both currentSelection and the selection model | - |
| 1452 | // intersect and have the same column contained | - |
| 1453 | if (d->currentCommand & Toggle && d->currentSelection.count()) { partially evaluated: d->currentCommand & Toggle| no Evaluation Count:0 | yes Evaluation Count:866 |
never evaluated: d->currentSelection.count() | 0-866 |
| 1454 | for (int i = 0; i < d->currentSelection.count(); ++i) { never evaluated: i < d->currentSelection.count() | 0 |
| 1455 | if (d->currentSelection.at(i).left() <= column && never evaluated: d->currentSelection.at(i).left() <= column | 0 |
| 1456 | d->currentSelection.at(i).right() >= column) { never evaluated: d->currentSelection.at(i).right() >= column | 0 |
| 1457 | for (int j = 0; j < d->ranges.count(); ++j) { never evaluated: j < d->ranges.count() | 0 |
| 1458 | if (d->ranges.at(j).left() <= column && d->ranges.at(j).right() >= column never evaluated: d->ranges.at(j).left() <= column never evaluated: d->ranges.at(j).right() >= column | 0 |
| 1459 | && d->currentSelection.at(i).intersected(d->ranges.at(j)).isValid()) { never evaluated: d->currentSelection.at(i).intersected(d->ranges.at(j)).isValid() | 0 |
| 1460 | return false; never executed: return false; | 0 |
| 1461 | } | - |
| 1462 | } | 0 |
| 1463 | } | 0 |
| 1464 | } | 0 |
| 1465 | } | 0 |
| 1466 | // add ranges and currentSelection and check through them all | - |
| 1467 | QList<QItemSelectionRange>::const_iterator it; executed (the execution status of this line is deduced): QList<QItemSelectionRange>::const_iterator it; | - |
| 1468 | QList<QItemSelectionRange> joined = d->ranges; executed (the execution status of this line is deduced): QList<QItemSelectionRange> joined = d->ranges; | - |
| 1469 | if (d->currentSelection.count()) evaluated: d->currentSelection.count()| yes Evaluation Count:750 | yes Evaluation Count:116 |
| 116-750 |
| 1470 | joined += d->currentSelection; executed: joined += d->currentSelection;Execution Count:750 | 750 |
| 1471 | int rowCount = d->model->rowCount(parent); executed (the execution status of this line is deduced): int rowCount = d->model->rowCount(parent); | - |
| 1472 | for (int row = 0; row < rowCount; ++row) { evaluated: row < rowCount| yes Evaluation Count:1069 | yes Evaluation Count:127 |
| 127-1069 |
| 1473 | for (it = joined.constBegin(); it != joined.constEnd(); ++it) { evaluated: it != joined.constEnd()| yes Evaluation Count:1712 | yes Evaluation Count:739 |
| 739-1712 |
| 1474 | if ((*it).contains(row, column, parent)) { evaluated: (*it).contains(row, column, parent)| yes Evaluation Count:334 | yes Evaluation Count:1378 |
| 334-1378 |
| 1475 | Qt::ItemFlags flags = d->model->index(row, column, parent).flags(); executed (the execution status of this line is deduced): Qt::ItemFlags flags = d->model->index(row, column, parent).flags(); | - |
| 1476 | if ((flags & Qt::ItemIsSelectable) && (flags & Qt::ItemIsEnabled)) { partially evaluated: (flags & Qt::ItemIsSelectable)| yes Evaluation Count:334 | no Evaluation Count:0 |
evaluated: (flags & Qt::ItemIsEnabled)| yes Evaluation Count:330 | yes Evaluation Count:4 |
| 0-334 |
| 1477 | row = qMax(row, (*it).bottom()); executed (the execution status of this line is deduced): row = qMax(row, (*it).bottom()); | - |
| 1478 | break; executed: break;Execution Count:330 | 330 |
| 1479 | } | - |
| 1480 | } executed: }Execution Count:4 | 4 |
| 1481 | } executed: }Execution Count:1382 | 1382 |
| 1482 | if (it == joined.constEnd()) evaluated: it == joined.constEnd()| yes Evaluation Count:739 | yes Evaluation Count:330 |
| 330-739 |
| 1483 | return false; executed: return false;Execution Count:739 | 739 |
| 1484 | } executed: }Execution Count:330 | 330 |
| 1485 | return rowCount > 0; // no rows means no selected items executed: return rowCount > 0;Execution Count:127 | 127 |
| 1486 | } | - |
| 1487 | | - |
| 1488 | /*! | - |
| 1489 | Returns true if there are any items selected in the \a row with the given | - |
| 1490 | \a parent. | - |
| 1491 | */ | - |
| 1492 | bool QItemSelectionModel::rowIntersectsSelection(int row, const QModelIndex &parent) const | - |
| 1493 | { | - |
| 1494 | Q_D(const QItemSelectionModel); executed (the execution status of this line is deduced): const QItemSelectionModelPrivate * const d = d_func(); | - |
| 1495 | if (parent.isValid() && d->model != parent.model()) evaluated: parent.isValid()| yes Evaluation Count:3 | yes Evaluation Count:926 |
partially evaluated: d->model != parent.model()| no Evaluation Count:0 | yes Evaluation Count:3 |
| 0-926 |
| 1496 | return false; never executed: return false; | 0 |
| 1497 | | - |
| 1498 | QItemSelection sel = d->ranges; executed (the execution status of this line is deduced): QItemSelection sel = d->ranges; | - |
| 1499 | sel.merge(d->currentSelection, d->currentCommand); executed (the execution status of this line is deduced): sel.merge(d->currentSelection, d->currentCommand); | - |
| 1500 | for (int i = 0; i < sel.count(); ++i) { evaluated: i < sel.count()| yes Evaluation Count:811 | yes Evaluation Count:651 |
| 651-811 |
| 1501 | QItemSelectionRange range = sel.at(i); executed (the execution status of this line is deduced): QItemSelectionRange range = sel.at(i); | - |
| 1502 | if (range.parent() != parent) evaluated: range.parent() != parent| yes Evaluation Count:3 | yes Evaluation Count:808 |
| 3-808 |
| 1503 | return false; executed: return false;Execution Count:3 | 3 |
| 1504 | int top = range.top(); executed (the execution status of this line is deduced): int top = range.top(); | - |
| 1505 | int bottom = range.bottom(); executed (the execution status of this line is deduced): int bottom = range.bottom(); | - |
| 1506 | int left = range.left(); executed (the execution status of this line is deduced): int left = range.left(); | - |
| 1507 | int right = range.right(); executed (the execution status of this line is deduced): int right = range.right(); | - |
| 1508 | if (top <= row && bottom >= row) { evaluated: top <= row| yes Evaluation Count:554 | yes Evaluation Count:254 |
evaluated: bottom >= row| yes Evaluation Count:317 | yes Evaluation Count:237 |
| 237-554 |
| 1509 | for (int j = left; j <= right; j++) { evaluated: j <= right| yes Evaluation Count:334 | yes Evaluation Count:42 |
| 42-334 |
| 1510 | const Qt::ItemFlags flags = d->model->index(row, j, parent).flags(); executed (the execution status of this line is deduced): const Qt::ItemFlags flags = d->model->index(row, j, parent).flags(); | - |
| 1511 | if ((flags & Qt::ItemIsSelectable) && (flags & Qt::ItemIsEnabled)) partially evaluated: (flags & Qt::ItemIsSelectable)| yes Evaluation Count:334 | no Evaluation Count:0 |
evaluated: (flags & Qt::ItemIsEnabled)| yes Evaluation Count:275 | yes Evaluation Count:59 |
| 0-334 |
| 1512 | return true; executed: return true;Execution Count:275 | 275 |
| 1513 | } executed: }Execution Count:59 | 59 |
| 1514 | } executed: }Execution Count:42 | 42 |
| 1515 | } executed: }Execution Count:533 | 533 |
| 1516 | | - |
| 1517 | return false; executed: return false;Execution Count:651 | 651 |
| 1518 | } | - |
| 1519 | | - |
| 1520 | /*! | - |
| 1521 | Returns true if there are any items selected in the \a column with the given | - |
| 1522 | \a parent. | - |
| 1523 | */ | - |
| 1524 | bool QItemSelectionModel::columnIntersectsSelection(int column, const QModelIndex &parent) const | - |
| 1525 | { | - |
| 1526 | Q_D(const QItemSelectionModel); executed (the execution status of this line is deduced): const QItemSelectionModelPrivate * const d = d_func(); | - |
| 1527 | if (parent.isValid() && d->model != parent.model()) partially evaluated: parent.isValid()| no Evaluation Count:0 | yes Evaluation Count:495 |
never evaluated: d->model != parent.model() | 0-495 |
| 1528 | return false; never executed: return false; | 0 |
| 1529 | | - |
| 1530 | QItemSelection sel = d->ranges; executed (the execution status of this line is deduced): QItemSelection sel = d->ranges; | - |
| 1531 | sel.merge(d->currentSelection, d->currentCommand); executed (the execution status of this line is deduced): sel.merge(d->currentSelection, d->currentCommand); | - |
| 1532 | for (int i = 0; i < sel.count(); ++i) { evaluated: i < sel.count()| yes Evaluation Count:348 | yes Evaluation Count:284 |
| 284-348 |
| 1533 | int left = sel.at(i).left(); executed (the execution status of this line is deduced): int left = sel.at(i).left(); | - |
| 1534 | int right = sel.at(i).right(); executed (the execution status of this line is deduced): int right = sel.at(i).right(); | - |
| 1535 | int top = sel.at(i).top(); executed (the execution status of this line is deduced): int top = sel.at(i).top(); | - |
| 1536 | int bottom = sel.at(i).bottom(); executed (the execution status of this line is deduced): int bottom = sel.at(i).bottom(); | - |
| 1537 | if (left <= column && right >= column) { evaluated: left <= column| yes Evaluation Count:301 | yes Evaluation Count:47 |
evaluated: right >= column| yes Evaluation Count:219 | yes Evaluation Count:82 |
| 47-301 |
| 1538 | for (int j = top; j <= bottom; j++) { evaluated: j <= bottom| yes Evaluation Count:229 | yes Evaluation Count:8 |
| 8-229 |
| 1539 | const Qt::ItemFlags flags = d->model->index(j, column, parent).flags(); executed (the execution status of this line is deduced): const Qt::ItemFlags flags = d->model->index(j, column, parent).flags(); | - |
| 1540 | if ((flags & Qt::ItemIsSelectable) && (flags & Qt::ItemIsEnabled)) partially evaluated: (flags & Qt::ItemIsSelectable)| yes Evaluation Count:229 | no Evaluation Count:0 |
evaluated: (flags & Qt::ItemIsEnabled)| yes Evaluation Count:211 | yes Evaluation Count:18 |
| 0-229 |
| 1541 | return true; executed: return true;Execution Count:211 | 211 |
| 1542 | } executed: }Execution Count:18 | 18 |
| 1543 | } executed: }Execution Count:8 | 8 |
| 1544 | } executed: }Execution Count:137 | 137 |
| 1545 | | - |
| 1546 | return false; executed: return false;Execution Count:284 | 284 |
| 1547 | } | - |
| 1548 | | - |
| 1549 | /*! | - |
| 1550 | \since 4.2 | - |
| 1551 | | - |
| 1552 | Returns true if the selection model contains any selection ranges; | - |
| 1553 | otherwise returns false. | - |
| 1554 | */ | - |
| 1555 | bool QItemSelectionModel::hasSelection() const | - |
| 1556 | { | - |
| 1557 | Q_D(const QItemSelectionModel); executed (the execution status of this line is deduced): const QItemSelectionModelPrivate * const d = d_func(); | - |
| 1558 | if (d->currentCommand & (Toggle | Deselect)) { evaluated: d->currentCommand & (Toggle | Deselect)| yes Evaluation Count:69 | yes Evaluation Count:865 |
| 69-865 |
| 1559 | QItemSelection sel = d->ranges; executed (the execution status of this line is deduced): QItemSelection sel = d->ranges; | - |
| 1560 | sel.merge(d->currentSelection, d->currentCommand); executed (the execution status of this line is deduced): sel.merge(d->currentSelection, d->currentCommand); | - |
| 1561 | return !sel.isEmpty(); executed: return !sel.isEmpty();Execution Count:69 | 69 |
| 1562 | } else { | - |
| 1563 | return !(d->ranges.isEmpty() && d->currentSelection.isEmpty()); executed: return !(d->ranges.isEmpty() && d->currentSelection.isEmpty());Execution Count:865 | 865 |
| 1564 | } | - |
| 1565 | } | - |
| 1566 | | - |
| 1567 | /*! | - |
| 1568 | Returns a list of all selected model item indexes. The list contains no | - |
| 1569 | duplicates, and is not sorted. | - |
| 1570 | */ | - |
| 1571 | QModelIndexList QItemSelectionModel::selectedIndexes() const | - |
| 1572 | { | - |
| 1573 | Q_D(const QItemSelectionModel); executed (the execution status of this line is deduced): const QItemSelectionModelPrivate * const d = d_func(); | - |
| 1574 | QItemSelection selected = d->ranges; executed (the execution status of this line is deduced): QItemSelection selected = d->ranges; | - |
| 1575 | selected.merge(d->currentSelection, d->currentCommand); executed (the execution status of this line is deduced): selected.merge(d->currentSelection, d->currentCommand); | - |
| 1576 | return selected.indexes(); executed: return selected.indexes();Execution Count:408 | 408 |
| 1577 | } | - |
| 1578 | | - |
| 1579 | /*! | - |
| 1580 | \since 4.2 | - |
| 1581 | Returns the indexes in the given \a column for the rows where all columns are selected. | - |
| 1582 | | - |
| 1583 | \sa selectedIndexes(), selectedColumns() | - |
| 1584 | */ | - |
| 1585 | | - |
| 1586 | QModelIndexList QItemSelectionModel::selectedRows(int column) const | - |
| 1587 | { | - |
| 1588 | QModelIndexList indexes; executed (the execution status of this line is deduced): QModelIndexList indexes; | - |
| 1589 | //the QSet contains pairs of parent modelIndex | - |
| 1590 | //and row number | - |
| 1591 | QSet< QPair<QModelIndex, int> > rowsSeen; executed (the execution status of this line is deduced): QSet< QPair<QModelIndex, int> > rowsSeen; | - |
| 1592 | | - |
| 1593 | const QItemSelection ranges = selection(); executed (the execution status of this line is deduced): const QItemSelection ranges = selection(); | - |
| 1594 | for (int i = 0; i < ranges.count(); ++i) { evaluated: i < ranges.count()| yes Evaluation Count:255 | yes Evaluation Count:778 |
| 255-778 |
| 1595 | const QItemSelectionRange &range = ranges.at(i); executed (the execution status of this line is deduced): const QItemSelectionRange &range = ranges.at(i); | - |
| 1596 | QModelIndex parent = range.parent(); executed (the execution status of this line is deduced): QModelIndex parent = range.parent(); | - |
| 1597 | for (int row = range.top(); row <= range.bottom(); row++) { evaluated: row <= range.bottom()| yes Evaluation Count:282 | yes Evaluation Count:255 |
| 255-282 |
| 1598 | QPair<QModelIndex, int> rowDef = qMakePair(parent, row); executed (the execution status of this line is deduced): QPair<QModelIndex, int> rowDef = qMakePair(parent, row); | - |
| 1599 | if (!rowsSeen.contains(rowDef)) { partially evaluated: !rowsSeen.contains(rowDef)| yes Evaluation Count:282 | no Evaluation Count:0 |
| 0-282 |
| 1600 | rowsSeen << rowDef; executed (the execution status of this line is deduced): rowsSeen << rowDef; | - |
| 1601 | if (isRowSelected(row, parent)) { evaluated: isRowSelected(row, parent)| yes Evaluation Count:272 | yes Evaluation Count:10 |
| 10-272 |
| 1602 | indexes.append(model()->index(row, column, parent)); executed (the execution status of this line is deduced): indexes.append(model()->index(row, column, parent)); | - |
| 1603 | } executed: }Execution Count:272 | 272 |
| 1604 | } executed: }Execution Count:282 | 282 |
| 1605 | } executed: }Execution Count:282 | 282 |
| 1606 | } executed: }Execution Count:255 | 255 |
| 1607 | | - |
| 1608 | return indexes; executed: return indexes;Execution Count:778 | 778 |
| 1609 | } | - |
| 1610 | | - |
| 1611 | /*! | - |
| 1612 | \since 4.2 | - |
| 1613 | Returns the indexes in the given \a row for columns where all rows are selected. | - |
| 1614 | | - |
| 1615 | \sa selectedIndexes(), selectedRows() | - |
| 1616 | */ | - |
| 1617 | | - |
| 1618 | QModelIndexList QItemSelectionModel::selectedColumns(int row) const | - |
| 1619 | { | - |
| 1620 | QModelIndexList indexes; executed (the execution status of this line is deduced): QModelIndexList indexes; | - |
| 1621 | //the QSet contains pairs of parent modelIndex | - |
| 1622 | //and column number | - |
| 1623 | QSet< QPair<QModelIndex, int> > columnsSeen; executed (the execution status of this line is deduced): QSet< QPair<QModelIndex, int> > columnsSeen; | - |
| 1624 | | - |
| 1625 | const QItemSelection ranges = selection(); executed (the execution status of this line is deduced): const QItemSelection ranges = selection(); | - |
| 1626 | for (int i = 0; i < ranges.count(); ++i) { evaluated: i < ranges.count()| yes Evaluation Count:22 | yes Evaluation Count:10 |
| 10-22 |
| 1627 | const QItemSelectionRange &range = ranges.at(i); executed (the execution status of this line is deduced): const QItemSelectionRange &range = ranges.at(i); | - |
| 1628 | QModelIndex parent = range.parent(); executed (the execution status of this line is deduced): QModelIndex parent = range.parent(); | - |
| 1629 | for (int column = range.left(); column <= range.right(); column++) { evaluated: column <= range.right()| yes Evaluation Count:59 | yes Evaluation Count:22 |
| 22-59 |
| 1630 | QPair<QModelIndex, int> columnDef = qMakePair(parent, column); executed (the execution status of this line is deduced): QPair<QModelIndex, int> columnDef = qMakePair(parent, column); | - |
| 1631 | if (!columnsSeen.contains(columnDef)) { partially evaluated: !columnsSeen.contains(columnDef)| yes Evaluation Count:59 | no Evaluation Count:0 |
| 0-59 |
| 1632 | columnsSeen << columnDef; executed (the execution status of this line is deduced): columnsSeen << columnDef; | - |
| 1633 | if (isColumnSelected(column, parent)) { evaluated: isColumnSelected(column, parent)| yes Evaluation Count:29 | yes Evaluation Count:30 |
| 29-30 |
| 1634 | indexes.append(model()->index(row, column, parent)); executed (the execution status of this line is deduced): indexes.append(model()->index(row, column, parent)); | - |
| 1635 | } executed: }Execution Count:29 | 29 |
| 1636 | } executed: }Execution Count:59 | 59 |
| 1637 | } executed: }Execution Count:59 | 59 |
| 1638 | } executed: }Execution Count:22 | 22 |
| 1639 | | - |
| 1640 | return indexes; executed: return indexes;Execution Count:10 | 10 |
| 1641 | } | - |
| 1642 | | - |
| 1643 | /*! | - |
| 1644 | Returns the selection ranges stored in the selection model. | - |
| 1645 | */ | - |
| 1646 | const QItemSelection QItemSelectionModel::selection() const | - |
| 1647 | { | - |
| 1648 | Q_D(const QItemSelectionModel); executed (the execution status of this line is deduced): const QItemSelectionModelPrivate * const d = d_func(); | - |
| 1649 | QItemSelection selected = d->ranges; executed (the execution status of this line is deduced): QItemSelection selected = d->ranges; | - |
| 1650 | selected.merge(d->currentSelection, d->currentCommand); executed (the execution status of this line is deduced): selected.merge(d->currentSelection, d->currentCommand); | - |
| 1651 | int i = 0; executed (the execution status of this line is deduced): int i = 0; | - |
| 1652 | // make sure we have no invalid ranges | - |
| 1653 | // ### should probably be handled more generic somewhere else | - |
| 1654 | while (i<selected.count()) { evaluated: i<selected.count()| yes Evaluation Count:361 | yes Evaluation Count:1143 |
| 361-1143 |
| 1655 | if (selected.at(i).isValid()) partially evaluated: selected.at(i).isValid()| yes Evaluation Count:361 | no Evaluation Count:0 |
| 0-361 |
| 1656 | ++i; executed: ++i;Execution Count:361 | 361 |
| 1657 | else | - |
| 1658 | (selected.removeAt(i)); never executed: (selected.removeAt(i)); | 0 |
| 1659 | } | - |
| 1660 | return selected; executed: return selected;Execution Count:1143 | 1143 |
| 1661 | } | - |
| 1662 | | - |
| 1663 | /*! | - |
| 1664 | Returns the item model operated on by the selection model. | - |
| 1665 | */ | - |
| 1666 | const QAbstractItemModel *QItemSelectionModel::model() const | - |
| 1667 | { | - |
| 1668 | return d_func()->model; executed: return d_func()->model;Execution Count:6492 | 6492 |
| 1669 | } | - |
| 1670 | | - |
| 1671 | /*! | - |
| 1672 | Compares the two selections \a newSelection and \a oldSelection | - |
| 1673 | and emits selectionChanged() with the deselected and selected items. | - |
| 1674 | */ | - |
| 1675 | void QItemSelectionModel::emitSelectionChanged(const QItemSelection &newSelection, | - |
| 1676 | const QItemSelection &oldSelection) | - |
| 1677 | { | - |
| 1678 | // if both selections are empty or equal we return | - |
| 1679 | if ((oldSelection.isEmpty() && newSelection.isEmpty()) || evaluated: oldSelection.isEmpty()| yes Evaluation Count:2374 | yes Evaluation Count:4119 |
evaluated: newSelection.isEmpty()| yes Evaluation Count:622 | yes Evaluation Count:1752 |
| 622-4119 |
| 1680 | oldSelection == newSelection) evaluated: oldSelection == newSelection| yes Evaluation Count:974 | yes Evaluation Count:4897 |
| 974-4897 |
| 1681 | return; executed: return;Execution Count:1596 | 1596 |
| 1682 | | - |
| 1683 | // if either selection is empty we do not need to compare | - |
| 1684 | if (oldSelection.isEmpty() || newSelection.isEmpty()) { evaluated: oldSelection.isEmpty()| yes Evaluation Count:1752 | yes Evaluation Count:3145 |
evaluated: newSelection.isEmpty()| yes Evaluation Count:970 | yes Evaluation Count:2175 |
| 970-3145 |
| 1685 | emit selectionChanged(newSelection, oldSelection); executed (the execution status of this line is deduced): selectionChanged(newSelection, oldSelection); | - |
| 1686 | return; executed: return;Execution Count:2722 | 2722 |
| 1687 | } | - |
| 1688 | | - |
| 1689 | QItemSelection deselected = oldSelection; executed (the execution status of this line is deduced): QItemSelection deselected = oldSelection; | - |
| 1690 | QItemSelection selected = newSelection; executed (the execution status of this line is deduced): QItemSelection selected = newSelection; | - |
| 1691 | | - |
| 1692 | // remove equal ranges | - |
| 1693 | bool advance; executed (the execution status of this line is deduced): bool advance; | - |
| 1694 | for (int o = 0; o < deselected.count(); ++o) { evaluated: o < deselected.count()| yes Evaluation Count:2348 | yes Evaluation Count:2175 |
| 2175-2348 |
| 1695 | advance = true; executed (the execution status of this line is deduced): advance = true; | - |
| 1696 | for (int s = 0; s < selected.count() && o < deselected.count();) { evaluated: s < selected.count()| yes Evaluation Count:3376 | yes Evaluation Count:2186 |
evaluated: o < deselected.count()| yes Evaluation Count:3214 | yes Evaluation Count:162 |
| 162-3376 |
| 1697 | if (deselected.at(o) == selected.at(s)) { evaluated: deselected.at(o) == selected.at(s)| yes Evaluation Count:632 | yes Evaluation Count:2582 |
| 632-2582 |
| 1698 | deselected.removeAt(o); executed (the execution status of this line is deduced): deselected.removeAt(o); | - |
| 1699 | selected.removeAt(s); executed (the execution status of this line is deduced): selected.removeAt(s); | - |
| 1700 | advance = false; executed (the execution status of this line is deduced): advance = false; | - |
| 1701 | } else { executed: }Execution Count:632 | 632 |
| 1702 | ++s; executed (the execution status of this line is deduced): ++s; | - |
| 1703 | } executed: }Execution Count:2582 | 2582 |
| 1704 | } | - |
| 1705 | if (advance) evaluated: advance| yes Evaluation Count:2107 | yes Evaluation Count:241 |
| 241-2107 |
| 1706 | ++o; executed: ++o;Execution Count:2107 | 2107 |
| 1707 | } executed: }Execution Count:2348 | 2348 |
| 1708 | | - |
| 1709 | // find intersections | - |
| 1710 | QItemSelection intersections; executed (the execution status of this line is deduced): QItemSelection intersections; | - |
| 1711 | for (int o = 0; o < deselected.count(); ++o) { evaluated: o < deselected.count()| yes Evaluation Count:2315 | yes Evaluation Count:2175 |
| 2175-2315 |
| 1712 | for (int s = 0; s < selected.count(); ++s) { evaluated: s < selected.count()| yes Evaluation Count:2608 | yes Evaluation Count:2315 |
| 2315-2608 |
| 1713 | if (deselected.at(o).intersects(selected.at(s))) evaluated: deselected.at(o).intersects(selected.at(s))| yes Evaluation Count:305 | yes Evaluation Count:2303 |
| 305-2303 |
| 1714 | intersections.append(deselected.at(o).intersected(selected.at(s))); executed: intersections.append(deselected.at(o).intersected(selected.at(s)));Execution Count:305 | 305 |
| 1715 | } executed: }Execution Count:2608 | 2608 |
| 1716 | } executed: }Execution Count:2315 | 2315 |
| 1717 | | - |
| 1718 | // compare remaining ranges with intersections and split them to find deselected and selected | - |
| 1719 | for (int i = 0; i < intersections.count(); ++i) { evaluated: i < intersections.count()| yes Evaluation Count:305 | yes Evaluation Count:2175 |
| 305-2175 |
| 1720 | // split deselected | - |
| 1721 | for (int o = 0; o < deselected.count();) { evaluated: o < deselected.count()| yes Evaluation Count:755 | yes Evaluation Count:305 |
| 305-755 |
| 1722 | if (deselected.at(o).intersects(intersections.at(i))) { evaluated: deselected.at(o).intersects(intersections.at(i))| yes Evaluation Count:305 | yes Evaluation Count:450 |
| 305-450 |
| 1723 | QItemSelection::split(deselected.at(o), intersections.at(i), &deselected); executed (the execution status of this line is deduced): QItemSelection::split(deselected.at(o), intersections.at(i), &deselected); | - |
| 1724 | deselected.removeAt(o); executed (the execution status of this line is deduced): deselected.removeAt(o); | - |
| 1725 | } else { executed: }Execution Count:305 | 305 |
| 1726 | ++o; executed (the execution status of this line is deduced): ++o; | - |
| 1727 | } executed: }Execution Count:450 | 450 |
| 1728 | } | - |
| 1729 | // split selected | - |
| 1730 | for (int s = 0; s < selected.count();) { evaluated: s < selected.count()| yes Evaluation Count:748 | yes Evaluation Count:305 |
| 305-748 |
| 1731 | if (selected.at(s).intersects(intersections.at(i))) { evaluated: selected.at(s).intersects(intersections.at(i))| yes Evaluation Count:315 | yes Evaluation Count:433 |
| 315-433 |
| 1732 | QItemSelection::split(selected.at(s), intersections.at(i), &selected); executed (the execution status of this line is deduced): QItemSelection::split(selected.at(s), intersections.at(i), &selected); | - |
| 1733 | selected.removeAt(s); executed (the execution status of this line is deduced): selected.removeAt(s); | - |
| 1734 | } else { executed: }Execution Count:315 | 315 |
| 1735 | ++s; executed (the execution status of this line is deduced): ++s; | - |
| 1736 | } executed: }Execution Count:433 | 433 |
| 1737 | } | - |
| 1738 | } executed: }Execution Count:305 | 305 |
| 1739 | | - |
| 1740 | if (!selected.isEmpty() || !deselected.isEmpty()) evaluated: !selected.isEmpty()| yes Evaluation Count:2065 | yes Evaluation Count:110 |
evaluated: !deselected.isEmpty()| yes Evaluation Count:84 | yes Evaluation Count:26 |
| 26-2065 |
| 1741 | emit selectionChanged(selected, deselected); executed: selectionChanged(selected, deselected);Execution Count:2149 | 2149 |
| 1742 | } executed: }Execution Count:2175 | 2175 |
| 1743 | | - |
| 1744 | #ifndef QT_NO_DEBUG_STREAM | - |
| 1745 | QDebug operator<<(QDebug dbg, const QItemSelectionRange &range) | - |
| 1746 | { | - |
| 1747 | dbg.nospace() << "QItemSelectionRange(" << range.topLeft() never executed (the execution status of this line is deduced): dbg.nospace() << "QItemSelectionRange(" << range.topLeft() | - |
| 1748 | << ',' << range.bottomRight() << ')'; never executed (the execution status of this line is deduced): << ',' << range.bottomRight() << ')'; | - |
| 1749 | return dbg.space(); never executed: return dbg.space(); | 0 |
| 1750 | } | - |
| 1751 | #endif | - |
| 1752 | | - |
| 1753 | QT_END_NAMESPACE | - |
| 1754 | | - |
| 1755 | #include "moc_qitemselectionmodel.cpp" | - |
| 1756 | | - |
| 1757 | #endif // QT_NO_ITEMVIEWS | - |
| 1758 | | - |
| | |