26#include "moc_qgslayoutguidewidget.cpp"
36 mHozProxyModel->setSourceModel( &mLayout->guides() );
38 mVertProxyModel->setSourceModel( &mLayout->guides() );
40 mHozGuidesTableView->setModel( mHozProxyModel );
41 mVertGuidesTableView->setModel( mVertProxyModel );
43 mHozGuidesTableView->setEditTriggers( QAbstractItemView::AllEditTriggers );
44 mVertGuidesTableView->setEditTriggers( QAbstractItemView::AllEditTriggers );
52 connect( mAddHozGuideButton, &QPushButton::clicked,
this, &QgsLayoutGuideWidget::addHorizontalGuide );
53 connect( mAddVertGuideButton, &QPushButton::clicked,
this, &QgsLayoutGuideWidget::addVerticalGuide );
55 connect( mDeleteHozGuideButton, &QPushButton::clicked,
this, &QgsLayoutGuideWidget::deleteHorizontalGuide );
56 connect( mDeleteVertGuideButton, &QPushButton::clicked,
this, &QgsLayoutGuideWidget::deleteVerticalGuide );
58 connect( mClearAllButton, &QPushButton::clicked,
this, &QgsLayoutGuideWidget::clearAll );
59 connect( mApplyToAllButton, &QPushButton::clicked,
this, &QgsLayoutGuideWidget::applyToAll );
63 connect( mPageNumberComboBox, qOverload<int>( &QComboBox::currentIndexChanged ),
this, [
this](
int ) {
71void QgsLayoutGuideWidget::addHorizontalGuide()
77void QgsLayoutGuideWidget::addVerticalGuide()
79 auto newGuide = std::make_unique<QgsLayoutGuide>( Qt::Vertical, QgsLayoutMeasurement( 0 ), mLayout->pageCollection()->page( mPage ) );
80 mLayout->guides().addGuide( newGuide.release() );
83void QgsLayoutGuideWidget::deleteHorizontalGuide()
85 mLayout->undoStack()->beginMacro( tr(
"Remove Horizontal Guides" ) );
86 const auto constSelectedIndexes = mHozGuidesTableView->selectionModel()->selectedIndexes();
87 for (
const QModelIndex &index : constSelectedIndexes )
89 mHozGuidesTableView->closePersistentEditor( index );
90 if ( index.column() == 0 )
91 mHozProxyModel->removeRow( index.row() );
93 mLayout->undoStack()->endMacro();
96void QgsLayoutGuideWidget::deleteVerticalGuide()
98 mLayout->undoStack()->beginMacro( tr(
"Remove Vertical Guides" ) );
99 const auto constSelectedIndexes = mVertGuidesTableView->selectionModel()->selectedIndexes();
100 for (
const QModelIndex &index : constSelectedIndexes )
102 mVertGuidesTableView->closePersistentEditor( index );
103 if ( index.column() == 0 )
104 mVertProxyModel->removeRow( index.row() );
106 mLayout->undoStack()->endMacro();
116 const auto horizontalSelectedIndexes = mHozGuidesTableView->selectionModel()->selectedIndexes();
117 for (
const QModelIndex &index : horizontalSelectedIndexes )
119 mHozGuidesTableView->closePersistentEditor( index );
121 const auto verticalSelectedIndexes = mVertGuidesTableView->selectionModel()->selectedIndexes();
122 for (
const QModelIndex &index : verticalSelectedIndexes )
124 mVertGuidesTableView->closePersistentEditor( index );
127 mHozProxyModel->setPage( page );
128 mVertProxyModel->setPage( page );
130 whileBlocking( mPageNumberComboBox )->setCurrentIndex( page );
133void QgsLayoutGuideWidget::clearAll()
136 const auto horizontalSelectedIndexes = mHozGuidesTableView->selectionModel()->selectedIndexes();
137 for (
const QModelIndex &index : horizontalSelectedIndexes )
139 mHozGuidesTableView->closePersistentEditor( index );
141 const auto verticalSelectedIndexes = mVertGuidesTableView->selectionModel()->selectedIndexes();
142 for (
const QModelIndex &index : verticalSelectedIndexes )
144 mVertGuidesTableView->closePersistentEditor( index );
147 mLayout->undoStack()->beginMacro( tr(
"Remove All Guides" ) );
148 mVertProxyModel->removeRows( 0, mVertProxyModel->rowCount() );
149 mHozProxyModel->removeRows( 0, mHozProxyModel->rowCount() );
150 mLayout->undoStack()->endMacro();
153void QgsLayoutGuideWidget::applyToAll()
155 mLayout->guides().applyGuidesToAllOtherPages( mPage );
158void QgsLayoutGuideWidget::updatePageCount()
160 const int prevPage = mPageNumberComboBox->currentIndex();
161 mPageNumberComboBox->clear();
162 for (
int i = 0; i < mLayout->pageCollection()->pageCount(); ++i )
163 mPageNumberComboBox->addItem( QString::number( i + 1 ), i );
165 if ( mPageNumberComboBox->count() > prevPage )
166 mPageNumberComboBox->setCurrentIndex( prevPage );
171 : QStyledItemDelegate( parent )
178 spin->setMinimum( 0 );
179 spin->setMaximum( 1000000 );
180 spin->setDecimals( 2 );
182 connect( spin,
static_cast<void (
QgsDoubleSpinBox::* )(
double )
>( &QgsDoubleSpinBox::valueChanged ),
this, [
this, spin](
double ) {
196 : QStyledItemDelegate( parent )
LayoutUnit
Layout measurement units.
The QgsSpinBox is a spin box with a clear button that will set the value to the defined clear value.
void setShowClearButton(bool showClearButton)
Sets whether the widget will show a clear button.
void addGuide(QgsLayoutGuide *guide)
Adds a guide to the collection.
@ Position
Guide position role.
@ Units
Guide position units role.
View delegate displaying a QgsDoubleSpinBox for the layout guide position.
QWidget * createEditor(QWidget *parent, const QStyleOptionViewItem &, const QModelIndex &index) const override
QgsLayoutGuidePositionDelegate(QObject *parent)
constructor
void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const override
Filters QgsLayoutGuideCollection models to guides of a single orientation (horizontal or vertical).
View delegate displaying a QgsLayoutUnitsComboBox for the layout guide unit.
void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const override
QgsLayoutGuideUnitDelegate(QObject *parent)
constructor
QWidget * createEditor(QWidget *parent, const QStyleOptionViewItem &, const QModelIndex &index) const override
Provides a method of storing measurements for use in QGIS layouts using a variety of different measur...
void changed()
Emitted when pages are added or removed from the collection.
QgsLayoutItemPage * page(int pageNumber)
Returns a specific page (by pageNumber) from the collection.
A custom combo box for selecting units for layout settings.
void unitChanged(Qgis::LayoutUnit unit)
Emitted when the unit is changed.
A graphical widget to display and interact with QgsLayouts.
void pageChanged(int page)
Emitted when the page visible in the view is changed.
Base class for layouts, which can contain items such as maps, labels, scalebars, etc.
QgsLayoutPageCollection * pageCollection()
Returns a pointer to the layout's page collection, which stores and manages page items in the layout.
QgsLayoutGuideCollection & guides()
Returns a reference to the layout's guide collection, which manages page snap guides.
QgsSignalBlocker< Object > whileBlocking(Object *object)
Temporarily blocks signals from a QObject while calling a single method from the object.