Changeset 561 for trunk/src/corelib/kernel/qabstractitemmodel.cpp
- Timestamp:
- Feb 11, 2010, 11:19:06 PM (15 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
-
Property svn:mergeinfo
set to (toggle deleted branches)
/branches/vendor/nokia/qt/4.6.1 merged eligible /branches/vendor/nokia/qt/current merged eligible /branches/vendor/trolltech/qt/current 3-149
-
Property svn:mergeinfo
set to (toggle deleted branches)
-
trunk/src/corelib/kernel/qabstractitemmodel.cpp
r2 r561 2 2 ** 3 3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). 4 ** Contact: Qt Software Information ([email protected]) 4 ** All rights reserved. 5 ** Contact: Nokia Corporation ([email protected]) 5 6 ** 6 7 ** This file is part of the QtCore module of the Qt Toolkit. … … 21 22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 22 23 ** 23 ** In addition, as a special exception, Nokia gives you certain 24 ** additional rights. These rights are described in the Nokia Qt LGPL 25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this 26 ** package. 24 ** In addition, as a special exception, Nokia gives you certain additional 25 ** rights. These rights are described in the Nokia Qt LGPL Exception 26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 27 27 ** 28 28 ** GNU General Public License Usage … … 34 34 ** met: http://www.gnu.org/copyleft/gpl.html. 35 35 ** 36 ** If you are unsure which license is appropriate for your use, please37 ** contact the sales department at qt-sales@nokia.com.36 ** If you 37 ** @nokia.com. 38 38 ** $QT_END_LICENSE$ 39 39 ** … … 252 252 Returns true if this persistent model index refers to the same location as 253 253 the \a other model index; otherwise returns false. 254 Note that all values in the persistent model index are used when comparing 255 with another model index. 254 255 All values in the persistent model index are used when comparing with 256 another model index. 256 257 */ 257 258 … … 336 337 337 338 /*! 338 Returns the parent QModelIndex for this persistent index, or339 QModelIndex()if it has no parent.340 341 \sa child() sibling() model()339 340 if it has no parent. 341 342 \sa child() sibling() model() 342 343 */ 343 344 QModelIndex QPersistentModelIndex::parent() const … … 349 350 350 351 /*! 351 Returns the sibling at \a row and \a column or an invalid352 QModelIndex ifthere is no sibling at this position.353 354 \sa parent() child()352 353 there is no sibling at this position. 354 355 \sa parent() child() 355 356 */ 356 357 … … 363 364 364 365 /*! 365 Returns the child of the model index that is stored in the given366 \a rowand \a column.367 368 \sa parent() sibling()366 367 and \a column. 368 369 \sa parent() sibling() 369 370 */ 370 371 … … 377 378 378 379 /*! 379 Returns the data for the given \a role for the item referred to by the index. 380 381 \sa Qt::ItemDataRole, QAbstractItemModel::setData() 380 Returns the data for the given \a role for the item referred to by the 381 index. 382 383 \sa Qt::ItemDataRole, QAbstractItemModel::setData() 382 384 */ 383 385 QVariant QPersistentModelIndex::data(int role) const … … 389 391 390 392 /*! 391 \since 4.2392 393 Returns the flags for the item referred to by the index.393 \since 4.2 394 395 Returns the flags for the item referred to by the index. 394 396 */ 395 397 Qt::ItemFlags QPersistentModelIndex::flags() const … … 401 403 402 404 /*! 403 Returns the model that the index belongs to.405 Returns the model that the index belongs to. 404 406 */ 405 407 const QAbstractItemModel *QPersistentModelIndex::model() const … … 415 417 Returns true if this persistent model index is valid; otherwise returns 416 418 false. 417 A valid index belongs to a model, and has non-negative row and column numbers. 419 420 A valid index belongs to a model, and has non-negative row and column 421 numbers. 418 422 419 423 \sa model(), row(), column() … … 429 433 { 430 434 #ifndef Q_BROKEN_DEBUG_STREAM 431 dbg.nospace() << "QModelIndex(" << idx.row() << ","<< idx.column()432 << "," << idx.internalPointer() << "," << idx.model() << ")";435 dbg.nospace() << "QModelIndex(" << idx.row() << << idx.column() 436 << ; 433 437 return dbg.space(); 434 438 #else … … 466 470 { 467 471 return qEmptyModel(); 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 468 537 } 469 538 … … 526 595 persistent.insertMultiAtEnd(data->index, data); 527 596 } else { 528 qWarning() << "QAbstractItemModel::endInsertRows: Invalid index (" << old.row() + count << ","<< old.column() << ") in model" << q_func();597 qWarning() << "QAbstractItemModel::endInsertRows: Invalid index (" << old.row() + count << << old.column() << ") in model" << q_func(); 529 598 } 530 599 } 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 531 711 } 532 712 … … 575 755 persistent.insertMultiAtEnd(data->index, data); 576 756 } else { 577 qWarning() << "QAbstractItemModel::endRemoveRows: Invalid index (" << old.row() - count << ","<< old.column() << ") in model" << q_func();757 qWarning() << "QAbstractItemModel::endRemoveRows: Invalid index (" << old.row() - count << << old.column() << ") in model" << q_func(); 578 758 } 579 759 } … … 620 800 persistent.insertMultiAtEnd(data->index, data); 621 801 } else { 622 qWarning() << "QAbstractItemModel::endInsertColumns: Invalid index (" << old.row() << ","<< old.column() + count << ") in model" << q_func();802 qWarning() << "QAbstractItemModel::endInsertColumns: Invalid index (" << old.row() << << old.column() + count << ") in model" << q_func(); 623 803 } 624 804 } … … 670 850 persistent.insertMultiAtEnd(data->index, data); 671 851 } else { 672 qWarning() << "QAbstractItemModel::endRemoveColumns: Invalid index (" << old.row() << ","<< old.column() - count << ") in model" << q_func();852 qWarning() << "QAbstractItemModel::endRemoveColumns: Invalid index (" << old.row() << << old.column() - count << ") in model" << q_func(); 673 853 } 674 854 } … … 689 869 690 870 \ingroup model-view 691 \mainclass 871 692 872 693 873 This class is used as an index into item models derived from … … 696 876 697 877 New QModelIndex objects are created by the model using the 698 QAbstractItemModel::createIndex() function. An \e invalid model index 699 can be constructed with the QModelIndex constructor. Invalid indexes are700 oftenused as parent indexes when referring to top-level items in a model.878 QAbstractItemModel::createIndex() function. An \e invalid model index 879 880 used as parent indexes when referring to top-level items in a model. 701 881 702 882 Model indexes refer to items in models, and contain all the information 703 883 required to specify their locations in those models. Each index is located 704 in a given row and column, and may have a parent index; use row(), column(), 705 and parent() to obtain this information. Each top-level item in a model is 706 represented by a model index that does not have a parent index - in this 707 case, parent() will return an invalid model index, equivalent to an index 708 constructed with the zero argument form of the QModelIndex() constructor. 884 in a given row and column, and may have a parent index; use row(), 885 column(), and parent() to obtain this information. Each top-level item in a 886 model is represented by a model index that does not have a parent index - 887 in this case, parent() will return an invalid model index, equivalent to an 888 index constructed with the zero argument form of the QModelIndex() 889 constructor. 709 890 710 891 To obtain a model index that refers to an existing item in a model, call 711 QAbstractItemModel::index() with the required row and column 712 values, and the model index of the parent. When referring to713 top-level items in amodel, supply QModelIndex() as the parent index.892 QAbstractItemModel::index() with the required row and column 893 894 model, supply QModelIndex() as the parent index. 714 895 715 896 The model() function returns the model that the index references as a 716 QAbstractItemModel. 717 The child() function is used to examine the items held beneath the index 718 in the model. 719 The sibling() function allows you to traverse items in the model on the 720 same level as the index. 897 QAbstractItemModel. The child() function is used to examine items held 898 under the index in the model. The sibling() function allows you to traverse 899 items in the model on the same level as the index. 721 900 722 901 \note Model indexes should be used immediately and then discarded. You … … 725 904 keep a model index over time use a QPersistentModelIndex. 726 905 727 \sa \link model-view-programming.html Model/View Programming\endlink QPersistentModelIndexQAbstractItemModel906 \sa QAbstractItemModel 728 907 */ 729 908 … … 731 910 \fn QModelIndex::QModelIndex() 732 911 733 Creates a new empty model index. 734 This type of model index is used to indicate 735 that the position in the model is invalid. 912 Creates a new empty model index. This type of model index is used to 913 indicate that the position in the model is invalid. 736 914 737 915 \sa isValid() QAbstractItemModel … … 796 974 797 975 Returns true if this model index is valid; otherwise returns false. 798 A valid index belongs to a model, and has non-negative row and column numbers. 976 977 A valid index belongs to a model, and has non-negative row and column 978 numbers. 799 979 800 980 \sa model(), row(), column() … … 807 987 refers to. 808 988 809 You receive a const pointer to the model because calls to810 non-const functions of the model might invalidate the model index811 - and possiblycrash your application.989 990 991 crash your application. 812 992 */ 813 993 … … 815 995 \fn QModelIndex QModelIndex::sibling(int row, int column) const 816 996 817 Returns the sibling at \a row and \a column or an invalid818 QModelIndex if there is no sibling at this position.819 820 \sa parent() child()997 Returns the sibling at \a row and \a column 998 . 999 1000 \sa parent() child() 821 1001 */ 822 1002 … … 824 1004 \fn QModelIndex QModelIndex::child(int row, int column) const 825 1005 826 Returns the child of the model index that is stored in the given 827 \a row and \acolumn.828 829 \sa parent() sibling()1006 Returns the child of the model index that is stored in the given 1007 \a column. 1008 1009 \sa parent() sibling() 830 1010 */ 831 1011 … … 833 1013 \fn QVariant QModelIndex::data(int role) const 834 1014 835 Returns the data for the given \a role for the item referred to by the index. 1015 Returns the data for the given \a role for the item referred to by the 1016 index. 836 1017 */ 837 1018 … … 846 1027 \fn bool QModelIndex::operator==(const QModelIndex &other) const 847 1028 848 Returns true if this model index refers to the same location as 1029 Returns true if this model index refers to the same location as the 1030 \a other model index; otherwise returns false. 1031 1032 All values in the model index are used when comparing with another model 1033 index. 1034 */ 1035 1036 1037 /*! 1038 \fn bool QModelIndex::operator!=(const QModelIndex &other) const 1039 1040 Returns true if this model index does not refer to the same location as 849 1041 the \a other model index; otherwise returns false. 850 Note that all values in the model index are used when comparing 851 with another model index. 852 */ 853 854 855 /*! 856 \fn bool QModelIndex::operator!=(const QModelIndex &other) const 857 858 Returns true if this model index does not refer to the same 859 location as the \a other model index; otherwise returns false. 860 */ 861 862 863 /*! 864 \fn QModelIndex QModelIndex::parent() const 865 866 Returns the parent of the model index, or QModelIndex() if it has no 867 parent. 868 869 \sa child() sibling() model() 1042 */ 1043 1044 1045 /*! 1046 \fn QModelIndex QModelIndex::parent() const 1047 1048 Returns the parent of the model index, or QModelIndex() if it has no 1049 parent. 1050 1051 \sa child(), sibling(), model() 870 1052 */ 871 1053 … … 877 1059 878 1060 \ingroup model-view 879 \mainclass 1061 880 1062 881 1063 The QAbstractItemModel class defines the standard interface that item … … 896 1078 a QModelIndex. 897 1079 898 \im gmodelindex-no-parent.png1080 \im modelindex-no-parent.png 899 1081 900 1082 Every item of data that can be accessed via a model has an associated model … … 1014 1196 \sa {Model Classes}, {Model Subclassing Reference}, QModelIndex, 1015 1197 QAbstractItemView, {Using Drag and Drop with Item Views}, 1016 {Simple DOM Model Example}, 1017 {Simple Tree Model Example}, {Editable Tree Model Example}, 1018 {Fetch More Example} 1198 {Simple DOM Model Example}, {Simple Tree Model Example}, 1199 {Editable Tree Model Example}, {Fetch More Example} 1019 1200 */ 1020 1201 … … 1025 1206 \a column and \a parent index. 1026 1207 1027 When reimplementing this function in a subclass, call createIndex() to generate 1028 model indexes that other components can use to refer to items in your model. 1208 When reimplementing this function in a subclass, call createIndex() to 1209 generate model indexes that other components can use to refer to items in 1210 your model. 1029 1211 1030 1212 \sa createIndex() … … 1035 1217 1036 1218 Inserts a single column before the given \a column in the child items of 1037 the \a parent specified. Returns true if the column is inserted; otherwise 1219 the \a parent specified. 1220 1221 Returns true if the column is inserted; otherwise returns false. 1222 1223 \sa insertColumns() insertRow() removeColumn() 1224 */ 1225 1226 /*! 1227 \fn bool QAbstractItemModel::insertRow(int row, const QModelIndex &parent) 1228 1229 \note The base class implementation of this function does nothing and 1038 1230 returns false. 1039 1231 1040 \sa insertColumns() insertRow() removeColumn()1041 */1042 1043 /*!1044 \fn bool QAbstractItemModel::insertRow(int row, const QModelIndex &parent)1045 1046 1232 Inserts a single row before the given \a row in the child items of the 1047 \a parent specified. Returns true if the row is inserted; otherwise 1048 returns false. 1233 \a parent specified. 1234 1235 Returns true if the row is inserted; otherwise returns false. 1049 1236 1050 1237 \sa insertRows() insertColumn() removeRow() … … 1059 1246 \fn QModelIndex QAbstractItemModel::parent(const QModelIndex &index) const = 0 1060 1247 1061 Returns the parent of the model item with the given \a index , or QModelIndex()1062 if it has no parent.1248 Returns the parent of the model item with the given \a index 1249 . 1063 1250 1064 1251 A common convention used in models that expose tree data structures is that 1065 only items in the first column have children. For that case, when reimplementing 1066 this function in a subclass the column of the returned QModelIndex would be 0. 1067 1068 \note When reimplementing this function in a subclass, be careful to avoid 1252 only items in the first column have children. For that case, when 1253 reimplementing this function in a subclass the column of the returned 1254 QModelIndex would be 0. 1255 1256 When reimplementing this function in a subclass, be careful to avoid 1069 1257 calling QModelIndex member functions, such as QModelIndex::parent(), since 1070 indexes belonging to your model will simply call your implementation, leading1071 to infinite recursion.1258 indexes belonging to your model will simply call your implementation, 1259 to infinite recursion. 1072 1260 1073 1261 \sa createIndex() … … 1077 1265 \fn bool QAbstractItemModel::removeColumn(int column, const QModelIndex &parent) 1078 1266 1079 Removes the given \a column from the child items of the \a parent specified. 1267 Removes the given \a column from the child items of the \a parent 1268 specified. 1269 1080 1270 Returns true if the column is removed; otherwise returns false. 1081 1271 … … 1087 1277 1088 1278 Removes the given \a row from the child items of the \a parent specified. 1279 1089 1280 Returns true if the row is removed; otherwise returns false. 1090 1281 1091 Th e removeRow() is a convenience function that calls removeRows().1092 The QAbstractItemModel implementation of removeRowsdoes nothing.1282 Th 1283 does nothing. 1093 1284 1094 1285 \sa removeRows(), removeColumn(), insertRow() … … 1102 1293 sections in the header from the \a first to the \a last need to be updated. 1103 1294 1104 Note that this signal must be emitted explicitly when 1105 reimplementing the setHeaderData() function. 1106 1107 If you are changing the number of columns or rows you don't need 1108 to emit this signal, but use the begin/end functions (see the 1109 section on subclassing in the QAbstractItemModel class description 1110 for details). 1295 When reimplementing the setHeaderData() function, this signal must be 1296 emitted explicitly. 1297 1298 If you are changing the number of columns or rows you do not need to emit 1299 this signal, but use the begin/end functions (refer to the section on 1300 subclassing in the QAbstractItemModel class description for details). 1111 1301 1112 1302 \sa headerData(), setHeaderData(), dataChanged() … … 1118 1308 1119 1309 This signal is emitted just before the layout of a model is changed. 1120 Components connected to this signal use it to adapt to changes 1121 in themodel's layout.1310 Components connected to this signal use it to adapt to changes 1311 model's layout. 1122 1312 1123 1313 Subclasses should update any persistent model indexes after emitting … … 1131 1321 1132 1322 This signal is emitted whenever the layout of items exposed by the model 1133 has changed; for example, when the model has been sorted. When this signal is1134 received by a view, it should update the layout of items to reflect this1323 has changed; for example, when the model has been sorted. When this signal 1324 received by a view, it should update the layout of items to reflect this 1135 1325 change. 1136 1326 1137 When subclassing QAbstractItemModel or QAbstractProxyModel, ensure that 1138 youemit layoutAboutToBeChanged() before changing the order of items or1327 When subclassing QAbstractItemModel or QAbstractProxyModel, ensure that 1328 emit layoutAboutToBeChanged() before changing the order of items or 1139 1329 altering the structure of the data you expose to views, and emit 1140 1330 layoutChanged() after changing the layout. 1141 1331 1142 Subclasses should update any persistent model indexes before 1143 emitting layoutChanged(). 1144 1145 \sa layoutAboutToBeChanged(), dataChanged(), headerDataChanged(), reset(), changePersistentIndex() 1332 Subclasses should update any persistent model indexes before emitting 1333 layoutChanged(). In other words, when the structure changes: 1334 1335 \list 1336 \o Call beginLayoutChanged() 1337 \o Remember the QModelIndex that will change 1338 \o Update your internal data 1339 \o Call changePersistentIndex() 1340 \o Call endLayoutChanged() 1341 \endlist 1342 1343 1344 \sa layoutAboutToBeChanged(), dataChanged(), headerDataChanged(), modelReset(), 1345 changePersistentIndex() 1146 1346 */ 1147 1347 … … 1173 1373 \fn QModelIndex QAbstractItemModel::sibling(int row, int column, const QModelIndex &index) const 1174 1374 1175 Returns the sibling at \a row and \a column for the item at \a index, or 1176 aninvalid QModelIndex if there is no sibling at that location.1375 Returns the sibling at \a row and \a column for the item at \a index, or 1376 invalid QModelIndex if there is no sibling at that location. 1177 1377 1178 1378 sibling() is just a convenience function that finds the item's parent, and 1179 uses it to retrieve the index of the child item in the specified \a row 1180 and\a column.1379 uses it to retrieve the index of the child item in the specified \a row 1380 \a column. 1181 1381 1182 1382 \sa index(), QModelIndex::row(), QModelIndex::column() … … 1187 1387 \fn int QAbstractItemModel::rowCount(const QModelIndex &parent) const 1188 1388 1189 Returns the number of rows under the given \a parent. When the parent1190 isvalid it means that rowCount is returning the number of children of parent.1191 1192 \ bold{Tip:} When implementing a table based model, rowCount() should return 0 when1193 the parent is valid.1389 Returns the number of rows under the given \a parent. 1390 valid it means that rowCount is returning the number of children of parent. 1391 1392 \ 1393 the parent is valid. 1194 1394 1195 1395 \sa columnCount() … … 1201 1401 Returns the number of columns for the children of the given \a parent. 1202 1402 1203 In most subclasses, the number of columns is independent of the 1204 \a parent. For example: 1403 In most subclasses, the number of columns is independent of the \a parent. 1404 1405 For example: 1205 1406 1206 1407 \snippet examples/itemviews/simpledommodel/dommodel.cpp 2 1207 1408 1208 \ bold{Tip:} When implementing a table based model, columnCount() should return 0 when1209 the parent is valid.1409 \ 1410 the parent is valid. 1210 1411 1211 1412 \sa rowCount() … … 1234 1435 inclusive, under the given \a parent item. 1235 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1236 1495 \bold{Note:} Components connected to this signal use it to adapt to changes 1237 1496 in the model's dimensions. It can only be emitted by the QAbstractItemModel 1238 1497 implementation, and cannot be explicitly emitted in subclass code. 1239 1498 1240 \sa insertRows(), beginInsertRows() 1241 */ 1242 1243 /*! 1244 \fn void QAbstractItemModel::rowsAboutToBeInserted(const QModelIndex &parent, int start, int end) 1245 1246 This signal is emitted just before rows are inserted into the 1247 model. The new items will be positioned between \a start and \a end 1248 inclusive, under the given \a parent item. 1499 \sa beginMoveRows() 1500 */ 1501 1502 /*! 1503 \fn void QAbstractItemModel::rowsAboutToBeMoved(const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destinationParent, int destinationRow) 1504 \since 4.6 1505 1506 This signal is emitted just before rows are moved within the 1507 model. The items that will be moved are those between \a sourceStart and \a sourceEnd 1508 inclusive, under the given \a sourceParent item. They will be moved to \a destinationParent 1509 starting at the row \a destinationRow. 1249 1510 1250 1511 \bold{Note:} Components connected to this signal use it to adapt to changes … … 1252 1513 implementation, and cannot be explicitly emitted in subclass code. 1253 1514 1254 \sa insertRows(), beginInsertRows() 1255 */ 1256 1257 /*! 1258 \fn void QAbstractItemModel::rowsRemoved(const QModelIndex &parent, int start, int end) 1259 1260 This signal is emitted after rows have been removed from the 1261 model. The removed items are those between \a start and \a end 1262 inclusive, under the given \a parent item. 1515 \sa beginMoveRows() 1516 */ 1517 1518 /*! 1519 \fn void QAbstractItemModel::columnsMoved(const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destinationParent, int destinationColumn) 1520 \since 4.6 1521 1522 This signal is emitted after columns have been moved within the 1523 model. The items between \a sourceStart and \a sourceEnd 1524 inclusive, under the given \a sourceParent item have been moved to \a destinationParent 1525 starting at the column \a destinationColumn. 1263 1526 1264 1527 \bold{Note:} Components connected to this signal use it to adapt to changes … … 1266 1529 implementation, and cannot be explicitly emitted in subclass code. 1267 1530 1268 \sa removeRows(), beginRemoveRows() 1269 */ 1270 1271 /*! 1272 \fn void QAbstractItemModel::rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end) 1273 1274 This signal is emitted just before rows are removed from the 1275 model. The items that will be removed are those between \a start and \a end 1276 inclusive, under the given \a parent item. 1531 \sa beginMoveRows() 1532 */ 1533 1534 /*! 1535 \fn void QAbstractItemModel::columnsAboutToBeMoved(const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destinationParent, int destinationColumn) 1536 \since 4.6 1537 1538 This signal is emitted just before columns are moved within the 1539 model. The items that will be moved are those between \a sourceStart and \a sourceEnd 1540 inclusive, under the given \a sourceParent item. They will be moved to \a destinationParent 1541 starting at the column \a destinationColumn. 1277 1542 1278 1543 \bold{Note:} Components connected to this signal use it to adapt to changes … … 1280 1545 implementation, and cannot be explicitly emitted in subclass code. 1281 1546 1282 \sa removeRows(), beginRemoveRows()1547 \sa oveRows() 1283 1548 */ 1284 1549 … … 1286 1551 \fn void QAbstractItemModel::columnsInserted(const QModelIndex &parent, int start, int end) 1287 1552 1288 This signal is emitted after columns have been inserted into the 1289 model. The new items are those between \a start and \a end1290 inclusive, under the given\a parent item.1291 1292 \ bold{Note:} Components connected to this signal use it to adapt to changes1293 in themodel's dimensions. It can only be emitted by the QAbstractItemModel1553 This signal is emitted after columns have been inserted into the 1554 1555 \a parent item. 1556 1557 \ 1558 model's dimensions. It can only be emitted by the QAbstractItemModel 1294 1559 implementation, and cannot be explicitly emitted in subclass code. 1295 1560 … … 1300 1565 \fn void QAbstractItemModel::columnsAboutToBeInserted(const QModelIndex &parent, int start, int end) 1301 1566 1302 This signal is emitted just before columns are inserted into the 1303 model. The new items will be positioned between \a start and \a end1304 inclusive, underthe given \a parent item.1305 1306 \ bold{Note:} Components connected to this signal use it to adapt to changes1307 in themodel's dimensions. It can only be emitted by the QAbstractItemModel1567 This signal is emitted just before columns are inserted into the 1568 1569 the given \a parent item. 1570 1571 \ 1572 model's dimensions. It can only be emitted by the QAbstractItemModel 1308 1573 implementation, and cannot be explicitly emitted in subclass code. 1309 1574 … … 1314 1579 \fn void QAbstractItemModel::columnsRemoved(const QModelIndex &parent, int start, int end) 1315 1580 1316 This signal is emitted after columns have been removed from the 1317 model. The removed items are those between \a start and \a end1318 inclusive,under the given \a parent item.1319 1320 \ bold{Note:} Components connected to this signal use it to adapt to changes1321 inthe model's dimensions. It can only be emitted by the QAbstractItemModel1581 This signal is emitted after columns have been removed from the 1582 1583 under the given \a parent item. 1584 1585 \ 1586 the model's dimensions. It can only be emitted by the QAbstractItemModel 1322 1587 implementation, and cannot be explicitly emitted in subclass code. 1323 1588 … … 1328 1593 \fn void QAbstractItemModel::columnsAboutToBeRemoved(const QModelIndex &parent, int start, int end) 1329 1594 1330 This signal is emitted just before columns are removed 1331 from the model. The items to be removed are those between \a start and1332 \a end inclusive, underthe given \a parent item.1333 1334 \ bold{Note:} Components connected to this signal use it to adapt to changes1335 in themodel's dimensions. It can only be emitted by the QAbstractItemModel1595 This signal is emitted just before columns are removed 1596 1597 the given \a parent item. 1598 1599 \ 1600 model's dimensions. It can only be emitted by the QAbstractItemModel 1336 1601 implementation, and cannot be explicitly emitted in subclass code. 1337 1602 … … 1340 1605 1341 1606 /*! 1342 Returns true if the model returns a valid QModelIndex for \a row and1343 \a column with \a parent, otherwise returns false.1607 Returns true if the model returns a valid QModelIndex for \a row and 1608 \a column with \a parent, otherwise returns false. 1344 1609 */ 1345 1610 bool QAbstractItemModel::hasIndex(int row, int column, const QModelIndex &parent) const … … 1352 1617 1353 1618 /*! 1354 Returns true if \a parent has any children; otherwise returns false. 1355 Use rowCount() on the parent to find out the number of children. 1356 1357 \sa parent() index() 1619 Returns true if \a parent has any children; otherwise returns false. 1620 1621 Use rowCount() on the parent to find out the number of children. 1622 1623 \sa parent() index() 1358 1624 */ 1359 1625 bool QAbstractItemModel::hasChildren(const QModelIndex &parent) const … … 1364 1630 1365 1631 /*! 1366 Returns a map with values for all predefined roles in the model 1367 for theitem at the given \a index.1368 1369 Reimplement ed this function if you want to extend the default behavior1370 ofthis function to include custom roles in the map.1632 Returns a map with values for all predefined roles in the model 1633 item at the given \a index. 1634 1635 Reimplement 1636 this function to include custom roles in the map. 1371 1637 1372 1638 \sa Qt::ItemDataRole, data() … … 1377 1643 for (int i = 0; i < Qt::UserRole; ++i) { 1378 1644 QVariant variantData = data(index, i); 1379 if (variantData. type() != QVariant::Invalid)1645 if (variantData.) 1380 1646 roles.insert(i, variantData); 1381 1647 } … … 1385 1651 /*! 1386 1652 Sets the \a role data for the item at \a index to \a value. 1653 1387 1654 Returns true if successful; otherwise returns false. 1388 1655 1389 The dataChanged() signal should be emitted if the data was successfully set. 1390 1391 The base class implementation returns false. This function and 1392 data() must be reimplemented for editable models. Note that the 1393 dataChanged() signal must be emitted explicitly when 1394 reimplementing this function. 1656 The dataChanged() signal should be emitted if the data was successfully 1657 set. 1658 1659 The base class implementation returns false. This function and data() must 1660 be reimplemented for editable models. 1395 1661 1396 1662 \sa Qt::ItemDataRole, data(), itemData() … … 1411 1677 1412 1678 \note If you do not have a value to return, return an \bold invalid 1413 QVariant ()instead of returning 0.1679 QVariant instead of returning 0. 1414 1680 1415 1681 \sa Qt::ItemDataRole, setData(), headerData() … … 1418 1684 /*! 1419 1685 Sets the role data for the item at \a index to the associated value in 1420 \a roles, for every Qt::ItemDataRole. Returns true if successful; otherwise 1421 returns false. 1686 \a roles, for every Qt::ItemDataRole. 1687 1688 Returns true if successful; otherwise returns false. 1422 1689 1423 1690 Roles that are not in \a roles will not be modified. … … 1434 1701 1435 1702 /*! 1436 Returns a list of MIME types that can be used to describe a list of 1437 modelindexes.1703 Returns a list of MIME types that can be used to describe a list of 1704 indexes. 1438 1705 1439 1706 \sa mimeData() … … 1447 1714 1448 1715 /*! 1449 Returns an object that contains serialized items of data corresponding to the1450 list of \a indexes specified. The formats used to describe the encoded data1451 is obtained from the mimeTypes() function.1452 1453 If the list of indexes is empty, or there are no supported MIME types, 1454 0 isreturned rather than a serialized empty list.1716 Returns an object that contains serialized items of data corresponding to 1717 1718 is obtained from the mimeTypes() function. 1719 1720 If the list of indexes is empty, or there are no supported MIME types, 1721 returned rather than a serialized empty list. 1455 1722 1456 1723 \sa mimeTypes(), dropMimeData() … … 1474 1741 /*! 1475 1742 Handles the \a data supplied by a drag and drop operation that ended with 1476 the given \a action. Returns true if the data and action can be handled 1477 by the model; otherwise returns false. 1478 1479 Although the specified \a row, \a column and \a parent indicate the location of 1480 an item in the model where the operation ended, it is the responsibility of the 1481 view to provide a suitable location for where the data should be inserted. 1482 1483 For instance, a drop action on an item in a QTreeView can result in new items 1484 either being inserted as children of the item specified by \a row, \a column, 1485 and \a parent, or as siblings of the item. 1743 the given \a action. 1744 1745 Returns true if the data and action can be handled by the model; otherwise 1746 returns false. 1747 1748 Although the specified \a row, \a column and \a parent indicate the 1749 location of an item in the model where the operation ended, it is the 1750 responsibility of the view to provide a suitable location for where the 1751 data should be inserted. 1752 1753 For instance, a drop action on an item in a QTreeView can result in new 1754 items either being inserted as children of the item specified by \a row, 1755 \a column, and \a parent, or as siblings of the item. 1486 1756 1487 1757 When row and column are -1 it means that it is up to the model to decide 1488 where to place the data. This can occur in a tree when data is dropped 1489 on a parent. Models will usually append the data to the parent in this case. 1490 1491 Returns true if the dropping was successful otherwise false. 1758 where to place the data. This can occur in a tree when data is dropped on 1759 a parent. Models will usually append the data to the parent in this case. 1492 1760 1493 1761 \sa supportedDropActions(), {Using Drag and Drop with Item Views} … … 1519 1787 1520 1788 /*! 1521 \since 4.21522 1523 Returns the drop actions supported by this model.1524 1525 The default implementation returns Qt::CopyAction. Reimplement this1526 function if you wish to support additional actions. Note that you1527 must also reimplement the dropMimeData() function to handle the1528 additionaloperations.1529 1530 \sa dropMimeData(), Qt::DropActions, {Using Drag and Drop with Item1531 Views}1789 \since 4.2 1790 1791 Returns the drop actions supported by this model. 1792 1793 The default implementation returns Qt::CopyAction. Reimplement this 1794 1795 1796 operations. 1797 1798 \sa dropMimeData(), Qt::DropActions, {Using Drag and Drop with Item 1799 Views} 1532 1800 */ 1533 1801 Qt::DropActions QAbstractItemModel::supportedDropActions() const … … 1537 1805 1538 1806 /*! 1539 Returns the actions supported by the data in this model.1540 1541 The default implementation returns supportedDropActions() unless1542 specificvalues have been set with setSupportedDragActions().1543 1544 supportedDragActions() is used by QAbstractItemView::startDrag() as1545 thedefault values when a drag occurs.1546 1547 \sa Qt::DropActions, {Using Drag and Drop with Item Views}1807 Returns the actions supported by the data in this model. 1808 1809 1810 values have been set with setSupportedDragActions(). 1811 1812 1813 default values when a drag occurs. 1814 1815 \sa Qt::DropActions, {Using Drag and Drop with Item Views} 1548 1816 */ 1549 1817 Qt::DropActions QAbstractItemModel::supportedDragActions() const … … 1570 1838 1571 1839 /*! 1572 On models that support this, inserts \a count rows into the model before the 1573 given \a row. The items in the new row will be children of the item 1574 represented by the \a parent model index. 1575 1576 If \a row is 0, the rows are prepended to any existing rows in the parent. 1577 If \a row is rowCount(), the rows are appended to any existing rows in the 1578 parent. 1579 If \a parent has no children, a single column with \a count rows is inserted. 1580 1581 Returns true if the rows were successfully inserted; otherwise returns 1582 false. 1583 1584 The base class implementation does nothing and returns false. 1585 1586 If you implement your own model, you can reimplement this function 1587 if you want to support insertions. Alternatively, you can provide 1588 you own API for altering the data. 1589 1590 \sa insertColumns(), removeRows(), beginInsertRows(), endInsertRows() 1840 \note The base class implementation of this function does nothing and 1841 returns false. 1842 1843 On models that support this, inserts \a count rows into the model before 1844 the given \a row. Items in the new row will be children of the item 1845 represented by the \a parent model index. 1846 1847 If \a row is 0, the rows are prepended to any existing rows in the parent. 1848 1849 If \a row is rowCount(), the rows are appended to any existing rows in the 1850 parent. 1851 1852 If \a parent has no children, a single column with \a count rows is 1853 inserted. 1854 1855 Returns true if the rows were successfully inserted; otherwise returns 1856 false. 1857 1858 If you implement your own model, you can reimplement this function if you 1859 want to support insertions. Alternatively, you can provide your own API for 1860 altering the data. In either case, you will need to call 1861 beginInsertRows() and endInsertRows() to notify other components that the 1862 model has changed. 1863 1864 \sa insertColumns(), removeRows(), beginInsertRows(), endInsertRows() 1591 1865 */ 1592 1866 bool QAbstractItemModel::insertRows(int, int, const QModelIndex &) … … 1596 1870 1597 1871 /*! 1598 On models that support this, inserts \a count new columns into the model 1599 before the given \a column. The items in each new column will be children 1600 of the item represented by the \a parent model index. 1601 1602 If \a column is 0, the columns are prepended to any existing columns. 1603 If \a column is columnCount(), the columns are appended to any existing 1604 columns. 1605 If \a parent has no children, a single row with \a count columns is inserted. 1606 1607 Returns true if the columns were successfully inserted; otherwise returns 1608 false. 1609 1610 The base class implementation does nothing and returns false. 1611 1612 If you implement your own model, you can reimplement this function 1613 if you want to support insertions. Alternatively, you can provide 1614 you own API for altering the data. 1615 1616 \sa insertRows(), removeColumns(), beginInsertColumns(), endInsertColumns() 1872 On models that support this, inserts \a count new columns into the model 1873 before the given \a column. The items in each new column will be children 1874 of the item represented by the \a parent model index. 1875 1876 If \a column is 0, the columns are prepended to any existing columns. 1877 1878 If \a column is columnCount(), the columns are appended to any existing 1879 columns. 1880 1881 If \a parent has no children, a single row with \a count columns is 1882 inserted. 1883 1884 Returns true if the columns were successfully inserted; otherwise returns 1885 false. 1886 1887 The base class implementation does nothing and returns false. 1888 1889 If you implement your own model, you can reimplement this function if you 1890 want to support insertions. Alternatively, you can provide your own API for 1891 altering the data. 1892 1893 \sa insertRows(), removeColumns(), beginInsertColumns(), endInsertColumns() 1617 1894 */ 1618 1895 bool QAbstractItemModel::insertColumns(int, int, const QModelIndex &) … … 1623 1900 /*! 1624 1901 On models that support this, removes \a count rows starting with the given 1625 \a row under parent \a parent from the model. Returns true if the rows 1626 were successfully removed; otherwise returns false. 1902 \a row under parent \a parent from the model. 1903 1904 Returns true if the rows were successfully removed; otherwise returns 1905 false. 1627 1906 1628 1907 The base class implementation does nothing and returns false. 1629 1908 1630 If you implement your own model, you can reimplement this function 1631 if you want to support removing. Alternatively, you can provide 1632 you own API for altering the data. 1633 1634 \sa removeRow(), removeColumns(), insertColumns(), beginRemoveRows(), endRemoveRows() 1909 If you implement your own model, you can reimplement this function if you 1910 want to support removing. Alternatively, you can provide your own API for 1911 altering the data. 1912 1913 \sa removeRow(), removeColumns(), insertColumns(), beginRemoveRows(), 1914 endRemoveRows() 1635 1915 */ 1636 1916 bool QAbstractItemModel::removeRows(int, int, const QModelIndex &) … … 1641 1921 /*! 1642 1922 On models that support this, removes \a count columns starting with the 1643 given \a column under parent \a parent from the model. Returns true if the 1644 columns were successfully removed; otherwise returns false. 1923 given \a column under parent \a parent from the model. 1924 1925 Returns true if the columns were successfully removed; otherwise returns 1926 false. 1645 1927 1646 1928 The base class implementation does nothing and returns false. 1647 1929 1648 If you implement your own model, you can reimplement this function 1649 if you want to support removing. Alternatively, you can provide 1650 you own API for altering the data. 1651 1652 \sa removeColumn(), removeRows(), insertColumns(), beginRemoveColumns(), endRemoveColumns() 1930 If you implement your own model, you can reimplement this function if you 1931 want to support removing. Alternatively, you can provide your own API for 1932 altering the data. 1933 1934 \sa removeColumn(), removeRows(), insertColumns(), beginRemoveColumns(), 1935 endRemoveColumns() 1653 1936 */ 1654 1937 bool QAbstractItemModel::removeColumns(int, int, const QModelIndex &) … … 1673 1956 1674 1957 /*! 1675 Returns true if there is more data available for \a parent; otherwise returns1676 false.1677 1958 Returns true if there is more data available for \a parent; otherwise 1959 false. 1960 1678 1961 The default implementation always returns false. 1679 1962 … … 1692 1975 Returns the item flags for the given \a index. 1693 1976 1694 The base class implementation returns a combination of flags that 1695 enables the item (\c ItemIsEnabled) and allows it to be1696 selected(\c ItemIsSelectable).1977 The base class implementation returns a combination of flags that 1978 1979 (\c ItemIsSelectable). 1697 1980 1698 1981 \sa Qt::ItemFlags … … 1720 2003 1721 2004 /*! 1722 Returns a model index for the buddy of the item represented by \a index. 1723 When the user wants to edit an item, the view will call this function to 1724 check whether another item in the model should be edited instead, and 1725 construct a delegate using the model index returned by the buddy item. 1726 1727 In the default implementation each item is its own buddy. 2005 Returns a model index for the buddy of the item represented by \a index. 2006 When the user wants to edit an item, the view will call this function to 2007 check whether another item in the model should be edited instead. Then, the 2008 view will construct a delegate using the model index returned by the buddy 2009 item. 2010 2011 The default implementation of this function has each item as its own buddy. 1728 2012 */ 1729 2013 QModelIndex QAbstractItemModel::buddy(const QModelIndex &index) const … … 1733 2017 1734 2018 /*! 1735 Returns a list of indexes for the items in the column of the \a 1736 start index where the data stored under the given \a role matches1737 the specified \a value. The way the search is performed is defined1738 by the \a flags given. The listthat is returned may be empty.1739 1740 The search starts from the \a start index, and continues until the1741 number of matching data items equals \a hits, the search reaches1742 the last row, or the search reaches \a start again, depending on1743 whether \c MatchWrap is specified in \a flags. If you want to search1744 for all matching items, use\a hits = -1.2019 Returns a list of indexes for the items in the column of the \a 2020 2021 2022 that is returned may be empty. 2023 2024 The search 2025 2026 the 2027 2028 \a hits = -1. 1745 2029 1746 2030 By default, this function will perform a wrapping, string-based comparison 1747 2031 on all items, searching for items that begin with the search term specified 1748 2032 by \a value. 1749 1750 \note The default implementation of this function only searches columns ,1751 This function can be reimplemented to include othersearch behavior.2033 2034 \note The default implementation of this function only searches columns 2035 search behavior. 1752 2036 */ 1753 2037 QModelIndexList QAbstractItemModel::match(const QModelIndex &start, int role, … … 1824 2108 Returns the row and column span of the item represented by \a index. 1825 2109 1826 Note: span is not used currently, but will be in the future.2110 . 1827 2111 */ 1828 2112 … … 1833 2117 1834 2118 /*! 1835 Called to let the model know that it should submit whatever it has cached 1836 to the permanent storage. Typically used for row editing. 1837 1838 Returns false on error, otherwise true. 2119 \since 4.6 2120 2121 Sets the model's role names to \a roleNames. 2122 2123 This function allows mapping of role identifiers to role property names in 2124 Declarative UI. This function must be called before the model is used. 2125 Modifying the role names after the model has been set may result in 2126 undefined behaviour. 2127 2128 \sa roleNames() 2129 */ 2130 void QAbstractItemModel::setRoleNames(const QHash<int,QByteArray> &roleNames) 2131 { 2132 Q_D(QAbstractItemModel); 2133 d->roleNames = roleNames; 2134 } 2135 2136 /*! 2137 \since 4.6 2138 2139 Returns the model's role names. 2140 2141 \sa setRoleNames() 2142 */ 2143 const QHash<int,QByteArray> &QAbstractItemModel::roleNames() const 2144 { 2145 Q_D(const QAbstractItemModel); 2146 return d->roleNames; 2147 } 2148 2149 /*! 2150 Lets the model know that it should submit cached information to permanent 2151 storage. This function is typically used for row editing. 2152 2153 Returns true if there is no error; otherwise returns false. 2154 2155 \sa revert() 1839 2156 */ 1840 2157 … … 1845 2162 1846 2163 /*! 1847 Called to let the model know that it should discard whatever it has cached. 1848 Typically used for row editing. 2164 Lets the model know that it should discard cached information. This 2165 function is typically used for row editing. 2166 2167 \sa submit() 1849 2168 */ 1850 2169 … … 1855 2174 1856 2175 /*! 1857 Returns the data for the given \a role and \a section in the header1858 withthe specified \a orientation.1859 1860 For horizontal headers, the section number corresponds to the column1861 number of items shown beneath it. For vertical headers, the section1862 number typically to the row number of items shown alongside it.1863 1864 \sa Qt::ItemDataRole, setHeaderData(), QHeaderView2176 2177 the specified \a orientation. 2178 2179 For horizontal headers, the section number corresponds to the column 2180 2181 . 2182 2183 \sa Qt::ItemDataRole, setHeaderData(), QHeaderView 1865 2184 */ 1866 2185 … … 1874 2193 1875 2194 /*! 1876 Sets the data for the given \a role and \a section in the header with 1877 the specified \a orientation to the \a value supplied. 1878 Returns true if the header's data was updated; otherwise returns false. 1879 1880 Note that the headerDataChanged() signal must be emitted explicitly 1881 when reimplementing this function. 1882 1883 \sa Qt::ItemDataRole, headerData() 2195 Sets the data for the given \a role and \a section in the header with the 2196 specified \a orientation to the \a value supplied. 2197 2198 Returns true if the header's data was updated; otherwise returns false. 2199 2200 When reimplementing this function, the headerDataChanged() signal must be 2201 emitted explicitly. 2202 2203 \sa Qt::ItemDataRole, headerData() 1884 2204 */ 1885 2205 … … 1897 2217 \fn QModelIndex QAbstractItemModel::createIndex(int row, int column, void *ptr) const 1898 2218 1899 Creates a model index for the given \a row and \a column with the internal pointer \a ptr. 1900 1901 Note that when you are using a QSortFilterProxyModel its indexes have their own 1902 internal pointer. It is not advisable to access the internal pointer in the index 1903 outside of the model. Use the data() function instead. 2219 Creates a model index for the given \a row and \a column with the internal 2220 pointer \a ptr. 2221 2222 When using a QSortFilterProxyModel, its indexes have their own internal 2223 pointer. It is not advisable to access this internal pointer outside of the 2224 model. Use the data() function instead. 1904 2225 1905 2226 This function provides a consistent interface that model subclasses must … … 1911 2232 \obsolete 1912 2233 1913 Use QModelIndex QAbstractItemModel::createIndex(int row, int column, quint32 id) instead. 2234 Use QModelIndex 2235 QAbstractItemModel::createIndex(int row, int column, quint32 id) instead. 1914 2236 */ 1915 2237 … … 1922 2244 This function provides a consistent interface that model subclasses must 1923 2245 use to create model indexes. 2246 1924 2247 \sa QModelIndex::internalId() 1925 2248 */ … … 2025 2348 Begins a row insertion operation. 2026 2349 2027 When reimplementing insertRows() in a subclass, you must call this 2028 function \e before inserting data into the model's underlying data 2029 store. 2030 2031 The \a parent index corresponds to the parent into which the new 2032 rows are inserted; \a first and \a last are the row numbers that the 2033 new rows will have after they have been inserted. 2350 When reimplementing insertRows() in a subclass, you must call this function 2351 \e before inserting data into the model's underlying data store. 2352 2353 The \a parent index corresponds to the parent into which the new rows are 2354 inserted; \a first and \a last are the row numbers that the new rows will 2355 have after they have been inserted. 2034 2356 2035 2357 \table 80% 2036 \row \o \inlineimage modelview-begin-insert-rows.png Inserting rows2037 \o Specify the first and last row numbers for the span of rows2038 you want to insert into an item in a model.2039 2040 For example, as shown in the diagram, we insert three rows before2041 row 2, so \a first is 2 and \a last is 4:2042 \snippet doc/src/snippets/code/src_corelib_kernel_qabstractitemmodel.cpp 02043 This inserts the three new rows as rows 2, 3, and 4.2044 2358 \row 2045 \o \inlineimage modelview-begin-append-rows.png Appending rows 2046 \o To append rows, insert them after the last row. 2047 2048 For example, as shown in the diagram, we append two rows to a 2049 collection of 4 existing rows (ending in row 3), so \a first is 4 2050 and \a last is 5: 2051 \snippet doc/src/snippets/code/src_corelib_kernel_qabstractitemmodel.cpp 1 2052 This appends the two new rows as rows 4 and 5. 2359 \o \inlineimage modelview-begin-insert-rows.png Inserting rows 2360 \o Specify the first and last row numbers for the span of rows you 2361 want to insert into an item in a model. 2362 2363 For example, as shown in the diagram, we insert three rows before 2364 row 2, so \a first is 2 and \a last is 4: 2365 2366 \snippet doc/src/snippets/code/src_corelib_kernel_qabstractitemmodel.cpp 0 2367 2368 This inserts the three new rows as rows 2, 3, and 4. 2369 \row 2370 \o \inlineimage modelview-begin-append-rows.png Appending rows 2371 \o To append rows, insert them after the last row. 2372 2373 For example, as shown in the diagram, we append two rows to a 2374 collection of 4 existing rows (ending in row 3), so \a first is 4 2375 and \a last is 5: 2376 2377 \snippet doc/src/snippets/code/src_corelib_kernel_qabstractitemmodel.cpp 1 2378 2379 This appends the two new rows as rows 4 and 5. 2053 2380 \endtable 2054 2381 2382 2383 2384 2055 2385 \sa endInsertRows() 2056 2386 */ … … 2068 2398 Ends a row insertion operation. 2069 2399 2070 When reimplementing insertRows() in a subclass, you must call this 2071 function \e after inserting data into the model's underlying data 2072 store. 2400 When reimplementing insertRows() in a subclass, you must call this function 2401 \e after inserting data into the model's underlying data store. 2073 2402 2074 2403 \sa beginInsertRows() … … 2086 2415 2087 2416 When reimplementing removeRows() in a subclass, you must call this 2088 function \e before removing data from the model's underlying data 2089 store. 2090 2091 The \a parent index corresponds to the parent from which the new 2092 rows are removed; \a first and \a last are the row numbers of the 2093 rows to be removed. 2417 function \e before removing data from the model's underlying data store. 2418 2419 The \a parent index corresponds to the parent from which the new rows are 2420 removed; \a first and \a last are the row numbers of the rows to be 2421 removed. 2094 2422 2095 2423 \table 80% 2096 \row \o \inlineimage modelview-begin-remove-rows.png Removing rows 2097 \o Specify the first and last row numbers for the span of rows 2098 you want to remove from an item in a model. 2099 2100 For example, as shown in the diagram, we remove the two rows from 2101 row 2 to row 3, so \a first is 2 and \a last is 3: 2102 \snippet doc/src/snippets/code/src_corelib_kernel_qabstractitemmodel.cpp 2 2424 \row 2425 \o \inlineimage modelview-begin-remove-rows.png Removing rows 2426 \o Specify the first and last row numbers for the span of rows you 2427 want to remove from an item in a model. 2428 2429 For example, as shown in the diagram, we remove the two rows from 2430 row 2 to row 3, so \a first is 2 and \a last is 3: 2431 2432 \snippet doc/src/snippets/code/src_corelib_kernel_qabstractitemmodel.cpp 2 2103 2433 \endtable 2434 2435 2436 2437 2104 2438 2105 2439 \sa endRemoveRows() … … 2118 2452 Ends a row removal operation. 2119 2453 2120 When reimplementing removeRows() in a subclass, you must call this 2121 function \e after removing data from the model's underlying data 2122 store. 2454 When reimplementing removeRows() in a subclass, you must call this function 2455 \e after removing data from the model's underlying data store. 2123 2456 2124 2457 \sa beginRemoveRows() … … 2133 2466 2134 2467 /*! 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2135 2582 Begins a column insertion operation. 2136 2583 2137 2584 When reimplementing insertColumns() in a subclass, you must call this 2138 function \e before inserting data into the model's underlying data 2139 store. 2140 2141 The \a parent index corresponds to the parent into which the new 2142 columns are inserted; \a first and \a last are the column numbers of 2143 the new columns will have after they have been inserted. 2585 function \e before inserting data into the model's underlying data store. 2586 2587 The \a parent index corresponds to the parent into which the new columns 2588 are inserted; \a first and \a last are the column numbers of the new 2589 columns will have after they have been inserted. 2144 2590 2145 2591 \table 80% 2146 \row \o \inlineimage modelview-begin-insert-columns.png Inserting columns2147 \o Specify the first and last column numbers for the span of columns2148 you want to insert into an item in a model.2149 2150 For example, as shown in the diagram, we insert three columns before2151 column 4, so \a first is 4 and \a last is 6:2152 \snippet doc/src/snippets/code/src_corelib_kernel_qabstractitemmodel.cpp 32153 This inserts the three new columns as columns 4, 5, and 6.2154 2592 \row 2155 \o \inlineimage modelview-begin-append-columns.png Appending columns 2156 \o To append columns, insert them after the last column. 2157 2158 For example, as shown in the diagram, we append three columns to a 2159 collection of six existing columns (ending in column 5), so \a first 2160 is 6 and \a last is 8: 2161 \snippet doc/src/snippets/code/src_corelib_kernel_qabstractitemmodel.cpp 4 2162 This appends the two new columns as columns 6, 7, and 8. 2593 \o \inlineimage modelview-begin-insert-columns.png Inserting columns 2594 \o Specify the first and last column numbers for the span of columns 2595 you want to insert into an item in a model. 2596 2597 For example, as shown in the diagram, we insert three columns 2598 before column 4, so \a first is 4 and \a last is 6: 2599 2600 \snippet doc/src/snippets/code/src_corelib_kernel_qabstractitemmodel.cpp 3 2601 2602 This inserts the three new columns as columns 4, 5, and 6. 2603 \row 2604 \o \inlineimage modelview-begin-append-columns.png Appending columns 2605 \o To append columns, insert them after the last column. 2606 2607 For example, as shown in the diagram, we append three columns to a 2608 collection of six existing columns (ending in column 5), so 2609 \a first is 6 and \a last is 8: 2610 2611 \snippet doc/src/snippets/code/src_corelib_kernel_qabstractitemmodel.cpp 4 2612 2613 This appends the two new columns as columns 6, 7, and 8. 2163 2614 \endtable 2615 2616 2617 2618 2164 2619 2165 2620 \sa endInsertColumns() … … 2196 2651 2197 2652 When reimplementing removeColumns() in a subclass, you must call this 2198 function \e before removing data from the model's underlying data 2199 store. 2200 2201 The \a parent index corresponds to the parent from which the new 2202 columns are removed; \a first and \a last are the column numbers of 2203 the first and last columns to be removed. 2653 function \e before removing data from the model's underlying data store. 2654 2655 The \a parent index corresponds to the parent from which the new columns 2656 are removed; \a first and \a last are the column numbers of the first and 2657 last columns to be removed. 2204 2658 2205 2659 \table 80% 2206 \row \o \inlineimage modelview-begin-remove-columns.png Removing columns 2207 \o Specify the first and last column numbers for the span of columns 2208 you want to remove from an item in a model. 2209 2210 For example, as shown in the diagram, we remove the three columns 2211 from column 4 to column 6, so \a first is 4 and \a last is 6: 2212 \snippet doc/src/snippets/code/src_corelib_kernel_qabstractitemmodel.cpp 5 2660 \row 2661 \o \inlineimage modelview-begin-remove-columns.png Removing columns 2662 \o Specify the first and last column numbers for the span of columns 2663 you want to remove from an item in a model. 2664 2665 For example, as shown in the diagram, we remove the three columns 2666 from column 4 to column 6, so \a first is 4 and \a last is 6: 2667 2668 \snippet doc/src/snippets/code/src_corelib_kernel_qabstractitemmodel.cpp 5 2213 2669 \endtable 2670 2671 2672 2673 2214 2674 2215 2675 \sa endRemoveColumns() … … 2229 2689 2230 2690 When reimplementing removeColumns() in a subclass, you must call this 2231 function \e after removing data from the model's underlying data 2232 store. 2691 function \e after removing data from the model's underlying data store. 2233 2692 2234 2693 \sa beginRemoveColumns() … … 2243 2702 2244 2703 /*! 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2245 2786 Resets the model to its original state in any attached views. 2246 2787 2247 \note The view to which the model is attached to will be reset as well. 2248 2249 When a model is reset it means that any previous data reported from the 2250 model is now invalid and has to be queried for again. 2251 2252 When a model radically changes its data it can sometimes be easier to just 2253 call this function rather than emit dataChanged() to inform other 2254 components when the underlying data source, or its structure, has changed. 2255 2256 \sa modelAboutToBeReset(), modelReset() 2788 \note Use beginResetModel() and endResetModel() instead whenever possible. 2789 Use this method only if there is no way to call beginResetModel() before invalidating the model. 2790 Otherwise it could lead to unexcpected behaviour, especially when used with proxy models. 2257 2791 */ 2258 2792 void QAbstractItemModel::reset() … … 2265 2799 2266 2800 /*! 2267 Changes the QPersistentModelIndex that is equal to the given \a from 2268 model index to the given \a to model index. 2269 2270 If no persistent model index equal to the given \a from model index was 2271 found, nothing is changed. 2272 2273 \sa persistentIndexList(), changePersistentIndexList() 2801 Begins a model reset operation. 2802 2803 A reset operation resets the model to its current state in any attached views. 2804 2805 \note Any views attached to this model will be reset as well. 2806 2807 When a model is reset it means that any previous data reported from the 2808 model is now invalid and has to be queried for again. This also means that 2809 the current item and any selected items will become invalid. 2810 2811 When a model radically changes its data it can sometimes be easier to just 2812 call this function rather than emit dataChanged() to inform other 2813 components when the underlying data source, or its structure, has changed. 2814 2815 You must call this function before resetting any internal data structures in your model 2816 or proxy model. 2817 2818 \sa modelAboutToBeReset(), modelReset(), endResetModel() 2819 \since 4.6 2820 */ 2821 void QAbstractItemModel::beginResetModel() 2822 { 2823 emit modelAboutToBeReset(); 2824 } 2825 2826 /*! 2827 Completes a model reset operation. 2828 2829 You must call this function after resetting any internal data structure in your model 2830 or proxy model. 2831 2832 \sa beginResetModel() 2833 \since 4.6 2834 */ 2835 void QAbstractItemModel::endResetModel() 2836 { 2837 Q_D(QAbstractItemModel); 2838 d->invalidatePersistentIndexes(); 2839 emit modelReset(); 2840 } 2841 2842 /*! 2843 Changes the QPersistentModelIndex that is equal to the given \a from model 2844 index to the given \a to model index. 2845 2846 If no persistent model index equal to the given \a from model index was 2847 found, nothing is changed. 2848 2849 \sa persistentIndexList(), changePersistentIndexList() 2274 2850 */ 2275 2851 void QAbstractItemModel::changePersistentIndex(const QModelIndex &from, const QModelIndex &to) … … 2292 2868 2293 2869 /*! 2294 \since 4.12295 2296 Changes the QPersistentModelIndexes that is equal to the indexes in the given \a from2297 model index list to the given \a to model index list.2298 2299 If no persistent model indexes equal to the indexes in the given \a from model index list2300 was found, nothing is changed.2301 2302 \sa persistentIndexList(), changePersistentIndex()2870 \since 4.1 2871 2872 2873 model index list to the given \a to model index list. 2874 2875 2876 was found, nothing is changed. 2877 2878 \sa persistentIndexList(), changePersistentIndex() 2303 2879 */ 2304 2880 void QAbstractItemModel::changePersistentIndexList(const QModelIndexList &from, … … 2333 2909 2334 2910 /*! 2335 \since 4.22336 2337 Returns the list of indexes stored as persistent indexes in the model.2911 \since 4.2 2912 2913 Returns the list of indexes stored as persistent indexes in the model. 2338 2914 */ 2339 2915 QModelIndexList QAbstractItemModel::persistentIndexList() const … … 2362 2938 2363 2939 Since the model provides a more specialized interface than 2364 QAbstractItemModel, it is not suitable for use with tree views, although 2365 it can be used to provide data to a QListView. If you need to represent2366 a simple list of items, and only need a model to contain a single column2367 ofdata, subclassing the QAbstractListModel may be more appropriate.2940 QAbstractItemModel, it is not suitable for use with tree views, although 2941 2942 2943 data, subclassing the QAbstractListModel may be more appropriate. 2368 2944 2369 2945 The rowCount() and columnCount() functions return the dimensions of the … … 2372 2948 2373 2949 \section1 Subclassing 2374 2375 \bold{Note:} Some general guidelines for subclassing models are2376 available in the \l{Model Subclassing Reference}.2377 2950 2378 2951 When subclassing QAbstractTableModel, you must implement rowCount(), … … 2406 2979 \endlist 2407 2980 2408 \sa {Model Classes}, {Model Subclassing Reference}, QAbstractItemModel, 2409 QAbstractListModel, 2410 {Pixelator Example} 2981 \note Some general guidelines for subclassing models are available in the 2982 \l{Model Subclassing Reference}. 2983 2984 \note 2985 2986 \sa {Model Classes}, QAbstractItemModel, QAbstractListModel, 2987 {Pixelator Example} 2411 2988 */ 2412 2989 … … 2505 3082 2506 3083 \section1 Subclassing 2507 2508 \bold{Note:} Some general guidelines for subclassing models are2509 available in the \l{Model Subclassing Reference}.2510 3084 2511 3085 When subclassing QAbstractListModel, you must provide implementations … … 2534 3108 call endRemoveRows() \e{immediately afterwards}. 2535 3109 \endlist 3110 3111 3112 2536 3113 2537 3114 \sa {Model Classes}, {Model Subclassing Reference}, QAbstractItemView, … … 2730 3307 state (e.g. persistent model indexes) has been invalidated. 2731 3308 2732 \sa reset(), modelReset()3309 \sa (), modelReset() 2733 3310 */ 2734 3311 … … 2740 3317 state (e.g. persistent model indexes) has been invalidated. 2741 3318 2742 \sa reset(), modelAboutToBeReset()3319 \sa (), modelAboutToBeReset() 2743 3320 */ 2744 3321
Note:
See TracChangeset
for help on using the changeset viewer.