Skip to content

Commit

Permalink
Start on settings menu
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Nov 4, 2022
1 parent b5e077b commit a98b802
Show file tree
Hide file tree
Showing 7 changed files with 106 additions and 96 deletions.
1 change: 1 addition & 0 deletions src/app/CMakeLists.txt
Expand Up @@ -264,6 +264,7 @@ set(QGIS_APP_SRCS
options/qgsvectorrenderingoptions.cpp

gps/qgsappgpsconnection.cpp
gps/qgsappgpssettingsmenu.cpp
gps/qgsgpsbearingitem.cpp
gps/qgsgpscanvasbridge.cpp
gps/qgsgpsinformationwidget.cpp
Expand Down
43 changes: 36 additions & 7 deletions src/app/gps/qgsappgpssettingsmenu.cpp
Expand Up @@ -18,6 +18,34 @@

#include <QRadioButton>
#include <QButtonGroup>
#include <QGridLayout>

QgsGpsMapRotationAction::QgsGpsMapRotationAction( QWidget *parent )
: QWidgetAction( parent )
{
QGridLayout *gLayout = new QGridLayout();
gLayout->setContentsMargins( 8, 2, 3, 2 );

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

gLayout->addWidget( mRadioAlwaysRecenter, 0, 0, 1, 2 );
gLayout->addWidget( mRadioRecenterWhenOutside, 1, 0, 1, 2 );
gLayout->addWidget( mRadioNeverRecenter, 2, 0, 1, 2 );

QWidget *w = new QWidget();
w->setLayout( gLayout );
setDefaultWidget( w );
}

//
// QgsAppGpsSettingsMenu
//

QgsAppGpsSettingsMenu::QgsAppGpsSettingsMenu( QWidget *parent )
: QMenu( parent )
Expand Down Expand Up @@ -61,13 +89,10 @@ QgsAppGpsSettingsMenu::QgsAppGpsSettingsMenu( QWidget *parent )

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 );
QgsGpsMapRotationAction *rotateAction = new QgsGpsMapRotationAction( this );
mRadioAlwaysRecenter = rotateAction->radioAlwaysRecenter();
mRadioRecenterWhenOutside = rotateAction->radioRecenterWhenOutside();
mRadioNeverRecenter = rotateAction->radioNeverRecenter();

//pan mode
const QString panMode = settings.value( QStringLiteral( "panMode" ), "recenterWhenNeeded", QgsSettings::Gps ).toString();
Expand Down Expand Up @@ -113,6 +138,9 @@ QgsAppGpsSettingsMenu::QgsAppGpsSettingsMenu( QWidget *parent )
emit mapCenteringModeChanged( QgsAppGpsSettingsMenu::MapCenteringMode::Never );
}
} );

addSeparator();
addAction( rotateAction );
}

bool QgsAppGpsSettingsMenu::locationMarkerVisible() const
Expand Down Expand Up @@ -146,3 +174,4 @@ QgsAppGpsSettingsMenu::MapCenteringMode QgsAppGpsSettingsMenu::mapCenteringMode(
return QgsAppGpsSettingsMenu::MapCenteringMode::Never;
}
}

22 changes: 20 additions & 2 deletions src/app/gps/qgsappgpssettingsmenu.h
Expand Up @@ -17,9 +17,29 @@
#define QGSAPPGPSSETTINGSMENU_H

#include <QMenu>
#include <QWidgetAction>

class QRadioButton;

class QgsGpsMapRotationAction: public QWidgetAction
{
Q_OBJECT

public:

QgsGpsMapRotationAction( QWidget *parent = nullptr );

QRadioButton *radioAlwaysRecenter() { return mRadioAlwaysRecenter; }
QRadioButton *radioRecenterWhenOutside() { return mRadioRecenterWhenOutside; }
QRadioButton *radioNeverRecenter() { return mRadioNeverRecenter; }

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

};

class QgsAppGpsSettingsMenu : public QMenu
{
Q_OBJECT
Expand Down Expand Up @@ -58,8 +78,6 @@ class QgsAppGpsSettingsMenu : public QMenu
QRadioButton *mRadioRecenterWhenOutside = nullptr;
QRadioButton *mRadioNeverRecenter = nullptr;



};

#endif // QGSAPPGPSSETTINGSMANAGER_H
12 changes: 12 additions & 0 deletions src/app/gps/qgsgpstoolbar.cpp
Expand Up @@ -20,8 +20,12 @@
#include "qgsproject.h"
#include "qgis.h"
#include "qgscoordinateutils.h"
#include "qgisapp.h"
#include "qgsappgpssettingsmenu.h"
#include "qgsapplication.h"

