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