|
|
|
@ -541,43 +541,48 @@ void ShopForm::on_btnAddItem_clicked()
|
|
|
|
|
|
|
|
|
|
void ShopForm::on_commoditySearch_textChanged(const QString &text)
|
|
|
|
|
{
|
|
|
|
|
QString replacedText = text;
|
|
|
|
|
|
|
|
|
|
if (ui->numOnly->isChecked())
|
|
|
|
|
for (int i = 0; i < 2; i++)
|
|
|
|
|
{
|
|
|
|
|
replacedText = Helper::replaceByNumbers(text);
|
|
|
|
|
ui->commoditySearch->setText(replacedText);
|
|
|
|
|
}
|
|
|
|
|
QString replacedText = text;
|
|
|
|
|
|
|
|
|
|
QSortFilterProxyModel proxy;
|
|
|
|
|
proxy.setSourceModel(m_commodityModel);
|
|
|
|
|
proxy.setFilterKeyColumn(0);
|
|
|
|
|
proxy.setFilterCaseSensitivity(Qt::CaseInsensitive);
|
|
|
|
|
proxy.setFilterFixedString(replacedText);
|
|
|
|
|
if (i == 1)
|
|
|
|
|
{
|
|
|
|
|
replacedText = Helper::replaceByNumbers(text);
|
|
|
|
|
//ui->commoditySearch->setText(replacedText);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
auto moveToIndex = [this](const QModelIndex &matchingIndex) {
|
|
|
|
|
ui->commodityTable->scrollTo(matchingIndex,QAbstractItemView::EnsureVisible);
|
|
|
|
|
ui->commodityTable->setCurrentIndex(matchingIndex);
|
|
|
|
|
};
|
|
|
|
|
QSortFilterProxyModel proxy;
|
|
|
|
|
proxy.setSourceModel(m_commodityModel);
|
|
|
|
|
proxy.setFilterKeyColumn(0);
|
|
|
|
|
proxy.setFilterCaseSensitivity(Qt::CaseInsensitive);
|
|
|
|
|
proxy.setFilterFixedString(replacedText);
|
|
|
|
|
|
|
|
|
|
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));
|
|
|
|
|
auto moveToIndex = [this](const QModelIndex &matchingIndex) {
|
|
|
|
|
ui->commodityTable->scrollTo(matchingIndex,QAbstractItemView::EnsureVisible);
|
|
|
|
|
ui->commodityTable->setCurrentIndex(matchingIndex);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (matchingIndex.isValid())
|
|
|
|
|
{
|
|
|
|
|
QModelIndex matchingIndex = proxy.mapToSource(proxy.index(0,0));
|
|
|
|
|
if(matchingIndex.isValid()) {
|
|
|
|
|
moveToIndex(matchingIndex);
|
|
|
|
|
m_itemFound = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|