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