Skip to content
Permalink
Browse files

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.
  • Loading branch information
signedav committed Mar 29, 2018
1 parent 901327c commit 5b7a525ed2a63e27c45924652e3efeaa1b7b0f65
Showing with 19 additions and 11 deletions.
  1. +13 −10 src/app/qgsattributesformproperties.cpp
  2. +6 −1 src/app/qgsattributesformproperties.h
@@ -88,14 +88,14 @@ void QgsAttributesFormProperties::initAvailableWidgetsTree()

//load Fields

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

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

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

//load Relations
catItemData = DnDTreeItemData( DnDTreeItemData::Container, "Relations" );
catItemData = DnDTreeItemData( DnDTreeItemData::Container, "Relations", "Relations" );
catitem = mAvailableWidgetsTree->addItem( mAvailableWidgetsTree->invisibleRootItem(), catItemData );

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

for ( const QgsRelation &relation : relations )
{
DnDTreeItemData itemData = DnDTreeItemData( DnDTreeItemData::Relation, QStringLiteral( "%1" ).arg( relation.id() ) );
DnDTreeItemData itemData = DnDTreeItemData( DnDTreeItemData::Relation, QStringLiteral( "%1" ).arg( relation.id() ), QStringLiteral( "%1" ).arg( relation.name() ) );
itemData.setShowLabel( true );

RelationConfig cfg( mLayer, relation.id() );
@@ -399,7 +399,7 @@ QTreeWidgetItem *QgsAttributesFormProperties::loadAttributeEditorTreeItem( QgsAt
{
case QgsAttributeEditorElement::AeTypeField:
{
DnDTreeItemData itemData = DnDTreeItemData( DnDTreeItemData::Field, widgetDef->name() );
DnDTreeItemData itemData = DnDTreeItemData( DnDTreeItemData::Field, widgetDef->name(), widgetDef->name() );
itemData.setShowLabel( widgetDef->showLabel() );
newWidget = tree->addItem( parent, itemData );
break;
@@ -408,7 +408,7 @@ QTreeWidgetItem *QgsAttributesFormProperties::loadAttributeEditorTreeItem( QgsAt
case QgsAttributeEditorElement::AeTypeRelation:
{
const QgsAttributeEditorRelation *relationEditor = static_cast<const QgsAttributeEditorRelation *>( widgetDef );
DnDTreeItemData itemData = DnDTreeItemData( DnDTreeItemData::Relation, relationEditor->relation().id());
DnDTreeItemData itemData = DnDTreeItemData( DnDTreeItemData::Relation, relationEditor->relation().id(), relationEditor->relation().name());
itemData.setShowLabel( widgetDef->showLabel() );
RelationEditorConfiguration relEdConfig;
relEdConfig.showLinkButton = relationEditor->showLinkButton();
@@ -420,7 +420,7 @@ QTreeWidgetItem *QgsAttributesFormProperties::loadAttributeEditorTreeItem( QgsAt

case QgsAttributeEditorElement::AeTypeContainer:
{
DnDTreeItemData itemData( DnDTreeItemData::Container, widgetDef->name() );
DnDTreeItemData itemData( DnDTreeItemData::Container, widgetDef->name(), widgetDef->name() );
itemData.setShowLabel( widgetDef->showLabel() );

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

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

QDataStream &operator<<( QDataStream &stream, const QgsAttributesFormProperties::DnDTreeItemData &data )
{
stream << ( quint32 )data.type() << data.name();
stream << ( quint32 )data.type() << data.name() << data.displayName();
return stream;
}

QDataStream &operator>>( QDataStream &stream, QgsAttributesFormProperties::DnDTreeItemData &data )
{
QString name;
QString displayName;
quint32 type;

stream >> type >> name;
stream >> type >> name >> displayName;

data.setType( ( QgsAttributesFormProperties::DnDTreeItemData::Type )type );
data.setName( name );
data.setDisplayName( displayName );

return stream;
}
@@ -83,9 +83,10 @@ class APP_EXPORT QgsAttributesFormProperties : public QWidget, private Ui_QgsAtt
//do we need that
DnDTreeItemData() = default;

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

QString displayName() const { return mDisplayName; }
void setDisplayName( const QString &displayName ) { mDisplayName = displayName; }

Type type() const { return mType; }
void setType( Type type ) { mType = type; }

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

0 comments on commit 5b7a525

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