| 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(ObservedValue_Index_t, bool);
|
|---|
| 59 | void MayStartSelections();
|
|---|
| 60 | void MayNotStartSelections();
|
|---|
| 61 |
|
|---|
| 62 | private slots:
|
|---|
| 63 | void moleculeInserted(QtObservedMolecule::ptr _mol);
|
|---|
| 64 | void moleculeRemoved(ObservedValue_Index_t _id);
|
|---|
| 65 |
|
|---|
| 66 | private:
|
|---|
| 67 | friend class QtMoleculeListView;
|
|---|
| 68 |
|
|---|
| 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;
|
|---|
| 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 |
|
|---|
| 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);
|
|---|
| 92 | void removeMoleculeItem(QtMoleculeItem * const _item);
|
|---|
| 93 | int setOccurrence(QStandardItem * const _groupitem);
|
|---|
| 94 | void setVisibilityForMoleculeItem(QtMoleculeItem* _item);
|
|---|
| 95 | void setVisibilityForGroupItem(QStandardItem* _item);
|
|---|
| 96 | void moveItem(QtMoleculeItem *_molitem, const std::string &_new_formula);
|
|---|
| 97 |
|
|---|
| 98 | // void updateItemStates();
|
|---|
| 99 |
|
|---|
| 100 | //!> reference to InstanceBoard
|
|---|
| 101 | QtObservedInstanceBoard *board;
|
|---|
| 102 |
|
|---|
| 103 | typedef std::map<std::string, unsigned int> FormulaVisibilityCountMap_t;
|
|---|
| 104 | FormulaVisibilityCountMap_t FormulaVisibilityCountMap;
|
|---|
| 105 |
|
|---|
| 106 | typedef boost::bimap<std::string, QStandardItem*> FormulaTreeItemBiMap_t;
|
|---|
| 107 | //!> map of (unique) formulas in the world
|
|---|
| 108 | FormulaTreeItemBiMap_t FormulaItemBiMap;
|
|---|
| 109 |
|
|---|
| 110 | typedef std::map<ObservedValue_Index_t, std::string> MoleculeFormulaMap_t;
|
|---|
| 111 | //!> map of (unique) formulas in the world
|
|---|
| 112 | MoleculeFormulaMap_t MoleculeFormulaMap;
|
|---|
| 113 |
|
|---|
| 114 | typedef boost::bimap<ObservedValue_Index_t, QtMoleculeItem*> MoleculeItemBiMap_t;
|
|---|
| 115 | MoleculeItemBiMap_t MoleculeItemBiMap;
|
|---|
| 116 |
|
|---|
| 117 | //!> listens to all QtObservedMolecule and relays important events to us
|
|---|
| 118 | QtObservedMoleculeObserver observer;
|
|---|
| 119 |
|
|---|
| 120 | //!> flag to indicate name change cam from outside
|
|---|
| 121 | bool nameIsChanged;
|
|---|
| 122 | };
|
|---|
| 123 |
|
|---|
| 124 | #endif /* QTMOLECULELIST_HPP_ */
|
|---|