4 LimitsGroup::LimitsGroup(Firmware
* firmware
, TableLayout
* tableLayout
, int row
, int col
, int & value
, const ModelData
& model
, int min
, int max
, int deflt
):
6 spinbox(new QDoubleSpinBox()),
10 BoardEnum board
= firmware
->getBoard();
11 bool allowGVars
= (IS_TARANIS(board
) || IS_HORUS(board
));
14 spinbox
->setProperty("index", row
);
15 spinbox
->setAlignment(Qt::AlignRight
|Qt::AlignTrailing
|Qt::AlignVCenter
);
16 spinbox
->setAccelerated(true);
18 if (firmware
->getCapability(PPMUnitMicroseconds
)) {
20 spinbox
->setDecimals(1);
21 spinbox
->setSuffix("us");
24 spinbox
->setDecimals(0);
25 spinbox
->setSuffix("%");
28 if (HAS_LARGE_LCD(board
) || deflt
== 0 /*it's the offset*/) {
29 spinbox
->setDecimals(1);
35 spinbox
->setSingleStep(displayStep
*internalStep
);
36 spinbox
->setSizePolicy(QSizePolicy::MinimumExpanding
, QSizePolicy::Fixed
);
38 QHBoxLayout
* horizontalLayout
= new QHBoxLayout();
39 QCheckBox
* gv
= new QCheckBox(QObject::tr("GV"));
40 gv
->setSizePolicy(QSizePolicy::Minimum
, QSizePolicy::Fixed
);
41 horizontalLayout
->addWidget(gv
);
42 QComboBox
* cb
= new QComboBox();
43 cb
->setSizePolicy(QSizePolicy::MinimumExpanding
, QSizePolicy::Fixed
);
44 horizontalLayout
->addWidget(cb
);
45 horizontalLayout
->addWidget(spinbox
);
46 tableLayout
->addLayout(row
, col
, horizontalLayout
);
47 gvarGroup
= new GVarGroup(gv
, spinbox
, cb
, value
, model
, deflt
, min
, max
, displayStep
, allowGVars
);
50 LimitsGroup::~LimitsGroup()
55 void LimitsGroup::updateMinMax(int max
)
57 if (spinbox
->maximum() == 0) {
58 spinbox
->setMinimum(-max
*displayStep
);
63 if (spinbox
->minimum() == 0) {
64 spinbox
->setMaximum(max
*displayStep
);
71 Channels::Channels(QWidget
* parent
, ModelData
& model
, GeneralSettings
& generalSettings
, Firmware
* firmware
):
72 ModelPanel(parent
, model
, generalSettings
, firmware
)
74 Stopwatch
s1("Channels");
76 int channelNameMaxLen
= firmware
->getCapability(ChannelsName
);
78 QStringList headerLabels
;
80 if (channelNameMaxLen
> 0) {
81 headerLabels
<< tr("Name");
83 headerLabels
<< tr("Subtrim") << tr("Min") << tr("Max") << tr("Direction");
84 if (IS_TARANIS(GetEepromInterface()->getBoard()))
85 headerLabels
<< tr("Curve");
86 if (firmware
->getCapability(PPMCenter
))
87 headerLabels
<< tr("PPM Center");
88 if (firmware
->getCapability(SYMLimits
))
89 headerLabels
<< tr("Linear Subtrim");
90 TableLayout
* tableLayout
= new TableLayout(this, firmware
->getCapability(LogicalSwitches
), headerLabels
);
94 for (int i
=0; i
<firmware
->getCapability(Outputs
); i
++) {
98 QLabel
*label
= new QLabel(this);
99 label
->setText(tr("CH%1").arg(i
+1));
100 label
->setSizePolicy(QSizePolicy::Fixed
, QSizePolicy::Minimum
);
101 tableLayout
->addWidget(i
, col
++, label
);
104 if (channelNameMaxLen
> 0) {
105 QLineEdit
* name
= new QLineEdit(this);
106 name
->setProperty("index", i
);
107 name
->setMaxLength(channelNameMaxLen
);
108 QRegExp
rx(CHAR_FOR_NAMES_REGEX
);
109 name
->setValidator(new QRegExpValidator(rx
, this));
110 name
->setText(model
.limitData
[i
].name
);
111 connect(name
, SIGNAL(editingFinished()), this, SLOT(nameEdited()));
112 tableLayout
->addWidget(i
, col
++, name
);
116 limitsGroups
<< new LimitsGroup(firmware
, tableLayout
, i
, col
++, model
.limitData
[i
].offset
, model
, -1000, 1000, 0);
119 limitsGroups
<< new LimitsGroup(firmware
, tableLayout
, i
, col
++, model
.limitData
[i
].min
, model
, -model
.getChannelsMax()*10, 0, -1000);
122 limitsGroups
<< new LimitsGroup(firmware
, tableLayout
, i
, col
++, model
.limitData
[i
].max
, model
, 0, model
.getChannelsMax()*10, 1000);
125 QComboBox
* invCB
= new QComboBox(this);
126 invCB
->insertItems(0, QStringList() << tr("---") << tr("INV"));
127 invCB
->setProperty("index", i
);
128 invCB
->setCurrentIndex((model
.limitData
[i
].revert
) ? 1 : 0);
129 connect(invCB
, SIGNAL(currentIndexChanged(int)), this, SLOT(invEdited()));
130 tableLayout
->addWidget(i
, col
++, invCB
);
133 if (IS_TARANIS(GetEepromInterface()->getBoard())) {
134 QComboBox
* curveCB
= new QComboBox(this);
135 curveCB
->setProperty("index", i
);
136 int numcurves
= firmware
->getCapability(NumCurves
);
137 for (int j
=-numcurves
; j
<=numcurves
; j
++) {
138 curveCB
->addItem(CurveReference(CurveReference::CURVE_REF_CUSTOM
, j
).toString(), j
);
140 curveCB
->setCurrentIndex(model
.limitData
[i
].curve
.value
+numcurves
);
141 connect(curveCB
, SIGNAL(currentIndexChanged(int)), this, SLOT(curveEdited()));
142 tableLayout
->addWidget(i
, col
++, curveCB
);
146 int ppmCenterMax
= firmware
->getCapability(PPMCenter
);
148 QSpinBox
* center
= new QSpinBox(this);
149 center
->setProperty("index", i
);
150 center
->setAlignment(Qt::AlignRight
|Qt::AlignTrailing
|Qt::AlignVCenter
);
151 center
->setSuffix("us");
152 center
->setMinimum(1500-ppmCenterMax
);
153 center
->setMaximum(1500+ppmCenterMax
);
154 center
->setValue(1500);
155 center
->setValue(model
.limitData
[i
].ppmCenter
+ 1500);
156 connect(center
, SIGNAL(editingFinished()), this, SLOT(ppmcenterEdited()));
157 tableLayout
->addWidget(i
, col
++, center
);
161 if (firmware
->getCapability(SYMLimits
)) {
162 QCheckBox
* symlimits
= new QCheckBox(this);
163 symlimits
->setProperty("index", i
);
164 symlimits
->setChecked(model
.limitData
[i
].symetrical
);
165 connect(symlimits
, SIGNAL(toggled(bool)), this, SLOT(symlimitsEdited()));
166 tableLayout
->addWidget(i
, col
++, symlimits
);
169 s1
.report("add elements");
171 disableMouseScrolling();
172 tableLayout
->resizeColumnsToContents();
173 tableLayout
->pushRowsUp(firmware
->getCapability(Outputs
)+1);
177 Channels::~Channels()
179 foreach(LimitsGroup
*group
, limitsGroups
) {
184 void Channels::symlimitsEdited()
186 QCheckBox
* ckb
= qobject_cast
<QCheckBox
*>(sender());
187 int index
= ckb
->property("index").toInt();
188 model
->limitData
[index
].symetrical
= (ckb
->checkState() ? 1 : 0);
192 void Channels::nameEdited()
195 QLineEdit
*le
= qobject_cast
<QLineEdit
*>(sender());
196 int index
= le
->property("index").toInt();
197 strcpy(model
->limitData
[index
].name
, le
->text().toLatin1());
202 void Channels::refreshExtendedLimits()
204 int channelMax
= model
->getChannelsMax();
206 foreach(LimitsGroup
*group
, limitsGroups
) {
207 group
->updateMinMax(10*channelMax
);
213 void Channels::invEdited()
215 QComboBox
*cb
= qobject_cast
<QComboBox
*>(sender());
216 int index
= cb
->property("index").toInt();
217 model
->limitData
[index
].revert
= cb
->currentIndex();
221 void Channels::curveEdited()
223 QComboBox
*cb
= qobject_cast
<QComboBox
*>(sender());
224 int index
= cb
->property("index").toInt();
225 model
->limitData
[index
].curve
= CurveReference(CurveReference::CURVE_REF_CUSTOM
, cb
->itemData(cb
->currentIndex()).toInt());
229 void Channels::ppmcenterEdited()
231 QSpinBox
*sb
= qobject_cast
<QSpinBox
*>(sender());
232 int index
= sb
->property("index").toInt();
233 model
->limitData
[index
].ppmCenter
= sb
->value() - 1500;