/usr/include/Wt/WAbstractItemModel is in libwt-dev 3.3.3+dfsg-4.1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 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 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 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 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 | // This may look like C code, but it's really -*- C++ -*-
/*
* Copyright (C) 2008 Emweb bvba, Kessel-Lo, Belgium.
*
* See the LICENSE file for terms of use.
*/
#ifndef WABSTRACT_ITEM_MODEL_H_
#define WABSTRACT_ITEM_MODEL_H_
#include <Wt/WObject>
#include <Wt/WModelIndex>
#include <Wt/WSignal>
#include <Wt/WGlobal>
#include <boost/any.hpp>
#include <Wt/WBoostAny>
namespace Wt {
class WDropEvent;
/*! \class WAbstractItemModel Wt/WAbstractItemModel Wt/WAbstractItemModel
* \brief An abstract model for use with %Wt's view classes.
*
* This abstract model is used by several %Wt view widgets as data models.
*
* It may model data for both tree-like and table-like view
* widgets. Data is therefore organized in a hierarchical structure of
* tables, where every item stores data and items in column 0 can be
* the parent of a nested table of data. Every data item is uniquely
* identified by their row, column and parent index, and items may be
* referenced using the helper class WModelIndex.
*
* Each item may provide data for one or more \link Wt::ItemDataRole
* roles\endlink, and indicate options using \link Wt::ItemFlag
* flags\endlink. The different roles can be used to model different
* aspects of an item (its text value, an icon, style class), or to
* hold auxiliary custom information. The flags provide information to
* the View on possible interactivity.
*
* \if cpp
* Top level data have an \link WModelIndex::isValid() invalid\endlink
* parent WModelIndex.
* \endif
* \if java
* Top level data have a \c null parent WModelIndex.
* \endif
*
* \if cpp
* The data itself is of type <b>boost::any</b>, which can either be
* empty, or hold any type of data. Depending on the role however,
* view classes may expect certain types of data (e.g. a string for
* Wt::StyleClassRole).
*
* Wt's standard view classes can display (Wt::DisplayRole) the following data:
*
* - strings of type WString or std::string
* - WDate, WTime, WDateTime, WLocalDateTime
* - standard C++ numeric types (int, double, etc...)
* - bool
*
* The view classes know how to interpret data of these types \link
* Wt::asString() as a string\endlink or \link Wt::asNumber() as a
* number\endlink.
*
* \elseif java
*
* The data itself is of type Object, which can either be \c null, or be
* any type of data. Depending on the role however, view classes may
* expect certain types of data (e.g. numerical types for charts) or
* will convert the data to a string (e.g. for Wt::DisplayRole).
*
* \endif
*
* \if cpp
* Conversion between native types and boost::any is done like this:
* <ul>
* <li>Conversion from <i>v</i> (of type <i>Type</i>) to boost::any <i>a</i>
* (for setData() and setHeaderData())
* <pre>
* boost::any <i>a</i> = boost::any(<i>v</i>);
* </pre>
* For example:
* <pre>
* WDate d(1976,6,14);
* model->setData(row, column, boost::any(d));
* </pre>
*
* </li>
* <li>Conversion from boost::any <i>a</i> to <i>v</i> (of type <i>Type</i>)
(for data() and headerData()):
* <pre>
* <i>Type v</i> = boost::any_cast<<i>Type</i>>(<i>a</i>);
* </pre>
* For example:
* <pre>
* WDate d = boost::any_cast<WDate>(model->data(row, column));
* </pre>
* </li>
* <li>Checking if a boost::any <i>a</i> holds a value:</li>
* <pre>
* if (!<i>a</i>.empty()) {
* ...
* }
* </pre>
* </li>
* <li>Determining the value type of a boost::any <i>a</i>, for example:</li>
* <pre>
* if (<i>a</i>.type() == typeid(double)) {
* ...
* }
* </pre>
* </li>
* </ul>
*
* \endif
*
* To implement a custom model, you need to reimplement the following methods:
* - index() and parent() methods that allow one to navigate the model
* - columnCount() and rowCount() to specify the top level geometry and the
* nested geometry at every item
* - data() to return the data for an item
* - optionally, headerData() to return row and column header data
* - optionally, flags() to indicate data options
*
* \if cpp
* A crucial point in implementing a hierarchical model is to decide
* how to reference an index in terms of an internal pointer
* (WModelIndex::internalPointer()) or internal id
* (WModelIndex::internalId()). Other than the top-level index, which
* is special since it is referenced using an \link
* WModelIndex::isValid() invalid\endlink index, every index with
* children must be identifiable using this number or pointer. For
* example, in the WStandardItemModel, the internal pointer points to
* the parent WStandardItem. For table models, the internal pointer
* plays no role, since only the toplevel index has children.
* \elseif java
* A crucial point in implementing a hierarchical model is to decide
* how to reference an index in terms of an internal pointer
* (WModelIndex::internalPointer()).
* Other than the top-level index, which is special since it is
* referenced using an invalid index, every index with
* children must be identifiable using this object. For
* example, in the WStandardItemModel, the internal pointer points to
* the parent WStandardItem. For table models, the internal pointer
* plays no role, since only the toplevel index has children.
* \endif
*
* If you want to support editing of the model, then you need to
* indicate this support using a Wt::ItemIsEditable flag, and
* reimplement setData(). View classes will use the \link Wt::EditRole
* EditRole\endlink to read and update the data for the editor.
*
* When the model's data has been changed, the model must emit the
* dataChanged() signal.
*
* Finally, there is a generic interface for insertion of new data or
* removal of data (changing the geometry), although this interface is
* not yet used by any View class:
*
* - insertRows()
* - insertColumns()
* - removeRows()
* - removeColumns()
*
* Alternatively, you can provide your own API for changing the
* model. In either case it is important that you call the
* corresponding protected member functions which will emit the
* relevant signals so that views can adapt themselves to the new
* geometry.
*
* \ingroup modelview
*/
class WT_API WAbstractItemModel : public WObject
{
public:
/*! \brief Data map.
*
* A map of data, indexed by a role.
*/
#ifndef WT_TARGET_JAVA
typedef std::map<int, boost::any> DataMap;
#else
typedef std::treemap<int, boost::any> DataMap;
#endif
/*! \brief Creates a new data model.
*/
WAbstractItemModel(WObject *parent = 0);
virtual ~WAbstractItemModel();
/*! \brief Returns the number of columns.
*
* This returns the number of columns at index \p parent.
*
* \sa rowCount()
*/
virtual int columnCount(const WModelIndex& parent = WModelIndex()) const = 0;
/*! \brief Returns the number of rows.
*
* This returns the number of rows at index \p parent.
*
* \sa columnCount()
*/
virtual int rowCount(const WModelIndex& parent = WModelIndex()) const = 0;
// not yet used by views
virtual bool canFetchMore(const WModelIndex& parent) const;
// not yet used by views
virtual void fetchMore(const WModelIndex& parent);
/*! \brief Returns the flags for an item.
*
* The default implementation returns \link Wt::ItemIsSelectable
* ItemIsSelectable\endlink.
*
* \sa Wt::ItemFlag
*/
virtual WFlags<ItemFlag> flags(const WModelIndex& index) const;
/*! \brief Returns the flags for a header.
*
* The default implementation returns no flags set.
*
* \sa Wt::HeaderFlag
*/
virtual WFlags<HeaderFlag> headerFlags(int section,
Orientation orientation = Horizontal)
const;
/*! \brief Returns if there are children at an index.
*
* Returns \c true when rowCount(index) > 0 and columnCount(index) > 0.
*
* \sa rowCount(), columnCount()
*/
virtual bool hasChildren(const WModelIndex& index) const;
/*! \brief Returns the parent for a model index.
*
* An implementation should use createIndex() to create a model
* index that corresponds to the parent of a given index.
*
* Note that the index itself may be stale (referencing a row/column
* within the parent that is outside the model geometry), but its
* parent (identified by the WModelIndex::internalPointer()) is
* referencing an existing parent. A stale index can only be used
* while the model geometry is being updated, i.e. during the
* emission of the corresponding
* [rows/columns](Being)[Removed/Inserted]() signals.
*
* \sa index()
*/
virtual WModelIndex parent(const WModelIndex& index) const = 0;
/*! \brief Returns data at a specific model index.
*
* Return data for a given role at a given index.
*
* You should check the \p role to decide what data to
* return. Usually a View class will ask for data for several roles
* which affect not only the contents (Wt::DisplayRole) but also
* icons (Wt::DecorationRole), URLs (Wt::LinkRole), and other visual
* aspects. If your item does not specify data for a particular
* role, it should simply return a boost::any().
*
* \sa flags(), headerData(), setData()
*/
virtual boost::any data(const WModelIndex& index, int role = DisplayRole)
const = 0;
/*! \brief Returns all data at a specific index.
*
* This is a convenience function that returns a map with data
* corresponding to all standard roles.
*
* \sa data()
*/
virtual DataMap itemData(const WModelIndex& index) const;
/*! \brief Returns the row or column header data.
*
* When \p orientation is \link Wt::Horizontal
* Horizontal\endlink, \p section is a column number, when
* \p orientation is \link Wt::Vertical Vertical\endlink,
* \p section is a row number.
*
* \sa data(), setHeaderData()
*/
virtual boost::any headerData(int section,
Orientation orientation = Horizontal,
int role = DisplayRole) const;
/*! \brief Returns the child index for the given row and column.
*
* When implementing this method, you can use createIndex() to
* create an index that corresponds to the item at \p row and
* \p column within \p parent.
*
* If the location is invalid (out of bounds at the parent), then an
* invalid index must be returned.
*
* \sa parent()
*/
virtual WModelIndex index(int row, int column,
const WModelIndex& parent = WModelIndex())
const = 0;
/*! \brief Returns an index list for data items that match.
*
* Returns an index list of data items that match, starting at
* start, and searching further in that column. If flags specifies
* \link Wt::MatchWrap MatchWrap \endlink then the search wraps around
* from the start. If hits is not -1, then at most that number of
* hits are returned.
*/
virtual WModelIndexList match(const WModelIndex& start,
int role,
const boost::any& value,
int hits = -1,
WFlags<MatchFlag> flags
= WFlags<MatchFlag>(MatchStartsWith
| MatchWrap))
const;
/*! \brief Returns the data item at the given column and row.
*
* This is a convenience method, and is equivalent to:
* \code
* index(row, column, parent).data(role)
* \endcode
*
* \sa index(), data()
*/
boost::any data(int row, int column, int role = DisplayRole,
const WModelIndex& parent = WModelIndex()) const;
/*! \brief Returns if an index at the given position is valid
* (i.e. falls within the column-row bounds).
*
* Equivalent to:
* \code
* return row >= 0 && column >= 0
* && row < rowCount(parent) && column < columnCount(parent);
* \endcode
*
* \sa rowCount(), columnCount()
*/
virtual bool hasIndex(int row, int column,
const WModelIndex& parent = WModelIndex()) const;
/*! \brief Inserts one or more columns.
*
* In models that support column insertion, this inserts \c count
* columns, starting at \c column, and returns \c true if the
* operation was successful. The new columns are inserted under \p
* parent.
*
* The default implementation returns \c false.
*
* The model implementation must call beginInsertColumns() and
* endInsertColumns() before and after the operation whenever its
* geometry is changed by inserting columns. This emits signals for
* views to properly react to these changes.
*
* \sa insertRows(), removeColumns(), beginInsertColumns(), endInsertColumns()
*/
virtual bool insertColumns(int column, int count,
const WModelIndex& parent = WModelIndex());
/*! \brief Inserts one or more rows.
*
* In models that support row insertion, this inserts \c count rows,
* starting at \c row, and returns \c true if the operation was
* successful. The new rows are inserted under \p parent.
*
* If parent had no children, then a single column is added with \c
* count rows.
*
* The default implementation returns \c false.
*
* The model implementation must call beginInsertRows() and
* endInsertRows() before and after the operation whenever its
* geometry is changed by inserting rows. This emits signals for
* views to properly react to these changes.
*
* \sa insertColumns(), removeRows(), beginInsertRows(), endInsertRows()
*/
virtual bool insertRows(int row, int count,
const WModelIndex& parent = WModelIndex());
/*! \brief Removes columns.
*
* Returns \c true if the operation was successful.
*
* The default implementation returns \c false.
*
* The model implementation must call beginRemoveColumns() and
* endRemoveColumns() before and after the operation whenever its
* geometry is changed by removing columns. This emits signals for
* views to properly react to these changes.
*
* \sa removeRows(), insertColumns(), beginRemoveColumns(), endRemoveColumns()
*/
virtual bool removeColumns(int column, int count,
const WModelIndex& parent = WModelIndex());
/*! \brief Removes rows.
*
* Returns \c true if the operation was successful.
*
* The default implementation returns \c false.
*
* The model implementation must call beginRemoveRows() and
* endRemoveRows() before and after the operation whenever its
* geometry is changed by removing rows. This emits signals for
* views to properly react to these changes.
*
* \sa removeColumns(), insertRows(), beginRemoveRows(), endRemoveRows()
*/
virtual bool removeRows(int row, int count,
const WModelIndex& parent = WModelIndex());
/*! \brief Sets data at the given model index.
*
* Returns \c true if the operation was successful.
*
* The default implementation returns \c false.
*
* The model implementation must emit the dataChanged() signal after
* data was changed.
*
* \sa data()
*/
virtual bool setData(const WModelIndex& index, const boost::any& value,
int role = EditRole);
/*! \brief Sets data at the given model index.
*
* This is a convenience function that sets data for all roles at once.
*
* \sa setData()
*/
virtual bool setItemData(const WModelIndex& index, const DataMap& values);
/*! \brief Sets header data for a column or row.
*
* Returns \c true if the operation was successful.
*
* \sa headerData()
*/
virtual bool setHeaderData(int section, Orientation orientation,
const boost::any& value,
int role = EditRole);
/*! \brief Sets column header data.
*
* Returns \c true if the operation was successful.
*
* \sa setHeaderData(int, Orientation, const boost::any&, int)
*/
bool setHeaderData(int section, const boost::any& value);
/*! \brief Sorts the model according to a particular column.
*
* If the model supports sorting, then it should emit the
* layoutAboutToBeChanged() signal, rearrange its items, and
* afterwards emit the layoutChanged() signal.
*
* \sa layoutAboutToBeChanged(), layoutChanged()
*/
virtual void sort(int column, SortOrder order = AscendingOrder);
/*! \brief Expands a column.
*
* Expands a column. This may only be called by a view when the
* Wt::ColumnIsCollapsed flag is set.
*
* The default implementation does nothing.
*
* \sa WAggregateProxyModel
*/
virtual void expandColumn(int column);
/*! \brief Collapses a column.
*
* Collapses a column. This may only be called by a view when the
* Wt::ColumnIsExpandedLeft or Wt::ColumnIsExpandedRight flag is set.
*
* The default implementation does nothing.
*
* \sa WAggregateProxyModel
*/
virtual void collapseColumn(int column);
/*! \brief Converts a model index to a raw pointer that remains valid
* while the model's layout is changed.
*
* Use this method to temporarily save model indexes while the model's
* layout is changed by for example a sorting operation.
*
* The default implementation returns \c 0, which indicates that the
* index cannot be converted to a raw pointer. If you reimplement
* this method, you also need to reimplemnt fromRawIndex().
*
* \sa layoutAboutToBeChanged, sort(), fromRawIndex()
*/
virtual void *toRawIndex(const WModelIndex& index) const;
/*! \brief Converts a raw pointer to a model index.
*
* Use this method to create model index from temporary raw
* pointers. It is the reciproce method of toRawIndex().
*
* You can return an invalid modelindex if the rawIndex no longer points
* to a valid item because of the layout change.
*
* \sa toRawIndex()
*/
virtual WModelIndex fromRawIndex(void *rawIndex) const;
/*! \brief Returns a mime-type for dragging a set of indexes.
*
* This method returns a mime-type that describes dragging of a selection
* of items.
*
* The drop event will indicate a \link WItemSelectionModel
* selection model\endlink for this abstract item model as \link
* WDropEvent::source() source\endlink.
*
* The default implementation returns a mime-type for generic
* drag&drop support between abstract item models.
*
* \sa acceptDropMimeTypes()
*/
virtual std::string mimeType() const;
/*! \brief Returns a list of mime-types that could be accepted for a
* drop event.
*
* The default implementation only accepts drag&drop support between
* abstract item models.
*
* \sa mimeType()
*/
virtual std::vector<std::string> acceptDropMimeTypes() const;
/*! \brief Handles a drop event.
*
* The default implementation only handles generic drag&drop between
* abstract item models. Source item data is copied (but not the
* source item's flags).
*
* The location in the model is indicated by the \p row and
* \p column within the \p parent index. If \p row is
* -1, then the item is appended to the \p parent. Otherwise,
* the item is inserted at or copied over the indicated item (and
* subsequent rows). When \p action is a \link Wt::MoveAction
* MoveAction\endlink, the original items are deleted from the
* source model.
*
* You may want to reimplement this method if you want to handle
* other mime-type data, or if you want to refine how the drop event
* of an item selection must be interpreted.
*
* \note Currently, only row selections are handled by the default
* implementation.
*
* \sa mimeType(), WItemSelectionModel
*/
virtual void dropEvent(const WDropEvent& e, DropAction action,
int row, int column, const WModelIndex& parent);
/*! \brief Inserts one column.
*
* This is a convenience method that adds a single column, and is
* equivalent to:
* \code
* insertColumns(column, 1, parent);
* \endcode
*
* Returns \c true if the operation was successful.
*
* \sa insertColumns()
*/
bool insertColumn(int column, const WModelIndex& parent = WModelIndex());
/*! \brief Inserts one row.
*
* This is a convenience method that adds a single row, and is
* equivalent to:
* \code
* insertRows(row, 1, parent);
* \endcode
*
* Returns \c true if the operation was successful.
*
* \sa insertRows()
*/
bool insertRow(int row, const WModelIndex& parent = WModelIndex());
/*! \brief Removes one column.
*
* This is a convenience method that removes a single column, and is
* equivalent to:
* \code
* removeColumns(column, 1, parent);
* \endcode
*
* Returns \c true if the operation was successful.
*
* \sa removeColumns()
*/
bool removeColumn(int column, const WModelIndex& parent = WModelIndex());
/*! \brief Removes one row.
*
* This is a convenience method that removes a single row, and is
* equivalent to:
* \code
* removeRows(row, 1, parent);
* \endcode
*
* Returns \c true if the operation was successful.
*
* \sa removeRows()
*/
bool removeRow(int row, const WModelIndex& parent = WModelIndex());
/*! \brief Sets data at the given row and column.
*
* This is a convience method, and is equivalent to:
* \code
* setData(index(row, column, parent), value, role);
* \endcode
*
* Returns \c true if the operation was successful.
*
* \sa setData(), index()
*/
bool setData(int row, int column, const boost::any& value,
int role = EditRole, const WModelIndex& parent = WModelIndex());
/*! \brief %Signal emitted before a number of columns will be inserted.
*
* The first argument is the parent index. The two integer arguments
* are the column numbers that the first and last column will have when
* inserted.
*
* \sa columnsInserted(), beginInsertColumns()
*/
virtual Signal<WModelIndex, int, int>& columnsAboutToBeInserted()
{ return columnsAboutToBeInserted_; }
/*! \brief %Signal emitted before a number of columns will be removed.
*
* The first argument is the parent index. The two integer arguments
* are the column numbers of the first and last column that will be
* removed.
*
* \sa columnsRemoved(), beginRemoveColumns()
*/
virtual Signal<WModelIndex, int, int>& columnsAboutToBeRemoved()
{ return columnsAboutToBeRemoved_; }
/*! \brief %Signal emitted after a number of columns were inserted.
*
* The first argument is the parent index. The two integer arguments
* are the column numbers of the first and last column that were
* inserted.
*
* \sa columnsAboutToBeInserted(), endInsertColumns()
*/
virtual Signal<WModelIndex, int, int>& columnsInserted()
{ return columnsInserted_; }
/*! \brief %Signal emitted after a number of columns were removed.
*
* The first argument is the parent index. The two integer arguments
* are the column numbers of the first and last column that were removed.
*
* \sa columnsAboutToBeRemoved(), endRemoveColumns()
*/
virtual Signal<WModelIndex, int, int>& columnsRemoved()
{ return columnsRemoved_; }
/*! \brief %Signal emitted before a number of rows will be inserted.
*
* The first argument is the parent index. The two integer arguments
* are the row numbers that the first and last row will have when
* inserted.
*
* \sa rowsInserted(), beginInsertRows()
*/
virtual Signal<WModelIndex, int, int>& rowsAboutToBeInserted()
{ return rowsAboutToBeInserted_; }
/*! \brief %Signal emitted before a number of rows will be removed.
*
* The first argument is the parent index. The two integer arguments
* are the row numbers of the first and last row that will be
* removed.
*
* \sa rowsRemoved(), beginRemoveRows()
*/
virtual Signal<WModelIndex, int, int>& rowsAboutToBeRemoved()
{ return rowsAboutToBeRemoved_; }
/*! \brief %Signal emitted after a number of rows were inserted.
*
* The first argument is the parent index. The two integer arguments
* are the row numbers of the first and last row that were inserted.
*
* \sa rowsAboutToBeInserted(), endInsertRows()
*/
virtual Signal<WModelIndex, int, int>& rowsInserted()
{ return rowsInserted_; }
/*! \brief %Signal emitted after a number of rows were removed.
*
* The first argument is the parent index. The two integer arguments
* are the row numbers of the first and last row that were removed.
*
* \sa rowsAboutToBeRemoved(), endRemoveRows()
*/
virtual Signal<WModelIndex, int, int>& rowsRemoved()
{ return rowsRemoved_; }
/*! \brief %Signal emitted when some data was changed.
*
* The two arguments are the model indexes of the top-left and bottom-right
* data items that span the rectangle of changed data items.
*
* \sa setData()
*/
virtual Signal<WModelIndex, WModelIndex>& dataChanged()
{ return dataChanged_; }
/*! \brief %Signal emitted when some header data was changed.
*
* The first argument indicates the orientation of the header, and
* the two integer arguments are the row or column numbers of the
* first and last header item of which the value was changed.
*
* \sa setHeaderData()
*/
virtual Signal<Orientation, int, int>& headerDataChanged()
{ return headerDataChanged_; }
/*! \brief %Signal emitted when the layout is about to be changed.
*
* A layout change may reorder or add/remove rows in the model, but
* columns are preserved. Model indexes are invalidated by a layout
* change, but indexes may be ported across a layout change by using
* the toRawIndex() and fromRawIndex() methods.
*
* \sa layoutChanged(), toRawIndex(), fromRawIndex()
*/
virtual Signal<>& layoutAboutToBeChanged() { return layoutAboutToBeChanged_; }
/*! \brief %Signal emitted when the layout is changed.
*
* \sa layoutAboutToBeChanged()
*/
virtual Signal<>& layoutChanged() { return layoutChanged_; }
/*! \brief %Signal emitted when the model was reset.
*
* A model reset invalidates all existing data, and the model may change
* its entire geometry (column count, row count).
*
* \sa reset()
*/
virtual Signal<>& modelReset() { return modelReset_; }
protected:
/*! \brief Resets the model and invalidate any data.
*
* Informs any attached view that all data in the model was invalidated,
* and the model's data should be reread.
*
* This causes the modelReset() signal to be emitted.
*/
void reset();
/*! \brief Creates a model index for the given row and column.
*
* Use this method to create a model index. \p ptr is an internal
* pointer that may be used to identify the <b>parent</b> of the
* corresponding item. For a flat table model, \p ptr can thus
* always be 0.
*
* \sa WModelIndex::internalPointer()
*/
WModelIndex createIndex(int row, int column, void *ptr) const;
/*! \brief Creates a model index for the given row and column.
*
* Use this method to create a model index. \p id is an internal id
* that may be used to identify the <b>parent</b> of the
* corresponding item. For a flat table model, \p ptr can thus
* always be 0.
*
* \sa WModelIndex::internalId()
*/
WModelIndex createIndex(int row, int column, ::uint64_t id) const;
/*! \brief Method to be called before inserting columns.
*
* If your model supports insertion of columns, then you should call
* this method before inserting one or more columns, and
* endInsertColumns() afterwards. These methods emit the necessary
* signals to allow view classes to update themselves.
*
* \sa endInsertColumns(), insertColumns(), columnsAboutToBeInserted
*/
void beginInsertColumns(const WModelIndex& parent, int first, int last);
/*! \brief Method to be called before inserting rows.
*
* If your model supports insertion of rows, then you should call
* this method before inserting one or more rows, and
* endInsertRows() afterwards. These methods emit the necessary
* signals to allow view classes to update themselves.
*
* \sa endInsertRows(), insertRows(), rowsAboutToBeInserted
*/
void beginInsertRows(const WModelIndex& parent, int first, int last);
/*! \brief Method to be called before removing columns.
*
* If your model supports removal of columns, then you should call
* this method before removing one or more columns, and
* endRemoveColumns() afterwards. These methods emit the necessary
* signals to allow view classes to update themselves.
*
* \sa endRemoveColumns(), removeColumns(), columnsAboutToBeRemoved
*/
void beginRemoveColumns(const WModelIndex& parent, int first, int last);
/*! \brief Method to be called before removing rows.
*
* If your model supports removal of rows, then you should call this
* method before removing one or more rows, and endRemoveRows()
* afterwards. These methods emit the necessary signals to allow
* view classes to update themselves.
*
* \sa endRemoveRows(), removeRows(), rowsAboutToBeRemoved
*/
void beginRemoveRows(const WModelIndex& parent, int first, int last);
/*! \brief Method to be called after inserting columns.
*
* \sa beginInsertColumns()
*/
void endInsertColumns();
/*! \brief Method to be called after inserting rows.
*
* \sa beginInsertRows()
*/
void endInsertRows();
/*! \brief Method to be called after removing columns.
*
* \sa beginRemoveColumns()
*/
void endRemoveColumns();
/*! \brief Method to be called after removing rows.
*
* \sa beginRemoveRows()
*/
void endRemoveRows();
private:
int first_, last_;
WModelIndex parent_;
Signal<WModelIndex, int, int> columnsAboutToBeInserted_;
Signal<WModelIndex, int, int> columnsAboutToBeRemoved_;
Signal<WModelIndex, int, int> columnsInserted_;
Signal<WModelIndex, int, int> columnsRemoved_;
Signal<WModelIndex, int, int> rowsAboutToBeInserted_;
Signal<WModelIndex, int, int> rowsAboutToBeRemoved_;
Signal<WModelIndex, int, int> rowsInserted_;
Signal<WModelIndex, int, int> rowsRemoved_;
Signal<WModelIndex, WModelIndex> dataChanged_;
Signal<Orientation, int, int> headerDataChanged_;
Signal<> layoutAboutToBeChanged_;
Signal<> layoutChanged_;
Signal<> modelReset_;
static void copyData(const WAbstractItemModel *source,
const WModelIndex& sIndex,
WAbstractItemModel *destination,
const WModelIndex& dIndex);
friend class WAbstractProxyModel;
};
}
#endif // WABSTRACT_ITEM_MODEL_H_
|