| 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 <map>
|
|---|
| 23 | #include <set>
|
|---|
| 24 | #include <string>
|
|---|
| 25 |
|
|---|
| 26 | #include "CodePatterns/Observer/Observer.hpp"
|
|---|
| 27 |
|
|---|
| 28 | #include "UIElements/Views/Qt4/MoleculeList/QtMoleculeItem.hpp"
|
|---|
| 29 |
|
|---|
| 30 | #include "types.hpp"
|
|---|
| 31 |
|
|---|
| 32 | class molecule;
|
|---|
| 33 | class MoleculeListClass;
|
|---|
| 34 | class QtMoleculeItem;
|
|---|
| 35 | class QtMoleculeListView;
|
|---|
| 36 |
|
|---|
| 37 | class QtMoleculeList : public QStandardItemModel, public Observer
|
|---|
| 38 | {
|
|---|
| 39 | Q_OBJECT
|
|---|
| 40 |
|
|---|
| 41 | public:
|
|---|
| 42 | QtMoleculeList();
|
|---|
| 43 | virtual ~QtMoleculeList();
|
|---|
| 44 |
|
|---|
| 45 | protected:
|
|---|
| 46 | virtual void update(Observable *publisher);
|
|---|
| 47 | virtual void recieveNotification(Observable *publisher, Notification_ptr notification);
|
|---|
| 48 | virtual void subjectKilled(Observable *publisher);
|
|---|
| 49 |
|
|---|
| 50 | void refill();
|
|---|
| 51 |
|
|---|
| 52 | QVariant headerData(int section, Qt::Orientation orientation, int role) const;
|
|---|
| 53 |
|
|---|
| 54 | private slots:
|
|---|
| 55 | void moleculeChanged();
|
|---|
| 56 | // void visibilityChanged(QStandardItem*, int);
|
|---|
| 57 | void checkForVisibilityChange(QStandardItem*);
|
|---|
| 58 | void checkState();
|
|---|
| 59 |
|
|---|
| 60 | friend class QtMoleculeItem;
|
|---|
| 61 |
|
|---|
| 62 | void readdItem(QtMoleculeItem *_molitem);
|
|---|
| 63 |
|
|---|
| 64 | signals:
|
|---|
| 65 | void moleculeSelected(molecule*);
|
|---|
| 66 | void moleculeUnSelected(molecule*);
|
|---|
| 67 | void moleculesVisibilityChanged(const moleculeId_t, bool);
|
|---|
| 68 |
|
|---|
| 69 | private:
|
|---|
| 70 |
|
|---|
| 71 | bool changing;
|
|---|
| 72 | bool ChangingChildrensVisibility;
|
|---|
| 73 | bool list_accessing;
|
|---|
| 74 |
|
|---|
| 75 | //!> informs the view in regular intervals about updates
|
|---|
| 76 | QTimer *update_timer;
|
|---|
| 77 |
|
|---|
| 78 | //!> how often per second update is signalled to view
|
|---|
| 79 | static const unsigned int update_times_per_second;
|
|---|
| 80 |
|
|---|
| 81 | friend class QtMoleculeListView;
|
|---|
| 82 |
|
|---|
| 83 | QtMoleculeItem * MoleculeIdToItem(const moleculeId_t _molid) const;
|
|---|
| 84 | const moleculeId_t IndexToMoleculeId(const QModelIndex &_index) const;
|
|---|
| 85 | const moleculeId_t ItemToMoleculeId(const QtMoleculeItem * const _item) const;
|
|---|
| 86 |
|
|---|
| 87 | void addMolecule(const molecule * const _mol);
|
|---|
| 88 | void addGroupItem(QStandardItem *&mainitem, const std::string &_molecule_formula);
|
|---|
| 89 | void addMoleculeItem(QStandardItem *_groupitem, const moleculeId_t _molid, const std::string &molecule_formula);
|
|---|
| 90 | void removeItem(QtMoleculeItem * const _item);
|
|---|
| 91 | int setOccurrence(QStandardItem * const _groupitem);
|
|---|
| 92 | bool areAnyItemsDirty();
|
|---|
| 93 | void addToBeSetOccurrence(QStandardItem *_groupitem);
|
|---|
| 94 | void setVisibilityForMoleculeItem(QtMoleculeItem* _item);
|
|---|
| 95 | void setVisibilityForGroupItem(QStandardItem* _item);
|
|---|
| 96 |
|
|---|
| 97 | void informDirtyState(QtMoleculeItem *_item, const QtMoleculeItem::MoveTypes _type);
|
|---|
| 98 |
|
|---|
| 99 | void updateItemStates();
|
|---|
| 100 |
|
|---|
| 101 | typedef std::map<std::string, unsigned int> FormulaVisibilityCountMap_t;
|
|---|
| 102 | FormulaVisibilityCountMap_t FormulaVisibilityCountMap;
|
|---|
| 103 |
|
|---|
| 104 | typedef std::map<std::string, QStandardItem*> FormulaTreeItemMap_t;
|
|---|
| 105 | //!> map of (unique) formulas in the world
|
|---|
| 106 | FormulaTreeItemMap_t formula;
|
|---|
| 107 |
|
|---|
| 108 | typedef boost::bimap<moleculeId_t, QtMoleculeItem*> MoleculeItemBiMap_t;
|
|---|
| 109 | MoleculeItemBiMap_t MoleculeItemBiMap;
|
|---|
| 110 |
|
|---|
| 111 | //!> callback function to hand over to items that inform about requiring update
|
|---|
| 112 | const QtMoleculeItem::emitDirtyState_t callback_DirtyItems;
|
|---|
| 113 |
|
|---|
| 114 | typedef std::set<QtMoleculeItem*> list_of_items_t;
|
|---|
| 115 | //!> list of items that need an update
|
|---|
| 116 | list_of_items_t dirtyItems;
|
|---|
| 117 | //!> list of items that need an update of visibility
|
|---|
| 118 | list_of_items_t visibilityItems;
|
|---|
| 119 | //!> list of items to molecule's whose formulas has changed and need to be moved
|
|---|
| 120 | list_of_items_t toBeMovedItems;
|
|---|
| 121 | //!> list of items to new molecules which need to be added
|
|---|
| 122 | std::vector<const molecule *> newItems;
|
|---|
| 123 | //!> list of items to molecules that have been removed
|
|---|
| 124 | std::vector<const molecule *> toBeRemovedItems;
|
|---|
| 125 | //!> list of group items that need update due to moved molecule items
|
|---|
| 126 | std::set<QStandardItem*> toBeSetOccurrenceItems;
|
|---|
| 127 | //!> list of group items that need visibility update due to changed molecule items
|
|---|
| 128 | std::set<QStandardItem*> toBeSetVisibilityItems;
|
|---|
| 129 | };
|
|---|
| 130 |
|
|---|
| 131 | #endif /* QTMOLECULELIST_HPP_ */
|
|---|