A item-based model for storing the chart of accounts. More...
#include <FdModelCoa.hpp>
Public Slots | |
QModelIndex | addItem (const QModelIndex &selected) |
void | removeSelected (QModelIndexList selected) |
void | recomputeBalances () |
Public Member Functions | |
FdModelCoa (FdSubWindow *parent) | |
FdModelCoa (FdSubWindow *parent, QDomElement &coa) | |
FdModelCoa (FdSubWindow *parent, const FdModelCoa *model) | |
FdItemCoa_p | getRootItem () const |
QVariant | data (FdItemCoa_p item, CoaColumn column) const |
QVariant | data (const QModelIndex &index, int role=Qt::DisplayRole) const |
void | setData (FdItemCoa_p, CoaColumn column, const QVariant &value) |
bool | setData (const QModelIndex &index, const QVariant &value, int role=Qt::EditRole) |
QVariant | headerData (int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const |
Qt::ItemFlags | flags (const QModelIndex &index) const |
Qt::DropActions | supportedDragActions () const |
Qt::DropActions | supportedDropActions () const |
QModelIndex | index (int row, int column, const QModelIndex &parent=QModelIndex()) const |
QModelIndex | index (FdItemCoa_p item) const |
QModelIndex | index (FdItemCoa_p item, CoaColumn column) const |
QModelIndex | parent (const QModelIndex &index) const |
QStringList | mimeTypes () const |
QMimeData * | mimeData (const QModelIndexList &indexes) const |
bool | dropMimeData (const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) |
int | rowCount (const QModelIndex &parent=QModelIndex()) const |
int | columnCount (const QModelIndex &parent=QModelIndex()) const |
bool | insertItem (FdItemCoa_p item, int row, FdItemCoa_p parent) |
bool | insertItems (QList< FdItemCoa_p > items, int row, FdItemCoa_p parent) |
bool | removeItem (FdItemCoa_p item, FdItemCoa_p parent) |
void | moveItem (FdItemCoa_p item, FdItemCoa_p parent, int row) |
void | orderItems (FdItemCoa_p parent=FdItemCoa_p(0)) |
FdItemCoa_p | item (const QModelIndex &index) const |
QAction * | redo () |
QAction * | undo () |
bool | idExists (QString id) const |
bool | labelExists (QString label) const |
bool | isAccountId (QString id) const |
bool | isAccountLabel (QString label) const |
bool | isRemovable (FdItemCoa_p item) const |
bool | isRemovable (const QModelIndex &index) const |
QStringList | accountsIds () const |
QStringList | accountsLabels () const |
QList< FdItemCoa_p > | accounts () const |
FdItemCoa_p | itemById (QString id) const |
FdItemCoa_p | itemByLabel (QString label) const |
QModelIndexList | itemByPartialText (QString text) const |
QDomElement | toXml (QDomDocument &document) const |
Protected Attributes | |
QUndoStack * | mStack |
Private Member Functions | |
void | init () |
Private Attributes | |
FdSubWindow * | mSubwindow |
FdItemCoa_p | mRootItem |
QMap< qint32, FdItemCoa_p > | mIndexes |
Friends | |
class | FdCoaAddItem |
class | FdCoaDragDrop |
class | FdCoaSetData |
class | FdCoaRemove |
A item-based model for storing the chart of accounts.
The chart of accounts consists in categories and accounts, with a tree structure. Each line of the tree widget is an item of either class FdItemCoa (with four columns).
New categories and accounts can be added to the COA calling addCategory() and addAccount().
FdItemCoa are stored in the tree using QSharedPointer FdItemCoa_p, this to make the implementation of the undo/redo framework easier. Items currently visible are mapped in the member mIndexes.
Definition at line 41 of file FdModelCoa.hpp.
|
explicit |
Creates undo/redo actions for the coa tab, calling QUndoStack::createUndoAction() and QUndoStack::createRedoAction().
Definition at line 29 of file FdModelCoa.cpp.
FdModelCoa::FdModelCoa | ( | FdSubWindow * | parent, |
QDomElement & | coa | ||
) |
Constructor to create an instance from data file.
Definition at line 38 of file FdModelCoa.cpp.
FdModelCoa::FdModelCoa | ( | FdSubWindow * | parent, |
const FdModelCoa * | model | ||
) |
Copy constructor to build a COA based on model.
This is no exact copy, it is used to create a new year accounting.
Definition at line 49 of file FdModelCoa.cpp.
QList< FdItemCoa_p > FdModelCoa::accounts | ( | ) | const |
Returns a list of all accounts (in user order).
Definition at line 592 of file FdModelCoa.cpp.
QStringList FdModelCoa::accountsIds | ( | ) | const |
Returns a QStringList containing the ids of all items of type #AccountType.
Definition at line 572 of file FdModelCoa.cpp.
QStringList FdModelCoa::accountsLabels | ( | ) | const |
Returns a QStringList containing the labels of all items of type #AccountType.
Definition at line 582 of file FdModelCoa.cpp.
|
slot |
Adds a new item under the parent selected. If selected is of type #AccountType and is already used in an entry (see FdModelJournal::isUsed()), the new item will be created under the parent of selected.
This action is undoable, see FdCoaAddItem.
Definition at line 643 of file FdModelCoa.cpp.
int FdModelCoa::columnCount | ( | const QModelIndex & | parent = QModelIndex() | ) | const |
Definition at line 363 of file FdModelCoa.cpp.
QVariant FdModelCoa::data | ( | FdItemCoa_p | item, |
CoaColumn | column | ||
) | const |
Definition at line 73 of file FdModelCoa.cpp.
QVariant FdModelCoa::data | ( | const QModelIndex & | index, |
int | role = Qt::DisplayRole |
||
) | const |
Definition at line 96 of file FdModelCoa.cpp.
bool FdModelCoa::dropMimeData | ( | const QMimeData * | data, |
Qt::DropAction | action, | ||
int | row, | ||
int | column, | ||
const QModelIndex & | parent | ||
) |
Handles items drop. This action is undoable, see FdCoaDragDrop.
Definition at line 326 of file FdModelCoa.cpp.
Qt::ItemFlags FdModelCoa::flags | ( | const QModelIndex & | index | ) | const |
Sets flags to items, to handle edition and drag/drop rights. The rules are :
Definition at line 206 of file FdModelCoa.cpp.
FdItemCoa_p FdModelCoa::getRootItem | ( | ) | const |
Definition at line 68 of file FdModelCoa.cpp.
QVariant FdModelCoa::headerData | ( | int | section, |
Qt::Orientation | orientation, | ||
int | role = Qt::DisplayRole |
||
) | const |
Definition at line 177 of file FdModelCoa.cpp.
bool FdModelCoa::idExists | ( | QString | id | ) | const |
Checks if an item with user defined id id exists.
Definition at line 487 of file FdModelCoa.cpp.
QModelIndex FdModelCoa::index | ( | int | row, |
int | column, | ||
const QModelIndex & | parent = QModelIndex() |
||
) | const |
Create an index for the item at row and column, with the given parent.
It calls QAbstractItemModel::createIndex(int row, int column, quint32 id), where id is the the unique identifier of the item stored in mIndexes.
Definition at line 239 of file FdModelCoa.cpp.
QModelIndex FdModelCoa::index | ( | FdItemCoa_p | item | ) | const |
Builds the QModelIndex of the item item in column 0.
Definition at line 254 of file FdModelCoa.cpp.
QModelIndex FdModelCoa::index | ( | FdItemCoa_p | item, |
CoaColumn | column | ||
) | const |
Builds the QModelIndex of the item item in column column.
This function, unlike index(int row, int column, const QModelIndex &parent), builds the index starting from an item, not a position in the tree.
Definition at line 264 of file FdModelCoa.cpp.
|
private |
Definition at line 55 of file FdModelCoa.cpp.
bool FdModelCoa::insertItem | ( | FdItemCoa_p | item, |
int | row, | ||
FdItemCoa_p | parent | ||
) |
Definition at line 368 of file FdModelCoa.cpp.
bool FdModelCoa::insertItems | ( | QList< FdItemCoa_p > | items, |
int | row, | ||
FdItemCoa_p | parent | ||
) |
Inserts the items under the given parent at position row.
Definition at line 376 of file FdModelCoa.cpp.
bool FdModelCoa::isAccountId | ( | QString | id | ) | const |
Returns true if the user defined id <id> corresponds to an item of type #AccountType, false otherwise.
Definition at line 510 of file FdModelCoa.cpp.
bool FdModelCoa::isAccountLabel | ( | QString | label | ) | const |
Returns true if the user defined label label corresponds to an item of type #AccountType, false otherwise.
Definition at line 522 of file FdModelCoa.cpp.
bool FdModelCoa::isRemovable | ( | FdItemCoa_p | item | ) | const |
Returns true if the item item can be removed. The rules are simple :
Definition at line 541 of file FdModelCoa.cpp.
bool FdModelCoa::isRemovable | ( | const QModelIndex & | index | ) | const |
Definition at line 560 of file FdModelCoa.cpp.
FdItemCoa_p FdModelCoa::item | ( | const QModelIndex & | index | ) | const |
Returns the item with the given index.
It retrieves the unique indentifier, mapping an item, stored in mIndexes. index() stores identifiers for all item in mIndexes.
Definition at line 457 of file FdModelCoa.cpp.
FdItemCoa_p FdModelCoa::itemById | ( | QString | id | ) | const |
Returns a #FdItemCoa_p, which is invalid if id does not exist. Therefore, the validity of the pointer returned by this function should always be tested calling QSharedPointer::isNull().
Definition at line 602 of file FdModelCoa.cpp.
FdItemCoa_p FdModelCoa::itemByLabel | ( | QString | label | ) | const |
Returns a #FdItemCoa_p, which is invalid if label does not exist. Therefore, the validity of the pointer returned by this function should always be tested calling QSharedPointer::isNull().
Definition at line 612 of file FdModelCoa.cpp.
QModelIndexList FdModelCoa::itemByPartialText | ( | QString | text | ) | const |
This function returns the index of the first item whose id or label contains text, or an invalid index if it founds nothing.
Definition at line 621 of file FdModelCoa.cpp.
bool FdModelCoa::labelExists | ( | QString | label | ) | const |
Checks if an item with label label already exists.
Definition at line 499 of file FdModelCoa.cpp.
QMimeData * FdModelCoa::mimeData | ( | const QModelIndexList & | indexes | ) | const |
This function doesn't serialise the items. It simply stores in a QMimeData the identifiers (see mIndexes) of dragged items.
In this class, drag and drop of items is a simple change of owner. There are no destruction/creation.
Definition at line 303 of file FdModelCoa.cpp.
QStringList FdModelCoa::mimeTypes | ( | ) | const |
Definition at line 293 of file FdModelCoa.cpp.
void FdModelCoa::moveItem | ( | FdItemCoa_p | item, |
FdItemCoa_p | parent, | ||
int | row | ||
) |
Moves an item under the given parent, to row row.
Definition at line 414 of file FdModelCoa.cpp.
void FdModelCoa::orderItems | ( | FdItemCoa_p | parent = FdItemCoa_p(0) | ) |
Orders items by id under parent.
Definition at line 423 of file FdModelCoa.cpp.
QModelIndex FdModelCoa::parent | ( | const QModelIndex & | index | ) | const |
Definition at line 280 of file FdModelCoa.cpp.
|
slot |
Recomputes all accounts and categories balances.
Definition at line 705 of file FdModelCoa.cpp.
QAction * FdModelCoa::redo | ( | ) |
Creates redo action for the tab.
Definition at line 470 of file FdModelCoa.cpp.
bool FdModelCoa::removeItem | ( | FdItemCoa_p | item, |
FdItemCoa_p | parent | ||
) |
There exists no removeItems() function, to better handle uncontiguous selections.
Definition at line 398 of file FdModelCoa.cpp.
|
slot |
Removes the selected items from the chart of accounts.
This functions get a QModelIndexList which contains indexes of items to be removed. selected can't contain a child's and parent's (recursively up to the top) index at the same time (see FdViewCoa::selectedItems()).
Definition at line 687 of file FdModelCoa.cpp.
int FdModelCoa::rowCount | ( | const QModelIndex & | parent = QModelIndex() | ) | const |
Definition at line 358 of file FdModelCoa.cpp.
void FdModelCoa::setData | ( | FdItemCoa_p | item, |
CoaColumn | column, | ||
const QVariant & | value | ||
) |
Definition at line 118 of file FdModelCoa.cpp.
bool FdModelCoa::setData | ( | const QModelIndex & | index, |
const QVariant & | value, | ||
int | role = Qt::EditRole |
||
) |
Handles user modification of the item fields, calld automatically by the view (FdViewCoa).
This function filters user input. It rejects :
Definition at line 152 of file FdModelCoa.cpp.
Qt::DropActions FdModelCoa::supportedDragActions | ( | ) | const |
Definition at line 224 of file FdModelCoa.cpp.
Qt::DropActions FdModelCoa::supportedDropActions | ( | ) | const |
Definition at line 229 of file FdModelCoa.cpp.
QDomElement FdModelCoa::toXml | ( | QDomDocument & | document | ) | const |
Sets the undostack as cleaned.
Definition at line 631 of file FdModelCoa.cpp.
QAction * FdModelCoa::undo | ( | ) |
Creates undo action for the tab.
Definition at line 478 of file FdModelCoa.cpp.
|
friend |
Definition at line 45 of file FdModelCoa.hpp.
|
friend |
Definition at line 46 of file FdModelCoa.hpp.
|
friend |
Definition at line 48 of file FdModelCoa.hpp.
|
friend |
Definition at line 47 of file FdModelCoa.hpp.
|
private |
The FdItemCoa_p pointer to each visible item are stored in this member, mapped to a unique qint32 identifier. This identifier is copied in an QModelIndex (see index()).
Definition at line 62 of file FdModelCoa.hpp.
|
private |
The base, invisible item of the tree. Access function :
Definition at line 57 of file FdModelCoa.hpp.
|
protected |
Definition at line 66 of file FdModelCoa.hpp.
|
private |
Definition at line 51 of file FdModelCoa.hpp.