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

Relation editor rework to allow for map panning/zooming to child feature #4391

Merged
merged 13 commits into from
Jul 7, 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
2 changes: 2 additions & 0 deletions images/images.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,7 @@
<file>themes/qfield/xhdpi/ic_info_white_18dp.png</file>
<file>themes/qfield/xxhdpi/ic_info_white_18dp.png</file>
<file>themes/qfield/xxxhdpi/ic_info_white_18dp.png</file>
<file>themes/qfield/nodpi/ic_baseline-list_alt-24dp.svg</file>
<file>themes/qfield/hdpi/ic_baseline-list_alt-24px.png</file>
<file>themes/qfield/mdpi/ic_baseline-list_alt-24px.png</file>
<file>themes/qfield/xhdpi/ic_baseline-list_alt-24px.png</file>
Expand All @@ -418,6 +419,7 @@
<file>themes/qfield/mdpi/ic_edit_geometry_white.png</file>
<file>themes/qfield/xhdpi/ic_edit_geometry_white.png</file>
<file>themes/qfield/xxhdpi/ic_edit_geometry_white.png</file>
<file>themes/qfield/nodpi/ic_edit_attributes_white-24dp.svg</file>
<file>themes/qfield/hdpi/ic_edit_attributes_white.png</file>
<file>themes/qfield/xxxhdpi/ic_edit_attributes_white.png</file>
<file>themes/qfield/mdpi/ic_edit_attributes_white.png</file>
Expand Down
24 changes: 4 additions & 20 deletions src/core/featurelistextentcontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
***************************************************************************/

#include "featurelistextentcontroller.h"
#include "featureutils.h"

#include <qgsgeometry.h>
#include <qgsvectorlayer.h>
Expand Down Expand Up @@ -54,26 +55,9 @@ void FeatureListExtentController::zoomToSelected( bool skipIfIntersects ) const

if ( layer && layer->geometryType() != Qgis::GeometryType::Unknown && layer->geometryType() != Qgis::GeometryType::Null )
{
QgsCoordinateTransform transf( layer->crs(), mMapSettings->destinationCrs(), mMapSettings->mapSettings().transformContext() );
QgsGeometry geom( feat.geometry() );
if ( !geom.isNull() )
{
geom.transform( transf );

if ( geom.type() == Qgis::GeometryType::Point )
{
if ( !skipIfIntersects || !mMapSettings->extent().intersects( geom.boundingBox() ) )
mMapSettings->setCenter( QgsPoint( geom.asPoint() ) );
}
else
{
QgsRectangle featureExtent = geom.boundingBox();
QgsRectangle bufferedExtent = featureExtent.buffered( std::max( featureExtent.width(), featureExtent.height() ) );

if ( !skipIfIntersects || !mMapSettings->extent().intersects( bufferedExtent ) )
mMapSettings->setExtent( bufferedExtent );
}
}
QgsRectangle extent = FeatureUtils::extent( mMapSettings, layer, feat, mFeatureForm ? mFeatureForm->x() : 0.0, mFeatureForm ? mFeatureForm->y() : 0.0 );
if ( !skipIfIntersects || !mMapSettings->extent().intersects( extent ) )
mMapSettings->setExtent( extent );
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/core/featurelistextentcontroller.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "qgsquickmapsettings.h"

#include <QObject>
#include <QQuickItem>

class FeatureListExtentController : public QObject
{
Expand All @@ -30,6 +31,7 @@ class FeatureListExtentController : public QObject
Q_PROPERTY( FeatureListModelSelection *selection MEMBER mSelection NOTIFY selectionChanged )
Q_PROPERTY( bool autoZoom MEMBER mAutoZoom NOTIFY autoZoomChanged )
Q_PROPERTY( QgsQuickMapSettings *mapSettings MEMBER mMapSettings NOTIFY mapSettingsChanged )
Q_PROPERTY( QQuickItem *featureForm MEMBER mFeatureForm NOTIFY featureFormChanged )

public:
explicit FeatureListExtentController( QObject *parent = nullptr );
Expand All @@ -54,6 +56,7 @@ class FeatureListExtentController : public QObject
void selectionChanged();
void modelChanged();
void mapSettingsChanged();
void featureFormChanged();
void featureFormStateRequested();

private slots:
Expand All @@ -64,6 +67,7 @@ class FeatureListExtentController : public QObject
MultiFeatureListModel *mModel = nullptr;
FeatureListModelSelection *mSelection = nullptr;
QgsQuickMapSettings *mMapSettings = nullptr;
QQuickItem *mFeatureForm = nullptr;
bool mAutoZoom = false;
};

Expand Down
2 changes: 1 addition & 1 deletion src/core/orderedrelationmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ QVariant OrderedRelationModel::data( const QModelIndex &index, int role ) const
return ReferencingFeatureListModel::data( index, role );
}

