Commit fc550843 authored by Valentin Platzgummer's avatar Valentin Platzgummer

resizing issue: measurement item editor solved

parent ab5abb37
......@@ -7,9 +7,15 @@ import QGroundControl.Controls 1.0
import QGroundControl.FactControls 1.0
import QGroundControl.ScreenTools 1.0
GridLayout {
import QGroundControl.Palette 1.0
Rectangle {
id: _root
width: mainGrid.width
height: mainGrid.height
color: qgcPal.windowShadeDark
property bool checked: true
property var missionItem: undefined
property int availableWidth: 300
......@@ -21,10 +27,6 @@ GridLayout {
property var _areaData: missionItem.areaData
property real _margin: ScreenTools.defaultFontPixelWidth / 2
columnSpacing: _margin
rowSpacing: _margin
columns: 2
Component.onCompleted: {
console.assert(missionItem !== undefined,
"please set the missionItem property")
......@@ -41,6 +43,14 @@ GridLayout {
}
}
GridLayout {
id: mainGrid
width: availableWidth
columnSpacing: _margin
rowSpacing: _margin
columns: 2
QGCLabel {
text: _root.errorString
wrapMode: Text.WordWrap
......@@ -108,16 +118,17 @@ GridLayout {
if (geoArea.editorQML && !_visualItem) {
var component = Qt.createComponent(geoArea.editorQML)
if (component.status === Component.Error) {
console.log("Error loading Qml: ", geoArea.editorQML,
console.log("Error loading Qml: ",
geoArea.editorQML,
component.errorString())
} else {
_visualItem = component.createObject(editorParent, {
"geoArea": editor.geoArea,
"visible": Qt.binding(function () {
"visible": Qt.binding(
function () {
return editor.visible
}),
"availableWidth": Qt.binding(
function () {
"availableWidth": Qt.binding(function () {
return editorParent.width
})
})
......@@ -223,4 +234,5 @@ Use the Abort button to reset the areas and leave the tab.")
Settings {
property alias showHint: hintHeader.checked
}
}
} // GridLayout
} // Rectangle
......@@ -23,7 +23,8 @@ GridLayout {
property real _margin: ScreenTools.defaultFontPixelWidth / 2
Component.onCompleted: {
console.assert(geoArea !== undefined, "please set the areaItem property")
console.assert(geoArea !== undefined,
"please set the areaItem property")
}
SectionHeader {
......@@ -33,7 +34,7 @@ GridLayout {
Layout.fillWidth: true
}
GridLayout{
GridLayout {
visible: tilesHeader.checked
Layout.fillWidth: true
Layout.columnSpan: 2
......@@ -71,14 +72,12 @@ GridLayout {
Layout.fillWidth: true
}
FactCheckBox {
text: qsTr("Show Tiles")
fact: geoArea.showTiles
}
}
SectionHeader {
id: statsHeader
text: qsTr("Statistics")
......@@ -86,7 +85,7 @@ GridLayout {
Layout.columnSpan: 2
}
GridLayout{
GridLayout {
visible: statsHeader.checked
Layout.fillWidth: true
Layout.columnSpan: 2
......@@ -94,14 +93,27 @@ GridLayout {
rowSpacing: _margin
columns: 2
QGCLabel { text: qsTr("Area") }
// QGCLabel { text: QGroundControl.squareMetersToAppSettingsAreaUnits(geoArea.area).toFixed(2) + " " + QGroundControl.appSettingsAreaUnitsString }
QGCLabel {
text: qsTr("Area")
}
QGCLabel {
text: QGroundControl.unitsConversion.squareMetersToAppSettingsAreaUnits(
geoArea.area).toFixed(
2) + " " + QGroundControl.unitsConversion.appSettingsAreaUnitsString
}
QGCLabel { text: qsTr("Tiles") }
QGCLabel { text: geoArea.tiles.count }
QGCLabel {
text: qsTr("Tiles")
}
QGCLabel {
text: geoArea.tiles.count
}
QGCLabel { text: qsTr("Max. Tiles") }
QGCLabel { text: geoArea.maxTiles }
QGCLabel {
text: qsTr("Max. Tiles")
}
QGCLabel {
text: geoArea.maxTiles
}
}
} // Column
......@@ -53,7 +53,7 @@ Rectangle {
readonly property int areaEditorIndex: 0
readonly property int parameterEditorIndex: 1
readonly property int nemoControlsIndex: 2
readonly property int nemoEditorIndex: 2
property bool editing: _missionItem.editing
property bool correct: false
......@@ -102,15 +102,13 @@ Rectangle {
}
}
StackLayout {
width: parent.width
currentIndex: tabBar.currentIndex
MCI.AreaDataEditor {
id: areaEditor
visible: tabBar.currentIndex === tabBar.areaEditorIndex
checked: visible
missionItem: _root._missionItem
availableWidth: parent.width
availableWidth: mainColumn.width
onAbort: {
missionItem.abortEditing()
tabBar.currentIndex = tabBar.parameterEditorIndex
......@@ -120,6 +118,7 @@ Rectangle {
MCI.ParameterEditor {
id: parameterEditor
visible: tabBar.currentIndex === tabBar.parameterEditorIndex
checked: visible
missionItem: _root._missionItem
availableWidth: mainColumn.width
......@@ -128,10 +127,10 @@ Rectangle {
MCI.NemoEditor {
id: nemoEditor
visible: tabBar.currentIndex === tabBar.nemoEditorIndex
checked: visible
missionItem: _root._missionItem
availableWidth: mainColumn.width
}
}
} // main Column
} // Rectangle
import QtQuick 2.0
import Qt.labs.settings 1.0
import QtQuick.Layouts 1.11
import QtQuick.Controls 1.4
import QGroundControl.Controls 1.0
import QGroundControl.FactControls 1.0
import QGroundControl.ScreenTools 1.0
import QGroundControl.Palette 1.0
import MeasurementComplexItem 1.0 as MCI
GridLayout {
Rectangle {
id: _root
width: mainGrid.width
height: mainGrid.height
color: qgcPal.windowShadeDark
property bool checked: true
property var missionItem: undefined
property int availableWidth: 300
......@@ -26,10 +31,6 @@ GridLayout {
property var _nemoInterface: MCI.NemoInterface
property bool _holding
columnSpacing: _margin
rowSpacing: _margin
columns: 2
Component.onCompleted: {
console.assert(missionItem !== undefined,
"please set the missionItem property")
......@@ -37,6 +38,14 @@ GridLayout {
_stopHolding()
}
GridLayout {
id: mainGrid
width: availableWidth
columnSpacing: _margin
rowSpacing: _margin
columns: 2
QGCLabel {
text: _root.errorString
wrapMode: Text.WordWrap
......@@ -176,6 +185,7 @@ Use the Random button to simulate measurement progress.")
Settings {
property alias showHint: hintHeader.checked
}
} // GridLayout
function _holdProgress() {
var areaArray = _areaData.measurementAreaList
......@@ -224,4 +234,4 @@ Use the Random button to simulate measurement progress.")
}
}
}
}
} // Rectangle
......@@ -14,8 +14,12 @@ import QGroundControl.FactControls 1.0
import QGroundControl.Palette 1.0
import QGroundControl.FlightMap 1.0
GridLayout {
id:_root
Rectangle {
id: _root
width: mainGrid.width
height: mainGrid.height
color: qgcPal.windowShadeDark
property bool checked: true
property var missionItem: undefined
......@@ -25,13 +29,9 @@ GridLayout {
property var _generator: missionItem.generator
property var _generatorEditor: undefined
width: availableWidth
columnSpacing: _margin
rowSpacing: _margin
columns: 2
Component.onCompleted: {
console.assert(missionItem !== undefined, "please set the missionItem property")
console.assert(missionItem !== undefined,
"please set the missionItem property")
_addGeneratorEditor()
}
......@@ -44,7 +44,13 @@ GridLayout {
_addGeneratorEditor()
}
GridLayout {
id: mainGrid
columnSpacing: _margin
rowSpacing: _margin
columns: 2
width: availableWidth
SectionHeader {
id: generalHeader
......@@ -54,7 +60,6 @@ GridLayout {
text: qsTr("General")
}
GridLayout {
id: generalGrid
Layout.fillWidth: true
......@@ -80,9 +85,11 @@ GridLayout {
visible: variantRepeater.len > 0
}
ExclusiveGroup{id:variantGroup}
ExclusiveGroup {
id: variantGroup
}
GridLayout{
GridLayout {
Layout.columnSpan: parent.columns
Layout.maximumWidth: parent.width
columns: 3
......@@ -90,7 +97,7 @@ GridLayout {
columnSpacing: _margin
rowSpacing: _margin
Repeater{
Repeater {
id: variantRepeater
property var names: missionItem.variantNames
......@@ -99,19 +106,19 @@ GridLayout {
model: len
delegate: QGCRadioButton {
checked: index === variantIndex
text: variantRepeater.names[index] ? variantRepeater.names[index]: ""
text: variantRepeater.names[index] ? variantRepeater.names[index] : ""
Layout.fillWidth: true
property int variantIndex: missionItem.variantIndex.value
onVariantIndexChanged: {
if (variantIndex === index){
if (variantIndex === index) {
checked = true
}
}
onCheckedChanged: {
if (checked && variantIndex !== index){
if (checked && variantIndex !== index) {
missionItem.variantIndex.value = index
}
}
......@@ -128,7 +135,7 @@ GridLayout {
text: qsTr("Generator")
}
GridLayout{
GridLayout {
Layout.fillWidth: true
columnSpacing: _margin
Layout.maximumWidth: parent.width
......@@ -148,35 +155,35 @@ GridLayout {
model: missionItem.generatorNameList
onActivated: {
if (index != -1){
if (index != -1) {
missionItem.switchToGenerator(index)
}
}
}
}
ColumnLayout{
id:generatorEditorParent
ColumnLayout {
id: generatorEditorParent
Layout.fillWidth: true
Layout.columnSpan: parent.columns
Layout.maximumWidth: parent.width
visible: generatorHeader.checked
}
QGCButton{
text:qsTr("Reverse")
QGCButton {
text: qsTr("Reverse")
onClicked: missionItem.reverseRoute()
Layout.columnSpan: 2
Layout.fillWidth: true
}
// bussy indicator
ColumnLayout{
ColumnLayout {
Layout.fillWidth: true
spacing: _margin
Layout.maximumWidth: parent.width
BusyIndicator{
BusyIndicator {
id: indicator
property bool calculating: missionItem.calculating
......@@ -185,13 +192,13 @@ GridLayout {
visible: calculating || timer.running
onCalculatingChanged: {
if(!calculating){
if (!calculating) {
// defer hiding
timer.restart()
}
}
Timer{
Timer {
id: timer
interval: 1000
repeat: false
......@@ -199,28 +206,28 @@ GridLayout {
}
}
} // indicator column
} // GridLayout
function _addGeneratorEditor(){
function _addGeneratorEditor() {
if (_generator && _generator.editorQml && !_generatorEditor) {
var component = Qt.createComponent(_generator.editorQml)
if (component.status === Component.Error) {
console.log("Error loading Qml: ",
_generator.editorQml, component.errorString())
console.log("Error loading Qml: ", _generator.editorQml,
component.errorString())
} else {
_generatorEditor =
component.createObject(
_generatorEditor = component.createObject(
generatorEditorParent, {
"generator": _root._generator,
"availableWidth": generatorEditorParent.width,
"availableWidth": generatorEditorParent.width
})
}
}
}
function _destroyGeneratorEditor(){
if (_generatorEditor){
function _destroyGeneratorEditor() {
if (_generatorEditor) {
_generatorEditor.destroy()
_generatorEditor = undefined
}
}
}
} // Rectangle
......@@ -20,7 +20,8 @@ GridLayout {
property real _margin: ScreenTools.defaultFontPixelWidth / 2
Component.onCompleted: {
console.assert(geoArea !== undefined, "please set the areaItem property")
console.assert(geoArea !== undefined,
"please set the areaItem property")
}
SectionHeader {
......@@ -38,7 +39,13 @@ GridLayout {
Layout.fillWidth: true
Layout.columnSpan: 2
QGCLabel { text: qsTr("Area") }
//QGCLabel { text: QGroundControl.squareMetersToAppSettingsAreaUnits(geoArea.area).toFixed(2) + " " + QGroundControl.appSettingsAreaUnitsString }
QGCLabel {
text: qsTr("Area")
}
QGCLabel {
text: QGroundControl.unitsConversion.squareMetersToAppSettingsAreaUnits(
geoArea.area).toFixed(
2) + " " + QGroundControl.unitsConversion.appSettingsAreaUnitsString
}
}
}
#include "QmlObjectVectorModel.h"
#include <QDebug>
#include <QQmlEngine>
const int QmlObjectVectorModel::ObjectRole = Qt::UserRole;
const int QmlObjectVectorModel::TextRole = Qt::UserRole + 1;
QmlObjectVectorModel::QmlObjectVectorModel(QObject* parent)
: QAbstractListModel(parent)
, _dirty(false)
, _skipDirtyFirstItem(false)
{
}
int QmlObjectVectorModel::rowCount(const QModelIndex& parent) const
{
Q_UNUSED(parent);
return _objectList.count();
}
QVariant QmlObjectVectorModel::data(const QModelIndex &index, int role) const
{
if (!index.isValid()) {
return QVariant();
}
if (index.row() < 0 || index.row() >= _objectList.count()) {
return QVariant();
}
if (role == ObjectRole) {
return QVariant::fromValue(_objectList[index.row()]);
} else if (role == TextRole) {
return QVariant::fromValue(_objectList[index.row()]->objectName());
} else {
return QVariant();
}
}
QHash<int, QByteArray> QmlObjectVectorModel::roleNames(void) const
{
QHash<int, QByteArray> hash;
hash[ObjectRole] = "object";
hash[TextRole] = "text";
return hash;
}
bool QmlObjectVectorModel::setData(const QModelIndex& index, const QVariant& value, int role)
{
if (index.isValid() && role == ObjectRole) {
_objectList.replace(index.row(), value.value<QObject*>());
emit dataChanged(index, index);
return true;
}
return false;
}
bool QmlObjectVectorModel::insertRows(int position, int rows, const QModelIndex& parent)
{
Q_UNUSED(parent);
if (position < 0 || position > _objectList.count() + 1) {
qWarning() << "Invalid position position:count" << position << _objectList.count();
}
beginInsertRows(QModelIndex(), position, position + rows - 1);
endInsertRows();
emit countChanged(count());
return true;
}
bool QmlObjectVectorModel::removeRows(int position, int rows, const QModelIndex& parent)
{
Q_UNUSED(parent);
if (position < 0 || position >= _objectList.count()) {
qWarning() << "Invalid position position:count" << position << _objectList.count();
} else if (position + rows > _objectList.count()) {
qWarning() << "Invalid rows position:rows:count" << position << rows << _objectList.count();
}
beginRemoveRows(QModelIndex(), position, position + rows - 1);
for (int row=0; row<rows; row++) {
_objectList.removeAt(position);
}
endRemoveRows();
emit countChanged(count());
return true;
}
QObject* QmlObjectVectorModel::operator[](int index)
{
if (index < 0 || index >= _objectList.count()) {
return NULL;
}
return _objectList[index];
}
const QObject* QmlObjectVectorModel::operator[](int index) const
{
if (index < 0 || index >= _objectList.count()) {
return NULL;
}
return _objectList[index];
}
void QmlObjectVectorModel::clear()
{
while (rowCount()) {
removeAt(0);
}
}
QObject* QmlObjectVectorModel::removeAt(int i)
{
QObject* removedObject = _objectList[i];
if(removedObject) {
// Look for a dirtyChanged signal on the object
if (_objectList[i]->metaObject()->indexOfSignal(QMetaObject::normalizedSignature("dirtyChanged(bool)")) != -1) {
if (!_skipDirtyFirstItem || i != 0) {
QObject::disconnect(_objectList[i], SIGNAL(dirtyChanged(bool)), this, SLOT(_childDirtyChanged(bool)));
}
}
}
removeRows(i, 1);
setDirty(true);
return removedObject;
}
void QmlObjectVectorModel::insert(int i, QObject* object)
{
if (i < 0 || i > _objectList.count()) {
qWarning() << "Invalid index index:count" << i << _objectList.count();
}
QQmlEngine::setObjectOwnership(object, QQmlEngine::CppOwnership);
// Look for a dirtyChanged signal on the object
if (object->metaObject()->indexOfSignal(QMetaObject::normalizedSignature("dirtyChanged(bool)")) != -1) {
if (!_skipDirtyFirstItem || i != 0) {
QObject::connect(object, SIGNAL(dirtyChanged(bool)), this, SLOT(_childDirtyChanged(bool)));
}
}
_objectList.insert(i, object);
insertRows(i, 1);
setDirty(true);
}
void QmlObjectVectorModel::insert(int i, QVector<QObject*> objects)
{
if (i < 0 || i > _objectList.count()) {
qWarning() << "Invalid index index:count" << i << _objectList.count();
}
int j = i;
for (QObject* object: objects) {
QQmlEngine::setObjectOwnership(object, QQmlEngine::CppOwnership);
// Look for a dirtyChanged signal on the object
if (object->metaObject()->indexOfSignal(QMetaObject::normalizedSignature("dirtyChanged(bool)")) != -1) {
if (!_skipDirtyFirstItem || j != 0) {
QObject::connect(object, SIGNAL(dirtyChanged(bool)), this, SLOT(_childDirtyChanged(bool)));
}
}
j++;
_objectList.insert(j, object);
}
insertRows(i, objects.count());
setDirty(true);
}
void QmlObjectVectorModel::append(QObject* object)
{
insert(_objectList.count(), object);
}
void QmlObjectVectorModel::append(QVector<QObject*> objects)
{
insert(_objectList.count(), objects);
}
QVector<QObject*> QmlObjectVectorModel::swapObjectList(const QVector<QObject*>& newlist)
{
QVector<QObject*> oldlist(_objectList);
beginResetModel();
_objectList = newlist;
endResetModel();
emit countChanged(count());
return oldlist;
}
int QmlObjectVectorModel::count() const
{
return rowCount();
}
void QmlObjectVectorModel::setDirty(bool dirty)
{
if (_dirty != dirty) {
_dirty = dirty;
if (!dirty) {
// Need to clear dirty from all children
for(QObject* object: _objectList) {
if (object->property("dirty").isValid()) {
object->setProperty("dirty", false);
}
}
}
emit dirtyChanged(_dirty);
}
}
void QmlObjectVectorModel::_childDirtyChanged(bool dirty)
{
_dirty |= dirty;
// We want to emit dirtyChanged even if the actual value of _dirty didn't change. It can be a useful
// signal to know when a child has changed dirty state
emit dirtyChanged(_dirty);
}
void QmlObjectVectorModel::deleteListAndContents()
{
for (int i=0; i<_objectList.count(); i++) {
_objectList[i]->deleteLater();
}
deleteLater();
}
void QmlObjectVectorModel::clearAndDeleteContents()
{
beginResetModel();
for (int i=0; i<_objectList.count(); i++) {
_objectList[i]->deleteLater();
}
clear();
endResetModel();
}
void swap(QmlObjectVectorModel &list1, QmlObjectVectorModel &list2)
{
using std::swap;
swap(list1._objectList, list2._objectList);
swap(list1._dirty, list2._dirty);
swap(list1._skipDirtyFirstItem, list2._skipDirtyFirstItem);
}
#pragma once
#include <QAbstractListModel>
class QmlObjectVectorModel : public QAbstractListModel
{
Q_OBJECT
public:
QmlObjectVectorModel(QObject* parent = nullptr);
Q_PROPERTY(int count READ count NOTIFY countChanged)
/// Returns true if any of the items in the list are dirty. Requires each object to have
/// a dirty property and dirtyChanged signal.
Q_PROPERTY(bool dirty READ dirty WRITE setDirty NOTIFY dirtyChanged)
Q_INVOKABLE QObject* get(int index) { return _objectList[index]; }
// Property accessors
int count () const;
bool dirty () const { return _dirty; }
void setDirty (bool dirty);
void append (QObject* object);
void append (QVector<QObject*> objects);
QVector<QObject*> swapObjectList (const QVector<QObject*>& newlist);
void clear ();
QObject* removeAt (int i);
QObject* removeOne (QObject* object) { return removeAt(indexOf(object)); }
void insert (int i, QObject* object);
void insert (int i, QVector<QObject*> objects);
bool contains (QObject* object) { return _objectList.indexOf(object) != -1; }
int indexOf (QObject* object) { return _objectList.indexOf(object); }
QObject* operator[] (int i);
const QObject* operator[] (int i) const;
template<class T> T value (int index) { return qobject_cast<T>(_objectList[index]); }
QVector<QObject*>* objectList () { return &_objectList; }
/// Calls deleteLater on all items and this itself.
void deleteListAndContents ();
/// Clears the list and calls deleteLater on each entry
void clearAndDeleteContents ();
void beginReset () { beginResetModel(); }
void endReset () { endResetModel(); }
// Friends
friend void swap(QmlObjectVectorModel& list1, QmlObjectVectorModel& list2);
signals:
void countChanged (int count);
void dirtyChanged (bool dirtyChanged);
private slots:
void _childDirtyChanged (bool dirty);
private:
// Overrides from QAbstractListModel
int rowCount (const QModelIndex & parent = QModelIndex()) const override;
QVariant data (const QModelIndex & index, int role = Qt::DisplayRole) const override;
bool insertRows (int position, int rows, const QModelIndex &index = QModelIndex()) override;
bool removeRows (int position, int rows, const QModelIndex &index = QModelIndex()) override;
bool setData (const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;
QHash<int, QByteArray> roleNames(void) const override;
private:
QVector<QObject*> _objectList;
bool _dirty;
bool _skipDirtyFirstItem;
static const int ObjectRole;
static const int TextRole;
};
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