[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>
|
---|
[fcdf05] | 22 | #include <boost/thread/recursive_mutex.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;
|
---|
[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:
|
---|
[07b800] | 55 | void moleculeNameChanged(QStandardItem*);
|
---|
[2696b1] | 56 | void checkForVisibilityChange(QStandardItem*);
|
---|
[53c1ff] | 57 | void checkState();
|
---|
[8ccf3b] | 58 |
|
---|
[53c1ff] | 59 | friend class QtMoleculeItem;
|
---|
[b47bfc] | 60 |
|
---|
[fcdf05] | 61 | std::string readdItem(QtMoleculeItem *_molitem);
|
---|
[b47bfc] | 62 |
|
---|
| 63 | signals:
|
---|
| 64 | void moleculeSelected(molecule*);
|
---|
| 65 | void moleculeUnSelected(molecule*);
|
---|
[739ee9] | 66 | void moleculesVisibilityChanged(const moleculeId_t, bool);
|
---|
[b47bfc] | 67 |
|
---|
| 68 | private:
|
---|
[53c1ff] | 69 |
|
---|
[3eb91c] | 70 | bool ChangingChildrensVisibility;
|
---|
[7d0ddb] | 71 |
|
---|
[fcdf05] | 72 | mutable boost::recursive_mutex listAccessing_mutex;
|
---|
| 73 | mutable boost::recursive_mutex refill_mutex;
|
---|
| 74 | mutable boost::recursive_mutex map_mutex;
|
---|
[53c1ff] | 75 |
|
---|
| 76 | //!> informs the view in regular intervals about updates
|
---|
| 77 | QTimer *update_timer;
|
---|
| 78 |
|
---|
| 79 | //!> how often per second update is signalled to view
|
---|
| 80 | static const unsigned int update_times_per_second;
|
---|
[3eb91c] | 81 |
|
---|
[f62e60] | 82 | friend class QtMoleculeListView;
|
---|
[8ccf3b] | 83 |
|
---|
[fcdf05] | 84 | bool isMoleculeItemPresent(const moleculeId_t _molid) const;
|
---|
[69b434] | 85 | QtMoleculeItem * MoleculeIdToItem(const moleculeId_t _molid) const;
|
---|
| 86 | const moleculeId_t ItemToMoleculeId(const QtMoleculeItem * const _item) const;
|
---|
[015f8c] | 87 | const QModelIndex MoleculeIdToIndex(const moleculeId_t _id) const;
|
---|
| 88 | const moleculeId_t IndexToMoleculeId(const QModelIndex &_index) const;
|
---|
[fcdf05] | 89 | QtMoleculeItem * getSpecificMoleculeItem(
|
---|
| 90 | const QtMoleculeItem * const _item,
|
---|
| 91 | const enum QtMoleculeItem::COLUMNTYPES _type) const;
|
---|
| 92 | bool isGroupItemPresent(const std::string &_formula) const;
|
---|
| 93 | const std::string& GroupItemToFormula(const QStandardItem * const _item) const;
|
---|
| 94 | QStandardItem * FormulaToGroupItem(const std::string &_formula) const;
|
---|
| 95 | QStandardItem * getSpecificGroupItem(
|
---|
| 96 | const QStandardItem * const _item,
|
---|
| 97 | const enum QtMoleculeItem::COLUMNTYPES _type) const;
|
---|
| 98 |
|
---|
| 99 | std::string addMolecule(const molecule * const _mol);
|
---|
[8ccf3b] | 100 | void addGroupItem(QStandardItem *&mainitem, const std::string &_molecule_formula);
|
---|
[a39d72] | 101 | QList<QStandardItem *> createMoleculeItems(const moleculeId_t _molid, std::string &molecule_formula);
|
---|
[fcdf05] | 102 | void removeMoleculeItem(QtMoleculeItem * const _item);
|
---|
[53c1ff] | 103 | int setOccurrence(QStandardItem * const _groupitem);
|
---|
| 104 | bool areAnyItemsDirty();
|
---|
[2696b1] | 105 | void setVisibilityForMoleculeItem(QtMoleculeItem* _item);
|
---|
| 106 | void setVisibilityForGroupItem(QStandardItem* _item);
|
---|
[53c1ff] | 107 |
|
---|
[fcdf05] | 108 | void informDirtyState(
|
---|
| 109 | const moleculeId_t _id,
|
---|
| 110 | const QtMoleculeItem::COLUMNTYPES _type,
|
---|
| 111 | const QtMoleculeItem::MoveTypes _movetype);
|
---|
[53c1ff] | 112 |
|
---|
[cc2976] | 113 | void receiveSubjectKilled(const moleculeId_t _id);
|
---|
| 114 |
|
---|
[53c1ff] | 115 | void updateItemStates();
|
---|
[6770fa] | 116 |
|
---|
[3eb91c] | 117 | typedef std::map<std::string, unsigned int> FormulaVisibilityCountMap_t;
|
---|
| 118 | FormulaVisibilityCountMap_t FormulaVisibilityCountMap;
|
---|
| 119 |
|
---|
[fcdf05] | 120 | typedef boost::bimap<std::string, QStandardItem*> FormulaTreeItemBiMap_t;
|
---|
| 121 | //!> map of (unique) formulas in the world
|
---|
| 122 | FormulaTreeItemBiMap_t FormulaItemBiMap;
|
---|
| 123 |
|
---|
| 124 | typedef std::map<moleculeId_t, std::string> MoleculeFormulaMap_t;
|
---|
[3eb91c] | 125 | //!> map of (unique) formulas in the world
|
---|
[fcdf05] | 126 | MoleculeFormulaMap_t MoleculeFormulaMap;
|
---|
[8ccf3b] | 127 |
|
---|
[69b434] | 128 | typedef boost::bimap<moleculeId_t, QtMoleculeItem*> MoleculeItemBiMap_t;
|
---|
[8ccf3b] | 129 | MoleculeItemBiMap_t MoleculeItemBiMap;
|
---|
[53c1ff] | 130 |
|
---|
| 131 | //!> callback function to hand over to items that inform about requiring update
|
---|
| 132 | const QtMoleculeItem::emitDirtyState_t callback_DirtyItems;
|
---|
| 133 |
|
---|
[cc2976] | 134 | //!> callback function to hand over to items that inform about called subjectKilled()
|
---|
| 135 | const QtMoleculeItem::emitSubjectKilledState_t callback_subjectKilledItems;
|
---|
| 136 |
|
---|
| 137 | typedef std::map<moleculeId_t, unsigned int> KilledItemsPerMolecule_t;
|
---|
| 138 | //!> takes note of how many items have already been killed for a specific row/molecule
|
---|
| 139 | KilledItemsPerMolecule_t KilledItemsPerMolecule;
|
---|
| 140 |
|
---|
[fcdf05] | 141 | typedef std::set< moleculeId_t > list_of_molecules_t;
|
---|
| 142 | typedef std::set< std::pair<moleculeId_t, QtMoleculeItem::COLUMNTYPES> > list_of_molecule_items_t;
|
---|
| 143 | typedef std::set< std::pair<std::string, QtMoleculeItem::COLUMNTYPES> > list_of_group_items_t;
|
---|
| 144 | //!> list of molecule items that need an update
|
---|
| 145 | list_of_molecule_items_t dirtyMolItems;
|
---|
| 146 | //!> list of molecule items that need an update of visibility
|
---|
| 147 | list_of_molecules_t visibilityMolItems;
|
---|
| 148 | //!> list of group items that need an update
|
---|
| 149 | list_of_group_items_t dirtyGroupItems;
|
---|
| 150 | //!> list of group items that need an update of visibility
|
---|
| 151 | list_of_group_items_t visibilityGroupItems;
|
---|
| 152 | //!> list of new molecules which need to be added
|
---|
| 153 | std::vector<moleculeId_t> newMolecules;
|
---|
| 154 | //!> list of molecules that have been removed
|
---|
| 155 | std::vector<moleculeId_t> removedMolecules;
|
---|
| 156 | //!> list of molecule items to molecule's whose formulas has changed and need to be moved
|
---|
| 157 | list_of_molecules_t toBeMovedItems;
|
---|
[b47bfc] | 158 | };
|
---|
| 159 |
|
---|
[0eb7bf3] | 160 | #endif /* QTMOLECULELIST_HPP_ */
|
---|