15 STYLE& operator[] (
int index) {
16 assert(index < styles.count());
17 return * styles[index];
20 STYLE* getDefault(){
return m_default; }
22 const STYLE&
get(
const QString& name)
const {
23 return *
dynamic_cast<const STYLE*
>(resolve(name));
26 const STYLE& operator[] (
int index)
const {
27 assert(index < styles.count());
28 return * styles[index];
31 inline bool contains(
const QString& name)
const;
33 inline int find(
const QString& name)
const;
35 inline const Style* resolve(
const QString& name)
const;
38 return styles.count();
41 STYLE* append(STYLE* style) {
43 style->setContext(
this);
47 inline void remove(
int index);
49 inline void redefine(
const StyleSet<STYLE>& defs,
bool removeUnused=
false);
51 inline void rename(
const QMap<QString,QString>& newNames);
53 STYLE* create(
const STYLE& proto) {
54 return append(
new STYLE(proto));
57 void makeDefault(STYLE* def) {
60 def->setContext(
this);
64 bool isDefault(
const STYLE& style)
const {
65 return &style == m_default;
69 StyleSet() : styles(), m_context(NULL), m_default(NULL) {}
80 void clear(
bool invalid =
true) {
81 while(styles.count()>0)
83 delete styles.front();
91 bool reallyNew = m_context != context;
106 QList<STYLE*> styles;
111 template<
class STYLE>
114 assert(index>=0 && index < styles.count());
116 if (styles.at(index) == m_default)
120 styles.removeAt(index);
123 template<
class STYLE>
126 for (
int i=0; i < styles.count(); ++i)
127 if (styles[i]->name() == name)
132 template<
class STYLE>
135 for (
int i=0; i < styles.count(); ++i)
136 if (styles[i]->name() == name)
141 template<
class STYLE>
146 for (
int i=0; i < styles.count(); ++i)
148 if (styles[i]->name() == name)
151 return m_context ? m_context->resolve(name) : NULL;
154 template<
class STYLE>
157 for (
int i=
signed(styles.count())-1; i >= 0; --i)
160 for (
int j=0; j < defs.count(); ++j)
162 if (styles[i]->name() == defs[j].name())
165 (*styles[i]) = defs[j];
166 (*styles[i]).setContext(
this);
167 if (defs.m_default == defs.styles[j])
168 makeDefault(styles[i]);
172 if (!found && removeUnused)
174 if (styles[i] == m_default)
179 for (
int j=0; j < defs.count(); ++j)
181 if (find(defs[j].name()) < 0)
183 STYLE* newStyle = create(defs[j]);
184 if (defs.m_default == defs.styles[j])
185 makeDefault(newStyle);
191 template<
class STYLE>
194 for (
int i=0; i < styles.count(); ++i)
196 QMap<QString,QString>::ConstIterator it;
198 it = newNames.find(styles[i]->name());
199 if (it != newNames.end())
200 styles[i]->setName(it.value());
202 it = newNames.find(styles[i]->parent());
203 if (it != newNames.end())
204 styles[i]->setParent(it.value());
Definition: stylecontext.h:35
void clear(bool invalid=true)
Definition: styleset.h:80
Definition: styleset.h:13