GLC_lib  2.5.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
glc_movercontroller.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 
3  This file is part of the GLC-lib library.
4  Copyright (C) 2005-2008 Laurent Ribon (laumaya@users.sourceforge.net)
5  http://glc-lib.sourceforge.net
6 
7  GLC-lib is free software; you can redistribute it and/or modify
8  it under the terms of the GNU Lesser General Public License as published by
9  the Free Software Foundation; either version 3 of the License, or
10  (at your option) any later version.
11 
12  GLC-lib is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU Lesser General Public License for more details.
16 
17  You should have received a copy of the GNU Lesser General Public License
18  along with GLC-lib; if not, write to the Free Software
19  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 
21  *****************************************************************************/
22 
24 
25 #include "glc_movercontroller.h"
26 
27 // Default constructor
29 : QObject()
30 , m_ActiveMoverId(0)
31 , m_MoverHash()
32 {
33 
34 
35 }
36 
37 // Copy constructor
39 : QObject()
40 , m_ActiveMoverId(controller.m_ActiveMoverId)
41 , m_MoverHash()
42 {
43  MoverHash::const_iterator iMover= controller.m_MoverHash.constBegin();
44  while (iMover != controller.m_MoverHash.constEnd())
45  {
46  m_MoverHash.insert(iMover.key(), iMover.value()->clone());
47  ++iMover;
48  }
49 }
50 
51 // Destructor
53 {
54  MoverHash::iterator iMover= m_MoverHash.begin();
55  while (iMover != m_MoverHash.constEnd())
56  {
57  delete iMover.value();
58 
59  ++iMover;
60  }
61 }
62 
64 // Set Functions
66 
69 {
70  if (&controller != this)
71  {
72  m_ActiveMoverId= controller.m_ActiveMoverId;
73 
74  // Clear the inner movers
75  {
76  MoverHash::iterator iMover= m_MoverHash.begin();
77  while (iMover != m_MoverHash.constEnd())
78  {
79  delete iMover.value();
80 
81  ++iMover;
82  }
83  m_MoverHash.clear();
84  }
85  // Copy movers
86  MoverHash::const_iterator iMover= controller.m_MoverHash.constBegin();
87  while (iMover != controller.m_MoverHash.constEnd())
88  {
89  m_MoverHash.insert(iMover.key(), iMover.value()->clone());
90  ++iMover;
91  }
92  }
93  return *this;
94 }
95 
96 // Add a mover to the controller
97 void GLC_MoverController::addMover(GLC_Mover* pMover, const int id)
98 {
99  Q_ASSERT(!m_MoverHash.contains(id));
100  m_MoverHash.insert(id, pMover);
101 }
102 
103 // Remove mover from the controller
105 {
106  Q_ASSERT(m_MoverHash.contains(id));
107  m_MoverHash.remove(id);
108  if (id == m_ActiveMoverId)
109  {
110  m_ActiveMoverId= 0;
111  }
112 }
113 
114 void GLC_MoverController::setActiveMover(const int id, const GLC_UserInput& userInput)
115 {
116  Q_ASSERT(m_MoverHash.contains(id));
117  m_ActiveMoverId= id;
118  connect(m_MoverHash.value(m_ActiveMoverId), SIGNAL(updated()), this, SIGNAL(repaintNeeded()));
119  m_MoverHash.value(m_ActiveMoverId)->init(userInput);
120 }
121 
123 {
124  if (0 != m_ActiveMoverId)
125  {
126  m_MoverHash.value(m_ActiveMoverId)->ends();
127  disconnect(m_MoverHash.value(m_ActiveMoverId), SIGNAL(updated()), this, SIGNAL(repaintNeeded()));
128  m_ActiveMoverId= 0;
129  }
130 }
131 

©2005-2013 Laurent Ribon