Skip to content

Commit

Permalink
no need for setLayout when you set the widged as parent, little cle…
Browse files Browse the repository at this point in the history
…anup with toolbar slots
  • Loading branch information
Mr-Auto committed Apr 29, 2024
1 parent 9e1b259 commit 6619242
Show file tree
Hide file tree
Showing 22 changed files with 168 additions and 181 deletions.
5 changes: 0 additions & 5 deletions include/Views/ViewEntities.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include <QLineEdit>
#include <QPushButton>
#include <QString>
#include <QVBoxLayout>
#include <array>

namespace S2Plugin
Expand Down Expand Up @@ -49,7 +48,6 @@ namespace S2Plugin
const MASK mask;
const QString name;
};
QVBoxLayout* mMainLayout;
TreeViewMemoryFields* mMainTreeView;

QCheckBox* mCheckboxLayer0;
Expand Down Expand Up @@ -78,8 +76,5 @@ namespace S2Plugin
uintptr_t mLayer0Offset = 0;
uintptr_t mLayer1Offset = 0;
uintptr_t mLayerMapOffset = 0;

void initializeTreeView();
void initializeRefreshAndFilter();
};
} // namespace S2Plugin
23 changes: 13 additions & 10 deletions include/Views/ViewToolbar.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,34 +19,37 @@ namespace S2Plugin
Q_OBJECT
public:
ViewToolbar(QMdiArea* mdiArea, QWidget* parent = nullptr);
void showEntity(uintptr_t offset);
void showEntity(uintptr_t address);
void showState(uintptr_t statePtr);
void resetSpelunky2Data();
void showStdVector(uintptr_t address, const std::string& typeName);
void showStdMap(uintptr_t address, const std::string& keytypeName, const std::string& valuetypeName);
void showVirtualFunctions(uintptr_t address, const std::string& typeName);
void showJournalPage(uintptr_t address, const std::string& pageType);
void showLevelGen(uintptr_t address);

public slots:
ViewEntityDB* showEntityDB();
ViewParticleDB* showParticleDB();
ViewTextureDB* showTextureDB();
void showStringsTable();
ViewCharacterDB* showCharacterDB();

void showMainThreadState();
void showGameManager();
void showLevelGen();
void showMainThreadLevelGen();
void showEntities();
ViewVirtualTable* showVirtualTableLookup();
void showStringsTable();
ViewCharacterDB* showCharacterDB();
void showSaveGame();
void showLogger();
void showVirtualFunctions(size_t offset, const std::string& typeName);
void showOnline();
void showStdVector(size_t offset, const std::string& typeName);
void showStdMap(size_t offset, const std::string& keytypeName, const std::string& valuetypeName);
void showJournalPage(size_t offset, const std::string& pageType);
void showThreads();

private slots:
void clearLabels();
void reloadConfig();

private:
QMdiArea* mMDIArea;
QVBoxLayout* mMainLayout;
friend struct QtPluginStruct;
};
} // namespace S2Plugin
1 change: 0 additions & 1 deletion src/QtHelpers/DialogEditSimpleValue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ S2Plugin::DialogEditSimpleValue::DialogEditSimpleValue(const QString& fieldName,
layout->addStretch();
layout->addLayout(buttonLayout);

setLayout(layout);
mLineEditDecValue->setFocus();
mLineEditDecValue->selectAll();
}
Expand Down
2 changes: 0 additions & 2 deletions src/QtHelpers/DialogEditState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,6 @@ S2Plugin::DialogEditState::DialogEditState(const QString& fieldName, const std::
layout->addLayout(gridLayout);
layout->addStretch();
layout->addLayout(buttonLayout);

setLayout(layout);
}

