/* Copyright (C) 2013 * swift Project Community / Contributors * * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level * directory of this distribution. No part of swift project, including this file, may be copied, modified, propagated, * or distributed except according to the terms contained in the LICENSE file. */ #include "blackmisc/namevariantpair.h" #include "blackmisc/propertyindexvariantmap.h" #include BLACK_DEFINE_VALUEOBJECT_MIXINS(BlackMisc, CNameVariantPair) namespace BlackMisc { CNameVariantPair::CNameVariantPair(const QString &name, const CVariant &variant, const CIcon &icon) : m_name(name), m_variant(variant), m_icon(icon) { } CIcons::IconIndex CNameVariantPair::toIcon() const { return m_icon.getIndex(); } bool CNameVariantPair::hasIcon() const { return this->m_icon.isSet(); } QString CNameVariantPair::convertToQString(bool i18n) const { QString s(this->m_name); s.append(" ").append(this->m_variant.toQString(i18n)); return s; } QVariant CNameVariantPair::propertyByIndex(BlackMisc::CPropertyIndexRef index) const { if (index.isMyself()) { return QVariant::fromValue(*this); } ColumnIndex i = index.frontCasted(); switch (i) { case IndexName: return QVariant(this->m_name); case IndexVariant: return this->m_variant; default: return CValueObject::propertyByIndex(index); } } void CNameVariantPair::setPropertyByIndex(CPropertyIndexRef index, const QVariant &variant) { if (index.isMyself()) { (*this) = variant.value(); return; } ColumnIndex i = index.frontCasted(); // special case, handle icon and allow to set it // doing this in the switch gives gcc warning as IndexIcon is no member of ColumnIndex if (static_cast(i) == static_cast(IndexIcon)) { if (static_cast(variant.type()) == QMetaType::Int) { CIcons::IconIndex iconIndex = variant.value(); this->m_icon = CIcon::iconByIndex(iconIndex); } else { this->m_icon = variant.value(); } return; } // properties switch (i) { case IndexName: this->setName(variant.value()); break; case IndexVariant: this->m_variant = variant; break; default: CValueObject::setPropertyByIndex(index, variant); break; } } } // namespace