From d977c34d53a2d11b2d0f912e303c27c8af64a4cb Mon Sep 17 00:00:00 2001 From: Daniel Jones Date: Mon, 8 Apr 2019 16:45:24 +0930 Subject: database changes, lots of core work --- database.cpp | 15 +++++- dbdesign/database.mwb | Bin 6988 -> 6976 bytes productinventory.cpp | 37 ++++++++++--- productinventory.h | 7 ++- productinventory.ui | 146 +++++++++++++++++++++++++++++++++----------------- 5 files changed, 147 insertions(+), 58 deletions(-) diff --git a/database.cpp b/database.cpp index c079238..1c4f620 100644 --- a/database.cpp +++ b/database.cpp @@ -43,6 +43,7 @@ ProductInventory::dbConnect() return true; } qDebug() << "sql connection failed:" << db.lastError().text(); + genericMessageBox(db.lastError().text(), "server error"); return false; } @@ -100,6 +101,7 @@ ProductInventory::populateInterface() if (query == nullptr) { qDebug() << "failed to populate interface"; + return; } else { @@ -107,6 +109,13 @@ ProductInventory::populateInterface() { QString name = query->value(2).toString(); 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); } delete query; } @@ -116,6 +125,7 @@ ProductInventory::populateInterface() if (query == nullptr) { qDebug() << "failed to populate interface"; + return; } else { @@ -129,7 +139,7 @@ ProductInventory::populateInterface() return; } - QSqlQuery *inner = genericQuery("SELECT brand, color, comment FROM product WHERE 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()); if (inner == nullptr) { qDebug() << "failed to populate interface"; @@ -142,10 +152,13 @@ ProductInventory::populateInterface() item.append(inner->value(0).toString()); item.append(inner->value(1).toString()); item.append(inner->value(2).toString()); + item.append("images here"); + item.append(inner->value(3).toString()); addItemToTable(tables.at(t), &item); } delete inner; } delete query; + resizeRows(); } } diff --git a/dbdesign/database.mwb b/dbdesign/database.mwb index 947cc04..11d1546 100644 Binary files a/dbdesign/database.mwb and b/dbdesign/database.mwb differ diff --git a/productinventory.cpp b/productinventory.cpp index 6b26aa0..5842a81 100644 --- a/productinventory.cpp +++ b/productinventory.cpp @@ -45,6 +45,12 @@ ProductInventory::ProductInventory(QWidget *parent) : headerLabels.append(QString("Brand")); headerLabels.append(QString("Color")); headerLabels.append(QString("Comment")); + 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); } /*! @@ -53,6 +59,7 @@ ProductInventory::ProductInventory(QWidget *parent) : ProductInventory::~ProductInventory() { clearTables(); + delete categoryLayout; delete ui; } @@ -140,11 +147,7 @@ ProductInventory::resizeEvent(QResizeEvent* event) { QMainWindow::resizeEvent(event); ui->tableWidget->resizeRowsToContents(); // not needed? - QList::iterator i; - for (i = tables.begin(); i != tables.end(); i++) - { - (*i)->resizeRowsToContents(); - } + resizeRows(); } void ProductInventory::on_mustHaveImagesCheckBox_clicked() @@ -199,7 +202,16 @@ ProductInventory::clearTables() { (*l)->hide(); labels.erase(l); + delete *l; } + + QList::iterator c; + for (c = checkboxes.begin(); c != checkboxes.end(); c++) + { + checkboxes.erase(c); + delete *c; + } + } /*! @@ -213,7 +225,7 @@ ProductInventory::createTable(QString category) if (table == nullptr) return -1; table->setMinimumHeight(100); - table->setColumnCount(3); + table->setColumnCount(headerLabels.size()); table->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch); table->setHorizontalHeaderLabels(headerLabels); table->verticalHeader()->hide(); @@ -228,3 +240,16 @@ ProductInventory::createTable(QString category) tables.append(table); return tables.size()-1; } + +/*! + * resize each row in every table to fit its content + */ +void +ProductInventory::resizeRows() +{ + QList::iterator i; + for (i = tables.begin(); i != tables.end(); i++) + { + (*i)->resizeRowsToContents(); + } +} diff --git a/productinventory.h b/productinventory.h index 34df6c4..8d748bc 100644 --- a/productinventory.h +++ b/productinventory.h @@ -26,6 +26,9 @@ #include #include #include +#include +#include +#include #include namespace Ui { @@ -71,7 +74,9 @@ private: int createTable(QString category); // create a table and add it to our tables list with a header, returns index in list or -1 QStringList headerLabels; // labels used for table headers 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 2837b39..fe3ecb7 100644 --- a/productinventory.ui +++ b/productinventory.ui @@ -68,13 +68,6 @@ - - - - inventory - - - @@ -89,6 +82,13 @@ + + + + inventory + + + @@ -104,10 +104,10 @@ - - + + - Connect + Database @@ -118,10 +118,24 @@ - - + + - Database + Connect + + + + + + + Images directory + + + + + + + https://192.168.1.17/inventory/images/ @@ -136,20 +150,6 @@ - - - - Filter brands - - - - - - - Includes text: - - - @@ -163,6 +163,13 @@ + + + + Filter brands + + + @@ -173,6 +180,38 @@ + + + + Includes text: + + + + + + + + + Filter + + + + + + + + + Stats: + + + + + + + STATS_PLACEHOLDER + + + @@ -207,14 +246,14 @@ - + Includes text: - + @@ -230,7 +269,7 @@ - + Qt::LeftToRight @@ -243,35 +282,42 @@ - + Must not have images - - - - - - Filter - - - - - - - + + + + true + + + + + 0 + 0 + 318 + 68 + + + + + + + + - Stats: + Newest first - - + + - STATS_PLACEHOLDER + Oldest first @@ -291,8 +337,8 @@ 0 0 - 563 - 165 + 549 + 118 -- cgit v1.2.3