Merge pull request #7939 from elecpower/cpn_data_models
Companion refactor of ui datamodels
This commit is contained in:
@@ -36,6 +36,15 @@ class CurveReference {
|
||||
CURVE_REF_CUSTOM
|
||||
};
|
||||
|
||||
enum CurveRefGroups {
|
||||
NoneGroup = 0x001,
|
||||
NegativeGroup = 0x002,
|
||||
PositiveGroup = 0x004,
|
||||
|
||||
AllCurveRefGroups = NoneGroup | NegativeGroup | PositiveGroup,
|
||||
PositiveCurveRefGroups = AllCurveRefGroups &~ NegativeGroup
|
||||
};
|
||||
|
||||
CurveReference() { clear(); }
|
||||
|
||||
CurveReference(CurveRefType type, int value):
|
||||
@@ -51,6 +60,14 @@ class CurveReference {
|
||||
|
||||
QString toString(const ModelData * model = NULL, bool verbose = true) const;
|
||||
bool isSet() const { return type != CURVE_REF_DIFF || value != 0; }
|
||||
|
||||
bool operator == ( const CurveReference & other) const {
|
||||
return (this->type == other.type) && (this->value == other.value);
|
||||
}
|
||||
|
||||
bool operator != ( const CurveReference & other) const {
|
||||
return (this->type != other.type) || (this->value != other.value);
|
||||
}
|
||||
};
|
||||
|
||||
#endif // CURVEREFERENCE_H
|
||||
|
||||
@@ -126,20 +126,15 @@ void CustomFunctionData::populateResetParams(const ModelData * model, QComboBox
|
||||
b->addItem(tr("REa"), val++);
|
||||
b->addItem(tr("REb"), val++);
|
||||
}
|
||||
if ((int)value < b->count()) {
|
||||
b->setCurrentIndex(value);
|
||||
}
|
||||
if (model) {
|
||||
for (unsigned i=0; i<CPN_MAX_SENSORS; ++i) {
|
||||
for (int i = 0; i < firmware->getCapability(Sensors); ++i) {
|
||||
if (model->sensorData[i].isAvailable()) {
|
||||
RawSource item = RawSource(SOURCE_TYPE_TELEMETRY, 3*i);
|
||||
b->addItem(item.toString(model), val+i);
|
||||
if (value == val+i) {
|
||||
b->setCurrentIndex(b->count()-1);
|
||||
}
|
||||
RawSource item = RawSource(SOURCE_TYPE_TELEMETRY, 3 * i);
|
||||
b->addItem(item.toString(model), val + i);
|
||||
}
|
||||
}
|
||||
}
|
||||
b->setCurrentIndex(b->findData(value));
|
||||
}
|
||||
|
||||
void CustomFunctionData::populatePlaySoundParams(QStringList & qs)
|
||||
|
||||
@@ -723,11 +723,15 @@ int ModelData::updateReference()
|
||||
updateAssignFunc(cfd);
|
||||
if (!cfd->isEmpty()) {
|
||||
updateSwitchRef(cfd->swtch);
|
||||
if (cfd->func == FuncVolume || cfd->func == FuncBacklight || cfd->func == FuncPlayValue || (cfd->func >= FuncAdjustGV1 && cfd->func <= FuncAdjustGVLast && (cfd->adjustMode == FUNC_ADJUST_GVAR_GVAR || cfd->adjustMode == FUNC_ADJUST_GVAR_SOURCE))) {
|
||||
if (cfd->func == FuncVolume || cfd->func == FuncBacklight || cfd->func == FuncPlayValue ||
|
||||
(cfd->func >= FuncAdjustGV1 && cfd->func <= FuncAdjustGVLast && (cfd->adjustMode == FUNC_ADJUST_GVAR_GVAR || cfd->adjustMode == FUNC_ADJUST_GVAR_SOURCE))) {
|
||||
updateSourceIntRef(cfd->param);
|
||||
if (cfd->param == 0)
|
||||
cfd->clear();
|
||||
}
|
||||
else if (cfd->func == FuncReset) {
|
||||
updateResetParam(cfd);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -847,7 +851,7 @@ void ModelData::updateTypeIndexRef(R & curRef, const T type, const int idxAdj, c
|
||||
newRef.clear();
|
||||
else {
|
||||
newRef.type = (T)defType;
|
||||
newRef.index = defIndex + idxAdj;
|
||||
newRef.index = defIndex;
|
||||
}
|
||||
break;
|
||||
case REF_UPD_ACT_SHIFT:
|
||||
@@ -904,7 +908,7 @@ void ModelData::updateTypeValueRef(R & curRef, const T type, const int idxAdj, c
|
||||
newRef.clear();
|
||||
else {
|
||||
newRef.type = (T)defType;
|
||||
newRef.value = defValue + idxAdj;
|
||||
newRef.value = defValue;
|
||||
}
|
||||
break;
|
||||
case REF_UPD_ACT_SHIFT:
|
||||
@@ -972,7 +976,7 @@ void ModelData::updateAssignFunc(CustomFunctionData * cfd)
|
||||
{
|
||||
const int invalidateRef = -1;
|
||||
int newRef = (int)cfd->func;
|
||||
int idxAdj;
|
||||
int idxAdj = 0;
|
||||
|
||||
switch (updRefInfo.type)
|
||||
{
|
||||
@@ -1374,3 +1378,64 @@ void ModelData::sortMixes()
|
||||
|
||||
memcpy(&mixData[0], &sortedMixData[0], CPN_MAX_MIXERS * sizeof(MixData));
|
||||
}
|
||||
|
||||
void ModelData::updateResetParam(CustomFunctionData * cfd)
|
||||
{
|
||||
|
||||
if (cfd->func != FuncReset)
|
||||
return;
|
||||
|
||||
const int invalidateRef = -1;
|
||||
int newRef = cfd->param;
|
||||
int idxAdj = 0;
|
||||
Firmware *firmware = getCurrentFirmware();
|
||||
|
||||
switch (updRefInfo.type)
|
||||
{
|
||||
case REF_UPD_TYPE_SENSOR:
|
||||
idxAdj = 5/*3 Timers + Flight + Telemetery*/ + firmware->getCapability(RotaryEncoders);
|
||||
if (cfd->param < idxAdj || cfd->param > (idxAdj + firmware->getCapability(Sensors)))
|
||||
return;
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
switch (updRefInfo.action)
|
||||
{
|
||||
case REF_UPD_ACT_CLEAR:
|
||||
if (newRef != (updRefInfo.index1 + idxAdj))
|
||||
return;
|
||||
newRef = invalidateRef;
|
||||
break;
|
||||
case REF_UPD_ACT_SHIFT:
|
||||
if (newRef < (updRefInfo.index1 + idxAdj))
|
||||
return;
|
||||
|
||||
newRef += updRefInfo.shift;
|
||||
|
||||
if (newRef < (updRefInfo.index1 + idxAdj) || newRef > (updRefInfo.maxindex + idxAdj))
|
||||
newRef = invalidateRef;
|
||||
break;
|
||||
case REF_UPD_ACT_SWAP:
|
||||
if (newRef == updRefInfo.index1 + idxAdj)
|
||||
newRef = updRefInfo.index2 + idxAdj;
|
||||
else if (newRef == updRefInfo.index2 + idxAdj)
|
||||
newRef = updRefInfo.index1 + idxAdj;
|
||||
break;
|
||||
default:
|
||||
qDebug() << "Error - unhandled action:" << updRefInfo.action;
|
||||
return;
|
||||
}
|
||||
|
||||
if (newRef == invalidateRef) {
|
||||
cfd->clear();
|
||||
//qDebug() << "Function cleared";
|
||||
updRefInfo.updcnt++;
|
||||
}
|
||||
else if (cfd->param != newRef) {
|
||||
//qDebug() << "Updated reference:" << cfd->param << " -> " << newRef;
|
||||
cfd->param = newRef;
|
||||
updRefInfo.updcnt++;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -338,6 +338,7 @@ class ModelData {
|
||||
value = swtch.toValue();
|
||||
}
|
||||
void sortMixes();
|
||||
void updateResetParam(CustomFunctionData * cfd);
|
||||
};
|
||||
|
||||
#endif // MODELDATA_H
|
||||
|
||||
@@ -59,7 +59,7 @@ QString RawSwitch::toString(Board::Type board, const GeneralSettings * const gen
|
||||
tr("THs"), tr("TH%"), tr("THt")
|
||||
};
|
||||
|
||||
const QStringList directionIndicators = QStringList()
|
||||
static const QStringList directionIndicators = QStringList()
|
||||
<< CPN_STR_SW_INDICATOR_UP
|
||||
<< CPN_STR_SW_INDICATOR_NEUT
|
||||
<< CPN_STR_SW_INDICATOR_DN;
|
||||
|
||||
Reference in New Issue
Block a user