- Timestamp:
- May 5, 2011, 5:36:53 AM (14 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
- Property svn:mergeinfo changed
/branches/vendor/nokia/qt/4.7.2 (added) merged: 845 /branches/vendor/nokia/qt/current merged: 844 /branches/vendor/nokia/qt/4.6.3 removed
- Property svn:mergeinfo changed
-
trunk/doc/src/frameworks-technologies/model-view-programming.qdoc
r651 r846 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation (qt-info@nokia.com) … … 7 7 ** This file is part of the documentation of the Qt Toolkit. 8 8 ** 9 ** $QT_BEGIN_LICENSE: LGPL$9 ** $QT_BEGIN_LICENSE:FDL$ 10 10 ** Commercial Usage 11 11 ** Licensees holding valid Qt Commercial licenses may use this file in 12 12 ** accordance with the Qt Commercial License Agreement provided with the 13 ** Software or, alternatively, in accordance with the terms contained in 14 ** awritten agreement between you and Nokia.13 ** Software or, alternatively, in accordance with the terms contained in a 14 ** written agreement between you and Nokia. 15 15 ** 16 ** GNU Lesser General Public License Usage 17 ** Alternatively, this file may be used under the terms of the GNU Lesser 18 ** General Public License version 2.1 as published by the Free Software 19 ** Foundation and appearing in the file LICENSE.LGPL included in the 20 ** packaging of this file. Please review the following information to 21 ** ensure the GNU Lesser General Public License version 2.1 requirements 22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 23 ** 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 ** 28 ** GNU General Public License Usage 29 ** Alternatively, this file may be used under the terms of the GNU 30 ** General Public License version 3.0 as published by the Free Software 31 ** Foundation and appearing in the file LICENSE.GPL included in the 32 ** packaging of this file. Please review the following information to 33 ** ensure the GNU General Public License version 3.0 requirements will be 34 ** met: http://www.gnu.org/copyleft/gpl.html. 16 ** GNU Free Documentation License 17 ** Alternatively, this file may be used under the terms of the GNU Free 18 ** Documentation License version 1.3 as published by the Free Software 19 ** Foundation and appearing in the file included in the packaging of this 20 ** file. 35 21 ** 36 22 ** If you have questions regarding the use of this file, please contact … … 47 33 /*! 48 34 \page model-view-programming.html 49 \nextpage An Introduction to Model/View Programming 50 \startpage index.html Qt Reference Documentation 35 \ingroup qt-basic-concepts 51 36 52 37 \title Model/View Programming 53 \brief A guide to the extensible model/view architecture used by Qt's 54 item view classes. 55 56 \ingroup frameworks-technologies 57 58 \list 59 \o \l{An Introduction to Model/View Programming} 60 \tableofcontents{1 An Introduction to Model/View Programming} 61 \o \l{Using Models and Views} 62 \tableofcontents{1 Using Models and Views} 63 \o \l{Model Classes} 64 \tableofcontents{1 Model Classes} 65 \o \l{Creating New Models} 66 \tableofcontents{1 Creating New Models} 67 \o \l{View Classes} 68 \tableofcontents{1 View Classes} 69 \o \l{Handling Selections in Item Views} 70 \tableofcontents{1 Handling Selections in Item Views} 71 \o \l{Delegate Classes} 72 \tableofcontents{1 Delegate Classes} 73 \o \l{Item View Convenience Classes} 74 \tableofcontents{1 Item View Convenience Classes} 75 \o \l{Using Drag and Drop with Item Views} 76 \tableofcontents{1 Using Drag and Drop with Item Views} 77 \o \l{Proxy Models} 78 \tableofcontents{1 Proxy Models} 79 \o \l{Model Subclassing Reference} 80 \tableofcontents{1 Model Subclassing Reference} 81 \endlist 82 83 \keyword Model/View Classes 84 \section1 All Model/View Classes 85 86 These classes use the model/view design pattern in which the 87 underlying data (in the model) is kept separate from the way the data 88 is presented and manipulated by the user (in the view). 89 90 \annotatedlist model-view 91 92 \section1 Related Examples 93 94 \list 95 \o \l{itemviews/dirview}{Dir View} 96 \o \l{itemviews/spinboxdelegate}{Spin Box Delegate} 97 \o \l{itemviews/pixelator}{Pixelator} 98 \o \l{itemviews/simpletreemodel}{Simple Tree Model} 99 \o \l{itemviews/chart}{Chart} 100 \endlist 101 */ 102 103 /*! 104 \page model-view-introduction.html 105 \previouspage Model/View Programming 106 \nextpage Using Models and Views 107 \startpage index.html Qt Reference Documentation 108 109 \title An Introduction to Model/View Programming 110 111 \tableofcontents 112 113 Qt 4 introduces a new set of item view classes that use a model/view 38 \brief A guide to Qt's extensible model/view architecture. 39 40 \section1 Introduction to Model/View Programming 41 42 Qt 4 introduced a new set of item view classes that use a model/view 114 43 architecture to manage the relationship between data and the way it 115 44 is presented to the user. The separation of functionality introduced by … … 122 51 and examples are given that show how to use the classes provided. 123 52 124 \section 1 The Model/View Architecture53 \section2 The model/view architecture 125 54 126 55 Model-View-Controller (MVC) is a design pattern originating from … … 186 115 \endlist 187 116 188 \section 2Models117 \section3 Models 189 118 190 119 All item models are based on the QAbstractItemModel class. This class … … 226 155 your own custom models. 227 156 228 \section 2Views157 \section3 Views 229 158 230 159 Complete implementations are provided for different kinds of … … 238 167 The available views are examined in the section on \l{View Classes}. 239 168 240 \section 2Delegates169 \section3 Delegates 241 170 242 171 QAbstractItemDelegate is the abstract base class for delegates in the … … 252 181 Delegates are described in the section on \l{Delegate Classes}. 253 182 254 \section 2Sorting183 \section3 Sorting 255 184 256 185 There are two ways of approaching sorting in the model/view … … 273 202 in the section on \l {Proxy Models}. 274 203 275 \section 2 Convenience Classes204 \section3 Convenience classes 276 205 277 206 A number of \e convenience classes are derived from the standard view … … 294 223 QStandardItemModel. 295 224 296 \section1 The Model/View Components 297 298 The following sections describe the way in which the model/view pattern 299 is used in Qt. Each section provides an example of use, and is followed 300 by a section showing how you can create new components. 301 */ 302 303 /*! 304 \page model-view-using.html 305 \contentspage model-view-programming.html Contents 306 \previouspage An Introduction to Model/View Programming 307 \nextpage Model Classes 308 309 \title Using Models and Views 310 311 \tableofcontents 312 313 \section1 Introduction 225 \section1 Using models and views 226 227 The following sections explain how to use the model/view pattern 228 in Qt. Each section includes an an example and is followed by a 229 section showing how to create new components. 230 231 \section2 Two models included in Qt 314 232 315 233 Two of the standard models provided by Qt are QStandardItemModel and … … 326 244 manipulate data using model indexes. 327 245 328 \section 1 Using Views with an Existing Model246 \section2 Using views with an existing model 329 247 330 248 The QListView and QTreeView classes are the most suitable views … … 362 280 The \c index() function used in this case is unique to QFileSystemModel; we 363 281 supply it with a directory and it returns a model index. Model indexes are 364 discussed in the \l{Model Classes} chapter.282 discussed in \l{Model Classes}. 365 283 366 284 The rest of the function just displays the views within a splitter … … 370 288 371 289 In the above example, we neglected to mention how to handle selections 372 of items. This subject is covered in more detail in the chapter on 373 \l{Handling Selections in Item Views}. Before examining how selections 374 are handled, you may find it useful to read the \l{Model Classes} chapter 375 which describes the concepts used in the model/view framework. 376 */ 377 378 /*! 379 \page model-view-model.html 380 \contentspage model-view-programming.html Contents 381 \previouspage Using Models and Views 382 \nextpage Creating New Models 383 384 \title Model Classes 385 386 \tableofcontents 387 388 \section1 Basic Concepts 290 of items. This subject is covered in more detail in the section about 291 \l{Handling Selections in Item Views}. 292 293 \section1 Model classes 294 295 Before examining how selections are handled, you may find it 296 useful to examine the concepts used in the model/view framework. 297 298 \section2 Basic concepts 389 299 390 300 In the model/view architecture, the model provides a standard interface … … 402 312 signals and slots mechanism. 403 313 404 This chapterdescribes some basic concepts that are central to the way314 This section describes some basic concepts that are central to the way 405 315 item of data are accessed by other components via a model class. More 406 advanced concepts are discussed in later chapters.407 408 \section 2 Model Indexes316 advanced concepts are discussed in later sections. 317 318 \section3 Model indexes 409 319 410 320 To ensure that the representation of the data is kept separate from the … … 436 346 and explain these properties in detail. 437 347 438 \section 2 Rows and Columns348 \section3 Rows and columns 439 349 440 350 In its most basic form, a model can be accessed as a simple table in which … … 469 379 \endtable 470 380 471 \section 2 Parents of Items381 \section3 Parents of items 472 382 473 383 The table-like interface to item data provided by models is ideal when … … 502 412 \endtable 503 413 504 \section 2 Item Roles414 \section3 Item roles 505 415 506 416 Items in a model can perform various \e roles for other components, … … 535 445 define additional roles for application-specific purposes. 536 446 537 \section 2 Summary of Concepts447 \section3 Summary 538 448 539 449 \list … … 547 457 \o If a valid model index is specified for the parent item when an index is 548 458 requested using \l{QAbstractItemModel::index()}{index()}, the index 549 returned will refer to an item beneath that parent item in the 550 model. 459 returned refers to an item beneath that parent item in the model. 551 460 The index obtained refers to a child of that item. 552 461 \o If an invalid model index is specified for the parent item when an index 553 462 is requested using \l{QAbstractItemModel::index()}{index()}, the index 554 returned will referto a top-level item in the model.463 returned refers to a top-level item in the model. 555 464 \o The \l{Qt::ItemDataRole}{role} distinguishes between the 556 465 different kinds of data associated with an item. 557 466 \endlist 558 467 559 \section2 Using Model Indexes468 \section2 Using model indexes 560 469 561 470 To demonstrate how data can be retrieved from a model, using model … … 611 520 \endlist 612 521 613 614 \section1 Further Reading 615 616 New models can be created by implementing the standard interface provided 617 by QAbstractItemModel. In the \l{Creating New Models} chapter, we will 618 demonstrate this by creating a convenient ready-to-use model for holding 619 lists of strings. 620 */ 621 622 /*! 623 \page model-view-view.html 624 \contentspage model-view-programming.html Contents 625 \previouspage Creating New Models 626 \nextpage Handling Selections in Item Views 627 628 \title View Classes 629 630 \tableofcontents 631 632 \section1 Concepts 522 \section2 Further reading 523 524 New models can be created by implementing the standard interface 525 provided by QAbstractItemModel. In the \l{Creating New Models} 526 section, we demonstrate this by creating a convenient ready-to-use 527 model for holding lists of strings. 528 529 \section1 View classes 530 531 \section2 Concepts 633 532 634 533 In the model/view architecture, the view obtains items of data from the … … 669 568 labels for views. 670 569 671 \section 1 Using an Existing View570 \section2 Using an existing view 672 571 673 572 Qt provides three ready-to-use view classes that present data from … … 687 586 user interfaces. 688 587 689 \section 2 Using a Model588 \section3 Using a model 690 589 691 590 We take the string list model that \l{Creating New Models}{we created as … … 698 597 Note that the \c StringListModel is declared as a \l QAbstractItemModel. 699 598 This allows us to use the abstract interface to the model, and 700 ensures that the code will still workeven if we replace the string list701 model with a different model in the future.599 ensures that the code still works, even if we replace the string list 600 model with a different model. 702 601 703 602 The list view provided by \l QListView is sufficient for presenting … … 722 621 each item in the list to be edited using the default delegate. 723 622 724 \section 2 Using Multiple Views onto the Same Model623 \section3 Using multiple views of a model 725 624 726 625 Providing multiple views onto the same model is simply a matter of … … 746 645 many applications, a shared selection model is desirable. 747 646 748 \section 1 Handling Selections of Items647 \section2 Handling selections of items 749 648 750 649 The mechanism for handling selections of items within views is provided … … 759 658 data. 760 659 761 Generally, unless you are subclassing a model or view, you will not 762 need to manipulate the contents of selections directly. However, the 763 interface to the selection model can be accessed, if required, and 764 this is explored in the chapter on 765 \l{Handling Selections in Item Views}. 766 767 \section2 Sharing Selections Between Views 660 Generally, unless you are subclassing a model or view, you don't 661 need to manipulate the contents of selections directly. However, 662 the interface to the selection model can be accessed, if required, 663 and this is explored in \l{Handling Selections in Item Views}. 664 665 \section3 Sharing selections among views 768 666 769 667 Although it is convenient that the view classes provide their own … … 789 687 represented as a fragmented set of highlighted items in a tree view. 790 688 791 */ 792 793 /*! 794 \page model-view-delegate.html 795 \contentspage model-view-programming.html Contents 796 \previouspage Handling Selections in Item Views 797 \nextpage Item View Convenience Classes 798 799 \title Delegate Classes 800 801 \tableofcontents 802 803 \section1 Concepts 689 \section1 Delegate classes 690 691 \section2 Concepts 804 692 805 693 Unlike the Model-View-Controller pattern, the model/view design does not … … 822 710 Editors for delegates can be implemented either by using widgets to manage 823 711 the editing process or by handling events directly. 824 The first approach is covered later in this chapter, and it is also712 The first approach is covered later in this section, and it is also 825 713 shown in the \l{Spin Box Delegate Example}{Spin Box Delegate} example. 826 714 … … 828 716 custom delegate that performs specialized rendering for a table view. 829 717 830 \section 1 Using an Existing Delegate718 \section2 Using an existing delegate 831 719 832 720 The standard views provided with Qt use instances of \l QItemDelegate … … 846 734 view. 847 735 848 \section 1 A Simple Delegate849 850 The delegate implemented here uses a \l QSpinBox to provide editing851 facilities, and is mainly intended for use with models that display852 integers. Although we set up a custom integer-based table model for853 t his purpose, we could easily have used \l QStandardItemModel instead854 since the custom delegate will control data entry. We construct a855 table view to display the contents of the model, and this will use856 the custom delegate for editing.736 \section2 A simple delegate 737 738 The delegate implemented here uses a \l QSpinBox to provide 739 editing facilities, and is mainly intended for use with models 740 that display integers. Although we set up a custom integer-based 741 table model for this purpose, we could easily have used \l 742 QStandardItemModel instead, since the custom delegate controls 743 data entry. We construct a table view to display the contents of 744 the model, and this will use the custom delegate for editing. 857 745 858 746 \img spinboxdelegate-example.png … … 867 755 constructed. We only construct an editor widget when it is needed. 868 756 869 \section 2 Providing an Editor757 \section3 Providing an editor 870 758 871 759 In this example, when the table view needs to provide an editor, it … … 907 795 appropriate type before accessing its member functions. 908 796 909 \section 2 Submitting Data to the Model797 \section3 Submitting data to the model 910 798 911 799 When the user has finished editing the value in the spin box, the view … … 936 824 provides sensible default values for unexpected data. 937 825 938 \section 2 Updating the Editor's Geometry826 \section3 Updating the editor's geometry 939 827 940 828 It is the responsibility of the delegate to manage the editor's … … 952 840 953 841 \target EditingHints 954 \section 2 Editing Hints842 \section3 Editing hints 955 843 956 844 After editing, delegates should provide hints to the other components … … 983 871 be less integrated into applications, and will be less usable than 984 872 those that emit hints to support common editing actions. 985 */ 986 987 /*! 988 \page model-view-selection.html 989 \contentspage model-view-programming.html Contents 990 \previouspage View Classes 991 \nextpage Delegate Classes 992 993 \title Handling Selections in Item Views 994 995 \tableofcontents 996 997 \section1 Concepts 873 874 \section1 Handling selections in item views 875 876 \section2 Concepts 998 877 999 878 The selection model used in the item view classes offers many improvements … … 1023 902 commands. These are discussed later in this section. 1024 903 1025 1026 \section2 Current Item and Selected Items 904 \section3 Current item and selected items 1027 905 1028 906 In a view, there is always a current item and a selected item - two … … 1069 947 mechanism. 1070 948 1071 1072 \section1 Using a Selection Model 949 \section2 Using a selection model 1073 950 1074 951 The standard view classes provide default selection models that can … … 1089 966 selection model. 1090 967 1091 1092 \section2 Selecting Items 968 \section3 Selecting items 1093 969 1094 970 To demonstrate some of the principal features of selections, we construct … … 1123 999 The selection of items can be modified using various operations that 1124 1000 are defined by the selection flags. The selection that results from 1125 these operations may have a complex structure, but will berepresented1001 these operations may have a complex structure, but it is represented 1126 1002 efficiently by the selection model. The use of different selection 1127 1003 flags to manipulate the selected items is described when we examine 1128 1004 how to update a selection. 1129 1005 1130 \section 2 Reading the Selection State1006 \section3 Reading the selection state 1131 1007 1132 1008 The model indexes stored in the selection model can be read using … … 1137 1013 \snippet doc/src/snippets/reading-selections/window.cpp 0 1138 1014 1139 The above code uses Qt's convenient \l{ Generic Containers}{foreach1015 The above code uses Qt's convenient \l{Container Classes}{foreach 1140 1016 keyword} to iterate over, and modify, the items corresponding to the 1141 1017 indexes returned by the selection model. … … 1177 1053 signals, but we can also update the selection model directly. 1178 1054 1179 \section 2 Updating a Selection1055 \section3 Updating a selection 1180 1056 1181 1057 Selection commands are provided by a combination of selection flags, … … 1216 1092 \l{QItemSelectionModel::SelectionFlag}{Select} and 1217 1093 \l{QItemSelectionModel::SelectionFlag}{Rows}, the 1218 entire row containing the item referred to will beselected.1094 entire row containing the item referred to is selected. 1219 1095 The following code demonstrates the use of the 1220 1096 \l{QItemSelectionModel::SelectionFlag}{Rows} and … … 1249 1125 indexes. 1250 1126 1251 \section 2 Selecting All Items in a Model1127 \section3 Selecting all items in a model 1252 1128 1253 1129 To select all items in a model, it is necessary to create a … … 1272 1148 determine whether any given item is the parent of another level of 1273 1149 items. 1274 */ 1275 1276 /*! 1277 \page model-view-creating-models.html 1278 \contentspage model-view-programming.html Contents 1279 \previouspage Model Classes 1280 \nextpage View Classes 1281 1282 \title Creating New Models 1283 1284 \tableofcontents 1285 1286 \section1 Introduction 1150 1151 \section1 Creating new models 1287 1152 1288 1153 The separation of functionality between the model/view components allows … … 1302 1167 easier to use as a starting point for simple list and table models. 1303 1168 1304 In this chapter, we create a simple read-only model to explore1169 In this section, we create a simple read-only model to explore 1305 1170 the basic principles of the model/view architecture. Later in this 1306 chapter, we willadapt this simple model so that items can be modified1171 section, we adapt this simple model so that items can be modified 1307 1172 by the user. 1308 1173 … … 1313 1178 detail in the \l{Model Subclassing Reference} document. 1314 1179 1315 \section 1 Designing a Model1316 1317 When creating a new model for an existing data structure, it is important1318 to consider which type of model should be used to provide an interface1319 onto the data. If the data structure can be represented as a1320 list or table of items, you can subclass QAbstractListModel or1321 QAbstract TableModel since these classes provide suitable default1322 implementations for many functions.1323 1324 However, if the underlying data structure can only be represented by a1325 hierarchical tree structure, it is necessary to subclass1180 \section2 Designing a model 1181 1182 When creating a new model for an existing data structure, it is 1183 important to consider which type of model should be used to 1184 provide an interface onto the data. If the data structure can be 1185 represented as a list or table of items, you can subclass 1186 QAbstractListModel or QAbstractTableModel since these classes 1187 provide suitable default implementations for many functions. 1188 1189 However, if the underlying data structure can only be represented 1190 by a hierarchical tree structure, it is necessary to subclass 1326 1191 QAbstractItemModel. This approach is taken in the 1327 1192 \l{itemviews/simpletreemodel}{Simple Tree Model} example. 1328 1193 1329 In this chapter, we willimplement a simple model based on a list of1194 In this section, we implement a simple model based on a list of 1330 1195 strings, so the QAbstractListModel provides an ideal base class on 1331 1196 which to build. … … 1339 1204 provides a custom constructor for just this purpose. 1340 1205 1341 \section 1 A Read-Only Example Model1206 \section2 A read-only example model 1342 1207 1343 1208 The model implemented here is a simple, non-hierarchical, read-only data … … 1356 1221 interface. The class declaration is as follows: 1357 1222 1358 1359 1223 \snippet doc/src/snippets/stringlistmodel/model.h 0 1360 1224 \snippet doc/src/snippets/stringlistmodel/model.h 1 … … 1380 1244 member variable. 1381 1245 1382 \section 2 Dimensions of The Model1246 \section3 Dimensions of the model 1383 1247 1384 1248 We want the number of rows in the model to be the same as the number of … … 1395 1259 function. 1396 1260 1397 \section 2 Model Headers and Data1261 \section3 Model headers and data 1398 1262 1399 1263 For items in the view, we want to return the strings in the string list. … … 1434 1298 display information about items in a tooltip. 1435 1299 1436 \section 1 An Editable Model1300 \section2 An editable model 1437 1301 1438 1302 The read-only model shows how simple choices could be presented to the … … 1448 1312 \snippet doc/src/snippets/stringlistmodel/model.h 3 1449 1313 1450 \section 2 Making the Model Editable1314 \section3 Making the model editable 1451 1315 1452 1316 A delegate checks whether an item is editable before creating an … … 1474 1338 standard item delegate. For boolean values, however, you can use 1475 1339 Qt::CheckStateRole and set the Qt::ItemIsUserCheckable flag; a 1476 checkbox will then beused for editing the value. The underlying1340 checkbox is then used for editing the value. The underlying 1477 1341 data in this model is the same for all roles, so this detail just 1478 1342 makes it easier to integrate the model with standard components. … … 1488 1352 \snippet doc/src/snippets/stringlistmodel/model.cpp 1 1489 1353 1490 \section 2 Inserting and Removing Rows1354 \section3 Inserting and removing rows 1491 1355 1492 1356 It is possible to change the number of rows and columns in a model. In the … … 1537 1401 have changed. 1538 1402 1539 \section 1 Next Steps1403 \section2 Next steps 1540 1404 1541 1405 We can display the data provided by this model, or any other model, using … … 1544 1408 For the string list model, this view also provides a default editor so that 1545 1409 the items can be manipulated. We examine the possibilities made available by 1546 the standard view classes in the chapter on\l{View Classes}.1410 the standard view classes in \l{View Classes}. 1547 1411 1548 1412 The \l{Model Subclassing Reference} document discusses the requirements of … … 1550 1414 virtual functions that must be implemented to enable various features in 1551 1415 different types of models. 1552 */ 1553 1554 /*! 1555 \page model-view-convenience.html 1556 \contentspage model-view-programming.html Contents 1557 \previouspage Delegate Classes 1558 \nextpage Using Drag and Drop with Item Views 1559 1560 \title Item View Convenience Classes 1561 1562 \tableofcontents 1563 1564 \section1 Overview 1565 1566 Alongside the model/view classes, Qt 4 also includes standard widgets to 1567 provide classic item-based container widgets. These behave in a similar 1568 way to the item view classes in Qt 3, but have been rewritten to use the 1569 underlying model/view framework for performance and maintainability. The 1570 old item view classes are still available in the compatibility library 1571 (see the \l{porting4.html}{Porting Guide} for more information). 1416 1417 \section1 Item view convenience classes 1418 1419 Qt 4 also introduced some standard widgets to provide classic 1420 item-based container widgets. These behave in a similar way to the 1421 item view classes in Qt 3, but have been rewritten to use the 1422 underlying model/view framework for performance and 1423 maintainability. The old item view classes are still available in 1424 the compatibility library (see the \l{porting4.html}{Porting 1425 Guide} for more information). 1572 1426 1573 1427 The item-based widgets have been given names which reflect their uses: … … 1578 1432 management. 1579 1433 1580 \section 1 List Widgets1434 \section2 List widgets 1581 1435 1582 1436 Single level lists of items are typically displayed using a \c QListWidget … … 1613 1467 \snippet doc/src/snippets/qlistwidget-using/mainwindow.cpp 5 1614 1468 1615 1616 \section1 Tree Widgets 1469 \section2 Tree widgets 1617 1470 1618 1471 Trees or hierarchical lists of items are provided by the \c QTreeWidget … … 1669 1522 \snippet doc/src/snippets/qtreewidget-using/mainwindow.cpp 9 1670 1523 1671 1672 \section1 Table Widgets 1524 \section2 Table widgets 1673 1525 1674 1526 Tables of items similar to those found in spreadsheet applications … … 1694 1546 Note that the rows and columns in the table begin at zero. 1695 1547 1696 \section 1 Common Features1548 \section2 Common features 1697 1549 1698 1550 There are a number of item-based features common to each of the … … 1703 1555 for more details about the use of each function used. 1704 1556 1705 \section 2 Hidden Items1557 \section3 Hidden items 1706 1558 1707 1559 It is sometimes useful to be able to hide items in an item view widget … … 1714 1566 all three convenience classes. 1715 1567 1716 \section 2Selections1568 \section3 Selections 1717 1569 1718 1570 The way items are selected is controlled by the widget's selection mode … … 1765 1617 user formed the selection. 1766 1618 1767 \section 2Searching1619 \section3 Searching 1768 1620 1769 1621 It is often useful to be able to find items within an item view widget, … … 1783 1635 contain the text given in the search string. This pattern can also be 1784 1636 used in the list and table widgets. 1785 */ 1786 1787 /*! 1788 \page model-view-dnd.html 1789 \contentspage model-view-programming.html Contents 1790 \previouspage Item View Convenience Classes 1791 \nextpage Proxy Models 1792 1793 \title Using Drag and Drop with Item Views 1794 1795 \tableofcontents 1796 1797 \section1 Overview 1637 1638 \section1 Using Drag and Drop with Item Views 1798 1639 1799 1640 Qt's drag and drop infrastructure is fully supported by the model/view framework. … … 1814 1655 enabling drag and drop support in new models. 1815 1656 1816 \section 1 Using Convenience Views1657 \section2 Using convenience views 1817 1658 1818 1659 Each of the types of item used with QListWidget, QTableWidget, and QTreeWidget … … 1853 1694 \snippet doc/src/snippets/qlistwidget-dnd/mainwindow.cpp 1 1854 1695 1855 \section 1 Using Model/View Classes1696 \section2 Using model/view classes 1856 1697 1857 1698 Setting up a view for drag and drop follows the same pattern used with the … … 1875 1716 implementation from its base class. 1876 1717 1877 \section 2 Enabling Drag and Drop for Items1718 \section3 Enabling drag and drop for items 1878 1719 1879 1720 Models indicate to views which items can be dragged, and which will accept drops, … … 1895 1736 function. 1896 1737 1897 \section 2 Encoding Exported Data1738 \section3 Encoding exported data 1898 1739 1899 1740 When items of data are exported from a model in a drag and drop operation, they … … 1924 1765 class description for details. 1925 1766 1926 \section 2 Inserting Dropped Data into a Model1767 \section3 Inserting dropped data into a model 1927 1768 1928 1769 The way that any given model handles dropped data depends on both its type … … 1989 1830 appropriate. 1990 1831 1991 \section 2 Decoding Imported Data1832 \section3 Decoding imported data 1992 1833 1993 1834 Each implementation of \l{QAbstractItemModel::dropMimeData()}{dropMimeData()} must … … 2008 1849 2009 1850 \sa {Item Views Puzzle Example} 2010 */ 2011 2012 /*! 2013 \page model-view-proxy-models.html 2014 \contentspage model-view-programming.html Contents 2015 \previouspage Using Drag and Drop with Item Views 2016 \nextpage Model Subclassing Reference 2017 2018 \title Proxy Models 2019 2020 \tableofcontents 2021 2022 \section1 Overview 1851 1852 \section1 Proxy models 2023 1853 2024 1854 In the model/view framework, items of data supplied by a single model can be shared … … 2043 1873 are placed between itself and the source model. 2044 1874 2045 \section 1 Using Proxy Models1875 \section2 Using proxy models 2046 1876 2047 1877 Proxy models can be inserted between an existing model and any number of views. … … 2062 1892 classes and implementing the required comparison operations. 2063 1893 2064 \section 1 Customizing Proxy Models1894 \section2 Customizing proxy models 2065 1895 2066 1896 Generally, the type of processing used in a proxy model involves mapping each item of … … 2075 1905 be supplied to views as pre-sorted data. 2076 1906 2077 \section 2 Custom Filtering Models1907 \section3 Custom filtering models 2078 1908 2079 1909 The QSortFilterProxyModel class provides a filtering model that is fairly versatile, … … 2096 1926 of these functions should return false to filter out individual rows and columns. 2097 1927 2098 \section 2 Custom Sorting Models1928 \section3 Custom sorting models 2099 1929 2100 1930 QSortFilterProxyModel instances use Qt's built-in qStableSort() function to set up … … 2104 1934 \l{QSortFilterProxyModel::lessThan()}{lessThan()} function to perform custom 2105 1935 comparisons. 2106 */ 2107 2108 /*! 2109 \page model-view-model-subclassing.html 2110 \contentspage model-view-programming.html Contents 2111 \previouspage Proxy Models 2112 2113 \title Model Subclassing Reference 2114 2115 \tableofcontents 2116 2117 \section1 Introduction 1936 1937 \section1 Model subclassing reference 2118 1938 2119 1939 Model subclasses need to provide implementations of many of the virtual functions … … 2144 1964 {"Item View Classes" Chapter of C++ GUI Programming with Qt 4}. 2145 1965 2146 \section 1 Item Data Handling1966 \section2 Item data handling 2147 1967 2148 1968 Models can provide varying levels of access to the data they provide: They can be … … 2150 1970 others may allow items to be edited. 2151 1971 2152 \section2 Read-Only Access1972 \section2 Read-Only access 2153 1973 2154 1974 To provide read-only access to data provided by a model, the following functions … … 2186 2006 \endtable 2187 2007 2188 \section 2 Editable Items2008 \section3 Editable items 2189 2009 2190 2010 Editable models allow items of data to be modified, and may also provide … … 2212 2032 \endtable 2213 2033 2214 \section 2 Resizable Models2034 \section3 Resizable models 2215 2035 2216 2036 All types of model can support the insertion and removal of rows. Table models … … 2272 2092 signal to cause any attached views to be updated. 2273 2093 2274 \section 2 Lazy Population of Model Data2094 \section3 Lazy population of model data 2275 2095 2276 2096 Lazy population of model data effectively allows requests for information … … 2306 2126 attempts to view the non-existent child items. 2307 2127 2308 2309 \section1 Navigation and Model Index Creation 2128 \section2 Navigation and model index creation 2310 2129 2311 2130 Hierarchical models need to provide functions that views can call to navigate the 2312 2131 tree-like structures they expose, and obtain model indexes for items. 2313 2132 2314 \section 2 Parents and Children2133 \section3 Parents and children 2315 2134 2316 2135 Since the structure exposed to views is determined by the underlying data … … 2336 2155 the model index can be re-associated with its corresponding item later on. 2337 2156 2338 \section 1 Drag and Drop Support and MIME Type Handling2157 \section2 Drag and drop support and MIME type handling 2339 2158 2340 2159 The model/view classes support drag and drop operations, providing default behavior … … 2348 2167 behavior. 2349 2168 2350 \section 2 MIME Data2169 \section3 MIME data 2351 2170 2352 2171 By default, the built-in models and views use an internal MIME type … … 2395 2214 QMimeData::setHtml() functions. 2396 2215 2397 \section 2 Accepting Dropped Data2216 \section3 Accepting dropped data 2398 2217 2399 2218 When a drag and drop operation is performed over a view, the underlying model is … … 2465 2284 2466 2285 For more information about drag and drop with item views, refer to 2467 \l{Using Drag and Drop with Item Views}.2468 2469 \section 2 Convenience Views2286 \l{Using drag and drop with item views}. 2287 2288 \section3 Convenience views 2470 2289 2471 2290 The convenience views (QListWidget, QTableWidget, and QTreeWidget) override … … 2476 2295 will set the data of the target items rather than insert new rows and columns 2477 2296 into the model. For more information on drag and drop in convenience views, 2478 you can see \l{Using Drag and Drop with Item Views}.2479 2480 \section 1 Performance Optimization for Large Amounts of Data2297 you can see \l{Using drag and drop with item views}. 2298 2299 \section2 Performance optimization for large amounts of data 2481 2300 2482 2301 The \l{QAbstractItemModel::}{canFetchMore()} function checks if the parent … … 2499 2318 {fetchMore()} must be reimplemented as their default implementation returns 2500 2319 false and does nothing. 2320 2321 \keyword Model/View Classes 2322 \section1 The model/view classes 2323 2324 These classes use the model/view design pattern in which the 2325 underlying data (in the model) is kept separate from the way the 2326 data is presented and manipulated by the user (in the view). 2327 2328 \annotatedlist model-view 2329 2330 \section1 Related examples 2331 2332 \list 2333 \o \l{itemviews/dirview}{Dir View} 2334 \o \l{itemviews/spinboxdelegate}{Spin Box Delegate} 2335 \o \l{itemviews/pixelator}{Pixelator} 2336 \o \l{itemviews/simpletreemodel}{Simple Tree Model} 2337 \o \l{itemviews/chart}{Chart} 2338 \endlist 2501 2339 */
Note:
See TracChangeset
for help on using the changeset viewer.