Commit 2e970666e5f1f77f54a104e9c90ea78bbf175d36

Authored by Scott Klum
1 parent 04c9bf9c

Fixed FileList::sort

sdk/openbr_plugin.cpp
@@ -359,36 +359,31 @@ QStringList FileList::names() const @@ -359,36 +359,31 @@ QStringList FileList::names() const
359 return names; 359 return names;
360 } 360 }
361 361
362 -typedef std::pair<std::string,int> metadataPair;  
363 -bool comparator( const metadataPair &l, const metadataPair &r) 362 +typedef std::pair<QString,int> MetadataPair;
  363 +static bool comparator( const MetadataPair &l, const MetadataPair &r)
364 { 364 {
365 return l.first < r.first; 365 return l.first < r.first;
366 } 366 }
367 367
368 void FileList::sort(const QString& key) 368 void FileList::sort(const QString& key)
369 { 369 {
370 - std::vector<metadataPair> metadata; 370 + if (this->size() <= 1) return;
371 371
372 - int i = 0; 372 + QList<MetadataPair> metadata;
373 373
374 - foreach (const File &file, *this)  
375 - {  
376 - metadataPair pair = std::make_pair(file.get(key).toString().toStdString().c_str(), i);  
377 - metadata.push_back(pair);  
378 - i++; 374 + for (int i = 0; i < this->size(); i++) {
  375 + MetadataPair pair = std::make_pair(this->at(i).get(key).toString(), i);
  376 + metadata.append(pair);
379 } 377 }
380 378
381 std::sort(metadata.begin(), metadata.end(), comparator); 379 std::sort(metadata.begin(), metadata.end(), comparator);
382 380
383 - for (int j = 0; j < metadata.size(); j++)  
384 - {  
385 - this->push_back(this->at(metadata[j].second));  
386 - } 381 + FileList newList;
387 382
388 - iterator half = this->begin();  
389 - half += metadata.size(); 383 + for (int i = 0; i < metadata.size(); i++)
  384 + newList.append(this->at(metadata[i].second));
390 385
391 - this->erase(this->begin(), half); 386 + *this = newList;
392 } 387 }
393 388
394 QList<float> FileList::labels() const 389 QList<float> FileList::labels() const
1 -Subproject commit 504960df12db25e09c39ab098fb8614c1db51617 1 +Subproject commit 1031e9e416427f5dd8e9f4e7ff4dd74632626c22