Skip to content

Refactor UI widget generation (less generic, more explicit)

Goal is to simplify SessionItem/SessionModel structure.

Common practice in Qt applications is to define UI ( labels, tooltips, type of controls etc.) directly in widget classes. In BornAgain, this is done in the SessionItem derived classes. This should be changed.

Example:

The status quo of defining UI texts and to use a QComboBox on the UI is like this:

const QString tooltip_ambientmaterial =
"Define if the material used for Fresnel calculations should be the ambient layer "
"material or the average material of the layer and the particles it contains";

const QString SimulationOptionsItem::P_FRESNEL_MATERIAL_METHOD =
"Material for Fresnel calculations";


SimulationOptionsItem::SimulationOptionsItem() : SessionItem(M_TYPE)
{
    ComboProperty averageLayerMaterials;
    averageLayerMaterials << "Ambient Layer Material"
                          << "Average Layer Material";
    addProperty(P_FRESNEL_MATERIAL_METHOD, averageLayerMaterials.variant())
        ->setToolTip(tooltip_ambientmaterial);

The UI related stuff should be moved to the dedicated widget:

SimulationOptionsWidget::SimulationOptionsWidget(QWidget* parent)
{
    // ...
    m_materialCombo = new QComboBox;
    m_materialCombo->addItems({"Ambient Layer Material", "Average Layer Material"});
    m_materialCombo->setToolTip(
        "Define if the material used for Fresnel calculations should be the ambient layer "
        "material or the average material of the layer and the particles it contains");
    layout->addRow("Material for Fresnel calculations:", m_materialCombo);

The data item will only contain the data related code:

SimulationOptionsItem::SimulationOptionsItem() : SessionItem(M_TYPE)
{
    addProperty(P_FRESNEL_MATERIAL_METHOD, averageLayerMaterials.variant());

Edited by m.puchner