Skip to content

Commit

Permalink
Shows appropriate text for device selection box
Browse files Browse the repository at this point in the history
  • Loading branch information
GrantComm committed Oct 9, 2024
1 parent 50c3eec commit 4188d35
Showing 1 changed file with 45 additions and 10 deletions.
55 changes: 45 additions & 10 deletions ui/trace_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,18 +88,35 @@ TraceDialog::TraceDialog(QWidget *parent)
m_main_layout = new QVBoxLayout();

m_devices = Dive::GetDeviceManager().ListDevice();
for (size_t i = 0; i < m_devices.size(); i++)
if (m_devices.size() == 0)
{
QStandardItem *item = new QStandardItem(m_devices[i].GetDisplayName().c_str());
QStandardItem *item = new QStandardItem("No devices found");
item->setFlags(item->flags() & ~Qt::ItemIsSelectable);
m_dev_model->appendRow(item);
m_dev_box->setCurrentIndex(0);
}
else
{
for (size_t i = 0; i < m_devices.size(); i++)
{
if (i == 0)
{
QStandardItem *item = new QStandardItem("Please select a device");
item->setFlags(item->flags() & ~Qt::ItemIsSelectable);
m_dev_model->appendRow(item);
m_dev_box->setCurrentIndex(0);
}
QStandardItem *item = new QStandardItem(m_devices[i].GetDisplayName().c_str());
m_dev_model->appendRow(item);
}
}
for (const auto &ty : kAppTypes)
{
QStandardItem *item = new QStandardItem(ty.c_str());
m_app_type_model->appendRow(item);
}
m_dev_box->setModel(m_dev_model);
m_dev_box->setCurrentIndex(-1);
m_dev_box->setCurrentIndex(0);
m_dev_box->setCurrentText("Please select a device");

m_pkg_box->setModel(m_pkg_model);
Expand Down Expand Up @@ -228,26 +245,44 @@ void TraceDialog::UpdateDeviceList()
m_devices = cur_list;
m_dev_model->clear();

for (size_t i = 0; i < m_devices.size(); i++)
if (m_devices.size() == 0)
{
QStandardItem *item = new QStandardItem(m_devices[i].GetDisplayName().c_str());
QStandardItem *item = new QStandardItem("No devices found");
item->setFlags(item->flags() & ~Qt::ItemIsSelectable);
m_dev_model->appendRow(item);
// Keep the original selected devices as selected.
if (m_cur_dev == m_devices[i].m_serial)
m_dev_box->setCurrentIndex(0);
}
else
{
for (size_t i = 0; i < m_devices.size(); i++)
{
m_dev_box->setCurrentIndex(static_cast<int>(i));
if (i == 0)
{
QStandardItem *item = new QStandardItem("Please select a device");
item->setFlags(item->flags() & ~Qt::ItemIsSelectable);
m_dev_model->appendRow(item);
m_dev_box->setCurrentIndex(0);
}

QStandardItem *item = new QStandardItem(m_devices[i].GetDisplayName().c_str());
m_dev_model->appendRow(item);
// Keep the original selected devices as selected.
if (m_cur_dev == m_devices[i].m_serial)
{
m_dev_box->setCurrentIndex(static_cast<int>(i));
}
}
}
}

void TraceDialog::OnDeviceSelected(const QString &s)
{
if (s.isEmpty() || m_dev_box->currentIndex() == -1)
if (s.isEmpty() || m_dev_box->currentIndex() == 0)
{
qDebug() << "No devices selected";
return;
}
int dev_index = m_dev_box->currentIndex();
int dev_index = m_dev_box->currentIndex() - 1;
assert(static_cast<size_t>(dev_index) < m_devices.size());

qDebug() << "Device selected: " << m_cur_dev.c_str() << ", index " << dev_index
Expand Down

0 comments on commit 4188d35

Please sign in to comment.