-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a shortcut menu to items panel, with option to show
item properties Refs #11581
- Loading branch information
1 parent
f69771c
commit 91c3b5d
Showing
7 changed files
with
144 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/*************************************************************************** | ||
qgslayoutitemslistview.cpp | ||
-------------------------- | ||
Date : October 2017 | ||
Copyright : (C) 2017 Nyall Dawson | ||
Email : nyall dot dawson at gmail dot com | ||
*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#include "qgslayoutitemslistview.h" | ||
#include "qgslayout.h" | ||
#include "qgslayoutmodel.h" | ||
#include "qgslayoutdesignerdialog.h" | ||
#include <QHeaderView> | ||
|
||
QgsLayoutItemsListView::QgsLayoutItemsListView( QWidget *parent, QgsLayoutDesignerDialog *designer ) | ||
: QTreeView( parent ) | ||
, mDesigner( designer ) | ||
{ | ||
setColumnWidth( 0, 30 ); | ||
setColumnWidth( 1, 30 ); | ||
setDragEnabled( true ); | ||
setAcceptDrops( true ); | ||
setDropIndicatorShown( true ); | ||
setDragDropMode( QAbstractItemView::InternalMove ); | ||
setContextMenuPolicy( Qt::CustomContextMenu ); | ||
setIndentation( 0 ); | ||
connect( this, &QWidget::customContextMenuRequested, this, &QgsLayoutItemsListView::showContextMenu ); | ||
} | ||
|
||
void QgsLayoutItemsListView::setCurrentLayout( QgsLayout *layout ) | ||
{ | ||
mLayout = layout; | ||
mModel = layout->itemsModel(); | ||
setModel( mModel ); | ||
|
||
header()->setSectionResizeMode( 0, QHeaderView::Fixed ); | ||
header()->setSectionResizeMode( 1, QHeaderView::Fixed ); | ||
setColumnWidth( 0, Qgis::UI_SCALE_FACTOR * fontMetrics().width( QStringLiteral( "xxxx" ) ) ); | ||
setColumnWidth( 1, Qgis::UI_SCALE_FACTOR * fontMetrics().width( QStringLiteral( "xxxx" ) ) ); | ||
header()->setSectionsMovable( false ); | ||
|
||
connect( selectionModel(), &QItemSelectionModel::currentChanged, mLayout->itemsModel(), &QgsLayoutModel::setSelected ); | ||
} | ||
|
||
void QgsLayoutItemsListView::showContextMenu( QPoint point ) | ||
{ | ||
QModelIndex index = indexAt( point ); | ||
QgsLayoutItem *item = mModel->itemFromIndex( index ); | ||
if ( !item ) | ||
return; | ||
|
||
QMenu *menu = new QMenu( this ); | ||
|
||
QAction *itemPropertiesAction = new QAction( tr( "Item Properties…" ), menu ); | ||
connect( itemPropertiesAction, &QAction::triggered, this, [this, item]() | ||
{ | ||
mDesigner->showItemOptions( item, true ); | ||
} ); | ||
menu->addAction( itemPropertiesAction ); | ||
|
||
menu->popup( mapToGlobal( point ) ); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/*************************************************************************** | ||
qgslayoutitemslistview.h | ||
------------------------ | ||
Date : October 2017 | ||
Copyright : (C) 2017 Nyall Dawson | ||
Email : nyall dot dawson at gmail dot com | ||
*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#ifndef QGSLAYOUTITEMSLISTVIEW_H | ||
#define QGSLAYOUTITEMSLISTVIEW_H | ||
|
||
#include "qgis.h" | ||
#include <QTreeView> | ||
|
||
class QgsLayout; | ||
class QgsLayoutDesignerDialog; | ||
class QgsLayoutModel; | ||
|
||
/** | ||
* A list view for showing items in a layout | ||
*/ | ||
class QgsLayoutItemsListView : public QTreeView | ||
{ | ||
Q_OBJECT | ||
|
||
public: | ||
|
||
/** | ||
* Constructor for QgsLayoutItemsListView. | ||
*/ | ||
QgsLayoutItemsListView( QWidget *parent, QgsLayoutDesignerDialog *designer ); | ||
|
||
void setCurrentLayout( QgsLayout *layout ); | ||
|
||
private slots: | ||
|
||
void showContextMenu( QPoint point ); | ||
|
||
private: | ||
|
||
QgsLayout *mLayout = nullptr; | ||
QgsLayoutModel *mModel = nullptr; | ||
QgsLayoutDesignerDialog *mDesigner = nullptr; | ||
}; | ||
|
||
#endif // QGSLAYOUTITEMSLISTVIEW_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters