QGIS API Documentation 3.41.0-Master (45a0abf3bec)
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 "moc_qgsmaplayerrefreshsettingswidget.cpp"
20#include "qgsmaplayer.h"
21
23 : QWidget( parent )
24 , mLayer( layer )
25{
26 setupUi( this );
27 mModeComboBox->addItem( tr( "Reload Data" ), QVariant::fromValue( Qgis::AutoRefreshMode::ReloadData ) );
28 mModeComboBox->addItem( tr( "Redraw Layer Only" ), QVariant::fromValue( Qgis::AutoRefreshMode::RedrawOnly ) );
29 connect( mModeComboBox, qOverload< int >( &QComboBox::currentIndexChanged ), this, &QgsMapLayerRefreshSettingsWidget::updateHelp );
31}
32
34{
35 mLayer = layer;
37}
38
40{
41 mLayer->setAutoRefreshInterval( static_cast< int >( mRefreshLayerIntervalSpinBox->value() * 1000.0 ) );
42 if ( !mEnabledGroupBox->isChecked() )
43 {
44 mLayer->setAutoRefreshMode( Qgis::AutoRefreshMode::Disabled );
45 }
46 else
47 {
48 mLayer->setAutoRefreshMode( mModeComboBox->currentData().value< Qgis::AutoRefreshMode >() );
49 }
50}
51
53{
54 if ( !mLayer )
55 return;
56
57 switch ( mLayer->autoRefreshMode() )
58 {
60 mEnabledGroupBox->setChecked( false );
61 break;
62
65 mEnabledGroupBox->setChecked( true );
66 mModeComboBox->setCurrentIndex( mModeComboBox->findData( QVariant::fromValue( mLayer->autoRefreshMode() ) ) );
67 break;
68 }
69
70 mRefreshLayerIntervalSpinBox->setValue( mLayer->autoRefreshInterval() / 1000.0 );
71 updateHelp();
72}
73
74void QgsMapLayerRefreshSettingsWidget::updateHelp()
75{
76 QString title;
77 QString help;
78 switch ( mModeComboBox->currentData().value< Qgis::AutoRefreshMode >() )
79 {
81 break;
82
84 title = tr( "The layer will be completely refreshed." );
85 help = tr( "Any cached data will be discarded and refetched from the provider. This mode may result in slower map refreshes." );
86 break;
87
89 title = tr( "The layer will be redrawn only." );
90 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." );
91 break;
92 }
93
94 mHelpLabel->setText( QStringLiteral( "<b>%1</b><p>%2" ).arg( title, help ) );
95}
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