Added support for grid columns translations. Translated columns in

addressbook plugin.
print
Josef Rokos 9 years ago
parent 676ea77404
commit 60887e7700

@ -24,5 +24,19 @@
\"addressZipCode\" TEXT NULL);"
],
"dependencies" : []
"dependencies" : [],
"translations" : {
"CZ" : {
"title" : "Titul",
"firstName" : "Jméno",
"lastName" : "Příjmení",
"birthDate" : "Datum narození",
"idCardNumber" : "Číslo dokladu",
"ztp" : "ZTP",
"addressCity" : "Město",
"addressStreet" : "Ulice",
"addressHouseNumber" : "Číslo popisné",
"addressZipCode" : "PSČ"
}
}
}

@ -109,7 +109,12 @@ public:
if (i == section) {
QString colName(entity->metaObject()->property(i + 1).name());
delete entity;
return tr(colName.toStdString().c_str());
if (m_translations.contains(colName))
{
return m_translations[colName];
}
return colName;
}
}
@ -179,6 +184,11 @@ public:
endResetModel();
}
void setTranslations(const QMap<QString, QString> &translations)
{
m_translations = translations;
}
protected:
void handleFilter(const QString &filter) override
{
@ -210,6 +220,7 @@ protected:
private:
QList<QSharedPointer<T> > m_list;
QList<QSharedPointer<T> > m_fullList;
QMap<QString, QString> m_translations;
bool filtered;

@ -80,6 +80,10 @@ public:
m_formHandler = handler;
}
virtual void setTranslations(const QMap<QString, QString> &translations) {
m_tableModel->setTranslations(translations);
}
public slots:
bool fillData() {
if (m_tableModel == NULL) {

@ -27,6 +27,7 @@ public:
void setPluginId(const QString &pluginId);
QString pluginId();
QTableView *tableView();
virtual void setTranslations(const QMap<QString, QString> &translations) = 0;
signals:
void dataChanged();

@ -59,6 +59,7 @@ void IMetaDataPlugin::init(const QJsonObject &metaData)
if (IGridForm *pluginUi = dynamic_cast<IGridForm*>(m_ui))
{
pluginUi->setPluginId(pluginId());
pluginUi->setTranslations(m_translations);
}
if (m_service != NULL)
@ -87,6 +88,23 @@ void IMetaDataPlugin::parseMetaData(const QJsonObject &metaData)
foreach (QJsonValue depVal, data.toObject()["dependecies"].toArray()) {
m_dependsOn.append(depVal.toString());
}
QJsonValue trVal = data.toObject()["translations"];
QString locale = QLocale::system().name();
QJsonValue trLocalized;
foreach (QString key, trVal.toObject().keys()) {
if (locale.contains(key, Qt::CaseInsensitive)) {
trLocalized = trVal.toObject()[key];
break;
}
}
if (!trLocalized.isNull())
{
foreach (QString key, trLocalized.toObject().keys()) {
m_translations[key] = trLocalized.toObject()[key].toString();
}
}
}
QString IMetaDataPlugin::parseLocaleText(const QJsonObject &object)

@ -75,6 +75,7 @@ public:
virtual QTranslator* translator() { return NULL; }
virtual QIcon pluginIcon() { return QIcon(); }
QMap<QString, QString> translations() { return m_translations; }
protected:
QTranslator* translatorFrom(QString fileName) {
@ -87,6 +88,7 @@ protected:
QWidget *m_ui;
QWidget *m_settingsUi;
IService *m_service;
QMap<QString, QString> m_translations;
};
#define PluginInterface_iid "cz.itsolved.prodejna.IPlugin"

Loading…
Cancel
Save