Skip to content
Snippets Groups Projects
Commit 459e71c1 authored by Mikhail Svechnikov's avatar Mikhail Svechnikov
Browse files

RectangularDetectorItem: alignment_names_map: swap values and keys

parent 362905fe
No related branches found
No related tags found
1 merge request!1172GUI: rm SelectionDescriptor for detector alignment
......@@ -45,13 +45,13 @@ const double default_detector_width = 20.0;
const double default_detector_height = 20.0;
const double default_detector_distance = 1000.0;
const QMap<QString, RectangularDetector::EDetectorArrangement> alignment_names_map = {
{"Generic", RectangularDetector::GENERIC},
{"Perpendicular to sample x-axis", RectangularDetector::PERPENDICULAR_TO_SAMPLE},
{"Perpendicular to direct beam", RectangularDetector::PERPENDICULAR_TO_DIRECT_BEAM},
{"Perpendicular to reflected beam", RectangularDetector::PERPENDICULAR_TO_REFLECTED_BEAM},
{"Perpendicular to reflected beam (intersection unknown)",
RectangularDetector::PERPENDICULAR_TO_REFLECTED_BEAM_DPOS}};
//! Holds the alignments as expected on the UI (map is sorted by keys)
const QMap<RectangularDetector::EDetectorArrangement, QString> alignment_names_map = {
{RectangularDetector::GENERIC, "Generic"},
{RectangularDetector::PERPENDICULAR_TO_SAMPLE, "Perpendicular to sample x-axis"},
{RectangularDetector::PERPENDICULAR_TO_DIRECT_BEAM, "Perpendicular to direct beam"},
{RectangularDetector::PERPENDICULAR_TO_REFLECTED_BEAM, "Perpendicular to reflected beam"},
{RectangularDetector::PERPENDICULAR_TO_REFLECTED_BEAM_DPOS, "Perpendicular to reflected beam (intersection unknown)"}};
QString alignmentTitle(RectangularDetector::EDetectorArrangement a)
{
......@@ -71,15 +71,6 @@ QString alignmentTitle(RectangularDetector::EDetectorArrangement a)
}
}
//! Returns the alignments as expected on the UI
QList<RectangularDetector::EDetectorArrangement> alignments()
{
return {RectangularDetector::GENERIC, RectangularDetector::PERPENDICULAR_TO_SAMPLE,
RectangularDetector::PERPENDICULAR_TO_DIRECT_BEAM,
RectangularDetector::PERPENDICULAR_TO_REFLECTED_BEAM,
RectangularDetector::PERPENDICULAR_TO_REFLECTED_BEAM_DPOS};
}
void initResolutionFunction(ResolutionFunctionItem* newFunc, const ResolutionFunctionItem*)
{
newFunc->setUnit("mm");
......@@ -116,8 +107,8 @@ RectangularDetectorItem::RectangularDetectorItem()
default_detector_distance, "mm", "distance");
m_detectorAlignment.fromList(
alignment_names_map.keys(),
alignment_names_map.key(RectangularDetector::PERPENDICULAR_TO_DIRECT_BEAM));
alignment_names_map.values(),
alignment_names_map.value(RectangularDetector::PERPENDICULAR_TO_DIRECT_BEAM));
updateTooltips();
}
......@@ -153,21 +144,21 @@ void RectangularDetectorItem::serialize(Streamer& s)
void RectangularDetectorItem::setDetectorAlignment(const QString& alignment)
{
ASSERT(alignment_names_map.keys().contains(alignment));
setDetectorAlignment(alignment_names_map.value(alignment));
ASSERT(alignment_names_map.values().contains(alignment));
setDetectorAlignment(alignment_names_map.key(alignment));
}
void RectangularDetectorItem::setDetectorAlignment(
RectangularDetector::EDetectorArrangement alignment)
{
m_detectorAlignment.setCurrentValue(alignment_names_map.key(alignment));
m_detectorAlignment.setCurrentValue(alignment_names_map.value(alignment));
updateTooltips();
}
RectangularDetector::EDetectorArrangement RectangularDetectorItem::detectorAlignment() const
{
ASSERT(alignment_names_map.keys().contains(m_detectorAlignment.currentValue()));
return alignment_names_map.value(m_detectorAlignment.currentValue());
ASSERT(alignment_names_map.values().contains(m_detectorAlignment.currentValue()));
return alignment_names_map.key(m_detectorAlignment.currentValue());
}
SelectionDescriptor<RectangularDetector::EDetectorArrangement>
......@@ -176,14 +167,14 @@ RectangularDetectorItem::detectorAlignmentSelection() const
SelectionDescriptor<RectangularDetector::EDetectorArrangement> d;
d.label = "Alignment";
for (auto a : alignments())
for (auto a : alignment_names_map.keys())
d.options << alignmentTitle(a);
d.currentIndexSetter = [&](int newIndex) {
const_cast<RectangularDetectorItem*>(this)->setDetectorAlignment(alignments()[newIndex]);
const_cast<RectangularDetectorItem*>(this)->setDetectorAlignment(alignment_names_map.keys()[newIndex]);
};
d.currentIndexGetter = [&]() { return alignments().indexOf(detectorAlignment()); };
d.currentIndexGetter = [&]() { return alignment_names_map.keys().indexOf(detectorAlignment()); };
return d;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment