summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--database.cpp35
-rw-r--r--dbdesign/database.mwbbin6976 -> 7059 bytes
-rw-r--r--productinventory.cpp54
-rw-r--r--productinventory.h24
-rw-r--r--productinventory.ui193
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
--- a/dbdesign/database.mwb
+++ b/dbdesign/database.mwb
Binary files 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<QString> *values)
void
ProductInventory::clearTables()
{
- qDebug() << "clearing table and deleting items";
+ qDebug() << "clearing tables and deleting items";
ui->tableWidget->setRowCount(0); // automagically deletes items
QList<QTableWidget *>::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<QCheckBox *>::iterator c;
+ for (c = checkboxes.begin(); c != checkboxes.end(); c++)
+ {
+ (*c)->setChecked(true);
+ }
+}
+
+void
+ProductInventory::on_unselectAllButton_clicked()
+{
+ QList<QCheckBox *>::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 <QTableWidgetItem>
#include <QSplitter>
#include <QCheckBox>
-#include <QGridLayout>
+#include <QVBoxLayout>
+#include <qscrollbar.h>
#include <QDebug>
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<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 3bd84d4..1e10f34 100644
--- a/productinventory.ui
+++ b/productinventory.ui
@@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
- <width>583</width>
- <height>484</height>
+ <width>705</width>
+ <height>564</height>
</rect>
</property>
<property name="windowTitle">
@@ -18,7 +18,7 @@
<item>
<widget class="QTabWidget" name="mainTabs">
<property name="sizePolicy">
- <sizepolicy hsizetype="Ignored" vsizetype="Expanding">
+ <sizepolicy hsizetype="Minimum" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
@@ -150,7 +150,21 @@
<layout class="QFormLayout" name="formLayout_6">
<item row="0" column="0">
<layout class="QGridLayout" name="gridLayout_4">
- <item row="3" column="1">
+ <item row="1" column="0">
+ <widget class="QLabel" name="filterBrandsLabel">
+ <property name="text">
+ <string>Filter brands</string>
+ </property>
+ </widget>
+ </item>
+ <item row="3" column="0">
+ <widget class="QLabel" name="label">
+ <property name="text">
+ <string>Sorting</string>
+ </property>
+ </widget>
+ </item>
+ <item row="5" column="1">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
@@ -163,13 +177,6 @@
</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">
@@ -187,28 +194,17 @@
</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="1">
+ <widget class="QCheckBox" name="filterSortReverseAlphabeticalCheckBox">
<property name="text">
- <string>Stats:</string>
+ <string>Reverse alphabetical</string>
</property>
</widget>
</item>
- <item row="1" column="0">
- <widget class="QLabel" name="statsHereLabel">
+ <item row="4" column="0">
+ <widget class="QCheckBox" name="filterSortAlphabeticalCheckBox">
<property name="text">
- <string>STATS_PLACEHOLDER</string>
+ <string>Alphabetical</string>
</property>
</widget>
</item>
@@ -216,22 +212,22 @@
</item>
<item row="0" column="1">
<layout class="QFormLayout" name="formLayout_2">
- <item row="0" column="0">
+ <item row="1" column="0">
<widget class="QLabel" name="filterProductsLabel">
<property name="text">
<string>Filter products</string>
</property>
</widget>
</item>
- <item row="1" column="0">
- <widget class="QLabel" name="filterCategoryLabel">
+ <item row="2" column="0">
+ <widget class="QLabel" name="includesTextProductsLabel">
<property name="text">
- <string>Category</string>
+ <string>Includes text:</string>
</property>
</widget>
</item>
- <item row="1" column="1">
- <widget class="QComboBox" name="filterCategoryComboBox">
+ <item row="2" column="1">
+ <widget class="QLineEdit" name="includesTextProductsInput">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
<horstretch>0</horstretch>
@@ -246,30 +242,85 @@
</property>
</widget>
</item>
- <item row="3" column="0">
- <widget class="QLabel" name="includesTextProductsLabel">
+ <item row="5" column="0">
+ <widget class="QLabel" name="filterCategoryLabel">
<property name="text">
- <string>Includes text:</string>
+ <string>Categories</string>
</property>
</widget>
</item>
- <item row="3" column="1">
- <widget class="QLineEdit" name="includesTextProductsInput">
- <property name="sizePolicy">
- <sizepolicy hsizetype="Maximum" vsizetype="Fixed">
- <horstretch>0</horstretch>
- <verstretch>0</verstretch>
- </sizepolicy>
+ <item row="5" column="1">
+ <layout class="QGridLayout" name="gridLayout_5">
+ <item row="0" column="0">
+ <widget class="QPushButton" name="selectAllButton">
+ <property name="minimumSize">
+ <size>
+ <width>0</width>
+ <height>0</height>
+ </size>
+ </property>
+ <property name="maximumSize">
+ <size>
+ <width>90</width>
+ <height>16777215</height>
+ </size>
+ </property>
+ <property name="text">
+ <string>Select all</string>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="1">
+ <widget class="QPushButton" name="unselectAllButton">
+ <property name="minimumSize">
+ <size>
+ <width>0</width>
+ <height>0</height>
+ </size>
+ </property>
+ <property name="maximumSize">
+ <size>
+ <width>90</width>
+ <height>16777215</height>
+ </size>
+ </property>
+ <property name="text">
+ <string>Unselect all</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item row="7" column="0" colspan="2">
+ <widget class="QScrollArea" name="filterCategoryScrollArea">
+ <property name="sizeAdjustPolicy">
+ <enum>QAbstractScrollArea::AdjustToContents</enum>
</property>
- <property name="minimumSize">
- <size>
- <width>115</width>
- <height>0</height>
- </size>
+ <property name="widgetResizable">
+ <bool>true</bool>
</property>
+ <widget class="QWidget" name="scrollAreaWidgetContents_2">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>395</width>
+ <height>68</height>
+ </rect>
+ </property>
+ <layout class="QGridLayout" name="gridLayout_3">
+ <item row="0" column="0">
+ <layout class="QGridLayout" name="filterCategoryGrid">
+ <property name="spacing">
+ <number>0</number>
+ </property>
+ </layout>
+ </item>
+ </layout>
+ </widget>
</widget>
</item>
- <item row="5" column="0">
+ <item row="8" column="0">
<widget class="QCheckBox" name="mustHaveImagesCheckBox">
<property name="layoutDirection">
<enum>Qt::LeftToRight</enum>
@@ -282,39 +333,21 @@
</property>
</widget>
</item>
- <item row="6" column="0">
+ <item row="8" column="1">
<widget class="QCheckBox" name="mustNotHaveImagesCheckBox">
<property name="text">
<string>Must not have images</string>
</property>
</widget>
</item>
- <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">
+ <item row="9" column="0">
<widget class="QCheckBox" name="newestFirstCheckBox">
<property name="text">
<string>Newest first</string>
</property>
</widget>
</item>
- <item row="6" column="1">
+ <item row="9" column="1">
<widget class="QCheckBox" name="oldestFirstCheckBox">
<property name="text">
<string>Oldest first</string>
@@ -323,6 +356,13 @@
</item>
</layout>
</item>
+ <item row="1" column="0">
+ <widget class="QPushButton" name="pushButton">
+ <property name="text">
+ <string>Filter</string>
+ </property>
+ </widget>
+ </item>
</layout>
</widget>
</widget>
@@ -337,8 +377,8 @@
<rect>
<x>0</x>
<y>0</y>
- <width>549</width>
- <height>118</height>
+ <width>685</width>
+ <height>187</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout">
@@ -429,7 +469,7 @@
<rect>
<x>0</x>
<y>0</y>
- <width>583</width>
+ <width>705</width>
<height>20</height>
</rect>
</property>
@@ -461,13 +501,8 @@
<tabstop>scrollArea</tabstop>
<tabstop>tableWidget</tabstop>
<tabstop>includesTextBrandsInput</tabstop>
- <tabstop>filterCategoryComboBox</tabstop>
- <tabstop>includesTextProductsInput</tabstop>
<tabstop>filterCategoryScrollArea</tabstop>
<tabstop>mustHaveImagesCheckBox</tabstop>
- <tabstop>newestFirstCheckBox</tabstop>
- <tabstop>mustNotHaveImagesCheckBox</tabstop>
- <tabstop>oldestFirstCheckBox</tabstop>
<tabstop>pushButton</tabstop>
</tabstops>
<resources/>