Skip to content

Commit 7db8601

Browse files
committed
Attribute Editor: Synchronize editable QComboBox for LineEdit's and similar.
Fixes http://hub.qgis.org/issues/6647
1 parent fce38c5 commit 7db8601

File tree

2 files changed

+59
-3
lines changed

2 files changed

+59
-3
lines changed

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: 26 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,30 @@ class GUI_EXPORT QgsAttributeEditor : public QObject
7980
void selectDate();
8081
};
8182

83+
class QgsStringRelay : public QObject
84+
{
85+
Q_OBJECT
86+
87+
public:
88+
QgsStringRelay()
89+
: QObject( NULL ) {}
90+
91+
QgsStringRelay( QObject* parent )
92+
: QObject( parent ) {}
93+
94+
QgsStringRelay( const QgsStringRelay& sr )
95+
: QObject( sr.parent() ) {}
96+
97+
public slots:
98+
void changeText( QString str )
99+
{
100+
emit textChanged( str );
101+
}
102+
103+
signals:
104+
void textChanged( QString );
105+
};
106+
107+
Q_DECLARE_METATYPE( QgsStringRelay )
82108

83109
#endif

0 commit comments

Comments
 (0)