mirror of
https://github.com/edisionnano/QDiskInfo.git
synced 2026-03-07 11:59:57 +03:00
Connect the grid view to show disks
This commit is contained in:
7
include/diskitem.h
Normal file
7
include/diskitem.h
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
#include <QString>
|
||||||
|
|
||||||
|
struct DiskItem {
|
||||||
|
QString name;
|
||||||
|
QString temperature;
|
||||||
|
QString health;
|
||||||
|
};
|
||||||
@@ -5,22 +5,22 @@
|
|||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
#include <QScrollArea>
|
#include <QScrollArea>
|
||||||
|
|
||||||
|
#include "diskitem.h"
|
||||||
|
|
||||||
class GridView : public QWidget {
|
class GridView : public QWidget {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit GridView(QWidget *parent = nullptr);
|
explicit GridView(QWidget *parent = nullptr);
|
||||||
|
void setDisks(const QVector<DiskItem> &newDisks);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void resizeEvent(QResizeEvent *) override;
|
void resizeEvent(QResizeEvent *) override;
|
||||||
|
|
||||||
private:
|
signals:
|
||||||
struct DiskItem {
|
void diskSelected(const QString &diskName);
|
||||||
QString name;
|
|
||||||
QString category;
|
|
||||||
QString icon;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
private:
|
||||||
QString searchQuery;
|
QString searchQuery;
|
||||||
QScrollArea *scrollArea;
|
QScrollArea *scrollArea;
|
||||||
QWidget *gridContainer;
|
QWidget *gridContainer;
|
||||||
|
|||||||
@@ -14,6 +14,7 @@
|
|||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
#include "gridview.h"
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
@@ -80,6 +81,7 @@ private:
|
|||||||
QString globalHealth;
|
QString globalHealth;
|
||||||
bool globalIsNvme;
|
bool globalIsNvme;
|
||||||
QVector<QPair<QString, int>> globalNvmeSmartOrdered;
|
QVector<QPair<QString, int>> globalNvmeSmartOrdered;
|
||||||
|
GridView *gridView;
|
||||||
|
|
||||||
void onNextButtonClicked();
|
void onNextButtonClicked();
|
||||||
void onPrevButtonClicked();
|
void onPrevButtonClicked();
|
||||||
|
|||||||
@@ -50,13 +50,6 @@ GridView::GridView(QWidget *parent) : QWidget(parent) {
|
|||||||
gridLayout->setAlignment(Qt::AlignTop | Qt::AlignHCenter);
|
gridLayout->setAlignment(Qt::AlignTop | Qt::AlignHCenter);
|
||||||
gridLayout->setSpacing(gridLayoutSpacing);
|
gridLayout->setSpacing(gridLayoutSpacing);
|
||||||
gridFrame->setLayout(gridLayout);
|
gridFrame->setLayout(gridLayout);
|
||||||
disks = {
|
|
||||||
{"/dev/sda", "40C", "Bad"},
|
|
||||||
{"/dev/sdb", "40C", "Good"},
|
|
||||||
{"/dev/sdc", "40C", "Unknown"},
|
|
||||||
{"/dev/sdd", "40C", "Warning"}
|
|
||||||
};
|
|
||||||
populateGrid();
|
|
||||||
|
|
||||||
setLayout(mainLayout);
|
setLayout(mainLayout);
|
||||||
}
|
}
|
||||||
@@ -65,6 +58,11 @@ void GridView::resizeEvent(QResizeEvent *) {
|
|||||||
populateGrid();
|
populateGrid();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GridView::setDisks(const QVector<DiskItem> &newDisks) {
|
||||||
|
disks = newDisks;
|
||||||
|
populateGrid();
|
||||||
|
}
|
||||||
|
|
||||||
void GridView::populateGrid() {
|
void GridView::populateGrid() {
|
||||||
selectedButton = nullptr;
|
selectedButton = nullptr;
|
||||||
QLayoutItem *child;
|
QLayoutItem *child;
|
||||||
@@ -86,7 +84,7 @@ void GridView::populateGrid() {
|
|||||||
const DiskItem &disk = *it;
|
const DiskItem &disk = *it;
|
||||||
if (searchQuery.isEmpty() ||
|
if (searchQuery.isEmpty() ||
|
||||||
disk.name.contains(searchQuery, Qt::CaseInsensitive) ||
|
disk.name.contains(searchQuery, Qt::CaseInsensitive) ||
|
||||||
disk.category.contains(searchQuery, Qt::CaseInsensitive)) {
|
disk.temperature.contains(searchQuery, Qt::CaseInsensitive)) {
|
||||||
filteredDisks.append(disk);
|
filteredDisks.append(disk);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -103,7 +101,7 @@ void GridView::extracted(const QVector<DiskItem> &filteredDisks, int &cols, int
|
|||||||
diskLayout->setContentsMargins(0, 0, 0, 0);
|
diskLayout->setContentsMargins(0, 0, 0, 0);
|
||||||
|
|
||||||
QPushButton *iconButton = new QPushButton();
|
QPushButton *iconButton = new QPushButton();
|
||||||
QString iconPath = QString(":/icons/Disk_%1.svg").arg(disk.icon);
|
QString iconPath = QString(":/icons/Disk_%1.svg").arg(disk.health);
|
||||||
iconButton->setIcon(QIcon(iconPath));
|
iconButton->setIcon(QIcon(iconPath));
|
||||||
iconButton->setIconSize(QSize(48, 48));
|
iconButton->setIconSize(QSize(48, 48));
|
||||||
iconButton->setFixedSize(iconButtonSize, iconButtonSize);
|
iconButton->setFixedSize(iconButtonSize, iconButtonSize);
|
||||||
@@ -116,9 +114,9 @@ void GridView::extracted(const QVector<DiskItem> &filteredDisks, int &cols, int
|
|||||||
|
|
||||||
QLabel *nameLabel = new QLabel(disk.name);
|
QLabel *nameLabel = new QLabel(disk.name);
|
||||||
nameLabel->setAlignment(Qt::AlignCenter);
|
nameLabel->setAlignment(Qt::AlignCenter);
|
||||||
QLabel *categoryLabel = new QLabel(disk.category);
|
QLabel *temperatureLabel = new QLabel(disk.temperature);
|
||||||
categoryLabel->setAlignment(Qt::AlignCenter);
|
temperatureLabel->setAlignment(Qt::AlignCenter);
|
||||||
categoryLabel->setStyleSheet("font-size: 10px; color: gray;");
|
temperatureLabel->setStyleSheet("font-size: 10px; color: gray;");
|
||||||
|
|
||||||
connect(iconButton, &QPushButton::clicked, this, [this, iconButton]() {
|
connect(iconButton, &QPushButton::clicked, this, [this, iconButton]() {
|
||||||
if (selectedButton) {
|
if (selectedButton) {
|
||||||
@@ -133,7 +131,7 @@ void GridView::extracted(const QVector<DiskItem> &filteredDisks, int &cols, int
|
|||||||
|
|
||||||
diskLayout->addWidget(iconButton, 0, Qt::AlignCenter);
|
diskLayout->addWidget(iconButton, 0, Qt::AlignCenter);
|
||||||
diskLayout->addWidget(nameLabel, 0, Qt::AlignCenter);
|
diskLayout->addWidget(nameLabel, 0, Qt::AlignCenter);
|
||||||
diskLayout->addWidget(categoryLabel, 0, Qt::AlignCenter);
|
diskLayout->addWidget(temperatureLabel, 0, Qt::AlignCenter);
|
||||||
diskWidget->setLayout(diskLayout);
|
diskWidget->setLayout(diskLayout);
|
||||||
gridLayout->addWidget(diskWidget, row, col);
|
gridLayout->addWidget(diskWidget, row, col);
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,6 @@
|
|||||||
#include "statusdot.h"
|
#include "statusdot.h"
|
||||||
#include "custombutton.h"
|
#include "custombutton.h"
|
||||||
#include "jsonparser.h"
|
#include "jsonparser.h"
|
||||||
#include "gridview.h"
|
|
||||||
|
|
||||||
#include <QDesktopServices>
|
#include <QDesktopServices>
|
||||||
#include <QFileDialog>
|
#include <QFileDialog>
|
||||||
@@ -94,6 +93,8 @@ MainWindow::MainWindow(QWidget *parent)
|
|||||||
|
|
||||||
statusLabel = new QLabel;
|
statusLabel = new QLabel;
|
||||||
|
|
||||||
|
gridView = new GridView(nullptr);
|
||||||
|
|
||||||
ui->actionIgnore_C4_Reallocation_Event_Count->setChecked(settings.value("IgnoreC4", true).toBool());
|
ui->actionIgnore_C4_Reallocation_Event_Count->setChecked(settings.value("IgnoreC4", true).toBool());
|
||||||
ui->actionHEX->setChecked(settings.value("HEX", true).toBool());
|
ui->actionHEX->setChecked(settings.value("HEX", true).toBool());
|
||||||
ui->actionUse_Fahrenheit->setChecked(settings.value("Fahrenheit", false).toBool());
|
ui->actionUse_Fahrenheit->setChecked(settings.value("Fahrenheit", false).toBool());
|
||||||
@@ -174,6 +175,8 @@ void MainWindow::updateNavigationButtons(qsizetype currentIndex)
|
|||||||
|
|
||||||
void MainWindow::updateUI()
|
void MainWindow::updateUI()
|
||||||
{
|
{
|
||||||
|
QVector<DiskItem> diskItems;
|
||||||
|
|
||||||
bool firstTime = true;
|
bool firstTime = true;
|
||||||
globalIsNvme = false;
|
globalIsNvme = false;
|
||||||
|
|
||||||
@@ -326,6 +329,8 @@ void MainWindow::updateUI()
|
|||||||
|
|
||||||
qsizetype buttonIndex = buttonGroup->buttons().indexOf(button);
|
qsizetype buttonIndex = buttonGroup->buttons().indexOf(button);
|
||||||
|
|
||||||
|
diskItems.append({ deviceName, temperature, health });
|
||||||
|
|
||||||
auto updateWindow = [=]() {
|
auto updateWindow = [=]() {
|
||||||
if (isNvme) {
|
if (isNvme) {
|
||||||
populateWindow(localObj, health, nvmeSmartOrdered);
|
populateWindow(localObj, health, nvmeSmartOrdered);
|
||||||
@@ -368,6 +373,7 @@ void MainWindow::updateUI()
|
|||||||
}
|
}
|
||||||
|
|
||||||
updateNavigationButtons(buttonGroup->buttons().indexOf(buttonGroup->checkedButton()));
|
updateNavigationButtons(buttonGroup->buttons().indexOf(buttonGroup->checkedButton()));
|
||||||
|
gridView->setDisks(diskItems);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::populateWindow(const QJsonObject &localObj, const QString &health, const QVector<QPair<QString, int>>& nvmeLogOrdered)
|
void MainWindow::populateWindow(const QJsonObject &localObj, const QString &health, const QVector<QPair<QString, int>>& nvmeLogOrdered)
|
||||||
@@ -1207,6 +1213,16 @@ void MainWindow::transformWindow() {
|
|||||||
ui->centralwidget->setAutoFillBackground(true);
|
ui->centralwidget->setAutoFillBackground(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::mousePressEvent(QMouseEvent *event)
|
||||||
|
{
|
||||||
|
if (event->button() == Qt::ForwardButton && nextButton->isEnabled()) {
|
||||||
|
onNextButtonClicked();
|
||||||
|
} else if (event->button() == Qt::BackButton && prevButton->isEnabled()) {
|
||||||
|
onPrevButtonClicked();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Slots
|
||||||
void MainWindow::on_actionQuit_triggered()
|
void MainWindow::on_actionQuit_triggered()
|
||||||
{
|
{
|
||||||
qApp->quit();
|
qApp->quit();
|
||||||
@@ -1316,15 +1332,6 @@ void MainWindow::on_actionUse_GB_instead_of_TB_toggled(bool gigabytes)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::mousePressEvent(QMouseEvent *event)
|
|
||||||
{
|
|
||||||
if (event->button() == Qt::ForwardButton && nextButton->isEnabled()) {
|
|
||||||
onNextButtonClicked();
|
|
||||||
} else if (event->button() == Qt::BackButton && prevButton->isEnabled()) {
|
|
||||||
onPrevButtonClicked();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void MainWindow::on_actionClear_Settings_triggered()
|
void MainWindow::on_actionClear_Settings_triggered()
|
||||||
{
|
{
|
||||||
QMessageBox msgBox;
|
QMessageBox msgBox;
|
||||||
@@ -1412,11 +1419,8 @@ void MainWindow::on_actionASCII_View_triggered()
|
|||||||
asciiViewDialog->exec();
|
asciiViewDialog->exec();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void MainWindow::on_actionGrid_View_triggered()
|
void MainWindow::on_actionGrid_View_triggered()
|
||||||
{
|
{
|
||||||
auto *gridView = new GridView(nullptr);
|
|
||||||
gridView->setAttribute(Qt::WA_DeleteOnClose);
|
|
||||||
gridView->show();
|
gridView->show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user