From 89bd070613a3afa20cffe15193ffe61757cfae00 Mon Sep 17 00:00:00 2001 From: ziabric Date: Sat, 17 Jan 2026 14:57:03 +0300 Subject: [PATCH] feat: added information dialog and handle selection change --- CMakeLists.txt | 32 +++++++++++++++++++++ src/LicenseModel/LicenseModel.cpp | 4 +-- src/MainWidget/MainWidget.cpp | 46 +++++++++++++++++++++++++++++-- src/MainWidget/MainWidget.h | 2 ++ 4 files changed, 80 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ec28e02..f1e67b9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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}\" +) diff --git a/src/LicenseModel/LicenseModel.cpp b/src/LicenseModel/LicenseModel.cpp index 645126c..a36e69a 100644 --- a/src/LicenseModel/LicenseModel.cpp +++ b/src/LicenseModel/LicenseModel.cpp @@ -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'); } diff --git a/src/MainWidget/MainWidget.cpp b/src/MainWidget/MainWidget.cpp index fd7fa97..e4fafeb 100644 --- a/src/MainWidget/MainWidget.cpp +++ b/src/MainWidget/MainWidget.cpp @@ -1,8 +1,10 @@ #include "MainWidget.h" // Qt +#include +#include #include -#include +#include #include #include #include @@ -12,6 +14,8 @@ #include // Self +#include + #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; diff --git a/src/MainWidget/MainWidget.h b/src/MainWidget/MainWidget.h index bac8167..4e2edf4 100644 --- a/src/MainWidget/MainWidget.h +++ b/src/MainWidget/MainWidget.h @@ -3,6 +3,7 @@ // Qt #include +#include 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();