33 mHozProxyModel->setSourceModel( &mLayout->
guides() );
35 mVertProxyModel->setSourceModel( &mLayout->
guides() );
37 mHozGuidesTableView->setModel( mHozProxyModel );
38 mVertGuidesTableView->setModel( mVertProxyModel );
40 mHozGuidesTableView->setEditTriggers( QAbstractItemView::AllEditTriggers );
41 mVertGuidesTableView->setEditTriggers( QAbstractItemView::AllEditTriggers );
49 connect( mAddHozGuideButton, &QPushButton::clicked,
this, &QgsLayoutGuideWidget::addHorizontalGuide );
50 connect( mAddVertGuideButton, &QPushButton::clicked,
this, &QgsLayoutGuideWidget::addVerticalGuide );
52 connect( mDeleteHozGuideButton, &QPushButton::clicked,
this, &QgsLayoutGuideWidget::deleteHorizontalGuide );
53 connect( mDeleteVertGuideButton, &QPushButton::clicked,
this, &QgsLayoutGuideWidget::deleteVerticalGuide );
55 connect( mClearAllButton, &QPushButton::clicked,
this, &QgsLayoutGuideWidget::clearAll );
56 connect( mApplyToAllButton, &QPushButton::clicked,
this, &QgsLayoutGuideWidget::applyToAll );
60 connect( mPageNumberComboBox, qOverload< int >( &QComboBox::currentIndexChanged ),
this, [ = ](
int )
69 void QgsLayoutGuideWidget::addHorizontalGuide()
75 void QgsLayoutGuideWidget::addVerticalGuide()
81 void 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() );
94 void 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 );
131 void 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() );
151 void QgsLayoutGuideWidget::applyToAll()
156 void 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 )
177 spin->setMinimum( 0 );
178 spin->setMaximum( 1000000 );
179 spin->setDecimals( 2 );
181 connect( spin,
static_cast < void (
QgsDoubleSpinBox::* )(
double )
> ( &QgsDoubleSpinBox::valueChanged ),
this, [ = ](
double )
196 : QStyledItemDelegate( parent )
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.
void applyGuidesToAllOtherPages(int sourcePage)
Resets all other pages' guides to match the guides from the specified sourcePage.
@ PositionRole
Guide position role.
@ UnitsRole
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).
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 changed(QgsUnitTypes::LayoutUnit unit)
Emitted when the unit is changed.
QgsUnitTypes::LayoutUnit unit
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.