QGIS API Documentation 3.99.0-Master (26c88405ac0)
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
18#include "qgsgeometrywidget.h"
19#include "qgsmessagebar.h"
20#include "qgsvectorlayer.h"
21
22#include <QAction>
23#include <QFileDialog>
24#include <QHBoxLayout>
25#include <QLabel>
26#include <QMenu>
27#include <QMessageBox>
28#include <QToolButton>
29#include <QUrl>
30
31#include "moc_qgsgeometrywidgetwrapper.cpp"
32
34 : QgsEditorWidgetWrapper( layer, fieldIdx, editor, parent )
35{
36 Q_UNUSED( messageBar )
37}
38
39
41{
42 if ( !mWidget )
43 return QVariant();
44
45 const QgsReferencedGeometry geomValue = mWidget->geometryValue();
46 if ( geomValue.isNull() )
47 return QgsVariantUtils::createNullVariant( QMetaType::Type::User );
48
49 return QVariant::fromValue( geomValue );
50}
51
53{
54 if ( mWidget )
55 mWidget->setReadOnly( !enabled );
56}
57
58QWidget *QgsGeometryWidgetWrapper::createWidget( QWidget *parent )
59{
61 widget->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Minimum );
62 return widget;
63}
64
66{
67 mWidget = qobject_cast<QgsGeometryWidget *>( editor );
68
69 if ( mWidget )
70 {
72 }
73}
74
76{
77 return mWidget;
78}
79
80void QgsGeometryWidgetWrapper::updateValues( const QVariant &value, const QVariantList & )
81{
84 {
85 if ( value.userType() == qMetaTypeId<QgsReferencedGeometry>() )
86 {
87 geom = value.value<QgsReferencedGeometry>();
88 }
89 else if ( value.userType() == qMetaTypeId<QgsGeometry>() )
90 {
91 geom = QgsReferencedGeometry( value.value<QgsGeometry>(), QgsCoordinateReferenceSystem() );
92 }
93 }
94
95 if ( mWidget )
96 {
97 mWidget->setGeometryValue( geom );
98 }
99}
int fieldIdx() const
Access the field index.
QgsEditorWidgetWrapper(QgsVectorLayer *vl, int fieldIdx, QWidget *editor=nullptr, QWidget *parent=nullptr)
Create a new widget wrapper.
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 geometryValueChanged(const QgsReferencedGeometry &value)
Emitted whenever the geometry value of the widget is changed.
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 dataset.
QWidget * widget()
Access the widget managed by this wrapper.
QgsVectorLayer * layer() const
Returns the vector layer associated with the widget.