diff --git a/CMakeLists.txt b/CMakeLists.txt index 63e743b..ec28e02 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,6 +10,7 @@ find_package(Qt5 COMPONENTS Core Gui Widgets + Sql REQUIRED ) @@ -18,6 +19,7 @@ file(GLOB "src/*" "src/MainWidget/*" "src/LicenseModel/*" + "deps/deps.qrc" ) add_executable( diff --git a/db/build.sh b/db/build.sh deleted file mode 100644 index e69de29..0000000 diff --git a/db/ext/.ext b/db/ext/.ext deleted file mode 100644 index e69de29..0000000 diff --git a/db/func/.func b/db/func/.func deleted file mode 100644 index e69de29..0000000 diff --git a/db/tables/.tables b/db/tables/.tables deleted file mode 100644 index e69de29..0000000 diff --git a/db/tables/clients.ddl b/db/tables/clients.ddl deleted file mode 100644 index e69de29..0000000 diff --git a/db/views/.views b/db/views/.views deleted file mode 100644 index e69de29..0000000 diff --git a/deps/add.png b/deps/add.png new file mode 100644 index 0000000..f29d4fd Binary files /dev/null and b/deps/add.png differ diff --git a/deps/delete.png b/deps/delete.png new file mode 100644 index 0000000..6b9cf8d Binary files /dev/null and b/deps/delete.png differ diff --git a/deps/deps.qrc b/deps/deps.qrc index b99d629..92d38fb 100644 --- a/deps/deps.qrc +++ b/deps/deps.qrc @@ -2,5 +2,11 @@ icon.png + reload.png + add.png + edit.png + delete.png + info.png + tables.ddl \ No newline at end of file diff --git a/deps/edit.png b/deps/edit.png new file mode 100644 index 0000000..2350817 Binary files /dev/null and b/deps/edit.png differ diff --git a/deps/info.png b/deps/info.png new file mode 100644 index 0000000..a123630 Binary files /dev/null and b/deps/info.png differ diff --git a/deps/reload.png b/deps/reload.png new file mode 100644 index 0000000..b3ca29f Binary files /dev/null and b/deps/reload.png differ diff --git a/deps/tables.ddl b/deps/tables.ddl new file mode 100644 index 0000000..c796cd8 --- /dev/null +++ b/deps/tables.ddl @@ -0,0 +1,15 @@ +CREATE TABLE IF NOT EXISTS clients ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + city TEXT NOT NULL, + email TEXT NOT NULL, + firstName TEXT NOT NULL, + hardwareHash TEXT NOT NULL, + lastName TEXT NOT NULL, + patronymic TEXT NOT NULL, + phone TEXT NOT NULL, + yourCompany TEXT NOT NULL, + comment TEXT +); + +COMMENT ON TABLE clients IS ''; +COMMENT ON FIELD clients.id IS ''; diff --git a/src/LicenseModel/LicenseModel.cpp b/src/LicenseModel/LicenseModel.cpp index a4505c0..645126c 100644 --- a/src/LicenseModel/LicenseModel.cpp +++ b/src/LicenseModel/LicenseModel.cpp @@ -1,5 +1,81 @@ -// -// Created by debian on 1/16/26. -// - #include "LicenseModel.h" + +const static int COLUMN_COUNT = 9; + +LicenseModel::LicenseModel(QObject* parent) + : QAbstractTableModel(parent) +{ + +} + +LicenseModel::~LicenseModel() +{ + +} + +int LicenseModel::rowCount(const QModelIndex &parent) const +{ + return 0; +} + +int LicenseModel::columnCount(const QModelIndex &parent) const +{ + return COLUMN_COUNT; +} +QVariant LicenseModel::data(const QModelIndex &index, int role) const +{ + switch (role) + { + case Qt::DisplayRole: + break; + case Qt::ToolTipRole: + return {}; // TODO: return client id + default: + return {}; + } + + return {}; +} + +QVariant LicenseModel::headerData(int section, Qt::Orientation orientation, int role) const +{ + if (role != Qt::DisplayRole) + return {}; + + if (orientation == Qt::Vertical) + return QString::number(section + 1); + + switch (section) + { + case 0: + return tr("Last name"); + case 1: + return tr("First name"); + case 2: + return tr("Patronymic"); + case 3: + return tr("Email"); + case 4: + return tr("Phone number"); + case 5: + return tr("Company"); + case 6: + return tr("City"); + case 7: + return tr("Created date"); + case 8: + return tr("Comment"); + default: + return {}; + } +} + +LicenseModel::Status LicenseModel::getStatus() +{ + +} + +QString LicenseModel::getStatusText() +{ + +} diff --git a/src/LicenseModel/LicenseModel.h b/src/LicenseModel/LicenseModel.h index ad86462..3bb7fd4 100644 --- a/src/LicenseModel/LicenseModel.h +++ b/src/LicenseModel/LicenseModel.h @@ -1,8 +1,50 @@ #ifndef LICENSEMANAGER_LICENSEMODEL_H #define LICENSEMANAGER_LICENSEMODEL_H +#include -class LicenseModel {}; +class LicenseModel : public QAbstractTableModel +{ + Q_OBJECT +public: + + enum class Status + { + None = 0, + Ok, + DbStructError, + DbExistError, + }; + + struct LicenseItem + { + QString id; + QString city; + QString email; + QString firstName; + QString hardwareHash; + QString lastName; + QString patronymic; + QString phone; + QString yourCompany; + QString comment; + }; + + explicit LicenseModel(QObject* parent = nullptr); + ~LicenseModel(); + + int rowCount(const QModelIndex &parent = QModelIndex()) const override; + int columnCount(const QModelIndex &parent = QModelIndex()) const override; + QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; + QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const; + + Status getStatus(); + QString getStatusText(); + +private: + QList m_data; + QStringList m_errors; +}; #endif // LICENSEMANAGER_LICENSEMODEL_H diff --git a/src/MainWidget/MainWidget.cpp b/src/MainWidget/MainWidget.cpp index 3fc5f22..fd7fa97 100644 --- a/src/MainWidget/MainWidget.cpp +++ b/src/MainWidget/MainWidget.cpp @@ -1,22 +1,66 @@ #include "MainWidget.h" // Qt +#include +#include #include +#include #include +#include + +// Qt +#include + +// Self +#include "LicenseModel/LicenseModel.h" MainWidget::MainWidget(QWidget *parent) : QMainWindow(parent) + , m_licenseModel(new LicenseModel(this)) { - setWindowIcon(QIcon(":/icon.png")); + setWindowIcon(QIcon(QStringLiteral("qrc:/deps/icon.png"))); setWindowTitle("LicenseManager"); - resize({640, 480}); + resize({800, 600}); // Ui { m_tableView = new QTableView(this); + m_tableView->setModel(m_licenseModel); setCentralWidget(m_tableView); + + // ToolTip + { + m_toolBar = addToolBar("ToolBar"); + m_toolBar->setMovable(false); + m_addClientToolBarAction = m_toolBar->addAction(QIcon(QStringLiteral(":/deps/add.png")), tr("Add client")); + m_infoToolBarAction = m_toolBar->addAction(QIcon(QStringLiteral(":/deps/info.png")), tr("Get info")); + + connect(m_addClientToolBarAction, &QAction::triggered, this, &MainWidget::onAddClientTriggered); + connect(m_infoToolBarAction, &QAction::triggered, this, &MainWidget::onGetInfoTriggered); + } + + // Table Menu + { + m_menu = new QMenu(m_tableView); + + m_reloadTableMenuAction = m_menu->addAction(QIcon(QStringLiteral(":/deps/reload.png")), tr("Reload table")); + m_menu->addSeparator(); + m_addClientsMenuAction = m_menu->addAction(QIcon(QStringLiteral(":/deps/add.png")), tr("Add client")); + m_editClientsMenuAction = m_menu->addAction(QIcon(QStringLiteral(":/deps/edit.png")), tr("Edit client")); + m_deleteClientsMenuAction = m_menu->addAction(QIcon(QStringLiteral(":/deps/delete.png")), tr("Delete client")); + + connect(m_reloadTableMenuAction, &QAction::triggered, this, &MainWidget::onAddClientTriggered); + connect(m_addClientsMenuAction, &QAction::triggered, this, &MainWidget::onAddClientTriggered); + connect(m_editClientsMenuAction, &QAction::triggered, this, &MainWidget::onEditClientTriggered); + connect(m_deleteClientsMenuAction, &QAction::triggered, this, &MainWidget::onDeleteClientTriggered); + + m_tableView->setContextMenuPolicy(Qt::CustomContextMenu); + connect(m_tableView, &QTableView::customContextMenuRequested, + this, &MainWidget::onCustomContextMenuRequested); + } } + m_tableView->resizeColumnsToContents(); loadSettings(); } @@ -25,6 +69,52 @@ MainWidget::~MainWidget() saveSettings(); } +void MainWidget::onCustomContextMenuRequested(const QPoint &pos) +{ + m_menu->popup(m_tableView->viewport()->mapToGlobal(pos)); +} + +void MainWidget::onGetInfoTriggered() +{ + +} + +void MainWidget::onReloadTableTriggered() +{ + +} + +void MainWidget::onAddClientTriggered() +{ + +} + +void MainWidget::onEditClientTriggered() +{ + +} + +void MainWidget::onDeleteClientTriggered() +{ + +} + +void MainWidget::closeEvent(QCloseEvent *event) +{ + QMessageBox::StandardButton reply; + reply = QMessageBox::question( + this, + tr("Confirmation of exit"), + tr("Are you sure you want to exit the app?"), + QMessageBox::Yes | QMessageBox::No + ); + + if (reply == QMessageBox::Yes) + event->accept(); + else + event->ignore(); +} + void MainWidget::loadSettings() { diff --git a/src/MainWidget/MainWidget.h b/src/MainWidget/MainWidget.h index 7a63d89..bac8167 100644 --- a/src/MainWidget/MainWidget.h +++ b/src/MainWidget/MainWidget.h @@ -4,6 +4,11 @@ // Qt #include class QTableView; +class QMenu; +class QAction; + +// Self +class LicenseModel; class MainWidget : public QMainWindow { @@ -11,11 +16,33 @@ class MainWidget : public QMainWindow public: explicit MainWidget(QWidget *parent = nullptr); ~MainWidget(); + +protected: + void closeEvent(QCloseEvent *event) override; + +private slots: + void onCustomContextMenuRequested(const QPoint &pos); + void onGetInfoTriggered(); + void onReloadTableTriggered(); + void onAddClientTriggered(); + void onEditClientTriggered(); + void onDeleteClientTriggered(); + private: void saveSettings(); void loadSettings(); + private: QTableView* m_tableView{nullptr}; + LicenseModel* m_licenseModel{nullptr}; + QToolBar* m_toolBar{nullptr}; + QMenu* m_menu{nullptr}; + QAction* m_addClientToolBarAction{nullptr}; + QAction* m_infoToolBarAction{nullptr}; + QAction* m_reloadTableMenuAction{nullptr}; + QAction* m_addClientsMenuAction{nullptr}; + QAction* m_deleteClientsMenuAction{nullptr}; + QAction* m_editClientsMenuAction{nullptr}; }; diff --git a/src/def.h b/src/def.h new file mode 100644 index 0000000..e542b6b --- /dev/null +++ b/src/def.h @@ -0,0 +1,8 @@ +#ifndef LICENSEMANAGER_DEF_H +#define LICENSEMANAGER_DEF_H + +#include + +const static QStringView DB_PATH = "./db.sqlite"; + +#endif //LICENSEMANAGER_DEF_H \ No newline at end of file