Skip to content

Commit

Permalink
spacer
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterPetrik committed Oct 20, 2023
1 parent 0448b19 commit 7c32469
Show file tree
Hide file tree
Showing 7 changed files with 122 additions and 27 deletions.
30 changes: 27 additions & 3 deletions app/attributes/attributecontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "qgsattributeeditorrelation.h"
#include "qgsattributeeditorcontainer.h"
#include "qgsvectorlayerutils.h"
#include "qgsattributeeditorspacerelement.h"
#include "qgsvectorlayereditbuffer.h"
#include "qgsexpressioncontextutils.h"
#include "qgsrelation.h"
Expand Down Expand Up @@ -246,7 +247,6 @@ void AttributeController::flatten(
field,
groupName,
parentTabRow,
FormItem::Field,
layer->attributeDisplayName( fieldIndex ),
!isReadOnly,
getEditorWidgetSetup( layer, fieldIndex ),
Expand Down Expand Up @@ -300,7 +300,6 @@ void AttributeController::flatten(
widgetUuid,
groupName,
parentTabRow,
FormItem::Relation,
label,
parentVisibilityExpressions, // relation field doesn't have visibility expression itself
associatedRelation
Expand All @@ -312,9 +311,34 @@ void AttributeController::flatten(

break;
}
case Qgis::AttributeEditorType::SpacerElement:
{
QUuid fieldUuid = QUuid::createUuid();

QgsAttributeEditorSpacerElement *spacerElement = static_cast<QgsAttributeEditorSpacerElement *>( element );

const QString groupName = container->isGroupBox() ? container->name() : QString();
std::shared_ptr<FormItem> formItemData =
std::shared_ptr<FormItem>(
FormItem::createSpacerItem(
fieldUuid,
groupName,
parentTabRow,
spacerElement->name(),
spacerElement->drawLine(),
parentVisibilityExpressions // spacer doesn't have visibility expression itself
)
);

mFormItems[formItemData->id()] = formItemData;


items.append( fieldUuid );
break;
}

default:
// Invalid, Action, QmlElement, HtmlElement, TextElement and SpacerElement
// Invalid, Action, QmlElement, HtmlElement, TextElement
// are not supported at the moment
break;
}
Expand Down
64 changes: 46 additions & 18 deletions app/attributes/attributedata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,18 @@

#include "attributedata.h"

FormItem::FormItem(
const QUuid &id,
const QgsField &field,
const QString &groupName,
const int parentTabId,
FormItem::FormItemType type,
const QString &name,
bool isEditable,
const QgsEditorWidgetSetup &editorWidgetSetup,
int fieldIndex,
const QgsExpression &visibilityExpression,
const QgsRelation &relation
)
FormItem::FormItem( const QUuid &id,
const QgsField &field,
const QString &groupName,
const int parentTabId,
FormItem::FormItemType type,
const QString &name,
bool isEditable,
const QgsEditorWidgetSetup &editorWidgetSetup,
int fieldIndex,
const QgsExpression &visibilityExpression,
const QgsRelation &relation
)
: mId( id )
, mField( field )
, mGroupName( groupName )
Expand All @@ -48,7 +47,6 @@ FormItem *FormItem::createFieldItem(
const QgsField &field,
const QString &groupName,
int parentTabId,
FormItemType type,
const QString &name,
bool isEditable,
const QgsEditorWidgetSetup
Expand All @@ -62,19 +60,19 @@ FormItem *FormItem::createFieldItem(
field,
groupName,
parentTabId,
type,
FormItem::Field,
name,
isEditable,
editorWidgetSetup,
fieldIndex,
visibilityExpression
visibilityExpression,
QgsRelation()
);
}

FormItem *FormItem::createRelationItem( const QUuid &id,
const QString &groupName,
int parentTabId,
FormItemType type,
const QString &name,
const QgsExpression &visibilityExpression,
const QgsRelation &relation
Expand All @@ -85,7 +83,7 @@ FormItem *FormItem::createRelationItem( const QUuid &id,
QgsField(),
groupName,
parentTabId,
type,
FormItem::Relation,
name,
true,
QgsEditorWidgetSetup(),
Expand All @@ -96,6 +94,33 @@ FormItem *FormItem::createRelationItem( const QUuid &id,
return item;
}

FormItem *FormItem::createSpacerItem(
const QUuid &id,
const QString &groupName,
int parentTabId,
const QString &name,
bool isHLine,
const QgsExpression &visibilityExpression
)
{
FormItem *it = new FormItem(
id,
QgsField(),
groupName,
parentTabId,
FormItem::Spacer,
name,
false,
QgsEditorWidgetSetup(),
-1,
visibilityExpression,
QgsRelation()
);

it->setRawValue( isHLine );
return it;
}

FormItem::FormItemType FormItem::type() const
{
return mType;
Expand All @@ -116,6 +141,9 @@ QString FormItem::editorWidgetType() const
if ( mType == FormItem::Relation )
return QStringLiteral( "relation" );

if ( mType == FormItem::Spacer )
return QStringLiteral( "spacer" );

return mEditorWidgetSetup.type();
}

Expand Down
16 changes: 12 additions & 4 deletions app/attributes/attributedata.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class FormItem
Container,
Relation,
Field,
Spacer
};
Q_ENUMS( FormItemType )

Expand All @@ -59,15 +60,14 @@ class FormItem
const QgsEditorWidgetSetup &editorWidgetSetup,
int fieldIndex,
const QgsExpression &visibilityExpression,
const QgsRelation &relation = QgsRelation()
const QgsRelation &relation
);

static FormItem *createFieldItem(
const QUuid &id,
const QgsField &field,
const QString &groupName,
int parentTabId,
FormItem::FormItemType type,
const QString &name,
bool isEditable,
const QgsEditorWidgetSetup &editorWidgetSetup,
Expand All @@ -79,12 +79,20 @@ class FormItem
const QUuid &id,
const QString &groupName,
int parentTabId,
FormItem::FormItemType type,
const QString &name,
const QgsExpression &visibilityExpression,
const QgsRelation &relation
);

static FormItem *createSpacerItem(
const QUuid &id,
const QString &groupName,
int parentTabId,
const QString &name,
bool isHLine,
const QgsExpression &visibilityExpression
);

FormItem::FormItemType type() const;
QString name() const;
bool isEditable() const;
Expand Down Expand Up @@ -141,7 +149,7 @@ class FormItem
QVariant mOriginalValue; // original unmodified value
QVariant mRawValue;

const QgsRelation mRelation; // empty if type is field
const QgsRelation mRelation; // Only used for FormItemType::Relation
};

