Wed, 18 Oct 2023 16:00:06 +0200
Added application icon
/** * 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 "MainWindow.h" #include "config.h" /* * Build the table and buttons on the mainscreen. * Don't use a ui file, do it dynamicly. */ InventorySuppliers::InventorySuppliers(QWidget *parent) : QDialog(parent) { qDebug() << "InventorySuppliers start"; gridLayout = new QGridLayout(this); gridLayout->setObjectName(QString::fromUtf8("gridLayout")); tableSuppliers = new QTableWidget(this); tableSuppliers->setObjectName(QString::fromUtf8("tableSuppliers")); tableSuppliers->setEnabled(true); QSizePolicy sizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding); sizePolicy.setHorizontalStretch(0); sizePolicy.setVerticalStretch(0); sizePolicy.setHeightForWidth(tableSuppliers->sizePolicy().hasHeightForWidth()); tableSuppliers->setSizePolicy(sizePolicy); tableSuppliers->setMinimumSize(QSize(1054, 0)); gridLayout->addWidget(tableSuppliers, 0, 0, 1, 1); groupBox = new QGroupBox(this); groupBox->setObjectName(QString::fromUtf8("groupBox")); groupBox->setEnabled(true); groupBox->setFlat(false); horizontalLayout = new QHBoxLayout(groupBox); horizontalLayout->setSpacing(6); horizontalLayout->setObjectName(QString::fromUtf8("horizontalLayout")); horizontalLayout->setContentsMargins(0, 0, 0, 0); quitButton = new QPushButton(groupBox); quitButton->setObjectName(QString::fromUtf8("quitButton")); quitButton->setMinimumSize(QSize(80, 24)); quitButton->setText(tr("Quit")); QIcon icon; icon.addFile(QString::fromUtf8(":icons/silk/door_out.png"), QSize(), QIcon::Normal, QIcon::Off); quitButton->setIcon(icon); horizontalLayout->addWidget(quitButton, 0, Qt::AlignLeft); insertButton = new QPushButton(groupBox); insertButton->setObjectName(QString::fromUtf8("insertButton")); insertButton->setMinimumSize(QSize(80, 24)); insertButton->setText(tr("New")); QIcon icon1; icon1.addFile(QString::fromUtf8(":icons/silk/table_row_insert.png"), QSize(), QIcon::Normal, QIcon::Off); insertButton->setIcon(icon1); horizontalLayout->addWidget(insertButton, 0, Qt::AlignRight); gridLayout->addWidget(groupBox, 1, 0, 1, 1); connect(quitButton, SIGNAL(clicked()), parent, SLOT(fromInventorySuppliers())); connect(insertButton, SIGNAL(clicked()), this, SLOT(on_insertButton_clicked())); connect(this, SIGNAL(setStatus(QString)), parent, SLOT(statusMsg(QString))); emit refreshTable(); } void InventorySuppliers::refreshTable() { qDebug() << "InventorySuppliers reload"; QSqlQuery query("SELECT * FROM inventory_suppliers ORDER BY name"); const QStringList labels({tr("Name"), tr("Address"), tr("City"), tr("Country"), tr("Phone"), tr("Edit")}); this->tableSuppliers->setColumnCount(6); this->tableSuppliers->setColumnWidth(0, 250); /* Name */ this->tableSuppliers->setColumnWidth(1, 250); /* Address */ this->tableSuppliers->setColumnWidth(2, 200); /* City */ this->tableSuppliers->setColumnWidth(3, 120); /* Country */ this->tableSuppliers->setColumnWidth(4, 120); /* Phone */ this->tableSuppliers->setColumnWidth(5, 90); /* Edit button */ this->tableSuppliers->setRowCount(query.size()); this->tableSuppliers->setHorizontalHeaderLabels(labels); this->tableSuppliers->verticalHeader()->hide(); /* Set the widget size to 1054 x 575 in the ui. */ query.first(); for (int ridx = 0 ; ridx < query.size() ; ridx++ ) { this->tableSuppliers->setItem(ridx, 0, new QTableWidgetItem(query.value(1).toString())); this->tableSuppliers->setItem(ridx, 1, new QTableWidgetItem(query.value(2).toString())); this->tableSuppliers->setItem(ridx, 2, new QTableWidgetItem(query.value(3).toString())); this->tableSuppliers->setItem(ridx, 3, new QTableWidgetItem(query.value(5).toString())); this->tableSuppliers->setItem(ridx, 4, new QTableWidgetItem(query.value(8).toString())); /* 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->setContentsMargins(5, 0, 5, 0); pWidget->setLayout(pLayout); this->tableSuppliers->setCellWidget(ridx, 5, pWidget); query.next(); } emit setStatus(QString(tr("Total items: %1")).arg(query.size())); } InventorySuppliers::~InventorySuppliers() {} void InventorySuppliers::edit(int 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(); edit(recno); } void InventorySuppliers::on_insertButton_clicked() { edit(-1); }