QSize S2Plugin::DialogEditState::minimumSizeHint() const
Expand Down
2 changes: 1 addition & 1 deletion src/QtHelpers/TreeViewMemoryFields.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2131,7 +2131,7 @@ void S2Plugin::TreeViewMemoryFields::cellClicked(const QModelIndex& index)
auto rawValue = clickedItem->data(gsRoleMemoryAddress).toULongLong();
if (rawValue != 0)
{
getToolbar()->showLevelGen(); // TODO: use pointer
getToolbar()->showLevelGen(rawValue);
}
break;
}
Expand Down
3 changes: 1 addition & 2 deletions src/QtHelpers/WidgetDatabaseView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,12 @@ namespace std
S2Plugin::WidgetDatabaseView::WidgetDatabaseView(MemoryFieldType type, QWidget* parent) : QWidget(parent)
{
setWindowIcon(getCavemanIcon());
auto mainLayout = new QVBoxLayout();
auto mainLayout = new QVBoxLayout(this);
mainLayout->setMargin(5);

mMainTabWidget = new QTabWidget();
mMainTabWidget->setDocumentMode(false);
mainLayout->addWidget(mMainTabWidget);
setLayout(mainLayout);

auto tabLookup = new QWidget();
auto tabCompare = new QWidget();
Expand Down
12 changes: 11 additions & 1 deletion src/QtPlugin.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "QtPlugin.h"
#include "Spelunky2.h"
#include "Views/ViewToolbar.h"
#include "Views/ViewVirtualTable.h"
#include "pluginmain.h"
Expand Down Expand Up @@ -87,9 +88,18 @@ void QtPlugin::ShowTab()
GuiShowQWidgetTab(gsSpelunky2MainWindow);
}

struct S2Plugin::QtPluginStruct
{
void static inline resetSpelunky2Data()
{
gsViewToolbar->mMDIArea->closeAllSubWindows();
S2Plugin::Spelunky2::reset();
};
};

void QtPlugin::Detach()
{
gsViewToolbar->resetSpelunky2Data();
S2Plugin::QtPluginStruct::resetSpelunky2Data();
}

void QtPlugin::MenuPrepare([[maybe_unused]] int hMenu) {}
Expand Down
106 changes: 50 additions & 56 deletions src/Views/ViewEntities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,83 +10,77 @@
#include <QHeaderView>
#include <QLabel>
#include <QTimer>
#include <QVBoxLayout>

