glc_movercontroller.cpp

Go to the documentation of this file.
00001 /****************************************************************************
00002 
00003  This file is part of the GLC-lib library.
00004  Copyright (C) 2005-2008 Laurent Ribon (laumaya@users.sourceforge.net)
00005  http://glc-lib.sourceforge.net
00006 
00007  GLC-lib is free software; you can redistribute it and/or modify
00008  it under the terms of the GNU Lesser General Public License as published by
00009  the Free Software Foundation; either version 3 of the License, or
00010  (at your option) any later version.
00011 
00012  GLC-lib is distributed in the hope that it will be useful,
00013  but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  GNU Lesser General Public License for more details.
00016 
00017  You should have received a copy of the GNU Lesser General Public License
00018  along with GLC-lib; if not, write to the Free Software
00019  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00020 
00021  *****************************************************************************/
00022 
00024 
00025 #include "glc_movercontroller.h"
00026 
00027 // Default constructor
00028 GLC_MoverController::GLC_MoverController()
00029 : QObject()
00030 , m_ActiveMoverId(0)
00031 , m_MoverHash()
00032 {
00033 
00034 
00035 }
00036 
00037 // Copy constructor
00038 GLC_MoverController::GLC_MoverController(const GLC_MoverController& controller)
00039 : QObject()
00040 , m_ActiveMoverId(controller.m_ActiveMoverId)
00041 , m_MoverHash()
00042 {
00043         MoverHash::const_iterator iMover= controller.m_MoverHash.constBegin();
00044         while (iMover != controller.m_MoverHash.constEnd())
00045         {
00046                 m_MoverHash.insert(iMover.key(), iMover.value()->clone());
00047                 ++iMover;
00048         }
00049 }
00050 
00051 // Destructor
00052 GLC_MoverController::~GLC_MoverController()
00053 {
00054         MoverHash::iterator iMover= m_MoverHash.begin();
00055         while (iMover != m_MoverHash.constEnd())
00056         {
00057                 delete iMover.value();
00058 
00059                 ++iMover;
00060         }
00061 }
00062 
00064 // Set Functions
00066 
00068 GLC_MoverController& GLC_MoverController::operator = (const GLC_MoverController& controller)
00069 {
00070         if (&controller != this)
00071         {
00072                  m_ActiveMoverId= controller.m_ActiveMoverId;
00073 
00074                  // Clear the inner movers
00075                  {
00076                          MoverHash::iterator iMover= m_MoverHash.begin();
00077                          while (iMover != m_MoverHash.constEnd())
00078                          {
00079                                  delete iMover.value();
00080 
00081                                  ++iMover;
00082                          }
00083                          m_MoverHash.clear();
00084                  }
00085                  // Copy movers
00086                  MoverHash::const_iterator iMover= controller.m_MoverHash.constBegin();
00087                  while (iMover != controller.m_MoverHash.constEnd())
00088                  {
00089                          m_MoverHash.insert(iMover.key(), iMover.value()->clone());
00090                          ++iMover;
00091                  }
00092         }
00093         return *this;
00094 }
00095 
00096 // Add a mover to the controller
00097 void GLC_MoverController::addMover(GLC_Mover* pMover, const int id)
00098 {
00099         Q_ASSERT(!m_MoverHash.contains(id));
00100         m_MoverHash.insert(id, pMover);
00101 }
00102 
00103 // Remove mover from the controller
00104 void GLC_MoverController::removeMover(const int id)
00105 {
00106         Q_ASSERT(m_MoverHash.contains(id));
00107         m_MoverHash.remove(id);
00108         if (id == m_ActiveMoverId)
00109         {
00110                 m_ActiveMoverId= 0;
00111         }
00112 }
00113 
00114 void GLC_MoverController::setActiveMover(const int id, const GLC_UserInput& userInput)
00115 {
00116         Q_ASSERT(m_MoverHash.contains(id));
00117         m_ActiveMoverId= id;
00118         connect(m_MoverHash.value(m_ActiveMoverId), SIGNAL(updated()), this, SIGNAL(repaintNeeded()));
00119         m_MoverHash.value(m_ActiveMoverId)->init(userInput);
00120 }
00121 
00122 void GLC_MoverController::setNoMover()
00123 {
00124         if (0 != m_ActiveMoverId)
00125         {
00126                 m_MoverHash.value(m_ActiveMoverId)->ends();
00127                 disconnect(m_MoverHash.value(m_ActiveMoverId), SIGNAL(updated()), this, SIGNAL(repaintNeeded()));
00128                 m_ActiveMoverId= 0;
00129         }
00130 }
00131 

SourceForge.net Logo

©2005-2011 Laurent Ribon