一、相关配置文件及对应画面 1.界面GeneralSettings.qml 2.Video.SettingsGroup.json对应界面如下:
{
"name": "VideoSource",
"shortDescription": "Video source",
"longDescription": "Source for video. UDP, TCP, RTSP and UVC Cameras may be supported depending on Vehicle and ground station version.",
"type": "string",
"defaultValue": ""
},
{
"name": "VideoUDPPort",
"shortDescription": "Video UDP Port",
"longDescription": "UDP port to bind to for video stream.",
"type": "uint16",
"min": 1025,
"defaultValue": 5600
},
3.相机配置参数写到QGroundControl.ini配置文件
[General]
AudioMuted=true
BaseDeviceFontPointSize=13
DroneConnectionTimeout=5
MaxDiskCache=1024
MaxMemoryCache=128
SavePath=/home/xt/\x6587\x6863/QGroundControl
SettingsVersion=7
StreamEnabled=true
VideoRTSPUrl=rtsp://127.0.0.1:8554/
VideoSource=UDP Video Stream
VideoUDPPort=5600
VirtualTabletJoystick=false
VisibleWidgets=
_geometry=@ByteArray(\x1\xd9\xd0\xcb\0\x2\0\0\0\0\0\x41\0\0\0\x34\0\0\x4@\0\0\x2\x8b\0\0\0\x41\0\0\0P\0\0\x4@\0\0\x2\x8b\0\0\0\0\0\0\0\0\x6\x8e)
二、程序片段说明 GeneralSettings.qml
Row {
spacing: ScreenTools.defaultFontPixelWidth
visible: QGroundControl.settingsManager.videoSettings.videoSource.visible
QGCLabel {
text: qsTr("Video Source:")
width: _labelWidth
anchors.verticalCenter: parent.verticalCenter
}
FactComboBox {
id: videoSource
width: _editFieldWidth
indexModel: false
fact: QGroundControl.settingsManager.videoSettings.videoSource
anchors.verticalCenter: parent.verticalCenter
}
}
Row {
spacing: ScreenTools.defaultFontPixelWidth
visible: QGroundControl.settingsManager.videoSettings.udpPort.visible && QGroundControl.videoManager.isGStreamer && videoSource.currentIndex === 1
QGCLabel {
text: qsTr("UDP Port:")
width: _labelWidth
anchors.verticalCenter: parent.verticalCenter
}
FactTextField {
width: _editFieldWidth
fact: QGroundControl.settingsManager.videoSettings.udpPort
anchors.verticalCenter: parent.verticalCenter
}
}
对QGroundControl.settingsManager.videoSettings.videoSource说明
Fact* VideoSettings::videoSource(void)
{
if (!_videoSourceFact) {
_videoSourceFact = _createSettingsFact(videoSourceName);
connect(_videoSourceFact, &Fact::valueChanged, this, &VideoSettings::_configChanged);
}
return _videoSourceFact;
}
const char* VideoSettings::videoSourceName = "VideoSource";
SettingsGroup::SettingsGroup(const QString& name, const QString& settingsGroup, QObject* parent)
: QObject(parent)
, _name(name)
, _settingsGroup(settingsGroup)
, _visible(qgcApp()->toolbox()->corePlugin()->overrideSettingsGroupVisibility(name))
{
QString jsonNameFormat(":/json/%1.SettingsGroup.json");
_nameToMetaDataMap = FactMetaData::createMapFromJsonFile(jsonNameFormat.arg(name), this);
}
SettingsFact* SettingsGroup::_createSettingsFact(const QString& name)
{
return new SettingsFact(_settingsGroup, _nameToMetaDataMap[name], this);
}
VideoSettings::VideoSettings(QObject* parent)
: SettingsGroup(videoSettingsGroupName, QString() , parent)
const char* VideoSettings::videoSettingsGroupName = "Video";
SettingsFact::SettingsFact(QString settingGroup, FactMetaData* metaData, QObject* parent)
: Fact(0, metaData->name(), metaData->type(), parent)
, _settingGroup(settingGroup)
, _visible(true)
{
QSettings settings;
if (!_settingGroup.isEmpty()) {
settings.beginGroup(_settingGroup);
}
_visible = qgcApp()->toolbox()->corePlugin()->adjustSettingMetaData(*metaData);
setMetaData(metaData);
QVariant rawDefaultValue = metaData->rawDefaultValue();
if (_visible) {
QVariant typedValue;
QString errorString;
metaData->convertAndValidateRaw(settings.value(_name, rawDefaultValue), true , typedValue, errorString);
_rawValue = typedValue;
} else {
settings.setValue(_name, rawDefaultValue);
_rawValue = rawDefaultValue;
}
connect(this, &Fact::rawValueChanged, this, &SettingsFact::_rawValueChanged);
}
const char* FactMetaData::_decimalPlacesJsonKey = "decimalPlaces";
const char* FactMetaData::_nameJsonKey = "name";
const char* FactMetaData::_typeJsonKey = "type";
const char* FactMetaData::_shortDescriptionJsonKey = "shortDescription";
const char* FactMetaData::_longDescriptionJsonKey = "longDescription";
const char* FactMetaData::_unitsJsonKey = "units";
const char* FactMetaData::_defaultValueJsonKey = "defaultValue";
const char* FactMetaData::_mobileDefaultValueJsonKey = "mobileDefaultValue";
const char* FactMetaData::_minJsonKey = "min";
const char* FactMetaData::_maxJsonKey = "max";
const char* FactMetaData::_hasControlJsonKey = "control";
三、ParameterEditorDialog.qml对话框
function accept() {
if (bitmaskColumn.visible && !manualEntry.checked) {
fact.value = bitmaskValue();
fact.valueChanged(fact.value)
hideDialog();
} else if (factCombo.visible && !manualEntry.checked) {
fact.enumIndex = factCombo.currentIndex
hideDialog()
} else {
var errorString = fact.validate(valueField.text, forceSave.checked)
if (errorString === "") {
fact.value = valueField.text
fact.valueChanged(fact.value)
hideDialog()
} else {
validationError.text = errorString
if (_allowForceSave) {
forceSave.visible = true
}
}
}
}
function reject() {
fact.valueChanged(fact.value)
hideDialog();
}
|