Subversion Repositories Scribus

Compare Revisions

Ignore whitespace Rev 24752 → Rev 24753

/trunk/Scribus/scribus/prefscontext.cpp
28,44 → 28,53
#include "scclocale.h"
 
PrefsContext::PrefsContext()
: m_isPersistent(false),
m_isPlugin(false)
{
m_isPersistent = false;
m_isPlugin = false;
 
}
 
PrefsContext::PrefsContext(const QString& contextName, bool persistent, bool plugin)
: m_name(contextName),
m_isPersistent(persistent),
m_isPlugin(plugin)
{
m_name = contextName;
m_isPersistent = persistent;
m_isPlugin = plugin;
 
}
 
QString PrefsContext::getName()
PrefsContext::~PrefsContext()
{
TableMap::Iterator it;
for (it = tables.begin(); it != tables.end(); ++it)
delete it.value();
}
 
QString PrefsContext::getName() const
{
return m_name;
}
 
bool PrefsContext::isPersistent()
bool PrefsContext::isPersistent() const
{
return m_isPersistent;
}
 
bool PrefsContext::isPlugin()
bool PrefsContext::isPlugin() const
{
return m_isPlugin;
}
 
bool PrefsContext::isEmpty()
bool PrefsContext::isEmpty() const
{
return (values.empty() && tables.empty());
}
 
bool PrefsContext::contains(const QString& key)
bool PrefsContext::contains(const QString& key) const
{
return values.contains(key);
}
 
bool PrefsContext::containsTable(const QString& key)
bool PrefsContext::containsTable(const QString& key) const
{
return tables.contains(key);
}
174,10 → 183,3
{
tables.remove(name);
}
 
PrefsContext::~PrefsContext()
{
TableMap::Iterator it;
for (it = tables.begin(); it != tables.end(); ++it)
delete it.value();
}
/trunk/Scribus/scribus/prefscontext.h
34,8 → 34,8
#include "scribusapi.h"
#include "prefstable.h"
 
typedef QMap<QString, QString> AttributeMap;
typedef QMap<QString, PrefsTable*> TableMap;
using AttributeMap = QMap<QString, QString>;
using TableMap = QMap<QString, PrefsTable*>;
 
class SCRIBUS_API PrefsContext
{
47,23 → 47,23
AttributeMap values;
TableMap tables;
 
QString getName();
bool isPersistent();
bool isPlugin();
bool isEmpty();
bool contains(const QString& key);
bool containsTable(const QString& key);
QString getName() const;
bool isPersistent() const;
bool isPlugin() const;
bool isEmpty() const;
bool contains(const QString& key) const;
bool containsTable(const QString& key) const;
QString get(const QString& key, const QString& defValue = "");
int getInt(const QString& key, int defValue = -1);
uint getUInt(const QString& key, uint defValue = 0);
double getDouble(const QString& key, double defValue = -1.0);
bool getBool(const QString& key, bool defValue = false);
void set(const QString& key, const char* value);
void set(const QString& key, const std::string& value);
void set(const QString& key, const QString& value);
int getInt(const QString& key, int defValue = -1);
void set(const QString& key, int value);
void set(const QString& key, uint value);
uint getUInt(const QString& key, uint defValue = 0);
double getDouble(const QString& key, double defValue = -1.0);
void set(const QString& key, double value);
bool getBool(const QString& key, bool defValue = false);
void set(const QString& key, bool value);
PrefsTable* getTable(const QString& m_name);
void removeTable(const QString& m_name);
/trunk/Scribus/scribus/prefsfile.cpp
33,14 → 33,10
#include "prefsreader.h"
#include "prefstable.h"
 
PrefsFile::PrefsFile()
{
}
 
PrefsFile::PrefsFile(const QString& pFilePath, bool write)
: m_prefsFilePath(pFilePath),
m_ioEnabled(write)
{
m_prefsFilePath = pFilePath;
m_ioEnabled = write;
if (m_ioEnabled)
canWrite();
load();
86,72 → 82,71
{
if ((!m_ioEnabled) || ((m_contexts.empty()) && (m_pluginContexts.empty())))
return; // No prefs file path set -> can't write or no prefs to write
QFile* prefsXML = new QFile(m_prefsFilePath);
if (prefsXML->open(QIODevice::WriteOnly))
 
QFile prefsXML(m_prefsFilePath);
if (!prefsXML.open(QIODevice::WriteOnly))
return;
 
QTextStream stream(&prefsXML);
stream.setCodec("UTF-8");
stream << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
stream << "<preferences>\n";
if (!m_contexts.empty())
{
QTextStream stream(prefsXML);
stream.setCodec("UTF-8");
stream << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
stream << "<preferences>\n";
if (!m_contexts.empty())
{
stream << "\t<level name=\"application\">\n";
writeContexts(&m_contexts, stream);
stream << "\t</level>\n";
}
if (!m_userprefsContexts.empty())
{
stream << "\t<level name=\"plugin\">\n";
writeContexts(&m_userprefsContexts, stream);
stream << "\t</level>\n";
}
if (!m_pluginContexts.empty())
{
stream << "\t<level name=\"plugin\">\n";
writeContexts(&m_pluginContexts, stream);
stream << "\t</level>\n";
}
stream << "</preferences>\n";
stream << "\t<level name=\"application\">\n";
writeContexts(&m_contexts, stream);
stream << "\t</level>\n";
}
if (!m_userprefsContexts.empty())
{
stream << "\t<level name=\"plugin\">\n";
writeContexts(&m_userprefsContexts, stream);
stream << "\t</level>\n";
}
if (!m_pluginContexts.empty())
{
stream << "\t<level name=\"plugin\">\n";
writeContexts(&m_pluginContexts, stream);
stream << "\t</level>\n";
}
stream << "</preferences>\n";
 
prefsXML->close();
}
delete prefsXML;
prefsXML.close();
}
 
void PrefsFile::writeContexts(ContextMap* contextMap, QTextStream& stream)
void PrefsFile::writeContexts(const ContextMap* contextMap, QTextStream& stream)
{
ContextMap::Iterator it;
for (it = contextMap->begin(); it != contextMap->end(); ++it)
for (auto it = contextMap->begin(); it != contextMap->end(); ++it)
{
if ((it.value()->isPersistent()) && (!it.value()->isEmpty()))
const PrefsContext* prefsContext = it.value();
if (!prefsContext->isPersistent() || prefsContext->isEmpty())
continue;
 
stream << "\t\t<context name=\"" + replaceIllegalChars(it.key()) + "\">\n";
 
for (auto it2 = prefsContext->values.begin(); it2 != prefsContext->values.end(); ++it2)
{
stream << "\t\t<context name=\"" + replaceIllegalChars(it.key()) + "\">\n";
AttributeMap::Iterator it2;
PrefsContext* tmpCon = it.value();
for (it2 = tmpCon->values.begin(); it2 != tmpCon->values.end(); ++it2)
stream << "\t\t\t<attribute key=\"" + replaceIllegalChars(it2.key()) + "\" ";
stream << "value=\"" + replaceIllegalChars(it2.value()) + "\"/>\n";
}
 
for (auto it3 = prefsContext->tables.begin(); it3 != prefsContext->tables.end(); ++it3)
{
stream << "\t\t\t<table name=\"" + replaceIllegalChars(it3.key()) + "\">\n";
PrefsTable* t = it3.value();
for (int i = 0; i < t->height(); ++i)
{
stream << "\t\t\t<attribute key=\"" + replaceIllegalChars(it2.key()) + "\" ";
stream << "value=\"" + replaceIllegalChars(it2.value()) + "\"/>\n";
}
TableMap::Iterator it3;
for (it3 = tmpCon->tables.begin(); it3 != tmpCon->tables.end(); ++it3)
{
stream << "\t\t\t<table name=\"" + replaceIllegalChars(it3.key()) + "\">\n";
PrefsTable* t = it3.value();
for (int i = 0; i < t->height(); ++i)
stream << QString("\t\t\t\t<row index=\"%1\">\n").arg(i);
for (int j = 0; j < t->width(); ++j)
{
stream << QString("\t\t\t\t<row index=\"%1\">\n").arg(i);
for (int j = 0; j < t->width(); ++j)
{
stream << QString("\t\t\t\t\t<col index=\"%1\">").arg(j);
stream << replaceIllegalChars(t->get(i, j, "__NOT__SET__")) << "</col>\n";
}
stream << "\t\t\t\t</row>\n";
stream << QString("\t\t\t\t\t<col index=\"%1\">").arg(j);
stream << replaceIllegalChars(t->get(i, j, "__NOT__SET__")) << "</col>\n";
}
stream << "\t\t\t</table>\n";
stream << "\t\t\t\t</row>\n";
}
stream << "\t\t</context>\n";
stream << "\t\t\t</table>\n";
}
stream << "\t\t</context>\n";
}
}
 
/trunk/Scribus/scribus/prefsfile.h
37,27 → 37,28
 
class SCRIBUS_API PrefsFile
{
public:
PrefsFile() = default;
PrefsFile(const QString& pFilePath, bool write = true);
~PrefsFile();
 
bool hasContext(const QString& contextName) const;
PrefsContext* getContext(const QString& contextName, bool persistent = true);
PrefsContext* getPluginContext(const QString& contextName, bool persistent = true);
PrefsContext* getUserPrefsContext(const QString& contextName, bool persistent = true);
void write();
 
private:
QString m_prefsFilePath;
ContextMap m_contexts;
ContextMap m_pluginContexts;
ContextMap m_userprefsContexts;
bool m_ioEnabled {false};
bool m_ioEnabled { false };
 
void load();
QString replaceIllegalChars(const QString& text);
void writeContexts(ContextMap* contextMap, QTextStream& stream);
void writeContexts(const ContextMap* contextMap, QTextStream& stream);
void canWrite();
 
public:
PrefsFile();
PrefsFile(const QString& pFilePath, bool write = true);
~PrefsFile();
bool hasContext(const QString& contextName) const;
PrefsContext* getContext(const QString& contextName, bool persistent = true);
PrefsContext* getPluginContext(const QString& contextName, bool persistent = true);
PrefsContext* getUserPrefsContext(const QString& contextName, bool persistent = true);
void write();
};
 
#endif // PREFSFILE_H
/trunk/Scribus/scribus/prefsreader.cpp
27,15 → 27,10
#include "prefsreader.h"
 
PrefsReader::PrefsReader(ContextMap *appContexts, ContextMap *pluginContexts)
: m_aContexts(appContexts),
m_pContexts(pluginContexts)
{
m_aContexts = appContexts;
m_pContexts = pluginContexts;
m_currentContext = nullptr;
m_currentTable = nullptr;
m_inApp = false;
m_rowIndex = 0;
m_colIndex = 0;
m_inTable = false;
 
}
 
bool PrefsReader::startElement(const QString&, const QString&, const QString &name, const QXmlAttributes &attrs)
114,8 → 109,3
}
return true;
}
 
PrefsReader::~PrefsReader()
{
 
}
/trunk/Scribus/scribus/prefsreader.h
39,21 → 39,23
 
class SCRIBUS_API PrefsReader : public QXmlDefaultHandler
{
private:
ContextMap* m_aContexts;
ContextMap* m_pContexts;
PrefsContext* m_currentContext;
PrefsTable* m_currentTable;
bool m_inApp;
int m_rowIndex;
int m_colIndex;
bool m_inTable;
public:
PrefsReader(ContextMap *appContexts, ContextMap *pluginContexts);
~PrefsReader();
~PrefsReader() override = default;
 
bool startElement(const QString&, const QString&, const QString &name, const QXmlAttributes &attrs);
bool characters (const QString& ch);
bool endElement(const QString&, const QString&, const QString &name);
 
private:
ContextMap* m_aContexts { nullptr };
ContextMap* m_pContexts { nullptr };
PrefsContext* m_currentContext { nullptr };
PrefsTable* m_currentTable { nullptr };
bool m_inApp { false };
bool m_inTable { false };
int m_rowIndex { 0 };
int m_colIndex { 0 };
};
 
#endif
/trunk/Scribus/scribus/prefstable.cpp
27,33 → 27,32
#include "prefstable.h"
 
PrefsTable::PrefsTable(const QString& tableName)
: m_name(tableName)
{
m_name = tableName;
m_rowCount = 0;
m_colCount = 0;
 
}
 
