Mantid
Loading...
Searching...
No Matches
WorkspaceObserver.h
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2007 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#include "DllOption.h"
12#include <Poco/NObserver.h>
13#include <QMetaType>
14#include <QObject>
15
16Q_DECLARE_METATYPE(std::string)
17Q_DECLARE_METATYPE(Mantid::API::Workspace_sptr)
18
19//------------------------------------------------
20// Mantid Forward declaration
21//------------------------------------------------
22
23namespace MantidQt {
24namespace API {
25//------------------------------------------------
26// Forward declaration
27//------------------------------------------------
28class WorkspaceObserver;
29
45 Q_OBJECT
46
47public:
48 ObserverCallback(WorkspaceObserver *observer) : QObject(nullptr), m_observer(observer) {}
49
50signals:
53 void postDeleteRequested(const std::string &name);
54 void addRequested(const std::string &name, Mantid::API::Workspace_sptr workspace);
55 void afterReplaced(const std::string &name, Mantid::API::Workspace_sptr workspace);
56 void renamed(const std::string &oldName, const std::string &newName);
57 void adsCleared();
58
59private slots:
61 void handlePreDelete(const std::string &name, const Mantid::API::Workspace_sptr &workspace);
63 void handlePostDelete(const std::string &name);
65 void handleAdd(const std::string &name, const Mantid::API::Workspace_sptr &workspace);
67 void handleAfterReplace(const std::string &name, const Mantid::API::Workspace_sptr &workspace);
69 void handleRename(const std::string &oldName, const std::string &newName);
71 void handleClearADS();
72
73private:
74 friend class WorkspaceObserver;
79};
80
90
91public:
95 virtual ~WorkspaceObserver();
97 void observePreDelete(bool on = true);
99 void observePostDelete(bool on = true);
101 void observeAfterReplace(bool on = true);
103 void observeRename(bool on = true);
105 void observeAdd(bool on = true);
107 void observeADSClear(bool on = true);
108
109protected:
116 virtual void preDeleteHandle(const std::string &wsName, const Mantid::API::Workspace_sptr &ws) {
117 Q_UNUSED(wsName);
118 Q_UNUSED(ws);
119 }
120
126 virtual void postDeleteHandle(const std::string &wsName) { Q_UNUSED(wsName); }
132 virtual void addHandle(const std::string &wsName, const Mantid::API::Workspace_sptr &ws) {
133 Q_UNUSED(wsName);
134 Q_UNUSED(ws);
135 }
142 virtual void afterReplaceHandle(const std::string &wsName, const Mantid::API::Workspace_sptr &ws) {
143 Q_UNUSED(wsName);
144 Q_UNUSED(ws);
145 }
146
153 virtual void renameHandle(const std::string &oldName, const std::string &newName) {
154 Q_UNUSED(oldName);
155 Q_UNUSED(newName);
156 }
157
161 virtual void clearADSHandle() {}
162
163protected:
168 m_proxy->preDeleteRequested(pNf->objectName(), pNf->object());
169 }
172
177 m_proxy->postDeleteRequested(pNf->objectName());
178 }
181
186 m_proxy->addRequested(pNf->objectName(), pNf->object());
187 }
190
195 m_proxy->afterReplaced(pNf->objectName(), pNf->object());
196 }
199
204 m_proxy->renamed(pNf->objectName(), pNf->newObjectName());
205 }
208
212 void _clearADSHandle(Mantid::API::ClearADSNotification_ptr /*unused*/) { m_proxy->adsCleared(); }
213
214private:
215 friend class ObserverCallback;
216 std::unique_ptr<ObserverCallback> m_proxy;
217
218 bool m_predel_observed, m_postdel_observed, m_add_observed, m_repl_observed, m_rename_observed, m_clr_observed;
219};
220
221} // namespace API
222} // namespace MantidQt
#define EXPORT_OPT_MANTIDQT_COMMON
Definition: DllOption.h:15
IPeaksWorkspace_sptr workspace
Definition: IndexPeaks.cpp:114
A simple callback class so that we avoid multiple inheritance issues with QObject.
ObserverCallback(WorkspaceObserver *observer)
WorkspaceObserver * m_observer
Object to call back to.
void preDeleteRequested(const std::string &name, Mantid::API::Workspace_sptr workspace)
Delete signal handler.
void addRequested(const std::string &name, Mantid::API::Workspace_sptr workspace)
void afterReplaced(const std::string &name, Mantid::API::Workspace_sptr workspace)
void renamed(const std::string &oldName, const std::string &newName)
void postDeleteRequested(const std::string &name)
ObserverCallback()
Default constructor.
Observes AnalysisDataService notifications: add,replace,delete.
void _renameHandle(Mantid::API::WorkspaceRenameNotification_ptr pNf)
Poco notification handler for DataService::RenameNotification.
virtual void afterReplaceHandle(const std::string &wsName, const Mantid::API::Workspace_sptr &ws)
Handler of the AfterReplace notifications.
Poco::NObserver< WorkspaceObserver, Mantid::API::WorkspaceAddNotification > m_addObserver
Poco::NObserver for DataServise::AddNotification.
void _clearADSHandle(Mantid::API::ClearADSNotification_ptr)
ADS clear notification.
virtual void postDeleteHandle(const std::string &wsName)
Handler of the delete notifications.
Poco::NObserver< WorkspaceObserver, Mantid::API::ClearADSNotification > m_clearADSObserver
Clear notification observer.
void _addHandle(Mantid::API::WorkspaceAddNotification_ptr pNf)
Poco notification handler for DataService::DeleteNotification.
void _postDeleteHandle(Mantid::API::WorkspacePostDeleteNotification_ptr pNf)
Poco notification handler for DataService::PostDeleteNotification.
virtual void addHandle(const std::string &wsName, const Mantid::API::Workspace_sptr &ws)
Handler of the add notifications.
virtual void preDeleteHandle(const std::string &wsName, const Mantid::API::Workspace_sptr &ws)
Handler of the delete notifications.
void _afterReplaceHandle(Mantid::API::WorkspaceAfterReplaceNotification_ptr pNf)
Poco notification handler for DataService::AfterReplaceNotification.
Poco::NObserver< WorkspaceObserver, Mantid::API::WorkspaceAfterReplaceNotification > m_afterReplaceObserver
Poco::NObserver for DataServise::AfterReplaceNotification.
Poco::NObserver< WorkspaceObserver, Mantid::API::WorkspaceRenameNotification > m_renameObserver
Poco::NObserver for DataServise::RenameNotification.
virtual void renameHandle(const std::string &oldName, const std::string &newName)
Handler of the Rename notifications.
Poco::NObserver< WorkspaceObserver, Mantid::API::WorkspacePreDeleteNotification > m_preDeleteObserver
Poco::NObserver for DataServise::DeleteNotification.
virtual void clearADSHandle()
Handle an ADS clear notification.
void _preDeleteHandle(Mantid::API::WorkspacePreDeleteNotification_ptr pNf)
Poco notification handler for DataService::PostDeleteNotification.
Poco::NObserver< WorkspaceObserver, Mantid::API::WorkspacePostDeleteNotification > m_postDeleteObserver
Poco::NObserver for DataServise::DeleteNotification.
std::unique_ptr< ObserverCallback > m_proxy
The AlgorithmProgressDialogPresenter keeps track of the running algorithms and displays a progress ba...
const Poco::AutoPtr< Mantid::Kernel::DataService< Mantid::API::Workspace >::AfterReplaceNotification > & WorkspaceAfterReplaceNotification_ptr
const Poco::AutoPtr< Mantid::Kernel::DataService< Mantid::API::Workspace >::ClearNotification > & ClearADSNotification_ptr
const Poco::AutoPtr< Mantid::Kernel::DataService< Mantid::API::Workspace >::PreDeleteNotification > & WorkspacePreDeleteNotification_ptr
std::shared_ptr< Workspace > Workspace_sptr
shared pointer to Mantid::API::Workspace
Definition: Workspace_fwd.h:20
const Poco::AutoPtr< Mantid::Kernel::DataService< Mantid::API::Workspace >::RenameNotification > & WorkspaceRenameNotification_ptr
const Poco::AutoPtr< Mantid::Kernel::DataService< Mantid::API::Workspace >::AddNotification > & WorkspaceAddNotification_ptr
const Poco::AutoPtr< Mantid::Kernel::DataService< Mantid::API::Workspace >::PostDeleteNotification > & WorkspacePostDeleteNotification_ptr