Skip to content

Commit a2d7222

Browse files
committed
Reformulate conditional inclusions in configuration file
After review
1 parent c6c2e23 commit a2d7222

3 files changed

Lines changed: 48 additions & 51 deletions

File tree

addon/doxywizard/expert.cpp

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -107,15 +107,15 @@ static void translateEnumDescription(QDomElement &valueElem,const QDomElement &t
107107
}
108108
}
109109

110-
static bool getFilter(QDomElement docsVal)
110+
static bool getFilter(QDomElement docsVal, QString &mode)
111111
{
112112
QString attr = docsVal.attribute(SA("filter"));
113113
if (attr.isEmpty()) return true;
114-
if (attr.contains(SA("doxywizard"))) return true;
114+
if (attr.contains(mode)) return true;
115115
return false;
116116
}
117117

118-
static void translateOption(QDomElement &configRoot,const QDomElement &translationRoot)
118+
static void translateOption(QDomElement &configRoot,const QDomElement &translationRoot, QString &mode)
119119
{
120120
QDomElement docsVal = configRoot.firstChildElement();
121121
QDomElement trDocsVal = translationRoot.firstChildElement();
@@ -131,7 +131,7 @@ static void translateOption(QDomElement &configRoot,const QDomElement &translati
131131
while (!docsVal.isNull())
132132
{
133133
//qDebug() << "tagName" << docsVal.tagName();
134-
if (docsVal.tagName()==SA("docs") && getFilter(docsVal))
134+
if (docsVal.tagName()==SA("docs") && getFilter(docsVal, mode))
135135
{
136136
docsVal.removeAttribute(SA("filter"));
137137
// we just need a value so we don't have an empty filter (and thus potential a match on doxywizard later on).
@@ -146,7 +146,7 @@ static void translateOption(QDomElement &configRoot,const QDomElement &translati
146146
}
147147
}
148148

149-
static void translateTopics(QDomElement &configRoot,const QDomElement &translationRoot)
149+
static void translateTopics(QDomElement &configRoot,const QDomElement &translationRoot, QString &mode)
150150
{
151151
struct GroupInfo
152152
{
@@ -206,7 +206,7 @@ static void translateTopics(QDomElement &configRoot,const QDomElement &translati
206206
QString id = optionElem.attribute(SA("id"));
207207
if (groupMap[name].options.contains(id))
208208
{
209-
translateOption(groupMap[name].options[id],optionElem);
209+
translateOption(groupMap[name].options[id],optionElem,mode);
210210
}
211211
else
212212
{
@@ -297,6 +297,8 @@ Expert::Expert()
297297
mainLayout->addWidget(m_searchBox);
298298
mainLayout->addWidget(m_splitter);
299299

300+
QString mode = SA("doxywizard");
301+
300302
QFile file(SA(":/config.xml"));
301303
QString err = tr("Error");
302304
int errLine=0,errCol=0;
@@ -340,7 +342,7 @@ Expert::Expert()
340342
childElem = childElem.nextSiblingElement();
341343
}
342344
// overrule english text with translations
343-
translateTopics(m_rootElement,trConfigXml.documentElement());
345+
translateTopics(m_rootElement,trConfigXml.documentElement(),mode);
344346
}
345347
else
346348
{
@@ -352,7 +354,7 @@ Expert::Expert()
352354
// createGroups() activates group 0 (lazy), but the Wizard needs all m_options
353355
// populated before it is constructed, so we create all cards eagerly here.
354356
createGroups(m_rootElement);
355-
ensureAllGroupsCreated();
357+
ensureAllGroupsCreated(mode);
356358

357359
// --- Wire up signals ---
358360
m_filterTimer = new QTimer(this);
@@ -446,14 +448,14 @@ void Expert::createGroups(const QDomElement &rootElem)
446448
}
447449
}
448450

449-
void Expert::createOptionCard(GroupEntry &group, const QDomElement &child)
451+
void Expert::createOptionCard(GroupEntry &group, const QDomElement &child, QString &mode)
450452
{
451453
QString setting = child.attribute(SA("setting"));
452454
if (!setting.isEmpty() && !IS_SUPPORTED(setting.toLatin1())) return;
453455

454456
QString type = child.attribute(SA("type"));
455457
QString id = child.attribute(SA("id"));
456-
QString docs = getDocsForNode(child);
458+
QString docs = getDocsForNode(child, mode);
457459

458460
// Each option gets its own control layout
459461
QWidget *ctrlWidget = new QWidget;
@@ -668,7 +670,7 @@ void Expert::wireDependencies()
668670
}
669671

670672
// Create option cards for 'group' if they haven't been created yet.
671-
void Expert::ensureGroupCardsCreated(GroupEntry &group)
673+
void Expert::ensureGroupCardsCreated(GroupEntry &group, QString &mode)
672674
{
673675
if (group.cardsCreated) return;
674676
group.cardsCreated = true;
@@ -678,7 +680,7 @@ void Expert::ensureGroupCardsCreated(GroupEntry &group)
678680
{
679681
if (optElem.tagName() == SA("option"))
680682
{
681-
createOptionCard(group, optElem);
683+
createOptionCard(group, optElem, mode);
682684
}
683685
optElem = optElem.nextSiblingElement();
684686
}
@@ -730,11 +732,11 @@ void Expert::setDocumentationVisibility(bool hidden)
730732

731733
// Create cards for every group that hasn't been created yet, then do a full
732734
// dependency update (needed when cross-group deps span newly-created groups).
733-
void Expert::ensureAllGroupsCreated()
735+
void Expert::ensureAllGroupsCreated(QString &mode)
734736
{
735737
for (GroupEntry &group : m_groups)
736738
{
737-
ensureGroupCardsCreated(group);
739+
ensureGroupCardsCreated(group, mode);
738740
}
739741

740742
// Re-run update so cross-group dependencies are fully applied
@@ -783,7 +785,7 @@ void Expert::nextGroup()
783785
}
784786

785787

786-
QString Expert::getDocsForNode(const QDomElement &child) const
788+
QString Expert::getDocsForNode(const QDomElement &child, QString &mode) const
787789
{
788790
QString type = child.attribute(SA("type"));
789791
QString docs = SA("");
@@ -792,7 +794,7 @@ QString Expert::getDocsForNode(const QDomElement &child) const
792794
bool first = true;
793795
while (!docsVal.isNull())
794796
{
795-
if (docsVal.tagName()==SA("docs") && getFilter(docsVal))
797+
if (docsVal.tagName()==SA("docs") && getFilter(docsVal, mode))
796798
{
797799
if (!first) docs += SA("<br/>");
798800
first = false;

addon/doxywizard/expert.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,14 +104,14 @@ class Expert : public QWidget, public DocIntf
104104
};
105105

106106
void createGroups(const QDomElement &rootElem);
107-
void createOptionCard(GroupEntry &group, const QDomElement &child);
108-
void ensureGroupCardsCreated(GroupEntry &group);
109-
void ensureAllGroupsCreated();
107+
void createOptionCard(GroupEntry &group, const QDomElement &child, QString &mode);
108+
void ensureGroupCardsCreated(GroupEntry &group, QString &mode);
109+
void ensureAllGroupsCreated(QString &mode);
110110
void wireDependencies();
111111
void activateGroup(int index);
112112
void saveTopic(QTextStream &t, QDomElement &elem, TextCodecAdapter *codec,
113113
bool brief, bool condensed, bool convert);
114-
QString getDocsForNode(const QDomElement &child) const;
114+
QString getDocsForNode(const QDomElement &child, QString &mode) const;
115115

116116
QSplitter *m_splitter;
117117
QTreeWidget *m_treeWidget;

src/configgen.py

Lines changed: 26 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import glob
2222

2323
messages = {}
24-
mode = ""
2524

2625
# wrapper class to write to file/output in UTF-8 format
2726
class OutputWriter:
@@ -145,8 +144,7 @@ def addValues(var, node):
145144
print(" %s->addValue(\"%s\");" % (var, name))
146145

147146

148-
def getFilter(node):
149-
global mode
147+
def getFilter(node, mode):
150148
attr = node.getAttribute('filter')
151149
if not attr:
152150
return True
@@ -155,12 +153,12 @@ def getFilter(node):
155153
return False
156154

157155

158-
def parseHeader(node,objName):
156+
def parseHeader(node, objName, mode):
159157
doc = ""
160158
for n in node.childNodes:
161159
if n.nodeType == Node.ELEMENT_NODE:
162160
if (n.nodeName == "docs"):
163-
if getFilter(n):
161+
if getFilter(n, mode):
164162
doc += parseDocs(n)
165163
docC = transformDocs(doc)
166164
print(" %s->setHeader(" % (objName))
@@ -174,15 +172,15 @@ def parseHeader(node,objName):
174172
print(" );")
175173

176174

177-
def prepCDocs(node):
175+
def prepCDocs(node, mode):
178176
type = node.getAttribute('type')
179177
format = node.getAttribute('format')
180178
defval = node.getAttribute('defval')
181179
doc = ""
182180
if (type != 'obsolete'):
183181
for n in node.childNodes:
184182
if (n.nodeName == "docs"):
185-
if getFilter(n):
183+
if getFilter(n, mode):
186184
if n.nodeType == Node.ELEMENT_NODE:
187185
doc += parseDocs(n)
188186
if (type == 'enum'):
@@ -253,7 +251,7 @@ def prepCDocs(node):
253251
return docC
254252

255253

256-
def parseOption(node):
254+
def parseOption(node, mode):
257255
# Handling part for Doxyfile
258256
name = node.getAttribute('id')
259257
if len(name)>23:
@@ -264,7 +262,7 @@ def parseOption(node):
264262
depends = node.getAttribute('depends')
265263
setting = node.getAttribute('setting')
266264
orgtype = node.getAttribute('orgtype')
267-
docC = prepCDocs(node)
265+
docC = prepCDocs(node, mode)
268266
if len(setting) > 0:
269267
print("#if %s" % (setting))
270268
print(" //----")
@@ -374,7 +372,7 @@ def parseOption(node):
374372
print("#endif")
375373

376374

377-
def parseGroups(node):
375+
def parseGroups(node, mode):
378376
name = node.getAttribute('name')
379377
doc = node.getAttribute('docs')
380378
setting = node.getAttribute('setting')
@@ -390,7 +388,7 @@ def parseGroups(node):
390388
print("")
391389
for n in node.childNodes:
392390
if n.nodeType == Node.ELEMENT_NODE:
393-
parseOption(n)
391+
parseOption(n, mode)
394392

395393
def parseGroupMapEnums(node):
396394
def escape(value):
@@ -541,12 +539,12 @@ def parseGroupMapInit(node):
541539
if len(setting) > 0:
542540
print("#endif")
543541

544-
def parseGroupCDocs(node):
542+
def parseGroupCDocs(node, mode):
545543
for n in node.childNodes:
546544
if n.nodeType == Node.ELEMENT_NODE:
547545
type = n.getAttribute('type')
548546
name = n.getAttribute('id')
549-
docC = prepCDocs(n)
547+
docC = prepCDocs(n, mode)
550548
if type != 'obsolete':
551549
print(" doc->add(")
552550
print(" \"%s\"," % (name))
@@ -559,7 +557,7 @@ def parseGroupCDocs(node):
559557
print(" \"%s\"" % (line))
560558
print(" );")
561559

562-
def parseOptionDoc(node, first):
560+
def parseOptionDoc(node, first, mode):
563561
# Handling part for documentation
564562
name = node.getAttribute('id')
565563
type = node.getAttribute('type')
@@ -571,7 +569,7 @@ def parseOptionDoc(node, first):
571569
if (type != 'obsolete'):
572570
for n in node.childNodes:
573571
if (n.nodeName == "docs"):
574-
if getFilter(n):
572+
if getFilter(n, mode):
575573
if n.nodeType == Node.ELEMENT_NODE:
576574
doc += parseDocs(n)
577575
if (first):
@@ -669,7 +667,7 @@ def parseOptionDoc(node, first):
669667
return False
670668

671669

672-
def parseGroupsDoc(node):
670+
def parseGroupsDoc(node, mode):
673671
name = node.getAttribute('name')
674672
doc = node.getAttribute('docs')
675673
print("\\section config_%s %s" % (name.lower(), doc))
@@ -680,7 +678,7 @@ def parseGroupsDoc(node):
680678
first = True
681679
for n in node.childNodes:
682680
if n.nodeType == Node.ELEMENT_NODE:
683-
first = parseOptionDoc(n, first)
681+
first = parseOptionDoc(n, first, mode)
684682
if (not first):
685683
print("</dl>")
686684

@@ -704,22 +702,22 @@ def parseDocs(node):
704702
#doc += "<br>"
705703
return doc
706704

707-
def parseHeaderDoc(node):
705+
def parseHeaderDoc(node, mode):
708706
doc = ""
709707
for n in node.childNodes:
710708
if n.nodeType == Node.ELEMENT_NODE:
711709
if (n.nodeName == "docs"):
712-
if getFilter(n):
710+
if getFilter(n, mode):
713711
doc += parseDocs(n)
714712
print(doc)
715713

716714

717-
def parseFooterDoc(node):
715+
def parseFooterDoc(node, mode):
718716
doc = ""
719717
for n in node.childNodes:
720718
if n.nodeType == Node.ELEMENT_NODE:
721719
if (n.nodeName == "docs"):
722-
if getFilter(n):
720+
if getFilter(n, mode):
723721
doc += parseDocs(n)
724722
print(doc)
725723

@@ -1123,7 +1121,6 @@ def main():
11231121
if len(messages)==0:
11241122
sys.exit('<generator> section missing in %s' % configFile)
11251123

1126-
global mode
11271124
if (sys.argv[1] == "-doc"):
11281125
mode = "documentation"
11291126
print("/* WARNING: This file is generated!")
@@ -1134,7 +1131,7 @@ def main():
11341131
for n in elem.childNodes:
11351132
if n.nodeType == Node.ELEMENT_NODE:
11361133
if (n.nodeName == "header"):
1137-
parseHeaderDoc(n)
1134+
parseHeaderDoc(n, mode)
11381135
# generate list with all commands
11391136
commandsList = ()
11401137
for n in elem.childNodes:
@@ -1149,14 +1146,13 @@ def main():
11491146
for n in elem.childNodes:
11501147
if n.nodeType == Node.ELEMENT_NODE:
11511148
if (n.nodeName == "group"):
1152-
parseGroupsDoc(n)
1149+
parseGroupsDoc(n, mode)
11531150
# process footers
11541151
for n in elem.childNodes:
11551152
if n.nodeType == Node.ELEMENT_NODE:
11561153
if (n.nodeName == "footer"):
1157-
parseFooterDoc(n)
1154+
parseFooterDoc(n, mode)
11581155
elif (sys.argv[1] == "-maph"):
1159-
mode = "doxyfile"
11601156
print("/* WARNING: This file is generated!")
11611157
print(" * Do not edit this file, but edit %s instead and run" % configFile)
11621158
print(" * python configgen.py -maph %s to regenerate this file!" % configFile)
@@ -1227,7 +1223,6 @@ def main():
12271223
print("")
12281224
print("#endif")
12291225
elif (sys.argv[1] == "-maps"):
1230-
mode = "doxyfile"
12311226
print("/* WARNING: This file is generated!")
12321227
print(" * Do not edit this file, but edit %s instead and run" % configFile)
12331228
print(" * python configgen.py -maps %s to regenerate this file!" % configFile)
@@ -1318,11 +1313,11 @@ def main():
13181313
for n in elem.childNodes:
13191314
if n.nodeType == Node.ELEMENT_NODE:
13201315
if (n.nodeName == "header"):
1321-
parseHeader(n,'cfg')
1316+
parseHeader(n,'cfg', mode)
13221317
for n in elem.childNodes:
13231318
if n.nodeType == Node.ELEMENT_NODE:
13241319
if (n.nodeName == "group"):
1325-
parseGroups(n)
1320+
parseGroups(n, mode)
13261321
print("}")
13271322
elif (sys.argv[1] == "-wiz"):
13281323
mode = "doxywizard"
@@ -1342,11 +1337,11 @@ def main():
13421337
for n in elem.childNodes:
13431338
if n.nodeType == Node.ELEMENT_NODE:
13441339
if (n.nodeName == "header"):
1345-
parseHeader(n,'doc')
1340+
parseHeader(n,'doc', mode)
13461341
for n in elem.childNodes:
13471342
if n.nodeType == Node.ELEMENT_NODE:
13481343
if (n.nodeName == "group"):
1349-
parseGroupCDocs(n)
1344+
parseGroupCDocs(n, mode)
13501345
print("}")
13511346
elif (sys.argv[1] == "-wizswitch"):
13521347
print("#ifndef CONFIGSWITCHER_H")

0 commit comments

Comments
 (0)