Skip to content

Commit

Permalink
alias field and fixed problem with storing
Browse files Browse the repository at this point in the history
  • Loading branch information
signedav committed Oct 27, 2017
1 parent 10ab904 commit 9df37d3
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 30 deletions.
42 changes: 26 additions & 16 deletions src/app/qgsattributesformproperties.cpp
Expand Up @@ -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;
Expand All @@ -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 );
Expand All @@ -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 )
Expand All @@ -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();
Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -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() );
Expand Down Expand Up @@ -402,6 +410,8 @@ QgsAttributeEditorElement *QgsAttributesFormProperties::createAttributeEditorWid

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

QgsEditFormConfig editFormConfig = mLayer->editFormConfig();

QTreeWidgetItem* fieldContainer=mAvailableWidgetsTree->invisibleRootItem()->child(0);
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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 )
Expand Down
5 changes: 4 additions & 1 deletion src/app/qgsattributesformproperties.h
Expand Up @@ -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 )
Expand Down Expand Up @@ -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();
};
Expand Down
33 changes: 27 additions & 6 deletions src/app/qgsattributetypedialog.cpp
Expand Up @@ -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() );
Expand Down Expand Up @@ -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();
Expand Down
22 changes: 21 additions & 1 deletion src/app/qgsattributetypedialog.h
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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();

Expand Down
14 changes: 8 additions & 6 deletions src/ui/qgsattributesformproperties.ui
Expand Up @@ -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>
Expand All @@ -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>
Expand All @@ -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">
Expand All @@ -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">
Expand Down

0 comments on commit 9df37d3

Please sign in to comment.