/*
* Project: MoleCuilder
* Description: creates and alters molecular systems
* Copyright (C) 2016 Frederik Heber. All rights reserved.
*
*
* This file is part of MoleCuilder.
*
* MoleCuilder is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* MoleCuilder is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with MoleCuilder. If not, see .
*/
/*
* QtObservedMoleculeObserver.cpp
*
* Created on: Mar 17, 2016
* Author: heber
*/
// include config.h
#ifdef HAVE_CONFIG_H
#include
#endif
#include "QtObservedMoleculeObserver.hpp"
#include "UIElements/Qt4/InstanceBoard/QtObservedInstanceBoard.hpp"
#include "CodePatterns/MemDebug.hpp"
QtObservedMoleculeObserver::QtObservedMoleculeObserver(
QtObservedInstanceBoard *_board,
QWidget * _parent) :
QWidget(_parent),
board(_board)
{
connect(_board, SIGNAL(moleculeInserted(QtObservedMolecule::ptr)),
this, SLOT(moleculeInserted(QtObservedMolecule::ptr)));
connect(_board, SIGNAL(moleculeRemoved(const moleculeId_t)),
this, SLOT(moleculeRemoved(const moleculeId_t)));
}
void QtObservedMoleculeObserver::moleculeInserted(const QtObservedMolecule::ptr _molecule)
{
connect( _molecule.get(), SIGNAL(atomcountChanged()), this, SLOT(atomcountChanged()));
connect( _molecule.get(), SIGNAL(formulaChanged()), this, SLOT(formulaChanged()));
connect( _molecule.get(), SIGNAL(nameChanged()), this, SLOT(nameChanged()));
connect( _molecule.get(), SIGNAL(selectedChanged()), this, SLOT(selectionChanged()));
emit MoleculeInserted(_molecule);
}
void QtObservedMoleculeObserver::moleculeRemoved(const moleculeId_t _moleculeid)
{
const QtObservedMolecule::ptr mol = board->getObservedMolecule(_moleculeid);
disconnect( mol.get(), SIGNAL(atomcountChanged()), this, SLOT(atomcountChanged()));
disconnect( mol.get(), SIGNAL(formulaChanged()), this, SLOT(formulaChanged()));
disconnect( mol.get(), SIGNAL(nameChanged()), this, SLOT(nameChanged()));
disconnect( mol.get(), SIGNAL(selectedChanged()), this, SLOT(selectionChanged()));
emit MoleculeRemoved(_moleculeid);
}
void QtObservedMoleculeObserver::atomcountChanged()
{
QtObservedMolecule * const mol = static_cast(sender());
emit AtomCountChanged(mol->getRef());
}
void QtObservedMoleculeObserver::formulaChanged()
{
QtObservedMolecule * const mol = static_cast(sender());
emit FormulaChanged(mol->getRef());
}
void QtObservedMoleculeObserver::nameChanged()
{
QtObservedMolecule * const mol = static_cast(sender());
emit NameChanged(mol->getRef());
}
void QtObservedMoleculeObserver::selectionChanged()
{
QtObservedMolecule * const mol = static_cast(sender());
emit SelectionChanged(mol->getRef());
}