Skip to content

Commit

Permalink
organise inputs and form editors
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasMizera committed Jan 31, 2024
1 parent 33cacbe commit 1e4e35a
Show file tree
Hide file tree
Showing 29 changed files with 298 additions and 166 deletions.
38 changes: 32 additions & 6 deletions app/qml/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ set(MM_QML
components/MMRoundButton.qml
components/MMButton.qml
components/MMComponent_reachedDataLimit.qml
components/MMCheckBox.qml
components/MMDrawer.qml
components/MMHeader.qml
components/MMHlineText.qml
Expand All @@ -54,7 +55,6 @@ set(MM_QML
components/MMNotification.qml
components/MMNotificationView.qml
components/MMPhoto.qml
components/MMPhotoGallery.qml
components/MMProgressBar.qml
components/MMProjectItem.qml
components/MMRadioButton.qml
Expand Down Expand Up @@ -100,18 +100,44 @@ set(MM_QML
editor/inputvaluerelationcombobox.qml
editor/inputvaluerelationpage.qml
editor/inputspacer.qml
inputs/MMAbstractEditor.qml
inputs/MMCheckBox.qml
inputs/MMInputEditor.qml
inputs/MMPasswordEditor.qml
inputs/MMSliderEditor.qml

#
# Inputs
#

inputs/MMBaseInput.qml
inputs/MMPasswordInput.qml
inputs/MMTextInput.qml
inputs/MMSearchInput.qml

#
# Forms
#

form/FeatureForm.qml
form/FeatureFormPage.qml
form/FeatureFormStyling.qml
form/FeatureToolbar.qml
form/FormWrapper.qml
form/MMFormTabBar.qml
form/PreviewPanel.qml
form/editors/MMButtonFormEditor.qml
form/editors/MMCalendarFormEditor.qml
form/editors/MMDropdownFormEditor.qml
form/editors/MMGalleryFormEditor.qml
form/editors/MMNumberFormEditor.qml
form/editors/MMPhotoFormEditor.qml
form/editors/MMScannerFormEditor.qml
form/editors/MMSliderFormEditor.qml
form/editors/MMSwitchFormEditor.qml
form/editors/MMTextMultilineFormEditor.qml
form/editors/MMTextFormEditor.qml
# we are missing the following form editors:
# - Spacer
# - Text / HTML widget
# - Relation reference
# - Relations

layers/FeaturesListPageV2.qml
layers/LayerDetail.qml
layers/LayersListPageV2.qml
Expand Down
File renamed without changes.
4 changes: 3 additions & 1 deletion app/qml/components/MMComboBoxDrawer.qml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import QtQuick.Controls
import QtQuick.Controls.Basic
import "../inputs"


// TODO: rename to MMDropdownDrawer
Drawer {
id: root

Expand Down Expand Up @@ -84,7 +86,7 @@ Drawer {
}
}

MMSearchEditor {
MMSearchInput {
id: searchBar

width: parent.width - 2 * root.padding
Expand Down
2 changes: 1 addition & 1 deletion app/qml/components/MMDrawer.qml
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ Drawer {

MouseArea {
anchors.fill: parent
onClicked: control.visible = false
onClicked: control.close()
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@
import QtQuick
import QtQuick.Controls
import QtQuick.Controls.Basic
import "../components"
import "../../components"
import "../../inputs"

MMAbstractEditor {
MMBaseInput {
id: root

property var parentValue: parent.value ?? ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@
import QtQuick
import QtQuick.Controls
import QtQuick.Controls.Basic
import "../components"
import "../../components"
import "../../inputs"

MMAbstractEditor {
MMBaseInput {
id: root

property var parentField: parent.field ?? ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@
import QtQuick
import QtQuick.Controls
import QtQuick.Controls.Basic
import "../components"
import "../../components"
import "../../inputs"

MMAbstractEditor {
MMBaseInput {
id: root

property alias placeholderText: textField.placeholderText
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import QtQuick
import QtQuick.Controls

import "../../components"

Item {
id: root

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,32 +10,52 @@
import QtQuick
import QtQuick.Controls
import QtQuick.Controls.Basic
import "../components"

MMAbstractEditor {
import "../../components"
import "../../inputs"

/*
* Number (range editable) editor for QGIS Attribute Form
* Requires various global properties set to function, see featureform Loader section.
* These properties are injected here via 'fieldXYZ' properties and captured with underscore `_`.
*
* Should be used only within feature form.
*/

MMBaseInput {
id: root

property var parentValue: parent.value ?? 0
property bool parentValueIsNull: parent.valueIsNull ?? false
property bool isReadOnly: parent.readOnly ?? false
property var _fieldValue: parent.fieldValue
property var _fieldConfig: parent.fieldConfig
property bool _fieldValueIsNull: parent.fieldValueIsNull

property bool _fieldShouldShowTitle: parent.fieldShouldShowTitle
property bool _fieldIsReadOnly: parent.fieldIsReadOnly

property string _fieldTitle: parent.fieldTitle
property string _fieldErrorMessage: parent.fieldErrorMessage
property string _fieldWarningMessage: parent.fieldWarningMessage

property var locale: Qt.locale()
// TODO: uncomment in Input app
property real precision//: config['Precision'] ? config['Precision'] : 0
property string suffix//: config['Suffix'] ? config['Suffix'] : ''
property real from //: config["Min"]
property real to //: config["Max"]
property real to: _fieldConfig["Max"]
property real from: _fieldConfig["Min"]
property string suffix: _fieldConfig['Suffix'] ? _fieldConfig['Suffix'] : ''
property real precision: _fieldConfig['Precision'] ? _fieldConfig['Precision'] : 0

property alias placeholderText: numberInput.placeholderText

// don't ever use a step smaller than would be visible in the widget
// i.e. if showing 2 decimals, smallest increment will be 0.01
// https://github.com/qgis/QGIS/blob/a038a79997fb560e797daf3903d94c7d68e25f42/src/gui/editorwidgets/qgsdoublespinbox.cpp#L83-L87
property real step//: Math.max(config["Step"], Math.pow( 10.0, 0.0 - precision ))
property real step: Math.max(_fieldConfig["Step"], Math.pow( 10.0, 0.0 - precision ))

signal editorValueChanged( var newValue, var isNull )

enabled: !isReadOnly
title: _fieldShouldShowTitle ? _fieldTitle : ""

errorMsg: _fieldErrorMessage
warningMsg: _fieldWarningMessage

enabled: !_fieldIsReadOnly
hasFocus: numberInput.activeFocus

leftAction: MMIcon {
Expand All @@ -48,8 +68,17 @@ MMAbstractEditor {
enabled: Number( numberInput.text ) - root.step >= root.from
}

onLeftActionClicked: {
if ( leftIcon.enabled )
{
let decremented = Number( numberInput.text ) - root.step
root.editorValueChanged( decremented.toFixed( root.precision ), false )
}
}

content: Item {
anchors.fill: parent

Row {
height: parent.height
anchors.horizontalCenter: parent.horizontalCenter
Expand All @@ -60,12 +89,16 @@ MMAbstractEditor {

height: parent.height

clip: true
text: root.parentValue === undefined || root.parentValueIsNull ? "" : root.parentValue
color: root.enabled ? __style.nightColor : __style.mediumGreenColor
text: root._fieldValue === undefined || root._fieldValueIsNull ? '' : root._fieldValue

placeholderTextColor: __style.nightAlphaColor
color: root.enabled ? __style.nightColor : __style.mediumGreenColor

font: __style.p5

clip: true
hoverEnabled: true

verticalAlignment: Qt.AlignVCenter
inputMethodHints: Qt.ImhFormattedNumbersOnly

Expand All @@ -83,7 +116,7 @@ MMAbstractEditor {
Text {
id: suffix

text: root.suffix
text: root.suffix ? ' ' + root.suffix : "" // to make sure there is a space between the number and the suffix

visible: root.suffix !== "" && numberInput.text !== ""

Expand All @@ -106,18 +139,14 @@ MMAbstractEditor {
enabled: Number( numberInput.text ) + root.step <= root.to
}

onLeftActionClicked: {
numberInput.forceActiveFocus()
if ( leftIcon.enabled ) {
let decremented = Number( numberInput.text ) - root.step
root.editorValueChanged( decremented.toFixed( root.precision ), false )
}
}
onRightActionClicked: {
numberInput.forceActiveFocus();
if ( rightIcon.enabled ) {
if ( rightIcon.enabled )
{
let incremented = Number( numberInput.text ) + root.step
root.editorValueChanged( incremented.toFixed( root.precision ), false )
}
}

// on press and hold behavior can be used from here:
// https://github.com/mburakov/qt5/blob/93bfa3874c10f6cb5aa376f24363513ba8264117/qtquickcontrols/src/controls/SpinBox.qml#L306-L309
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@
import QtQuick
import QtQuick.Controls
import QtQuick.Controls.Basic
import "../components"
import "../../components"
import "../../inputs"

MMAbstractEditor {
MMBaseInput {
id: root

property var parentValue: parent.value ?? ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@
import QtQuick
import QtQuick.Controls
import QtQuick.Controls.Basic
import "../components"
import "../../components"
import "../../inputs"

MMAbstractEditor {
MMBaseInput {
id: root

property var parentValue: parent.value
Expand Down Expand Up @@ -41,6 +42,8 @@ MMAbstractEditor {
background: Rectangle {
color: __style.transparentColor
}

onTextChanged: root.editorValueChanged( text, text === "" )
}

rightAction: MMIcon {
Expand Down
Loading

0 comments on commit 1e4e35a

Please sign in to comment.