1 /*
2 SPDX-License-Identifier: GPL-2.0-or-later
3 SPDX-FileCopyrightText: 2003-2020 Umbrello UML Modeller Authors <umbrello-devel@kde.org>
4 */
5
6 // own header
7 #include "classpropertiesdialog.h"
8
9 // app includes
10 #include "classassociationspage.h"
11 #include "classgeneralpage.h"
12 #include "classifierlistpage.h"
13 #include "classifierwidget.h"
14 #include "classoptionspage.h"
15 #include "componentwidget.h"
16 #include "constraintlistpage.h"
17 #include "debug_utils.h"
18 #include "entity.h"
19 #include "objectwidget.h"
20 #include "packagecontentspage.h"
21 #include "uml.h"
22 #include "umldoc.h"
23 #include "umlobject.h"
24 #include "umlview.h"
25 #include "umlwidgetstylepage.h"
26
27 // kde includes
28 #include <KLocalizedString>
29
30 // qt includes
31 #include <QFrame>
32 #include <QHBoxLayout>
33
34 /**
35 * Sets up a ClassPropDialog.
36 *
37 * @param parent The parent of the ClassPropDialog
38 * @param c The UMLObject to display properties of.
39 * @param assoc Determines whether to display associations
40 */
ClassPropertiesDialog(QWidget * parent,UMLObject * c,bool assoc)41 ClassPropertiesDialog::ClassPropertiesDialog(QWidget *parent, UMLObject * c, bool assoc)
42 : MultiPageDialogBase(parent)
43 {
44 init();
45 m_pWidget = 0;
46 m_pObject = c;
47
48 setupPages(assoc);
49
50 connect(this, SIGNAL(okClicked()), this, SLOT(slotOk()));
51 connect(this, SIGNAL(applyClicked()), this, SLOT(slotApply()));
52 }
53
54 /**
55 * Sets up a ClassPropDialog.
56 *
57 * @param parent The parent of the ClassPropDialog
58 * @param o The ObjectWidget to display properties of.
59 */
ClassPropertiesDialog(QWidget * parent,ObjectWidget * o)60 ClassPropertiesDialog::ClassPropertiesDialog(QWidget *parent, ObjectWidget *o)
61 : MultiPageDialogBase(parent)
62 {
63 init();
64 m_pWidget = o;
65 m_pObject = m_pWidget->umlObject();
66 m_doc = UMLApp::app()->document();
67
68 setupGeneralPage();
69 setupStylePage(m_pWidget);
70 setupFontPage(m_pWidget);
71
72 setMinimumSize(340, 420);
73 connect(this, SIGNAL(okClicked()), this, SLOT(slotOk()));
74 connect(this, SIGNAL(applyClicked()), this, SLOT(slotApply()));
75 }
76
77 /**
78 * Sets up a ClassPropDialog.
79 *
80 * @param parent The parent of the ClassPropDialog
81 * @param w The UMLWidget to display properties of.
82 */
ClassPropertiesDialog(QWidget * parent,UMLWidget * w)83 ClassPropertiesDialog::ClassPropertiesDialog(QWidget *parent, UMLWidget *w)
84 : MultiPageDialogBase(parent)
85 {
86 init();
87 m_pWidget = w;
88 m_pObject = w->umlObject();
89
90 if (w->isClassWidget()
91 || w->isInterfaceWidget()
92 || w->isEnumWidget()
93 || w->isPackageWidget()) {
94 setupPages(true);
95 } else if (w->isComponentWidget()) {
96 if (w->isInstance()) {
97 setupInstancePages();
98 } else {
99 setupPages(true);
100 }
101 } else if (w->isNodeWidget()) {
102 setupInstancePages();
103 } else {
104 setupPages();
105 }
106
107 // now setup the options page for classes
108 if (w->isClassWidget() || w->isInterfaceWidget()) {
109 setupDisplayPage();
110 }
111 setupStylePage(m_pWidget);
112 setupFontPage(m_pWidget);
113 connect(this, SIGNAL(okClicked()), this, SLOT(slotOk()));
114 connect(this, SIGNAL(applyClicked()), this, SLOT(slotApply()));
115 }
116
init()117 void ClassPropertiesDialog::init()
118 {
119 setCaption(i18n("Properties"));
120 m_pAssocPage = 0;
121 m_pGenPage = 0;
122 m_pAttPage = 0;
123 m_pOpsPage = 0;
124 m_pPkgContentsPage = 0;
125 m_pTemplatePage = 0;
126 m_pEnumLiteralPage = 0;
127 m_pEntityAttributePage = 0;
128 m_pEntityConstraintPage = 0;
129 m_pOptionsPage = 0;
130 m_doc = UMLApp::app()->document();
131 }
132
133 /**
134 * Standard destructor.
135 */
~ClassPropertiesDialog()136 ClassPropertiesDialog::~ClassPropertiesDialog()
137 {
138 }
139
140 /**
141 * Calls slotApply()
142 */
apply()143 void ClassPropertiesDialog::apply()
144 {
145 slotApply();
146 }
147
148 /**
149 * Calls slotApply() and accepts (closes) the dialog.
150 */
slotOk()151 void ClassPropertiesDialog::slotOk()
152 {
153 slotApply();
154 accept();
155 }
156
157 /**
158 * Applies the settings in the dialog to the widget and object.
159 */
slotApply()160 void ClassPropertiesDialog::slotApply()
161 {
162 if (m_pGenPage) {
163 m_pGenPage->apply();
164 }
165 if (m_pAttPage) {
166 m_pAttPage->apply();
167 }
168 if (m_pOpsPage) {
169 m_pOpsPage->apply();
170 }
171 if (m_pTemplatePage) {
172 m_pTemplatePage->apply();
173 }
174 if (m_pEnumLiteralPage) {
175 m_pEnumLiteralPage->apply();
176 }
177 if (m_pEntityAttributePage) {
178 m_pEntityAttributePage->apply();
179 }
180 if (m_pEntityConstraintPage) {
181 m_pEntityConstraintPage->apply();
182 }
183 if (m_pOptionsPage) {
184 m_pOptionsPage->apply();
185 }
186 if (m_pStylePage) {
187 m_pStylePage->apply();
188 }
189 if (m_pWidget) {
190 applyFontPage(m_pWidget);
191 }
192 }
193
194 /**
195 * Sets up the general, attribute, operations, template and association pages as appropriate.
196 */
setupPages(bool assoc)197 void ClassPropertiesDialog::setupPages(bool assoc)
198 {
199 setupGeneralPage();
200
201 UMLObject::ObjectType ot = UMLObject::ot_UMLObject;
202 if (m_pObject) {
203 ot = m_pObject->baseType();
204 }
205 // add extra pages for class
206 if (ot == UMLObject::ot_Class) {
207 setupAttributesPage();
208 }
209 if (ot == UMLObject::ot_Class || ot == UMLObject::ot_Interface) {
210 setupOperationsPage();
211 }
212 if (ot == UMLObject::ot_Class || ot == UMLObject::ot_Interface) {
213 setupTemplatesPage();
214 }
215 if (ot == UMLObject::ot_Enum) {
216 setupEnumLiteralsPage();
217 }
218 if (ot == UMLObject::ot_Entity) {
219 setupEntityAttributesPage();
220 setupEntityConstraintsPage();
221 if (m_pWidget && m_pWidget->isEntityWidget())
222 setupEntityDisplayPage(m_pWidget->asEntityWidget());
223 }
224 if (ot == UMLObject::ot_Package) {
225 setupContentsPage();
226 }
227 if (assoc) {
228 setupAssociationsPage();
229 } else {
230 m_pAssocPage = 0;
231 }
232 }
233
234 /**
235 * Sets up the page "General" for the component.
236 */
setupGeneralPage()237 void ClassPropertiesDialog::setupGeneralPage()
238 {
239 if (m_pWidget && m_pWidget->baseType() == UMLWidget::wt_Object)
240 m_pGenPage = new ClassGeneralPage(m_doc, 0, static_cast<ObjectWidget*>(m_pWidget));
241 else if (m_pWidget && !m_pObject)
242 m_pGenPage = new ClassGeneralPage(m_doc, 0, m_pWidget);
243 else
244 m_pGenPage = new ClassGeneralPage(m_doc, 0, m_pObject);
245 createPage(i18nc("general settings page name", "General"), i18n("General Settings"),
246 Icon_Utils::it_Properties_General, m_pGenPage)->widget()->setMinimumSize(310, 330);
247 m_pGenPage->setFocus();
248 }
249
250 /**
251 * Sets up the page "Display" for the component.
252 */
setupDisplayPage()253 void ClassPropertiesDialog::setupDisplayPage()
254 {
255 ClassifierWidget *cw = m_pWidget->asClassifierWidget();
256 m_pOptionsPage = new ClassOptionsPage(0, cw);
257 createPage(i18nc("display option page name", "Display"), i18n("Display Options"),
258 Icon_Utils::it_Properties_Display, m_pOptionsPage);
259 }
260
261 /**
262 * Sets up the page "Display" for the component.
263 */
setupEntityDisplayPage(EntityWidget * widget)264 void ClassPropertiesDialog::setupEntityDisplayPage(EntityWidget *widget)
265 {
266 m_pOptionsPage = new ClassOptionsPage(0, widget);
267 createPage(i18nc("display option page name", "Display"), i18n("Display Options"),
268 Icon_Utils::it_Properties_Display, m_pOptionsPage);
269 }
270
271 /**
272 * Sets up the page "Attributes" for the component.
273 */
setupAttributesPage()274 void ClassPropertiesDialog::setupAttributesPage()
275 {
276 m_pAttPage = new ClassifierListPage(0, (UMLClassifier *)m_pObject, m_doc, UMLObject::ot_Attribute);
277 createPage(i18n("Attributes"), i18n("Attribute Settings"),
278 Icon_Utils::it_Properties_Attributes, m_pAttPage);
279 }
280
281 /**
282 * Sets up the page "Operations" for the component.
283 */
setupOperationsPage()284 void ClassPropertiesDialog::setupOperationsPage()
285 {
286 m_pOpsPage = new ClassifierListPage(0, (UMLClassifier*)m_pObject, m_doc, UMLObject::ot_Operation);
287 createPage(i18n("Operations"), i18n("Operation Settings"),
288 Icon_Utils::it_Properties_Operations, m_pOpsPage);
289 }
290
291 /**
292 * Sets up the page "Templates" for the component.
293 */
setupTemplatesPage()294 void ClassPropertiesDialog::setupTemplatesPage()
295 {
296 m_pTemplatePage = new ClassifierListPage(0, (UMLClassifier *)m_pObject, m_doc, UMLObject::ot_Template);
297 createPage(i18n("Templates"), i18n("Templates Settings"),
298 Icon_Utils::it_Properties_Templates, m_pTemplatePage);
299 }
300
301 /**
302 * Sets up the page "Enum Literals" for the component.
303 */
setupEnumLiteralsPage()304 void ClassPropertiesDialog::setupEnumLiteralsPage()
305 {
306 m_pEnumLiteralPage = new ClassifierListPage(0, (UMLClassifier*)m_pObject, m_doc, UMLObject::ot_EnumLiteral);
307 createPage(i18n("Enum Literals"), i18n("Enum Literals Settings"),
308 Icon_Utils::it_Properties_EnumLiterals, m_pEnumLiteralPage);
309 }
310
311 /**
312 * Sets up the page "Entity Attributes" for the component.
313 */
setupEntityAttributesPage()314 void ClassPropertiesDialog::setupEntityAttributesPage()
315 {
316 m_pEntityAttributePage = new ClassifierListPage(0, (UMLEntity*)m_pObject, m_doc, UMLObject::ot_EntityAttribute);
317 createPage(i18n("Entity Attributes"), i18n("Entity Attributes Settings"),
318 Icon_Utils::it_Properties_EntityAttributes, m_pEntityAttributePage);
319 }
320
321 /**
322 * Sets up the page "Entity Constraints" for the component.
323 */
setupEntityConstraintsPage()324 void ClassPropertiesDialog::setupEntityConstraintsPage()
325 {
326 m_pEntityConstraintPage = new ConstraintListPage(0, (UMLClassifier*)m_pObject, m_doc, UMLObject::ot_EntityConstraint);
327 createPage(i18n("Entity Constraints"), i18n("Entity Constraints Settings"),
328 Icon_Utils::it_Properties_EntityConstraints, m_pEntityConstraintPage);
329 }
330
331 /**
332 * Sets up the page "Contents" for the component.
333 */
setupContentsPage()334 void ClassPropertiesDialog::setupContentsPage()
335 {
336 m_pPkgContentsPage = new PackageContentsPage(0, (UMLPackage*)m_pObject);
337 createPage(i18nc("contents settings page name", "Contents"), i18n("Contents Settings"),
338 Icon_Utils::it_Properties_Contents, m_pPkgContentsPage);
339 }
340
341 /**
342 * Sets up the page "Associations" for the component.
343 */
setupAssociationsPage()344 void ClassPropertiesDialog::setupAssociationsPage()
345 {
346 m_pAssocPage = new ClassAssociationsPage(0, UMLApp::app()->currentView()->umlScene(), m_pObject);
347 createPage(i18n("Associations"), i18n("Class Associations"),
348 Icon_Utils::it_Properties_Associations, m_pAssocPage);
349 }
350
351 /**
352 * Sets up the general page for the component.
353 */
setupInstancePages()354 void ClassPropertiesDialog::setupInstancePages()
355 {
356 m_pGenPage = new ClassGeneralPage(m_doc, 0, m_pWidget);
357 createPage(i18nc("instance general settings page name", "General"), i18n("General Settings"),
358 Icon_Utils::it_Properties_General, m_pGenPage)->widget()->setMinimumSize(310, 330);
359 m_pAssocPage = 0;
360 }
361
362