Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restore and reorganise style parameters #69

Merged
merged 1 commit into from
Dec 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions examples/quick/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,12 @@ target_link_libraries(QMapLibreExampleQuick
QMapLibre::Location
)

qmaplibre_location_copy_plugin(QMapLibreExampleQuick)
qmaplibre_location_setup_plugins(QMapLibreExampleQuick)

if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
get_property(_qmlImport TARGET QMapLibreExampleQuick PROPERTY QT_QML_IMPORT_PATH)
add_custom_target(deploy
COMMAND macdeployqt QMapLibreExampleQuick.app -qmldir=${CMAKE_SOURCE_DIR}
COMMAND macdeployqt QMapLibreExampleQuick.app -qmldir=${CMAKE_SOURCE_DIR} -qmlimport=${_qmlImport}
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
)
add_dependencies(deploy QMapLibreExampleQuick)
Expand Down
14 changes: 9 additions & 5 deletions src/config.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,36 @@ include(CMakeFindDependencyMacro)
set(_@MLN_QT_NAME@_supported_components @MLN_QT_SUPPORTED_COMPONENTS@)

foreach(_comp ${@MLN_QT_NAME@_FIND_COMPONENTS})
if (NOT _comp IN_LIST _@MLN_QT_NAME@_supported_components)
if(NOT _comp IN_LIST _@MLN_QT_NAME@_supported_components)
set(@MLN_QT_NAME@_FOUND False)
set(@MLN_QT_NAME@_NOT_FOUND_MESSAGE "Unsupported component: ${_comp}")
endif()

if (_comp STREQUAL Core)
if(_comp STREQUAL Core)
find_dependency(Qt@QT_VERSION_MAJOR@ COMPONENTS Gui Network)
if(NOT @MLN_QT_WITH_INTERNAL_SQLITE@)
find_dependency(Qt@QT_VERSION_MAJOR@ COMPONENTS Sql)
endif()

include("${CMAKE_CURRENT_LIST_DIR}/@MLN_QT_NAME@${_comp}Targets.cmake")
elseif(_comp STREQUAL Location)
find_dependency(@MLN_QT_NAME@ COMPONENTS Core)

find_dependency(Qt@QT_VERSION_MAJOR@ COMPONENTS Location)

include("${CMAKE_CURRENT_LIST_DIR}/@MLN_QT_NAME@${_comp}Targets.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/@MLN_QT_NAME@${_comp}Macros.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/@MLN_QT_NAME@${_comp}PluginGeoServicesTargets.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/@MLN_QT_NAME@${_comp}PluginQmlTargets.cmake")
elseif(_comp STREQUAL Widgets)
find_dependency(@MLN_QT_NAME@ COMPONENTS Core)

if (@QT_VERSION_MAJOR@ EQUAL 6)
if(@QT_VERSION_MAJOR@ EQUAL 6)
find_dependency(Qt@QT_VERSION_MAJOR@ COMPONENTS OpenGLWidgets Widgets)
else()
find_dependency(Qt@QT_VERSION_MAJOR@ COMPONENTS OpenGL Widgets)
endif()
endif()

include("${CMAKE_CURRENT_LIST_DIR}/@MLN_QT_NAME@${_comp}Targets.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/@MLN_QT_NAME@${_comp}Targets.cmake")
endif()
endforeach()
15 changes: 15 additions & 0 deletions src/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ set(Core_Headers
settings.hpp
types.hpp
utils.hpp

style/style_parameter.hpp
style/layer_parameter.hpp
style/source_parameter.hpp
)
# Header generation
mln_umbrella_header_preprocess(${MLN_QT_NAME_LOWERCASE} ${MLN_QT_NAME} HeaderOut)
Expand Down Expand Up @@ -52,6 +56,16 @@ target_sources(
settings.cpp settings_p.hpp
types.cpp
utils.cpp

style/style_parameter.cpp
style/layer_parameter.cpp
style/source_parameter.cpp

style/style_change.cpp style/style_change_p.hpp
style/style_change_utils.cpp style/style_change_utils_p.hpp
style/image_style_change.cpp style/image_style_change_p.hpp
style/layer_style_change.cpp style/layer_style_change_p.hpp
style/source_style_change.cpp style/source_style_change_p.hpp
)

