gerome69 hat geschrieben:
Nein, nicht wirklich. Das ist vom Prinzip her so wie in dem XML-Example, was bei QT dabei ist. Da ist ein TopLevel-Element und eine 2. Ebene, in der die wesentliche Parameter stehen.
Ich gehe aber von beliebiger Verschachtelungstiefe aus und brauche was Rekursives. Bin da schon am Basteln, wollte aber eben fragen, ob es da nicht schon was fertiges gibt.
Gruß, Bernd
Die while kan endlos sein auch in ene while innen .... oder man kann sich auch eine funktion machen die die ein elemene folgt....
um nicht 20 while ..... macht mann sich eine funktion ..... die dann sich selber ruft wenn noch mehr elemente kommen ..... so etwa wie einen vollen ordner recursive zu loeschen ...
Mit dem dom XML habe ich schnell bemerkt .... mann muss sich das leben einfacher machen .... und QDomDocument erweitern .... um einfach zu lesen ..... && schreiben
wichtig ist immer die QDomDocument in der class header zu haben sowie den root tag....
beim schreieben des xml kann ich sogar file Inhalte zu einen domelement appenden....
QDomElement Qxml::insertFragmentorFile( QString fragment )
aus 10 xml file kann ich einen machen && belibig auslesen .... bis 6MB xml
ist das ganze unter 600 millisekunden beim lesen.... & schreiben....
https://qt-webdav.svn.sourceforge.net/s ... r/qxml.cpp
https://qt-webdav.svn.sourceforge.net/s ... dir/qxml.h
Code: Alles auswählen
/* attribute schnell auslesen ... z.b. */
QString Qxml::GetAtt(QDomElement e , QString name )
{
QString textvalue;
QString errorvalue = "";
QDomAttr a1 = e.attributeNode(name);
textvalue = a1.value();
if (textvalue.size() > 0) {
return textvalue;
} else {
return errorvalue;
}
}
Code: Alles auswählen
QString Form::ComponentPub( QDomElement edi )
{
QString aline;
highter = 0;
QDomElement component = edi.firstChildElement("row");
while (!component.isNull()) {
subpo++;
highter++;
QString hboxlayo = QString("QHBoxLayout *hboxLayout%1;").arg(subpo);
QString subi = QString("%1 *%2;").arg(doc.GetAtt(component,"class")).arg(doc.GetAtt(component,"qtname"));
QString labeling = QString("QLabel *label_%1;").arg(subpo);
/* element */
aline.append("\t"+hboxlayo+"\n");
aline.append("\t"+subi+"\n");
aline.append("\t"+labeling+"\n");
/////qDebug() << "### aclassline "<< subi;
/* element */
component = component.nextSiblingElement("row");
}
return aline;
}
dieses dom xml geht 4 level nach unten...
Code: Alles auswählen
/* automatisch Ui dass eine sql Tabelle zu formular macht beispiel */
/* QGroupBox mit felder in 2 kolonnen .... extract */
sw << "gridLayout = new QGridLayout(wrapper);\n";
sw << "gridLayout->setSpacing(6);\n";
sw << "gridLayout->setMargin(9);\n";
sw << "gridLayout->setObjectName(QString::fromUtf8("gridLayout"));\n";
/////sw << "\n";
sw << "/* start while ..... from groups */\n";
position = 0;
grupi = root.firstChildElement("group");
while (!grupi.isNull()) {
position++;
bclassname = QString("box_%1").arg(position);
classline = bclassname;
classline2 = QString("gridLayout%1").arg(position);
/* groupbox*/
sw << classline << " = new QGroupBox(wrapper);\n";
sw << classline << "->setObjectName(QString::fromUtf8("" << classline << ""));\n";
sw << classline << "->setTitle(QApplication::translate("" << Firstupper(classname) << "", "" << doc.GetAtt(grupi,"trname") << "", 0, QApplication::UnicodeUTF8));\n";
/* groupbox*/
/* gridlayout */
sw << classline2 << " = new QGridLayout(" << classline << ");\n";
sw << classline2 << "->setSpacing(6);\n";
sw << classline2 << "->setMargin(9);\n";
sw << classline2 << "->setObjectName(QString::fromUtf8("" << classline2 << ""));\n";
/* gridlayout */
subpo = 0;
int rere = -1;
component = grupi.firstChildElement("row");
/* noch zum unter element */
while (!component.isNull()) {
subpo++;
summbox++;
QString tipeclass = doc.GetAtt(component,"class");
QString classname6 = doc.GetAtt(component,"qtname");
QString labelname = QString("label_%1").arg(subpo);
QString hboxlayo = QString("hboxLayout%1").arg(subpo);
QString enedit = doc.GetAtt(component,"edit");
sw << "/* zeile append label layou row */\n";
sw << hboxlayo << " = new QHBoxLayout();\n";
sw << hboxlayo << "->setSpacing(6);\n";
sw << hboxlayo << "->setMargin(0);\n";
sw << hboxlayo << "->setObjectName(QString::fromUtf8("" << hboxlayo << ""));\n";
sw << labelname << " = new QLabel(" << classline << ");\n";
/////////// sw << labelname << "->setObjectName(QString::fromUtf8("" << labelname << ""));\n";
sw << labelname << "->setObjectName(QString::fromUtf8("" << labelname << ""));\n";
sw << labelname << "->setText(QApplication::translate("" << Firstupper(classname) << "", "Nr." << doc.GetAtt(component,"id") << " " << Firstupper(doc.GetAtt(component,"name")) << "", 0, QApplication::UnicodeUTF8));\n";
sw << labelname << "->setToolTip(QApplication::translate("" << Firstupper(classname) << "", "" << classname6 << "", 0, QApplication::UnicodeUTF8));\n";
sw << labelname << "->setMaximumWidth(180);\n";
sw << labelname << "->setMinimumWidth(180);\n";
sw << hboxlayo << "->addWidget(" << labelname << ");\n";
sw << classname6 << " = new " << tipeclass << "(" << classline << ");\n";
////////////sw << classname6 << "->setMaximumSize(QSize(200, 16777215));\n";
sw << classname6 << "->setObjectName(QString::fromUtf8("" << classname6 << ""));\n";
sw << classname6 << "->setMaximumWidth(180);\n";
sw << classname6 << "->setMinimumWidth(180);\n";
if ( tipeclass == "QComboBox") {
sw << classname6 << "->clear();\n";
qbox = component.firstChildElement("box");
QDomElement items = qbox.firstChildElement("item");
while (!items.isNull()) {
sw << classname6 << "->addItem("" << doc.GetAtt(items,"value") << "");\n";
items = items.nextSiblingElement("item");
}
if (enedit == "1") {
sw << classname6 << "->setEditable(true);\n";
}
}
if ( tipeclass == "QDateTimeEdit") {
sw << classname6 << "->setDisplayFormat("" << doc.GetAtt(component,"format") << "");\n";
sw << classname6 << "->setCalendarPopup(true);\n";
if (enedit == "0") {
sw << classname6 << "->setReadOnly(true);\n";
}
}
sw << hboxlayo <<"->addWidget(" << classname6 << ");\n";
///////////////sw << "/* zeile append label layou row end */\n";
rere++;
/////////////sw << "/* zeile append zu alles */\n";
sw << classline2 <<"->addLayout(" << hboxlayo << ", " << rere << ", 0, 1, 1);\n";
////////////// sw << "/* zeile append zu alles */\n";
component = component.nextSiblingElement("row");
}
/*
int layoutLF = 0;
int layoutRT = 1;
int QridLine = 0;
*/
sw << "/* ###################layout insert!############################################ */\n";
LinePair++;
if (LinePair == 0) {
sw << "gridLayout->addWidget(" << classline << "," << QridLine << ", 0, Qt::AlignJustify);\n"; /* left */
} else {
sw << "gridLayout->addWidget(" << classline << "," << QridLine << ", 1, Qt::AlignJustify);\n"; /* right */
LinePair = -1;
QridLine++;
}
sw << "/* ###################layout insert!############################################ */\n";
grupi = grupi.nextSiblingElement("group");
}