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 | emitDirtyState_t _emitDirtyState) :
|
---|
37 | QtMoleculeItem(_molid, channellist_atomcount, QtMoleculeItem::NeedsMove, _emitDirtyState),
|
---|
38 | molref(getMolecule()),
|
---|
39 | atomcount(
|
---|
40 | molref,
|
---|
41 | boost::bind(&QtMoleculeItem_atomcount::updateAtomCount, this),
|
---|
42 | "MoleculeItem_atomcount_"+toString(_molid),
|
---|
43 | updateAtomCount(),
|
---|
44 | channellist_atomcount)
|
---|
45 | {
|
---|
46 | // cannot call pure virtual function in QtMoleculeItem's cstor
|
---|
47 | internal_updateState();
|
---|
48 | }
|
---|
49 |
|
---|
50 | int updateAtomCount() const
|
---|
51 | {
|
---|
52 | const molecule * const mol = getMolecule();
|
---|
53 | if (mol != NULL)
|
---|
54 | return mol->getAtomCount();
|
---|
55 | else
|
---|
56 | return -1;
|
---|
57 | }
|
---|
58 |
|
---|
59 | /** Performs the update of the molecule's atomcount.
|
---|
60 | *
|
---|
61 | */
|
---|
62 | void internal_updateState()
|
---|
63 | {
|
---|
64 | setText(QString::number(atomcount.get()));
|
---|
65 | }
|
---|
66 |
|
---|
67 | QtMoleculeItem::COLUMNTYPES getType() const
|
---|
68 | { return QtMoleculeItem::ATOMCOUNT; }
|
---|
69 |
|
---|
70 | //!> notification channels of molecule specific to this molecule item, required for update
|
---|
71 | static const QtMoleculeItem::channellist_t channellist_atomcount;
|
---|
72 |
|
---|
73 | //!> temporary value for molecule
|
---|
74 | const molecule * const molref;
|
---|
75 |
|
---|
76 | //!> contains visibility state
|
---|
77 | ObservedValue<int> atomcount;
|
---|
78 | };
|
---|
79 |
|
---|
80 |
|
---|
81 |
|
---|
82 | #endif /* QTMOLECULEITEM_ATOMCOUNT_HPP_ */
|
---|