Пример #1
0
void QLCFile_Test::readXML()
{
    QDomDocument doc;

    doc = QLCFile::readXML(QString());
    QVERIFY(doc.isNull() == true);

    doc = QLCFile::readXML("foobar");
    QVERIFY(doc.isNull() == true);

    doc = QLCFile::readXML("broken.xml");
    QVERIFY(doc.isNull() == false);
    QCOMPARE(doc.firstChild().toElement().tagName(), QString("Workspace"));
    QCOMPARE(doc.firstChild().firstChild().toElement().tagName(), QString("Creator"));

	QString path("readonly.xml");
#ifndef WIN32
	QFile::Permissions perms = QFile::permissions(path);
	QFile::setPermissions(path, 0);
    doc = QLCFile::readXML(path);
    QVERIFY(doc.isNull() == true);
	QFile::setPermissions(path, perms);
#endif

    doc = QLCFile::readXML(path);
    QVERIFY(doc.isNull() == false);
    QCOMPARE(doc.firstChild().toElement().tagName(), QString("Workspace"));
    QCOMPARE(doc.firstChild().firstChild().toElement().tagName(), QString("Creator"));
}
Пример #2
0
void AnnotationOutput::writeAnnotations(const QString &fileName, const QMap<uint, QPair<QString, QString> > &a_annotations)
{
  m_annotatedFileItems.clear();
  m_fileNames.clear();
  m_lines.clear();
  m_yourFileItems.clear();
  m_yourFileNames.clear();
  m_yourLines.clear();

  bool modified = false;
  QMap<uint, QPair<QString, QString> > annotations = a_annotations;
  QDomDocument *dom = Project::ref()->dom();
  QDomElement annotationElement = dom->firstChild().firstChild().namedItem("annotations").toElement();
  if (annotationElement.isNull())
  {
    annotationElement = dom->createElement("annotations");
    dom->firstChild().firstChild().appendChild(annotationElement);
  }
  QDomNode n = annotationElement.firstChild();
  while ( !n.isNull() ) 
  {
    QDomElement el = n.toElement();
    QString fName = el.attribute("url");
    QDomNode n2 = n.nextSibling();
    if (fileName == fName)    
    {
      QString text = el.attribute("text");
      bool ok;
      int line = el.attribute("line").toInt(&ok, 10);
      if (!annotations.contains(line) || (annotations[line].first != text))
      {
        n.parentNode().removeChild(n);
        modified = true;
      } else
        annotations.remove(line);
    }
    n = n2;
  }
  for (QMap<uint, QPair<QString, QString> >::ConstIterator it = annotations.constBegin(); it != annotations.constEnd(); ++it)
  {
    QDomElement el = dom->createElement("annotation");
    el.setAttribute("url", fileName);
    el.setAttribute("line", it.key());
    el.setAttribute("text", it.data().first);
    el.setAttribute("receiver", it.data().second.lower());
    annotationElement.appendChild(el);
    modified = true;
  }
  if (modified)
    Project::ref()->setModified(true);
  if (m_allAnnotations->isVisible() || m_yourAnnotations->isVisible())
    readAnnotations();
}
Пример #3
0
QList<QDomElement> TestTShuffle::createSeqList()
{
    QList<QDomElement> list;
    QDomDocument document;
    document.setContent(QString("<img xml:id=\"img0001\" />"));
    list.append(document.firstChild().toElement());
    document.setContent(QString("<img xml:id=\"img0002\" />"));
    list.append(document.firstChild().toElement());
    document.setContent(QString("<img xml:id=\"img0003\" />"));
    list.append(document.firstChild().toElement());
    document.setContent(QString("<img xml:id=\"img0004\" />"));
    list.append(document.firstChild().toElement());
    document.setContent(QString("<img xml:id=\"img0005\" />"));
    list.append(document.firstChild().toElement());
    return list;
}
Пример #4
0
void TestTShuffle::testWithOnePickPerRound()
{
    TShuffle *MyShuffle = new TShuffle(createSeqList());
    QDomDocument document;
    document.setContent(QString("<metadata><meta name=\"adapi:pickingAlgorithm\" content=\"shuffle\"/><meta name=\"adapi:pickingBehavior\" content=\"pickN\"/><meta name=\"adapi:pickNumber\" content=\"1\"/></metadata>"));
    MyShuffle->parse(document.firstChild().toElement());
    QCOMPARE(MyShuffle->canGetNextItem(), true);
    QDomElement element1 = MyShuffle->getNextItem();
    QCOMPARE(MyShuffle->canGetNextItem(), false);
    QDomElement element2 = MyShuffle->getNextItem();
    QCOMPARE(MyShuffle->canGetNextItem(), true);
    QDomElement element3 = MyShuffle->getNextItem();
    QCOMPARE(MyShuffle->canGetNextItem(), false);
    QDomElement element4 = MyShuffle->getNextItem();
    QCOMPARE(MyShuffle->canGetNextItem(), true);
    QDomElement element5 = MyShuffle->getNextItem();
    QCOMPARE(MyShuffle->canGetNextItem(), false);
    QDomElement element6 = MyShuffle->getNextItem();
    QCOMPARE(MyShuffle->canGetNextItem(), true);
    // check if all elements are played in this pass
    QVERIFY(element1 != element2 && element1 != element3  && element1 != element4  && element1 != element5);
    QVERIFY(element2 != element1 && element2 != element3  && element2 != element4  && element2 != element5);
    QVERIFY(element3 != element1 && element3 != element2  && element3 != element4  && element3 != element5);
    QVERIFY(element4 != element1 && element4 != element2  && element4 != element3  && element2 != element5);
    QVERIFY(element5 != element1 && element5 != element2  && element5 != element3  && element5 != element4);
    QVERIFY(element1 == element6);
    return;
}
Пример #5
0
void CXmlPropertyList::readPropertyDocs()
{
    if ( !propertyDocs.isEmpty() )
	return;

    QString docFile = MainWindow::self->documentationPath() + "/propertydocs";
    QFile f( docFile );
    if ( !f.open( IO_ReadOnly ) )
	return;
    QDomDocument doc;
    QString errMsg;
    int errLine;
    if ( !doc.setContent( &f, &errMsg, &errLine ) )
	return;
    QDomElement e = doc.firstChild().toElement().firstChild().toElement();

    for ( ; !e.isNull(); e = e.nextSibling().toElement() ) {
	QDomElement n = e.firstChild().toElement();
	QString name;
	QString doc;
	for ( ; !n.isNull(); n = n.nextSibling().toElement() ) {
	    if ( n.tagName() == "name" )
		name = n.firstChild().toText().data();
	    else if ( n.tagName() == "doc" )
		doc = n.firstChild().toText().data();
	}
	doc.insert( 0, "<p><b>" + name + "</b></p>" );
	propertyDocs.insert( name, doc );
    }
}
Пример #6
0
    int Creature::main(int argc, char** argv) {
        (void) argc;
        (void) argv;
        BasicCreature creature(1);

        QDomDocument doc;
        creature.toXml(doc);
        QString xml = doc.toString();
        //        std::cout << xml.toStdString() << std::endl;
        BDEBUG(xml.toStdString());

        doc.clear();
        QString * error_msg = new QString();
        int* error_line = new int();
        int* error_col = new int();
        doc.setContent(xml, error_msg, error_line, error_col);
        std::cout << "Error: " << error_msg->toStdString() << " at [" << *error_line << " , "
                << *error_col << "]" << std::endl;
        delete error_msg;
        delete error_line;
        delete error_col;

        QDomElement root = doc.firstChild().toElement();
        //        creature.fromXml(root);
        doc.clear();
        creature.toXml(doc);
        xml = doc.toString();
        BDEBUG("******************************");
        BDEBUG(xml.toStdString());
        std::cout << xml.toStdString() << std::endl;
        return 0;
    }
