35 #include <QDomDocument> 36 #include <QTextFormat> 43 #include "klfdatautil_p.h" 46 static inline bool klf_is_hex_char(
char c)
48 return (
'0' <= c && c <=
'9') || (
'a' <= c && c <=
'f') || (
'A' <= c && c <=
'F');
53 #define KLF_BRUSH_STYLE(sty) \ 54 { Qt::sty##Pattern, #sty } 57 { Qt::NoBrush,
"NoBrush" },
58 { Qt::SolidPattern,
"" },
59 { Qt::SolidPattern,
"Solid" },
78 #define KLF_TEXT_FORMAT_FORMAT(fmt) \ 79 { QTextFormat::fmt##Format, #fmt "Format" } 81 static struct {
int formatId;
const char *
format; } klf_text_format_formats[] = {
93 #define KLF_TEXT_FORMAT_PROP(p, type) \ 94 { QTextFormat::p, #p, #type } 96 static struct {
int propId;
const char *
key;
const char *
type; } klf_text_format_props[] = {
105 { QTextFormat::ForegroundBrush,
"FG",
"QBrush" },
106 { QTextFormat::BackgroundBrush,
"BG",
"QBrush" },
112 {
"NORMALWEIGHT", QTextFormat::FontWeight,
QVariant(QFont::Normal) },
113 {
"BOLD", QTextFormat::FontWeight,
QVariant(QFont::Bold) },
114 {
"NORMALSTYLE", QTextFormat::FontItalic,
QVariant(
false) },
115 {
"ITALIC", QTextFormat::FontItalic,
QVariant(
true) },
127 klfDbg(
"len="<<value_ba.
size()<<
" , data=`"<<value_ba<<
"' escapechar="<<
klfFmtCC(
"'\\x%02X'", (
int)escapechar));
131 for (k = 0; k < value_ba.
size(); ++k) {
133 if (value_ba[k] >= 32 && value_ba[k] <= 126 && value_ba[k] != escapechar) {
136 }
else if (value_ba[k] == escapechar) {
151 klfDbg(
"data=`"<<data<<
"', escapechar="<<
klfFmtCC(
"'\\x%02X'", (
int)escapechar));
157 while (k < data.
size()) {
158 if (data[k] != escapechar) {
164 if (data[k] == escapechar && k+1 >= data.
size()) {
165 value_ba += escapechar;
170 if (data[k+1] !=
'x') {
173 if (data[k+1] ==
'n')
175 if (data[k+1] ==
'0')
177 if (data[k+1] ==
't')
179 if (data[k+1] ==
'a')
181 if (data[k+1] ==
'b')
183 if (data[k+1] ==
'f')
185 if (data[k+1] ==
'r')
187 if (data[k+1] ==
'v')
190 value_ba += data[k+1];
195 if (k+3 >= data.
size() || !klf_is_hex_char(data[k+2]) || !klf_is_hex_char(data[k+3])) {
197 klfDbg(
"ignoring invalid escape sequence `"<<data.
mid(k,4)<<
"'") ;
203 uchar cval = data.
mid(k+2, 2).
toUInt(&convertOk, 16);
204 value_ba += (char)cval;
214 for (
int k = 0; k < list.
size(); ++k) {
221 if (k < list.
size()-1)
233 bool first_item =
true;
235 for (k = 0; k < sections.size(); ++k) {
248 if (val.
isEmpty() && ignore_empty_values)
251 data += key +
"=" + val;
260 klfDbg(
"decaps_list, data="<<ba_data);
270 while (k < data.
size()) {
271 if (data[k] ==
';') {
278 if (data[k] ==
'\\') {
279 if (k+1 < data.
size()) {
288 if (data[k] ==
']') {
305 klfDbg(
"sections="<<sections);
325 while (k < data.
size()) {
326 if (data[k] ==
';') {
328 if (!allow_empty_values && curChunk == &chunkkey)
329 qWarning()<<
KLF_FUNC_NAME<<
": no '=' in pair at pos "<<k<<
" in string: "<<data<<
"";
330 sections << QPair<QByteArray,QByteArray>(chunkkey, chunkvalue);
334 curChunk = &chunkkey;
337 if (data[k] ==
'\\') {
338 if (k+1 < data.
size()) {
339 *curChunk += data[k+1];
342 *curChunk += data[k];
347 if (curChunk == &chunkkey && data[k] ==
'=') {
349 curChunk = &chunkvalue;
353 if (data[k] ==
'}') {
356 if (!allow_empty_values && curChunk == &chunkkey)
357 qWarning()<<
"klfLoadVariantFromText: no '=' in pair at pos "<<k<<
" in string: "<<data<<
"";
358 sections << QPair<QByteArray,QByteArray>(chunkkey, chunkvalue);
362 *curChunk += data[k];
388 "Wrong XML root node in wrapper for klfLoadVariantFromText(): " 403 klfDbg(
"saving null variant.");
404 if (savedType != NULL)
410 switch ((
int)value.
type()) {
411 case QMetaType::Bool:
412 data = value.
toBool() ?
"true" :
"false";
415 case QMetaType::UInt:
416 case QMetaType::Short:
417 case QMetaType::UShort:
418 case QMetaType::Long:
419 case QMetaType::ULong:
420 case QMetaType::LongLong:
421 case QMetaType::ULongLong:
422 case QMetaType::Double:
425 case QMetaType::Char:
427 char c = value.
value<
char>();
428 if (c >= 32 && c <= 126 && c !=
'\\') {
430 }
else if (c ==
'\\') {
437 case QMetaType::QChar:
442 }
else if (c ==
'\\') {
449 case QMetaType::QString:
458 for (k = 0; k < s.
length(); ++k) {
468 case QMetaType::QStringList:
473 for (k = 0; k < list.
size(); ++k) {
476 data = encaps_list(sections);
479 case QMetaType::QUrl:
481 case QMetaType::QByteArray:
486 case QMetaType::QDate:
487 data = value.
value<
QDate>().toString(Qt::SystemLocaleShortDate).toLocal8Bit();
break;
488 case QMetaType::QTime:
489 data = value.
value<
QTime>().toString(Qt::SystemLocaleShortDate).toLocal8Bit();
break;
490 case QMetaType::QDateTime:
491 data = value.
value<
QDateTime>().toString(Qt::SystemLocaleShortDate).toLocal8Bit();
break;
492 case QMetaType::QSize:
497 case QMetaType::QPoint:
499 data =
QString(
"(%1 %2)").
arg(pt.
x()).arg(pt.
y()).toLatin1();
502 case QMetaType::QRect:
507 case QMetaType::QColor:
509 klfDbg(
"Saving color "<<c<<
": alpha="<<c.
alpha()) ;
510 if (c.
alpha() == 255)
516 case QMetaType::QFont:
520 case QFont::Light: data +=
" Light";
break;
521 case QFont::Normal:
break;
522 case QFont::DemiBold: data +=
" DemiBold";
break;
523 case QFont::Bold: data +=
" Bold";
break;
524 case QFont::Black: data +=
" Black";
break;
528 case QFont::StyleNormal:
break;
529 case QFont::StyleItalic: data +=
" Italic";
break;
530 case QFont::StyleOblique: data +=
" Oblique";
break;
537 case QMetaType::QBrush:
541 int bstyle = b.
style();
544 bool found_style =
false;
545 for (k = 0; klf_brush_styles[k].brushStyle >= 0 && klf_brush_styles[k].style != NULL; ++k) {
546 if (klf_brush_styles[k].
brushStyle == bstyle) {
557 data += klf_brush_styles[k].style;
558 if (strlen(klf_brush_styles[k].
style))
565 case QMetaType::QTextFormat:
574 for (k = 0; klf_text_format_formats[k].format != NULL; ++k)
577 if (klf_text_format_formats[k].
format == NULL) {
584 sections << QPair<QByteArray,QByteArray>(klf_text_format_formats[k].format,
QByteArray());
587 for (it = props.begin(); it != props.end(); ++it) {
593 for (k = 0; klf_text_format_keywords[k].keyword != NULL; ++k)
594 if (klf_text_format_keywords[k].propId == propId &&
595 klf_text_format_keywords[k].
fixed_value == propValue)
597 const char *kw = klf_text_format_keywords[k].keyword;
601 sections << QPair<QByteArray,QByteArray>(kw,
QByteArray());
606 for (k = 0; klf_text_format_props[k].key != NULL; ++k)
607 if (klf_text_format_props[k].propId == propId)
609 if (klf_text_format_props[k].
key != NULL) {
611 if ( !strcmp(klf_text_format_props[k].
type, propValue.
typeName()) ) {
615 sections << QPair<QByteArray,QByteArray>(
key, value);
618 qWarning()<<
KLF_FUNC_NAME<<
": QTextFormat property "<<klf_text_format_props[k].key
619 <<
" 's type is `"<<propValue.
typeName()<<
"' which is not the known type: " 620 <<klf_text_format_props[k].type;
629 data = encaps_map(sections,
true);
632 case QMetaType::QVariantList:
636 if (saveListAndMapsAsXML) {
643 for (k = 0; k < list.
size(); ++k) {
645 innertype = list[k].typeName();
646 if (innertype != list[k].typeName()) {
647 klfWarning(
"saving list: not all inner QVariants have same type. Found a "<<innertype
648 <<
" along with a "<<list[k].typeName());
652 if (savedListOrMapType != NULL)
653 *savedListOrMapType = innertype;
654 data = encaps_list(sections);
658 case QMetaType::QVariantMap:
662 if (saveListAndMapsAsXML) {
667 klfDbg(
"saved XML: data="<<data) ;
671 bool firstround =
true;
675 thistype = it.value().typeName();
677 innertype = thistype;
680 if (innertype != thistype) {
681 klfWarning(
"saving map: not all inner QVariants have same type. Found a "<<innertype
682 <<
" along with a "<<thistype);
684 sections << QPair<QByteArray,QByteArray>(k, v);
686 if (savedListOrMapType != NULL)
687 *savedListOrMapType = innertype;
688 data = encaps_map(sections);
706 if (savedType != NULL) {
707 *savedType = typeName +
"/" + typeSpec;
710 if (savedType != NULL)
711 *savedType = typeName;
714 if (typeName ==
"KLFEnumType") {
727 if (!hasfixedtypes) {
731 QVariantMap propstexts;
732 for (QVariantMap::const_iterator it = props.begin(); it != props.end(); ++it) {
734 klfDbg(
"Saving property "<<it.key()<<
" to text, value = "<<propstexts[it.key()]) ;
759 qDebug(
"\tVariant value is %s, len=%d", vdata.
constData(), vdata.
size());
764 klfDbg(
"klfSaveVariantToText("<<value<<
"): saved data (len="<<data.
size()<<
") : "<<data ) ;
772 const char *listOrMapDataTypeName)
778 #define RX_INT "-?\\d+" 779 #define RX_COORD_SEP "\\s*(?:[,;]|\\s)\\s*" // note: non-capturing parenthesis 780 #define RX_SIZE_SEP "\\s*(?:[,;x]|\\s)\\s*" // note: non-capturing parenthesis 784 static const int V2RX_X = 1, V2RX_Y = 2;
788 static const int SZRX_W = 1, SZRX_H = 2;
795 "(" RX_INT
")(?:" RX_COORD_SEP "|\\s*([x])\\s*)(" RX_INT
")\\s*\\)?");
796 static const int RECTRX_X1 = 1, RECTRX_Y1 = 2, RECTRX_MIDDLESEP_PLUS = 3,
797 RECTRX_X2orW = 4, RECTRX_LASTSEP_X = 5, RECTRX_Y2orH = 6;
802 "(" RX_COORD_SEP "(\\d+))?\\s*\\)?", Qt::CaseInsensitive);
803 static const int COLRX_R = 1, COLRX_G = 2, COLRX_B = 3, COLRX_MAYBE_ALPHA = 4, COLRX_A = 5;
806 QRegExp brushrx(
"^(?:q?brush)?\\(?\\s*(?:([A-Za-z_]\\w*)" RX_COORD_SEP
")?(\\d+)" RX_COORD_SEP
"(\\d+)" 808 RX_COORD_SEP
"(\\d+)" "(" RX_COORD_SEP
"(\\d+))?" "\\s*\\)?", Qt::CaseInsensitive);
809 static const int BRUSHRX_STYLE = 1, BRUSHRX_R = 2, BRUSHRX_G = 3, BRUSHRX_B = 4, BRUSHRX_A = 6;
812 QRegExp fontrx(
"^([\"']?)\\s*(.+)\\s*\\1" 814 "(\\s+(Light|Normal|DemiBold|Bold|Black|Wgt\\s*=\\s*(\\d+)))?" 816 "(\\s+(Normal|Italic|Oblique))?(\\s+(\\d+))?$");
818 static const int FONTRX_FAMILY = 2, FONTRX_WEIGHT_TEXT = 4, FONTRX_WEIGHT_VALUE = 5,
819 FONTRX_STYLE_TEXT = 7, FONTRX_POINTSIZE = 9;
827 if (dataTypeName == NULL || *dataTypeName == 0) {
828 klfDbg(
"loading null variant.");
836 klfDbg(
"\tAbout to read raw variant from datastr="<<vdata_esc<<
", ie. from data len="<<vdata.
size() ) ;
838 stream.setVersion(QDataStream::Qt_4_4);
845 klfDbg(
"Will start loading a `"<<dataTypeName<<
"' from data (len="<<data.
size()<<
") : "<<data ) ;
852 if ((idslash = tname.indexOf(
'/')) >= 0) {
853 tspecification = tname.
mid(idslash+1);
854 tname = tname.
left(idslash);
855 klfDbg(
"tspecification="<<tspecification<<
", tname="<<tname) ;
860 klfDbg(
"Type is "<<type) ;
861 bool convertOk =
false;
864 case QMetaType::Bool:
870 return QVariant::fromValue<bool>(c ==
't' || c ==
'y' || c ==
'1' || lowerdata ==
"on");
875 int i = data.
toInt(&convertOk);
877 return QVariant::fromValue<int>(i);
880 case QMetaType::UInt:
883 uint i = data.
toUInt(&convertOk);
885 return QVariant::fromValue<uint>(i);
888 case QMetaType::Short:
891 short i = data.
toShort(&convertOk);
893 return QVariant::fromValue<short>(i);
896 case QMetaType::UShort:
899 ushort i = data.
toUShort(&convertOk);
901 return QVariant::fromValue<ushort>(i);
904 case QMetaType::Long:
907 long i = data.
toLong(&convertOk);
909 return QVariant::fromValue<long>(i);
912 case QMetaType::ULong:
915 ulong i = data.
toULong(&convertOk);
917 return QVariant::fromValue<ulong>(i);
920 case QMetaType::LongLong:
925 return QVariant::fromValue<qlonglong>(i);
928 case QMetaType::ULongLong:
933 return QVariant::fromValue<qulonglong>(i);
936 case QMetaType::Double:
939 double val = data.
toDouble(&convertOk);
941 return QVariant::fromValue<double>(val);
944 case QMetaType::Char:
947 if (data[0] ==
'\\') {
951 return QVariant::fromValue<char>(
'\\');
954 uint c = data.
mid(1).
toUInt(&convertOk, 16);
960 return QVariant::fromValue<char>( (char)c );
962 return QVariant::fromValue<char>( (char)data[0] );
964 case QMetaType::QChar:
967 if (data[0] ==
'\\') {
971 return QVariant::fromValue<QChar>(
QChar(
'\\'));
974 uint c = data.
mid(1).
toUInt(&convertOk, 16);
980 return QVariant::fromValue<QChar>(
QChar(c) );
982 return QVariant::fromValue<QChar>(
QChar(data[0]) );
984 case QMetaType::QString:
990 while (k < data.
size()) {
991 if (data[k] !=
'\\') {
996 if (data[k] ==
'\\' && k+1 >= data.
size()) {
1002 if (data[k+1] !=
'x') {
1010 if (k+5 < data.
size() && klf_is_hex_char(data[k+2]) && klf_is_hex_char(data[k+3])
1011 && klf_is_hex_char(data[k+4]) && klf_is_hex_char(data[k+5])) {
1014 if (k+3 < data.
size() && klf_is_hex_char(data[k+2]) && klf_is_hex_char(data[k+3])) {
1024 ushort cval = data.
mid(k+2, nlen).
toUShort(&convertOk, 16);
1036 return QVariant::fromValue<QString>(s);
1038 case QMetaType::QStringList:
1045 for (k = 0; k < sections.
size(); ++k) {
1049 return QVariant::fromValue<QStringList>(list);
1051 case QMetaType::QUrl:
1056 case QMetaType::QByteArray:
1060 return QVariant::fromValue<QByteArray>(value_ba);
1062 case QMetaType::QDate:
1080 return QVariant::fromValue<QDate>(date);
1082 case QMetaType::QTime:
1101 return QVariant::fromValue<QTime>(time);
1103 case QMetaType::QDateTime:
1125 return QVariant::fromValue<QDateTime>(dt);
1127 case QMetaType::QSize:
1134 return QVariant::fromValue<QSize>(
QSize(vals[SZRX_W].toInt(), vals[SZRX_H].toInt()));
1136 case QMetaType::QPoint:
1143 return QVariant::fromValue<QPoint>(
QPoint(vals[V2RX_X].toInt(), vals[V2RX_Y].toInt()));
1145 case QMetaType::QRect:
1152 if (vals[RECTRX_MIDDLESEP_PLUS] ==
"+" || vals[RECTRX_LASTSEP_X] ==
"x") {
1153 return QVariant::fromValue<QRect>(
QRect(
QPoint(vals[RECTRX_X1].toInt(), vals[RECTRX_Y1].toInt()),
1154 QSize(vals[RECTRX_X2orW].toInt(), vals[RECTRX_Y2orH].toInt()) ));
1156 return QVariant::fromValue<QRect>(
QRect(
QPoint(vals[RECTRX_X1].toInt(), vals[RECTRX_Y1].toInt()),
1157 QPoint(vals[RECTRX_X2orW].toInt(), vals[RECTRX_Y2orH].toInt()) ));
1159 case QMetaType::QColor:
1164 if (colrx.
indexIn(colstr) < 0) {
1165 klfDbg(
"color "<<colstr<<
" does not match regexp="<<colrx.
pattern()<<
", trying named...") ;
1169 if (color.isValid())
1175 QColor color =
QColor(vals[COLRX_R].toInt(), vals[COLRX_G].toInt(), vals[COLRX_B].toInt(), 255);
1176 if (!vals[COLRX_MAYBE_ALPHA].isEmpty())
1177 color.
setAlpha(vals[COLRX_A].toInt());
1178 return QVariant::fromValue<QColor>(color);
1180 case QMetaType::QFont:
1184 klfDbg(
"malformed font: "<<data);
1188 klfDbg(
"parsing font: data="<<data<<
"; captured texts are: "<<vals );
1190 QString family = vals[FONTRX_FAMILY].trimmed();
1191 QString weighttxt = vals[FONTRX_WEIGHT_TEXT];
1192 QString weightval = vals[FONTRX_WEIGHT_VALUE];
1193 QString styletxt = vals[FONTRX_STYLE_TEXT];
1194 QString ptsval = vals[FONTRX_POINTSIZE];
1196 int weight = QFont::Normal;
1197 if (weighttxt ==
"Light") weight = QFont::Light;
1198 else if (weighttxt ==
"Normal") weight = QFont::Normal;
1199 else if (weighttxt ==
"DemiBold") weight = QFont::DemiBold;
1200 else if (weighttxt ==
"Bold") weight = QFont::Bold;
1201 else if (weighttxt ==
"Black") weight = QFont::Black;
1205 QFont::Style
style = QFont::StyleNormal;
1206 if (styletxt ==
"Normal") style = QFont::StyleNormal;
1207 else if (styletxt ==
"Italic") style = QFont::StyleItalic;
1208 else if (styletxt ==
"Oblique") style = QFont::StyleOblique;
1212 pt = ptsval.
toInt();
1214 QFont font(family, pt, weight);
1216 return QVariant::fromValue<QFont>(font);
1218 case QMetaType::QBrush:
1222 klfDbg(
"malformed brush text: "<<data) ;
1229 bool style_found =
false;
1230 for (k = 0; klf_brush_styles[k].brushStyle >= 0 && klf_brush_styles[k].style != NULL; ++k) {
1231 if (klf_brush_styles[k].style == style) {
1237 klfDbg(
"Can't find style"<<style<<
" in brush style list!");
1240 int qbrush_style = klf_brush_styles[k].brushStyle;
1242 QColor c =
QColor(vals[BRUSHRX_R].toInt(), vals[BRUSHRX_G].toInt(),
1243 vals[BRUSHRX_B].toInt());
1244 if (!vals[BRUSHRX_A].isEmpty())
1245 c.
setAlpha(vals[BRUSHRX_A].toInt());
1246 return QBrush(c, static_cast<Qt::BrushStyle>(qbrush_style));
1248 case QMetaType::QTextFormat:
1254 klfDbg(
"Invalid QTextFormat data.") ;
1260 for (k = 0; klf_text_format_formats[k].format != NULL; ++k)
1262 Qt::CaseInsensitive) == 0)
1264 if (klf_text_format_formats[k].format == NULL) {
1265 klfDbg(
"QTextFormat: Invalid format type: "<<fmttype) ;
1268 int qtextformat_type = klf_text_format_formats[k].formatId;
1273 for (it = sections.
begin(); it != sections.
end(); ++it) {
1276 klfDbg(
"QTextFormat: considering property pair key="<<key<<
"; value="<<value) ;
1278 for (k = 0; klf_text_format_keywords[k].keyword != NULL; ++k)
1280 key, Qt::CaseInsensitive) == 0)
1282 if (klf_text_format_keywords[k].keyword != NULL) {
1284 klfDbg(
"QTextFormat: is keyword, propId="<<klf_text_format_keywords[k].
propId<<
", fixed_value=" 1287 klf_text_format_keywords[k].fixed_value);
1291 for (k = 0; klf_text_format_props[k].key != NULL; ++k)
1293 key, Qt::CaseInsensitive) == 0)
1295 if (klf_text_format_props[k].key != NULL) {
1296 klfDbg(
"QTextFormat: is known property of type "<<klf_text_format_props[k].type) ;
1304 bool tointok =
true;
1305 int propid = key.toInt(&tointok);
1307 qWarning()<<
KLF_FUNC_NAME<<
": QTextFormat bad format for general property key=value pair; " 1308 <<
"key is not a numerical property ID, nor is it a known property name.";
1311 klfDbg(
"QTextFormat: property is not a known one. propid="<<propid) ;
1318 qWarning().nospace()<<
KLF_FUNC_NAME<<
": QTextFormat bad format for general property, value does " 1319 <<
"not begin with \"[type-name]\".";
1325 klfDbg(
"setting generalized property "<<propid<<
" to value "<<vval) ;
1330 case QMetaType::QVariantList:
1332 klfDbg(
"qvariantlist!") ;
1334 QDomElement el = parse_xml_wrapper(data,
"variant-list");
1341 for (k = 0; k < sections.
size(); ++k) {
1346 return QVariant::fromValue<QVariantList>(list);
1349 case QMetaType::QVariantMap:
1353 QDomElement el = parse_xml_wrapper(data,
"variant-map");
1359 for (it = sections.
begin(); it != sections.
end(); ++it) {
1364 return QVariant::fromValue<QVariantMap>(vmap);
1371 if (tname ==
"KLFEnumType") {
1376 return QVariant::fromValue<KLFEnumType>(e);
1379 klfDbg(
"other type or failed to load the good type!") ;
1388 if (tspecification.
size()) {
1396 klfDbg(
"loading an abstr.prop.obj: "<<obj) ;
1397 klfDbg(
"obj is of type "<<obj->
objectKind()<<
", fixedtypes="<<hasfixedtypes) ;
1400 if (!hasfixedtypes) {
1405 QVariantMap propsconverted;
1406 for (QVariantMap::const_iterator it = props.begin(); it != props.end(); ++it) {
1414 klfDbg(
"Loading property "<<it.key()<<
" from saved text, value = "<<propsconverted[it.key()]) ;
1416 props = propsconverted;
1421 qWarning(
"klfLoadVariantFromText: Can't load a %s from %s !", dataTypeName, stringdata.
constData());
1441 for (QVariantMap::const_iterator it = vmap.begin(); it != vmap.end(); ++it) {
1454 if (vtype ==
"QVariantMap") {
1457 }
else if (vtype ==
"QVariantList") {
1497 if ( ee.isNull() || nn.
nodeType() != QDomNode::ElementNode )
1499 if ( ee.nodeName() ==
"key" ) {
1503 if ( ee.nodeName() ==
"value" ) {
1506 valuedata = ee.text().toLocal8Bit();
1507 valuetype = ee.attribute(
"type").toUtf8();
1510 klfWarning(
"Ignoring unexpected tag "<<ee.nodeName()<<
" in <pair>!") ;
1513 if (valuetype ==
"QVariantMap") {
1515 }
else if (valuetype ==
"QVariantList") {
1531 for (QVariantList::const_iterator it = vlist.begin(); it != vlist.end(); ++it) {
1537 if (vtype ==
"QVariantMap") {
1540 }
else if (vtype ==
"QVariantList") {
1644 return saver->
save(obj, format);
1658 KLF_ASSERT_NOT_NULL(saver,
"Can't find object saver for format="<<f<<
" !",
return false; ) ;
1659 return saver->
load(data, obj, f);
virtual QString objectKind() const =0
A string representing this object type.
QByteArray fromUnicode(const QString &str) const
static bool isRegistered(const char *name)
static KLFAbstractPropertizedObjectSaver * findRecognizedFormat(const QByteArray &data, QString *format=NULL)
uint toUInt(bool *ok, int base) const
KLF_EXPORT QByteArray klfSaveVariantToText(const QVariant &value, bool saveListAndMapsAsXML, QByteArray *savedType, QByteArray *savedListOrMapType)
static bool isRegistered(const char *name)
void setProperty(int propertyId, const QVariant &value)
int toInt(bool *ok, int base) const
KLF_EXPORT QByteArray klfSave(const KLFAbstractPropertizedObject *obj, const QString &format)
QDomNode appendChild(const QDomNode &newChild)
short toShort(bool *ok, int base) const
QByteArray toLower() const
QByteArray trimmed() const
double toDouble(bool *ok) const
virtual QString recognizeDataFormat(const QByteArray &data) const =0
Qt::BrushStyle style() const
QString attribute(const QString &name, const QString &defValue) const
KLF_EXPORT QVariantList klfLoadVariantListFromXML(const QDomElement &xmlNode)
Load a list saved with klfSaveVariantListToXML()
void setMinimal(bool minimal)
KLF_EXPORT QDomElement klfSaveVariantMapToXML(const QVariantMap &vmap, QDomElement baseNode)
Lossless save of full map to XML with type information.
QList< QVariant > toList() const
Base declarations for klatexformula and some utilities.
ushort toUShort(bool *ok, int base) const
bool startsWith(const QByteArray &ba) const
#define klfDbg(streamableItems)
print debug stream items
#define KLF_DEBUG_BLOCK(msg)
Utility to debug the execution of a block.
QTime fromString(const QString &string, Qt::DateFormat format)
KLFAbstractPropertizedObjectSaver()
QDomElement documentElement() const
NodeType nodeType() const
long toLong(bool *ok, int base) const
void setNamedColor(const QString &name)
static KLFAbstractPropertizedObjectSaver * findSaverFor(const QString &format)
KLF_EXPORT QByteArray klfEscapedToData(const QByteArray &data, char escapechar)
virtual QMap< QString, QVariant > allProperties() const
Convenience function to retrieve all properties.
QTextCodec * codecForLocale()
Base class for factories.
#define KLF_ASSERT_NOT_NULL(ptr, msg, failaction)
Asserting Non-NULL pointers (NON-FATAL)
QDomNode nextSibling() const
const QColor & color() const
#define KLF_TEXT_FORMAT_PROP(p, type)
QDomElement toElement() const
int indexIn(const QString &str, int offset, CaretMode caretMode) const
QDate fromString(const QString &string, Qt::DateFormat format)
An abstract object characterized by properties.
virtual ~KLFAbstractPropertizedObjectSaver()
int indexOf(char ch, int from) const
QString number(int n, int base)
QString fromLocal8Bit(const char *str, int size)
virtual QByteArray typeNameFor(const QString &property) const
Corresonding type for the given property.
void append(const T &value)
QString fromUtf8(const char *str, int size)
void setStyle(Style style)
QDomDocument ownerDocument() const
#define klfWarning(streamableItems)
QStringList capturedTexts() const
void setAttribute(const QString &name, const QString &value)
QMap< int, QVariant > properties() const
int toInt(bool *ok, int base) const
KLF_EXPORT QDomElement klfSaveVariantListToXML(const QVariantList &vlist, QDomElement baseNode)
Lossless save of full list to XML with type information.
const char * constData() const
QByteArray number(int n, int base)
bool startsWith(const QString &s, Qt::CaseSensitivity cs) const
A base abstract factory manager class.
QByteArray & replace(int pos, int len, const char *after)
QByteArray mid(int pos, int len) const
#define KLF_DEBUG_TIME_BLOCK(msg)
Utility to time the execution of a block.
QDomText createTextNode(const QString &value)
QByteArray toLocal8Bit() const
virtual bool load(const QByteArray &data, KLFAbstractPropertizedObject *obj, const QString &format)=0
QDateTime fromString(const QString &string, Qt::DateFormat format)
qlonglong toLongLong(bool *ok, int base) const
const QMatrix & matrix() const
virtual QByteArray save(const KLFAbstractPropertizedObject *obj, const QString &format)=0
QString & replace(int position, int n, QChar after)
QByteArray left(int len) const
KLFFactoryBase * findFactoryFor(const QString &objType)
KLF_EXPORT bool klfLoad(const QByteArray &data, KLFAbstractPropertizedObject *obj, const QString &format)
QDomNode firstChild() const
QByteArray toLatin1() const
QMap< QString, QVariant > toMap() const
QString mid(int position, int n) const
virtual bool setSpecification(const QByteArray &data)=0
QStringList toStringList() const
#define KLF_BRUSH_STYLE(sty)
QList< KLFFactoryBase * > registeredFactories()
#define KLF_TEXT_FORMAT_FORMAT(fmt)
const char * typeName() const
bool contains(char ch) const
KLFBaseFormatsPropertizedObjectSaver __klf_baseformats_pobj_saver
bool canEncode(QChar ch) const
QString fromLatin1(const char *str, int size)
qulonglong toULongLong(bool *ok, int base) const
ulong toULong(bool *ok, int base) const
KLF_EXPORT QByteArray klfDataToEscaped(const QByteArray &value_ba, char escapechar)
bool setSpecification(const QByteArray &data)
virtual bool setAllProperties(const QMap< QString, QVariant > &data)
Convenience function to load a set of property values.
virtual bool hasFixedTypes() const
#define KLF_ASSERT_CONDITION(expr, msg, failaction)
Asserting Conditions (NON-FATAL)
QDomElement createElement(const QString &tagName)
KLF_EXPORT QVariant klfLoadVariantFromText(const QByteArray &stringdata, const char *dataTypeName, const char *listOrMapDataTypeName)
KLF_EXPORT QVariantMap klfLoadVariantMapFromXML(const QDomElement &xmlNode)
Load a map saved with klfSaveVariantMapToXML()
int compare(const QString &other, Qt::CaseSensitivity cs) const
virtual QByteArray specification() const =0
Inherit this class to implement a custom saver for KLFAbstractPropertizedObjects. ...
QByteArray & remove(int pos, int len)
QString arg(qlonglong a, int fieldWidth, int base, QChar fillChar) const
virtual QByteArray typeSpecificationFor(const QString &property) const
A type specification for the given property.
QByteArray toEncoded(FormattingOptions options) const
QByteArray toByteArray(int indent) const
bool setContent(const QByteArray &data, bool namespaceProcessing, QString *errorMsg, int *errorLine, int *errorColumn)