Implemented search in shop items on ShopForm. Prepare for favorite buttons.

This commit is contained in:
2017-02-17 15:15:45 +01:00
parent 44c74a5cfe
commit 2eb1039f6f
13 changed files with 593 additions and 44 deletions
+30
View File
@@ -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);
}
}
}