[Uml-devel] branches/KDE/3.5/kdesdk/umbrello/umbrello
Oliver Kellogg
okellogg at users.sourceforge.net
Thu Dec 22 11:57:11 UTC 2005
SVN commit 490686 by okellogg:
Implement "const" for methods in the old and new C++ generators.
Corresponds to the the XMI attribute "isQuery".
CCBUG:60452
M +2 -0 codegenerators/cppheadercodeoperation.cpp
M +8 -4 codegenerators/cppsourcecodeoperation.cpp
M +3 -0 codegenerators/cppwriter.cpp
M +10 -5 dialogs/umloperationdialog.cpp
M +1 -0 dialogs/umloperationdialog.h
M +15 -1 operation.cpp
M +11 -0 operation.h
--- branches/KDE/3.5/kdesdk/umbrello/umbrello/codegenerators/cppheadercodeoperation.cpp #490685:490686
@@ -149,6 +149,8 @@
// virtual functions
start = (inlinePolicy ? " {" : ";");
end = (inlinePolicy ? "}" : "");
+ if (pOp->getConst())
+ prototype += " const";
if (interface || pOp->getAbstract()) {
// constructor can't be virtual or abstract
if (!pOp->isLifeOperation()) {
--- branches/KDE/3.5/kdesdk/umbrello/umbrello/codegenerators/cppsourcecodeoperation.cpp #490685:490686
@@ -93,11 +93,15 @@
// if a property has a friend stereotype, the operation should
// not be a class name
- QString startText;
+ QString startText = returnType + " ";
+
if (!o->getStereotype().isEmpty() && o->getStereotype(false) == "friend")
- startText = returnType + " " + methodName + " ("+paramStr+") {";
- else
- startText = returnType + " " + className + "::" + methodName + " ("+paramStr+") {";
+ startText += className + "::";
+ startText += methodName + " ("+paramStr+")";
+ if (o->getConst())
+ startText += " const";
+ startText += " {";
+
setStartMethodText(startText);
// Only write this out if its a child of an interface OR is abstract.
--- branches/KDE/3.5/kdesdk/umbrello/umbrello/codegenerators/cppwriter.cpp #490685:490686
@@ -1196,6 +1196,9 @@
}
str += " )";
+ if (op->getConst())
+ str += " const";
+
// method body : only gets IF its not in a header
if (isHeaderMethod && !INLINE_OPERATION_METHODS)
str +=";"; // terminate now
--- branches/KDE/3.5/kdesdk/umbrello/umbrello/dialogs/umloperationdialog.cpp #490685:490686
@@ -86,11 +86,14 @@
genLayout -> addWidget(m_pStereoTypeCB, 1, 1);
m_pAbstractCB = new QCheckBox( i18n("&Abstract operation"), m_pGenGB );
- m_pAbstractCB -> setChecked( m_pOperation -> getAbstract() );
+ m_pAbstractCB -> setChecked( m_pOperation->getAbstract() );
+ genLayout -> addWidget( m_pAbstractCB, 2, 0 );
m_pStaticCB = new QCheckBox( i18n("Classifier &scope (\"static\")"), m_pGenGB );
- m_pStaticCB -> setChecked( m_pOperation -> getStatic() );
- genLayout -> addWidget( m_pAbstractCB, 2, 0 );
+ m_pStaticCB -> setChecked( m_pOperation->getStatic() );
genLayout -> addWidget( m_pStaticCB, 2, 1 );
+ m_pQueryCB = new QCheckBox( i18n("&Query (\"const\")"), m_pGenGB );
+ m_pQueryCB -> setChecked( m_pOperation->getConst() );
+ genLayout -> addWidget( m_pQueryCB, 2, 2 );
topLayout -> addWidget( m_pGenGB );
@@ -485,6 +488,8 @@
else
m_pOperation->setTypeName(typeName);
+ m_pOperation->setStereotype( m_pStereoTypeCB->currentText() );
+
bool isAbstract = m_pAbstractCB->isChecked();
m_pOperation -> setAbstract( isAbstract );
if (isAbstract) {
@@ -495,8 +500,8 @@
*/
classifier->setAbstract(true);
}
- m_pOperation -> setStatic( m_pStaticCB -> isChecked() );
- m_pOperation -> setStereotype( m_pStereoTypeCB->currentText() );
+ m_pOperation->setStatic( m_pStaticCB->isChecked() );
+ m_pOperation->setConst( m_pQueryCB->isChecked() );
return true;
}
--- branches/KDE/3.5/kdesdk/umbrello/umbrello/dialogs/umloperationdialog.h #490685:490686
@@ -99,6 +99,7 @@
QLineEdit * m_pNameLE;
QCheckBox * m_pAbstractCB;
QCheckBox * m_pStaticCB;
+ QCheckBox * m_pQueryCB;
QPushButton* m_pDeleteButton;
QPushButton* m_pPropertiesButton;
KArrowButton* m_pUpButton;
--- branches/KDE/3.5/kdesdk/umbrello/umbrello/operation.cpp #490685:490686
@@ -271,6 +271,14 @@
return (isConstructorOperation() || isDestructorOperation());
}
+void UMLOperation::setConst(bool b) {
+ m_bConst = b;
+}
+
+bool UMLOperation::getConst() const {
+ return m_bConst;
+}
+
bool UMLOperation::showPropertiesDialogue(QWidget* parent) {
UMLOperationDialog dialogue(parent, this);
return dialogue.exec();
@@ -278,6 +286,7 @@
void UMLOperation::saveToXMI( QDomDocument & qDoc, QDomElement & qElement ) {
QDomElement operationElement = UMLObject::save("UML:Operation", qDoc);
+ operationElement.setAttribute( "isQuery", m_bConst ? "true" : "false" );
QDomElement featureElement = qDoc.createElement( "UML:BehavioralFeature.parameter" );
if (m_pSecondary) {
QDomElement retElement = qDoc.createElement("UML:Parameter");
@@ -287,7 +296,6 @@
retElement.setAttribute( "kind", "return" );
featureElement.appendChild( retElement );
} else {
- //operationElement.setAttribute( "type", m_SecondaryId );
kdDebug() << "UMLOperation::saveToXMI: m_SecondaryId is "
<< m_SecondaryId << endl;
}
@@ -331,6 +339,12 @@
}
}
}
+ QString isQuery = element.attribute( "isQuery", "" );
+ if (!isQuery.isEmpty()) {
+ // We need this extra test for isEmpty() because load() might have been
+ // called again by the processing for BehavioralFeature.parameter (see below)
+ m_bConst = (isQuery == "true");
+ }
QDomNode node = element.firstChild();
if (node.isComment())
node = node.nextSibling();
--- branches/KDE/3.5/kdesdk/umbrello/umbrello/operation.h #490685:490686
@@ -184,6 +184,16 @@
bool isLifeOperation();
/**
+ * Sets whether this operation is a query (C++ "const".)
+ */
+ void setConst(bool b);
+
+ /**
+ * Returns whether this operation is a query (C++ "const".)
+ */
+ bool getConst() const;
+
+ /**
* Saves to the <UML:Operation> XMI element.
*/
void saveToXMI( QDomDocument & qDoc, QDomElement & qElement );
@@ -196,6 +206,7 @@
private:
UMLAttributeList m_List;
+ bool m_bConst;
};
#endif
More information about the umbrello-devel
mailing list