[Uml-devel] branches/work/isi-umbrello/umbrello/umbrello
Thibault Normand
thibault.normand at gmail.com
Mon Mar 12 21:17:30 UTC 2007
SVN commit 641922 by tnormand:
M +22 -0 dialog_utils.cpp
M +97 -6 notewidget.cpp
M +38 -1 notewidget.h
M +1 -1 pics/CMakeLists.txt
M +19 -2 toolbarstateother.cpp
M +1 -1 widget_factory.cpp
M +6 -1 worktoolbar.cpp
M +6 -1 worktoolbar.h
--- branches/work/isi-umbrello/umbrello/umbrello/dialog_utils.cpp #641921:641922
@@ -59,5 +59,27 @@
}
+/*void askForNoteType(UMLWidget* &targetWidget, const QString& dialogTitle,
+ const QString& dialogPrompt, const QString& defaultName) {
+
+ bool pressedOK = false;
+ const QStringList list = QStringList() << "Pre Condition" << "Post Condition";
+ const QStringList select = QStringList() << "Pre Condition" << "Post Condition";
+ QStringList result = KInputDialog::getItemList (dialogTitle, dialogPrompt, list, select, false, &pressedOK, UMLApp::app());
+
+ if (pressedOK) {
+ QString type = result.join("");
+ dynamic_cast<NoteWidget*>(targetWidget)->setNoteType(type);
+ if (type == "Reference")
+ askNameForWidget(targetWidget, i18n("Enter the name of the diagram referenced"), i18n("Enter the name of the diagram referenced"), i18n("Diagram name"));
+ if (type == "Loop")
+ askNameForWidget(targetWidget, i18n("Enter the guard of the loop"), i18n("Enter the guard of the loop"), i18n("-"));
+ } else {
+ targetWidget->cleanup();
+ delete targetWidget;
+ targetWidget = NULL;
+ }
+}*/
+
} // end namespace Dialog_Utils
--- branches/work/isi-umbrello/umbrello/umbrello/notewidget.cpp #641921:641922
@@ -20,7 +20,9 @@
#include <QMouseEvent>
// kde includes
#include <kdebug.h>
+#include <klocale.h>
#include <kcolordialog.h>
+#include <kinputdialog.h>
// app includes
#include "notewidgetcontroller.h"
#include "dialogs/notedialog.h"
@@ -29,15 +31,18 @@
#include "umlview.h"
#include "uml.h"
#include "listpopupmenu.h"
+#include "dialog_utils.h"
#define NOTEMARGIN 10
-NoteWidget::NoteWidget(UMLView * view, Uml::IDType id)
+NoteWidget::NoteWidget(UMLView * view, NoteType noteType , Uml::IDType id)
: UMLWidget(view, id, new NoteWidgetController(this)) {
+
init();
setSize(100,80);
setZ( 20 ); //make sure always on top.
#ifdef NOTEWIDGET_EMBED_EDITOR
+ kDebug()<<"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" <<endl;
// NB: This code is currently deactivated because
// Zoom does not yet work with the embedded text editor.
m_pEditor = new Q3TextEdit(view);
@@ -47,9 +52,11 @@
m_pEditor->setTextFormat(Qt::RichText);
m_pEditor->setShown(true);
setEditorGeometry();
+
connect(m_pView, SIGNAL(contentsMoving(int, int)),
this, SLOT(slotViewScrolled(int, int)));
#endif
+
}
void NoteWidget::init() {
@@ -57,6 +64,26 @@
m_DiagramLink = Uml::id_None;
}
+NoteWidget::NoteType NoteWidget::getNoteType() const {
+ return m_NoteType;
+}
+NoteWidget::NoteType NoteWidget::getNoteType(QString noteType) const {
+ if (noteType == "Precondition")
+ return NoteWidget::PreCondition;
+ if (noteType == "Postcondition")
+ return NoteWidget::PostCondition;
+ if (noteType == "Transformation")
+ return NoteWidget::Transformation;
+}
+
+void NoteWidget::setNoteType( NoteType noteType ) {
+ m_NoteType = noteType;
+
+}
+void NoteWidget::setNoteType( QString noteType ) {
+ setNoteType(getNoteType(noteType));
+}
+
NoteWidget::~NoteWidget() {
#ifdef NOTEWIDGET_EMBED_EDITOR
delete m_pEditor;
@@ -142,6 +169,8 @@
int w = width()-1;
int h= height()-1;
+ const QFontMetrics &fm = getFontMetrics(FT_NORMAL);
+ const int fontHeight = fm.lineSpacing();
QPolygon poly(6);
poly.setPoint(0, offsetX, offsetY);
poly.setPoint(1, offsetX, offsetY + h);
@@ -161,7 +190,24 @@
p.drawPolyline(poly);
p.drawLine(offsetX + w - margin, offsetY, offsetX + w - margin, offsetY + margin);
p.drawLine(offsetX + w - margin, offsetY + margin, offsetX + w, offsetY + margin);
- if(m_bSelected) {
+
+ switch(m_NoteType) {
+ case NoteWidget::PreCondition :
+ p.drawText(offsetX, offsetY + margin ,w, fontHeight, Qt::AlignCenter, "<< precondition >>");
+ break;
+
+ case NoteWidget::PostCondition :
+ p.drawText(offsetX, offsetY + margin ,w, fontHeight, Qt::AlignCenter, "<< postcondition >>");
+ break;
+
+ case NoteWidget::Transformation :
+ p.drawText(offsetX, offsetY + margin ,w, fontHeight, Qt::AlignCenter, "<< transformation >>");
+ break;
+
+ default : break;
+ }
+
+if(m_bSelected) {
drawSelected(&p, offsetX, offsetY);
}
@@ -169,7 +215,29 @@
}
QSize NoteWidget::calculateSize() {
- return QSize(50, 50);
+ int width = 50, height = 50;
+ const QFontMetrics &fm = getFontMetrics(FT_NORMAL);
+ const int fontHeight = fm.lineSpacing();
+ const int textWidth = fm.width(m_Text);
+ if (m_NoteType == PreCondition)
+ {
+ const int widthtemp = fm.width("<< precondition >>");
+ width = textWidth > widthtemp ? textWidth : widthtemp;
+ width += 10;
+ }
+ else if (m_NoteType == PostCondition)
+ {
+ const int widthtemp = fm.width("<< postcondition >>");
+ width = textWidth > widthtemp ? textWidth : widthtemp;
+ width += 10;
+ }
+ else if (m_NoteType == Transformation)
+ {
+ const int widthtemp = fm.width("<< transformation >>");
+ width = textWidth > widthtemp ? textWidth : widthtemp;
+ width += 10;
+ }
+ return QSize(width, height);
}
void NoteWidget::slotMenuSelection(int sel) {
@@ -219,9 +287,9 @@
p->setFont( font );
const QFontMetrics &fm = getFontMetrics(FT_NORMAL);
const int fontHeight = fm.lineSpacing();
- QString text = getDoc();
- if( text.length() == 0 )
- return;
+
+
+
QString word = "";
QString fullLine = "";
QString testCombineLine = "";
@@ -232,6 +300,13 @@
const int height = this -> height() - fontHeight;
QChar returnChar('\n');
QChar c;
+
+
+ // QString text = getDoc();
+ QString text = l_Type + "\n" + m_Text;
+ if( text.length() == 0 )
+ return;
+
for (uint i = 0; i <= text.length(); i++) {
if (i < text.length()) {
c = text[i];
@@ -293,6 +368,22 @@
#endif
}
+void NoteWidget::askForNoteType(UMLWidget* &targetWidget, const QString& dialogTitle,
+ const QString& dialogPrompt, const QString& defaultName) {
+
+ bool pressedOK = false;
+ const QStringList list = QStringList() << "Precondition" << "Postcondition" << "Transformation";
+ QString type = KInputDialog::getItem (dialogTitle, dialogPrompt, list, 0, false, &pressedOK, UMLApp::app());
+
+ if (pressedOK) {
+ dynamic_cast<NoteWidget*>(targetWidget)->setNoteType(type);
+ } else {
+ targetWidget->cleanup();
+ delete targetWidget;
+ targetWidget = NULL;
+ }
+}
+
void NoteWidget::saveToXMI( QDomDocument & qDoc, QDomElement & qElement ) {
QDomElement noteElement = qDoc.createElement( "notewidget" );
UMLWidget::saveToXMI( qDoc, noteElement );
--- branches/work/isi-umbrello/umbrello/umbrello/notewidget.h #641921:641922
@@ -37,21 +37,42 @@
public:
friend class NoteWidgetController;
+ enum NoteType
+ {
+ Normal,
+ PreCondition,
+ PostCondition,
+ Transformation
+ };
+
/**
* Constructs a NoteWidget.
*
* @param view The parent to this widget.
* @param id The unique id of the widget.
+ * @param NoteType The type of the widget.
* The default (-1) will prompt a new ID.
*/
- NoteWidget(UMLView * view, Uml::IDType id = Uml::id_None );
+ NoteWidget(UMLView * view, NoteWidget::NoteType noteType = Normal, Uml::IDType id = Uml::id_None );
/**
* destructor
*/
virtual ~NoteWidget();
+ /**
+ * Returns the type of note.
+ */
+ NoteType getNoteType() const;
+ NoteType getNoteType(QString noteType) const;
+
/**
+ * Sets the type of note.
+ */
+ void setNoteType( NoteType noteType );
+ void setNoteType( QString noteType );
+
+ /**
* Overrides method from UMLWidget.
*/
QSize calculateSize();
@@ -106,6 +127,12 @@
*/
void setY(int y);
+ /**
+ * Display a dialogBox to allow the user to choose the note's type
+ */
+ void askForNoteType(UMLWidget* &targetWidget, const QString& dialogTitle,
+ const QString& dialogPrompt, const QString& defaultName);
+
/**
* Saves to the <notewidget> XMI element.
*/
@@ -124,6 +151,16 @@
// Data loaded/saved
Uml::IDType m_DiagramLink;
+ /**
+ * Type of note.
+ */
+ NoteType m_NoteType;
+
+ /**
+ * Label to see the note's type
+ */
+ QString l_Type;
+
/**
* Draws the text. Auxiliary to draw().
*/
--- branches/work/isi-umbrello/umbrello/umbrello/pics/CMakeLists.txt #641921:641922
@@ -19,7 +19,7 @@
cursor-fork.png cursor-note.png cursor-branch.png cursor-generalisation.png cursor-object.png
cursor-entity.png cursor-relationship.png precondition.png cursor-precondition.png cursor-send_signal.png cursor-accept_signal.png cursor-accept_time_event.png cursor-region.png
cursor-message-found.png message-lost.png cursor-message-lost.png end_of_life.png cursor-end_of_life.png exception.png
-cursor-exception.png DESTINATION
+cursor-exception.png cursor-PrePostCondition.png PrePostCondition.png DESTINATION
${DATA_INSTALL_DIR}/umbrello/pics )
kde4_install_icons( ${ICON_INSTALL_DIR} )
--- branches/work/isi-umbrello/umbrello/umbrello/toolbarstateother.cpp #641921:641922
@@ -35,6 +35,7 @@
#include "umldoc.h"
#include "objectwidget.h"
#include "objectflowwidget.h"
+#include "pinwidget.h"
@@ -91,7 +92,7 @@
switch (getButton()) {
case WorkToolBar::tbb_Note:
- umlWidget = new NoteWidget(m_pUMLView);
+ umlWidget = new NoteWidget(m_pUMLView, NoteWidget::Normal);
break;
case WorkToolBar::tbb_Box:
@@ -164,6 +165,10 @@
umlWidget = new ObjectFlowWidget(m_pUMLView);
break;
+ case WorkToolBar::tbb_PrePostCondition:
+ umlWidget = new NoteWidget(m_pUMLView, NoteWidget::Normal);
+ break;
+
default:
break;
}
@@ -203,10 +208,22 @@
Dialog_Utils::askNameForWidget(
umlWidget, i18n("Enter Object Flow Name"),
i18n("Enter Object Flow"), i18n("new object flow"));
- } /*else if (getButton() == WorkToolBar::tbb_Object_Flow) {
+ } else if (getButton() == WorkToolBar::tbb_PrePostCondition) {
+ dynamic_cast<NoteWidget*>(umlWidget)->askForNoteType(
+ umlWidget, i18n("Select a note type"),
+ i18n("Select a note type"), i18n("Note type"));
+ } //else if (getButton() == WorkToolBar::tbb_PrePostCondition) {
+ //Dialog_Utils::askForNoteType(
+
+
+
+ /*else if (getButton() == WorkToolBar::tbb_Object_Flow) {
Dialog_Utils::askNameForWidgetType(umlWidget, i18n("Enter Object Flow Name"),
i18n("Enter the Object Flow"), i18n("new Object Flow"));
} */
+
+
+
// Create the widget. Some setup functions can remove the widget.
if (umlWidget != NULL) {
m_pUMLView->setupNewWidget(umlWidget);
--- branches/work/isi-umbrello/umbrello/umbrello/widget_factory.cpp #641921:641922
@@ -183,7 +183,7 @@
widget = new StateWidget(view, StateWidget::Normal, Uml::id_Reserved);
} else if (tag == "notewidget"
|| tag == "UML:NoteWidget") { // for bkwd compatibility
- widget = new NoteWidget(view, Uml::id_Reserved);
+ widget = new NoteWidget(view,NoteWidget::Normal, Uml::id_Reserved);
} else if (tag == "boxwidget") {
widget = new BoxWidget(view, Uml::id_Reserved);
} else if (tag == "floatingtext"
--- branches/work/isi-umbrello/umbrello/umbrello/worktoolbar.cpp #641921:641922
@@ -147,6 +147,9 @@
insertHotBtn(tbb_Fork);
insertHotBtn(tbb_Activity_Transition);
insertHotBtn(tbb_Exception);
+
+ insertHotBtn(tbb_PrePostCondition);
+
insertHotBtn(tbb_Object_Flow);
insertHotBtn(tbb_Send_Signal);
insertHotBtn(tbb_Accept_Signal);
@@ -317,7 +320,8 @@
{ tbb_Pin, i18n("Pin"), "pin.png", SLOT(slotPin()) },
{ tbb_Initial_Activity, i18n("Initial Activity"), "initial_state.png", SLOT(slotInitial_Activity()) },
{ tbb_Coll_Message, i18n("Message"), "message-asynchronous.png", SLOT(slotColl_Message()) },
- { tbb_Exception, i18n("Exception"), "exception.png", SLOT(slotException()) }
+ { tbb_Exception, i18n("Exception"), "exception.png", SLOT(slotException()) },
+ { tbb_PrePostCondition, i18n("Pre/Post condition"), "PrePostCondition.png", SLOT(slotPrePostCondition()) }
};
KStandardDirs * dirs = KGlobal::dirs();
@@ -405,6 +409,7 @@
void WorkToolBar::slotChoice() {buttonChanged(tbb_Choice);}
void WorkToolBar::slotAndline() {buttonChanged(tbb_Andline);}
void WorkToolBar::slotException() {buttonChanged(tbb_Exception);}
+void WorkToolBar::slotPrePostCondition() {buttonChanged(tbb_PrePostCondition);}
#include "worktoolbar.moc"
--- branches/work/isi-umbrello/umbrello/umbrello/worktoolbar.h #641921:641922
@@ -130,7 +130,8 @@
tbb_Junction,
tbb_Choice,
tbb_Andline,
- tbb_Exception
+ tbb_Exception,
+ tbb_PrePostCondition
};
private:
@@ -256,8 +257,12 @@
void slotChoice();
void slotAndline();
void slotException();
+
+ void slotPrePostCondition();
+
void slotPin();
+
};
#endif
More information about the umbrello-devel
mailing list