Skip to content

Commit

Permalink
Added proper code for tab switching
Browse files Browse the repository at this point in the history
Refs #11158
  • Loading branch information
DanNixon committed Feb 25, 2015
1 parent fef932f commit 9f8920f
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 204 deletions.
Expand Up @@ -8,9 +8,10 @@

#include "MantidQtAPI/AlgorithmRunner.h"
#include "MantidQtAPI/UserSubWindow.h"
#include "MantidQtCustomInterfaces/Indirect/IndirectDataReductionTab.h"

#include <QScrollArea>

#include <qwt_plot.h>
#include <qwt_plot_curve.h>

namespace MantidQt
{
Expand Down Expand Up @@ -114,6 +115,32 @@ namespace MantidQt
/// Set and show an instrument-specific widget
virtual void closeEvent(QCloseEvent* close);

template <typename T>
void addTab(const QString & name)
{
QWidget * tabWidget = new QWidget(m_uiForm.twIDRTabs);
QVBoxLayout * tabLayout = new QVBoxLayout(tabWidget);
tabWidget->setLayout(tabLayout);

QScrollArea * tabScrollArea = new QScrollArea(tabWidget);
tabLayout->addWidget(tabScrollArea);
tabScrollArea->setWidgetResizable(true);

QWidget * tabContent = new QWidget(tabScrollArea);
tabScrollArea->setWidget(tabContent);
tabScrollArea->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);

IndirectDataReductionTab * tabIDRContent = new T(this, tabContent);
tabIDRContent->setupTab();
tabContent->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);

connect(tabIDRContent, SIGNAL(runAsPythonScript(const QString&, bool)), this, SIGNAL(runAsPythonScript(const QString&, bool)));
connect(tabIDRContent, SIGNAL(showMessageBox(const QString&)), this, SLOT(showMessageBox(const QString&)));
connect(tabIDRContent, SIGNAL(updateRunButton(bool, QString, QString)), this, SLOT(updateRunButton(bool, QString, QString)));

m_tabs[name] = qMakePair(tabWidget, tabIDRContent);
}

friend class IndirectDataReductionTab;
/// The .ui form generated by Qt Designer
Ui::IndirectDataReduction m_uiForm;
Expand All @@ -125,7 +152,7 @@ namespace MantidQt
MantidQt::API::AlgorithmRunner* m_algRunner;

// All indirect tabs
std::map<QString, IndirectDataReductionTab*> m_tabs;
QMap<QString, QPair<QWidget *, IndirectDataReductionTab *>> m_tabs;

/// Poco observer for changes in user directory settings
Poco::NObserver<IndirectDataReduction, Mantid::Kernel::ConfigValChangeNotification> m_changeObserver;
Expand Down
Expand Up @@ -61,182 +61,14 @@
</sizepolicy>
</property>
<property name="currentIndex">
<number>0</number>
<number>-1</number>
</property>
<property name="iconSize">
<size>
<width>14</width>
<height>14</height>
</size>
</property>
<widget class="QWidget" name="tabISISEnergyTransfer">
<attribute name="title">
<string>ISIS Energy Transfer</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QScrollArea" name="saISISEnergyTransfer">
<property name="widgetResizable">
<bool>true</bool>
</property>
<widget class="QWidget" name="loISISEnergyTransfer">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>656</width>
<height>446</height>
</rect>
</property>
</widget>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="tabISISCalibration">
<attribute name="title">
<string>ISIS Calibration</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QScrollArea" name="saISISCalibration">
<property name="widgetResizable">
<bool>true</bool>
</property>
<widget class="QWidget" name="loISISCalibration">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>96</width>
<height>26</height>
</rect>
</property>
</widget>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="tabISISDiagnostics">
<attribute name="title">
<string>ISIS Diagnostics</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="QScrollArea" name="saISISDiagnostics">
<property name="widgetResizable">
<bool>true</bool>
</property>
<widget class="QWidget" name="loISISDiagnostics">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>96</width>
<height>26</height>
</rect>
</property>
</widget>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="tabTransmission">
<attribute name="title">
<string>Transmission</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_4">
<item>
<widget class="QScrollArea" name="saTransmission">
<property name="widgetResizable">
<bool>true</bool>
</property>
<widget class="QWidget" name="loTransmission">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>96</width>
<height>26</height>
</rect>
</property>
</widget>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="tabSymmertrise">
<attribute name="title">
<string>Symmetrise</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_5">
<item>
<widget class="QScrollArea" name="saSymmetrise">
<property name="widgetResizable">
<bool>true</bool>
</property>
<widget class="QWidget" name="loSymmetrise">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>96</width>
<height>26</height>
</rect>
</property>
</widget>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="tabSofQW">
<attribute name="title">
<string>S(Q, w)</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_7">
<item>
<widget class="QScrollArea" name="saSofQW">
<property name="widgetResizable">
<bool>true</bool>
</property>
<widget class="QWidget" name="loSofQW">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>96</width>
<height>26</height>
</rect>
</property>
</widget>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="tabMoments">
<attribute name="title">
<string>Moments</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_6">
<item>
<widget class="QScrollArea" name="saMoments">
<property name="widgetResizable">
<bool>true</bool>
</property>
<widget class="QWidget" name="loMoments">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>96</width>
<height>26</height>
</rect>
</property>
</widget>
</widget>
</item>
</layout>
</widget>
</widget>
</item>
<item>
Expand Down
Expand Up @@ -10,7 +10,6 @@
#include "MantidQtAPI/QwtWorkspaceSpectrumData.h"
#include "MantidQtMantidWidgets/IndirectInstrumentConfig.h"
#include "IndirectTab.h"
#include "IndirectDataReduction.h"
#include "MantidQtMantidWidgets/RangeSelector.h"

