Skip to content

Commit 5b7a525

Browse files
committed
displayName in DnDTreeItem
a displayName defined on creation. Usually on fields the fieldname and on relations the relationname. no other logical use for that. The DnDTreeItem.name is used as id and should be unique, not like displayName.
1 parent 901327c commit 5b7a525

File tree

2 files changed

+19
-11
lines changed

2 files changed

+19
-11
lines changed

src/app/qgsattributesformproperties.cpp

+13-10
Original file line numberDiff line numberDiff line change
@@ -88,14 +88,14 @@ void QgsAttributesFormProperties::initAvailableWidgetsTree()
8888

8989
//load Fields
9090

91-
DnDTreeItemData catItemData = DnDTreeItemData( DnDTreeItemData::Container, "Fields" );
91+
DnDTreeItemData catItemData = DnDTreeItemData( DnDTreeItemData::Container, "Fields", "Fields" );
9292
QTreeWidgetItem *catitem = mAvailableWidgetsTree->addItem( mAvailableWidgetsTree->invisibleRootItem(), catItemData );
9393

9494
const QgsFields fields = mLayer->fields();
9595
for ( int i = 0; i < fields.size(); ++i )
9696
{
9797
const QgsField field = fields.at( i );
98-
DnDTreeItemData itemData = DnDTreeItemData( DnDTreeItemData::Field, field.name() );
98+
DnDTreeItemData itemData = DnDTreeItemData( DnDTreeItemData::Field, field.name(), field.name() );
9999
itemData.setShowLabel( true );
100100

101101
FieldConfig cfg( mLayer, i );
@@ -108,14 +108,14 @@ void QgsAttributesFormProperties::initAvailableWidgetsTree()
108108
catitem->setExpanded( true );
109109

110110
//load Relations
111-
catItemData = DnDTreeItemData( DnDTreeItemData::Container, "Relations" );
111+
catItemData = DnDTreeItemData( DnDTreeItemData::Container, "Relations", "Relations" );
112112
catitem = mAvailableWidgetsTree->addItem( mAvailableWidgetsTree->invisibleRootItem(), catItemData );
113113

114114
const QList<QgsRelation> relations = QgsProject::instance()->relationManager()->referencedRelations( mLayer );
115115

116116
for ( const QgsRelation &relation : relations )
117117
{
118-
DnDTreeItemData itemData = DnDTreeItemData( DnDTreeItemData::Relation, QStringLiteral( "%1" ).arg( relation.id() ) );
118+
DnDTreeItemData itemData = DnDTreeItemData( DnDTreeItemData::Relation, QStringLiteral( "%1" ).arg( relation.id() ), QStringLiteral( "%1" ).arg( relation.name() ) );
119119
itemData.setShowLabel( true );
120120

121121
RelationConfig cfg( mLayer, relation.id() );
@@ -399,7 +399,7 @@ QTreeWidgetItem *QgsAttributesFormProperties::loadAttributeEditorTreeItem( QgsAt
399399
{
400400
case QgsAttributeEditorElement::AeTypeField:
401401
{
402-
DnDTreeItemData itemData = DnDTreeItemData( DnDTreeItemData::Field, widgetDef->name() );
402+
DnDTreeItemData itemData = DnDTreeItemData( DnDTreeItemData::Field, widgetDef->name(), widgetDef->name() );
403403
itemData.setShowLabel( widgetDef->showLabel() );
404404
newWidget = tree->addItem( parent, itemData );
405405
break;
@@ -408,7 +408,7 @@ QTreeWidgetItem *QgsAttributesFormProperties::loadAttributeEditorTreeItem( QgsAt
408408
case QgsAttributeEditorElement::AeTypeRelation:
409409
{
410410
const QgsAttributeEditorRelation *relationEditor = static_cast<const QgsAttributeEditorRelation *>( widgetDef );
411-
DnDTreeItemData itemData = DnDTreeItemData( DnDTreeItemData::Relation, relationEditor->relation().id());
411+
DnDTreeItemData itemData = DnDTreeItemData( DnDTreeItemData::Relation, relationEditor->relation().id(), relationEditor->relation().name());
412412
itemData.setShowLabel( widgetDef->showLabel() );
413413
RelationEditorConfiguration relEdConfig;
414414
relEdConfig.showLinkButton = relationEditor->showLinkButton();
@@ -420,7 +420,7 @@ QTreeWidgetItem *QgsAttributesFormProperties::loadAttributeEditorTreeItem( QgsAt
420420

421421
case QgsAttributeEditorElement::AeTypeContainer:
422422
{
423-
DnDTreeItemData itemData( DnDTreeItemData::Container, widgetDef->name() );
423+
DnDTreeItemData itemData( DnDTreeItemData::Container, widgetDef->name(), widgetDef->name() );
424424
itemData.setShowLabel( widgetDef->showLabel() );
425425

426426
const QgsAttributeEditorContainer *container = static_cast<const QgsAttributeEditorContainer *>( widgetDef );
@@ -771,7 +771,7 @@ QTreeWidgetItem *DnDTree::addContainer( QTreeWidgetItem *parent, const QString &
771771
QTreeWidgetItem *newItem = new QTreeWidgetItem( QStringList() << title );
772772
newItem->setBackground( 0, QBrush( Qt::lightGray ) );
773773
newItem->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled );
774-
QgsAttributesFormProperties::DnDTreeItemData itemData( QgsAttributesFormProperties::DnDTreeItemData::Container, title );
774+
QgsAttributesFormProperties::DnDTreeItemData itemData( QgsAttributesFormProperties::DnDTreeItemData::Container, title, title );
775775
itemData.setColumnCount( columnCount );
776776
newItem->setData( 0, QgsAttributesFormProperties::DnDTreeRole, itemData );
777777
parent->addChild( newItem );
@@ -811,6 +811,7 @@ QTreeWidgetItem *DnDTree::addItem( QTreeWidgetItem *parent, QgsAttributesFormPro
811811
}
812812
}
813813
newItem->setData( 0, QgsAttributesFormProperties::DnDTreeRole, data );
814+
newItem->setText( 0, data.displayName() );
814815

815816
if ( index < 0 )
816817
parent->addChild( newItem );
@@ -1082,19 +1083,21 @@ void DnDTree::setType( const Type &value )
10821083

10831084
QDataStream &operator<<( QDataStream &stream, const QgsAttributesFormProperties::DnDTreeItemData &data )
10841085
{
1085-
stream << ( quint32 )data.type() << data.name();
1086+
stream << ( quint32 )data.type() << data.name() << data.displayName();
10861087
return stream;
10871088
}
10881089

10891090
QDataStream &operator>>( QDataStream &stream, QgsAttributesFormProperties::DnDTreeItemData &data )
10901091
{
10911092
QString name;
1093+
QString displayName;
10921094
quint32 type;
10931095

1094-
stream >> type >> name;
1096+
stream >> type >> name >> displayName;
10951097

10961098
data.setType( ( QgsAttributesFormProperties::DnDTreeItemData::Type )type );
10971099
data.setName( name );
1100+
data.setDisplayName( displayName );
10981101

10991102
return stream;
11001103
}

src/app/qgsattributesformproperties.h

+6-1
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,10 @@ class APP_EXPORT QgsAttributesFormProperties : public QWidget, private Ui_QgsAtt
8383
//do we need that
8484
DnDTreeItemData() = default;
8585

86-
DnDTreeItemData( Type type, const QString &name )
86+
DnDTreeItemData( Type type, const QString &name, const QString &displayName )
8787
: mType( type )
8888
, mName( name )
89+
, mDisplayName( displayName )
8990
, mColumnCount( 1 )
9091
, mShowAsGroupBox( false )
9192
, mShowLabel( true )
@@ -94,6 +95,9 @@ class APP_EXPORT QgsAttributesFormProperties : public QWidget, private Ui_QgsAtt
9495
QString name() const { return mName; }
9596
void setName( const QString &name ) { mName = name; }
9697

98+
QString displayName() const { return mDisplayName; }
99+
void setDisplayName( const QString &displayName ) { mDisplayName = displayName; }
100+
97101
Type type() const { return mType; }
98102
void setType( Type type ) { mType = type; }
99103

@@ -117,6 +121,7 @@ class APP_EXPORT QgsAttributesFormProperties : public QWidget, private Ui_QgsAtt
117121
private:
118122
Type mType = Field;
119123
QString mName;
124+
QString mDisplayName;
120125
int mColumnCount = 1;
121126
bool mShowAsGroupBox = false;
122127
bool mShowLabel = true;

0 commit comments

Comments
 (0)