Skip to content
Permalink
Browse files

[FEATURE] Add setting for format to show angular bearings to projects

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 8, 2020
1 parent 338dcae commit c0ad4303d24954c29c1e567024dfe5163c542e33
@@ -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/;

@@ -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
@@ -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
@@ -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
@@ -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"
@@ -55,6 +57,7 @@
#include "qgsgui.h"
#include "qgswelcomepage.h"
#include "qgsnewsfeedparser.h"
#include "qgsbearingnumericformat.h"

#ifdef HAVE_OPENCL
#include "qgsopenclutils.h"
@@ -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
@@ -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() );
@@ -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() );
}
}
@@ -33,6 +33,7 @@ class QgsExpressionContext;
class QgsOptionsPageWidget;
class QgsLocatorOptionsWidget;
class QgsAuthConfigSelect;
class QgsBearingNumericFormat;

/**
* \class QgsOptions
@@ -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;
@@ -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();
@@ -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>
@@ -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),
@@ -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 )
{
@@ -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 )
{
@@ -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() );
}
}
@@ -34,6 +34,7 @@ class QgsLayerTreeGroup;
class QgsMetadataWidget;
class QgsTreeWidgetItem;
class QgsLayerCapabilitiesModel;
class QgsBearingNumericFormat;

/**
* Dialog to set project level properties
@@ -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 & );

/**
@@ -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:

/**
@@ -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
@@ -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 );
}
@@ -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;

@@ -19,7 +19,9 @@
#include "qgspercentagenumericformat.h"
#include "qgsbearingnumericformat.h"
#include "qgsscientificnumericformat.h"
#include "qgsgui.h"
#include "qgis.h"
#include <QDialogButtonBox>

//
// QgsBasicNumericFormatWidget
@@ -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
@@ -312,3 +343,4 @@ QgsNumericFormat *QgsScientificNumericFormatWidget::format()
return mFormat->clone();
}


@@ -19,6 +19,7 @@
#include "qgsnumericformat.h"
#include "qgspanelwidget.h"
#include <memory>
#include <QDialog>

/**
* \ingroup gui
@@ -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;

0 comments on commit c0ad430

Please sign in to comment.
You can’t perform that action at this time.