2018-06-06 11:05:20 +00:00
|
|
|
#include "StackWidget.h"
|
|
|
|
#include "ui_StackWidget.h"
|
2018-10-17 07:55:53 +00:00
|
|
|
#include "common/JsonModel.h"
|
|
|
|
#include "common/Helpers.h"
|
2018-07-24 23:15:38 +00:00
|
|
|
#include "dialogs/EditInstructionDialog.h"
|
2018-06-06 11:05:20 +00:00
|
|
|
|
|
|
|
#include "MainWindow.h"
|
|
|
|
#include "QHeaderView"
|
2018-07-24 23:15:38 +00:00
|
|
|
#include "QMenu"
|
2018-06-06 11:05:20 +00:00
|
|
|
|
|
|
|
StackWidget::StackWidget(MainWindow *main, QAction *action) :
|
|
|
|
CutterDockWidget(main, action),
|
|
|
|
ui(new Ui::StackWidget)
|
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
|
|
|
|
2018-11-05 21:51:27 +00:00
|
|
|
// Setup stack model
|
2018-06-06 11:05:20 +00:00
|
|
|
modelStack->setHorizontalHeaderItem(0, new QStandardItem(tr("Offset")));
|
|
|
|
modelStack->setHorizontalHeaderItem(1, new QStandardItem(tr("Value")));
|
|
|
|
modelStack->setHorizontalHeaderItem(2, new QStandardItem(tr("Reference")));
|
2018-07-18 10:15:10 +00:00
|
|
|
viewStack->setFont(Config()->getFont());
|
2018-06-06 11:05:20 +00:00
|
|
|
viewStack->setModel(modelStack);
|
|
|
|
viewStack->verticalHeader()->hide();
|
|
|
|
viewStack->setSortingEnabled(true);
|
2018-07-23 23:14:54 +00:00
|
|
|
viewStack->setHorizontalScrollMode(QAbstractItemView::ScrollPerPixel);
|
2018-06-06 11:05:20 +00:00
|
|
|
ui->verticalLayout->addWidget(viewStack);
|
|
|
|
|
2018-07-24 23:15:38 +00:00
|
|
|
seekAction = new QAction(tr("Seek to this offset"));
|
|
|
|
editAction = new QAction(tr("Edit stack value..."));
|
|
|
|
viewStack->setContextMenuPolicy(Qt::CustomContextMenu);
|
|
|
|
|
2018-06-06 11:05:20 +00:00
|
|
|
connect(Core(), &CutterCore::refreshAll, this, &StackWidget::updateContents);
|
|
|
|
connect(Core(), &CutterCore::seekChanged, this, &StackWidget::updateContents);
|
2018-07-24 23:15:38 +00:00
|
|
|
connect(Core(), &CutterCore::stackChanged, this, &StackWidget::updateContents);
|
2018-07-18 10:15:10 +00:00
|
|
|
connect(Config(), &Configuration::fontsUpdated, this, &StackWidget::fontsUpdatedSlot);
|
2018-07-24 23:15:38 +00:00
|
|
|
connect(viewStack, SIGNAL(doubleClicked(const QModelIndex &)), this,
|
|
|
|
SLOT(onDoubleClicked(const QModelIndex &)));
|
|
|
|
connect(viewStack, SIGNAL(customContextMenuRequested(QPoint)), SLOT(customMenuRequested(QPoint)));
|
|
|
|
connect(seekAction, &QAction::triggered, this, &StackWidget::seekOffset);
|
|
|
|
connect(editAction, &QAction::triggered, this, &StackWidget::editStack);
|
2018-06-06 11:05:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
StackWidget::~StackWidget() {}
|
|
|
|
|
|
|
|
void StackWidget::updateContents()
|
|
|
|
{
|
|
|
|
setStackGrid();
|
|
|
|
}
|
|
|
|
|
|
|
|
void StackWidget::setStackGrid()
|
|
|
|
{
|
|
|
|
QJsonArray stackValues = Core()->getStack().array();
|
|
|
|
int i = 0;
|
2018-11-26 22:34:34 +00:00
|
|
|
for (const QJsonValue &value : stackValues) {
|
2018-06-06 11:05:20 +00:00
|
|
|
QJsonObject stackItem = value.toObject();
|
|
|
|
QString addr = RAddressString(stackItem["addr"].toVariant().toULongLong());
|
|
|
|
QString valueStack = RAddressString(stackItem["value"].toVariant().toULongLong());
|
|
|
|
QStandardItem *rowOffset = new QStandardItem(addr);
|
2018-07-24 23:15:38 +00:00
|
|
|
rowOffset->setEditable(false);
|
2018-06-06 11:05:20 +00:00
|
|
|
QStandardItem *rowValue = new QStandardItem(valueStack);
|
|
|
|
modelStack->setItem(i, 0, rowOffset);
|
|
|
|
modelStack->setItem(i, 1, rowValue);
|
|
|
|
QJsonValue refObject = stackItem["ref"];
|
|
|
|
if (!refObject.isUndefined()) { // check that the key exists
|
|
|
|
QString ref = refObject.toString();
|
2018-07-24 23:15:38 +00:00
|
|
|
if (ref.contains("ascii") && ref.count("-->") == 1) {
|
|
|
|
ref = Core()->cmd("psz @ [" + addr + "]");
|
|
|
|
}
|
2018-06-06 11:05:20 +00:00
|
|
|
QStandardItem *rowRef = new QStandardItem(ref);
|
|
|
|
modelStack->setItem(i, 2, rowRef);
|
2018-07-24 23:15:38 +00:00
|
|
|
if (refObject.toString().contains("ascii") && refObject.toString().count("-->") == 1) {
|
2018-09-30 20:00:53 +00:00
|
|
|
modelStack->setData(modelStack->index(i, 2, QModelIndex()), QVariant(QColor(243, 156, 17)),
|
|
|
|
Qt::ForegroundRole); // orange
|
2018-07-24 23:15:38 +00:00
|
|
|
} else if (ref.contains("program R X") && ref.count("-->") == 0) {
|
2018-09-30 20:00:53 +00:00
|
|
|
modelStack->setData(modelStack->index(i, 2, QModelIndex()), QVariant(QColor(Qt::red)),
|
|
|
|
Qt::ForegroundRole);
|
2018-07-24 23:15:38 +00:00
|
|
|
} else if (ref.contains("stack") && ref.count("-->") == 0) {
|
2018-09-30 20:00:53 +00:00
|
|
|
modelStack->setData(modelStack->index(i, 2, QModelIndex()), QVariant(QColor(Qt::cyan)),
|
|
|
|
Qt::ForegroundRole);
|
2018-07-24 23:15:38 +00:00
|
|
|
} else if (ref.contains("library") && ref.count("-->") == 0) {
|
2018-09-30 20:00:53 +00:00
|
|
|
modelStack->setData(modelStack->index(i, 2, QModelIndex()), QVariant(QColor(Qt::green)),
|
|
|
|
Qt::ForegroundRole);
|
2018-07-24 23:15:38 +00:00
|
|
|
}
|
2018-06-06 11:05:20 +00:00
|
|
|
}
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
viewStack->setModel(modelStack);
|
|
|
|
viewStack->resizeColumnsToContents();;
|
|
|
|
}
|
2018-07-18 10:15:10 +00:00
|
|
|
|
|
|
|
void StackWidget::fontsUpdatedSlot()
|
|
|
|
{
|
|
|
|
viewStack->setFont(Config()->getFont());
|
2018-07-24 23:15:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void StackWidget::onDoubleClicked(const QModelIndex &index)
|
|
|
|
{
|
|
|
|
if (!index.isValid())
|
|
|
|
return;
|
2018-11-05 21:51:27 +00:00
|
|
|
// Check if we are clicking on the offset or value columns and seek if it is the case
|
2018-07-24 23:15:38 +00:00
|
|
|
if (index.column() <= 1) {
|
|
|
|
QString item = index.data().toString();
|
|
|
|
Core()->seek(item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void StackWidget::customMenuRequested(QPoint pos)
|
|
|
|
{
|
|
|
|
QMenu *menu = new QMenu(this);
|
|
|
|
menu->addAction(seekAction);
|
|
|
|
menu->addAction(editAction);
|
|
|
|
menu->popup(viewStack->viewport()->mapToGlobal(pos));
|
|
|
|
}
|
|
|
|
|
|
|
|
void StackWidget::seekOffset()
|
|
|
|
{
|
|
|
|
QString offset = viewStack->selectionModel()->currentIndex().data().toString();
|
|
|
|
Core()->seek(offset);
|
|
|
|
}
|
|
|
|
|
|
|
|
void StackWidget::editStack()
|
|
|
|
{
|
|
|
|
bool ok;
|
|
|
|
int row = viewStack->selectionModel()->currentIndex().row();
|
|
|
|
QString offset = viewStack->selectionModel()->currentIndex().sibling(row, 0).data().toString();
|
2018-10-23 05:06:26 +00:00
|
|
|
EditInstructionDialog *e = new EditInstructionDialog(this, EDIT_NONE);
|
2018-07-24 23:15:38 +00:00
|
|
|
e->setWindowTitle(tr("Edit stack at %1").arg(offset));
|
|
|
|
|
|
|
|
QString oldBytes = viewStack->selectionModel()->currentIndex().sibling(row, 1).data().toString();
|
|
|
|
e->setInstruction(oldBytes);
|
|
|
|
|
|
|
|
if (e->exec()) {
|
|
|
|
QString bytes = e->getInstruction();
|
|
|
|
if (bytes != oldBytes) {
|
2018-11-05 21:51:27 +00:00
|
|
|
Core()->editBytesEndian(offset.toULongLong(&ok, 16), bytes);
|
2018-07-24 23:15:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|