#include <QDoubleValidator>
Expand Down Expand Up @@ -43,6 +42,8 @@ namespace MantidQt
{
namespace CustomInterfaces
{
class IndirectDataReduction;

/** IndirectDataReductionTab
This class defines common functionality of tabs used in the Indirect Data Reduction interface.
Expand Down
Expand Up @@ -9,7 +9,6 @@
#include "MantidKernel/ConfigService.h"
#include "MantidQtAPI/HelpWindow.h"
#include "MantidQtAPI/ManageUserDirectories.h"
#include "MantidQtCustomInterfaces/Indirect/IndirectDataReductionTab.h"
#include "MantidQtCustomInterfaces/Indirect/IndirectMoments.h"
#include "MantidQtCustomInterfaces/Indirect/IndirectSqw.h"
#include "MantidQtCustomInterfaces/Indirect/IndirectSymmetrise.h"
Expand Down Expand Up @@ -94,7 +93,7 @@ void IndirectDataReduction::helpClicked()
void IndirectDataReduction::exportTabPython()
{
QString tabName = m_uiForm.twIDRTabs->tabText(m_uiForm.twIDRTabs->currentIndex());
m_tabs[tabName]->exportPythonScript();
m_tabs[tabName].second->exportPythonScript();
}


Expand All @@ -105,7 +104,7 @@ void IndirectDataReduction::exportTabPython()
void IndirectDataReduction::runClicked()
{
QString tabName = m_uiForm.twIDRTabs->tabText(m_uiForm.twIDRTabs->currentIndex());
m_tabs[tabName]->runTab();
m_tabs[tabName].second->runTab();
}


Expand All @@ -120,13 +119,13 @@ void IndirectDataReduction::initLayout()
updateRunButton(false, "Loading UI", "Initialising user interface components...");

// Create the tabs
m_tabs["ISIS Energy Transfer"] = new ISISEnergyTransfer(this, m_uiForm.twIDRTabs->findChild<QWidget *>("loISISEnergyTransfer"));
m_tabs["ISIS Calibration"] = new ISISCalibration(this, m_uiForm.twIDRTabs->findChild<QWidget *>("loISISCalibration"));
m_tabs["ISIS Diagnostics"] = new ISISDiagnostics(this, m_uiForm.twIDRTabs->findChild<QWidget *>("loISISDiagnostics"));
m_tabs["Transmission"] = new IndirectTransmission(this, m_uiForm.twIDRTabs->findChild<QWidget *>("loTransmission"));
m_tabs["Symmetrise"] = new IndirectSymmetrise(this, m_uiForm.twIDRTabs->findChild<QWidget *>("loSymmetrise"));
m_tabs["S(Q, w)"] = new IndirectSqw(this, m_uiForm.twIDRTabs->findChild<QWidget *>("loSofQW"));
m_tabs["Moments"] = new IndirectMoments(this, m_uiForm.twIDRTabs->findChild<QWidget *>("loMoments"));
addTab<ISISEnergyTransfer>("ISIS Energy Transfer");
addTab<ISISCalibration>("ISIS Calibration");
addTab<ISISDiagnostics>("ISIS Diagnostics");
addTab<IndirectTransmission>("Transmission");
addTab<IndirectSymmetrise>("Symmetrise");
addTab<IndirectSqw>("S(Q, w)");
addTab<IndirectMoments>("Moments");

// Connect "?" (Help) Button
connect(m_uiForm.pbHelp, SIGNAL(clicked()), this, SLOT(helpClicked()));
Expand All @@ -140,16 +139,6 @@ void IndirectDataReduction::initLayout()
// Reset the Run button state when the tab is changed
connect(m_uiForm.twIDRTabs, SIGNAL(currentChanged(int)), this, SLOT(updateRunButton()));

// Connect tab signals and run any setup code
for(auto it = m_tabs.begin(); it != m_tabs.end(); ++it)
{
connect(it->second, SIGNAL(runAsPythonScript(const QString&, bool)), this, SIGNAL(runAsPythonScript(const QString&, bool)));
connect(it->second, SIGNAL(showMessageBox(const QString&)), this, SLOT(showMessageBox(const QString&)));
connect(it->second, SIGNAL(updateRunButton(bool, QString, QString)), this, SLOT(updateRunButton(bool, QString, QString)));
connect(this, SIGNAL(newInstrumentConfiguration()), it->second, SIGNAL(newInstrumentConfiguration())),
it->second->setupTab();
}

// Handle instrument configuration changes
connect(m_uiForm.iicInstrumentConfiguration, SIGNAL(instrumentConfigurationUpdated(const QString &, const QString &, const QString &)),
this, SLOT(instrumentSetupChanged(const QString &, const QString &, const QString &)));
Expand All @@ -159,6 +148,7 @@ void IndirectDataReduction::initLayout()

std::string facility = Mantid::Kernel::ConfigService::Instance().getString("default.facility");
filterUiForFacility(QString::fromStdString(facility));
emit newInstrumentConfiguration();
}


Expand Down Expand Up @@ -485,25 +475,42 @@ void IndirectDataReduction::filterUiForFacility(QString facility)

QStringList enabledTabs;

// These tabs work at any facility
enabledTabs << "Transmission" << "Symmetrise" << "S(Q, w)" << "Moments";

// add facility specific tabs
// Add facility specific tabs
if(facility == "ISIS")
enabledTabs << "ISIS Energy Transfer"
<< "ISIS Calibration"
<< "ISIS Diagnostics";

// Modify tabs as required
for(int i = 0; i < m_uiForm.twIDRTabs->count(); i++)
// These tabs work at any facility (always at end of tabs)
enabledTabs << "Transmission" << "Symmetrise" << "S(Q, w)" << "Moments";

// First remove all tabs
while(m_uiForm.twIDRTabs->count() > 0)
{
// Disconnect the instrument changed signal
QString tabName = m_uiForm.twIDRTabs->tabText(0);
disconnect(this, SIGNAL(newInstrumentConfiguration()),
m_tabs[tabName].second, SIGNAL(newInstrumentConfiguration()));

// Remove the tab
m_uiForm.twIDRTabs->removeTab(0);

g_log.debug() << "Removing tab " << tabName.toStdString()
<< std::endl;
}

// Add the required tabs
for(auto it = enabledTabs.begin(); it != enabledTabs.end(); ++it)
{
QString name = m_uiForm.twIDRTabs->tabText(i);
bool enabled = enabledTabs.contains(name);
// Connect the insturment changed signal
connect(this, SIGNAL(newInstrumentConfiguration()),
m_tabs[*it].second, SIGNAL(newInstrumentConfiguration()));

m_uiForm.twIDRTabs->setTabEnabled(i, enabled);
m_tabs[name]->blockSignals(!enabled);
// Add the tab
m_uiForm.twIDRTabs->addTab(m_tabs[*it].first, *it);

//TODO: handle instrument update connection
g_log.debug() << "Adding tab " << (*it).toStdString()
<< std::endl;
}
}

Expand Down
Expand Up @@ -2,6 +2,7 @@

#include "MantidAPI/AlgorithmManager.h"
#include "MantidKernel/Logger.h"
#include "MantidQtCustomInterfaces/Indirect/IndirectDataReduction.h"

using namespace Mantid::API;
using namespace Mantid::Geometry;
Expand Down

0 comments on commit 9f8920f

Please sign in to comment.