17#include "moc_qgslayoutitemslistview.cpp" 
   29  : QSortFilterProxyModel( parent )
 
   32  setSourceModel( mModel );
 
 
   42  return mapFromSource( mModel->
indexForItem( item, column ) );
 
 
   47  mModel->setSelected( mapToSource( index ) );
 
 
   59  if ( !index.isValid() )
 
   68  if ( role == Qt::FontRole )
 
   74      boldFont.setBold( 
true );
 
   79  return QSortFilterProxyModel::data( index, role );
 
 
   89  , mDesigner( designer )
 
   91  setColumnWidth( 0, 30 );
 
   92  setColumnWidth( 1, 30 );
 
   93  setDragEnabled( 
true );
 
   94  setAcceptDrops( 
true );
 
   95  setDropIndicatorShown( 
true );
 
   96  setDragDropMode( QAbstractItemView::InternalMove );
 
   97  setContextMenuPolicy( Qt::CustomContextMenu );
 
  101  setSelectionMode( QAbstractItemView::ExtendedSelection );
 
  102  setSelectionBehavior( QAbstractItemView::SelectRows );
 
  104  connect( 
this, &QWidget::customContextMenuRequested, 
this, &QgsLayoutItemsListView::showContextMenu );
 
 
  114  header()->setSectionResizeMode( 0, QHeaderView::Fixed );
 
  115  header()->setSectionResizeMode( 1, QHeaderView::Fixed );
 
  118  header()->setSectionsMovable( 
false );
 
  120  connect( selectionModel(), &QItemSelectionModel::selectionChanged, 
this, &QgsLayoutItemsListView::updateSelection );
 
 
  125  if ( event->key() == Qt::Key_Space )
 
  127    const auto constSelectedIndexes = selectionModel()->selectedIndexes();
 
  128    if ( !constSelectedIndexes.isEmpty() )
 
  130      const bool isFirstItemVisible = mModel->
itemFromIndex( constSelectedIndexes[0] )->isVisible();
 
  132      for ( 
const QModelIndex &index : constSelectedIndexes )
 
  144  QTreeView::keyPressEvent( event );
 
 
  147void QgsLayoutItemsListView::updateSelection()
 
  152  if ( !mModel || mUpdatingFromView )
 
  156  mUpdatingSelection = 
true;
 
  162  QList<QgsLayoutItem *> selectedItems;
 
  163  for ( 
const QModelIndex &index : selectionModel()->selectedIndexes() )
 
  167      selectedItems << item;
 
  172  bool itemSelected = 
false;
 
  175  if ( selectionModel()->isSelected( selectionModel()->currentIndex() ) )
 
  194      item->setSelected( 
true );
 
  203    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]() {
 
  261  menu->addAction( copyAction );
 
  262  QAction *deleteAction = 
new QAction( tr( 
"Delete Item" ), menu );
 
  263  connect( deleteAction, &QAction::triggered, 
this, [
this, item]() {
 
  264    mDesigner->
view()->deleteItems( QList<QgsLayoutItem *>() << item );
 
  266  menu->addAction( deleteAction );
 
  267  menu->addSeparator();
 
  269  QAction *itemPropertiesAction = 
new QAction( tr( 
"Item Properties…" ), menu );
 
  270  connect( itemPropertiesAction, &QAction::triggered, 
this, [
this, item]() {
 
  273  menu->addAction( itemPropertiesAction );
 
  275  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.