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 <QScrollArea>
|
||||
|
||||
#include "diskitem.h"
|
||||
|
||||
class GridView : public QWidget {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit GridView(QWidget *parent = nullptr);
|
||||
void setDisks(const QVector<DiskItem> &newDisks);
|
||||
|
||||
protected:
|
||||
void resizeEvent(QResizeEvent *) override;
|
||||
|
||||
private:
|
||||
struct DiskItem {
|
||||
QString name;
|
||||
QString category;
|
||||
QString icon;
|
||||
};
|
||||
signals:
|
||||
void diskSelected(const QString &diskName);
|
||||
|
||||
private:
|
||||
QString searchQuery;
|
||||
QScrollArea *scrollArea;
|
||||
QWidget *gridContainer;
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
#include <cmath>
|
||||
|
||||
#include "utils.h"
|
||||
#include "gridview.h"
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
namespace Ui {
|
||||
@@ -80,6 +81,7 @@ private:
|
||||
QString globalHealth;
|
||||
bool globalIsNvme;
|
||||
QVector<QPair<QString, int>> globalNvmeSmartOrdered;
|
||||
GridView *gridView;
|
||||
|
||||
void onNextButtonClicked();
|
||||
void onPrevButtonClicked();
|
||||
|
||||
@@ -50,13 +50,6 @@ GridView::GridView(QWidget *parent) : QWidget(parent) {
|
||||
gridLayout->setAlignment(Qt::AlignTop | Qt::AlignHCenter);
|
||||
gridLayout->setSpacing(gridLayoutSpacing);
|
||||
gridFrame->setLayout(gridLayout);
|
||||
disks = {
|
||||
{"/dev/sda", "40C", "Bad"},
|
||||
{"/dev/sdb", "40C", "Good"},
|
||||
{"/dev/sdc", "40C", "Unknown"},
|
||||
{"/dev/sdd", "40C", "Warning"}
|
||||
};
|
||||
populateGrid();
|
||||
|
||||
setLayout(mainLayout);
|
||||
}
|
||||
@@ -65,6 +58,11 @@ void GridView::resizeEvent(QResizeEvent *) {
|
||||
populateGrid();
|
||||
}
|
||||
|
||||
void GridView::setDisks(const QVector<DiskItem> &newDisks) {
|
||||
disks = newDisks;
|
||||
populateGrid();
|
||||
}
|
||||
|
||||
void GridView::populateGrid() {
|
||||
selectedButton = nullptr;
|
||||
QLayoutItem *child;
|
||||
@@ -86,7 +84,7 @@ void GridView::populateGrid() {
|
||||
const DiskItem &disk = *it;
|
||||
if (searchQuery.isEmpty() ||
|
||||
disk.name.contains(searchQuery, Qt::CaseInsensitive) ||
|
||||
disk.category.contains(searchQuery, Qt::CaseInsensitive)) {
|
||||
disk.temperature.contains(searchQuery, Qt::CaseInsensitive)) {
|
||||
filteredDisks.append(disk);
|
||||
}
|
||||
}
|
||||
@@ -103,7 +101,7 @@ void GridView::extracted(const QVector<DiskItem> &filteredDisks, int &cols, int
|
||||
diskLayout->setContentsMargins(0, 0, 0, 0);
|
||||
|
||||
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->setIconSize(QSize(48, 48));
|
||||
iconButton->setFixedSize(iconButtonSize, iconButtonSize);
|
||||
@@ -116,9 +114,9 @@ void GridView::extracted(const QVector<DiskItem> &filteredDisks, int &cols, int
|
||||
|
||||
QLabel *nameLabel = new QLabel(disk.name);
|
||||
nameLabel->setAlignment(Qt::AlignCenter);
|
||||
QLabel *categoryLabel = new QLabel(disk.category);
|
||||
categoryLabel->setAlignment(Qt::AlignCenter);
|
||||
categoryLabel->setStyleSheet("font-size: 10px; color: gray;");
|
||||
QLabel *temperatureLabel = new QLabel(disk.temperature);
|
||||
temperatureLabel->setAlignment(Qt::AlignCenter);
|
||||
temperatureLabel->setStyleSheet("font-size: 10px; color: gray;");
|
||||
|
||||
connect(iconButton, &QPushButton::clicked, this, [this, iconButton]() {
|
||||
if (selectedButton) {
|
||||
@@ -133,7 +131,7 @@ void GridView::extracted(const QVector<DiskItem> &filteredDisks, int &cols, int
|
||||
|
||||
diskLayout->addWidget(iconButton, 0, Qt::AlignCenter);
|
||||
diskLayout->addWidget(nameLabel, 0, Qt::AlignCenter);
|
||||
diskLayout->addWidget(categoryLabel, 0, Qt::AlignCenter);
|
||||
diskLayout->addWidget(temperatureLabel, 0, Qt::AlignCenter);
|
||||
diskWidget->setLayout(diskLayout);
|
||||
gridLayout->addWidget(diskWidget, row, col);
|
||||
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
#include "statusdot.h"
|
||||
#include "custombutton.h"
|
||||
#include "jsonparser.h"
|
||||
#include "gridview.h"
|
||||
|
||||
#include <QDesktopServices>
|
||||
#include <QFileDialog>
|
||||
@@ -94,6 +93,8 @@ MainWindow::MainWindow(QWidget *parent)
|
||||
|
||||
statusLabel = new QLabel;
|
||||
|
||||
gridView = new GridView(nullptr);
|
||||
|
||||
ui->actionIgnore_C4_Reallocation_Event_Count->setChecked(settings.value("IgnoreC4", true).toBool());
|
||||
ui->actionHEX->setChecked(settings.value("HEX", true).toBool());
|
||||
ui->actionUse_Fahrenheit->setChecked(settings.value("Fahrenheit", false).toBool());
|
||||
@@ -174,6 +175,8 @@ void MainWindow::updateNavigationButtons(qsizetype currentIndex)
|
||||
|
||||
void MainWindow::updateUI()
|
||||
{
|
||||
QVector<DiskItem> diskItems;
|
||||
|
||||
bool firstTime = true;
|
||||
globalIsNvme = false;
|
||||
|
||||
@@ -326,6 +329,8 @@ void MainWindow::updateUI()
|
||||
|
||||
qsizetype buttonIndex = buttonGroup->buttons().indexOf(button);
|
||||
|
||||
diskItems.append({ deviceName, temperature, health });
|
||||
|
||||
auto updateWindow = [=]() {
|
||||
if (isNvme) {
|
||||
populateWindow(localObj, health, nvmeSmartOrdered);
|
||||
@@ -368,6 +373,7 @@ void MainWindow::updateUI()
|
||||
}
|
||||
|
||||
updateNavigationButtons(buttonGroup->buttons().indexOf(buttonGroup->checkedButton()));
|
||||
gridView->setDisks(diskItems);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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()
|
||||
{
|
||||
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()
|
||||
{
|
||||
QMessageBox msgBox;
|
||||
@@ -1412,11 +1419,8 @@ void MainWindow::on_actionASCII_View_triggered()
|
||||
asciiViewDialog->exec();
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::on_actionGrid_View_triggered()
|
||||
{
|
||||
auto *gridView = new GridView(nullptr);
|
||||
gridView->setAttribute(Qt::WA_DeleteOnClose);
|
||||
gridView->show();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user