28 : QSortFilterProxyModel( parent )
31 setSourceModel( mModel );
41 return mapFromSource( mModel->
indexForItem( item, column ) );
46 mModel->setSelected( mapToSource( index ) );
58 if ( !index.isValid() )
67 if ( role == Qt::FontRole )
73 boldFont.setBold(
true );
78 return QSortFilterProxyModel::data( index, role );
88 , mDesigner( designer )
90 setColumnWidth( 0, 30 );
91 setColumnWidth( 1, 30 );
92 setDragEnabled(
true );
93 setAcceptDrops(
true );
94 setDropIndicatorShown(
true );
95 setDragDropMode( QAbstractItemView::InternalMove );
96 setContextMenuPolicy( Qt::CustomContextMenu );
100 setSelectionMode( QAbstractItemView::ExtendedSelection );
101 setSelectionBehavior( QAbstractItemView::SelectRows );
103 connect(
this, &QWidget::customContextMenuRequested,
this, &QgsLayoutItemsListView::showContextMenu );
113 header()->setSectionResizeMode( 0, QHeaderView::Fixed );
114 header()->setSectionResizeMode( 1, QHeaderView::Fixed );
117 header()->setSectionsMovable(
false );
119 connect( selectionModel(), &QItemSelectionModel::selectionChanged,
this, &QgsLayoutItemsListView::updateSelection );
124 if ( event->key() == Qt::Key_Space )
126 const auto constSelectedIndexes = selectionModel()->selectedIndexes();
127 if ( !constSelectedIndexes.isEmpty() )
129 const bool isFirstItemVisible = mModel->
itemFromIndex( constSelectedIndexes[0] )->isVisible();
131 for (
const QModelIndex &index : constSelectedIndexes )
143 QTreeView::keyPressEvent( event );
146void QgsLayoutItemsListView::updateSelection()
151 if ( !mModel || mUpdatingFromView )
155 mUpdatingSelection =
true;
161 QList<QgsLayoutItem *> selectedItems;
162 for (
const QModelIndex &index : selectionModel()->selectedIndexes() )
166 selectedItems << item;
171 bool itemSelected =
false;
174 if ( selectionModel()->isSelected( selectionModel()->currentIndex() ) )
193 item->setSelected(
true );
202 if ( group && group != item )
207 mUpdatingSelection =
false;
210void QgsLayoutItemsListView::onItemFocused(
QgsLayoutItem *focusedItem )
213 if ( !mModel || mUpdatingSelection )
217 mUpdatingFromView =
true;
223 QModelIndex index = mModel->
indexForItem( focusedItem );
224 if ( index.isValid() )
226 setCurrentIndex( index );
233 const QModelIndex firstCol = mModel->
indexForItem( item );
234 if ( firstCol.isValid() )
237 QItemSelection selection;
238 selection.select( firstCol, firstCol.siblingAtColumn( mModel->columnCount( firstCol.parent() ) - 1 ) );
239 selectionModel()->select( selection, QItemSelectionModel::Select );
243 mUpdatingFromView =
false;
246void QgsLayoutItemsListView::showContextMenu( QPoint point )
250 const QModelIndex index = indexAt( point );
255 QMenu *menu =
new QMenu(
this );
257 QAction *copyAction =
new QAction( tr(
"Copy Item" ), menu );
258 connect( copyAction, &QAction::triggered,
this, [
this, item]()
262 menu->addAction( copyAction );
263 QAction *deleteAction =
new QAction( tr(
"Delete Item" ), menu );
264 connect( deleteAction, &QAction::triggered,
this, [
this, item]()
266 mDesigner->
view()->deleteItems( QList< QgsLayoutItem * >() << item );
268 menu->addAction( deleteAction );
269 menu->addSeparator();
271 QAction *itemPropertiesAction =
new QAction( tr(
"Item Properties…" ), menu );
272 connect( itemPropertiesAction, &QAction::triggered,
this, [
this, item]()
276 menu->addAction( itemPropertiesAction );
278 menu->popup( mapToGlobal( point ) );
static const double UI_SCALE_FACTOR
UI scaling factor.
A common interface for layout designer dialogs and widgets.
virtual void showItemOptions(QgsLayoutItem *item, bool bringPanelToFront=true)=0
Shows the configuration widget for the specified layout item.
virtual QgsLayoutView * view()=0
Returns the layout view utilized by the designer.
A container for grouping several QgsLayoutItems.
Base class for graphical items within a QgsLayout.
QgsLayoutItemGroup * parentGroup() const
Returns the item's parent group, if the item is part of a QgsLayoutItemGroup group.
virtual void setSelected(bool selected)
Sets whether the item should be selected.
virtual void setVisibility(bool visible)
Sets whether the item is visible.
Model for the layout items list view.
QgsLayoutItem * itemFromIndex(const QModelIndex &index) const
Returns the layout item listed at the specified index.
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override
QgsLayoutItemsListViewModel(QgsLayoutModel *model, QObject *parent)
constructor
void setSelected(const QModelIndex &index)
Sets the selected index.
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
QModelIndex indexForItem(QgsLayoutItem *item, const int column=0) const
Returns the model index matching the specified layout item.
void setCurrentLayout(QgsLayout *layout)
Sets the current layout.
QgsLayoutItemsListView(QWidget *parent, QgsLayoutDesignerInterface *designer)
Constructor for QgsLayoutItemsListView.
void keyPressEvent(QKeyEvent *event) override
A model for items attached to a layout.
QgsLayoutItem * itemFromIndex(const QModelIndex &index) const
Returns the QgsLayoutItem corresponding to a QModelIndex index, if possible.
QModelIndex indexForItem(QgsLayoutItem *item, int column=0)
Returns the QModelIndex corresponding to a QgsLayoutItem item and column, if possible.
void itemFocused(QgsLayoutItem *item)
Emitted when an item is "focused" in the view, i.e.
@ ClipboardCopy
Copy items.
Base class for layouts, which can contain items such as maps, labels, scalebars, etc.
QgsLayoutModel * itemsModel()
Returns the items model attached to the layout.
QList< QgsLayoutItem * > selectedLayoutItems(bool includeLockedItems=true)
Returns list of selected layout items.
void setSelectedItem(QgsLayoutItem *item)
Clears any selected items and sets item as the current selection.
QgsSignalBlocker< Object > whileBlocking(Object *object)
Temporarily blocks signals from a QObject while calling a single method from the object.