From a140c3d8d118a27d685ce06f7d296d27602c5043 Mon Sep 17 00:00:00 2001 From: Daniel Jones Date: Thu, 11 Apr 2019 10:51:31 +0930 Subject: many fixes, tweaks and things added, mainly checkbox related --- database.cpp | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) (limited to 'database.cpp') diff --git a/database.cpp b/database.cpp index 1c4f620..01ad851 100644 --- a/database.cpp +++ b/database.cpp @@ -96,8 +96,8 @@ ProductInventory::genericQuery(QString query) void ProductInventory::populateInterface() { - ui->filterCategoryComboBox->clear(); - QSqlQuery *query = genericQuery("SELECT * FROM category;"); +// ui->filterCategoryComboBox->clear(); + QSqlQuery *query = genericQuery("SELECT * FROM category ORDER BY name;"); if (query == nullptr) { qDebug() << "failed to populate interface"; @@ -105,17 +105,23 @@ ProductInventory::populateInterface() } else { + int x = 0; + int y = 0; while (query->next()) { + if (x >= 3) + { + y++; + x = 0; + } + QString name = query->value(2).toString(); - ui->filterCategoryComboBox->addItem(name); + //ui->filterCategoryComboBox->addItem(name); QCheckBox *chk = new QCheckBox; chk->setText(query->value(2).toString()); checkboxes.append(chk); - categoryLayout->addWidget(chk); - - ui->filterCategoryScrollArea->setLayout(categoryLayout); - //ui->filterCategoryScrollArea->widget()->layout()->addWidget(chk); + ui->filterCategoryGrid->addWidget(chk, y, x); + x++; } delete query; } @@ -139,7 +145,9 @@ ProductInventory::populateInterface() return; } - QSqlQuery *inner = genericQuery("SELECT brand, color, comment, DATE_FORMAT(dateAdded, \"%d-%m-%Y %h:%i %p\") FROM product WHERE deleted=0 AND categoryid="+query->value(0).toString()); + QSqlQuery *inner = genericQuery("SELECT brand, color, comment, DATE_FORMAT(dateAdded, " + "\"%d-%m-%Y %h:%i %p\") FROM product WHERE deleted=0 AND categoryid=" + +query->value(0).toString()+" ORDER BY brand DESC"); if (inner == nullptr) { qDebug() << "failed to populate interface"; @@ -156,9 +164,16 @@ ProductInventory::populateInterface() item.append(inner->value(3).toString()); addItemToTable(tables.at(t), &item); } + if (tables.at(t)->rowCount() == 0) + { + tables.at(t)->deleteLater(); + tables.removeAt(t); + labels.at(t)->deleteLater(); + labels.removeAt(t); + } delete inner; } - delete query; - resizeRows(); } + resizeRows(); + delete query; } -- cgit v1.2.3