#include <QLabel>
#include <QToolButton>

QgsGpsToolBar::QgsGpsToolBar( QgsAppGpsConnection *connection, QgsMapCanvas *canvas, QWidget *parent )
: QToolBar( parent )
Expand Down Expand Up @@ -104,6 +108,14 @@ QgsGpsToolBar::QgsGpsToolBar( QgsAppGpsConnection *connection, QgsMapCanvas *can

connect( mConnection, &QgsAppGpsConnection::positionChanged, this, &QgsGpsToolBar::updateLocationLabel );
updateLocationLabel( mConnection->lastValidLocation() );

QToolButton *settingsButton = new QToolButton();
settingsButton->setAutoRaise( true );
settingsButton->setToolTip( tr( "Settings" ) );
settingsButton->setMenu( QgisApp::instance()->gpsSettingsMenu() );
settingsButton->setPopupMode( QToolButton::InstantPopup );
settingsButton->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mActionOptions.svg" ) ) );
addWidget( settingsButton );
}

void QgsGpsToolBar::updateLocationLabel( const QgsPoint &point )
Expand Down
21 changes: 20 additions & 1 deletion src/app/qgisapp.cpp
Expand Up @@ -250,6 +250,7 @@ Q_GUI_EXPORT extern int qt_defaultDpiX();
#include "qgsprojectionselectiondialog.h"
#include "qgsgpsinformationwidget.h"
#include "qgsappgpsconnection.h"
#include "qgsappgpssettingsmenu.h"
#include "qgsgpstoolbar.h"
#include "qgsgpscanvasbridge.h"
#include "qgsguivectorlayertools.h"
Expand Down Expand Up @@ -1395,10 +1396,21 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, bool skipBadLayers

// create the GPS tool on starting QGIS - this is like the browser
mGpsConnection = new QgsAppGpsConnection( this );
mGpsSettingsMenu = new QgsAppGpsSettingsMenu( this );

mGpsToolBar = new QgsGpsToolBar( mGpsConnection, mMapCanvas, this );
addToolBar( mGpsToolBar );

mGpsCanvasBridge = new QgsGpsCanvasBridge( mGpsConnection, mMapCanvas );
mGpsCanvasBridge->setLocationMarkerVisible( mGpsSettingsMenu->locationMarkerVisible() );
mGpsCanvasBridge->setBearingLineVisible( mGpsSettingsMenu->bearingLineVisible() );
mGpsCanvasBridge->setRotateMap( mGpsSettingsMenu->rotateMap() );
mGpsCanvasBridge->setMapCenteringMode( mGpsSettingsMenu->mapCenteringMode() );
connect( mGpsSettingsMenu, &QgsAppGpsSettingsMenu::locationMarkerToggled, mGpsCanvasBridge, &QgsGpsCanvasBridge::setLocationMarkerVisible );
connect( mGpsSettingsMenu, &QgsAppGpsSettingsMenu::bearingLineToggled, mGpsCanvasBridge, &QgsGpsCanvasBridge::setBearingLineVisible );
connect( mGpsSettingsMenu, &QgsAppGpsSettingsMenu::rotateMapToggled, mGpsCanvasBridge, &QgsGpsCanvasBridge::setRotateMap );
connect( mGpsSettingsMenu, &QgsAppGpsSettingsMenu::mapCenteringModeChanged, mGpsCanvasBridge, &QgsGpsCanvasBridge::setMapCenteringMode );

mpGpsWidget = new QgsGpsInformationWidget( mGpsConnection, mMapCanvas );
QgsPanelWidgetStack *gpsStack = new QgsPanelWidgetStack();
gpsStack->setMainPanel( mpGpsWidget );
Expand All @@ -1420,7 +1432,6 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, bool skipBadLayers
mpGpsDock->setToggleVisibilityAction( mGpsToolBar->showInfoAction() );
mpGpsDock->hide();

mGpsCanvasBridge = new QgsGpsCanvasBridge( mGpsConnection, mMapCanvas );

mLastMapToolMessage = nullptr;

Expand Down Expand Up @@ -1984,6 +1995,9 @@ QgisApp::~QgisApp()
delete mGpsCanvasBridge;
mGpsCanvasBridge = nullptr;

delete mGpsSettingsMenu;
mGpsSettingsMenu = nullptr;

delete mGpsConnection;
mGpsConnection = nullptr;

Expand Down Expand Up @@ -4900,6 +4914,11 @@ void QgisApp::setGpsPanelConnection( QgsGpsConnection *connection )
mGpsConnection->setConnection( connection );
}

