本文整理汇总了C++中QDomNode::toElement方法的典型用法代码示例。如果您正苦于以下问题:C++ QDomNode::toElement方法的具体用法?C++ QDomNode::toElement怎么用?C++ QDomNode::toElement使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QDomNode
的用法示例。
在下文中一共展示了QDomNode::toElement方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: QStringLiteral
void QgsProjectFileTransform::transform0110to1000()
{
if ( ! mDom.isNull() )
{
QDomNodeList layerList = mDom.elementsByTagName( QStringLiteral( "maplayer" ) );
for ( int i = 0; i < layerList.size(); ++i )
{
QDomElement layerElem = layerList.at( i ).toElement();
QString typeString = layerElem.attribute( QStringLiteral( "type" ) );
if ( typeString != QLatin1String( "vector" ) )
{
continue;
}
//datasource
QDomNode dataSourceNode = layerElem.namedItem( QStringLiteral( "datasource" ) );
if ( dataSourceNode.isNull() )
{
return;
}
QString dataSource = dataSourceNode.toElement().text();
//provider key
QDomNode providerNode = layerElem.namedItem( QStringLiteral( "provider" ) );
if ( providerNode.isNull() )
{
return;
}
QString providerKey = providerNode.toElement().text();
//create the layer to get the provider for int->fieldName conversion
QgsVectorLayer* theLayer = new QgsVectorLayer( dataSource, QLatin1String( "" ), providerKey, false );
if ( !theLayer->isValid() )
{
delete theLayer;
return;
}
QgsVectorDataProvider* theProvider = theLayer->dataProvider();
if ( !theProvider )
{
return;
}
QgsFields theFields = theProvider->fields();
//read classificationfield
QDomNodeList classificationFieldList = layerElem.elementsByTagName( QStringLiteral( "classificationfield" ) );
for ( int j = 0; j < classificationFieldList.size(); ++j )
{
QDomElement classificationFieldElem = classificationFieldList.at( j ).toElement();
int fieldNumber = classificationFieldElem.text().toInt();
if ( fieldNumber >= 0 && fieldNumber < theFields.count() )
{
QDomText fieldName = mDom.createTextNode( theFields.at( fieldNumber ).name() );
QDomNode nameNode = classificationFieldElem.firstChild();
classificationFieldElem.replaceChild( fieldName, nameNode );
}
}
}
}
}
示例2: processGraph_Edges
bool GraphMLImporter::processGraph_Edges(
QDomElement& graphElement
)
{
bool ok = true;
iColor_ = 0;
// default direction
bool defaultDirection;
if ( graphElement.attribute( "edgedefault" ) == "directed" ) {
defaultDirection = true;
}
else {
defaultDirection = false;
}
// edges
for ( QDomElement edgeElement = graphElement.firstChildElement( "edge" ); ok && !edgeElement.isNull(); edgeElement = edgeElement.nextSiblingElement( "edge" ) ) {
QString sourceId = edgeElement.attribute( "source" );
QString targetId = edgeElement.attribute( "target" );
QString direction = NULL;
bool directed = false;
direction = edgeElement.attribute( "directed" );
if ( direction == NULL ) {
directed = defaultDirection;
if ( directed ) {
direction = "_directed";
}
else {
direction = "";
}
}
else {
if ( direction == "true" ) {
direction = "_directed";
directed = true;
}
else {
direction = "";
directed = false;
}
}
// pozerame sa na data ktore hrana nesie
Data::Type* newEdgeType;
newEdgeType = NULL;
QDomNodeList edgeDataList = edgeElement.elementsByTagName( "data" );
for ( unsigned int j = 0; j < edgeDataList.length(); j++ ) {
QDomNode edgeData = edgeDataList.item( static_cast<int>( j ) );
if ( !edgeData.isNull() && edgeData.isElement() ) {
QDomElement edgeDataElement = edgeData.toElement();
QString dataName = edgeDataElement.attribute( "key" );
QString dataValue = edgeDataElement.text();
// rozpoznavame typy deklarovane atributom relation
if ( dataName == edgeTypeAttribute_ ) {
// overime ci uz dany typ existuje v grafe
QList<Data::Type*> types = context_->getGraph().getTypesByName( dataValue+direction );
if ( types.isEmpty() ) {
QMap<QString, QString>* settings = new QMap<QString, QString>;
// FIXME spravit tak, aby to rotovalo po tom poli - palo az to budes prerabat tak pre hrany pouzi ine pole, take co ma alfu na 0.5.. a to sa tyka aj uzlov s defaultnym typom
settings->insert( "color.R", QString::number( colors_[iColor_][0] ) );
settings->insert( "color.G", QString::number( colors_[iColor_][1] ) );
settings->insert( "color.B", QString::number( colors_[iColor_][2] ) );
settings->insert( "color.A", QString::number( colors_[iColor_][3] ) );
settings->insert( "scale", Util::ApplicationConfig::get()->getValue( "Viewer.Textures.DefaultNodeScale" ) );
if ( !directed ) {
settings->insert( "textureFile", Util::ApplicationConfig::get()->getValue( "Viewer.Textures.Edge" ) );
}
else {
settings->insert( "textureFile", Util::ApplicationConfig::get()->getValue( "Viewer.Textures.OrientedEdgePrefix" ) );
settings->insert( "textureFile", Util::ApplicationConfig::get()->getValue( "Viewer.Textures.OrientedEdgeSuffix" ) );
}
newEdgeType = context_->getGraph().addType( dataValue+direction, settings );
iColor_++;
if ( iColor_ == colors_.size() ) {
iColor_ = 0;
}
}
else {
newEdgeType = types.first();
}
}
else {
// kazde dalsie data nacitame do nosica dat - Edge.name
// FIXME potom prerobit cez Adamove Node.settings
}
}
}
// ak nebol najdeny typ, tak pouzijeme defaulty
if ( newEdgeType == NULL ) {
newEdgeType = edgeType_;
}
//.........这里部分代码省略.........
示例3: processGraph_Nodes
bool GraphMLImporter::processGraph_Nodes(
QDomElement& graphElement
)
{
bool ok = true;
iColor_ = 0;
// nodes
for ( QDomElement nodeElement = graphElement.firstChildElement( "node" ); ok && !nodeElement.isNull(); nodeElement = nodeElement.nextSiblingElement( "node" ) ) {
QString nameId = nodeElement.attribute( "id" );
QString name = NULL;
// pozerame sa na data ktore nesie
Data::Type* newNodeType;
newNodeType = NULL;
QDomNodeList nodeDataList = nodeElement.elementsByTagName( "data" );
for ( unsigned int j = 0; j < nodeDataList.length(); j++ ) {
QDomNode nodeData = nodeDataList.item( static_cast<int>( j ) );
if ( !nodeData.isNull() && nodeData.isElement() ) {
QDomElement nodeDataElement = nodeData.toElement();
QString dataName = nodeDataElement.attribute( "key" );
QString dataValue = nodeDataElement.text();
// rozpoznavame typy
if ( dataName == nodeTypeAttribute_ ) {
// overime ci uz dany typ existuje v grafe
QList<Data::Type*> types = context_->getGraph().getTypesByName( dataValue );
if ( types.isEmpty() ) {
QMap<QString, QString>* settings = new QMap<QString, QString>;
settings->insert( "color.R", QString::number( colors_[iColor_][0] ) );
settings->insert( "color.G", QString::number( colors_[iColor_][1] ) );
settings->insert( "color.B", QString::number( colors_[iColor_][2] ) );
settings->insert( "color.A", QString::number( colors_[iColor_][3] ) );
settings->insert( "scale", Util::ApplicationConfig::get()->getValue( "Viewer.Textures.DefaultNodeScale" ) );
settings->insert( "textureFile", Util::ApplicationConfig::get()->getValue( "Viewer.Textures.Node" ) );
newNodeType = context_->getGraph().addType( dataValue, settings );
iColor_++;
if ( iColor_ == colors_.size() ) {
iColor_ = 0;
}
}
else {
newNodeType = types.first();
}
}
else {
// kazde dalsie data nacitame do nosica dat - Node.name
// FIXME potom prerobit cez Adamove Node.settings
if ( name == NULL ) {
name = dataName+":"+dataValue;
}
else {
name += " | "+dataName+":"+dataValue;
}
}
}
}
// ak sme nenasli name, tak ako name pouzijeme aspon ID
if ( name == NULL ) {
name = nameId;
}
// ak nebol najdeny ziaden typ, tak pouzijeme defaultny typ
osg::ref_ptr<Data::Node> node;
if ( newNodeType == NULL ) {
node = context_->getGraph().addNode( name, nodeType_ );
}
else {
node = context_->getGraph().addNode( name, newNodeType );
}
readNodes_->addNode( nameId, node );
// subgraphs
for ( QDomElement subgraphElement = nodeElement.firstChildElement( "graph" ); ok && !subgraphElement.isNull(); subgraphElement = subgraphElement.nextSiblingElement( "graph" ) ) {
if ( ok ) {
context_->getGraph().createNestedGraph( node );
}
if ( ok ) {
ok = processGraph( subgraphElement );
}
if ( ok ) {
context_->getGraph().closeNestedGraph();
}
}
entitiesProcessed_++;
context_->getInfoHandler().setProgress( static_cast<unsigned int>( entitiesProcessed_ * 100 / entitiesCount_ ) );
}
return ok;
}
示例4: _InternalLoad
void UPnpDeviceDesc::_InternalLoad( QDomNode oNode, UPnpDevice *pCurDevice )
{
QString pin = GetMythDB()->GetSetting( "SecurityPin", "");
pCurDevice->m_securityPin = (pin.isEmpty() || pin == "0000") ?
false : true;
for ( oNode = oNode.firstChild();
!oNode.isNull();
oNode = oNode.nextSibling() )
{
QDomElement e = oNode.toElement();
if (!e.isNull())
{
if ( e.tagName() == "deviceType" )
{ SetStrValue( e, pCurDevice->m_sDeviceType ); continue; }
if ( e.tagName() == "friendlyName" )
{ SetStrValue( e, pCurDevice->m_sFriendlyName ); continue; }
if ( e.tagName() == "manufacturer" )
{ SetStrValue( e, pCurDevice->m_sManufacturer ); continue; }
if ( e.tagName() == "manufacturerURL" )
{ SetStrValue( e, pCurDevice->m_sManufacturerURL ); continue; }
if ( e.tagName() == "modelDescription" )
{ SetStrValue( e, pCurDevice->m_sModelDescription); continue; }
if ( e.tagName() == "modelName" )
{ SetStrValue( e, pCurDevice->m_sModelName ); continue; }
if ( e.tagName() == "modelNumber" )
{ SetStrValue( e, pCurDevice->m_sModelNumber ); continue; }
if ( e.tagName() == "modelURL" )
{ SetStrValue( e, pCurDevice->m_sModelURL ); continue; }
if ( e.tagName() == "serialNumber" )
{ SetStrValue( e, pCurDevice->m_sSerialNumber ); continue; }
if ( e.tagName() == "UPC" )
{ SetStrValue( e, pCurDevice->m_sUPC ); continue; }
if ( e.tagName() == "presentationURL" )
{ SetStrValue( e, pCurDevice->m_sPresentationURL ); continue; }
if ( e.tagName() == "UDN" )
{ SetStrValue( e, pCurDevice->m_sUDN ); continue; }
if ( e.tagName() == "iconList" )
{ ProcessIconList ( oNode, pCurDevice ); continue; }
if ( e.tagName() == "serviceList" )
{ ProcessServiceList( oNode, pCurDevice ); continue; }
if ( e.tagName() == "deviceList" )
{ ProcessDeviceList ( oNode, pCurDevice ); continue; }
if ( e.tagName() == "mythtv:X_secure" )
{ SetBoolValue( e, pCurDevice->m_securityPin ); continue; }
if ( e.tagName() == "mythtv:X_protocol" )
{ SetStrValue( e, pCurDevice->m_protocolVersion ); continue; }
// Not one of the expected element names... add to extra list.
QString sValue = "";
SetStrValue( e, sValue );
pCurDevice->m_lstExtra.push_back(NameValue(e.tagName(), sValue));
}
}
}
示例5: file
void UpdatesInfo::Private::parseFile(const QString& updateXmlFile)
{
QFile file( updateXmlFile );
if( !file.open(QFile::ReadOnly) )
{
error = UpdatesInfo::CouldNotReadUpdateInfoFileError;
errorMessage = tr("Could not read \"%1\"").arg(updateXmlFile);
return;
}
QDomDocument doc;
QString parseErrorMessage;
int parseErrorLine;
int parseErrorColumn;
if( !doc.setContent( &file, &parseErrorMessage, &parseErrorLine, &parseErrorColumn ) )
{
error = UpdatesInfo::InvalidXmlError;
errorMessage = tr("Parse error in %1 at %2, %3: %4")
.arg( updateXmlFile,
QString::number( parseErrorLine ),
QString::number( parseErrorColumn ),
parseErrorMessage );
return;
}
const QDomElement rootE = doc.documentElement();
if( rootE.tagName() != QLatin1String( "Updates" ) )
{
setInvalidContentError(tr("root element %1 unexpected, should be \"Updates\"").arg(rootE.tagName()));
return;
}
const QDomNodeList childNodes = rootE.childNodes();
for(int i=0; i<childNodes.count(); i++)
{
const QDomNode childNode = childNodes.at(i);
const QDomElement childE = childNode.toElement();
if( childE.isNull() )
continue;
if ( childE.tagName() == QLatin1String( "TargetName" ) ||
childE.tagName() == QLatin1String( "ApplicationName" ) ) // backwards compat
targetName = childE.text();
else if ( childE.tagName() == QLatin1String( "TargetVersion" ) ||
childE.tagName() == QLatin1String( "ApplicationVersion" ) ) // backwards compat
targetVersion = childE.text();
else if( childE.tagName() == QLatin1String( "RequiredCompatLevel" ) )
compatLevel = childE.text().toInt();
else if( childE.tagName() == QLatin1String( "PackageUpdate" ) ) {
const bool res = parsePackageUpdateElement( childE );
if (!res) {
//error handled in subroutine
return;
}
} else if( childE.tagName() == QLatin1String( "CompatUpdate" ) ) {
const bool res = parseCompatUpdateElement( childE );
if (!res) {
//error handled in subroutine
return;
}
}
}
if ( targetName.isEmpty() )
{
setInvalidContentError( tr("TargetName element is missing") );
return;
}
if ( targetVersion.isEmpty() )
{
setInvalidContentError(tr("TargetVersion element is missing"));
return;
}
error = UpdatesInfo::NoError;
errorMessage.clear();
}
示例6: parseGradient
QBrush XMLParseBase::parseGradient(const QDomElement &element)
{
QLinearGradient gradient;
QString gradientStart = element.attribute("start", "");
QString gradientEnd = element.attribute("end", "");
int gradientAlpha = element.attribute("alpha", "255").toInt();
QString direction = element.attribute("direction", "vertical");
float x1, y1, x2, y2 = 0.0;
if (direction == "vertical")
{
x1 = 0.5;
x2 = 0.5;
y1 = 0.0;
y2 = 1.0;
}
else if (direction == "diagonal")
{
x1 = 0.0;
x2 = 1.0;
y1 = 0.0;
y2 = 1.0;
}
else
{
x1 = 0.0;
x2 = 1.0;
y1 = 0.5;
y2 = 0.5;
}
gradient.setCoordinateMode(QGradient::ObjectBoundingMode);
gradient.setStart(x1, y1);
gradient.setFinalStop(x2, y2);
QGradientStops stops;
if (!gradientStart.isEmpty())
{
QColor startColor = QColor(gradientStart);
startColor.setAlpha(gradientAlpha);
QGradientStop stop(0.0, startColor);
stops.append(stop);
}
if (!gradientEnd.isEmpty())
{
QColor endColor = QColor(gradientEnd);
endColor.setAlpha(gradientAlpha);
QGradientStop stop(1.0, endColor);
stops.append(stop);
}
for (QDomNode child = element.firstChild(); !child.isNull();
child = child.nextSibling())
{
QDomElement childElem = child.toElement();
if (childElem.tagName() == "stop")
{
float position = childElem.attribute("position", "0").toFloat();
QString color = childElem.attribute("color", "");
int alpha = childElem.attribute("alpha", "-1").toInt();
if (alpha < 0)
alpha = gradientAlpha;
QColor stopColor = QColor(color);
stopColor.setAlpha(alpha);
QGradientStop stop((position / 100), stopColor);
stops.append(stop);
}
}
gradient.setStops(stops);
return QBrush(gradient);
}
示例7: if
//.........这里部分代码省略.........
else
{
VERBOSE_XML(VB_IMPORTANT, filename, element,
LOC_ERR + "Unknown widget type.");
return NULL;
}
if (!uitype)
{
VERBOSE_XML(VB_IMPORTANT, filename, element,
LOC_ERR + "Failed to instantiate widget type.");
return NULL;
}
if (olduitype)
{
if (typeid(*olduitype) != typeid(*uitype))
{
VERBOSE_XML(VB_IMPORTANT, filename, element, LOC_ERR +
QString("Duplicate name: '%1' in parent '%2'")
.arg(name).arg(parent->objectName()));
parent->DeleteChild(olduitype);
}
else
{
parent->DeleteChild(uitype);
uitype = olduitype;
}
}
if (base)
{
if (typeid(*base) != typeid(*uitype))
{
VERBOSE_XML(VB_IMPORTANT, filename, element, LOC_ERR +
QString("Type of new widget '%1' doesn't "
"match old '%2'")
.arg(name).arg(inherits));
parent->DeleteChild(uitype);
return NULL;
}
else
uitype->CopyFrom(base);
}
for (QDomNode child = element.firstChild(); !child.isNull();
child = child.nextSibling())
{
QDomElement info = child.toElement();
if (!info.isNull())
{
if (uitype->ParseElement(filename, info, showWarnings))
{
}
else if (info.tagName() == "font" || info.tagName() == "fontdef")
{
bool global = (GetGlobalObjectStore() == parent);
MythFontProperties *font = MythFontProperties::ParseFromXml(
filename, info, parent, global, showWarnings);
if (!global && font)
{
QString name = info.attribute("name");
uitype->AddFont(name, font);
}
delete font;
}
else if (info.tagName() == "imagetype" ||
info.tagName() == "textarea" ||
info.tagName() == "group" ||
info.tagName() == "textedit" ||
info.tagName() == "button" ||
info.tagName() == "buttonlist" ||
info.tagName() == "buttonlist2" ||
info.tagName() == "buttontree" ||
info.tagName() == "spinbox" ||
info.tagName() == "checkbox" ||
info.tagName() == "statetype" ||
info.tagName() == "clock" ||
info.tagName() == "progressbar" ||
info.tagName() == "webbrowser" ||
info.tagName() == "guidegrid" ||
info.tagName() == "shape" ||
info.tagName() == "editbar")
{
ParseUIType(filename, info, info.tagName(),
uitype, screen, showWarnings);
}
else
{
VERBOSE_XML(VB_IMPORTANT, filename, info,
LOC_ERR + "Unknown widget type.");
}
}
}
uitype->Finalize();
return uitype;
}
示例8: if
MythFontProperties *MythFontProperties::ParseFromXml(
const QString &filename,
const QDomElement &element,
MythUIType *parent,
bool addToGlobal,
bool showWarnings)
{
// Crappy, but cached. Move to GlobalFontMap?
bool fromBase = false;
MythFontProperties *newFont = new MythFontProperties();
newFont->Freeze();
if (element.tagName() == "font")
LOG(VB_GENERAL, LOG_WARNING, LOC +
QString("File %1: Use of 'font' is deprecated in favour of "
"'fontdef'") .arg(filename));
QString name = element.attribute("name", "");
if (name.isEmpty())
{
VERBOSE_XML(VB_GENERAL, LOG_ERR,
filename, element, "Font requires a name");
delete newFont;
return NULL;
}
QString base = element.attribute("from", "");
if (!base.isEmpty())
{
MythFontProperties *tmp = NULL;
if (parent)
tmp = parent->GetFont(base);
if (!tmp)
tmp = GetGlobalFontMap()->GetFont(base);
if (!tmp)
{
VERBOSE_XML(VB_GENERAL, LOG_ERR, filename, element,
QString("Specified base font '%1' does not exist.").arg(base));
delete newFont;
return NULL;
}
*newFont = *tmp;
fromBase = true;
}
int size, pixelsize;
size = pixelsize = -1;
QString face = element.attribute("face", "");
if (face.isEmpty())
{
if (!fromBase)
{
VERBOSE_XML(VB_GENERAL, LOG_ERR, filename, element,
"Font needs a face");
delete newFont;
return NULL;
}
}
else
{
newFont->m_face.setFamily(face);
}
if (addToGlobal && GetGlobalFontMap()->Contains(name))
{
MythFontProperties *tmp = GetGlobalFontMap()->GetFont(name);
if (showWarnings)
{
VERBOSE_XML(VB_GENERAL, LOG_WARNING, filename, element,
QString("Attempting to define '%1'\n\t\t\t"
"with face '%2', but it already "
"exists with face '%3'")
.arg(name).arg(QFontInfo(newFont->m_face).family())
.arg((tmp) ? QFontInfo(tmp->m_face).family() : "ERROR"));
}
delete newFont;
return NULL;
}
QString hint = element.attribute("stylehint", "");
if (!hint.isEmpty())
{
newFont->m_face.setStyleHint((QFont::StyleHint)hint.toInt());
}
for (QDomNode child = element.firstChild(); !child.isNull();
child = child.nextSibling())
{
QDomElement info = child.toElement();
if (!info.isNull())
{
if (info.tagName() == "size")
//.........这里部分代码省略.........
示例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: parseGroup
void ShapePlug::parseGroup(QDomNode &DOC)
{
QString tmp = "";
QString FillCol = "White";
QString StrokeCol = "Black";
QString defFillCol = "White";
QString defStrokeCol = "Black";
QColor stroke = Qt::black;
QColor fill = Qt::white;
// Qt::PenStyle Dash = Qt::SolidLine;
Qt::PenCapStyle LineEnd = Qt::FlatCap;
Qt::PenJoinStyle LineJoin = Qt::MiterJoin;
// int fillStyle = 1;
double strokewidth = 0.1;
// bool poly = false;
while(!DOC.isNull())
{
double x1, y1, x2, y2;
StrokeCol = defStrokeCol;
FillCol = defFillCol;
stroke = Qt::black;
fill = Qt::white;
// fillStyle = 1;
strokewidth = 1.0;
// Dash = Qt::SolidLine;
LineEnd = Qt::FlatCap;
LineJoin = Qt::MiterJoin;
FPointArray PoLine;
PoLine.resize(0);
QDomElement pg = DOC.toElement();
QString STag = pg.tagName();
QString style = pg.attribute( "style", "" ).simplified();
if (style.isEmpty())
style = pg.attribute( "svg:style", "" ).simplified();
QStringList substyles = style.split(';', QString::SkipEmptyParts);
for( QStringList::Iterator it = substyles.begin(); it != substyles.end(); ++it )
{
QStringList substyle = (*it).split(':', QString::SkipEmptyParts);
QString command(substyle[0].trimmed());
QString params(substyle[1].trimmed());
if (command == "fill")
{
if (!((params == "foreground") || (params == "background") || (params == "fg") || (params == "bg") || (params == "none") || (params == "default") || (params == "inverse")))
{
if (params == "nofill")
FillCol = CommonStrings::None;
else
{
fill.setNamedColor( params );
FillCol = "FromDia"+fill.name();
ScColor tmp;
tmp.fromQColor(fill);
tmp.setSpotColor(false);
tmp.setRegistrationColor(false);
QString fNam = m_Doc->PageColors.tryAddColor(FillCol, tmp);
if (fNam == FillCol)
importedColors.append(FillCol);
FillCol = fNam;
}
}
}
else if (command == "stroke")
{
if (!((params == "foreground") || (params == "background") || (params == "fg") || (params == "bg") || (params == "none") || (params == "default")) || (params == "inverse"))
{
stroke.setNamedColor( params );
StrokeCol = "FromDia"+stroke.name();
ScColor tmp;
tmp.fromQColor(stroke);
tmp.setSpotColor(false);
tmp.setRegistrationColor(false);
QString fNam = m_Doc->PageColors.tryAddColor(StrokeCol, tmp);
if (fNam == StrokeCol)
importedColors.append(StrokeCol);
StrokeCol = fNam;
}
}
else if (command == "stroke-width")
strokewidth = ScCLocale::toDoubleC(params);
else if( command == "stroke-linejoin" )
{
if( params == "miter" )
LineJoin = Qt::MiterJoin;
else if( params == "round" )
LineJoin = Qt::RoundJoin;
else if( params == "bevel" )
LineJoin = Qt::BevelJoin;
}
else if( command == "stroke-linecap" )
{
if( params == "butt" )
LineEnd = Qt::FlatCap;
else if( params == "round" )
LineEnd = Qt::RoundCap;
else if( params == "square" )
LineEnd = Qt::SquareCap;
}
}
if (STag == "svg:line")
{
//.........这里部分代码省略.........
示例11: parseGroupProperties
void ShapePlug::parseGroupProperties(QDomNode &DOC, double &minXCoor, double &minYCoor, double &maxXCoor, double &maxYCoor, bool &firstCheck)
{
QString FillCol = "White";
QString StrokeCol = "Black";
while(!DOC.isNull())
{
double x1, y1, x2, y2;
FPointArray PoLine;
PoLine.resize(0);
QDomElement pg = DOC.toElement();
QString STag = pg.tagName();
if (STag == "svg:line")
{
x1 = ScCLocale::toDoubleC(pg.attribute("x1")) * Conversion;
y1 = ScCLocale::toDoubleC(pg.attribute("y1")) * Conversion;
x2 = ScCLocale::toDoubleC(pg.attribute("x2")) * Conversion;
y2 = ScCLocale::toDoubleC(pg.attribute("y2")) * Conversion;
PoLine.addPoint(x1, y1);
PoLine.addPoint(x1, y1);
PoLine.addPoint(x2, y2);
PoLine.addPoint(x2, y2);
}
else if (STag == "svg:rect")
{
x1 = ScCLocale::toDoubleC(pg.attribute("x")) * Conversion;
y1 = ScCLocale::toDoubleC(pg.attribute("y")) * Conversion;
x2 = ScCLocale::toDoubleC(pg.attribute("width")) * Conversion;
y2 = ScCLocale::toDoubleC(pg.attribute("height")) * Conversion;
static double rect[] = {0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0,
1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.0, 1.0, 0.0, 1.0,
0.0, 1.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0};
for (int a = 0; a < 29; a += 4)
{
double xa = x2 * rect[a];
double ya = y2 * rect[a+1];
double xb = x2 * rect[a+2];
double yb = y2 * rect[a+3];
PoLine.addPoint(x1+xa, y1+ya);
PoLine.addPoint(x1+xb, y1+yb);
}
}
else if ((STag == "svg:polygon") || (STag == "svg:polyline"))
{
bool bFirst = true;
double x = 0.0;
double y = 0.0;
QString points = pg.attribute( "points" ).simplified().replace(',', " ");
QStringList pointList = points.split(' ', QString::SkipEmptyParts);
FirstM = true;
for( QStringList::Iterator it1 = pointList.begin(); it1 != pointList.end(); it1++ )
{
x = ScCLocale::toDoubleC(*(it1++));
y = ScCLocale::toDoubleC(*it1);
if( bFirst )
{
svgMoveTo(x * Conversion, y * Conversion);
bFirst = false;
WasM = true;
}
else
{
svgLineTo(&PoLine, x * Conversion, y * Conversion);
}
}
if (STag == "svg:polygon")
svgClosePath(&PoLine);
if (PoLine.size() < 4)
{
DOC = DOC.nextSibling();
continue;
}
}
else if (STag == "svg:circle")
{
x1 = ScCLocale::toDoubleC(pg.attribute("r")) * Conversion;
y1 = ScCLocale::toDoubleC(pg.attribute("r")) * Conversion;
x2 = ScCLocale::toDoubleC(pg.attribute("cx")) * Conversion - x1;
y2 = ScCLocale::toDoubleC(pg.attribute("cy")) * Conversion - y1;
x1 *= 2.0;
y1 *= 2.0;
static double rect[] = {1.0, 0.5, 1.0, 0.77615235,0.5, 1.0, 0.77615235, 1.0,
0.5, 1.0, 0.22385765, 1.0, 0.0, 0.5, 0.0, 0.77615235,
0.0, 0.5, 0.0, 0.22385765, 0.5, 0.0, 0.22385765, 0.0,
0.5, 0.0, 0.77615235, 0.0, 1.0, 0.5, 1.0, 0.22385765};
for (int a = 0; a < 29; a += 4)
{
double xa = x1 * rect[a];
double ya = y1 * rect[a+1];
double xb = x1 * rect[a+2];
double yb = y1 * rect[a+3];
PoLine.addPoint(x2+xa, y2+ya);
PoLine.addPoint(x2+xb, y2+yb);
}
}
else if (STag == "svg:ellipse")
{
x1 = ScCLocale::toDoubleC(pg.attribute("rx")) * Conversion;
y1 = ScCLocale::toDoubleC(pg.attribute("ry")) * Conversion;
x2 = ScCLocale::toDoubleC(pg.attribute("cx")) * Conversion - x1;
y2 = ScCLocale::toDoubleC(pg.attribute("cy")) * Conversion - y1;
//.........这里部分代码省略.........
示例12: convertRasterProperties
void QgsProjectFileTransform::convertRasterProperties( QDomDocument& doc, QDomNode& parentNode,
QDomElement& rasterPropertiesElem, QgsRasterLayer* rlayer )
{
//no data
//TODO: We would need to set no data on all bands, but we don't know number of bands here
QDomNode noDataNode = rasterPropertiesElem.namedItem( QStringLiteral( "mNoDataValue" ) );
QDomElement noDataElement = noDataNode.toElement();
if ( !noDataElement.text().isEmpty() )
{
QgsDebugMsg( "mNoDataValue = " + noDataElement.text() );
QDomElement noDataElem = doc.createElement( QStringLiteral( "noData" ) );
QDomElement noDataRangeList = doc.createElement( QStringLiteral( "noDataRangeList" ) );
noDataRangeList.setAttribute( QStringLiteral( "bandNo" ), 1 );
QDomElement noDataRange = doc.createElement( QStringLiteral( "noDataRange" ) );
noDataRange.setAttribute( QStringLiteral( "min" ), noDataElement.text() );
noDataRange.setAttribute( QStringLiteral( "max" ), noDataElement.text() );
noDataRangeList.appendChild( noDataRange );
noDataElem.appendChild( noDataRangeList );
parentNode.appendChild( noDataElem );
}
QDomElement rasterRendererElem = doc.createElement( QStringLiteral( "rasterrenderer" ) );
//convert general properties
//invert color
rasterRendererElem.setAttribute( QStringLiteral( "invertColor" ), QStringLiteral( "0" ) );
QDomElement invertColorElem = rasterPropertiesElem.firstChildElement( QStringLiteral( "mInvertColor" ) );
if ( !invertColorElem.isNull() )
{
if ( invertColorElem.text() == QLatin1String( "true" ) )
{
rasterRendererElem.setAttribute( QStringLiteral( "invertColor" ), QStringLiteral( "1" ) );
}
}
//opacity
rasterRendererElem.setAttribute( QStringLiteral( "opacity" ), QStringLiteral( "1" ) );
QDomElement transparencyElem = parentNode.firstChildElement( QStringLiteral( "transparencyLevelInt" ) );
if ( !transparencyElem.isNull() )
{
double transparency = transparencyElem.text().toInt();
rasterRendererElem.setAttribute( QStringLiteral( "opacity" ), QString::number( transparency / 255.0 ) );
}
//alphaBand was not saved until now (bug)
rasterRendererElem.setAttribute( QStringLiteral( "alphaBand" ), -1 );
//gray band is used for several renderers
int grayBand = rasterBandNumber( rasterPropertiesElem, QStringLiteral( "mGrayBandName" ), rlayer );
//convert renderer specific properties
QString drawingStyle = rasterPropertiesElem.firstChildElement( QStringLiteral( "mDrawingStyle" ) ).text();
// While PalettedColor should normaly contain only integer values, usually
// color palette 0-255, it may happen (Tim, issue #7023) that it contains
// colormap classification with double values and text labels
// (which should normaly only appear in SingleBandPseudoColor drawingStyle)
// => we have to check first the values and change drawingStyle if necessary
if ( drawingStyle == QLatin1String( "PalettedColor" ) )
{
QDomElement customColorRampElem = rasterPropertiesElem.firstChildElement( QStringLiteral( "customColorRamp" ) );
QDomNodeList colorRampEntryList = customColorRampElem.elementsByTagName( QStringLiteral( "colorRampEntry" ) );
for ( int i = 0; i < colorRampEntryList.size(); ++i )
{
QDomElement colorRampEntryElem = colorRampEntryList.at( i ).toElement();
QString strValue = colorRampEntryElem.attribute( QStringLiteral( "value" ) );
double value = strValue.toDouble();
if ( value < 0 || value > 10000 || !qgsDoubleNear( value, static_cast< int >( value ) ) )
{
QgsDebugMsg( QString( "forcing SingleBandPseudoColor value = %1" ).arg( value ) );
drawingStyle = QStringLiteral( "SingleBandPseudoColor" );
break;
}
}
}
if ( drawingStyle == QLatin1String( "SingleBandGray" ) )
{
rasterRendererElem.setAttribute( QStringLiteral( "type" ), QStringLiteral( "singlebandgray" ) );
rasterRendererElem.setAttribute( QStringLiteral( "grayBand" ), grayBand );
transformContrastEnhancement( doc, rasterPropertiesElem, rasterRendererElem );
}
else if ( drawingStyle == QLatin1String( "SingleBandPseudoColor" ) )
{
rasterRendererElem.setAttribute( QStringLiteral( "type" ), QStringLiteral( "singlebandpseudocolor" ) );
rasterRendererElem.setAttribute( QStringLiteral( "band" ), grayBand );
QDomElement newRasterShaderElem = doc.createElement( QStringLiteral( "rastershader" ) );
QDomElement newColorRampShaderElem = doc.createElement( QStringLiteral( "colorrampshader" ) );
newRasterShaderElem.appendChild( newColorRampShaderElem );
rasterRendererElem.appendChild( newRasterShaderElem );
//switch depending on mColorShadingAlgorithm
QString colorShadingAlgorithm = rasterPropertiesElem.firstChildElement( QStringLiteral( "mColorShadingAlgorithm" ) ).text();
if ( colorShadingAlgorithm == QLatin1String( "PseudoColorShader" ) || colorShadingAlgorithm == QLatin1String( "FreakOutShader" ) )
{
//.........这里部分代码省略.........
示例13: setDocument
void RenderWindow::setDocument(const QDomDocument & doc)
{
// Clear out the param list for this new document
_params.clear();
_lists.clear();
_table->clear();
_table->setRowCount(0);
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;
}
_doc = doc;
_reportInfo->setEnabled(true);
_reportName->setText(QString::null);
_reportTitle->setText(QString::null);
_reportDescription->setText(QString::null);
for(QDomNode n = root.firstChild(); !n.isNull(); n = n.nextSibling())
{
if(n.nodeName() == "name")
_reportName->setText(n.firstChild().nodeValue());
else if(n.nodeName() == "title")
_reportTitle->setText(n.firstChild().nodeValue());
else if(n.nodeName() == "description")
_reportDescription->setText(n.firstChild().nodeValue());
else 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",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);
}
}
}
示例14: readLayerXML
bool QgsMapLayer::readLayerXML( const QDomElement& layerElement )
{
QgsCoordinateReferenceSystem savedCRS;
CUSTOM_CRS_VALIDATION savedValidation;
bool layerError;
QDomNode mnl;
QDomElement mne;
// read provider
QString provider;
mnl = layerElement.namedItem( "provider" );
mne = mnl.toElement();
provider = mne.text();
// set data source
mnl = layerElement.namedItem( "datasource" );
mne = mnl.toElement();
mDataSource = mne.text();
// TODO: this should go to providers
if ( provider == "spatialite" )
{
QgsDataSourceURI uri( mDataSource );
uri.setDatabase( QgsProject::instance()->readPath( uri.database() ) );
mDataSource = uri.uri();
}
else if ( provider == "ogr" )
{
QStringList theURIParts = mDataSource.split( "|" );
theURIParts[0] = QgsProject::instance()->readPath( theURIParts[0] );
mDataSource = theURIParts.join( "|" );
}
else if ( provider == "delimitedtext" )
{
QUrl urlSource = QUrl::fromEncoded( mDataSource.toAscii() );
if ( !mDataSource.startsWith( "file:" ) )
{
QUrl file = QUrl::fromLocalFile( mDataSource.left( mDataSource.indexOf( "?" ) ) );
urlSource.setScheme( "file" );
urlSource.setPath( file.path() );
}
QUrl urlDest = QUrl::fromLocalFile( QgsProject::instance()->readPath( urlSource.toLocalFile() ) );
urlDest.setQueryItems( urlSource.queryItems() );
mDataSource = QString::fromAscii( urlDest.toEncoded() );
}
else if ( provider == "wms" )
{
// >>> BACKWARD COMPATIBILITY < 1.9
// For project file backward compatibility we must support old format:
// 1. mode: <url>
// example: http://example.org/wms?
// 2. mode: tiled=<width>;<height>;<resolution>;<resolution>...,ignoreUrl=GetMap;GetFeatureInfo,featureCount=<count>,username=<name>,password=<password>,url=<url>
// example: tiled=256;256;0.703;0.351,url=http://example.org/tilecache?
// example: featureCount=10,http://example.org/wms?
// example: ignoreUrl=GetMap;GetFeatureInfo,username=cimrman,password=jara,url=http://example.org/wms?
// This is modified version of old QgsWmsProvider::parseUri
// The new format has always params crs,format,layers,styles and that params
// should not appear in old format url -> use them to identify version
if ( !mDataSource.contains( "crs=" ) && !mDataSource.contains( "format=" ) )
{
QgsDebugMsg( "Old WMS URI format detected -> converting to new format" );
QgsDataSourceURI uri;
if ( !mDataSource.startsWith( "http:" ) )
{
QStringList parts = mDataSource.split( "," );
QStringListIterator iter( parts );
while ( iter.hasNext() )
{
QString item = iter.next();
if ( item.startsWith( "username=" ) )
{
uri.setParam( "username", item.mid( 9 ) );
}
else if ( item.startsWith( "password=" ) )
{
uri.setParam( "password", item.mid( 9 ) );
}
else if ( item.startsWith( "tiled=" ) )
{
// in < 1.9 tiled= may apper in to variants:
// tiled=width;height - non tiled mode, specifies max width and max height
// tiled=width;height;resolutions-1;resolution2;... - tile mode
QStringList params = item.mid( 6 ).split( ";" );
if ( params.size() == 2 ) // non tiled mode
{
uri.setParam( "maxWidth", params.takeFirst() );
uri.setParam( "maxHeight", params.takeFirst() );
}
else if ( params.size() > 2 ) // tiled mode
{
// resolutions are no more needed and size limit is not used for tiles
// we have to tell to the provider however that it is tiled
uri.setParam( "tileMatrixSet", "" );
}
}
//.........这里部分代码省略.........
示例15: ParseFile
static void ParseFile(QMap<QString, QString>& result, const QString& fileName, const QString& bankName)
{
QFile f(fileName);
if (f.open(QIODevice::ReadOnly)) {
QTextStream stream(&f);
#if OFXHOME
stream.setCodec("UTF-8");
QString msg;
int errl, errc;
QDomDocument doc;
if (doc.setContent(stream.readAll(), &msg, &errl, &errc)) {
QDomNodeList olist = doc.elementsByTagName("institutionid");
for (int i = 0; i < olist.count(); ++i) {
QDomNode onode = olist.item(i);
if (onode.isElement()) {
QDomElement elo = onode.toElement();
QString name = elo.attribute("name");
if (bankName.isEmpty())
result[name].clear();
else if (name == bankName) {
result[elo.attribute("id")].clear();
}
}
}
}
#endif
#if MSN
stream.setCodec("UTF-16");
QString msg;
int errl, errc;
QDomDocument doc;
if (doc.setContent(stream.readAll(), &msg, &errl, &errc)) {
QDomNodeList olist = doc.elementsByTagName("prov");
for (int i = 0; i < olist.count(); ++i) {
QDomNode onode = olist.item(i);
if (onode.isElement()) {
bool collectGuid = false;
QDomElement elo = onode.toElement();
QDomNodeList ilist = onode.childNodes();
for (int j = 0; j < ilist.count(); ++j) {
QDomNode inode = ilist.item(j);
QDomElement el = inode.toElement();
if (el.tagName() == "name") {
if (bankName.isEmpty())
result[el.text()].clear();
else if (el.text() == bankName) {
collectGuid = true;
}
}
if (el.tagName() == "guid" && collectGuid) {
result[el.text()].clear();
}
}
}
}
}
#endif
f.close();
}
}