Changeset View
Changeset View
Standalone View
Standalone View
addons/symbolviewer/xml_parser.cpp
- This file was added.
1 | /*************************************************************************** | ||||
---|---|---|---|---|---|
2 | xml_parser.cpp - Produce a rudimentary list of tags/elements | ||||
3 | present in XML or HTML files. In the tree view of the | ||||
4 | symbolviewer plugin the list is grouped by the element type. | ||||
5 | ------------------- | ||||
6 | begin : May 3 2019 | ||||
7 | author : 20019 Andreas Hohenegger based on | ||||
8 | xslt_parser.cpp by jiri Tyr | ||||
9 | email : hohenegger@gmail.com | ||||
10 | ***************************************************************************/ | ||||
11 | /*************************************************************************** | ||||
12 | * | ||||
13 | * This program is free software; you can redistribute it and/or modify | ||||
14 | * it under the terms of the GNU General Public License as published by | ||||
15 | * the Free Software Foundation; either version 2 of the License, or | ||||
16 | * (at your option) any later version. | ||||
17 | * | ||||
18 | ***************************************************************************/ | ||||
19 | | ||||
20 | #include "plugin_katesymbolviewer.h" | ||||
21 | | ||||
22 | void KatePluginSymbolViewerView::parseXMLSymbols(void) | ||||
23 | { | ||||
24 | if (!m_mainWindow->activeView()) | ||||
25 | return; | ||||
26 | | ||||
27 | m_struct->setText(i18n("Show Tags")); | ||||
28 | | ||||
29 | QString cl; | ||||
30 | QString stripped; | ||||
31 | | ||||
32 | char comment = 0; | ||||
33 | int i; | ||||
34 | | ||||
35 | QPixmap cls( ( const char** ) class_xpm ); | ||||
36 | QPixmap sct( ( const char** ) struct_xpm ); | ||||
37 | | ||||
38 | QTreeWidgetItem *node = nullptr; | ||||
39 | QTreeWidgetItem *topNode = nullptr; | ||||
40 | | ||||
41 | KTextEditor::Document *kv = m_mainWindow->activeView()->document(); | ||||
42 | | ||||
43 | m_symbols->setRootIsDecorated(0); | ||||
44 | | ||||
45 | for (i=0; i<kv->lines(); i++) { | ||||
46 | cl = kv->line(i); | ||||
47 | cl = cl.trimmed(); | ||||
48 | | ||||
49 | if(cl.indexOf(QRegularExpression(QLatin1String("<!--"))) >= 0) { | ||||
50 | comment = 1; | ||||
51 | } | ||||
52 | if(cl.indexOf(QRegularExpression(QLatin1String("-->"))) >= 0) { | ||||
53 | comment = 0; | ||||
54 | continue; | ||||
55 | } | ||||
56 | | ||||
57 | if (comment==1) { | ||||
58 | continue; | ||||
59 | } | ||||
60 | | ||||
61 | if(cl.indexOf(QRegularExpression(QLatin1String("^<[a-zA-Z_]+[a-zA-Z0-9_\\.\\-]*"))) == 0 && m_struct->isChecked()){ | ||||
62 | | ||||
63 | /* Get the tag type */ | ||||
64 | QString type; | ||||
65 | QRegularExpressionMatch match; | ||||
66 | QRegularExpression re(QLatin1String("^<([a-zA-Z_]+[a-zA-Z0-9_\\.\\-]*)")); | ||||
67 | if (cl.contains(re, &match)) | ||||
68 | type = match.captured(1); | ||||
69 | else | ||||
70 | continue; | ||||
71 | | ||||
72 | QString stripped = cl.remove(QRegularExpression(QLatin1String("^<[a-zA-Z_]+[a-zA-Z0-9_\\.\\-]* *"))); | ||||
73 | stripped = stripped.remove(QRegularExpression(QLatin1String(" */*>.*"))); | ||||
74 | | ||||
75 | if (m_treeOn->isChecked()) { | ||||
76 | /* See if group already exists */ | ||||
77 | QList<QTreeWidgetItem*> reslist = m_symbols->findItems(type, Qt::MatchExactly); | ||||
78 | if(reslist.isEmpty()) { | ||||
79 | topNode = new QTreeWidgetItem(m_symbols, QStringList(type)); | ||||
80 | topNode->setIcon(0, QIcon(cls)); | ||||
81 | if (m_expandOn->isChecked()) { | ||||
82 | m_symbols->expandItem(topNode); | ||||
83 | } | ||||
84 | } else { | ||||
85 | topNode = reslist[0]; | ||||
86 | } | ||||
87 | node = new QTreeWidgetItem(topNode); | ||||
88 | topNode->addChild(node); | ||||
89 | } else { | ||||
90 | node = new QTreeWidgetItem(m_symbols); | ||||
91 | } | ||||
92 | node->setIcon(0, QIcon(sct)); | ||||
93 | node->setText(0, stripped); | ||||
94 | node->setText(1, QString::number( i, 10)); | ||||
95 | } | ||||
96 | } | ||||
97 | } |