MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / onDevicesChanged

Method onDevicesChanged

app/src/Console/Handler.cpp:915–952  ·  view source on GitHub ↗

* @brief Rebuilds the device name list from project sources and connection state. */

Source from the content-addressed store, hash-verified

913 * @brief Rebuilds the device name list from project sources and connection state.
914 */
915void 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

Callers

nothing calls this directly

Calls 8

operationModeMethod · 0.80
isEmptyMethod · 0.80
firstMethod · 0.80
sizeMethod · 0.45
appendMethod · 0.45
isConnectedMethod · 0.45
clearMethod · 0.45
containsMethod · 0.45

Tested by

no test coverage detected