Пример #7
0
bool QtSimpleXml::setContent(QIODevice *device)
{
    QDomDocument doc;
    QString errorMsg;
    int errorLine;
    int errorColumn;
    if (!doc.setContent(device, false, &errorMsg, &errorLine, &errorColumn)) {
        errorStr = errorMsg;
        errorStr += QLatin1String(" at ") + QString::number(errorLine) + QLatin1String(":") + QString::number(errorColumn);
        return false;
    }

    QDomNode child = doc.firstChild();
    while (!child.isNull() && !child.isElement())
        child = child.nextSibling();

    while (!child.isNull()) {
        QtSimpleXml *xmlNode = new QtSimpleXml;
        xmlNode->parse(child);
        xmlNode->parent=this;
        children.insert(xmlNode->name(), xmlNode);
        do {
            child = child.nextSibling();
        } while (!child.isNull() && !child.isElement());
    }

    return true;
}
void AVRStudioXMLParser::Parse(QString configDirPath, Part *pPart)
{
    QXmlQuery query;
    QString result;
    query.bindVariable("partName", QVariant(configDirPath));
    query.setQuery(GetXQuery());
    query.evaluateTo(&result);

    // for future use
    QString errorMsg;
    int line;
    int col;

    QDomDocument doc;
    if(!doc.setContent(result, &errorMsg, &line, &col))
        return;

    QDomNode root = doc.firstChild();
    QDomNode fuses = root.firstChild();
    QDomNode locks = fuses.nextSibling();
    QDomNode interfaces = locks.nextSibling();

    pPart->SetFuseBits(GetBits(fuses.firstChild()));
    pPart->SetLockBits(GetBits(locks.firstChild()));
    pPart->SetProgrammingInterfaces(GetInterfaces(interfaces.firstChild()));
}
Пример #9
0
void Dom::ecrire(QString fileName)
{
    QFile file;
    QDomDocument doc;
    QDomElement sauvegarde;
    QDomElement racine;

    QTextStream out;

    doc.clear();
    racine=doc.createElement("sauvegardes");
    doc.appendChild(racine); // filiation de la balise "sauvegarde"

    file.setFileName(fileName);
    if (!file.open(QIODevice::WriteOnly)) // ouverture du fichier de sauvegarde
        return; // en écriture
    out.setDevice(&file); // association du flux au fichier


    for(int i=0; i<p.size(); i++){
        sauvegarde=doc.createElement("sauvegarde");
        sauvegarde.setAttribute("valeur", p.at(i)->toQString());
        racine.appendChild(sauvegarde);
    }

    QDomNode noeud = doc.createProcessingInstruction("xml","version=\"1.0\"");
    doc.insertBefore(noeud,doc.firstChild());
    // sauvegarde dans le flux (deux espaces de décalage dans l'arborescence)
    doc.save(out,2);
    file.close();
}
Пример #10
0
QDomNode QDomDocumentProto::firstChild() const
{
    QDomDocument *item = qscriptvalue_cast<QDomDocument*>(thisObject());
    if (item)
        return item->firstChild();
    return QDomNode();
}
void CustomWidgetEditor::loadDescription()
{
    QString fn = KFileDialog::getOpenFileName( QString::null, i18n( "*.cw|Custom-Widget Description\n*|All Files" ), this );
    if ( fn.isEmpty() )
	return;

    QFile f( fn );
    if ( !f.open( IO_ReadOnly ) )
	return;

    QDomDocument doc;
    QString errMsg;
    int errLine;
    if ( !doc.setContent( &f, &errMsg, &errLine ) ) {
	qDebug( QString("Parse error: ") + errMsg + QString(" in line %d"), errLine );
	return;
    }

    QDomElement firstWidget = doc.firstChild().toElement().firstChild().toElement();

    while ( firstWidget.tagName() != "customwidgets" )
	firstWidget = firstWidget.nextSibling().toElement();

    Resource::loadCustomWidgets( firstWidget, 0 );
    boxWidgets->clear();
    setupDefinition();
    setupSignals();
    setupSlots();
    setupProperties();
}
Пример #12
0
list<QString> parse_conf (const string& prj_path)
{
  QFile f( QString::fromStdString(prj_path) + QDir::separator()  + "qtapp.xml");
  
  QDomDocument doc;
  if ( !doc.setContent(&f) ) {
    qWarning() << "qtapp: setContent of: "<<f.fileName()<<" FAILED!";
    return list<QString>();
  }
  

  
  list<QString> mp;
  
  QDomNode n = doc.firstChild().firstChild();
  
  //qDebug() << "qtapp: "<<doc.nodeName()<<"n: "<<n.nodeName();
  
  while (!n.isNull()) {
    mp.push_back( n.nodeName() );
    qDebug () << "qtapp: parsing: "<< n.nodeName();
    n = n.nextSibling();
  }
  
  return std::move(mp);
}
Пример #13
0
void DataStorage::save(QFile &file)
{
    QDomDocument doc;
    QDomNode xmlNode = doc.createProcessingInstruction("xml","version=\"1.0\" encoding=\"UTF-8\"");
    doc.insertBefore(xmlNode, doc.firstChild());
    QDomElement opp = doc.createElement("opp");
    opp.setAttribute("title", _projectTitle);
    opp.setAttribute("notes", _projectNotes);
    doc.appendChild(opp);

    QDomElement medias = doc.createElement("medias");
    QDomElement playlists = doc.createElement("playlists");
    QDomElement schedules = doc.createElement("schedules");
    opp.appendChild(medias);
    opp.appendChild(playlists);
    opp.appendChild(schedules);

    /*List of medias*/
    QDomElement media;
    const QList<Media*>& mediaList = _mediaListModel->mediaList();
    foreach(Media* mediaElement, mediaList)
    {
        media= doc.createElement("media");
        media.setAttribute("id",mediaElement->id());
        media.setAttribute("location",mediaElement->location());
        medias.appendChild(media);
    }
Пример #14
0
void tlen::socketReadyRead() {
	kdebugf();
	stream+=socket->readAll();
	stream.prepend("<xmlroot>");
	stream.append("</xmlroot>");

	if( tmpDoc->setContent(stream) || stream.startsWith("<xmlroot><s ") ) {
		qDebug()<<"Read:"<<tmpDoc->toString();

		QDomDocument d;
		d.setContent(stream);
		QDomNode root=d.firstChild();

		if(root.hasChildNodes()) {
			QDomNodeList sl=root.childNodes();
			for(int i=0; i<sl.count(); i++)
				emit eventReceived(sl.item(i));
		}
		tmpDoc->clear();
		stream.clear();
	} else {
		stream.replace("<xmlroot>", "");
		stream.replace("</xmlroot>","");
	}
}
Пример #15
0
QDomDocument Manager::creerXml()
{
    QDomDocument doc;
    QDomNode xmlNode = doc.createProcessingInstruction("xml","version=\"1.0\" encoding=\"UTF-8\"");

    doc.insertBefore(xmlNode, doc.firstChild());

    return doc;
}
Пример #16
0
	void send()
	{
		if(te_input->toPlainText().isEmpty())
			return;

		// construct a "temporary" document to parse the input
		QString str = "<stream xmlns=\"jabber:client\">\n";
		str += te_input->toPlainText() + '\n';
		str += "</stream>";

		QDomDocument doc;
		QString errMsg;
		int errLine, errCol;
		if(!doc.setContent(str, true, &errMsg, &errLine, &errCol)) {
			int lines = str.split('\n', QString::KeepEmptyParts).count();
			--errLine; // skip the first line
			if(errLine == lines-1) {
				errLine = lines-2;
				errCol = textedit_paragraphLength(te_input, errLine-1)+1;
				errMsg = "incomplete input";
			}
			textedit_setCursorPosition(te_input, errLine-1, errCol-1);
			QMessageBox::information(this, tr("Error"), tr("Bad XML input (%1,%2): %3\nPlease correct and try again.").arg(errCol).arg(errLine).arg(errMsg));
			return;
		}
		QDomElement e = doc.firstChild().toElement();

		int num = 0;
		QDomNodeList nl = e.childNodes();
		QList<XMPP::Stanza> stanzaList;
		for(int x = 0; x < nl.count(); ++x) {
			QDomNode n = nl.item(x);
			if(n.isElement()) {
				QDomElement e = n.toElement();
				XMPP::Stanza s = stream->createStanza(e);
				if(s.isNull()) {
					QMessageBox::information(this, tr("Error"), tr("Bad Stanza '%1'.  Must be 'message', 'presence', or 'iq'").arg(e.tagName()));
					return;
				}
				stanzaList += s;
				++num;
			}
		}
		if(num == 0) {
			QMessageBox::information(this, tr("Error"), tr("You must enter at least one stanza!"));
			return;
		}

		// out the door
		for(QList<XMPP::Stanza>::ConstIterator it = stanzaList.begin(); it != stanzaList.end(); ++it) {
			appendXmlOut(XMPP::Stream::xmlToString((*it).element(), true));
			stream->write(*it);
		}

		te_input->setText("");
	}
Пример #17
0
bool ProjectLoader::load(QDomDocument &doc, QString &error) {
	QDomElement root = doc.firstChild().toElement();
	QDomElement objects = root.firstChildElement("objects");

	for(QDomNode node = objects.firstChild(); !node.isNull(); node = node.nextSibling()) {

		QDomElement object = node.toElement();
		QString type = object.attribute("type");

		ScreenObject *obj = 0;
		if (object.attribute("interface") == "mcu") {
			if (!m_mcuManager->hasMCU(type)) {
				error = tr("File you want to load uses MCU module '%1'. This module is not installed or cannot be loaded.").arg(type);
				return false;
			}

			QString variant = object.firstChildElement("variant").text();
			obj = m_mcuManager->getMCU(type).create(variant);
		}
		else if (type == "ConnectionNode") {
			obj = new ConnectionNode();
		}
		else {
			if (!m_perManager->hasPeripheral(type)) {
				error = tr("File you want to load uses Peripheral module '%1'. This module is not installed or cannot be loaded.").arg(type);
				return false;
			}
			obj = m_perManager->getPeripheral(type).create();
		}

		if (!obj) {
			continue;
		}

		obj->load(object, error);
		if (!error.isEmpty()) {
			delete obj;
			return false;
		}

		QDomElement position = object.firstChildElement("position");
		obj->setX(position.attribute("x").toInt());
		obj->setY(position.attribute("y").toInt());

		if (!m_mcu) {
			m_mcu = dynamic_cast<MCU *>(obj);
			m_objects.append(obj);
		}
		else {
			m_objects.append(obj);
		}
	}

	return true;
}
Пример #18
0
int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);

    // 新建QDomDocument类对象,它代表一个XML文档
    QDomDocument doc;
    QFile file("../myDOM1/my.xml");
    if (!file.open(QIODevice::ReadOnly)) return 0;
    // 将文件内容读到doc中
    if (!doc.setContent(&file)) {
        file.close();
        return 0;
    }
    // 关闭文件
    file.close();
    // 获得doc的第一个结点,即XML说明
    QDomNode firstNode = doc.firstChild();
    // 输出XML说明,nodeName()为“xml”,nodeValue()为版本和编码信息
    qDebug() << qPrintable(firstNode.nodeName())
             << qPrintable(firstNode.nodeValue());

    // 返回根元素
    QDomElement docElem = doc.documentElement();
    // 返回根节点的第一个子结点
    QDomNode n = docElem.firstChild();
    // 如果结点不为空,则转到下一个节点
    while(!n.isNull())
    {
        // 如果结点是元素
        if (n.isElement())
        {
            // 将其转换为元素
            QDomElement e = n.toElement();
            // 返回元素标记和id属性的值
            qDebug() << qPrintable(e.tagName())
                     << qPrintable(e.attribute("id"));
            // 获得元素e的所有子结点的列表
            QDomNodeList list = e.childNodes();
            // 遍历该列表
            for(int i=0; i<list.count(); i++)
            {
                QDomNode node = list.at(i);
                if(node.isElement())
                    qDebug() << "   "<< qPrintable(node.toElement().tagName())
                             <<qPrintable(node.toElement().text());
            }
        }
        // 转到下一个兄弟结点
        n = n.nextSibling();
    }

    return a.exec();
}
Пример #19
0
QString SVT_Fcml::getSession(const QString &to, const QString &usr
                   ,const QString &pwd,int *error)
{

    //test
#if 0
    QString test="<fcml from=\"router@portal\" to=\"router@cp171,router@cp190,ui7244@portal,ui7245@portal,ui7246@portal\" >"
            "<portal.router.ui7244.is type=\"ui\" active=\"false\"/></fcml>"
            ;
    QDomDocument td;
    td.setContent(test);
    QDomNode tn=td.firstChild();
    QString t;
    int itest=getRetValue(tn,t);
    //test end
#endif



    QString req="<SessionManagement.startSession username=\"%1\" password=\"%2\"/>";
    req=req.arg(usr,pwd);
    const QDomNode &_node=fcmlRequest(QString("netrouter@")+to,req);
    QString desp;
    int itemp=getRetValue(_node,desp);
    QString stemp;
    if(itemp==0)
    {
        QDomNode node=_node.firstChild();
        stemp=node.toElement().attribute("sessionId");
    }
    if(error)
    {
        *error=itemp;
    }

    if(stemp.isEmpty())
    {
        mSession.remove(to);
    }
    else
    {
#ifdef SM_ONLY_ONE_SESSION
        endAllSessions();
#endif
        mSession.insert(to,stemp);
    }
    if(error &&(*error==0)&&stemp.isEmpty())
    {
        *error=FE_SESSION_NOTOK;
    }
    return stemp;
}
Пример #20
0
void Screen::loadTrackedPins(QDomDocument &doc) {
	QDomElement root = doc.firstChild().toElement();
	QDomElement connections = root.firstChildElement("trackedpins");

	for(QDomNode node = connections.firstChild(); !node.isNull(); node = node.nextSibling()) {
		QDomElement c = node.toElement();

		ScreenObject *object = objectFromId(c.attribute("id").toInt());
		int pin = c.attribute("pin").toInt();

		m_trackedPins[object].append(pin);
		onPinTracked(object, pin);
	}
}
Пример #21
0
void
Perso::load_caracteristics(){
    // Initializing xml document class
    QDomDocument doc;
    {
        QFile f("Persos.xml");
        f.open(QIODevice::ReadOnly);
        doc.setContent(&f);
        f.close();
    }

    // Filling data
    {
        QDomElement root=doc.firstChild().toElement();
        QDomElement child=root.firstChild().toElement();

        while(!child.isNull()) {
            if(child.tagName() == "persos") {
                QDomElement enemy_node = child.firstChild().toElement();
                while(!enemy_node.isNull()) {
                    // If we are
                    if (enemy_node.tagName() == "perso" && enemy_node.attribute("id").toStdString()==_name) {
                        QDomElement tag_child = enemy_node.firstChild().toElement();
                        while(!tag_child.isNull()) {
                            if (tag_child.tagName() == "dead") {
                                _dead_equipment.add_money(tag_child.attribute("gold").toInt());
                                _dead_equipment.set_xp(tag_child.attribute("xp").toInt());
                                // TODO _dead_equipment.add_item(new Weapon/Shield("tag_child.attribute("weapon/shield")"));
                            }
                            else if (tag_child.tagName() == "lvl") {
                                if (tag_child.attribute("id").toInt() == _lvl) {
                                    set_HP(tag_child.attribute("HP").toInt());
                                    set_MP(tag_child.attribute("MP").toInt());
                                    set_max_HP(tag_child.attribute("HP").toInt());
                                    set_max_MP(tag_child.attribute("MP").toInt());
                                    set_def(tag_child.attribute("def").toInt());
                                    set_strength(tag_child.attribute("str").toInt());
                                    set_mobility(tag_child.attribute("mob").toInt());
                                }
                            }
                            tag_child = tag_child.nextSibling().toElement();
                        }
                    }
                    enemy_node = enemy_node.nextSibling().toElement();
                }
            }
            child = child.nextSibling().toElement();
        }
    }
}
void ThemeManagerWidget::downloadFinished(QNetworkReply *reply)
{
    //ui->progressBar->setValue(100);
    ui->getListingButton->setDisabled(false);

    QString data = reply->readAll();
    QDomDocument document;
    document.setContent(data);
    qDebug() << data;
    qDebug() << document.firstChild().nodeName();
    QDomElement themeNode = document.firstChild().firstChildElement("theme");
    while (!themeNode.isNull()) {

        QString name = themeNode.attribute("name");
        QString author = themeNode.attribute("author");
        QString version = themeNode.attribute("version");
        QString downloadUrl = themeNode.attribute("downloadurl");
        QString forumId = themeNode.attribute("forumthread");
        bool directDownload = (themeNode.attribute("direct") == "yes");

        QStringList images;
        QDomElement imageNode = themeNode.firstChildElement("preview");
        while (!imageNode.isNull()) {
            qDebug() << "imagaNode" << &imageNode;
            images << imageNode.firstChild().toText().data();
            imageNode = imageNode.nextSiblingElement("preview");
        }
        themeNode = themeNode.nextSiblingElement("theme");

        qDebug() << "before creating themewidget";
        ThemeWidget *widget = new ThemeWidget(name, author, version, downloadUrl, forumId, directDownload);
        qDebug() << "after creating themewidget";
        widget->setImages(images);
        ui->themeWidgets->addWidget(widget);
    }
    ui->scrollAreaWidgetContents->adjustSize();
}
Пример #23
0
void MainWindow::generateMainWidgetsFromXml(const QString &xml)
{
    QDomDocument doc;
    if (!doc.setContent(xml)) {
        qDebug() << "Can't set content main widgets settings";
        return;
    }

    QDomElement widgets = doc.firstChild().toElement().firstChildElement("widgets");

    QDomNodeList list = widgets.childNodes();
    for (int i = 0; i < list.count(); i++) {
        addWidget(list.at(i));
    }
}
void Manager::handlePackage(Base::Package *const pkg)
{
    Server::Connection *cnn = pkg->source();
    // Server::TcpServer *server = cnn->server();
    
    if (pkg->root() == "chat") {

        QDomDocument doc;
        doc.setContent(pkg->xml());
        
        QDomElement element = doc.firstChild().firstChildElement("message");
        element.setAttribute("from", cnn->user()->login());
        cnn->sendToAll(doc);
        pkg->accept();

    } else if (pkg->root() == "notice") {

        QDomDocument doc;
        doc.setContent(pkg->xml());
        
        QDomElement element = doc.firstChild().firstChildElement("message");
        element.setAttribute("from", cnn->user()->login());
        cnn->sendToAll(doc);//TODO: enviar a todos los clientes del proyecto
        pkg->accept();

    } else if (pkg->root() == "wall") {

        QDomDocument doc;
        doc.setContent(pkg->xml());
        QDomElement element = doc.firstChild().firstChildElement("message");
        element.setAttribute("from", cnn->user()->login());
        cnn->sendToAll(doc);
        pkg->accept();

    }
}
Пример #25
0
/* $Desc Extend research for configuration file by building
 *	new document from file pathes. Thos edocuments are then
 *	read as the original was.
 * $Parm p_filename path to the file to read.
 * $Rtrn /.
 */
