Commit 33571cb6 authored by Ralf Habacker's avatar Ralf Habacker
Browse files

Modified the code to select a diagram for use at multiple locations

The new widget class is named 'SelectDiagramWidget'.

CCBUG:53369
parent d6a8aee3
......@@ -247,6 +247,7 @@ set(libdialogs_SRCS
dialogs/widgets/documentationwidget.cpp
dialogs/widgets/imagetypewidget.cpp
dialogs/widgets/resolutionwidget.cpp
dialogs/widgets/selectdiagramwidget.cpp
dialogs/widgets/umlartifacttypewidget.cpp
dialogs/widgets/umldatatypewidget.cpp
dialogs/widgets/defaultvaluewidget.cpp
......
......@@ -19,6 +19,7 @@
#include "umlviewlist.h"
#include "umldoc.h"
#include "uml.h"
#include "selectdiagramwidget.h"
#include "statewidget.h"
#include "dialog_utils.h"
#include "icon_utils.h"
......@@ -92,13 +93,7 @@ void StateDialog::applyPage(KPageWidgetItem*item)
m_bChangesMade = true;
if (item == pageGeneral) {
if (m_pStateWidget->stateType() == StateWidget::Combined) {
QString name = m_GenPageWidgets.diagramLinkCB->currentText();
Uml::ID::Type id;
foreach (UMLView *view, UMLApp::app()->document()->viewIterator()) {
if (name == view->umlScene()->name())
id = view->umlScene()->ID();
}
m_pStateWidget->setDiagramLink(id);
m_pStateWidget->setDiagramLink(m_GenPageWidgets.diagramLinkWidget->currentID());
}
m_pStateWidget->setName(m_GenPageWidgets.nameLE->text());
m_GenPageWidgets.docWidget->apply();
......@@ -190,28 +185,11 @@ void StateDialog::setupGeneralPage()
m_GenPageWidgets.nameLE->setText(m_pStateWidget->name());
if (type == StateWidget::Combined) {
m_GenPageWidgets.diagramLinkL = new QLabel(i18n("Linked diagram:"));
generalLayout->addWidget(m_GenPageWidgets.diagramLinkL, row, 0);
m_GenPageWidgets.diagramLinkCB = new KComboBox;
generalLayout->addWidget(m_GenPageWidgets.diagramLinkCB, row++, 1);
QStringList diagrams;
QString name;
foreach (UMLView *view, UMLApp::app()->document()->viewIterator()) {
if (view->umlScene()->ID() == m_pStateWidget->diagramLink())
name = view->umlScene()->name();
if (view->umlScene()->ID() == m_pStateWidget->umlScene()->ID())
continue;
diagrams << view->umlScene()->name();
}
diagrams.sort();
m_GenPageWidgets.diagramLinkCB->insertItems(-1, diagrams);
int currentIndex = m_GenPageWidgets.diagramLinkCB->findText(name);
if (currentIndex > -1) {
m_GenPageWidgets.diagramLinkCB->setCurrentIndex(currentIndex);
}
m_GenPageWidgets.diagramLinkCB->completionObject()->addItem(name);
m_GenPageWidgets.diagramLinkWidget = new SelectDiagramWidget(i18n("Linked diagram:"), this);
m_GenPageWidgets.diagramLinkWidget->setupWidget(Uml::DiagramType::State,
m_pStateWidget->linkedDiagram() ? m_pStateWidget->linkedDiagram()->name() : QString(),
m_pStateWidget->umlScene()->name(), false);
m_GenPageWidgets.diagramLinkWidget->addToLayout(generalLayout, row++);
}
m_GenPageWidgets.docWidget = new DocumentationWidget(m_pStateWidget);
......
......@@ -17,6 +17,7 @@
//forward declarations
class ActivityPage;
class DocumentationWidget;
class SelectDiagramWidget;
class StateWidget;
class KComboBox;
class KLineEdit;
......@@ -57,8 +58,8 @@ protected:
bool m_bChangesMade; ///< holds whether changes in the dialog have been made
struct GeneralPageWidgets {
QLabel * nameL, * typeL, * diagramLinkL;
KComboBox *diagramLinkCB;
QLabel * nameL, * typeL;
SelectDiagramWidget *diagramLinkWidget;
KLineEdit * nameLE, * typeLE;
DocumentationWidget *docWidget;
QGroupBox * generalGB;
......
/***************************************************************************
* 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) 2019 *
* Umbrello UML Modeller Authors <umbrello-devel@kde.org> *
***************************************************************************/
#include "selectdiagramwidget.h"
#include "uml.h"
#include "umldoc.h"
#include "umlscene.h"
#include "umlview.h"
#include <KComboBox>
#include <KLocalizedString>
#include <QLabel>
#include <QHBoxLayout>
/**
* constructor
* @param title title shown as label
* @param parent parent widget
*/
SelectDiagramWidget::SelectDiagramWidget(const QString &title, QWidget *parent)
: QWidget(parent)
{
QHBoxLayout *layout = new QHBoxLayout;
layout->setContentsMargins(0,0,0,0);
m_label = new QLabel(title, this);
layout->addWidget(m_label);
m_editField = new KComboBox(this);
m_editField->setEditable(true);
layout->addWidget(m_editField, 2);
setLayout(layout);
}
/**
* setup widget woth diagram type, currently used diagram, diagram name to exclude and an option to choose a new diagram
* @param type
* @param currentName
* @param excludeName
* @param withNewEntry
*/
void SelectDiagramWidget::setupWidget(Uml::DiagramType::Enum type, const QString &currentName, const QString &excludeName, bool withNewEntry)
{
QStringList diagrams;
foreach (UMLView *view, UMLApp::app()->document()->viewIterator()) {
QString name = view->umlScene()->name();
if (name == excludeName)
continue;
if (type == Uml::DiagramType::Undefined || type == view->umlScene()->type())
diagrams << name;
m_editField->completionObject()->addItem(name);
}
diagrams.sort();
if (withNewEntry)
diagrams.push_front(i18n("New"));
m_editField->clear();
m_editField->insertItems(-1, diagrams);
int currentIndex = m_editField->findText(currentName);
if (currentIndex > -1) {
m_editField->setCurrentIndex(currentIndex);
}
}
/**
* 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 SelectDiagramWidget::addToLayout(QGridLayout *layout, int row)
{
layout->addWidget(m_label, row, 0);
layout->addWidget(m_editField, row, 1);
}
/**
* Return current text
* @return The text entered by the user
*/
QString SelectDiagramWidget::currentText()
{
return m_editField->currentText();
}
/**
* Return the id of the currently selected diagram
* @return id of diagram
* @return Uml::ID::None in case the diagram was not found
*/
Uml::ID::Type SelectDiagramWidget::currentID()
{
QString name = m_editField->currentText();
foreach (UMLView *view, UMLApp::app()->document()->viewIterator()) {
if (name == view->umlScene()->name())
return view->umlScene()->ID();
}
return Uml::ID::None;
}
/***************************************************************************
* 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) 2019 *
* Umbrello UML Modeller Authors <umbrello-devel@kde.org> *
***************************************************************************/
#ifndef SELECTDIAGRAMWIDGET_H
#define SELECTDIAGRAMWIDGET_H
#include "basictypes.h"
#include <QWidget>
class KComboBox;
class QGridLayout;
class QLabel;
/**
* This widget provides selecting a diagram from the list of currently available diagrams
* @author Ralf Habacker
*/
class SelectDiagramWidget : public QWidget
{
Q_OBJECT
public:
explicit SelectDiagramWidget(const QString &title, QWidget *parent = nullptr);
void setupWidget(Uml::DiagramType::Enum type, const QString &currentName, const QString &excludeName, bool withNewEntry = true);
void addToLayout(QGridLayout *layout, int row);
QString currentText();
Uml::ID::Type currentID();
protected:
QLabel *m_label;
KComboBox *m_editField;
};
#endif // SELECTDIAGRAMWIDGET_H
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment