[KLF Backend][KLF Tools][KLF Home]
KLatexFormula Project
Defines | Functions | Variables
src/klftools/klfdatautil.cpp File Reference
#include <qglobal.h>
#include <QObject>
#include <QByteArray>
#include <QString>
#include <QUrl>
#include <QTextCodec>
#include <QDateTime>
#include <QRect>
#include <QIcon>
#include <QColor>
#include <QBrush>
#include <QDomDocument>
#include <QTextFormat>
#include "klfdefs.h"
#include "klfpobj.h"
#include "klfutil.h"
#include "klfdatautil.h"
#include "klfdatautil_p.h"
Include dependency graph for klfdatautil.cpp:

Go to the source code of this file.

Defines

#define KLF_BRUSH_STYLE(sty)   { Qt::sty##Pattern, #sty }
#define KLF_TEXT_FORMAT_FORMAT(fmt)   { QTextFormat::fmt##Format, #fmt "Format" }
#define KLF_TEXT_FORMAT_PROP(p, type)   { QTextFormat::p, #p, #type }
#define RX_INT   "-?\\d+"
#define RX_COORD_SEP   "\\s*(?:[,;]|\\s)\\s*"
#define RX_SIZE_SEP   "\\s*(?:[,;x]|\\s)\\s*"

Functions

KLF_EXPORT QByteArray klfDataToEscaped (const QByteArray &value_ba, char escapechar)
KLF_EXPORT QByteArray klfEscapedToData (const QByteArray &data, char escapechar)
KLF_EXPORT QByteArray klfSaveVariantToText (const QVariant &value, bool saveListAndMapsAsXML, QByteArray *savedType, QByteArray *savedListOrMapType)
KLF_EXPORT QVariant klfLoadVariantFromText (const QByteArray &stringdata, const char *dataTypeName, const char *listOrMapDataTypeName)
KLF_EXPORT QDomElement klfSaveVariantMapToXML (const QVariantMap &vmap, QDomElement baseNode)
 Lossless save of full map to XML with type information.
KLF_EXPORT QVariantMap klfLoadVariantMapFromXML (const QDomElement &xmlNode)
 Load a map saved with klfSaveVariantMapToXML()
KLF_EXPORT QDomElement klfSaveVariantListToXML (const QVariantList &vlist, QDomElement baseNode)
 Lossless save of full list to XML with type information.
KLF_EXPORT QVariantList klfLoadVariantListFromXML (const QDomElement &xmlNode)
 Load a list saved with klfSaveVariantListToXML()
KLF_EXPORT QByteArray klfSave (const KLFAbstractPropertizedObject *obj, const QString &format)
KLF_EXPORT bool klfLoad (const QByteArray &data, KLFAbstractPropertizedObject *obj, const QString &format)

Variables

KLFBaseFormatsPropertizedObjectSaver __klf_baseformats_pobj_saver

Define Documentation

#define KLF_BRUSH_STYLE (   sty)    { Qt::sty##Pattern, #sty }

Definition at line 53 of file klfdatautil.cpp.

#define KLF_TEXT_FORMAT_FORMAT (   fmt)    { QTextFormat::fmt##Format, #fmt "Format" }

Definition at line 78 of file klfdatautil.cpp.

#define KLF_TEXT_FORMAT_PROP (   p,
  type 
)    { QTextFormat::p, #p, #type }

Definition at line 93 of file klfdatautil.cpp.

#define RX_COORD_SEP   "\\s*(?:[,;]|\\s)\\s*"

Referenced by klfLoadVariantFromText().

#define RX_INT   "-?\\d+"

Referenced by klfLoadVariantFromText().

#define RX_SIZE_SEP   "\\s*(?:[,;x]|\\s)\\s*"

Referenced by klfLoadVariantFromText().


Function Documentation

KLF_EXPORT QByteArray klfDataToEscaped ( const QByteArray data,
char  escapechar = '\\' 
)

Escapes every character in data that is not in the range 32-126 (included) as \xHH whith HH the hex code of the character. Backslashes are replaced by double-backslashes.

If escapechar is specified, it replaces the backslash as escape character.

Definition at line 123 of file klfdatautil.cpp.

References QString::arg(), KLF_DEBUG_BLOCK, KLF_FUNC_NAME, klfDbg, klfFmtCC, QByteArray::size(), and QString::toLatin1().

Referenced by klfSaveVariantToText().

KLF_EXPORT QByteArray klfEscapedToData ( const QByteArray escaped,
char  escapechar = '\\' 
)

Performs the exact inverse of klfDataToEscaped().

Also understands standard short C escape sequences such as ' ', '\0', and ' '

If escapechar is specified, it replaces the backslash as escape character.

Definition at line 148 of file klfdatautil.cpp.

References KLF_DEBUG_BLOCK, KLF_FUNC_NAME, klfDbg, klfFmtCC, QByteArray::mid(), QByteArray::size(), and QByteArray::toUInt().

Referenced by klfLoadVariantFromText().

KLF_EXPORT bool klfLoad ( const QByteArray data,
KLFAbstractPropertizedObject obj,
const QString format = QString() 
)
KLF_EXPORT QVariant klfLoadVariantFromText ( const QByteArray string,
const char *  dataTypeName,
const char *  listOrMapTypeName = NULL 
)

Loads the value stored in string into a variant of data type dataTypeName. The string is parsed and the returned variant will by of the given type name, or invalid if the string could not be parsed.

Note:
The data type must be known when loading the value. It can in general not be guessed by looking at string.

Example use: to save/store settings values in QSettings in a human-read/writable format.

If dataTypeName is a variant list or map, then please specify the type of the values in the list or map (this function assumes all objects in list or map have the same type). As a special case, you can pass "XML" to load the list or map data with klfLoadVariantListFromXML() or klfLoadVariantMapFromXML(), which enables you to save arbitrary combination of types.

See also klfSaveVariantToText().

If dataTypeName contains a '/' (ie is of the form "KLFEnumType/a:b:c", then the string after the slash is treated as a specification for the given KLFSpecifyableType.

Definition at line 771 of file klfdatautil.cpp.

References QList::begin(), QRegExp::capturedTexts(), QString::compare(), QByteArray::constData(), QList::end(), fixed_value, format, QString::fromLatin1(), QString::fromLocal8Bit(), QDateTime::fromString(), QDate::fromString(), QTime::fromString(), QString::fromUtf8(), KLFAbstractPropertizedObject::hasFixedTypes(), QRegExp::indexIn(), QByteArray::indexOf(), QString::isEmpty(), QList::isEmpty(), QByteArray::isEmpty(), KLFPObjRegisteredType::isRegistered(), QChar::isSpace(), QTime::isValid(), QDateTime::isValid(), QDate::isValid(), key, keyword, KLF_DEBUG_TIME_BLOCK, KLF_FUNC_NAME, klfDbg, klfEscapedToData(), klfLoadVariantFromText(), klfLoadVariantListFromXML(), klfLoadVariantMapFromXML(), QByteArray::left(), QByteArray::mid(), KLFAbstractPropertizedObject::objectKind(), QRegExp::pattern(), propId, QByteArray::remove(), RX_COORD_SEP, RX_INT, RX_SIZE_SEP, KLFAbstractPropertizedObject::setAllProperties(), QColor::setAlpha(), QRegExp::setMinimal(), QColor::setNamedColor(), QTextFormat::setProperty(), KLFSpecifyableType::setSpecification(), KLFEnumType::setSpecification(), QFont::setStyle(), KLFEnumType::setValue(), QList::size(), QByteArray::size(), QByteArray::startsWith(), QString::startsWith(), style, QList::takeFirst(), QByteArray::toDouble(), QByteArray::toInt(), QString::toInt(), QByteArray::toLong(), QByteArray::toLongLong(), QByteArray::toLower(), QVariant::toMap(), QByteArray::toShort(), QVariant::toString(), QByteArray::toUInt(), QByteArray::toULong(), QByteArray::toULongLong(), QByteArray::toUShort(), QByteArray::trimmed(), QMetaType::type(), type, KLFAbstractPropertizedObject::typeNameFor(), and KLFAbstractPropertizedObject::typeSpecificationFor().

Referenced by klfLoadVariantFromText(), klfLoadVariantListFromXML(), and klfLoadVariantMapFromXML().

KLF_EXPORT QVariantList klfLoadVariantListFromXML ( const QDomElement xmlNode)
KLF_EXPORT QVariantMap klfLoadVariantMapFromXML ( const QDomElement xmlNode)
KLF_EXPORT QByteArray klfSave ( const KLFAbstractPropertizedObject obj,
const QString format 
)
KLF_EXPORT QDomElement klfSaveVariantListToXML ( const QVariantList &  vlist,
QDomElement  baseNode 
)
KLF_EXPORT QDomElement klfSaveVariantMapToXML ( const QVariantMap &  vmap,
QDomElement  baseNode 
)
KLF_EXPORT QByteArray klfSaveVariantToText ( const QVariant value,
bool  saveListAndMapsAsXML = false,
QByteArray savedType = NULL,
QByteArray savedListOrMapType = NULL 
)

Saves the variant value into a string, stored in Local 8-bit encoding text in QByteArray. The saved string is both human and machine readable, ie. the exact string can be recast again to a variant with klfLoadVariantFromText().

This function is aware of various QVariant formats, however maybe not all of them. The unknown formats are stored machine-readable only, by sending the variant in a datastream, and protecting the special characters from encoding artifacts (ascii chars only, proper escape sequences).

If saveListAndMapsAsXML is FALSE (the default), then variant-lists and -maps are saved in a format like "[element-1,element-2,...]" or "{key1=value1,key2=value2,....}", assuming that all elements are of the same QVariant type. If saveListAndMapsAsXML is TRUE, then variant lists and maps are saved with klfSaveVariantListToXML() and klfSaveVariantMapToXML(), which enables you to save arbitrary combination of types.

Note:
Note however that the saved string does NOT save the type. The data type must be known when loading the value. See klfLoadVariantFromText().

If savedType is not NULL, then the exact type of the variant that was saved is reported, including a type specifier if the type is a registered KLFSpecifyableType subclass.

If savedListOrMapType is not NULL, then if the saved type is a QVariantList or QVariantMap, the exact type of the variants in the list or map is reported. We assume that all those types are the same and a warning is printed if this is not the case. If the saved type is not a QVariantList or a QVariantMap, then saveListOrMapType is left undefined.

Definition at line 393 of file klfdatautil.cpp.

References KLFAbstractPropertizedObject::allProperties(), QColor::alpha(), QList::append(), QString::arg(), QMap::begin(), QColor::blue(), brushStyle, QTextCodec::canEncode(), QTextCodec::codecForLocale(), QBrush::color(), QByteArray::constData(), QMap::end(), QFont::family(), fixed_value, format, formatId, QTextCodec::fromUnicode(), QColor::green(), KLFAbstractPropertizedObject::hasFixedTypes(), QRect::height(), QSize::height(), QMatrix::isIdentity(), QByteArray::isNull(), QVariant::isNull(), KLFPObjRegisteredType::isRegistered(), KLFSpecifyableRegisteredType::isRegistered(), QVariant::isValid(), key, KLF_FUNC_NAME, klfDataToEscaped(), klfDbg, klfSaveVariantListToXML(), klfSaveVariantMapToXML(), klfSaveVariantToText(), klfWarning, QRect::left(), QString::length(), QBrush::matrix(), QString::mid(), QByteArray::number(), QString::number(), QDomNode::ownerDocument(), QTextFormat::properties(), propId, QColor::red(), QString::replace(), QDataStream::setVersion(), QList::size(), QByteArray::size(), KLFSpecifyableType::specification(), QByteArray::startsWith(), QFont::style(), QBrush::style(), style, QVariant::toBool(), QDomDocument::toByteArray(), QVariant::toChar(), QUrl::toEncoded(), QString::toLatin1(), QVariant::toList(), QString::toLocal8Bit(), QVariant::toMap(), QRect::top(), QVariant::toPoint(), QVariant::toRect(), QVariant::toSize(), QVariant::toString(), QVariant::toStringList(), QString::toUpper(), QVariant::toUrl(), QTextFormat::type(), QVariant::type(), type, QVariant::typeName(), QChar::unicode(), QVariant::value(), KLFEnumType::value(), QFont::weight(), QRect::width(), QSize::width(), QPoint::x(), and QPoint::y().

Referenced by klfSaveVariantListToXML(), klfSaveVariantMapToXML(), and klfSaveVariantToText().


Variable Documentation

KLFBaseFormatsPropertizedObjectSaver __klf_baseformats_pobj_saver

Definition at line 1635 of file klfdatautil.cpp.

Definition at line 56 of file klfdatautil.cpp.

Referenced by klfSaveVariantToText().

Definition at line 111 of file klfdatautil.cpp.

Referenced by klfLoadVariantFromText(), and klfSaveVariantToText().

const char* format

Definition at line 81 of file klfdatautil.cpp.

Referenced by klfLoad(), klfLoadVariantFromText(), and klfSaveVariantToText().

int formatId

Definition at line 81 of file klfdatautil.cpp.

Referenced by klfSaveVariantToText().

const char* key
const char* keyword

Definition at line 111 of file klfdatautil.cpp.

Referenced by klfLoadVariantFromText().

int propId
const char* style
const char* type

Generated by doxygen 1.7.6.1. The KLatexFormula website is hosted on sourceforge.net