Commit da769a8f authored by Hugo Hörnquist's avatar Hugo Hörnquist

admin: added search bar to product listing

parent a29a72ad
......@@ -365,12 +365,9 @@ void MainWindow::on_acquisitionModel_dataChanged(QModelIndex topLeft, QModelInde
ui->totalPriceLabel->setText(QString("%L1").arg(total));
}
void MainWindow::on_checkBox_toggled(bool checked)
void MainWindow::on_checkBox_toggled(bool /*checked*/)
{
if(checked)
model->setFilter("sale_status >= 0");
else
model->setFilter("sale_status IN (0, 1)");
setProductFilter();
}
// Add new row for new product
......@@ -840,3 +837,32 @@ void MainWindow::setStockValues()
double projVal = get_projected_stock_value().toDouble() / 100.0;
ui->valueProjectedLabel->setText(QString("%1").arg(projVal, 0, 'f', 2));
}
void MainWindow::setProductFilter()
{
QString searchStr = ui->productListSearch->text();
bool isNumber;
searchStr.toInt(&isNumber, 10);
QString filter = QString(
isNumber
? "bar_code = '%1'"
: "name LIKE '\%%1\%' "
).arg(searchStr);
if (ui->checkBox->isChecked()) {
filter.append ("AND sale_status >= 0");
} else {
filter.append ("AND sale_status IN (0, 1)");
}
QSqlTableModel* model = ((QSqlTableModel*) ui->tableView->model());
model->setFilter(filter);
model->select();
}
void MainWindow::on_productListSearch_textChanged(const QString &arg1)
{
setProductFilter();
}
......@@ -73,6 +73,8 @@ private slots:
void on_stockDiffReset_clicked();
void on_productListSearch_textChanged(const QString &arg1);
private:
Ui::MainWindow *ui;
QSqlTableModel* model;
......@@ -91,6 +93,7 @@ private:
void toVaultDrawer_shared(QString from, QString to);
void addRemoveCommon(QString from, QString to);
void clear_stockDiffTemp();
void setProductFilter();
QVariant get_projected_stock_value();
QVariant get_acquistion_stock_value();
......
......@@ -31,6 +31,13 @@
<string>Produktlista</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="QLineEdit" name="productListSearch">
<property name="placeholderText">
<string>Sök...</string>
</property>
</widget>
</item>
<item>
<widget class="QTableView" name="tableView">
<property name="sizeIncrement">
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment