41 #include <QMessageBox>
42 #include <QStringListModel>
47 , mMapCanvas( mapCanvas )
52 connect( mScaleLineEdit, &QLineEdit::editingFinished,
this, &QgsLayoutMapWidget::mScaleLineEdit_editingFinished );
53 connect( mActionSetToCanvasExtent, &QAction::triggered,
this, &QgsLayoutMapWidget::setToMapCanvasExtent );
54 connect( mActionViewExtentInCanvas, &QAction::triggered,
this, &QgsLayoutMapWidget::viewExtentInCanvas );
55 connect( mActionSetToCanvasScale, &QAction::triggered,
this, &QgsLayoutMapWidget::setToMapCanvasScale );
56 connect( mActionViewScaleInCanvas, &QAction::triggered,
this, &QgsLayoutMapWidget::viewScaleInCanvas );
57 connect( mActionUpdatePreview, &QAction::triggered,
this, &QgsLayoutMapWidget::updatePreview );
58 connect( mFollowVisibilityPresetCheckBox, &QCheckBox::stateChanged,
this, &QgsLayoutMapWidget::mFollowVisibilityPresetCheckBox_stateChanged );
59 connect( mKeepLayerListCheckBox, &QCheckBox::stateChanged,
this, &QgsLayoutMapWidget::mKeepLayerListCheckBox_stateChanged );
60 connect( mKeepLayerStylesCheckBox, &QCheckBox::stateChanged,
this, &QgsLayoutMapWidget::mKeepLayerStylesCheckBox_stateChanged );
61 connect( mDrawCanvasItemsCheckBox, &QCheckBox::stateChanged,
this, &QgsLayoutMapWidget::mDrawCanvasItemsCheckBox_stateChanged );
62 connect( mOverviewBlendModeComboBox,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsLayoutMapWidget::mOverviewBlendModeComboBox_currentIndexChanged );
63 connect( mOverviewInvertCheckbox, &QCheckBox::toggled,
this, &QgsLayoutMapWidget::mOverviewInvertCheckbox_toggled );
64 connect( mOverviewCenterCheckbox, &QCheckBox::toggled,
this, &QgsLayoutMapWidget::mOverviewCenterCheckbox_toggled );
65 connect( mOverviewPositionComboBox,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsLayoutMapWidget::overviewStackingChanged );
67 connect( mXMinLineEdit, &QLineEdit::editingFinished,
this, &QgsLayoutMapWidget::mXMinLineEdit_editingFinished );
68 connect( mXMaxLineEdit, &QLineEdit::editingFinished,
this, &QgsLayoutMapWidget::mXMaxLineEdit_editingFinished );
69 connect( mYMinLineEdit, &QLineEdit::editingFinished,
this, &QgsLayoutMapWidget::mYMinLineEdit_editingFinished );
70 connect( mYMaxLineEdit, &QLineEdit::editingFinished,
this, &QgsLayoutMapWidget::mYMaxLineEdit_editingFinished );
71 connect( mAtlasMarginRadio, &QRadioButton::toggled,
this, &QgsLayoutMapWidget::mAtlasMarginRadio_toggled );
72 connect( mAtlasCheckBox, &QgsCollapsibleGroupBoxBasic::toggled,
this, &QgsLayoutMapWidget::mAtlasCheckBox_toggled );
73 connect( mAtlasMarginSpinBox,
static_cast < void ( QSpinBox::* )(
int )
> ( &QSpinBox::valueChanged ),
this, &QgsLayoutMapWidget::mAtlasMarginSpinBox_valueChanged );
74 connect( mAtlasFixedScaleRadio, &QRadioButton::toggled,
this, &QgsLayoutMapWidget::mAtlasFixedScaleRadio_toggled );
75 connect( mAtlasPredefinedScaleRadio, &QRadioButton::toggled,
this, &QgsLayoutMapWidget::mAtlasPredefinedScaleRadio_toggled );
76 connect( mAddGridPushButton, &QPushButton::clicked,
this, &QgsLayoutMapWidget::mAddGridPushButton_clicked );
77 connect( mRemoveGridPushButton, &QPushButton::clicked,
this, &QgsLayoutMapWidget::mRemoveGridPushButton_clicked );
78 connect( mGridUpButton, &QPushButton::clicked,
this, &QgsLayoutMapWidget::mGridUpButton_clicked );
79 connect( mGridDownButton, &QPushButton::clicked,
this, &QgsLayoutMapWidget::mGridDownButton_clicked );
80 connect( mGridListWidget, &QListWidget::currentItemChanged,
this, &QgsLayoutMapWidget::mGridListWidget_currentItemChanged );
81 connect( mGridListWidget, &QListWidget::itemChanged,
this, &QgsLayoutMapWidget::mGridListWidget_itemChanged );
82 connect( mGridPropertiesButton, &QPushButton::clicked,
this, &QgsLayoutMapWidget::mGridPropertiesButton_clicked );
83 connect( mAddOverviewPushButton, &QPushButton::clicked,
this, &QgsLayoutMapWidget::mAddOverviewPushButton_clicked );
84 connect( mRemoveOverviewPushButton, &QPushButton::clicked,
this, &QgsLayoutMapWidget::mRemoveOverviewPushButton_clicked );
85 connect( mOverviewUpButton, &QPushButton::clicked,
this, &QgsLayoutMapWidget::mOverviewUpButton_clicked );
86 connect( mOverviewDownButton, &QPushButton::clicked,
this, &QgsLayoutMapWidget::mOverviewDownButton_clicked );
87 connect( mOverviewCheckBox, &QgsCollapsibleGroupBoxBasic::toggled,
this, &QgsLayoutMapWidget::mOverviewCheckBox_toggled );
88 connect( mOverviewListWidget, &QListWidget::currentItemChanged,
this, &QgsLayoutMapWidget::mOverviewListWidget_currentItemChanged );
89 connect( mOverviewListWidget, &QListWidget::itemChanged,
this, &QgsLayoutMapWidget::mOverviewListWidget_itemChanged );
90 connect( mActionLabelSettings, &QAction::triggered,
this, &QgsLayoutMapWidget::showLabelSettings );
91 connect( mActionClipSettings, &QAction::triggered,
this, &QgsLayoutMapWidget::showClipSettings );
93 connect( mTemporalCheckBox, &QgsCollapsibleGroupBoxBasic::toggled,
this, &QgsLayoutMapWidget::mTemporalCheckBox_toggled );
94 connect( mStartDateTime, &QDateTimeEdit::dateTimeChanged,
this, &QgsLayoutMapWidget::updateTemporalExtent );
95 connect( mEndDateTime, &QDateTimeEdit::dateTimeChanged,
this, &QgsLayoutMapWidget::updateTemporalExtent );
97 mStartDateTime->setDateTimeRange( QDateTime( QDate( 1, 1, 1 ), QTime( 0, 0, 0 ) ), mStartDateTime->maximumDateTime() );
98 mEndDateTime->setDateTimeRange( QDateTime( QDate( 1, 1, 1 ), QTime( 0, 0, 0 ) ), mStartDateTime->maximumDateTime() );
99 mStartDateTime->setDisplayFormat(
"yyyy-MM-dd HH:mm:ss" );
100 mEndDateTime->setDisplayFormat(
"yyyy-MM-dd HH:mm:ss" );
102 connect( mActionMoveContent, &QAction::triggered,
this, &QgsLayoutMapWidget::switchToMoveContentTool );
104 mMapRotationSpinBox->setClearValue( 0 );
108 mBookmarkMenu =
new QMenu(
this );
109 QToolButton *btnBookmarks =
new QToolButton(
this );
110 btnBookmarks->setAutoRaise(
true );
111 btnBookmarks->setToolTip( tr(
"Bookmarks" ) );
113 btnBookmarks->setPopupMode( QToolButton::InstantPopup );
114 btnBookmarks->setMenu( mBookmarkMenu );
116 mDockToolbar->insertWidget( mActionMoveContent, btnBookmarks );
117 connect( mBookmarkMenu, &QMenu::aboutToShow,
this, &QgsLayoutMapWidget::aboutToShowBookmarkMenu );
121 mainLayout->addWidget( mItemPropertiesWidget );
123 mScaleLineEdit->setValidator(
new QDoubleValidator( mScaleLineEdit ) );
125 mXMinLineEdit->setValidator(
new QDoubleValidator( mXMinLineEdit ) );
126 mXMaxLineEdit->setValidator(
new QDoubleValidator( mXMaxLineEdit ) );
127 mYMinLineEdit->setValidator(
new QDoubleValidator( mYMinLineEdit ) );
128 mYMaxLineEdit->setValidator(
new QDoubleValidator( mYMaxLineEdit ) );
136 blockAllSignals(
true );
139 mCrsSelector->setNotSetText( tr(
"Use Project CRS" ) );
140 mCrsSelector->setDialogTitle( tr(
"Map Item CRS" ) );
145 mFollowVisibilityPresetCombo->setModel(
new QStringListModel( mFollowVisibilityPresetCombo ) );
146 connect( mFollowVisibilityPresetCombo,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsLayoutMapWidget::followVisibilityPresetSelected );
148 this, &QgsLayoutMapWidget::onMapThemesChanged );
149 onMapThemesChanged();
152 QMenu *menuKeepLayers =
new QMenu(
this );
153 mLayerListFromPresetButton->setMenu( menuKeepLayers );
155 mLayerListFromPresetButton->setToolTip( tr(
"Set layer list from a map theme" ) );
156 connect( menuKeepLayers, &QMenu::aboutToShow,
this, &QgsLayoutMapWidget::aboutToShowKeepLayersVisibilityPresetsMenu );
161 this, &QgsLayoutMapWidget::atlasLayerChanged );
165 compositionAtlasToggled( atlas->enabled() );
168 mOverviewFrameMapComboBox->setCurrentLayout( item->
layout() );
170 mOverviewFrameStyleButton->registerExpressionContextGenerator( item );
176 mOverviewFrameStyleButton->registerExpressionContextGenerator( item );
199 loadOverviewEntries();
201 connect( mMapRotationSpinBox,
static_cast < void (
QgsDoubleSpinBox::* )(
double )
> ( &QgsDoubleSpinBox::valueChanged ),
this, &QgsLayoutMapWidget::rotationChanged );
205 blockAllSignals(
false );
210 if ( mItemPropertiesWidget )
216 mReportTypeString = string;
217 mAtlasCheckBox->setTitle( tr(
"Controlled by %1" ).arg(
string == tr(
"atlas" ) ? tr(
"Atlas" ) : tr(
"Report" ) ) );
218 mAtlasPredefinedScaleRadio->setToolTip( tr(
"Use one of the predefined scales of the project where the %1 feature best fits." ).arg(
string ) );
221 mClipWidget->setReportTypeString(
string );
223 mLabelWidget->setReportTypeString(
string );
244 mMapItem = qobject_cast< QgsLayoutItemMap * >( item );
245 mItemPropertiesWidget->
setItem( mMapItem );
247 mLabelWidget->setItem( mMapItem );
249 mClipWidget->setItem( mMapItem );
256 mOverviewFrameStyleButton->registerExpressionContextGenerator( mMapItem );
280 void QgsLayoutMapWidget::compositionAtlasToggled(
bool atlasEnabled )
283 mMapItem && mMapItem->layout() && mMapItem->layout()->reportContext().layer()
286 mAtlasCheckBox->setEnabled(
true );
290 mAtlasCheckBox->setEnabled(
false );
291 mAtlasCheckBox->setChecked(
false );
295 void QgsLayoutMapWidget::aboutToShowKeepLayersVisibilityPresetsMenu()
300 QMenu *menu = qobject_cast<QMenu *>( sender() );
306 for (
const QString &presetName : constMapThemes )
308 menu->addAction( presetName,
this, &QgsLayoutMapWidget::keepLayersVisibilityPresetSelected );
311 if ( menu->actions().isEmpty() )
312 menu->addAction( tr(
"No presets defined" ) )->setEnabled(
false );
315 void QgsLayoutMapWidget::followVisibilityPresetSelected(
int currentIndex )
320 if ( mBlockThemeComboChanges != 0 )
323 if ( currentIndex == -1 )
327 if ( currentIndex != 0 )
329 presetName = mFollowVisibilityPresetCombo->currentText();
332 if ( presetName == mMapItem->followVisibilityPresetName() )
335 mMapItem->layout()->undoStack()->beginCommand( mMapItem, tr(
"Change Map Preset" ) );
336 mFollowVisibilityPresetCheckBox->setChecked(
true );
337 mMapItem->setFollowVisibilityPresetName( presetName );
338 mMapItem->layout()->undoStack()->endCommand();
340 mMapItem->invalidateCache();
343 void QgsLayoutMapWidget::keepLayersVisibilityPresetSelected()
345 QAction *action = qobject_cast<QAction *>( sender() );
349 const QString presetName = action->text();
350 const QList<QgsMapLayer *> lst = orderedPresetVisibleLayers( presetName );
353 mKeepLayerListCheckBox->setChecked(
true );
354 mMapItem->setLayers( lst );
356 mKeepLayerStylesCheckBox->setChecked(
true );
358 mMapItem->layout()->undoStack()->beginCommand( mMapItem, tr(
"Change Map Preset" ) );
359 mMapItem->setLayerStyleOverrides(
QgsProject::instance()->mapThemeCollection()->mapThemeStyleOverrides( presetName ) );
360 mMapItem->layout()->undoStack()->endCommand();
362 mMapItem->invalidateCache();
366 void QgsLayoutMapWidget::onMapThemesChanged()
368 if ( QStringListModel *model = qobject_cast<QStringListModel *>( mFollowVisibilityPresetCombo->model() ) )
370 mBlockThemeComboChanges++;
372 lst.append( tr(
"(none)" ) );
374 model->setStringList( lst );
377 const int presetModelIndex = mFollowVisibilityPresetCombo->findText( mMapItem->followVisibilityPresetName() );
378 mFollowVisibilityPresetCombo->blockSignals(
true );
379 mFollowVisibilityPresetCombo->setCurrentIndex( presetModelIndex != -1 ? presetModelIndex : 0 );
380 mFollowVisibilityPresetCombo->blockSignals(
false );
381 mBlockThemeComboChanges--;
392 if ( mMapItem->presetCrs() ==
crs )
398 bool updateExtent =
false;
403 xForm.setBallparkTransformsAreAppropriate(
true );
405 newExtent = xForm.transformBoundingBox( prevExtent );
413 mMapItem->layout()->undoStack()->beginCommand( mMapItem, tr(
"Change Map CRS" ) );
414 mMapItem->setCrs(
crs );
416 mMapItem->zoomToExtent( newExtent );
417 mMapItem->layout()->undoStack()->endCommand();
418 mMapItem->invalidateCache();
421 void QgsLayoutMapWidget::overviewSymbolChanged()
429 mMapItem->endCommand();
430 mMapItem->invalidateCache();
433 void QgsLayoutMapWidget::showLabelSettings()
437 if ( !mReportTypeString.isEmpty() )
438 mLabelWidget->setReportTypeString( mReportTypeString );
443 void QgsLayoutMapWidget::showClipSettings()
446 if ( !mReportTypeString.isEmpty() )
447 mClipWidget->setReportTypeString( mReportTypeString );
451 void QgsLayoutMapWidget::switchToMoveContentTool()
457 void QgsLayoutMapWidget::aboutToShowBookmarkMenu()
459 mBookmarkMenu->clear();
463 if ( !mBookmarkModel )
466 QMap< QString, QMenu * > groupMenus;
467 for (
int i = 0; i < mBookmarkModel->rowCount(); ++i )
470 QMenu *destMenu = mBookmarkMenu;
471 if ( !group.isEmpty() )
473 destMenu = groupMenus.value( group );
476 destMenu =
new QMenu( group, mBookmarkMenu );
477 groupMenus[ group ] = destMenu;
482 connect( action, &QAction::triggered,
this, [ = ]
492 if ( extent.
crs() != mMapItem->crs() )
496 QgsCoordinateTransform xForm( extent.crs(), mMapItem->crs(), QgsProject::instance() );
497 xForm.setBallparkTransformsAreAppropriate( true );
498 newExtent = xForm.transformBoundingBox( newExtent );
507 mMapItem->layout()->undoStack()->beginCommand( mMapItem, tr(
"Change Map Extent" ) );
508 mMapItem->zoomToExtent( newExtent );
509 mMapItem->layout()->undoStack()->endCommand();
511 destMenu->addAction( action );
514 QStringList groupKeys = groupMenus.keys();
515 groupKeys.sort( Qt::CaseInsensitive );
516 for (
int i = 0; i < groupKeys.count(); ++i )
518 if ( mBookmarkMenu->actions().value( i ) )
519 mBookmarkMenu->insertMenu( mBookmarkMenu->actions().at( i ), groupMenus.value( groupKeys.at( i ) ) );
521 mBookmarkMenu->addMenu( groupMenus.value( groupKeys.at( i ) ) );
525 void QgsLayoutMapWidget::mTemporalCheckBox_toggled(
bool checked )
532 mMapItem->layout()->undoStack()->beginCommand( mMapItem, tr(
"Toggle Temporal Range" ) );
533 mMapItem->setIsTemporal( checked );
534 mMapItem->layout()->undoStack()->endCommand();
538 whileBlocking( mStartDateTime )->setDateTime( mMapItem->temporalRange().begin() );
539 whileBlocking( mEndDateTime )->setDateTime( mMapItem->temporalRange().end() );
545 void QgsLayoutMapWidget::updateTemporalExtent()
552 const QDateTime begin = mStartDateTime->dateTime();
553 const QDateTime end = mEndDateTime->dateTime();
554 const QgsDateTimeRange range = QgsDateTimeRange( begin, end,
true, begin == end );
556 mMapItem->layout()->undoStack()->beginCommand( mMapItem, tr(
"Set Temporal Range" ) );
557 mMapItem->setTemporalRange( range );
558 mMapItem->layout()->undoStack()->endCommand();
563 void QgsLayoutMapWidget::mAtlasCheckBox_toggled(
bool checked )
570 mAtlasFixedScaleRadio->setEnabled( checked );
571 mAtlasMarginRadio->setEnabled( checked );
573 if ( mAtlasMarginRadio->isEnabled() && mAtlasMarginRadio->isChecked() )
575 mAtlasMarginSpinBox->setEnabled(
true );
579 mAtlasMarginSpinBox->setEnabled(
false );
582 mAtlasPredefinedScaleRadio->setEnabled( checked );
587 if ( mMapItem->layout() )
589 toggleAtlasScalingOptionsByLayerType();
594 if ( !hasPredefinedScales() )
596 mAtlasPredefinedScaleRadio->setEnabled(
false );
599 mMapItem->layout()->undoStack()->beginCommand( mMapItem, tr(
"Set Atlas Driven" ) );
600 mMapItem->setAtlasDriven( checked );
601 mMapItem->layout()->undoStack()->endCommand();
605 void QgsLayoutMapWidget::updateMapForAtlas()
608 if ( mMapItem->atlasDriven() )
615 mMapItem->invalidateCache();
619 void QgsLayoutMapWidget::mAtlasMarginRadio_toggled(
bool checked )
621 mAtlasMarginSpinBox->setEnabled( checked );
623 if ( checked && mMapItem )
625 mMapItem->layout()->undoStack()->beginCommand( mMapItem, tr(
"Change Atlas Mode" ) );
627 mMapItem->layout()->undoStack()->endCommand();
632 void QgsLayoutMapWidget::mAtlasMarginSpinBox_valueChanged(
int value )
640 mMapItem->setAtlasMargin( value / 100. );
641 mMapItem->layout()->undoStack()->endCommand();
645 void QgsLayoutMapWidget::mAtlasFixedScaleRadio_toggled(
bool checked )
654 mMapItem->layout()->undoStack()->beginCommand( mMapItem, tr(
"Change Atlas Mode" ) );
656 mMapItem->layout()->undoStack()->endCommand();
661 void QgsLayoutMapWidget::mAtlasPredefinedScaleRadio_toggled(
bool checked )
668 if ( hasPredefinedScales() )
672 mMapItem->layout()->undoStack()->beginCommand( mMapItem, tr(
"Change Atlas Scales" ) );
674 mMapItem->layout()->undoStack()->endCommand();
682 mMapItem->layout()->undoStack()->beginCommand( mMapItem, tr(
"Change Atlas Mode" ) );
684 mMapItem->layout()->undoStack()->endCommand();
688 void QgsLayoutMapWidget::mScaleLineEdit_editingFinished()
695 bool conversionSuccess =
false;
696 const double scaleDenominator = QLocale().toDouble( mScaleLineEdit->text(), &conversionSuccess );
697 if ( !conversionSuccess )
705 mMapItem->layout()->undoStack()->beginCommand( mMapItem, tr(
"Change Map Scale" ) );
706 mMapItem->setScale( scaleDenominator );
707 mMapItem->layout()->undoStack()->endCommand();
710 void QgsLayoutMapWidget::rotationChanged(
double value )
718 mMapItem->setMapRotation( value );
719 mMapItem->layout()->undoStack()->endCommand();
720 mMapItem->invalidateCache();
723 void QgsLayoutMapWidget::setToMapCanvasExtent()
740 xForm.setBallparkTransformsAreAppropriate(
true );
741 newExtent = xForm.transformBoundingBox( newExtent );
750 mMapItem->layout()->undoStack()->beginCommand( mMapItem, tr(
"Change Map Extent" ) );
751 mMapItem->zoomToExtent( newExtent );
752 mMapItem->layout()->undoStack()->endCommand();
755 void QgsLayoutMapWidget::setToMapCanvasScale()
762 const double newScale = mMapCanvas->
scale();
764 mMapItem->layout()->undoStack()->beginCommand( mMapItem, tr(
"Change Map Scale" ) );
765 mMapItem->setScale( newScale );
766 mMapItem->layout()->undoStack()->endCommand();
769 void QgsLayoutMapWidget::viewExtentInCanvas()
776 const QgsRectangle currentMapExtent = mMapItem->extent();
778 if ( !currentMapExtent.
isEmpty() )
793 void QgsLayoutMapWidget::viewScaleInCanvas()
800 const double currentScale = mMapItem->scale();
801 mMapCanvas->
zoomScale( currentScale,
true );
804 void QgsLayoutMapWidget::mXMinLineEdit_editingFinished()
806 updateComposerExtentFromGui();
809 void QgsLayoutMapWidget::mXMaxLineEdit_editingFinished()
811 updateComposerExtentFromGui();
814 void QgsLayoutMapWidget::mYMinLineEdit_editingFinished()
816 updateComposerExtentFromGui();
819 void QgsLayoutMapWidget::mYMaxLineEdit_editingFinished()
821 updateComposerExtentFromGui();
824 void QgsLayoutMapWidget::updateGuiElements()
831 blockAllSignals(
true );
832 mLabel->setText( mMapItem->displayName() );
834 whileBlocking( mCrsSelector )->setCrs( mMapItem->presetCrs() );
837 const double scale = mMapItem->scale();
840 if ( scale >= 10000 )
843 mScaleLineEdit->setText( QLocale().toString( mMapItem->scale(),
'f', 0 ) );
845 else if ( scale >= 10 )
847 mScaleLineEdit->setText( QLocale().toString( mMapItem->scale(),
'f', 3 ) );
849 else if ( scale >= 1 )
852 mScaleLineEdit->setText( QLocale().toString( mMapItem->scale(),
'f', 4 ) );
857 mScaleLineEdit->setText( QLocale().toString( mMapItem->scale(),
'f', 10 ) );
861 const QgsRectangle composerMapExtent = mMapItem->extent();
862 mXMinLineEdit->setText( QLocale().toString( composerMapExtent.
xMinimum(),
'f', 3 ) );
863 mXMaxLineEdit->setText( QLocale().toString( composerMapExtent.
xMaximum(),
'f', 3 ) );
864 mYMinLineEdit->setText( QLocale().toString( composerMapExtent.
yMinimum(),
'f', 3 ) );
865 mYMaxLineEdit->setText( QLocale().toString( composerMapExtent.
yMaximum(),
'f', 3 ) );
870 mFollowVisibilityPresetCheckBox->setCheckState(
871 mMapItem->followVisibilityPreset() ? Qt::Checked : Qt::Unchecked );
872 const int presetModelIndex = mFollowVisibilityPresetCombo->findText( mMapItem->followVisibilityPresetName() );
873 mFollowVisibilityPresetCombo->setCurrentIndex( presetModelIndex != -1 ? presetModelIndex : 0 );
876 if ( mMapItem->keepLayerSet() )
878 mKeepLayerListCheckBox->setCheckState( Qt::Checked );
882 mKeepLayerListCheckBox->setCheckState( Qt::Unchecked );
885 mKeepLayerStylesCheckBox->setEnabled( mMapItem->keepLayerSet() );
886 mKeepLayerStylesCheckBox->setCheckState( mMapItem->keepLayerStyles() ? Qt::Checked : Qt::Unchecked );
889 if ( mMapItem->drawAnnotations() )
891 mDrawCanvasItemsCheckBox->setCheckState( Qt::Checked );
895 mDrawCanvasItemsCheckBox->setCheckState( Qt::Unchecked );
899 mAtlasCheckBox->setChecked( mMapItem->atlasDriven() );
902 mAtlasFixedScaleRadio->setEnabled( mMapItem->atlasDriven() );
905 mAtlasMarginRadio->setEnabled( mMapItem->atlasDriven() );
907 mAtlasPredefinedScaleRadio->setEnabled( mMapItem->atlasDriven() );
910 if ( mMapItem->atlasDriven() )
912 toggleAtlasScalingOptionsByLayerType();
915 if ( !hasPredefinedScales() )
917 mAtlasPredefinedScaleRadio->setEnabled(
false );
920 mTemporalCheckBox->setChecked( mMapItem->isTemporal() );
921 mTemporalCheckBox->setCollapsed( !mMapItem->isTemporal() );
922 mStartDateTime->setEnabled( mMapItem->isTemporal() );
923 mEndDateTime->setEnabled( mMapItem->isTemporal() );
924 if ( mMapItem->isTemporal() )
926 mStartDateTime->setDateTime( mMapItem->temporalRange().begin() );
927 mEndDateTime->setDateTime( mMapItem->temporalRange().end() );
932 loadOverviewEntries();
934 blockAllSignals(
false );
937 void QgsLayoutMapWidget::toggleAtlasScalingOptionsByLayerType()
955 mAtlasFixedScaleRadio->setChecked(
true );
956 mAtlasMarginRadio->setEnabled(
false );
961 mAtlasMarginRadio->setEnabled(
true );
965 void QgsLayoutMapWidget::updateComposerExtentFromGui()
972 double xmin, ymin, xmax, ymax;
973 bool conversionSuccess;
975 xmin = QLocale().toDouble( mXMinLineEdit->text(), &conversionSuccess );
976 if ( !conversionSuccess )
978 xmax = QLocale().toDouble( mXMaxLineEdit->text(), &conversionSuccess );
979 if ( !conversionSuccess )
981 ymin = QLocale().toDouble( mYMinLineEdit->text(), &conversionSuccess );
982 if ( !conversionSuccess )
984 ymax = QLocale().toDouble( mYMaxLineEdit->text(), &conversionSuccess );
985 if ( !conversionSuccess )
990 mMapItem->layout()->undoStack()->beginCommand( mMapItem, tr(
"Change Map Extent" ) );
991 mMapItem->setExtent( newExtent );
992 mMapItem->layout()->undoStack()->endCommand();
995 void QgsLayoutMapWidget::blockAllSignals(
bool b )
997 mScaleLineEdit->blockSignals( b );
998 mXMinLineEdit->blockSignals( b );
999 mXMaxLineEdit->blockSignals( b );
1000 mYMinLineEdit->blockSignals( b );
1001 mYMaxLineEdit->blockSignals( b );
1002 mDrawCanvasItemsCheckBox->blockSignals( b );
1003 mOverviewFrameMapComboBox->blockSignals( b );
1004 mOverviewFrameStyleButton->blockSignals( b );
1005 mOverviewBlendModeComboBox->blockSignals( b );
1006 mOverviewInvertCheckbox->blockSignals( b );
1007 mOverviewCenterCheckbox->blockSignals( b );
1008 mAtlasCheckBox->blockSignals( b );
1009 mAtlasMarginSpinBox->blockSignals( b );
1010 mAtlasFixedScaleRadio->blockSignals( b );
1011 mAtlasMarginRadio->blockSignals( b );
1012 mFollowVisibilityPresetCheckBox->blockSignals( b );
1013 mFollowVisibilityPresetCombo->blockSignals( b );
1014 mKeepLayerListCheckBox->blockSignals( b );
1015 mKeepLayerStylesCheckBox->blockSignals( b );
1016 mActionSetToCanvasExtent->blockSignals( b );
1017 mActionUpdatePreview->blockSignals( b );
1018 mTemporalCheckBox->blockSignals( b );
1019 mStartDateTime->blockSignals( b );
1020 mEndDateTime->blockSignals( b );
1022 blockOverviewItemsSignals( b );
1025 void QgsLayoutMapWidget::updatePreview()
1031 mMapItem->refresh();
1034 void QgsLayoutMapWidget::mFollowVisibilityPresetCheckBox_stateChanged(
int state )
1041 mMapItem->layout()->undoStack()->beginCommand( mMapItem, tr(
"Change Map Preset" ) );
1042 if ( state == Qt::Checked )
1044 mMapItem->setFollowVisibilityPreset(
true );
1047 mKeepLayerListCheckBox->setCheckState( Qt::Unchecked );
1048 mKeepLayerStylesCheckBox->setCheckState( Qt::Unchecked );
1050 mMapItem->invalidateCache();
1054 mMapItem->setFollowVisibilityPreset(
false );
1056 mMapItem->layout()->undoStack()->endCommand();
1059 void QgsLayoutMapWidget::mKeepLayerListCheckBox_stateChanged(
int state )
1067 mMapItem->layout()->undoStack()->beginCommand( mMapItem, tr(
"Map Preset Changed" ) );
1068 storeCurrentLayerSet();
1069 mMapItem->setKeepLayerSet( state == Qt::Checked );
1070 if ( state == Qt::Unchecked )
1072 mMapItem->setLayers( QList< QgsMapLayer * >() );
1074 mMapItem->layout()->undoStack()->endCommand();
1077 if ( state == Qt::Checked )
1080 mFollowVisibilityPresetCheckBox->setCheckState( Qt::Unchecked );
1084 mKeepLayerStylesCheckBox->setChecked( Qt::Unchecked );
1085 mMapItem->invalidateCache();
1088 mKeepLayerStylesCheckBox->setEnabled( state == Qt::Checked );
1091 void QgsLayoutMapWidget::mKeepLayerStylesCheckBox_stateChanged(
int state )
1098 mMapItem->layout()->undoStack()->beginCommand( mMapItem, tr(
"Change Map Preset" ) );
1099 if ( state == Qt::Checked )
1101 mMapItem->storeCurrentLayerStyles();
1102 mMapItem->setKeepLayerStyles(
true );
1106 mMapItem->setLayerStyleOverrides( QMap<QString, QString>() );
1107 mMapItem->setKeepLayerStyles(
false );
1109 mMapItem->layout()->undoStack()->endCommand();
1112 void QgsLayoutMapWidget::mDrawCanvasItemsCheckBox_stateChanged(
int state )
1119 mMapItem->layout()->undoStack()->beginCommand( mMapItem, tr(
"Toggle Map Item" ) );
1120 mMapItem->setDrawAnnotations( state == Qt::Checked );
1121 mMapItem->invalidateCache();
1122 mMapItem->layout()->undoStack()->endCommand();
1125 void QgsLayoutMapWidget::atlasLayerChanged(
QgsVectorLayer *layer )
1130 mAtlasCheckBox->setChecked(
false );
1131 mAtlasCheckBox->setEnabled(
false );
1136 mAtlasCheckBox->setEnabled(
true );
1140 if ( mAtlasCheckBox->isChecked() )
1141 toggleAtlasScalingOptionsByLayerType();
1144 bool QgsLayoutMapWidget::hasPredefinedScales()
const
1149 if ( !hasProjectScales || scales.isEmpty() )
1154 QStringList myScalesList = scalesStr.split(
',' );
1155 return !myScalesList.isEmpty() && !myScalesList[0].isEmpty();
1160 void QgsLayoutMapWidget::mAddGridPushButton_clicked()
1167 const QString itemName = tr(
"Grid %1" ).arg( mMapItem->grids()->size() + 1 );
1169 mMapItem->layout()->undoStack()->beginCommand( mMapItem, tr(
"Add Map Grid" ) );
1170 mMapItem->grids()->addGrid( grid );
1171 mMapItem->layout()->undoStack()->endCommand();
1172 mMapItem->updateBoundingRect();
1175 addGridListItem( grid->
id(), grid->
name() );
1176 mGridListWidget->setCurrentRow( 0 );
1177 mGridListWidget_currentItemChanged( mGridListWidget->currentItem(),
nullptr );
1180 void QgsLayoutMapWidget::mRemoveGridPushButton_clicked()
1182 QListWidgetItem *item = mGridListWidget->currentItem();
1188 mMapItem->beginCommand( tr(
"Remove Grid" ) );
1189 mMapItem->grids()->removeGrid( item->data( Qt::UserRole ).toString() );
1190 QListWidgetItem *delItem = mGridListWidget->takeItem( mGridListWidget->row( item ) );
1192 mMapItem->endCommand();
1193 mMapItem->updateBoundingRect();
1197 void QgsLayoutMapWidget::mGridUpButton_clicked()
1199 QListWidgetItem *item = mGridListWidget->currentItem();
1205 const int row = mGridListWidget->row( item );
1210 mGridListWidget->takeItem( row );
1211 mGridListWidget->insertItem( row - 1, item );
1212 mGridListWidget->setCurrentItem( item );
1213 mMapItem->beginCommand( tr(
"Move Grid Up" ) );
1214 mMapItem->grids()->moveGridUp( item->data( Qt::UserRole ).toString() );
1215 mMapItem->endCommand();
1219 void QgsLayoutMapWidget::mGridDownButton_clicked()
1221 QListWidgetItem *item = mGridListWidget->currentItem();
1227 const int row = mGridListWidget->row( item );
1228 if ( mGridListWidget->count() <= row )
1232 mGridListWidget->takeItem( row );
1233 mGridListWidget->insertItem( row + 1, item );
1234 mGridListWidget->setCurrentItem( item );
1235 mMapItem->beginCommand( tr(
"Move Grid Down" ) );
1236 mMapItem->grids()->moveGridDown( item->data( Qt::UserRole ).toString() );
1237 mMapItem->endCommand();
1248 QListWidgetItem *item = mGridListWidget->currentItem();
1253 return mMapItem->grids()->grid( item->data( Qt::UserRole ).toString() );
1256 void QgsLayoutMapWidget::mGridListWidget_currentItemChanged( QListWidgetItem *current, QListWidgetItem * )
1258 mGridPropertiesButton->setEnabled(
static_cast< bool >( current ) );
1261 void QgsLayoutMapWidget::mGridListWidget_itemChanged( QListWidgetItem *item )
1274 mMapItem->beginCommand( tr(
"Rename Grid" ) );
1275 grid->
setName( item->text() );
1276 mMapItem->endCommand();
1279 void QgsLayoutMapWidget::mGridPropertiesButton_clicked()
1296 QListWidgetItem *QgsLayoutMapWidget::addGridListItem(
const QString &
id,
const QString &name )
1298 QListWidgetItem *item =
new QListWidgetItem( name,
nullptr );
1299 item->setData( Qt::UserRole,
id );
1300 item->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable );
1301 mGridListWidget->insertItem( 0, item );
1305 void QgsLayoutMapWidget::loadGridEntries()
1308 QSet<QString> selectedIds;
1309 const QList<QListWidgetItem *> itemSelection = mGridListWidget->selectedItems();
1310 QList<QListWidgetItem *>::const_iterator sIt = itemSelection.constBegin();
1311 for ( ; sIt != itemSelection.constEnd(); ++sIt )
1313 selectedIds.insert( ( *sIt )->data( Qt::UserRole ).toString() );
1316 mGridListWidget->clear();
1322 const QList< QgsLayoutItemMapGrid * > grids = mMapItem->grids()->asList();
1323 QList< QgsLayoutItemMapGrid * >::const_iterator gridIt = grids.constBegin();
1324 for ( ; gridIt != grids.constEnd(); ++gridIt )
1326 QListWidgetItem *item = addGridListItem( ( *gridIt )->id(), ( *gridIt )->name() );
1327 if ( selectedIds.contains( ( *gridIt )->id() ) )
1329 item->setSelected(
true );
1330 mGridListWidget->setCurrentItem( item );
1334 if ( mGridListWidget->currentItem() )
1336 mGridListWidget_currentItemChanged( mGridListWidget->currentItem(),
nullptr );
1340 mGridListWidget_currentItemChanged(
nullptr,
nullptr );
1344 void QgsLayoutMapWidget::mAddOverviewPushButton_clicked()
1351 const QString itemName = tr(
"Overview %1" ).arg( mMapItem->overviews()->size() + 1 );
1353 mMapItem->layout()->undoStack()->beginCommand( mMapItem, tr(
"Add Map Overview" ) );
1354 mMapItem->overviews()->addOverview( overview );
1355 mMapItem->layout()->undoStack()->endCommand();
1356 mMapItem->invalidateCache();
1358 addOverviewListItem( overview->
id(), overview->
name() );
1360 mOverviewListWidget->setCurrentRow( 0 );
1363 void QgsLayoutMapWidget::mRemoveOverviewPushButton_clicked()
1365 QListWidgetItem *item = mOverviewListWidget->currentItem();
1370 mMapItem->beginCommand( tr(
"Remove Map Overview" ) );
1371 mMapItem->overviews()->removeOverview( item->data( Qt::UserRole ).toString() );
1372 mMapItem->endCommand();
1373 QListWidgetItem *delItem = mOverviewListWidget->takeItem( mOverviewListWidget->row( item ) );
1375 mMapItem->invalidateCache();
1378 void QgsLayoutMapWidget::mOverviewUpButton_clicked()
1380 QListWidgetItem *item = mOverviewListWidget->currentItem();
1386 const int row = mOverviewListWidget->row( item );
1391 mOverviewListWidget->takeItem( row );
1392 mOverviewListWidget->insertItem( row - 1, item );
1393 mOverviewListWidget->setCurrentItem( item );
1394 mMapItem->beginCommand( tr(
"Move Overview Up" ) );
1395 mMapItem->overviews()->moveOverviewUp( item->data( Qt::UserRole ).toString() );
1396 mMapItem->endCommand();
1397 mMapItem->invalidateCache();
1400 void QgsLayoutMapWidget::mOverviewDownButton_clicked()
1402 QListWidgetItem *item = mOverviewListWidget->currentItem();
1408 const int row = mOverviewListWidget->row( item );
1409 if ( mOverviewListWidget->count() <= row )
1413 mOverviewListWidget->takeItem( row );
1414 mOverviewListWidget->insertItem( row + 1, item );
1415 mOverviewListWidget->setCurrentItem( item );
1416 mMapItem->beginCommand( tr(
"Move Overview Down" ) );
1417 mMapItem->overviews()->moveOverviewDown( item->data( Qt::UserRole ).toString() );
1418 mMapItem->endCommand();
1419 mMapItem->invalidateCache();
1429 QListWidgetItem *item = mOverviewListWidget->currentItem();
1435 return mMapItem->overviews()->overview( item->data( Qt::UserRole ).toString() );
1438 void QgsLayoutMapWidget::mOverviewListWidget_currentItemChanged( QListWidgetItem *current, QListWidgetItem *previous )
1440 Q_UNUSED( previous )
1443 mOverviewCheckBox->setEnabled(
false );
1447 mOverviewCheckBox->setEnabled(
true );
1448 setOverviewItems( mMapItem->overviews()->overview( current->data( Qt::UserRole ).toString() ) );
1451 void QgsLayoutMapWidget::mOverviewListWidget_itemChanged( QListWidgetItem *item )
1464 mMapItem->beginCommand( QStringLiteral(
"Rename Overview" ) );
1465 overview->
setName( item->text() );
1466 mMapItem->endCommand();
1467 if ( item->isSelected() )
1470 mOverviewCheckBox->setTitle( tr(
"Draw \"%1\" overview" ).arg( overview->
name() ) );
1474 void QgsLayoutMapWidget::setOverviewItemsEnabled(
bool enabled )
1476 mOverviewFrameMapLabel->setEnabled( enabled );
1477 mOverviewFrameMapComboBox->setEnabled( enabled );
1478 mOverviewFrameStyleLabel->setEnabled( enabled );
1479 mOverviewFrameStyleButton->setEnabled( enabled );
1480 mOverviewBlendModeLabel->setEnabled( enabled );
1481 mOverviewBlendModeComboBox->setEnabled( enabled );
1482 mOverviewInvertCheckbox->setEnabled( enabled );
1483 mOverviewCenterCheckbox->setEnabled( enabled );
1484 mOverviewPositionComboBox->setEnabled( enabled );
1490 void QgsLayoutMapWidget::blockOverviewItemsSignals(
const bool block )
1492 mOverviewFrameMapComboBox->blockSignals( block );
1493 mOverviewFrameStyleButton->blockSignals( block );
1494 mOverviewBlendModeComboBox->blockSignals( block );
1495 mOverviewInvertCheckbox->blockSignals( block );
1496 mOverviewCenterCheckbox->blockSignals( block );
1497 mOverviewPositionComboBox->blockSignals( block );
1498 mOverviewStackingLayerComboBox->blockSignals( block );
1508 blockOverviewItemsSignals(
true );
1510 mOverviewCheckBox->setTitle( tr(
"Draw \"%1\" overview" ).arg( overview->
name() ) );
1511 mOverviewCheckBox->setChecked( overview->
enabled() );
1514 mOverviewFrameMapComboBox->setItem( overview->
linkedMap() );
1517 mOverviewBlendModeComboBox->setBlendMode( overview->
blendMode() );
1519 mOverviewInvertCheckbox->setChecked( overview->
inverted() );
1521 mOverviewCenterCheckbox->setChecked( overview->
centered() );
1523 mOverviewPositionComboBox->setCurrentIndex( mOverviewPositionComboBox->findData( overview->
stackingPosition() ) );
1524 mOverviewStackingLayerComboBox->setLayer( overview->
stackingLayer() );
1530 blockOverviewItemsSignals(
false );
1533 void QgsLayoutMapWidget::storeCurrentLayerSet()
1539 mMapItem->setLayers( layers );
1541 if ( mMapItem->keepLayerStyles() )
1544 mMapItem->storeCurrentLayerStyles();
1548 QList<QgsMapLayer *> QgsLayoutMapWidget::orderedPresetVisibleLayers(
const QString &name )
const
1553 QList<QgsMapLayer *> lst;
1557 if ( visibleIds.contains( layer->
id() ) )
1565 QListWidgetItem *QgsLayoutMapWidget::addOverviewListItem(
const QString &
id,
const QString &name )
1567 QListWidgetItem *item =
new QListWidgetItem( name,
nullptr );
1568 item->setData( Qt::UserRole,
id );
1569 item->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable );
1570 mOverviewListWidget->insertItem( 0, item );
1574 void QgsLayoutMapWidget::loadOverviewEntries()
1577 QSet<QString> selectedIds;
1578 const QList<QListWidgetItem *> itemSelection = mOverviewListWidget->selectedItems();
1579 QList<QListWidgetItem *>::const_iterator sIt = itemSelection.constBegin();
1580 for ( ; sIt != itemSelection.constEnd(); ++sIt )
1582 selectedIds.insert( ( *sIt )->data( Qt::UserRole ).toString() );
1585 mOverviewListWidget->clear();
1591 mOverviewFrameMapComboBox->setExceptedItemList( QList< QgsLayoutItem * >() << mMapItem );
1594 const QList< QgsLayoutItemMapOverview * > overviews = mMapItem->overviews()->asList();
1595 QList< QgsLayoutItemMapOverview * >::const_iterator overviewIt = overviews.constBegin();
1596 for ( ; overviewIt != overviews.constEnd(); ++overviewIt )
1598 QListWidgetItem *item = addOverviewListItem( ( *overviewIt )->id(), ( *overviewIt )->name() );
1599 if ( selectedIds.contains( ( *overviewIt )->id() ) )
1601 item->setSelected(
true );
1602 mOverviewListWidget->setCurrentItem( item );
1606 if ( mOverviewListWidget->currentItem() )
1608 mOverviewListWidget_currentItemChanged( mOverviewListWidget->currentItem(),
nullptr );
1612 mOverviewListWidget_currentItemChanged(
nullptr,
nullptr );
1616 void QgsLayoutMapWidget::mOverviewCheckBox_toggled(
bool state )
1624 mMapItem->layout()->undoStack()->beginCommand( mMapItem, tr(
"Overview Display Toggled" ) );
1626 mMapItem->invalidateCache();
1627 mMapItem->layout()->undoStack()->endCommand();
1630 void QgsLayoutMapWidget::overviewMapChanged(
QgsLayoutItem *item )
1642 mMapItem->beginCommand( tr(
"Change Overview Map" ) );
1644 mMapItem->invalidateCache();
1645 mMapItem->endCommand();
1648 void QgsLayoutMapWidget::mOverviewBlendModeComboBox_currentIndexChanged(
int index )
1657 mMapItem->beginCommand( tr(
"Change Overview Blend Mode" ) );
1658 overview->
setBlendMode( mOverviewBlendModeComboBox->blendMode() );
1659 mMapItem->invalidateCache();
1660 mMapItem->endCommand();
1663 void QgsLayoutMapWidget::mOverviewInvertCheckbox_toggled(
bool state )
1671 mMapItem->beginCommand( tr(
"Toggle Overview Inverted" ) );
1673 mMapItem->invalidateCache();
1674 mMapItem->endCommand();
1677 void QgsLayoutMapWidget::mOverviewCenterCheckbox_toggled(
bool state )
1685 mMapItem->beginCommand( tr(
"Toggle Overview Centered" ) );
1687 mMapItem->invalidateCache();
1688 mMapItem->endCommand();
1691 void QgsLayoutMapWidget::overviewStackingChanged(
int )
1699 mMapItem->beginCommand( tr(
"Change Overview Position" ) );
1701 mMapItem->invalidateCache();
1702 mMapItem->endCommand();
1709 mOverviewStackingLayerComboBox->setEnabled(
false );
1714 mOverviewStackingLayerComboBox->setEnabled(
true );
1719 void QgsLayoutMapWidget::overviewStackingLayerChanged(
QgsMapLayer *layer )
1727 mMapItem->beginCommand( tr(
"Change Overview Position" ) );
1729 mMapItem->invalidateCache();
1730 mMapItem->endCommand();
1744 mLabelBoundarySpinBox->setClearValue( 0 );
1745 mLabelBoundarySpinBox->setShowClearButton(
true );
1747 mLabelBoundaryUnitsCombo->linkToWidget( mLabelBoundarySpinBox );
1748 mLabelBoundaryUnitsCombo->setConverter( &mMapItem->layout()->renderContext().measurementConverter() );
1751 connect( mLabelBoundarySpinBox,
static_cast < void ( QDoubleSpinBox::* )(
double )
> ( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutMapLabelingWidget::labelMarginChanged );
1752 connect( mShowPartialLabelsCheckBox, &QCheckBox::toggled,
this, &QgsLayoutMapLabelingWidget::showPartialsToggled );
1753 connect( mShowUnplacedCheckBox, &QCheckBox::toggled,
this, &QgsLayoutMapLabelingWidget::showUnplacedToggled );
1770 mMapItem = qobject_cast< QgsLayoutItemMap * >( item );
1777 updateGuiElements();
1782 void QgsLayoutMapLabelingWidget::updateGuiElements()
1784 whileBlocking( mLabelBoundarySpinBox )->setValue( mMapItem->labelMargin().length() );
1785 whileBlocking( mLabelBoundaryUnitsCombo )->setUnit( mMapItem->labelMargin().units() );
1789 if ( mBlockingItemsListView->model() )
1791 QAbstractItemModel *oldModel = mBlockingItemsListView->model();
1792 mBlockingItemsListView->setModel(
nullptr );
1793 oldModel->deleteLater();
1797 mBlockingItemsListView->setModel( model );
1802 void QgsLayoutMapLabelingWidget::labelMarginChanged(
double val )
1809 mMapItem->layout()->undoStack()->endCommand();
1810 mMapItem->invalidateCache();
1813 void QgsLayoutMapLabelingWidget::labelMarginUnitsChanged()
1819 mMapItem->setLabelMargin(
QgsLayoutMeasurement( mLabelBoundarySpinBox->value(), mLabelBoundaryUnitsCombo->unit() ) );
1820 mMapItem->layout()->undoStack()->endCommand();
1821 mMapItem->invalidateCache();
1824 void QgsLayoutMapLabelingWidget::showPartialsToggled(
bool checked )
1829 mMapItem->layout()->undoStack()->beginCommand( mMapItem, tr(
"Change Label Visibility" ) );
1830 QgsLayoutItemMap::MapItemFlags flags = mMapItem->mapFlags();
1835 mMapItem->setMapFlags( flags );
1836 mMapItem->layout()->undoStack()->endCommand();
1837 mMapItem->invalidateCache();
1840 void QgsLayoutMapLabelingWidget::showUnplacedToggled(
bool checked )
1845 mMapItem->layout()->undoStack()->beginCommand( mMapItem, tr(
"Change Label Visibility" ) );
1846 QgsLayoutItemMap::MapItemFlags flags = mMapItem->mapFlags();
1851 mMapItem->setMapFlags( flags );
1852 mMapItem->layout()->undoStack()->endCommand();
1853 mMapItem->invalidateCache();
1857 : QSortFilterProxyModel( parent )
1858 , mLayoutModel( layoutModel )
1861 setSourceModel( layoutModel );
1874 if ( i.column() != 0 )
1887 case Qt::CheckStateRole:
1888 switch ( i.column() )
1891 return mMapItem ? ( mMapItem->isLabelBlockingItem( item ) ? Qt::Checked : Qt::Unchecked ) : Qt::Unchecked;
1897 return mLayoutModel->
data( sourceIndex, role );
1905 if ( !index.isValid() )
1909 if ( !item || !mMapItem )
1914 mMapItem->layout()->undoStack()->beginCommand( mMapItem, tr(
"Change Label Blocking Items" ) );
1916 if ( value.toBool() )
1918 mMapItem->addLabelBlockingItem( item );
1922 mMapItem->removeLabelBlockingItem( item );
1924 emit dataChanged( index, index, QVector<int>() << role );
1926 mMapItem->layout()->undoStack()->endCommand();
1927 mMapItem->invalidateCache();
1934 Qt::ItemFlags
flags = QAbstractItemModel::flags( index );
1936 if ( ! index.isValid() )
1941 switch ( index.column() )
1944 return flags | Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsUserCheckable;
1946 return flags | Qt::ItemIsEnabled | Qt::ItemIsSelectable;
1953 if ( !item || item == mMapItem )
1976 mLayersTreeView->setModel( mLayerModel );
1982 for (
int i = 0; i < mAtlasClippingTypeComboBox->count(); ++i )
1984 mItemClippingTypeComboBox->addItem( mAtlasClippingTypeComboBox->itemText( i ), mAtlasClippingTypeComboBox->itemData( i ) );
1987 mClipItemComboBox->setCurrentLayout( map->
layout() );
1990 connect( mRadioClipSelectedLayers, &QRadioButton::toggled, mLayersTreeView, &QWidget::setEnabled );
1991 mLayersTreeView->setEnabled(
false );
1992 mRadioClipAllLayers->setChecked(
true );
1994 connect( mClipToAtlasCheckBox, &QGroupBox::toggled,
this, [ = ](
bool active )
1996 if ( !mBlockUpdates )
1998 mMapItem->beginCommand( tr(
"Toggle Atlas Clipping" ) );
1999 mMapItem->atlasClippingSettings()->setEnabled( active );
2000 mMapItem->endCommand();
2003 connect( mForceLabelsInsideCheckBox, &QCheckBox::toggled,
this, [ = ](
bool active )
2005 if ( !mBlockUpdates )
2007 mMapItem->beginCommand( tr(
"Change Atlas Clipping Label Behavior" ) );
2008 mMapItem->atlasClippingSettings()->setForceLabelsInsideFeature( active );
2009 mMapItem->endCommand();
2012 connect( mAtlasClippingTypeComboBox, qOverload<int>( &QComboBox::currentIndexChanged ),
this, [ = ]
2014 if ( !mBlockUpdates )
2016 mMapItem->beginCommand( tr(
"Change Atlas Clipping Behavior" ) );
2018 mMapItem->endCommand();
2022 connect( mRadioClipSelectedLayers, &QCheckBox::toggled,
this, [ = ](
bool active )
2024 if ( active && !mBlockUpdates )
2026 mBlockUpdates =
true;
2027 mMapItem->beginCommand( tr(
"Change Atlas Clipping Layers" ) );
2028 mMapItem->atlasClippingSettings()->setRestrictToLayers(
true );
2029 mMapItem->endCommand();
2030 mBlockUpdates =
false;
2033 connect( mRadioClipAllLayers, &QCheckBox::toggled,
this, [ = ](
bool active )
2035 if ( active && !mBlockUpdates )
2037 mBlockUpdates =
true;
2038 mMapItem->beginCommand( tr(
"Change Atlas Clipping Layers" ) );
2039 mMapItem->atlasClippingSettings()->setRestrictToLayers(
false );
2040 mMapItem->endCommand();
2041 mBlockUpdates =
false;
2044 connect( mLayerModel, &QgsMapLayerModel::dataChanged,
this, [ = ](
const QModelIndex &,
const QModelIndex &,
const QVector<int> &roles = QVector<int>() )
2046 if ( !roles.contains( Qt::CheckStateRole ) )
2049 if ( !mBlockUpdates )
2051 mBlockUpdates =
true;
2052 mMapItem->beginCommand( tr(
"Change Atlas Clipping Layers" ) );
2053 mMapItem->atlasClippingSettings()->setLayersToClip( mLayerModel->
layersChecked() );
2054 mMapItem->endCommand();
2055 mBlockUpdates =
false;
2061 connect( mClipToItemCheckBox, &QGroupBox::toggled,
this, [ = ](
bool active )
2063 if ( !mBlockUpdates )
2065 mMapItem->beginCommand( tr(
"Toggle Map Clipping" ) );
2066 mMapItem->itemClippingSettings()->setEnabled( active );
2067 mMapItem->endCommand();
2070 connect( mItemClippingTypeComboBox, qOverload<int>( &QComboBox::currentIndexChanged ),
this, [ = ]
2072 if ( !mBlockUpdates )
2074 mMapItem->beginCommand( tr(
"Change Map Clipping Behavior" ) );
2076 mMapItem->endCommand();
2079 connect( mForceLabelsInsideItemCheckBox, &QCheckBox::toggled,
this, [ = ](
bool active )
2081 if ( !mBlockUpdates )
2083 mMapItem->beginCommand( tr(
"Change Map Clipping Label Behavior" ) );
2084 mMapItem->itemClippingSettings()->setForceLabelsInsideClipPath( active );
2085 mMapItem->endCommand();
2090 if ( !mBlockUpdates )
2092 mMapItem->beginCommand( tr(
"Change Map Clipping Item" ) );
2093 mMapItem->itemClippingSettings()->setSourceItem( item );
2094 mMapItem->endCommand();
2101 this, &QgsLayoutMapClippingWidget::atlasLayerChanged );
2105 atlasToggled( atlas->enabled() );
2111 mClipToAtlasCheckBox->setTitle( tr(
"Clip to %1 feature" ).arg(
string ) );
2112 mClipToAtlasLabel->setText( tr(
"<b>When enabled, map layers will be automatically clipped to the boundary of the current %1 feature.</b>" ).arg(
string ) );
2113 mForceLabelsInsideCheckBox->setText( tr(
"Force labels inside %1 feature" ).arg(
string ) );
2126 mMapItem = qobject_cast< QgsLayoutItemMap * >( item );
2133 updateGuiElements();
2138 void QgsLayoutMapClippingWidget::updateGuiElements()
2140 if ( mBlockUpdates )
2143 mBlockUpdates =
true;
2144 mClipToAtlasCheckBox->setChecked( mMapItem->atlasClippingSettings()->enabled() );
2145 mAtlasClippingTypeComboBox->setCurrentIndex( mAtlasClippingTypeComboBox->findData(
static_cast< int >( mMapItem->atlasClippingSettings()->featureClippingType() ) ) );
2146 mForceLabelsInsideCheckBox->setChecked( mMapItem->atlasClippingSettings()->forceLabelsInsideFeature() );
2148 mRadioClipAllLayers->setChecked( !mMapItem->atlasClippingSettings()->restrictToLayers() );
2149 mRadioClipSelectedLayers->setChecked( mMapItem->atlasClippingSettings()->restrictToLayers() );
2150 mLayerModel->
setLayersChecked( mMapItem->atlasClippingSettings()->layersToClip() );
2152 mClipToItemCheckBox->setChecked( mMapItem->itemClippingSettings()->enabled() );
2153 mItemClippingTypeComboBox->setCurrentIndex( mItemClippingTypeComboBox->findData(
static_cast< int >( mMapItem->itemClippingSettings()->featureClippingType() ) ) );
2154 mForceLabelsInsideItemCheckBox->setChecked( mMapItem->itemClippingSettings()->forceLabelsInsideClipPath() );
2155 mClipItemComboBox->setItem( mMapItem->itemClippingSettings()->sourceItem() );
2157 mBlockUpdates =
false;
2160 void QgsLayoutMapClippingWidget::atlasLayerChanged(
QgsVectorLayer *layer )
2165 mClipToAtlasCheckBox->setChecked(
false );
2166 mClipToAtlasCheckBox->setEnabled(
false );
2171 mClipToAtlasCheckBox->setEnabled(
true );
2175 void QgsLayoutMapClippingWidget::atlasToggled(
bool atlasEnabled )
2177 if ( atlasEnabled &&
2178 mMapItem && mMapItem->layout() && mMapItem->layout()->reportContext().layer()
2181 mClipToAtlasCheckBox->setEnabled(
true );
2185 mClipToAtlasCheckBox->setEnabled(
false );
2186 mClipToAtlasCheckBox->setChecked(
false );