| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/gui/itemmodels/qstandarditemmodel.cpp |
| Source code | Switch to Preprocessed file |
| Line | Source | Count | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | /**************************************************************************** | - | ||||||||||||||||||
| 2 | ** | - | ||||||||||||||||||
| 3 | ** Copyright (C) 2016 The Qt Company Ltd. | - | ||||||||||||||||||
| 4 | ** Contact: https://www.qt.io/licensing/ | - | ||||||||||||||||||
| 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 The Qt Company. For licensing terms | - | ||||||||||||||||||
| 14 | ** and conditions see https://www.qt.io/terms-conditions. For further | - | ||||||||||||||||||
| 15 | ** information use the contact form at https://www.qt.io/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 3 as published by the Free Software | - | ||||||||||||||||||
| 20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the | - | ||||||||||||||||||
| 21 | ** packaging of this file. Please review the following information to | - | ||||||||||||||||||
| 22 | ** ensure the GNU Lesser General Public License version 3 requirements | - | ||||||||||||||||||
| 23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. | - | ||||||||||||||||||
| 24 | ** | - | ||||||||||||||||||
| 25 | ** GNU General Public License Usage | - | ||||||||||||||||||
| 26 | ** Alternatively, this file may be used under the terms of the GNU | - | ||||||||||||||||||
| 27 | ** General Public License version 2.0 or (at your option) the GNU General | - | ||||||||||||||||||
| 28 | ** Public license version 3 or any later version approved by the KDE Free | - | ||||||||||||||||||
| 29 | ** Qt Foundation. The licenses are as published by the Free Software | - | ||||||||||||||||||
| 30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 | - | ||||||||||||||||||
| 31 | ** included in the packaging of this file. Please review the following | - | ||||||||||||||||||
| 32 | ** information to ensure the GNU General Public License requirements will | - | ||||||||||||||||||
| 33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and | - | ||||||||||||||||||
| 34 | ** https://www.gnu.org/licenses/gpl-3.0.html. | - | ||||||||||||||||||
| 35 | ** | - | ||||||||||||||||||
| 36 | ** $QT_END_LICENSE$ | - | ||||||||||||||||||
| 37 | ** | - | ||||||||||||||||||
| 38 | ****************************************************************************/ | - | ||||||||||||||||||
| 39 | - | |||||||||||||||||||
| 40 | #include "qstandarditemmodel.h" | - | ||||||||||||||||||
| 41 | - | |||||||||||||||||||
| 42 | #ifndef QT_NO_STANDARDITEMMODEL | - | ||||||||||||||||||
| 43 | - | |||||||||||||||||||
| 44 | #include <QtCore/qdatetime.h> | - | ||||||||||||||||||
| 45 | #include <QtCore/qlist.h> | - | ||||||||||||||||||
| 46 | #include <QtCore/qmap.h> | - | ||||||||||||||||||
| 47 | #include <QtCore/qpair.h> | - | ||||||||||||||||||
| 48 | #include <QtCore/qvariant.h> | - | ||||||||||||||||||
| 49 | #include <QtCore/qvector.h> | - | ||||||||||||||||||
| 50 | #include <QtCore/qstringlist.h> | - | ||||||||||||||||||
| 51 | #include <QtCore/qbitarray.h> | - | ||||||||||||||||||
| 52 | #include <QtCore/qmimedata.h> | - | ||||||||||||||||||
| 53 | - | |||||||||||||||||||
| 54 | #include <private/qstandarditemmodel_p.h> | - | ||||||||||||||||||
| 55 | #include <qdebug.h> | - | ||||||||||||||||||
| 56 | #include <algorithm> | - | ||||||||||||||||||
| 57 | - | |||||||||||||||||||
| 58 | QT_BEGIN_NAMESPACE | - | ||||||||||||||||||
| 59 | - | |||||||||||||||||||
| 60 | static inline QString qStandardItemModelDataListMimeType() | - | ||||||||||||||||||
| 61 | { | - | ||||||||||||||||||
| 62 | return QStringLiteral("application/x-qstandarditemmodeldatalist"); never executed: return ([]() -> QString { enum { Size = sizeof(u"" "application/x-qstandarditemmodeldatalist")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "application/x-qstandarditemmodeldatalist" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }());never executed: return qstring_literal_temp; | 0 | ||||||||||||||||||
| 63 | } | - | ||||||||||||||||||
| 64 | - | |||||||||||||||||||
| 65 | class QStandardItemModelLessThan | - | ||||||||||||||||||
| 66 | { | - | ||||||||||||||||||
| 67 | public: | - | ||||||||||||||||||
| 68 | inline QStandardItemModelLessThan() | - | ||||||||||||||||||
| 69 | { } | - | ||||||||||||||||||
| 70 | - | |||||||||||||||||||
| 71 | inline bool operator()(const QPair<QStandardItem*, int> &l, | - | ||||||||||||||||||
| 72 | const QPair<QStandardItem*, int> &r) const | - | ||||||||||||||||||
| 73 | { | - | ||||||||||||||||||
| 74 | return *(l.first) < *(r.first); | - | ||||||||||||||||||
| 75 | } | - | ||||||||||||||||||
| 76 | }; | - | ||||||||||||||||||
| 77 | - | |||||||||||||||||||
| 78 | class QStandardItemModelGreaterThan | - | ||||||||||||||||||
| 79 | { | - | ||||||||||||||||||
| 80 | public: | - | ||||||||||||||||||
| 81 | inline QStandardItemModelGreaterThan() | - | ||||||||||||||||||
| 82 | { } | - | ||||||||||||||||||
| 83 | - | |||||||||||||||||||
| 84 | inline bool operator()(const QPair<QStandardItem*, int> &l, | - | ||||||||||||||||||
| 85 | const QPair<QStandardItem*, int> &r) const | - | ||||||||||||||||||
| 86 | { | - | ||||||||||||||||||
| 87 | return *(r.first) < *(l.first); | - | ||||||||||||||||||
| 88 | } | - | ||||||||||||||||||
| 89 | }; | - | ||||||||||||||||||
| 90 | - | |||||||||||||||||||
| 91 | /*! | - | ||||||||||||||||||
| 92 | \internal | - | ||||||||||||||||||
| 93 | */ | - | ||||||||||||||||||
| 94 | QStandardItemPrivate::~QStandardItemPrivate() | - | ||||||||||||||||||
| 95 | { | - | ||||||||||||||||||
| 96 | QVector<QStandardItem*>::const_iterator it; | - | ||||||||||||||||||
| 97 | for (it = children.constBegin(); it != children.constEnd(); ++it) { | - | ||||||||||||||||||
| 98 | QStandardItem *child = *it; | - | ||||||||||||||||||
| 99 | if (child) | - | ||||||||||||||||||
| 100 | child->d_func()->setModel(0); | - | ||||||||||||||||||
| 101 | delete child; | - | ||||||||||||||||||
| 102 | } | - | ||||||||||||||||||
| 103 | children.clear(); | - | ||||||||||||||||||
| 104 | if (parent && model) | - | ||||||||||||||||||
| 105 | parent->d_func()->childDeleted(q_func()); | - | ||||||||||||||||||
| 106 | } | - | ||||||||||||||||||
| 107 | - | |||||||||||||||||||
| 108 | /*! | - | ||||||||||||||||||
| 109 | \internal | - | ||||||||||||||||||
| 110 | */ | - | ||||||||||||||||||
| 111 | QPair<int, int> QStandardItemPrivate::position() const | - | ||||||||||||||||||
| 112 | { | - | ||||||||||||||||||
| 113 | if (QStandardItem *par = parent) { | - | ||||||||||||||||||
| 114 | int idx = par->d_func()->childIndex(q_func()); | - | ||||||||||||||||||
| 115 | if (idx == -1) | - | ||||||||||||||||||
| 116 | return QPair<int, int>(-1, -1); | - | ||||||||||||||||||
| 117 | return QPair<int, int>(idx / par->columnCount(), idx % par->columnCount()); | - | ||||||||||||||||||
| 118 | } | - | ||||||||||||||||||
| 119 | // ### support header items? | - | ||||||||||||||||||
| 120 | return QPair<int, int>(-1, -1); | - | ||||||||||||||||||
| 121 | } | - | ||||||||||||||||||
| 122 | - | |||||||||||||||||||
| 123 | /*! | - | ||||||||||||||||||
| 124 | \internal | - | ||||||||||||||||||
| 125 | */ | - | ||||||||||||||||||
| 126 | void QStandardItemPrivate::setChild(int row, int column, QStandardItem *item, | - | ||||||||||||||||||
| 127 | bool emitChanged) | - | ||||||||||||||||||
| 128 | { | - | ||||||||||||||||||
| 129 | Q_Q(QStandardItem); | - | ||||||||||||||||||
| 130 | if (item == q) { | - | ||||||||||||||||||
| 131 | qWarning("QStandardItem::setChild: Can't make an item a child of itself %p", | - | ||||||||||||||||||
| 132 | item); | - | ||||||||||||||||||
| 133 | return; | - | ||||||||||||||||||
| 134 | } | - | ||||||||||||||||||
| 135 | if ((row < 0) || (column < 0)) | - | ||||||||||||||||||
| 136 | return; | - | ||||||||||||||||||
| 137 | if (rows <= row) | - | ||||||||||||||||||
| 138 | q->setRowCount(row + 1); | - | ||||||||||||||||||
| 139 | if (columns <= column) | - | ||||||||||||||||||
| 140 | q->setColumnCount(column + 1); | - | ||||||||||||||||||
| 141 | int index = childIndex(row, column); | - | ||||||||||||||||||
| 142 | Q_ASSERT(index != -1); | - | ||||||||||||||||||
| 143 | QStandardItem *oldItem = children.at(index); | - | ||||||||||||||||||
| 144 | if (item == oldItem) | - | ||||||||||||||||||
| 145 | return; | - | ||||||||||||||||||
| 146 | - | |||||||||||||||||||
| 147 | if (model && emitChanged) { | - | ||||||||||||||||||
| 148 | emit model->layoutAboutToBeChanged(); | - | ||||||||||||||||||
| 149 | } | - | ||||||||||||||||||
| 150 | - | |||||||||||||||||||
| 151 | if (item) { | - | ||||||||||||||||||
| 152 | if (item->d_func()->parent == 0) { | - | ||||||||||||||||||
| 153 | item->d_func()->setParentAndModel(q, model); | - | ||||||||||||||||||
| 154 | } else { | - | ||||||||||||||||||
| 155 | qWarning("QStandardItem::setChild: Ignoring duplicate insertion of item %p", | - | ||||||||||||||||||
| 156 | item); | - | ||||||||||||||||||
| 157 | return; | - | ||||||||||||||||||
| 158 | } | - | ||||||||||||||||||
| 159 | } | - | ||||||||||||||||||
| 160 | if (oldItem) | - | ||||||||||||||||||
| 161 | oldItem->d_func()->setModel(0); | - | ||||||||||||||||||
| 162 | delete oldItem; | - | ||||||||||||||||||
| 163 | children.replace(index, item); | - | ||||||||||||||||||
| 164 | - | |||||||||||||||||||
| 165 | if (model && emitChanged) | - | ||||||||||||||||||
| 166 | emit model->layoutChanged(); | - | ||||||||||||||||||
| 167 | - | |||||||||||||||||||
| 168 | if (emitChanged && model) | - | ||||||||||||||||||
| 169 | model->d_func()->itemChanged(item); | - | ||||||||||||||||||
| 170 | } | - | ||||||||||||||||||
| 171 | - | |||||||||||||||||||
| 172 | - | |||||||||||||||||||
| 173 | /*! | - | ||||||||||||||||||
| 174 | \internal | - | ||||||||||||||||||
| 175 | */ | - | ||||||||||||||||||
| 176 | void QStandardItemPrivate::changeFlags(bool enable, Qt::ItemFlags f) | - | ||||||||||||||||||
| 177 | { | - | ||||||||||||||||||
| 178 | Q_Q(QStandardItem); | - | ||||||||||||||||||
| 179 | Qt::ItemFlags flags = q->flags(); | - | ||||||||||||||||||
| 180 | if (enable) | - | ||||||||||||||||||
| 181 | flags |= f; | - | ||||||||||||||||||
| 182 | else | - | ||||||||||||||||||
| 183 | flags &= ~f; | - | ||||||||||||||||||
| 184 | q->setFlags(flags); | - | ||||||||||||||||||
| 185 | } | - | ||||||||||||||||||
| 186 | - | |||||||||||||||||||
| 187 | /*! | - | ||||||||||||||||||
| 188 | \internal | - | ||||||||||||||||||
| 189 | */ | - | ||||||||||||||||||
| 190 | void QStandardItemPrivate::childDeleted(QStandardItem *child) | - | ||||||||||||||||||
| 191 | { | - | ||||||||||||||||||
| 192 | int index = childIndex(child); | - | ||||||||||||||||||
| 193 | Q_ASSERT(index != -1); | - | ||||||||||||||||||
| 194 | children.replace(index, 0); | - | ||||||||||||||||||
| 195 | } | - | ||||||||||||||||||
| 196 | - | |||||||||||||||||||
| 197 | /*! | - | ||||||||||||||||||
| 198 | \internal | - | ||||||||||||||||||
| 199 | */ | - | ||||||||||||||||||
| 200 | void QStandardItemPrivate::setItemData(const QMap<int, QVariant> &roles) | - | ||||||||||||||||||
| 201 | { | - | ||||||||||||||||||
| 202 | Q_Q(QStandardItem); | - | ||||||||||||||||||
| 203 | - | |||||||||||||||||||
| 204 | //let's build the vector of new values | - | ||||||||||||||||||
| 205 | QVector<QStandardItemData> newValues; | - | ||||||||||||||||||
| QMap<int, QVariant>::const_iterator it; | ||||||||||||||||||||
| 206 | for (auto it = roles.begin(); it !=(), end = roles.end(); it != end; ++it) {
| 0 | ||||||||||||||||||
| 207 | const QVariant value&value = it.value(); | - | ||||||||||||||||||
| 208 | if (value.isValid()) {
| 0 | ||||||||||||||||||
| 209 | int role = it.key(); | - | ||||||||||||||||||
| 210 | role = (role == Qt::EditRole) ? Qt::DisplayRole : role;
| 0 | ||||||||||||||||||
| 211 | newValues.append(QStandardItemDatawid(role, it.value()); | - | ||||||||||||||||||
| newValues.append(wid);)); | ||||||||||||||||||||
| 212 | } never executed: end of block | 0 | ||||||||||||||||||
| 213 | } never executed: end of block | 0 | ||||||||||||||||||
| 214 | - | |||||||||||||||||||
| 215 | if (values!=newValues) {
| 0 | ||||||||||||||||||
| 216 | values=.swap(newValues;); | - | ||||||||||||||||||
| 217 | if (model)
| 0 | ||||||||||||||||||
| 218 | model->d_func()->itemChanged(q); never executed: model->d_func()->itemChanged(q); | 0 | ||||||||||||||||||
| 219 | } never executed: end of block | 0 | ||||||||||||||||||
| 220 | } never executed: end of block | 0 | ||||||||||||||||||
| 221 | - | |||||||||||||||||||
| 222 | /*! | - | ||||||||||||||||||
| 223 | \internal | - | ||||||||||||||||||
| 224 | */ | - | ||||||||||||||||||
| 225 | const QMap<int, QVariant> QStandardItemPrivate::itemData() const | - | ||||||||||||||||||
| 226 | { | - | ||||||||||||||||||
| 227 | QMap<int, QVariant> result; | - | ||||||||||||||||||
| 228 | QVector<QStandardItemData>::const_iterator it; | - | ||||||||||||||||||
| 229 | for (it = values.begin(); it != values.end(); ++it) | - | ||||||||||||||||||
| 230 | result.insert((*it).role, (*it).value); | - | ||||||||||||||||||
| 231 | return result; | - | ||||||||||||||||||
| 232 | } | - | ||||||||||||||||||
| 233 | - | |||||||||||||||||||
| 234 | /*! | - | ||||||||||||||||||
| 235 | \internal | - | ||||||||||||||||||
| 236 | */ | - | ||||||||||||||||||
| 237 | void QStandardItemPrivate::sortChildren(int column, Qt::SortOrder order) | - | ||||||||||||||||||
| 238 | { | - | ||||||||||||||||||
| 239 | Q_Q(QStandardItem); | - | ||||||||||||||||||
| 240 | if (column >= columnCount()) | - | ||||||||||||||||||
| 241 | return; | - | ||||||||||||||||||
| 242 | - | |||||||||||||||||||
| 243 | QVector<QPair<QStandardItem*, int> > sortable; | - | ||||||||||||||||||
| 244 | QVector<int> unsortable; | - | ||||||||||||||||||
| 245 | - | |||||||||||||||||||
| 246 | sortable.reserve(rowCount()); | - | ||||||||||||||||||
| 247 | unsortable.reserve(rowCount()); | - | ||||||||||||||||||
| 248 | - | |||||||||||||||||||
| 249 | for (int row = 0; row < rowCount(); ++row) { | - | ||||||||||||||||||
| 250 | QStandardItem *itm = q->child(row, column); | - | ||||||||||||||||||
| 251 | if (itm) | - | ||||||||||||||||||
| 252 | sortable.append(QPair<QStandardItem*,int>(itm, row)); | - | ||||||||||||||||||
| 253 | else | - | ||||||||||||||||||
| 254 | unsortable.append(row); | - | ||||||||||||||||||
| 255 | } | - | ||||||||||||||||||
| 256 | - | |||||||||||||||||||
| 257 | if (order == Qt::AscendingOrder) { | - | ||||||||||||||||||
| 258 | QStandardItemModelLessThan lt; | - | ||||||||||||||||||
| 259 | std::stable_sort(sortable.begin(), sortable.end(), lt); | - | ||||||||||||||||||
| 260 | } else { | - | ||||||||||||||||||
| 261 | QStandardItemModelGreaterThan gt; | - | ||||||||||||||||||
| 262 | std::stable_sort(sortable.begin(), sortable.end(), gt); | - | ||||||||||||||||||
| 263 | } | - | ||||||||||||||||||
| 264 | - | |||||||||||||||||||
| 265 | QModelIndexList changedPersistentIndexesFrom, changedPersistentIndexesTo; | - | ||||||||||||||||||
| 266 | QVector<QStandardItem*> sorted_children(children.count()); | - | ||||||||||||||||||
| 267 | for (int i = 0; i < rowCount(); ++i) { | - | ||||||||||||||||||
| 268 | int r = (i < sortable.count() | - | ||||||||||||||||||
| 269 | ? sortable.at(i).second | - | ||||||||||||||||||
| 270 | : unsortable.at(i - sortable.count())); | - | ||||||||||||||||||
| 271 | for (int c = 0; c < columnCount(); ++c) { | - | ||||||||||||||||||
| 272 | QStandardItem *itm = q->child(r, c); | - | ||||||||||||||||||
| 273 | sorted_children[childIndex(i, c)] = itm; | - | ||||||||||||||||||
| 274 | if (model) { | - | ||||||||||||||||||
| 275 | QModelIndex from = model->createIndex(r, c, q); | - | ||||||||||||||||||
| 276 | if (model->d_func()->persistent.indexes.contains(from)) { | - | ||||||||||||||||||
| 277 | QModelIndex to = model->createIndex(i, c, q); | - | ||||||||||||||||||
| 278 | changedPersistentIndexesFrom.append(from); | - | ||||||||||||||||||
| 279 | changedPersistentIndexesTo.append(to); | - | ||||||||||||||||||
| 280 | } | - | ||||||||||||||||||
| 281 | } | - | ||||||||||||||||||
| 282 | } | - | ||||||||||||||||||
| 283 | } | - | ||||||||||||||||||
| 284 | - | |||||||||||||||||||
| 285 | children = sorted_children; | - | ||||||||||||||||||
| 286 | - | |||||||||||||||||||
| 287 | if (model) { | - | ||||||||||||||||||
| 288 | model->changePersistentIndexList(changedPersistentIndexesFrom, changedPersistentIndexesTo); | - | ||||||||||||||||||
| 289 | } | - | ||||||||||||||||||
| 290 | - | |||||||||||||||||||
| 291 | QVector<QStandardItem*>::iterator it; | - | ||||||||||||||||||
| 292 | for (it = children.begin(); it != children.end(); ++it) { | - | ||||||||||||||||||
| 293 | if (*it) | - | ||||||||||||||||||
| 294 | (*it)->d_func()->sortChildren(column, order); | - | ||||||||||||||||||
| 295 | } | - | ||||||||||||||||||
| 296 | } | - | ||||||||||||||||||
| 297 | - | |||||||||||||||||||
| 298 | /*! | - | ||||||||||||||||||
| 299 | \internal | - | ||||||||||||||||||
| 300 | set the model of this item and all its children | - | ||||||||||||||||||
| 301 | */ | - | ||||||||||||||||||
| 302 | void QStandardItemPrivate::setModel(QStandardItemModel *mod) | - | ||||||||||||||||||
| 303 | { | - | ||||||||||||||||||
| 304 | if (children.isEmpty()) { | - | ||||||||||||||||||
| 305 | if (model) | - | ||||||||||||||||||
| 306 | model->d_func()->invalidatePersistentIndex(model->indexFromItem(q_ptr)); | - | ||||||||||||||||||
| 307 | model = mod; | - | ||||||||||||||||||
| 308 | } else { | - | ||||||||||||||||||
| 309 | QStack<QStandardItem*> stack; | - | ||||||||||||||||||
| 310 | stack.push(q_ptr); | - | ||||||||||||||||||
| 311 | while (!stack.isEmpty()) { | - | ||||||||||||||||||
| 312 | QStandardItem *itm = stack.pop(); | - | ||||||||||||||||||
| 313 | if (itm->d_func()->model) { | - | ||||||||||||||||||
| 314 | itm->d_func()->model->d_func()->invalidatePersistentIndex(itm->d_func()->model->indexFromItem(itm)); | - | ||||||||||||||||||
| 315 | } | - | ||||||||||||||||||
| 316 | itm->d_func()->model = mod; | - | ||||||||||||||||||
| 317 | const QVector<QStandardItem*> &childList = itm->d_func()->children; | - | ||||||||||||||||||
| 318 | for (int i = 0; i < childList.count(); ++i) { | - | ||||||||||||||||||
| 319 | QStandardItem *chi = childList.at(i); | - | ||||||||||||||||||
| 320 | if (chi) | - | ||||||||||||||||||
| 321 | stack.push(chi); | - | ||||||||||||||||||
| 322 | } | - | ||||||||||||||||||
| 323 | } | - | ||||||||||||||||||
| 324 | } | - | ||||||||||||||||||
| 325 | } | - | ||||||||||||||||||
| 326 | - | |||||||||||||||||||
| 327 | /*! | - | ||||||||||||||||||
| 328 | \internal | - | ||||||||||||||||||
| 329 | */ | - | ||||||||||||||||||
| 330 | QStandardItemModelPrivate::QStandardItemModelPrivate() | - | ||||||||||||||||||
| 331 | : root(new QStandardItem), | - | ||||||||||||||||||
| 332 | itemPrototype(0), | - | ||||||||||||||||||
| 333 | sortRole(Qt::DisplayRole) | - | ||||||||||||||||||
| 334 | { | - | ||||||||||||||||||
| 335 | root->setFlags(Qt::ItemIsDropEnabled); | - | ||||||||||||||||||
| 336 | } | - | ||||||||||||||||||
| 337 | - | |||||||||||||||||||
| 338 | /*! | - | ||||||||||||||||||
| 339 | \internal | - | ||||||||||||||||||
| 340 | */ | - | ||||||||||||||||||
| 341 | QStandardItemModelPrivate::~QStandardItemModelPrivate() | - | ||||||||||||||||||
| 342 | { | - | ||||||||||||||||||
| 343 | delete itemPrototype; | - | ||||||||||||||||||
| 344 | qDeleteAll(columnHeaderItems); | - | ||||||||||||||||||
| 345 | qDeleteAll(rowHeaderItems); | - | ||||||||||||||||||
| 346 | } | - | ||||||||||||||||||
| 347 | - | |||||||||||||||||||
| 348 | /*! | - | ||||||||||||||||||
| 349 | \internal | - | ||||||||||||||||||
| 350 | */ | - | ||||||||||||||||||
| 351 | void QStandardItemModelPrivate::init() | - | ||||||||||||||||||
| 352 | { | - | ||||||||||||||||||
| 353 | Q_Q(QStandardItemModel); | - | ||||||||||||||||||
| 354 | QObject::connect(q, SIGNAL(dataChanged(QModelIndex,QModelIndex)), | - | ||||||||||||||||||
| 355 | q, SLOT(_q_emitItemChanged(QModelIndex,QModelIndex))); | - | ||||||||||||||||||
| 356 | } | - | ||||||||||||||||||
| 357 | - | |||||||||||||||||||
| 358 | /*! | - | ||||||||||||||||||
| 359 | \internal | - | ||||||||||||||||||
| 360 | */ | - | ||||||||||||||||||
| 361 | void QStandardItemModelPrivate::_q_emitItemChanged(const QModelIndex &topLeft, | - | ||||||||||||||||||
| 362 | const QModelIndex &bottomRight) | - | ||||||||||||||||||
| 363 | { | - | ||||||||||||||||||
| 364 | Q_Q(QStandardItemModel); | - | ||||||||||||||||||
| 365 | QModelIndex parent = topLeft.parent(); | - | ||||||||||||||||||
| 366 | for (int row = topLeft.row(); row <= bottomRight.row(); ++row) { | - | ||||||||||||||||||
| 367 | for (int column = topLeft.column(); column <= bottomRight.column(); ++column) { | - | ||||||||||||||||||
| 368 | QModelIndex index = q->index(row, column, parent); | - | ||||||||||||||||||
| 369 | if (QStandardItem *item = itemFromIndex(index)) | - | ||||||||||||||||||
| 370 | emit q->itemChanged(item); | - | ||||||||||||||||||
| 371 | } | - | ||||||||||||||||||
| 372 | } | - | ||||||||||||||||||
| 373 | } | - | ||||||||||||||||||
| 374 | - | |||||||||||||||||||
| 375 | /*! | - | ||||||||||||||||||
| 376 | \internal | - | ||||||||||||||||||
| 377 | */ | - | ||||||||||||||||||
| 378 | bool QStandardItemPrivate::insertRows(int row, const QList<QStandardItem*> &items) | - | ||||||||||||||||||
| 379 | { | - | ||||||||||||||||||
| 380 | Q_Q(QStandardItem); | - | ||||||||||||||||||
| 381 | if ((row < 0) || (row > rowCount())) | - | ||||||||||||||||||
| 382 | return false; | - | ||||||||||||||||||
| 383 | int count = items.count(); | - | ||||||||||||||||||
| 384 | if (model) | - | ||||||||||||||||||
| 385 | model->d_func()->rowsAboutToBeInserted(q, row, row + count - 1); | - | ||||||||||||||||||
| 386 | if (rowCount() == 0) { | - | ||||||||||||||||||
| 387 | if (columnCount() == 0) | - | ||||||||||||||||||
| 388 | q->setColumnCount(1); | - | ||||||||||||||||||
| 389 | children.resize(columnCount() * count); | - | ||||||||||||||||||
| 390 | rows = count; | - | ||||||||||||||||||
| 391 | } else { | - | ||||||||||||||||||
| 392 | rows += count; | - | ||||||||||||||||||
| 393 | int index = childIndex(row, 0); | - | ||||||||||||||||||
| 394 | if (index != -1) | - | ||||||||||||||||||
| 395 | children.insert(index, columnCount() * count, 0); | - | ||||||||||||||||||
| 396 | } | - | ||||||||||||||||||
| 397 | for (int i = 0; i < items.count(); ++i) { | - | ||||||||||||||||||
| 398 | QStandardItem *item = items.at(i); | - | ||||||||||||||||||
| 399 | item->d_func()->model = model; | - | ||||||||||||||||||
| 400 | item->d_func()->parent = q; | - | ||||||||||||||||||
| 401 | int index = childIndex(i + row, 0); | - | ||||||||||||||||||
| 402 | children.replace(index, item); | - | ||||||||||||||||||
| 403 | } | - | ||||||||||||||||||
| 404 | if (model) | - | ||||||||||||||||||
| 405 | model->d_func()->rowsInserted(q, row, count); | - | ||||||||||||||||||
| 406 | return true; | - | ||||||||||||||||||
| 407 | } | - | ||||||||||||||||||
| 408 | - | |||||||||||||||||||
| 409 | bool QStandardItemPrivate::insertRows(int row, int count, const QList<QStandardItem*> &items) | - | ||||||||||||||||||
| 410 | { | - | ||||||||||||||||||
| 411 | Q_Q(QStandardItem); | - | ||||||||||||||||||
| 412 | if ((count < 1) || (row < 0) || (row > rowCount())) | - | ||||||||||||||||||
| 413 | return false; | - | ||||||||||||||||||
| 414 | if (model) | - | ||||||||||||||||||
| 415 | model->d_func()->rowsAboutToBeInserted(q, row, row + count - 1); | - | ||||||||||||||||||
| 416 | if (rowCount() == 0) { | - | ||||||||||||||||||
| 417 | children.resize(columnCount() * count); | - | ||||||||||||||||||
| 418 | rows = count; | - | ||||||||||||||||||
| 419 | } else { | - | ||||||||||||||||||
| 420 | rows += count; | - | ||||||||||||||||||
| 421 | int index = childIndex(row, 0); | - | ||||||||||||||||||
| 422 | if (index != -1) | - | ||||||||||||||||||
| 423 | children.insert(index, columnCount() * count, 0); | - | ||||||||||||||||||
| 424 | } | - | ||||||||||||||||||
| 425 | if (!items.isEmpty()) { | - | ||||||||||||||||||
| 426 | int index = childIndex(row, 0); | - | ||||||||||||||||||
| 427 | int limit = qMin(items.count(), columnCount() * count); | - | ||||||||||||||||||
| 428 | for (int i = 0; i < limit; ++i) { | - | ||||||||||||||||||
| 429 | QStandardItem *item = items.at(i); | - | ||||||||||||||||||
| 430 | if (item) { | - | ||||||||||||||||||
| 431 | if (item->d_func()->parent == 0) { | - | ||||||||||||||||||
| 432 | item->d_func()->setParentAndModel(q, model); | - | ||||||||||||||||||
| 433 | } else { | - | ||||||||||||||||||
| 434 | qWarning("QStandardItem::insertRows: Ignoring duplicate insertion of item %p", | - | ||||||||||||||||||
| 435 | item); | - | ||||||||||||||||||
| 436 | item = 0; | - | ||||||||||||||||||
| 437 | } | - | ||||||||||||||||||
| 438 | } | - | ||||||||||||||||||
| 439 | children.replace(index, item); | - | ||||||||||||||||||
| 440 | ++index; | - | ||||||||||||||||||
| 441 | } | - | ||||||||||||||||||
| 442 | } | - | ||||||||||||||||||
| 443 | if (model) | - | ||||||||||||||||||
| 444 | model->d_func()->rowsInserted(q, row, count); | - | ||||||||||||||||||
| 445 | return true; | - | ||||||||||||||||||
| 446 | } | - | ||||||||||||||||||
| 447 | - | |||||||||||||||||||
| 448 | /*! | - | ||||||||||||||||||
| 449 | \internal | - | ||||||||||||||||||
| 450 | */ | - | ||||||||||||||||||
| 451 | bool QStandardItemPrivate::insertColumns(int column, int count, const QList<QStandardItem*> &items) | - | ||||||||||||||||||
| 452 | { | - | ||||||||||||||||||
| 453 | Q_Q(QStandardItem); | - | ||||||||||||||||||
| 454 | if ((count < 1) || (column < 0) || (column > columnCount())) | - | ||||||||||||||||||
| 455 | return false; | - | ||||||||||||||||||
| 456 | if (model) | - | ||||||||||||||||||
| 457 | model->d_func()->columnsAboutToBeInserted(q, column, column + count - 1); | - | ||||||||||||||||||
| 458 | if (columnCount() == 0) { | - | ||||||||||||||||||
| 459 | children.resize(rowCount() * count); | - | ||||||||||||||||||
| 460 | columns = count; | - | ||||||||||||||||||
| 461 | } else { | - | ||||||||||||||||||
| 462 | columns += count; | - | ||||||||||||||||||
| 463 | int index = childIndex(0, column); | - | ||||||||||||||||||
| 464 | for (int row = 0; row < rowCount(); ++row) { | - | ||||||||||||||||||
| 465 | children.insert(index, count, 0); | - | ||||||||||||||||||
| 466 | index += columnCount(); | - | ||||||||||||||||||
| 467 | } | - | ||||||||||||||||||
| 468 | } | - | ||||||||||||||||||
| 469 | if (!items.isEmpty()) { | - | ||||||||||||||||||
| 470 | int limit = qMin(items.count(), rowCount() * count); | - | ||||||||||||||||||
| 471 | for (int i = 0; i < limit; ++i) { | - | ||||||||||||||||||
| 472 | QStandardItem *item = items.at(i); | - | ||||||||||||||||||
| 473 | if (item) { | - | ||||||||||||||||||
| 474 | if (item->d_func()->parent == 0) { | - | ||||||||||||||||||
| 475 | item->d_func()->setParentAndModel(q, model); | - | ||||||||||||||||||
| 476 | } else { | - | ||||||||||||||||||
| 477 | qWarning("QStandardItem::insertColumns: Ignoring duplicate insertion of item %p", | - | ||||||||||||||||||
| 478 | item); | - | ||||||||||||||||||
| 479 | item = 0; | - | ||||||||||||||||||
| 480 | } | - | ||||||||||||||||||
| 481 | } | - | ||||||||||||||||||
| 482 | int r = i / count; | - | ||||||||||||||||||
| 483 | int c = column + (i % count); | - | ||||||||||||||||||
| 484 | int index = childIndex(r, c); | - | ||||||||||||||||||
| 485 | children.replace(index, item); | - | ||||||||||||||||||
| 486 | } | - | ||||||||||||||||||
| 487 | } | - | ||||||||||||||||||
| 488 | if (model) | - | ||||||||||||||||||
| 489 | model->d_func()->columnsInserted(q, column, count); | - | ||||||||||||||||||
| 490 | return true; | - | ||||||||||||||||||
| 491 | } | - | ||||||||||||||||||
| 492 | - | |||||||||||||||||||
| 493 | /*! | - | ||||||||||||||||||
| 494 | \internal | - | ||||||||||||||||||
| 495 | */ | - | ||||||||||||||||||
| 496 | void QStandardItemModelPrivate::itemChanged(QStandardItem *item) | - | ||||||||||||||||||
| 497 | { | - | ||||||||||||||||||
| 498 | Q_Q(QStandardItemModel); | - | ||||||||||||||||||
| 499 | if (item->d_func()->parent == 0) { | - | ||||||||||||||||||
| 500 | // Header item | - | ||||||||||||||||||
| 501 | int idx = columnHeaderItems.indexOf(item); | - | ||||||||||||||||||
| 502 | if (idx != -1) { | - | ||||||||||||||||||
| 503 | emit q->headerDataChanged(Qt::Horizontal, idx, idx); | - | ||||||||||||||||||
| 504 | } else { | - | ||||||||||||||||||
| 505 | idx = rowHeaderItems.indexOf(item); | - | ||||||||||||||||||
| 506 | if (idx != -1) | - | ||||||||||||||||||
| 507 | emit q->headerDataChanged(Qt::Vertical, idx, idx); | - | ||||||||||||||||||
| 508 | } | - | ||||||||||||||||||
| 509 | } else { | - | ||||||||||||||||||
| 510 | // Normal item | - | ||||||||||||||||||
| 511 | QModelIndex index = q->indexFromItem(item); | - | ||||||||||||||||||
| 512 | emit q->dataChanged(index, index); | - | ||||||||||||||||||
| 513 | } | - | ||||||||||||||||||
| 514 | } | - | ||||||||||||||||||
| 515 | - | |||||||||||||||||||
| 516 | /*! | - | ||||||||||||||||||
| 517 | \internal | - | ||||||||||||||||||
| 518 | */ | - | ||||||||||||||||||
| 519 | void QStandardItemModelPrivate::rowsAboutToBeInserted(QStandardItem *parent, | - | ||||||||||||||||||
| 520 | int start, int end) | - | ||||||||||||||||||
| 521 | { | - | ||||||||||||||||||
| 522 | Q_Q(QStandardItemModel); | - | ||||||||||||||||||
| 523 | QModelIndex index = q->indexFromItem(parent); | - | ||||||||||||||||||
| 524 | q->beginInsertRows(index, start, end); | - | ||||||||||||||||||
| 525 | } | - | ||||||||||||||||||
| 526 | - | |||||||||||||||||||
| 527 | /*! | - | ||||||||||||||||||
| 528 | \internal | - | ||||||||||||||||||
| 529 | */ | - | ||||||||||||||||||
| 530 | void QStandardItemModelPrivate::columnsAboutToBeInserted(QStandardItem *parent, | - | ||||||||||||||||||
| 531 | int start, int end) | - | ||||||||||||||||||
| 532 | { | - | ||||||||||||||||||
| 533 | Q_Q(QStandardItemModel); | - | ||||||||||||||||||
| 534 | QModelIndex index = q->indexFromItem(parent); | - | ||||||||||||||||||
| 535 | q->beginInsertColumns(index, start, end); | - | ||||||||||||||||||
| 536 | } | - | ||||||||||||||||||
| 537 | - | |||||||||||||||||||
| 538 | /*! | - | ||||||||||||||||||
| 539 | \internal | - | ||||||||||||||||||
| 540 | */ | - | ||||||||||||||||||
| 541 | void QStandardItemModelPrivate::rowsAboutToBeRemoved(QStandardItem *parent, | - | ||||||||||||||||||
| 542 | int start, int end) | - | ||||||||||||||||||
| 543 | { | - | ||||||||||||||||||
| 544 | Q_Q(QStandardItemModel); | - | ||||||||||||||||||
| 545 | QModelIndex index = q->indexFromItem(parent); | - | ||||||||||||||||||
| 546 | q->beginRemoveRows(index, start, end); | - | ||||||||||||||||||
| 547 | } | - | ||||||||||||||||||
| 548 | - | |||||||||||||||||||
| 549 | /*! | - | ||||||||||||||||||
| 550 | \internal | - | ||||||||||||||||||
| 551 | */ | - | ||||||||||||||||||
| 552 | void QStandardItemModelPrivate::columnsAboutToBeRemoved(QStandardItem *parent, | - | ||||||||||||||||||
| 553 | int start, int end) | - | ||||||||||||||||||
| 554 | { | - | ||||||||||||||||||
| 555 | Q_Q(QStandardItemModel); | - | ||||||||||||||||||
| 556 | QModelIndex index = q->indexFromItem(parent); | - | ||||||||||||||||||
| 557 | q->beginRemoveColumns(index, start, end); | - | ||||||||||||||||||
| 558 | } | - | ||||||||||||||||||
| 559 | - | |||||||||||||||||||
| 560 | /*! | - | ||||||||||||||||||
| 561 | \internal | - | ||||||||||||||||||
| 562 | */ | - | ||||||||||||||||||
| 563 | void QStandardItemModelPrivate::rowsInserted(QStandardItem *parent, | - | ||||||||||||||||||
| 564 | int row, int count) | - | ||||||||||||||||||
| 565 | { | - | ||||||||||||||||||
| 566 | Q_Q(QStandardItemModel); | - | ||||||||||||||||||
| 567 | if (parent == root.data()) | - | ||||||||||||||||||
| 568 | rowHeaderItems.insert(row, count, 0); | - | ||||||||||||||||||
| 569 | q->endInsertRows(); | - | ||||||||||||||||||
| 570 | } | - | ||||||||||||||||||
| 571 | - | |||||||||||||||||||
| 572 | /*! | - | ||||||||||||||||||
| 573 | \internal | - | ||||||||||||||||||
| 574 | */ | - | ||||||||||||||||||
| 575 | void QStandardItemModelPrivate::columnsInserted(QStandardItem *parent, | - | ||||||||||||||||||
| 576 | int column, int count) | - | ||||||||||||||||||
| 577 | { | - | ||||||||||||||||||
| 578 | Q_Q(QStandardItemModel); | - | ||||||||||||||||||
| 579 | if (parent == root.data()) | - | ||||||||||||||||||
| 580 | columnHeaderItems.insert(column, count, 0); | - | ||||||||||||||||||
| 581 | q->endInsertColumns(); | - | ||||||||||||||||||
| 582 | } | - | ||||||||||||||||||
| 583 | - | |||||||||||||||||||
| 584 | /*! | - | ||||||||||||||||||
| 585 | \internal | - | ||||||||||||||||||
| 586 | */ | - | ||||||||||||||||||
| 587 | void QStandardItemModelPrivate::rowsRemoved(QStandardItem *parent, | - | ||||||||||||||||||
| 588 | int row, int count) | - | ||||||||||||||||||
| 589 | { | - | ||||||||||||||||||
| 590 | Q_Q(QStandardItemModel); | - | ||||||||||||||||||
| 591 | if (parent == root.data()) { | - | ||||||||||||||||||
| 592 | for (int i = row; i < row + count; ++i) { | - | ||||||||||||||||||
| 593 | QStandardItem *oldItem = rowHeaderItems.at(i); | - | ||||||||||||||||||
| 594 | if (oldItem) | - | ||||||||||||||||||
| 595 | oldItem->d_func()->setModel(0); | - | ||||||||||||||||||
| 596 | delete oldItem; | - | ||||||||||||||||||
| 597 | } | - | ||||||||||||||||||
| 598 | rowHeaderItems.remove(row, count); | - | ||||||||||||||||||
| 599 | } | - | ||||||||||||||||||
| 600 | q->endRemoveRows(); | - | ||||||||||||||||||
| 601 | } | - | ||||||||||||||||||
| 602 | - | |||||||||||||||||||
| 603 | /*! | - | ||||||||||||||||||
| 604 | \internal | - | ||||||||||||||||||
| 605 | */ | - | ||||||||||||||||||
| 606 | void QStandardItemModelPrivate::columnsRemoved(QStandardItem *parent, | - | ||||||||||||||||||
| 607 | int column, int count) | - | ||||||||||||||||||
| 608 | { | - | ||||||||||||||||||
| 609 | Q_Q(QStandardItemModel); | - | ||||||||||||||||||
| 610 | if (parent == root.data()) { | - | ||||||||||||||||||
| 611 | for (int i = column; i < column + count; ++i) { | - | ||||||||||||||||||
| 612 | QStandardItem *oldItem = columnHeaderItems.at(i); | - | ||||||||||||||||||
| 613 | if (oldItem) | - | ||||||||||||||||||
| 614 | oldItem->d_func()->setModel(0); | - | ||||||||||||||||||
| 615 | delete oldItem; | - | ||||||||||||||||||
| 616 | } | - | ||||||||||||||||||
| 617 | columnHeaderItems.remove(column, count); | - | ||||||||||||||||||
| 618 | } | - | ||||||||||||||||||
| 619 | q->endRemoveColumns(); | - | ||||||||||||||||||
| 620 | } | - | ||||||||||||||||||
| 621 | - | |||||||||||||||||||
| 622 | /*! | - | ||||||||||||||||||
| 623 | \class QStandardItem | - | ||||||||||||||||||
| 624 | \brief The QStandardItem class provides an item for use with the | - | ||||||||||||||||||
| 625 | QStandardItemModel class. | - | ||||||||||||||||||
| 626 | \since 4.2 | - | ||||||||||||||||||
| 627 | \ingroup model-view | - | ||||||||||||||||||
| 628 | \inmodule QtGui | - | ||||||||||||||||||
| 629 | - | |||||||||||||||||||
| 630 | Items usually contain text, icons, or checkboxes. | - | ||||||||||||||||||
| 631 | - | |||||||||||||||||||
| 632 | Each item can have its own background brush which is set with the | - | ||||||||||||||||||
| 633 | setBackground() function. The current background brush can be found with | - | ||||||||||||||||||
| 634 | background(). The text label for each item can be rendered with its own | - | ||||||||||||||||||
| 635 | font and brush. These are specified with the setFont() and setForeground() | - | ||||||||||||||||||
| 636 | functions, and read with font() and foreground(). | - | ||||||||||||||||||
| 637 | - | |||||||||||||||||||
| 638 | By default, items are enabled, editable, selectable, checkable, and can be | - | ||||||||||||||||||
| 639 | used both as the source of a drag and drop operation and as a drop target. | - | ||||||||||||||||||
| 640 | Each item's flags can be changed by calling setFlags(). Checkable items | - | ||||||||||||||||||
| 641 | can be checked and unchecked with the setCheckState() function. The | - | ||||||||||||||||||
| 642 | corresponding checkState() function indicates whether the item is | - | ||||||||||||||||||
| 643 | currently checked. | - | ||||||||||||||||||
| 644 | - | |||||||||||||||||||
| 645 | You can store application-specific data in an item by calling setData(). | - | ||||||||||||||||||
| 646 | - | |||||||||||||||||||
| 647 | Each item can have a two-dimensional table of child items. This makes it | - | ||||||||||||||||||
| 648 | possible to build hierarchies of items. The typical hierarchy is the tree, | - | ||||||||||||||||||
| 649 | in which case the child table is a table with a single column (a list). | - | ||||||||||||||||||
| 650 | - | |||||||||||||||||||
| 651 | The dimensions of the child table can be set with setRowCount() and | - | ||||||||||||||||||
| 652 | setColumnCount(). Items can be positioned in the child table with | - | ||||||||||||||||||
| 653 | setChild(). Get a pointer to a child item with child(). New rows and | - | ||||||||||||||||||
| 654 | columns of children can also be inserted with insertRow() and | - | ||||||||||||||||||
| 655 | insertColumn(), or appended with appendRow() and appendColumn(). When | - | ||||||||||||||||||
| 656 | using the append and insert functions, the dimensions of the child table | - | ||||||||||||||||||
| 657 | will grow as needed. | - | ||||||||||||||||||
| 658 | - | |||||||||||||||||||
| 659 | An existing row of children can be removed with removeRow() or takeRow(); | - | ||||||||||||||||||
| 660 | correspondingly, a column can be removed with removeColumn() or | - | ||||||||||||||||||
| 661 | takeColumn(). | - | ||||||||||||||||||
| 662 | - | |||||||||||||||||||
| 663 | An item's children can be sorted by calling sortChildren(). | - | ||||||||||||||||||
| 664 | - | |||||||||||||||||||
| 665 | \section1 Subclassing | - | ||||||||||||||||||
| 666 | - | |||||||||||||||||||
| 667 | When subclassing QStandardItem to provide custom items, it is possible to | - | ||||||||||||||||||
| 668 | define new types for them so that they can be distinguished from the base | - | ||||||||||||||||||
| 669 | class. The type() function should be reimplemented to return a new type | - | ||||||||||||||||||
| 670 | value equal to or greater than \l UserType. | - | ||||||||||||||||||
| 671 | - | |||||||||||||||||||
| 672 | Reimplement data() and setData() if you want to perform custom handling of | - | ||||||||||||||||||
| 673 | data queries and/or control how an item's data is represented. | - | ||||||||||||||||||
| 674 | - | |||||||||||||||||||
| 675 | Reimplement clone() if you want QStandardItemModel to be able to create | - | ||||||||||||||||||
| 676 | instances of your custom item class on demand (see | - | ||||||||||||||||||
| 677 | QStandardItemModel::setItemPrototype()). | - | ||||||||||||||||||
| 678 | - | |||||||||||||||||||
| 679 | Reimplement read() and write() if you want to control how items are | - | ||||||||||||||||||
| 680 | represented in their serialized form. | - | ||||||||||||||||||
| 681 | - | |||||||||||||||||||
| 682 | Reimplement \l{operator<()} if you want to control the semantics of item | - | ||||||||||||||||||
| 683 | comparison. \l{operator<()} determines the sorted order when sorting items | - | ||||||||||||||||||
| 684 | with sortChildren() or with QStandardItemModel::sort(). | - | ||||||||||||||||||
| 685 | - | |||||||||||||||||||
| 686 | \sa QStandardItemModel, {Item View Convenience Classes}, {Model/View Programming} | - | ||||||||||||||||||
| 687 | */ | - | ||||||||||||||||||
| 688 | - | |||||||||||||||||||
| 689 | /*! | - | ||||||||||||||||||
| 690 | \enum QStandardItem::ItemType | - | ||||||||||||||||||
| 691 | - | |||||||||||||||||||
| 692 | This enum describes the types that are used to describe standard items. | - | ||||||||||||||||||
| 693 | - | |||||||||||||||||||
| 694 | \value Type The default type for standard items. | - | ||||||||||||||||||
| 695 | \value UserType The minimum value for custom types. Values below UserType are | - | ||||||||||||||||||
| 696 | reserved by Qt. | - | ||||||||||||||||||
| 697 | - | |||||||||||||||||||
| 698 | You can define new user types in QStandardItem subclasses to ensure that | - | ||||||||||||||||||
| 699 | custom items are treated specially; for example, when items are sorted. | - | ||||||||||||||||||
| 700 | - | |||||||||||||||||||
| 701 | \sa type() | - | ||||||||||||||||||
| 702 | */ | - | ||||||||||||||||||
| 703 | - | |||||||||||||||||||
| 704 | /*! | - | ||||||||||||||||||
| 705 | Constructs an item. | - | ||||||||||||||||||
| 706 | */ | - | ||||||||||||||||||
| 707 | QStandardItem::QStandardItem() | - | ||||||||||||||||||
| 708 | : d_ptr(new QStandardItemPrivate) | - | ||||||||||||||||||
| 709 | { | - | ||||||||||||||||||
| 710 | Q_D(QStandardItem); | - | ||||||||||||||||||
| 711 | d->q_ptr = this; | - | ||||||||||||||||||
| 712 | } | - | ||||||||||||||||||
| 713 | - | |||||||||||||||||||
| 714 | /*! | - | ||||||||||||||||||
| 715 | Constructs an item with the given \a text. | - | ||||||||||||||||||
| 716 | */ | - | ||||||||||||||||||
| 717 | QStandardItem::QStandardItem(const QString &text) | - | ||||||||||||||||||
| 718 | : d_ptr(new QStandardItemPrivate) | - | ||||||||||||||||||
| 719 | { | - | ||||||||||||||||||
| 720 | Q_D(QStandardItem); | - | ||||||||||||||||||
| 721 | d->q_ptr = this; | - | ||||||||||||||||||
| 722 | setText(text); | - | ||||||||||||||||||
| 723 | } | - | ||||||||||||||||||
| 724 | - | |||||||||||||||||||
| 725 | /*! | - | ||||||||||||||||||
| 726 | Constructs an item with the given \a icon and \a text. | - | ||||||||||||||||||
| 727 | */ | - | ||||||||||||||||||
| 728 | QStandardItem::QStandardItem(const QIcon &icon, const QString &text) | - | ||||||||||||||||||
| 729 | : d_ptr(new QStandardItemPrivate) | - | ||||||||||||||||||
| 730 | { | - | ||||||||||||||||||
| 731 | Q_D(QStandardItem); | - | ||||||||||||||||||
| 732 | d->q_ptr = this; | - | ||||||||||||||||||
| 733 | setIcon(icon); | - | ||||||||||||||||||
| 734 | setText(text); | - | ||||||||||||||||||
| 735 | } | - | ||||||||||||||||||
| 736 | - | |||||||||||||||||||
| 737 | /*! | - | ||||||||||||||||||
| 738 | Constructs an item with \a rows rows and \a columns columns of child items. | - | ||||||||||||||||||
| 739 | */ | - | ||||||||||||||||||
| 740 | QStandardItem::QStandardItem(int rows, int columns) | - | ||||||||||||||||||
| 741 | : d_ptr(new QStandardItemPrivate) | - | ||||||||||||||||||
| 742 | { | - | ||||||||||||||||||
| 743 | Q_D(QStandardItem); | - | ||||||||||||||||||
| 744 | d->q_ptr = this; | - | ||||||||||||||||||
| 745 | setRowCount(rows); | - | ||||||||||||||||||
| 746 | setColumnCount(columns); | - | ||||||||||||||||||
| 747 | } | - | ||||||||||||||||||
| 748 | - | |||||||||||||||||||
| 749 | /*! | - | ||||||||||||||||||
| 750 | \internal | - | ||||||||||||||||||
| 751 | */ | - | ||||||||||||||||||
| 752 | QStandardItem::QStandardItem(QStandardItemPrivate &dd) | - | ||||||||||||||||||
| 753 | : d_ptr(&dd) | - | ||||||||||||||||||
| 754 | { | - | ||||||||||||||||||
| 755 | Q_D(QStandardItem); | - | ||||||||||||||||||
| 756 | d->q_ptr = this; | - | ||||||||||||||||||
| 757 | } | - | ||||||||||||||||||
| 758 | - | |||||||||||||||||||
| 759 | /*! | - | ||||||||||||||||||
| 760 | Constructs a copy of \a other. Note that model() is | - | ||||||||||||||||||
| 761 | not copied. | - | ||||||||||||||||||
| 762 | - | |||||||||||||||||||
| 763 | This function is useful when reimplementing clone(). | - | ||||||||||||||||||
| 764 | */ | - | ||||||||||||||||||
| 765 | QStandardItem::QStandardItem(const QStandardItem &other) | - | ||||||||||||||||||
| 766 | : d_ptr(new QStandardItemPrivate) | - | ||||||||||||||||||
| 767 | { | - | ||||||||||||||||||
| 768 | Q_D(QStandardItem); | - | ||||||||||||||||||
| 769 | d->q_ptr = this; | - | ||||||||||||||||||
| 770 | operator=(other); | - | ||||||||||||||||||
| 771 | } | - | ||||||||||||||||||
| 772 | - | |||||||||||||||||||
| 773 | /*! | - | ||||||||||||||||||
| 774 | Assigns \a other's data and flags to this item. Note that | - | ||||||||||||||||||
| 775 | type() and model() are not copied. | - | ||||||||||||||||||
| 776 | - | |||||||||||||||||||
| 777 | This function is useful when reimplementing clone(). | - | ||||||||||||||||||
| 778 | */ | - | ||||||||||||||||||
| 779 | QStandardItem &QStandardItem::operator=(const QStandardItem &other) | - | ||||||||||||||||||
| 780 | { | - | ||||||||||||||||||
| 781 | Q_D(QStandardItem); | - | ||||||||||||||||||
| 782 | d->values = other.d_func()->values; | - | ||||||||||||||||||
| 783 | return *this; | - | ||||||||||||||||||
| 784 | } | - | ||||||||||||||||||
| 785 | - | |||||||||||||||||||
| 786 | /*! | - | ||||||||||||||||||
| 787 | Destructs the item. | - | ||||||||||||||||||
| 788 | This causes the item's children to be destructed as well. | - | ||||||||||||||||||
| 789 | */ | - | ||||||||||||||||||
| 790 | QStandardItem::~QStandardItem() | - | ||||||||||||||||||
| 791 | { | - | ||||||||||||||||||
| 792 | } | - | ||||||||||||||||||
| 793 | - | |||||||||||||||||||
| 794 | /*! | - | ||||||||||||||||||
| 795 | Returns the item's parent item, or 0 if the item has no parent. | - | ||||||||||||||||||
| 796 | \note For toplevel items parent() returns 0. To receive toplevel | - | ||||||||||||||||||
| 797 | item's parent use QStandardItemModel::invisibleRootItem() instead. | - | ||||||||||||||||||
| 798 | - | |||||||||||||||||||
| 799 | \sa child(), QStandardItemModel::invisibleRootItem() | - | ||||||||||||||||||
| 800 | */ | - | ||||||||||||||||||
| 801 | QStandardItem *QStandardItem::parent() const | - | ||||||||||||||||||
| 802 | { | - | ||||||||||||||||||
| 803 | Q_D(const QStandardItem); | - | ||||||||||||||||||
| 804 | if (!d->model || (d->model->d_func()->root.data() != d->parent)) | - | ||||||||||||||||||
| 805 | return d->parent; | - | ||||||||||||||||||
| 806 | return 0; | - | ||||||||||||||||||
| 807 | } | - | ||||||||||||||||||
| 808 | - | |||||||||||||||||||
| 809 | /*! | - | ||||||||||||||||||
| 810 | Sets the item's data for the given \a role to the specified \a value. | - | ||||||||||||||||||
| 811 | - | |||||||||||||||||||
| 812 | If you subclass QStandardItem and reimplement this function, your | - | ||||||||||||||||||
| 813 | reimplementation should call emitDataChanged() if you do not call | - | ||||||||||||||||||
| 814 | the base implementation of setData(). This will ensure that e.g. | - | ||||||||||||||||||
| 815 | views using the model are notified of the changes. | - | ||||||||||||||||||
| 816 | - | |||||||||||||||||||
| 817 | \note The default implementation treats Qt::EditRole and Qt::DisplayRole | - | ||||||||||||||||||
| 818 | as referring to the same data. | - | ||||||||||||||||||
| 819 | - | |||||||||||||||||||
| 820 | \sa Qt::ItemDataRole, data(), setFlags() | - | ||||||||||||||||||
| 821 | */ | - | ||||||||||||||||||
| 822 | void QStandardItem::setData(const QVariant &value, int role) | - | ||||||||||||||||||
| 823 | { | - | ||||||||||||||||||
| 824 | Q_D(QStandardItem); | - | ||||||||||||||||||
| 825 | role = (role == Qt::EditRole) ? Qt::DisplayRole : role; | - | ||||||||||||||||||
| 826 | QVector<QStandardItemData>::iterator it; | - | ||||||||||||||||||
| 827 | for (it = d->values.begin(); it != d->values.end(); ++it) { | - | ||||||||||||||||||
| 828 | if ((*it).role == role) { | - | ||||||||||||||||||
| 829 | if (value.isValid()) { | - | ||||||||||||||||||
| 830 | if ((*it).value.type() == value.type() && (*it).value == value) | - | ||||||||||||||||||
| 831 | return; | - | ||||||||||||||||||
| 832 | (*it).value = value; | - | ||||||||||||||||||
| 833 | } else { | - | ||||||||||||||||||
| 834 | d->values.erase(it); | - | ||||||||||||||||||
| 835 | } | - | ||||||||||||||||||
| 836 | if (d->model) | - | ||||||||||||||||||
| 837 | d->model->d_func()->itemChanged(this); | - | ||||||||||||||||||
| 838 | return; | - | ||||||||||||||||||
| 839 | } | - | ||||||||||||||||||
| 840 | } | - | ||||||||||||||||||
| 841 | d->values.append(QStandardItemData(role, value)); | - | ||||||||||||||||||
| 842 | if (d->model) | - | ||||||||||||||||||
| 843 | d->model->d_func()->itemChanged(this); | - | ||||||||||||||||||
| 844 | } | - | ||||||||||||||||||
| 845 | - | |||||||||||||||||||
| 846 | /*! | - | ||||||||||||||||||
| 847 | Returns the item's data for the given \a role, or an invalid | - | ||||||||||||||||||
| 848 | QVariant if there is no data for the role. | - | ||||||||||||||||||
| 849 | - | |||||||||||||||||||
| 850 | \note The default implementation treats Qt::EditRole and Qt::DisplayRole | - | ||||||||||||||||||
| 851 | as referring to the same data. | - | ||||||||||||||||||
| 852 | */ | - | ||||||||||||||||||
| 853 | QVariant QStandardItem::data(int role) const | - | ||||||||||||||||||
| 854 | { | - | ||||||||||||||||||
| 855 | Q_D(const QStandardItem); | - | ||||||||||||||||||
| 856 | role = (role == Qt::EditRole) ? Qt::DisplayRole : role; | - | ||||||||||||||||||
| 857 | QVector<QStandardItemData>::const_iterator it; | - | ||||||||||||||||||
| 858 | for (it = d->values.begin(); it != d->values.end(); ++it) { | - | ||||||||||||||||||
| 859 | if ((*it).role == role) | - | ||||||||||||||||||
| 860 | return (*it).value; | - | ||||||||||||||||||
| 861 | } | - | ||||||||||||||||||
| 862 | return QVariant(); | - | ||||||||||||||||||
| 863 | } | - | ||||||||||||||||||
| 864 | - | |||||||||||||||||||
| 865 | /*! | - | ||||||||||||||||||
| 866 | \since 4.4 | - | ||||||||||||||||||
| 867 | - | |||||||||||||||||||
| 868 | Causes the model associated with this item to emit a | - | ||||||||||||||||||
| 869 | \l{QAbstractItemModel::dataChanged()}{dataChanged}() signal for this | - | ||||||||||||||||||
| 870 | item. | - | ||||||||||||||||||
| 871 | - | |||||||||||||||||||
| 872 | You normally only need to call this function if you have subclassed | - | ||||||||||||||||||
| 873 | QStandardItem and reimplemented data() and/or setData(). | - | ||||||||||||||||||
| 874 | - | |||||||||||||||||||
| 875 | \sa setData() | - | ||||||||||||||||||
| 876 | */ | - | ||||||||||||||||||
| 877 | void QStandardItem::emitDataChanged() | - | ||||||||||||||||||
| 878 | { | - | ||||||||||||||||||
| 879 | Q_D(QStandardItem); | - | ||||||||||||||||||
| 880 | if (d->model) | - | ||||||||||||||||||
| 881 | d->model->d_func()->itemChanged(this); | - | ||||||||||||||||||
| 882 | } | - | ||||||||||||||||||
| 883 | - | |||||||||||||||||||
| 884 | /*! | - | ||||||||||||||||||
| 885 | Sets the item flags for the item to \a flags. | - | ||||||||||||||||||
| 886 | - | |||||||||||||||||||
| 887 | The item flags determine how the user can interact with the item. | - | ||||||||||||||||||
| 888 | This is often used to disable an item. | - | ||||||||||||||||||
| 889 | - | |||||||||||||||||||
| 890 | \sa flags(), setData() | - | ||||||||||||||||||
| 891 | */ | - | ||||||||||||||||||
| 892 | void QStandardItem::setFlags(Qt::ItemFlags flags) | - | ||||||||||||||||||
| 893 | { | - | ||||||||||||||||||
| 894 | setData((int)flags, Qt::UserRole - 1); | - | ||||||||||||||||||
| 895 | } | - | ||||||||||||||||||
| 896 | - | |||||||||||||||||||
| 897 | /*! | - | ||||||||||||||||||
| 898 | Returns the item flags for the item. | - | ||||||||||||||||||
| 899 | - | |||||||||||||||||||
| 900 | The item flags determine how the user can interact with the item. | - | ||||||||||||||||||
| 901 | - | |||||||||||||||||||
| 902 | By default, items are enabled, editable, selectable, checkable, and can be | - | ||||||||||||||||||
| 903 | used both as the source of a drag and drop operation and as a drop target. | - | ||||||||||||||||||
| 904 | - | |||||||||||||||||||
| 905 | \sa setFlags() | - | ||||||||||||||||||
| 906 | */ | - | ||||||||||||||||||
| 907 | Qt::ItemFlags QStandardItem::flags() const | - | ||||||||||||||||||
| 908 | { | - | ||||||||||||||||||
| 909 | QVariant v = data(Qt::UserRole - 1); | - | ||||||||||||||||||
| 910 | if (!v.isValid()) | - | ||||||||||||||||||
| 911 | return (Qt::ItemIsSelectable|Qt::ItemIsEnabled|Qt::ItemIsEditable | - | ||||||||||||||||||
| 912 | |Qt::ItemIsDragEnabled|Qt::ItemIsDropEnabled); | - | ||||||||||||||||||
| 913 | return Qt::ItemFlags(v.toInt()); | - | ||||||||||||||||||
| 914 | } | - | ||||||||||||||||||
| 915 | - | |||||||||||||||||||
| 916 | /*! | - | ||||||||||||||||||
| 917 | \fn QString QStandardItem::text() const | - | ||||||||||||||||||
| 918 | - | |||||||||||||||||||
| 919 | Returns the item's text. This is the text that's presented to the user | - | ||||||||||||||||||
| 920 | in a view. | - | ||||||||||||||||||
| 921 | - | |||||||||||||||||||
| 922 | \sa setText() | - | ||||||||||||||||||
| 923 | */ | - | ||||||||||||||||||
| 924 | - | |||||||||||||||||||
| 925 | /*! | - | ||||||||||||||||||
| 926 | \fn void QStandardItem::setText(const QString &text) | - | ||||||||||||||||||
| 927 | - | |||||||||||||||||||
| 928 | Sets the item's text to the \a text specified. | - | ||||||||||||||||||
| 929 | - | |||||||||||||||||||
| 930 | \sa text(), setFont(), setForeground() | - | ||||||||||||||||||
| 931 | */ | - | ||||||||||||||||||
| 932 | - | |||||||||||||||||||
| 933 | /*! | - | ||||||||||||||||||
| 934 | \fn QIcon QStandardItem::icon() const | - | ||||||||||||||||||
| 935 | - | |||||||||||||||||||
| 936 | Returns the item's icon. | - | ||||||||||||||||||
| 937 | - | |||||||||||||||||||
| 938 | \sa setIcon(), {QAbstractItemView::iconSize}{iconSize} | - | ||||||||||||||||||
| 939 | */ | - | ||||||||||||||||||
| 940 | - | |||||||||||||||||||
| 941 | /*! | - | ||||||||||||||||||
| 942 | \fn void QStandardItem::setIcon(const QIcon &icon) | - | ||||||||||||||||||
| 943 | - | |||||||||||||||||||
| 944 | Sets the item's icon to the \a icon specified. | - | ||||||||||||||||||
| 945 | */ | - | ||||||||||||||||||
| 946 | - | |||||||||||||||||||
| 947 | /*! | - | ||||||||||||||||||
| 948 | \fn QString QStandardItem::statusTip() const | - | ||||||||||||||||||
| 949 | - | |||||||||||||||||||
| 950 | Returns the item's status tip. | - | ||||||||||||||||||
| 951 | - | |||||||||||||||||||
| 952 | \sa setStatusTip(), toolTip(), whatsThis() | - | ||||||||||||||||||
| 953 | */ | - | ||||||||||||||||||
| 954 | - | |||||||||||||||||||
| 955 | /*! | - | ||||||||||||||||||
| 956 | \fn void QStandardItem::setStatusTip(const QString &statusTip) | - | ||||||||||||||||||
| 957 | - | |||||||||||||||||||
| 958 | Sets the item's status tip to the string specified by \a statusTip. | - | ||||||||||||||||||
| 959 | - | |||||||||||||||||||
| 960 | \sa statusTip(), setToolTip(), setWhatsThis() | - | ||||||||||||||||||
| 961 | */ | - | ||||||||||||||||||
| 962 | - | |||||||||||||||||||
| 963 | /*! | - | ||||||||||||||||||
| 964 | \fn QString QStandardItem::toolTip() const | - | ||||||||||||||||||
| 965 | - | |||||||||||||||||||
| 966 | Returns the item's tooltip. | - | ||||||||||||||||||
| 967 | - | |||||||||||||||||||
| 968 | \sa setToolTip(), statusTip(), whatsThis() | - | ||||||||||||||||||
| 969 | */ | - | ||||||||||||||||||
| 970 | - | |||||||||||||||||||
| 971 | /*! | - | ||||||||||||||||||
| 972 | \fn void QStandardItem::setToolTip(const QString &toolTip) | - | ||||||||||||||||||
| 973 | - | |||||||||||||||||||
| 974 | Sets the item's tooltip to the string specified by \a toolTip. | - | ||||||||||||||||||
| 975 | - | |||||||||||||||||||
| 976 | \sa toolTip(), setStatusTip(), setWhatsThis() | - | ||||||||||||||||||
| 977 | */ | - | ||||||||||||||||||
| 978 | - | |||||||||||||||||||
| 979 | /*! | - | ||||||||||||||||||
| 980 | \fn QString QStandardItem::whatsThis() const | - | ||||||||||||||||||
| 981 | - | |||||||||||||||||||
| 982 | Returns the item's "What's This?" help. | - | ||||||||||||||||||
| 983 | - | |||||||||||||||||||
| 984 | \sa setWhatsThis(), toolTip(), statusTip() | - | ||||||||||||||||||
| 985 | */ | - | ||||||||||||||||||
| 986 | - | |||||||||||||||||||
| 987 | /*! | - | ||||||||||||||||||
| 988 | \fn void QStandardItem::setWhatsThis(const QString &whatsThis) | - | ||||||||||||||||||
| 989 | - | |||||||||||||||||||
| 990 | Sets the item's "What's This?" help to the string specified by \a whatsThis. | - | ||||||||||||||||||
| 991 | - | |||||||||||||||||||
| 992 | \sa whatsThis(), setStatusTip(), setToolTip() | - | ||||||||||||||||||
| 993 | */ | - | ||||||||||||||||||
| 994 | - | |||||||||||||||||||
| 995 | /*! | - | ||||||||||||||||||
| 996 | \fn QFont QStandardItem::font() const | - | ||||||||||||||||||
| 997 | - | |||||||||||||||||||
| 998 | Returns the font used to render the item's text. | - | ||||||||||||||||||
| 999 | - | |||||||||||||||||||
| 1000 | \sa setFont() | - | ||||||||||||||||||
| 1001 | */ | - | ||||||||||||||||||
| 1002 | - | |||||||||||||||||||
| 1003 | /*! | - | ||||||||||||||||||
| 1004 | \fn void QStandardItem::setFont(const QFont &font) | - | ||||||||||||||||||
| 1005 | - | |||||||||||||||||||
| 1006 | Sets the font used to display the item's text to the given \a font. | - | ||||||||||||||||||
| 1007 | - | |||||||||||||||||||
| 1008 | \sa font(), setText(), setForeground() | - | ||||||||||||||||||
| 1009 | */ | - | ||||||||||||||||||
| 1010 | - | |||||||||||||||||||
| 1011 | /*! | - | ||||||||||||||||||
| 1012 | \fn QBrush QStandardItem::background() const | - | ||||||||||||||||||
| 1013 | - | |||||||||||||||||||
| 1014 | Returns the brush used to render the item's background. | - | ||||||||||||||||||
| 1015 | - | |||||||||||||||||||
| 1016 | \sa foreground(), setBackground() | - | ||||||||||||||||||
| 1017 | */ | - | ||||||||||||||||||
| 1018 | - | |||||||||||||||||||
| 1019 | /*! | - | ||||||||||||||||||
| 1020 | \fn void QStandardItem::setBackground(const QBrush &brush) | - | ||||||||||||||||||
| 1021 | - | |||||||||||||||||||
| 1022 | Sets the item's background brush to the specified \a brush. | - | ||||||||||||||||||
| 1023 | - | |||||||||||||||||||
| 1024 | \sa background(), setForeground() | - | ||||||||||||||||||
| 1025 | */ | - | ||||||||||||||||||
| 1026 | - | |||||||||||||||||||
| 1027 | /*! | - | ||||||||||||||||||
| 1028 | \fn QBrush QStandardItem::foreground() const | - | ||||||||||||||||||
| 1029 | - | |||||||||||||||||||
| 1030 | Returns the brush used to render the item's foreground (e.g. text). | - | ||||||||||||||||||
| 1031 | - | |||||||||||||||||||
| 1032 | \sa setForeground(), background() | - | ||||||||||||||||||
| 1033 | */ | - | ||||||||||||||||||
| 1034 | - | |||||||||||||||||||
| 1035 | /*! | - | ||||||||||||||||||
| 1036 | \fn void QStandardItem::setForeground(const QBrush &brush) | - | ||||||||||||||||||
| 1037 | - | |||||||||||||||||||
| 1038 | Sets the brush used to display the item's foreground (e.g. text) to the | - | ||||||||||||||||||
| 1039 | given \a brush. | - | ||||||||||||||||||
| 1040 | - | |||||||||||||||||||
| 1041 | \sa foreground(), setBackground(), setFont() | - | ||||||||||||||||||
| 1042 | */ | - | ||||||||||||||||||
| 1043 | - | |||||||||||||||||||
| 1044 | /*! | - | ||||||||||||||||||
| 1045 | \fn int QStandardItem::textAlignment() const | - | ||||||||||||||||||
| 1046 | - | |||||||||||||||||||
| 1047 | Returns the text alignment for the item's text. | - | ||||||||||||||||||
| 1048 | */ | - | ||||||||||||||||||
| 1049 | - | |||||||||||||||||||
| 1050 | /*! | - | ||||||||||||||||||
| 1051 | \fn void QStandardItem::setTextAlignment(Qt::Alignment alignment) | - | ||||||||||||||||||
| 1052 | - | |||||||||||||||||||
| 1053 | Sets the text alignment for the item's text to the \a alignment | - | ||||||||||||||||||
| 1054 | specified. | - | ||||||||||||||||||
| 1055 | - | |||||||||||||||||||
| 1056 | \sa textAlignment() | - | ||||||||||||||||||
| 1057 | */ | - | ||||||||||||||||||
| 1058 | - | |||||||||||||||||||
| 1059 | /*! | - | ||||||||||||||||||
| 1060 | \fn QSize QStandardItem::sizeHint() const | - | ||||||||||||||||||
| 1061 | - | |||||||||||||||||||
| 1062 | Returns the size hint set for the item, or an invalid QSize if no | - | ||||||||||||||||||
| 1063 | size hint has been set. | - | ||||||||||||||||||
| 1064 | - | |||||||||||||||||||
| 1065 | If no size hint has been set, the item delegate will compute the | - | ||||||||||||||||||
| 1066 | size hint based on the item data. | - | ||||||||||||||||||
| 1067 | - | |||||||||||||||||||
| 1068 | \sa setSizeHint() | - | ||||||||||||||||||
| 1069 | */ | - | ||||||||||||||||||
| 1070 | - | |||||||||||||||||||
| 1071 | /*! | - | ||||||||||||||||||
| 1072 | \fn void QStandardItem::setSizeHint(const QSize &size) | - | ||||||||||||||||||
| 1073 | - | |||||||||||||||||||
| 1074 | Sets the size hint for the item to be \a size. | - | ||||||||||||||||||
| 1075 | If no size hint is set, the item delegate will compute the | - | ||||||||||||||||||
| 1076 | size hint based on the item data. | - | ||||||||||||||||||
| 1077 | - | |||||||||||||||||||
| 1078 | \sa sizeHint() | - | ||||||||||||||||||
| 1079 | */ | - | ||||||||||||||||||
| 1080 | - | |||||||||||||||||||
| 1081 | /*! | - | ||||||||||||||||||
| 1082 | \fn Qt::CheckState QStandardItem::checkState() const | - | ||||||||||||||||||
| 1083 | - | |||||||||||||||||||
| 1084 | Returns the checked state of the item. | - | ||||||||||||||||||
| 1085 | - | |||||||||||||||||||
| 1086 | \sa setCheckState(), isCheckable() | - | ||||||||||||||||||
| 1087 | */ | - | ||||||||||||||||||
| 1088 | - | |||||||||||||||||||
| 1089 | /*! | - | ||||||||||||||||||
| 1090 | \fn void QStandardItem::setCheckState(Qt::CheckState state) | - | ||||||||||||||||||
| 1091 | - | |||||||||||||||||||
| 1092 | Sets the check state of the item to be \a state. | - | ||||||||||||||||||
| 1093 | - | |||||||||||||||||||
| 1094 | \sa checkState(), setCheckable() | - | ||||||||||||||||||
| 1095 | */ | - | ||||||||||||||||||
| 1096 | - | |||||||||||||||||||
| 1097 | /*! | - | ||||||||||||||||||
| 1098 | \fn QString QStandardItem::accessibleText() const | - | ||||||||||||||||||
| 1099 | - | |||||||||||||||||||
| 1100 | Returns the item's accessible text. | - | ||||||||||||||||||
| 1101 | - | |||||||||||||||||||
| 1102 | The accessible text is used by assistive technologies (i.e. for users who | - | ||||||||||||||||||
| 1103 | cannot use conventional means of interaction). | - | ||||||||||||||||||
| 1104 | - | |||||||||||||||||||
| 1105 | \sa setAccessibleText(), accessibleDescription() | - | ||||||||||||||||||
| 1106 | */ | - | ||||||||||||||||||
| 1107 | - | |||||||||||||||||||
| 1108 | /*! | - | ||||||||||||||||||
| 1109 | \fn void QStandardItem::setAccessibleText(const QString &accessibleText) | - | ||||||||||||||||||
| 1110 | - | |||||||||||||||||||
| 1111 | Sets the item's accessible text to the string specified by \a accessibleText. | - | ||||||||||||||||||
| 1112 | - | |||||||||||||||||||
| 1113 | The accessible text is used by assistive technologies (i.e. for users who | - | ||||||||||||||||||
| 1114 | cannot use conventional means of interaction). | - | ||||||||||||||||||
| 1115 | - | |||||||||||||||||||
| 1116 | \sa accessibleText(), setAccessibleDescription() | - | ||||||||||||||||||
| 1117 | */ | - | ||||||||||||||||||
| 1118 | - | |||||||||||||||||||
| 1119 | /*! | - | ||||||||||||||||||
| 1120 | \fn QString QStandardItem::accessibleDescription() const | - | ||||||||||||||||||
| 1121 | - | |||||||||||||||||||
| 1122 | Returns the item's accessible description. | - | ||||||||||||||||||
| 1123 | - | |||||||||||||||||||
| 1124 | The accessible description is used by assistive technologies (i.e. for | - | ||||||||||||||||||
| 1125 | users who cannot use conventional means of interaction). | - | ||||||||||||||||||
| 1126 | - | |||||||||||||||||||
| 1127 | \sa setAccessibleDescription(), accessibleText() | - | ||||||||||||||||||
| 1128 | */ | - | ||||||||||||||||||
| 1129 | - | |||||||||||||||||||
| 1130 | /*! | - | ||||||||||||||||||
| 1131 | \fn void QStandardItem::setAccessibleDescription(const QString &accessibleDescription) | - | ||||||||||||||||||
| 1132 | - | |||||||||||||||||||
| 1133 | Sets the item's accessible description to the string specified by \a | - | ||||||||||||||||||
| 1134 | accessibleDescription. | - | ||||||||||||||||||
| 1135 | - | |||||||||||||||||||
| 1136 | The accessible description is used by assistive technologies (i.e. for | - | ||||||||||||||||||
| 1137 | users who cannot use conventional means of interaction). | - | ||||||||||||||||||
| 1138 | - | |||||||||||||||||||
| 1139 | \sa accessibleDescription(), setAccessibleText() | - | ||||||||||||||||||
| 1140 | */ | - | ||||||||||||||||||
| 1141 | - | |||||||||||||||||||
| 1142 | /*! | - | ||||||||||||||||||
| 1143 | Sets whether the item is enabled. If \a enabled is true, the item is enabled, | - | ||||||||||||||||||
| 1144 | meaning that the user can interact with the item; if \a enabled is false, the | - | ||||||||||||||||||
| 1145 | user cannot interact with the item. | - | ||||||||||||||||||
| 1146 | - | |||||||||||||||||||
| 1147 | This flag takes precedence over the other item flags; e.g. if an item is not | - | ||||||||||||||||||
| 1148 | enabled, it cannot be selected by the user, even if the Qt::ItemIsSelectable | - | ||||||||||||||||||
| 1149 | flag has been set. | - | ||||||||||||||||||
| 1150 | - | |||||||||||||||||||
| 1151 | \sa isEnabled(), Qt::ItemIsEnabled, setFlags() | - | ||||||||||||||||||
| 1152 | */ | - | ||||||||||||||||||
| 1153 | void QStandardItem::setEnabled(bool enabled) | - | ||||||||||||||||||
| 1154 | { | - | ||||||||||||||||||
| 1155 | Q_D(QStandardItem); | - | ||||||||||||||||||
| 1156 | d->changeFlags(enabled, Qt::ItemIsEnabled); | - | ||||||||||||||||||
| 1157 | } | - | ||||||||||||||||||
| 1158 | - | |||||||||||||||||||
| 1159 | /*! | - | ||||||||||||||||||
| 1160 | \fn bool QStandardItem::isEnabled() const | - | ||||||||||||||||||
| 1161 | - | |||||||||||||||||||
| 1162 | Returns whether the item is enabled. | - | ||||||||||||||||||
| 1163 | - | |||||||||||||||||||
| 1164 | When an item is enabled, the user can interact with it. The possible | - | ||||||||||||||||||
| 1165 | types of interaction are specified by the other item flags, such as | - | ||||||||||||||||||
| 1166 | isEditable() and isSelectable(). | - | ||||||||||||||||||
| 1167 | - | |||||||||||||||||||
| 1168 | The default value is true. | - | ||||||||||||||||||
| 1169 | - | |||||||||||||||||||
| 1170 | \sa setEnabled(), flags() | - | ||||||||||||||||||
| 1171 | */ | - | ||||||||||||||||||
| 1172 | - | |||||||||||||||||||
| 1173 | /*! | - | ||||||||||||||||||
| 1174 | Sets whether the item is editable. If \a editable is true, the item can be | - | ||||||||||||||||||
| 1175 | edited by the user; otherwise, the user cannot edit the item. | - | ||||||||||||||||||
| 1176 | - | |||||||||||||||||||
| 1177 | How the user can edit items in a view is determined by the view's edit | - | ||||||||||||||||||
| 1178 | triggers; see QAbstractItemView::editTriggers. | - | ||||||||||||||||||
| 1179 | - | |||||||||||||||||||
| 1180 | \sa isEditable(), setFlags() | - | ||||||||||||||||||
| 1181 | */ | - | ||||||||||||||||||
| 1182 | void QStandardItem::setEditable(bool editable) | - | ||||||||||||||||||
| 1183 | { | - | ||||||||||||||||||
| 1184 | Q_D(QStandardItem); | - | ||||||||||||||||||
| 1185 | d->changeFlags(editable, Qt::ItemIsEditable); | - | ||||||||||||||||||
| 1186 | } | - | ||||||||||||||||||
| 1187 | - | |||||||||||||||||||
| 1188 | /*! | - | ||||||||||||||||||
| 1189 | \fn bool QStandardItem::isEditable() const | - | ||||||||||||||||||
| 1190 | - | |||||||||||||||||||
| 1191 | Returns whether the item can be edited by the user. | - | ||||||||||||||||||
| 1192 | - | |||||||||||||||||||
| 1193 | When an item is editable (and enabled), the user can edit the item by | - | ||||||||||||||||||
| 1194 | invoking one of the view's edit triggers; see | - | ||||||||||||||||||
| 1195 | QAbstractItemView::editTriggers. | - | ||||||||||||||||||
| 1196 | - | |||||||||||||||||||
| 1197 | The default value is true. | - | ||||||||||||||||||
| 1198 | - | |||||||||||||||||||
| 1199 | \sa setEditable(), flags() | - | ||||||||||||||||||
| 1200 | */ | - | ||||||||||||||||||
| 1201 | - | |||||||||||||||||||
| 1202 | /*! | - | ||||||||||||||||||
| 1203 | Sets whether the item is selectable. If \a selectable is true, the item | - | ||||||||||||||||||
| 1204 | can be selected by the user; otherwise, the user cannot select the item. | - | ||||||||||||||||||
| 1205 | - | |||||||||||||||||||
| 1206 | You can control the selection behavior and mode by manipulating their | - | ||||||||||||||||||
| 1207 | view properties; see QAbstractItemView::selectionMode and | - | ||||||||||||||||||
| 1208 | QAbstractItemView::selectionBehavior. | - | ||||||||||||||||||
| 1209 | - | |||||||||||||||||||
| 1210 | \sa isSelectable(), setFlags() | - | ||||||||||||||||||
| 1211 | */ | - | ||||||||||||||||||
| 1212 | void QStandardItem::setSelectable(bool selectable) | - | ||||||||||||||||||
| 1213 | { | - | ||||||||||||||||||
| 1214 | Q_D(QStandardItem); | - | ||||||||||||||||||
| 1215 | d->changeFlags(selectable, Qt::ItemIsSelectable); | - | ||||||||||||||||||
| 1216 | } | - | ||||||||||||||||||
| 1217 | - | |||||||||||||||||||
| 1218 | /*! | - | ||||||||||||||||||
| 1219 | \fn bool QStandardItem::isSelectable() const | - | ||||||||||||||||||
| 1220 | - | |||||||||||||||||||
| 1221 | Returns whether the item is selectable by the user. | - | ||||||||||||||||||
| 1222 | - | |||||||||||||||||||
| 1223 | The default value is true. | - | ||||||||||||||||||
| 1224 | - | |||||||||||||||||||
| 1225 | \sa setSelectable(), flags() | - | ||||||||||||||||||
| 1226 | */ | - | ||||||||||||||||||
| 1227 | - | |||||||||||||||||||
| 1228 | /*! | - | ||||||||||||||||||
| 1229 | Sets whether the item is user-checkable. If \a checkable is true, the | - | ||||||||||||||||||
| 1230 | item can be checked by the user; otherwise, the user cannot check | - | ||||||||||||||||||
| 1231 | the item. | - | ||||||||||||||||||
| 1232 | - | |||||||||||||||||||
| 1233 | The item delegate will render a checkable item with a check box next to the | - | ||||||||||||||||||
| 1234 | item's text. | - | ||||||||||||||||||
| 1235 | - | |||||||||||||||||||
| 1236 | \sa isCheckable(), setCheckState(), setUserTristate(), setAutoTristate() | - | ||||||||||||||||||
| 1237 | */ | - | ||||||||||||||||||
| 1238 | void QStandardItem::setCheckable(bool checkable) | - | ||||||||||||||||||
| 1239 | { | - | ||||||||||||||||||
| 1240 | Q_D(QStandardItem); | - | ||||||||||||||||||
| 1241 | if (checkable && !isCheckable()) { | - | ||||||||||||||||||
| 1242 | // make sure there's data for the checkstate role | - | ||||||||||||||||||
| 1243 | if (!data(Qt::CheckStateRole).isValid()) | - | ||||||||||||||||||
| 1244 | setData(Qt::Unchecked, Qt::CheckStateRole); | - | ||||||||||||||||||
| 1245 | } | - | ||||||||||||||||||
| 1246 | d->changeFlags(checkable, Qt::ItemIsUserCheckable); | - | ||||||||||||||||||
| 1247 | } | - | ||||||||||||||||||
| 1248 | - | |||||||||||||||||||
| 1249 | /*! | - | ||||||||||||||||||
| 1250 | \fn bool QStandardItem::isCheckable() const | - | ||||||||||||||||||
| 1251 | - | |||||||||||||||||||
| 1252 | Returns whether the item is user-checkable. | - | ||||||||||||||||||
| 1253 | - | |||||||||||||||||||
| 1254 | The default value is false. | - | ||||||||||||||||||
| 1255 | - | |||||||||||||||||||
| 1256 | \sa setCheckable(), checkState(), isUserTristate(), isAutoTristate() | - | ||||||||||||||||||
| 1257 | */ | - | ||||||||||||||||||
| 1258 | - | |||||||||||||||||||
| 1259 | /*! | - | ||||||||||||||||||
| 1260 | \fn void QStandardItem::setTristate(bool tristate) | - | ||||||||||||||||||
| 1261 | \obsolete | - | ||||||||||||||||||
| 1262 | - | |||||||||||||||||||
| 1263 | Use QStandardItem::setAutoTristate(bool tristate) instead. | - | ||||||||||||||||||
| 1264 | For a tristate checkbox that the user can change between all three | - | ||||||||||||||||||
| 1265 | states, use QStandardItem::setUserTristate(bool tristate) instead. | - | ||||||||||||||||||
| 1266 | */ | - | ||||||||||||||||||
| 1267 | - | |||||||||||||||||||
| 1268 | /*! | - | ||||||||||||||||||
| 1269 | \fn void QStandardItem::isTristate() const | - | ||||||||||||||||||
| 1270 | \obsolete | - | ||||||||||||||||||
| 1271 | - | |||||||||||||||||||
| 1272 | Use QStandardItem::isAutoTristate() instead. | - | ||||||||||||||||||
| 1273 | For a tristate checkbox that the user can change between all three | - | ||||||||||||||||||
| 1274 | states, use QStandardItem::isUserTristate() instead. | - | ||||||||||||||||||
| 1275 | */ | - | ||||||||||||||||||
| 1276 | - | |||||||||||||||||||
| 1277 | /*! | - | ||||||||||||||||||
| 1278 | Determines that the item is tristate and controlled by QTreeWidget if \a tristate | - | ||||||||||||||||||
| 1279 | is \c true. | - | ||||||||||||||||||
| 1280 | This enables automatic management of the state of parent items in QTreeWidget | - | ||||||||||||||||||
| 1281 | (checked if all children are checked, unchecked if all children are unchecked, | - | ||||||||||||||||||
| 1282 | or partially checked if only some children are checked). | - | ||||||||||||||||||
| 1283 | - | |||||||||||||||||||
| 1284 | \since 5.6 | - | ||||||||||||||||||
| 1285 | \sa isAutoTristate(), setCheckable(), setCheckState() | - | ||||||||||||||||||
| 1286 | */ | - | ||||||||||||||||||
| 1287 | void QStandardItem::setAutoTristate(bool tristate) | - | ||||||||||||||||||
| 1288 | { | - | ||||||||||||||||||
| 1289 | Q_D(QStandardItem); | - | ||||||||||||||||||
| 1290 | d->changeFlags(tristate, Qt::ItemIsAutoTristate); | - | ||||||||||||||||||
| 1291 | } | - | ||||||||||||||||||
| 1292 | - | |||||||||||||||||||
| 1293 | /*! | - | ||||||||||||||||||
| 1294 | \fn bool QStandardItem::isAutoTristate() const | - | ||||||||||||||||||
| 1295 | - | |||||||||||||||||||
| 1296 | Returns whether the item is tristate and is controlled by QTreeWidget. | - | ||||||||||||||||||
| 1297 | - | |||||||||||||||||||
| 1298 | The default value is false. | - | ||||||||||||||||||
| 1299 | - | |||||||||||||||||||
| 1300 | \since 5.6 | - | ||||||||||||||||||
| 1301 | \sa setAutoTristate(), isCheckable(), checkState() | - | ||||||||||||||||||
| 1302 | */ | - | ||||||||||||||||||
| 1303 | - | |||||||||||||||||||
| 1304 | /*! | - | ||||||||||||||||||
| 1305 | Sets whether the item is tristate and controlled by the user. | - | ||||||||||||||||||
| 1306 | If \a tristate is true, the user can cycle through three separate states; | - | ||||||||||||||||||
| 1307 | otherwise, the item is checkable with two states. | - | ||||||||||||||||||
| 1308 | (Note that this also requires that the item is checkable; see isCheckable().) | - | ||||||||||||||||||
| 1309 | - | |||||||||||||||||||
| 1310 | \since 5.6 | - | ||||||||||||||||||
| 1311 | \sa isUserTristate(), setCheckable(), setCheckState() | - | ||||||||||||||||||
| 1312 | */ | - | ||||||||||||||||||
| 1313 | void QStandardItem::setUserTristate(bool tristate) | - | ||||||||||||||||||
| 1314 | { | - | ||||||||||||||||||
| 1315 | Q_D(QStandardItem); | - | ||||||||||||||||||
| 1316 | d->changeFlags(tristate, Qt::ItemIsUserTristate); | - | ||||||||||||||||||
| 1317 | } | - | ||||||||||||||||||
| 1318 | - | |||||||||||||||||||
| 1319 | /*! | - | ||||||||||||||||||
| 1320 | \fn bool QStandardItem::isUserTristate() const | - | ||||||||||||||||||
| 1321 | \since 5.6 | - | ||||||||||||||||||
| 1322 | - | |||||||||||||||||||
| 1323 | Returns whether the item is tristate; that is, if it's checkable with three | - | ||||||||||||||||||
| 1324 | separate states and the user can cycle through all three states. | - | ||||||||||||||||||
| 1325 | - | |||||||||||||||||||
| 1326 | The default value is false. | - | ||||||||||||||||||
| 1327 | - | |||||||||||||||||||
| 1328 | \sa setUserTristate(), isCheckable(), checkState() | - | ||||||||||||||||||
| 1329 | */ | - | ||||||||||||||||||
| 1330 | - | |||||||||||||||||||
| 1331 | #if QT_DEPRECATED_SINCE(5, 6) | - | ||||||||||||||||||
| 1332 | void QStandardItem::setTristate(bool tristate) | - | ||||||||||||||||||
| 1333 | { | - | ||||||||||||||||||
| 1334 | setAutoTristate(tristate); | - | ||||||||||||||||||
| 1335 | } | - | ||||||||||||||||||
| 1336 | #endif | - | ||||||||||||||||||
| 1337 | - | |||||||||||||||||||
| 1338 | #ifndef QT_NO_DRAGANDDROP | - | ||||||||||||||||||
| 1339 | - | |||||||||||||||||||
| 1340 | /*! | - | ||||||||||||||||||
| 1341 | Sets whether the item is drag enabled. If \a dragEnabled is true, the item | - | ||||||||||||||||||
| 1342 | can be dragged by the user; otherwise, the user cannot drag the item. | - | ||||||||||||||||||
| 1343 | - | |||||||||||||||||||
| 1344 | Note that you also need to ensure that item dragging is enabled in the view; | - | ||||||||||||||||||
| 1345 | see QAbstractItemView::dragEnabled. | - | ||||||||||||||||||
| 1346 | - | |||||||||||||||||||
| 1347 | \sa isDragEnabled(), setDropEnabled(), setFlags() | - | ||||||||||||||||||
| 1348 | */ | - | ||||||||||||||||||
| 1349 | void QStandardItem::setDragEnabled(bool dragEnabled) | - | ||||||||||||||||||
| 1350 | { | - | ||||||||||||||||||
| 1351 | Q_D(QStandardItem); | - | ||||||||||||||||||
| 1352 | d->changeFlags(dragEnabled, Qt::ItemIsDragEnabled); | - | ||||||||||||||||||
| 1353 | } | - | ||||||||||||||||||
| 1354 | - | |||||||||||||||||||
| 1355 | /*! | - | ||||||||||||||||||
| 1356 | \fn bool QStandardItem::isDragEnabled() const | - | ||||||||||||||||||
| 1357 | - | |||||||||||||||||||
| 1358 | Returns whether the item is drag enabled. An item that is drag enabled can | - | ||||||||||||||||||
| 1359 | be dragged by the user. | - | ||||||||||||||||||
| 1360 | - | |||||||||||||||||||
| 1361 | The default value is true. | - | ||||||||||||||||||
| 1362 | - | |||||||||||||||||||
| 1363 | Note that item dragging must be enabled in the view for dragging to work; | - | ||||||||||||||||||
| 1364 | see QAbstractItemView::dragEnabled. | - | ||||||||||||||||||
| 1365 | - | |||||||||||||||||||
| 1366 | \sa setDragEnabled(), isDropEnabled(), flags() | - | ||||||||||||||||||
| 1367 | */ | - | ||||||||||||||||||
| 1368 | - | |||||||||||||||||||
| 1369 | /*! | - | ||||||||||||||||||
| 1370 | Sets whether the item is drop enabled. If \a dropEnabled is true, the item | - | ||||||||||||||||||
| 1371 | can be used as a drop target; otherwise, it cannot. | - | ||||||||||||||||||
| 1372 | - | |||||||||||||||||||
| 1373 | Note that you also need to ensure that drops are enabled in the view; see | - | ||||||||||||||||||
| 1374 | QWidget::acceptDrops(); and that the model supports the desired drop actions; | - | ||||||||||||||||||
| 1375 | see QAbstractItemModel::supportedDropActions(). | - | ||||||||||||||||||
| 1376 | - | |||||||||||||||||||
| 1377 | \sa isDropEnabled(), setDragEnabled(), setFlags() | - | ||||||||||||||||||
| 1378 | */ | - | ||||||||||||||||||
| 1379 | void QStandardItem::setDropEnabled(bool dropEnabled) | - | ||||||||||||||||||
| 1380 | { | - | ||||||||||||||||||
| 1381 | Q_D(QStandardItem); | - | ||||||||||||||||||
| 1382 | d->changeFlags(dropEnabled, Qt::ItemIsDropEnabled); | - | ||||||||||||||||||
| 1383 | } | - | ||||||||||||||||||
| 1384 | - | |||||||||||||||||||
| 1385 | /*! | - | ||||||||||||||||||
| 1386 | \fn bool QStandardItem::isDropEnabled() const | - | ||||||||||||||||||
| 1387 | - | |||||||||||||||||||
| 1388 | Returns whether the item is drop enabled. When an item is drop enabled, it | - | ||||||||||||||||||
| 1389 | can be used as a drop target. | - | ||||||||||||||||||
| 1390 | - | |||||||||||||||||||
| 1391 | The default value is true. | - | ||||||||||||||||||
| 1392 | - | |||||||||||||||||||
| 1393 | \sa setDropEnabled(), isDragEnabled(), flags() | - | ||||||||||||||||||
| 1394 | */ | - | ||||||||||||||||||
| 1395 | - | |||||||||||||||||||
| 1396 | #endif // QT_NO_DRAGANDDROP | - | ||||||||||||||||||
| 1397 | - | |||||||||||||||||||
| 1398 | /*! | - | ||||||||||||||||||
| 1399 | Returns the row where the item is located in its parent's child table, or | - | ||||||||||||||||||
| 1400 | -1 if the item has no parent. | - | ||||||||||||||||||
| 1401 | - | |||||||||||||||||||
| 1402 | \sa column(), parent() | - | ||||||||||||||||||
| 1403 | */ | - | ||||||||||||||||||
| 1404 | int QStandardItem::row() const | - | ||||||||||||||||||
| 1405 | { | - | ||||||||||||||||||
| 1406 | Q_D(const QStandardItem); | - | ||||||||||||||||||
| 1407 | QPair<int, int> pos = d->position(); | - | ||||||||||||||||||
| 1408 | return pos.first; | - | ||||||||||||||||||
| 1409 | } | - | ||||||||||||||||||
| 1410 | - | |||||||||||||||||||
| 1411 | /*! | - | ||||||||||||||||||
| 1412 | Returns the column where the item is located in its parent's child table, | - | ||||||||||||||||||
| 1413 | or -1 if the item has no parent. | - | ||||||||||||||||||
| 1414 | - | |||||||||||||||||||
| 1415 | \sa row(), parent() | - | ||||||||||||||||||
| 1416 | */ | - | ||||||||||||||||||
| 1417 | int QStandardItem::column() const | - | ||||||||||||||||||
| 1418 | { | - | ||||||||||||||||||
| 1419 | Q_D(const QStandardItem); | - | ||||||||||||||||||
| 1420 | QPair<int, int> pos = d->position(); | - | ||||||||||||||||||
| 1421 | return pos.second; | - | ||||||||||||||||||
| 1422 | } | - | ||||||||||||||||||
| 1423 | - | |||||||||||||||||||
| 1424 | /*! | - | ||||||||||||||||||
| 1425 | Returns the QModelIndex associated with this item. | - | ||||||||||||||||||
| 1426 | - | |||||||||||||||||||
| 1427 | When you need to invoke item functionality in a QModelIndex-based API (e.g. | - | ||||||||||||||||||
| 1428 | QAbstractItemView), you can call this function to obtain an index that | - | ||||||||||||||||||
| 1429 | corresponds to the item's location in the model. | - | ||||||||||||||||||
| 1430 | - | |||||||||||||||||||
| 1431 | If the item is not associated with a model, an invalid QModelIndex is | - | ||||||||||||||||||
| 1432 | returned. | - | ||||||||||||||||||
| 1433 | - | |||||||||||||||||||
| 1434 | \sa model(), QStandardItemModel::itemFromIndex() | - | ||||||||||||||||||
| 1435 | */ | - | ||||||||||||||||||
| 1436 | QModelIndex QStandardItem::index() const | - | ||||||||||||||||||
| 1437 | { | - | ||||||||||||||||||
| 1438 | Q_D(const QStandardItem); | - | ||||||||||||||||||
| 1439 | return d->model ? d->model->indexFromItem(this) : QModelIndex(); | - | ||||||||||||||||||
| 1440 | } | - | ||||||||||||||||||
| 1441 | - | |||||||||||||||||||
| 1442 | /*! | - | ||||||||||||||||||
| 1443 | Returns the QStandardItemModel that this item belongs to. | - | ||||||||||||||||||
| 1444 | - | |||||||||||||||||||
| 1445 | If the item is not a child of another item that belongs to the model, this | - | ||||||||||||||||||
| 1446 | function returns 0. | - | ||||||||||||||||||
| 1447 | - | |||||||||||||||||||
| 1448 | \sa index() | - | ||||||||||||||||||
| 1449 | */ | - | ||||||||||||||||||
| 1450 | QStandardItemModel *QStandardItem::model() const | - | ||||||||||||||||||
| 1451 | { | - | ||||||||||||||||||
| 1452 | Q_D(const QStandardItem); | - | ||||||||||||||||||
| 1453 | return d->model; | - | ||||||||||||||||||
| 1454 | } | - | ||||||||||||||||||
| 1455 | - | |||||||||||||||||||
| 1456 | /*! | - | ||||||||||||||||||
| 1457 | Sets the number of child item rows to \a rows. If this is less than | - | ||||||||||||||||||
| 1458 | rowCount(), the data in the unwanted rows is discarded. | - | ||||||||||||||||||
| 1459 | - | |||||||||||||||||||
| 1460 | \sa rowCount(), setColumnCount() | - | ||||||||||||||||||
| 1461 | */ | - | ||||||||||||||||||
| 1462 | void QStandardItem::setRowCount(int rows) | - | ||||||||||||||||||
| 1463 | { | - | ||||||||||||||||||
| 1464 | int rc = rowCount(); | - | ||||||||||||||||||
| 1465 | if (rc == rows) | - | ||||||||||||||||||
| 1466 | return; | - | ||||||||||||||||||
| 1467 | if (rc < rows) | - | ||||||||||||||||||
| 1468 | insertRows(qMax(rc, 0), rows - rc); | - | ||||||||||||||||||
| 1469 | else | - | ||||||||||||||||||
| 1470 | removeRows(qMax(rows, 0), rc - rows); | - | ||||||||||||||||||
| 1471 | } | - | ||||||||||||||||||
| 1472 | - | |||||||||||||||||||
| 1473 | /*! | - | ||||||||||||||||||
| 1474 | Returns the number of child item rows that the item has. | - | ||||||||||||||||||
| 1475 | - | |||||||||||||||||||
| 1476 | \sa setRowCount(), columnCount() | - | ||||||||||||||||||
| 1477 | */ | - | ||||||||||||||||||
| 1478 | int QStandardItem::rowCount() const | - | ||||||||||||||||||
| 1479 | { | - | ||||||||||||||||||
| 1480 | Q_D(const QStandardItem); | - | ||||||||||||||||||
| 1481 | return d->rowCount(); | - | ||||||||||||||||||
| 1482 | } | - | ||||||||||||||||||
| 1483 | - | |||||||||||||||||||
| 1484 | /*! | - | ||||||||||||||||||
| 1485 | Sets the number of child item columns to \a columns. If this is less than | - | ||||||||||||||||||
| 1486 | columnCount(), the data in the unwanted columns is discarded. | - | ||||||||||||||||||
| 1487 | - | |||||||||||||||||||
| 1488 | \sa columnCount(), setRowCount() | - | ||||||||||||||||||
| 1489 | */ | - | ||||||||||||||||||
| 1490 | void QStandardItem::setColumnCount(int columns) | - | ||||||||||||||||||
| 1491 | { | - | ||||||||||||||||||
| 1492 | int cc = columnCount(); | - | ||||||||||||||||||
| 1493 | if (cc == columns) | - | ||||||||||||||||||
| 1494 | return; | - | ||||||||||||||||||
| 1495 | if (cc < columns) | - | ||||||||||||||||||
| 1496 | insertColumns(qMax(cc, 0), columns - cc); | - | ||||||||||||||||||
| 1497 | else | - | ||||||||||||||||||
| 1498 | removeColumns(qMax(columns, 0), cc - columns); | - | ||||||||||||||||||
| 1499 | } | - | ||||||||||||||||||
| 1500 | - | |||||||||||||||||||
| 1501 | /*! | - | ||||||||||||||||||
| 1502 | Returns the number of child item columns that the item has. | - | ||||||||||||||||||
| 1503 | - | |||||||||||||||||||
| 1504 | \sa setColumnCount(), rowCount() | - | ||||||||||||||||||
| 1505 | */ | - | ||||||||||||||||||
| 1506 | int QStandardItem::columnCount() const | - | ||||||||||||||||||
| 1507 | { | - | ||||||||||||||||||
| 1508 | Q_D(const QStandardItem); | - | ||||||||||||||||||
| 1509 | return d->columnCount(); | - | ||||||||||||||||||
| 1510 | } | - | ||||||||||||||||||
| 1511 | - | |||||||||||||||||||
| 1512 | /*! | - | ||||||||||||||||||
| 1513 | Inserts a row at \a row containing \a items. If necessary, the column | - | ||||||||||||||||||
| 1514 | count is increased to the size of \a items. | - | ||||||||||||||||||
| 1515 | - | |||||||||||||||||||
| 1516 | \sa insertRows(), insertColumn() | - | ||||||||||||||||||
| 1517 | */ | - | ||||||||||||||||||
| 1518 | void QStandardItem::insertRow(int row, const QList<QStandardItem*> &items) | - | ||||||||||||||||||
| 1519 | { | - | ||||||||||||||||||
| 1520 | Q_D(QStandardItem); | - | ||||||||||||||||||
| 1521 | if (row < 0) | - | ||||||||||||||||||
| 1522 | return; | - | ||||||||||||||||||
| 1523 | if (columnCount() < items.count()) | - | ||||||||||||||||||
| 1524 | setColumnCount(items.count()); | - | ||||||||||||||||||
| 1525 | d->insertRows(row, 1, items); | - | ||||||||||||||||||
| 1526 | } | - | ||||||||||||||||||
| 1527 | - | |||||||||||||||||||
| 1528 | /*! | - | ||||||||||||||||||
| 1529 | Inserts \a items at \a row. The column count won't be changed. | - | ||||||||||||||||||
| 1530 | - | |||||||||||||||||||
| 1531 | \sa insertRow(), insertColumn() | - | ||||||||||||||||||
| 1532 | */ | - | ||||||||||||||||||
| 1533 | void QStandardItem::insertRows(int row, const QList<QStandardItem*> &items) | - | ||||||||||||||||||
| 1534 | { | - | ||||||||||||||||||
| 1535 | Q_D(QStandardItem); | - | ||||||||||||||||||
| 1536 | if (row < 0) | - | ||||||||||||||||||
| 1537 | return; | - | ||||||||||||||||||
| 1538 | d->insertRows(row, items); | - | ||||||||||||||||||
| 1539 | } | - | ||||||||||||||||||
| 1540 | - | |||||||||||||||||||
| 1541 | /*! | - | ||||||||||||||||||
| 1542 | Inserts a column at \a column containing \a items. If necessary, | - | ||||||||||||||||||
| 1543 | the row count is increased to the size of \a items. | - | ||||||||||||||||||
| 1544 | - | |||||||||||||||||||
| 1545 | \sa insertColumns(), insertRow() | - | ||||||||||||||||||
| 1546 | */ | - | ||||||||||||||||||
| 1547 | void QStandardItem::insertColumn(int column, const QList<QStandardItem*> &items) | - | ||||||||||||||||||
| 1548 | { | - | ||||||||||||||||||
| 1549 | Q_D(QStandardItem); | - | ||||||||||||||||||
| 1550 | if (column < 0) | - | ||||||||||||||||||
| 1551 | return; | - | ||||||||||||||||||
| 1552 | if (rowCount() < items.count()) | - | ||||||||||||||||||
| 1553 | setRowCount(items.count()); | - | ||||||||||||||||||
| 1554 | d->insertColumns(column, 1, items); | - | ||||||||||||||||||
| 1555 | } | - | ||||||||||||||||||
| 1556 | - | |||||||||||||||||||
| 1557 | /*! | - | ||||||||||||||||||
| 1558 | Inserts \a count rows of child items at row \a row. | - | ||||||||||||||||||
| 1559 | - | |||||||||||||||||||
| 1560 | \sa insertRow(), insertColumns() | - | ||||||||||||||||||
| 1561 | */ | - | ||||||||||||||||||
| 1562 | void QStandardItem::insertRows(int row, int count) | - | ||||||||||||||||||
| 1563 | { | - | ||||||||||||||||||
| 1564 | Q_D(QStandardItem); | - | ||||||||||||||||||
| 1565 | if (rowCount() < row) { | - | ||||||||||||||||||
| 1566 | count += row - rowCount(); | - | ||||||||||||||||||
| 1567 | row = rowCount(); | - | ||||||||||||||||||
| 1568 | } | - | ||||||||||||||||||
| 1569 | d->insertRows(row, count, QList<QStandardItem*>()); | - | ||||||||||||||||||
| 1570 | } | - | ||||||||||||||||||
| 1571 | - | |||||||||||||||||||
| 1572 | /*! | - | ||||||||||||||||||
| 1573 | Inserts \a count columns of child items at column \a column. | - | ||||||||||||||||||
| 1574 | - | |||||||||||||||||||
| 1575 | \sa insertColumn(), insertRows() | - | ||||||||||||||||||
| 1576 | */ | - | ||||||||||||||||||
| 1577 | void QStandardItem::insertColumns(int column, int count) | - | ||||||||||||||||||
| 1578 | { | - | ||||||||||||||||||
| 1579 | Q_D(QStandardItem); | - | ||||||||||||||||||
| 1580 | if (columnCount() < column) { | - | ||||||||||||||||||
| 1581 | count += column - columnCount(); | - | ||||||||||||||||||
| 1582 | column = columnCount(); | - | ||||||||||||||||||
| 1583 | } | - | ||||||||||||||||||
| 1584 | d->insertColumns(column, count, QList<QStandardItem*>()); | - | ||||||||||||||||||
| 1585 | } | - | ||||||||||||||||||
| 1586 | - | |||||||||||||||||||
| 1587 | /*! | - | ||||||||||||||||||
| 1588 | \fn void QStandardItem::appendRow(const QList<QStandardItem*> &items) | - | ||||||||||||||||||
| 1589 | - | |||||||||||||||||||
| 1590 | Appends a row containing \a items. If necessary, the column count is | - | ||||||||||||||||||
| 1591 | increased to the size of \a items. | - | ||||||||||||||||||
| 1592 | - | |||||||||||||||||||
| 1593 | \sa insertRow() | - | ||||||||||||||||||
| 1594 | */ | - | ||||||||||||||||||
| 1595 | - | |||||||||||||||||||
| 1596 | /*! | - | ||||||||||||||||||
| 1597 | \fn void QStandardItem::appendRows(const QList<QStandardItem*> &items) | - | ||||||||||||||||||
| 1598 | - | |||||||||||||||||||
| 1599 | Appends rows containing \a items. The column count will not change. | - | ||||||||||||||||||
| 1600 | - | |||||||||||||||||||
| 1601 | \sa insertRow() | - | ||||||||||||||||||
| 1602 | */ | - | ||||||||||||||||||
| 1603 | - | |||||||||||||||||||
| 1604 | /*! | - | ||||||||||||||||||
| 1605 | \fn void QStandardItem::appendColumn(const QList<QStandardItem*> &items) | - | ||||||||||||||||||
| 1606 | - | |||||||||||||||||||
| 1607 | Appends a column containing \a items. If necessary, the row count is | - | ||||||||||||||||||
| 1608 | increased to the size of \a items. | - | ||||||||||||||||||
| 1609 | - | |||||||||||||||||||
| 1610 | \sa insertColumn() | - | ||||||||||||||||||
| 1611 | */ | - | ||||||||||||||||||
| 1612 | - | |||||||||||||||||||
| 1613 | /*! | - | ||||||||||||||||||
| 1614 | \fn bool QStandardItemModel::insertRow(int row, const QModelIndex &parent) | - | ||||||||||||||||||
| 1615 | - | |||||||||||||||||||
| 1616 | Inserts a single row before the given \a row in the child items of the | - | ||||||||||||||||||
| 1617 | \a parent specified. Returns \c true if the row is inserted; otherwise | - | ||||||||||||||||||
| 1618 | returns \c false. | - | ||||||||||||||||||
| 1619 | - | |||||||||||||||||||
| 1620 | \sa insertRows(), insertColumn(), removeRow() | - | ||||||||||||||||||
| 1621 | */ | - | ||||||||||||||||||
| 1622 | - | |||||||||||||||||||
| 1623 | /*! | - | ||||||||||||||||||
| 1624 | \fn bool QStandardItemModel::insertColumn(int column, const QModelIndex &parent) | - | ||||||||||||||||||
| 1625 | - | |||||||||||||||||||
| 1626 | Inserts a single column before the given \a column in the child items of | - | ||||||||||||||||||
| 1627 | the \a parent specified. Returns \c true if the column is inserted; otherwise | - | ||||||||||||||||||
| 1628 | returns \c false. | - | ||||||||||||||||||
| 1629 | - | |||||||||||||||||||
| 1630 | \sa insertColumns(), insertRow(), removeColumn() | - | ||||||||||||||||||
| 1631 | */ | - | ||||||||||||||||||
| 1632 | - | |||||||||||||||||||
| 1633 | /*! | - | ||||||||||||||||||
| 1634 | \fn QStandardItem::insertRow(int row, QStandardItem *item) | - | ||||||||||||||||||
| 1635 | \overload | - | ||||||||||||||||||
| 1636 | - | |||||||||||||||||||
| 1637 | Inserts a row at \a row containing \a item. | - | ||||||||||||||||||
| 1638 | - | |||||||||||||||||||
| 1639 | When building a list or a tree that has only one column, this function | - | ||||||||||||||||||
| 1640 | provides a convenient way to insert a single new item. | - | ||||||||||||||||||
| 1641 | */ | - | ||||||||||||||||||
| 1642 | - | |||||||||||||||||||
| 1643 | /*! | - | ||||||||||||||||||
| 1644 | \fn QStandardItem::appendRow(QStandardItem *item) | - | ||||||||||||||||||
| 1645 | \overload | - | ||||||||||||||||||
| 1646 | - | |||||||||||||||||||
| 1647 | Appends a row containing \a item. | - | ||||||||||||||||||
| 1648 | - | |||||||||||||||||||
| 1649 | When building a list or a tree that has only one column, this function | - | ||||||||||||||||||
| 1650 | provides a convenient way to append a single new item. | - | ||||||||||||||||||
| 1651 | */ | - | ||||||||||||||||||
| 1652 | - | |||||||||||||||||||
| 1653 | /*! | - | ||||||||||||||||||
| 1654 | Removes the given \a row. The items that were in the row are deleted. | - | ||||||||||||||||||
| 1655 | - | |||||||||||||||||||
| 1656 | \sa takeRow(), removeRows(), removeColumn() | - | ||||||||||||||||||
| 1657 | */ | - | ||||||||||||||||||
| 1658 | void QStandardItem::removeRow(int row) | - | ||||||||||||||||||
| 1659 | { | - | ||||||||||||||||||
| 1660 | removeRows(row, 1); | - | ||||||||||||||||||
| 1661 | } | - | ||||||||||||||||||
| 1662 | - | |||||||||||||||||||
| 1663 | /*! | - | ||||||||||||||||||
| 1664 | Removes the given \a column. The items that were in the | - | ||||||||||||||||||
| 1665 | column are deleted. | - | ||||||||||||||||||
| 1666 | - | |||||||||||||||||||
| 1667 | \sa takeColumn(), removeColumns(), removeRow() | - | ||||||||||||||||||
| 1668 | */ | - | ||||||||||||||||||
| 1669 | void QStandardItem::removeColumn(int column) | - | ||||||||||||||||||
| 1670 | { | - | ||||||||||||||||||
| 1671 | removeColumns(column, 1); | - | ||||||||||||||||||
| 1672 | } | - | ||||||||||||||||||
| 1673 | - | |||||||||||||||||||
| 1674 | /*! | - | ||||||||||||||||||
| 1675 | Removes \a count rows at row \a row. The items that were in those rows are | - | ||||||||||||||||||
| 1676 | deleted. | - | ||||||||||||||||||
| 1677 | - | |||||||||||||||||||
| 1678 | \sa removeRow(), removeColumn() | - | ||||||||||||||||||
| 1679 | */ | - | ||||||||||||||||||
| 1680 | void QStandardItem::removeRows(int row, int count) | - | ||||||||||||||||||
| 1681 | { | - | ||||||||||||||||||
| 1682 | Q_D(QStandardItem); | - | ||||||||||||||||||
| 1683 | if ((count < 1) || (row < 0) || ((row + count) > rowCount())) | - | ||||||||||||||||||
| 1684 | return; | - | ||||||||||||||||||
| 1685 | if (d->model) | - | ||||||||||||||||||
| 1686 | d->model->d_func()->rowsAboutToBeRemoved(this, row, row + count - 1); | - | ||||||||||||||||||
| 1687 | int i = d->childIndex(row, 0); | - | ||||||||||||||||||
| 1688 | int n = count * d->columnCount(); | - | ||||||||||||||||||
| 1689 | for (int j = i; j < n+i; ++j) { | - | ||||||||||||||||||
| 1690 | QStandardItem *oldItem = d->children.at(j); | - | ||||||||||||||||||
| 1691 | if (oldItem) | - | ||||||||||||||||||
| 1692 | oldItem->d_func()->setModel(0); | - | ||||||||||||||||||
| 1693 | delete oldItem; | - | ||||||||||||||||||
| 1694 | } | - | ||||||||||||||||||
| 1695 | d->children.remove(qMax(i, 0), n); | - | ||||||||||||||||||
| 1696 | d->rows -= count; | - | ||||||||||||||||||
| 1697 | if (d->model) | - | ||||||||||||||||||
| 1698 | d->model->d_func()->rowsRemoved(this, row, count); | - | ||||||||||||||||||
| 1699 | } | - | ||||||||||||||||||
| 1700 | - | |||||||||||||||||||
| 1701 | /*! | - | ||||||||||||||||||
| 1702 | Removes \a count columns at column \a column. The items that were in those | - | ||||||||||||||||||
| 1703 | columns are deleted. | - | ||||||||||||||||||
| 1704 | - | |||||||||||||||||||
| 1705 | \sa removeColumn(), removeRows() | - | ||||||||||||||||||
| 1706 | */ | - | ||||||||||||||||||
| 1707 | void QStandardItem::removeColumns(int column, int count) | - | ||||||||||||||||||
| 1708 | { | - | ||||||||||||||||||
| 1709 | Q_D(QStandardItem); | - | ||||||||||||||||||
| 1710 | if ((count < 1) || (column < 0) || ((column + count) > columnCount())) | - | ||||||||||||||||||
| 1711 | return; | - | ||||||||||||||||||
| 1712 | if (d->model) | - | ||||||||||||||||||
| 1713 | d->model->d_func()->columnsAboutToBeRemoved(this, column, column + count - 1); | - | ||||||||||||||||||
| 1714 | for (int row = d->rowCount() - 1; row >= 0; --row) { | - | ||||||||||||||||||
| 1715 | int i = d->childIndex(row, column); | - | ||||||||||||||||||
| 1716 | for (int j=i; j<i+count; ++j) { | - | ||||||||||||||||||
| 1717 | QStandardItem *oldItem = d->children.at(j); | - | ||||||||||||||||||
| 1718 | if (oldItem) | - | ||||||||||||||||||
| 1719 | oldItem->d_func()->setModel(0); | - | ||||||||||||||||||
| 1720 | delete oldItem; | - | ||||||||||||||||||
| 1721 | } | - | ||||||||||||||||||
| 1722 | d->children.remove(i, count); | - | ||||||||||||||||||
| 1723 | } | - | ||||||||||||||||||
| 1724 | d->columns -= count; | - | ||||||||||||||||||
| 1725 | if (d->model) | - | ||||||||||||||||||
| 1726 | d->model->d_func()->columnsRemoved(this, column, count); | - | ||||||||||||||||||
| 1727 | } | - | ||||||||||||||||||
| 1728 | - | |||||||||||||||||||
| 1729 | /*! | - | ||||||||||||||||||
| 1730 | Returns \c true if this item has any children; otherwise returns \c false. | - | ||||||||||||||||||
| 1731 | - | |||||||||||||||||||
| 1732 | \sa rowCount(), columnCount(), child() | - | ||||||||||||||||||
| 1733 | */ | - | ||||||||||||||||||
| 1734 | bool QStandardItem::hasChildren() const | - | ||||||||||||||||||
| 1735 | { | - | ||||||||||||||||||
| 1736 | return (rowCount() > 0) && (columnCount() > 0); | - | ||||||||||||||||||
| 1737 | } | - | ||||||||||||||||||
| 1738 | - | |||||||||||||||||||
| 1739 | /*! | - | ||||||||||||||||||
| 1740 | Sets the child item at (\a row, \a column) to \a item. This item (the parent | - | ||||||||||||||||||
| 1741 | item) takes ownership of \a item. If necessary, the row count and column | - | ||||||||||||||||||
| 1742 | count are increased to fit the item. | - | ||||||||||||||||||
| 1743 | - | |||||||||||||||||||
| 1744 | \sa child() | - | ||||||||||||||||||
| 1745 | */ | - | ||||||||||||||||||
| 1746 | void QStandardItem::setChild(int row, int column, QStandardItem *item) | - | ||||||||||||||||||
| 1747 | { | - | ||||||||||||||||||
| 1748 | Q_D(QStandardItem); | - | ||||||||||||||||||
| 1749 | d->setChild(row, column, item, true); | - | ||||||||||||||||||
| 1750 | } | - | ||||||||||||||||||
| 1751 | - | |||||||||||||||||||
| 1752 | /*! | - | ||||||||||||||||||
| 1753 | \fn QStandardItem::setChild(int row, QStandardItem *item) | - | ||||||||||||||||||
| 1754 | \overload | - | ||||||||||||||||||
| 1755 | - | |||||||||||||||||||
| 1756 | Sets the child at \a row to \a item. | - | ||||||||||||||||||
| 1757 | */ | - | ||||||||||||||||||
| 1758 | - | |||||||||||||||||||
| 1759 | /*! | - | ||||||||||||||||||
| 1760 | Returns the child item at (\a row, \a column) if one has been set; otherwise | - | ||||||||||||||||||
| 1761 | returns 0. | - | ||||||||||||||||||
| 1762 | - | |||||||||||||||||||
| 1763 | \sa setChild(), takeChild(), parent() | - | ||||||||||||||||||
| 1764 | */ | - | ||||||||||||||||||
| 1765 | QStandardItem *QStandardItem::child(int row, int column) const | - | ||||||||||||||||||
| 1766 | { | - | ||||||||||||||||||
| 1767 | Q_D(const QStandardItem); | - | ||||||||||||||||||
| 1768 | int index = d->childIndex(row, column); | - | ||||||||||||||||||
| 1769 | if (index == -1) | - | ||||||||||||||||||
| 1770 | return 0; | - | ||||||||||||||||||
| 1771 | return d->children.at(index); | - | ||||||||||||||||||
| 1772 | } | - | ||||||||||||||||||
| 1773 | - | |||||||||||||||||||
| 1774 | /*! | - | ||||||||||||||||||
| 1775 | Removes the child item at (\a row, \a column) without deleting it, and returns | - | ||||||||||||||||||
| 1776 | a pointer to the item. If there was no child at the given location, then | - | ||||||||||||||||||
| 1777 | this function returns 0. | - | ||||||||||||||||||
| 1778 | - | |||||||||||||||||||
| 1779 | Note that this function, unlike takeRow() and takeColumn(), does not affect | - | ||||||||||||||||||
| 1780 | the dimensions of the child table. | - | ||||||||||||||||||
| 1781 | - | |||||||||||||||||||
| 1782 | \sa child(), takeRow(), takeColumn() | - | ||||||||||||||||||
| 1783 | */ | - | ||||||||||||||||||
| 1784 | QStandardItem *QStandardItem::takeChild(int row, int column) | - | ||||||||||||||||||
| 1785 | { | - | ||||||||||||||||||
| 1786 | Q_D(QStandardItem); | - | ||||||||||||||||||
| 1787 | QStandardItem *item = 0; | - | ||||||||||||||||||
| 1788 | int index = d->childIndex(row, column); | - | ||||||||||||||||||
| 1789 | if (index != -1) { | - | ||||||||||||||||||
| 1790 | item = d->children.at(index); | - | ||||||||||||||||||
| 1791 | if (item) | - | ||||||||||||||||||
| 1792 | item->d_func()->setParentAndModel(0, 0); | - | ||||||||||||||||||
| 1793 | d->children.replace(index, 0); | - | ||||||||||||||||||
| 1794 | } | - | ||||||||||||||||||
| 1795 | return item; | - | ||||||||||||||||||
| 1796 | } | - | ||||||||||||||||||
| 1797 | - | |||||||||||||||||||
| 1798 | /*! | - | ||||||||||||||||||
| 1799 | Removes \a row without deleting the row items, and returns a list of | - | ||||||||||||||||||
| 1800 | pointers to the removed items. For items in the row that have not been | - | ||||||||||||||||||
| 1801 | set, the corresponding pointers in the list will be 0. | - | ||||||||||||||||||
| 1802 | - | |||||||||||||||||||
| 1803 | \sa removeRow(), insertRow(), takeColumn() | - | ||||||||||||||||||
| 1804 | */ | - | ||||||||||||||||||
| 1805 | QList<QStandardItem*> QStandardItem::takeRow(int row) | - | ||||||||||||||||||
| 1806 | { | - | ||||||||||||||||||
| 1807 | Q_D(QStandardItem); | - | ||||||||||||||||||
| 1808 | QList<QStandardItem*> items; | - | ||||||||||||||||||
| 1809 | if ((row < 0) || (row >= rowCount()))
| 0 | ||||||||||||||||||
| 1810 | return QList<QStandardItem*>();items; never executed: return items; | 0 | ||||||||||||||||||
| 1811 | if (d->model)
| 0 | ||||||||||||||||||
| 1812 | d->model->d_func()->rowsAboutToBeRemoved(this, row, row); never executed: d->model->d_func()->rowsAboutToBeRemoved(this, row, row); | 0 | ||||||||||||||||||
| 1813 | - | |||||||||||||||||||
| 1814 | QList<QStandardItem*> items;int index = d->childIndex(row, 0); // Will return -1 if there are no columns | - | ||||||||||||||||||
| 1815 | if (index != -1) {
| 0 | ||||||||||||||||||
| 1816 | int col_count = d->columnCount(); | - | ||||||||||||||||||
| 1817 | items.reserve(col_count); | - | ||||||||||||||||||
| 1818 | for (int column = 0; column < col_count; ++column) {
| 0 | ||||||||||||||||||
| 1819 | QStandardItem *ch = d->children.at(index + column); | - | ||||||||||||||||||
| 1820 | if (ch)
| 0 | ||||||||||||||||||
| 1821 | ch->d_func()->setParentAndModel(0, 0); never executed: ch->d_func()->setParentAndModel(0, 0); | 0 | ||||||||||||||||||
| 1822 | items.append(ch); | - | ||||||||||||||||||
| 1823 | } never executed: end of block | 0 | ||||||||||||||||||
| 1824 | d->children.remove(index, col_count); | - | ||||||||||||||||||
| 1825 | } never executed: end of block | 0 | ||||||||||||||||||
| 1826 | d->rows--; | - | ||||||||||||||||||
| 1827 | if (d->model)
| 0 | ||||||||||||||||||
| 1828 | d->model->d_func()->rowsRemoved(this, row, 1); never executed: d->model->d_func()->rowsRemoved(this, row, 1); | 0 | ||||||||||||||||||
| 1829 | return items; never executed: return items; | 0 | ||||||||||||||||||
| 1830 | } | - | ||||||||||||||||||
| 1831 | - | |||||||||||||||||||
| 1832 | /*! | - | ||||||||||||||||||
| 1833 | Removes \a column without deleting the column items, and returns a list of | - | ||||||||||||||||||
| 1834 | pointers to the removed items. For items in the column that have not been | - | ||||||||||||||||||
| 1835 | set, the corresponding pointers in the list will be 0. | - | ||||||||||||||||||
| 1836 | - | |||||||||||||||||||
| 1837 | \sa removeColumn(), insertColumn(), takeRow() | - | ||||||||||||||||||
| 1838 | */ | - | ||||||||||||||||||
| 1839 | QList<QStandardItem*> QStandardItem::takeColumn(int column) | - | ||||||||||||||||||
| 1840 | { | - | ||||||||||||||||||
| 1841 | Q_D(QStandardItem); | - | ||||||||||||||||||
| 1842 | QList<QStandardItem*> items; | - | ||||||||||||||||||
| 1843 | if ((column < 0) || (column >= columnCount()))
| 0 | ||||||||||||||||||
| 1844 | return QList<QStandardItem*>();items; never executed: return items; | 0 | ||||||||||||||||||
| 1845 | if (d->model)
| 0 | ||||||||||||||||||
| 1846 | d->model->d_func()->columnsAboutToBeRemoved(this, column, column); never executed: d->model->d_func()->columnsAboutToBeRemoved(this, column, column); | 0 | ||||||||||||||||||
| 1847 | - | |||||||||||||||||||
| 1848 | QList<QStandardItem*>const int rowCount = d->rowCount(); | - | ||||||||||||||||||
| 1849 | items;.reserve(rowCount); | - | ||||||||||||||||||
| 1850 | for (int row = d->rowCount ()- 1; row >= 0; --row) {
| 0 | ||||||||||||||||||
| 1851 | int index = d->childIndex(row, column); | - | ||||||||||||||||||
| 1852 | QStandardItem *ch = d->children.at(index); | - | ||||||||||||||||||
| 1853 | if (ch)
| 0 | ||||||||||||||||||
| 1854 | ch->d_func()->setParentAndModel(0, 0); never executed: ch->d_func()->setParentAndModel(0, 0); | 0 | ||||||||||||||||||
| 1855 | d->children.remove(index); | - | ||||||||||||||||||
| 1856 | items.prepend(ch); | - | ||||||||||||||||||
| 1857 | } never executed: end of block | 0 | ||||||||||||||||||
| 1858 | d->columns--; | - | ||||||||||||||||||
| 1859 | if (d->model)
| 0 | ||||||||||||||||||
| 1860 | d->model->d_func()->columnsRemoved(this, column, 1); never executed: d->model->d_func()->columnsRemoved(this, column, 1); | 0 | ||||||||||||||||||
| 1861 | return items; never executed: return items; | 0 | ||||||||||||||||||
| 1862 | } | - | ||||||||||||||||||
| 1863 | - | |||||||||||||||||||
| 1864 | /*! | - | ||||||||||||||||||
| 1865 | Returns \c true if this item is less than \a other; otherwise returns \c false. | - | ||||||||||||||||||
| 1866 | - | |||||||||||||||||||
| 1867 | The default implementation uses the data for the item's sort role (see | - | ||||||||||||||||||
| 1868 | QStandardItemModel::sortRole) to perform the comparison if the item | - | ||||||||||||||||||
| 1869 | belongs to a model; otherwise, the data for the item's Qt::DisplayRole | - | ||||||||||||||||||
| 1870 | (text()) is used to perform the comparison. | - | ||||||||||||||||||
| 1871 | - | |||||||||||||||||||
| 1872 | sortChildren() and QStandardItemModel::sort() use this function when | - | ||||||||||||||||||
| 1873 | sorting items. If you want custom sorting, you can subclass QStandardItem | - | ||||||||||||||||||
| 1874 | and reimplement this function. | - | ||||||||||||||||||
| 1875 | */ | - | ||||||||||||||||||
| 1876 | bool QStandardItem::operator<(const QStandardItem &other) const | - | ||||||||||||||||||
| 1877 | { | - | ||||||||||||||||||
| 1878 | const int role = model() ? model()->sortRole() : Qt::DisplayRole; | - | ||||||||||||||||||
| 1879 | const QVariant l = data(role), r = other.data(role); | - | ||||||||||||||||||
| 1880 | // this code is copied from QSortFilterProxyModel::lessThan() | - | ||||||||||||||||||
| 1881 | if (l.userType() == QVariant::Invalid) | - | ||||||||||||||||||
| 1882 | return false; | - | ||||||||||||||||||
| 1883 | if (r.userType() == QVariant::Invalid) | - | ||||||||||||||||||
| 1884 | return true; | - | ||||||||||||||||||
| 1885 | switch (l.userType()) { | - | ||||||||||||||||||
| 1886 | case QVariant::Int: | - | ||||||||||||||||||
| 1887 | return l.toInt() < r.toInt(); | - | ||||||||||||||||||
| 1888 | case QVariant::UInt: | - | ||||||||||||||||||
| 1889 | return l.toUInt() < r.toUInt(); | - | ||||||||||||||||||
| 1890 | case QVariant::LongLong: | - | ||||||||||||||||||
| 1891 | return l.toLongLong() < r.toLongLong(); | - | ||||||||||||||||||
| 1892 | case QVariant::ULongLong: | - | ||||||||||||||||||
| 1893 | return l.toULongLong() < r.toULongLong(); | - | ||||||||||||||||||
| 1894 | case QMetaType::Float: | - | ||||||||||||||||||
| 1895 | return l.toFloat() < r.toFloat(); | - | ||||||||||||||||||
| 1896 | case QVariant::Double: | - | ||||||||||||||||||
| 1897 | return l.toDouble() < r.toDouble(); | - | ||||||||||||||||||
| 1898 | case QVariant::Char: | - | ||||||||||||||||||
| 1899 | return l.toChar() < r.toChar(); | - | ||||||||||||||||||
| 1900 | case QVariant::Date: | - | ||||||||||||||||||
| 1901 | return l.toDate() < r.toDate(); | - | ||||||||||||||||||
| 1902 | case QVariant::Time: | - | ||||||||||||||||||
| 1903 | return l.toTime() < r.toTime(); | - | ||||||||||||||||||
| 1904 | case QVariant::DateTime: | - | ||||||||||||||||||
| 1905 | return l.toDateTime() < r.toDateTime(); | - | ||||||||||||||||||
| 1906 | case QVariant::String: | - | ||||||||||||||||||
| 1907 | default: | - | ||||||||||||||||||
| 1908 | return l.toString().compare(r.toString()) < 0; | - | ||||||||||||||||||
| 1909 | } | - | ||||||||||||||||||
| 1910 | } | - | ||||||||||||||||||
| 1911 | - | |||||||||||||||||||
| 1912 | /*! | - | ||||||||||||||||||
| 1913 | Sorts the children of the item using the given \a order, by the values in | - | ||||||||||||||||||
| 1914 | the given \a column. | - | ||||||||||||||||||
| 1915 | - | |||||||||||||||||||
| 1916 | \note This function is recursive, therefore it sorts the children of the | - | ||||||||||||||||||
| 1917 | item, its grandchildren, etc. | - | ||||||||||||||||||
| 1918 | - | |||||||||||||||||||
| 1919 | \sa {operator<()} | - | ||||||||||||||||||
| 1920 | */ | - | ||||||||||||||||||
| 1921 | void QStandardItem::sortChildren(int column, Qt::SortOrder order) | - | ||||||||||||||||||
| 1922 | { | - | ||||||||||||||||||
| 1923 | Q_D(QStandardItem); | - | ||||||||||||||||||
| 1924 | if ((column < 0) || (rowCount() == 0)) | - | ||||||||||||||||||
| 1925 | return; | - | ||||||||||||||||||
| 1926 | - | |||||||||||||||||||
| 1927 | QList<QPersistentModelIndex> parents; | - | ||||||||||||||||||
| 1928 | if (d->model) { | - | ||||||||||||||||||
| 1929 | parents << index(); | - | ||||||||||||||||||
| 1930 | emit d->model->layoutAboutToBeChanged(parents, QAbstractItemModel::VerticalSortHint); | - | ||||||||||||||||||
| 1931 | } | - | ||||||||||||||||||
| 1932 | d->sortChildren(column, order); | - | ||||||||||||||||||
| 1933 | if (d->model) | - | ||||||||||||||||||
| 1934 | emit d->model->layoutChanged(parents, QAbstractItemModel::VerticalSortHint); | - | ||||||||||||||||||
| 1935 | } | - | ||||||||||||||||||
| 1936 | - | |||||||||||||||||||
| 1937 | /*! | - | ||||||||||||||||||
| 1938 | Returns a copy of this item. The item's children are not copied. | - | ||||||||||||||||||
| 1939 | - | |||||||||||||||||||
| 1940 | When subclassing QStandardItem, you can reimplement this function | - | ||||||||||||||||||
| 1941 | to provide QStandardItemModel with a factory that it can use to | - | ||||||||||||||||||
| 1942 | create new items on demand. | - | ||||||||||||||||||
| 1943 | - | |||||||||||||||||||
| 1944 | \sa QStandardItemModel::setItemPrototype(), operator=() | - | ||||||||||||||||||
| 1945 | */ | - | ||||||||||||||||||
| 1946 | QStandardItem *QStandardItem::clone() const | - | ||||||||||||||||||
| 1947 | { | - | ||||||||||||||||||
| 1948 | return new QStandardItem(*this); | - | ||||||||||||||||||
| 1949 | } | - | ||||||||||||||||||
| 1950 | - | |||||||||||||||||||
| 1951 | /*! | - | ||||||||||||||||||
| 1952 | Returns the type of this item. The type is used to distinguish custom | - | ||||||||||||||||||
| 1953 | items from the base class. When subclassing QStandardItem, you should | - | ||||||||||||||||||
| 1954 | reimplement this function and return a new value greater than or equal | - | ||||||||||||||||||
| 1955 | to \l UserType. | - | ||||||||||||||||||
| 1956 | - | |||||||||||||||||||
| 1957 | \sa QStandardItem::Type | - | ||||||||||||||||||
| 1958 | */ | - | ||||||||||||||||||
| 1959 | int QStandardItem::type() const | - | ||||||||||||||||||
| 1960 | { | - | ||||||||||||||||||
| 1961 | return Type; | - | ||||||||||||||||||
| 1962 | } | - | ||||||||||||||||||
| 1963 | - | |||||||||||||||||||
| 1964 | #ifndef QT_NO_DATASTREAM | - | ||||||||||||||||||
| 1965 | - | |||||||||||||||||||
| 1966 | /*! | - | ||||||||||||||||||
| 1967 | Reads the item from stream \a in. Only the data and flags of the item are | - | ||||||||||||||||||
| 1968 | read, not the child items. | - | ||||||||||||||||||
| 1969 | - | |||||||||||||||||||
| 1970 | \sa write() | - | ||||||||||||||||||
| 1971 | */ | - | ||||||||||||||||||
| 1972 | void QStandardItem::read(QDataStream &in) | - | ||||||||||||||||||
| 1973 | { | - | ||||||||||||||||||
| 1974 | Q_D(QStandardItem); | - | ||||||||||||||||||
| 1975 | in >> d->values; | - | ||||||||||||||||||
| 1976 | qint32 flags; | - | ||||||||||||||||||
| 1977 | in >> flags; | - | ||||||||||||||||||
| 1978 | setFlags(Qt::ItemFlags(flags)); | - | ||||||||||||||||||
| 1979 | } | - | ||||||||||||||||||
| 1980 | - | |||||||||||||||||||
| 1981 | /*! | - | ||||||||||||||||||
| 1982 | Writes the item to stream \a out. Only the data and flags of the item | - | ||||||||||||||||||
| 1983 | are written, not the child items. | - | ||||||||||||||||||
| 1984 | - | |||||||||||||||||||
| 1985 | \sa read() | - | ||||||||||||||||||
| 1986 | */ | - | ||||||||||||||||||
| 1987 | void QStandardItem::write(QDataStream &out) const | - | ||||||||||||||||||
| 1988 | { | - | ||||||||||||||||||
| 1989 | Q_D(const QStandardItem); | - | ||||||||||||||||||
| 1990 | out << d->values; | - | ||||||||||||||||||
| 1991 | out << flags(); | - | ||||||||||||||||||
| 1992 | } | - | ||||||||||||||||||
| 1993 | - | |||||||||||||||||||
| 1994 | /*! | - | ||||||||||||||||||
| 1995 | \relates QStandardItem | - | ||||||||||||||||||
| 1996 | \since 4.2 | - | ||||||||||||||||||
| 1997 | - | |||||||||||||||||||
| 1998 | Reads a QStandardItem from stream \a in into \a item. | - | ||||||||||||||||||
| 1999 | - | |||||||||||||||||||
| 2000 | This operator uses QStandardItem::read(). | - | ||||||||||||||||||
| 2001 | - | |||||||||||||||||||
| 2002 | \sa {Serializing Qt Data Types} | - | ||||||||||||||||||
| 2003 | */ | - | ||||||||||||||||||
| 2004 | QDataStream &operator>>(QDataStream &in, QStandardItem &item) | - | ||||||||||||||||||
| 2005 | { | - | ||||||||||||||||||
| 2006 | item.read(in); | - | ||||||||||||||||||
| 2007 | return in; | - | ||||||||||||||||||
| 2008 | } | - | ||||||||||||||||||
| 2009 | - | |||||||||||||||||||
| 2010 | /*! | - | ||||||||||||||||||
| 2011 | \relates QStandardItem | - | ||||||||||||||||||
| 2012 | \since 4.2 | - | ||||||||||||||||||
| 2013 | - | |||||||||||||||||||
| 2014 | Writes the QStandardItem \a item to stream \a out. | - | ||||||||||||||||||
| 2015 | - | |||||||||||||||||||
| 2016 | This operator uses QStandardItem::write(). | - | ||||||||||||||||||
| 2017 | - | |||||||||||||||||||
| 2018 | \sa {Serializing Qt Data Types} | - | ||||||||||||||||||
| 2019 | */ | - | ||||||||||||||||||
| 2020 | QDataStream &operator<<(QDataStream &out, const QStandardItem &item) | - | ||||||||||||||||||
| 2021 | { | - | ||||||||||||||||||
| 2022 | item.write(out); | - | ||||||||||||||||||
| 2023 | return out; | - | ||||||||||||||||||
| 2024 | } | - | ||||||||||||||||||
| 2025 | - | |||||||||||||||||||
| 2026 | #endif // QT_NO_DATASTREAM | - | ||||||||||||||||||
| 2027 | - | |||||||||||||||||||
| 2028 | /*! | - | ||||||||||||||||||
| 2029 | \class QStandardItemModel | - | ||||||||||||||||||
| 2030 | \brief The QStandardItemModel class provides a generic model for storing custom data. | - | ||||||||||||||||||
| 2031 | \ingroup model-view | - | ||||||||||||||||||
| 2032 | \inmodule QtGui | - | ||||||||||||||||||
| 2033 | - | |||||||||||||||||||
| 2034 | QStandardItemModel can be used as a repository for standard Qt | - | ||||||||||||||||||
| 2035 | data types. It is one of the \l {Model/View Classes} and is part | - | ||||||||||||||||||
| 2036 | of Qt's \l {Model/View Programming}{model/view} framework. | - | ||||||||||||||||||
| 2037 | - | |||||||||||||||||||
| 2038 | QStandardItemModel provides a classic item-based approach to working with | - | ||||||||||||||||||
| 2039 | the model. The items in a QStandardItemModel are provided by | - | ||||||||||||||||||
| 2040 | QStandardItem. | - | ||||||||||||||||||
| 2041 | - | |||||||||||||||||||
| 2042 | QStandardItemModel implements the QAbstractItemModel interface, which | - | ||||||||||||||||||
| 2043 | means that the model can be used to provide data in any view that supports | - | ||||||||||||||||||
| 2044 | that interface (such as QListView, QTableView and QTreeView, and your own | - | ||||||||||||||||||
| 2045 | custom views). For performance and flexibility, you may want to subclass | - | ||||||||||||||||||
| 2046 | QAbstractItemModel to provide support for different kinds of data | - | ||||||||||||||||||
| 2047 | repositories. For example, the QDirModel provides a model interface to the | - | ||||||||||||||||||
| 2048 | underlying file system. | - | ||||||||||||||||||
| 2049 | - | |||||||||||||||||||
| 2050 | When you want a list or tree, you typically create an empty | - | ||||||||||||||||||
| 2051 | QStandardItemModel and use appendRow() to add items to the model, and | - | ||||||||||||||||||
| 2052 | item() to access an item. If your model represents a table, you typically | - | ||||||||||||||||||
| 2053 | pass the dimensions of the table to the QStandardItemModel constructor and | - | ||||||||||||||||||
| 2054 | use setItem() to position items into the table. You can also use setRowCount() | - | ||||||||||||||||||
| 2055 | and setColumnCount() to alter the dimensions of the model. To insert items, | - | ||||||||||||||||||
| 2056 | use insertRow() or insertColumn(), and to remove items, use removeRow() or | - | ||||||||||||||||||
| 2057 | removeColumn(). | - | ||||||||||||||||||
| 2058 | - | |||||||||||||||||||
| 2059 | You can set the header labels of your model with setHorizontalHeaderLabels() | - | ||||||||||||||||||
| 2060 | and setVerticalHeaderLabels(). | - | ||||||||||||||||||
| 2061 | - | |||||||||||||||||||
| 2062 | You can search for items in the model with findItems(), and sort the model by | - | ||||||||||||||||||
| 2063 | calling sort(). | - | ||||||||||||||||||
| 2064 | - | |||||||||||||||||||
| 2065 | Call clear() to remove all items from the model. | - | ||||||||||||||||||
| 2066 | - | |||||||||||||||||||
| 2067 | An example usage of QStandardItemModel to create a table: | - | ||||||||||||||||||
| 2068 | - | |||||||||||||||||||
| 2069 | \snippet code/src_gui_itemviews_qstandarditemmodel.cpp 0 | - | ||||||||||||||||||
| 2070 | - | |||||||||||||||||||
| 2071 | An example usage of QStandardItemModel to create a tree: | - | ||||||||||||||||||
| 2072 | - | |||||||||||||||||||
| 2073 | \snippet code/src_gui_itemviews_qstandarditemmodel.cpp 1 | - | ||||||||||||||||||
| 2074 | - | |||||||||||||||||||
| 2075 | After setting the model on a view, you typically want to react to user | - | ||||||||||||||||||
| 2076 | actions, such as an item being clicked. Since a QAbstractItemView provides | - | ||||||||||||||||||
| 2077 | QModelIndex-based signals and functions, you need a way to obtain the | - | ||||||||||||||||||
| 2078 | QStandardItem that corresponds to a given QModelIndex, and vice | - | ||||||||||||||||||
| 2079 | versa. itemFromIndex() and indexFromItem() provide this mapping. Typical | - | ||||||||||||||||||
| 2080 | usage of itemFromIndex() includes obtaining the item at the current index | - | ||||||||||||||||||
| 2081 | in a view, and obtaining the item that corresponds to an index carried by | - | ||||||||||||||||||
| 2082 | a QAbstractItemView signal, such as QAbstractItemView::clicked(). First | - | ||||||||||||||||||
| 2083 | you connect the view's signal to a slot in your class: | - | ||||||||||||||||||
| 2084 | - | |||||||||||||||||||
| 2085 | \snippet code/src_gui_itemviews_qstandarditemmodel.cpp 2 | - | ||||||||||||||||||
| 2086 | - | |||||||||||||||||||
| 2087 | When you receive the signal, you call itemFromIndex() on the given model | - | ||||||||||||||||||
| 2088 | index to get a pointer to the item: | - | ||||||||||||||||||
| 2089 | - | |||||||||||||||||||
| 2090 | \snippet code/src_gui_itemviews_qstandarditemmodel.cpp 3 | - | ||||||||||||||||||
| 2091 | - | |||||||||||||||||||
| 2092 | Conversely, you must obtain the QModelIndex of an item when you want to | - | ||||||||||||||||||
| 2093 | invoke a model/view function that takes an index as argument. You can | - | ||||||||||||||||||
| 2094 | obtain the index either by using the model's indexFromItem() function, or, | - | ||||||||||||||||||
| 2095 | equivalently, by calling QStandardItem::index(): | - | ||||||||||||||||||
| 2096 | - | |||||||||||||||||||
| 2097 | \snippet code/src_gui_itemviews_qstandarditemmodel.cpp 4 | - | ||||||||||||||||||
| 2098 | - | |||||||||||||||||||
| 2099 | You are, of course, not required to use the item-based approach; you could | - | ||||||||||||||||||
| 2100 | instead rely entirely on the QAbstractItemModel interface when working with | - | ||||||||||||||||||
| 2101 | the model, or use a combination of the two as appropriate. | - | ||||||||||||||||||
| 2102 | - | |||||||||||||||||||
| 2103 | \sa QStandardItem, {Model/View Programming}, QAbstractItemModel, | - | ||||||||||||||||||
| 2104 | {itemviews/simpletreemodel}{Simple Tree Model example}, | - | ||||||||||||||||||
| 2105 | {Item View Convenience Classes} | - | ||||||||||||||||||
| 2106 | */ | - | ||||||||||||||||||
| 2107 | - | |||||||||||||||||||
| 2108 | /*! | - | ||||||||||||||||||
| 2109 | \fn void QStandardItemModel::itemChanged(QStandardItem *item) | - | ||||||||||||||||||
| 2110 | \since 4.2 | - | ||||||||||||||||||
| 2111 | - | |||||||||||||||||||
| 2112 | This signal is emitted whenever the data of \a item has changed. | - | ||||||||||||||||||
| 2113 | */ | - | ||||||||||||||||||
| 2114 | - | |||||||||||||||||||
| 2115 | /*! | - | ||||||||||||||||||
| 2116 | Constructs a new item model with the given \a parent. | - | ||||||||||||||||||
| 2117 | */ | - | ||||||||||||||||||
| 2118 | QStandardItemModel::QStandardItemModel(QObject *parent) | - | ||||||||||||||||||
| 2119 | : QAbstractItemModel(*new QStandardItemModelPrivate, parent) | - | ||||||||||||||||||
| 2120 | { | - | ||||||||||||||||||
| 2121 | Q_D(QStandardItemModel); | - | ||||||||||||||||||
| 2122 | d->init(); | - | ||||||||||||||||||
| 2123 | d->root->d_func()->setModel(this); | - | ||||||||||||||||||
| 2124 | } | - | ||||||||||||||||||
| 2125 | - | |||||||||||||||||||
| 2126 | /*! | - | ||||||||||||||||||
| 2127 | Constructs a new item model that initially has \a rows rows and \a columns | - | ||||||||||||||||||
| 2128 | columns, and that has the given \a parent. | - | ||||||||||||||||||
| 2129 | */ | - | ||||||||||||||||||
| 2130 | QStandardItemModel::QStandardItemModel(int rows, int columns, QObject *parent) | - | ||||||||||||||||||
| 2131 | : QAbstractItemModel(*new QStandardItemModelPrivate, parent) | - | ||||||||||||||||||
| 2132 | { | - | ||||||||||||||||||
| 2133 | Q_D(QStandardItemModel); | - | ||||||||||||||||||
| 2134 | d->init(); | - | ||||||||||||||||||
| 2135 | d->root->insertColumns(0, columns); | - | ||||||||||||||||||
| 2136 | d->columnHeaderItems.insert(0, columns, 0); | - | ||||||||||||||||||
| 2137 | d->root->insertRows(0, rows); | - | ||||||||||||||||||
| 2138 | d->rowHeaderItems.insert(0, rows, 0); | - | ||||||||||||||||||
| 2139 | d->root->d_func()->setModel(this); | - | ||||||||||||||||||
| 2140 | } | - | ||||||||||||||||||
| 2141 | - | |||||||||||||||||||
| 2142 | /*! | - | ||||||||||||||||||
| 2143 | \internal | - | ||||||||||||||||||
| 2144 | */ | - | ||||||||||||||||||
| 2145 | QStandardItemModel::QStandardItemModel(QStandardItemModelPrivate &dd, QObject *parent) | - | ||||||||||||||||||
| 2146 | : QAbstractItemModel(dd, parent) | - | ||||||||||||||||||
| 2147 | { | - | ||||||||||||||||||
| 2148 | Q_D(QStandardItemModel); | - | ||||||||||||||||||
| 2149 | d->init(); | - | ||||||||||||||||||
| 2150 | } | - | ||||||||||||||||||
| 2151 | - | |||||||||||||||||||
| 2152 | /*! | - | ||||||||||||||||||
| 2153 | Destructs the model. The model destroys all its items. | - | ||||||||||||||||||
| 2154 | */ | - | ||||||||||||||||||
| 2155 | QStandardItemModel::~QStandardItemModel() | - | ||||||||||||||||||
| 2156 | { | - | ||||||||||||||||||
| 2157 | } | - | ||||||||||||||||||
| 2158 | - | |||||||||||||||||||
| 2159 | /*! | - | ||||||||||||||||||
| 2160 | Sets the item role names to \a roleNames. | - | ||||||||||||||||||
| 2161 | */ | - | ||||||||||||||||||
| 2162 | void QStandardItemModel::setItemRoleNames(const QHash<int,QByteArray> &roleNames) | - | ||||||||||||||||||
| 2163 | { | - | ||||||||||||||||||
| 2164 | Q_D(QStandardItemModel); | - | ||||||||||||||||||
| 2165 | d->roleNames = roleNames; | - | ||||||||||||||||||
| 2166 | } | - | ||||||||||||||||||
| 2167 | - | |||||||||||||||||||
| 2168 | /*! | - | ||||||||||||||||||
| 2169 | Removes all items (including header items) from the model and sets the | - | ||||||||||||||||||
| 2170 | number of rows and columns to zero. | - | ||||||||||||||||||
| 2171 | - | |||||||||||||||||||
| 2172 | \sa removeColumns(), removeRows() | - | ||||||||||||||||||
| 2173 | */ | - | ||||||||||||||||||
| 2174 | void QStandardItemModel::clear() | - | ||||||||||||||||||
| 2175 | { | - | ||||||||||||||||||
| 2176 | Q_D(QStandardItemModel); | - | ||||||||||||||||||
| 2177 | beginResetModel(); | - | ||||||||||||||||||
| 2178 | d->root.reset(new QStandardItem); | - | ||||||||||||||||||
| 2179 | d->root->setFlags(Qt::ItemIsDropEnabled); | - | ||||||||||||||||||
| 2180 | d->root->d_func()->setModel(this); | - | ||||||||||||||||||
| 2181 | qDeleteAll(d->columnHeaderItems); | - | ||||||||||||||||||
| 2182 | d->columnHeaderItems.clear(); | - | ||||||||||||||||||
| 2183 | qDeleteAll(d->rowHeaderItems); | - | ||||||||||||||||||
| 2184 | d->rowHeaderItems.clear(); | - | ||||||||||||||||||
| 2185 | endResetModel(); | - | ||||||||||||||||||
| 2186 | } never executed: end of block | 0 | ||||||||||||||||||
| 2187 | - | |||||||||||||||||||
| 2188 | /*! | - | ||||||||||||||||||
| 2189 | \since 4.2 | - | ||||||||||||||||||
| 2190 | - | |||||||||||||||||||
| 2191 | Returns a pointer to the QStandardItem associated with the given \a index. | - | ||||||||||||||||||
| 2192 | - | |||||||||||||||||||
| 2193 | Calling this function is typically the initial step when processing | - | ||||||||||||||||||
| 2194 | QModelIndex-based signals from a view, such as | - | ||||||||||||||||||
| 2195 | QAbstractItemView::activated(). In your slot, you call itemFromIndex(), | - | ||||||||||||||||||
| 2196 | with the QModelIndex carried by the signal as argument, to obtain a | - | ||||||||||||||||||
| 2197 | pointer to the corresponding QStandardItem. | - | ||||||||||||||||||
| 2198 | - | |||||||||||||||||||
| 2199 | Note that this function will lazily create an item for the index (using | - | ||||||||||||||||||
| 2200 | itemPrototype()), and set it in the parent item's child table, if no item | - | ||||||||||||||||||
| 2201 | already exists at that index. | - | ||||||||||||||||||
| 2202 | - | |||||||||||||||||||
| 2203 | If \a index is an invalid index, this function returns 0. | - | ||||||||||||||||||
| 2204 | - | |||||||||||||||||||
| 2205 | \sa indexFromItem() | - | ||||||||||||||||||
| 2206 | */ | - | ||||||||||||||||||
| 2207 | QStandardItem *QStandardItemModel::itemFromIndex(const QModelIndex &index) const | - | ||||||||||||||||||
| 2208 | { | - | ||||||||||||||||||
| 2209 | Q_D(const QStandardItemModel); | - | ||||||||||||||||||
| 2210 | if ((index.row() < 0) || (index.column() < 0) || (index.model() != this)) | - | ||||||||||||||||||
| 2211 | return 0; | - | ||||||||||||||||||
| 2212 | QStandardItem *parent = static_cast<QStandardItem*>(index.internalPointer()); | - | ||||||||||||||||||
| 2213 | if (parent == 0) | - | ||||||||||||||||||
| 2214 | return 0; | - | ||||||||||||||||||
| 2215 | QStandardItem *item = parent->child(index.row(), index.column()); | - | ||||||||||||||||||
| 2216 | // lazy part | - | ||||||||||||||||||
| 2217 | if (item == 0) { | - | ||||||||||||||||||
| 2218 | item = d->createItem(); | - | ||||||||||||||||||
| 2219 | parent->d_func()->setChild(index.row(), index.column(), item); | - | ||||||||||||||||||
| 2220 | } | - | ||||||||||||||||||
| 2221 | return item; | - | ||||||||||||||||||
| 2222 | } | - | ||||||||||||||||||
| 2223 | - | |||||||||||||||||||
| 2224 | /*! | - | ||||||||||||||||||
| 2225 | \since 4.2 | - | ||||||||||||||||||
| 2226 | - | |||||||||||||||||||
| 2227 | Returns the QModelIndex associated with the given \a item. | - | ||||||||||||||||||
| 2228 | - | |||||||||||||||||||
| 2229 | Use this function when you want to perform an operation that requires the | - | ||||||||||||||||||
| 2230 | QModelIndex of the item, such as | - | ||||||||||||||||||
| 2231 | QAbstractItemView::scrollTo(). QStandardItem::index() is provided as | - | ||||||||||||||||||
| 2232 | convenience; it is equivalent to calling this function. | - | ||||||||||||||||||
| 2233 | - | |||||||||||||||||||
| 2234 | \sa itemFromIndex(), QStandardItem::index() | - | ||||||||||||||||||
| 2235 | */ | - | ||||||||||||||||||
| 2236 | QModelIndex QStandardItemModel::indexFromItem(const QStandardItem *item) const | - | ||||||||||||||||||
| 2237 | { | - | ||||||||||||||||||
| 2238 | if (item && item->d_func()->parent) { | - | ||||||||||||||||||
| 2239 | QPair<int, int> pos = item->d_func()->position(); | - | ||||||||||||||||||
| 2240 | return createIndex(pos.first, pos.second, item->d_func()->parent); | - | ||||||||||||||||||
| 2241 | } | - | ||||||||||||||||||
| 2242 | return QModelIndex(); | - | ||||||||||||||||||
| 2243 | } | - | ||||||||||||||||||
| 2244 | - | |||||||||||||||||||
| 2245 | /*! | - | ||||||||||||||||||
| 2246 | \since 4.2 | - | ||||||||||||||||||
| 2247 | - | |||||||||||||||||||
| 2248 | Sets the number of rows in this model to \a rows. If | - | ||||||||||||||||||
| 2249 | this is less than rowCount(), the data in the unwanted rows | - | ||||||||||||||||||
| 2250 | is discarded. | - | ||||||||||||||||||
| 2251 | - | |||||||||||||||||||
| 2252 | \sa setColumnCount() | - | ||||||||||||||||||
| 2253 | */ | - | ||||||||||||||||||
| 2254 | void QStandardItemModel::setRowCount(int rows) | - | ||||||||||||||||||
| 2255 | { | - | ||||||||||||||||||
| 2256 | Q_D(QStandardItemModel); | - | ||||||||||||||||||
| 2257 | d->root->setRowCount(rows); | - | ||||||||||||||||||
| 2258 | } | - | ||||||||||||||||||
| 2259 | - | |||||||||||||||||||
| 2260 | /*! | - | ||||||||||||||||||
| 2261 | \since 4.2 | - | ||||||||||||||||||
| 2262 | - | |||||||||||||||||||
| 2263 | Sets the number of columns in this model to \a columns. If | - | ||||||||||||||||||
| 2264 | this is less than columnCount(), the data in the unwanted columns | - | ||||||||||||||||||
| 2265 | is discarded. | - | ||||||||||||||||||
| 2266 | - | |||||||||||||||||||
| 2267 | \sa setRowCount() | - | ||||||||||||||||||
| 2268 | */ | - | ||||||||||||||||||
| 2269 | void QStandardItemModel::setColumnCount(int columns) | - | ||||||||||||||||||
| 2270 | { | - | ||||||||||||||||||
| 2271 | Q_D(QStandardItemModel); | - | ||||||||||||||||||
| 2272 | d->root->setColumnCount(columns); | - | ||||||||||||||||||
| 2273 | } | - | ||||||||||||||||||
| 2274 | - | |||||||||||||||||||
| 2275 | /*! | - | ||||||||||||||||||
| 2276 | \since 4.2 | - | ||||||||||||||||||
| 2277 | - | |||||||||||||||||||
| 2278 | Sets the item for the given \a row and \a column to \a item. The model | - | ||||||||||||||||||
| 2279 | takes ownership of the item. If necessary, the row count and column count | - | ||||||||||||||||||
| 2280 | are increased to fit the item. The previous item at the given location (if | - | ||||||||||||||||||
| 2281 | there was one) is deleted. | - | ||||||||||||||||||
| 2282 | - | |||||||||||||||||||
| 2283 | \sa item() | - | ||||||||||||||||||
| 2284 | */ | - | ||||||||||||||||||
| 2285 | void QStandardItemModel::setItem(int row, int column, QStandardItem *item) | - | ||||||||||||||||||
| 2286 | { | - | ||||||||||||||||||
| 2287 | Q_D(QStandardItemModel); | - | ||||||||||||||||||
| 2288 | d->root->d_func()->setChild(row, column, item, true); | - | ||||||||||||||||||
| 2289 | } | - | ||||||||||||||||||
| 2290 | - | |||||||||||||||||||
| 2291 | /*! | - | ||||||||||||||||||
| 2292 | \fn QStandardItemModel::setItem(int row, QStandardItem *item) | - | ||||||||||||||||||
| 2293 | \overload | - | ||||||||||||||||||
| 2294 | */ | - | ||||||||||||||||||
| 2295 | - | |||||||||||||||||||
| 2296 | /*! | - | ||||||||||||||||||
| 2297 | \since 4.2 | - | ||||||||||||||||||
| 2298 | - | |||||||||||||||||||
| 2299 | Returns the item for the given \a row and \a column if one has been set; | - | ||||||||||||||||||
| 2300 | otherwise returns 0. | - | ||||||||||||||||||
| 2301 | - | |||||||||||||||||||
| 2302 | \sa setItem(), takeItem(), itemFromIndex() | - | ||||||||||||||||||
| 2303 | */ | - | ||||||||||||||||||
| 2304 | QStandardItem *QStandardItemModel::item(int row, int column) const | - | ||||||||||||||||||
| 2305 | { | - | ||||||||||||||||||
| 2306 | Q_D(const QStandardItemModel); | - | ||||||||||||||||||
| 2307 | return d->root->child(row, column); | - | ||||||||||||||||||
| 2308 | } | - | ||||||||||||||||||
| 2309 | - | |||||||||||||||||||
| 2310 | /*! | - | ||||||||||||||||||
| 2311 | \since 4.2 | - | ||||||||||||||||||
| 2312 | - | |||||||||||||||||||
| 2313 | Returns the model's invisible root item. | - | ||||||||||||||||||
| 2314 | - | |||||||||||||||||||
| 2315 | The invisible root item provides access to the model's top-level items | - | ||||||||||||||||||
| 2316 | through the QStandardItem API, making it possible to write functions that | - | ||||||||||||||||||
| 2317 | can treat top-level items and their children in a uniform way; for | - | ||||||||||||||||||
| 2318 | example, recursive functions involving a tree model. | - | ||||||||||||||||||
| 2319 | - | |||||||||||||||||||
| 2320 | \note Calling \l{QAbstractItemModel::index()}{index()} on the QStandardItem object | - | ||||||||||||||||||
| 2321 | retrieved from this function is not valid. | - | ||||||||||||||||||
| 2322 | */ | - | ||||||||||||||||||
| 2323 | QStandardItem *QStandardItemModel::invisibleRootItem() const | - | ||||||||||||||||||
| 2324 | { | - | ||||||||||||||||||
| 2325 | Q_D(const QStandardItemModel); | - | ||||||||||||||||||
| 2326 | return d->root.data(); | - | ||||||||||||||||||
| 2327 | } | - | ||||||||||||||||||
| 2328 | - | |||||||||||||||||||
| 2329 | /*! | - | ||||||||||||||||||
| 2330 | \since 4.2 | - | ||||||||||||||||||
| 2331 | - | |||||||||||||||||||
| 2332 | Sets the horizontal header item for \a column to \a item. The model takes | - | ||||||||||||||||||
| 2333 | ownership of the item. If necessary, the column count is increased to fit | - | ||||||||||||||||||
| 2334 | the item. The previous header item (if there was one) is deleted. | - | ||||||||||||||||||
| 2335 | - | |||||||||||||||||||
| 2336 | \sa horizontalHeaderItem(), setHorizontalHeaderLabels(), | - | ||||||||||||||||||
| 2337 | setVerticalHeaderItem() | - | ||||||||||||||||||
| 2338 | */ | - | ||||||||||||||||||
| 2339 | void QStandardItemModel::setHorizontalHeaderItem(int column, QStandardItem *item) | - | ||||||||||||||||||
| 2340 | { | - | ||||||||||||||||||
| 2341 | Q_D(QStandardItemModel); | - | ||||||||||||||||||
| 2342 | if (column < 0) | - | ||||||||||||||||||
| 2343 | return; | - | ||||||||||||||||||
| 2344 | if (columnCount() <= column) | - | ||||||||||||||||||
| 2345 | setColumnCount(column + 1); | - | ||||||||||||||||||
| 2346 | - | |||||||||||||||||||
| 2347 | QStandardItem *oldItem = d->columnHeaderItems.at(column); | - | ||||||||||||||||||
| 2348 | if (item == oldItem) | - | ||||||||||||||||||
| 2349 | return; | - | ||||||||||||||||||
| 2350 | - | |||||||||||||||||||
| 2351 | if (item) { | - | ||||||||||||||||||
| 2352 | if (item->model() == 0) { | - | ||||||||||||||||||
| 2353 | item->d_func()->setModel(this); | - | ||||||||||||||||||
| 2354 | } else { | - | ||||||||||||||||||
| 2355 | qWarning("QStandardItem::setHorizontalHeaderItem: Ignoring duplicate insertion of item %p", | - | ||||||||||||||||||
| 2356 | item); | - | ||||||||||||||||||
| 2357 | return; | - | ||||||||||||||||||
| 2358 | } | - | ||||||||||||||||||
| 2359 | } | - | ||||||||||||||||||
| 2360 | - | |||||||||||||||||||
| 2361 | if (oldItem) | - | ||||||||||||||||||
| 2362 | oldItem->d_func()->setModel(0); | - | ||||||||||||||||||
| 2363 | delete oldItem; | - | ||||||||||||||||||
| 2364 | - | |||||||||||||||||||
| 2365 | d->columnHeaderItems.replace(column, item); | - | ||||||||||||||||||
| 2366 | emit headerDataChanged(Qt::Horizontal, column, column); | - | ||||||||||||||||||
| 2367 | } | - | ||||||||||||||||||
| 2368 | - | |||||||||||||||||||
| 2369 | /*! | - | ||||||||||||||||||
| 2370 | \since 4.2 | - | ||||||||||||||||||
| 2371 | - | |||||||||||||||||||
| 2372 | Returns the horizontal header item for \a column if one has been set; | - | ||||||||||||||||||
| 2373 | otherwise returns 0. | - | ||||||||||||||||||
| 2374 | - | |||||||||||||||||||
| 2375 | \sa setHorizontalHeaderItem(), verticalHeaderItem() | - | ||||||||||||||||||
| 2376 | */ | - | ||||||||||||||||||
| 2377 | QStandardItem *QStandardItemModel::horizontalHeaderItem(int column) const | - | ||||||||||||||||||
| 2378 | { | - | ||||||||||||||||||
| 2379 | Q_D(const QStandardItemModel); | - | ||||||||||||||||||
| 2380 | if ((column < 0) || (column >= columnCount())) | - | ||||||||||||||||||
| 2381 | return 0; | - | ||||||||||||||||||
| 2382 | return d->columnHeaderItems.at(column); | - | ||||||||||||||||||
| 2383 | } | - | ||||||||||||||||||
| 2384 | - | |||||||||||||||||||
| 2385 | /*! | - | ||||||||||||||||||
| 2386 | \since 4.2 | - | ||||||||||||||||||
| 2387 | - | |||||||||||||||||||
| 2388 | Sets the vertical header item for \a row to \a item. The model takes | - | ||||||||||||||||||
| 2389 | ownership of the item. If necessary, the row count is increased to fit the | - | ||||||||||||||||||
| 2390 | item. The previous header item (if there was one) is deleted. | - | ||||||||||||||||||
| 2391 | - | |||||||||||||||||||
| 2392 | \sa verticalHeaderItem(), setVerticalHeaderLabels(), | - | ||||||||||||||||||
| 2393 | setHorizontalHeaderItem() | - | ||||||||||||||||||
| 2394 | */ | - | ||||||||||||||||||
| 2395 | void QStandardItemModel::setVerticalHeaderItem(int row, QStandardItem *item) | - | ||||||||||||||||||
| 2396 | { | - | ||||||||||||||||||
| 2397 | Q_D(QStandardItemModel); | - | ||||||||||||||||||
| 2398 | if (row < 0) | - | ||||||||||||||||||
| 2399 | return; | - | ||||||||||||||||||
| 2400 | if (rowCount() <= row) | - | ||||||||||||||||||
| 2401 | setRowCount(row + 1); | - | ||||||||||||||||||
| 2402 | - | |||||||||||||||||||
| 2403 | QStandardItem *oldItem = d->rowHeaderItems.at(row); | - | ||||||||||||||||||
| 2404 | if (item == oldItem) | - | ||||||||||||||||||
| 2405 | return; | - | ||||||||||||||||||
| 2406 | - | |||||||||||||||||||
| 2407 | if (item) { | - | ||||||||||||||||||
| 2408 | if (item->model() == 0) { | - | ||||||||||||||||||
| 2409 | item->d_func()->setModel(this); | - | ||||||||||||||||||
| 2410 | } else { | - | ||||||||||||||||||
| 2411 | qWarning("QStandardItem::setVerticalHeaderItem: Ignoring duplicate insertion of item %p", | - | ||||||||||||||||||
| 2412 | item); | - | ||||||||||||||||||
| 2413 | return; | - | ||||||||||||||||||
| 2414 | } | - | ||||||||||||||||||
| 2415 | } | - | ||||||||||||||||||
| 2416 | - | |||||||||||||||||||
| 2417 | if (oldItem) | - | ||||||||||||||||||
| 2418 | oldItem->d_func()->setModel(0); | - | ||||||||||||||||||
| 2419 | delete oldItem; | - | ||||||||||||||||||
| 2420 | - | |||||||||||||||||||
| 2421 | d->rowHeaderItems.replace(row, item); | - | ||||||||||||||||||
| 2422 | emit headerDataChanged(Qt::Vertical, row, row); | - | ||||||||||||||||||
| 2423 | } | - | ||||||||||||||||||
| 2424 | - | |||||||||||||||||||
| 2425 | /*! | - | ||||||||||||||||||
| 2426 | \since 4.2 | - | ||||||||||||||||||
| 2427 | - | |||||||||||||||||||
| 2428 | Returns the vertical header item for row \a row if one has been set; | - | ||||||||||||||||||
| 2429 | otherwise returns 0. | - | ||||||||||||||||||
| 2430 | - | |||||||||||||||||||
| 2431 | \sa setVerticalHeaderItem(), horizontalHeaderItem() | - | ||||||||||||||||||
| 2432 | */ | - | ||||||||||||||||||
| 2433 | QStandardItem *QStandardItemModel::verticalHeaderItem(int row) const | - | ||||||||||||||||||
| 2434 | { | - | ||||||||||||||||||
| 2435 | Q_D(const QStandardItemModel); | - | ||||||||||||||||||
| 2436 | if ((row < 0) || (row >= rowCount())) | - | ||||||||||||||||||
| 2437 | return 0; | - | ||||||||||||||||||
| 2438 | return d->rowHeaderItems.at(row); | - | ||||||||||||||||||
| 2439 | } | - | ||||||||||||||||||
| 2440 | - | |||||||||||||||||||
| 2441 | /*! | - | ||||||||||||||||||
| 2442 | \since 4.2 | - | ||||||||||||||||||
| 2443 | - | |||||||||||||||||||
| 2444 | Sets the horizontal header labels using \a labels. If necessary, the | - | ||||||||||||||||||
| 2445 | column count is increased to the size of \a labels. | - | ||||||||||||||||||
| 2446 | - | |||||||||||||||||||
| 2447 | \sa setHorizontalHeaderItem() | - | ||||||||||||||||||
| 2448 | */ | - | ||||||||||||||||||
| 2449 | void QStandardItemModel::setHorizontalHeaderLabels(const QStringList &labels) | - | ||||||||||||||||||
| 2450 | { | - | ||||||||||||||||||
| 2451 | Q_D(QStandardItemModel); | - | ||||||||||||||||||
| 2452 | if (columnCount() < labels.count()) | - | ||||||||||||||||||
| 2453 | setColumnCount(labels.count()); | - | ||||||||||||||||||
| 2454 | for (int i = 0; i < labels.count(); ++i) { | - | ||||||||||||||||||
| 2455 | QStandardItem *item = horizontalHeaderItem(i); | - | ||||||||||||||||||
| 2456 | if (!item) { | - | ||||||||||||||||||
| 2457 | item = d->createItem(); | - | ||||||||||||||||||
| 2458 | setHorizontalHeaderItem(i, item); | - | ||||||||||||||||||
| 2459 | } | - | ||||||||||||||||||
| 2460 | item->setText(labels.at(i)); | - | ||||||||||||||||||
| 2461 | } | - | ||||||||||||||||||
| 2462 | } | - | ||||||||||||||||||
| 2463 | - | |||||||||||||||||||
| 2464 | /*! | - | ||||||||||||||||||
| 2465 | \since 4.2 | - | ||||||||||||||||||
| 2466 | - | |||||||||||||||||||
| 2467 | Sets the vertical header labels using \a labels. If necessary, the row | - | ||||||||||||||||||
| 2468 | count is increased to the size of \a labels. | - | ||||||||||||||||||
| 2469 | - | |||||||||||||||||||
| 2470 | \sa setVerticalHeaderItem() | - | ||||||||||||||||||
| 2471 | */ | - | ||||||||||||||||||
| 2472 | void QStandardItemModel::setVerticalHeaderLabels(const QStringList &labels) | - | ||||||||||||||||||
| 2473 | { | - | ||||||||||||||||||
| 2474 | Q_D(QStandardItemModel); | - | ||||||||||||||||||
| 2475 | if (rowCount() < labels.count()) | - | ||||||||||||||||||
| 2476 | setRowCount(labels.count()); | - | ||||||||||||||||||
| 2477 | for (int i = 0; i < labels.count(); ++i) { | - | ||||||||||||||||||
| 2478 | QStandardItem *item = verticalHeaderItem(i); | - | ||||||||||||||||||
| 2479 | if (!item) { | - | ||||||||||||||||||
| 2480 | item = d->createItem(); | - | ||||||||||||||||||
| 2481 | setVerticalHeaderItem(i, item); | - | ||||||||||||||||||
| 2482 | } | - | ||||||||||||||||||
| 2483 | item->setText(labels.at(i)); | - | ||||||||||||||||||
| 2484 | } | - | ||||||||||||||||||
| 2485 | } | - | ||||||||||||||||||
| 2486 | - | |||||||||||||||||||
| 2487 | /*! | - | ||||||||||||||||||
| 2488 | \since 4.2 | - | ||||||||||||||||||
| 2489 | - | |||||||||||||||||||
| 2490 | Sets the item prototype for the model to the specified \a item. The model | - | ||||||||||||||||||
| 2491 | takes ownership of the prototype. | - | ||||||||||||||||||
| 2492 | - | |||||||||||||||||||
| 2493 | The item prototype acts as a QStandardItem factory, by relying on the | - | ||||||||||||||||||
| 2494 | QStandardItem::clone() function. To provide your own prototype, subclass | - | ||||||||||||||||||
| 2495 | QStandardItem, reimplement QStandardItem::clone() and set the prototype to | - | ||||||||||||||||||
| 2496 | be an instance of your custom class. Whenever QStandardItemModel needs to | - | ||||||||||||||||||
| 2497 | create an item on demand (for instance, when a view or item delegate calls | - | ||||||||||||||||||
| 2498 | setData())), the new items will be instances of your custom class. | - | ||||||||||||||||||
| 2499 | - | |||||||||||||||||||
| 2500 | \sa itemPrototype(), QStandardItem::clone() | - | ||||||||||||||||||
| 2501 | */ | - | ||||||||||||||||||
| 2502 | void QStandardItemModel::setItemPrototype(const QStandardItem *item) | - | ||||||||||||||||||
| 2503 | { | - | ||||||||||||||||||
| 2504 | Q_D(QStandardItemModel); | - | ||||||||||||||||||
| 2505 | if (d->itemPrototype != item) { | - | ||||||||||||||||||
| 2506 | delete d->itemPrototype; | - | ||||||||||||||||||
| 2507 | d->itemPrototype = item; | - | ||||||||||||||||||
| 2508 | } | - | ||||||||||||||||||
| 2509 | } | - | ||||||||||||||||||
| 2510 | - | |||||||||||||||||||
| 2511 | /*! | - | ||||||||||||||||||
| 2512 | \since 4.2 | - | ||||||||||||||||||
| 2513 | - | |||||||||||||||||||
| 2514 | Returns the item prototype used by the model. The model uses the item | - | ||||||||||||||||||
| 2515 | prototype as an item factory when it needs to construct new items on | - | ||||||||||||||||||
| 2516 | demand (for instance, when a view or item delegate calls setData()). | - | ||||||||||||||||||
| 2517 | - | |||||||||||||||||||
| 2518 | \sa setItemPrototype() | - | ||||||||||||||||||
| 2519 | */ | - | ||||||||||||||||||
| 2520 | const QStandardItem *QStandardItemModel::itemPrototype() const | - | ||||||||||||||||||
| 2521 | { | - | ||||||||||||||||||
| 2522 | Q_D(const QStandardItemModel); | - | ||||||||||||||||||
| 2523 | return d->itemPrototype; | - | ||||||||||||||||||
| 2524 | } | - | ||||||||||||||||||
| 2525 | - | |||||||||||||||||||
| 2526 | /*! | - | ||||||||||||||||||
| 2527 | \since 4.2 | - | ||||||||||||||||||
| 2528 | - | |||||||||||||||||||
| 2529 | Returns a list of items that match the given \a text, using the given \a | - | ||||||||||||||||||
| 2530 | flags, in the given \a column. | - | ||||||||||||||||||
| 2531 | */ | - | ||||||||||||||||||
| 2532 | QList<QStandardItem*> QStandardItemModel::findItems(const QString &text, | - | ||||||||||||||||||
| 2533 | Qt::MatchFlags flags, int column) const | - | ||||||||||||||||||
| 2534 | { | - | ||||||||||||||||||
| 2535 | QModelIndexList indexes = match(index(0, column, QModelIndex()), | - | ||||||||||||||||||
| 2536 | Qt::DisplayRole, text, -1, flags); | - | ||||||||||||||||||
| 2537 | QList<QStandardItem*> items; | - | ||||||||||||||||||
| 2538 | const int numIndexes = indexes.size(); | - | ||||||||||||||||||
| 2539 | items.reserve(numIndexes); | - | ||||||||||||||||||
| 2540 | for (int i = 0; i < numIndexes; ++i) | - | ||||||||||||||||||
| 2541 | items.append(itemFromIndex(indexes.at(i))); | - | ||||||||||||||||||
| 2542 | return items; | - | ||||||||||||||||||
| 2543 | } | - | ||||||||||||||||||
| 2544 | - | |||||||||||||||||||
| 2545 | /*! | - | ||||||||||||||||||
| 2546 | \since 4.2 | - | ||||||||||||||||||
| 2547 | - | |||||||||||||||||||
| 2548 | Appends a row containing \a items. If necessary, the column count is | - | ||||||||||||||||||
| 2549 | increased to the size of \a items. | - | ||||||||||||||||||
| 2550 | - | |||||||||||||||||||
| 2551 | \sa insertRow(), appendColumn() | - | ||||||||||||||||||
| 2552 | */ | - | ||||||||||||||||||
| 2553 | void QStandardItemModel::appendRow(const QList<QStandardItem*> &items) | - | ||||||||||||||||||
| 2554 | { | - | ||||||||||||||||||
| 2555 | invisibleRootItem()->appendRow(items); | - | ||||||||||||||||||
| 2556 | } | - | ||||||||||||||||||
| 2557 | - | |||||||||||||||||||
| 2558 | /*! | - | ||||||||||||||||||
| 2559 | \since 4.2 | - | ||||||||||||||||||
| 2560 | - | |||||||||||||||||||
| 2561 | Appends a column containing \a items. If necessary, the row count is | - | ||||||||||||||||||
| 2562 | increased to the size of \a items. | - | ||||||||||||||||||
| 2563 | - | |||||||||||||||||||
| 2564 | \sa insertColumn(), appendRow() | - | ||||||||||||||||||
| 2565 | */ | - | ||||||||||||||||||
| 2566 | void QStandardItemModel::appendColumn(const QList<QStandardItem*> &items) | - | ||||||||||||||||||
| 2567 | { | - | ||||||||||||||||||
| 2568 | invisibleRootItem()->appendColumn(items); | - | ||||||||||||||||||
| 2569 | } | - | ||||||||||||||||||
| 2570 | - | |||||||||||||||||||
| 2571 | /*! | - | ||||||||||||||||||
| 2572 | \since 4.2 | - | ||||||||||||||||||
| 2573 | \fn QStandardItemModel::appendRow(QStandardItem *item) | - | ||||||||||||||||||
| 2574 | \overload | - | ||||||||||||||||||
| 2575 | - | |||||||||||||||||||
| 2576 | When building a list or a tree that has only one column, this function | - | ||||||||||||||||||
| 2577 | provides a convenient way to append a single new \a item. | - | ||||||||||||||||||
| 2578 | */ | - | ||||||||||||||||||
| 2579 | - | |||||||||||||||||||
| 2580 | /*! | - | ||||||||||||||||||
| 2581 | \since 4.2 | - | ||||||||||||||||||
| 2582 | - | |||||||||||||||||||
| 2583 | Inserts a row at \a row containing \a items. If necessary, the column | - | ||||||||||||||||||
| 2584 | count is increased to the size of \a items. | - | ||||||||||||||||||
| 2585 | - | |||||||||||||||||||
| 2586 | \sa takeRow(), appendRow(), insertColumn() | - | ||||||||||||||||||
| 2587 | */ | - | ||||||||||||||||||
| 2588 | void QStandardItemModel::insertRow(int row, const QList<QStandardItem*> &items) | - | ||||||||||||||||||
| 2589 | { | - | ||||||||||||||||||
| 2590 | invisibleRootItem()->insertRow(row, items); | - | ||||||||||||||||||
| 2591 | } | - | ||||||||||||||||||
| 2592 | - | |||||||||||||||||||
| 2593 | /*! | - | ||||||||||||||||||
| 2594 | \since 4.2 | - | ||||||||||||||||||
| 2595 | - | |||||||||||||||||||
| 2596 | \fn void QStandardItemModel::insertRow(int row, QStandardItem *item) | - | ||||||||||||||||||
| 2597 | \overload | - | ||||||||||||||||||
| 2598 | - | |||||||||||||||||||
| 2599 | Inserts a row at \a row containing \a item. | - | ||||||||||||||||||
| 2600 | - | |||||||||||||||||||
| 2601 | When building a list or a tree that has only one column, this function | - | ||||||||||||||||||
| 2602 | provides a convenient way to append a single new item. | - | ||||||||||||||||||
| 2603 | */ | - | ||||||||||||||||||
| 2604 | - | |||||||||||||||||||
| 2605 | /*! | - | ||||||||||||||||||
| 2606 | \since 4.2 | - | ||||||||||||||||||
| 2607 | - | |||||||||||||||||||
| 2608 | Inserts a column at \a column containing \a items. If necessary, the row | - | ||||||||||||||||||
| 2609 | count is increased to the size of \a items. | - | ||||||||||||||||||
| 2610 | - | |||||||||||||||||||
| 2611 | \sa takeColumn(), appendColumn(), insertRow() | - | ||||||||||||||||||
| 2612 | */ | - | ||||||||||||||||||
| 2613 | void QStandardItemModel::insertColumn(int column, const QList<QStandardItem*> &items) | - | ||||||||||||||||||
| 2614 | { | - | ||||||||||||||||||
| 2615 | invisibleRootItem()->insertColumn(column, items); | - | ||||||||||||||||||
| 2616 | } | - | ||||||||||||||||||
| 2617 | - | |||||||||||||||||||
| 2618 | /*! | - | ||||||||||||||||||
| 2619 | \since 4.2 | - | ||||||||||||||||||
| 2620 | - | |||||||||||||||||||
| 2621 | Removes the item at (\a row, \a column) without deleting it. The model | - | ||||||||||||||||||
| 2622 | releases ownership of the item. | - | ||||||||||||||||||
| 2623 | - | |||||||||||||||||||
| 2624 | \sa item(), takeRow(), takeColumn() | - | ||||||||||||||||||
| 2625 | */ | - | ||||||||||||||||||
| 2626 | QStandardItem *QStandardItemModel::takeItem(int row, int column) | - | ||||||||||||||||||
| 2627 | { | - | ||||||||||||||||||
| 2628 | Q_D(QStandardItemModel); | - | ||||||||||||||||||
| 2629 | return d->root->takeChild(row, column); | - | ||||||||||||||||||
| 2630 | } | - | ||||||||||||||||||
| 2631 | - | |||||||||||||||||||
| 2632 | /*! | - | ||||||||||||||||||
| 2633 | \since 4.2 | - | ||||||||||||||||||
| 2634 | - | |||||||||||||||||||
| 2635 | Removes the given \a row without deleting the row items, and returns a | - | ||||||||||||||||||
| 2636 | list of pointers to the removed items. The model releases ownership of the | - | ||||||||||||||||||
| 2637 | items. For items in the row that have not been set, the corresponding | - | ||||||||||||||||||
| 2638 | pointers in the list will be 0. | - | ||||||||||||||||||
| 2639 | - | |||||||||||||||||||
| 2640 | \sa takeColumn() | - | ||||||||||||||||||
| 2641 | */ | - | ||||||||||||||||||
| 2642 | QList<QStandardItem*> QStandardItemModel::takeRow(int row) | - | ||||||||||||||||||
| 2643 | { | - | ||||||||||||||||||
| 2644 | Q_D(QStandardItemModel); | - | ||||||||||||||||||
| 2645 | return d->root->takeRow(row); | - | ||||||||||||||||||
| 2646 | } | - | ||||||||||||||||||
| 2647 | - | |||||||||||||||||||
| 2648 | /*! | - | ||||||||||||||||||
| 2649 | \since 4.2 | - | ||||||||||||||||||
| 2650 | - | |||||||||||||||||||
| 2651 | Removes the given \a column without deleting the column items, and returns | - | ||||||||||||||||||
| 2652 | a list of pointers to the removed items. The model releases ownership of | - | ||||||||||||||||||
| 2653 | the items. For items in the column that have not been set, the | - | ||||||||||||||||||
| 2654 | corresponding pointers in the list will be 0. | - | ||||||||||||||||||
| 2655 | - | |||||||||||||||||||
| 2656 | \sa takeRow() | - | ||||||||||||||||||
| 2657 | */ | - | ||||||||||||||||||
| 2658 | QList<QStandardItem*> QStandardItemModel::takeColumn(int column) | - | ||||||||||||||||||
| 2659 | { | - | ||||||||||||||||||
| 2660 | Q_D(QStandardItemModel); | - | ||||||||||||||||||
| 2661 | return d->root->takeColumn(column); | - | ||||||||||||||||||
| 2662 | } | - | ||||||||||||||||||
| 2663 | - | |||||||||||||||||||
| 2664 | /*! | - | ||||||||||||||||||
| 2665 | \since 4.2 | - | ||||||||||||||||||
| 2666 | - | |||||||||||||||||||
| 2667 | Removes the horizontal header item at \a column from the header without | - | ||||||||||||||||||
| 2668 | deleting it, and returns a pointer to the item. The model releases | - | ||||||||||||||||||
| 2669 | ownership of the item. | - | ||||||||||||||||||
| 2670 | - | |||||||||||||||||||
| 2671 | \sa horizontalHeaderItem(), takeVerticalHeaderItem() | - | ||||||||||||||||||
| 2672 | */ | - | ||||||||||||||||||
| 2673 | QStandardItem *QStandardItemModel::takeHorizontalHeaderItem(int column) | - | ||||||||||||||||||
| 2674 | { | - | ||||||||||||||||||
| 2675 | Q_D(QStandardItemModel); | - | ||||||||||||||||||
| 2676 | if ((column < 0) || (column >= columnCount())) | - | ||||||||||||||||||
| 2677 | return 0; | - | ||||||||||||||||||
| 2678 | QStandardItem *headerItem = d->columnHeaderItems.at(column); | - | ||||||||||||||||||
| 2679 | if (headerItem) { | - | ||||||||||||||||||
| 2680 | headerItem->d_func()->setParentAndModel(0, 0); | - | ||||||||||||||||||
| 2681 | d->columnHeaderItems.replace(column, 0); | - | ||||||||||||||||||
| 2682 | } | - | ||||||||||||||||||
| 2683 | return headerItem; | - | ||||||||||||||||||
| 2684 | } | - | ||||||||||||||||||
| 2685 | - | |||||||||||||||||||
| 2686 | /*! | - | ||||||||||||||||||
| 2687 | \since 4.2 | - | ||||||||||||||||||
| 2688 | - | |||||||||||||||||||
| 2689 | Removes the vertical header item at \a row from the header without | - | ||||||||||||||||||
| 2690 | deleting it, and returns a pointer to the item. The model releases | - | ||||||||||||||||||
| 2691 | ownership of the item. | - | ||||||||||||||||||
| 2692 | - | |||||||||||||||||||
| 2693 | \sa verticalHeaderItem(), takeHorizontalHeaderItem() | - | ||||||||||||||||||
| 2694 | */ | - | ||||||||||||||||||
| 2695 | QStandardItem *QStandardItemModel::takeVerticalHeaderItem(int row) | - | ||||||||||||||||||
| 2696 | { | - | ||||||||||||||||||
| 2697 | Q_D(QStandardItemModel); | - | ||||||||||||||||||
| 2698 | if ((row < 0) || (row >= rowCount())) | - | ||||||||||||||||||
| 2699 | return 0; | - | ||||||||||||||||||
| 2700 | QStandardItem *headerItem = d->rowHeaderItems.at(row); | - | ||||||||||||||||||
| 2701 | if (headerItem) { | - | ||||||||||||||||||
| 2702 | headerItem->d_func()->setParentAndModel(0, 0); | - | ||||||||||||||||||
| 2703 | d->rowHeaderItems.replace(row, 0); | - | ||||||||||||||||||
| 2704 | } | - | ||||||||||||||||||
| 2705 | return headerItem; | - | ||||||||||||||||||
| 2706 | } | - | ||||||||||||||||||
| 2707 | - | |||||||||||||||||||
| 2708 | /*! | - | ||||||||||||||||||
| 2709 | \since 4.2 | - | ||||||||||||||||||
| 2710 | \property QStandardItemModel::sortRole | - | ||||||||||||||||||
| 2711 | \brief the item role that is used to query the model's data when sorting items | - | ||||||||||||||||||
| 2712 | - | |||||||||||||||||||
| 2713 | The default value is Qt::DisplayRole. | - | ||||||||||||||||||
| 2714 | - | |||||||||||||||||||
| 2715 | \sa sort(), QStandardItem::sortChildren() | - | ||||||||||||||||||
| 2716 | */ | - | ||||||||||||||||||
| 2717 | int QStandardItemModel::sortRole() const | - | ||||||||||||||||||
| 2718 | { | - | ||||||||||||||||||
| 2719 | Q_D(const QStandardItemModel); | - | ||||||||||||||||||
| 2720 | return d->sortRole; | - | ||||||||||||||||||
| 2721 | } | - | ||||||||||||||||||
| 2722 | - | |||||||||||||||||||
| 2723 | void QStandardItemModel::setSortRole(int role) | - | ||||||||||||||||||
| 2724 | { | - | ||||||||||||||||||
| 2725 | Q_D(QStandardItemModel); | - | ||||||||||||||||||
| 2726 | d->sortRole = role; | - | ||||||||||||||||||
| 2727 | } | - | ||||||||||||||||||
| 2728 | - | |||||||||||||||||||
| 2729 | /*! | - | ||||||||||||||||||
| 2730 | \reimp | - | ||||||||||||||||||
| 2731 | */ | - | ||||||||||||||||||
| 2732 | int QStandardItemModel::columnCount(const QModelIndex &parent) const | - | ||||||||||||||||||
| 2733 | { | - | ||||||||||||||||||
| 2734 | Q_D(const QStandardItemModel); | - | ||||||||||||||||||
| 2735 | QStandardItem *item = d->itemFromIndex(parent); | - | ||||||||||||||||||
| 2736 | return item ? item->columnCount() : 0; | - | ||||||||||||||||||
| 2737 | } | - | ||||||||||||||||||
| 2738 | - | |||||||||||||||||||
| 2739 | /*! | - | ||||||||||||||||||
| 2740 | \reimp | - | ||||||||||||||||||
| 2741 | */ | - | ||||||||||||||||||
| 2742 | QVariant QStandardItemModel::data(const QModelIndex &index, int role) const | - | ||||||||||||||||||
| 2743 | { | - | ||||||||||||||||||
| 2744 | Q_D(const QStandardItemModel); | - | ||||||||||||||||||
| 2745 | QStandardItem *item = d->itemFromIndex(index); | - | ||||||||||||||||||
| 2746 | return item ? item->data(role) : QVariant(); | - | ||||||||||||||||||
| 2747 | } | - | ||||||||||||||||||
| 2748 | - | |||||||||||||||||||
| 2749 | /*! | - | ||||||||||||||||||
| 2750 | \reimp | - | ||||||||||||||||||
| 2751 | */ | - | ||||||||||||||||||
| 2752 | Qt::ItemFlags QStandardItemModel::flags(const QModelIndex &index) const | - | ||||||||||||||||||
| 2753 | { | - | ||||||||||||||||||
| 2754 | Q_D(const QStandardItemModel); | - | ||||||||||||||||||
| 2755 | if (!d->indexValid(index)) | - | ||||||||||||||||||
| 2756 | return d->root->flags(); | - | ||||||||||||||||||
| 2757 | QStandardItem *item = d->itemFromIndex(index); | - | ||||||||||||||||||
| 2758 | if (item) | - | ||||||||||||||||||
| 2759 | return item->flags(); | - | ||||||||||||||||||
| 2760 | return Qt::ItemIsSelectable | - | ||||||||||||||||||
| 2761 | |Qt::ItemIsEnabled | - | ||||||||||||||||||
| 2762 | |Qt::ItemIsEditable | - | ||||||||||||||||||
| 2763 | |Qt::ItemIsDragEnabled | - | ||||||||||||||||||
| 2764 | |Qt::ItemIsDropEnabled; | - | ||||||||||||||||||
| 2765 | } | - | ||||||||||||||||||
| 2766 | - | |||||||||||||||||||
| 2767 | /*! | - | ||||||||||||||||||
| 2768 | \reimp | - | ||||||||||||||||||
| 2769 | */ | - | ||||||||||||||||||
| 2770 | bool QStandardItemModel::hasChildren(const QModelIndex &parent) const | - | ||||||||||||||||||
| 2771 | { | - | ||||||||||||||||||
| 2772 | Q_D(const QStandardItemModel); | - | ||||||||||||||||||
| 2773 | QStandardItem *item = d->itemFromIndex(parent); | - | ||||||||||||||||||
| 2774 | return item ? item->hasChildren() : false; | - | ||||||||||||||||||
| 2775 | } | - | ||||||||||||||||||
| 2776 | - | |||||||||||||||||||
| 2777 | /*! | - | ||||||||||||||||||
| 2778 | \reimp | - | ||||||||||||||||||
| 2779 | */ | - | ||||||||||||||||||
| 2780 | QModelIndex QStandardItemModel::sibling(int row, int column, const QModelIndex &idx) const | - | ||||||||||||||||||
| 2781 | { | - | ||||||||||||||||||
| 2782 | return QAbstractItemModel::sibling(row, column, idx); | - | ||||||||||||||||||
| 2783 | } | - | ||||||||||||||||||
| 2784 | - | |||||||||||||||||||
| 2785 | /*! | - | ||||||||||||||||||
| 2786 | \reimp | - | ||||||||||||||||||
| 2787 | */ | - | ||||||||||||||||||
| 2788 | QVariant QStandardItemModel::headerData(int section, Qt::Orientation orientation, int role) const | - | ||||||||||||||||||
| 2789 | { | - | ||||||||||||||||||
| 2790 | Q_D(const QStandardItemModel); | - | ||||||||||||||||||
| 2791 | if ((section < 0) | - | ||||||||||||||||||
| 2792 | || ((orientation == Qt::Horizontal) && (section >= columnCount())) | - | ||||||||||||||||||
| 2793 | || ((orientation == Qt::Vertical) && (section >= rowCount()))) { | - | ||||||||||||||||||
| 2794 | return QVariant(); | - | ||||||||||||||||||
| 2795 | } | - | ||||||||||||||||||
| 2796 | QStandardItem *headerItem = 0; | - | ||||||||||||||||||
| 2797 | if (orientation == Qt::Horizontal) | - | ||||||||||||||||||
| 2798 | headerItem = d->columnHeaderItems.at(section); | - | ||||||||||||||||||
| 2799 | else if (orientation == Qt::Vertical) | - | ||||||||||||||||||
| 2800 | headerItem = d->rowHeaderItems.at(section); | - | ||||||||||||||||||
| 2801 | return headerItem ? headerItem->data(role) | - | ||||||||||||||||||
| 2802 | : QAbstractItemModel::headerData(section, orientation, role); | - | ||||||||||||||||||
| 2803 | } | - | ||||||||||||||||||
| 2804 | - | |||||||||||||||||||
| 2805 | /*! | - | ||||||||||||||||||
| 2806 | \reimp | - | ||||||||||||||||||
| 2807 | - | |||||||||||||||||||
| 2808 | QStandardItemModel supports both copy and move. | - | ||||||||||||||||||
| 2809 | */ | - | ||||||||||||||||||
| 2810 | Qt::DropActions QStandardItemModel::supportedDropActions () const | - | ||||||||||||||||||
| 2811 | { | - | ||||||||||||||||||
| 2812 | return Qt::CopyAction | Qt::MoveAction; | - | ||||||||||||||||||
| 2813 | } | - | ||||||||||||||||||
| 2814 | - | |||||||||||||||||||
| 2815 | /*! | - | ||||||||||||||||||
| 2816 | \reimp | - | ||||||||||||||||||
| 2817 | */ | - | ||||||||||||||||||
| 2818 | QModelIndex QStandardItemModel::index(int row, int column, const QModelIndex &parent) const | - | ||||||||||||||||||
| 2819 | { | - | ||||||||||||||||||
| 2820 | Q_D(const QStandardItemModel); | - | ||||||||||||||||||
| 2821 | QStandardItem *parentItem = d->itemFromIndex(parent); | - | ||||||||||||||||||
| 2822 | if ((parentItem == 0) | - | ||||||||||||||||||
| 2823 | || (row < 0) | - | ||||||||||||||||||
| 2824 | || (column < 0) | - | ||||||||||||||||||
| 2825 | || (row >= parentItem->rowCount()) | - | ||||||||||||||||||
| 2826 | || (column >= parentItem->columnCount())) { | - | ||||||||||||||||||
| 2827 | return QModelIndex(); | - | ||||||||||||||||||
| 2828 | } | - | ||||||||||||||||||
| 2829 | return createIndex(row, column, parentItem); | - | ||||||||||||||||||
| 2830 | } | - | ||||||||||||||||||
| 2831 | - | |||||||||||||||||||
| 2832 | /*! | - | ||||||||||||||||||
| 2833 | \reimp | - | ||||||||||||||||||
| 2834 | */ | - | ||||||||||||||||||
| 2835 | bool QStandardItemModel::insertColumns(int column, int count, const QModelIndex &parent) | - | ||||||||||||||||||
| 2836 | { | - | ||||||||||||||||||
| 2837 | Q_D(QStandardItemModel); | - | ||||||||||||||||||
| 2838 | QStandardItem *item = parent.isValid() ? itemFromIndex(parent) : d->root.data(); | - | ||||||||||||||||||
| 2839 | if (item == 0) | - | ||||||||||||||||||
| 2840 | return false; | - | ||||||||||||||||||
| 2841 | return item->d_func()->insertColumns(column, count, QList<QStandardItem*>()); | - | ||||||||||||||||||
| 2842 | } | - | ||||||||||||||||||
| 2843 | - | |||||||||||||||||||
| 2844 | /*! | - | ||||||||||||||||||
| 2845 | \reimp | - | ||||||||||||||||||
| 2846 | */ | - | ||||||||||||||||||
| 2847 | bool QStandardItemModel::insertRows(int row, int count, const QModelIndex &parent) | - | ||||||||||||||||||
| 2848 | { | - | ||||||||||||||||||
| 2849 | Q_D(QStandardItemModel); | - | ||||||||||||||||||
| 2850 | QStandardItem *item = parent.isValid() ? itemFromIndex(parent) : d->root.data(); | - | ||||||||||||||||||
| 2851 | if (item == 0) | - | ||||||||||||||||||
| 2852 | return false; | - | ||||||||||||||||||
| 2853 | return item->d_func()->insertRows(row, count, QList<QStandardItem*>()); | - | ||||||||||||||||||
| 2854 | } | - | ||||||||||||||||||
| 2855 | - | |||||||||||||||||||
| 2856 | /*! | - | ||||||||||||||||||
| 2857 | \reimp | - | ||||||||||||||||||
| 2858 | */ | - | ||||||||||||||||||
| 2859 | QMap<int, QVariant> QStandardItemModel::itemData(const QModelIndex &index) const | - | ||||||||||||||||||
| 2860 | { | - | ||||||||||||||||||
| 2861 | Q_D(const QStandardItemModel); | - | ||||||||||||||||||
| 2862 | QStandardItem *item = d->itemFromIndex(index); | - | ||||||||||||||||||
| 2863 | return item ? item->d_func()->itemData() : QMap<int, QVariant>(); | - | ||||||||||||||||||
| 2864 | } | - | ||||||||||||||||||
| 2865 | - | |||||||||||||||||||
| 2866 | /*! | - | ||||||||||||||||||
| 2867 | \reimp | - | ||||||||||||||||||
| 2868 | */ | - | ||||||||||||||||||
| 2869 | QModelIndex QStandardItemModel::parent(const QModelIndex &child) const | - | ||||||||||||||||||
| 2870 | { | - | ||||||||||||||||||
| 2871 | Q_D(const QStandardItemModel); | - | ||||||||||||||||||
| 2872 | if (!d->indexValid(child)) | - | ||||||||||||||||||
| 2873 | return QModelIndex(); | - | ||||||||||||||||||
| 2874 | QStandardItem *parentItem = static_cast<QStandardItem*>(child.internalPointer()); | - | ||||||||||||||||||
| 2875 | return indexFromItem(parentItem); | - | ||||||||||||||||||
| 2876 | } | - | ||||||||||||||||||
| 2877 | - | |||||||||||||||||||
| 2878 | /*! | - | ||||||||||||||||||
| 2879 | \reimp | - | ||||||||||||||||||
| 2880 | */ | - | ||||||||||||||||||
| 2881 | bool QStandardItemModel::removeColumns(int column, int count, const QModelIndex &parent) | - | ||||||||||||||||||
| 2882 | { | - | ||||||||||||||||||
| 2883 | Q_D(QStandardItemModel); | - | ||||||||||||||||||
| 2884 | QStandardItem *item = d->itemFromIndex(parent); | - | ||||||||||||||||||
| 2885 | if ((item == 0) || (count < 1) || (column < 0) || ((column + count) > item->columnCount())) | - | ||||||||||||||||||
| 2886 | return false; | - | ||||||||||||||||||
| 2887 | item->removeColumns(column, count); | - | ||||||||||||||||||
| 2888 | return true; | - | ||||||||||||||||||
| 2889 | } | - | ||||||||||||||||||
| 2890 | - | |||||||||||||||||||
| 2891 | /*! | - | ||||||||||||||||||
| 2892 | \reimp | - | ||||||||||||||||||
| 2893 | */ | - | ||||||||||||||||||
| 2894 | bool QStandardItemModel::removeRows(int row, int count, const QModelIndex &parent) | - | ||||||||||||||||||
| 2895 | { | - | ||||||||||||||||||
| 2896 | Q_D(QStandardItemModel); | - | ||||||||||||||||||
| 2897 | QStandardItem *item = d->itemFromIndex(parent); | - | ||||||||||||||||||
| 2898 | if ((item == 0) || (count < 1) || (row < 0) || ((row + count) > item->rowCount())) | - | ||||||||||||||||||
| 2899 | return false; | - | ||||||||||||||||||
| 2900 | item->removeRows(row, count); | - | ||||||||||||||||||
| 2901 | return true; | - | ||||||||||||||||||
| 2902 | } | - | ||||||||||||||||||
| 2903 | - | |||||||||||||||||||
| 2904 | /*! | - | ||||||||||||||||||
| 2905 | \reimp | - | ||||||||||||||||||
| 2906 | */ | - | ||||||||||||||||||
| 2907 | int QStandardItemModel::rowCount(const QModelIndex &parent) const | - | ||||||||||||||||||
| 2908 | { | - | ||||||||||||||||||
| 2909 | Q_D(const QStandardItemModel); | - | ||||||||||||||||||
| 2910 | QStandardItem *item = d->itemFromIndex(parent); | - | ||||||||||||||||||
| 2911 | return item ? item->rowCount() : 0; | - | ||||||||||||||||||
| 2912 | } | - | ||||||||||||||||||
| 2913 | - | |||||||||||||||||||
| 2914 | /*! | - | ||||||||||||||||||
| 2915 | \reimp | - | ||||||||||||||||||
| 2916 | */ | - | ||||||||||||||||||
| 2917 | bool QStandardItemModel::setData(const QModelIndex &index, const QVariant &value, int role) | - | ||||||||||||||||||
| 2918 | { | - | ||||||||||||||||||
| 2919 | if (!index.isValid()) | - | ||||||||||||||||||
| 2920 | return false; | - | ||||||||||||||||||
| 2921 | QStandardItem *item = itemFromIndex(index); | - | ||||||||||||||||||
| 2922 | if (item == 0) | - | ||||||||||||||||||
| 2923 | return false; | - | ||||||||||||||||||
| 2924 | item->setData(value, role); | - | ||||||||||||||||||
| 2925 | return true; | - | ||||||||||||||||||
| 2926 | } | - | ||||||||||||||||||
| 2927 | - | |||||||||||||||||||
| 2928 | /*! | - | ||||||||||||||||||
| 2929 | \reimp | - | ||||||||||||||||||
| 2930 | */ | - | ||||||||||||||||||
| 2931 | bool QStandardItemModel::setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role) | - | ||||||||||||||||||
| 2932 | { | - | ||||||||||||||||||
| 2933 | Q_D(QStandardItemModel); | - | ||||||||||||||||||
| 2934 | if ((section < 0) | - | ||||||||||||||||||
| 2935 | || ((orientation == Qt::Horizontal) && (section >= columnCount())) | - | ||||||||||||||||||
| 2936 | || ((orientation == Qt::Vertical) && (section >= rowCount()))) { | - | ||||||||||||||||||
| 2937 | return false; | - | ||||||||||||||||||
| 2938 | } | - | ||||||||||||||||||
| 2939 | QStandardItem *headerItem = 0; | - | ||||||||||||||||||
| 2940 | if (orientation == Qt::Horizontal) { | - | ||||||||||||||||||
| 2941 | headerItem = d->columnHeaderItems.at(section); | - | ||||||||||||||||||
| 2942 | if (headerItem == 0) { | - | ||||||||||||||||||
| 2943 | headerItem = d->createItem(); | - | ||||||||||||||||||
| 2944 | headerItem->d_func()->setModel(this); | - | ||||||||||||||||||
| 2945 | d->columnHeaderItems.replace(section, headerItem); | - | ||||||||||||||||||
| 2946 | } | - | ||||||||||||||||||
| 2947 | } else if (orientation == Qt::Vertical) { | - | ||||||||||||||||||
| 2948 | headerItem = d->rowHeaderItems.at(section); | - | ||||||||||||||||||
| 2949 | if (headerItem == 0) { | - | ||||||||||||||||||
| 2950 | headerItem = d->createItem(); | - | ||||||||||||||||||
| 2951 | headerItem->d_func()->setModel(this); | - | ||||||||||||||||||
| 2952 | d->rowHeaderItems.replace(section, headerItem); | - | ||||||||||||||||||
| 2953 | } | - | ||||||||||||||||||
| 2954 | } | - | ||||||||||||||||||
| 2955 | if (headerItem) { | - | ||||||||||||||||||
| 2956 | headerItem->setData(value, role); | - | ||||||||||||||||||
| 2957 | return true; | - | ||||||||||||||||||
| 2958 | } | - | ||||||||||||||||||
| 2959 | return false; | - | ||||||||||||||||||
| 2960 | } | - | ||||||||||||||||||
| 2961 | - | |||||||||||||||||||
| 2962 | /*! | - | ||||||||||||||||||
| 2963 | \reimp | - | ||||||||||||||||||
| 2964 | */ | - | ||||||||||||||||||
| 2965 | bool QStandardItemModel::setItemData(const QModelIndex &index, const QMap<int, QVariant> &roles) | - | ||||||||||||||||||
| 2966 | { | - | ||||||||||||||||||
| 2967 | QStandardItem *item = itemFromIndex(index); | - | ||||||||||||||||||
| 2968 | if (item == 0) | - | ||||||||||||||||||
| 2969 | return false; | - | ||||||||||||||||||
| 2970 | item->d_func()->setItemData(roles); | - | ||||||||||||||||||
| 2971 | return true; | - | ||||||||||||||||||
| 2972 | } | - | ||||||||||||||||||
| 2973 | - | |||||||||||||||||||
| 2974 | /*! | - | ||||||||||||||||||
| 2975 | \reimp | - | ||||||||||||||||||
| 2976 | */ | - | ||||||||||||||||||
| 2977 | void QStandardItemModel::sort(int column, Qt::SortOrder order) | - | ||||||||||||||||||
| 2978 | { | - | ||||||||||||||||||
| 2979 | Q_D(QStandardItemModel); | - | ||||||||||||||||||
| 2980 | d->root->sortChildren(column, order); | - | ||||||||||||||||||
| 2981 | } | - | ||||||||||||||||||
| 2982 | - | |||||||||||||||||||
| 2983 | /*! | - | ||||||||||||||||||
| 2984 | \reimp | - | ||||||||||||||||||
| 2985 | */ | - | ||||||||||||||||||
| 2986 | QStringList QStandardItemModel::mimeTypes() const | - | ||||||||||||||||||
| 2987 | { | - | ||||||||||||||||||
| 2988 | return QAbstractItemModel::mimeTypes() << QLatin1String("application/x-qstandarditemmodeldatalist");qStandardItemModelDataListMimeType(); never executed: return QAbstractItemModel::mimeTypes() << qStandardItemModelDataListMimeType(); | 0 | ||||||||||||||||||
| 2989 | } | - | ||||||||||||||||||
| 2990 | - | |||||||||||||||||||
| 2991 | /*! | - | ||||||||||||||||||
| 2992 | \reimp | - | ||||||||||||||||||
| 2993 | */ | - | ||||||||||||||||||
| 2994 | QMimeData *QStandardItemModel::mimeData(const QModelIndexList &indexes) const | - | ||||||||||||||||||
| 2995 | { | - | ||||||||||||||||||
| 2996 | QMimeData *data = QAbstractItemModel::mimeData(indexes); | - | ||||||||||||||||||
| 2997 | if(!data)
| 0 | ||||||||||||||||||
| 2998 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
| 2999 | - | |||||||||||||||||||
| 3000 | const QString format = QLatin1String("application/x-qstandarditemmodeldatalist");qStandardItemModelDataListMimeType(); | - | ||||||||||||||||||
| 3001 | if (!mimeTypes().contains(format))
| 0 | ||||||||||||||||||
| 3002 | return data; never executed: return data; | 0 | ||||||||||||||||||
| 3003 | QByteArray encoded; | - | ||||||||||||||||||
| 3004 | QDataStream stream(&encoded, QIODevice::WriteOnly); | - | ||||||||||||||||||
| 3005 | - | |||||||||||||||||||
| 3006 | QSet<QStandardItem*> itemsSet; | - | ||||||||||||||||||
| 3007 | QStack<QStandardItem*> stack; | - | ||||||||||||||||||
| 3008 | itemsSet.reserve(indexes.count()); | - | ||||||||||||||||||
| 3009 | stack.reserve(indexes.count()); | - | ||||||||||||||||||
| 3010 | for (int i = 0; i < indexes.count(); ++i) {
| 0 | ||||||||||||||||||
| 3011 | if (QStandardItem *item = itemFromIndex(indexes.at(i))) {
| 0 | ||||||||||||||||||
| 3012 | itemsSet << item; | - | ||||||||||||||||||
| 3013 | stack.push(item); | - | ||||||||||||||||||
| 3014 | } else { never executed: end of block | 0 | ||||||||||||||||||
| 3015 | qWarning() << ("QStandardItemModel::mimeData: No item associated with invalid index";); | - | ||||||||||||||||||
| 3016 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
| 3017 | } | - | ||||||||||||||||||
| 3018 | } | - | ||||||||||||||||||
| 3019 | - | |||||||||||||||||||
| 3020 | //remove duplicates childrens | - | ||||||||||||||||||
| 3021 | { | - | ||||||||||||||||||
| 3022 | QSet<QStandardItem *> seen; | - | ||||||||||||||||||
| 3023 | while (!stack.isEmpty()) {
| 0 | ||||||||||||||||||
| 3024 | QStandardItem *itm = stack.pop(); | - | ||||||||||||||||||
| 3025 | if (seen.contains(itm))
| 0 | ||||||||||||||||||
| 3026 | continue; never executed: continue; | 0 | ||||||||||||||||||
| 3027 | seen.insert(itm); | - | ||||||||||||||||||
| 3028 | - | |||||||||||||||||||
| 3029 | const QVector<QStandardItem*> &childList = itm->d_func()->children; | - | ||||||||||||||||||
| 3030 | for (int i = 0; i < childList.count(); ++i) {
| 0 | ||||||||||||||||||
| 3031 | QStandardItem *chi = childList.at(i); | - | ||||||||||||||||||
| 3032 | if (chi) {
| 0 | ||||||||||||||||||
| 3033 | QSet<QStandardItem *>::iterator it =itemsSet.find(chi); | - | ||||||||||||||||||
| iferase(it != itemsSet.end()) {itemsSet.eraseconstFind(it); | ||||||||||||||||||||
| }chi)); | ||||||||||||||||||||
| 3034 | stack.push(chi); | - | ||||||||||||||||||
| 3035 | } never executed: end of block | 0 | ||||||||||||||||||
| 3036 | } never executed: end of block | 0 | ||||||||||||||||||
| 3037 | } never executed: end of block | 0 | ||||||||||||||||||
| 3038 | } | - | ||||||||||||||||||
| 3039 | - | |||||||||||||||||||
| 3040 | stack.reserve(itemsSet.count()); | - | ||||||||||||||||||
| 3041 | foreachfor (QStandardItem *item ,: qAsConst(itemsSet) {)) | - | ||||||||||||||||||
| 3042 | stack.push(item); never executed: stack.push(item); | 0 | ||||||||||||||||||
| 3043 | - | |||||||||||||||||||
| 3044 | }//stream everything recursively | - | ||||||||||||||||||
| 3045 | while (!stack.isEmpty()) {
| 0 | ||||||||||||||||||
| 3046 | QStandardItem *item = stack.pop(); | - | ||||||||||||||||||
| 3047 | if (itemsSet.contains(item)) //if the item is selection 'top-level', stream its position
| 0 | ||||||||||||||||||
| 3048 | stream << item->row() << item->column(); never executed: stream << item->row() << item->column(); | 0 | ||||||||||||||||||
| 3049 | - | |||||||||||||||||||
| 3050 | stream << *item << item->columnCount() << item->d_ptr->children.count(); | - | ||||||||||||||||||
| 3051 | stack += item->d_ptr->children; | - | ||||||||||||||||||
| 3052 | } never executed: end of block | 0 | ||||||||||||||||||
| 3053 | - | |||||||||||||||||||
| 3054 | data->setData(format, encoded); | - | ||||||||||||||||||
| 3055 | return data; never executed: return data; | 0 | ||||||||||||||||||
| 3056 | } | - | ||||||||||||||||||
| 3057 | - | |||||||||||||||||||
| 3058 | - | |||||||||||||||||||
| 3059 | /* \internal | - | ||||||||||||||||||
| 3060 | Used by QStandardItemModel::dropMimeData | - | ||||||||||||||||||
| 3061 | stream out an item and his children | - | ||||||||||||||||||
| 3062 | */ | - | ||||||||||||||||||
| 3063 | void QStandardItemModelPrivate::decodeDataRecursive(QDataStream &stream, QStandardItem *item) | - | ||||||||||||||||||
| 3064 | { | - | ||||||||||||||||||
| 3065 | int colCount, childCount; | - | ||||||||||||||||||
| 3066 | stream >> *item; | - | ||||||||||||||||||
| 3067 | stream >> colCount >> childCount; | - | ||||||||||||||||||
| 3068 | item->setColumnCount(colCount); | - | ||||||||||||||||||
| 3069 | - | |||||||||||||||||||
| 3070 | int childPos = childCount; | - | ||||||||||||||||||
| 3071 | - | |||||||||||||||||||
| 3072 | while(childPos > 0) { | - | ||||||||||||||||||
| 3073 | childPos--; | - | ||||||||||||||||||
| 3074 | QStandardItem *child = createItem(); | - | ||||||||||||||||||
| 3075 | decodeDataRecursive(stream, child); | - | ||||||||||||||||||
| 3076 | item->setChild( childPos / colCount, childPos % colCount, child); | - | ||||||||||||||||||
| 3077 | } | - | ||||||||||||||||||
| 3078 | } | - | ||||||||||||||||||
| 3079 | - | |||||||||||||||||||
| 3080 | - | |||||||||||||||||||
| 3081 | /*! | - | ||||||||||||||||||
| 3082 | \reimp | - | ||||||||||||||||||
| 3083 | */ | - | ||||||||||||||||||
| 3084 | bool QStandardItemModel::dropMimeData(const QMimeData *data, Qt::DropAction action, | - | ||||||||||||||||||
| 3085 | int row, int column, const QModelIndex &parent) | - | ||||||||||||||||||
| 3086 | { | - | ||||||||||||||||||
| 3087 | Q_D(QStandardItemModel); | - | ||||||||||||||||||
| 3088 | // check if the action is supported | - | ||||||||||||||||||
| 3089 | if (!data || !(action == Qt::CopyAction || action == Qt::MoveAction))
| 0 | ||||||||||||||||||
| 3090 | return false; never executed: return false; | 0 | ||||||||||||||||||
| 3091 | // check if the format is supported | - | ||||||||||||||||||
| 3092 | const QString format = QLatin1String("application/x-qstandarditemmodeldatalist");qStandardItemModelDataListMimeType(); | - | ||||||||||||||||||
| 3093 | if (!data->hasFormat(format))
| 0 | ||||||||||||||||||
| 3094 | return QAbstractItemModel::dropMimeData(data, action, row, column, parent); never executed: return QAbstractItemModel::dropMimeData(data, action, row, column, parent); | 0 | ||||||||||||||||||
| 3095 | - | |||||||||||||||||||
| 3096 | if (row > rowCount(parent))
| 0 | ||||||||||||||||||
| 3097 | row = rowCount(parent); never executed: row = rowCount(parent); | 0 | ||||||||||||||||||
| 3098 | if (row == -1)
| 0 | ||||||||||||||||||
| 3099 | row = rowCount(parent); never executed: row = rowCount(parent); | 0 | ||||||||||||||||||
| 3100 | if (column == -1)
| 0 | ||||||||||||||||||
| 3101 | column = 0; never executed: column = 0; | 0 | ||||||||||||||||||
| 3102 | - | |||||||||||||||||||
| 3103 | // decode and insert | - | ||||||||||||||||||
| 3104 | QByteArray encoded = data->data(format); | - | ||||||||||||||||||
| 3105 | QDataStream stream(&encoded, QIODevice::ReadOnly); | - | ||||||||||||||||||
| 3106 | - | |||||||||||||||||||
| 3107 | - | |||||||||||||||||||
| 3108 | //code based on QAbstractItemModel::decodeData | - | ||||||||||||||||||
| 3109 | // adapted to work with QStandardItem | - | ||||||||||||||||||
| 3110 | int top = INT_MAX; | - | ||||||||||||||||||
| 3111 | int left = INT_MAX; | - | ||||||||||||||||||
| 3112 | int bottom = 0; | - | ||||||||||||||||||
| 3113 | int right = 0; | - | ||||||||||||||||||
| 3114 | QVector<int> rows, columns; | - | ||||||||||||||||||
| 3115 | QVector<QStandardItem *> items; | - | ||||||||||||||||||
| 3116 | - | |||||||||||||||||||
| 3117 | while (!stream.atEnd()) {
| 0 | ||||||||||||||||||
| 3118 | int r, c; | - | ||||||||||||||||||
| 3119 | QStandardItem *item = d->createItem(); | - | ||||||||||||||||||
| 3120 | stream >> r >> c; | - | ||||||||||||||||||
| 3121 | d->decodeDataRecursive(stream, item); | - | ||||||||||||||||||
| 3122 | - | |||||||||||||||||||
| 3123 | rows.append(r); | - | ||||||||||||||||||
| 3124 | columns.append(c); | - | ||||||||||||||||||
| 3125 | items.append(item); | - | ||||||||||||||||||
| 3126 | top = qMin(r, top); | - | ||||||||||||||||||
| 3127 | left = qMin(c, left); | - | ||||||||||||||||||
| 3128 | bottom = qMax(r, bottom); | - | ||||||||||||||||||
| 3129 | right = qMax(c, right); | - | ||||||||||||||||||
| 3130 | } never executed: end of block | 0 | ||||||||||||||||||
| 3131 | - | |||||||||||||||||||
| 3132 | // insert the dragged items into the table, use a bit array to avoid overwriting items, | - | ||||||||||||||||||
| 3133 | // since items from different tables can have the same row and column | - | ||||||||||||||||||
| 3134 | int dragRowCount = 0; | - | ||||||||||||||||||
| 3135 | int dragColumnCount = right - left + 1; | - | ||||||||||||||||||
| 3136 | - | |||||||||||||||||||
| 3137 | // Compute the number of continuous rows upon insertion and modify the rows to match | - | ||||||||||||||||||
| 3138 | QVector<int> rowsToInsert(bottom + 1); | - | ||||||||||||||||||
| 3139 | for (int i = 0; i < rows.count(); ++i)
| 0 | ||||||||||||||||||
| 3140 | rowsToInsert[rows.at(i)] = 1; never executed: rowsToInsert[rows.at(i)] = 1; | 0 | ||||||||||||||||||
| 3141 | for (int i = 0; i < rowsToInsert.count(); ++i) {
| 0 | ||||||||||||||||||
| 3142 | if (rowsToInsert[.at(i]) == 1){
| 0 | ||||||||||||||||||
| 3143 | rowsToInsert[i] = dragRowCount; | - | ||||||||||||||||||
| 3144 | ++dragRowCount; | - | ||||||||||||||||||
| 3145 | } never executed: end of block | 0 | ||||||||||||||||||
| 3146 | } never executed: end of block | 0 | ||||||||||||||||||
| 3147 | for (int i = 0; i < rows.count(); ++i)
| 0 | ||||||||||||||||||
| 3148 | rows[i] = top + rowsToInsert[.at(rows[.at(i]];)); never executed: rows[i] = top + rowsToInsert.at(rows.at(i)); | 0 | ||||||||||||||||||
| 3149 | - | |||||||||||||||||||
| 3150 | QBitArray isWrittenTo(dragRowCount * dragColumnCount); | - | ||||||||||||||||||
| 3151 | - | |||||||||||||||||||
| 3152 | // make space in the table for the dropped data | - | ||||||||||||||||||
| 3153 | int colCount = columnCount(parent); | - | ||||||||||||||||||
| 3154 | if (colCount < dragColumnCount + column) {
| 0 | ||||||||||||||||||
| 3155 | insertColumns(colCount, dragColumnCount + column - colCount, parent); | - | ||||||||||||||||||
| 3156 | colCount = columnCount(parent); | - | ||||||||||||||||||
| 3157 | } never executed: end of block | 0 | ||||||||||||||||||
| 3158 | insertRows(row, dragRowCount, parent); | - | ||||||||||||||||||
| 3159 | - | |||||||||||||||||||
| 3160 | row = qMax(0, row); | - | ||||||||||||||||||
| 3161 | column = qMax(0, column); | - | ||||||||||||||||||
| 3162 | - | |||||||||||||||||||
| 3163 | QStandardItem *parentItem = itemFromIndex (parent); | - | ||||||||||||||||||
| 3164 | if (!parentItem)
| 0 | ||||||||||||||||||
| 3165 | parentItem = invisibleRootItem(); never executed: parentItem = invisibleRootItem(); | 0 | ||||||||||||||||||
| 3166 | - | |||||||||||||||||||
| 3167 | QVector<QPersistentModelIndex> newIndexes(items.size()); | - | ||||||||||||||||||
| 3168 | // set the data in the table | - | ||||||||||||||||||
| 3169 | for (int j = 0; j < items.size(); ++j) {
| 0 | ||||||||||||||||||
| 3170 | int relativeRow = rows.at(j) - top; | - | ||||||||||||||||||
| 3171 | int relativeColumn = columns.at(j) - left; | - | ||||||||||||||||||
| 3172 | int destinationRow = relativeRow + row; | - | ||||||||||||||||||
| 3173 | int destinationColumn = relativeColumn + column; | - | ||||||||||||||||||
| 3174 | int flat = (relativeRow * dragColumnCount) + relativeColumn; | - | ||||||||||||||||||
| 3175 | // if the item was already written to, or we just can't fit it in the table, create a new row | - | ||||||||||||||||||
| 3176 | if (destinationColumn >= colCount || isWrittenTo.testBit(flat)) {
| 0 | ||||||||||||||||||
| 3177 | destinationColumn = qBound(column, destinationColumn, colCount - 1); | - | ||||||||||||||||||
| 3178 | destinationRow = row + dragRowCount; | - | ||||||||||||||||||
| 3179 | insertRows(row + dragRowCount, 1, parent); | - | ||||||||||||||||||
| 3180 | flat = (dragRowCount * dragColumnCount) + relativeColumn; | - | ||||||||||||||||||
| 3181 | isWrittenTo.resize(++dragRowCount * dragColumnCount); | - | ||||||||||||||||||
| 3182 | } never executed: end of block | 0 | ||||||||||||||||||
| 3183 | if (!isWrittenTo.testBit(flat)) {
| 0 | ||||||||||||||||||
| 3184 | newIndexes[j] = index(destinationRow, destinationColumn, parentItem->index()); | - | ||||||||||||||||||
| 3185 | isWrittenTo.setBit(flat); | - | ||||||||||||||||||
| 3186 | } never executed: end of block | 0 | ||||||||||||||||||
| 3187 | } never executed: end of block | 0 | ||||||||||||||||||
| 3188 | - | |||||||||||||||||||
| 3189 | for(int k = 0; k < newIndexes.size(); k++) {
| 0 | ||||||||||||||||||
| 3190 | if (newIndexes.at(k).isValid()) {
| 0 | ||||||||||||||||||
| 3191 | parentItem->setChild(newIndexes.at(k).row(), newIndexes.at(k).column(), items.at(k)); | - | ||||||||||||||||||
| 3192 | } else { never executed: end of block | 0 | ||||||||||||||||||
| 3193 | delete items.at(k); | - | ||||||||||||||||||
| 3194 | } never executed: end of block | 0 | ||||||||||||||||||
| 3195 | } | - | ||||||||||||||||||
| 3196 | - | |||||||||||||||||||
| 3197 | return true; never executed: return true; | 0 | ||||||||||||||||||
| 3198 | } | - | ||||||||||||||||||
| 3199 | - | |||||||||||||||||||
| 3200 | QT_END_NAMESPACE | - | ||||||||||||||||||
| 3201 | - | |||||||||||||||||||
| 3202 | #include "moc_qstandarditemmodel.cpp" | - | ||||||||||||||||||
| 3203 | - | |||||||||||||||||||
| 3204 | #endif // QT_NO_STANDARDITEMMODEL | - | ||||||||||||||||||
| Source code | Switch to Preprocessed file |