Skip to content

Commit

Permalink
Create bridge
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Nov 4, 2022
1 parent 9527271 commit b5e077b
Show file tree
Hide file tree
Showing 7 changed files with 431 additions and 207 deletions.
2 changes: 0 additions & 2 deletions src/app/gps/qgsappgpsconnection.h
Expand Up @@ -136,8 +136,6 @@ class APP_EXPORT QgsAppGpsConnection : public QObject

void onConnected( QgsGpsConnection *conn );

void onDeviceStateChanged( const QgsGpsInformation &info );

private:

void showStatusBarMessage( const QString &msg );
Expand Down
148 changes: 148 additions & 0 deletions src/app/gps/qgsappgpssettingsmenu.cpp
@@ -0,0 +1,148 @@
/***************************************************************************
qgsappgpssettingsmenu.cpp
-------------------
begin : October 2022
copyright : (C) 2022 Nyall Dawson
email : nyall dot dawson at gmail dot com
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#include "qgsappgpssettingsmenu.h"
#include "qgssettings.h"

#include <QRadioButton>
#include <QButtonGroup>

QgsAppGpsSettingsMenu::QgsAppGpsSettingsMenu( QWidget *parent )
: QMenu( parent )
{
QgsSettings settings;

mShowLocationMarkerAction = new QAction( tr( "Show Location Marker" ), this );
mShowLocationMarkerAction->setCheckable( true );
mShowLocationMarkerAction->setChecked( settings.value( QStringLiteral( "showMarker" ), "true", QgsSettings::Gps ).toBool() );
connect( mShowLocationMarkerAction, &QAction::toggled, this, [ = ]( bool checked )
{
emit locationMarkerToggled( checked );
QgsSettings settings;
settings.setValue( QStringLiteral( "showMarker" ), checked, QgsSettings::Gps );
} );
addAction( mShowLocationMarkerAction );


mShowBearingLineAction = new QAction( tr( "Show Bearing Line" ), this );
mShowBearingLineAction->setCheckable( true );
mShowBearingLineAction->setChecked( settings.value( QStringLiteral( "showBearingLine" ), false, QgsSettings::Gps ).toBool() );
connect( mShowBearingLineAction, &QAction::toggled, this, [ = ]( bool checked )
{
emit bearingLineToggled( checked );
QgsSettings settings;
settings.setValue( QStringLiteral( "showBearingLine" ), checked, QgsSettings::Gps );
} );

addAction( mShowBearingLineAction );


mRotateMapAction = new QAction( tr( "Rotate map to match GPS direction" ), this );
mRotateMapAction->setCheckable( true );
mRotateMapAction->setChecked( settings.value( QStringLiteral( "rotateMap" ), false, QgsSettings::Gps ).toBool() );
connect( mRotateMapAction, &QAction::toggled, this, [ = ]( bool checked )
{
emit rotateMapToggled( checked );
QgsSettings settings;
settings.setValue( QStringLiteral( "rotateMap" ), checked, QgsSettings::Gps );
} );

addAction( mRotateMapAction );

mRadioAlwaysRecenter = new QRadioButton( "Always Recenter Map", this );
mRadioRecenterWhenOutside = new QRadioButton( "Recenter Map When Leaving Extent", this );
mRadioNeverRecenter = new QRadioButton( "Never Recenter", this );
QButtonGroup *recenterGroup = new QButtonGroup( this );
recenterGroup->addButton( mRadioAlwaysRecenter );
recenterGroup->addButton( mRadioRecenterWhenOutside );
recenterGroup->addButton( mRadioNeverRecenter );

//pan mode
const QString panMode = settings.value( QStringLiteral( "panMode" ), "recenterWhenNeeded", QgsSettings::Gps ).toString();
if ( panMode == QLatin1String( "none" ) )
{
mRadioNeverRecenter->setChecked( true );
}
else if ( panMode == QLatin1String( "recenterAlways" ) )
{
mRadioAlwaysRecenter->setChecked( true );
}
else
{
mRadioRecenterWhenOutside->setChecked( true );
}

connect( mRadioAlwaysRecenter, &QRadioButton::toggled, this, [ = ]( bool checked )
{
if ( checked )
{
QgsSettings settings;
settings.setValue( QStringLiteral( "panMode" ), "recenterAlways", QgsSettings::Gps );
emit mapCenteringModeChanged( QgsAppGpsSettingsMenu::MapCenteringMode::Always );
}
} );

connect( mRadioRecenterWhenOutside, &QRadioButton::toggled, this, [ = ]( bool checked )
{
if ( checked )
{
QgsSettings settings;
settings.setValue( QStringLiteral( "panMode" ), "recenterWhenNeeded", QgsSettings::Gps );
emit mapCenteringModeChanged( QgsAppGpsSettingsMenu::MapCenteringMode::WhenLeavingExtent );
}
} );

connect( mRadioNeverRecenter, &QRadioButton::toggled, this, [ = ]( bool checked )
{
if ( checked )
{
QgsSettings settings;
settings.setValue( QStringLiteral( "panMode" ), "none", QgsSettings::Gps );
emit mapCenteringModeChanged( QgsAppGpsSettingsMenu::MapCenteringMode::Never );
}
} );
}

bool QgsAppGpsSettingsMenu::locationMarkerVisible() const
{
return mShowLocationMarkerAction->isChecked();
}

bool QgsAppGpsSettingsMenu::bearingLineVisible() const
{
return mShowBearingLineAction->isChecked();
}

bool QgsAppGpsSettingsMenu::rotateMap() const
{
return mRotateMapAction->isChecked();
}

QgsAppGpsSettingsMenu::MapCenteringMode QgsAppGpsSettingsMenu::mapCenteringMode() const
{
// pan mode
if ( mRadioAlwaysRecenter->isChecked() )
{
return QgsAppGpsSettingsMenu::MapCenteringMode::Always;
}
else if ( mRadioRecenterWhenOutside->isChecked() )
{
return QgsAppGpsSettingsMenu::MapCenteringMode::WhenLeavingExtent;
}
else
{
return QgsAppGpsSettingsMenu::MapCenteringMode::Never;
}
}
65 changes: 65 additions & 0 deletions src/app/gps/qgsappgpssettingsmenu.h
@@ -0,0 +1,65 @@
/***************************************************************************
qgsappgpssettingsmenu.h
-------------------
begin : October 2022
copyright : (C) 2022 Nyall Dawson
email : nyall dot dawson at gmail dot com
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#ifndef QGSAPPGPSSETTINGSMENU_H
#define QGSAPPGPSSETTINGSMENU_H

#include <QMenu>

class QRadioButton;

class QgsAppGpsSettingsMenu : public QMenu
{
Q_OBJECT

public:

enum class MapCenteringMode
{
Always,
WhenLeavingExtent,
Never
};
Q_ENUM( MapCenteringMode )

QgsAppGpsSettingsMenu( QWidget *parent );

bool locationMarkerVisible() const;
bool bearingLineVisible() const;
bool rotateMap() const;
MapCenteringMode mapCenteringMode() const;

signals:

void locationMarkerToggled( bool visible );
void bearingLineToggled( bool visible );
void rotateMapToggled( bool enabled );
void mapCenteringModeChanged( MapCenteringMode mode );

private:

QAction *mShowLocationMarkerAction = nullptr;
QAction *mShowBearingLineAction = nullptr;
QAction *mRotateMapAction = nullptr;

QRadioButton *mRadioAlwaysRecenter = nullptr;
QRadioButton *mRadioRecenterWhenOutside = nullptr;
QRadioButton *mRadioNeverRecenter = nullptr;



};

#endif // QGSAPPGPSSETTINGSMANAGER_H

0 comments on commit b5e077b

Please sign in to comment.