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 );
103 #if QT_VERSION < QT_VERSION_CHECK(5, 11, 0)
110 header()->setSectionsMovable(
false );
115 void QgsLayoutItemsListView::showContextMenu( QPoint point )
117 QModelIndex index = indexAt( point );
122 QMenu *menu =
new QMenu(
this );
124 QAction *copyAction =
new QAction( tr(
"Copy Item" ), menu );
125 connect( copyAction, &QAction::triggered,
this, [
this, item]()
129 menu->addAction( copyAction );
130 QAction *deleteAction =
new QAction( tr(
"Delete Item" ), menu );
131 connect( deleteAction, &QAction::triggered,
this, [
this, item]()
133 mDesigner->
view()->deleteItems( QList< QgsLayoutItem * >() << item );
135 menu->addAction( deleteAction );
136 menu->addSeparator();
138 QAction *itemPropertiesAction =
new QAction( tr(
"Item Properties…" ), menu );
139 connect( itemPropertiesAction, &QAction::triggered,
this, [
this, item]()
143 menu->addAction( itemPropertiesAction );
145 menu->popup( mapToGlobal( point ) );