Skip to content

Commit

Permalink
Clean code logic
Browse files Browse the repository at this point in the history
  • Loading branch information
IKhonakhbeeva committed Oct 14, 2021
1 parent 0f72825 commit 59deb54
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public slots:
, Reason reason) override;

void propagateChanges(const QString &robotId, const robotModel::PortInfo &port
, const robotModel::DeviceInfo &sensor);
, const robotModel::DeviceInfo &sensor, Reason reason);

void propagateChangesFromBox(QComboBox *box);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,12 @@ void DevicesConfigurationProvider::deviceConfigurationChanged(const QString &rob
{
if (mCurrentConfiguration[robotId][port] != device) {
mCurrentConfiguration[robotId][port] = device;
// Allow provider to react on configuration change.
onDeviceConfigurationChanged(robotId, port, device, reason);

for (DevicesConfigurationProvider * const provider : mConnectedProviders) {
// Broadcast change.
provider->deviceConfigurationChanged(robotId, port, device, reason);

// Allow connected providers to react on configuration change.
provider->onDeviceConfigurationChanged(robotId, port, device, reason);
}
}
}
Expand All @@ -88,9 +87,9 @@ void DevicesConfigurationProvider::onDeviceConfigurationChanged(const QString &r
, const PortInfo &port, const DeviceInfo &sensor, Reason reason)
{
Q_UNUSED(robotId)
Q_UNUSED(port);
Q_UNUSED(sensor);
Q_UNUSED(reason);
Q_UNUSED(port)
Q_UNUSED(sensor)
Q_UNUSED(reason)
}

void DevicesConfigurationProvider::clearConfiguration(Reason reason)
Expand Down
16 changes: 7 additions & 9 deletions plugins/robots/common/kitBase/src/devicesConfigurationWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,7 @@ QLayout *DevicesConfigurationWidget::initPort(const QString &robotModelName
void DevicesConfigurationWidget::onDeviceConfigurationChanged(const QString &robotId
, const PortInfo &port, const DeviceInfo &sensor, Reason reason)
{
Q_UNUSED(reason)

propagateChanges(robotId, port, sensor);
propagateChanges(robotId, port, sensor, reason);
// This method can be called when we did not accomplish processing all combo boxes during saving.
// So ignoring such case.
if (!mSaving && robotId == mCurrentRobotId) {
Expand Down Expand Up @@ -179,14 +177,14 @@ void DevicesConfigurationWidget::save()

void DevicesConfigurationWidget::propagateChangesFromBox(QComboBox *box)
{
const PortInfo port = box->property("port").value<PortInfo>();
const DeviceInfo device = box->itemData(box->currentIndex()).value<DeviceInfo>();
const PortInfo &port = box->property("port").value<PortInfo>();
const DeviceInfo &device = box->itemData(box->currentIndex()).value<DeviceInfo>();
if (currentConfiguration(mCurrentRobotId, port) != device) {
propagateChanges(mCurrentRobotId, port, device);
propagateChanges(mCurrentRobotId, port, device, Reason::userAction);
}
}

void DevicesConfigurationWidget::propagateChanges(const QString &robotId, const PortInfo &port, const DeviceInfo &sensor)
void DevicesConfigurationWidget::propagateChanges(const QString &robotId, const PortInfo &port, const DeviceInfo &sensor, Reason reason)
{
const auto kit = robotId.split(QRegExp("[A-Z]")).first();
for (const QString &robotModelType : mRobotModels.keys()) {
Expand All @@ -195,12 +193,12 @@ void DevicesConfigurationWidget::propagateChanges(const QString &robotId, const
for (const PortInfo &otherPort : robotModel->configurablePorts()) {
if (areConvertible(port, otherPort)) {
if (sensor.isNull()) {
deviceConfigurationChanged(robotModel->robotId(), otherPort, DeviceInfo(), Reason::userAction);
deviceConfigurationChanged(robotModel->robotId(), otherPort, DeviceInfo(), reason);
} else {
const DeviceInfo otherDevice = convertibleDevice(robotModel, otherPort, sensor);
if (!otherDevice.isNull()) {
deviceConfigurationChanged(robotModel->robotId(), otherPort
, otherDevice, Reason::userAction);
, otherDevice, reason);
}
}
}
Expand Down

0 comments on commit 59deb54

Please sign in to comment.