QGIS API Documentation  2.10.1-Pisa
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 dot kuhn at gmx 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( NULL )
23  , mLineEdit( NULL )
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  if ( value.isNull() )
55  {
56  if ( mLineEdit )
57  mLineEdit->setText( QUuid::createUuid().toString() );
58  if ( mLabel )
59  mLabel->setText( QUuid::createUuid().toString() );
60 
61  valueChanged();
62  }
63  else
64  {
65  if ( mLineEdit )
66  mLineEdit->setText( value.toString() );
67  if ( mLabel )
68  mLabel->setText( value.toString() );
69  }
70 }
71 
73 {
74  Q_UNUSED( enabled )
75  // Do nothing... it is always disabled
76 }
void valueChanged()
Will call the value() method to determine the emitted value.
Manages an editor widget Widget and wrapper share the same parent.
QgsUuidWidgetWrapper(QgsVectorLayer *vl, int fieldIdx, QWidget *editor=0, QWidget *parent=0)
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
QVariant value() override
Will be used to access the widget's value.
void initWidget(QWidget *editor) override
This method should initialize the editor widget with runtime data.
Represents a vector layer which manages a vector based data sets.
QString toString() const
QUuid createUuid()