Newer
Older
/*=====================================================================
QGroundControl Open Source Ground Control Station
(c) 2009 - 2015 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
This file is part of the QGROUNDCONTROL project
QGROUNDCONTROL 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 3 of the License, or
(at your option) any later version.
QGROUNDCONTROL is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with QGROUNDCONTROL. If not, see <http://www.gnu.org/licenses/>.
======================================================================*/
/// @file
/// @author Don Gagne <don@thegagnes.com>
import QGroundControl.Controls 1.0
import QGroundControl.Palette 1.0
import QGroundControl.ScreenTools 1.0
import QGroundControl.Controllers 1.0
import QGroundControl.FactSystem 1.0
import QGroundControl.FactControls 1.0
QGCPalette { id: __qgcPal; colorGroupEnabled: true }
property Fact __editorDialogFact: Fact { }
readonly property real __leftMargin: 10
readonly property real __rightMargin: 20
readonly property int __maxParamChars: 16
property bool _searchFilter: false ///< true: showing results of search
property var _searchResults ///< List of parameter names from search results
ParameterEditorController {
id: controller;
factPanel: panel
onShowErrorMessage: {
showMessage("Parameter Load Errors", errorMsg, StandardButton.Ok)
}
}
ParameterEditorDialog { fact: __editorDialogFact }
Component {
id: searchDialogComponent
QGCViewDialog {
function accept() {
_searchResults = controller.searchParametersForComponent(-1, searchFor.text, true /*searchInName.checked*/, true /*searchInDescriptions.checked*/)
_searchFilter = true
hideDialog()
}
function reject() {
_searchFilter = false
hideDialog()
}
QGCLabel {
id: searchForLabel
text: "Search for:"
}
QGCTextField {
id: searchFor
anchors.topMargin: defaultTextHeight / 3
anchors.top: searchForLabel.bottom
width: defaultTextWidth * 20
}
/*
// Leaving in for possible future use. We'll see if needed from user comments.
QGCLabel {
id: searchInLabel
anchors.topMargin: defaultTextHeight
anchors.top: searchFor.bottom
text: "Search in:"
}
QGCCheckBox {
id: searchInName
anchors.topMargin: defaultTextHeight / 3
anchors.top: searchInLabel.bottom
text: "Name"
}
QGCCheckBox {
id: searchInDescriptions
anchors.topMargin: defaultTextHeight / 3
anchors.top: searchInName.bottom
text: "Descriptions"
}
QGCLabel {
anchors.topMargin: defaultTextHeight
width: parent.width
wrapMode: Text.WordWrap
text: "Hint: Leave 'Search For' blank and click Apply to list all parameters sorted by name."
}
}
}
Column {
id: factColumn
x: __leftMargin
QGCLabel {
text: group
verticalAlignment: Text.AlignVCenter
font.pixelSize: ScreenTools.mediumFontPixelSize
}
Rectangle {
width: parent.width
height: 1
color: __qgcPal.text
}
Column {
property Fact modelFact: controller.getParameterFact(componentId, modelData)
Item {
x: __leftMargin
width: parent.width
height: ScreenTools.defaultFontPixelSize * 1.75
QGCLabel {
id: nameLabel
width: defaultTextWidth * (__maxParamChars + 1)
height: parent.height
verticalAlignment: Text.AlignVCenter
text: modelFact.name
}
QGCLabel {
id: valueLabel
width: defaultTextWidth * 20
height: parent.height
anchors.left: nameLabel.right
verticalAlignment: Text.AlignVCenter
color: modelFact.valueEqualsDefault ? __qgcPal.text : "orange"
text: modelFact.valueString + " " + modelFact.units
}
QGCLabel {
height: parent.height
anchors.left: valueLabel.right
verticalAlignment: Text.AlignVCenter
text: modelFact.shortDescription
MouseArea {
anchors.fill: parent
acceptedButtons: Qt.LeftButton
onClicked: {
__editorDialogFact = modelFact
showDialog(editorDialogComponent, "Parameter Editor", 50, StandardButton.Cancel | StandardButton.Save)
}
Rectangle {
x: __leftMargin
width: factColumn.width - __leftMargin - __rightMargin
height: 1
color: __qgcPal.windowShade
}
} // Column - Fact
} // Repeater - Facts
} // Column - Facts
} // Component - factRowsComponent
Component {
id: groupedViewComponent
Item {
Flickable {
id : groupScroll
width: defaultTextWidth * 25
height: parent.height
clip: true
contentHeight: groupedViewComponentColumn.height
contentWidth: groupedViewComponentColumn.width
boundsBehavior: Flickable.StopAtBounds
flickableDirection: Flickable.VerticalFlick
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
Repeater {
model: controller.componentIds
Column {
id: componentColumn
readonly property int componentId: parseInt(modelData)
QGCLabel {
height: contentHeight + (ScreenTools.defaultFontPixelHeight * 0.5)
text: "Component #: " + componentId.toString()
verticalAlignment: Text.AlignVCenter
font.pixelSize: ScreenTools.mediumFontPixelSize
}
Repeater {
model: controller.getGroupsForComponent(componentColumn.componentId)
Column {
QGCButton {
x: __leftMargin
width: groupScroll.width - __leftMargin - __rightMargin
text: modelData
onClicked: {
factRowsLoader.sourceComponent = null
factRowsLoader.componentId = componentId
factRowsLoader.group = modelData
factRowsLoader.sourceComponent = factRowsComponent
}
}
Item {
width: 1
height: ScreenTools.defaultFontPixelSize * 0.25
}
} // Column - Group
} // Repeater - Groups
Item {
height: 10
width: 10
}
} // Column - Component
} // Repeater - Components
} // Column - Component
id: factScrollView
anchors.left: groupScroll.right
anchors.right: parent.right
height: parent.height
contentHeight: factRowsLoader.height
contentWidth: panel.width * 2 //-- TODO: Find how to get actual resulting width. "factRowsLoader.sourceComponent.width" doesn't work.
boundsBehavior: Flickable.StopAtBounds
clip: true
Loader {
id: factRowsLoader
sourceComponent: factRowsComponent
property int componentId: controller.componentIds[0]
property string group: controller.getGroupsForComponent(controller.componentIds[0])[0]
property var parameterNames: controller.getParametersForGroup(componentId, group)
}
} // Item
} // Component - groupedViewComponent
Component {
id: searchResultsViewComponent
Item {
ScrollView {
id: factScrollView
anchors.left: parent.left
anchors.right: parent.right
height: parent.height
horizontalScrollBarPolicy: Qt.ScrollBarAlwaysOff
verticalScrollBarPolicy: Qt.ScrollBarAlwaysOff
Loader {
id: factRowsLoader
width: factScrollView.width
sourceComponent: factRowsComponent
property int componentId: -1
property string group: "Search results"
property var parameterNames: _searchResults
}
} // ScrollView - Facts
} // Item
} // Component - sortedViewComponent
QGCViewPanel {
id: panel
anchors.fill: parent
Column {
anchors.fill: parent
Item {
width: parent.width
font.pixelSize: ScreenTools.mediumFontPixelSize
text: "PARAMETERS"
QGCButton {
id: toolsButton
anchors.right: parent.right
text: "Tools"
menu: Menu {
MenuItem {
text: "Refresh"
onTriggered: controller.refresh()
}
MenuItem {
text: "Reset all to defaults"
onTriggered: controller.resetAllToDefaults()
}
MenuItem {
text: "Search..."
onTriggered: showDialog(searchDialogComponent, "Parameter Search", 50, StandardButton.Reset | StandardButton.Apply)
}
MenuSeparator { }
MenuItem {
onTriggered: controller.loadFromFile()
}
MenuItem {
onTriggered: controller.saveToFile()
}
MenuSeparator { }
MenuItem {
text: "Clear RC to Param"
onTriggered: controller.clearRCToParam()
}
Item {
id: lastSpacer
height: 10
width: 5
}
Loader {
width: parent.width
height: parent.height - (lastSpacer.y + lastSpacer.height)
sourceComponent: _searchFilter ? searchResultsViewComponent: groupedViewComponent
}