Using IlvAbstractMatrix
The class
IlvAbstractMatrix is an abstract class for drawing matrices. Several of its member functions are virtual and must be redefined in subclasses. This class allows you to specify whether items should extend over several rows or columns, and also how many fixed rows and columns a matrix should contain. It also manages scrolling.
This section covers the following topics:
Subclassing IlvAbstractMatrix
The class
IlvAbstractMatrix does not contain any values. It provides a set of pure virtual member functions that must be implemented in subclasses:
rows and
columns must return the number of rows and columns in the matrix.
getRowHeight and
getColumnWidth must return the height of each row and the width of each column. If
rowSameHeight returns
IlTrue,
getRowHeight(0) returns the height of the rows and
getColumnWidth(0) returns the width of the columns.
drawItem draws an item in a matrix at the specified location defined by a row and a column number. This member function also specifies the bounding box of the matrix item and a clip rectangle.
Drawing Items Over Multiple Cells
You can have items extend to multiple rows and columns. To enable this feature, you must set the Boolean member value
_allowCellMode to
IlTrue in the
IlvAbstractMatrix constructor. Also, you must redefine
cellInfo. This member function specifies how many rows and columns the matrix item spans and the position of its top-left cell.
In the following example, the matrix item is defined to start at position (10,10) and to occupy five rows and five columns:
if ((colno >= 10) && (colno < 15) &&
(rowno >= 10) && (rowno < 15))
{
startcol = 10;
startrow = 10;
nbcol = 5;
nbrow = 5;
}
else
IlvAbstractMatrix::cellInfo(colno, rowno,
startcol, startrow,
nbcol, nbrow);
Note: Items extending over several rows and columns cannot overlap. |
When this member function is redefined, only the top-left cell is drawn (see
drawItem). The rectangle passed to the
drawItem member function encompasses all the rows and columns that the matrix item covers.
Setting Fixed Rows and Columns
You can specify that a number of rows and columns in a matrix remain fixed. Fixed rows and columns are always visible even when the user scrolls the matrix. Only the leftmost columns and the topmost rows can be fixed.
To have fixed rows or columns, use
setNbFixedRow and
setNbFixedColumn.
Handling Events
The class
IlvAbstractMatrix does not define particular behaviors.
The member function
IlvAbstractMatrix::handleEvent simply handles events related to scrollbars, if the matrix has scrollbars, and calls
handleMatrixEvent.
If you want to implement a specific behavior for a matrix, you must redefine this member function in a subclass.
The following methods can help you write the behavior for your class:
virtual IlBoolean pointToPosition(const IlvPoint& p,
IlUShort& colno,
IlUShort& rowno,
const IlvTransformer* t = 0) const;
This method returns, in colno and rowno, the location of the item which is under the point p when the matrix is displayed using the transformer t. The returned value is IlTrue if there is an item at this location, or IlFalse if there is none.
IlBoolean rowBBox(IlUShort rowno,
IlvRect& rect,
const IlvTransformer* t = 0) const;
IlBoolean columnBBox(IlUShort colno,
IlvRect& rect,
const IlvTransformer* t = 0) const;
IlBoolean cellBBox(IlUShort colno,
IlUShort rowno,
IlvRect& rect,
const IlvTransformer* t = 0) const;
The above methods compute in rect the bounding box of a column, a row, or a cell when the matrix is drawn with the transformer t.The method returns IlTrue if the item is visible (even partially), or IlFalse if it is not.
To redraw a column, use the
invalidateColumn method. To redraw a row, use the
invalidateRow method.
Version 6.1
Copyright © 2016, Rogue Wave Software, Inc. All Rights Reserved.