/* Copyright (C) 2015 * 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 and at http://www.swift-project.org/license.html. 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/network/role.h" #include #include namespace BlackMisc { namespace Network { CRole::CRole(const QString &name, const QString &description) : m_name(name), m_description(description) { } QString CRole::convertToQString(bool i18n) const { Q_UNUSED(i18n); return "Role: " + m_name + " description: " + m_description + " " + this->getDbKeyAsStringInParentheses(); } CVariant CRole::propertyByIndex(const CPropertyIndex &index) const { if (index.isMyself()) { return CVariant::from(*this); } if (IDatastoreObjectWithIntegerKey::canHandleIndex(index)) { return IDatastoreObjectWithIntegerKey::propertyByIndex(index); } ColumnIndex i = index.frontCasted(); switch (i) { case IndexName: return CVariant::fromValue(this->m_name); case IndexDescription: return CVariant::fromValue(this->m_description); default: return CValueObject::propertyByIndex(index); } } void CRole::setPropertyByIndex(const CPropertyIndex &index, const CVariant &variant) { if (index.isMyself()) { (*this) = variant.to(); return; } if (IDatastoreObjectWithIntegerKey::canHandleIndex(index)) { IDatastoreObjectWithIntegerKey::setPropertyByIndex(index, variant); return; } ColumnIndex i = index.frontCasted(); switch (i) { case IndexName: this->setName(variant.value()); break; case IndexDescription: this->setDescription(variant.value()); default: CValueObject::setPropertyByIndex(index, variant); break; } } CRole CRole::fromDatabaseJson(const QJsonObject &json) { CRole role; role.setName(json.value("name").toString()); role.setDescription(json.value("description").toString()); role.setDbKey(json.value("idrole").toInt(-1)); return role; } } // ns } // ns