Documents > BPS V2 C++ API
BpsRelationTableModel Class Reference

This class implements a relation table model for option assignments, such as for example t_grouppermissions. More...

#include <bpsrelationtablemodel.h>

List of all members.

Public Types

enum  Status {
  StatusFalse = 0,
  StatusTrue = 1,
  StatusEnable = 2,
  StatusDisable = 3
}
 Current status of an option. More...

Signals

void wasModified ()
 This signal is emitted whenever a status is changed to StatusEnable or StatusDisable.

Public Member Functions

 BpsRelationTableModel (QObject *aParent, BpsDatastore *aDatastore, const QString &aRelationTable, const QString &aMasterColumn, const QString &aOptionColumn, const QString &aOptionTable, const QString &aOptionKey)
 Constructor for a BpsRelationTableModel.
QStringList checkedOptionNames (qlonglong aMaster) const
void checkOptions (qlonglong aMaster, const QStringList &aList)
 Sets all options in the list as checked, and all options not in the list as unchecked.
void clear ()
 Clears all data from the model.
bool isDirty ()
QString relationTable () const
void revertAll ()
 Reverts all unsaved changes.
void select ()
 Select the list of all available options.
void setDescriptions (const QMap< QString, QString > &aDescriptions)
 Add a second column with descriptions for the option table key.
void setItemsEnabled (bool aEnabled=true)
 Enable/disable the displayed items.
void setMaster (qlonglong aMaster)
 Set the model to the master table item.
void submitAll ()
 Submits all unsaved changed to the database.

Detailed Description

This class implements a relation table model for option assignments, such as for example t_grouppermissions.

The model is best combined with a QListView: It has one column and each item has a check box role to select the valid options.

The following assumptions are made:

  • There is a table where options can be assigned to. This table is referred to as the master table. In the example below that is t_groups.
  • There is a table with available options, with at least the the two columns c_key and a key column. This table is referred to as the options table. In the example below that is table t_permissions with the key column c_name.
  • There is a relation table with exactly two identifier columns, one referring to the master table c_key column, and one referring to the option table c_key column.
    mPermissionsModel = new BpsRelationTableModel(
        this, 
        mLicenseToken->datastore(),
        "t_grouppermissions", 
        "c_group", 
        "c_permission",
        "t_permissions,"
        "c_name"
    );
    connect(mPermissionsModel, SIGNAL(wasModified()), this, SLOT(setModified()));
    mPermissionsModel->select();

Member Enumeration Documentation

Current status of an option.

Enumerator:
StatusFalse 

The option is deselected in the database.

StatusTrue 

The option is selected in the database.

StatusEnable 

The option is marked for selection, but the status is not yet saved.

StatusDisable 

The option is marked for deselection, but the status is not yet saved.


Constructor & Destructor Documentation

BpsRelationTableModel::BpsRelationTableModel ( QObject *  aParent,
BpsDatastore aDatastore,
const QString &  aRelationTable,
const QString &  aMasterColumn,
const QString &  aOptionColumn,
const QString &  aOptionTable,
const QString &  aOptionKey 
)

Constructor for a BpsRelationTableModel.

    mPermissionsModel = new BpsRelationTableModel(
        this, 
        mDatastore,
        "t_grouppermissions", 
        "c_group", 
        "c_permission",
        "t_permissions,"
        "c_name"
    );
    mPermissionsModel->select();
Parameters:
[in]aParentThe parent object.
[in]aDatastoreA open datastore.
[in]aRelationTableName of the relation table.
[in]aMasterColumnName of the master table foreign key column in the relation table.
[in]aOptionColumnName of the option table foreign key in the relation table.
[in]aOptionTableName of the options table. Assumed to have a column c_key and a key column at least.
[in]aOptionKeyName of the options table key column to be displayed.
Exceptions:
BpsExceptionWhen parse error.

Member Function Documentation

QStringList BpsRelationTableModel::checkedOptionNames ( qlonglong  aMaster) const
Parameters:
[in]aMasterThe c_key primary key in the master table.
Returns:
A list of the currently selected option names, independent of save status.
void BpsRelationTableModel::checkOptions ( qlonglong  aMaster,
const QStringList &  aList 
)

Sets all options in the list as checked, and all options not in the list as unchecked.

Parameters:
[in]aMasterThe c_key primary key in the master table.
[in]aListThe option name list.
void BpsRelationTableModel::clear ( )

Clears all data from the model.

If you want to continue working after, you should again call select and set the master table item.

bool BpsRelationTableModel::isDirty ( )
Returns:
True if the model holds any unsaved changes.
QString BpsRelationTableModel::relationTable ( ) const
Returns:
Name of the relation table.
void BpsRelationTableModel::select ( )

Select the list of all available options.

Should be called at the beginning of work.

Exceptions:
BpsExceptionWhen SQL error querying the list of available options.
void BpsRelationTableModel::setDescriptions ( const QMap< QString, QString > &  aDescriptions)

Add a second column with descriptions for the option table key.

Set the descriptions before calling select().

Parameters:
[in]aDescriptionsThe map where the keys are the option table keys, and the values are the descriptions.
void BpsRelationTableModel::setItemsEnabled ( bool  aEnabled = true)

Enable/disable the displayed items.

By default the items are enabled.

Parameters:
[in]aEnabledThe new status to set.
void BpsRelationTableModel::setMaster ( qlonglong  aMaster)

Set the model to the master table item.

Parameters:
[in]aMasterThe c_key primary key in the master table.
Returns:
A void is returned.
Exceptions:
BpsExceptionWhen SQL error querying the options for the item.
void BpsRelationTableModel::submitAll ( )

Submits all unsaved changed to the database.

Exceptions:
WhenSQL error.

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