Back to index

scribus-ng  1.3.4.dfsg+svn20071115
Public Types | Public Member Functions | Private Member Functions | Private Attributes
StyleStack Class Reference

This class implements a stack for the different styles of an object. More...

#include <stylestack.h>

List of all members.

Public Types

enum  Mode { OODraw1x = 1, OODraw2x = 2 }

Public Member Functions

 StyleStack ()
virtual ~StyleStack ()
void setMode (const StyleStack::Mode mode)
 Set attribute analysis mode.
void clear ()
 Clears the complete stack.
void save ()
 Save the current state of the stack.
void restore ()
 Restore the stack to the state it was at the corresponding save() call.
void pop ()
 Removes the style on top of the stack.
void push (const QDomElement &style)
 Pushes the new style onto the stack.
bool hasAttribute (const QString &name) const
 Check if any of the styles on the stack has an attribute called 'name'.
QString attribute (const QString &name) const
 Search for the attribute called 'name', starting on top of the stack, and return it.
bool hasAttribute (const QString &name, const QString &detail) const
 Check if any of the styles on the stack has an attribute called 'name'-'detail' where detail is e.g.
QString attribute (const QString &name, const QString &detail) const
 Search for the attribute called 'name', starting on top of the stack, and return it.
bool hasChildNode (const QString &name) const
 Check if any of the styles on the stack has a child node called 'name'.
QDomNode childNode (const QString &name) const
 Search for a child node called 'name', starting on top of the stack, and return it.
double fontSize () const
 Special case for the current font size, due to special handling of fo:font-size="115%".
QString userStyleName () const
 Return the name of the style specified by the user, i.e.

Private Member Functions

void fillNodeNameList (QStringList &names, const StyleStack::Mode mode)
QDomElement searchAttribute (const QDomElement &element, const QStringList &names, const QString &name) const
QDomElement searchAttribute (const QDomElement &element, const QStringList &names, const QString &name, const QString &fullName) const

Private Attributes

QStringList m_nodeNames
QValueStack< intm_marks
QValueList< QDomElement > m_stack

Detailed Description

This class implements a stack for the different styles of an object.

There can be several styles that are valid for one object. For example a textobject on a page has styles 'pr3' and 'P7' and a paragraph in that textobject has styles 'P1' and 'T3'. And some styles even have parent-styles...

If you want to know if there is, for example, the attribute 'fo:font-family' for this paragraph, you have to look into style 'T3', 'P1', 'P7' and 'pr3'. When you find this attribute in one style you have to stop processing the list and take the found attribute for this object.

This is what this class does. You can push styles on the stack while walking through the xml-tree to your object and then ask the stack if any of the styles provides a certain attribute. The stack will search from top to bottom, i.e. in our example from 'T3' to 'pr3' and return the first occurrence of the wanted attribute.

So this is some sort of inheritance where the styles on top of the stack overwrite the same attribute of a lower style on the stack.

Definition at line 57 of file stylestack.h.


Member Enumeration Documentation

Enumerator:
OODraw1x 
OODraw2x 

Definition at line 63 of file stylestack.h.

       {
              OODraw1x = 1,
              OODraw2x = 2
       };

Constructor & Destructor Documentation

Definition at line 30 of file stylestack.cpp.

Here is the call graph for this function:

StyleStack::~StyleStack ( ) [virtual]

Definition at line 36 of file stylestack.cpp.

{
}

Member Function Documentation

QString StyleStack::attribute ( const QString &  name) const

Search for the attribute called 'name', starting on top of the stack, and return it.

Definition at line 91 of file stylestack.cpp.

{
    // TODO: has to be fixed for complex styles like list-styles
    QValueList<QDomElement>::ConstIterator it = m_stack.end();
    while ( it != m_stack.begin() )
    {
        --it;
        QDomElement properties = searchAttribute( *it, m_nodeNames, name );
        if ( properties.hasAttribute( name ) )
            return properties.attribute( name );
    }

    return QString::null;
}

Here is the call graph for this function:

Here is the caller graph for this function:

