File indexing completed on 2024-05-12 05:09:46
0001 /*************************************************************************** 0002 Copyright (C) 2006-2009 Robby Stephenson <robby@periapsis.org> 0003 ***************************************************************************/ 0004 0005 /*************************************************************************** 0006 * * 0007 * This program is free software; you can redistribute it and/or * 0008 * modify it under the terms of the GNU General Public License as * 0009 * published by the Free Software Foundation; either version 2 of * 0010 * the License or (at your option) version 3 or any later version * 0011 * accepted by the membership of KDE e.V. (or its successor approved * 0012 * by the membership of KDE e.V.), which shall act as a proxy * 0013 * defined in Section 14 of version 3 of the license. * 0014 * * 0015 * This program is distributed in the hope that it will be useful, * 0016 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 0017 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 0018 * GNU General Public License for more details. * 0019 * * 0020 * You should have received a copy of the GNU General Public License * 0021 * along with this program. If not, see <http://www.gnu.org/licenses/>. * 0022 * * 0023 ***************************************************************************/ 0024 0025 #include "collectiontypecombo.h" 0026 #include "../collection.h" 0027 #include "../collectionfactory.h" 0028 0029 #include <QIcon> 0030 0031 using Tellico::GUI::CollectionTypeCombo; 0032 0033 CollectionTypeCombo::CollectionTypeCombo(QWidget* parent_) : ComboBox(parent_) { 0034 reset(); 0035 } 0036 0037 void CollectionTypeCombo::reset() { 0038 clear(); 0039 // I want to sort the collection names, so use a map 0040 const CollectionNameHash nameHash = CollectionFactory::nameHash(); 0041 // the values go into the combobox in alphabetical order by collection type name (which should be unique) 0042 // with the custom collection coming last 0043 // use a map to sort the values 0044 QMap<QString, int> nameMap; 0045 for(CollectionNameHash::ConstIterator it = nameHash.constBegin(); it != nameHash.constEnd(); ++it) { 0046 // skip the custom type, we add it later 0047 if(it.key() != Data::Collection::Base && 0048 (m_includedTypes.isEmpty() || m_includedTypes.contains(it.key()))) { 0049 nameMap.insert(it.value(), it.key()); 0050 } 0051 } 0052 for(QMap<QString, int>::ConstIterator it = nameMap.constBegin(); it != nameMap.constEnd(); ++it) { 0053 addItem(it.key(), it.value()); 0054 } 0055 // now add the custom type last 0056 if(m_includedTypes.isEmpty() || m_includedTypes.contains(Data::Collection::Base)) { 0057 ComboBox::addItem(QIcon::fromTheme(QStringLiteral("document-new")), 0058 nameHash.value(Data::Collection::Base), Data::Collection::Base); 0059 } 0060 } 0061 0062 void CollectionTypeCombo::setCurrentType(int type_) { 0063 setCurrentData(type_); 0064 } 0065 0066 void CollectionTypeCombo::setIncludedTypes(const QList<int> types_) { 0067 m_includedTypes = types_; 0068 reset(); 0069 } 0070 0071 void CollectionTypeCombo::addItem(const QString& value_, int collType_) { 0072 ComboBox::addItem(QIcon(QLatin1String(":/icons/") + CollectionFactory::typeName(collType_)), value_, collType_); 0073 }