WARNING: USE THIS SOFTWARE AT YOUR OWN RISK! THIS IS EXPERIMENTAL SOFTWARE NOT INTENDED FOR PRODUCTION USE! Zuble is currently an early stage prototype. As such Zuble is minimally tested and inherently unstable. It is provided for experimental, development, and demonstration purposes only. Zuble QML Types   |  Zuble C++ Classes   |  Zuble Overview
Zuble  0.1
Zuble Framework C++/QML extension API
Public Types | Public Member Functions | Protected Member Functions | Private Attributes | List of all members
Zbl::ZblDataModel Class Reference

This class is an implementation of an N+1 dimensional data store suitable for use as a generic QAbstractItemModel data container. More...

#include <ZblDataModel.h>

Collaboration diagram for Zbl::ZblDataModel:
Collaboration graph
[legend]

Public Types

typedef QHash< int, QByteArray > zRoleNames
 

Public Member Functions

 ZblDataModel ()
 
 ~ZblDataModel ()
 
void setColumnCount (int count, ZblTableCell *cell=NULL)
 Sets the number of columns in the data table. This method fails if the data table contains rows. More...
 
int columnCount (const ZblTableCell *cell=NULL) const
 
int rowCount (const ZblTableCell *cell=NULL) const
 
QVariant data (int role, int row, int col, const ZblTableCell *cell=NULL) const
 
void setData (int role, int row, int col, const QVariant &value, ZblTableCell *cell=NULL)
 
QVariant getTableColumnRows (QList< int > roles, int startRow, int col, int rowCount, ZblTableCell *cell=NULL) const
 
void putTableColumnRows (QVariant rows, int startRow, int col, ZblTableCell *cell=NULL)
 
void appendRow (QMap< int, QList< QVariant > > data, ZblTableCell *cell=NULL)
 
void appendRows (QList< QMap< int, QList< QVariant > > > data, ZblTableCell *cell=NULL)
 
void prependRow (QMap< int, QList< QVariant > > data, ZblTableCell *cell=NULL)
 
void prependRows (QList< QMap< int, QList< QVariant > > > data, ZblTableCell *cell=NULL)
 
void removeRows (int row, int count, ZblTableCell *cell=NULL)
 Removes the specified data rows from the model. More...
 
bool addRole (int roleNumber, ZblTableCell *cell=NULL)
 Adds the specified role to the data table. More...
 
bool addRole (int roleNumber, const QByteArray &roleName, ZblTableCell *cell=NULL)
 Adds the specified role to the data table. More...
 
bool hasRole (int role, const ZblTableCell *cell=NULL) const
 Determines if a specified role already exists in the data table. More...
 
QList< int > roles (const ZblTableCell *cell=NULL) const
 Determines which roles are in the data set. More...
 
zRoleNames roleNames () const
 Obtains a hash that maps role numbers to role names. More...
 
int roleCount (const ZblTableCell *cell=NULL) const
 Obtains the number of roles contained by the specified cell. More...
 
void clearData (ZblTableCell *cell=NULL)
 Removes all data rows from the specified table cell. More...
 
void clearRoles ()
 Removes all information from the model and returns the model to it's uninitialized state. More...
 
void dumpModelData (const ZblTableCell *cell=NULL) const
 Prints diagnostic information about the state of the contained data to debug output. More...
 
int findNextItemRow (int startRow, const QString &text, int column=0, bool caseSensitive=true, bool forwardDirection=true, bool keySearch=false, const ZblTableCell *cell=NULL) const
 Searches for the specified text from startIndex. More...
 
bool copyColumn (int fromColumn, int toColumn, ZblTableCell *cell=NULL)
 Copies data between data model columns for all rows and roles in the model. More...
 

Protected Member Functions

ZblTableHeadersheaders ()
 
ZblTableCellcolNamesCell ()
 
ZblTableCellrootCell ()
 
const ZblTableCellconstRootCell () const
 

Private Attributes

ZblTableHeadersm_headers
 This object contains row and column header values for the model. More...
 
ZblTableCellm_columnNames
 The cell containing column names if column names have been set. TBD: do we need column names? roles have subsumed this? More...
 
zRoleNamesm_roleNames
 A hash of role value/name pairs. More...
 
ZblTableCellm_rootCell
 The model's root cell contains the top level items. The root cell has no parent. More...
 

Detailed Description

This class is an implementation of an N+1 dimensional data store suitable for use as a generic QAbstractItemModel data container.

It can be internally configured to store any data structure the item data model can represent. Optimizations are possible for typical configurations such as list, table and tree.

The data model is composed of cell data, role name, model header and column name components. Lazy allocation is employed for these subcomponents.

Internally the data store uses the composite design pattern to define a table cell which contains the role data for it's child cells. If a table cell's child cells have children the table cell contains a table of child cell objects to contain their data.

This class is reentrant but not thread safe.

Definition at line 62 of file ZblDataModel.h.

Member Typedef Documentation

◆ zRoleNames

