2009年1月11日 星期日

StarUML - 建立一個類別圖

這裡有一個例子:

class DiagramItem:public QGraphicsPolygonItem {
public:
  enum {Type = UserType + 15}; // 匿名列舉
  enum DiagramType {Step,Conditional,StartEnd,Io}; // 列舉
  DiagramItem(DiagramType diagramType,QMenu *contextMenu,QGraphicsItem *parent=0,QGraphicsScene *scene=0); // 建構子
  inline int type() const; // const function且inline function且有回傳值
  QVariant itemChange(GraphicsItemChange change, const QVariant &value); // call by reference
private:
  int x;
};


前置作業:
先建立兩個類別:QGraphicsPolygonItem與其子類別DiagramItem
按左邊Generalization按紐,並由DiagramItem拉線到QGraphicsPolygonItem

一、建立第一個匿名列舉
1.對DiagramItem按右鍵Add→Enumeration,必需在右邊的Mode explorer作業,不建立名稱,並且再對它按右鍵,Add→Enumeration Literal加入Type = UserType + 15

二、建立一個名為DiagramType列舉
1.對DiagramItem按右鍵Add→Enumeration,必需在右邊的Mode explorer作業,建立的名稱為DiagramType,並且再對它按右鍵,Add→Enumeration Literal,加入四個Enumeration Literal,名稱分別為Step,Conditional,StartEnd,Io

三、建立建構子
1. 建立一個名為DiagramItem的function
2. 設定Stereotype為create:表示建構子
3. 設定參數
  (1). 對建構子按右鍵Add→Parameter, 新增一個Name為diagramType、Type為DiagramType
  (2). 對建構子按右鍵Add→Parameter, 新增一個Name為diagramType、Type為DiagramType
  (3). 對建構子按右鍵Add→Parameter, 新增一個Name為*parent、Type為QGraphicsItem、初始值為0
  (4). 對建構子按右鍵Add→Parameter, 新增一個Name為*scene、Type為QGraphicsScene、初始值為0

四、建立一個inline function且回傳值為int,又是const的function
1. 建立一個名為type的function
2. 對function按右鍵Add→Parameter, 新增一個Name為空字串、Type為int、DirectionKind為RETURN
3. 對function按右鍵Add→Tagged Values,CPP標籤下接CppConst勾選CppConst、CppMemberFunction的CppInline勾選

五、建立一個名為itemChange的function,回傳值為QVariable,參數有用到conference
1. 建立一個名為itemChange的function
2. 對function按右鍵Add→Parameter, 新增一個Name為空字串、Type為QVariable、DirectionKind為RETURN
3. 對function按右鍵Add→Parameter, 新增一個Name為change、Type為GraphicsItemChange
4. 對function按右鍵Add→Parameter, 新增一個Name為&value、Type為QVariant、對此參數按右鍵Add→Tagged Values,CPP標籤下接CppConst勾選CppConst

六、建立一個private的int型別的變數x
1. 建立一個名為x的Attribute
2. Type為int且Visiability為private

七、接下來要產生C++程式,對要產生圖型的class圖按右鍵:C++→Generate Code,然後,一直下一步,就可以產生沒有實作內容的原始碼啦~

沒有留言: