本文整理汇总了C++中QDomNodeList类的典型用法代码示例。如果您正苦于以下问题:C++ QDomNodeList类的具体用法?C++ QDomNodeList怎么用?C++ QDomNodeList使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QDomNodeList类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: QLOG_TRACE_IN
// Index any resources
void NoteIndexer::indexRecognition(qint32 reslid, Resource &r) {
QLOG_TRACE_IN();
if (!r.noteGuid.isSet() || !r.guid.isSet())
return;
if (reslid <= 0)
return;
NSqlQuery sql(db);
// Make sure we have something to look through.
Data recognition;
if (r.recognition.isSet())
recognition = r.recognition;
if (!recognition.body.isSet())
return;
QDomDocument doc;
QString emsg;
doc.setContent(recognition.body, &emsg);
// look for text tags
QDomNodeList anchors = doc.documentElement().elementsByTagName("t");
QLOG_TRACE() << "Beginning insertion of recognition:";
QLOG_TRACE() << "Anchors found: " << anchors.length();
sql.exec("begin;");
#if QT_VERSION < 0x050000
for (unsigned int i=0; i<anchors.length(); i++) {
#else
for (int i=0; i<anchors.length(); i++) {
#endif
QLOG_TRACE() << "Anchor: " << i;
QApplication::processEvents();
QDomElement enmedia = anchors.at(i).toElement();
QString weight = enmedia.attribute("w");
QString text = enmedia.text();
if (text != "") {
// Add the new content. it is basically a text version of the note with a weight of 100.
sql.prepare("Insert into SearchIndex (lid, weight, source, content) values (:lid, :weight, :source, :content)");
sql.bindValue(":lid", reslid);
sql.bindValue(":weight", weight);
sql.bindValue(":source", "recognition");
text = global.normalizeTermForSearchAndIndex(text);
sql.bindValue(":content", text);
sql.exec();
}
}
QLOG_TRACE() << "Committing";
sql.exec("commit");
QLOG_TRACE_OUT();
}
// Index any PDFs that are attached. Basically it turns the PDF into text and adds it the same
// way as a note's body
void NoteIndexer::indexPdf(qint32 reslid) {
QLOG_TRACE_IN();
if (!global.indexPDFLocally)
return;
NSqlQuery sql(db);
if (reslid <= 0)
return;
QString file = global.fileManager.getDbaDirPath() + QString::number(reslid) +".pdf";
QString text = "";
Poppler::Document *doc = Poppler::Document::load(file);
if (doc == nullptr || doc->isEncrypted() || doc->isLocked())
return;
for (int i=0; i<doc->numPages(); i++) {
QRectF rect;
text = text + doc->page(i)->text(rect) + QString(" ");
}
QLOG_TRACE() << "Adding PDF";
// Add the new content. it is basically a text version of the note with a weight of 100.
sql.prepare("Insert into SearchIndex (lid, weight, source, content) values (:lid, :weight, :source, :content)");
sql.bindValue(":lid", reslid);
sql.bindValue(":weight", 100);
sql.bindValue(":source", "recognition");
text = global.normalizeTermForSearchAndIndex(text);
sql.bindValue(":content", text);
sql.exec();
QLOG_TRACE_OUT();
}
示例2: for_each_node
void for_each_node(const QDomNodeList & list, F f) {
for (int i = 0; i < list.size(); ++i) {
f(list.at(i));
}
}
示例3: setDataAvailable
bool LH_MonitoringSource_Aida64::doUpdate()
{
#ifdef Q_OS_WIN
bool resultVal = true;
const char* mapnameAida64 = "AIDA64_SensorValues";
const char* mapnameEverest = "EVEREST_SensorValues";
// Create file mapping
HANDLE filemap = (HANDLE)OpenFileMappingA(FILE_MAP_READ,0,mapnameAida64);
if(filemap == NULL)
filemap = (HANDLE)OpenFileMappingA(FILE_MAP_READ,0,mapnameEverest);
setDataAvailable(filemap != NULL);
if(dataAvailable())
{
char* aidaData = (char*)MapViewOfFile(filemap, FILE_MAP_READ, 0, 0, 0);
if (aidaData) {
aidaXml_.setContent(QString("<data>%1</data>").arg(QString(aidaData)));
QRegExp rx = QRegExp("([^0-9]*)([0-9]+#?\\s?)(.*)");
rx.setPatternSyntax(QRegExp::RegExp2);
QDomNode n = aidaXml_.documentElement().firstChild();
while(!n.isNull()) {
QDomElement e = n.toElement(); // try to convert the node to an element.
if(!e.isNull()) {
QDomNodeList labelNodes = e.elementsByTagName("label");
QDomNodeList valueNodes = e.elementsByTagName("value");
if(labelNodes.count()==1 && valueNodes.count()==1)
{
QString typeName = e.tagName();
QString itemName = labelNodes.at(0).toElement().text();
QString groupName = (rx.indexIn(reverse(itemName))==-1 ? itemName : reverse(rx.cap(3)) + reverse(rx.cap(1)) );
QString valueString = valueNodes.at(0).toElement().text();
QString units="";
if(typeName=="sys")
{
typeName = "System";
if (itemName.endsWith("FSB")) units="mhz";
if (itemName.endsWith("Clock")) units="mhz";
if (itemName.endsWith("Utilization")) units="%";
if (itemName.endsWith("Memory")) units="MB";
}
if(typeName=="temp")
{
typeName = "Temperatures";
units=QLatin1Literal("\260C");
}
if(typeName=="fan")
{
typeName = "Cooling Fans";
units="rpm";
}
if(typeName=="duty")
{
typeName = "Fan Speeds";
}
if(typeName=="volt")
{
typeName = "Voltage Values";
units="V";
}
bool ok;
double valueDouble = valueString.toDouble(&ok);
if(ok)
updateValue(typeName,groupName,itemName, valueDouble, SensorDefinition(units));
else
updateValue(typeName,groupName,itemName, valueString, SensorDefinition(units));
}
}
n = n.nextSibling();
}
UnmapViewOfFile(aidaData);
}
else
resultVal = false;
CloseHandle(filemap);
}
else
resultVal = false;
return resultVal;
#else
return false;
#endif
}
示例4: InitReportConfig
bool ConfigManager::InitReportConfig()
{
XmlHelper *xmlhelper = XmlHelper::GetInstance();
QString node_str;
node_str = "report_config";
QDomElement root = xmlhelper->GetXmlNodeParent(node_str);
QDomNodeList nodelist = root.childNodes();
for(int i = 0;i < nodelist.count();++i)
{
QDomNode child = nodelist.at(i);
if (child.nodeName() == "export_path")
{
app_settings_.set_export_path(child.toElement().text());
continue;
}
if (child.nodeName() == "summary_day")
{
app_settings_.set_summary_day(child.toElement().text().toInt());
continue;
}
if (child.nodeName() == "summary_reference_magnitude")
{
app_settings_.set_summary_reference_magnitude(child.toElement().text().toFloat());
continue;
}
if (child.nodeName() == "reference_date_order")
{
app_settings_.set_reference_date_order(child.toElement().text().toInt() != 0);
continue;
}
if (child.nodeName() == "reference_date_include")
{
app_settings_.set_reference_date_include(child.toElement().text().toInt() != 0);
continue;
}
if (child.nodeName() == "seis_event_column")
{
app_settings_.set_seis_event_column(child.toElement().text().toInt());
continue;
}
if (child.nodeName() == "trigger_start")
{
app_settings_.set_trigger_start(child.toElement().text().toInt());
continue;
}
if (child.nodeName() == "trigger_end")
{
app_settings_.set_trigger_end(child.toElement().text().toInt());
continue;
}
if (child.nodeName() == "stat_trigger_filter")
{
app_settings_.set_stat_trigger_filter(child.toElement().text().toInt());
continue;
}
// if (child.nodeName() == "stat_magnitude_filter")
// {
// app_settings_.set_stat_magnitude_filter(child.toElement().text().toFloat());
// continue;
// }
if (child.nodeName() == "stat_reference_magnitude")
{
app_settings_.set_stat_reference_magnitude(child.toElement().text().toFloat());
continue;
}
if (child.nodeName() == "enable_large_event_config")
{
app_settings_.set_enable_large_event_config(child.toElement().text().toInt() != 0);
continue;
}
if (child.nodeName() == "large_event_reference_magnitude")
{
app_settings_.set_large_event_reference_magnitude(child.toElement().text().toFloat());
continue;
}
// if (child.nodeName() == "large_event_show_num")
// {
// app_settings_.set_large_event_show_num(child.toElement().text().toInt());
// continue;
// }
if (child.nodeName() == "fit_magnitude")
{
app_settings_.set_fit_magnitude(child.toElement().text().toFloat());
continue;
}
//.........这里部分代码省略.........
示例5: QgsDebugMsg
bool QgsPropertyValue::readXML( QDomNode & keyNode )
{
// this *should* be a Dom element node
QDomElement subkeyElement = keyNode.toElement();
// get the type so that we can properly parse the key value
QString typeString = subkeyElement.attribute( "type" );
if ( QString::null == typeString )
{
QgsDebugMsg( QString( "null ``type'' attribute for %1" ).arg( keyNode.nodeName() ) );
return false;
}
// the values come in as strings; we need to restore them to their
// original values *and* types
value_.clear();
// get the type associated with the value first
QVariant::Type type = QVariant::nameToType( typeString.toLocal8Bit().constData() );
// This huge switch is left-over from an earlier incarnation of
// QgsProject where there was a fine level of granularity for value
// types. The current interface, borrowed from QSettings, supports a
// very small sub-set of these types. However, I've left all the
// other types just in case the interface is expanded to include these
// other types.
switch ( type )
{
case QVariant::Invalid:
QgsDebugMsg( QString( "invalid value type %1 .. " ).arg( typeString ) );
return false;
case QVariant::Map:
QgsDebugMsg( "no support for QVariant::Map" );
return false;
case QVariant::List:
QgsDebugMsg( "no support for QVariant::List" );
return false;
case QVariant::String:
value_ = subkeyElement.text(); // no translating necessary
break;
case QVariant::StringList:
{
int i = 0;
QDomNodeList values = keyNode.childNodes();
// all the QStringList values will be inside <value> elements
QStringList valueStringList;
while ( i < values.count() )
{
if ( "value" == values.item( i ).nodeName() )
{ // <value>s have only one element, which contains actual string value
valueStringList.append( values.item( i ).firstChild().nodeValue() );
}
else
{
QgsDebugMsg( QString( "non <value> element ``%1'' in string list" ).arg( values.item( i ).nodeName() ) );
}
++i;
}
value_ = valueStringList;
break;
}
case QVariant::Font:
QgsDebugMsg( "no support for QVariant::Font" );
return false;
case QVariant::Pixmap:
QgsDebugMsg( "no support for QVariant::Pixmap" );
return false;
case QVariant::Brush:
QgsDebugMsg( "no support for QVariant::Brush" );
return false;
case QVariant::Rect:
QgsDebugMsg( "no support for QVariant::Rect" );
return false;
case QVariant::Size:
QgsDebugMsg( "no support for QVariant::Size" );
return false;
case QVariant::Color:
QgsDebugMsg( "no support for QVariant::Color" );
return false;
case QVariant::Palette:
QgsDebugMsg( "no support for QVariant::Palette" );
return false;
//.........这里部分代码省略.........
示例6: request
void PacificaServices::downloadFinished(QNetworkReply *reply)
{
const char *prefix = "";
QDomElement root;
QDomNode services;
QDomNode n;
QDomElement e;
int i;
int res;
QUrl url;
QVariant possible_redirect = reply->attribute(QNetworkRequest::RedirectionTargetAttribute);
url = possible_redirect.toUrl();
if(!url.isEmpty() && current_url != url && redirect_count < 5)
{
redirect_count++;
current_url = url;
std::cout << "Redirecting to " << url.toString().toStdString() << "\n";
QNetworkRequest request(current_url);
QNetworkReply *reply = manager.get(request);
return;
}
//FIXME handle error.
_services = new QHash<QString, QString>();
//FIXME rename root element once server is updated.
QDomDocument doc("myemsl");
std::cout << doc.setContent(reply) << "\n";
root = doc.documentElement();
QDomNodeList list = root.elementsByTagName("prefix");
for(i = 0; i < list.count(); i++)
{
e = list.at(i).toElement();
prefix = strdup(e.text().toStdString().c_str());
}
QSettings settings;
if(settings.contains("url/prefix"))
{
prefix = strdup(settings.value("url/prefix").toString().toStdString().c_str());
}
list = root.elementsByTagName("services");
for(i = 0; i < list.count(); i++)
{
services = list.at(i);
}
list = services.childNodes();
for(i = 0; i < list.count(); i++)
{
e = list.at(i).toElement();
if(e.nodeName() == "service")
{
if(e.attribute("location", "").toStdString().c_str()[0] == '/')
{
_services->insert(e.attribute("name", NULL), prefix + e.attribute("location", ""));
}
else
{
_services->insert(e.attribute("name", NULL), e.attribute("location", ""));
}
}
}
ready(_services);
}
示例7: oresponse
void UpgradeCheck::httpRequestFinished(int requestId, bool error)
{
bd_.upgradeCallbacks++;
if (http == 0 || error) {
bd_.upgradeErrors++;
return;
}
// This is not an error state; it's just the internal state of Qt's network
// stack flailing around.
if (requestId != httpRequestId) {
return;
}
QString oresponse(http->readAll());
QDomDocument document;
int line = -1;
QString error_text;
// This shouldn't ever be seen by a user.
if (!document.setContent(oresponse, &error_text, &line)) {
QMessageBox::critical(0, tr("Error"),
tr("Invalid return data at line %1: %2.")
.arg(line)
.arg( error_text));
bd_.upgradeErrors++;
return;
}
QString response;
QString upgradeText;
if (testing)
currentVersion = "1.3.1"; // for testing
bool allowBeta = true; // TODO: come from prefs or current version...
QDomNodeList upgrades = document.elementsByTagName("update");
QUrl downloadUrl;
updateStatus_ = updateCurrent; // Current until proven guilty.
for (unsigned int i = 0; i < upgrades.length(); i++) {
QDomNode upgradeNode = upgrades.item(i);
QDomElement upgrade = upgradeNode.toElement();
QString updateVersion = upgrade.attribute("version");
if (upgrade.attribute("downloadURL").isEmpty()) {
downloadUrl = "http://www.gpsbabel.org/download.html";
} else {
downloadUrl = upgrade.attribute("downloadURL");
}
bool updateIsBeta = upgrade.attribute("type") == "beta";
bool updateIsMajor = upgrade.attribute("type") == "major";
bool updateIsMinor = upgrade.attribute("type") == "minor";
bool updateCandidate = updateIsMajor || updateIsMinor || (updateIsBeta && allowBeta);
upgradeText = upgrade.firstChildElement("overview").text();
// String compare, not a numeric one. Server will return "best first".
if((updateVersion > currentVersion) && updateCandidate) {
bd_.upgradeOffers++;
updateStatus_ = updateNeeded;
response = tr("A new version of GPSBabel is available.<br />"
"Your version is %1 <br />"
"The latest version is %2")
.arg(currentVersion)
.arg(updateVersion);
break;
}
}
if (response.length()) {
QMessageBox information;
information.setWindowTitle(tr("Upgrade"));
information.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
information.setDefaultButton(QMessageBox::Yes);
information.setText(response);
information.setInformativeText(tr("Do you wish to download an upgrade?"));
information.setDetailedText(upgradeText);
switch (information.exec()) {
case QMessageBox::Yes:
// downloadUrl.addQueryItem("os", getOsName());
QDesktopServices::openUrl(downloadUrl);
default: ;
bd_.upgradeDeclines++;
}
}
upgradeWarningTime = QDateTime(QDateTime::currentDateTime());
for (int i = 0; i < formatList_.size(); i++) {
formatList_[i].zeroUseCounts();
}
}
示例8: readXML
bool QgsPropertyKey::readXML( QDomNode & keyNode )
{
int i = 0;
QDomNodeList subkeys = keyNode.childNodes();
while ( i < subkeys.count() )
{
// if the current node is an element that has a "type" attribute,
// then we know it's a leaf node; i.e., a subkey _value_, and not
// a subkey
if ( subkeys.item( i ).hasAttributes() && // if we have attributes
subkeys.item( i ).isElement() && // and we're an element
subkeys.item( i ).toElement().hasAttribute( "type" ) ) // and we have a "type" attribute
{ // then we're a key value
delete mProperties.take( subkeys.item( i ).nodeName() );
mProperties.insert( subkeys.item( i ).nodeName(), new QgsPropertyValue );
QDomNode subkey = subkeys.item( i );
if ( !mProperties[subkeys.item( i ).nodeName()]->readXML( subkey ) )
{
QgsDebugMsg( QString( "unable to parse key value %1" ).arg( subkeys.item( i ).nodeName() ) );
}
}
else // otherwise it's a subkey, so just recurse on down the remaining keys
{
addKey( subkeys.item( i ).nodeName() );
QDomNode subkey = subkeys.item( i );
if ( !mProperties[subkeys.item( i ).nodeName()]->readXML( subkey ) )
{
QgsDebugMsg( QString( "unable to parse subkey %1" ).arg( subkeys.item( i ).nodeName() ) );
}
}
++i;
}
return true;
} // QgsPropertyKey::readXML(QDomNode & keyNode)
示例9: tr
bool ParameterEdit::setDocument(const QDomDocument & doc)
{
QDomElement root = doc.documentElement();
if(root.tagName() != "report")
{
QMessageBox::critical(this, tr("Not a Valid Report"),
tr("The report definition does not appear to be a valid report."
"\n\nThe root node is not 'report'."));
return false;
}
_list->show();
_new->hide();
_delete->hide();
for(QDomNode n = root.firstChild(); !n.isNull(); n = n.nextSibling())
{
if(n.nodeName() == "parameter")
{
QDomElement elemSource = n.toElement();
ORParameter param;
param.name = elemSource.attribute("name");
if(param.name.isEmpty())
continue;
param.type = elemSource.attribute("type");
param.defaultValue = elemSource.attribute("default");
param.active = (elemSource.attribute("active") == "true");
param.listtype = elemSource.attribute("listtype");
QList<QPair<QString,QString> > pairs;
if(param.listtype.isEmpty())
param.description = elemSource.text();
else
{
QDomNodeList section = elemSource.childNodes();
for(int nodeCounter = 0; nodeCounter < section.count(); nodeCounter++)
{
QDomElement elemThis = section.item(nodeCounter).toElement();
if(elemThis.tagName() == "description")
param.description = elemThis.text();
else if(elemThis.tagName() == "query")
param.query = elemThis.text();
else if(elemThis.tagName() == "item")
param.values.append(qMakePair(elemThis.attribute("value"), elemThis.text()));
else
qDebug("While parsing parameter encountered an unknown element: %s",(const char*)elemThis.tagName().toLatin1().data());
}
}
QVariant defaultVar;
if(!param.defaultValue.isEmpty())
defaultVar = QVariant(param.defaultValue);
if("integer" == param.type)
defaultVar = defaultVar.toInt();
else if("double" == param.type)
defaultVar = defaultVar.toDouble();
else if("bool" == param.type)
defaultVar = QVariant(defaultVar.toBool());
else
defaultVar = defaultVar.toString();
updateParam(param.name, defaultVar, param.active);
QList<QPair<QString, QString> > list;
if("static" == param.listtype)
list = param.values;
else if("dynamic" == param.listtype && !param.query.isEmpty())
{
QSqlQuery qry(param.query);
while(qry.next())
list.append(qMakePair(qry.value(0).toString(), qry.value(1).toString()));
}
if(!list.isEmpty())
_lists.insert(param.name, list);
}
}
if(_lists.isEmpty())
return false; // no defined parameters
else
return true;
}
示例10: loadDetailsFromXML
static bool loadDetailsFromXML(const QString &filename, FileDetails *details)
{
QDomDocument doc("mydocument");
QFile file(filename);
if (!file.open(QIODevice::ReadOnly))
return false;
if (!doc.setContent(&file))
{
file.close();
return false;
}
file.close();
QString docType = doc.doctype().name();
if (docType == "MYTHARCHIVEITEM")
{
QDomNodeList itemNodeList = doc.elementsByTagName("item");
QString type, dbVersion;
if (itemNodeList.count() < 1)
{
LOG(VB_GENERAL, LOG_ERR,
"Couldn't find an 'item' element in XML file");
return false;
}
QDomNode n = itemNodeList.item(0);
QDomElement e = n.toElement();
type = e.attribute("type");
dbVersion = e.attribute("databaseversion");
if (type == "recording")
{
QDomNodeList nodeList = e.elementsByTagName("recorded");
if (nodeList.count() < 1)
{
LOG(VB_GENERAL, LOG_ERR,
"Couldn't find a 'recorded' element in XML file");
return false;
}
n = nodeList.item(0);
e = n.toElement();
n = e.firstChild();
while (!n.isNull())
{
e = n.toElement();
if (!e.isNull())
{
if (e.tagName() == "title")
details->title = e.text();
if (e.tagName() == "subtitle")
details->subtitle = e.text();
if (e.tagName() == "starttime")
details->startTime = MythDate::fromString(e.text());
if (e.tagName() == "description")
details->description = e.text();
}
n = n.nextSibling();
}
// get channel info
n = itemNodeList.item(0);
e = n.toElement();
nodeList = e.elementsByTagName("channel");
if (nodeList.count() < 1)
{
LOG(VB_GENERAL, LOG_ERR,
"Couldn't find a 'channel' element in XML file");
details->chanID = "";
details->chanNo = "";
details->chanName = "";
details->callsign = "";
return false;
}
n = nodeList.item(0);
e = n.toElement();
details->chanID = e.attribute("chanid");
details->chanNo = e.attribute("channum");
details->chanName = e.attribute("name");
details->callsign = e.attribute("callsign");
return true;
}
else if (type == "video")
{
QDomNodeList nodeList = e.elementsByTagName("videometadata");
if (nodeList.count() < 1)
{
LOG(VB_GENERAL, LOG_ERR,
"Couldn't find a 'videometadata' element in XML file");
return false;
}
n = nodeList.item(0);
e = n.toElement();
//.........这里部分代码省略.........
示例11: file
/**
* Parse a kxml file and insert content into the document. Returns
* true on success.
*/
bool KDocument::loadKxml(QString filename) {
QFile file(filename);
file.open(QIODevice::ReadOnly);
QDomDocument document("kxml");
if (!document.setContent(&file)) {
return false;
}
/*
* Meta information
*/
QStringList meta;
meta << "title" << "author" << "description" << "language";
for (int i = 0; i < meta.size(); i++) {
setProperty(
meta.at(i).toUtf8(),
document.elementsByTagName( meta.at(i) ).at(0).toElement().text()
);
}
/*
* Categories
*/
QDomNodeList categories = document.elementsByTagName("category");
for (uint i = 0; i < categories.length(); i++) {
QDomElement category = categories.at(i).toElement();
m_categories.append(category.attribute("name"));
/*
* Questions
*/
QDomNodeList questions = category.elementsByTagName("question");
for (uint j = 0; j < questions.length(); j++) {
QDomElement question = questions.at(j).toElement();
KQuestion q;
q.setCategory(category.attribute("name"));
// Text
QDomElement text = question.elementsByTagName("text").at(0).toElement();
q.setText(text.text());
// Id
if (question.hasAttribute("id")) {
q.setId(question.attribute("id").toInt());
}
// Type
if (question.attribute("type") == "alternatives") {
q.setType(KQuestion::Alternatives);
} else {
q.setType(KQuestion::Manual);
}
// Level
if (question.attribute("level") == "easy") {
q.setLevel(KQuestion::Easy);
} else if (question.attribute("level") == "medium") {
q.setLevel(KQuestion::Medium);
} else {
q.setLevel(KQuestion::Hard);
}
// Image
QDomNodeList images = question.elementsByTagName("image");
if (images.count() > 0) {
QDomElement image = images.at(0).toElement();
QByteArray ba = QByteArray::fromBase64(image.text().toUtf8());
QPixmap p;
p.loadFromData(ba, "PNG");
q.setImage(p);
}
// Answers
QDomNodeList answers = question.elementsByTagName("answer");
for (uint k = 0; k < answers.length(); k++) {
QDomElement answer = answers.at(k).toElement();
if (answer.attribute("correct") != 0) {
q.m_answers.prepend(answer.text());
} else {
q.m_answers.append(answer.text());
}
}
m_questions.append(q);
}
}
/*
//.........这里部分代码省略.........
示例12: file
SyncDocument *SyncDocument::load(const QString &fileName)
{
SyncDocument *ret = new SyncDocument;
ret->fileName = fileName;
QFile file(fileName);
if (!file.open(QIODevice::ReadOnly)) {
QMessageBox::critical(NULL, "Error", file.errorString());
return NULL;
}
QDomDocument doc;
QString err;
if (!doc.setContent(&file, &err)) {
file.close();
QMessageBox::critical(NULL, "Error", err);
return NULL;
}
file.close();
QDomNamedNodeMap attribs = doc.documentElement().attributes();
QDomNode rowsParam = attribs.namedItem("rows");
if (!rowsParam.isNull()) {
QString rowsString = rowsParam.nodeValue();
ret->setRows(rowsString.toInt());
}
QDomNodeList trackNodes =
doc.documentElement().elementsByTagName("track");
for (int i = 0; i < int(trackNodes.length()); ++i) {
QDomNode trackNode = trackNodes.item(i);
QDomNamedNodeMap attribs = trackNode.attributes();
QString name = attribs.namedItem("name").nodeValue();
// look up track-name, create it if it doesn't exist
int trackIndex = sync_find_track(ret, name.toUtf8());
if (0 > trackIndex)
trackIndex = int(ret->createTrack(name.toUtf8().constData()));
QDomNodeList rowNodes = trackNode.childNodes();
for (int i = 0; i < int(rowNodes.length()); ++i) {
QDomNode keyNode = rowNodes.item(i);
QString baseName = keyNode.nodeName();
if (baseName == "key") {
QDomNamedNodeMap rowAttribs = keyNode.attributes();
QString rowString = rowAttribs.namedItem("row").nodeValue();
QString valueString = rowAttribs.namedItem("value").nodeValue();
QString interpolationString = rowAttribs.namedItem("interpolation").nodeValue();
track_key k;
k.row = rowString.toInt();
k.value = valueString.toFloat();
k.type = key_type(interpolationString.toInt());
Q_ASSERT(!is_key_frame(ret->tracks[trackIndex], k.row));
if (sync_set_key(ret->tracks[trackIndex], &k))
qFatal("failed to insert key");
}
}
}
// YUCK: gathers from entire document
QDomNodeList bookmarkNodes =
doc.documentElement().elementsByTagName("bookmark");
for (int i = 0; i < int(bookmarkNodes.length()); ++i) {
QDomNode bookmarkNode =
bookmarkNodes.item(i);
QDomNamedNodeMap bookmarkAttribs =
bookmarkNode.attributes();
QString str =
bookmarkAttribs.namedItem("row").nodeValue();
int row = str.toInt();
ret->toggleRowBookmark(row);
}
return ret;
}
示例13: QStringLiteral
bool QgsLayoutItemScaleBar::readPropertiesFromElement( const QDomElement &itemElem, const QDomDocument &, const QgsReadWriteContext &context )
{
mSettings.setHeight( itemElem.attribute( QStringLiteral( "height" ), QStringLiteral( "5.0" ) ).toDouble() );
mSettings.setLabelBarSpace( itemElem.attribute( QStringLiteral( "labelBarSpace" ), QStringLiteral( "3.0" ) ).toDouble() );
mSettings.setBoxContentSpace( itemElem.attribute( QStringLiteral( "boxContentSpace" ), QStringLiteral( "1.0" ) ).toDouble() );
mSettings.setNumberOfSegments( itemElem.attribute( QStringLiteral( "numSegments" ), QStringLiteral( "2" ) ).toInt() );
mSettings.setNumberOfSegmentsLeft( itemElem.attribute( QStringLiteral( "numSegmentsLeft" ), QStringLiteral( "0" ) ).toInt() );
mSettings.setUnitsPerSegment( itemElem.attribute( QStringLiteral( "numUnitsPerSegment" ), QStringLiteral( "1.0" ) ).toDouble() );
mSettings.setSegmentSizeMode( static_cast<QgsScaleBarSettings::SegmentSizeMode>( itemElem.attribute( QStringLiteral( "segmentSizeMode" ), QStringLiteral( "0" ) ).toInt() ) );
mSettings.setMinimumBarWidth( itemElem.attribute( QStringLiteral( "minBarWidth" ), QStringLiteral( "50" ) ).toDouble() );
mSettings.setMaximumBarWidth( itemElem.attribute( QStringLiteral( "maxBarWidth" ), QStringLiteral( "150" ) ).toDouble() );
mSegmentMillimeters = itemElem.attribute( QStringLiteral( "segmentMillimeters" ), QStringLiteral( "0.0" ) ).toDouble();
mSettings.setMapUnitsPerScaleBarUnit( itemElem.attribute( QStringLiteral( "numMapUnitsPerScaleBarUnit" ), QStringLiteral( "1.0" ) ).toDouble() );
mSettings.setLineWidth( itemElem.attribute( QStringLiteral( "outlineWidth" ), QStringLiteral( "0.3" ) ).toDouble() );
mSettings.setUnitLabel( itemElem.attribute( QStringLiteral( "unitLabel" ) ) );
mSettings.setLineJoinStyle( QgsSymbolLayerUtils::decodePenJoinStyle( itemElem.attribute( QStringLiteral( "lineJoinStyle" ), QStringLiteral( "miter" ) ) ) );
mSettings.setLineCapStyle( QgsSymbolLayerUtils::decodePenCapStyle( itemElem.attribute( QStringLiteral( "lineCapStyle" ), QStringLiteral( "square" ) ) ) );
QDomNodeList textFormatNodeList = itemElem.elementsByTagName( QStringLiteral( "text-style" ) );
if ( !textFormatNodeList.isEmpty() )
{
QDomElement textFormatElem = textFormatNodeList.at( 0 ).toElement();
mSettings.textFormat().readXml( textFormatElem, context );
}
else
{
QFont f;
if ( !QgsFontUtils::setFromXmlChildNode( f, itemElem, QStringLiteral( "scaleBarFont" ) ) )
{
f.fromString( itemElem.attribute( QStringLiteral( "font" ), QString() ) );
}
mSettings.textFormat().setFont( f );
if ( f.pointSizeF() > 0 )
{
mSettings.textFormat().setSize( f.pointSizeF() );
mSettings.textFormat().setSizeUnit( QgsUnitTypes::RenderPoints );
}
else if ( f.pixelSize() > 0 )
{
mSettings.textFormat().setSize( f.pixelSize() );
mSettings.textFormat().setSizeUnit( QgsUnitTypes::RenderPixels );
}
}
//colors
//fill color
QDomNodeList fillColorList = itemElem.elementsByTagName( QStringLiteral( "fillColor" ) );
if ( !fillColorList.isEmpty() )
{
QDomElement fillColorElem = fillColorList.at( 0 ).toElement();
bool redOk, greenOk, blueOk, alphaOk;
int fillRed, fillGreen, fillBlue, fillAlpha;
fillRed = fillColorElem.attribute( QStringLiteral( "red" ) ).toDouble( &redOk );
fillGreen = fillColorElem.attribute( QStringLiteral( "green" ) ).toDouble( &greenOk );
fillBlue = fillColorElem.attribute( QStringLiteral( "blue" ) ).toDouble( &blueOk );
fillAlpha = fillColorElem.attribute( QStringLiteral( "alpha" ) ).toDouble( &alphaOk );
if ( redOk && greenOk && blueOk && alphaOk )
{
mSettings.setFillColor( QColor( fillRed, fillGreen, fillBlue, fillAlpha ) );
}
}
else
{
mSettings.setFillColor( QColor( itemElem.attribute( QStringLiteral( "brushColor" ), QStringLiteral( "#000000" ) ) ) );
}
//fill color 2
QDomNodeList fillColor2List = itemElem.elementsByTagName( QStringLiteral( "fillColor2" ) );
if ( !fillColor2List.isEmpty() )
{
QDomElement fillColor2Elem = fillColor2List.at( 0 ).toElement();
bool redOk, greenOk, blueOk, alphaOk;
int fillRed, fillGreen, fillBlue, fillAlpha;
fillRed = fillColor2Elem.attribute( QStringLiteral( "red" ) ).toDouble( &redOk );
fillGreen = fillColor2Elem.attribute( QStringLiteral( "green" ) ).toDouble( &greenOk );
fillBlue = fillColor2Elem.attribute( QStringLiteral( "blue" ) ).toDouble( &blueOk );
fillAlpha = fillColor2Elem.attribute( QStringLiteral( "alpha" ) ).toDouble( &alphaOk );
if ( redOk && greenOk && blueOk && alphaOk )
{
mSettings.setFillColor2( QColor( fillRed, fillGreen, fillBlue, fillAlpha ) );
}
}
else
{
mSettings.setFillColor2( QColor( itemElem.attribute( QStringLiteral( "brush2Color" ), QStringLiteral( "#ffffff" ) ) ) );
}
//stroke color
QDomNodeList strokeColorList = itemElem.elementsByTagName( QStringLiteral( "strokeColor" ) );
if ( !strokeColorList.isEmpty() )
{
QDomElement strokeColorElem = strokeColorList.at( 0 ).toElement();
bool redOk, greenOk, blueOk, alphaOk;
int strokeRed, strokeGreen, strokeBlue, strokeAlpha;
strokeRed = strokeColorElem.attribute( QStringLiteral( "red" ) ).toDouble( &redOk );
//.........这里部分代码省略.........
示例14: clear
QList< QgsLayoutItem * > QgsLayout::loadFromTemplate( const QDomDocument &document, const QgsReadWriteContext &context, bool clearExisting, bool *ok )
{
if ( ok )
*ok = false;
QList< QgsLayoutItem * > result;
if ( clearExisting )
{
clear();
}
QDomDocument doc;
// If this is a 2.x composition template, convert it to a layout template
if ( QgsCompositionConverter::isCompositionTemplate( document ) )
{
doc = QgsCompositionConverter::convertCompositionTemplate( document, mProject );
}
else
{
doc = document;
}
// remove all uuid attributes since we don't want duplicates UUIDS
QDomNodeList itemsNodes = doc.elementsByTagName( QStringLiteral( "LayoutItem" ) );
for ( int i = 0; i < itemsNodes.count(); ++i )
{
QDomNode itemNode = itemsNodes.at( i );
if ( itemNode.isElement() )
{
itemNode.toElement().removeAttribute( QStringLiteral( "uuid" ) );
}
}
QDomNodeList multiFrameNodes = doc.elementsByTagName( QStringLiteral( "LayoutMultiFrame" ) );
for ( int i = 0; i < multiFrameNodes.count(); ++i )
{
QDomNode multiFrameNode = multiFrameNodes.at( i );
if ( multiFrameNode.isElement() )
{
multiFrameNode.toElement().removeAttribute( QStringLiteral( "uuid" ) );
QDomNodeList frameNodes = multiFrameNode.toElement().elementsByTagName( QStringLiteral( "childFrame" ) );
QDomNode itemNode = frameNodes.at( i );
if ( itemNode.isElement() )
{
itemNode.toElement().removeAttribute( QStringLiteral( "uuid" ) );
}
}
}
//read general settings
if ( clearExisting )
{
QDomElement layoutElem = doc.documentElement();
if ( layoutElem.isNull() )
{
return result;
}
bool loadOk = readXml( layoutElem, doc, context );
if ( !loadOk )
{
return result;
}
layoutItems( result );
}
else
{
result = addItemsFromXml( doc.documentElement(), doc, context );
}
if ( ok )
*ok = true;
return result;
}
示例15: loadData
void editorModel::loadData(TtableDef table)
{
activeTable = table;
this->beginResetModel();
//m_dataFile = dataFile;
//doc = QDomDocument("ODKDocument");
/*QFile xmlfile(dataFile);
if (!xmlfile.open(QIODevice::ReadOnly))
return ;
if (!doc.setContent(&xmlfile))
{
xmlfile.close();
return ;
}
xmlfile.close();*/
int index;
index = 0;
//qDebug() << "Begin load data";
for (int idoc = 0; idoc <= fileList.count()-1;idoc++)
{
if (fileList[idoc].opened)
{
fileList[idoc].dataList.clear();
if (table.name == "mainModule")
{
QDomNodeList records;
QDomNodeList fields;
int clm;
records = fileList[idoc].doc.elementsByTagName(table.xmlCode);
for (int pos = 0; pos <= records.count()-1;pos++)
{
TdataDef record;
record.modified = false;
record.itemElement = records.item(pos).toElement();
record.index = index;
for (clm = 0; clm <= activeTable.fields.count()-1; clm++)
{
fields = record.itemElement.elementsByTagName(activeTable.fields[clm].name);
if (fields.count() > 0)
{
TdataItemDef item;
item.ignore = false;
item.modified = false;
item.itemElement = fields.item(0).toElement();
item.value = fields.item(0).toElement().firstChild().nodeValue();
record.fields.append(item);
}
else
{
TdataItemDef item;
item.ignore = true;
item.value = "NA";
item.modified = false;
record.fields.append(item);
}
}
fileList[idoc].dataList.append(record);
index++;
}
}
else
{
QDomNodeList records;
QDomNodeList fields;
int clm;
records = fileList[idoc].doc.elementsByTagName(table.name);
for (int pos = 0; pos <= records.count()-1;pos++)
{
TdataDef record;
record.modified = false;
record.itemElement = records.item(pos).toElement();
record.index = index;
for (clm = 0; clm <= activeTable.fields.count()-1; clm++)
{
fields = record.itemElement.elementsByTagName(activeTable.fields[clm].name);
if (fields.count() > 0)
{
TdataItemDef item;
item.ignore = false;
item.modified = false;
item.itemElement = fields.item(0).toElement();
item.value = fields.item(0).toElement().firstChild().nodeValue();
record.fields.append(item);
}
else
{
TdataItemDef item;
item.ignore = true;
item.value = "NA";
item.modified = false;
record.fields.append(item);
}
}
fileList[idoc].dataList.append(record);
//.........这里部分代码省略.........