Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #320 from matthias-kuhn/fix-attredit
  • Loading branch information
jef-n committed Nov 16, 2012
2 parents 5bc0a8a + 6abedba commit 9183adc
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 3 deletions.
13 changes: 13 additions & 0 deletions python/core/qgsvectorlayer.sip
Expand Up @@ -73,6 +73,13 @@ class QgsVectorLayer : QgsMapLayer
UuidGenerator, /* uuid generator - readonly and automatically intialized @added in 1.9 */
};

enum EditorLayout
{
GeneratedLayout,
TabLayout,
UiFileLayout,
};

struct RangeData
{
RangeData();
Expand Down Expand Up @@ -569,6 +576,12 @@ class QgsVectorLayer : QgsMapLayer
/**set edit type*/
void setEditType( int idx, EditType edit );

/**get editor layout**/
EditorLayout editorLayout();

/**set editor layout*/
void setEditorLayout( EditorLayout layout );

/** set string representing 'true' for a checkbox (added in 1.4) */
void setCheckedState( int idx, QString checked, QString notChecked );

Expand Down
36 changes: 33 additions & 3 deletions src/gui/qgsattributeeditor.cpp
Expand Up @@ -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:
Expand Down Expand Up @@ -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 )
{
Expand Down Expand Up @@ -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 ) );
}
}
}
Expand Down
19 changes: 19 additions & 0 deletions src/gui/qgsattributeeditor.h
Expand Up @@ -18,6 +18,7 @@
#define QGSATTRIBUTEEDITOR_H

#include <QVariant>
#include <QMetaType>

#include "qgsfeature.h"

Expand Down Expand Up @@ -79,5 +80,23 @@ class GUI_EXPORT QgsAttributeEditor : public QObject
void selectDate();
};

class QgsStringRelay : public QObject
{
Q_OBJECT

public:

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

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

signals:
void textChanged( QString );
};

#endif

0 comments on commit 9183adc

Please sign in to comment.