diff --git a/src/widgets/Dashboard.cpp b/src/widgets/Dashboard.cpp index 34d6b6dc..3c16a6ee 100644 --- a/src/widgets/Dashboard.cpp +++ b/src/widgets/Dashboard.cpp @@ -80,6 +80,17 @@ void Dashboard::updateContents() QJsonObject hashes = Core()->cmdj("itj").object(); + // Delete hashesWidget if it isn't null to avoid duplicate components + if (hashesWidget) { + hashesWidget->deleteLater(); + } + + // Define dynamic components to hold the hashes + hashesWidget = new QWidget(); + QFormLayout *hashesLayout = new QFormLayout; + hashesWidget->setLayout(hashesLayout); + ui->hashesVerticalLayout->addWidget(hashesWidget); + // Add hashes as a pair of Hash Name : Hash Value. for (const QString& key : hashes.keys()) { // Create a bold QString with the hash name uppercased @@ -89,12 +100,13 @@ void Dashboard::updateContents() QLineEdit *hashLineEdit = new QLineEdit(); hashLineEdit->setReadOnly(true); hashLineEdit->setText(hashes.value(key).toString()); + // Set cursor position to begining to avoid long hashes (e.g sha256) // to look truncated at the begining hashLineEdit->setCursorPosition(0); // Add both controls to a form layout in a single row - ui->formLayout_2->addRow(new QLabel(label), hashLineEdit); + hashesLayout->addRow(new QLabel(label), hashLineEdit); } // Add the Entropy value of the file to the dashboard @@ -111,7 +123,7 @@ void Dashboard::updateContents() QLineEdit *entropyLineEdit = new QLineEdit(); entropyLineEdit->setReadOnly(true); entropyLineEdit->setText(entropy); - ui->formLayout_2->addRow(new QLabel(tr("Entropy:")), entropyLineEdit); + hashesLayout->addRow(new QLabel(tr("Entropy:")), entropyLineEdit); } QJsonObject analinfo = Core()->cmdj("aaij").object(); diff --git a/src/widgets/Dashboard.h b/src/widgets/Dashboard.h index 9a0826ef..264f4c82 100644 --- a/src/widgets/Dashboard.h +++ b/src/widgets/Dashboard.h @@ -1,6 +1,7 @@ #ifndef DASHBOARD_H #define DASHBOARD_H +#include #include #include "CutterDockWidget.h" @@ -32,6 +33,8 @@ private: std::unique_ptr ui; void setPlainText(QLineEdit *textBox, const QString &text); void setBool(QLineEdit *textBox, const QJsonObject &jsonObject, const QString &key); + + QWidget *hashesWidget = nullptr; }; #endif // DASHBOARD_H diff --git a/src/widgets/Dashboard.ui b/src/widgets/Dashboard.ui index b599e782..521da7f2 100644 --- a/src/widgets/Dashboard.ui +++ b/src/widgets/Dashboard.ui @@ -1068,17 +1068,7 @@ 5 - - - QFormLayout::ExpandingFieldsGrow - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter - - - 3 - - +