40 #include <QMessageBox>
41 #include <QStringListModel>
46 , mMapCanvas( mapCanvas )
51 connect( mScaleLineEdit, &QLineEdit::editingFinished,
this, &QgsLayoutMapWidget::mScaleLineEdit_editingFinished );
52 connect( mActionSetToCanvasExtent, &QAction::triggered,
this, &QgsLayoutMapWidget::setToMapCanvasExtent );
53 connect( mActionViewExtentInCanvas, &QAction::triggered,
this, &QgsLayoutMapWidget::viewExtentInCanvas );
54 connect( mActionSetToCanvasScale, &QAction::triggered,
this, &QgsLayoutMapWidget::setToMapCanvasScale );
55 connect( mActionViewScaleInCanvas, &QAction::triggered,
this, &QgsLayoutMapWidget::viewScaleInCanvas );
56 connect( mActionUpdatePreview, &QAction::triggered,
this, &QgsLayoutMapWidget::updatePreview );
57 connect( mFollowVisibilityPresetCheckBox, &QCheckBox::stateChanged,
this, &QgsLayoutMapWidget::mFollowVisibilityPresetCheckBox_stateChanged );
58 connect( mKeepLayerListCheckBox, &QCheckBox::stateChanged,
this, &QgsLayoutMapWidget::mKeepLayerListCheckBox_stateChanged );
59 connect( mKeepLayerStylesCheckBox, &QCheckBox::stateChanged,
this, &QgsLayoutMapWidget::mKeepLayerStylesCheckBox_stateChanged );
60 connect( mDrawCanvasItemsCheckBox, &QCheckBox::stateChanged,
this, &QgsLayoutMapWidget::mDrawCanvasItemsCheckBox_stateChanged );
61 connect( mOverviewBlendModeComboBox,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsLayoutMapWidget::mOverviewBlendModeComboBox_currentIndexChanged );
62 connect( mOverviewInvertCheckbox, &QCheckBox::toggled,
this, &QgsLayoutMapWidget::mOverviewInvertCheckbox_toggled );
63 connect( mOverviewCenterCheckbox, &QCheckBox::toggled,
this, &QgsLayoutMapWidget::mOverviewCenterCheckbox_toggled );
64 connect( mOverviewPositionComboBox,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsLayoutMapWidget::overviewStackingChanged );
66 connect( mXMinLineEdit, &QLineEdit::editingFinished,
this, &QgsLayoutMapWidget::mXMinLineEdit_editingFinished );
67 connect( mXMaxLineEdit, &QLineEdit::editingFinished,
this, &QgsLayoutMapWidget::mXMaxLineEdit_editingFinished );
68 connect( mYMinLineEdit, &QLineEdit::editingFinished,
this, &QgsLayoutMapWidget::mYMinLineEdit_editingFinished );
69 connect( mYMaxLineEdit, &QLineEdit::editingFinished,
this, &QgsLayoutMapWidget::mYMaxLineEdit_editingFinished );
70 connect( mAtlasMarginRadio, &QRadioButton::toggled,
this, &QgsLayoutMapWidget::mAtlasMarginRadio_toggled );
71 connect( mAtlasCheckBox, &QgsCollapsibleGroupBoxBasic::toggled,
this, &QgsLayoutMapWidget::mAtlasCheckBox_toggled );
72 connect( mAtlasMarginSpinBox,
static_cast < void ( QSpinBox::* )(
int )
> ( &QSpinBox::valueChanged ),
this, &QgsLayoutMapWidget::mAtlasMarginSpinBox_valueChanged );
73 connect( mAtlasFixedScaleRadio, &QRadioButton::toggled,
this, &QgsLayoutMapWidget::mAtlasFixedScaleRadio_toggled );
74 connect( mAtlasPredefinedScaleRadio, &QRadioButton::toggled,
this, &QgsLayoutMapWidget::mAtlasPredefinedScaleRadio_toggled );
75 connect( mAddGridPushButton, &QPushButton::clicked,
this, &QgsLayoutMapWidget::mAddGridPushButton_clicked );
76 connect( mRemoveGridPushButton, &QPushButton::clicked,
this, &QgsLayoutMapWidget::mRemoveGridPushButton_clicked );
77 connect( mGridUpButton, &QPushButton::clicked,
this, &QgsLayoutMapWidget::mGridUpButton_clicked );
78 connect( mGridDownButton, &QPushButton::clicked,
this, &QgsLayoutMapWidget::mGridDownButton_clicked );
79 connect( mGridListWidget, &QListWidget::currentItemChanged,
this, &QgsLayoutMapWidget::mGridListWidget_currentItemChanged );
80 connect( mGridListWidget, &QListWidget::itemChanged,
this, &QgsLayoutMapWidget::mGridListWidget_itemChanged );
81 connect( mGridPropertiesButton, &QPushButton::clicked,
this, &QgsLayoutMapWidget::mGridPropertiesButton_clicked );
82 connect( mAddOverviewPushButton, &QPushButton::clicked,
this, &QgsLayoutMapWidget::mAddOverviewPushButton_clicked );
83 connect( mRemoveOverviewPushButton, &QPushButton::clicked,
this, &QgsLayoutMapWidget::mRemoveOverviewPushButton_clicked );
84 connect( mOverviewUpButton, &QPushButton::clicked,
this, &QgsLayoutMapWidget::mOverviewUpButton_clicked );
85 connect( mOverviewDownButton, &QPushButton::clicked,
this, &QgsLayoutMapWidget::mOverviewDownButton_clicked );
86 connect( mOverviewCheckBox, &QgsCollapsibleGroupBoxBasic::toggled,
this, &QgsLayoutMapWidget::mOverviewCheckBox_toggled );
87 connect( mOverviewListWidget, &QListWidget::currentItemChanged,
this, &QgsLayoutMapWidget::mOverviewListWidget_currentItemChanged );
88 connect( mOverviewListWidget, &QListWidget::itemChanged,
this, &QgsLayoutMapWidget::mOverviewListWidget_itemChanged );
89 connect( mActionLabelSettings, &QAction::triggered,
this, &QgsLayoutMapWidget::showLabelSettings );
90 connect( mActionClipSettings, &QAction::triggered,
this, &QgsLayoutMapWidget::showClipSettings );
92 connect( mTemporalCheckBox, &QgsCollapsibleGroupBoxBasic::toggled,
this, &QgsLayoutMapWidget::mTemporalCheckBox_toggled );
93 connect( mStartDateTime, &QDateTimeEdit::dateTimeChanged,
this, &QgsLayoutMapWidget::updateTemporalExtent );
94 connect( mEndDateTime, &QDateTimeEdit::dateTimeChanged,
this, &QgsLayoutMapWidget::updateTemporalExtent );
96 mStartDateTime->setDateTimeRange( QDateTime( QDate( 1, 1, 1 ), QTime( 0, 0, 0 ) ), mStartDateTime->maximumDateTime() );
97 mEndDateTime->setDateTimeRange( QDateTime( QDate( 1, 1, 1 ), QTime( 0, 0, 0 ) ), mStartDateTime->maximumDateTime() );
98 mStartDateTime->setDisplayFormat(
"yyyy-MM-dd HH:mm:ss" );
99 mEndDateTime->setDisplayFormat(
"yyyy-MM-dd HH:mm:ss" );
101 connect( mActionMoveContent, &QAction::triggered,
this, &QgsLayoutMapWidget::switchToMoveContentTool );
103 mMapRotationSpinBox->setClearValue( 0 );
107 mBookmarkMenu =
new QMenu(
this );
108 QToolButton *btnBookmarks =
new QToolButton(
this );
109 btnBookmarks->setAutoRaise(
true );
110 btnBookmarks->setToolTip( tr(
"Bookmarks" ) );
112 btnBookmarks->setPopupMode( QToolButton::InstantPopup );
113 btnBookmarks->setMenu( mBookmarkMenu );
115 mDockToolbar->insertWidget( mActionMoveContent, btnBookmarks );
116 connect( mBookmarkMenu, &QMenu::aboutToShow,
this, &QgsLayoutMapWidget::aboutToShowBookmarkMenu );
120 mainLayout->addWidget( mItemPropertiesWidget );
122 mScaleLineEdit->setValidator(
new QDoubleValidator( mScaleLineEdit ) );
124 mXMinLineEdit->setValidator(
new QDoubleValidator( mXMinLineEdit ) );
125 mXMaxLineEdit->setValidator(
new QDoubleValidator( mXMaxLineEdit ) );
126 mYMinLineEdit->setValidator(
new QDoubleValidator( mYMinLineEdit ) );
127 mYMaxLineEdit->setValidator(
new QDoubleValidator( mYMaxLineEdit ) );
135 blockAllSignals(
true );
138 mCrsSelector->setNotSetText( tr(
"Use Project 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 );
278 void QgsLayoutMapWidget::compositionAtlasToggled(
bool atlasEnabled )
281 mMapItem && mMapItem->layout() && mMapItem->layout()->reportContext().layer()
284 mAtlasCheckBox->setEnabled(
true );
288 mAtlasCheckBox->setEnabled(
false );
289 mAtlasCheckBox->setChecked(
false );
293 void 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 );
313 void 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();
341 void QgsLayoutMapWidget::keepLayersVisibilityPresetSelected()
343 QAction *action = qobject_cast<QAction *>( sender() );
347 QString presetName = action->text();
348 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();
364 void QgsLayoutMapWidget::onMapThemesChanged()
366 if ( QStringListModel *model = qobject_cast<QStringListModel *>( mFollowVisibilityPresetCombo->model() ) )
368 mBlockThemeComboChanges++;
370 lst.append( tr(
"(none)" ) );
372 model->setStringList( lst );
375 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;
402 newExtent = xForm.transformBoundingBox( prevExtent );
410 mMapItem->layout()->undoStack()->beginCommand( mMapItem, tr(
"Change Map CRS" ) );
411 mMapItem->setCrs(
crs );
413 mMapItem->zoomToExtent( newExtent );
414 mMapItem->layout()->undoStack()->endCommand();
415 mMapItem->invalidateCache();
418 void QgsLayoutMapWidget::overviewSymbolChanged()
426 mMapItem->endCommand();
427 mMapItem->invalidateCache();
430 void QgsLayoutMapWidget::showLabelSettings()
434 if ( !mReportTypeString.isEmpty() )
435 mLabelWidget->setReportTypeString( mReportTypeString );
440 void QgsLayoutMapWidget::showClipSettings()
443 if ( !mReportTypeString.isEmpty() )
444 mClipWidget->setReportTypeString( mReportTypeString );
448 void QgsLayoutMapWidget::switchToMoveContentTool()
454 void QgsLayoutMapWidget::aboutToShowBookmarkMenu()
456 mBookmarkMenu->clear();
460 if ( !mBookmarkModel )
463 QMap< QString, QMenu * > groupMenus;
464 for (
int i = 0; i < mBookmarkModel->rowCount(); ++i )
467 QMenu *destMenu = mBookmarkMenu;
468 if ( !group.isEmpty() )
470 destMenu = groupMenus.value( group );
473 destMenu =
new QMenu( group, mBookmarkMenu );
474 groupMenus[ group ] = destMenu;
479 connect( action, &QAction::triggered,
this, [ = ]
489 if ( extent.
crs() != mMapItem->crs() )
493 QgsCoordinateTransform xForm( extent.crs(), mMapItem->crs(), QgsProject::instance() );
494 newExtent = xForm.transformBoundingBox( newExtent );
503 mMapItem->layout()->undoStack()->beginCommand( mMapItem, tr(
"Change Map Extent" ) );
504 mMapItem->zoomToExtent( newExtent );
505 mMapItem->layout()->undoStack()->endCommand();
507 destMenu->addAction( action );
510 QStringList groupKeys = groupMenus.keys();
511 groupKeys.sort( Qt::CaseInsensitive );
512 for (
int i = 0; i < groupKeys.count(); ++i )
514 if ( mBookmarkMenu->actions().value( i ) )
515 mBookmarkMenu->insertMenu( mBookmarkMenu->actions().at( i ), groupMenus.value( groupKeys.at( i ) ) );
517 mBookmarkMenu->addMenu( groupMenus.value( groupKeys.at( i ) ) );
521 void QgsLayoutMapWidget::mTemporalCheckBox_toggled(
bool checked )
528 mStartDateTime->setEnabled( checked );
529 mEndDateTime->setEnabled( checked );
531 mMapItem->layout()->undoStack()->beginCommand( mMapItem, tr(
"Toggle Temporal Range" ) );
532 mMapItem->setIsTemporal( checked );
533 mMapItem->layout()->undoStack()->endCommand();
537 whileBlocking( mStartDateTime )->setDateTime( mMapItem->temporalRange().begin() );
538 whileBlocking( mEndDateTime )->setDateTime( mMapItem->temporalRange().end() );
544 void QgsLayoutMapWidget::updateTemporalExtent()
551 QgsDateTimeRange range = QgsDateTimeRange( mStartDateTime->dateTime(), mEndDateTime->dateTime() );
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() )
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, qgis::overload<int>::of( &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, qgis::overload<int>::of( &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 QgsBookmarkManager * bookmarkManager()
Returns the application's bookmark manager, used for storing installation-wide bookmarks.
static QIcon getThemeIcon(const QString &name)
Helper to get a theme icon.
@ 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.
This class is a composition of two QSettings instances:
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), Section section=NoSection) const
Returns the value for setting key.
Represents a vector layer which manages a vector based data sets.
Q_INVOKABLE QgsWkbTypes::Type wkbType() const FINAL
Returns the WKBType or WKBUnknown in case of error.
Q_INVOKABLE QgsWkbTypes::GeometryType geometryType() const
Returns point, line or polygon.
static GeometryType geometryType(Type type) SIP_HOLDGIL
Returns the geometry type for a WKB type, e.g., both MultiPolygon and CurvePolygon would have a Polyg...
QSize iconSize(bool dockableToolbar)
Returns the user-preferred size of a window's toolbar icons.
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
QgsSignalBlocker< Object > whileBlocking(Object *object)
Temporarily blocks signals from a QObject while calling a single method from the object.
const QgsCoordinateReferenceSystem & crs