mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-02 15:15:50 +08:00
refs #404, and discussion https://dev.vatsim-germany.org/issues/404#note-8 * Changed CSimulatorSetup to use CNameVariantPairList as data. The old version was an hack and had to go, CNameVariantPairList would allow complex types in the future and can be already shown in the GUI. * CNameVariantPairList was improved slightly in the same step * Functions to get CSimulatorSetup from driver / context * Removed CSimulatorSetup data from CSimulatorPluginInfo
85 lines
2.8 KiB
C++
85 lines
2.8 KiB
C++
/* 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 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 "namevariantpairlist.h"
|
|
#include "predicates.h"
|
|
|
|
namespace BlackMisc
|
|
{
|
|
CNameVariantPairList::CNameVariantPairList() { }
|
|
|
|
CNameVariantPairList::CNameVariantPairList(const CSequence<CNameVariantPair> &other) :
|
|
CSequence<CNameVariantPair>(other)
|
|
{ }
|
|
|
|
bool CNameVariantPairList::containsName(const QString &name)const
|
|
{
|
|
return this->contains(&CNameVariantPair::getName, name);
|
|
}
|
|
|
|
CNameVariantPair CNameVariantPairList::getValue(const QString &name) const
|
|
{
|
|
if (name.isEmpty()) { return CNameVariantPair(); }
|
|
return this->findBy(&CNameVariantPair::getName, name).frontOrDefault();
|
|
}
|
|
|
|
CVariant CNameVariantPairList::getVariantValue(const QString &name) const
|
|
{
|
|
if (name.isEmpty()) { return CVariant(); }
|
|
return getValue(name).getVariant();
|
|
}
|
|
|
|
QString CNameVariantPairList::getValueAsString(const QString &name) const
|
|
{
|
|
if (name.isEmpty()) { return QString(); }
|
|
CVariant cs(getValue(name).getVariant());
|
|
if (cs.isNull() || !cs.canConvert<QString>()) { return QString(); }
|
|
return cs.value<QString>();
|
|
}
|
|
|
|
bool CNameVariantPairList::addOrReplaceValue(const QString &name, const CVariant &value, const CIcon &icon)
|
|
{
|
|
if (name.isEmpty()) { return false; }
|
|
int i = getIndexForName(name);
|
|
if (i < 0)
|
|
{
|
|
this->push_back(CNameVariantPair(name, value, icon));
|
|
return false;
|
|
}
|
|
else
|
|
{
|
|
(*this)[i] = CNameVariantPair(name, value, icon);
|
|
return true;
|
|
}
|
|
}
|
|
|
|
int CNameVariantPairList::getIndexForName(const QString &name) const
|
|
{
|
|
for (int i = 0; i < this->size(); i++)
|
|
{
|
|
if ((*this)[i].getName() == name)
|
|
{
|
|
return i;
|
|
}
|
|
}
|
|
return -1;
|
|
}
|
|
|
|
void CNameVariantPairList::registerMetadata()
|
|
{
|
|
qRegisterMetaType<BlackMisc::CSequence<CNameVariantPair>>();
|
|
qDBusRegisterMetaType<BlackMisc::CSequence<CNameVariantPair>>();
|
|
qRegisterMetaType<BlackMisc::CCollection<CNameVariantPair>>();
|
|
qDBusRegisterMetaType<BlackMisc::CCollection<CNameVariantPair>>();
|
|
qRegisterMetaType<CNameVariantPairList>();
|
|
qDBusRegisterMetaType<CNameVariantPairList>();
|
|
registerMetaValueType<CNameVariantPairList>();
|
|
}
|
|
} // namespace
|