New TaskProgressIndicator widget for the memory inspection pane

This commit is contained in:
Nav
2023-03-15 20:41:54 +00:00
parent 5b04c5397a
commit 70e2a39eba
8 changed files with 243 additions and 11 deletions

View File

@@ -6,7 +6,6 @@
#include "src/Insight/UserInterfaces/InsightWindow/Widgets/ErrorDialogue/ErrorDialogue.hpp"
#include "src/Insight/InsightWorker/Tasks/RetrieveMemorySnapshots.hpp"
#include "src/Insight/InsightWorker/Tasks/CaptureMemorySnapshot.hpp"
#include "src/Insight/InsightWorker/InsightWorker.hpp"
#include "src/Services/PathService.hpp"
@@ -161,6 +160,8 @@ namespace Bloom::Widgets
}
);
emit this->captureTaskCreated(captureTask);
InsightWorker::queueTask(captureTask);
}

View File

@@ -14,6 +14,8 @@
#include "src/Targets/TargetMemory.hpp"
#include "src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/MemorySnapshot.hpp"
#include "src/Insight/InsightWorker/Tasks/CaptureMemorySnapshot.hpp"
#include "./CreateSnapshotWindow/CreateSnapshotWindow.hpp"
#include "MemorySnapshotItem.hpp"
@@ -35,6 +37,9 @@ namespace Bloom::Widgets
PanelWidget* parent = nullptr
);
signals:
void captureTaskCreated(const QSharedPointer<CaptureMemorySnapshot>& task);
protected:
void resizeEvent(QResizeEvent* event) override;
void showEvent(QShowEvent* event) override;

View File

