00001
00002
00003
00004
00005
00006
00007
00008
00009 #include <QObject>
00010 #include "sctextstruct.h"
00011 #include "scfonts.h"
00012 #include "resourcecollection.h"
00013
00014 #include "styles/style.h"
00015 #include "linestyle.h"
00016 #include "desaxe/saxiohelper.h"
00017 #include "desaxe/simple_actions.h"
00018 #include "prefsmanager.h"
00019
00020
00021 void LineStyle::applyLineStyle(const LineStyle & other)
00022 {
00023 Style::applyStyle(other);
00024 #define ATTRDEF(attr_TYPE, attr_GETTER, attr_NAME, attr_DEFAULT) \
00025 if (! other.inh_##attr_NAME) \
00026 set##attr_NAME(other.m_##attr_NAME);
00027 #include "linestyle.attrdefs.cxx"
00028 #undef ATTRDEF
00029 }
00030
00031
00032 void LineStyle::eraseLineStyle(const LineStyle & other)
00033 {
00034 other.validate();
00035 Style::eraseStyle(other);
00036 #define ATTRDEF(attr_TYPE, attr_GETTER, attr_NAME, attr_DEFAULT) \
00037 if (!inh_##attr_NAME && m_##attr_NAME == other.m_##attr_NAME) \
00038 reset##attr_NAME();
00039 #include "linestyle.attrdefs.cxx"
00040 #undef ATTRDEF
00041 }
00042
00043 bool LineStyle::equiv(const Style & other) const
00044 {
00045 other.validate();
00046 const LineStyle * oth = dynamic_cast<const LineStyle*> ( & other );
00047 return oth &&
00048 parent() == oth->parent()
00049 #define ATTRDEF(attr_TYPE, attr_GETTER, attr_NAME, attr_DEFAULT) \
00050 && (inh_##attr_NAME == oth->inh_##attr_NAME) \
00051 && (inh_##attr_NAME || m_##attr_NAME == oth->m_##attr_NAME)
00052 #include "linestyle.attrdefs.cxx"
00053 #undef ATTRDEF
00054 ;
00055 }
00056
00057
00058 QString LineStyle::displayName() const
00059 {
00060 if ( hasName() || !hasParent() || ! m_context)
00061 return name();
00062
00063
00064 else
00065 return parentStyle()->displayName() + "+";
00066 }
00067
00068
00069
00070 QString LineStyle::asString() const
00071 {
00072 QString result;
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097 return result.trimmed();
00098 }
00099
00100
00101 void LineStyle::update(const StyleContext* context)
00102 {
00103 Style::update(context);
00104 const LineStyle * oth = dynamic_cast<const LineStyle*> ( parentStyle() );
00105 if (oth) {
00106 #define ATTRDEF(attr_TYPE, attr_GETTER, attr_NAME, attr_DEFAULT) \
00107 if (inh_##attr_NAME) \
00108 m_##attr_NAME = oth->attr_GETTER();
00109 #include "linestyle.attrdefs.cxx"
00110 #undef ATTRDEF
00111 }
00112 }
00113
00114
00115 void LineStyle::setStyle(const LineStyle& other)
00116 {
00117 other.validate();
00118 setParent(other.parent());
00119 #define ATTRDEF(attr_TYPE, attr_GETTER, attr_NAME, attr_DEFAULT) \
00120 inh_##attr_NAME = other.inh_##attr_NAME; \
00121 m_##attr_NAME = other.m_##attr_NAME;
00122 #include "linestyle.attrdefs.cxx"
00123 #undef ATTRDEF
00124 }
00125
00126 void LineStyle::getNamedResources(ResourceCollection& lists) const
00127 {
00128 QList<LineStyle>::const_iterator it, itend = m_Sublines.constEnd();
00129
00130 lists.collectColor(color());
00131 for (const Style* sty = parentStyle(); sty != NULL; sty = sty->parentStyle())
00132 lists.collectLineStyle(sty->name());
00133 for (it = m_Sublines.begin(); it != itend; ++it)
00134 (*it).getNamedResources(lists);
00135 }
00136
00137 void LineStyle::replaceNamedResources(ResourceCollection& newNames)
00138 {
00139 QMap<QString,QString>::ConstIterator it;
00140 QList<LineStyle>::iterator itl, itle = m_Sublines.end();
00141
00142 if (!inh_Color && (it = newNames.colors().find(color())) != newNames.colors().end())
00143 setColor(it.value());
00144 if (hasParent() && (it = newNames.lineStyles().find(parent())) != newNames.lineStyles().end())
00145 setParent(it.value());
00146 for (itl = m_Sublines.begin(); itl != itle; ++itl)
00147 (*itl).replaceNamedResources(newNames);
00148 }
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188 typedef QList<LineStyle> Sublist;
00189
00190 static QString toXMLString(const Sublist & )
00191 {
00192 return "dummy";
00193 }
00194
00195
00196 void LineStyle::saxx(SaxHandler& handler, const Xml_string& elemtag) const
00197 {
00198 Xml_attr att;
00199 Style::saxxAttributes(att);
00200 #define ATTRDEF(attr_TYPE, attr_GETTER, attr_NAME, attr_DEFAULT) \
00201 if (!inh_##attr_NAME && strcmp(# attr_NAME, "Sublines") != 0 ) \
00202 att.insert(# attr_NAME, toXMLString(m_##attr_NAME));
00203 #include "linestyle.attrdefs.cxx"
00204 #undef ATTRDEF
00205 if (!name().isEmpty())
00206 att["id"] = mkXMLName(elemtag + name());
00207 handler.begin(elemtag, att);
00208 if (parentStyle())
00209 parentStyle()->saxx(handler);
00210 Sublist::const_iterator it;
00211 for (it=m_Sublines.begin(); it != m_Sublines.end(); ++it)
00212 {
00213 (*it).saxx(handler, "subline");
00214 }
00215 handler.end(elemtag);
00216 }
00217
00218
00219
00220
00221 template<>
00222 Sublist parse<Sublist>(const Xml_string& str)
00223 {
00224 return Sublist();
00225 }
00226
00227 template<>
00228 Qt::PenStyle parse<Qt::PenStyle>(const Xml_string& str)
00229 {
00230 return parseEnum<Qt::PenStyle>(str);
00231 }
00232
00233 template<>
00234 Qt::PenCapStyle parse<Qt::PenCapStyle>(const Xml_string& str)
00235 {
00236 return parseEnum<Qt::PenCapStyle>(str);
00237 }
00238
00239 template<>
00240 Qt::PenJoinStyle parse<Qt::PenJoinStyle>(const Xml_string& str)
00241 {
00242 return parseEnum<Qt::PenJoinStyle>(str);
00243 }
00244
00245
00246
00247 using namespace desaxe;
00248
00249
00250 const Xml_string LineStyle::saxxDefaultElem("linestyle");
00251
00252 void LineStyle::desaxeRules(const Xml_string& prefixPattern, Digester& ruleset, Xml_string elemtag)
00253 {
00254 Xml_string stylePrefix(Digester::concat(prefixPattern, elemtag));
00255 ruleset.addRule(stylePrefix, Factory<LineStyle>());
00256 ruleset.addRule(stylePrefix, IdRef<LineStyle>());
00257 Style::desaxeRules<LineStyle>(prefixPattern, ruleset, elemtag);
00258
00259
00260
00261 const Xml_string& stylePrefixRec(stylePrefix);
00262 Xml_string subPrefix(Digester::concat(stylePrefixRec, "subline"));
00263 ruleset.addRule(subPrefix, Factory<LineStyle>());
00264 Style::desaxeRules<LineStyle>(stylePrefixRec, ruleset, "subline");
00265
00266 #define ATTRDEF(attr_TYPE, attr_GETTER, attr_NAME, attr_DEFAULT) \
00267 if ( strcmp(# attr_NAME, "Sublines") != 0 ) { \
00268 ruleset.addRule(stylePrefix, SetAttributeWithConversion<LineStyle, attr_TYPE> ( & LineStyle::set##attr_NAME, # attr_NAME, &parse<attr_TYPE> )); \
00269 ruleset.addRule(subPrefix, SetAttributeWithConversion<LineStyle, attr_TYPE> ( & LineStyle::set##attr_NAME, # attr_NAME, &parse<attr_TYPE> )); \
00270 }
00271 #include "linestyle.attrdefs.cxx"
00272 #undef ATTRDEF
00273 ruleset.addRule(subPrefix, SetterWithConversion<LineStyle, const LineStyle&, LineStyle>( & LineStyle::appendSubline ));
00274 }