Wt
3.2.0
|
A proxy model for Wt's item models that provides column aggregation. More...
#include <Wt/WAggregateProxyModel>
Public Member Functions | |
WAggregateProxyModel (WObject *parent=0) | |
Constructor. | |
virtual | ~WAggregateProxyModel () |
Destructor. | |
void | addAggregate (int parentColumn, int firstColumn, int lastColumn) |
Adds a new column aggregation definition. | |
virtual WModelIndex | mapFromSource (const WModelIndex &sourceIndex) const |
Maps a source model index to the proxy model. | |
virtual WModelIndex | mapToSource (const WModelIndex &proxyIndex) const |
Maps a proxy model index to the source model. | |
virtual void | setSourceModel (WAbstractItemModel *sourceModel) |
Sets the source model. | |
virtual void | expandColumn (int column) |
Expands a column. | |
virtual void | collapseColumn (int column) |
Collapses a column. | |
virtual int | columnCount (const WModelIndex &parent=WModelIndex()) const |
Returns the number of columns. | |
virtual int | rowCount (const WModelIndex &parent=WModelIndex()) const |
Returns the number of rows. | |
virtual WFlags< HeaderFlag > | headerFlags (int section, Orientation orientation=Horizontal) const |
Returns the flags for a header. | |
virtual bool | setHeaderData (int section, Orientation orientation, const boost::any &value, int role=EditRole) |
Sets header data for a column or row. | |
virtual boost::any | headerData (int section, Orientation orientation=Horizontal, int role=DisplayRole) const |
Returns the row or column header data. | |
virtual WModelIndex | parent (const WModelIndex &index) const |
Returns the parent for a model index. | |
virtual WModelIndex | index (int row, int column, const WModelIndex &parent=WModelIndex()) const |
Returns the child index for the given row and column. | |
virtual void | sort (int column, SortOrder order=AscendingOrder) |
Sorts the model according to a particular column. |
A proxy model for Wt's item models that provides column aggregation.
This proxy model does not store data itself, but presents data from a source model, and presents methods to organize columns using aggregation, through which a user may navigate (usually to obtain more detailed results related to a single aggregate quantity).
To use this proxy model, you should provide a source model using setSourceModel(), and define column ranges that can be aggregated using addAggregate().
Example:
int COLS = 18; int ROWS = 20; // set up the source model model_ = new WStandardItemModel(0, COLS); std::string columns[] = { "Supplier", "2004", "Q1", "January", "February", "March", "Q2", "April", "May", "June", "Q3", "July", "August", "September", "Q4", "October", "November", "December" }; for (unsigned i = 0; i < COLS; ++i) { model_->setHeaderData(i, Horizontal, columns[i]); } for (unsigned i = 0; i < ROWS; ++i) { model_->insertRow(i); for (unsigned j = 0; j < COLS; ++j) model_->setData(i, j, "col " + boost::lexical_cast<std::string>(j)); } // set up the proxy model WAggregateProxyModel *proxy = new WAggregateProxyModel(); proxy->setSourceModel(model_); proxy->addAggregate(1, 2, 17); proxy->addAggregate(2, 3, 5); proxy->addAggregate(6, 7, 9); proxy->addAggregate(10, 11, 13); proxy->addAggregate(14, 15, 17); proxy->expandColumn(1); // expand 2004 -> Q1 Q2 Q3 Q4 // define a view treeView_ = new WTreeView(root()); treeView_->setColumnBorder(Wt::black); treeView_->setModel(proxy); treeView_->setColumnWidth(0, 160); treeView_->setColumnResizeEnabled(true); treeView_->setSortingEnabled(true);
This example would render like this:
Wt::WAggregateProxyModel::WAggregateProxyModel | ( | WObject * | parent = 0 | ) |
Constructor.
Sets up the proxy without aggregation functionality.
void Wt::WAggregateProxyModel::addAggregate | ( | int | parentColumn, |
int | firstColumn, | ||
int | lastColumn | ||
) |
Adds a new column aggregation definition.
The parentColumn
is the column index in the source model that acts as an aggregate for columns firstColumn
to lastColumn
. parentColumn
must border the range defined by firstColumn
to lastColumn:
parentColumn == firstColumn - 1 || parentColumn == lastColumn + 1
Note that column parameters reference column indexes in the source model.
Aggregation definitions can be nested, but should be strictly hierarchical.
The aggregate column will initially be collapsed.
Only one aggregate can be defined per parentColumn
.
void Wt::WAggregateProxyModel::collapseColumn | ( | int | column | ) | [virtual] |
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.
Reimplemented from Wt::WAbstractItemModel.
int Wt::WAggregateProxyModel::columnCount | ( | const WModelIndex & | parent = WModelIndex() | ) | const [virtual] |
Returns the number of columns.
This returns the number of columns at index parent
.
Implements Wt::WAbstractItemModel.
void Wt::WAggregateProxyModel::expandColumn | ( | int | column | ) | [virtual] |
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.
Reimplemented from Wt::WAbstractItemModel.
boost::any Wt::WAggregateProxyModel::headerData | ( | int | section, |
Orientation | orientation = Horizontal , |
||
int | role = DisplayRole |
||
) | const [virtual] |
Returns the row or column header data.
When orientation
is Horizontal, section
is a column number, when orientation
is Vertical, section
is a row number.
Reimplemented from Wt::WAbstractItemModel.
WFlags< HeaderFlag > Wt::WAggregateProxyModel::headerFlags | ( | int | section, |
Orientation | orientation = Horizontal |
||
) | const [virtual] |
Returns the flags for a header.
The default implementation returns no flags set.
Reimplemented from Wt::WAbstractItemModel.
WModelIndex Wt::WAggregateProxyModel::index | ( | int | row, |
int | column, | ||
const WModelIndex & | parent = WModelIndex() |
||
) | const [virtual] |
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 row
and column
within parent
.
If the location is invalid (out of bounds at the parent), then an invalid index must be returned.
Implements Wt::WAbstractItemModel.
WModelIndex Wt::WAggregateProxyModel::mapFromSource | ( | const WModelIndex & | sourceIndex | ) | const [virtual] |
Maps a source model index to the proxy model.
This method returns a model index in the proxy model that corresponds to the model index sourceIndex
in the source model. This method must only be implemented for source model indexes that are mapped and thus are the result of mapToSource().
Implements Wt::WAbstractProxyModel.
WModelIndex Wt::WAggregateProxyModel::mapToSource | ( | const WModelIndex & | proxyIndex | ) | const [virtual] |
Maps a proxy model index to the source model.
This method returns a model index in the source model that corresponds to the proxy model index proxyIndex
.
Implements Wt::WAbstractProxyModel.
WModelIndex Wt::WAggregateProxyModel::parent | ( | const WModelIndex & | index | ) | const [virtual] |
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.
Implements Wt::WAbstractItemModel.
int Wt::WAggregateProxyModel::rowCount | ( | const WModelIndex & | parent = WModelIndex() | ) | const [virtual] |
Returns the number of rows.
This returns the number of rows at index parent
.
Implements Wt::WAbstractItemModel.
bool Wt::WAggregateProxyModel::setHeaderData | ( | int | section, |
Orientation | orientation, | ||
const boost::any & | value, | ||
int | role = EditRole |
||
) | [virtual] |
Sets header data for a column or row.
Returns true
if the operation was successful.
Reimplemented from Wt::WAbstractItemModel.
void Wt::WAggregateProxyModel::setSourceModel | ( | WAbstractItemModel * | sourceModel | ) | [virtual] |
Sets the source model.
The source model provides the actual data for the proxy model.
Ownership of the source model is not transferred.
Reimplemented from Wt::WAbstractProxyModel.
void Wt::WAggregateProxyModel::sort | ( | int | column, |
Wt::SortOrder | order = AscendingOrder |
||
) | [virtual] |
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.
Reimplemented from Wt::WAbstractItemModel.