40 #include <QMessageBox>
45 , mMapCanvas( mapCanvas )
50 connect( mScaleLineEdit, &QLineEdit::editingFinished,
this, &QgsLayoutMapWidget::mScaleLineEdit_editingFinished );
51 connect( mActionSetToCanvasExtent, &QAction::triggered,
this, &QgsLayoutMapWidget::setToMapCanvasExtent );
52 connect( mActionViewExtentInCanvas, &QAction::triggered,
this, &QgsLayoutMapWidget::viewExtentInCanvas );
53 connect( mActionSetToCanvasScale, &QAction::triggered,
this, &QgsLayoutMapWidget::setToMapCanvasScale );
54 connect( mActionViewScaleInCanvas, &QAction::triggered,
this, &QgsLayoutMapWidget::viewScaleInCanvas );
55 connect( mActionUpdatePreview, &QAction::triggered,
this, &QgsLayoutMapWidget::updatePreview );
56 connect( mFollowVisibilityPresetCheckBox, &QCheckBox::stateChanged,
this, &QgsLayoutMapWidget::mFollowVisibilityPresetCheckBox_stateChanged );
57 connect( mKeepLayerListCheckBox, &QCheckBox::stateChanged,
this, &QgsLayoutMapWidget::mKeepLayerListCheckBox_stateChanged );
58 connect( mKeepLayerStylesCheckBox, &QCheckBox::stateChanged,
this, &QgsLayoutMapWidget::mKeepLayerStylesCheckBox_stateChanged );
59 connect( mDrawCanvasItemsCheckBox, &QCheckBox::stateChanged,
this, &QgsLayoutMapWidget::mDrawCanvasItemsCheckBox_stateChanged );
60 connect( mOverviewBlendModeComboBox,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsLayoutMapWidget::mOverviewBlendModeComboBox_currentIndexChanged );
61 connect( mOverviewInvertCheckbox, &QCheckBox::toggled,
this, &QgsLayoutMapWidget::mOverviewInvertCheckbox_toggled );
62 connect( mOverviewCenterCheckbox, &QCheckBox::toggled,
this, &QgsLayoutMapWidget::mOverviewCenterCheckbox_toggled );
63 connect( mOverviewPositionComboBox,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsLayoutMapWidget::overviewStackingChanged );
65 connect( mXMinLineEdit, &QLineEdit::editingFinished,
this, &QgsLayoutMapWidget::mXMinLineEdit_editingFinished );
66 connect( mXMaxLineEdit, &QLineEdit::editingFinished,
this, &QgsLayoutMapWidget::mXMaxLineEdit_editingFinished );
67 connect( mYMinLineEdit, &QLineEdit::editingFinished,
this, &QgsLayoutMapWidget::mYMinLineEdit_editingFinished );
68 connect( mYMaxLineEdit, &QLineEdit::editingFinished,
this, &QgsLayoutMapWidget::mYMaxLineEdit_editingFinished );
69 connect( mAtlasMarginRadio, &QRadioButton::toggled,
this, &QgsLayoutMapWidget::mAtlasMarginRadio_toggled );
70 connect( mAtlasCheckBox, &QgsCollapsibleGroupBoxBasic::toggled,
this, &QgsLayoutMapWidget::mAtlasCheckBox_toggled );
71 connect( mAtlasMarginSpinBox,
static_cast < void ( QSpinBox::* )(
int )
> ( &QSpinBox::valueChanged ),
this, &QgsLayoutMapWidget::mAtlasMarginSpinBox_valueChanged );
72 connect( mAtlasFixedScaleRadio, &QRadioButton::toggled,
this, &QgsLayoutMapWidget::mAtlasFixedScaleRadio_toggled );
73 connect( mAtlasPredefinedScaleRadio, &QRadioButton::toggled,
this, &QgsLayoutMapWidget::mAtlasPredefinedScaleRadio_toggled );
74 connect( mAddGridPushButton, &QPushButton::clicked,
this, &QgsLayoutMapWidget::mAddGridPushButton_clicked );
75 connect( mRemoveGridPushButton, &QPushButton::clicked,
this, &QgsLayoutMapWidget::mRemoveGridPushButton_clicked );
76 connect( mGridUpButton, &QPushButton::clicked,
this, &QgsLayoutMapWidget::mGridUpButton_clicked );
77 connect( mGridDownButton, &QPushButton::clicked,
this, &QgsLayoutMapWidget::mGridDownButton_clicked );
78 connect( mGridListWidget, &QListWidget::currentItemChanged,
this, &QgsLayoutMapWidget::mGridListWidget_currentItemChanged );
79 connect( mGridListWidget, &QListWidget::itemChanged,
this, &QgsLayoutMapWidget::mGridListWidget_itemChanged );
80 connect( mGridPropertiesButton, &QPushButton::clicked,
this, &QgsLayoutMapWidget::mGridPropertiesButton_clicked );
81 connect( mAddOverviewPushButton, &QPushButton::clicked,
this, &QgsLayoutMapWidget::mAddOverviewPushButton_clicked );
82 connect( mRemoveOverviewPushButton, &QPushButton::clicked,
this, &QgsLayoutMapWidget::mRemoveOverviewPushButton_clicked );
83 connect( mOverviewUpButton, &QPushButton::clicked,
this, &QgsLayoutMapWidget::mOverviewUpButton_clicked );
84 connect( mOverviewDownButton, &QPushButton::clicked,
this, &QgsLayoutMapWidget::mOverviewDownButton_clicked );
85 connect( mOverviewCheckBox, &QgsCollapsibleGroupBoxBasic::toggled,
this, &QgsLayoutMapWidget::mOverviewCheckBox_toggled );
86 connect( mOverviewListWidget, &QListWidget::currentItemChanged,
this, &QgsLayoutMapWidget::mOverviewListWidget_currentItemChanged );
87 connect( mOverviewListWidget, &QListWidget::itemChanged,
this, &QgsLayoutMapWidget::mOverviewListWidget_itemChanged );
88 connect( mActionLabelSettings, &QAction::triggered,
this, &QgsLayoutMapWidget::showLabelSettings );
89 connect( mActionClipSettings, &QAction::triggered,
this, &QgsLayoutMapWidget::showClipSettings );
91 connect( mTemporalCheckBox, &QgsCollapsibleGroupBoxBasic::toggled,
this, &QgsLayoutMapWidget::mTemporalCheckBox_toggled );
92 connect( mStartDateTime, &QDateTimeEdit::dateTimeChanged,
this, &QgsLayoutMapWidget::updateTemporalExtent );
93 connect( mEndDateTime, &QDateTimeEdit::dateTimeChanged,
this, &QgsLayoutMapWidget::updateTemporalExtent );
95 mStartDateTime->setDateTimeRange( QDateTime( QDate( 1, 1, 1 ), QTime( 0, 0, 0 ) ), mStartDateTime->maximumDateTime() );
96 mEndDateTime->setDateTimeRange( QDateTime( QDate( 1, 1, 1 ), QTime( 0, 0, 0 ) ), mStartDateTime->maximumDateTime() );
97 mStartDateTime->setDisplayFormat(
"yyyy-MM-dd HH:mm:ss" );
98 mEndDateTime->setDisplayFormat(
"yyyy-MM-dd HH:mm:ss" );
100 connect( mActionMoveContent, &QAction::triggered,
this, &QgsLayoutMapWidget::switchToMoveContentTool );
102 mMapRotationSpinBox->setClearValue( 0 );
106 mBookmarkMenu =
new QMenu(
this );
107 QToolButton *btnBookmarks =
new QToolButton(
this );
108 btnBookmarks->setAutoRaise(
true );
109 btnBookmarks->setToolTip( tr(
"Bookmarks" ) );
111 btnBookmarks->setPopupMode( QToolButton::InstantPopup );
112 btnBookmarks->setMenu( mBookmarkMenu );
114 mDockToolbar->insertWidget( mActionMoveContent, btnBookmarks );
115 connect( mBookmarkMenu, &QMenu::aboutToShow,
this, &QgsLayoutMapWidget::aboutToShowBookmarkMenu );
119 mainLayout->addWidget( mItemPropertiesWidget );
121 mScaleLineEdit->setValidator(
new QDoubleValidator( mScaleLineEdit ) );
123 mXMinLineEdit->setValidator(
new QDoubleValidator( mXMinLineEdit ) );
124 mXMaxLineEdit->setValidator(
new QDoubleValidator( mXMaxLineEdit ) );
125 mYMinLineEdit->setValidator(
new QDoubleValidator( mYMinLineEdit ) );
126 mYMaxLineEdit->setValidator(
new QDoubleValidator( mYMaxLineEdit ) );
134 blockAllSignals(
true );
137 mCrsSelector->setNotSetText( tr(
"Use Project CRS" ) );
142 mFollowVisibilityPresetCombo->setModel(
new QStringListModel( mFollowVisibilityPresetCombo ) );
143 connect( mFollowVisibilityPresetCombo,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsLayoutMapWidget::followVisibilityPresetSelected );
145 this, &QgsLayoutMapWidget::onMapThemesChanged );
146 onMapThemesChanged();
149 QMenu *menuKeepLayers =
new QMenu(
this );
150 mLayerListFromPresetButton->setMenu( menuKeepLayers );
152 mLayerListFromPresetButton->setToolTip( tr(
"Set layer list from a map theme" ) );
153 connect( menuKeepLayers, &QMenu::aboutToShow,
this, &QgsLayoutMapWidget::aboutToShowKeepLayersVisibilityPresetsMenu );
158 this, &QgsLayoutMapWidget::atlasLayerChanged );
162 compositionAtlasToggled( atlas->enabled() );
165 mOverviewFrameMapComboBox->setCurrentLayout( item->
layout() );
167 mOverviewFrameStyleButton->registerExpressionContextGenerator( item );
173 mOverviewFrameStyleButton->registerExpressionContextGenerator( item );
196 loadOverviewEntries();
198 connect( mMapRotationSpinBox,
static_cast < void (
QgsDoubleSpinBox::* )(
double )
> ( &QgsDoubleSpinBox::valueChanged ),
this, &QgsLayoutMapWidget::rotationChanged );
202 blockAllSignals(
false );
207 if ( mItemPropertiesWidget )
213 mReportTypeString = string;
214 mAtlasCheckBox->setTitle( tr(
"Controlled by %1" ).arg(
string == tr(
"atlas" ) ? tr(
"Atlas" ) : tr(
"Report" ) ) );
215 mAtlasPredefinedScaleRadio->setToolTip( tr(
"Use one of the predefined scales of the project where the %1 feature best fits." ).arg(
string ) );
218 mClipWidget->setReportTypeString(
string );
220 mLabelWidget->setReportTypeString(
string );
241 mMapItem = qobject_cast< QgsLayoutItemMap * >( item );
242 mItemPropertiesWidget->
setItem( mMapItem );
244 mLabelWidget->setItem( mMapItem );
246 mClipWidget->setItem( mMapItem );
253 mOverviewFrameStyleButton->registerExpressionContextGenerator( mMapItem );
277 void QgsLayoutMapWidget::compositionAtlasToggled(
bool atlasEnabled )
280 mMapItem && mMapItem->layout() && mMapItem->layout()->reportContext().layer()
283 mAtlasCheckBox->setEnabled(
true );
287 mAtlasCheckBox->setEnabled(
false );
288 mAtlasCheckBox->setChecked(
false );
292 void QgsLayoutMapWidget::aboutToShowKeepLayersVisibilityPresetsMenu()
297 QMenu *menu = qobject_cast<QMenu *>( sender() );
303 for (
const QString &presetName : constMapThemes )
305 menu->addAction( presetName,
this, &QgsLayoutMapWidget::keepLayersVisibilityPresetSelected );
308 if ( menu->actions().isEmpty() )
309 menu->addAction( tr(
"No presets defined" ) )->setEnabled(
false );
312 void QgsLayoutMapWidget::followVisibilityPresetSelected(
int currentIndex )
317 if ( currentIndex == -1 )
321 if ( currentIndex != 0 )
323 presetName = mFollowVisibilityPresetCombo->currentText();
326 if ( presetName == mMapItem->followVisibilityPresetName() )
329 mMapItem->layout()->undoStack()->beginCommand( mMapItem, tr(
"Change Map Preset" ) );
330 mFollowVisibilityPresetCheckBox->setChecked(
true );
331 mMapItem->setFollowVisibilityPresetName( presetName );
332 mMapItem->layout()->undoStack()->endCommand();
334 mMapItem->invalidateCache();
337 void QgsLayoutMapWidget::keepLayersVisibilityPresetSelected()
339 QAction *action = qobject_cast<QAction *>( sender() );
343 QString presetName = action->text();
344 QList<QgsMapLayer *> lst = orderedPresetVisibleLayers( presetName );
347 mKeepLayerListCheckBox->setChecked(
true );
348 mMapItem->setLayers( lst );
350 mKeepLayerStylesCheckBox->setChecked(
true );
352 mMapItem->layout()->undoStack()->beginCommand( mMapItem, tr(
"Change Map Preset" ) );
353 mMapItem->setLayerStyleOverrides(
QgsProject::instance()->mapThemeCollection()->mapThemeStyleOverrides( presetName ) );
354 mMapItem->layout()->undoStack()->endCommand();
356 mMapItem->invalidateCache();
360 void QgsLayoutMapWidget::onMapThemesChanged()
362 if ( QStringListModel *model = qobject_cast<QStringListModel *>( mFollowVisibilityPresetCombo->model() ) )
365 lst.append( tr(
"(none)" ) );
367 model->setStringList( lst );
370 int presetModelIndex = mFollowVisibilityPresetCombo->findText( mMapItem->followVisibilityPresetName() );
371 mFollowVisibilityPresetCombo->blockSignals(
true );
372 mFollowVisibilityPresetCombo->setCurrentIndex( presetModelIndex != -1 ? presetModelIndex : 0 );
373 mFollowVisibilityPresetCombo->blockSignals(
false );
384 if ( mMapItem->presetCrs() ==
crs )
390 bool updateExtent =
false;
396 newExtent = xForm.transformBoundingBox( prevExtent );
404 mMapItem->layout()->undoStack()->beginCommand( mMapItem, tr(
"Change Map CRS" ) );
405 mMapItem->setCrs(
crs );
407 mMapItem->zoomToExtent( newExtent );
408 mMapItem->layout()->undoStack()->endCommand();
409 mMapItem->invalidateCache();
412 void QgsLayoutMapWidget::overviewSymbolChanged()
420 mMapItem->endCommand();
421 mMapItem->invalidateCache();
424 void QgsLayoutMapWidget::showLabelSettings()
428 if ( !mReportTypeString.isEmpty() )
429 mLabelWidget->setReportTypeString( mReportTypeString );
434 void QgsLayoutMapWidget::showClipSettings()
437 if ( !mReportTypeString.isEmpty() )
438 mClipWidget->setReportTypeString( mReportTypeString );
442 void QgsLayoutMapWidget::switchToMoveContentTool()
448 void QgsLayoutMapWidget::aboutToShowBookmarkMenu()
450 mBookmarkMenu->clear();
454 if ( !mBookmarkModel )
457 QMap< QString, QMenu * > groupMenus;
458 for (
int i = 0; i < mBookmarkModel->rowCount(); ++i )
461 QMenu *destMenu = mBookmarkMenu;
462 if ( !group.isEmpty() )
464 destMenu = groupMenus.value( group );
467 destMenu =
new QMenu( group, mBookmarkMenu );
468 groupMenus[ group ] = destMenu;
473 connect( action, &QAction::triggered,
this, [ = ]
483 if ( extent.
crs() != mMapItem->crs() )
487 QgsCoordinateTransform xForm( extent.crs(), mMapItem->crs(), QgsProject::instance() );
488 newExtent = xForm.transformBoundingBox( newExtent );
497 mMapItem->layout()->undoStack()->beginCommand( mMapItem, tr(
"Change Map Extent" ) );
498 mMapItem->zoomToExtent( newExtent );
499 mMapItem->layout()->undoStack()->endCommand();
501 destMenu->addAction( action );
504 QStringList groupKeys = groupMenus.keys();
505 groupKeys.sort( Qt::CaseInsensitive );
506 for (
int i = 0; i < groupKeys.count(); ++i )
508 if ( mBookmarkMenu->actions().value( i ) )
509 mBookmarkMenu->insertMenu( mBookmarkMenu->actions().at( i ), groupMenus.value( groupKeys.at( i ) ) );
511 mBookmarkMenu->addMenu( groupMenus.value( groupKeys.at( i ) ) );
515 void QgsLayoutMapWidget::mTemporalCheckBox_toggled(
bool checked )
522 mStartDateTime->setEnabled( checked );
523 mEndDateTime->setEnabled( checked );
525 mMapItem->layout()->undoStack()->beginCommand( mMapItem, tr(
"Toggle Temporal Range" ) );
526 mMapItem->setIsTemporal( checked );
527 mMapItem->layout()->undoStack()->endCommand();
531 whileBlocking( mStartDateTime )->setDateTime( mMapItem->temporalRange().begin() );
532 whileBlocking( mEndDateTime )->setDateTime( mMapItem->temporalRange().end() );
538 void QgsLayoutMapWidget::updateTemporalExtent()
545 QgsDateTimeRange range = QgsDateTimeRange( mStartDateTime->dateTime(), mEndDateTime->dateTime() );
547 mMapItem->layout()->undoStack()->beginCommand( mMapItem, tr(
"Set Temporal Range" ) );
548 mMapItem->setTemporalRange( range );
549 mMapItem->layout()->undoStack()->endCommand();
554 void QgsLayoutMapWidget::mAtlasCheckBox_toggled(
bool checked )
561 mAtlasFixedScaleRadio->setEnabled( checked );
562 mAtlasMarginRadio->setEnabled( checked );
564 if ( mAtlasMarginRadio->isEnabled() && mAtlasMarginRadio->isChecked() )
566 mAtlasMarginSpinBox->setEnabled(
true );
570 mAtlasMarginSpinBox->setEnabled(
false );
573 mAtlasPredefinedScaleRadio->setEnabled( checked );
578 if ( mMapItem->layout() )
580 toggleAtlasScalingOptionsByLayerType();
585 if ( !hasPredefinedScales() )
587 mAtlasPredefinedScaleRadio->setEnabled(
false );
590 mMapItem->layout()->undoStack()->beginCommand( mMapItem, tr(
"Set Atlas Driven" ) );
591 mMapItem->setAtlasDriven( checked );
592 mMapItem->layout()->undoStack()->endCommand();
596 void QgsLayoutMapWidget::updateMapForAtlas()
599 if ( mMapItem->atlasDriven() )
606 mMapItem->invalidateCache();
610 void QgsLayoutMapWidget::mAtlasMarginRadio_toggled(
bool checked )
612 mAtlasMarginSpinBox->setEnabled( checked );
614 if ( checked && mMapItem )
616 mMapItem->layout()->undoStack()->beginCommand( mMapItem, tr(
"Change Atlas Mode" ) );
618 mMapItem->layout()->undoStack()->endCommand();
623 void QgsLayoutMapWidget::mAtlasMarginSpinBox_valueChanged(
int value )
631 mMapItem->setAtlasMargin( value / 100. );
632 mMapItem->layout()->undoStack()->endCommand();
636 void QgsLayoutMapWidget::mAtlasFixedScaleRadio_toggled(
bool checked )
645 mMapItem->layout()->undoStack()->beginCommand( mMapItem, tr(
"Change Atlas Mode" ) );
647 mMapItem->layout()->undoStack()->endCommand();
652 void QgsLayoutMapWidget::mAtlasPredefinedScaleRadio_toggled(
bool checked )
659 if ( hasPredefinedScales() )
663 mMapItem->layout()->undoStack()->beginCommand( mMapItem, tr(
"Change Atlas Scales" ) );
665 mMapItem->layout()->undoStack()->endCommand();
673 mMapItem->layout()->undoStack()->beginCommand( mMapItem, tr(
"Change Atlas Mode" ) );
675 mMapItem->layout()->undoStack()->endCommand();
679 void QgsLayoutMapWidget::mScaleLineEdit_editingFinished()
686 bool conversionSuccess =
false;
687 double scaleDenominator = QLocale().toDouble( mScaleLineEdit->text(), &conversionSuccess );
688 if ( !conversionSuccess )
696 mMapItem->layout()->undoStack()->beginCommand( mMapItem, tr(
"Change Map Scale" ) );
697 mMapItem->setScale( scaleDenominator );
698 mMapItem->layout()->undoStack()->endCommand();
701 void QgsLayoutMapWidget::rotationChanged(
double value )
709 mMapItem->setMapRotation( value );
710 mMapItem->layout()->undoStack()->endCommand();
711 mMapItem->invalidateCache();
714 void QgsLayoutMapWidget::setToMapCanvasExtent()
731 newExtent = xForm.transformBoundingBox( newExtent );
740 mMapItem->layout()->undoStack()->beginCommand( mMapItem, tr(
"Change Map Extent" ) );
741 mMapItem->zoomToExtent( newExtent );
742 mMapItem->layout()->undoStack()->endCommand();
745 void QgsLayoutMapWidget::setToMapCanvasScale()
752 const double newScale = mMapCanvas->
scale();
754 mMapItem->layout()->undoStack()->beginCommand( mMapItem, tr(
"Change Map Scale" ) );
755 mMapItem->setScale( newScale );
756 mMapItem->layout()->undoStack()->endCommand();
759 void QgsLayoutMapWidget::viewExtentInCanvas()
768 if ( !currentMapExtent.
isEmpty() )
783 void QgsLayoutMapWidget::viewScaleInCanvas()
790 const double currentScale = mMapItem->scale();
791 mMapCanvas->
zoomScale( currentScale,
true );
794 void QgsLayoutMapWidget::mXMinLineEdit_editingFinished()
796 updateComposerExtentFromGui();
799 void QgsLayoutMapWidget::mXMaxLineEdit_editingFinished()
801 updateComposerExtentFromGui();
804 void QgsLayoutMapWidget::mYMinLineEdit_editingFinished()
806 updateComposerExtentFromGui();
809 void QgsLayoutMapWidget::mYMaxLineEdit_editingFinished()
811 updateComposerExtentFromGui();
814 void QgsLayoutMapWidget::updateGuiElements()
821 blockAllSignals(
true );
822 mLabel->setText( mMapItem->displayName() );
824 whileBlocking( mCrsSelector )->setCrs( mMapItem->presetCrs() );
827 double scale = mMapItem->scale();
830 if ( scale >= 10000 )
833 mScaleLineEdit->setText( QLocale().toString( mMapItem->scale(),
'f', 0 ) );
835 else if ( scale >= 10 )
837 mScaleLineEdit->setText( QLocale().toString( mMapItem->scale(),
'f', 3 ) );
839 else if ( scale >= 1 )
842 mScaleLineEdit->setText( QLocale().toString( mMapItem->scale(),
'f', 4 ) );
847 mScaleLineEdit->setText( QLocale().toString( mMapItem->scale(),
'f', 10 ) );
852 mXMinLineEdit->setText( QLocale().toString( composerMapExtent.
xMinimum(),
'f', 3 ) );
853 mXMaxLineEdit->setText( QLocale().toString( composerMapExtent.
xMaximum(),
'f', 3 ) );
854 mYMinLineEdit->setText( QLocale().toString( composerMapExtent.
yMinimum(),
'f', 3 ) );
855 mYMaxLineEdit->setText( QLocale().toString( composerMapExtent.
yMaximum(),
'f', 3 ) );
860 mFollowVisibilityPresetCheckBox->setCheckState(
861 mMapItem->followVisibilityPreset() ? Qt::Checked : Qt::Unchecked );
862 int presetModelIndex = mFollowVisibilityPresetCombo->findText( mMapItem->followVisibilityPresetName() );
863 mFollowVisibilityPresetCombo->setCurrentIndex( presetModelIndex != -1 ? presetModelIndex : 0 );
866 if ( mMapItem->keepLayerSet() )
868 mKeepLayerListCheckBox->setCheckState( Qt::Checked );
872 mKeepLayerListCheckBox->setCheckState( Qt::Unchecked );
875 mKeepLayerStylesCheckBox->setEnabled( mMapItem->keepLayerSet() );
876 mKeepLayerStylesCheckBox->setCheckState( mMapItem->keepLayerStyles() ? Qt::Checked : Qt::Unchecked );
879 if ( mMapItem->drawAnnotations() )
881 mDrawCanvasItemsCheckBox->setCheckState( Qt::Checked );
885 mDrawCanvasItemsCheckBox->setCheckState( Qt::Unchecked );
889 mAtlasCheckBox->setChecked( mMapItem->atlasDriven() );
892 mAtlasFixedScaleRadio->setEnabled( mMapItem->atlasDriven() );
895 mAtlasMarginRadio->setEnabled( mMapItem->atlasDriven() );
897 mAtlasPredefinedScaleRadio->setEnabled( mMapItem->atlasDriven() );
900 if ( mMapItem->atlasDriven() )
902 toggleAtlasScalingOptionsByLayerType();
905 if ( !hasPredefinedScales() )
907 mAtlasPredefinedScaleRadio->setEnabled(
false );
910 mTemporalCheckBox->setChecked( mMapItem->isTemporal() );
911 mTemporalCheckBox->setCollapsed( !mMapItem->isTemporal() );
912 mStartDateTime->setEnabled( mMapItem->isTemporal() );
913 mEndDateTime->setEnabled( mMapItem->isTemporal() );
914 if ( mMapItem->isTemporal() )
916 mStartDateTime->setDateTime( mMapItem->temporalRange().begin() );
917 mEndDateTime->setDateTime( mMapItem->temporalRange().end() );
922 loadOverviewEntries();
924 blockAllSignals(
false );
927 void QgsLayoutMapWidget::toggleAtlasScalingOptionsByLayerType()
944 mAtlasFixedScaleRadio->setChecked(
true );
945 mAtlasMarginRadio->setEnabled(
false );
946 mAtlasPredefinedScaleRadio->setEnabled(
false );
951 mAtlasMarginRadio->setEnabled(
true );
952 mAtlasPredefinedScaleRadio->setEnabled(
true );
956 void QgsLayoutMapWidget::updateComposerExtentFromGui()
963 double xmin, ymin, xmax, ymax;
964 bool conversionSuccess;
966 xmin = QLocale().toDouble( mXMinLineEdit->text(), &conversionSuccess );
967 if ( !conversionSuccess )
969 xmax = QLocale().toDouble( mXMaxLineEdit->text(), &conversionSuccess );
970 if ( !conversionSuccess )
972 ymin = QLocale().toDouble( mYMinLineEdit->text(), &conversionSuccess );
973 if ( !conversionSuccess )
975 ymax = QLocale().toDouble( mYMaxLineEdit->text(), &conversionSuccess );
976 if ( !conversionSuccess )
981 mMapItem->layout()->undoStack()->beginCommand( mMapItem, tr(
"Change Map Extent" ) );
982 mMapItem->setExtent( newExtent );
983 mMapItem->layout()->undoStack()->endCommand();
986 void QgsLayoutMapWidget::blockAllSignals(
bool b )
988 mScaleLineEdit->blockSignals( b );
989 mXMinLineEdit->blockSignals( b );
990 mXMaxLineEdit->blockSignals( b );
991 mYMinLineEdit->blockSignals( b );
992 mYMaxLineEdit->blockSignals( b );
993 mDrawCanvasItemsCheckBox->blockSignals( b );
994 mOverviewFrameMapComboBox->blockSignals( b );
995 mOverviewFrameStyleButton->blockSignals( b );
996 mOverviewBlendModeComboBox->blockSignals( b );
997 mOverviewInvertCheckbox->blockSignals( b );
998 mOverviewCenterCheckbox->blockSignals( b );
999 mAtlasCheckBox->blockSignals( b );
1000 mAtlasMarginSpinBox->blockSignals( b );
1001 mAtlasFixedScaleRadio->blockSignals( b );
1002 mAtlasMarginRadio->blockSignals( b );
1003 mFollowVisibilityPresetCheckBox->blockSignals( b );
1004 mFollowVisibilityPresetCombo->blockSignals( b );
1005 mKeepLayerListCheckBox->blockSignals( b );
1006 mKeepLayerStylesCheckBox->blockSignals( b );
1007 mActionSetToCanvasExtent->blockSignals( b );
1008 mActionUpdatePreview->blockSignals( b );
1009 mTemporalCheckBox->blockSignals( b );
1010 mStartDateTime->blockSignals( b );
1011 mEndDateTime->blockSignals( b );
1013 blockOverviewItemsSignals( b );
1016 void QgsLayoutMapWidget::updatePreview()
1022 mMapItem->refresh();
1025 void QgsLayoutMapWidget::mFollowVisibilityPresetCheckBox_stateChanged(
int state )
1032 mMapItem->layout()->undoStack()->beginCommand( mMapItem, tr(
"Change Map Preset" ) );
1033 if ( state == Qt::Checked )
1035 mMapItem->setFollowVisibilityPreset(
true );
1038 mKeepLayerListCheckBox->setCheckState( Qt::Unchecked );
1039 mKeepLayerStylesCheckBox->setCheckState( Qt::Unchecked );
1041 mMapItem->invalidateCache();
1045 mMapItem->setFollowVisibilityPreset(
false );
1047 mMapItem->layout()->undoStack()->endCommand();
1050 void QgsLayoutMapWidget::mKeepLayerListCheckBox_stateChanged(
int state )
1058 mMapItem->layout()->undoStack()->beginCommand( mMapItem, tr(
"Map Preset Changed" ) );
1059 storeCurrentLayerSet();
1060 mMapItem->setKeepLayerSet( state == Qt::Checked );
1061 if ( state == Qt::Unchecked )
1063 mMapItem->setLayers( QList< QgsMapLayer * >() );
1065 mMapItem->layout()->undoStack()->endCommand();
1068 if ( state == Qt::Checked )
1071 mFollowVisibilityPresetCheckBox->setCheckState( Qt::Unchecked );
1075 mKeepLayerStylesCheckBox->setChecked( Qt::Unchecked );
1076 mMapItem->invalidateCache();
1079 mKeepLayerStylesCheckBox->setEnabled( state == Qt::Checked );
1082 void QgsLayoutMapWidget::mKeepLayerStylesCheckBox_stateChanged(
int state )
1089 mMapItem->layout()->undoStack()->beginCommand( mMapItem, tr(
"Change Map Preset" ) );
1090 if ( state == Qt::Checked )
1092 mMapItem->storeCurrentLayerStyles();
1093 mMapItem->setKeepLayerStyles(
true );
1097 mMapItem->setLayerStyleOverrides( QMap<QString, QString>() );
1098 mMapItem->setKeepLayerStyles(
false );
1100 mMapItem->layout()->undoStack()->endCommand();
1103 void QgsLayoutMapWidget::mDrawCanvasItemsCheckBox_stateChanged(
int state )
1110 mMapItem->layout()->undoStack()->beginCommand( mMapItem, tr(
"Toggle Map Item" ) );
1111 mMapItem->setDrawAnnotations( state == Qt::Checked );
1112 mMapItem->invalidateCache();
1113 mMapItem->layout()->undoStack()->endCommand();
1116 void QgsLayoutMapWidget::atlasLayerChanged(
QgsVectorLayer *layer )
1121 mAtlasCheckBox->setChecked(
false );
1122 mAtlasCheckBox->setEnabled(
false );
1127 mAtlasCheckBox->setEnabled(
true );
1131 if ( mAtlasCheckBox->isChecked() )
1132 toggleAtlasScalingOptionsByLayerType();
1135 bool QgsLayoutMapWidget::hasPredefinedScales()
const
1140 if ( !hasProjectScales || scales.isEmpty() )
1145 QStringList myScalesList = scalesStr.split(
',' );
1146 return !myScalesList.isEmpty() && !myScalesList[0].isEmpty();
1151 void QgsLayoutMapWidget::mAddGridPushButton_clicked()
1158 QString itemName = tr(
"Grid %1" ).arg( mMapItem->grids()->size() + 1 );
1160 mMapItem->layout()->undoStack()->beginCommand( mMapItem, tr(
"Add Map Grid" ) );
1161 mMapItem->grids()->addGrid( grid );
1162 mMapItem->layout()->undoStack()->endCommand();
1163 mMapItem->updateBoundingRect();
1166 addGridListItem( grid->
id(), grid->
name() );
1167 mGridListWidget->setCurrentRow( 0 );
1168 mGridListWidget_currentItemChanged( mGridListWidget->currentItem(),
nullptr );
1171 void QgsLayoutMapWidget::mRemoveGridPushButton_clicked()
1173 QListWidgetItem *item = mGridListWidget->currentItem();
1179 mMapItem->beginCommand( tr(
"Remove Grid" ) );
1180 mMapItem->grids()->removeGrid( item->data( Qt::UserRole ).toString() );
1181 QListWidgetItem *delItem = mGridListWidget->takeItem( mGridListWidget->row( item ) );
1183 mMapItem->endCommand();
1184 mMapItem->updateBoundingRect();
1188 void QgsLayoutMapWidget::mGridUpButton_clicked()
1190 QListWidgetItem *item = mGridListWidget->currentItem();
1196 int row = mGridListWidget->row( item );
1201 mGridListWidget->takeItem( row );
1202 mGridListWidget->insertItem( row - 1, item );
1203 mGridListWidget->setCurrentItem( item );
1204 mMapItem->beginCommand( tr(
"Move Grid Up" ) );
1205 mMapItem->grids()->moveGridUp( item->data( Qt::UserRole ).toString() );
1206 mMapItem->endCommand();
1210 void QgsLayoutMapWidget::mGridDownButton_clicked()
1212 QListWidgetItem *item = mGridListWidget->currentItem();
1218 int row = mGridListWidget->row( item );
1219 if ( mGridListWidget->count() <= row )
1223 mGridListWidget->takeItem( row );
1224 mGridListWidget->insertItem( row + 1, item );
1225 mGridListWidget->setCurrentItem( item );
1226 mMapItem->beginCommand( tr(
"Move Grid Down" ) );
1227 mMapItem->grids()->moveGridDown( item->data( Qt::UserRole ).toString() );
1228 mMapItem->endCommand();
1239 QListWidgetItem *item = mGridListWidget->currentItem();
1244 return mMapItem->grids()->grid( item->data( Qt::UserRole ).toString() );
1247 void QgsLayoutMapWidget::mGridListWidget_currentItemChanged( QListWidgetItem *current, QListWidgetItem * )
1249 mGridPropertiesButton->setEnabled(
static_cast< bool >( current ) );
1252 void QgsLayoutMapWidget::mGridListWidget_itemChanged( QListWidgetItem *item )
1265 mMapItem->beginCommand( tr(
"Rename Grid" ) );
1266 grid->
setName( item->text() );
1267 mMapItem->endCommand();
1270 void QgsLayoutMapWidget::mGridPropertiesButton_clicked()
1287 QListWidgetItem *QgsLayoutMapWidget::addGridListItem(
const QString &
id,
const QString &name )
1289 QListWidgetItem *item =
new QListWidgetItem( name,
nullptr );
1290 item->setData( Qt::UserRole,
id );
1291 item->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable );
1292 mGridListWidget->insertItem( 0, item );
1296 void QgsLayoutMapWidget::loadGridEntries()
1299 QSet<QString> selectedIds;
1300 QList<QListWidgetItem *> itemSelection = mGridListWidget->selectedItems();
1301 QList<QListWidgetItem *>::const_iterator sIt = itemSelection.constBegin();
1302 for ( ; sIt != itemSelection.constEnd(); ++sIt )
1304 selectedIds.insert( ( *sIt )->data( Qt::UserRole ).toString() );
1307 mGridListWidget->clear();
1313 QList< QgsLayoutItemMapGrid * > grids = mMapItem->grids()->asList();
1314 QList< QgsLayoutItemMapGrid * >::const_iterator gridIt = grids.constBegin();
1315 for ( ; gridIt != grids.constEnd(); ++gridIt )
1317 QListWidgetItem *item = addGridListItem( ( *gridIt )->id(), ( *gridIt )->name() );
1318 if ( selectedIds.contains( ( *gridIt )->id() ) )
1320 item->setSelected(
true );
1321 mGridListWidget->setCurrentItem( item );
1325 if ( mGridListWidget->currentItem() )
1327 mGridListWidget_currentItemChanged( mGridListWidget->currentItem(),
nullptr );
1331 mGridListWidget_currentItemChanged(
nullptr,
nullptr );
1335 void QgsLayoutMapWidget::mAddOverviewPushButton_clicked()
1342 QString itemName = tr(
"Overview %1" ).arg( mMapItem->overviews()->size() + 1 );
1344 mMapItem->layout()->undoStack()->beginCommand( mMapItem, tr(
"Add Map Overview" ) );
1345 mMapItem->overviews()->addOverview( overview );
1346 mMapItem->layout()->undoStack()->endCommand();
1347 mMapItem->invalidateCache();
1349 addOverviewListItem( overview->
id(), overview->
name() );
1351 mOverviewListWidget->setCurrentRow( 0 );
1354 void QgsLayoutMapWidget::mRemoveOverviewPushButton_clicked()
1356 QListWidgetItem *item = mOverviewListWidget->currentItem();
1361 mMapItem->beginCommand( tr(
"Remove Map Overview" ) );
1362 mMapItem->overviews()->removeOverview( item->data( Qt::UserRole ).toString() );
1363 mMapItem->endCommand();
1364 QListWidgetItem *delItem = mOverviewListWidget->takeItem( mOverviewListWidget->row( item ) );
1366 mMapItem->invalidateCache();
1369 void QgsLayoutMapWidget::mOverviewUpButton_clicked()
1371 QListWidgetItem *item = mOverviewListWidget->currentItem();
1377 int row = mOverviewListWidget->row( item );
1382 mOverviewListWidget->takeItem( row );
1383 mOverviewListWidget->insertItem( row - 1, item );
1384 mOverviewListWidget->setCurrentItem( item );
1385 mMapItem->beginCommand( tr(
"Move Overview Up" ) );
1386 mMapItem->overviews()->moveOverviewUp( item->data( Qt::UserRole ).toString() );
1387 mMapItem->endCommand();
1388 mMapItem->invalidateCache();
1391 void QgsLayoutMapWidget::mOverviewDownButton_clicked()
1393 QListWidgetItem *item = mOverviewListWidget->currentItem();
1399 int row = mOverviewListWidget->row( item );
1400 if ( mOverviewListWidget->count() <= row )
1404 mOverviewListWidget->takeItem( row );
1405 mOverviewListWidget->insertItem( row + 1, item );
1406 mOverviewListWidget->setCurrentItem( item );
1407 mMapItem->beginCommand( tr(
"Move Overview Down" ) );
1408 mMapItem->overviews()->moveOverviewDown( item->data( Qt::UserRole ).toString() );
1409 mMapItem->endCommand();
1410 mMapItem->invalidateCache();
1420 QListWidgetItem *item = mOverviewListWidget->currentItem();
1426 return mMapItem->overviews()->overview( item->data( Qt::UserRole ).toString() );
1429 void QgsLayoutMapWidget::mOverviewListWidget_currentItemChanged( QListWidgetItem *current, QListWidgetItem *previous )
1431 Q_UNUSED( previous )
1434 mOverviewCheckBox->setEnabled(
false );
1438 mOverviewCheckBox->setEnabled(
true );
1439 setOverviewItems( mMapItem->overviews()->overview( current->data( Qt::UserRole ).toString() ) );
1442 void QgsLayoutMapWidget::mOverviewListWidget_itemChanged( QListWidgetItem *item )
1455 mMapItem->beginCommand( QStringLiteral(
"Rename Overview" ) );
1456 overview->
setName( item->text() );
1457 mMapItem->endCommand();
1458 if ( item->isSelected() )
1461 mOverviewCheckBox->setTitle( tr(
"Draw \"%1\" overview" ).arg( overview->
name() ) );
1465 void QgsLayoutMapWidget::setOverviewItemsEnabled(
bool enabled )
1467 mOverviewFrameMapLabel->setEnabled( enabled );
1468 mOverviewFrameMapComboBox->setEnabled( enabled );
1469 mOverviewFrameStyleLabel->setEnabled( enabled );
1470 mOverviewFrameStyleButton->setEnabled( enabled );
1471 mOverviewBlendModeLabel->setEnabled( enabled );
1472 mOverviewBlendModeComboBox->setEnabled( enabled );
1473 mOverviewInvertCheckbox->setEnabled( enabled );
1474 mOverviewCenterCheckbox->setEnabled( enabled );
1475 mOverviewPositionComboBox->setEnabled( enabled );
1481 void QgsLayoutMapWidget::blockOverviewItemsSignals(
const bool block )
1483 mOverviewFrameMapComboBox->blockSignals( block );
1484 mOverviewFrameStyleButton->blockSignals( block );
1485 mOverviewBlendModeComboBox->blockSignals( block );
1486 mOverviewInvertCheckbox->blockSignals( block );
1487 mOverviewCenterCheckbox->blockSignals( block );
1488 mOverviewPositionComboBox->blockSignals( block );
1489 mOverviewStackingLayerComboBox->blockSignals( block );
1499 blockOverviewItemsSignals(
true );
1501 mOverviewCheckBox->setTitle( tr(
"Draw \"%1\" overview" ).arg( overview->
name() ) );
1502 mOverviewCheckBox->setChecked( overview->
enabled() );
1505 mOverviewFrameMapComboBox->setItem( overview->
linkedMap() );
1508 mOverviewBlendModeComboBox->setBlendMode( overview->
blendMode() );
1510 mOverviewInvertCheckbox->setChecked( overview->
inverted() );
1512 mOverviewCenterCheckbox->setChecked( overview->
centered() );
1514 mOverviewPositionComboBox->setCurrentIndex( mOverviewPositionComboBox->findData( overview->
stackingPosition() ) );
1515 mOverviewStackingLayerComboBox->setLayer( overview->
stackingLayer() );
1521 blockOverviewItemsSignals(
false );
1524 void QgsLayoutMapWidget::storeCurrentLayerSet()
1530 mMapItem->setLayers( layers );
1532 if ( mMapItem->keepLayerStyles() )
1535 mMapItem->storeCurrentLayerStyles();
1539 QList<QgsMapLayer *> QgsLayoutMapWidget::orderedPresetVisibleLayers(
const QString &name )
const
1544 QList<QgsMapLayer *> lst;
1548 if ( visibleIds.contains( layer->
id() ) )
1556 QListWidgetItem *QgsLayoutMapWidget::addOverviewListItem(
const QString &
id,
const QString &name )
1558 QListWidgetItem *item =
new QListWidgetItem( name,
nullptr );
1559 item->setData( Qt::UserRole,
id );
1560 item->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable );
1561 mOverviewListWidget->insertItem( 0, item );
1565 void QgsLayoutMapWidget::loadOverviewEntries()
1568 QSet<QString> selectedIds;
1569 QList<QListWidgetItem *> itemSelection = mOverviewListWidget->selectedItems();
1570 QList<QListWidgetItem *>::const_iterator sIt = itemSelection.constBegin();
1571 for ( ; sIt != itemSelection.constEnd(); ++sIt )
1573 selectedIds.insert( ( *sIt )->data( Qt::UserRole ).toString() );
1576 mOverviewListWidget->clear();
1582 mOverviewFrameMapComboBox->setExceptedItemList( QList< QgsLayoutItem * >() << mMapItem );
1585 QList< QgsLayoutItemMapOverview * > overviews = mMapItem->overviews()->asList();
1586 QList< QgsLayoutItemMapOverview * >::const_iterator overviewIt = overviews.constBegin();
1587 for ( ; overviewIt != overviews.constEnd(); ++overviewIt )
1589 QListWidgetItem *item = addOverviewListItem( ( *overviewIt )->id(), ( *overviewIt )->name() );
1590 if ( selectedIds.contains( ( *overviewIt )->id() ) )
1592 item->setSelected(
true );
1593 mOverviewListWidget->setCurrentItem( item );
1597 if ( mOverviewListWidget->currentItem() )
1599 mOverviewListWidget_currentItemChanged( mOverviewListWidget->currentItem(),
nullptr );
1603 mOverviewListWidget_currentItemChanged(
nullptr,
nullptr );
1607 void QgsLayoutMapWidget::mOverviewCheckBox_toggled(
bool state )
1615 mMapItem->layout()->undoStack()->beginCommand( mMapItem, tr(
"Overview Display Toggled" ) );
1617 mMapItem->invalidateCache();
1618 mMapItem->layout()->undoStack()->endCommand();
1621 void QgsLayoutMapWidget::overviewMapChanged(
QgsLayoutItem *item )
1633 mMapItem->beginCommand( tr(
"Change Overview Map" ) );
1635 mMapItem->invalidateCache();
1636 mMapItem->endCommand();
1639 void QgsLayoutMapWidget::mOverviewBlendModeComboBox_currentIndexChanged(
int index )
1648 mMapItem->beginCommand( tr(
"Change Overview Blend Mode" ) );
1649 overview->
setBlendMode( mOverviewBlendModeComboBox->blendMode() );
1650 mMapItem->invalidateCache();
1651 mMapItem->endCommand();
1654 void QgsLayoutMapWidget::mOverviewInvertCheckbox_toggled(
bool state )
1662 mMapItem->beginCommand( tr(
"Toggle Overview Inverted" ) );
1664 mMapItem->invalidateCache();
1665 mMapItem->endCommand();
1668 void QgsLayoutMapWidget::mOverviewCenterCheckbox_toggled(
bool state )
1676 mMapItem->beginCommand( tr(
"Toggle Overview Centered" ) );
1678 mMapItem->invalidateCache();
1679 mMapItem->endCommand();
1682 void QgsLayoutMapWidget::overviewStackingChanged(
int )
1690 mMapItem->beginCommand( tr(
"Change Overview Position" ) );
1692 mMapItem->invalidateCache();
1693 mMapItem->endCommand();
1700 mOverviewStackingLayerComboBox->setEnabled(
false );
1705 mOverviewStackingLayerComboBox->setEnabled(
true );
1710 void QgsLayoutMapWidget::overviewStackingLayerChanged(
QgsMapLayer *layer )
1718 mMapItem->beginCommand( tr(
"Change Overview Position" ) );
1720 mMapItem->invalidateCache();
1721 mMapItem->endCommand();
1735 mLabelBoundarySpinBox->setClearValue( 0 );
1736 mLabelBoundarySpinBox->setShowClearButton(
true );
1738 mLabelBoundaryUnitsCombo->linkToWidget( mLabelBoundarySpinBox );
1739 mLabelBoundaryUnitsCombo->setConverter( &mMapItem->layout()->renderContext().measurementConverter() );
1742 connect( mLabelBoundarySpinBox,
static_cast < void ( QDoubleSpinBox::* )(
double )
> ( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutMapLabelingWidget::labelMarginChanged );
1743 connect( mShowPartialLabelsCheckBox, &QCheckBox::toggled,
this, &QgsLayoutMapLabelingWidget::showPartialsToggled );
1744 connect( mShowUnplacedCheckBox, &QCheckBox::toggled,
this, &QgsLayoutMapLabelingWidget::showUnplacedToggled );
1761 mMapItem = qobject_cast< QgsLayoutItemMap * >( item );
1768 updateGuiElements();
1773 void QgsLayoutMapLabelingWidget::updateGuiElements()
1775 whileBlocking( mLabelBoundarySpinBox )->setValue( mMapItem->labelMargin().length() );
1776 whileBlocking( mLabelBoundaryUnitsCombo )->setUnit( mMapItem->labelMargin().units() );
1780 if ( mBlockingItemsListView->model() )
1782 QAbstractItemModel *oldModel = mBlockingItemsListView->model();
1783 mBlockingItemsListView->setModel(
nullptr );
1784 oldModel->deleteLater();
1788 mBlockingItemsListView->setModel( model );
1793 void QgsLayoutMapLabelingWidget::labelMarginChanged(
double val )
1800 mMapItem->layout()->undoStack()->endCommand();
1801 mMapItem->invalidateCache();
1804 void QgsLayoutMapLabelingWidget::labelMarginUnitsChanged()
1810 mMapItem->setLabelMargin(
QgsLayoutMeasurement( mLabelBoundarySpinBox->value(), mLabelBoundaryUnitsCombo->unit() ) );
1811 mMapItem->layout()->undoStack()->endCommand();
1812 mMapItem->invalidateCache();
1815 void QgsLayoutMapLabelingWidget::showPartialsToggled(
bool checked )
1820 mMapItem->layout()->undoStack()->beginCommand( mMapItem, tr(
"Change Label Visibility" ) );
1821 QgsLayoutItemMap::MapItemFlags flags = mMapItem->mapFlags();
1826 mMapItem->setMapFlags( flags );
1827 mMapItem->layout()->undoStack()->endCommand();
1828 mMapItem->invalidateCache();
1831 void QgsLayoutMapLabelingWidget::showUnplacedToggled(
bool checked )
1836 mMapItem->layout()->undoStack()->beginCommand( mMapItem, tr(
"Change Label Visibility" ) );
1837 QgsLayoutItemMap::MapItemFlags flags = mMapItem->mapFlags();
1842 mMapItem->setMapFlags( flags );
1843 mMapItem->layout()->undoStack()->endCommand();
1844 mMapItem->invalidateCache();
1848 : QSortFilterProxyModel( parent )
1849 , mLayoutModel( layoutModel )
1852 setSourceModel( layoutModel );
1865 if ( i.column() != 0 )
1878 case Qt::CheckStateRole:
1879 switch ( i.column() )
1882 return mMapItem ? ( mMapItem->isLabelBlockingItem( item ) ? Qt::Checked : Qt::Unchecked ) : Qt::Unchecked;
1888 return mLayoutModel->
data( sourceIndex, role );
1896 if ( !index.isValid() )
1900 if ( !item || !mMapItem )
1905 mMapItem->layout()->undoStack()->beginCommand( mMapItem, tr(
"Change Label Blocking Items" ) );
1907 if ( value.toBool() )
1909 mMapItem->addLabelBlockingItem( item );
1913 mMapItem->removeLabelBlockingItem( item );
1915 emit dataChanged( index, index, QVector<int>() << role );
1917 mMapItem->layout()->undoStack()->endCommand();
1918 mMapItem->invalidateCache();
1925 Qt::ItemFlags
flags = QAbstractItemModel::flags( index );
1927 if ( ! index.isValid() )
1932 switch ( index.column() )
1935 return flags | Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsUserCheckable;
1937 return flags | Qt::ItemIsEnabled | Qt::ItemIsSelectable;
1944 if ( !item || item == mMapItem )
1967 mLayersTreeView->setModel( mLayerModel );
1973 for (
int i = 0; i < mAtlasClippingTypeComboBox->count(); ++i )
1975 mItemClippingTypeComboBox->addItem( mAtlasClippingTypeComboBox->itemText( i ), mAtlasClippingTypeComboBox->itemData( i ) );
1978 mClipItemComboBox->setCurrentLayout( map->
layout() );
1981 connect( mRadioClipSelectedLayers, &QRadioButton::toggled, mLayersTreeView, &QWidget::setEnabled );
1982 mLayersTreeView->setEnabled(
false );
1983 mRadioClipAllLayers->setChecked(
true );
1985 connect( mClipToAtlasCheckBox, &QGroupBox::toggled,
this, [ = ](
bool active )
1987 if ( !mBlockUpdates )
1989 mMapItem->beginCommand( tr(
"Toggle Atlas Clipping" ) );
1990 mMapItem->atlasClippingSettings()->setEnabled( active );
1991 mMapItem->endCommand();
1994 connect( mForceLabelsInsideCheckBox, &QCheckBox::toggled,
this, [ = ](
bool active )
1996 if ( !mBlockUpdates )
1998 mMapItem->beginCommand( tr(
"Change Atlas Clipping Label Behavior" ) );
1999 mMapItem->atlasClippingSettings()->setForceLabelsInsideFeature( active );
2000 mMapItem->endCommand();
2003 connect( mAtlasClippingTypeComboBox, qgis::overload<int>::of( &QComboBox::currentIndexChanged ),
this, [ = ]
2005 if ( !mBlockUpdates )
2007 mMapItem->beginCommand( tr(
"Change Atlas Clipping Behavior" ) );
2009 mMapItem->endCommand();
2013 connect( mRadioClipSelectedLayers, &QCheckBox::toggled,
this, [ = ](
bool active )
2015 if ( active && !mBlockUpdates )
2017 mBlockUpdates =
true;
2018 mMapItem->beginCommand( tr(
"Change Atlas Clipping Layers" ) );
2019 mMapItem->atlasClippingSettings()->setRestrictToLayers(
true );
2020 mMapItem->endCommand();
2021 mBlockUpdates =
false;
2024 connect( mRadioClipAllLayers, &QCheckBox::toggled,
this, [ = ](
bool active )
2026 if ( active && !mBlockUpdates )
2028 mBlockUpdates =
true;
2029 mMapItem->beginCommand( tr(
"Change Atlas Clipping Layers" ) );
2030 mMapItem->atlasClippingSettings()->setRestrictToLayers(
false );
2031 mMapItem->endCommand();
2032 mBlockUpdates =
false;
2035 connect( mLayerModel, &QgsMapLayerModel::dataChanged,
this, [ = ](
const QModelIndex &,
const QModelIndex &,
const QVector<int> &roles = QVector<int>() )
2037 if ( !roles.contains( Qt::CheckStateRole ) )
2040 if ( !mBlockUpdates )
2042 mBlockUpdates =
true;
2043 mMapItem->beginCommand( tr(
"Change Atlas Clipping Layers" ) );
2044 mMapItem->atlasClippingSettings()->setLayersToClip( mLayerModel->
layersChecked() );
2045 mMapItem->endCommand();
2046 mBlockUpdates =
false;
2052 connect( mClipToItemCheckBox, &QGroupBox::toggled,
this, [ = ](
bool active )
2054 if ( !mBlockUpdates )
2056 mMapItem->beginCommand( tr(
"Toggle Map Clipping" ) );
2057 mMapItem->itemClippingSettings()->setEnabled( active );
2058 mMapItem->endCommand();
2061 connect( mItemClippingTypeComboBox, qgis::overload<int>::of( &QComboBox::currentIndexChanged ),
this, [ = ]
2063 if ( !mBlockUpdates )
2065 mMapItem->beginCommand( tr(
"Change Map Clipping Behavior" ) );
2067 mMapItem->endCommand();
2070 connect( mForceLabelsInsideItemCheckBox, &QCheckBox::toggled,
this, [ = ](
bool active )
2072 if ( !mBlockUpdates )
2074 mMapItem->beginCommand( tr(
"Change Map Clipping Label Behavior" ) );
2075 mMapItem->itemClippingSettings()->setForceLabelsInsideClipPath( active );
2076 mMapItem->endCommand();
2081 if ( !mBlockUpdates )
2083 mMapItem->beginCommand( tr(
"Change Map Clipping Item" ) );
2084 mMapItem->itemClippingSettings()->setSourceItem( item );
2085 mMapItem->endCommand();
2092 this, &QgsLayoutMapClippingWidget::atlasLayerChanged );
2096 atlasToggled( atlas->enabled() );
2102 mClipToAtlasCheckBox->setTitle( tr(
"Clip to %1 feature" ).arg(
string ) );
2103 mClipToAtlasLabel->setText( tr(
"<b>When enabled, map layers will be automatically clipped to the boundary of the current %1 feature.</b>" ).arg(
string ) );
2104 mForceLabelsInsideCheckBox->setText( tr(
"Force labels inside %1 feature" ).arg(
string ) );
2117 mMapItem = qobject_cast< QgsLayoutItemMap * >( item );
2124 updateGuiElements();
2129 void QgsLayoutMapClippingWidget::updateGuiElements()
2131 if ( mBlockUpdates )
2134 mBlockUpdates =
true;
2135 mClipToAtlasCheckBox->setChecked( mMapItem->atlasClippingSettings()->enabled() );
2136 mAtlasClippingTypeComboBox->setCurrentIndex( mAtlasClippingTypeComboBox->findData(
static_cast< int >( mMapItem->atlasClippingSettings()->featureClippingType() ) ) );
2137 mForceLabelsInsideCheckBox->setChecked( mMapItem->atlasClippingSettings()->forceLabelsInsideFeature() );
2139 mRadioClipAllLayers->setChecked( !mMapItem->atlasClippingSettings()->restrictToLayers() );
2140 mRadioClipSelectedLayers->setChecked( mMapItem->atlasClippingSettings()->restrictToLayers() );
2141 mLayerModel->
setLayersChecked( mMapItem->atlasClippingSettings()->layersToClip() );
2143 mClipToItemCheckBox->setChecked( mMapItem->itemClippingSettings()->enabled() );
2144 mItemClippingTypeComboBox->setCurrentIndex( mItemClippingTypeComboBox->findData(
static_cast< int >( mMapItem->itemClippingSettings()->featureClippingType() ) ) );
2145 mForceLabelsInsideItemCheckBox->setChecked( mMapItem->itemClippingSettings()->forceLabelsInsideClipPath() );
2146 mClipItemComboBox->setItem( mMapItem->itemClippingSettings()->sourceItem() );
2148 mBlockUpdates =
false;
2151 void QgsLayoutMapClippingWidget::atlasLayerChanged(
QgsVectorLayer *layer )
2156 mClipToAtlasCheckBox->setChecked(
false );
2157 mClipToAtlasCheckBox->setEnabled(
false );
2162 mClipToAtlasCheckBox->setEnabled(
true );
2166 void QgsLayoutMapClippingWidget::atlasToggled(
bool atlasEnabled )
2168 if ( atlasEnabled &&
2169 mMapItem && mMapItem->layout() && mMapItem->layout()->reportContext().layer()
2172 mClipToAtlasCheckBox->setEnabled(
true );
2176 mClipToAtlasCheckBox->setEnabled(
false );
2177 mClipToAtlasCheckBox->setChecked(
false );