1*313a820fSNicolas Bonnefon /* 2*313a820fSNicolas Bonnefon * Copyright (C) 2013 Nicolas Bonnefon and other contributors 3*313a820fSNicolas Bonnefon * 4*313a820fSNicolas Bonnefon * This file is part of glogg. 5*313a820fSNicolas Bonnefon * 6*313a820fSNicolas Bonnefon * glogg is free software: you can redistribute it and/or modify 7*313a820fSNicolas Bonnefon * it under the terms of the GNU General Public License as published by 8*313a820fSNicolas Bonnefon * the Free Software Foundation, either version 3 of the License, or 9*313a820fSNicolas Bonnefon * (at your option) any later version. 10*313a820fSNicolas Bonnefon * 11*313a820fSNicolas Bonnefon * glogg is distributed in the hope that it will be useful, 12*313a820fSNicolas Bonnefon * but WITHOUT ANY WARRANTY; without even the implied warranty of 13*313a820fSNicolas Bonnefon * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14*313a820fSNicolas Bonnefon * GNU General Public License for more details. 15*313a820fSNicolas Bonnefon * 16*313a820fSNicolas Bonnefon * You should have received a copy of the GNU General Public License 17*313a820fSNicolas Bonnefon * along with glogg. If not, see <http://www.gnu.org/licenses/>. 18*313a820fSNicolas Bonnefon */ 19*313a820fSNicolas Bonnefon 20*313a820fSNicolas Bonnefon #ifndef SIGNALMUX_H 21*313a820fSNicolas Bonnefon #define SIGNALMUX_H 22*313a820fSNicolas Bonnefon 23*313a820fSNicolas Bonnefon // This class multiplexes Qt signals exchanged between one main 24*313a820fSNicolas Bonnefon // window and several 'document' widgets. 25*313a820fSNicolas Bonnefon // The main window register signals with the mux (instead of directly 26*313a820fSNicolas Bonnefon // with the document) and then just notify the mux when the 'current 27*313a820fSNicolas Bonnefon // document' changes 28*313a820fSNicolas Bonnefon /* 29*313a820fSNicolas Bonnefon +---------------------------------------+ 30*313a820fSNicolas Bonnefon | | 31*313a820fSNicolas Bonnefon | Main Window |--+ 32*313a820fSNicolas Bonnefon | | | 33*313a820fSNicolas Bonnefon +---------------------------------------+ | 34*313a820fSNicolas Bonnefon + ^ | 35*313a820fSNicolas Bonnefon v + | 36*313a820fSNicolas Bonnefon +---------------------------------------+ | 37*313a820fSNicolas Bonnefon | MUX |<-+ 38*313a820fSNicolas Bonnefon +---------------------------------------+ 39*313a820fSNicolas Bonnefon +----------^ + 40*313a820fSNicolas Bonnefon | +----------+ 41*313a820fSNicolas Bonnefon | v 42*313a820fSNicolas Bonnefon +--+-----+ +--------+ +-------+ +-------+ 43*313a820fSNicolas Bonnefon | | | | | | | | 44*313a820fSNicolas Bonnefon | Doc 1 | | Doc 2 | | Doc 3 | | Doc 4 | 45*313a820fSNicolas Bonnefon | | | | | | | | 46*313a820fSNicolas Bonnefon +--------+ +--------+ +-------+ +-------+ 47*313a820fSNicolas Bonnefon */ 48*313a820fSNicolas Bonnefon // Strongly inspired by http://doc.qt.digia.com/qq/qq08-action-multiplexer.html 49*313a820fSNicolas Bonnefon 50*313a820fSNicolas Bonnefon #include <list> 51*313a820fSNicolas Bonnefon #include <QPointer> 52*313a820fSNicolas Bonnefon 53*313a820fSNicolas Bonnefon class QObject; 54*313a820fSNicolas Bonnefon 55*313a820fSNicolas Bonnefon class SignalMux { 56*313a820fSNicolas Bonnefon public: 57*313a820fSNicolas Bonnefon SignalMux(); 58*313a820fSNicolas Bonnefon 59*313a820fSNicolas Bonnefon // Connect an 'downstream' signal 60*313a820fSNicolas Bonnefon void connect(QObject *sender, const char *signal, const char *slot); 61*313a820fSNicolas Bonnefon void disconnect(QObject *sender, const char *signal, const char *slot); 62*313a820fSNicolas Bonnefon // Connect an 'upstream' signal 63*313a820fSNicolas Bonnefon void connect(const char *signal, QObject *receiver, const char *slot); 64*313a820fSNicolas Bonnefon void disconnect(const char *signal, QObject *receiver, const char *slot); 65*313a820fSNicolas Bonnefon 66*313a820fSNicolas Bonnefon // Change the current document 67*313a820fSNicolas Bonnefon void setCurrentDocument( QObject* current_document ); 68*313a820fSNicolas Bonnefon 69*313a820fSNicolas Bonnefon private: 70*313a820fSNicolas Bonnefon struct Connection { 71*313a820fSNicolas Bonnefon QPointer<QObject> source; 72*313a820fSNicolas Bonnefon QPointer<QObject> sink; 73*313a820fSNicolas Bonnefon const char* signal; 74*313a820fSNicolas Bonnefon const char* slot; 75*313a820fSNicolas Bonnefon }; 76*313a820fSNicolas Bonnefon 77*313a820fSNicolas Bonnefon void connect( const Connection& connection); 78*313a820fSNicolas Bonnefon void disconnect( const Connection& connection); 79*313a820fSNicolas Bonnefon 80*313a820fSNicolas Bonnefon std::list<Connection> connectionList_; 81*313a820fSNicolas Bonnefon 82*313a820fSNicolas Bonnefon QPointer<QObject> currentDocument_; 83*313a820fSNicolas Bonnefon }; 84*313a820fSNicolas Bonnefon 85*313a820fSNicolas Bonnefon #endif 86