mirror of
https://github.com/subsurface/subsurface.git
synced 2025-01-19 06:15:26 +00:00
Localization: remove gettextFromC::instance()
There were a handfull instances of the kind 1) gettextFromC::instance()->tr(...) 2) gettextFromC::instance()->trGettext(...) 1) is pointless, as tr is a static function. All instances of 2) were likewise pointless, because trGettext() returns a C-string, which was then immediately converted to a QString. Thus, replace both constructs by gettextFromC::tr(...). After this change there was only one user of gettextFromC::instance() left, viz. the C-interface funtion trGettext(). Therefore, remove gettextFromC::instance() and do all the caching / translating directly in the global trGettext(). Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
61b8add590
commit
879cb73b8b
5 changed files with 9 additions and 30 deletions
|
@ -1,28 +1,13 @@
|
|||
// SPDX-License-Identifier: GPL-2.0
|
||||
#include <QCoreApplication>
|
||||
#include <QString>
|
||||
#include "gettextfromc.h"
|
||||
#include <QHash>
|
||||
|
||||
const char *gettextFromC::trGettext(const char *text)
|
||||
{
|
||||
QByteArray &result = translationCache[QByteArray(text)];
|
||||
if (result.isEmpty())
|
||||
result = translationCache[QByteArray(text)] = trUtf8(text).toUtf8();
|
||||
return result.constData();
|
||||
}
|
||||
|
||||
void gettextFromC::reset(void)
|
||||
{
|
||||
translationCache.clear();
|
||||
}
|
||||
|
||||
gettextFromC *gettextFromC::instance()
|
||||
{
|
||||
static gettextFromC self;
|
||||
return &self;
|
||||
}
|
||||
static QHash<QByteArray, QByteArray> translationCache;
|
||||
|
||||
extern "C" const char *trGettext(const char *text)
|
||||
{
|
||||
return gettextFromC::instance()->trGettext(text);
|
||||
QByteArray &result = translationCache[QByteArray(text)];
|
||||
if (result.isEmpty())
|
||||
result = gettextFromC::tr(text).toUtf8();
|
||||
return result.constData();
|
||||
}
|
||||
|
|
|
@ -2,18 +2,12 @@
|
|||
#ifndef GETTEXTFROMC_H
|
||||
#define GETTEXTFROMC_H
|
||||
|
||||
#include <QHash>
|
||||
#include <QCoreApplication>
|
||||
|
||||
extern "C" const char *trGettext(const char *text);
|
||||
|
||||
class gettextFromC {
|
||||
Q_DECLARE_TR_FUNCTIONS(gettextFromC)
|
||||
public:
|
||||
static gettextFromC *instance();
|
||||
const char *trGettext(const char *text);
|
||||
void reset(void);
|
||||
QHash<QByteArray, QByteArray> translationCache;
|
||||
};
|
||||
|
||||
#endif // GETTEXTFROMC_H
|
||||
|
|
|
@ -301,7 +301,7 @@ QWidget *TankUseDelegate::createEditor(QWidget * parent, const QStyleOptionViewI
|
|||
{
|
||||
QComboBox *comboBox = new QComboBox(parent);
|
||||
for (int i = 0; i < NUM_GAS_USE; i++)
|
||||
comboBox->addItem(gettextFromC::instance()->trGettext(cylinderuse_text[i]));
|
||||
comboBox->addItem(gettextFromC::tr(cylinderuse_text[i]));
|
||||
return comboBox;
|
||||
}
|
||||
|
||||
|
|
|
@ -222,7 +222,7 @@ QVariant CylindersModel::data(const QModelIndex &index, int role) const
|
|||
ret = get_depth_string(gas_mnd(&cyl->gasmix, prefs.bestmixend, &displayed_dive, M_OR_FT(1,1)), true);
|
||||
break;
|
||||
case USE:
|
||||
ret = gettextFromC::instance()->trGettext(cylinderuse_text[cyl->cylinder_use]);
|
||||
ret = gettextFromC::tr(cylinderuse_text[cyl->cylinder_use]);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
|
|
@ -176,7 +176,7 @@ GeoReferencingOptionsModel::GeoReferencingOptionsModel(QObject *parent) : QStrin
|
|||
QStringList list;
|
||||
int i;
|
||||
for (i = 0; i < TC_NR_CATEGORIES; i++)
|
||||
list << gettextFromC::instance()->trGettext(taxonomy_category_names[i]);
|
||||
list << gettextFromC::tr(taxonomy_category_names[i]);
|
||||
setStringList(list);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue