Commit b10cdc25 authored by Oliver Kellogg's avatar Oliver Kellogg
Browse files

umbrello/dialogs/pages/classgeneralpage.{h,cpp}

umbrello/dialogs/dialog_utils.{h,cpp}
- Move function insertStereotypesSorted() from ClassGeneralPage to
  Dialog_Utils.

umbrello/dialogs/pages/associationgeneralpage.{h,cpp}
- Allow for selection of stereotype in place of name.
parent 62024dd3
......@@ -13,6 +13,8 @@
// app includes
#include "uml.h"
#include "umldoc.h"
#include "stereotype.h"
#include "umlwidget.h"
// kde includes
......@@ -20,6 +22,7 @@
#include <kmessagebox.h>
#include <klocale.h>
#include <klineedit.h>
#include <kcombobox.h>
// qt includes
#include <QGridLayout>
......@@ -77,5 +80,36 @@ void askNameForWidget(UMLWidget * &targetWidget, const QString& dialogTitle,
}
}
/**
* Helper function for inserting available stereotypes into a KComboBox
*
* @param kcb The KComboBox into which to insert the stereotypes
* @param type The stereotype to activate
*/
void insertStereotypesSorted(KComboBox *kcb, const QString& type)
{
UMLDoc *umldoc = UMLApp::app()->document();
QStringList types;
types << ""; // an empty stereotype is the default
foreach (UMLStereotype* ust, umldoc->stereotypes()) {
types << ust->name();
}
// add the given parameter
if (!types.contains(type)) {
types << type;
}
types.sort();
kcb->clear();
kcb->insertItems(-1, types);
// select the given parameter
int currentIndex = kcb->findText(type);
if (currentIndex > -1) {
kcb->setCurrentIndex(currentIndex);
}
kcb->completionObject()->addItem(type);
}
} // end namespace Dialog_Utils
......@@ -18,6 +18,7 @@ class QGridLayout;
class QLabel;
class UMLWidget;
class KLineEdit;
class KComboBox;
/**
* Dialog utilities.
......@@ -34,6 +35,7 @@ KLineEdit* makeLabeledEditField(QGridLayout *layout, int row,
void askNameForWidget(UMLWidget * &targetWidget, const QString& dialogTitle,
const QString& dialogPrompt, const QString& defaultName);
void insertStereotypesSorted(KComboBox *kcb, const QString& type);
}
......
......@@ -13,12 +13,14 @@
// local includes
#include "associationwidget.h"
#include "floatingtextwidget.h"
#include "assocrules.h"
#include "debug_utils.h"
#include "dialog_utils.h"
#include "objectwidget.h"
#include "umldoc.h"
#include "umlobject.h"
#include "association.h"
// kde includes
#include <kcombobox.h>
......@@ -31,6 +33,7 @@
#include <QHBoxLayout>
#include <QGridLayout>
#include <QGroupBox>
#include <QCheckBox>
#include <QLabel>
#include <QLayout>
#include <QVBoxLayout>
......@@ -44,7 +47,10 @@
*/
AssociationGeneralPage::AssociationGeneralPage (UMLDoc *d, QWidget *parent, AssociationWidget *assoc)
: DialogPageBase(parent),
m_pAssocNameL(0),
m_pAssocNameLE(0),
m_pAssocNameComB(0),
m_pStereoChkB(0),
m_pTypeCB(0),
m_pAssociationWidget(assoc),
m_pUmldoc(d),
......@@ -71,7 +77,7 @@ void AssociationGeneralPage::constructWidget()
QVBoxLayout * topLayout = new QVBoxLayout(this);
topLayout->setSpacing(6);
// group boxes for name/type, documentation properties
// group boxes for name+type, documentation properties
QGroupBox *nameAndTypeGB = new QGroupBox(this);
QGroupBox *docGB = new QGroupBox(this);
nameAndTypeGB->setTitle(i18n("Properties"));
......@@ -79,22 +85,45 @@ void AssociationGeneralPage::constructWidget()
topLayout->addWidget(nameAndTypeGB);
topLayout->addWidget(docGB);
QGridLayout * nameAndTypeLayout = new QGridLayout(nameAndTypeGB);
nameAndTypeLayout->setSpacing(6);
nameAndTypeLayout->setMargin(margin);
m_pNameAndTypeLayout = new QGridLayout(nameAndTypeGB);
m_pNameAndTypeLayout->setSpacing(6);
m_pNameAndTypeLayout->setMargin(margin);
// Association name
QLabel *pAssocNameL = NULL;
KLineEdit* nameField = Dialog_Utils::makeLabeledEditField(nameAndTypeLayout, 0,
pAssocNameL, i18nc("name of association widget", "Name:"),
m_pAssocNameLE, m_pAssociationWidget->name());
nameField->setFocus();
m_pAssocNameL = new QLabel(i18nc("name of association widget", "Name:"));
m_pNameAndTypeLayout->addWidget(m_pAssocNameL, 0, 0);
m_pAssocNameLE = new KLineEdit(m_pAssociationWidget->name());
m_pAssocNameComB = new KComboBox(true, nameAndTypeGB);
m_pAssocNameComB->setCompletionMode(KGlobalSettings::CompletionPopup);
m_pAssocNameComB->setDuplicatesEnabled(false); // only allow one of each type in box
QWidget *nameInputWidget = m_pAssocNameLE;
UMLAssociation *umlAssoc = m_pAssociationWidget->association();
if (umlAssoc && umlAssoc->umlStereotype()) {
m_pAssocNameLE->hide();
Dialog_Utils::insertStereotypesSorted(m_pAssocNameComB, umlAssoc->stereotype());
nameInputWidget = m_pAssocNameComB;
} else {
m_pAssocNameComB->hide();
}
m_pNameAndTypeLayout->addWidget(nameInputWidget, 0, 1);
nameInputWidget->setFocus();
m_pAssocNameL->setBuddy(nameInputWidget);
if (umlAssoc) {
// stereotype checkbox
m_pStereoChkB = new QCheckBox(i18n("Stereotype"), nameAndTypeGB);
m_pStereoChkB->setChecked(umlAssoc->umlStereotype() != NULL);
connect(m_pStereoChkB, SIGNAL(stateChanged(int)), this, SLOT(slotStereoCheckboxChanged(int)));
m_pNameAndTypeLayout->addWidget(m_pStereoChkB, 0, 2);
}
// type
Uml::AssociationType::Enum currentType = m_pAssociationWidget->associationType();
QString currentTypeAsString = Uml::AssociationType::toStringI18n(currentType);
QLabel *pTypeL = new QLabel(i18n("Type:"), nameAndTypeGB);
nameAndTypeLayout->addWidget(pTypeL, 1, 0);
m_pNameAndTypeLayout->addWidget(pTypeL, 1, 0);
// Here is a list of all the supported choices for changing
// association types.
......@@ -149,7 +178,7 @@ void AssociationGeneralPage::constructWidget()
m_pTypeCB->setDuplicatesEnabled(false); // only allow one of each type in box
m_pTypeCB->setCompletionMode(KGlobalSettings::CompletionPopup);
nameAndTypeLayout->addWidget(m_pTypeCB, 1, 1);
m_pNameAndTypeLayout->addWidget(m_pTypeCB, 1, 1);
// document
QHBoxLayout * docLayout = new QHBoxLayout(docGB);
......@@ -161,6 +190,26 @@ void AssociationGeneralPage::constructWidget()
m_doc->setWordWrapMode(QTextOption::WordWrap);
}
void AssociationGeneralPage::slotStereoCheckboxChanged(int state)
{
QWidget *nameInputWidget = NULL;
if (state) {
m_pAssocNameLE->hide();
m_pNameAndTypeLayout->removeWidget(m_pAssocNameLE);
UMLAssociation *umlAssoc = m_pAssociationWidget->association();
Dialog_Utils::insertStereotypesSorted(m_pAssocNameComB, umlAssoc->stereotype());
nameInputWidget = m_pAssocNameComB;
} else {
m_pAssocNameComB->hide();
m_pNameAndTypeLayout->removeWidget(m_pAssocNameComB);
nameInputWidget = m_pAssocNameLE;
}
m_pNameAndTypeLayout->addWidget(nameInputWidget, 0, 1);
nameInputWidget->show();
nameInputWidget->setFocus();
m_pAssocNameL->setBuddy(nameInputWidget);
}
/**
* Will move information from the dialog into the object.
* Call when the ok or apply button is pressed.
......@@ -171,8 +220,16 @@ void AssociationGeneralPage::updateObject()
int comboBoxItem = m_pTypeCB->currentIndex();
Uml::AssociationType::Enum newType = m_AssocTypes[comboBoxItem];
m_pAssociationWidget->setAssociationType(newType);
m_pAssociationWidget->setName(m_pAssocNameLE->text());
m_pAssociationWidget->setDocumentation(m_doc->toPlainText());
if (m_pStereoChkB->isChecked()) {
UMLAssociation *umlAssoc = m_pAssociationWidget->association();
QString stereo = m_pAssocNameComB->currentText();
umlAssoc->setStereotype(stereo);
FloatingTextWidget* ft = m_pAssociationWidget->nameWidget();
ft->setText(umlAssoc->stereotype(true));
} else {
m_pAssociationWidget->setName(m_pAssocNameLE->text());
}
}
}
......
......@@ -18,6 +18,9 @@
#include <QWidget>
class AssociationWidget;
class QCheckBox;
class QGridLayout;
class QLabel;
class KComboBox;
class KLineEdit;
class KTextEdit;
......@@ -43,7 +46,11 @@ public:
void updateObject();
private:
KLineEdit *m_pAssocNameLE;
QGridLayout *m_pNameAndTypeLayout;
QLabel *m_pAssocNameL;
KLineEdit *m_pAssocNameLE; // is used if m_pStereoChkB is unchecked
KComboBox *m_pAssocNameComB; // is used if m_pStereoChkB is checked
QCheckBox *m_pStereoChkB;
KComboBox *m_pTypeCB;
/* Choices for the QComboBox, and we store ints and strings
......@@ -59,12 +66,7 @@ private:
void constructWidget();
public slots:
// /**
// * When the draw as actor check box is toggled, the draw
// * as multi instance need to be enabled/disabled. They
// * both can't be available at the same time.
// */
// void slotActorToggled(bool state);
void slotStereoCheckboxChanged(int state);
};
......
......@@ -13,6 +13,7 @@
// app includes
#include "debug_utils.h"
#include "dialog_utils.h"
#include "classifier.h"
#include "umlobject.h"
#include "objectwidget.h"
......@@ -278,7 +279,7 @@ ClassGeneralPage::ClassGeneralPage(UMLDoc* d, QWidget* parent, UMLObject* o)
// manage stereotypes
m_pStereoTypeCB->setDuplicatesEnabled(false); // only allow one of each type in box
m_pStereoTypeCB->setCompletionMode(KGlobalSettings::CompletionPopup);
insertStereotypesSorted(m_pObject->stereotype());
Dialog_Utils::insertStereotypesSorted(m_pStereoTypeCB, m_pObject->stereotype());
m_doc->setLineWrapMode(QTextEdit::WidgetWidth);
}
......@@ -418,30 +419,6 @@ ClassGeneralPage::~ClassGeneralPage()
{
}
void ClassGeneralPage::insertStereotypesSorted(const QString& type)
{
QStringList types;
types << ""; // an empty stereotype is the default
foreach (UMLStereotype* ust, m_pUmldoc->stereotypes()) {
types << ust->name();
}
// add the given parameter
if (!types.contains(type)) {
types << type;
}
types.sort();
m_pStereoTypeCB->clear();
m_pStereoTypeCB->insertItems(-1, types);
// select the given parameter
int currentIndex = m_pStereoTypeCB->findText(type);
if (currentIndex > -1) {
m_pStereoTypeCB->setCurrentIndex(currentIndex);
}
m_pStereoTypeCB->completionObject()->addItem(type);
}
/**
* Will move information from the dialog into the object.
* Call when the ok or apply button is pressed.
......
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