# Linux/Mac: Set framework, version and headers
Expand Down Expand Up @@ -89,6 +103,7 @@ target_include_directories(
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/style
${CMAKE_CURRENT_BINARY_DIR}/include
${MLN_CORE_PATH}/src
)
Expand Down
14 changes: 10 additions & 4 deletions src/core/conversion_p.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,12 @@ class ConversionTraits<QVariant> {

static std::optional<float> toNumber(const QVariant &value) {
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
if (value.typeId() == QMetaType::Int || value.typeId() == QMetaType::Double) {
if (value.typeId() == QMetaType::Int || value.typeId() == QMetaType::Double ||
value.typeId() == QMetaType::Long || value.typeId() == QMetaType::LongLong ||
value.typeId() == QMetaType::ULong || value.typeId() == QMetaType::ULongLong) {
#else
if (value.type() == QVariant::Int || value.type() == QVariant::Double) {
if (value.type() == QVariant::Int || value.type() == QVariant::Double || value.type() == QVariant::LongLong ||
value.type() == QVariant::ULongLong) {
#endif
return value.toFloat();
}
Expand All @@ -104,9 +107,12 @@ class ConversionTraits<QVariant> {

static std::optional<double> toDouble(const QVariant &value) {
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
if (value.typeId() == QMetaType::Int || value.typeId() == QMetaType::Double) {
if (value.typeId() == QMetaType::Int || value.typeId() == QMetaType::Double ||
value.typeId() == QMetaType::Long || value.typeId() == QMetaType::LongLong ||
value.typeId() == QMetaType::ULong || value.typeId() == QMetaType::ULongLong) {
#else
if (value.type() == QVariant::Int || value.type() == QVariant::Double) {
if (value.type() == QVariant::Int || value.type() == QVariant::Double || value.type() == QVariant::LongLong ||
value.type() == QVariant::ULongLong) {
#endif
return value.toDouble();
}
Expand Down
72 changes: 36 additions & 36 deletions src/core/map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -699,8 +699,8 @@ void Map::removeAnnotation(AnnotationID id) {
\li QVariantList
\endtable
*/
bool Map::setLayoutProperty(const QString &layer, const QString &propertyName, const QVariant &value) {
return d_ptr->setProperty(&mbgl::style::Layer::setProperty, layer, propertyName, value);
bool Map::setLayoutProperty(const QString &layerId, const QString &propertyName, const QVariant &value) {
return d_ptr->setProperty(&mbgl::style::Layer::setProperty, layerId, propertyName, value);
}

/*!
Expand Down Expand Up @@ -758,8 +758,8 @@ bool Map::setLayoutProperty(const QString &layer, const QString &propertyName, c
\endcode
*/

bool Map::setPaintProperty(const QString &layer, const QString &propertyName, const QVariant &value) {
return d_ptr->setProperty(&mbgl::style::Layer::setProperty, layer, propertyName, value);
bool Map::setPaintProperty(const QString &layerId, const QString &propertyName, const QVariant &value) {
return d_ptr->setProperty(&mbgl::style::Layer::setProperty, layerId, propertyName, value);
}

/*!
Expand Down Expand Up @@ -929,18 +929,18 @@ void Map::addSource(const QString &id, const QVariantMap &params) {
mbgl::style::conversion::convert<std::unique_ptr<mbgl::style::Source>>(
QVariant(params), error, id.toStdString());
if (!source) {
qWarning() << "Unable to add source:" << error.message.c_str();
qWarning() << "Unable to add source with id" << id << ":" << error.message.c_str();
return;
}

d_ptr->mapObj->getStyle().addSource(std::move(*source));
}

/*!
Returns true if the layer with given \a sourceID exists, false otherwise.
Returns true if the layer with given \a id exists, false otherwise.
*/
bool Map::sourceExists(const QString &sourceID) {
return d_ptr->mapObj->getStyle().getSource(sourceID.toStdString()) != nullptr;
bool Map::sourceExists(const QString &id) {
return d_ptr->mapObj->getStyle().getSource(id.toStdString()) != nullptr;
}

/*!
Expand Down Expand Up @@ -980,10 +980,10 @@ void Map::updateSource(const QString &id, const QVariantMap &params) {
This method has no effect if the source does not exist.
*/
void Map::removeSource(const QString &id) {
auto sourceIDStdString = id.toStdString();
auto idStdString = id.toStdString();

if (d_ptr->mapObj->getStyle().getSource(sourceIDStdString) != nullptr) {
d_ptr->mapObj->getStyle().removeSource(sourceIDStdString);
if (d_ptr->mapObj->getStyle().getSource(idStdString) != nullptr) {
d_ptr->mapObj->getStyle().removeSource(idStdString);
}
}

Expand Down Expand Up @@ -1047,12 +1047,12 @@ void Map::addCustomLayer(const QString &id, std::unique_ptr<CustomLayerHostInter

/note The source must exist prior to adding a layer.
*/
void Map::addLayer(const QVariantMap &params, const QString &before) {
void Map::addLayer(const QString &id, const QVariantMap &params, const QString &before) {
mbgl::style::conversion::Error error;
std::optional<std::unique_ptr<mbgl::style::Layer>> layer =
mbgl::style::conversion::convert<std::unique_ptr<mbgl::style::Layer>>(QVariant(params), error);
if (!layer) {
qWarning() << "Unable to add layer:" << error.message.c_str();
qWarning() << "Unable to add layer with id" << id << ":" << error.message.c_str();
return;
}

Expand Down Expand Up @@ -1101,19 +1101,19 @@ QVector<QString> Map::layerIds() const {

\sa addLayer()
*/
void Map::addImage(const QString &name, const QImage &sprite) {
void Map::addImage(const QString &id, const QImage &sprite) {
if (sprite.isNull()) {
return;
}

d_ptr->mapObj->getStyle().addImage(toStyleImage(name, sprite));
d_ptr->mapObj->getStyle().addImage(toStyleImage(id, sprite));
}

/*!
Removes the image \a id.
*/
void Map::removeImage(const QString &name) {
d_ptr->mapObj->getStyle().removeImage(name.toStdString());
void Map::removeImage(const QString &id) {
d_ptr->mapObj->getStyle().removeImage(id.toStdString());
}

/*!
Expand All @@ -1136,10 +1136,10 @@ void Map::removeImage(const QString &name) {
map->setFilter(QLatin1String("marker"), filter);
\endcode
*/
void Map::setFilter(const QString &layer, const QVariant &filter) {
mbgl::style::Layer *layer_ = d_ptr->mapObj->getStyle().getLayer(layer.toStdString());
if (layer_ == nullptr) {
qWarning() << "Layer not found:" << layer;
void Map::setFilter(const QString &layerId, const QVariant &filter) {
mbgl::style::Layer *layer = d_ptr->mapObj->getStyle().getLayer(layerId.toStdString());
if (layer == nullptr) {
qWarning() << "Layer not found:" << layerId;
return;
}

Expand All @@ -1150,7 +1150,7 @@ void Map::setFilter(const QString &layer, const QVariant &filter) {
return;
}

layer_->setFilter(*converted);
layer->setFilter(*converted);
}

QVariant QVariantFromValue(const mbgl::Value &value) {
Expand Down Expand Up @@ -1186,18 +1186,18 @@ QVariant QVariantFromValue(const mbgl::Value &value) {

/*!
Returns the current \a expression-based filter value applied to a style
\layer, if any.
\layerId, if any.

Filter value types are described in the {https://maplibre.org/maplibre-style-spec/types/}{MapLibre Style Spec}.
*/
QVariant Map::getFilter(const QString &layer) const {
mbgl::style::Layer *layer_ = d_ptr->mapObj->getStyle().getLayer(layer.toStdString());
if (layer_ == nullptr) {
qWarning() << "Layer not found:" << layer;
QVariant Map::getFilter(const QString &layerId) const {
mbgl::style::Layer *layer = d_ptr->mapObj->getStyle().getLayer(layerId.toStdString());
if (layer == nullptr) {
qWarning() << "Layer not found:" << layerId;
return {};
}

auto serialized = layer_->getFilter().serialize();
auto serialized = layer->getFilter().serialize();
return QVariantFromValue(serialized);
}

Expand Down Expand Up @@ -1448,12 +1448,12 @@ void MapPrivate::requestRendering() {
}

bool MapPrivate::setProperty(const PropertySetter &setter,
const QString &layer,
const QString &layerId,
const QString &name,
const QVariant &value) const {
mbgl::style::Layer *layerObject = mapObj->getStyle().getLayer(layer.toStdString());
if (layerObject == nullptr) {
qWarning() << "Layer not found:" << layer;
mbgl::style::Layer *layer = mapObj->getStyle().getLayer(layerId.toStdString());
if (layer == nullptr) {
qWarning() << "Layer not found:" << layerId;
return false;
}

Expand All @@ -1471,16 +1471,16 @@ bool MapPrivate::setProperty(const PropertySetter &setter,
if (!document.HasParseError()) {
// Treat value as a valid JSON.
const mbgl::JSValue *jsonValue = &document;
result = (layerObject->*setter)(propertyString, jsonValue);
result = (layer->*setter)(propertyString, jsonValue);
} else {
result = (layerObject->*setter)(propertyString, value);
result = (layer->*setter)(propertyString, value);
}
} else {
result = (layerObject->*setter)(propertyString, value);
result = (layer->*setter)(propertyString, value);
}

if (result) {
qWarning() << "Error setting property" << name << "on layer" << layer << ":"
qWarning() << "Error setting property" << name << "on layer" << layerId << ":"
<< QString::fromStdString(result->message);
return false;
}
Expand Down
22 changes: 11 additions & 11 deletions src/core/map.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ class Q_MAPLIBRE_CORE_EXPORT Map : public QObject {
void updateAnnotation(AnnotationID, const Annotation &);
void removeAnnotation(AnnotationID);

bool setLayoutProperty(const QString &layer, const QString &property, const QVariant &value);
bool setPaintProperty(const QString &layer, const QString &property, const QVariant &value);
bool setLayoutProperty(const QString &layerId, const QString &propertyName, const QVariant &value);
bool setPaintProperty(const QString &layerId, const QString &propertyName, const QVariant &value);

[[nodiscard]] bool isFullyLoaded() const;

Expand All @@ -150,25 +150,25 @@ class Q_MAPLIBRE_CORE_EXPORT Map : public QObject {
void setMargins(const QMargins &margins);
[[nodiscard]] QMargins margins() const;

void addSource(const QString &sourceID, const QVariantMap &params);
bool sourceExists(const QString &sourceID);
void updateSource(const QString &sourceID, const QVariantMap &params);
void removeSource(const QString &sourceID);
void addSource(const QString &id, const QVariantMap &params);
bool sourceExists(const QString &id);
void updateSource(const QString &id, const QVariantMap &params);
void removeSource(const QString &id);

void addImage(const QString &name, const QImage &sprite);
void removeImage(const QString &name);
void addImage(const QString &id, const QImage &sprite);
void removeImage(const QString &id);

void addCustomLayer(const QString &id,
std::unique_ptr<CustomLayerHostInterface> host,
const QString &before = QString());
void addLayer(const QVariantMap &params, const QString &before = QString());
void addLayer(const QString &id, const QVariantMap &params, const QString &before = QString());
bool layerExists(const QString &id);
void removeLayer(const QString &id);

[[nodiscard]] QVector<QString> layerIds() const;

void setFilter(const QString &layer, const QVariant &filter);
[[nodiscard]] QVariant getFilter(const QString &layer) const;
void setFilter(const QString &layerId, const QVariant &filter);
[[nodiscard]] QVariant getFilter(const QString &layerId) const;
// When rendering on a different thread,
// should be called on the render thread.
void createRenderer();
Expand Down
2 changes: 1 addition & 1 deletion src/core/map_p.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class MapPrivate : public QObject, public mbgl::RendererFrontend {
using PropertySetter = std::optional<mbgl::style::conversion::Error> (mbgl::style::Layer::*)(
const std::string &, const mbgl::style::conversion::Convertible &);
[[nodiscard]] bool setProperty(const PropertySetter &setter,
const QString &layer,
const QString &layerId,
const QString &name,
const QVariant &value) const;

Expand Down
Loading