Beispiel #1
0
void Molecule::removeBond(unsigned long id)
{
    if (id < m_bonds.size()) {
        Q_D(Molecule);
        if (m_bonds[id] == 0)
            return;

        d->invalidRings = true;
        m_invalidPartialCharges = true;
        m_invalidAromaticity = true;
        Bond *bond = m_bonds[id];
        m_bonds[id] = 0;
        // Delete the bond from the list and reorder the remaining bonds
        int index = bond->index();
        m_bondList.removeAt(index);
        for (int i = index; i < m_bondList.size(); ++i) {
            m_bondList[i]->setIndex(i);
        }

        // Also delete the bond from the attached atoms
        if (m_atoms.size() > bond->beginAtomId()) {
            if (m_atoms[bond->beginAtomId()])
                m_atoms[bond->beginAtomId()]->removeBond(id);
        }
        if (m_atoms.size() > bond->endAtomId()) {
            if (m_atoms[bond->endAtomId()])
                m_atoms[bond->endAtomId()]->removeBond(id);
        }

        disconnect(bond, SIGNAL(updated()), this, SLOT(updateBond()));
        emit bondRemoved(bond);
        bond->deleteLater();
    }
}
void MoleculeWatcher::bondChanged(const Bond *bond, Molecule::ChangeType changeType)
{
    switch(changeType){
        case Molecule::BondAdded:
            Q_EMIT bondAdded(bond);
            break;
        case Molecule::BondRemoved:
            Q_EMIT bondRemoved(bond);
            break;
        case Molecule::BondOrderChanged:
            Q_EMIT bondOrderChanged(bond);
        default:
            break;
    }
}