Skip to content

Commit

Permalink
Restore and reorganise style parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
ntadej committed Nov 26, 2023
1 parent 3f29481 commit 0bcfcc6
Show file tree
Hide file tree
Showing 51 changed files with 2,141 additions and 700 deletions.
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()
14 changes: 14 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,15 @@ 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/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 +102,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 ||

Check warning on line 111 in src/core/conversion_p.hpp

View check run for this annotation

Codecov / codecov/patch

src/core/conversion_p.hpp#L111

Added line #L111 was not covered by tests
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
70 changes: 36 additions & 34 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);

Check warning on line 703 in src/core/map.cpp

View check run for this annotation

Codecov / codecov/patch

src/core/map.cpp#L702-L703

Added lines #L702 - L703 were not covered by tests
}

/*!
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 @@ -937,10 +937,10 @@ void Map::addSource(const QString &id, const QVariantMap &params) {
}

/*!
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;

Check warning on line 943 in src/core/map.cpp

View check run for this annotation

Codecov / codecov/patch

src/core/map.cpp#L942-L943

Added lines #L942 - L943 were not covered by tests
}

/*!
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,7 +1047,9 @@ 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) {
Q_UNUSED(id)

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);
Expand Down Expand Up @@ -1101,19 +1103,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) {

Check warning on line 1106 in src/core/map.cpp

View check run for this annotation

Codecov / codecov/patch

src/core/map.cpp#L1106

Added line #L1106 was not covered by tests
if (sprite.isNull()) {
return;
}

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

Check warning on line 1111 in src/core/map.cpp

View check run for this annotation

Codecov / codecov/patch

src/core/map.cpp#L1111

Added line #L1111 was not covered by tests
}

/*!
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());

Check warning on line 1118 in src/core/map.cpp

View check run for this annotation

Codecov / codecov/patch

src/core/map.cpp#L1117-L1118

Added lines #L1117 - L1118 were not covered by tests
}

/*!
Expand All @@ -1136,10 +1138,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;

Check warning on line 1144 in src/core/map.cpp

View check run for this annotation

Codecov / codecov/patch

src/core/map.cpp#L1141-L1144

Added lines #L1141 - L1144 were not covered by tests
return;
}

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

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

Check warning on line 1155 in src/core/map.cpp

View check run for this annotation

Codecov / codecov/patch

src/core/map.cpp#L1155

Added line #L1155 was not covered by tests
}

QVariant QVariantFromValue(const mbgl::Value &value) {
Expand Down Expand Up @@ -1186,18 +1188,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;

Check warning on line 1198 in src/core/map.cpp

View check run for this annotation

Codecov / codecov/patch

src/core/map.cpp#L1195-L1198

Added lines #L1195 - L1198 were not covered by tests
return {};
}

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

Check warning on line 1202 in src/core/map.cpp

View check run for this annotation

Codecov / codecov/patch

src/core/map.cpp#L1202

Added line #L1202 was not covered by tests
return QVariantFromValue(serialized);
}

Expand Down Expand Up @@ -1448,12 +1450,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;

Check warning on line 1458 in src/core/map.cpp

View check run for this annotation

Codecov / codecov/patch

src/core/map.cpp#L1458

Added line #L1458 was not covered by tests
return false;
}

Expand All @@ -1471,16 +1473,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);

Check warning on line 1476 in src/core/map.cpp

View check run for this annotation

Codecov / codecov/patch

src/core/map.cpp#L1476

Added line #L1476 was not covered by tests
} else {
result = (layerObject->*setter)(propertyString, value);
result = (layer->*setter)(propertyString, value);

Check warning on line 1478 in src/core/map.cpp

View check run for this annotation

Codecov / codecov/patch

src/core/map.cpp#L1478

Added line #L1478 was not covered by tests
}
} 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 << ":"

Check warning on line 1485 in src/core/map.cpp

View check run for this annotation

Codecov / codecov/patch

src/core/map.cpp#L1485

Added line #L1485 was not covered by tests
<< 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
31 changes: 31 additions & 0 deletions src/core/style/image_style_change.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright (C) 2023 MapLibre contributors

// SPDX-License-Identifier: BSD-2-Clause

#include "image_style_change_p.hpp"

#include <QMapLibre/Map>

namespace QMapLibre {

// StyleAddImage
StyleAddImage::StyleAddImage(const StyleParameter *parameter)
: m_id(parameter->property("id").toString()),
m_sprite(QImage(parameter->property("sprite").toString())) {}

Check warning on line 14 in src/core/style/image_style_change.cpp

View check run for this annotation

Codecov / codecov/patch

src/core/style/image_style_change.cpp#L12-L14

Added lines #L12 - L14 were not covered by tests

void StyleAddImage::apply(Map *map) {
map->addImage(m_id, m_sprite);
}

Check warning on line 18 in src/core/style/image_style_change.cpp

View check run for this annotation

Codecov / codecov/patch

src/core/style/image_style_change.cpp#L16-L18

Added lines #L16 - L18 were not covered by tests

// StyleRemoveImage
StyleRemoveImage::StyleRemoveImage(QString id)
: m_id(std::move(id)) {}

Check warning on line 22 in src/core/style/image_style_change.cpp

View check run for this annotation

Codecov / codecov/patch

src/core/style/image_style_change.cpp#L21-L22

Added lines #L21 - L22 were not covered by tests

StyleRemoveImage::StyleRemoveImage(const StyleParameter *parameter)
: m_id(parameter->property("id").toString()) {}

Check warning on line 25 in src/core/style/image_style_change.cpp

View check run for this annotation

Codecov / codecov/patch

src/core/style/image_style_change.cpp#L24-L25

Added lines #L24 - L25 were not covered by tests

void StyleRemoveImage::apply(Map *map) {
map->removeImage(m_id);
}

Check warning on line 29 in src/core/style/image_style_change.cpp

View check run for this annotation

Codecov / codecov/patch

src/core/style/image_style_change.cpp#L27-L29

Added lines #L27 - L29 were not covered by tests

} // namespace QMapLibre
Loading

0 comments on commit 0bcfcc6

Please sign in to comment.