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

Oliver Kellogg okellogg at users.sourceforge.net
Thu Nov 9 22:38:59 UTC 2006


SVN commit 603735 by okellogg:

Change the UniqueID::gen() function to return a random string of reasonable
length instead of just a small integer. Addresses first part of Comment #1.
CCBUG:126547


 A             configure.in.bot  
 M  +7 -0      configure.in.in  
 M  +1 -1      umbrello/Makefile.am  
 M  +7 -12     umbrello/umlobject.cpp  
 M  +4 -7      umbrello/umlview.cpp  
 M  +1 -5      umbrello/umlview.h  
 M  +13 -10    umbrello/uniqueid.cpp  


--- branches/KDE/3.5/kdesdk/umbrello/configure.in.in #603734:603735
@@ -34,7 +34,14 @@
 dnl #endif
 dnl ])
 
+KDE_CHECK_HEADER(uuid/uuid.h,
+  [kde_have_libuuid=yes],
+  [kde_have_libuuid=])
 
+if test -z "$kde_have_libuuid"; then
+  DO_NOT_COMPILE="$DO_NOT_COMPILE umbrello"
+fi
+
 HAVE_XSLT=yes
 
 KDE_FIND_PATH(xml2-config, XML_CONFIG, [${prefix}/bin ${exec_prefix}/bin], [
--- branches/KDE/3.5/kdesdk/umbrello/umbrello/Makefile.am #603734:603735
@@ -136,7 +136,7 @@
 
 METASOURCES = AUTO
 
-umbrello_LDFLAGS = $(all_libraries) $(KDE_RPATH) -export-dynamic
+umbrello_LDFLAGS = $(all_libraries) -luuid $(KDE_RPATH) -export-dynamic
 
 messages: rc.cpp
 	$(PREPARETIPS) > tips.cpp
--- branches/KDE/3.5/kdesdk/umbrello/umbrello/umlobject.cpp #603734:603735
@@ -599,20 +599,15 @@
     }
 
     QString stereo = element.attribute( "stereotype", "" );
-    if (!stereo.isEmpty() && stereo != "-1") {
-        if (stereo.contains(QRegExp("\\D"))) {
-            // Old versions saved the stereotype name instead of the xmi.id.
-            setStereotype( stereo );
-        } else {
-            Uml::IDType stereoID = STR2ID(stereo);
-            m_pStereotype = umldoc->findStereotypeById(stereoID);
-            if (m_pStereotype)
-                m_pStereotype->incrRefCount();
-            else
-                kdError() << "UMLObject::loadFromXMI(" << m_Name << "): "
+    if (!stereo.isEmpty()) {
+        Uml::IDType stereoID = STR2ID(stereo);
+        m_pStereotype = umldoc->findStereotypeById(stereoID);
+        if (m_pStereotype)
+            m_pStereotype->incrRefCount();
+        else
+            kdError() << "UMLObject::loadFromXMI(" << m_Name << "): "
                 << "UMLStereotype " << ID2STR(stereoID)
                 << " not found" << endl;
-        }
     }
 
     if( element.hasAttribute("abstract") ) {     // for bkwd compat.
--- branches/KDE/3.5/kdesdk/umbrello/umbrello/umlview.cpp #603734:603735
@@ -93,8 +93,6 @@
 #include "toolbarstatefactory.h"
 
 
-# define EXTERNALIZE_ID(id)  QString::number(id).ascii()
-
 // control the manual DoubleBuffering of QCanvas
 // with a define, so that this memory X11 effect can
 // be tested more easily
@@ -119,7 +117,6 @@
     m_pDoc = NULL;
     m_Documentation = "";
     m_Type = dt_Undefined;
-    m_nLocalID = 900000;
     m_bUseSnapToGrid = false;
     m_bUseSnapComponentSizeToGrid = false;
     m_bShowSnapGrid = false;
@@ -1107,8 +1104,8 @@
 }
 
 Uml::IDType UMLView::getLocalID() {
-    --m_nLocalID;
-    return EXTERNALIZE_ID(m_nLocalID);
+    m_nLocalID = UniqueID::gen();
+    return m_nLocalID;
 }
 
 bool UMLView::isSavedInSeparateFile() {
@@ -2860,7 +2857,7 @@
     viewElement.setAttribute( "showscope", m_Options.classState.showVisibility );
     viewElement.setAttribute( "showstereotype", m_Options.classState.showStereoType );
     //misc
-    viewElement.setAttribute( "localid", m_nLocalID );
+    viewElement.setAttribute( "localid", ID2STR(m_nLocalID) );
     viewElement.setAttribute( "showgrid", m_bShowSnapGrid );
     viewElement.setAttribute( "snapgrid", m_bUseSnapToGrid );
     viewElement.setAttribute( "snapcsgrid", m_bUseSnapComponentSizeToGrid );
@@ -3025,7 +3022,7 @@
         m_Options.uiState.lineColor = QColor( linecolor );
     if( !linewidth.isEmpty() )
         m_Options.uiState.lineWidth = linewidth.toInt();
-    m_nLocalID = localid.toInt();
+    m_nLocalID = STR2ID(localid);
 
     QDomNode node = qElement.firstChild();
     bool widgetsLoaded = false, messagesLoaded = false, associationsLoaded = false;
--- branches/KDE/3.5/kdesdk/umbrello/umbrello/umlview.h #603734:603735
@@ -930,12 +930,8 @@
     /**
      * Contains the unique ID to allocate to a widget that needs an
      * ID for the view.  @ref ObjectWidgets are an example of this.
-     * NOTE: Currently this is an int although Uml::IDType is a string
-     *       (unless ID_USE_INT is defined.) Perhaps it should be changed
-     *       to Uml::IDType but then we need a unique string generator.
-     *       See also UMLDoc::m_uniqueID.
      */
-    int m_nLocalID;
+    Uml::IDType m_nLocalID;
 
     /**
      * The ID of the view.  Allocated by @ref UMLDoc
--- branches/KDE/3.5/kdesdk/umbrello/umbrello/uniqueid.cpp #603734:603735
@@ -9,35 +9,38 @@
  *   Umbrello UML Modeller Authors <uml-devel@ uml.sf.net>                 *
  ***************************************************************************/
 
+// own header
 #include "uniqueid.h"
 
-# define EXTERNALIZE_ID(id)  QString::number(id).ascii()
+// system includes
+#include <uuid/uuid.h>
 
 namespace UniqueID {
 
 /**
  * Each model object gets assigned a unique ID.
- * NOTE: Currently this is an int although Uml::IDType is a string.
- *       See also UMLView::m_nLocalID.
  */
-int m_uniqueID = 0;
+Uml::IDType m_uniqueID;
 
 Uml::IDType gen() {
-    ++m_uniqueID;
-    return EXTERNALIZE_ID(m_uniqueID);
+    static char buf[40];
+    uuid_t uuid;
+    uuid_generate(uuid);
+    uuid_unparse_upper(uuid, buf);
+    m_uniqueID = std::string(buf);
+    return m_uniqueID;
 }
 
 void init() {
-    m_uniqueID = 0;
+    m_uniqueID = Uml::id_Reserved;
 }
 
 Uml::IDType get() {
-    return EXTERNALIZE_ID(m_uniqueID);
+    return m_uniqueID;
 }
 
 void set(Uml::IDType id) {
-    QString uniqueid = ID2STR(id);
-    m_uniqueID = uniqueid.toInt();
+    m_uniqueID = id;
 }
 
 }  // end namespace UniqueID




More information about the umbrello-devel mailing list