18#include "moc_qgslayoutguidewidget.cpp"
34 mHozProxyModel->setSourceModel( &mLayout->
guides() );
36 mVertProxyModel->setSourceModel( &mLayout->
guides() );
38 mHozGuidesTableView->setModel( mHozProxyModel );
39 mVertGuidesTableView->setModel( mVertProxyModel );
41 mHozGuidesTableView->setEditTriggers( QAbstractItemView::AllEditTriggers );
42 mVertGuidesTableView->setEditTriggers( QAbstractItemView::AllEditTriggers );
50 connect( mAddHozGuideButton, &QPushButton::clicked,
this, &QgsLayoutGuideWidget::addHorizontalGuide );
51 connect( mAddVertGuideButton, &QPushButton::clicked,
this, &QgsLayoutGuideWidget::addVerticalGuide );
53 connect( mDeleteHozGuideButton, &QPushButton::clicked,
this, &QgsLayoutGuideWidget::deleteHorizontalGuide );
54 connect( mDeleteVertGuideButton, &QPushButton::clicked,
this, &QgsLayoutGuideWidget::deleteVerticalGuide );
56 connect( mClearAllButton, &QPushButton::clicked,
this, &QgsLayoutGuideWidget::clearAll );
57 connect( mApplyToAllButton, &QPushButton::clicked,
this, &QgsLayoutGuideWidget::applyToAll );
61 connect( mPageNumberComboBox, qOverload<int>( &QComboBox::currentIndexChanged ),
this, [=](
int ) {
69void QgsLayoutGuideWidget::addHorizontalGuide()
75void QgsLayoutGuideWidget::addVerticalGuide()
81void QgsLayoutGuideWidget::deleteHorizontalGuide()
84 const auto constSelectedIndexes = mHozGuidesTableView->selectionModel()->selectedIndexes();
85 for (
const QModelIndex &index : constSelectedIndexes )
87 mHozGuidesTableView->closePersistentEditor( index );
88 if ( index.column() == 0 )
89 mHozProxyModel->removeRow( index.row() );
94void QgsLayoutGuideWidget::deleteVerticalGuide()
97 const auto constSelectedIndexes = mVertGuidesTableView->selectionModel()->selectedIndexes();
98 for (
const QModelIndex &index : constSelectedIndexes )
100 mVertGuidesTableView->closePersistentEditor( index );
101 if ( index.column() == 0 )
102 mVertProxyModel->removeRow( index.row() );
114 const auto horizontalSelectedIndexes = mHozGuidesTableView->selectionModel()->selectedIndexes();
115 for (
const QModelIndex &index : horizontalSelectedIndexes )
117 mHozGuidesTableView->closePersistentEditor( index );
119 const auto verticalSelectedIndexes = mVertGuidesTableView->selectionModel()->selectedIndexes();
120 for (
const QModelIndex &index : verticalSelectedIndexes )
122 mVertGuidesTableView->closePersistentEditor( index );
125 mHozProxyModel->
setPage( page );
126 mVertProxyModel->
setPage( page );
128 whileBlocking( mPageNumberComboBox )->setCurrentIndex( page );
131void QgsLayoutGuideWidget::clearAll()
134 const auto horizontalSelectedIndexes = mHozGuidesTableView->selectionModel()->selectedIndexes();
135 for (
const QModelIndex &index : horizontalSelectedIndexes )
137 mHozGuidesTableView->closePersistentEditor( index );
139 const auto verticalSelectedIndexes = mVertGuidesTableView->selectionModel()->selectedIndexes();
140 for (
const QModelIndex &index : verticalSelectedIndexes )
142 mVertGuidesTableView->closePersistentEditor( index );
146 mVertProxyModel->removeRows( 0, mVertProxyModel->rowCount() );
147 mHozProxyModel->removeRows( 0, mHozProxyModel->rowCount() );
151void QgsLayoutGuideWidget::applyToAll()
156void QgsLayoutGuideWidget::updatePageCount()
158 const int prevPage = mPageNumberComboBox->currentIndex();
159 mPageNumberComboBox->clear();
160 for (
int i = 0; i < mLayout->
pageCollection()->pageCount(); ++i )
161 mPageNumberComboBox->addItem( QString::number( i + 1 ), i );
163 if ( mPageNumberComboBox->count() > prevPage )
164 mPageNumberComboBox->setCurrentIndex( prevPage );
169 : QStyledItemDelegate( parent )
176 spin->setMinimum( 0 );
177 spin->setMaximum( 1000000 );
178 spin->setDecimals( 2 );
180 connect( spin,
static_cast<void (
QgsDoubleSpinBox::* )(
double )
>( &QgsDoubleSpinBox::valueChanged ),
this, [=](
double ) {
194 : 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.
void applyGuidesToAllOtherPages(int sourcePage)
Resets all other pages' guides to match the guides from the specified sourcePage.
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).
void setPage(int page)
Sets the current page for filtering matching guides.
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
Contains the configuration for a single snap guide used by a layout.
This class provides a method of storing measurements for use in QGIS layouts using a variety of diffe...
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.
void beginMacro(const QString &commandText)
Starts a macro command, with the given descriptive commandText.
void endMacro()
Ends a macro command.
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.
QgsLayoutUndoStack * undoStack()
Returns a pointer to the layout's undo stack, which manages undo/redo states for the layout and it's ...
QgsSignalBlocker< Object > whileBlocking(Object *object)
Temporarily blocks signals from a QObject while calling a single method from the object.