PDA

View Full Version : QT Nested Sets SQL/XML - categories (tree)



patrik08
12th June 2006, 13:15
I search an idea how to write and read file like this:
http://marmo.ch/user/db_marmo/tree_index_de.xml
http://marmo.ch/user/db_marmo/tree_index_en.xml
http://marmo.ch/user/db_marmo/tree_index_it.xml

add categories add page .... title description ... same as a homepage sitemap

QMap or QMultiMap or class structure data ??
How i can make this? pleas have you any idea?


IMO ... on php5 i make so....
http://ppk.ciz.ch/php_snips/Pulitzer_Category.phps from an example by .... http://www.klempert.de/nested_sets/

wysota
12th June 2006, 13:36
But what exactly is the problem? Use QDomDocument and family...

patrik08
12th June 2006, 13:55
Yes to read ok QDomdocument .... and diplay a tree qwidget... (and attributes edit on pop-up) add category on Qt::CustomContextMenu ...
But on programm I must save / register data array on a Qmap or Qmapmulti ??
to at end rewrite the file exact same + diffs....

QDomdocument dont have XPath to get fast on attribute from a xml file... and must read file from new....

wysota
12th June 2006, 17:45
But on programm I must save / register data array on a Qmap or Qmapmulti ??
to at end rewrite the file exact same + diffs....

What for? Work with a QDomDocument all the way...

QDomdocument dont have XPath to get fast on attribute from a xml file...
I don't quite understand what you mean. If you want to find some grandchild item, just use QDomNode::firstChildElement() and QDomNode::nextSiblingElement() to traverse the tree.


and must read file from new....
I completely don't understand what you mean here... What file? Read when? From "new"? You mean from beginning? What for? If you have the tree in QDomDocument, you don't need to reread the file unless its content changes.

patrik08
12th June 2006, 23:24
and how bring priority up & down on tree ...

IMO
Sorry but i love xml / xslt my CMS http://slide.pulitzer.ch/title.html work only on xml....
mysql work only to search and to admin site....
And i like to bring admin all to qt ... i have enough with browser version xxx and javascripts version xxx to admin page...

if user like to bring moore priority to <subdir>(cat3) and move up how to swap this? from xml code down..?

QDomNode QDomNode::insertBefore ( const QDomNode & newChild, subcat1 )
or
$node->parentNode->replaceChild($frag,$node); ?? cat0,cat3

:) i see all dom function from php is same name as qt.... only DomXPath not exist and AppenddocumentFragment to node... i suppose QTextDocumentFragment is only a qtextedit QTextDocument class...

xml code...



<root>
<topdir name"qt">
<subdir name="libs1"/>
<subdir name="libs2"/>
<subdir name="libs3">
<subdir name="cat0">
<page name="qtstring"/>
</subdir>
<subdir name="cat3">
<page name="stringlist"/>
</subdir>
</subdir>
</topdir>
<topdir name="wx"/>
<subdir name="cat7">
<page name="wxstring"/>
</subdir>
</topdir>
</root>


php5 code



///////////////////////// replace strong to b //////////////////////
$dom->loadHTML($xhtml);
$xp = new DomXPath($dom);
$resulta = $xp->query("//strong");
foreach ($resulta as $node) {
$internal=$node->nodeValue;
$frag = $dom->createElement("b",$internal);
$node->parentNode->replaceChild($frag,$node);
}
///////////////////////// replace strong to b //////////////////////


class XML extends DOMDocument {

function appendXML_or_File($node,$frag) {

if (is_file($frag)) {
$frag = @file_get_contents($frag);
}

$tmpdoc = new self('1.0', 'utf-8');
$tmpdoc->loadXML("<dummyroot>".$this->Remove_Version($frag)."</dummyroot>") or Error_Manager::msg('Error on fragment not possibel to insert xml Fragment!'.htmlentities($frag, ENT_QUOTES),__FILE__,__LINE__);
$newnode = $node->ownerDocument->importNode($tmpdoc->documentElement,true);
$child = $newnode->firstChild;
while ($child) {
$nextChild = $child->nextSibling;
$node->appendChild($child);
$child = $nextChild;
}
}

wysota
12th June 2006, 23:37
if user like to bring moore priority to <subdir>(cat3) and move up how to swap this? from xml code down..?

QDomNode QDomNode::insertBefore ( const QDomNode & newChild, subcat1 )
or
$node->parentNode->replaceChild($frag,$node); ?? cat0,cat3

If you read the docs of those two methods, I'm sure you'll be able to answer that question yourself.


:) i see all dom function from php is same name as qt....
These are standard DOM methods defined in W3C Dom specification (http://www.w3.org/DOM/DOMTR) which is implemented by (among other) both Qt and PHP. So it's not a situation when Qt has the same function names as PHP -- they both implement the same interface (I think first seen in JavaScript).



i suppose QTextDocumentFragment is only a qtextedit QTextDocument class...
QDomDocumentFragment


only DomXPath not exist and AppenddocumentFragment to node
QDomDocumentFragment inherits QDomNode so you can append a document fragment to the tree like any other node.

patrik08
13th June 2006, 00:17
Well done... You are convinced me to build and manage this xml tree on dom and leaving Nested Sets SQL from my mind... all the operations is possibel on qtdomdoc.. i hope...:rolleyes:

OK ... Tanks...

the next battle is QTreeWidgetItem..... and signal from QTreeWidget to find tags...
QTreeWidgetItem *childItem = createItem(child, item);
childItem->setFlags(item->flags() | Qt::ItemIsEditable | Qt::ItemIsautoSave);