Skip to content
Permalink
Browse files
CRS selection dialog can now be opened inlined
  • Loading branch information
nyalldawson committed Jan 11, 2022
1 parent 6e7e8d3 commit adc7b6a1434f52d0d3e2186ef315c8cb9279c3f2
@@ -23,12 +23,6 @@ A generic widget allowing users to pick a Coordinate Reference System (or define
%End
public:

enum class CrsType
{
Predefined,
Custom,
};

QgsCrsSelectionWidget( QWidget *parent /TransferThis/ = 0 );
%Docstring
Constructor for QgsCrsSelectionWidget, with the specified ``parent`` widget.
@@ -125,6 +125,24 @@ ensemble datum, regardless of the ensemble's accuracy.
.. seealso:: :py:func:`setSourceEnsemble`

.. versionadded:: 3.20
%End

void setDialogTitle( const QString &title );
%Docstring
Sets the ``title`` for the CRS selector dialog window.

.. seealso:: :py:func:`dialogTitle`

.. versionadded:: 3.24
%End

QString dialogTitle() const;
%Docstring
Returns the title for the CRS selector dialog window.

.. seealso:: :py:func:`setDialogTitle`

.. versionadded:: 3.24
%End

signals:
@@ -115,6 +115,7 @@ QgsLayoutMapGridWidget::QgsLayoutMapGridWidget( QgsLayoutItemMapGrid *mapGrid, Q

mMapGridCrsSelector->setOptionVisible( QgsProjectionSelectionWidget::CrsNotSet, true );
mMapGridCrsSelector->setNotSetText( tr( "Use Map CRS" ) );
mMapGridCrsSelector->setDialogTitle( tr( "Grid CRS" ) );

connect( mMapGridCrsSelector, &QgsProjectionSelectionWidget::crsChanged, this, &QgsLayoutMapGridWidget::mapGridCrsChanged );

@@ -137,6 +137,7 @@ QgsLayoutMapWidget::QgsLayoutMapWidget( QgsLayoutItemMap *item, QgsMapCanvas *ma

mCrsSelector->setOptionVisible( QgsProjectionSelectionWidget::CrsNotSet, true );
mCrsSelector->setNotSetText( tr( "Use Project CRS" ) );
mCrsSelector->setDialogTitle( tr( "Map Item CRS" ) );

mOverviewFrameStyleButton->setSymbolType( Qgis::SymbolType::Fill );

@@ -124,6 +124,7 @@ void QgsCrsSelectionWidget::setShowNoCrs( bool show )
if ( mShowNoCrsOption == show )
return;

mBlockSignals++;
mShowNoCrsOption = show;
if ( mShowNoCrsOption )
{
@@ -139,6 +140,11 @@ void QgsCrsSelectionWidget::setShowNoCrs( bool show )
mComboCrsType->setCurrentIndex( 0 );
}

mBlockSignals--;

if ( mDeferedInvalidCrsSet )
emit crsChanged();

mDeferedInvalidCrsSet = false;

emit hasValidSelectionChanged( hasValidSelection() );
@@ -165,6 +171,8 @@ bool QgsCrsSelectionWidget::hasValidSelection() const
{
if ( !mComboCrsType->currentData().isValid() )
return true;
else if ( mDeferedInvalidCrsSet )
return false;
else
{
switch ( static_cast< CrsType >( mComboCrsType->currentData().toInt() ) )
@@ -197,6 +205,7 @@ QgsCoordinateReferenceSystem QgsCrsSelectionWidget::crs() const

void QgsCrsSelectionWidget::setCrs( const QgsCoordinateReferenceSystem &crs )
{
mBlockSignals++;
if ( !crs.isValid() )
{
if ( mShowNoCrsOption )
@@ -219,6 +228,7 @@ void QgsCrsSelectionWidget::setCrs( const QgsCoordinateReferenceSystem &crs )
mStackedWidget->setCurrentWidget( mPageDatabase );
}
}
mBlockSignals--;

emit crsChanged();
emit hasValidSelectionChanged( hasValidSelection() );
@@ -41,15 +41,6 @@ class GUI_EXPORT QgsCrsSelectionWidget : public QgsPanelWidget, private Ui::QgsG
Q_OBJECT
public:

/**
* CRS types
*/
enum class CrsType
{
Predefined, //!< Predefined (from database )
Custom, //!< Custom CRS
};

/**
* Constructor for QgsCrsSelectionWidget, with the specified \a parent widget.
*/
@@ -137,6 +128,15 @@ class GUI_EXPORT QgsCrsSelectionWidget : public QgsPanelWidget, private Ui::QgsG

private:

/**
* CRS types
*/
enum class CrsType
{
Predefined, //!< Predefined (from database )
Custom, //!< Custom CRS
};

QString mNotSetText;
bool mShowNoCrsOption = false;
bool mDeferedInvalidCrsSet = false;
@@ -26,7 +26,9 @@

QgsProjectionSelectionWidget::QgsProjectionSelectionWidget( QWidget *parent )
: QWidget( parent )
, mDialogTitle( tr( "Select CRS" ) )
{

mCrsComboBox = new QgsHighlightableComboBox( this );
mCrsComboBox->addItem( tr( "invalid projection" ), QgsProjectionSelectionWidget::CurrentCrs );
mCrsComboBox->setSizePolicy( QSizePolicy::Ignored, QSizePolicy::Preferred );
@@ -197,33 +199,75 @@ bool QgsProjectionSelectionWidget::optionVisible( QgsProjectionSelectionWidget::

void QgsProjectionSelectionWidget::selectCrs()
{
//find out crs id of current proj4 string
QgsProjectionSelectionDialog dlg( this );
if ( !mMessage.isEmpty() )
dlg.setMessage( mMessage );
dlg.setCrs( mCrs );
QgsPanelWidget *panel = QgsPanelWidget::findParentPanel( this );
if ( panel && panel->dockMode() )
{
mActivePanel = new QgsCrsSelectionWidget( this );
if ( !mMessage.isEmpty() )
mActivePanel->setMessage( mMessage );
mActivePanel->setCrs( mCrs );

if ( !mNotSetText.isEmpty() )
dlg.setNotSetText( mNotSetText );
if ( !mNotSetText.isEmpty() )
mActivePanel->setNotSetText( mNotSetText );

if ( optionVisible( QgsProjectionSelectionWidget::CrsOption::CrsNotSet ) )
{
dlg.setShowNoProjection( true );
}
dlg.setRequireValidSelection();
mActivePanel->setPanelTitle( mDialogTitle );

if ( dlg.exec() )
{
mCrsComboBox->blockSignals( true );
mCrsComboBox->setCurrentIndex( mCrsComboBox->findData( QgsProjectionSelectionWidget::CurrentCrs ) );
mCrsComboBox->blockSignals( false );
const QgsCoordinateReferenceSystem crs = dlg.crs();
setCrs( crs );
emit crsChanged( crs );
if ( optionVisible( QgsProjectionSelectionWidget::CrsOption::CrsNotSet ) )
{
mActivePanel->setShowNoCrs( true );
}

connect( mActivePanel, &QgsCrsSelectionWidget::crsChanged, this, [ this ]
{
if ( mIgnorePanelSignals )
return;

if ( !mActivePanel->hasValidSelection() )
return;

mCrsComboBox->blockSignals( true );
mCrsComboBox->setCurrentIndex( mCrsComboBox->findData( QgsProjectionSelectionWidget::CurrentCrs ) );
mCrsComboBox->blockSignals( false );
const QgsCoordinateReferenceSystem crs = mActivePanel->crs();

mIgnorePanelSignals++;
setCrs( crs );
mIgnorePanelSignals--;

emit crsChanged( crs );
} );
panel->openPanel( mActivePanel );
}
else
{
QApplication::restoreOverrideCursor();
QgsProjectionSelectionDialog dlg( this );
if ( !mMessage.isEmpty() )
dlg.setMessage( mMessage );
dlg.setCrs( mCrs );
dlg.setWindowTitle( mDialogTitle );

if ( !mNotSetText.isEmpty() )
dlg.setNotSetText( mNotSetText );

if ( optionVisible( QgsProjectionSelectionWidget::CrsOption::CrsNotSet ) )
{
dlg.setShowNoProjection( true );
}
dlg.setRequireValidSelection();

if ( dlg.exec() )
{
mCrsComboBox->blockSignals( true );
mCrsComboBox->setCurrentIndex( mCrsComboBox->findData( QgsProjectionSelectionWidget::CurrentCrs ) );
mCrsComboBox->blockSignals( false );
const QgsCoordinateReferenceSystem crs = dlg.crs();
setCrs( crs );
emit crsChanged( crs );
}
else
{
QApplication::restoreOverrideCursor();
}
}
}

@@ -294,6 +338,16 @@ QString QgsProjectionSelectionWidget::sourceEnsemble() const
return mSourceEnsemble;
}

void QgsProjectionSelectionWidget::setDialogTitle( const QString &title )
{
mDialogTitle = title;
}

QString QgsProjectionSelectionWidget::dialogTitle() const
{
return mDialogTitle;
}

void QgsProjectionSelectionWidget::setSourceEnsemble( const QString &ensemble )
{
if ( mSourceEnsemble == ensemble )
@@ -448,6 +502,12 @@ void QgsProjectionSelectionWidget::setCrs( const QgsCoordinateReferenceSystem &c
crsOptionText( crs ) );
}
}
if ( mActivePanel && !mIgnorePanelSignals )
{
mIgnorePanelSignals++;
mActivePanel->setCrs( crs );
mIgnorePanelSignals--;
}
if ( mCrs != crs )
{
mCrs = crs;
@@ -22,12 +22,13 @@
#include <QLineEdit>
#include <QToolButton>
#include <QComboBox>
#include <QPointer>

#include "qgscoordinatereferencesystem.h"
#include "qgis_gui.h"

class QgsProjectionSelectionDialog;
class QgsHighlightableComboBox;
class QgsCrsSelectionWidget;
class QLabel;

/**
@@ -141,6 +142,20 @@ class GUI_EXPORT QgsProjectionSelectionWidget : public QWidget
*/
QString sourceEnsemble() const;

/**
* Sets the \a title for the CRS selector dialog window.
* \see dialogTitle()
* \since QGIS 3.24
*/
void setDialogTitle( const QString &title );

/**
* Returns the title for the CRS selector dialog window.
* \see setDialogTitle()
* \since QGIS 3.24
*/
QString dialogTitle() const;

signals:

/**
@@ -188,7 +203,6 @@ class GUI_EXPORT QgsProjectionSelectionWidget : public QWidget
QgsCoordinateReferenceSystem mDefaultCrs;
QgsHighlightableComboBox *mCrsComboBox = nullptr;
QToolButton *mButton = nullptr;
QgsProjectionSelectionDialog *mDialog = nullptr;
QString mNotSetText;
QString mMessage;

@@ -198,6 +212,11 @@ class GUI_EXPORT QgsProjectionSelectionWidget : public QWidget
QWidget *mWarningLabelContainer = nullptr;
QLabel *mWarningLabel = nullptr;

QPointer< QgsCrsSelectionWidget > mActivePanel;
int mIgnorePanelSignals = 0;

QString mDialogTitle;

void addNotSetOption();
void addProjectCrsOption();
void addDefaultCrsOption();
@@ -62,6 +62,7 @@ ADD_PYTHON_TEST(PyQgsConditionalStyle test_qgsconditionalstyle.py)
ADD_PYTHON_TEST(PyQgsConnectionRegistry test_qgsconnectionregistry.py)
ADD_PYTHON_TEST(PyQgsCoordinateTransformContext test_qgscoordinatetransformcontext.py)
ADD_PYTHON_TEST(PyQgsCrsDefinitionWidget test_qgscrsdefinitionwidget.py)
ADD_PYTHON_TEST(PyQgsCrsSelectionWidget test_qgscrsselectionwidget.py)
ADD_PYTHON_TEST(PyQgsDefaultValue test_qgsdefaultvalue.py)
ADD_PYTHON_TEST(PyQgsXmlUtils test_qgsxmlutils.py)
ADD_PYTHON_TEST(PyQgsCore test_qgscore.py)
@@ -19,7 +19,7 @@
start_app()


class TestQgsCrsDefinitionWidge(unittest.TestCase):
class TestQgsCrsDefinitionWidget(unittest.TestCase):

def testWidget(self):
"""

0 comments on commit adc7b6a

Please sign in to comment.