Skip to content

Commit 1afd153

Browse files
committed
Merge pull request #377 from matthias-kuhn/attredit-load-idx
Fix issue 6899: Drag and drop designer uses first field after project re...
2 parents 4ff5b29 + c4115cf commit 1afd153

File tree

4 files changed

+17
-5
lines changed

4 files changed

+17
-5
lines changed

src/app/qgsfieldsproperties.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -752,7 +752,7 @@ QgsAttributeEditorElement* QgsFieldsProperties::createAttributeEditorWidget( QTr
752752

753753
if ( item->data( 0, Qt::UserRole ) == "field" )
754754
{
755-
int idx = *mLayer->dataProvider()->fieldNameMap().find( item->text( 0 ) );
755+
int idx = *( mLayer->dataProvider()->fieldNameMap() ).find( item->text( 0 ) );
756756
widgetDef = new QgsAttributeEditorField( item->text( 0 ), idx, parent );
757757
}
758758
else

src/core/qgsvectorlayer.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -3387,7 +3387,9 @@ QgsAttributeEditorElement* QgsVectorLayer::attributeEditorElementFromDomElement(
33873387
}
33883388
else if ( elem.tagName() == "attributeEditorField" )
33893389
{
3390-
newElement = new QgsAttributeEditorField( elem.attribute( "name" ), elem.attribute( "idx" ).toInt(), parent );
3390+
QString name = elem.attribute( "name" );
3391+
int idx = *( dataProvider()->fieldNameMap() ).find( name );
3392+
newElement = new QgsAttributeEditorField( name, idx, parent );
33913393
}
33923394

33933395
return newElement;

src/core/qgsvectorlayer.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
389389
* @param elem the DOM element
390390
* @param parent the QObject which will own this object
391391
*/
392-
static QgsAttributeEditorElement* attributeEditorElementFromDomElement( QDomElement &elem, QObject* parent );
392+
QgsAttributeEditorElement* attributeEditorElementFromDomElement( QDomElement &elem, QObject* parent );
393393

394394
/** Read the symbology for the current layer from the Dom node supplied.
395395
* @param node node that will contain the symbology definition for this layer.

src/gui/qgsattributeeditor.cpp

+12-2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include <qgsmaplayerregistry.h>
2727
#include <qgslogger.h>
2828

29+
#include <QScrollArea>
2930
#include <QPushButton>
3031
#include <QLineEdit>
3132
#include <QTextEdit>
@@ -987,13 +988,23 @@ QWidget* QgsAttributeEditor::createWidgetFromDef( const QgsAttributeEditorElemen
987988
QGroupBox* groupBox = new QGroupBox( parent );
988989
groupBox->setTitle( container->name() );
989990
myContainer = groupBox;
991+
newWidget = myContainer;
990992
}
991993
else
992994
{
993-
myContainer = new QWidget( parent );
995+
QScrollArea *scrollArea = new QScrollArea( parent );
996+
997+
myContainer = new QWidget( scrollArea );
998+
999+
scrollArea->setWidget( myContainer );
1000+
scrollArea->setWidgetResizable( true );
1001+
scrollArea->setFrameShape( QFrame::NoFrame );
1002+
1003+
newWidget = scrollArea;
9941004
}
9951005

9961006
QGridLayout* gbLayout = new QGridLayout( myContainer );
1007+
myContainer->setLayout( gbLayout );
9971008

9981009
int index = 0;
9991010

@@ -1026,7 +1037,6 @@ QWidget* QgsAttributeEditor::createWidgetFromDef( const QgsAttributeEditorElemen
10261037
}
10271038
gbLayout->addItem( new QSpacerItem( 0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding ), index , 0 );
10281039

1029-
newWidget = myContainer;
10301040
break;
10311041
}
10321042

0 commit comments

Comments
 (0)