class TabItem
Expand Down
1 change: 1 addition & 0 deletions app/inpututils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1062,6 +1062,7 @@ const QUrl InputUtils::getEditorComponentSource( const QString &widgetName, cons
QStringLiteral( "datetime" ),
QStringLiteral( "range" ),
QStringLiteral( "relation" ),
QStringLiteral( "spacer" ),
QStringLiteral( "relationreference" )
};
if ( supportedWidgets.contains( widgetName ) )
Expand Down
1 change: 1 addition & 0 deletions app/qml/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ set(MM_QML
editor/inputvaluemap.qml
editor/inputvaluerelationcombobox.qml
editor/inputvaluerelationpage.qml
editor/inputspacer.qml
form/FeatureForm.qml
form/FeatureFormPage.qml
form/FeatureFormStyling.qml
Expand Down
30 changes: 30 additions & 0 deletions app/qml/editor/inputspacer.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/***************************************************************************
checkbox.qml
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

import QtQuick
import QtQuick.Controls
import "../components"

Rectangle {
id: spacer

property bool isHLine: value
property int spacerHeight: customStyle.fields.height
property int hLineWidth: 1

height: isHLine ? hLineWidth : spacerHeight
width: parent.width
color: isHLine ? customStyle.fields.fontColor : "transparent"
anchors {
right: parent.right
left: parent.left
}
}
7 changes: 5 additions & 2 deletions app/qml/form/FeatureForm.qml
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ Item {
id: fieldContainer

// TODO: filter such fields in field proxy model instead
property bool shouldBeVisible: Type === FormItem.Field || Type === FormItem.Relation
property bool shouldBeVisible: Type === FormItem.Field || Type === FormItem.Relation || Type === FormItem.Spacer

visible: shouldBeVisible

Expand Down Expand Up @@ -434,6 +434,8 @@ Item {
id: fieldLabel

text: Name
height: visible ? paintedHeight : 0
visible: Type !== FormItem.Spacer
color: form.style.constraint.validColor
leftPadding: form.style.fields.sideMargin
font.pixelSize: form.style.fields.labelPixelSize
Expand Down Expand Up @@ -512,7 +514,8 @@ Item {
source: {
if ( widget !== undefined )
return __inputUtils.getEditorComponentSource( widget.toLowerCase(), config, field )
else return ''
else
return ''
}
}

Expand Down

1 comment on commit 7c32469

@inputapp-bot
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

iOS - version 23.10.471411 just submitted!

Please sign in to comment.