Skip to content
Permalink
Browse files

alias field and fixed problem with storing

  • Loading branch information
signedav committed Oct 27, 2017
1 parent 10ab904 commit 9df37d315bbe183b606355e9df8a2de97db1751e
@@ -74,15 +74,16 @@ void QgsAttributesFormProperties::loadAttributeTypeDialog()

//
mAttributeTypeDialog = new QgsAttributeTypeDialog( mLayer, index, mAttributeTypeFrame );

mAttributeTypeDialog->setAlias( cfg.mAlias );
mAttributeTypeDialog->setFieldEditable( cfg.mEditable );
mAttributeTypeDialog->setLabelOnTop( cfg.mLabelOnTop );
mAttributeTypeDialog->setNotNull( cfg.mConstraints & QgsFieldConstraints::ConstraintNotNull );
mAttributeTypeDialog->setNotNullEnforced( cfg.mConstraintStrength.value( QgsFieldConstraints::ConstraintNotNull, QgsFieldConstraints::ConstraintStrengthHard ) == QgsFieldConstraints::ConstraintStrengthHard );
mAttributeTypeDialog->setUnique( cfg.mConstraints & QgsFieldConstraints::ConstraintUnique );
mAttributeTypeDialog->setUniqueEnforced( cfg.mConstraintStrength.value( QgsFieldConstraints::ConstraintUnique, QgsFieldConstraints::ConstraintStrengthHard ) == QgsFieldConstraints::ConstraintStrengthHard );

QgsFieldConstraints constraints = mLayer->fields().at( index ).constraints();
//confustion (will be removed): when we make this, the contraint stuff is allways reloaded from layer when we only change the widged-selection... : QgsFieldConstraints constraints = mLayer->fields().at( index ).constraints();
QgsFieldConstraints constraints = cfg.mFieldConstraints;
QgsFieldConstraints::Constraints providerConstraints = 0;
if ( constraints.constraintOrigin( QgsFieldConstraints::ConstraintNotNull ) == QgsFieldConstraints::ConstraintOriginProvider )
providerConstraints |= QgsFieldConstraints::ConstraintNotNull;
@@ -95,7 +96,9 @@ void QgsAttributesFormProperties::loadAttributeTypeDialog()
mAttributeTypeDialog->setConstraintExpression( cfg.mConstraint );
mAttributeTypeDialog->setConstraintExpressionDescription( cfg.mConstraintDescription );
mAttributeTypeDialog->setConstraintExpressionEnforced( cfg.mConstraintStrength.value( QgsFieldConstraints::ConstraintExpression, QgsFieldConstraints::ConstraintStrengthHard ) == QgsFieldConstraints::ConstraintStrengthHard );
mAttributeTypeDialog->setDefaultValueExpression( mLayer->defaultValueExpression( index ) );
mAttributeTypeDialog->setDefaultValueExpression( mLayer->defaultValueDefinition( index ).expression() );
mAttributeTypeDialog->setApplyDefaultValueOnUpdate( mLayer->defaultValueDefinition( index ).applyOnUpdate() );
//confustion (will be removed): das hier funktioniert nicht, es is neu, aber ich weiss nicht woher: mAttributeTypeDialog->setDefaultValueExpression( mLayer->defaultValueExpression( index ) );

mAttributeTypeDialog->setEditorWidgetConfig( cfg.mEditorWidgetConfig );
mAttributeTypeDialog->setEditorWidgetType( cfg.mEditorWidgetType );
@@ -114,7 +117,10 @@ void QgsAttributesFormProperties::storeAttributeTypeDialog()

cfg.mEditable = mAttributeTypeDialog->fieldEditable();
cfg.mLabelOnTop = mAttributeTypeDialog->labelOnTop();
cfg.mAlias = mAttributeTypeDialog->alias();
cfg.mComment = mAttributeTypeDialog->comment();

