Skip to content

Commit b3c2a7d

Browse files
committed
Reduce duplication of string literals
1 parent 82ecf34 commit b3c2a7d

2 files changed

Lines changed: 67 additions & 158 deletions

File tree

addon/doxywizard/doxywizard.cpp

Lines changed: 62 additions & 158 deletions
Original file line numberDiff line numberDiff line change
@@ -53,113 +53,57 @@
5353
// globally accessible variables
5454
bool DoxygenWizard::debugFlag = false;
5555

56-
QString DoxygenWizard::msgFileNotFound(const QString &fileName)
57-
{
58-
return QCoreApplication::translate("Messages", "Sorry, cannot find file(%1);").arg(fileName);
59-
}
60-
61-
QString DoxygenWizard::msgNoPreviewAvailable(const QString &fileName)
62-
{
63-
return QCoreApplication::translate("Messages", "Sorry, no preview available (%1);").arg(fileName);
64-
}
65-
66-
QString DoxygenWizard::msgNoProjectLogoSelected()
67-
{
68-
return QCoreApplication::translate("Messages", "No Project logo selected.");
69-
}
70-
71-
QString DoxygenWizard::msgBrowseToFile()
72-
{
73-
return QCoreApplication::translate("Messages", "Browse to a file");
74-
}
75-
76-
QString DoxygenWizard::msgBrowseToFolder()
77-
{
78-
return QCoreApplication::translate("Messages", "Browse to a folder");
79-
}
80-
81-
QString DoxygenWizard::msgSelectButton()
82-
{
83-
return QCoreApplication::translate("Messages", "Select...");
84-
}
85-
86-
QString DoxygenWizard::msgPreviousButton()
87-
{
88-
return QCoreApplication::translate("Messages", "Previous");
89-
}
90-
91-
QString DoxygenWizard::msgNextButton()
92-
{
93-
return QCoreApplication::translate("Messages", "Next");
94-
}
95-
96-
QString DoxygenWizard::msgTopicsHeader()
97-
{
98-
return QCoreApplication::translate("Messages", "Topics");
99-
}
100-
101-
QString DoxygenWizard::msgProjectTopic()
102-
{
103-
return QCoreApplication::translate("Messages", "Project");
104-
}
105-
106-
#define TR_MSG_ENTRY(name) { QLatin1String(name), []() { return QCoreApplication::translate("Messages", name); } }
107-
108-
static QMap<QString, std::function<QString()>> createMessageMap()
109-
{
110-
static QMap<QString, std::function<QString()>> map = {
111-
TR_MSG_ENTRY("HTML"),
112-
TR_MSG_ENTRY("LaTeX"),
113-
TR_MSG_ENTRY("XML"),
114-
TR_MSG_ENTRY("Docbook"),
115-
TR_MSG_ENTRY("Build"),
116-
TR_MSG_ENTRY("Messages"),
117-
TR_MSG_ENTRY("Input"),
118-
TR_MSG_ENTRY("Source Browser"),
119-
TR_MSG_ENTRY("Index"),
120-
TR_MSG_ENTRY("RTF"),
121-
TR_MSG_ENTRY("Man"),
122-
TR_MSG_ENTRY("AutoGen"),
123-
TR_MSG_ENTRY("Sqlite3"),
124-
TR_MSG_ENTRY("PerlMod"),
125-
TR_MSG_ENTRY("Preprocessor"),
126-
TR_MSG_ENTRY("External"),
127-
TR_MSG_ENTRY("Dot")
128-
};
129-
return map;
130-
}
131-
132-
static QMap<QString, std::function<QString()>> &messageMap()
133-
{
134-
static QMap<QString, std::function<QString()>> map = createMessageMap();
135-
return map;
136-
}
137-
138-
QString DoxygenWizard::msgHtmlFormat() { return messageMap()[QLatin1String("HTML")](); }
139-
QString DoxygenWizard::msgLatexFormat() { return messageMap()[QLatin1String("LaTeX")](); }
140-
QString DoxygenWizard::msgXmlFormat() { return messageMap()[QLatin1String("XML")](); }
141-
QString DoxygenWizard::msgDocbookFormat() { return messageMap()[QLatin1String("Docbook")](); }
142-
QString DoxygenWizard::msgBuildTopic() { return messageMap()[QLatin1String("Build")](); }
143-
QString DoxygenWizard::msgMessagesTopic() { return messageMap()[QLatin1String("Messages")](); }
144-
QString DoxygenWizard::msgInputTopic() { return messageMap()[QLatin1String("Input")](); }
145-
QString DoxygenWizard::msgSourceBrowserTopic() { return messageMap()[QLatin1String("Source Browser")](); }
146-
QString DoxygenWizard::msgIndexTopic() { return messageMap()[QLatin1String("Index")](); }
147-
QString DoxygenWizard::msgRtfFormat() { return messageMap()[QLatin1String("RTF")](); }
148-
QString DoxygenWizard::msgManFormat() { return messageMap()[QLatin1String("Man")](); }
149-
QString DoxygenWizard::msgAutoGenFormat() { return messageMap()[QLatin1String("AutoGen")](); }
150-
QString DoxygenWizard::msgSqlite3Format() { return messageMap()[QLatin1String("Sqlite3")](); }
151-
QString DoxygenWizard::msgPerlModFormat() { return messageMap()[QLatin1String("PerlMod")](); }
152-
QString DoxygenWizard::msgPreprocessorTopic() { return messageMap()[QLatin1String("Preprocessor")](); }
153-
QString DoxygenWizard::msgExternalTopic() { return messageMap()[QLatin1String("External")](); }
154-
QString DoxygenWizard::msgDotTopic() { return messageMap()[QLatin1String("Dot")](); }
56+
#define TR_WIZARD_MESSAGES \
57+
TR_MSG_ENTRY(HtmlFormat, "HTML") \
58+
TR_MSG_ENTRY(LatexFormat, "LaTeX") \
59+
TR_MSG_ENTRY(XmlFormat, "XML") \
60+
TR_MSG_ENTRY(DocbookFormat, "Docbook") \
61+
TR_MSG_ENTRY(BuildTopic, "Build") \
62+
TR_MSG_ENTRY(MessagesTopic, "Messages") \
63+
TR_MSG_ENTRY(InputTopic, "Input") \
64+
TR_MSG_ENTRY(SourceBrowserTopic, "Source Browser") \
65+
TR_MSG_ENTRY(IndexTopic, "Index") \
66+
TR_MSG_ENTRY(RtfFormat, "RTF") \
67+
TR_MSG_ENTRY(ManFormat, "Man") \
68+
TR_MSG_ENTRY(AutoGenFormat, "AutoGen") \
69+
TR_MSG_ENTRY(Sqlite3Format, "Sqlite3") \
70+
TR_MSG_ENTRY(PerlModFormat, "PerlMod") \
71+
TR_MSG_ENTRY(PreprocessorTopic, "Preprocessor") \
72+
TR_MSG_ENTRY(ExternalTopic, "External") \
73+
TR_MSG_ENTRY(DotTopic, "Dot")
74+
75+
#undef TR_MSG_ENTRY
76+
#define TR_MSG_ENTRY(func,name) { QLatin1String(name), []() { return QCoreApplication::translate("Messages", name); } },
77+
78+
static QMap<QString, std::function<QString()>> g_messageMap = {
79+
TR_WIZARD_MESSAGES
80+
};
81+
82+
#undef TR_MSG_ENTRY
83+
#define TR_MSG_ENTRY(func,name) QString DoxygenWizard::msg##func() { return g_messageMap[QLatin1String(name)](); }
84+
TR_WIZARD_MESSAGES
85+
#undef TR_MSG_ENTRY
15586

