本文整理汇总了C++中QDomElement::attribute方法的典型用法代码示例。如果您正苦于以下问题:C++ QDomElement::attribute方法的具体用法?C++ QDomElement::attribute怎么用?C++ QDomElement::attribute使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QDomElement
的用法示例。
在下文中一共展示了QDomElement::attribute方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: drawField
void QtRPT::drawField(QDomNode n, int bandTop) {
//В качестве параметра подается нод бэнда
QDomNode c = n.firstChild();
while(!c.isNull()) {
QDomElement e = c.toElement(); // try to convert the node to an element.
if ((!e.isNull()) && (e.tagName() == "TContainerField")) {
if (isFieldVisible(e)) {
QFont font(e.attribute("fontFamily"),e.attribute("fontSize").toInt());
font.setBold(processHighligthing(e, FontBold).toInt());
font.setItalic(processHighligthing(e, FontItalic).toInt());
font.setUnderline(processHighligthing(e, FontUnderline).toInt());
painter.setFont(font);
painter.setPen(Qt::black);
int left_ = e.attribute("left").toInt()*koefRes_w;
int top_ = (bandTop+e.attribute("top").toInt())*koefRes_h;
int width_ = (e.attribute("width").toInt()-1)*koefRes_w;;
int height_ = e.attribute("height").toInt()*koefRes_h;
int cor = QFontMetrics(font).height() * koefRes_h;
QRect textRect(left_, top_-height_, width_, height_);
textRect.translate(0, cor );
QPen pen = painter.pen();
Qt::Alignment al;
Qt::Alignment alH, alV;
if (e.attribute("aligmentH") == "hRight") alH = Qt::AlignRight;
if (e.attribute("aligmentH") == "hLeft") alH = Qt::AlignLeft;
if (e.attribute("aligmentH") == "hCenter") alH = Qt::AlignHCenter;
if (e.attribute("aligmentH") == "hJustify") alH = Qt::AlignJustify;
if (e.attribute("aligmentV") == "vTop") alV = Qt::AlignTop;
if (e.attribute("aligmentV") == "vBottom") alV = Qt::AlignBottom;
if (e.attribute("aligmentV") == "vCenter") alV = Qt::AlignVCenter;
al = alH | alV;
if ( colorFromString(processHighligthing(e, BgColor).toString() ) != QColor(255,255,255,0))
painter.fillRect(left_+1,top_+1,width_-2,height_-2,colorFromString(processHighligthing(e, BgColor).toString()));
/*if ( colorFromString(e.attribute("backgroundColor")) != QColor(255,255,255,0))
painter.fillRect(left_+1,top_+1,width_-2,height_-2,colorFromString(e.attribute("backgroundColor")));*/
//Set border width
pen.setWidth(e.attribute("borderWidth","1").replace("px","").toInt()*5);
//Set border style
QString borderStyle = e.attribute("borderStyle","solid");
if (borderStyle == "dashed")
pen.setStyle(Qt::DashLine);
else if (borderStyle == "dotted")
pen.setStyle(Qt::DotLine);
else if (borderStyle == "dot-dash")
pen.setStyle(Qt::DashDotLine);
else if (borderStyle == "dot-dot-dash")
pen.setStyle(Qt::DashDotDotLine);
else
pen.setStyle(Qt::SolidLine);
if ( colorFromString(e.attribute("borderTop")) != QColor(255,255,255,0) ) {
pen.setColor(colorFromString(e.attribute("borderTop")));
painter.setPen(pen);
painter.drawLine(left_, top_, left_ + width_, top_);
}
if ( colorFromString(e.attribute("borderBottom")) != QColor(255,255,255,0) ) {
pen.setColor(colorFromString(e.attribute("borderBottom")));
painter.setPen(pen);
painter.drawLine(left_, top_ + height_, left_ + width_, top_ + height_);
}
if ( colorFromString(e.attribute("borderLeft")) != QColor(255,255,255,0) ) {
pen.setColor(colorFromString(e.attribute("borderLeft")));
painter.setPen(pen);
painter.drawLine(left_, top_, left_, top_ + height_);
}
if ( colorFromString(e.attribute("borderRight")) != QColor(255,255,255,0) ) {
pen.setColor(colorFromString(e.attribute("borderRight")));
painter.setPen(pen);
painter.drawLine(left_ + width_, top_, left_ + width_, top_ + height_);
}
if (e.attribute("type","label") == "label") { //NOT Proccess if field set as ImageField
QString txt = sectionField(e.attribute("value"),false);
//pen.setColor(colorFromString(e.attribute("fontColor")));
pen.setColor(colorFromString(processHighligthing(e, FontColor).toString()));
painter.setPen(pen);
painter.drawText(left_+10,top_,width_-10,height_, al | Qt::TextDontClip | Qt::TextWordWrap, txt);
}
if (e.attribute("type","label") == "labelImage") { //Proccess field as ImageField
QImage image = sectionFieldImage(e.attribute("value"));
if (!image.isNull()) {
QRectF target(left_, top_, width_, height_);
painter.drawImage(target,image);
}
}
if (e.attribute("type","label") == "image") { //Proccess as static ImageField
QByteArray byteArray;
byteArray = QByteArray::fromBase64(e.attribute("picture","text").toLatin1());
QPixmap pixmap = QPixmap::fromImage(QImage::fromData(byteArray, "PNG"));
painter.drawPixmap(left_,top_,width_,height_,pixmap);
}
}
//.........这里部分代码省略.........
示例2: initialiseDefaultPrefs
void ColorSetManager::initialiseDefaultPrefs(struct ApplicationPrefs& appPrefs)
{
QString pfadC = ScPaths::instance().libDir()+"swatches/";
QString pfadC2 = pfadC + "Scribus_Basic.xml";
QFile fiC(pfadC2);
if (!fiC.exists())
{
appPrefs.colorPrefs.DColors.insert("White", ScColor(0, 0, 0, 0));
appPrefs.colorPrefs.DColors.insert("Black", ScColor(0, 0, 0, 255));
ScColor cc = ScColor(255, 255, 255, 255);
cc.setRegistrationColor(true);
appPrefs.colorPrefs.DColors.insert("Registration", cc);
appPrefs.colorPrefs.DColors.insert("Blue", ScColor(255, 255, 0, 0));
appPrefs.colorPrefs.DColors.insert("Cyan", ScColor(255, 0, 0, 0));
appPrefs.colorPrefs.DColors.insert("Green", ScColor(255, 0, 255, 0));
appPrefs.colorPrefs.DColors.insert("Red", ScColor(0, 255, 255, 0));
appPrefs.colorPrefs.DColors.insert("Yellow", ScColor(0, 0, 255, 0));
appPrefs.colorPrefs.DColors.insert("Magenta", ScColor(0, 255, 0, 0));
appPrefs.colorPrefs.DColorSet = "Scribus-Small";
}
else
{
if (fiC.open(QIODevice::ReadOnly))
{
QString ColorEn, Cname;
int Rval, Gval, Bval;
QTextStream tsC(&fiC);
ColorEn = tsC.readLine();
if (ColorEn.startsWith("<?xml version="))
{
QByteArray docBytes("");
loadRawText(pfadC2, docBytes);
QString docText("");
docText = QString::fromUtf8(docBytes);
QDomDocument docu("scridoc");
docu.setContent(docText);
ScColor lf = ScColor();
QDomElement elem = docu.documentElement();
QDomNode PAGE = elem.firstChild();
while(!PAGE.isNull())
{
QDomElement pg = PAGE.toElement();
if(pg.tagName()=="COLOR" && pg.attribute("NAME")!=CommonStrings::None)
{
if (pg.hasAttribute("CMYK"))
lf.setNamedColor(pg.attribute("CMYK"));
else
lf.fromQColor(QColor(pg.attribute("RGB")));
if (pg.hasAttribute("Spot"))
lf.setSpotColor(static_cast<bool>(pg.attribute("Spot").toInt()));
else
lf.setSpotColor(false);
if (pg.hasAttribute("Register"))
lf.setRegistrationColor(static_cast<bool>(pg.attribute("Register").toInt()));
else
lf.setRegistrationColor(false);
appPrefs.colorPrefs.DColors.insert(pg.attribute("NAME"), lf);
}
PAGE=PAGE.nextSibling();
}
}
else
{
while (!tsC.atEnd())
{
ColorEn = tsC.readLine();
QTextStream CoE(&ColorEn, QIODevice::ReadOnly);
CoE >> Rval;
CoE >> Gval;
CoE >> Bval;
CoE >> Cname;
ScColor tmp;
tmp.setColorRGB(Rval, Gval, Bval);
appPrefs.colorPrefs.DColors.insert(Cname, tmp);
}
}
fiC.close();
}
appPrefs.colorPrefs.DColorSet = "Scribus Basic";
}
示例3: loadWFSConnections
void QgsManageConnectionsDialog::loadWFSConnections( const QDomDocument &doc, const QStringList &items )
{
QDomElement root = doc.documentElement();
if ( root.tagName() != "qgsWFSConnections" )
{
QMessageBox::information( this, tr( "Loading connections" ),
tr( "The file is not an WFS connections exchange file." ) );
return;
}
QString connectionName;
QSettings settings;
settings.beginGroup( "/Qgis/connections-wfs" );
QStringList keys = settings.childGroups();
settings.endGroup();
QDomElement child = root.firstChildElement();
bool prompt = true;
bool overwrite = true;
while ( !child.isNull() )
{
connectionName = child.attribute( "name" );
if ( !items.contains( connectionName ) )
{
child = child.nextSiblingElement();
continue;
}
// check for duplicates
if ( keys.contains( connectionName ) && prompt )
{
int res = QMessageBox::warning( this,
tr( "Loading connections" ),
tr( "Connection with name '%1' already exists. Overwrite?" )
.arg( connectionName ),
QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel );
switch ( res )
{
case QMessageBox::Cancel:
return;
case QMessageBox::No:
child = child.nextSiblingElement();
continue;
case QMessageBox::Yes:
overwrite = true;
break;
case QMessageBox::YesToAll:
prompt = false;
overwrite = true;
break;
case QMessageBox::NoToAll:
prompt = false;
overwrite = false;
break;
}
}
if ( keys.contains( connectionName ) && !overwrite )
{
child = child.nextSiblingElement();
continue;
}
// no dups detected or overwrite is allowed
settings.beginGroup( "/Qgis/connections-wfs" );
settings.setValue( QString( "/" + connectionName + "/url" ) , child.attribute( "url" ) );
settings.endGroup();
if ( !child.attribute( "username" ).isEmpty() )
{
settings.beginGroup( "/Qgis/WFS/" + connectionName );
settings.setValue( "/username", child.attribute( "username" ) );
settings.setValue( "/password", child.attribute( "password" ) );
settings.endGroup();
}
child = child.nextSiblingElement();
}
}
示例4: parse
void QXmppDataForm::parse(const QDomElement &element)
{
if (element.isNull())
return;
/* form type */
const QString typeStr = element.attribute("type");
if (typeStr == "form")
m_type = QXmppDataForm::Form;
else if (typeStr == "submit")
m_type = QXmppDataForm::Submit;
else if (typeStr == "cancel")
m_type = QXmppDataForm::Cancel;
else if (typeStr == "result")
m_type = QXmppDataForm::Result;
else
{
qWarning() << "Unknown form type" << typeStr;
return;
}
/* form properties */
m_title = element.firstChildElement("title").text();
m_instructions = element.firstChildElement("instructions").text();
QDomElement fieldElement = element.firstChildElement("field");
while (!fieldElement.isNull())
{
QXmppDataForm::Field field;
/* field type */
QXmppDataForm::Field::Type type = QXmppDataForm::Field::TextSingleField;
const QString typeStr = fieldElement.attribute("type");
struct field_type *ptr;
for (ptr = field_types; ptr->str; ptr++)
{
if (typeStr == ptr->str)
{
type = ptr->type;
break;
}
}
field.setType(type);
/* field attributes */
field.setLabel(fieldElement.attribute("label"));
field.setKey(fieldElement.attribute("var"));
/* field value(s) */
if (type == QXmppDataForm::Field::BooleanField)
{
const QString valueStr = fieldElement.firstChildElement("value").text();
field.setValue(valueStr == "1" || valueStr == "true");
}
else if (type == QXmppDataForm::Field::ListMultiField ||
type == QXmppDataForm::Field::JidMultiField ||
type == QXmppDataForm::Field::TextMultiField)
{
QStringList values;
QDomElement valueElement = fieldElement.firstChildElement("value");
while (!valueElement.isNull())
{
values.append(valueElement.text());
valueElement = valueElement.nextSiblingElement("value");
}
field.setValue(values);
}
else
{
field.setValue(fieldElement.firstChildElement("value").text());
}
/* field options */
if (type == QXmppDataForm::Field::ListMultiField ||
type == QXmppDataForm::Field::ListSingleField)
{
QList<QPair<QString, QString> > options;
QDomElement optionElement = fieldElement.firstChildElement("option");
while (!optionElement.isNull())
{
options.append(QPair<QString, QString>(optionElement.attribute("label"),
optionElement.firstChildElement("value").text()));
optionElement = optionElement.nextSiblingElement("option");
}
field.setOptions(options);
}
/* other properties */
field.setDescription(fieldElement.firstChildElement("description").text());
field.setRequired(!fieldElement.firstChildElement("required").isNull());
m_fields.append(field);
fieldElement = fieldElement.nextSiblingElement("field");
}
}
示例5: save
void VCButton_Test::save()
{
QWidget w;
Scene* sc = new Scene(m_doc);
m_doc->addFunction(sc);
VCButton btn(&w, m_doc);
btn.setCaption("Foobar");
btn.setIcon("../../../gfx/qlc.png");
btn.setFunction(sc->id());
btn.setAction(VCButton::Flash);
btn.setKeySequence(QKeySequence(keySequenceB));
btn.setAdjustIntensity(true);
btn.setIntensityAdjustment(0.2);
QDomDocument xmldoc;
QDomElement root = xmldoc.createElement("Root");
xmldoc.appendChild(root);
int function = 0, action = 0, key = 0, intensity = 0, wstate = 0, appearance = 0;
QCOMPARE(btn.saveXML(&xmldoc, &root), true);
QDomElement tag = root.firstChild().toElement();
QCOMPARE(tag.tagName(), QString("Button"));
QCOMPARE(tag.attribute("Icon"), QString("../../../gfx/qlc.png"));
QCOMPARE(tag.attribute("Caption"), QString("Foobar"));
QDomNode node = tag.firstChild();
while (node.isNull() == false)
{
QDomElement tag = node.toElement();
if (tag.tagName() == "Function")
{
function++;
QCOMPARE(tag.attribute("ID"), QString::number(sc->id()));
}
else if (tag.tagName() == "Action")
{
action++;
QCOMPARE(tag.text(), QString("Flash"));
}
else if (tag.tagName() == "Key")
{
key++;
QCOMPARE(tag.text(), QKeySequence(keySequenceB).toString());
}
else if (tag.tagName() == "Intensity")
{
intensity++;
QCOMPARE(tag.attribute("Adjust"), QString("True"));
QCOMPARE(tag.text(), QString("20"));
}
else if (tag.tagName() == "WindowState")
{
wstate++;
}
else if (tag.tagName() == "Appearance")
{
appearance++;
}
else
{
QFAIL(QString("Unexpected tag: %1").arg(tag.tagName()).toUtf8().constData());
}
node = node.nextSibling();
}
QCOMPARE(function, 1);
QCOMPARE(action, 1);
QCOMPARE(key, 1);
QCOMPARE(intensity, 1);
QCOMPARE(wstate, 1);
QCOMPARE(appearance, 1);
}
示例6: tableReadXML
bool QgsComposerTable::tableReadXML( const QDomElement& itemElem, const QDomDocument& doc )
{
if ( itemElem.isNull() )
{
return false;
}
if ( !QgsFontUtils::setFromXmlChildNode( mHeaderFont, itemElem, "headerFontProperties" ) )
{
mHeaderFont.fromString( itemElem.attribute( "headerFont", "" ) );
}
mHeaderFontColor = QgsSymbolLayerV2Utils::decodeColor( itemElem.attribute( "headerFontColor", "0,0,0,255" ) );
mHeaderHAlignment = QgsComposerTable::HeaderHAlignment( itemElem.attribute( "headerHAlignment", "0" ).toInt() );
if ( !QgsFontUtils::setFromXmlChildNode( mContentFont, itemElem, "contentFontProperties" ) )
{
mContentFont.fromString( itemElem.attribute( "contentFont", "" ) );
}
mContentFontColor = QgsSymbolLayerV2Utils::decodeColor( itemElem.attribute( "contentFontColor", "0,0,0,255" ) );
mLineTextDistance = itemElem.attribute( "lineTextDist", "1.0" ).toDouble();
mGridStrokeWidth = itemElem.attribute( "gridStrokeWidth", "0.5" ).toDouble();
mShowGrid = itemElem.attribute( "showGrid", "1" ).toInt();
//grid color
if ( itemElem.hasAttribute( "gridColor" ) )
{
mGridColor = QgsSymbolLayerV2Utils::decodeColor( itemElem.attribute( "gridColor", "0,0,0,255" ) );
}
else
{
//old style grid color
int gridRed = itemElem.attribute( "gridColorRed", "0" ).toInt();
int gridGreen = itemElem.attribute( "gridColorGreen", "0" ).toInt();
int gridBlue = itemElem.attribute( "gridColorBlue", "0" ).toInt();
int gridAlpha = itemElem.attribute( "gridColorAlpha", "255" ).toInt();
mGridColor = QColor( gridRed, gridGreen, gridBlue, gridAlpha );
}
//restore column specifications
qDeleteAll( mColumns );
mColumns.clear();
QDomNodeList columnsList = itemElem.elementsByTagName( "displayColumns" );
if ( columnsList.size() > 0 )
{
QDomElement columnsElem = columnsList.at( 0 ).toElement();
QDomNodeList columnEntryList = columnsElem.elementsByTagName( "column" );
for ( int i = 0; i < columnEntryList.size(); ++i )
{
QDomElement columnElem = columnEntryList.at( i ).toElement();
QgsComposerTableColumn* column = new QgsComposerTableColumn;
column->readXML( columnElem );
mColumns.append( column );
}
}
//restore general composer item properties
QDomNodeList composerItemList = itemElem.elementsByTagName( "ComposerItem" );
if ( composerItemList.size() > 0 )
{
QDomElement composerItemElem = composerItemList.at( 0 ).toElement();
_readXML( composerItemElem, doc );
}
return true;
}
示例7: load
bool Profile::load(const QString &fileName) {
QDomDocument doc("renamah_profile");
QFile file(fileName);
if (!file.open(QIODevice::ReadOnly)) {
qCritical("Cannot open the profile file");
return false;
}
if (!doc.setContent(&file)) {
qCritical("Error in the XML scheme");
file.close();
return false;
}
file.close();
QDomElement rootElem = doc.firstChildElement("profile");
if (rootElem.isNull()) {
qCritical("Error in format of the profile file");
return false;
}
FilterModel::instance().clear();
QDomElement extensionPolicyElem = rootElem.firstChildElement("extension_policy");
if (!extensionPolicyElem.isNull())
FilterModel::instance().setExtensionPolicy(loadExtensionPolicy(extensionPolicyElem));
// Filters
QDomElement filtersElem = rootElem.firstChildElement("filters");
if (!filtersElem.isNull()) {
QDomElement filterElem = filtersElem.firstChildElement("modifier");
while (!filterElem.isNull()) {
QString factoryName = filterElem.attribute("factory");
core::ModifierFactory *factory = FilterManager::instance().factoryByName(factoryName);
if (factory) {
core::Modifier *modifier = factory->makeModifier();
FilterModel::instance().addModifier(modifier);
FilterModel::instance().setModifierState(modifier, !filterElem.hasAttribute("state") || filterElem.attribute("state").toInt());
bool exclusive = filterElem.attribute("exclusive").toInt();
if (exclusive)
FilterModel::instance().setExclusiveModifier(modifier);
// Properties
QDomElement propElem = filterElem.firstChildElement("properties").firstChildElement("property");
QMap<QString,QPair<QString,QVariant> > properties;
while (!propElem.isNull()) {
QString name = propElem.attribute("name");
QString type = propElem.attribute("type");
QVariant value(propElem.attribute("value"));
properties.insert(name, QPair<QString,QVariant>(type, value));
// To the next prop
propElem = propElem.nextSiblingElement("property");
}
modifier->deserializeProperties(properties);
// Extension policy
QDomElement extensionPolicyElem = filterElem.firstChildElement("extension_policy");
if (!extensionPolicyElem.isNull()) {
FilterModel::instance().setLocalExtensionPolicyEnabled(static_cast<core::Filter*>(modifier), true);
FilterModel::instance().setLocalExtensionPolicy(static_cast<core::Filter*>(modifier), loadExtensionPolicy(extensionPolicyElem));
}
}
// To the next modifier
filterElem = filterElem.nextSiblingElement("modifier");
}
}
return true;
}
示例8: loadChildTextBlocksFromNode
// Sigh. NOT optimal. The only reason that we need to have this
// is so we can create the XMLNodes, if needed.
// would be better if we could create a handler interface that each
// codeblock used so all we have to do here is add the handler
void JavaANTCodeDocument::loadChildTextBlocksFromNode (QDomElement & root)
{
QDomNode tnode = root.firstChild();
QDomElement telement = tnode.toElement();
bool loadCheckForChildrenOK = false;
while (!telement.isNull()) {
QString nodeName = telement.tagName();
if (nodeName == QLatin1String("textblocks")) {
QDomNode node = telement.firstChild();
QDomElement element = node.toElement();
// if there is nothing to begin with, then we don't worry about it
loadCheckForChildrenOK = element.isNull() ? true : false;
while (!element.isNull()) {
QString name = element.tagName();
if (name == QLatin1String("codecomment")) {
CodeComment * block = new XMLCodeComment(this);
block->loadFromXMI(element);
if (!addTextBlock(block))
{
uError()<<"Unable to add codeComment to :"<<this;
delete block;
} else
loadCheckForChildrenOK= true;
} else if (name == QLatin1String("codeaccessormethod") ||
name == QLatin1String("ccfdeclarationcodeblock")) {
QString acctag = element.attribute(QLatin1String("tag"));
// search for our method in the
TextBlock * tb = findCodeClassFieldTextBlockByTag(acctag);
if (!tb || !addTextBlock(tb)) {
uError()<<"Unable to add codeclassfield child method to:"<<this;
// DON'T delete
} else {
loadCheckForChildrenOK= true;
}
} else if (name == QLatin1String("codeblock")) {
CodeBlock * block = newCodeBlock();
block->loadFromXMI(element);
if (!addTextBlock(block)) {
uError()<<"Unable to add codeBlock to :"<<this;
delete block;
} else {
loadCheckForChildrenOK= true;
}
} else if (name == QLatin1String("codeblockwithcomments")) {
CodeBlockWithComments * block = newCodeBlockWithComments();
block->loadFromXMI(element);
if (!addTextBlock(block)) {
uError()<<"Unable to add codeBlockwithcomments to:"<<this;
delete block;
} else {
loadCheckForChildrenOK= true;
}
} else if (name == QLatin1String("header")) {
// do nothing.. this is treated elsewhere
} else if (name == QLatin1String("hierarchicalcodeblock")) {
HierarchicalCodeBlock * block = newHierarchicalCodeBlock();
block->loadFromXMI(element);
if (!addTextBlock(block)) {
uError()<<"Unable to add hierarchicalcodeBlock to:"<<this;
delete block;
} else {
loadCheckForChildrenOK= true;
}
} else if (name == QLatin1String("codeoperation")) {
// find the code operation by id
QString id = element.attribute(QLatin1String("parent_id"),QLatin1String("-1"));
UMLObject * obj = UMLApp::app()->document()->findObjectById(Uml::ID::fromString(id));
UMLOperation * op = obj->asUMLOperation();
if (op) {
CodeOperation * block = 0;
uError() << "TODO: implement CodeGenFactory::newCodeOperation() for JavaANTCodeDocument";
break; // remove when above is implemented
block->loadFromXMI(element);
if (addTextBlock(block)) {
loadCheckForChildrenOK= true;
} else {
uError()<<"Unable to add codeoperation to:"<<this;
block->deleteLater();
}
} else {
uError()<<"Unable to find operation create codeoperation for:"<<this;
}
} else if (name == QLatin1String("xmlelementblock")) {
QString xmltag = element.attribute(QLatin1String("nodeName"),QLatin1String("UNKNOWN"));
XMLElementCodeBlock * block = new XMLElementCodeBlock(this, xmltag);
block->loadFromXMI(element);
if (!addTextBlock(block)) {
uError()<<"Unable to add XMLelement to Java ANT document:"<<this;
delete block;
} else {
loadCheckForChildrenOK= true;
//.........这里部分代码省略.........
示例9: if
ProgInfo *XMLTVParser::parseProgram(QDomElement &element)
{
QString uniqueid, season, episode, totalepisodes;
int dd_progid_done = 0;
ProgInfo *pginfo = new ProgInfo();
QString text = element.attribute("start", "");
fromXMLTVDate(text, pginfo->starttime);
pginfo->startts = text;
text = element.attribute("stop", "");
fromXMLTVDate(text, pginfo->endtime);
pginfo->endts = text;
text = element.attribute("channel", "");
QStringList split = text.split(" ");
pginfo->channel = split[0];
text = element.attribute("clumpidx", "");
if (!text.isEmpty())
{
split = text.split('/');
pginfo->clumpidx = split[0];
pginfo->clumpmax = split[1];
}
for (QDomNode child = element.firstChild(); !child.isNull();
child = child.nextSibling())
{
QDomElement info = child.toElement();
if (!info.isNull())
{
if (info.tagName() == "title")
{
if (info.attribute("lang") == "ja_JP")
{
pginfo->title = getFirstText(info);
}
else if (info.attribute("lang") == "[email protected]")
{
pginfo->title_pronounce = getFirstText(info);
}
else if (pginfo->title.isEmpty())
{
pginfo->title = getFirstText(info);
}
}
else if (info.tagName() == "sub-title" &&
pginfo->subtitle.isEmpty())
{
pginfo->subtitle = getFirstText(info);
}
else if (info.tagName() == "desc" && pginfo->description.isEmpty())
{
pginfo->description = getFirstText(info);
}
else if (info.tagName() == "category")
{
const QString cat = getFirstText(info).toLower();
if (ProgramInfo::kCategoryNone == pginfo->categoryType &&
string_to_myth_category_type(cat) != ProgramInfo::kCategoryNone)
{
pginfo->categoryType = string_to_myth_category_type(cat);
}
else if (pginfo->category.isEmpty())
{
pginfo->category = cat;
}
if (cat == QObject::tr("movie") || cat == QObject::tr("film"))
{
// Hack for tv_grab_uk_rt
pginfo->categoryType = ProgramInfo::kCategoryMovie;
}
}
else if (info.tagName() == "date" && !pginfo->airdate)
{
// Movie production year
QString date = getFirstText(info);
pginfo->airdate = date.left(4).toUInt();
}
else if (info.tagName() == "star-rating" && pginfo->stars.isEmpty())
{
QDomNodeList values = info.elementsByTagName("value");
QDomElement item;
QString stars, num, den;
float rating = 0.0;
// Use the first rating to appear in the xml, this should be
// the most important one.
//
// Averaging is not a good idea here, any subsequent ratings
// are likely to represent that days recommended programmes
// which on a bad night could given to an average programme.
// In the case of uk_rt it's not unknown for a recommendation
// to be given to programmes which are 'so bad, you have to
// watch!'
item = values.item(0).toElement();
//.........这里部分代码省略.........
示例10: parseFile
bool XMLTVParser::parseFile(
QString filename, ChannelInfoList *chanlist,
QMap<QString, QList<ProgInfo> > *proglist)
{
QDomDocument doc;
QFile f;
if (!dash_open(f, filename, QIODevice::ReadOnly))
{
LOG(VB_GENERAL, LOG_ERR,
QString("Error unable to open '%1' for reading.") .arg(filename));
return false;
}
QString errorMsg = "unknown";
int errorLine = 0;
int errorColumn = 0;
if (!doc.setContent(&f, &errorMsg, &errorLine, &errorColumn))
{
LOG(VB_GENERAL, LOG_ERR, QString("Error in %1:%2: %3")
.arg(errorLine).arg(errorColumn).arg(errorMsg));
f.close();
return true;
}
f.close();
QDomElement docElem = doc.documentElement();
QUrl baseUrl(docElem.attribute("source-data-url", ""));
//QUrl sourceUrl(docElem.attribute("source-info-url", ""));
QString aggregatedTitle;
QString aggregatedDesc;
QDomNode n = docElem.firstChild();
while (!n.isNull())
{
QDomElement e = n.toElement();
if (!e.isNull())
{
if (e.tagName() == "channel")
{
ChannelInfo *chinfo = parseChannel(e, baseUrl);
if (!chinfo->xmltvid.isEmpty())
chanlist->push_back(*chinfo);
delete chinfo;
}
else if (e.tagName() == "programme")
{
ProgInfo *pginfo = parseProgram(e);
if (pginfo->startts == pginfo->endts)
{
LOG(VB_GENERAL, LOG_WARNING, QString("Invalid programme (%1), "
"identical start and end "
"times, skipping")
.arg(pginfo->title));
}
else
{
if (pginfo->clumpidx.isEmpty())
(*proglist)[pginfo->channel].push_back(*pginfo);
else
{
/* append all titles/descriptions from one clump */
if (pginfo->clumpidx.toInt() == 0)
{
aggregatedTitle.clear();
aggregatedDesc.clear();
}
if (!pginfo->title.isEmpty())
{
if (!aggregatedTitle.isEmpty())
aggregatedTitle.append(" | ");
aggregatedTitle.append(pginfo->title);
}
if (!pginfo->description.isEmpty())
{
if (!aggregatedDesc.isEmpty())
aggregatedDesc.append(" | ");
aggregatedDesc.append(pginfo->description);
}
if (pginfo->clumpidx.toInt() ==
pginfo->clumpmax.toInt() - 1)
{
pginfo->title = aggregatedTitle;
pginfo->description = aggregatedDesc;
(*proglist)[pginfo->channel].push_back(*pginfo);
}
}
}
delete pginfo;
}
}
n = n.nextSibling();
//.........这里部分代码省略.........
示例11: loadShortcuts
void QgsConfigureShortcutsDialog::loadShortcuts()
{
QString fileName = QFileDialog::getOpenFileName( this, tr( "Load shortcuts" ), ".", tr( "XML file (*.xml);; All files (*)" ) );
if ( fileName.isEmpty() )
{
return;
}
QFile file( fileName );
if ( !file.open( QIODevice::ReadOnly | QIODevice::Text ) )
{
QMessageBox::warning( this, tr( "Loading shortcuts" ),
tr( "Cannot read file %1:\n%2." )
.arg( fileName )
.arg( file.errorString() ) );
return;
}
QDomDocument doc;
QString errorStr;
int errorLine;
int errorColumn;
if ( !doc.setContent( &file, true, &errorStr, &errorLine, &errorColumn ) )
{
QMessageBox::information( this, tr( "Loading shortcuts" ),
tr( "Parse error at line %1, column %2:\n%3" )
.arg( errorLine )
.arg( errorColumn )
.arg( errorStr ) );
return;
}
QDomElement root = doc.documentElement();
if ( root.tagName() != "qgsshortcuts" )
{
QMessageBox::information( this, tr( "Loading shortcuts" ),
tr( "The file is not an shortcuts exchange file." ) );
return;
}
QSettings settings;
QString currentLocale;
bool localeOverrideFlag = settings.value( "locale/overrideFlag", false ).toBool();
if ( localeOverrideFlag )
{
currentLocale = settings.value( "locale/userLocale", "en_US" ).toString();
}
else // use QGIS locale
{
currentLocale = QLocale::system().name();
}
if ( root.attribute( "locale" ) != currentLocale )
{
QMessageBox::information( this, tr( "Loading shortcuts" ),
tr( "The file contains shortcuts created with different locale, so you can't use it." ) );
return;
}
QAction* action;
QString actionName;
QString actionShortcut;
QDomElement child = root.firstChildElement();
while ( !child.isNull() )
{
actionName = child.attribute( "name" );
actionShortcut = child.attribute( "shortcut" );
action = QgsShortcutsManager::instance()->actionByName( actionName );
QgsShortcutsManager::instance()->setActionShortcut( action, actionShortcut );
child = child.nextSiblingElement();
}
treeActions->clear();
populateActions();
}
示例12: loadFromXMI
/**
* This method loads the generic parts of the XMI common to most model
* classes. It is not usually reimplemented by child classes.
* Instead, it invokes the load() method which implements the loading
* of the specifics of each child class.
*
* @param element The QDomElement from which to load.
*/
bool UMLObject::loadFromXMI(QDomElement & element)
{
UMLDoc* umldoc = UMLApp::app()->document();
if (umldoc == 0) {
uError() << "umldoc is NULL";
return false;
}
// Read the name first so that if we encounter a problem, the error
// message can say the name.
m_name = element.attribute("name", "");
QString id = element.attribute("xmi.id", "");
if (id.isEmpty() || id == "-1") {
if (m_BaseType == ot_Role) {
// Before version 1.4, Umbrello did not save the xmi.id
// of UMLRole objects.
m_nId = UniqueID::gen();
} else {
uError() << m_name << ": nonexistent or illegal xmi.id";
return false;
}
} else {
Uml::IDType nId = STR2ID(id);
if (m_BaseType == ot_Role) {
// Some older Umbrello versions had a problem with xmi.id's
// of other objects being reused for the UMLRole, see e.g.
// attachment 21179 at http://bugs.kde.org/147988 .
// If the xmi.id is already being used then we generate a new one.
UMLObject *o = umldoc->findObjectById(nId);
if (o) {
uError() << "loadFromXMI(UMLRole): id " << id
<< " is already in use!!! Please fix your XMI file.";
}
}
m_nId = nId;
}
if (element.hasAttribute("documentation")) // for bkwd compat.
m_Doc = element.attribute("documentation", "");
else
m_Doc = element.attribute("comment", ""); //CHECK: need a UML:Comment?
m_Vis = Uml::Visibility::Public;
if (element.hasAttribute("scope")) { // for bkwd compat.
QString scope = element.attribute("scope", "");
if (scope == "instance_level") // nsuml compat.
m_bStatic = false;
else if (scope == "classifier_level") // nsuml compat.
m_bStatic = true;
else {
int nScope = scope.toInt();
switch (nScope) {
case 200:
m_Vis = Uml::Visibility::Public;
break;
case 201:
m_Vis = Uml::Visibility::Private;
break;
case 202:
m_Vis = Uml::Visibility::Protected;
break;
default:
uError() << m_name << ": illegal scope " << nScope;
}
}
} else {
QString visibility = element.attribute("visibility", "public");
if (visibility == "private"
|| visibility == "private_vis") // for compatibility with other programs
m_Vis = Uml::Visibility::Private;
else if (visibility == "protected"
|| visibility == "protected_vis") // for compatibility with other programs
m_Vis = Uml::Visibility::Protected;
else if (visibility == "implementation")
m_Vis = Uml::Visibility::Implementation;
}
QString stereo = element.attribute("stereotype", "");
if (!stereo.isEmpty()) {
Uml::IDType stereoID = STR2ID(stereo);
m_pStereotype = umldoc->findStereotypeById(stereoID);
if (m_pStereotype) {
m_pStereotype->incrRefCount();
} else {
uDebug() << m_name << ": UMLStereotype " << ID2STR(stereoID)
<< " not found, creating now.";
setStereotype(stereo);
}
}
if (element.hasAttribute("abstract")) { // for bkwd compat.
QString abstract = element.attribute("abstract", "0");
m_bAbstract = (bool)abstract.toInt();
//.........这里部分代码省略.........
示例13:
ViewGeometry::ViewGeometry(QDomElement & geometry) {
m_wireFlags = (WireFlags) geometry.attribute("wireFlags").toInt();
m_z = geometry.attribute("z").toDouble();
m_loc.setX(geometry.attribute("x").toDouble());
m_loc.setY(geometry.attribute("y").toDouble());
QString x1 = geometry.attribute("x1");
if (!x1.isEmpty()) {
m_line.setLine( geometry.attribute("x1").toDouble(),
geometry.attribute("y1").toDouble(),
geometry.attribute("x2").toDouble(),
geometry.attribute("y2").toDouble() );
}
QString w = geometry.attribute("width");
if (!w.isEmpty()) {
m_rect.setX(geometry.attribute("x").toDouble());
m_rect.setY(geometry.attribute("y").toDouble());
m_rect.setWidth(geometry.attribute("width").toDouble());
m_rect.setHeight(geometry.attribute("height").toDouble());
}
GraphicsUtils::loadTransform(geometry.firstChildElement("transform"), m_transform);
}
示例14: loadFromDom
void ThymioVisualProgramming::loadFromDom(const QDomDocument& document, bool fromFile)
{
scene->clear();
QDomNode domNode = document.documentElement().firstChild();
while (!domNode.isNull())
{
if (domNode.isElement())
{
QDomElement element = domNode.toElement();
if (element.tagName() == "settings")
{
if( element.attribute("advanced-mode") == "true" )
advancedMode();
else
{
advancedButton->setEnabled(true);
actionButtons.last()->hide(); // state button
scene->setAdvanced(false);
}
colorComboButton->setCurrentIndex(element.attribute("color-scheme").toInt());
}
else if(element.tagName() == "buttonset")
{
QString buttonName;
ThymioButton *eventButton = 0;
ThymioButton *actionButton = 0;
if( !(buttonName = element.attribute("event-name")).isEmpty() )
{
if ( buttonName == "button" )
eventButton = new ThymioButtonsEvent(0,scene->getAdvanced());
else if ( buttonName == "prox" )
eventButton = new ThymioProxEvent(0,scene->getAdvanced());
else if ( buttonName == "proxground" )
eventButton = new ThymioProxGroundEvent(0,scene->getAdvanced());
else if ( buttonName == "tap" )
{
eventButton = new ThymioTapEvent(0,scene->getAdvanced());
eventButton->setSharedRenderer(tapSvg);
}
else if ( buttonName == "clap" )
{
eventButton = new ThymioClapEvent(0,scene->getAdvanced());
eventButton->setSharedRenderer(clapSvg);
}
else
{
QMessageBox::warning(this,tr("Loading"),
tr("Error in XML source file: %0 unknown event type").arg(buttonName));
return;
}
for(int i=0; i<eventButton->getNumButtons(); ++i)
eventButton->setClicked(i,element.attribute(QString("eb%0").arg(i)).toInt());
eventButton->setState(element.attribute("state").toInt());
}
if( !(buttonName = element.attribute("action-name")).isEmpty() )
{
if ( buttonName == "move" )
actionButton = new ThymioMoveAction();
else if ( buttonName == "color" )
actionButton = new ThymioColorAction();
else if ( buttonName == "circle" )
actionButton = new ThymioCircleAction();
else if ( buttonName == "sound" )
actionButton = new ThymioSoundAction();
else if ( buttonName == "memory" )
actionButton = new ThymioMemoryAction();
else
{
QMessageBox::warning(this,tr("Loading"),
tr("Error in XML source file: %0 unknown event type").arg(buttonName));
return;
}
for(int i=0; i<actionButton->getNumButtons(); ++i)
actionButton->setClicked(i,element.attribute(QString("ab%0").arg(i)).toInt());
}
scene->addButtonSet(eventButton, actionButton);
}
}
domNode = domNode.nextSibling();
}
scene->setModified(!fromFile);
if (!scene->isEmpty())
QTimer::singleShot(0, this, SLOT(exec()));
}
示例15: loader
bool Function::loader(const QDomElement& root, Doc* doc)
{
if (root.tagName() != KXMLQLCFunction)
{
qWarning("Function node not found!");
return false;
}
/* Get common information from the tag's attributes */
quint32 id = root.attribute(KXMLQLCFunctionID).toUInt();
QString name = root.attribute(KXMLQLCFunctionName);
Type type = Function::stringToType(root.attribute(KXMLQLCFunctionType));
QString path;
if (root.hasAttribute(KXMLQLCFunctionPath))
path = root.attribute(KXMLQLCFunctionPath);
/* Check for ID validity before creating the function */
if (id == Function::invalidId())
{
qWarning() << Q_FUNC_INFO << "Function ID" << id << "is not allowed.";
return false;
}
/* Create a new function according to the type */
Function* function = NULL;
if (type == Function::Scene)
function = new class Scene(doc);
else if (type == Function::Chaser)
function = new class Chaser(doc);
else if (type == Function::Collection)
function = new class Collection(doc);
else if (type == Function::EFX)
function = new class EFX(doc);
else if (type == Function::Script)
function = new class Script(doc);
else if (type == Function::RGBMatrix)
function = new class RGBMatrix(doc);
else if (type == Function::Show)
function = new class Show(doc);
else if (type == Function::Audio)
function = new class Audio(doc);
else
return false;
function->setName(name);
function->setPath(path);
if (function->loadXML(root) == true)
{
if (doc->addFunction(function, id) == true)
{
/* Success */
return true;
}
else
{
qWarning() << "Function" << name << "cannot be created.";
delete function;
return false;
}
}
else
{
qWarning() << "Function" << name << "cannot be loaded.";
delete function;
return false;
}
}