ICS

QicsTable Documentation Set

QicsTable Architectural Overview

The QicsTable distribution contains many different classes. This page describes some of the more important and commonly used classes and how they work together.

Model-View-Controller

QicsTable implements a form of the model-view-controller architecture. In this type of architecture, the data is stored in the model, where it can be accessed by many views. The view displays the data from the model. The controller allows one to manipulate the data in the model.

mvc.jpg

For a more general description of the model-view-controller architecture, see http://ootips.org/mvc-pattern.html .

In QicsTable, the model is represented by the abstract class QicsDataModel. This class defines the common interface that all data models must support. The QicsDataModelDefault class is the default implementation of the QicsDataModel interface. If QicsDataModelDefault does not meet your needs, you may create your own implementation of the QicsDataModel API (see Extending the QicsTable Data Model for details).

In many designs using the model-view-controller architecture, the view and the controller are grouped together. This is especially common in GUI applications and toolkits, where the widget abstraction encompasses the domains of both the view (what is drawn in the widget's window) and the controller (how the user interacts with the widget). In this case, it is natural to group the view and controller functions together into a widget. This is the approach used in QicsTable.

The main table widget is QicsTable. This widget acts as both view and controller. Each QicsTable widget is associated with a single data model object, which holds the data that the table will display.

Table Components

The table widget itself has a number of different parts. It has a main grid, which displays data from the model. It has one or more row header grids, which display row indices, row labels, or arbitrary data for each row. It has one or more column header grids, which display column indices, column labels, or arbitrary data for each column. It has optional scrollbars, which allow the user to control which rows and columns of data are displayed. Optional title widgets can be placed on each of the four sides of the table widget.

tableparts.png

In the QicsTable architecture, each component type is responsible for the layout and/or display of a particular part of the table. The QicsTable widget is responsible for the overall layout of the table. Each grid (row, column, or table) is responsible for the display of its frame and grid lines, and is also responsible for the layout of the cells within the grid. For more information on grids, see Customizing Grid Keyboard and Mouse Event Behavior.

The actual drawing of individual cells is performed by cell display objects. A cell display object is a property of each cell (see below for more details on cell properties). For more information on cell display objects, see Customizing Table Display Using Cell Display Objects.

Flyweight Objects

In an object-oriented programming environment, it is desirable to define a class for each distinct object type in the application. So, in a table, there should be a class representing the table as a whole, a class representing a row in the table, a class representing a column in the table, and a class representing a cell in the table. Each object should be able to retrieve and set all of the properties of that entity. It is often very inefficient, however, to actually store instances of these objects for each row, column, and cell.

A design pattern called the flyweight pattern solves this problem by defining small efficient classes that represent rows, columns, and cells, but don't actually contain redundant copies of all of the properties of the entities. Rather, they contain just enough information to retrieve and set those properties within the table's internal data structures. In addition, no instances of these flyweight classes exist until needed by the programmer.

When a programmer wants to refer to cell (3,2) in the table, s/he needs an instance of the QicsCell class. There are three ways to get an instance of this flyweight class:

Similar methods exist for QicsRow and QicsColumn.

QicsRepeatingRow and QicsRepeatingColumn are special flyweight objects that refer to a repeating set of rows or columns. Properties that are set on these objects will affect all rows or columns in the set.

In addition, there are flyweight objects that represent entire grids in the table. QicsMainGrid represents the central grid, while QicsRowHeader and QicsColumnHeader refer to the header grids.

These grid objects can be accessed and/or created in the following ways:

Once you have a header object, you can refer to cells and rows and columns in the header in a similar way to the cells in the main table. For cells in the row header, use one of the following two methods:

These methods work similarly to the corresponding methods of QicsTable. Similar methods exist for rows and columns, and all of these methods are duplicated in QicsColumnHeader.

Properties

The table widget has three sets of properties. Table properties specify attributes of the table as a whole. Grid properties specify attributes of a specific grid (either the main grid or one of the headers). Cell properties specify attributes of individual cells.

Table properties can be set only on a QicsTable widget. These properties specify the visual and behavioral characteristics of the table widget.

Grid properties can be set on the main grid of the QicsTable widget, or on one of the header grids. These properties specify the visual and behavioral characteristics of an individual grid. When setting or retrieving a grid property on the main grid of the table widget, use the read and write functions of the main grid object (QicsMainGrid). For example, to set the frameStyle property, use QicsMainGrid::setFrameStyle(). When setting or retrieving a grid property on one of the header grids, use the read and write functions from the appropriate flyweight class (QicsRowHeader and QicsColumnHeader). For example, to set the frameStyle property on the row header grid, use QicsRowHeader::setFrameStyle().

Cell properties can be set on a single cell, an entire row or column, or an entire grid. For example, one property of a cell is "font". This property exists in all of the following objects: QicsCell (single cell), QicsRow (entire row), QicsColumn (entire column), QicsMainGrid (entire main grid), QicsRowHeader (entire row header grid), and QicsColumnHeader (entire column header grid). Calling setFont() on a row sets the font for all cells in that row, overriding any previous font settings. Similarly, setting the font on a column overrides all previous font settings for cells in that column. Calling setFont() for an entire grid overrides all font settings for all cells in the grid.

If you wish to set a cell or grid property on all of the grids, you can use the read and write functions on the QicsTable widget itself. For example, calling QicsTable::setAlignment() will change the alignment of all cells in the main grid, the row header, and the column header.

All trademarks and copyrights on this page are properties of their respective owners.
The rest is copyright 1999-2006 Integrated Computer Solutions, Inc.