QGIS API Documentation  2.5.0-Master
 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 
20 QgsUuidWidgetWrapper::QgsUuidWidgetWrapper( QgsVectorLayer* vl, int fieldIdx, QWidget* editor, QWidget* parent )
21  : QgsEditorWidgetWrapper( vl, fieldIdx, editor, parent )
22 {
23 }
24 
26 {
27  QVariant v;
28 
29  if ( mLineEdit )
30  v = mLineEdit->text();
31  if ( mLabel )
32  v = mLabel->text();
33 
34  return v;
35 }
36 
37 QWidget* QgsUuidWidgetWrapper::createWidget( QWidget* parent )
38 {
39  return new QLineEdit( parent );
40 }
41 
42 void QgsUuidWidgetWrapper::initWidget( QWidget* editor )
43 {
44  mLineEdit = qobject_cast<QLineEdit*>( editor );
45  mLabel = qobject_cast<QLabel*>( editor );
46  if ( mLineEdit )
47  mLineEdit->setEnabled( false );
48 }
49 
50 void QgsUuidWidgetWrapper::setValue( const QVariant& value )
51 {
52  if ( value.isNull() )
53  {
54  if ( mLineEdit )
55  mLineEdit->setText( QUuid::createUuid().toString() );
56  if ( mLabel )
57  mLabel->setText( QUuid::createUuid().toString() );
58 
59  valueChanged();
60  }
61  else
62  {
63  if ( mLineEdit )
64  mLineEdit->setText( value.toString() );
65  if ( mLabel )
66  mLabel->setText( value.toString() );
67  }
68 }
69 
71 {
72  Q_UNUSED( enabled )
73  // Do nothing... it is always disabled
74 }
QWidget * createWidget(QWidget *parent)
This method should create a new widget with the provided parent.
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 initWidget(QWidget *editor)
This method should initialize the editor widget with runtime data.
QVariant value()
Will be used to access the widget's value.
void setValue(const QVariant &value)
void setEnabled(bool enabled)
Represents a vector layer which manages a vector based data sets.