Unverified Commit 17e713b5 authored by Don Gagne's avatar Don Gagne Committed by GitHub

Merge pull request #9009 from DonLakeFlyer/ValueGridTwitch

Fly: Less twitchy value grid width sizing
parents 76b58cbc 1313a698
...@@ -670,7 +670,6 @@ HEADERS += \ ...@@ -670,7 +670,6 @@ HEADERS += \
src/QmlControls/TerrainProfile.h \ src/QmlControls/TerrainProfile.h \
src/QmlControls/ToolStripAction.h \ src/QmlControls/ToolStripAction.h \
src/QmlControls/ToolStripActionList.h \ src/QmlControls/ToolStripActionList.h \
src/QmlControls/VerticalFactValueGrid.h \
src/QtLocationPlugin/QMLControl/QGCMapEngineManager.h \ src/QtLocationPlugin/QMLControl/QGCMapEngineManager.h \
src/Settings/ADSBVehicleManagerSettings.h \ src/Settings/ADSBVehicleManagerSettings.h \
src/Settings/AppSettings.h \ src/Settings/AppSettings.h \
...@@ -890,7 +889,6 @@ SOURCES += \ ...@@ -890,7 +889,6 @@ SOURCES += \
src/QmlControls/TerrainProfile.cc \ src/QmlControls/TerrainProfile.cc \
src/QmlControls/ToolStripAction.cc \ src/QmlControls/ToolStripAction.cc \
src/QmlControls/ToolStripActionList.cc \ src/QmlControls/ToolStripActionList.cc \
src/QmlControls/VerticalFactValueGrid.cc \
src/QtLocationPlugin/QMLControl/QGCMapEngineManager.cc \ src/QtLocationPlugin/QMLControl/QGCMapEngineManager.cc \
src/Settings/ADSBVehicleManagerSettings.cc \ src/Settings/ADSBVehicleManagerSettings.cc \
src/Settings/AppSettings.cc \ src/Settings/AppSettings.cc \
......
...@@ -183,7 +183,6 @@ ...@@ -183,7 +183,6 @@
<file alias="QGroundControl/Controls/TransectStyleComplexItemTerrainFollow.qml">src/PlanView/TransectStyleComplexItemTerrainFollow.qml</file> <file alias="QGroundControl/Controls/TransectStyleComplexItemTerrainFollow.qml">src/PlanView/TransectStyleComplexItemTerrainFollow.qml</file>
<file alias="QGroundControl/Controls/VehicleRotationCal.qml">src/QmlControls/VehicleRotationCal.qml</file> <file alias="QGroundControl/Controls/VehicleRotationCal.qml">src/QmlControls/VehicleRotationCal.qml</file>
<file alias="QGroundControl/Controls/VehicleSummaryRow.qml">src/QmlControls/VehicleSummaryRow.qml</file> <file alias="QGroundControl/Controls/VehicleSummaryRow.qml">src/QmlControls/VehicleSummaryRow.qml</file>
<file alias="QGroundControl/Controls/VerticalFactValueGrid.qml">src/QmlControls/VerticalFactValueGrid.qml</file>
<file alias="QGroundControl/Controls/VTOLLandingPatternMapVisual.qml">src/PlanView/VTOLLandingPatternMapVisual.qml</file> <file alias="QGroundControl/Controls/VTOLLandingPatternMapVisual.qml">src/PlanView/VTOLLandingPatternMapVisual.qml</file>
<file alias="QGroundControl/FactControls/AltitudeFactTextField.qml">src/FactSystem/FactControls/AltitudeFactTextField.qml</file> <file alias="QGroundControl/FactControls/AltitudeFactTextField.qml">src/FactSystem/FactControls/AltitudeFactTextField.qml</file>
<file alias="QGroundControl/FactControls/FactBitmask.qml">src/FactSystem/FactControls/FactBitmask.qml</file> <file alias="QGroundControl/FactControls/FactBitmask.qml">src/FactSystem/FactControls/FactBitmask.qml</file>
......
...@@ -77,7 +77,6 @@ ...@@ -77,7 +77,6 @@
#include "MAVLinkInspectorController.h" #include "MAVLinkInspectorController.h"
#endif #endif
#include "HorizontalFactValueGrid.h" #include "HorizontalFactValueGrid.h"
#include "VerticalFactValueGrid.h"
#include "InstrumentValueData.h" #include "InstrumentValueData.h"
#include "AppMessages.h" #include "AppMessages.h"
#include "SimulatedPosition.h" #include "SimulatedPosition.h"
...@@ -553,7 +552,6 @@ void QGCApplication::_initCommon() ...@@ -553,7 +552,6 @@ void QGCApplication::_initCommon()
qmlRegisterUncreatableType<FactValueGrid> (kQGCTemplates, 1, 0, "FactValueGrid", kRefOnly); qmlRegisterUncreatableType<FactValueGrid> (kQGCTemplates, 1, 0, "FactValueGrid", kRefOnly);
qmlRegisterType<HorizontalFactValueGrid> (kQGCTemplates, 1, 0, "HorizontalFactValueGrid"); qmlRegisterType<HorizontalFactValueGrid> (kQGCTemplates, 1, 0, "HorizontalFactValueGrid");
qmlRegisterType<VerticalFactValueGrid> (kQGCTemplates, 1, 0, "VerticalFactValueGrid");
qmlRegisterType<QGCMapCircle> ("QGroundControl.FlightMap", 1, 0, "QGCMapCircle"); qmlRegisterType<QGCMapCircle> ("QGroundControl.FlightMap", 1, 0, "QGCMapCircle");
......
...@@ -15,9 +15,7 @@ ...@@ -15,9 +15,7 @@
#include <QSettings> #include <QSettings>
const char* FactValueGrid::_rowsKey = "rows"; const char* FactValueGrid::_rowsKey = "rows";
const char* FactValueGrid::_columnsKey = "columns";
const char* FactValueGrid::_fontSizeKey = "fontSize"; const char* FactValueGrid::_fontSizeKey = "fontSize";
const char* FactValueGrid::_orientationKey = "orientation";
const char* FactValueGrid::_versionKey = "version"; const char* FactValueGrid::_versionKey = "version";
const char* FactValueGrid::_factGroupNameKey = "groupName"; const char* FactValueGrid::_factGroupNameKey = "groupName";
const char* FactValueGrid::_factNameKey = "factName"; const char* FactValueGrid::_factNameKey = "factName";
...@@ -44,7 +42,7 @@ const QStringList FactValueGrid::_fontSizeNames = { ...@@ -44,7 +42,7 @@ const QStringList FactValueGrid::_fontSizeNames = {
FactValueGrid::FactValueGrid(QQuickItem* parent) FactValueGrid::FactValueGrid(QQuickItem* parent)
: QQuickItem(parent) : QQuickItem(parent)
, _rows (new QmlObjectListModel(this)) , _columns (new QmlObjectListModel(this))
{ {
if (_iconNames.isEmpty()) { if (_iconNames.isEmpty()) {
QDir iconDir(":/InstrumentValueIcons/"); QDir iconDir(":/InstrumentValueIcons/");
...@@ -57,7 +55,7 @@ FactValueGrid::FactValueGrid(QQuickItem* parent) ...@@ -57,7 +55,7 @@ FactValueGrid::FactValueGrid(QQuickItem* parent)
FactValueGrid::FactValueGrid(const QString& defaultSettingsGroup) FactValueGrid::FactValueGrid(const QString& defaultSettingsGroup)
: QQuickItem (nullptr) : QQuickItem (nullptr)
, _defaultSettingsGroup (defaultSettingsGroup) , _defaultSettingsGroup (defaultSettingsGroup)
, _rows (new QmlObjectListModel(this)) , _columns (new QmlObjectListModel(this))
{ {
_init(); _init();
} }
...@@ -189,46 +187,46 @@ void FactValueGrid::_connectSaveSignals(InstrumentValueData* value) ...@@ -189,46 +187,46 @@ void FactValueGrid::_connectSaveSignals(InstrumentValueData* value)
connect(value, &InstrumentValueData::rangeIconsChanged, this, &FactValueGrid::_saveSettings); connect(value, &InstrumentValueData::rangeIconsChanged, this, &FactValueGrid::_saveSettings);
} }
void FactValueGrid::appendColumn(void) void FactValueGrid::appendRow(void)
{ {
for (int rowIndex=0; rowIndex<_rows->count(); rowIndex++) { for (int colIndex=0; colIndex<_columns->count(); colIndex++) {
QmlObjectListModel* list = _rows->value<QmlObjectListModel*>(rowIndex); QmlObjectListModel* list = _columns->value<QmlObjectListModel*>(colIndex);
list->append(_createNewInstrumentValueWorker(list)); list->append(_createNewInstrumentValueWorker(list));
} }
_columnCount++; _rowCount++;
emit columnCountChanged(_columnCount); emit rowCountChanged(_rowCount);
_saveSettings(); _saveSettings();
} }
void FactValueGrid::deleteLastColumn(void) void FactValueGrid::deleteLastRow(void)
{ {
if (_columnCount <= 1) { if (_rowCount <= 1) {
return; return;
} }
for (int rowIndex=0; rowIndex<_rows->count(); rowIndex++) { for (int colIndex=0; colIndex<_columns->count(); colIndex++) {
QmlObjectListModel* list = _rows->value<QmlObjectListModel*>(rowIndex); QmlObjectListModel* list = _columns->value<QmlObjectListModel*>(colIndex);
list->removeAt(list->count() - 1)->deleteLater(); list->removeAt(list->count() - 1)->deleteLater();
} }
_columnCount--; _rowCount--;
emit columnCountChanged(_columnCount); emit rowCountChanged(_rowCount);
_saveSettings(); _saveSettings();
} }
QmlObjectListModel* FactValueGrid::appendRow(void) QmlObjectListModel* FactValueGrid::appendColumn(void)
{ {
QmlObjectListModel* newList = new QmlObjectListModel(_rows); QmlObjectListModel* newList = new QmlObjectListModel(_columns);
_rows->append(newList); _columns->append(newList);
// If this is the first row then we automatically add the first column as well // If this is the first row then we automatically add the first column as well
int cColsToAdd = qMax(_columnCount, 1); int cRowsToAdd = qMax(_rowCount, 1);
for (int i=0; i<cColsToAdd; i++) { for (int i=0; i<cRowsToAdd; i++) {
newList->append(_createNewInstrumentValueWorker(newList)); newList->append(_createNewInstrumentValueWorker(newList));
} }
if (cColsToAdd != _columnCount) { if (cRowsToAdd != _rowCount) {
_columnCount = cColsToAdd; _rowCount = cRowsToAdd;
emit columnCountChanged(_columnCount); emit rowCountChanged(_rowCount);
} }
_saveSettings(); _saveSettings();
...@@ -236,10 +234,10 @@ QmlObjectListModel* FactValueGrid::appendRow(void) ...@@ -236,10 +234,10 @@ QmlObjectListModel* FactValueGrid::appendRow(void)
return newList; return newList;
} }
void FactValueGrid::deleteLastRow(void) void FactValueGrid::deleteLastColumn(void)
{ {
if (_rows->count() > 1) { if (_columns->count() > 1) {
_rows->removeAt(_rows->count() - 1)->deleteLater(); _columns->removeAt(_columns->count() - 1)->deleteLater();
} }
} }
...@@ -272,17 +270,16 @@ void FactValueGrid::_saveSettings(void) ...@@ -272,17 +270,16 @@ void FactValueGrid::_saveSettings(void)
settings.remove(""); // Remove any previous settings settings.remove(""); // Remove any previous settings
settings.setValue(_versionKey, 1); settings.setValue(_versionKey, 1);
settings.setValue(_fontSizeKey, _fontSize); settings.setValue(_fontSizeKey, _fontSize);
settings.setValue(_orientationKey, _orientation); settings.setValue(_rowsKey, _rowCount);
settings.setValue(_columnsKey, _columnCount);
settings.beginWriteArray(_rowsKey); settings.beginWriteArray(_rowsKey);
for (int rowIndex=0; rowIndex<_rows->count(); rowIndex++) { for (int colIndex=0; colIndex<_columns->count(); colIndex++) {
QmlObjectListModel* columns = _rows->value<QmlObjectListModel*>(rowIndex); QmlObjectListModel* columns = _columns->value<QmlObjectListModel*>(colIndex);
settings.setArrayIndex(rowIndex); settings.setArrayIndex(colIndex);
settings.beginWriteArray(_columnsKey); settings.beginWriteArray(_rowsKey);
for (int colIndex=0; colIndex<columns->count(); colIndex++) { for (int colIndex=0; colIndex<columns->count(); colIndex++) {
InstrumentValueData* value = columns->value<InstrumentValueData*>(colIndex); InstrumentValueData* value = columns->value<InstrumentValueData*>(colIndex);
...@@ -299,10 +296,10 @@ void FactValueGrid::_loadSettings(void) ...@@ -299,10 +296,10 @@ void FactValueGrid::_loadSettings(void)
{ {
_preventSaveSettings = true; _preventSaveSettings = true;
_rows->deleteLater(); _columns->deleteLater();
_rows = new QmlObjectListModel(this); _columns = new QmlObjectListModel(this);
_columnCount = 0; _rowCount = 0;
QSettings settings; QSettings settings;
QString groupNameFormat("%1-%2"); QString groupNameFormat("%1-%2");
...@@ -325,27 +322,26 @@ void FactValueGrid::_loadSettings(void) ...@@ -325,27 +322,26 @@ void FactValueGrid::_loadSettings(void)
qgcApp()->toolbox()->corePlugin()->factValueGridCreateDefaultSettings(_defaultSettingsGroup); qgcApp()->toolbox()->corePlugin()->factValueGridCreateDefaultSettings(_defaultSettingsGroup);
} }
_fontSize = settings.value(_fontSizeKey, DefaultFontSize).value<FontSize>(); _fontSize = settings.value(_fontSizeKey, DefaultFontSize).value<FontSize>();
_orientation = settings.value(_orientationKey, VerticalOrientation).value<Orientation>();
// Initial setup of empty items // Initial setup of empty items
int cColumns = settings.value(_columnsKey).toInt(); int cColumns = settings.value(_rowsKey).toInt();
int cModelLists = settings.beginReadArray(_rowsKey); int cModelLists = settings.beginReadArray(_rowsKey);
if (cModelLists && cColumns) { if (cModelLists && cColumns) {
appendRow(); appendColumn();
for (int itemIndex=1; itemIndex<cColumns; itemIndex++) { for (int itemIndex=1; itemIndex<cColumns; itemIndex++) {
appendColumn();
}
for (int rowIndex=1; rowIndex<cModelLists; rowIndex++) {
appendRow(); appendRow();
} }
for (int colIndex=1; colIndex<cModelLists; colIndex++) {
appendColumn();
}
} }
// Fill in the items from settings // Fill in the items from settings
for (int rowIndex=0; rowIndex<cModelLists; rowIndex++) { for (int colIndex=0; colIndex<cModelLists; colIndex++) {
settings.setArrayIndex(rowIndex); settings.setArrayIndex(colIndex);
int cItems = settings.beginReadArray(_columnsKey); int cItems = settings.beginReadArray(_rowsKey);
for (int itemIndex=0; itemIndex<cItems; itemIndex++) { for (int itemIndex=0; itemIndex<cItems; itemIndex++) {
QmlObjectListModel* list = _rows->value<QmlObjectListModel*>(rowIndex); QmlObjectListModel* list = _columns->value<QmlObjectListModel*>(colIndex);
InstrumentValueData* value = list->value<InstrumentValueData*>(itemIndex); InstrumentValueData* value = list->value<InstrumentValueData*>(itemIndex);
settings.setArrayIndex(itemIndex); settings.setArrayIndex(itemIndex);
_loadValueData(settings, value); _loadValueData(settings, value);
...@@ -354,7 +350,7 @@ void FactValueGrid::_loadSettings(void) ...@@ -354,7 +350,7 @@ void FactValueGrid::_loadSettings(void)
} }
settings.endArray(); settings.endArray();
emit rowsChanged(_rows); emit columnsChanged(_columns);
_preventSaveSettings = false; _preventSaveSettings = false;
} }
...@@ -26,12 +26,6 @@ public: ...@@ -26,12 +26,6 @@ public:
FactValueGrid(QQuickItem *parent = nullptr); FactValueGrid(QQuickItem *parent = nullptr);
FactValueGrid(const QString& defaultSettingsGroup); FactValueGrid(const QString& defaultSettingsGroup);
enum Orientation {
HorizontalOrientation=0, // Labels will be to the left of the value
VerticalOrientation // Labels will be above the value
};
Q_ENUMS(Orientation)
enum FontSize { enum FontSize {
DefaultFontSize=0, DefaultFontSize=0,
SmallFontSize, SmallFontSize,
...@@ -50,22 +44,21 @@ public: ...@@ -50,22 +44,21 @@ public:
// The combination of the two valuePage*SettingsGroup values allows each FactValueGrid to have it's own persistence space. // The combination of the two valuePage*SettingsGroup values allows each FactValueGrid to have it's own persistence space.
Q_PROPERTY(QmlObjectListModel* rows MEMBER _rows NOTIFY rowsChanged) Q_PROPERTY(QmlObjectListModel* columns MEMBER _columns NOTIFY columnsChanged)
Q_PROPERTY(int columnCount MEMBER _columnCount NOTIFY columnCountChanged) Q_PROPERTY(int rowCount MEMBER _rowCount NOTIFY rowCountChanged)
Q_PROPERTY(QString userSettingsGroup MEMBER _userSettingsGroup NOTIFY userSettingsGroupChanged) Q_PROPERTY(QString userSettingsGroup MEMBER _userSettingsGroup NOTIFY userSettingsGroupChanged)
Q_PROPERTY(QString defaultSettingsGroup MEMBER _defaultSettingsGroup NOTIFY defaultSettingsGroupChanged) Q_PROPERTY(QString defaultSettingsGroup MEMBER _defaultSettingsGroup NOTIFY defaultSettingsGroupChanged)
Q_PROPERTY(Orientation orientation MEMBER _orientation CONSTANT)
Q_PROPERTY(QStringList iconNames READ iconNames CONSTANT) Q_PROPERTY(QStringList iconNames READ iconNames CONSTANT)
Q_PROPERTY(FontSize fontSize READ fontSize WRITE setFontSize NOTIFY fontSizeChanged) Q_PROPERTY(FontSize fontSize READ fontSize WRITE setFontSize NOTIFY fontSizeChanged)
Q_PROPERTY(QStringList fontSizeNames MEMBER _fontSizeNames CONSTANT) Q_PROPERTY(QStringList fontSizeNames MEMBER _fontSizeNames CONSTANT)
Q_INVOKABLE void resetToDefaults (void); Q_INVOKABLE void resetToDefaults (void);
Q_INVOKABLE QmlObjectListModel* appendRow (void); Q_INVOKABLE QmlObjectListModel* appendColumn (void);
Q_INVOKABLE void deleteLastRow (void); Q_INVOKABLE void deleteLastColumn(void);
Q_INVOKABLE void appendColumn (void); Q_INVOKABLE void appendRow (void);
Q_INVOKABLE void deleteLastColumn (void); Q_INVOKABLE void deleteLastRow (void);
QmlObjectListModel* rows (void) const { return _rows; } QmlObjectListModel* columns (void) const { return _columns; }
FontSize fontSize (void) const { return _fontSize; } FontSize fontSize (void) const { return _fontSize; }
QStringList iconNames (void) const { return _iconNames; } QStringList iconNames (void) const { return _iconNames; }
QGCMAVLink::VehicleClass_t vehicleClass(void) const { return _vehicleClass; } QGCMAVLink::VehicleClass_t vehicleClass(void) const { return _vehicleClass; }
...@@ -79,8 +72,8 @@ signals: ...@@ -79,8 +72,8 @@ signals:
void userSettingsGroupChanged (const QString& userSettingsGroup); void userSettingsGroupChanged (const QString& userSettingsGroup);
void defaultSettingsGroupChanged(const QString& defaultSettingsGroup); void defaultSettingsGroupChanged(const QString& defaultSettingsGroup);
void fontSizeChanged (FontSize fontSize); void fontSizeChanged (FontSize fontSize);
void rowsChanged (QmlObjectListModel* model); void columnsChanged (QmlObjectListModel* model);
void columnCountChanged (int columnCount); void rowCountChanged (int rowCount);
protected: protected:
Q_DISABLE_COPY(FactValueGrid) Q_DISABLE_COPY(FactValueGrid)
...@@ -88,11 +81,10 @@ protected: ...@@ -88,11 +81,10 @@ protected:
QGCMAVLink::VehicleClass_t _vehicleClass = QGCMAVLink::VehicleClassGeneric; QGCMAVLink::VehicleClass_t _vehicleClass = QGCMAVLink::VehicleClassGeneric;
QString _defaultSettingsGroup; // Settings group to read from if the user has not modified from the default settings QString _defaultSettingsGroup; // Settings group to read from if the user has not modified from the default settings
QString _userSettingsGroup; // Settings group to read from for user modified settings QString _userSettingsGroup; // Settings group to read from for user modified settings
Orientation _orientation = VerticalOrientation;
FontSize _fontSize = DefaultFontSize; FontSize _fontSize = DefaultFontSize;
bool _preventSaveSettings = false; bool _preventSaveSettings = false;
QmlObjectListModel* _rows = nullptr; QmlObjectListModel* _columns = nullptr;
int _columnCount = 0; int _rowCount = 0;
private slots: private slots:
void _offlineVehicleTypeChanged(void); void _offlineVehicleTypeChanged(void);
...@@ -113,8 +105,6 @@ private: ...@@ -113,8 +105,6 @@ private:
static const char* _versionKey; static const char* _versionKey;
static const char* _rowsKey; static const char* _rowsKey;
static const char* _columnsKey;
static const char* _orientationKey;
static const char* _fontSizeKey; static const char* _fontSizeKey;
static const char* _factGroupNameKey; static const char* _factGroupNameKey;
static const char* _factNameKey; static const char* _factNameKey;
...@@ -133,4 +123,3 @@ private: ...@@ -133,4 +123,3 @@ private:
QML_DECLARE_TYPE(FactValueGrid) QML_DECLARE_TYPE(FactValueGrid)
Q_DECLARE_METATYPE(FactValueGrid::FontSize) Q_DECLARE_METATYPE(FactValueGrid::FontSize)
Q_DECLARE_METATYPE(FactValueGrid::Orientation)
...@@ -14,17 +14,17 @@ ...@@ -14,17 +14,17 @@
#include <QSettings> #include <QSettings>
const QString HorizontalFactValueGrid::_toolbarUserSettingsGroup ("TelemetryBarUserSettingsWIP0"); const QString HorizontalFactValueGrid::_toolbarUserSettingsGroup ("TelemetryBarUserSettingsWIP01");
const QString HorizontalFactValueGrid::telemetryBarDefaultSettingsGroup ("TelemetryBarDefaultSettingsWIP0"); const QString HorizontalFactValueGrid::telemetryBarDefaultSettingsGroup ("TelemetryBarDefaultSettingsWIP01");
HorizontalFactValueGrid::HorizontalFactValueGrid(QQuickItem* parent) HorizontalFactValueGrid::HorizontalFactValueGrid(QQuickItem* parent)
: FactValueGrid(parent) : FactValueGrid(parent)
{ {
_orientation = HorizontalOrientation;
} }
HorizontalFactValueGrid::HorizontalFactValueGrid(const QString& defaultSettingsGroup) HorizontalFactValueGrid::HorizontalFactValueGrid(const QString& defaultSettingsGroup)
: FactValueGrid(defaultSettingsGroup) : FactValueGrid(defaultSettingsGroup)
{ {
_orientation = HorizontalOrientation;
} }
...@@ -71,11 +71,11 @@ T.HorizontalFactValueGrid { ...@@ -71,11 +71,11 @@ T.HorizontalFactValueGrid {
GridLayout { GridLayout {
id: valueGrid id: valueGrid
rows: _root.rows.count rows: _root.columns.count
rowSpacing: 0 rowSpacing: 0
Repeater { Repeater {
model: _root.rows model: _root.columns
Repeater { Repeater {
id: labelRepeater id: labelRepeater
...@@ -84,8 +84,8 @@ T.HorizontalFactValueGrid { ...@@ -84,8 +84,8 @@ T.HorizontalFactValueGrid {
property real _index: index property real _index: index
InstrumentValueLabel { InstrumentValueLabel {
Layout.row: labelRepeater._index Layout.row: index
Layout.column: index * 3 Layout.column: labelRepeater._index * 3
Layout.fillHeight: true Layout.fillHeight: true
Layout.alignment: Qt.AlignRight Layout.alignment: Qt.AlignRight
instrumentValueData: object instrumentValueData: object
...@@ -94,26 +94,55 @@ T.HorizontalFactValueGrid { ...@@ -94,26 +94,55 @@ T.HorizontalFactValueGrid {
} }
Repeater { Repeater {
model: _root.rows model: _root.columns
Repeater { Repeater {
id: valueRepeater id: valueRepeater
model: object model: object
property real _index: index property real _index: index
property real maxWidth: 0
property var lastCheck: new Date().getTime()
function recalcWidth() {
var newMaxWidth = 0
for (var i=0; i<valueRepeater.count; i++) {
newMaxWidth = Math.max(newMaxWidth, valueRepeater.itemAt(0).contentWidth)
}
console.log("recalcWidth", newMaxWidth, maxWidth)
maxWidth = Math.min(maxWidth, newMaxWidth)
}
InstrumentValueValue { InstrumentValueValue {
Layout.row: valueRepeater._index Layout.row: index
Layout.column: (index * 3) + 1 Layout.column: (valueRepeater._index * 3) + 1
Layout.fillHeight: true Layout.fillHeight: true
Layout.alignment: Qt.AlignLeft Layout.alignment: Qt.AlignLeft
Layout.preferredWidth: maxWidth
instrumentValueData: object instrumentValueData: object
property real lastContentWidth
Component.onCompleted: {
maxWidth = Math.max(maxWidth, contentWidth)
lastContentWidth = contentWidth
}
onContentWidthChanged: {
maxWidth = Math.max(maxWidth, contentWidth)
lastContentWidth = contentWidth
var currentTime = new Date().getTime()
if (currentTime - lastCheck > 30 * 1000) {
lastCheck = currentTime
valueRepeater.recalcWidth()
}
}
} }
} }
} }
Repeater { Repeater {
model: _root.rows model: _root.columns
Repeater { Repeater {
id: spacerRepeater id: spacerRepeater
...@@ -122,8 +151,8 @@ T.HorizontalFactValueGrid { ...@@ -122,8 +151,8 @@ T.HorizontalFactValueGrid {
property real _index: index property real _index: index
Item { Item {
Layout.row: spacerRepeater._index Layout.row: index
Layout.column: (index * 3) + 2 Layout.column: (spacerRepeater._index * 3) + 2
Layout.preferredWidth: ScreenTools.defaultFontPixelWidth Layout.preferredWidth: ScreenTools.defaultFontPixelWidth
Layout.preferredHeight: 1 Layout.preferredHeight: 1
} }
...@@ -150,7 +179,7 @@ T.HorizontalFactValueGrid { ...@@ -150,7 +179,7 @@ T.HorizontalFactValueGrid {
Layout.fillWidth: true Layout.fillWidth: true
Layout.preferredHeight: parent.height Layout.preferredHeight: parent.height
text: qsTr("-") text: qsTr("-")
enabled: _root.rows.count > 1 enabled: _root.rowCount > 1
onClicked: deleteLastRow() onClicked: deleteLastRow()
} }
} }
...@@ -177,7 +206,7 @@ T.HorizontalFactValueGrid { ...@@ -177,7 +206,7 @@ T.HorizontalFactValueGrid {
Layout.preferredHeight: ScreenTools.minTouchPixels Layout.preferredHeight: ScreenTools.minTouchPixels
Layout.preferredWidth: parent.width Layout.preferredWidth: parent.width
text: qsTr("-") text: qsTr("-")
enabled: _root.columnCount > 1 enabled: _root.columns.count > 1
onClicked: deleteLastColumn() onClicked: deleteLastColumn()
} }
} }
......
...@@ -21,6 +21,7 @@ import QGroundControl.Palette 1.0 ...@@ -21,6 +21,7 @@ import QGroundControl.Palette 1.0
ColumnLayout { ColumnLayout {
property var instrumentValueData: null property var instrumentValueData: null
property bool settingsUnlocked: false property bool settingsUnlocked: false
property alias contentWidth: label.contentWidth
property bool _verticalOrientation: instrumentValueData.factValueGrid.orientation === FactValueGrid.VerticalOrientation property bool _verticalOrientation: instrumentValueData.factValueGrid.orientation === FactValueGrid.VerticalOrientation
property var _rgFontSizes: [ ScreenTools.defaultFontPointSize, ScreenTools.smallFontPointSize, ScreenTools.mediumFontPointSize, ScreenTools.largeFontPointSize ] property var _rgFontSizes: [ ScreenTools.defaultFontPointSize, ScreenTools.smallFontPointSize, ScreenTools.mediumFontPointSize, ScreenTools.largeFontPointSize ]
...@@ -36,6 +37,7 @@ ColumnLayout { ...@@ -36,6 +37,7 @@ ColumnLayout {
property real _height: 0 property real _height: 0
QGCLabel { QGCLabel {
id: label
Layout.alignment: _verticalOrientation ? Qt.AlignHCenter : Qt.AlignVCenter Layout.alignment: _verticalOrientation ? Qt.AlignHCenter : Qt.AlignVCenter
font.pointSize: _fontSize font.pointSize: _fontSize
text: instrumentValueData.fact.enumOrValueString + (instrumentValueData.showUnits ? " " + instrumentValueData.fact.units : "") text: instrumentValueData.fact.enumOrValueString + (instrumentValueData.showUnits ? " " + instrumentValueData.fact.units : "")
......
...@@ -107,6 +107,5 @@ TransectStyleMapVisuals 1.0 TransectStyleMapVisuals.qml ...@@ -107,6 +107,5 @@ TransectStyleMapVisuals 1.0 TransectStyleMapVisuals.qml
ToolStrip 1.0 ToolStrip.qml ToolStrip 1.0 ToolStrip.qml
VehicleRotationCal 1.0 VehicleRotationCal.qml VehicleRotationCal 1.0 VehicleRotationCal.qml
VehicleSummaryRow 1.0 VehicleSummaryRow.qml VehicleSummaryRow 1.0 VehicleSummaryRow.qml
VerticalFactValueGrid 1.0 VerticalFactValueGrid.qml
QGCHoverButton 1.0 QGCHoverButton.qml QGCHoverButton 1.0 QGCHoverButton.qml
MAVLinkChart 1.0 MAVLinkChart.qml MAVLinkChart 1.0 MAVLinkChart.qml
/****************************************************************************
*
* (c) 2009-2020 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
*
* QGroundControl is licensed according to the terms in the file
* COPYING.md in the root of the source code directory.
*
****************************************************************************/
#include "VerticalFactValueGrid.h"
#include "InstrumentValueData.h"
#include "QGCApplication.h"
#include "QGCCorePlugin.h"
#include <QSettings>
const QString VerticalFactValueGrid::_valuePageUserSettingsGroup ("ValuePageUserSettings2");
const QString VerticalFactValueGrid::valuePageDefaultSettingsGroup("ValuePageDefaultSettings2");
VerticalFactValueGrid::VerticalFactValueGrid(QQuickItem* parent)
: FactValueGrid(parent)
{
_orientation = VerticalOrientation;
}
VerticalFactValueGrid::VerticalFactValueGrid(const QString& defaultSettingsGroup)
: FactValueGrid(defaultSettingsGroup)
{
_orientation = VerticalOrientation;
}
/****************************************************************************
*
* (c) 2009-2020 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
*
* QGroundControl is licensed according to the terms in the file
* COPYING.md in the root of the source code directory.
*
****************************************************************************/
#pragma once
#include "FactSystem.h"
#include "QmlObjectListModel.h"
#include "QGCApplication.h"
#include "FactValueGrid.h"
class InstrumentValueData;
class VerticalFactValueGrid : public FactValueGrid
{
Q_OBJECT
public:
VerticalFactValueGrid(QQuickItem *parent = nullptr);
VerticalFactValueGrid(const QString& defaultSettingsGroup);
Q_PROPERTY(QString valuePageDefaultSettingsGroup MEMBER valuePageDefaultSettingsGroup CONSTANT)
Q_PROPERTY(QString valuePageUserSettingsGroup MEMBER _valuePageUserSettingsGroup CONSTANT)
static const QString valuePageDefaultSettingsGroup;
private:
Q_DISABLE_COPY(VerticalFactValueGrid)
static const QString _valuePageUserSettingsGroup;
};
QML_DECLARE_TYPE(VerticalFactValueGrid)
/****************************************************************************
*
* (c) 2009-2020 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
*
* QGroundControl is licensed according to the terms in the file
* COPYING.md in the root of the source code directory.
*
****************************************************************************/
import QtQuick 2.12
import QtQuick.Layouts 1.2
import QtQuick.Controls 2.5
import QtQml 2.12
import QGroundControl.Templates 1.0 as T
import QGroundControl.Controls 1.0
import QGroundControl.ScreenTools 1.0
import QGroundControl.Controllers 1.0
import QGroundControl.Palette 1.0
import QGroundControl.FlightMap 1.0
import QGroundControl 1.0
// Note: This control will spit out qWarnings like this: "QGridLayoutEngine::addItem: Cell (0, 1) already taken"
// This is due to Qt bug https://bugreports.qt.io/browse/QTBUG-65121
// If this becomes a problem I'll implement our own grid layout control
T.VerticalFactValueGrid {
id: _root
height: childrenRect.height
property bool settingsUnlocked: false
QGCPalette { id: qgcPal; colorGroupEnabled: enabled }
QGCFlickable {
width: parent.width
height: topLevelRowLayout.height
flickableDirection: QGCFlickable.HorizontalFlick
contentWidth: topLevelRowLayout.width
RowLayout {
id: topLevelRowLayout
spacing: 0
ColumnLayout {
spacing: 0
GridLayout {
id: valueGrid
Layout.minimumWidth: _root.width - (columnButtons.visible? columnButtons.width + columnSpacing : 0)
rows: _root.rows.count * 2
rowSpacing: 0
columnSpacing: 5
Repeater {
model: _root.rows
Repeater {
id: labelRepeater
model: object
property real _index: index
InstrumentValueLabel {
Layout.row: labelRepeater._index * 2
Layout.column: index
Layout.fillWidth: true
Layout.alignment: Qt.AlignHCenter
instrumentValueData: object
}
}
}
Repeater {
model: _root.rows
Repeater {
id: valueRepeater
model: object
property real _index: index
InstrumentValueValue {
Layout.row: valueRepeater._index * 2 + 1
Layout.column: index
Layout.fillWidth: true
Layout.alignment: Qt.AlignHCenter
instrumentValueData: object
}
}
}
}
RowLayout {
id: rowButtons
height: ScreenTools.minTouchPixels / 2
Layout.fillWidth: true
spacing: 1
visible: settingsUnlocked
QGCButton {
Layout.fillWidth: true
Layout.preferredHeight: parent.height
text: qsTr("+")
onClicked: appendRow()
}
QGCButton {
Layout.fillWidth: true
Layout.preferredHeight: parent.height
text: qsTr("-")
enabled: _root.rows.count > 1
onClicked: deleteLastRow()
}
}
}
ColumnLayout {
id: columnButtons
Layout.fillHeight: true
Layout.bottomMargin: rowButtons.height
width: ScreenTools.minTouchPixels / 2
spacing: 1
visible: settingsUnlocked
QGCButton {
Layout.fillHeight: true
Layout.preferredHeight: ScreenTools.minTouchPixels
Layout.preferredWidth: parent.width
text: qsTr("+")
onClicked: appendColumn()
}
QGCButton {
Layout.fillHeight: true
Layout.preferredHeight: ScreenTools.minTouchPixels
Layout.preferredWidth: parent.width
text: qsTr("-")
enabled: _root.columnCount > 1
onClicked: deleteLastColumn()
}
}
}
QGCMouseArea {
x: valueGrid.x
y: valueGrid.y
width: valueGrid.width
height: valueGrid.height
visible: settingsUnlocked
onClicked: {
var item = valueGrid.childAt(mouse.x, mouse.y)
//console.log(item, item ? item.instrumentValueData : "null", item && item.parent ? item.parent.instrumentValueData : "null")
if (item && item.instrumentValueData !== undefined) {
mainWindow.showPopupDialogFromComponent(valueEditDialog, { instrumentValueData: item.instrumentValueData })
}
}
/*Rectangle {
anchors.fill: parent
border.color: "green"
border.width: 1
color: "transparent"
}*/
}
}
Component {
id: valueEditDialog
InstrumentValueEditDialog { }
}
}
...@@ -23,7 +23,6 @@ ...@@ -23,7 +23,6 @@
#include "QGCLoggingCategory.h" #include "QGCLoggingCategory.h"
#include "QGCCameraManager.h" #include "QGCCameraManager.h"
#include "HorizontalFactValueGrid.h" #include "HorizontalFactValueGrid.h"
#include "VerticalFactValueGrid.h"
#include "InstrumentValueData.h" #include "InstrumentValueData.h"
#include <QtQml> #include <QtQml>
...@@ -298,65 +297,70 @@ void QGCCorePlugin::factValueGridCreateDefaultSettings(const QString& defaultSet ...@@ -298,65 +297,70 @@ void QGCCorePlugin::factValueGridCreateDefaultSettings(const QString& defaultSet
factValueGrid.setFontSize(FactValueGrid::LargeFontSize); factValueGrid.setFontSize(FactValueGrid::LargeFontSize);
factValueGrid.appendRow(); factValueGrid.appendColumn();
factValueGrid.appendRow();
factValueGrid.appendColumn(); factValueGrid.appendColumn();
factValueGrid.appendColumn(); factValueGrid.appendColumn();
if (includeFWValues) { if (includeFWValues) {
factValueGrid.appendColumn(); factValueGrid.appendColumn();
} }
factValueGrid.appendRow();
int colIndex = 0; int rowIndex = 0;
QmlObjectListModel* row = factValueGrid.rows()->value<QmlObjectListModel*>(0); QmlObjectListModel* column = factValueGrid.columns()->value<QmlObjectListModel*>(0);
InstrumentValueData* value = row->value<InstrumentValueData*>(colIndex++); InstrumentValueData* value = column->value<InstrumentValueData*>(rowIndex++);
value->setFact("Vehicle", "AltitudeRelative"); value->setFact("Vehicle", "AltitudeRelative");
value->setIcon("arrow-thick-up.svg"); value->setIcon("arrow-thick-up.svg");
value->setText(value->fact()->shortDescription()); value->setText(value->fact()->shortDescription());
value->setShowUnits(true); value->setShowUnits(true);
value = row->value<InstrumentValueData*>(colIndex++); value = column->value<InstrumentValueData*>(rowIndex++);
value->setFact("Vehicle", "ClimbRate"); value->setFact("Vehicle", "DistanceToHome");
value->setIcon("arrow-simple-up.svg"); value->setIcon("bookmark copy 3.svg");
value->setText(value->fact()->shortDescription()); value->setText(value->fact()->shortDescription());
value->setShowUnits(true); value->setShowUnits(true);
if (includeFWValues) { rowIndex = 0;
value = row->value<InstrumentValueData*>(colIndex++); column = factValueGrid.columns()->value<QmlObjectListModel*>(1);
value->setFact("Vehicle", "AirSpeed");
value->setText("AirSpd");
value->setShowUnits(true);
}
value = row->value<InstrumentValueData*>(colIndex++);
value->setFact("Vehicle", "FlightTime");
value->setIcon("timer.svg");
value->setText(value->fact()->shortDescription());
value->setShowUnits(false);
colIndex = 0; value = column->value<InstrumentValueData*>(rowIndex++);
row = factValueGrid.rows()->value<QmlObjectListModel*>(1); value->setFact("Vehicle", "ClimbRate");
value->setIcon("arrow-simple-up.svg");
value = row->value<InstrumentValueData*>(colIndex++);
value->setFact("Vehicle", "DistanceToHome");
value->setIcon("bookmark copy 3.svg");
value->setText(value->fact()->shortDescription()); value->setText(value->fact()->shortDescription());
value->setShowUnits(true); value->setShowUnits(true);
value = row->value<InstrumentValueData*>(colIndex++); value = column->value<InstrumentValueData*>(rowIndex++);
value->setFact("Vehicle", "GroundSpeed"); value->setFact("Vehicle", "GroundSpeed");
value->setIcon("arrow-simple-right.svg"); value->setIcon("arrow-simple-right.svg");
value->setText(value->fact()->shortDescription()); value->setText(value->fact()->shortDescription());
value->setShowUnits(true); value->setShowUnits(true);
if (includeFWValues) { if (includeFWValues) {
value = row->value<InstrumentValueData*>(colIndex++); rowIndex = 0;
column = factValueGrid.columns()->value<QmlObjectListModel*>(2);
value = column->value<InstrumentValueData*>(rowIndex++);
value->setFact("Vehicle", "AirSpeed");
value->setText("AirSpd");
value->setShowUnits(true);
value = column->value<InstrumentValueData*>(rowIndex++);
value->setFact("Vehicle", "ThrottlePct"); value->setFact("Vehicle", "ThrottlePct");
value->setText("Thr"); value->setText("Thr");
value->setShowUnits(true); value->setShowUnits(true);
} }
value = row->value<InstrumentValueData*>(colIndex++); rowIndex = 0;
column = factValueGrid.columns()->value<QmlObjectListModel*>(includeFWValues ? 3 : 2);
value = column->value<InstrumentValueData*>(rowIndex++);
value->setFact("Vehicle", "FlightTime");
value->setIcon("timer.svg");
value->setText(value->fact()->shortDescription());
value->setShowUnits(false);
value = column->value<InstrumentValueData*>(rowIndex++);
value->setFact("Vehicle", "FlightDistance"); value->setFact("Vehicle", "FlightDistance");
value->setIcon("travel-walk.svg"); value->setIcon("travel-walk.svg");
value->setText(value->fact()->shortDescription()); value->setText(value->fact()->shortDescription());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment