Skip to content

Commit fc324d2

Browse files
committed
Added "Select All" checkbox for fit params
1 parent b080b3f commit fc324d2

1 file changed

Lines changed: 118 additions & 11 deletions

File tree

  • EasyReflectometryApp/Gui/Pages/Analysis/Sidebar/Basic/Groups

EasyReflectometryApp/Gui/Pages/Analysis/Sidebar/Basic/Groups/Fittables.qml

Lines changed: 118 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,18 @@ EaElements.GroupBox {
1818
//title: qsTr("Parameters")
1919
collapsible: false
2020
last: true
21+
readonly property var backend: Globals.BackendWrapper
2122

2223
Column {
2324
id: fittables
2425
property int selectedParamIndex: Globals.BackendWrapper.analysisCurrentParameterIndex
26+
property bool bulkUpdatingSelection: false
27+
property real fitColumnWidth: EaStyle.Sizes.fontPixelSize * 3.0
28+
property alias parameterSlider: slider
2529
onSelectedParamIndexChanged: {
30+
if (bulkUpdatingSelection) {
31+
return
32+
}
2633
updateSliderLimits()
2734
updateSliderValue()
2835
}
@@ -189,7 +196,7 @@ EaElements.GroupBox {
189196
}
190197

191198
EaComponents.TableViewLabel {
192-
width: EaStyle.Sizes.fontPixelSize * 3.0
199+
width: fittables.fitColumnWidth
193200
color: EaStyle.Colors.themeForegroundMinor
194201
text: qsTr("Fit")
195202
}
@@ -302,6 +309,36 @@ EaElements.GroupBox {
302309
}
303310
// Table
304311

312+
Item {
313+
id: fitAllContainer
314+
visible: Globals.BackendWrapper.analysisFitableParameters.length
315+
width: tableView.width
316+
height: EaStyle.Sizes.tableRowHeight
317+
318+
EaComponents.TableViewLabel {
319+
anchors.verticalCenter: parent.verticalCenter
320+
anchors.left: parent.left
321+
anchors.right: fitAllCheckBox.left
322+
anchors.rightMargin: EaStyle.Sizes.fontPixelSize * 0.5
323+
text: qsTr("Select All")
324+
horizontalAlignment: Text.AlignRight
325+
elide: Text.ElideNone
326+
}
327+
328+
EaComponents.TableViewCheckBox {
329+
id: fitAllCheckBox
330+
anchors.verticalCenter: parent.verticalCenter
331+
anchors.left: parent.left
332+
anchors.leftMargin: Math.max(tableView.width - fittables.fitColumnWidth, 0)
333+
enabled: Globals.BackendWrapper.analysisExperimentsAvailable.length &&
334+
Globals.BackendWrapper.analysisFitableParameters.length
335+
checked: allFittablesSelected()
336+
onToggled: {
337+
setAllFittablesFit(checked)
338+
}
339+
}
340+
}
341+
305342
// Parameter change slider
306343
Row {
307344
visible: Globals.BackendWrapper.analysisFitableParameters.length
@@ -357,27 +394,97 @@ EaElements.GroupBox {
357394
}
358395
}
359396
}
397+
360398
// Logic
361399

362400
function updateSliderValue() {
363-
const value = Globals.BackendWrapper.analysisFitableParameters[Globals.BackendWrapper.analysisCurrentParameterIndex].value
364-
slider.value = EaLogic.Utils.toDefaultPrecision(value)
401+
if (!backend.analysisFitableParameters.length) {
402+
return
403+
}
404+
const currentIndex = backend.analysisCurrentParameterIndex
405+
if (currentIndex < 0 || currentIndex >= backend.analysisFitableParameters.length) {
406+
return
407+
}
408+
const value = backend.analysisFitableParameters[currentIndex].value
409+
fittables.parameterSlider.value = EaLogic.Utils.toDefaultPrecision(value)
365410
}
366411

367412
function updateSliderLimits() {
368-
var from = Globals.BackendWrapper.analysisFitableParameters[Globals.BackendWrapper.analysisCurrentParameterIndex].value * 0.9
369-
var to = Globals.BackendWrapper.analysisFitableParameters[Globals.BackendWrapper.analysisCurrentParameterIndex].value * 1.1
413+
if (!backend.analysisFitableParameters.length) {
414+
return
415+
}
416+
const currentIndex = backend.analysisCurrentParameterIndex
417+
if (currentIndex < 0 || currentIndex >= backend.analysisFitableParameters.length) {
418+
return
419+
}
420+
var from = backend.analysisFitableParameters[currentIndex].value * 0.9
421+
var to = backend.analysisFitableParameters[currentIndex].value * 1.1
370422
if (from === 0 && to === 0) {
371423
to = 0.1
372424
}
373-
if (Globals.BackendWrapper.analysisFitableParameters[Globals.BackendWrapper.analysisCurrentParameterIndex].max < to) {
374-
to = Globals.BackendWrapper.analysisFitableParameters[Globals.BackendWrapper.analysisCurrentParameterIndex].max
425+
if (backend.analysisFitableParameters[currentIndex].max < to) {
426+
to = backend.analysisFitableParameters[currentIndex].max
427+
}
428+
if (backend.analysisFitableParameters[currentIndex].min > from) {
429+
from = backend.analysisFitableParameters[currentIndex].min
430+
}
431+
fittables.parameterSlider.from = EaLogic.Utils.toDefaultPrecision(from)
432+
fittables.parameterSlider.to = EaLogic.Utils.toDefaultPrecision(to)
433+
}
434+
435+
function allFittablesSelected() {
436+
const params = backend.analysisFitableParameters
437+
if (!params || !params.length) {
438+
return false
439+
}
440+
for (let i = 0; i < params.length; i++) {
441+
const parameter = params[i]
442+
const independent = parameter.independent !== undefined ? parameter.independent : true
443+
if (!independent) {
444+
continue
445+
}
446+
if (!parameter.fit) {
447+
return false
448+
}
449+
}
450+
return true
451+
}
452+
453+
function setAllFittablesFit(enable) {
454+
const params = backend.analysisFitableParameters
455+
if (!params || !params.length) {
456+
return
375457
}
376-
if (Globals.BackendWrapper.analysisFitableParameters[Globals.BackendWrapper.analysisCurrentParameterIndex].min > from) {
377-
from = Globals.BackendWrapper.analysisFitableParameters[Globals.BackendWrapper.analysisCurrentParameterIndex].min
458+
const originalIndex = backend.analysisCurrentParameterIndex
459+
var hasChanges = false
460+
const targetFit = !!enable
461+
fittables.bulkUpdatingSelection = true
462+
try {
463+
for (let i = 0; i < params.length; i++) {
464+
const parameter = params[i]
465+
const independent = parameter.independent !== undefined ? parameter.independent : true
466+
if (!independent) {
467+
continue
468+
}
469+
if (!!parameter.fit === targetFit) {
470+
continue
471+
}
472+
backend.analysisSetCurrentParameterIndex(i)
473+
backend.analysisSetCurrentParameterFit(targetFit)
474+
hasChanges = true
475+
}
476+
} finally {
477+
const paramsLength = params.length
478+
if (paramsLength) {
479+
const targetIndex = originalIndex >= 0 && originalIndex < paramsLength ? originalIndex : Math.min(Math.max(originalIndex, 0), paramsLength - 1)
480+
backend.analysisSetCurrentParameterIndex(targetIndex)
481+
}
482+
fittables.bulkUpdatingSelection = false
483+
}
484+
if (hasChanges) {
485+
updateSliderLimits()
486+
updateSliderValue()
378487
}
379-
slider.from = EaLogic.Utils.toDefaultPrecision(from)
380-
slider.to = EaLogic.Utils.toDefaultPrecision(to)
381488
}
382489
}
383490

0 commit comments

Comments
 (0)