QGIS API Documentation 3.41.0-Master (cea29feecf2)
Loading...
Searching...
No Matches
qgskeyvaluewidgetwrapper.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgskeyvaluewidgetwrapper.cpp
3 --------------------------------------
4 Date : 08.2016
5 Copyright : (C) 2016 Patrick Valsecchi
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_qgskeyvaluewidgetwrapper.cpp"
18#include "qgskeyvaluewidget.h"
19#include "qgsattributeform.h"
20
21QgsKeyValueWidgetWrapper::QgsKeyValueWidgetWrapper( QgsVectorLayer *layer, int fieldIdx, QWidget *editor, QWidget *parent )
22 : QgsEditorWidgetWrapper( layer, fieldIdx, editor, parent )
23{
24}
25
27{
28 if ( !mWidget )
29 return QgsVariantUtils::createNullVariant( QMetaType::Type::QVariantMap );
30 return mWidget->map();
31}
32
34{
35 mWidget->setMap( QVariantMap() );
36}
37
39{
40 if ( mWidget )
41 {
42 mWidget->setReadOnly( !enabled );
43 }
44}
45
46QWidget *QgsKeyValueWidgetWrapper::createWidget( QWidget *parent )
47{
48 if ( isInTable( parent ) )
49 {
50 // if to be put in a table, draw a border and set a decent size
51 QFrame *ret = new QFrame( parent );
52 ret->setFrameShape( QFrame::StyledPanel );
53 QHBoxLayout *layout = new QHBoxLayout( ret );
54 layout->addWidget( new QgsKeyValueWidget( ret ) );
55 ret->setMinimumSize( QSize( 320, 110 ) );
56 return ret;
57 }
58 else
59 {
60 return new QgsKeyValueWidget( parent );
61 }
62}
63
65{
66 mWidget = qobject_cast<QgsKeyValueWidget *>( editor );
67 if ( !mWidget )
68 {
69 mWidget = editor->findChild<QgsKeyValueWidget *>();
70 }
71
72 connect( mWidget, &QgsKeyValueWidget::valueChanged, this, &QgsKeyValueWidgetWrapper::onValueChanged );
73}
74
76{
77 return true;
78}
79
80void QgsKeyValueWidgetWrapper::updateValues( const QVariant &value, const QVariantList & )
81{
82 mWidget->setMap( value.toMap() );
83}
84
85void QgsKeyValueWidgetWrapper::updateConstraintWidgetStatus()
86{
87 // Nothing
88}
89
90void QgsKeyValueWidgetWrapper::onValueChanged()
91{
93}
Manages an editor widget Widget and wrapper share the same parent.
static bool isInTable(const QWidget *parent)
Check if the given widget or one of its parent is a QTableView.
void emitValueChanged()
Will call the value() method to determine the emitted value.
QVariant value() const override
Will be used to access the widget's value.
QWidget * createWidget(QWidget *parent) override
This method should create a new widget with the provided parent.
void showIndeterminateState() override
Sets the widget to display in an indeterminate "mixed value" state.
QgsKeyValueWidgetWrapper(QgsVectorLayer *layer, int fieldIdx, QWidget *editor=nullptr, QWidget *parent=nullptr)
Constructor for QgsKeyValueWidgetWrapper.
void initWidget(QWidget *editor) override
This method should initialize the editor widget with runtime data.
void setEnabled(bool enabled) override
bool valid() const override
Returns true if the widget has been properly initialized.
Widget allowing to edit a QVariantMap, using a table.
void setReadOnly(bool readOnly) override
void setMap(const QVariantMap &map)
Set the initial value of the widget.
void valueChanged()
Emitted each time a key or a value is changed.
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.