VR-Forces 4.1 Class Documentation
DtConfigurableMenu.h
Go to the documentation of this file.
1 /******************************************************************************
2 ** Copyright (c) 2008 MAK Technologies, Inc.
3 ** All rights reserved.
4 ******************************************************************************/
5 
8 
10 
11 #pragma once
12 
17 #include <vrvCoreQt/DtMenuItem.h>
18 #include <vrvCoreQt/DtMenu.h>
20 #include <vrvCoreQt/DtMenuManager.h>
21 
22 #include <QtCore/QString>
23 
24 
25 namespace makVrv
26 {
27  class DtDe;
28 };
29 
30 namespace makVrf
31 {
33  {
34  public:
36  {
37  public:
38  SubMenuPathBuilder(const std::string& path)
39  : MenuPathBuilder(path)
40  {
41  }
42  };
43 
44  DtSubMenuPath(const makVrv::DtMenuPath& p) : makVrv::DtMenuPath(p) {};
45  DtSubMenuPath(const std::string& p) : makVrv::DtMenuPath(SubMenuPathBuilder(p)) {};
46 
47  DtSubMenuPath& operator=(const DtSubMenuPath& rhs)
48  {
49  makVrv::DtMenuPath::operator=(rhs);
50  return *this;
51  }
52 
53  DtSubMenuPath& operator=(const SubMenuPathBuilder& rhs)
54  {
55  makVrv::DtMenuPath::operator=(rhs);
56  return *this;
57  }
58 
59  DtSubMenuPath& operator=(const std::string& rhs)
60  {
61  myPath = rhs;
62  return *this;
63  }
64 
65  const std::string& path() const
66  {
67  return makVrv::DtMenuPath::path();
68  }
69 
70  static SubMenuPathBuilder path(const makVrv::DtMenuPath& p)
71  {
72  return SubMenuPathBuilder(p.path());
73  }
74 
75  static SubMenuPathBuilder path(const std::string& p)
76  {
77  return SubMenuPathBuilder(p);
78  }
79 
80  void strip(const std::string& str1, const std::string& str2)
81  {
82  QString str = myPath.c_str();
83  str.replace(str1.c_str(), str2.c_str());
84  myPath = str.toLatin1().constData();
85  }
86  };
87 
92  {
93  public:
95  : makVrv::DtMenuConfiguration()
96  , myDe(0)
97  {
98  }
99 
101  : makVrv::DtMenuConfiguration(c)
102  , myDe(0)
103  {
104  }
105 
107 
108  virtual ~DtSubMenuConfiguration();
109 
111  virtual bool isUnique(const std::string&) const;
112 
113  int size() const
114  {
115  return myMenuPaths.size();
116  }
117 
118  void convert(const std::string& str1, const std::string& str2)
119  {
120  MenuPathSet::iterator curIter = myMenuPaths.begin();
121  for ( ; curIter != myMenuPaths.end(); curIter++)
122  {
123  if (curIter->isMenu() || curIter->isAbsolutePath())
124  {
125  ((DtSubMenuPath&)*curIter).strip(str1, str2);
126  }
127  }
128 
129  MenuPathOrderMap newMap;
130  MenuPathOrderMap::const_iterator iter = myMenuOrder.begin();
131  for ( ; iter != myMenuOrder.end(); iter++)
132  {
133  if (iter->first.isMenu() || iter->first.isAbsolutePath())
134  {
135  DtSubMenuPath path(iter->first);
136  path.strip(str1, str2);
137 
138  newMap[path] = iter->second;
139  }
140  else
141  {
142  newMap[iter->first] = iter->second;
143  }
144  }
145  myMenuOrder = newMap;
146  }
147 
154  virtual void addMenuPath( const makVrv::DtMenuPath& path, int weight = -1);
155 
159  virtual void removeMenuPath(const makVrv::DtMenuPath& path);
160 
164  virtual void addMenuPathAfter(const makVrv::DtMenuPath& newPath, const makVrv::DtMenuPath& relativeTo);
165 
169  virtual void addMenuPathBefore(const makVrv::DtMenuPath& newPath, const makVrv::DtMenuPath& relativeTo);
170 
174  virtual void addMenuItemAfter(const std::string& menuItem, const std::string& after);
175 
177  virtual void removeMenuItem(const std::string& menuItem);
178 
182  virtual void addMenuItemBefore(const std::string& menuItem, const std::string& before);
183 
185  virtual makVrv::DtMenuPath menuPathForItem(const std::string& menuItem) const;
186 
188  virtual std::string mainMenu() const;
189 
191  {
193 
194  return *this;
195  }
196 
197  void makeChangesTo(makVrv::DtMenuConfiguration* c)
198  {
199  myMakeChangesTo.push_back(c);
200  }
201 
202  void clearMakeChangesTo()
203  {
204  myMakeChangesTo.clear();
205  }
206 
207  const MenuPathSet& pathsRemoved() const
208  {
209  return myPathsRemoved;
210  }
211 
212  const MenuPathSet& menuPaths() const
213  {
214  return myMenuPaths;
215  }
216 
217  void setProtected(const std::string& p, bool b)
218  {
219  if (b)
220  {
221  myIsProtected[p] = b;
222  }
223  else
224  {
225  std::map<std::string, bool>::iterator iter = myIsProtected.find(p);
226  if (iter != myIsProtected.end())
227  {
228  myIsProtected.erase(iter);
229  }
230  }
231  }
232 
233  bool isProtected(const std::string& p) const
234  {
235  return (myIsProtected.find(p) != myIsProtected.end());
236  }
237 
238  bool isGoingToBeRemoved(const makVrv::DtMenuPath& p) const
239  {
240  return (myPathsRemoved.find(p) != myPathsRemoved.end());
241  }
242 
246  virtual void reworkRelativeOrder();
247 
248  protected:
250 
251  std::vector<makVrv::DtMenuConfiguration*> myMakeChangesTo;
253  std::map<std::string, bool> myIsProtected;
254  };
255 
257  {
258  public:
260  : makVrv::DtMenuManager()
261  , myDeleteMenus(false)
262  {
263  }
264 
265  void setDeleteMenus(bool b)
266  {
267  myDeleteMenus = b;
268  }
269 
270  bool deleteMenus() const
271  {
272  return myDeleteMenus;
273  }
274 
276  {
277  if (myDeleteMenus) cleanup();
278  }
279 
280  void cleanup();
281 
282  std::string findMenuPath(QMenu*) const;
283  std::string findItemPath(QAction*) const;
284 
285  protected:
287  };
288 
293  {
294  public:
296 
298  {
299  if (!myDeleteReferences)
300  {
301  myMenuBuilders.clear();
302  myMenuItemBuilders.clear();
303  }
304  else
305  {
306  cleanup();
307  }
308  }
309 
310  void setDeleteReferences(bool b)
311  {
312  myDeleteReferences = b;
313  }
314 
315  bool deleteReferences() const
316  {
317  return myDeleteReferences;
318  }
319 
320  void setLocalOnly(bool b)
321  {
322  myLocalOnly = b;
323  }
324 
325  bool localOnly() const
326  {
327  return myLocalOnly;
328  }
329 
330  void cleanup();
331 
333  makVrv::DtMenuManager& menuManager()
334  {
335  return myMenuManager;
336  }
337 
338  const makVrv::DtMenuManager& menuManager() const
339  {
340  return myMenuManager;
341  }
342 
344  QMenu* findMenu(const makVrv::DtMenuPath& path)
345  {
346  return menuManager().findMenu(path);
347  }
348 
349  QAction* findMenuItem(const makVrv::DtMenuPath& path)
350  {
351  return menuManager().findMenuItem(path);
352  }
353 
355  virtual void registerMenu(makVrv::DtMenu*);
356 
358  virtual void unregisterMenu(makVrv::DtMenu*, bool deleteBuilder = true);
359 
361  virtual void registerMenu(makVrv::DtMenuItem*);
362 
364  virtual void unregisterMenu(makVrv::DtMenuItem*, bool deleteBuilder = true);
365 
366  void makeChangesTo(makVrv::DtQtMenuAssembler* c)
367  {
368  myMakeChangesTo.push_back(c);
369  }
370 
371  void clearMakeChangesTo()
372  {
373  myMakeChangesTo.clear();
374  }
375 
376  virtual QMenuBar* menuBar()
377  {
378  if (myLocalOnly) return 0;
380  }
381 
382  virtual QWidget* menuWindow()
383  {
384  if (myLocalOnly) return 0;
386  }
387 
389  void setCreateSubMenusForMissingMenus(bool b)
390  {
391  myCreateSubMenusForMissingMenus = b;
392  }
393 
394  virtual void assembleMenu(const makVrv::DtMenuPath& menuPath);
395 
396  protected:
398  std::vector<makVrv::DtQtMenuAssembler*> myMakeChangesTo;
402  };
403 
406  {
407  public:
408 
410  DtConfigurableMenu(makVrv::DtDe&, const std::string& className);
411 
413  virtual ~DtConfigurableMenu();
414 
416  virtual DtSubMenuConfiguration& menuConfiguration()
417  {
418  return myConfiguration;
419  }
420 
422  virtual DtConfigurableMenuAssembler& menuAssembler()
423  {
424  return myAssembler;
425  }
426 
430  virtual void registerMenu(makVrv::DtMenu* customMenu);
431 
435  virtual void registerMenuItem(makVrv::DtMenuItem* customMenuItem);
436 
437  virtual void createSimpleMenu(std::string menuText, makVrv::DtMenuPath menuIdPath, int weight = -1);
438  virtual void createSimpleMenuAfter(std::string menuText, makVrv::DtMenuPath menuIdPath, makVrv::DtMenuPath afterIdPath);
439  virtual void createSimpleMenuBefore(std::string menuText, makVrv::DtMenuPath menuIdPath, makVrv::DtMenuPath beforeIdPath);
440 
441  virtual void createSimpleMenuItem(std::string itemText, makVrv::DtMenuPath itemIdPath,
442  DtSimpleMenuItemAction* action, void* usr = NULL, int weight = -1);
443  virtual void createSimpleMenuItemAfter(std::string itemText, makVrv::DtMenuPath itemIdPath, makVrv::DtMenuPath afterIdPath,
444  DtSimpleMenuItemAction* action, void* usr = NULL);
445  virtual void createSimpleMenuItemBefore(std::string itemText, makVrv::DtMenuPath itemIdPath, makVrv::DtMenuPath beforeIdPath,
446  DtSimpleMenuItemAction* action, void* usr = NULL);
447 
450  virtual void mergeMenu(makVrv::DtQtMenuAssembler& assembler, makVrv::DtMenuConfiguration& configuration);
451 
454  virtual void mergeMenu(makVrv::DtQtMenuAssembler& assembler);
455 
457  virtual void mergeMenu(makVrv::DtMenuConfiguration& configuration);
458 
459  protected:
460  virtual void initMenuItems(makVrv::DtDe& de);
461 
463  {
464  return myAssembler;
465  }
466 
467  DtSubMenuConfiguration& configuration()
468  {
469  return myConfiguration;
470  }
471 
473  virtual void createMenuConfiguration(makVrv::DtDe&) {};
474 
475  protected:
476  DtConfigurableMenuAssembler myAssembler;
479 
480  public:
481  boost::signal<void (QAction*)> signal_validateMenuItem;
482 
483  };
484 }

Document ID: Generated on Tue Jan 29 18:21:16 EST 2013 from SVN revision 123193
Copyright © 2005-2013 VT MÄK Inc. All Rights Reserved (www.mak.com)