Skip to content
Permalink
Browse files

Merge pull request #320 from matthias-kuhn/fix-attredit

  • Loading branch information
jef-n committed Nov 16, 2012
2 parents 5bc0a8a + 6abedba commit 9183adce9f257a097fc54e5a8a700e4d494b2962
Showing with 65 additions and 3 deletions.
  1. +13 −0 python/core/qgsvectorlayer.sip
  2. +33 −3 src/gui/qgsattributeeditor.cpp
  3. +19 −0 src/gui/qgsattributeeditor.h
@@ -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();
@@ -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 );

@@ -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,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.
You can’t perform that action at this time.