typedef QHash<int, QByteArray> Zbl::ZblDataModel::zRoleNames

Definition at line 66 of file ZblDataModel.h.

Constructor & Destructor Documentation

◆ ZblDataModel()

Zbl::ZblDataModel::ZblDataModel ( )

Definition at line 32 of file ZblDataModel.cpp.

◆ ~ZblDataModel()

Zbl::ZblDataModel::~ZblDataModel ( )

Definition at line 41 of file ZblDataModel.cpp.

Member Function Documentation

◆ addRole() [1/2]

bool Zbl::ZblDataModel::addRole ( int  roleNumber,
ZblTableCell cell = NULL 
)

Adds the specified role to the data table.

Parameters
roleNumberid number for the role to be added
cellthe table cell object to which the role will be added, NULL selects the table root cell
Returns
true if specified role was added, false if specified role already existed

Definition at line 229 of file ZblDataModel.cpp.

Referenced by Zbl::ZTableModel::addRole(), and Zbl::ZTableModel::putJsonData().

◆ addRole() [2/2]

bool Zbl::ZblDataModel::addRole ( int  roleNumber,
const QByteArray &  roleName,
ZblTableCell cell = NULL 
)

Adds the specified role to the data table.

Parameters
roleNumberid number for the role to be added
roleNamename for the role (must be unique)
cellthe table cell object to which the role will be added, NULL selects the table root cell
Returns
true if specified role was added, false if specified role already existed

Definition at line 237 of file ZblDataModel.cpp.

◆ appendRow()

void Zbl::ZblDataModel::appendRow ( QMap< int, QList< QVariant > >  data,
ZblTableCell cell = NULL 
)

◆ appendRows()

void Zbl::ZblDataModel::appendRows ( QList< QMap< int, QList< QVariant > > >  data,
ZblTableCell cell = NULL 
)

Definition at line 181 of file ZblDataModel.cpp.

Referenced by Zbl::ZTableModel::appendRows().

◆ clearData()

void Zbl::ZblDataModel::clearData ( ZblTableCell cell = NULL)

Removes all data rows from the specified table cell.

Parameters
cellthe table cell object for which rows will be removed, NULL selects the table root cell

Definition at line 321 of file ZblDataModel.cpp.

Referenced by Zbl::ZTableModel::clearData().

◆ clearRoles()

void Zbl::ZblDataModel::clearRoles ( )

Removes all information from the model and returns the model to it's uninitialized state.

This includes roles, data rows, row headers, column headers and column names for the root cell and all descendants.

Parameters
cellthe table cell object for which roles and rows will be removed, NULL selects the table root cell

Definition at line 329 of file ZblDataModel.cpp.

Referenced by Zbl::ZTableModel::clearRoles().

◆ colNamesCell()

ZblTableCell & Zbl::ZblDataModel::colNamesCell ( )
protected

Definition at line 305 of file ZblDataModel.cpp.

◆ columnCount()

int Zbl::ZblDataModel::columnCount ( const ZblTableCell cell = NULL) const

◆ constRootCell()

const ZblTableCell & Zbl::ZblDataModel::constRootCell ( ) const
protected

◆ copyColumn()

bool Zbl::ZblDataModel::copyColumn ( int  fromColumn,
int  toColumn,
ZblTableCell cell = NULL 
)

Copies data between data model columns for all rows and roles in the model.

Parameters
fromColumnColumn from which data will be copied
toColumnColumn to which data will be copied
cellthe table cell to act on
Returns
true if column was copied, false otherwise

Definition at line 288 of file ZblDataModel.cpp.

Referenced by Zbl::ZTableModel::copyColumn().

◆ data()

QVariant Zbl::ZblDataModel::data ( int  role,
int  row,
int  col,
const ZblTableCell cell = NULL 
) const

◆ dumpModelData()

void Zbl::ZblDataModel::dumpModelData ( const ZblTableCell cell = NULL) const

Prints diagnostic information about the state of the contained data to debug output.

Definition at line 280 of file ZblDataModel.cpp.

Referenced by Zbl::ZTableModel::dumpModelData().

◆ findNextItemRow()

int Zbl::ZblDataModel::findNextItemRow ( int  startRow,
const QString &  text,
int  column = 0,
bool  caseSensitive = true,
bool  forwardDirection = true,
bool  keySearch = false,
const ZblTableCell cell = NULL 
) const

Searches for the specified text from startIndex.

Definition at line 379 of file ZblDataModel.cpp.

Referenced by Zbl::ZTableModel::appendMissingRow(), and Zbl::ZTableModel::findNextItemRow().

◆ getTableColumnRows()

QVariant Zbl::ZblDataModel::getTableColumnRows ( QList< int >  roles,
int  startRow,
int  col,
int  rowCount,
ZblTableCell cell = NULL 
) const

Definition at line 116 of file ZblDataModel.cpp.

Referenced by Zbl::ZTableModel::getTableColumnRows().

◆ hasRole()

