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 )
70void QgsLayoutGuideWidget::addHorizontalGuide()
76void QgsLayoutGuideWidget::addVerticalGuide()
82void QgsLayoutGuideWidget::deleteHorizontalGuide()
85 const auto constSelectedIndexes = mHozGuidesTableView->selectionModel()->selectedIndexes();
86 for (
const QModelIndex &index : constSelectedIndexes )
88 mHozGuidesTableView->closePersistentEditor( index );
89 if ( index.column() == 0 )
90 mHozProxyModel->removeRow( index.row() );
95void QgsLayoutGuideWidget::deleteVerticalGuide()
98 const auto constSelectedIndexes = mVertGuidesTableView->selectionModel()->selectedIndexes();
99 for (
const QModelIndex &index : constSelectedIndexes )
101 mVertGuidesTableView->closePersistentEditor( index );
102 if ( index.column() == 0 )
103 mVertProxyModel->removeRow( index.row() );
115 const auto horizontalSelectedIndexes = mHozGuidesTableView->selectionModel()->selectedIndexes();
116 for (
const QModelIndex &index : horizontalSelectedIndexes )
118 mHozGuidesTableView->closePersistentEditor( index );
120 const auto verticalSelectedIndexes = mVertGuidesTableView->selectionModel()->selectedIndexes();
121 for (
const QModelIndex &index : verticalSelectedIndexes )
123 mVertGuidesTableView->closePersistentEditor( index );
126 mHozProxyModel->
setPage( page );
127 mVertProxyModel->
setPage( page );
129 whileBlocking( mPageNumberComboBox )->setCurrentIndex( page );
132void QgsLayoutGuideWidget::clearAll()
135 const auto horizontalSelectedIndexes = mHozGuidesTableView->selectionModel()->selectedIndexes();
136 for (
const QModelIndex &index : horizontalSelectedIndexes )
138 mHozGuidesTableView->closePersistentEditor( index );
140 const auto verticalSelectedIndexes = mVertGuidesTableView->selectionModel()->selectedIndexes();
141 for (
const QModelIndex &index : verticalSelectedIndexes )
143 mVertGuidesTableView->closePersistentEditor( index );
147 mVertProxyModel->removeRows( 0, mVertProxyModel->rowCount() );
148 mHozProxyModel->removeRows( 0, mHozProxyModel->rowCount() );
152void QgsLayoutGuideWidget::applyToAll()
157void QgsLayoutGuideWidget::updatePageCount()
159 const int prevPage = mPageNumberComboBox->currentIndex();
160 mPageNumberComboBox->clear();
161 for (
int i = 0; i < mLayout->
pageCollection()->pageCount(); ++ i )
162 mPageNumberComboBox->addItem( QString::number( i + 1 ), i );
164 if ( mPageNumberComboBox->count() > prevPage )
165 mPageNumberComboBox->setCurrentIndex( prevPage );
170 : 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, [ = ](
double )
197 : 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.