Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add mechanism for QgsMapLayerConfigWidgetFactory to create sub widgets
which are embedded into the raster layer temporal properties widget
  • Loading branch information
nyalldawson committed Mar 24, 2021
1 parent 4faceaf commit 207be1d
Show file tree
Hide file tree
Showing 9 changed files with 93 additions and 56 deletions.
4 changes: 2 additions & 2 deletions python/gui/auto_additions/qgsmaplayerconfigwidgetfactory.py
@@ -1,6 +1,6 @@
# The following has been generated automatically from src/gui/qgsmaplayerconfigwidgetfactory.h
# monkey patching scoped based enum
QgsMapLayerConfigWidgetFactory.ParentPage.None.__doc__ = "Factory creates pages itself, not sub-components"
QgsMapLayerConfigWidgetFactory.ParentPage.NoParent.__doc__ = "Factory creates pages itself, not sub-components"
QgsMapLayerConfigWidgetFactory.ParentPage.Temporal.__doc__ = "Factory creates sub-components of the temporal properties page"
QgsMapLayerConfigWidgetFactory.ParentPage.__doc__ = 'Available parent pages, for factories which create a widget which is a sub-component\nof a standard page.\n\n.. versionadded:: 3.20\n\n' + '* ``None``: ' + QgsMapLayerConfigWidgetFactory.ParentPage.None.__doc__ + '\n' + '* ``Temporal``: ' + QgsMapLayerConfigWidgetFactory.ParentPage.Temporal.__doc__
QgsMapLayerConfigWidgetFactory.ParentPage.__doc__ = 'Available parent pages, for factories which create a widget which is a sub-component\nof a standard page.\n\n.. versionadded:: 3.20\n\n' + '* ``NoParent``: ' + QgsMapLayerConfigWidgetFactory.ParentPage.NoParent.__doc__ + '\n' + '* ``Temporal``: ' + QgsMapLayerConfigWidgetFactory.ParentPage.Temporal.__doc__
# --
Expand Up @@ -24,7 +24,7 @@ Factory class for creating custom map layer property pages

enum class ParentPage
{
None,
NoParent,
Temporal,
};

Expand Down Expand Up @@ -132,7 +132,7 @@ Check if the layer is supported for this widget.
%Docstring
Returns the associated parent page, for factories which create sub-components of a standard page.

The default implementation returns QgsMapLayerConfigWidgetFactory.ParentPage.None, indicating that the
The default implementation returns QgsMapLayerConfigWidgetFactory.ParentPage.NoParent, indicating that the
factory creates top-level pages which are not subcomponents.

.. versionadded:: 3.20
Expand Down
Expand Up @@ -37,6 +37,13 @@ Save widget temporal properties inputs.
void syncToLayer();
%Docstring
Updates the widget state to match the current layer state.
%End

void addWidget( QgsMapLayerConfigWidget *widget /Transfer/ );
%Docstring
Adds a child ``widget`` to the properties widget.

.. versionadded:: 3.20
%End

};
Expand Down
2 changes: 1 addition & 1 deletion src/gui/qgsmaplayerconfigwidgetfactory.cpp
Expand Up @@ -34,5 +34,5 @@ bool QgsMapLayerConfigWidgetFactory::supportsLayer( QgsMapLayer *layer ) const

QgsMapLayerConfigWidgetFactory::ParentPage QgsMapLayerConfigWidgetFactory::parentPage() const
{
return ParentPage::None;
return ParentPage::NoParent;
}
4 changes: 2 additions & 2 deletions src/gui/qgsmaplayerconfigwidgetfactory.h
Expand Up @@ -42,7 +42,7 @@ class GUI_EXPORT QgsMapLayerConfigWidgetFactory
*/
enum class ParentPage : int
{
None, //!< Factory creates pages itself, not sub-components
NoParent, //!< Factory creates pages itself, not sub-components
Temporal, //!< Factory creates sub-components of the temporal properties page
};

Expand Down Expand Up @@ -130,7 +130,7 @@ class GUI_EXPORT QgsMapLayerConfigWidgetFactory
/**
* Returns the associated parent page, for factories which create sub-components of a standard page.
*
* The default implementation returns QgsMapLayerConfigWidgetFactory::ParentPage::None, indicating that the
* The default implementation returns QgsMapLayerConfigWidgetFactory::ParentPage::NoParent, indicating that the
* factory creates top-level pages which are not subcomponents.
*
* \since QGIS 3.20
Expand Down
23 changes: 17 additions & 6 deletions src/gui/raster/qgsrasterlayerproperties.cpp
Expand Up @@ -550,13 +550,24 @@ void QgsRasterLayerProperties::addPropertiesPageFactory( const QgsMapLayerConfig
}

QgsMapLayerConfigWidget *page = factory->createWidget( mRasterLayer, nullptr, false, this );
mLayerPropertiesPages << page;
switch ( factory->parentPage() )
{
case QgsMapLayerConfigWidgetFactory::ParentPage::NoParent:
{
mLayerPropertiesPages << 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 );
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 );
break;
}

case QgsMapLayerConfigWidgetFactory::ParentPage::Temporal:
mTemporalWidget->addWidget( page );
break;
}
}

void QgsRasterLayerProperties::setupTransparencyTable( int nBands )
Expand Down
23 changes: 21 additions & 2 deletions src/gui/raster/qgsrasterlayertemporalpropertieswidget.cpp
Expand Up @@ -22,6 +22,7 @@
#include "qgsrasterdataprovidertemporalcapabilities.h"
#include "qgsrasterlayer.h"
#include "qgsrasterlayertemporalproperties.h"
#include "qgsmaplayerconfigwidget.h"

QgsRasterLayerTemporalPropertiesWidget::QgsRasterLayerTemporalPropertiesWidget( QWidget *parent, QgsRasterLayer *layer )
: QWidget( parent )
Expand All @@ -30,10 +31,12 @@ QgsRasterLayerTemporalPropertiesWidget::QgsRasterLayerTemporalPropertiesWidget(
Q_ASSERT( mLayer );
setupUi( this );

mExtraWidgetContainer->setLayout( new QVBoxLayout() );

connect( mModeFixedRangeRadio, &QRadioButton::toggled, mFixedTimeRangeFrame, &QWidget::setEnabled );

mStartTemporalDateTimeEdit->setDisplayFormat( "yyyy-MM-dd HH:mm:ss" );
mEndTemporalDateTimeEdit->setDisplayFormat( "yyyy-MM-dd HH:mm:ss" );
mStartTemporalDateTimeEdit->setDisplayFormat( QStringLiteral( "yyyy-MM-dd HH:mm:ss" ) );
mEndTemporalDateTimeEdit->setDisplayFormat( QStringLiteral( "yyyy-MM-dd HH:mm:ss" ) );

if ( !mLayer->dataProvider() || !mLayer->dataProvider()->temporalCapabilities()->hasTemporalCapabilities() )
{
Expand All @@ -59,6 +62,11 @@ void QgsRasterLayerTemporalPropertiesWidget::saveTemporalProperties()
else if ( mModeFixedRangeRadio->isChecked() )
temporalProperties->setMode( QgsRasterLayerTemporalProperties::ModeFixedTemporalRange );
temporalProperties->setFixedTemporalRange( normalRange );

for ( QgsMapLayerConfigWidget *widget : std::as_const( mExtraWidgets ) )
{
widget->apply();
}
}

void QgsRasterLayerTemporalPropertiesWidget::syncToLayer()
Expand All @@ -78,4 +86,15 @@ void QgsRasterLayerTemporalPropertiesWidget::syncToLayer()
mEndTemporalDateTimeEdit->setDateTime( temporalProperties->fixedTemporalRange().end() );

mTemporalGroupBox->setChecked( temporalProperties->isActive() );

for ( QgsMapLayerConfigWidget *widget : std::as_const( mExtraWidgets ) )
{
widget->syncToLayer( mLayer );
}
}

void QgsRasterLayerTemporalPropertiesWidget::addWidget( QgsMapLayerConfigWidget *widget )
{
mExtraWidgets << widget;
mExtraWidgetContainer->layout()->addWidget( widget );
}
10 changes: 10 additions & 0 deletions src/gui/raster/qgsrasterlayertemporalpropertieswidget.h
Expand Up @@ -22,6 +22,7 @@
#include "qgis_gui.h"

class QgsRasterLayer;
class QgsMapLayerConfigWidget;

/**
* \ingroup gui
Expand Down Expand Up @@ -51,12 +52,21 @@ class GUI_EXPORT QgsRasterLayerTemporalPropertiesWidget : public QWidget, privat
*/
void syncToLayer();

/**
* Adds a child \a widget to the properties widget.
*
* \since QGIS 3.20
*/
void addWidget( QgsMapLayerConfigWidget *widget SIP_TRANSFER );

private:

/**
* The corresponding map layer with temporal attributes
*/
QgsRasterLayer *mLayer = nullptr;

QList< QgsMapLayerConfigWidget * > mExtraWidgets;

};
#endif // QGSRASTERLAYERTEMPORALPROPERTIESWIDGET_H
72 changes: 31 additions & 41 deletions src/ui/raster/qgsrasterlayertemporalpropertieswidgetbase.ui
Expand Up @@ -52,7 +52,7 @@
<height>413</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout">
<layout class="QGridLayout" name="gridLayout" rowstretch="0,1">
<property name="leftMargin">
<number>0</number>
</property>
Expand All @@ -65,6 +65,9 @@
<property name="bottomMargin">
<number>0</number>
</property>
<item row="1" column="0">
<widget class="QWidget" name="mExtraWidgetContainer" native="true"/>
</item>
<item row="0" column="0">
<widget class="QGroupBox" name="mTemporalGroupBox">
<property name="enabled">
Expand Down Expand Up @@ -94,6 +97,19 @@ background: white;QgsCollapsibleGroupBoxBasic::title, QgsCollapsibleGroupBox::ti
</property>
</widget>
</item>
<item row="0" column="0" colspan="2">
<widget class="QRadioButton" name="mModeAutomaticRadio">
<property name="toolTip">
<string>Delegates temporal handling to the data provider</string>
</property>
<property name="text">
<string>Automatic</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item row="3" column="0" colspan="2">
<widget class="QFrame" name="mFixedTimeRangeFrame">
<property name="enabled">
Expand All @@ -108,7 +124,7 @@ background: white;QgsCollapsibleGroupBoxBasic::title, QgsCollapsibleGroupBox::ti
<property name="lineWidth">
<number>0</number>
</property>
<layout class="QGridLayout" name="gridLayout_2" columnstretch="0,2,0,2">
<layout class="QGridLayout" name="gridLayout_2" columnstretch="0,0,0,0">
<property name="topMargin">
<number>0</number>
</property>
Expand All @@ -132,6 +148,19 @@ background: white;QgsCollapsibleGroupBoxBasic::title, QgsCollapsibleGroupBox::ti
</property>
</widget>
</item>
<item row="1" column="3">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="1" colspan="2">
<widget class="QgsDateTimeEdit" name="mStartTemporalDateTimeEdit">
<property name="displayFormat">
Expand All @@ -149,48 +178,9 @@ background: white;QgsCollapsibleGroupBoxBasic::title, QgsCollapsibleGroupBox::ti
</property>
</widget>
</item>
<item row="1" column="3">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
<item row="0" column="0" colspan="2">
<widget class="QRadioButton" name="mModeAutomaticRadio">
<property name="toolTip">
<string>Delegates temporal handling to the data provider</string>
</property>
<property name="text">
<string>Automatic</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item row="4" column="1">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
Expand Down

0 comments on commit 207be1d

Please sign in to comment.