Skip to content

Commit

Permalink
Shows appropriate text for device selection box (#137)
Browse files Browse the repository at this point in the history
* Shows appropriate text for device selection box

* Keeps device list logic contained in UpdateDeviceList function
  • Loading branch information
GrantComm authored Oct 9, 2024
1 parent 50c3eec commit efa9b3a
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 18 deletions.
2 changes: 1 addition & 1 deletion ui/main_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -691,7 +691,7 @@ void MainWindow::OnCaptureTrigger()
//--------------------------------------------------------------------------------------------------
void MainWindow::OnCapture(bool is_capture_delayed)
{
m_trace_dig->UpdateDeviceList();
m_trace_dig->UpdateDeviceList(true);
m_trace_dig->exec();
}

Expand Down
46 changes: 30 additions & 16 deletions ui/trace_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,18 +88,14 @@ TraceDialog::TraceDialog(QWidget *parent)
m_main_layout = new QVBoxLayout();

m_devices = Dive::GetDeviceManager().ListDevice();
for (size_t i = 0; i < m_devices.size(); i++)
{
QStandardItem *item = new QStandardItem(m_devices[i].GetDisplayName().c_str());
m_dev_model->appendRow(item);
}
UpdateDeviceList(false);
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 @@ -215,11 +211,11 @@ void ShowErrorMessage(const std::string &err_msg)
return;
}

void TraceDialog::UpdateDeviceList()
void TraceDialog::UpdateDeviceList(bool isInitialized)
{
auto cur_list = Dive::GetDeviceManager().ListDevice();
qDebug() << "m_dev_box->currentIndex() " << m_dev_box->currentIndex();
if (cur_list == m_devices)
if (cur_list == m_devices && isInitialized)
{
qDebug() << "No changes from the list of the connected devices. ";
return;
Expand All @@ -228,26 +224,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.empty())
{
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 Expand Up @@ -590,7 +604,7 @@ void TraceWorker::run()

void TraceDialog::OnDevListRefresh()
{
UpdateDeviceList();
UpdateDeviceList(true);
}

void TraceDialog::OnAppListRefresh()
Expand Down
2 changes: 1 addition & 1 deletion ui/trace_window.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class TraceDialog : public QDialog
public:
TraceDialog(QWidget *parent = 0);
~TraceDialog();
void UpdateDeviceList();
void UpdateDeviceList(bool isInitialized);
void UpdatePackageList();
void Cleanup() { Dive::GetDeviceManager().RemoveDevice(); }

Expand Down

0 comments on commit efa9b3a

Please sign in to comment.