本文整理汇总了C++中QXmlQuery::setFocus方法的典型用法代码示例。如果您正苦于以下问题:C++ QXmlQuery::setFocus方法的具体用法?C++ QXmlQuery::setFocus怎么用?C++ QXmlQuery::setFocus使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QXmlQuery
的用法示例。
在下文中一共展示了QXmlQuery::setFocus方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: loadMasterSettings
void MasterConfiguration::loadMasterSettings()
{
QXmlQuery query;
if(!query.setFocus(QUrl(filename_)))
{
put_flog(LOG_FATAL, "failed to load %s", filename_.toLatin1().constData());
exit(-1);
}
QString queryResult;
// dock start directory
query.setQuery("string(/configuration/dock/@directory)");
if (query.evaluateTo(&queryResult))
dockStartDir_ = queryResult.remove(QRegExp("[\\n\\t\\r]"));
if( dockStartDir_.isEmpty( ))
dockStartDir_ = QDir::homePath();
// WebService server port
query.setQuery("string(/configuration/webservice/@port)");
if (query.evaluateTo(&queryResult))
{
if (queryResult.isEmpty())
dcWebServicePort_ = DEFAULT_WEBSERVICE_PORT;
else
dcWebServicePort_ = queryResult.toInt();
}
}
示例2: readContextReply
void LastFmContext::readContextReply() {
qDebug("Got reply!");
QString replyString = QString::fromUtf8(contextReply->readAll());
if (replyString.isEmpty()) {
emit contextError();
return; // Avoid empty parsing of XML
}
// Parametres
QString status;
QString artistName;
QString artistPicture;
QString artistSummary;
QString artistProfile;
QXmlQuery query;
query.setFocus(replyString);
query.setQuery("lfm[@status = 'ok']/count(artist)");
query.evaluateTo(&status);
status = status.trimmed();
qDebug("Status: " + status.toUtf8());
/*
* If we got the data successfully, let's read it.
* I hate XML.
*/
if (status == "1") {
query.setQuery("lfm/artist/name/text()");
query.evaluateTo(&artistName);
artistName = artistName.trimmed();
query.setQuery("lfm/artist/url/text()");
query.evaluateTo(&artistProfile);
artistProfile = artistProfile.trimmed();
query.setQuery("lfm/artist/image[@size=\"extralarge\"]/text()");
query.evaluateTo(&artistPicture);
artistPicture = artistPicture.trimmed();
// Summary has HTML entities that must be un-replaced.
query.setQuery("lfm/artist/bio/summary/text()");
query.evaluateTo(&artistSummary);
artistSummary = artistSummary.trimmed().replace("<","<").replace(">",">");
// Store the context data into... contextData. Nice!
contextData.clear();
contextData.insert("artist", artistName);
contextData.insert("picture", artistPicture);
contextData.insert("summary", artistSummary);
contextData.insert("profile", artistProfile);
// Emit the signal
emit contextUpdated(contextData);
}
else {
qDebug("FAIL!");
emit contextError();
}
}
示例3: setContent
void JobEventList::setContent(const QString &content, const QString &userName,
QList<qint64> jobIds)
{
m_xml = content;
m_valid = true;
MessageHandler handler;
QXmlQuery query;
query.setMessageHandler(&handler);
JobEventListXmlReceiver receiver(query.namePool());
query.setFocus(m_xml);
if (jobIds.isEmpty()) {
query.setQuery("/list/JobEvent");
}
else {
QString xpath = "/list/JobEvent/jobID[";
QListIterator<qint64> iter(jobIds);
while (iter.hasNext()) {
qint64 jobId = iter.next();
xpath += QString("starts-with(text(), '%1')").arg(jobId);
if (iter.hasNext())
xpath += " or ";
}
xpath += "]/parent::node()";
query.setQuery(xpath);
}
m_valid = query.evaluateTo(&receiver);
m_jobEvents = receiver.jobEvents();
}
示例4: findElement
SimXmlElement SimXmlDoc::findElement(const std::string& elementName, const std::string& refId) const
{
SimXmlElement result(QSharedPointer<QDomElement>(), *this);
if (isNull()){
return result;
}
QString queryString = simQuery("/SimModel/" + elementName + "[@RefId='" + refId + "'][1]");
QXmlQuery query;
QDomNodeModel model(query.namePool(), *(impl()));
query.setFocus(QXmlItem(model.fromDomNode(impl()->documentElement())));
query.setQuery(queryString, QUrl(QString::fromStdString(this->path())));
if (query.isValid()) {
QXmlResultItems items;
query.evaluateTo(&items);
QXmlItem item(items.next());
if(!item.isNull()) {
QDomElement elem = model.toDomNode(item.toNodeModelIndex()).toElement();
QSharedPointer<QDomElement> impl(new QDomElement(elem));
result = SimXmlElement(impl, *this);
}
}
return result;
}
示例5: xml
QString F520xmlserializer::query(F520Status *f520, QString day, QString month, SysError &sysErr) {
QXmlQuery query;
QString res;
QFile xml(f520->getXmlPath());
if ( ! xml.exists()) {
xml.setFileName(f520->getXmlPath());
if ( ! xml.exists()) {
sysErr = SysError(SysError::F520_CAN_NOT_OPEN_FILE, "F520 Rasource file not exist");
return "";
}
}
if (!xml.open(QIODevice::ReadOnly | QIODevice::Text)) {
sysErr = SysError(SysError::F520_RESOUCES_NOT_EXIST, "F520 can not open xml resource file");
return "";
}
QString queryStr = CARICO + "/" + DAYS + "/" + DAY + "[@" + DAY_VALUE + "='" + day + "'][@" + MONTH_VALUE + "='" + month + "']";
qDebug() << "F520xmlserializer::query: " << queryStr;
query.setFocus(&xml);
query.setQuery(queryStr);
if ( ! query.isValid()) {
qDebug() << "F520xmlserializer::query query not valid";
sysErr = SysError(SysError::F520_QUERY_ERROR, "F520 Query is invalid: " + queryStr);
return "";
}
query.evaluateTo(&res);
if (!(res.length() > 1)) {
queryStr = CARICO + "/" + DAYS + "/" + DAY + "[@" + NAME + "='" + DEFAULT_DAY + "']";
qDebug() << "F520xmlserializer::query: " << queryStr;
query.setQuery(queryStr);
if (!query.isValid()) {
qDebug() << "F520xmlserializer::query query not valid";
sysErr = SysError(SysError::F520_QUERY_ERROR, "F520 Query is invalid: " + queryStr);
return "";
}
query.evaluateTo(&res);
}
xml.close();
qDebug() << "F520xmlserializer::query " << res;
QDomDocument watt;
watt.setContent("" + res + "");
QDomNodeList entryNodes = watt.elementsByTagName(DAY);
QString rtn;
for (int i = 0; i < entryNodes.count(); i++) {
QDomElement node = entryNodes.at(i).toElement();
rtn = node.attribute(WATT);
break;
}
qDebug() << "F520xmlserializer::query " << rtn;
return rtn;
}
示例6: render
void RssFeedNode::render(Grantlee::OutputStream* stream, Grantlee::Context* c)
{
QNetworkAccessManager *mgr = new QNetworkAccessManager(this);
QUrl url(Grantlee::getSafeString(m_url.resolve(c)));
QNetworkReply *reply = mgr->get(QNetworkRequest(url));
QEventLoop eLoop;
connect( mgr, SIGNAL( finished( QNetworkReply * ) ), &eLoop, SLOT( quit() ) );
eLoop.exec( QEventLoop::ExcludeUserInputEvents );
c->push();
foreach(Grantlee::Node *n, m_childNodes) {
if (!n->inherits(XmlNamespaceNode::staticMetaObject.className()))
continue;
Grantlee::OutputStream _dummy;
n->render(&_dummy, c);
}
QXmlQuery query;
QByteArray ba = reply->readAll();
QBuffer buffer;
buffer.setData(ba);
buffer.open(QIODevice::ReadOnly);
query.bindVariable("inputDocument", &buffer);
QString ns;
QHash<QString, QVariant> h = c->lookup("_ns").toHash();
QHash<QString, QVariant>::const_iterator it = h.constBegin();
const QHash<QString, QVariant>::const_iterator end = h.constEnd();
for ( ; it != end; ++it ) {
if (it.key().isEmpty()) {
ns += QLatin1Literal( "declare default element namespace " ) + QLatin1Literal( " \"" ) + it.value().toString() + QLatin1Literal( "\";\n" );
} else {
ns += QLatin1Literal( "declare namespace " ) + it.key() + QLatin1Literal( " = \"" ) + it.value().toString() + QLatin1Literal( "\";\n" );
}
}
query.setQuery(ns + "doc($inputDocument)" + Grantlee::getSafeString(m_query.resolve(c)).get());
QXmlResultItems result;
query.evaluateTo(&result);
QXmlItem item(result.next());
int count = 0;
while (!item.isNull()) {
if (count++ > 20)
break;
query.setFocus(item);
c->push();
foreach(Grantlee::Node *n, m_childNodes) {
if (n->inherits(XmlNamespaceNode::staticMetaObject.className()))
continue;
c->insert("_q", QVariant::fromValue(query));
n->render(stream, c);
}
c->pop();
item = result.next();
}
c->pop();
}
示例7: load
void Configuration::load()
{
QXmlQuery query;
if(!query.setFocus(QUrl(filename_)))
throw std::runtime_error("Invalid configuration file: " + filename_.toStdString());
QString queryResult;
// get screen / mullion dimensions
query.setQuery("string(/configuration/dimensions/@numTilesWidth)");
if(query.evaluateTo(&queryResult))
totalScreenCountX_ = queryResult.toInt();
query.setQuery("string(/configuration/dimensions/@numTilesHeight)");
if(query.evaluateTo(&queryResult))
totalScreenCountY_ = queryResult.toInt();
query.setQuery("string(/configuration/dimensions/@screenWidth)");
if(query.evaluateTo(&queryResult))
screenWidth_ = queryResult.toInt();
query.setQuery("string(/configuration/dimensions/@screenHeight)");
if(query.evaluateTo(&queryResult))
screenHeight_ = queryResult.toInt();
query.setQuery("string(/configuration/dimensions/@mullionWidth)");
if(query.evaluateTo(&queryResult))
mullionWidth_ = queryResult.toInt();
query.setQuery("string(/configuration/dimensions/@mullionHeight)");
if(query.evaluateTo(&queryResult))
mullionHeight_ = queryResult.toInt();
// check for fullscreen mode flag
query.setQuery("string(/configuration/dimensions/@fullscreen)");
if(query.evaluateTo(&queryResult))
fullscreen_ = queryResult.toInt() != 0;
// Background content URI
query.setQuery("string(/configuration/background/@uri)");
if(query.evaluateTo(&queryResult))
backgroundUri_ = queryResult.remove(QRegExp("[\\n\\t\\r]"));
// Background color
query.setQuery("string(/configuration/background/@color)");
if (query.evaluateTo(&queryResult))
{
queryResult.remove(QRegExp("[\\n\\t\\r]"));
QColor newColor( queryResult );
if( newColor.isValid( ))
backgroundColor_ = newColor;
}
}
示例8: onDirectoryChecked
void YandexNarodUploadJob::onDirectoryChecked()
{
QNetworkReply *reply = qobject_cast<QNetworkReply *>(sender());
Q_ASSERT(reply);
reply->deleteLater();
const int code = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
if (code == 404) {
// Directory is not created yet, so be a god
YandexRequest request(reply->url());
QNetworkReply *reply = YandexNarodFactory::networkManager()
->sendCustomRequest(request, "MKCOL");
connect(reply, SIGNAL(finished()), this, SLOT(onDirectoryCreated()));
return;
}
const QString xmlData = QString::fromUtf8(reply->readAll());
QStringList files;
QXmlQuery query;
query.setFocus(xmlData);
query.setQuery(QLatin1String("declare default element namespace \"DAV:\";"
"/multistatus/response/href/text()/string()"));
query.evaluateTo(&files);
if (files.contains(QLatin1String("/qutim-filetransfer"))) {
// Oops... May be check another directories?
setState(Error);
setError(NetworkError);
setErrorString(QT_TR_NOOP("Can't create directory \"/qutim-filetransfer/\""));
return;
}
const QString fileName = YandexNarodUploadJob::fileName();
QUrl url = reply->url();
QString path = url.path();
QString filePath = path + fileName;
if (files.contains(filePath)) {
const QString basename = fileName.section(QLatin1Char('.'), 0, 0);
const QString suffix = fileName.section(QLatin1Char('.'), 1);
for (int i = 1; ; ++i) {
filePath = path % basename
% QLatin1Char('(') % QString::number(i) % QLatin1Char(')')
% (suffix.isEmpty() ? QLatin1Literal("") : QLatin1Literal("."))
% suffix;
if (!files.contains(filePath))
break;
}
}
uploadFile(reply->url().resolved(QUrl(filePath)));
}
示例9: loadMasterSettings
void MasterConfiguration::loadMasterSettings()
{
QXmlQuery query;
if(!query.setFocus(QUrl(filename_)))
{
put_flog(LOG_FATAL, "failed to load %s", filename_.toLatin1().constData());
exit(-1);
}
loadDockStartDirectory(query);
loadWebBrowserStartURL(query);
}
示例10: ParseRepoInfo
RepoInfo ParseRepoInfo (const QUrl& url, const QString& data)
{
QXmlQuery query;
query.setFocus (data);
RepoInfo info (url);
QString out;
query.setQuery ("/repo/name/text()");
if (!query.evaluateTo (&out))
throw QObject::tr ("Could not get repo name.");
info.SetName (out.simplified ());
query.setQuery ("/repo/description/short/text()");
if (!query.evaluateTo (&out))
throw QObject::tr ("Could not get repo description.");
info.SetShortDescr (out.simplified ());
query.setQuery ("/repo/description/long/text()");
if (!query.evaluateTo (&out))
throw QObject::tr ("Could not get long repo description.");
info.SetLongDescr (out.simplified ());
MaintainerInfo maintInfo;
query.setQuery ("/repo/maintainer/name/text()");
if (!query.evaluateTo (&out))
throw QObject::tr ("Could not get maintainer name.");
maintInfo.Name_ = out.simplified ();
query.setQuery ("/repo/maintainer/email/text()");
if (!query.evaluateTo (&out))
throw QObject::tr ("Could not get maintainer email.");
maintInfo.Email_ = out.simplified ();
info.SetMaintainer (maintInfo);
QStringList components;
query.setQuery ("/repo/components/component/text()");
if (query.evaluateTo (&components))
info.SetComponents (components);
else if (query.evaluateTo (&out))
info.SetComponents (QStringList (out));
else
throw QObject::tr ("Could not get components.");
return info;
}
示例11: runXmlQuerry
QString runXmlQuerry(QFile *file, QString querry)
{
F_TRACE;
QXmlQuery query;
QString res;
file->seek(0);
query.setFocus(file);
query.setQuery(querry);
if ( ! query.isValid())
{
qDebug() << "Invalid querry" << querry;
}
query.evaluateTo(&res);
return res.simplified();
}
示例12: xmlFile
QString
CXSettingsXML::getValue(const QString& aFileName, const QString& aName, const QString& def)
{
QString result;
QFile xmlFile(aFileName);
if (xmlFile.open(QIODevice::ReadOnly))
{
QXmlQuery query;
query.setFocus(&xmlFile);
query.setQuery(QString("/Settings/%1/text()").arg(aName));
query.evaluateTo(&result);
xmlFile.close();
}
if(result.length() == 0) result = def;
return result;
}
示例13: handleGetChallengeRequestFinished
void FotoBilderAccount::handleGetChallengeRequestFinished ()
{
QDomDocument document;
const QByteArray& content = CreateDomDocumentFromReply (qobject_cast<QNetworkReply*> (sender ()),
document);
if (content.isEmpty ())
return;
QXmlQuery query;
query.setFocus (content);
QString challenge;
query.setQuery ("/FBResponse/GetChallengeResponse/Challenge/text()");
if (!query.evaluateTo (&challenge))
return;
if (!CallsQueue_.isEmpty ())
CallsQueue_.dequeue () (challenge.trimmed ());
}
示例14: newMessage
Presets *PtzManagement::getPresets()
{
Presets *presets = NULL;
Message *msg = newMessage();
QDomElement getPresets = newElement("wsdl:GetPresets");
QDomElement profileToken = newElement("wsdl:ProfileToken","profile_CIF");
getPresets.appendChild(profileToken);
msg->appendToBody(getPresets);
MessageParser *result = sendMessage(msg);
if(result != NULL){
presets = new Presets();
QXmlQuery *query = result->query();
QXmlResultItems items;
QXmlItem item;
QString value,xml;
QDomDocument doc;
QDomNodeList itemNodeList;
QDomNode node;
query->setQuery(result->nameSpace()+"doc($inputDocument)//tptz:Preset");
query->evaluateTo(&items);
item = items.next();
while(!item.isNull()){
query->setFocus(item);
query->setQuery(result->nameSpace()+".");
query->evaluateTo(&xml);
doc.setContent(xml);
itemNodeList = doc.elementsByTagName("tptz:Preset");
for(int i=0; i<itemNodeList.size(); i++)
{
node = itemNodeList.at(i);
value = node.toElement().attribute("token");
presets->setToken(value.trimmed());
}
query->setQuery(result->nameSpace()+"./tt:Name/string()");
query->evaluateTo(&value);
presets->setName(value.trimmed());
item = items.next();
}
}
delete msg;
delete result;
return presets;
}
示例15: handleLoginReply
void Twitter::handleLoginReply()
{
QNetworkReply *reply = qobject_cast<QNetworkReply *>(sender());
m_credentialsXml = reply->readAll();
QString error;
if (!m_credentialsXml.isEmpty()) {
QBuffer buffer(&m_credentialsXml);
buffer.open(QIODevice::ReadOnly);
QXmlQuery query;
query.setFocus(&buffer);
query.setQuery("data(/hash/error)");
QString error;
query.evaluateTo(&error);
} else {
error = reply->errorString();
}
emit credentialsVerified(reply->error() == QNetworkReply::NoError, error);
}