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