Skip to content

Commit

Permalink
Move QgsElevationProfileLayerTreeView to GUI library
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jan 16, 2023
1 parent 508d96e commit ba7fbca
Show file tree
Hide file tree
Showing 8 changed files with 160 additions and 176 deletions.
2 changes: 0 additions & 2 deletions src/app/CMakeLists.txt
Expand Up @@ -180,8 +180,6 @@ set(QGIS_APP_SRCS

elevation/qgselevationprofileexportsettingswidget.cpp
elevation/qgselevationprofileimageexportdialog.cpp
elevation/qgselevationprofilelayertreemodel.cpp
elevation/qgselevationprofilelayertreeview.cpp
elevation/qgselevationprofilepdfexportdialog.cpp
elevation/qgselevationprofiletoolidentify.cpp
elevation/qgselevationprofiletoolmeasure.cpp
Expand Down
93 changes: 0 additions & 93 deletions src/app/elevation/qgselevationprofilelayertreeview.cpp

This file was deleted.

68 changes: 0 additions & 68 deletions src/app/elevation/qgselevationprofilelayertreeview.h

This file was deleted.

30 changes: 29 additions & 1 deletion src/app/elevation/qgselevationprofilewidget.cpp
Expand Up @@ -80,7 +80,7 @@ QgsElevationProfileWidget::QgsElevationProfileWidget( const QString &name )

mPanTool = new QgsPlotToolPan( mCanvas );

mLayerTreeView = new QgsElevationProfileLayerTreeView( mLayerTree.get() );
mLayerTreeView = new QgsAppElevationProfileLayerTreeView( mLayerTree.get() );

connect( mLayerTreeView, &QAbstractItemView::doubleClicked, this, [ = ]( const QModelIndex & index )
{
Expand Down Expand Up @@ -765,3 +765,31 @@ QgsElevationProfileWidgetSettingsAction::QgsElevationProfileWidgetSettingsAction
w->setLayout( gLayout );
setDefaultWidget( w );
}

QgsAppElevationProfileLayerTreeView::QgsAppElevationProfileLayerTreeView( QgsLayerTree *rootNode, QWidget *parent )
: QgsElevationProfileLayerTreeView( rootNode, parent )
{

}

void QgsAppElevationProfileLayerTreeView::contextMenuEvent( QContextMenuEvent *event )
{
const QModelIndex index = indexAt( event->pos() );
if ( !index.isValid() )
setCurrentIndex( QModelIndex() );

if ( QgsMapLayer *layer = indexToLayer( index ) )
{
QMenu *menu = new QMenu();

QAction *propertiesAction = new QAction( tr( "Properties…" ), menu );
connect( propertiesAction, &QAction::triggered, this, [layer]
{
QgisApp::instance()->showLayerProperties( layer, QStringLiteral( "mOptsPage_Elevation" ) );
} );
menu->addAction( propertiesAction );

menu->exec( mapToGlobal( event->pos() ) );
delete menu;
}
}
14 changes: 13 additions & 1 deletion src/app/elevation/qgselevationprofilewidget.h
Expand Up @@ -23,6 +23,7 @@
#include "qgsgeometry.h"
#include "qobjectuniqueptr.h"
#include "qgssettingsentryimpl.h"
#include "qgselevationprofilelayertreeview.h"

#include <QWidgetAction>
#include <QElapsedTimer>
Expand All @@ -42,14 +43,25 @@ class QgsPlotToolZoom;
class QgsPlotToolXAxisZoom;
class QgsDoubleSpinBox;
class QgsElevationProfileWidgetSettingsAction;
class QgsElevationProfileLayerTreeView;
class QgsLayerTree;
class QgsLayerTreeRegistryBridge;
class QgsElevationProfileToolIdentify;
class QgsElevationProfileToolMeasure;
class QLabel;
class QgsProfilePoint;

class QgsAppElevationProfileLayerTreeView : public QgsElevationProfileLayerTreeView
{
Q_OBJECT
public:

explicit QgsAppElevationProfileLayerTreeView( QgsLayerTree *rootNode, QWidget *parent = nullptr );

protected:

void contextMenuEvent( QContextMenuEvent *event ) override;
};

class QgsElevationProfileWidget : public QWidget
{
Q_OBJECT
Expand Down
2 changes: 2 additions & 0 deletions src/gui/CMakeLists.txt
Expand Up @@ -230,6 +230,7 @@ set(QGIS_GUI_SRCS
editorwidgets/qgsvaluerelationwidgetfactory.cpp

elevation/qgselevationprofilecanvas.cpp
elevation/qgselevationprofilelayertreeview.cpp

history/qgshistoryprovider.cpp
history/qgshistoryproviderregistry.cpp
Expand Down Expand Up @@ -1108,6 +1109,7 @@ set(QGIS_GUI_HDRS
effects/qgspainteffectwidget.h

elevation/qgselevationprofilecanvas.h
elevation/qgselevationprofilelayertreeview.h

history/qgshistoryprovider.h
history/qgshistoryproviderregistry.h
Expand Down
@@ -1,5 +1,5 @@
/***************************************************************************
qgselevationprofilelayertreemodel.cpp
qgselevationprofilelayertreeview.cpp
-----------------
begin : April 2022
copyright : (C) 2022 by Nyall Dawson
Expand All @@ -16,7 +16,9 @@
* *
***************************************************************************/

#include "qgselevationprofilelayertreemodel.h"
#include "qgselevationprofilelayertreeview.h"
#include "qgslayertreenode.h"
#include "qgslayertree.h"
#include "qgslayertreenode.h"
#include "qgslayertree.h"
#include "qgssymbollayerutils.h"
Expand All @@ -28,8 +30,12 @@
#include "qgsmarkersymbol.h"
#include "qgsfillsymbol.h"

#include <QHeaderView>
#include <QContextMenuEvent>
#include <QMenu>
#include <QMimeData>


QgsElevationProfileLayerTreeModel::QgsElevationProfileLayerTreeModel( QgsLayerTree *rootNode, QObject *parent )
: QgsLayerTreeModel( rootNode, parent )
{
Expand Down Expand Up @@ -324,3 +330,48 @@ bool QgsElevationProfileLayerTreeProxyModel::filterAcceptsRow( int sourceRow, co
return false;
}
}


QgsElevationProfileLayerTreeView::QgsElevationProfileLayerTreeView( QgsLayerTree *rootNode, QWidget *parent )
: QTreeView( parent )
, mLayerTree( rootNode )
{
mModel = new QgsElevationProfileLayerTreeModel( rootNode, this );
mProxyModel = new QgsElevationProfileLayerTreeProxyModel( mModel, this );

setHeaderHidden( true );

setDragEnabled( true );
setAcceptDrops( true );
setDropIndicatorShown( true );
setExpandsOnDoubleClick( false );

// Ensure legend graphics are scrollable
header()->setStretchLastSection( false );
header()->setSectionResizeMode( QHeaderView::ResizeToContents );

// If vertically scrolling by item, legend graphics can get clipped
setVerticalScrollMode( QAbstractItemView::ScrollPerPixel );

setDefaultDropAction( Qt::MoveAction );

setModel( mProxyModel );
}

QgsMapLayer *QgsElevationProfileLayerTreeView::indexToLayer( const QModelIndex &index )
{
if ( QgsLayerTreeNode *node = mModel->index2node( mProxyModel->mapToSource( index ) ) )
{
if ( QgsLayerTreeLayer *layerTreeLayerNode = mLayerTree->toLayer( node ) )
{
return layerTreeLayerNode->layer();
}
}
return nullptr;
}

void QgsElevationProfileLayerTreeView::resizeEvent( QResizeEvent *event )
{
header()->setMinimumSectionSize( viewport()->width() );
QTreeView::resizeEvent( event );
}

0 comments on commit ba7fbca

Please sign in to comment.