QString StyleStack::attribute ( const QString &  name,
const QString &  detail 
) const

Search for the attribute called 'name', starting on top of the stack, and return it.

Definition at line 123 of file stylestack.cpp.

{
    QString fullName( name );
    fullName += '-';
    fullName += detail;
    QValueList<QDomElement>::ConstIterator it = m_stack.end();
    while ( it != m_stack.begin() )
    {
        --it;
        QDomElement properties = searchAttribute( *it, m_nodeNames, name, fullName );
        if ( properties.hasAttribute( fullName ) )
            return properties.attribute( fullName );
        if ( properties.hasAttribute( name ) )
            return properties.attribute( name );
    }

    return QString::null;
}

Here is the call graph for this function:

QDomNode StyleStack::childNode ( const QString &  name) const

Search for a child node called 'name', starting on top of the stack, and return it.

Definition at line 179 of file stylestack.cpp.

{
    QValueList<QDomElement>::ConstIterator it = m_stack.end();
    while ( it != m_stack.begin() )
    {
        --it;
        QDomElement properties = searchAttribute( *it, m_nodeNames, name );
        if ( !properties.namedItem( name ).isNull() )
            return properties.namedItem( name );
    }

    return QDomNode();          // a null node
}

Here is the call graph for this function:

Clears the complete stack.

Definition at line 46 of file stylestack.cpp.

{
    m_stack.clear();
}

Here is the caller graph for this function:

void StyleStack::fillNodeNameList ( QStringList &  names,
const StyleStack::Mode  mode 
) [private]

Definition at line 212 of file stylestack.cpp.

{
       if ( mode == StyleStack::OODraw2x )
       {
              names.append("style:graphic-properties");
              names.append("style:paragraph-properties");
              names.append("style:page-layout-properties");
              names.append("style:drawing-page-properties");
              names.append("style:text-properties");
       }
       else
              names.append("style:properties");         
}

Here is the caller graph for this function:

double StyleStack::fontSize ( ) const

Special case for the current font size, due to special handling of fo:font-size="115%".

Definition at line 145 of file stylestack.cpp.

{
    QString name = "fo:font-size";
    double percent = 1;
    QValueList<QDomElement>::ConstIterator it = m_stack.end();
    while ( it != m_stack.begin() )
    {
        --it;
        QDomElement properties = searchAttribute( *it, m_nodeNames, name );
        if ( properties.hasAttribute( name ) ) {
            QString value = properties.attribute( name );
            if ( value.endsWith( "%" ) )
                percent *= value.toDouble() / 100.0;
            else
                return percent * OODPlug::parseUnit( value ); // e.g. 12pt
        }
    }
    return 0;
}

Here is the call graph for this function:

bool StyleStack::hasAttribute ( const QString &  name) const

Check if any of the styles on the stack has an attribute called 'name'.

Definition at line 76 of file stylestack.cpp.

{
    // TODO: has to be fixed for complex styles like list-styles
    QValueList<QDomElement>::ConstIterator it = m_stack.end();
    while ( it != m_stack.begin() )
    {
        --it;
              QDomElement properties = searchAttribute( *it, m_nodeNames, name );
        if ( properties.hasAttribute( name ) )
            return true;
    }

    return false;
}

Here is the call graph for this function:

Here is the caller graph for this function:

bool StyleStack::hasAttribute ( const QString &  name,
const QString &  detail 
) const

Check if any of the styles on the stack has an attribute called 'name'-'detail' where detail is e.g.

left, right, top or bottom. This allows to also find 'name' alone (e.g. padding implies padding-left, padding-right etc.)

Definition at line 106 of file stylestack.cpp.

{
    QString fullName( name );
    fullName += '-';
    fullName += detail;
    QValueList<QDomElement>::ConstIterator it = m_stack.end();
    while ( it != m_stack.begin() )
    {
        --it;
              QDomElement properties = searchAttribute( *it, m_nodeNames, name, fullName );
        if ( properties.hasAttribute( name ) || properties.hasAttribute( fullName ) )
            return true;
    }

    return false;
}

Here is the call graph for this function:

