Skip to content

Commit

Permalink
Place 3d tab in vector properties at the correct position
Browse files Browse the repository at this point in the history
Fixes #35010
  • Loading branch information
nyalldawson committed Jun 9, 2020
1 parent 3c0ecbf commit ce9f519
Show file tree
Hide file tree
Showing 9 changed files with 144 additions and 11 deletions.
14 changes: 14 additions & 0 deletions python/gui/auto_generated/qgsmaplayerconfigwidgetfactory.sip.in
Expand Up @@ -92,6 +92,20 @@ Flag if widget is supported for use in layer properties dialog.
The default implementation returns ``False``.

:return: ``True`` if supported
%End

virtual QString layerPropertiesPagePositionHint() const;
%Docstring
Returns a tab name hinting at where this page should be inserted into the
layer properties tab list.

If the returned string is non-empty, the config widget page will be inserted
before the existing page with matching object name.

The default implementation returns an empty string, which causes the widget
to be placed at the end of the dialog page list.

.. versionadded:: 3.14
%End

void setSupportLayerPropertiesDialog( bool supports );
Expand Down
29 changes: 29 additions & 0 deletions python/gui/auto_generated/qgsoptionsdialogbase.sip.in
Expand Up @@ -91,6 +91,35 @@ Determine if the options list is in icon only mode
%Docstring
Sets the dialog ``page`` (by object name) to show.

.. versionadded:: 3.14
%End

void addPage( const QString &title, const QString &tooltip, const QIcon &icon, QWidget *widget /Transfer/ );
%Docstring
Adds a new page to the dialog pages.

The ``title``, ``tooltip`` and ``icon`` arguments dictate the page list item title, tooltip and icon respectively.

The page content is specified via the ``widget`` argument. Ownership of ``widget`` is transferred to the dialog.

.. seealso:: :py:func:`insertPage`

.. versionadded:: 3.14
%End

void insertPage( const QString &title, const QString &tooltip, const QIcon &icon, QWidget *widget /Transfer/, const QString &before );
%Docstring
Inserts a new page into the dialog pages.

The ``title``, ``tooltip`` and ``icon`` arguments dictate the page list item title, tooltip and icon respectively.

The page content is specified via the ``widget`` argument. Ownership of ``widget`` is transferred to the dialog.

The ``before`` argument specifies the object name of an existing page. The new page will be inserted directly
before the matching page.

.. seealso:: :py:func:`addPage`

.. versionadded:: 3.14
%End

Expand Down
10 changes: 10 additions & 0 deletions src/app/3d/qgsvectorlayer3drendererwidget.cpp
Expand Up @@ -208,7 +208,17 @@ QgsMapLayerConfigWidget *QgsVectorLayer3DRendererWidgetFactory::createWidget( Qg
return new QgsVectorLayer3DRendererWidget( layer, canvas, parent );
}

bool QgsVectorLayer3DRendererWidgetFactory::supportLayerPropertiesDialog() const
{
return true;
}

bool QgsVectorLayer3DRendererWidgetFactory::supportsLayer( QgsMapLayer *layer ) const
{
return layer->type() == QgsMapLayerType::VectorLayer;
}

QString QgsVectorLayer3DRendererWidgetFactory::layerPropertiesPagePositionHint() const
{
return QStringLiteral( "mOptsPage_Diagrams" );
}
6 changes: 3 additions & 3 deletions src/app/3d/qgsvectorlayer3drendererwidget.h
Expand Up @@ -92,11 +92,11 @@ class QgsVectorLayer3DRendererWidgetFactory : public QObject, public QgsMapLayer
Q_OBJECT
public:
explicit QgsVectorLayer3DRendererWidgetFactory( QObject *parent = nullptr );
QgsMapLayerConfigWidget *createWidget( QgsMapLayer *layer, QgsMapCanvas *canvas, bool dockWidget, QWidget *parent ) const override;

bool supportLayerPropertiesDialog() const override { return true; }

QgsMapLayerConfigWidget *createWidget( QgsMapLayer *layer, QgsMapCanvas *canvas, bool dockWidget, QWidget *parent ) const override;
bool supportLayerPropertiesDialog() const override;
bool supportsLayer( QgsMapLayer *layer ) const override;
QString layerPropertiesPagePositionHint() const override;
};


