VR-Forces 4.7 Class Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties 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 
19 #include <vrvCoreQt/DtMenuItem.h>
20 #include <vrvCoreQt/DtMenu.h>
22 #include <vrvCoreQt/DtMenuManager.h>
23 
24 #include <QtCore/QString>
25 
26 
27 namespace makVrv
28 {
29  class DtDe;
30 };
31 
32 namespace makVrf
33 {
35  {
36  public:
38  {
39  public:
40  SubMenuPathBuilder(const std::string& path)
41  : MenuPathBuilder(path)
42  {
43  }
44  };
45 
46  DtSubMenuPath(const makVrv::DtMenuPath& p) : makVrv::DtMenuPath(p) {};
47  DtSubMenuPath(const std::string& p) : makVrv::DtMenuPath(SubMenuPathBuilder(p)) {};
48 
49  DtSubMenuPath& operator=(const DtSubMenuPath& rhs)
50  {
51  makVrv::DtMenuPath::operator=(rhs);
52  return *this;
53  }
54 
55  DtSubMenuPath& operator=(const SubMenuPathBuilder& rhs)
56  {
57  makVrv::DtMenuPath::operator=(rhs);
58  return *this;
59  }
60 
61  DtSubMenuPath& operator=(const std::string& rhs)
62  {
63  myPath = rhs;
64  return *this;
65  }
66 
67  const std::string& path() const
68  {
69  return makVrv::DtMenuPath::path();
70  }
71 
72  static SubMenuPathBuilder path(const makVrv::DtMenuPath& p)
73  {
74  return SubMenuPathBuilder(p.path());
75  }
76 
77  static SubMenuPathBuilder path(const std::string& p)
78  {
79  return SubMenuPathBuilder(p);
80  }
81 
82  void strip(const std::string& str1, const std::string& str2)
83  {
84  QString str = myPath.c_str();
85  str.replace(str1.c_str(), str2.c_str());
86  myPath = str.toLatin1().constData();
87  }
88  };
89 
91  {
92  public:
94  {
95  public:
96  SubToolbarPathBuilder(const std::string& path)
97  : ToolbarPathBuilder(path)
98  {
99  }
100  };
101 
102  DtSubToolbarPath(const makVrv::DtToolbarPath& p) : makVrv::DtToolbarPath(p) {};
103  DtSubToolbarPath(const std::string& p) : makVrv::DtToolbarPath(SubToolbarPathBuilder(p)) {};
104 
105  DtSubToolbarPath& operator=(const DtSubToolbarPath& rhs)
106  {
107  makVrv::DtToolbarPath::operator=(rhs);
108  return *this;
109  }
110 
112  {
113  makVrv::DtToolbarPath::operator=(rhs);
114  return *this;
115  }
116 
117  DtSubToolbarPath& operator=(const std::string& rhs)
118  {
119  myPath = rhs;
120  return *this;
121  }
122 
123  const std::string& path() const
124  {
126  }
127 
129  {
130  return SubToolbarPathBuilder(p.path());
131  }
132 
133  static SubToolbarPathBuilder path(const std::string& p)
134  {
135  return SubToolbarPathBuilder(p);
136  }
137  };
138 
143  {
144  public:
146  : makVrv::DtMenuConfiguration()
147  , myDe(0)
148  {
149  }
150 
152  : makVrv::DtMenuConfiguration(c)
153  , myDe(0)
154  {
155  }
156 
158 
159  virtual ~DtSubMenuConfiguration();
160 
162  virtual bool isUnique(const std::string&) const;
163 
164  int size() const
165  {
166  return myMenuPaths.size();
167  }
168 
169  void convert(const std::string& str1, const std::string& str2)
170  {
171  MenuPathSet::iterator curIter = myMenuPaths.begin();
172  for ( ; curIter != myMenuPaths.end(); curIter++)
173  {
174  if (curIter->isMenu() || curIter->isAbsolutePath())
175  {
176  ((DtSubMenuPath&)*curIter).strip(str1, str2);
177  }
178  }
179 
180  MenuPathOrderMap newMap;
181  MenuPathOrderMap::const_iterator iter = myMenuOrder.begin();
182  for ( ; iter != myMenuOrder.end(); iter++)
183  {
184  if (iter->first.isMenu() || iter->first.isAbsolutePath())
185  {
186  DtSubMenuPath path(iter->first);
187  path.strip(str1, str2);
188 
189  newMap[path] = iter->second;
190  }
191  else
192  {
193  newMap[iter->first] = iter->second;
194  }
195  }
196  myMenuOrder = newMap;
197  }
198 
205  virtual void addMenuPath( const makVrv::DtMenuPath& path, int weight = -1);
206 
210  virtual void removeMenuPath(const makVrv::DtMenuPath& path);
211 
215  virtual void addMenuPathAfter(const makVrv::DtMenuPath& newPath, const makVrv::DtMenuPath& relativeTo);
216 
220  virtual void addMenuPathBefore(const makVrv::DtMenuPath& newPath, const makVrv::DtMenuPath& relativeTo);
221 
225  virtual void addMenuItemAfter(const std::string& menuItem, const std::string& after);
226 
228  virtual void removeMenuItem(const std::string& menuItem);
229 
233  virtual void addMenuItemBefore(const std::string& menuItem, const std::string& before);
234 
236  virtual makVrv::DtMenuPath menuPathForItem(const std::string& menuItem) const;
237 
239  virtual std::string mainMenu() const;
240 
242  {
244 
245  return *this;
246  }
247 
249  virtual bool fixSortChildren(makVrv::DtMenuConfiguration::MenuPathList&, bool checkOnly = false);
250 
251  void makeChangesTo(makVrv::DtMenuConfiguration* c)
252  {
253  myMakeChangesTo.push_back(c);
254  }
255 
256  void clearMakeChangesTo()
257  {
258  myMakeChangesTo.clear();
259  }
260 
261  const MenuPathSet& pathsRemoved() const
262  {
263  return myPathsRemoved;
264  }
265 
266  const MenuPathSet& menuPaths() const
267  {
268  return myMenuPaths;
269  }
270 
271  void setProtected(const std::string& p, bool b)
272  {
273  if (b)
274  {
275  myIsProtected[p] = b;
276  }
277  else
278  {
279  std::map<std::string, bool>::iterator iter = myIsProtected.find(p);
280  if (iter != myIsProtected.end())
281  {
282  myIsProtected.erase(iter);
283  }
284  }
285  }
286 
287  bool isProtected(const std::string& p) const
288  {
289  return (myIsProtected.find(p) != myIsProtected.end());
290  }
291 
292  bool isGoingToBeRemoved(const makVrv::DtMenuPath& p) const
293  {
294  return (myPathsRemoved.find(p) != myPathsRemoved.end());
295  }
296 
300  virtual void reworkRelativeOrder();
301 
302  protected:
303  bool sortAbsolute(const makVrv::DtMenuPath& a, const makVrv::DtMenuPath& b) const;
304 
305  protected:
307 
308  std::vector<makVrv::DtMenuConfiguration*> myMakeChangesTo;
310  std::map<std::string, bool> myIsProtected;
311  };
312 
314  {
315  public:
317  : makVrv::DtMenuManager()
318  , myDeleteMenus(false)
319  {
320  }
321 
322  void clear()
323  {
324  myMenuItems.clear();
325  myMenus.clear();
326  }
327 
328  void setDeleteMenus(bool b)
329  {
330  myDeleteMenus = b;
331  }
332 
333  bool deleteMenus() const
334  {
335  return myDeleteMenus;
336  }
337 
339  {
340  if (myDeleteMenus) cleanup();
341  }
342 
343  void cleanup();
344 
345  std::string findMenuPath(QMenu*) const;
346  std::string findItemPath(QAction*) const;
347 
348  protected:
350  };
351 
356  {
357  public:
359 
361  {
362  myMenuManager.clear();
363 
364  if (!myDeleteReferences)
365  {
366  myMenuBuilders.clear();
367  myMenuItemBuilders.clear();
368  }
369  else
370  {
371  cleanup();
372  }
373  }
374 
375  void setDeleteReferences(bool b)
376  {
377  myDeleteReferences = b;
378  }
379 
380  bool deleteReferences() const
381  {
382  return myDeleteReferences;
383  }
384 
385  void setLocalOnly(bool b)
386  {
387  myLocalOnly = b;
388  }
389 
390  void setLocalMenuManager(bool b)
391  {
392  myLocalMenuManager = b;
393  }
394 
396  virtual void assemble(const makVrv::DtMenuConfiguration& configuration);
397  virtual void fixCircularDependencies(DtSubMenuConfiguration& configuration) const;
398 
400  virtual bool hasCircularDependency(DtSubMenuConfiguration& configuration) const;
401 
402  bool localOnly() const
403  {
404  return myLocalOnly;
405  }
406 
407  void cleanup();
408 
410  makVrv::DtMenuManager& menuManager()
411  {
412  if (myLocalMenuManager)
413  {
414  return myMenuManager;
415  }
416  else
417  {
418  return DtQtMenuAssembler::menuManager();
419  }
420  }
421 
422  const makVrv::DtMenuManager& menuManager() const
423  {
424  if (myLocalMenuManager)
425  {
426  return myMenuManager;
427  }
428  else
429  {
430  return makVrv::DtMenuManager::instance(myDe);
431  }
432  }
433 
435  QMenu* findMenu(const makVrv::DtMenuPath& path)
436  {
437  return menuManager().findMenu(path);
438  }
439 
440  QAction* findMenuItem(const makVrv::DtMenuPath& path)
441  {
442  return menuManager().findMenuItem(path);
443  }
444 
446  virtual void registerMenu(makVrv::DtMenu*);
447 
449  virtual void unregisterMenu(makVrv::DtMenu*, bool deleteBuilder = true);
450 
452  virtual void registerMenu(makVrv::DtMenuItem*);
453 
455  virtual void unregisterMenu(makVrv::DtMenuItem*, bool deleteBuilder = true);
456 
459  virtual void merge(const DtQtMenuAssembler::MenuBuilderMap&);
460 
463  virtual void merge(const DtQtMenuAssembler::MenuItemBuilderMap&);
464 
465  void makeChangesTo(makVrv::DtQtMenuAssembler* c)
466  {
467  myMakeChangesTo.push_back(c);
468  }
469 
470  void clearMakeChangesTo()
471  {
472  myMakeChangesTo.clear();
473  }
474 
475  virtual QMenuBar* menuBar()
476  {
477  if (myLocalOnly) return 0;
479  }
480 
481  virtual QWidget* menuWindow()
482  {
483  if (myLocalOnly) return 0;
485  }
486 
488  void setCreateSubMenusForMissingMenus(bool b)
489  {
490  myCreateSubMenusForMissingMenus = b;
491  }
492 
493  virtual void assembleMenu(const makVrv::DtMenuPath& menuPath);
494 
495  protected:
497  virtual bool fixMenuPath(const makVrv::DtMenuPath& menuPath, DtSubMenuConfiguration& configuration, bool checkOnly = false) const;
498 
499  protected:
501  std::vector<makVrv::DtQtMenuAssembler*> myMakeChangesTo;
506  };
507 
510  {
511  public:
512 
514  DtConfigurableMenu(makVrv::DtDe&, const std::string& className);
515 
517  virtual ~DtConfigurableMenu();
518 
520  virtual DtSubMenuConfiguration& menuConfiguration()
521  {
522  return myConfiguration;
523  }
524 
526  virtual DtConfigurableMenuAssembler& menuAssembler()
527  {
528  return myAssembler;
529  }
530 
534  virtual void registerMenu(makVrv::DtMenu* customMenu);
535 
539  virtual void registerMenuItem(makVrv::DtMenuItem* customMenuItem);
540 
541  virtual void createSimpleMenu(std::string menuText, makVrv::DtMenuPath menuIdPath, int weight = -1);
542  virtual void createSimpleMenuAfter(std::string menuText, makVrv::DtMenuPath menuIdPath, makVrv::DtMenuPath afterIdPath);
543  virtual void createSimpleMenuBefore(std::string menuText, makVrv::DtMenuPath menuIdPath, makVrv::DtMenuPath beforeIdPath);
544 
545  virtual void createSimpleMenuItem(std::string itemText, makVrv::DtMenuPath itemIdPath,
546  DtSimpleMenuItemAction* action, void* usr = NULL, int weight = -1);
547  virtual void createSimpleMenuItemAfter(std::string itemText, makVrv::DtMenuPath itemIdPath, makVrv::DtMenuPath afterIdPath,
548  DtSimpleMenuItemAction* action, void* usr = NULL);
549  virtual void createSimpleMenuItemBefore(std::string itemText, makVrv::DtMenuPath itemIdPath, makVrv::DtMenuPath beforeIdPath,
550  DtSimpleMenuItemAction* action, void* usr = NULL);
551 
554  virtual void mergeMenu(makVrv::DtQtMenuAssembler& assembler, makVrv::DtMenuConfiguration& configuration);
555 
558  virtual void mergeMenu(makVrv::DtQtMenuAssembler& assembler);
559 
561  virtual void mergeMenu(makVrv::DtMenuConfiguration& configuration);
562 
563  static bool hasMenuPath(const makVrv::DtMenuConfiguration& menus, const makVrv::DtMenuPath& sourcePath, const std::string& item, makVrv::DtMenuPath& foundPath);
564 
566  boost::signal<void (DtConfigurableMenu*)> signal_menuRecreated;
567 
568  protected:
569  virtual void initMenuItems(makVrv::DtDe& de);
570 
572  {
573  return myAssembler;
574  }
575 
576  DtSubMenuConfiguration& configuration()
577  {
578  return myConfiguration;
579  }
580 
582  virtual void createMenuConfiguration(makVrv::DtDe&) {};
583 
584  protected:
585  DtConfigurableMenuAssembler myAssembler;
589 
590  public:
591  boost::signal<void (QAction*)> signal_validateMenuItem;
592 
593  };
594 }

Document ID: Generated on Fri Apr 26 21:53:14 EDT 2019 from SVN revision 197883
Copyright © 2005-2019 VT MAK. All Rights Reserved (www.mak.com)