summaryrefslogtreecommitdiffstats
path: root/kmymoney2/views/kaccountsview.h
blob: 96c547aa9f29f5266f20029cae71d9943c1afd9b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
/***************************************************************************
                             kaccountssview.h
                             -------------------
    copyright            : (C) 2005 by Thomas Baumgart
    email                : [email protected]
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#ifndef KACCOUNTSSVIEW_H
#define KACCOUNTSSVIEW_H

// ----------------------------------------------------------------------------
// QT Includes

// ----------------------------------------------------------------------------
// KDE Includes

#include <kiconview.h>

// ----------------------------------------------------------------------------
// Project Includes

#include <kmymoney/mymoneyaccount.h>
#include <kmymoney/kmymoneyaccounttree.h>
#include <kmymoney/mymoneyutils.h>
class TDEListViewSearchLineWidget;

#include "../views/kaccountsviewdecl.h"

/**
  * @author Thomas Baumgart
  */

/**
  * This class represents an item in the account icon view. It is used
  * by the KAccountsView to select between the accounts using icons.
  */
class KMyMoneyAccountIconItem : public KIconViewItem
{
public:
  /**
    * Constructor to be used to construct an account icon object.
    *
    * @param parent pointer to the KIconView object this entry should be
    *               added to.
    * @param account const reference to MyMoneyAccount for which
    *               the KIconView entry is constructed
    */
  KMyMoneyAccountIconItem(TQIconView *parent, const MyMoneyAccount& account);
  ~KMyMoneyAccountIconItem();

  /**
    * This method is loads new information into the item and updates the fields
    *
    * @param account the account data for the object to be updated
    *
    * @note if account.id() is not equal to the current account id
    *       then this method returns immediately
    */
  void updateAccount(const MyMoneyAccount& account);

  const MyMoneyObject& itemObject(void) const { return m_account; };

  void setReconciliation(bool);

protected:

private:
  MyMoneyAccount        m_account;
  bool                  m_reconcileFlag;
};




/**
  * This class implements the accounts hierarchical and iconic 'view'.
  */
class KAccountsView : public KAccountsViewDecl
{
  Q_OBJECT
  
private:

public:
  KAccountsView(TQWidget *parent=0, const char *name=0);
  virtual ~KAccountsView();

public slots:
  void slotLoadAccounts(void);

  /**
    * Override the base class behaviour to include all updates that
    * happened in the meantime.
    */
  void show(void);

  /**
   * Override the base class behaviour to restore the layout. Do not
   * do this in show() because show() itself may change the layout
   * in undesired ways.
   */
  void polish(void);

  /**
    * update the account objects if their icon position has changed since
    * the last time.
    *
    * @param action must be KMyMoneyView::preSave, otherwise this slot is a NOP.
    */
  void slotUpdateIconPos(unsigned int action);

  void slotReconcileAccount(const MyMoneyAccount& acc, const TQDate& reconciliationDate, const MyMoneyMoney& endingBalance);

protected:
  typedef enum {
    ListView = 0,
    IconView,
    // insert new values above this line
    MaxViewTabs
  } AccountsViewTab;

  /**
    * This method loads the accounts for the respective tab.
    *
    * @param tab which tab should be loaded
    */
  void loadAccounts(AccountsViewTab tab);
  void loadListView(void);
  void loadIconView(void);

  bool loadSubAccounts(KMyMoneyAccountTreeItem* parent, const TQStringList& accountList);

  /**
    * This method returns a pointer to the currently selected
    * account icon or 0 if no icon is selected.
    */
  KMyMoneyAccountIconItem* selectedIcon(void) const;

  TQPoint point(const TQString& str) const;
  TQString point(const TQPoint& val) const;

protected slots:
  void slotUpdateNetWorth(void);
  void slotTabChanged(TQWidget*);
  void slotSelectIcon(TQIconViewItem* item);
  void slotOpenContext(TQIconViewItem* item);
  void slotOpenObject(TQIconViewItem* item);
  void slotExpandCollapse(void);

signals:
  /**
    * This signal serves as proxy for KMyMoneyAccountTree::selectObject()
    *
    * @param obj const reference to object
    */
  void selectObject(const MyMoneyObject& obj);

  /**
    * This signal serves as proxy for
    * KMyMoneyAccountTree::openContextMenu(const MyMoneyObject&)
    *
    * @param obj const reference to object
    */
  void openContextMenu(const MyMoneyObject& obj);

  /**
    * This signal will be emitted when the left mouse button is double
    * clicked (actually the KDE executed setting is used) on an object.
    *
    * @param obj const reference to object
    */
  void openObject(const MyMoneyObject& obj);

  /**
    * This signal is emitted, when the user selected to reparent the
    * account @p acc to be a subordinate account of @p parent.
    *
    * @param acc const reference to account to be reparented
    * @param parent const reference to new parent account
    */
  void reparent(const MyMoneyAccount& acc, const MyMoneyAccount& parent);

private:
  MyMoneyAccount                      m_reconciliationAccount;
  TQMap<TQString, MyMoneySecurity>      m_securityMap;
  TQMap<TQString, unsigned long>        m_transactionCountMap;

  KMyMoneyAccountTreeItem*            m_assetItem;
  KMyMoneyAccountTreeItem*            m_liabilityItem;

  /**
   * Search widget for the list
   */
  TDEListViewSearchLineWidget*  m_searchWidget;

  /// set if a view needs to be reloaded during show()
  bool                                m_needReload[MaxViewTabs];
  bool                                m_haveUnusedCategories;
};

#endif