File indexing completed on 2024-04-06 12:11:42
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 #include <functional>
0015 #include <iostream>
0016 #include <cassert>
0017
0018
0019 #include "Fireworks/Core/interface/FWSelectionManager.h"
0020 #include "Fireworks/Core/interface/FWModelChangeManager.h"
0021 #include "Fireworks/Core/interface/FWEventItem.h"
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034 FWSelectionManager::FWSelectionManager(FWModelChangeManager* iCM) : m_changeManager(iCM), m_wasChanged(false) {
0035 assert(nullptr != m_changeManager);
0036 m_changeManager->changeSignalsAreDone_.connect(std::bind(&FWSelectionManager::finishedAllSelections, this));
0037 }
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063 void FWSelectionManager::clearSelection() {
0064 FWChangeSentry sentry(*m_changeManager);
0065 for (std::set<FWModelId>::iterator it = m_selection.begin(), itEnd = m_selection.end(); it != itEnd; ++it) {
0066
0067 it->unselect();
0068 }
0069 clearItemSelection();
0070 }
0071
0072 void FWSelectionManager::clearItemSelection() {
0073
0074
0075 std::set<FWEventItem*> items;
0076 items.swap(m_itemSelection);
0077 for (std::set<FWEventItem*>::iterator it = items.begin(), itEnd = items.end(); it != itEnd; ++it) {
0078
0079 (*it)->unselectItem();
0080 }
0081 }
0082
0083 void FWSelectionManager::clearModelSelectionLeaveItem() {
0084 FWChangeSentry sentry(*m_changeManager);
0085 for (std::set<FWModelId>::iterator it = m_selection.begin(), itEnd = m_selection.end(); it != itEnd; ++it) {
0086
0087 it->unselect();
0088 }
0089 }
0090
0091 void FWSelectionManager::finishedAllSelections() {
0092 if (m_wasChanged) {
0093 m_selection = m_newSelection;
0094 selectionChanged_(*this);
0095 m_wasChanged = false;
0096 }
0097 }
0098
0099 void FWSelectionManager::select(const FWModelId& iId) {
0100 bool changed = m_newSelection.insert(iId).second;
0101 m_wasChanged |= changed;
0102 if (changed) {
0103
0104 if (m_itemConnectionCount.size() <= iId.item()->id()) {
0105 m_itemConnectionCount.resize(iId.item()->id() + 1);
0106 }
0107 if (1 == ++(m_itemConnectionCount[iId.item()->id()].first)) {
0108
0109
0110
0111 m_itemConnectionCount[iId.item()->id()].second =
0112 iId.item()->preItemChanged_.connect(std::bind(&FWSelectionManager::itemChanged, this, std::placeholders::_1));
0113 }
0114 }
0115 }
0116
0117 void FWSelectionManager::unselect(const FWModelId& iId) {
0118 bool changed = (0 != m_newSelection.erase(iId));
0119 m_wasChanged |= changed;
0120 if (changed) {
0121 assert(m_itemConnectionCount.size() > iId.item()->id());
0122
0123 if (0 == --(m_itemConnectionCount[iId.item()->id()].first)) {
0124 m_itemConnectionCount[iId.item()->id()].second.disconnect();
0125 }
0126 }
0127 }
0128
0129 void FWSelectionManager::itemChanged(const FWEventItem* iItem) {
0130 assert(nullptr != iItem);
0131 assert(m_itemConnectionCount.size() > iItem->id());
0132
0133 FWModelId low(iItem, 0);
0134 FWModelId high(iItem, 0x7FFFFFFF);
0135 bool someoneChanged = false;
0136 {
0137 std::set<FWModelId>::iterator itL = m_newSelection.lower_bound(low), itH = m_newSelection.upper_bound(high);
0138 if (itL != itH) {
0139 m_wasChanged = true;
0140 someoneChanged = true;
0141 m_newSelection.erase(itL, itH);
0142 }
0143 }
0144 {
0145 std::set<FWModelId>::iterator itL = m_selection.lower_bound(low), itH = m_selection.upper_bound(high);
0146 if (itL != itH) {
0147 m_wasChanged = true;
0148 someoneChanged = true;
0149
0150 }
0151 }
0152 assert(someoneChanged);
0153 m_itemConnectionCount[iItem->id()].second.disconnect();
0154 m_itemConnectionCount[iItem->id()].first = 0;
0155 }
0156
0157 void FWSelectionManager::selectItem(FWEventItem* iItem) {
0158 m_itemSelection.insert(iItem);
0159 itemSelectionChanged_(*this);
0160 }
0161 void FWSelectionManager::unselectItem(FWEventItem* iItem) {
0162 m_itemSelection.erase(iItem);
0163 itemSelectionChanged_(*this);
0164 }
0165
0166
0167
0168 const std::set<FWModelId>& FWSelectionManager::selected() const { return m_selection; }
0169
0170 const std::set<FWEventItem*>& FWSelectionManager::selectedItems() const { return m_itemSelection; }
0171
0172
0173
0174