40#include <QStringListModel>
45 , mMapCanvas( mapCanvas )
50 connect( mScaleLineEdit, &QLineEdit::editingFinished,
this, &QgsLayoutMapWidget::mScaleLineEdit_editingFinished );
51 connect( mActionSetToCanvasExtent, &QAction::triggered,
this, &QgsLayoutMapWidget::setToMapCanvasExtent );
52 connect( mActionViewExtentInCanvas, &QAction::triggered,
this, &QgsLayoutMapWidget::viewExtentInCanvas );
53 connect( mActionSetToCanvasScale, &QAction::triggered,
this, &QgsLayoutMapWidget::setToMapCanvasScale );
54 connect( mActionViewScaleInCanvas, &QAction::triggered,
this, &QgsLayoutMapWidget::viewScaleInCanvas );
55 connect( mActionUpdatePreview, &QAction::triggered,
this, &QgsLayoutMapWidget::updatePreview );
56 connect( mFollowVisibilityPresetCheckBox, &QCheckBox::stateChanged,
this, &QgsLayoutMapWidget::mFollowVisibilityPresetCheckBox_stateChanged );
57 connect( mKeepLayerListCheckBox, &QCheckBox::stateChanged,
this, &QgsLayoutMapWidget::mKeepLayerListCheckBox_stateChanged );
58 connect( mKeepLayerStylesCheckBox, &QCheckBox::stateChanged,
this, &QgsLayoutMapWidget::mKeepLayerStylesCheckBox_stateChanged );
59 connect( mDrawCanvasItemsCheckBox, &QCheckBox::stateChanged,
this, &QgsLayoutMapWidget::mDrawCanvasItemsCheckBox_stateChanged );
60 connect( mOverviewBlendModeComboBox,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsLayoutMapWidget::mOverviewBlendModeComboBox_currentIndexChanged );
61 connect( mOverviewInvertCheckbox, &QCheckBox::toggled,
this, &QgsLayoutMapWidget::mOverviewInvertCheckbox_toggled );
62 connect( mOverviewCenterCheckbox, &QCheckBox::toggled,
this, &QgsLayoutMapWidget::mOverviewCenterCheckbox_toggled );
63 connect( mOverviewPositionComboBox,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsLayoutMapWidget::overviewStackingChanged );
65 connect( mXMinLineEdit, &QLineEdit::editingFinished,
this, &QgsLayoutMapWidget::mXMinLineEdit_editingFinished );
66 connect( mXMaxLineEdit, &QLineEdit::editingFinished,
this, &QgsLayoutMapWidget::mXMaxLineEdit_editingFinished );
67 connect( mYMinLineEdit, &QLineEdit::editingFinished,
this, &QgsLayoutMapWidget::mYMinLineEdit_editingFinished );
68 connect( mYMaxLineEdit, &QLineEdit::editingFinished,
this, &QgsLayoutMapWidget::mYMaxLineEdit_editingFinished );
69 connect( mAtlasMarginRadio, &QRadioButton::toggled,
this, &QgsLayoutMapWidget::mAtlasMarginRadio_toggled );
70 connect( mAtlasCheckBox, &QgsCollapsibleGroupBoxBasic::toggled,
this, &QgsLayoutMapWidget::mAtlasCheckBox_toggled );
71 connect( mAtlasMarginSpinBox,
static_cast < void ( QSpinBox::* )(
int )
> ( &QSpinBox::valueChanged ),
this, &QgsLayoutMapWidget::mAtlasMarginSpinBox_valueChanged );
72 connect( mAtlasFixedScaleRadio, &QRadioButton::toggled,
this, &QgsLayoutMapWidget::mAtlasFixedScaleRadio_toggled );
73 connect( mAtlasPredefinedScaleRadio, &QRadioButton::toggled,
this, &QgsLayoutMapWidget::mAtlasPredefinedScaleRadio_toggled );
74 connect( mAddGridPushButton, &QPushButton::clicked,
this, &QgsLayoutMapWidget::mAddGridPushButton_clicked );
75 connect( mRemoveGridPushButton, &QPushButton::clicked,
this, &QgsLayoutMapWidget::mRemoveGridPushButton_clicked );
76 connect( mGridUpButton, &QPushButton::clicked,
this, &QgsLayoutMapWidget::mGridUpButton_clicked );
77 connect( mGridDownButton, &QPushButton::clicked,
this, &QgsLayoutMapWidget::mGridDownButton_clicked );
78 connect( mGridListWidget, &QListWidget::currentItemChanged,
this, &QgsLayoutMapWidget::mGridListWidget_currentItemChanged );
79 connect( mGridListWidget, &QListWidget::itemChanged,
this, &QgsLayoutMapWidget::mGridListWidget_itemChanged );
80 connect( mGridPropertiesButton, &QPushButton::clicked,
this, &QgsLayoutMapWidget::mGridPropertiesButton_clicked );
81 connect( mAddOverviewPushButton, &QPushButton::clicked,
this, &QgsLayoutMapWidget::mAddOverviewPushButton_clicked );
82 connect( mRemoveOverviewPushButton, &QPushButton::clicked,
this, &QgsLayoutMapWidget::mRemoveOverviewPushButton_clicked );
83 connect( mOverviewUpButton, &QPushButton::clicked,
this, &QgsLayoutMapWidget::mOverviewUpButton_clicked );
84 connect( mOverviewDownButton, &QPushButton::clicked,
this, &QgsLayoutMapWidget::mOverviewDownButton_clicked );
85 connect( mOverviewCheckBox, &QgsCollapsibleGroupBoxBasic::toggled,
this, &QgsLayoutMapWidget::mOverviewCheckBox_toggled );
86 connect( mOverviewListWidget, &QListWidget::currentItemChanged,
this, &QgsLayoutMapWidget::mOverviewListWidget_currentItemChanged );
87 connect( mOverviewListWidget, &QListWidget::itemChanged,
this, &QgsLayoutMapWidget::mOverviewListWidget_itemChanged );
88 connect( mActionLabelSettings, &QAction::triggered,
this, &QgsLayoutMapWidget::showLabelSettings );
89 connect( mActionClipSettings, &QAction::triggered,
this, &QgsLayoutMapWidget::showClipSettings );
91 connect( mTemporalCheckBox, &QgsCollapsibleGroupBoxBasic::toggled,
this, &QgsLayoutMapWidget::mTemporalCheckBox_toggled );
92 connect( mStartDateTime, &QDateTimeEdit::dateTimeChanged,
this, &QgsLayoutMapWidget::updateTemporalExtent );
93 connect( mEndDateTime, &QDateTimeEdit::dateTimeChanged,
this, &QgsLayoutMapWidget::updateTemporalExtent );
95 mStartDateTime->setDateTimeRange( QDateTime( QDate( 1, 1, 1 ), QTime( 0, 0, 0 ) ), mStartDateTime->maximumDateTime() );
96 mEndDateTime->setDateTimeRange( QDateTime( QDate( 1, 1, 1 ), QTime( 0, 0, 0 ) ), mStartDateTime->maximumDateTime() );
97 mStartDateTime->setDisplayFormat(
"yyyy-MM-dd HH:mm:ss" );
98 mEndDateTime->setDisplayFormat(
"yyyy-MM-dd HH:mm:ss" );
100 connect( mActionMoveContent, &QAction::triggered,
this, &QgsLayoutMapWidget::switchToMoveContentTool );
102 mMapRotationSpinBox->setClearValue( 0 );
106 mBookmarkMenu =
new QMenu(
this );
107 QToolButton *btnBookmarks =
new QToolButton(
this );
108 btnBookmarks->setAutoRaise(
true );
109 btnBookmarks->setToolTip( tr(
"Bookmarks" ) );
111 btnBookmarks->setPopupMode( QToolButton::InstantPopup );
112 btnBookmarks->setMenu( mBookmarkMenu );
114 mDockToolbar->insertWidget( mActionMoveContent, btnBookmarks );
115 connect( mBookmarkMenu, &QMenu::aboutToShow,
this, &QgsLayoutMapWidget::aboutToShowBookmarkMenu );
119 mainLayout->addWidget( mItemPropertiesWidget );
121 mScaleLineEdit->setValidator(
new QDoubleValidator( mScaleLineEdit ) );
123 mXMinLineEdit->setValidator(
new QDoubleValidator( mXMinLineEdit ) );
124 mXMaxLineEdit->setValidator(
new QDoubleValidator( mXMaxLineEdit ) );
125 mYMinLineEdit->setValidator(
new QDoubleValidator( mYMinLineEdit ) );
126 mYMaxLineEdit->setValidator(
new QDoubleValidator( mYMaxLineEdit ) );
134 blockAllSignals(
true );
137 mCrsSelector->setNotSetText( tr(
"Use Project CRS" ) );
138 mCrsSelector->setDialogTitle( tr(
"Map Item CRS" ) );
143 mFollowVisibilityPresetCombo->setModel(
new QStringListModel( mFollowVisibilityPresetCombo ) );
144 connect( mFollowVisibilityPresetCombo,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsLayoutMapWidget::followVisibilityPresetSelected );
146 this, &QgsLayoutMapWidget::onMapThemesChanged );
147 onMapThemesChanged();
150 QMenu *menuKeepLayers =
new QMenu(
this );
151 mLayerListFromPresetButton->setMenu( menuKeepLayers );
153 mLayerListFromPresetButton->setToolTip( tr(
"Set layer list from a map theme" ) );
154 connect( menuKeepLayers, &QMenu::aboutToShow,
this, &QgsLayoutMapWidget::aboutToShowKeepLayersVisibilityPresetsMenu );
159 this, &QgsLayoutMapWidget::atlasLayerChanged );
163 compositionAtlasToggled( atlas->enabled() );
166 mOverviewFrameMapComboBox->setCurrentLayout( item->
layout() );
168 mOverviewFrameStyleButton->registerExpressionContextGenerator( item );
174 mOverviewFrameStyleButton->registerExpressionContextGenerator( item );
197 loadOverviewEntries();
199 connect( mMapRotationSpinBox,
static_cast < void (
QgsDoubleSpinBox::* )(
double )
> ( &QgsDoubleSpinBox::valueChanged ),
this, &QgsLayoutMapWidget::rotationChanged );
203 blockAllSignals(
false );
208 if ( mItemPropertiesWidget )
214 mReportTypeString = string;
215 mAtlasCheckBox->setTitle( tr(
"Controlled by %1" ).arg(
string == tr(
"atlas" ) ? tr(
"Atlas" ) : tr(
"Report" ) ) );
216 mAtlasPredefinedScaleRadio->setToolTip( tr(
"Use one of the predefined scales of the project where the %1 feature best fits." ).arg(
string ) );
219 mClipWidget->setReportTypeString(
string );
221 mLabelWidget->setReportTypeString(
string );
242 mMapItem = qobject_cast< QgsLayoutItemMap * >( item );
243 mItemPropertiesWidget->
setItem( mMapItem );
245 mLabelWidget->setItem( mMapItem );
247 mClipWidget->setItem( mMapItem );
254 mOverviewFrameStyleButton->registerExpressionContextGenerator( mMapItem );
278void QgsLayoutMapWidget::compositionAtlasToggled(
bool atlasEnabled )
281 mMapItem && mMapItem->layout() && mMapItem->layout()->reportContext().layer()
284 mAtlasCheckBox->setEnabled(
true );
288 mAtlasCheckBox->setEnabled(
false );
289 mAtlasCheckBox->setChecked(
false );
293void QgsLayoutMapWidget::aboutToShowKeepLayersVisibilityPresetsMenu()
298 QMenu *menu = qobject_cast<QMenu *>( sender() );
304 for (
const QString &presetName : constMapThemes )
306 menu->addAction( presetName,
this, &QgsLayoutMapWidget::keepLayersVisibilityPresetSelected );
309 if ( menu->actions().isEmpty() )
310 menu->addAction( tr(
"No presets defined" ) )->setEnabled(
false );
313void QgsLayoutMapWidget::followVisibilityPresetSelected(
int currentIndex )
318 if ( mBlockThemeComboChanges != 0 )
321 if ( currentIndex == -1 )
325 if ( currentIndex != 0 )
327 presetName = mFollowVisibilityPresetCombo->currentText();
330 if ( presetName == mMapItem->followVisibilityPresetName() )
333 mMapItem->layout()->undoStack()->beginCommand( mMapItem, tr(
"Change Map Preset" ) );
334 mFollowVisibilityPresetCheckBox->setChecked(
true );
335 mMapItem->setFollowVisibilityPresetName( presetName );
336 mMapItem->layout()->undoStack()->endCommand();
338 mMapItem->invalidateCache();
341void QgsLayoutMapWidget::keepLayersVisibilityPresetSelected()
343 QAction *action = qobject_cast<QAction *>( sender() );
347 const QString presetName = action->text();
348 const QList<QgsMapLayer *> lst = orderedPresetVisibleLayers( presetName );
351 mKeepLayerListCheckBox->setChecked(
true );
352 mMapItem->setLayers( lst );
354 mKeepLayerStylesCheckBox->setChecked(
true );
356 mMapItem->layout()->undoStack()->beginCommand( mMapItem, tr(
"Change Map Preset" ) );
357 mMapItem->setLayerStyleOverrides(
QgsProject::instance()->mapThemeCollection()->mapThemeStyleOverrides( presetName ) );
358 mMapItem->layout()->undoStack()->endCommand();
360 mMapItem->invalidateCache();
364void QgsLayoutMapWidget::onMapThemesChanged()
366 if ( QStringListModel *model = qobject_cast<QStringListModel *>( mFollowVisibilityPresetCombo->model() ) )
368 mBlockThemeComboChanges++;
370 lst.append( tr(
"(none)" ) );
372 model->setStringList( lst );
375 const int presetModelIndex = mFollowVisibilityPresetCombo->findText( mMapItem->followVisibilityPresetName() );
376 mFollowVisibilityPresetCombo->blockSignals(
true );
377 mFollowVisibilityPresetCombo->setCurrentIndex( presetModelIndex != -1 ? presetModelIndex : 0 );
378 mFollowVisibilityPresetCombo->blockSignals(
false );
379 mBlockThemeComboChanges--;
390 if ( mMapItem->presetCrs() ==
crs )
396 bool updateExtent =
false;
403 newExtent = xForm.transformBoundingBox( prevExtent );
411 mMapItem->layout()->undoStack()->beginCommand( mMapItem, tr(
"Change Map CRS" ) );
412 mMapItem->setCrs(
crs );
414 mMapItem->zoomToExtent( newExtent );
415 mMapItem->layout()->undoStack()->endCommand();
416 mMapItem->invalidateCache();
419void QgsLayoutMapWidget::overviewSymbolChanged()
427 mMapItem->endCommand();
428 mMapItem->invalidateCache();
431void QgsLayoutMapWidget::showLabelSettings()
435 if ( !mReportTypeString.isEmpty() )
436 mLabelWidget->setReportTypeString( mReportTypeString );
441void QgsLayoutMapWidget::showClipSettings()
444 if ( !mReportTypeString.isEmpty() )
445 mClipWidget->setReportTypeString( mReportTypeString );
449void QgsLayoutMapWidget::switchToMoveContentTool()
455void QgsLayoutMapWidget::aboutToShowBookmarkMenu()
457 mBookmarkMenu->clear();
461 if ( !mBookmarkModel )
464 QMap< QString, QMenu * > groupMenus;
465 for (
int i = 0; i < mBookmarkModel->rowCount(); ++i )
468 QMenu *destMenu = mBookmarkMenu;
469 if ( !group.isEmpty() )
471 destMenu = groupMenus.value( group );
474 destMenu =
new QMenu( group, mBookmarkMenu );
475 groupMenus[ group ] = destMenu;
480 connect( action, &QAction::triggered,
this, [ = ]
490 if ( extent.
crs() != mMapItem->crs() )
494 QgsCoordinateTransform xForm( extent.crs(), mMapItem->crs(), QgsProject::instance() );
495 xForm.setBallparkTransformsAreAppropriate( true );
496 newExtent = xForm.transformBoundingBox( newExtent );
505 mMapItem->layout()->undoStack()->beginCommand( mMapItem, tr(
"Change Map Extent" ) );
506 mMapItem->zoomToExtent( newExtent );
507 mMapItem->layout()->undoStack()->endCommand();
509 destMenu->addAction( action );
512 QStringList groupKeys = groupMenus.keys();
513 groupKeys.sort( Qt::CaseInsensitive );
514 for (
int i = 0; i < groupKeys.count(); ++i )
516 if ( mBookmarkMenu->actions().value( i ) )
517 mBookmarkMenu->insertMenu( mBookmarkMenu->actions().at( i ), groupMenus.value( groupKeys.at( i ) ) );
519 mBookmarkMenu->addMenu( groupMenus.value( groupKeys.at( i ) ) );
523void QgsLayoutMapWidget::mTemporalCheckBox_toggled(
bool checked )
530 mMapItem->layout()->undoStack()->beginCommand( mMapItem, tr(
"Toggle Temporal Range" ) );
531 mMapItem->setIsTemporal( checked );
532 mMapItem->layout()->undoStack()->endCommand();
536 whileBlocking( mStartDateTime )->setDateTime( mMapItem->temporalRange().begin() );
537 whileBlocking( mEndDateTime )->setDateTime( mMapItem->temporalRange().end() );
543void QgsLayoutMapWidget::updateTemporalExtent()
550 const QDateTime begin = mStartDateTime->dateTime();
551 const QDateTime end = mEndDateTime->dateTime();
554 mMapItem->layout()->undoStack()->beginCommand( mMapItem, tr(
"Set Temporal Range" ) );
555 mMapItem->setTemporalRange( range );
556 mMapItem->layout()->undoStack()->endCommand();
561void QgsLayoutMapWidget::mAtlasCheckBox_toggled(
bool checked )
568 mAtlasFixedScaleRadio->setEnabled( checked );
569 mAtlasMarginRadio->setEnabled( checked );
571 if ( mAtlasMarginRadio->isEnabled() && mAtlasMarginRadio->isChecked() )
573 mAtlasMarginSpinBox->setEnabled(
true );
577 mAtlasMarginSpinBox->setEnabled(
false );
580 mAtlasPredefinedScaleRadio->setEnabled( checked );
585 if ( mMapItem->layout() )
587 toggleAtlasScalingOptionsByLayerType();
592 if ( !hasPredefinedScales() )
594 mAtlasPredefinedScaleRadio->setEnabled(
false );
597 mMapItem->layout()->undoStack()->beginCommand( mMapItem, tr(
"Set Atlas Driven" ) );
598 mMapItem->setAtlasDriven( checked );
599 mMapItem->layout()->undoStack()->endCommand();
603void QgsLayoutMapWidget::updateMapForAtlas()
606 if ( mMapItem->atlasDriven() )
613 mMapItem->invalidateCache();
617void QgsLayoutMapWidget::mAtlasMarginRadio_toggled(
bool checked )
619 mAtlasMarginSpinBox->setEnabled( checked );
621 if ( checked && mMapItem )
623 mMapItem->layout()->undoStack()->beginCommand( mMapItem, tr(
"Change Atlas Mode" ) );
625 mMapItem->layout()->undoStack()->endCommand();
630void QgsLayoutMapWidget::mAtlasMarginSpinBox_valueChanged(
int value )
638 mMapItem->setAtlasMargin( value / 100. );
639 mMapItem->layout()->undoStack()->endCommand();
643void QgsLayoutMapWidget::mAtlasFixedScaleRadio_toggled(
bool checked )
652 mMapItem->layout()->undoStack()->beginCommand( mMapItem, tr(
"Change Atlas Mode" ) );
654 mMapItem->layout()->undoStack()->endCommand();
659void QgsLayoutMapWidget::mAtlasPredefinedScaleRadio_toggled(
bool checked )
666 if ( hasPredefinedScales() )
670 mMapItem->layout()->undoStack()->beginCommand( mMapItem, tr(
"Change Atlas Scales" ) );
672 mMapItem->layout()->undoStack()->endCommand();
680 mMapItem->layout()->undoStack()->beginCommand( mMapItem, tr(
"Change Atlas Mode" ) );
682 mMapItem->layout()->undoStack()->endCommand();
686void QgsLayoutMapWidget::mScaleLineEdit_editingFinished()
693 bool conversionSuccess =
false;
694 const double scaleDenominator = QLocale().toDouble( mScaleLineEdit->text(), &conversionSuccess );
695 if ( !conversionSuccess )
703 mMapItem->layout()->undoStack()->beginCommand( mMapItem, tr(
"Change Map Scale" ) );
704 mMapItem->setScale( scaleDenominator );
705 mMapItem->layout()->undoStack()->endCommand();
708void QgsLayoutMapWidget::rotationChanged(
double value )
716 mMapItem->setMapRotation( value );
717 mMapItem->layout()->undoStack()->endCommand();
718 mMapItem->invalidateCache();
721void QgsLayoutMapWidget::setToMapCanvasExtent()
738 xForm.setBallparkTransformsAreAppropriate(
true );
739 newExtent = xForm.transformBoundingBox( newExtent );
748 mMapItem->layout()->undoStack()->beginCommand( mMapItem, tr(
"Change Map Extent" ) );
749 mMapItem->zoomToExtent( newExtent );
750 mMapItem->layout()->undoStack()->endCommand();
753void QgsLayoutMapWidget::setToMapCanvasScale()
760 const double newScale = mMapCanvas->
scale();
762 mMapItem->layout()->undoStack()->beginCommand( mMapItem, tr(
"Change Map Scale" ) );
763 mMapItem->setScale( newScale );
764 mMapItem->layout()->undoStack()->endCommand();
767void QgsLayoutMapWidget::viewExtentInCanvas()
774 const QgsRectangle currentMapExtent = mMapItem->extent();
776 if ( !currentMapExtent.
isEmpty() )
791void QgsLayoutMapWidget::viewScaleInCanvas()
798 const double currentScale = mMapItem->scale();
799 mMapCanvas->
zoomScale( currentScale,
true );
802void QgsLayoutMapWidget::mXMinLineEdit_editingFinished()
804 updateComposerExtentFromGui();
807void QgsLayoutMapWidget::mXMaxLineEdit_editingFinished()
809 updateComposerExtentFromGui();
812void QgsLayoutMapWidget::mYMinLineEdit_editingFinished()
814 updateComposerExtentFromGui();
817void QgsLayoutMapWidget::mYMaxLineEdit_editingFinished()
819 updateComposerExtentFromGui();
822void QgsLayoutMapWidget::updateGuiElements()
829 blockAllSignals(
true );
830 mLabel->setText( mMapItem->displayName() );
832 whileBlocking( mCrsSelector )->setCrs( mMapItem->presetCrs() );
835 const double scale = mMapItem->scale();
838 if ( scale >= 10000 )
841 mScaleLineEdit->setText( QLocale().toString( mMapItem->scale(),
'f', 0 ) );
843 else if ( scale >= 10 )
845 mScaleLineEdit->setText( QLocale().toString( mMapItem->scale(),
'f', 3 ) );
847 else if ( scale >= 1 )
850 mScaleLineEdit->setText( QLocale().toString( mMapItem->scale(),
'f', 4 ) );
855 mScaleLineEdit->setText( QLocale().toString( mMapItem->scale(),
'f', 10 ) );
859 const QgsRectangle composerMapExtent = mMapItem->extent();
860 mXMinLineEdit->setText( QLocale().toString( composerMapExtent.
xMinimum(),
'f', 3 ) );
861 mXMaxLineEdit->setText( QLocale().toString( composerMapExtent.
xMaximum(),
'f', 3 ) );
862 mYMinLineEdit->setText( QLocale().toString( composerMapExtent.
yMinimum(),
'f', 3 ) );
863 mYMaxLineEdit->setText( QLocale().toString( composerMapExtent.
yMaximum(),
'f', 3 ) );
868 mFollowVisibilityPresetCheckBox->setCheckState(
869 mMapItem->followVisibilityPreset() ? Qt::Checked : Qt::Unchecked );
870 const int presetModelIndex = mFollowVisibilityPresetCombo->findText( mMapItem->followVisibilityPresetName() );
871 mFollowVisibilityPresetCombo->setCurrentIndex( presetModelIndex != -1 ? presetModelIndex : 0 );
874 if ( mMapItem->keepLayerSet() )
876 mKeepLayerListCheckBox->setCheckState( Qt::Checked );
880 mKeepLayerListCheckBox->setCheckState( Qt::Unchecked );
883 mKeepLayerStylesCheckBox->setEnabled( mMapItem->keepLayerSet() );
884 mKeepLayerStylesCheckBox->setCheckState( mMapItem->keepLayerStyles() ? Qt::Checked : Qt::Unchecked );
887 if ( mMapItem->drawAnnotations() )
889 mDrawCanvasItemsCheckBox->setCheckState( Qt::Checked );
893 mDrawCanvasItemsCheckBox->setCheckState( Qt::Unchecked );
897 mAtlasCheckBox->setChecked( mMapItem->atlasDriven() );
900 mAtlasFixedScaleRadio->setEnabled( mMapItem->atlasDriven() );
903 mAtlasMarginRadio->setEnabled( mMapItem->atlasDriven() );
905 mAtlasPredefinedScaleRadio->setEnabled( mMapItem->atlasDriven() );
908 if ( mMapItem->atlasDriven() )
910 toggleAtlasScalingOptionsByLayerType();
913 if ( !hasPredefinedScales() )
915 mAtlasPredefinedScaleRadio->setEnabled(
false );
918 mTemporalCheckBox->setChecked( mMapItem->isTemporal() );
919 mTemporalCheckBox->setCollapsed( !mMapItem->isTemporal() );
920 mStartDateTime->setEnabled( mMapItem->isTemporal() );
921 mEndDateTime->setEnabled( mMapItem->isTemporal() );
922 if ( mMapItem->isTemporal() )
924 mStartDateTime->setDateTime( mMapItem->temporalRange().begin() );
925 mEndDateTime->setDateTime( mMapItem->temporalRange().end() );
930 loadOverviewEntries();
932 blockAllSignals(
false );
935void QgsLayoutMapWidget::toggleAtlasScalingOptionsByLayerType()
953 mAtlasFixedScaleRadio->setChecked(
true );
954 mAtlasMarginRadio->setEnabled(
false );
959 mAtlasMarginRadio->setEnabled(
true );
963void QgsLayoutMapWidget::updateComposerExtentFromGui()
970 double xmin, ymin, xmax, ymax;
971 bool conversionSuccess;
973 xmin = QLocale().toDouble( mXMinLineEdit->text(), &conversionSuccess );
974 if ( !conversionSuccess )
976 xmax = QLocale().toDouble( mXMaxLineEdit->text(), &conversionSuccess );
977 if ( !conversionSuccess )
979 ymin = QLocale().toDouble( mYMinLineEdit->text(), &conversionSuccess );
980 if ( !conversionSuccess )
982 ymax = QLocale().toDouble( mYMaxLineEdit->text(), &conversionSuccess );
983 if ( !conversionSuccess )
988 mMapItem->layout()->undoStack()->beginCommand( mMapItem, tr(
"Change Map Extent" ) );
989 mMapItem->setExtent( newExtent );
990 mMapItem->layout()->undoStack()->endCommand();
993void QgsLayoutMapWidget::blockAllSignals(
bool b )
995 mScaleLineEdit->blockSignals( b );
996 mXMinLineEdit->blockSignals( b );
997 mXMaxLineEdit->blockSignals( b );
998 mYMinLineEdit->blockSignals( b );
999 mYMaxLineEdit->blockSignals( b );
1000 mDrawCanvasItemsCheckBox->blockSignals( b );
1001 mOverviewFrameMapComboBox->blockSignals( b );
1002 mOverviewFrameStyleButton->blockSignals( b );
1003 mOverviewBlendModeComboBox->blockSignals( b );
1004 mOverviewInvertCheckbox->blockSignals( b );
1005 mOverviewCenterCheckbox->blockSignals( b );
1006 mAtlasCheckBox->blockSignals( b );
1007 mAtlasMarginSpinBox->blockSignals( b );
1008 mAtlasFixedScaleRadio->blockSignals( b );
1009 mAtlasMarginRadio->blockSignals( b );
1010 mFollowVisibilityPresetCheckBox->blockSignals( b );
1011 mFollowVisibilityPresetCombo->blockSignals( b );
1012 mKeepLayerListCheckBox->blockSignals( b );
1013 mKeepLayerStylesCheckBox->blockSignals( b );
1014 mActionSetToCanvasExtent->blockSignals( b );
1015 mActionUpdatePreview->blockSignals( b );
1016 mTemporalCheckBox->blockSignals( b );
1017 mStartDateTime->blockSignals( b );
1018 mEndDateTime->blockSignals( b );
1020 blockOverviewItemsSignals( b );
1023void QgsLayoutMapWidget::updatePreview()
1029 mMapItem->refresh();
1032void QgsLayoutMapWidget::mFollowVisibilityPresetCheckBox_stateChanged(
int state )
1039 mMapItem->layout()->undoStack()->beginCommand( mMapItem, tr(
"Change Map Preset" ) );
1040 if ( state == Qt::Checked )
1042 mMapItem->setFollowVisibilityPreset(
true );
1045 mKeepLayerListCheckBox->setCheckState( Qt::Unchecked );
1046 mKeepLayerStylesCheckBox->setCheckState( Qt::Unchecked );
1048 mMapItem->invalidateCache();
1052 mMapItem->setFollowVisibilityPreset(
false );
1054 mMapItem->layout()->undoStack()->endCommand();
1057void QgsLayoutMapWidget::mKeepLayerListCheckBox_stateChanged(
int state )
1065 mMapItem->layout()->undoStack()->beginCommand( mMapItem, tr(
"Map Preset Changed" ) );
1066 storeCurrentLayerSet();
1067 mMapItem->setKeepLayerSet( state == Qt::Checked );
1068 if ( state == Qt::Unchecked )
1070 mMapItem->setLayers( QList< QgsMapLayer * >() );
1072 mMapItem->layout()->undoStack()->endCommand();
1075 if ( state == Qt::Checked )
1078 mFollowVisibilityPresetCheckBox->setCheckState( Qt::Unchecked );
1082 mKeepLayerStylesCheckBox->setChecked( Qt::Unchecked );
1083 mMapItem->invalidateCache();
1086 mKeepLayerStylesCheckBox->setEnabled( state == Qt::Checked );
1089void QgsLayoutMapWidget::mKeepLayerStylesCheckBox_stateChanged(
int state )
1096 mMapItem->layout()->undoStack()->beginCommand( mMapItem, tr(
"Change Map Preset" ) );
1097 if ( state == Qt::Checked )
1099 mMapItem->storeCurrentLayerStyles();
1100 mMapItem->setKeepLayerStyles(
true );
1104 mMapItem->setLayerStyleOverrides( QMap<QString, QString>() );
1105 mMapItem->setKeepLayerStyles(
false );
1107 mMapItem->layout()->undoStack()->endCommand();
1110void QgsLayoutMapWidget::mDrawCanvasItemsCheckBox_stateChanged(
int state )
1117 mMapItem->layout()->undoStack()->beginCommand( mMapItem, tr(
"Toggle Map Item" ) );
1118 mMapItem->setDrawAnnotations( state == Qt::Checked );
1119 mMapItem->invalidateCache();
1120 mMapItem->layout()->undoStack()->endCommand();
1123void QgsLayoutMapWidget::atlasLayerChanged(
QgsVectorLayer *layer )
1128 mAtlasCheckBox->setChecked(
false );
1129 mAtlasCheckBox->setEnabled(
false );
1134 mAtlasCheckBox->setEnabled(
true );
1138 if ( mAtlasCheckBox->isChecked() )
1139 toggleAtlasScalingOptionsByLayerType();
1142bool QgsLayoutMapWidget::hasPredefinedScales()
const
1147 if ( !hasProjectScales || scales.isEmpty() )
1152 return !scales.isEmpty() && !scales[0].isEmpty();
1157void QgsLayoutMapWidget::mAddGridPushButton_clicked()
1164 const QString itemName = tr(
"Grid %1" ).arg( mMapItem->grids()->size() + 1 );
1166 mMapItem->layout()->undoStack()->beginCommand( mMapItem, tr(
"Add Map Grid" ) );
1167 mMapItem->grids()->addGrid( grid );
1168 mMapItem->layout()->undoStack()->endCommand();
1169 mMapItem->updateBoundingRect();
1172 addGridListItem( grid->
id(), grid->
name() );
1173 mGridListWidget->setCurrentRow( 0 );
1174 mGridListWidget_currentItemChanged( mGridListWidget->currentItem(),
nullptr );
1177void QgsLayoutMapWidget::mRemoveGridPushButton_clicked()
1179 QListWidgetItem *item = mGridListWidget->currentItem();
1185 mMapItem->beginCommand( tr(
"Remove Grid" ) );
1186 mMapItem->grids()->removeGrid( item->data( Qt::UserRole ).toString() );
1187 QListWidgetItem *delItem = mGridListWidget->takeItem( mGridListWidget->row( item ) );
1189 mMapItem->endCommand();
1190 mMapItem->updateBoundingRect();
1194void QgsLayoutMapWidget::mGridUpButton_clicked()
1196 QListWidgetItem *item = mGridListWidget->currentItem();
1202 const int row = mGridListWidget->row( item );
1207 mGridListWidget->takeItem( row );
1208 mGridListWidget->insertItem( row - 1, item );
1209 mGridListWidget->setCurrentItem( item );
1210 mMapItem->beginCommand( tr(
"Move Grid Up" ) );
1211 mMapItem->grids()->moveGridUp( item->data( Qt::UserRole ).toString() );
1212 mMapItem->endCommand();
1216void QgsLayoutMapWidget::mGridDownButton_clicked()
1218 QListWidgetItem *item = mGridListWidget->currentItem();
1224 const int row = mGridListWidget->row( item );
1225 if ( mGridListWidget->count() <= row )
1229 mGridListWidget->takeItem( row );
1230 mGridListWidget->insertItem( row + 1, item );
1231 mGridListWidget->setCurrentItem( item );
1232 mMapItem->beginCommand( tr(
"Move Grid Down" ) );
1233 mMapItem->grids()->moveGridDown( item->data( Qt::UserRole ).toString() );
1234 mMapItem->endCommand();
1245 QListWidgetItem *item = mGridListWidget->currentItem();
1250 return mMapItem->grids()->grid( item->data( Qt::UserRole ).toString() );
1253void QgsLayoutMapWidget::mGridListWidget_currentItemChanged( QListWidgetItem *current, QListWidgetItem * )
1255 mGridPropertiesButton->setEnabled(
static_cast< bool >( current ) );
1258void QgsLayoutMapWidget::mGridListWidget_itemChanged( QListWidgetItem *item )
1271 mMapItem->beginCommand( tr(
"Rename Grid" ) );
1272 grid->
setName( item->text() );
1273 mMapItem->endCommand();
1276void QgsLayoutMapWidget::mGridPropertiesButton_clicked()
1293QListWidgetItem *QgsLayoutMapWidget::addGridListItem(
const QString &
id,
const QString &name )
1295 QListWidgetItem *item =
new QListWidgetItem( name,
nullptr );
1296 item->setData( Qt::UserRole,
id );
1297 item->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable );
1298 mGridListWidget->insertItem( 0, item );
1302void QgsLayoutMapWidget::loadGridEntries()
1305 QSet<QString> selectedIds;
1306 const QList<QListWidgetItem *> itemSelection = mGridListWidget->selectedItems();
1307 QList<QListWidgetItem *>::const_iterator sIt = itemSelection.constBegin();
1308 for ( ; sIt != itemSelection.constEnd(); ++sIt )
1310 selectedIds.insert( ( *sIt )->data( Qt::UserRole ).toString() );
1313 mGridListWidget->clear();
1319 const QList< QgsLayoutItemMapGrid * > grids = mMapItem->grids()->asList();
1320 QList< QgsLayoutItemMapGrid * >::const_iterator gridIt = grids.constBegin();
1321 for ( ; gridIt != grids.constEnd(); ++gridIt )
1323 QListWidgetItem *item = addGridListItem( ( *gridIt )->id(), ( *gridIt )->name() );
1324 if ( selectedIds.contains( ( *gridIt )->id() ) )
1326 item->setSelected(
true );
1327 mGridListWidget->setCurrentItem( item );
1331 if ( mGridListWidget->currentItem() )
1333 mGridListWidget_currentItemChanged( mGridListWidget->currentItem(),
nullptr );
1337 mGridListWidget_currentItemChanged(
nullptr,
nullptr );
1341void QgsLayoutMapWidget::mAddOverviewPushButton_clicked()
1348 const QString itemName = tr(
"Overview %1" ).arg( mMapItem->overviews()->size() + 1 );
1350 mMapItem->layout()->undoStack()->beginCommand( mMapItem, tr(
"Add Map Overview" ) );
1351 mMapItem->overviews()->addOverview( overview );
1352 mMapItem->layout()->undoStack()->endCommand();
1353 mMapItem->invalidateCache();
1355 addOverviewListItem( overview->
id(), overview->
name() );
1357 mOverviewListWidget->setCurrentRow( 0 );
1360void QgsLayoutMapWidget::mRemoveOverviewPushButton_clicked()
1362 QListWidgetItem *item = mOverviewListWidget->currentItem();
1367 mMapItem->beginCommand( tr(
"Remove Map Overview" ) );
1368 mMapItem->overviews()->removeOverview( item->data( Qt::UserRole ).toString() );
1369 mMapItem->endCommand();
1370 QListWidgetItem *delItem = mOverviewListWidget->takeItem( mOverviewListWidget->row( item ) );
1372 mMapItem->invalidateCache();
1375void QgsLayoutMapWidget::mOverviewUpButton_clicked()
1377 QListWidgetItem *item = mOverviewListWidget->currentItem();
1383 const int row = mOverviewListWidget->row( item );
1388 mOverviewListWidget->takeItem( row );
1389 mOverviewListWidget->insertItem( row - 1, item );
1390 mOverviewListWidget->setCurrentItem( item );
1391 mMapItem->beginCommand( tr(
"Move Overview Up" ) );
1392 mMapItem->overviews()->moveOverviewUp( item->data( Qt::UserRole ).toString() );
1393 mMapItem->endCommand();
1394 mMapItem->invalidateCache();
1397void QgsLayoutMapWidget::mOverviewDownButton_clicked()
1399 QListWidgetItem *item = mOverviewListWidget->currentItem();
1405 const int row = mOverviewListWidget->row( item );
1406 if ( mOverviewListWidget->count() <= row )
1410 mOverviewListWidget->takeItem( row );
1411 mOverviewListWidget->insertItem( row + 1, item );
1412 mOverviewListWidget->setCurrentItem( item );
1413 mMapItem->beginCommand( tr(
"Move Overview Down" ) );
1414 mMapItem->overviews()->moveOverviewDown( item->data( Qt::UserRole ).toString() );
1415 mMapItem->endCommand();
1416 mMapItem->invalidateCache();
1426 QListWidgetItem *item = mOverviewListWidget->currentItem();
1432 return mMapItem->overviews()->overview( item->data( Qt::UserRole ).toString() );
1435void QgsLayoutMapWidget::mOverviewListWidget_currentItemChanged( QListWidgetItem *current, QListWidgetItem *previous )
1437 Q_UNUSED( previous )
1440 mOverviewCheckBox->setEnabled(
false );
1444 mOverviewCheckBox->setEnabled(
true );
1445 setOverviewItems( mMapItem->overviews()->overview( current->data( Qt::UserRole ).toString() ) );
1448void QgsLayoutMapWidget::mOverviewListWidget_itemChanged( QListWidgetItem *item )
1461 mMapItem->beginCommand( QStringLiteral(
"Rename Overview" ) );
1462 overview->
setName( item->text() );
1463 mMapItem->endCommand();
1464 if ( item->isSelected() )
1467 mOverviewCheckBox->setTitle( tr(
"Draw \"%1\" overview" ).arg( overview->
name() ) );
1471void QgsLayoutMapWidget::setOverviewItemsEnabled(
bool enabled )
1473 mOverviewFrameMapLabel->setEnabled( enabled );
1474 mOverviewFrameMapComboBox->setEnabled( enabled );
1475 mOverviewFrameStyleLabel->setEnabled( enabled );
1476 mOverviewFrameStyleButton->setEnabled( enabled );
1477 mOverviewBlendModeLabel->setEnabled( enabled );
1478 mOverviewBlendModeComboBox->setEnabled( enabled );
1479 mOverviewInvertCheckbox->setEnabled( enabled );
1480 mOverviewCenterCheckbox->setEnabled( enabled );
1481 mOverviewPositionComboBox->setEnabled( enabled );
1487void QgsLayoutMapWidget::blockOverviewItemsSignals(
const bool block )
1489 mOverviewFrameMapComboBox->blockSignals( block );
1490 mOverviewFrameStyleButton->blockSignals( block );
1491 mOverviewBlendModeComboBox->blockSignals( block );
1492 mOverviewInvertCheckbox->blockSignals( block );
1493 mOverviewCenterCheckbox->blockSignals( block );
1494 mOverviewPositionComboBox->blockSignals( block );
1495 mOverviewStackingLayerComboBox->blockSignals( block );
1505 blockOverviewItemsSignals(
true );
1507 mOverviewCheckBox->setTitle( tr(
"Draw \"%1\" overview" ).arg( overview->
name() ) );
1508 mOverviewCheckBox->setChecked( overview->
enabled() );
1511 mOverviewFrameMapComboBox->setItem( overview->
linkedMap() );
1514 mOverviewBlendModeComboBox->setBlendMode( overview->
blendMode() );
1516 mOverviewInvertCheckbox->setChecked( overview->
inverted() );
1518 mOverviewCenterCheckbox->setChecked( overview->
centered() );
1520 mOverviewPositionComboBox->setCurrentIndex( mOverviewPositionComboBox->findData( overview->
stackingPosition() ) );
1521 mOverviewStackingLayerComboBox->setLayer( overview->
stackingLayer() );
1527 blockOverviewItemsSignals(
false );
1530void QgsLayoutMapWidget::storeCurrentLayerSet()
1537 mMapItem->setLayers( layers );
1539 if ( mMapItem->keepLayerStyles() )
1542 mMapItem->storeCurrentLayerStyles();
1546QList<QgsMapLayer *> QgsLayoutMapWidget::orderedPresetVisibleLayers(
const QString &name )
const
1551 QList<QgsMapLayer *> lst;
1555 if ( visibleIds.contains( layer->
id() ) )
1563QListWidgetItem *QgsLayoutMapWidget::addOverviewListItem(
const QString &
id,
const QString &name )
1565 QListWidgetItem *item =
new QListWidgetItem( name,
nullptr );
1566 item->setData( Qt::UserRole,
id );
1567 item->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable );
1568 mOverviewListWidget->insertItem( 0, item );
1572void QgsLayoutMapWidget::loadOverviewEntries()
1575 QSet<QString> selectedIds;
1576 const QList<QListWidgetItem *> itemSelection = mOverviewListWidget->selectedItems();
1577 QList<QListWidgetItem *>::const_iterator sIt = itemSelection.constBegin();
1578 for ( ; sIt != itemSelection.constEnd(); ++sIt )
1580 selectedIds.insert( ( *sIt )->data( Qt::UserRole ).toString() );
1583 mOverviewListWidget->clear();
1589 mOverviewFrameMapComboBox->setExceptedItemList( QList< QgsLayoutItem * >() << mMapItem );
1592 const QList< QgsLayoutItemMapOverview * > overviews = mMapItem->overviews()->asList();
1593 QList< QgsLayoutItemMapOverview * >::const_iterator overviewIt = overviews.constBegin();
1594 for ( ; overviewIt != overviews.constEnd(); ++overviewIt )
1596 QListWidgetItem *item = addOverviewListItem( ( *overviewIt )->id(), ( *overviewIt )->name() );
1597 if ( selectedIds.contains( ( *overviewIt )->id() ) )
1599 item->setSelected(
true );
1600 mOverviewListWidget->setCurrentItem( item );
1604 if ( mOverviewListWidget->currentItem() )
1606 mOverviewListWidget_currentItemChanged( mOverviewListWidget->currentItem(),
nullptr );
1610 mOverviewListWidget_currentItemChanged(
nullptr,
nullptr );
1614void QgsLayoutMapWidget::mOverviewCheckBox_toggled(
bool state )
1622 mMapItem->layout()->undoStack()->beginCommand( mMapItem, tr(
"Overview Display Toggled" ) );
1624 mMapItem->invalidateCache();
1625 mMapItem->layout()->undoStack()->endCommand();
1628void QgsLayoutMapWidget::overviewMapChanged(
QgsLayoutItem *item )
1640 mMapItem->beginCommand( tr(
"Change Overview Map" ) );
1642 mMapItem->invalidateCache();
1643 mMapItem->endCommand();
1646void QgsLayoutMapWidget::mOverviewBlendModeComboBox_currentIndexChanged(
int index )
1655 mMapItem->beginCommand( tr(
"Change Overview Blend Mode" ) );
1656 overview->
setBlendMode( mOverviewBlendModeComboBox->blendMode() );
1657 mMapItem->invalidateCache();
1658 mMapItem->endCommand();
1661void QgsLayoutMapWidget::mOverviewInvertCheckbox_toggled(
bool state )
1669 mMapItem->beginCommand( tr(
"Toggle Overview Inverted" ) );
1671 mMapItem->invalidateCache();
1672 mMapItem->endCommand();
1675void QgsLayoutMapWidget::mOverviewCenterCheckbox_toggled(
bool state )
1683 mMapItem->beginCommand( tr(
"Toggle Overview Centered" ) );
1685 mMapItem->invalidateCache();
1686 mMapItem->endCommand();
1689void QgsLayoutMapWidget::overviewStackingChanged(
int )
1697 mMapItem->beginCommand( tr(
"Change Overview Position" ) );
1699 mMapItem->invalidateCache();
1700 mMapItem->endCommand();
1707 mOverviewStackingLayerComboBox->setEnabled(
false );
1712 mOverviewStackingLayerComboBox->setEnabled(
true );
1717void QgsLayoutMapWidget::overviewStackingLayerChanged(
QgsMapLayer *layer )
1725 mMapItem->beginCommand( tr(
"Change Overview Position" ) );
1727 mMapItem->invalidateCache();
1728 mMapItem->endCommand();
1742 mLabelBoundarySpinBox->setClearValue( 0 );
1743 mLabelBoundarySpinBox->setShowClearButton(
true );
1745 mLabelBoundaryUnitsCombo->linkToWidget( mLabelBoundarySpinBox );
1746 mLabelBoundaryUnitsCombo->setConverter( &mMapItem->layout()->renderContext().measurementConverter() );
1749 connect( mLabelBoundarySpinBox,
static_cast < void ( QDoubleSpinBox::* )(
double )
> ( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutMapLabelingWidget::labelMarginChanged );
1750 connect( mShowPartialLabelsCheckBox, &QCheckBox::toggled,
this, &QgsLayoutMapLabelingWidget::showPartialsToggled );
1751 connect( mShowUnplacedCheckBox, &QCheckBox::toggled,
this, &QgsLayoutMapLabelingWidget::showUnplacedToggled );
1768 mMapItem = qobject_cast< QgsLayoutItemMap * >( item );
1775 updateGuiElements();
1780void QgsLayoutMapLabelingWidget::updateGuiElements()
1782 whileBlocking( mLabelBoundarySpinBox )->setValue( mMapItem->labelMargin().length() );
1783 whileBlocking( mLabelBoundaryUnitsCombo )->setUnit( mMapItem->labelMargin().units() );
1787 if ( mBlockingItemsListView->model() )
1789 QAbstractItemModel *oldModel = mBlockingItemsListView->model();
1790 mBlockingItemsListView->setModel(
nullptr );
1791 oldModel->deleteLater();
1795 mBlockingItemsListView->setModel( model );
1800void QgsLayoutMapLabelingWidget::labelMarginChanged(
double val )
1807 mMapItem->layout()->undoStack()->endCommand();
1808 mMapItem->invalidateCache();
1811void QgsLayoutMapLabelingWidget::labelMarginUnitsChanged()
1817 mMapItem->setLabelMargin(
QgsLayoutMeasurement( mLabelBoundarySpinBox->value(), mLabelBoundaryUnitsCombo->unit() ) );
1818 mMapItem->layout()->undoStack()->endCommand();
1819 mMapItem->invalidateCache();
1822void QgsLayoutMapLabelingWidget::showPartialsToggled(
bool checked )
1827 mMapItem->layout()->undoStack()->beginCommand( mMapItem, tr(
"Change Label Visibility" ) );
1828 QgsLayoutItemMap::MapItemFlags flags = mMapItem->mapFlags();
1833 mMapItem->setMapFlags( flags );
1834 mMapItem->layout()->undoStack()->endCommand();
1835 mMapItem->invalidateCache();
1838void QgsLayoutMapLabelingWidget::showUnplacedToggled(
bool checked )
1843 mMapItem->layout()->undoStack()->beginCommand( mMapItem, tr(
"Change Label Visibility" ) );
1844 QgsLayoutItemMap::MapItemFlags flags = mMapItem->mapFlags();
1849 mMapItem->setMapFlags( flags );
1850 mMapItem->layout()->undoStack()->endCommand();
1851 mMapItem->invalidateCache();
1855 : QSortFilterProxyModel( parent )
1856 , mLayoutModel( layoutModel )
1859 setSourceModel( layoutModel );
1872 if ( i.column() != 0 )
1885 case Qt::CheckStateRole:
1886 switch ( i.column() )
1889 return mMapItem ? ( mMapItem->isLabelBlockingItem( item ) ? Qt::Checked : Qt::Unchecked ) : Qt::Unchecked;
1895 return mLayoutModel->
data( sourceIndex, role );
1903 if ( !index.isValid() )
1907 if ( !item || !mMapItem )
1912 mMapItem->layout()->undoStack()->beginCommand( mMapItem, tr(
"Change Label Blocking Items" ) );
1914 if ( value.toBool() )
1916 mMapItem->addLabelBlockingItem( item );
1920 mMapItem->removeLabelBlockingItem( item );
1922 emit dataChanged( index, index, QVector<int>() << role );
1924 mMapItem->layout()->undoStack()->endCommand();
1925 mMapItem->invalidateCache();
1932 Qt::ItemFlags
flags = QSortFilterProxyModel::flags( index );
1934 if ( ! index.isValid() )
1939 switch ( index.column() )
1942 return flags | Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsUserCheckable;
1944 return flags | Qt::ItemIsEnabled | Qt::ItemIsSelectable;
1951 if ( !item || item == mMapItem )
1974 mLayersTreeView->setModel( mLayerModel );
1980 for (
int i = 0; i < mAtlasClippingTypeComboBox->count(); ++i )
1982 mItemClippingTypeComboBox->addItem( mAtlasClippingTypeComboBox->itemText( i ), mAtlasClippingTypeComboBox->itemData( i ) );
1985 mClipItemComboBox->setCurrentLayout( map->
layout() );
1988 connect( mRadioClipSelectedLayers, &QRadioButton::toggled,
this, &QgsLayoutMapClippingWidget::toggleLayersSelectionGui );
1989 mLayersTreeView->setEnabled(
false );
1990 mSelectAllButton->setEnabled(
false );
1991 mDeselectAllButton->setEnabled(
false );
1992 mInvertSelectionButton->setEnabled(
false );
1993 mRadioClipAllLayers->setChecked(
true );
1995 connect( mClipToAtlasCheckBox, &QGroupBox::toggled,
this, [ = ](
bool active )
1997 if ( !mBlockUpdates )
1999 mMapItem->beginCommand( tr(
"Toggle Atlas Clipping" ) );
2000 mMapItem->atlasClippingSettings()->setEnabled( active );
2001 mMapItem->endCommand();
2004 connect( mForceLabelsInsideCheckBox, &QCheckBox::toggled,
this, [ = ](
bool active )
2006 if ( !mBlockUpdates )
2008 mMapItem->beginCommand( tr(
"Change Atlas Clipping Label Behavior" ) );
2009 mMapItem->atlasClippingSettings()->setForceLabelsInsideFeature( active );
2010 mMapItem->endCommand();
2013 connect( mAtlasClippingTypeComboBox, qOverload<int>( &QComboBox::currentIndexChanged ),
this, [ = ]
2015 if ( !mBlockUpdates )
2017 mMapItem->beginCommand( tr(
"Change Atlas Clipping Behavior" ) );
2019 mMapItem->endCommand();
2023 connect( mRadioClipSelectedLayers, &QCheckBox::toggled,
this, [ = ](
bool active )
2025 if ( active && !mBlockUpdates )
2027 mBlockUpdates =
true;
2028 mMapItem->beginCommand( tr(
"Change Atlas Clipping Layers" ) );
2029 mMapItem->atlasClippingSettings()->setRestrictToLayers(
true );
2030 mMapItem->endCommand();
2031 mBlockUpdates =
false;
2035 connect( mSelectAllButton, &QPushButton::clicked,
this, &QgsLayoutMapClippingWidget::selectAll );
2036 connect( mDeselectAllButton, &QPushButton::clicked,
this, &QgsLayoutMapClippingWidget::deselectAll );
2037 connect( mInvertSelectionButton, &QPushButton::clicked,
this, &QgsLayoutMapClippingWidget::invertSelection );
2039 connect( mRadioClipAllLayers, &QCheckBox::toggled,
this, [ = ](
bool active )
2041 if ( active && !mBlockUpdates )
2043 mBlockUpdates =
true;
2044 mMapItem->beginCommand( tr(
"Change Atlas Clipping Layers" ) );
2045 mMapItem->atlasClippingSettings()->setRestrictToLayers(
false );
2046 mMapItem->endCommand();
2047 mBlockUpdates =
false;
2050 connect( mLayerModel, &QgsMapLayerModel::dataChanged,
this, [ = ](
const QModelIndex &,
const QModelIndex &,
const QVector<int> &roles = QVector<int>() )
2052 if ( !roles.contains( Qt::CheckStateRole ) )
2055 if ( !mBlockUpdates )
2057 mBlockUpdates =
true;
2058 mMapItem->beginCommand( tr(
"Change Atlas Clipping Layers" ) );
2059 mMapItem->atlasClippingSettings()->setLayersToClip( mLayerModel->
layersChecked() );
2060 mMapItem->endCommand();
2061 mBlockUpdates =
false;
2067 connect( mClipToItemCheckBox, &QGroupBox::toggled,
this, [ = ](
bool active )
2069 if ( !mBlockUpdates )
2071 mMapItem->beginCommand( tr(
"Toggle Map Clipping" ) );
2072 mMapItem->itemClippingSettings()->setEnabled( active );
2073 mMapItem->endCommand();
2076 connect( mItemClippingTypeComboBox, qOverload<int>( &QComboBox::currentIndexChanged ),
this, [ = ]
2078 if ( !mBlockUpdates )
2080 mMapItem->beginCommand( tr(
"Change Map Clipping Behavior" ) );
2082 mMapItem->endCommand();
2085 connect( mForceLabelsInsideItemCheckBox, &QCheckBox::toggled,
this, [ = ](
bool active )
2087 if ( !mBlockUpdates )
2089 mMapItem->beginCommand( tr(
"Change Map Clipping Label Behavior" ) );
2090 mMapItem->itemClippingSettings()->setForceLabelsInsideClipPath( active );
2091 mMapItem->endCommand();
2096 if ( !mBlockUpdates )
2098 mMapItem->beginCommand( tr(
"Change Map Clipping Item" ) );
2099 mMapItem->itemClippingSettings()->setSourceItem( item );
2100 mMapItem->endCommand();
2107 this, &QgsLayoutMapClippingWidget::atlasLayerChanged );
2111 atlasToggled( atlas->enabled() );
2117 mClipToAtlasCheckBox->setTitle( tr(
"Clip to %1 feature" ).arg(
string ) );
2118 mClipToAtlasLabel->setText( tr(
"<b>When enabled, map layers will be automatically clipped to the boundary of the current %1 feature.</b>" ).arg(
string ) );
2119 mForceLabelsInsideCheckBox->setText( tr(
"Force labels inside %1 feature" ).arg(
string ) );
2132 mMapItem = qobject_cast< QgsLayoutItemMap * >( item );
2139 updateGuiElements();
2144void QgsLayoutMapClippingWidget::updateGuiElements()
2146 if ( mBlockUpdates )
2149 mBlockUpdates =
true;
2150 mClipToAtlasCheckBox->setChecked( mMapItem->atlasClippingSettings()->enabled() );
2151 mAtlasClippingTypeComboBox->setCurrentIndex( mAtlasClippingTypeComboBox->findData(
static_cast< int >( mMapItem->atlasClippingSettings()->featureClippingType() ) ) );
2152 mForceLabelsInsideCheckBox->setChecked( mMapItem->atlasClippingSettings()->forceLabelsInsideFeature() );
2154 mRadioClipAllLayers->setChecked( !mMapItem->atlasClippingSettings()->restrictToLayers() );
2155 mRadioClipSelectedLayers->setChecked( mMapItem->atlasClippingSettings()->restrictToLayers() );
2156 mLayerModel->
setLayersChecked( mMapItem->atlasClippingSettings()->layersToClip() );
2158 mClipToItemCheckBox->setChecked( mMapItem->itemClippingSettings()->enabled() );
2159 mItemClippingTypeComboBox->setCurrentIndex( mItemClippingTypeComboBox->findData(
static_cast< int >( mMapItem->itemClippingSettings()->featureClippingType() ) ) );
2160 mForceLabelsInsideItemCheckBox->setChecked( mMapItem->itemClippingSettings()->forceLabelsInsideClipPath() );
2161 mClipItemComboBox->setItem( mMapItem->itemClippingSettings()->sourceItem() );
2163 mBlockUpdates =
false;
2166void QgsLayoutMapClippingWidget::atlasLayerChanged(
QgsVectorLayer *layer )
2171 mClipToAtlasCheckBox->setChecked(
false );
2172 mClipToAtlasCheckBox->setEnabled(
false );
2177 mClipToAtlasCheckBox->setEnabled(
true );
2181void QgsLayoutMapClippingWidget::atlasToggled(
bool atlasEnabled )
2183 if ( atlasEnabled &&
2184 mMapItem && mMapItem->layout() && mMapItem->layout()->reportContext().layer()
2187 mClipToAtlasCheckBox->setEnabled(
true );
2191 mClipToAtlasCheckBox->setEnabled(
false );
2192 mClipToAtlasCheckBox->setChecked(
false );
2196void QgsLayoutMapClippingWidget::invertSelection()
2198 for (
int i = 0; i < mLayerModel->
rowCount( QModelIndex() ); i++ )
2200 QModelIndex index = mLayerModel->
index( i, 0 );
2201 Qt::CheckState currentState = Qt::CheckState( mLayerModel->
data( index, Qt::CheckStateRole ).toInt() );
2202 Qt::CheckState newState = ( currentState == Qt::Checked ) ? Qt::Unchecked : Qt::Checked;
2203 mLayerModel->
setData( index, newState, Qt::CheckStateRole );
2207void QgsLayoutMapClippingWidget::selectAll()
2209 for (
int i = 0; i < mLayerModel->
rowCount( QModelIndex() ); i++ )
2211 QModelIndex index = mLayerModel->
index( i, 0 );
2212 mLayerModel->
setData( index, Qt::Checked, Qt::CheckStateRole );
2216void QgsLayoutMapClippingWidget::deselectAll()
2218 for (
int i = 0; i < mLayerModel->
rowCount( QModelIndex() ); i++ )
2220 QModelIndex index = mLayerModel->
index( i, 0 );
2221 mLayerModel->
setData( index, Qt::Unchecked, Qt::CheckStateRole );
2225void QgsLayoutMapClippingWidget::toggleLayersSelectionGui(
bool toggled )
2227 mLayersTreeView->setEnabled( toggled );
2228 mSelectAllButton->setEnabled( toggled );
2229 mDeselectAllButton->setEnabled( toggled );
2230 mInvertSelectionButton->setEnabled( toggled );
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.
@ Extent
Bookmark extent as a QgsReferencedRectangle.
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.
@ StartDateTime
Temporal range's start DateTime.
@ MapLayers
Map layer set.
@ MapRotation
Map rotation.
@ MapXMax
Map extent x maximum.
@ MapStylePreset
Layer and style map theme.
@ MapYMax
Map extent y maximum.
@ MapAtlasMargin
Map atlas margin.
@ EndDateTime
Temporal range's end DateTime.
@ MapXMin
Map extent x minimum.
@ MapLabelMargin
Map label margin.
@ OriginalValue
Return the original, user set value.
void layerChanged(QgsVectorLayer *layer)
Emitted when the context's layer is changed.
void unitChanged(Qgis::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)
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.
int rowCount(const QModelIndex &parent=QModelIndex()) const override
QList< QgsMapLayer * > layersChecked(Qt::CheckState checkState=Qt::Checked)
layersChecked returns the list of layers which are checked (or unchecked)
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const override
void setItemsCheckable(bool checkable)
setItemsCheckable defines if layers should be selectable in the widget
bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole) override
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.
QList< QgsMapLayer * > layers(bool expandGroupLayers=false) const
Returns the list of layers which will be rendered in the map.
QgsRectangle visibleExtent() const
Returns the actual extent derived from requested extent that takes output image size into account.
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.
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
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.
A rectangle specified with double values.
double xMinimum() const
Returns the x minimum value (left side of rectangle).
double yMinimum() const
Returns the y minimum value (bottom side of rectangle).
double xMaximum() const
Returns the x maximum value (right side of rectangle).
double yMaximum() const
Returns the y maximum value (top side of rectangle).
bool isEmpty() const
Returns true if the rectangle has no area.
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.
T value(const QString &dynamicKeyPart=QString()) const
Returns settings value.
static const QgsSettingsEntryStringList * settingsMapScales
This class is a composition of two QSettings instances:
Represents a vector layer which manages a vector based data sets.
Q_INVOKABLE Qgis::WkbType wkbType() const FINAL
Returns the WKBType or WKBUnknown in case of error.
Q_INVOKABLE Qgis::GeometryType geometryType() const
Returns point, line or polygon.
static Qgis::GeometryType geometryType(Qgis::WkbType type)
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.
QgsTemporalRange< QDateTime > QgsDateTimeRange
QgsRange which stores a range of date times.
const QgsCoordinateReferenceSystem & crs