void OrderedRelationModel::onViewCurrentFeatureChanged( int index )
void OrderedRelationModel::triggerViewCurrentFeatureChange( int index )
{
if ( index < 0 || index >= rowCount( QModelIndex() ) )
return;
Expand Down
4 changes: 1 addition & 3 deletions src/core/orderedrelationmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class OrderedRelationModel : public ReferencingFeatureListModel
QVariant data( const QModelIndex &index, int role = Qt::DisplayRole ) const override;
Q_INVOKABLE bool moveItems( const int fromIdx, const int toIdx );
QHash<int, QByteArray> roleNames() const override;
Q_INVOKABLE void triggerViewCurrentFeatureChange( int index );

signals:
void orderingFieldChanged();
Expand All @@ -60,9 +61,6 @@ class OrderedRelationModel : public ReferencingFeatureListModel
void currentFeatureChanged( QgsFeature feature );
void failedReorder();

private slots:
void onViewCurrentFeatureChanged( int index );

private:
bool beforeDeleteFeature( QgsVectorLayer *referencingLayer, QgsFeatureId referencingFeatureId ) override;
void sortEntries() override;
Expand Down
4 changes: 2 additions & 2 deletions src/core/qgssggeometry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ QgsSGGeometry::QgsSGGeometry( const QgsGeometry &geom, const QColor &color, floa
if ( pg.isMultipart() )
{
QSGOpacityNode *on = new QSGOpacityNode;
on->setOpacity( 0.5 );
on->setOpacity( 0.25 );

QgsGeometryPartIterator it = pg.parts();
while ( it.hasNext() )
Expand Down Expand Up @@ -105,7 +105,7 @@ QgsSGGeometry::QgsSGGeometry( const QgsGeometry &geom, const QColor &color, floa
else
{
QSGOpacityNode *on = new QSGOpacityNode;
on->setOpacity( 0.5 );
on->setOpacity( 0.25 );
QSGGeometryNode *geomNode = new QSGGeometryNode;
QgsCurvePolygon *c = qgsgeometry_cast<QgsCurvePolygon *>( pg.get() );
if ( !c )
Expand Down
47 changes: 47 additions & 0 deletions src/core/utils/featureutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
***************************************************************************/

#include "featureutils.h"
#include "qgsquickmapsettings.h"

#include <qgsexpressioncontextutils.h>
#include <qgsproject.h>
Expand Down Expand Up @@ -50,3 +51,49 @@ QString FeatureUtils::displayName( QgsVectorLayer *layer, const QgsFeature &feat

return name;
}

QgsRectangle FeatureUtils::extent( QgsQuickMapSettings *mapSettings, QgsVectorLayer *layer, const QgsFeature &feature, const double &rightEdge, const double &bottomEdge )
{
if ( mapSettings && layer && layer->geometryType() != Qgis::GeometryType::Unknown && layer->geometryType() != Qgis::GeometryType::Null )
{
QgsCoordinateTransform transf( layer->crs(), mapSettings->destinationCrs(), mapSettings->mapSettings().transformContext() );
QgsGeometry geom( feature.geometry() );
if ( !geom.isNull() )
{
geom.transform( transf );

QgsRectangle extent;
const double rightPercentage = rightEdge / mapSettings->outputSize().width();
const double bottomPercentage = bottomEdge / mapSettings->outputSize().height();
if ( geom.type() == Qgis::GeometryType::Point )
{
extent = mapSettings->extent();
QgsVector delta = QgsPointXY( geom.asPoint() ) - extent.center();
const double deltaX = delta.x() + ( rightEdge > 0.0 ? mapSettings->mapUnitsPerPoint() * mapSettings->outputSize().width() * ( 0.5 - rightPercentage / 2.0 ) : 0.0 );
const double deltaY = delta.y() - ( bottomEdge > 0.0 ? mapSettings->mapUnitsPerPoint() * mapSettings->outputSize().height() * ( 0.5 - ( 1.0 - bottomPercentage ) / 2.0 ) : 0.0 );
extent.setXMinimum( extent.xMinimum() + deltaX );
extent.setXMaximum( extent.xMaximum() + deltaX );
extent.setYMinimum( extent.yMinimum() + deltaY );
extent.setYMaximum( extent.yMaximum() + deltaY );
}
else
{
extent = geom.boundingBox();
extent = extent.buffered( std::max( extent.width(), extent.height() ) / 6.0 );

if ( rightEdge > 0.0 )
{
extent.setXMaximum( extent.xMaximum() + ( extent.xMaximum() - extent.xMinimum() ) * rightPercentage );
}
if ( bottomEdge > 0.0 )
{
extent.setYMinimum( extent.yMinimum() - ( extent.yMaximum() - extent.yMinimum() ) * bottomPercentage * 2 );
}
}

return extent;
}
}

return QgsRectangle();
}
12 changes: 12 additions & 0 deletions src/core/utils/featureutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <qgsgeometry.h>

class QgsVectorLayer;
class QgsQuickMapSettings;

class QFIELD_CORE_EXPORT FeatureUtils : public QObject
{
Expand All @@ -38,6 +39,17 @@ class QFIELD_CORE_EXPORT FeatureUtils : public QObject
* \param feature the feature to be named
*/
static Q_INVOKABLE QString displayName( QgsVectorLayer *layer, const QgsFeature &feature );

/**
* Returns the map extent encompassig a given feature
* \param mapSettings the map settings used to determine the CRS
* \param layer the vector layer containing the feature
* \param feature the feature from which the geometry will be used
* \param righeEdge provide a right edge beyond which the canvas is hidden and extent shouldn't overlap with
* \param bottomEdge provide a bottom edge beyond which the canvas is hidden and extent shouldn't overlap with
* \returns a QgsRectangle extent
*/
static Q_INVOKABLE QgsRectangle extent( QgsQuickMapSettings *mapSettings, QgsVectorLayer *layer, const QgsFeature &feature, const double &rightEdge = 0.0, const double &bottomEdge = 0.0 );
};

#endif // FEATUREUTILS_H
1 change: 1 addition & 0 deletions src/qml/FeatureListForm.qml
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,7 @@ Rectangle {
model: globalFeaturesList.model
selection: featureForm.selection
mapSettings: featureForm.mapSettings
featureForm: featureForm

onFeatureFormStateRequested: {
featureForm.state = "FeatureForm"
Expand Down
2 changes: 1 addition & 1 deletion src/qml/FeatureListSelectionHighlight.qml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Repeater {

visible: featureListSelectionHighlight.visible && ( !showSelectedOnly || model.featureSelected )
color: model.featureSelected ? featureListSelectionHighlight.selectedColor : selectionModel.model.selectedCount === 0 && selectionModel && model.index === selectionModel.focusedItem ? featureListSelectionHighlight.focusedColor : featureListSelectionHighlight.color
borderColor: "white"
z: model.index === selectionModel.focusedItem ? 1 : 0

transform: Translate {
x: featureListSelectionHighlight.translateX
Expand Down
37 changes: 27 additions & 10 deletions src/qml/GeometryHighlighter.qml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,31 @@ import org.qfield 1.0

Item {
id: geometryHighlighter

property alias geometryWrapper: geometryRenderer.geometryWrapper
property int duration: 3000

Connections {
target: geometryRenderer.geometryWrapper
SequentialAnimation {
id: timer
running: false
loops: 3
alwaysRunToEnd: true

function onQgsGeometryChanged() {
timer.restart()
OpacityAnimator {
target: geometryHighlighter;
from: 1;
to: 0;
duration: 500
}
OpacityAnimator {
target: geometryHighlighter;
from: 0;
to: 1;
duration: 500
}

onFinished: {
geometryHighlighter.geometryWrapper.clear()
}
}

Expand All @@ -20,11 +37,11 @@ Item {
mapSettings: mapCanvas.mapSettings
}

Timer {
id: timer
interval: geometryHighlighter.duration
running: false
repeat: false
onTriggered: geometryHighlighter.geometryWrapper.clear()
Connections {
target: geometryRenderer.geometryWrapper

function onQgsGeometryChanged() {
timer.restart()
}
}
}
9 changes: 4 additions & 5 deletions src/qml/GeometryRenderer.qml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@ Item {
property MapSettings mapSettings
property alias geometryWrapper: geometryWrapper
property double lineWidth: 3.5
property color color: "yellow"
property color color: "#ff0000"
property double pointSize: 20
property color borderColor: "blue"
property double borderSize: 2
property double borderSize: 3

QgsGeometryWrapper {
id: geometryWrapper
Expand Down Expand Up @@ -70,12 +69,12 @@ Item {
x: mapToScreenPosition.screenPoint.x - width/2
y: mapToScreenPosition.screenPoint.y - width/2

color: geometryRenderer.color
color: Qt.hsla(geometryRenderer.color.hslHue, geometryRenderer.color.hslSaturation, geometryRenderer.color.hslLightness, 0.5)
width: geometryRenderer.pointSize
height: geometryRenderer.pointSize
radius: geometryRenderer.pointSize / 2

border.color: geometryRenderer.borderColor
border.color: geometryRenderer.color
border.width: geometryRenderer.borderSize
}
}
Expand Down
13 changes: 13 additions & 0 deletions src/qml/LocatorItem.qml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import QtQuick 2.14
import QtQuick.Controls 2.14
import QtQuick.Controls.Material 2.14
import QtQuick.Controls.Material.impl 2.14

import org.qgis 1.0
import org.qfield 1.0
Expand Down Expand Up @@ -272,6 +274,16 @@ Item {
color: isFilterName ? Theme.mainColor : isGroup ? Theme.controlBorderColor : "transparent"
opacity: 0.95

Ripple {
clip: true
width: parent.width
height: parent.height
pressed: mouseArea.pressed
anchor: delegateRect
active: mouseArea.pressed
color: Material.rippleColor
}

Text {
id: textCell
text: isFilterName ? model.ResultFilterName : model.Text.trim()
Expand Down Expand Up @@ -322,6 +334,7 @@ Item {
}

MouseArea {
id: mouseArea
anchors.left: parent.left
anchors.top: parent.top
anchors.bottom: parent.bottom
Expand Down
Loading