You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
prodejna/shop/receiptloadform.cpp

73 lines
2.3 KiB
C++

#include <QSortFilterProxyModel>
#include "receiptloadform.h"
#include "ui_receiptloadform.h"
#include "shopservice.h"
#include "shop-odb.hxx"
ReceiptLoadForm::ReceiptLoadForm(QWidget *parent) :
QDialog(parent),
ui(new Ui::ReceiptLoadForm)
{
ui->setupUi(this);
m_voucherModel = new AutoTableModel<Voucher>(this);
ShopService srv;
m_voucherModel->setData(srv.all(QString("status = %1").arg(QString::number(Voucher::NOT_PAID))));
m_voucherModel->setTranslations(Context::instance().plugin("SHOP")->translations());
ui->tabVouchers->setModel(m_voucherModel);
9 years ago
ui->tabVouchers->hideColumn(0);
ui->tabVouchers->hideColumn(1);
ui->tabVouchers->hideColumn(5);
ui->tabVouchers->hideColumn(6);
ui->tabVouchers->hideColumn(7);
ui->tabVouchers->hideColumn(8);
9 years ago
ui->tabVouchers->hideColumn(9);
ui->tabVouchers->hideColumn(10);
9 years ago
ui->tabVouchers->hideColumn(12);
ui->tabVouchers->horizontalHeader()->setSectionResizeMode(2, QHeaderView::Stretch);
ui->tabVouchers->setColumnWidth(3, 200);
ui->tabVouchers->setColumnWidth(4, 200);
m_itemModel = new AutoTableModel<VoucherItem>(this);
m_itemModel->setCheckboxSelect(true);
ui->tabItems->setModel(m_itemModel);
9 years ago
ui->tabItems->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch);
connect(ui->tabVouchers->selectionModel(), &QItemSelectionModel::currentRowChanged, [this](const QModelIndex &current, QModelIndex){
ShopService srv;
VoucherPtr voucher = m_voucherModel->itemFromIndex(current);
srv.loadItems(voucher);
m_itemModel->setData(voucher->items());
});
}
ReceiptLoadForm::~ReceiptLoadForm()
{
delete ui;
}
QList<VoucherItemPtr> ReceiptLoadForm::selectedItems()
{
return m_itemModel->selectedItems();
}
VoucherPtr ReceiptLoadForm::selectedVoucher()
{
return m_voucherModel->itemFromIndex(ui->tabVouchers->currentIndex());
}
void ReceiptLoadForm::on_lineEdit_textChanged(const QString &text)
{
QSortFilterProxyModel proxy;
proxy.setSourceModel(m_voucherModel);
9 years ago
proxy.setFilterKeyColumn(2);
proxy.setFilterFixedString(text);
QModelIndex matchingIndex = proxy.mapToSource(proxy.index(0,0));
if(matchingIndex.isValid()){
ui->tabVouchers->scrollTo(matchingIndex,QAbstractItemView::EnsureVisible);
ui->tabVouchers->setCurrentIndex(matchingIndex);
}
}