signal_multiplexer.cpp
Go to the documentation of this file.
00001 #include <pcl/apps/cloud_composer/signal_multiplexer.h>
00002 #include <pcl/apps/cloud_composer/project_model.h>
00003 
00004 pcl::cloud_composer::SignalMultiplexer::SignalMultiplexer (QObject* parent)
00005   : QObject (parent)
00006 {
00007 
00008 }
00009 
00010 
00011 void
00012 pcl::cloud_composer::SignalMultiplexer::connect (QObject* sender, const char* signal, const char* slot)
00013 {
00014   Connection conn;
00015   conn.sender = sender;
00016   conn.signal = signal;
00017   conn.slot = slot;
00018 
00019   connections << conn;
00020   connect (conn);
00021 }
00022 
00023 
00024 void
00025 pcl::cloud_composer::SignalMultiplexer::connect (const char* signal, QObject* receiver, const char* slot)
00026 {
00027   Connection conn;
00028   conn.receiver = receiver;
00029   conn.signal = signal;
00030   conn.slot = slot;
00031 
00032   connections << conn;
00033   connect (conn);
00034 }
00035 
00036 
00037 bool
00038 pcl::cloud_composer::SignalMultiplexer::disconnect (QObject* sender, const char* signal, const char* slot)
00039 {
00040   QMutableListIterator<Connection> it (connections);
00041   while (it.hasNext ())
00042   {
00043     Connection conn = it.next();
00044     if ( (QObject*) conn.sender == sender &&
00045           qstrcmp (conn.signal, signal) == 0 && qstrcmp (conn.slot, slot) == 0)
00046     {
00047       disconnect (conn);
00048       it.remove();
00049       return true;
00050     }
00051   }
00052   return false;
00053 }
00054 
00055 
00056 bool
00057 pcl::cloud_composer::SignalMultiplexer::disconnect (const char* signal, QObject* receiver, const char* slot)
00058 {
00059   QMutableListIterator<Connection> it (connections);
00060   while (it.hasNext ())
00061   {
00062     Connection conn = it.next();
00063     if ( (QObject*) conn.receiver == receiver &&
00064           qstrcmp (conn.signal, signal) == 0 && qstrcmp (conn.slot, slot) == 0)
00065     {
00066       disconnect (conn);
00067       it.remove();
00068       return true;
00069     }
00070   }
00071   return false;
00072 }
00073 
00074 
00075 void
00076 pcl::cloud_composer::SignalMultiplexer::connect (const Connection& conn)
00077 {
00078   if (!object)
00079     return;
00080   if (!conn.sender && !conn.receiver)
00081     return;
00082 
00083   if (conn.sender)
00084     QObject::connect ( (QObject*) conn.sender, conn.signal, (QObject*) object, conn.slot);
00085   else
00086     QObject::connect ( (QObject*) object, conn.signal, (QObject*) conn.receiver, conn.slot);
00087 }
00088 
00089 
00090 void 
00091 pcl::cloud_composer::SignalMultiplexer::disconnect (const Connection& conn)
00092 {
00093   if (!object)
00094     return;
00095   if (!conn.sender && !conn.receiver)
00096     return;
00097 
00098   if (conn.sender)
00099     QObject::disconnect ( (QObject*) conn.sender, conn.signal, (QObject*) object, conn.slot);
00100   else
00101     QObject::disconnect ( (QObject*) object, conn.signal, (QObject*) conn.receiver, conn.slot);
00102 
00103 }
00104 
00105 
00106 void 
00107 pcl::cloud_composer::SignalMultiplexer::setCurrentObject (QObject* newObject)
00108 {
00109   if (newObject == object)
00110     return;
00111 
00112   QList<Connection>::ConstIterator it;
00113   for (it = connections.begin (); it != connections.end (); ++it)
00114     disconnect (*it);
00115   object = newObject;
00116   for (it = connections.begin (); it != connections.end (); ++it)
00117     connect (*it);
00118 
00119   ProjectModel* model = dynamic_cast<ProjectModel*> (newObject);
00120   if (model)
00121     model->emitAllStateSignals ();
00122   
00123   //let the world know about who's on top now
00124   emit currentObjectChanged (object);
00125 }


pcl
Author(s): Open Perception
autogenerated on Wed Aug 26 2015 15:33:37