24 void GraphTableModel::removeFromVector(
const std::set<T>& objects,std::vector<T>& vect,TLP_HASH_MAP<T,int>& objToIndexes,
bool deleteRows) {
26 std::set<int, std::greater<int> > indexes;
28 for(
typename std::set<T>::const_iterator it = objects.begin(); it != objects.end(); ++it) {
29 assert(objToIndexes.find(*it)!=objToIndexes.end());
30 indexes.insert(objToIndexes[*it]);
31 objToIndexes.erase(*it);
34 while(!indexes.empty()) {
36 std::set<int, std::greater<int> >::const_iterator from = indexes.begin();
38 std::set<int, std::greater<int> >::const_iterator current = from;
39 std::set<int, std::greater<int> >::const_iterator to=from;
43 while(to != indexes.end() && *to == (*current)-1 ) {
49 int fromIndex = *current;
53 indexes.erase(from,to);
56 beginRemoveRows(QModelIndex(),fromIndex,toIndex);
59 beginRemoveColumns(QModelIndex(),fromIndex,toIndex);
63 vect.erase(vect.begin()+fromIndex,vect.begin()+toIndex+1);
66 for(
unsigned int i = fromIndex ; i < vect.size() ; ++i) {
67 objToIndexes[vect[i]] =
static_cast<int>(i);
79 template<
typename T,
class Compare>
80 void GraphTableModel::addToVector(
const std::set<T>& objects,std::vector<T>& vect,TLP_HASH_MAP<T,int>& objToIndex,
bool addRows, Compare* comp) {
82 if(vect.capacity() <= vect.size() + objects.size()) {
83 vect.reserve(vect.size() + objects.size());
89 beginInsertRows(QModelIndex(),vect.size(),vect.size()+objects.size()-1);
92 beginInsertColumns(QModelIndex(),vect.size(),vect.size()+objects.size()-1);
95 for(
typename std::set<T>::const_iterator it = objects.begin(); it != objects.end() ; ++it) {
96 unsigned int i = vect.size();
98 vect.push_back((*it));
110 std::vector<T> sortedObjects(objects.begin(),objects.end());
111 std::sort(sortedObjects.begin(),sortedObjects.end(),*comp);
112 unsigned int current = 0;
113 typename std::vector<T>::iterator it;
115 for( it = vect.begin() , current = 0 ; it != vect.end() && !sortedObjects.empty() ; ++it, ++current) {
117 if(!(*comp)(*it,sortedObjects.front())) {
119 typename std::vector<T>::iterator to = sortedObjects.begin()+1;
120 unsigned int insertedElementsCount = 1;
123 while(to != sortedObjects.end() && !(*comp)(*it,*to)) {
125 ++insertedElementsCount;
130 beginInsertRows(QModelIndex(),current,current+insertedElementsCount-1);
133 beginInsertColumns(QModelIndex(),current,current+insertedElementsCount-1);
137 vect.insert(it,sortedObjects.begin(),to);
140 for(
unsigned int i = current ; i < vect.size() ; ++i) {
141 objToIndex[vect[i]]=i;
152 sortedObjects.erase(sortedObjects.begin(),to);
153 it = vect.begin()+current;
158 if(!sortedObjects.empty()) {
160 beginInsertRows(QModelIndex(),vect.size(),vect.size()+sortedObjects.size()-1);
163 beginInsertColumns(QModelIndex(),vect.size(),vect.size()+sortedObjects.size()-1);
166 size_t from = vect.size();
168 vect.insert(vect.end(),sortedObjects.begin(),sortedObjects.end());
171 for(
unsigned int i = from ; i < vect.size() ; ++i) {
172 objToIndex[vect[i]]=i;
186 void GraphTableModel::updateIndexMap(
const std::vector<T>& table,TLP_HASH_MAP<T,int>& indexMap) {
189 for(
size_t i = 0 ; i < table.size(); ++i) {
190 indexMap[table[i]]=i;
195 std::pair<unsigned int,unsigned int> GraphTableModel::computeArea(
const std::set<T>& elementsToFind,
const std::vector<T>& elements,
const TLP_HASH_MAP<T,int>& objToIndex)
const {
197 int first=elements.size()-1,last=0;
199 for(
typename std::set<T>::const_iterator it = elementsToFind.begin(); it != elementsToFind.end() ; ++it) {
200 assert(objToIndex.find(*it) != objToIndex.end());
201 int index = (objToIndex.find(*it))->second;
202 first = std::min(first,index);
203 last = std::max(last,index);
206 first = std::max(first,0);
207 last = std::min(last,static_cast<int>(elements.size()-1));
208 return std::make_pair(first,last);