Skip to content
Permalink
Browse files

Place 3d tab in vector properties at the correct position

Fixes #35010
  • Loading branch information
nyalldawson committed Jun 9, 2020
1 parent 3c0ecbf commit ce9f519468d46bb6fe6dd0bc68efd7d58129be68
@@ -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 );
@@ -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

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


@@ -21,6 +21,11 @@ QgsMapLayerConfigWidgetFactory::QgsMapLayerConfigWidgetFactory( const QString &t
{
}

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

bool QgsMapLayerConfigWidgetFactory::supportsLayer( QgsMapLayer *layer ) const
{
Q_UNUSED( layer )
@@ -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.
@@ -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;
@@ -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:

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

0 comments on commit ce9f519

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