Skip to content

Commit

Permalink
Cleanup and add dynamic info from device.
Browse files Browse the repository at this point in the history
  • Loading branch information
mohsenD98 committed Sep 1, 2024
1 parent fa2419a commit 6b90761
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 77 deletions.
45 changes: 6 additions & 39 deletions src/core/positioning/nmeagnssreceiver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,45 +120,12 @@ QList<QPair<QString, QVariant>> NmeaGnssReceiver::details()
{
QList<QPair<QString, QVariant>> 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;
}
Expand Down
43 changes: 21 additions & 22 deletions src/core/positioning/positioningmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,12 @@ void PositioningModel::refreshData()
return;
}

//! Update all info dynamically :)
//QList<QPair<QString, QVariant>> 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<QPair<QString, QVariant>> deviceDetails = mPositioningSource->device()->details();

QString coord1Label, coord2Label;
QString coord1Value, coord2Value;
Expand All @@ -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 )
Expand Down Expand Up @@ -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<QStandardItem *>() << nameItem );
}

Expand All @@ -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:
Expand All @@ -201,8 +200,8 @@ bool PositioningModel::setData( const QModelIndex &index, const QVariant &value,
QHash<int, QByteArray> PositioningModel::roleNames() const
{
QHash<int, QByteArray> names = QStandardItemModel::roleNames();
names[VariableNameRole] = "VariableName";
names[VariableValueRole] = "VariableValue";
names[NameRole] = "Name";
names[ValueRole] = "Value";
return names;
}

Expand Down
4 changes: 2 additions & 2 deletions src/core/positioning/positioningmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
24 changes: 10 additions & 14 deletions src/qml/PositioningInformationView.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
}
}

Expand All @@ -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
}
Expand Down

0 comments on commit 6b90761

Please sign in to comment.