1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2016 The Qt Company Ltd. |
4 | ** Contact: https://www.qt.io/licensing/ |
5 | ** |
6 | ** This file is part of the tools applications of the Qt Toolkit. |
7 | ** |
8 | ** $QT_BEGIN_LICENSE:GPL-EXCEPT$ |
9 | ** Commercial License Usage |
10 | ** Licensees holding valid commercial Qt licenses may use this file in |
11 | ** accordance with the commercial license agreement provided with the |
12 | ** Software or, alternatively, in accordance with the terms contained in |
13 | ** a written agreement between you and The Qt Company. For licensing terms |
14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
15 | ** information use the contact form at https://www.qt.io/contact-us. |
16 | ** |
17 | ** GNU General Public License Usage |
18 | ** Alternatively, this file may be used under the terms of the GNU |
19 | ** General Public License version 3 as published by the Free Software |
20 | ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT |
21 | ** included in the packaging of this file. Please review the following |
22 | ** information to ensure the GNU General Public License requirements will |
23 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
24 | ** |
25 | ** $QT_END_LICENSE$ |
26 | ** |
27 | ****************************************************************************/ |
28 | |
29 | #ifndef DRIVER_H |
30 | #define DRIVER_H |
31 | |
32 | #include "option.h" |
33 | #include <qhash.h> |
34 | #include <qstring.h> |
35 | #include <qstringlist.h> |
36 | #include <qtextstream.h> |
37 | |
38 | QT_BEGIN_NAMESPACE |
39 | |
40 | class QTextStream; |
41 | class DomUI; |
42 | class DomWidget; |
43 | class DomSpacer; |
44 | class DomLayout; |
45 | class DomLayoutItem; |
46 | class DomActionGroup; |
47 | class DomAction; |
48 | class DomButtonGroup; |
49 | |
50 | class Driver |
51 | { |
52 | Q_DISABLE_COPY_MOVE(Driver) |
53 | public: |
54 | Driver(); |
55 | virtual ~Driver(); |
56 | |
57 | // tools |
58 | bool printDependencies(const QString &fileName); |
59 | bool uic(const QString &fileName, QTextStream *output = nullptr); |
60 | bool uic(const QString &fileName, DomUI *ui, QTextStream *output = nullptr); |
61 | |
62 | // configuration |
63 | inline QTextStream &output() const { return *m_output; } |
64 | inline Option &option() { return m_option; } |
65 | |
66 | // utils |
67 | static QString (const QString &fileName); |
68 | QString () const; |
69 | |
70 | static QString normalizedName(const QString &name); |
71 | static QString qtify(const QString &name); |
72 | QString unique(const QString &instanceName=QString(), |
73 | const QString &className=QString()); |
74 | |
75 | // symbol table |
76 | QString findOrInsertWidget(const DomWidget *ui_widget); |
77 | QString findOrInsertSpacer(const DomSpacer *ui_spacer); |
78 | QString findOrInsertLayout(const DomLayout *ui_layout); |
79 | QString findOrInsertLayoutItem(const DomLayoutItem *ui_layoutItem); |
80 | QString findOrInsertName(const QString &name); |
81 | QString findOrInsertActionGroup(const DomActionGroup *ui_group); |
82 | QString findOrInsertAction(const DomAction *ui_action); |
83 | QString findOrInsertButtonGroup(const DomButtonGroup *ui_group); |
84 | // Find a group by its non-uniqified name |
85 | const DomButtonGroup *findButtonGroup(const QString &attributeName) const; |
86 | |
87 | const DomWidget *widgetByName(const QString &attributeName) const; |
88 | QString widgetVariableName(const QString &attributeName) const; |
89 | const DomActionGroup *actionGroupByName(const QString &attributeName) const; |
90 | const DomAction *actionByName(const QString &attributeName) const; |
91 | |
92 | bool useIdBasedTranslations() const { return m_idBasedTranslations; } |
93 | void setUseIdBasedTranslations(bool u) { m_idBasedTranslations = u; } |
94 | |
95 | private: |
96 | template <class DomClass> using DomObjectHash = QHash<const DomClass *, QString>; |
97 | template <class DomClass> using DomObjectHashConstIt = |
98 | typename DomObjectHash<DomClass>::ConstIterator; |
99 | |
100 | template <class DomClass> |
101 | DomObjectHashConstIt<DomClass> findByAttributeNameIt(const DomObjectHash<DomClass> &domHash, |
102 | const QString &name) const; |
103 | template <class DomClass> |
104 | const DomClass *findByAttributeName(const DomObjectHash<DomClass> &domHash, |
105 | const QString &name) const; |
106 | template <class DomClass> |
107 | QString findOrInsert(DomObjectHash<DomClass> *domHash, const DomClass *dom, const QString &className, |
108 | bool isMember = true); |
109 | |
110 | Option m_option; |
111 | QTextStream m_stdout; |
112 | QTextStream *m_output; |
113 | |
114 | // symbol tables |
115 | DomObjectHash<DomWidget> m_widgets; |
116 | DomObjectHash<DomSpacer> m_spacers; |
117 | DomObjectHash<DomLayout> m_layouts; |
118 | DomObjectHash<DomActionGroup> m_actionGroups; |
119 | DomObjectHash<DomButtonGroup> m_buttonGroups; |
120 | DomObjectHash<DomAction> m_actions; |
121 | QHash<QString, bool> m_nameRepository; |
122 | bool m_idBasedTranslations = false; |
123 | }; |
124 | |
125 | QT_END_NAMESPACE |
126 | |
127 | #endif // DRIVER_H |
128 | |