bool Zbl::ZblDataModel::hasRole ( int  role,
const ZblTableCell cell = NULL 
) const

Determines if a specified role already exists in the data table.

Returns
true if specified role exists, false otherwise

Definition at line 256 of file ZblDataModel.cpp.

◆ headers()

ZblTableHeaders & Zbl::ZblDataModel::headers ( )
protected

Definition at line 297 of file ZblDataModel.cpp.

◆ prependRow()

void Zbl::ZblDataModel::prependRow ( QMap< int, QList< QVariant > >  data,
ZblTableCell cell = NULL 
)

Definition at line 191 of file ZblDataModel.cpp.

Referenced by Zbl::ZTableModel::prependRow().

◆ prependRows()

void Zbl::ZblDataModel::prependRows ( QList< QMap< int, QList< QVariant > > >  data,
ZblTableCell cell = NULL 
)

Definition at line 210 of file ZblDataModel.cpp.

Referenced by Zbl::ZTableModel::prependRows().

◆ putTableColumnRows()

void Zbl::ZblDataModel::putTableColumnRows ( QVariant  rows,
int  startRow,
int  col,
ZblTableCell cell = NULL 
)

Definition at line 137 of file ZblDataModel.cpp.

Referenced by Zbl::ZTableModel::insertTableColumnRows().

◆ removeRows()

void Zbl::ZblDataModel::removeRows ( int  row,
int  count,
ZblTableCell cell = NULL 
)

Removes the specified data rows from the model.

Parameters
rowrow number of the first row to remove
countnumber of rows to remove
celltable cell to remove rows from, NULL to use root cell

Definition at line 220 of file ZblDataModel.cpp.

Referenced by Zbl::ZTableModel::removeRows().

◆ roleCount()

int Zbl::ZblDataModel::roleCount ( const ZblTableCell cell = NULL) const

Obtains the number of roles contained by the specified cell.

Parameters
cellthe table cell object for which role numbers wll be returned, NULL selects the table root cell
Returns
current number of roles contained in the cell

Definition at line 272 of file ZblDataModel.cpp.

Referenced by Zbl::ZTableModel::getRoleCount(), and Zbl::ZTableModel::mergeCells().

◆ roleNames()

ZblDataModel::zRoleNames Zbl::ZblDataModel::roleNames ( ) const

Obtains a hash that maps role numbers to role names.

Parameters
cellthe table cell object for which role numbers wll be returned, NULL selects the table root cell
Returns
QHash<int, QBytearray>

Definition at line 313 of file ZblDataModel.cpp.

Referenced by clearRoles(), and Zbl::ZTableModel::roleNames().

◆ roles()

QList< int > Zbl::ZblDataModel::roles ( const ZblTableCell cell = NULL) const

Determines which roles are in the data set.

Returns
A list of integers representing the roles currently in the data set.

Definition at line 264 of file ZblDataModel.cpp.

Referenced by Zbl::ZTableModel::mergeCells(), and Zbl::ZTableModel::roles().

◆ rootCell()

ZblTableCell & Zbl::ZblDataModel::rootCell ( )
protected

◆ rowCount()

int Zbl::ZblDataModel::rowCount ( const ZblTableCell cell = NULL) const

◆ setColumnCount()

void Zbl::ZblDataModel::setColumnCount ( int  count,
ZblTableCell cell = NULL 
)

Sets the number of columns in the data table. This method fails if the data table contains rows.

Definition at line 57 of file ZblDataModel.cpp.

Referenced by Zbl::ZTableModel::setColumnCount().

◆ setData()

void Zbl::ZblDataModel::setData ( int  role,
int  row,
int  col,
const QVariant &  value,
ZblTableCell cell = NULL 
)

Definition at line 93 of file ZblDataModel.cpp.

Referenced by Zbl::ZTableModel::putValue().

Member Data Documentation

◆ m_columnNames

ZblTableCell* Zbl::ZblDataModel::m_columnNames
private

The cell containing column names if column names have been set. TBD: do we need column names? roles have subsumed this?

Definition at line 268 of file ZblDataModel.h.

Referenced by clearRoles(), colNamesCell(), and ~ZblDataModel().

◆ m_headers

ZblTableHeaders* Zbl::ZblDataModel::m_headers
private

This object contains row and column header values for the model.

Definition at line 260 of file ZblDataModel.h.

Referenced by clearRoles(), headers(), and ~ZblDataModel().

◆ m_roleNames

zRoleNames* Zbl::ZblDataModel::m_roleNames
private

A hash of role value/name pairs.

Definition at line 274 of file ZblDataModel.h.

Referenced by addRole(), clearRoles(), roleNames(), and ~ZblDataModel().

◆ m_rootCell

ZblTableCell* Zbl::ZblDataModel::m_rootCell
private

The model's root cell contains the top level items. The root cell has no parent.

Definition at line 281 of file ZblDataModel.h.

Referenced by clearRoles(), constRootCell(), rootCell(), and ~ZblDataModel().


The documentation for this class was generated from the following files: