This class implements a relation table model for option assignments, such as for example t_grouppermissions. More...
#include <bpsrelationtablemodel.h>
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. | |
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:
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();
Current status of an option.
| 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();
| [in] | aParent | The parent object. |
| [in] | aDatastore | A open datastore. |
| [in] | aRelationTable | Name of the relation table. |
| [in] | aMasterColumn | Name of the master table foreign key column in the relation table. |
| [in] | aOptionColumn | Name of the option table foreign key in the relation table. |
| [in] | aOptionTable | Name of the options table. Assumed to have a column c_key and a key column at least. |
| [in] | aOptionKey | Name of the options table key column to be displayed. |
| BpsException | When parse error. |
| QStringList BpsRelationTableModel::checkedOptionNames | ( | qlonglong | aMaster | ) | const |
| [in] | aMaster | The c_key primary key in the master table. |
| 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.
| [in] | aMaster | The c_key primary key in the master table. |
| [in] | aList | The 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 | ( | ) |
| QString BpsRelationTableModel::relationTable | ( | ) | const |
| void BpsRelationTableModel::select | ( | ) |
Select the list of all available options.
Should be called at the beginning of work.
| BpsException | When 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().
| [in] | aDescriptions | The 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.
| [in] | aEnabled | The new status to set. |
| void BpsRelationTableModel::setMaster | ( | qlonglong | aMaster | ) |
Set the model to the master table item.
| [in] | aMaster | The c_key primary key in the master table. |
| BpsException | When SQL error querying the options for the item. |
| void BpsRelationTableModel::submitAll | ( | ) |
Submits all unsaved changed to the database.
| When | SQL error. |