Implemented search in shop items on ShopForm. Prepare for favorite buttons.
This commit is contained in:
@@ -11,6 +11,8 @@
|
||||
#include "isellableservice.h"
|
||||
#include <QList>
|
||||
#include <QSharedPointer>
|
||||
#include <QSortFilterProxyModel>
|
||||
|
||||
#include "shop-odb.hxx"
|
||||
|
||||
ShopForm::ShopForm(QWidget *parent) :
|
||||
@@ -313,3 +315,31 @@ void ShopForm::on_btnAddItem_clicked()
|
||||
ShopItemPtr item = m_commodityModel->itemFromIndex(ui->commodityTable->currentIndex());
|
||||
addItem(item, ui->spnCount->value());
|
||||
}
|
||||
|
||||
void ShopForm::on_commoditySearch_textChanged(const QString &text)
|
||||
{
|
||||
QSortFilterProxyModel proxy;
|
||||
proxy.setSourceModel(m_commodityModel);
|
||||
proxy.setFilterKeyColumn(0);
|
||||
proxy.setFilterFixedString(text);
|
||||
|
||||
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);
|
||||
}
|
||||
else
|
||||
{
|
||||
proxy.setFilterKeyColumn(1);
|
||||
matchingIndex = proxy.mapToSource(proxy.index(0,0));
|
||||
|
||||
if (matchingIndex.isValid())
|
||||
{
|
||||
moveToIndex(matchingIndex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user