KDevelop API Documentation

buildtools/generic/variantserializer.cpp

Go to the documentation of this file.
00001 /*************************************************************************** 00002 * Copyright (C) 2003 Alexander Dymo * 00003 * cloudtemple@mksat.net * 00004 * * 00005 * This program is free software; you can redistribute it and/or modify * 00006 * it under the terms of the GNU General Public License as published by * 00007 * the Free Software Foundation; either version 2 of the License, or * 00008 * (at your option) any later version. * 00009 * * 00010 ***************************************************************************/ 00011 #include "variantserializer.h" 00012 00013 void VariantSerializer::storeValue( QDomElement & node, const QVariant & var ) 00014 { 00015 if (var.type() == QVariant::String) 00016 storeString(node, var); 00017 else if (var.type() == QVariant::StringList) 00018 storeStringList(node, var); 00019 else if (var.type() == QVariant::Int) 00020 storeInt(node, var); 00021 else if (var.type() == QVariant::Double) 00022 storeDouble(node, var); 00023 else if (var.type() == QVariant::Bool) 00024 storeBool(node, var); 00025 } 00026 00027 void VariantSerializer::storeString( QDomElement & node, const QVariant & var ) 00028 { 00029 node.setAttribute("type", "String"); 00030 QDomText text = node.ownerDocument().createTextNode(var.toStringList().join(":::")); 00031 node.appendChild(text); 00032 } 00033 00034 void VariantSerializer::storeStringList( QDomElement & node, const QVariant & var ) 00035 { 00036 node.setAttribute("type", "StringList"); 00037 QDomText text = node.ownerDocument().createTextNode(var.toStringList().join(":::")); 00038 node.appendChild(text); 00039 } 00040 00041 void VariantSerializer::storeBool( QDomElement & node, const QVariant & var ) 00042 { 00043 node.setAttribute("type", "Bool"); 00044 QDomText text = node.ownerDocument().createTextNode(var.toString()); 00045 node.appendChild(text); 00046 } 00047 00048 void VariantSerializer::storeInt( QDomElement & node, const QVariant & var ) 00049 { 00050 node.setAttribute("type", "Int"); 00051 QDomText text = node.ownerDocument().createTextNode(var.toString()); 00052 node.appendChild(text); 00053 } 00054 00055 void VariantSerializer::storeDouble( QDomElement & node, const QVariant & var ) 00056 { 00057 node.setAttribute("type", "Double"); 00058 QDomText text = node.ownerDocument().createTextNode(var.toString()); 00059 node.appendChild(text); 00060 } 00061 00062 QVariant VariantSerializer::loadString( const QDomText & node ) 00063 { 00064 return QVariant(node.nodeValue()); 00065 } 00066 00067 QVariant VariantSerializer::loadStringList( const QDomText & node ) 00068 { 00069 return QVariant(QStringList::split(":::", node.nodeValue())); 00070 } 00071 00072 QVariant VariantSerializer::loadBool( const QDomText & node ) 00073 { 00074 if (node.nodeValue() == "false") 00075 return QVariant(false); 00076 else 00077 return QVariant(true); 00078 } 00079 00080 QVariant VariantSerializer::loadInt( const QDomText & node ) 00081 { 00082 return QVariant(node.nodeValue().toInt()); 00083 } 00084 00085 QVariant VariantSerializer::loadDouble( const QDomText & node ) 00086 { 00087 return QVariant(node.nodeValue().toDouble()); 00088 } 00089 00090 QVariant VariantSerializer::loadValue( const QDomElement & el ) 00091 { 00092 QString type = el.attribute("type", "QString"); 00093 QDomText val = el.firstChild().toText(); 00094 if (type == "String") 00095 return loadString(val); 00096 else if (type == "StringList") 00097 return loadStringList(val); 00098 else if (type == "Bool") 00099 return loadBool(val); 00100 else if (type == "Int") 00101 return loadInt(val); 00102 else if (type == "Double") 00103 return loadDouble(val); 00104 return QVariant(); 00105 } 00106 00107
KDE Logo
This file is part of the documentation for KDevelop Version 3.0.4.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Oct 6 17:38:54 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003