RCToParamDialogController.cc 2.28 KB
Newer Older
DoinLakeFlyer's avatar
DoinLakeFlyer committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
/****************************************************************************
 *
 * (c) 2009-2020 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
 *
 * QGroundControl is licensed according to the terms in the file
 * COPYING.md in the root of the source code directory.
 *
 ****************************************************************************/

#include "RCToParamDialogController.h"
#include "QGCApplication.h"
#include "ParameterManager.h"

const char*  RCToParamDialogController::_scaleFactName =    "Scale";
const char*  RCToParamDialogController::_centerFactName =   "CenterValue";
const char*  RCToParamDialogController::_minFactName =      "MinValue";
const char*  RCToParamDialogController::_maxFactName =      "MaxValue";

QMap<QString, FactMetaData*> RCToParamDialogController::_metaDataMap;

RCToParamDialogController::RCToParamDialogController(void)
    : _scaleFact    (0, _scaleFactName,     FactMetaData::valueTypeDouble)
    , _centerFact   (0, _centerFactName,    FactMetaData::valueTypeDouble)
    , _minFact      (0, _minFactName,       FactMetaData::valueTypeDouble)
    , _maxFact      (0, _maxFactName,       FactMetaData::valueTypeDouble)
{
    if (_metaDataMap.isEmpty()) {
        _metaDataMap = FactMetaData::createMapFromJsonFile(QStringLiteral(":/json/RCToParamDialog.FactMetaData.json"), nullptr /* QObject parent */);
    }

    _scaleFact.setMetaData  (_metaDataMap[_scaleFactName],  true /* setDefaultFromMetaData */);
    _centerFact.setMetaData (_metaDataMap[_centerFactName]);
    _minFact.setMetaData    (_metaDataMap[_minFactName]);
    _maxFact.setMetaData    (_metaDataMap[_maxFactName]);
}

void RCToParamDialogController::setTuningFact(Fact* tuningFact)
{
    _tuningFact = tuningFact;
    emit tuningFactChanged(tuningFact);

    _centerFact.setRawValue(_tuningFact->rawValue().toDouble());
    _minFact.setRawValue(_tuningFact->rawMin().toDouble());
    _maxFact.setRawValue(_tuningFact->rawMax().toDouble());

    connect(_tuningFact, &Fact::vehicleUpdated, this, &RCToParamDialogController::_parameterUpdated);
    qgcApp()->toolbox()->multiVehicleManager()->activeVehicle()->parameterManager()->refreshParameter(FactSystem::defaultComponentId, _tuningFact->name());
}

void RCToParamDialogController::_parameterUpdated(void)
{
    _ready = true;
    emit readyChanged(true);
}