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 <boost/optional.hpp>
21#include <set>
22
23namespace MantidQt {
24
25namespace API {
26
27//-------------------------------
28// MantidQt forward declarations
29//-------------------------------
30class AlgorithmDialog;
31class UserSubWindow;
32
41public:
44 // Override createUnwrapped to search through the alias list
45 UserSubWindow *createUnwrapped(const std::string &name) const override;
46
47 QSet<QString> categories(const QString &interfaceName) const;
48 QStringList keys() const;
49
50 BaseEncoder *findEncoder(QWidget *window);
51 BaseDecoder *findDecoder(const std::string &decodeString);
52
53 template <typename TYPE> void subscribe();
54 template <typename WindowType, typename EncoderType, typename DecoderType>
55 void subscribe(const std::string &decoderTag);
56
57protected:
58 // Unhide the inherited create method
59 using Mantid::Kernel::DynamicFactory<UserSubWindow>::createUnwrapped;
60
61private:
63
67 ~UserSubWindowFactoryImpl() override = default;
69 UserSubWindow *createFromAlias(const std::string &name) const;
70
72 template <typename TYPE> void saveAliasNames(const std::string &realName);
73
74private:
81
82 // QHash doesn't seem to support std::unique_ptr<> as a valueso a std::map is
83 // used instead
84 std::map<std::string, std::shared_ptr<Mantid::Kernel::AbstractInstantiator<BaseEncoder>>> m_encoders;
85 std::map<std::string, std::shared_ptr<Mantid::Kernel::AbstractInstantiator<BaseDecoder>>> m_decoders;
86};
87
88template <typename TYPE> void UserSubWindowFactoryImpl::subscribe() {
89 std::string realName = TYPE::name();
91 saveAliasNames<TYPE>(realName);
92
93 // Make a record of each interface's categories.
94 const QStringList categories = TYPE::categoryInfo().split(";", Qt::SkipEmptyParts);
95 QSet<QString> result;
96 foreach (const QString category, categories) { result.insert(category.trimmed()); }
97 m_categoryLookup[QString::fromStdString(realName)] = result;
98}
99
100template <typename WindowType, typename EncoderType, typename DecoderType>
101void UserSubWindowFactoryImpl::subscribe(const std::string &decoderTag) {
102 subscribe<WindowType>();
103 m_encoders.insert({WindowType::name(), std::make_shared<Mantid::Kernel::Instantiator<EncoderType, BaseEncoder>>()});
104 m_decoders.insert({decoderTag, std::make_shared<Mantid::Kernel::Instantiator<DecoderType, BaseDecoder>>()});
105}
106
111template <typename TYPE> void UserSubWindowFactoryImpl::saveAliasNames(const std::string &realName) {
112 std::set<std::string> aliases = TYPE::aliases();
113 for (const auto &alias_std_str : aliases) {
114 QString alias = QString::fromStdString(alias_std_str);
115 if (m_aliasLookup.contains(alias)) {
116 if (m_badAliases.contains(alias)) {
117 QList<std::string> names = m_badAliases.value(alias);
118 names.append(realName);
119 m_badAliases[alias] = names;
120 } else {
121 QList<std::string> names;
122 names.append(m_aliasLookup.value(alias));
123 names.append(realName);
124 m_badAliases.insert(alias, names);
125 }
126 continue;
127 }
128 m_aliasLookup.insert(alias, realName);
129 }
130}
131
134
135} // namespace API
136} // namespace MantidQt
137
138namespace Mantid {
139namespace Kernel {
142} // namespace Kernel
143} // namespace Mantid
#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.
QSet< QString > categories(const QString &interfaceName) const
Return the set of categories that the interface with the given name belongs to.
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...
Definition: UserSubWindow.h:70
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.
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...