From ed7d514c3150ee750d38d010ff9a9ff3ca0c8ba2 Mon Sep 17 00:00:00 2001 From: Megamouse Date: Fri, 30 Mar 2018 12:55:43 +0200 Subject: [PATCH] rsx_debugger: move debugger table resize to qt_utils for reusability maybe create a custom table class in the future --- rpcs3/rpcs3qt/qt_utils.cpp | 36 +++++++++++++++++++++++++ rpcs3/rpcs3qt/qt_utils.h | 5 ++++ rpcs3/rpcs3qt/rsx_debugger.cpp | 48 +++++++++------------------------- rpcs3/rpcs3qt/rsx_debugger.h | 1 - 4 files changed, 53 insertions(+), 37 deletions(-) diff --git a/rpcs3/rpcs3qt/qt_utils.cpp b/rpcs3/rpcs3qt/qt_utils.cpp index 2f0c2d9064..2e1ba7317d 100644 --- a/rpcs3/rpcs3qt/qt_utils.cpp +++ b/rpcs3/rpcs3qt/qt_utils.cpp @@ -155,5 +155,41 @@ namespace gui return image.copy(QRect(QPoint(w_max, h_max), QPoint(w_min, h_min))); } + + void update_table_item_count(QTableWidget* table) + { + if (!table) + return; + + int item_count = table->rowCount(); + bool is_empty = item_count < 1; + if (is_empty) + table->insertRow(0); + + int item_height = table->rowHeight(0); + if (is_empty) + { + table->clearContents(); + table->setRowCount(0); + } + + int available_height = table->rect().height() - table->horizontalHeader()->height() - table->frameWidth() * 2; + if (available_height < item_height || item_height < 1) + return; + + int new_item_count = available_height / item_height; + if (new_item_count == item_count) + return; + + item_count = new_item_count; + table->clearContents(); + table->setRowCount(0); + + for (u32 i = 0; i < item_count; ++i) + table->insertRow(i); + + if (table->horizontalScrollBar()) + table->removeRow(--item_count); + } } // utils } // gui diff --git a/rpcs3/rpcs3qt/qt_utils.h b/rpcs3/rpcs3qt/qt_utils.h index 2bb4071fcc..4bdc8e3849 100644 --- a/rpcs3/rpcs3qt/qt_utils.h +++ b/rpcs3/rpcs3qt/qt_utils.h @@ -5,6 +5,8 @@ #include #include #include +#include +#include namespace gui { @@ -35,5 +37,8 @@ namespace gui // Returns the part of the image loaded from path that is inside the bounding box of its opaque areas QImage get_opaque_image_area(const QString& path); + + // Recalculates a table's item count based on the available visible space and fills it with empty items + void update_table_item_count(QTableWidget* table); } // utils } // gui diff --git a/rpcs3/rpcs3qt/rsx_debugger.cpp b/rpcs3/rpcs3qt/rsx_debugger.cpp index 5e3c0c02d5..c558eee650 100644 --- a/rpcs3/rpcs3qt/rsx_debugger.cpp +++ b/rpcs3/rpcs3qt/rsx_debugger.cpp @@ -1,5 +1,6 @@ #include "rsx_debugger.h" +#include "qt_utils.h" enum GCMEnumTypes { @@ -301,35 +302,7 @@ bool rsx_debugger::eventFilter(QObject* object, QEvent* event) { case QEvent::Resize: { - bool is_empty = m_list_commands->rowCount() < 1; - if (is_empty) - m_list_commands->insertRow(m_list_commands->rowCount()); - - int item_height = m_list_commands->rowHeight(0); - if (is_empty) - { - m_list_commands->clearContents(); - m_list_commands->setRowCount(0); - } - - int available_height = m_list_commands->rect().height() - m_list_commands->horizontalHeader()->height() - m_list_commands->frameWidth() * 2; - if (available_height < item_height || item_height < 1) - break; - - int new_item_count = available_height / item_height; - if (new_item_count == m_item_count) - break; - - m_item_count = new_item_count; - m_list_commands->clearContents(); - m_list_commands->setRowCount(0); - - for (u32 i = 0; i < m_item_count; ++i) - m_list_commands->insertRow(m_list_commands->rowCount()); - - if (m_list_commands->horizontalScrollBar()) - m_list_commands->removeRow(--m_item_count); - + gui::utils::update_table_item_count(m_list_commands); UpdateInformation(); break; } @@ -337,12 +310,13 @@ bool rsx_debugger::eventFilter(QObject* object, QEvent* event) { QWheelEvent* wheelEvent = static_cast(event); QPoint numSteps = wheelEvent->angleDelta() / 8 / 15; // http://doc.qt.io/qt-5/qwheelevent.html#pixelDelta + int steps = numSteps.y(); + int item_count = m_list_commands->rowCount(); + int step_size = wheelEvent->modifiers() & Qt::ControlModifier ? item_count : 1; if (vm::check_addr(m_addr, 4)) { - int items = wheelEvent->modifiers() & Qt::ControlModifier ? m_item_count : 1; - - for (int i = 0; imodifiers() & Qt::ControlModifier ? m_item_count : 1) * 4 * numSteps.y(); + m_addr -= step_size * 4 * steps; } UpdateInformation(); @@ -667,12 +641,14 @@ void rsx_debugger::UpdateInformation() void rsx_debugger::GetMemory() { + int item_count = m_list_commands->rowCount(); + // Clean commands column - for(u32 i=0; isetItem(i, 2, new QTableWidgetItem("")); // Write information - for(u32 i=0, addr = m_addr; isetItem(i, 0, new QTableWidgetItem(qstr(fmt::format("%08x", addr)))); diff --git a/rpcs3/rpcs3qt/rsx_debugger.h b/rpcs3/rpcs3qt/rsx_debugger.h index 3bc80af131..32f53559b7 100644 --- a/rpcs3/rpcs3qt/rsx_debugger.h +++ b/rpcs3/rpcs3qt/rsx_debugger.h @@ -55,7 +55,6 @@ class rsx_debugger : public QDialog QLineEdit* m_addr_line; - u32 m_item_count; QTableWidget* m_list_commands; QTableWidget* m_list_captured_frame; QTableWidget* m_list_captured_draw_calls;