[Uml-devel] branches/KDE/3.5/kdesdk/umbrello/umbrello

Oliver Kellogg okellogg at users.sourceforge.net
Sun Jan 29 09:45:03 UTC 2006


SVN commit 503608 by okellogg:

petalTree2Uml(): New. Start making Umbrello objects from the PetalNode tree.
CCBUG:81364


 M  +1 -0      Makefile.am  
 M  +27 -30    import_rose.cpp  
 M  +14 -0     petalnode.cpp  
 M  +10 -1     petalnode.h  
 A             petaltree2uml.cpp   [License: GPL (v2+)]
 A             petaltree2uml.h   [License: GPL (v2+)]


--- branches/KDE/3.5/kdesdk/umbrello/umbrello/Makefile.am #503607:503608
@@ -74,6 +74,7 @@
 package.cpp \
 packagewidget.cpp \
 petalnode.cpp \
+petaltree2uml.cpp \
 plugin.cpp \
 pluginloader.cpp \
 pythonimport.cpp \
--- branches/KDE/3.5/kdesdk/umbrello/umbrello/import_rose.cpp #503607:503608
@@ -23,6 +23,7 @@
 #include <kdebug.h>
 // app includes
 #include "petalnode.h"
+#include "petaltree2uml.h"
 
 namespace Import_Rose {
 
@@ -37,9 +38,17 @@
                 // counter indicating how many additional node closings
                 // have been seen.
 
-QString comment;  // comment buffer
-
 uint linum;  // line number
+QString g_methodName;
+void methodName(QString m) {
+    g_methodName = m;
+}
+/**
+ * Auxiliary function for diagnostics: Return current location.
+ */
+QString loc() {
+    return "Import_Rose::" + g_methodName + " line " + linum + ": ";
+}
 
 /**
  * Split a line into lexemes.
@@ -96,18 +105,13 @@
         return false;
     if (tokens.last() == ")") {
         // For a single closing parenthesis, we just return true.
-        // But if there are more closing parentheses, we need to set the
-        // seenClosure for each corresponding scope to true.
+        // But if there are more closing parentheses, we need to increment
+        // nClosures for each scope.
         tokens.pop_back();
         while (tokens.count() && tokens.last() == ")") {
             nClosures++;
             tokens.pop_back();
         }
-        /*
-        if (tokens.last() == ")") {
-            kdError() << "Import_Rose::checkClosing:" << linum
-                << " too many ')' in file " << endl;
-        }  */
         return true;
     }
     return false;
