[Uml-devel] branches/work/soc-umbrello/umbrello

Andi Fischer andi.fischer at hispeed.ch
Sun Dec 25 09:44:04 UTC 2011


SVN commit 1270546 by fischer:

Patch from Ralf Habacker also applied.

 M  +86 -91    docwindow.cpp  
 M  +6 -2      docwindow.h  


--- branches/work/soc-umbrello/umbrello/docwindow.cpp #1270545:1270546
@@ -4,7 +4,7 @@
  *   the Free Software Foundation; either version 2 of the License, or     *
  *   (at your option) any later version.                                   *
  *                                                                         *
- *   copyright (C) 2002-2010                                               *
+ *   copyright (C) 2002-2011                                               *
  *   Umbrello UML Modeller Authors <uml-devel at uml.sf.net>                  *
  ***************************************************************************/
 
@@ -25,12 +25,20 @@
 #include "umlview.h"
 #include "umlwidget.h"
 #include "umlscene.h"
+#include "debug_utils.h"
 
 /**
  * Constructor.
  */
 DocWindow::DocWindow( UMLDoc * doc, QWidget *parent )
-  : QWidget( parent )
+  : QWidget(parent),
+    m_pUMLObject(0),
+    m_pUMLView(0),
+    m_pUMLDoc(doc),
+    m_pUMLWidget(0),
+    m_pAssocWidget(0),
+    m_Showing(st_Project),
+    m_modified(false)
 {
     //setup visual display
     QVBoxLayout * docLayout = new QVBoxLayout( this );
@@ -40,15 +48,9 @@
     docLayout->setMargin(0);
     //m_pDocTE->setWordWrapMode(QTextEdit::WidgetWidth);
 
-    //setup the documentation variables
     //show projects documentation to start
-    m_pUMLDoc = doc;
-    m_Showing = st_Project;
-    m_pUMLObject = 0;
-    m_pUMLView = 0;
-    m_pUMLWidget = 0;
-    m_pAssocWidget = 0;
     updateDocumentation( true, true );
+    connect(m_pDocTE, SIGNAL(textChanged()), this, SLOT(slotTextChanged()));
 }
 
 /**
@@ -80,95 +82,16 @@
     m_Showing = st_UMLObject;
     if( !object ) {
         m_pDocTE->setText( m_pUMLDoc->documentation() );
+        m_modified = false;
         m_pUMLObject = 0;
         return;
     }
     m_pUMLObject = object;
     m_pDocTE->setText( m_pUMLObject->doc() );
+    m_modified = false;
 }
 
 /**
- * Call when you wish move changes in the doc window back into the
- * members documentation.
- *
- * If clear is true the doc window will display the documentation
- * for the current project instead of the widget documentation.
- *
- * This is usually called before displaying a properties dialog.
- *
- * @param clear     If true, show the documentation of current project
- * @param startup   If true, no setModified(true) calls will be done and nothing is pushed to the undo stack
- */
-void DocWindow::updateDocumentation( bool clear, bool startup )
-{
-    bool mark_modified = false;
-    if( m_pUMLObject )
-    {
-        // the file is marked modified, if the documentation differs
-        // we don't do this on startup/load of a xmi file, because every time
-        // modified is set, we get another undo/redo backup point
-        if ( startup == false && m_pDocTE->toPlainText() != m_pUMLObject->doc() ) {
-            mark_modified = true;
-        }
-        m_pUMLObject->setDoc( m_pDocTE->toPlainText() );
-
-    } else if( m_pUMLView ) {
-        // the file is marked modified, if the documentation differs
-        // we don't do this on startup/load of a xmi file, because every time
-        // modified is set, we get another undo/redo backup point
-        // [PORT] Use UMLScene here
-        if ( startup == false && m_pDocTE->toPlainText() != m_pUMLView->umlScene()->documentation() ) {
-            mark_modified = true;
-        }
-
-        // [PORT] Replace with umlScene in future
-        m_pUMLView->umlScene()->setDocumentation( m_pDocTE->toPlainText() );
-    } else if ( m_pUMLWidget ) {
-        // the file is marked modified, if the documentation differs
-        // we don't do this on startup/load of a xmi file, because every time
-        // modified is set, we get another undo/redo backup point
-        if ( startup == false && m_pDocTE->toPlainText() != m_pUMLWidget->documentation() ) {
-            mark_modified = true;
-        }
-
-        m_pUMLWidget->setDocumentation( m_pDocTE->toPlainText() );
-    } else if ( m_pAssocWidget ) {
-        // the file is marked modified, if the documentation differs
-        // we don't do this on startup/load of a xmi file, because every time
-        // modified is set, we get another undo/redo backup point
-        if ( startup == false && m_pDocTE->toPlainText() != m_pAssocWidget->documentation() ) {
-            mark_modified = true;
-        }
-
-        m_pAssocWidget->setDocumentation( m_pDocTE->toPlainText() );
-    } else {
-        // the file is marked modified, if the documentation differs
-        // we don't do this on startup/load of a xmi file, because every time
-        // modified is set, we get another undo/redo backup point
-        if ( startup == false && m_pDocTE->toPlainText() != m_pUMLDoc->documentation() ) {
-            mark_modified = true;
-        }
-
-        m_pUMLDoc->setDocumentation( m_pDocTE->toPlainText() );
-    }
-
-    // now do the setModified call
-    if (mark_modified) {
-        m_pUMLDoc->setModified( true );
-    }
-
-    // we should show the documentation of the whole project
-    if( clear ) {
-        m_pDocTE->setText( m_pUMLDoc->documentation() );
-        m_pUMLObject = 0;
-        m_pUMLView = 0;
-        m_pUMLWidget = 0;
-        m_pAssocWidget = 0;
-        m_Showing = st_Project;
-    }
-}
-
-/**
  * This method is the same as the one for UMLObjects except it
  * displays documentation for a diagram.
  */
