From 6b90761677316433c1ebd9cef4b0a71bd023d743 Mon Sep 17 00:00:00 2001 From: Mohsen Date: Sun, 1 Sep 2024 17:49:26 +0330 Subject: [PATCH] Cleanup and add dynamic info from device. --- src/core/positioning/nmeagnssreceiver.cpp | 45 +++-------------------- src/core/positioning/positioningmodel.cpp | 43 +++++++++++----------- src/core/positioning/positioningmodel.h | 4 +- src/qml/PositioningInformationView.qml | 24 +++++------- 4 files changed, 39 insertions(+), 77 deletions(-) diff --git a/src/core/positioning/nmeagnssreceiver.cpp b/src/core/positioning/nmeagnssreceiver.cpp index 13cef3bc42..3c67744500 100644 --- a/src/core/positioning/nmeagnssreceiver.cpp +++ b/src/core/positioning/nmeagnssreceiver.cpp @@ -120,45 +120,12 @@ QList> NmeaGnssReceiver::details() { QList> dataList; - dataList.append( qMakePair( "latitude", mCurrentNmeaGnssPositionInformation.latitude() ) ); - dataList.append( qMakePair( "latitudeValid", mCurrentNmeaGnssPositionInformation.latitudeValid() ) ); - dataList.append( qMakePair( "longitude", mCurrentNmeaGnssPositionInformation.longitude() ) ); - dataList.append( qMakePair( "longitudeValid", mCurrentNmeaGnssPositionInformation.longitudeValid() ) ); - dataList.append( qMakePair( "elevation", mCurrentNmeaGnssPositionInformation.elevation() ) ); - dataList.append( qMakePair( "elevationValid", mCurrentNmeaGnssPositionInformation.elevationValid() ) ); - dataList.append( qMakePair( "speed", mCurrentNmeaGnssPositionInformation.speed() ) ); - dataList.append( qMakePair( "speedValid", mCurrentNmeaGnssPositionInformation.speedValid() ) ); - dataList.append( qMakePair( "direction", mCurrentNmeaGnssPositionInformation.direction() ) ); - dataList.append( qMakePair( "directionValid", mCurrentNmeaGnssPositionInformation.directionValid() ) ); - dataList.append( qMakePair( "pdop", mCurrentNmeaGnssPositionInformation.pdop() ) ); - dataList.append( qMakePair( "hdop", mCurrentNmeaGnssPositionInformation.hdop() ) ); - dataList.append( qMakePair( "vdop", mCurrentNmeaGnssPositionInformation.vdop() ) ); - dataList.append( qMakePair( "hacc", mCurrentNmeaGnssPositionInformation.hacc() ) ); - dataList.append( qMakePair( "haccValid", mCurrentNmeaGnssPositionInformation.haccValid() ) ); - dataList.append( qMakePair( "vacc", mCurrentNmeaGnssPositionInformation.vacc() ) ); - dataList.append( qMakePair( "vaccValid", mCurrentNmeaGnssPositionInformation.vaccValid() ) ); - dataList.append( qMakePair( "hvacc", mCurrentNmeaGnssPositionInformation.hvacc() ) ); - dataList.append( qMakePair( "hvaccValid", mCurrentNmeaGnssPositionInformation.hvaccValid() ) ); - dataList.append( qMakePair( "utcDateTime", mCurrentNmeaGnssPositionInformation.utcDateTime() ) ); - dataList.append( qMakePair( "fixMode", mCurrentNmeaGnssPositionInformation.fixMode() ) ); - dataList.append( qMakePair( "fixType", mCurrentNmeaGnssPositionInformation.fixType() ) ); - dataList.append( qMakePair( "quality", mCurrentNmeaGnssPositionInformation.quality() ) ); - dataList.append( qMakePair( "satellitesUsed", mCurrentNmeaGnssPositionInformation.satellitesUsed() ) ); - dataList.append( qMakePair( "status", mCurrentNmeaGnssPositionInformation.status() ) ); - dataList.append( qMakePair( "satInfoComplete", mCurrentNmeaGnssPositionInformation.satInfoComplete() ) ); - dataList.append( qMakePair( "isValid", mCurrentNmeaGnssPositionInformation.isValid() ) ); - dataList.append( qMakePair( "fixStatus", mCurrentNmeaGnssPositionInformation.fixStatus() ) ); - dataList.append( qMakePair( "qualityDescription", mCurrentNmeaGnssPositionInformation.qualityDescription() ) ); - dataList.append( qMakePair( "fixStatusDescription", mCurrentNmeaGnssPositionInformation.fixStatusDescription() ) ); - dataList.append( qMakePair( "verticalSpeed", mCurrentNmeaGnssPositionInformation.verticalSpeed() ) ); - dataList.append( qMakePair( "magneticVariation", mCurrentNmeaGnssPositionInformation.magneticVariation() ) ); - dataList.append( qMakePair( "averagedCount", mCurrentNmeaGnssPositionInformation.averagedCount() ) ); - dataList.append( qMakePair( "sourceName", mCurrentNmeaGnssPositionInformation.sourceName() ) ); - dataList.append( qMakePair( "imuCorrection", mCurrentNmeaGnssPositionInformation.imuCorrection() ) ); - dataList.append( qMakePair( "orientation", mCurrentNmeaGnssPositionInformation.orientation() ) ); - dataList.append( qMakePair( "orientationValid", mCurrentNmeaGnssPositionInformation.orientationValid() ) ); - // dataList.append(qMakePair("satPrn", QVariant::fromValue(mCurrentNmeaGnssPositionInformation.satPrn()))); - // dataList.append(qMakePair("satellitesInView", QVariant::fromValue(mCurrentNmeaGnssPositionInformation.satellitesInView()))); + dataList.append( qMakePair( "PDOP", QLocale::system().toString( mCurrentNmeaGnssPositionInformation.pdop(), 'f', 1 ) ) ); + dataList.append( qMakePair( "HDOP", QLocale::system().toString( mCurrentNmeaGnssPositionInformation.hdop(), 'f', 1 ) ) ); + dataList.append( qMakePair( "VDOP", QLocale::system().toString( mCurrentNmeaGnssPositionInformation.vdop(), 'f', 1 ) ) ); + dataList.append( qMakePair( "Valid", mCurrentNmeaGnssPositionInformation.isValid() ? "True" : "False" ) ); + dataList.append( qMakePair( "Fix", mCurrentNmeaGnssPositionInformation.fixStatusDescription() ) ); + dataList.append( qMakePair( "Quality", mCurrentNmeaGnssPositionInformation.qualityDescription() ) ); return dataList; } diff --git a/src/core/positioning/positioningmodel.cpp b/src/core/positioning/positioningmodel.cpp index a1706ec987..edfed8c0f4 100644 --- a/src/core/positioning/positioningmodel.cpp +++ b/src/core/positioning/positioningmodel.cpp @@ -23,21 +23,12 @@ void PositioningModel::refreshData() return; } - //! Update all info dynamically :) - //QList> details = mPositioningSource->device()->details(); - // for ( int i = 0; i < details.size(); ++i ) - // { - // const QString key = details[i].first; - // const QVariant value = details[i].second; - - // updateInfo( key, value ); - // } - const bool coordinatesIsXY = CoordinateReferenceSystemUtils::defaultCoordinateOrderForCrsIsXY( coordinateDisplayCrs() ); const bool coordinatesIsGeographic = coordinateDisplayCrs().isGeographic(); const QgsPoint coordinates = GeometryUtils::reprojectPoint( positioningSource()->sourcePosition(), CoordinateReferenceSystemUtils::wgs84Crs(), coordinateDisplayCrs() ); const double distanceUnitFactor = QgsUnitTypes::fromUnitToUnitFactor( Qgis::DistanceUnit::Meters, distanceUnits() ); const QString distanceUnitAbbreviation = QgsUnitTypes::toAbbreviatedString( distanceUnits() ); + const QList> deviceDetails = mPositioningSource->device()->details(); QString coord1Label, coord2Label; QString coord1Value, coord2Value; @@ -56,6 +47,14 @@ void PositioningModel::refreshData() updateInfo( "Speed", speed ); updateInfo( "H. Accuracy", hAccuracy ); updateInfo( "V. Accuracy", vAccuracy ); + + for ( int i = 0; i < deviceDetails.size(); ++i ) + { + const QString key = deviceDetails[i].first; + const QVariant value = deviceDetails[i].second; + + updateInfo( key, value ); + } } void PositioningModel::getCoordinateLabels( QString &coord1Label, QString &coord2Label, bool coordinatesIsXY, bool isGeographic ) @@ -148,16 +147,16 @@ void PositioningModel::updateInfo( const QString &name, const QVariant &value ) for ( int row = 0; row < rowCount(); ++row ) { QStandardItem *rowItem = item( row ); - if ( rowItem->data( VariableNameRole ).toString() == name ) + if ( rowItem->data( NameRole ).toString() == name ) { - rowItem->setData( value.toString(), VariableValueRole ); + rowItem->setData( value.toString(), ValueRole ); return; } } QStandardItem *nameItem = new QStandardItem( name ); - nameItem->setData( name, VariableNameRole ); - nameItem->setData( value.toString(), VariableValueRole ); + nameItem->setData( name, NameRole ); + nameItem->setData( value.toString(), ValueRole ); insertRow( rowCount(), QList() << nameItem ); } @@ -172,23 +171,23 @@ bool PositioningModel::setData( const QModelIndex &index, const QVariant &value, switch ( role ) { - case VariableNameRole: - if ( rowItem->data( VariableNameRole ) == value ) + case NameRole: + if ( rowItem->data( NameRole ) == value ) { return false; } - rowItem->setData( value, VariableNameRole ); + rowItem->setData( value, NameRole ); return true; - case VariableValueRole: + case ValueRole: - if ( rowItem->data( VariableValueRole ) == value ) + if ( rowItem->data( ValueRole ) == value ) { return false; } - rowItem->setData( value, VariableValueRole ); + rowItem->setData( value, ValueRole ); return true; default: @@ -201,8 +200,8 @@ bool PositioningModel::setData( const QModelIndex &index, const QVariant &value, QHash PositioningModel::roleNames() const { QHash names = QStandardItemModel::roleNames(); - names[VariableNameRole] = "VariableName"; - names[VariableValueRole] = "VariableValue"; + names[NameRole] = "Name"; + names[ValueRole] = "Value"; return names; } diff --git a/src/core/positioning/positioningmodel.h b/src/core/positioning/positioningmodel.h index 10f99c9daf..db2de5635a 100644 --- a/src/core/positioning/positioningmodel.h +++ b/src/core/positioning/positioningmodel.h @@ -18,8 +18,8 @@ class PositioningModel : public QStandardItemModel public: enum Roles { - VariableNameRole = Qt::UserRole, - VariableValueRole = Qt::UserRole + 1, + NameRole = Qt::UserRole, + ValueRole = Qt::UserRole + 1, }; PositioningModel( QObject *parent = nullptr ); diff --git a/src/qml/PositioningInformationView.qml b/src/qml/PositioningInformationView.qml index 4c229d3e07..bcef10d042 100644 --- a/src/qml/PositioningInformationView.qml +++ b/src/qml/PositioningInformationView.qml @@ -10,23 +10,24 @@ Rectangle { property alias positionSource: positioningModel.positioningSource property alias antennaHeight: positioningModel.antennaHeight - property real contentHeight: grid.contentHeight property color backgroundColor: "transparent" property color alternateBackgroundColor: Theme.positionBackgroundColor property color textColor: positionSource.currentness ? Theme.mainTextColor : Theme.secondaryTextColor property double cellHeight: 26 property double cellPadding: 6 + property real contentHeight: grid.count / grid.numberOfColumns * cellHeight + color: Theme.mainBackgroundColorSemiOpaque anchors.margins: 20 width: parent.width - color: Theme.mainBackgroundColorSemiOpaque GridView { id: grid readonly property real numberOfColumns: parent.width / cellWidth + flow: GridView.FlowTopToBottom model: PositioningModel { id: positioningModel distanceUnits: projectInfo.distanceUnits @@ -51,20 +52,15 @@ Rectangle { positioningModel.setupConnections(); } delegate: Rectangle { + readonly property real currentColumn: parseInt(index / (grid.count / grid.numberOfColumns)) + width: grid.cellWidth height: grid.cellHeight - - readonly property real currentRow: parseInt(index / grid.numberOfColumns) - color: { - if (grid.numberOfColumns % 2 == 0) { - if (currentRow % 2 == 0) { - return index % 2 == 0 ? positioningInformationView.alternateBackgroundColor : positioningInformationView.backgroundColor; - } else { - return index % 2 == 0 ? positioningInformationView.backgroundColor : positioningInformationView.alternateBackgroundColor; - } + if (currentColumn % 2 == 0) { + return index % 2 == 0 ? alternateBackgroundColor : backgroundColor; } else { - return index % 2 == 0 ? positioningInformationView.alternateBackgroundColor : positioningInformationView.backgroundColor; + return index % 2 == 0 ? backgroundColor : alternateBackgroundColor; } } @@ -77,14 +73,14 @@ Rectangle { Text { font: Theme.tipFont color: Theme.secondaryTextColor - text: VariableName + text: Name } Text { Layout.fillWidth: true font: Theme.tipFont color: positioningInformationView.textColor - text: VariableValue ? VariableValue : qsTr("N/A") + text: Value ? Value : qsTr("N/A") verticalAlignment: Text.AlignVCenter elide: Text.ElideRight }