Files
qt5-legatus-legacy/Lts/Viewer/SituationMap/Map/layer_parameter.cpp
T
2026-08-13 18:33:10 +02:00

153 lines
4.4 KiB
C++
Executable File

/**
* @RDE_HEADER@
* Class LayerParameter
* $Id$
* $HeadURL$
* $Author$
*/
// Own
#include "layer_parameter.h"
// Qt
#include <QJsonObject>
//----------------------------------------------------------------------------
namespace SituationMap
{
LayerParameter::LayerParameter()
{
resetView();
}
void LayerParameter::resetView()
{
visible = true;
opacity = 100;
brightness = 0;
contrast = 0;
gamma = 0;
}
bool LayerParameter::operator==(const LayerParameter &other) const
{
return ((this->visible == other.visible)
&& (this->opacity == other.opacity)
&& (this->brightness == other.brightness)
&& (this->contrast == other.contrast)
&& (this->gamma == other.gamma)
&& (this->minScale == other.minScale)
&& (this->maxScale == other.maxScale)
&& (this->basemapType == other.basemapType)
&& (this->displayName == other.displayName)
&& (this->description == other.description)
&& (this->previewImage == other.previewImage)
&& (this->url == other.url)
&& (this->svcDescription == other.svcDescription)
);
}
bool LayerParameter::operator!=(const LayerParameter &other) const
{
return !(*this == other);
}
LayerParameter LayerParameter::read(const QJsonObject &json)
{
LayerParameter lp;
// skip reading, values should be taken from new/current sources
// maybe mapUrls (and its name, description) has changed in the meantime...
// if (json.contains(QLatin1String("displayname")))
// lp.displayName = json[QLatin1String("displayname")].toString();
// if (json.contains(QLatin1String("description")))
// lp.description = json[QLatin1String("description")].toString();
if (json.contains(QLatin1String("visible")))
lp.visible = json[QLatin1String("visible")].toBool();
if (json.contains(QLatin1String("opacity")))
lp.opacity = json[QLatin1String("opacity")].toInt();
if (json.contains(QLatin1String("brightness")))
lp.brightness = json[QLatin1String("brightness")].toInt();
if (json.contains(QLatin1String("contrast")))
lp.contrast = json[QLatin1String("contrast")].toInt();
if (json.contains(QLatin1String("gamma")))
lp.gamma = json[QLatin1String("gamma")].toInt();
if (json.contains(QLatin1String("minScale")))
lp.minScale = json[QLatin1String("minScale")].toDouble();
if (json.contains(QLatin1String("maxScale")))
lp.maxScale = json[QLatin1String("maxScale")].toDouble();
if (json.contains(QLatin1String("basemapType")))
lp.basemapType = static_cast<BasemapType>(json[QLatin1String("basemapType")].toInt());
// maybe some more!?
return lp;
}
QJsonObject LayerParameter::toJsonObject() const
{
QJsonObject json;
json[QLatin1String("displayname")] = displayName;
json[QLatin1String("description")] = description;
json[QLatin1String("visible")] = visible;
json[QLatin1String("opacity")] = opacity;
json[QLatin1String("brightness")] = brightness;
json[QLatin1String("contrast")] = contrast;
json[QLatin1String("gamma")] = gamma;
json[QLatin1String("minScale")] = minScale;
json[QLatin1String("maxScale")] = maxScale;
json[QLatin1String("basemapType")] = static_cast<int>(basemapType);
// maybe some more!?
return json;
}
QString LayerParameter::toString() const
{
QString str;
str.append(QStringLiteral("visible=%1").arg(visible));
str.append(QStringLiteral(" opacity=%1").arg(opacity));
str.append(QStringLiteral(" brightness=%1").arg(brightness));
str.append(QStringLiteral(" contrast=%1").arg(contrast));
str.append(QStringLiteral(" gamma=%1").arg(gamma));
str.append(QStringLiteral(" minScale=%1").arg(minScale));
str.append(QStringLiteral(" maxScale=%1").arg(maxScale));
str.append(QStringLiteral(" basemapType=%1").arg((int)basemapType));
str.append(QStringLiteral(" displayName='%1'").arg(displayName));
str.append(QStringLiteral(" description='%1'").arg(description));
str.append(QStringLiteral(" previewImage.isNull=%1").arg(previewImage.isNull()));
str.append(QStringLiteral(" url='%1'").arg(url.toString()));
str.append(QStringLiteral(" svcDescription='%1'").arg(svcDescription));
return str;
}
std::ostream &operator<< (std::ostream &stream,
const LayerParameter &value)
{
stream << value.toString().toUtf8().data();
return stream;
}
} // namespace SituationMap