VR-Forces 4.5 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 
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 
248  void makeChangesTo(makVrv::DtMenuConfiguration* c)
249  {
250  myMakeChangesTo.push_back(c);
251  }
252 
253  void clearMakeChangesTo()
254  {
255  myMakeChangesTo.clear();
256  }
257 
258  const MenuPathSet& pathsRemoved() const
259  {
260  return myPathsRemoved;
261  }
262 
263  const MenuPathSet& menuPaths() const
264  {
265  return myMenuPaths;
266  }
267 
268  void setProtected(const std::string& p, bool b)
269  {
270  if (b)
271  {
272  myIsProtected[p] = b;
273  }
274  else
275  {
276  std::map<std::string, bool>::iterator iter = myIsProtected.find(p);
277  if (iter != myIsProtected.end())
278  {
279  myIsProtected.erase(iter);
280  }
281  }
282  }
283 
284  bool isProtected(const std::string& p) const
285  {
286  return (myIsProtected.find(p) != myIsProtected.end());
287  }
288 
289  bool isGoingToBeRemoved(const makVrv::DtMenuPath& p) const
290  {
291  return (myPathsRemoved.find(p) != myPathsRemoved.end());
292  }
293 
297  virtual void reworkRelativeOrder();
298 
299  protected:
301 
302  std::vector<makVrv::DtMenuConfiguration*> myMakeChangesTo;
304  std::map<std::string, bool> myIsProtected;
305  };
306 
308  {
309  public:
311  : makVrv::DtMenuManager()
312  , myDeleteMenus(false)
313  {
314  }
315 
316  void clear()
317  {
318  myMenuItems.clear();
319  myMenus.clear();
320  }
321 
322  void setDeleteMenus(bool b)
323  {
324  myDeleteMenus = b;
325  }
326 
327  bool deleteMenus() const
328  {
329  return myDeleteMenus;
330  }
331 
333  {
334  if (myDeleteMenus) cleanup();
335  }
336 
337  void cleanup();
338 
339  std::string findMenuPath(QMenu*) const;
340  std::string findItemPath(QAction*) const;
341 
342  protected:
344  };
345 
350  {
351  public:
353 
355  {
356  myMenuManager.clear();
357 
358  if (!myDeleteReferences)
359  {
360  myMenuBuilders.clear();
361  myMenuItemBuilders.clear();
362  }
363  else
364  {
365  cleanup();
366  }
367  }
368 
369  void setDeleteReferences(bool b)
370  {
371  myDeleteReferences = b;
372  }
373 
374  bool deleteReferences() const
375  {
376  return myDeleteReferences;
377  }
378 
379  void setLocalOnly(bool b)
380  {
381  myLocalOnly = b;
382  }
383 
384  bool localOnly() const
385  {
386  return myLocalOnly;
387  }
388 
389  void cleanup();
390 
392  makVrv::DtMenuManager& menuManager()
393  {
394  return myMenuManager;
395  }
396 
397  const makVrv::DtMenuManager& menuManager() const
398  {
399  return myMenuManager;
400  }
401 
403  QMenu* findMenu(const makVrv::DtMenuPath& path)
404  {
405  return menuManager().findMenu(path);
406  }
407 
408  QAction* findMenuItem(const makVrv::DtMenuPath& path)
409  {
410  return menuManager().findMenuItem(path);
411  }
412 
414  virtual void registerMenu(makVrv::DtMenu*);
415 
417  virtual void unregisterMenu(makVrv::DtMenu*, bool deleteBuilder = true);
418 
420  virtual void registerMenu(makVrv::DtMenuItem*);
421 
423  virtual void unregisterMenu(makVrv::DtMenuItem*, bool deleteBuilder = true);
424 
427  virtual void merge(const DtQtMenuAssembler::MenuBuilderMap&);
428 
431  virtual void merge(const DtQtMenuAssembler::MenuItemBuilderMap&);
432 
433  void makeChangesTo(makVrv::DtQtMenuAssembler* c)
434  {
435  myMakeChangesTo.push_back(c);
436  }
437 
438  void clearMakeChangesTo()
439  {
440  myMakeChangesTo.clear();
441  }
442 
443  virtual QMenuBar* menuBar()
444  {
445  if (myLocalOnly) return 0;
447  }
448 
449  virtual QWidget* menuWindow()
450  {
451  if (myLocalOnly) return 0;
453  }
454 
456  void setCreateSubMenusForMissingMenus(bool b)
457  {
458  myCreateSubMenusForMissingMenus = b;
459  }
460 
461  virtual void assembleMenu(const makVrv::DtMenuPath& menuPath);
462 
463  protected:
465  std::vector<makVrv::DtQtMenuAssembler*> myMakeChangesTo;
469  };
470 
473  {
474  public:
475 
477  DtConfigurableMenu(makVrv::DtDe&, const std::string& className);
478 
480  virtual ~DtConfigurableMenu();
481 
483  virtual DtSubMenuConfiguration& menuConfiguration()
484  {
485  return myConfiguration;
486  }
487 
489  virtual DtConfigurableMenuAssembler& menuAssembler()
490  {
491  return myAssembler;
492  }
493 
497  virtual void registerMenu(makVrv::DtMenu* customMenu);
498 
502  virtual void registerMenuItem(makVrv::DtMenuItem* customMenuItem);
503 
504  virtual void createSimpleMenu(std::string menuText, makVrv::DtMenuPath menuIdPath, int weight = -1);
505  virtual void createSimpleMenuAfter(std::string menuText, makVrv::DtMenuPath menuIdPath, makVrv::DtMenuPath afterIdPath);
506  virtual void createSimpleMenuBefore(std::string menuText, makVrv::DtMenuPath menuIdPath, makVrv::DtMenuPath beforeIdPath);
507 
508  virtual void createSimpleMenuItem(std::string itemText, makVrv::DtMenuPath itemIdPath,
509  DtSimpleMenuItemAction* action, void* usr = NULL, int weight = -1);
510  virtual void createSimpleMenuItemAfter(std::string itemText, makVrv::DtMenuPath itemIdPath, makVrv::DtMenuPath afterIdPath,
511  DtSimpleMenuItemAction* action, void* usr = NULL);
512  virtual void createSimpleMenuItemBefore(std::string itemText, makVrv::DtMenuPath itemIdPath, makVrv::DtMenuPath beforeIdPath,
513  DtSimpleMenuItemAction* action, void* usr = NULL);
514 
517  virtual void mergeMenu(makVrv::DtQtMenuAssembler& assembler, makVrv::DtMenuConfiguration& configuration);
518 
521  virtual void mergeMenu(makVrv::DtQtMenuAssembler& assembler);
522 
524  virtual void mergeMenu(makVrv::DtMenuConfiguration& configuration);
525 
527  boost::signal<void (DtConfigurableMenu*)> signal_menuRecreated;
528 
529  protected:
530  virtual void initMenuItems(makVrv::DtDe& de);
531 
533  {
534  return myAssembler;
535  }
536 
537  DtSubMenuConfiguration& configuration()
538  {
539  return myConfiguration;
540  }
541 
543  virtual void createMenuConfiguration(makVrv::DtDe&) {};
544 
545  protected:
546  DtConfigurableMenuAssembler myAssembler;
550 
551  public:
552  boost::signal<void (QAction*)> signal_validateMenuItem;
553 
554  };
555 }

Document ID: Generated on Thu Mar 23 18:54:12 EDT 2017 from SVN revision 174804
Copyright © 2005-2017 VT MÄK. All Rights Reserved (www.mak.com)