Commit a5b5a46a authored by Ralf Habacker's avatar Ralf Habacker

Move operation properties dialog related setup and applying code into class SelectOperationDialog

Dialog setup from widget/umlobject and applying to them was implemented
in client code (class FloatingTextWidget) instead of the related dialog
class, which makes it hard to reuse the operation properties dialog from
other locations.

CCBUG:390507
parent 57cabe23
......@@ -15,6 +15,7 @@
#include "attribute.h"
#include "classifier.h"
#include "debug_utils.h"
#include "linkwidget.h"
#include "operation.h"
#include "umlclassifierlistitemlist.h"
#include "umlscene.h"
......@@ -47,11 +48,13 @@ bool caseInsensitiveLessThan(const UMLOperation *s1, const UMLOperation *s2)
* @param c The concept to get the operations from.
* @param enableAutoIncrement Flag to enable auto increment checkbox
*/
SelectOperationDialog::SelectOperationDialog(UMLView *parent, UMLClassifier * c, bool enableAutoIncrement)
SelectOperationDialog::SelectOperationDialog(UMLView *parent, UMLClassifier * c, LinkWidget *widget, bool enableAutoIncrement)
: SinglePageDialogBase(parent),
m_id(CUSTOM),
m_pView(parent),
m_classifier(c)
m_classifier(c),
m_widget(widget),
m_enableAutoIncrement(enableAutoIncrement)
{
setCaption(i18n("Select Operation"));
......@@ -101,6 +104,7 @@ SelectOperationDialog::SelectOperationDialog(UMLView *parent, UMLClassifier * c,
mainLayout->addWidget(m_pOpLE, 2, 1, 1, 2);
setupOperationsList();
enableButtonOk(false);
setupDialog();
}
/**
......@@ -270,3 +274,67 @@ bool SelectOperationDialog::autoIncrementSequence()
{
return m_pOpAS->isChecked();
}
/**
* internal setup function
*/
void SelectOperationDialog::setupDialog()
{
if (m_enableAutoIncrement && m_pView->umlScene()->autoIncrementSequence()) {
setAutoIncrementSequence(true);
setSeqNumber(m_pView->umlScene()->autoIncrementSequenceValue());
} else
setSeqNumber(m_widget->sequenceNumber());
if (m_widget->operation() == 0) {
setCustomOp(m_widget->lwOperationText());
} else {
setClassOp(m_widget->lwOperationText());
}
}
/**
* apply changes to the related instamces
* @return true - success
* @return false - failure
*/
bool SelectOperationDialog::apply()
{
QString opText = getOpText();
if (isClassOp()) {
Model_Utils::OpDescriptor od;
Model_Utils::Parse_Status st = Model_Utils::parseOperation(opText, od, m_classifier);
if (st == Model_Utils::PS_OK) {
UMLClassifierList selfAndAncestors = m_classifier->findSuperClassConcepts();
selfAndAncestors.prepend(m_classifier);
UMLOperation *op = 0;
foreach (UMLClassifier *cl, selfAndAncestors) {
op = cl->findOperation(od.m_name, od.m_args);
if (op) {
break;
}
}
if (!op) {
// The op does not yet exist. Create a new one.
UMLObject *o = m_classifier->createOperation(od.m_name, 0, &od.m_args);
op = o->asUMLOperation();
}
if (od.m_pReturnType) {
op->setType(od.m_pReturnType);
}
m_widget->setOperation(op);
opText.clear();
} else {
m_widget->setOperation(0);
}
} else {
m_widget->setOperation(0);
}
m_widget->setSequenceNumber(getSeqNumber());
m_widget->setOperationText(opText);
if (m_enableAutoIncrement) {
m_pView->umlScene()->setAutoIncrementSequence(autoIncrementSequence());
}
return true;
}
......@@ -20,6 +20,7 @@ class QGroupBox;
class QLabel;
class UMLClassifier;
class UMLView;
class LinkWidget;
/**
* A dialog used to select an operation.
......@@ -32,7 +33,7 @@ class SelectOperationDialog : public SinglePageDialogBase
{
Q_OBJECT
public:
SelectOperationDialog(UMLView * parent, UMLClassifier * c, bool enableAutoIncrement = true);
SelectOperationDialog(UMLView * parent, UMLClassifier * c, LinkWidget *widget, bool enableAutoIncrement = true);
~SelectOperationDialog();
QString getOpText();
......@@ -48,7 +49,10 @@ public:
void setCustomOp(const QString &op);
bool setClassOp(const QString &op);
bool apply();
protected:
void setupDialog();
void setupOperationsList();
private:
......@@ -67,6 +71,8 @@ private:
int m_id; ///< takes on the value OP or CUSTOM according to what the user selected
UMLView *m_pView;
UMLClassifier *m_classifier;
LinkWidget *m_widget;
bool m_enableAutoIncrement;
public slots:
void slotAutoIncrementChecked(bool state);
......
......@@ -231,64 +231,15 @@ bool FloatingTextWidget::showOperationDialog(bool enableAutoIncrement)
uError() << "m_linkWidget is NULL";
return false;
}
QString seqNum = m_linkWidget->sequenceNumber();
UMLClassifier* c = m_linkWidget->lwClassifier();
QString opText = m_linkWidget->lwOperationText();
if (!c) {
if (!m_linkWidget->lwClassifier()) {
uError() << "m_linkWidget->lwClassifier() returns a NULL classifier";
return false;
}
bool result = false;
QPointer<SelectOperationDialog> selectDialog = new SelectOperationDialog(m_scene->activeView(), c, enableAutoIncrement);
if (enableAutoIncrement && m_scene->autoIncrementSequence()) {
seqNum = m_scene->autoIncrementSequenceValue();
selectDialog->setAutoIncrementSequence(true);
}
selectDialog->setSeqNumber(seqNum);
if (m_linkWidget->operation() == 0) {
selectDialog->setCustomOp(opText);
} else {
selectDialog->setClassOp(opText);
}
QPointer<SelectOperationDialog> selectDialog = new SelectOperationDialog(m_scene->activeView(), m_linkWidget->lwClassifier(), m_linkWidget, enableAutoIncrement);
if (selectDialog->exec()) {
seqNum = selectDialog->getSeqNumber();
opText = selectDialog->getOpText();
if (selectDialog->isClassOp()) {
Model_Utils::OpDescriptor od;
Model_Utils::Parse_Status st = Model_Utils::parseOperation(opText, od, c);
if (st == Model_Utils::PS_OK) {
UMLClassifierList selfAndAncestors = c->findSuperClassConcepts();
selfAndAncestors.prepend(c);
UMLOperation *op = 0;
foreach (UMLClassifier *cl, selfAndAncestors) {
op = cl->findOperation(od.m_name, od.m_args);
if (op) {
break;
}
}
if (!op) {
// The op does not yet exist. Create a new one.
UMLObject *o = c->createOperation(od.m_name, 0, &od.m_args);
op = o->asUMLOperation();
}
if (od.m_pReturnType) {
op->setType(od.m_pReturnType);
}
m_linkWidget->setOperation(op);
opText.clear();
} else {
m_linkWidget->setOperation(0);
}
} else {
m_linkWidget->setOperation(0);
}
m_linkWidget->setSequenceNumber(seqNum);
m_linkWidget->setOperationText(opText);
if (enableAutoIncrement) {
m_scene->setAutoIncrementSequence(selectDialog->autoIncrementSequence());
}
selectDialog->apply();
setMessageText();
result = true;
}
......
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