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