15687
QString DoxygenWizard::translateExpertTopic(const QString &name)
15788
{
15889
if (name == QLatin1String("Project")) return msgProjectTopic();
159-
if (messageMap().contains(name)) return messageMap()[name]();
90+
if (g_messageMap.contains(name)) return g_messageMap[name]();
16091
return name;
16192
}
16293

94+
#define TR_MSG(msg) QCoreApplication::translate("Messages",msg)
95+
QString DoxygenWizard::msgFileNotFound(const QString &fileName) { return TR_MSG("Sorry, cannot find file(%1);").arg(fileName); }
96+
QString DoxygenWizard::msgNoPreviewAvailable(const QString &fileName) { return TR_MSG("Sorry, no preview available (%1);").arg(fileName); }
97+
QString DoxygenWizard::msgNoProjectLogoSelected() { return TR_MSG("No Project logo selected."); }
98+
QString DoxygenWizard::msgBrowseToFile() { return TR_MSG("Browse to a file"); }
99+
QString DoxygenWizard::msgBrowseToFolder() { return TR_MSG("Browse to a folder"); }
100+
QString DoxygenWizard::msgSelectButton() { return TR_MSG("Select..."); }
101+
QString DoxygenWizard::msgPreviousButton() { return TR_MSG("Previous"); }
102+
QString DoxygenWizard::msgNextButton() { return TR_MSG("Next"); }
103+
QString DoxygenWizard::msgTopicsHeader() { return TR_MSG("Topics"); }
104+
QString DoxygenWizard::msgProjectTopic() { return TR_MSG("Project"); }
105+
#undef TR_MSG
106+
163107
const int messageTimeout = 5000; //!< status bar message timeout in milliseconds.
164108

