Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Expose field alias option when creating new fields in vector
layers where the data provider supports alias storage
  • Loading branch information
nyalldawson committed Apr 14, 2023
1 parent ed4052b commit 5b92283
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 15 deletions.
28 changes: 19 additions & 9 deletions src/gui/qgsaddattrdialog.cpp
Expand Up @@ -69,6 +69,11 @@ QgsAddAttrDialog::QgsAddAttrDialog( QgsVectorLayer *vlayer, QWidget *parent, Qt:

mNameEdit->setFocus();

if ( !( attributeEditCapabilities & Qgis::VectorDataProviderAttributeEditCapability::EditAlias ) )
{
mLabelAlias->hide();
mAliasEdit->hide();
}
if ( !( attributeEditCapabilities & Qgis::VectorDataProviderAttributeEditCapability::EditComment ) )
{
mLabelComment->hide();
Expand Down Expand Up @@ -164,13 +169,18 @@ QgsField QgsAddAttrDialog::field() const
.arg( mPrec->value() )
.arg( mCommentEdit->text() ), 2 );

return QgsField(
mNameEdit->text(),
( QVariant::Type ) mTypeBox->currentData( Qt::UserRole ).toInt(),
mTypeBox->currentData( Qt::UserRole + 1 ).toString(),
mLength->value(),
mPrec->isEnabled() ? mPrec->value() : 0,
mCommentEdit->text(),
static_cast<QVariant::Type>( mTypeBox->currentData( Qt::UserRole ).toInt() ) == QVariant::Map ? QVariant::String : QVariant::Invalid
);
QgsField res = QgsField(
mNameEdit->text(),
( QVariant::Type ) mTypeBox->currentData( Qt::UserRole ).toInt(),
mTypeBox->currentData( Qt::UserRole + 1 ).toString(),
mLength->value(),
mPrec->isEnabled() ? mPrec->value() : 0,
mCommentEdit->text(),
static_cast<QVariant::Type>( mTypeBox->currentData( Qt::UserRole ).toInt() ) == QVariant::Map ? QVariant::String : QVariant::Invalid
);

if ( !mAliasEdit->text().isEmpty() )
res.setAlias( mAliasEdit->text() );

return res;
}
27 changes: 21 additions & 6 deletions src/ui/qgsaddattrdialogbase.ui
Expand Up @@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>279</width>
<height>236</height>
<height>268</height>
</rect>
</property>
<property name="windowTitle">
Expand Down Expand Up @@ -73,13 +73,16 @@
</property>
</widget>
</item>
<item row="8" column="1">
<item row="9" column="1">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
<item row="7" column="1">
<widget class="QLineEdit" name="mCommentEdit"/>
</item>
<item row="3" column="1">
<widget class="QLabel" name="mTypeName">
<property name="text">
Expand All @@ -97,6 +100,16 @@
</property>
</widget>
</item>
<item row="7" column="0">
<widget class="QLabel" name="mLabelComment">
<property name="text">
<string>Comment</string>
</property>
<property name="buddy">
<cstring>mCommentEdit</cstring>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QComboBox" name="mTypeBox"/>
</item>
Expand All @@ -107,7 +120,7 @@
</property>
</widget>
</item>
<item row="7" column="1">
<item row="8" column="1">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
Expand All @@ -121,17 +134,17 @@
</spacer>
</item>
<item row="6" column="0">
<widget class="QLabel" name="mLabelComment">
<widget class="QLabel" name="mLabelAlias">
<property name="text">
<string>Comment</string>
<string>Alias</string>
</property>
<property name="buddy">
<cstring>mCommentEdit</cstring>
</property>
</widget>
</item>
<item row="6" column="1">
<widget class="QLineEdit" name="mCommentEdit"/>
<widget class="QLineEdit" name="mAliasEdit"/>
</item>
</layout>
</widget>
Expand All @@ -148,6 +161,8 @@
<tabstop>mTypeBox</tabstop>
<tabstop>mLength</tabstop>
<tabstop>mPrec</tabstop>
<tabstop>mAliasEdit</tabstop>
<tabstop>mCommentEdit</tabstop>
</tabstops>
<resources/>
<connections>
Expand Down

0 comments on commit 5b92283

Please sign in to comment.