umbrello API Documentation

docwindow.cpp

00001 /***************************************************************************
00002  *                                                                         *
00003  *   This program is free software; you can redistribute it and/or modify  *
00004  *   it under the terms of the GNU General Public License as published by  *
00005  *   the Free Software Foundation; either version 2 of the License, or     *
00006  *   (at your option) any later version.                                   *
00007  *                                                                         *
00008  *   copyright (C) 2002-2007                                               *
00009  *   Umbrello UML Modeller Authors <uml-devel@uml.sf.net>                  *
00010  ***************************************************************************/
00011 
00012 // own header
00013 #include "docwindow.h"
00014 
00015 // qt/kde includes
00016 #include <qgroupbox.h>
00017 #include <qlayout.h>
00018 #include <qmultilineedit.h>
00019 #include <klocale.h>
00020 
00021 // local includes
00022 #include "associationwidget.h"
00023 #include "umldoc.h"
00024 #include "umlobject.h"
00025 #include "umlview.h"
00026 #include "umlwidget.h"
00027 
00028 
00029 DocWindow::DocWindow( UMLDoc * doc, QWidget *parent, const char *name ) : QWidget( parent, name ) {
00030     //setup visual display
00031     QHBoxLayout * mainLayout = new QHBoxLayout( this );
00032 
00033     m_pDocGB = new QGroupBox( i18n( "Documentation" ), this );
00034     mainLayout -> addWidget( m_pDocGB );
00035 
00036     QHBoxLayout * docLayout = new QHBoxLayout( m_pDocGB );
00037     m_pDocMLE = new QMultiLineEdit( m_pDocGB );
00038     m_pDocMLE -> setText( "" );
00039     docLayout -> setMargin( fontMetrics().height() );
00040     docLayout -> addWidget( m_pDocMLE);
00041     m_pDocMLE -> setWordWrap(QMultiLineEdit::WidgetWidth);
00042 
00043     //setup the documentation variables
00044     //show projects documentation to start
00045     m_pUMLDoc = doc;
00046     m_Showing = st_Project;
00047     m_pUMLObject = 0;
00048     m_pUMLView = 0;
00049     m_pUMLWidget = 0;
00050     m_pAssocWidget = 0;
00051     updateDocumentation( true, true );
00052 }
00053 
00054 DocWindow::~DocWindow() {}
00055 
00056 void DocWindow::showDocumentation( UMLObject * object, bool overwrite ) {
00057     if( object == m_pUMLObject && !overwrite )
00058         return;
00059     if( object != m_pUMLObject )
00060         updateDocumentation( true );
00061 
00062     m_Showing = st_UMLObject;
00063     if( !object ) {
00064         m_pDocMLE->setText( m_pUMLDoc->getDocumentation() );
00065         m_pUMLObject = 0;
00066         return;
00067     }
00068     m_pUMLObject = object;
00069     m_pDocMLE -> setText( m_pUMLObject -> getDoc() );
00070 }
00071 
00072 void DocWindow::updateDocumentation( bool clear, bool startup ) {
00073 
00074     bool mark_modified = false;
00075     if( m_pUMLObject )
00076     {
00077         // the file is marked modified, if the documentation differs
00078         // we don't do this on startup/load of a xmi file, because every time
00079         // modified is set, we get another undo/redo backup point
00080         if ( startup == false && m_pDocMLE -> text() != m_pUMLObject -> getDoc() )
00081         {
00082             mark_modified = true;
00083         }
00084         m_pUMLObject -> setDoc( m_pDocMLE -> text() );
00085 
00086     } else if( m_pUMLView ) {
00087         // the file is marked modified, if the documentation differs
00088         // we don't do this on startup/load of a xmi file, because every time
00089         // modified is set, we get another undo/redo backup point
00090         if ( startup == false && m_pDocMLE -> text() != m_pUMLView -> getDoc() )
00091         {
00092             mark_modified = true;
00093         }
00094 
00095         m_pUMLView -> setDoc( m_pDocMLE -> text() );
00096     } else if ( m_pUMLWidget ) {
00097         // the file is marked modified, if the documentation differs
00098         // we don't do this on startup/load of a xmi file, because every time
00099         // modified is set, we get another undo/redo backup point
00100         if ( startup == false && m_pDocMLE -> text() != m_pUMLWidget -> getDoc() )
00101         {
00102             mark_modified = true;
00103         }
00104 
00105         m_pUMLWidget -> setDoc( m_pDocMLE -> text() );
00106     } else if( m_pAssocWidget ) {
00107         // the file is marked modified, if the documentation differs
00108         // we don't do this on startup/load of a xmi file, because every time
00109         // modified is set, we get another undo/redo backup point
00110         if ( startup == false && m_pDocMLE -> text() != m_pAssocWidget -> getDoc() )
00111         {
00112             mark_modified = true;
00113         }
00114 
00115         m_pAssocWidget -> setDoc( m_pDocMLE -> text() );
00116     } else {
00117         // the file is marked modified, if the documentation differs
00118         // we don't do this on startup/load of a xmi file, because every time
00119         // modified is set, we get another undo/redo backup point
00120         if ( startup == false && m_pDocMLE -> text() != m_pUMLDoc->getDocumentation() )
00121         {
00122             mark_modified = true;
00123         }
00124 
00125         m_pUMLDoc->setDocumentation( m_pDocMLE->text() );
00126     }
00127 
00128     // now do the setModified call
00129     if (mark_modified == true)
00130         m_pUMLDoc -> setModified( true );
00131 
00132     // we should show the documentation of the whole project
00133     if( clear ) {
00134         m_pDocMLE->setText( m_pUMLDoc->getDocumentation() );
00135         m_pUMLObject = 0;
00136         m_pUMLView = 0;
00137         m_pUMLWidget = 0;
00138         m_pAssocWidget = 0;
00139         m_Showing = st_Project;
00140     }
00141 
00142     return;
00143 }
00144 
00145 void DocWindow::showDocumentation( UMLView * view, bool overwrite ) {
00146     if( view == m_pUMLView && !overwrite )
00147         return;
00148     if( view != m_pUMLView )
00149         updateDocumentation( true );
00150     m_Showing = st_UMLView;
00151     if( !view ) {
00152         m_pDocMLE->setText( m_pUMLDoc->getDocumentation() );
00153         m_pUMLView = 0;
00154         return;
00155     }
00156     m_pUMLView = view;
00157     m_pDocMLE -> setText( m_pUMLView -> getDoc() );
00158 }
00159 
00160 void DocWindow::showDocumentation( UMLWidget * widget, bool overwrite ) {
00161     if( widget == m_pUMLWidget && !overwrite )
00162         return;
00163     if( widget != m_pUMLWidget )
00164         updateDocumentation( true );
00165     m_Showing = st_UMLWidget;
00166     if( !widget ) {
00167         m_pDocMLE->setText( m_pUMLDoc->getDocumentation() );
00168         m_pUMLWidget = 0;
00169         return;
00170     }
00171     m_pUMLWidget = widget;
00172     m_pDocMLE -> setText( m_pUMLWidget -> getDoc() );
00173 }
00174 
00175 void DocWindow::showDocumentation( AssociationWidget * widget, bool overwrite ) {
00176     if( widget == m_pAssocWidget && !overwrite )
00177         return;
00178     if( widget != m_pAssocWidget )
00179         updateDocumentation( true );
00180     m_Showing = st_Association;
00181     if( !widget ) {
00182         m_pDocMLE->setText( m_pUMLDoc->getDocumentation() );
00183         m_pAssocWidget = 0;
00184         return;
00185     }
00186     m_pAssocWidget = widget;
00187     m_pDocMLE -> setText( m_pAssocWidget -> getDoc() );
00188 }
00189 
00190 void DocWindow::newDocumentation( ) {
00191     m_pUMLView = 0;
00192     m_pUMLObject = 0;
00193     m_pUMLWidget = 0;
00194     m_pAssocWidget = 0;
00195     m_Showing = st_Project;
00196     m_pDocMLE->setText( m_pUMLDoc->getDocumentation() );
00197 }
00198 
00199 bool DocWindow::isTyping()
00200 {
00201     if (m_pDocMLE->hasFocus())
00202         return true;
00203     else
00204         return false;
00205 }
00206 
00207 void DocWindow::slotAssociationRemoved(AssociationWidget* association) {
00208     if (association == m_pAssocWidget || association->getUMLObject() == m_pUMLObject) {
00209         // In old code, the below line crashed (bugs.kde.org/89860)
00210         // A hotfix was made and detailed analysis was To Be Done:
00211         // newDocumentation()
00212         // However, it seems to have been fixed and the below line seems to work fine
00213         updateDocumentation(true);
00214     }
00215 }
00216 
00217 void DocWindow::slotWidgetRemoved(UMLWidget* widget) {
00218     if (widget == m_pUMLWidget || widget->getUMLObject() == m_pUMLObject) {
00219         updateDocumentation(true);
00220     }
00221 }
00222 
00223 #include "docwindow.moc"
KDE Logo
This file is part of the documentation for umbrello Version 3.1.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Tue Jun 26 08:07:56 2007 by doxygen 1.4.1 written by Dimitri van Heesch, © 1997-2003