Debian Codegraph @

addon/doxywizard/expert.cpp

raw
1 /******************************************************************************
2 *
3 * Copyright (C) 1997-2019 by Dimitri van Heesch.
4 *
5 * Permission to use, copy, modify, and distribute this software and its
6 * documentation under the terms of the GNU General Public License is hereby
7 * granted. No representations are made about the suitability of this software
8 * for any purpose. It is provided "as is" without express or implied warranty.
9 * See the GNU General Public License for more details.
10 *
11 */
12
13 #include "expert.h"
14 #include "inputbool.h"
15 #include "inputstring.h"
16 #include "inputint.h"
17 #include "inputstring.h"
18 #include "inputstrlist.h"
19 #include "inputobsolete.h"
20 #include "config.h"
21 #include "version.h"
22 #include "configdoc.h"
23 #include "settings.h"
24
25 #include <QTreeWidget>
26 #include <QStackedWidget>
27 #include <QTextBrowser>
28 #include <QSplitter>
29 #include <QGridLayout>
30 #include <QPushButton>
31 #include <QScrollArea>
32 #include <QFile>
33 #include <QMessageBox>
34 #include <QSettings>
35 #include <QTextStream>
36 #include <QFileInfo>
37 #include <QRegularExpression>
38
39 #define SA(x) QString::fromLatin1(x)
40
41
42 static QString convertToComment(const QString &s)
43 {
44 if (s.isEmpty())
45 {
46 return QString();
47 }
48 else
49 {
50 return SA("# ")+
51 s.trimmed().replace(SA("\n"),SA("\n# ")).replace(SA("# \n"), SA("#\n"))+
52 SA("\n");
53 }
54 }
55
56 void Expert::setHeader(const char *header)
57 {
58 m_header = SA(header);
59 }
60
61 void Expert::add(const char *name,const char *docs)
62 {
63 Input *opt = m_options[SA(name)];
64 if (opt)
65 {
66 opt->setTemplateDocs(SA(docs));
67 }
68 }
69
70 //------------------------------------------------------------------------------------
71
72 Expert::Expert()
73 {
74 m_treeWidget = new QTreeWidget;
75 m_treeWidget->setColumnCount(1);
76 m_topicStack = new QStackedWidget;
77 m_inShowHelp = false;
78
79 QFile file(SA(":/config.xml"));
80 QString err;
81 int errLine,errCol;
82 QDomDocument configXml;
83 if (file.open(QIODevice::ReadOnly))
84 {
85 if (!configXml.setContent(&file,false,&err,&errLine,&errCol))
86 {
87 QString msg = tr("Error parsing internal config.xml at line %1 column %2.\n%3").
88 arg(errLine).arg(errCol).arg(err);
89 QMessageBox::warning(this, tr("Error"), msg);
90 exit(1);
91 }
92 }
93 m_rootElement = configXml.documentElement();
94
95 createTopics(m_rootElement);
96 m_helper = new QTextBrowser;
97 m_helper->setReadOnly(true);
98 m_helper->setOpenExternalLinks(true);
99 m_splitter = new QSplitter(Qt::Vertical);
100 m_splitter->addWidget(m_treeWidget);
101 m_splitter->addWidget(m_helper);
102
103 QWidget *rightSide = new QWidget;
104 QGridLayout *grid = new QGridLayout(rightSide);
105 m_prev = new QPushButton(tr("Previous"));
106 m_prev->setEnabled(false);
107 m_next = new QPushButton(tr("Next"));
108 grid->addWidget(m_topicStack,0,0,1,2);
109 grid->addWidget(m_prev,1,0,Qt::AlignLeft);
110 grid->addWidget(m_next,1,1,Qt::AlignRight);
111 grid->setColumnStretch(0,1);
112 grid->setRowStretch(0,1);
113
114 addWidget(m_splitter);
115 addWidget(rightSide);
116 connect(m_next,SIGNAL(clicked()),SLOT(nextTopic()));
117
118 connect(m_prev,SIGNAL(clicked()),SLOT(prevTopic()));
119
120 addConfigDocs(this);
121 }
122
123 Expert::~Expert()
124 {
125 QHashIterator<QString,Input*> i(m_options);
126 while (i.hasNext())
127 {
128 i.next();
129 delete i.value();
130 }
131 }
132
133 void Expert::createTopics(const QDomElement &rootElem)
134 {
135 QList<QTreeWidgetItem*> items;
136 QDomElement childElem = rootElem.firstChildElement();
137 while (!childElem.isNull())
138 {
139 if (childElem.tagName()==SA("group"))
140 {
141 // Remove _ from a group name like: Source_Browser
142 QString name = childElem.attribute(SA("name")).replace(SA("_"),SA(" "));
143 QString setting = childElem.attribute(SA("setting"));
144 if (setting.isEmpty() || IS_SUPPORTED(setting.toLatin1()))
145 {
146 items.append(new QTreeWidgetItem((QTreeWidget*)nullptr,QStringList(name)));
147 QWidget *widget = createTopicWidget(childElem);
148 m_topics[name] = widget;
149 m_topicStack->addWidget(widget);
150 }
151 }
152 childElem = childElem.nextSiblingElement();
153 }
154 m_treeWidget->setHeaderLabels(QStringList() << SA("Topics"));
155 m_treeWidget->insertTopLevelItems(0,items);
156 connect(m_treeWidget,
157 SIGNAL(currentItemChanged(QTreeWidgetItem *,QTreeWidgetItem *)),
158 this,
159 SLOT(activateTopic(QTreeWidgetItem *,QTreeWidgetItem *)));
160 }
161
162 static QString getDocsForNode(const QDomElement &child)
163 {
164 QString type = child.attribute(SA("type"));
165 QString docs = SA("");
166 // read documentation text
167 QDomElement docsVal = child.firstChildElement();
168 while (!docsVal.isNull())
169 {
170 if (docsVal.tagName()==SA("docs") &&
171 docsVal.attribute(SA("doxywizard")) != SA("0"))
172 {
173 for (QDomNode n = docsVal.firstChild(); !n.isNull(); n = n.nextSibling())
174 {
175 QDomText t = n.toText();
176 if (!t.isNull()) docs+=t.data();
177 }
178 docs += SA("<br/>");
179 }
180 docsVal = docsVal.nextSiblingElement();
181 }
182
183 // for an enum we list the values
184 if (type==SA("enum"))
185 {
186 docs += SA("<br/>");
187 docs += SA("Possible values are: ");
188 int numValues=0;
189 docsVal = child.firstChildElement();
190 while (!docsVal.isNull())
191 {
192 if (docsVal.tagName()==SA("value"))
193 {
194 numValues++;
195 }
196 docsVal = docsVal.nextSiblingElement();
197 }
198 int i=0;
199 docsVal = child.firstChildElement();
200 while (!docsVal.isNull())
201 {
202 if (docsVal.tagName()==SA("value"))
203 {
204 i++;
205 docs += SA("<code>") + docsVal.attribute(SA("name")) + SA("</code>");
206 QString desc = docsVal.attribute(SA("desc"));
207 if (!desc.isEmpty())
208 {
209 docs+= SA(" ")+desc;
210 }
211 if (i==numValues-1)
212 {
213 docs+=SA(" and ");
214 }
215 else if (i==numValues)
216 {
217 docs+=SA(".");
218 }
219 else
220 {
221 docs+=SA(", ");
222 }
223 }
224 docsVal = docsVal.nextSiblingElement();
225 }
226 if (child.attribute(SA("defval")) != SA(""))
227 {
228 docs+=SA("<br/>");
229 docs+=SA("<br/>");
230 docs+=SA(" The default value is: <code>")+
231 child.attribute(SA("defval"))+
232 SA("</code>.");
233 }
234 docs+= SA("<br/>");
235 }
236 else if (type==SA("int"))
237 {
238 docs+=SA("<br/>");
239 docs+=SA("Minimum value: ")+child.attribute(SA("minval"))+SA(", ");
240 docs+=SA("maximum value: ")+child.attribute(SA("maxval"))+SA(", ");
241 docs+=SA("default value: ")+child.attribute(SA("defval"))+SA(".");
242 docs+= SA("<br/>");
243 }
244 else if (type==SA("bool"))
245 {
246 docs+=SA("<br/>");
247 if (child.hasAttribute(SA("altdefval")))
248 {
249 docs+=SA(" The default value is: system dependent.");
250 }
251 else
252 {
253 QString defval = child.attribute(SA("defval"));
254 docs+=SA(" The default value is: <code>")+
255 (defval==SA("1")?SA("YES"):SA("NO"))+
256 SA("</code>.");
257 }
258 docs+= SA("<br/>");
259 }
260 else if (type==SA("list"))
261 {
262 if (child.attribute(SA("format"))==SA("string"))
263 {
264 int numValues = 0;
265 docsVal = child.firstChildElement();
266 while (!docsVal.isNull())
267 {
268 if (docsVal.tagName()==SA("value"))
269 {
270 QString showDocu = SA("");
271 if (docsVal.hasAttribute(SA("show_docu")))
272 {
273 showDocu = docsVal.attribute(SA("show_docu")).toLower();
274 }
275 if ((showDocu != SA("no")) && (docsVal.attribute(SA("name"))!=SA(""))) numValues++;
276 }
277 docsVal = docsVal.nextSiblingElement();
278 }
279 if (numValues>0)
280 {
281 int i = 0;
282 docsVal = child.firstChildElement();
283 while (!docsVal.isNull())
284 {
285 if (docsVal.tagName()==SA("value"))
286 {
287 QString showDocu = SA("");
288 if (docsVal.hasAttribute(SA("show_docu")))
289 {
290 showDocu = docsVal.attribute(SA("show_docu")).toLower();
291 }
292 if ((showDocu != SA("no")) && (docsVal.attribute(SA("name"))!=SA("")))
293 {
294 i++;
295 docs += SA("<code>") + docsVal.attribute(SA("name")) + SA("</code>");
296 QString desc = docsVal.attribute(SA("desc"));
297 if (desc != SA(""))
298 {
299 docs += SA(" ") + desc;
300 }
301 if (i==numValues-1)
302 {
303 docs += SA(" and ");
304 }
305 else if (i==numValues)
306 {
307 docs += SA(".");
308 }
309 else
310 {
311 docs += SA(", ");
312 }
313 }
314 }
315 docsVal = docsVal.nextSiblingElement();
316 }
317 }
318 // docs+= SA("<br/>");
319 }
320 }
321 else if (type==SA("string"))
322 {
323 QString defval = child.attribute(SA("defval"));
324 if (child.attribute(SA("format")) == SA("dir"))
325 {
326 if (defval != SA(""))
327 {
328 docs+=SA("<br/>");
329 docs += SA(" The default directory is: <code>") + defval + SA("</code>.");
330 docs += SA("<br/>");
331 }
332 }
333 else if (child.attribute(SA("format")) == SA("file"))
334 {
335 QString abspath = child.attribute(SA("abspath"));
336 if (defval != SA(""))
337 {
338 docs+=SA("<br/>");
339 if (abspath != SA("1"))
340 {
341 docs += SA(" The default file is: <code>") + defval + SA("</code>.");
342 }
343 else
344 {
345 docs += SA(" The default file (with absolute path) is: <code>") + defval + SA("</code>.");
346 }
347 docs += SA("<br/>");
348 }
349 else
350 {
351 if (abspath == SA("1"))
352 {
353 docs+=SA("<br/>");
354 docs += SA(" The file has to be specified with full path.");
355 docs += SA("<br/>");
356 }
357 }
358 }
359 else if (child.attribute(SA("format")) == SA("image"))
360 {
361 QString abspath = child.attribute(SA("abspath"));
362 if (defval != SA(""))
363 {
364 docs+=SA("<br/>");
365 if (abspath != SA("1"))
366 {
367 docs += SA(" The default image is: <code>") + defval + SA("</code>.");
368 }
369 else
370 {
371 docs += SA(" The default image (with absolute path) is: <code>") + defval + SA("</code>.");
372 }
373 docs += SA("<br/>");
374 }
375 else
376 {
377 if (abspath == SA("1"))
378 {
379 docs+=SA("<br/>");
380 docs += SA(" The image has to be specified with full path.");
381 docs += SA("<br/>");
382 }
383 }
384 }
385 else // if (child.attribute(SA("format")) == SA("string"))
386 {
387 if (defval != SA(""))
388 {
389 docs+=SA("<br/>");
390 docs += SA(" The default value is: <code>") + defval + SA("</code>.");
391 docs += SA("<br/>");
392 }
393 }
394 }
395
396 if (child.hasAttribute(SA("depends")))
397 {
398 QString dependsOn = child.attribute(SA("depends"));
399 docs+=SA("<br/>");
400 docs+= SA(" This tag requires that the tag \\ref cfg_");
401 docs+= dependsOn.toLower();
402 docs+= SA(" \"");
403 docs+= dependsOn.toUpper();
404 docs+= SA("\" is set to <code>YES</code>.");
405 }
406
407 // Remove / replace doxygen markup strings
408 // the regular expressions are hard to read so the intention will be given
409 // Note: see also configgen.py in the src directory for other doxygen parts
410 QRegularExpression regexp;
411 // remove \n at end and replace by a space
412 regexp.setPattern(SA("\\n$"));
413 docs.replace(regexp,SA(" "));
414 // remove <br> at end
415 regexp.setPattern(SA("<br> *$"));
416 docs.replace(regexp,SA(" "));
417 // \c word -> <code>word</code>; word ends with ')', ',', '.' or ' '
418 regexp.setPattern(SA("\\\\c[ ]+([^ \\)]+)\\)"));
419 docs.replace(regexp,SA("<code>\\1</code>)"));
420
421 regexp.setPattern(SA("\\\\c[ ]+([^ ,]+),"));
422 docs.replace(regexp,SA("<code>\\1</code>,"));
423
424 regexp.setPattern(SA("\\\\c[ ]+([^ \\.]+)\\."));
425 docs.replace(regexp,SA("<code>\\1</code>."));
426
427 regexp.setPattern(SA("\\\\c[ ]+([^ ]+) "));
428 docs.replace(regexp,SA("<code>\\1</code> "));
429 // `word` -> <code>word</code>
430 docs.replace(SA("``"),SA(""));
431 regexp.setPattern(SA("`([^`]+)`"));
432 docs.replace(regexp,SA("<code>\\1</code>"));
433 // \ref key "desc" -> <code>desc</code>
434 regexp.setPattern(SA("\\\\ref[ ]+[^ ]+[ ]+\"([^\"]+)\""));
435 docs.replace(regexp,SA("<code>\\1</code> "));
436 //\ref specials
437 // \ref <key> -> description
438 regexp.setPattern(SA("\\\\ref[ ]+doxygen_usage"));
439 docs.replace(regexp,SA("\"Doxygen usage\""));
440 regexp.setPattern(SA("\\\\ref[ ]+extsearch"));
441 docs.replace(regexp,SA("\"External Indexing and Searching\""));
442 regexp.setPattern(SA("\\\\ref[ ]+external"));
443 docs.replace(regexp,SA("\"Linking to external documentation\""));
444 regexp.setPattern(SA("\\\\ref[ ]+formulas"));
445 docs.replace(regexp,SA("\"Including formulas\""));
446 // fallback for not handled
447 docs.replace(SA("\\\\ref"),SA(""));
448 // \b word -> <b>word<\b>
449 regexp.setPattern(SA("\\\\b[ ]+([^ ]+) "));
450 docs.replace(regexp,SA("<b>\\1</b> "));
451 // \e word -> <em>word<\em>
452 regexp.setPattern(SA("\\\\e[ ]+([^ ]+) "));
453 docs.replace(regexp,SA("<em>\\1</em> "));
454 // \note -> <br>Note:
455 // @note -> <br>Note:
456 docs.replace(SA("\\note"),SA("<br>Note:"));
457 docs.replace(SA("@note"),SA("<br>Note:"));
458 // \#include -> #include
459 // \#undef -> #undef
460 docs.replace(SA("\\#include"),SA("#include"));
461 docs.replace(SA("\\#undef"),SA("#undef"));
462 // -# -> <br>-
463 // " - " -> <br>-
464 docs.replace(SA("-#"),SA("<br>-"));
465 docs.replace(SA(" - "),SA("<br>-"));
466 // \verbatim -> <pre>
467 // \endverbatim -> </pre>
468 docs.replace(SA("\\verbatim"),SA("<pre>"));
469 docs.replace(SA("\\endverbatim"),SA("</pre>"));
470 // \sa -> <br>See also:
471 // \par -> <br>
472 docs.replace(SA("\\sa"),SA("<br>See also:"));
473 docs.replace(SA("\\par"),SA("<br>"));
474 // 2xbackslash -> backslash
475 // \@ -> @
476 docs.replace(SA("\\\\"),SA("\\"));
477 docs.replace(SA("\\@"),SA("@"));
478 // \& -> &
479 // \$ -> $
480 docs.replace(SA("\\&"),SA("&"));
481 docs.replace(SA("\\$"),SA("$"));
482 // \< -> &lt;
483 // \> -> &gt;
484 docs.replace(SA("\\<"),SA("&lt;"));
485 docs.replace(SA("\\>"),SA("&gt;"));
486 regexp.setPattern(SA(" (http:[^ \\)]*)([ \\)])"));
487 docs.replace(regexp,SA(" <a href=\"\\1\">\\1</a>\\2"));
488 regexp.setPattern(SA(" (https:[^ \\)]*)([ \\)])"));
489 docs.replace(regexp,SA(" <a href=\"\\1\">\\1</a>\\2"));
490 // LaTeX name as formula -> LaTeX
491 regexp.setPattern(SA("\\\\f\\$\\\\mbox\\{\\\\LaTeX\\}\\\\f\\$"));
492 docs.replace(regexp,SA("LaTeX"));
493 // Other formula's (now just 2) so explicitly mentioned.
494 regexp.setPattern(SA("\\\\f\\$2\\^\\{\\(16\\+\\\\mbox\\{LOOKUP\\\\_CACHE\\\\_SIZE\\}\\)\\}\\\\f\\$"));
495 docs.replace(regexp,SA("2^(16+LOOKUP_CACHE_SIZE)"));
496 regexp.setPattern(SA("\\\\f\\$2\\^\\{16\\} = 65536\\\\f\\$"));
497 docs.replace(regexp,SA("2^16=65536"));
498
499 return docs.trimmed();
500 }
501
502 QWidget *Expert::createTopicWidget(QDomElement &elem)
503 {
504 QScrollArea *area = new QScrollArea;
505 QWidget *topic = new QWidget;
506 QGridLayout *layout = new QGridLayout(topic);
507 QDomElement child = elem.firstChildElement();
508 int row=0;
509 while (!child.isNull())
510 {
511 QString setting = child.attribute(SA("setting"));
512 if (setting.isEmpty() || IS_SUPPORTED(setting.toLatin1()))
513 {
514 QString type = child.attribute(SA("type"));
515 QString docs = getDocsForNode(child);
516 if (type==SA("bool"))
517 {
518 InputBool *boolOption =
519 new InputBool(
520 layout,row,
521 child.attribute(SA("id")),
522 child.attribute(SA("defval"))==SA("1"),
523 docs
524 );
525 m_options.insert(
526 child.attribute(SA("id")),
527 boolOption
528 );
529 connect(boolOption,SIGNAL(showHelp(Input*)),SLOT(showHelp(Input*)));
530 connect(boolOption,SIGNAL(changed()),SIGNAL(changed()));
531 }
532 else if (type==SA("string"))
533 {
534 InputString::StringMode mode;
535 QString format = child.attribute(SA("format"));
536 if (format==SA("dir"))
537 {
538 mode = InputString::StringDir;
539 }
540 else if (format==SA("file"))
541 {
542 mode = InputString::StringFile;
543 }
544 else if (format==SA("filedir"))
545 {
546 mode = InputString::StringFileDir;
547 }
548 else if (format==SA("image"))
549 {
550 mode = InputString::StringImage;
551 }
552 else // format=="string"
553 {
554 mode = InputString::StringFree;
555 }
556 InputString *stringOption =
557 new InputString(
558 layout,row,
559 child.attribute(SA("id")),
560 child.attribute(SA("defval")),
561 mode,
562 docs,
563 child.attribute(SA("abspath"))
564 );
565 m_options.insert(
566 child.attribute(SA("id")),
567 stringOption
568 );
569 connect(stringOption,SIGNAL(showHelp(Input*)),SLOT(showHelp(Input*)));
570 connect(stringOption,SIGNAL(changed()),SIGNAL(changed()));
571 }
572 else if (type==SA("enum"))
573 {
574 InputString *enumList = new InputString(
575 layout,row,
576 child.attribute(SA("id")),
577 child.attribute(SA("defval")),
578 InputString::StringFixed,
579 docs
580 );
581 QDomElement enumVal = child.firstChildElement();
582 while (!enumVal.isNull())
583 {
584 if (enumVal.tagName()==SA("value"))
585 {
586 enumList->addValue(enumVal.attribute(SA("name")));
587 }
588 enumVal = enumVal.nextSiblingElement();
589 }
590 enumList->setDefault();
591
592 m_options.insert(child.attribute(SA("id")),enumList);
593 connect(enumList,SIGNAL(showHelp(Input*)),SLOT(showHelp(Input*)));
594 connect(enumList,SIGNAL(changed()),SIGNAL(changed()));
595 }
596 else if (type==SA("int"))
597 {
598 InputInt *intOption =
599 new InputInt(
600 layout,row,
601 child.attribute(SA("id")),
602 child.attribute(SA("defval")).toInt(),
603 child.attribute(SA("minval")).toInt(),
604 child.attribute(SA("maxval")).toInt(),
605 docs
606 );
607 m_options.insert(
608 child.attribute(SA("id")),
609 intOption
610 );
611 connect(intOption,SIGNAL(showHelp(Input*)),SLOT(showHelp(Input*)));
612 connect(intOption,SIGNAL(changed()),SIGNAL(changed()));
613 }
614 else if (type==SA("list"))
615 {
616 InputStrList::ListMode mode;
617 QString format = child.attribute(SA("format"));
618 if (format==SA("dir"))
619 {
620 mode = InputStrList::ListDir;
621 }
622 else if (format==SA("file"))
623 {
624 mode = InputStrList::ListFile;
625 }
626 else if (format==SA("filedir"))
627 {
628 mode = InputStrList::ListFileDir;
629 }
630 else // format=="string"
631 {
632 mode = InputStrList::ListString;
633 }
634 QStringList sl;
635 QDomElement listVal = child.firstChildElement();
636 while (!listVal.isNull())
637 {
638 if (listVal.tagName()==SA("value"))
639 {
640 sl.append(listVal.attribute(SA("name")));
641 }
642 listVal = listVal.nextSiblingElement();
643 }
644 InputStrList *listOption =
645 new InputStrList(
646 layout,row,
647 child.attribute(SA("id")),
648 sl,
649 mode,
650 docs
651 );
652 m_options.insert(
653 child.attribute(SA("id")),
654 listOption
655 );
656 connect(listOption,SIGNAL(showHelp(Input*)),SLOT(showHelp(Input*)));
657 connect(listOption,SIGNAL(changed()),SIGNAL(changed()));
658 }
659 else if (type==SA("obsolete"))
660 {
661 Input::Kind orgKind;
662 QString orgKindStr = child.attribute(SA("orgtype"));
663 if (orgKindStr==SA("int"))
664 {
665 orgKind = Input::Int;
666 }
667 else if (orgKindStr==SA("bool"))
668 {
669 orgKind = Input::Bool;
670 }
671 else if (orgKindStr==SA("string") || orgKindStr==SA("enum"))
672 {
673 orgKind = Input::String;
674 }
675 else if (orgKindStr==SA("strlist"))
676 {
677 orgKind = Input::StrList;
678 }
679 else
680 {
681 orgKind = Input::Obsolete;
682 }
683 InputObsolete *obsoleteOption =
684 new InputObsolete(child.attribute(SA("id")),orgKind);
685 m_options.insert(child.attribute(SA("id")),obsoleteOption);
686 // ignore
687 }
688 else // should not happen
689 {
690 printf("Unsupported type %s\n",qPrintable(child.attribute(SA("type"))));
691 }
692 } // IS_SUPPORTED
693 child = child.nextSiblingElement();
694 }
695
696 // compute dependencies between options
697 child = elem.firstChildElement();
698 while (!child.isNull())
699 {
700 QString setting = child.attribute(SA("setting"));
701 QString dependsOn = child.attribute(SA("depends"));
702 QString id = child.attribute(SA("id"));
703 if (!dependsOn.isEmpty() &&
704 (setting.isEmpty() || IS_SUPPORTED(setting.toLatin1())))
705 {
706 Input *parentOption = m_options[dependsOn];
707 if (parentOption==nullptr)
708 {
709 printf("%s has depends=%s that is not valid\n",
710 qPrintable(id),qPrintable(dependsOn));
711 }
712 Input *thisOption = m_options[id];
713 Q_ASSERT(parentOption);
714 Q_ASSERT(thisOption);
715 if (parentOption && thisOption)
716 {
717 //printf("Adding dependency '%s' (%p)->'%s' (%p)\n",
718 // qPrintable(dependsOn),parentOption,
719 // qPrintable(id),thisOption);
720 parentOption->addDependency(thisOption);
721 }
722 }
723 child = child.nextSiblingElement();
724 }
725
726 // set initial dependencies
727 QHashIterator<QString,Input*> i(m_options);
728 while (i.hasNext())
729 {
730 i.next();
731 if (i.value())
732 {
733 i.value()->updateDependencies();
734 }
735 }
736
737 layout->setRowStretch(row,1);
738 layout->setColumnStretch(1,2);
739 layout->setSpacing(5);
740 topic->setLayout(layout);
741 area->setWidget(topic);
742 area->setWidgetResizable(true);
743 return area;
744 }
745
746 void Expert::activateTopic(QTreeWidgetItem *item,QTreeWidgetItem *)
747 {
748 if (item)
749 {
750 QWidget *w = m_topics[item->text(0)];
751 m_topicStack->setCurrentWidget(w);
752 m_prev->setEnabled(m_topicStack->currentIndex()!=0);
753 m_next->setEnabled(true);
754 }
755 }
756
757 void Expert::loadSettings(QSettings *s)
758 {
759 QHashIterator<QString,Input*> i(m_options);
760 while (i.hasNext())
761 {
762 i.next();
763 QVariant var = s->value(SA("config/")+i.key());
764 if (i.value() && var.isValid())
765 {
766 //printf("Loading key %s: type=%d value='%s'\n",qPrintable(i.key()),var.type(),qPrintable(var.toString()));
767 i.value()->value() = var;
768 i.value()->update();
769 }
770 }
771 }
772
773 void Expert::saveSettings(QSettings *s)
774 {
775 QHashIterator<QString,Input*> i(m_options);
776 while (i.hasNext())
777 {
778 i.next();
779 //printf("Saving key %s: type=%d value='%s'\n",qPrintable(i.key()),i.value()->value().type(),qPrintable(i.value()->value().toString()));
780 if (i.value())
781 {
782 s->setValue(SA("config/")+i.key(),i.value()->value());
783 }
784 }
785 }
786
787 void Expert::loadConfig(const QString &fileName)
788 {
789 //printf("Expert::loadConfig(%s)\n",qPrintable(fileName));
790 parseConfig(fileName,m_options);
791 }
792
793 void Expert::saveTopic(QTextStream &t,QDomElement &elem,TextCodecAdapter *codec,
794 bool brief,bool condensed,bool convert)
795 {
796 if (!brief)
797 {
798 t << "\n";
799 }
800 if (!condensed)
801 {
802 t << "#---------------------------------------------------------------------------\n";
803 t << "# " << elem.attribute(SA("docs")) << "\n";
804 t << "#---------------------------------------------------------------------------\n";
805 }
806 // write options...
807 QDomElement childElem = elem.firstChildElement();
808 while (!childElem.isNull())
809 {
810 QString setting = childElem.attribute(SA("setting"));
811 QString type = childElem.attribute(SA("type"));
812 QString name = childElem.attribute(SA("id"));
813 if (setting.isEmpty() || IS_SUPPORTED(setting.toLatin1()))
814 {
815 QHash<QString,Input*>::const_iterator i = m_options.find(name);
816 if (i!=m_options.end())
817 {
818 Input *option = i.value();
819 if (option->kind()!=Input::Obsolete)
820 {
821 if (option && !brief)
822 {
823 t << "\n";
824 t << convertToComment(option->templateDocs());
825 t << "\n";
826 }
827 bool toPrint = true;
828 if (option && condensed) toPrint = !option->isDefault();
829 if (toPrint)
830 {
831 t << name.leftJustified(MAX_OPTION_LENGTH) << "=";
832 if (option && !option->isEmpty())
833 {
834 t << " ";
835 option->writeValue(t,codec,convert);
836 }
837 t << "\n";
838 }
839 }
840 }
841 }
842 childElem = childElem.nextSiblingElement();
843 }
844 }
845
846 bool Expert::writeConfig(QTextStream &t,bool brief, bool condensed, bool convert)
847 {
848 // write global header
849 t << "# Doxyfile " << getDoxygenVersion().c_str() << "\n\n";
850 if (!brief && !condensed)
851 {
852 t << convertToComment(m_header);
853 }
854
855 Input *option = m_options[QString::fromLatin1("DOXYFILE_ENCODING")];
856 TextCodecAdapter codec(option->value().toString().toLatin1());
857 QDomElement childElem = m_rootElement.firstChildElement();
858 while (!childElem.isNull())
859 {
860 if (childElem.tagName()==SA("group"))
861 {
862 saveTopic(t,childElem,&codec,brief,condensed,convert);
863 }
864 childElem = childElem.nextSiblingElement();
865 }
866 return true;
867 }
868
869 QByteArray Expert::saveInnerState () const
870 {
871 return m_splitter->saveState();
872 }
873
874 bool Expert::restoreInnerState ( const QByteArray & state )
875 {
876 return m_splitter->restoreState(state);
877 }
878
879 void Expert::showHelp(Input *option)
880 {
881 if (!m_inShowHelp)
882 {
883 m_inShowHelp = true;
884 m_helper->setText(
885 QString::fromLatin1("<qt><b>")+option->id()+
886 QString::fromLatin1("</b><br>")+
887 QString::fromLatin1("<br/>")+
888 option->docs().
889 replace(QChar::fromLatin1('\n'),QChar::fromLatin1(' '))+
890 QString::fromLatin1("</qt>")
891 );
892 m_inShowHelp = false;
893 }
894 }
895
896 void Expert::nextTopic()
897 {
898 if (m_topicStack->currentIndex()+1==m_topicStack->count()) // last topic
899 {
900 done();
901 }
902 else
903 {
904 m_topicStack->setCurrentIndex(m_topicStack->currentIndex()+1);
905 m_next->setEnabled(m_topicStack->count()!=m_topicStack->currentIndex()+1);
906 m_prev->setEnabled(m_topicStack->currentIndex()!=0);
907 m_treeWidget->setCurrentItem(m_treeWidget->invisibleRootItem()->child(m_topicStack->currentIndex()));
908 }
909 }
910
911 void Expert::prevTopic()
912 {
913 m_topicStack->setCurrentIndex(m_topicStack->currentIndex()-1);
914 m_next->setEnabled(m_topicStack->count()!=m_topicStack->currentIndex()+1);
915 m_prev->setEnabled(m_topicStack->currentIndex()!=0);
916 m_treeWidget->setCurrentItem(m_treeWidget->invisibleRootItem()->child(m_topicStack->currentIndex()));
917 }
918
919 void Expert::resetToDefaults()
920 {
921 //printf("Expert::makeDefaults()\n");
922 QHashIterator<QString,Input*> i(m_options);
923 while (i.hasNext())
924 {
925 i.next();
926 if (i.value())
927 {
928 i.value()->reset();
929 }
930 }
931 }
932
933 static bool stringVariantToBool(const QVariant &v)
934 {
935 QString s = v.toString().toLower();
936 return s==QString::fromLatin1("yes") || s==QString::fromLatin1("true") || s==QString::fromLatin1("1");
937 }
938
939 static bool getBoolOption(
940 const QHash<QString,Input*>&model,const QString &name)
941 {
942 Input *option = model[name];
943 Q_ASSERT(option!=nullptr);
944 return stringVariantToBool(option->value());
945 }
946
947 static QString getStringOption(
948 const QHash<QString,Input*>&model,const QString &name)
949 {
950 Input *option = model[name];
951 Q_ASSERT(option!=nullptr);
952 return option->value().toString();
953 }
954
955
956 bool Expert::htmlOutputPresent(const QString &workingDir) const
957 {
958 bool generateHtml = getBoolOption(m_options,QString::fromLatin1("GENERATE_HTML"));
959 if (!generateHtml || workingDir.isEmpty()) return false;
960 QString indexFile = getHtmlOutputIndex(workingDir);
961 QFileInfo fi(indexFile);
962 return fi.exists() && fi.isFile();
963 }
964
965 QString Expert::getHtmlOutputIndex(const QString &workingDir) const
966 {
967 QString outputDir = getStringOption(m_options,QString::fromLatin1("OUTPUT_DIRECTORY"));
968 QString htmlOutputDir = getStringOption(m_options,QString::fromLatin1("HTML_OUTPUT"));
969 //printf("outputDir=%s\n",qPrintable(outputDir));
970 //printf("htmlOutputDir=%s\n",qPrintable(htmlOutputDir));
971 QString indexFile = workingDir;
972 if (QFileInfo(outputDir).isAbsolute()) // override
973 {
974 indexFile = outputDir;
975 }
976 else // append
977 {
978 indexFile += QString::fromLatin1("/")+outputDir;
979 }
980 if (QFileInfo(htmlOutputDir).isAbsolute()) // override
981 {
982 indexFile = htmlOutputDir;
983 }
984 else // append
985 {
986 indexFile += QString::fromLatin1("/")+htmlOutputDir;
987 }
988 indexFile+=QString::fromLatin1("/index.html");
989 return indexFile;
990 }
991
992 bool Expert::pdfOutputPresent(const QString &workingDir) const
993 {
994 bool generateLatex = getBoolOption(m_options,QString::fromLatin1("GENERATE_LATEX"));
995 bool pdfLatex = getBoolOption(m_options,QString::fromLatin1("USE_PDFLATEX"));
996 if (!generateLatex || !pdfLatex) return false;
997 QString latexOutput = getStringOption(m_options,QString::fromLatin1("LATEX_OUTPUT"));
998 QString indexFile;
999 if (QFileInfo(latexOutput).isAbsolute())
1000 {
1001 indexFile = latexOutput+QString::fromLatin1("/refman.pdf");
1002 }
1003 else
1004 {
1005 indexFile = workingDir+QString::fromLatin1("/")+
1006 latexOutput+QString::fromLatin1("/refman.pdf");
1007 }
1008 QFileInfo fi(indexFile);
1009 return fi.exists() && fi.isFile();
1010 }
1011
1012 void Expert::refresh()
1013 {
1014 m_treeWidget->setCurrentItem(m_treeWidget->invisibleRootItem()->child(0));
1015 }
1016