void XmlBehavior::readFile(const QString& p_filename)
{
	QFile file(p_filename);

	if(file.exists() && file.open(QIODevice::ReadOnly)){
		QDomDocument config;
		if(config.setContent(&file, true))
			from(config.firstChild());
		else
			logE("XmlBehavior::readFile() : parsing error " + p_filename);
		file.close();
	}
	else
		logE("XmlBehavior::readFile() : can't open " + p_filename);
}
Пример #26
0
void save(const char* filename, const Grammar& grammar) {
    QFile file(filename);
    file.open(QFile::WriteOnly);

    QDomDocument doc;
    QDomElement root = doc.createElement("grammar");
    root.setAttribute("version", "1.0");
    root.setAttribute("author", "Gen Nishida");
    doc.appendChild(root);

    save(doc, root, grammar);

    QTextStream out(&file);
    QDomNode xmlNode = doc.createProcessingInstruction("xml", "version=\"1.0\" encoding=\"ISO-8859-1\"");
    doc.insertBefore(xmlNode, doc.firstChild());
    doc.save(out, 4);
}
Пример #27
0
QDomElement Ui3Reader::parse(const QDomDocument &doc)
{
    root = doc.firstChild().toElement();
    widget = QDomElement();

    pixmapLoaderFunction = getPixmapLoaderFunction(doc.firstChild().toElement());
    nameOfClass = getFormClassName(doc.firstChild().toElement());

    uiFileVersion = doc.firstChild().toElement().attribute(QLatin1String("version"));
    stdsetdef = toBool(doc.firstChild().toElement().attribute(QLatin1String("stdsetdef")));

    if (doc.firstChild().isNull() || doc.firstChild().firstChild().isNull())
        return widget;

    QDomElement e = doc.firstChild().firstChild().toElement();
    while (!e.isNull()) {
        if (e.tagName() == QLatin1String("widget")) {
            widget = e;
        } else if (e.tagName() == QLatin1String("pixmapinproject")) {
            externPixmaps = true;
        } else if (e.tagName() == QLatin1String("layoutdefaults")) {
            defSpacing = e.attribute(QLatin1String("spacing"), defSpacing.toString());
            defMargin = e.attribute(QLatin1String("margin"), defMargin.toString());
        } else if (e.tagName() == QLatin1String("layoutfunctions")) {
            defSpacing = e.attribute(QLatin1String("spacing"), defSpacing.toString());
            bool ok;
            defSpacing.toInt(&ok);
            if (!ok) {
                QString buf = defSpacing.toString();
                defSpacing = buf.append(QLatin1String("()"));
            }
            defMargin = e.attribute(QLatin1String("margin"), defMargin.toString());
            defMargin.toInt(&ok);
            if (!ok) {
                QString buf = defMargin.toString();
                defMargin = buf.append(QLatin1String("()"));
            }
        }
        e = e.nextSibling().toElement();
    }

    return widget;
}
Пример #28
0
void Qtfe::save()
{
	QDomDocument doc;
	QDomElement MultiEditor;
	QFile file;
	QTextStream out;

	file.setFileName(filename);
	if (!file.open(QIODevice::WriteOnly))
		return;
	out.setDevice(&file);

	MultiEditor = doc.createElement("Qtfe");
	doc.appendChild(MultiEditor); 

	for(int i=0 ; i<canals.size() ; ++i)
	{
		QDomElement func = doc.createElement("Function");
		MultiEditor.appendChild(func);

		for(int j=0 ; j<canals[i]->getPoints().size() ; ++j)
		{
			QDomElement point = doc.createElement("point");
			func.appendChild(point);
			point.setAttribute("x", QString::number(canals[i]->getPoints()[j]->x()));
			point.setAttribute("y", QString::number(canals[i]->getPoints()[j]->y()));
		}
	}
	for(int i=0 ; i<outputs.size() ; ++i)
	{
		QDomElement output = doc.createElement("Output");
		MultiEditor.appendChild(output);
		output.setAttribute("R",  QString::number(outputs[i]->R));
		output.setAttribute("G",  QString::number(outputs[i]->G));
		output.setAttribute("B",  QString::number(outputs[i]->B));
		output.setAttribute("A",  QString::number(outputs[i]->A));
	}
	
	QDomNode noeud = doc.createProcessingInstruction("xml","version=\"1.0\"");
	doc.insertBefore(noeud,doc.firstChild());

	doc.save(out,2);

	file.close();
}
Пример #29
0
bool Database::addProject(const SProject * project)
{
    QDomDocument db = loadDataBase();
    QDomNode  root = db.firstChild();
    
    root.appendChild(project->infoToXml(db));
    
    QFile file(m_dbfile);
    
    if (file.open(QIODevice::WriteOnly| QIODevice::Text)) {
        QTextStream ts(&file);
        ts << db.toString();
        file.close();
    } else {
        return false;
    }

    return true;
}
Пример #30
0
void MainWindow::generateMenuFromXml(const QString &xml)
{
    QDomDocument doc;
    if (!doc.setContent(xml)) {
        qDebug() << "Can't set content menu settings";
        return;
    }

    QDomElement mainmenu = doc.firstChild().toElement().firstChildElement("mainmenu");

    QDomNodeList list = mainmenu.childNodes();
    for (int i = 0; i < list.count(); i++) {
        QMenu *menu = getMenu(list.at(i));

        if (menu) {
            m_menuBar->addMenu(menu);
        }
    }
}