feat: added information dialog and handle selection change

This commit is contained in:
2026-01-17 14:57:03 +03:00
parent f6ec31183a
commit 89bd070613
4 changed files with 80 additions and 4 deletions

View File

@@ -40,3 +40,35 @@ target_link_libraries(
Qt5::Widgets
)
find_package(Git QUIET)
set(GIT_BRANCH "unknown")
set(GIT_COMMIT_HASH "unknown")
if(GIT_FOUND)
execute_process(
COMMAND "${GIT_EXECUTABLE}" rev-parse --abbrev-ref HEAD
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
OUTPUT_VARIABLE GIT_BRANCH
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_QUIET
)
execute_process(
COMMAND "${GIT_EXECUTABLE}" rev-parse HEAD
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
OUTPUT_VARIABLE GIT_COMMIT_HASH
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_QUIET
)
if(GIT_BRANCH STREQUAL "HEAD")
set(GIT_BRANCH "detached")
endif()
endif()
target_compile_definitions(${PROJECT_NAME} PRIVATE
PROJECT_VERSION_STR=\"${PROJECT_NAME}\"
GIT_BRANCH_STR=\"${GIT_BRANCH}\"
GIT_COMMIT_HASH_STR=\"${GIT_COMMIT_HASH}\"
)

View File

@@ -72,10 +72,10 @@ QVariant LicenseModel::headerData(int section, Qt::Orientation orientation, int
LicenseModel::Status LicenseModel::getStatus()
{
return Status::Ok;
}
QString LicenseModel::getStatusText()
{
return m_errors.join('n');
}

View File

@@ -1,8 +1,10 @@
#include "MainWidget.h"
// Qt
#include <QHeaderView>
#include <QLabel>
#include <QMenu>
#include <QMessageBox>
#include <QPushButton>
#include <QTableView>
#include <QToolBar>
#include <QVBoxLayout>
@@ -12,6 +14,8 @@
#include <QAction>
// Self
#include <QMessageBox>
#include "LicenseModel/LicenseModel.h"
MainWidget::MainWidget(QWidget *parent)
@@ -25,9 +29,12 @@ MainWidget::MainWidget(QWidget *parent)
// Ui
{
m_tableView = new QTableView(this);
m_tableView->horizontalHeader()->setStretchLastSection(true);
m_tableView->setModel(m_licenseModel);
setCentralWidget(m_tableView);
connect(m_tableView->selectionModel(), &QItemSelectionModel::selectionChanged, this, &MainWidget::selectionChanged);
// ToolTip
{
m_toolBar = addToolBar("ToolBar");
@@ -61,6 +68,7 @@ MainWidget::MainWidget(QWidget *parent)
}
m_tableView->resizeColumnsToContents();
selectionChanged({}, {});
loadSettings();
}
@@ -76,7 +84,32 @@ void MainWidget::onCustomContextMenuRequested(const QPoint &pos)
void MainWidget::onGetInfoTriggered()
{
QDialog dialog(this);
dialog.setModal(true);
auto vLayout = new QVBoxLayout;
dialog.setLayout(vLayout);
QIcon icon(":/deps/icon.png");
QLabel *iconLabel = new QLabel;
iconLabel->setPixmap(icon.pixmap(300, 300));
iconLabel->setAlignment(Qt::AlignCenter);
vLayout->addWidget(iconLabel);
auto projectLabel = new QLabel(QString(tr("Project name: %1")).arg(PROJECT_VERSION_STR), &dialog);
projectLabel->setTextInteractionFlags(Qt::TextSelectableByMouse);
vLayout->addWidget(projectLabel);
auto gitBranchLabel = new QLabel(QString("Git branch: %1").arg(GIT_BRANCH_STR), &dialog);
gitBranchLabel->setTextInteractionFlags(Qt::TextSelectableByMouse);
vLayout->addWidget(gitBranchLabel);
auto gitCommitLabel = new QLabel(QString("Git commit: %1").arg(GIT_COMMIT_HASH_STR), &dialog);
gitCommitLabel->setTextInteractionFlags(Qt::TextSelectableByMouse);
vLayout->addWidget(gitCommitLabel);
vLayout->addStretch();
auto hLayout = new QHBoxLayout;
hLayout->addStretch();
auto closeButton = new QPushButton(tr("Close"), &dialog);
hLayout->addWidget(closeButton);
vLayout->addItem(hLayout);
connect(closeButton, &QPushButton::clicked, &dialog, &QDialog::reject);
dialog.exec();
}
void MainWidget::onReloadTableTriggered()
@@ -99,6 +132,15 @@ void MainWidget::onDeleteClientTriggered()
}
void MainWidget::selectionChanged(const QItemSelection &selected, const QItemSelection &deselected)
{
Q_UNUSED(deselected);
auto selectedCount = selected.size();
m_editClientsMenuAction->setEnabled(selectedCount == 1);
m_deleteClientsMenuAction->setEnabled(selectedCount > 0);
}
void MainWidget::closeEvent(QCloseEvent *event)
{
QMessageBox::StandardButton reply;

View File

@@ -3,6 +3,7 @@
// Qt
#include <QMainWindow>
#include <QItemSelection>
class QTableView;
class QMenu;
class QAction;
@@ -27,6 +28,7 @@ private slots:
void onAddClientTriggered();
void onEditClientTriggered();
void onDeleteClientTriggered();
void selectionChanged(const QItemSelection &selected, const QItemSelection &deselected);
private:
void saveSettings();