Shop - improved commodity search with bar code scanner.
This commit is contained in:
+34
-29
@@ -541,43 +541,48 @@ void ShopForm::on_btnAddItem_clicked()
|
|||||||
|
|
||||||
void ShopForm::on_commoditySearch_textChanged(const QString &text)
|
void ShopForm::on_commoditySearch_textChanged(const QString &text)
|
||||||
{
|
{
|
||||||
QString replacedText = text;
|
for (int i = 0; i < 2; i++)
|
||||||
|
|
||||||
if (ui->numOnly->isChecked())
|
|
||||||
{
|
{
|
||||||
replacedText = Helper::replaceByNumbers(text);
|
QString replacedText = text;
|
||||||
ui->commoditySearch->setText(replacedText);
|
|
||||||
}
|
|
||||||
|
|
||||||
QSortFilterProxyModel proxy;
|
if (i == 1)
|
||||||
proxy.setSourceModel(m_commodityModel);
|
|
||||||
proxy.setFilterKeyColumn(0);
|
|
||||||
proxy.setFilterCaseSensitivity(Qt::CaseInsensitive);
|
|
||||||
proxy.setFilterFixedString(replacedText);
|
|
||||||
|
|
||||||
auto moveToIndex = [this](const QModelIndex &matchingIndex) {
|
|
||||||
ui->commodityTable->scrollTo(matchingIndex,QAbstractItemView::EnsureVisible);
|
|
||||||
ui->commodityTable->setCurrentIndex(matchingIndex);
|
|
||||||
};
|
|
||||||
|
|
||||||
QModelIndex matchingIndex = proxy.mapToSource(proxy.index(0,0));
|
|
||||||
if(matchingIndex.isValid()) {
|
|
||||||
moveToIndex(matchingIndex);
|
|
||||||
m_itemFound = true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
proxy.setFilterKeyColumn(1);
|
|
||||||
matchingIndex = proxy.mapToSource(proxy.index(0,0));
|
|
||||||
|
|
||||||
if (matchingIndex.isValid())
|
|
||||||
{
|
{
|
||||||
|
replacedText = Helper::replaceByNumbers(text);
|
||||||
|
//ui->commoditySearch->setText(replacedText);
|
||||||
|
}
|
||||||
|
|
||||||
|
QSortFilterProxyModel proxy;
|
||||||
|
proxy.setSourceModel(m_commodityModel);
|
||||||
|
proxy.setFilterKeyColumn(0);
|
||||||
|
proxy.setFilterCaseSensitivity(Qt::CaseInsensitive);
|
||||||
|
proxy.setFilterFixedString(replacedText);
|
||||||
|
|
||||||
|
auto moveToIndex = [this](const QModelIndex &matchingIndex) {
|
||||||
|
ui->commodityTable->scrollTo(matchingIndex,QAbstractItemView::EnsureVisible);
|
||||||
|
ui->commodityTable->setCurrentIndex(matchingIndex);
|
||||||
|
};
|
||||||
|
|
||||||
|
QModelIndex matchingIndex = proxy.mapToSource(proxy.index(0,0));
|
||||||
|
if(matchingIndex.isValid()) {
|
||||||
moveToIndex(matchingIndex);
|
moveToIndex(matchingIndex);
|
||||||
m_itemFound = true;
|
m_itemFound = true;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
m_itemFound = false;
|
proxy.setFilterKeyColumn(1);
|
||||||
|
matchingIndex = proxy.mapToSource(proxy.index(0,0));
|
||||||
|
|
||||||
|
if (matchingIndex.isValid())
|
||||||
|
{
|
||||||
|
moveToIndex(matchingIndex);
|
||||||
|
m_itemFound = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_itemFound = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,13 +45,6 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
|
||||||
<widget class="QCheckBox" name="numOnly">
|
|
||||||
<property name="text">
|
|
||||||
<string>Replace chars by numbers</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item>
|
<item>
|
||||||
<widget class="QLineEdit" name="commoditySearch"/>
|
<widget class="QLineEdit" name="commoditySearch"/>
|
||||||
</item>
|
</item>
|
||||||
|
|||||||
Reference in New Issue
Block a user