summaryrefslogtreecommitdiffstatshomepage
path: root/src/osd/modules/debugger/qt/deviceswindow.cpp
blob: 7484e03cb1a457bdc8efc785dbbc43c01e67bce4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
// license:BSD-3-Clause
// copyright-holders:Andrew Gardner
#include "deviceswindow.h"
#include "deviceinformationwindow.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<device_t *>(index.internalPointer());
	switch(index.column()) {
	case 0: return dev == &m_machine->root_device() ? QString("<root>") : QString(dev->basetag().c_str());
	case 1: return QString(dev->name().c_str());
	}

	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<device_t *>(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<device_t *>(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<device_t *>(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)
{
	m_selected_device = NULL;

	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);
	connect(m_devices_view->selectionModel(), &QItemSelectionModel::currentRowChanged, this, &DevicesWindow::currentRowChanged);
	connect(m_devices_view, &QTreeView::activated, this, &DevicesWindow::activated);
	setCentralWidget(m_devices_view);
}


DevicesWindow::~DevicesWindow()
{
}


void DevicesWindow::currentRowChanged(const QModelIndex &current, const QModelIndex &previous)
{
	m_selected_device = static_cast<device_t *>(current.internalPointer());
}


void DevicesWindow::activated(const QModelIndex &index)
{
	device_t *dev = static_cast<device_t *>(index.internalPointer());
	(new DeviceInformationWindow(m_machine, dev, this))->show();
}



//=========================================================================
//  DevicesWindowQtConfig
//=========================================================================
void DevicesWindowQtConfig::buildFromQWidget(QWidget* widget)
{
	WindowQtConfig::buildFromQWidget(widget);
	//  DevicesWindow* window = dynamic_cast<DevicesWindow*>(widget);
}


void DevicesWindowQtConfig::applyToQWidget(QWidget* widget)
{
	WindowQtConfig::applyToQWidget(widget);
	//  DevicesWindow* window = dynamic_cast<DevicesWindow*>(widget);
}


void DevicesWindowQtConfig::addToXmlDataNode(xml_data_node* node) const
{
	WindowQtConfig::addToXmlDataNode(node);
}


void DevicesWindowQtConfig::recoverFromXmlNode(xml_data_node* node)
{
	WindowQtConfig::recoverFromXmlNode(node);
}