QGIS API Documentation 3.40.0-Bratislava (b56115d8743)
Loading...
Searching...
No Matches
qgsmaplayerrefreshsettingswidget.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsmaplayerrefreshsettingswidget.cpp
3 ---------------
4 begin : August 2023
5 copyright : (C) 2023 by Nyall Dawson
6 email : nyall dot dawson at gmail dot com
7 ***************************************************************************/
8
9/***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
17
19#include "qgsmaplayer.h"
20
22 : QWidget( parent )
23 , mLayer( layer )
24{
25 setupUi( this );
26 mModeComboBox->addItem( tr( "Reload Data" ), QVariant::fromValue( Qgis::AutoRefreshMode::ReloadData ) );
27 mModeComboBox->addItem( tr( "Redraw Layer Only" ), QVariant::fromValue( Qgis::AutoRefreshMode::RedrawOnly ) );
28 connect( mModeComboBox, qOverload< int >( &QComboBox::currentIndexChanged ), this, &QgsMapLayerRefreshSettingsWidget::updateHelp );
30}
31
33{
34 mLayer = layer;
36}
37
39{
40 mLayer->setAutoRefreshInterval( static_cast< int >( mRefreshLayerIntervalSpinBox->value() * 1000.0 ) );
41 if ( !mEnabledGroupBox->isChecked() )
42 {
43 mLayer->setAutoRefreshMode( Qgis::AutoRefreshMode::Disabled );
44 }
45 else
46 {
47 mLayer->setAutoRefreshMode( mModeComboBox->currentData().value< Qgis::AutoRefreshMode >() );
48 }
49}
50
52{
53 if ( !mLayer )
54 return;
55
56 switch ( mLayer->autoRefreshMode() )
57 {
59 mEnabledGroupBox->setChecked( false );
60 break;
61
64 mEnabledGroupBox->setChecked( true );
65 mModeComboBox->setCurrentIndex( mModeComboBox->findData( QVariant::fromValue( mLayer->autoRefreshMode() ) ) );
66 break;
67 }
68
69 mRefreshLayerIntervalSpinBox->setValue( mLayer->autoRefreshInterval() / 1000.0 );
70 updateHelp();
71}
72
73void QgsMapLayerRefreshSettingsWidget::updateHelp()
74{
75 QString title;
76 QString help;
77 switch ( mModeComboBox->currentData().value< Qgis::AutoRefreshMode >() )
78 {
80 break;
81
83 title = tr( "The layer will be completely refreshed." );
84 help = tr( "Any cached data will be discarded and refetched from the provider. This mode may result in slower map refreshes." );
85 break;
86
88 title = tr( "The layer will be redrawn only." );
89 help = tr( "This mode is useful for animation or when the layer's style will be updated at regular intervals. Canvas updates are deferred in order to avoid refreshing multiple times if more than one layer has an auto update interval set." );
90 break;
91 }
92
93 mHelpLabel->setText( QStringLiteral( "<b>%1</b><p>%2" ).arg( title, help ) );
94}
AutoRefreshMode
Map layer automatic refresh modes.
Definition qgis.h:2128
@ RedrawOnly
Redraw current data only.
@ ReloadData
Reload data (and draw the new data)
@ Disabled
Automatic refreshing is disabled.
QgsMapLayerRefreshSettingsWidget(QWidget *parent=nullptr, QgsMapLayer *layer=nullptr)
Constructor for QgsMapLayerRefreshSettingsWidget.
void setLayer(QgsMapLayer *layer)
Sets the layer associated with the widget.
void syncToLayer()
Updates the widget state to match the current layer state.
void saveToLayer()
Saves the settings to the layer.
Base class for all map layer types.
Definition qgsmaplayer.h:76