⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qmconfig.cpp

📁 可以播放MP3,wma等文件格式的播放器
💻 CPP
📖 第 1 页 / 共 2 页
字号:
	{				if(n.firstChild().isNull() == false)		{			QDomNode t = findNode(n, name);			if( ! t.isNull())				n = t;		}		if(n.isElement() && n.nodeName() == name)			break;					n = n.nextSibling();	}	return n;}/*!  Retrieves the key node \a key in \a group or a null node if not found.  For example, in a tree like this:  \verbatim  <group>      <integer>42</integer>  </group>  \endverbatim  the returned node will be the <integer> node, so in order to get the  actual value (42) you need to get the first child of the <integer> node.  \return The key node or a null node if not found.*/QDomNodeQmConfig::findKeyNode(	const QString &group,	const QString &key) const{	QDomNode group_node = findNode(group);	if(group_node.isNull())	{		qWarning("QmConfig::findKeyNode(): Group \'%s\' not found.  The value for \'%s\' will "				 "not be retrieved.", group.latin1(), key.latin1());		return group_node;	}	QDomNode n = group_node.namedItem(key);//  rk: that's ok, the "getter" can deal with it.//      if it's usefull for debugging we could add a debug variable to test on// 	if(n.isNull())// 	{// 		qWarning("QmConfig::findKeyNode(): The key \'%s\' was not found in the group \'%s\'.  "// 				 "No value will be returned.", key.latin1(), group.latin1());// 	}	return n;}voidQmConfig::clear(	const QString &group,	const QString &key){	QDomNode group_node = findNode(group);	if(group_node.isNull())	{		qWarning("QmConfig::clear(): Group \'%s\' not found.  The key \'%s\' will not be cleared.",				 group.latin1(), key.latin1());		return;	}	QDomNode n = group_node.namedItem(key);	if( ! n.isNull())	{        group_node.removeChild( n );	}}/*! \name Set functions  Use these functions to persistently store values.  Each set() function has  a corresponding get() function to retrieve the value. *//*@{*//*!  Assigns \a i as the value of \a key and adds this key to \a group.  If  \a group does not exist, a warning will be printed, but the key and its  value will not be stored.    For example:  \code  set("mpg123", "buffer", 1024);  \endcode  will produce:  \verbatim  <mpg123>      <buffer>1024</buffer>  </mpg123>  \endverbatim  \warning The result is undefined if you try to set a key of one type to  an already existing key of another type.  For example, if a rectangle  exists with name 'size', then trying to set the contents of that key  with a string will give undefined behaviour. */voidQmConfig::set(	const QString &group,	const QString &key,	int i){	QDomNode group_node = findNode(group);	if(group_node.isNull())	{		qWarning("QmConfig::set(): Group \'%s\' not found.  The key \'%s\' will not be set.",				 group.latin1(), key.latin1());		return;	}	QDomNode n = group_node.namedItem(key);	if( ! n.isNull())	{		// n will be the key element (<key> ... </key>).  The first child will be the		// text (value).		if( ! m_LazySetMode)		{			n = n.firstChild();			n.setNodeValue(QString::number(i));		}	}	else	{		// Create an element for the key (<key> ... </key>) and a text node within the		// key (<key> textnode goes here </key>).				n = m_pRoot->createElement(key);		n.appendChild( m_pRoot->createTextNode( QString::number(i) ) );		group_node.appendChild(n);	}}voidQmConfig::set(	const QString &group,	const QString &key,	bool b){	QDomNode group_node = findNode(group);	if(group_node.isNull())	{		qWarning("QmConfig::set(): Group \'%s\' not found.  The key \'%s\' will not be set.",				 group.latin1(), key.latin1());		return;	}	QDomNode n = group_node.namedItem(key);	if( ! n.isNull())	{		// n will be the key element (<key> ... </key>).  The first child will be the		// text (value).		if( ! m_LazySetMode)		{			n = n.firstChild();            n.setNodeValue(b ? "true" : "false");		}	}	else	{		// Create an element for the key (<key> ... </key>) and a text node within the		// key (<key> textnode goes here </key>).				n = m_pRoot->createElement(key);		n.appendChild( m_pRoot->createTextNode( b ? "true" : "false" ) );		group_node.appendChild(n);	}}/*!  \overload*/voidQmConfig::set(	const QString &group,	const QString &key,	const QRect &rect){	QDomNode group_node = findNode(group);	if(group_node.isNull())	{		qWarning("QmConfig::set(): Group \'%s\' not found.  The key \'%s\' will not be set.",				 group.latin1(), key.latin1());		return;	}	QDomNode n = group_node.namedItem(key);	if( ! n.isNull())	{		// n will be the key element (<key> ... </key>).  The first child will be the		// text (value).				if( ! m_LazySetMode)		{			QDomNode w = n.namedItem("width").firstChild();			QDomNode h = n.namedItem("height").firstChild();			QDomNode x = n.namedItem("x").firstChild();			QDomNode y = n.namedItem("y").firstChild();					w.setNodeValue(QString::number(rect.width()));			h.setNodeValue(QString::number(rect.height()));			x.setNodeValue(QString::number(rect.x()));			y.setNodeValue(QString::number(rect.y()));		}	}	else	{		// Create an element for the key (<key> ... </key>) and a text node within the		// key (<key> textnode goes here </key>).				QDomNode r = m_pRoot->createElement(key);		QDomNode w = m_pRoot->createElement("width");		QDomNode h = m_pRoot->createElement("height");		QDomNode x = m_pRoot->createElement("x");		QDomNode y = m_pRoot->createElement("y");		w.appendChild(m_pRoot->createTextNode( QString::number(rect.width())));		h.appendChild(m_pRoot->createTextNode( QString::number(rect.height())));		x.appendChild(m_pRoot->createTextNode( QString::number(rect.x())));		y.appendChild(m_pRoot->createTextNode( QString::number(rect.y())));		r.appendChild(w);		r.appendChild(h);		r.appendChild(x);		r.appendChild(y);		group_node.appendChild(r);	}}/*!  \overload*/voidQmConfig::set(	const QString &group,	const QString &key,	const QPoint &pos){	QDomNode group_node = findNode(group);	if(group_node.isNull())	{		qWarning("QmConfig::set(): Group \'%s\' not found.  The key \'%s\' will not be set.",				 group.latin1(), key.latin1());		return;	}	QDomNode n = group_node.namedItem(key);	if( ! n.isNull())	{		// n will be the key element (<key> ... </key>).  The first child will be the		// text (value).		if( ! m_LazySetMode)		{			QDomNode x = n.namedItem("x").firstChild();			QDomNode y = n.namedItem("y").firstChild();					x.setNodeValue(QString::number(pos.x()));			y.setNodeValue(QString::number(pos.y()));		}	}	else	{		// Create an element for the key (<key> ... </key>) and a text node within the		// key (<key> textnode goes here </key>).				QDomNode p = m_pRoot->createElement(key);		QDomNode x = m_pRoot->createElement("x");		QDomNode y = m_pRoot->createElement("y");		x.appendChild(m_pRoot->createTextNode( QString::number(pos.x())));		y.appendChild(m_pRoot->createTextNode( QString::number(pos.y())));		p.appendChild(x);		p.appendChild(y);		group_node.appendChild(p);	}}/*!  \overload*/voidQmConfig::set(	const QString &group,	const QString &key,	const QString &text){	QDomNode group_node = findNode(group);	if(group_node.isNull())	{		qWarning("QmConfig::set(): Group \'%s\' not found.  The key \'%s\' will not be set.",				 group.latin1(), key.latin1());		return;	}	QDomNode n = group_node.namedItem(key);	if( ! n.isNull())	{		// n will be the key element (<key> ... </key>).  The first child will be the		// text (value).				if( ! m_LazySetMode)		{			n = n.firstChild();			n.setNodeValue(text);		}	}	else	{		// Create an element for the key (<key> ... </key>) and a text node within the		// key (<key> textnode goes here </key>).				n = m_pRoot->createElement(key);		n.appendChild( m_pRoot->createCDATASection(text));		group_node.appendChild(n);	}}voidQmConfig::set(	const QString &group,	const QString &key,	const char *text){	QDomNode group_node = findNode(group);	if(group_node.isNull())	{		qWarning("QmConfig::set(): Group \'%s\' not found.  The key \'%s\' will not be set.",				 group.latin1(), key.latin1());		return;	}	QDomNode n = group_node.namedItem(key);	if( ! n.isNull())	{		// n will be the key element (<key> ... </key>).  The first child will be the		// text (value).				if( ! m_LazySetMode)		{			n = n.firstChild();			n.setNodeValue(text);		}	}	else	{		// Create an element for the key (<key> ... </key>) and a text node within the		// key (<key> textnode goes here </key>).				n = m_pRoot->createElement(key);		n.appendChild( m_pRoot->createCDATASection(text));		group_node.appendChild(n);	}}/*@}*/ // End of Doxygen group tag./*!  Returns true if the \a key in \a group exists, false otherwise.*/boolQmConfig::has(	const QString &group,	const QString &key) const{	QDomNode key_node = findKeyNode(group, key).firstChild();    return !key_node.isNull();}/** \name Get functions  Use these functions to retrieve persistently stored values.  Each get() function has  a corresponding set() function to set the value. *//*@{*//*!  Retrieves the value of \a key in \a group.  If \a key or \a group could not  be found, a warning will be printed and \a i will remain unchanged. */voidQmConfig::get(	const QString &group,	const QString &key,	int &i) const{	QDomNode key_node = findKeyNode(group, key).firstChild();	if( ! key_node.isNull())		i = key_node.nodeValue().toInt();}voidQmConfig::get(	const QString &group,	const QString &key,	bool &b) const{	QDomNode key_node = findKeyNode(group, key).firstChild();	if( ! key_node.isNull())        b = key_node.nodeValue() == "true";    else        b = false;}/*!  \overload*/voidQmConfig::get(	const QString &group,	const QString &key,	QRect &rect) const{	QDomNode key_node = findKeyNode(group, key);	if( ! key_node.isNull())	{		QDomNode x = key_node.namedItem("x").firstChild();		QDomNode y = key_node.namedItem("y").firstChild();		QDomNode w = key_node.namedItem("width").firstChild();		QDomNode h = key_node.namedItem("height").firstChild();		rect.setRect(x.nodeValue().toInt(),					 y.nodeValue().toInt(),					 w.nodeValue().toInt(),					 h.nodeValue().toInt());	}}/*!  \overload*/voidQmConfig::get(	const QString &group,	const QString &key,	QPoint &pos) const{	QDomNode key_node = findKeyNode(group, key);	if( ! key_node.isNull())	{		QDomNode x = key_node.namedItem("x").firstChild();		QDomNode y = key_node.namedItem("y").firstChild();		pos.setX(x.nodeValue().toInt());		pos.setY(x.nodeValue().toInt());	}}/*!  \overload*/voidQmConfig::get(	const QString &group,	const QString &key,	QString &text) const{	QDomNode key_node = findKeyNode(group, key).firstChild();	if( ! key_node.isNull())		text = key_node.nodeValue();}/*!  \return The rectangle \a group, \a key or an invalid rectangle if not found.*/QRectQmConfig::getRect(	const QString &group,	const QString &key) const{    QRect rect;    get( group, key, rect );    return rect;}/*!  \return The point \a group, \a key or (0, 0) if not found.*/QPointQmConfig::getPoint(	const QString &group,	const QString &key ) const{    QPoint pos;    get( group, key, pos );    return pos;}/*!  \return The string \a group, \a key or null string if not found.*/QStringQmConfig::getString(	const QString &group,	const QString &key ) const{    QString text;    get( group, key, text );    return text;}/*!  \return The integer \a group, \a key or 0 if not found.*/intQmConfig::getInt(	const QString &group,	const QString &key ) const{    int val;    get( group, key, val );    return val;}/*@}*/ // End of Doxygen group tag.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -