src/InventorySuppliers.cpp

Sun, 13 Feb 2022 20:24:33 +0100

author
Michiel Broek <mbroek@mbse.eu>
date
Sun, 13 Feb 2022 20:24:33 +0100
changeset 9
85656dc48131
parent 8
ac4e363c09a7
child 10
8aa2bd9ba9e8
permissions
-rw-r--r--

The Edit buttons include the record number in the database. Ready to build the modal supplier edit/insert/delete screen.

/**
 * 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 "../ui/ui_InventorySuppliers.h"
#include "config.h"

#include <QDebug>
#include <QtSql>
#include <QtWidgets>
#include <QTableWidget>


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

    ui->setupUi(this);

    ui->tableSuppliers = new QTableWidget(ui->tableSuppliers);
    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();
    // So far, so good.
    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 );
	}
	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(0, 0, 0, 0);
	pWidget->setLayout(pLayout);
	ui->tableSuppliers->setCellWidget(ridx, 6, pWidget);
	query.next();
    }

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


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


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

    // Call editor with recno
}


void InventorySuppliers::on_insertButton_clicked()
{
    qDebug() << Q_FUNC_INFO;

    // Call editor with -1
}


void InventorySuppliers::on_quitButton_clicked()
{
    qDebug() << Q_FUNC_INFO;
    emit firstWindow();
}

mercurial