src/InventorySuppliers.cpp

Fri, 18 Feb 2022 15:53:02 +0100

author
Michiel Broek <mbroek@mbse.eu>
date
Fri, 18 Feb 2022 15:53:02 +0100
changeset 19
c94edc758a5b
parent 12
66e10898a2a9
child 22
b52978ee7412
permissions
-rw-r--r--

Added Inventory Fermentables table.

/**
 * InventorySuppliers.cpp is part of bmsapp.
 *
 * bmsapp is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * bmsapp is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
#include "InventorySuppliers.h"
#include "EditSupplier.h"
#include "../ui/ui_InventorySuppliers.h"
#include "config.h"
#include "bmsapp.h"



InventorySuppliers::InventorySuppliers(QWidget *parent) : QDialog(parent), ui(new Ui::InventorySuppliers)
{
    qDebug() << "InventorySuppliers start";

    ui->setupUi(this);
    emit refreshTable();

    setWindowTitle( QString("BMSapp - %1 - Inventory Suppliers").arg(VERSIONSTRING) );
}


void InventorySuppliers::refreshTable()
{
    qDebug() << "slot"  << Q_FUNC_INFO;

    QSqlQuery query("SELECT * FROM inventory_suppliers ORDER BY name");
    const QStringList labels({tr("Record"), tr("Name"), tr("Address"), tr("City"), tr("Country"), tr("Phone"), tr("Edit")});

    ui->tableSuppliers->setColumnCount(7);
    ui->tableSuppliers->setColumnWidth(0, 50);	/* Record	*/
    ui->tableSuppliers->setColumnWidth(1, 250);	/* Name		*/
    ui->tableSuppliers->setColumnWidth(2, 250);	/* Address	*/
    ui->tableSuppliers->setColumnWidth(3, 200);	/* City		*/
    ui->tableSuppliers->setColumnWidth(4, 120);	/* Country	*/
    ui->tableSuppliers->setColumnWidth(5, 120);	/* Phone	*/
    ui->tableSuppliers->setColumnWidth(6, 90);	/* Edit button	*/
    ui->tableSuppliers->setRowCount(query.size());
    ui->tableSuppliers->setHorizontalHeaderLabels(labels);
    ui->tableSuppliers->verticalHeader()->hide();
    ui->tableSuppliers->setFixedSize(1280, 640);	/* Even if this is too large, it works */

//    qDebug() << query.record().count() << query.size();
    query.first();
    for (int ridx = 0 ; ridx < query.size() ; ridx++ ) {
	for (int cidx = 0 ; cidx < 4; cidx++) {
	    QTableWidgetItem* item = new QTableWidgetItem(query.value(cidx).toString());
	    ui->tableSuppliers->setItem(ridx, cidx, item );
	}
//	qDebug() << ridx << "record:" << query.value(0).toString() << " name:" << query.value(1).toString();
	QTableWidgetItem* item = new QTableWidgetItem(query.value(5).toString());
	ui->tableSuppliers->setItem(ridx, 4, item );
	item = new QTableWidgetItem(query.value(8).toString());
        ui->tableSuppliers->setItem(ridx, 5, item );
	/* Add the Edit button */
	QWidget* pWidget = new QWidget();
	QPushButton* btn_edit = new QPushButton();
	btn_edit->setObjectName(QString("%1").arg(query.value(0).toString()));	/* Send record with the button */
	btn_edit->setText(tr("Edit"));
	connect(btn_edit, SIGNAL(clicked()), this, SLOT(on_editButton_clicked()));
	QHBoxLayout* pLayout = new QHBoxLayout(pWidget);
	pLayout->addWidget(btn_edit);
//	pLayout->setAlignment(Qt::AlignCenter);
	pLayout->setContentsMargins(5, 0, 5, 0);
	pWidget->setLayout(pLayout);
	ui->tableSuppliers->setCellWidget(ridx, 6, pWidget);
	query.next();
    }

    setWindowTitle( QString("BMSapp - %1 - Inventory Suppliers").arg(VERSIONSTRING) );
}


InventorySuppliers::~InventorySuppliers()
{
    qDebug() << "InventorySuppliers done";
    delete ui;
}


void InventorySuppliers::edit(int recno)
{
    qDebug() << "InventorySuppliers edit:" << recno;

    EditSupplier dialog(recno, this);
    /* Signal from editor if a refresh is needed */
    connect(&dialog, SIGNAL(entry_changed()), this, SLOT(refreshTable()));
    dialog.setModal(true);
    dialog.exec();
}


void InventorySuppliers::on_editButton_clicked()
{
    QPushButton *pb = qobject_cast<QPushButton *>(QObject::sender());
    int recno = pb->objectName().toInt();
    qDebug() << Q_FUNC_INFO << recno;
    edit(recno);
}


void InventorySuppliers::on_insertButton_clicked()
{
    qDebug() << Q_FUNC_INFO;
    edit(-1);
}


void InventorySuppliers::on_quitButton_clicked()
{
    emit firstWindow();
}

mercurial