Skip to content

Commit

Permalink
[FEATURE] Add setting for format to show angular bearings to projects
Browse files Browse the repository at this point in the history
and profile options

The Settings - Options - Map Tools tab contains a new setting for
controlling the default format to use for displaying angular bearings for
newly created projects. Whenever a new project is created, it will
inherit this default settings.

The Project Properties dialog also has a new setting for the project-specific
bearing format.

The intention is that whenever angular bearings are shown in QGIS,
they will be formatted using the current project's bearing format
settings.
  • Loading branch information
nyalldawson committed Jan 9, 2020
1 parent 338dcae commit c0ad430
Show file tree
Hide file tree
Showing 16 changed files with 293 additions and 35 deletions.
Expand Up @@ -42,7 +42,7 @@ Default constructor

virtual QString formatDouble( double value, const QgsNumericFormatContext &context ) const;

virtual QgsNumericFormat *clone() const /Factory/;
virtual QgsBearingNumericFormat *clone() const /Factory/;

virtual QgsNumericFormat *create( const QVariantMap &configuration, const QgsReadWriteContext &context ) const /Factory/;

Expand Down
Expand Up @@ -110,6 +110,36 @@ Constructor for QgsBearingNumericFormatWidget, initially showing the specified `
};


class QgsBearingNumericFormatDialog : QDialog
{
%Docstring
A dialog which allow control over the properties of a :py:class:`QgsBearingNumericFormat`.

.. versionadded:: 3.12
%End

%TypeHeaderCode
#include "qgsnumericformatwidget.h"
%End
public:

QgsBearingNumericFormatDialog( const QgsNumericFormat *format, QWidget *parent /TransferThis/ = 0 );
%Docstring
Constructor for QgsBearingNumericFormatDialog, initially showing the specified ``format``.
%End

QgsBearingNumericFormat *format() /Factory/;
%Docstring
Returns the format defined by the current settings in the dialog.

Ownership of the returned object is transferred to the caller
%End

};






class QgsCurrencyNumericFormatWidget : QgsNumericFormatWidget
Expand Down
2 changes: 2 additions & 0 deletions src/app/CMakeLists.txt
Expand Up @@ -438,6 +438,7 @@ INCLUDE_DIRECTORIES(
${CMAKE_SOURCE_DIR}/src/core/geocms/geonode
${CMAKE_SOURCE_DIR}/src/core/metadata
${CMAKE_SOURCE_DIR}/src/core/mesh
${CMAKE_SOURCE_DIR}/src/core/numericformats
${CMAKE_SOURCE_DIR}/src/core/labeling
${CMAKE_SOURCE_DIR}/src/core/layertree
${CMAKE_SOURCE_DIR}/src/core/locator
Expand All @@ -454,6 +455,7 @@ INCLUDE_DIRECTORIES(
${CMAKE_SOURCE_DIR}/src/gui/auth
${CMAKE_SOURCE_DIR}/src/gui/labeling
${CMAKE_SOURCE_DIR}/src/gui/ogr
${CMAKE_SOURCE_DIR}/src/gui/numericformats
${CMAKE_SOURCE_DIR}/src/gui/processing
${CMAKE_SOURCE_DIR}/src/gui/raster
${CMAKE_SOURCE_DIR}/src/gui/editorwidgets
Expand Down
18 changes: 18 additions & 0 deletions src/app/qgsoptions.cpp
Expand Up @@ -36,6 +36,8 @@
#include "qgsrasterminmaxorigin.h"
#include "qgscontrastenhancement.h"
#include "qgsexpressioncontextutils.h"
#include "qgslocaldefaultsettings.h"
#include "qgsnumericformatwidget.h"

#include "qgsattributetablefiltermodel.h"
#include "qgsrasterformatsaveoptionswidget.h"
Expand All @@ -55,6 +57,7 @@
#include "qgsgui.h"
#include "qgswelcomepage.h"
#include "qgsnewsfeedparser.h"
#include "qgsbearingnumericformat.h"

#ifdef HAVE_OPENCL
#include "qgsopenclutils.h"
Expand Down Expand Up @@ -1198,6 +1201,9 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WindowFlags fl, const QList<QgsOpti
// restore window and widget geometry/state
connect( mRestoreDefaultWindowStateBtn, &QAbstractButton::clicked, this, &QgsOptions::restoreDefaultWindowState );

mBearingFormat.reset( QgsLocalDefaultSettings::bearingFormat() );
connect( mCustomizeBearingFormatButton, &QPushButton::clicked, this, &QgsOptions::customizeBearingFormat );

restoreOptionsBaseUi();

#ifdef QGISDEBUG
Expand Down Expand Up @@ -1755,6 +1761,8 @@ void QgsOptions::saveOptions()
// Number settings
mSettings->setValue( QStringLiteral( "locale/showGroupSeparator" ), cbShowGroupSeparator->isChecked( ) );

QgsLocalDefaultSettings::setBearingFormat( mBearingFormat.release() );

#ifdef HAVE_OPENCL
// OpenCL settings
QgsOpenClUtils::setEnabled( mGPUEnableCheckBox->isChecked() );
Expand Down Expand Up @@ -2667,3 +2675,13 @@ void QgsOptions::showHelp()
}
QgsHelp::openHelp( link );
}

void QgsOptions::customizeBearingFormat()
{
QgsBearingNumericFormatDialog dlg( mBearingFormat.get(), this );
dlg.setWindowTitle( tr( "Bearing Format" ) );
if ( dlg.exec() )
{
mBearingFormat.reset( dlg.format() );
}
}
5 changes: 5 additions & 0 deletions src/app/qgsoptions.h
Expand Up @@ -33,6 +33,7 @@ class QgsExpressionContext;
class QgsOptionsPageWidget;
class QgsLocatorOptionsWidget;
class QgsAuthConfigSelect;
class QgsBearingNumericFormat;

/**
* \class QgsOptions
Expand Down Expand Up @@ -265,6 +266,8 @@ class APP_EXPORT QgsOptions : public QgsOptionsDialogBase, private Ui::QgsOption

void updateSampleLocaleText();

void customizeBearingFormat();

protected:
QgisAppStyleSheet *mStyleSheetBuilder = nullptr;
QMap<QString, QVariant> mStyleSheetNewOpts;
Expand All @@ -278,6 +281,8 @@ class APP_EXPORT QgsOptions : public QgsOptionsDialogBase, private Ui::QgsOption
QList< QgsOptionsPageWidget * > mAdditionalOptionWidgets;
QgsLocatorOptionsWidget *mLocatorOptionsWidget = nullptr;

std::unique_ptr< QgsBearingNumericFormat > mBearingFormat;

void updateActionsForCurrentColorScheme( QgsColorScheme *scheme );

void checkPageWidgetNameMap();
Expand Down
21 changes: 20 additions & 1 deletion src/app/qgsprojectproperties.cpp
Expand Up @@ -66,6 +66,9 @@
#include "qgsprojectstorage.h"
#include "qgsprojectstorageregistry.h"
#include "qgsprojectviewsettings.h"
#include "qgsnumericformatwidget.h"
#include "qgsbearingnumericformat.h"
#include "qgsprojectdisplaysettings.h"

//qt includes
#include <QInputDialog>
Expand Down Expand Up @@ -115,6 +118,7 @@ QgsProjectProperties::QgsProjectProperties( QgsMapCanvas *mapCanvas, QWidget *pa
connect( pbtnStyleColorRamp, &QToolButton::clicked, this, &QgsProjectProperties::pbtnStyleColorRamp_clicked );
connect( mButtonAddColor, &QToolButton::clicked, this, &QgsProjectProperties::mButtonAddColor_clicked );
connect( buttonBox, &QDialogButtonBox::helpRequested, this, &QgsProjectProperties::showHelp );
connect( mCustomizeBearingFormatButton, &QPushButton::clicked, this, &QgsProjectProperties::customizeBearingFormat );

// QgsOptionsDialogBase handles saving/restoring of geometry, splitter and current tab states,
// switching vertical tabs between icon/text to icon-only modes (splitter collapsed to left),
Expand Down Expand Up @@ -954,17 +958,21 @@ QgsProjectProperties::QgsProjectProperties( QgsMapCanvas *mapCanvas, QWidget *pa
// Reading ellipsoid from settings
setCurrentEllipsoid( QgsProject::instance()->ellipsoid() );

mBearingFormat.reset( QgsProject::instance()->displaySettings()->bearingFormat()->clone() );

restoreOptionsBaseUi();

#ifdef QGISDEBUG
checkPageWidgetNameMap();
#endif
}

QgsProjectProperties::~QgsProjectProperties() = default;

QString QgsProjectProperties::title() const
{
return titleEdit->text();
} // QgsProjectPropertires::title() const
}

void QgsProjectProperties::title( QString const &title )
{
Expand Down Expand Up @@ -1486,6 +1494,8 @@ void QgsProjectProperties::apply()
//save variables
QgsProject::instance()->setCustomVariables( mVariableEditor->variablesInActiveScope() );

QgsProject::instance()->displaySettings()->setBearingFormat( mBearingFormat->clone() );

//refresh canvases to reflect new properties, eg background color and scale bar after changing display units.
for ( QgsMapCanvas *canvas : constMapCanvases )
{
Expand Down Expand Up @@ -2593,3 +2603,12 @@ void QgsProjectProperties::onGenerateTsFileButton() const
"When you open it again in QGIS having set the target language (de), the project will be translated and saved with postfix (eg. aproject_de.qgs)." ).arg( l ) ) ;
}

void QgsProjectProperties::customizeBearingFormat()
{
QgsBearingNumericFormatDialog dlg( mBearingFormat.get(), this );
dlg.setWindowTitle( tr( "Bearing Format" ) );
if ( dlg.exec() )
{
mBearingFormat.reset( dlg.format() );
}
}
9 changes: 9 additions & 0 deletions src/app/qgsprojectproperties.h
Expand Up @@ -34,6 +34,7 @@ class QgsLayerTreeGroup;
class QgsMetadataWidget;
class QgsTreeWidgetItem;
class QgsLayerCapabilitiesModel;
class QgsBearingNumericFormat;

/**
* Dialog to set project level properties
Expand All @@ -49,6 +50,8 @@ class APP_EXPORT QgsProjectProperties : public QgsOptionsDialogBase, private Ui:
//! Constructor
QgsProjectProperties( QgsMapCanvas *mapCanvas, QWidget *parent = nullptr, Qt::WindowFlags fl = QgsGuiUtils::ModalDialogFlags );

~QgsProjectProperties() override;

void setCurrentPage( const QString & );

/**
Expand Down Expand Up @@ -177,6 +180,10 @@ class APP_EXPORT QgsProjectProperties : public QgsOptionsDialogBase, private Ui:
//! Signal used to inform listeners that the mouse display precision may have changed
void displayPrecisionChanged();

private slots:

void customizeBearingFormat();

private:

/**
Expand Down Expand Up @@ -226,6 +233,8 @@ class APP_EXPORT QgsProjectProperties : public QgsOptionsDialogBase, private Ui:
int mEllipsoidIndex;
bool mBlockCrsUpdates = false;

std::unique_ptr< QgsBearingNumericFormat > mBearingFormat;

//! populate WMTS tree
void populateWmtsTree( const QgsLayerTreeGroup *treeGroup, QgsTreeWidgetItem *treeItem );
//! add WMTS Grid definition based on CRS
Expand Down
2 changes: 1 addition & 1 deletion src/core/numericformats/qgsbearingnumericformat.cpp
Expand Up @@ -84,7 +84,7 @@ QString QgsBearingNumericFormat::formatDouble( double value, const QgsNumericFor
return QgsBasicNumericFormat::formatDouble( value, context );
}

QgsNumericFormat *QgsBearingNumericFormat::clone() const
QgsBearingNumericFormat *QgsBearingNumericFormat::clone() const
{
return new QgsBearingNumericFormat( *this );
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/numericformats/qgsbearingnumericformat.h
Expand Up @@ -50,7 +50,7 @@ class CORE_EXPORT QgsBearingNumericFormat : public QgsBasicNumericFormat
int sortKey() override;
double suggestSampleValue() const override;
QString formatDouble( double value, const QgsNumericFormatContext &context ) const override;
QgsNumericFormat *clone() const override SIP_FACTORY;
QgsBearingNumericFormat *clone() const override SIP_FACTORY;
QgsNumericFormat *create( const QVariantMap &configuration, const QgsReadWriteContext &context ) const override SIP_FACTORY;
QVariantMap configuration( const QgsReadWriteContext &context ) const override;

Expand Down
32 changes: 32 additions & 0 deletions src/gui/numericformats/qgsnumericformatwidget.cpp
Expand Up @@ -19,7 +19,9 @@
#include "qgspercentagenumericformat.h"
#include "qgsbearingnumericformat.h"
#include "qgsscientificnumericformat.h"
#include "qgsgui.h"
#include "qgis.h"
#include <QDialogButtonBox>

//
// QgsBasicNumericFormatWidget
Expand Down Expand Up @@ -133,6 +135,35 @@ QgsNumericFormat *QgsBearingNumericFormatWidget::format()
return mFormat->clone();
}

//
// QgsBearingNumericFormatDialog
//

QgsBearingNumericFormatDialog::QgsBearingNumericFormatDialog( const QgsNumericFormat *format, QWidget *parent )
: QDialog( parent )
{
setLayout( new QVBoxLayout() );
mWidget = new QgsBearingNumericFormatWidget( format );
QDialogButtonBox *buttonBox = new QDialogButtonBox( QDialogButtonBox::Cancel | QDialogButtonBox::Ok );

connect( buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept );
connect( buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject );

layout()->addWidget( mWidget );
layout()->addWidget( buttonBox );

connect( mWidget, &QgsPanelWidget::panelAccepted, this, &QDialog::reject );

setObjectName( QStringLiteral( "QgsBearingNumericFormatDialog" ) );
QgsGui::instance()->enableAutoGeometryRestore( this );
}

QgsBearingNumericFormat *QgsBearingNumericFormatDialog::format()
{
return static_cast< QgsBearingNumericFormat * >( mWidget->format() );
}



//
// QgsCurrencyNumericFormatWidget
Expand Down Expand Up @@ -312,3 +343,4 @@ QgsNumericFormat *QgsScientificNumericFormatWidget::format()
return mFormat->clone();
}


33 changes: 33 additions & 0 deletions src/gui/numericformats/qgsnumericformatwidget.h
Expand Up @@ -19,6 +19,7 @@
#include "qgsnumericformat.h"
#include "qgspanelwidget.h"
#include <memory>
#include <QDialog>

/**
* \ingroup gui
Expand Down Expand Up @@ -129,6 +130,38 @@ class GUI_EXPORT QgsBearingNumericFormatWidget : public QgsNumericFormatWidget,
};


/**
* \ingroup gui
* \class QgsBearingNumericFormatDialog
* A dialog which allow control over the properties of a QgsBearingNumericFormat.
* \since QGIS 3.12
*/
class GUI_EXPORT QgsBearingNumericFormatDialog : public QDialog
{
Q_OBJECT

public:

/**
* Constructor for QgsBearingNumericFormatDialog, initially showing the specified \a format.
*/
QgsBearingNumericFormatDialog( const QgsNumericFormat *format, QWidget *parent SIP_TRANSFERTHIS = nullptr );

/**
* Returns the format defined by the current settings in the dialog.
*
* Ownership of the returned object is transferred to the caller
*/
QgsBearingNumericFormat *format() SIP_FACTORY;

private:

QgsBearingNumericFormatWidget *mWidget = nullptr;
};




#include "ui_qgscurrencynumericformatwidgetbase.h"

class QgsCurrencyNumericFormat;
Expand Down

0 comments on commit c0ad430

Please sign in to comment.