QString PrefsTable::getName()
QString PrefsTable::getName() const
{
return m_name;
}
 
int PrefsTable::height()
int PrefsTable::height() const
{
return m_rowCount;
}
 
int PrefsTable::getRowCount()
int PrefsTable::getRowCount() const
{
return m_rowCount;
}
 
int PrefsTable::width()
int PrefsTable::width() const
{
return m_colCount;
}
 
int PrefsTable::getColCount()
int PrefsTable::getColCount() const
{
return m_colCount;
}
62,7 → 61,7
{
checkSize(row, col, defValue);
if (m_table[row][col] == "__NOT__SET__")
m_table[row].insert(m_table[row].begin()+col, defValue);
m_table[row].insert(m_table[row].begin() + col, defValue);
 
return (m_table[row][col]);
}
80,7 → 79,7
void PrefsTable::set(int row, int col, const QString& value)
{
checkSize(row, col, "__NOT__SET__");
m_table[row].insert(m_table[row].begin()+col, value);
m_table[row].insert(m_table[row].begin() + col, value);
}
 
int PrefsTable::getInt(int row, int col, int defValue)
152,7 → 151,7
for (int i = 0; i < height(); ++i)
{
if ((get(i, searchCol, "__NOT__SET__") == what) &&
(get(i, searchCol, "__NOT__SET__") != "__NOT__SET__"))
(get(i, searchCol, "__NOT__SET__") != "__NOT__SET__"))
{
rowi = i;
break;
218,7 → 217,3
m_colCount = 0;
m_table.clear();
}
 
PrefsTable::~PrefsTable()
{
}
/trunk/Scribus/scribus/prefstable.h
35,26 → 35,19
 
#include "scribusapi.h"
 
typedef std::vector<QStringList> Table;
using Table = std::vector<QStringList>;
 
class SCRIBUS_API PrefsTable
{
private:
QString m_name;
Table m_table;
int m_rowCount;
int m_colCount;
void checkSize(int rowIndex, int colIndex, const QString& defValue = "");
void checkHeight(int rowIndex);
void checkWidth(int rowIndex, int colIndex, const QString& defValue = "");
public:
PrefsTable(const QString& tableName);
~PrefsTable();
QString getName();
int height();
int getRowCount();
int width();
int getColCount();
explicit PrefsTable(const QString& tableName);
~PrefsTable() = default;
 
QString getName() const;
int height() const;
int getRowCount() const;
int width() const;
int getColCount() const;
QString get(int row, int col, const QString& defValue = "");
void set(int row, int col, const char* value);
void set(int row, int col, const std::string& value);
73,6 → 66,16
void removeRow(int colIndex, const QString& what);
/*** Empties the table ***/
void clear();
 
private:
QString m_name;
Table m_table;
int m_rowCount { 0 };
int m_colCount { 0 };
 
void checkSize(int rowIndex, int colIndex, const QString& defValue = "");
void checkHeight(int rowIndex);
void checkWidth(int rowIndex, int colIndex, const QString& defValue = "");
};
 
#endif