QGIS API Documentation  2.4.0-Chugiak
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
qgsattributeeditor.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsattributeeditor.cpp - description
3  -------------------
4  begin : July 2009
5  copyright : (C) 2009 by J├╝rgen E. Fischer
6  email : jef@norbit.de
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 
19 #include "qgseditorwidgetfactory.h"
20 #include "qgseditorwidgetregistry.h"
21 #include "qgseditorwidgetwrapper.h"
22 
23 #include "qgsattributedialog.h"
24 #include "qgsattributeeditor.h"
27 #include "qgscolorbutton.h"
28 #include "qgsexpression.h"
29 #include "qgsfieldvalidator.h"
30 #include "qgsfilterlineedit.h"
31 #include "qgslogger.h"
32 #include "qgslonglongvalidator.h"
33 #include "qgsmaplayerregistry.h"
35 #include "qgsrelationeditor.h"
36 #include "qgsrelationmanager.h"
37 #include "qgsvectordataprovider.h"
38 #include "qgsvectorlayer.h"
39 
40 #include <QScrollArea>
41 #include <QPushButton>
42 #include <QLineEdit>
43 #include <QTextEdit>
44 #include <QFileDialog>
45 #include <QComboBox>
46 #include <QListWidget>
47 #include <QCheckBox>
48 #include <QSpinBox>
49 #include <QCompleter>
50 #include <QHBoxLayout>
51 #include <QPlainTextEdit>
52 #include <QDial>
53 #include <QCalendarWidget>
54 #include <QDialogButtonBox>
55 #include <QSettings>
56 #include <QDir>
57 #include <QUuid>
58 #include <QGroupBox>
59 #include <QLabel>
60 #include <QWebView>
61 #include <QDesktopServices>
62 
63 QWidget *QgsAttributeEditor::createAttributeEditor( QWidget *parent, QWidget *editor, QgsVectorLayer *vl, int idx, const QVariant &value )
64 {
66 
67  return createAttributeEditor( parent, editor, vl, idx, value, context );
68 }
69 
70 QWidget *QgsAttributeEditor::createAttributeEditor( QWidget *parent, QWidget *editor, QgsVectorLayer *vl, int idx, const QVariant &value, QMap<int, QWidget*> &proxyWidgets )
71 {
72  Q_UNUSED( proxyWidgets )
73 
75 
76  return createAttributeEditor( parent, editor, vl, idx, value, context );
77 }
78 
79 QWidget* QgsAttributeEditor::createAttributeEditor( QWidget* parent, QWidget* editor, QgsVectorLayer* vl, int idx, const QVariant& value, QgsAttributeEditorContext& context )
80 {
81  QString widgetType = vl->editorWidgetV2( idx );
83 
84  QgsEditorWidgetWrapper* eww = QgsEditorWidgetRegistry::instance()->create( widgetType, vl, idx, cfg, editor, parent, context );
85 
86  if ( eww )
87  {
88  eww->setValue( value );
89  return eww->widget();
90  }
91  else
92  {
93  return 0;
94  }
95 }
96 
97 bool QgsAttributeEditor::retrieveValue( QWidget *editor, QgsVectorLayer *vl, int idx, QVariant &value )
98 {
99  Q_UNUSED( vl )
100  Q_UNUSED( idx )
101 
102  if ( !editor )
103  return false;
104 
105  QgsEditorWidgetWrapper* wrapper = QgsEditorWidgetWrapper::fromWidget( editor );
106 
107  if ( wrapper )
108  {
109  value = wrapper->value();
110  return true;
111  }
112  return false;
113 }
114 
115 bool QgsAttributeEditor::setValue( QWidget *editor, QgsVectorLayer *vl, int idx, const QVariant &value )
116 {
117  Q_UNUSED( vl )
118  Q_UNUSED( idx )
119 
120  if ( !editor )
121  return false;
122 
123  QgsEditorWidgetWrapper* wrapper = QgsEditorWidgetWrapper::fromWidget( editor );
124 
125  if ( wrapper )
126  {
127  wrapper->setValue( value );
128  return true;
129  }
130  return false;
131 }
const QgsEditorWidgetConfig editorWidgetV2Config(int fieldIdx) const
Get the configuration for the editor widget used to represent the field at the given index...
static bool retrieveValue(QWidget *widget, QgsVectorLayer *vl, int idx, QVariant &value)
This class contains context information for attribute editor widgets.
const QString editorWidgetV2(int fieldIdx) const
Get the id for the editor widget used to represent the field at the given index.
static bool setValue(QWidget *widget, QgsVectorLayer *vl, int idx, const QVariant &value)
static Q_DECL_DEPRECATED QWidget * createAttributeEditor(QWidget *parent, QWidget *editor, QgsVectorLayer *vl, int idx, const QVariant &value, QMap< int, QWidget * > &proxyWidgets)
Creates or prepares a attribute editor widget.
QMap< QString, QVariant > QgsEditorWidgetConfig
Holds a set of configuration parameters for a editor widget wrapper.
Represents a vector layer which manages a vector based data sets.