| [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;
|
|---|
| 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 |
|
|---|
| [fcdf05] | 63 | std::string 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 |
|
|---|
| [fcdf05] | 74 | mutable boost::recursive_mutex listAccessing_mutex;
|
|---|
| 75 | mutable boost::recursive_mutex refill_mutex;
|
|---|
| 76 | mutable boost::recursive_mutex map_mutex;
|
|---|
| [53c1ff] | 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;
|
|---|
| [3eb91c] | 83 |
|
|---|
| [f62e60] | 84 | friend class QtMoleculeListView;
|
|---|
| [8ccf3b] | 85 |
|
|---|
| [fcdf05] | 86 | bool isMoleculeItemPresent(const moleculeId_t _molid) const;
|
|---|
| [69b434] | 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;
|
|---|
| [fcdf05] | 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);
|
|---|
| [8ccf3b] | 101 | void addGroupItem(QStandardItem *&mainitem, const std::string &_molecule_formula);
|
|---|
| [69b434] | 102 | void addMoleculeItem(QStandardItem *_groupitem, const moleculeId_t _molid, const std::string &molecule_formula);
|
|---|
| [fcdf05] | 103 | void removeMoleculeItem(QtMoleculeItem * const _item);
|
|---|
| [53c1ff] | 104 | int setOccurrence(QStandardItem * const _groupitem);
|
|---|
| 105 | bool areAnyItemsDirty();
|
|---|
| [2696b1] | 106 | void setVisibilityForMoleculeItem(QtMoleculeItem* _item);
|
|---|
| 107 | void setVisibilityForGroupItem(QStandardItem* _item);
|
|---|
| [53c1ff] | 108 |
|
|---|
| [fcdf05] | 109 | void informDirtyState(
|
|---|
| 110 | const moleculeId_t _id,
|
|---|
| 111 | const QtMoleculeItem::COLUMNTYPES _type,
|
|---|
| 112 | const QtMoleculeItem::MoveTypes _movetype);
|
|---|
| [53c1ff] | 113 |
|
|---|
| [cc2976] | 114 | void receiveSubjectKilled(const moleculeId_t _id);
|
|---|
| 115 |
|
|---|
| [53c1ff] | 116 | void updateItemStates();
|
|---|
| [6770fa] | 117 |
|
|---|
| [3eb91c] | 118 | typedef std::map<std::string, unsigned int> FormulaVisibilityCountMap_t;
|
|---|
| 119 | FormulaVisibilityCountMap_t FormulaVisibilityCountMap;
|
|---|
| 120 |
|
|---|
| [fcdf05] | 121 | typedef boost::bimap<std::string, QStandardItem*> FormulaTreeItemBiMap_t;
|
|---|
| 122 | //!> map of (unique) formulas in the world
|
|---|
| 123 | FormulaTreeItemBiMap_t FormulaItemBiMap;
|
|---|
| 124 |
|
|---|
| 125 | typedef std::map<moleculeId_t, std::string> MoleculeFormulaMap_t;
|
|---|
| [3eb91c] | 126 | //!> map of (unique) formulas in the world
|
|---|
| [fcdf05] | 127 | MoleculeFormulaMap_t MoleculeFormulaMap;
|
|---|
| [8ccf3b] | 128 |
|
|---|
| [69b434] | 129 | typedef boost::bimap<moleculeId_t, QtMoleculeItem*> MoleculeItemBiMap_t;
|
|---|
| [8ccf3b] | 130 | MoleculeItemBiMap_t MoleculeItemBiMap;
|
|---|
| [53c1ff] | 131 |
|
|---|
| 132 | //!> callback function to hand over to items that inform about requiring update
|
|---|
| 133 | const QtMoleculeItem::emitDirtyState_t callback_DirtyItems;
|
|---|
| 134 |
|
|---|
| [cc2976] | 135 | //!> callback function to hand over to items that inform about called subjectKilled()
|
|---|
| 136 | const QtMoleculeItem::emitSubjectKilledState_t callback_subjectKilledItems;
|
|---|
| 137 |
|
|---|
| 138 | typedef std::map<moleculeId_t, unsigned int> KilledItemsPerMolecule_t;
|
|---|
| 139 | //!> takes note of how many items have already been killed for a specific row/molecule
|
|---|
| 140 | KilledItemsPerMolecule_t KilledItemsPerMolecule;
|
|---|
| 141 |
|
|---|
| [fcdf05] | 142 | typedef std::set< moleculeId_t > list_of_molecules_t;
|
|---|
| 143 | typedef std::set< std::pair<moleculeId_t, QtMoleculeItem::COLUMNTYPES> > list_of_molecule_items_t;
|
|---|
| 144 | typedef std::set< std::pair<std::string, QtMoleculeItem::COLUMNTYPES> > list_of_group_items_t;
|
|---|
| 145 | //!> list of molecule items that need an update
|
|---|
| 146 | list_of_molecule_items_t dirtyMolItems;
|
|---|
| 147 | //!> list of molecule items that need an update of visibility
|
|---|
| 148 | list_of_molecules_t visibilityMolItems;
|
|---|
| 149 | //!> list of group items that need an update
|
|---|
| 150 | list_of_group_items_t dirtyGroupItems;
|
|---|
| 151 | //!> list of group items that need an update of visibility
|
|---|
| 152 | list_of_group_items_t visibilityGroupItems;
|
|---|
| 153 | //!> list of new molecules which need to be added
|
|---|
| 154 | std::vector<moleculeId_t> newMolecules;
|
|---|
| 155 | //!> list of molecules that have been removed
|
|---|
| 156 | std::vector<moleculeId_t> removedMolecules;
|
|---|
| 157 | //!> list of molecule items to molecule's whose formulas has changed and need to be moved
|
|---|
| 158 | list_of_molecules_t toBeMovedItems;
|
|---|
| [b47bfc] | 159 | };
|
|---|
| 160 |
|
|---|
| [0eb7bf3] | 161 | #endif /* QTMOLECULELIST_HPP_ */
|
|---|