//confustion (will be removed): wir laden teilweise sachen einfach beim store anstelle des applys auf die mLayer - eingie Sachen laden wir auch vom layer anstatt über das cfg. wieso
QgsFieldConstraints constraints = mLayer->fields().at( mAttributeTypeDialog->fieldIdx() ).constraints();
QgsFieldConstraints::Constraints providerConstraints = 0;
if ( constraints.constraintOrigin( QgsFieldConstraints::ConstraintNotNull ) == QgsFieldConstraints::ConstraintOriginProvider )
@@ -139,7 +145,8 @@ void QgsAttributesFormProperties::storeAttributeTypeDialog()

cfg.mConstraintDescription = mAttributeTypeDialog->constraintExpressionDescription();
cfg.mConstraint = mAttributeTypeDialog->constraintExpression();
mLayer->setDefaultValueExpression( mAttributeTypeDialog->fieldIdx(), mAttributeTypeDialog->defaultValueExpression() );
//confustion (will be removed): das hier funktioniert nicht, es is neu, aber ich weiss nicht woher: mLayer->setDefaultValueExpression( mAttributeTypeDialog->fieldIdx(), mAttributeTypeDialog->defaultValueExpression() );
mLayer->setDefaultValueDefinition( mAttributeTypeDialog->fieldIdx(), QgsDefaultValue( mAttributeTypeDialog->defaultValueExpression(), mAttributeTypeDialog->applyDefaultValueOnUpdate() ) );

