Skip to content

Commit

Permalink
Added the ability to record distance traveled using GPS.
Browse files Browse the repository at this point in the history
  • Loading branch information
ic005k committed Feb 8, 2025
1 parent 1c993c9 commit ae0e554
Show file tree
Hide file tree
Showing 9 changed files with 418 additions and 320 deletions.
2 changes: 1 addition & 1 deletion Knot.pro
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
QT += core gui network printsupport core-private
QT += charts sensors
QT += qml quick quickwidgets webview
QT += qml quick quickwidgets webview positioning
QT += xml svg


Expand Down
5 changes: 3 additions & 2 deletions android/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http:// schemas.android.com/ tools" package="com.x" android:installLocation="auto"
android:versionCode="1" android:versionName="1.2.09">
android:versionCode="1" android:versionName="1.2.10">
<!-- The following comment will be replaced upon deployment with default permissions based on
the dependencies of the application.
Remove the comment if you do not require these default permissions. -->
Expand All @@ -15,7 +15,8 @@
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.REORDER_TASKS" />

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>

<uses-feature android:name="android.hardware.sensor.stepcounter" android:required="true" />
<uses-feature android:name="android.hardware.sensor.stepdetector" android:required="true" />
Expand Down
12 changes: 11 additions & 1 deletion src/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
QList<QPointF> PointList;
QList<double> doubleList;

QString ver = "1.2.09";
QString ver = "1.2.10";
QGridLayout *gl1;
QTreeWidgetItem *parentItem;
bool isrbFreq = true;
Expand Down Expand Up @@ -6034,3 +6034,13 @@ void MainWindow::on_btnMove_clicked() {
on_btnOkEditRecord_clicked();
}
}

void MainWindow::on_btnGPS_clicked() {
if (ui->btnGPS->text() == tr("Start")) {
m_Steps->startRecordMotion();
ui->btnGPS->setText(tr("Stop"));
} else if (ui->btnGPS->text() == tr("Stop")) {
m_Steps->stopRecordMotion();
ui->btnGPS->setText(tr("Start"));
}
}
2 changes: 2 additions & 0 deletions src/MainWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -797,6 +797,8 @@ class MainWindow : public QMainWindow {

void on_btnMove_clicked();

void on_btnGPS_clicked();

private:
bool isMoveEntry;
QTimer *tmeFlash;
Expand Down
17 changes: 15 additions & 2 deletions src/MainWindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>687</width>
<width>698</width>
<height>8948</height>
</rect>
</property>
Expand Down Expand Up @@ -4505,6 +4505,19 @@ QRadioButton::indicator:checked {
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="btnGPS">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Start</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
Expand Down Expand Up @@ -7277,7 +7290,7 @@ QSlider::handle:horizontal:disabled {
<rect>
<x>0</x>
<y>0</y>
<width>687</width>
<width>698</width>
<height>21</height>
</rect>
</property>
Expand Down
47 changes: 47 additions & 0 deletions src/Steps/Steps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -444,3 +444,50 @@ void Steps::setScrollBarPos(double pos) {
QMetaObject::invokeMethod((QObject*)root, "setScrollBarPos",
Q_ARG(QVariant, pos));
}

void Steps::startRecordMotion() {
m_positionSource = QGeoPositionInfoSource::createDefaultSource(this);
if (m_positionSource) {
connect(m_positionSource, &QGeoPositionInfoSource::positionUpdated, this,
&Steps::positionUpdated);
m_positionSource->setUpdateInterval(2000);
}

timer = new QTimer(this);
connect(timer, &QTimer::timeout, this, [this]() {
m_time = m_time.addSecs(1);
emit timeChanged();
});

if (m_positionSource) {
m_positionSource->startUpdates();
}
m_time = QTime(0, 0);
timer->start(1000);
m_distance = 0;
emit distanceChanged();
emit timeChanged();
}

void Steps::positionUpdated(const QGeoPositionInfo& info) {
if (lastPosition.isValid()) {
m_distance +=
lastPosition.distanceTo(info.coordinate()) / 1000.0; // Convert to km
emit distanceChanged();
}
lastPosition = info.coordinate();
}

void Steps::stopRecordMotion() {
if (m_positionSource) {
m_positionSource->stopUpdates();
}
timer->stop();

QString str1 = "运动距离: " + QString::number(m_distance) + " km";
QString str2 = "运动时间: " + m_time.toString("hh:mm:ss");
ShowMessage* msg = new ShowMessage(this);
msg->showMsg("Knot", str1 + "\n\n" + str2, 1);

delete m_positionSource;
}
20 changes: 20 additions & 0 deletions src/Steps/Steps.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

#include <QAccelerometer>
#include <QDialog>
#include <QGeoCoordinate>
#include <QGeoPositionInfoSource>
#include <QRegularExpressionValidator>

#include "src/Steps/StepsOptions.h"
Expand Down Expand Up @@ -74,11 +76,29 @@ class Steps : public QDialog {

void setTableData(int index, QString date, int steps, QString km);

void startRecordMotion();
void stopRecordMotion();

private slots:
void positionUpdated(const QGeoPositionInfo &info);

private:
QBrush brush1 = QBrush(QColor(255, 228, 225));
QBrush brush2 = QBrush(QColor(245, 222, 179));
QBrush brushMax = QBrush(QColor(245, 222, 79));
int maxCount = 90;

double distance() const { return m_distance; }
QGeoPositionInfoSource *m_positionSource;
QGeoCoordinate lastPosition;
double m_distance;
QDateTime m_startTime;
QTime m_time;
QTimer *timer;

signals:
void distanceChanged();
void timeChanged();
};

#endif // STEPS_H
Binary file modified src/cn.qm
Binary file not shown.
Loading

0 comments on commit ae0e554

Please sign in to comment.