File: ClassViewDialog.cpp

package info (click to toggle)
bouml 4.21-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 73,336 kB
  • ctags: 55,459
  • sloc: cpp: 290,644; makefile: 228; sh: 13
file content (237 lines) | stat: -rw-r--r-- 6,655 bytes parent folder | download
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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
// *************************************************************************
//
// Copyright 2004-2010 Bruno PAGES  .
//
// This file is part of the BOUML Uml Toolkit.
//
// 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.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//
// e-mail : bouml@free.fr
// home   : http://bouml.free.fr
//
// *************************************************************************





#include <qgrid.h> 
#include <qlabel.h>
#include <qpushbutton.h>
#include <qcombobox.h> 
#include <qvbox.h> 

#include "ClassViewDialog.h"
#include "BasicData.h"
#include "BrowserClassView.h"
#include "BrowserDeploymentView.h"
#include "UmlWindow.h"
#include "DialogUtil.h"
#include "KeyValueTable.h"
#include "UmlDesktop.h"
#include "BodyDialog.h"
#include "strutil.h"
#include "ProfiledStereotypes.h"
#include "translate.h"

QSize ClassViewDialog::previous_size;

ClassViewDialog::ClassViewDialog(BasicData * nd)
    : QTabDialog(0, 0, FALSE, WDestructiveClose), data(nd) {
  nd->get_browser_node()->edit_start();
  
  if (nd->get_browser_node()->is_writable()) {
    setOkButton(TR("OK"));
    setCancelButton(TR("Cancel"));
  }
  else {
    setOkButton(QString::null);
    setCancelButton(TR("Close"));
  }

  setCaption(TR("class view dialog"));

  bool visit = !hasOkButton();
  
  // general tab
  
  BrowserClassView * bn = (BrowserClassView *) data->get_browser_node();
  QGrid * grid = new QGrid(2, this);

  umltab = grid;
  grid->setMargin(5);
  grid->setSpacing(5);

  new QLabel(TR("name : "), grid);
  edname = new LineEdit(bn->get_name(), grid);
  edname->setReadOnly(visit);
    
  new QLabel(TR("stereotype : "), grid);
  edstereotype = new QComboBox(!visit, grid);
  edstereotype->insertItem(toUnicode(data->get_stereotype()));
  if (!visit) {
    edstereotype->insertStringList(BrowserClassView::default_stereotypes());
    edstereotype->insertStringList(ProfiledStereotypes::defaults(UmlClassView));
    edstereotype->setAutoCompletion(completion());
  }
  edstereotype->setCurrentItem(0);
  QSizePolicy sp = edstereotype->sizePolicy();
  sp.setHorData(QSizePolicy::Expanding);
  edstereotype->setSizePolicy(sp);
  
  BrowserNode * bcv = bn->get_associated();
  
  if (visit) {
    if ((bcv != 0) && !bcv->deletedp()) {
      new QLabel(TR("deployment\nview : "), grid);
      deploymentview = new QComboBox(FALSE, grid);
      
      BrowserNode * bcv = bn->get_associated();
      
      deploymentview->insertItem(bcv->full_name(TRUE));
      deploymentview->setCurrentItem(0);
    }
    else
      deploymentview = 0;
  }
  else {
    BrowserDeploymentView::instances(deploymentviews);
    if (!deploymentviews.isEmpty()) {
      QStringList deploymentview_names;
      
      deploymentviews.full_names(deploymentview_names);
      new QLabel(TR("deployment\nview : "), grid);
      deploymentview = new QComboBox(FALSE, grid);
      deploymentview->insertItem("");
      deploymentview->insertStringList(deploymentview_names);
      
      if (bcv != 0) {
	if (bcv->deletedp()) {
	  QString fn = bcv->full_name(TRUE);
	  
	  deploymentview->insertItem(fn);
	  deploymentviews.append(bcv);
	  deploymentview->setCurrentItem(deploymentviews.count());
	}
	else
	  deploymentview->setCurrentItem(deploymentviews.find(bcv) + 1);
      }
      else
	deploymentview->setCurrentItem(0);
    }
    else
      deploymentview = 0;
  }
    
  QVBox * vtab = new QVBox(grid);
  new QLabel(TR("description :"), vtab);
  if (!visit)
    connect(new SmallPushButton(TR("Editor"), vtab), SIGNAL(clicked()),
	    this, SLOT(edit_description()));
  comment = new MultiLineEdit(grid);
  comment->setReadOnly(visit);
  comment->setText(bn->get_comment());
  QFont font = comment->font();
  if (! hasCodec())
    font.setFamily("Courier");
  font.setFixedPitch(TRUE);
  comment->setFont(font);
  
  addTab(grid, "Uml");
  
  // USER : list key - value
  
  grid = new QGrid(2, this);
  grid->setMargin(5);
  grid->setSpacing(5);
  
  kvtable = new KeyValuesTable(bn, grid, visit);
  addTab(grid, TR("Properties"));
  
  //
    
  connect(this, SIGNAL(currentChanged(QWidget *)),
	  this, SLOT(change_tabs(QWidget *)));
  
  open_dialog(this);
}

void ClassViewDialog::polish() {
  QTabDialog::polish();
  UmlDesktop::limitsize_move(this, previous_size, 0.8, 0.8);
}

ClassViewDialog::~ClassViewDialog() {
  data->get_browser_node()->edit_end();
  previous_size = size();
  
  while (!edits.isEmpty())
    edits.take(0)->close();
  
  close_dialog(this);
}

void ClassViewDialog::change_tabs(QWidget * w) {
  if (hasOkButton() && (w == umltab))
    edname->setFocus();
}

void ClassViewDialog::edit_description() {
  edit(comment->text(), edname->text().stripWhiteSpace() + "_description",
       data, TxtEdit, this, (post_edit) post_edit_description, edits);
}

void ClassViewDialog::post_edit_description(ClassViewDialog * d, QString s) {
  d->comment->setText(s);
}

void ClassViewDialog::accept() {
  if (!check_edits(edits) || !kvtable->check_unique())
    return;
    
  QString s = edname->text().stripWhiteSpace();
  BrowserClassView * bn = (BrowserClassView *) data->get_browser_node();
  
  if ((s != bn->get_name()) &&
      ((BrowserNode *) bn->parent())->wrong_child_name(s, bn->get_type(),
						       bn->allow_spaces(),
						       bn->allow_empty()))
    msg_critical(TR("Error"), edname->text() + TR("\n\nillegal name or already used"));
  else {  
    bn->set_name(s);
    
    bool newst = data->set_stereotype(fromUnicode(edstereotype->currentText().stripWhiteSpace()));
    
    if (deploymentview != 0) {
      int index = deploymentview->currentItem();
      
      bn->set_associated_deploymentview((index == 0)
				       ? 0 // "" : no deploymentview
				       : ((BrowserDeploymentView *) deploymentviews.at(index - 1)));
    }
    
    bn->set_comment(comment->text());
    UmlWindow::update_comment_if_needed(bn);
    
    kvtable->update(bn);
  
    ProfiledStereotypes::modified(bn, newst);
    
    data->modified();
    bn->package_modified();
    
    QTabDialog::accept();
  }
}