summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRalf Habacker <[email protected]>2014-12-09 16:53:23 +0100
committerAndi Fischer <[email protected]>2014-12-11 21:16:33 +0100
commit272b5a0367d250f394851d755e6bcc0466427c40 (patch)
treecea4873f1f1bcf522748bbf4119b17099dbb9ee8
parent3d83fa922390634c8cf423a0cd28bbfeda41d749 (diff)
Use UMLArtifactTypeWidget for artifact type editing.
CCBUG:97291
-rw-r--r--umbrello/CMakeLists.txt1
-rw-r--r--umbrello/dialogs/pages/classgeneralpage.cpp44
-rw-r--r--umbrello/dialogs/pages/classgeneralpage.h4
-rw-r--r--umbrello/dialogs/widgets/umlartifacttypewidget.cpp77
-rw-r--r--umbrello/dialogs/widgets/umlartifacttypewidget.h42
5 files changed, 126 insertions, 42 deletions
diff --git a/umbrello/CMakeLists.txt b/umbrello/CMakeLists.txt
index 4a12957..37ea972 100644
--- a/umbrello/CMakeLists.txt
+++ b/umbrello/CMakeLists.txt
@@ -222,6 +222,7 @@ set(libdialogs_SRCS
dialogs/pages/diagramprintpage.cpp
dialogs/pages/umlroleproperties.cpp
dialogs/pages/umlwidgetstylepage.cpp
+ dialogs/widgets/umlartifacttypewidget.cpp
dialogs/widgets/umlstereotypewidget.cpp
dialogs/widgets/umlobjectnamewidget.cpp
dialogs/widgets/umlpackagewidget.cpp
diff --git a/umbrello/dialogs/pages/classgeneralpage.cpp b/umbrello/dialogs/pages/classgeneralpage.cpp
index 4fdf3e9..870a8e6 100644
--- a/umbrello/dialogs/pages/classgeneralpage.cpp
+++ b/umbrello/dialogs/pages/classgeneralpage.cpp
@@ -32,6 +32,7 @@
#include "umlobjectnamewidget.h"
#include "umlpackagewidget.h"
#include "umlstereotypewidget.h"
+#include "umlartifacttypewidget.h"
// kde includes
#include <KLocalizedString>
@@ -167,35 +168,8 @@ ClassGeneralPage::ClassGeneralPage(UMLDoc* d, QWidget* parent, UMLObject* o)
}
if (t == UMLObject::ot_Artifact) {
- // setup artifact draw as
- m_pDrawAsGB = new QGroupBox(i18n("Draw As"), this);
- QHBoxLayout* drawAsLayout = new QHBoxLayout(m_pDrawAsGB);
- drawAsLayout->setMargin(margin);
-
- m_pDefaultRB = new QRadioButton(i18nc("draw as default", "&Default"), m_pDrawAsGB);
- drawAsLayout->addWidget(m_pDefaultRB);
-
- m_pFileRB = new QRadioButton(i18n("&File"), m_pDrawAsGB);
- drawAsLayout->addWidget(m_pFileRB);
-
- m_pLibraryRB = new QRadioButton(i18n("&Library"), m_pDrawAsGB);
- drawAsLayout->addWidget(m_pLibraryRB);
-
- m_pTableRB = new QRadioButton(i18n("&Table"), m_pDrawAsGB);
- drawAsLayout->addWidget(m_pTableRB);
-
- topLayout->addWidget(m_pDrawAsGB);
-
- UMLArtifact::Draw_Type drawAs = (static_cast<UMLArtifact*>(o))->getDrawAsType();
- if (drawAs == UMLArtifact::file) {
- m_pFileRB->setChecked(true);
- } else if (drawAs == UMLArtifact::library) {
- m_pLibraryRB->setChecked(true);
- } else if (drawAs == UMLArtifact::table) {
- m_pTableRB->setChecked(true);
- } else {
- m_pDefaultRB->setChecked(true);
- }
+ m_artifactTypeWidget = new UMLArtifactTypeWidget(static_cast<UMLArtifact*>(o));
+ m_artifactTypeWidget->addToLayout(topLayout);
}
// setup scope
@@ -417,17 +391,7 @@ void ClassGeneralPage::updateObject()
}
if (m_pObject->baseType() == UMLObject::ot_Artifact) {
- UMLArtifact::Draw_Type drawAsType;
- if (m_pFileRB->isChecked()) {
- drawAsType = UMLArtifact::file;
- } else if (m_pLibraryRB->isChecked()) {
- drawAsType = UMLArtifact::library;
- } else if (m_pTableRB->isChecked()) {
- drawAsType = UMLArtifact::table;
- } else {
- drawAsType = UMLArtifact::defaultDraw;
- }
- (static_cast<UMLArtifact*>(m_pObject))->setDrawAsType(drawAsType);
+ m_artifactTypeWidget->apply();
m_pObject->emitModified();
}
} // end if m_pObject
diff --git a/umbrello/dialogs/pages/classgeneralpage.h b/umbrello/dialogs/pages/classgeneralpage.h
index 5f64401..1dbea77 100644
--- a/umbrello/dialogs/pages/classgeneralpage.h
+++ b/umbrello/dialogs/pages/classgeneralpage.h
@@ -25,6 +25,7 @@ class UMLObject;
class UMLWidget;
class ObjectWidget;
class UMLDoc;
+class UMLArtifactTypeWidget;
class UMLObjectNameWidget;
class UMLPackageWidget;
class UMLStereotypeWidget;
@@ -87,13 +88,12 @@ private:
QRadioButton * m_pPublicRB, * m_pPrivateRB, * m_pProtectedRB, * m_pImplementationRB;
QCheckBox * m_pMultiCB, * m_pDrawActorCB, * m_pAbstractCB, * m_pDeconCB;
KTextEdit * m_doc;
- QGroupBox * m_pDrawAsGB;
- QRadioButton * m_pDefaultRB, * m_pFileRB, * m_pLibraryRB, * m_pTableRB;
QCheckBox * m_pExecutableCB;
UMLObjectNameWidget *m_nameWidget;
UMLObjectNameWidget *m_instanceNameWidget;
UMLStereotypeWidget *m_stereotypeWidget;
UMLPackageWidget *m_packageWidget;
+ UMLArtifactTypeWidget *m_artifactTypeWidget;
void insertStereotypesSorted(const QString& type);
diff --git a/umbrello/dialogs/widgets/umlartifacttypewidget.cpp b/umbrello/dialogs/widgets/umlartifacttypewidget.cpp
new file mode 100644
index 0000000..0fdbb33
--- /dev/null
+++ b/umbrello/dialogs/widgets/umlartifacttypewidget.cpp
@@ -0,0 +1,77 @@
+/***************************************************************************
+ * 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. *
+ * *
+ * copyright (C) 2002-2014 *
+ * Umbrello UML Modeller Authors <[email protected]> *
+ ***************************************************************************/
+
+#include "umlartifacttypewidget.h"
+
+#include "uml.h"
+
+#include <KLocalizedString>
+
+#include <QHBoxLayout>
+#include <QGroupBox>
+#include <QRadioButton>
+
+typedef QMap<UMLArtifact::Draw_Type,QString> Map;
+
+UMLArtifactTypeWidget::UMLArtifactTypeWidget(UMLArtifact *a, QWidget *parent) :
+ QWidget(parent),
+ m_object(a)
+{
+ Map texts;
+
+ texts[UMLArtifact::file] = i18n("&File");
+ texts[UMLArtifact::library] = i18n("&Library");
+ texts[UMLArtifact::table] = i18n("&Table");
+ texts[UMLArtifact::defaultDraw] = i18nc("draw as default", "&Default");
+
+ QHBoxLayout *layout = new QHBoxLayout;
+ layout->setContentsMargins(0,0,0,0);
+
+ m_box = new QGroupBox(i18n("Draw As"), this);
+ QHBoxLayout* drawAsLayout = new QHBoxLayout(m_box );
+ int margin = fontMetrics().height();
+ drawAsLayout->setMargin(margin);
+
+ for(Map::const_iterator i = texts.constBegin(); i != texts.constEnd(); i++) {
+ QRadioButton *button = new QRadioButton(i.value(), m_box );
+ m_buttons[i.key()] = button;
+ drawAsLayout->addWidget(button);
+ }
+ m_buttons[a->getDrawAsType()]->setChecked(true);
+ layout->addWidget(m_box);
+ setLayout(layout);
+}
+
+UMLArtifactTypeWidget::~UMLArtifactTypeWidget()
+{
+ delete m_box;
+}
+
+/**
+ * Add this widget to a given grid layout. Umbrello dialogs places labels in column 0
+ * and the editable field in column 1.
+ * @param layout The layout to which the widget should be added
+ * @param row The row in the grid layout where the widget should be placed
+ */
+void UMLArtifactTypeWidget::addToLayout(QVBoxLayout *layout)
+{
+ layout->addWidget(m_box);
+}
+
+/**
+ * Apply changes to the related UMLObject.
+ */
+void UMLArtifactTypeWidget::apply()
+{
+ for(ButtonMap::const_iterator i = m_buttons.constBegin(); i != m_buttons.constEnd(); i++) {
+ if (i.value()->isChecked())
+ m_object->setDrawAsType(i.key());
+ }
+}
diff --git a/umbrello/dialogs/widgets/umlartifacttypewidget.h b/umbrello/dialogs/widgets/umlartifacttypewidget.h
new file mode 100644
index 0000000..f9b9c2b
--- /dev/null
+++ b/umbrello/dialogs/widgets/umlartifacttypewidget.h
@@ -0,0 +1,42 @@
+/***************************************************************************
+ * 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. *
+ * *
+ * copyright (C) 2002-2014 *
+ * Umbrello UML Modeller Authors <[email protected]> *
+ ***************************************************************************/
+
+#ifndef UMLARTIFACTTYPEWIDGET_H
+#define UMLARTIFACTTYPEWIDGET_H
+
+#include "artifact.h"
+
+#include <QMap>
+#include <QWidget>
+
+class QVBoxLayout;
+class QGroupBox;
+class QRadioButton;
+
+class UMLArtifactTypeWidget : public QWidget
+{
+ Q_OBJECT
+public:
+ typedef QMap<UMLArtifact::Draw_Type,QRadioButton*> ButtonMap;
+
+ UMLArtifactTypeWidget(UMLArtifact *a, QWidget *parent = 0);
+ ~UMLArtifactTypeWidget();
+
+ void addToLayout(QVBoxLayout *layout);
+ void apply();
+
+protected:
+ QGroupBox *m_box;
+ UMLArtifact *m_object;
+ ButtonMap m_buttons;
+
+};
+
+#endif // UMLARTIFACTTYPEWIDGET_H