cfg.mEditorWidgetType = mAttributeTypeDialog->editorWidgetType();
cfg.mEditorWidgetConfig = mAttributeTypeDialog->editorWidgetConfig();
@@ -279,6 +286,7 @@ void QgsAttributesFormProperties::initAvailableWidgetsTree()
{
const QgsField field = fields.at( i );
DnDTreeItemData itemData = DnDTreeItemData( DnDTreeItemData::Field, field.name() );
//should we load here stuff like in im loadAttributeEditorTreeItem other stuff like itemData.setShowLabel( true );?
itemData.setShowLabel( true );

FieldConfig cfg( mLayer, i );
@@ -359,7 +367,7 @@ QgsAttributeEditorElement *QgsAttributesFormProperties::createAttributeEditorWid

switch ( itemData.type() )
{
//dave hier auch indexed rein?
//indexed here?
case DnDTreeItemData::Field:
{
int idx = mLayer->fields().lookupField( itemData.name() );
@@ -402,6 +410,8 @@ QgsAttributeEditorElement *QgsAttributesFormProperties::createAttributeEditorWid

void QgsAttributesFormProperties::apply()
{
storeAttributeTypeDialog();

QgsEditFormConfig editFormConfig = mLayer->editFormConfig();

QTreeWidgetItem* fieldContainer=mAvailableWidgetsTree->invisibleRootItem()->child(0);
@@ -444,7 +454,8 @@ void QgsAttributesFormProperties::apply()
mLayer->removeFieldConstraint( idx, QgsFieldConstraints::ConstraintExpression );
}

//mLayer->setFieldAlias( idx, aliasItem->text() );
mLayer->setFieldAlias( idx, cfg.mAlias );
//wo?? ( idx, cfg.mComment );
}

// tabs and groups
@@ -519,17 +530,18 @@ QgsAttributesFormProperties::FieldConfig::FieldConfig()
QgsAttributesFormProperties::FieldConfig::FieldConfig( QgsVectorLayer *layer, int idx )
: mButton( nullptr )
{
mAlias=layer->fields().at( idx ).alias();
mEditable = !layer->editFormConfig().readOnly( idx );
mEditableEnabled = layer->fields().fieldOrigin( idx ) != QgsFields::OriginJoin
&& layer->fields().fieldOrigin( idx ) != QgsFields::OriginExpression;
mLabelOnTop = layer->editFormConfig().labelOnTop( idx );
QgsFieldConstraints constraints = layer->fields().at( idx ).constraints();
mConstraints = constraints.constraints();
mConstraint = constraints.constraintExpression();
mConstraintStrength.insert( QgsFieldConstraints::ConstraintNotNull, constraints.constraintStrength( QgsFieldConstraints::ConstraintNotNull ) );
mConstraintStrength.insert( QgsFieldConstraints::ConstraintUnique, constraints.constraintStrength( QgsFieldConstraints::ConstraintUnique ) );
mConstraintStrength.insert( QgsFieldConstraints::ConstraintExpression, constraints.constraintStrength( QgsFieldConstraints::ConstraintExpression ) );
mConstraintDescription = constraints.constraintDescription();
mFieldConstraints = layer->fields().at( idx ).constraints();
mConstraints = mFieldConstraints.constraints();
mConstraint = mFieldConstraints.constraintExpression();
mConstraintStrength.insert( QgsFieldConstraints::ConstraintNotNull, mFieldConstraints.constraintStrength( QgsFieldConstraints::ConstraintNotNull ) );
mConstraintStrength.insert( QgsFieldConstraints::ConstraintUnique, mFieldConstraints.constraintStrength( QgsFieldConstraints::ConstraintUnique ) );
mConstraintStrength.insert( QgsFieldConstraints::ConstraintExpression, mFieldConstraints.constraintStrength( QgsFieldConstraints::ConstraintExpression ) );
mConstraintDescription = mFieldConstraints.constraintDescription();
const QgsEditorWidgetSetup setup = QgsGui::editorWidgetRegistry()->findBest( layer, layer->fields().field( idx ).name() );
mEditorWidgetType = setup.type();
mEditorWidgetConfig = setup.config();
@@ -561,9 +573,7 @@ DnDTree::DnDTree( QgsVectorLayer *layer, QWidget *parent )
: QTreeWidget( parent )
, mLayer( layer )
{
//connect( this, &QTreeWidget::itemDoubleClicked, this, &DnDTree::onItemDoubleClicked );
//connect( this, &QTreeWidget::itemDoubleClicked, this, &DnDTree::attributeTypeDialog );
//connect( this, &QTreeWidget::itemSelectionChanged, this, &DnDTree::attributeTypeDialog );
connect( this, &QTreeWidget::itemDoubleClicked, this, &DnDTree::onItemDoubleClicked );
}

QTreeWidgetItem *DnDTree::addItem( QTreeWidgetItem *parent, QgsAttributesFormProperties::DnDTreeItemData data )
@@ -81,7 +81,7 @@ class APP_EXPORT QgsAttributesFormProperties : public QWidget, private Ui_QgsAtt
Container
};

//dave: do we need that
//do we need that
DnDTreeItemData()
: mType( Field )
, mColumnCount( 1 )
@@ -142,13 +142,16 @@ class APP_EXPORT QgsAttributesFormProperties : public QWidget, private Ui_QgsAtt
bool mEditable;
bool mEditableEnabled;
bool mLabelOnTop;
QgsFieldConstraints mFieldConstraints;
QgsFieldConstraints::Constraints mConstraints;
QHash< QgsFieldConstraints::Constraint, QgsFieldConstraints::ConstraintStrength > mConstraintStrength;
QString mConstraint;
QString mConstraintDescription;
QPushButton *mButton = nullptr;
QString mEditorWidgetType;
QMap<QString, QVariant> mEditorWidgetConfig;
QString mAlias;
QString mComment;

operator QVariant();
};
@@ -45,7 +45,7 @@ QgsAttributeTypeDialog::QgsAttributeTypeDialog( QgsVectorLayer *vl, int fieldIdx
, mFieldIdx( fieldIdx )
{
setupUi( this );
connect( selectionListWidget, &QListWidget::currentRowChanged, this, &QgsAttributeTypeDialog::selectionListWidget_currentRowChanged );
//removed selectionListWidget: connect( selectionListWidget, &QListWidget::currentRowChanged, this, &QgsAttributeTypeDialog::selectionListWidget_currentRowChanged );
setWindowTitle( tr( "Edit Widget Properties - %1 (%2)" ).arg( vl->fields().at( fieldIdx ).name(), vl->name() ) );

QMapIterator<QString, QgsEditorWidgetFactory *> it( QgsGui::editorWidgetRegistry()->factories() );
@@ -336,18 +336,39 @@ void QgsAttributeTypeDialog::setFieldEditable( bool editable )
isFieldEditableCheckBox->setChecked( editable );
}

void QgsAttributeTypeDialog::setLabelOnTop( bool onTop )
void QgsAttributeTypeDialog::setAlias( const QString &alias )
{
labelOnTopCheckBox->setChecked( onTop );
leAlias->setText( alias );
}

void QgsAttributeTypeDialog::selectionListWidget_currentRowChanged( int index )
QString QgsAttributeTypeDialog::alias()
{
const QString editType = selectionListWidget->item( index )->data( Qt::UserRole ).toString();
return leAlias->text();
}

setEditorWidgetType( editType );
void QgsAttributeTypeDialog::setComment( const QString &comment )
{
leComment->setText( comment );
}

QString QgsAttributeTypeDialog::comment()
{
return leComment->text();
}


void QgsAttributeTypeDialog::setLabelOnTop( bool onTop )
{
labelOnTopCheckBox->setChecked( onTop );
}

//removed selectionListWidget: void QgsAttributeTypeDialog::selectionListWidget_currentRowChanged( int index )
//removed selectionListWidget: {
//removed selectionListWidget: const QString editType = selectionListWidget->item( index )->data( Qt::UserRole ).toString();
//removed selectionListWidget:
//removed selectionListWidget: setEditorWidgetType( editType );
//removed selectionListWidget: }

void QgsAttributeTypeDialog::defaultExpressionChanged()
{
QString expression = mExpressionWidget->expression();
@@ -63,6 +63,26 @@ class APP_EXPORT QgsAttributeTypeDialog: public QWidget, private Ui::QgsAttribut
*/
bool labelOnTop() const;

/**
* Setter for lable alias
*/
void setAlias( const QString &alias );

/**
* Getter for lable alias
*/
QString alias();

/**
* Setter for lable comment
*/
void setComment( const QString &comment );

/**
* Getter for lable comment
*/
QString comment();

/**
* Setter for checkbox for editable state of field
*/
@@ -183,7 +203,7 @@ class APP_EXPORT QgsAttributeTypeDialog: public QWidget, private Ui::QgsAttribut
*/
void onCurrentWidgetChanged( int index );

void selectionListWidget_currentRowChanged( int index );
//removed selectionListWidget: void selectionListWidget_currentRowChanged( int index );

void defaultExpressionChanged();

@@ -13,7 +13,7 @@
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="leftMargin">
<number>0</number>
</property>
@@ -26,7 +26,7 @@
<property name="bottomMargin">
<number>0</number>
</property>
<item row="0" column="0">
<item>
<widget class="QSplitter" name="splitter">
<property name="orientation">
<enum>Qt::Horizontal</enum>
@@ -45,10 +45,9 @@
</widget>
</item>
<item row="0" column="1" rowspan="6">
<widget class="QWidget" name="mFormLayoutWidget" native="true"/>
</item>
<item row="0" column="0" rowspan="6">
<widget class="QWidget" name="mAvailableWidgetsWidget" native="true"/>
<widget class="QWidget" name="mFormLayoutWidget" native="true">
<zorder>mAvailableWidgetsWidget</zorder>
</widget>
</item>
<item row="2" column="2">
<widget class="QToolButton" name="mRemoveTabOrGroupButton">
@@ -74,6 +73,9 @@
</property>
</spacer>
</item>
<item row="0" column="0" rowspan="6">
<widget class="QWidget" name="mAvailableWidgetsWidget" native="true"/>
</item>
</layout>
</widget>
<widget class="QWidget" name="mAttributeTypeFrame" native="true">

0 comments on commit 9df37d3

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