/usr/include/Wt/WStandardItemModel is in libwt-dev 3.3.4+dfsg-6ubuntu1.
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 | // 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 WSTANDARD_ITEM_MODEL_H_
#define WSTANDARD_ITEM_MODEL_H_
#include <Wt/WAbstractItemModel>
namespace Wt {
class WStandardItem;
/*! \class WStandardItemModel Wt/WStandardItemModel Wt/WStandardItemModel
* \brief A standard data model, which stores its data in memory.
*
* The standard item model supports all features of
* WAbstractItemModel, and can thus be used to represent tables, trees
* and tree tables.
*
* The data itself are organized in WStandardItem objects. There is
* one invisible root object (invisibleRootItem()) that holds the
* toplevel data. Most methods in this class that access or manipulate
* data internally operate on this root item.
*
* If you want to use the model as a table, then you can use
* WStandardItemModel(int, int, WObject *) to set the initial table
* size, and use the item() and setItem() methods to set data. You can
* change the geometry by inserting rows (insertRow()) or columns
* (insertColumn()) or removing rows (removeRow()) or columns
* (removeColumn()).
*
* If you want to use the model as a tree (or tree table), then you
* can use the default constructor to start with an empty tree, and
* use the WStandardItem API on invisibleRootItem() to manipulate the
* tree root. When you are building a tree, the column count at each
* node is 1. When you are building a tree table, you can add
* additional columns of data for each internal node. Only the items
* in the first column have children that result in a hierarchical
* tree structure.
*
* When using the model with a view class, you can use the
* itemFromIndex() and indexFromItem() models to translate between
* model indexes (that are used by the view class) and standard items.
*
* \if cpp
* Usage example for tabular data:
* \code
* int rows = 5;
* int columns = 4;
*
* Wt::WStandardItemModel *model = new Wt::WStandardItemModel(rows, columns, this);
*
* for (int row = 0; row < rows; ++row) {
* for (int column = 0; column < columns; ++column) {
* Wt::WStandardItem *item = new Wt::WStandardItem();
* item->setText("Item " + boost::lexical_cast<std::string>(row)
* + ", " + boost::lexical_cast<std::string>(column));
* model->setItem(row, column, item);
* }
* }
* \endcode
*
* Usage example for tree-like data:
* \code
* int topLevelRows = 5;
* int secondLevelRows = 7;
*
* Wt::WStandardItemModel *model = new Wt::WStandardItemModel();
* Wt::WStandardItem *root = model->invisibleRootItem();
*
* for (int row = 0; row < topLevelRows; ++row) {
* Wt::WStandardItem *topLevel = new Wt::WStandardItem();
* topLevel->setText("Item " + boost::lexical_cast<std::string>(row));
* for (int row2 = 0; row2 < secondLevelRows; ++row2) {
* Wt::WStandardItem *item = new Wt::WStandardItem();
* item->setText("Item " + boost::lexical_cast<std::string>(row)
* + ": " + boost::lexical_cast<std::string>(row2));
* topLevel->appendRow(item);
* }
* root->appendRow(topLevel);
* }
* \endcode
* \endif
*
* \ingroup modelview
*/
class WT_API WStandardItemModel : public WAbstractItemModel
{
public:
/*! \brief Creates a new standard item model.
*/
WStandardItemModel(WObject *parent = 0);
/*! \brief Creates a new standard item model with an initial geometry.
*
* Creates a standard item model with a geometry of
* <i>rows</i> x \p columns. All items are set to \c 0.
*/
WStandardItemModel(int rows, int columns, WObject *parent = 0);
/*! \brief Destructor.
*/
~WStandardItemModel();
/*! \brief Erases all data in the model.
*
* After clearing the model, rowCount() and columnCount() are 0.
*/
void clear();
/*! \brief Returns the invisible root item.
*
* The invisible root item is a special item that is not rendered
* itself, but holds the top level data.
*/
WStandardItem *invisibleRootItem() const { return invisibleRootItem_; }
/*! \brief Returns the model index for a particular item.
*
* If the \p item is the invisibleRootItem(), then an invalid
* index is returned.
*
* \sa itemFromIndex()
*/
WModelIndex indexFromItem(const WStandardItem *item) const;
/*! \brief Returns the standard item that corresponds to a model index.
*
* If the index is an invalid index, then the invisibleRootItem() is
* returned.
*
* \sa indexFromItem()
*/
WStandardItem *itemFromIndex(const WModelIndex& index) const;
/*! \brief Adds a single column of top level items.
*
* Appends a single column of top level \p items. If necessary,
* the row count is increased.
*
* Equivalent to:
* \code
* insertColumn(columnCount(), items);
* \endcode
*
* \sa insertColumn(), appendRow()
*/
void appendColumn(const std::vector<WStandardItem *>& items);
/*! \brief Inserts a single column of top level items.
*
* Inserts a single column of top level \p items at column
* \p column. If necessary, the row count is increased.
*
* Equivalent to:
* \code
* invisibleRootItem()->insertColumn(column, items);
* \endcode
*
* \sa WStandardItem::insertColumn()
*/
void insertColumn(int column, const std::vector<WStandardItem *>& items);
/*! \brief Adds a single row of top level items.
*
* Appends a single row of top level \p items. If necessary,
* the column count is increased.
*
* Equivalent to:
* \code
* insertRow(rowCount(), items);
* \endcode
*
* \sa insertRow(), appendColumn()
*/
void appendRow(const std::vector<WStandardItem *>& items);
using WAbstractItemModel::insertRow;
using WAbstractItemModel::insertColumn;
/*! \brief Inserts a single row of top level items.
*
* Inserts a single row of top level \p items at row
* \p row. If necessary, the column count is increased.
*
* Equivalent to:
* \code
* invisibleRootItem()->insertRow(row, items);
* \endcode
*
* \sa WStandardItem::insertRow()
*/
void insertRow(int row, const std::vector<WStandardItem *>& items);
/*! \brief Appends a single row containing a single item.
*
* Appends a single toplevel row, with a single item.
*
* Equivalent to:
* \code
* insertRow(rowCount(), item);
* \endcode
*
* \sa WStandardItem::insertRow(int, WStandardItem *)
*/
void appendRow(WStandardItem *item);
/*! \brief Inserts a single row containing a single item.
*
* Inserts a single toplevel row, with a single item.
*
* Equivalent to:
* \code
* invisibleRootItem()->insertRow(row, item);
* \endcode
*
* \sa WStandardItem::insertRow(int, WStandardItem *)
*/
void insertRow(int row, WStandardItem *item);
/*! \brief Returns a toplevel item.
*
* Returns the top level at at (<i>row</i>, \p column). This may
* be 0 if no item was set previously at that position, or if the
* indicated position is out of bounds.
*
* Equivalent to:
* \code
* invisibleRootItem()->child(row, column);
* \endcode
*
* \sa WStandardItem::child()
*/
WStandardItem *item(int row, int column = 0) const;
/*! \brief Sets a toplevel item.
*
* Sets the top level at at (<i>row</i>, \p column). If
* necessary, the number of rows or columns is increased.
*
* If an item was previously set for that position, it is deleted
* first.
*
* Equivalent to:
* \code
* invisibleRootItem()->setChild(row, column, item);
* \endcode
*
* \sa WStandardItem::setChild(int, int, WStandardItem *item)
*/
void setItem(int row, int column, WStandardItem *item);
/*! \brief Returns the item prototype.
*
* \sa setItemPrototype()
*/
WStandardItem *itemPrototype() const;
/*! \brief Sets the item prototype.
*
* Set the item that is cloned when an item needs to be created
* because the model is manipulated through its WAbstractItemModel
* API. For example, this may be needed when a view sets data at a
* position for which no item was previously set and thus created.
*
* The new item is created based on this prototype by using
* WStandardItem::clone().
*
* The default prototype is WStandardItem().
*
* \sa setItemPrototype()
*/
void setItemPrototype(WStandardItem *item);
/*! \brief Takes a column out of the model.
*
* Removes a column from the model, and returns the items that it
* contained. Ownership of the items is transferred out of the
* model.
*
* Equivalent to:
* \code
* invisibleRootItem()->takeColumn(column);
* \endcode
*
* \sa WStandardItem::takeColumn(), WStandardItem::takeRow()
*/
std::vector<WStandardItem *> takeColumn(int column);
/*! \brief Takes a row out of the model.
*
* Removes a row from the model, and returns the items that it
* contained. Ownership of the items is transferred out of the
* model.
*
* Equivalent to:
* \code
* invisibleRootItem()->takeRow(row);
* \endcode
*
* \sa WStandardItem::takeRow(), takeColumn()
*/
std::vector<WStandardItem *> takeRow(int row);
/*! \brief Takes an item out of the model.
*
* Removes an item from the model, and returns it. Ownership of the
* item is transferred out of the model.
*
* Equivalent to:
* \code
* invisibleRootItem()->takeItem(row, column);
* \endcode
*
* \sa takeItem(), WStandardItem::takeRow(), WStandardItem::takeColumn()
*/
WStandardItem *takeItem(int row, int column = 0);
/*! \brief Sets header flags.
*
* By default, no flags are set.
*/
void setHeaderFlags(int section, Orientation orientation,
WFlags<HeaderFlag> flags);
#ifndef DOXYGEN_ONLY
using WAbstractItemModel::setData;
using WAbstractItemModel::data;
using WAbstractItemModel::setHeaderData;
virtual WFlags<HeaderFlag> headerFlags(int section,
Orientation orientation = Horizontal)
const;
virtual WFlags<ItemFlag> flags(const WModelIndex& index) const;
virtual WModelIndex parent(const WModelIndex& index) const;
virtual boost::any data(const WModelIndex& index, int role = DisplayRole)
const;
virtual boost::any headerData(int section,
Orientation orientation = Horizontal,
int role = DisplayRole) const;
virtual WModelIndex index(int row, int column,
const WModelIndex& parent = WModelIndex()) const;
virtual int columnCount(const WModelIndex& parent = WModelIndex()) const;
virtual int rowCount(const WModelIndex& parent = WModelIndex()) const;
virtual bool insertColumns(int column, int count,
const WModelIndex& parent = WModelIndex());
virtual bool insertRows(int row, int count,
const WModelIndex& parent = WModelIndex());
virtual bool removeColumns(int column, int count,
const WModelIndex& parent = WModelIndex());
virtual bool removeRows(int row, int count,
const WModelIndex& parent = WModelIndex());
virtual bool setData(const WModelIndex& index, const boost::any& value,
int role = EditRole);
virtual bool setHeaderData(int section, Orientation orientation,
const boost::any& value, int role = EditRole);
virtual void *toRawIndex(const WModelIndex& index) const;
virtual WModelIndex fromRawIndex(void *rawIndex) const;
#endif // DOXYGEN_ONLY
/*! \brief Set the role used to sort the model.
*
* The default role is \link Wt::DisplayRole DisplayRole\endlink.
*
* \sa sort().
*/
void setSortRole(int role);
/*! \brief Returns the role used to sort the model.
*
* \sa setSortRole()
*/
int sortRole() const { return sortRole_; }
virtual void sort(int column, SortOrder order = AscendingOrder);
/*! \brief %Signal emitted when an item is changed.
*
* This signal is emitted whenever data for an item has changed. The
* item that has changed is passed as the first parameter.
*
* \sa WStandardItem::setData()
*/
Signal<WStandardItem *>& itemChanged() { return itemChanged_; }
protected:
#ifndef DOXYGEN_ONLY
void beginInsertColumns(const WModelIndex& parent, int first, int last);
void beginInsertRows(const WModelIndex& parent, int first, int last);
void beginRemoveColumns(const WModelIndex& parent, int first, int last);
void beginRemoveRows(const WModelIndex& parent, int first, int last);
#endif // DOXYGEN_ONLY
private:
typedef std::map<int, boost::any> HeaderData;
int sortRole_;
std::vector<HeaderData> columnHeaderData_, rowHeaderData_;
std::vector<WFlags<HeaderFlag> > columnHeaderFlags_, rowHeaderFlags_;
WStandardItem *invisibleRootItem_, *itemPrototype_;
Signal<WStandardItem *> itemChanged_;
void init();
WStandardItem *itemFromIndex(const WModelIndex& index, bool lazyCreate) const;
void insertHeaderData(std::vector<HeaderData>& headerData,
std::vector<WFlags<HeaderFlag> >& fl,
WStandardItem *item, int index, int count);
void removeHeaderData(std::vector<HeaderData>& headerData,
std::vector<WFlags<HeaderFlag> >& fl,
WStandardItem *item, int index, int count);
friend class WStandardItem;
};
}
#endif // WSTANDARD_ITEM_MODEL_H_
|