Skip to content

Commit

Permalink
Implemented hiding of unrelevant parameter group in the dialog.
Browse files Browse the repository at this point in the history
Refs #7441
  • Loading branch information
arturbekasov committed Jul 22, 2013
1 parent 097b57e commit b5158e0
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,31 @@ Q_OBJECT
public:
/// Constructor
SmoothNeighboursDialog(QWidget* parent = 0);

protected:
/// Overridden to enable validators
void accept();

private slots:
/// Called when input workspace get changed
void inputWorkspaceChanged(const QString& pName);

private:
/// Initialise the layout
void initLayout();
/// Non rectangular detector group name
static const QString NON_UNIFORM_GROUP;
/// Rectangular detector group name
static const QString RECTANGULAR_GROUP;
/// Input workspace name
static const QString INPUT_WORKSPACE;

/// Parse the input
void parseInput();
/// Initialize the layout
void initLayout();

/// Widget for all the PropertyWidgets
AlgorithmPropertiesWidget* m_algPropertiesWidget;
AlgorithmPropertiesWidget* m_propertiesWidget;

/// Main layout for the dialog
QVBoxLayout* m_dialogLayout;
};

#endif
#endif
85 changes: 72 additions & 13 deletions Code/Mantid/MantidQt/CustomDialogs/src/SmoothNeighboursDialog.cpp
Original file line number Diff line number Diff line change
@@ -1,30 +1,89 @@
#include "MantidQtCustomDialogs/SmoothNeighboursDialog.h"

using Mantid::Geometry::Instrument;
using Mantid::API::MatrixWorkspace_sptr;

//Register the class with the factory
DECLARE_DIALOG(SmoothNeighboursDialog)


// As defined in algorithm. Make sure you change them in SmoothNeighbours.cpp as well.
const QString SmoothNeighboursDialog::NON_UNIFORM_GROUP = "NonUniform Detectors";
const QString SmoothNeighboursDialog::RECTANGULAR_GROUP = "Rectangular Detectors";
const QString SmoothNeighboursDialog::INPUT_WORKSPACE = "InputWorkspace";

SmoothNeighboursDialog::SmoothNeighboursDialog(QWidget* parent)
: AlgorithmDialog(parent)
{
}

void SmoothNeighboursDialog::initLayout()
{
// Set main layout
QVBoxLayout *dialog_layout = new QVBoxLayout();
setLayout(dialog_layout);
// Create main layout
m_dialogLayout = new QVBoxLayout();

this->setLayout(m_dialogLayout);

// Set to size which fits all the possible widget changes
this->resize(475, 545);

// Create yellow information box
this->addOptionalMessage(m_dialogLayout);

m_propertiesWidget = new AlgorithmPropertiesWidget(this);

m_propertiesWidget->setAlgorithm(this->getAlgorithm());

// Tie all the widgets to properties
for (auto it = m_propertiesWidget->m_propWidgets.begin(); it != m_propertiesWidget->m_propWidgets.end(); it++)
this->tie(it.value(), it.key());

m_propertiesWidget->hideOrDisableProperties();

PropertyWidget* inputWorkspaceWidget = m_propertiesWidget->m_propWidgets[INPUT_WORKSPACE];

connect(inputWorkspaceWidget, SIGNAL(valueChanged(const QString&)),
this, SLOT(inputWorkspaceChanged(const QString&)));

// Create and add widget with all the properties
m_algPropertiesWidget = new AlgorithmPropertiesWidget(this);
m_algPropertiesWidget->setAlgorithm(this->getAlgorithm());
m_algPropertiesWidget->hideOrDisableProperties();
dialog_layout->addWidget(m_algPropertiesWidget, 1);
m_dialogLayout->addWidget(m_propertiesWidget);

// Create and add the OK/Cancel/Help. buttons
dialog_layout->addLayout(this->createDefaultButtonLayout(), 0);
m_dialogLayout->addLayout(this->createDefaultButtonLayout());

// Explicitly call, to hide/show property group from the beginning
inputWorkspaceWidget->valueChangedSlot();
}

void SmoothNeighboursDialog::parseInput()
void SmoothNeighboursDialog::inputWorkspaceChanged(const QString& pName)
{
// TODO: implement
}
UNUSED_ARG(pName);

m_propertiesWidget->m_groupWidgets[RECTANGULAR_GROUP]->setVisible(false);
m_propertiesWidget->m_groupWidgets[NON_UNIFORM_GROUP]->setVisible(false);

// Workspace should have been set by PropertyWidget before emitting valueChanged
MatrixWorkspace_sptr workspace = this->getAlgorithm()->getProperty(INPUT_WORKSPACE.toStdString());

// If invalid workspace, do nothing
if(!workspace)
return;

Instrument::ContainsState containsRectDetectors = workspace->getInstrument()->containsRectDetectors();

QString groupToShow;

if(containsRectDetectors == Instrument::ContainsState::Full)
groupToShow = RECTANGULAR_GROUP;
else
groupToShow = NON_UNIFORM_GROUP;

m_propertiesWidget->m_groupWidgets[groupToShow]->setVisible(true);
}

void SmoothNeighboursDialog::accept()
{
AlgorithmDialog::accept();

// If got there, there were errors
for(auto it = m_errors.begin(); it != m_errors.end(); it++)
m_propertiesWidget->m_propWidgets[it.key()]->setError(it.value());
}

0 comments on commit b5158e0

Please sign in to comment.