@@ -161,32 +165,29 @@
 
 QString collectVerbatimText(QTextStream& stream) {
     QString result;
-    const QRegExp closingParenth("^\\s*\\)");
     QString line;
+    methodName("collectVerbatimText");
     while ((line = stream.readLine()) != QString::null) {
         linum++;
         line = line.stripWhiteSpace();
         if (line.isEmpty() || line.startsWith(")"))
             break;
         if (line[0] != '|') {
-            kdError() << "Import_Rose::collectVerbatimText " << linum
-                    << ": expecting '|' at start of verbatim text" << endl;
+            kdError() << loc() << "expecting '|' at start of verbatim text" << endl;
             return QString::null;
         } else {
             result += line.mid(1) + "\n";
         }
     }
     if (line == QString::null) {
-        kdError() << "Import_Rose::collectVerbatimText " << linum
-                << ": premature EOF" << endl;
+        kdError() << loc() << "premature EOF" << endl;
         return QString::null;
     }
     if (! line.isEmpty()) {
         for (uint i = 0; i < line.length(); i++) {
             const QChar& clParenth = line[i];
             if (clParenth != ')') {
-                kdError() << "Import_Rose::collectVerbatimText " << linum
-                        << ": expected ')', found: " << clParenth << endl;
+                kdError() << loc() << "expected ')', found: " << clParenth << endl;
                 return QString::null;
             }
             nClosures++;
@@ -216,6 +217,7 @@
  * The line ending '\n' of each line is preserved.
  */
 QString extractValue(QStringList& l, QTextStream& stream) {
+    methodName("extractValue");
     if (l.count() == 0)
         return QString::null;
     if (l.first() == "(")
@@ -232,8 +234,7 @@
     } else {
         result = shift(l);
         if (l.first() != ")") {
-            kdError() << "Import_Rose::extractValue " << linum
-                 << ": expecting closing parenthesis" << endl;
+            kdError() << loc() << "expecting closing parenthesis" << endl;
             return result;
         }
         l.pop_front();
@@ -253,10 +254,10 @@
  * @return           Pointer to the created PetalNode or NULL on error.
  */
 PetalNode *readAttributes(QStringList initialArgs, QTextStream& stream) {
+    methodName("readAttributes");
     if (initialArgs.count() == 0) {
-        kdError() << "Import_Rose::readAttributes " << linum
-            << ": firstLine is empty" << endl;
-        return false;
+        kdError() << loc() << "initialArgs is empty" << endl;
+        return NULL;
     }
     PetalNode::NodeType nt;
     QString type = shift(initialArgs);
@@ -265,8 +266,7 @@
     else if (type == "list")
         nt = PetalNode::nt_list;
     else {
-        kdError() << "Import_Rose::readAttributes " << linum
-            << ": unknown node type " << type << endl;
+        kdError() << loc() << "unknown node type " << type << endl;
         return NULL;
     }
     PetalNode *node = new PetalNode(nt);
@@ -285,8 +285,7 @@
         QString stringOrNodeOpener = shift(tokens);
         QString name;
         if (nt == PetalNode::nt_object && !stringOrNodeOpener.contains(QRegExp("^[A-Za-z]"))) {
-            kdError() << "Import_Rose::readAttributes " << linum
-                << ": unexpected line " << line << endl;
+            kdError() << loc() << "unexpected line " << line << endl;
             return NULL;
         }
         PetalNode::StringOrNode value;
@@ -312,8 +311,8 @@
             PetalNode::NameValue attr(QString::null, value);
             attrs.append(attr);
             if (tokens.count() && tokens.first() != ")") {
-                kdDebug() << "Import_Rose::readAttributes " << linum
-                        << ": NYI - immediate list entry with more than one item" << endl;
+                kdDebug() << loc()
+                    << "NYI - immediate list entry with more than one item" << endl;
             }
             if (checkClosing(tokens))
                 break;
@@ -380,9 +379,7 @@
     file.close();
     if (root == NULL)
         return false;
-    // @todo traverse the PetalNode tree and create Umbrello model objects
-    //
-    return true;
+    return petalTree2Uml(root);
 }
 
 }
--- branches/KDE/3.5/kdesdk/umbrello/umbrello/petalnode.cpp #503607:503608
@@ -27,6 +27,12 @@
     return m_initialArgs;
 }
 
+QString PetalNode::name() const {
+    if (m_initialArgs.count() == 0)
+        return QString::null;
+    return m_initialArgs.first();
+}
+
 PetalNode::NameValueList PetalNode::attributes() const {
     return m_attributes;
 }
@@ -45,3 +51,11 @@
     m_attributes = vl;
 }
 
+PetalNode::StringOrNode PetalNode::findAttribute(QString name) const {
+    for (uint i = 0; i < m_attributes.count(); i++) {
+        if (m_attributes[i].first == name)
+            return m_attributes[i].second;
+    }
+    return StringOrNode();
+}
+
--- branches/KDE/3.5/kdesdk/umbrello/umbrello/petalnode.h #503607:503608
@@ -49,7 +49,8 @@
         QString string;
         PetalNode *node;
         StringOrNode() { node = 0; }
-        virtual ~StringOrNode() { /* if (node) delete node; */ }
+        virtual ~StringOrNode() { }
+        bool isEmpty() { return (string.isEmpty() && node == 0); }
     };
     typedef QPair<QString, StringOrNode> NameValue;
     typedef QValueList<NameValue> NameValueList;
@@ -62,11 +63,19 @@
     // getters
     NodeType type() const;
     QStringList initialArgs() const;  // name and other initial args
+    QString name() const;  // convenience function: equal to initialArgs().first()
     NameValueList attributes() const;
     // setters
     //void setType(NodeType nt);   see constructor
     void setInitialArgs(QStringList args);
     void setAttributes(NameValueList vl);
+    // utilities
+    /**
+     * Find an attribute by name.
+     * @return  The value of the attribute. StringOrNode::isEmpty() returns true
+     *          if the name could not be found.
+     */
+    StringOrNode findAttribute(QString name) const;
 private:
     NodeType m_type;
     QStringList m_initialArgs;




More information about the umbrello-devel mailing list