Subversion Repositories Scribus

Compare Revisions

Ignore whitespace Rev 8133 → Rev 8134

/branches/Version13x/Scribus/scribus/style.cpp
16,54 → 16,31
 
#include "style.h"
 
void StyleBase::invalidate()
{
++m_version;
if (m_cnt > 0) // activate() can be slow even if there's nothing to signal
m_sig.activate();
}
 
bool StyleBase::connect(const QObject* receiver, const char *member ) const
{
bool result = m_sig.connect(receiver, member);
if (result)
++m_cnt;
return result;
}
 
bool StyleBase::disconnect(const QObject* receiver, const char *member ) const
{
bool result = m_sig.disconnect(receiver, member);
if (result)
--m_cnt;
return result;
}
 
 
void Style::setBase(const StyleBase* base)
void Style::setContext(const StyleContext* context)
{
if (m_base != base) {
m_base = base;
m_baseversion = -1;
assert( !m_base || m_base->checkConsistency() );
if (m_context != context) {
m_context = context;
m_contextversion = -1;
assert( !m_context || m_context->checkConsistency() );
}
//qDebug(QString("setBase of %2 base %1").arg(reinterpret_cast<uint>(m_base),16).arg(reinterpret_cast<uint>(this),16));
//qDebug(QString("setContext of %2 context %1").arg(reinterpret_cast<uint>(m_context),16).arg(reinterpret_cast<uint>(this),16));
}
 
 
void Style::update(const StyleBase* b)
void Style::update(const StyleContext* b)
{
if (b)
m_base = b;
if (m_base)
m_baseversion = m_base->version();
m_context = b;
if (m_context)
m_contextversion = m_context->version();
}
 
void Style::validate() const
{
if (m_base && m_baseversion != m_base->version()) {
const_cast<Style*>(this)->update(m_base);
assert( m_base->checkConsistency() );
if (m_context && m_contextversion != m_context->version()) {
const_cast<Style*>(this)->update(m_context);
assert( m_context->checkConsistency() );
}
}
 
70,24 → 47,8
 
const Style* Style::parentStyle() const
{
//qDebug(QString("follow %1").arg(reinterpret_cast<uint>(m_base),16));
const Style * par = m_base ? m_base->resolve(m_parent) : NULL;
//qDebug(QString("follow %1").arg(reinterpret_cast<uint>(m_context),16));
const Style * par = m_context ? m_context->resolve(m_parent) : NULL;
if (par == this) return NULL; else return par;
}
 
 
const Style* StyleBaseProxy::resolve(const QString& name) const
{
const StyleBase* base = m_default->base();
// if (!name.isEmpty())
// qDebug(QString("resolve %4 %3 -%1- %2").arg(name)
// .arg(reinterpret_cast<uint>(base),16).arg(reinterpret_cast<uint>(this),16)
// .arg(m_default->name()));
 
if (name.isEmpty() || ! base)
return m_default;
else if (this == base)
return NULL;
else
return base->resolve(name);
}
/branches/Version13x/Scribus/scribus/styles/charstyle.cpp
135,7 → 135,7
 
QString CharStyle::displayName() const
{
if ( hasName() || !hasParent() || ! m_base)
if ( hasName() || !hasParent() || ! m_context)
return name();
// else if ( inheritsAll() )
// return parent()->displayName();
176,9 → 176,9
}
 
 
void CharStyle::update(const StyleBase* base)
void CharStyle::update(const StyleContext* context)
{
Style::update(base);
Style::update(context);
const CharStyle * oth = dynamic_cast<const CharStyle*> ( parentStyle() );
if (oth) {
#define ATTRDEF(attr_TYPE, attr_GETTER, attr_NAME, attr_DEFAULT) \
/branches/Version13x/Scribus/scribus/styles/styleset.h
8,7 → 8,7
 
 
template<class STYLE>
class StyleSet : public StyleBase {
class StyleSet : public StyleContext {
public:
STYLE& operator[] (uint index) {
assert(index < styles.count());
34,7 → 34,7
STYLE* append(STYLE* style) {
styles.append(style);
style->setBase(this);
style->setContext(this);
return style;
}
49,7 → 49,7
void makeDefault(STYLE* def) {
m_default = def;
if(def)
def->setBase(this);
def->setContext(this);
invalidate();
}
57,7 → 57,7
return &style == m_default;
}
StyleSet() : styles(), m_base(NULL), m_default(NULL) {}
StyleSet() : styles(), m_context(NULL), m_default(NULL) {}
~StyleSet() {
clear();
72,15 → 72,15
invalidate();
}
 
void setBase(const StyleBase* base) {
bool reallyNew = m_base != base;
m_base = base;
void setContext(const StyleContext* context) {
bool reallyNew = m_context != context;
m_context = context;
if (reallyNew)
invalidate();
}
const StyleBase* base() const {
return m_base;
const StyleContext* context() const {
return m_context;
}
private:
88,7 → 88,7
StyleSet& operator= (const StyleSet&) { assert(false); return *this; }
 
QValueList<STYLE*> styles;
const StyleBase* m_base;
const StyleContext* m_context;
STYLE* m_default;
};
 
122,7 → 122,7
if (styles[i]->name() == name)
return styles[i];
}
return m_base ? m_base->resolve(name) : NULL;
return m_context ? m_context->resolve(name) : NULL;
}
 
template<class STYLE>
137,7 → 137,7
{
found = true;
(*styles[i]) = defs[j];
(*styles[i]).setBase(this);
(*styles[i]).setContext(this);
if (defs.m_default == defs.styles[j])
makeDefault(styles[i]);
break;
/branches/Version13x/Scribus/scribus/styles/charstyle.h
96,7 → 96,7
QString displayName() const;
 
void update(const StyleBase * b);
void update(const StyleContext * b);
bool equiv(const Style& other) const;
166,8 → 166,8
inh_##attr_NAME = other.inh_##attr_NAME;
#include "charstyle.attrdefs.cxx"
#undef ATTRDEF
// m_base = NULL;
m_baseversion = -1;
// m_context = NULL;
m_contextversion = -1;
return *this;
}
 
178,7 → 178,7
inh_##attr_NAME = other.inh_##attr_NAME;
#include "charstyle.attrdefs.cxx"
#undef ATTRDEF
// m_base = NULL;
m_baseversion = -1;
// m_context = NULL;
m_contextversion = -1;
}
 
/branches/Version13x/Scribus/scribus/styles/stylecontext.cpp
0,0 → 1,41
/*
For general Scribus (>=1.3.2) copyright and licensing information please refer
to the COPYING file provided with the program. Following this notice may exist
a copyright and/or license notice that predates the release of Scribus 1.3.2
for which a new license (GPL+exception) is in place.
*/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
 
 
#include "stylecontext.h"
 
void StyleContext::invalidate()
{
++m_version;
if (m_cnt > 0) // activate() can be slow even if there's nothing to signal
m_sig.activate();
}
 
bool StyleContext::connect(const QObject* receiver, const char *member ) const
{
bool result = m_sig.connect(receiver, member);
if (result)
++m_cnt;
return result;
}
 
bool StyleContext::disconnect(const QObject* receiver, const char *member ) const
{
bool result = m_sig.disconnect(receiver, member);
if (result)
--m_cnt;
return result;
}
 
Property changes:
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Author Date Id Revision
\ No newline at end of property
Index: branches/Version13x/Scribus/scribus/styles/paragraphstyle.cpp
===================================================================
--- branches/Version13x/Scribus/scribus/styles/paragraphstyle.cpp (revision 8133)
+++ branches/Version13x/Scribus/scribus/styles/paragraphstyle.cpp (revision 8134)
@@ -18,11 +18,11 @@
#include "style.h"
-ParagraphStyle::ParagraphStyle() : Style(), cstyleBase(NULL), cstyleBaseIsInh(true), cstyle()
+ParagraphStyle::ParagraphStyle() : Style(), cstyleContext(NULL), cstyleContextIsInh(true), cstyle()
{
setParent("");
- cstyleBase.setDefaultStyle( &cstyle );
-// qDebug(QString("ParagraphStyle() %1 pbase %2 cbase %3").arg(reinterpret_cast<uint>(this)).arg(reinterpret_cast<uint>(base())).arg(reinterpret_cast<uint>(defaultStyle()->base())));
+ cstyleContext.setDefaultStyle( &cstyle );
+// qDebug(QString("ParagraphStyle() %1 pcontext %2 ccontext %3").arg(reinterpret_cast<uint>(this)).arg(reinterpret_cast<uint>(context())).arg(reinterpret_cast<uint>(defaultStyle()->context())));
#define ATTRDEF(attr_TYPE, attr_GETTER, attr_NAME, attr_DEFAULT) \
m_##attr_NAME = attr_DEFAULT; \
inh_##attr_NAME = true;
@@ -31,13 +31,13 @@
}
-ParagraphStyle::ParagraphStyle(const ParagraphStyle& other) : Style(other), cstyleBase(NULL), cstyleBaseIsInh(other.cstyleBaseIsInh), cstyle(other.charStyle())
+ParagraphStyle::ParagraphStyle(const ParagraphStyle& other) : Style(other), cstyleContext(NULL), cstyleContextIsInh(other.cstyleContextIsInh), cstyle(other.charStyle())
{
- if (cstyleBaseIsInh)
- cstyle.setBase(NULL);
+ if (cstyleContextIsInh)
+ cstyle.setContext(NULL);
else
- cstyle.setBase(other.charStyle().base());
- cstyleBase.setDefaultStyle( &cstyle );
+ cstyle.setContext(other.charStyle().context());
+ cstyleContext.setDefaultStyle( &cstyle );
// qDebug(QString("ParagraphStyle(%2) %1").arg(reinterpret_cast<uint>(&other)).arg(reinterpret_cast<uint>(this)));
other.validate();
@@ -55,7 +55,7 @@
QString ParagraphStyle::displayName() const
{
- if ( hasName() || !hasParent() || !m_base)
+ if ( hasName() || !hasParent() || !m_context)
return name();
// else if ( inheritsAll() )
// return parent()->displayName();
@@ -87,17 +87,17 @@
cstyle = other.charStyle();
- // we dont want cstyleBase to point to other's charstyle...
- cstyleBase.setDefaultStyle( &cstyle );
+ // we dont want cstyleContext to point to other's charstyle...
+ cstyleContext.setDefaultStyle( &cstyle );
- if (cstyleBaseIsInh)
+ if (cstyleContextIsInh)
{
const ParagraphStyle * parent = dynamic_cast<const ParagraphStyle*> ( parentStyle() );
- cstyle.setBase(parent ? parent->charStyleBase() : NULL);
+ cstyle.setContext(parent ? parent->charStyleContext() : NULL);
}
else
{
- cstyle.setBase(other.charStyle().base());
+ cstyle.setContext(other.charStyle().context());
}
#define ATTRDEF(attr_TYPE, attr_GETTER, attr_NAME, attr_DEFAULT) \
@@ -109,18 +109,18 @@
}
-void ParagraphStyle::setBase(const StyleBase* base)
+void ParagraphStyle::setContext(const StyleContext* context)
{
- Style::setBase(base);
-// qDebug(QString("ParagraphStyle::setBase(%1) parent=%2").arg((unsigned long int)base).arg((unsigned long int)oth));
+ Style::setContext(context);
+// qDebug(QString("ParagraphStyle::setContext(%1) parent=%2").arg((unsigned long int)context).arg((unsigned long int)oth));
repairImplicitCharStyleInheritance();
}
void ParagraphStyle::repairImplicitCharStyleInheritance()
{
- if (cstyleBaseIsInh) {
+ if (cstyleContextIsInh) {
const ParagraphStyle * newParent = dynamic_cast<const ParagraphStyle*> ( parentStyle() );
- cstyle.setBase(newParent ? newParent->charStyleBase() : NULL);
+ cstyle.setContext(newParent ? newParent->charStyleContext() : NULL);
}
}
@@ -127,22 +127,23 @@
void ParagraphStyle::breakImplicitCharStyleInheritance(bool val)
{
- cstyleBaseIsInh = !val;
+ cstyleContextIsInh = !val;
repairImplicitCharStyleInheritance();
}
-void ParagraphStyle::update(const StyleBase* base)
+void ParagraphStyle::update(const StyleContext* context)
{
- Style::update(base);
- assert ( &cstyleBase != cstyle.base());
+ Style::update(context);
+ assert ( &cstyleContext != cstyle.context());
repairImplicitCharStyleInheritance();
+ assert ( &cstyleContext != cstyle.context());
+ cstyle.validate();
+ cstyleContext.invalidate();
const ParagraphStyle * oth = dynamic_cast<const ParagraphStyle*> ( parentStyle() );
-// qDebug(QString("ParagraphStyle::update(%1) parent=%2").arg((unsigned long int)base).arg((unsigned long int)oth));
+// qDebug(QString("ParagraphStyle::update(%1) parent=%2").arg((unsigned long int)context).arg((unsigned long int)oth));
if (oth) {
- assert ( &cstyleBase != cstyle.base());
- cstyle.validate();
#define ATTRDEF(attr_TYPE, attr_GETTER, attr_NAME, attr_DEFAULT) \
if (inh_##attr_NAME) \
m_##attr_NAME = oth->attr_GETTER();
@@ -149,7 +150,6 @@
#include "paragraphstyle.attrdefs.cxx"
#undef ATTRDEF
}
- cstyleBase.invalidate();
}
@@ -158,7 +158,7 @@
{
Style::applyStyle(other);
cstyle.applyCharStyle(other.charStyle());
- cstyleBase.invalidate();
+ cstyleContext.invalidate();
#define ATTRDEF(attr_TYPE, attr_GETTER, attr_NAME, attr_DEFAULT) \
if (! other.inh_##attr_NAME) \
set##attr_NAME(other.m_##attr_NAME);
@@ -172,7 +172,7 @@
other.validate();
Style::eraseStyle(other);
cstyle.eraseCharStyle(other.charStyle());
- cstyleBase.invalidate();
+ cstyleContext.invalidate();
#define ATTRDEF(attr_TYPE, attr_GETTER, attr_NAME, attr_DEFAULT) \
if (!inh_##attr_NAME && m_##attr_NAME == other.m_##attr_NAME) \
reset##attr_NAME();
@@ -185,7 +185,7 @@
other.validate();
setParent(other.parent());
cstyle.setStyle(other.charStyle());
- cstyleBase.invalidate();
+ cstyleContext.invalidate();
#define ATTRDEF(attr_TYPE, attr_GETTER, attr_NAME, attr_DEFAULT) \
inh_##attr_NAME = other.inh_##attr_NAME; \
m_##attr_NAME = other.m_##attr_NAME;
/branches/Version13x/Scribus/scribus/styles/stylecontextproxy.cpp
0,0 → 1,34
/*
For general Scribus (>=1.3.2) copyright and licensing information please refer
to the COPYING file provided with the program. Following this notice may exist
a copyright and/or license notice that predates the release of Scribus 1.3.2
for which a new license (GPL+exception) is in place.
*/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
 
#include "style.h"
#include "stylecontextproxy.h"
 
 
const Style* StyleContextProxy::resolve(const QString& name) const
{
const StyleContext* context = m_default->context();
// if (!name.isEmpty())
// qDebug(QString("resolve %4 %3 -%1- %2").arg(name)
// .arg(reinterpret_cast<uint>(context),16).arg(reinterpret_cast<uint>(this),16)
// .arg(m_default->name()));
if (name.isEmpty() || ! context)
return m_default;
else if (this == context)
return NULL;
else
return context->resolve(name);
}
Property changes:
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Author Date Id Revision
\ No newline at end of property
Index: branches/Version13x/Scribus/scribus/styles/stylecontext.h
===================================================================
--- branches/Version13x/Scribus/scribus/styles/stylecontext.h (nonexistent)
+++ branches/Version13x/Scribus/scribus/styles/stylecontext.h (revision 8134)
@@ -0,0 +1,82 @@
+/*
+ For general Scribus (>=1.3.2) copyright and licensing information please refer
+ to the COPYING file provided with the program. Following this notice may exist
+ a copyright and/or license notice that predates the release of Scribus 1.3.2
+ for which a new license (GPL+exception) is in place.
+ */
+/***************************************************************************
+* *
+* This program is free software; you can redistribute it and/or modify *
+* it under the terms of the GNU General Public License as published by *
+* the Free Software Foundation; either version 2 of the License, or *
+* (at your option) any later version. *
+* *
+***************************************************************************/
+
+
+#ifndef STYLECONTEXT_H
+#define STYLECONTEXT_H
+
+#include <cassert>
+#include <qsignal.h>
+#include <qstring.h>
+#include <qvaluelist.h>
+#include "scribusapi.h"
+
+
+class Style;
+
+
+/**
+ Style inheritance works with names. A StyleContext finds the Style to a given name.
+ If there are changes to the Styles contained in a StyleContext, you have to call
+ invalidate() to increase the version info. Styles using this StyleContext will then
+ update their cached values the next time they are used.
+ */
+class SCRIBUS_API StyleContext {
+
+public:
+ StyleContext()
+ : m_version(0), m_sig(), m_cnt(0)
+ {
+// qDebug(QString("constr. %1 /%2").arg(reinterpret_cast<uint>(this),16).arg(m_level));
+ }
+
+ StyleContext(const StyleContext& o)
+ : m_version(o.m_version), m_sig(), m_cnt(0)
+ {
+// qDebug(QString("constr. cp %1 /%2").arg(reinterpret_cast<uint>(this),16).arg(m_level));
+ }
+
+
+ StyleContext& operator= (const StyleContext& o)
+ {
+ m_version = o.m_version;
+ m_cnt = 0;
+ return *this;
+ }
+
+
+ int version() const { return m_version; }
+
+ virtual bool contextContained(const StyleContext* context) const { return context == this; }
+ virtual bool checkConsistency() const { return true; }
+ virtual const Style* resolve(const QString& name) const = 0;
+ virtual ~StyleContext()
+ {
+// qDebug(QString("destr. %1").arg(reinterpret_cast<uint>(this),16));
+ }
+
+ void invalidate();
+
+ bool connect(const QObject* receiver, const char *member ) const;
+ bool disconnect(const QObject* receiver, const char *member=0 ) const;
+
+
+protected:
+ int m_version;
+ mutable QSignal m_sig;
+ mutable int m_cnt;
+};
+
+#endif
/branches/Version13x/Scribus/scribus/styles/stylecontext.h
Property changes:
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Author Date Id Revision
\ No newline at end of property
Index: branches/Version13x/Scribus/scribus/styles/paragraphstyle.h
===================================================================
--- branches/Version13x/Scribus/scribus/styles/paragraphstyle.h (revision 8133)
+++ branches/Version13x/Scribus/scribus/styles/paragraphstyle.h (revision 8134)
@@ -65,8 +65,8 @@
QString displayName() const;
- void setBase(const StyleBase* base);
- void update(const StyleBase*);
+ void setContext(const StyleContext* context);
+ void update(const StyleContext*);
bool equiv(const Style& other) const;
@@ -75,17 +75,17 @@
void setStyle(const ParagraphStyle& other);
void erase() { eraseStyle(*this); }
- StyleBase* charStyleBase() { return & cstyleBase; }
- const StyleBase* charStyleBase() const { return & cstyleBase; }
+ StyleContext* charStyleContext() { return & cstyleContext; }
+ const StyleContext* charStyleContext() const { return & cstyleContext; }
CharStyle & charStyle() { return cstyle; }
const CharStyle& charStyle() const { return cstyle; }
- /** Normally the base for charStyle() is parentStyle()->charStyleBase()
- Use this method to break that relation and set charStyle()'s base manually
+ /** Normally the context for charStyle() is parentStyle()->charStyleContext()
+ Use this method to break that relation and set charStyle()'s context manually
*/
void breakImplicitCharStyleInheritance(bool val = true);
/** used internally to establish the implicit relation
- charStyle().base() == parentStyle()->charStyleBase()
- Done implicitly in setBase(), update(), operator= and breakImplicitCharStyleInheritance()
+ charStyle().context() == parentStyle()->charStyleContext()
+ Done implicitly in setContext(), update(), operator= and breakImplicitCharStyleInheritance()
*/
void repairImplicitCharStyleInheritance();
@@ -131,8 +131,8 @@
private:
// member declarations:
- StyleBaseProxy cstyleBase;
- bool cstyleBaseIsInh;
+ StyleContextProxy cstyleContext;
+ bool cstyleContextIsInh;
CharStyle cstyle;
#define ATTRDEF(attr_TYPE, attr_GETTER, attr_NAME, attr_DEFAULT) \
/branches/Version13x/Scribus/scribus/styles/CMakeLists.txt
8,6 → 8,8
)
 
SET(SCRIBUS_STYLES_LIB_SOURCES
stylecontext.cpp
stylecontextproxy.cpp
charstyle.cpp
paragraphstyle.cpp
)
/branches/Version13x/Scribus/scribus/styles/stylecontextproxy.h
0,0 → 1,79
/*
For general Scribus (>=1.3.2) copyright and licensing information please refer
to the COPYING file provided with the program. Following this notice may exist
a copyright and/or license notice that predates the release of Scribus 1.3.2
for which a new license (GPL+exception) is in place.
*/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
 
 
#ifndef STYLECONTEXTPROXY_H
#define STYLECONTEXTPROXY_H
 
#include <cassert>
#include <qsignal.h>
#include <qstring.h>
#include <qvaluelist.h>
#include "scfonts.h"
#include "scribusapi.h"
#include "sccolor.h"
#include "styles/stylecontext.h"
 
 
/** This class turns a style into a new stylecontext:
* it maps the empty name "" to the given default style and uses
* the style's context to resolve all other names.
*/
class StyleContextProxy: public StyleContext
{
public:
const Style* resolve(const QString& name) const;
StyleContextProxy(const Style* style)
: StyleContext(), m_default(style) {
}
StyleContextProxy(const StyleContextProxy& other)
: StyleContext(other), m_default(other.m_default) {
}
StyleContextProxy& operator= (const StyleContextProxy& other)
{
static_cast<StyleContext&>(*this) = static_cast<const StyleContext&>(other);
m_default = other.m_default;
return *this;
}
const Style* defaultStyle() const { return m_default; }
void setDefaultStyle(const Style* def) {
assert(def);
m_default = def;
invalidate();
}
bool checkConsistency() const
{
const StyleContext* context = m_default->context();
return !context || context == this || !context->contextContained(this);
}
bool contextContained(const StyleContext* context) const
{
const StyleContext* mycontext = m_default->context();
return context == this ||
(mycontext && mycontext->contextContained(context));
}
private:
const Style* m_default;
};
 
#endif
Property changes:
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Author Date Id Revision
\ No newline at end of property
Index: branches/Version13x/Scribus/scribus/text/sctext_shared.cpp
===================================================================
--- branches/Version13x/Scribus/scribus/text/sctext_shared.cpp (revision 8133)
+++ branches/Version13x/Scribus/scribus/text/sctext_shared.cpp (revision 8134)
@@ -9,16 +9,16 @@
#include "scribus.h"
#include "util.h"
-ScText_Shared::ScText_Shared(const StyleBase* pstyles) : QPtrList<ScText>(),
+ScText_Shared::ScText_Shared(const StyleContext* pstyles) : QPtrList<ScText>(),
defaultStyle(),
- pstyleBase(NULL),
+ pstyleContext(NULL),
refs(1), len(0), trailingStyle()
{
- pstyleBase.setDefaultStyle( & defaultStyle );
+ pstyleContext.setDefaultStyle( & defaultStyle );
setAutoDelete(true);
- defaultStyle.setBase( pstyles );
- trailingStyle.setBase( &pstyleBase );
-// defaultStyle.charStyle().setBase( cstyles );
+ defaultStyle.setContext( pstyles );
+ trailingStyle.setContext( &pstyleContext );
+// defaultStyle.charStyle().setContext( cstyles );
// qDebug(QString("ScText_Shared() %1 %2 %3 %4").arg(reinterpret_cast<uint>(this)).arg(reinterpret_cast<uint>(&defaultStyle)).arg(reinterpret_cast<uint>(pstyles)).arg(reinterpret_cast<uint>(cstyles)));
}
@@ -25,11 +25,11 @@
ScText_Shared::ScText_Shared(const ScText_Shared& other) : QPtrList<ScText>(),
defaultStyle(other.defaultStyle),
- pstyleBase(other.pstyleBase),
+ pstyleContext(other.pstyleContext),
refs(1), len(0), trailingStyle(other.trailingStyle)
{
- pstyleBase.setDefaultStyle( &defaultStyle );
- trailingStyle.setBase( &pstyleBase );
+ pstyleContext.setDefaultStyle( &defaultStyle );
+ trailingStyle.setContext( &pstyleContext );
setAutoDelete(true);
QPtrListIterator<ScText> it( other );
ScText* elem;
@@ -38,13 +38,13 @@
ScText* elem2 = new ScText(*elem);
append(elem2);
if (elem2->parstyle) {
- elem2->parstyle->setBase( & pstyleBase);
-// elem2->parstyle->charStyle().setBase( defaultStyle.charStyleBase() );
- replaceCharStyleBaseInParagraph(count()-1, elem2->parstyle->charStyleBase());
+ elem2->parstyle->setContext( & pstyleContext);
+// elem2->parstyle->charStyle().setContext( defaultStyle.charStyleContext() );
+ replaceCharStyleContextInParagraph(count()-1, elem2->parstyle->charStyleContext());
}
}
len = count();
- replaceCharStyleBaseInParagraph(len, trailingStyle.charStyleBase() );
+ replaceCharStyleContextInParagraph(len, trailingStyle.charStyleContext() );
// qDebug(QString("ScText_Shared(%2) %1").arg(reinterpret_cast<uint>(this)).arg(reinterpret_cast<uint>(&other)));
}
@@ -54,10 +54,10 @@
{
defaultStyle = other.defaultStyle;
trailingStyle = other.trailingStyle;
- pstyleBase = other.pstyleBase;
- pstyleBase.setDefaultStyle( &defaultStyle );
- defaultStyle.setBase( other.defaultStyle.base() );
- trailingStyle.setBase( &pstyleBase );
+ pstyleContext = other.pstyleContext;
+ pstyleContext.setDefaultStyle( &defaultStyle );
+ defaultStyle.setContext( other.defaultStyle.context() );
+ trailingStyle.setContext( &pstyleContext );
clear();
QPtrListIterator<ScText> it( other );
ScText* elem;
@@ -66,19 +66,19 @@
ScText* elem2 = new ScText(*elem);
append(elem2);
if (elem2->parstyle) {
- elem2->parstyle->setBase( & pstyleBase );
+ elem2->parstyle->setContext( & pstyleContext );
// qDebug(QString("StoryText::copy: * %1 align=%2").arg(elem2->parstyle->parent())
// .arg(elem2->parstyle->alignment())
-// .arg((uint)elem2->parstyle->base()));
- // elem2->parstyle->charStyle().setBase( defaultStyle.charStyleBase() );
- replaceCharStyleBaseInParagraph(count()-1, elem2->parstyle->charStyleBase());
+// .arg((uint)elem2->parstyle->context()));
+ // elem2->parstyle->charStyle().setContext( defaultStyle.charStyleContext() );
+ replaceCharStyleContextInParagraph(count()-1, elem2->parstyle->charStyleContext());
}
}
len = count();
- pstyleBase.invalidate();
+ pstyleContext.invalidate();
// qDebug(QString("StoryText::copy: %1 align=%2 %3").arg(trailingStyle.parentStyle()->name())
-// .arg(trailingStyle.alignment()).arg((uint)trailingStyle.base()));
- replaceCharStyleBaseInParagraph(len, trailingStyle.charStyleBase());
+// .arg(trailingStyle.alignment()).arg((uint)trailingStyle.context()));
+ replaceCharStyleContextInParagraph(len, trailingStyle.charStyleContext());
}
// qDebug(QString("ScText_Shared: %1 = %2").arg(reinterpret_cast<uint>(this)).arg(reinterpret_cast<uint>(&other)));
return *this;
@@ -89,11 +89,11 @@
}
/**
- A char's stylebase is the containing paragraph's style,
+ A char's stylecontext is the containing paragraph's style,
This routines makes sure that all charstyles look for defaults
in the parstyle first.
*/
-void ScText_Shared::replaceCharStyleBaseInParagraph(int pos, const StyleBase* newBase)
+void ScText_Shared::replaceCharStyleContextInParagraph(int pos, const StyleContext* newContext)
{
QPtrListIterator<ScText> it( *this );
it += (pos-1);
@@ -101,12 +101,12 @@
while ( (elem = it.current()) != NULL ) {
if (elem->ch[0] == SpecialChars::PARSEP)
break;
- elem->setBase(newBase);
+ elem->setContext(newContext);
--it;
}
// assert that all chars point to the following parstyle
QPtrListIterator<ScText> test( *this );
- const StyleBase* lastBase = NULL;
+ const StyleContext* lastContext = NULL;
while ( (elem = it.current()) != NULL ) {
if ( elem->ch.isEmpty() )
{
@@ -115,21 +115,21 @@
else if (elem->ch[0] == SpecialChars::PARSEP)
{
assert( elem->parstyle );
- if ( lastBase )
- assert( lastBase == elem->parstyle->charStyleBase() );
- lastBase = NULL;
+ if ( lastContext )
+ assert( lastContext == elem->parstyle->charStyleContext() );
+ lastContext = NULL;
}
- else if (lastBase == NULL)
+ else if (lastContext == NULL)
{
- lastBase = elem->base();
+ lastContext = elem->context();
}
else
{
- assert( lastBase == elem->base() );
+ assert( lastContext == elem->context() );
}
++it;
}
- if ( lastBase )
- assert( lastBase == trailingStyle.charStyleBase() );
+ if ( lastContext )
+ assert( lastContext == trailingStyle.charStyleContext() );
}
/branches/Version13x/Scribus/scribus/text/sctext_shared.h
11,6 → 11,7
//#include "text/paragraphlayout.h"
#include "text/frect.h"
#include "style.h"
#include "styles/stylecontextproxy.h"
 
#ifdef NLS_CONFORMANCE
#define NLS_PRIVATE private
27,11 → 28,11
{
public:
ParagraphStyle defaultStyle;
StyleBaseProxy pstyleBase;
StyleContextProxy pstyleContext;
uint refs;
uint len;
ParagraphStyle trailingStyle;
ScText_Shared(const StyleBase* pstyles);
ScText_Shared(const StyleContext* pstyles);
 
ScText_Shared(const ScText_Shared& other);
 
40,11 → 41,11
~ScText_Shared();
/**
A char's stylebase is the containing paragraph's style,
A char's stylecontext is the containing paragraph's style,
This routines makes sure that all charstyles look for defaults
in the parstyle first.
*/
void replaceCharStyleBaseInParagraph(int pos, const StyleBase* newBase);
void replaceCharStyleContextInParagraph(int pos, const StyleContext* newContext);
};
 
#endif /*SCTEXT_SHARED_H*/
/branches/Version13x/Scribus/scribus/text/storytext.cpp
261,12 → 261,12
ScText* it = that->item_p(pos);
if(!it->parstyle) {
it->parstyle = new ParagraphStyle(that->paragraphStyle(pos+1));
it->parstyle->setBase( & d->pstyleBase);
it->parstyle->setContext( & d->pstyleContext);
it->parstyle->setName("para"); // DONT TRANSLATE
it->parstyle->charStyle().setName("cpara"); // DONT TRANSLATE
// it->parstyle->charStyle().setBase( d->defaultStyle.charStyleBase() );
// it->parstyle->charStyle().setContext( d->defaultStyle.charStyleContext() );
}
d->replaceCharStyleBaseInParagraph(pos, it->parstyle->charStyleBase());
d->replaceCharStyleContextInParagraph(pos, it->parstyle->charStyleContext());
}
/**
need to remove the ParagraphStyle structure and replace all pointers
282,10 → 282,10
delete it->parstyle;
it->parstyle = 0;
}
// demote this parsep so the assert code in replaceCharStyleBaseInParagraph()
// demote this parsep so the assert code in replaceCharStyleContextInParagraph()
// doesnt choke:
it->ch = "";
d->replaceCharStyleBaseInParagraph(pos, that->paragraphStyle(pos+1).charStyleBase());
d->replaceCharStyleContextInParagraph(pos, that->paragraphStyle(pos+1).charStyleContext());
}
 
void StoryText::removeChars(int pos, uint len)
328,13 → 328,13
if (txt.length() == 0)
return;
const StyleBase* cStyleBase = paragraphStyle(pos).charStyleBase();
const StyleContext* cStyleContext = paragraphStyle(pos).charStyleContext();
// assert( !style.font().isNone() );
for (uint i = 0; i < txt.length(); ++i) {
ScText * item = new ScText();
item->ch= txt.mid(i, 1);
item->setBase(cStyleBase);
item->setContext(cStyleContext);
d->insert(pos + i, item);
d->len++;
if (item->ch[0] == SpecialChars::PARSEP) {
499,10 → 499,10
else if ( !that->d->current()->parstyle ) {
qDebug(QString("inserting default parstyle at %1").arg(pos));
that->d->current()->parstyle = new ParagraphStyle();
that->d->current()->parstyle->setBase( & d->pstyleBase);
that->d->current()->parstyle->setContext( & d->pstyleContext);
that->d->current()->parstyle->setName( "para(paragraphStyle)" ); // DONT TRANSLATE
that->d->current()->parstyle->charStyle().setName( "cpara(paragraphStyle)" ); // DONT TRANSLATE
// that->d->current()->parstyle->charStyle().setBase( d->defaultStyle.charStyleBase());
// that->d->current()->parstyle->charStyle().setContext( d->defaultStyle.charStyleContext());
}
else {
// qDebug(QString("using parstyle at %1").arg(pos));
520,17 → 520,17
 
void StoryText::setDefaultStyle(const ParagraphStyle& style)
{
const StyleBase * oldPBase = d->defaultStyle.base();
const StyleBase * oldCBase = d->defaultStyle.charStyle().base();
const StyleContext * oldPContext = d->defaultStyle.context();
const StyleContext * oldCContext = d->defaultStyle.charStyle().context();
d->defaultStyle = style;
d->defaultStyle.setBase( oldPBase );
d->defaultStyle.setContext( oldPContext );
d->defaultStyle.setName( "storydefault" ); // DONT TRANSLATE
d->defaultStyle.charStyle().setName( "cstorydefault" ); // DONT TRANSLATE
// qDebug(QString("defstyle %1 base %2 defcstyle %3 cbase %4 newbase %5")
// .arg((uint)&d->defaultStyle,16).arg((uint)oldPBase,16)
// .arg((uint)&d->defaultStyle.charStyle(),16).arg((uint)oldCBase,16)
// .arg((uint)d->defaultStyle.charStyle().base(),16));
// d->defaultStyle.charStyle().setBase( oldCBase );
// qDebug(QString("defstyle %1 context %2 defcstyle %3 ccontext %4 newcontext %5")
// .arg((uint)&d->defaultStyle,16).arg((uint)oldPContext,16)
// .arg((uint)&d->defaultStyle.charStyle(),16).arg((uint)oldCContext,16)
// .arg((uint)d->defaultStyle.charStyle().context(),16));
// d->defaultStyle.charStyle().setContext( oldCContext );
invalidateAll();
}
 
610,10 → 610,10
if (!d->at(i)->parstyle) {
qDebug(QString("PARSEP without style at pos %1").arg(i));
d->at(i)->parstyle = new ParagraphStyle();
d->at(i)->parstyle->setBase( & d->pstyleBase);
d->at(i)->parstyle->setContext( & d->pstyleContext);
d->at(i)->parstyle->setName( "para(applyStyle)" ); // DONT TRANSLATE
d->at(i)->parstyle->charStyle().setName( "cpara(applyStyle)" ); // DONT TRANSLATE
// d->at(i)->parstyle->charStyle().setBase( d->defaultStyle.charStyleBase() );
// d->at(i)->parstyle->charStyle().setContext( d->defaultStyle.charStyleContext() );
}
// qDebug(QString("applying parstyle %2 at %1 for %3").arg(i).arg(paragraphStyle(pos).name()).arg(pos));
d->at(i)->parstyle->applyStyle(style);
642,10 → 642,10
if (!d->at(i)->parstyle) {
qDebug(QString("PARSEP without style at pos %1").arg(i));
d->at(i)->parstyle = new ParagraphStyle();
d->at(i)->parstyle->setBase( & d->pstyleBase);
d->at(i)->parstyle->setContext( & d->pstyleContext);
d->at(i)->parstyle->setName( "para(eraseStyle)" ); // DONT TRANSLATE
d->at(i)->parstyle->charStyle().setName( "cpara(eraseStyle)" ); // DONT TRANSLATE
// d->at(i)->parstyle->charStyle().setBase( d->defaultStyle.charStyleBase());
// d->at(i)->parstyle->charStyle().setContext( d->defaultStyle.charStyleContext());
}
// qDebug(QString("applying parstyle %2 at %1 for %3").arg(i).arg(paragraphStyle(pos).name()).arg(pos));
d->at(i)->parstyle->eraseStyle(style);
1056,7 → 1056,7
 
void StoryText::invalidateAll()
{
d->pstyleBase.invalidate();
d->pstyleContext.invalidate();
invalidate(0, nrOfItems());
}
 
1065,7 → 1065,7
for (int i=firstItem; i < endItem; ++i) {
ParagraphStyle* par = item(i)->parstyle;
if (par)
par->charStyleBase()->invalidate();
par->charStyleContext()->invalidate();
}
}
 
/branches/Version13x/Scribus/scribus/style.h
24,93 → 24,37
#include "scfonts.h"
#include "scribusapi.h"
#include "sccolor.h"
#include "styles/stylecontext.h"
 
 
class Style;
 
 
/**
Style inheritance works with names. A StyleBase finds the Style to a given name.
If there are changes to the Styles contained in a StyleBase, you have to call
invalidate() to increase the version info. Styles using this StyleBase will then
update their cached values the next time they are used.
*/
class SCRIBUS_API StyleBase {
public:
StyleBase()
: m_version(0), m_sig(), m_cnt(0)
{
// qDebug(QString("constr. %1 /%2").arg(reinterpret_cast<uint>(this),16).arg(m_level));
}
StyleBase(const StyleBase& o)
: m_version(o.m_version), m_sig(), m_cnt(0)
{
// qDebug(QString("constr. cp %1 /%2").arg(reinterpret_cast<uint>(this),16).arg(m_level));
}
 
StyleBase& operator= (const StyleBase& o)
{
m_version = o.m_version;
m_cnt = 0;
return *this;
}
int version() const { return m_version; }
virtual bool baseContained(const StyleBase* base) const { return base == this; }
virtual bool checkConsistency() const { return true; }
virtual const Style* resolve(const QString& name) const = 0;
virtual ~StyleBase()
{
// qDebug(QString("destr. %1").arg(reinterpret_cast<uint>(this),16));
}
 
void invalidate();
 
bool connect(const QObject* receiver, const char *member ) const;
bool disconnect(const QObject* receiver, const char *member=0 ) const;
protected:
int m_version;
mutable QSignal m_sig;
mutable int m_cnt;
};
 
 
 
/**
* This as a virtual base class for all style-like objects: CharStyles,
* ParagraphStyles(indirectly), LineStyles, FrameStyles, CellStyles,
* This is the base class for all style-like objects: CharStyles,
* ParagraphStyles, LineStyles, FrameStyles, CellStyles,
* FlowStyles,...
* It provides a name and an inheritance mechanism which uses a StyleBase.
* It provides a name and an inheritance mechanism which uses a Stylecontext.
* Before any attribute is queried, you have to call validate(), which checks
* the stored m_baseversion against the StyleBase's version and updates all
* the stored m_contextversion against the StyleContext's version and updates all
* attributes if they are different.
*/
class SCRIBUS_API Style {
protected:
QString m_name;
const StyleBase* m_base;
int m_baseversion;
const StyleContext* m_context;
int m_contextversion;
QString m_parent;
QString m_shortcut;
public:
// static const short NOVALUE = -16000;
 
Style(): m_name(""), m_base(NULL), m_baseversion(-1), m_parent(), m_shortcut() {}
Style(): m_name(""), m_context(NULL), m_contextversion(-1), m_parent(), m_shortcut() {}
 
Style(StyleBase* b, QString n): m_name(n), m_base(b), m_baseversion(-1), m_parent(), m_shortcut() {}
Style(StyleContext* b, QString n): m_name(n), m_context(b), m_contextversion(-1), m_parent(), m_shortcut() {}
Style& operator=(const Style& o)
{ //assert(typeinfo() == o.typeinfo());
m_name = o.m_name;
// m_base = o.m_base;
m_baseversion = -1;
// m_context = o.m_context;
m_contextversion = -1;
m_parent = o.m_parent;
m_shortcut = o.m_shortcut;
return *this;
117,7 → 61,7
}
Style(const Style& o) : m_name(o.m_name),
m_base(o.m_base), m_baseversion(o.m_baseversion), m_parent(o.m_parent), m_shortcut(o.m_shortcut) {}
m_context(o.m_context), m_contextversion(o.m_contextversion), m_parent(o.m_parent), m_shortcut(o.m_shortcut) {}
virtual ~Style() {}
 
126,7 → 70,7
bool hasName() const { return ! m_name.isEmpty(); }
 
virtual QString displayName() const {
if ( hasName() || !hasParent() || !m_base)
if ( hasName() || !hasParent() || !m_context)
return name();
// else if ( inheritsAll() )
// return parent()->displayName();
135,19 → 79,19
}
QString parent() const { return m_parent; }
void setParent(const QString& p) { if (m_parent != p) m_baseversion = -1; m_parent = p; }
void setParent(const QString& p) { if (m_parent != p) m_contextversion = -1; m_parent = p; }
bool hasParent() const { return ! m_parent.isEmpty(); }
const Style* parentStyle() const;
virtual void setBase(const StyleBase* base);
const StyleBase* base() const { return m_base; }
virtual void setContext(const StyleContext* context);
const StyleContext* context() const { return m_context; }
/**
sets a new StyleBase if b is not NULL and then uses the StyleBase
sets a new StyleContext if b is not NULL and then uses the StyleContext
to set all inherited attributes to their valid value.
*/
virtual void update(const StyleBase* b = NULL);
virtual void update(const StyleContext* b = NULL);
/**
Checks if this Style needs an update
160,12 → 104,12
/**
returns true if both Styles are of the same type, inherit the same attributes,
have the same parent, and agree on all attributes which are not inherited.
The StyleBase, the name and any inherited attrinutes may be different.
The StyleContext, the name and any inherited attrinutes may be different.
*/
virtual bool equiv(const Style& other) const = 0;
/**
returns true if both Styles are equivalent and have the same name.
Since the base is not tested, this does *not* ensure they will return
Since the context is not tested, this does *not* ensure they will return
the same values for all attributes.
*/
virtual bool operator==(const Style& other) const { return name() == other.name() && equiv(other); }
182,7 → 126,7
void applyStyle(const Style& other) {
if (other.hasParent())
setParent(other.parent());
m_baseversion = -1;
m_contextversion = -1;
}
/**
if other has the same parent, remove this parent
190,62 → 134,13
void eraseStyle(const Style& other) {
if (other.parent() == parent())
setParent("");
m_baseversion = -1;
m_contextversion = -1;
}
};
 
 
/** This class turns a style into a new stylebase:
* it maps the empty name "" to the given default style and uses
* the style's base to resolve all other names.
*/
class StyleBaseProxy: public StyleBase
{
public:
const Style* resolve(const QString& name) const;
StyleBaseProxy(const Style* style)
: StyleBase(), m_default(style) {
}
StyleBaseProxy(const StyleBaseProxy& other)
: StyleBase(other), m_default(other.m_default) {
}
StyleBaseProxy& operator= (const StyleBaseProxy& other)
{
static_cast<StyleBase&>(*this) = static_cast<const StyleBase&>(other);
m_default = other.m_default;
return *this;
}
const Style* defaultStyle() const { return m_default; }
void setDefaultStyle(const Style* def) {
assert(def);
m_default = def;
invalidate();
}
bool checkConsistency() const
{
const StyleBase* base = m_default->base();
return !base || base == this || !base->baseContained(this);
}
bool baseContained(const StyleBase* base) const
{
const StyleBase* mybase = m_default->base();
return base == this ||
(mybase && mybase->baseContained(base));
}
private:
const Style* m_default;
};
 
 
 
//FIXME: make this proper: charstyle.h #includes style.h, pstyle.h #includes style.h and stylecontextproxy.h
#include "styles/stylecontextproxy.h"
#include "styles/charstyle.h"
#include "styles/paragraphstyle.h"
 
/branches/Version13x/Scribus/scribus/scribusdoc.cpp
395,7 → 395,7
docCharStyles.makeDefault( &(docCharStyles[0]) );
docParagraphStyles[0].breakImplicitCharStyleInheritance();
docParagraphStyles[0].charStyle().setBase( & docCharStyles );
docParagraphStyles[0].charStyle().setContext( & docCharStyles );
docParagraphStyles[0].charStyle().setName( "cdocdefault" ); // DONT TRANSLATE
 
currentStyle = pstyle;
870,7 → 870,7
if (deletion.count() > 0)
replaceStyles(deletion);
}
// repair charstyle base:
// repair charstyle context:
for (uint i=0; i < docParagraphStyles.count(); ++i)
{
ParagraphStyle& sty(docParagraphStyles[i]);
877,7 → 877,7
if (docParagraphStyles.isDefault(sty))
{
sty.breakImplicitCharStyleInheritance(true);
sty.charStyle().setBase( & docCharStyles );
sty.charStyle().setContext( & docCharStyles );
sty.charStyle().setName( "cdocdefault" ); // DONT TRANSLATE
}
else {
/branches/Version13x/Scribus/scribus/smtextstyles.cpp
387,7 → 387,7
deleted_.clear();
tmpStyles_.redefine(doc_->paragraphStyles(), true);
Q_ASSERT(tmpStyles_.count() > 0);
tmpStyles_[0].charStyle().setBase(cstyles_);
tmpStyles_[0].charStyle().setContext(cstyles_);
}
 
void SMParagraphStyle::setupConnections()