Back to index

scribus-ng  1.3.4.dfsg+svn20071115
style.cpp
Go to the documentation of this file.
00001 /*
00002  For general Scribus (>=1.3.2) copyright and licensing information please refer
00003  to the COPYING file provided with the program. Following this notice may exist
00004  a copyright and/or license notice that predates the release of Scribus 1.3.2
00005  for which a new license (GPL+exception) is in place.
00006  */
00007 /***************************************************************************
00008 *                                                                         *
00009 *   This program is free software; you can redistribute it and/or modify  *
00010 *   it under the terms of the GNU General Public License as published by  *
00011 *   the Free Software Foundation; either version 2 of the License, or     *
00012 *   (at your option) any later version.                                   *
00013 *                                                                         *
00014 ***************************************************************************/
00015 
00016 
00017 #include "style.h"
00018 #include "desaxe/digester.h"
00019 #include "desaxe/simple_actions.h"
00020 #include "desaxe/saxiohelper.h"
00021 
00022 const QString Style::INHERIT_PARENT = "\n";
00023 
00024 void Style::setContext(const StyleContext* context)
00025 { 
00026        if (m_context != context) {
00027               m_context = context;
00028               m_contextversion = -1;
00029               assert( !m_context || m_context->checkConsistency() );
00030        }
00031        //qDebug(QString("setContext of %2 context %1").arg(reinterpret_cast<uint>(m_context),16).arg(reinterpret_cast<uint>(this),16));
00032 }
00033 
00034 
00035 void Style::update(const StyleContext* b)
00036 {
00037        if (b)
00038               m_context = b;
00039        if (m_context)
00040               m_contextversion = m_context->version(); 
00041 }
00042 
00043 void Style::validate() const
00044 { 
00045        if (m_context && m_contextversion != m_context->version()) {
00046               const_cast<Style*>(this)->update(m_context); 
00047               assert( m_context->checkConsistency() );
00048        }
00049 }
00050 
00051 
00052 const Style* Style::parentStyle() const 
00053 { 
00054        //qDebug(QString("follow %1").arg(reinterpret_cast<uint>(m_context),16));
00055        const Style * par = m_context ? m_context->resolve(m_parent) : NULL;
00056        if (par == this) return NULL; else return par;
00057 }
00058 
00059 
00060 void Style::saxxAttributes(Xml_attr& attr) const
00061 {
00062        if (!name().isEmpty())
00063               attr["name"] = name();
00064        if(!parent().isEmpty())
00065               attr["parent"] = parent();
00066        if (!shortcut().isEmpty())
00067               attr["shortcut"] = shortcut();
00068 }