src/InventorySuppliers.cpp

changeset 65
2ef981980daa
parent 64
b0d30697af67
child 66
72386c164f54
equal deleted inserted replaced
64:b0d30697af67 65:2ef981980daa
15 * along with this program. If not, see <http://www.gnu.org/licenses/>. 15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */ 16 */
17 #include "InventorySuppliers.h" 17 #include "InventorySuppliers.h"
18 #include "EditSupplier.h" 18 #include "EditSupplier.h"
19 #include "MainWindow.h" 19 #include "MainWindow.h"
20 #include "../ui/ui_InventorySuppliers.h"
21 #include "config.h" 20 #include "config.h"
22 #include "bmsapp.h" 21 #include "bmsapp.h"
23 22
24 23
25 24
26 InventorySuppliers::InventorySuppliers(QWidget *parent) : QDialog(parent), ui(new Ui::InventorySuppliers) 25 InventorySuppliers::InventorySuppliers(QWidget *parent) : QDialog(parent) /*, ui(new Ui::InventorySuppliers)*/
27 { 26 {
28 qDebug() << "InventorySuppliers start"; 27 qDebug() << "InventorySuppliers start";
29 28
30 ui->setupUi(this); 29 gridLayout = new QGridLayout(this);
30 gridLayout->setObjectName(QString::fromUtf8("gridLayout"));
31 tableSuppliers = new QTableWidget(this);
32 tableSuppliers->setObjectName(QString::fromUtf8("tableSuppliers"));
33 tableSuppliers->setEnabled(true);
34 QSizePolicy sizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);
35 sizePolicy.setHorizontalStretch(0);
36 sizePolicy.setVerticalStretch(0);
37 sizePolicy.setHeightForWidth(tableSuppliers->sizePolicy().hasHeightForWidth());
38 tableSuppliers->setSizePolicy(sizePolicy);
39 tableSuppliers->setMinimumSize(QSize(1054, 0));
40 gridLayout->addWidget(tableSuppliers, 0, 0, 1, 1);
41
42 groupBox = new QGroupBox(this);
43 groupBox->setObjectName(QString::fromUtf8("groupBox"));
44 groupBox->setEnabled(true);
45 groupBox->setFlat(false);
46 horizontalLayout = new QHBoxLayout(groupBox);
47 horizontalLayout->setSpacing(6);
48 horizontalLayout->setObjectName(QString::fromUtf8("horizontalLayout"));
49 horizontalLayout->setContentsMargins(0, 0, 0, 0);
50 quitButton = new QPushButton(groupBox);
51 quitButton->setObjectName(QString::fromUtf8("quitButton"));
52 quitButton->setMinimumSize(QSize(80, 24));
53 QIcon icon;
54 icon.addFile(QString::fromUtf8(":icons/silk/door_out.png"), QSize(), QIcon::Normal, QIcon::Off);
55 quitButton->setIcon(icon);
56 horizontalLayout->addWidget(quitButton, 0, Qt::AlignLeft);
57
58 insertButton = new QPushButton(groupBox);
59 insertButton->setObjectName(QString::fromUtf8("insertButton"));
60 insertButton->setMinimumSize(QSize(80, 24));
61 QIcon icon1;
62 icon1.addFile(QString::fromUtf8(":icons/silk/table_row_insert.png"), QSize(), QIcon::Normal, QIcon::Off);
63 insertButton->setIcon(icon1);
64 horizontalLayout->addWidget(insertButton, 0, Qt::AlignRight);
65
66 gridLayout->addWidget(groupBox, 1, 0, 1, 1);
67
68 //retranslateUi(this);
69
70 connect(quitButton, SIGNAL(clicked()), parent, SLOT(fromInventorySuppliers()));
71 connect(insertButton, SIGNAL(clicked()), this, SLOT(on_insertButton_clicked()));
31 emit refreshTable(); 72 emit refreshTable();
32 } 73 }
33 74
34 75
35 void InventorySuppliers::refreshTable() 76 void InventorySuppliers::refreshTable()
37 qDebug() << "InventorySuppliers reload"; 78 qDebug() << "InventorySuppliers reload";
38 79
39 QSqlQuery query("SELECT * FROM inventory_suppliers ORDER BY name"); 80 QSqlQuery query("SELECT * FROM inventory_suppliers ORDER BY name");
40 const QStringList labels({tr("Name"), tr("Address"), tr("City"), tr("Country"), tr("Phone"), tr("Edit")}); 81 const QStringList labels({tr("Name"), tr("Address"), tr("City"), tr("Country"), tr("Phone"), tr("Edit")});
41 82
42 ui->tableSuppliers->setColumnCount(6); 83 this->tableSuppliers->setColumnCount(6);
43 ui->tableSuppliers->setColumnWidth(0, 250); /* Name */ 84 this->tableSuppliers->setColumnWidth(0, 250); /* Name */
44 ui->tableSuppliers->setColumnWidth(1, 250); /* Address */ 85 this->tableSuppliers->setColumnWidth(1, 250); /* Address */
45 ui->tableSuppliers->setColumnWidth(2, 200); /* City */ 86 this->tableSuppliers->setColumnWidth(2, 200); /* City */
46 ui->tableSuppliers->setColumnWidth(3, 120); /* Country */ 87 this->tableSuppliers->setColumnWidth(3, 120); /* Country */
47 ui->tableSuppliers->setColumnWidth(4, 120); /* Phone */ 88 this->tableSuppliers->setColumnWidth(4, 120); /* Phone */
48 ui->tableSuppliers->setColumnWidth(5, 90); /* Edit button */ 89 this->tableSuppliers->setColumnWidth(5, 90); /* Edit button */
49 ui->tableSuppliers->setRowCount(query.size()); 90 this->tableSuppliers->setRowCount(query.size());
50 ui->tableSuppliers->setHorizontalHeaderLabels(labels); 91 this->tableSuppliers->setHorizontalHeaderLabels(labels);
51 ui->tableSuppliers->verticalHeader()->hide(); 92 this->tableSuppliers->verticalHeader()->hide();
52 /* Set the widget size to 1054 x 575 in the ui. */ 93 /* Set the widget size to 1054 x 575 in the ui. */
53 94
54 query.first(); 95 query.first();
55 for (int ridx = 0 ; ridx < query.size() ; ridx++ ) { 96 for (int ridx = 0 ; ridx < query.size() ; ridx++ ) {
56 ui->tableSuppliers->setItem(ridx, 0, new QTableWidgetItem(query.value(1).toString())); 97 this->tableSuppliers->setItem(ridx, 0, new QTableWidgetItem(query.value(1).toString()));
57 ui->tableSuppliers->setItem(ridx, 1, new QTableWidgetItem(query.value(2).toString())); 98 this->tableSuppliers->setItem(ridx, 1, new QTableWidgetItem(query.value(2).toString()));
58 ui->tableSuppliers->setItem(ridx, 2, new QTableWidgetItem(query.value(3).toString())); 99 this->tableSuppliers->setItem(ridx, 2, new QTableWidgetItem(query.value(3).toString()));
59 ui->tableSuppliers->setItem(ridx, 3, new QTableWidgetItem(query.value(5).toString())); 100 this->tableSuppliers->setItem(ridx, 3, new QTableWidgetItem(query.value(5).toString()));
60 ui->tableSuppliers->setItem(ridx, 4, new QTableWidgetItem(query.value(8).toString())); 101 this->tableSuppliers->setItem(ridx, 4, new QTableWidgetItem(query.value(8).toString()));
61 102
62 /* Add the Edit button */ 103 /* Add the Edit button */
63 QWidget* pWidget = new QWidget(); 104 QWidget* pWidget = new QWidget();
64 QPushButton* btn_edit = new QPushButton(); 105 QPushButton* btn_edit = new QPushButton();
65 btn_edit->setObjectName(QString("%1").arg(query.value(0).toString())); /* Send record with the button */ 106 btn_edit->setObjectName(QString("%1").arg(query.value(0).toString())); /* Send record with the button */
67 connect(btn_edit, SIGNAL(clicked()), this, SLOT(on_editButton_clicked())); 108 connect(btn_edit, SIGNAL(clicked()), this, SLOT(on_editButton_clicked()));
68 QHBoxLayout* pLayout = new QHBoxLayout(pWidget); 109 QHBoxLayout* pLayout = new QHBoxLayout(pWidget);
69 pLayout->addWidget(btn_edit); 110 pLayout->addWidget(btn_edit);
70 pLayout->setContentsMargins(5, 0, 5, 0); 111 pLayout->setContentsMargins(5, 0, 5, 0);
71 pWidget->setLayout(pLayout); 112 pWidget->setLayout(pLayout);
72 ui->tableSuppliers->setCellWidget(ridx, 5, pWidget); 113 this->tableSuppliers->setCellWidget(ridx, 5, pWidget);
73 query.next(); 114 query.next();
74 } 115 }
75 } 116 }
76 117
77 118
78 InventorySuppliers::~InventorySuppliers() 119 InventorySuppliers::~InventorySuppliers()
79 { 120 {
80 qDebug() << "InventorySuppliers done"; 121 qDebug() << "InventorySuppliers done";
81 // delete ui;
82 } 122 }
83 123
84 124
85 void InventorySuppliers::edit(int recno) 125 void InventorySuppliers::edit(int recno)
86 { 126 {
107 { 147 {
108 qDebug() << Q_FUNC_INFO; 148 qDebug() << Q_FUNC_INFO;
109 edit(-1); 149 edit(-1);
110 } 150 }
111 151
112
113 void InventorySuppliers::on_quitButton_clicked()
114 {
115 qDebug() << Q_FUNC_INFO;
116
117 MainWindow a;
118 a.fromInventorySuppliers();
119 }
120

mercurial