bool StyleStack::hasChildNode ( const QString &  name) const

Check if any of the styles on the stack has a child node called 'name'.

Definition at line 165 of file stylestack.cpp.

{
    QValueList<QDomElement>::ConstIterator it = m_stack.end();
    while ( it != m_stack.begin() )
    {
        --it;
        QDomElement properties = searchAttribute( *it, m_nodeNames, name );
        if ( !properties.namedItem( name ).isNull() )
            return true;
    }

    return false;
}

Here is the call graph for this function:

void StyleStack::pop ( )

Removes the style on top of the stack.

Definition at line 66 of file stylestack.cpp.

{
    m_stack.pop_back();
}
void StyleStack::push ( const QDomElement &  style)

Pushes the new style onto the stack.

Definition at line 71 of file stylestack.cpp.

{
    m_stack.append( style );
}

Here is the caller graph for this function:

Restore the stack to the state it was at the corresponding save() call.

Definition at line 56 of file stylestack.cpp.

{
    Q_ASSERT( !m_marks.isEmpty() );
    int toIndex = m_marks.pop();
    Q_ASSERT( toIndex > -1 );
    Q_ASSERT( toIndex <= (int)m_stack.count() ); // If equal, nothing to remove. If greater, bug.
    for ( int index = (int)m_stack.count() - 1; index >= toIndex; --index )
        m_stack.pop_back();
}
void StyleStack::save ( )

Save the current state of the stack.

Any items added between this call and its corresponding restore() will be removed when calling restore().

Definition at line 51 of file stylestack.cpp.

{
    m_marks.push( m_stack.count() );
}
QDomElement StyleStack::searchAttribute ( const QDomElement &  element,
const QStringList &  names,
const QString &  name 
) const [private]

Definition at line 226 of file stylestack.cpp.

{
       QDomElement node;
       QDomNodeList childNodes;
       childNodes = element.childNodes();
       for ( uint i = 0; i < childNodes.count(); i++ )
       {
              QDomNode n = childNodes.item(i);
              if ( n.isElement() )
              {
                     QDomElement* e = (QDomElement*) (&n);
                     if ( (names.findIndex(e->nodeName()) >= 0) && e->hasAttribute(name) )
                     {
                            node = *e;
                            break;
                     }
              }
       }
       return node;
}

Here is the caller graph for this function:

QDomElement StyleStack::searchAttribute ( const QDomElement &  element,
const QStringList &  names,
const QString &  name,
const QString &  fullName 
) const [private]

Definition at line 247 of file stylestack.cpp.

{
       QDomElement node;
       QDomNodeList childNodes;
       childNodes = element.childNodes();
       for ( uint i = 0; i < childNodes.count(); i++ )
       {
              QDomNode n = childNodes.item(i);
              if ( n.isElement() )
              {
                     QDomElement* e = (QDomElement*) (&n);
                     if ( (names.findIndex(e->nodeName()) >= 0) && (e->hasAttribute(name) || e->hasAttribute(fullName)) )
                     {
                            node = *e;
                            break;
                     }
              }
       }
       return node;
}
void StyleStack::setMode ( const StyleStack::Mode  mode)

Set attribute analysis mode.

Definition at line 40 of file stylestack.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

QString StyleStack::userStyleName ( ) const

Return the name of the style specified by the user, i.e.

not an auto style

Definition at line 199 of file stylestack.cpp.

{
    QValueList<QDomElement>::ConstIterator it = m_stack.end();
    while ( it != m_stack.begin() )
    {
        --it;
        if ( isUserStyle( *it ) )
            return (*it).attribute("style:name");
    }
    // Can this ever happen?
    return "Standard";
}

Here is the call graph for this function:


Member Data Documentation

QValueStack<int> StyleStack::m_marks [private]

Definition at line 152 of file stylestack.h.

QStringList StyleStack::m_nodeNames [private]

Definition at line 149 of file stylestack.h.

QValueList<QDomElement> StyleStack::m_stack [private]

Definition at line 156 of file stylestack.h.


The documentation for this class was generated from the following files: