QGIS API Documentation  2.13.0-Master
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 
21  : QgsEditorWidgetWrapper( vl, fieldIdx, editor, parent )
22  , mLabel( nullptr )
23  , mLineEdit( nullptr )
24 {
25 }
26 
28 {
29  QVariant v;
30 
31  if ( mLineEdit )
32  v = mLineEdit->text();
33  if ( mLabel )
34  v = mLabel->text();
35 
36  return v;
37 }
38 
40 {
41  return new QLineEdit( parent );
42 }
43 
45 {
46  mLineEdit = qobject_cast<QLineEdit*>( editor );
47  mLabel = qobject_cast<QLabel*>( editor );
48  if ( mLineEdit )
49  mLineEdit->setEnabled( false );
50 }
51 
53 {
54  return mLineEdit || mLabel;
55 }
56 
58 {
59  if ( value.isNull() )
60  {
61  if ( mLineEdit )
62  mLineEdit->setText( QUuid::createUuid().toString() );
63  if ( mLabel )
64  mLabel->setText( QUuid::createUuid().toString() );
65 
66  valueChanged();
67  }
68  else
69  {
70  if ( mLineEdit )
71  mLineEdit->setText( value.toString() );
72  if ( mLabel )
73  mLabel->setText( value.toString() );
74  }
75 }
76 
78 {
79  Q_UNUSED( enabled )
80  // Do nothing... it is always disabled
81 }
void valueChanged()
Will call the value() method to determine the emitted value.
QVariant value() const override
Will be used to access the widget's value.
Manages an editor widget Widget and wrapper share the same parent.
void setEnabled(bool)
bool isNull() const
QWidget * createWidget(QWidget *parent) override
This method should create a new widget with the provided parent.
void setValue(const QVariant &value) override
void setEnabled(bool enabled) override
void initWidget(QWidget *editor) override
This method should initialize the editor widget with runtime data.
bool valid() const override
Return true if the widget has been properly initialized.
Represents a vector layer which manages a vector based data sets.
QString toString() const
QgsUuidWidgetWrapper(QgsVectorLayer *vl, int fieldIdx, QWidget *editor=nullptr, QWidget *parent=nullptr)
QUuid createUuid()