KTutorial  0.5.1
WaitForComposed.cpp
00001 /***************************************************************************
00002  *   Copyright (C) 2008 by Daniel Calviño Sánchez <danxuliu@gmail.com>     *
00003  *   Copyright (C) 2009 by Daniel Calviño Sánchez <danxuliu@gmail.com>     *
00004  *   Copyright (C) 2010 by Daniel Calviño Sánchez <danxuliu@gmail.com>     *
00005  *   Copyright (C) 2011 by Daniel Calviño Sánchez <danxuliu@gmail.com>     *
00006  *   Copyright (C) 2012 by Daniel Calviño Sánchez <danxuliu@gmail.com>     *
00007  *                                                                         *
00008  *   This program is free software; you can redistribute it and/or modify  *
00009  *   it under the terms of the GNU General Public License as published by  *
00010  *   the Free Software Foundation; either version 2 of the License, or     *
00011  *   (at your option) any later version.                                   *
00012  *                                                                         *
00013  *   This program is distributed in the hope that it will be useful,       *
00014  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00015  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00016  *   GNU General Public License for more details.                          *
00017  *                                                                         *
00018  *   You should have received a copy of the GNU General Public License     *
00019  *   along with this program; If not, see <http://www.gnu.org/licenses/>.  *
00020  ***************************************************************************/
00021 
00022 #include "WaitForComposed.h"
00023 #include "WaitForComposed_p.h"
00024 
00025 namespace ktutorial {
00026 
00027 //public:
00028 
00029 WaitForComposed::~WaitForComposed() {
00030     delete d;
00031 }
00032 
00033 void WaitForComposed::setActive(bool active) {
00034     WaitFor::setActive(active);
00035 
00036     QListIterator<WaitFor*> it(d->mWaitFors);
00037     while (it.hasNext()) {
00038         it.next()->setActive(active);
00039     }
00040 }
00041 
00042 void WaitForComposed::add(WaitFor* waitFor) {
00043     if (d->mWaitFors.contains(waitFor)) {
00044         return;
00045     }
00046 
00047     waitFor->setParent(this);
00048     d->mWaitFors.append(waitFor);
00049 
00050     connect(waitFor, SIGNAL(waitEnded(WaitFor*)),
00051             this, SLOT(childWaitEnd(WaitFor*)));
00052 }
00053 
00054 //public slots:
00055 
00056 void WaitForComposed::childWaitEnd(WaitFor* waitFor) {
00057     Q_UNUSED(waitFor);
00058 
00059     Q_ASSERT(d->mWaitFors.contains(waitFor));
00060 
00061     if (!isActive()) {
00062         return;
00063     }
00064 
00065     if (conditionMet()) {
00066         emit waitEnded(this);
00067     }
00068 }
00069 
00070 //protected:
00071 
00072 WaitForComposed::WaitForComposed(): WaitFor(),
00073     d(new WaitForComposedPrivate()) {
00074 }
00075 
00076 QList<WaitFor*>& WaitForComposed::waitFors() const {
00077     return d->mWaitFors;
00078 }
00079 
00080 }