[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 |
|
---|
[53c1ff] | 27 | #include "UIElements/Views/Qt4/MoleculeList/QtMoleculeItem.hpp"
|
---|
[ca1535] | 28 | #include "UIElements/Qt4/InstanceBoard/QtObservedMolecule.hpp"
|
---|
[53c1ff] | 29 |
|
---|
[739ee9] | 30 | #include "types.hpp"
|
---|
| 31 |
|
---|
[53c1ff] | 32 | class QtMoleculeItem;
|
---|
[f62e60] | 33 | class QtMoleculeListView;
|
---|
[ca1535] | 34 | class QtObservedInstanceBoard;
|
---|
[b47bfc] | 35 |
|
---|
[ca1535] | 36 | class QtMoleculeList : public QStandardItemModel
|
---|
[b47bfc] | 37 | {
|
---|
| 38 | Q_OBJECT
|
---|
| 39 |
|
---|
| 40 | public:
|
---|
[b2c2e4] | 41 | QtMoleculeList(QtObservedInstanceBoard *_board, QObject *_parent = NULL);
|
---|
[0eb7bf3] | 42 | virtual ~QtMoleculeList();
|
---|
[b47bfc] | 43 |
|
---|
[ca1535] | 44 | void resetUpdateTimer();
|
---|
[b47bfc] | 45 |
|
---|
[1c3390] | 46 | QVariant headerData(int section, Qt::Orientation orientation, int role) const;
|
---|
| 47 |
|
---|
[b47bfc] | 48 | private slots:
|
---|
[07b800] | 49 | void moleculeNameChanged(QStandardItem*);
|
---|
[2696b1] | 50 | void checkForVisibilityChange(QStandardItem*);
|
---|
[53c1ff] | 51 | void checkState();
|
---|
[8ccf3b] | 52 |
|
---|
[53c1ff] | 53 | friend class QtMoleculeItem;
|
---|
[b47bfc] | 54 |
|
---|
[fcdf05] | 55 | std::string readdItem(QtMoleculeItem *_molitem);
|
---|
[b47bfc] | 56 |
|
---|
| 57 | signals:
|
---|
| 58 | void moleculeSelected(molecule*);
|
---|
| 59 | void moleculeUnSelected(molecule*);
|
---|
[739ee9] | 60 | void moleculesVisibilityChanged(const moleculeId_t, bool);
|
---|
[b47bfc] | 61 |
|
---|
| 62 | private:
|
---|
[53c1ff] | 63 |
|
---|
[3eb91c] | 64 | bool ChangingChildrensVisibility;
|
---|
[7d0ddb] | 65 |
|
---|
[ca1535] | 66 | private slots:
|
---|
| 67 | void moleculeInserted(const moleculeId_t _id);
|
---|
| 68 | void moleculeRemoved(const moleculeId_t _id);
|
---|
| 69 | void moleculeIndexChanged(const moleculeId_t _oldid, const moleculeId_t _newid);
|
---|
| 70 |
|
---|
| 71 | private:
|
---|
[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 |
|
---|
[ca1535] | 99 | std::string addMolecule(
|
---|
| 100 | QtObservedMolecule::ptr &_ObservedMolecule);
|
---|
| 101 | void addGroupItem(
|
---|
| 102 | QStandardItem *&mainitem,
|
---|
| 103 | const std::string &_molecule_formula);
|
---|
| 104 | QList<QStandardItem *> createMoleculeItems(
|
---|
| 105 | QtObservedMolecule::ptr &_ObservedMolecule,
|
---|
| 106 | std::string &molecule_formula);
|
---|
[fcdf05] | 107 | void removeMoleculeItem(QtMoleculeItem * const _item);
|
---|
[53c1ff] | 108 | int setOccurrence(QStandardItem * const _groupitem);
|
---|
| 109 | bool areAnyItemsDirty();
|
---|
[2696b1] | 110 | void setVisibilityForMoleculeItem(QtMoleculeItem* _item);
|
---|
| 111 | void setVisibilityForGroupItem(QStandardItem* _item);
|
---|
[53c1ff] | 112 |
|
---|
[fcdf05] | 113 | void informDirtyState(
|
---|
| 114 | const moleculeId_t _id,
|
---|
| 115 | const QtMoleculeItem::COLUMNTYPES _type,
|
---|
| 116 | const QtMoleculeItem::MoveTypes _movetype);
|
---|
[53c1ff] | 117 |
|
---|
| 118 | void updateItemStates();
|
---|
[6770fa] | 119 |
|
---|
[ca1535] | 120 | //!> reference to InstanceBoard
|
---|
| 121 | QtObservedInstanceBoard *board;
|
---|
| 122 |
|
---|
[3eb91c] | 123 | typedef std::map<std::string, unsigned int> FormulaVisibilityCountMap_t;
|
---|
| 124 | FormulaVisibilityCountMap_t FormulaVisibilityCountMap;
|
---|
| 125 |
|
---|
[fcdf05] | 126 | typedef boost::bimap<std::string, QStandardItem*> FormulaTreeItemBiMap_t;
|
---|
| 127 | //!> map of (unique) formulas in the world
|
---|
| 128 | FormulaTreeItemBiMap_t FormulaItemBiMap;
|
---|
| 129 |
|
---|
| 130 | typedef std::map<moleculeId_t, std::string> MoleculeFormulaMap_t;
|
---|
[3eb91c] | 131 | //!> map of (unique) formulas in the world
|
---|
[fcdf05] | 132 | MoleculeFormulaMap_t MoleculeFormulaMap;
|
---|
[8ccf3b] | 133 |
|
---|
[69b434] | 134 | typedef boost::bimap<moleculeId_t, QtMoleculeItem*> MoleculeItemBiMap_t;
|
---|
[8ccf3b] | 135 | MoleculeItemBiMap_t MoleculeItemBiMap;
|
---|
[53c1ff] | 136 |
|
---|
| 137 | //!> callback function to hand over to items that inform about requiring update
|
---|
| 138 | const QtMoleculeItem::emitDirtyState_t callback_DirtyItems;
|
---|
| 139 |
|
---|
[cc2976] | 140 | typedef std::map<moleculeId_t, unsigned int> KilledItemsPerMolecule_t;
|
---|
| 141 | //!> takes note of how many items have already been killed for a specific row/molecule
|
---|
| 142 | KilledItemsPerMolecule_t KilledItemsPerMolecule;
|
---|
| 143 |
|
---|
[fcdf05] | 144 | typedef std::set< moleculeId_t > list_of_molecules_t;
|
---|
| 145 | typedef std::set< std::pair<moleculeId_t, QtMoleculeItem::COLUMNTYPES> > list_of_molecule_items_t;
|
---|
| 146 | typedef std::set< std::pair<std::string, QtMoleculeItem::COLUMNTYPES> > list_of_group_items_t;
|
---|
[ca1535] | 147 |
|
---|
[fcdf05] | 148 | //!> list of molecule items that need an update
|
---|
| 149 | list_of_molecule_items_t dirtyMolItems;
|
---|
| 150 | //!> list of molecule items that need an update of visibility
|
---|
| 151 | list_of_molecules_t visibilityMolItems;
|
---|
| 152 | //!> list of group items that need an update
|
---|
| 153 | list_of_group_items_t dirtyGroupItems;
|
---|
| 154 | //!> list of group items that need an update of visibility
|
---|
| 155 | list_of_group_items_t visibilityGroupItems;
|
---|
| 156 | //!> list of new molecules which need to be added
|
---|
[aa41a3] | 157 | std::vector<moleculeId_t> newMolecules;
|
---|
[fcdf05] | 158 | //!> list of molecules that have been removed
|
---|
| 159 | std::vector<moleculeId_t> removedMolecules;
|
---|
| 160 | //!> list of molecule items to molecule's whose formulas has changed and need to be moved
|
---|
| 161 | list_of_molecules_t toBeMovedItems;
|
---|
[b47bfc] | 162 | };
|
---|
| 163 |
|
---|
[0eb7bf3] | 164 | #endif /* QTMOLECULELIST_HPP_ */
|
---|