本文整理汇总了C++中QDomDocument类的典型用法代码示例。如果您正苦于以下问题:C++ QDomDocument类的具体用法?C++ QDomDocument怎么用?C++ QDomDocument使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QDomDocument类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: createGetCapabilitiesDocument
QDomDocument createGetCapabilitiesDocument( QgsServerInterface *serverIface, const QgsProject *project, const QString &version,
const QgsServerRequest &request )
{
Q_UNUSED( version );
QDomDocument doc;
//wcs:WCS_Capabilities element
QDomElement wcsCapabilitiesElement = doc.createElement( QStringLiteral( "WCS_Capabilities" )/*wcs:WCS_Capabilities*/ );
wcsCapabilitiesElement.setAttribute( QStringLiteral( "xmlns" ), WCS_NAMESPACE );
wcsCapabilitiesElement.setAttribute( QStringLiteral( "xmlns:xsi" ), QStringLiteral( "http://www.w3.org/2001/XMLSchema-instance" ) );
wcsCapabilitiesElement.setAttribute( QStringLiteral( "xsi:schemaLocation" ), WCS_NAMESPACE + " http://schemas.opengis.net/wcs/1.0.0/wcsCapabilities.xsd" );
wcsCapabilitiesElement.setAttribute( QStringLiteral( "xmlns:gml" ), GML_NAMESPACE );
wcsCapabilitiesElement.setAttribute( QStringLiteral( "xmlns:xlink" ), QStringLiteral( "http://www.w3.org/1999/xlink" ) );
wcsCapabilitiesElement.setAttribute( QStringLiteral( "version" ), implementationVersion() );
wcsCapabilitiesElement.setAttribute( QStringLiteral( "updateSequence" ), QStringLiteral( "0" ) );
doc.appendChild( wcsCapabilitiesElement );
//INSERT Service
wcsCapabilitiesElement.appendChild( getServiceElement( doc, project ) );
//wcs:Capability element
QDomElement capabilityElement = doc.createElement( QStringLiteral( "Capability" )/*wcs:Capability*/ );
wcsCapabilitiesElement.appendChild( capabilityElement );
//wcs:Request element
QDomElement requestElement = doc.createElement( QStringLiteral( "Request" )/*wcs:Request*/ );
capabilityElement.appendChild( requestElement );
//wcs:GetCapabilities
QDomElement getCapabilitiesElement = doc.createElement( QStringLiteral( "GetCapabilities" )/*wcs:GetCapabilities*/ );
requestElement.appendChild( getCapabilitiesElement );
QDomElement dcpTypeElement = doc.createElement( QStringLiteral( "DCPType" )/*wcs:DCPType*/ );
getCapabilitiesElement.appendChild( dcpTypeElement );
QDomElement httpElement = doc.createElement( QStringLiteral( "HTTP" )/*wcs:HTTP*/ );
dcpTypeElement.appendChild( httpElement );
//Prepare url
QString hrefString = serviceUrl( request, project );
QDomElement getElement = doc.createElement( QStringLiteral( "Get" )/*wcs:Get*/ );
httpElement.appendChild( getElement );
QDomElement onlineResourceElement = doc.createElement( QStringLiteral( "OnlineResource" )/*wcs:OnlineResource*/ );
onlineResourceElement.setAttribute( QStringLiteral( "xlink:type" ), QStringLiteral( "simple" ) );
onlineResourceElement.setAttribute( QStringLiteral( "xlink:href" ), hrefString );
getElement.appendChild( onlineResourceElement );
QDomElement getCapabilitiesDhcTypePostElement = dcpTypeElement.cloneNode().toElement();//this is the same as for 'GetCapabilities'
getCapabilitiesDhcTypePostElement.firstChild().firstChild().toElement().setTagName( QStringLiteral( "Post" ) );
getCapabilitiesElement.appendChild( getCapabilitiesDhcTypePostElement );
QDomElement describeCoverageElement = getCapabilitiesElement.cloneNode().toElement();//this is the same as 'GetCapabilities'
describeCoverageElement.setTagName( QStringLiteral( "DescribeCoverage" ) );
requestElement.appendChild( describeCoverageElement );
QDomElement getCoverageElement = getCapabilitiesElement.cloneNode().toElement();//this is the same as 'GetCapabilities'
getCoverageElement.setTagName( QStringLiteral( "GetCoverage" ) );
requestElement.appendChild( getCoverageElement );
//INSERT ContentMetadata
wcsCapabilitiesElement.appendChild( getContentMetadataElement( doc, serverIface, project ) );
return doc;
}
示例2: tr
void SamplerBank::slotLoadSamplerBank(double v) {
if (v == 0.0 || m_pPlayerManager == NULL) {
return;
}
QString samplerBankPath = QFileDialog::getOpenFileName(
NULL,
tr("Load Sampler Bank"),
QString(),
tr("Mixxx Sampler Banks (*.xml)"));
if (samplerBankPath.isEmpty()) {
return;
}
// The user has picked a new directory via a file dialog. This means the
// system sandboxer (if we are sandboxed) has granted us permission to this
// folder. We don't need access to this file on a regular basis so we do not
// register a security bookmark.
QFile file(samplerBankPath);
if (!file.open(QIODevice::ReadOnly)) {
QMessageBox::warning(NULL,
tr("Error Reading Sampler Bank"),
tr("Could not open the sampler bank file '%1'.")
.arg(samplerBankPath));
return;
}
QDomDocument doc;
if (!doc.setContent(file.readAll())) {
QMessageBox::warning(NULL,
tr("Error Reading Sampler Bank"),
tr("Could not read the sampler bank file '%1'.")
.arg(samplerBankPath));
return;
}
QDomElement root = doc.documentElement();
if(root.tagName() != "samplerbank") {
QMessageBox::warning(NULL,
tr("Error Reading Sampler Bank"),
tr("Could not read the sampler bank file '%1'.")
.arg(samplerBankPath));
return;
}
QDomNode n = root.firstChild();
while (!n.isNull()) {
QDomElement e = n.toElement();
if (!e.isNull()) {
if (e.tagName() == "sampler") {
QString group = e.attribute("group", "");
QString location = e.attribute("location", "");
if (!group.isEmpty()) {
if (location.isEmpty()) {
m_pPlayerManager->slotLoadTrackToPlayer(TrackPointer(), group);
} else {
m_pPlayerManager->slotLoadToPlayer(location, group);
}
}
}
}
n = n.nextSibling();
}
file.close();
}
示例3: saveXML
QDomElement KCValidity::saveXML(QDomDocument& doc, const KCValueConverter *converter) const
{
QDomElement validityElement = doc.createElement("validity");
QDomElement param = doc.createElement("param");
param.setAttribute("cond", (int)d->cond);
param.setAttribute("action", (int)d->action);
param.setAttribute("allow", (int)d->restriction);
param.setAttribute("valmin", converter->asString(d->minValue).asString());
param.setAttribute("valmax", converter->asString(d->maxValue).asString());
param.setAttribute("displaymessage", d->displayMessage);
param.setAttribute("displayvalidationinformation", d->displayValidationInformation);
param.setAttribute("allowemptycell", d->allowEmptyCell);
if (!d->listValidity.isEmpty())
param.setAttribute("listvalidity", d->listValidity.join(";"));
validityElement.appendChild(param);
QDomElement titleElement = doc.createElement("title");
titleElement.appendChild(doc.createTextNode(d->title));
validityElement.appendChild(titleElement);
QDomElement messageElement = doc.createElement("message");
messageElement.appendChild(doc.createCDATASection(d->message));
validityElement.appendChild(messageElement);
QDomElement inputTitle = doc.createElement("inputtitle");
inputTitle.appendChild(doc.createTextNode(d->titleInfo));
validityElement.appendChild(inputTitle);
QDomElement inputMessage = doc.createElement("inputmessage");
inputMessage.appendChild(doc.createTextNode(d->messageInfo));
validityElement.appendChild(inputMessage);
QString tmp;
if (d->restriction == Time) {
QDomElement timeMinElement = doc.createElement("timemin");
tmp = converter->asString(d->minValue).asString();
timeMinElement.appendChild(doc.createTextNode(tmp));
validityElement.appendChild(timeMinElement);
if (d->cond == KCConditional::Between || d->cond == KCConditional::Different) {
QDomElement timeMaxElement = doc.createElement("timemax");
tmp = converter->asString(d->maxValue).asString();
timeMaxElement.appendChild(doc.createTextNode(tmp));
validityElement.appendChild(timeMaxElement);
}
}
if (d->restriction == Date) {
QDomElement dateMinElement = doc.createElement("datemin");
const QDate minDate = d->minValue.asDate(converter->settings());
QString tmp("%1/%2/%3");
tmp = tmp.arg(minDate.year()).arg(minDate.month()).arg(minDate.day());
dateMinElement.appendChild(doc.createTextNode(tmp));
validityElement.appendChild(dateMinElement);
if (d->cond == KCConditional::Between || d->cond == KCConditional::Different) {
QDomElement dateMaxElement = doc.createElement("datemax");
const QDate maxDate = d->maxValue.asDate(converter->settings());
QString tmp("%1/%2/%3");
tmp = tmp.arg(maxDate.year()).arg(maxDate.month()).arg(maxDate.day());
dateMaxElement.appendChild(doc.createTextNode(tmp));
validityElement.appendChild(dateMaxElement);
}
}
return validityElement;
}
示例4: qDebug
bool CalculateConfig::getDefaultConfig()
{
m_Config.clear();
// start cl-install -v and parse out
QProcess cl_install;
qDebug() << "Start cl-install -v --xml --filter \"os_install|os_locale_lang$|os_disk|os_device|^cl_migrate_user$\"";
cl_install.start(
"cl-install -v --xml --filter \"os_install|os_locale_lang|os_disk|os_device|^cl_migrate_user$\""
);
if ( !cl_install.waitForStarted() )
return false;
if ( !cl_install.waitForFinished() )
return false;
QString outVars = cl_install.readAll();
qDebug() << endl << outVars;
QDomDocument xmlVars;
QString errMsg;
int errLine;
int errColumn;
if ( xmlVars.setContent(outVars, true, &errMsg, &errLine, &errColumn) )
{
QDomElement domRoot = xmlVars.documentElement();
if (domRoot.tagName() == "variables") {
parseVariables(domRoot, m_Config);
} else {
qDebug() << "Section \"variables\" not found";
return false;
}
}
// installer settings
// gui_partitioning - install type: auto, manual
m_Config["gui_install_language"] = m_Config["os_locale_lang"];
QStringList devs = m_Config["os_device_dev"].toStringList();
m_Config.remove("os_device_dev");
m_Config["os_device_dev"] = devs;
if ( !m_Config["os_device_dev"].toStringList().isEmpty() )
m_Config["gui_os_device_dev"] = m_Config["os_device_dev"].toStringList().at(0);
m_Config["gui_os_device_dev_def"] = m_Config["gui_os_device_dev"];
// copy default values
m_Config["gui_os_install_net_hostname"] = m_Config["os_install_net_hostname"];
m_Config["gui_os_install_net_domain"] = m_Config["os_install_net_domain"];
m_Config["gui_os_install_net_domain"] = m_Config["os_install_net_domain"];
m_Config["gui_os_install_clock_timezone"] = m_Config["os_install_clock_timezone"];
m_Config["gui_os_install_x11_video_drv"] = m_Config["os_install_x11_video_drv"];
m_Config["gui_os_install_x11_composite"] = m_Config["os_install_x11_composite"];
m_Config["gui_os_install_autologin"] = m_Config["os_install_autologin"];
m_Config["gui_os_install_makeopts"] = m_Config["os_install_makeopts"];
m_Config["gui_os_install_proxy"] = m_Config["os_install_proxy"];
m_Config["gui_os_install_ntp"] = m_Config["os_install_ntp"];
m_Config["gui_os_install_clock_type"] = m_Config["os_install_clock_type"];
m_Config["def_os_install_disk_format"] = m_Config["os_install_disk_format"];
m_Config["def_os_install_disk_mount"] = m_Config["os_install_disk_mount"];
m_Config["def_os_install_disk_perform_format"] = m_Config["os_install_disk_perform_format"];
m_Config["def_cl_migrate_user"] = m_Config["cl_migrate_user"];
qDebug() << endl << "Start variables: ";
MapConfig::ConstIterator cfgIt = m_Config.constBegin();
while(cfgIt != m_Config.constEnd())
{
qDebug() <<
cfgIt.key() +
" = " +
(( QString(cfgIt.value().typeName()) == "QStringList") ?
("[" + cfgIt.value().toStringList().join(", ") + "]") :
( cfgIt.value().toString() ) );
++cfgIt;
}
return true;
}
示例5: writeXML
void QgsDiagramSettings::writeXML( QDomElement& rendererElem, QDomDocument& doc ) const
{
QDomElement categoryElem = doc.createElement( "DiagramCategory" );
categoryElem.setAttribute( "font", font.toString() );
categoryElem.setAttribute( "backgroundColor", backgroundColor.name() );
categoryElem.setAttribute( "backgroundAlpha", backgroundColor.alpha() );
categoryElem.setAttribute( "width", QString::number( size.width() ) );
categoryElem.setAttribute( "height", QString::number( size.height() ) );
categoryElem.setAttribute( "penColor", penColor.name() );
categoryElem.setAttribute( "penAlpha", penColor.alpha() );
categoryElem.setAttribute( "penWidth", QString::number( penWidth ) );
categoryElem.setAttribute( "minScaleDenominator", QString::number( minScaleDenominator ) );
categoryElem.setAttribute( "maxScaleDenominator", QString::number( maxScaleDenominator ) );
categoryElem.setAttribute( "transparency", QString::number( transparency ) );
// site type (mm vs. map units)
if ( sizeType == MM )
{
categoryElem.setAttribute( "sizeType", "MM" );
}
else
{
categoryElem.setAttribute( "sizeType", "MapUnits" );
}
// label placement method (text diagram)
if ( labelPlacementMethod == Height )
{
categoryElem.setAttribute( "labelPlacementMethod", "Height" );
}
else
{
categoryElem.setAttribute( "labelPlacementMethod", "XHeight" );
}
if ( scaleByArea )
{
categoryElem.setAttribute( "scaleDependency", "Area" );
}
else
{
categoryElem.setAttribute( "scaleDependency", "Diameter" );
}
// orientation (histogram)
switch ( diagramOrientation )
{
case Left:
categoryElem.setAttribute( "diagramOrientation", "Left" );
break;
case Right:
categoryElem.setAttribute( "diagramOrientation", "Right" );
break;
case Down:
categoryElem.setAttribute( "diagramOrientation", "Down" );
break;
case Up:
categoryElem.setAttribute( "diagramOrientation", "Up" );
break;
default:
categoryElem.setAttribute( "diagramOrientation", "Up" );
break;
}
categoryElem.setAttribute( "barWidth", QString::number( barWidth ) );
categoryElem.setAttribute( "minimumSize", QString::number( minimumSize ) );
categoryElem.setAttribute( "angleOffset", QString::number( angleOffset ) );
QString colors;
for ( int i = 0; i < categoryColors.size(); ++i )
{
if ( i > 0 )
{
colors.append( "/" );
}
colors.append( categoryColors.at( i ).name() );
}
categoryElem.setAttribute( "colors", colors );
QString categories;
for ( int i = 0; i < categoryIndices.size(); ++i )
{
if ( i > 0 )
{
categories.append( "/" );
}
categories.append( QString::number( categoryIndices.at( i ) ) );
}
categoryElem.setAttribute( "categories", categories );
rendererElem.appendChild( categoryElem );
}
示例6: variantToDomElement
QDomElement variantToDomElement (const QVariant &v, QDomDocument &root)
{
QString result;
QString type = QLatin1String("string");
QDomElement element;
switch (v.type()) {
case QVariant::StringList:
case QVariant::List:
case QVariant::Map: {
return element;
}
case QVariant::Invalid:
result = QLatin1String("@Invalid()");
break;
case QVariant::ByteArray: {
QByteArray a = v.toByteArray();
result = a.toBase64();
type = QLatin1String("data");
break;
}
case QVariant::String: {
result = v.toString();
break;
}
case QVariant::LongLong:
case QVariant::ULongLong:
case QVariant::Int:
case QVariant::UInt: {
result = v.toString();
type = QLatin1String("integer");
break;
}
case QVariant::Bool: {
element = root.createElement(v.toString());
return element;
}
case QVariant::Double: {
result = v.toString();
type = QLatin1String("real");
break;
}
case QVariant::KeySequence: {
result = v.toString();
if (result.startsWith(QLatin1Char('@')))
result.prepend(QLatin1Char('@'));
break;
}
case QVariant::Rect: {
QRect r = qvariant_cast<QRect>(v);
result += QLatin1String("@Rect(");
result += QString::number(r.x());
result += QLatin1Char(' ');
result += QString::number(r.y());
result += QLatin1Char(' ');
result += QString::number(r.width());
result += QLatin1Char(' ');
result += QString::number(r.height());
result += QLatin1Char(')');
break;
}
case QVariant::Size: {
QSize s = qvariant_cast<QSize>(v);
result += QLatin1String("@Size(");
result += QString::number(s.width());
result += QLatin1Char(' ');
result += QString::number(s.height());
result += QLatin1Char(')');
break;
}
case QVariant::Point: {
QPoint p = qvariant_cast<QPoint>(v);
result += QLatin1String("@Point(");
result += QString::number(p.x());
result += QLatin1Char(' ');
result += QString::number(p.y());
result += QLatin1Char(')');
break;
}
default: {
QByteArray a;
{
QDataStream s(&a, QIODevice::WriteOnly);
s.setVersion(QDataStream::Qt_4_0);
s << v;
}
result = QLatin1String("@Variant(");
result += QString::fromLatin1(a.constData(), a.size());
result += QLatin1Char(')');
break;
}
}
element = root.createElement(type);
element.appendChild(root.createTextNode(result));
return element;
}
示例7: saveNamedStyle
QString QgsMapLayer::saveNamedStyle( const QString theURI, bool & theResultFlag )
{
QString myErrorMessage;
QDomDocument myDocument;
exportNamedStyle( myDocument, myErrorMessage );
// check if the uri is a file or ends with .qml,
// which indicates that it should become one
// everything else goes to the database
QString filename;
QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( this );
if ( vlayer && vlayer->providerType() == "ogr" )
{
QStringList theURIParts = theURI.split( "|" );
filename = theURIParts[0];
}
else if ( vlayer && vlayer->providerType() == "delimitedtext" )
{
filename = QUrl::fromEncoded( theURI.toAscii() ).toLocalFile();
}
else
{
filename = theURI;
}
QFileInfo myFileInfo( filename );
if ( myFileInfo.exists() || filename.endsWith( ".qml", Qt::CaseInsensitive ) )
{
QFileInfo myDirInfo( myFileInfo.path() ); //excludes file name
if ( !myDirInfo.isWritable() )
{
return tr( "The directory containing your dataset needs to be writable!" );
}
// now construct the file name for our .qml style file
QString myFileName = myFileInfo.path() + QDir::separator() + myFileInfo.completeBaseName() + ".qml";
QFile myFile( myFileName );
if ( myFile.open( QFile::WriteOnly | QFile::Truncate ) )
{
QTextStream myFileStream( &myFile );
// save as utf-8 with 2 spaces for indents
myDocument.save( myFileStream, 2 );
myFile.close();
theResultFlag = true;
return tr( "Created default style file as %1" ).arg( myFileName );
}
else
{
theResultFlag = false;
return tr( "ERROR: Failed to created default style file as %1. Check file permissions and retry." ).arg( myFileName );
}
}
else
{
QString qml = myDocument.toString();
// read from database
sqlite3 *myDatabase;
sqlite3_stmt *myPreparedStatement;
const char *myTail;
int myResult;
myResult = sqlite3_open( QDir( QgsApplication::qgisSettingsDirPath() ).absoluteFilePath( "qgis.qmldb" ).toUtf8().data(), &myDatabase );
if ( myResult != SQLITE_OK )
{
return tr( "User database could not be opened." );
}
QByteArray param0 = theURI.toUtf8();
QByteArray param1 = qml.toUtf8();
QString mySql = "create table if not exists tbl_styles(style varchar primary key,qml varchar)";
myResult = sqlite3_prepare( myDatabase, mySql.toUtf8().data(), mySql.toUtf8().length(), &myPreparedStatement, &myTail );
if ( myResult == SQLITE_OK )
{
if ( sqlite3_step( myPreparedStatement ) != SQLITE_DONE )
{
sqlite3_finalize( myPreparedStatement );
sqlite3_close( myDatabase );
theResultFlag = false;
return tr( "The style table could not be created." );
}
}
sqlite3_finalize( myPreparedStatement );
mySql = "insert into tbl_styles(style,qml) values (?,?)";
myResult = sqlite3_prepare( myDatabase, mySql.toUtf8().data(), mySql.toUtf8().length(), &myPreparedStatement, &myTail );
if ( myResult == SQLITE_OK )
{
if ( sqlite3_bind_text( myPreparedStatement, 1, param0.data(), param0.length(), SQLITE_STATIC ) == SQLITE_OK &&
sqlite3_bind_text( myPreparedStatement, 2, param1.data(), param1.length(), SQLITE_STATIC ) == SQLITE_OK &&
sqlite3_step( myPreparedStatement ) == SQLITE_DONE )
{
theResultFlag = true;
myErrorMessage = tr( "The style %1 was saved to database" ).arg( theURI );
}
}
//.........这里部分代码省略.........
示例8: LOG
MetadataLookupList MetadataDownload::readMXML(QString MXMLpath,
MetadataLookup* lookup,
bool passseas)
{
MetadataLookupList list;
LOG(VB_GENERAL, LOG_INFO,
QString("Matching MXML file found. Parsing %1 for metadata...")
.arg(MXMLpath));
if (lookup->GetType() == kMetadataVideo)
{
QByteArray mxmlraw;
QDomElement item;
if (MXMLpath.startsWith("myth://"))
{
RemoteFile *rf = new RemoteFile(MXMLpath);
if (rf && rf->Open())
{
bool loaded = rf->SaveAs(mxmlraw);
if (loaded)
{
QDomDocument doc;
if (doc.setContent(mxmlraw, true))
{
lookup->SetStep(kLookupData);
QDomElement root = doc.documentElement();
item = root.firstChildElement("item");
}
else
LOG(VB_GENERAL, LOG_ERR,
QString("Corrupt or invalid MXML file."));
}
rf->Close();
}
delete rf;
rf = NULL;
}
else
{
QFile file(MXMLpath);
if (file.open(QIODevice::ReadOnly))
{
mxmlraw = file.readAll();
QDomDocument doc;
if (doc.setContent(mxmlraw, true))
{
lookup->SetStep(kLookupData);
QDomElement root = doc.documentElement();
item = root.firstChildElement("item");
}
else
LOG(VB_GENERAL, LOG_ERR,
QString("Corrupt or invalid MXML file."));
file.close();
}
}
MetadataLookup *tmp = ParseMetadataItem(item, lookup, passseas);
list.append(tmp);
}
return list;
}
示例9: result
QDomElement SmartPlaylistEditor::result() {
QDomDocument doc;
QDomNode node = doc.namedItem( "smartplaylists" );
QDomElement nodeE;
nodeE = node.toElement();
QDomElement smartplaylist = doc.createElement( "smartplaylist" );
smartplaylist.setAttribute( "name", name() );
// Limit
if ( m_limitCheck->isChecked() )
smartplaylist.setAttribute( "maxresults", m_limitSpin->value() );
nodeE.appendChild( smartplaylist );
// Matches
if( m_matchAnyCheck->isChecked() ) {
QDomElement matches = doc.createElement("matches");
smartplaylist.appendChild( matches );
// Iterate through all criteria list
CriteriaEditor *criteriaeditor = m_criteriaEditorAnyList.first();
for( int i=0; criteriaeditor; criteriaeditor = m_criteriaEditorAnyList.next(), ++i ) {
matches.appendChild( doc.importNode( criteriaeditor->getDomSearchCriteria( doc ), true ) );
}
matches.setAttribute( "glue", "OR" );
smartplaylist.appendChild( matches );
}
if( m_matchAllCheck->isChecked() ) {
QDomElement matches = doc.createElement("matches");
smartplaylist.appendChild( matches );
// Iterate through all criteria list
CriteriaEditor *criteriaeditor = m_criteriaEditorAllList.first();
for( int i=0; criteriaeditor; criteriaeditor = m_criteriaEditorAllList.next(), ++i ) {
matches.appendChild( doc.importNode( criteriaeditor->getDomSearchCriteria( doc ), true ) );
}
matches.setAttribute( "glue", "AND" );
smartplaylist.appendChild( matches );
}
// Order By
if( m_orderCheck->isChecked() ) {
QDomElement orderby = doc.createElement("orderby");
if (m_orderCombo->currentItem() != m_orderCombo->count()-1) {
orderby.setAttribute( "field", m_dbFields[ m_orderCombo->currentItem() ] );
orderby.setAttribute( "order", m_orderTypeCombo->currentItem() == 1 ? "DESC" : "ASC" );
} else {
orderby.setAttribute( "field", "random" );
orderby.setAttribute( "order", m_orderTypeCombo->currentItem() == 1 ? "weighted" : "random" );
}
smartplaylist.appendChild( orderby );
}
QDomElement Sql = doc.createElement("sqlquery");
buildQuery();
Sql.appendChild( doc.createTextNode( m_query ) );
smartplaylist.appendChild( Sql );
if( m_expandCheck->isChecked() ) {
QDomElement expandBy = doc.createElement("expandby");
expandBy.setAttribute( "field", m_expandableFields[ m_expandCombo->currentItem() ] );
QDomText t = doc.createTextNode( m_expandQuery );
expandBy.appendChild( t );
smartplaylist.appendChild( expandBy );
}
return (smartplaylist);
}
示例10: writeLayerXML
bool QgsMapLayer::writeLayerXML( QDomElement& layerElement, QDomDocument& document )
{
// use scale dependent visibility flag
layerElement.setAttribute( "hasScaleBasedVisibilityFlag", hasScaleBasedVisibility() ? 1 : 0 );
layerElement.setAttribute( "minimumScale", QString::number( minimumScale() ) );
layerElement.setAttribute( "maximumScale", QString::number( maximumScale() ) );
// ID
QDomElement layerId = document.createElement( "id" );
QDomText layerIdText = document.createTextNode( id() );
layerId.appendChild( layerIdText );
layerElement.appendChild( layerId );
// data source
QDomElement dataSource = document.createElement( "datasource" );
QString src = source();
QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( this );
// TODO: what about postgres, mysql and others, they should not go through writePath()
if ( vlayer && vlayer->providerType() == "spatialite" )
{
QgsDataSourceURI uri( src );
QString database = QgsProject::instance()->writePath( uri.database() );
uri.setConnection( uri.host(), uri.port(), database, uri.username(), uri.password() );
src = uri.uri();
}
else if ( vlayer && vlayer->providerType() == "ogr" )
{
QStringList theURIParts = src.split( "|" );
theURIParts[0] = QgsProject::instance()->writePath( theURIParts[0] );
src = theURIParts.join( "|" );
}
else if ( vlayer && vlayer->providerType() == "delimitedtext" )
{
QUrl urlSource = QUrl::fromEncoded( src.toAscii() );
QUrl urlDest = QUrl::fromLocalFile( QgsProject::instance()->writePath( urlSource.toLocalFile() ) );
urlDest.setQueryItems( urlSource.queryItems() );
src = QString::fromAscii( urlDest.toEncoded() );
}
else
{
src = QgsProject::instance()->writePath( src );
}
QDomText dataSourceText = document.createTextNode( src );
dataSource.appendChild( dataSourceText );
layerElement.appendChild( dataSource );
// layer name
QDomElement layerName = document.createElement( "layername" );
QDomText layerNameText = document.createTextNode( originalName() );
layerName.appendChild( layerNameText );
// layer title
QDomElement layerTitle = document.createElement( "title" ) ;
QDomText layerTitleText = document.createTextNode( title() );
layerTitle.appendChild( layerTitleText );
// layer abstract
QDomElement layerAbstract = document.createElement( "abstract" );
QDomText layerAbstractText = document.createTextNode( abstract() );
layerAbstract.appendChild( layerAbstractText );
layerElement.appendChild( layerName );
layerElement.appendChild( layerTitle );
layerElement.appendChild( layerAbstract );
// layer keyword list
QStringList keywordStringList = keywordList().split( "," );
if ( keywordStringList.size() > 0 )
{
QDomElement layerKeywordList = document.createElement( "keywordList" );
for ( int i = 0; i < keywordStringList.size(); ++i )
{
QDomElement layerKeywordValue = document.createElement( "value" );
QDomText layerKeywordText = document.createTextNode( keywordStringList.at( i ).trimmed() );
layerKeywordValue.appendChild( layerKeywordText );
layerKeywordList.appendChild( layerKeywordValue );
}
layerElement.appendChild( layerKeywordList );
}
// layer metadataUrl
QString aDataUrl = dataUrl();
if ( !aDataUrl.isEmpty() )
{
QDomElement layerDataUrl = document.createElement( "dataUrl" ) ;
QDomText layerDataUrlText = document.createTextNode( aDataUrl );
layerDataUrl.appendChild( layerDataUrlText );
layerDataUrl.setAttribute( "format", dataUrlFormat() );
layerElement.appendChild( layerDataUrl );
}
// layer attribution
QString aAttribution = attribution();
if ( !aAttribution.isEmpty() )
//.........这里部分代码省略.........
示例11: moveAppData
/**
* @brief Load contents of the settings file
* @param string _filename
* @return bool
*/
bool Settings::load(QString _filename)
{
if (_filename.isEmpty())
{
if (!m_enviro->isPortable() && !QFile(Environment::APPDATA_DIR + APP_CONFIG_FILE).exists() && QFile(APP_CONFIG_FILE).exists())
{
moveAppData();
}
_filename = Environment::APPDATA_DIR + APP_CONFIG_FILE;
}
// open xml file
QFile file(_filename);
if (!file.exists() || !file.open(QIODevice::ReadOnly))
{
QLOG_ERROR() << "Unable to load config file";
return false;
}
// initialize domdocument
QDomDocument dom;
if (!dom.setContent(file.readAll()))
{
QLOG_ERROR() << "Unable to load config file";
return false;
}
file.close();
clearSets();
// read settings node
QDomElement settingsNode = dom.documentElement().firstChild().toElement();
int newHotkey = 0;
UM::MODE newMode = UM::MODE_NONE;
bool updated = false;
while (!settingsNode.isNull())
{
// config node
if (settingsNode.tagName() == "config")
{
QDomElement configNode = settingsNode.firstChild().toElement();
while (!configNode.isNull())
{
// migration to 1.3
if (configNode.tagName() == "hotkey")
{
newHotkey = configNode.text().toInt();
}
// migration to 1.9
else if (configNode.tagName() == "mode")
{
newMode = configNode.text() == "random" ? UM::MODE_RANDOM : UM::MODE_SEQUENTIAL;
}
else if (m_options.contains(configNode.tagName()))
{
m_options[ configNode.tagName() ] = configNode.text();
}
configNode = configNode.nextSibling().toElement();
}
}
else if (settingsNode.tagName() == "hotkeys")
{
QDomElement hotkeyNode = settingsNode.firstChild().toElement();
while (!hotkeyNode.isNull())
{
// 1.3 format
if (hotkeyNode.hasAttribute("key"))
{
m_hotkeys[ hotkeyNode.tagName() ] =
hotkeyNode.attribute("key").toInt() +
hotkeyNode.attribute("mod").toInt();
updated = true;
}
// 1.4 format
else
{
// stored in string representation since 2.2.1
bool isInt;
m_hotkeys[ hotkeyNode.tagName() ] = hotkeyNode.text().toInt(&isInt);
if (!isInt)
{
m_hotkeys[ hotkeyNode.tagName() ] = UM::keySequenceToInt(QKeySequence(hotkeyNode.text()));
}
}
hotkeyNode = hotkeyNode.nextSibling().toElement();
//.........这里部分代码省略.........
示例12: QUrl
bool AccessCert::download( bool noCard )
{
if( noCard )
{
QDesktopServices::openUrl( QUrl( "http://www.sk.ee/toend/" ) );
return false;
}
QMessageBox d( QMessageBox::Information, tr("Server access certificate"),
tr("Hereby I agree to terms and conditions of validity confirmation service and "
"will use the service in extent of 10 signatures per month. If you going to "
"exceed the limit of 10 signatures per month or/and will use the service for "
"commercial purposes, please refer to IT support of your company. Additional "
"information is available from <a href=\"http://www.sk.ee/kehtivuskinnitus\">"
"http://www.sk.ee/kehtivuskinnitus</a> or phone 1777"),
QMessageBox::Help, m_parent );
d.addButton( tr("Agree"), QMessageBox::AcceptRole );
if( QLabel *label = d.findChild<QLabel*>() )
label->setOpenExternalLinks( true );
if( d.exec() == QMessageBox::Help )
{
QDesktopServices::openUrl( QUrl( "http://www.sk.ee/kehtivuskinnitus" ) );
return false;
}
qApp->signer()->lock();
QScopedPointer<SSLConnect> ssl( new SSLConnect() );
ssl->setPKCS11( Application::confValue( Application::PKCS11Module ), false );
ssl->setCard( qApp->signer()->token().card() );
bool retry = false;
do
{
retry = false;
if( ssl->flags() & TokenData::PinLocked )
{
showWarning( tr("Error downloading server access certificate!\nPIN1 is blocked" ) );
qApp->signer()->unlock();
return false;
}
ssl->waitForFinished( SSLConnect::AccessCert );
switch( ssl->error() )
{
case SSLConnect::PinCanceledError:
qApp->signer()->unlock();
return false;
case SSLConnect::PinInvalidError:
showWarning( ssl->errorString() );
retry = true;
break;
default:
if( !ssl->errorString().isEmpty() )
{
showWarning( tr("Error downloading server access certificate!\n%1").arg( ssl->errorString() ) );
qApp->signer()->unlock();
return false;
}
break;
}
}
while( retry );
QByteArray result = ssl->result();
qApp->signer()->unlock();
if( result.isEmpty() )
{
showWarning( tr("Empty result!") );
return false;
}
QDomDocument domDoc;
if( !domDoc.setContent( QString::fromUtf8( result ) ) )
{
showWarning( tr("Error parsing server access certificate result!") );
return false;
}
QDomElement e = domDoc.documentElement();
QDomNodeList status = e.elementsByTagName( "StatusCode" );
if( status.isEmpty() )
{
showWarning( tr("Error parsing server access certificate result!") );
return false;
}
switch( status.item(0).toElement().text().toInt() )
{
case 1: //need to order cert manually from SK web
QDesktopServices::openUrl( QUrl( "http://www.sk.ee/toend/" ) );
return false;
case 2: //got error, show message from MessageToDisplay element
showWarning( tr("Error downloading server access certificate!\n%1")
.arg( e.elementsByTagName( "MessageToDisplay" ).item(0).toElement().text() ) );
return false;
default: break; //ok
}
QString cert = e.elementsByTagName( "TokenData" ).item(0).toElement().text();
if ( cert.isEmpty() )
//.........这里部分代码省略.........
示例13: QString
//.........这里部分代码省略.........
questions.append (question);
}
elem.setAttribute ("ljPollQuestions", QString (questions.toUtf8 ().toBase64 ()));
while (!children.isEmpty ())
elem.removeChild (children.at (0));
auto textElem = elem.ownerDocument ().createTextNode (tr ("Poll: %1").arg (name));
elem.appendChild (textElem);
};
ljPollTag.FromKnown_ = [] (QDomElement& elem) -> bool
{
if (!elem.hasAttribute ("id") ||
elem.attribute ("id") != "pollDiv")
return false;
auto whoView = elem.attribute ("ljPollWhoview");
auto whoVote = elem.attribute ("ljPollWhovote");
auto name = elem.attribute ("ljPollName");
auto questions = QByteArray::fromBase64 (elem.attribute ("ljPollQuestions").toUtf8 ());
elem.removeAttribute ("style");
elem.removeAttribute ("ljPollWhoview");
elem.removeAttribute ("ljPollWhovot");
elem.removeAttribute ("ljPollName");
elem.removeAttribute ("ljPollQuestions");
elem.removeAttribute ("id");
elem.removeChild (elem.firstChild ());
elem.setTagName ("lj-poll");
elem.setAttribute ("whoview", whoView);
elem.setAttribute ("whovote", whoVote);
elem.setAttribute ("name", name);
QDomDocument doc;
doc.setContent (questions);
elem.appendChild (doc.documentElement ());
return true;
};
tags << ljPollTag;
IAdvancedHTMLEditor::CustomTag ljEmbedTag;
ljEmbedTag.TagName_ = "lj-embed";
ljEmbedTag.ToKnown_ = [this] (QDomElement& elem) -> void
{
const auto& id = elem.attribute ("id");
elem.removeAttribute ("id");
elem.setTagName ("div");
elem.setAttribute ("style", "overflow:auto;border-width:2px;border-style:solid;border-radius:5px;margin-left:3em;padding:2em 2em;");
elem.setAttribute ("id", "embedTag");
elem.setAttribute ("name", id);
auto textElem = elem.ownerDocument ().createTextNode (tr ("Embedded: %1")
.arg (id));
elem.appendChild (textElem);
};
ljEmbedTag.FromKnown_ = [] (QDomElement& elem) -> bool
{
if (!elem.hasAttribute ("id") ||
elem.attribute ("id") != "embedTag")
return false;
elem.removeAttribute ("style");
elem.removeChild (elem.firstChild ());
const auto& id = elem.attribute ("name");
示例14: file
bool FormularEditor::readFromFile(QString fileName) {
QString errorString;
int errorLine;
int errorColumn;
QFile file(fileName);
QDomDocument domDocument;
if(!file.open(QIODevice::ReadOnly))
return false;
if(!domDocument.setContent(&file, true, &errorString, &errorLine, &errorColumn)) {
qWarning() << "Line " << errorLine << "colunm " << errorColumn << " message ";
return false;
}
QDomElement domRoot = domDocument.documentElement();
qDebug() << "[Formular editor] Read from file: Root tag name" << domRoot.tagName();
if(domRoot.tagName() != "formular") {
qCritical() << "[Formular editor] Read from file: Bad file, incorrect root tag name";
return false;
}
QString inputCheck;
const uint defaultCapacity = 8;
inputCheck = domRoot.attribute("capacity", "_err_");
if(inputCheck == "_err_") {
qWarning() << "[Formular editor] Read from file: No \"capacity\" attribute. Set default" << defaultCapacity;
inputCheck = QString::number(defaultCapacity);
}
if(inputCheck.toInt()%8) {
qWarning() << "[Formular editor] Read from file: Bad \"capacity\" attribute. Set default" << defaultCapacity;
inputCheck = QString::number(defaultCapacity);
}
ui->capacityBox->setCurrentIndex(Formular::capacities.indexOf(inputCheck));
inputCheck = domRoot.attribute("description", "_err_");
if(inputCheck == "_err_")
{
qWarning() << "[Formular editor] Read from file: No \"description\" attribute. Set empty string";
inputCheck = "";
}
ui->descriptionEdit->setText(inputCheck);
QDomElement domField = domRoot.firstChildElement();
while(!domField.isNull()) {
inputCheck = domField.attribute("name", "_err_");
if(inputCheck == "_err_") {
qWarning() << "[Formular editor] Read from file: No \"name\" attribute. Set empty string";
inputCheck = "";
}
QString name = inputCheck;
inputCheck = domField.attribute("description", "_err_");
if(inputCheck == "_err_") {
qWarning() << "[Formular editor] Read from file: No \"description\" attribute. Set empty string";
inputCheck = "";
}
QString description = inputCheck;
const uint defaultFieldSize = 1;
inputCheck = domField.attribute("size", "_err_");
if(inputCheck == "_err_") {
qWarning() << "[Formular editor] Read from file: No \"size\" attribute. Set default" << defaultFieldSize;
inputCheck = QString::number(defaultFieldSize);
}
if(inputCheck.toInt() <= 0) {
qWarning() << "[Formular editor] Read from file: Bad \"size\" attribute. Set default" << defaultFieldSize;
inputCheck = QString::number(defaultFieldSize);
}
int size = inputCheck.toInt();
const FieldData::Dimension defaultFieldDimension = FieldData::No;
inputCheck = domField.attribute("dimension", "_err_");
if(inputCheck == "_err_") {
qWarning() << "[Formular editor] Read from file: No \"dimension\" attribute. Set default" << FieldData::dimensions.at(defaultFieldDimension);
inputCheck = FieldData::dimensions.at(defaultFieldDimension);
}
if(FieldData::dimensions.indexOf(inputCheck) == -1) {
qWarning() << "[Formular editor] Read from file: Bad \"dimension\" attribute. Set default" << FieldData::dimensions.at(defaultFieldDimension);
inputCheck = FieldData::dimensions.at(defaultFieldDimension);
}
FieldData::Dimension dimension = (FieldData::Dimension)FieldData::dimensions.indexOf(inputCheck);
const FieldData::Type defaultFieldType = FieldData::Integer;
inputCheck = domField.attribute("type", "_err_");
if(inputCheck == "_err_") {
qWarning() << "[Formular editor] Read from file: No \"type\" attribute. Set default" << FieldData::types.at(defaultFieldType);
inputCheck = FieldData::types.at(defaultFieldType);
}
if(FieldData::types.indexOf(inputCheck) == -1) {
qWarning() << "[Formular editor] Read from file: Bad \"type\" attribute. Set default" << FieldData::types.at(defaultFieldType);
inputCheck = FieldData::types.at(defaultFieldType);
}
FieldData::Type type = (FieldData::Type)FieldData::types.indexOf(inputCheck);
switch(type) {
case FieldData::Integer:
case FieldData::Real:
case FieldData::Boolean:
//.........这里部分代码省略.........
示例15: onNetworkReply
void WAccount::onNetworkReply(QNetworkReply *reply)
{
reply->deleteLater();
WContact *contact = qobject_cast<WContact*>(reply->request().originatingObject());
if (!contact)
return;
QDomDocument doc;
if (!doc.setContent(reply->readAll()))
return;
bool needMessage = reply->property("needMessage").toBool();
QDomElement rootElement = doc.documentElement();
QDomElement units = rootElement.namedItem(QLatin1String("units")).toElement();
QString tempUnit = units.namedItem(QLatin1String("temp")).toElement().text();
QDomElement local = rootElement.namedItem(QLatin1String("local")).toElement();
QString cityName = local.namedItem(QLatin1String("city")).toElement().text();
contact->setNameInternal(cityName);
QDomElement current = rootElement.namedItem(QLatin1String("current")).toElement();
if (!current.isNull()) {
QString temperature = current.namedItem(QLatin1String("temperature")).toElement().text();
QString iconId = current.namedItem(QLatin1String("weathericon")).toElement().text();
QString text = tr("Weather: %1°%2").arg(temperature, tempUnit);
contact->setStatusInternal(iconId, text);
if (needMessage) {
QString text = loadResourceFile(QLatin1String("Current.txt"));
QString html = loadResourceFile(QLatin1String("Current.html"));
fillStrings(text, html, units, QLatin1String("%units"));
fillStrings(text, html, current, QLatin1String("%"));
Message message(text);
message.setHtml(html);
message.setChatUnit(contact);
message.setIncoming(true);
message.setTime(QDateTime::currentDateTime());
ChatLayer::get(contact, true)->appendMessage(message);
}
}
QDomElement forecast = rootElement.namedItem(QLatin1String("forecast")).toElement();
if (needMessage && !forecast.isNull()) {
QString textResult = loadResourceFile(QLatin1String("ForecastTitle.txt"));
QString htmlResult = loadResourceFile(QLatin1String("ForecastTitle.html"));
QString textBody = loadResourceFile(QLatin1String("ForecastDay.txt"));
QString htmlBody = loadResourceFile(QLatin1String("ForecastDay.html"));
fillStrings(textBody, htmlBody, units, QLatin1String("%units"));
QDomNodeList days = forecast.elementsByTagName(QLatin1String("day"));
for (int i = 0; i < days.count(); ++i) {
if (!days.at(i).isElement())
continue;
QDomElement day = days.at(i).toElement();
QString text = textBody;
QString html = htmlBody;
fillStrings(text, html, day, QLatin1String("%"));
textResult += text;
htmlResult += html;
}
Message message(textResult);
message.setHtml(htmlResult);
message.setChatUnit(contact);
message.setIncoming(true);
message.setTime(QDateTime::currentDateTime());
ChatLayer::get(contact, true)->appendMessage(message);
}
}