summaryrefslogtreecommitdiffstats
path: root/src/gui/collectiontypecombo.cpp
blob: c255c875281d8b8e083443c9d931cbe07c3862d9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/***************************************************************************
    copyright            : (C) 2006 by Robby Stephenson
    email                : robby@periapsis.org
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of version 2 of the GNU General Public License as  *
 *   published by the Free Software Foundation;                            *
 *                                                                         *
 ***************************************************************************/

#include "collectiontypecombo.h"
#include "../collection.h"
#include "../collectionfactory.h"

using Tellico::GUI::CollectionTypeCombo;

CollectionTypeCombo::CollectionTypeCombo(TQWidget* parent_) : ComboBox(parent_) {
  reset();
}

void CollectionTypeCombo::reset() {
  clear();
  // I want to sort the collection names
  const CollectionNameMap nameMap = CollectionFactory::nameMap();
  TQMap<TQString, int> rNameMap;
  for(CollectionNameMap::ConstIterator it = nameMap.begin(); it != nameMap.end(); ++it) {
    rNameMap.insert(it.data(), it.key());
  }
  const TQValueList<int> collTypes = rNameMap.values();
  const TQStringList collNames = rNameMap.keys();
  int custom = -1;
  const int total = collTypes.count();
  // when i equals the size, then go back and do custom
  for(int i = 0; i <= total; ++i) {
    // put custom last
    if(custom > -1 && count() >= total) {
      break; // already done it!
    } else if(i == total) {
      i = custom;
    } else if(collTypes[i] == Data::Collection::Base) {
      custom = i;
      continue;
    }
    insertItem(collNames[i], collTypes[i]);
  }
}

void CollectionTypeCombo::setCurrentType(int type_) {
  setCurrentData(type_);
}