00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef KPTACCOUNT_H
00021 #define KPTACCOUNT_H
00022
00023 #include <qdatetime.h>
00024 #include <QHash>
00025 #include <QList>
00026 #include <qstringlist.h>
00027
00028 #include "kpteffortcostmap.h"
00029 #include "kptnode.h"
00030
00031 #include <kdebug.h>
00032
00033 class QDomElement;
00034 class QString;
00035
00036 namespace KPlato
00037 {
00038
00039 class Accounts;
00040 class Account;
00041
00042
00048 class Account
00049 {
00050 public:
00051
00055 Account();
00056
00060 Account(QString name, QString description=QString::null);
00061
00065 ~Account();
00066
00067
00068 QString name() const { return m_name; }
00069 void setName(QString name);
00070
00071 QString description() const { return m_description; }
00072 void setDescription(QString desc) { m_description = desc; }
00073
00074 bool isElement() const { return m_accountList.isEmpty(); }
00075
00076 Accounts *list() const { return m_list; }
00077 void setList(Accounts *list) { m_list = list; }
00078 Account *parent() const { return m_parent; }
00079 void setParent(Account *parent) { m_parent = parent; }
00080 void clear() { m_accountList.clear(); }
00081 void append(Account *account);
00082 void take(Account *account);
00083 void insertChildren();
00084
00085 bool load(QDomElement &element, Project &project);
00086 void save(QDomElement &element) const;
00087
00088 const QList<Account*> &accountList() const { return m_accountList; }
00089
00090 Account *findAccount() const { return findAccount(m_name); }
00091 Account *findAccount(const QString &id) const;
00092 bool removeId() { return removeId(m_name); }
00093 bool removeId(const QString &id);
00094 bool insertId();
00095 bool insertId(Account *account);
00096
00097 class CostPlace {
00098 public:
00099 CostPlace()
00100 : m_account(0), m_nodeId(), m_node(0), m_running(false), m_startup(false), m_shutdown(false)
00101 {}
00102 CostPlace(Account *acc)
00103 : m_account(acc), m_nodeId(), m_node(0), m_running(false), m_startup(false), m_shutdown(false)
00104 {}
00105 CostPlace(Account *acc, Node *node, bool running=false, bool strtup=false, bool shutdown=false)
00106 : m_account(acc), m_nodeId(node->id()), m_node(node) {
00107 if (node) {
00108 setRunning(running);
00109 setStartup(strtup);
00110 setShutdown(shutdown);
00111 }
00112 }
00113 CostPlace(CostPlace *cp) {
00114 m_account = cp->m_account;
00115 m_nodeId = cp->m_nodeId;
00116 m_node = cp->m_node;
00117 m_running = cp->m_running;
00118 m_startup = cp->m_startup;
00119 m_shutdown = cp->m_shutdown;
00120 }
00121 ~CostPlace();
00122
00123 bool isEmpty() { return !(m_running || m_startup || m_shutdown); }
00124 Node *node() const { return m_node; }
00125
00126 bool running() const { return m_running; }
00127 void setRunning(bool on );
00128 bool startup() const { return m_startup; }
00129 void setStartup(bool on);
00130 bool shutdown() const { return m_shutdown; }
00131 void setShutdown(bool on);
00132
00133 bool load(QDomElement &element, Project &project);
00134 void save(QDomElement &element) const;
00135
00136 private:
00137 Account *m_account;
00138 QString m_nodeId;
00139 Node *m_node;
00140 bool m_running;
00141 bool m_startup;
00142 bool m_shutdown;
00143 };
00144
00145 void append(CostPlace *cp) { m_costPlaces.append(cp); }
00146 const QList<CostPlace*> &costPlaces() const {return m_costPlaces; }
00147 Account::CostPlace *findCostPlace(const Node &node) const;
00148 CostPlace *findRunning(const Node &node) const;
00149 void removeRunning(const Node &node);
00150 void addRunning(Node &node);
00151 CostPlace *findStartup(const Node &node) const;
00152 void removeStartup(const Node &node);
00153 void addStartup(Node &node);
00154 CostPlace *findShutdown(const Node &node) const;
00155 void removeShutdown(const Node &node);
00156 void addShutdown(Node &node);
00157 void deleteCostPlace(CostPlace *cp);
00158 private:
00159 QString m_name;
00160 QString m_description;
00161 Accounts *m_list;
00162 Account *m_parent;
00163 QList<Account*> m_accountList;
00164 QList<CostPlace*> m_costPlaces;
00165
00166 #ifndef NDEBUG
00167 public:
00168 void printDebug(QString indent);
00169 #endif
00170 };
00171
00172 typedef QList<Account*> AccountList;
00173 typedef QListIterator<Account*> AccountListIterator;
00174
00179 class Accounts
00180 {
00181 public:
00182 Accounts(Project &project);
00183 ~Accounts();
00184
00185 Account *defaultAccount() const { return m_defaultAccount; }
00186 void setDefaultAccount(Account *account) { m_defaultAccount = account; }
00187
00188 EffortCostMap plannedCost(const Account &account, const QDate &start, const QDate &end);
00189
00190 void clear() { m_accountList.clear(); m_idDict.clear(); }
00191 void append(Account *account);
00192 void take(Account *account);
00193
00194 bool load(QDomElement &element, Project &project);
00195 void save(QDomElement &element) const;
00196
00197 QStringList costElements() const;
00198 QStringList nameList() const;
00199
00200 const AccountList &accountList() const { return m_accountList; }
00201
00202 Account *findRunningAccount(const Node &node) const;
00203 Account *findStartupAccount(const Node &node) const;
00204 Account *findShutdownAccount(const Node &node) const;
00205 Account *findAccount(const QString &id) const;
00206 bool insertId(Account *account);
00207 bool removeId(const QString &id);
00208
00209 void accountDeleted(Account *account)
00210 { if (account == m_defaultAccount) m_defaultAccount = 0; }
00211 private:
00212 Project &m_project;
00213 AccountList m_accountList;
00214 QHash<QString, Account*> m_idDict;
00215
00216 Account *m_defaultAccount;
00217
00218 #ifndef NDEBUG
00219 public:
00220 void printDebug(QString indent);
00221 #endif
00222 };
00223
00224 }
00225
00226 #endif