Skip to content

Commit 9183adc

Browse files
committed
Merge pull request #320 from matthias-kuhn/fix-attredit
Fix for http://hub.qgis.org/issues/6647
2 parents 5bc0a8a + 6abedba commit 9183adc

File tree

3 files changed

+65
-3
lines changed

3 files changed

+65
-3
lines changed

python/core/qgsvectorlayer.sip

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,13 @@ class QgsVectorLayer : QgsMapLayer
7373
UuidGenerator, /* uuid generator - readonly and automatically intialized @added in 1.9 */
7474
};
7575

76+
enum EditorLayout
77+
{
78+
GeneratedLayout,
79+
TabLayout,
80+
UiFileLayout,
81+
};
82+
7683
struct RangeData
7784
{
7885
RangeData();
@@ -569,6 +576,12 @@ class QgsVectorLayer : QgsMapLayer
569576
/**set edit type*/
570577
void setEditType( int idx, EditType edit );
571578

579+
/**get editor layout**/
580+
EditorLayout editorLayout();
581+
582+
/**set editor layout*/
583+
void setEditorLayout( EditorLayout layout );
584+
572585
/** set string representing 'true' for a checkbox (added in 1.4) */
573586
void setCheckedState( int idx, QString checked, QString notChecked );
574587

src/gui/qgsattributeeditor.cpp

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,12 +136,13 @@ QWidget *QgsAttributeEditor::createAttributeEditor( QWidget *parent, QWidget *ed
136136
if ( !vl )
137137
return 0;
138138

139-
bool synchronized = false;
140139
QWidget *myWidget = 0;
141140
QgsVectorLayer::EditType editType = vl->editType( idx );
142141
const QgsField &field = vl->pendingFields()[idx];
143142
QVariant::Type myFieldType = field.type();
144143

144+
bool synchronized = false;
145+
145146
switch ( editType )
146147
{
147148
case QgsVectorLayer::UniqueValues:
@@ -438,12 +439,14 @@ QWidget *QgsAttributeEditor::createAttributeEditor( QWidget *parent, QWidget *ed
438439
QLineEdit *le = 0;
439440
QTextEdit *te = 0;
440441
QPlainTextEdit *pte = 0;
442+
QComboBox * cb = 0;
441443

442444
if ( editor )
443445
{
444446
le = qobject_cast<QLineEdit *>( editor );
445447
te = qobject_cast<QTextEdit *>( editor );
446448
pte = qobject_cast<QPlainTextEdit *>( editor );
449+
cb = qobject_cast<QComboBox *>( editor );
447450
}
448451
else if ( editType == QgsVectorLayer::TextEdit )
449452
{
@@ -491,15 +494,42 @@ QWidget *QgsAttributeEditor::createAttributeEditor( QWidget *parent, QWidget *ed
491494
myWidget = pte;
492495
}
493496

497+
if ( cb )
498+
{
499+
myWidget = cb;
500+
}
501+
494502
if ( myWidget )
495503
{
496504
myWidget->setDisabled( editType == QgsVectorLayer::Immutable );
497505

506+
QgsStringRelay* relay = NULL;
507+
498508
QMap<int, QWidget*>::const_iterator it = proxyWidgets.find( idx );
499509
if ( it != proxyWidgets.end() )
500510
{
501-
synchronized = connect( *it, SIGNAL( textChanged( QString ) ), myWidget, SLOT( setText( QString ) ) );
502-
synchronized &= connect( myWidget, SIGNAL( textChanged( QString ) ), *it, SLOT( setText( QString ) ) );
511+
QObject* obj = qvariant_cast<QObject*>( (*it)->property( "QgisAttrEditProxy" ) );
512+
relay = qobject_cast<QgsStringRelay*>( obj );
513+
}
514+
else
515+
{
516+
relay = new QgsStringRelay( myWidget );
517+
}
518+
519+
if ( cb && cb->isEditable() )
520+
{
521+
synchronized = connect( relay, SIGNAL( textChanged( QString ) ), myWidget, SLOT( setEditText( QString ) ) );
522+
synchronized &= connect( myWidget, SIGNAL( editTextChanged( QString ) ), relay, SLOT( changeText( QString ) ) );
523+
}
524+
else
525+
{
526+
synchronized = connect( relay, SIGNAL( textChanged( QString ) ), myWidget, SLOT( setText( QString ) ) );
527+
synchronized &= connect( myWidget, SIGNAL( textChanged( QString ) ), relay, SLOT( changeText( QString ) ) );
528+
}
529+
530+
if ( !cb || cb->isEditable() )
531+
{
532+
myWidget->setProperty( "QgisAttrEditProxy", QVariant( QMetaType::QObjectStar, &relay ) );
503533
}
504534
}
505535
}

src/gui/qgsattributeeditor.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#define QGSATTRIBUTEEDITOR_H
1919

2020
#include <QVariant>
21+
#include <QMetaType>
2122

2223
#include "qgsfeature.h"
2324

@@ -79,5 +80,23 @@ class GUI_EXPORT QgsAttributeEditor : public QObject
7980
void selectDate();
8081
};
8182

83+
class QgsStringRelay : public QObject
84+
{
85+
Q_OBJECT
86+
87+
public:
88+
89+
QgsStringRelay( QObject* parent = NULL )
90+
: QObject( parent ) {}
91+
92+
public slots:
93+
void changeText( QString str )
94+
{
95+
emit textChanged( str );
96+
}
97+
98+
signals:
99+
void textChanged( QString );
100+
};
82101

83102
#endif

0 commit comments

Comments
 (0)