From 09ec9d600606227187afec5c6d7699f3e2cb9c83 Mon Sep 17 00:00:00 2001 From: Olivier Galibert Date: Fri, 19 Dec 2014 18:26:05 +0100 Subject: [PATCH] qt/debug: Device tree view. Looks cool with mu100 or lindbios [O. Galibert] --- src/osd/modules/debugger/debugqt.c | 6 + .../debugger/qt/debugqtdeviceswindow.c | 162 ++++++++++++++++++ .../debugger/qt/debugqtdeviceswindow.h | 74 ++++++++ src/osd/modules/debugger/qt/debugqtwindow.c | 16 ++ src/osd/modules/debugger/qt/debugqtwindow.h | 15 +- src/osd/sdl/sdl.mak | 4 +- 6 files changed, 270 insertions(+), 7 deletions(-) create mode 100644 src/osd/modules/debugger/qt/debugqtdeviceswindow.c create mode 100644 src/osd/modules/debugger/qt/debugqtdeviceswindow.h diff --git a/src/osd/modules/debugger/debugqt.c b/src/osd/modules/debugger/debugqt.c index 55956500398..40942a63506 100644 --- a/src/osd/modules/debugger/debugqt.c +++ b/src/osd/modules/debugger/debugqt.c @@ -25,6 +25,7 @@ #include "qt/debugqtdasmwindow.h" #include "qt/debugqtmemorywindow.h" #include "qt/debugqtbreakpointswindow.h" +#include "qt/debugqtdeviceswindow.h" #include "debugqt.h" @@ -90,6 +91,7 @@ static void xml_configuration_load(running_machine &machine, int config_type, xm case WindowQtConfig::WIN_TYPE_DASM: xmlConfigurations.push_back(new DasmWindowQtConfig()); break; case WindowQtConfig::WIN_TYPE_LOG: xmlConfigurations.push_back(new LogWindowQtConfig()); break; case WindowQtConfig::WIN_TYPE_BREAK_POINTS: xmlConfigurations.push_back(new BreakpointsWindowQtConfig()); break; + case WindowQtConfig::WIN_TYPE_DEVICES: xmlConfigurations.push_back(new DevicesWindowQtConfig()); break; default: continue; } xmlConfigurations.back()->recoverFromXmlNode(wnode); @@ -145,6 +147,8 @@ static void gather_save_configurations() xmlConfigurations.push_back(new LogWindowQtConfig()); else if (dynamic_cast(widget)) xmlConfigurations.push_back(new BreakpointsWindowQtConfig()); + else if (dynamic_cast(widget)) + xmlConfigurations.push_back(new DevicesWindowQtConfig()); xmlConfigurations.back()->buildFromQWidget(widget); } @@ -187,6 +191,8 @@ static void setup_additional_startup_windows(running_machine& machine, std::vect foo = new LogWindow(&machine); break; case WindowQtConfig::WIN_TYPE_BREAK_POINTS: foo = new BreakpointsWindow(&machine); break; + case WindowQtConfig::WIN_TYPE_DEVICES: + foo = new DevicesWindow(&machine); break; default: break; } config->applyToQWidget(foo); diff --git a/src/osd/modules/debugger/qt/debugqtdeviceswindow.c b/src/osd/modules/debugger/qt/debugqtdeviceswindow.c new file mode 100644 index 00000000000..ee833941b2d --- /dev/null +++ b/src/osd/modules/debugger/qt/debugqtdeviceswindow.c @@ -0,0 +1,162 @@ +#define NO_MEM_TRACKING + +#include "debugqtdeviceswindow.h" + +DevicesWindowModel::DevicesWindowModel(running_machine *machine, QObject *parent) +{ + m_machine = machine; +} + +DevicesWindowModel::~DevicesWindowModel() +{ +} + +QVariant DevicesWindowModel::data(const QModelIndex &index, int role) const +{ + if(!index.isValid() || role != Qt::DisplayRole) + return QVariant(); + + device_t *dev = static_cast(index.internalPointer()); + switch(index.column()) { + case 0: return QString(dev->basetag()); break; + case 1: return QString(dev->name()); break; + } + + return QVariant(); +} + +Qt::ItemFlags DevicesWindowModel::flags(const QModelIndex &index) const +{ + if(!index.isValid()) + return 0; + + return QAbstractItemModel::flags(index); +} + +QVariant DevicesWindowModel::headerData(int section, Qt::Orientation orientation, int role) const +{ + if(role != Qt::DisplayRole || section < 0 || section >= 2) + return QVariant(); + return QString(section ? "Name" : "Tag"); +} + +QModelIndex DevicesWindowModel::index(int row, int column, const QModelIndex &parent) const +{ + if(!hasIndex(row, column, parent)) + return QModelIndex(); + + device_t *target = NULL; + + if(!parent.isValid()) { + if(row == 0) + target = &m_machine->root_device(); + + } else { + device_t *dparent = static_cast(parent.internalPointer()); + int count = row; + for(target = dparent->first_subdevice(); count && target; target = target->next()) + count--; + } + + if(target) + return createIndex(row, column, target); + + return QModelIndex(); +} + +QModelIndex DevicesWindowModel::parent(const QModelIndex &index) const +{ + if(!index.isValid()) + return QModelIndex(); + + device_t *dchild = static_cast(index.internalPointer()); + device_t *dparent = dchild->owner(); + + if(!dparent) + return QModelIndex(); + + device_t *dpp = dparent->owner(); + int row = 0; + if(dpp) { + for(device_t *child = dpp->first_subdevice(); child && child != dparent; child = child->next()) + row++; + } + return createIndex(row, 0, dparent); +} + +int DevicesWindowModel::rowCount(const QModelIndex &parent) const +{ + if(!parent.isValid()) + return 1; + + device_t *dparent = static_cast(parent.internalPointer()); + int count = 0; + for(device_t *child = dparent->first_subdevice(); child; child = child->next()) + count++; + + return count; +} + +int DevicesWindowModel::columnCount(const QModelIndex &parent) const +{ + return 2; +} + + + +DevicesWindow::DevicesWindow(running_machine* machine, QWidget* parent) : + WindowQt(machine, NULL), + m_devices_model(machine) +{ + setWindowTitle("Debug: All Devices"); + + if (parent != NULL) + { + QPoint parentPos = parent->pos(); + setGeometry(parentPos.x()+100, parentPos.y()+100, 600, 400); + } + + // + // The tree widget + // + m_devices_view = new QTreeView(this); + m_devices_view->setModel(&m_devices_model); + m_devices_view->expandAll(); + m_devices_view->resizeColumnToContents(0); + setCentralWidget(m_devices_view); +} + + +DevicesWindow::~DevicesWindow() +{ +} + + + +//========================================================================= +// DevicesWindowQtConfig +//========================================================================= +void DevicesWindowQtConfig::buildFromQWidget(QWidget* widget) +{ + WindowQtConfig::buildFromQWidget(widget); + // DevicesWindow* window = dynamic_cast(widget); +} + + +void DevicesWindowQtConfig::applyToQWidget(QWidget* widget) +{ + WindowQtConfig::applyToQWidget(widget); + // DevicesWindow* window = dynamic_cast(widget); +} + + +void DevicesWindowQtConfig::addToXmlDataNode(xml_data_node* node) const +{ + WindowQtConfig::addToXmlDataNode(node); +} + + +void DevicesWindowQtConfig::recoverFromXmlNode(xml_data_node* node) +{ + WindowQtConfig::recoverFromXmlNode(node); +} diff --git a/src/osd/modules/debugger/qt/debugqtdeviceswindow.h b/src/osd/modules/debugger/qt/debugqtdeviceswindow.h new file mode 100644 index 00000000000..de3645d5517 --- /dev/null +++ b/src/osd/modules/debugger/qt/debugqtdeviceswindow.h @@ -0,0 +1,74 @@ +#ifndef __DEBUG_QT_DEVICES_WINDOW_H__ +#define __DEBUG_QT_DEVICES_WINDOW_H__ + +#include + +#include "debugqtwindow.h" + + +//============================================================ +// The model for the treeview +//============================================================ + +class DevicesWindowModel : public QAbstractItemModel +{ + Q_OBJECT + +public: + explicit DevicesWindowModel(running_machine *machine, QObject *parent = 0); + ~DevicesWindowModel(); + + QVariant data(const QModelIndex &index, int role) const; + Qt::ItemFlags flags(const QModelIndex &index) const; + QVariant headerData(int section, Qt::Orientation orientation, + int role = Qt::DisplayRole) const; + QModelIndex index(int row, int column, + const QModelIndex &parent = QModelIndex()) const; + QModelIndex parent(const QModelIndex &index) const; + int rowCount(const QModelIndex &parent = QModelIndex()) const; + int columnCount(const QModelIndex &parent = QModelIndex()) const; + +private: + running_machine *m_machine; +}; + +//============================================================ +// The Devices Window. +//============================================================ +class DevicesWindow : public WindowQt +{ + Q_OBJECT + +public: + DevicesWindow(running_machine* machine, QWidget* parent=NULL); + virtual ~DevicesWindow(); + +private: + QTreeView *m_devices_view; + DevicesWindowModel m_devices_model; +}; + + + + +//========================================================================= +// A way to store the configuration of a window long enough to read/write. +//========================================================================= +class DevicesWindowQtConfig : public WindowQtConfig +{ +public: + DevicesWindowQtConfig() : + WindowQtConfig(WIN_TYPE_DEVICES) + { + } + + ~DevicesWindowQtConfig() {} + + void buildFromQWidget(QWidget* widget); + void applyToQWidget(QWidget* widget); + void addToXmlDataNode(xml_data_node* node) const; + void recoverFromXmlNode(xml_data_node* node); +}; + + +#endif diff --git a/src/osd/modules/debugger/qt/debugqtwindow.c b/src/osd/modules/debugger/qt/debugqtwindow.c index 5294bad8ef4..9570ad83d5e 100644 --- a/src/osd/modules/debugger/qt/debugqtwindow.c +++ b/src/osd/modules/debugger/qt/debugqtwindow.c @@ -5,6 +5,7 @@ #include "debugqtdasmwindow.h" #include "debugqtmemorywindow.h" #include "debugqtbreakpointswindow.h" +#include "debugqtdeviceswindow.h" bool WindowQt::s_refreshAll = false; bool WindowQt::s_hideAll = false; @@ -38,6 +39,10 @@ WindowQt::WindowQt(running_machine* machine, QWidget* parent) : debugActOpenPoints->setShortcut(QKeySequence("Ctrl+B")); connect(debugActOpenPoints, SIGNAL(triggered()), this, SLOT(debugActOpenPoints())); + QAction* debugActOpenDevices = new QAction("New D&evices Window", this); + debugActOpenDevices->setShortcut(QKeySequence("Shift+Ctrl+D")); + connect(debugActOpenDevices, SIGNAL(triggered()), this, SLOT(debugActOpenDevices())); + QAction* dbgActRun = new QAction("Run", this); dbgActRun->setShortcut(Qt::Key_F5); connect(dbgActRun, SIGNAL(triggered()), this, SLOT(debugActRun())); @@ -92,6 +97,7 @@ WindowQt::WindowQt(running_machine* machine, QWidget* parent) : debugMenu->addAction(debugActOpenDasm); debugMenu->addAction(debugActOpenLog); debugMenu->addAction(debugActOpenPoints); + debugMenu->addAction(debugActOpenDevices); debugMenu->addSeparator(); debugMenu->addAction(dbgActRun); debugMenu->addAction(dbgActRunAndHide); @@ -155,6 +161,16 @@ void WindowQt::debugActOpenPoints() } +void WindowQt::debugActOpenDevices() +{ + DevicesWindow* foo = new DevicesWindow(m_machine, this); + // A valiant effort, but it just doesn't wanna' hide behind the main window & not make a new toolbar icon + // foo->setWindowFlags(Qt::Dialog); + // foo->setWindowFlags(foo->windowFlags() & ~Qt::WindowStaysOnTopHint); + foo->show(); +} + + void WindowQt::debugActRun() { debug_cpu_get_visible_cpu(*m_machine)->debug()->go(); diff --git a/src/osd/modules/debugger/qt/debugqtwindow.h b/src/osd/modules/debugger/qt/debugqtwindow.h index e6027465b76..ecaf1c24217 100644 --- a/src/osd/modules/debugger/qt/debugqtwindow.h +++ b/src/osd/modules/debugger/qt/debugqtwindow.h @@ -34,6 +34,7 @@ protected slots: void debugActOpenDasm(); void debugActOpenLog(); void debugActOpenPoints(); + void debugActOpenDevices(); void debugActRun(); void debugActRunAndHide(); void debugActRunToNextCpu(); @@ -64,12 +65,14 @@ class WindowQtConfig public: enum WindowType { - WIN_TYPE_MAIN = 0x01, - WIN_TYPE_MEMORY = 0x02, - WIN_TYPE_DASM = 0x04, - WIN_TYPE_LOG = 0x08, - WIN_TYPE_BREAK_POINTS = 0x10, - WIN_TYPE_UNKNOWN = 0x20 + WIN_TYPE_UNKNOWN, + WIN_TYPE_MAIN, + WIN_TYPE_MEMORY, + WIN_TYPE_DASM, + WIN_TYPE_LOG, + WIN_TYPE_BREAK_POINTS, + WIN_TYPE_DEVICES, + WIN_TYPE_DEVICE_INFORMATION }; public: diff --git a/src/osd/sdl/sdl.mak b/src/osd/sdl/sdl.mak index c7aa5756ce8..6ec71d3a162 100644 --- a/src/osd/sdl/sdl.mak +++ b/src/osd/sdl/sdl.mak @@ -679,13 +679,15 @@ DEBUGOBJS = \ $(OSDOBJ)/modules/debugger/qt/debugqtmainwindow.o \ $(OSDOBJ)/modules/debugger/qt/debugqtmemorywindow.o \ $(OSDOBJ)/modules/debugger/qt/debugqtbreakpointswindow.o \ + $(OSDOBJ)/modules/debugger/qt/debugqtdeviceswindow.o \ $(OSDOBJ)/modules/debugger/qt/debugqtview.moc.o \ $(OSDOBJ)/modules/debugger/qt/debugqtwindow.moc.o \ $(OSDOBJ)/modules/debugger/qt/debugqtlogwindow.moc.o \ $(OSDOBJ)/modules/debugger/qt/debugqtdasmwindow.moc.o \ $(OSDOBJ)/modules/debugger/qt/debugqtmainwindow.moc.o \ $(OSDOBJ)/modules/debugger/qt/debugqtmemorywindow.moc.o \ - $(OSDOBJ)/modules/debugger/qt/debugqtbreakpointswindow.moc.o + $(OSDOBJ)/modules/debugger/qt/debugqtbreakpointswindow.moc.o \ + $(OSDOBJ)/modules/debugger/qt/debugqtdeviceswindow.moc.o endif ifeq ($(NO_DEBUGGER),1)