Skip to content
Permalink
Browse files

Attribute Editor: Synchronize editable QComboBox for LineEdit's and s…

  • Loading branch information
m-kuhn committed Nov 8, 2012
1 parent fce38c5 commit 7db860150300930593e598ecf63621d6d632a71c
Showing with 59 additions and 3 deletions.
  1. +33 −3 src/gui/qgsattributeeditor.cpp
  2. +26 −0 src/gui/qgsattributeeditor.h
@@ -136,12 +136,13 @@ QWidget *QgsAttributeEditor::createAttributeEditor( QWidget *parent, QWidget *ed
if ( !vl )
return 0;

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

bool synchronized = false;

switch ( editType )
{
case QgsVectorLayer::UniqueValues:
@@ -438,12 +439,14 @@ QWidget *QgsAttributeEditor::createAttributeEditor( QWidget *parent, QWidget *ed
QLineEdit *le = 0;
QTextEdit *te = 0;
QPlainTextEdit *pte = 0;
QComboBox * cb = 0;

if ( editor )
{
le = qobject_cast<QLineEdit *>( editor );
te = qobject_cast<QTextEdit *>( editor );
pte = qobject_cast<QPlainTextEdit *>( editor );
cb = qobject_cast<QComboBox *>( editor );
}
else if ( editType == QgsVectorLayer::TextEdit )
{
@@ -491,15 +494,42 @@ QWidget *QgsAttributeEditor::createAttributeEditor( QWidget *parent, QWidget *ed
myWidget = pte;
}

if ( cb )
{
myWidget = cb;
}

if ( myWidget )
{
myWidget->setDisabled( editType == QgsVectorLayer::Immutable );

QgsStringRelay* relay = NULL;

QMap<int, QWidget*>::const_iterator it = proxyWidgets.find( idx );
if ( it != proxyWidgets.end() )
{
synchronized = connect( *it, SIGNAL( textChanged( QString ) ), myWidget, SLOT( setText( QString ) ) );
synchronized &= connect( myWidget, SIGNAL( textChanged( QString ) ), *it, SLOT( setText( QString ) ) );
QObject* obj = qvariant_cast<QObject*>( (*it)->property( "QgisAttrEditProxy" ) );
relay = qobject_cast<QgsStringRelay*>( obj );
}
else
{
relay = new QgsStringRelay( myWidget );
}

if ( cb && cb->isEditable() )
{
synchronized = connect( relay, SIGNAL( textChanged( QString ) ), myWidget, SLOT( setEditText( QString ) ) );
synchronized &= connect( myWidget, SIGNAL( editTextChanged( QString ) ), relay, SLOT( changeText( QString ) ) );
}
else
{
synchronized = connect( relay, SIGNAL( textChanged( QString ) ), myWidget, SLOT( setText( QString ) ) );
synchronized &= connect( myWidget, SIGNAL( textChanged( QString ) ), relay, SLOT( changeText( QString ) ) );
}

if ( !cb || cb->isEditable() )
{
myWidget->setProperty( "QgisAttrEditProxy", QVariant( QMetaType::QObjectStar, &relay ) );
}
}
}
@@ -18,6 +18,7 @@
#define QGSATTRIBUTEEDITOR_H

#include <QVariant>
#include <QMetaType>

#include "qgsfeature.h"

@@ -79,5 +80,30 @@ class GUI_EXPORT QgsAttributeEditor : public QObject
void selectDate();
};

class QgsStringRelay : public QObject
{
Q_OBJECT

public:
QgsStringRelay()
: QObject( NULL ) {}

QgsStringRelay( QObject* parent )
: QObject( parent ) {}

QgsStringRelay( const QgsStringRelay& sr )
: QObject( sr.parent() ) {}

public slots:
void changeText( QString str )
{
emit textChanged( str );
}

signals:
void textChanged( QString );
};

Q_DECLARE_METATYPE( QgsStringRelay )

#endif

0 comments on commit 7db8601

Please sign in to comment.
You can’t perform that action at this time.