1 | /*
|
---|
2 | * QtMoleculeList.hpp
|
---|
3 | *
|
---|
4 | * Created on: Jan 21, 2010
|
---|
5 | * Author: crueger
|
---|
6 | */
|
---|
7 |
|
---|
8 | #ifndef QTMOLECULELIST_HPP_
|
---|
9 | #define QTMOLECULELIST_HPP_
|
---|
10 |
|
---|
11 | // include config.h
|
---|
12 | #ifdef HAVE_CONFIG_H
|
---|
13 | #include <config.h>
|
---|
14 | #endif
|
---|
15 |
|
---|
16 | #include <QtGui/QItemSelection>
|
---|
17 | #include <QtGui/QStandardItem>
|
---|
18 | #include <QtGui/QStandardItemModel>
|
---|
19 | #include <QTimer>
|
---|
20 |
|
---|
21 | #include <boost/bimap.hpp>
|
---|
22 | #include <boost/thread/recursive_mutex.hpp>
|
---|
23 | #include <map>
|
---|
24 | #include <set>
|
---|
25 | #include <string>
|
---|
26 |
|
---|
27 | #include "UIElements/Views/Qt4/MoleculeList/QtMoleculeItem.hpp"
|
---|
28 | #include "UIElements/Views/Qt4/MoleculeList/QtObservedMoleculeObserver.hpp"
|
---|
29 | #include "UIElements/Qt4/InstanceBoard/QtObservedMolecule.hpp"
|
---|
30 |
|
---|
31 | #include "types.hpp"
|
---|
32 |
|
---|
33 | class QtMoleculeItem;
|
---|
34 | class QtMoleculeListView;
|
---|
35 | class QtObservedInstanceBoard;
|
---|
36 |
|
---|
37 | class QtMoleculeList : public QStandardItemModel
|
---|
38 | {
|
---|
39 | Q_OBJECT
|
---|
40 |
|
---|
41 | public:
|
---|
42 | QtMoleculeList(QtObservedInstanceBoard *_board, QObject *_parent = NULL);
|
---|
43 | virtual ~QtMoleculeList();
|
---|
44 |
|
---|
45 | void resetUpdateTimer();
|
---|
46 |
|
---|
47 | QVariant headerData(int section, Qt::Orientation orientation, int role) const;
|
---|
48 |
|
---|
49 | private slots:
|
---|
50 | void formulaChanged(const QtObservedMolecule::ptr _mol);
|
---|
51 | void nameChanged(const QtObservedMolecule::ptr _mol);
|
---|
52 | void atomcountChanged(const QtObservedMolecule::ptr _mol);
|
---|
53 |
|
---|
54 | void moleculeNameChanged(QStandardItem*);
|
---|
55 | void checkForVisibilityChange(QStandardItem*);
|
---|
56 |
|
---|
57 | signals:
|
---|
58 | void moleculesVisibilityChanged(const moleculeId_t, bool);
|
---|
59 |
|
---|
60 | private slots:
|
---|
61 | void moleculeInserted(QtObservedMolecule::ptr _mol);
|
---|
62 | void moleculeRemoved(const moleculeId_t _id);
|
---|
63 | void moleculeIndexChanged(const moleculeId_t _oldid, const moleculeId_t _newid);
|
---|
64 |
|
---|
65 | private:
|
---|
66 | friend class QtMoleculeListView;
|
---|
67 |
|
---|
68 | bool isMoleculeItemPresent(const moleculeId_t _molid) const;
|
---|
69 | QtMoleculeItem * MoleculeIdToItem(const moleculeId_t _molid) const;
|
---|
70 | const moleculeId_t ItemToMoleculeId(const QtMoleculeItem * const _item) const;
|
---|
71 | const QModelIndex MoleculeIdToIndex(const moleculeId_t _id) const;
|
---|
72 | const moleculeId_t IndexToMoleculeId(const QModelIndex &_index) const;
|
---|
73 | QtMoleculeItem * getSpecificMoleculeItem(
|
---|
74 | const QtMoleculeItem * const _item,
|
---|
75 | const enum QtMoleculeItem::COLUMNTYPES _type) const;
|
---|
76 | bool isGroupItemPresent(const std::string &_formula) const;
|
---|
77 | const std::string& GroupItemToFormula(const QStandardItem * const _item) const;
|
---|
78 | QStandardItem * FormulaToGroupItem(const std::string &_formula) const;
|
---|
79 | QStandardItem * getSpecificGroupItem(
|
---|
80 | const QStandardItem * const _item,
|
---|
81 | const enum QtMoleculeItem::COLUMNTYPES _type) const;
|
---|
82 |
|
---|
83 | std::string addMolecule(
|
---|
84 | QtObservedMolecule::ptr &_ObservedMolecule);
|
---|
85 | void addGroupItem(
|
---|
86 | QStandardItem *&mainitem,
|
---|
87 | const std::string &_molecule_formula);
|
---|
88 | QList<QStandardItem *> createMoleculeItems(
|
---|
89 | QtObservedMolecule::ptr &_ObservedMolecule,
|
---|
90 | std::string &molecule_formula);
|
---|
91 | void removeMoleculeItem(QtMoleculeItem * const _item);
|
---|
92 | int setOccurrence(QStandardItem * const _groupitem);
|
---|
93 | void setVisibilityForMoleculeItem(QtMoleculeItem* _item);
|
---|
94 | void setVisibilityForGroupItem(QStandardItem* _item);
|
---|
95 | void moveItem(QtMoleculeItem *_molitem, const std::string &_new_formula);
|
---|
96 |
|
---|
97 | // void updateItemStates();
|
---|
98 |
|
---|
99 | //!> reference to InstanceBoard
|
---|
100 | QtObservedInstanceBoard *board;
|
---|
101 |
|
---|
102 | typedef std::map<std::string, unsigned int> FormulaVisibilityCountMap_t;
|
---|
103 | FormulaVisibilityCountMap_t FormulaVisibilityCountMap;
|
---|
104 |
|
---|
105 | typedef boost::bimap<std::string, QStandardItem*> FormulaTreeItemBiMap_t;
|
---|
106 | //!> map of (unique) formulas in the world
|
---|
107 | FormulaTreeItemBiMap_t FormulaItemBiMap;
|
---|
108 |
|
---|
109 | typedef std::map<moleculeId_t, std::string> MoleculeFormulaMap_t;
|
---|
110 | //!> map of (unique) formulas in the world
|
---|
111 | MoleculeFormulaMap_t MoleculeFormulaMap;
|
---|
112 |
|
---|
113 | typedef boost::bimap<moleculeId_t, QtMoleculeItem*> MoleculeItemBiMap_t;
|
---|
114 | MoleculeItemBiMap_t MoleculeItemBiMap;
|
---|
115 |
|
---|
116 | typedef std::set< moleculeId_t > list_of_molecules_t;
|
---|
117 | typedef std::set< std::pair<moleculeId_t, QtMoleculeItem::COLUMNTYPES> > list_of_molecule_items_t;
|
---|
118 | typedef std::set< std::pair<std::string, QtMoleculeItem::COLUMNTYPES> > list_of_group_items_t;
|
---|
119 |
|
---|
120 | //!> listens to all QtObservedMolecule and relays important events to us
|
---|
121 | QtObservedMoleculeObserver observer;
|
---|
122 | };
|
---|
123 |
|
---|
124 | #endif /* QTMOLECULELIST_HPP_ */
|
---|