@@ -69,16 +69,13 @@ namespace Bloom::Widgets
this->container->setStyleSheet(stylesheetFile.readAll());
this->container->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
this->subContainerLayout = this->container->findChild<QHBoxLayout*>("container-sub-layout");
this->titleBar = this->container->findChild<QWidget*>("title-bar");
this->titleBar->layout()->setContentsMargins(7, 0, 7, 0);
auto* titleLabel = this->titleBar->findChild<Label*>("title");
titleLabel->setText(memoryName);
this->bottomBar = this->container->findChild<QWidget*>("bottom-bar");
this->bottomBarLayout = this->bottomBar->findChild<QHBoxLayout*>();
// Quick sanity check to ensure the validity of persisted settings.
this->sanitiseSettings();
this->subContainerLayout = this->container->findChild<QHBoxLayout*>("container-sub-layout");
this->manageMemoryRegionsButton = this->container->findChild<SvgToolButton*>("manage-memory-regions-btn");
this->manageMemorySnapshotsButton = this->container->findChild<QToolButton*>("manage-memory-snapshots-btn");
@@ -91,10 +88,17 @@ namespace Bloom::Widgets
this->manageMemorySnapshotsButton->layout()->setContentsMargins(0, 0, 0, 0);
this->staleDataLabelContainer = this->container->findChild<QWidget*>("stale-data-label");
this->titleBar->layout()->setContentsMargins(7, 0, 7, 0);
auto* titleLabel = this->titleBar->findChild<Label*>("title");
titleLabel->setText(memoryName);
auto* memoryCapacityLabel = this->container->findChild<Label*>("memory-capacity-label");
memoryCapacityLabel->setText(QLocale(QLocale::English).toString(this->targetMemoryDescriptor.size()) + " Bytes");
this->staleDataLabelContainer = this->container->findChild<QWidget*>("stale-data-label");
// Quick sanity check to ensure the validity of persisted settings.
this->sanitiseSettings();
this->hexViewerWidget = new HexViewerWidget(
this->targetMemoryDescriptor,
@@ -128,6 +132,9 @@ namespace Bloom::Widgets
this->setRefreshOnTargetStopEnabled(this->settings.refreshOnTargetStop);
this->setRefreshOnActivationEnabled(this->settings.refreshOnActivation);
this->bottomBarHorizontalSpacer = new QSpacerItem(1, 1, QSizePolicy::Expanding, QSizePolicy::Expanding);
this->bottomBarLayout->insertItem(5, this->bottomBarHorizontalSpacer);
QObject::connect(
this,
&PaneWidget::paneActivated,
@@ -188,6 +195,13 @@ namespace Bloom::Widgets
}
);
QObject::connect(
this->snapshotManager,
&SnapshotManager::captureTaskCreated,
this,
&TargetMemoryInspectionPane::onCaptureMemoryTaskCreated
);
QObject::connect(
this->refreshButton,
&QToolButton::clicked,
@@ -397,6 +411,7 @@ namespace Bloom::Widgets
);
}
this->setTaskProgressIndicator(readMemoryTask);
InsightWorker::queueTask(readMemoryTask);
}
@@ -612,6 +627,36 @@ namespace Bloom::Widgets
}
}
void TargetMemoryInspectionPane::onCaptureMemoryTaskCreated(const QSharedPointer<CaptureMemorySnapshot>& task) {
this->setTaskProgressIndicator(task);
}
void TargetMemoryInspectionPane::setTaskProgressIndicator(const QSharedPointer<InsightWorkerTask>& task) {
if (this->taskProgressIndicator != nullptr) {
this->bottomBarLayout->removeWidget(this->taskProgressIndicator);
this->taskProgressIndicator->deleteLater();
this->taskProgressIndicator = nullptr;
}
this->taskProgressIndicator = new TaskProgressIndicator(task, this);
QObject::connect(
this->taskProgressIndicator,
&TaskProgressIndicator::taskComplete,
this,
[this] {
this->bottomBarLayout->removeWidget(this->taskProgressIndicator);
this->taskProgressIndicator->deleteLater();
this->taskProgressIndicator = nullptr;
this->bottomBarLayout->insertItem(5, this->bottomBarHorizontalSpacer);
}
);
this->bottomBarLayout->removeItem(this->bottomBarHorizontalSpacer);
this->bottomBarLayout->insertWidget(5, this->taskProgressIndicator);
}
void TargetMemoryInspectionPane::setStaleData(bool staleData) {
this->staleData = staleData;
this->staleDataLabelContainer->setVisible(this->staleData);

View File

@@ -6,6 +6,7 @@
#include <QResizeEvent>
#include <QHBoxLayout>
#include <QToolButton>
#include <QSpacerItem>
#include <QKeyEvent>
#include "src/Insight/UserInterfaces/InsightWindow/Widgets/PaneWidget.hpp"
@@ -16,6 +17,9 @@
#include "src/Insight/UserInterfaces/InsightWindow/Widgets/PanelWidget.hpp"
#include "src/Insight/UserInterfaces/InsightWindow/Widgets/SvgToolButton.hpp"
#include "src/Insight/UserInterfaces/InsightWindow/Widgets/Label.hpp"
#include "src/Insight/UserInterfaces/InsightWindow/Widgets/TaskProgressIndicator/TaskProgressIndicator.hpp"
#include "src/Insight/InsightWorker/Tasks/CaptureMemorySnapshot.hpp"
#include "HexViewerWidget/HexViewerWidget.hpp"
#include "MemoryRegionManager/MemoryRegionManagerWindow.hpp"
@@ -59,6 +63,9 @@ namespace Bloom::Widgets
QHBoxLayout* subContainerLayout = nullptr;
QWidget* titleBar = nullptr;
QWidget* bottomBar = nullptr;
QHBoxLayout* bottomBarLayout = nullptr;
SvgToolButton* manageMemoryRegionsButton = nullptr;
QToolButton* manageMemorySnapshotsButton = nullptr;
@@ -73,6 +80,8 @@ namespace Bloom::Widgets
PanelWidget* rightPanel = nullptr;
SnapshotManager* snapshotManager = nullptr;
TaskProgressIndicator* taskProgressIndicator = nullptr;
QSpacerItem* bottomBarHorizontalSpacer = nullptr;
QWidget* staleDataLabelContainer = nullptr;
Targets::TargetState targetState = Targets::TargetState::UNKNOWN;
@@ -96,6 +105,8 @@ namespace Bloom::Widgets
Bloom::Targets::TargetMemoryType memoryType,
Targets::TargetMemoryAddressRange addressRange
);
void onCaptureMemoryTaskCreated(const QSharedPointer<CaptureMemorySnapshot>& task);
void setTaskProgressIndicator(const QSharedPointer<InsightWorkerTask>& task);
void setStaleData(bool staleData);
};
}

View File

