/usr/include/scribus/styles/styleset.h is in scribus-dev 1.4.6+dfsg-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 | #ifndef STYLESET_H
#define STYLESET_H
#include <assert.h>
#include "style.h"
//Added by qt3to4:
#include <QList>
template<class STYLE>
class StyleSet : public StyleContext {
public:
STYLE& operator[] (int index) {
assert(index < styles.count());
return * styles[index];
}
STYLE* getDefault(){ return m_default; }
const STYLE& get(const QString& name) const {
return * dynamic_cast<const STYLE*>(resolve(name));
}
const STYLE& operator[] (int index) const {
assert(index < styles.count());
return * styles[index];
}
inline int find(const QString& name) const;
inline const Style* resolve(const QString& name) const;
int count() const {
return styles.count();
}
STYLE* append(STYLE* style) {
styles.append(style);
style->setContext(this);
return style;
}
inline void remove(int index);
inline void redefine(const StyleSet<STYLE>& defs, bool removeUnused=false);
inline void rename(const QMap<QString,QString>& newNames);
STYLE* create(const STYLE& proto) {
return append(new STYLE(proto));
}
void makeDefault(STYLE* def) {
m_default = def;
if(def)
def->setContext(this);
invalidate();
}
bool isDefault(const STYLE& style) const {
return &style == m_default;
}
StyleSet() : styles(), m_context(NULL), m_default(NULL) {}
~StyleSet() {
clear();
}
void clear() {
while(styles.count()>0)
{
delete styles.front();
styles.pop_front();
}
invalidate();
}
void setContext(const StyleContext* context) {
bool reallyNew = m_context != context;
m_context = context;
if (reallyNew)
invalidate();
}
const StyleContext* context() const {
return m_context;
}
private:
StyleSet(const StyleSet&) { assert(false); }
StyleSet& operator= (const StyleSet&) { assert(false); return *this; }
QList<STYLE*> styles;
const StyleContext* m_context;
STYLE* m_default;
};
template<class STYLE>
inline void StyleSet<STYLE>::remove(int index)
{
assert(index>=0 && index < styles.count());
// QList<STYLE*> it = styles.at(index);
if (styles.at(index) == m_default)
return;
// delete (*it);
// styles.erase(it);
styles.removeAt(index);
}
template<class STYLE>
inline int StyleSet<STYLE>::find(const QString& name) const
{
for (int i=0; i < styles.count(); ++i)
if (styles[i]->name() == name)
return i;
return -1;
}
template<class STYLE>
inline const Style* StyleSet<STYLE>::resolve(const QString& name) const
{
if (name.isEmpty())
return m_default;
for (int i=0; i < styles.count(); ++i)
{
if (styles[i]->name() == name)
return styles[i];
}
return m_context ? m_context->resolve(name) : NULL;
}
template<class STYLE>
inline void StyleSet<STYLE>::redefine(const StyleSet<STYLE>& defs, bool removeUnused)
{
for (int i=signed(styles.count())-1; i >= 0; --i)
{
bool found = false;
for (int j=0; j < defs.count(); ++j)
{
if (styles[i]->name() == defs[j].name())
{
found = true;
(*styles[i]) = defs[j];
(*styles[i]).setContext(this);
if (defs.m_default == defs.styles[j])
makeDefault(styles[i]);
break;
}
}
if (!found && removeUnused)
{
if (styles[i] == m_default)
makeDefault(NULL);
remove(i);
}
}
for (int j=0; j < defs.count(); ++j)
{
if (find(defs[j].name()) < 0)
{
STYLE* newStyle = create(defs[j]);
if (defs.m_default == defs.styles[j])
makeDefault(newStyle);
}
}
invalidate();
}
template<class STYLE>
inline void StyleSet<STYLE>::rename(const QMap<QString,QString>& newNames)
{
for (int i=0; i < styles.count(); ++i)
{
QMap<QString,QString>::ConstIterator it;
it = newNames.find(styles[i]->name());
if (it != newNames.end())
styles[i]->setName(it.value());
it = newNames.find(styles[i]->parent());
if (it != newNames.end())
styles[i]->setParent(it.value());
}
invalidate();
}
#endif
|