From d108a42b0859f9a847bb404acc70119c93cdfd05 Mon Sep 17 00:00:00 2001 From: Josef Rokos Date: Wed, 2 Mar 2016 20:33:24 +0100 Subject: [PATCH 1/2] Column widths saving to user settings. Fixed memory leak in AutoTableModel. --- core/autotablemodel.h | 1 + core/gridform.h | 6 ++++++ core/igridform.cpp | 11 +++++++++++ core/igridform.h | 1 + 4 files changed, 19 insertions(+) diff --git a/core/autotablemodel.h b/core/autotablemodel.h index 2e5c309..0866a87 100644 --- a/core/autotablemodel.h +++ b/core/autotablemodel.h @@ -89,6 +89,7 @@ public: for (int i = 0; i < entity->metaObject()->propertyCount(); i++) { if (i == section) { QString colName(entity->metaObject()->property(i + 1).name()); + delete entity; return tr(colName.toStdString().c_str()); } } diff --git a/core/gridform.h b/core/gridform.h index cb65446..2e18917 100644 --- a/core/gridform.h +++ b/core/gridform.h @@ -98,6 +98,12 @@ public slots: hide.append(var.toInt()); } + QMap widths = Context::instance().settings()->value("grids/" + pluginId() + "/widths").toMap(); + foreach (QString key, widths.keys()) { + tableView()->setColumnWidth(key.toInt(), widths[key].toInt()); + } + + connect(tableView()->horizontalHeader(), SIGNAL(sectionResized(int,int,int)), this, SLOT(widthChanged(int,int,int))); hideColumns(hide); } diff --git a/core/igridform.cpp b/core/igridform.cpp index ef1d899..f58f52d 100644 --- a/core/igridform.cpp +++ b/core/igridform.cpp @@ -2,6 +2,8 @@ #include "ui_gridform.h" #include +#include +#include #include "context.h" #include "filterui.h" @@ -108,6 +110,15 @@ void IGridForm::columnsAccepted() Context::instance().settings()->setValue("grids/" + pluginId() + "/hide", QVariant::fromValue(varList)); } +void IGridForm::widthChanged(int logicalIndex, int oldSize, int newSize) +{ + Q_UNUSED(oldSize); + + QMap widths = Context::instance().settings()->value("grids/" + pluginId() + "/widths").toMap(); + widths[QString::number(logicalIndex)] = newSize; + Context::instance().settings()->setValue("grids/" + pluginId() + "/widths", QVariant::fromValue(widths)); +} + void IGridForm::on_btnFilter_toggled(bool checked) { diff --git a/core/igridform.h b/core/igridform.h index bf22dc6..fb70ab6 100644 --- a/core/igridform.h +++ b/core/igridform.h @@ -48,6 +48,7 @@ private slots: void on_tableView_customContextMenuRequested(const QPoint &pos); void on_actionSelectColumns_triggered(); void columnsAccepted(); + void widthChanged(int logicalIndex, int oldSize, int newSize); void on_btnFilter_toggled(bool checked); From c0db311a23d4dcf3a269b732e3fbdafd4d08ffb7 Mon Sep 17 00:00:00 2001 From: Josef Rokos Date: Wed, 9 Mar 2016 19:56:45 +0100 Subject: [PATCH 2/2] Translation suport --- application/appRc.qrc | 1 + application/application.pro | 4 + application/main.cpp | 14 +- application/translations/prodejna_cs_CZ.qm | Bin 0 -> 272 bytes application/translations/prodejna_cz.ts | 52 ++++ core/autoform.h | 2 +- core/context.cpp | 6 + core/core.pro | 2 + core/coreplugin.cpp | 8 + core/coreplugin.h | 4 + core/iplugin.h | 6 +- core/translations/core_cs_CZ.qm | Bin 0 -> 118 bytes core/translations/core_cs_CZ.ts | 330 +++++++++++++++++++++ 13 files changed, 423 insertions(+), 6 deletions(-) create mode 100644 application/translations/prodejna_cs_CZ.qm create mode 100644 application/translations/prodejna_cz.ts create mode 100644 core/translations/core_cs_CZ.qm create mode 100644 core/translations/core_cs_CZ.ts diff --git a/application/appRc.qrc b/application/appRc.qrc index a37b608..afa9743 100644 --- a/application/appRc.qrc +++ b/application/appRc.qrc @@ -4,5 +4,6 @@ icons/login_64.png style.css icons/settings.svg + translations/prodejna_cs_CZ.qm diff --git a/application/application.pro b/application/application.pro index 307a02c..eeb2f76 100644 --- a/application/application.pro +++ b/application/application.pro @@ -56,3 +56,7 @@ INCLUDEPATH += $$PWD/../qdecimal/decnumber RESOURCES += \ appRc.qrc + +TRANSLATIONS = translations/prodejna_cz.ts + +DISTFILES += diff --git a/application/main.cpp b/application/main.cpp index ac8a17e..6b68e87 100644 --- a/application/main.cpp +++ b/application/main.cpp @@ -1,12 +1,22 @@ #include "mainwindow.h" #include #include - -#include +#include +#include int main(int argc, char *argv[]) { QApplication a(argc, argv); + + QTranslator qtTranslator; + qtTranslator.load("qt_" + QLocale::system().name(), + QLibraryInfo::location(QLibraryInfo::TranslationsPath)); + a.installTranslator(&qtTranslator); + + QTranslator myappTranslator; + myappTranslator.load(":/translations/prodejna_" + QLocale::system().name()); + a.installTranslator(&myappTranslator); + MainWindow w; w.move(QApplication::desktop()->screen()->rect().center() - w.rect().center()); w.show(); diff --git a/application/translations/prodejna_cs_CZ.qm b/application/translations/prodejna_cs_CZ.qm new file mode 100644 index 0000000000000000000000000000000000000000..9d707a849a513c51f858f2ea3b88c881a834b462 GIT binary patch literal 272 zcmcE7ks@*G{hX<16=n7(EZlq7iGhJZfq~_MDv(ZO2#);+q#2lR7pDWM2^^~)KLOJE znLy$+Gmzk7@L|YjNN31o$m0NV8Q6fB)h9naGmjm};s&!^G81$1(-|SkJs46MiWzbk z^5M!k0uqah%kzs;u + + + + LoginDialog + + + + Login + Login + + + + Password + Heslo + + + + MainWindow + + + MainWindow + Nastaveni + + + + File + Soubor + + + + Exit + + + + + Open database... + + + + + Login... + + + + + + Settings + + + + diff --git a/core/autoform.h b/core/autoform.h index 7de9d38..02e944b 100644 --- a/core/autoform.h +++ b/core/autoform.h @@ -17,7 +17,7 @@ class AutoForm : public FormBinder { public: explicit AutoForm(QWidget *parent = 0) { - setParent(parent); + this->setParent(parent); m_serviceConnected = false; m_saved = false; } diff --git a/core/context.cpp b/core/context.cpp index 2052f57..58c5d22 100644 --- a/core/context.cpp +++ b/core/context.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include @@ -49,6 +50,8 @@ void Context::loadPlugins() m_plugins.append(new Users); m_plugins.append(new Roles); + qApp->installTranslator(corePlugin->translator()); + QDir pluginsDir(qApp->applicationDirPath() + "/../plugins"); foreach (QString fileName, pluginsDir.entryList(QStringList() << "*.so" << "*.dll")) { @@ -59,6 +62,9 @@ void Context::loadPlugins() IPlugin *plugin = qobject_cast(p); if (plugin != NULL) { plugin->init(pluginLoader.metaData()); + + QTranslator *translator = plugin->translator(); + qApp->installTranslator(translator); m_plugins.append(plugin); } } diff --git a/core/core.pro b/core/core.pro index 370f413..2ed2239 100644 --- a/core/core.pro +++ b/core/core.pro @@ -146,3 +146,5 @@ else:unix: LIBS += -L$$OUT_PWD/../qdecimal/lib/ -lqdecimal -ldecnumber INCLUDEPATH += $$PWD/../qdecimal/src INCLUDEPATH += $$PWD/../qdecimal/decnumber + +TRANSLATIONS = translations/core_cz.ts diff --git a/core/coreplugin.cpp b/core/coreplugin.cpp index d36d224..5c96908 100644 --- a/core/coreplugin.cpp +++ b/core/coreplugin.cpp @@ -25,3 +25,11 @@ void CorePlugin::initServiceUi() m_settingsUi = new GlobalSettingsForm(); } +QTranslator *CorePlugin::translator() +{ + QTranslator *trans = new QTranslator(); + trans->load(":/translations/core_" + QLocale::system().name()); + + return trans; +} + diff --git a/core/coreplugin.h b/core/coreplugin.h index c1b1f29..7186b0d 100644 --- a/core/coreplugin.h +++ b/core/coreplugin.h @@ -12,6 +12,10 @@ public: // IMetaDataPlugin interface protected: virtual void initServiceUi(); + + // IPlugin interface +public: + QTranslator *translator() override; }; #endif // COREPLUGIN_H diff --git a/core/iplugin.h b/core/iplugin.h index bdc0aab..4ce3014 100644 --- a/core/iplugin.h +++ b/core/iplugin.h @@ -7,6 +7,7 @@ #include #include #include +#include #include "service.h" #include "igridform.h" @@ -71,9 +72,8 @@ public: return (Service*)m_service; } - virtual QIcon pluginIcon() { - return QIcon(); - } + virtual QTranslator* translator() { return NULL; } + virtual QIcon pluginIcon() { return QIcon(); } protected: QWidget *m_ui; diff --git a/core/translations/core_cs_CZ.qm b/core/translations/core_cs_CZ.qm new file mode 100644 index 0000000000000000000000000000000000000000..a0aa1c79b4eab0e634f7832d23259c0a55eb6da1 GIT binary patch literal 118 zcmcE7ks@*G{hX<16=n7(EZlq7iGhKEgRMhxF_31+1Y%ESAR)yN#*ojD!;r*~$e_Sb z3}odqlrj`BBr}w9fE2O;F<)?MPHJ+ALUMjiX>MLIJ5Y$n8O(OcOw7qoXY2qeWMur$ H!o&gqB8D7M literal 0 HcmV?d00001 diff --git a/core/translations/core_cs_CZ.ts b/core/translations/core_cs_CZ.ts new file mode 100644 index 0000000..daf845e --- /dev/null +++ b/core/translations/core_cs_CZ.ts @@ -0,0 +1,330 @@ + + + + + ColumnDialog + + + Select columns + Volba sloupcu + + + + FilterDialog + + + Manage filters + + + + + Name + + + + + Filter + + + + + FilterUi + + + Form + + + + + Apply + + + + + Go + + + + + Load filter: + + + + + + Save + + + + + + Manage + + + + + Add condition "AND" + + + + + Add condition "OR" + + + + + Remove condition + + + + + OR + + + + + AND + + + + + FormDialog + + + Edit record + + + + + Validation error + + + + + GlobalSettingsForm + + + Form + + + + + Company info + + + + + IC + + + + + VAT number + + + + + VAT payer + + + + + Contact + + + + + Firm Name + + + + + Street + + + + + House Number + + + + + City + + + + + ZIP code + + + + + + Logo + + + + + Select file + + + + + GridForm + + + Form + + + + + Add record + + + + + N + + + + + Edit record + + + + + E + + + + + + Delete record + + + + + D + + + + + Filter + + + + + F + + + + + Print + + + + + P + + + + + Select columns + + + + + + Database error + + + + + Realy delete this record? + + + + + RolesForm + + + Form + + + + + Name + + + + + Active + + + + + Permissions: + + + + + SaveFilterDialog + + + + Filter name + + + + + SettingsForm + + + Settings + + + + + UserForm + + + Form + + + + + Login + + + + + Password + + + + + Name + + + + + Is Admin + + + + + Active + + + + + Roles + + + + + Retype Password + + + +