21 #include <QHeaderView> 
   23 #include <QMouseEvent> 
   27   : QSortFilterProxyModel( parent )
 
   30   setSourceModel( mModel );
 
   40   mModel->setSelected( mapToSource( index ) );
 
   52   if ( !index.isValid() )
 
   61   if ( role == Qt::FontRole )
 
   67       boldFont.setBold( 
true );
 
   72   return QSortFilterProxyModel::data( index, role );
 
   82   , mDesigner( designer )
 
   84   setColumnWidth( 0, 30 );
 
   85   setColumnWidth( 1, 30 );
 
   86   setDragEnabled( 
true );
 
   87   setAcceptDrops( 
true );
 
   88   setDropIndicatorShown( 
true );
 
   89   setDragDropMode( QAbstractItemView::InternalMove );
 
   90   setContextMenuPolicy( Qt::CustomContextMenu );
 
   92   connect( 
this, &QWidget::customContextMenuRequested, 
this, &QgsLayoutItemsListView::showContextMenu );
 
  101   header()->setSectionResizeMode( 0, QHeaderView::Fixed );
 
  102   header()->setSectionResizeMode( 1, QHeaderView::Fixed );
 
  105   header()->setSectionsMovable( 
false );
 
  110 void QgsLayoutItemsListView::showContextMenu( QPoint point )
 
  114   QModelIndex index = indexAt( point );
 
  119   QMenu *menu = 
new QMenu( 
this );
 
  121   QAction *copyAction = 
new QAction( tr( 
"Copy Item" ), menu );
 
  122   connect( copyAction, &QAction::triggered, 
this, [
this, item]()
 
  126   menu->addAction( copyAction );
 
  127   QAction *deleteAction = 
new QAction( tr( 
"Delete Item" ), menu );
 
  128   connect( deleteAction, &QAction::triggered, 
this, [
this, item]()
 
  130     mDesigner->
view()->deleteItems( QList< QgsLayoutItem * >() << item );
 
  132   menu->addAction( deleteAction );
 
  133   menu->addSeparator();
 
  135   QAction *itemPropertiesAction = 
new QAction( tr( 
"Item Properties…" ), menu );
 
  136   connect( itemPropertiesAction, &QAction::triggered, 
this, [
this, item]()
 
  140   menu->addAction( itemPropertiesAction );
 
  142   menu->popup( mapToGlobal( point ) );
 
static const double UI_SCALE_FACTOR
UI scaling factor.
A common interface for layout designer dialogs and widgets.
virtual QgsLayoutView * view()=0
Returns the layout view utilized by the designer.
virtual void showItemOptions(QgsLayoutItem *item, bool bringPanelToFront=true)=0
Shows the configuration widget for the specified layout item.
Base class for graphical items within a QgsLayout.
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
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.
@ 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.