File indexing completed on 2024-05-19 05:40:50
0001 /*************************************************************************** 0002 * Copyright (C) 2020 by Renaud Guezennec * 0003 * http://www.rolisteam.org/contact * 0004 * * 0005 * This software is free software; you can redistribute it and/or modify * 0006 * it under the terms of the GNU General Public License as published by * 0007 * the Free Software Foundation; either version 2 of the License, or * 0008 * (at your option) any later version. * 0009 * * 0010 * This program is distributed in the hope that it will be useful, * 0011 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 0012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 0013 * GNU General Public License for more details. * 0014 * * 0015 * You should have received a copy of the GNU General Public License * 0016 * along with this program; if not, write to the * 0017 * Free Software Foundation, Inc., * 0018 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 0019 ***************************************************************************/ 0020 #include "updater/vmapitem/ellipsecontrollerupdater.h" 0021 0022 #include <QDebug> 0023 #include <QMetaObject> 0024 #include <QMetaProperty> 0025 #include <QSet> 0026 0027 #include "controller/item_controllers/ellipsecontroller.h" 0028 #include "controller/view_controller/vectorialmapcontroller.h" 0029 #include "network/networkmessagereader.h" 0030 #include "network/networkmessagewriter.h" 0031 #include "worker/convertionhelper.h" 0032 #include "worker/messagehelper.h" 0033 0034 EllipseControllerUpdater::EllipseControllerUpdater(QObject* parent) : VMapItemControllerUpdater(parent) {} 0035 0036 EllipseControllerUpdater::~EllipseControllerUpdater() {} 0037 0038 void EllipseControllerUpdater::addItemController(vmap::VisualItemController* ctrl, bool sendOff) 0039 { 0040 if(nullptr == ctrl) 0041 return; 0042 0043 auto elliCtrl= dynamic_cast<vmap::EllipseController*>(ctrl); 0044 0045 if(nullptr == elliCtrl) 0046 return; 0047 0048 VMapItemControllerUpdater::addItemController(ctrl); 0049 0050 connect(elliCtrl, &vmap::EllipseController::filledChanged, this, 0051 [this, elliCtrl]() { sendOffVMapChanges<bool>(elliCtrl, QStringLiteral("filled")); }); 0052 connect(elliCtrl, &vmap::EllipseController::ryEditionChanged, this, 0053 [this, elliCtrl]() { sendOffVMapChanges<qreal>(elliCtrl, QStringLiteral("ry")); }); 0054 connect(elliCtrl, &vmap::EllipseController::rxEditionChanged, this, 0055 [this, elliCtrl]() { sendOffVMapChanges<qreal>(elliCtrl, QStringLiteral("rx")); }); 0056 connect(elliCtrl, &vmap::EllipseController::penWidthChanged, this, 0057 [this, elliCtrl]() { sendOffVMapChanges<quint16>(elliCtrl, QStringLiteral("penWidth")); }); 0058 0059 if(!ctrl->remote() && sendOff) 0060 connect(elliCtrl, &vmap::EllipseController::initializedChanged, this, 0061 [elliCtrl]() { MessageHelper::sendOffEllispe(elliCtrl, elliCtrl->mapUuid()); }); 0062 } 0063 0064 bool EllipseControllerUpdater::updateItemProperty(NetworkMessageReader* msg, vmap::VisualItemController* ctrl) 0065 { 0066 if(nullptr == msg || nullptr == ctrl) 0067 return false; 0068 0069 // TODO implement save/restore 0070 auto datapos= msg->pos(); 0071 0072 if(VMapItemControllerUpdater::updateItemProperty(msg, ctrl)) 0073 return true; 0074 0075 msg->resetToPos(datapos); 0076 0077 updatingCtrl= ctrl; 0078 0079 auto property= msg->string16(); 0080 0081 QVariant var; 0082 0083 if(property == QStringLiteral("filled")) 0084 { 0085 var= QVariant::fromValue(static_cast<bool>(msg->uint8())); 0086 } 0087 else if(property == QStringLiteral("rx")) 0088 { 0089 var= QVariant::fromValue(msg->real()); 0090 } 0091 else if(property == QStringLiteral("ry")) 0092 { 0093 var= QVariant::fromValue(msg->real()); 0094 } 0095 else if(property == QStringLiteral("penWidth")) 0096 { 0097 var= QVariant::fromValue(msg->int64()); 0098 } 0099 else 0100 { 0101 return false; 0102 } 0103 0104 m_updatingFromNetwork= true; 0105 auto feedback= ctrl->setProperty(property.toLocal8Bit().data(), var); 0106 m_updatingFromNetwork= false; 0107 updatingCtrl= nullptr; 0108 0109 return feedback; 0110 }