QGIS API Documentation 3.41.0-Master (d5b93354e9c)
Loading...
Searching...
No Matches
qgsvaluemapwidgetwrapper.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsvaluemapwidgetwrapper.cpp
3 --------------------------------------
4 Date : 5.1.2014
5 Copyright : (C) 2014 Matthias Kuhn
6 Email : matthias at opengis dot ch
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_qgsvaluemapwidgetwrapper.cpp"
20#include "qgsapplication.h"
21
22#include <QSettings>
23
24QgsValueMapWidgetWrapper::QgsValueMapWidgetWrapper( QgsVectorLayer *layer, int fieldIdx, QWidget *editor, QWidget *parent )
25 : QgsEditorWidgetWrapper( layer, fieldIdx, editor, parent )
26
27{
28}
29
30
32{
33 QVariant v;
34
35 if ( mComboBox )
36 {
37 v = mComboBox->currentData();
38 }
39
42
43 return v;
44}
45
47{
48 if ( mComboBox )
49 {
50 whileBlocking( mComboBox )->setCurrentIndex( -1 );
51 }
52}
53
54QWidget *QgsValueMapWidgetWrapper::createWidget( QWidget *parent )
55{
56 QComboBox *combo = new QComboBox( parent );
57 combo->setMinimumContentsLength( 1 );
58 combo->setSizeAdjustPolicy( QComboBox::SizeAdjustPolicy::AdjustToMinimumContentsLengthWithIcon );
59 return combo;
60}
61
63{
64 mComboBox = qobject_cast<QComboBox *>( editor );
65
66 if ( mComboBox )
67 {
69 mComboBox->view()->setVerticalScrollBarPolicy( Qt::ScrollBarAsNeeded );
70 connect( mComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, static_cast<void ( QgsEditorWidgetWrapper::* )()>( &QgsEditorWidgetWrapper::emitValueChanged ) );
71 }
72}
73
75{
76 return mComboBox;
77}
78
79void QgsValueMapWidgetWrapper::updateValues( const QVariant &value, const QVariantList & )
80{
81 QString v;
84 else
85 v = value.toString();
86
87 if ( mComboBox )
88 {
89 if ( mComboBox->findData( v ) == -1 )
90 {
92 {
93 mComboBox->addItem( QgsApplication::nullRepresentation().prepend( '(' ).append( ')' ), v );
94 }
95 else
96 {
97 mComboBox->addItem( QString( v ).prepend( '(' ).append( ')' ), v );
98 }
99 }
100 mComboBox->setCurrentIndex( mComboBox->findData( v ) );
101 }
102}
static QString nullRepresentation()
Returns the string used to represent the value NULL throughout QGIS.
Manages an editor widget Widget and wrapper share the same parent.
void emitValueChanged()
Will call the value() method to determine the emitted value.
QgsField field() const
Access the field.
static void populateComboBox(QComboBox *comboBox, const QVariantMap &configuration, bool skipNull)
Populates a comboBox with the appropriate entries based on a value map configuration.
static const QString NULL_VALUE
Will be saved in the configuration when a value is NULL.
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.
void showIndeterminateState() override
Sets the widget to display in an indeterminate "mixed value" state.
QgsValueMapWidgetWrapper(QgsVectorLayer *layer, int fieldIdx, QWidget *editor=nullptr, QWidget *parent=nullptr)
Constructor for QgsValueMapWidgetWrapper.
QWidget * createWidget(QWidget *parent) override
This method should create a new widget with the provided parent.
QVariant value() const override
Will be used to access the widget's value.
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.
QVariantMap config() const
Returns the whole config.
QgsSignalBlocker< Object > whileBlocking(Object *object)
Temporarily blocks signals from a QObject while calling a single method from the object.
Definition qgis.h:5928