FreeDebks  1.0.3
 All Classes Files Functions Variables Friends Pages
Public Slots | Public Member Functions | Protected Attributes | Private Member Functions | Private Attributes | Friends | List of all members
FdModelCoa Class Reference

A item-based model for storing the chart of accounts. More...

#include <FdModelCoa.hpp>

Collaboration diagram for FdModelCoa:
Collaboration graph
[legend]

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

FdSubWindowmSubwindow
FdItemCoa_p mRootItem
QMap< qint32, FdItemCoa_p > mIndexes

Friends

class FdCoaAddItem
class FdCoaDragDrop
class FdCoaSetData
class FdCoaRemove

Detailed Description

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.

Remarks
When changing the number of columns, it is necessary to update #CoaColumn enum, headerData(), data() and setData(). To handle specific column behaviour, it may be necessary to update flags() and some other members of FdViewCoa.

Definition at line 41 of file FdModelCoa.hpp.

Constructor & Destructor Documentation

FdModelCoa::FdModelCoa ( FdSubWindow parent)
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.

Member Function Documentation

QList< FdItemCoa_p > FdModelCoa::accounts ( ) const

Returns a list of all accounts (in user order).

See Also
FdItemCoa::childrenAccounts()

Definition at line 592 of file FdModelCoa.cpp.

QStringList FdModelCoa::accountsIds ( ) const

Returns a QStringList containing the ids of all items of type #AccountType.

See Also
FdItemCoa::childrenAccountsIds()

Definition at line 572 of file FdModelCoa.cpp.

QStringList FdModelCoa::accountsLabels ( ) const

Returns a QStringList containing the labels of all items of type #AccountType.

See Also
FdItemCoa::childrenAccountsLabels()

Definition at line 582 of file FdModelCoa.cpp.

QModelIndex FdModelCoa::addItem ( const QModelIndex &  selected)
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 :

  • Item of type #AccountType can't be droped on, ie the can't have children.
  • #CoaInitial can't be modified for #CategoryType.
  • #CoaSigns can't be modified for #CategoryType.
  • #CoaBalance can't be modified.

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.

Returns
true if there exists an item with id id, false otherwise.

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.

void FdModelCoa::init ( )
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 :

  • An account can be removed if
    • its initial balance is 0
    • its previous balance is 0
    • it is used in no entry.
  • A category can be removed all of its children account can be removed.
See Also
FdItemJournal::isUsed()

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().

See Also
FdItemCoa::childById().

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().

See Also
FdItemCoa::childByLabel().

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.

Returns
true if there exists an item with label label, false otherwise.

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.

void FdModelCoa::recomputeBalances ( )
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.

void FdModelCoa::removeSelected ( QModelIndexList  selected)
slot

Removes the selected items from the chart of accounts.

See Also
FdModelCoa::isRemovable().

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 :

  • blank value
  • duplicate id
  • duplicate label
  • modification of the current balance

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.

Friends And Related Function Documentation

friend class FdCoaAddItem
friend

Definition at line 45 of file FdModelCoa.hpp.

friend class FdCoaDragDrop
friend

Definition at line 46 of file FdModelCoa.hpp.

friend class FdCoaRemove
friend

Definition at line 48 of file FdModelCoa.hpp.

friend class FdCoaSetData
friend

Definition at line 47 of file FdModelCoa.hpp.

Member Data Documentation

QMap<qint32, FdItemCoa_p> FdModelCoa::mIndexes
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.

FdItemCoa_p FdModelCoa::mRootItem
private

The base, invisible item of the tree. Access function :

Definition at line 57 of file FdModelCoa.hpp.

QUndoStack* FdModelCoa::mStack
protected

Definition at line 66 of file FdModelCoa.hpp.

FdSubWindow* FdModelCoa::mSubwindow
private

Definition at line 51 of file FdModelCoa.hpp.


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