mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-22 14:55:36 +08:00
* utility function for CVariant * use CVariant for cut/copy/paste
This commit is contained in:
committed by
Mathew Sutcliffe
parent
5ba438699f
commit
08f8916344
@@ -94,8 +94,10 @@ namespace BlackGui
|
||||
{
|
||||
try
|
||||
{
|
||||
CAircraftIcaoCodeList icaos;
|
||||
icaos.convertFromJson(Json::jsonObjectFromString(json));
|
||||
CVariant jsonVariant;
|
||||
jsonVariant.convertFromJson(Json::jsonObjectFromString(json));
|
||||
if (!jsonVariant.canConvert<CAircraftIcaoCodeList>()) { return; }
|
||||
const CAircraftIcaoCodeList icaos = jsonVariant.value<CAircraftIcaoCodeList>();
|
||||
if (!icaos.isEmpty())
|
||||
{
|
||||
this->setValue(icaos.front());
|
||||
|
||||
@@ -159,8 +159,10 @@ namespace BlackGui
|
||||
{
|
||||
try
|
||||
{
|
||||
CAirlineIcaoCodeList icaos;
|
||||
icaos.convertFromJson(Json::jsonObjectFromString(json));
|
||||
CVariant jsonVariant;
|
||||
jsonVariant.convertFromJson(Json::jsonObjectFromString(json));
|
||||
if (!jsonVariant.canConvert<CAirlineIcaoCodeList>()) { return; }
|
||||
const CAirlineIcaoCodeList icaos = jsonVariant.value<CAirlineIcaoCodeList>();
|
||||
if (!icaos.isEmpty())
|
||||
{
|
||||
this->setValue(icaos.front());
|
||||
|
||||
@@ -117,8 +117,10 @@ namespace BlackGui
|
||||
{
|
||||
try
|
||||
{
|
||||
CLiveryList liveries;
|
||||
liveries.convertFromJson(Json::jsonObjectFromString(json));
|
||||
CVariant jsonVariant;
|
||||
jsonVariant.convertFromJson(Json::jsonObjectFromString(json));
|
||||
if (!jsonVariant.canConvert<CLiveryList>()) { return; }
|
||||
const CLiveryList liveries = jsonVariant.value<CLiveryList>();
|
||||
if (!liveries.isEmpty())
|
||||
{
|
||||
this->setValue(liveries.front());
|
||||
|
||||
@@ -1454,7 +1454,8 @@ namespace BlackGui
|
||||
if (!this->hasSelection()) { return; }
|
||||
const ContainerType selection = this->selectedObjects();
|
||||
if (selection.isEmpty()) { return; }
|
||||
const QString json = selection.toJsonString();
|
||||
const CVariant copyJson = CVariant::from(selection);
|
||||
const QString json = copyJson.toJsonString();
|
||||
clipboard->setText(json);
|
||||
}
|
||||
|
||||
|
||||
@@ -91,7 +91,7 @@ namespace BlackMisc
|
||||
else
|
||||
{
|
||||
CLogMessage(&a).warning("Comparing two CVariants containing unrelated value objects: %1 (%2) and %3 (%4)")
|
||||
<< a.typeName() << a.userType() << b.typeName() << b.userType();
|
||||
<< a.typeName() << a.userType() << b.typeName() << b.userType();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -152,6 +152,12 @@ namespace BlackMisc
|
||||
return json;
|
||||
}
|
||||
|
||||
QString CVariant::toJsonString(QJsonDocument::JsonFormat format) const
|
||||
{
|
||||
QJsonDocument jsonDoc(toJson());
|
||||
return jsonDoc.toJson(format);
|
||||
}
|
||||
|
||||
void CVariant::convertFromJson(const QJsonObject &json)
|
||||
{
|
||||
// Remark: Names "type" and "value" are also used for drag and drop
|
||||
|
||||
@@ -273,6 +273,9 @@ namespace BlackMisc
|
||||
//! \copydoc BlackMisc::Mixin::JsonByMetaClass::toJson
|
||||
QJsonObject toJson() const;
|
||||
|
||||
//! Convenience function JSON as string
|
||||
QString toJsonString(QJsonDocument::JsonFormat format = QJsonDocument::Indented) const;
|
||||
|
||||
//! \copydoc BlackMisc::Mixin::JsonByMetaClass::convertFromJson
|
||||
void convertFromJson(const QJsonObject &json);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user