Mantid
Loading...
Searching...
No Matches
UserSubWindowFactory.h
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2019 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
7#pragma once
8
9//------------------------
10// Includes
11//------------------------
12#include "DllOption.h"
17#include <QHash>
18#include <QSetIterator>
19#include <QStringList>
20#include <set>
21
22namespace MantidQt {
23
24namespace API {
25
26//-------------------------------
27// MantidQt forward declarations
28//-------------------------------
29class AlgorithmDialog;
30class UserSubWindow;
31
40public:
43 // Override createUnwrapped to search through the alias list
44 UserSubWindow *createUnwrapped(const std::string &name) const override;
45
46 QSet<QString> categories(const QString &interfaceName) const;
47 QStringList keys() const;
48
49 BaseEncoder *findEncoder(QWidget *window);
50 BaseDecoder *findDecoder(const std::string &decodeString);
51
52 template <typename TYPE> void subscribe();
53 template <typename WindowType, typename EncoderType, typename DecoderType>
54 void subscribe(const std::string &decoderTag);
55
56protected:
57 // Unhide the inherited create method
58 using Mantid::Kernel::DynamicFactory<UserSubWindow>::createUnwrapped;
59
60private:
62
66 ~UserSubWindowFactoryImpl() override = default;
68 UserSubWindow *createFromAlias(const std::string &name) const;
69
71 template <typename TYPE> void saveAliasNames(const std::string &realName);
72
73private:
80
81 // QHash doesn't seem to support std::unique_ptr<> as a valueso a std::map is
82 // used instead
83 std::map<std::string, std::shared_ptr<Mantid::Kernel::AbstractInstantiator<BaseEncoder>>> m_encoders;
84 std::map<std::string, std::shared_ptr<Mantid::Kernel::AbstractInstantiator<BaseDecoder>>> m_decoders;
85};
86
87template <typename TYPE> void UserSubWindowFactoryImpl::subscribe() {
88 std::string realName = TYPE::name();
90 saveAliasNames<TYPE>(realName);
91
92 // Make a record of each interface's categories.
93 const QStringList interfaceCategories = TYPE::categoryInfo().split(";", Qt::SkipEmptyParts);
94 QSet<QString> result;
95 foreach (const QString &category, interfaceCategories) {
96 result.insert(category.trimmed());
97 }
98 m_categoryLookup[QString::fromStdString(realName)] = result;
99}
100
101template <typename WindowType, typename EncoderType, typename DecoderType>
102void UserSubWindowFactoryImpl::subscribe(const std::string &decoderTag) {
103 subscribe<WindowType>();
104 m_encoders.insert({WindowType::name(), std::make_shared<Mantid::Kernel::Instantiator<EncoderType, BaseEncoder>>()});
105 m_decoders.insert({decoderTag, std::make_shared<Mantid::Kernel::Instantiator<DecoderType, BaseDecoder>>()});
106}
107
112template <typename TYPE> void UserSubWindowFactoryImpl::saveAliasNames(const std::string &realName) {
113 std::set<std::string> aliases = TYPE::aliases();
114 for (const auto &alias_std_str : aliases) {
115 QString alias = QString::fromStdString(alias_std_str);
116 if (m_aliasLookup.contains(alias)) {
117 if (m_badAliases.contains(alias)) {
118 QList<std::string> names = m_badAliases.value(alias);
119 names.append(realName);
120 m_badAliases[alias] = names;
121 } else {
122 QList<std::string> names;
123 names.append(m_aliasLookup.value(alias));
124 names.append(realName);
125 m_badAliases.insert(alias, names);
126 }
127 continue;
128 }
129 m_aliasLookup.insert(alias, realName);
130 }
131}
132
135
136} // namespace API
137} // namespace MantidQt
138
139namespace Mantid {
140namespace Kernel {
143} // namespace Kernel
144} // namespace Mantid
std::string name
Definition Run.cpp:60
#define EXPORT_OPT_MANTIDQT_COMMON
Definition DllOption.h:15
#define EXTERN_MANTIDQT_COMMON
Definition DllOption.h:16
The UserSubWindowFactory is responsible for creating concrete instances of user interface classes.
std::map< std::string, std::shared_ptr< Mantid::Kernel::AbstractInstantiator< BaseEncoder > > > m_encoders
UserSubWindowFactoryImpl(const UserSubWindowFactoryImpl &)=delete
QHash< QString, QSet< QString > > m_categoryLookup
A map of interfaces to their categories.
~UserSubWindowFactoryImpl() override=default
Private Destructor.
QHash< QString, std::string > m_aliasLookup
A map of alias names to "real" names.
std::map< std::string, std::shared_ptr< Mantid::Kernel::AbstractInstantiator< BaseDecoder > > > m_decoders
UserSubWindowFactoryImpl & operator=(const UserSubWindowFactoryImpl &)=delete
void saveAliasNames(const std::string &realName)
Save the list of aliases.
QHash< QString, QList< std::string > > m_badAliases
An index of multiply defined aliases.
This is the base class all customised user interfaces that do not wish to be tied to a specific Manti...
The dynamic factory is a base dynamic factory for serving up objects in response to requests from oth...
Manage the lifetime of a class intended to be a singleton.
Mantid::Kernel::SingletonHolder< UserSubWindowFactoryImpl > UserSubWindowFactory
The specific instantiation of the templated type.
The AlgorithmProgressDialogPresenter keeps track of the running algorithms and displays a progress ba...
Helper class which provides the Collimation Length for SANS instruments.
Policy class controlling creation of the singleton Implementation classes should mark their default c...