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" ) );
144 mFollowVisibilityPresetCombo->setModel(
new QStringListModel( mFollowVisibilityPresetCombo ) );
145 connect( mFollowVisibilityPresetCombo,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsLayoutMapWidget::followVisibilityPresetSelected );
147 this, &QgsLayoutMapWidget::onMapThemesChanged );
148 onMapThemesChanged();
151 QMenu *menuKeepLayers =
new QMenu(
this );
152 mLayerListFromPresetButton->setMenu( menuKeepLayers );
154 mLayerListFromPresetButton->setToolTip( tr(
"Set layer list from a map theme" ) );
155 connect( menuKeepLayers, &QMenu::aboutToShow,
this, &QgsLayoutMapWidget::aboutToShowKeepLayersVisibilityPresetsMenu );
160 this, &QgsLayoutMapWidget::atlasLayerChanged );
164 compositionAtlasToggled( atlas->enabled() );
167 mOverviewFrameMapComboBox->setCurrentLayout( item->
layout() );
169 mOverviewFrameStyleButton->registerExpressionContextGenerator( item );
175 mOverviewFrameStyleButton->registerExpressionContextGenerator( item );
198 loadOverviewEntries();
200 connect( mMapRotationSpinBox,
static_cast < void (
QgsDoubleSpinBox::* )(
double )
> ( &QgsDoubleSpinBox::valueChanged ),
this, &QgsLayoutMapWidget::rotationChanged );
204 blockAllSignals(
false );
209 if ( mItemPropertiesWidget )
215 mReportTypeString = string;
216 mAtlasCheckBox->setTitle( tr(
"Controlled by %1" ).arg(
string == tr(
"atlas" ) ? tr(
"Atlas" ) : tr(
"Report" ) ) );
217 mAtlasPredefinedScaleRadio->setToolTip( tr(
"Use one of the predefined scales of the project where the %1 feature best fits." ).arg(
string ) );
220 mClipWidget->setReportTypeString(
string );
222 mLabelWidget->setReportTypeString(
string );
243 mMapItem = qobject_cast< QgsLayoutItemMap * >( item );
244 mItemPropertiesWidget->
setItem( mMapItem );
246 mLabelWidget->setItem( mMapItem );
248 mClipWidget->setItem( mMapItem );
255 mOverviewFrameStyleButton->registerExpressionContextGenerator( mMapItem );
279 void QgsLayoutMapWidget::compositionAtlasToggled(
bool atlasEnabled )
282 mMapItem && mMapItem->layout() && mMapItem->layout()->reportContext().layer()
285 mAtlasCheckBox->setEnabled(
true );
289 mAtlasCheckBox->setEnabled(
false );
290 mAtlasCheckBox->setChecked(
false );
294 void QgsLayoutMapWidget::aboutToShowKeepLayersVisibilityPresetsMenu()
299 QMenu *menu = qobject_cast<QMenu *>( sender() );
305 for (
const QString &presetName : constMapThemes )
307 menu->addAction( presetName,
this, &QgsLayoutMapWidget::keepLayersVisibilityPresetSelected );
310 if ( menu->actions().isEmpty() )
311 menu->addAction( tr(
"No presets defined" ) )->setEnabled(
false );
314 void QgsLayoutMapWidget::followVisibilityPresetSelected(
int currentIndex )
319 if ( mBlockThemeComboChanges != 0 )
322 if ( currentIndex == -1 )
326 if ( currentIndex != 0 )
328 presetName = mFollowVisibilityPresetCombo->currentText();
331 if ( presetName == mMapItem->followVisibilityPresetName() )
334 mMapItem->layout()->undoStack()->beginCommand( mMapItem, tr(
"Change Map Preset" ) );
335 mFollowVisibilityPresetCheckBox->setChecked(
true );
336 mMapItem->setFollowVisibilityPresetName( presetName );
337 mMapItem->layout()->undoStack()->endCommand();
339 mMapItem->invalidateCache();
342 void QgsLayoutMapWidget::keepLayersVisibilityPresetSelected()
344 QAction *action = qobject_cast<QAction *>( sender() );
348 const QString presetName = action->text();
349 const QList<QgsMapLayer *> lst = orderedPresetVisibleLayers( presetName );
352 mKeepLayerListCheckBox->setChecked(
true );
353 mMapItem->setLayers( lst );
355 mKeepLayerStylesCheckBox->setChecked(
true );
357 mMapItem->layout()->undoStack()->beginCommand( mMapItem, tr(
"Change Map Preset" ) );
358 mMapItem->setLayerStyleOverrides(
QgsProject::instance()->mapThemeCollection()->mapThemeStyleOverrides( presetName ) );
359 mMapItem->layout()->undoStack()->endCommand();
361 mMapItem->invalidateCache();
365 void QgsLayoutMapWidget::onMapThemesChanged()
367 if ( QStringListModel *model = qobject_cast<QStringListModel *>( mFollowVisibilityPresetCombo->model() ) )
369 mBlockThemeComboChanges++;
371 lst.append( tr(
"(none)" ) );
373 model->setStringList( lst );
376 const int presetModelIndex = mFollowVisibilityPresetCombo->findText( mMapItem->followVisibilityPresetName() );
377 mFollowVisibilityPresetCombo->blockSignals(
true );
378 mFollowVisibilityPresetCombo->setCurrentIndex( presetModelIndex != -1 ? presetModelIndex : 0 );
379 mFollowVisibilityPresetCombo->blockSignals(
false );
380 mBlockThemeComboChanges--;
391 if ( mMapItem->presetCrs() ==
crs )
397 bool updateExtent =
false;
402 xForm.setBallparkTransformsAreAppropriate(
true );
404 newExtent = xForm.transformBoundingBox( prevExtent );
412 mMapItem->layout()->undoStack()->beginCommand( mMapItem, tr(
"Change Map CRS" ) );
413 mMapItem->setCrs(
crs );
415 mMapItem->zoomToExtent( newExtent );
416 mMapItem->layout()->undoStack()->endCommand();
417 mMapItem->invalidateCache();
420 void QgsLayoutMapWidget::overviewSymbolChanged()
428 mMapItem->endCommand();
429 mMapItem->invalidateCache();
432 void QgsLayoutMapWidget::showLabelSettings()
436 if ( !mReportTypeString.isEmpty() )
437 mLabelWidget->setReportTypeString( mReportTypeString );
442 void QgsLayoutMapWidget::showClipSettings()
445 if ( !mReportTypeString.isEmpty() )
446 mClipWidget->setReportTypeString( mReportTypeString );
450 void QgsLayoutMapWidget::switchToMoveContentTool()
456 void QgsLayoutMapWidget::aboutToShowBookmarkMenu()
458 mBookmarkMenu->clear();
462 if ( !mBookmarkModel )
465 QMap< QString, QMenu * > groupMenus;
466 for (
int i = 0; i < mBookmarkModel->rowCount(); ++i )
469 QMenu *destMenu = mBookmarkMenu;
470 if ( !group.isEmpty() )
472 destMenu = groupMenus.value( group );
475 destMenu =
new QMenu( group, mBookmarkMenu );
476 groupMenus[ group ] = destMenu;
481 connect( action, &QAction::triggered,
this, [ = ]
491 if ( extent.
crs() != mMapItem->crs() )
495 QgsCoordinateTransform xForm( extent.crs(), mMapItem->crs(), QgsProject::instance() );
496 xForm.setBallparkTransformsAreAppropriate( true );
497 newExtent = xForm.transformBoundingBox( newExtent );
506 mMapItem->layout()->undoStack()->beginCommand( mMapItem, tr(
"Change Map Extent" ) );
507 mMapItem->zoomToExtent( newExtent );
508 mMapItem->layout()->undoStack()->endCommand();
510 destMenu->addAction( action );
513 QStringList groupKeys = groupMenus.keys();
514 groupKeys.sort( Qt::CaseInsensitive );
515 for (
int i = 0; i < groupKeys.count(); ++i )
517 if ( mBookmarkMenu->actions().value( i ) )
518 mBookmarkMenu->insertMenu( mBookmarkMenu->actions().at( i ), groupMenus.value( groupKeys.at( i ) ) );
520 mBookmarkMenu->addMenu( groupMenus.value( groupKeys.at( i ) ) );
524 void QgsLayoutMapWidget::mTemporalCheckBox_toggled(
bool checked )
531 mMapItem->layout()->undoStack()->beginCommand( mMapItem, tr(
"Toggle Temporal Range" ) );
532 mMapItem->setIsTemporal( checked );
533 mMapItem->layout()->undoStack()->endCommand();
537 whileBlocking( mStartDateTime )->setDateTime( mMapItem->temporalRange().begin() );
538 whileBlocking( mEndDateTime )->setDateTime( mMapItem->temporalRange().end() );
544 void QgsLayoutMapWidget::updateTemporalExtent()
551 const QDateTime begin = mStartDateTime->dateTime();
552 const QDateTime end = mEndDateTime->dateTime();
553 const QgsDateTimeRange range = QgsDateTimeRange( begin, end,
true, begin == end );
555 mMapItem->layout()->undoStack()->beginCommand( mMapItem, tr(
"Set Temporal Range" ) );
556 mMapItem->setTemporalRange( range );
557 mMapItem->layout()->undoStack()->endCommand();
562 void QgsLayoutMapWidget::mAtlasCheckBox_toggled(
bool checked )
569 mAtlasFixedScaleRadio->setEnabled( checked );
570 mAtlasMarginRadio->setEnabled( checked );
572 if ( mAtlasMarginRadio->isEnabled() && mAtlasMarginRadio->isChecked() )
574 mAtlasMarginSpinBox->setEnabled(
true );
578 mAtlasMarginSpinBox->setEnabled(
false );
581 mAtlasPredefinedScaleRadio->setEnabled( checked );
586 if ( mMapItem->layout() )
588 toggleAtlasScalingOptionsByLayerType();
593 if ( !hasPredefinedScales() )
595 mAtlasPredefinedScaleRadio->setEnabled(
false );
598 mMapItem->layout()->undoStack()->beginCommand( mMapItem, tr(
"Set Atlas Driven" ) );
599 mMapItem->setAtlasDriven( checked );
600 mMapItem->layout()->undoStack()->endCommand();
604 void QgsLayoutMapWidget::updateMapForAtlas()
607 if ( mMapItem->atlasDriven() )
614 mMapItem->invalidateCache();
618 void QgsLayoutMapWidget::mAtlasMarginRadio_toggled(
bool checked )
620 mAtlasMarginSpinBox->setEnabled( checked );
622 if ( checked && mMapItem )
624 mMapItem->layout()->undoStack()->beginCommand( mMapItem, tr(
"Change Atlas Mode" ) );
626 mMapItem->layout()->undoStack()->endCommand();
631 void QgsLayoutMapWidget::mAtlasMarginSpinBox_valueChanged(
int value )
639 mMapItem->setAtlasMargin( value / 100. );
640 mMapItem->layout()->undoStack()->endCommand();
644 void QgsLayoutMapWidget::mAtlasFixedScaleRadio_toggled(
bool checked )
653 mMapItem->layout()->undoStack()->beginCommand( mMapItem, tr(
"Change Atlas Mode" ) );
655 mMapItem->layout()->undoStack()->endCommand();
660 void QgsLayoutMapWidget::mAtlasPredefinedScaleRadio_toggled(
bool checked )
667 if ( hasPredefinedScales() )
671 mMapItem->layout()->undoStack()->beginCommand( mMapItem, tr(
"Change Atlas Scales" ) );
673 mMapItem->layout()->undoStack()->endCommand();
681 mMapItem->layout()->undoStack()->beginCommand( mMapItem, tr(
"Change Atlas Mode" ) );
683 mMapItem->layout()->undoStack()->endCommand();
687 void QgsLayoutMapWidget::mScaleLineEdit_editingFinished()
694 bool conversionSuccess =
false;
695 const double scaleDenominator = QLocale().toDouble( mScaleLineEdit->text(), &conversionSuccess );
696 if ( !conversionSuccess )
704 mMapItem->layout()->undoStack()->beginCommand( mMapItem, tr(
"Change Map Scale" ) );
705 mMapItem->setScale( scaleDenominator );
706 mMapItem->layout()->undoStack()->endCommand();
709 void QgsLayoutMapWidget::rotationChanged(
double value )
717 mMapItem->setMapRotation( value );
718 mMapItem->layout()->undoStack()->endCommand();
719 mMapItem->invalidateCache();
722 void QgsLayoutMapWidget::setToMapCanvasExtent()
739 xForm.setBallparkTransformsAreAppropriate(
true );
740 newExtent = xForm.transformBoundingBox( newExtent );
749 mMapItem->layout()->undoStack()->beginCommand( mMapItem, tr(
"Change Map Extent" ) );
750 mMapItem->zoomToExtent( newExtent );
751 mMapItem->layout()->undoStack()->endCommand();
754 void QgsLayoutMapWidget::setToMapCanvasScale()
761 const double newScale = mMapCanvas->
scale();
763 mMapItem->layout()->undoStack()->beginCommand( mMapItem, tr(
"Change Map Scale" ) );
764 mMapItem->setScale( newScale );
765 mMapItem->layout()->undoStack()->endCommand();
768 void QgsLayoutMapWidget::viewExtentInCanvas()
775 const QgsRectangle currentMapExtent = mMapItem->extent();
777 if ( !currentMapExtent.
isEmpty() )
792 void QgsLayoutMapWidget::viewScaleInCanvas()
799 const double currentScale = mMapItem->scale();
800 mMapCanvas->
zoomScale( currentScale,
true );
803 void QgsLayoutMapWidget::mXMinLineEdit_editingFinished()
805 updateComposerExtentFromGui();
808 void QgsLayoutMapWidget::mXMaxLineEdit_editingFinished()
810 updateComposerExtentFromGui();
813 void QgsLayoutMapWidget::mYMinLineEdit_editingFinished()
815 updateComposerExtentFromGui();
818 void QgsLayoutMapWidget::mYMaxLineEdit_editingFinished()
820 updateComposerExtentFromGui();
823 void QgsLayoutMapWidget::updateGuiElements()
830 blockAllSignals(
true );
831 mLabel->setText( mMapItem->displayName() );
833 whileBlocking( mCrsSelector )->setCrs( mMapItem->presetCrs() );
836 const double scale = mMapItem->scale();
839 if ( scale >= 10000 )
842 mScaleLineEdit->setText( QLocale().toString( mMapItem->scale(),
'f', 0 ) );
844 else if ( scale >= 10 )
846 mScaleLineEdit->setText( QLocale().toString( mMapItem->scale(),
'f', 3 ) );
848 else if ( scale >= 1 )
851 mScaleLineEdit->setText( QLocale().toString( mMapItem->scale(),
'f', 4 ) );
856 mScaleLineEdit->setText( QLocale().toString( mMapItem->scale(),
'f', 10 ) );
860 const QgsRectangle composerMapExtent = mMapItem->extent();
861 mXMinLineEdit->setText( QLocale().toString( composerMapExtent.
xMinimum(),
'f', 3 ) );
862 mXMaxLineEdit->setText( QLocale().toString( composerMapExtent.
xMaximum(),
'f', 3 ) );
863 mYMinLineEdit->setText( QLocale().toString( composerMapExtent.
yMinimum(),
'f', 3 ) );
864 mYMaxLineEdit->setText( QLocale().toString( composerMapExtent.
yMaximum(),
'f', 3 ) );
869 mFollowVisibilityPresetCheckBox->setCheckState(
870 mMapItem->followVisibilityPreset() ? Qt::Checked : Qt::Unchecked );
871 const int presetModelIndex = mFollowVisibilityPresetCombo->findText( mMapItem->followVisibilityPresetName() );
872 mFollowVisibilityPresetCombo->setCurrentIndex( presetModelIndex != -1 ? presetModelIndex : 0 );
875 if ( mMapItem->keepLayerSet() )
877 mKeepLayerListCheckBox->setCheckState( Qt::Checked );
881 mKeepLayerListCheckBox->setCheckState( Qt::Unchecked );
884 mKeepLayerStylesCheckBox->setEnabled( mMapItem->keepLayerSet() );
885 mKeepLayerStylesCheckBox->setCheckState( mMapItem->keepLayerStyles() ? Qt::Checked : Qt::Unchecked );
888 if ( mMapItem->drawAnnotations() )
890 mDrawCanvasItemsCheckBox->setCheckState( Qt::Checked );
894 mDrawCanvasItemsCheckBox->setCheckState( Qt::Unchecked );
898 mAtlasCheckBox->setChecked( mMapItem->atlasDriven() );
901 mAtlasFixedScaleRadio->setEnabled( mMapItem->atlasDriven() );
904 mAtlasMarginRadio->setEnabled( mMapItem->atlasDriven() );
906 mAtlasPredefinedScaleRadio->setEnabled( mMapItem->atlasDriven() );
909 if ( mMapItem->atlasDriven() )
911 toggleAtlasScalingOptionsByLayerType();
914 if ( !hasPredefinedScales() )
916 mAtlasPredefinedScaleRadio->setEnabled(
false );
919 mTemporalCheckBox->setChecked( mMapItem->isTemporal() );
920 mTemporalCheckBox->setCollapsed( !mMapItem->isTemporal() );
921 mStartDateTime->setEnabled( mMapItem->isTemporal() );
922 mEndDateTime->setEnabled( mMapItem->isTemporal() );
923 if ( mMapItem->isTemporal() )
925 mStartDateTime->setDateTime( mMapItem->temporalRange().begin() );
926 mEndDateTime->setDateTime( mMapItem->temporalRange().end() );
931 loadOverviewEntries();
933 blockAllSignals(
false );
936 void QgsLayoutMapWidget::toggleAtlasScalingOptionsByLayerType()
954 mAtlasFixedScaleRadio->setChecked(
true );
955 mAtlasMarginRadio->setEnabled(
false );
960 mAtlasMarginRadio->setEnabled(
true );
964 void QgsLayoutMapWidget::updateComposerExtentFromGui()
971 double xmin, ymin, xmax, ymax;
972 bool conversionSuccess;
974 xmin = QLocale().toDouble( mXMinLineEdit->text(), &conversionSuccess );
975 if ( !conversionSuccess )
977 xmax = QLocale().toDouble( mXMaxLineEdit->text(), &conversionSuccess );
978 if ( !conversionSuccess )
980 ymin = QLocale().toDouble( mYMinLineEdit->text(), &conversionSuccess );
981 if ( !conversionSuccess )
983 ymax = QLocale().toDouble( mYMaxLineEdit->text(), &conversionSuccess );
984 if ( !conversionSuccess )
989 mMapItem->layout()->undoStack()->beginCommand( mMapItem, tr(
"Change Map Extent" ) );
990 mMapItem->setExtent( newExtent );
991 mMapItem->layout()->undoStack()->endCommand();
994 void QgsLayoutMapWidget::blockAllSignals(
bool b )
996 mScaleLineEdit->blockSignals( b );
997 mXMinLineEdit->blockSignals( b );
998 mXMaxLineEdit->blockSignals( b );
999 mYMinLineEdit->blockSignals( b );
1000 mYMaxLineEdit->blockSignals( b );
1001 mDrawCanvasItemsCheckBox->blockSignals( b );
1002 mOverviewFrameMapComboBox->blockSignals( b );
1003 mOverviewFrameStyleButton->blockSignals( b );
1004 mOverviewBlendModeComboBox->blockSignals( b );
1005 mOverviewInvertCheckbox->blockSignals( b );
1006 mOverviewCenterCheckbox->blockSignals( b );
1007 mAtlasCheckBox->blockSignals( b );
1008 mAtlasMarginSpinBox->blockSignals( b );
1009 mAtlasFixedScaleRadio->blockSignals( b );
1010 mAtlasMarginRadio->blockSignals( b );
1011 mFollowVisibilityPresetCheckBox->blockSignals( b );
1012 mFollowVisibilityPresetCombo->blockSignals( b );
1013 mKeepLayerListCheckBox->blockSignals( b );
1014 mKeepLayerStylesCheckBox->blockSignals( b );
1015 mActionSetToCanvasExtent->blockSignals( b );
1016 mActionUpdatePreview->blockSignals( b );
1017 mTemporalCheckBox->blockSignals( b );
1018 mStartDateTime->blockSignals( b );
1019 mEndDateTime->blockSignals( b );
1021 blockOverviewItemsSignals( b );
1024 void QgsLayoutMapWidget::updatePreview()
1030 mMapItem->refresh();
1033 void QgsLayoutMapWidget::mFollowVisibilityPresetCheckBox_stateChanged(
int state )
1040 mMapItem->layout()->undoStack()->beginCommand( mMapItem, tr(
"Change Map Preset" ) );
1041 if ( state == Qt::Checked )
1043 mMapItem->setFollowVisibilityPreset(
true );
1046 mKeepLayerListCheckBox->setCheckState( Qt::Unchecked );
1047 mKeepLayerStylesCheckBox->setCheckState( Qt::Unchecked );
1049 mMapItem->invalidateCache();
1053 mMapItem->setFollowVisibilityPreset(
false );
1055 mMapItem->layout()->undoStack()->endCommand();
1058 void QgsLayoutMapWidget::mKeepLayerListCheckBox_stateChanged(
int state )
1066 mMapItem->layout()->undoStack()->beginCommand( mMapItem, tr(
"Map Preset Changed" ) );
1067 storeCurrentLayerSet();
1068 mMapItem->setKeepLayerSet( state == Qt::Checked );
1069 if ( state == Qt::Unchecked )
1071 mMapItem->setLayers( QList< QgsMapLayer * >() );
1073 mMapItem->layout()->undoStack()->endCommand();
1076 if ( state == Qt::Checked )
1079 mFollowVisibilityPresetCheckBox->setCheckState( Qt::Unchecked );
1083 mKeepLayerStylesCheckBox->setChecked( Qt::Unchecked );
1084 mMapItem->invalidateCache();
1087 mKeepLayerStylesCheckBox->setEnabled( state == Qt::Checked );
1090 void QgsLayoutMapWidget::mKeepLayerStylesCheckBox_stateChanged(
int state )
1097 mMapItem->layout()->undoStack()->beginCommand( mMapItem, tr(
"Change Map Preset" ) );
1098 if ( state == Qt::Checked )
1100 mMapItem->storeCurrentLayerStyles();
1101 mMapItem->setKeepLayerStyles(
true );
1105 mMapItem->setLayerStyleOverrides( QMap<QString, QString>() );
1106 mMapItem->setKeepLayerStyles(
false );
1108 mMapItem->layout()->undoStack()->endCommand();
1111 void QgsLayoutMapWidget::mDrawCanvasItemsCheckBox_stateChanged(
int state )
1118 mMapItem->layout()->undoStack()->beginCommand( mMapItem, tr(
"Toggle Map Item" ) );
1119 mMapItem->setDrawAnnotations( state == Qt::Checked );
1120 mMapItem->invalidateCache();
1121 mMapItem->layout()->undoStack()->endCommand();
1124 void QgsLayoutMapWidget::atlasLayerChanged(
QgsVectorLayer *layer )
1129 mAtlasCheckBox->setChecked(
false );
1130 mAtlasCheckBox->setEnabled(
false );
1135 mAtlasCheckBox->setEnabled(
true );
1139 if ( mAtlasCheckBox->isChecked() )
1140 toggleAtlasScalingOptionsByLayerType();
1143 bool QgsLayoutMapWidget::hasPredefinedScales()
const
1148 if ( !hasProjectScales || scales.isEmpty() )
1153 QStringList myScalesList = scalesStr.split(
',' );
1154 return !myScalesList.isEmpty() && !myScalesList[0].isEmpty();
1159 void QgsLayoutMapWidget::mAddGridPushButton_clicked()
1166 const QString itemName = tr(
"Grid %1" ).arg( mMapItem->grids()->size() + 1 );
1168 mMapItem->layout()->undoStack()->beginCommand( mMapItem, tr(
"Add Map Grid" ) );
1169 mMapItem->grids()->addGrid( grid );
1170 mMapItem->layout()->undoStack()->endCommand();
1171 mMapItem->updateBoundingRect();
1174 addGridListItem( grid->
id(), grid->
name() );
1175 mGridListWidget->setCurrentRow( 0 );
1176 mGridListWidget_currentItemChanged( mGridListWidget->currentItem(),
nullptr );
1179 void QgsLayoutMapWidget::mRemoveGridPushButton_clicked()
1181 QListWidgetItem *item = mGridListWidget->currentItem();
1187 mMapItem->beginCommand( tr(
"Remove Grid" ) );
1188 mMapItem->grids()->removeGrid( item->data( Qt::UserRole ).toString() );
1189 QListWidgetItem *delItem = mGridListWidget->takeItem( mGridListWidget->row( item ) );
1191 mMapItem->endCommand();
1192 mMapItem->updateBoundingRect();
1196 void QgsLayoutMapWidget::mGridUpButton_clicked()
1198 QListWidgetItem *item = mGridListWidget->currentItem();
1204 const int row = mGridListWidget->row( item );
1209 mGridListWidget->takeItem( row );
1210 mGridListWidget->insertItem( row - 1, item );
1211 mGridListWidget->setCurrentItem( item );
1212 mMapItem->beginCommand( tr(
"Move Grid Up" ) );
1213 mMapItem->grids()->moveGridUp( item->data( Qt::UserRole ).toString() );
1214 mMapItem->endCommand();
1218 void QgsLayoutMapWidget::mGridDownButton_clicked()
1220 QListWidgetItem *item = mGridListWidget->currentItem();
1226 const int row = mGridListWidget->row( item );
1227 if ( mGridListWidget->count() <= row )
1231 mGridListWidget->takeItem( row );
1232 mGridListWidget->insertItem( row + 1, item );
1233 mGridListWidget->setCurrentItem( item );
1234 mMapItem->beginCommand( tr(
"Move Grid Down" ) );
1235 mMapItem->grids()->moveGridDown( item->data( Qt::UserRole ).toString() );
1236 mMapItem->endCommand();
1247 QListWidgetItem *item = mGridListWidget->currentItem();
1252 return mMapItem->grids()->grid( item->data( Qt::UserRole ).toString() );
1255 void QgsLayoutMapWidget::mGridListWidget_currentItemChanged( QListWidgetItem *current, QListWidgetItem * )
1257 mGridPropertiesButton->setEnabled(
static_cast< bool >( current ) );
1260 void QgsLayoutMapWidget::mGridListWidget_itemChanged( QListWidgetItem *item )
1273 mMapItem->beginCommand( tr(
"Rename Grid" ) );
1274 grid->
setName( item->text() );
1275 mMapItem->endCommand();
1278 void QgsLayoutMapWidget::mGridPropertiesButton_clicked()
1295 QListWidgetItem *QgsLayoutMapWidget::addGridListItem(
const QString &
id,
const QString &name )
1297 QListWidgetItem *item =
new QListWidgetItem( name,
nullptr );
1298 item->setData( Qt::UserRole,
id );
1299 item->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable );
1300 mGridListWidget->insertItem( 0, item );
1304 void QgsLayoutMapWidget::loadGridEntries()
1307 QSet<QString> selectedIds;
1308 const QList<QListWidgetItem *> itemSelection = mGridListWidget->selectedItems();
1309 QList<QListWidgetItem *>::const_iterator sIt = itemSelection.constBegin();
1310 for ( ; sIt != itemSelection.constEnd(); ++sIt )
1312 selectedIds.insert( ( *sIt )->data( Qt::UserRole ).toString() );
1315 mGridListWidget->clear();
1321 const QList< QgsLayoutItemMapGrid * > grids = mMapItem->grids()->asList();
1322 QList< QgsLayoutItemMapGrid * >::const_iterator gridIt = grids.constBegin();
1323 for ( ; gridIt != grids.constEnd(); ++gridIt )
1325 QListWidgetItem *item = addGridListItem( ( *gridIt )->id(), ( *gridIt )->name() );
1326 if ( selectedIds.contains( ( *gridIt )->id() ) )
1328 item->setSelected(
true );
1329 mGridListWidget->setCurrentItem( item );
1333 if ( mGridListWidget->currentItem() )
1335 mGridListWidget_currentItemChanged( mGridListWidget->currentItem(),
nullptr );
1339 mGridListWidget_currentItemChanged(
nullptr,
nullptr );
1343 void QgsLayoutMapWidget::mAddOverviewPushButton_clicked()
1350 const QString itemName = tr(
"Overview %1" ).arg( mMapItem->overviews()->size() + 1 );
1352 mMapItem->layout()->undoStack()->beginCommand( mMapItem, tr(
"Add Map Overview" ) );
1353 mMapItem->overviews()->addOverview( overview );
1354 mMapItem->layout()->undoStack()->endCommand();
1355 mMapItem->invalidateCache();
1357 addOverviewListItem( overview->
id(), overview->
name() );
1359 mOverviewListWidget->setCurrentRow( 0 );
1362 void QgsLayoutMapWidget::mRemoveOverviewPushButton_clicked()
1364 QListWidgetItem *item = mOverviewListWidget->currentItem();
1369 mMapItem->beginCommand( tr(
"Remove Map Overview" ) );
1370 mMapItem->overviews()->removeOverview( item->data( Qt::UserRole ).toString() );
1371 mMapItem->endCommand();
1372 QListWidgetItem *delItem = mOverviewListWidget->takeItem( mOverviewListWidget->row( item ) );
1374 mMapItem->invalidateCache();
1377 void QgsLayoutMapWidget::mOverviewUpButton_clicked()
1379 QListWidgetItem *item = mOverviewListWidget->currentItem();
1385 const int row = mOverviewListWidget->row( item );
1390 mOverviewListWidget->takeItem( row );
1391 mOverviewListWidget->insertItem( row - 1, item );
1392 mOverviewListWidget->setCurrentItem( item );
1393 mMapItem->beginCommand( tr(
"Move Overview Up" ) );
1394 mMapItem->overviews()->moveOverviewUp( item->data( Qt::UserRole ).toString() );
1395 mMapItem->endCommand();
1396 mMapItem->invalidateCache();
1399 void QgsLayoutMapWidget::mOverviewDownButton_clicked()
1401 QListWidgetItem *item = mOverviewListWidget->currentItem();
1407 const int row = mOverviewListWidget->row( item );
1408 if ( mOverviewListWidget->count() <= row )
1412 mOverviewListWidget->takeItem( row );
1413 mOverviewListWidget->insertItem( row + 1, item );
1414 mOverviewListWidget->setCurrentItem( item );
1415 mMapItem->beginCommand( tr(
"Move Overview Down" ) );
1416 mMapItem->overviews()->moveOverviewDown( item->data( Qt::UserRole ).toString() );
1417 mMapItem->endCommand();
1418 mMapItem->invalidateCache();
1428 QListWidgetItem *item = mOverviewListWidget->currentItem();
1434 return mMapItem->overviews()->overview( item->data( Qt::UserRole ).toString() );
1437 void QgsLayoutMapWidget::mOverviewListWidget_currentItemChanged( QListWidgetItem *current, QListWidgetItem *previous )
1439 Q_UNUSED( previous )
1442 mOverviewCheckBox->setEnabled(
false );
1446 mOverviewCheckBox->setEnabled(
true );
1447 setOverviewItems( mMapItem->overviews()->overview( current->data( Qt::UserRole ).toString() ) );
1450 void QgsLayoutMapWidget::mOverviewListWidget_itemChanged( QListWidgetItem *item )
1463 mMapItem->beginCommand( QStringLiteral(
"Rename Overview" ) );
1464 overview->
setName( item->text() );
1465 mMapItem->endCommand();
1466 if ( item->isSelected() )
1469 mOverviewCheckBox->setTitle( tr(
"Draw \"%1\" overview" ).arg( overview->
name() ) );
1473 void QgsLayoutMapWidget::setOverviewItemsEnabled(
bool enabled )
1475 mOverviewFrameMapLabel->setEnabled( enabled );
1476 mOverviewFrameMapComboBox->setEnabled( enabled );
1477 mOverviewFrameStyleLabel->setEnabled( enabled );
1478 mOverviewFrameStyleButton->setEnabled( enabled );
1479 mOverviewBlendModeLabel->setEnabled( enabled );
1480 mOverviewBlendModeComboBox->setEnabled( enabled );
1481 mOverviewInvertCheckbox->setEnabled( enabled );
1482 mOverviewCenterCheckbox->setEnabled( enabled );
1483 mOverviewPositionComboBox->setEnabled( enabled );
1489 void QgsLayoutMapWidget::blockOverviewItemsSignals(
const bool block )
1491 mOverviewFrameMapComboBox->blockSignals( block );
1492 mOverviewFrameStyleButton->blockSignals( block );
1493 mOverviewBlendModeComboBox->blockSignals( block );
1494 mOverviewInvertCheckbox->blockSignals( block );
1495 mOverviewCenterCheckbox->blockSignals( block );
1496 mOverviewPositionComboBox->blockSignals( block );
1497 mOverviewStackingLayerComboBox->blockSignals( block );
1507 blockOverviewItemsSignals(
true );
1509 mOverviewCheckBox->setTitle( tr(
"Draw \"%1\" overview" ).arg( overview->
name() ) );
1510 mOverviewCheckBox->setChecked( overview->
enabled() );
1513 mOverviewFrameMapComboBox->setItem( overview->
linkedMap() );
1516 mOverviewBlendModeComboBox->setBlendMode( overview->
blendMode() );
1518 mOverviewInvertCheckbox->setChecked( overview->
inverted() );
1520 mOverviewCenterCheckbox->setChecked( overview->
centered() );
1522 mOverviewPositionComboBox->setCurrentIndex( mOverviewPositionComboBox->findData( overview->
stackingPosition() ) );
1523 mOverviewStackingLayerComboBox->setLayer( overview->
stackingLayer() );
1529 blockOverviewItemsSignals(
false );
1532 void QgsLayoutMapWidget::storeCurrentLayerSet()
1538 mMapItem->setLayers( layers );
1540 if ( mMapItem->keepLayerStyles() )
1543 mMapItem->storeCurrentLayerStyles();
1547 QList<QgsMapLayer *> QgsLayoutMapWidget::orderedPresetVisibleLayers(
const QString &name )
const
1552 QList<QgsMapLayer *> lst;
1556 if ( visibleIds.contains( layer->
id() ) )
1564 QListWidgetItem *QgsLayoutMapWidget::addOverviewListItem(
const QString &
id,
const QString &name )
1566 QListWidgetItem *item =
new QListWidgetItem( name,
nullptr );
1567 item->setData( Qt::UserRole,
id );
1568 item->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable );
1569 mOverviewListWidget->insertItem( 0, item );
1573 void QgsLayoutMapWidget::loadOverviewEntries()
1576 QSet<QString> selectedIds;
1577 const QList<QListWidgetItem *> itemSelection = mOverviewListWidget->selectedItems();
1578 QList<QListWidgetItem *>::const_iterator sIt = itemSelection.constBegin();
1579 for ( ; sIt != itemSelection.constEnd(); ++sIt )
1581 selectedIds.insert( ( *sIt )->data( Qt::UserRole ).toString() );
1584 mOverviewListWidget->clear();
1590 mOverviewFrameMapComboBox->setExceptedItemList( QList< QgsLayoutItem * >() << mMapItem );
1593 const QList< QgsLayoutItemMapOverview * > overviews = mMapItem->overviews()->asList();
1594 QList< QgsLayoutItemMapOverview * >::const_iterator overviewIt = overviews.constBegin();
1595 for ( ; overviewIt != overviews.constEnd(); ++overviewIt )
1597 QListWidgetItem *item = addOverviewListItem( ( *overviewIt )->id(), ( *overviewIt )->name() );
1598 if ( selectedIds.contains( ( *overviewIt )->id() ) )
1600 item->setSelected(
true );
1601 mOverviewListWidget->setCurrentItem( item );
1605 if ( mOverviewListWidget->currentItem() )
1607 mOverviewListWidget_currentItemChanged( mOverviewListWidget->currentItem(),
nullptr );
1611 mOverviewListWidget_currentItemChanged(
nullptr,
nullptr );
1615 void QgsLayoutMapWidget::mOverviewCheckBox_toggled(
bool state )
1623 mMapItem->layout()->undoStack()->beginCommand( mMapItem, tr(
"Overview Display Toggled" ) );
1625 mMapItem->invalidateCache();
1626 mMapItem->layout()->undoStack()->endCommand();
1629 void QgsLayoutMapWidget::overviewMapChanged(
QgsLayoutItem *item )
1641 mMapItem->beginCommand( tr(
"Change Overview Map" ) );
1643 mMapItem->invalidateCache();
1644 mMapItem->endCommand();
1647 void QgsLayoutMapWidget::mOverviewBlendModeComboBox_currentIndexChanged(
int index )
1656 mMapItem->beginCommand( tr(
"Change Overview Blend Mode" ) );
1657 overview->
setBlendMode( mOverviewBlendModeComboBox->blendMode() );
1658 mMapItem->invalidateCache();
1659 mMapItem->endCommand();
1662 void QgsLayoutMapWidget::mOverviewInvertCheckbox_toggled(
bool state )
1670 mMapItem->beginCommand( tr(
"Toggle Overview Inverted" ) );
1672 mMapItem->invalidateCache();
1673 mMapItem->endCommand();
1676 void QgsLayoutMapWidget::mOverviewCenterCheckbox_toggled(
bool state )
1684 mMapItem->beginCommand( tr(
"Toggle Overview Centered" ) );
1686 mMapItem->invalidateCache();
1687 mMapItem->endCommand();
1690 void QgsLayoutMapWidget::overviewStackingChanged(
int )
1698 mMapItem->beginCommand( tr(
"Change Overview Position" ) );
1700 mMapItem->invalidateCache();
1701 mMapItem->endCommand();
1708 mOverviewStackingLayerComboBox->setEnabled(
false );
1713 mOverviewStackingLayerComboBox->setEnabled(
true );
1718 void QgsLayoutMapWidget::overviewStackingLayerChanged(
QgsMapLayer *layer )
1726 mMapItem->beginCommand( tr(
"Change Overview Position" ) );
1728 mMapItem->invalidateCache();
1729 mMapItem->endCommand();
1743 mLabelBoundarySpinBox->setClearValue( 0 );
1744 mLabelBoundarySpinBox->setShowClearButton(
true );
1746 mLabelBoundaryUnitsCombo->linkToWidget( mLabelBoundarySpinBox );
1747 mLabelBoundaryUnitsCombo->setConverter( &mMapItem->layout()->renderContext().measurementConverter() );
1750 connect( mLabelBoundarySpinBox,
static_cast < void ( QDoubleSpinBox::* )(
double )
> ( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutMapLabelingWidget::labelMarginChanged );
1751 connect( mShowPartialLabelsCheckBox, &QCheckBox::toggled,
this, &QgsLayoutMapLabelingWidget::showPartialsToggled );
1752 connect( mShowUnplacedCheckBox, &QCheckBox::toggled,
this, &QgsLayoutMapLabelingWidget::showUnplacedToggled );
1769 mMapItem = qobject_cast< QgsLayoutItemMap * >( item );
1776 updateGuiElements();
1781 void QgsLayoutMapLabelingWidget::updateGuiElements()
1783 whileBlocking( mLabelBoundarySpinBox )->setValue( mMapItem->labelMargin().length() );
1784 whileBlocking( mLabelBoundaryUnitsCombo )->setUnit( mMapItem->labelMargin().units() );
1788 if ( mBlockingItemsListView->model() )
1790 QAbstractItemModel *oldModel = mBlockingItemsListView->model();
1791 mBlockingItemsListView->setModel(
nullptr );
1792 oldModel->deleteLater();
1796 mBlockingItemsListView->setModel( model );
1801 void QgsLayoutMapLabelingWidget::labelMarginChanged(
double val )
1808 mMapItem->layout()->undoStack()->endCommand();
1809 mMapItem->invalidateCache();
1812 void QgsLayoutMapLabelingWidget::labelMarginUnitsChanged()
1818 mMapItem->setLabelMargin(
QgsLayoutMeasurement( mLabelBoundarySpinBox->value(), mLabelBoundaryUnitsCombo->unit() ) );
1819 mMapItem->layout()->undoStack()->endCommand();
1820 mMapItem->invalidateCache();
1823 void QgsLayoutMapLabelingWidget::showPartialsToggled(
bool checked )
1828 mMapItem->layout()->undoStack()->beginCommand( mMapItem, tr(
"Change Label Visibility" ) );
1829 QgsLayoutItemMap::MapItemFlags flags = mMapItem->mapFlags();
1834 mMapItem->setMapFlags( flags );
1835 mMapItem->layout()->undoStack()->endCommand();
1836 mMapItem->invalidateCache();
1839 void QgsLayoutMapLabelingWidget::showUnplacedToggled(
bool checked )
1844 mMapItem->layout()->undoStack()->beginCommand( mMapItem, tr(
"Change Label Visibility" ) );
1845 QgsLayoutItemMap::MapItemFlags flags = mMapItem->mapFlags();
1850 mMapItem->setMapFlags( flags );
1851 mMapItem->layout()->undoStack()->endCommand();
1852 mMapItem->invalidateCache();
1856 : QSortFilterProxyModel( parent )
1857 , mLayoutModel( layoutModel )
1860 setSourceModel( layoutModel );
1873 if ( i.column() != 0 )
1886 case Qt::CheckStateRole:
1887 switch ( i.column() )
1890 return mMapItem ? ( mMapItem->isLabelBlockingItem( item ) ? Qt::Checked : Qt::Unchecked ) : Qt::Unchecked;
1896 return mLayoutModel->
data( sourceIndex, role );
1904 if ( !index.isValid() )
1908 if ( !item || !mMapItem )
1913 mMapItem->layout()->undoStack()->beginCommand( mMapItem, tr(
"Change Label Blocking Items" ) );
1915 if ( value.toBool() )
1917 mMapItem->addLabelBlockingItem( item );
1921 mMapItem->removeLabelBlockingItem( item );
1923 emit dataChanged( index, index, QVector<int>() << role );
1925 mMapItem->layout()->undoStack()->endCommand();
1926 mMapItem->invalidateCache();
1933 Qt::ItemFlags
flags = QAbstractItemModel::flags( index );
1935 if ( ! index.isValid() )
1940 switch ( index.column() )
1943 return flags | Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsUserCheckable;
1945 return flags | Qt::ItemIsEnabled | Qt::ItemIsSelectable;
1952 if ( !item || item == mMapItem )
1975 mLayersTreeView->setModel( mLayerModel );
1981 for (
int i = 0; i < mAtlasClippingTypeComboBox->count(); ++i )
1983 mItemClippingTypeComboBox->addItem( mAtlasClippingTypeComboBox->itemText( i ), mAtlasClippingTypeComboBox->itemData( i ) );
1986 mClipItemComboBox->setCurrentLayout( map->
layout() );
1989 connect( mRadioClipSelectedLayers, &QRadioButton::toggled, mLayersTreeView, &QWidget::setEnabled );
1990 mLayersTreeView->setEnabled(
false );
1991 mRadioClipAllLayers->setChecked(
true );
1993 connect( mClipToAtlasCheckBox, &QGroupBox::toggled,
this, [ = ](
bool active )
1995 if ( !mBlockUpdates )
1997 mMapItem->beginCommand( tr(
"Toggle Atlas Clipping" ) );
1998 mMapItem->atlasClippingSettings()->setEnabled( active );
1999 mMapItem->endCommand();
2002 connect( mForceLabelsInsideCheckBox, &QCheckBox::toggled,
this, [ = ](
bool active )
2004 if ( !mBlockUpdates )
2006 mMapItem->beginCommand( tr(
"Change Atlas Clipping Label Behavior" ) );
2007 mMapItem->atlasClippingSettings()->setForceLabelsInsideFeature( active );
2008 mMapItem->endCommand();
2011 connect( mAtlasClippingTypeComboBox, qOverload<int>( &QComboBox::currentIndexChanged ),
this, [ = ]
2013 if ( !mBlockUpdates )
2015 mMapItem->beginCommand( tr(
"Change Atlas Clipping Behavior" ) );
2017 mMapItem->endCommand();
2021 connect( mRadioClipSelectedLayers, &QCheckBox::toggled,
this, [ = ](
bool active )
2023 if ( active && !mBlockUpdates )
2025 mBlockUpdates =
true;
2026 mMapItem->beginCommand( tr(
"Change Atlas Clipping Layers" ) );
2027 mMapItem->atlasClippingSettings()->setRestrictToLayers(
true );
2028 mMapItem->endCommand();
2029 mBlockUpdates =
false;
2032 connect( mRadioClipAllLayers, &QCheckBox::toggled,
this, [ = ](
bool active )
2034 if ( active && !mBlockUpdates )
2036 mBlockUpdates =
true;
2037 mMapItem->beginCommand( tr(
"Change Atlas Clipping Layers" ) );
2038 mMapItem->atlasClippingSettings()->setRestrictToLayers(
false );
2039 mMapItem->endCommand();
2040 mBlockUpdates =
false;
2043 connect( mLayerModel, &QgsMapLayerModel::dataChanged,
this, [ = ](
const QModelIndex &,
const QModelIndex &,
const QVector<int> &roles = QVector<int>() )
2045 if ( !roles.contains( Qt::CheckStateRole ) )
2048 if ( !mBlockUpdates )
2050 mBlockUpdates =
true;
2051 mMapItem->beginCommand( tr(
"Change Atlas Clipping Layers" ) );
2052 mMapItem->atlasClippingSettings()->setLayersToClip( mLayerModel->
layersChecked() );
2053 mMapItem->endCommand();
2054 mBlockUpdates =
false;
2060 connect( mClipToItemCheckBox, &QGroupBox::toggled,
this, [ = ](
bool active )
2062 if ( !mBlockUpdates )
2064 mMapItem->beginCommand( tr(
"Toggle Map Clipping" ) );
2065 mMapItem->itemClippingSettings()->setEnabled( active );
2066 mMapItem->endCommand();
2069 connect( mItemClippingTypeComboBox, qOverload<int>( &QComboBox::currentIndexChanged ),
this, [ = ]
2071 if ( !mBlockUpdates )
2073 mMapItem->beginCommand( tr(
"Change Map Clipping Behavior" ) );
2075 mMapItem->endCommand();
2078 connect( mForceLabelsInsideItemCheckBox, &QCheckBox::toggled,
this, [ = ](
bool active )
2080 if ( !mBlockUpdates )
2082 mMapItem->beginCommand( tr(
"Change Map Clipping Label Behavior" ) );
2083 mMapItem->itemClippingSettings()->setForceLabelsInsideClipPath( active );
2084 mMapItem->endCommand();
2089 if ( !mBlockUpdates )
2091 mMapItem->beginCommand( tr(
"Change Map Clipping Item" ) );
2092 mMapItem->itemClippingSettings()->setSourceItem( item );
2093 mMapItem->endCommand();
2100 this, &QgsLayoutMapClippingWidget::atlasLayerChanged );
2104 atlasToggled( atlas->enabled() );
2110 mClipToAtlasCheckBox->setTitle( tr(
"Clip to %1 feature" ).arg(
string ) );
2111 mClipToAtlasLabel->setText( tr(
"<b>When enabled, map layers will be automatically clipped to the boundary of the current %1 feature.</b>" ).arg(
string ) );
2112 mForceLabelsInsideCheckBox->setText( tr(
"Force labels inside %1 feature" ).arg(
string ) );
2125 mMapItem = qobject_cast< QgsLayoutItemMap * >( item );
2132 updateGuiElements();
2137 void QgsLayoutMapClippingWidget::updateGuiElements()
2139 if ( mBlockUpdates )
2142 mBlockUpdates =
true;
2143 mClipToAtlasCheckBox->setChecked( mMapItem->atlasClippingSettings()->enabled() );
2144 mAtlasClippingTypeComboBox->setCurrentIndex( mAtlasClippingTypeComboBox->findData(
static_cast< int >( mMapItem->atlasClippingSettings()->featureClippingType() ) ) );
2145 mForceLabelsInsideCheckBox->setChecked( mMapItem->atlasClippingSettings()->forceLabelsInsideFeature() );
2147 mRadioClipAllLayers->setChecked( !mMapItem->atlasClippingSettings()->restrictToLayers() );
2148 mRadioClipSelectedLayers->setChecked( mMapItem->atlasClippingSettings()->restrictToLayers() );
2149 mLayerModel->
setLayersChecked( mMapItem->atlasClippingSettings()->layersToClip() );
2151 mClipToItemCheckBox->setChecked( mMapItem->itemClippingSettings()->enabled() );
2152 mItemClippingTypeComboBox->setCurrentIndex( mItemClippingTypeComboBox->findData(
static_cast< int >( mMapItem->itemClippingSettings()->featureClippingType() ) ) );
2153 mForceLabelsInsideItemCheckBox->setChecked( mMapItem->itemClippingSettings()->forceLabelsInsideClipPath() );
2154 mClipItemComboBox->setItem( mMapItem->itemClippingSettings()->sourceItem() );
2156 mBlockUpdates =
false;
2159 void QgsLayoutMapClippingWidget::atlasLayerChanged(
QgsVectorLayer *layer )
2164 mClipToAtlasCheckBox->setChecked(
false );
2165 mClipToAtlasCheckBox->setEnabled(
false );
2170 mClipToAtlasCheckBox->setEnabled(
true );
2174 void QgsLayoutMapClippingWidget::atlasToggled(
bool atlasEnabled )
2176 if ( atlasEnabled &&
2177 mMapItem && mMapItem->layout() && mMapItem->layout()->reportContext().layer()
2180 mClipToAtlasCheckBox->setEnabled(
true );
2184 mClipToAtlasCheckBox->setEnabled(
false );
2185 mClipToAtlasCheckBox->setChecked(
false );
static QString defaultProjectScales()
A string with default project scales.
static QIcon getThemeIcon(const QString &name, const QColor &fillColor=QColor(), const QColor &strokeColor=QColor())
Helper to get a theme icon.
static QgsBookmarkManager * bookmarkManager()
Returns the application's bookmark manager, used for storing installation-wide bookmarks.
@ RoleExtent
Bookmark extent as a QgsReferencedRectangle.
@ RoleGroup
Bookmark group.
A QSortFilterProxyModel subclass for sorting the entries in a QgsBookmarkManagerModel.
This class represents a coordinate reference system (CRS).
bool isValid() const
Returns whether this CRS is correctly initialized and usable.
Custom exception class for Coordinate Reference System related exceptions.
The QgsSpinBox is a spin box with a clear button that will set the value to the defined clear value.
A fill symbol type, for rendering Polygon and MultiPolygon geometries.
QgsFillSymbol * clone() const override
Returns a deep copy of this symbol.
QList< QgsMapLayer * > layerOrder() const
The order in which layers will be rendered on the canvas.
Class used to render QgsLayout as an atlas, by iterating over the features from an associated vector ...
void toggled(bool)
Emitted when atlas is enabled or disabled.
A common interface for layout designer dialogs and widgets.
virtual void activateTool(StandardTool tool)=0
Activates a standard layout designer tool.
@ ToolMoveItemContent
Move item content tool.
void itemChanged(QgsLayoutItem *item)
Emitted whenever the currently selected item changes.
An individual grid which is drawn above the map content in a QgsLayoutItemMap.
QString id() const
Returns the unique id for the map item.
StackingPosition
Item stacking position, specifies where the in the map's stack the item should be rendered.
@ StackBelowMapLabels
Render above all map layers, but below map labels.
@ StackAboveMapLabels
Render above all map layers and labels.
@ StackBelowMapLayer
Render below a specific map layer (see stackingLayer())
@ StackAboveMapLayer
Render above a specific map layer (see stackingLayer())
@ StackBelowMap
Render below all map layers.
void setStackingLayer(QgsMapLayer *layer)
Sets the item's stacking layer, which specifies where the in the map's stack the item should be rende...
virtual void setEnabled(bool enabled)
Controls whether the item will be drawn.
void setStackingPosition(StackingPosition position)
Sets the item's stacking position, which specifies where the in the map's stack the item should be re...
StackingPosition stackingPosition() const
Returns the item's stacking position, which specifies where the in the map's stack the item should be...
QString name() const
Returns the friendly display name for the item.
void setName(const QString &name)
Sets the friendly display name for the item.
bool enabled() const
Returns whether the item will be drawn.
QgsMapLayer * stackingLayer() const
Returns the item's stacking layer, which specifies where the in the map's stack the item should be re...
An individual overview which is drawn above the map content in a QgsLayoutItemMap,...
QgsFillSymbol * frameSymbol()
Returns the fill symbol used for drawing the overview extent.
QPainter::CompositionMode blendMode() const
Retrieves the blending mode used for drawing the overview.
void setBlendMode(QPainter::CompositionMode mode)
Sets the blending mode used for drawing the overview.
bool centered() const
Returns whether the extent of the map is forced to center on the overview.
void setLinkedMap(QgsLayoutItemMap *map)
Sets the map to show the overview extent of.
void setFrameSymbol(QgsFillSymbol *symbol)
Sets the fill symbol used for drawing the overview extent.
bool inverted() const
Returns whether the overview frame is inverted, ie, whether the shaded area is drawn outside the exte...
void setInverted(bool inverted)
Sets whether the overview frame is inverted, ie, whether the shaded area is drawn outside the extent ...
void setCentered(bool centered)
Sets whether the extent of the map is forced to center on the overview.
QgsLayoutItemMap * linkedMap()
Returns the source map to show the overview extent of.
Layout graphical items for displaying a map.
void extentChanged()
Emitted when the map's extent changes.
@ Predefined
A scale is chosen from the predefined scales.
@ Auto
The extent is adjusted so that each feature is fully visible.
@ Fixed
The current scale of the map is used for each feature of the atlas.
void mapRotationChanged(double newRotation)
Emitted when the map's rotation changes.
@ ShowPartialLabels
Whether to draw labels which are partially outside of the map view.
@ ShowUnplacedLabels
Whether to render unplaced labels in the map view.
Base class for graphical items within a QgsLayout.
@ UndoOverviewStyle
Map overview style.
@ UndoMapRotation
Map rotation changed.
@ UndoAtlasMargin
Map atlas margin changed.
@ UndoMapLabelMargin
Margin for labels from edge of map.
int type() const override
Returns a unique graphics item type identifier.
@ FlagProvidesClipPath
Item can act as a clipping path provider (see clipPath())
Model for label blocking items.
bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const override
QgsLayoutMapItemBlocksLabelsModel(QgsLayoutItemMap *map, QgsLayoutModel *layoutModel, QObject *parent=nullptr)
constructor
Qt::ItemFlags flags(const QModelIndex &index) const override
bool setData(const QModelIndex &index, const QVariant &value, int role) override
QVariant data(const QModelIndex &index, int role) const override
int columnCount(const QModelIndex &parent=QModelIndex()) const override
This class provides a method of storing measurements for use in QGIS layouts using a variety of diffe...
A model for items attached to a layout.
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const override
QVariant data(const QModelIndex &index, int role) const override
QgsLayoutItem * itemFromIndex(const QModelIndex &index) const
Returns the QgsLayoutItem corresponding to a QModelIndex index, if possible.
const QgsLayout * layout() const
Returns the layout the object is attached to.
void changed()
Emitted when the object's properties change.
@ MapYMin
Map extent y minimum.
@ MapStylePreset
Layer and style map theme.
@ MapXMax
Map extent x maximum.
@ StartDateTime
Temporal range's start DateTime.
@ EndDateTime
Temporal range's end DateTime.
@ MapAtlasMargin
Map atlas margin.
@ MapYMax
Map extent y maximum.
@ MapXMin
Map extent x minimum.
@ MapLabelMargin
Map label margin.
@ MapLayers
Map layer set.
@ MapRotation
Map rotation.
@ OriginalValue
Return the original, user set value.
void layerChanged(QgsVectorLayer *layer)
Emitted when the context's layer is changed.
void changed(QgsUnitTypes::LayoutUnit unit)
Emitted when the unit is changed.
QgsLayoutReportContext & reportContext()
Returns a reference to the layout's report context, which stores information relating to the current ...
Map canvas is a class for displaying all GIS data types on a canvas.
void zoomScale(double scale, bool ignoreScaleLock=false)
Zooms the canvas to a specific scale.
bool setReferencedExtent(const QgsReferencedRectangle &extent) SIP_THROW(QgsCsException)
Sets the canvas to the specified extent.
double scale() const
Returns the last reported scale of the canvas.
const QgsMapSettings & mapSettings() const
Gets access to properties used for map rendering.
void refresh()
Repaints the canvas map.
FeatureClippingType
Feature clipping behavior, which controls how features from vector layers will be clipped.
@ NoClipping
Only render features which intersect the clipping region, but do not clip these features to the regio...
@ ClipPainterOnly
Applying clipping on the painter only (i.e. feature boundaries will be unchanged, but may be invisibl...
@ ClipToIntersection
Clip the geometry of these features to the region prior to rendering (i.e. feature boundaries will fo...
void layerChanged(QgsMapLayer *layer)
Emitted whenever the currently selected layer changes.
The QgsMapLayerModel class is a model to display layers in widgets.
QList< QgsMapLayer * > layersChecked(Qt::CheckState checkState=Qt::Checked)
layersChecked returns the list of layers which are checked (or unchecked)
void setItemsCheckable(bool checkable)
setItemsCheckable defines if layers should be selectable in the widget
void setLayersChecked(const QList< QgsMapLayer * > &layers)
Sets which layers are checked in the model.
Base class for all map layer types.
QString id() const
Returns the layer's unique ID, which is used to access this layer from QgsProject.
QgsRectangle visibleExtent() const
Returns the actual extent derived from requested extent that takes output image size into account.
QList< QgsMapLayer * > layers() const
Returns the list of layers which will be rendered in the map.
QgsCoordinateReferenceSystem destinationCrs() const
Returns the destination coordinate reference system for the map render.
void mapThemesChanged()
Emitted when map themes within the collection are changed.
QStringList mapThemeVisibleLayerIds(const QString &name) const
Returns the list of layer IDs that are visible for the specified map theme.
Interface for master layout type objects, such as print layouts and reports.
static QgsProject * instance()
Returns the QgsProject singleton instance.
QgsMapThemeCollection * mapThemeCollection
QgsLayerTree * layerTreeRoot() const
Returns pointer to the root (invisible) node of the project's layer tree.
QgsCoordinateReferenceSystem crs
A rectangle specified with double values.
double yMaximum() const SIP_HOLDGIL
Returns the y maximum value (top side of rectangle).
double xMaximum() const SIP_HOLDGIL
Returns the x maximum value (right side of rectangle).
double xMinimum() const SIP_HOLDGIL
Returns the x minimum value (left side of rectangle).
double yMinimum() const SIP_HOLDGIL
Returns the y minimum value (bottom side of rectangle).
bool isEmpty() const
Returns true if the rectangle is empty.
QgsCoordinateReferenceSystem crs() const
Returns the associated coordinate reference system, or an invalid CRS if no reference system is set.
A QgsRectangle with associated coordinate reference system.
This class is a composition of two QSettings instances:
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), Section section=NoSection) const
Returns the value for setting key.
Represents a vector layer which manages a vector based data sets.
Q_INVOKABLE QgsWkbTypes::Type wkbType() const FINAL
Returns the WKBType or WKBUnknown in case of error.
Q_INVOKABLE QgsWkbTypes::GeometryType geometryType() const
Returns point, line or polygon.
static GeometryType geometryType(Type type) SIP_HOLDGIL
Returns the geometry type for a WKB type, e.g., both MultiPolygon and CurvePolygon would have a Polyg...
QSize iconSize(bool dockableToolbar)
Returns the user-preferred size of a window's toolbar icons.
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
QgsSignalBlocker< Object > whileBlocking(Object *object)
Temporarily blocks signals from a QObject while calling a single method from the object.
const QgsCoordinateReferenceSystem & crs