S2Plugin::ViewEntities::ViewEntities(QWidget* parent) : QWidget(parent)
{
mMainLayout = new QVBoxLayout(this);
auto mainLayout = new QVBoxLayout(this);

auto config = Configuration::get();
mLayer0Offset = config->offsetForField(MemoryFieldType::State, "layer0", Spelunky2::get()->get_StatePtr());
mLayer1Offset = config->offsetForField(MemoryFieldType::State, "layer1", Spelunky2::get()->get_StatePtr());
mLayerMapOffset = config->offsetForField(config->typeFieldsOfDefaultStruct("LayerPointer"), "entities_by_mask");

initializeRefreshAndFilter();
initializeTreeView();
setWindowIcon(getCavemanIcon());

mMainLayout->setMargin(5);
setLayout(mMainLayout);
// initializeRefreshAndFilter
{
auto filterLayout = new QGridLayout();

setWindowTitle("Entities");
mMainTreeView->setVisible(true);
auto refreshButton = new QPushButton("Refresh", this);
QObject::connect(refreshButton, &QPushButton::clicked, this, &ViewEntities::refreshEntities);
filterLayout->addWidget(refreshButton, 0, 0);

mMainTreeView->activeColumns.disable(gsColComparisonValue).disable(gsColComparisonValueHex).disable(gsColMemoryAddressDelta).disable(gsColMemoryAddress).disable(gsColComment);
refreshEntities();
mFilterLineEdit->setFocus();
}
auto label = new QLabel("Filter:", this);
filterLayout->addWidget(label, 0, 1);

void S2Plugin::ViewEntities::initializeTreeView()
{
mMainTreeView = new TreeViewMemoryFields(this);
mMainTreeView->setEnableChangeHighlighting(false);
mFilterLineEdit = new QLineEdit(this);
mFilterLineEdit->setPlaceholderText("Search for UID (dec or hex starting with 0x) or (part of) the entity name");
QObject::connect(mFilterLineEdit, &QLineEdit::textChanged, this, &ViewEntities::refreshEntities);
filterLayout->addWidget(mFilterLineEdit, 0, 2, 1, 6);

mMainLayout->addWidget(mMainTreeView);
}
mCheckboxLayer0 = new QCheckBox("Front layer (0)", this);
mCheckboxLayer0->setChecked(true);
QObject::connect(mCheckboxLayer0, &QCheckBox::stateChanged, this, &ViewEntities::refreshEntities);
filterLayout->addWidget(mCheckboxLayer0, 2, 2);

void S2Plugin::ViewEntities::initializeRefreshAndFilter()
{
auto filterLayout = new QGridLayout(this);
mCheckboxLayer1 = new QCheckBox("Back layer (0)", this);
QObject::connect(mCheckboxLayer1, &QCheckBox::stateChanged, this, &ViewEntities::refreshEntities);
filterLayout->addWidget(mCheckboxLayer1, 2, 3);

auto refreshButton = new QPushButton("Refresh", this);
QObject::connect(refreshButton, &QPushButton::clicked, this, &ViewEntities::refreshEntities);
filterLayout->addWidget(refreshButton, 0, 0);
int row = 3;
int col = 2;
for (auto& checkbox : mCheckbox)
{
checkbox.mCheckbox = new QCheckBox(checkbox.name + " (0)", this);
QObject::connect(checkbox.mCheckbox, &QCheckBox::stateChanged, this, &ViewEntities::refreshEntities);
filterLayout->addWidget(checkbox.mCheckbox, row, col);
++col;
if (col == 9)
{
col = 2;
++row;
}
}

auto label = new QLabel("Filter:", this);
filterLayout->addWidget(label, 0, 1);
auto horLayout = new QHBoxLayout();
horLayout->addLayout(filterLayout);
horLayout->addStretch();
mainLayout->addLayout(horLayout);
}

mFilterLineEdit = new QLineEdit(this);
mFilterLineEdit->setPlaceholderText("Search for UID (dec or hex starting with 0x) or (part of) the entity name");
QObject::connect(mFilterLineEdit, &QLineEdit::textChanged, this, &ViewEntities::refreshEntities);
filterLayout->addWidget(mFilterLineEdit, 0, 2, 1, 6);
mMainTreeView = new TreeViewMemoryFields(this);
mMainTreeView->setEnableChangeHighlighting(false);
mainLayout->addWidget(mMainTreeView);

mCheckboxLayer0 = new QCheckBox("Front layer (0)", this);
mCheckboxLayer0->setChecked(true);
QObject::connect(mCheckboxLayer0, &QCheckBox::stateChanged, this, &ViewEntities::refreshEntities);
filterLayout->addWidget(mCheckboxLayer0, 2, 2);
setWindowIcon(getCavemanIcon());

mCheckboxLayer1 = new QCheckBox("Back layer (0)", this);
QObject::connect(mCheckboxLayer1, &QCheckBox::stateChanged, this, &ViewEntities::refreshEntities);
filterLayout->addWidget(mCheckboxLayer1, 2, 3);
mainLayout->setMargin(5);

int row = 3;
int col = 2;
for (auto& checkbox : mCheckbox)
{
checkbox.mCheckbox = new QCheckBox(checkbox.name + " (0)", this);
QObject::connect(checkbox.mCheckbox, &QCheckBox::stateChanged, this, &ViewEntities::refreshEntities);
filterLayout->addWidget(checkbox.mCheckbox, row, col);
++col;
if (col == 9)
{
col = 2;
++row;
}
}
setWindowTitle("Entities");
mMainTreeView->setVisible(true);

auto horLayout = new QHBoxLayout(this);
horLayout->addLayout(filterLayout);
horLayout->addStretch();
mMainLayout->addLayout(horLayout);
mMainTreeView->activeColumns.disable(gsColComparisonValue).disable(gsColComparisonValueHex).disable(gsColMemoryAddressDelta).disable(gsColMemoryAddress).disable(gsColComment);
refreshEntities();
mFilterLineEdit->setFocus();
}

void S2Plugin::ViewEntities::refreshEntities()
Expand Down
3 changes: 1 addition & 2 deletions src/Views/ViewEntity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ S2Plugin::ViewEntity::ViewEntity(size_t entityOffset, QWidget* parent) : QWidget
setWindowIcon(getCavemanIcon());

mMainLayout->setMargin(5);
setLayout(mMainLayout);

setWindowTitle(QString::asprintf("Entity %s 0x%016llX", Entity{mEntityPtr}.entityTypeName().c_str(), entityOffset));
mMainTreeView->setVisible(true);
Expand All @@ -46,7 +45,7 @@ S2Plugin::ViewEntity::ViewEntity(size_t entityOffset, QWidget* parent) : QWidget

void S2Plugin::ViewEntity::initializeUI()
{
mMainLayout = new QVBoxLayout();
mMainLayout = new QVBoxLayout(this);
mTopLayout = new QHBoxLayout();
mMainLayout->addLayout(mTopLayout);

Expand Down
1 change: 0 additions & 1 deletion src/Views/ViewGameManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ void S2Plugin::ViewGameManager::initializeUI()
mMainTreeView->updateTableHeader();

mMainLayout->setMargin(5);
setLayout(mMainLayout);
mMainTreeView->setVisible(true);
}

