VPTissue Reference Manual
IProject.h
Go to the documentation of this file.
1 #ifndef WS_IPROJECT_H_INCLUDED
2 #define WS_IPROJECT_H_INCLUDED
3 /*
4  * Copyright 2011-2016 Universiteit Antwerpen
5  *
6  * Licensed under the EUPL, Version 1.1 or as soon they will be approved by
7  * the European Commission - subsequent versions of the EUPL (the "Licence");
8  * You may not use this work except in compliance with the Licence.
9  * You may obtain a copy of the Licence at: http://ec.europa.eu/idabc/eupl5
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the Licence is distributed on an "AS IS" basis,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the Licence for the specific language governing
15  * permissions and limitations under the Licence.
16  */
22 #include "IWorkspace.h"
23 #include "IPreferences.h"
25 #include "event/ProjectChanged.h"
26 #include "util/misc/Subject.h"
27 
28 #include <map>
29 #include <vector>
30 #include <boost/property_tree/ptree.hpp>
31 
32 class QAction;
33 class QWidget;
34 
35 namespace SimShell {
36 
37 namespace Session {
38 class ISession;
39 }
40 
41 namespace Ws {
42 
43 class IFile;
44 class MergedPreferences;
45 
59 class IProject : public virtual IPreferences,
60  public IUserData,
61  public SimPT_Sim::Util::Subject<Event::ProjectChanged, std::weak_ptr<const void>>
62 {
63 public:
70  using ConstructorType = std::function<std::shared_ptr<IProject>(
71  const std::string&, const std::string&, const std::string&, const std::shared_ptr<IWorkspace>&)>;
72  using FileMap = std::map<std::string, std::shared_ptr<IFile>>;
73  using FileIterator = typename FileMap::iterator;
74  using ConstFileIterator = typename FileMap::const_iterator;
75 
76  struct WidgetCallback {
77  typedef std::function<std::shared_ptr<QWidget>(std::shared_ptr<MergedPreferences>, QWidget*)> Type;
78 
79  std::string name;
80  Type callback;
81  };
82 
83 public:
85  virtual ~IProject() {}
86 
90  virtual FileIterator Add(const std::string& name) = 0;
91 
94  virtual std::shared_ptr<IFile> Back() = 0;
95 
98  virtual std::shared_ptr<const IFile> Back() const = 0;
99 
101  virtual FileIterator begin() = 0;
102 
104  virtual ConstFileIterator begin() const = 0;
105 
107  virtual FileIterator end() = 0;
108 
110  virtual ConstFileIterator end() const = 0;
111 
115  virtual void Close() = 0;
116 
119  virtual FileIterator Find(const std::string& name) = 0;
120 
123  virtual ConstFileIterator Find(const std::string& name) const = 0;
124 
127  virtual std::shared_ptr<IFile> Front() = 0;
128 
131  virtual std::shared_ptr<const IFile> Front() const = 0;
132 
135  virtual std::shared_ptr<IFile> Get(const std::string& name) = 0;
136 
139  virtual std::shared_ptr<const IFile> Get(const std::string& name) const = 0;
140 
142  virtual std::vector<QAction*> GetContextMenuActions() const = 0;
143 
145  virtual const std::string& GetIndexFile() const = 0;
146 
148  virtual const std::string& GetPath() const = 0;
149 
151  virtual std::shared_ptr<Session::ISession> GetSession() const = 0;
152 
156  virtual std::string GetSessionFileName() const = 0;
157 
159  virtual std::vector<WidgetCallback> GetWidgets() = 0;
160 
164  virtual bool IsLeaf(const std::string& name) const = 0;
165 
168  virtual bool IsOpened() const = 0;
169 
174  virtual bool IsWatchingDirectory() const = 0;
175 
177  virtual void Open() = 0;
178 
181  virtual void Open(const std::string& name) = 0;
182 
185  virtual void Open(FileIterator it) = 0;
186 
188  virtual void Refresh() = 0;
189 
193  virtual void Remove(const std::string& name) = 0;
194 
197  virtual void Remove(FileIterator it) = 0;
198 
202  virtual Session::ISession& Session() const = 0;
203 
207  virtual void SetWatchingDirectory(bool) = 0;
208 };
209 
210 } // namespace
211 } // namespace
212 
213 #endif // end_of_inclde_guard
virtual std::shared_ptr< Session::ISession > GetSession() const =0
Get session pointer. THIS IS A TEMPORARY HACK.
virtual void Open()=0
Open most recent file in project.
virtual bool IsWatchingDirectory() const =0
Test whether project is currently watching its directory for changes.
Interface for project-like behavior.
Definition: IProject.h:59
virtual const std::string & GetPath() const =0
Get path project was initialized with.
virtual FileIterator Add(const std::string &name)=0
Add existing file to project.
virtual std::shared_ptr< IFile > Front()=0
Get first file.
virtual FileIterator end()=0
Get iterator pointing to one position after last file.
virtual void SetWatchingDirectory(bool)=0
Set whether project must watch its directory for changes.
virtual FileIterator Find(const std::string &name)=0
Get iterator pointing to file with given name.
virtual void Refresh()=0
Refresh project.
Interface/Implementation of Subject.
Definition for ProjectChanged.
std::string name
Name of callback.
Definition: IProject.h:79
Interface expressing the ability of an object to have a ptree of preferences stored in it...
Definition: IPreferences.h:33
virtual bool IsOpened() const =0
Test whether project is in 'opened' state.
virtual FileIterator begin()=0
Get iterator pointing to first file.
virtual std::shared_ptr< IFile > Get(const std::string &name)=0
Get file with given name.
virtual std::string GetSessionFileName() const =0
Get name of file used to initiate session.
Type callback
Callback to create widget. Argument is parent widget, returns created widget.
Definition: IProject.h:80
Interface that expresses the ability to have user data, i.e.
Definition: IUserData.h:29
virtual std::vector< QAction * > GetContextMenuActions() const =0
Get Qt actions that can be triggered on this project.
virtual std::vector< WidgetCallback > GetWidgets()=0
Get map of widget creator callbacks.
Interface for IWorkspace.
virtual std::shared_ptr< IFile > Back()=0
Get last file.
virtual ~IProject()
Virtual destructor.
Definition: IProject.h:85
Interface for IPreferences.
Subject in Observer pattern.
Definition: Subject.h:34
virtual const std::string & GetIndexFile() const =0
Get name of index file for this type of project.
see the online Qt documentation
Definition for PreferencesChanged.
virtual Session::ISession & Session() const =0
Get session of opened project.
std::function< std::shared_ptr< IProject >(const std::string &, const std::string &, const std::string &, const std::shared_ptr< IWorkspace > &)> ConstructorType
First argument : type of project to create.
Definition: IProject.h:71
Namespace for generic graphical shell for simulators.
Definition: SimSession.h:32
virtual void Remove(const std::string &name)=0
Remove file with given name.
Generic session interface.
Definition: ISession.h:53
virtual bool IsLeaf(const std::string &name) const =0
Test whether file with given name exists in project.
virtual void Close()=0
Close project.