QGIS API Documentation  3.10.0-A Coruña (6c816b4204)
qgsuuidwidgetwrapper.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsuuidwidgetwrapper.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 
16 #include "qgsuuidwidgetwrapper.h"
17 
18 #include <QUuid>
19 
20 QgsUuidWidgetWrapper::QgsUuidWidgetWrapper( QgsVectorLayer *layer, int fieldIdx, QWidget *editor, QWidget *parent )
21  : QgsEditorWidgetWrapper( layer, fieldIdx, editor, parent )
22 
23 {
24 }
25 
27 {
28  QVariant v;
29 
30  if ( mLineEdit )
31  v = mLineEdit->text();
32  if ( mLabel )
33  v = mLabel->text();
34 
35  return v;
36 }
37 
38 QWidget *QgsUuidWidgetWrapper::createWidget( QWidget *parent )
39 {
40  return new QLineEdit( parent );
41 }
42 
43 void QgsUuidWidgetWrapper::initWidget( QWidget *editor )
44 {
45  mLineEdit = qobject_cast<QLineEdit *>( editor );
46  mLabel = qobject_cast<QLabel *>( editor );
47  if ( mLineEdit )
48  mLineEdit->setEnabled( false );
49 }
50 
52 {
53  return mLineEdit || mLabel;
54 }
55 
56 void QgsUuidWidgetWrapper::updateValues( const QVariant &value, const QVariantList & )
57 {
58  if ( value.isNull() )
59  {
60  if ( mLineEdit )
61  mLineEdit->setText( QUuid::createUuid().toString() );
62  if ( mLabel )
63  mLabel->setText( QUuid::createUuid().toString() );
64 
66  }
67  else
68  {
69  if ( mLineEdit )
70  mLineEdit->setText( value.toString() );
71  if ( mLabel )
72  mLabel->setText( value.toString() );
73  }
74 }
75 
77 {
78  Q_UNUSED( enabled )
79  // Do nothing... it is always disabled
80 }
void emitValueChanged()
Will call the value() method to determine the emitted value.
QVariant value() const override
Will be used to access the widget&#39;s value.
Manages an editor widget Widget and wrapper share the same parent.
QgsUuidWidgetWrapper(QgsVectorLayer *layer, int fieldIdx, QWidget *editor=nullptr, QWidget *parent=nullptr)
Constructor for QgsUuidWidgetWrapper.
QWidget * createWidget(QWidget *parent) override
This method should create a new widget with the provided parent.
void setEnabled(bool enabled) override
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.
Represents a vector layer which manages a vector based data sets.