165109
#define APPQT(x) QString::fromLatin1("<qt><pre>") + x + QString::fromLatin1("</pre></qt>")
@@ -175,53 +119,9 @@ MainWindow::MainWindow()
175119
{
176120
m_translationManager = new TranslationManager;
177121

178-
QMenu *file = menuBar()->addMenu(tr("File"));
179-
file->addAction(tr("Open..."),
180-
this, SLOT(openConfig()), QKeySequence{ Qt::CTRL | Qt::Key_O });
181-
m_recentMenu = file->addMenu(tr("Open recent"));
182-
file->addAction(tr("Save"),
183-
this, SLOT(saveConfig()), QKeySequence{ Qt::CTRL | Qt::Key_S });
184-
file->addAction(tr("Save as..."),
185-
this, SLOT(saveConfigAs()), QKeySequence{ Qt::SHIFT | Qt::CTRL | Qt::Key_S });
186-
file->addAction(tr("Quit"),
187-
this, SLOT(quit()), QKeySequence{ Qt::CTRL | Qt::Key_Q });
188-
189-
QMenu *settings = menuBar()->addMenu(tr("Settings"));
190-
m_resetDefault = settings->addAction(tr("Reset to factory defaults"),
191-
this,SLOT(resetToDefaults()));
192-
settings->addAction(tr("Use current settings at startup"),
193-
this,SLOT(makeDefaults()));
194-
m_clearRecent = settings->addAction(tr("Clear recent list"),
195-
this,SLOT(clearRecent()));
196-
settings->addSeparator();
197-
m_runMenu = settings->addAction(tr("Run doxygen"),
198-
this, SLOT(runDoxygenMenu()), QKeySequence{ Qt::CTRL | Qt::Key_R });
199-
m_runMenu->setEnabled(false);
200-
201-
m_languageMenu = menuBar()->addMenu(tr("Language"));
202122
m_languageActionGroup = new QActionGroup(this);
203123
m_languageActionGroup->setExclusive(true);
204124

205-
QStringList languages = m_translationManager->availableLanguages();
206-
QString currentLang = m_translationManager->currentLanguageCode();
207-
208-
foreach (const QString &langCode, languages)
209-
{
210-
TranslationManager::LanguageInfo info = m_translationManager->languageInfo(langCode);
211-
QAction *action = m_languageMenu->addAction(info.nativeName);
212-
action->setData(langCode);
213-
action->setCheckable(true);
214-
action->setChecked(langCode == currentLang);
215-
m_languageActionGroup->addAction(action);
216-
}
217-
connect(m_languageMenu, SIGNAL(triggered(QAction*)), SLOT(switchLanguage(QAction*)));
218-
219-
QMenu *help = menuBar()->addMenu(tr("Help"));
220-
help->addAction(tr("Online manual"),
221-
this, SLOT(manual()), Qt::Key_F1);
222-
help->addAction(tr("About"),
223-
this, SLOT(about()) );
224-
225125
m_expert = new Expert(m_translationManager);
226126
m_wizard = new Wizard(m_expert->modelData(),m_translationManager);
227127

@@ -272,7 +172,7 @@ MainWindow::MainWindow()
272172

273173
QHBoxLayout *runVH2Layout = new QHBoxLayout;
274174
runVLayout->addLayout(runVH2Layout);
275-
m_launchHtml = new QPushButton(tr("Show HTML output"));
175+
m_launchHtml = new QPushButton();
276176
runVH2Layout->addWidget(m_launchHtml);
277177
runVH2Layout->addStretch(1); // to have launch button not being stretched
278178

@@ -291,7 +191,7 @@ MainWindow::MainWindow()
291191

292192
// output produced by Doxygen
293193
runTabLayout->addLayout(runLayout);
294-
m_outputLabel = new QLabel(tr("Output produced by doxygen"));
194+
m_outputLabel = new QLabel();
295195
runTabLayout->addWidget(m_outputLabel);
296196
QGridLayout *grid = new QGridLayout;
297197
//m_outputLog = new QTextEdit;
@@ -306,14 +206,14 @@ MainWindow::MainWindow()
306206
runTabLayout->addLayout(grid);
307207

308208
m_tabs = new QTabWidget;
309-
m_tabs->addTab(m_wizard,tr("Wizard"));
310-
m_tabs->addTab(m_expert,tr("Expert"));
311-
m_tabs->addTab(m_runTab,tr("Run"));
209+
m_tabs->addTab(m_wizard,QString::fromLatin1("1"));
210+
m_tabs->addTab(m_expert,QString::fromLatin1("2"));
211+
m_tabs->addTab(m_runTab,QString::fromLatin1("3"));
312212

313-
m_workingDirLabel = new QLabel(tr("Specify the working directory from which doxygen will run"));
213+
m_workingDirLabel = new QLabel();
314214
rowLayout->addWidget(m_workingDirLabel);
315215
rowLayout->addLayout(dirLayout);
316-
m_workingDirHintLabel = new QLabel(tr("Configure doxygen using the Wizard and/or Expert tab, then switch to the Run tab to generate the documentation"));
216+
m_workingDirHintLabel = new QLabel();
317217
rowLayout->addWidget(m_workingDirHintLabel);
318218
mainLayout->addWidget(m_tabs);
319219

@@ -324,6 +224,8 @@ MainWindow::MainWindow()
324224
m_running = false;
325225
m_timer = new QTimer;
326226

227+
retranslateUi();
228+
327229
// connect signals and slots
328230
connect(m_tabs,SIGNAL(currentChanged(int)),SLOT(selectTab(int)));
329231
connect(m_selWorkingDir,SIGNAL(clicked()),SLOT(selectWorkingDir()));
@@ -409,16 +311,18 @@ void MainWindow::retranslateUi()
409311
m_runMenu->setEnabled(!m_workingDir->text().isEmpty());
410312

411313
m_languageMenu = menuBar()->addMenu(tr("Language"));
314+
412315
QString currentLang = m_translationManager->currentLanguageCode();
413316
QStringList languages = m_translationManager->availableLanguages();
414-
foreach (const QString &code, languages)
317+
318+
foreach (const QString &langCode, languages)
415319
{
416-
TranslationManager::LanguageInfo info = m_translationManager->languageInfo(code);
417-
QAction *langAction = m_languageMenu->addAction(info.nativeName);
418-
langAction->setData(code);
419-
langAction->setCheckable(true);
420-
langAction->setChecked(code == currentLang);
421-
m_languageActionGroup->addAction(langAction);
320+
TranslationManager::LanguageInfo info = m_translationManager->languageInfo(langCode);
321+
QAction *action = m_languageMenu->addAction(info.nativeName);
322+
action->setData(langCode);
323+
action->setCheckable(true);
324+
action->setChecked(langCode == currentLang);
325+
m_languageActionGroup->addAction(action);
422326
}
423327
connect(m_languageMenu, SIGNAL(triggered(QAction*)), SLOT(switchLanguage(QAction*)));
424328

addon/doxywizard/doxywizard.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
#include <QMainWindow>
1717
#include <QSettings>
1818
#include <QStringList>
19+
#include <QMap>
20+
21+
#include <functional>
1922

2023
class Expert;
2124
class Wizard;
@@ -130,6 +133,7 @@ class MainWindow : public QMainWindow
130133
*
131134
* All fields in this class are public and static, so they can be used directly.
132135
*/
136+
133137
class DoxygenWizard
134138
{
135139
public:
@@ -162,5 +166,6 @@ class DoxygenWizard
162166
static QString msgExternalTopic();
163167
static QString msgDotTopic();
164168
static QString translateExpertTopic(const QString &name);
169+
165170
};
166171
#endif

0 commit comments

Comments
 (0)