From b69637165d5a474db8b530ea40e0720c44a55d70 Mon Sep 17 00:00:00 2001 From: Josef Rokos Date: Thu, 10 May 2018 15:06:27 +0200 Subject: [PATCH] Fixed barcode scanner issue on Windows with czech keyboard. --- core/core.h | 1 + core/core.pro | 6 ++++-- core/helper.cpp | 39 +++++++++++++++++++++++++++++++++++++++ core/helper.h | 18 ++++++++++++++++++ shop/shopform.cpp | 10 +++++++++- shop/shopform.ui | 9 ++++++++- 6 files changed, 79 insertions(+), 4 deletions(-) create mode 100644 core/helper.cpp create mode 100644 core/helper.h diff --git a/core/core.h b/core/core.h index b94ea6c..01ffc69 100644 --- a/core/core.h +++ b/core/core.h @@ -13,5 +13,6 @@ #include "settingsform.h" #include "enums.h" #include "objectbinder.h" +#include "helper.h" #endif // CORE_H diff --git a/core/core.pro b/core/core.pro index 7d40d7c..721cacb 100644 --- a/core/core.pro +++ b/core/core.pro @@ -66,7 +66,8 @@ SOURCES += \ csvimporter.cpp \ importdialog.cpp \ importprogress.cpp \ - reporting/variablefiller.cpp + reporting/variablefiller.cpp \ + helper.cpp HEADERS += core.h\ core_global.h \ @@ -132,7 +133,8 @@ HEADERS += core.h\ iimportprogress.h \ importdialog.h \ importprogress.h \ - reporting/variablefiller.h + reporting/variablefiller.h \ + helper.h unix { target.path = /usr/lib diff --git a/core/helper.cpp b/core/helper.cpp new file mode 100644 index 0000000..a2dcc9c --- /dev/null +++ b/core/helper.cpp @@ -0,0 +1,39 @@ +#include "helper.h" +#include "define.h" + +const QMap Helper::m_numMap{ + {"+", "1"}, + {"ě", "2"}, + {"š", "3"}, + {"č", "4"}, + {"ř", "5"}, + {"ž", "6"}, + {"ý", "7"}, + {"á", "8"}, + {"í", "9"}, + {"é", "0"} +}; + +Helper::Helper() +{ +} + +QString Helper::replaceByNumbers(const QString &str) +{ + QString ret; + + std::for_each(ALL(str), [&](QChar c){ + QString replaced = m_numMap[c]; + + if (replaced.isEmpty()) + { + ret.append(c); + } + else + { + ret.append(replaced); + } + }); + + return ret; +} diff --git a/core/helper.h b/core/helper.h new file mode 100644 index 0000000..cd8d28b --- /dev/null +++ b/core/helper.h @@ -0,0 +1,18 @@ +#ifndef HELPER_H +#define HELPER_H + +#include +#include + +class Helper +{ +public: + Helper(); + + static QString replaceByNumbers(const QString &str); + +private: + static const QMap m_numMap; +}; + +#endif // HELPER_H diff --git a/shop/shopform.cpp b/shop/shopform.cpp index e7844d5..91326a5 100644 --- a/shop/shopform.cpp +++ b/shop/shopform.cpp @@ -541,11 +541,19 @@ void ShopForm::on_btnAddItem_clicked() void ShopForm::on_commoditySearch_textChanged(const QString &text) { + QString replacedText = text; + + if (ui->numOnly->isChecked()) + { + replacedText = Helper::replaceByNumbers(text); + ui->commoditySearch->setText(replacedText); + } + QSortFilterProxyModel proxy; proxy.setSourceModel(m_commodityModel); proxy.setFilterKeyColumn(0); proxy.setFilterCaseSensitivity(Qt::CaseInsensitive); - proxy.setFilterFixedString(text); + proxy.setFilterFixedString(replacedText); auto moveToIndex = [this](const QModelIndex &matchingIndex) { ui->commodityTable->scrollTo(matchingIndex,QAbstractItemView::EnsureVisible); diff --git a/shop/shopform.ui b/shop/shopform.ui index d3d2047..f210d9e 100644 --- a/shop/shopform.ui +++ b/shop/shopform.ui @@ -6,7 +6,7 @@ 0 0 - 975 + 988 643 @@ -45,6 +45,13 @@ + + + + Replace chars by numbers + + +