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 );
47 mHozGuidesTableView->setItemDelegateForColumn( 0, hozPosDelegate );
51 mVertGuidesTableView->setItemDelegateForColumn( 0, vertPosDelegate );
54 connect( hozPosDelegate, &QAbstractItemDelegate::closeEditor, mHozProxyModel, [
this]( QWidget *, QAbstractItemDelegate::EndEditHint ) { mHozProxyModel->invalidate(); } );
55 connect( vertPosDelegate, &QAbstractItemDelegate::closeEditor, mVertProxyModel, [
this]( QWidget *, QAbstractItemDelegate::EndEditHint ) { mVertProxyModel->invalidate(); } );
57 connect( mAddHozGuideButton, &QPushButton::clicked,
this, &QgsLayoutGuideWidget::addHorizontalGuide );
58 connect( mAddVertGuideButton, &QPushButton::clicked,
this, &QgsLayoutGuideWidget::addVerticalGuide );
60 connect( mDeleteHozGuideButton, &QPushButton::clicked,
this, &QgsLayoutGuideWidget::deleteHorizontalGuide );
61 connect( mDeleteVertGuideButton, &QPushButton::clicked,
this, &QgsLayoutGuideWidget::deleteVerticalGuide );
63 connect( mClearAllButton, &QPushButton::clicked,
this, &QgsLayoutGuideWidget::clearAll );
64 connect( mApplyToAllButton, &QPushButton::clicked,
this, &QgsLayoutGuideWidget::applyToAll );
68 connect( mPageNumberComboBox, qOverload<int>( &QComboBox::currentIndexChanged ),
this, [
this](
int ) {
setCurrentPage( mPageNumberComboBox->currentData().toInt() ); } );
74void QgsLayoutGuideWidget::addHorizontalGuide()
76 const int newSourceRow = mLayout->
guides().
rowCount( QModelIndex() );
80 const QModelIndex sourceIndex = mLayout->
guides().index( newSourceRow, 0 );
81 const QModelIndex proxyIndex = mHozProxyModel->mapFromSource( sourceIndex );
82 if ( proxyIndex.isValid() )
84 mHozGuidesTableView->selectionModel()->select( proxyIndex, QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows );
85 mHozGuidesTableView->edit( proxyIndex );
89void QgsLayoutGuideWidget::addVerticalGuide()
91 const int newSourceRow = mLayout->guides().rowCount( QModelIndex() );
92 auto newGuide = std::make_unique<QgsLayoutGuide>( Qt::Vertical, QgsLayoutMeasurement( 0 ), mLayout->pageCollection()->page( mPage ) );
93 mLayout->guides().addGuide( newGuide.release() );
95 const QModelIndex sourceIndex = mLayout->guides().index( newSourceRow, 0 );
96 const QModelIndex proxyIndex = mVertProxyModel->mapFromSource( sourceIndex );
97 if ( proxyIndex.isValid() )
99 mVertGuidesTableView->selectionModel()->select( proxyIndex, QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows );
100 mVertGuidesTableView->edit( proxyIndex );
104void QgsLayoutGuideWidget::deleteHorizontalGuide()
106 mLayout->undoStack()->beginMacro( tr(
"Remove Horizontal Guides" ) );
107 const auto constSelectedIndexes = mHozGuidesTableView->selectionModel()->selectedIndexes();
108 for (
const QModelIndex &index : constSelectedIndexes )
110 mHozGuidesTableView->closePersistentEditor( index );
111 if ( index.column() == 0 )
112 mHozProxyModel->removeRow( index.row() );
114 mLayout->undoStack()->endMacro();
117void QgsLayoutGuideWidget::deleteVerticalGuide()
119 mLayout->undoStack()->beginMacro( tr(
"Remove Vertical Guides" ) );
120 const auto constSelectedIndexes = mVertGuidesTableView->selectionModel()->selectedIndexes();
121 for (
const QModelIndex &index : constSelectedIndexes )
123 mVertGuidesTableView->closePersistentEditor( index );
124 if ( index.column() == 0 )
125 mVertProxyModel->removeRow( index.row() );
127 mLayout->undoStack()->endMacro();
137 const auto horizontalSelectedIndexes = mHozGuidesTableView->selectionModel()->selectedIndexes();
138 for (
const QModelIndex &index : horizontalSelectedIndexes )
140 mHozGuidesTableView->closePersistentEditor( index );
142 const auto verticalSelectedIndexes = mVertGuidesTableView->selectionModel()->selectedIndexes();
143 for (
const QModelIndex &index : verticalSelectedIndexes )
145 mVertGuidesTableView->closePersistentEditor( index );
148 mHozProxyModel->setPage( page );
149 mVertProxyModel->setPage( page );
151 whileBlocking( mPageNumberComboBox )->setCurrentIndex( page );
154void QgsLayoutGuideWidget::clearAll()
157 const auto horizontalSelectedIndexes = mHozGuidesTableView->selectionModel()->selectedIndexes();
158 for (
const QModelIndex &index : horizontalSelectedIndexes )
160 mHozGuidesTableView->closePersistentEditor( index );
162 const auto verticalSelectedIndexes = mVertGuidesTableView->selectionModel()->selectedIndexes();
163 for (
const QModelIndex &index : verticalSelectedIndexes )
165 mVertGuidesTableView->closePersistentEditor( index );
168 mLayout->undoStack()->beginMacro( tr(
"Remove All Guides" ) );
169 mVertProxyModel->removeRows( 0, mVertProxyModel->rowCount() );
170 mHozProxyModel->removeRows( 0, mHozProxyModel->rowCount() );
171 mLayout->undoStack()->endMacro();
174void QgsLayoutGuideWidget::applyToAll()
176 mLayout->guides().applyGuidesToAllOtherPages( mPage );
179void QgsLayoutGuideWidget::updatePageCount()
181 const int prevPage = mPageNumberComboBox->currentIndex();
182 mPageNumberComboBox->clear();
183 for (
int i = 0; i < mLayout->pageCollection()->pageCount(); ++i )
184 mPageNumberComboBox->addItem( QString::number( i + 1 ), i );
186 if ( mPageNumberComboBox->count() > prevPage )
187 mPageNumberComboBox->setCurrentIndex( prevPage );
192 : QStyledItemDelegate( parent )
198 spin->setMinimum( 0 );
199 spin->setMaximum( 1000000 );
200 spin->setDecimals( 2 );
202 connect( spin,
static_cast<void (
QgsDoubleSpinBox::* )(
double )
>( &QgsDoubleSpinBox::valueChanged ),
this, [
this, spin](
double ) {
216 : 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.
int rowCount(const QModelIndex &) const override
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.