QgsAppGpsSettingsMenu *QgisApp::gpsSettingsMenu()
{
return mGpsSettingsMenu;
}

void QgisApp::autoSelectAddedLayer( QList<QgsMapLayer *> layers )
{
if ( mBlockAutoSelectAddedLayer )
Expand Down
9 changes: 8 additions & 1 deletion src/app/qgisapp.h
Expand Up @@ -156,6 +156,7 @@ class QgsElevationProfileWidget;
class QgsScreenHelper;
class QgsAppGpsConnection;
class QgsGpsToolBar;
class QgsAppGpsSettingsMenu;

#include <QMainWindow>
#include <QToolBar>
Expand Down Expand Up @@ -883,6 +884,11 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
*/
void setGpsPanelConnection( QgsGpsConnection *connection );

/**
* Returns the GPS settings menu;
*/
QgsAppGpsSettingsMenu *gpsSettingsMenu();

//! Returns the application vertex editor
QgsVertexEditor *vertexEditor() { return mVertexEditorDock; }

Expand Down Expand Up @@ -2559,9 +2565,10 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow

//! Persistent GPS toolbox
QgsAppGpsConnection *mGpsConnection = nullptr;
QgsAppGpsSettingsMenu *mGpsSettingsMenu = nullptr;
QgsGpsInformationWidget *mpGpsWidget = nullptr;
QgsGpsToolBar *mGpsToolBar = nullptr;
QgsGpsCanvasBridge* mGpsCanvasBridge = nullptr;
QgsGpsCanvasBridge *mGpsCanvasBridge = nullptr;

QgsMessageBarItem *mLastMapToolMessage = nullptr;

Expand Down
94 changes: 9 additions & 85 deletions src/ui/qgsgpsinformationwidgetbase.ui
Expand Up @@ -711,72 +711,7 @@ gray = no data
</layout>
</widget>
</item>
<item row="5" column="0">
<widget class="QgsCollapsibleGroupBoxBasic" name="groupBox">
<property name="title">
<string>Map Centering</string>
</property>
<layout class="QGridLayout" name="gridLayout_8">
<property name="topMargin">
<number>2</number>
</property>
<property name="bottomMargin">
<number>4</number>
</property>
<property name="verticalSpacing">
<number>2</number>
</property>
<item row="0" column="0">
<widget class="QRadioButton" name="radRecenterMap">
<property name="text">
<string>Always</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QRadioButton" name="radNeverRecenter">
<property name="text">
<string>Never</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QRadioButton" name="radRecenterWhenNeeded">
<property name="text">
<string>When leaving map extent</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="2" column="0">
<widget class="QCheckBox" name="mCheckShowMarker">
<property name="text">
<string>Show GPS location cursor</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item row="7" column="0">
<spacer name="verticalSpacer_6">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item row="6" column="0">
<widget class="QgsCollapsibleGroupBox" name="mLogFileGroupBox">
<property name="enabled">
<bool>true</bool>
Expand Down Expand Up @@ -817,18 +752,17 @@ gray = no data
</widget>
</item>
<item row="3" column="0">
<widget class="QCheckBox" name="mShowBearingLineCheck">
<property name="text">
<string>Show bearing line</string>
<spacer name="verticalSpacer_6">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QCheckBox" name="mRotateMapCheckBox">
<property name="text">
<string>Rotate map to match GPS direction</string>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</widget>
</spacer>
</item>
</layout>
</widget>
Expand Down Expand Up @@ -1000,12 +934,6 @@ gray = no data
<header>qgsscrollarea.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>QgsCollapsibleGroupBoxBasic</class>
<extends>QGroupBox</extends>
<header location="global">qgscollapsiblegroupbox.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>QgsCollapsibleGroupBox</class>
<extends>QGroupBox</extends>
Expand Down Expand Up @@ -1045,10 +973,6 @@ gray = no data
<tabstop>mCboTimeZones</tabstop>
<tabstop>mCbxLeapSeconds</tabstop>
<tabstop>mLeapSeconds</tabstop>
<tabstop>mCheckShowMarker</tabstop>
<tabstop>radRecenterMap</tabstop>
<tabstop>radRecenterWhenNeeded</tabstop>
<tabstop>radNeverRecenter</tabstop>
<tabstop>mLogFileGroupBox</tabstop>
<tabstop>mLogFilename</tabstop>
<tabstop>mGPSPlainTextEdit</tabstop>
Expand Down

0 comments on commit a98b802

Please sign in to comment.