QGIS API Documentation 3.34.0-Prizren (ffbdd678812)
Loading...
Searching...
No Matches
qgsgeometrywidgetwrapper.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsgeometrywidgetwrapper.cpp
3 -----------------------
4 Date : February 2023
5 Copyright : (C) 2023 Nyall Dawson
6 Email : nyall dot dawson at gmail dot com
7 ***************************************************************************
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 ***************************************************************************/
15
17#include "qgsvectorlayer.h"
18#include "qgsmessagebar.h"
19#include "qgsgeometrywidget.h"
20#include <QHBoxLayout>
21#include <QFileDialog>
22#include <QLabel>
23#include <QToolButton>
24#include <QAction>
25#include <QMenu>
26#include <QMessageBox>
27#include <QUrl>
28
29QgsGeometryWidgetWrapper::QgsGeometryWidgetWrapper( QgsVectorLayer *layer, int fieldIdx, QWidget *editor, QWidget *parent, QgsMessageBar *messageBar )
30 : QgsEditorWidgetWrapper( layer, fieldIdx, editor, parent )
31 , mMessageBar( messageBar )
32{
33}
34
35
37{
38 if ( !mWidget )
39 return QVariant();
40
41 const QgsReferencedGeometry geomValue = mWidget->geometryValue();
42 if ( geomValue.isNull() )
43 return QVariant( QVariant::UserType );
44
45 return QVariant::fromValue( geomValue );
46}
47
49{
50 if ( mWidget )
51 mWidget->setReadOnly( !enabled );
52}
53
54QWidget *QgsGeometryWidgetWrapper::createWidget( QWidget *parent )
55{
57 widget->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Minimum );
58 return widget;
59}
60
62{
63 mWidget = qobject_cast<QgsGeometryWidget *>( editor );
64
65 if ( mWidget )
66 {
68 }
69}
70
72{
73 return mWidget;
74}
75
76void QgsGeometryWidgetWrapper::updateValues( const QVariant &value, const QVariantList & )
77{
80 {
81 if ( value.userType() == QMetaType::type( "QgsReferencedGeometry" ) )
82 {
83 geom = value.value< QgsReferencedGeometry >();
84 }
85 else if ( value.userType() == QMetaType::type( "QgsGeometry" ) )
86 {
88 }
89 }
90
91 if ( mWidget )
92 {
93 mWidget->setGeometryValue( geom );
94 }
95}
96
This class represents a coordinate reference system (CRS).
Manages an editor widget Widget and wrapper share the same parent.
void emitValueChanged()
Will call the value() method to determine the emitted value.
QgsGeometryWidgetWrapper(QgsVectorLayer *layer, int fieldIdx, QWidget *editor=nullptr, QWidget *parent=nullptr, QgsMessageBar *messageBar=nullptr)
Constructor for QgsGeometryWidgetWrapper.
void initWidget(QWidget *editor) override
This method should initialize the editor widget with runtime data.
bool valid() const override
Returns true if the widget has been properly initialized.
QVariant value() const override
Will be used to access the widget's value.
void setEnabled(bool enabled) override
Is used to enable or disable the edit functionality of the managed widget.
QWidget * createWidget(QWidget *parent) override
This method should create a new widget with the provided parent.
A widget for storing and interacting with a QgsGeometry object.
void setGeometryValue(const QgsReferencedGeometry &geometry)
Sets the current geometry value for the widget.
QgsReferencedGeometry geometryValue
void setReadOnly(bool readOnly)
Sets whether the widget should be in a read-only state.
void geometryValueChanged(const QgsReferencedGeometry &value)
Emitted whenever the geometry value of the widget is changed.
A geometry is the spatial representation of a feature.
A bar for displaying non-blocking messages to the user.
A QgsGeometry with associated coordinate reference system.
static bool isNull(const QVariant &variant)
Returns true if the specified variant should be considered a NULL value.
Represents a vector layer which manages a vector based data sets.
QWidget * widget()
Access the widget managed by this wrapper.