KConfig

KConfigXmlParser.h
1 /*
2  This file is part of the KDE libraries
3 
4  SPDX-FileCopyrightText: 2003 Cornelius Schumacher <schumacher@kde.org>
5  SPDX-FileCopyrightText: 2003 Waldo Bastian <bastian@kde.org>
6  SPDX-FileCopyrightText: 2003 Zack Rusin <zack@kde.org>
7  SPDX-FileCopyrightText: 2006 MichaĆ«l Larouche <michael.larouche@kdemail.net>
8  SPDX-FileCopyrightText: 2008 Allen Winter <winter@kde.org>
9  SPDX-FileCopyrightText: 2020 Tomaz Cananbrava <tcanabrava@kde.org>
10 
11  SPDX-License-Identifier: LGPL-2.0-or-later
12 */
13 
14 #ifndef KCONFIGXMLPARSER_H
15 #define KCONFIGXMLPARSER_H
16 
17 #include <QDomDocument>
18 #include <QRegularExpression>
19 #include <QString>
20 
21 #include "KConfigCommonStructs.h"
22 #include "KConfigParameters.h"
23 
24 /* This parses the contents of a Xml file into a ParseResult Structure,
25  * It also fails hard:
26  * If start() succeeds, you can use the result,
27  * if start() fails, the program aborts with an error message so there's
28  * no possibility of generating incorrect code information.
29  */
30 class KConfigXmlParser
31 {
32 public:
33  KConfigXmlParser(const KConfigParameters &cfg, const QString &inputFileName);
34 
35  // Start the parser and reads the contents of the inputFileName into the ParseResult Structure
36  void start();
37 
38  // Get the result of the parse
39  ParseResult getParseResult() const;
40 
41 private:
42  // creates a `somethingChanged` signal for every property
43  void createChangedSignal(CfgEntry &readEntry);
44 
45  void validateNameAndKey(CfgEntry &readEntry, const QDomElement &element);
46 
47  // TODO: Use std::optional and CfgEntry (without heap allocation) for this function
48  // *or* fail hard if the parse fails.
49  CfgEntry *parseEntry(const QString &group, const QString &parentGroup, const QDomElement &element);
50 
51  // Steps
52  void readIncludeTag(const QDomElement &element);
53  void readGroupTag(const QDomElement &element);
54  void readKcfgfileTag(const QDomElement &element);
55  void readSignalTag(const QDomElement &element);
56 
57  // Those are the Entries in the Xml, that represent a parameter within the <group> </group> tag.
58  void readParameterFromEntry(CfgEntry &entry, const QDomElement &element);
59  bool hasDefaultCode(CfgEntry &entry, const QDomElement &element);
60  void readChoicesFromEntry(CfgEntry &entry, const QDomElement &element);
61  void readGroupElements(CfgEntry &entry, const QDomElement &element);
62  void readParamDefaultValues(CfgEntry &entry, const QDomElement &element);
63 
64 private:
65  ParseResult mParseResult;
67  QString mInputFileName;
68  QStringList mAllNames;
69  QRegularExpression mValidNameRegexp;
70 };
71 
72 #endif
Configuration Compiler Configuration.
Q_SCRIPTABLE Q_NOREPLY void start()
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Thu Feb 15 2024 04:07:59 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.