Mantid
Loading...
Searching...
No Matches
UserSubWindowFactory.cpp
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//-----------------------------------------------
8// Includes
9//-----------------------------------------------
11#include "MantidKernel/Logger.h"
13#include <sstream>
14
15using namespace MantidQt::API;
16
17namespace {
19Mantid::Kernel::Logger g_log("UserSubWindowFactoryImpl");
20} // namespace
21
22//*********************************************************
23// UserSubWindow
24//*********************************************************
25
26//----------------------------------------
27// Public member functions
28//----------------------------------------
29
36 // Try primary name as a start
37 UserSubWindow *window;
38 try {
41 g_log.debug() << "\"" << name << "\" not registered as a real name, trying an alias.\n";
42 window = nullptr;
43 }
44 if (!window) {
45 window = createFromAlias(name);
46 }
47 if (!window) {
48 g_log.error() << "UserSubWindowFactory: \"" + name + "\" is not registered as an interface name.\n";
49 throw Mantid::Kernel::Exception::NotFoundError("UserSubWindowFactory:" + name +
50 " is not registered or recognised as "
51 "an alias of a known interface.\n",
52 name);
53 }
54 return window;
55}
56
66QSet<QString> UserSubWindowFactoryImpl::categories(const QString &interfaceName) const {
67 if (!m_categoryLookup.contains(interfaceName))
68 return QSet<QString>();
69
70 return m_categoryLookup[interfaceName];
71}
72
73//----------------------------------------
74// Public member functions
75//----------------------------------------
76
78UserSubWindowFactoryImpl::UserSubWindowFactoryImpl() : m_aliasLookup(), m_badAliases(), m_encoders(), m_decoders() {}
79
87 QString alias = QString::fromStdString(name);
88 if (m_badAliases.contains(alias)) {
89 std::string error = "Alias \"" + name + "\" is defined for multiple real interfaces: \"";
90 QListIterator<std::string> itr(m_badAliases.value(alias));
91 while (itr.hasNext()) {
92 error += itr.next();
93 if (itr.hasNext()) {
94 error += ",";
95 }
96 }
97 g_log.error() << error + "\n";
98 return nullptr;
99 }
100
101 if (m_aliasLookup.contains(alias)) {
102 return this->createUnwrapped(m_aliasLookup.value(alias));
103 } else {
104 return nullptr;
105 }
106}
107
114 QStringList key_list;
115 const auto keys = getKeys();
116 for (const auto &key : keys) {
117 key_list.append(QString::fromStdString(key));
118 }
119 return key_list;
120}
121
130 auto subWindow = dynamic_cast<UserSubWindow *>(window);
131 if (subWindow) {
132 auto itemIt = m_encoders.find(subWindow->windowTitle().toStdString());
133 if (itemIt != m_encoders.end()) {
134 auto item = itemIt->second->createUnwrappedInstance();
135 return item;
136 }
137 }
138 return nullptr;
139}
140
148BaseDecoder *UserSubWindowFactoryImpl::findDecoder(const std::string &decodeString) {
149 auto itemIt = m_decoders.find(decodeString);
150 if (itemIt != m_decoders.end()) {
151 auto item = itemIt->second->createUnwrappedInstance();
152 return item;
153 }
154 return nullptr;
155}
double error
Definition: IndexPeaks.cpp:133
std::map< std::string, std::shared_ptr< Mantid::Kernel::AbstractInstantiator< BaseEncoder > > > m_encoders
UserSubWindowFactoryImpl()
Private Constructor for singleton class.
QHash< QString, QSet< QString > > m_categoryLookup
A map of interfaces to their categories.
BaseEncoder * findEncoder(QWidget *window)
Finds the Encoder for the given window and returns a raw pointer to it.
QHash< QString, std::string > m_aliasLookup
A map of alias names to "real" names.
QStringList keys() const
The keys associated with UserSubWindow classes.
BaseDecoder * findDecoder(const std::string &decodeString)
Finds the Decoder for the given window and returns a raw pointer to it.
std::map< std::string, std::shared_ptr< Mantid::Kernel::AbstractInstantiator< BaseDecoder > > > m_decoders
UserSubWindow * createFromAlias(const std::string &name) const
Try to create a sub window from the list of aliases for an interface.
QSet< QString > categories(const QString &interfaceName) const
Return the set of categories that the interface with the given name belongs to.
UserSubWindow * createUnwrapped(const std::string &name) const override
Create a raw pointer to the interface with the given name.
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
virtual Base * createUnwrapped(const std::string &className) const
Creates a new instance of the class with the given name, which is not wrapped in a boost shared_ptr.
virtual const std::vector< std::string > getKeys() const
Returns the keys in the map.
Exception for when an item is not found in a collection.
Definition: Exception.h:145
The Logger class is in charge of the publishing messages from the framework through various channels.
Definition: Logger.h:52
void debug(const std::string &msg)
Logs at debug level.
Definition: Logger.cpp:114
void error(const std::string &msg)
Logs at error level.
Definition: Logger.cpp:77
Kernel::Logger g_log("ExperimentInfo")
static logger object