first commit
This commit is contained in:
commit
abec938590
27
.gitignore
vendored
Normal file
27
.gitignore
vendored
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
# Created by https://www.toptal.com/developers/gitignore/api/cmake
|
||||||
|
# Edit at https://www.toptal.com/developers/gitignore?templates=cmake
|
||||||
|
|
||||||
|
### CMake ###
|
||||||
|
CMakeLists.txt.user
|
||||||
|
CMakeCache.txt
|
||||||
|
CMakeFiles
|
||||||
|
CMakeScripts
|
||||||
|
Testing
|
||||||
|
Makefile
|
||||||
|
cmake_install.cmake
|
||||||
|
install_manifest.txt
|
||||||
|
compile_commands.json
|
||||||
|
CTestTestfile.cmake
|
||||||
|
_deps
|
||||||
|
|
||||||
|
### CMake Patch ###
|
||||||
|
CMakeUserPresets.json
|
||||||
|
|
||||||
|
# External projects
|
||||||
|
*-prefix/
|
||||||
|
|
||||||
|
# End of https://www.toptal.com/developers/gitignore/api/cmake
|
||||||
|
|
||||||
|
build
|
||||||
|
|
||||||
|
data
|
20
CMakeLists.txt
Normal file
20
CMakeLists.txt
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.16)
|
||||||
|
project(stock_manager)
|
||||||
|
|
||||||
|
set(CMAKE_CXX_STANDARD 17)
|
||||||
|
set(CMAKE_AUTOMOC ON)
|
||||||
|
|
||||||
|
find_package(Qt5 REQUIRED COMPONENTS Widgets)
|
||||||
|
find_package(nlohmann_json REQUIRED)
|
||||||
|
|
||||||
|
include_directories(include src)
|
||||||
|
|
||||||
|
add_executable(stock_manager
|
||||||
|
main.cpp
|
||||||
|
src/stockmanager.cpp
|
||||||
|
)
|
||||||
|
|
||||||
|
target_link_libraries(stock_manager
|
||||||
|
Qt5::Widgets
|
||||||
|
nlohmann_json::nlohmann_json
|
||||||
|
)
|
18
include/models.hpp
Normal file
18
include/models.hpp
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
#ifndef MODELS_HPP
|
||||||
|
#define MODELS_HPP
|
||||||
|
|
||||||
|
#include <QString>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
struct Item {
|
||||||
|
QString name;
|
||||||
|
int quantity;
|
||||||
|
int limit;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Category {
|
||||||
|
QString name;
|
||||||
|
std::vector<Item> items;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // MODELS_HPP
|
14
main.cpp
Normal file
14
main.cpp
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
#include <QApplication>
|
||||||
|
#include "stockmanager.h"
|
||||||
|
|
||||||
|
int main(int argc, char *argv[]) {
|
||||||
|
QApplication app(argc, argv);
|
||||||
|
StockManager w;
|
||||||
|
|
||||||
|
w.setGeometry(0, 0, 1024, 600); // position en haut à gauche, taille 1024x600
|
||||||
|
w.setWindowFlags(Qt::FramelessWindowHint); // pas de barre de fenêtre
|
||||||
|
w.setFixedSize(1024, 600); // taille non redimensionnable
|
||||||
|
w.show();
|
||||||
|
|
||||||
|
return app.exec();
|
||||||
|
}
|
131
src/stockmanager.cpp
Normal file
131
src/stockmanager.cpp
Normal file
@ -0,0 +1,131 @@
|
|||||||
|
#include "stockmanager.h"
|
||||||
|
#include <QVBoxLayout>
|
||||||
|
#include <QHBoxLayout>
|
||||||
|
#include <QPushButton>
|
||||||
|
#include <QLabel>
|
||||||
|
#include <QMessageBox>
|
||||||
|
#include <QFileDialog>
|
||||||
|
#include <fstream>
|
||||||
|
#include <nlohmann/json.hpp>
|
||||||
|
|
||||||
|
using json = nlohmann::json;
|
||||||
|
|
||||||
|
StockManager::StockManager() {
|
||||||
|
setWindowTitle("Gestionnaire de Stock");
|
||||||
|
|
||||||
|
QWidget* central = new QWidget;
|
||||||
|
QVBoxLayout* mainLayout = new QVBoxLayout;
|
||||||
|
QHBoxLayout* topLayout = new QHBoxLayout;
|
||||||
|
|
||||||
|
categoryList = new QListWidget;
|
||||||
|
itemList = new QListWidget;
|
||||||
|
|
||||||
|
topLayout->addWidget(categoryList);
|
||||||
|
topLayout->addWidget(itemList);
|
||||||
|
|
||||||
|
QHBoxLayout* addCatLayout = new QHBoxLayout;
|
||||||
|
catNameInput = new QLineEdit;
|
||||||
|
QPushButton* addCatButton = new QPushButton("Ajouter Categorie");
|
||||||
|
addCatLayout->addWidget(catNameInput);
|
||||||
|
addCatLayout->addWidget(addCatButton);
|
||||||
|
|
||||||
|
QHBoxLayout* addItemLayout = new QHBoxLayout;
|
||||||
|
itemNameInput = new QLineEdit;
|
||||||
|
itemQtyInput = new QSpinBox;
|
||||||
|
itemLimitInput = new QSpinBox;
|
||||||
|
itemQtyInput->setMaximum(10000);
|
||||||
|
itemLimitInput->setMaximum(10000);
|
||||||
|
QPushButton* addItemButton = new QPushButton("Ajouter Objet");
|
||||||
|
addItemLayout->addWidget(itemNameInput);
|
||||||
|
addItemLayout->addWidget(itemQtyInput);
|
||||||
|
addItemLayout->addWidget(itemLimitInput);
|
||||||
|
addItemLayout->addWidget(addItemButton);
|
||||||
|
|
||||||
|
QPushButton* saveButton = new QPushButton("Sauvegarder");
|
||||||
|
QPushButton* loadButton = new QPushButton("Charger");
|
||||||
|
|
||||||
|
mainLayout->addLayout(topLayout);
|
||||||
|
mainLayout->addLayout(addCatLayout);
|
||||||
|
mainLayout->addLayout(addItemLayout);
|
||||||
|
mainLayout->addWidget(saveButton);
|
||||||
|
mainLayout->addWidget(loadButton);
|
||||||
|
central->setLayout(mainLayout);
|
||||||
|
setCentralWidget(central);
|
||||||
|
|
||||||
|
connect(addCatButton, &QPushButton::clicked, this, &StockManager::addCategory);
|
||||||
|
connect(addItemButton, &QPushButton::clicked, this, &StockManager::addItem);
|
||||||
|
connect(saveButton, &QPushButton::clicked, this, &StockManager::saveToFile);
|
||||||
|
connect(loadButton, &QPushButton::clicked, this, &StockManager::loadFromFile);
|
||||||
|
connect(categoryList, &QListWidget::currentTextChanged, this, &StockManager::updateItemList);
|
||||||
|
}
|
||||||
|
|
||||||
|
void StockManager::addCategory() {
|
||||||
|
QString name = catNameInput->text();
|
||||||
|
if (name.isEmpty() || categories.count(name)) return;
|
||||||
|
categories[name] = Category{name};
|
||||||
|
categoryList->addItem(name);
|
||||||
|
catNameInput->clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
void StockManager::addItem() {
|
||||||
|
QString catName = categoryList->currentItem() ? categoryList->currentItem()->text() : "";
|
||||||
|
if (catName.isEmpty()) return;
|
||||||
|
QString name = itemNameInput->text();
|
||||||
|
int qty = itemQtyInput->value();
|
||||||
|
int lim = itemLimitInput->value();
|
||||||
|
if (name.isEmpty()) return;
|
||||||
|
|
||||||
|
auto& items = categories[catName].items;
|
||||||
|
for (const auto& i : items)
|
||||||
|
if (i.name == name) return;
|
||||||
|
|
||||||
|
items.push_back(Item{name, qty, lim});
|
||||||
|
updateItemList(catName);
|
||||||
|
itemNameInput->clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
void StockManager::updateItemList(const QString& catName) {
|
||||||
|
itemList->clear();
|
||||||
|
for (const auto& item : categories[catName].items) {
|
||||||
|
itemList->addItem(item.name + " | Stock: " + QString::number(item.quantity) + " / Limite: " + QString::number(item.limit));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void StockManager::saveToFile() {
|
||||||
|
QString filename = QFileDialog::getSaveFileName(this, "Sauvegarder sous", "stock.json");
|
||||||
|
if (filename.isEmpty()) return;
|
||||||
|
json j;
|
||||||
|
for (const auto& [catName, cat] : categories) {
|
||||||
|
for (const auto& item : cat.items) {
|
||||||
|
j[catName.toStdString()].push_back({{"name", item.name.toStdString()}, {"quantity", item.quantity}, {"limit", item.limit}});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
std::ofstream file(filename.toStdString());
|
||||||
|
file << j.dump(4);
|
||||||
|
}
|
||||||
|
|
||||||
|
void StockManager::loadFromFile() {
|
||||||
|
QString filename = QFileDialog::getOpenFileName(this, "Charger depuis", "stock.json");
|
||||||
|
if (filename.isEmpty()) return;
|
||||||
|
std::ifstream file(filename.toStdString());
|
||||||
|
if (!file) return;
|
||||||
|
|
||||||
|
json j;
|
||||||
|
file >> j;
|
||||||
|
categories.clear();
|
||||||
|
categoryList->clear();
|
||||||
|
itemList->clear();
|
||||||
|
|
||||||
|
for (auto& [catName, items] : j.items()) {
|
||||||
|
Category cat{QString::fromStdString(catName)};
|
||||||
|
for (auto& it : items) {
|
||||||
|
cat.items.push_back(Item{
|
||||||
|
QString::fromStdString(it["name"]),
|
||||||
|
it["quantity"],
|
||||||
|
it["limit"]
|
||||||
|
});
|
||||||
|
}
|
||||||
|
categories[QString::fromStdString(catName)] = cat;
|
||||||
|
categoryList->addItem(QString::fromStdString(catName));
|
||||||
|
}
|
||||||
|
}
|
35
src/stockmanager.h
Normal file
35
src/stockmanager.h
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
#ifndef STOCKMANAGER_H
|
||||||
|
#define STOCKMANAGER_H
|
||||||
|
|
||||||
|
#include <QMainWindow>
|
||||||
|
#include <QListWidget>
|
||||||
|
#include <QLineEdit>
|
||||||
|
#include <QSpinBox>
|
||||||
|
#include <unordered_map>
|
||||||
|
#include "models.hpp"
|
||||||
|
|
||||||
|
class StockManager : public QMainWindow {
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::unordered_map<QString, Category> categories;
|
||||||
|
|
||||||
|
QListWidget* categoryList;
|
||||||
|
QListWidget* itemList;
|
||||||
|
QLineEdit* catNameInput;
|
||||||
|
QLineEdit* itemNameInput;
|
||||||
|
QSpinBox* itemQtyInput;
|
||||||
|
QSpinBox* itemLimitInput;
|
||||||
|
|
||||||
|
public:
|
||||||
|
StockManager();
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void addCategory();
|
||||||
|
void addItem();
|
||||||
|
void updateItemList(const QString& catName);
|
||||||
|
void saveToFile();
|
||||||
|
void loadFromFile();
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // STOCKMANAGER_H
|
Loading…
x
Reference in New Issue
Block a user