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 ++++++--- dbdesign/database.mwb | Bin 6976 -> 7059 bytes productinventory.cpp | 54 ++++++++++++-- productinventory.h | 24 ++++++- productinventory.ui | 193 +++++++++++++++++++++++++++++--------------------- 5 files changed, 209 insertions(+), 97 deletions(-) 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; } diff --git a/dbdesign/database.mwb b/dbdesign/database.mwb index 11d1546..68ff242 100644 Binary files a/dbdesign/database.mwb and b/dbdesign/database.mwb differ diff --git a/productinventory.cpp b/productinventory.cpp index 5842a81..7ba3482 100644 --- a/productinventory.cpp +++ b/productinventory.cpp @@ -48,9 +48,6 @@ ProductInventory::ProductInventory(QWidget *parent) : headerLabels.append(QString("Images")); headerLabels.append(QString("Date added")); createTable("Connect to the database to populate the tables"); - - categoryLayout = new QGridLayout; - ui->filterCategoryScrollArea->setLayout(categoryLayout); } /*! @@ -59,7 +56,6 @@ ProductInventory::ProductInventory(QWidget *parent) : ProductInventory::~ProductInventory() { clearTables(); - delete categoryLayout; delete ui; } @@ -187,7 +183,7 @@ ProductInventory::addItemToTable(QTableWidget *table, QList *values) void ProductInventory::clearTables() { - qDebug() << "clearing table and deleting items"; + qDebug() << "clearing tables and deleting items"; ui->tableWidget->setRowCount(0); // automagically deletes items QList::iterator i; for (i = tables.begin(); i != tables.end(); i++) @@ -224,7 +220,7 @@ ProductInventory::createTable(QString category) QTableWidget *table = new QTableWidget; if (table == nullptr) return -1; - table->setMinimumHeight(100); + table->setMinimumHeight(200); table->setColumnCount(headerLabels.size()); table->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch); table->setHorizontalHeaderLabels(headerLabels); @@ -253,3 +249,49 @@ ProductInventory::resizeRows() (*i)->resizeRowsToContents(); } } + +void +ProductInventory::on_selectAllButton_clicked() +{ + QList::iterator c; + for (c = checkboxes.begin(); c != checkboxes.end(); c++) + { + (*c)->setChecked(true); + } +} + +void +ProductInventory::on_unselectAllButton_clicked() +{ + QList::iterator c; + for (c = checkboxes.begin(); c != checkboxes.end(); c++) + { + (*c)->setChecked(false); + } + +} + +void +ProductInventory::on_filterSortAlphabeticalCheckBox_clicked() +{ + ui->filterSortReverseAlphabeticalCheckBox->setChecked(false); +} + +void +ProductInventory::on_filterSortReverseAlphabeticalCheckBox_clicked() +{ + + ui->filterSortAlphabeticalCheckBox->setChecked(false); +} + +void +ProductInventory::on_newestFirstCheckBox_clicked() +{ + ui->oldestFirstCheckBox->setChecked(false); +} + +void +ProductInventory::on_oldestFirstCheckBox_clicked() +{ + ui->newestFirstCheckBox->setChecked(false); +} diff --git a/productinventory.h b/productinventory.h index 8d748bc..d79b949 100644 --- a/productinventory.h +++ b/productinventory.h @@ -28,7 +28,8 @@ #include #include #include -#include +#include +#include #include namespace Ui { @@ -56,6 +57,26 @@ private slots: void on_mustHaveImagesCheckBox_clicked(); // called when must have images filter selected void on_mustNotHaveImagesCheckBox_clicked(); // called when must not have images filter selected + void on_selectAllButton_clicked(); + + void on_unselectAllButton_clicked(); + + void on_checkBox_2_clicked(); + + void on_filterSortAlphaCheckBox_clicked(); + + void on_filterSortRevAlphaCheckBox_clicked(); + + void on_filterSortAlphabeticalCheckBox_clicked(); + + void on_filterSortReverseAlphabeticalCheckbox_clicked(); + + void on_filterSortReverseAlphabeticalCheckBox_clicked(); + + void on_newestFirstCheckBox_clicked(); + + void on_oldestFirstCheckBox_clicked(); + private: Ui::ProductInventory *ui; QString conStatus; // connection status text @@ -76,7 +97,6 @@ private: QList labels; // labels used for table names void resizeRows(); // resize all table rows to fit the content QList checkboxes; // checkboxes used to filter product categories - QGridLayout *categoryLayout; // layout }; #endif // PRODUCTINVENTORY_H diff --git a/productinventory.ui b/productinventory.ui index 3bd84d4..1e10f34 100644 --- a/productinventory.ui +++ b/productinventory.ui @@ -6,8 +6,8 @@ 0 0 - 583 - 484 + 705 + 564 @@ -18,7 +18,7 @@ - + 0 0 @@ -150,7 +150,21 @@ - + + + + Filter brands + + + + + + + Sorting + + + + Qt::Vertical @@ -163,13 +177,6 @@ - - - - Filter brands - - - @@ -187,28 +194,17 @@ - - - - - - Filter - - - - - - - + + - Stats: + Reverse alphabetical - - + + - STATS_PLACEHOLDER + Alphabetical @@ -216,22 +212,22 @@ - + Filter products - - + + - Category + Includes text: - - + + 0 @@ -246,30 +242,85 @@ - - + + - Includes text: + Categories - - - - - 0 - 0 - + + + + + + + 0 + 0 + + + + + 90 + 16777215 + + + + Select all + + + + + + + + 0 + 0 + + + + + 90 + 16777215 + + + + Unselect all + + + + + + + + + QAbstractScrollArea::AdjustToContents - - - 115 - 0 - + + true + + + + 0 + 0 + 395 + 68 + + + + + + + 0 + + + + + - + Qt::LeftToRight @@ -282,39 +333,21 @@ - + Must not have images - - - - true - - - - - 0 - 0 - 318 - 68 - - - - - - - + Newest first - + Oldest first @@ -323,6 +356,13 @@ + + + + Filter + + + @@ -337,8 +377,8 @@ 0 0 - 549 - 118 + 685 + 187 @@ -429,7 +469,7 @@ 0 0 - 583 + 705 20 @@ -461,13 +501,8 @@ scrollArea tableWidget includesTextBrandsInput - filterCategoryComboBox - includesTextProductsInput filterCategoryScrollArea mustHaveImagesCheckBox - newestFirstCheckBox - mustNotHaveImagesCheckBox - oldestFirstCheckBox pushButton -- cgit v1.2.3