diff --git a/GUI/Model/Data/DataItem.cpp b/GUI/Model/Data/DataItem.cpp index e05dec9263caac503012f48df41f69036ef1d489..475e830c880f3ba500032ab466ffb205230f342b 100644 --- a/GUI/Model/Data/DataItem.cpp +++ b/GUI/Model/Data/DataItem.cpp @@ -105,11 +105,6 @@ void DataItem::setLastModified(const QDateTime& dtime) m_last_modified = dtime; } -QString DataItem::selectedAxesUnits() const -{ - return getItemValue(P_AXES_UNITS).value<ComboProperty>().currentValue(); -} - int DataItem::xSize() const { return xAxisItem()->binCount(); @@ -186,28 +181,27 @@ void DataItem::copyXYRangesFromItem(DataItem* sourceItem) copyYRangeFromItem(sourceItem); } -ComboProperty DataItem::axesUnitsCombo() const +QString DataItem::currentAxesUnits() const { - return getItemValue(P_AXES_UNITS).value<ComboProperty>(); + return axesUnitsCombo().currentValue(); } -void DataItem::setAxesUnits(const ComboProperty& units) +void DataItem::setCurrentAxesUnits(const QString& units) { - setItemValue(P_AXES_UNITS, units.variant()); - emit axesUnitsChanged(this); + ComboProperty combo = axesUnitsCombo(); + combo.setCurrentValue(units); + setAxesUnitsCombo(combo); } -SelectionDescriptor<QString> DataItem::axesUnits() const +ComboProperty DataItem::axesUnitsCombo() const +{ + return getItemValue(P_AXES_UNITS).value<ComboProperty>(); +} + +void DataItem::setAxesUnitsCombo(const ComboProperty& unitsCombo) { - SelectionDescriptor<QString> d(getItem(P_AXES_UNITS)); - d.currentIndexSetter = [=](int index) { - ComboProperty units = axesUnitsCombo(); - if (units.currentIndex() != index) { - units.setCurrentIndex(index); - const_cast<DataItem*>(this)->setAxesUnits(units); - } - }; - return d; + setItemValue(P_AXES_UNITS, unitsCombo.variant()); + emit axesUnitsChanged(this); } const BasicAxisItem* DataItem::xAxisItem() const diff --git a/GUI/Model/Data/DataItem.h b/GUI/Model/Data/DataItem.h index 648636859ce9dc4723f85c8436f33e98c1a04178..a94bacc40b5108682093f47e21a6f730e633d65a 100644 --- a/GUI/Model/Data/DataItem.h +++ b/GUI/Model/Data/DataItem.h @@ -96,10 +96,10 @@ public: void copyXYRangesFromItem(DataItem* sourceItem); // Axes units + QString currentAxesUnits() const; + void setCurrentAxesUnits(const QString& units); ComboProperty axesUnitsCombo() const; - void setAxesUnits(const ComboProperty& units); - SelectionDescriptor<QString> axesUnits() const; - QString selectedAxesUnits() const; + void setAxesUnitsCombo(const ComboProperty& unitsCombo); //! Updates data on the change of axes units virtual void updateCoords(const InstrumentItem* instrument) = 0; diff --git a/GUI/Model/Data/IntensityDataItem.cpp b/GUI/Model/Data/IntensityDataItem.cpp index f6bd0d0e97e39c99e569cf3fe50766268902ed38..3ba252bbac1efadfafcde48fafd4aa2da7689087 100644 --- a/GUI/Model/Data/IntensityDataItem.cpp +++ b/GUI/Model/Data/IntensityDataItem.cpp @@ -134,9 +134,21 @@ void IntensityDataItem::copyZRangeFromItem(DataItem* sourceItem) setUpperZ(source->upperZ()); } -QCPColorGradient IntensityDataItem::gradientQCP() const +QCPColorGradient IntensityDataItem::currentGradientQCP() const { - return gradient_map.value(gradientCombo().currentValue()); + return gradient_map.value(currentGradient()); +} + +QString IntensityDataItem::currentGradient() const +{ + return gradientCombo().currentValue(); +} + +void IntensityDataItem::setCurrentGradient(const QString& gradient) +{ + ComboProperty combo = gradientCombo(); + combo.setCurrentValue(gradient); + setGradientCombo(combo); } ComboProperty IntensityDataItem::gradientCombo() const @@ -144,25 +156,12 @@ ComboProperty IntensityDataItem::gradientCombo() const return getItemValue(P_GRADIENT).value<ComboProperty>(); } -void IntensityDataItem::setGradient(const ComboProperty& gradient) +void IntensityDataItem::setGradientCombo(const ComboProperty& gradient) { setItemValue(P_GRADIENT, gradient.variant()); emit gradientChanged(); } -SelectionDescriptor<QString> IntensityDataItem::gradient() const -{ - SelectionDescriptor<QString> d(getItem(P_GRADIENT)); - d.currentIndexSetter = [=](int index) { - ComboProperty combo = gradientCombo(); - if (combo.currentIndex() != index) { - combo.setCurrentIndex(index); - const_cast<IntensityDataItem*>(this)->setGradient(combo); - } - }; - return d; -} - bool IntensityDataItem::isLog() const { return zAxisItem()->isLogScale(); @@ -213,7 +212,7 @@ void IntensityDataItem::reset(ImportDataInfo data) { ASSERT(data.unitsLabel() == "nbins"); ComboProperty combo = ComboProperty() << data.unitsLabel(); - setAxesUnits(combo); + setAxesUnitsCombo(combo); setXaxisTitle(data.axisLabel(0)); setYaxisTitle(data.axisLabel(1)); MaskUnitsConverter converter; diff --git a/GUI/Model/Data/IntensityDataItem.h b/GUI/Model/Data/IntensityDataItem.h index 3709aafafe182ba25c55933b715ebe3af4752a2d..0346416b976c904dcd109a09bdcb456a3e3b323e 100644 --- a/GUI/Model/Data/IntensityDataItem.h +++ b/GUI/Model/Data/IntensityDataItem.h @@ -64,11 +64,12 @@ public: void setLowerAndUpperZ(double zmin, double zmax); void copyZRangeFromItem(DataItem* sourceItem); - // Color scheme of the color map - QCPColorGradient gradientQCP() const; + //! Color scheme of the color map + QCPColorGradient currentGradientQCP() const; + QString currentGradient() const; + void setCurrentGradient(const QString& gradient); ComboProperty gradientCombo() const; - void setGradient(const ComboProperty& gradient); - SelectionDescriptor<QString> gradient() const; + void setGradientCombo(const ComboProperty& gradient); // Logarithmic Z scale bool isLog() const; diff --git a/GUI/Model/Data/JobItemUtils.cpp b/GUI/Model/Data/JobItemUtils.cpp index 10d6f531222895de5c26a5c8af29a94d32c9516d..562d4c6d0097bcdf4b400a2ef64d3b3130868410 100644 --- a/GUI/Model/Data/JobItemUtils.cpp +++ b/GUI/Model/Data/JobItemUtils.cpp @@ -49,7 +49,7 @@ void GUI::Model::JobItemUtils::updateDataAxes(DataItem* dataItem, if (!dataItem->getDatafield()) return; - Coords axes_units = GUI::Util::CoordName::coordFromName(dataItem->selectedAxesUnits()); + Coords axes_units = GUI::Util::CoordName::coordFromName(dataItem->currentAxesUnits()); auto* const converter = instrumentItem->createCoordSystem(); @@ -77,7 +77,7 @@ void GUI::Model::JobItemUtils::setIntensityItemCoords(DataItem* intensityItem, const ICoordSystem& converter) { ComboProperty combo = availableUnits(converter); - intensityItem->setAxesUnits(combo); + intensityItem->setAxesUnitsCombo(combo); } void GUI::Model::JobItemUtils::createDefaultDetectorMap(DataItem* intensityItem, @@ -97,7 +97,7 @@ void GUI::Model::JobItemUtils::setResults(DataItem* intensityItem, const Simulat GUI::Model::JobItemUtils::setIntensityItemCoords(intensityItem, converter); updateAxesTitle(intensityItem, converter, converter.defaultUnits()); } - auto selected_units = GUI::Util::CoordName::coordFromName(intensityItem->selectedAxesUnits()); + auto selected_units = GUI::Util::CoordName::coordFromName(intensityItem->currentAxesUnits()); intensityItem->setDatafield(result.datafield(selected_units)); } diff --git a/GUI/Model/Data/SpecularDataItem.cpp b/GUI/Model/Data/SpecularDataItem.cpp index 68bad88eb2b54555da78aadcf701db39c6359925..75c5eb7d3047d839d67413c2afce93f2566b02d8 100644 --- a/GUI/Model/Data/SpecularDataItem.cpp +++ b/GUI/Model/Data/SpecularDataItem.cpp @@ -126,7 +126,7 @@ std::vector<int> SpecularDataItem::shape() const void SpecularDataItem::reset(ImportDataInfo data) { ComboProperty combo = ComboProperty() << data.unitsLabel(); - setAxesUnits(combo); + setAxesUnitsCombo(combo); setXaxisTitle(data.axisLabel(0)); setYaxisTitle(data.axisLabel(1)); setDatafield(std::move(data).intensityData().release()); diff --git a/GUI/Model/Device/AxesItems.cpp b/GUI/Model/Device/AxesItems.cpp index 554b5144ab485da5bc6a4b46411f7053d5e6e29f..694eb0b6116777c9b76d666f0c36005984cead92 100644 --- a/GUI/Model/Device/AxesItems.cpp +++ b/GUI/Model/Device/AxesItems.cpp @@ -38,14 +38,9 @@ SessionItem* BasicAxisItem::binsItem() const return getItem(P_NBINS); } -DoubleDescriptor BasicAxisItem::min(const QString& unit) const +double BasicAxisItem::min() const { - DoubleDescriptor d(getItem(P_MIN_DEG), unit); - d.label = "Min"; - d.set = [=](double v) { - const_cast<BasicAxisItem*>(this)->setMin(v); - }; - return d; + return getItemValue(P_MIN_DEG).toDouble(); } void BasicAxisItem::setMin(double value) @@ -59,14 +54,9 @@ SessionItem* BasicAxisItem::minItem() const return getItem(P_MIN_DEG); } -DoubleDescriptor BasicAxisItem::max(const QString& unit) const +double BasicAxisItem::max() const { - DoubleDescriptor d(getItem(P_MAX_DEG), unit); - d.label = "Max"; - d.set = [=](double v) { - const_cast<BasicAxisItem*>(this)->setMax(v); - }; - return d; + return getItemValue(P_MAX_DEG).toDouble(); } void BasicAxisItem::setMax(double value) diff --git a/GUI/Model/Device/AxesItems.h b/GUI/Model/Device/AxesItems.h index 422438376f670c7f5ce90eb1cfdb2ea4881cd041..78265a0d7cf905c5651fd7aa476e881a01a66722 100644 --- a/GUI/Model/Device/AxesItems.h +++ b/GUI/Model/Device/AxesItems.h @@ -44,11 +44,11 @@ public: void setBinCount(size_t value); SessionItem* binsItem() const; - DoubleDescriptor min(const QString& unit = QString()) const; + double min() const; void setMin(double value); SessionItem* minItem() const; - DoubleDescriptor max(const QString& unit = QString()) const; + double max() const; void setMax(double value); SessionItem* maxItem() const; diff --git a/GUI/Model/Job/JobItem.cpp b/GUI/Model/Job/JobItem.cpp index 45a476e51b907e17df25c85e424ea8f269c39943..768b37164204823c81359bb0155290147458f910 100644 --- a/GUI/Model/Job/JobItem.cpp +++ b/GUI/Model/Job/JobItem.cpp @@ -319,7 +319,7 @@ RealDataItem* JobItem::copyRealDataIntoJob(const RealDataItem* real_data) real_data->copyTo(m_realDataItem.get()); if (!isSpecularJob()) { - m_realDataItem->intensityDataItem()->setGradient(intensityDataItem()->gradientCombo()); + m_realDataItem->intensityDataItem()->setGradientCombo(intensityDataItem()->gradientCombo()); } else { // TODO temporary m_realDataItem->specularDataItem()->setScatter(QCPScatterStyle::ScatterShape::ssDisc); diff --git a/GUI/Model/Model/JobFunctions.cpp b/GUI/Model/Model/JobFunctions.cpp index 3d2057dd79bf0d654a49609f3a284c7c00557358..8e49549554167a4b6781b3da94b04689dc9ff04d 100644 --- a/GUI/Model/Model/JobFunctions.cpp +++ b/GUI/Model/Model/JobFunctions.cpp @@ -113,7 +113,7 @@ void GUI::Model::JobFunctions::initDataView(JobItem* job_item) // by setting new value of P_AXES_UNITS. auto* converter = job_item->instrumentItem()->createCoordSystem(); - view_item->setAxesUnits(GUI::Model::JobItemUtils::availableUnits(*converter)); + view_item->setAxesUnitsCombo(GUI::Model::JobItemUtils::availableUnits(*converter)); } */ diff --git a/GUI/Util/ComboProperty.cpp b/GUI/Util/ComboProperty.cpp index 43fe45088b1b00da5e0227abfc0d6d426f73a4af..3acaec228c7a6bc3581f879820e1a2526123336c 100644 --- a/GUI/Util/ComboProperty.cpp +++ b/GUI/Util/ComboProperty.cpp @@ -69,6 +69,7 @@ void ComboProperty::setValues(const QStringList& values) setCurrentIndex(m_values.contains(current) ? m_values.indexOf(current) : 0); } +//! Returns common tool tip for combo QString ComboProperty::toolTip() const { return m_tooltip; diff --git a/GUI/View/Common/DataAccessWidget.cpp b/GUI/View/Common/DataAccessWidget.cpp index 0bfcd59619555df8d3f62d2cd4d3de4bc8093ebb..7dd524cd44987fb0856465ed375e9eaf83bef640 100644 --- a/GUI/View/Common/DataAccessWidget.cpp +++ b/GUI/View/Common/DataAccessWidget.cpp @@ -93,21 +93,11 @@ QList<SpecularDataItem*> DataAccessWidget::mainSpecularDataItems() const return mainDataItems<SpecularDataItem>(); } -QList<SpecularDataItem*> DataAccessWidget::otherMainSpecularDataItems() const -{ - return otherMainDataItems<SpecularDataItem>(); -} - QList<SpecularDataItem*> DataAccessWidget::allSpecularDataItems() const { return allDataItems<SpecularDataItem>(); } -QList<SpecularDataItem*> DataAccessWidget::otherAllSpecularDataItems() const -{ - return otherAllDataItems<SpecularDataItem>(); -} - SpecularDataItem* DataAccessWidget::currentSpecularDataItem() const { ASSERT(allSpecularDataItems().first()); @@ -121,13 +111,6 @@ QList<IntensityDataItem*> DataAccessWidget::mainIntensityDataItems() const return mainDataItems<IntensityDataItem>(); } -QList<IntensityDataItem*> DataAccessWidget::otherMainIntensityDataItems() const -{ - if(m_fftItem) - return {}; - return otherMainDataItems<IntensityDataItem>(); -} - QList<IntensityDataItem*> DataAccessWidget::allIntensityDataItems() const { if(m_fftItem) @@ -135,13 +118,6 @@ QList<IntensityDataItem*> DataAccessWidget::allIntensityDataItems() const return allDataItems<IntensityDataItem>(); } -QList<IntensityDataItem*> DataAccessWidget::otherAllIntensityDataItems() const -{ - if(m_fftItem) - return {}; - return otherAllDataItems<IntensityDataItem>(); -} - IntensityDataItem* DataAccessWidget::currentIntensityDataItem() const { ASSERT(allIntensityDataItems().first()); diff --git a/GUI/View/Common/DataAccessWidget.h b/GUI/View/Common/DataAccessWidget.h index bd4530f0636c2c69da0a079dccd52bf17102dc46..2d897427a4ea5ec77f125477a86c644f36658fe0 100644 --- a/GUI/View/Common/DataAccessWidget.h +++ b/GUI/View/Common/DataAccessWidget.h @@ -73,15 +73,9 @@ public: //! Simulated + real specular data as list, non-nullptr items QList<SpecularDataItem*> mainSpecularDataItems() const; - //! mainSpecularDataItems() without first element - QList<SpecularDataItem*> otherMainSpecularDataItems() const; - //! Simulated + real + difference specular data as list, non-nullptr items QList<SpecularDataItem*> allSpecularDataItems() const; - //! allSpecularDataItems() without first element - QList<SpecularDataItem*> otherAllSpecularDataItems() const; - //! first element of allSpecularDataItems() with nullptr check SpecularDataItem* currentSpecularDataItem() const; @@ -90,9 +84,6 @@ public: //! Simulated + real intensity data as list, non-nullptr items QList<IntensityDataItem*> mainIntensityDataItems() const; - //! mainIntensityDataItems() without first element - QList<IntensityDataItem*> otherMainIntensityDataItems() const; - //! Simulated + real + difference intensity data as list, non-nullptr items QList<IntensityDataItem*> allIntensityDataItems() const; @@ -124,14 +115,6 @@ private: template <class T> QList<T*> allDataItems() const; - // allDataItems() without first element - template <class T> - QList<T*> otherAllDataItems() const; - - // mainDataItems() without first element - template <class T> - QList<T*> otherMainDataItems() const; - JobRealBase* m_item; IntensityDataItem* m_fftItem; }; @@ -196,20 +179,4 @@ QList<T*> DataAccessWidget::allDataItems() const return mainDataItems<T>() + diffDataItems<T>(); } -template <class T> -QList<T*> DataAccessWidget::otherAllDataItems() const -{ - QList<T*> output = allDataItems<T>(); - output.removeFirst(); - return output; -} - -template <class T> -QList<T*> DataAccessWidget::otherMainDataItems() const -{ - QList<T*> output = mainDataItems<T>(); - output.removeFirst(); - return output; -} - #endif // BORNAGAIN_GUI_VIEW_COMMON_DATAACCESSWIDGET_H diff --git a/GUI/View/Loaders/QREDataLoader.cpp b/GUI/View/Loaders/QREDataLoader.cpp index 85c50141f2d68963f695034f8be1615fa47ebf29..041ef9598fb89a4110221efabd64d3aa8913d8bd 100644 --- a/GUI/View/Loaders/QREDataLoader.cpp +++ b/GUI/View/Loaders/QREDataLoader.cpp @@ -555,7 +555,7 @@ void QREDataLoader::datafieldFromParsingResult(RealDataItem* item) const SpecularDataItem* specularItem = item->specularDataItem(); ComboProperty combo = ComboProperty() << units_name; - specularItem->setAxesUnits(combo); + specularItem->setAxesUnitsCombo(combo); auto label_map = DataUtils::AxisNames::specAxis; const auto xAxisTitle = QString::fromStdString(label_map[Coords::QSPACE]); diff --git a/GUI/View/Plot2D/ColorMap.cpp b/GUI/View/Plot2D/ColorMap.cpp index 82867508874e5e3b9db92f9dc366bf84cf2d2b00..2060308f6d02c3aa20ae59f980097e4d1a4aab52 100644 --- a/GUI/View/Plot2D/ColorMap.cpp +++ b/GUI/View/Plot2D/ColorMap.cpp @@ -119,7 +119,7 @@ void ColorMap::setGradient() { if(!intensityItem()) return; - m_colorMap->setGradient(intensityItem()->gradientQCP()); + m_colorMap->setGradient(intensityItem()->currentGradientQCP()); replot(); } diff --git a/GUI/View/Plot2D/IntensityDataPropertyWidget.cpp b/GUI/View/Plot2D/IntensityDataPropertyWidget.cpp index 0c1ccbad0a4c05fc3eea318056b752e98f8a61b5..2afc4961ec124e65ab08f4fc243955515cf4b42b 100644 --- a/GUI/View/Plot2D/IntensityDataPropertyWidget.cpp +++ b/GUI/View/Plot2D/IntensityDataPropertyWidget.cpp @@ -51,18 +51,18 @@ void IntensityDataPropertyWidget::createPanelElements() GUI::Util::Layout::clearLayout(m_mainLayout); m_updaters.clear(); - m_mainLayout->addRow("Axes units:", GUI::Util::createComboBoxUpdScrollFromDescriptor( - currentIntensityDataItem()->axesUnits(), &m_updaters, [=](int newIndex) { - for(auto item : otherAllIntensityDataItems()) - item->axesUnits().setCurrentIndex(newIndex); })); + m_mainLayout->addRow("Axes units:", GUI::Util::createComboBoxUpdScroll( + [=]{ return currentIntensityDataItem()->axesUnitsCombo(); }, [=](const QString& newVal) { + for(auto item : allIntensityDataItems()) + item->setCurrentAxesUnits(newVal); }, &m_updaters)); - m_mainLayout->addRow("Color scheme:", GUI::Util::createComboBoxUpdScrollFromDescriptor( - currentIntensityDataItem()->gradient(), &m_updaters, [=](int newIndex) { - for(auto item : otherAllIntensityDataItems()) - item->gradient().setCurrentIndex(newIndex); })); + m_mainLayout->addRow("Color scheme:", GUI::Util::createComboBoxUpdScroll( + [=]{ return currentIntensityDataItem()->gradientCombo(); }, [=](const QString& newVal) { + for(auto item : allIntensityDataItems()) + item->setCurrentGradient(newVal); }, &m_updaters)); m_mainLayout->addRow(GUI::Util::createCheckBox("Interpolate", - [=]() { return currentIntensityDataItem()->isInterpolated(); }, [=](bool b) { + [=]{ return currentIntensityDataItem()->isInterpolated(); }, [=](bool b) { for(auto item : allIntensityDataItems()) item->setInterpolated(b); }, &m_updaters)); @@ -72,18 +72,18 @@ void IntensityDataPropertyWidget::createPanelElements() xFormLayout->setContentsMargins(0, 0, 0, 0); xFormLayout->setSpacing(5); - xFormLayout->addRow("Min:", GUI::Util::createDoubleSpinboxScrollFromDescriptor( - currentIntensityDataItem()->xAxisItem()->min(), &m_updaters, [=](double newValue) { - for(auto item : otherAllIntensityDataItems()) - item->xAxisItem()->min().set(newValue); })); + xFormLayout->addRow("Min:", GUI::Util::createDoubleSpinboxUpdScroll( + [=]{ return currentIntensityDataItem()->xAxisItem()->min(); }, [=](double newValue) { + for(auto item : allIntensityDataItems()) + item->xAxisItem()->setMin(newValue); }, &m_updaters)); - xFormLayout->addRow("Max:", GUI::Util::createDoubleSpinboxScrollFromDescriptor( - currentIntensityDataItem()->xAxisItem()->max(), &m_updaters, [=](double newValue) { - for(auto item : otherAllIntensityDataItems()) - item->xAxisItem()->max().set(newValue); })); + xFormLayout->addRow("Max:", GUI::Util::createDoubleSpinboxUpdScroll( + [=]{ return currentIntensityDataItem()->xAxisItem()->max(); }, [=](double newValue) { + for(auto item : allIntensityDataItems()) + item->xAxisItem()->setMax(newValue); }, &m_updaters)); xFormLayout->addRow("Title:", GUI::Util::createTextEdit( - [=]() { return currentIntensityDataItem()->xAxisItem()->title(); }, [=](QString newText) { + [=]{ return currentIntensityDataItem()->xAxisItem()->title(); }, [=](QString newText) { for(auto item : allIntensityDataItems()) item->xAxisItem()->setTitle(newText); }, &m_updaters)); @@ -95,18 +95,18 @@ void IntensityDataPropertyWidget::createPanelElements() yFormLayout->setContentsMargins(0, 0, 0, 0); yFormLayout->setSpacing(5); - yFormLayout->addRow("Min:", GUI::Util::createDoubleSpinboxScrollFromDescriptor( - currentIntensityDataItem()->yAxisItem()->min(), &m_updaters, [=](double newValue) { - for(auto item : otherAllIntensityDataItems()) - item->yAxisItem()->min().set(newValue); })); + yFormLayout->addRow("Min:", GUI::Util::createDoubleSpinboxUpdScroll( + [=]{ return currentIntensityDataItem()->yAxisItem()->min(); }, [=](double newValue) { + for(auto item : allIntensityDataItems()) + item->yAxisItem()->setMin(newValue); }, &m_updaters)); - yFormLayout->addRow("Max:", GUI::Util::createDoubleSpinboxScrollFromDescriptor( - currentIntensityDataItem()->yAxisItem()->max(), &m_updaters, [=](double newValue) { - for(auto item : otherAllIntensityDataItems()) - item->yAxisItem()->max().set(newValue); })); + yFormLayout->addRow("Max:", GUI::Util::createDoubleSpinboxUpdScroll( + [=]{ return currentIntensityDataItem()->yAxisItem()->max(); }, [=](double newValue) { + for(auto item : allIntensityDataItems()) + item->yAxisItem()->setMax(newValue); }, &m_updaters)); yFormLayout->addRow("Title:", GUI::Util::createTextEdit( - [=]() { return currentIntensityDataItem()->yAxisItem()->title(); }, [=](QString newText) { + [=]{ return currentIntensityDataItem()->yAxisItem()->title(); }, [=](QString newText) { for(auto item : allIntensityDataItems()) item->yAxisItem()->setTitle(newText); }, &m_updaters)); @@ -118,23 +118,23 @@ void IntensityDataPropertyWidget::createPanelElements() zFormLayout->setContentsMargins(0, 0, 0, 0); zFormLayout->setSpacing(5); - zFormLayout->addRow("Min:", GUI::Util::createDoubleSpinboxScrollFromDescriptor( - currentIntensityDataItem()->zAxisItem()->min(), &m_updaters, [=](double newValue) { - for(auto item : otherMainIntensityDataItems()) - item->zAxisItem()->min().set(newValue); })); + zFormLayout->addRow("Min:", GUI::Util::createDoubleSpinboxUpdScroll( + [=]{ return currentIntensityDataItem()->zAxisItem()->min(); }, [=](double newValue) { + for(auto item : allIntensityDataItems()) + item->zAxisItem()->setMin(newValue); }, &m_updaters)); - zFormLayout->addRow("Max:", GUI::Util::createDoubleSpinboxScrollFromDescriptor( - currentIntensityDataItem()->zAxisItem()->max(), &m_updaters, [=](double newValue) { - for(auto item : otherMainIntensityDataItems()) - item->zAxisItem()->max().set(newValue); })); + yFormLayout->addRow("Max:", GUI::Util::createDoubleSpinboxUpdScroll( + [=]{ return currentIntensityDataItem()->zAxisItem()->max(); }, [=](double newValue) { + for(auto item : mainIntensityDataItems()) + item->zAxisItem()->setMax(newValue); }, &m_updaters)); zFormLayout->addRow(GUI::Util::createCheckBox("log10", - [=]() { return currentIntensityDataItem()->zAxisItem()->isLogScale(); }, [=](bool b) { + [=]{ return currentIntensityDataItem()->zAxisItem()->isLogScale(); }, [=](bool b) { for(auto item : allIntensityDataItems()) item->zAxisItem()->setLogScale(b); }, &m_updaters)); zFormLayout->addRow(GUI::Util::createCheckBox("Visible", - [=]() { return currentIntensityDataItem()->zAxisItem()->isVisible(); }, [=](bool b) { + [=]{ return currentIntensityDataItem()->zAxisItem()->isVisible(); }, [=](bool b) { for(auto item : allIntensityDataItems()) item->zAxisItem()->setVisibilityValue(b); }, &m_updaters)); diff --git a/GUI/View/PlotSpecular/SpecularDataPropertyWidget.cpp b/GUI/View/PlotSpecular/SpecularDataPropertyWidget.cpp index b850a99df8ed9671b3ac73df3dcd684737d02fdd..7f3c5d5047c03cbeed65ffb66350aa6856ac8c90 100644 --- a/GUI/View/PlotSpecular/SpecularDataPropertyWidget.cpp +++ b/GUI/View/PlotSpecular/SpecularDataPropertyWidget.cpp @@ -43,10 +43,10 @@ void SpecularDataPropertyWidget::createPanelElements() GUI::Util::Layout::clearLayout(m_mainLayout); m_updaters.clear(); - m_mainLayout->addRow("Axes units:", GUI::Util::createComboBoxUpdScrollFromDescriptor( - currentSpecularDataItem()->axesUnits(), &m_updaters, [=](int newIndex) { - for(auto item : otherAllSpecularDataItems()) - item->axesUnits().setCurrentIndex(newIndex); })); + m_mainLayout->addRow("Axes units:", GUI::Util::createComboBoxUpdScroll( + [=]{ return currentSpecularDataItem()->axesUnitsCombo(); }, [=](const QString& newVal) { + for(auto item : allSpecularDataItems()) + item->setCurrentAxesUnits(newVal); }, &m_updaters)); // -- x-axis auto* xGroup = new QGroupBox("X axis", this); @@ -54,18 +54,18 @@ void SpecularDataPropertyWidget::createPanelElements() xFormLayout->setContentsMargins(0, 0, 0, 0); xFormLayout->setSpacing(5); - xFormLayout->addRow("Min:", GUI::Util::createDoubleSpinboxScrollFromDescriptor( - currentSpecularDataItem()->xAxisItem()->min(), &m_updaters, [=](double newValue) { - for(auto item : otherAllSpecularDataItems()) - item->xAxisItem()->min().set(newValue); })); + xFormLayout->addRow("Min:", GUI::Util::createDoubleSpinboxUpdScroll( + [=]{ return currentSpecularDataItem()->xAxisItem()->min(); }, [=](double newValue) { + for(auto item : allSpecularDataItems()) + item->xAxisItem()->setMin(newValue); }, &m_updaters)); - xFormLayout->addRow("Max:", GUI::Util::createDoubleSpinboxScrollFromDescriptor( - currentSpecularDataItem()->xAxisItem()->max(), &m_updaters, [=](double newValue) { - for(auto item : otherAllSpecularDataItems()) - item->xAxisItem()->max().set(newValue); })); + xFormLayout->addRow("Max:", GUI::Util::createDoubleSpinboxUpdScroll( + [=]{ return currentSpecularDataItem()->xAxisItem()->max(); }, [=](double newValue) { + for(auto item : allSpecularDataItems()) + item->xAxisItem()->setMax(newValue); }, &m_updaters)); xFormLayout->addRow("Title:", GUI::Util::createTextEdit( - [=]() { return currentSpecularDataItem()->xAxisItem()->title(); }, [=](QString newText) { + [=]{ return currentSpecularDataItem()->xAxisItem()->title(); }, [=](QString newText) { for(auto item : allSpecularDataItems()) item->xAxisItem()->setTitle(newText); }, &m_updaters)); @@ -77,23 +77,23 @@ void SpecularDataPropertyWidget::createPanelElements() yFormLayout->setContentsMargins(0, 0, 0, 0); yFormLayout->setSpacing(5); - yFormLayout->addRow("Min:", GUI::Util::createDoubleSpinboxScrollFromDescriptor( - currentSpecularDataItem()->yAxisItem()->min(), &m_updaters, [=](double newValue) { - for(auto item : otherMainSpecularDataItems()) - item->yAxisItem()->min().set(newValue); })); + yFormLayout->addRow("Min:", GUI::Util::createDoubleSpinboxUpdScroll( + [=]{ return currentSpecularDataItem()->yAxisItem()->min(); }, [=](double newValue) { + for(auto item : mainSpecularDataItems()) + item->yAxisItem()->setMin(newValue); }, &m_updaters)); - yFormLayout->addRow("Max:", GUI::Util::createDoubleSpinboxScrollFromDescriptor( - currentSpecularDataItem()->yAxisItem()->max(), &m_updaters, [=](double newValue) { - for(auto item : otherMainSpecularDataItems()) - item->yAxisItem()->max().set(newValue); })); + yFormLayout->addRow("Max:", GUI::Util::createDoubleSpinboxUpdScroll( + [=]{ return currentSpecularDataItem()->yAxisItem()->max(); }, [=](double newValue) { + for(auto item : mainSpecularDataItems()) + item->yAxisItem()->setMax(newValue); }, &m_updaters)); yFormLayout->addRow("Title:", GUI::Util::createTextEdit( - [=]() { return currentSpecularDataItem()->yAxisItem()->title(); }, [=](QString newText) { + [=]{ return currentSpecularDataItem()->yAxisItem()->title(); }, [=](QString newText) { for(auto item : mainSpecularDataItems()) { item->yAxisItem()->setTitle(newText); }}, &m_updaters)); yFormLayout->addRow(GUI::Util::createCheckBox("log10", - [=]() { return currentSpecularDataItem()->yAxisItem()->isLogScale(); }, [=](bool b) { + [=]{ return currentSpecularDataItem()->yAxisItem()->isLogScale(); }, [=](bool b) { for(auto item : allSpecularDataItems()) item->yAxisItem()->setLogScale(b); }, &m_updaters)); diff --git a/GUI/View/Tool/WidgetUtils.cpp b/GUI/View/Tool/WidgetUtils.cpp index e456ee68f6dcfc852b65a11b1b5ef788b2f555bc..c56b90ce735a1cc40b49f8a9b5fc65a12b47ef97 100644 --- a/GUI/View/Tool/WidgetUtils.cpp +++ b/GUI/View/Tool/WidgetUtils.cpp @@ -27,6 +27,42 @@ using std::function; using std::variant; +QComboBox* GUI::Util::createComboBox(function<ComboProperty()> comboFunction, + function<void(const QString&)> slot, + QList<function<void()>>* updaters, + bool isScrollable) +{ + QComboBox* combo = new QComboBox; + combo->addItems(comboFunction().values()); + combo->setMaxCount(comboFunction().values().size()); + combo->setToolTip(comboFunction().toolTip()); + combo->setCurrentText(comboFunction().currentValue()); + + if(comboFunction().toolTips().size() == combo->count()) + for(int index=0; index<combo->count(); index++) + combo->setItemData(index, comboFunction().toolTips().at(index), Qt::ToolTipRole); + + if (!isScrollable) + WheelEventEater::install(combo); + + QObject::connect(combo, &QComboBox::currentTextChanged, [=]{ slot(combo->currentText()); }); + + if (updaters) + (*updaters) << [=]() { + QSignalBlocker b(combo); + combo->setCurrentText(comboFunction().currentValue()); + }; + + return combo; +} + +QComboBox* GUI::Util::createComboBoxUpdScroll(function<ComboProperty()> comboFunction, + function<void(const QString&)> slot, + QList<function<void()>>* updaters) +{ + return GUI::Util::createComboBox(comboFunction, slot, updaters, true); +} + SafeSpinBox* GUI::Util::createSpinBox(const UIntDescriptor& d, QList<function<void()>>* updaters, function<void(uint)> slot, @@ -185,3 +221,37 @@ DoubleSpinBox* GUI::Util::createDoubleSpinboxScrollFromDescriptor(DoubleDescript { return GUI::Util::createDoubleSpinboxFromDescriptor(d, updaters, slot, true); } + +QDoubleSpinBox* GUI::Util::createDoubleSpinbox(function<double()> getter, + function<void(double)> slot, + QList<function<void()>>* updaters, + bool easyScrollable) +{ + QDoubleSpinBox* spin = new QDoubleSpinBox; + spin->setFocusPolicy(Qt::StrongFocus); + spin->setMinimum(-std::numeric_limits<double>::max()); + spin->setMaximum( std::numeric_limits<double>::max()); + spin->setDecimals(3); + spin->setSingleStep(0.01); + spin->setValue(getter()); + + if (!easyScrollable) + WheelEventEater::install(spin); + + QObject::connect(spin, &QDoubleSpinBox::valueChanged, [=]{ slot(spin->value()); }); + + if (updaters) + (*updaters) << [=]() { + QSignalBlocker b(spin); + spin->setValue(getter()); + }; + + return spin; +} + +QDoubleSpinBox* GUI::Util::createDoubleSpinboxUpdScroll(function<double()> getter, + function<void(double)> slot, + QList<function<void()>>* updaters) +{ + return GUI::Util::createDoubleSpinbox(getter, slot, updaters, true); +} diff --git a/GUI/View/Tool/WidgetUtils.h b/GUI/View/Tool/WidgetUtils.h index 76a8dfe8d59b90c196b7fc0ae29aef6aba81d9de..b3128962a10cc0582d7b883f4a2eadfa2c4374f7 100644 --- a/GUI/View/Tool/WidgetUtils.h +++ b/GUI/View/Tool/WidgetUtils.h @@ -26,12 +26,33 @@ class SafeSpinBox; class QCheckBox; class UIntDescriptor; class DoubleSpinBox; +class QDoubleSpinBox; class DoubleDescriptor; class QFormLayout; class ScientificSpinBox; namespace GUI::Util { +//! Create a combo box with the information found in a ComboProperty. +//! +//! The combo box will be filled with the available options and will get the found tooltips, +//! the common one and individual for each item. The current text will be just passes to "slot" function. +//! Furthermore, the combo box can prohibit accidental changes by the mouse wheel. Otherwise it +//! would be dangerous if the combo is on a scrollable form - unintended and unnoticed changes would +//! take place when just scrolling through the form. +//! +//! The combo can be updated from outside using "updaters" list. +//! +QComboBox* createComboBox(std::function<ComboProperty()> comboFunction, + std::function<void(const QString&)> slot, + QList<std::function<void()>>* updaters = nullptr, + bool isScrollable = false); + +//! Creates combobox with scrolling turned on +QComboBox* createComboBoxUpdScroll(std::function<ComboProperty()> comboFunction, + std::function<void(const QString&)> slot, + QList<std::function<void()>>* updaters = nullptr); + //! Create a combo box with the information found in a selection descriptor. //! //! The combo will be filled with the available options and will get the found tooltip. @@ -171,16 +192,27 @@ QLineEdit* createTextEdit(std::function<QString()> getter, std::function<void(QString)> setter, QList<std::function<void()>>* updaters); -//! Creates an updatable doublespinBox +//! Creates an updatable doublespinBox from DoubleDescriptor DoubleSpinBox* createDoubleSpinboxFromDescriptor(DoubleDescriptor d, QList<std::function<void ()>>* updaters = nullptr, std::function<void(double)> slot = nullptr, bool easyScrollable = false); -//! Creates a scrollable updatable doublespinBox +//! Creates a scrollable updatable doublespinBox from DoubleDescriptor DoubleSpinBox* createDoubleSpinboxScrollFromDescriptor(DoubleDescriptor d, - QList<std::function<void()>>* updaters = nullptr, - std::function<void(double)> slot = nullptr); + QList<std::function<void()>>* updaters = nullptr, + std::function<void(double)> slot = nullptr); + +//! Creates a scrollable updatable doublespinBox +QDoubleSpinBox* createDoubleSpinbox(std::function<double()> getter, + std::function<void(double)> slot, + QList<std::function<void()>>* updaters, + bool easyScrollable); + +//! Creates a doublespinBox with enabled scrolling +QDoubleSpinBox* createDoubleSpinboxUpdScroll(std::function<double()> getter, + std::function<void(double)> slot, + QList<std::function<void()>>* updaters); } // namespace GUI::Util #endif // BORNAGAIN_GUI_VIEW_TOOL_WIDGETUTILS_H