| 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 "CodePatterns/Observer/Observer.hpp"
|
|---|
| 28 |
|
|---|
| 29 | #include "UIElements/Views/Qt4/MoleculeList/QtMoleculeItem.hpp"
|
|---|
| 30 |
|
|---|
| 31 | #include "types.hpp"
|
|---|
| 32 |
|
|---|
| 33 | class molecule;
|
|---|
| 34 | class MoleculeListClass;
|
|---|
| 35 | class QtMoleculeItem;
|
|---|
| 36 | class QtMoleculeListView;
|
|---|
| 37 |
|
|---|
| 38 | class QtMoleculeList : public QStandardItemModel, public Observer
|
|---|
| 39 | {
|
|---|
| 40 | Q_OBJECT
|
|---|
| 41 |
|
|---|
| 42 | public:
|
|---|
| 43 | QtMoleculeList();
|
|---|
| 44 | virtual ~QtMoleculeList();
|
|---|
| 45 |
|
|---|
| 46 | protected:
|
|---|
| 47 | virtual void update(Observable *publisher);
|
|---|
| 48 | virtual void recieveNotification(Observable *publisher, Notification_ptr notification);
|
|---|
| 49 | virtual void subjectKilled(Observable *publisher);
|
|---|
| 50 |
|
|---|
| 51 | void refill();
|
|---|
| 52 |
|
|---|
| 53 | QVariant headerData(int section, Qt::Orientation orientation, int role) const;
|
|---|
| 54 |
|
|---|
| 55 | private slots:
|
|---|
| 56 | void moleculeChanged();
|
|---|
| 57 | // void visibilityChanged(QStandardItem*, int);
|
|---|
| 58 | void checkForVisibilityChange(QStandardItem*);
|
|---|
| 59 | void checkState();
|
|---|
| 60 |
|
|---|
| 61 | friend class QtMoleculeItem;
|
|---|
| 62 |
|
|---|
| 63 | std::string readdItem(QtMoleculeItem *_molitem);
|
|---|
| 64 |
|
|---|
| 65 | signals:
|
|---|
| 66 | void moleculeSelected(molecule*);
|
|---|
| 67 | void moleculeUnSelected(molecule*);
|
|---|
| 68 | void moleculesVisibilityChanged(const moleculeId_t, bool);
|
|---|
| 69 |
|
|---|
| 70 | private:
|
|---|
| 71 |
|
|---|
| 72 | bool ChangingChildrensVisibility;
|
|---|
| 73 |
|
|---|
| 74 | mutable boost::recursive_mutex listAccessing_mutex;
|
|---|
| 75 | mutable boost::recursive_mutex refill_mutex;
|
|---|
| 76 | mutable boost::recursive_mutex map_mutex;
|
|---|
| 77 |
|
|---|
| 78 | //!> informs the view in regular intervals about updates
|
|---|
| 79 | QTimer *update_timer;
|
|---|
| 80 |
|
|---|
| 81 | //!> how often per second update is signalled to view
|
|---|
| 82 | static const unsigned int update_times_per_second;
|
|---|
| 83 |
|
|---|
| 84 | friend class QtMoleculeListView;
|
|---|
| 85 |
|
|---|
| 86 | bool isMoleculeItemPresent(const moleculeId_t _molid) const;
|
|---|
| 87 | QtMoleculeItem * MoleculeIdToItem(const moleculeId_t _molid) const;
|
|---|
| 88 | const moleculeId_t IndexToMoleculeId(const QModelIndex &_index) const;
|
|---|
| 89 | const moleculeId_t ItemToMoleculeId(const QtMoleculeItem * const _item) const;
|
|---|
| 90 | QtMoleculeItem * getSpecificMoleculeItem(
|
|---|
| 91 | const QtMoleculeItem * const _item,
|
|---|
| 92 | const enum QtMoleculeItem::COLUMNTYPES _type) const;
|
|---|
| 93 | bool isGroupItemPresent(const std::string &_formula) const;
|
|---|
| 94 | const std::string& GroupItemToFormula(const QStandardItem * const _item) const;
|
|---|
| 95 | QStandardItem * FormulaToGroupItem(const std::string &_formula) const;
|
|---|
| 96 | QStandardItem * getSpecificGroupItem(
|
|---|
| 97 | const QStandardItem * const _item,
|
|---|
| 98 | const enum QtMoleculeItem::COLUMNTYPES _type) const;
|
|---|
| 99 |
|
|---|
| 100 | std::string addMolecule(const molecule * const _mol);
|
|---|
| 101 | void addGroupItem(QStandardItem *&mainitem, const std::string &_molecule_formula);
|
|---|
| 102 | void addMoleculeItem(QStandardItem *_groupitem, const moleculeId_t _molid, const std::string &molecule_formula);
|
|---|
| 103 | void removeMoleculeItem(QtMoleculeItem * const _item);
|
|---|
| 104 | int setOccurrence(QStandardItem * const _groupitem);
|
|---|
| 105 | bool areAnyItemsDirty();
|
|---|
| 106 | void setVisibilityForMoleculeItem(QtMoleculeItem* _item);
|
|---|
| 107 | void setVisibilityForGroupItem(QStandardItem* _item);
|
|---|
| 108 |
|
|---|
| 109 | void informDirtyState(
|
|---|
| 110 | const moleculeId_t _id,
|
|---|
| 111 | const QtMoleculeItem::COLUMNTYPES _type,
|
|---|
| 112 | const QtMoleculeItem::MoveTypes _movetype);
|
|---|
| 113 |
|
|---|
| 114 | void updateItemStates();
|
|---|
| 115 |
|
|---|
| 116 | typedef std::map<std::string, unsigned int> FormulaVisibilityCountMap_t;
|
|---|
| 117 | FormulaVisibilityCountMap_t FormulaVisibilityCountMap;
|
|---|
| 118 |
|
|---|
| 119 | typedef boost::bimap<std::string, QStandardItem*> FormulaTreeItemBiMap_t;
|
|---|
| 120 | //!> map of (unique) formulas in the world
|
|---|
| 121 | FormulaTreeItemBiMap_t FormulaItemBiMap;
|
|---|
| 122 |
|
|---|
| 123 | typedef std::map<moleculeId_t, std::string> MoleculeFormulaMap_t;
|
|---|
| 124 | //!> map of (unique) formulas in the world
|
|---|
| 125 | MoleculeFormulaMap_t MoleculeFormulaMap;
|
|---|
| 126 |
|
|---|
| 127 | typedef boost::bimap<moleculeId_t, QtMoleculeItem*> MoleculeItemBiMap_t;
|
|---|
| 128 | MoleculeItemBiMap_t MoleculeItemBiMap;
|
|---|
| 129 |
|
|---|
| 130 | //!> callback function to hand over to items that inform about requiring update
|
|---|
| 131 | const QtMoleculeItem::emitDirtyState_t callback_DirtyItems;
|
|---|
| 132 |
|
|---|
| 133 | typedef std::set< moleculeId_t > list_of_molecules_t;
|
|---|
| 134 | typedef std::set< std::pair<moleculeId_t, QtMoleculeItem::COLUMNTYPES> > list_of_molecule_items_t;
|
|---|
| 135 | typedef std::set< std::pair<std::string, QtMoleculeItem::COLUMNTYPES> > list_of_group_items_t;
|
|---|
| 136 | //!> list of molecule items that need an update
|
|---|
| 137 | list_of_molecule_items_t dirtyMolItems;
|
|---|
| 138 | //!> list of molecule items that need an update of visibility
|
|---|
| 139 | list_of_molecules_t visibilityMolItems;
|
|---|
| 140 | //!> list of group items that need an update
|
|---|
| 141 | list_of_group_items_t dirtyGroupItems;
|
|---|
| 142 | //!> list of group items that need an update of visibility
|
|---|
| 143 | list_of_group_items_t visibilityGroupItems;
|
|---|
| 144 | //!> list of new molecules which need to be added
|
|---|
| 145 | std::vector<moleculeId_t> newMolecules;
|
|---|
| 146 | //!> list of molecules that have been removed
|
|---|
| 147 | std::vector<moleculeId_t> removedMolecules;
|
|---|
| 148 | //!> list of molecule items to molecule's whose formulas has changed and need to be moved
|
|---|
| 149 | list_of_molecules_t toBeMovedItems;
|
|---|
| 150 | };
|
|---|
| 151 |
|
|---|
| 152 | #endif /* QTMOLECULELIST_HPP_ */
|
|---|