[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>
|
---|
[3eb91c] | 22 | #include <map>
|
---|
[53c1ff] | 23 | #include <set>
|
---|
[3eb91c] | 24 | #include <string>
|
---|
| 25 |
|
---|
[02ce36] | 26 | #include "CodePatterns/Observer/Observer.hpp"
|
---|
[b47bfc] | 27 |
|
---|
[53c1ff] | 28 | #include "UIElements/Views/Qt4/MoleculeList/QtMoleculeItem.hpp"
|
---|
| 29 |
|
---|
[739ee9] | 30 | #include "types.hpp"
|
---|
| 31 |
|
---|
[b47bfc] | 32 | class molecule;
|
---|
| 33 | class MoleculeListClass;
|
---|
[53c1ff] | 34 | class QtMoleculeItem;
|
---|
[f62e60] | 35 | class QtMoleculeListView;
|
---|
[b47bfc] | 36 |
|
---|
[8ccf3b] | 37 | class QtMoleculeList : public QStandardItemModel, public Observer
|
---|
[b47bfc] | 38 | {
|
---|
| 39 | Q_OBJECT
|
---|
| 40 |
|
---|
| 41 | public:
|
---|
[8ccf3b] | 42 | QtMoleculeList();
|
---|
[0eb7bf3] | 43 | virtual ~QtMoleculeList();
|
---|
[b47bfc] | 44 |
|
---|
| 45 | protected:
|
---|
| 46 | virtual void update(Observable *publisher);
|
---|
[3eb91c] | 47 | virtual void recieveNotification(Observable *publisher, Notification_ptr notification);
|
---|
[b47bfc] | 48 | virtual void subjectKilled(Observable *publisher);
|
---|
| 49 |
|
---|
[53c1ff] | 50 | void refill();
|
---|
[b47bfc] | 51 |
|
---|
[1c3390] | 52 | QVariant headerData(int section, Qt::Orientation orientation, int role) const;
|
---|
| 53 |
|
---|
[b47bfc] | 54 | private slots:
|
---|
[79b59b] | 55 | void moleculeChanged();
|
---|
[8ccf3b] | 56 | // void visibilityChanged(QStandardItem*, int);
|
---|
[2696b1] | 57 | void checkForVisibilityChange(QStandardItem*);
|
---|
[53c1ff] | 58 | void checkState();
|
---|
[8ccf3b] | 59 |
|
---|
[53c1ff] | 60 | friend class QtMoleculeItem;
|
---|
[b47bfc] | 61 |
|
---|
[53c1ff] | 62 | void readdItem(QtMoleculeItem *_molitem);
|
---|
[b47bfc] | 63 |
|
---|
| 64 | signals:
|
---|
| 65 | void moleculeSelected(molecule*);
|
---|
| 66 | void moleculeUnSelected(molecule*);
|
---|
[739ee9] | 67 | void moleculesVisibilityChanged(const moleculeId_t, bool);
|
---|
[b47bfc] | 68 |
|
---|
| 69 | private:
|
---|
[53c1ff] | 70 |
|
---|
[6770fa] | 71 | bool changing;
|
---|
[3eb91c] | 72 | bool ChangingChildrensVisibility;
|
---|
[53c1ff] | 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;
|
---|
[3eb91c] | 80 |
|
---|
[f62e60] | 81 | friend class QtMoleculeListView;
|
---|
[8ccf3b] | 82 |
|
---|
[53c1ff] | 83 | QtMoleculeItem * MoleculeToItem(const molecule * const _mol) const;
|
---|
| 84 | const molecule * const IndexToMolecule(const QModelIndex &_index) const;
|
---|
| 85 | const molecule * const ItemToMolecule(const QtMoleculeItem * const _item) const;
|
---|
| 86 |
|
---|
| 87 | void addMolecule(const molecule * const _mol);
|
---|
[8ccf3b] | 88 | void addGroupItem(QStandardItem *&mainitem, const std::string &_molecule_formula);
|
---|
[53c1ff] | 89 | void addMoleculeItem(QStandardItem *_groupitem, const molecule * const _mol, 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);
|
---|
[2696b1] | 94 | void setVisibilityForMoleculeItem(QtMoleculeItem* _item);
|
---|
| 95 | void setVisibilityForGroupItem(QStandardItem* _item);
|
---|
[53c1ff] | 96 |
|
---|
| 97 | void informDirtyState(QtMoleculeItem *_item, const QtMoleculeItem::MoveTypes _type);
|
---|
| 98 |
|
---|
| 99 | void updateItemStates();
|
---|
[6770fa] | 100 |
|
---|
[3eb91c] | 101 | typedef std::map<std::string, unsigned int> FormulaVisibilityCountMap_t;
|
---|
| 102 | FormulaVisibilityCountMap_t FormulaVisibilityCountMap;
|
---|
| 103 |
|
---|
[8ccf3b] | 104 | typedef std::map<std::string, QStandardItem*> FormulaTreeItemMap_t;
|
---|
[3eb91c] | 105 | //!> map of (unique) formulas in the world
|
---|
| 106 | FormulaTreeItemMap_t formula;
|
---|
[8ccf3b] | 107 |
|
---|
[53c1ff] | 108 | typedef boost::bimap<const molecule *, QtMoleculeItem*> MoleculeItemBiMap_t;
|
---|
[8ccf3b] | 109 | MoleculeItemBiMap_t MoleculeItemBiMap;
|
---|
[53c1ff] | 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;
|
---|
[2696b1] | 117 | //!> list of items that need an update of visibility
|
---|
| 118 | list_of_items_t visibilityItems;
|
---|
[53c1ff] | 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;
|
---|
[2696b1] | 127 | //!> list of group items that need visibility update due to changed molecule items
|
---|
| 128 | std::set<QStandardItem*> toBeSetVisibilityItems;
|
---|
[b47bfc] | 129 | };
|
---|
| 130 |
|
---|
[0eb7bf3] | 131 | #endif /* QTMOLECULELIST_HPP_ */
|
---|