1 | /*
|
---|
2 | * QtMoleculeItem_atomcount.hpp
|
---|
3 | *
|
---|
4 | * Created on: Jan 18, 2015
|
---|
5 | * Author: heber
|
---|
6 | */
|
---|
7 |
|
---|
8 | #ifndef QTMOLECULEITEM_ATOMCOUNT_HPP_
|
---|
9 | #define QTMOLECULEITEM_ATOMCOUNT_HPP_
|
---|
10 |
|
---|
11 | // include config.h
|
---|
12 | #ifdef HAVE_CONFIG_H
|
---|
13 | #include <config.h>
|
---|
14 | #endif
|
---|
15 |
|
---|
16 | #include "UIElements/Views/Qt4/MoleculeList/QtMoleculeItem.hpp"
|
---|
17 |
|
---|
18 | #include "CodePatterns/ObservedValue.hpp"
|
---|
19 |
|
---|
20 | #include "Descriptors/MoleculeIdDescriptor.hpp"
|
---|
21 | #include "molecule.hpp"
|
---|
22 | #include "World.hpp"
|
---|
23 |
|
---|
24 | class QtMoleculeItemFactory;
|
---|
25 |
|
---|
26 | /** This class contains the atomcount of a molecule and keeps it up to date.
|
---|
27 | *
|
---|
28 | */
|
---|
29 | class QtMoleculeItem_atomcount : public QtMoleculeItem
|
---|
30 | {
|
---|
31 | //!> only allow factory to instantiate items
|
---|
32 | friend class QtMoleculeItemFactory;
|
---|
33 |
|
---|
34 | QtMoleculeItem_atomcount(
|
---|
35 | const moleculeId_t _molid,
|
---|
36 | const emitDirtyState_t &_emitDirtyState,
|
---|
37 | const emitSubjectKilledState_t &_emitSubjectKilledState) :
|
---|
38 | QtMoleculeItem(_molid, channellist_atomcount, QtMoleculeItem::NeedsMove, _emitDirtyState, _emitSubjectKilledState),
|
---|
39 | molref(getMolecule()),
|
---|
40 | atomcount(
|
---|
41 | molref,
|
---|
42 | boost::bind(&QtMoleculeItem_atomcount::updateAtomCount, this),
|
---|
43 | "MoleculeItem_atomcount_"+toString(_molid),
|
---|
44 | updateAtomCount(),
|
---|
45 | channellist_atomcount)
|
---|
46 | {
|
---|
47 | signOnToMolecule();
|
---|
48 | // cannot call pure virtual function in QtMoleculeItem's cstor
|
---|
49 | internal_updateState();
|
---|
50 | }
|
---|
51 |
|
---|
52 | ~QtMoleculeItem_atomcount()
|
---|
53 | {
|
---|
54 | signOffFromMolecule();
|
---|
55 | }
|
---|
56 |
|
---|
57 | int updateAtomCount() const
|
---|
58 | {
|
---|
59 | const molecule * const mol = getMolecule();
|
---|
60 | if (mol != NULL)
|
---|
61 | return mol->getAtomCount();
|
---|
62 | else
|
---|
63 | return -1;
|
---|
64 | }
|
---|
65 |
|
---|
66 | /** Performs the update of the molecule's atomcount.
|
---|
67 | *
|
---|
68 | */
|
---|
69 | void internal_updateState()
|
---|
70 | {
|
---|
71 | setText(QString::number(atomcount.get()));
|
---|
72 | }
|
---|
73 |
|
---|
74 | QtMoleculeItem::COLUMNTYPES getType() const
|
---|
75 | { return QtMoleculeItem::ATOMCOUNT; }
|
---|
76 |
|
---|
77 | //!> notification channels of molecule specific to this molecule item, required for update
|
---|
78 | static const QtMoleculeItem::channellist_t channellist_atomcount;
|
---|
79 |
|
---|
80 | //!> temporary value for molecule
|
---|
81 | const molecule * const molref;
|
---|
82 |
|
---|
83 | //!> contains visibility state
|
---|
84 | ObservedValue<int> atomcount;
|
---|
85 | };
|
---|
86 |
|
---|
87 |
|
---|
88 |
|
---|
89 | #endif /* QTMOLECULEITEM_ATOMCOUNT_HPP_ */
|
---|