Expand Down
5 changes: 5 additions & 0 deletions src/gui/qgsmaplayerconfigwidgetfactory.cpp
Expand Up @@ -21,6 +21,11 @@ QgsMapLayerConfigWidgetFactory::QgsMapLayerConfigWidgetFactory( const QString &t
{
}

QString QgsMapLayerConfigWidgetFactory::layerPropertiesPagePositionHint() const
{
return QString();
}

bool QgsMapLayerConfigWidgetFactory::supportsLayer( QgsMapLayer *layer ) const
{
Q_UNUSED( layer )
Expand Down
14 changes: 14 additions & 0 deletions src/gui/qgsmaplayerconfigwidgetfactory.h
Expand Up @@ -89,6 +89,20 @@ class GUI_EXPORT QgsMapLayerConfigWidgetFactory
*/
virtual bool supportLayerPropertiesDialog() const { return false; }

/**
* Returns a tab name hinting at where this page should be inserted into the
* layer properties tab list.
*
* If the returned string is non-empty, the config widget page will be inserted
* before the existing page with matching object name.
*
* The default implementation returns an empty string, which causes the widget
* to be placed at the end of the dialog page list.
*
* \since QGIS 3.14
*/
virtual QString layerPropertiesPagePositionHint() const;

/**
* Set support flag for style dock
* \param supports TRUE if this widget is supported in the style dock.
Expand Down
36 changes: 36 additions & 0 deletions src/gui/qgsoptionsdialogbase.cpp
Expand Up @@ -254,6 +254,42 @@ void QgsOptionsDialogBase::setCurrentPage( const QString &page )
}
}

void QgsOptionsDialogBase::addPage( const QString &title, const QString &tooltip, const QIcon &icon, QWidget *widget )
{
QListWidgetItem *item = new QListWidgetItem();
item->setIcon( icon );
item->setText( title );
item->setToolTip( tooltip );

mOptListWidget->addItem( item );
mOptStackedWidget->addWidget( widget );
}

void QgsOptionsDialogBase::insertPage( const QString &title, const QString &tooltip, const QIcon &icon, QWidget *widget, const QString &before )
{
//find the page with a matching widget name
for ( int idx = 0; idx < mOptStackedWidget->count(); ++idx )
{
QWidget *currentPage = mOptStackedWidget->widget( idx );
if ( currentPage->objectName() == before )
{
//found the "before" page

QListWidgetItem *item = new QListWidgetItem();
item->setIcon( icon );
item->setText( title );
item->setToolTip( tooltip );

mOptListWidget->insertItem( idx, item );
mOptStackedWidget->insertWidget( idx, widget );
return;
}
}

// no matching pages, so just add the page
addPage( title, tooltip, icon, widget );
}

void QgsOptionsDialogBase::searchText( const QString &text )
{
const int minimumTextLength = 3;
Expand Down
27 changes: 27 additions & 0 deletions src/gui/qgsoptionsdialogbase.h
Expand Up @@ -117,6 +117,33 @@ class GUI_EXPORT QgsOptionsDialogBase : public QDialog
*/
void setCurrentPage( const QString &page );

/**
* Adds a new page to the dialog pages.
*
* The \a title, \a tooltip and \a icon arguments dictate the page list item title, tooltip and icon respectively.
*
* The page content is specified via the \a widget argument. Ownership of \a widget is transferred to the dialog.
*
* \see insertPage()
* \since QGIS 3.14
*/
void addPage( const QString &title, const QString &tooltip, const QIcon &icon, QWidget *widget SIP_TRANSFER );

/**
* Inserts a new page into the dialog pages.
*
* The \a title, \a tooltip and \a icon arguments dictate the page list item title, tooltip and icon respectively.
*
* The page content is specified via the \a widget argument. Ownership of \a widget is transferred to the dialog.
*
* The \a before argument specifies the object name of an existing page. The new page will be inserted directly
* before the matching page.
*
* \see addPage()
* \since QGIS 3.14
*/
void insertPage( const QString &title, const QString &tooltip, const QIcon &icon, QWidget *widget SIP_TRANSFER, const QString &before );

public slots:

/**
Expand Down
14 changes: 6 additions & 8 deletions src/gui/vector/qgsvectorlayerproperties.cpp
Expand Up @@ -462,16 +462,14 @@ void QgsVectorLayerProperties::addPropertiesPageFactory( QgsMapLayerConfigWidget
return;
}

QListWidgetItem *item = new QListWidgetItem();
item->setIcon( factory->icon() );
item->setText( factory->title() );
item->setToolTip( factory->title() );

mOptionsListWidget->addItem( item );

QgsMapLayerConfigWidget *page = factory->createWidget( mLayer, nullptr, false, this );
mLayerPropertiesPages << page;
mOptionsStackedWidget->addWidget( page );

const QString beforePage = factory->layerPropertiesPagePositionHint();
if ( beforePage.isEmpty() )
addPage( factory->title(), factory->title(), factory->icon(), page );
else
insertPage( factory->title(), factory->title(), factory->icon(), page, beforePage );
}

void QgsVectorLayerProperties::insertFieldOrExpression()
Expand Down

0 comments on commit ce9f519

Please sign in to comment.