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 );
122void QgsLayoutItemsListView::updateSelection()
127 if ( !mModel || mUpdatingFromView )
131 mUpdatingSelection =
true;
137 QList<QgsLayoutItem *> selectedItems;
138 for (
const QModelIndex &index : selectionModel()->selectedIndexes() )
142 selectedItems << item;
147 bool itemSelected =
false;
150 if ( selectionModel()->isSelected( selectionModel()->currentIndex() ) )
169 item->setSelected(
true );
178 if ( group && group != item )
183 mUpdatingSelection =
false;
186void QgsLayoutItemsListView::onItemFocused(
QgsLayoutItem *focusedItem )
189 if ( !mModel || mUpdatingSelection )
193 mUpdatingFromView =
true;
199 QModelIndex index = mModel->
indexForItem( focusedItem );
200 if ( index.isValid() )
202 setCurrentIndex( index );
209 const QModelIndex firstCol = mModel->
indexForItem( item );
210 if ( firstCol.isValid() )
213 QItemSelection selection;
214 selection.select( firstCol, firstCol.siblingAtColumn( mModel->columnCount( firstCol.parent() ) - 1 ) );
215 selectionModel()->select( selection, QItemSelectionModel::Select );
219 mUpdatingFromView =
false;
222void QgsLayoutItemsListView::showContextMenu( QPoint point )
226 const QModelIndex index = indexAt( point );
231 QMenu *menu =
new QMenu(
this );
233 QAction *copyAction =
new QAction( tr(
"Copy Item" ), menu );
234 connect( copyAction, &QAction::triggered,
this, [
this, item]()
238 menu->addAction( copyAction );
239 QAction *deleteAction =
new QAction( tr(
"Delete Item" ), menu );
240 connect( deleteAction, &QAction::triggered,
this, [
this, item]()
242 mDesigner->
view()->deleteItems( QList< QgsLayoutItem * >() << item );
244 menu->addAction( deleteAction );
245 menu->addSeparator();
247 QAction *itemPropertiesAction =
new QAction( tr(
"Item Properties…" ), menu );
248 connect( itemPropertiesAction, &QAction::triggered,
this, [
this, item]()
252 menu->addAction( itemPropertiesAction );
254 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.
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.
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.