@@ -366,6 +366,9 @@
<property name="toolTip">
<string>Memory Capacity</string>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed"/>
</property>
</widget>
</item>
<item>
@@ -385,8 +388,25 @@
</item>
<item>
<spacer name="horizontal-spacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
<property name="sizeHint">
<size>
<width>5</width>
</size>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
</spacer>
</item>
<item>
<spacer name="horizontal-spacer">
<property name="sizeHint">
<size>
<width>15</width>
</size>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
</spacer>
</item>
@@ -395,6 +415,9 @@
<property name="visible">
<bool>false</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed"/>
</property>
<layout class="QHBoxLayout">
<property name="spacing">
<number>1</number>

View File

@@ -0,0 +1,111 @@
#include "TaskProgressIndicator.hpp"
#include <QPainter>
#include <QColor>
#include <algorithm>
#include <QTimer>
namespace Bloom::Widgets
{
TaskProgressIndicator::TaskProgressIndicator(
const QSharedPointer<InsightWorkerTask>& task,
QWidget* parent
)
: QWidget(parent)
, task(task)
{
this->setObjectName("task-progress-indicator");
this->setFixedHeight(26);
this->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed);
QObject::connect(
this->task.get(),
&InsightWorkerTask::progressUpdate,
this,
&TaskProgressIndicator::onTaskProgressUpdate
);
QObject::connect(
this->task.get(),
&InsightWorkerTask::failed,
this,
&TaskProgressIndicator::onTaskFailed
);
QObject::connect(
this->task.get(),
&InsightWorkerTask::finished,
this,
&TaskProgressIndicator::onTaskFinished
);
}
void TaskProgressIndicator::paintEvent(QPaintEvent* event) {
auto painter = QPainter(this);
const auto size = this->size();
static constexpr auto backgroundBarColor = QColor(0x8E, 0x8B, 0x83, 40);
static constexpr auto barColor = QColor(0x8E, 0x8B, 0x83, 90);
static constexpr auto fontColor = QColor(0x99, 0x9a, 0x9d);
static auto font = QFont("'Ubuntu', sans-serif", 9);
painter.setFont(font);
painter.setPen(fontColor);
static constexpr auto barHeight = 3;
const auto barYPosition = size.height() - barHeight - 3;
const auto percentage = std::max(this->taskProgressPercentage, 2);
painter.drawText(
0,
barYPosition - 5,
this->task->brief() + QString(this->taskFailed ? " - Failed" : (percentage == 100 ? " - Completed" : ""))
);
painter.setPen(Qt::PenStyle::NoPen);
painter.setBrush(backgroundBarColor);
painter.drawRect(
0,
barYPosition,
size.width(),
barHeight
);
painter.setBrush(barColor);
painter.drawRect(
0,
barYPosition,
static_cast<int>(static_cast<float>(size.width()) * (static_cast<float>(percentage) / 100)),
barHeight
);
}
void TaskProgressIndicator::onTaskProgressUpdate(int taskProgressPercentage) {
this->taskProgressPercentage = taskProgressPercentage;
this->update();
}
void TaskProgressIndicator::onTaskFailed() {
this->taskFailed = true;
this->update();
}
void TaskProgressIndicator::onTaskFinished() {
this->taskProgressPercentage = 100;
this->update();
auto* finishedSignalTimer = new QTimer();
finishedSignalTimer->setSingleShot(true);
finishedSignalTimer->setInterval(2500);
QObject::connect(finishedSignalTimer, &QTimer::timeout, this, [this] {
emit this->taskComplete();
});
finishedSignalTimer->start();
}
}

View File

@@ -0,0 +1,35 @@
#pragma once
#include <QWidget>
#include <QSharedPointer>
#include <cstdint>
#include <unordered_map>
#include <QEvent>
#include "src/Insight/InsightWorker/Tasks/InsightWorkerTask.hpp"
namespace Bloom::Widgets
{
class TaskProgressIndicator: public QWidget
{
Q_OBJECT
public:
TaskProgressIndicator(const QSharedPointer<InsightWorkerTask>& task, QWidget* parent);
signals:
void taskComplete();
protected:
void paintEvent(QPaintEvent* event) override;
private:
QSharedPointer<InsightWorkerTask> task;
int taskProgressPercentage = 0;
bool taskFailed = false;
void onTaskProgressUpdate(int progressPercentage);
void onTaskFailed();
void onTaskFinished();
};
}