本文整理汇总了C++中QDomImplementation::setInvalidDataPolicy方法的典型用法代码示例。如果您正苦于以下问题:C++ QDomImplementation::setInvalidDataPolicy方法的具体用法?C++ QDomImplementation::setInvalidDataPolicy怎么用?C++ QDomImplementation::setInvalidDataPolicy使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QDomImplementation
的用法示例。
在下文中一共展示了QDomImplementation::setInvalidDataPolicy方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: write
bool QgsProject::write()
{
clearError();
// if we have problems creating or otherwise writing to the project file,
// let's find out up front before we go through all the hand-waving
// necessary to create all the Dom objects
if ( !imp_->file.open( QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate ) )
{
imp_->file.close(); // even though we got an error, let's make
// sure it's closed anyway
setError( tr( "Unable to save to file %1" ).arg( imp_->file.fileName() ) );
return false;
}
QFileInfo myFileInfo( imp_->file );
if ( !myFileInfo.isWritable() )
{
// even though we got an error, let's make
// sure it's closed anyway
imp_->file.close();
setError( tr( "%1 is not writable. Please adjust permissions (if possible) and try again." )
.arg( imp_->file.fileName() ) );
return false;
}
QDomImplementation DomImplementation;
DomImplementation.setInvalidDataPolicy( QDomImplementation::DropInvalidChars );
QDomDocumentType documentType =
DomImplementation.createDocumentType( "qgis", "http://mrcc.com/qgis.dtd",
"SYSTEM" );
std::auto_ptr < QDomDocument > doc =
std::auto_ptr < QDomDocument > ( new QDomDocument( documentType ) );
QDomElement qgisNode = doc->createElement( "qgis" );
qgisNode.setAttribute( "projectname", title() );
qgisNode.setAttribute( "version", QString( "%1" ).arg( QGis::QGIS_VERSION ) );
doc->appendChild( qgisNode );
// title
QDomElement titleNode = doc->createElement( "title" );
qgisNode.appendChild( titleNode );
QDomText titleText = doc->createTextNode( title() ); // XXX why have title TWICE?
titleNode.appendChild( titleText );
// let map canvas and legend write their information
emit writeProject( *doc );
// within top level node save list of layers
QMap<QString, QgsMapLayer*> & layers = QgsMapLayerRegistry::instance()->mapLayers();
// Iterate over layers in zOrder
// Call writeXML() on each
QDomElement projectLayersNode = doc->createElement( "projectlayers" );
projectLayersNode.setAttribute( "layercount", qulonglong( layers.size() ) );
QMap<QString, QgsMapLayer*>::iterator li = layers.begin();
while ( li != layers.end() )
{
//QgsMapLayer *ml = QgsMapLayerRegistry::instance()->mapLayer(*li);
QgsMapLayer* ml = li.value();
if ( ml )
{
QString externalProjectFile = layerIsEmbedded( ml->id() );
QHash< QString, QPair< QString, bool> >::const_iterator emIt = mEmbeddedLayers.find( ml->id() );
if ( emIt == mEmbeddedLayers.constEnd() )
{
// general layer metadata
QDomElement maplayerElem = doc->createElement( "maplayer" );
ml->writeLayerXML( maplayerElem, *doc );
emit writeMapLayer( ml, maplayerElem, *doc );
projectLayersNode.appendChild( maplayerElem );
}
else //layer defined in an external project file
{
//only save embedded layer if not managed by a legend group
if ( emIt.value().second )
{
QDomElement mapLayerElem = doc->createElement( "maplayer" );
mapLayerElem.setAttribute( "embedded", 1 );
mapLayerElem.setAttribute( "project", writePath( emIt.value().first ) );
mapLayerElem.setAttribute( "id", ml->id() );
projectLayersNode.appendChild( mapLayerElem );
}
}
}
li++;
}
qgisNode.appendChild( projectLayersNode );
// now add the optional extra properties
//.........这里部分代码省略.........
示例2: setInvalidDataPolicy
void QDomImplementationProto::setInvalidDataPolicy(int policy)
{
QDomImplementation *item = qscriptvalue_cast<QDomImplementation*>(thisObject());
if (item)
item->setInvalidDataPolicy((QDomImplementation::InvalidDataPolicy)policy);
}