/* * QtMoleculeItem.hpp * * Created on: Jan 17, 2015 * Author: heber */ #ifndef QTMOLECULEITEM_HPP_ #define QTMOLECULEITEM_HPP_ // include config.h #ifdef HAVE_CONFIG_H #include #endif #include #include #include "CodePatterns/Observer/Observer.hpp" #include #include #include #include #include "molecule.hpp" /** This class describes the general interface for a specific item in a QtAbstractItemModel * to contain a specific piece of information about a specific molecule. * * To this end, we need a ref to the molecule for updating the information when * necessary and we need to know the channels we have to listen to know when an * update is necessary. * * This class takes care of of all the rest: * -# informing QtMoleculeList about required update ("dirty") * -# relaying updateState() call from QtMoleculeList to the specific internal_updateState() */ class QtMoleculeItem : public QStandardItem, public Observer { public: //!> typedef for a list of notification channels required, to know when to update typedef Observable::channels_t channellist_t; //!> enum states whether an item's formula changed or not enum MoveTypes { NeedsMove, DoesNotMove }; //!> enumerates all different item types, coinciding with column in QtMoleculeList enum COLUMNTYPES {NAME,VISIBILITY,ATOMCOUNT,FORMULA,OCCURRENCE,COLUMNTYPES_MAX}; //!> typedef for callback function to model to inform when we need update typedef const boost::function emitDirtyState_t; //!> typedef for callback function to model to inform when our subjectKilled() was called typedef const boost::function emitSubjectKilledState_t; QtMoleculeItem( const moleculeId_t _molid, const channellist_t &_channellist, const enum MoveTypes _movetype, const emitDirtyState_t _emitDirtyState, const emitSubjectKilledState_t _emitSubjectKilledState); virtual ~QtMoleculeItem(); /** Update the state of this item. * */ void updateState(); /** Const getter to this item's molecule. * * \return const ref to \a mol */ const molecule * const getMolecule() const; /** Getter for the id of the molecule this item is associated to * * \return id of molecule */ moleculeId_t getMoleculeId() const { return molid; } /** Returns the type of this QtMoleculeItem, i.e. the column in QtMoleculeList. * * @return type of this item */ virtual QtMoleculeItem::COLUMNTYPES getType() const = 0; private: void update(Observable *publisher); void recieveNotification(Observable *publisher, Notification_ptr notification); void subjectKilled(Observable *publisher); protected: void signOnToMolecule(); void signOffFromMolecule(); protected: /** This function needs to be implemented to make the specific update. * */ virtual void internal_updateState() = 0; //!> molecule we are signed on to const moleculeId_t molid; private: //!> move type for this specific item, set this when implementing const enum MoveTypes movetype; //!> ref to the specific static list of channels we are signed on to const channellist_t &channellist; //!> the Observable we are signed on, also indicates whether we are sign on (not NULL) const Observable * owner; //!> states that this item needs to be updated bool dirty; //!> bound callback function to inform model about change const emitDirtyState_t emitDirtyState; //!> bound callback function to inform model about change const emitSubjectKilledState_t emitSubjectKilledState; //!> this protects the signing on and off mutable boost::recursive_mutex owner_mutex; }; #endif /* QTMOLECULEITEM_HPP_ */