1 /*
2     SPDX-License-Identifier: GPL-2.0-or-later
3     SPDX-FileCopyrightText: 2002-2020 Umbrello UML Modeller Authors <umbrello-devel@kde.org>
4 */
5 
6 // own header
7 #include "diagrampropertiespage.h"
8 
9 // local includes
10 #include "uml.h"
11 #include "umldoc.h"
12 #include "umlscene.h"
13 #include "umlview.h"
14 
15 // kde includes
16 #include <KMessageBox>
17 
18 // qt includes
19 
20 /**
21  * Constructor
22  * @param parent   the parent (wizard) of this wizard page
23  * @param scene    the UMLScene to which the properties apply
24  */
DiagramPropertiesPage(QWidget * parent,UMLScene * scene)25 DiagramPropertiesPage::DiagramPropertiesPage(QWidget *parent, UMLScene *scene)
26   : DialogPageBase(parent), m_scene(scene)
27 {
28     setupUi(this);
29 
30     ui_diagramName->setText(scene->name());
31     ui_zoom->setValue(scene->activeView()->zoom());
32 
33     ui_checkBoxShowGrid->setChecked(scene->isSnapGridVisible());
34     ui_snapToGrid->setChecked(scene->snapToGrid());
35     ui_snapComponentSizeToGrid->setChecked(scene->snapComponentSizeToGrid());
36 
37     ui_gridSpaceX->setValue(scene->snapX());
38     ui_gridSpaceY->setValue(scene->snapY());
39     ui_documentation->setText(scene->documentation());
40     if (scene->isSequenceDiagram() || scene->isCollaborationDiagram()) {
41         ui_autoIncrementSequence->setVisible(true);
42         ui_autoIncrementSequence->setChecked(scene->autoIncrementSequence());
43     } else {
44         ui_autoIncrementSequence->setVisible(false);
45     }
46 }
47 
48 /**
49  * destructor
50  */
~DiagramPropertiesPage()51 DiagramPropertiesPage::~DiagramPropertiesPage()
52 {
53 }
54 
55 /**
56  * sets default values
57  */
setDefaults()58 void DiagramPropertiesPage::setDefaults()
59 {
60 }
61 
62 /**
63  Checks whether the diagram name is unique and sets it if it is.
64 */
checkUniqueDiagramName()65 bool DiagramPropertiesPage::checkUniqueDiagramName()
66 {
67     // check name
68     QString newName = ui_diagramName->text();
69     if (newName.length() == 0) {
70         KMessageBox::sorry(this, i18n("The name you have entered is invalid."),
71                            i18n("Invalid Name"), 0);
72         ui_diagramName->setText(m_scene->name());
73         return false;
74     }
75 
76     if (newName != m_scene->name()) {
77         UMLDoc* doc = UMLApp::app()->document();
78         UMLView* view = doc->findView(m_scene->type(), newName);
79         if (view) {
80             KMessageBox::sorry(this, i18n("The name you have entered is not unique."),
81                                i18n("Name Not Unique"), 0);
82             ui_diagramName->setText(m_scene->name());
83         }
84         else {
85             // uDebug() << "Cannot find view with name " << newName;
86             m_scene->setName(newName);
87             doc->signalDiagramRenamed(m_scene->activeView());
88             return true;
89         }
90     }
91     return false;
92 }
93 
94 /**
95  * Reads the set values from their corresponding widgets, writes them back to
96  * the data structure, and notifies clients.
97  */
apply()98 void DiagramPropertiesPage::apply()
99 {
100     checkUniqueDiagramName();
101     m_scene->activeView()->setZoom(ui_zoom->value());
102     m_scene->setDocumentation(ui_documentation->toPlainText());
103     m_scene->setSnapSpacing(ui_gridSpaceX->value(), ui_gridSpaceY->value());
104     m_scene->setSnapToGrid(ui_snapToGrid->isChecked());
105     m_scene->setSnapComponentSizeToGrid(ui_snapComponentSizeToGrid->isChecked());
106     m_scene->setSnapGridVisible(ui_checkBoxShowGrid->isChecked());
107     if (m_scene->isSequenceDiagram() || m_scene->isCollaborationDiagram()) {
108         m_scene->setAutoIncrementSequence(ui_autoIncrementSequence->isChecked());
109     }
110     emit applyClicked();
111 }
112