@@ -183,11 +106,12 @@
     if( !view ) {
         m_pDocTE->setText( m_pUMLDoc->documentation() );
         m_pUMLView = 0;
+        m_modified = false;
         return;
     }
     m_pUMLView = view;
-    // [PORT]
     m_pDocTE->setText(m_pUMLView->umlScene()->documentation());
+    m_modified = false;
 }
 
 /**
@@ -205,10 +129,12 @@
     if( !widget ) {
         m_pDocTE->setText( m_pUMLDoc->documentation() );
         m_pUMLWidget = 0;
+        m_modified = false;
         return;
     }
     m_pUMLWidget = widget;
     m_pDocTE->setText( m_pUMLWidget->documentation() );
+    m_modified = false;
 }
 
 /**
@@ -226,13 +152,64 @@
     if( !widget ) {
         m_pDocTE->setText( m_pUMLDoc->documentation() );
         m_pAssocWidget = 0;
+        m_modified = false;
         return;
     }
     m_pAssocWidget = widget;
     m_pDocTE->setText( m_pAssocWidget->documentation() );
+    m_modified = false;
 }
 
 /**
+ * Call when you wish move changes in the doc window back into the
+ * members documentation.
+ *
+ * If clear is true the doc window will display the documentation
+ * for the current project instead of the widget documentation.
+ *
+ * This is usually called before displaying a properties dialog.
+ *
+ * @param clear     If true, show the documentation of current project
+ * @param startup   If true, no setModified(true) calls will be done and nothing is pushed to the undo stack
+ */
+void DocWindow::updateDocumentation( bool clear, bool startup )
+{
+    // the file is marked modified, if the documentation differs
+    // we don't do this on startup/load of a xmi file, because every time
+    // modified is set, we get another undo/redo backup point
+    if (isModified()) {
+        if( m_pUMLObject ) {
+            m_pUMLObject->setDoc( m_pDocTE->toPlainText() );
+        } else if( m_pUMLView ) {
+            m_pUMLView->umlScene()->setDocumentation( m_pDocTE->toPlainText() );
+        } else if ( m_pUMLWidget ) {
+            m_pUMLWidget->setDocumentation( m_pDocTE->toPlainText() );
+        } else if ( m_pAssocWidget ) {
+            m_pAssocWidget->setDocumentation( m_pDocTE->toPlainText() );
+        } else {
+            m_pUMLDoc->setDocumentation( m_pDocTE->toPlainText() );
+        }
+
+        // now do the setModified call
+        if (startup == false) {
+            m_pUMLDoc->setModified( true );
+        }
+    }
+
+    // we should show the documentation of the whole project
+    // FIXME: this is exactly what newDocumentation() does
+    if( clear ) {
+        m_pDocTE->setText( m_pUMLDoc->documentation() );
+        m_modified = false;
+        m_pUMLObject = 0;
+        m_pUMLView = 0;
+        m_pUMLWidget = 0;
+        m_pAssocWidget = 0;
+        m_Showing = st_Project;
+    }
+}
+
+/**
  *  Re-initializes the class for a new document.
  */
 void DocWindow::newDocumentation( )
@@ -243,6 +220,7 @@
     m_pAssocWidget = 0;
     m_Showing = st_Project;
     m_pDocTE->setText( m_pUMLDoc->documentation() );
+    m_modified = false;
 }
 
 /**
@@ -257,6 +235,15 @@
 }
 
 /**
+ * check if the content in the documentation window has been changed
+ * @return true when content has been changed
+ */
+bool DocWindow::isModified()
+{
+   return m_modified;
+}
+
+/**
  * An association was removed from the UMLView.
  * If the association removed was the association which documentation is
  * being shown, m_pAssocWidget is set to 0.
@@ -284,4 +271,12 @@
     }
 }
 
+/**
+ * text from the edit field has been changed
+ */
+void DocWindow::slotTextChanged()
+{
+    m_modified = true;
+}
+
 #include "docwindow.moc"
--- branches/work/soc-umbrello/umbrello/docwindow.h #1270545:1270546
@@ -4,7 +4,7 @@
  *   the Free Software Foundation; either version 2 of the License, or     *
  *   (at your option) any later version.                                   *
  *                                                                         *
- *   copyright (C) 2002-2009                                               *
+ *   copyright (C) 2002-2011                                               *
  *   Umbrello UML Modeller Authors <uml-devel at uml.sf.net>                  *
  ***************************************************************************/
 
@@ -41,13 +41,16 @@
     void newDocumentation( );
 
     bool isTyping();
+    bool isModified();
 
 public slots:
     void slotAssociationRemoved(AssociationWidget* association);
     void slotWidgetRemoved(UMLWidget* widget);
 
+private slots:
+    void slotTextChanged();
+
 private:
-
     /**
      * Used internally to know which type of object we are showing
      * documentation for.
@@ -71,6 +74,7 @@
     //visual widgets
     KTextEdit *  m_pDocTE;
 
+    bool m_modified; ///< state of text content
 };
 
 #endif




More information about the umbrello-devel mailing list