From 63e4b7afd569f617469c58a8cbd6240a57dbf81f Mon Sep 17 00:00:00 2001 From: IKhonakhbeeva Date: Mon, 28 Sep 2020 22:01:31 +0300 Subject: [PATCH] Fix loading robot image from settings --- .../include/twoDModel/robotModel/twoDRobotModel.h | 3 +++ .../common/twoDModel/src/engine/view/scene/robotItem.cpp | 8 ++++++++ .../common/twoDModel/src/engine/view/scene/robotItem.h | 1 + .../common/twoDModel/src/robotModel/twoDRobotModel.cpp | 5 +++++ 4 files changed, 17 insertions(+) diff --git a/plugins/robots/common/twoDModel/include/twoDModel/robotModel/twoDRobotModel.h b/plugins/robots/common/twoDModel/include/twoDModel/robotModel/twoDRobotModel.h index 35ac022acf..82d46c68c5 100644 --- a/plugins/robots/common/twoDModel/include/twoDModel/robotModel/twoDRobotModel.h +++ b/plugins/robots/common/twoDModel/include/twoDModel/robotModel/twoDRobotModel.h @@ -47,6 +47,7 @@ class TWO_D_MODEL_EXPORT TwoDRobotModel : public kitBase::robotModel::CommonRobo QList configurablePorts() const override; QList convertibleBases() const override; int priority() const override; + void rereadSettings() override; /// Configures 2D model window`s engine for using it in 2D model devices emulators. void setEngine(engine::TwoDModelEngineInterface &engine); @@ -128,6 +129,8 @@ class TWO_D_MODEL_EXPORT TwoDRobotModel : public kitBase::robotModel::CommonRobo /// Returns scanning angle and max distance by given device type. virtual QPair rangeSensorAngleAndDistance (const kitBase::robotModel::DeviceInfo &deviceType) const; +signals: + void settingsChanged(); protected: kitBase::robotModel::robotParts::Device *createDevice( const kitBase::robotModel::PortInfo &port diff --git a/plugins/robots/common/twoDModel/src/engine/view/scene/robotItem.cpp b/plugins/robots/common/twoDModel/src/engine/view/scene/robotItem.cpp index aa5be25cb3..11e682ab0d 100644 --- a/plugins/robots/common/twoDModel/src/engine/view/scene/robotItem.cpp +++ b/plugins/robots/common/twoDModel/src/engine/view/scene/robotItem.cpp @@ -40,6 +40,9 @@ RobotItem::RobotItem(const QString &robotImageFileName, model::RobotModel &robot connect(&mRobotModel.configuration(), &model::SensorsConfiguration::rotationChanged , this, &RobotItem::updateSensorRotation); + connect(&mRobotModel.info(), &twoDModel::robotModel::TwoDRobotModel::settingsChanged + , this, &RobotItem::updateImage); + setAcceptHoverEvents(true); setAcceptDrops(true); setZValue(ZValue::Robot); @@ -324,3 +327,8 @@ void RobotItem::BeepItem::drawBeepArcs(QPainter *painter, const QPointF ¢er, painter->drawArc(rect, 225 * 16, 90 * 16); painter->restore(); } + +void RobotItem::updateImage() +{ + mImage.loadFrom(mRobotModel.info().robotImage()); +} diff --git a/plugins/robots/common/twoDModel/src/engine/view/scene/robotItem.h b/plugins/robots/common/twoDModel/src/engine/view/scene/robotItem.h index f88f9afa79..beb98a5417 100644 --- a/plugins/robots/common/twoDModel/src/engine/view/scene/robotItem.h +++ b/plugins/robots/common/twoDModel/src/engine/view/scene/robotItem.h @@ -102,6 +102,7 @@ class RobotItem : public graphicsUtils::RotateItem, public items::SolidItem void ride(const QPointF &newPos, qreal rotation); void onLanded(); + void updateImage(); /** @brief Image of a robot drawn on scene */ // Use utilitary class that can handle PNG & SVG properly. diff --git a/plugins/robots/common/twoDModel/src/robotModel/twoDRobotModel.cpp b/plugins/robots/common/twoDModel/src/robotModel/twoDRobotModel.cpp index 4328dfc8ed..fd2b31a705 100644 --- a/plugins/robots/common/twoDModel/src/robotModel/twoDRobotModel.cpp +++ b/plugins/robots/common/twoDModel/src/robotModel/twoDRobotModel.cpp @@ -222,3 +222,8 @@ DeviceInfo TwoDRobotModel::markerInfo() const { return DeviceInfo::create(); } + +void TwoDRobotModel::rereadSettings() +{ + emit settingsChanged(); +}