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 QString presetName = action->text();
349 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 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;
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();
419 void QgsLayoutMapWidget::overviewSymbolChanged()
427 mMapItem->endCommand();
428 mMapItem->invalidateCache();
431 void QgsLayoutMapWidget::showLabelSettings()
435 if ( !mReportTypeString.isEmpty() )
436 mLabelWidget->setReportTypeString( mReportTypeString );
441 void QgsLayoutMapWidget::showClipSettings()
444 if ( !mReportTypeString.isEmpty() )
445 mClipWidget->setReportTypeString( mReportTypeString );
449 void QgsLayoutMapWidget::switchToMoveContentTool()
455 void 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 newExtent = xForm.transformBoundingBox( newExtent );
504 mMapItem->layout()->undoStack()->beginCommand( mMapItem, tr(
"Change Map Extent" ) );
505 mMapItem->zoomToExtent( newExtent );
506 mMapItem->layout()->undoStack()->endCommand();
508 destMenu->addAction( action );
511 QStringList groupKeys = groupMenus.keys();
512 groupKeys.sort( Qt::CaseInsensitive );
513 for (
int i = 0; i < groupKeys.count(); ++i )
515 if ( mBookmarkMenu->actions().value( i ) )
516 mBookmarkMenu->insertMenu( mBookmarkMenu->actions().at( i ), groupMenus.value( groupKeys.at( i ) ) );
518 mBookmarkMenu->addMenu( groupMenus.value( groupKeys.at( i ) ) );
522 void QgsLayoutMapWidget::mTemporalCheckBox_toggled(
bool checked )
529 mMapItem->layout()->undoStack()->beginCommand( mMapItem, tr(
"Toggle Temporal Range" ) );
530 mMapItem->setIsTemporal( checked );
531 mMapItem->layout()->undoStack()->endCommand();
535 whileBlocking( mStartDateTime )->setDateTime( mMapItem->temporalRange().begin() );
536 whileBlocking( mEndDateTime )->setDateTime( mMapItem->temporalRange().end() );
542 void QgsLayoutMapWidget::updateTemporalExtent()
549 const QDateTime begin = mStartDateTime->dateTime();
550 const QDateTime end = mEndDateTime->dateTime();
551 QgsDateTimeRange range = QgsDateTimeRange( begin, end,
true, begin == end );
553 mMapItem->layout()->undoStack()->beginCommand( mMapItem, tr(
"Set Temporal Range" ) );
554 mMapItem->setTemporalRange( range );
555 mMapItem->layout()->undoStack()->endCommand();
560 void QgsLayoutMapWidget::mAtlasCheckBox_toggled(
bool checked )
567 mAtlasFixedScaleRadio->setEnabled( checked );
568 mAtlasMarginRadio->setEnabled( checked );
570 if ( mAtlasMarginRadio->isEnabled() && mAtlasMarginRadio->isChecked() )
572 mAtlasMarginSpinBox->setEnabled(
true );
576 mAtlasMarginSpinBox->setEnabled(
false );
579 mAtlasPredefinedScaleRadio->setEnabled( checked );
584 if ( mMapItem->layout() )
586 toggleAtlasScalingOptionsByLayerType();
591 if ( !hasPredefinedScales() )
593 mAtlasPredefinedScaleRadio->setEnabled(
false );
596 mMapItem->layout()->undoStack()->beginCommand( mMapItem, tr(
"Set Atlas Driven" ) );
597 mMapItem->setAtlasDriven( checked );
598 mMapItem->layout()->undoStack()->endCommand();
602 void QgsLayoutMapWidget::updateMapForAtlas()
605 if ( mMapItem->atlasDriven() )
612 mMapItem->invalidateCache();
616 void QgsLayoutMapWidget::mAtlasMarginRadio_toggled(
bool checked )
618 mAtlasMarginSpinBox->setEnabled( checked );
620 if ( checked && mMapItem )
622 mMapItem->layout()->undoStack()->beginCommand( mMapItem, tr(
"Change Atlas Mode" ) );
624 mMapItem->layout()->undoStack()->endCommand();
629 void QgsLayoutMapWidget::mAtlasMarginSpinBox_valueChanged(
int value )
637 mMapItem->setAtlasMargin( value / 100. );
638 mMapItem->layout()->undoStack()->endCommand();
642 void QgsLayoutMapWidget::mAtlasFixedScaleRadio_toggled(
bool checked )
651 mMapItem->layout()->undoStack()->beginCommand( mMapItem, tr(
"Change Atlas Mode" ) );
653 mMapItem->layout()->undoStack()->endCommand();
658 void QgsLayoutMapWidget::mAtlasPredefinedScaleRadio_toggled(
bool checked )
665 if ( hasPredefinedScales() )
669 mMapItem->layout()->undoStack()->beginCommand( mMapItem, tr(
"Change Atlas Scales" ) );
671 mMapItem->layout()->undoStack()->endCommand();
679 mMapItem->layout()->undoStack()->beginCommand( mMapItem, tr(
"Change Atlas Mode" ) );
681 mMapItem->layout()->undoStack()->endCommand();
685 void QgsLayoutMapWidget::mScaleLineEdit_editingFinished()
692 bool conversionSuccess =
false;
693 double scaleDenominator = QLocale().toDouble( mScaleLineEdit->text(), &conversionSuccess );
694 if ( !conversionSuccess )
702 mMapItem->layout()->undoStack()->beginCommand( mMapItem, tr(
"Change Map Scale" ) );
703 mMapItem->setScale( scaleDenominator );
704 mMapItem->layout()->undoStack()->endCommand();
707 void QgsLayoutMapWidget::rotationChanged(
double value )
715 mMapItem->setMapRotation( value );
716 mMapItem->layout()->undoStack()->endCommand();
717 mMapItem->invalidateCache();
720 void QgsLayoutMapWidget::setToMapCanvasExtent()
737 newExtent = xForm.transformBoundingBox( newExtent );
746 mMapItem->layout()->undoStack()->beginCommand( mMapItem, tr(
"Change Map Extent" ) );
747 mMapItem->zoomToExtent( newExtent );
748 mMapItem->layout()->undoStack()->endCommand();
751 void QgsLayoutMapWidget::setToMapCanvasScale()
758 const double newScale = mMapCanvas->
scale();
760 mMapItem->layout()->undoStack()->beginCommand( mMapItem, tr(
"Change Map Scale" ) );
761 mMapItem->setScale( newScale );
762 mMapItem->layout()->undoStack()->endCommand();
765 void QgsLayoutMapWidget::viewExtentInCanvas()
774 if ( !currentMapExtent.
isEmpty() )
789 void QgsLayoutMapWidget::viewScaleInCanvas()
796 const double currentScale = mMapItem->scale();
797 mMapCanvas->
zoomScale( currentScale,
true );
800 void QgsLayoutMapWidget::mXMinLineEdit_editingFinished()
802 updateComposerExtentFromGui();
805 void QgsLayoutMapWidget::mXMaxLineEdit_editingFinished()
807 updateComposerExtentFromGui();
810 void QgsLayoutMapWidget::mYMinLineEdit_editingFinished()
812 updateComposerExtentFromGui();
815 void QgsLayoutMapWidget::mYMaxLineEdit_editingFinished()
817 updateComposerExtentFromGui();
820 void QgsLayoutMapWidget::updateGuiElements()
827 blockAllSignals(
true );
828 mLabel->setText( mMapItem->displayName() );
830 whileBlocking( mCrsSelector )->setCrs( mMapItem->presetCrs() );
833 double scale = mMapItem->scale();
836 if ( scale >= 10000 )
839 mScaleLineEdit->setText( QLocale().toString( mMapItem->scale(),
'f', 0 ) );
841 else if ( scale >= 10 )
843 mScaleLineEdit->setText( QLocale().toString( mMapItem->scale(),
'f', 3 ) );
845 else if ( scale >= 1 )
848 mScaleLineEdit->setText( QLocale().toString( mMapItem->scale(),
'f', 4 ) );
853 mScaleLineEdit->setText( QLocale().toString( mMapItem->scale(),
'f', 10 ) );
858 mXMinLineEdit->setText( QLocale().toString( composerMapExtent.
xMinimum(),
'f', 3 ) );
859 mXMaxLineEdit->setText( QLocale().toString( composerMapExtent.
xMaximum(),
'f', 3 ) );
860 mYMinLineEdit->setText( QLocale().toString( composerMapExtent.
yMinimum(),
'f', 3 ) );
861 mYMaxLineEdit->setText( QLocale().toString( composerMapExtent.
yMaximum(),
'f', 3 ) );
866 mFollowVisibilityPresetCheckBox->setCheckState(
867 mMapItem->followVisibilityPreset() ? Qt::Checked : Qt::Unchecked );
868 int presetModelIndex = mFollowVisibilityPresetCombo->findText( mMapItem->followVisibilityPresetName() );
869 mFollowVisibilityPresetCombo->setCurrentIndex( presetModelIndex != -1 ? presetModelIndex : 0 );
872 if ( mMapItem->keepLayerSet() )
874 mKeepLayerListCheckBox->setCheckState( Qt::Checked );
878 mKeepLayerListCheckBox->setCheckState( Qt::Unchecked );
881 mKeepLayerStylesCheckBox->setEnabled( mMapItem->keepLayerSet() );
882 mKeepLayerStylesCheckBox->setCheckState( mMapItem->keepLayerStyles() ? Qt::Checked : Qt::Unchecked );
885 if ( mMapItem->drawAnnotations() )
887 mDrawCanvasItemsCheckBox->setCheckState( Qt::Checked );
891 mDrawCanvasItemsCheckBox->setCheckState( Qt::Unchecked );
895 mAtlasCheckBox->setChecked( mMapItem->atlasDriven() );
898 mAtlasFixedScaleRadio->setEnabled( mMapItem->atlasDriven() );
901 mAtlasMarginRadio->setEnabled( mMapItem->atlasDriven() );
903 mAtlasPredefinedScaleRadio->setEnabled( mMapItem->atlasDriven() );
906 if ( mMapItem->atlasDriven() )
908 toggleAtlasScalingOptionsByLayerType();
911 if ( !hasPredefinedScales() )
913 mAtlasPredefinedScaleRadio->setEnabled(
false );
916 mTemporalCheckBox->setChecked( mMapItem->isTemporal() );
917 mTemporalCheckBox->setCollapsed( !mMapItem->isTemporal() );
918 mStartDateTime->setEnabled( mMapItem->isTemporal() );
919 mEndDateTime->setEnabled( mMapItem->isTemporal() );
920 if ( mMapItem->isTemporal() )
922 mStartDateTime->setDateTime( mMapItem->temporalRange().begin() );
923 mEndDateTime->setDateTime( mMapItem->temporalRange().end() );
928 loadOverviewEntries();
930 blockAllSignals(
false );
933 void QgsLayoutMapWidget::toggleAtlasScalingOptionsByLayerType()
950 mAtlasFixedScaleRadio->setChecked(
true );
951 mAtlasMarginRadio->setEnabled(
false );
952 mAtlasPredefinedScaleRadio->setEnabled(
false );
957 mAtlasMarginRadio->setEnabled(
true );
958 mAtlasPredefinedScaleRadio->setEnabled(
true );
962 void QgsLayoutMapWidget::updateComposerExtentFromGui()
969 double xmin, ymin, xmax, ymax;
970 bool conversionSuccess;
972 xmin = QLocale().toDouble( mXMinLineEdit->text(), &conversionSuccess );
973 if ( !conversionSuccess )
975 xmax = QLocale().toDouble( mXMaxLineEdit->text(), &conversionSuccess );
976 if ( !conversionSuccess )
978 ymin = QLocale().toDouble( mYMinLineEdit->text(), &conversionSuccess );
979 if ( !conversionSuccess )
981 ymax = QLocale().toDouble( mYMaxLineEdit->text(), &conversionSuccess );
982 if ( !conversionSuccess )
987 mMapItem->layout()->undoStack()->beginCommand( mMapItem, tr(
"Change Map Extent" ) );
988 mMapItem->setExtent( newExtent );
989 mMapItem->layout()->undoStack()->endCommand();
992 void QgsLayoutMapWidget::blockAllSignals(
bool b )
994 mScaleLineEdit->blockSignals( b );
995 mXMinLineEdit->blockSignals( b );
996 mXMaxLineEdit->blockSignals( b );
997 mYMinLineEdit->blockSignals( b );
998 mYMaxLineEdit->blockSignals( b );
999 mDrawCanvasItemsCheckBox->blockSignals( b );
1000 mOverviewFrameMapComboBox->blockSignals( b );
1001 mOverviewFrameStyleButton->blockSignals( b );
1002 mOverviewBlendModeComboBox->blockSignals( b );
1003 mOverviewInvertCheckbox->blockSignals( b );
1004 mOverviewCenterCheckbox->blockSignals( b );
1005 mAtlasCheckBox->blockSignals( b );
1006 mAtlasMarginSpinBox->blockSignals( b );
1007 mAtlasFixedScaleRadio->blockSignals( b );
1008 mAtlasMarginRadio->blockSignals( b );
1009 mFollowVisibilityPresetCheckBox->blockSignals( b );
1010 mFollowVisibilityPresetCombo->blockSignals( b );
1011 mKeepLayerListCheckBox->blockSignals( b );
1012 mKeepLayerStylesCheckBox->blockSignals( b );
1013 mActionSetToCanvasExtent->blockSignals( b );
1014 mActionUpdatePreview->blockSignals( b );
1015 mTemporalCheckBox->blockSignals( b );
1016 mStartDateTime->blockSignals( b );
1017 mEndDateTime->blockSignals( b );
1019 blockOverviewItemsSignals( b );
1022 void QgsLayoutMapWidget::updatePreview()
1028 mMapItem->refresh();
1031 void QgsLayoutMapWidget::mFollowVisibilityPresetCheckBox_stateChanged(
int state )
1038 mMapItem->layout()->undoStack()->beginCommand( mMapItem, tr(
"Change Map Preset" ) );
1039 if ( state == Qt::Checked )
1041 mMapItem->setFollowVisibilityPreset(
true );
1044 mKeepLayerListCheckBox->setCheckState( Qt::Unchecked );
1045 mKeepLayerStylesCheckBox->setCheckState( Qt::Unchecked );
1047 mMapItem->invalidateCache();
1051 mMapItem->setFollowVisibilityPreset(
false );
1053 mMapItem->layout()->undoStack()->endCommand();
1056 void QgsLayoutMapWidget::mKeepLayerListCheckBox_stateChanged(
int state )
1064 mMapItem->layout()->undoStack()->beginCommand( mMapItem, tr(
"Map Preset Changed" ) );
1065 storeCurrentLayerSet();
1066 mMapItem->setKeepLayerSet( state == Qt::Checked );
1067 if ( state == Qt::Unchecked )
1069 mMapItem->setLayers( QList< QgsMapLayer * >() );
1071 mMapItem->layout()->undoStack()->endCommand();
1074 if ( state == Qt::Checked )
1077 mFollowVisibilityPresetCheckBox->setCheckState( Qt::Unchecked );
1081 mKeepLayerStylesCheckBox->setChecked( Qt::Unchecked );
1082 mMapItem->invalidateCache();
1085 mKeepLayerStylesCheckBox->setEnabled( state == Qt::Checked );
1088 void QgsLayoutMapWidget::mKeepLayerStylesCheckBox_stateChanged(
int state )
1095 mMapItem->layout()->undoStack()->beginCommand( mMapItem, tr(
"Change Map Preset" ) );
1096 if ( state == Qt::Checked )
1098 mMapItem->storeCurrentLayerStyles();
1099 mMapItem->setKeepLayerStyles(
true );
1103 mMapItem->setLayerStyleOverrides( QMap<QString, QString>() );
1104 mMapItem->setKeepLayerStyles(
false );
1106 mMapItem->layout()->undoStack()->endCommand();
1109 void QgsLayoutMapWidget::mDrawCanvasItemsCheckBox_stateChanged(
int state )
1116 mMapItem->layout()->undoStack()->beginCommand( mMapItem, tr(
"Toggle Map Item" ) );
1117 mMapItem->setDrawAnnotations( state == Qt::Checked );
1118 mMapItem->invalidateCache();
1119 mMapItem->layout()->undoStack()->endCommand();
1122 void QgsLayoutMapWidget::atlasLayerChanged(
QgsVectorLayer *layer )
1127 mAtlasCheckBox->setChecked(
false );
1128 mAtlasCheckBox->setEnabled(
false );
1133 mAtlasCheckBox->setEnabled(
true );
1137 if ( mAtlasCheckBox->isChecked() )
1138 toggleAtlasScalingOptionsByLayerType();
1141 bool QgsLayoutMapWidget::hasPredefinedScales()
const
1146 if ( !hasProjectScales || scales.isEmpty() )
1149 QgsSettings settings;
1151 QStringList myScalesList = scalesStr.split(
',' );
1152 return !myScalesList.isEmpty() && !myScalesList[0].isEmpty();
1157 void QgsLayoutMapWidget::mAddGridPushButton_clicked()
1164 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 );
1177 void 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();
1194 void QgsLayoutMapWidget::mGridUpButton_clicked()
1196 QListWidgetItem *item = mGridListWidget->currentItem();
1202 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();
1216 void QgsLayoutMapWidget::mGridDownButton_clicked()
1218 QListWidgetItem *item = mGridListWidget->currentItem();
1224 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() );
1253 void QgsLayoutMapWidget::mGridListWidget_currentItemChanged( QListWidgetItem *current, QListWidgetItem * )
1255 mGridPropertiesButton->setEnabled(
static_cast< bool >( current ) );
1258 void QgsLayoutMapWidget::mGridListWidget_itemChanged( QListWidgetItem *item )
1271 mMapItem->beginCommand( tr(
"Rename Grid" ) );
1272 grid->
setName( item->text() );
1273 mMapItem->endCommand();
1276 void QgsLayoutMapWidget::mGridPropertiesButton_clicked()
1293 QListWidgetItem *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 );
1302 void QgsLayoutMapWidget::loadGridEntries()
1305 QSet<QString> selectedIds;
1306 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 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 );
1341 void QgsLayoutMapWidget::mAddOverviewPushButton_clicked()
1348 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 );
1360 void 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();
1375 void QgsLayoutMapWidget::mOverviewUpButton_clicked()
1377 QListWidgetItem *item = mOverviewListWidget->currentItem();
1383 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();
1397 void QgsLayoutMapWidget::mOverviewDownButton_clicked()
1399 QListWidgetItem *item = mOverviewListWidget->currentItem();
1405 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() );
1435 void 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() ) );
1448 void 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() ) );
1471 void 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 );
1487 void 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 );
1530 void QgsLayoutMapWidget::storeCurrentLayerSet()
1536 mMapItem->setLayers( layers );
1538 if ( mMapItem->keepLayerStyles() )
1541 mMapItem->storeCurrentLayerStyles();
1545 QList<QgsMapLayer *> QgsLayoutMapWidget::orderedPresetVisibleLayers(
const QString &name )
const
1550 QList<QgsMapLayer *> lst;
1554 if ( visibleIds.contains( layer->
id() ) )
1562 QListWidgetItem *QgsLayoutMapWidget::addOverviewListItem(
const QString &
id,
const QString &name )
1564 QListWidgetItem *item =
new QListWidgetItem( name,
nullptr );
1565 item->setData( Qt::UserRole,
id );
1566 item->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable );
1567 mOverviewListWidget->insertItem( 0, item );
1571 void QgsLayoutMapWidget::loadOverviewEntries()
1574 QSet<QString> selectedIds;
1575 QList<QListWidgetItem *> itemSelection = mOverviewListWidget->selectedItems();
1576 QList<QListWidgetItem *>::const_iterator sIt = itemSelection.constBegin();
1577 for ( ; sIt != itemSelection.constEnd(); ++sIt )
1579 selectedIds.insert( ( *sIt )->data( Qt::UserRole ).toString() );
1582 mOverviewListWidget->clear();
1588 mOverviewFrameMapComboBox->setExceptedItemList( QList< QgsLayoutItem * >() << mMapItem );
1591 QList< QgsLayoutItemMapOverview * > overviews = mMapItem->overviews()->asList();
1592 QList< QgsLayoutItemMapOverview * >::const_iterator overviewIt = overviews.constBegin();
1593 for ( ; overviewIt != overviews.constEnd(); ++overviewIt )
1595 QListWidgetItem *item = addOverviewListItem( ( *overviewIt )->id(), ( *overviewIt )->name() );
1596 if ( selectedIds.contains( ( *overviewIt )->id() ) )
1598 item->setSelected(
true );
1599 mOverviewListWidget->setCurrentItem( item );
1603 if ( mOverviewListWidget->currentItem() )
1605 mOverviewListWidget_currentItemChanged( mOverviewListWidget->currentItem(),
nullptr );
1609 mOverviewListWidget_currentItemChanged(
nullptr,
nullptr );
1613 void QgsLayoutMapWidget::mOverviewCheckBox_toggled(
bool state )
1621 mMapItem->layout()->undoStack()->beginCommand( mMapItem, tr(
"Overview Display Toggled" ) );
1623 mMapItem->invalidateCache();
1624 mMapItem->layout()->undoStack()->endCommand();
1627 void QgsLayoutMapWidget::overviewMapChanged(
QgsLayoutItem *item )
1639 mMapItem->beginCommand( tr(
"Change Overview Map" ) );
1641 mMapItem->invalidateCache();
1642 mMapItem->endCommand();
1645 void QgsLayoutMapWidget::mOverviewBlendModeComboBox_currentIndexChanged(
int index )
1654 mMapItem->beginCommand( tr(
"Change Overview Blend Mode" ) );
1655 overview->
setBlendMode( mOverviewBlendModeComboBox->blendMode() );
1656 mMapItem->invalidateCache();
1657 mMapItem->endCommand();
1660 void QgsLayoutMapWidget::mOverviewInvertCheckbox_toggled(
bool state )
1668 mMapItem->beginCommand( tr(
"Toggle Overview Inverted" ) );
1670 mMapItem->invalidateCache();
1671 mMapItem->endCommand();
1674 void QgsLayoutMapWidget::mOverviewCenterCheckbox_toggled(
bool state )
1682 mMapItem->beginCommand( tr(
"Toggle Overview Centered" ) );
1684 mMapItem->invalidateCache();
1685 mMapItem->endCommand();
1688 void QgsLayoutMapWidget::overviewStackingChanged(
int )
1696 mMapItem->beginCommand( tr(
"Change Overview Position" ) );
1698 mMapItem->invalidateCache();
1699 mMapItem->endCommand();
1706 mOverviewStackingLayerComboBox->setEnabled(
false );
1711 mOverviewStackingLayerComboBox->setEnabled(
true );
1716 void QgsLayoutMapWidget::overviewStackingLayerChanged(
QgsMapLayer *layer )
1724 mMapItem->beginCommand( tr(
"Change Overview Position" ) );
1726 mMapItem->invalidateCache();
1727 mMapItem->endCommand();
1741 mLabelBoundarySpinBox->setClearValue( 0 );
1742 mLabelBoundarySpinBox->setShowClearButton(
true );
1744 mLabelBoundaryUnitsCombo->linkToWidget( mLabelBoundarySpinBox );
1745 mLabelBoundaryUnitsCombo->setConverter( &mMapItem->layout()->renderContext().measurementConverter() );
1748 connect( mLabelBoundarySpinBox,
static_cast < void ( QDoubleSpinBox::* )(
double )
> ( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutMapLabelingWidget::labelMarginChanged );
1749 connect( mShowPartialLabelsCheckBox, &QCheckBox::toggled,
this, &QgsLayoutMapLabelingWidget::showPartialsToggled );
1750 connect( mShowUnplacedCheckBox, &QCheckBox::toggled,
this, &QgsLayoutMapLabelingWidget::showUnplacedToggled );
1767 mMapItem = qobject_cast< QgsLayoutItemMap * >( item );
1774 updateGuiElements();
1779 void QgsLayoutMapLabelingWidget::updateGuiElements()
1781 whileBlocking( mLabelBoundarySpinBox )->setValue( mMapItem->labelMargin().length() );
1782 whileBlocking( mLabelBoundaryUnitsCombo )->setUnit( mMapItem->labelMargin().units() );
1786 if ( mBlockingItemsListView->model() )
1788 QAbstractItemModel *oldModel = mBlockingItemsListView->model();
1789 mBlockingItemsListView->setModel(
nullptr );
1790 oldModel->deleteLater();
1794 mBlockingItemsListView->setModel( model );
1799 void QgsLayoutMapLabelingWidget::labelMarginChanged(
double val )
1806 mMapItem->layout()->undoStack()->endCommand();
1807 mMapItem->invalidateCache();
1810 void QgsLayoutMapLabelingWidget::labelMarginUnitsChanged()
1816 mMapItem->setLabelMargin(
QgsLayoutMeasurement( mLabelBoundarySpinBox->value(), mLabelBoundaryUnitsCombo->unit() ) );
1817 mMapItem->layout()->undoStack()->endCommand();
1818 mMapItem->invalidateCache();
1821 void QgsLayoutMapLabelingWidget::showPartialsToggled(
bool checked )
1826 mMapItem->layout()->undoStack()->beginCommand( mMapItem, tr(
"Change Label Visibility" ) );
1827 QgsLayoutItemMap::MapItemFlags flags = mMapItem->mapFlags();
1832 mMapItem->setMapFlags( flags );
1833 mMapItem->layout()->undoStack()->endCommand();
1834 mMapItem->invalidateCache();
1837 void QgsLayoutMapLabelingWidget::showUnplacedToggled(
bool checked )
1842 mMapItem->layout()->undoStack()->beginCommand( mMapItem, tr(
"Change Label Visibility" ) );
1843 QgsLayoutItemMap::MapItemFlags flags = mMapItem->mapFlags();
1848 mMapItem->setMapFlags( flags );
1849 mMapItem->layout()->undoStack()->endCommand();
1850 mMapItem->invalidateCache();
1854 : QSortFilterProxyModel( parent )
1855 , mLayoutModel( layoutModel )
1858 setSourceModel( layoutModel );
1871 if ( i.column() != 0 )
1884 case Qt::CheckStateRole:
1885 switch ( i.column() )
1888 return mMapItem ? ( mMapItem->isLabelBlockingItem( item ) ? Qt::Checked : Qt::Unchecked ) : Qt::Unchecked;
1894 return mLayoutModel->
data( sourceIndex, role );
1902 if ( !index.isValid() )
1906 if ( !item || !mMapItem )
1911 mMapItem->layout()->undoStack()->beginCommand( mMapItem, tr(
"Change Label Blocking Items" ) );
1913 if ( value.toBool() )
1915 mMapItem->addLabelBlockingItem( item );
1919 mMapItem->removeLabelBlockingItem( item );
1921 emit dataChanged( index, index, QVector<int>() << role );
1923 mMapItem->layout()->undoStack()->endCommand();
1924 mMapItem->invalidateCache();
1931 Qt::ItemFlags
flags = QAbstractItemModel::flags( index );
1933 if ( ! index.isValid() )
1938 switch ( index.column() )
1941 return flags | Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsUserCheckable;
1943 return flags | Qt::ItemIsEnabled | Qt::ItemIsSelectable;
1950 if ( !item || item == mMapItem )
1973 mLayersTreeView->setModel( mLayerModel );
1979 for (
int i = 0; i < mAtlasClippingTypeComboBox->count(); ++i )
1981 mItemClippingTypeComboBox->addItem( mAtlasClippingTypeComboBox->itemText( i ), mAtlasClippingTypeComboBox->itemData( i ) );
1984 mClipItemComboBox->setCurrentLayout( map->
layout() );
1987 connect( mRadioClipSelectedLayers, &QRadioButton::toggled, mLayersTreeView, &QWidget::setEnabled );
1988 mLayersTreeView->setEnabled(
false );
1989 mRadioClipAllLayers->setChecked(
true );
1991 connect( mClipToAtlasCheckBox, &QGroupBox::toggled,
this, [ = ](
bool active )
1993 if ( !mBlockUpdates )
1995 mMapItem->beginCommand( tr(
"Toggle Atlas Clipping" ) );
1996 mMapItem->atlasClippingSettings()->setEnabled( active );
1997 mMapItem->endCommand();
2000 connect( mForceLabelsInsideCheckBox, &QCheckBox::toggled,
this, [ = ](
bool active )
2002 if ( !mBlockUpdates )
2004 mMapItem->beginCommand( tr(
"Change Atlas Clipping Label Behavior" ) );
2005 mMapItem->atlasClippingSettings()->setForceLabelsInsideFeature( active );
2006 mMapItem->endCommand();
2009 connect( mAtlasClippingTypeComboBox, qOverload<int>( &QComboBox::currentIndexChanged ),
this, [ = ]
2011 if ( !mBlockUpdates )
2013 mMapItem->beginCommand( tr(
"Change Atlas Clipping Behavior" ) );
2015 mMapItem->endCommand();
2019 connect( mRadioClipSelectedLayers, &QCheckBox::toggled,
this, [ = ](
bool active )
2021 if ( active && !mBlockUpdates )
2023 mBlockUpdates =
true;
2024 mMapItem->beginCommand( tr(
"Change Atlas Clipping Layers" ) );
2025 mMapItem->atlasClippingSettings()->setRestrictToLayers(
true );
2026 mMapItem->endCommand();
2027 mBlockUpdates =
false;
2030 connect( mRadioClipAllLayers, &QCheckBox::toggled,
this, [ = ](
bool active )
2032 if ( active && !mBlockUpdates )
2034 mBlockUpdates =
true;
2035 mMapItem->beginCommand( tr(
"Change Atlas Clipping Layers" ) );
2036 mMapItem->atlasClippingSettings()->setRestrictToLayers(
false );
2037 mMapItem->endCommand();
2038 mBlockUpdates =
false;
2041 connect( mLayerModel, &QgsMapLayerModel::dataChanged,
this, [ = ](
const QModelIndex &,
const QModelIndex &,
const QVector<int> &roles = QVector<int>() )
2043 if ( !roles.contains( Qt::CheckStateRole ) )
2046 if ( !mBlockUpdates )
2048 mBlockUpdates =
true;
2049 mMapItem->beginCommand( tr(
"Change Atlas Clipping Layers" ) );
2050 mMapItem->atlasClippingSettings()->setLayersToClip( mLayerModel->
layersChecked() );
2051 mMapItem->endCommand();
2052 mBlockUpdates =
false;
2058 connect( mClipToItemCheckBox, &QGroupBox::toggled,
this, [ = ](
bool active )
2060 if ( !mBlockUpdates )
2062 mMapItem->beginCommand( tr(
"Toggle Map Clipping" ) );
2063 mMapItem->itemClippingSettings()->setEnabled( active );
2064 mMapItem->endCommand();
2067 connect( mItemClippingTypeComboBox, qOverload<int>( &QComboBox::currentIndexChanged ),
this, [ = ]
2069 if ( !mBlockUpdates )
2071 mMapItem->beginCommand( tr(
"Change Map Clipping Behavior" ) );
2073 mMapItem->endCommand();
2076 connect( mForceLabelsInsideItemCheckBox, &QCheckBox::toggled,
this, [ = ](
bool active )
2078 if ( !mBlockUpdates )
2080 mMapItem->beginCommand( tr(
"Change Map Clipping Label Behavior" ) );
2081 mMapItem->itemClippingSettings()->setForceLabelsInsideClipPath( active );
2082 mMapItem->endCommand();
2087 if ( !mBlockUpdates )
2089 mMapItem->beginCommand( tr(
"Change Map Clipping Item" ) );
2090 mMapItem->itemClippingSettings()->setSourceItem( item );
2091 mMapItem->endCommand();
2098 this, &QgsLayoutMapClippingWidget::atlasLayerChanged );
2102 atlasToggled( atlas->enabled() );
2108 mClipToAtlasCheckBox->setTitle( tr(
"Clip to %1 feature" ).arg(
string ) );
2109 mClipToAtlasLabel->setText( tr(
"<b>When enabled, map layers will be automatically clipped to the boundary of the current %1 feature.</b>" ).arg(
string ) );
2110 mForceLabelsInsideCheckBox->setText( tr(
"Force labels inside %1 feature" ).arg(
string ) );
2123 mMapItem = qobject_cast< QgsLayoutItemMap * >( item );
2130 updateGuiElements();
2135 void QgsLayoutMapClippingWidget::updateGuiElements()
2137 if ( mBlockUpdates )
2140 mBlockUpdates =
true;
2141 mClipToAtlasCheckBox->setChecked( mMapItem->atlasClippingSettings()->enabled() );
2142 mAtlasClippingTypeComboBox->setCurrentIndex( mAtlasClippingTypeComboBox->findData(
static_cast< int >( mMapItem->atlasClippingSettings()->featureClippingType() ) ) );
2143 mForceLabelsInsideCheckBox->setChecked( mMapItem->atlasClippingSettings()->forceLabelsInsideFeature() );
2145 mRadioClipAllLayers->setChecked( !mMapItem->atlasClippingSettings()->restrictToLayers() );
2146 mRadioClipSelectedLayers->setChecked( mMapItem->atlasClippingSettings()->restrictToLayers() );
2147 mLayerModel->
setLayersChecked( mMapItem->atlasClippingSettings()->layersToClip() );
2149 mClipToItemCheckBox->setChecked( mMapItem->itemClippingSettings()->enabled() );
2150 mItemClippingTypeComboBox->setCurrentIndex( mItemClippingTypeComboBox->findData(
static_cast< int >( mMapItem->itemClippingSettings()->featureClippingType() ) ) );
2151 mForceLabelsInsideItemCheckBox->setChecked( mMapItem->itemClippingSettings()->forceLabelsInsideClipPath() );
2152 mClipItemComboBox->setItem( mMapItem->itemClippingSettings()->sourceItem() );
2154 mBlockUpdates =
false;
2157 void QgsLayoutMapClippingWidget::atlasLayerChanged(
QgsVectorLayer *layer )
2162 mClipToAtlasCheckBox->setChecked(
false );
2163 mClipToAtlasCheckBox->setEnabled(
false );
2168 mClipToAtlasCheckBox->setEnabled(
true );
2172 void QgsLayoutMapClippingWidget::atlasToggled(
bool atlasEnabled )
2174 if ( atlasEnabled &&
2175 mMapItem && mMapItem->layout() && mMapItem->layout()->reportContext().layer()
2178 mClipToAtlasCheckBox->setEnabled(
true );
2182 mClipToAtlasCheckBox->setEnabled(
false );
2183 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 takes output image size into accou...
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.
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