Expand Down
1 change: 0 additions & 1 deletion src/Views/ViewJournalPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ void S2Plugin::ViewJournalPage::initializeUI()
mMainTreeView->updateTableHeader();

mMainLayout->setMargin(5);
setLayout(mMainLayout);
mMainTreeView->setVisible(true);
}

Expand Down
3 changes: 1 addition & 2 deletions src/Views/ViewLevelGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ S2Plugin::ViewLevelGen::ViewLevelGen(QWidget* parent) : QWidget(parent)

void S2Plugin::ViewLevelGen::initializeUI()
{
mMainLayout = new QVBoxLayout();
mMainLayout = new QVBoxLayout(this);
mRefreshLayout = new QHBoxLayout();
mMainLayout->addLayout(mRefreshLayout);

Expand Down Expand Up @@ -111,7 +111,6 @@ void S2Plugin::ViewLevelGen::initializeUI()
}

mMainLayout->setMargin(5);
setLayout(mMainLayout);
mMainTreeView->setVisible(true);
}

Expand Down
1 change: 0 additions & 1 deletion src/Views/ViewLogger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ void S2Plugin::ViewLogger::initializeUI()
{
mMainLayout = new QVBoxLayout(this);
mMainLayout->setMargin(5);
setLayout(mMainLayout);

mTopLayout = new QHBoxLayout(this);
mTopLayout->addWidget(new QLabel("Sample period:", this));
Expand Down
3 changes: 1 addition & 2 deletions src/Views/ViewOnline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ S2Plugin::ViewOnline::ViewOnline(QWidget* parent) : QWidget(parent)
void S2Plugin::ViewOnline::initializeUI()
{
mMainLayout = new QVBoxLayout(this);
mRefreshLayout = new QHBoxLayout(this);
mRefreshLayout = new QHBoxLayout();
mMainLayout->addLayout(mRefreshLayout);

mRefreshButton = new QPushButton("Refresh", this);
Expand Down Expand Up @@ -63,7 +63,6 @@ void S2Plugin::ViewOnline::initializeUI()
mMainTreeView->updateTableHeader();

mMainLayout->setMargin(5);
setLayout(mMainLayout);
mMainTreeView->setVisible(true);
}

Expand Down
1 change: 0 additions & 1 deletion src/Views/ViewSaveGame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ void S2Plugin::ViewSaveGame::initializeUI()
mMainTreeView->updateTableHeader();

mMainLayout->setMargin(5);
setLayout(mMainLayout);
mMainTreeView->setVisible(true);
}

Expand Down
3 changes: 1 addition & 2 deletions src/Views/ViewState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ S2Plugin::ViewState::ViewState(uintptr_t state, QWidget* parent) : QWidget(paren

void S2Plugin::ViewState::initializeUI()
{
mMainLayout = new QVBoxLayout();
mMainLayout = new QVBoxLayout(this);
mRefreshLayout = new QHBoxLayout();
mMainLayout->addLayout(mRefreshLayout);

Expand Down Expand Up @@ -63,7 +63,6 @@ void S2Plugin::ViewState::initializeUI()
mMainTreeView->updateTableHeader();

mMainLayout->setMargin(5);
setLayout(mMainLayout);
mMainTreeView->setVisible(true);
}

Expand Down
1 change: 0 additions & 1 deletion src/Views/ViewStdMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ S2Plugin::ViewStdMap::ViewStdMap(const std::string& keytypeName, const std::stri
void S2Plugin::ViewStdMap::initializeRefreshLayout()
{
mMainLayout = new QVBoxLayout(this);
setLayout(mMainLayout);

auto refreshLayout = new QHBoxLayout(this);
mMainLayout->addLayout(refreshLayout);
Expand Down
3 changes: 1 addition & 2 deletions src/Views/ViewStdVector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ S2Plugin::ViewStdVector::ViewStdVector(const std::string& vectorType, uintptr_t

void S2Plugin::ViewStdVector::initializeRefreshLayout()
{
mMainLayout = new QVBoxLayout();
setLayout(mMainLayout);
mMainLayout = new QVBoxLayout(this);

auto refreshLayout = new QHBoxLayout();
mMainLayout->addLayout(refreshLayout);
Expand Down
Loading

0 comments on commit 6619242

Please sign in to comment.