* @brief Rebuilds the device name list from project sources and connection state. */
| 913 | * @brief Rebuilds the device name list from project sources and connection state. |
| 914 | */ |
| 915 | void Console::Handler::onDevicesChanged() |
| 916 | { |
| 917 | const auto& mgr = IO::ConnectionManager::instance(); |
| 918 | const auto opMode = AppState::instance().operationMode(); |
| 919 | const auto& sources = DataModel::ProjectModel::instance().sources(); |
| 920 | |
| 921 | QStringList names; |
| 922 | QList<int> ids; |
| 923 | |
| 924 | if (opMode == SerialStudio::ProjectFile && sources.size() > 1) { |
| 925 | for (const auto& src : sources) { |
| 926 | const auto label = src.title.isEmpty() ? tr("Device %1").arg(src.sourceId) : src.title; |
| 927 | names.append(label); |
| 928 | ids.append(src.sourceId); |
| 929 | } |
| 930 | } |
| 931 | |
| 932 | if (names == m_deviceNames && ids == m_deviceSourceIds) |
| 933 | return; |
| 934 | |
| 935 | m_deviceNames = names; |
| 936 | m_deviceSourceIds = ids; |
| 937 | |
| 938 | if (!mgr.isConnected()) { |
| 939 | m_deviceState.clear(); |
| 940 | m_currentDeviceId = -1; |
| 941 | Q_EMIT deviceNamesChanged(); |
| 942 | Q_EMIT currentDeviceIdChanged(); |
| 943 | return; |
| 944 | } |
| 945 | |
| 946 | if (!ids.isEmpty() && !ids.contains(m_currentDeviceId)) |
| 947 | setCurrentDeviceId(ids.first()); |
| 948 | else if (ids.isEmpty()) |
| 949 | m_currentDeviceId = -1; |
| 950 | |
| 951 | Q_EMIT deviceNamesChanged(); |
| 952 | } |
| 953 | |
| 954 | //-------------------------------------------------------------------------------------------------- |
| 955 | // Internal utilities |
nothing calls this directly
no test coverage detected