1 | // Copyright (C) 2016 The Qt Company Ltd. |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 |
3 | |
4 | #ifndef DRIVER_H |
5 | #define DRIVER_H |
6 | |
7 | #include "option.h" |
8 | #include <qhash.h> |
9 | #include <qstring.h> |
10 | #include <qstringlist.h> |
11 | #include <qtextstream.h> |
12 | |
13 | QT_BEGIN_NAMESPACE |
14 | |
15 | class QTextStream; |
16 | class DomUI; |
17 | class DomWidget; |
18 | class DomSpacer; |
19 | class DomLayout; |
20 | class DomLayoutItem; |
21 | class DomActionGroup; |
22 | class DomAction; |
23 | class DomButtonGroup; |
24 | |
25 | class Driver |
26 | { |
27 | Q_DISABLE_COPY_MOVE(Driver) |
28 | public: |
29 | Driver(); |
30 | virtual ~Driver(); |
31 | |
32 | // tools |
33 | bool printDependencies(const QString &fileName); |
34 | bool uic(const QString &fileName, QTextStream *output = nullptr); |
35 | bool uic(const QString &fileName, DomUI *ui, QTextStream *output = nullptr); |
36 | |
37 | // configuration |
38 | inline QTextStream &output() const { return *m_output; } |
39 | inline Option &option() { return m_option; } |
40 | |
41 | // utils |
42 | static QString (const QString &fileName); |
43 | QString () const; |
44 | |
45 | static QString normalizedName(const QString &name); |
46 | static QString qtify(const QString &name); |
47 | QString unique(const QString &instanceName=QString(), |
48 | const QString &className=QString()); |
49 | |
50 | // symbol table |
51 | QString findOrInsertWidget(const DomWidget *ui_widget); |
52 | QString findOrInsertSpacer(const DomSpacer *ui_spacer); |
53 | QString findOrInsertLayout(const DomLayout *ui_layout); |
54 | QString findOrInsertLayoutItem(const DomLayoutItem *ui_layoutItem); |
55 | QString findOrInsertName(const QString &name); |
56 | QString findOrInsertActionGroup(const DomActionGroup *ui_group); |
57 | QString findOrInsertAction(const DomAction *ui_action); |
58 | QString findOrInsertButtonGroup(const DomButtonGroup *ui_group); |
59 | // Find a group by its non-uniqified name |
60 | const DomButtonGroup *findButtonGroup(const QString &attributeName) const; |
61 | |
62 | const DomWidget *widgetByName(const QString &attributeName) const; |
63 | QString widgetVariableName(const QString &attributeName) const; |
64 | const DomActionGroup *actionGroupByName(const QString &attributeName) const; |
65 | const DomAction *actionByName(const QString &attributeName) const; |
66 | |
67 | bool useIdBasedTranslations() const { return m_idBasedTranslations; } |
68 | void setUseIdBasedTranslations(bool u) { m_idBasedTranslations = u; } |
69 | |
70 | private: |
71 | template <class DomClass> using DomObjectHash = QHash<const DomClass *, QString>; |
72 | template <class DomClass> using DomObjectHashConstIt = |
73 | typename DomObjectHash<DomClass>::ConstIterator; |
74 | |
75 | template <class DomClass> |
76 | DomObjectHashConstIt<DomClass> findByAttributeNameIt(const DomObjectHash<DomClass> &domHash, |
77 | const QString &name) const; |
78 | template <class DomClass> |
79 | const DomClass *findByAttributeName(const DomObjectHash<DomClass> &domHash, |
80 | const QString &name) const; |
81 | template <class DomClass> |
82 | QString findOrInsert(DomObjectHash<DomClass> *domHash, const DomClass *dom, const QString &className, |
83 | bool isMember = true); |
84 | |
85 | Option m_option; |
86 | QTextStream m_stdout; |
87 | QTextStream *m_output; |
88 | |
89 | // symbol tables |
90 | DomObjectHash<DomWidget> m_widgets; |
91 | DomObjectHash<DomSpacer> m_spacers; |
92 | DomObjectHash<DomLayout> m_layouts; |
93 | DomObjectHash<DomActionGroup> m_actionGroups; |
94 | DomObjectHash<DomButtonGroup> m_buttonGroups; |
95 | DomObjectHash<DomAction> m_actions; |
96 | QHash<QString, bool> m_nameRepository; |
97 | bool m_idBasedTranslations = false; |
98 | }; |
99 | |
100 | QT_END_NAMESPACE |
101 | |
102 | #endif // DRIVER_H |
103 | |