VR-Forces 4.3 Class Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
configurableMenu.h
Go to the documentation of this file.
1 /******************************************************************************
2 ** Copyright (c) 2014 MAK Technologies, Inc.
3 ** All rights reserved.
4 ******************************************************************************/
5 
8 
10 
11 #pragma once
12 
18 #include <vrvCoreQt/DtMenuItem.h>
19 #include <vrvCoreQt/DtMenu.h>
21 #include <vrvCoreQt/DtMenuManager.h>
22 
23 #include <QtCore/QString>
24 
25 
26 namespace makVrv
27 {
28  class DtDe;
29 };
30 
31 namespace makVrf
32 {
34  {
35  public:
37  {
38  public:
39  SubMenuPathBuilder(const std::string& path)
40  : MenuPathBuilder(path)
41  {
42  }
43  };
44 
45  DtSubMenuPath(const makVrv::DtMenuPath& p) : makVrv::DtMenuPath(p) {};
46  DtSubMenuPath(const std::string& p) : makVrv::DtMenuPath(SubMenuPathBuilder(p)) {};
47 
48  DtSubMenuPath& operator=(const DtSubMenuPath& rhs)
49  {
50  makVrv::DtMenuPath::operator=(rhs);
51  return *this;
52  }
53 
54  DtSubMenuPath& operator=(const SubMenuPathBuilder& rhs)
55  {
56  makVrv::DtMenuPath::operator=(rhs);
57  return *this;
58  }
59 
60  DtSubMenuPath& operator=(const std::string& rhs)
61  {
62  myPath = rhs;
63  return *this;
64  }
65 
66  const std::string& path() const
67  {
68  return makVrv::DtMenuPath::path();
69  }
70 
71  static SubMenuPathBuilder path(const makVrv::DtMenuPath& p)
72  {
73  return SubMenuPathBuilder(p.path());
74  }
75 
76  static SubMenuPathBuilder path(const std::string& p)
77  {
78  return SubMenuPathBuilder(p);
79  }
80 
81  void strip(const std::string& str1, const std::string& str2)
82  {
83  QString str = myPath.c_str();
84  str.replace(str1.c_str(), str2.c_str());
85  myPath = str.toLatin1().constData();
86  }
87  };
88 
90  {
91  public:
93  {
94  public:
95  SubToolbarPathBuilder(const std::string& path)
96  : ToolbarPathBuilder(path)
97  {
98  }
99  };
100 
101  DtSubToolbarPath(const makVrv::DtToolbarPath& p) : makVrv::DtToolbarPath(p) {};
102  DtSubToolbarPath(const std::string& p) : makVrv::DtToolbarPath(SubToolbarPathBuilder(p)) {};
103 
104  DtSubToolbarPath& operator=(const DtSubToolbarPath& rhs)
105  {
106  makVrv::DtToolbarPath::operator=(rhs);
107  return *this;
108  }
109 
111  {
112  makVrv::DtToolbarPath::operator=(rhs);
113  return *this;
114  }
115 
116  DtSubToolbarPath& operator=(const std::string& rhs)
117  {
118  myPath = rhs;
119  return *this;
120  }
121 
122  const std::string& path() const
123  {
125  }
126 
128  {
129  return SubToolbarPathBuilder(p.path());
130  }
131 
132  static SubToolbarPathBuilder path(const std::string& p)
133  {
134  return SubToolbarPathBuilder(p);
135  }
136  };
137 
142  {
143  public:
145  : makVrv::DtMenuConfiguration()
146  , myDe(0)
147  {
148  }
149 
151  : makVrv::DtMenuConfiguration(c)
152  , myDe(0)
153  {
154  }
155 
157 
158  virtual ~DtSubMenuConfiguration();
159 
161  virtual bool isUnique(const std::string&) const;
162 
163  int size() const
164  {
165  return myMenuPaths.size();
166  }
167 
168  void convert(const std::string& str1, const std::string& str2)
169  {
170  MenuPathSet::iterator curIter = myMenuPaths.begin();
171  for ( ; curIter != myMenuPaths.end(); curIter++)
172  {
173  if (curIter->isMenu() || curIter->isAbsolutePath())
174  {
175  ((DtSubMenuPath&)*curIter).strip(str1, str2);
176  }
177  }
178 
179  MenuPathOrderMap newMap;
180  MenuPathOrderMap::const_iterator iter = myMenuOrder.begin();
181  for ( ; iter != myMenuOrder.end(); iter++)
182  {
183  if (iter->first.isMenu() || iter->first.isAbsolutePath())
184  {
185  DtSubMenuPath path(iter->first);
186  path.strip(str1, str2);
187 
188  newMap[path] = iter->second;
189  }
190  else
191  {
192  newMap[iter->first] = iter->second;
193  }
194  }
195  myMenuOrder = newMap;
196  }
197 
204  virtual void addMenuPath( const makVrv::DtMenuPath& path, int weight = -1);
205 
209  virtual void removeMenuPath(const makVrv::DtMenuPath& path);
210 
214  virtual void addMenuPathAfter(const makVrv::DtMenuPath& newPath, const makVrv::DtMenuPath& relativeTo);
215 
219  virtual void addMenuPathBefore(const makVrv::DtMenuPath& newPath, const makVrv::DtMenuPath& relativeTo);
220 
224  virtual void addMenuItemAfter(const std::string& menuItem, const std::string& after);
225 
227  virtual void removeMenuItem(const std::string& menuItem);
228 
232  virtual void addMenuItemBefore(const std::string& menuItem, const std::string& before);
233 
235  virtual makVrv::DtMenuPath menuPathForItem(const std::string& menuItem) const;
236 
238  virtual std::string mainMenu() const;
239 
241  {
243 
244  return *this;
245  }
246 
247  void makeChangesTo(makVrv::DtMenuConfiguration* c)
248  {
249  myMakeChangesTo.push_back(c);
250  }
251 
252  void clearMakeChangesTo()
253  {
254  myMakeChangesTo.clear();
255  }
256 
257  const MenuPathSet& pathsRemoved() const
258  {
259  return myPathsRemoved;
260  }
261 
262  const MenuPathSet& menuPaths() const
263  {
264  return myMenuPaths;
265  }
266 
267  void setProtected(const std::string& p, bool b)
268  {
269  if (b)
270  {
271  myIsProtected[p] = b;
272  }
273  else
274  {
275  std::map<std::string, bool>::iterator iter = myIsProtected.find(p);
276  if (iter != myIsProtected.end())
277  {
278  myIsProtected.erase(iter);
279  }
280  }
281  }
282 
283  bool isProtected(const std::string& p) const
284  {
285  return (myIsProtected.find(p) != myIsProtected.end());
286  }
287 
288  bool isGoingToBeRemoved(const makVrv::DtMenuPath& p) const
289  {
290  return (myPathsRemoved.find(p) != myPathsRemoved.end());
291  }
292 
296  virtual void reworkRelativeOrder();
297 
298  protected:
300 
301  std::vector<makVrv::DtMenuConfiguration*> myMakeChangesTo;
303  std::map<std::string, bool> myIsProtected;
304  };
305 
307  {
308  public:
310  : makVrv::DtMenuManager()
311  , myDeleteMenus(false)
312  {
313  }
314 
315  void clear()
316  {
317  myMenuItems.clear();
318  myMenus.clear();
319  }
320 
321  void setDeleteMenus(bool b)
322  {
323  myDeleteMenus = b;
324  }
325 
326  bool deleteMenus() const
327  {
328  return myDeleteMenus;
329  }
330 
332  {
333  if (myDeleteMenus) cleanup();
334  }
335 
336  void cleanup();
337 
338  std::string findMenuPath(QMenu*) const;
339  std::string findItemPath(QAction*) const;
340 
341  protected:
343  };
344 
349  {
350  public:
352 
354  {
355  myMenuManager.clear();
356 
357  if (!myDeleteReferences)
358  {
359  myMenuBuilders.clear();
360  myMenuItemBuilders.clear();
361  }
362  else
363  {
364  cleanup();
365  }
366  }
367 
368  void setDeleteReferences(bool b)
369  {
370  myDeleteReferences = b;
371  }
372 
373  bool deleteReferences() const
374  {
375  return myDeleteReferences;
376  }
377 
378  void setLocalOnly(bool b)
379  {
380  myLocalOnly = b;
381  }
382 
383  bool localOnly() const
384  {
385  return myLocalOnly;
386  }
387 
388  void cleanup();
389 
391  makVrv::DtMenuManager& menuManager()
392  {
393  return myMenuManager;
394  }
395 
396  const makVrv::DtMenuManager& menuManager() const
397  {
398  return myMenuManager;
399  }
400 
402  QMenu* findMenu(const makVrv::DtMenuPath& path)
403  {
404  return menuManager().findMenu(path);
405  }
406 
407  QAction* findMenuItem(const makVrv::DtMenuPath& path)
408  {
409  return menuManager().findMenuItem(path);
410  }
411 
413  virtual void registerMenu(makVrv::DtMenu*);
414 
416  virtual void unregisterMenu(makVrv::DtMenu*, bool deleteBuilder = true);
417 
419  virtual void registerMenu(makVrv::DtMenuItem*);
420 
422  virtual void unregisterMenu(makVrv::DtMenuItem*, bool deleteBuilder = true);
423 
426  virtual void merge(const DtQtMenuAssembler::MenuBuilderMap&);
427 
430  virtual void merge(const DtQtMenuAssembler::MenuItemBuilderMap&);
431 
432  void makeChangesTo(makVrv::DtQtMenuAssembler* c)
433  {
434  myMakeChangesTo.push_back(c);
435  }
436 
437  void clearMakeChangesTo()
438  {
439  myMakeChangesTo.clear();
440  }
441 
442  virtual QMenuBar* menuBar()
443  {
444  if (myLocalOnly) return 0;
446  }
447 
448  virtual QWidget* menuWindow()
449  {
450  if (myLocalOnly) return 0;
452  }
453 
455  void setCreateSubMenusForMissingMenus(bool b)
456  {
457  myCreateSubMenusForMissingMenus = b;
458  }
459 
460  virtual void assembleMenu(const makVrv::DtMenuPath& menuPath);
461 
462  protected:
464  std::vector<makVrv::DtQtMenuAssembler*> myMakeChangesTo;
468  };
469 
472  {
473  public:
474 
476  DtConfigurableMenu(makVrv::DtDe&, const std::string& className);
477 
479  virtual ~DtConfigurableMenu();
480 
482  virtual DtSubMenuConfiguration& menuConfiguration()
483  {
484  return myConfiguration;
485  }
486 
488  virtual DtConfigurableMenuAssembler& menuAssembler()
489  {
490  return myAssembler;
491  }
492 
496  virtual void registerMenu(makVrv::DtMenu* customMenu);
497 
501  virtual void registerMenuItem(makVrv::DtMenuItem* customMenuItem);
502 
503  virtual void createSimpleMenu(std::string menuText, makVrv::DtMenuPath menuIdPath, int weight = -1);
504  virtual void createSimpleMenuAfter(std::string menuText, makVrv::DtMenuPath menuIdPath, makVrv::DtMenuPath afterIdPath);
505  virtual void createSimpleMenuBefore(std::string menuText, makVrv::DtMenuPath menuIdPath, makVrv::DtMenuPath beforeIdPath);
506 
507  virtual void createSimpleMenuItem(std::string itemText, makVrv::DtMenuPath itemIdPath,
508  DtSimpleMenuItemAction* action, void* usr = NULL, int weight = -1);
509  virtual void createSimpleMenuItemAfter(std::string itemText, makVrv::DtMenuPath itemIdPath, makVrv::DtMenuPath afterIdPath,
510  DtSimpleMenuItemAction* action, void* usr = NULL);
511  virtual void createSimpleMenuItemBefore(std::string itemText, makVrv::DtMenuPath itemIdPath, makVrv::DtMenuPath beforeIdPath,
512  DtSimpleMenuItemAction* action, void* usr = NULL);
513 
516  virtual void mergeMenu(makVrv::DtQtMenuAssembler& assembler, makVrv::DtMenuConfiguration& configuration);
517 
520  virtual void mergeMenu(makVrv::DtQtMenuAssembler& assembler);
521 
523  virtual void mergeMenu(makVrv::DtMenuConfiguration& configuration);
524 
525  protected:
526  virtual void initMenuItems(makVrv::DtDe& de);
527 
529  {
530  return myAssembler;
531  }
532 
533  DtSubMenuConfiguration& configuration()
534  {
535  return myConfiguration;
536  }
537 
539  virtual void createMenuConfiguration(makVrv::DtDe&) {};
540 
541  protected:
542  DtConfigurableMenuAssembler myAssembler;
545 
546  public:
547  boost::signal<void (QAction*)> signal_validateMenuItem;
548 
549  };
550 }

Document ID: Generated on Wed Mar 11 21:20:57 EDT 2015 from SVN revision 150940
Copyright © 2005-2014 VT MÄK. All Rights Reserved (www.mak.com)