diff --git a/Core/Algorithms/inc/DistributionHandler.h b/Core/Algorithms/inc/DistributionHandler.h index dd7a148c6aeed468178f387e7ebf2104b835f38c..dfff842df66444f94f7478fdd7d119eec3269c59 100644 --- a/Core/Algorithms/inc/DistributionHandler.h +++ b/Core/Algorithms/inc/DistributionHandler.h @@ -29,6 +29,7 @@ class IDistribution1D; class BA_CORE_API_ DistributionHandler : public IParameterized { public: + typedef std::vector<ParameterDistribution> Distributions_t; DistributionHandler(); ~DistributionHandler(); @@ -37,6 +38,8 @@ public: const IDistribution1D &distribution, size_t nbr_samples, double sigma_factor=0.0); + void addParameterDistribution(const ParameterDistribution &par_distr); + //! get the total number of parameter value combinations (product //! of the individual sizes of each parameter distribution size_t getTotalNumberOfSamples() const; @@ -46,9 +49,11 @@ public: //! than the total number of combinations) and returns the weight //! associated with this combination of parameter values double setParameterValues(ParameterPool *p_parameter_pool, size_t index); + + const Distributions_t& getDistributions() const; private: size_t m_nbr_combinations; - std::vector<ParameterDistribution> m_distributions; + Distributions_t m_distributions; std::vector<std::vector<ParameterSample> > m_cached_samples; }; diff --git a/Core/Algorithms/inc/Simulation.h b/Core/Algorithms/inc/Simulation.h index 02ff6e9263a09ccacb44f0a73fc7dfd899c92693..bbbaae080dc77c872ac0a4105b07c7c08e4a7565 100644 --- a/Core/Algorithms/inc/Simulation.h +++ b/Core/Algorithms/inc/Simulation.h @@ -137,12 +137,14 @@ public: int copy_number=-1) const; //! add a sampled parameter distribution - void addParameterDistribution(const std::string ¶m_name, - const IDistribution1D &distribution, size_t nbr_samples, - double sigma_factor=0.0) { - m_distribution_handler.addParameterDistribution(param_name, - distribution, nbr_samples, sigma_factor); - } + void addParameterDistribution(const std::string ¶m_name, + const IDistribution1D &distribution, size_t nbr_samples, + double sigma_factor=0.0); + + //! add a sampled parameter distribution + void addParameterDistribution(const ParameterDistribution &par_distr); + + const DistributionHandler& getDistributionHandler() const; //! OffSpecSimulation needs protected copy constructor friend class OffSpecSimulation; diff --git a/Core/Algorithms/src/DistributionHandler.cpp b/Core/Algorithms/src/DistributionHandler.cpp index b1cd3914c09c740cdff7c1651d0b2b8a50696cee..611ef8ef5ad95c625f84fee49d7fe02c893c70e8 100644 --- a/Core/Algorithms/src/DistributionHandler.cpp +++ b/Core/Algorithms/src/DistributionHandler.cpp @@ -37,6 +37,15 @@ void DistributionHandler::addParameterDistribution( } } +void DistributionHandler::addParameterDistribution(const ParameterDistribution &par_distr) +{ + if(par_distr.getNbrSamples() > 0) { + m_distributions.push_back(par_distr); + m_nbr_combinations *= par_distr.getNbrSamples(); + m_cached_samples.push_back(par_distr.generateSamples()); + } +} + size_t DistributionHandler::getTotalNumberOfSamples() const { return m_nbr_combinations; @@ -71,3 +80,8 @@ double DistributionHandler::setParameterValues(ParameterPool *p_parameter_pool, } return weight; } + +const DistributionHandler::Distributions_t& DistributionHandler::getDistributions() const +{ + return m_distributions; +} diff --git a/Core/Algorithms/src/Simulation.cpp b/Core/Algorithms/src/Simulation.cpp index 1c325e2002df4ba18d04c8bf8286ecab8f009ad9..c5366a8e77ab5e7161c23479d3f1c8a46cbabe62 100644 --- a/Core/Algorithms/src/Simulation.cpp +++ b/Core/Algorithms/src/Simulation.cpp @@ -258,6 +258,20 @@ std::string Simulation::addParametersToExternalPool( return new_path; } +void Simulation::addParameterDistribution(const std::string ¶m_name, const IDistribution1D &distribution, size_t nbr_samples, double sigma_factor) { + m_distribution_handler.addParameterDistribution(param_name, + distribution, nbr_samples, sigma_factor); +} + +void Simulation::addParameterDistribution(const ParameterDistribution &par_distr) +{ + m_distribution_handler.addParameterDistribution(par_distr); +} + +const DistributionHandler &Simulation::getDistributionHandler() const +{ + return m_distribution_handler; +} void Simulation::updateIntensityMapAxes() { diff --git a/Core/StandardSamples/IsGISAXS03Builder.cpp b/Core/StandardSamples/CylindersBuilder.cpp similarity index 87% rename from Core/StandardSamples/IsGISAXS03Builder.cpp rename to Core/StandardSamples/CylindersBuilder.cpp index 18aa33b2b7a7d79baa78ebf76504a46796afd995..43eb508b0cee3cb46eb8b8df6d8ccb21cb6362be 100644 --- a/Core/StandardSamples/IsGISAXS03Builder.cpp +++ b/Core/StandardSamples/CylindersBuilder.cpp @@ -2,8 +2,8 @@ // // BornAgain: simulate and fit scattering at grazing incidence // -//! @file StandardSamples/IsGISAXS03Builder.cpp -//! @brief Implements class IsGISAXS03Builder. +//! @file StandardSamples/CylindersBuilder.cpp +//! @brief Implements classes of CylindersBuilder family. //! //! @homepage http://www.bornagainproject.org //! @license GNU General Public License v3 or higher (see COPYING) @@ -13,7 +13,7 @@ // // ************************************************************************** // -#include "IsGISAXS03Builder.h" +#include "CylindersBuilder.h" #include "MultiLayer.h" #include "ParticleLayout.h" #include "Materials.h" @@ -27,7 +27,7 @@ // ----------------------------------------------------------------------------- // Cylinders in DWBA // ----------------------------------------------------------------------------- -IsGISAXS03DWBABuilder::IsGISAXS03DWBABuilder() +CylindersInDWBABuilder::CylindersInDWBABuilder() : m_height(5*Units::nanometer) , m_radius(5*Units::nanometer) { @@ -35,7 +35,7 @@ IsGISAXS03DWBABuilder::IsGISAXS03DWBABuilder() } -void IsGISAXS03DWBABuilder::init_parameters() +void CylindersInDWBABuilder::init_parameters() { clearParameterPool(); registerParameter("radius", &m_radius); @@ -43,7 +43,7 @@ void IsGISAXS03DWBABuilder::init_parameters() } -ISample *IsGISAXS03DWBABuilder::buildSample() const +ISample *CylindersInDWBABuilder::buildSample() const { MultiLayer *multi_layer = new MultiLayer(); @@ -72,7 +72,7 @@ ISample *IsGISAXS03DWBABuilder::buildSample() const // ----------------------------------------------------------------------------- // Cylinders in BA // ----------------------------------------------------------------------------- -IsGISAXS03BABuilder::IsGISAXS03BABuilder() +CylindersInBABuilder::CylindersInBABuilder() : m_height(5*Units::nanometer) , m_radius(5*Units::nanometer) { @@ -80,7 +80,7 @@ IsGISAXS03BABuilder::IsGISAXS03BABuilder() } -void IsGISAXS03BABuilder::init_parameters() +void CylindersInBABuilder::init_parameters() { clearParameterPool(); registerParameter("radius", &m_radius); @@ -88,7 +88,7 @@ void IsGISAXS03BABuilder::init_parameters() } -ISample *IsGISAXS03BABuilder::buildSample() const +ISample *CylindersInBABuilder::buildSample() const { MultiLayer *multi_layer = new MultiLayer(); @@ -113,7 +113,7 @@ ISample *IsGISAXS03BABuilder::buildSample() const // ----------------------------------------------------------------------------- // Cylinders in BA with size distribution // ----------------------------------------------------------------------------- -IsGISAXS03BASizeBuilder::IsGISAXS03BASizeBuilder() +CylindersWithSizeDistributionBuilder::CylindersWithSizeDistributionBuilder() : m_height(5*Units::nanometer) , m_radius(5*Units::nanometer) { @@ -121,7 +121,7 @@ IsGISAXS03BASizeBuilder::IsGISAXS03BASizeBuilder() } -void IsGISAXS03BASizeBuilder::init_parameters() +void CylindersWithSizeDistributionBuilder::init_parameters() { clearParameterPool(); registerParameter("radius", &m_radius); @@ -129,7 +129,7 @@ void IsGISAXS03BASizeBuilder::init_parameters() } -ISample *IsGISAXS03BASizeBuilder::buildSample() const +ISample *CylindersWithSizeDistributionBuilder::buildSample() const { MultiLayer *multi_layer = new MultiLayer(); diff --git a/Core/StandardSamples/IsGISAXS03Builder.h b/Core/StandardSamples/CylindersBuilder.h similarity index 69% rename from Core/StandardSamples/IsGISAXS03Builder.h rename to Core/StandardSamples/CylindersBuilder.h index bbc284295b7c3dbaba7d1f5456fead402d880983..6b2a2ee7835d2c65f9f3bbc1d2d558fbdddda1e3 100644 --- a/Core/StandardSamples/IsGISAXS03Builder.h +++ b/Core/StandardSamples/CylindersBuilder.h @@ -2,8 +2,8 @@ // // BornAgain: simulate and fit scattering at grazing incidence // -//! @file StandardSamples/IsGISAXS03Builder.h -//! @brief Defines class IsGISAXS03Builder. +//! @file StandardSamples/CylindersBuilder.h +//! @brief Defines classes of CylindersBuilder family. //! //! @homepage http://www.bornagainproject.org //! @license GNU General Public License v3 or higher (see COPYING) @@ -13,20 +13,20 @@ // // ************************************************************************** // -#ifndef ISGISAXS03BUILDER_H -#define ISGISAXS03BUILDER_H +#ifndef CYLINDERSBUILDER_H +#define CYLINDERSBUILDER_H #include "ISampleBuilder.h" -//! @class IsGISAXS03DWBABuilder +//! @class CylindersInBABuilder //! @ingroup standard_samples //! @brief Builds sample: cylinder formfactor in DWBA (IsGISAXS example #3, part I) -class BA_CORE_API_ IsGISAXS03DWBABuilder : public ISampleBuilder +class BA_CORE_API_ CylindersInDWBABuilder : public ISampleBuilder { public: - IsGISAXS03DWBABuilder(); + CylindersInDWBABuilder(); ISample *buildSample() const; protected: @@ -38,14 +38,14 @@ private: }; -//! @class IsGISAXS03BABuilder +//! @class CylindersInBABuilder //! @ingroup standard_samples //! @brief Builds sample: cylinder formfactor in BA (IsGISAXS example #3, part II) -class BA_CORE_API_ IsGISAXS03BABuilder : public ISampleBuilder +class BA_CORE_API_ CylindersInBABuilder : public ISampleBuilder { public: - IsGISAXS03BABuilder(); + CylindersInBABuilder(); ISample *buildSample() const; protected: @@ -57,15 +57,15 @@ private: }; -//! @class IsGISAXS03BASizeBuilder +//! @class CylindersWithSizeDistributionBuilder //! @ingroup standard_samples //! @brief Builds sample: cylinder formfactor in BA with size distribution //! (IsGISAXS example #3, part II) -class IsGISAXS03BASizeBuilder : public ISampleBuilder +class CylindersWithSizeDistributionBuilder : public ISampleBuilder { public: - IsGISAXS03BASizeBuilder(); + CylindersWithSizeDistributionBuilder(); ISample *buildSample() const; protected: @@ -78,4 +78,4 @@ private: -#endif // ISGISAXS03BUILDER_H +#endif // CYLINDERSBUILDER_H diff --git a/Core/StandardSamples/FunctionalTestRegistry.cpp b/Core/StandardSamples/FunctionalTestRegistry.cpp index 8e8dfbd7626d2f3a593ed11acaf1549874855389..b3c4620270e70150160a7e6cf49d2771f8fea01f 100644 --- a/Core/StandardSamples/FunctionalTestRegistry.cpp +++ b/Core/StandardSamples/FunctionalTestRegistry.cpp @@ -32,13 +32,13 @@ FunctionalTestRegistry::Catalogue::Catalogue() "Mixture cylinder particles with different size distribution", "isgisaxs02_reference.int.gz", 2e-10); - add("isgisaxs03_ba", + add("cylinders_ba", "Cylinder formfactor in BA", "isgisaxs03_reference_BA.int.gz", 2e-10); - add("isgisaxs03_dwba", + add("cylinders_dwba", "Cylinder formfactor in DWBA", "isgisaxs03_reference_DWBA.int.gz", 2e-10); - add("isgisaxs03_basize", + add("cylinders_basize", "Cylinder formfactor in BA with size distribution", "isgisaxs03_reference_BA_size.int.gz", 2e-10); @@ -117,6 +117,10 @@ FunctionalTestRegistry::Catalogue::Catalogue() "Cosine ripple within the 1D-paracrystal model", "ripple1_reference.int.gz", 1e-10); + add("beam_divergence", + "Cylinders in DWBA with beam divergence", + "beamdivergence_reference.int.gz", 1e-10); + } diff --git a/Core/StandardSamples/SampleBuilderFactory.cpp b/Core/StandardSamples/SampleBuilderFactory.cpp index 8716402adc89c00582bcb67411c3df744d9bdfad..f72bc2c21bcbb52df97777bcbe8c13bf7474a752 100644 --- a/Core/StandardSamples/SampleBuilderFactory.cpp +++ b/Core/StandardSamples/SampleBuilderFactory.cpp @@ -16,7 +16,7 @@ #include "SampleBuilderFactory.h" #include "IsGISAXS01Builder.h" #include "IsGISAXS02Builder.h" -#include "IsGISAXS03Builder.h" +#include "CylindersBuilder.h" #include "IsGISAXS04Builder.h" #include "IsGISAXS06Builder.h" #include "IsGISAXS07Builder.h" @@ -46,16 +46,16 @@ SampleBuilderFactory::SampleBuilderFactory() "Mixture cylinder particles with different size distribution "); registerItem( - "isgisaxs03_ba", - IFactoryCreateFunction<IsGISAXS03BABuilder, ISampleBuilder>, + "cylinders_ba", + IFactoryCreateFunction<CylindersInBABuilder, ISampleBuilder>, "Cylinder formfactor in BA"); registerItem( - "isgisaxs03_dwba", - IFactoryCreateFunction<IsGISAXS03DWBABuilder, ISampleBuilder>, + "cylinders_dwba", + IFactoryCreateFunction<CylindersInDWBABuilder, ISampleBuilder>, "Cylinder formfactor in DWBA"); registerItem( - "isgisaxs03_basize", - IFactoryCreateFunction<IsGISAXS03BASizeBuilder, ISampleBuilder>, + "cylinders_basize", + IFactoryCreateFunction<CylindersWithSizeDistributionBuilder, ISampleBuilder>, "Cylinder formfactor in BA with size distribution"); registerItem( diff --git a/Core/StandardSamples/SimulationRegistry.cpp b/Core/StandardSamples/SimulationRegistry.cpp index 34bbbb170683d9d806b0e1f9e391bd4eb279e417..6ece08397c8846d8875ed9201a32a6d5d46d133d 100644 --- a/Core/StandardSamples/SimulationRegistry.cpp +++ b/Core/StandardSamples/SimulationRegistry.cpp @@ -28,13 +28,13 @@ SimulationRegistry::SimulationRegistry() "Mixture cylinder particles with different size distribution"); registerItem( - "isgisaxs03_ba", StandardSimulations::IsGISAXS03BA, + "cylinders_ba", StandardSimulations::CylindersInBA, "Cylinder formfactor in BA"); registerItem( - "isgisaxs03_dwba", StandardSimulations::IsGISAXS03DWBA, + "cylinders_dwba", StandardSimulations::CylindersInDWBA, "Cylinder formfactor in DWBA"); registerItem( - "isgisaxs03_basize", StandardSimulations::IsGISAXS03BAsize, + "cylinders_basize", StandardSimulations::CylindersWithSizeDistribution, "Cylinder formfactor in BA with size distribution"); registerItem( @@ -141,6 +141,10 @@ SimulationRegistry::SimulationRegistry() registerItem( "gui_multiple_layouts", StandardSimulations::gui_MultipleLayouts, "GUI: Mixture of Cylinders and Prisms using Multiple Layouts"); + + registerItem( + "beam_divergence", StandardSimulations::BeamDivergence, + "Cylinders in DWBA with beam divergence"); } diff --git a/Core/StandardSamples/StandardSimulations.cpp b/Core/StandardSamples/StandardSimulations.cpp index 23bdb93180163b6e50bd49204d9662c46e70cd2d..daea39a1ec343b08b4994431e416c81f242eae63 100644 --- a/Core/StandardSamples/StandardSimulations.cpp +++ b/Core/StandardSamples/StandardSimulations.cpp @@ -20,6 +20,7 @@ #include "Units.h" #include "FileSystem.h" #include "IntensityDataIOFactory.h" +#include "Distributions.h" Simulation *StandardSimulations::IsGISAXS01() { @@ -56,10 +57,10 @@ Simulation *StandardSimulations::IsGISAXS02() return result; } -Simulation *StandardSimulations::IsGISAXS03BA() +Simulation *StandardSimulations::CylindersInBA() { SampleBuilderFactory factory; - SampleBuilder_t builder = factory.createBuilder("isgisaxs03_ba"); + SampleBuilder_t builder = factory.createBuilder("cylinders_ba"); Simulation *result = new Simulation(); @@ -74,10 +75,10 @@ Simulation *StandardSimulations::IsGISAXS03BA() return result; } -Simulation *StandardSimulations::IsGISAXS03DWBA() +Simulation *StandardSimulations::CylindersInDWBA() { SampleBuilderFactory factory; - SampleBuilder_t builder = factory.createBuilder("isgisaxs03_dwba"); + SampleBuilder_t builder = factory.createBuilder("cylinders_dwba"); Simulation *result = new Simulation(); @@ -93,10 +94,10 @@ Simulation *StandardSimulations::IsGISAXS03DWBA() return result; } -Simulation *StandardSimulations::IsGISAXS03BAsize() +Simulation *StandardSimulations::CylindersWithSizeDistribution() { SampleBuilderFactory factory; - SampleBuilder_t builder = factory.createBuilder("isgisaxs03_basize"); + SampleBuilder_t builder = factory.createBuilder("cylinders_basize"); Simulation *result = new Simulation(); @@ -607,3 +608,31 @@ Simulation *StandardSimulations::gui_MultipleLayouts() return result; } + + +Simulation *StandardSimulations::BeamDivergence() +{ + SampleBuilderFactory factory; + SampleBuilder_t builder = factory.createBuilder("cylinders_dwba"); + + Simulation *result = new Simulation(); + + result->setDetectorParameters(40, -0.2*Units::degree, 1.8*Units::degree, + 60, 0.0*Units::degree, 2.2*Units::degree); + result->setBeamParameters(1.0*Units::angstrom, 0.2*Units::degree, + 0.0*Units::degree); + + + DistributionLogNormal wavelength_distr(1.0*Units::angstrom, 0.1); + DistributionGaussian alpha_distr(-0.2*Units::degree, 0.1*Units::degree); + //DistributionGaussian phi_distr(0.0*Units::degree, 0.1*Units::degree); + DistributionGate phi_distr(-0.1*Units::degree, 0.1*Units::degree); + + result->addParameterDistribution("*/Beam/wavelength", wavelength_distr, 5); + result->addParameterDistribution("*/Beam/alpha", alpha_distr, 4); + result->addParameterDistribution("*/Beam/phi", phi_distr, 3); + + result->setSampleBuilder( builder ); + + return result; +} diff --git a/Core/StandardSamples/StandardSimulations.h b/Core/StandardSamples/StandardSimulations.h index 04eccd4a6c89d6a9d50f999ac77c3e43ffe8a7e5..d9304225658919c2e1e853c528cb71978a455eac 100644 --- a/Core/StandardSamples/StandardSimulations.h +++ b/Core/StandardSamples/StandardSimulations.h @@ -25,9 +25,9 @@ namespace StandardSimulations{ Simulation *IsGISAXS01(); Simulation *IsGISAXS02(); -Simulation *IsGISAXS03BA(); -Simulation *IsGISAXS03DWBA(); -Simulation *IsGISAXS03BAsize(); +Simulation *CylindersInBA(); +Simulation *CylindersInDWBA(); +Simulation *CylindersWithSizeDistribution(); Simulation *IsGISAXS041DDL(); Simulation *IsGISAXS042DDL(); Simulation *IsGISAXS06L1(); @@ -56,6 +56,7 @@ Simulation *gui_IsGISAXS06L1(); Simulation *gui_IsGISAXS06L2(); Simulation *gui_IsGISAXS07(); Simulation *gui_MultipleLayouts(); +Simulation *BeamDivergence(); } diff --git a/GUI/coregui/CMakeLists.txt b/GUI/coregui/CMakeLists.txt index 3802493b792c49d77de7f6b666105e01cc975f74..2af36ed08f2f0b26b695b9c0977fab51468a9c4c 100644 --- a/GUI/coregui/CMakeLists.txt +++ b/GUI/coregui/CMakeLists.txt @@ -31,6 +31,7 @@ set(include_dirs ${CMAKE_CURRENT_SOURCE_DIR}/Views/InstrumentWidgets ${CMAKE_CURRENT_SOURCE_DIR}/Views/SimulationWidgets ${CMAKE_CURRENT_SOURCE_DIR}/Views/FitWidgets + ${CMAKE_CURRENT_SOURCE_DIR}/Views/PropertyEditor ) include_directories(${include_dirs}) @@ -46,6 +47,7 @@ file(GLOB source_files "Views/InstrumentWidgets/*.cpp" "Views/SimulationWidgets/*.cpp" "Views/FitWidgets/*.cpp" + "Views/PropertyEditor/*.cpp" ) set(source_widgetbox @@ -68,6 +70,7 @@ file(GLOB include_files "Views/InstrumentWidgets/*.h" "Views/SimulationWidgets/*.h" "Views/FitWidgets/*.h" + "Views/PropertyEditor/*.h" ) set(include_widgetbox diff --git a/GUI/coregui/Models/AxesItems.cpp b/GUI/coregui/Models/AxesItems.cpp index 03bfbe645eaf1b17bec15957b10e51be1ab098e4..917422c8cd0e7d96ee81785a19e70f8f3254e87a 100644 --- a/GUI/coregui/Models/AxesItems.cpp +++ b/GUI/coregui/Models/AxesItems.cpp @@ -15,6 +15,7 @@ #include "AxesItems.h" +const QString BasicAxisItem::P_NBINS = "nbins"; const QString BasicAxisItem::P_MIN = "min"; const QString BasicAxisItem::P_MAX = "max"; const QString BasicAxisItem::P_TITLE = "title"; @@ -23,6 +24,7 @@ BasicAxisItem::BasicAxisItem(const QString &type, ParameterizedItem *parent) : ParameterizedItem(type, parent) { setItemName(type); + registerProperty(P_NBINS, 100, PropertyAttribute(AttLimits::limited(1, 1024))); registerProperty(P_MIN, 0.0, PropertyAttribute(AttLimits::limitless())); registerProperty(P_MAX, -1.0, PropertyAttribute(AttLimits::limitless())); registerProperty(P_TITLE, QString()); diff --git a/GUI/coregui/Models/AxesItems.h b/GUI/coregui/Models/AxesItems.h index e381fc54b40775dcfa5657091cc2a89a7389b35d..f67ce3967c4c7cb9a608f68186f66cdc787372e2 100644 --- a/GUI/coregui/Models/AxesItems.h +++ b/GUI/coregui/Models/AxesItems.h @@ -23,6 +23,7 @@ class BA_CORE_API_ BasicAxisItem : public ParameterizedItem { Q_OBJECT public: + static const QString P_NBINS; static const QString P_MIN; static const QString P_MAX; static const QString P_TITLE; diff --git a/GUI/coregui/Models/BeamAngleItems.cpp b/GUI/coregui/Models/BeamAngleItems.cpp new file mode 100644 index 0000000000000000000000000000000000000000..d3f69535ad0268b38f603fcca8e6d1580557ec41 --- /dev/null +++ b/GUI/coregui/Models/BeamAngleItems.cpp @@ -0,0 +1,97 @@ +// ************************************************************************** // +// +// BornAgain: simulate and fit scattering at grazing incidence +// +//! @file coregui/Models/BeamWavelengthItem.cpp +//! @brief Implements class BeamWavelengthItem +//! +//! @homepage http://www.bornagainproject.org +//! @license GNU General Public License v3 or higher (see COPYING) +//! @copyright Forschungszentrum Jülich GmbH 2015 +//! @authors Scientific Computing Group at MLZ Garching +//! @authors C. Durniak, M. Ganeva, G. Pospelov, W. Van Herck, J. Wuttke +// +// ************************************************************************** // + +#include "BeamAngleItems.h" +#include "item_constants.h" +#include "Distributions.h" +#include "Units.h" + + +BeamInclinationAngleItem::BeamInclinationAngleItem(ParameterizedItem *parent) + : BeamDistributionItem(Constants::BeamInclinationAngleType, parent) +{ + setItemName(Constants::BeamInclinationAngleType); + setRegisteredProperty(BeamDistributionItem::P_CACHED_VALUE, 0.2); + setPropertyAttribute(BeamDistributionItem::P_CACHED_VALUE, PropertyAttribute(PropertyAttribute::HIDDEN, AttLimits::limited(0.0, 90.0), 2)); +} + +IDistribution1D *BeamInclinationAngleItem::createDistribution1D() +{ + IDistribution1D *result(0); + if(DistributionItem *distributionItem = dynamic_cast<DistributionItem *>(getSubItems()[P_DISTRIBUTION])) { + result = BeamAngleHelper::creatAngleDistribution(distributionItem, BeamAngleHelper::INCLINATION_ANGLE); + } + return result; +} + +// -------------------------------------------------------------------------- // + +BeamAzimuthalAngleItem::BeamAzimuthalAngleItem(ParameterizedItem *parent) + : BeamDistributionItem(Constants::BeamAzimuthalAngleType, parent) +{ + setItemName(Constants::BeamAzimuthalAngleType); + setRegisteredProperty(BeamDistributionItem::P_CACHED_VALUE, 0.0); + setPropertyAttribute(BeamDistributionItem::P_CACHED_VALUE, PropertyAttribute(PropertyAttribute::HIDDEN, AttLimits::limited(-90.0, 90.0), 2)); +} + +IDistribution1D *BeamAzimuthalAngleItem::createDistribution1D() +{ + IDistribution1D *result(0); + if(DistributionItem *distributionItem = dynamic_cast<DistributionItem *>(getSubItems()[P_DISTRIBUTION])) { + result = BeamAngleHelper::creatAngleDistribution(distributionItem, BeamAngleHelper::AZIMUTHAL_ANGLE); + } + return result; +} + +// -------------------------------------------------------------------------- // + +//! FIXME, It is so ugly +IDistribution1D *BeamAngleHelper::creatAngleDistribution(DistributionItem *distributionItem, BeamAngleHelper::EAngleType angle_type) +{ + int invertion(1); + if(angle_type == INCLINATION_ANGLE) invertion = -1; + + IDistribution1D *result(0); + if(distributionItem->modelType() == Constants::DistributionGateType) { + double min = invertion*distributionItem->getRegisteredProperty(DistributionGateItem::P_MIN).toDouble(); + double max = invertion*distributionItem->getRegisteredProperty(DistributionGateItem::P_MAX).toDouble(); + if(min > max) { + result = new DistributionGate(Units::deg2rad(max), Units::deg2rad(min)); + } else { + result = new DistributionGate(Units::deg2rad(min), Units::deg2rad(max)); + } + } + else if(distributionItem->modelType() == Constants::DistributionLorentzType) { + double mean = invertion*distributionItem->getRegisteredProperty(DistributionLorentzItem::P_MEAN).toDouble(); + double hwhm = distributionItem->getRegisteredProperty(DistributionLorentzItem::P_HWHM).toDouble(); + result = new DistributionLorentz(Units::deg2rad(mean), Units::deg2rad(hwhm)); + } + else if(distributionItem->modelType() == Constants::DistributionGaussianType) { + double mean = invertion*distributionItem->getRegisteredProperty(DistributionGaussianItem::P_MEAN).toDouble(); + double std_dev = distributionItem->getRegisteredProperty(DistributionGaussianItem::P_STD_DEV).toDouble(); + result = new DistributionGaussian(Units::deg2rad(mean), Units::deg2rad(std_dev)); + } + else if(distributionItem->modelType() == Constants::DistributionLogNormalType) { + double median = invertion*distributionItem->getRegisteredProperty(DistributionLogNormalItem::P_MEDIAN).toDouble(); + double scale_par = distributionItem->getRegisteredProperty(DistributionLogNormalItem::P_SCALE_PAR).toDouble(); + return new DistributionLogNormal(Units::deg2rad(median), scale_par); + } + else if(distributionItem->modelType() == Constants::DistributionCosineType) { + double mean = invertion*distributionItem->getRegisteredProperty(DistributionCosineItem::P_MEAN).toDouble(); + double sigma = distributionItem->getRegisteredProperty(DistributionCosineItem::P_SIGMA).toDouble(); + return new DistributionCosine(Units::deg2rad(mean), Units::deg2rad(sigma)); + } + return result; +} diff --git a/GUI/coregui/Models/BeamAngleItems.h b/GUI/coregui/Models/BeamAngleItems.h new file mode 100644 index 0000000000000000000000000000000000000000..3255c5e558b35f7e7eff4d328c6ac3b58ac73e14 --- /dev/null +++ b/GUI/coregui/Models/BeamAngleItems.h @@ -0,0 +1,49 @@ +// ************************************************************************** // +// +// BornAgain: simulate and fit scattering at grazing incidence +// +//! @file coregui/Models/BeamAngleItem.h +//! @brief Defines class BeamAngleItem +//! +//! @homepage http://www.bornagainproject.org +//! @license GNU General Public License v3 or higher (see COPYING) +//! @copyright Forschungszentrum Jülich GmbH 2015 +//! @authors Scientific Computing Group at MLZ Garching +//! @authors C. Durniak, M. Ganeva, G. Pospelov, W. Van Herck, J. Wuttke +// +// ************************************************************************** // + +#ifndef BEAMANGLEITEM_H +#define BEAMANGLEITEM_H + +#include "WinDllMacros.h" +#include "BeamDistributionItem.h" + +class BA_CORE_API_ BeamAzimuthalAngleItem : public BeamDistributionItem +{ + Q_OBJECT +public: + explicit BeamAzimuthalAngleItem(ParameterizedItem *parent=0); + ~BeamAzimuthalAngleItem(){} +protected: + virtual IDistribution1D *createDistribution1D(); +}; + +class BA_CORE_API_ BeamInclinationAngleItem : public BeamDistributionItem +{ + Q_OBJECT +public: + explicit BeamInclinationAngleItem(ParameterizedItem *parent=0); + ~BeamInclinationAngleItem(){} + virtual IDistribution1D *createDistribution1D(); +}; + +class BA_CORE_API_ BeamAngleHelper +{ +public: + enum EAngleType {INCLINATION_ANGLE, AZIMUTHAL_ANGLE}; + static IDistribution1D *creatAngleDistribution(DistributionItem *distributionItem, EAngleType angle_type); +}; + + +#endif diff --git a/GUI/coregui/Models/BeamDistributionItem.cpp b/GUI/coregui/Models/BeamDistributionItem.cpp new file mode 100644 index 0000000000000000000000000000000000000000..a33f71e6d93e390e3aa1402888c5c8bfb2c8eb2b --- /dev/null +++ b/GUI/coregui/Models/BeamDistributionItem.cpp @@ -0,0 +1,100 @@ +// ************************************************************************** // +// +// BornAgain: simulate and fit scattering at grazing incidence +// +//! @file coregui/Models/BeamDistributionItem.cpp +//! @brief Implements class BeamDistributionItem +//! +//! @homepage http://www.bornagainproject.org +//! @license GNU General Public License v3 or higher (see COPYING) +//! @copyright Forschungszentrum Jülich GmbH 2015 +//! @authors Scientific Computing Group at MLZ Garching +//! @authors C. Durniak, M. Ganeva, G. Pospelov, W. Van Herck, J. Wuttke +// +// ************************************************************************** // + +#include "BeamDistributionItem.h" +#include "DistributionItem.h" +#include "ParameterDistribution.h" +#include <QDebug> +#include <boost/scoped_ptr.hpp> + + +const QString BeamDistributionItem::P_DISTRIBUTION = "Distribution"; +const QString BeamDistributionItem::P_CACHED_VALUE = "Cached value"; + +BeamDistributionItem::BeamDistributionItem(const QString name, ParameterizedItem *parent) + : ParameterizedItem(name, parent) +{ + setItemName(Constants::BeamDistributionType); + registerProperty(P_CACHED_VALUE, 0.0, PropertyAttribute(PropertyAttribute::HIDDEN)); + registerGroupProperty(P_DISTRIBUTION, Constants::DistributionExtendedGroup); + setGroupProperty(P_DISTRIBUTION, Constants::DistributionNoneType); +} + +void BeamDistributionItem::onPropertyChange(const QString &name) +{ + if(name == P_CACHED_VALUE) { + DistributionItem *distribution = dynamic_cast<DistributionItem *>(getSubItems()[P_DISTRIBUTION]); + if(distribution) { + double cached_value = getRegisteredProperty(P_CACHED_VALUE).toDouble(); + PropertyAttribute cached_attribute = getPropertyAttribute(P_CACHED_VALUE); + cached_attribute.setAppearance(PropertyAttribute::VISIBLE); + distribution->init_parameters(cached_value, cached_attribute); + } + } +} + +//! returns parameter distribution to add into the Simulation +ParameterDistribution *BeamDistributionItem::getParameterDistributionForName(const QString ¶meter_name) +{ + ParameterDistribution *result(0); + if(DistributionItem *distributionItem = dynamic_cast<DistributionItem *>(getSubItems()[P_DISTRIBUTION])) { + boost::scoped_ptr<IDistribution1D> distribution(createDistribution1D()); + + if(distribution) { + int nbr_samples = distributionItem->getRegisteredProperty(DistributionItem::P_NUMBER_OF_SAMPLES).toInt(); + double sigma_factor(0); + if(distributionItem->isRegisteredProperty(DistributionItem::P_SIGMA_FACTOR)) { + sigma_factor = distributionItem->getRegisteredProperty(DistributionItem::P_SIGMA_FACTOR).toInt(); + } + + result = new ParameterDistribution(parameter_name.toStdString(), *distribution, nbr_samples, sigma_factor); + } + } + return result; +} + +//! updates new DistributionItem with cached_value +void BeamDistributionItem::onSubItemChanged(const QString &propertyName) +{ + qDebug() << "BeamWavelengthItem::onSubItemChanged(const QString &propertyName)" << propertyName; + if(propertyName == P_DISTRIBUTION) { + DistributionItem *distribution = dynamic_cast<DistributionItem *>(getSubItems()[P_DISTRIBUTION]); + Q_ASSERT(distribution); + double cached_value = getRegisteredProperty(P_CACHED_VALUE).toDouble(); + PropertyAttribute cached_attribute = getPropertyAttribute(P_CACHED_VALUE); + cached_attribute.setAppearance(PropertyAttribute::VISIBLE); + distribution->init_parameters(cached_value, cached_attribute); + } + ParameterizedItem::onSubItemChanged(propertyName); +} + +void BeamDistributionItem::onSubItemPropertyChanged(const QString &property_group, const QString &property_name) +{ + qDebug() << "BeamWavelengthItem::onSubItemPropertyChanged(const QString &property_group, const QString &property_name)" << property_group << property_name; + if(property_group == P_DISTRIBUTION && property_name == DistributionNoneItem::P_VALUE) { + double value_to_cache = getSubItems()[P_DISTRIBUTION]->getRegisteredProperty(DistributionNoneItem::P_VALUE).toDouble(); + setRegisteredProperty(P_CACHED_VALUE, value_to_cache); + } + ParameterizedItem::onSubItemPropertyChanged(property_group, property_name); +} + +IDistribution1D *BeamDistributionItem::createDistribution1D() +{ + IDistribution1D *result(0); + if(DistributionItem *distributionItem = dynamic_cast<DistributionItem *>(getSubItems()[P_DISTRIBUTION])) { + result = distributionItem->createDistribution(); + } + return result; +} diff --git a/GUI/coregui/Models/BeamDistributionItem.h b/GUI/coregui/Models/BeamDistributionItem.h new file mode 100644 index 0000000000000000000000000000000000000000..78bc965723f2e520853464695f4ee0b73b6cd07e --- /dev/null +++ b/GUI/coregui/Models/BeamDistributionItem.h @@ -0,0 +1,46 @@ +// ************************************************************************** // +// +// BornAgain: simulate and fit scattering at grazing incidence +// +//! @file coregui/Models/BeamDistributionItem.h +//! @brief Defines class BeamDistributionItem +//! +//! @homepage http://www.bornagainproject.org +//! @license GNU General Public License v3 or higher (see COPYING) +//! @copyright Forschungszentrum Jülich GmbH 2015 +//! @authors Scientific Computing Group at MLZ Garching +//! @authors C. Durniak, M. Ganeva, G. Pospelov, W. Van Herck, J. Wuttke +// +// ************************************************************************** // + +#ifndef BEAMDISTRIBUTIONITEM_H +#define BEAMDISTRIBUTIONITEM_H + +#include "ParameterizedItem.h" +#include "DistributionItem.h" +class ParameterDistribution; +class IDistribution1D; + +//! The BeamDistributionItem handles wavelength, inclination and azimuthal parameter +//! distribution for BeamItem +class BA_CORE_API_ BeamDistributionItem : public ParameterizedItem +{ + Q_OBJECT +public: + static const QString P_DISTRIBUTION; + static const QString P_CACHED_VALUE; + explicit BeamDistributionItem(const QString name = QString(), ParameterizedItem *parent=0); + ~BeamDistributionItem(){} + void onPropertyChange(const QString &name); + + ParameterDistribution *getParameterDistributionForName(const QString ¶meter_name); + +protected slots: + void onSubItemChanged(const QString &propertyName); + void onSubItemPropertyChanged(const QString &property_group, const QString &property_name); + +protected: + virtual IDistribution1D *createDistribution1D(); +}; + +#endif diff --git a/GUI/coregui/Models/BeamItem.cpp b/GUI/coregui/Models/BeamItem.cpp index af70b210195dc87a6aff6d326d0d11ee938c426e..f7b621be33216c1fa5ff10a385456c78092b8ef4 100644 --- a/GUI/coregui/Models/BeamItem.cpp +++ b/GUI/coregui/Models/BeamItem.cpp @@ -17,34 +17,98 @@ #include "InterferenceFunctionItems.h" #include "ComboProperty.h" #include "AngleProperty.h" +#include "DistributionItem.h" +#include "ScientificDoubleProperty.h" +#include "BeamDistributionItem.h" #include "Units.h" +#include "BeamDistributionItem.h" #include <QDebug> const QString BeamItem::P_INTENSITY = "Intensity [1/s]"; -const QString BeamItem::P_WAVELENGTH = "Wavelength [nm]"; +const QString BeamItem::P_WAVELENGTH = "Wavelength"; const QString BeamItem::P_INCLINATION_ANGLE = "Inclination Angle"; const QString BeamItem::P_AZIMUTHAL_ANGLE = "Azimuthal Angle"; BeamItem::BeamItem(ParameterizedItem *parent) : ParameterizedItem(Constants::BeamType, parent) { - setItemName(Constants::BeamType); - registerProperty(P_INTENSITY, 1e+08); - registerProperty(P_WAVELENGTH, 0.1, PropertyAttribute(AttLimits::lowerLimited(1e-4), 4)); - registerProperty(P_AZIMUTHAL_ANGLE, AngleProperty::Degrees(0.0), PropertyAttribute(AttLimits::limited(-90.0, 90.0), 3)); - registerProperty(P_INCLINATION_ANGLE, AngleProperty::Degrees(0.2)); + ScientificDoubleProperty intensity(1e+08); + registerProperty(P_INTENSITY, intensity.getVariant(), PropertyAttribute(AttLimits::limited(0.0, 1e+32))); + + registerGroupProperty(P_WAVELENGTH, Constants::BeamWavelengthType); +// BeamDistributionItem *distributionItem = dynamic_cast<BeamDistributionItem *>(item); +// distributionItem->setInitialValue(0.1, PropertyAttribute(PropertyAttribute::HIDDEN, AttLimits::lowerLimited(1e-4), 4)); + + registerGroupProperty(P_INCLINATION_ANGLE, Constants::BeamInclinationAngleType); +// BeamDistributionItem *distributionItem = dynamic_cast<BeamDistributionItem *>(item); +// distributionItem->setInitialValue(0.2, PropertyAttribute(PropertyAttribute::HIDDEN, AttLimits::limited(0.0, 90.0), 2)); + + registerGroupProperty(P_AZIMUTHAL_ANGLE, Constants::BeamAzimuthalAngleType); +// distributionItem = dynamic_cast<BeamDistributionItem *>(item); +// distributionItem->setInitialValue(0.0, PropertyAttribute(PropertyAttribute::HIDDEN, AttLimits::limited(-90.0, 90.0), 2)); +} + +double BeamItem::getIntensity() const +{ + ScientificDoubleProperty intensity = getRegisteredProperty(P_INTENSITY).value<ScientificDoubleProperty>(); + return intensity.getValue(); } +void BeamItem::setIntensity(double value) +{ + ScientificDoubleProperty intensity = getRegisteredProperty(P_INTENSITY).value<ScientificDoubleProperty>(); + intensity.setValue(value); + setRegisteredProperty(P_INTENSITY, intensity.getVariant()); +} -void BeamItem::onPropertyChange(const QString &name) +double BeamItem::getWavelength() const { - if(name == P_INCLINATION_ANGLE) { - qDebug() << "BeamItem::onPropertyChange()" << name; - AngleProperty inclination_angle = getRegisteredProperty(BeamItem::P_INCLINATION_ANGLE).value<AngleProperty>(); + ParameterizedItem *beamWavelength = getSubItems()[P_WAVELENGTH]; + Q_ASSERT(beamWavelength); + return beamWavelength->getRegisteredProperty(BeamDistributionItem::P_CACHED_VALUE).toDouble(); +} - AngleProperty azimuthal_angle = getRegisteredProperty(BeamItem::P_AZIMUTHAL_ANGLE).value<AngleProperty>(); - azimuthal_angle.setUnits(inclination_angle.getUnits()); - setRegisteredProperty(P_AZIMUTHAL_ANGLE, azimuthal_angle.getVariant()); - } - ParameterizedItem::onPropertyChange(name); +void BeamItem::setWavelength(double value, const QString &distribution_name) +{ + Q_UNUSED(distribution_name); + ParameterizedItem *beamWavelength = getSubItems()[P_WAVELENGTH]; + Q_ASSERT(beamWavelength); + ParameterizedItem *distributionItem = beamWavelength->setGroupProperty(BeamDistributionItem::P_DISTRIBUTION, Constants::DistributionNoneType); + Q_ASSERT(distributionItem); + distributionItem->setRegisteredProperty(DistributionNoneItem::P_VALUE, value); } + +double BeamItem::getInclinationAngle() const +{ + ParameterizedItem *angleItem = getSubItems()[P_INCLINATION_ANGLE]; + Q_ASSERT(angleItem); + return angleItem->getRegisteredProperty(BeamDistributionItem::P_CACHED_VALUE).toDouble(); +} + +void BeamItem::setInclinationAngle(double value, const QString &distribution_name) +{ + Q_UNUSED(distribution_name); + ParameterizedItem *angleItem = getSubItems()[P_INCLINATION_ANGLE]; + Q_ASSERT(angleItem); + ParameterizedItem *distributionItem = angleItem->setGroupProperty(BeamDistributionItem::P_DISTRIBUTION, Constants::DistributionNoneType); + Q_ASSERT(distributionItem); + distributionItem->setRegisteredProperty(DistributionNoneItem::P_VALUE, value); +} + +double BeamItem::getAzimuthalAngle() const +{ + ParameterizedItem *angleItem = getSubItems()[P_AZIMUTHAL_ANGLE]; + Q_ASSERT(angleItem); + return angleItem->getRegisteredProperty(BeamDistributionItem::P_CACHED_VALUE).toDouble(); +} + +void BeamItem::setAzimuthalAngle(double value, const QString &distribution_name) +{ + Q_UNUSED(distribution_name); + ParameterizedItem *angleItem = getSubItems()[P_AZIMUTHAL_ANGLE]; + Q_ASSERT(angleItem); + ParameterizedItem *distributionItem = angleItem->setGroupProperty(BeamDistributionItem::P_DISTRIBUTION, Constants::DistributionNoneType); + Q_ASSERT(distributionItem); + distributionItem->setRegisteredProperty(DistributionNoneItem::P_VALUE, value); +} + diff --git a/GUI/coregui/Models/BeamItem.h b/GUI/coregui/Models/BeamItem.h index 22ee07f35cbac38e8f8de84ee2b3b78ec0a87ac8..4554326fd9c5c88bc37f6811ef3fc12e7f35698a 100644 --- a/GUI/coregui/Models/BeamItem.h +++ b/GUI/coregui/Models/BeamItem.h @@ -16,7 +16,6 @@ #ifndef BEAMITEM_H #define BEAMITEM_H - #include "ParameterizedItem.h" class BA_CORE_API_ BeamItem : public ParameterizedItem @@ -30,11 +29,18 @@ public: explicit BeamItem(ParameterizedItem *parent=0); ~BeamItem(){} - void onPropertyChange(const QString &name); + double getIntensity() const; + void setIntensity(double value); -}; + double getWavelength() const; + void setWavelength(double value, const QString &distribution_name = QString()); + double getInclinationAngle() const; + void setInclinationAngle(double value, const QString &distribution_name = QString()); + double getAzimuthalAngle() const; + void setAzimuthalAngle(double value, const QString &distribution_name = QString()); +}; #endif diff --git a/GUI/coregui/Models/BeamWavelengthItem.cpp b/GUI/coregui/Models/BeamWavelengthItem.cpp new file mode 100644 index 0000000000000000000000000000000000000000..ebe72a242e57646521244255a785059620eb7eda --- /dev/null +++ b/GUI/coregui/Models/BeamWavelengthItem.cpp @@ -0,0 +1,24 @@ +// ************************************************************************** // +// +// BornAgain: simulate and fit scattering at grazing incidence +// +//! @file coregui/Models/BeamWavelengthItem.cpp +//! @brief Implements class BeamWavelengthItem +//! +//! @homepage http://www.bornagainproject.org +//! @license GNU General Public License v3 or higher (see COPYING) +//! @copyright Forschungszentrum Jülich GmbH 2015 +//! @authors Scientific Computing Group at MLZ Garching +//! @authors C. Durniak, M. Ganeva, G. Pospelov, W. Van Herck, J. Wuttke +// +// ************************************************************************** // + +#include "BeamWavelengthItem.h" + +BeamWavelengthItem::BeamWavelengthItem(ParameterizedItem *parent) + : BeamDistributionItem(Constants::BeamWavelengthType, parent) +{ + setItemName(Constants::BeamWavelengthType); + setRegisteredProperty(BeamDistributionItem::P_CACHED_VALUE, 0.1); + setPropertyAttribute(BeamDistributionItem::P_CACHED_VALUE, PropertyAttribute(PropertyAttribute::HIDDEN, AttLimits::lowerLimited(1e-4), 4)); +} diff --git a/GUI/coregui/Models/BeamWavelengthItem.h b/GUI/coregui/Models/BeamWavelengthItem.h new file mode 100644 index 0000000000000000000000000000000000000000..5faa695d415b8da34365f421d6e9630afb2d3db9 --- /dev/null +++ b/GUI/coregui/Models/BeamWavelengthItem.h @@ -0,0 +1,30 @@ +// ************************************************************************** // +// +// BornAgain: simulate and fit scattering at grazing incidence +// +//! @file coregui/Models/BeamWavelengthItem.h +//! @brief Defines class BeamWavelengthItem +//! +//! @homepage http://www.bornagainproject.org +//! @license GNU General Public License v3 or higher (see COPYING) +//! @copyright Forschungszentrum Jülich GmbH 2015 +//! @authors Scientific Computing Group at MLZ Garching +//! @authors C. Durniak, M. Ganeva, G. Pospelov, W. Van Herck, J. Wuttke +// +// ************************************************************************** // + +#ifndef BEAMWAVELENGTHITEM_H +#define BEAMWAVELENGTHITEM_H + +#include "WinDllMacros.h" +#include "BeamDistributionItem.h" + +class BA_CORE_API_ BeamWavelengthItem : public BeamDistributionItem +{ + Q_OBJECT +public: + explicit BeamWavelengthItem(ParameterizedItem *parent=0); + ~BeamWavelengthItem(){} +}; + +#endif diff --git a/GUI/coregui/Models/DetectorItems.cpp b/GUI/coregui/Models/DetectorItems.cpp index 239cd9b5c1b35c402f871cd7e9e1bec0be725838..d43baaabdc145b7cb38a112d08e2b7d40fe785ec 100644 --- a/GUI/coregui/Models/DetectorItems.cpp +++ b/GUI/coregui/Models/DetectorItems.cpp @@ -16,6 +16,7 @@ #include "DetectorItems.h" #include "ComboProperty.h" #include "AngleProperty.h" +#include "AxesItems.h" #include <QDebug> const QString DetectorItem::P_DETECTOR = "Detector"; @@ -27,59 +28,33 @@ DetectorItem::DetectorItem(ParameterizedItem *parent) registerGroupProperty(P_DETECTOR, Constants::DetectorGroup); } +// -------------------------------------------------------------------------- // -const QString PhiAlphaDetectorItem::P_AXES_UNITS = "Axes Units"; const QString PhiAlphaDetectorItem::P_BINNING = "Binning"; -const QString PhiAlphaDetectorItem::P_NPHI = "Phi, nbins"; -const QString PhiAlphaDetectorItem::P_PHI_MIN = "Phi, min"; -const QString PhiAlphaDetectorItem::P_PHI_MAX = "Phi, max"; -const QString PhiAlphaDetectorItem::P_NALPHA = "Alpha, nbins"; -const QString PhiAlphaDetectorItem::P_ALPHA_MIN = "Alpha, min"; -const QString PhiAlphaDetectorItem::P_ALPHA_MAX = "Alpha, max"; +const QString PhiAlphaDetectorItem::P_PHI_AXIS = "Phi axis"; +const QString PhiAlphaDetectorItem::P_ALPHA_AXIS = "Alpha axis"; +const QString PhiAlphaDetectorItem::P_RESOLUTION_FUNCTION = "Distribution"; PhiAlphaDetectorItem::PhiAlphaDetectorItem(ParameterizedItem *parent) : ParameterizedItem(Constants::PhiAlphaDetectorType, parent) { setItemName(Constants::PhiAlphaDetectorType); - ComboProperty binning; - binning << "Const KBin" << "Fixed"; + binning << Constants::AXIS_CONSTK_BINNING << Constants::AXIS_FIXED_BINNING; registerProperty(P_BINNING, binning.getVariant()); - registerProperty(P_NPHI, 100); - registerProperty(P_PHI_MIN, AngleProperty::Degrees(-1.0)); - registerProperty(P_PHI_MAX, AngleProperty::Degrees(1.0)); - registerProperty(P_NALPHA, 100); - registerProperty(P_ALPHA_MIN, AngleProperty::Degrees(0.0)); - registerProperty(P_ALPHA_MAX, AngleProperty::Degrees(2.0)); - registerProperty(P_AXES_UNITS, AngleProperty::Degrees()); -} - - -void PhiAlphaDetectorItem::onPropertyChange(const QString &name) -{ + registerGroupProperty(P_PHI_AXIS, Constants::BasicAxisType); + getSubItems()[P_PHI_AXIS]->setPropertyAppearance(BasicAxisItem::P_TITLE, PropertyAttribute::HIDDEN); + getSubItems()[P_PHI_AXIS]->setRegisteredProperty(BasicAxisItem::P_MIN, -1.0); + getSubItems()[P_PHI_AXIS]->setRegisteredProperty(BasicAxisItem::P_MAX, 1.0); - if(name == P_AXES_UNITS) { - qDebug() << "PhiAlphaDetectorItem::onPropertyChange()" << name; - AngleProperty axes_units = getRegisteredProperty(P_AXES_UNITS).value<AngleProperty>(); + registerGroupProperty(P_ALPHA_AXIS, Constants::BasicAxisType); + getSubItems()[P_ALPHA_AXIS]->setPropertyAppearance(BasicAxisItem::P_TITLE, PropertyAttribute::HIDDEN); + getSubItems()[P_ALPHA_AXIS]->setRegisteredProperty(BasicAxisItem::P_MIN, 0.0); + getSubItems()[P_ALPHA_AXIS]->setRegisteredProperty(BasicAxisItem::P_MAX, 2.0); - AngleProperty phi_min_property = getRegisteredProperty(PhiAlphaDetectorItem::P_PHI_MIN).value<AngleProperty>(); - phi_min_property.setUnits(axes_units.getUnits()); - setRegisteredProperty(P_PHI_MIN, phi_min_property.getVariant()); - - AngleProperty phi_max_property = getRegisteredProperty(PhiAlphaDetectorItem::P_PHI_MAX).value<AngleProperty>(); - phi_max_property.setUnits(axes_units.getUnits()); - setRegisteredProperty(P_PHI_MAX, phi_max_property.getVariant()); - - AngleProperty alpha_min_property = getRegisteredProperty(PhiAlphaDetectorItem::P_ALPHA_MIN).value<AngleProperty>(); - alpha_min_property.setUnits(axes_units.getUnits()); - setRegisteredProperty(P_ALPHA_MIN, alpha_min_property.getVariant()); + registerGroupProperty(P_RESOLUTION_FUNCTION, Constants::ResolutionFunctionGroup); +} - AngleProperty alpha_max_property = getRegisteredProperty(PhiAlphaDetectorItem::P_ALPHA_MAX).value<AngleProperty>(); - alpha_max_property.setUnits(axes_units.getUnits()); - setRegisteredProperty(P_ALPHA_MAX, alpha_max_property.getVariant()); - } - ParameterizedItem::onPropertyChange(name); -} diff --git a/GUI/coregui/Models/DetectorItems.h b/GUI/coregui/Models/DetectorItems.h index 6dc4a4f7904c50a66d557c9104d89d4d8a58494b..03cafb70872d25865d689eb29209edbd83277de3 100644 --- a/GUI/coregui/Models/DetectorItems.h +++ b/GUI/coregui/Models/DetectorItems.h @@ -28,33 +28,16 @@ public: ~DetectorItem(){} }; - class PhiAlphaDetectorItem : public ParameterizedItem { - Q_OBJECT public: - static const QString P_AXES_UNITS; static const QString P_BINNING; - static const QString P_PHI_MIN; - static const QString P_PHI_MAX; - static const QString P_NPHI; - static const QString P_ALPHA_MIN; - static const QString P_ALPHA_MAX; - static const QString P_NALPHA; + static const QString P_PHI_AXIS; + static const QString P_ALPHA_AXIS; + static const QString P_RESOLUTION_FUNCTION; explicit PhiAlphaDetectorItem(ParameterizedItem *parent=0); ~PhiAlphaDetectorItem(){} - - virtual void onPropertyChange(const QString &name); }; -//class XYDetectorItem : public ParameterizedItem -//{ -// Q_OBJECT -//public: -// explicit XYDetectorItem(ParameterizedItem *parent=0); -// ~XYDetectorItem(){} - -//}; - #endif diff --git a/GUI/coregui/Models/DistributionItem.cpp b/GUI/coregui/Models/DistributionItem.cpp index 59574aff6ac1571322aee7ee3ab225d867a6a48c..52d27a17d366e68aa226e9bdc20314ca7b0c6fab 100644 --- a/GUI/coregui/Models/DistributionItem.cpp +++ b/GUI/coregui/Models/DistributionItem.cpp @@ -15,6 +15,48 @@ #include "DistributionItem.h" #include "ComboProperty.h" +#include <QDebug> + +const QString DistributionItem::P_NUMBER_OF_SAMPLES = "Number of samples"; +const QString DistributionItem::P_SIGMA_FACTOR = "Sigma factor"; + +DistributionItem::DistributionItem(const QString name, ParameterizedItem *parent) + : ParameterizedItem(name, parent) +{ + +} + +void DistributionItem::register_number_of_samples() +{ + registerProperty(P_NUMBER_OF_SAMPLES, 5); +} + +void DistributionItem::register_sigma_factor() +{ + registerProperty(P_SIGMA_FACTOR, 2.0); +} + +/* ------------------------------------------------ */ + +const QString DistributionNoneItem::P_VALUE = "Value"; + +DistributionNoneItem::DistributionNoneItem(ParameterizedItem *parent) + : DistributionItem(Constants::DistributionNoneType, parent) +{ + setItemName(Constants::DistributionNoneType); + registerProperty(P_VALUE, 0.1); +} + +IDistribution1D *DistributionNoneItem::createDistribution() const +{ + return 0; +} + +void DistributionNoneItem::init_parameters(double value, PropertyAttribute attribute) +{ + setRegisteredProperty(DistributionNoneItem::P_VALUE, value); + setPropertyAttribute(DistributionNoneItem::P_VALUE, attribute); +} /* ------------------------------------------------ */ @@ -27,6 +69,7 @@ DistributionGateItem::DistributionGateItem(ParameterizedItem *parent) setItemName(Constants::DistributionGateType); registerProperty(P_MIN, 0.0); registerProperty(P_MAX, 1.0); + register_number_of_samples(); } IDistribution1D *DistributionGateItem::createDistribution() const @@ -36,10 +79,18 @@ IDistribution1D *DistributionGateItem::createDistribution() const return new DistributionGate(min, max); } +void DistributionGateItem::init_parameters(double value, PropertyAttribute attribute) +{ + setRegisteredProperty(P_MIN, value - 0.1*value); + setPropertyAttribute(P_MIN, attribute); + setRegisteredProperty(P_MAX, value + 0.1*value); + setPropertyAttribute(P_MAX, attribute); +} + /* ------------------------------------------------ */ const QString DistributionLorentzItem::P_MEAN = "Mean"; -const QString DistributionLorentzItem::P_HWHM = "Half width half maximum"; +const QString DistributionLorentzItem::P_HWHM = "HWHM"; DistributionLorentzItem::DistributionLorentzItem(ParameterizedItem *parent) : DistributionItem(Constants::DistributionLorentzType, parent) @@ -47,6 +98,8 @@ DistributionLorentzItem::DistributionLorentzItem(ParameterizedItem *parent) setItemName(Constants::DistributionLorentzType); registerProperty(P_MEAN, 0.0); registerProperty(P_HWHM, 1.0); + register_number_of_samples(); + register_sigma_factor(); } IDistribution1D *DistributionLorentzItem::createDistribution() const @@ -56,6 +109,14 @@ IDistribution1D *DistributionLorentzItem::createDistribution() const return new DistributionLorentz(mean, hwhm); } +void DistributionLorentzItem::init_parameters(double value, PropertyAttribute attribute) +{ + setRegisteredProperty(P_MEAN, value); + setPropertyAttribute(P_MEAN, attribute); + setRegisteredProperty(P_HWHM, 0.1*value); + setPropertyAttribute(P_HWHM, attribute); +} + /* ------------------------------------------------ */ const QString DistributionGaussianItem::P_MEAN = "Mean"; @@ -67,6 +128,8 @@ DistributionGaussianItem::DistributionGaussianItem(ParameterizedItem *parent) setItemName(Constants::DistributionGaussianType); registerProperty(P_MEAN, 0.0); registerProperty(P_STD_DEV, 1.0); + register_number_of_samples(); + register_sigma_factor(); } IDistribution1D *DistributionGaussianItem::createDistribution() const @@ -76,6 +139,14 @@ IDistribution1D *DistributionGaussianItem::createDistribution() const return new DistributionGaussian(mean, std_dev); } +void DistributionGaussianItem::init_parameters(double value, PropertyAttribute attribute) +{ + setRegisteredProperty(P_MEAN, value); + setPropertyAttribute(P_MEAN, attribute); + setRegisteredProperty(P_STD_DEV, 0.1*value); + setPropertyAttribute(P_STD_DEV, attribute); +} + /* ------------------------------------------------ */ const QString DistributionLogNormalItem::P_MEDIAN = "Median"; @@ -87,6 +158,8 @@ DistributionLogNormalItem::DistributionLogNormalItem(ParameterizedItem *parent) setItemName(Constants::DistributionLogNormalType); registerProperty(P_MEDIAN, 1.0); registerProperty(P_SCALE_PAR, 1.0); + register_number_of_samples(); + register_sigma_factor(); } IDistribution1D *DistributionLogNormalItem::createDistribution() const @@ -96,6 +169,14 @@ IDistribution1D *DistributionLogNormalItem::createDistribution() const return new DistributionLogNormal(median, scale_par); } +void DistributionLogNormalItem::init_parameters(double value, PropertyAttribute attribute) +{ + setRegisteredProperty(P_MEDIAN, value); + setPropertyAttribute(P_MEDIAN, attribute); + setRegisteredProperty(P_SCALE_PAR, 0.1*value); + setPropertyAttribute(P_SCALE_PAR, attribute); +} + /* ------------------------------------------------ */ const QString DistributionCosineItem::P_MEAN = "Mean"; @@ -107,6 +188,8 @@ DistributionCosineItem::DistributionCosineItem(ParameterizedItem *parent) setItemName(Constants::DistributionCosineType); registerProperty(P_MEAN, 0.0); registerProperty(P_SIGMA, 1.0); + register_number_of_samples(); + register_sigma_factor(); } IDistribution1D *DistributionCosineItem::createDistribution() const @@ -115,3 +198,11 @@ IDistribution1D *DistributionCosineItem::createDistribution() const double sigma = getRegisteredProperty(P_SIGMA).toDouble(); return new DistributionCosine(mean, sigma); } + +void DistributionCosineItem::init_parameters(double value, PropertyAttribute attribute) +{ + setRegisteredProperty(P_MEAN, value); + setPropertyAttribute(P_MEAN, attribute); + setRegisteredProperty(P_SIGMA, 0.1*value); + setPropertyAttribute(P_SIGMA, attribute); +} diff --git a/GUI/coregui/Models/DistributionItem.h b/GUI/coregui/Models/DistributionItem.h index 21db8327b0abe9cf66b81d24153e4cb4cf3b6339..3a58893f1cc147eb692a14c8ce67e77ae16db0b1 100644 --- a/GUI/coregui/Models/DistributionItem.h +++ b/GUI/coregui/Models/DistributionItem.h @@ -19,15 +19,32 @@ #include "ParameterizedItem.h" #include "Distributions.h" + class BA_CORE_API_ DistributionItem : public ParameterizedItem { Q_OBJECT public: - explicit DistributionItem(const QString name, ParameterizedItem *parent=0) - : ParameterizedItem(name, parent) {} + static const QString P_NUMBER_OF_SAMPLES; + static const QString P_SIGMA_FACTOR; + explicit DistributionItem(const QString name, ParameterizedItem *parent=0); virtual ~DistributionItem() {} virtual IDistribution1D *createDistribution() const=0; + + virtual void init_parameters(double, PropertyAttribute){} +protected: + void register_number_of_samples(); + void register_sigma_factor(); +}; + +class BA_CORE_API_ DistributionNoneItem : public DistributionItem +{ + Q_OBJECT +public: + static const QString P_VALUE; + explicit DistributionNoneItem(ParameterizedItem *parent=0); + virtual IDistribution1D *createDistribution() const; + virtual void init_parameters(double value, PropertyAttribute attribute); }; @@ -40,6 +57,7 @@ public: explicit DistributionGateItem(ParameterizedItem *parent=0); virtual IDistribution1D *createDistribution() const; + virtual void init_parameters(double value, PropertyAttribute attribute); }; @@ -52,6 +70,7 @@ public: explicit DistributionLorentzItem(ParameterizedItem *parent=0); virtual IDistribution1D *createDistribution() const; + virtual void init_parameters(double value, PropertyAttribute attribute); }; @@ -64,6 +83,7 @@ public: explicit DistributionGaussianItem(ParameterizedItem *parent=0); virtual IDistribution1D *createDistribution() const; + virtual void init_parameters(double value, PropertyAttribute attribute); }; @@ -76,6 +96,7 @@ public: explicit DistributionLogNormalItem(ParameterizedItem *parent=0); virtual IDistribution1D *createDistribution() const; + virtual void init_parameters(double value, PropertyAttribute attribute); }; @@ -88,6 +109,7 @@ public: explicit DistributionCosineItem(ParameterizedItem *parent=0); virtual IDistribution1D *createDistribution() const; + virtual void init_parameters(double value, PropertyAttribute attribute); }; #endif // DISTRIBUTIONITEM_H diff --git a/GUI/coregui/Models/DomainObjectBuilder.cpp b/GUI/coregui/Models/DomainObjectBuilder.cpp index c9c140c1d1f64d8e9ab32041a4b7f5979398d00f..aa73f651c26f26c2a362c17085d0f019a2e7c23b 100644 --- a/GUI/coregui/Models/DomainObjectBuilder.cpp +++ b/GUI/coregui/Models/DomainObjectBuilder.cpp @@ -30,45 +30,15 @@ #include "ParticleDistribution.h" #include "Distributions.h" #include "ComboProperty.h" - +#include "MultiLayerItem.h" #include <QDebug> - #include <boost/scoped_ptr.hpp> -DomainObjectBuilder::DomainObjectBuilder() - : mp_sample(0) - , m_instrument(0) -{ - -} - -DomainObjectBuilder::~DomainObjectBuilder() -{ - delete mp_sample; - delete m_instrument; -} - -void DomainObjectBuilder::buildItem(const ParameterizedItem &item) -{ - if (item.modelType() == Constants::MultiLayerType) { - delete mp_sample; - mp_sample = buildMultiLayer(item); - } - else if(item.modelType() == Constants::InstrumentType) { - delete m_instrument; - m_instrument = buildInstrument(item); - } - else { - throw GUIHelpers::Error("DomainObjectBuilder::buildItem() -> Error. Not a suitable top level object."); - } -} - -MultiLayer *DomainObjectBuilder::buildMultiLayer( - const ParameterizedItem &item) const +MultiLayer *DomainObjectBuilder::buildMultiLayer(const ParameterizedItem &multilayer_item) const { - MultiLayer *result = TransformToDomain::createMultiLayer(item); - QList<ParameterizedItem *> children = item.childItems(); + MultiLayer *result = TransformToDomain::createMultiLayer(multilayer_item); + QList<ParameterizedItem *> children = multilayer_item.childItems(); for (int i=0; i<children.size(); ++i) { if (children[i]->modelType() == Constants::LayerType) { boost::scoped_ptr<Layer> P_layer(buildLayer(*children[i])); @@ -238,10 +208,10 @@ IInterferenceFunction *DomainObjectBuilder::buildInterferenceFunction( } -Instrument *DomainObjectBuilder::buildInstrument(const ParameterizedItem &item) const +Instrument *DomainObjectBuilder::buildInstrument(const ParameterizedItem &instrument_item) const { - Instrument *result = TransformToDomain::createInstrument(item); - QList<ParameterizedItem *> children = item.childItems(); + Instrument *result = TransformToDomain::createInstrument(instrument_item); + QList<ParameterizedItem *> children = instrument_item.childItems(); for (int i=0; i<children.size(); ++i) { if (children[i]->modelType() == Constants::BeamType) { boost::scoped_ptr<Beam> P_beam(buildBeam(*children[i])); diff --git a/GUI/coregui/Models/DomainObjectBuilder.h b/GUI/coregui/Models/DomainObjectBuilder.h index 53099aa84fdd779d7623ebe4bd3a46e7b3695540..d5f8ddbc4e2737f7499a8c39a69506498e5e87e4 100644 --- a/GUI/coregui/Models/DomainObjectBuilder.h +++ b/GUI/coregui/Models/DomainObjectBuilder.h @@ -33,16 +33,11 @@ class LayerRoughness; class BA_CORE_API_ DomainObjectBuilder { public: - explicit DomainObjectBuilder(); - ~DomainObjectBuilder(); + explicit DomainObjectBuilder(){} + ~DomainObjectBuilder(){} - void buildItem(const ParameterizedItem &item); - - ISample *getSample() { return mp_sample; } - Instrument *getInstrument() { return m_instrument; } - - MultiLayer *buildMultiLayer(const ParameterizedItem &item) const; - Instrument *buildInstrument(const ParameterizedItem &item) const; + MultiLayer *buildMultiLayer(const ParameterizedItem &multilayer_item) const; + Instrument *buildInstrument(const ParameterizedItem &instrument_item) const; private: Layer *buildLayer(const ParameterizedItem &item) const; @@ -60,9 +55,6 @@ private: void addParticleToLayout(ParticleLayout *result, ParameterizedItem *particle_item, double depth, double abundance, const Particle& particle) const; - - ISample *mp_sample; - Instrument *m_instrument; }; #endif // DOMAINOBJECTBUILDER_H diff --git a/GUI/coregui/Models/DomainSimulationBuilder.cpp b/GUI/coregui/Models/DomainSimulationBuilder.cpp index a859c29bb3fa73e664474404f1591ee04f319585..da48800ee1226ae01ccf45e5245ff05d4dee2b2d 100644 --- a/GUI/coregui/Models/DomainSimulationBuilder.cpp +++ b/GUI/coregui/Models/DomainSimulationBuilder.cpp @@ -17,28 +17,33 @@ #include "SampleModel.h" #include "InstrumentModel.h" #include "Instrument.h" +#include "InstrumentItem.h" #include "MultiLayer.h" +#include "MultiLayerItem.h" +#include "BeamItem.h" #include "DomainObjectBuilder.h" +#include "TransformToDomain.h" #include <QDebug> +#include <boost/scoped_ptr.hpp> + //! Creates domain simulation from sample and instrument models for given names of MultiLayer and Instrument Simulation *DomainSimulationBuilder::getSimulation(SampleModel *sampleModel, const QString &sample_name, InstrumentModel *instrumentModel, const QString &instrument_name) { qDebug() << "QuickSimulationHelper::getSimulation() " << sample_name << instrument_name; + DomainObjectBuilder builder; - Simulation *result = new Simulation; - - MultiLayer *multilayer = getMultiLayer(sampleModel, sample_name); - Q_ASSERT(multilayer); + MultiLayerItem *sampleItem = sampleModel->getMultiLayerItem(sample_name); + InstrumentItem *instrumentItem = instrumentModel->getInstrumentItem(instrument_name); - Instrument *instrument = getInstrument(instrumentModel, instrument_name); - Q_ASSERT(instrument); + Simulation *result = new Simulation; + boost::scoped_ptr<MultiLayer> multilayer(builder.buildMultiLayer(*sampleItem)); + boost::scoped_ptr<Instrument> instrument(builder.buildInstrument(*instrumentItem)); result->setSample(*multilayer); result->setInstrument(*instrument); - delete multilayer; - delete instrument; + TransformToDomain::addDistributionParametersToSimulation(*instrumentItem->getBeamItem(), result); return result; } @@ -51,54 +56,25 @@ Simulation *DomainSimulationBuilder::getSimulation(SampleModel *sampleModel, Ins } -//! Creates domain instrument from InstrumentModel and given instrument name. If name is empty, then uses first instrument in the model. -Instrument *DomainSimulationBuilder::getInstrument(InstrumentModel *instrumentModel, const QString &instrument_name) -{ - qDebug() << "QuickSimulationHelper::getInstrument()"; +////! Creates domain instrument from InstrumentModel and given instrument name. If name is empty, then uses first instrument in the model. +//Instrument *DomainSimulationBuilder::getInstrument(InstrumentModel *instrumentModel, const QString &instrument_name) +//{ +// qDebug() << "DomainSimulationBuilder::getInstrument()"; +// DomainObjectBuilder builder; +// ParameterizedItem *instrumentItem = instrumentModel->getInstrumentItem(instrument_name); +// return builder.buildInstrument(*instrumentItem); +//} - Instrument *result(0); - QMap<QString, ParameterizedItem *> instrumentMap = instrumentModel->getInstrumentMap(); +////! Creates domain MultiLayer from SampleModel and given MultiLayer name. If name is empty, then uses first MultiLayer in the model. +//MultiLayer *DomainSimulationBuilder::getMultiLayer(SampleModel *sampleModel, const QString &sample_name) +//{ +// qDebug() << "DomainSimulationBuilder::getMultiLayer()"; - if(instrumentMap.size()) { - ParameterizedItem *instrumentItem(0); - if(instrument_name.isEmpty()) { - instrumentItem = instrumentMap.first(); - } else { - instrumentItem = instrumentMap[instrument_name]; - } - - Q_ASSERT(instrumentItem); - DomainObjectBuilder builder; - result = builder.buildInstrument(*instrumentItem); - } - - return result; -} +// DomainObjectBuilder builder; +// ParameterizedItem *sampleItem = sampleModel->getMultiLayerItem(sample_name); +// return builder.buildMultiLayer(*sampleItem); +//} -//! Creates domain MultiLayer from SampleModel and given MultiLayer name. If name is empty, then uses first MultiLayer in the model. -MultiLayer *DomainSimulationBuilder::getMultiLayer(SampleModel *sampleModel, const QString &sample_name) -{ - qDebug() << "QuickSimulationHelper::getMultiLayer()"; - - MultiLayer *result(0); - - QMap<QString, ParameterizedItem *> sampleMap = sampleModel->getSampleMap(); - - if(sampleMap.size()) { - ParameterizedItem *sampleItem(0); - if(sample_name.isEmpty()) { - sampleItem = sampleMap.first(); - } else { - sampleItem = sampleMap[sample_name]; - } - - Q_ASSERT(sampleItem); - DomainObjectBuilder builder; - result = builder.buildMultiLayer(*sampleItem); - } - - return result; -} diff --git a/GUI/coregui/Models/DomainSimulationBuilder.h b/GUI/coregui/Models/DomainSimulationBuilder.h index 5bb8c87b2bf591f1dd763968b71f532e5f3a629f..0c8805c1b0019a08e2d1db00eafcf1dcadd67b64 100644 --- a/GUI/coregui/Models/DomainSimulationBuilder.h +++ b/GUI/coregui/Models/DomainSimulationBuilder.h @@ -35,10 +35,10 @@ public: static Simulation *getSimulation(SampleModel *sampleModel, InstrumentModel *instrumentModel); -private: - static Instrument *getInstrument(InstrumentModel *instrumentModel, const QString &instrument_name = QString()); +//private: +// static Instrument *getInstrument(InstrumentModel *instrumentModel, const QString &instrument_name = QString()); - static MultiLayer *getMultiLayer(SampleModel *sampleModel, const QString &sample_name = QString()); +// static MultiLayer *getMultiLayer(SampleModel *sampleModel, const QString &sample_name = QString()); }; #endif diff --git a/GUI/coregui/Models/FancyGroupProperty.cpp b/GUI/coregui/Models/FancyGroupProperty.cpp index ca82618812abe49f93d3b8c3075d7f0783572f47..4ac972485a8af70619376740f02be546f9eda439 100644 --- a/GUI/coregui/Models/FancyGroupProperty.cpp +++ b/GUI/coregui/Models/FancyGroupProperty.cpp @@ -64,7 +64,7 @@ void FancyGroupProperty::setValue(const QString &value) if(m_parent) { m_parent->addPropertyItem(getGroupName(), createCorrespondingItem()); - emit m_parent->propertyItemChanged(getGroupName()); + //emit m_parent->subItemChanged(getGroupName()); } } diff --git a/GUI/coregui/Models/GUIExamplesFactory.cpp b/GUI/coregui/Models/GUIExamplesFactory.cpp index 1ebaf3619c5e84f846b9f4a6d952ff0710eecc2c..ddfe80c3fb523fe74645f3b2c35c29b2ed73adce 100644 --- a/GUI/coregui/Models/GUIExamplesFactory.cpp +++ b/GUI/coregui/Models/GUIExamplesFactory.cpp @@ -35,6 +35,7 @@ QMap<QString, QString > init_NameToRegistry() result["example05"] = "LayerWithRoughness"; result["example06"] = "gui_isgisaxs06a"; result["example07"] = "gui_isgisaxs07"; + result["example08"] = "beam_divergence"; return result; } @@ -45,51 +46,26 @@ bool GUIExamplesFactory::isValidExampleName(const QString &name) return m_name_to_registry.contains(name); } - +//! Populate sample model with ParameterizedItem *GUIExamplesFactory::createSampleItems(const QString &name, SampleModel *sampleModel) { - if(sampleModel->getModelTag() != SessionXML::SampleModelTag ) { - throw GUIHelpers::Error("GUIExamplesFactory::createSampleItems() -> Error. Not a SampleModelTag"); - } - QString exampleName = m_name_to_registry[name]; - SimulationRegistry registry; - boost::scoped_ptr<Simulation> simulation(registry.createItem(exampleName.toLatin1().data())); + boost::scoped_ptr<Simulation> simulation(registry.createSimulation(exampleName.toStdString())); Q_ASSERT(simulation.get()); - boost::scoped_ptr<ISample> sample(simulation->getSampleBuilder()->buildSample()); - - Q_ASSERT(sample.get()); - sample->setName(name.toUtf8().constData()); - //sample->printSampleTree(); - GUIObjectBuilder guiBuilder; - return guiBuilder.populateSampleModel(sampleModel, sample.get()); - //return guiBuilder.getTopItem(); + return guiBuilder.populateSampleModel(sampleModel, *simulation, name); } ParameterizedItem *GUIExamplesFactory::createInstrumentItems(const QString &name, InstrumentModel *instrumentModel) { - if(instrumentModel->getModelTag() != SessionXML::InstrumentModelTag ) { - throw GUIHelpers::Error("GUIExamplesFactory::createInstrumentItems() -> Error. Not an InstrumentModelTag"); - } - QString exampleName = m_name_to_registry[name]; - qDebug() << " "; - qDebug() << " "; - qDebug() << " GUIExamplesFactory::createInstrumentItems()" << name << exampleName; - SimulationRegistry registry; - boost::scoped_ptr<Simulation> simulation(registry.createItem(exampleName.toLatin1().data())); + boost::scoped_ptr<Simulation> simulation(registry.createSimulation(exampleName.toStdString())); Q_ASSERT(simulation.get()); - boost::scoped_ptr<Instrument> instrument(new Instrument(simulation.get()->getInstrument())); QString instrumentName = name + "_instrument"; - instrument->setName(instrumentName.toUtf8().constData()); - - //simulation->setName(name.toUtf8().constData()); - GUIObjectBuilder guiBuilder; - return guiBuilder.populateInstrumentModel(instrumentModel, instrument.get()); + return guiBuilder.populateInstrumentModel(instrumentModel, *simulation, instrumentName); } diff --git a/GUI/coregui/Models/GUIObjectBuilder.cpp b/GUI/coregui/Models/GUIObjectBuilder.cpp index 3b910c6478b4c7103c8d91682e913849d91336e5..afba273864e1ce89313d4787f279b17376b8ae85 100644 --- a/GUI/coregui/Models/GUIObjectBuilder.cpp +++ b/GUI/coregui/Models/GUIObjectBuilder.cpp @@ -40,6 +40,7 @@ #include "ConstKBinAxis.h" #include "FixedBinAxis.h" #include "RotationItems.h" +#include "AxesItems.h" #include "ParticleDistribution.h" #include "ParticleDistributionItem.h" #include <QDebug> @@ -50,87 +51,73 @@ GUIObjectBuilder::GUIObjectBuilder() { } -ParameterizedItem *GUIObjectBuilder::populateSampleModel( - SampleModel *sampleModel, ISample *sample) + +ParameterizedItem *GUIObjectBuilder::populateSampleModel(SampleModel *sampleModel, + const Simulation &simulation, const QString &sampleName) +{ + boost::scoped_ptr<ISample> sample; + if(simulation.getSampleBuilder()) { + sample.reset(simulation.getSampleBuilder()->buildSample()); + } else if(simulation.getSample()) { + sample.reset(simulation.getSample()->clone()); + } else { + throw GUIHelpers::Error("GUIObjectBuilder::populateSampleModel() -> No valid sample"); + } + + return populateSampleModel(sampleModel, *sample, sampleName); +} + +ParameterizedItem *GUIObjectBuilder::populateSampleModel(SampleModel *sampleModel, const ISample &sample, const QString &sampleName) { Q_ASSERT(sampleModel); - Q_ASSERT(sample); m_levelToParentItem.clear(); - m_topSampleName = sample->getName().c_str(); + m_topSampleName = sampleName; + if(m_topSampleName.isEmpty()) m_topSampleName = sample.getName().c_str(); + m_sampleModel = sampleModel; - qDebug() << "GUIObjectBuilder::populateModel()" << m_topSampleName; + VisitSampleTree(sample, *this); + ParameterizedItem *result = m_levelToParentItem[0]; - //sample->accept(this); - VisitSampleTree(*sample, *this); - return m_levelToParentItem[0]; + result->setItemName(m_topSampleName); + return result; } -ParameterizedItem *GUIObjectBuilder::populateInstrumentModel( - InstrumentModel *instrumentModel, Instrument *instrument) +ParameterizedItem *GUIObjectBuilder::populateInstrumentModel(InstrumentModel *instrumentModel, + const Simulation &simulation, const QString &instrumentName) { - Q_UNUSED(instrumentModel); - Q_UNUSED(instrument); - + Q_ASSERT(instrumentModel); ParameterizedItem *instrumentItem = instrumentModel->insertNewItem(Constants::InstrumentType); - instrumentItem->setItemName(instrument->getName().c_str()); - Beam beam = instrument->getBeam(); - ParameterizedItem *beamItem = instrumentModel->insertNewItem( + if(instrumentName.isEmpty()) { + instrumentItem->setItemName(simulation.getInstrument().getName().c_str()); + } else { + instrumentItem->setItemName(instrumentName); + } + + // beam + BeamItem *beamItem = dynamic_cast<BeamItem *>(instrumentModel->insertNewItem( Constants::BeamType, - instrumentModel->indexOfItem(instrumentItem)); - beamItem->setRegisteredProperty(BeamItem::P_INTENSITY, - beam.getIntensity()); - beamItem->setRegisteredProperty(BeamItem::P_WAVELENGTH, - beam.getWavelength()); - - beamItem->setRegisteredProperty(BeamItem::P_INCLINATION_ANGLE, - AngleProperty::Degrees(Units::rad2deg(-1.0*beam.getAlpha()))); - beamItem->setRegisteredProperty(BeamItem::P_AZIMUTHAL_ANGLE, - AngleProperty::Degrees(Units::rad2deg(-1.0*beam.getPhi()))); - - Detector detector = instrument->getDetector(); + instrumentModel->indexOfItem(instrumentItem))); + + TransformFromDomain::setItemFromSample(beamItem, simulation); + + // detector ParameterizedItem *detectorItem = instrumentModel->insertNewItem( Constants::DetectorType, instrumentModel->indexOfItem(instrumentItem)); - ParameterizedItem *detectorSubItem = - detectorItem->getSubItems()[DetectorItem::P_DETECTOR]; - Q_ASSERT(detectorSubItem); - - - const IAxis &phi_axis = detector.getAxis(0); - const IAxis &alpha_axis = detector.getAxis(1); - - ComboProperty binning_property = detectorSubItem->getRegisteredProperty( - PhiAlphaDetectorItem::P_BINNING).value<ComboProperty>(); - binning_property.setValue(TransformFromDomain::getDetectorBinning(&detector)); - detectorSubItem->setRegisteredProperty( - PhiAlphaDetectorItem::P_BINNING, binning_property.getVariant()); - - detectorSubItem->setRegisteredProperty( - PhiAlphaDetectorItem::P_NPHI, (int)phi_axis.getSize()); - - detectorSubItem->setRegisteredProperty( - PhiAlphaDetectorItem::P_PHI_MIN, - AngleProperty::Degrees(Units::rad2deg(phi_axis.getMin()))); - detectorSubItem->setRegisteredProperty( - PhiAlphaDetectorItem::P_PHI_MAX, - AngleProperty::Degrees(Units::rad2deg(phi_axis.getMax()))); - - detectorSubItem->setRegisteredProperty( - PhiAlphaDetectorItem::P_NALPHA, (int)alpha_axis.getSize()); - detectorSubItem->setRegisteredProperty( - PhiAlphaDetectorItem::P_ALPHA_MIN, - AngleProperty::Degrees(Units::rad2deg(alpha_axis.getMin()))); - detectorSubItem->setRegisteredProperty( - PhiAlphaDetectorItem::P_ALPHA_MAX, - AngleProperty::Degrees(Units::rad2deg(alpha_axis.getMax()))); + + PhiAlphaDetectorItem *detectorSubItem = + dynamic_cast<PhiAlphaDetectorItem *>(detectorItem->getSubItems()[DetectorItem::P_DETECTOR]); + + TransformFromDomain::setItemFromSample(detectorSubItem, simulation); return instrumentItem; } + void GUIObjectBuilder::visit(const ParticleLayout *sample) { qDebug() << "GUIObjectBuilder::visit(const ParticleLayout *)" << getLevel(); diff --git a/GUI/coregui/Models/GUIObjectBuilder.h b/GUI/coregui/Models/GUIObjectBuilder.h index fe9fc721cc9acc7867ab8a43a5882b2afa38cf37..97583c6cb63c65843b49d146becd4927a0a018e2 100644 --- a/GUI/coregui/Models/GUIObjectBuilder.h +++ b/GUI/coregui/Models/GUIObjectBuilder.h @@ -34,9 +34,17 @@ public: virtual ~GUIObjectBuilder(){} ParameterizedItem *populateSampleModel(SampleModel *sampleModel, - ISample *sample); + const Simulation &simulation, + const QString &sampleName=QString()); + + ParameterizedItem *populateSampleModel(SampleModel *sampleModel, + const ISample &sample, + const QString &sampleName=QString()); + ParameterizedItem *populateInstrumentModel(InstrumentModel *instrumentModel, - Instrument *instrument); + const Simulation &simulation, + const QString &instrumentName=QString()); + using ISampleVisitor::visit; diff --git a/GUI/coregui/Models/GroupPropertyRegistry.cpp b/GUI/coregui/Models/GroupPropertyRegistry.cpp index 705e8432b66bdd42a9eb4f210089f2bed24556d5..12cf4a869640d739b610ea9694ca31b8b2d0436a 100644 --- a/GUI/coregui/Models/GroupPropertyRegistry.cpp +++ b/GUI/coregui/Models/GroupPropertyRegistry.cpp @@ -19,6 +19,7 @@ #include "FixedGroupProperty.h" #include "GUIHelpers.h" #include "item_constants.h" +#include <QDebug> namespace { @@ -73,6 +74,15 @@ GroupPropertyRegistry::SelectableGroupMap_t initializeSelectableGroupMap() distributions[Constants::DistributionCosineType] = "Cosine distribution"; result[Constants::DistributionGroup] = distributions; + QMap<QString, QString> distributions_ext; + distributions_ext[Constants::DistributionNoneType] = "None"; + distributions_ext[Constants::DistributionGateType] = "Gate distribution"; + distributions_ext[Constants::DistributionLorentzType] = "Lorentz distribution"; + distributions_ext[Constants::DistributionGaussianType] = "Gaussian distribution"; + distributions_ext[Constants::DistributionLogNormalType] = "Log Normal distribution"; + distributions_ext[Constants::DistributionCosineType] = "Cosine distribution"; + result[Constants::DistributionExtendedGroup] = distributions_ext; + QMap<QString, QString> pdfs_1d; pdfs_1d[Constants::FTDistribution1DCauchyType] = "Cauchy 1D"; pdfs_1d[Constants::FTDistribution1DGaussType] = "Gauss 1D"; @@ -96,6 +106,11 @@ GroupPropertyRegistry::SelectableGroupMap_t initializeSelectableGroupMap() lattices[Constants::HexagonalLatticeType] = "Hexagonal"; result[Constants::LatticeGroup] = lattices; + QMap<QString, QString> resolution_functions; + resolution_functions[Constants::ResolutionFunctionNoneType] = "None"; + resolution_functions[Constants::ResolutionFunction2DGaussianType] = "2D Gaussian"; + result[Constants::ResolutionFunctionGroup] = resolution_functions; + return result; } @@ -113,6 +128,7 @@ FancyGroupProperty_t GroupPropertyRegistry::createGroupProperty(const QString &g FancyGroupProperty_t result(new FancyGroupProperty(group_name)); if(m_selectable_group_map.contains(groupModelType)) { + qDebug() << "GroupPropertyRegistry::createGroupProperty() -> creating selectable group of groupModelType" << groupModelType; result->setGroupType(FancyGroupProperty::SELECTABLE); result->setGroupMap(m_selectable_group_map[groupModelType]); } diff --git a/GUI/coregui/Models/InstrumentModel.cpp b/GUI/coregui/Models/InstrumentModel.cpp index 758cb47cabdac5525de3ba1db1d12da560176387..49a4400cf5ab8d8ea013a5de392828cb9e0739d0 100644 --- a/GUI/coregui/Models/InstrumentModel.cpp +++ b/GUI/coregui/Models/InstrumentModel.cpp @@ -34,29 +34,12 @@ InstrumentModel *InstrumentModel::createCopy(ParameterizedItem *parent) //! returns list of Instruments defined in the model QMap<QString, ParameterizedItem *> InstrumentModel::getInstrumentMap() const { - QMap<QString, ParameterizedItem *> result; - QModelIndex parentIndex; - for( int i_row = 0; i_row < rowCount( parentIndex); ++i_row) { - QModelIndex itemIndex = index( i_row, 0, parentIndex ); - - if (ParameterizedItem *item = itemForIndex(itemIndex)){ - if(item->modelType() == Constants::InstrumentType) { - result[item->itemName()] = item; - } - } - } - return result; + return getTopItemMap(Constants::InstrumentType); } -InstrumentItem *InstrumentModel::getInstrumentItem() +InstrumentItem *InstrumentModel::getInstrumentItem(const QString &instrument_name) { - InstrumentItem *result(0); - - QMap<QString, ParameterizedItem *> instrumentMap = getInstrumentMap(); - if(instrumentMap.size()) { - result = dynamic_cast<InstrumentItem *>(instrumentMap.values().at(0)); - } - return result; + return dynamic_cast<InstrumentItem *>(getTopItem(Constants::InstrumentType, instrument_name)); } diff --git a/GUI/coregui/Models/InstrumentModel.h b/GUI/coregui/Models/InstrumentModel.h index b3079897af1dbf9f85d81015fd4a82c5302a9d6e..3d8455d6c2c49b53769a18eac1909b36c935fb63 100644 --- a/GUI/coregui/Models/InstrumentModel.h +++ b/GUI/coregui/Models/InstrumentModel.h @@ -33,7 +33,7 @@ public: QMap<QString, ParameterizedItem *> getInstrumentMap() const; - InstrumentItem *getInstrumentItem(); + InstrumentItem *getInstrumentItem(const QString &instrument_name = QString()); }; diff --git a/GUI/coregui/Models/IntensityDataItem.cpp b/GUI/coregui/Models/IntensityDataItem.cpp index cf97ebbf483b184b4f7ca494e0f2bd6d3f14f3a8..7b92d69a004ce33b137123eb234057d97bfbb776 100644 --- a/GUI/coregui/Models/IntensityDataItem.cpp +++ b/GUI/coregui/Models/IntensityDataItem.cpp @@ -53,8 +53,13 @@ IntensityDataItem::IntensityDataItem(ParameterizedItem *parent) registerProperty(P_PROPERTY_PANEL_FLAG, false, PropertyAttribute(PropertyAttribute::HIDDEN)); registerGroupProperty(P_XAXIS, Constants::BasicAxisType); + getSubItems()[P_XAXIS]->setPropertyAppearance(BasicAxisItem::P_NBINS, PropertyAttribute::HIDDEN); + registerGroupProperty(P_YAXIS, Constants::BasicAxisType); + getSubItems()[P_YAXIS]->setPropertyAppearance(BasicAxisItem::P_NBINS, PropertyAttribute::HIDDEN); + registerGroupProperty(P_ZAXIS, Constants::AmplitudeAxisType); + getSubItems()[P_ZAXIS]->setPropertyAppearance(BasicAxisItem::P_NBINS, PropertyAttribute::HIDDEN); } IntensityDataItem::~IntensityDataItem() diff --git a/GUI/coregui/Models/ItemFactory.cpp b/GUI/coregui/Models/ItemFactory.cpp index 4244381d4680b0cabda0e43d4dc84b4ce27a9391..08b4fcd6f126bedf638c415cfab95afd763ffda4 100644 --- a/GUI/coregui/Models/ItemFactory.cpp +++ b/GUI/coregui/Models/ItemFactory.cpp @@ -40,6 +40,10 @@ #include "JobItem.h" #include "IntensityDataItem.h" #include "AxesItems.h" +#include "ResolutionFunctionItems.h" +#include "BeamDistributionItem.h" +#include "BeamWavelengthItem.h" +#include "BeamAngleItems.h" #include <QDebug> namespace { @@ -93,6 +97,7 @@ ItemFactory::ItemMap_t initializeItemMap() { result[Constants::DetectorType] = &createInstance<DetectorItem>; result[Constants::PhiAlphaDetectorType] = &createInstance<PhiAlphaDetectorItem>; + result[Constants::DistributionNoneType] = &createInstance<DistributionNoneItem>; result[Constants::DistributionGateType] = &createInstance<DistributionGateItem>; result[Constants::DistributionLorentzType] = &createInstance<DistributionLorentzItem>; result[Constants::DistributionGaussianType] = &createInstance<DistributionGaussianItem>; @@ -131,6 +136,14 @@ ItemFactory::ItemMap_t initializeItemMap() { result[Constants::BasicAxisType] = &createInstance<BasicAxisItem>; result[Constants::AmplitudeAxisType] = &createInstance<AmplitudeAxisItem>; +// result[Constants::BeamDistributionType] = &createInstance<BeamDistributionItem>; + result[Constants::BeamWavelengthType] = &createInstance<BeamWavelengthItem>; + result[Constants::BeamAzimuthalAngleType] = &createInstance<BeamAzimuthalAngleItem>; + result[Constants::BeamInclinationAngleType] = &createInstance<BeamInclinationAngleItem>; + + result[Constants::ResolutionFunctionNoneType] = &createInstance<ResolutionFunctionNoneItem>; + result[Constants::ResolutionFunction2DGaussianType] = &createInstance<ResolutionFunction2DGaussianItem>; + return result; } } diff --git a/GUI/coregui/Models/ItemLink.cpp b/GUI/coregui/Models/ItemLink.cpp index 8de452eabfe49792166f1c5fa799308e135f3838..650ce2f9441c67485e161e4876baacad200bc4e0 100644 --- a/GUI/coregui/Models/ItemLink.cpp +++ b/GUI/coregui/Models/ItemLink.cpp @@ -15,19 +15,19 @@ #include "ItemLink.h" #include "AngleProperty.h" +#include "ScientificDoubleProperty.h" - -ItemLink::ItemLink(const QString name, ParameterizedItem *item) - : m_name(name) +ItemLink::ItemLink(const QString property_name, ParameterizedItem *item) + : m_property_name(property_name) , m_item(item) , m_value(0) { } -void ItemLink::setItem(QString name, ParameterizedItem *item) +void ItemLink::setItem(QString property_name, ParameterizedItem *item) { - m_name = name; + m_property_name = property_name; m_item = item; } @@ -43,7 +43,7 @@ void ItemLink::setValue(double value) QVariant ItemLink::getVariant() { - QVariant variant = m_item->getRegisteredProperty(m_name); + QVariant variant = m_item->getRegisteredProperty(m_property_name); if(variant.typeName() == QString("double")) { variant.setValue(m_value); return variant; @@ -53,6 +53,11 @@ QVariant ItemLink::getVariant() angle_property.setValue(m_value); return angle_property.getVariant(); } + else if(variant.typeName() == QString("ScientificDoubleProperty")) { + ScientificDoubleProperty scdouble_property = variant.value<ScientificDoubleProperty>(); + scdouble_property.setValue(m_value); + return scdouble_property.getVariant(); + } return QVariant(); } diff --git a/GUI/coregui/Models/ItemLink.h b/GUI/coregui/Models/ItemLink.h index 9a37c2e681469044af7da9c2294a13c4a2de27c8..fe1ad6799ca5978e608e83dc7ce7e22803839989 100644 --- a/GUI/coregui/Models/ItemLink.h +++ b/GUI/coregui/Models/ItemLink.h @@ -24,13 +24,13 @@ class BA_CORE_API_ ItemLink { public: - explicit ItemLink(const QString name = QString(), ParameterizedItem *item = 0); + explicit ItemLink(const QString property_name = QString(), ParameterizedItem *item = 0); virtual ~ItemLink(){} - QString getPropertyName() const { return m_name; } + QString getPropertyName() const { return m_property_name; } ParameterizedItem *getItem() const { return m_item; } - void setItem(QString name, ParameterizedItem *item); + void setItem(QString property_name, ParameterizedItem *item); void setValue(double value); @@ -39,7 +39,7 @@ public: private: double getValue() const; QVariant getVariant(); - QString m_name; + QString m_property_name; ParameterizedItem *m_item; double m_value; }; diff --git a/GUI/coregui/Models/JobQueueData.cpp b/GUI/coregui/Models/JobQueueData.cpp index af004e5ddd692e9ca1258f7ce9357feec9d972b4..7414df27eb500807268eec9257a38a0e49e7cd26 100644 --- a/GUI/coregui/Models/JobQueueData.cpp +++ b/GUI/coregui/Models/JobQueueData.cpp @@ -90,21 +90,20 @@ void JobQueueData::setResults(JobItem *jobItem, const Simulation *simulation) } // propagatind angle units to OutputDataItem - if(jobItem->getInstrumentModel()) { - InstrumentItem *instrumentItem = dynamic_cast<InstrumentItem *>(jobItem->getInstrumentModel()->getInstrumentMap().begin().value()); - qDebug() << instrumentItem->modelType(); - Q_ASSERT(instrumentItem); - DetectorItem *detectorItem = instrumentItem->getDetectorItem(); - Q_ASSERT(detectorItem); - ParameterizedItem *subDetector = detectorItem->getSubItems()[DetectorItem::P_DETECTOR]; - Q_ASSERT(subDetector); - - if (subDetector->modelType() == Constants::PhiAlphaDetectorType) { - AngleProperty angle_property = subDetector->getRegisteredProperty(PhiAlphaDetectorItem::P_AXES_UNITS).value<AngleProperty>(); - intensityItem->setRegisteredProperty(IntensityDataItem::P_AXES_UNITS, angle_property.getVariant()); - } - - } +// if(jobItem->getInstrumentModel()) { +// InstrumentItem *instrumentItem = dynamic_cast<InstrumentItem *>(jobItem->getInstrumentModel()->getInstrumentMap().begin().value()); +// qDebug() << instrumentItem->modelType(); +// Q_ASSERT(instrumentItem); +// DetectorItem *detectorItem = instrumentItem->getDetectorItem(); +// Q_ASSERT(detectorItem); +// ParameterizedItem *subDetector = detectorItem->getSubItems()[DetectorItem::P_DETECTOR]; +// Q_ASSERT(subDetector); + +// if (subDetector->modelType() == Constants::PhiAlphaDetectorType) { +// AngleProperty angle_property = subDetector->getRegisteredProperty(PhiAlphaDetectorItem::P_AXES_UNITS).value<AngleProperty>(); +// intensityItem->setRegisteredProperty(IntensityDataItem::P_AXES_UNITS, angle_property.getVariant()); +// } +// } qDebug() << "JobItem::setResults()" << intensityItem; intensityItem->setItemName(QString("data_%1_%2.int").arg(jobItem->itemName(), QString::number(0))); diff --git a/GUI/coregui/Models/LayerItem.cpp b/GUI/coregui/Models/LayerItem.cpp index 7673ddf12fb45f5a2fd2f5e6c355c2e8fb3f5b26..9cefc84ed670e4b212e98e8e3b8681a1045564b8 100644 --- a/GUI/coregui/Models/LayerItem.cpp +++ b/GUI/coregui/Models/LayerItem.cpp @@ -15,6 +15,7 @@ #include "LayerItem.h" #include "MaterialUtils.h" +#include "ComboProperty.h" const QString LayerItem::P_THICKNESS = "Thickness"; const QString LayerItem::P_ROUGHNESS = "Top roughness"; diff --git a/GUI/coregui/Models/LayerRoughnessItems.cpp b/GUI/coregui/Models/LayerRoughnessItems.cpp index 9ffee0da0ce8a35deaa62150ef48c3268e7bcc4d..ef45869596bc2d49097039fa8db9fb8def502f95 100644 --- a/GUI/coregui/Models/LayerRoughnessItems.cpp +++ b/GUI/coregui/Models/LayerRoughnessItems.cpp @@ -35,5 +35,4 @@ LayerBasicRoughnessItem::LayerBasicRoughnessItem(ParameterizedItem *parent) registerProperty(P_SIGMA, 1.0); registerProperty(P_HURST, 0.3, PropertyAttribute(AttLimits::limited(0.0, 1.0),3)); registerProperty(P_LATERAL_CORR_LENGTH, 5.0); - } diff --git a/GUI/coregui/Models/ParameterModelBuilder.cpp b/GUI/coregui/Models/ParameterModelBuilder.cpp index 4e4e32631e367ea5595d5a55a202022217fc886c..379d9c59e890f21cef703a459c753add71a670e9 100644 --- a/GUI/coregui/Models/ParameterModelBuilder.cpp +++ b/GUI/coregui/Models/ParameterModelBuilder.cpp @@ -18,9 +18,12 @@ #include "InstrumentModel.h" #include "InstrumentItem.h" #include "BeamItem.h" +#include "BeamDistributionItem.h" +#include "BeamWavelengthItem.h" #include "ItemLink.h" #include "AngleProperty.h" #include "GUIHelpers.h" +#include "DistributionItem.h" #include <QStandardItem> #include <QStandardItemModel> #include <QDebug> @@ -88,7 +91,7 @@ QStandardItem *ParameterModelBuilder::iterateSessionModel(SampleModel *sampleMod int type = GUIHelpers::getVariantType(propertyValue); if (type == QVariant::Double) { // qDebug() << " Items: "<<propertyName << propertyValue.toDouble(); - insertRowIntoItem(standardItem, propertyName, propertyValue, item); + addPropertyToParameterModel(standardItem, propertyName, propertyName, propertyValue, item); } else if(item->getSubItems().contains(propertyName)) { @@ -115,12 +118,12 @@ QStandardItem *ParameterModelBuilder::iterateSessionModel(SampleModel *sampleMod if (proValueType == QVariant::Double) { //qDebug() << "Items: "<<prop_name << prop_value.toDouble(); isChildPropertyFound = true; - insertRowIntoItem(childStandardItem, childPropertyName, childPropertyValue, subItem); + addPropertyToParameterModel(childStandardItem, childPropertyName, childPropertyName, childPropertyValue, subItem); } } if(isChildPropertyFound) { - insertRowIntoItem(standardItem, childStandardItem); + InsertRowIntoItem(standardItem, childStandardItem); } @@ -135,7 +138,7 @@ QStandardItem *ParameterModelBuilder::iterateSessionModel(SampleModel *sampleMod } else { - insertRowIntoItem(parentItem, standardItem); + InsertRowIntoItem(parentItem, standardItem); } //qDebug() << "iteration called" << i_row; iterateSessionModel(sampleModel, itemIndex, standardItem); @@ -152,19 +155,45 @@ QStandardItem *ParameterModelBuilder::iterateInstrumentModel(InstrumentModel *in { QStandardItem *standardItem(0); - InstrumentItem *instrument = instrumentModel->getInstrumentItem(); + InstrumentItem *instrument = dynamic_cast<InstrumentItem *>(instrumentModel->getInstrumentItem()); if(instrument) { BeamItem *beamItem = instrument->getBeamItem(); if(beamItem) { standardItem = new QStandardItem(instrument->itemName()); - insertRowIntoItem(standardItem, BeamItem::P_WAVELENGTH, beamItem->getRegisteredProperty(BeamItem::P_WAVELENGTH), beamItem); - double v = beamItem->getRegisteredProperty(BeamItem::P_INCLINATION_ANGLE).value<AngleProperty>().getValue(); - QVariant variant_inclination(v); - insertRowIntoItem(standardItem, BeamItem::P_INCLINATION_ANGLE, variant_inclination, beamItem); + // intensity + addPropertyToParameterModel(standardItem, BeamItem::P_INTENSITY, BeamItem::P_INTENSITY, QVariant(beamItem->getIntensity()), beamItem); + + // wavelength, incident and azimuthal angle will be varied only if there is no distribution assigned to them + ParameterizedItem *beamWavelength = beamItem->getSubItems()[BeamItem::P_WAVELENGTH]; + Q_ASSERT(beamWavelength); + ParameterizedItem *wavelengthDistribution = beamWavelength->getSubItems()[BeamDistributionItem::P_DISTRIBUTION]; + Q_ASSERT(wavelengthDistribution); + if(wavelengthDistribution->modelType() == Constants::DistributionNoneType) { + addPropertyToParameterModel(standardItem, BeamItem::P_WAVELENGTH, BeamDistributionItem::P_CACHED_VALUE, beamWavelength->getRegisteredProperty(BeamDistributionItem::P_CACHED_VALUE), beamWavelength); + } else { + addDisabledProperty(standardItem, BeamItem::P_INCLINATION_ANGLE); + } + + ParameterizedItem *inclinationAngle = beamItem->getSubItems()[BeamItem::P_INCLINATION_ANGLE]; + Q_ASSERT(inclinationAngle); + ParameterizedItem *inclinationDistribution = inclinationAngle->getSubItems()[BeamDistributionItem::P_DISTRIBUTION]; + Q_ASSERT(inclinationDistribution); + if(inclinationDistribution->modelType() == Constants::DistributionNoneType) { + addPropertyToParameterModel(standardItem, BeamItem::P_INCLINATION_ANGLE, BeamDistributionItem::P_CACHED_VALUE, inclinationAngle->getRegisteredProperty(BeamDistributionItem::P_CACHED_VALUE), inclinationAngle); + } else { + addDisabledProperty(standardItem, BeamItem::P_INCLINATION_ANGLE); + } - v = beamItem->getRegisteredProperty(BeamItem::P_AZIMUTHAL_ANGLE).value<AngleProperty>().getValue(); - insertRowIntoItem(standardItem, BeamItem::P_AZIMUTHAL_ANGLE, QVariant(v), beamItem); + ParameterizedItem *azimuthalAngle = beamItem->getSubItems()[BeamItem::P_AZIMUTHAL_ANGLE]; + Q_ASSERT(azimuthalAngle); + ParameterizedItem *azimuthalDistribution = azimuthalAngle->getSubItems()[BeamDistributionItem::P_DISTRIBUTION]; + Q_ASSERT(azimuthalDistribution); + if(azimuthalDistribution->modelType() == Constants::DistributionNoneType) { + addPropertyToParameterModel(standardItem, BeamItem::P_AZIMUTHAL_ANGLE, BeamDistributionItem::P_CACHED_VALUE, azimuthalAngle->getRegisteredProperty(BeamDistributionItem::P_CACHED_VALUE), azimuthalAngle); + } else { + addDisabledProperty(standardItem, BeamItem::P_AZIMUTHAL_ANGLE); + } } } @@ -173,7 +202,7 @@ QStandardItem *ParameterModelBuilder::iterateInstrumentModel(InstrumentModel *in } -void ParameterModelBuilder::insertRowIntoItem(QStandardItem *parentItem, QStandardItem *childTitleItem, QStandardItem *childValueItem) +void ParameterModelBuilder::InsertRowIntoItem(QStandardItem *parentItem, QStandardItem *childTitleItem, QStandardItem *childValueItem) { if(childValueItem == NULL) { @@ -185,10 +214,13 @@ void ParameterModelBuilder::insertRowIntoItem(QStandardItem *parentItem, QStanda parentItem->appendRow(QList<QStandardItem *>() << childTitleItem << childValueItem); } - -void ParameterModelBuilder::insertRowIntoItem(QStandardItem *parentItem, QString title, QVariant value, ParameterizedItem *parameterizedItem) +//! adds property of ParameterizedItem to the QStandardItem of ParameterTree +//! title - the name of the property as it will be shown by QTreeView +//! property_name - the name of the property to add (normally coincide with 'title') +//! value - QVariant representing property_value +void ParameterModelBuilder::addPropertyToParameterModel(QStandardItem *parentItem, const QString &title, const QString &property_name, QVariant value, ParameterizedItem *parameterizedItem) { - ItemLink itemLink(title, parameterizedItem); + ItemLink itemLink(property_name, parameterizedItem); QVariant itemLinkData; itemLinkData.setValue(itemLink); @@ -200,6 +232,21 @@ void ParameterModelBuilder::insertRowIntoItem(QStandardItem *parentItem, QString valueItem->setData(itemLinkData, Qt::UserRole); valueItem->setData(value, Qt::EditRole); valueItem->setEditable(true); - insertRowIntoItem(parentItem, titleItem, valueItem); + InsertRowIntoItem(parentItem, titleItem, valueItem); +} + +void ParameterModelBuilder::addDisabledProperty(QStandardItem *parentItem, const QString &title) +{ + QStandardItem *titleItem = new QStandardItem(title); + titleItem->setEditable(false); + QStandardItem *valueItem = new QStandardItem("disabled"); + valueItem->setEditable(false); + + QFont font("Arial", 8); + font.setItalic(true); + valueItem->setData(font, Qt::FontRole); + valueItem->setData("Disabled because of the distribution attached to this item.", Qt::ToolTipRole); + + InsertRowIntoItem(parentItem, titleItem, valueItem); } diff --git a/GUI/coregui/Models/ParameterModelBuilder.h b/GUI/coregui/Models/ParameterModelBuilder.h index b136ac109ccba9784d3b5de88c160d06efebdbe3..0a307cc48fd02d62721f01b0586b537b8abf5a4a 100644 --- a/GUI/coregui/Models/ParameterModelBuilder.h +++ b/GUI/coregui/Models/ParameterModelBuilder.h @@ -39,8 +39,9 @@ public: private: static QStandardItem *iterateSessionModel(SampleModel *sampleModel, const QModelIndex &parentIndex = QModelIndex(), QStandardItem *parentItem = 0); static QStandardItem *iterateInstrumentModel(InstrumentModel *instrumentModel); - static void insertRowIntoItem(QStandardItem *parentItem, QStandardItem *childTitleItem, QStandardItem *childValueItem = 0); - static void insertRowIntoItem(QStandardItem *parentItem, QString title, QVariant value, ParameterizedItem *parameterizedItem); + static void InsertRowIntoItem(QStandardItem *parentItem, QStandardItem *childTitleItem, QStandardItem *childValueItem = 0); + static void addPropertyToParameterModel(QStandardItem *parentItem, const QString &title, const QString &property_name, QVariant value, ParameterizedItem *parameterizedItem); + static void addDisabledProperty(QStandardItem *parentItem, const QString &title); }; diff --git a/GUI/coregui/Models/ParameterizedItem.cpp b/GUI/coregui/Models/ParameterizedItem.cpp index 91605a2ed052566838e8cf6ee9c103fe5aa72bd6..178694640c431ea75f42679592e3e644d74dd8c0 100644 --- a/GUI/coregui/Models/ParameterizedItem.cpp +++ b/GUI/coregui/Models/ParameterizedItem.cpp @@ -143,29 +143,6 @@ void ParameterizedItem::setItemPort(ParameterizedItem::PortInfo::EPorts nport) setRegisteredProperty(P_PORT, nport); } - -// to update label of FixedGroupProperty -void ParameterizedItem::onPropertyItemChanged(const QString & propertyName) -{ - Q_UNUSED(propertyName); - ParameterizedItem *propertyItem = qobject_cast<ParameterizedItem *>(sender()); - for(QMap<QString, ParameterizedItem *>::iterator it=m_sub_items.begin(); - it!= m_sub_items.end(); ++it) { - if(it.value() == propertyItem) { - FancyGroupProperty_t group_property = - getRegisteredProperty(it.key()).value<FancyGroupProperty_t>(); - group_property->setValueLabel(propertyItem->getItemLabel()); - emit propertyItemPropertyChanged(it.key(), propertyName); -// emit propertyItemChanged(it.key()); - if (m_parent) m_parent->onChildPropertyChange(); - return; - } - } - throw GUIHelpers::Error("ParameterizedItem::onPropertyItemChanged() ->" - " Error. No such propertyItem found"); -} - - void ParameterizedItem::addToValidChildren(const QString &name, PortInfo::EPorts nport, int nmax_items) { m_valid_children.append(name); @@ -178,7 +155,6 @@ void ParameterizedItem::addToValidChildren(const QString &name, PortInfo::EPorts } } - void ParameterizedItem::addPropertyItem(QString name, ParameterizedItem *item) { //if (!item) return; @@ -192,16 +168,16 @@ void ParameterizedItem::addPropertyItem(QString name, ParameterizedItem *item) } m_sub_items[name] = item; item->m_parent = this; - connect(item, SIGNAL(propertyChanged(QString)), this, SLOT(onPropertyItemChanged(QString))); + //connect(item, SIGNAL(propertyChanged(QString)), this, SLOT(onSubItemPropertyChanged(QString)), Qt::UniqueConnection); + onSubItemChanged(name); onChildPropertyChange(); qDebug() << "ParameterizedItem::addPropertyItem() -> about to leave" << name; } - ParameterizedItem *ParameterizedItem::registerGroupProperty(const QString &group_name, const Constants::ModelType &group_model) { - qDebug() << "registerFancyGroupProperty " - << modelType() << group_name; + qDebug() << "ParameterizedItem::registerGroupProperty() ->" + << "this->modelType" << modelType() << "group_name" << group_name << " group_model" << group_model; FancyGroupProperty_t group_property = GroupPropertyRegistry::createGroupProperty(group_name, group_model); QVariant variant; @@ -253,7 +229,7 @@ void ParameterizedItem::setRegisteredProperty(const QString &name, const QVarian QVariant ParameterizedItem::getRegisteredProperty(const QString &name) const { if( !m_registered_properties.contains(name)) - throw GUIHelpers::Error("ParameterizedItem::getRegisteredProperty() -> Error. Unknown property "+name); + throw GUIHelpers::Error("ParameterizedItem::getRegisteredProperty() -> Error. Unknown property "+name+" model="+modelType()); return property(name.toUtf8().constData()); } @@ -335,9 +311,43 @@ QStringList ParameterizedItem::getParameterTreeList() const void ParameterizedItem::onChildPropertyChange() { + qDebug() << "ParameterizedItem::onChildPropertyChange()"; if (m_parent) m_parent->onChildPropertyChange(); } +//! called when new SubItem appeared +void ParameterizedItem::onSubItemChanged(const QString &propertyName) +{ + connect(m_sub_items[propertyName], SIGNAL(propertyChanged(QString)), this, SLOT(processSubItemPropertyChanged(QString)), Qt::UniqueConnection); + emit subItemChanged(propertyName); +} + +//! called when SubItem change one of its properties +void ParameterizedItem::processSubItemPropertyChanged(const QString & propertyName) +{ + Q_UNUSED(propertyName); + ParameterizedItem *propertyItem = qobject_cast<ParameterizedItem *>(sender()); + for(QMap<QString, ParameterizedItem *>::iterator it=m_sub_items.begin(); + it!= m_sub_items.end(); ++it) { + if(it.value() == propertyItem) { + FancyGroupProperty_t group_property = + getRegisteredProperty(it.key()).value<FancyGroupProperty_t>(); + group_property->setValueLabel(propertyItem->getItemLabel()); +// emit subItemPropertyChanged(it.key(), propertyName); +// if (m_parent) m_parent->onChildPropertyChange(); + onSubItemPropertyChanged(it.key(), propertyName); + return; + } + } + throw GUIHelpers::Error("ParameterizedItem::onSubItemPropertyChanged() ->" + " Error. No such propertyItem found"); +} + +void ParameterizedItem::onSubItemPropertyChanged(const QString &property_group, const QString &property_name) +{ + emit subItemPropertyChanged(property_group, property_name); + if (m_parent) m_parent->onChildPropertyChange(); +} PropertyAttribute ParameterizedItem::getPropertyAttribute(const QString &name) const { diff --git a/GUI/coregui/Models/ParameterizedItem.h b/GUI/coregui/Models/ParameterizedItem.h index 869f81562c46dbf9f048dc7182f222feb7ffab23..1ece46eb838fa37384dfb8a87e83c9c1bef25459 100644 --- a/GUI/coregui/Models/ParameterizedItem.h +++ b/GUI/coregui/Models/ParameterizedItem.h @@ -130,18 +130,22 @@ public: QStringList getParameterTreeList() const; virtual void onChildPropertyChange(); - -public slots: - void onPropertyItemChanged(const QString &propertyName); + void setPropertyAttribute(const QString &name, const PropertyAttribute &attribute); signals: void propertyChanged(const QString &propertyName); - void propertyItemChanged(const QString &propertyName); - void propertyItemPropertyChanged(const QString &property_group, const QString &property_name); + void subItemChanged(const QString &propertyName); + void subItemPropertyChanged(const QString &property_group, const QString &property_name); + +protected slots: + virtual void onSubItemChanged(const QString &propertyName); + virtual void onSubItemPropertyChanged(const QString &property_group, const QString &property_name); + +private slots: + virtual void processSubItemPropertyChanged(const QString &propertyName); protected: void addToValidChildren(const QString &name, PortInfo::EPorts nport = PortInfo::PORT_0, int nmax_children = 0); - void setPropertyAttribute(const QString &name, const PropertyAttribute &attribute); QStringList m_registered_properties; diff --git a/GUI/coregui/Models/ResolutionFunctionItems.cpp b/GUI/coregui/Models/ResolutionFunctionItems.cpp new file mode 100644 index 0000000000000000000000000000000000000000..f0320dc18b6ce209e3f98e96e6a8536666197c0c --- /dev/null +++ b/GUI/coregui/Models/ResolutionFunctionItems.cpp @@ -0,0 +1,57 @@ +// ************************************************************************** // +// +// BornAgain: simulate and fit scattering at grazing incidence +// +//! @file coregui/Models/ResolutionFunctionItems.cpp +//! @brief Implements family of ResolutionFunctionItem +//! +//! @homepage http://www.bornagainproject.org +//! @license GNU General Public License v3 or higher (see COPYING) +//! @copyright Forschungszentrum Jülich GmbH 2015 +//! @authors Scientific Computing Group at MLZ Garching +//! @authors C. Durniak, M. Ganeva, G. Pospelov, W. Van Herck, J. Wuttke +// +// ************************************************************************** // + +#include "ResolutionFunctionItems.h" +#include "ComboProperty.h" +#include <QDebug> + +ResolutionFunctionItem::ResolutionFunctionItem(const QString name, ParameterizedItem *parent) + : ParameterizedItem(name, parent) +{ + +} + +/* ------------------------------------------------ */ + +ResolutionFunctionNoneItem::ResolutionFunctionNoneItem(ParameterizedItem *parent) + : ResolutionFunctionItem(Constants::ResolutionFunctionNoneType, parent) +{ + setItemName(Constants::ResolutionFunctionNoneType); +} + +IResolutionFunction2D *ResolutionFunctionNoneItem::createResolutionFunction() const +{ + return 0; +} + +/* ------------------------------------------------ */ + +const QString ResolutionFunction2DGaussianItem::P_SIGMA_X = "Sigma phi"; +const QString ResolutionFunction2DGaussianItem::P_SIGMA_Y = "Sigma alpha"; + +ResolutionFunction2DGaussianItem::ResolutionFunction2DGaussianItem(ParameterizedItem *parent) + : ResolutionFunctionItem(Constants::ResolutionFunction2DGaussianType, parent) +{ + setItemName(Constants::ResolutionFunction2DGaussianType); + registerProperty(P_SIGMA_X, 0.02); + registerProperty(P_SIGMA_Y, 0.02); +} + +IResolutionFunction2D *ResolutionFunction2DGaussianItem::createResolutionFunction() const +{ + double sigma_x = getRegisteredProperty(P_SIGMA_X).toDouble(); + double sigma_y = getRegisteredProperty(P_SIGMA_Y).toDouble(); + return new ResolutionFunction2DGaussian(sigma_x, sigma_y); +} diff --git a/GUI/coregui/Models/ResolutionFunctionItems.h b/GUI/coregui/Models/ResolutionFunctionItems.h new file mode 100644 index 0000000000000000000000000000000000000000..94871a6428893d7dc5785a8e0d292d579604645a --- /dev/null +++ b/GUI/coregui/Models/ResolutionFunctionItems.h @@ -0,0 +1,54 @@ +// ************************************************************************** // +// +// BornAgain: simulate and fit scattering at grazing incidence +// +//! @file coregui/Models/ResolutionFunctionItems.h +//! @brief Defines family of ResolutionFunctionItem +//! +//! @homepage http://www.bornagainproject.org +//! @license GNU General Public License v3 or higher (see COPYING) +//! @copyright Forschungszentrum Jülich GmbH 2015 +//! @authors Scientific Computing Group at MLZ Garching +//! @authors C. Durniak, M. Ganeva, G. Pospelov, W. Van Herck, J. Wuttke +// +// ************************************************************************** // + +#ifndef RESOLUTIONFUNCTIONITEMS_H +#define RESOLUTIONFUNCTIONITEMS_H + +#include "ParameterizedItem.h" +#include "ResolutionFunction2DGaussian.h" + + +class BA_CORE_API_ ResolutionFunctionItem : public ParameterizedItem +{ + Q_OBJECT +public: + explicit ResolutionFunctionItem(const QString name, ParameterizedItem *parent=0); + virtual ~ResolutionFunctionItem() {} + + virtual IResolutionFunction2D *createResolutionFunction() const=0; +}; + +class BA_CORE_API_ ResolutionFunctionNoneItem : public ResolutionFunctionItem +{ + Q_OBJECT +public: + explicit ResolutionFunctionNoneItem(ParameterizedItem *parent=0); + virtual IResolutionFunction2D *createResolutionFunction() const; +}; + +class BA_CORE_API_ ResolutionFunction2DGaussianItem : public ResolutionFunctionItem +{ + Q_OBJECT +public: + static const QString P_SIGMA_X; + static const QString P_SIGMA_Y; + explicit ResolutionFunction2DGaussianItem(ParameterizedItem *parent=0); + virtual IResolutionFunction2D *createResolutionFunction() const; +}; + + + +#endif // DISTRIBUTIONITEM_H + diff --git a/GUI/coregui/Models/SampleModel.cpp b/GUI/coregui/Models/SampleModel.cpp index 45b00430e671f43782cb6eba306759a6c59f0190..35deb779de10993c135e385545ff659e89901835 100644 --- a/GUI/coregui/Models/SampleModel.cpp +++ b/GUI/coregui/Models/SampleModel.cpp @@ -17,6 +17,7 @@ #include "MaterialModel.h" #include "MaterialItem.h" #include "LayerItem.h" +#include "MultiLayerItem.h" #include "ParticleItem.h" #include <QDebug> @@ -39,18 +40,12 @@ SampleModel *SampleModel::createCopy(ParameterizedItem *parent) //! returns list of MultiLayers defined in the model QMap<QString, ParameterizedItem *> SampleModel::getSampleMap() const { - QMap<QString, ParameterizedItem *> result; - QModelIndex parentIndex; - for( int i_row = 0; i_row < rowCount( parentIndex); ++i_row) { - QModelIndex itemIndex = index( i_row, 0, parentIndex ); + return getTopItemMap(Constants::MultiLayerType); +} - if (ParameterizedItem *item = itemForIndex(itemIndex)){ - if(item->modelType() == Constants::MultiLayerType) { - result[item->itemName()] = item; - } - } - } - return result; +MultiLayerItem *SampleModel::getMultiLayerItem(const QString &item_name) +{ + return dynamic_cast<MultiLayerItem *>(getTopItem(Constants::MultiLayerType, item_name)); } diff --git a/GUI/coregui/Models/SampleModel.h b/GUI/coregui/Models/SampleModel.h index db928cfd0d44a981fc1be74dca1052ee1bcb296b..027e06d7bec86a83aa981c23347ab29739774a5b 100644 --- a/GUI/coregui/Models/SampleModel.h +++ b/GUI/coregui/Models/SampleModel.h @@ -20,6 +20,7 @@ #include "MaterialProperty.h" #include <QStringList> +class MultiLayerItem; class BA_CORE_API_ SampleModel : public SessionModel { Q_OBJECT @@ -32,6 +33,8 @@ public: QMap<QString, ParameterizedItem *> getSampleMap() const; + MultiLayerItem *getMultiLayerItem(const QString &item_name); + public slots: void onMaterialModelChanged(const QModelIndex &first, const QModelIndex &second); diff --git a/GUI/coregui/Models/SelectableGroupProperty.cpp b/GUI/coregui/Models/SelectableGroupProperty.cpp index 32953bd9dfe09618f7e85af72939ba241eb02314..36a3e8622600371ebe1f5980bd2fcbf94d13c9de 100644 --- a/GUI/coregui/Models/SelectableGroupProperty.cpp +++ b/GUI/coregui/Models/SelectableGroupProperty.cpp @@ -17,19 +17,3 @@ #include "GUIHelpers.h" #include "ItemFactory.h" #include <QDebug> - - - -//void SelectableGroupProperty::setValue(const QString &value) -//{ -// qDebug() << "SelectableGroupProperty::setValue() -> " << value; -// if(value == getValue()) return; - -// FancyGroupProperty::setValue(value); - -// if(m_parent) { -// m_parent->addPropertyItem(getGroupName(), createCorrespondingItem()); -// emit m_parent->propertyItemChanged(getGroupName()); -// } -//} - diff --git a/GUI/coregui/Models/SessionModel.cpp b/GUI/coregui/Models/SessionModel.cpp index 300e7cf86efda1267dd82e5a07a6e21e7ddac6ca..2da9c7904378d10f7f658964cbe4ff992bf02660 100644 --- a/GUI/coregui/Models/SessionModel.cpp +++ b/GUI/coregui/Models/SessionModel.cpp @@ -408,7 +408,40 @@ SessionModel *SessionModel::createCopy(ParameterizedItem *parent) throw GUIHelpers::Error("SessionModel::createCopy() -> Error. Not implemented."); } +//! returns map of item name to ParameterizedItem for all top level items in the model +QMap<QString, ParameterizedItem *> SessionModel::getTopItemMap(const QString &model_type) const +{ + QMap<QString, ParameterizedItem *> result; + QModelIndex parentIndex; + for( int i_row = 0; i_row < rowCount( parentIndex); ++i_row) { + QModelIndex itemIndex = index( i_row, 0, parentIndex ); + if (ParameterizedItem *item = itemForIndex(itemIndex)){ + if(model_type.isEmpty()) { + result.insertMulti(item->itemName(), item); + } else { + if(item->modelType() == model_type) { + result.insertMulti(item->itemName(), item); + } + } + } + } + return result; +} +//! returns top level item with given name and model type +ParameterizedItem *SessionModel::getTopItem(const QString &model_type, const QString &item_name) const +{ + ParameterizedItem *result(0); + QMap<QString, ParameterizedItem *> item_map = getTopItemMap(model_type); + if(item_map.size()) { + if(item_name.isEmpty()) { + result = item_map.first(); + } else { + result = item_map[item_name]; + } + } + return result; +} ParameterizedItem *SessionModel::insertNewItem(QString model_type, ParameterizedItem *parent, diff --git a/GUI/coregui/Models/SessionModel.h b/GUI/coregui/Models/SessionModel.h index 5fce22c8eadb14a37a1aefd0e24c1e583ac5a3df..674f43ed519c9c06991e53d6984d349e9ee510bf 100644 --- a/GUI/coregui/Models/SessionModel.h +++ b/GUI/coregui/Models/SessionModel.h @@ -127,6 +127,10 @@ public: virtual SessionModel *createCopy(ParameterizedItem *parent=0); + + QMap<QString, ParameterizedItem *> getTopItemMap(const QString &model_type = QString()) const; + ParameterizedItem *getTopItem(const QString &model_type = QString(), const QString &item_name = QString()) const; + public slots: void onItemPropertyChange(const QString &name); diff --git a/GUI/coregui/Models/TestItem.cpp b/GUI/coregui/Models/TestItem.cpp new file mode 100644 index 0000000000000000000000000000000000000000..d4011c975152fb85c22159b85e959b5863c8f85f --- /dev/null +++ b/GUI/coregui/Models/TestItem.cpp @@ -0,0 +1,36 @@ +// ************************************************************************** // +// +// BornAgain: simulate and fit scattering at grazing incidence +// +//! @file coregui/Models/TestItem.cpp +//! @brief Implements class TestItem +//! +//! @homepage http://www.bornagainproject.org +//! @license GNU General Public License v3 or higher (see COPYING) +//! @copyright Forschungszentrum Jülich GmbH 2015 +//! @authors Scientific Computing Group at MLZ Garching +//! @authors C. Durniak, M. Ganeva, G. Pospelov, W. Van Herck, J. Wuttke +// +// ************************************************************************** // + +#include "TestItem.h" +#include "ComboProperty.h" +#include "AngleProperty.h" +#include "Units.h" +#include <QDebug> + +const QString TestItem::P_DISTRIBUTION = "Distribution"; +const QString TestItem::P_VALUE = "Value"; +const QString TestItem::P_COMBO = "Combo"; +const QString TestItem::P_VECTOR = "Vector"; +TestItem::TestItem(ParameterizedItem *parent) + : ParameterizedItem(QString("TestItem"), parent) +{ + setItemName(QString("TestItem")); + registerGroupProperty(P_DISTRIBUTION, Constants::DistributionExtendedGroup); + registerProperty(P_VALUE, 99.0, PropertyAttribute(PropertyAttribute::DISABLED)); + ComboProperty types; + types << "property 1" << "property 2" << "property 3"; + registerProperty(P_COMBO, types.getVariant()); + registerGroupProperty(P_VECTOR, Constants::VectorType); +} diff --git a/GUI/coregui/Models/TestItem.h b/GUI/coregui/Models/TestItem.h new file mode 100644 index 0000000000000000000000000000000000000000..1f3b906bb985386293e79ef6087aef761e169872 --- /dev/null +++ b/GUI/coregui/Models/TestItem.h @@ -0,0 +1,34 @@ +// ************************************************************************** // +// +// BornAgain: simulate and fit scattering at grazing incidence +// +//! @file coregui/Models/TestItem.h +//! @brief Defines class TestItem +//! +//! @homepage http://www.bornagainproject.org +//! @license GNU General Public License v3 or higher (see COPYING) +//! @copyright Forschungszentrum Jülich GmbH 2015 +//! @authors Scientific Computing Group at MLZ Garching +//! @authors C. Durniak, M. Ganeva, G. Pospelov, W. Van Herck, J. Wuttke +// +// ************************************************************************** // + +#ifndef TESTITEM_H +#define TESTITEM_H + +#include "ParameterizedItem.h" + +//! The TestItem class for TestParameterizedItem unit tests and for checking AwesomePropertyEditor machinery +class BA_CORE_API_ TestItem : public ParameterizedItem +{ + Q_OBJECT +public: + static const QString P_DISTRIBUTION; + static const QString P_VALUE; + static const QString P_COMBO; + static const QString P_VECTOR; + explicit TestItem(ParameterizedItem *parent=0); + ~TestItem(){} +}; + +#endif diff --git a/GUI/coregui/Models/TransformFromDomain.cpp b/GUI/coregui/Models/TransformFromDomain.cpp index 3a33296f783363cdc86535898db0b2dcd7ccb46a..225f288c66e2b7b42d08319f90e4d36dd98535f3 100644 --- a/GUI/coregui/Models/TransformFromDomain.cpp +++ b/GUI/coregui/Models/TransformFromDomain.cpp @@ -38,6 +38,14 @@ #include "ParticleDistribution.h" #include "Distributions.h" #include "DistributionItem.h" +#include "DetectorItems.h" +#include "BeamItem.h" +#include "ComboProperty.h" +#include "DistributionHandler.h" +#include "ParameterDistribution.h" +#include "BeamDistributionItem.h" +#include "BeamAngleItems.h" +#include "AxesItems.h" #include <QString> #include <QDebug> #include <vector> @@ -529,14 +537,140 @@ QString TransformFromDomain::getDetectorBinning(const Detector *detector) if( dynamic_cast<ConstKBinAxis *>(phi_axis.get()) && dynamic_cast<ConstKBinAxis *>(alpha_axis.get())) { - return QString("Const KBin"); + return Constants::AXIS_CONSTK_BINNING; } else if( dynamic_cast<FixedBinAxis *>(phi_axis.get()) && dynamic_cast<FixedBinAxis *>(alpha_axis.get())) { - return QString("Fixed"); + return Constants::AXIS_FIXED_BINNING; } else { throw GUIHelpers::Error("TransformFromDomain::getDetectorBinning()" " -> Error. Can't determine detector binning"); } } + + +void TransformFromDomain::setItemFromSample(BeamItem *beamItem, const Simulation &simulation) +{ + Q_ASSERT(beamItem); + Beam beam = simulation.getInstrument().getBeam(); + + beamItem->setIntensity(beam.getIntensity()); + beamItem->setWavelength(beam.getWavelength()); + beamItem->setInclinationAngle(Units::rad2deg(-1.0*beam.getAlpha())); + beamItem->setAzimuthalAngle(Units::rad2deg(-1.0*beam.getPhi())); + + // distribution parameters + const DistributionHandler::Distributions_t distributions = simulation.getDistributionHandler().getDistributions(); + for(size_t i=0; i<distributions.size(); ++i) { + QString mainParameterName = QString::fromStdString(distributions[i].getMainParameterName()); + if(mainParameterName == QStringLiteral("*/Beam/wavelength") ) { + BeamDistributionItem *beamWavelength = dynamic_cast<BeamDistributionItem *>(beamItem->getSubItems()[BeamItem::P_WAVELENGTH]); + setItemFromSample(beamWavelength, distributions[i]); + } + else if(mainParameterName == QStringLiteral("*/Beam/alpha") ) { + BeamDistributionItem *inclinationAngle = dynamic_cast<BeamDistributionItem *>(beamItem->getSubItems()[BeamItem::P_INCLINATION_ANGLE]); + setItemFromSample(inclinationAngle, distributions[i]); + } + else if(mainParameterName == QStringLiteral("*/Beam/phi") ) { + BeamDistributionItem *azimuthalAngle = dynamic_cast<BeamDistributionItem *>(beamItem->getSubItems()[BeamItem::P_AZIMUTHAL_ANGLE]); + setItemFromSample(azimuthalAngle, distributions[i]); + + } + } +} + + +void TransformFromDomain::setItemFromSample(PhiAlphaDetectorItem *detectorItem, const Simulation &simulation) +{ + Q_ASSERT(detectorItem); + Detector detector = simulation.getInstrument().getDetector(); + + const IAxis &phi_axis = detector.getAxis(0); + const IAxis &alpha_axis = detector.getAxis(1); + + ComboProperty binning_property = detectorItem->getRegisteredProperty( + PhiAlphaDetectorItem::P_BINNING).value<ComboProperty>(); + binning_property.setValue(TransformFromDomain::getDetectorBinning(&detector)); + detectorItem->setRegisteredProperty( + PhiAlphaDetectorItem::P_BINNING, binning_property.getVariant()); + + BasicAxisItem *phiAxisItem = dynamic_cast<BasicAxisItem *>(detectorItem->getSubItems()[PhiAlphaDetectorItem::P_PHI_AXIS]); + Q_ASSERT(phiAxisItem); + phiAxisItem->setRegisteredProperty(BasicAxisItem::P_NBINS, (int)phi_axis.getSize()); + phiAxisItem->setRegisteredProperty(BasicAxisItem::P_MIN, Units::rad2deg(phi_axis.getMin())); + phiAxisItem->setRegisteredProperty(BasicAxisItem::P_MAX, Units::rad2deg(phi_axis.getMax())); + + BasicAxisItem *alphaAxisItem = dynamic_cast<BasicAxisItem *>(detectorItem->getSubItems()[PhiAlphaDetectorItem::P_ALPHA_AXIS]); + Q_ASSERT(alphaAxisItem); + alphaAxisItem->setRegisteredProperty(BasicAxisItem::P_NBINS, (int)alpha_axis.getSize()); + alphaAxisItem->setRegisteredProperty(BasicAxisItem::P_MIN, Units::rad2deg(alpha_axis.getMin())); + alphaAxisItem->setRegisteredProperty(BasicAxisItem::P_MAX, Units::rad2deg(alpha_axis.getMax())); + +} + + +void TransformFromDomain::setItemFromSample(BeamDistributionItem *beamDistributionItem, const ParameterDistribution ¶meterDistribution) +{ + Q_ASSERT(beamDistributionItem); + + double unit_factor(1.0); + double sign_factor(1.0); + if(beamDistributionItem->modelType() == Constants::BeamAzimuthalAngleType) { + unit_factor = 1./Units::degree; + sign_factor = 1.0; + } + else if(beamDistributionItem->modelType() == Constants::BeamInclinationAngleType) { + unit_factor = 1./Units::degree; + sign_factor = -1.0; + } + + const IDistribution1D *p_distr = parameterDistribution.getDistribution(); + ParameterizedItem *distributionItem(0); + if(const DistributionGate * distr = dynamic_cast<const DistributionGate *>(p_distr)) { + qDebug() << "XXX gate" << beamDistributionItem->modelType(); + distributionItem = beamDistributionItem->setGroupProperty(BeamDistributionItem::P_DISTRIBUTION, Constants::DistributionGateType); + double x1=sign_factor*unit_factor*distr->getMin(); + double x2=sign_factor*unit_factor*distr->getMax(); + distributionItem->setRegisteredProperty(DistributionGateItem::P_MIN, std::min(x1, x2)); + distributionItem->setRegisteredProperty(DistributionGateItem::P_MAX, std::max(x1, x2)); + } + else if(const DistributionLorentz *distr = dynamic_cast<const DistributionLorentz *>(p_distr)) { + qDebug() << "XXX lorentz" << beamDistributionItem->modelType(); + distributionItem = beamDistributionItem->setGroupProperty(BeamDistributionItem::P_DISTRIBUTION, Constants::DistributionLorentzType); + distributionItem->setRegisteredProperty(DistributionLorentzItem::P_MEAN, sign_factor*unit_factor*distr->getMean()); + distributionItem->setRegisteredProperty(DistributionLorentzItem::P_HWHM, unit_factor*distr->getHWHM()); + } + else if(const DistributionGaussian *distr = dynamic_cast<const DistributionGaussian *>(p_distr)) { + qDebug() << "XXX gauss" << beamDistributionItem->modelType(); + distributionItem = beamDistributionItem->setGroupProperty(BeamDistributionItem::P_DISTRIBUTION, Constants::DistributionGaussianType); + distributionItem->setRegisteredProperty(DistributionGaussianItem::P_MEAN, sign_factor*unit_factor*distr->getMean()); + distributionItem->setRegisteredProperty(DistributionGaussianItem::P_STD_DEV, unit_factor*distr->getStdDev()); + } + else if(const DistributionLogNormal *distr = dynamic_cast<const DistributionLogNormal *>(p_distr)) { + qDebug() << "XXX lognormal" << beamDistributionItem->modelType(); + distributionItem = beamDistributionItem->setGroupProperty(BeamDistributionItem::P_DISTRIBUTION, Constants::DistributionLogNormalType); + distributionItem->setRegisteredProperty(DistributionLogNormalItem::P_MEDIAN, sign_factor*unit_factor*distr->getMedian()); + distributionItem->setRegisteredProperty(DistributionLogNormalItem::P_SCALE_PAR, distr->getScalePar()); + } + else if(const DistributionCosine *distr = dynamic_cast<const DistributionCosine *>(p_distr)) { + qDebug() << "XXX cosine" << beamDistributionItem->modelType(); + distributionItem = beamDistributionItem->setGroupProperty(BeamDistributionItem::P_DISTRIBUTION, Constants::DistributionCosineType); + distributionItem->setRegisteredProperty(DistributionCosineItem::P_MEAN, sign_factor*unit_factor*distr->getMean()); + distributionItem->setRegisteredProperty(DistributionCosineItem::P_SIGMA, unit_factor*distr->getSigma()); + } + else { + throw GUIHelpers::Error("TransformFromDomain::setItemFromSample(BeamDistributionItem *distributionItem, const ParameterDistribution ¶meterDistribution) -> unknown distribution"); + } + + if(distributionItem->isRegisteredProperty(DistributionItem::P_NUMBER_OF_SAMPLES)) + distributionItem->setRegisteredProperty(DistributionItem::P_NUMBER_OF_SAMPLES, (int)parameterDistribution.getNbrSamples()); + + if(distributionItem->isRegisteredProperty(DistributionItem::P_SIGMA_FACTOR)) { + double sigma_factor = parameterDistribution.getSigmaFactor(); + if(sigma_factor == 0.0) sigma_factor = 2.0; + distributionItem->setRegisteredProperty(DistributionItem::P_SIGMA_FACTOR, sigma_factor); + } + +} + diff --git a/GUI/coregui/Models/TransformFromDomain.h b/GUI/coregui/Models/TransformFromDomain.h index 341042309665e275dde3bf15582a6a0ccb919713..c8a4d3449ee0ee27a075c2055ccd7f82b98f951e 100644 --- a/GUI/coregui/Models/TransformFromDomain.h +++ b/GUI/coregui/Models/TransformFromDomain.h @@ -19,8 +19,10 @@ #include "WinDllMacros.h" #include <QString> -class FormFactorAnisoPyramid; class ParameterizedItem; +class BeamItem; +class PhiAlphaDetectorItem; +class FormFactorAnisoPyramid; class InterferenceFunctionRadialParaCrystal; class InterferenceFunction2DParaCrystal; class InterferenceFunction2DLattice; @@ -29,6 +31,12 @@ class LayerInterface; class Layer; class Detector; class ParticleDistribution; +class Beam; +class Simulation; +class BeamDistributionItem; +class ParameterDistribution; +class DistributionItem; +class IDistribution1D; namespace TransformFromDomain { @@ -60,6 +68,12 @@ BA_CORE_API_ bool isHexagonalLattice(double length1, double length2, double angl BA_CORE_API_ QString getDetectorBinning(const Detector *detector); +BA_CORE_API_ void setItemFromSample(BeamItem *beamItem, const Simulation &simulation); + +BA_CORE_API_ void setItemFromSample(PhiAlphaDetectorItem *detectorItem, const Simulation &simulation); + +BA_CORE_API_ void setItemFromSample(BeamDistributionItem *beamDistributionItem, const ParameterDistribution ¶meterDistribution); + } #endif diff --git a/GUI/coregui/Models/TransformToDomain.cpp b/GUI/coregui/Models/TransformToDomain.cpp index cf246fccef3e89f65c28cabb3279cbcc7c6ccba5..5396e3108887089545e1e5204f9ee7494a9e58b0 100644 --- a/GUI/coregui/Models/TransformToDomain.cpp +++ b/GUI/coregui/Models/TransformToDomain.cpp @@ -23,6 +23,7 @@ #include "BeamItem.h" #include "ComboProperty.h" #include "DetectorItems.h" +#include "AxesItems.h" #include "MultiLayerItem.h" #include "LatticeTypeItems.h" #include "FTDistributionItems.h" @@ -37,6 +38,9 @@ #include "ConstKBinAxis.h" #include "ParticleLayoutItem.h" #include "DistributionItem.h" +//#include "BeamDistributionItem.h" +#include "BeamWavelengthItem.h" +#include "BeamAngleItems.h" #include <QDebug> #include <boost/scoped_ptr.hpp> @@ -288,12 +292,18 @@ Beam *TransformToDomain::createBeam(const ParameterizedItem &item) // qDebug() << "TransformToDomain::createBeam"; Beam *result = new Beam(); result->setName(item.itemName().toUtf8().constData()); - result->setIntensity(item.getRegisteredProperty(BeamItem::P_INTENSITY).toDouble()); - double lambda = item.getRegisteredProperty(BeamItem::P_WAVELENGTH).toDouble(); - AngleProperty inclination_angle = item.getRegisteredProperty(BeamItem::P_INCLINATION_ANGLE).value<AngleProperty>(); - AngleProperty azimuthal_angle = item.getRegisteredProperty(BeamItem::P_AZIMUTHAL_ANGLE).value<AngleProperty>(); - result->setCentralK( lambda, inclination_angle.getValueInRadians(), azimuthal_angle.getValueInRadians()); + const BeamItem *beamItem = dynamic_cast<const BeamItem *>(&item); + + result->setIntensity(beamItem->getIntensity()); + double lambda = beamItem->getWavelength(); + double inclination_angle = Units::deg2rad(beamItem->getInclinationAngle()); + double azimuthal_angle = Units::deg2rad(beamItem->getAzimuthalAngle()); + result->setCentralK( lambda, inclination_angle, azimuthal_angle); + +// AngleProperty inclination_angle = item.getRegisteredProperty(BeamItem::P_INCLINATION_ANGLE).value<AngleProperty>(); +// AngleProperty azimuthal_angle = item.getRegisteredProperty(BeamItem::P_AZIMUTHAL_ANGLE).value<AngleProperty>(); +// result->setCentralK( lambda, inclination_angle.getValueInRadians(), azimuthal_angle.getValueInRadians()); return result; } @@ -307,35 +317,29 @@ void TransformToDomain::initInstrumentFromDetectorItem(const ParameterizedItem & // qDebug() << " TransformToDomain::initInstrumentWithDetectorItem()" << subDetector->modelType(); if (subDetector->modelType() == Constants::PhiAlphaDetectorType) { - int nphi = subDetector->getRegisteredProperty(PhiAlphaDetectorItem::P_NPHI).toInt(); - AngleProperty phi_min_property = subDetector->getRegisteredProperty(PhiAlphaDetectorItem::P_PHI_MIN).value<AngleProperty>(); - AngleProperty phi_max_property = subDetector->getRegisteredProperty(PhiAlphaDetectorItem::P_PHI_MAX).value<AngleProperty>(); - double phi_min = phi_min_property.getValueInRadians(); - double phi_max = phi_max_property.getValueInRadians(); + BasicAxisItem *phiAxis = dynamic_cast<BasicAxisItem *>(subDetector->getSubItems()[PhiAlphaDetectorItem::P_PHI_AXIS]); + Q_ASSERT(phiAxis); + int nphi = phiAxis->getRegisteredProperty(BasicAxisItem::P_NBINS).toInt(); + double phi_min = Units::deg2rad(phiAxis->getRegisteredProperty(BasicAxisItem::P_MIN).toDouble()); + double phi_max = Units::deg2rad(phiAxis->getRegisteredProperty(BasicAxisItem::P_MAX).toDouble()); - int nalpha = subDetector->getRegisteredProperty(PhiAlphaDetectorItem::P_NALPHA).toInt(); - - AngleProperty alpha_min_property = subDetector->getRegisteredProperty(PhiAlphaDetectorItem::P_ALPHA_MIN).value<AngleProperty>(); - AngleProperty alpha_max_property = subDetector->getRegisteredProperty(PhiAlphaDetectorItem::P_ALPHA_MAX).value<AngleProperty>(); - double alpha_min = alpha_min_property.getValueInRadians(); - double alpha_max = alpha_max_property.getValueInRadians(); + BasicAxisItem *alphaAxis = dynamic_cast<BasicAxisItem *>(subDetector->getSubItems()[PhiAlphaDetectorItem::P_ALPHA_AXIS]); + Q_ASSERT(alphaAxis); + int nalpha = alphaAxis->getRegisteredProperty(BasicAxisItem::P_NBINS).toInt(); + double alpha_min = Units::deg2rad(alphaAxis->getRegisteredProperty(BasicAxisItem::P_MIN).toDouble()); + double alpha_max = Units::deg2rad(alphaAxis->getRegisteredProperty(BasicAxisItem::P_MAX).toDouble()); ComboProperty binning = subDetector->getRegisteredProperty(PhiAlphaDetectorItem::P_BINNING).value<ComboProperty>(); - // FIXME Get rid from hardcoded string -// if(binning.getValue() != QStringLiteral("Const KBin")) -// throw GUIHelpers::Error("TransformToDomain::initInstrumentFromDetectorItem() -> Not implemented"); - if(binning.getValue() == QStringLiteral("Const KBin")) { + if(binning.getValue() == Constants::AXIS_CONSTK_BINNING) { instrument->setDetectorAxes(ConstKBinAxis("phi_x",nphi, phi_min, phi_max), ConstKBinAxis("alpha_x", nalpha, alpha_min, alpha_max)); - }else if(binning.getValue() == QStringLiteral("Fixed")) { + }else if(binning.getValue() == Constants::AXIS_FIXED_BINNING) { instrument->setDetectorAxes(FixedBinAxis("phi_x",nphi, phi_min, phi_max), FixedBinAxis("alpha_x", nalpha, alpha_min, alpha_max)); } else { throw GUIHelpers::Error("TransformToDomain::initInstrumentFromDetectorItem() -> Unknown axes"); } -// instrument->setDetectorParameters(nphi, phi_min, phi_max, nalpha, alpha_min, alpha_max); - } else { throw GUIHelpers::Error("TransformToDomain::initInstrumentWithDetectorItem() -> Error. Unknown model type "+subDetector->modelType()); @@ -379,3 +383,29 @@ LayerRoughness *TransformToDomain::createLayerRoughness(const ParameterizedItem } } + +//! adds DistributionParameters to the Simulation +void TransformToDomain::addDistributionParametersToSimulation(const ParameterizedItem &beam_item, Simulation *simulation) +{ + if(beam_item.modelType() == Constants::BeamType) { + + if(BeamWavelengthItem *beamWavelength = dynamic_cast<BeamWavelengthItem *>(beam_item.getSubItems()[BeamItem::P_WAVELENGTH])) { + ParameterDistribution *distr = beamWavelength->getParameterDistributionForName("*/Beam/wavelength"); + if(distr) simulation->addParameterDistribution(*distr); + delete distr; + } + + if(BeamInclinationAngleItem *inclinationAngle = dynamic_cast<BeamInclinationAngleItem *>(beam_item.getSubItems()[BeamItem::P_INCLINATION_ANGLE])) { + ParameterDistribution *distr = inclinationAngle->getParameterDistributionForName("*/Beam/alpha"); + if(distr) simulation->addParameterDistribution(*distr); + delete distr; + } + + if(BeamAzimuthalAngleItem *azimuthalAngle = dynamic_cast<BeamAzimuthalAngleItem *>(beam_item.getSubItems()[BeamItem::P_AZIMUTHAL_ANGLE])) { + ParameterDistribution *distr = azimuthalAngle->getParameterDistributionForName("*/Beam/phi"); + if(distr) simulation->addParameterDistribution(*distr); + delete distr; + } + } + +} diff --git a/GUI/coregui/Models/TransformToDomain.h b/GUI/coregui/Models/TransformToDomain.h index 5459ff080e1087210a73cee803cd08ce2b39c106..b008a7e0c864466124852181f748d39d443671e6 100644 --- a/GUI/coregui/Models/TransformToDomain.h +++ b/GUI/coregui/Models/TransformToDomain.h @@ -42,6 +42,7 @@ BA_CORE_API_ Beam *createBeam(const ParameterizedItem &item); BA_CORE_API_ LayerRoughness *createLayerRoughness(const ParameterizedItem &item); BA_CORE_API_ void initInstrumentFromDetectorItem(const ParameterizedItem &item, Instrument *instrument); +BA_CORE_API_ void addDistributionParametersToSimulation(const ParameterizedItem &beam_item, Simulation *simulation); } #endif // TRANSFORMTODOMAIN_H diff --git a/GUI/coregui/Models/item_constants.h b/GUI/coregui/Models/item_constants.h index b7bc2a1b0f288a18bf958082186265070eeb49b3..6433d6fc7e91a9cd3668119ec9f8de264f8f0920 100644 --- a/GUI/coregui/Models/item_constants.h +++ b/GUI/coregui/Models/item_constants.h @@ -69,9 +69,8 @@ const ModelType LayerBasicRoughnessType = "LayerBasicRoughness"; const ModelType LayerZeroRoughnessType = "LayerZeroRoughness"; const ModelType PhiAlphaDetectorType = "PhiAlphaDetector"; -const ModelType XYDetectorType = "XYDetector"; -const ModelType DistributionType = "Distribution"; +const ModelType DistributionNoneType = "DistributionNone"; const ModelType DistributionGateType = "DistributionGate"; const ModelType DistributionLorentzType = "DistributionLorentz"; const ModelType DistributionGaussianType = "DistributionGaussian"; @@ -111,6 +110,14 @@ const ModelType IntensityDataType = "IntensityData"; const ModelType BasicAxisType = "BasicAxis"; const ModelType AmplitudeAxisType = "AmplitudeAxis"; +const ModelType BeamDistributionType = "BeamDistribution"; +const ModelType BeamWavelengthType = "BeamWavelength"; +const ModelType BeamAzimuthalAngleType = "BeamAzimuthalAngle"; +const ModelType BeamInclinationAngleType = "BeamInclinationAngle"; + +const ModelType ResolutionFunctionNoneType = "ResolutionFunctionNone"; +const ModelType ResolutionFunction2DGaussianType = "ResolutionFunction2DGaussian"; + // --- Groups ------------------------------------------------------------------ const ModelType FormFactorGroup = "Form Factor"; @@ -118,10 +125,12 @@ const ModelType RotationGroup = "Rotation"; const ModelType LayerRoughnessGroup = "Roughness"; const ModelType DetectorGroup = "Detector group"; const ModelType DistributionGroup = "Distribution group"; +const ModelType DistributionExtendedGroup = "Distribution extended group"; const ModelType FTDistribution1DGroup = "PDF 1D"; const ModelType FTDistribution2DGroup = "PDF 2D"; const ModelType LatticeGroup = "Lattice group"; const ModelType MaterialGroup = "Material group"; +const ModelType ResolutionFunctionGroup = "Resolution function group"; // --- Units&Constants---------------------------------------------------------- const ModelType UnitsDegrees = "Degrees"; @@ -146,6 +155,9 @@ const ModelType GRADIENT_SPECTRUM = "Spectrum"; const ModelType GRADIENT_JET = "Jet"; const ModelType GRADIENT_HUES = "Hues"; +const ModelType AXIS_FIXED_BINNING = "Fixed"; +const ModelType AXIS_CONSTK_BINNING = "Const KBin"; + } diff --git a/GUI/coregui/Views/InstrumentView.cpp b/GUI/coregui/Views/InstrumentView.cpp index 6009bee9a310cfc97383c5a7f6b5c1c9f20a0ccf..4a21aab73a230eb6240f7d9f18c5769b44f9a48a 100644 --- a/GUI/coregui/Views/InstrumentView.cpp +++ b/GUI/coregui/Views/InstrumentView.cpp @@ -17,6 +17,7 @@ #include "InstrumentModel.h" #include "InstrumentSelectorWidget.h" #include "InstrumentEditorWidget.h" +#include "InstrumentItem.h" #include "styledbar.h" #include "minisplitter.h" #include <QBoxLayout> diff --git a/GUI/coregui/Views/InstrumentWidgets/BeamEditorWidget.cpp b/GUI/coregui/Views/InstrumentWidgets/BeamEditorWidget.cpp index ff88c2da53be3a84aafdd6067eced58c1bd456ea..d2ac34de4ec1a085b06b0261b2709c7c274ce795 100644 --- a/GUI/coregui/Views/InstrumentWidgets/BeamEditorWidget.cpp +++ b/GUI/coregui/Views/InstrumentWidgets/BeamEditorWidget.cpp @@ -14,232 +14,80 @@ // ************************************************************************** // #include "BeamEditorWidget.h" -#include "ComboProperty.h" -#include "DetectorItems.h" +#include "UniversalPropertyEditor.h" +#include "AwesomePropertyEditor.h" #include "BeamItem.h" -#include "Units.h" -#include "AngleProperty.h" -#include "GUIHelpers.h" +#include "LayerItem.h" #include "GroupBox.h" -#include "ComboWidget.h" -#include <QLineEdit> -#include <QBoxLayout> -#include <QDoubleValidator> -#include <QLabel> #include <QGroupBox> +#include <QVBoxLayout> +#include <QLabel> +#include <QLineEdit> #include <QComboBox> -#include <QSpinBox> -#include <QDoubleSpinBox> -#include <QGridLayout> #include <QDebug> BeamEditorWidget::BeamEditorWidget(QWidget *parent) : QWidget(parent) - , m_intensityText( new QLineEdit) - , m_intensityValidator(0) - , m_wavelengthSpinBox(new QDoubleSpinBox) - , m_angleUnits(new QComboBox) - , m_inclinationAngleSpinBox(new QDoubleSpinBox) - , m_azimuthalAngleSpinBox(new QDoubleSpinBox) - , m_beamTypeCombo(new QComboBox) - , m_currentItem(0) - , m_block_signals(false) + , m_intensityEditor(0) + , m_wavelengthEditor(0) + , m_inclinationAngleEditor(0) + , m_azimuthalAngleEditor(0) + , m_beamItem(0) { - - m_intensityValidator = new QDoubleValidator(0.1, 1e+100, 2, this); - m_intensityValidator->setNotation(QDoubleValidator::ScientificNotation); - m_intensityText->setValidator(m_intensityValidator); - - m_wavelengthSpinBox->setSingleStep(0.1); - m_wavelengthSpinBox->setDecimals(4); - m_wavelengthSpinBox->setMinimum(0.0001); - m_wavelengthSpinBox->setMaximum(100.); - - m_beamTypeCombo->addItem("Monochromatic"); - + setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding); // group box layout - QGroupBox *beamGroup = new QGroupBox("Beam Parameters"); - QVBoxLayout *beamGroupLayout = new QVBoxLayout; - beamGroup->setLayout(beamGroupLayout); - - QGridLayout *beamParamsLayout = new QGridLayout; - beamParamsLayout->addWidget(new QLabel(BeamItem::P_INTENSITY), 0, 0); - beamParamsLayout->addWidget(m_intensityText, 0, 1); - beamParamsLayout->addWidget(new QLabel(BeamItem::P_WAVELENGTH), 1, 0); - beamParamsLayout->addWidget(m_wavelengthSpinBox, 1, 1); - beamParamsLayout->addWidget(new QLabel(" "), 2, 2); - beamParamsLayout->addWidget(new QLabel("Inclination angle"), 3, 0); - beamParamsLayout->addWidget(m_inclinationAngleSpinBox, 3, 1); - beamParamsLayout->addWidget(m_angleUnits, 3, 2); - beamParamsLayout->addWidget(new QLabel("Azimuthal angle"), 4, 0); - beamParamsLayout->addWidget(m_azimuthalAngleSpinBox, 4, 1); - beamParamsLayout->addWidget(new QLabel("Beam Type"), 5, 0); - beamParamsLayout->addWidget(m_beamTypeCombo, 5, 1); - - - /* Code of Mahadi, will be used in the future for beam divergence - - //GroupBox Test - GroupBox *settingsGroupBox = new GroupBox("Beam Type Settings"); - QVBoxLayout *beamTypeSettingsGroupLayout2 = new QVBoxLayout; - settingsGroupBox->setLayout(beamTypeSettingsGroupLayout2); - - QGridLayout *beamTypeLayout2 = new QGridLayout; - beamTypeLayout2->addWidget(new QLabel("Param 1"), 0, 0); - beamTypeLayout2->addWidget(new QLineEdit, 0, 1); - beamTypeLayout2->addWidget(new QLabel("Param 2"), 1, 0); - beamTypeLayout2->addWidget(new QLineEdit, 1, 1); - - beamTypeSettingsGroupLayout2->addLayout(beamTypeLayout2); + QGroupBox *groupBox = new QGroupBox("Beam Parameters"); + //QGroupBox *groupBox = new GroupBox("Beam Parameters"); - beamParamsLayout->addWidget(settingsGroupBox, 6,1,1,1); - //end of GroupBox Test + QVBoxLayout *groupLayout = new QVBoxLayout; + groupBox->setLayout(groupLayout); + // whole content is represented as grid layout + QGridLayout *gridLayout = new QGridLayout; + m_intensityEditor = new AwesomePropertyEditor(this, AwesomePropertyEditor::BROWSER_GROUPBOX_TYPE); + gridLayout->addWidget(m_intensityEditor, 0, 0); - //ComboWidget Test - QGridLayout *comboLayout = new QGridLayout; - comboLayout->addWidget(new QLabel("Param 1"), 0, 0); - comboLayout->addWidget(new QLineEdit, 0, 1); - comboLayout->addWidget(new QLabel("Param 2"), 1, 0); - comboLayout->addWidget(new QLineEdit, 1, 1); + m_wavelengthEditor = new AwesomePropertyEditor(this, AwesomePropertyEditor::BROWSER_GROUPBOX_TYPE); + gridLayout->addWidget(m_wavelengthEditor, 1, 0); + m_inclinationAngleEditor = new AwesomePropertyEditor(this, AwesomePropertyEditor::BROWSER_GROUPBOX_TYPE); + gridLayout->addWidget(m_inclinationAngleEditor, 2, 0); + m_azimuthalAngleEditor = new AwesomePropertyEditor(this, AwesomePropertyEditor::BROWSER_GROUPBOX_TYPE); + gridLayout->addWidget(m_azimuthalAngleEditor, 2, 1); - ComboWidget *comboWidget = new ComboWidget("Monochromatic", comboLayout, this); - beamParamsLayout->addWidget(new QLabel("Beam Type"), 7, 0); - beamParamsLayout->addWidget(comboWidget, 7,1,1,2); +// gridLayout->setColumnStretch(0,0); +// gridLayout->setColumnStretch(1,0); - comboWidget->addItem("Dichromatic"); - //end of ComboWidget Test - - */ - - - - beamGroupLayout->addLayout(beamParamsLayout); + groupLayout->addLayout(gridLayout); // main layout QVBoxLayout *mainLayout = new QVBoxLayout; - mainLayout->addWidget(beamGroup); + mainLayout->addWidget(groupBox); + mainLayout->addStretch(); setLayout(mainLayout); - - // signals - connect(m_intensityText, SIGNAL(editingFinished()), this, SLOT(onIntensityEditingFinished())); - connect(m_wavelengthSpinBox, SIGNAL(valueChanged(const QString &)), this, SLOT(onChangedWavelength(const QString &))); - connect(m_angleUnits, SIGNAL(currentIndexChanged(int)), this, SLOT(onAngleUnitsChanged(int))); - connect(m_inclinationAngleSpinBox, SIGNAL(valueChanged(const QString &)), this, SLOT(onChangedAngle(const QString &))); - connect(m_azimuthalAngleSpinBox, SIGNAL(valueChanged(const QString &)), this, SLOT(onChangedAngle(const QString &))); } -void BeamEditorWidget::initFromItem(BeamItem *item) +void BeamEditorWidget::setBeamItem(BeamItem *beamItem) { - qDebug() << "DetectorEditorWidget::initFromItem()"; - - if(item != m_currentItem) { - if(m_currentItem) { - disconnect(m_currentItem, SIGNAL(propertyChanged(const QString &)), this, SLOT(onPropertyChanged(const QString &))); - //disconnect(m_currentItem, SIGNAL(propertyItemChanged(const QString &)), this, SLOT(onPropertyChanged(const QString &))); - } - - m_currentItem = item; + m_beamItem = beamItem; + m_intensityEditor->clearEditor(); + m_wavelengthEditor->clearEditor(); + m_inclinationAngleEditor->clearEditor(); + m_azimuthalAngleEditor->clearEditor(); - connect(item, SIGNAL(propertyChanged(const QString &)), this, SLOT(onPropertyChanged(const QString &))); -// connect(item, SIGNAL(propertyItemChanged(const QString &)), this, SLOT(onPropertyChanged(const QString &))); + if(!m_beamItem) return; - updateWidgets(); - } -} + m_intensityEditor->addItemProperty(m_beamItem, BeamItem::P_INTENSITY); + ParameterizedItem *wavelengthItem = m_beamItem->getSubItems()[BeamItem::P_WAVELENGTH]; + m_wavelengthEditor->addItemProperties(wavelengthItem, QString("Wavelength"), AwesomePropertyEditor::INSERT_AFTER); -void BeamEditorWidget::onIntensityEditingFinished() -{ - if(m_block_signals) return; - m_currentItem->setRegisteredProperty(BeamItem::P_INTENSITY, m_intensityText->text().toDouble()); -} + ParameterizedItem *inclinationAngleItem = m_beamItem->getSubItems()[BeamItem::P_INCLINATION_ANGLE]; + m_inclinationAngleEditor->addItemProperties(inclinationAngleItem, QString("Inclination angle"), AwesomePropertyEditor::INSERT_AFTER); + ParameterizedItem *azimuthalAngleItem = m_beamItem->getSubItems()[BeamItem::P_AZIMUTHAL_ANGLE]; + m_azimuthalAngleEditor->addItemProperties(azimuthalAngleItem, QString("Azimuthal angle"), AwesomePropertyEditor::INSERT_AFTER); -void BeamEditorWidget::onChangedWavelength(const QString & /* text */) -{ - if(m_block_signals) return; - m_currentItem->setRegisteredProperty(BeamItem::P_WAVELENGTH, m_wavelengthSpinBox->value()); } -void BeamEditorWidget::onChangedAngle(const QString &) -{ - if(m_block_signals) return; - - AngleProperty inclination_angle = m_currentItem->getRegisteredProperty(BeamItem::P_INCLINATION_ANGLE).value<AngleProperty>(); - inclination_angle.setValue(m_inclinationAngleSpinBox->value()); - m_currentItem->setRegisteredProperty(BeamItem::P_INCLINATION_ANGLE, inclination_angle.getVariant()); - - AngleProperty azimuthal_angle = m_currentItem->getRegisteredProperty(BeamItem::P_AZIMUTHAL_ANGLE).value<AngleProperty>(); - azimuthal_angle.setValue(m_azimuthalAngleSpinBox->value()); - m_currentItem->setRegisteredProperty(BeamItem::P_AZIMUTHAL_ANGLE, azimuthal_angle.getVariant()); -} - - -void BeamEditorWidget::onPropertyChanged(const QString &name) -{ - qDebug() << "BeamEditorWidget::onPropertyChanged() -> " << name; - updateWidgets(); -} - - - -void BeamEditorWidget::onAngleUnitsChanged(int) -{ - if(m_block_signals) return; - qDebug() << "BeamEditorWidget::onAngleUnitsChanged(int) " << m_angleUnits->currentText(); - AngleProperty inclination_angle = m_currentItem->getRegisteredProperty(BeamItem::P_INCLINATION_ANGLE).value<AngleProperty>(); - inclination_angle.setUnits(m_angleUnits->currentText()); - m_currentItem->setRegisteredProperty(BeamItem::P_INCLINATION_ANGLE, inclination_angle.getVariant()); -} - - -void BeamEditorWidget::updateWidgets() -{ - Q_ASSERT(m_currentItem); - qDebug() << "DetectorEditorWidget::updateWidgets() ->"; - - setBlockSignals(true); - m_intensityText->setText(QString::number(m_currentItem->getRegisteredProperty(BeamItem::P_INTENSITY).toDouble())); - m_wavelengthSpinBox->setValue(m_currentItem->getRegisteredProperty(BeamItem::P_WAVELENGTH).toDouble()); - - AngleProperty inclination_angle = m_currentItem->getRegisteredProperty(BeamItem::P_INCLINATION_ANGLE).value<AngleProperty>(); - AngleProperty azimuthal_angle = m_currentItem->getRegisteredProperty(BeamItem::P_AZIMUTHAL_ANGLE).value<AngleProperty>(); - - // Units from inclination_agle will control azimuthal_angle too - m_angleUnits->clear(); - m_angleUnits->addItems(inclination_angle.getLabels()); - m_angleUnits->setCurrentText(inclination_angle.getUnits()); - - setAngleUnits(m_inclinationAngleSpinBox, inclination_angle); - setAngleUnits(m_azimuthalAngleSpinBox, azimuthal_angle); - - setBlockSignals(false); -} - - -void BeamEditorWidget::setBlockSignals(bool flag) -{ - m_block_signals = flag; -} - - -void BeamEditorWidget::setAngleUnits(QDoubleSpinBox *editor, const AngleProperty &units, double min_deg, double max_deg) -{ - if(units.inDegrees()) { - editor->setSingleStep(0.01); - editor->setMinimum(min_deg); - editor->setMaximum(max_deg); - editor->setDecimals(3); - editor->setValue(units.getValue()); - } - else { - editor->setSingleStep(0.0001); - editor->setMinimum(Units::deg2rad(min_deg)); - editor->setMaximum(Units::deg2rad(max_deg)); - editor->setDecimals(6); - editor->setValue(units.getValue()); - } -} diff --git a/GUI/coregui/Views/InstrumentWidgets/BeamEditorWidget.h b/GUI/coregui/Views/InstrumentWidgets/BeamEditorWidget.h index c78fe2d93af84939f0e45159bac940a113215546..beac0758352cdff05703a0af5ea3119a1e4c9c4f 100644 --- a/GUI/coregui/Views/InstrumentWidgets/BeamEditorWidget.h +++ b/GUI/coregui/Views/InstrumentWidgets/BeamEditorWidget.h @@ -13,53 +13,29 @@ // // ************************************************************************** // -#ifndef BEAM_EDITOR_WIDGET_H -#define BEAM_EDITOR_WIDGET_H +#ifndef BEAMEDITORWIDGET_H +#define BEAMEDITORWIDGET_H #include "WinDllMacros.h" #include <QWidget> -class QComboBox; -class QDoubleSpinBox; -class QLineEdit; -class QLabel; class BeamItem; -class QDoubleValidator; -class AngleProperty; +class AwesomePropertyEditor; class BA_CORE_API_ BeamEditorWidget : public QWidget { Q_OBJECT - public: BeamEditorWidget(QWidget *parent = 0); - void initFromItem(BeamItem *item); - -public slots: - void onIntensityEditingFinished(); - void onChangedWavelength(const QString &); - void onChangedAngle(const QString &); - - void onPropertyChanged(const QString &); - - void onAngleUnitsChanged(int); + void setBeamItem(BeamItem *beamItem); private: - void updateWidgets(); - void setBlockSignals(bool flag); - void setAngleUnits(QDoubleSpinBox *, const AngleProperty &units, double min_deg = -90.0, double max_deg = 90.0); - - QLineEdit *m_intensityText; - QDoubleValidator *m_intensityValidator; - QDoubleSpinBox *m_wavelengthSpinBox; - QComboBox *m_angleUnits; - QDoubleSpinBox *m_inclinationAngleSpinBox; - QDoubleSpinBox *m_azimuthalAngleSpinBox; - QComboBox *m_beamTypeCombo; - BeamItem *m_currentItem; - bool m_block_signals; + AwesomePropertyEditor *m_intensityEditor; + AwesomePropertyEditor *m_wavelengthEditor; + AwesomePropertyEditor *m_inclinationAngleEditor; + AwesomePropertyEditor *m_azimuthalAngleEditor; + BeamItem *m_beamItem; }; - #endif diff --git a/GUI/coregui/Views/InstrumentWidgets/DetectorEditorWidget.cpp b/GUI/coregui/Views/InstrumentWidgets/DetectorEditorWidget.cpp index 4f72d71a10ee7bea4e7dbbc91ba7434ee58b0f01..fc79a3d15ef1f71303048f98e3f6305a5828e2b3 100644 --- a/GUI/coregui/Views/InstrumentWidgets/DetectorEditorWidget.cpp +++ b/GUI/coregui/Views/InstrumentWidgets/DetectorEditorWidget.cpp @@ -14,256 +14,73 @@ // ************************************************************************** // #include "DetectorEditorWidget.h" -#include "FancyGroupProperty.h" -#include "ComboProperty.h" +#include "AwesomePropertyEditor.h" #include "DetectorItems.h" -#include "GUIHelpers.h" -#include "Units.h" -#include "AngleProperty.h" -#include <QBoxLayout> -#include <QLabel> #include <QGroupBox> -#include <QComboBox> -#include <QSpinBox> -#include <QDoubleSpinBox> -#include <QGridLayout> -#include <QDebug> +#include <QVBoxLayout> DetectorEditorWidget::DetectorEditorWidget(QWidget *parent) : QWidget(parent) - , m_detectorTypeCombo(new QComboBox) - , m_unitsCombo(new QComboBox) - , m_binningTypeCombo(new QComboBox) - , m_axis0Label(0) - , m_axis1Label(0) - , m_phiMinEdit(new QDoubleSpinBox) - , m_phiMaxEdit(new QDoubleSpinBox) - , m_nphiEdit(new QSpinBox) - , m_alphaMinEdit(new QDoubleSpinBox) - , m_alphaMaxEdit(new QDoubleSpinBox) - , m_nalphaEdit(new QSpinBox) - , m_currentItem(0) - , m_block_signals(false) - + , m_binningEditor(0) + , m_phiAxisEditor(0) + , m_alphaAxisEditor(0) + , m_resolutionFunctionEditor(0) + , m_detectorItem(0) { + QGroupBox *groupBox = new QGroupBox("Detector Parameters"); + QVBoxLayout *groupLayout = new QVBoxLayout; + groupBox->setLayout(groupLayout); - QGroupBox *detectorGroup = new QGroupBox("Detector Parameters"); - - m_axis0Label = new QLabel("Phi"); - m_axis1Label = new QLabel("Alpha"); - - m_nphiEdit->setMinimum(1); - m_nphiEdit->setMaximum(1024); - m_nalphaEdit->setMinimum(1); - m_nalphaEdit->setMaximum(1024); - - QGridLayout *detectorLayout = new QGridLayout; - detectorLayout->addWidget(new QLabel("Detector Type"), 0, 0); - detectorLayout->addWidget(m_detectorTypeCombo, 0, 1, 1, 1); - detectorLayout->addWidget(new QLabel("Units"), 1, 0); - detectorLayout->addWidget(m_unitsCombo, 1, 1); - detectorLayout->addWidget(new QLabel("Binning"), 2, 0); - detectorLayout->addWidget(m_binningTypeCombo, 2, 1); - detectorLayout->addWidget(m_binningTypeCombo, 2, 1); + // whole content is represented as grid layout + QGridLayout *gridLayout = new QGridLayout; - detectorLayout->addWidget(new QLabel("min"), 3, 1); - detectorLayout->addWidget(new QLabel("max"), 3, 2); - detectorLayout->addWidget(new QLabel("nbins"), 3, 3); + m_binningEditor = new AwesomePropertyEditor(this, AwesomePropertyEditor::BROWSER_GROUPBOX_TYPE); + gridLayout->addWidget(m_binningEditor, 0, 0); + m_phiAxisEditor = new AwesomePropertyEditor(this, AwesomePropertyEditor::BROWSER_GROUPBOX_TYPE); + gridLayout->addWidget(m_phiAxisEditor, 1, 0); + m_alphaAxisEditor = new AwesomePropertyEditor(this, AwesomePropertyEditor::BROWSER_GROUPBOX_TYPE); + gridLayout->addWidget(m_alphaAxisEditor, 1, 1); - detectorLayout->addWidget(m_axis0Label, 5, 0); - detectorLayout->addWidget(m_phiMinEdit, 5, 1); - detectorLayout->addWidget(m_phiMaxEdit, 5, 2); - detectorLayout->addWidget(m_nphiEdit, 5, 3); + m_resolutionFunctionEditor = new AwesomePropertyEditor(this, AwesomePropertyEditor::BROWSER_GROUPBOX_TYPE); + gridLayout->addWidget(m_resolutionFunctionEditor, 2, 0); - detectorLayout->addWidget(m_axis1Label, 6, 0); - detectorLayout->addWidget(m_alphaMinEdit, 6, 1); - detectorLayout->addWidget(m_alphaMaxEdit, 6, 2); - detectorLayout->addWidget(m_nalphaEdit, 6, 3); - - detectorLayout->setColumnStretch(0,1); - detectorLayout->setColumnStretch(1,3); - detectorLayout->setColumnStretch(2,3); - detectorLayout->setColumnStretch(3,1); - detectorLayout->setColumnStretch(4,3); - detectorGroup->setLayout(detectorLayout); + groupLayout->addLayout(gridLayout); // main layout QVBoxLayout *mainLayout = new QVBoxLayout; - mainLayout->addWidget(detectorGroup); + mainLayout->addWidget(groupBox); + mainLayout->addStretch(); setLayout(mainLayout); - connect(m_detectorTypeCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(onDetectorTypeChanged(int))); - connect(m_unitsCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(onAngleUnitsChanged(int))); - connect(m_binningTypeCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(onBinningTypeChanged(int))); - connect(m_phiMinEdit, SIGNAL(valueChanged(QString)), this, SLOT(onAngleEditorChanged(QString))); - connect(m_phiMaxEdit, SIGNAL(valueChanged(QString)), this, SLOT(onAngleEditorChanged(QString))); - connect(m_nphiEdit, SIGNAL(valueChanged(QString)), this, SLOT(onAngleEditorChanged(QString))); - connect(m_alphaMinEdit, SIGNAL(valueChanged(QString)), this, SLOT(onAngleEditorChanged(QString))); - connect(m_alphaMaxEdit, SIGNAL(valueChanged(QString)), this, SLOT(onAngleEditorChanged(QString))); - connect(m_nalphaEdit, SIGNAL(valueChanged(QString)), this, SLOT(onAngleEditorChanged(QString))); -} - - -void DetectorEditorWidget::initFromItem(ParameterizedItem *item) -{ - qDebug() << "DetectorEditorWidget::initFromItem()" << item->modelType(); - - if(item != m_currentItem) { - if(m_currentItem) { - disconnect(item, SIGNAL(propertyChanged(const QString &)), this, SLOT(onPropertyChanged(const QString &))); - disconnect(item, SIGNAL(propertyItemChanged(const QString &)), this, SLOT(onPropertyChanged(const QString &))); - } - - m_currentItem = item; - - connect(item, SIGNAL(propertyChanged(const QString &)), this, SLOT(onPropertyChanged(const QString &))); - connect(item, SIGNAL(propertyItemChanged(const QString &)), this, SLOT(onPropertyChanged(const QString &))); - - updateWidgets(); - } } - -void DetectorEditorWidget::updateWidgets() +void DetectorEditorWidget::setDetectorItem(DetectorItem *detectorItem) { - qDebug() << "DetectorEditorWidget::updateWidgets() ->"; - - m_block_signals = true; - m_detectorTypeCombo->clear(); - FancyGroupProperty_t detector_property = m_currentItem->getRegisteredProperty(DetectorItem::P_DETECTOR).value<FancyGroupProperty_t>(); + m_detectorItem = detectorItem; + m_binningEditor->clearEditor(); + m_phiAxisEditor->clearEditor(); + m_alphaAxisEditor->clearEditor(); + m_resolutionFunctionEditor->clearEditor(); - m_detectorTypeCombo->addItems(detector_property->getValueLabels()); - m_detectorTypeCombo->setCurrentIndex(detector_property->toIndex(detector_property->getValue())); + if(!m_detectorItem) return; - ParameterizedItem *subDetector = m_currentItem->getSubItems()[DetectorItem::P_DETECTOR]; - Q_ASSERT(subDetector); + PhiAlphaDetectorItem *subDetector = dynamic_cast<PhiAlphaDetectorItem *>(detectorItem->getSubItems()[DetectorItem::P_DETECTOR]); - if (subDetector->modelType() == Constants::PhiAlphaDetectorType) { - AngleProperty units = subDetector->getRegisteredProperty(PhiAlphaDetectorItem::P_AXES_UNITS).value<AngleProperty>(); - m_unitsCombo->clear(); - m_unitsCombo->addItems(units.getLabels()); - m_unitsCombo->setCurrentText(units.getUnits()); + m_binningEditor->addItemProperty(subDetector, PhiAlphaDetectorItem::P_BINNING); - m_binningTypeCombo->clear(); - ComboProperty binning_property = subDetector->getRegisteredProperty(PhiAlphaDetectorItem::P_BINNING).value<ComboProperty>(); - m_binningTypeCombo->addItems(binning_property.getValues()); - m_binningTypeCombo->setCurrentText(binning_property.getValue()); + ParameterizedItem *phiAxisItem = subDetector->getSubItems()[PhiAlphaDetectorItem::P_PHI_AXIS]; + m_phiAxisEditor->addItemProperties(phiAxisItem, QString("Phi axis"), AwesomePropertyEditor::INSERT_AFTER); - int nphi = subDetector->getRegisteredProperty(PhiAlphaDetectorItem::P_NPHI).toInt(); - m_nphiEdit->setValue(nphi); - AngleProperty phi_min_property = subDetector->getRegisteredProperty(PhiAlphaDetectorItem::P_PHI_MIN).value<AngleProperty>(); - setAngleUnits(m_phiMinEdit, phi_min_property); - AngleProperty phi_max_property = subDetector->getRegisteredProperty(PhiAlphaDetectorItem::P_PHI_MAX).value<AngleProperty>(); - setAngleUnits(m_phiMaxEdit, phi_max_property); + ParameterizedItem *alphaAxisItem = subDetector->getSubItems()[PhiAlphaDetectorItem::P_ALPHA_AXIS]; + m_alphaAxisEditor->addItemProperties(alphaAxisItem, QString("Alpha axis"), AwesomePropertyEditor::INSERT_AFTER); - int nalpha = subDetector->getRegisteredProperty(PhiAlphaDetectorItem::P_NALPHA).toInt(); - AngleProperty alpha_min_property = subDetector->getRegisteredProperty(PhiAlphaDetectorItem::P_ALPHA_MIN).value<AngleProperty>(); - setAngleUnits(m_alphaMinEdit, alpha_min_property); - AngleProperty alpha_max_property = subDetector->getRegisteredProperty(PhiAlphaDetectorItem::P_ALPHA_MAX).value<AngleProperty>(); - setAngleUnits(m_alphaMaxEdit, alpha_max_property); - m_nalphaEdit->setValue(nalpha); +// ParameterizedItem *resolutionFunctionItem = m_detectorItem->getSubItems()[TestDetectorItem::P_RESOLUTION_FUNCTION]; +// m_resolutionFunctionEditor->addItemProperties(resolutionFunctionItem, QString("Resolution function"), AwesomePropertyEditor::INSERT_AFTER); - } else { - throw GUIHelpers::Error("DetectorEditorWidget::updateWidgets() -> Unknown detector item"); - } - - m_block_signals = false; -} + m_resolutionFunctionEditor->addItemProperty(subDetector, PhiAlphaDetectorItem::P_RESOLUTION_FUNCTION, "Resolution function", AwesomePropertyEditor::INSERT_AFTER); - - -void DetectorEditorWidget::onPropertyChanged(const QString &name) -{ - qDebug() << "DetectorEditorWidget::onPropertyChanged() -> " << name; - updateWidgets(); } -void DetectorEditorWidget::onDetectorTypeChanged(int) -{ - qDebug() << "DetectorEditorWidget::onDetectorTypeChanged() -> "; - if(m_block_signals) return; - m_currentItem->setGroupProperty(Constants::DetectorGroup, m_detectorTypeCombo->currentText()); -} - - -void DetectorEditorWidget::onAngleUnitsChanged(int) -{ - if(m_block_signals) return; - qDebug() << "DetectorEditorWidget::onAngleUnitsChanged()" << m_currentItem; - ParameterizedItem *subDetector = m_currentItem->getSubItems()[DetectorItem::P_DETECTOR]; - - - AngleProperty units = subDetector->getRegisteredProperty(PhiAlphaDetectorItem::P_AXES_UNITS).value<AngleProperty>(); - units.setUnits(m_unitsCombo->currentText()); - subDetector->setRegisteredProperty(PhiAlphaDetectorItem::P_AXES_UNITS, units.getVariant()); - updateWidgets(); - -} - - -void DetectorEditorWidget::onBinningTypeChanged(int) -{ - qDebug() << "DetectorEditorWidget::onBinningTypeChanged() -> " << m_block_signals; - if(m_block_signals) return; - - ParameterizedItem *subDetector = m_currentItem->getSubItems()[DetectorItem::P_DETECTOR]; - - ComboProperty combo_property = subDetector->getRegisteredProperty(PhiAlphaDetectorItem::P_BINNING).value<ComboProperty>(); - combo_property.setValue(m_binningTypeCombo->currentText()); - subDetector->setRegisteredProperty(PhiAlphaDetectorItem::P_BINNING, combo_property.getVariant()); -} - - - - -void DetectorEditorWidget::onAngleEditorChanged(const QString &) -{ - qDebug() << "DetectorEditorWidget::onAngleEditorChanged() ->"; - if(m_block_signals) return; - qDebug() << "DetectorEditorWidget::onAngleEditorChanged()"; - ParameterizedItem *subDetector = m_currentItem->getSubItems()[DetectorItem::P_DETECTOR]; - Q_ASSERT(subDetector); - Q_ASSERT(subDetector->modelType() == Constants::PhiAlphaDetectorType); - subDetector->setRegisteredProperty(PhiAlphaDetectorItem::P_NPHI, m_nphiEdit->value()); - - AngleProperty phi_min_property = subDetector->getRegisteredProperty(PhiAlphaDetectorItem::P_PHI_MIN).value<AngleProperty>(); - phi_min_property.setValue(m_phiMinEdit->value()); - subDetector->setRegisteredProperty(PhiAlphaDetectorItem::P_PHI_MIN, phi_min_property.getVariant()); - - AngleProperty phi_max_property = subDetector->getRegisteredProperty(PhiAlphaDetectorItem::P_PHI_MAX).value<AngleProperty>(); - phi_max_property.setValue(m_phiMaxEdit->value()); - subDetector->setRegisteredProperty(PhiAlphaDetectorItem::P_PHI_MAX, phi_max_property.getVariant()); - - subDetector->setRegisteredProperty(PhiAlphaDetectorItem::P_NALPHA, m_nalphaEdit->value()); - - AngleProperty alpha_min_property = subDetector->getRegisteredProperty(PhiAlphaDetectorItem::P_ALPHA_MIN).value<AngleProperty>(); - alpha_min_property.setValue(m_alphaMinEdit->value()); - subDetector->setRegisteredProperty(PhiAlphaDetectorItem::P_ALPHA_MIN, alpha_min_property.getVariant()); - - AngleProperty alpha_max_property = subDetector->getRegisteredProperty(PhiAlphaDetectorItem::P_ALPHA_MAX).value<AngleProperty>(); - alpha_max_property.setValue(m_alphaMaxEdit->value()); - subDetector->setRegisteredProperty(PhiAlphaDetectorItem::P_ALPHA_MAX, alpha_max_property.getVariant()); - -} - - -void DetectorEditorWidget::setAngleUnits(QDoubleSpinBox *editor, const AngleProperty &units, double min_deg, double max_deg) -{ - if(units.inDegrees()) { - editor->setSingleStep(0.01); - editor->setMinimum(min_deg); - editor->setMaximum(max_deg); - editor->setDecimals(3); - editor->setValue(units.getValue()); - } - else { - editor->setSingleStep(0.0001); - editor->setMinimum(Units::deg2rad(min_deg)); - editor->setMaximum(Units::deg2rad(max_deg)); - editor->setDecimals(6); - editor->setValue(units.getValue()); - } -} diff --git a/GUI/coregui/Views/InstrumentWidgets/DetectorEditorWidget.h b/GUI/coregui/Views/InstrumentWidgets/DetectorEditorWidget.h index 157c27335af938dd116e785c228d37ca1cd3971f..7b1a1cb729fba65ff2256ddb8b494bb52f016596 100644 --- a/GUI/coregui/Views/InstrumentWidgets/DetectorEditorWidget.h +++ b/GUI/coregui/Views/InstrumentWidgets/DetectorEditorWidget.h @@ -13,55 +13,29 @@ // // ************************************************************************** // -#ifndef DETECTOR_EDITOR_WIDGET_H -#define DETECTOR_EDITOR_WIDGET_H +#ifndef DETECTOREDITORWIDGET_H +#define DETECTOREDITORWIDGET_H #include "WinDllMacros.h" #include <QWidget> -class QComboBox; -class QLabel; -class ParameterizedItem; -class QSpinBox; -class QDoubleSpinBox; -class AngleProperty; +class DetectorItem; +class AwesomePropertyEditor; class BA_CORE_API_ DetectorEditorWidget : public QWidget { Q_OBJECT - public: DetectorEditorWidget(QWidget *parent = 0); - void initFromItem(ParameterizedItem *item); - -public slots: - void onPropertyChanged(const QString &); - void onDetectorTypeChanged(int); - void onAngleUnitsChanged(int); - void onBinningTypeChanged(int); - void onAngleEditorChanged(const QString &); + void setDetectorItem(DetectorItem *detectorItem); private: - void updateWidgets(); - void setAngleUnits(QDoubleSpinBox *editor, const AngleProperty &units, double min_deg = -90.0, double max_deg = 90.0); - - QComboBox *m_detectorTypeCombo; - QComboBox *m_unitsCombo; - QComboBox *m_binningTypeCombo; - - QLabel *m_axis0Label; - QLabel *m_axis1Label; - - QDoubleSpinBox *m_phiMinEdit; - QDoubleSpinBox *m_phiMaxEdit; - QSpinBox *m_nphiEdit; - QDoubleSpinBox *m_alphaMinEdit; - QDoubleSpinBox *m_alphaMaxEdit; - QSpinBox *m_nalphaEdit; - - ParameterizedItem *m_currentItem; - bool m_block_signals; + AwesomePropertyEditor *m_binningEditor; + AwesomePropertyEditor *m_phiAxisEditor; + AwesomePropertyEditor *m_alphaAxisEditor; + AwesomePropertyEditor *m_resolutionFunctionEditor; + DetectorItem *m_detectorItem; }; #endif diff --git a/GUI/coregui/Views/InstrumentWidgets/InstrumentComponentsWidget.cpp b/GUI/coregui/Views/InstrumentWidgets/InstrumentComponentsWidget.cpp new file mode 100644 index 0000000000000000000000000000000000000000..a713a53950a824c89f74f760e33d801f6185eaa2 --- /dev/null +++ b/GUI/coregui/Views/InstrumentWidgets/InstrumentComponentsWidget.cpp @@ -0,0 +1,46 @@ +// ************************************************************************** // +// +// BornAgain: simulate and fit scattering at grazing incidence +// +//! @file coregui/Views/InstrumentWidgets/InstrumentComponentsWidget.cpp +//! @brief Implements class InstrumentComponentsWidget +//! +//! @homepage http://www.bornagainproject.org +//! @license GNU General Public License v3 or higher (see COPYING) +//! @copyright Forschungszentrum Jülich GmbH 2015 +//! @authors Scientific Computing Group at MLZ Garching +//! @authors C. Durniak, M. Ganeva, G. Pospelov, W. Van Herck, J. Wuttke +// +// ************************************************************************** // + +#include "InstrumentComponentsWidget.h" +#include "BeamEditorWidget.h" +#include "DetectorEditorWidget.h" +#include <QVBoxLayout> +#include <QDebug> + +InstrumentComponentsWidget::InstrumentComponentsWidget(QWidget *parent) + : QWidget(parent) + , m_beamEditor(new BeamEditorWidget) + , m_detectorEditor(new DetectorEditorWidget) + , m_beamItem(0) + , m_detectorItem(0) +{ + QVBoxLayout *mainLayout = new QVBoxLayout(this); + mainLayout->addWidget(m_beamEditor); + mainLayout->addWidget(m_detectorEditor); + mainLayout->addStretch(); +} + +void InstrumentComponentsWidget::setBeamItem(BeamItem *beamItem) +{ + m_beamItem = beamItem; + m_beamEditor->setBeamItem(beamItem); +} + +void InstrumentComponentsWidget::setDetectorItem(DetectorItem *detectorItem) +{ + m_detectorItem = detectorItem; + m_detectorEditor->setDetectorItem(detectorItem); + +} diff --git a/GUI/coregui/Views/InstrumentWidgets/InstrumentComponentsWidget.h b/GUI/coregui/Views/InstrumentWidgets/InstrumentComponentsWidget.h new file mode 100644 index 0000000000000000000000000000000000000000..d385d5420f6ea83c0da187f0e11c1a9c754b4565 --- /dev/null +++ b/GUI/coregui/Views/InstrumentWidgets/InstrumentComponentsWidget.h @@ -0,0 +1,43 @@ +// ************************************************************************** // +// +// BornAgain: simulate and fit scattering at grazing incidence +// +//! @file coregui/Views/InstrumentWidgets/InstrumentComponentsWidget.h +//! @brief Defines class InstrumentComponentsWidget +//! +//! @homepage http://www.bornagainproject.org +//! @license GNU General Public License v3 or higher (see COPYING) +//! @copyright Forschungszentrum Jülich GmbH 2015 +//! @authors Scientific Computing Group at MLZ Garching +//! @authors C. Durniak, M. Ganeva, G. Pospelov, W. Van Herck, J. Wuttke +// +// ************************************************************************** // + +#ifndef INSTRUMENTCOMPONENTSWIDGET_H +#define INSTRUMENTCOMPONENTSWIDGET_H + +#include "WinDllMacros.h" +#include <QWidget> + +class BeamItem; +class DetectorItem; +class BeamEditorWidget; +class DetectorEditorWidget; + +class BA_CORE_API_ InstrumentComponentsWidget : public QWidget +{ + Q_OBJECT +public: + InstrumentComponentsWidget(QWidget *parent = 0); + + void setBeamItem(BeamItem *beamItem); + void setDetectorItem(DetectorItem *detectorItem); + +private: + BeamEditorWidget *m_beamEditor; + DetectorEditorWidget *m_detectorEditor; + BeamItem *m_beamItem; + DetectorItem *m_detectorItem; +}; + +#endif diff --git a/GUI/coregui/Views/InstrumentWidgets/InstrumentEditorWidget.cpp b/GUI/coregui/Views/InstrumentWidgets/InstrumentEditorWidget.cpp index 8e3bc90bf70d87700d882645ae7b80bc8f9e3c48..f94b12ddd5da9998864bfe462ae9b5bd416f6d24 100644 --- a/GUI/coregui/Views/InstrumentWidgets/InstrumentEditorWidget.cpp +++ b/GUI/coregui/Views/InstrumentWidgets/InstrumentEditorWidget.cpp @@ -19,30 +19,71 @@ #include "DetectorItems.h" #include "DetectorEditorWidget.h" #include "BeamEditorWidget.h" +#include "InstrumentComponentsWidget.h" +#include "InstrumentItem.h" #include <QBoxLayout> #include <QGroupBox> #include <QComboBox> #include <QLineEdit> +#include <QScrollArea> +#include <QScrollBar> +#include <QEvent> #include <QDebug> +class AdjustingScrollArea : public QScrollArea { + bool eventFilter(QObject * obj, QEvent * ev) { + if (obj == widget() && ev->type() != QEvent::Resize) { +// setMaximumWidth(width() - viewport()->width() + widget()->width()); + widget()->setMaximumWidth(viewport()->width()); + setMaximumHeight(height() - viewport()->height() + widget()->height()); + } + return QScrollArea::eventFilter(obj, ev); + } + + QSize sizeHint() const { + QScrollBar *horizontal = horizontalScrollBar(); + QSize result(viewport()->width(), widget()->height()+horizontal->height()*2); + return result; + } +public: + AdjustingScrollArea(QWidget * parent = 0) : QScrollArea(parent) + { + setObjectName("MyScrollArea"); + } + void setWidget(QWidget *w) { + QScrollArea::setWidget(w); + // It so happens that QScrollArea already filters widget events, + // but that's an implementation detail that we shouldn't rely on. + w->installEventFilter(this); + } +}; + + InstrumentEditorWidget::InstrumentEditorWidget(QWidget *parent) : QWidget(parent) , m_nameLineEdit(new QLineEdit()) , m_typeComboBox(new QComboBox()) - , m_beamWidget(new BeamEditorWidget(this)) - , m_detectorWidget(new DetectorEditorWidget(this)) , m_currentItem(0) , m_block_signals(false) + , m_instrumentComponents(new InstrumentComponentsWidget) { - setMinimumSize(400, 400); setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); + // main group box with all instrument parameters + QGroupBox *instrumentGroup = new QGroupBox(tr("Instrument Parameters")); + QVBoxLayout *instrumentGroupLayout = new QVBoxLayout; + instrumentGroupLayout->setContentsMargins(0,0,0,0); + instrumentGroup->setLayout(instrumentGroupLayout); + + // top block with instrument name and type m_typeComboBox->setMinimumWidth(300); m_typeComboBox->addItem("Default GISAS Instrument"); QHBoxLayout *topLayout = new QHBoxLayout; + topLayout->addSpacing(16); + QGridLayout *nameAndTypeLayout = new QGridLayout; nameAndTypeLayout->addWidget(new QLabel("Name"), 0, 0); nameAndTypeLayout->addWidget(m_nameLineEdit, 0, 1); @@ -51,24 +92,29 @@ InstrumentEditorWidget::InstrumentEditorWidget(QWidget *parent) topLayout->addLayout(nameAndTypeLayout ); topLayout->addStretch(1); - QGroupBox *instrumentGroup = new QGroupBox(tr("Instrument Parameters")); - QVBoxLayout *instrumentGroupLayout = new QVBoxLayout; + instrumentGroupLayout->addSpacing(10); instrumentGroupLayout->addLayout(topLayout); - instrumentGroupLayout->addWidget(m_beamWidget); - instrumentGroupLayout->addWidget(m_detectorWidget); - instrumentGroup->setLayout(instrumentGroupLayout); + // Scroling area with insturment components + m_instrumentComponents->setStyleSheet("InstrumentComponentsWidget {background-color:black;}"); + + AdjustingScrollArea *area = new AdjustingScrollArea; + area->setContentsMargins( 0, 0, 0, 0 ); + area->setWidgetResizable(true); + area->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); + area->setWidget(m_instrumentComponents); + area->setStyleSheet("QScrollArea#MyScrollArea {border: 0px; background-color:#D3D0CE;}"); + instrumentGroupLayout->addWidget(area, 1); + instrumentGroupLayout->addStretch(); + + // setting main layout QVBoxLayout *mainLayout = new QVBoxLayout; mainLayout->addWidget(instrumentGroup); - mainLayout->addStretch(); setLayout(mainLayout); connect(m_nameLineEdit, SIGNAL(textChanged(const QString &)), this, SLOT(onChangedEditor(const QString &))); } - - - void InstrumentEditorWidget::setInstrumentItem(ParameterizedItem *instrument) { Q_ASSERT(instrument); @@ -76,40 +122,23 @@ void InstrumentEditorWidget::setInstrumentItem(ParameterizedItem *instrument) if(instrument != m_currentItem) { if(m_currentItem) { disconnect(m_currentItem, SIGNAL(propertyChanged(QString)), this, SLOT(onPropertyChanged(QString))); - disconnect(m_currentItem, SIGNAL(propertyItemChanged(QString)), this, SLOT(onPropertyChanged(QString))); + disconnect(m_currentItem, SIGNAL(subItemChanged(QString)), this, SLOT(onPropertyChanged(QString))); } m_currentItem = instrument; connect(m_currentItem, SIGNAL(propertyChanged(QString)), this, SLOT(onPropertyChanged(QString))); - connect(m_currentItem, SIGNAL(propertyItemChanged(QString)), this, SLOT(onPropertyChanged(QString))); + connect(m_currentItem, SIGNAL(subItemChanged(QString)), this, SLOT(onPropertyChanged(QString))); updateWidgets(); } - BeamItem *beamItem(0); - DetectorItem *detectorItem(0); - - instrument->print(); + InstrumentItem *instrumentItem = dynamic_cast<InstrumentItem *>(instrument); - foreach(ParameterizedItem *item, instrument->childItems()) { - qDebug() << "XXX " << item->modelType(); - item->print(); - if(item->modelType() == Constants::BeamType) { - beamItem = dynamic_cast<BeamItem *>(item); - } - else if(item->modelType() == Constants::DetectorType) { - detectorItem = dynamic_cast<DetectorItem *>(item); - } - } - Q_ASSERT(beamItem); - Q_ASSERT(detectorItem); - - m_beamWidget->initFromItem(beamItem); - m_detectorWidget->initFromItem(detectorItem); + m_instrumentComponents->setBeamItem(instrumentItem->getBeamItem()); + m_instrumentComponents->setDetectorItem(instrumentItem->getDetectorItem()); } - void InstrumentEditorWidget::onChangedEditor(const QString &) { qDebug() << "InstrumentEditorWidget::onChangedEditor() ->"; @@ -123,7 +152,7 @@ void InstrumentEditorWidget::onChangedEditor(const QString &) void InstrumentEditorWidget::onPropertyChanged(const QString &) { qDebug() << "InstrumentEditorWidget::onPropertyChanged() ->"; - updateWidgets(); +// updateWidgets(); } diff --git a/GUI/coregui/Views/InstrumentWidgets/InstrumentEditorWidget.h b/GUI/coregui/Views/InstrumentWidgets/InstrumentEditorWidget.h index 2a29922efd17d20343f073466bcc65d6eec0f69c..f4bbecaf9ec350e760c1319567ebf0ad15f2227c 100644 --- a/GUI/coregui/Views/InstrumentWidgets/InstrumentEditorWidget.h +++ b/GUI/coregui/Views/InstrumentWidgets/InstrumentEditorWidget.h @@ -27,6 +27,7 @@ class DetectorEditorWidget; class BeamEditorWidget; class QLineEdit; class QComboBox; +class InstrumentComponentsWidget; class BA_CORE_API_ InstrumentEditorWidget : public QWidget { @@ -47,11 +48,9 @@ private: QLineEdit *m_nameLineEdit; QComboBox *m_typeComboBox; - BeamEditorWidget *m_beamWidget; - DetectorEditorWidget *m_detectorWidget; - ParameterizedItem *m_currentItem; bool m_block_signals; + InstrumentComponentsWidget *m_instrumentComponents; }; #endif diff --git a/GUI/coregui/Views/IntensityDataWidgets/ColorMapPlot.cpp b/GUI/coregui/Views/IntensityDataWidgets/ColorMapPlot.cpp index eeb0b3215fd7d28b4a8104a18e023f6acc25e44c..09b3c31d5d995910cdb8e27727381781c4b11c07 100644 --- a/GUI/coregui/Views/IntensityDataWidgets/ColorMapPlot.cpp +++ b/GUI/coregui/Views/IntensityDataWidgets/ColorMapPlot.cpp @@ -49,8 +49,8 @@ void ColorMapPlot::setItem(IntensityDataItem *item) if (m_item) { disconnect(m_item, SIGNAL(propertyChanged(QString)), this, SLOT(onPropertyChanged(QString))); - disconnect(m_item, SIGNAL(propertyItemPropertyChanged(QString,QString)), - this, SLOT(onPropertyItemPropertyChanged(QString,QString))); + disconnect(m_item, SIGNAL(subItemPropertyChanged(QString,QString)), + this, SLOT(onSubItemPropertyChanged(QString,QString))); } m_item = item; @@ -62,8 +62,8 @@ void ColorMapPlot::setItem(IntensityDataItem *item) connect(m_item, SIGNAL(propertyChanged(QString)), this, SLOT(onPropertyChanged(QString))); - connect(m_item, SIGNAL(propertyItemPropertyChanged(QString,QString)), - this, SLOT(onPropertyItemPropertyChanged(QString,QString))); + connect(m_item, SIGNAL(subItemPropertyChanged(QString,QString)), + this, SLOT(onSubItemPropertyChanged(QString,QString))); } @@ -247,11 +247,11 @@ void ColorMapPlot::onPropertyChanged(const QString &property_name) } } -void ColorMapPlot::onPropertyItemPropertyChanged(const QString &property_group, const QString &property_name) +void ColorMapPlot::onSubItemPropertyChanged(const QString &property_group, const QString &property_name) { if(m_block_update) return; - qDebug() << "ColorMapPlot::onPropertyItemChanged(const QString &property_name)" << property_group << property_name; + qDebug() << "ColorMapPlot::onSubItemPropertyChanged(const QString &property_name)" << property_group << property_name; if(property_group == IntensityDataItem::P_XAXIS) { if(property_name == BasicAxisItem::P_MIN) { QCPRange range = m_customPlot->xAxis->range(); diff --git a/GUI/coregui/Views/IntensityDataWidgets/ColorMapPlot.h b/GUI/coregui/Views/IntensityDataWidgets/ColorMapPlot.h index 5bb5b8324bd48cd9a1449c5afeea66a98ffed269..7eef1ac89cf63d388778761de557adb075972ec7 100644 --- a/GUI/coregui/Views/IntensityDataWidgets/ColorMapPlot.h +++ b/GUI/coregui/Views/IntensityDataWidgets/ColorMapPlot.h @@ -60,7 +60,7 @@ public slots: private slots: void onPropertyChanged(const QString &property_name); - void onPropertyItemPropertyChanged(const QString &property_group, const QString &property_name); + void onSubItemPropertyChanged(const QString &property_group, const QString &property_name); void onDataRangeChanged(QCPRange newRange); void onXaxisRangeChanged(QCPRange newRange); void onYaxisRangeChanged(QCPRange newRange); diff --git a/GUI/coregui/Views/IntensityDataWidgets/HorizontalSlicePlot.cpp b/GUI/coregui/Views/IntensityDataWidgets/HorizontalSlicePlot.cpp index 1f009c576536ab2c23341ee43fa2bf5e0f7ee870..f25bac378af20fcb7999bace864905f55db43ae8 100644 --- a/GUI/coregui/Views/IntensityDataWidgets/HorizontalSlicePlot.cpp +++ b/GUI/coregui/Views/IntensityDataWidgets/HorizontalSlicePlot.cpp @@ -45,8 +45,8 @@ void HorizontalSlicePlot::setItem(IntensityDataItem *item) if (m_item) { // disconnect(m_item, SIGNAL(propertyChanged(QString)), // this, SLOT(onPropertyChanged(QString))); - disconnect(m_item, SIGNAL(propertyItemPropertyChanged(QString,QString)), - this, SLOT(onPropertyItemPropertyChanged(QString,QString))); + disconnect(m_item, SIGNAL(subItemPropertyChanged(QString,QString)), + this, SLOT(onSubItemPropertyChanged(QString,QString))); } m_item = item; @@ -58,8 +58,8 @@ void HorizontalSlicePlot::setItem(IntensityDataItem *item) // connect(m_item, SIGNAL(propertyChanged(QString)), // this, SLOT(onPropertyChanged(QString))); - connect(m_item, SIGNAL(propertyItemPropertyChanged(QString,QString)), - this, SLOT(onPropertyItemPropertyChanged(QString,QString))); + connect(m_item, SIGNAL(subItemPropertyChanged(QString,QString)), + this, SLOT(onSubItemPropertyChanged(QString,QString))); } @@ -70,9 +70,9 @@ void HorizontalSlicePlot::plotData(const QVector<double> &x, const QVector<doubl m_customPlot->replot(); } -void HorizontalSlicePlot::onPropertyItemPropertyChanged(const QString &property_group, const QString &property_name) +void HorizontalSlicePlot::onSubItemPropertyChanged(const QString &property_group, const QString &property_name) { - qDebug() << "HorizontalSlicePlot::onPropertyItemChanged(const QString &property_name)" << property_group << property_name; + qDebug() << "HorizontalSlicePlot::onSubItemPropertyChanged(const QString &property_name)" << property_group << property_name; if(property_group == IntensityDataItem::P_XAXIS) { if(property_name == BasicAxisItem::P_MIN) { setXmin(m_item->getLowerX()); diff --git a/GUI/coregui/Views/IntensityDataWidgets/HorizontalSlicePlot.h b/GUI/coregui/Views/IntensityDataWidgets/HorizontalSlicePlot.h index 2832d1d49aa825b55518e67f0d2d52d4d567a0b8..04151b99a986ab278d094190e42391403077a810 100644 --- a/GUI/coregui/Views/IntensityDataWidgets/HorizontalSlicePlot.h +++ b/GUI/coregui/Views/IntensityDataWidgets/HorizontalSlicePlot.h @@ -40,7 +40,7 @@ public slots: private slots: // void onPropertyChanged(const QString &property_name); - void onPropertyItemPropertyChanged(const QString &property_group, const QString &property_name); + void onSubItemPropertyChanged(const QString &property_group, const QString &property_name); private: void plotItem(IntensityDataItem *intensityItem); diff --git a/GUI/coregui/Views/IntensityDataWidgets/IntensityDataPropertyWidget.cpp b/GUI/coregui/Views/IntensityDataWidgets/IntensityDataPropertyWidget.cpp index 885c3ce7c0595e865945938c093424824c20cfb3..c6fd7e310eeab52b5f274ef5894a416acf6854bd 100644 --- a/GUI/coregui/Views/IntensityDataWidgets/IntensityDataPropertyWidget.cpp +++ b/GUI/coregui/Views/IntensityDataWidgets/IntensityDataPropertyWidget.cpp @@ -14,7 +14,7 @@ // ************************************************************************** // #include "IntensityDataPropertyWidget.h" -#include "UniversalPropertyEditor.h" +#include "AwesomePropertyEditor.h" #include "JobModel.h" #include "IntensityDataItem.h" #include <QVBoxLayout> @@ -34,7 +34,7 @@ IntensityDataPropertyWidget::IntensityDataPropertyWidget(QWidget *parent) mainLayout->setMargin(0); mainLayout->setSpacing(0); - m_propertyEditor = new UniversalPropertyEditor(0, this); + m_propertyEditor = new AwesomePropertyEditor(this); //m_propertyEditor->setCreateGroupProperty(false); mainLayout->addWidget(m_propertyEditor); @@ -64,5 +64,5 @@ void IntensityDataPropertyWidget::setModel(JobModel *model) void IntensityDataPropertyWidget::setItem(IntensityDataItem *jobItem) { - m_propertyEditor->setItem(jobItem); + m_propertyEditor->setItem(jobItem, "Plot Properties"); } diff --git a/GUI/coregui/Views/IntensityDataWidgets/IntensityDataPropertyWidget.h b/GUI/coregui/Views/IntensityDataWidgets/IntensityDataPropertyWidget.h index 6e40d147029a125882011efe378ef08193a59262..fc8f08cbdbfce6764963b5437561efa2a3ec03e6 100644 --- a/GUI/coregui/Views/IntensityDataWidgets/IntensityDataPropertyWidget.h +++ b/GUI/coregui/Views/IntensityDataWidgets/IntensityDataPropertyWidget.h @@ -21,7 +21,7 @@ class JobModel; class IntensityDataItem; -class UniversalPropertyEditor; +class AwesomePropertyEditor; //! Widget to show and change properties of currently selected JobItem //! Left buttom corner of JobQueueView @@ -42,7 +42,7 @@ public slots: private: JobModel *m_jobModel; IntensityDataItem *m_currentItem; - UniversalPropertyEditor *m_propertyEditor; + AwesomePropertyEditor *m_propertyEditor; }; diff --git a/GUI/coregui/Views/IntensityDataWidgets/VerticalSlicePlot.cpp b/GUI/coregui/Views/IntensityDataWidgets/VerticalSlicePlot.cpp index 2bbf7abbc45c2ede90bd16157ab22e9010fe89ec..e29ba3cbe23f939262f9641034f3d583600417bb 100644 --- a/GUI/coregui/Views/IntensityDataWidgets/VerticalSlicePlot.cpp +++ b/GUI/coregui/Views/IntensityDataWidgets/VerticalSlicePlot.cpp @@ -45,8 +45,8 @@ void VerticalSlicePlot::setItem(IntensityDataItem *item) if (m_item) { // disconnect(m_item, SIGNAL(propertyChanged(QString)), // this, SLOT(onPropertyChanged(QString))); - disconnect(m_item, SIGNAL(propertyItemPropertyChanged(QString,QString)), - this, SLOT(onPropertyItemPropertyChanged(QString,QString))); + disconnect(m_item, SIGNAL(subItemPropertyChanged(QString,QString)), + this, SLOT(onSubItemPropertyChanged(QString,QString))); } m_item = item; @@ -58,8 +58,8 @@ void VerticalSlicePlot::setItem(IntensityDataItem *item) // connect(m_item, SIGNAL(propertyChanged(QString)), // this, SLOT(onPropertyChanged(QString))); - connect(m_item, SIGNAL(propertyItemPropertyChanged(QString,QString)), - this, SLOT(onPropertyItemPropertyChanged(QString,QString))); + connect(m_item, SIGNAL(subItemPropertyChanged(QString,QString)), + this, SLOT(onSubItemPropertyChanged(QString,QString))); } @@ -70,9 +70,9 @@ void VerticalSlicePlot::plotData(const QVector<double> &x, const QVector<double> m_customPlot->replot(); } -void VerticalSlicePlot::onPropertyItemPropertyChanged(const QString &property_group, const QString &property_name) +void VerticalSlicePlot::onSubItemPropertyChanged(const QString &property_group, const QString &property_name) { - qDebug() << "HorizontalSlicePlot::onPropertyItemChanged(const QString &property_name)" << property_group << property_name; + qDebug() << "HorizontalSlicePlot::onSubItemPropertyChanged(const QString &property_name)" << property_group << property_name; if(property_group == IntensityDataItem::P_XAXIS) { if(property_name == BasicAxisItem::P_MIN) { setXmin(m_item->getLowerX()); diff --git a/GUI/coregui/Views/IntensityDataWidgets/VerticalSlicePlot.h b/GUI/coregui/Views/IntensityDataWidgets/VerticalSlicePlot.h index 254826331c31889f1031f91b6c7b1036594200f3..4729fea799a63c9803051ddfc0987a4436e8e48d 100644 --- a/GUI/coregui/Views/IntensityDataWidgets/VerticalSlicePlot.h +++ b/GUI/coregui/Views/IntensityDataWidgets/VerticalSlicePlot.h @@ -39,7 +39,7 @@ public slots: private slots: // void onPropertyChanged(const QString &property_name); - void onPropertyItemPropertyChanged(const QString &property_group, const QString &property_name); + void onSubItemPropertyChanged(const QString &property_group, const QString &property_name); private: void plotItem(IntensityDataItem *intensityItem); diff --git a/GUI/coregui/Views/JobWidgets/JobPropertiesWidget.cpp b/GUI/coregui/Views/JobWidgets/JobPropertiesWidget.cpp index ee030ac631fb3a1cc28eed30e37be76518d50cea..1d177101f27cab91ae8ac77e132ee9f931809c7e 100644 --- a/GUI/coregui/Views/JobWidgets/JobPropertiesWidget.cpp +++ b/GUI/coregui/Views/JobWidgets/JobPropertiesWidget.cpp @@ -14,7 +14,7 @@ // ************************************************************************** // #include "JobPropertiesWidget.h" -#include "UniversalPropertyEditor.h" +#include "AwesomePropertyEditor.h" #include "JobModel.h" #include "JobItem.h" #include <QVBoxLayout> @@ -39,8 +39,8 @@ JobPropertiesWidget::JobPropertiesWidget(QWidget *parent) mainLayout->setMargin(0); mainLayout->setSpacing(0); - m_propertyEditor = new UniversalPropertyEditor(0, this); - m_propertyEditor->setCreateGroupProperty(false); + m_propertyEditor = new AwesomePropertyEditor(this); + //m_propertyEditor->setCreateGroupProperty(false); m_commentsEditor = new QTextEdit(); diff --git a/GUI/coregui/Views/JobWidgets/JobPropertiesWidget.h b/GUI/coregui/Views/JobWidgets/JobPropertiesWidget.h index b763e5d65046413711df81044c8104605b4f9ab8..9dc07023b1d471555a32810d5209802295132d2f 100644 --- a/GUI/coregui/Views/JobWidgets/JobPropertiesWidget.h +++ b/GUI/coregui/Views/JobWidgets/JobPropertiesWidget.h @@ -24,7 +24,7 @@ class JobModel; class JobItem; class QTextEdit; class QTabWidget; -class UniversalPropertyEditor; +class AwesomePropertyEditor; //! Widget to show and change properties of currently selected JobItem //! Left buttom corner of JobView @@ -47,7 +47,7 @@ private: JobModel *m_jobModel; JobItem *m_currentItem; QTabWidget *m_tabWidget; - UniversalPropertyEditor *m_propertyEditor; + AwesomePropertyEditor *m_propertyEditor; QTextEdit *m_commentsEditor; }; diff --git a/GUI/coregui/Views/JobWidgets/ModelTuningDelegate.cpp b/GUI/coregui/Views/JobWidgets/ModelTuningDelegate.cpp index 012f8042daa79c3c5db99375ca734d4376c6f9de..a559c24979eeb57f0b4d4d2b8134078c3bbc51f0 100644 --- a/GUI/coregui/Views/JobWidgets/ModelTuningDelegate.cpp +++ b/GUI/coregui/Views/JobWidgets/ModelTuningDelegate.cpp @@ -34,8 +34,9 @@ namespace { -const double maximum_doublespin_value(10000.0); -const double minimum_doublespin_value(10000.0); +//const double maximum_doublespin_value(1e+20); +const double maximum_doublespin_value(20000.0); +const double minimum_doublespin_value(0.0); } ModelTuningDelegate::SliderData::SliderData() @@ -95,31 +96,27 @@ void ModelTuningDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const { - if (index.column() == m_valueColumn) { - if(index.parent().isValid() == false) - return; + if(!index.parent().isValid()) return; QVariant prop_value = index.model()->data(index, Qt::EditRole); - int type = GUIHelpers::getVariantType(prop_value); - if (type == QVariant::Double) { - double value = prop_value.toDouble(); - QString text(QString::number(value)); - - QStyleOptionViewItem myOption = option; - myOption.displayAlignment = Qt::AlignLeft | Qt::AlignVCenter; - - - drawDisplay(painter, myOption, myOption.rect, text); - drawFocus(painter, myOption, myOption.rect); - } else { - return; + if(prop_value.isValid()) { + int type = GUIHelpers::getVariantType(prop_value); + if (type == QVariant::Double) { + double value = prop_value.toDouble(); + QString text(QString::number(value)); + + QStyleOptionViewItem myOption = option; + myOption.displayAlignment = Qt::AlignLeft | Qt::AlignVCenter; + + drawDisplay(painter, myOption, myOption.rect, text); + drawFocus(painter, myOption, myOption.rect); + return; + } } - - } else{ - QItemDelegate::paint(painter, option, index); } + QItemDelegate::paint(painter, option, index); } @@ -128,12 +125,7 @@ QWidget *ModelTuningDelegate::createEditor(QWidget *parent, const QModelIndex &index) const { if (index.column() == m_valueColumn) { - - - if(index.parent().isValid() == false) - { - return NULL; - } + if(index.parent().isValid() == false) return NULL; double value = index.model()->data(index, Qt::EditRole).toDouble(); diff --git a/GUI/coregui/Views/PropertyEditor/AwesomePropertyEditor.cpp b/GUI/coregui/Views/PropertyEditor/AwesomePropertyEditor.cpp new file mode 100644 index 0000000000000000000000000000000000000000..ff732d706a72e9ecb16d22b2d153984156e32cf5 --- /dev/null +++ b/GUI/coregui/Views/PropertyEditor/AwesomePropertyEditor.cpp @@ -0,0 +1,449 @@ +// ************************************************************************** // +// +// BornAgain: simulate and fit scattering at grazing incidence +// +//! @file coregui/Views/PropertyEditor/AwesomePropertyEditor.cpp +//! @brief Implements class AwesomePropertyEditor +//! +//! @homepage http://www.bornagainproject.org +//! @license GNU General Public License v3 or higher (see COPYING) +//! @copyright Forschungszentrum Jülich GmbH 2015 +//! @authors Scientific Computing Group at MLZ Garching +//! @authors C. Durniak, M. Ganeva, G. Pospelov, W. Van Herck, J. Wuttke +// +// ************************************************************************** // + +#include "AwesomePropertyEditor.h" +#include "PropertyVariantManager.h" +#include "PropertyVariantFactory.h" +#include "ParameterizedItem.h" +#include "tooltipdatabase.h" +#include "GUIHelpers.h" +#include "qttreepropertybrowser.h" +#include "qtgroupboxpropertybrowser.h" +#include "qtbuttonpropertybrowser.h" +#include <QtProperty> +#include <QMetaProperty> +#include <QDebug> +#include <QVBoxLayout> +#include <cmath> + + +class AwesomePropertyEditorPrivate +{ +public: + struct ItemPropertyPair { + ItemPropertyPair(ParameterizedItem *item=0, QString property_name = QString()) + : m_item(item), m_name(property_name) {} + ParameterizedItem *m_item; + QString m_name; + friend bool operator <(const ItemPropertyPair& left, const ItemPropertyPair& right) + { + if(left.m_item == right.m_item) + return left.m_name < right.m_name; + return left.m_item < right.m_item; + } + friend bool operator == (const ItemPropertyPair& left, const ItemPropertyPair& right) + { + return (left.m_item == right.m_item) && (left.m_name < right.m_name); + } + void clear() { m_name.clear(); m_item = 0; } + }; + + AwesomePropertyEditorPrivate(QWidget *parent, AwesomePropertyEditor::EBrowserType browser_type); + QtAbstractPropertyBrowser *m_browser; + QtVariantPropertyManager *m_manager; + QtVariantPropertyManager *m_read_only_manager; + AwesomePropertyEditor::EBrowserType m_browser_type; + QMap<QtProperty *, ItemPropertyPair> m_qtproperty_to_itempropertypair; + QMap<ParameterizedItem *, QMap<QString, QtVariantProperty *> > m_item_to_property_to_qtvariant; + QMap<QString, QtVariantProperty *> m_groupname_to_qtvariant; + QMap<QtVariantProperty *, QList<QtVariantProperty *> > m_qtvariant_to_dependend; + QMap<ParameterizedItem *, QMap<QString, AwesomePropertyEditor::EInsertMode > > m_item_subitem_insert_mode; + ItemPropertyPair m_current_item_property_pair; +}; + +AwesomePropertyEditorPrivate::AwesomePropertyEditorPrivate(QWidget *parent, AwesomePropertyEditor::EBrowserType browser_type) + : m_browser(0) + , m_manager(0) + , m_read_only_manager(0) + , m_browser_type(browser_type) +{ + if(m_browser_type == AwesomePropertyEditor::BROWSER_TREE_TYPE) { + QtTreePropertyBrowser *browser = new QtTreePropertyBrowser(parent); + browser->setResizeMode(QtTreePropertyBrowser::Interactive); + browser->setRootIsDecorated(false); + m_browser = browser; + } + else if(m_browser_type == AwesomePropertyEditor::BROWSER_GROUPBOX_TYPE) { + m_browser = new QtGroupBoxPropertyBrowser(parent); + } + else if(m_browser_type == AwesomePropertyEditor::BROWSER_BUTTON_TYPE) { + m_browser = new QtButtonPropertyBrowser(parent); + } + else { + throw GUIHelpers::Error("UniversalPropertyEditor::UniversalPropertyEditor() -> Error. Unknown browser type."); + } + m_read_only_manager = new PropertyVariantManager(parent); + + m_manager = new PropertyVariantManager(parent); + QtVariantEditorFactory *factory = new PropertyVariantFactory(); + m_browser->setFactoryForManager(m_manager, factory); + +} + + +AwesomePropertyEditor::AwesomePropertyEditor(QWidget *parent, EBrowserType browser_type) + : QWidget(parent) + , m_d(new AwesomePropertyEditorPrivate(this, browser_type)) +{ + setWindowTitle(QLatin1String("Property Editor")); + setObjectName(QLatin1String("AwesomePropertyEditor")); + + m_d->m_browser->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); + + QVBoxLayout *layout = new QVBoxLayout(this); + layout->setMargin(0); + layout->addWidget(m_d->m_browser); + + connect(m_d->m_manager, SIGNAL(valueChanged(QtProperty *, const QVariant &)), + this, SLOT(slotValueChanged(QtProperty *, const QVariant &))); +} + +AwesomePropertyEditor::~AwesomePropertyEditor() +{ + delete m_d; +} + +void AwesomePropertyEditor::setItem(ParameterizedItem *item, const QString &group_name) +{ + qDebug() << "AwesomePropertyEditor::setItem(ParameterizedItem *item)"; + clearEditor(); + if(item) addItemProperties(item, group_name); +} + +//! adds given ParameterizedItem's property to the group +void AwesomePropertyEditor::addItemProperty(ParameterizedItem *item, const QString &property_name, const QString &group_name, AwesomePropertyEditor::EInsertMode subitem_insert_policy) +{ + Q_ASSERT(item); + qDebug() << " AwesomePropertyEditor::addItemProperty() " << item << property_name << group_name << subitem_insert_policy; + QtVariantProperty *groupVariantProperty(0); + if(!group_name.isEmpty()) { + if(m_d->m_groupname_to_qtvariant.contains(group_name)) { + groupVariantProperty = m_d->m_groupname_to_qtvariant[group_name]; + } else { + groupVariantProperty = m_d->m_manager->addProperty(QtVariantPropertyManager::groupTypeId(), group_name); + m_d->m_groupname_to_qtvariant[group_name] = groupVariantProperty; + m_d->m_browser->addProperty(groupVariantProperty); + } + } + insertItemProperty(item, property_name, groupVariantProperty, INSERT_AS_CHILD, subitem_insert_policy); +} + +//! adds all ParameterizedItem properties to the group +void AwesomePropertyEditor::addItemProperties(ParameterizedItem *item, const QString &group_name, AwesomePropertyEditor::EInsertMode subitem_insert_policy) +{ + Q_ASSERT(item); + qDebug() << "AwesomePropertyEditor::addItemProperties() group_name:" << group_name; + QtVariantProperty *groupVariantProperty(0); + if(!group_name.isEmpty()) { + if(m_d->m_groupname_to_qtvariant.contains(group_name)) { + groupVariantProperty = m_d->m_groupname_to_qtvariant[group_name]; + qDebug() << "AwesomePropertyEditor::addItemProperties() 1.1"; + } else { + groupVariantProperty = m_d->m_manager->addProperty(QtVariantPropertyManager::groupTypeId(), group_name); + m_d->m_groupname_to_qtvariant[group_name] = groupVariantProperty; + m_d->m_browser->addProperty(groupVariantProperty); + qDebug() << "AwesomePropertyEditor::addItemProperties() 1.2" << groupVariantProperty; + } + } + insertItemProperties(item, groupVariantProperty, INSERT_AS_CHILD, subitem_insert_policy); +} + +//! clears the editor from all properties and connections +void AwesomePropertyEditor::clearEditor() +{ + qDebug() << "AwesomePropertyEditor::clearEditor()"; + disconnect(m_d->m_manager, SIGNAL(valueChanged(QtProperty *, const QVariant &)), + this, SLOT(slotValueChanged(QtProperty *, const QVariant &))); + disconnect(); + + m_d->m_browser->clear(); + + QMap<QtProperty *, AwesomePropertyEditorPrivate::ItemPropertyPair>::iterator it = m_d->m_qtproperty_to_itempropertypair.begin(); + while(it!=m_d->m_qtproperty_to_itempropertypair.end()) { + delete it.key(); + it++; + } + + m_d->m_qtproperty_to_itempropertypair.clear(); + m_d->m_item_to_property_to_qtvariant.clear(); + m_d->m_groupname_to_qtvariant.clear(); + m_d->m_qtvariant_to_dependend.clear(); + m_d->m_item_subitem_insert_mode.clear(); + + connect(m_d->m_manager, SIGNAL(valueChanged(QtProperty *, const QVariant &)), + this, SLOT(slotValueChanged(QtProperty *, const QVariant &))); + +} + +//! updates corresponding property of ParameterizedItem on editor change +void AwesomePropertyEditor::slotValueChanged(QtProperty *property, + const QVariant &value) +{ + qDebug() << "AwesomePropertyEditor::slotValueChanged() BROWSER_ID:" << m_d->m_browser_type << "property:" << property->propertyName() << "value:" << value; + + if (!m_d->m_qtproperty_to_itempropertypair.contains(property)) { + qDebug() << " AwesomePropertyEditor::slotValueChanged() -> No such property"; + return; + } + + + AwesomePropertyEditorPrivate::ItemPropertyPair itemPropertyPair = m_d->m_qtproperty_to_itempropertypair[property]; + qDebug() << " AwesomePropertyEditor::slotValueChanged()-> itemPropertyPair" << itemPropertyPair.m_item << itemPropertyPair.m_name; + + +// disconnect(itemPropertyPair.m_item, SIGNAL(propertyChanged(QString)), +// this, SLOT(onPropertyChanged(QString))); + + // FIXME Find more elegant solution + m_d->m_current_item_property_pair = itemPropertyPair; + itemPropertyPair.m_item->setProperty(itemPropertyPair.m_name.toUtf8().data(), value); + m_d->m_current_item_property_pair.clear(); + +// connect(itemPropertyPair.m_item, SIGNAL(propertyChanged(QString)), +// this, SLOT(onPropertyChanged(QString))); + +} + +//! updates editors on ParameterizedItem's propertyChanged +void AwesomePropertyEditor::onPropertyChanged(const QString &property_name) +{ + ParameterizedItem *item = qobject_cast<ParameterizedItem *>(sender()); + qDebug() << "AwesomePropertyEditor::onPropertyChanged(const QString &property_name) BROWSER_ID:" << m_d->m_browser_type << "item->modelType(), property_name" << item->modelType() << property_name; + + QtVariantProperty *variant_property = m_d->m_item_to_property_to_qtvariant[item][property_name]; + if(variant_property) { + QVariant property_value = item->property(property_name.toUtf8().data()); + + disconnect(item, SIGNAL(propertyChanged(QString)), + this, SLOT(onPropertyChanged(QString))); + disconnect(item, SIGNAL(subItemChanged(QString)), + this, SLOT(onSubItemChanged(QString))); + + qDebug() << " AwesomePropertyEditor::onPropertyChanged(const QString &property_name) -> Setting variant_property"; + variant_property->setValue(property_value); + PropertyAttribute prop_attribute = item->getPropertyAttribute(property_name); + if(prop_attribute.getAppearance() & PropertyAttribute::DISABLED) { + variant_property->setEnabled(false); + } else { + variant_property->setEnabled(true); + } + + + connect(item, SIGNAL(propertyChanged(QString)), + this, SLOT(onPropertyChanged(QString)), Qt::UniqueConnection); + connect(item, SIGNAL(subItemChanged(QString)), + this, SLOT(onSubItemChanged(QString)), Qt::UniqueConnection); + + } +} + +void AwesomePropertyEditor::onSubItemChanged(const QString &property_name) +{ + ParameterizedItem *item = qobject_cast<ParameterizedItem *>(sender()); + qDebug() << "AwesomePropertyEditor::onSubItemChanged(const QString &property_name) BROWSER_ID:" << m_d->m_browser_type << "item->modelType(), property_name" << item->modelType() << property_name; + + if(m_d->m_current_item_property_pair.m_item == item && m_d->m_current_item_property_pair.m_name == property_name) { + return; + } + + QtVariantProperty *variant_property = m_d->m_item_to_property_to_qtvariant[item][property_name]; + if(variant_property) { + QVariant property_value = item->property(property_name.toUtf8().data()); + + disconnect(item, SIGNAL(propertyChanged(QString)), + this, SLOT(onPropertyChanged(QString))); + disconnect(item, SIGNAL(subItemChanged(QString)), + this, SLOT(onSubItemChanged(QString))); + + variant_property->setValue(property_value); + PropertyAttribute prop_attribute = item->getPropertyAttribute(property_name); + if(prop_attribute.getAppearance() & PropertyAttribute::DISABLED) { + variant_property->setEnabled(false); + } else { + variant_property->setEnabled(true); + } + + removeQtVariantProperties(m_d->m_qtvariant_to_dependend[variant_property]); + + insertItemProperties( item->getSubItems()[property_name], variant_property, m_d->m_item_subitem_insert_mode[item][property_name]); + + + connect(item, SIGNAL(propertyChanged(QString)), + this, SLOT(onPropertyChanged(QString))); + connect(item, SIGNAL(subItemChanged(QString)), + this, SLOT(onSubItemChanged(QString))); + } +} + +//! Inserts all properties of given ParameterizedItem +void AwesomePropertyEditor::insertItemProperties(ParameterizedItem *item, QtVariantProperty *parent_qtproperty, EInsertMode insert_mode, EInsertMode subitem_insert_mode) +{ + Q_ASSERT(item); + qDebug() << "AwesomePropertyEditor::insertItemProperties() item" << item << "parent_qtproperty" << parent_qtproperty << insert_mode << subitem_insert_mode; + QList<QByteArray> property_names = item->dynamicPropertyNames(); + for (int i = 0; i < property_names.length(); ++i) { + QString prop_name = QString(property_names[i]); + insertItemProperty(item, prop_name, parent_qtproperty, insert_mode, subitem_insert_mode); + } + +} + +//! Creates QtVariantProperty for given ParameterizedItem property name, inserts it into proper place, creates all signals, fills correspondance maps +void AwesomePropertyEditor::insertItemProperty(ParameterizedItem *item, const QString &property_name, QtVariantProperty *parent_qtproperty, EInsertMode insert_mode, EInsertMode subitem_insert_mode) +{ + Q_ASSERT(item); + qDebug() << "AwesomePropertyEditor::insertItemProperty()" << item << property_name << parent_qtproperty << insert_mode << subitem_insert_mode; + if(insert_mode == SKIP) return; + + QtVariantProperty *qtVariantItem = createQtVariantProperty(item, property_name); + qDebug() << " AwesomePropertyEditor::insertItemProperty(): qtVariantItem" << qtVariantItem; + if(!qtVariantItem) return; + + insertQtVariantProperty(qtVariantItem, parent_qtproperty, insert_mode); + + // Processing SubProperty + if(subitem_insert_mode != SKIP && item->getSubItems().contains(property_name)) { + ParameterizedItem *subitem = item->getSubItems()[property_name]; + if (subitem) { + insertItemProperties(subitem, qtVariantItem, subitem_insert_mode, subitem_insert_mode); + } + } + + // registering given property + AwesomePropertyEditorPrivate::ItemPropertyPair itemPropertyPair(item, property_name); + m_d->m_qtproperty_to_itempropertypair[qtVariantItem] = itemPropertyPair; + m_d->m_item_to_property_to_qtvariant[item][property_name] = qtVariantItem; + + m_d->m_qtvariant_to_dependend[parent_qtproperty].append(qtVariantItem); + m_d->m_item_subitem_insert_mode[item][property_name] = subitem_insert_mode; + + connect(item, SIGNAL(propertyChanged(QString)), + this, SLOT(onPropertyChanged(QString)), Qt::UniqueConnection); + connect(item, SIGNAL(subItemChanged(QString)), + this, SLOT(onSubItemChanged(QString)), Qt::UniqueConnection); +} + +//! creates QtVariantProperty for given ParameterizedItem's property +QtVariantProperty *AwesomePropertyEditor::createQtVariantProperty(ParameterizedItem *item, const QString &property_name) +{ + qDebug() << " "; + qDebug() << "QtVariantProperty *AwesomePropertyEditor::createQtVariantProperty(ParameterizedItem *item, const QString &property_name) item" << item << property_name; + QtVariantProperty *result(0); + + PropertyAttribute prop_attribute = item->getPropertyAttribute(property_name); + if(prop_attribute.getAppearance() & PropertyAttribute::HIDDEN) return 0; + + QVariant prop_value = item->property(property_name.toUtf8().data()); + Q_ASSERT(prop_value.isValid()); + int type = GUIHelpers::getVariantType(prop_value); + + QtVariantPropertyManager *manager = m_d->m_manager; + if(prop_attribute.getAppearance() & PropertyAttribute::READONLY) manager = m_d->m_read_only_manager; + + if(!manager->isPropertyTypeSupported(type)) { + throw GUIHelpers::Error("AwesomePropertyEditor::createQtVariantProperty() -> Error. Not supported property type "+property_name); + } + + if(prop_attribute.getLabel().isEmpty()) { + result = manager->addProperty(type, property_name); + } else { + result = manager->addProperty(type, prop_attribute.getLabel()); + } + + if(type == QVariant::Double) { + //result->setAttribute(QLatin1String("decimals"), prop_attribute.getDecimals()); + AttLimits limits = prop_attribute.getLimits(); + if(limits.hasLowerLimit()) result->setAttribute(QLatin1String("minimum"), limits.getLowerLimit()); + if(limits.hasUpperLimit()) result->setAttribute(QLatin1String("maximum"), limits.getUpperLimit()); + result->setAttribute(QLatin1String("decimals"), prop_attribute.getDecimals()); + result->setAttribute(QLatin1String("singleStep"), 1./std::pow(10.,prop_attribute.getDecimals()-1)); + } + else if(type == QVariant::Int) { + AttLimits limits = prop_attribute.getLimits(); + if(limits.hasLowerLimit()) result->setAttribute(QLatin1String("minimum"), int(limits.getLowerLimit())); + if(limits.hasUpperLimit()) result->setAttribute(QLatin1String("maximum"), int(limits.getUpperLimit())); + } + + QString toolTip = ToolTipDataBase::getSampleViewToolTip(item->modelType(), property_name); + if(!toolTip.isEmpty()) result->setToolTip(toolTip); + + if(prop_attribute.getAppearance() & PropertyAttribute::DISABLED) { + result->setEnabled(false); + } + + result->setValue(prop_value); + + qDebug() << " QtVariantProperty *AwesomePropertyEditor::createQtVariantProperty(ParameterizedItem *item, const QString &property_name) result" << result; + + return result; +} + +//! inserts QtVariantProperty in proper place of the browser +void AwesomePropertyEditor::insertQtVariantProperty(QtVariantProperty *qtVariantItem, QtVariantProperty *parent_qtproperty, AwesomePropertyEditor::EInsertMode insert_mode) +{ + qDebug() << "AwesomePropertyEditor::insertQtVariantProperty qtVariantItem:" << qtVariantItem << " parent_property" << parent_qtproperty << insert_mode; + + if(parent_qtproperty) { + if(insert_mode == INSERT_AS_CHILD) { + parent_qtproperty->addSubProperty(qtVariantItem); + qDebug() << " AwesomePropertyEditor::insertQtVariantProperty() -> adding " << qtVariantItem << " as subproperty of" << parent_qtproperty; + } + else if(insert_mode == INSERT_AFTER) { + if(m_d->m_browser->items(parent_qtproperty).size() == 1) { + // inserting qtVariantItem after parent property, so we need to know parent of parent + QtProperty *new_parent = m_d->m_browser->items(parent_qtproperty).at(0)->parent()->property(); + //new_parent->insertSubProperty(qtVariantItem, parent_qtproperty); + //new_parent->insertSubProperty(qtVariantItem, new_parent->subProperties().back()); + if(m_d->m_qtvariant_to_dependend[parent_qtproperty].size()) { + if(!new_parent->subProperties().contains(m_d->m_qtvariant_to_dependend[parent_qtproperty].back())) throw 1; + new_parent->insertSubProperty(qtVariantItem, m_d->m_qtvariant_to_dependend[parent_qtproperty].back()); + } else { +// new_parent->insertSubProperty(qtVariantItem, new_parent->subProperties().back()); + new_parent->insertSubProperty(qtVariantItem, parent_qtproperty); + } + } else { + // our parent property is already at the top, so need to add into the browser + QtBrowserItem *browserItem = m_d->m_browser->insertProperty(qtVariantItem, parent_qtproperty); + if(!browserItem) { + throw GUIHelpers::Error("AwesomePropertyEditor::insertQtVariantProperty() -> Failed while inserting property"); + } + } + } + else { + throw GUIHelpers::Error("AwesomePropertyEditor::insertQtVariantProperty() -> Error. Unknown insert mode"); + } + } else { + m_d->m_browser->addProperty(qtVariantItem); + } +} + +//! removes list of QtVariantProperties from the browser and from all maps +void AwesomePropertyEditor::removeQtVariantProperties(QList<QtVariantProperty *> &list_of_properties) +{ + qDebug() << "AwesomePropertyEditor::removeQtVarintProperties(QList<QtVariantProperty> &list_of_properties)"; + + foreach(QtVariantProperty *child, list_of_properties) { + m_d->m_browser->removeProperty(child); + delete child; + QMap<QtProperty *, AwesomePropertyEditorPrivate::ItemPropertyPair >::iterator it = m_d->m_qtproperty_to_itempropertypair.find(child); + if(it != m_d->m_qtproperty_to_itempropertypair.end()) { + AwesomePropertyEditorPrivate::ItemPropertyPair itemPair = it.value(); + m_d->m_item_to_property_to_qtvariant.remove(itemPair.m_item); + m_d->m_qtproperty_to_itempropertypair.erase(it); + } + } + + list_of_properties.clear(); +} diff --git a/GUI/coregui/Views/PropertyEditor/AwesomePropertyEditor.h b/GUI/coregui/Views/PropertyEditor/AwesomePropertyEditor.h new file mode 100644 index 0000000000000000000000000000000000000000..12195f4c996009a3651936d7d37b487fe079ee8c --- /dev/null +++ b/GUI/coregui/Views/PropertyEditor/AwesomePropertyEditor.h @@ -0,0 +1,71 @@ +// ************************************************************************** // +// +// BornAgain: simulate and fit scattering at grazing incidence +// +//! @file coregui/Views/PropertyEditor/AwesomePropertyEditor.h +//! @brief Defines class AwesomePropertyEditor +//! +//! @homepage http://www.bornagainproject.org +//! @license GNU General Public License v3 or higher (see COPYING) +//! @copyright Forschungszentrum Jülich GmbH 2015 +//! @authors Scientific Computing Group at MLZ Garching +//! @authors C. Durniak, M. Ganeva, G. Pospelov, W. Van Herck, J. Wuttke +// +// ************************************************************************** // + +#ifndef AWESOMEPROPERTYEDITOR_H +#define AWESOMEPROPERTYEDITOR_H + +#include "WinDllMacros.h" +#include <QWidget> + +class ParameterizedItem; +class AwesomePropertyEditorPrivate; +class ParameterizedIytem; +class QtProperty; +class QtVariantProperty; + +//! property editor to display and modify properties of multiple ParameterizedItem +class BA_CORE_API_ AwesomePropertyEditor : public QWidget +{ + Q_OBJECT + +public: + enum EBrowserType { + BROWSER_TREE_TYPE, + BROWSER_GROUPBOX_TYPE, + BROWSER_BUTTON_TYPE + }; + + enum EInsertMode { + INSERT_AS_CHILD, //! child will be inserted as child to form tree structure + INSERT_AFTER, //! child will be inserted on the same level as parent right after him + SKIP + }; + + AwesomePropertyEditor(QWidget *parent = 0, EBrowserType browser_type = BROWSER_TREE_TYPE); + virtual ~AwesomePropertyEditor(); + + void setItem(ParameterizedItem *item, const QString &group_name = QString()); + void addItemProperty(ParameterizedItem *item, const QString &property_name, const QString &group_name=QString(), EInsertMode subitem_insert_policy = INSERT_AS_CHILD); + void addItemProperties(ParameterizedItem *item, const QString &group_name=QString(), EInsertMode subitem_insert_policy = INSERT_AS_CHILD); + + void clearEditor(); + +private slots: + void slotValueChanged(QtProperty *property, const QVariant &value); + void onPropertyChanged(const QString &property_name); + void onSubItemChanged(const QString &property_name); + +private: + void insertItemProperties(ParameterizedItem *item, QtVariantProperty *parent_qtproperty=0, EInsertMode insert_mode = INSERT_AFTER, EInsertMode subitem_insert_mode = INSERT_AS_CHILD); + void insertItemProperty(ParameterizedItem *item, const QString &property_name, QtVariantProperty *parent_qtproperty=0, EInsertMode insert_mode = INSERT_AFTER, EInsertMode subitem_insert_mode = INSERT_AS_CHILD); + QtVariantProperty *createQtVariantProperty(ParameterizedItem *item, const QString &property_name); + void insertQtVariantProperty(QtVariantProperty *qtVariantItem, QtVariantProperty *parent_qtproperty, EInsertMode insert_mode); + void removeQtVariantProperties(QList<QtVariantProperty *> &list_of_properties); + + AwesomePropertyEditorPrivate *m_d; +}; + + +#endif // SAMPLEPROPERTYEDITOR_H diff --git a/GUI/coregui/Views/SampleDesigner/PropertyBrowserUtils.cpp b/GUI/coregui/Views/PropertyEditor/PropertyBrowserUtils.cpp similarity index 75% rename from GUI/coregui/Views/SampleDesigner/PropertyBrowserUtils.cpp rename to GUI/coregui/Views/PropertyEditor/PropertyBrowserUtils.cpp index 74d474eb345ea013e169362fc7709d40a4f74815..d9a83e0e39cd8cdfb9968e418fafa072eac7f81c 100644 --- a/GUI/coregui/Views/SampleDesigner/PropertyBrowserUtils.cpp +++ b/GUI/coregui/Views/PropertyEditor/PropertyBrowserUtils.cpp @@ -2,7 +2,7 @@ // // BornAgain: simulate and fit scattering at grazing incidence // -//! @file coregui/Views/SampleDesigner/PropertyBrowserUtils.cpp +//! @file coregui/Views/PropertyEditor/PropertyBrowserUtils.cpp //! @brief Implements class PropertyBrowserUtils //! //! @homepage http://www.bornagainproject.org @@ -85,15 +85,32 @@ void MaterialPropertyEdit::setMaterialProperty( // ----------------------------------------------------------------------------- FancyGroupPropertyEdit::FancyGroupPropertyEdit(QWidget *parent) : QWidget(parent) - , m_box(0) - , m_label(0) + , m_box(new QComboBox()) + , m_label(new QLabel()) , m_groupProperty(0) { + setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); + + QVBoxLayout *layout = new QVBoxLayout(); + layout->setMargin(0); + layout->setSpacing(0); + layout->addWidget(m_box); + layout->addWidget(m_label); + // setLayout(layout); + m_label->hide(); +// update(); +// setFocusPolicy(Qt::StrongFocus); +// setAttribute(Qt::WA_InputMethodEnabled); + + connect(m_box, SIGNAL(currentIndexChanged(int)), + this, SLOT(indexChanged(int))); + + setLayout(layout); } FancyGroupPropertyEdit::~FancyGroupPropertyEdit() { - qDebug() << "FancyGroupPropertyEdit::~FancyGroupPropertyEditor() -> destroyed"; + qDebug() << "FancyGroupPropertyEdit::~FancyGroupPropertyEditor() -> destroyed" << this; } @@ -121,19 +138,28 @@ void FancyGroupPropertyEdit::setFancyGroupProperty( void FancyGroupPropertyEdit::processFixedGroup() { qDebug() << "FancyGroupPropertyEdit::processFixedGroup()" << m_groupProperty->getValueLabel(); - if(!m_label) m_label = new QLabel(this); +// if(!m_label) m_label = new QLabel(this); + m_box->hide(); + m_label->show(); m_label->setText(m_groupProperty->getValueLabel()); } void FancyGroupPropertyEdit::processSelectableGroup() { - if(!m_box) m_box = new QComboBox(this); + qDebug() << "FancyGroupPropertyEdit::processSelectableGroup()"; +// if(!m_box) m_box = new QComboBox(this); +// m_label->hide(); +// m_box->show(); disconnect(m_box, SIGNAL(currentIndexChanged(int)), this, SLOT(indexChanged(int))); - if(!m_box->count()) m_box->insertItems(0, m_groupProperty->getValueLabels()); + if(m_box->count() != m_groupProperty->getValueLabels().size()) { + m_box->clear(); + qDebug() << "XXX inserting_items" << m_groupProperty->getValueLabels(); + m_box->insertItems(0, m_groupProperty->getValueLabels()); + } m_box->setCurrentIndex(m_groupProperty->index()); connect(m_box, SIGNAL(currentIndexChanged(int)), @@ -146,7 +172,8 @@ void FancyGroupPropertyEdit::indexChanged(int index) { qDebug() << "FancyGroupPropertyEdit::textChanged() -> " << index; m_groupProperty->setValue(m_groupProperty->toString(index)); - emit fancyGroupPropertyChanged(m_groupProperty); +// emit fancyGroupPropertyChanged(m_groupProperty); +// update(); } @@ -158,7 +185,7 @@ QSize FancyGroupPropertyEdit::sizeHint() const if(m_label) { return m_label->sizeHint(); } - return QSize(10,10); + return QSize(100,10); } QSize FancyGroupPropertyEdit::minimumSizeHint() const @@ -169,7 +196,7 @@ QSize FancyGroupPropertyEdit::minimumSizeHint() const if(m_label) { return m_label->minimumSizeHint(); } - return QSize(10,10); + return QSize(100,10); } @@ -242,7 +269,14 @@ QString ColorPropertyEdit::colorValueText(const QColor &c) ScientificDoublePropertyEdit::ScientificDoublePropertyEdit(QWidget *parent) : QWidget(parent) { + setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); + + QVBoxLayout *layout = new QVBoxLayout(); + layout->setMargin(0); + layout->setSpacing(0); + m_lineEdit = new QLineEdit(this); + layout->addWidget(m_lineEdit); m_validator = new QDoubleValidator(0.0, 1e+100, 1000, this); m_validator->setNotation(QDoubleValidator::ScientificNotation); @@ -250,6 +284,8 @@ ScientificDoublePropertyEdit::ScientificDoublePropertyEdit(QWidget *parent) connect(m_lineEdit, SIGNAL(editingFinished()), this, SLOT(onEditingFinished())); + + setLayout(layout); } void ScientificDoublePropertyEdit::setScientificDoubleProperty( @@ -283,27 +319,45 @@ QSize ScientificDoublePropertyEdit::minimumSizeHint() const // ComboPropertyEdit // ----------------------------------------------------------------------------- +//ComboPropertyEdit::ComboPropertyEdit(QWidget *parent) +// : QWidget(parent) +// , m_comboBox(0) +//{ +// m_comboBox->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); +//} + ComboPropertyEdit::ComboPropertyEdit(QWidget *parent) - : QWidget(parent) - , m_comboBox(0) + : QComboBox(parent) { } +//ComboPropertyEdit::~ComboPropertyEdit() +//{ +// qDebug() << "ComboPropertyEdit::~ComboPropertyEdit()" << this; +//} + void ComboPropertyEdit::setComboProperty( const ComboProperty &combo_property) { + qDebug() << "ComboPropertyEdit::setComboProperty() this=" << this; m_combo_property = combo_property; - if (!m_comboBox) m_comboBox = new QComboBox(this); +// if (!m_comboBox) { +// m_comboBox = new QComboBox(this); +// } - disconnect(m_comboBox, SIGNAL(currentIndexChanged(QString)), + disconnect(this, SIGNAL(currentIndexChanged(QString)), this, SLOT(onCurrentIndexChanged(QString))); - m_comboBox->clear(); - QStringList value_list = m_combo_property.getValues(); - m_comboBox->addItems(value_list); - m_comboBox->setCurrentText(comboValueText()); +// m_comboBox->clear(); + if(count() !=m_combo_property.getValues().size()) { + clear(); + QStringList value_list = m_combo_property.getValues(); - connect(m_comboBox, SIGNAL(currentIndexChanged(QString)), + addItems(value_list); + } + setCurrentText(comboValueText()); + + connect(this, SIGNAL(currentIndexChanged(QString)), this, SLOT(onCurrentIndexChanged(QString))); } @@ -312,9 +366,24 @@ QString ComboPropertyEdit::comboValueText() return m_combo_property.getValue(); } +//QSize ComboPropertyEdit::sizeHint() const +//{ +// Q_ASSERT(m_comboBox); +// return m_comboBox->sizeHint(); + +//} + +//QSize ComboPropertyEdit::minimumSizeHint() const +//{ +// Q_ASSERT(m_comboBox); +// return m_comboBox->minimumSizeHint(); +//} + void ComboPropertyEdit::onCurrentIndexChanged(QString current_value) { + qDebug() << "ComboPropertyEdit::onCurrentIndexChanged(QString current_value)" << current_value; m_combo_property.setValue(current_value); + qDebug() << " ComboPropertyEdit::onCurrentIndexChanged(QString current_value) -> emitting combo property"; emit comboPropertyChanged(m_combo_property); } diff --git a/GUI/coregui/Views/SampleDesigner/PropertyBrowserUtils.h b/GUI/coregui/Views/PropertyEditor/PropertyBrowserUtils.h similarity index 92% rename from GUI/coregui/Views/SampleDesigner/PropertyBrowserUtils.h rename to GUI/coregui/Views/PropertyEditor/PropertyBrowserUtils.h index f28e9cb0671a0f4840fafa486539f9124a9d2388..1bb8dea4f9c4be3017e5c8b83be80d606c35cd3b 100644 --- a/GUI/coregui/Views/SampleDesigner/PropertyBrowserUtils.h +++ b/GUI/coregui/Views/PropertyEditor/PropertyBrowserUtils.h @@ -2,7 +2,7 @@ // // BornAgain: simulate and fit scattering at grazing incidence // -//! @file coregui/Views/SampleDesigner/PropertyBrowserUtils.h +//! @file coregui/Views/PropertyEditor/PropertyBrowserUtils.h //! @brief Defines class PropertyBrowserUtils //! //! @homepage http://www.bornagainproject.org @@ -129,27 +129,33 @@ private: ScientificDoubleProperty m_scientificDoubleProperty; }; - +#include <QComboBox> //! The ComboPropertyEdit class provides PropertyVariantFactory with editing //! widget for ComboProperty -class BA_CORE_API_ ComboPropertyEdit : public QWidget +//class BA_CORE_API_ ComboPropertyEdit : public QWidget +class BA_CORE_API_ ComboPropertyEdit : public QComboBox { Q_OBJECT public: ComboPropertyEdit(QWidget *parent = 0); +// ~ComboPropertyEdit(); void setComboProperty(const ComboProperty &combo_property); ComboProperty getComboProperty() const {return m_combo_property; } QString comboValueText(); +// QSize sizeHint() const; +// QSize minimumSizeHint() const; + + signals: void comboPropertyChanged(const ComboProperty &combo_property); private slots: void onCurrentIndexChanged(QString current_value); private: - QComboBox *m_comboBox; +// QComboBox *m_comboBox; ComboProperty m_combo_property; }; diff --git a/GUI/coregui/Views/SampleDesigner/PropertyVariantFactory.cpp b/GUI/coregui/Views/PropertyEditor/PropertyVariantFactory.cpp similarity index 93% rename from GUI/coregui/Views/SampleDesigner/PropertyVariantFactory.cpp rename to GUI/coregui/Views/PropertyEditor/PropertyVariantFactory.cpp index 10a188d1e748a8a41e54b7c9632473418e60d37f..5f7bcce4122fbe3185878e9a6d43086589a264f5 100644 --- a/GUI/coregui/Views/SampleDesigner/PropertyVariantFactory.cpp +++ b/GUI/coregui/Views/PropertyEditor/PropertyVariantFactory.cpp @@ -2,7 +2,7 @@ // // BornAgain: simulate and fit scattering at grazing incidence // -//! @file coregui/Views/SampleDesigner/PropertyVariantFactory.cpp +//! @file coregui/Views/PropertyEditor/PropertyVariantFactory.cpp //! @brief Implements class PropertyVariantFactory //! //! @homepage http://www.bornagainproject.org @@ -21,6 +21,7 @@ PropertyVariantFactory::~PropertyVariantFactory() { + qDebug() << "PropertyVariantFactory::~PropertyVariantFactory()"; QList<MaterialPropertyEdit *> mat_editors = m_material_editor_to_property.keys(); QListIterator<MaterialPropertyEdit *> mat_it(mat_editors); @@ -69,6 +70,7 @@ void PropertyVariantFactory::connectPropertyManager( QWidget *PropertyVariantFactory::createEditor(QtVariantPropertyManager *manager, QtProperty *property, QWidget *parent) { + qDebug() << "PropertyVariantFactory::createEditor()" << property->propertyName(); if (manager->propertyType(property) == PropertyVariantManager::materialTypeId()) { MaterialPropertyEdit *editor = new MaterialPropertyEdit(parent); @@ -143,6 +145,8 @@ QWidget *PropertyVariantFactory::createEditor(QtVariantPropertyManager *manager, if (manager->propertyType(property) == PropertyVariantManager::comboPropertyTypeId()) { ComboPropertyEdit *editor = new ComboPropertyEdit(parent); + qDebug() << " PropertyVariantFactory::createEditor() -> created ComboEditor" << editor; + QVariant var = manager->value(property); ComboProperty combo = var.value<ComboProperty>(); editor->setComboProperty(combo); @@ -177,6 +181,7 @@ void PropertyVariantFactory::disconnectPropertyManager( void PropertyVariantFactory::slotPropertyChanged(QtProperty *property, const QVariant &value) { + qDebug() << "PropertyVariantFactory::slotPropertyChanged()" << property->propertyName() << value; if (m_property_to_material_editors.contains(property)) { QList<MaterialPropertyEdit *> editors = m_property_to_material_editors[property]; @@ -210,6 +215,7 @@ void PropertyVariantFactory::slotPropertyChanged(QtProperty *property, QListIterator<FancyGroupPropertyEdit *> itEditor(editors); while (itEditor.hasNext()) { FancyGroupProperty_t mat = value.value<FancyGroupProperty_t>(); + qDebug() << " PropertyVariantFactory::slotPropertyChanged() -> Setting editor"; itEditor.next()->setFancyGroupProperty(mat); } } @@ -218,6 +224,7 @@ void PropertyVariantFactory::slotPropertyChanged(QtProperty *property, m_property_to_combo_editors[property]; QListIterator<ComboPropertyEdit *> itEditor(editors); while (itEditor.hasNext()) { + qDebug() << " PropertyVariantFactory::slotPropertyChanged() -> Setting editor"; ComboProperty combo = value.value<ComboProperty>(); itEditor.next()->setComboProperty(combo); } @@ -240,7 +247,7 @@ void PropertyVariantFactory::slotSetValue(const MaterialProperty &value) var.setValue(value); manager->setValue(property, var); // FIXME g.p. Is it the right place to delete? - object->deleteLater(); + //object->deleteLater(); return; } itEditor++; @@ -261,7 +268,7 @@ void PropertyVariantFactory::slotSetValue(const ColorProperty &value) var.setValue(value); manager->setValue(property, var); // FIXME g.p. Is it the right place to delete? - object->deleteLater(); + //object->deleteLater(); return; } itEditor++; @@ -289,6 +296,7 @@ void PropertyVariantFactory::slotSetValue(const ScientificDoubleProperty &value) void PropertyVariantFactory::slotSetValue(const FancyGroupProperty_t &value) { + qDebug() << "PropertyVariantFactory::slotSetValue(const FancyGroupProperty_t &value)"; QObject *object = sender(); QMap<FancyGroupPropertyEdit *, QtProperty *>::ConstIterator itEditor = m_fancygroup_editor_to_property.constBegin(); @@ -308,6 +316,7 @@ void PropertyVariantFactory::slotSetValue(const FancyGroupProperty_t &value) void PropertyVariantFactory::slotSetValue(const ComboProperty &value) { + qDebug() << "PropertyVariantFactory::slotSetValue(const ComboProperty &value)"; QObject *object = sender(); QMap<ComboPropertyEdit *, QtProperty *>::ConstIterator itEditor = m_combo_editor_to_property.constBegin(); @@ -320,7 +329,7 @@ void PropertyVariantFactory::slotSetValue(const ComboProperty &value) var.setValue(value); manager->setValue(property, var); // FIXME g.p. Is it the right place to delete? - object->deleteLater(); + //object->deleteLater(); return; } itEditor++; @@ -329,6 +338,7 @@ void PropertyVariantFactory::slotSetValue(const ComboProperty &value) void PropertyVariantFactory::slotEditorDestroyed(QObject *object) { + qDebug() << "PropertyVariantFactory::slotEditorDestroyed(QObject *object)"; QMap<MaterialPropertyEdit *, QtProperty *>::ConstIterator mat_it_editor = m_material_editor_to_property.constBegin(); while (mat_it_editor != m_material_editor_to_property.constEnd()) { @@ -378,6 +388,8 @@ void PropertyVariantFactory::slotEditorDestroyed(QObject *object) m_fancygroup_editor_to_property.constBegin(); while (fancygroup_editor_it != m_fancygroup_editor_to_property.constEnd()) { if (fancygroup_editor_it.key() == object) { + qDebug() << "PropertyVariantFactory::slotEditorDestroyed(QObject *object) -> fancy group editor"; + FancyGroupPropertyEdit *editor = fancygroup_editor_it.key(); QtProperty *property = fancygroup_editor_it.value(); m_fancygroup_editor_to_property.remove(editor); @@ -407,6 +419,7 @@ void PropertyVariantFactory::slotEditorDestroyed(QObject *object) void PropertyVariantFactory::slotPropertyAttributeChanged(QtProperty *, const QString &, const QVariant &) { +// qDebug() << "PropertyVariantFactory::slotPropertyAttributeChanged(QtProperty *, const QString &, const QVariant &) -> ???"; } diff --git a/GUI/coregui/Views/SampleDesigner/PropertyVariantFactory.h b/GUI/coregui/Views/PropertyEditor/PropertyVariantFactory.h similarity index 98% rename from GUI/coregui/Views/SampleDesigner/PropertyVariantFactory.h rename to GUI/coregui/Views/PropertyEditor/PropertyVariantFactory.h index 5d4e47ebd13128cb7150dd0089a916fbb4dc0862..0a9a4ae63d7c2a760ce90bd9a1e5b777eebf35da 100644 --- a/GUI/coregui/Views/SampleDesigner/PropertyVariantFactory.h +++ b/GUI/coregui/Views/PropertyEditor/PropertyVariantFactory.h @@ -2,7 +2,7 @@ // // BornAgain: simulate and fit scattering at grazing incidence // -//! @file coregui/Views/SampleDesigner/PropertyVariantFactory.h +//! @file coregui/Views/PropertyEditor/PropertyVariantFactory.h //! @brief Defines class PropertyVariantFactory //! //! @homepage http://www.bornagainproject.org diff --git a/GUI/coregui/Views/SampleDesigner/PropertyVariantManager.cpp b/GUI/coregui/Views/PropertyEditor/PropertyVariantManager.cpp similarity index 96% rename from GUI/coregui/Views/SampleDesigner/PropertyVariantManager.cpp rename to GUI/coregui/Views/PropertyEditor/PropertyVariantManager.cpp index d66f4781859cfd1e09db17c46d695c501f14a0f5..3345e09d58b88148bdaed19962b4ca5198e9c146 100644 --- a/GUI/coregui/Views/SampleDesigner/PropertyVariantManager.cpp +++ b/GUI/coregui/Views/PropertyEditor/PropertyVariantManager.cpp @@ -2,7 +2,7 @@ // // BornAgain: simulate and fit scattering at grazing incidence // -//! @file coregui/Views/SampleDesigner/PropertyVariantManager.cpp +//! @file coregui/Views/PropertyEditor/PropertyVariantManager.cpp //! @brief Implements class PropertyVariantManager //! //! @homepage http://www.bornagainproject.org @@ -16,7 +16,7 @@ #include "PropertyVariantManager.h" #include "DesignerHelper.h" #include "ParameterizedItem.h" - +#include <QDebug> PropertyVariantManager::PropertyVariantManager(QObject *parent) : QtVariantPropertyManager(parent) @@ -154,6 +154,7 @@ QIcon PropertyVariantManager::valueIcon(const QtProperty *property) const void PropertyVariantManager::setValue(QtProperty *property, const QVariant &val) { + qDebug() << "PropertyVariantManager::setValue(QtProperty *property, const QVariant &val)"; if (m_theMaterialValues.contains(property)) { if( val.userType() != materialTypeId() ) return; MaterialProperty mat = val.value<MaterialProperty>(); @@ -211,6 +212,7 @@ void PropertyVariantManager::setValue(QtProperty *property, const QVariant &val) void PropertyVariantManager::initializeProperty(QtProperty *property) { + qDebug() << "PropertyVariantManager::initializeProperty(QtProperty *property)"; if (propertyType(property) == materialTypeId()) { MaterialProperty m; m_theMaterialValues[property] = m; diff --git a/GUI/coregui/Views/SampleDesigner/PropertyVariantManager.h b/GUI/coregui/Views/PropertyEditor/PropertyVariantManager.h similarity index 97% rename from GUI/coregui/Views/SampleDesigner/PropertyVariantManager.h rename to GUI/coregui/Views/PropertyEditor/PropertyVariantManager.h index ba19281aefcf5db7349fc59176ff41cb8689796d..186ca21e659fafc0929753298d921821e0b471ab 100644 --- a/GUI/coregui/Views/SampleDesigner/PropertyVariantManager.h +++ b/GUI/coregui/Views/PropertyEditor/PropertyVariantManager.h @@ -2,7 +2,7 @@ // // BornAgain: simulate and fit scattering at grazing incidence // -//! @file coregui/Views/SampleDesigner/PropertyVariantManager.h +//! @file coregui/Views/PropertyEditor/PropertyVariantManager.h //! @brief Defines class PropertyVariantManager //! //! @homepage http://www.bornagainproject.org diff --git a/GUI/coregui/Views/JobWidgets/UniversalPropertyEditor.cpp b/GUI/coregui/Views/PropertyEditor/UniversalPropertyEditor.cpp similarity index 79% rename from GUI/coregui/Views/JobWidgets/UniversalPropertyEditor.cpp rename to GUI/coregui/Views/PropertyEditor/UniversalPropertyEditor.cpp index b7d1a5608ba3afe6441d864a4dac2340405eda26..704843be7698541a706a77d2588fc1919eda434c 100644 --- a/GUI/coregui/Views/JobWidgets/UniversalPropertyEditor.cpp +++ b/GUI/coregui/Views/PropertyEditor/UniversalPropertyEditor.cpp @@ -2,7 +2,7 @@ // // BornAgain: simulate and fit scattering at grazing incidence // -//! @file coregui/Views/JobWidgets/UniversalPropertyEditor.cpp +//! @file coregui/Views/PropertyEditor/UniversalPropertyEditor.cpp //! @brief Implements class UniversalPropertyEditor //! //! @homepage http://www.bornagainproject.org @@ -30,23 +30,34 @@ #include <cmath> UniversalPropertyEditor::UniversalPropertyEditor(QItemSelectionModel *selection_model, - QWidget *parent) + QWidget *parent, EBrowserType browser_type) : QWidget(parent) , m_item(0) , m_selection_model(0) + , m_browser(0) , m_create_group_property(true) + , m_browser_type(browser_type) { setSelectionModel(selection_model); setWindowTitle(QLatin1String("Property Editor")); setObjectName(QLatin1String("PropertyEditor")); -// QtAbstractPropertyBrowser *browser = new QtGroupBoxPropertyBrowser(); -// QtAbstractPropertyBrowser *browser = new QtButtonPropertyBrowser(); + if(m_browser_type == BROWSER_TREE_TYPE) { + QtTreePropertyBrowser *browser = new QtTreePropertyBrowser(this); + browser->setRootIsDecorated(false); + m_browser = browser; + } + else if(m_browser_type == BROWSER_GROUPBOX_TYPE) { + m_browser = new QtGroupBoxPropertyBrowser(); + } + else if(m_browser_type == BROWSER_BUTTON_TYPE) { + m_browser = new QtButtonPropertyBrowser(); + } + else { + throw GUIHelpers::Error("UniversalPropertyEditor::UniversalPropertyEditor() -> Error. Unknown browser type."); + } - QtTreePropertyBrowser *browser = new QtTreePropertyBrowser(this); - browser->setRootIsDecorated(false); - m_browser = browser; QVBoxLayout *layout = new QVBoxLayout(this); layout->setMargin(0); layout->addWidget(m_browser); @@ -141,22 +152,22 @@ void UniversalPropertyEditor::updateSubItems(const QString &name) if (!m_item) return; - clearEditor(); - disconnect(m_item, SIGNAL(propertyChanged(QString)), this, SLOT(onPropertyChanged(QString))); - disconnect(m_item, SIGNAL(propertyItemChanged(QString)), + disconnect(m_item, SIGNAL(subItemChanged(QString)), this, SLOT(updateSubItems(QString))); - disconnect(m_item, SIGNAL(propertyItemPropertyChanged(QString,QString)), - this, SLOT(onPropertyItemPropertyChanged(QString,QString))); + disconnect(m_item, SIGNAL(subItemPropertyChanged(QString,QString)), + this, SLOT(onSubItemPropertyChanged(QString,QString))); + + clearEditor(); addItemProperties(m_item); - connect(m_item, SIGNAL(propertyItemChanged(QString)), + connect(m_item, SIGNAL(subItemChanged(QString)), this, SLOT(updateSubItems(QString))); connect(m_item, SIGNAL(propertyChanged(QString)), this, SLOT(onPropertyChanged(QString))); - connect(m_item, SIGNAL(propertyItemPropertyChanged(QString,QString)), - this, SLOT(onPropertyItemPropertyChanged(QString,QString))); + connect(m_item, SIGNAL(subItemPropertyChanged(QString,QString)), + this, SLOT(onSubItemPropertyChanged(QString,QString))); } void UniversalPropertyEditor::onPropertyChanged(const QString &property_name) @@ -170,10 +181,10 @@ void UniversalPropertyEditor::onPropertyChanged(const QString &property_name) disconnect(m_item, SIGNAL(propertyChanged(QString)), this, SLOT(onPropertyChanged(QString))); - disconnect(m_item, SIGNAL(propertyItemChanged(QString)), + disconnect(m_item, SIGNAL(subItemChanged(QString)), this, SLOT(updateSubItems(QString))); - disconnect(m_item, SIGNAL(propertyItemPropertyChanged(QString,QString)), - this, SLOT(onPropertyItemPropertyChanged(QString,QString))); + disconnect(m_item, SIGNAL(subItemPropertyChanged(QString,QString)), + this, SLOT(onSubItemPropertyChanged(QString,QString))); variant_property->setValue(property_value); @@ -186,45 +197,44 @@ void UniversalPropertyEditor::onPropertyChanged(const QString &property_name) connect(m_item, SIGNAL(propertyChanged(QString)), this, SLOT(onPropertyChanged(QString))); - connect(m_item, SIGNAL(propertyItemChanged(QString)), + connect(m_item, SIGNAL(subItemChanged(QString)), this, SLOT(updateSubItems(QString))); - connect(m_item, SIGNAL(propertyItemPropertyChanged(QString,QString)), - this, SLOT(onPropertyItemPropertyChanged(QString,QString))); + connect(m_item, SIGNAL(subItemPropertyChanged(QString,QString)), + this, SLOT(onSubItemPropertyChanged(QString,QString))); } } -void UniversalPropertyEditor::onPropertyItemPropertyChanged(const QString &property_group, const QString &property_name) +void UniversalPropertyEditor::onSubItemPropertyChanged(const QString &property_group, const QString &property_name) { - qDebug() << "UniversalPropertyEditor::onPropertyItemPropertyChanged" << property_group << property_name; + qDebug() << "UniversalPropertyEditor::onSubItemPropertyChanged" << property_group << property_name; ParameterizedItem *subItem = m_item->getSubItems()[property_group]; if(subItem){ - qDebug() << "XXX "; QtVariantProperty *variant_property = m_item_to_propertyname_to_qtvariantproperty[subItem][property_name]; if(variant_property) { QVariant property_value = subItem->getRegisteredProperty(property_name); disconnect(m_item, SIGNAL(propertyChanged(QString)), this, SLOT(onPropertyChanged(QString))); - disconnect(m_item, SIGNAL(propertyItemChanged(QString)), + disconnect(m_item, SIGNAL(subItemChanged(QString)), this, SLOT(updateSubItems(QString))); - disconnect(m_item, SIGNAL(propertyItemPropertyChanged(QString,QString)), - this, SLOT(onPropertyItemPropertyChanged(QString,QString))); + disconnect(m_item, SIGNAL(subItemPropertyChanged(QString,QString)), + this, SLOT(onSubItemPropertyChanged(QString,QString))); variant_property->setValue(property_value); -// PropertyAttribute prop_attribute = m_item->getPropertyAttribute(property_name); -// if(prop_attribute.getAppearance() & PropertyAttribute::DISABLED) { -// variant_property->setEnabled(false); -// } else { -// variant_property->setEnabled(true); -// } + PropertyAttribute prop_attribute = subItem->getPropertyAttribute(property_name); + if(prop_attribute.getAppearance() & PropertyAttribute::DISABLED) { + variant_property->setEnabled(false); + } else { + variant_property->setEnabled(true); + } connect(m_item, SIGNAL(propertyChanged(QString)), this, SLOT(onPropertyChanged(QString))); - connect(m_item, SIGNAL(propertyItemChanged(QString)), + connect(m_item, SIGNAL(subItemChanged(QString)), this, SLOT(updateSubItems(QString))); - connect(m_item, SIGNAL(propertyItemPropertyChanged(QString,QString)), - this, SLOT(onPropertyItemPropertyChanged(QString,QString))); + connect(m_item, SIGNAL(subItemPropertyChanged(QString,QString)), + this, SLOT(onSubItemPropertyChanged(QString,QString))); } @@ -239,14 +249,15 @@ void UniversalPropertyEditor::setItem(ParameterizedItem *item) if (m_item == item) return; if (m_item) { - clearEditor(); - - disconnect(m_item, SIGNAL(propertyItemChanged(QString)), + disconnect(m_item, SIGNAL(subItemChanged(QString)), this, SLOT(updateSubItems(QString))); disconnect(m_item, SIGNAL(propertyChanged(QString)), this, SLOT(onPropertyChanged(QString))); - disconnect(m_item, SIGNAL(propertyItemPropertyChanged(QString,QString)), - this, SLOT(onPropertyItemPropertyChanged(QString,QString))); + disconnect(m_item, SIGNAL(subItemPropertyChanged(QString,QString)), + this, SLOT(onSubItemPropertyChanged(QString,QString))); + + clearEditor(); + } m_item = item; @@ -254,12 +265,12 @@ void UniversalPropertyEditor::setItem(ParameterizedItem *item) if (!m_item) return; addItemProperties(m_item); - connect(m_item, SIGNAL(propertyItemChanged(QString)), + connect(m_item, SIGNAL(subItemChanged(QString)), this, SLOT(updateSubItems(QString))); connect(m_item, SIGNAL(propertyChanged(QString)), this, SLOT(onPropertyChanged(QString))); - connect(m_item, SIGNAL(propertyItemPropertyChanged(QString,QString)), - this, SLOT(onPropertyItemPropertyChanged(QString,QString))); + connect(m_item, SIGNAL(subItemPropertyChanged(QString,QString)), + this, SLOT(onSubItemPropertyChanged(QString,QString))); } diff --git a/GUI/coregui/Views/JobWidgets/UniversalPropertyEditor.h b/GUI/coregui/Views/PropertyEditor/UniversalPropertyEditor.h similarity index 88% rename from GUI/coregui/Views/JobWidgets/UniversalPropertyEditor.h rename to GUI/coregui/Views/PropertyEditor/UniversalPropertyEditor.h index 02ab7dd89ede6f315a135a3a9257d24b7d93039c..7bae0f6a66ccc6d40fee7e72295f607c5e7ea69c 100644 --- a/GUI/coregui/Views/JobWidgets/UniversalPropertyEditor.h +++ b/GUI/coregui/Views/PropertyEditor/UniversalPropertyEditor.h @@ -2,7 +2,7 @@ // // BornAgain: simulate and fit scattering at grazing incidence // -//! @file coregui/Views/JobWidgets/UniversalPropertyEditor.h +//! @file coregui/Views/PropertyEditor/UniversalPropertyEditor.h //! @brief Defines class UniversalPropertyEditor //! //! @homepage http://www.bornagainproject.org @@ -39,8 +39,10 @@ class BA_CORE_API_ UniversalPropertyEditor : public QWidget Q_OBJECT public: + enum EBrowserType { BROWSER_TREE_TYPE, BROWSER_GROUPBOX_TYPE, BROWSER_BUTTON_TYPE}; + UniversalPropertyEditor(QItemSelectionModel *selection_model, - QWidget *parent = 0); + QWidget *parent = 0, EBrowserType browser_type = BROWSER_TREE_TYPE); virtual ~UniversalPropertyEditor(){} QObject *getObject() const; @@ -67,7 +69,7 @@ private slots: void slotValueChanged(QtProperty *property, const QVariant &value); void updateSubItems(const QString &name); void onPropertyChanged(const QString &property_name); - void onPropertyItemPropertyChanged(const QString &property_group, const QString &property_name); + void onSubItemPropertyChanged(const QString &property_group, const QString &property_name); private: //! clear editor @@ -97,6 +99,9 @@ private: //! ParameterizedItem will be sub-properties of group with the name modelType //! (as in PropertyEditor of SampleDesigner) bool m_create_group_property; + + //! type of property browser + EBrowserType m_browser_type; }; diff --git a/GUI/coregui/Views/SampleDesigner/DesignerScene.cpp b/GUI/coregui/Views/SampleDesigner/DesignerScene.cpp index c5e0c09a5c21cbcf2a6c37532f571b4d95b7fb33..bd47027d7ecee891080d947806a94de7d82163fc 100644 --- a/GUI/coregui/Views/SampleDesigner/DesignerScene.cpp +++ b/GUI/coregui/Views/SampleDesigner/DesignerScene.cpp @@ -199,7 +199,8 @@ void DesignerScene::onSceneSelectionChanged() ParameterizedItem *sampleItem = view->getParameterizedItem(); QModelIndex itemIndex = m_sampleModel->indexOfItem(sampleItem); Q_ASSERT(itemIndex.isValid()); - m_selectionModel->select(itemIndex, QItemSelectionModel::Select); + if(!m_selectionModel->isSelected(itemIndex)) + m_selectionModel->select(itemIndex, QItemSelectionModel::Select); //break; // selection of only one item will be propagated to the model } } diff --git a/GUI/coregui/Views/SampleDesigner/EditorMimeData.cpp.autosave b/GUI/coregui/Views/SampleDesigner/EditorMimeData.cpp.autosave deleted file mode 100644 index c86298d5cbd7089b2bd203d474c2502f57ae8833..0000000000000000000000000000000000000000 --- a/GUI/coregui/Views/SampleDesigner/EditorMimeData.cpp.autosave +++ /dev/null @@ -1,29 +0,0 @@ -#include "EditorMimeData.h" - - - -Qt::DropAction EditorMimeData::execDrag(const QDesignerDnDItems &items, QWidget * dragSource) -{ - - if (items.empty()) - return Qt::IgnoreAction; - - QDrag *drag = new QDrag(dragSource); - QDesignerMimeData *mimeData = new QDesignerMimeData(items, drag); - - // Store pointers to widgets that are to be re-shown if a move operation is canceled - QWidgetList reshowWidgets; - const QDesignerDnDItems::const_iterator cend = items.constEnd(); - for (QDesignerDnDItems::const_iterator it = items.constBegin(); it != cend; ++it ) - if (QWidget *w = (*it)->widget()) - if ((*it)->type() == QDesignerDnDItemInterface::MoveDrop) - reshowWidgets.push_back(w); - - const Qt::DropAction executedAction = drag->exec(Qt::CopyAction|Qt::MoveAction, mimeData->proposedDropAction()); - - if (executedAction == Qt::IgnoreAction && !reshowWidgets.empty()) - foreach (QWidget *w, reshowWidgets) - w->show(); - - return executedAction; -} diff --git a/GUI/coregui/Views/SampleDesigner/IView.cpp b/GUI/coregui/Views/SampleDesigner/IView.cpp index 4fa667cb691a69ce2226b7777cd7dc9e64cef4eb..849cc3dfa3bcabedf7ab3e46c91341b815211d3a 100644 --- a/GUI/coregui/Views/SampleDesigner/IView.cpp +++ b/GUI/coregui/Views/SampleDesigner/IView.cpp @@ -34,7 +34,7 @@ void IView::setParameterizedItem(ParameterizedItem *item) setX(m_item->getRegisteredProperty(ParameterizedGraphicsItem::P_XPOS).toReal()); setY(m_item->getRegisteredProperty(ParameterizedGraphicsItem::P_YPOS).toReal()); connect(m_item, SIGNAL(propertyChanged(const QString &)), this, SLOT(onPropertyChange(const QString &))); - connect(m_item, SIGNAL(propertyItemChanged(const QString &)), this, SLOT(onPropertyChange(const QString &))); + connect(m_item, SIGNAL(subItemChanged(const QString &)), this, SLOT(onPropertyChange(const QString &))); } } diff --git a/GUI/coregui/Views/SampleDesigner/SampleDesigner.h b/GUI/coregui/Views/SampleDesigner/SampleDesigner.h index 0d68d62d0688cd02977938182cafb360ecd53040..11b702430d4164f5c51bc96b21a4baa40cdc5d36 100644 --- a/GUI/coregui/Views/SampleDesigner/SampleDesigner.h +++ b/GUI/coregui/Views/SampleDesigner/SampleDesigner.h @@ -22,7 +22,6 @@ #include "DesignerScene.h" class DesignerScene; -class SamplePropertyEditor; class DesignerWidgetFactory; class InstrumentModel; class SampleModel; diff --git a/GUI/coregui/Views/SampleDesigner/SamplePropertyEditor.cpp b/GUI/coregui/Views/SampleDesigner/SamplePropertyEditor.cpp deleted file mode 100644 index 50d082ea5b3bc4b55e8432f61a9afd65d7026f54..0000000000000000000000000000000000000000 --- a/GUI/coregui/Views/SampleDesigner/SamplePropertyEditor.cpp +++ /dev/null @@ -1,278 +0,0 @@ -// ************************************************************************** // -// -// BornAgain: simulate and fit scattering at grazing incidence -// -//! @file coregui/Views/SampleDesigner/SamplePropertyEditor.cpp -//! @brief Implements class SamplePropertyEditor -//! -//! @homepage http://www.bornagainproject.org -//! @license GNU General Public License v3 or higher (see COPYING) -//! @copyright Forschungszentrum Jülich GmbH 2015 -//! @authors Scientific Computing Group at MLZ Garching -//! @authors C. Durniak, M. Ganeva, G. Pospelov, W. Van Herck, J. Wuttke -// -// ************************************************************************** // - -#include "SamplePropertyEditor.h" -#include "PropertyVariantManager.h" -#include "PropertyVariantFactory.h" -#include "ParameterizedItem.h" -#include "tooltipdatabase.h" -#include "GUIHelpers.h" - -#include "qttreepropertybrowser.h" -#include "qtgroupboxpropertybrowser.h" -#include "qtbuttonpropertybrowser.h" - -#include <QtProperty> -#include <QItemSelectionModel> -#include <QVBoxLayout> -#include <QMetaProperty> -#include <QDebug> - -SamplePropertyEditor::SamplePropertyEditor(QItemSelectionModel *selection_model, - QWidget *parent) - : QWidget(parent) - , m_item(0) - , m_selection_model(selection_model) -{ - setWindowTitle(QLatin1String("Property Editor")); - setObjectName(QLatin1String("PropertyEditor")); - -// QtAbstractPropertyBrowser *browser = new QtGroupBoxPropertyBrowser(); -// QtAbstractPropertyBrowser *browser = new QtButtonPropertyBrowser(); - - QtTreePropertyBrowser *browser = new QtTreePropertyBrowser(this); - browser->setRootIsDecorated(false); - m_browser = browser; - QVBoxLayout *layout = new QVBoxLayout(this); - layout->setMargin(0); - layout->addWidget(m_browser); - - m_read_only_manager = new PropertyVariantManager(this); - - m_manager = new PropertyVariantManager(this); - - QtVariantEditorFactory *factory = new PropertyVariantFactory(); - m_browser->setFactoryForManager(m_manager, factory); - - connect(m_manager, SIGNAL(valueChanged(QtProperty *, const QVariant &)), - this, SLOT(slotValueChanged(QtProperty *, const QVariant &))); - - if(m_selection_model) - connect(m_selection_model, - SIGNAL(selectionChanged(QItemSelection,QItemSelection)), - this, - SLOT(selectionChanged(QItemSelection,QItemSelection)) ); -} - - -// show property of currently selected object (triggered by the graphics scene) -// if more than one object is selected, show only last selected -void SamplePropertyEditor::selectionChanged(const QItemSelection & selected, - const QItemSelection & deselected) -{ - (void)deselected; - QModelIndexList indices = selected.indexes(); - if(indices.size()) { - ParameterizedItem *item = static_cast<ParameterizedItem *>( - indices.back().internalPointer()); - setItem(item); - } else { - setItem(0); - } -} - - -void SamplePropertyEditor::slotValueChanged(QtProperty *property, - const QVariant &value) -{ - qDebug() << "SamplePropertyEditor::slotValueChanged()" << value; - if (!m_property_to_item_index_pair.contains(property)) - return; - - ItemIndexPair item_index_pair = - m_property_to_item_index_pair.value(property); - - if (item_index_pair.m_item) { - QList<QByteArray> prop_list = - item_index_pair.m_item->dynamicPropertyNames(); - if (item_index_pair.m_index > prop_list.length()) { - return; - } - qDebug() << "setting ..." << prop_list[item_index_pair.m_index].constData(); - item_index_pair.m_item->setProperty( - prop_list[item_index_pair.m_index].constData(), value); - } -} - - -void SamplePropertyEditor::clearEditor() -{ - qDebug() << "SamplePropertyEditor::clearEditor()"; - //updateExpandState(SaveExpandState); - - QListIterator<QtProperty *> it(m_browser->properties()); - while (it.hasNext()) { - m_browser->removeProperty(it.next()); - } - m_property_to_item_index_pair.clear(); - m_item_to_index_to_property.clear(); -} - - -void SamplePropertyEditor::updateSubItems(const QString &name) -{ - qDebug() << "SamplePropertyEditor::updateSubItems()"; - (void)name; - if (!m_item) return; - -// QListIterator<QtProperty *> it(m_browser->properties()); -// while (it.hasNext()) { -// m_browser->removeProperty(it.next()); -// } - clearEditor(); - - disconnect(m_item, SIGNAL(propertyItemChanged(QString)), - this, SLOT(updateSubItems(QString))); - addItemProperties(m_item); - connect(m_item, SIGNAL(propertyItemChanged(QString)), - this, SLOT(updateSubItems(QString))); - connect(m_item, SIGNAL(propertyChanged(QString)), - this, SLOT(onPropertyChanged(QString))); -} - -void SamplePropertyEditor::onPropertyChanged(const QString &property_name) -{ - qDebug() << "SamplePropertyEditor::onPropertyChanged() " << property_name ; - if(!m_item) return; - - QtVariantProperty *variant_property = m_item_to_propertyname_to_qtvariantproperty[m_item][property_name]; - if(variant_property) { - QVariant property_value = m_item->getRegisteredProperty(property_name); - - disconnect(m_item, SIGNAL(propertyChanged(QString)), - this, SLOT(onPropertyChanged(QString))); - disconnect(m_item, SIGNAL(propertyItemChanged(QString)), - this, SLOT(updateSubItems(QString))); - - variant_property->setValue(property_value); - - PropertyAttribute prop_attribute = m_item->getPropertyAttribute(property_name); - if(prop_attribute.getAppearance() & PropertyAttribute::DISABLED) { - variant_property->setEnabled(false); - } else { - variant_property->setEnabled(true); - } - - connect(m_item, SIGNAL(propertyChanged(QString)), - this, SLOT(onPropertyChanged(QString))); - connect(m_item, SIGNAL(propertyItemChanged(QString)), - this, SLOT(updateSubItems(QString))); - } -} - - -// assigns item to the property editor -void SamplePropertyEditor::setItem(ParameterizedItem *item) -{ - if (m_item == item) return; - - if (m_item) { -// QListIterator<QtProperty *> it(m_browser->properties()); -// while (it.hasNext()) { -// m_browser->removeProperty(it.next()); -// } - clearEditor(); - - disconnect(m_item, SIGNAL(propertyItemChanged(QString)), - this, SLOT(updateSubItems(QString))); - } - - m_item = item; - - if (!m_item) return; - - addItemProperties(m_item); - connect(m_item, SIGNAL(propertyItemChanged(QString)), - this, SLOT(updateSubItems(QString))); - connect(m_item, SIGNAL(propertyChanged(QString)), - this, SLOT(onPropertyChanged(QString))); - -} - - -void SamplePropertyEditor::addItemProperties(const ParameterizedItem *item) -{ - QString item_type = item->modelType(); - QtProperty *item_property = m_manager->addProperty( - QtVariantPropertyManager::groupTypeId(), item_type); - - addSubProperties(item_property, item); - m_browser->addProperty(item_property); -} - - -void SamplePropertyEditor::addSubProperties(QtProperty *item_property, - const ParameterizedItem *item) -{ - QList<QByteArray> property_names = item->dynamicPropertyNames(); - for (int i = 0; i < property_names.length(); ++i) { - QString prop_name = QString(property_names[i]); - PropertyAttribute prop_attribute = item->getPropertyAttribute(prop_name); - - if(prop_attribute.getAppearance() & PropertyAttribute::HIDDEN) continue; - - QVariant prop_value = item->property(prop_name.toUtf8().data()); - int type = GUIHelpers::getVariantType(prop_value); - - qDebug() << "XXX " << item->modelType() << prop_name << type; - QtVariantProperty *subProperty = 0; - if (m_manager->isPropertyTypeSupported(type)) { - - if(prop_attribute.getLabel().isEmpty()) { - subProperty = m_manager->addProperty(type, prop_name); - } else { - subProperty = m_manager->addProperty(type, prop_attribute.getLabel()); - } - - subProperty->setValue(prop_value); - - if(type == QVariant::Double) { - subProperty->setAttribute(QLatin1String("decimals"), prop_attribute.getDecimals()); - AttLimits limits = prop_attribute.getLimits(); - if(limits.hasLowerLimit()) subProperty->setAttribute(QLatin1String("minimum"), limits.getLowerLimit()); - if(limits.hasUpperLimit()) subProperty->setAttribute(QLatin1String("maximum"), limits.getUpperLimit()); - } - - QString toolTip = ToolTipDataBase::getSampleViewToolTip(item->modelType(), prop_name); - if(!toolTip.isEmpty()) subProperty->setToolTip(toolTip); - - if(prop_attribute.getAppearance() & PropertyAttribute::DISABLED) { - subProperty->setEnabled(false); - } - - if (item->getSubItems().contains(prop_name)) { - ParameterizedItem *subitem = item->getSubItems()[prop_name]; - if (subitem) { - addSubProperties(subProperty, subitem); - } - } - - } else { - subProperty = m_read_only_manager->addProperty(QVariant::String, - prop_name); - subProperty->setValue(QLatin1String("< Unknown Type >")); - subProperty->setEnabled(false); - } - - item_property->addSubProperty(subProperty); - ParameterizedItem *non_const_item = - const_cast<ParameterizedItem *>(item); - ItemIndexPair item_index_pair(non_const_item, i); - m_property_to_item_index_pair[subProperty] = item_index_pair; - m_item_to_index_to_property[item][i] = subProperty; - m_item_to_propertyname_to_qtvariantproperty[item][prop_name] = subProperty; - } -} - diff --git a/GUI/coregui/Views/SampleDesigner/SamplePropertyEditor.h b/GUI/coregui/Views/SampleDesigner/SamplePropertyEditor.h deleted file mode 100644 index 092e78c74b8fd798fbda231d29f9a439a647ad7b..0000000000000000000000000000000000000000 --- a/GUI/coregui/Views/SampleDesigner/SamplePropertyEditor.h +++ /dev/null @@ -1,94 +0,0 @@ -// ************************************************************************** // -// -// BornAgain: simulate and fit scattering at grazing incidence -// -//! @file coregui/Views/SampleDesigner/SamplePropertyEditor.h -//! @brief Defines class SamplePropertyEditor -//! -//! @homepage http://www.bornagainproject.org -//! @license GNU General Public License v3 or higher (see COPYING) -//! @copyright Forschungszentrum Jülich GmbH 2015 -//! @authors Scientific Computing Group at MLZ Garching -//! @authors C. Durniak, M. Ganeva, G. Pospelov, W. Van Herck, J. Wuttke -// -// ************************************************************************** // - -#ifndef SAMPLEPROPERTYEDITOR_H -#define SAMPLEPROPERTYEDITOR_H - -#include "WinDllMacros.h" -#include <QWidget> -#include <QMap> -#include <QString> - -class SampleDesignerInterface; -class QItemSelectionModel; -class QItemSelection; -class QtVariantPropertyManager; -class QtTreePropertyBrowser; -class QtProperty; -class QtVariantProperty; -class QVariant; -class QtAbstractPropertyBrowser; -class ParameterizedItem; - - -//! property editor to modify property of the objectcurrently selected on the graphics scene -//! located in the bottom right corner of SampleView -class BA_CORE_API_ SamplePropertyEditor : public QWidget -{ - Q_OBJECT - -public: - SamplePropertyEditor(QItemSelectionModel *selection_model, - QWidget *parent = 0); - virtual ~SamplePropertyEditor(){} - - QObject *getObject() const; - struct ItemIndexPair { - ItemIndexPair(ParameterizedItem *item=0, int index=0) - : m_item(item), m_index(index) {} - ParameterizedItem *m_item; - int m_index; - }; - -public slots: - //! show property of currently selected object (triggered by graphics scene) - void selectionChanged(const QItemSelection & selected, - const QItemSelection & deselected); - -private slots: - void slotValueChanged(QtProperty *property, const QVariant &value); - void updateSubItems(const QString &name); - void onPropertyChanged(const QString &property_name); - -private: - //! assigns item to the property editor - void setItem(ParameterizedItem *item); - - //! clear editor - void clearEditor(); - - ParameterizedItem *m_item; //! object to modify - - QItemSelectionModel *m_selection_model; - - QMap<QtProperty *, ItemIndexPair> m_property_to_item_index_pair; - QMap<const ParameterizedItem *, QMap<int, QtVariantProperty *> > - m_item_to_index_to_property; - - QMap<const ParameterizedItem *, QMap<QString, QtVariantProperty *> > - m_item_to_propertyname_to_qtvariantproperty; - - - QtAbstractPropertyBrowser *m_browser; - QtVariantPropertyManager *m_manager; - QtVariantPropertyManager *m_read_only_manager; - - void addItemProperties(const ParameterizedItem *item); - void addSubProperties(QtProperty *item_property, - const ParameterizedItem *item); -}; - - -#endif // SAMPLEPROPERTYEDITOR_H diff --git a/GUI/coregui/Views/SampleDesigner/SamplePropertyWidget.cpp b/GUI/coregui/Views/SampleDesigner/SamplePropertyWidget.cpp new file mode 100644 index 0000000000000000000000000000000000000000..a26bb679f4fc38b1155b79220c654ebba01cc624 --- /dev/null +++ b/GUI/coregui/Views/SampleDesigner/SamplePropertyWidget.cpp @@ -0,0 +1,78 @@ +// ************************************************************************** // +// +// BornAgain: simulate and fit scattering at grazing incidence +// +//! @file coregui/Views/SampleDesigner/SamplePropertyWidget.cpp +//! @brief Implements class IntensityDataPropertyWidget +//! +//! @homepage http://www.bornagainproject.org +//! @license GNU General Public License v3 or higher (see COPYING) +//! @copyright Forschungszentrum Jülich GmbH 2015 +//! @authors Scientific Computing Group at MLZ Garching +//! @authors C. Durniak, M. Ganeva, G. Pospelov, W. Van Herck, J. Wuttke +// +// ************************************************************************** // + +#include "SamplePropertyWidget.h" +#include "AwesomePropertyEditor.h" +#include "ParameterizedItem.h" +#include <QVBoxLayout> +#include <QItemSelection> +#include <QModelIndexList> +#include <QDebug> + +SamplePropertyWidget::SamplePropertyWidget(QItemSelectionModel *selection_model, QWidget *parent) + : QWidget(parent) + , m_selection_model(0) +{ + setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); + setWindowTitle(QLatin1String("Property Editor")); + setObjectName(QLatin1String("SamplePropertyWidget")); + + setSelectionModel(selection_model); + + QVBoxLayout *mainLayout = new QVBoxLayout; + mainLayout->setMargin(0); + mainLayout->setSpacing(0); + + m_propertyEditor = new AwesomePropertyEditor(this); + + mainLayout->addWidget(m_propertyEditor); + setLayout(mainLayout); +} + +void SamplePropertyWidget::setSelectionModel(QItemSelectionModel *selection_model) +{ + if(selection_model != m_selection_model) { + if(m_selection_model) + disconnect(m_selection_model, + SIGNAL(selectionChanged(QItemSelection,QItemSelection)), + this, + SLOT(selectionChanged(QItemSelection,QItemSelection)) ); + + m_selection_model = selection_model; + + connect(m_selection_model, + SIGNAL(selectionChanged(QItemSelection,QItemSelection)), + this, + SLOT(selectionChanged(QItemSelection,QItemSelection)) ); + + } +} + +// show property of currently selected object (triggered by the graphics scene) +// if more than one object is selected, show only last selected +void SamplePropertyWidget::selectionChanged(const QItemSelection & selected, + const QItemSelection & deselected) +{ + qDebug() << "SamplePropertyWidget::selectionChanged" << selected << deselected; + (void)deselected; + QModelIndexList indices = selected.indexes(); + if(indices.size()) { + ParameterizedItem *item = static_cast<ParameterizedItem *>( + indices.back().internalPointer()); + m_propertyEditor->setItem(item, item->modelType()); + } else { + m_propertyEditor->setItem(0); + } +} diff --git a/GUI/coregui/Views/SampleDesigner/SamplePropertyWidget.h b/GUI/coregui/Views/SampleDesigner/SamplePropertyWidget.h new file mode 100644 index 0000000000000000000000000000000000000000..7d4181c02c97151f0e7be1e6e3893d404b71e3c2 --- /dev/null +++ b/GUI/coregui/Views/SampleDesigner/SamplePropertyWidget.h @@ -0,0 +1,50 @@ +// ************************************************************************** // +// +// BornAgain: simulate and fit scattering at grazing incidence +// +//! @file coregui/Views/SampleDesigner/SamplePropertyWidget.h +//! @brief Defines class SamplePropertyWidget +//! +//! @homepage http://www.bornagainproject.org +//! @license GNU General Public License v3 or higher (see COPYING) +//! @copyright Forschungszentrum Jülich GmbH 2015 +//! @authors Scientific Computing Group at MLZ Garching +//! @authors C. Durniak, M. Ganeva, G. Pospelov, W. Van Herck, J. Wuttke +// +// ************************************************************************** // + +#ifndef SAMPLEPROPERTYWIDGET_H +#define SAMPLEPROPERTYWIDGET_H + +#include "WinDllMacros.h" +#include <QWidget> + +class QItemSelectionModel; +class QItemSelection; +class AwesomePropertyEditor; + +//! Property editor to modify property of the objectcurrently selected on the +//! graphics scene, located in the bottom right corner of SampleView. +class BA_CORE_API_ SamplePropertyWidget : public QWidget +{ + Q_OBJECT +public: + SamplePropertyWidget(QItemSelectionModel *selection_model, + QWidget *parent = 0); + + QSize sizeHint() const { return QSize(230, 256); } + QSize minimumSizeHint() const { return QSize(230, 64); } + + void setSelectionModel(QItemSelectionModel *selection_model); + +public slots: + //! show property of currently selected object (triggered by graphics scene) + void selectionChanged(const QItemSelection & selected, + const QItemSelection & deselected); + +private: + QItemSelectionModel *m_selection_model; + AwesomePropertyEditor *m_propertyEditor; +}; + +#endif diff --git a/GUI/coregui/Views/SampleView.cpp b/GUI/coregui/Views/SampleView.cpp index 69cc7ccb959d09955d325079c3f7eef7e09034e7..d6bc4859a4751a17e8d261a6adb41552a8285182 100644 --- a/GUI/coregui/Views/SampleView.cpp +++ b/GUI/coregui/Views/SampleView.cpp @@ -18,6 +18,7 @@ #include "SampleDesigner.h" #include "SampleToolBar.h" #include "GUIHelpers.h" +#include "SamplePropertyWidget.h" #include <ItemFactory.h> @@ -102,9 +103,10 @@ void SampleView::initSubWindows() m_tree_view = SampleViewComponents::createTreeView(m_sampleModel, this); m_subWindows[SAMPLE_TREE] = m_tree_view; - m_subWindows[PROPERTY_EDITOR] = - SampleViewComponents::createPropertyEditor( - m_tree_view->selectionModel(), this); +// m_subWindows[PROPERTY_EDITOR] = +// SampleViewComponents::createPropertyEditor( +// m_tree_view->selectionModel(), this); + m_subWindows[PROPERTY_EDITOR] = new SamplePropertyWidget(m_tree_view->selectionModel(), this); SampleInfoStreamInterface *ae = SampleViewComponents::createInfoStream(this); diff --git a/GUI/coregui/Views/SampleViewComponents.cpp b/GUI/coregui/Views/SampleViewComponents.cpp index b7fdf21dff0342bf35a357d7e1b063e67e786b2d..69ce986b66d3408c5298adc155cf185f1e99e17f 100644 --- a/GUI/coregui/Views/SampleViewComponents.cpp +++ b/GUI/coregui/Views/SampleViewComponents.cpp @@ -24,11 +24,11 @@ SampleWidgetBox *SampleViewComponents::createWidgetBox( return new SampleWidgetBox(core, parent); } -SamplePropertyEditor *SampleViewComponents::createPropertyEditor( - QItemSelectionModel *selection_model, QWidget *parent) -{ - return new SamplePropertyEditor(selection_model, parent); -} +//SamplePropertyEditor *SampleViewComponents::createPropertyEditor( +// QItemSelectionModel *selection_model, QWidget *parent) +//{ +// return new SamplePropertyEditor(selection_model, parent); +//} ItemTreeView *SampleViewComponents::createTreeView( SampleModel *sampleModel, QWidget *parent) diff --git a/GUI/coregui/Views/SampleViewComponents.h b/GUI/coregui/Views/SampleViewComponents.h index de9ab906b8f360ff9329402170e195eacdaf3059..5c5f038a4167382ab3504ac7aaba6c5aad081a2c 100644 --- a/GUI/coregui/Views/SampleViewComponents.h +++ b/GUI/coregui/Views/SampleViewComponents.h @@ -20,7 +20,7 @@ #include "ItemTreeView.h" #include "widgetbox.h" -#include "SamplePropertyEditor.h" +//#include "SamplePropertyEditor.h" #include "SampleWidgetBox.h" #include "SampleModel.h" @@ -42,8 +42,8 @@ class BA_CORE_API_ SampleViewComponents public: static SampleWidgetBox *createWidgetBox( SampleDesignerInterface *core, QWidget *parent); - static SamplePropertyEditor *createPropertyEditor( - QItemSelectionModel *selection_model, QWidget *parent); +// static SamplePropertyEditor *createPropertyEditor( +// QItemSelectionModel *selection_model, QWidget *parent); static ItemTreeView *createTreeView( SampleModel *sample_model, QWidget *parent); static SampleInfoStreamInterface *createInfoStream(QWidget *parent); diff --git a/GUI/coregui/Views/SimulationWidgets/SimulationSetupWidget.cpp b/GUI/coregui/Views/SimulationWidgets/SimulationSetupWidget.cpp index 4fb89b188bb41ee0aed09988f81f255c6dfdcc19..eee57d69840c06e7ea0f21dbf106be4e488f50d2 100644 --- a/GUI/coregui/Views/SimulationWidgets/SimulationSetupWidget.cpp +++ b/GUI/coregui/Views/SimulationWidgets/SimulationSetupWidget.cpp @@ -159,12 +159,21 @@ QString SimulationSetupWidget::getInstrumentSelection() const return instrumentSelectionBox->currentText(); } +int SimulationSetupWidget::getInstrumentCurrentIndex() const +{ + return instrumentSelectionBox->currentIndex(); +} QString SimulationSetupWidget::getSampleSelection() const { return sampleSelectionBox->currentText(); } +int SimulationSetupWidget::getSampleCurrentIndex() const +{ + return sampleSelectionBox->currentIndex(); +} + void SimulationSetupWidget::updateViewElements() { updateSelectionBox(instrumentSelectionBox, m_instrumentModel->getInstrumentMap().keys()); @@ -277,9 +286,14 @@ InstrumentModel *SimulationSetupWidget::getJobInstrumentModel() { InstrumentModel *result(0); QMap<QString, ParameterizedItem *> instruments = m_instrumentModel->getInstrumentMap(); - if(instruments[getInstrumentSelection()]) { - result = m_instrumentModel->createCopy(instruments[getInstrumentSelection()]); - } +// if(instruments[getInstrumentSelection()]) { +// result = m_instrumentModel->createCopy(instruments[getInstrumentSelection()]); +// } + // there can be several instruments with same name + int index = getInstrumentCurrentIndex(); + QMap<QString, ParameterizedItem *>::iterator it = instruments.begin()+index; + result = m_instrumentModel->createCopy(it.value()); + return result; } @@ -288,9 +302,12 @@ SampleModel *SimulationSetupWidget::getJobSampleModel() { SampleModel *result(0); QMap<QString, ParameterizedItem *> samples = m_sampleModel->getSampleMap(); - if(samples[getSampleSelection()]) { - result = m_sampleModel->createCopy(samples[getSampleSelection()]); - } +// if(samples[getSampleSelection()]) { +// result = m_sampleModel->createCopy(samples[getSampleSelection()]); +// } + int index = getSampleCurrentIndex(); + QMap<QString, ParameterizedItem *>::iterator it = samples.begin()+index; + result = m_sampleModel->createCopy(it.value()); return result; } diff --git a/GUI/coregui/Views/SimulationWidgets/SimulationSetupWidget.h b/GUI/coregui/Views/SimulationWidgets/SimulationSetupWidget.h index 8815f275cb5d7bddefbc658469855dedb62317f4..db5a571fbbe9064e27b44f3da83536eec3268282 100644 --- a/GUI/coregui/Views/SimulationWidgets/SimulationSetupWidget.h +++ b/GUI/coregui/Views/SimulationWidgets/SimulationSetupWidget.h @@ -39,7 +39,10 @@ public: void setInstrumentModel(InstrumentModel *model); QString getInstrumentSelection() const; + int getInstrumentCurrentIndex() const; + QString getSampleSelection() const; + int getSampleCurrentIndex() const; public slots: void onRunSimulation(); diff --git a/GUI/coregui/Views/TestView.cpp b/GUI/coregui/Views/TestView.cpp index 217d321640e465d429114bc8c6e1a5ccceb8de40..14fa3f1a883d3b65b3889dddea6ec56241f35b42 100644 --- a/GUI/coregui/Views/TestView.cpp +++ b/GUI/coregui/Views/TestView.cpp @@ -14,11 +14,47 @@ // ************************************************************************** // #include "TestView.h" +#include "TestItem.h" +#include "LayerItem.h" +#include "AwesomePropertyEditor.h" +#include <QGroupBox> +#include <QGridLayout> TestView::TestView(QWidget *parent) : QWidget(parent) { setMinimumSize(128, 128); setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); + + QGroupBox *groupBox = new QGroupBox("Beam Parameters"); + QVBoxLayout *groupLayout = new QVBoxLayout; + groupBox->setLayout(groupLayout); + + // whole content is represented as grid layout + QGridLayout *gridLayout = new QGridLayout; + + AwesomePropertyEditor *editor1 = new AwesomePropertyEditor(this); + editor1->setMinimumSize(256, 256); + AwesomePropertyEditor *editor2 = new AwesomePropertyEditor(this, AwesomePropertyEditor::BROWSER_GROUPBOX_TYPE); + + TestItem *item1 = new TestItem; + LayerItem *layer = new LayerItem(); + editor1->addItemProperty(layer, LayerItem::P_THICKNESS, "MyGroup"); + editor1->addItemProperties(item1, "MyGroup"); + + editor2->addItemProperty(layer, LayerItem::P_THICKNESS, "MyGroup"); + editor2->addItemProperties(item1, "MyGroup", AwesomePropertyEditor::INSERT_AFTER); + + gridLayout->addWidget(editor1, 0, 0); + gridLayout->addWidget(editor2, 0, 1); + + groupLayout->addLayout(gridLayout); + + // main layout + QVBoxLayout *mainLayout = new QVBoxLayout; + mainLayout->addWidget(groupBox); + setLayout(mainLayout); + + } diff --git a/GUI/coregui/Views/TestView.h b/GUI/coregui/Views/TestView.h index 04330d7b69634ff472fabbbf41608a19748f714d..209b14223256fe292e2835c39dd8e8c84d2f431f 100644 --- a/GUI/coregui/Views/TestView.h +++ b/GUI/coregui/Views/TestView.h @@ -18,7 +18,6 @@ #include <QWidget> - class TestView : public QWidget { Q_OBJECT @@ -27,10 +26,6 @@ public: TestView(QWidget *parent = 0); virtual ~TestView() {} - }; - - - #endif diff --git a/GUI/coregui/Views/widgetbox/widgetbox.xml b/GUI/coregui/Views/widgetbox/widgetbox.xml index 69ebb633f87a949d742414a4b8562149374f3b37..5aa1a1ee9a62aebc3341a84e7ac2c842b0f06499 100644 --- a/GUI/coregui/Views/widgetbox/widgetbox.xml +++ b/GUI/coregui/Views/widgetbox/widgetbox.xml @@ -300,6 +300,15 @@ </widget> </categoryentry> + <categoryentry name="Example #8 (Beam Divergence)" icon="images/sample_layers2.png"> + <widget class="example08"> + <property name="objectName"> + <string notr="true">somestring</string> + </property> + </widget> + </categoryentry> + + </category> </widgetbox> diff --git a/GUI/coregui/mainwindow/mainwindow.cpp b/GUI/coregui/mainwindow/mainwindow.cpp index a38d494806addb40981d1020fe6c10740352b318..0a559f98893e8d3be94d610dc7da079d169f2570 100644 --- a/GUI/coregui/mainwindow/mainwindow.cpp +++ b/GUI/coregui/mainwindow/mainwindow.cpp @@ -59,6 +59,7 @@ #include "FitModel.h" #include "FitProxyModel.h" #include "FitView.h" +#include "TestView.h" #include <boost/scoped_ptr.hpp> #include <QApplication> @@ -119,7 +120,7 @@ MainWindow::MainWindow(QWidget *parent) //m_scriptView = new PyScriptView(mp_sim_data_model); m_simulationView = new SimulationView(this); - //m_testView = new TestView(m_sampleModel, this); +// m_testView = new TestView(m_sampleModel, this); //m_fitView = new FitView(m_fitProxyModel, this); m_jobView = new JobView(m_jobModel, m_projectManager); @@ -133,8 +134,9 @@ MainWindow::MainWindow(QWidget *parent) m_tabWidget->insertTab(JOB, m_jobView, QIcon(":/images/main_jobqueue.png"), "Jobs"); //m_tabWidget->insertTab(TestViewTab, m_testView, QIcon(":/images/main_simulation.png"), "Test"); //m_tabWidget->insertTab(FitViewTab, m_fitView, QIcon(":/images/main_simulation.png"), "Fit"); - - m_tabWidget->setCurrentIndex(WELCOME); + m_tabWidget->insertTab(FIT_VIEW, new TestView(this), QIcon(":/images/main_simulation.png"), "Test"); +// + m_tabWidget->setCurrentIndex(INSTRUMENT); m_progressBar = new Manhattan::ProgressBar(this); m_tabWidget->addBottomCornerWidget(m_progressBar); @@ -150,6 +152,8 @@ MainWindow::MainWindow(QWidget *parent) connect(m_jobView, SIGNAL(focusRequest(int)), this, SLOT(onFocusRequest(int))); m_projectManager->createNewProject(); + + testGUIObjectBuilder(); } MainWindow::~MainWindow() @@ -303,7 +307,7 @@ void MainWindow::testGUIObjectBuilder() boost::scoped_ptr<ISample> sample(factory.createSample("isgisaxs01")); GUIObjectBuilder guiBuilder; - guiBuilder.populateSampleModel(m_sampleModel, sample.get()); + guiBuilder.populateSampleModel(m_sampleModel, *sample); } void MainWindow::onAboutApplication() diff --git a/GUI/coregui/utils/GUIFunctionalTest.cpp b/GUI/coregui/utils/GUIFunctionalTest.cpp index 468281577c345a9817c69576e5049580869f7724..36e7b0ec5eb5c4cc42f80ebce1adf9e19fdd2338 100644 --- a/GUI/coregui/utils/GUIFunctionalTest.cpp +++ b/GUI/coregui/utils/GUIFunctionalTest.cpp @@ -24,6 +24,7 @@ #include "DomainObjectBuilder.h" #include "ParameterizedItem.h" #include "IntensityDataFunctions.h" +#include "DomainSimulationBuilder.h" #include <boost/scoped_ptr.hpp> #include <QDebug> @@ -81,30 +82,28 @@ void GUIFunctionalTest::createDomainSimulation() boost::scoped_ptr<MaterialEditor> materialEditor(new MaterialEditor(materialModel.get())); // populating GUI models from domain - boost::scoped_ptr<ISample> reference_sample(m_reference_simulation->getSample()->clone()); - boost::scoped_ptr<Instrument> reference_instrument(new Instrument(m_reference_simulation->getInstrument())); - GUIObjectBuilder guiBuilder; - guiBuilder.populateSampleModel(sampleModel.get(), reference_sample.get()); - guiBuilder.populateInstrumentModel(instrumentModel.get(), reference_instrument.get()); + guiBuilder.populateSampleModel(sampleModel.get(), *m_reference_simulation); + guiBuilder.populateInstrumentModel(instrumentModel.get(), *m_reference_simulation); // building sample back - QModelIndex sampleIndex = sampleModel->index(0, 0, QModelIndex()); - ParameterizedItem *sampleItem = sampleModel->itemForIndex(sampleIndex); - DomainObjectBuilder builder; - MultiLayer *new_sample = builder.buildMultiLayer(*sampleItem); - new_sample->printSampleTree(); - - // building multilayer back - QModelIndex instrumentIndex = instrumentModel->index(0, 0, QModelIndex()); - ParameterizedItem *instrumentItem = sampleModel->itemForIndex(instrumentIndex); - Q_ASSERT(sampleItem); - Instrument *new_instrument = builder.buildInstrument(*instrumentItem); - - // running simulation again - m_domain_simulation = new Simulation; - m_domain_simulation->setSample(*new_sample); - m_domain_simulation->setInstrument(*new_instrument); + +// QModelIndex sampleIndex = sampleModel->index(0, 0, QModelIndex()); +// ParameterizedItem *sampleItem = sampleModel->itemForIndex(sampleIndex); +// DomainObjectBuilder builder; +// MultiLayer *new_sample = builder.buildMultiLayer(*sampleItem); + +// // building multilayer back +// QModelIndex instrumentIndex = instrumentModel->index(0, 0, QModelIndex()); +// ParameterizedItem *instrumentItem = sampleModel->itemForIndex(instrumentIndex); +// Q_ASSERT(sampleItem); +// Instrument *new_instrument = builder.buildInstrument(*instrumentItem); + +// m_domain_simulation = new Simulation; +// m_domain_simulation->setSample(*new_sample); +// m_domain_simulation->setInstrument(*new_instrument); + + m_domain_simulation = DomainSimulationBuilder::getSimulation(sampleModel.get(), instrumentModel.get()); } diff --git a/GUI/externals/qtpropertybrowser/qtbuttonpropertybrowser.cpp b/GUI/externals/qtpropertybrowser/qtbuttonpropertybrowser.cpp index d2388cbaa6d04db275646cda7c4fc3b03a324f1f..a98a8be67af383220ffdf04bb7a8f351962cc376 100644 --- a/GUI/externals/qtpropertybrowser/qtbuttonpropertybrowser.cpp +++ b/GUI/externals/qtpropertybrowser/qtbuttonpropertybrowser.cpp @@ -1,40 +1,32 @@ /**************************************************************************** ** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). ** Contact: http://www.qt-project.org/legal ** ** This file is part of the tools applications of the Qt Toolkit. ** -** $QT_BEGIN_LICENSE:LGPL$ +** $QT_BEGIN_LICENSE:LGPL21$ ** Commercial License Usage ** Licensees holding valid commercial Qt licenses may use this file in ** accordance with the commercial license agreement provided with the ** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information ** use the contact form at http://qt.digia.com/contact-us. ** ** GNU Lesser General Public License Usage ** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. ** ** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception +** rights. These rights are described in the Digia Qt LGPL Exception ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. ** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** ** $QT_END_LICENSE$ ** ****************************************************************************/ diff --git a/GUI/externals/qtpropertybrowser/qtbuttonpropertybrowser.h b/GUI/externals/qtpropertybrowser/qtbuttonpropertybrowser.h index c5c1aacf7e675600cb93bc86dac0acd205e4bed6..9a41434a1fd9c8c3482f556542556cbafba0dbb5 100644 --- a/GUI/externals/qtpropertybrowser/qtbuttonpropertybrowser.h +++ b/GUI/externals/qtpropertybrowser/qtbuttonpropertybrowser.h @@ -1,40 +1,32 @@ /**************************************************************************** ** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). ** Contact: http://www.qt-project.org/legal ** ** This file is part of the tools applications of the Qt Toolkit. ** -** $QT_BEGIN_LICENSE:LGPL$ +** $QT_BEGIN_LICENSE:LGPL21$ ** Commercial License Usage ** Licensees holding valid commercial Qt licenses may use this file in ** accordance with the commercial license agreement provided with the ** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information ** use the contact form at http://qt.digia.com/contact-us. ** ** GNU Lesser General Public License Usage ** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. ** ** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception +** rights. These rights are described in the Digia Qt LGPL Exception ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. ** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** ** $QT_END_LICENSE$ ** ****************************************************************************/ diff --git a/GUI/externals/qtpropertybrowser/qteditorfactory.cpp b/GUI/externals/qtpropertybrowser/qteditorfactory.cpp index 30af0699cb997eef821105b232aef678bfba48a9..ce2669a30971f7f4eadc4708d00f5692036c8b0f 100644 --- a/GUI/externals/qtpropertybrowser/qteditorfactory.cpp +++ b/GUI/externals/qtpropertybrowser/qteditorfactory.cpp @@ -1,40 +1,32 @@ /**************************************************************************** ** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). ** Contact: http://www.qt-project.org/legal ** ** This file is part of the tools applications of the Qt Toolkit. ** -** $QT_BEGIN_LICENSE:LGPL$ +** $QT_BEGIN_LICENSE:LGPL21$ ** Commercial License Usage ** Licensees holding valid commercial Qt licenses may use this file in ** accordance with the commercial license agreement provided with the ** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information ** use the contact form at http://qt.digia.com/contact-us. ** ** GNU Lesser General Public License Usage ** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. ** ** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception +** rights. These rights are described in the Digia Qt LGPL Exception ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. ** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** ** $QT_END_LICENSE$ ** ****************************************************************************/ @@ -56,6 +48,7 @@ #include <QtWidgets/QColorDialog> #include <QtWidgets/QFontDialog> #include <QtWidgets/QSpacerItem> +#include <QtWidgets/QKeySequenceEdit> #include <QtCore/QMap> #if defined(Q_CC_MSVC) @@ -1410,7 +1403,7 @@ void QtDateTimeEditFactory::disconnectPropertyManager(QtDateTimePropertyManager // QtKeySequenceEditorFactory -class QtKeySequenceEditorFactoryPrivate : public EditorFactoryPrivate<QtKeySequenceEdit> +class QtKeySequenceEditorFactoryPrivate : public EditorFactoryPrivate<QKeySequenceEdit> { QtKeySequenceEditorFactory *q_ptr; Q_DECLARE_PUBLIC(QtKeySequenceEditorFactory) @@ -1426,9 +1419,9 @@ void QtKeySequenceEditorFactoryPrivate::slotPropertyChanged(QtProperty *property if (!m_createdEditors.contains(property)) return; - QListIterator<QtKeySequenceEdit *> itEditor(m_createdEditors[property]); + QListIterator<QKeySequenceEdit *> itEditor(m_createdEditors[property]); while (itEditor.hasNext()) { - QtKeySequenceEdit *editor = itEditor.next(); + QKeySequenceEdit *editor = itEditor.next(); editor->blockSignals(true); editor->setKeySequence(value); editor->blockSignals(false); @@ -1438,8 +1431,8 @@ void QtKeySequenceEditorFactoryPrivate::slotPropertyChanged(QtProperty *property void QtKeySequenceEditorFactoryPrivate::slotSetValue(const QKeySequence &value) { QObject *object = q_ptr->sender(); - const QMap<QtKeySequenceEdit *, QtProperty *>::ConstIterator ecend = m_editorToProperty.constEnd(); - for (QMap<QtKeySequenceEdit *, QtProperty *>::ConstIterator itEditor = m_editorToProperty.constBegin(); itEditor != ecend; ++itEditor) + const QMap<QKeySequenceEdit *, QtProperty *>::ConstIterator ecend = m_editorToProperty.constEnd(); + for (QMap<QKeySequenceEdit *, QtProperty *>::ConstIterator itEditor = m_editorToProperty.constBegin(); itEditor != ecend; ++itEditor) if (itEditor.key() == object) { QtProperty *property = itEditor.value(); QtKeySequencePropertyManager *manager = q_ptr->propertyManager(property); @@ -1499,7 +1492,7 @@ void QtKeySequenceEditorFactory::connectPropertyManager(QtKeySequencePropertyMan QWidget *QtKeySequenceEditorFactory::createEditor(QtKeySequencePropertyManager *manager, QtProperty *property, QWidget *parent) { - QtKeySequenceEdit *editor = d_ptr->createEditor(property, parent); + QKeySequenceEdit *editor = d_ptr->createEditor(property, parent); editor->setKeySequence(manager->value(property)); connect(editor, SIGNAL(keySequenceChanged(QKeySequence)), diff --git a/GUI/externals/qtpropertybrowser/qteditorfactory.h b/GUI/externals/qtpropertybrowser/qteditorfactory.h index 6b40f08f8779895d83c5dad341afc79853cedc6e..c810bf84bb9de3c8e28b2f75d958c52d8c05e330 100644 --- a/GUI/externals/qtpropertybrowser/qteditorfactory.h +++ b/GUI/externals/qtpropertybrowser/qteditorfactory.h @@ -1,40 +1,32 @@ /**************************************************************************** ** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). ** Contact: http://www.qt-project.org/legal ** ** This file is part of the tools applications of the Qt Toolkit. ** -** $QT_BEGIN_LICENSE:LGPL$ +** $QT_BEGIN_LICENSE:LGPL21$ ** Commercial License Usage ** Licensees holding valid commercial Qt licenses may use this file in ** accordance with the commercial license agreement provided with the ** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information ** use the contact form at http://qt.digia.com/contact-us. ** ** GNU Lesser General Public License Usage ** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. ** ** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception +** rights. These rights are described in the Digia Qt LGPL Exception ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. ** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** ** $QT_END_LICENSE$ ** ****************************************************************************/ diff --git a/GUI/externals/qtpropertybrowser/qtgroupboxpropertybrowser.cpp b/GUI/externals/qtpropertybrowser/qtgroupboxpropertybrowser.cpp index f0a3686c3ecb98f9ccf2436a2f5b0fffa8d861c5..a8f43ad4dafbfbdb190a4099ede37e07b80ffa3f 100644 --- a/GUI/externals/qtpropertybrowser/qtgroupboxpropertybrowser.cpp +++ b/GUI/externals/qtpropertybrowser/qtgroupboxpropertybrowser.cpp @@ -1,40 +1,32 @@ /**************************************************************************** ** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). ** Contact: http://www.qt-project.org/legal ** ** This file is part of the tools applications of the Qt Toolkit. ** -** $QT_BEGIN_LICENSE:LGPL$ +** $QT_BEGIN_LICENSE:LGPL21$ ** Commercial License Usage ** Licensees holding valid commercial Qt licenses may use this file in ** accordance with the commercial license agreement provided with the ** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information ** use the contact form at http://qt.digia.com/contact-us. ** ** GNU Lesser General Public License Usage ** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. ** ** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception +** rights. These rights are described in the Digia Qt LGPL Exception ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. ** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** ** $QT_END_LICENSE$ ** ****************************************************************************/ @@ -228,6 +220,8 @@ void QtGroupBoxPropertyBrowserPrivate::propertyInserted(QtBrowserItem *index, Qt parentItem->widget->setParent(parentItem->groupBox); parentItem->layout->addWidget(parentItem->widget, 0, 0, 1, 2); parentItem->line = new QFrame(parentItem->groupBox); + // g.p. 18.02.2015 AwesomePropertyEditor Bedurf + parentItem->widget->show(); } else if (parentItem->widgetLabel) { l->removeWidget(parentItem->widgetLabel); delete parentItem->widgetLabel; @@ -320,7 +314,8 @@ void QtGroupBoxPropertyBrowserPrivate::propertyRemoved(QtBrowserItem *index) } if (parentItem->widget) { - parentItem->widget->hide(); + // g.p. 18.02.2015 AwesomePropertyEditor Bedurf + //parentItem->widget->hide(); parentItem->widget->setParent(0); } else if (parentItem->widgetLabel) { parentItem->widgetLabel->hide(); diff --git a/GUI/externals/qtpropertybrowser/qtgroupboxpropertybrowser.h b/GUI/externals/qtpropertybrowser/qtgroupboxpropertybrowser.h index dc4e05214376fcee8864585d1751d21da976451c..c80222e8e2803dfaba3d5cba74e7d82451f537f1 100644 --- a/GUI/externals/qtpropertybrowser/qtgroupboxpropertybrowser.h +++ b/GUI/externals/qtpropertybrowser/qtgroupboxpropertybrowser.h @@ -1,40 +1,32 @@ /**************************************************************************** ** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). ** Contact: http://www.qt-project.org/legal ** ** This file is part of the tools applications of the Qt Toolkit. ** -** $QT_BEGIN_LICENSE:LGPL$ +** $QT_BEGIN_LICENSE:LGPL21$ ** Commercial License Usage ** Licensees holding valid commercial Qt licenses may use this file in ** accordance with the commercial license agreement provided with the ** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information ** use the contact form at http://qt.digia.com/contact-us. ** ** GNU Lesser General Public License Usage ** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. ** ** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception +** rights. These rights are described in the Digia Qt LGPL Exception ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. ** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** ** $QT_END_LICENSE$ ** ****************************************************************************/ diff --git a/GUI/externals/qtpropertybrowser/qtpropertybrowser.cpp b/GUI/externals/qtpropertybrowser/qtpropertybrowser.cpp index bd1305f1998904b980a4e8334a9ab5d6c4fbdcb3..76246d1c494497b1711d7289bb742a915a2cb554 100644 --- a/GUI/externals/qtpropertybrowser/qtpropertybrowser.cpp +++ b/GUI/externals/qtpropertybrowser/qtpropertybrowser.cpp @@ -1,40 +1,32 @@ /**************************************************************************** ** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). ** Contact: http://www.qt-project.org/legal ** ** This file is part of the tools applications of the Qt Toolkit. ** -** $QT_BEGIN_LICENSE:LGPL$ +** $QT_BEGIN_LICENSE:LGPL21$ ** Commercial License Usage ** Licensees holding valid commercial Qt licenses may use this file in ** accordance with the commercial license agreement provided with the ** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information ** use the contact form at http://qt.digia.com/contact-us. ** ** GNU Lesser General Public License Usage ** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. ** ** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception +** rights. These rights are described in the Digia Qt LGPL Exception ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. ** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** ** $QT_END_LICENSE$ ** ****************************************************************************/ diff --git a/GUI/externals/qtpropertybrowser/qtpropertybrowser.h b/GUI/externals/qtpropertybrowser/qtpropertybrowser.h index 74bd0651b082d4a719c61ee21f3ffb6aba44151f..00d480b72b7a76988ffeda79a80da18a99b1173c 100644 --- a/GUI/externals/qtpropertybrowser/qtpropertybrowser.h +++ b/GUI/externals/qtpropertybrowser/qtpropertybrowser.h @@ -1,40 +1,32 @@ /**************************************************************************** ** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). ** Contact: http://www.qt-project.org/legal ** ** This file is part of the tools applications of the Qt Toolkit. ** -** $QT_BEGIN_LICENSE:LGPL$ +** $QT_BEGIN_LICENSE:LGPL21$ ** Commercial License Usage ** Licensees holding valid commercial Qt licenses may use this file in ** accordance with the commercial license agreement provided with the ** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information ** use the contact form at http://qt.digia.com/contact-us. ** ** GNU Lesser General Public License Usage ** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. ** ** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception +** rights. These rights are described in the Digia Qt LGPL Exception ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. ** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** ** $QT_END_LICENSE$ ** ****************************************************************************/ diff --git a/GUI/externals/qtpropertybrowser/qtpropertybrowser.qrc b/GUI/externals/qtpropertybrowser/qtpropertybrowser.qrc index 03e9c5612e61d4248db1c4553ac01ed7331f93df..a7d37dd10dbb2741f6832f4b603d62fff2c25a2a 100644 --- a/GUI/externals/qtpropertybrowser/qtpropertybrowser.qrc +++ b/GUI/externals/qtpropertybrowser/qtpropertybrowser.qrc @@ -20,4 +20,4 @@ <file>images/cursor-whatsthis.png</file> </qresource> </RCC> - + diff --git a/GUI/externals/qtpropertybrowser/qtpropertybrowserutils.cpp b/GUI/externals/qtpropertybrowser/qtpropertybrowserutils.cpp index 16a67430a3cbae11e3245bac960bb9db96c4b44a..d7a26b140dac44d6eaeec8e6777ec27ed045ba24 100644 --- a/GUI/externals/qtpropertybrowser/qtpropertybrowserutils.cpp +++ b/GUI/externals/qtpropertybrowser/qtpropertybrowserutils.cpp @@ -1,40 +1,32 @@ /**************************************************************************** ** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). ** Contact: http://www.qt-project.org/legal ** ** This file is part of the tools applications of the Qt Toolkit. ** -** $QT_BEGIN_LICENSE:LGPL$ +** $QT_BEGIN_LICENSE:LGPL21$ ** Commercial License Usage ** Licensees holding valid commercial Qt licenses may use this file in ** accordance with the commercial license agreement provided with the ** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information ** use the contact form at http://qt.digia.com/contact-us. ** ** GNU Lesser General Public License Usage ** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. ** ** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception +** rights. These rights are described in the Digia Qt LGPL Exception ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. ** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** ** $QT_END_LICENSE$ ** ****************************************************************************/ @@ -223,7 +215,7 @@ QString QtPropertyBrowserUtils::timeFormat() { QLocale loc; // ShortFormat is missing seconds on UNIX. - return loc.timeFormat(QLocale::LongFormat); + return loc.timeFormat(QLocale::LongFormat); } QString QtPropertyBrowserUtils::dateTimeFormat() @@ -301,152 +293,4 @@ void QtBoolEdit::mousePressEvent(QMouseEvent *event) } } - -QtKeySequenceEdit::QtKeySequenceEdit(QWidget *parent) - : QWidget(parent), m_num(0), m_lineEdit(new QLineEdit(this)) -{ - QHBoxLayout *layout = new QHBoxLayout(this); - layout->addWidget(m_lineEdit); - layout->setMargin(0); - m_lineEdit->installEventFilter(this); - m_lineEdit->setReadOnly(true); - m_lineEdit->setFocusProxy(this); - setFocusPolicy(m_lineEdit->focusPolicy()); - setAttribute(Qt::WA_InputMethodEnabled); -} - -bool QtKeySequenceEdit::eventFilter(QObject *o, QEvent *e) -{ - if (o == m_lineEdit && e->type() == QEvent::ContextMenu) { - QContextMenuEvent *c = static_cast<QContextMenuEvent *>(e); - QMenu *menu = m_lineEdit->createStandardContextMenu(); - const QList<QAction *> actions = menu->actions(); - QListIterator<QAction *> itAction(actions); - while (itAction.hasNext()) { - QAction *action = itAction.next(); - action->setShortcut(QKeySequence()); - QString actionString = action->text(); - const int pos = actionString.lastIndexOf(QLatin1Char('\t')); - if (pos > 0) - actionString.remove(pos, actionString.length() - pos); - action->setText(actionString); - } - QAction *actionBefore = 0; - if (actions.count() > 0) - actionBefore = actions[0]; - QAction *clearAction = new QAction(tr("Clear Shortcut"), menu); - menu->insertAction(actionBefore, clearAction); - menu->insertSeparator(actionBefore); - clearAction->setEnabled(!m_keySequence.isEmpty()); - connect(clearAction, SIGNAL(triggered()), this, SLOT(slotClearShortcut())); - menu->exec(c->globalPos()); - delete menu; - e->accept(); - return true; - } - - return QWidget::eventFilter(o, e); -} - -void QtKeySequenceEdit::slotClearShortcut() -{ - if (m_keySequence.isEmpty()) - return; - setKeySequence(QKeySequence()); - emit keySequenceChanged(m_keySequence); -} - -void QtKeySequenceEdit::handleKeyEvent(QKeyEvent *e) -{ - int nextKey = e->key(); - if (nextKey == Qt::Key_Control || nextKey == Qt::Key_Shift || - nextKey == Qt::Key_Meta || nextKey == Qt::Key_Alt || - nextKey == Qt::Key_Super_L || nextKey == Qt::Key_AltGr) - return; - - nextKey |= translateModifiers(e->modifiers(), e->text()); - int k0 = m_keySequence[0]; - int k1 = m_keySequence[1]; - int k2 = m_keySequence[2]; - int k3 = m_keySequence[3]; - switch (m_num) { - case 0: k0 = nextKey; k1 = 0; k2 = 0; k3 = 0; break; - case 1: k1 = nextKey; k2 = 0; k3 = 0; break; - case 2: k2 = nextKey; k3 = 0; break; - case 3: k3 = nextKey; break; - default: break; - } - ++m_num; - if (m_num > 3) - m_num = 0; - m_keySequence = QKeySequence(k0, k1, k2, k3); - m_lineEdit->setText(m_keySequence.toString(QKeySequence::NativeText)); - e->accept(); - emit keySequenceChanged(m_keySequence); -} - -void QtKeySequenceEdit::setKeySequence(const QKeySequence &sequence) -{ - if (sequence == m_keySequence) - return; - m_num = 0; - m_keySequence = sequence; - m_lineEdit->setText(m_keySequence.toString(QKeySequence::NativeText)); -} - -QKeySequence QtKeySequenceEdit::keySequence() const -{ - return m_keySequence; -} - -int QtKeySequenceEdit::translateModifiers(Qt::KeyboardModifiers state, const QString &text) const -{ - int result = 0; - if ((state & Qt::ShiftModifier) && (text.size() == 0 || !text.at(0).isPrint() || text.at(0).isLetter() || text.at(0).isSpace())) - result |= Qt::SHIFT; - if (state & Qt::ControlModifier) - result |= Qt::CTRL; - if (state & Qt::MetaModifier) - result |= Qt::META; - if (state & Qt::AltModifier) - result |= Qt::ALT; - return result; -} - -void QtKeySequenceEdit::focusInEvent(QFocusEvent *e) -{ - m_lineEdit->event(e); - m_lineEdit->selectAll(); - QWidget::focusInEvent(e); -} - -void QtKeySequenceEdit::focusOutEvent(QFocusEvent *e) -{ - m_num = 0; - m_lineEdit->event(e); - QWidget::focusOutEvent(e); -} - -void QtKeySequenceEdit::keyPressEvent(QKeyEvent *e) -{ - handleKeyEvent(e); - e->accept(); -} - -void QtKeySequenceEdit::keyReleaseEvent(QKeyEvent *e) -{ - m_lineEdit->event(e); -} - -bool QtKeySequenceEdit::event(QEvent *e) -{ - if (e->type() == QEvent::Shortcut || - e->type() == QEvent::ShortcutOverride || - e->type() == QEvent::KeyRelease) { - e->accept(); - return true; - } - return QWidget::event(e); -} - QT_END_NAMESPACE diff --git a/GUI/externals/qtpropertybrowser/qtpropertybrowserutils_p.h b/GUI/externals/qtpropertybrowser/qtpropertybrowserutils_p.h index c55c6ecbe9d087517b8af9be0cbc201f5443f62f..5566f9a7a3b63bb923346caa59ccd7f6662c705f 100644 --- a/GUI/externals/qtpropertybrowser/qtpropertybrowserutils_p.h +++ b/GUI/externals/qtpropertybrowser/qtpropertybrowserutils_p.h @@ -1,40 +1,32 @@ /**************************************************************************** ** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). ** Contact: http://www.qt-project.org/legal ** ** This file is part of the tools applications of the Qt Toolkit. ** -** $QT_BEGIN_LICENSE:LGPL$ +** $QT_BEGIN_LICENSE:LGPL21$ ** Commercial License Usage ** Licensees holding valid commercial Qt licenses may use this file in ** accordance with the commercial license agreement provided with the ** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information ** use the contact form at http://qt.digia.com/contact-us. ** ** GNU Lesser General Public License Usage ** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. ** ** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception +** rights. These rights are described in the Digia Qt LGPL Exception ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. ** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** ** $QT_END_LICENSE$ ** ****************************************************************************/ @@ -127,35 +119,6 @@ private: bool m_textVisible; }; -class QtKeySequenceEdit : public QWidget -{ - Q_OBJECT -public: - QtKeySequenceEdit(QWidget *parent = 0); - - QKeySequence keySequence() const; - bool eventFilter(QObject *o, QEvent *e); -public Q_SLOTS: - void setKeySequence(const QKeySequence &sequence); -Q_SIGNALS: - void keySequenceChanged(const QKeySequence &sequence); -protected: - void focusInEvent(QFocusEvent *e); - void focusOutEvent(QFocusEvent *e); - void keyPressEvent(QKeyEvent *e); - void keyReleaseEvent(QKeyEvent *e); - bool event(QEvent *e); -private slots: - void slotClearShortcut(); -private: - void handleKeyEvent(QKeyEvent *e); - int translateModifiers(Qt::KeyboardModifiers state, const QString &text) const; - - int m_num; - QKeySequence m_keySequence; - QLineEdit *m_lineEdit; -}; - QT_END_NAMESPACE #endif diff --git a/GUI/externals/qtpropertybrowser/qtpropertymanager.cpp b/GUI/externals/qtpropertybrowser/qtpropertymanager.cpp index 73a43f0a4317cd6df4cf0fc6c7c7acfec1512a6e..2e88849e16d5d197de23c6e33983ae1f8374dcb6 100644 --- a/GUI/externals/qtpropertybrowser/qtpropertymanager.cpp +++ b/GUI/externals/qtpropertybrowser/qtpropertymanager.cpp @@ -1,40 +1,32 @@ /**************************************************************************** ** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). ** Contact: http://www.qt-project.org/legal ** ** This file is part of the tools applications of the Qt Toolkit. ** -** $QT_BEGIN_LICENSE:LGPL$ +** $QT_BEGIN_LICENSE:LGPL21$ ** Commercial License Usage ** Licensees holding valid commercial Qt licenses may use this file in ** accordance with the commercial license agreement provided with the ** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information ** use the contact form at http://qt.digia.com/contact-us. ** ** GNU Lesser General Public License Usage ** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. ** ** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception +** rights. These rights are described in the Digia Qt LGPL Exception ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. ** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** ** $QT_END_LICENSE$ ** ****************************************************************************/ @@ -880,7 +872,7 @@ public: struct Data { - Data() : val(0), minVal(-INT_MAX), maxVal(INT_MAX), singleStep(1), decimals(2) {} + Data() : val(0), minVal(-DBL_MAX), maxVal(DBL_MAX), singleStep(1), decimals(2) {} double val; double minVal; double maxVal; diff --git a/GUI/externals/qtpropertybrowser/qtpropertymanager.h b/GUI/externals/qtpropertybrowser/qtpropertymanager.h index 3b8edf10501f943f7208ce718d50eee513e95dac..cf4cb58dd3c0c517be77f6d737d2fc8728e7aaeb 100644 --- a/GUI/externals/qtpropertybrowser/qtpropertymanager.h +++ b/GUI/externals/qtpropertybrowser/qtpropertymanager.h @@ -1,40 +1,32 @@ /**************************************************************************** ** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). ** Contact: http://www.qt-project.org/legal ** ** This file is part of the tools applications of the Qt Toolkit. ** -** $QT_BEGIN_LICENSE:LGPL$ +** $QT_BEGIN_LICENSE:LGPL21$ ** Commercial License Usage ** Licensees holding valid commercial Qt licenses may use this file in ** accordance with the commercial license agreement provided with the ** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information ** use the contact form at http://qt.digia.com/contact-us. ** ** GNU Lesser General Public License Usage ** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. ** ** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception +** rights. These rights are described in the Digia Qt LGPL Exception ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. ** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** ** $QT_END_LICENSE$ ** ****************************************************************************/ diff --git a/GUI/externals/qtpropertybrowser/qttreepropertybrowser.cpp b/GUI/externals/qtpropertybrowser/qttreepropertybrowser.cpp index b93add1580cd4a0d111a91fc808ebaabeed0232c..d1dfc316d7bffaea05d994766f5beab16ebb4b7a 100644 --- a/GUI/externals/qtpropertybrowser/qttreepropertybrowser.cpp +++ b/GUI/externals/qtpropertybrowser/qttreepropertybrowser.cpp @@ -1,40 +1,32 @@ /**************************************************************************** ** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). ** Contact: http://www.qt-project.org/legal ** ** This file is part of the tools applications of the Qt Toolkit. ** -** $QT_BEGIN_LICENSE:LGPL$ +** $QT_BEGIN_LICENSE:LGPL21$ ** Commercial License Usage ** Licensees holding valid commercial Qt licenses may use this file in ** accordance with the commercial license agreement provided with the ** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information ** use the contact form at http://qt.digia.com/contact-us. ** ** GNU Lesser General Public License Usage ** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. ** ** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception +** rights. These rights are described in the Digia Qt LGPL Exception ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. ** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** ** $QT_END_LICENSE$ ** ****************************************************************************/ @@ -585,10 +577,10 @@ void QtTreePropertyBrowserPrivate::updateItem(QTreeWidgetItem *item) QtProperty *property = m_itemToIndex[item]->property(); QIcon expandIcon; if (property->hasValue()) { -// QString toolTip = property->toolTip(); -// if (toolTip.isEmpty()) -// toolTip = property->valueText(); -// item->setToolTip(1, toolTip); + QString toolTip = property->toolTip(); + if (toolTip.isEmpty()) + toolTip = property->valueText(); + item->setToolTip(1, toolTip); item->setIcon(1, property->valueIcon()); item->setText(1, property->valueText()); } else if (markPropertiesWithoutValue() && !m_treeWidget->rootIsDecorated()) { @@ -596,14 +588,7 @@ void QtTreePropertyBrowserPrivate::updateItem(QTreeWidgetItem *item) } item->setIcon(0, expandIcon); item->setFirstColumnSpanned(!property->hasValue()); - - // g.p. - QString toolTip = property->toolTip(); - if (toolTip.isEmpty()) { - item->setToolTip(0, property->propertyName()); - } else { - item->setToolTip(0, toolTip); - } + item->setToolTip(0, property->propertyName()); item->setStatusTip(0, property->statusTip()); item->setWhatsThis(0, property->whatsThis()); item->setText(0, property->propertyName()); diff --git a/GUI/externals/qtpropertybrowser/qttreepropertybrowser.h b/GUI/externals/qtpropertybrowser/qttreepropertybrowser.h index d403171c6995f254806ce9260c143159d3397c82..052a998c81fed03ceb6c5820d2e514471a77712e 100644 --- a/GUI/externals/qtpropertybrowser/qttreepropertybrowser.h +++ b/GUI/externals/qtpropertybrowser/qttreepropertybrowser.h @@ -1,40 +1,32 @@ /**************************************************************************** ** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). ** Contact: http://www.qt-project.org/legal ** ** This file is part of the tools applications of the Qt Toolkit. ** -** $QT_BEGIN_LICENSE:LGPL$ +** $QT_BEGIN_LICENSE:LGPL21$ ** Commercial License Usage ** Licensees holding valid commercial Qt licenses may use this file in ** accordance with the commercial license agreement provided with the ** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information ** use the contact form at http://qt.digia.com/contact-us. ** ** GNU Lesser General Public License Usage ** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. ** ** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception +** rights. These rights are described in the Digia Qt LGPL Exception ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. ** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** ** $QT_END_LICENSE$ ** ****************************************************************************/ diff --git a/GUI/externals/qtpropertybrowser/qtvariantproperty.cpp b/GUI/externals/qtpropertybrowser/qtvariantproperty.cpp index 445ba4932596251b2f1988afb3b88c588fca92e0..3056984a5e20937d738822febe5f9226faabbd3a 100644 --- a/GUI/externals/qtpropertybrowser/qtvariantproperty.cpp +++ b/GUI/externals/qtpropertybrowser/qtvariantproperty.cpp @@ -1,40 +1,32 @@ /**************************************************************************** ** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). ** Contact: http://www.qt-project.org/legal ** ** This file is part of the tools applications of the Qt Toolkit. ** -** $QT_BEGIN_LICENSE:LGPL$ +** $QT_BEGIN_LICENSE:LGPL21$ ** Commercial License Usage ** Licensees holding valid commercial Qt licenses may use this file in ** accordance with the commercial license agreement provided with the ** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information ** use the contact form at http://qt.digia.com/contact-us. ** ** GNU Lesser General Public License Usage ** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. ** ** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception +** rights. These rights are described in the Digia Qt LGPL Exception ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. ** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** ** $QT_END_LICENSE$ ** ****************************************************************************/ diff --git a/Tests/FunctionalTests/TestCore/IsGISAXS03BAsize/IsGISAXS03BAsize.cpp b/Tests/FunctionalTests/TestCore/BeamDivergence/BeamDivergence.cpp similarity index 76% rename from Tests/FunctionalTests/TestCore/IsGISAXS03BAsize/IsGISAXS03BAsize.cpp rename to Tests/FunctionalTests/TestCore/BeamDivergence/BeamDivergence.cpp index c7e0a0676ac2e44257f6cceefbc2c6747d2aba46..a48124bdc8409739b382d4cb5007cd6e4a330d92 100644 --- a/Tests/FunctionalTests/TestCore/IsGISAXS03BAsize/IsGISAXS03BAsize.cpp +++ b/Tests/FunctionalTests/TestCore/BeamDivergence/BeamDivergence.cpp @@ -4,5 +4,5 @@ int main(int argc, char **argv) { if(argc == 2) Utils::FileSystem::SetReferenceDataDir(argv[1]); - return FUNCTIONAL_TEST("isgisaxs03_basize"); + return FUNCTIONAL_TEST("beam_divergence"); } diff --git a/Tests/FunctionalTests/TestCore/CMakeLists.txt b/Tests/FunctionalTests/TestCore/CMakeLists.txt index 11f74a6958e0295c75667c996bc62f68ca1a8fab..e71d40779e20e8f28a320d04c4d5106e6d802b29 100644 --- a/Tests/FunctionalTests/TestCore/CMakeLists.txt +++ b/Tests/FunctionalTests/TestCore/CMakeLists.txt @@ -7,9 +7,9 @@ set(CMAKE_CXX_FLAGS "-DSTANDALONE") set(list_of_tests "IsGISAXS01" "IsGISAXS02" - "IsGISAXS03BA" - "IsGISAXS03DWBA" - "IsGISAXS03BAsize" + "CylindersInBA" + "CylindersInDWBA" + "CylindersWithSizeDistribution" "IsGISAXS041DDL" "IsGISAXS042DDL" "IsGISAXS06L1" @@ -32,6 +32,7 @@ set(list_of_tests "Ripple2" "Ripple1" "BatchSimulation" + "BeamDivergence" ) # for some reason these flags doesn't propagated here by SetUpWindows.cmake diff --git a/Tests/FunctionalTests/TestCore/IsGISAXS03BA/IsGISAXS03BA.cpp b/Tests/FunctionalTests/TestCore/CylindersInBA/CylindersInBA.cpp similarity index 78% rename from Tests/FunctionalTests/TestCore/IsGISAXS03BA/IsGISAXS03BA.cpp rename to Tests/FunctionalTests/TestCore/CylindersInBA/CylindersInBA.cpp index b96c38239374e770769b8c6a6a9e0015cb9471ab..47e063483afb1f9bbbe0dfa033b8ecb9ccbbfe11 100644 --- a/Tests/FunctionalTests/TestCore/IsGISAXS03BA/IsGISAXS03BA.cpp +++ b/Tests/FunctionalTests/TestCore/CylindersInBA/CylindersInBA.cpp @@ -4,5 +4,5 @@ int main(int argc, char **argv) { if(argc == 2) Utils::FileSystem::SetReferenceDataDir(argv[1]); - return FUNCTIONAL_TEST("isgisaxs03_ba"); + return FUNCTIONAL_TEST("cylinders_ba"); } diff --git a/Tests/FunctionalTests/TestCore/IsGISAXS03DWBA/IsGISAXS03DWBA.cpp b/Tests/FunctionalTests/TestCore/CylindersInDWBA/CylindersInDWBA.cpp similarity index 77% rename from Tests/FunctionalTests/TestCore/IsGISAXS03DWBA/IsGISAXS03DWBA.cpp rename to Tests/FunctionalTests/TestCore/CylindersInDWBA/CylindersInDWBA.cpp index 6799ddfd7d4446f7bda9aee22c6f5a90607e6c7f..85eb2b5708a8b377181da479cf406e391e2e461c 100644 --- a/Tests/FunctionalTests/TestCore/IsGISAXS03DWBA/IsGISAXS03DWBA.cpp +++ b/Tests/FunctionalTests/TestCore/CylindersInDWBA/CylindersInDWBA.cpp @@ -4,6 +4,6 @@ int main(int argc, char **argv) { if(argc == 2) Utils::FileSystem::SetReferenceDataDir(argv[1]); - return FUNCTIONAL_TEST("isgisaxs03_dwba"); + return FUNCTIONAL_TEST("cylinders_dwba"); } diff --git a/Tests/FunctionalTests/TestCore/CylindersWithSizeDistribution/CylindersWithSizeDistribution.cpp b/Tests/FunctionalTests/TestCore/CylindersWithSizeDistribution/CylindersWithSizeDistribution.cpp new file mode 100644 index 0000000000000000000000000000000000000000..0f196c4a5fbcdab9f4a0b433b7906a17ccc021f4 --- /dev/null +++ b/Tests/FunctionalTests/TestCore/CylindersWithSizeDistribution/CylindersWithSizeDistribution.cpp @@ -0,0 +1,8 @@ +#include "FunctionalTestRegistry.h" +#include "FileSystem.h" + +int main(int argc, char **argv) +{ + if(argc == 2) Utils::FileSystem::SetReferenceDataDir(argv[1]); + return FUNCTIONAL_TEST("cylinders_basize"); +} diff --git a/Tests/FunctionalTests/TestGUI/CMakeLists.txt b/Tests/FunctionalTests/TestGUI/CMakeLists.txt index b8e94ae6160b47bc83e823162d0cd80c52069e3c..e7dcac073fd121f9601bfccad14a15d6893c0941 100644 --- a/Tests/FunctionalTests/TestGUI/CMakeLists.txt +++ b/Tests/FunctionalTests/TestGUI/CMakeLists.txt @@ -17,6 +17,7 @@ set(list_of_tests "TestGUI05" "TestGUI06" "TestGUI07" + "TestGUIBeamDivergence" ) # for some reason these flags doesn't propagated here by SetUpWindows.cmake diff --git a/Tests/FunctionalTests/TestGUI/TestGUIBeamDivergence/TestGUIBeamDivergence.cpp b/Tests/FunctionalTests/TestGUI/TestGUIBeamDivergence/TestGUIBeamDivergence.cpp new file mode 100644 index 0000000000000000000000000000000000000000..92e15b1aa3883765f5fdd3e3960c00aae9d4e584 --- /dev/null +++ b/Tests/FunctionalTests/TestGUI/TestGUIBeamDivergence/TestGUIBeamDivergence.cpp @@ -0,0 +1,6 @@ +#include "GUIFunctionalTest.h" + +int main() +{ + return GUI_FUNCTIONAL_TEST("beam_divergence"); +} diff --git a/Tests/FunctionalTests/TestPyCore/CMakeLists.txt b/Tests/FunctionalTests/TestPyCore/CMakeLists.txt index 41af8e39c69b2fe4f338004e4186ea56a22a6911..dbe781bec2a8177bb56d32198a6f13a2b1d5bff6 100644 --- a/Tests/FunctionalTests/TestPyCore/CMakeLists.txt +++ b/Tests/FunctionalTests/TestPyCore/CMakeLists.txt @@ -10,7 +10,7 @@ set(list_of_tests "isgisaxs01.py" "isgisaxs01_normalize.py" "isgisaxs02.py" - "isgisaxs03.py" + "cylinders_ba_dwba_size.py" "isgisaxs04.py" "isgisaxs06.py" "isgisaxs07.py" @@ -28,6 +28,7 @@ set(list_of_tests "ripple1.py" "customformfactor.py" "montecarlo_integration.py" + "beam_divergence.py" ) set(list_of_cpp_python_tests diff --git a/Tests/FunctionalTests/TestPyCore/beam_divergence.py b/Tests/FunctionalTests/TestPyCore/beam_divergence.py new file mode 100644 index 0000000000000000000000000000000000000000..b364752cce028e9df1e3f64c9a54565656e1eceb --- /dev/null +++ b/Tests/FunctionalTests/TestPyCore/beam_divergence.py @@ -0,0 +1,79 @@ +# Cylinders in DWBA with beam divergence +import sys +import os +import numpy +from utils import get_reference_data + +sys.path.append(os.path.abspath( + os.path.join(os.path.split(__file__)[0], + '..', '..', '..', 'lib'))) + +from libBornAgainCore import * + +phi_min, phi_max = -0.2, 1.8 +alpha_min, alpha_max = 0.0, 2.2 + +def RunSimulation(): + """ + describe sample and run simulation + """ + # defining materials + m_ambience = HomogeneousMaterial("Air", 0.0, 0.0) + m_substrate = HomogeneousMaterial("Substrate", 6e-6, 2e-8) + m_particle = HomogeneousMaterial("Particle", 6e-4, 2e-8) + + # collection of particles + cylinder_ff = FormFactorCylinder(5*nanometer, 5*nanometer) + cylinder = Particle(m_particle, cylinder_ff) + particle_layout = ParticleLayout() + particle_layout.addParticle(cylinder, 0.0, 1.0) + + # assembling the sample + air_layer = Layer(m_ambience) + air_layer.addLayout(particle_layout) + substrate_layer = Layer(m_substrate) + + multi_layer = MultiLayer() + multi_layer.addLayer(air_layer) + multi_layer.addLayer(substrate_layer) + + # build simulation + simulation = Simulation() + simulation.setDetectorParameters(40, phi_min*degree, phi_max*degree, 60, alpha_min*degree, alpha_max*degree) + simulation.setBeamParameters(1.0*angstrom, 0.2*degree, 0.0*degree) + wavelength_distr = DistributionLogNormal(1.0*angstrom, 0.1) + alpha_distr = DistributionGaussian(-0.2*degree, 0.1*degree) + #phi_distr = DistributionGaussian(0.0*degree, 0.1*degree) + phi_distr = DistributionGate(-0.1*degree, 0.1*degree) + simulation.addParameterDistribution("*/Beam/wavelength", wavelength_distr, 5) + simulation.addParameterDistribution("*/Beam/alpha", alpha_distr, 4) + simulation.addParameterDistribution("*/Beam/phi", phi_distr, 3) + simulation.setSample(multi_layer) + + # run simulation and retrieve results + simulation.runSimulation() + return simulation.getIntensityData() + + +def runTest(): + """ + run test and analyse test results + """ + result = RunSimulation() + + diff = IntensityDataFunctions.getRelativeDifference(result, get_reference_data("beamdivergence_reference.int.gz")) + + status = "OK" + if(diff > 2e-10 or numpy.isnan(diff)): + status = "FAILED" + return "beam_divergence", "Cylinder in DWBA with beam divergence", diff, status + + +if __name__ == '__main__': + name, description, diff, status = runTest() + print name, description, diff, status + if("FAILED" in status): + exit(1) + + + diff --git a/Tests/FunctionalTests/TestPyCore/isgisaxs03.py b/Tests/FunctionalTests/TestPyCore/cylinders_ba_dwba_size.py similarity index 98% rename from Tests/FunctionalTests/TestPyCore/isgisaxs03.py rename to Tests/FunctionalTests/TestPyCore/cylinders_ba_dwba_size.py index 75b1b49591f92117ea713ed918d8225e01ffb67f..b5421e797538d81ab934070adc9e412c931bad4f 100644 --- a/Tests/FunctionalTests/TestPyCore/isgisaxs03.py +++ b/Tests/FunctionalTests/TestPyCore/cylinders_ba_dwba_size.py @@ -137,7 +137,7 @@ def runTest(): status = "OK" if(diff > 2e-10 or numpy.isnan(diff)): status = "FAILED" - return "IsGISAXS03", "Cylinder formfactor in BA and DWBA", diff, status + return "Cylinders_BA_DWBA_SIZE", "Cylinder formfactor in BA and DWBA", diff, status if __name__ == '__main__': diff --git a/Tests/ReferenceData/BornAgain/beamdivergence_reference.int.gz b/Tests/ReferenceData/BornAgain/beamdivergence_reference.int.gz new file mode 100644 index 0000000000000000000000000000000000000000..18b9f55957e3516da73183e9a2ac83fb6e703f3c Binary files /dev/null and b/Tests/ReferenceData/BornAgain/beamdivergence_reference.int.gz differ diff --git a/Tests/UnitTests/TestCore/ParameterDistributionTest.h b/Tests/UnitTests/TestCore/ParameterDistributionTest.h new file mode 100644 index 0000000000000000000000000000000000000000..ce48dbff9a873c05eec2538c265615102048f292 --- /dev/null +++ b/Tests/UnitTests/TestCore/ParameterDistributionTest.h @@ -0,0 +1,80 @@ +#ifndef PARAMETERDISTRIBUTIONTEST_H +#define PARAMETERDISTRIBUTIONTEST_H + +#include "ParameterDistribution.h" +#include "Distributions.h" + +class ParameterDistributionTest : public ::testing::Test +{ +protected: + ParameterDistributionTest(){} + virtual ~ParameterDistributionTest(){} +}; + + +TEST_F(ParameterDistributionTest, InitialState) +{ + DistributionGate gate(1.0, 2.0); + std::string par_name("name"); + int nbr_samples(5); + double sigma_factor(2.0); + ParameterDistribution par(par_name, gate, nbr_samples, sigma_factor); + + EXPECT_EQ(par.getMainParameterName(), par_name); + EXPECT_EQ(par.getNbrSamples(), nbr_samples); + EXPECT_EQ(par.getSigmaFactor(), sigma_factor); + + const DistributionGate *gate2 = dynamic_cast<const DistributionGate *>(par.getDistribution()); + EXPECT_FALSE(gate2 == 0); + EXPECT_EQ(gate2->getMin(), gate.getMin()); + EXPECT_EQ(gate2->getMax(), gate.getMax()); + EXPECT_EQ(size_t(0), par.getLinkedParameterNames().size()); + + par.linkParameter("aaa").linkParameter("bbb"); + std::vector<std::string> linked = par.getLinkedParameterNames(); + EXPECT_EQ(linked[0], std::string("aaa")); + EXPECT_EQ(linked[1], std::string("bbb")); +} + +TEST_F(ParameterDistributionTest, AssignmentOperator) +{ + DistributionLogNormal lognormal(1.0, 2.0); + std::string par_name("name"); + int nbr_samples(2); + double sigma_factor(5.0); + ParameterDistribution par(par_name, lognormal, nbr_samples, sigma_factor); + par.linkParameter("aaa").linkParameter("bbb"); + + ParameterDistribution par2 = par; + + EXPECT_EQ(par2.getMainParameterName(), par.getMainParameterName()); + EXPECT_EQ(par2.getNbrSamples(), par.getNbrSamples()); + EXPECT_EQ(par2.getSigmaFactor(), par.getSigmaFactor()); + EXPECT_EQ(dynamic_cast<const DistributionLogNormal *>(par2.getDistribution())->getMean(), lognormal.getMean()); + EXPECT_EQ(dynamic_cast<const DistributionLogNormal *>(par2.getDistribution())->getMedian(), lognormal.getMedian()); + EXPECT_EQ(par2.getLinkedParameterNames()[0], par.getLinkedParameterNames()[0]); + EXPECT_EQ(par2.getLinkedParameterNames()[1], par.getLinkedParameterNames()[1]); +} + +TEST_F(ParameterDistributionTest, CopyConstructor) +{ + DistributionLorentz lorents(1.0, 2.0); + std::string par_name("name"); + int nbr_samples(2); + double sigma_factor(5.0); + ParameterDistribution par(par_name, lorents, nbr_samples, sigma_factor); + par.linkParameter("aaa").linkParameter("bbb"); + + ParameterDistribution par2(par); + + EXPECT_EQ(par2.getMainParameterName(), par.getMainParameterName()); + EXPECT_EQ(par2.getNbrSamples(), par.getNbrSamples()); + EXPECT_EQ(par2.getSigmaFactor(), par.getSigmaFactor()); + EXPECT_EQ(dynamic_cast<const DistributionLorentz *>(par2.getDistribution())->getMean(), lorents.getMean()); + EXPECT_EQ(dynamic_cast<const DistributionLorentz *>(par2.getDistribution())->getHWHM(), lorents.getHWHM()); + EXPECT_EQ(par2.getLinkedParameterNames()[0], par.getLinkedParameterNames()[0]); + EXPECT_EQ(par2.getLinkedParameterNames()[1], par.getLinkedParameterNames()[1]); +} + + +#endif diff --git a/Tests/UnitTests/TestCore/main.cpp b/Tests/UnitTests/TestCore/main.cpp index 976131d464821c3070967470bf0b6ae9ee95a814..2a18d47d2f221b8904c31fe0f5cbc78a46a1040a 100644 --- a/Tests/UnitTests/TestCore/main.cpp +++ b/Tests/UnitTests/TestCore/main.cpp @@ -43,6 +43,7 @@ #include "IntensityDataFunctionsTest.h" #include "SpecularSimulationTest.h" #include "ParticleCoreShellTest.h" +#include "ParameterDistributionTest.h" struct ErrorStreamRedirect { ErrorStreamRedirect( std::streambuf * new_buffer ) diff --git a/Tests/UnitTests/TestGUI/TestParaCrystalItems.h b/Tests/UnitTests/TestGUI/TestParaCrystalItems.h index 343d2a319877c60e911302b64f10e7734b91b683..fa9d978e6f96e13d8ab656adfb107721e1c03e57 100644 --- a/Tests/UnitTests/TestGUI/TestParaCrystalItems.h +++ b/Tests/UnitTests/TestGUI/TestParaCrystalItems.h @@ -49,7 +49,7 @@ inline void TestParaCrystalItems::test_Para1D_PDFGroupProperty() foreach(QString pdf_name, pdfs) { QSignalSpy spyItem(&item, SIGNAL(propertyChanged(QString))); - QSignalSpy spyPropertyItem(&item, SIGNAL(propertyItemChanged(QString))); + QSignalSpy spyPropertyItem(&item, SIGNAL(subItemChanged(QString))); ParameterizedItem *pdfItem = item.setGroupProperty(InterferenceFunctionRadialParaCrystalItem::P_PDF, pdf_name); QVERIFY(pdfItem); QCOMPARE(item.getSubItems().size(), 1); diff --git a/Tests/UnitTests/TestGUI/TestParameterizedItem.h b/Tests/UnitTests/TestGUI/TestParameterizedItem.h index 069dab6cc4869d4a5e303922382f7ea251466510..c91c6f23c70fd118d0d9e968dc564b1f0a52d532 100644 --- a/Tests/UnitTests/TestGUI/TestParameterizedItem.h +++ b/Tests/UnitTests/TestGUI/TestParameterizedItem.h @@ -4,12 +4,17 @@ #include <QtTest> #include "ParameterizedItem.h" +#include "GUIHelpers.h" +#include "verify_throw_macro.h" + + class TestParameterizedItem : public QObject { Q_OBJECT private slots: void test_ItemName(); + void test_registerProperty(); void test_SelectableGroupProperty(); }; @@ -24,15 +29,51 @@ inline void TestParameterizedItem::test_ItemName() QCOMPARE(item.getRegisteredProperty(ParameterizedItem::P_NAME).toString(), QString("NewName")); } -//const QString FormFactorGroup = "Form Factor"; -//const QString LayerRoughnessGroup = "Roughness"; -//const QString DetectorGroup = "Detector group"; -//const QString FTDistribution1DGroup = "PDF 1D"; -//const QString FTDistribution2DGroupA = "PDF 2D #1"; -//const QString FTDistribution2DGroupB = "PDF 2D #2"; -//const QString LatticeGroup = "Lattice_type"; +inline void TestParameterizedItem::test_registerProperty() +{ + ParameterizedItem item; + QString property_name("MyProperty"); + double value(1.0); + QSignalSpy spy(&item, SIGNAL(propertyChanged(QString))); + + // access non-existing property + QCOMPARE(false, item.isRegisteredProperty(property_name)); + QVERIFY_THROW(item.getRegisteredProperty(property_name), GUIHelpers::Error); + QVERIFY_THROW(item.setRegisteredProperty(property_name, value), GUIHelpers::Error); + + // registering new property + item.registerProperty(property_name, value); + QCOMPARE(true, item.isRegisteredProperty(property_name)); + QCOMPARE(spy.count(), 1); + QList<QVariant> arguments = spy.takeFirst(); + QCOMPARE(arguments.size(), 1); + QCOMPARE(arguments.at(0).toString(), property_name); + QCOMPARE(item.getRegisteredProperty(property_name).toDouble(), value); + QCOMPARE(spy.count(), 0); + + // setting property value + double new_value(2.0); + item.setRegisteredProperty(property_name, new_value); + QCOMPARE(spy.count(), 1); + arguments = spy.takeFirst(); + QCOMPARE(arguments.size(), 1); + QCOMPARE(arguments.at(0).toString(), property_name); + QCOMPARE(item.getRegisteredProperty(property_name).toDouble(), new_value); + // setting property value to wrong QVariant + QVERIFY_THROW(item.setRegisteredProperty(property_name, QString("aaa")), GUIHelpers::Error); + // attempt to register already existing property + QVERIFY_THROW(item.registerProperty(property_name, 1.0), GUIHelpers::Error); + + // remove registered property + item.removeRegisteredProperty(property_name); + QCOMPARE(spy.count(), 1); + arguments = spy.takeFirst(); + QCOMPARE(arguments.size(), 1); + QCOMPARE(arguments.at(0).toString(), property_name); + QVERIFY_THROW(item.getRegisteredProperty(property_name), GUIHelpers::Error); +} inline void TestParameterizedItem::test_SelectableGroupProperty() { diff --git a/Tests/UnitTests/TestGUI/verify_throw_macro.h b/Tests/UnitTests/TestGUI/verify_throw_macro.h new file mode 100644 index 0000000000000000000000000000000000000000..ceb3dbb9165a0d861cbe794211f435d82c90ffe6 --- /dev/null +++ b/Tests/UnitTests/TestGUI/verify_throw_macro.h @@ -0,0 +1,33 @@ +// ************************************************************************** // +// +// BornAgain: simulate and fit scattering at grazing incidence +// +//! @file coregui/Models/verify_throw_macro.h +//! @brief Defines macro to test exception throw +//! +//! @homepage http://www.bornagainproject.org +//! @license GNU General Public License v3 or higher (see COPYING) +//! @copyright Forschungszentrum Jülich GmbH 2015 +//! @authors Scientific Computing Group at MLZ Garching +//! @authors C. Durniak, M. Ganeva, G. Pospelov, W. Van Herck, J. Wuttke +// +// ************************************************************************** // + +#ifndef VERIFY_THROW_MACRO_H +#define VERIFY_THROW_MACRO_H + +#include <QTest> + +#define QVERIFY_THROW(expression, ExpectedExceptionType) \ +do \ +{ \ +bool caught_ = false; \ +try { expression; } \ +catch (ExpectedExceptionType const&) { caught_ = true; } \ +catch (...) {} \ +if (!QTest::qVerify(caught_, #expression ", " #ExpectedExceptionType, "", __FILE__, __LINE__))\ +return; \ +} while(0) + + +#endif