Commit 62b5a617 authored by Mathieu Tillet's avatar Mathieu Tillet
Browse files

Refactor XIntegration use in the instrument widget

The Xintegration widget, which control the integration scroll at the
bottom of the instrument view, should only appear when the workspace
needs it.

This was currently the case, but only if the instrument view was opened
with this workspace : changing the underlying workspace midway, as
intended by replaceWorkspace, was not managed.

Thus, the way the integration range is managed was changed to a more
concise and modular way, so that it is only hidden or shown when needed,
but exists in all cases.
parent 9a065365
......@@ -43,6 +43,8 @@ class QDragEnterEvent;
class QDropEvent;
class QStackedLayout;
class QSettings;
class QVBoxLayout;
class QHBoxLayout;
namespace MantidQt {
namespace MantidWidgets {
......@@ -164,7 +166,8 @@ public:
void addTab(const std::string &tabName);
void hideHelp();
InstrumentWidgetPickTab *getPickTab() { return m_pickTab; }
bool isIntegrable() const { return m_isIntegrable; }
/// Determine if the workspace requires an integration bar
bool isIntegrable();
signals:
void enableLighting(bool /*_t1*/);
......@@ -264,6 +267,9 @@ protected:
QString getSaveGroupingFilename();
/// add the selected tabs
void addSelectedTabs();
/// update integration widget visibility and range
void updateIntegrationWidget();
// GUI elements
QLabel *mInteractionInfo;
QTabWidget *mControlsTab;
......@@ -316,9 +322,6 @@ protected:
/// dict of selected tabs
std::vector<std::pair<std::string, bool>> m_stateOfTabs;
/// Is the workspace monochromatic ?
bool m_isIntegrable;
private:
/// ADS notification handlers
void preDeleteHandle(
......@@ -347,6 +350,7 @@ private:
bool m_wsReplace;
QPushButton *m_help;
QVBoxLayout *m_mainLayout;
};
} // namespace MantidWidgets
......
......@@ -126,7 +126,7 @@ InstrumentWidget::InstrumentWidget(const QString &wsName, QWidget *parent,
m_stateOfTabs(std::vector<std::pair<std::string, bool>>{}),
m_wsReplace(false), m_help(nullptr) {
setFocusPolicy(Qt::StrongFocus);
QVBoxLayout *mainLayout = new QVBoxLayout(this);
m_mainLayout = new QVBoxLayout(this);
auto *controlPanelLayout = new QSplitter(Qt::Horizontal);
// Add Tab control panel
......@@ -152,27 +152,15 @@ InstrumentWidget::InstrumentWidget(const QString &wsName, QWidget *parent,
controlPanelLayout->addWidget(aWidget);
mainLayout->addWidget(controlPanelLayout);
m_mainLayout->addWidget(controlPanelLayout);
m_instrumentActor.reset(
new InstrumentActor(m_workspaceName, autoscaling, scaleMin, scaleMax));
try {
size_t blockSize = m_instrumentActor->getWorkspace()->blocksize();
m_isIntegrable =
(blockSize > 1 ||
m_instrumentActor->getWorkspace()->id() == "EventWorkspace");
} catch (...) {
m_isIntegrable = true;
}
if (m_isIntegrable) {
m_xIntegration = new XIntegrationControl(this);
mainLayout->addWidget(m_xIntegration);
connect(m_xIntegration, SIGNAL(changed(double, double)), this,
SLOT(setIntegrationRange(double, double)));
}
m_xIntegration = new XIntegrationControl(this);
m_mainLayout->addWidget(m_xIntegration);
connect(m_xIntegration, SIGNAL(changed(double, double)), this,
SLOT(setIntegrationRange(double, double)));
// Set the mouse/keyboard operation info and help button
auto *infoLayout = new QHBoxLayout();
......@@ -184,7 +172,7 @@ InstrumentWidget::InstrumentWidget(const QString &wsName, QWidget *parent,
infoLayout->addWidget(m_help);
infoLayout->setStretchFactor(mInteractionInfo, 1);
infoLayout->setStretchFactor(m_help, 0);
mainLayout->addLayout(infoLayout);
m_mainLayout->addLayout(infoLayout);
QSettings settings;
settings.beginGroup(InstrumentWidgetSettingsGroup);
......@@ -307,12 +295,8 @@ void InstrumentWidget::init(bool resetGeometry, bool autoscaling,
new InstrumentActor(m_workspaceName, autoscaling, scaleMin, scaleMax));
}
if (m_isIntegrable) {
m_xIntegration->setTotalRange(m_instrumentActor->minBinValue(),
m_instrumentActor->maxBinValue());
m_xIntegration->setUnits(QString::fromStdString(
m_instrumentActor->getWorkspace()->getAxis(0)->unit()->caption()));
}
updateIntegrationWidget();
auto surface = getSurface();
if (resetGeometry || !surface) {
if (setDefaultView) {
......@@ -420,6 +404,21 @@ QString InstrumentWidget::getSaveFileName(const QString &title,
return filename;
}
/**
* @brief InstrumentWidget::isIntegrable
* Returns whether or not the workspace requires an integration bar.
*/
bool InstrumentWidget::isIntegrable() {
try {
size_t blockSize = m_instrumentActor->getWorkspace()->blocksize();
return (blockSize > 1 ||
m_instrumentActor->getWorkspace()->id() == "EventWorkspace");
} catch (...) {
return true;
}
}
/**
* Update the info text displayed at the bottom of the window.
*/
......@@ -595,11 +594,31 @@ void InstrumentWidget::replaceWorkspace(
surface->resetInstrumentActor(m_instrumentActor.get());
setupColorMap();
updateIntegrationWidget();
// change the title of the instrument window
nativeParentWidget()->setWindowTitle(
QString().fromStdString(newInstrumentWindowName));
}
/**
* Update the range of the integration widget, and show or hide it is needed
*/
void InstrumentWidget::updateIntegrationWidget() {
m_xIntegration->setTotalRange(m_instrumentActor->minBinValue(),
m_instrumentActor->maxBinValue());
m_xIntegration->setUnits(QString::fromStdString(
m_instrumentActor->getWorkspace()->getAxis(0)->unit()->caption()));
bool integrable = isIntegrable();
if (integrable) {
m_xIntegration->show();
} else {
m_xIntegration->hide();
}
}
/**
* Update the colormap on the render tab.
*/
......@@ -926,9 +945,7 @@ void InstrumentWidget::setIntegrationRange(double xmin, double xmax) {
* python.
*/
void InstrumentWidget::setBinRange(double xmin, double xmax) {
if (m_isIntegrable) {
m_xIntegration->setRange(xmin, xmax);
}
m_xIntegration->setRange(xmin, xmax);
}
/**
......@@ -1298,10 +1315,9 @@ void InstrumentWidget::createTabs(QSettings &settings) {
this, SLOT(executeAlgorithm(const QString &, const QString &)));
m_maskTab->loadSettings(settings);
if (m_isIntegrable) {
connect(m_xIntegration, SIGNAL(changed(double, double)), m_maskTab,
SLOT(changedIntegrationRange(double, double)));
}
connect(m_xIntegration, SIGNAL(changed(double, double)), m_maskTab,
SLOT(changedIntegrationRange(double, double)));
// Instrument tree controls
m_treeTab = new InstrumentWidgetTreeTab(this);
m_treeTab->loadSettings(settings);
......@@ -1544,12 +1560,8 @@ std::string InstrumentWidget::saveToProject() const {
tsv.writeLine("SurfaceType") << getSurfaceType();
tsv.writeSection("surface", getSurface()->saveToProject());
tsv.writeLine("CurrentTab") << getCurrentTab();
if (this->isIntegrable()) {
tsv.writeLine("EnergyTransfer")
<< m_xIntegration->getMinimum() << m_xIntegration->getMaximum() << true;
} else {
tsv.writeLine("EnergyTransfer") << -1 << -1 << false;
}
tsv.writeLine("EnergyTransfer")
<< m_xIntegration->getMinimum() << m_xIntegration->getMaximum();
// serialise widget subsections
tsv.writeSection("actor", m_instrumentActor->saveToProject());
......@@ -1613,7 +1625,7 @@ void InstrumentWidget::loadFromProject(const std::string &lines) {
if (tsv.selectLine("EnergyTransfer")) {
double min, max;
bool isIntegrable;
bool isIntegrable = true;
tsv >> min >> max >> isIntegrable;
if (isIntegrable) {
setBinRange(min, max);
......
......@@ -49,14 +49,10 @@ InstrumentWidgetEncoder::encode(const InstrumentWidget &obj,
map.insert(QString("currentTab"), QVariant(obj.getCurrentTab()));
QList<QVariant> energyTransferList;
if (obj.isIntegrable()) {
energyTransferList.append(QVariant(obj.m_xIntegration->getMinimum()));
energyTransferList.append(QVariant(obj.m_xIntegration->getMaximum()));
} else {
energyTransferList.append(QVariant(0));
energyTransferList.append(QVariant(1));
}
energyTransferList.append(QVariant(obj.isIntegrable()));
energyTransferList.append(QVariant(obj.m_xIntegration->getMinimum()));
energyTransferList.append(QVariant(obj.m_xIntegration->getMaximum()));
map.insert(QString("energyTransfer"), QVariant(energyTransferList));
map.insert(QString("surface"),
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment