bool LocalXmlBackend::domToTodo(const QDomDocument &doc, OpenTodoList::ITodo *todo) { QDomElement root = doc.documentElement(); if ( !root.isElement() ) { return false; } todo->setUuid( QUuid( root.attribute( "id" ) ) ); todo->setTitle( root.attribute( "title" ) ); if ( root.hasAttribute( "done" ) ) { todo->setDone( root.attribute( "done", "true" ) == "true" ); } else { // TODO: Remove this in 0.3 release todo->setDone( root.attribute( "progress", 0 ).toInt() >= 100 ); } todo->setPriority( qBound( -1, root.attribute( "priority", QString::number(todo->priority()) ).toInt(), 10 ) ); if ( root.hasAttribute( "dueDate" ) ) { todo->setDueDate( QDateTime::fromString( root.attribute( "dueDate" ) ) ); } else { todo->setDueDate( QDateTime() ); } todo->setWeight( root.attribute( "weight", QString::number( todo->weight() ) ).toDouble() ); QDomElement description = root.firstChildElement( "description" ); if ( description.isElement() ) { todo->setDescription( description.text() ); } return true; }
bool LocalXmlBackend::todoToDom(const OpenTodoList::ITodo *todo, QDomDocument &doc) { QDomElement root = doc.documentElement(); if ( !root.isElement() ) { root = doc.createElement( "todo" ); doc.appendChild( root ); } root.setAttribute( "id", todo->uuid().toString() ); root.setAttribute( "title", todo->title() ); root.setAttribute( "done", todo->done() ? "true" : "false" ); root.setAttribute( "priority", todo->priority() ); root.setAttribute( "weight", todo->weight() ); if ( todo->dueDate().isValid() ) { root.setAttribute( "dueDate", todo->dueDate().toString() ); } else { root.removeAttribute( "dueDate" ); } QDomElement descriptionElement = root.firstChildElement( "description" ); if ( !descriptionElement.isElement() ) { descriptionElement = doc.createElement( "description" ); root.appendChild( descriptionElement ); } while ( !descriptionElement.firstChild().isNull() ) { descriptionElement.removeChild( descriptionElement.firstChild() ); } QDomText descriptionText = doc.createTextNode( todo->description() ); descriptionElement.appendChild( descriptionText ); return true; }
void CFuncHelper::onRefreshAll() { m_listFuncs.clear(); QString qsPath = qApp->applicationDirPath() + "/Funcs.xml"; QFile file(qsPath); if(!file.open(QFile::ReadOnly)) return; QDomDocument doc; doc.setContent(file.readAll()); file.close(); QDomElement eleRoot = doc.firstChildElement("funcs"); if(!eleRoot.isElement()) return; QDomElement eleFunc = eleRoot.firstChildElement("func"); while(eleFunc.isElement()) { QDomElement eleName = eleFunc.firstChildElement("name"); QDomElement eleDesc = eleFunc.firstChildElement("desc"); if(eleName.isElement() && eleDesc.isElement()) { QListWidgetItem* pItem = new QListWidgetItem(eleName.text()); pItem->setData(Qt::UserRole,eleDesc.text()); m_listFuncs.addItem(pItem); } eleFunc = eleFunc.nextSiblingElement("func"); } }
bool FotowallFile::read(const QString & fwFilePath, Canvas * canvas, bool inHistory) { // open the file for reading QFile file(fwFilePath); if (!file.open(QIODevice::ReadOnly)) { QMessageBox::critical(0, QObject::tr("Loading error"), QObject::tr("Unable to load the Fotowall file %1").arg(fwFilePath)); return false; } // load the DOM QString error; QDomDocument doc; if (!doc.setContent(&file, false, &error)) { QMessageBox::critical(0, QObject::tr("Parsing error"), QObject::tr("Unable to parse the Fotowall file %1. The error was: %2").arg(fwFilePath, error)); return false; } file.close(); // get the Canvas node QDomElement root = doc.documentElement(); QDomElement canvasElement = root.firstChildElement("canvas"); if (!canvasElement.isElement()) // 'Format 1' canvasElement = root; if (!canvasElement.isElement()) return false; // restore the canvas canvas->setFilePath(fwFilePath); canvas->loadFromXml(canvasElement); // add to the recent history if (inHistory) App::settings->addRecentFotowallUrl(QUrl(fwFilePath)); return true; }
QString DocParser::documentation(const AbstractMetaEnumValue *java_enum_value) const { if (!m_dom) return QString(); QDomElement root_node = m_dom->documentElement(); QDomNodeList enums = root_node.elementsByTagName("enum"); for (int i = 0; i < enums.size(); ++i) { QDomNode node = enums.item(i); QDomElement *e = (QDomElement *) & node; Q_ASSERT(e->isElement()); QDomNodeList enumValues = e->elementsByTagName("enum-value"); for (int j = 0; j < enumValues.size(); ++j) { QDomNode node = enumValues.item(j); QDomElement *ev = (QDomElement *) & node; if (ev->attribute("name") == java_enum_value->name()) { return ev->attribute("doc"); } } } return QString(); }
void ReadAttributes(QObject* obj,QDomElement& el) { QDomElement prop = el.firstChildElement("property"); while (prop.isElement()) { QString propName = prop.attribute("name"); int propIndx = obj->metaObject()->indexOfProperty(propName.toLatin1().constData()); if (propIndx>=0 && propIndx<obj->metaObject()->propertyCount()) { QMetaProperty metaProperty(obj->metaObject()->property(propIndx)); QString valueStr = prop.attribute("value"); if (metaProperty.type()==QVariant::String) { metaProperty.write(obj,valueStr); } else if (metaProperty.type()==QVariant::Int) { metaProperty.write(obj,valueStr.toInt()); } else if (metaProperty.type()==QVariant::UInt) { metaProperty.write(obj,valueStr.toUInt()); } else if (metaProperty.type()==QVariant::Double) { metaProperty.write(obj,valueStr.toDouble()); } else if (metaProperty.type()==QVariant::Bool) { metaProperty.write(obj,bool(valueStr.toInt())); } else if (metaProperty.type()==QVariant::Point) { QStringList sl = valueStr.split(";"); metaProperty.write(obj,QPoint(sl.first().toInt(),sl.last().toInt())); } else if (metaProperty.type()==QVariant::PointF) { QStringList sl = valueStr.split(";"); metaProperty.write(obj,QPoint(sl.first().toDouble(),sl.last().toDouble())); } else if (metaProperty.type()==QVariant::Size) { QStringList sl = valueStr.split(";"); metaProperty.write(obj,QSize(sl.first().toInt(),sl.last().toInt())); } else if (metaProperty.type()==QVariant::SizeF) { QStringList sl = valueStr.split(";"); metaProperty.write(obj,QSizeF(sl.first().toDouble(),sl.last().toDouble())); } } prop = prop.nextSiblingElement("property"); } }
void LinguistExportPlugin::setContext( QDomDocument& doc, QString newContext ) { // Nothing to do here. if ( newContext == context ) return; // Find out whether there is already such a context in the QDomDocument. QDomNode node = doc.documentElement( ).firstChild( ); while ( !node.isNull( ) ) { if ( node.isElement( ) ) { QDomElement elem = node.firstChild( ).toElement( ); if ( elem.isElement( ) && elem.tagName( ) == "name" && elem.text( ) == newContext ) { // We found the context. context = newContext; contextElement = node.toElement( ); // Nothing more to do. return; } } node = node.nextSibling( ); } // Create new context element. contextElement = doc.createElement( "context" ); doc.documentElement( ).appendChild( contextElement ); // Appropriate name element. QDomElement nameElement = doc.createElement( "name" ); QDomText text = doc.createTextNode( newContext ); nameElement.appendChild( text ); contextElement.appendChild( nameElement ); // Store new context. context = newContext; }
/** * Helper function to parse a matrix. Example matrix: * * <matrix> * <row a="1" b="0" c="0" d="0"/> * <row a="0" b="1" c="0" d="0"/> * <row a="0" b="0" c="1" d="0"/> * <row a="0" b="0" c="0" d="1"/> * </matrix> */ bool parseMatrix(const QDomElement &matrix, double m[16]) { QDomNode childNode = matrix.firstChild(); int row = 0; while (!childNode.isNull()) { QDomElement e = childNode.toElement(); if (e.isElement()) { float a, b, c, d; if (!parseQuadruple(e, a, b, c, d, "a", "b", "c", "d") && !parseQuadruple(e, a, b, c, d, "v1", "v2", "v3", "v4")) { PARSE_ERROR(e); return false; } m[row*4 + 0] = a; m[row*4 + 1] = b; m[row*4 + 2] = c; m[row*4 + 3] = d; if (++row == 4) break; } childNode = childNode.nextSibling(); } return (row == 4); }
bool PictureContent::fromXml(QDomElement & pe) { AbstractContent::fromXml(pe); // load picture properties QString path = pe.firstChildElement("path").text(); // build the afterload effects list m_afterLoadEffects.clear(); QDomElement effectsE = pe.firstChildElement("effects"); for (QDomElement effectE = effectsE.firstChildElement("effect"); effectE.isElement(); effectE = effectE.nextSiblingElement("effect")) { PictureEffect fx; fx.effect = (PictureEffect::Effect)effectE.attribute("type").toInt(); fx.param = effectE.attribute("param").toDouble(); if (fx.effect == PictureEffect::Opacity) setOpacity(fx.param); else if (fx.effect == PictureEffect::Crop) { QString rect = effectE.attribute("cropingRect"); QStringList coordinates = rect.split(" "); if(coordinates.size() >= 3) { QRect cropingRect (coordinates.at(0).toInt(), coordinates.at(1).toInt(), coordinates.at(2).toInt(), coordinates.at(3).toInt()); fx.cropingRect = cropingRect; } } m_afterLoadEffects.append(fx); } // load Network image if (path.startsWith("http", Qt::CaseInsensitive) || path.startsWith("ftp", Qt::CaseInsensitive)) return loadFromNetwork(path, 0); // load Local image return loadPhoto(path); }
void tst_ICheck::doTests() { QString msg; QString xmltestfile = getTestFileFolder(); xmltestfile += "/Test.xml"; QFile xmlfile(xmltestfile); bool failed = false; if (xmlfile.exists()){ QDomDocument document; if (document.setContent(&xmlfile)) { QDomElement rootnd = document.documentElement(); if(rootnd.isElement()){ QDomNodeList nodeList = rootnd.childNodes(); for(int i = 0; i < nodeList.count(); i++){ QDomNode nd = nodeList.at(i); TestCase test(nd); if(!test.run()){ QWARN(test.getErrorMsg().toLatin1()); failed = true; } } } } } else { QFAIL ( QString(xmltestfile + " file not found").toLatin1() ); } if(failed) QFAIL ( "Test failed, please read warnings!" ); }
bool XmlState::readOrCreateIdentifier(const QDomElement& el) { if (!el.isElement()) { return false; } QDomElement eId = el.firstChildElement(QLatin1String("Sky:Id")); if (eId.isElement()) { mId = eId.text(); } if (!mId.isValid()) { mId = QUuid::createUuid().toString(); } return true; }
/** * @brief UpdateNamePosition save new position label to the pattern file. * @param mx label bias x axis. * @param my label bias y axis. */ void VToolPoint::UpdateNamePosition(qreal mx, qreal my) { QDomElement domElement = doc->elementById(QString().setNum(id)); if (domElement.isElement()) { doc->SetAttribute(domElement, AttrMx, qApp->fromPixel(mx)); doc->SetAttribute(domElement, AttrMy, qApp->fromPixel(my)); emit toolhaveChange(); } }
bool LocalXmlBackend::domToTodoList(const QDomDocument &doc, OpenTodoList::ITodoList *list) { QDomElement root = doc.documentElement(); if ( !root.isElement() ) { return false; } list->setUuid( QUuid( root.attribute( "id", list->uuid().toString() ) ) ); list->setName( root.attribute( "name", list->name() ) ); return true; }
bool TextContent::fromXml(QDomElement & contentElement, const QDir & baseDir) { // FIRST load text properties and shape // NOTE: order matters here, we don't want to override the size restored later QString text = contentElement.firstChildElement("html-text").text(); setHtml(text); // load default font QDomElement domElement; domElement = contentElement.firstChildElement("default-font"); if (domElement.isElement()) { QFont font; font.setFamily(domElement.attribute("font-family")); font.setPointSize(domElement.attribute("font-size").toInt()); m_text->setDefaultFont(font); } // load shape domElement = contentElement.firstChildElement("shape"); if (domElement.isElement()) { bool shapeEnabled = domElement.attribute("enabled").toInt(); domElement = domElement.firstChildElement("control-points"); if (shapeEnabled && domElement.isElement()) { QList<QPointF> points; QStringList strPoint; strPoint = domElement.attribute("one").split(" "); points << QPointF(strPoint.at(0).toFloat(), strPoint.at(1).toFloat()); strPoint = domElement.attribute("two").split(" "); points << QPointF(strPoint.at(0).toFloat(), strPoint.at(1).toFloat()); strPoint = domElement.attribute("three").split(" "); points << QPointF(strPoint.at(0).toFloat(), strPoint.at(1).toFloat()); strPoint = domElement.attribute("four").split(" "); points << QPointF(strPoint.at(0).toFloat(), strPoint.at(1).toFloat()); m_shapeEditor->setControlPoints(points); } } // THEN restore the geometry AbstractContent::fromXml(contentElement, baseDir); return true; }
bool LocalXmlBackend::todoListToDom(const OpenTodoList::ITodoList *list, QDomDocument &doc) { QDomElement root = doc.documentElement(); if ( !root.isElement() ) { root = doc.createElement( "todoList" ); doc.appendChild( root ); } root.setAttribute( "id", list->uuid().toString() ); root.setAttribute( "name", list->name() ); return true; }
/** * @brief FullUpdateFromFile update tool data form file. */ void VToolAlongLine::FullUpdateFromFile() { QDomElement domElement = doc->elementById(QString().setNum(id)); if (domElement.isElement()) { typeLine = domElement.attribute(AttrTypeLine, ""); formula = domElement.attribute(AttrLength, ""); basePointId = domElement.attribute(AttrFirstPoint, "").toUInt(); secondPointId = domElement.attribute(AttrSecondPoint, "").toUInt(); } RefreshGeometry(); }
bool XmlState::readChildren(const QDomElement& elParent, ChildTypes allowed) { QStringList tags; QStringList skipTags; if (allowed & CTContainers) { tags << QLatin1String("Sky:Splitter") << QLatin1String("Sky:Tab"); } if (allowed & CTViews) { tags << QLatin1String("Sky:View"); } if (allowed & CTWindows) { tags << QLatin1String("Sky:Window"); } skipTags << QLatin1String("Sky:Id") << QLatin1String("Sky:Horizontal") << QLatin1String("Sky:Vertical") << QLatin1String("Sky:Top") << QLatin1String("Sky:Left") << QLatin1String("Sky:Bottom") << QLatin1String("Sky:Right"); QDomElement e = elParent.firstChildElement(); while (e.isElement()) { QString tag = e.tagName(); if (!skipTags.contains(tag)) { if (tags.contains(tag)) { XmlState::Ptr child = read(e); if (!child) { qDebug() << "Could not read a" << tag; return false; } append(child); } else { qDebug() << "Ignoring invalid XmlState-Tag: " << tag; } } e = e.nextSiblingElement(); } return true; }
/** * @brief RefreshDataInFile refresh attributes in file. If attributes don't exist create them. */ void VToolUnionDetails::RefreshDataInFile() { QDomElement domElement = doc->elementById(QString().setNum(id)); if (domElement.isElement()) { doc->SetAttribute(domElement, AttrIndexD1, indexD1); doc->SetAttribute(domElement, AttrIndexD2, indexD2); QDomNode domNode = domElement.firstChild(); domNode = UpdateDetail(domNode, d1); UpdateDetail(domNode, d2); } }
void LanguagesManager::onePluginAdded(const PluginsAvailable &plugin) { if(plugin.category!=PluginType_Languages) return; ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,"start"); QDomElement child = plugin.categorySpecific.firstChildElement("fullName"); LanguagesAvailable temp; if(!child.isNull() && child.isElement()) temp.fullName=child.text(); child = plugin.categorySpecific.firstChildElement("shortName"); while(!child.isNull()) { if(child.isElement()) { if(child.hasAttribute("mainCode") && child.attribute("mainCode")=="true") temp.mainShortName=child.text(); temp.shortName<<child.text(); } child = child.nextSiblingElement("shortName"); } temp.path=plugin.path; if(temp.fullName.isEmpty()) ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Warning,"fullName empty for: "+plugin.path); else if(temp.path.isEmpty()) ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Warning,"path empty for: "+plugin.path); else if(temp.mainShortName.isEmpty()) ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Warning,"mainShortName empty for: "+plugin.path); else if(temp.shortName.size()<=0) ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Warning,"temp.shortName.size()<=0 for: "+plugin.path); else if(!QFile::exists(temp.path+"flag.png")) ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Warning,"flag file not found for: "+plugin.path); else if(!QFile::exists(temp.path+"translation.qm") && temp.mainShortName!="en") ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Warning,"translation not found for: "+plugin.path); else LanguagesAvailableList<<temp; if(plugins->allPluginHaveBeenLoaded()) setCurrentLanguage(getTheRightLanguage()); }
//--------------------------------------------------------------------------------------------------------------------- void DelTool::redo() { QDomElement domElement = doc->elementById(QString().setNum(toolId)); if (domElement.isElement()) { parentNode.removeChild(domElement); emit NeedFullParsing(); } else { qDebug()<<"Can't get tool by id = "<<toolId<<Q_FUNC_INFO; return; } }
/** * @brief RefreshDataInFile refresh attributes in file. If attributes don't exist create them. */ void VToolAlongLine::RefreshDataInFile() { const VPointF *point = VAbstractTool::data.GeometricObject<const VPointF *>(id); QDomElement domElement = doc->elementById(QString().setNum(id)); if (domElement.isElement()) { doc->SetAttribute(domElement, AttrMx, qApp->fromPixel(point->mx())); doc->SetAttribute(domElement, AttrMy, qApp->fromPixel(point->my())); doc->SetAttribute(domElement, AttrName, point->name()); doc->SetAttribute(domElement, AttrTypeLine, typeLine); doc->SetAttribute(domElement, AttrLength, formula); doc->SetAttribute(domElement, AttrFirstPoint, basePointId); doc->SetAttribute(domElement, AttrSecondPoint, secondPointId); } }
/** * @brief RefreshDataInFile refresh attributes in file. If attributes don't exist create them. */ void VToolSpline::RefreshDataInFile() { const VSpline *spl = VAbstractTool::data.GeometricObject<const VSpline *>(id); QDomElement domElement = doc->elementById(QString().setNum(id)); if (domElement.isElement()) { doc->SetAttribute(domElement, AttrPoint1, spl->GetP1().id()); doc->SetAttribute(domElement, AttrPoint4, spl->GetP4().id()); doc->SetAttribute(domElement, AttrAngle1, spl->GetAngle1()); doc->SetAttribute(domElement, AttrAngle2, spl->GetAngle2()); doc->SetAttribute(domElement, AttrKAsm1, spl->GetKasm1()); doc->SetAttribute(domElement, AttrKAsm2, spl->GetKasm2()); doc->SetAttribute(domElement, AttrKCurve, spl->GetKcurve()); } }
bool LocalXmlBackend::domToTask(const QDomDocument &doc, ITask *task) { QDomElement root = doc.documentElement(); if ( !root.isElement() ) { return false; } task->setUuid( QUuid( root.attribute( "id" ) )); task->setDone( root.attribute( "done" ) == "true" ); task->setTitle( root.attribute( "title" ) ); task->setWeight( root.attribute( "weight" ).toDouble() ); return true; }
//--------------------------------------------------------------------------------------------------------------------- void DelTool::undo() { if (cursor <= 0) { parentNode.appendChild(xml); } else { QDomElement refElement = doc->elementById(QString().setNum(cursor)); if (refElement.isElement()) { parentNode.insertAfter(xml, refElement); } } emit NeedFullParsing(); }
bool LocalXmlBackend::taskToDom(const ITask *task, QDomDocument &doc) { QDomElement root = doc.documentElement(); if ( !root.isElement() ) { root = doc.createElement( "task" ); doc.appendChild( root ); } root.setAttribute( "id", task->uuid().toString() ); root.setAttribute( "done", task->done() ? "true" : "false" ); root.setAttribute( "title", task->title() ); root.setAttribute( "weight", task->weight() ); return true; }
/** * @brief RefreshDataInFile refresh attributes in file. If attributes don't exist create them. */ void VToolDetail::RefreshDataInFile() { QDomElement domElement = doc->elementById(QString().setNum(id)); if (domElement.isElement()) { VDetail det = VAbstractTool::data.GetDetail(id); doc->SetAttribute(domElement, AttrName, det.getName()); doc->SetAttribute(domElement, AttrSupplement, QString().setNum(det.getSeamAllowance())); doc->SetAttribute(domElement, AttrClosed, QString().setNum(det.getClosed())); doc->SetAttribute(domElement, AttrWidth, QString().setNum(det.getWidth())); doc->RemoveAllChild(domElement); for (ptrdiff_t i = 0; i < det.CountNode(); ++i) { AddNode(doc, domElement, det.at(i)); } } }
//--------------------------------------------------------------------------------------------------------------------- DelTool::DelTool(VPattern *doc, quint32 id, QUndoCommand *parent) : QObject(), QUndoCommand(parent), xml(QDomElement()), parentNode(QDomNode()), doc(doc), toolId(id), cursor(doc->getCursor()) { setText(tr("Delete tool")); QDomElement domElement = doc->elementById(QString().setNum(id)); if (domElement.isElement()) { xml = domElement.cloneNode().toElement(); parentNode = domElement.parentNode(); } else { qDebug()<<"Can't get tool by id = "<<toolId<<Q_FUNC_INFO; return; } }
//--------------------------------------------------------------------------------------------------------------------- void VAbstractTool::SaveOption(QSharedPointer<VGObject> &obj) { QDomElement oldDomElement = doc->elementById(QString().setNum(id)); if (oldDomElement.isElement()) { QDomElement newDomElement = oldDomElement.cloneNode().toElement(); SaveOptions(newDomElement, obj); SaveToolOptions *saveOptions = new SaveToolOptions(oldDomElement, newDomElement, doc, id); connect(saveOptions, &SaveToolOptions::NeedLiteParsing, doc, &VPattern::LiteParseTree); qApp->getUndoStack()->push(saveOptions); } else { qDebug()<<"Can't find tool with id ="<< id << Q_FUNC_INFO; } }
//--------------------------------------------------------------------------------------------------------------------- void MoveDetail::undo() { QDomElement domElement = doc->elementById(QString().setNum(detId)); if (domElement.isElement()) { doc->SetAttribute(domElement, VAbstractTool::AttrMx, QString().setNum(qApp->fromPixel(oldX))); doc->SetAttribute(domElement, VAbstractTool::AttrMy, QString().setNum(qApp->fromPixel(oldY))); emit NeedLiteParsing(); QList<QGraphicsView*> list = scene->views(); VAbstractTool::NewSceneRect(scene, list[0]); } else { qDebug()<<"Can't find detail with id ="<< detId << Q_FUNC_INFO; return; } }
//--------------------------------------------------------------------------------------------------------------------- void MoveSPoint::redo() { QDomElement domElement = doc->elementById(QString().setNum(sPointId)); if (domElement.isElement()) { doc->SetAttribute(domElement, VAbstractTool::AttrX, QString().setNum(qApp->fromPixel(newX))); doc->SetAttribute(domElement, VAbstractTool::AttrY, QString().setNum(qApp->fromPixel(newY))); emit NeedLiteParsing(); QList<QGraphicsView*> list = scene->views(); VAbstractTool::NewSceneRect(scene, list[0]); } else { qDebug()<<"Can't find spoint with id ="<< sPointId << Q_FUNC_INFO; return; } }