QGIS API Documentation 3.41.0-Master (af5edcb665c)
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 "moc_qgsgeometrywidgetwrapper.cpp"
18#include "qgsvectorlayer.h"
19#include "qgsmessagebar.h"
20#include "qgsgeometrywidget.h"
21#include <QHBoxLayout>
22#include <QFileDialog>
23#include <QLabel>
24#include <QToolButton>
25#include <QAction>
26#include <QMenu>
27#include <QMessageBox>
28#include <QUrl>
29
30QgsGeometryWidgetWrapper::QgsGeometryWidgetWrapper( QgsVectorLayer *layer, int fieldIdx, QWidget *editor, QWidget *parent, QgsMessageBar *messageBar )
31 : QgsEditorWidgetWrapper( layer, fieldIdx, editor, parent )
32{
33 Q_UNUSED( messageBar )
34}
35
36
38{
39 if ( !mWidget )
40 return QVariant();
41
42 const QgsReferencedGeometry geomValue = mWidget->geometryValue();
43 if ( geomValue.isNull() )
44 return QgsVariantUtils::createNullVariant( QMetaType::Type::User );
45
46 return QVariant::fromValue( geomValue );
47}
48
50{
51 if ( mWidget )
52 mWidget->setReadOnly( !enabled );
53}
54
55QWidget *QgsGeometryWidgetWrapper::createWidget( QWidget *parent )
56{
58 widget->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Minimum );
59 return widget;
60}
61
63{
64 mWidget = qobject_cast<QgsGeometryWidget *>( editor );
65
66 if ( mWidget )
67 {
69 }
70}
71
73{
74 return mWidget;
75}
76
77void QgsGeometryWidgetWrapper::updateValues( const QVariant &value, const QVariantList & )
78{
81 {
82 if ( value.userType() == qMetaTypeId<QgsReferencedGeometry>() )
83 {
84 geom = value.value<QgsReferencedGeometry>();
85 }
86 else if ( value.userType() == qMetaTypeId<QgsGeometry>() )
87 {
89 }
90 }
91
92 if ( mWidget )
93 {
94 mWidget->setGeometryValue( geom );
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, bool silenceNullWarnings=false)
Returns true if the specified variant should be considered a NULL value.
static QVariant createNullVariant(QMetaType::Type metaType)
Helper method to properly create a null QVariant from a metaType Returns the created QVariant.
Represents a vector layer which manages a vector based data sets.
QWidget * widget()
Access the widget managed by this wrapper.