feat: Add edit client dialog
This commit is contained in:
@@ -19,6 +19,7 @@ file(GLOB
|
||||
"src/*"
|
||||
"src/MainWidget/*"
|
||||
"src/LicenseModel/*"
|
||||
"src/EditClientDialog/*"
|
||||
"deps/deps.qrc"
|
||||
)
|
||||
|
||||
|
||||
1
deps/deps.qrc
vendored
1
deps/deps.qrc
vendored
@@ -7,6 +7,7 @@
|
||||
<file alias="edit.png">edit.png</file>
|
||||
<file alias="delete.png">delete.png</file>
|
||||
<file alias="info.png">info.png</file>
|
||||
<file alias="dropFiles.png">dropFiles.png</file>
|
||||
<file alias="tables.ddl">tables.ddl</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
BIN
deps/dropFiles.png
vendored
Normal file
BIN
deps/dropFiles.png
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.5 MiB |
85
src/EditClientDialog/DropFileWidget.cpp
Normal file
85
src/EditClientDialog/DropFileWidget.cpp
Normal file
@@ -0,0 +1,85 @@
|
||||
#include "DropFileWidget.h"
|
||||
|
||||
// Qt
|
||||
#include <QDebug>
|
||||
#include <QDropEvent>
|
||||
#include <QFileDialog>
|
||||
#include <QIcon>
|
||||
#include <QLabel>
|
||||
#include <QMimeData>
|
||||
#include <QStandardPaths>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
DropFileWidget::DropFileWidget(QWidget *parent)
|
||||
: QWidget(parent)
|
||||
{
|
||||
setAcceptDrops(true);
|
||||
|
||||
QVBoxLayout *layout = new QVBoxLayout(this);
|
||||
setLayout(layout);
|
||||
|
||||
QIcon icon(":/deps/dropFiles.png");
|
||||
QLabel *iconLabel = new QLabel(this);
|
||||
iconLabel->setPixmap(icon.pixmap(300, 300));
|
||||
iconLabel->setAlignment(Qt::AlignCenter);
|
||||
layout->addWidget(iconLabel);
|
||||
}
|
||||
|
||||
void DropFileWidget::dragEnterEvent(QDragEnterEvent *e)
|
||||
{
|
||||
if (e->mimeData()->hasUrls())
|
||||
e->acceptProposedAction();
|
||||
else
|
||||
e->ignore();
|
||||
}
|
||||
|
||||
void DropFileWidget::dragMoveEvent(QDragMoveEvent *e)
|
||||
{
|
||||
if (e->mimeData()->hasUrls())
|
||||
e->acceptProposedAction();
|
||||
else
|
||||
e->ignore();
|
||||
}
|
||||
|
||||
void DropFileWidget::dropEvent(QDropEvent *e)
|
||||
{
|
||||
if (e->mimeData()->hasUrls())
|
||||
{
|
||||
QStringList paths;
|
||||
const auto urls = e->mimeData()->urls();
|
||||
for (const QUrl &url : urls)
|
||||
{
|
||||
if (url.isLocalFile())
|
||||
{
|
||||
const QString path = url.toLocalFile();
|
||||
if (!path.isEmpty())
|
||||
paths << path;
|
||||
}
|
||||
}
|
||||
|
||||
if (!paths.isEmpty())
|
||||
{
|
||||
emit filesDropped(paths);
|
||||
e->acceptProposedAction();
|
||||
}
|
||||
else
|
||||
e->ignore();
|
||||
}
|
||||
}
|
||||
|
||||
void DropFileWidget::mousePressEvent(QMouseEvent *e)
|
||||
{
|
||||
if (e->button() == Qt::LeftButton)
|
||||
selectFiles();
|
||||
QWidget::mousePressEvent(e);
|
||||
}
|
||||
|
||||
void DropFileWidget::selectFiles()
|
||||
{
|
||||
auto files = QFileDialog::getOpenFileNames(
|
||||
this
|
||||
, tr("Select config file")
|
||||
, QStandardPaths::writableLocation(QStandardPaths::HomeLocation)
|
||||
);
|
||||
emit filesDropped(files);
|
||||
}
|
||||
23
src/EditClientDialog/DropFileWidget.h
Normal file
23
src/EditClientDialog/DropFileWidget.h
Normal file
@@ -0,0 +1,23 @@
|
||||
#ifndef LICENSEMANAGER_DROPFILEWIDGET_H
|
||||
#define LICENSEMANAGER_DROPFILEWIDGET_H
|
||||
|
||||
// Qt
|
||||
#include <QWidget>
|
||||
class QLabel;
|
||||
|
||||
class DropFileWidget : public QWidget {
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit DropFileWidget(QWidget *parent = nullptr);
|
||||
signals:
|
||||
void filesDropped(const QStringList &paths);
|
||||
protected:
|
||||
void dragEnterEvent(QDragEnterEvent *e) override;
|
||||
void dragMoveEvent(QDragMoveEvent *e) override;
|
||||
void dropEvent(QDropEvent *e) override;
|
||||
void mousePressEvent(QMouseEvent *e) override;
|
||||
private:
|
||||
void selectFiles();
|
||||
};
|
||||
|
||||
#endif //LICENSEMANAGER_DROPFILEWIDGET_H
|
||||
103
src/EditClientDialog/EditClientDialog.cpp
Normal file
103
src/EditClientDialog/EditClientDialog.cpp
Normal file
@@ -0,0 +1,103 @@
|
||||
#include "EditClientDialog.h"
|
||||
|
||||
// Qt
|
||||
#include <QLabel>
|
||||
#include <QPushButton>
|
||||
#include <QTabWidget>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
// Self
|
||||
#include "DropFileWidget.h"
|
||||
#include "LicenseModel/LicenseModel.h"
|
||||
|
||||
EditClientDialog::EditClientDialog(LicenseModel* model, QWidget *parent)
|
||||
: QDialog(parent)
|
||||
, m_model(model)
|
||||
{
|
||||
setWindowTitle(tr("Edit Client"));
|
||||
setModal(true);
|
||||
setAcceptDrops(true);
|
||||
|
||||
// Ui
|
||||
{
|
||||
auto vLayout = new QVBoxLayout;
|
||||
setLayout(vLayout);
|
||||
m_tabWidget = new QTabWidget(this);
|
||||
vLayout->addWidget(m_tabWidget);
|
||||
|
||||
// Auto filled widget
|
||||
{
|
||||
auto autoFilledWidget = new QWidget(m_tabWidget);
|
||||
auto layout = new QVBoxLayout;
|
||||
autoFilledWidget->setLayout(layout);
|
||||
|
||||
auto dropWidget = new DropFileWidget(autoFilledWidget);
|
||||
layout->addWidget(dropWidget);
|
||||
layout->addStretch();
|
||||
m_configPathLabel = new QLabel(tr("Drop file here"));
|
||||
m_configPathLabel->setAlignment(Qt::AlignCenter);
|
||||
layout->addWidget(m_configPathLabel);
|
||||
m_tabWidget->addTab(autoFilledWidget, tr("File autofilled"));
|
||||
|
||||
connect(dropWidget, &DropFileWidget::filesDropped, this, &EditClientDialog::onFilesChanged);
|
||||
}
|
||||
|
||||
// Manual user add widget
|
||||
{
|
||||
auto manualWidget = new QWidget(m_tabWidget);
|
||||
auto layout = new QVBoxLayout;
|
||||
manualWidget->setLayout(layout);
|
||||
|
||||
|
||||
|
||||
m_tabWidget->addTab(manualWidget, tr("Manual"));
|
||||
}
|
||||
|
||||
auto hLayout = new QHBoxLayout;
|
||||
hLayout->setSpacing(vLayout->spacing());
|
||||
hLayout->addStretch();
|
||||
m_saveButton = new QPushButton(tr("Save"), this);
|
||||
hLayout->addWidget(m_saveButton);
|
||||
auto cancelButton = new QPushButton(tr("Cancel"), this);
|
||||
hLayout->addWidget(cancelButton);
|
||||
vLayout->addItem(hLayout);
|
||||
|
||||
connect(m_saveButton, &QPushButton::clicked, this, &EditClientDialog::onSaveButtonClicked);
|
||||
connect(cancelButton, &QPushButton::clicked, this, &QDialog::reject);
|
||||
}
|
||||
|
||||
loadSettings();
|
||||
}
|
||||
|
||||
EditClientDialog::~EditClientDialog()
|
||||
{
|
||||
saveSettings();
|
||||
}
|
||||
|
||||
void EditClientDialog::loadSettings()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void EditClientDialog::saveSettings()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void EditClientDialog::onSaveButtonClicked()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void EditClientDialog::onFilesChanged(const QStringList &paths)
|
||||
{
|
||||
if (paths.isEmpty())
|
||||
return;
|
||||
QFile file(paths.at(0));
|
||||
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
|
||||
return;
|
||||
|
||||
file.close();
|
||||
m_filesPath = paths.at(0);
|
||||
m_configPathLabel->setText(paths.at(0).split("/").last());
|
||||
}
|
||||
37
src/EditClientDialog/EditClientDialog.h
Normal file
37
src/EditClientDialog/EditClientDialog.h
Normal file
@@ -0,0 +1,37 @@
|
||||
#ifndef LICENSEMANAGER_EDITCLIENTDIALOG_H
|
||||
#define LICENSEMANAGER_EDITCLIENTDIALOG_H
|
||||
|
||||
// Qt
|
||||
#include <QDebug>
|
||||
#include <QDialog>
|
||||
#include <QDragEnterEvent>
|
||||
#include <QLabel>
|
||||
#include <QMimeData>
|
||||
class QTabWidget;
|
||||
|
||||
// Self
|
||||
class LicenseModel;
|
||||
|
||||
class EditClientDialog : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
EditClientDialog(LicenseModel* model, QWidget *parent = nullptr);
|
||||
~EditClientDialog();
|
||||
|
||||
private slots:
|
||||
void onSaveButtonClicked();
|
||||
void onFilesChanged(const QStringList &paths);
|
||||
private:
|
||||
void loadSettings();
|
||||
void saveSettings();
|
||||
private:
|
||||
LicenseModel* m_model{nullptr};
|
||||
QTabWidget* m_tabWidget{nullptr};
|
||||
QLabel* m_configPathLabel{nullptr};
|
||||
|
||||
QPushButton* m_saveButton{nullptr};
|
||||
QString m_filesPath;
|
||||
};
|
||||
|
||||
#endif //LICENSEMANAGER_EDITCLIENTDIALOG_H
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
// Self
|
||||
#include "LicenseModel/LicenseModel.h"
|
||||
#include "EditClientDialog/EditClientDialog.h"
|
||||
|
||||
MainWidget::MainWidget(QWidget *parent)
|
||||
: QMainWindow(parent)
|
||||
@@ -107,7 +108,7 @@ void MainWidget::onGetInfoTriggered()
|
||||
auto vLayout = new QVBoxLayout;
|
||||
dialog.setLayout(vLayout);
|
||||
QIcon icon(":/deps/icon.png");
|
||||
QLabel *iconLabel = new QLabel;
|
||||
QLabel *iconLabel = new QLabel(&dialog);
|
||||
iconLabel->setPixmap(icon.pixmap(300, 300));
|
||||
iconLabel->setAlignment(Qt::AlignCenter);
|
||||
vLayout->addWidget(iconLabel);
|
||||
@@ -137,7 +138,8 @@ void MainWidget::onReloadTableTriggered()
|
||||
|
||||
void MainWidget::onAddClientTriggered()
|
||||
{
|
||||
|
||||
EditClientDialog dialog(m_licenseModel, this);
|
||||
dialog.exec();
|
||||
}
|
||||
|
||||
void MainWidget::onEditClientTriggered()
|
||||
|
||||
Reference in New Issue
Block a user