Widget used to pick items from one list and add them to another. More...
#include <selectionwidget.h>
Public Slots | |
virtual void | sAdd () |
Moves selected items from the "available" tree to the "selected" tree. More... | |
virtual void | sAddAll () |
Moves all items from the "available" tree to the "selected" tree. More... | |
virtual void | sCancel () |
Emits cancelClicked() signal. More... | |
virtual int | sCommitChanges () |
Calls functions to execute the appropriate INSERT and DELETE queries. More... | |
virtual void | sRemove () |
Moves selected items from the "selected" tree to the "available" tree. More... | |
virtual void | sRemoveAll () |
Moves all items from the "selected" tree to the "available" tree. More... | |
virtual void | sSelect () |
Emits selectClicked() signal. More... | |
Signals | |
void | addAllClickedAfter () |
void | addAllClickedBefore () |
void | addClickedAfter () |
void | addClickedBefore () |
void | cancelClicked () |
void | itemAdded (int id) |
void | itemRemoved (int id) |
void | removeAllClickedAfter () |
void | removeAllClickedBefore () |
void | removeClickedAfter () |
void | removeClickedBefore () |
void | selectClicked () |
Public Member Functions | |
SelectionWidget (QWidget *parent=0, Qt::WindowFlags fl=0) | |
~SelectionWidget () | |
Q_INVOKABLE ParameterList | getAddConstraints () const |
Q_INVOKABLE QList< XTreeWidgetItem * > | getAdded () const |
Returns the _added list. More... | |
Q_INVOKABLE XTreeWidget * | getAvail () const |
Returns the "available" tree. More... | |
Q_INVOKABLE ParameterList | getEqualityColumns () const |
Q_INVOKABLE QString | getModifyTableName () const |
Q_INVOKABLE bool | getRemoveByAltId () const |
Q_INVOKABLE QString | getRemoveByIdTableColName () const |
Q_INVOKABLE QList< XTreeWidgetItem * > | getRemoved () const |
Returns the _removed list. More... | |
Q_INVOKABLE XTreeWidget * | getSel () const |
Returns the "selected" tree. More... | |
Q_INVOKABLE void | hideCancel () |
Hides the cancel button. More... | |
Q_INVOKABLE void | hideSelect () |
Hides the select button. More... | |
Q_INVOKABLE bool | isParentInTrans () const |
void | retranslateUi (QWidget *SelectionWidget) |
void | retranslateUi (QWidget *SelectionWidget) |
Q_INVOKABLE void | setAddConstraints (ParameterList constraints) |
Q_INVOKABLE void | setEqualityColumns (ParameterList columns) |
Q_INVOKABLE void | setModifyTableName (QString name) |
Q_INVOKABLE void | setParentInTrans (bool parInTrans=true) |
Q_INVOKABLE void | setRemoveByAltId (bool useAlt=true) |
Q_INVOKABLE void | setRemoveByIdTableColName (QString name) |
void | setupUi (QWidget *SelectionWidget) |
void | setupUi (QWidget *SelectionWidget) |
Q_INVOKABLE void | showCancel () |
Shows the cancel button. More... | |
Q_INVOKABLE void | showSelect () |
Shows the select button. More... | |
Public Attributes | |
QPushButton * | _add |
QPushButton * | _addAll |
XTreeWidget * | _avail |
QLabel * | _availLit |
QPushButton * | _cancel |
QPushButton * | _remove |
QPushButton * | _removeAll |
XTreeWidget * | _sel |
QPushButton * | _select |
QLabel * | _selLit |
QGridLayout * | gridLayout |
QSpacerItem * | verticalSpacer |
QSpacerItem * | verticalSpacer_2 |
QSpacerItem * | verticalSpacer_3 |
Protected Slots | |
void | sFilterDuplicates () |
Removes items from the "available" tree that are already in the "selected" tree. More... | |
Protected Member Functions | |
int | execAddQuery (XSqlQuery &outQry) |
Builds and executes an INSERT query for each item in the _added list. More... | |
int | execRemoveQuery (XSqlQuery &outQry) |
Builds and executes a DELETE query to remove all items in the _removed list. More... | |
bool | isSameItem (XTreeWidgetItem *pXtitem1, XTreeWidgetItem *pXtitem2) const |
Determines if 2 items are equal based on configured equality criteria. More... | |
void | move (XTreeWidgetItem *pXtitem, bool pAdd) |
Moves an item from one tree to another based on the value of pAdd. More... | |
Protected Attributes | |
ParameterList | _addConstraints |
Name value pairs indicating column names and values to insert. More... | |
QList< XTreeWidgetItem * > | _added |
List of items added to "available" tree since loading. More... | |
ParameterList | _equalityColumns |
Name Value pairs indicating pairs of columns to be compared for equality. More... | |
QString | _modifyTableName |
Name of table where items will be added or removed. More... | |
bool | _parentInTrans |
When true, insert and delete statements will not be wrapped in a transaction block. More... | |
bool | _removeByAltId |
When true, delete statements use the item's altId instead of id. More... | |
QString | _removeByIdTableColName |
Column name used as a key by the delete statement to remove records. More... | |
QList< XTreeWidgetItem * > | _removed |
List of items removed from the "selected" tree since loading. More... | |
Widget used to pick items from one list and add them to another.
The selection widget incorporates 2 XTreeWidgets, one as a source (or available) and one as a destination (or selected). Each tree will be populated from a different query but the data should be compatible with the fields on both trees otherwise moving items back and forth doesn't make sense.
The widget was designed to be adaptable and thus requires some configuration first. The following must be done before the widget will function properly:
Tree Setup:
The internal trees are exposed via the getAvail() and getSel() functions. Once you have pointers to the trees, they must be configured as is usual for XTreeWidgets.
Equality Columns:
Since each of the trees may present different attributes of the underlying data, there needs to be a way to determine equality between items on different trees. A list of name-value pairs must be passed to the setEqualityColumns() function. Each pair will contain the XTreeWidget column names to be considered equivalent. When the trees first load, any items in the "available" tree that are already present in the "selected" tree (based on the equality columns) will be filtered out of the available list.
The widget can either be automatic or handled manually depending on the situation.
Manual:
With the above setup in place, the widget will function properly and track selections. Various signals are emitted by the widget when buttons are clicked and before/after items are moved in either direction. At any point you can retrieve a list of changes from the getAdded() and getRemoved() functions. The getAdded function will return a list of items that are currently in the "selected" tree that were not there when the widget first loaded. getRemoved() returns items that were in the "selected" tree when the widget first loaded and are no longer there. Between the accessor functions and the signals, you can process the changes in whatever way suits your needs.
Set Modification Table:
The table where new items will be added (and from which removed items will be deleted) must be passed to setModifyTableName(). Ideally this will be the table from which the "selected" tree was populated though this is not necessary. The only requirement is that calling id() or altId() on the XTreeWidget item will return an id that is sufficient to identify a single record in the table passed to setModifyTableName().
Set Insert Criteria:
In order to insert records into an arbitrary table, a list of column names and values to insert must be provided. A parameter list must be passed to setAddConstraints(). This list will contain one entry for each column to be populated and must, at a minimum, contain entries for each required column in the table passed to setModifyTableName(). In each entry, the parameter name must be the table column name. The parameter value can either be a literal value, or the name of a column in the "selected" XTreeWidget. If the parameter value matches a column name, the contents of that column will be inserted, otherwise the parameter value will be inserted directly.
SelectionWidget::SelectionWidget | ( | QWidget * | parent = 0 , |
Qt::WindowFlags | fl = 0 |
||
) |
SelectionWidget::~SelectionWidget | ( | ) |
|
signal |
|
signal |
|
signal |
|
signal |
|
signal |
|
protected |
Builds and executes an INSERT query for each item in the _added list.
This function builds INSERT statements using _modifyTableName and _addConstraints in order to create flexible queries for any table needed. Values to be inserted are bound to "parameterN" for N = 0 to addConstraints.count() - 1. Returns the query executed to allow for error reporting outside of a transaction block.
The entries in _addConstraints will determine how the query is built. For each entry in _addConstraints, the parameter name specifies the column where the value will be inserted. the parameter value will either be a column name in the "available" tree or a literal value. If the parameter value matches a column name, the value in that column will be inserted, otherwise the parameter value itself will be inserted directly.
[out] | outQry | returns the last executed query before either detecting an error or completing. |
|
protected |
Builds and executes a DELETE query to remove all items in the _removed list.
This function builds a DELETE statement using _modifyTableName and _removeByIdTableColName in order to create flexible queries for any table needed. Ids to be deleted are bound to "parameterN" for N = 0 to _removed.count() - 1 Returns the last query executed to allow for error reporting outside of a transaction block.
The delete statement will use the value returned by calling id() on each item in the _removed list to identify which records to remove. If the _removeByAltId flag is set to true, the statement will instead use the result of calling altId().
[out] | outQry | returns the executed query. |
|
inline |
|
inline |
Returns the _added list.
|
inline |
Returns the "available" tree.
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
Returns the _removed list.
|
inline |
Returns the "selected" tree.
void SelectionWidget::hideCancel | ( | ) |
Hides the cancel button.
void SelectionWidget::hideSelect | ( | ) |
Hides the select button.
|
inline |
|
protected |
Determines if 2 items are equal based on configured equality criteria.
This function checks the _equalityColumns list. For each name value pair entry, it checks the contents of the corresponding columns in each tree item and returns true only if they are the same for all entries in the list
|
signal |
|
signal |
|
protected |
Moves an item from one tree to another based on the value of pAdd.
Based on the value of pAdd, one tree is designated as a source, the other as a destination. Likewise _added and _removed are designated as either a check list or an append list. pXtitem is removed from the source tree. If pXtitem is NOT in the check list, it means this is a new change we must track. pXtitem is then added to the append list. If pXtitem IS present in the check list, it means the item was previously moved, and this move is merely undoing that action. Therefore, pXtitem is only removed from the check list and not added to the append list. Finally, pXtitem is added to the destination tree. The key idea here is that depending on pAdd, the append and check lists will switch places. So the list we add an item to in one direction, will be the list we check against when going in the opposite direction.
pXtitem | XTreeWidgetItem to be moved from one tree to another. |
pAdd | True when moving from "available" tree to "selected" tree, false otherwise. |
|
signal |
|
signal |
|
signal |
|
signal |
|
inlineinherited |
|
inlineinherited |
|
virtualslot |
Moves selected items from the "available" tree to the "selected" tree.
Emits addClickedBefore() and addClickedAfter() before and after moving an item respectively. Emits itemAdded() after each item is moved
|
virtualslot |
Moves all items from the "available" tree to the "selected" tree.
Emits addAllClickedBefore() and addAllClickedAfter() before and after moving an item respectively. Emits itemAdded() after each item is moved.
|
virtualslot |
Emits cancelClicked() signal.
|
virtualslot |
Calls functions to execute the appropriate INSERT and DELETE queries.
This function will call execAddQuery() and execRemoveQuery() then clear the _added and _removed lists. If the _parentInTrans flag is false, the calls to these functions will be wrapped in a transaction block to ensure atomicity. It is left to the caller to ensure that the _parentInTrans flag is set appropriately.
|
signal |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inlineinherited |
|
inlineinherited |
|
protectedslot |
Removes items from the "available" tree that are already in the "selected" tree.
This function iterates through the items in the "available" tree and for each, uses the isSameItem() function to find any items in the "selected" tree that match. If it finds any, the item is removed from the "available" tree.
void SelectionWidget::showCancel | ( | ) |
Shows the cancel button.
void SelectionWidget::showSelect | ( | ) |
Shows the select button.
|
virtualslot |
Moves selected items from the "selected" tree to the "available" tree.
Emits removeClickedBefore() and removeClickedAfter() before and after moving an item respectively. Emits itemRemoved() after each item is moved.
|
virtualslot |
Moves all items from the "selected" tree to the "available" tree.
Emits removeAllClickedBefore() and removeAllClickedAfter() before and after moving an item respectively. Emits itemRemoved() after each item is moved.
|
virtualslot |
Emits selectClicked() signal.
|
inherited |
|
inherited |
|
protected |
Name value pairs indicating column names and values to insert.
|
protected |
List of items added to "available" tree since loading.
|
inherited |
|
inherited |
|
inherited |
|
protected |
Name Value pairs indicating pairs of columns to be compared for equality.
|
protected |
Name of table where items will be added or removed.
|
protected |
When true, insert and delete statements will not be wrapped in a transaction block.
|
inherited |
|
inherited |
|
protected |
When true, delete statements use the item's altId instead of id.
|
protected |
Column name used as a key by the delete statement to remove records.
|
protected |
List of items removed from the "selected" tree since loading.
|
inherited |
|
inherited |
|
inherited |
|
inherited |
|
inherited |
|
inherited |
|
inherited |
Generated on Fri Apr 9 2021 | xTuple ERP Programmer Reference, Version 5.1.0 | 1.8.17 |