feat: added data model and ui for main window
This commit is contained in:
@@ -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(
|
||||
|
||||
BIN
deps/add.png
vendored
Normal file
BIN
deps/add.png
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 647 KiB |
BIN
deps/delete.png
vendored
Normal file
BIN
deps/delete.png
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 631 KiB |
6
deps/deps.qrc
vendored
6
deps/deps.qrc
vendored
@@ -2,5 +2,11 @@
|
||||
<RCC version="1.0">
|
||||
<qresource prefix="/deps">
|
||||
<file alias="icon.png">icon.png</file>
|
||||
<file alias="reload.png">reload.png</file>
|
||||
<file alias="add.png">add.png</file>
|
||||
<file alias="edit.png">edit.png</file>
|
||||
<file alias="delete.png">delete.png</file>
|
||||
<file alias="info.png">info.png</file>
|
||||
<file alias="tables.ddl">tables.ddl</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
BIN
deps/edit.png
vendored
Normal file
BIN
deps/edit.png
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.4 MiB |
BIN
deps/info.png
vendored
Normal file
BIN
deps/info.png
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.4 MiB |
BIN
deps/reload.png
vendored
Normal file
BIN
deps/reload.png
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.4 MiB |
15
deps/tables.ddl
vendored
Normal file
15
deps/tables.ddl
vendored
Normal file
@@ -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 '';
|
||||
@@ -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()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@@ -1,8 +1,50 @@
|
||||
#ifndef LICENSEMANAGER_LICENSEMODEL_H
|
||||
#define LICENSEMANAGER_LICENSEMODEL_H
|
||||
|
||||
#include <QAbstractTableModel>
|
||||
|
||||
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<LicenseItem> m_data;
|
||||
QStringList m_errors;
|
||||
};
|
||||
|
||||
|
||||
#endif // LICENSEMANAGER_LICENSEMODEL_H
|
||||
|
||||
@@ -1,22 +1,66 @@
|
||||
#include "MainWidget.h"
|
||||
|
||||
// Qt
|
||||
#include <QMenu>
|
||||
#include <QMessageBox>
|
||||
#include <QTableView>
|
||||
#include <QToolBar>
|
||||
#include <QVBoxLayout>
|
||||
#include <QContextMenuEvent>
|
||||
|
||||
// Qt
|
||||
#include <QAction>
|
||||
|
||||
// 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()
|
||||
{
|
||||
|
||||
|
||||
@@ -4,6 +4,11 @@
|
||||
// Qt
|
||||
#include <QMainWindow>
|
||||
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};
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user