PageRenderTime 40ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/src/data/BasicData.cpp

http://github.com/gregsmirnov/bouml
C++ | 259 lines | 180 code | 48 blank | 31 comment | 31 complexity | faab065eeb9bce14f82fcc2a69b15627 MD5 | raw file
Possible License(s): GPL-2.0
  1. // *************************************************************************
  2. //
  3. // Copyright 2004-2010 Bruno PAGES .
  4. //
  5. // This file is part of the BOUML Uml Toolkit.
  6. //
  7. // This program is free software; you can redistribute it and/or modify
  8. // it under the terms of the GNU General Public License as published by
  9. // the Free Software Foundation; either version 2 of the License, or
  10. // (at your option) any later version.
  11. //
  12. // This program is distributed in the hope that it will be useful,
  13. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. // GNU General Public License for more details.
  16. //
  17. // You should have received a copy of the GNU General Public License
  18. // along with this program; if not, write to the Free Software
  19. // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  20. //
  21. // e-mail : bouml@free.fr
  22. // home : http://bouml.free.fr
  23. //
  24. // *************************************************************************
  25. #include "BasicData.h"
  26. #include "BrowserNode.h"
  27. #include "myio.h"
  28. #include "ToolCom.h"
  29. #include "mu.h"
  30. BasicParent BasicParent::the;
  31. void BasicParent::insertChild(QObject *){
  32. // does nothing !
  33. }
  34. void BasicParent::removeChild(QObject *){
  35. // does nothing !
  36. }
  37. //
  38. QList<BasicData> BasicData::removed;
  39. BasicData::BasicData(const BasicData * model)
  40. : QObject(&BasicParent::the), browser_node(0) {
  41. stereotype = model->stereotype;
  42. }
  43. BasicData::~BasicData() {
  44. }
  45. // does not really delete it for undelete management
  46. void BasicData::delete_it() {
  47. if (!deletedp()) {
  48. set_deletedp(TRUE);
  49. emit deleted();
  50. removed.append(this);
  51. }
  52. }
  53. void BasicData::undelete(QString &, QString &) {
  54. if (deletedp()) {
  55. set_deletedp(FALSE);
  56. emit changed();
  57. removed.removeRef(this);
  58. }
  59. }
  60. void BasicData::resignal_deleted()
  61. {
  62. BasicData * d;
  63. for (d = removed.last(); d != 0; d = removed.prev())
  64. d->redelete_it();
  65. }
  66. void BasicData::on_delete() {
  67. browser_node->on_delete();
  68. }
  69. void BasicData::modified() {
  70. emit changed();
  71. }
  72. //
  73. const char * BasicData::get_short_stereotype() const {
  74. const char * s = stereotype;
  75. const char * p = strchr(s, ':');
  76. return (p != 0) ? p+1 : s;
  77. }
  78. bool BasicData::set_stereotype(const QString & s) {
  79. bool result = ((const char *) stereotype != s);
  80. stereotype = s;
  81. if (browser_node != 0)
  82. browser_node->update_stereotype();
  83. return result;
  84. }
  85. bool BasicData::set_stereotype(const QCString & s) {
  86. bool result = ((const char *) stereotype != s);
  87. stereotype = s;
  88. if (browser_node != 0)
  89. browser_node->update_stereotype();
  90. return result;
  91. }
  92. bool BasicData::set_stereotype(const char * s) {
  93. bool result = ((const char *) stereotype != s);
  94. stereotype = s;
  95. if (browser_node != 0)
  96. browser_node->update_stereotype();
  97. return result;
  98. }
  99. void BasicData::set_browser_node(BrowserNode * bn) {
  100. browser_node = bn;
  101. bn->update_stereotype();
  102. }
  103. QString BasicData::definition(bool, bool with_kind) const {
  104. return (with_kind)
  105. ? "[" + browser_node->get_stype() + "] " + browser_node->get_name()
  106. : QString(browser_node->get_name());
  107. }
  108. bool BasicData::decldefbody_contain(const QString &, bool,
  109. BrowserNode *) {
  110. return FALSE;
  111. }
  112. void BasicData::save(QTextStream & st, QString &) const {
  113. if (! stereotype.isEmpty()) {
  114. nl_indent(st);
  115. st << "stereotype ";
  116. save_string(stereotype, st);
  117. }
  118. }
  119. void BasicData::read(char * & st, char * & k) {
  120. if (!strcmp(k, "stereotype")) {
  121. set_stereotype(read_string(st));
  122. k = read_keyword(st);
  123. }
  124. else
  125. set_stereotype(QString::null);
  126. }
  127. //
  128. void BasicData::send_uml_def(ToolCom * com, BrowserNode * bn,
  129. const QString & comment) {
  130. if (browser_node != 0) {
  131. BrowserNode * d = browser_node->get_associated();
  132. if (d != browser_node) {
  133. // may have an associated diagram/view
  134. if ((d != 0) && !d->deletedp())
  135. d->write_id(com);
  136. else
  137. com->write_id(0);
  138. }
  139. }
  140. com->write_string(stereotype);
  141. ((HaveKeyValueData *) bn)->send_def(com);
  142. com->write_string(comment);
  143. int api = com->api_format();
  144. if (api > 11) {
  145. com->write_bool(bn->markedp());
  146. if (api > 30)
  147. com->write_unsigned(bn->get_identifier());
  148. }
  149. }
  150. void BasicData::send_cpp_def(ToolCom *) {
  151. }
  152. void BasicData::send_java_def(ToolCom *) {
  153. }
  154. void BasicData::send_php_def(ToolCom *) {
  155. }
  156. void BasicData::send_python_def(ToolCom *) {
  157. }
  158. void BasicData::send_idl_def(ToolCom *) {
  159. }
  160. bool BasicData::tool_cmd(ToolCom * com, const char * args,
  161. BrowserNode * bn, const QString & comment) {
  162. switch ((unsigned char) args[-1]) {
  163. case setStereotypeCmd:
  164. if (!bn->is_writable() && !root_permission())
  165. com->write_ack(FALSE);
  166. else {
  167. set_stereotype(args);
  168. browser_node->package_modified();
  169. modified();
  170. com->write_ack(TRUE);
  171. }
  172. break;
  173. case getDefCmd:
  174. send_uml_def(com, bn, comment);
  175. send_cpp_def(com);
  176. send_java_def(com);
  177. if (com->api_format() >= 34) {
  178. send_php_def(com);
  179. if (com->api_format() >= 39)
  180. send_python_def(com);
  181. }
  182. send_idl_def(com);
  183. break;
  184. case getUmlDefCmd:
  185. send_uml_def(com, bn, comment);
  186. break;
  187. case getCppDefCmd:
  188. send_uml_def(com, bn, comment);
  189. send_cpp_def(com);
  190. break;
  191. case getJavaDefCmd:
  192. send_uml_def(com, bn, comment);
  193. send_java_def(com);
  194. break;
  195. case getPhpDefCmd:
  196. send_uml_def(com, bn, comment);
  197. send_php_def(com);
  198. break;
  199. case getPythonDefCmd:
  200. send_uml_def(com, bn, comment);
  201. send_python_def(com);
  202. break;
  203. case getIdlDefCmd:
  204. send_uml_def(com, bn, comment);
  205. send_idl_def(com);
  206. break;
  207. default:
  208. return FALSE;
  209. }
  210. return TRUE;
  211. }