umbrello API Documentation

widgetbase.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) 2004-2007                                               *
00009  *   Umbrello UML Modeller Authors <uml-devel@uml.sf.net>                  *
00010  ***************************************************************************/
00011 
00012 #include "widgetbase.h"
00013 
00014 #include <kdebug.h>
00015 #include "umlview.h"
00016 #include "umlobject.h"
00017 #include "optionstate.h"
00018 
00019 WidgetBase::WidgetBase(UMLView *view) : QObject(view) {
00020     init(view);
00021 }
00022 
00023 void WidgetBase::init(UMLView *view, Uml::Widget_Type type /* = Uml::wt_UMLWidget */) {
00024     m_pView = view;
00025     m_Type = type;
00026     m_pObject = NULL;
00027     if (m_pView) {
00028         m_bUsesDiagramLineColour = true;
00029         m_bUsesDiagramLineWidth  = true;
00030         const Settings::OptionState& optionState = m_pView->getOptionState();
00031         m_LineColour = optionState.uiState.lineColor;
00032         m_LineWidth  = optionState.uiState.lineWidth;
00033     } else {
00034         kError() << "WidgetBase constructor: SERIOUS PROBLEM - m_pView is NULL" << endl;
00035         m_bUsesDiagramLineColour = false;
00036         m_bUsesDiagramLineWidth  = false;
00037         m_LineColour = QColor("black");
00038         m_LineWidth = 0; // initialize with 0 to have valid start condition
00039     }
00040 }
00041 
00042 void WidgetBase::setBaseType( Uml::Widget_Type type ) {
00043     m_Type = type;
00044 }
00045 
00046 Uml::Widget_Type WidgetBase::getBaseType() const {
00047     return m_Type;
00048 }
00049 
00050 UMLObject *WidgetBase::getUMLObject() {
00051     return m_pObject;
00052 }
00053 
00054 void WidgetBase::setUMLObject(UMLObject * o) {
00055     m_pObject = o;
00056 }
00057 
00058 void WidgetBase::setID(Uml::IDType id) {
00059     if (m_pObject) {
00060         if (m_pObject->getID() != Uml::id_None)
00061             kWarning() << "WidgetBase::setID(): changing old UMLObject "
00062             << ID2STR(m_pObject->getID()) << " to "
00063             << ID2STR(id) << endl;
00064         m_pObject->setID(id);
00065     }
00066     m_nId = id;
00067 }
00068 
00069 Uml::IDType WidgetBase::getID() const {
00070     if (m_pObject)
00071         return m_pObject->getID();
00072     return m_nId;
00073 }
00074 
00075 QString WidgetBase::getDoc() const {
00076     if (m_pObject != NULL)
00077         return m_pObject->getDoc();
00078     return m_Doc;
00079 }
00080 
00081 void WidgetBase::setDoc( const QString &doc ) {
00082     if (m_pObject != NULL)
00083         m_pObject->setDoc( doc );
00084     else
00085         m_Doc = doc;
00086 }
00087 
00088 void WidgetBase::setLineColor(const QColor &colour) {
00089     m_LineColour = colour;
00090     m_bUsesDiagramLineColour = false;
00091 }
00092 
00093 void WidgetBase::setLineWidth(uint width) {
00094     m_LineWidth = width;
00095     m_bUsesDiagramLineWidth = false;
00096 }
00097 
00098 void WidgetBase::saveToXMI( QDomDocument & /*qDoc*/, QDomElement & qElement ) {
00099     if (m_bUsesDiagramLineColour) {
00100         qElement.setAttribute( "linecolor", "none" );
00101     } else {
00102         qElement.setAttribute( "linecolor", m_LineColour.name() );
00103     }
00104     if (m_bUsesDiagramLineWidth) {
00105         qElement.setAttribute( "linewidth", "none" );
00106     } else {
00107         qElement.setAttribute( "linewidth", m_LineWidth );
00108     }
00109 }
00110 
00111 bool WidgetBase::loadFromXMI( QDomElement & qElement ) {
00112     // first load from "linecolour" and then overwrite with the "linecolor"
00113     // attribute if that one is present. The "linecolour" name was a "typo" in
00114     // earlier versions of Umbrello
00115     QString lineColor = qElement.attribute( "linecolour", "none" );
00116     lineColor = qElement.attribute( "linecolor", lineColor );
00117 
00118     QString lineWidth = qElement.attribute( "linewidth", "none" );
00119     if (lineColor != "none") {
00120         setLineColor( QColor(lineColor) );
00121         m_bUsesDiagramLineColour = false;
00122     } else if (m_Type != Uml::wt_Box && m_pView != NULL) {
00123         setLineColor( m_pView->getLineColor() );
00124         m_bUsesDiagramLineColour = true;
00125     }
00126     if (lineWidth != "none") {
00127         setLineWidth( lineWidth.toInt() );
00128         m_bUsesDiagramLineWidth = false;
00129     } else if ( m_pView ) {
00130         setLineWidth( m_pView->getLineWidth() );
00131         m_bUsesDiagramLineWidth = true;
00132     }
00133     return true;
00134 }
00135 
00136 #include "widgetbase.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:08:03 2007 by doxygen 1.4.1 written by Dimitri van Heesch, © 1997-2003