mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-25 02:05:43 +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
|
try
|
||||||
{
|
{
|
||||||
CAircraftIcaoCodeList icaos;
|
CVariant jsonVariant;
|
||||||
icaos.convertFromJson(Json::jsonObjectFromString(json));
|
jsonVariant.convertFromJson(Json::jsonObjectFromString(json));
|
||||||
|
if (!jsonVariant.canConvert<CAircraftIcaoCodeList>()) { return; }
|
||||||
|
const CAircraftIcaoCodeList icaos = jsonVariant.value<CAircraftIcaoCodeList>();
|
||||||
if (!icaos.isEmpty())
|
if (!icaos.isEmpty())
|
||||||
{
|
{
|
||||||
this->setValue(icaos.front());
|
this->setValue(icaos.front());
|
||||||
|
|||||||
@@ -159,8 +159,10 @@ namespace BlackGui
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
CAirlineIcaoCodeList icaos;
|
CVariant jsonVariant;
|
||||||
icaos.convertFromJson(Json::jsonObjectFromString(json));
|
jsonVariant.convertFromJson(Json::jsonObjectFromString(json));
|
||||||
|
if (!jsonVariant.canConvert<CAirlineIcaoCodeList>()) { return; }
|
||||||
|
const CAirlineIcaoCodeList icaos = jsonVariant.value<CAirlineIcaoCodeList>();
|
||||||
if (!icaos.isEmpty())
|
if (!icaos.isEmpty())
|
||||||
{
|
{
|
||||||
this->setValue(icaos.front());
|
this->setValue(icaos.front());
|
||||||
|
|||||||
@@ -117,8 +117,10 @@ namespace BlackGui
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
CLiveryList liveries;
|
CVariant jsonVariant;
|
||||||
liveries.convertFromJson(Json::jsonObjectFromString(json));
|
jsonVariant.convertFromJson(Json::jsonObjectFromString(json));
|
||||||
|
if (!jsonVariant.canConvert<CLiveryList>()) { return; }
|
||||||
|
const CLiveryList liveries = jsonVariant.value<CLiveryList>();
|
||||||
if (!liveries.isEmpty())
|
if (!liveries.isEmpty())
|
||||||
{
|
{
|
||||||
this->setValue(liveries.front());
|
this->setValue(liveries.front());
|
||||||
|
|||||||
@@ -1454,7 +1454,8 @@ namespace BlackGui
|
|||||||
if (!this->hasSelection()) { return; }
|
if (!this->hasSelection()) { return; }
|
||||||
const ContainerType selection = this->selectedObjects();
|
const ContainerType selection = this->selectedObjects();
|
||||||
if (selection.isEmpty()) { return; }
|
if (selection.isEmpty()) { return; }
|
||||||
const QString json = selection.toJsonString();
|
const CVariant copyJson = CVariant::from(selection);
|
||||||
|
const QString json = copyJson.toJsonString();
|
||||||
clipboard->setText(json);
|
clipboard->setText(json);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -91,7 +91,7 @@ namespace BlackMisc
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
CLogMessage(&a).warning("Comparing two CVariants containing unrelated value objects: %1 (%2) and %3 (%4)")
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -152,6 +152,12 @@ namespace BlackMisc
|
|||||||
return json;
|
return json;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString CVariant::toJsonString(QJsonDocument::JsonFormat format) const
|
||||||
|
{
|
||||||
|
QJsonDocument jsonDoc(toJson());
|
||||||
|
return jsonDoc.toJson(format);
|
||||||
|
}
|
||||||
|
|
||||||
void CVariant::convertFromJson(const QJsonObject &json)
|
void CVariant::convertFromJson(const QJsonObject &json)
|
||||||
{
|
{
|
||||||
// Remark: Names "type" and "value" are also used for drag and drop
|
// Remark: Names "type" and "value" are also used for drag and drop
|
||||||
|
|||||||
@@ -273,6 +273,9 @@ namespace BlackMisc
|
|||||||
//! \copydoc BlackMisc::Mixin::JsonByMetaClass::toJson
|
//! \copydoc BlackMisc::Mixin::JsonByMetaClass::toJson
|
||||||
QJsonObject toJson() const;
|
QJsonObject toJson() const;
|
||||||
|
|
||||||
|
//! Convenience function JSON as string
|
||||||
|
QString toJsonString(QJsonDocument::JsonFormat format = QJsonDocument::Indented) const;
|
||||||
|
|
||||||
//! \copydoc BlackMisc::Mixin::JsonByMetaClass::convertFromJson
|
//! \copydoc BlackMisc::Mixin::JsonByMetaClass::convertFromJson
|
||||||
void convertFromJson(const QJsonObject &json);
|
void convertFromJson(const QJsonObject &json);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user