From 0302204b4c04466afc1b4474adf7546b0930c4ef Mon Sep 17 00:00:00 2001 From: Martyn Gigg <martyn.gigg@stfc.ac.uk> Date: Wed, 11 Aug 2010 07:54:44 +0000 Subject: [PATCH] Added an instrument selector widget and a designer plugin wrapper. Re #1400 --- .../CustomInterfaces/inc/ConvertToEnergy.ui | 34 +---- .../DesignerPlugins/DesignerPlugins.pro | 8 +- .../FileFinderPlugin.h | 14 -- .../InstrumentSelectorPlugin.h | 68 +++++++++ .../PluginCollectionInterface.h | 48 +++++++ .../DesignerPlugins/src/FileFinderPlugin.cpp | 2 - .../src/InstrumentSelectorPlugin.cpp | 131 ++++++++++++++++++ .../src/PluginCollectionInterface.cpp | 28 ++++ .../MantidQt/MantidWidgets/MantidWidgets.pro | 9 +- .../MantidWidgets/inc/InstrumentSelector.h | 61 ++++++++ .../MantidQt/MantidWidgets/inc/MantidWidget.h | 8 -- .../MantidWidgets/inc/WidgetDllOption.h | 14 +- .../MantidWidgets/src/InstrumentSelector.cpp | 81 +++++++++++ 13 files changed, 438 insertions(+), 68 deletions(-) create mode 100644 Code/qtiplot/MantidQt/DesignerPlugins/inc/MantidQtDesignerPlugins/InstrumentSelectorPlugin.h create mode 100644 Code/qtiplot/MantidQt/DesignerPlugins/inc/MantidQtDesignerPlugins/PluginCollectionInterface.h create mode 100644 Code/qtiplot/MantidQt/DesignerPlugins/src/InstrumentSelectorPlugin.cpp create mode 100644 Code/qtiplot/MantidQt/DesignerPlugins/src/PluginCollectionInterface.cpp create mode 100644 Code/qtiplot/MantidQt/MantidWidgets/inc/InstrumentSelector.h create mode 100644 Code/qtiplot/MantidQt/MantidWidgets/src/InstrumentSelector.cpp diff --git a/Code/qtiplot/MantidQt/CustomInterfaces/inc/ConvertToEnergy.ui b/Code/qtiplot/MantidQt/CustomInterfaces/inc/ConvertToEnergy.ui index 2c251416883..0a5e3f7e4a3 100644 --- a/Code/qtiplot/MantidQt/CustomInterfaces/inc/ConvertToEnergy.ui +++ b/Code/qtiplot/MantidQt/CustomInterfaces/inc/ConvertToEnergy.ui @@ -56,26 +56,7 @@ </widget> </item> <item> - <widget class="QComboBox" name="loadRun_cbInst" > - <property name="enabled" > - <bool>true</bool> - </property> - <property name="sizePolicy" > - <sizepolicy vsizetype="Fixed" hsizetype="Fixed" > - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - <property name="maximumSize" > - <size> - <width>100</width> - <height>16777215</height> - </size> - </property> - <property name="editable" > - <bool>true</bool> - </property> - </widget> + <widget class="MantidQt::MantidWidgets::InstrumentSelector" name="loadRun_cbInst" /> </item> <item> <spacer name="horizontalSpacer_3" > @@ -104,11 +85,7 @@ </widget> </item> <item> - <widget class="QComboBox" name="cbInst" > - <property name="toolTip" > - <string>Select instrument experiment(s) were run on.</string> - </property> - </widget> + <widget class="MantidQt::MantidWidgets::InstrumentSelector" name="cbInst" /> </item> <item> <widget class="QLabel" name="lbAnalyser" > @@ -2781,10 +2758,14 @@ p, li { white-space: pre-wrap; } <extends>QWidget</extends> <header>MantidQtMantidWidgets/MWRunFiles.h</header> </customwidget> + <customwidget> + <class>MantidQt::MantidWidgets::InstrumentSelector</class> + <extends>QComboBox</extends> + <header>MantidQtMantidWidgets/InstrumentSelector.h</header> + </customwidget> </customwidgets> <tabstops> <tabstop>tabWidget</tabstop> - <tabstop>loadRun_cbInst</tabstop> <tabstop>runFiles</tabstop> <tabstop>ckSumSpecs</tabstop> <tabstop>mapFile</tabstop> @@ -2840,7 +2821,6 @@ p, li { white-space: pre-wrap; } <tabstop>leCalibrationFile</tabstop> <tabstop>leRunFiles</tabstop> <tabstop>pbCalibrationFilesBrowse</tabstop> - <tabstop>cbInst</tabstop> <tabstop>ckRunDiag</tabstop> <tabstop>ckRunAbsol</tabstop> <tabstop>leDetailedBalance</tabstop> diff --git a/Code/qtiplot/MantidQt/DesignerPlugins/DesignerPlugins.pro b/Code/qtiplot/MantidQt/DesignerPlugins/DesignerPlugins.pro index 4222009d1e2..b9e664eb9c6 100644 --- a/Code/qtiplot/MantidQt/DesignerPlugins/DesignerPlugins.pro +++ b/Code/qtiplot/MantidQt/DesignerPlugins/DesignerPlugins.pro @@ -24,10 +24,14 @@ HEADERDIR = inc/MantidQtDesignerPlugins SRCDIR = src SOURCES = \ - $$SRCDIR/FileFinderPlugin.cpp + $$SRCDIR/PluginCollectionInterface.cpp\ + $$SRCDIR/FileFinderPlugin.cpp \ + $$SRCDIR/InstrumentSelectorPlugin.cpp HEADERS = \ - $$HEADERDIR/FileFinderPlugin.h + $$HEADERDIR/PluginCollectionInterface.h\ + $$HEADERDIR/FileFinderPlugin.h \ + $$HEADERDIR/InstrumentSelectorPlugin.h INCLUDEPATH += inc diff --git a/Code/qtiplot/MantidQt/DesignerPlugins/inc/MantidQtDesignerPlugins/FileFinderPlugin.h b/Code/qtiplot/MantidQt/DesignerPlugins/inc/MantidQtDesignerPlugins/FileFinderPlugin.h index 75c727b9119..0afbc84767f 100644 --- a/Code/qtiplot/MantidQt/DesignerPlugins/inc/MantidQtDesignerPlugins/FileFinderPlugin.h +++ b/Code/qtiplot/MantidQt/DesignerPlugins/inc/MantidQtDesignerPlugins/FileFinderPlugin.h @@ -2,20 +2,6 @@ #define FILEFINDERPLUGIN_H #include <QDesignerCustomWidgetInterface> -#include <QHash> -#include <QSet> - -namespace MantidQt -{ - - namespace MantidWidgets - { - //------------------------------------------- - // Forward declaration - //------------------------------------------- - class MWRunFiles; - } -} /** The FileFinderPlugin creates a Qt designer plugin of the FileFinder. diff --git a/Code/qtiplot/MantidQt/DesignerPlugins/inc/MantidQtDesignerPlugins/InstrumentSelectorPlugin.h b/Code/qtiplot/MantidQt/DesignerPlugins/inc/MantidQtDesignerPlugins/InstrumentSelectorPlugin.h new file mode 100644 index 00000000000..fdde9d8a608 --- /dev/null +++ b/Code/qtiplot/MantidQt/DesignerPlugins/inc/MantidQtDesignerPlugins/InstrumentSelectorPlugin.h @@ -0,0 +1,68 @@ +#ifndef INSTRUMENTSELETORPLUGIN_H +#define INSTRUMENTSELETORPLUGIN_H + +#include <QDesignerCustomWidgetInterface> + +/** +The InstrumentSelectorPlugin creates a Qt designer plugin out of the InstrumentSelector widget. + +@author Martyn Gigg, Tessella plc +@date 10/08/2009 + +Copyright © 2010 ISIS Rutherford Appleton Laboratory & NScD Oak Ridge National Laboratory + +This file is part of Mantid. + +Mantid is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 3 of the License, or +(at your option) any later version. + +Mantid is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see <http://www.gnu.org/licenses/>. + +File change history is stored at: <https://svn.mantidproject.org/mantid/trunk/Code/Mantid> +*/ +class InstrumentSelectorPlugin : public QObject, public QDesignerCustomWidgetInterface +{ + Q_OBJECT + Q_INTERFACES(QDesignerCustomWidgetInterface) + +public: + /// Default constructor + InstrumentSelectorPlugin(QObject *parent = 0); + /// Initialize the plugin + void initialize(QDesignerFormEditorInterface *core); + /// Returns a pointer to a newly constructed widget for this plugin wraps + QWidget *createWidget(QWidget *parent); + /// Returns if the plugin is initliaized + bool isInitialized() const; + /// Returns if this plugins is able to contain other widgets + bool isContainer() const; + /// Returns the fully-qualified class name + QString name() const; + /// Returns the group name within the designer + QString group() const; + /// Returns the icon to use + QIcon icon() const; + /// Returns a tool tip for the widget + QString toolTip() const; + /// Returns a short description of the widget + QString whatsThis() const; + /// Returns the include file that appears at the top of the generated .h file + QString includeFile() const; + /// Returns the XML that defines the widget and its properties + QString domXml() const; + +private: + /// Are we initialized? + bool m_initialized; +}; + + +#endif //MANTIDQT_DESIGNERPLUGINS_INSTRUMENTSELETORPLUGIN_H \ No newline at end of file diff --git a/Code/qtiplot/MantidQt/DesignerPlugins/inc/MantidQtDesignerPlugins/PluginCollectionInterface.h b/Code/qtiplot/MantidQt/DesignerPlugins/inc/MantidQtDesignerPlugins/PluginCollectionInterface.h new file mode 100644 index 00000000000..f5bb52b139e --- /dev/null +++ b/Code/qtiplot/MantidQt/DesignerPlugins/inc/MantidQtDesignerPlugins/PluginCollectionInterface.h @@ -0,0 +1,48 @@ +#ifndef PLUGINCOLLECTIONINTERFACE_H_ +#define PLUGINCOLLECTIONINTERFACE_H_ + +#include <QtDesigner> +#include <QtPlugin> + +/** +The PluginCollectionInterface implements the interface for the plugin library and holds a +list of plugins defined by the library. + +@author Martyn Gigg, Tessella plc +@date 10/08/2009 + +Copyright © 2010 ISIS Rutherford Appleton Laboratory & NScD Oak Ridge National Laboratory + +This file is part of Mantid. + +Mantid is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 3 of the License, or +(at your option) any later version. + +Mantid is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see <http://www.gnu.org/licenses/>. + +File change history is stored at: <https://svn.mantidproject.org/mantid/trunk/Code/Mantid> +*/ +class PluginCollectionInterface : public QObject, public QDesignerCustomWidgetCollectionInterface +{ + Q_OBJECT + Q_INTERFACES(QDesignerCustomWidgetCollectionInterface) + +public: + /// Default constructor + PluginCollectionInterface(QObject *parent = 0); + /// Returns a list of the custom widgets within this library + virtual QList<QDesignerCustomWidgetInterface*> customWidgets() const; + +private: + QList<QDesignerCustomWidgetInterface*> m_widgets; +}; + +#endif \ No newline at end of file diff --git a/Code/qtiplot/MantidQt/DesignerPlugins/src/FileFinderPlugin.cpp b/Code/qtiplot/MantidQt/DesignerPlugins/src/FileFinderPlugin.cpp index 660862978c7..5eac67d3c51 100644 --- a/Code/qtiplot/MantidQt/DesignerPlugins/src/FileFinderPlugin.cpp +++ b/Code/qtiplot/MantidQt/DesignerPlugins/src/FileFinderPlugin.cpp @@ -5,8 +5,6 @@ using namespace MantidQt::MantidWidgets; -Q_EXPORT_PLUGIN2(LIBRARY_NAME, FileFinderPlugin) - /** * Default constructor * @param parent The parent of the plugin (default: NULL) diff --git a/Code/qtiplot/MantidQt/DesignerPlugins/src/InstrumentSelectorPlugin.cpp b/Code/qtiplot/MantidQt/DesignerPlugins/src/InstrumentSelectorPlugin.cpp new file mode 100644 index 00000000000..44ff7f00518 --- /dev/null +++ b/Code/qtiplot/MantidQt/DesignerPlugins/src/InstrumentSelectorPlugin.cpp @@ -0,0 +1,131 @@ +//----------------------------------------------------------- +// Includes +//----------------------------------------------------------- +#include "MantidQtDesignerPlugins/InstrumentSelectorPlugin.h" +#include "MantidQtMantidWidgets/InstrumentSelector.h" + +#include <QDesignerFormEditorInterface> +#include <QtPlugin> + +using namespace MantidQt::MantidWidgets; + +/** + * Default constructor + * @param parent The parent of the plugin (default: NULL) + */ +InstrumentSelectorPlugin::InstrumentSelectorPlugin(QObject *parent) : QObject(parent), m_initialized(false) +{ +} + +/** + * Initialize the plugin + * @param formEditor A pointer to the interface that will control this plugin + */ +void InstrumentSelectorPlugin::initialize(QDesignerFormEditorInterface * formEditor) +{ + if (m_initialized) + { + return; + } + m_initialized = true; +} + +/** + * Create a widget of the type wrapped by the plugin + * @param parent The parent widget + * @returns A newly constructed widget for the wrapped type. + */ +QWidget *InstrumentSelectorPlugin::createWidget(QWidget *parent) +{ + return new InstrumentSelector(parent, false); +} + +/** +* Returns whether the plugin initialized or not +* @returns True if initialize() has been called, false otherwise +*/ +bool InstrumentSelectorPlugin::isInitialized() const +{ + return m_initialized; +} + +/** + * Returns whether this widget can contain other widgets + * @returns True if other widgets can be placed within this widget, false otherwise + */ +bool InstrumentSelectorPlugin::isContainer() const +{ + return false; +} + +/** + * Returns the class name of the widget that this plugin manages + * @returns A string containing the fully qualified class name of the widget + */ +QString InstrumentSelectorPlugin::name() const +{ + return "MantidQt::MantidWidgets::InstrumentSelector"; +} + +/** + * Returns the group within the designer that this plugin should be placed + * @returns The name of the group of widgets in the designer + */ +QString InstrumentSelectorPlugin::group() const +{ + return "MantidWidgets"; +} + +/** + * Returns the icon to display in the designer + * @returns An icon that is used within the designer + */ +QIcon InstrumentSelectorPlugin::icon() const +{ + return QIcon(); +} + +/** + * The tooltip for the widget + * @returns A string containing the tooltip for this widget + */ +QString InstrumentSelectorPlugin::toolTip() const +{ + return "Sets the current instrument within Mantid."; +} + +/** A short description of the widget + * @returns A string containing a short description of the widget + */ +QString InstrumentSelectorPlugin::whatsThis() const +{ + return "A instrument selector widget"; +} + +/** + * The include file to use when generating the header file + * @returns A string containing the path to the widget's header file + */ +QString InstrumentSelectorPlugin::includeFile() const +{ + return "MantidQtMantidWidgets/InstrumentSelector.h"; +} + +/** + * Returns the XML used to define the widget in the designer + * @returns A string containing the XML for the widget + */ +QString InstrumentSelectorPlugin::domXml() const +{ + return + "<widget class=\"MantidQt::MantidWidgets::InstrumentSelector\" name=\"instrSelector\">\n" + //" <property name=\"geometry\">\n" + //" <rect>\n" + //" <x>0</x>\n" + //" <y>0</y>\n" + //" <width>300</width>\n" + //" <height>20</height>\n" + //" </rect>\n" + //" </property>\n" + "</widget>\n"; +} diff --git a/Code/qtiplot/MantidQt/DesignerPlugins/src/PluginCollectionInterface.cpp b/Code/qtiplot/MantidQt/DesignerPlugins/src/PluginCollectionInterface.cpp new file mode 100644 index 00000000000..2bbd4d18fc0 --- /dev/null +++ b/Code/qtiplot/MantidQt/DesignerPlugins/src/PluginCollectionInterface.cpp @@ -0,0 +1,28 @@ +//------------------------------------------------------- +// Includes +//------------------------------------------------------- +#include "MantidQtDesignerPlugins/PluginCollectionInterface.h" + +#include "MantidQtDesignerPlugins/FileFinderPlugin.h" +#include "MantidQtDesignerPlugins/InstrumentSelectorPlugin.h" + +Q_EXPORT_PLUGIN2(LIBRARY_NAME, PluginCollectionInterface) + +/** + * Default constructor + * @param parent The parent widget + */ +PluginCollectionInterface::PluginCollectionInterface(QObject *parent) : QObject(parent) +{ + m_widgets.append(new FileFinderPlugin(this)); + m_widgets.append(new InstrumentSelectorPlugin(this)); +} + +/** + * Return the custom widgets exported by this library + * @param Returns a list of custom widget interfaces contained within this library + */ +QList<QDesignerCustomWidgetInterface*> PluginCollectionInterface::customWidgets() const +{ + return m_widgets; +} diff --git a/Code/qtiplot/MantidQt/MantidWidgets/MantidWidgets.pro b/Code/qtiplot/MantidQt/MantidWidgets/MantidWidgets.pro index da0fd395f80..01d6038d685 100644 --- a/Code/qtiplot/MantidQt/MantidWidgets/MantidWidgets.pro +++ b/Code/qtiplot/MantidQt/MantidWidgets/MantidWidgets.pro @@ -33,9 +33,9 @@ SOURCES = \ $$SRCDIR/SaveWorkspaces.cpp \ $$SRCDIR/ICatSearch.cpp \ $$SRCDIR/ICatInvestigation.cpp \ - $$SRCDIR/ICatMyDataSearch.cpp - - + $$SRCDIR/ICatMyDataSearch.cpp \ + $$SRCDIR/InstrumentSelector.cpp + HEADERS = \ $$HEADERDIR/MantidWidget.h \ $$HEADERDIR/MWRunFiles.h \ @@ -47,7 +47,8 @@ HEADERS = \ $$HEADERDIR/SaveWorkspaces.h \ $$HEADERDIR/ICatSearch.h \ $$HEADERDIR/ICatInvestigation.h \ - $$HEADERDIR/ICatMyDataSearch.h + $$HEADERDIR/ICatMyDataSearch.h \ + $$HEADERDIR/InstrumentSelector.h UI_DIR = $$HEADERDIR diff --git a/Code/qtiplot/MantidQt/MantidWidgets/inc/InstrumentSelector.h b/Code/qtiplot/MantidQt/MantidWidgets/inc/InstrumentSelector.h new file mode 100644 index 00000000000..9234023b852 --- /dev/null +++ b/Code/qtiplot/MantidQt/MantidWidgets/inc/InstrumentSelector.h @@ -0,0 +1,61 @@ +#ifndef MANTIDQTMANTIDWIDGETS_INSTRUMENTSELECTOR_H_ +#define MANTIDQTMANTIDWIDGETS_INSTRUMENTSELECTOR_H_ + +#include "WidgetDllOption.h" +#include <QComboBox> + +namespace MantidQt +{ + namespace MantidWidgets + { + /** + This class defines a widget for selecting an instrument known to Mantid + + @author Martyn Gigg, Tessella Support Services plc + @date 10/08/2010 + + Copyright © 2010 ISIS Rutherford Appleton Laboratory & NScD Oak Ridge National Laboratory + + This file is part of Mantid. + + Mantid is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + Mantid is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. + + File change history is stored at: <https://svn.mantidproject.org/mantid/trunk/Code/Mantid> + Code Documentation is available at: <http://doxygen.mantidproject.org> + */ + class EXPORT_OPT_MANTIDQT_MANTIDWIDGETS InstrumentSelector : public QComboBox + { + Q_OBJECT + + public: + /// Default Constructor + InstrumentSelector(QWidget *parent = NULL, bool init = true); + + public slots: + /// Update list for a new facility + void fillFromFacility(const QString & name = QString()); + + signals: + /// Indicate that the instrument selection has changed. The parameter will contain the new name + void instrumentSelectionChanged(const QString &); + + private slots: + /// Update Mantid's default instrument + void updateDefaultInstrument(const QString & name) const; + }; + + } +} + +#endif //MANTIDQTMANTIDWIDGETS_INSTRUMENTSELECTOR_H_ \ No newline at end of file diff --git a/Code/qtiplot/MantidQt/MantidWidgets/inc/MantidWidget.h b/Code/qtiplot/MantidQt/MantidWidgets/inc/MantidWidget.h index 255b6de9859..39213ce74b8 100644 --- a/Code/qtiplot/MantidQt/MantidWidgets/inc/MantidWidget.h +++ b/Code/qtiplot/MantidQt/MantidWidgets/inc/MantidWidget.h @@ -2,15 +2,7 @@ #define MANTIDQTMANTIDWIDGETS_MANTIDWIDGETS_H_ #include <QWidget> -#include "Poco/Path.h" #include "WidgetDllOption.h" -#include <QGroupBox> -#include <QGridLayout> -#include <QLabel> -#include <QString> -#include <QHash> -#include <string> -#include <map> /** The ase class from which mantid custom widgets are derived it contains * some useful functions diff --git a/Code/qtiplot/MantidQt/MantidWidgets/inc/WidgetDllOption.h b/Code/qtiplot/MantidQt/MantidWidgets/inc/WidgetDllOption.h index bd73dcb926d..6acc1a2621b 100644 --- a/Code/qtiplot/MantidQt/MantidWidgets/inc/WidgetDllOption.h +++ b/Code/qtiplot/MantidQt/MantidWidgets/inc/WidgetDllOption.h @@ -1,20 +1,12 @@ #ifndef MANTIDQT_MANTIDWIDGETS_DLLOPTION_H_ #define MANTIDQT_MANTIDWIDGETS_DLLOPTION_H_ -#ifndef DLLExport - #ifdef _WIN32 - #define DLLExport __declspec( dllexport ) - #define DLLImport __declspec( dllimport ) - #else - #define DLLExport - #define DLLImport - #endif -#endif +#include <MantidKernel/System.h> #ifdef IN_MANTIDQT_MANTIDWIDGETS #define EXPORT_OPT_MANTIDQT_MANTIDWIDGETS DLLExport #else #define EXPORT_OPT_MANTIDQT_MANTIDWIDGETS DLLImport -#endif /* IN_MANTIDQT_API */ +#endif /* IN_MANTIDQT_MANTIDWIDGETS */ -#endif //MANTIDQT_API_DLLOPTION_H_ \ No newline at end of file +#endif //MANTIDQT_MANTIDWIDGETS_DLLOPTION_H_ \ No newline at end of file diff --git a/Code/qtiplot/MantidQt/MantidWidgets/src/InstrumentSelector.cpp b/Code/qtiplot/MantidQt/MantidWidgets/src/InstrumentSelector.cpp new file mode 100644 index 00000000000..21a1f2448f4 --- /dev/null +++ b/Code/qtiplot/MantidQt/MantidWidgets/src/InstrumentSelector.cpp @@ -0,0 +1,81 @@ +//------------------------------------------------------ +// Includes +//------------------------------------------------------ +#include "MantidQtMantidWidgets/InstrumentSelector.h" +#include "MantidKernel/ConfigService.h" +#include "MantidKernel/FacilityInfo.h" + +namespace MantidQt +{ + namespace MantidWidgets + { + using namespace Mantid::Kernel; + + //------------------------------------------------------ + // Public member functions + //------------------------------------------------------ + + /** + * Default constructor + * @param parent A widget to act as this widget's parent (default = NULL) + * @param init If true then the widget will be populated with the instrument list (default = true) + */ + InstrumentSelector::InstrumentSelector(QWidget *parent, bool init) : QComboBox(parent) + { + if( init ) + { + fillFromFacility(); + connect(this, SIGNAL(currentIndexChanged(const QString &)), this, SLOT(updateDefaultInstrument(const QString &))); + connect(this, SIGNAL(currentIndexChanged(const QString &)), this, SIGNAL(instrumentSelectionChanged(const QString &))); + } + } + + //------------------------------------------------------ + // Public slot member functions + //------------------------------------------------------ + + /** + * Populate list with instruments from the named facility. Note the current list is cleared. + * @param name The name of the facility whose instruments should be placed in the list. An empty string uses the default + * facility defined in Mantid. + */ + void InstrumentSelector::fillFromFacility(const QString & name) + { + ConfigServiceImpl & mantidSettings = ConfigService::Instance(); + + clear(); + const std::vector<InstrumentInfo> & instruments = mantidSettings.Facility(name.toStdString()).Instruments(); + std::vector<InstrumentInfo>::const_iterator iend = instruments.end(); + for( std::vector<InstrumentInfo>::const_iterator itr = instruments.begin(); itr != iend; ++itr ) + { + QString name = QString::fromStdString(itr->name()); + QString shortName = QString::fromStdString(itr->shortName()); + this->addItem(name, QVariant(shortName)); + } + + // Set the correct default + QString defaultName = QString::fromStdString(mantidSettings.Facility().Instrument().name()); + int index = this->findText(defaultName); + if( index >= 0 ) + { + this->setCurrentIndex(index); + } + } + + //------------------------------------------------------ + // Privte slot member functions + //------------------------------------------------------ + /** + * Set the named instrument as the default for Mantid + * @param name A string containing the new instrument to set as the default + */ + void InstrumentSelector::updateDefaultInstrument(const QString & name) const + { + if( !name.isEmpty() ) + { + ConfigService::Instance().setString("default.instrument", name.toStdString()); + } + } + + } +} \ No newline at end of file -- GitLab