summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--database.cpp15
-rw-r--r--dbdesign/database.mwbbin6988 -> 6976 bytes
-rw-r--r--productinventory.cpp37
-rw-r--r--productinventory.h7
-rw-r--r--productinventory.ui146
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
--- a/dbdesign/database.mwb
+++ b/dbdesign/database.mwb
Binary files 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<QTableWidget *>::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<QCheckBox *>::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<QTableWidget *>::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 <QSqlError>
#include <QMessageBox>
#include <QTableWidgetItem>
+#include <QSplitter>
+#include <QCheckBox>
+#include <QGridLayout>
#include <QDebug>
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<QLabel *> labels; // labels used for table names
-
+ void resizeRows(); // resize all table rows to fit the content
+ QList<QCheckBox *> 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 @@
</item>
<item row="2" column="0">
<layout class="QFormLayout" name="formLayout">
- <item row="1" column="0">
- <widget class="QLineEdit" name="usernameInput">
- <property name="text">
- <string>inventory</string>
- </property>
- </widget>
- </item>
<item row="0" column="0">
<widget class="QLabel" name="usernameLabel">
<property name="text">
@@ -89,6 +82,13 @@
</property>
</widget>
</item>
+ <item row="1" column="0">
+ <widget class="QLineEdit" name="usernameInput">
+ <property name="text">
+ <string>inventory</string>
+ </property>
+ </widget>
+ </item>
<item row="1" column="1">
<widget class="QLineEdit" name="passwordInput">
<property name="font">
@@ -104,10 +104,10 @@
</property>
</widget>
</item>
- <item row="4" column="0">
- <widget class="QPushButton" name="connectButton">
+ <item row="2" column="0">
+ <widget class="QLabel" name="databaseLabel">
<property name="text">
- <string>Connect</string>
+ <string>Database</string>
</property>
</widget>
</item>
@@ -118,10 +118,24 @@
</property>
</widget>
</item>
- <item row="2" column="0">
- <widget class="QLabel" name="databaseLabel">
+ <item row="6" column="0">
+ <widget class="QPushButton" name="connectButton">
<property name="text">
- <string>Database</string>
+ <string>Connect</string>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="1">
+ <widget class="QLabel" name="imagesDirLabel">
+ <property name="text">
+ <string>Images directory</string>
+ </property>
+ </widget>
+ </item>
+ <item row="3" column="1">
+ <widget class="QLineEdit" name="imagesDirInput">
+ <property name="text">
+ <string>https://192.168.1.17/inventory/images/</string>
</property>
</widget>
</item>
@@ -136,20 +150,6 @@
<layout class="QFormLayout" name="formLayout_6">
<item row="0" column="0">
<layout class="QGridLayout" name="gridLayout_4">
- <item row="1" column="0">
- <widget class="QLabel" name="filterBrandsLabel">
- <property name="text">
- <string>Filter brands</string>
- </property>
- </widget>
- </item>
- <item row="2" column="0">
- <widget class="QLabel" name="IncludesTextBrandsLabel">
- <property name="text">
- <string>Includes text:</string>
- </property>
- </widget>
- </item>
<item row="3" column="1">
<spacer name="verticalSpacer">
<property name="orientation">
@@ -163,6 +163,13 @@
</property>
</spacer>
</item>
+ <item row="1" column="0">
+ <widget class="QLabel" name="filterBrandsLabel">
+ <property name="text">
+ <string>Filter brands</string>
+ </property>
+ </widget>
+ </item>
<item row="2" column="1">
<widget class="QLineEdit" name="includesTextBrandsInput">
<property name="minimumSize">
@@ -173,6 +180,38 @@
</property>
</widget>
</item>
+ <item row="2" column="0">
+ <widget class="QLabel" name="IncludesTextBrandsLabel">
+ <property name="text">
+ <string>Includes text:</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item row="1" column="0">
+ <widget class="QPushButton" name="pushButton">
+ <property name="text">
+ <string>Filter</string>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="0">
+ <layout class="QFormLayout" name="formLayout_5">
+ <item row="0" column="0">
+ <widget class="QLabel" name="statsLabel">
+ <property name="text">
+ <string>Stats:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="0">
+ <widget class="QLabel" name="statsHereLabel">
+ <property name="text">
+ <string>STATS_PLACEHOLDER</string>
+ </property>
+ </widget>
+ </item>
</layout>
</item>
<item row="0" column="1">
@@ -207,14 +246,14 @@
</property>
</widget>
</item>
- <item row="2" column="0">
+ <item row="3" column="0">
<widget class="QLabel" name="includesTextProductsLabel">
<property name="text">
<string>Includes text:</string>
</property>
</widget>
</item>
- <item row="2" column="1">
+ <item row="3" column="1">
<widget class="QLineEdit" name="includesTextProductsInput">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
@@ -230,7 +269,7 @@
</property>
</widget>
</item>
- <item row="3" column="0">
+ <item row="5" column="0">
<widget class="QCheckBox" name="mustHaveImagesCheckBox">
<property name="layoutDirection">
<enum>Qt::LeftToRight</enum>
@@ -243,35 +282,42 @@
</property>
</widget>
</item>
- <item row="4" column="0">
+ <item row="6" column="0">
<widget class="QCheckBox" name="mustNotHaveImagesCheckBox">
<property name="text">
<string>Must not have images</string>
</property>
</widget>
</item>
- </layout>
- </item>
- <item row="1" column="0">
- <widget class="QPushButton" name="pushButton">
- <property name="text">
- <string>Filter</string>
- </property>
- </widget>
- </item>
- <item row="2" column="0">
- <layout class="QFormLayout" name="formLayout_5">
- <item row="0" column="0">
- <widget class="QLabel" name="statsLabel">
+ <item row="4" column="0" colspan="2">
+ <widget class="QScrollArea" name="filterCategoryScrollArea">
+ <property name="widgetResizable">
+ <bool>true</bool>
+ </property>
+ <widget class="QWidget" name="scrollAreaWidgetContents_2">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>318</width>
+ <height>68</height>
+ </rect>
+ </property>
+ <layout class="QGridLayout" name="gridLayout_3"/>
+ </widget>
+ </widget>
+ </item>
+ <item row="5" column="1">
+ <widget class="QCheckBox" name="newestFirstCheckBox">
<property name="text">
- <string>Stats:</string>
+ <string>Newest first</string>
</property>
</widget>
</item>
- <item row="1" column="0">
- <widget class="QLabel" name="statsHereLabel">
+ <item row="6" column="1">
+ <widget class="QCheckBox" name="oldestFirstCheckBox">
<property name="text">
- <string>STATS_PLACEHOLDER</string>
+ <string>Oldest first</string>
</property>
</widget>
</item>
@@ -291,8 +337,8 @@
<rect>
<x>0</x>
<y>0</y>
- <width>563</width>
- <height>165</height>
+ <width>549</width>
+ <height>118</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout">