Skip to content

Commit

Permalink
refs #8992. Problem fixed.
Browse files Browse the repository at this point in the history
Although, I'd like to do some more refactoring to neaten things up before hand.
  • Loading branch information
OwenArnold committed Feb 21, 2014
1 parent b65e614 commit e6789be
Show file tree
Hide file tree
Showing 3 changed files with 116 additions and 41 deletions.
Expand Up @@ -57,6 +57,8 @@ protected slots:

void onRebuildDimensions();

void onCalculateChanged(bool checked);

private:

enum History{Remember, Forget};
Expand Down Expand Up @@ -95,6 +97,13 @@ protected slots:

/// Give base classes the opportunity to do any custom overriding.
virtual void customiseInitLayout() = 0;

/// Load settings
void loadSettings();

/// Save settings
void saveSettings();

};

/*
Expand Down Expand Up @@ -131,4 +140,4 @@ class BinMDDialog : public SlicingAlgorithmDialog
}
}

#endif
#endif
Expand Up @@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>372</width>
<height>540</height>
<width>386</width>
<height>660</height>
</rect>
</property>
<property name="windowTitle">
Expand Down Expand Up @@ -57,6 +57,33 @@
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="extents_layout">
<item>
<widget class="QPushButton" name="btn_calculate">
<property name="toolTip">
<string>Calculate axis-aligned extents from the workspace dimension limits</string>
</property>
<property name="text">
<string>Calculate Extents</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="ck_calculate">
<property name="enabled">
<bool>true</bool>
</property>
<property name="toolTip">
<string>Always calculate axis-aligned extents from the workspace dimension limits</string>
</property>
<property name="text">
<string>Always Calculate Extents</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QGroupBox" name="axis_aligned_layout">
<property name="title">
Expand Down Expand Up @@ -388,16 +415,6 @@
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="btn_rebuild_dimensions">
<property name="toolTip">
<string>Force the dimension inputs to be rebuilt to mirror values in the input workspace.</string>
</property>
<property name="text">
<string>Refresh Dims</string>
</property>
</widget>
</item>
<item>
<widget class="QDialogButtonBox" name="controls">
<property name="orientation">
Expand Down
105 changes: 77 additions & 28 deletions Code/Mantid/MantidQt/CustomDialogs/src/SlicingAlgorithmDialog.cpp
Expand Up @@ -7,6 +7,7 @@
#include <QIntValidator>
#include <QFileDialog>
#include <QDir>
#include <QSettings>

using namespace Mantid::API;
using namespace Mantid::Geometry;
Expand All @@ -33,6 +34,8 @@ namespace MantidQt
ui.setupUi(this);
this->setWindowTitle(m_algName);

loadSettings();

//Tie core widgets to core properties.
tie(ui.workspace_selector, "InputWorkspace", ui.input_layout);
tie(ui.ck_axis_aligned, "AxisAligned");
Expand All @@ -51,9 +54,10 @@ namespace MantidQt
connect(ui.controls, SIGNAL(rejected()), this, SLOT(reject()));
connect(ui.ck_axis_aligned, SIGNAL(clicked(bool)), this, SLOT(onAxisAlignedChanged(bool)));
connect(ui.ck_max_from_input, SIGNAL(clicked(bool)), this, SLOT(onMaxFromInput(bool)));
connect(ui.ck_calculate, SIGNAL(clicked(bool)), this, SLOT(onCalculateChanged(bool)));
connect(ui.btn_browse, SIGNAL(clicked()), this, SLOT(onBrowse()));
connect(ui.btn_help, SIGNAL(clicked()), this, SLOT(helpClicked()));
connect(ui.btn_rebuild_dimensions, SIGNAL(clicked()), this, SLOT(onRebuildDimensions()));
connect(ui.btn_calculate, SIGNAL(clicked()), this, SLOT(onRebuildDimensions()));

//Configure workspace selector
ui.workspace_selector->setValidatingAlgorithm(m_algName);
Expand Down Expand Up @@ -82,12 +86,13 @@ namespace MantidQt
customiseInitLayout();

//Dynamically create the input dimensions.
buildDimensionInputs();
buildDimensionInputs(ui.ck_calculate->isChecked());
}

/// Destructor
SlicingAlgorithmDialog::~SlicingAlgorithmDialog()
{
saveSettings();
}

/**
Expand Down Expand Up @@ -120,7 +125,7 @@ namespace MantidQt
//Deliberately return an empty string here, because it's not obveious how the basis vectors could be automatically formed.
return QString("");
}

/**
Clears the layout of any qwidget
@param layout : layout to clean
Expand Down Expand Up @@ -192,24 +197,30 @@ namespace MantidQt
}

/**
Determine if properties relating to the dimension history have changed.
Determine if properties relating to the dimension history have changed.
@return True if it has changed.
*/
SlicingAlgorithmDialog::HistoryChanged SlicingAlgorithmDialog::hasDimensionHistoryChanged() const
{
SlicingAlgorithmDialog::HistoryChanged result = HasNotChanged;

const QString& currentWorkspaceName = getCurrentInputWorkspaceName();
const QString previousInputWorkspaceName = MantidQt::API::AlgorithmInputHistory::Instance().previousInput(m_algName, "InputWorkspace");
if(currentWorkspaceName.isEmpty())
{
return HasChanged; //Force a rebuild because the dialog cant find any eligable input workspaces. That's why there is an empty entry.
result = HasChanged; //Force a rebuild because the dialog cant find any eligable input workspaces. That's why there is an empty entry.
}

QString previousInputWorkspaceName = MantidQt::API::AlgorithmInputHistory::Instance().previousInput(m_algName, "InputWorkspace");
if(previousInputWorkspaceName != currentWorkspaceName)
else if(AnalysisDataService::Instance().doesExist(previousInputWorkspaceName.toStdString()))
{
return HasChanged; //The input workspace has been switched, so rebuilding will be necessary.
const auto oldWS = AnalysisDataService::Instance().retrieveWS<IMDWorkspace>(previousInputWorkspaceName.toStdString());
const auto newWS = AnalysisDataService::Instance().retrieveWS<IMDWorkspace>(currentWorkspaceName.toStdString());
if(oldWS->getNumDims() != newWS->getNumDims())
{
result = HasChanged;
}
}

return HasNotChanged;
return result;
}

/*
Expand All @@ -226,7 +237,7 @@ namespace MantidQt
History history;
if(changedStatus == HasChanged || bForceForget)
{
history = Forget;
history = Forget;
}
else
{
Expand All @@ -251,31 +262,37 @@ namespace MantidQt
@param format: function pointer to the formatting function
@param history : Whether to remember of forget property history.
*/
void SlicingAlgorithmDialog::buildDimensionInputs(const QString& propertyPrefix, QLayout* owningLayout, QString(*format)(IMDDimension_const_sptr), History history)
void SlicingAlgorithmDialog::buildDimensionInputs(const QString& propertyPrefix,
QLayout* owningLayout, QString (*format)(IMDDimension_const_sptr), History history)
{

const QString& txt = getCurrentInputWorkspaceName();
if(!txt.isEmpty())
if (!txt.isEmpty())
{
IMDWorkspace_sptr ws = boost::dynamic_pointer_cast<IMDWorkspace>(AnalysisDataService::Instance().retrieve(txt.toStdString()));
IMDWorkspace_sptr ws = boost::dynamic_pointer_cast<IMDWorkspace>(
AnalysisDataService::Instance().retrieve(txt.toStdString()));

size_t nDimensions = ws->getNumDims();
for(size_t index = 0; index < nDimensions; ++index)

for (size_t index = 0; index < nDimensions; ++index)
{
Mantid::Geometry::IMDDimension_const_sptr dim = ws->getDimension(index);

// Create a widget to contain the dimension components.
QHBoxLayout* layout = new QHBoxLayout;
QWidget* w = new QWidget;
w->setLayout(layout);

// Configure the label
QString propertyName = propertyPrefix.copy().append(QString().number(index));
// Configure the label
const QString propertyName = propertyPrefix.copy().append(QString().number(index));

QLabel* dimensionLabel = new QLabel(propertyName);

// Configure the default input.
QString dimensioninfo = format(dim);
const QString dimensionInfo = format(dim);

QLineEdit* txtDimension = new QLineEdit(dimensionInfo);

// Create a widget to contain the dimension components.
QHBoxLayout* layout = new QHBoxLayout;
QWidget* w = new QWidget;
w->setLayout(layout);

QLineEdit* txtDimension = new QLineEdit(dimensioninfo);
tie(txtDimension, propertyName, layout, (history == Remember));

// Add components to the layout.
Expand All @@ -287,10 +304,36 @@ namespace MantidQt
}
}

/** Save settings for next time. */
void SlicingAlgorithmDialog::saveSettings()
{
QSettings settings;
settings.beginGroup("Mantid/SlicingAlgorithm");
settings.setValue("AlwaysCalculateExtents", (ui.ck_calculate->isChecked() ? 1 : 0));
settings.endGroup();
}

/**
* Load Settings
*/
void SlicingAlgorithmDialog::loadSettings()
{
QSettings settings;
settings.beginGroup("Mantid/SlicingAlgorithm");

const bool alwaysCalculateExtents = settings.value("AlwaysCalculateExtents", 1).toInt();
ui.ck_calculate->setChecked(alwaysCalculateExtents);

const QString alignedDimensions = settings.value("AlignedDimensions", "").toString();
const QString nonAlignedDimensions = settings.value("NonAlignedDimensions", "").toString();

settings.endGroup();
}

/// Event handler for the workspace changed event.
void SlicingAlgorithmDialog::onWorkspaceChanged()
{
buildDimensionInputs();
buildDimensionInputs(ui.ck_calculate->isChecked());
}

/**
Expand All @@ -299,11 +342,11 @@ namespace MantidQt
*/
void SlicingAlgorithmDialog::onAxisAlignedChanged(bool)
{
buildDimensionInputs();
buildDimensionInputs(ui.ck_calculate->isChecked());
}

/**
Event handler for changes so that recursion depth for the ouput workspace is either taken
Event handler for changes so that recursion depth for the ouput workspace is either taken
from the input workspace or from an external field.
*/
void SlicingAlgorithmDialog::onMaxFromInput(bool)
Expand All @@ -321,6 +364,12 @@ namespace MantidQt
buildDimensionInputs(true);
}

void SlicingAlgorithmDialog::onCalculateChanged(bool checked)
{
if(checked)
buildDimensionInputs(true);
}

/**
Handler for the onbrowse event.
*/
Expand Down

0 comments on commit e6789be

Please sign in to comment.